Click here to Skip to main content
12,400,556 members (59,877 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C
Hello

I am trying to write a program to connect to wifi routers/ap. I have been successfull into connecting to open networks.

However when i try to connect to secured networks, a baloon pop up asking for password. Can i not pass the password automatically.

My code is as below. Can someone modify this to work for secured network. My APs does not have any profile names.
/* Client opens a handle for connection */
status = WlanOpenHandle( WLAN_API_VERSION, NULL, &dwCurVersion,&hClient );
 
/* Get the list of wi-fi interfaces */
status = WlanEnumInterfaces(hClient, NULL, &pIfList);
 
    pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[0];
 

/* Get the list of visible networks */
    status = WlanGetAvailableNetworkList (hClient,&pIfInfo->InterfaceGuid,0,NULL,&pBssList);
 
    for (tmploop = 0; tmploop < pBssList->dwNumberOfItems; tmploop++)
    {
        pBssEntry = (WLAN_AVAILABLE_NETWORK *) & pBssList->Network[tmploop];
        if (pBssEntry->dot11Ssid.uSSIDLength != 0)
        {
 
            strcpy(tmpBuffer,(char *) pBssEntry->dot11Ssid.ucSSID );
 
            /* Whether the HOST to be connected is found ? */
            if(strcmp(tmpBuffer,"2WIRE472") == 0)
            {
                //hostFoundflag = SET;
                wlanConnPara.wlanConnectionMode = wlan_connection_mode_discovery_secure;//wlan_connection_mode_discovery_unsecure;
                wlanConnPara.strProfile = pBssEntry->strProfileName;
                strcpy( (char *)(infoForSSID.ucSSID), tmpBuffer);
                infoForSSID.uSSIDLength = pBssEntry->dot11Ssid.uSSIDLength;
                wlanConnPara.pDot11Ssid =&infoForSSID;
                wlanConnPara.pDesiredBssidList = NULL;
                wlanConnPara.dot11BssType = pBssEntry->dot11BssType;
                wlanConnPara.dwFlags = pBssEntry->dwFlags;
 
                /* Connect to the host */
                status = WlanConnect( hClient, &pIfInfo->InterfaceGuid, &wlanConnPara, NULL );
 
            }
        }
    }
Thanks
Nishith
Posted 6-Oct-12 15:01pm
Updated 6-Oct-12 18:30pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100