Home |
Function xn_wlan_setup |
Function xn_wlan_setupThis function initializes a WLAN interface. It must be called before xn_interface_open or xn_interface_open_config: int xn_wlan_setup(int iface_no, const char * SSID, const char * Name, int Channel, int WEPKeyIndex, const char * WEPKey, DWORD Flags); Parametersiface_noInterface number returned by xn_interface_open or xn_interface_open_config. SSIDPointer to the Service Set Identifier of the network to connect to. This value is also frequently called the network name. In Ad-Hoc mode, the string must be identical to the value set in the peer station to connect to. NamePointer to the name of the local host. In many wireless networks, this value is not used. ChannelThe radio channel to use in the range 1 to 14. For Ad-Hoc connections, this value must match the value set in the peer station. To connect to an Access Point, it may alternatively be set to 0 to have the WLAN device search for an Access Point on all channels. If several Access Points are in range, specifying an explicit value unequal to 0 can ensure that the device connects to the correct Access Point. WEPKeyIndexIf WEP (Wireless Encryption Protocol) is to be used, this parameter must specify the WEP Key index to use in the range 0 to 3 (for key 1 to 4). The value must match the corresponding value set in the Access Point or peer station. This parameter is ignored if WebKey is NULL. WEPKeyPointer to the WEP key to use, or NULL if no encryption is desired. The data pointed to must have 5 bytes for 64-bit encryption or 13 bytes for 128-bit encryption. FlagsA combination of the following values may be specified:
return value0 on success or -1 on failure. After the xn_wlan_setup call, software should wait at least 1-5 seconds before using the interface, since the interface may need some time to negotiate encryption parameters, link speed, etc. before IP traffic can be routed. Example:static BYTE TargetIP[] = {192, 168, 1, 10}; static BYTE NetMask[] = {255, 255, 255, 0}; static BYTE DefaultGateway[] = {192, 168, 1, 1}; // set to zero if no gateway static BYTE DNSServer[] = {192, 168, 1, 1}; // ditto ... Result = xn_rtip_init(); // Initialize the RTIP stack if (Result == SOCKET_ERROR) Error("xn_rtip_init failed"); Result = BIND_DRIVER(MINOR_0); // tell RTIP what Ethernet driver we want (see netcfg.h) if (Result == SOCKET_ERROR) Error("driver initialization failed"); #if DEVICE_ID == PRISM_PCMCIA_DEVICE // if this is a PCMCIA device, start the PCMCIA driver if (RTPCInit(-1, 0, 2, NULL) == 0) Error("No PCMCIA controller found"); #endif // Open the interface interface = xn_interface_open_config(DEVICE_ID, MINOR_0, ED_IO_ADD, ED_IRQ, ED_MEM_ADD); if (interface == SOCKET_ERROR) Error("xn_interface_open_config failed"); xn_wlan_setup(interface, // iface_no: value returned by xn_interface_open_config() "network name", // SSID : network name set in the access point "station name", // Name : name of this node 0, // Channel : 0 for access points, 1..14 for ad-hoc 0, // KeyIndex: 0 .. 3 "12345", // WEP Key : key to use (5 or 13 bytes) 0); // Flags : see manual and Wlanapi.h for details Sleep(1000); // wireless devices need a little time before they can be used // Set the IP address and interface printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]); Result = xn_set_ip(interface, TargetIP, NetMask); // define default gateway and DNS server xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF); xn_set_server_list((DWORD*)DNSServer, 1);
|