views:

1201

answers:

2

Wifi support on Vista is fine, but Native Wifi on XP is half baked. NDIS 802.11 Wireless LAN Miniport Drivers only gets you part of the way there (e.g. network scanning). From what I've read (and tried), the 802.11 NDIS drivers on XP will not allow you to configure a wireless connection. You have to use the Native Wifi API in order to do this. (Please, correct me if I'm wrong here.) Applications like InSSIDer have helped me to understand the APIs, but InSSIDer is just a scanner and is not designed to configure Wifi networks.

So, the question is: where can I find some code examples (C# or C++) that deal with the configuration of Wifi networks on XP -- e.g. profile creation and connection management?

I should note that this is a XP Embedded application on a closed system where we can't use the built-in Wireless Zero Configuration (WZC). We have to build all Wifi management functionality into our .NET application.

Yes, I've Googled myself blue. It seems that someone should have a solution to this problem, but I can't find it. That's why I'm asking here.

Thanks.

+1  A: 

We use WZC on XP and Native WiFi on Vista, but here's the code which we use on Vista, FWIW.

Profile creation:

// open a handle to the service
if ((dwError = WlanOpenHandle(
        WLAN_API_VERSION,
        NULL,               // reserved
        &dwServiceVersion,
        &hClient
        )) != ERROR_SUCCESS)
{
hClient = NULL;
}
return dwError;
dwError=WlanSetProfile(hClient, &guid, 0, profile, NULL, TRUE, NULL, &reason_code);

Make a connection:

    WLAN_CONNECTION_PARAMETERS conn;

    conn.wlanConnectionMode=wlan_connection_mode_profile;
    conn.strProfile=name;
    conn.pDot11Ssid=NULL;
    conn.pDesiredBssidList=NULL;
    conn.dot11BssType=dot11_BSS_type_independent;
    conn.dwFlags=NULL;

    dwError = WlanConnect(hClient, &guid, &conn, NULL);

Check for connection:

    BOOL ret=FALSE;
    DWORD dwError;
    DWORD size;
    void *p=NULL;
    WLAN_INTERFACE_STATE *ps;

    dwError = WlanQueryInterface(hClient, &guid, wlan_intf_opcode_interface_state, NULL, &size, &p, NULL);
    ps=(WLAN_INTERFACE_STATE *)p;
    if(dwError!=0) 
        ret=FALSE;
    else
        if(*ps==wlan_interface_state_connected) 
            ret=TRUE;
    if(p!=NULL) WlanFreeMemory(p);
    return ret;

To keep connected to the network, just spawn a thread then keep checking for a connection, then re-connecting if need be.

EDIT: Man this markup stuff is lame. Takes me like 3 edits to get the farking thing right.

Nick
+1  A: 

Thanks for the feedback Nick. I've pretty much gotten the profile and connection management working. The trick is figuring out which parts of the Native Wifi API are not supported on XP. Fortunately, the Managed Wifi API has connect/disconnect notification events that do work on XP (NetworkChange also gives similar change events).

Bob Nadler