rtw_ioctl_query.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  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. *****************************************************************************/
  15. #define _RTW_IOCTL_QUERY_C_
  16. #include <drv_types.h>
  17. #ifdef PLATFORM_WINDOWS
  18. /*
  19. * Added for WPA2-PSK, by Annie, 2005-09-20.
  20. * */
  21. u8
  22. query_802_11_capability(
  23. _adapter *Adapter,
  24. u8 *pucBuf,
  25. u32 *pulOutLen
  26. )
  27. {
  28. static NDIS_802_11_AUTHENTICATION_ENCRYPTION szAuthEnc[] = {
  29. {Ndis802_11AuthModeOpen, Ndis802_11EncryptionDisabled},
  30. {Ndis802_11AuthModeOpen, Ndis802_11Encryption1Enabled},
  31. {Ndis802_11AuthModeShared, Ndis802_11EncryptionDisabled},
  32. {Ndis802_11AuthModeShared, Ndis802_11Encryption1Enabled},
  33. {Ndis802_11AuthModeWPA, Ndis802_11Encryption2Enabled},
  34. {Ndis802_11AuthModeWPA, Ndis802_11Encryption3Enabled},
  35. {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption2Enabled},
  36. {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption3Enabled},
  37. {Ndis802_11AuthModeWPANone, Ndis802_11Encryption2Enabled},
  38. {Ndis802_11AuthModeWPANone, Ndis802_11Encryption3Enabled},
  39. {Ndis802_11AuthModeWPA2, Ndis802_11Encryption2Enabled},
  40. {Ndis802_11AuthModeWPA2, Ndis802_11Encryption3Enabled},
  41. {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption2Enabled},
  42. {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption3Enabled}
  43. };
  44. static ULONG ulNumOfPairSupported = sizeof(szAuthEnc) / sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
  45. NDIS_802_11_CAPABILITY *pCap = (NDIS_802_11_CAPABILITY *)pucBuf;
  46. u8 *pucAuthEncryptionSupported = (u8 *) pCap->AuthenticationEncryptionSupported;
  47. pCap->Length = sizeof(NDIS_802_11_CAPABILITY);
  48. if (ulNumOfPairSupported > 1)
  49. pCap->Length += (ulNumOfPairSupported - 1) * sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
  50. pCap->Version = 2;
  51. pCap->NoOfPMKIDs = NUM_PMKID_CACHE;
  52. pCap->NoOfAuthEncryptPairsSupported = ulNumOfPairSupported;
  53. if (sizeof(szAuthEnc) <= 240) /* 240 = 256 - 4*4 */ { /* SecurityInfo.szCapability: only 256 bytes in size. */
  54. _rtw_memcpy(pucAuthEncryptionSupported, (u8 *)szAuthEnc, sizeof(szAuthEnc));
  55. *pulOutLen = pCap->Length;
  56. return _TRUE;
  57. } else {
  58. *pulOutLen = 0;
  59. return _FALSE;
  60. }
  61. }
  62. u8 query_802_11_association_information(_adapter *padapter, PNDIS_802_11_ASSOCIATION_INFORMATION pAssocInfo)
  63. {
  64. struct wlan_network *tgt_network;
  65. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  66. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  67. WLAN_BSSID_EX *psecnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  68. u8 *pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  69. unsigned char i, *auth_ie, *supp_ie;
  70. /* NdisZeroMemory(pAssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION)); */
  71. _rtw_memset(pAssocInfo, 0, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
  72. /* pAssocInfo->Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION); */
  73. /* ------------------------------------------------------ */
  74. /* Association Request related information */
  75. /* ------------------------------------------------------ */
  76. /* Req_1. AvailableRequestFixedIEs */
  77. if (psecnetwork != NULL) {
  78. pAssocInfo->AvailableRequestFixedIEs |= NDIS_802_11_AI_REQFI_CAPABILITIES | NDIS_802_11_AI_REQFI_CURRENTAPADDRESS;
  79. pAssocInfo->RequestFixedIEs.Capabilities = (unsigned short) *&psecnetwork->IEs[10];
  80. _rtw_memcpy(pAssocInfo->RequestFixedIEs.CurrentAPAddress,
  81. &psecnetwork->MacAddress, 6);
  82. pAssocInfo->OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  83. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING | _FW_LINKED) == _TRUE) {
  84. if (psecuritypriv->ndisauthtype >= Ndis802_11AuthModeWPA2)
  85. pDest[0] = 48; /* RSN Information Element */
  86. else
  87. pDest[0] = 221; /* WPA(SSN) Information Element */
  88. supp_ie = &psecuritypriv->supplicant_ie[0];
  89. i = 13; /* 0~11 is fixed information element */
  90. while ((i < supp_ie[0]) && (i < 256)) {
  91. if ((unsigned char)supp_ie[i] == pDest[0]) {
  92. _rtw_memcpy((u8 *)(pDest),
  93. &supp_ie[i],
  94. supp_ie[1 + i] + 2);
  95. break;
  96. }
  97. i = i + supp_ie[i + 1] + 2;
  98. if (supp_ie[1 + i] == 0)
  99. i = i + 1;
  100. }
  101. pAssocInfo->RequestIELength += (2 + supp_ie[1 + i]); /* (2 + psecnetwork->IEs[1+i]+4); */
  102. }
  103. }
  104. /* ------------------------------------------------------ */
  105. /* Association Response related information */
  106. /* ------------------------------------------------------ */
  107. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  108. tgt_network = &(pmlmepriv->cur_network);
  109. if (tgt_network != NULL) {
  110. pAssocInfo->AvailableResponseFixedIEs =
  111. NDIS_802_11_AI_RESFI_CAPABILITIES
  112. | NDIS_802_11_AI_RESFI_ASSOCIATIONID
  113. ;
  114. pAssocInfo->ResponseFixedIEs.Capabilities = (unsigned short) *&tgt_network->network.IEs[10];
  115. pAssocInfo->ResponseFixedIEs.StatusCode = 0;
  116. pAssocInfo->ResponseFixedIEs.AssociationId = (unsigned short) tgt_network->aid;
  117. pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAssocInfo->RequestIELength;
  118. auth_ie = &psecuritypriv->authenticator_ie[0];
  119. i = auth_ie[0] - 12;
  120. if (i > 0) {
  121. _rtw_memcpy((u8 *)&pDest[0], &auth_ie[1], i);
  122. pAssocInfo->ResponseIELength = i;
  123. }
  124. pAssocInfo->OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAssocInfo->RequestIELength;
  125. }
  126. }
  127. return _TRUE;
  128. }
  129. #endif