rtw_ioctl_query.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_IOCTL_QUERY_C_
  21. #include <drv_types.h>
  22. #ifdef PLATFORM_WINDOWS
  23. /*
  24. * Added for WPA2-PSK, by Annie, 2005-09-20.
  25. * */
  26. u8
  27. query_802_11_capability(
  28. _adapter *Adapter,
  29. u8 *pucBuf,
  30. u32 *pulOutLen
  31. )
  32. {
  33. static NDIS_802_11_AUTHENTICATION_ENCRYPTION szAuthEnc[] = {
  34. {Ndis802_11AuthModeOpen, Ndis802_11EncryptionDisabled},
  35. {Ndis802_11AuthModeOpen, Ndis802_11Encryption1Enabled},
  36. {Ndis802_11AuthModeShared, Ndis802_11EncryptionDisabled},
  37. {Ndis802_11AuthModeShared, Ndis802_11Encryption1Enabled},
  38. {Ndis802_11AuthModeWPA, Ndis802_11Encryption2Enabled},
  39. {Ndis802_11AuthModeWPA, Ndis802_11Encryption3Enabled},
  40. {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption2Enabled},
  41. {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption3Enabled},
  42. {Ndis802_11AuthModeWPANone, Ndis802_11Encryption2Enabled},
  43. {Ndis802_11AuthModeWPANone, Ndis802_11Encryption3Enabled},
  44. {Ndis802_11AuthModeWPA2, Ndis802_11Encryption2Enabled},
  45. {Ndis802_11AuthModeWPA2, Ndis802_11Encryption3Enabled},
  46. {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption2Enabled},
  47. {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption3Enabled}
  48. };
  49. static ULONG ulNumOfPairSupported = sizeof(szAuthEnc) / sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
  50. NDIS_802_11_CAPABILITY *pCap = (NDIS_802_11_CAPABILITY *)pucBuf;
  51. u8 *pucAuthEncryptionSupported = (u8 *) pCap->AuthenticationEncryptionSupported;
  52. pCap->Length = sizeof(NDIS_802_11_CAPABILITY);
  53. if (ulNumOfPairSupported > 1)
  54. pCap->Length += (ulNumOfPairSupported - 1) * sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
  55. pCap->Version = 2;
  56. pCap->NoOfPMKIDs = NUM_PMKID_CACHE;
  57. pCap->NoOfAuthEncryptPairsSupported = ulNumOfPairSupported;
  58. if (sizeof(szAuthEnc) <= 240) /* 240 = 256 - 4*4 */ { /* SecurityInfo.szCapability: only 256 bytes in size. */
  59. _rtw_memcpy(pucAuthEncryptionSupported, (u8 *)szAuthEnc, sizeof(szAuthEnc));
  60. *pulOutLen = pCap->Length;
  61. return _TRUE;
  62. } else {
  63. *pulOutLen = 0;
  64. return _FALSE;
  65. }
  66. }
  67. u8 query_802_11_association_information(_adapter *padapter, PNDIS_802_11_ASSOCIATION_INFORMATION pAssocInfo)
  68. {
  69. struct wlan_network *tgt_network;
  70. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  71. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  72. WLAN_BSSID_EX *psecnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  73. u8 *pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  74. unsigned char i, *auth_ie, *supp_ie;
  75. /* NdisZeroMemory(pAssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION)); */
  76. _rtw_memset(pAssocInfo, 0, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
  77. /* pAssocInfo->Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION); */
  78. /* ------------------------------------------------------ */
  79. /* Association Request related information */
  80. /* ------------------------------------------------------ */
  81. /* Req_1. AvailableRequestFixedIEs */
  82. if (psecnetwork != NULL) {
  83. pAssocInfo->AvailableRequestFixedIEs |= NDIS_802_11_AI_REQFI_CAPABILITIES | NDIS_802_11_AI_REQFI_CURRENTAPADDRESS;
  84. pAssocInfo->RequestFixedIEs.Capabilities = (unsigned short) *&psecnetwork->IEs[10];
  85. _rtw_memcpy(pAssocInfo->RequestFixedIEs.CurrentAPAddress,
  86. &psecnetwork->MacAddress, 6);
  87. pAssocInfo->OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  88. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING | _FW_LINKED) == _TRUE) {
  89. if (psecuritypriv->ndisauthtype >= Ndis802_11AuthModeWPA2)
  90. pDest[0] = 48; /* RSN Information Element */
  91. else
  92. pDest[0] = 221; /* WPA(SSN) Information Element */
  93. supp_ie = &psecuritypriv->supplicant_ie[0];
  94. i = 13; /* 0~11 is fixed information element */
  95. while ((i < supp_ie[0]) && (i < 256)) {
  96. if ((unsigned char)supp_ie[i] == pDest[0]) {
  97. _rtw_memcpy((u8 *)(pDest),
  98. &supp_ie[i],
  99. supp_ie[1 + i] + 2);
  100. break;
  101. }
  102. i = i + supp_ie[i + 1] + 2;
  103. if (supp_ie[1 + i] == 0)
  104. i = i + 1;
  105. }
  106. pAssocInfo->RequestIELength += (2 + supp_ie[1 + i]); /* (2 + psecnetwork->IEs[1+i]+4); */
  107. }
  108. }
  109. /* ------------------------------------------------------ */
  110. /* Association Response related information */
  111. /* ------------------------------------------------------ */
  112. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  113. tgt_network = &(pmlmepriv->cur_network);
  114. if (tgt_network != NULL) {
  115. pAssocInfo->AvailableResponseFixedIEs =
  116. NDIS_802_11_AI_RESFI_CAPABILITIES
  117. | NDIS_802_11_AI_RESFI_ASSOCIATIONID
  118. ;
  119. pAssocInfo->ResponseFixedIEs.Capabilities = (unsigned short) *&tgt_network->network.IEs[10];
  120. pAssocInfo->ResponseFixedIEs.StatusCode = 0;
  121. pAssocInfo->ResponseFixedIEs.AssociationId = (unsigned short) tgt_network->aid;
  122. pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAssocInfo->RequestIELength;
  123. auth_ie = &psecuritypriv->authenticator_ie[0];
  124. i = auth_ie[0] - 12;
  125. if (i > 0) {
  126. _rtw_memcpy((u8 *)&pDest[0], &auth_ie[1], i);
  127. pAssocInfo->ResponseIELength = i;
  128. }
  129. pAssocInfo->OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAssocInfo->RequestIELength;
  130. }
  131. }
  132. return _TRUE;
  133. }
  134. #endif