September
2004, Issue 170
Uncomplicated
Wireless Networking
WIRELESS API
The
seemingly automatic operation of the wireless CompactFlash
card was actually pulled off by the default settings
inside the Dynamic C wireless packet driver and TCP/IP
functions. You can override the defaults in your code
using the Dynamic C wireless API. The structure of the
Dynamic C wireless API is as follows:
pd_ioctl(int
nic, int cmd, char
*data, int len);
where
nic is always zero, and cmd is the Dynamic C Wi-Fi command.
*data is the string, character array, or pointer to
a structure. len is the size of the data field.
To
command the Linksys wireless CompactFlash card to perform
a scan, you must issue the API call in the following
way:
pd_ioctl(0,WIFI_SCANREQ,(char
*)0,0);
To
inspect the results of the scan, all you have to do
is define a buffer (unsigned scanbuf[1000];) and call
the wireless API:
pd_ioctl(0,WIFI_SCANRES,(char
*)scanbuf,sizeof(scanbuf));
The
wireless scan process requires the wireless CompactFlash
card’s Roam mode be set to manual. You also might want
to force the wireless CompactFlash card into Infrastructure
mode. Because you’re actively scanning, the SSID should
be set to “any” (any is defined as “ ”). These tasks
are easily performed by filling in the API blanks in
the WIFI_INIT macro (see Listing 3).
As
you can see in Listing 3, there are a number of API
commands that can be issued in your wireless code. To
set up the Wi-Fi application kit for IBSS mode, the
Dynamic C documentation says to code IBBS in the parameter
field of the WIFI_MODE command. This is a typo and the
example programs will compile but they won’t run. I
checked the API source code and the API is expecting
to see IBSS in the WIFI_MODE parameter field.
The
WIFI_OWNCHAN and WIFI_OWNSSID API commands are also
used in Ad Hoc mode to define the channel and SSID of
the independent station. I installed a second AP called
CircuitCellar in a remote part of the Florida room and
forced the Linksys wireless CompactFlash card to associate
with it by coding CircuitCellar in the parameter field
of the WIFI_SSID command.
WEP
is enabled by coding:
pd_ioctl(0,WIFI_WEP_FLAG,”1”,0);.
Four
sets of 13 bytes form the WEP keys. The transmit key
is selected using the WIFI_WEP_USEKEY command. Private
authentication is activated with the WIFI_WEP_AUTH command
and a 1 in the parameter field.
There’s
one more API command that allows the wireless programmer
to start and stop the MAC. pd_ioctl (0,WIFI_MAC,”off”,0);
disables the wireless CompactFlash card’s MAC engine
and pd_ioctl(0,WIFI_MAC, ”on”,0); enables the MAC. This command is useful
when you want to programmatically change the wireless
CompactFlash card’s configuration. Stop the MAC to make
your changes.