REALbasic Airport Classes
by Charlie Boisseau
December 2004
http://www.boisseau.co.uk/


About these classes.
These classes are based on Apple's private Airport Framework. The framework was reverse-engeneered by Jason Toffaletti <jason at subterrific dot net> into a C header file. I have turned the functions into REALbasic declares and written these wrapper classes for ease of use.

Requirements
These classes use Mac OS X Framework declares and therefore must be compiled as Mach-O. Attempting to compile these classes in a PEF application will not work.

These classes use a small portion of the CoreFoundation classes (namely CFString and CFData). I have successfully tested it both with Thomas Reed's CoreFoundation Classes and with Kevin Ballard's CFPlugin. Because the use is so minimal, with 5 minutes work, you could probably have it working with Christian Schmitz's MBS Plugin CF implementation.

If you use these classes in your project, be sure to let me know, and give credit in your about box.



Module WirelessGlobals
  Available As Integer
    This function should be called before any instance of Apple80211 is created. If WirelessAvailable returns false, you shouldn't use Apple80211, it will cause errors
  ParseMACAddress(s As String) As String
    Formats a 6-byte string representation of a MAC address into a fully-formed hexidecimal representation, with colons delimiting each byte. (eg. 00:A1:B2:C3:D4:E5)
  Bit(Extends m As MemoryBlock, Offset As Integer) As Boolean
    A MemoryBlock extenstion, used by Apple80211.GetChannels to get a single-bit value at the specified offset. Example:
If m.Bit(1) Then
//Channel 1 is available
End If

Class Apple80211
Attributes:
  BestChannel As Integer
    The best channel to use for creating an AdHoc network.
  CurrentChannel As Integer
    The channel currently in use by the Airport network you are connected to.
  DesiredSSID As String
    The name of the network attempting to be used on the AdHoc network.
  OwnMACAddress As String
    The wireless address of your Airport card.
  Enabled As Boolean (read/write)
    The on/off state of the Airport I/O.
  Power As Boolean (read/write)
    The on/off state of the Airport card.
Functions:
  Encrypt (Password As String, Make104Bit As Boolean) As String
    This function takes a password and returns it in the form of a WEP encrypted key. Normally it generates a 40bit key, but if Make104Bit is set to True, it will generate a 104-bit key.
  GetChannels As Integer()
    Returns an array of Integers containing a list of valid AdHoc channels.
  GetInfo As WirelessInfo
    Returns an instance of the WirelessInfo class, containing all sorts of info about the wireless network currently in use.
  JoinNetwork (Network As String, [Password As String])
    Attempts to join the specified wireless network. Optional Passowrd parameter will attempt to join with a WEP key.
  MakeIBSS (Name As String, Password As String, Channel As Integer)
    Creates an AdHoc wireless network with the name, password and channel specified.
  Scan (StripDups As Boolean, [AdHoc As Boolean]) As WirelessNetworkInfo()
    Scans for local wireless networks. Returns an array of the networks represented as the WirelessNetworkInfo class. If StripDuplicates is True, networks with the same name will not appear more than once. If the optional parameter, AdHoc, is True then only AdHoc networks are returned in the array.

Class WirelessInfo
Attributes:
  ClientMode As Integer
    Shows whether the airport card is being used as a BSS client or as a host (AdHoc network). 1 = BSS Client, 4 = AdHoc Host
  CommunicationQuality As Integer
    The quality of the communication with the base station or AdHoc client.
  LinkQuality As String
    The overall quality of the link with the base station or AdHoc client.
  MACAddress As String
    The wireless network address of the base station curently in use.
  Name As String
    The SSID name of the network currently in use.
  Noise As Integer
    The level of noise disturbing the wireless link.
  PortStatus As Integer
    The status of the Airport card. 1 = Off, 2 = Bad Connection, 3 = AdHoc Host, 4 = BSS Client, 5 = BSS Out Of Range
  Power As Boolean
    The same as Apple80211.Power (read-only).
  Signal As Integer
    The signal strength of the wireless link.
  WEPStatus As Integer
    The status of the WEP encryption. 0 = Bad/Error, 1 = OK, 2 = Wrong Key

Class WirelessNetworkInfo
Attributes:
  Name As String
    The SSID (network name) of the network found.
  MACAddress As String
    The MAC (wireless) address of the base station the network was found on.
  Channel As Integer
    The wireless channel the network communicates over.
  Signal As Integer
    The signal level (percentage) between the Airport Card and the base station.
  Noise As Integer
    The noise level (percentage) between the Airport Card and the base station.
  BeaconInterval As Integer
    The interval at which one's application should poll the network (milliseconds).
  Flags As Integer
    Other information on the found network:

&h0001 = NetworkManagedFlag
&h0002 = NetworkAdhocFlag
&h0004 = NetworkCFPollable
&h0008 = NetworkCFPollRequest
&h0010 = NetworkEncryptedFlag
&h0020 = NetworkShortPreamble
&h0040 = NetworkPBCC
&h0080 = NetworkChannelAgility
&hFF00 = NetworkReserved