Link to home
Start Free TrialLog in
Avatar of ravi_pvkumar
ravi_pvkumar

asked on

How to set the Wireless Key and access the Wireless Access point.

Hi,

We are facing the problem to access the Wireless Router, we are using the D-Link router.
We are able to Enumerate the device and also able to retrieve the list of AP's.  We need to access the router using the SSID and Wireless key as the inputs and we are failing to do so.
steps followed are:
1.net stop ndisuio - asks for stopping wzc serivce and we stopped it.
2.net start ndisuio
and excuting following program.

WRAPI_NDIS_DEVICE            *pDeviceList = NULL;
      HRESULT                        hRes;
      
      long                        lItems = 0;
      long                        lNumItems = 0;
      UCHAR                        Ssid[32] = {0};
      
      AP_DATA                        *pAP_list = NULL;
      CHAR                        *pSSId

      ULONG                        lSSIdLength = strlen(pSSId);
      ULONG                        lRTSThresh = 0;
      
      MAC_ADDR                  addr = {0};
      DOT_11_STATS                  DOT11Stats;

      // Get the list of Devices in the System
      hRes = WRAPIEnumerateDevices(&pDeviceList, &lItems);

      // Print the list of devices obtained
      for ( int i = 0; i < lItems; i++)
      {
            printf("%ws\n  - %ws\n", pDeviceList[i].pDeviceDescription, pDeviceList[i].pDeviceName);
      }

      
      // Open the device at pDeviceList[1] -- pDeviceList[0] happens to be the        * Ethernet Interface
      hRes = WRAPIOpenNdisDevice(pDeviceList[0].pDeviceName);
      
      int mymode;
      
      WRAPIGetAuthMode(&mymode);
      PrintAuthMode(mymode);

      mymode=Ndis802_11AuthModeShared;//Ndis802_11AuthModeOpen;//Ndis802_11AuthModeAutoSwitch;//Ndis802_11AuthModeShared;
      hRes=WRAPISetAuthMode(&mymode);
      
      hRes=WRAPIGetAuthMode(&mymode);
      PrintAuthMode(mymode);


      // Get the value of RTS Threshold
      hRes = WRAPIGetRTSThreshold(&lRTSThresh);
      
      // Get the MAC address of the AP to which this station is associated
      // Get Packet-level statistics from the 802.11 interface
      hRes = WRAPIGetPacketStats(&DOT11Stats);

      // Get a list of all APs within range of this station in a list of AP_DATA
       // structures
      hRes = WRAPIGetAPList(&pAP_list, &lNumItems);


      // Print out the list of all APs and their signal strengths

      printf("MAC Address \t\tSignal Strength (dBm) \n");

      for ( i = 0; i < lNumItems; i++ )
      {
            for ( int j = 0; j < 6; j++)
            {
                  printf("%02x", pAP_list[i].mac_addr[j]);
            }

            printf("\t\t%d\n", pAP_list[i].Rssi);
      }

      // Print out the list of all APs and their signal strengths

      printf("MAC Address \t\tSignal Strength (dBm) \n");

      for ( i = 0; i < lNumItems; i++ )
      {
            for ( int j = 0; j < 6; j++)
            {
                  printf("%02x", pAP_info[i].mac_addr[j]);
            }

            printf("\t\t%d\t%s\n", pAP_info[i].Rssi, pAP_info[i].Ssid.Ssid);
      }
      if(pAP_list[0].mac_addr!=NULL)
      {
            MAC_ADDR mac_addr;
            for ( int j = 0; j < 6; j++)
            {
                   mac_addr[j]=pAP_list[0].mac_addr[j];
            }
            hRes=WRAPISetAssociatedAP(mac_addr);
            printf("\nAssociatedAP:%02x\n",mac_addr);
      }

      ///Setting Infrastructure mode
      int mynetworkmode;
      hRes=WRAPIGetNetworkMode(&mynetworkmode);
      mynetworkmode=Ndis802_11Infrastructure;
      hRes=WRAPISetNetworkMode(&mynetworkmode);

      ///Set WEP Wnable
      hRes=WRAPISetWEPEnable();
      ///////Set Wep Key
      UCHAR mykey[]="abcdefghijklm";
      WCHAR wkey[13];
      for(i=0;i<13;i++)
            wkey[i]=(WCHAR)mykey[i];
      hRes=WRAPISetWirelessKey(wkey);

/////Set Associate AP
      if(pAP_info[0].mac_addr!=NULL)
      {
            MAC_ADDR mac_addr;
            for ( int j = 0; j < 6; j++)
            {
                   mac_addr[j]=pAP_info[0].mac_addr[j];
            }
            hRes=WRAPIDisassociate();
            hRes=WRAPISetAssociatedAP(mac_addr);
            printf("\nAssociatedAP:%02x\n",mac_addr);
      }
      
      // Free all the memory that gets allocated inside the WRAPI dll
      free(pAP_list);
      free(pAP_info);


      for (i = 0; i < lItems; i++ )
      {
            free(pDeviceList[i].pDeviceName);
            free(pDeviceList[i].pDeviceDescription);
      }

      free(pDeviceList);

      return 0;


can anybody help us to access the router using the SSID and Wireless Key we are using WRAPI.dll as a reference.
regards,
RKV
ASKER CERTIFIED SOLUTION
Avatar of opanza
opanza

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial