Problem on associate AP.

Hi expert,

My another problem is how to issue the association instruction by my application.  Likewise the OID_802_11_DISASSOCIATE  defined in "ntddndis.h", I suppose the OID for associating AP should be also defined.  But I can not find any hint on such kind of OID.  Is there any trick to the problem?

Thanks!

-Liang
overlookAsked:
Who is Participating?
 
jhanceConnect With a Mentor Commented:
It's not necessary to set the BSSID to associate UNLESS there are multiple APs with the same SSID (which is quite possible location covered by several APs).  So by using the BSSID you FORCE an association.  If there are multiple APs with the same SSID and you don't use BSSID, the driver in the wireless NIC is supposed to choose the best one.  In my experience the driver rarely chooses well.

If the site scan shows only a single AP with the desired SSID, then:

1) Set the infastructure mode to INFRASTRUCTURE
2) Set the authentication mode to the desired value.  If WEP, set the WEP key.
3) Set the SSID to the one desired.

If you need to set the BSSID, set it before setting the SSID.

Generally you would use the signal strength values in the site scan to determine which AP has the strongest signal if there are multiple choices among the same SSID.
0
 
opanzaCommented:
As the MSDN says, you can use OID_802_11_BSSID OID to "requests that the miniport driver set the media access control (MAC) address of the access point to associate with. After this OID is set, the device can only associate with an access point (AP) with the desired BSSID".

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/network/hh/network/213_802.11_8e2ae679-a150-4ac8-9e01-0c742740bd79.xml.asp
0
 
overlookAuthor Commented:
I learned form the doc that if I want to associate the AP by myself, I should set an SSID for my STA and then set the MAC address of targeted AP.

However, I can not associate AP by setting OID_802_11_BSSID.  And likewise, the tearing down operation of an established association also failed withe the error code 21.  Why?

By the way, how can I monitor the MAC layer frame exchange between STA and AP, by MS Network Monitor?

Thank you!

-Liang

==============================================
NDIS_STATUS            Dot11_SetAssociatedAP(
      HANDLE      handle,
      MAC_ADDR mac_addr)
{
      UCHAR                        buf[sizeof(NDIS_OID) + sizeof(NDIS_802_11_MAC_ADDRESS)];
      PNDISUIO_SET_OID      pSetOid;
      DWORD                        dwBytesReturned;
      DWORD                        dwError;
      NDIS_STATUS                  status = S_OK;
      int i = 0;

      pSetOid = (PNDISUIO_SET_OID) buf;
      pSetOid->Oid = OID_802_11_BSSID;

      //
      //      for debug
      //
      PRINTF(("Associate the AP with the MAC: \t"));
      showMACAddress( mac_addr );

      for ( i = 0; i < 6; i++ )
      {
            pSetOid->Data[i] = mac_addr[i];
      }

      if (!DeviceIoControl(
                              handle,
                              IOCTL_NDISUIO_SET_OID_VALUE,
                              (LPVOID) &buf[0],
                              sizeof(buf),
                              (LPVOID) &buf[0],
                              0,
                              &dwBytesReturned,
                              NULL))
      {
            dwError = GetLastError();
            DEBUGP(("IOCTL SET_BSSID failed: %d\n", dwError));
            status = E_FAIL;
      }


      //
      //      Enable roaming among APs if necessary
      //

      if( status != E_FAIL )
      {
            for ( i = 0; i < 6; i++ )
            {
                  pSetOid->Data[i] = 0xFF;
            }

            if (!DeviceIoControl(
                                    handle,
                                    IOCTL_NDISUIO_SET_OID_VALUE,
                                    (LPVOID) &buf[0],
                                    sizeof(buf),
                                    (LPVOID) &buf[0],
                                    0,
                                    &dwBytesReturned,
                                    NULL))
            {
                  dwError = GetLastError();
                  DEBUGP(("IOCTL SET_BSSID failed: %d\n", dwError));
                  status = E_FAIL;
            }
            
      }
      
      return status;
} //Dot11_SetAssociatedAP



NDIS_STATUS            Dot11_Disassociate(
      HANDLE      handle)
{
      UCHAR                               buf[1024];
      NDIS_STATUS                        status = S_OK;
      PNDISUIO_SET_OID            pSetOid;
      DWORD                              dwBytesReturned;
      DWORD                              dwError;

      pSetOid = (PNDISUIO_SET_OID) buf;
      pSetOid->Oid = OID_802_11_DISASSOCIATE;

      if (!DeviceIoControl(
                        handle,
                        IOCTL_NDISUIO_SET_OID_VALUE,
                        (LPVOID) &buf[0],
                        sizeof(buf),
                        (LPVOID) &buf[0],
                        0,
                        &dwBytesReturned,
                        NULL))
      {
            dwError = GetLastError();
            DEBUGP(("IOCTL DISASSOCIATE failed: %d\n", dwError));
            status = E_FAIL;
      }


            
      return status;
} //Dot11_Disassociate
0
 
opanzaConnect With a Mentor Commented:
I supposed you already had your connection established to your AP. However, for associating to the access point it has to be done by using OID_802_11_BSSID OID.

Your code should work and it's prepared for roaming if association fails. Maybe you get error 21 (device not ready) because you are attempting to set the BSSID before setting the SSID.


A correction to the above comment.

The BSSID has to be set after having set the SSID.

(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/network/hh/network/213_802.11_8e2ae679-a150-4ac8-9e01-0c742740bd79.xml.asp)
0
All Courses

From novice to tech pro — start learning today.