rtw_ioctl_query.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. {
  35. {Ndis802_11AuthModeOpen, Ndis802_11EncryptionDisabled},
  36. {Ndis802_11AuthModeOpen, Ndis802_11Encryption1Enabled},
  37. {Ndis802_11AuthModeShared, Ndis802_11EncryptionDisabled},
  38. {Ndis802_11AuthModeShared, Ndis802_11Encryption1Enabled},
  39. {Ndis802_11AuthModeWPA, Ndis802_11Encryption2Enabled},
  40. {Ndis802_11AuthModeWPA, Ndis802_11Encryption3Enabled},
  41. {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption2Enabled},
  42. {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption3Enabled},
  43. {Ndis802_11AuthModeWPANone, Ndis802_11Encryption2Enabled},
  44. {Ndis802_11AuthModeWPANone, Ndis802_11Encryption3Enabled},
  45. {Ndis802_11AuthModeWPA2, Ndis802_11Encryption2Enabled},
  46. {Ndis802_11AuthModeWPA2, Ndis802_11Encryption3Enabled},
  47. {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption2Enabled},
  48. {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption3Enabled}
  49. };
  50. static ULONG ulNumOfPairSupported = sizeof(szAuthEnc)/sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
  51. NDIS_802_11_CAPABILITY * pCap = (NDIS_802_11_CAPABILITY *)pucBuf;
  52. u8* pucAuthEncryptionSupported = (u8*) pCap->AuthenticationEncryptionSupported;
  53. pCap->Length = sizeof(NDIS_802_11_CAPABILITY);
  54. if(ulNumOfPairSupported > 1 )
  55. pCap->Length += (ulNumOfPairSupported-1) * sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
  56. pCap->Version = 2;
  57. pCap->NoOfPMKIDs = NUM_PMKID_CACHE;
  58. pCap->NoOfAuthEncryptPairsSupported = ulNumOfPairSupported;
  59. if( sizeof (szAuthEnc) <= 240 ) // 240 = 256 - 4*4 // SecurityInfo.szCapability: only 256 bytes in size.
  60. {
  61. _rtw_memcpy( pucAuthEncryptionSupported, (u8*)szAuthEnc, sizeof (szAuthEnc) );
  62. *pulOutLen = pCap->Length;
  63. return _TRUE;
  64. }
  65. else
  66. {
  67. *pulOutLen = 0;
  68. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("_query_802_11_capability(): szAuthEnc size is too large.\n"));
  69. return _FALSE;
  70. }
  71. }
  72. u8 query_802_11_association_information( _adapter *padapter,PNDIS_802_11_ASSOCIATION_INFORMATION pAssocInfo)
  73. {
  74. struct wlan_network *tgt_network;
  75. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  76. struct security_priv *psecuritypriv=&(padapter->securitypriv);
  77. WLAN_BSSID_EX *psecnetwork=(WLAN_BSSID_EX*)&(psecuritypriv->sec_bss);
  78. u8 * pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  79. unsigned char i,*auth_ie,*supp_ie;
  80. //NdisZeroMemory(pAssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
  81. _rtw_memset(pAssocInfo, 0, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
  82. //pAssocInfo->Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  83. //------------------------------------------------------
  84. // Association Request related information
  85. //------------------------------------------------------
  86. // Req_1. AvailableRequestFixedIEs
  87. if(psecnetwork!=NULL){
  88. pAssocInfo->AvailableRequestFixedIEs |= NDIS_802_11_AI_REQFI_CAPABILITIES|NDIS_802_11_AI_REQFI_CURRENTAPADDRESS;
  89. pAssocInfo->RequestFixedIEs.Capabilities = (unsigned short)* & psecnetwork->IEs[10];
  90. _rtw_memcpy(pAssocInfo->RequestFixedIEs.CurrentAPAddress,
  91. & psecnetwork->MacAddress, 6);
  92. pAssocInfo->OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  93. if(check_fwstate( pmlmepriv, _FW_UNDER_LINKING|_FW_LINKED)==_TRUE)
  94. {
  95. if(psecuritypriv->ndisauthtype>=Ndis802_11AuthModeWPA2)
  96. pDest[0] =48; //RSN Information Element
  97. else
  98. pDest[0] =221; //WPA(SSN) Information Element
  99. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n Adapter->ndisauthtype==Ndis802_11AuthModeWPA)?0xdd:0x30 [%d]",pDest[0]));
  100. supp_ie=&psecuritypriv->supplicant_ie[0];
  101. for(i=0;i<supp_ie[0];i++)
  102. {
  103. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("IEs [%d] = 0x%x \n\n", i,supp_ie[i]));
  104. }
  105. i=13; //0~11 is fixed information element
  106. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("i= %d tgt_network->network.IELength=%d\n\n", i,(int)psecnetwork->IELength));
  107. while((i<supp_ie[0]) && (i<256)){
  108. if((unsigned char)supp_ie[i]==pDest[0]){
  109. _rtw_memcpy((u8 *)(pDest),
  110. &supp_ie[i],
  111. supp_ie[1+i]+2);
  112. break;
  113. }
  114. i=i+supp_ie[i+1]+2;
  115. if(supp_ie[1+i]==0)
  116. i=i+1;
  117. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("iteration i=%d IEs [%d] = 0x%x \n\n", i,i,supp_ie[i+1]));
  118. }
  119. pAssocInfo->RequestIELength += (2 + supp_ie[1+i]);// (2 + psecnetwork->IEs[1+i]+4);
  120. }
  121. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n psecnetwork != NULL,fwstate==_FW_UNDER_LINKING \n"));
  122. }
  123. //------------------------------------------------------
  124. // Association Response related information
  125. //------------------------------------------------------
  126. if(check_fwstate( pmlmepriv, _FW_LINKED)==_TRUE)
  127. {
  128. tgt_network =&(pmlmepriv->cur_network);
  129. if(tgt_network!=NULL){
  130. pAssocInfo->AvailableResponseFixedIEs =
  131. NDIS_802_11_AI_RESFI_CAPABILITIES
  132. |NDIS_802_11_AI_RESFI_ASSOCIATIONID
  133. ;
  134. pAssocInfo->ResponseFixedIEs.Capabilities =(unsigned short)* & tgt_network->network.IEs[10];
  135. pAssocInfo->ResponseFixedIEs.StatusCode = 0;
  136. pAssocInfo->ResponseFixedIEs.AssociationId =(unsigned short) tgt_network->aid;
  137. pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION)+pAssocInfo->RequestIELength;
  138. auth_ie=&psecuritypriv->authenticator_ie[0];
  139. for(i=0;i<auth_ie[0];i++)
  140. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("IEs [%d] = 0x%x \n\n", i,auth_ie[i]));
  141. i=auth_ie[0]-12;
  142. if(i>0){
  143. _rtw_memcpy((u8 *)&pDest[0],&auth_ie[1],i);
  144. pAssocInfo->ResponseIELength =i;
  145. }
  146. pAssocInfo->OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAssocInfo->RequestIELength;
  147. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n tgt_network != NULL,fwstate==_FW_LINKED \n"));
  148. }
  149. }
  150. RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n exit query_802_11_association_information \n"));
  151. _func_exit_;
  152. return _TRUE;
  153. }
  154. #endif