wifi: renew patch drivers/net/wireless
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rtl8723au / core / rtw_ioctl_query.c
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
22 #include <drv_conf.h>
23 #include <osdep_service.h>
24 #include <drv_types.h>
25 #include <rtw_ioctl_query.h>
26 #include <wifi.h>
27
28
29 #ifdef PLATFORM_WINDOWS
30 //
31 // Added for WPA2-PSK, by Annie, 2005-09-20.
32 //
33 u8
34 query_802_11_capability(
35         _adapter*               Adapter,
36         u8*                     pucBuf,
37         u32 *           pulOutLen
38 )
39 {
40         static NDIS_802_11_AUTHENTICATION_ENCRYPTION szAuthEnc[] = 
41         {
42                 {Ndis802_11AuthModeOpen, Ndis802_11EncryptionDisabled}, 
43                 {Ndis802_11AuthModeOpen, Ndis802_11Encryption1Enabled},
44                 {Ndis802_11AuthModeShared, Ndis802_11EncryptionDisabled}, 
45                 {Ndis802_11AuthModeShared, Ndis802_11Encryption1Enabled},
46                 {Ndis802_11AuthModeWPA, Ndis802_11Encryption2Enabled}, 
47                 {Ndis802_11AuthModeWPA, Ndis802_11Encryption3Enabled},
48                 {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption2Enabled}, 
49                 {Ndis802_11AuthModeWPAPSK, Ndis802_11Encryption3Enabled},
50                 {Ndis802_11AuthModeWPANone, Ndis802_11Encryption2Enabled}, 
51                 {Ndis802_11AuthModeWPANone, Ndis802_11Encryption3Enabled},
52                 {Ndis802_11AuthModeWPA2, Ndis802_11Encryption2Enabled}, 
53                 {Ndis802_11AuthModeWPA2, Ndis802_11Encryption3Enabled},
54                 {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption2Enabled}, 
55                 {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption3Enabled}
56         };      
57         static ULONG    ulNumOfPairSupported = sizeof(szAuthEnc)/sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
58         NDIS_802_11_CAPABILITY * pCap = (NDIS_802_11_CAPABILITY *)pucBuf;
59         u8*     pucAuthEncryptionSupported = (u8*) pCap->AuthenticationEncryptionSupported;
60
61
62         pCap->Length = sizeof(NDIS_802_11_CAPABILITY);
63         if(ulNumOfPairSupported > 1 )
64                 pCap->Length +=         (ulNumOfPairSupported-1) * sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION);
65         
66         pCap->Version = 2;      
67         pCap->NoOfPMKIDs = NUM_PMKID_CACHE;     
68         pCap->NoOfAuthEncryptPairsSupported = ulNumOfPairSupported;
69
70         if( sizeof (szAuthEnc) <= 240 )         // 240 = 256 - 4*4      // SecurityInfo.szCapability: only 256 bytes in size.
71         {
72                 _rtw_memcpy( pucAuthEncryptionSupported, (u8*)szAuthEnc,  sizeof (szAuthEnc) );
73                 *pulOutLen = pCap->Length;
74                 return _TRUE;
75         }
76         else
77         {
78                 *pulOutLen = 0;
79                 RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("_query_802_11_capability(): szAuthEnc size is too large.\n"));
80                 return _FALSE;
81         }
82 }
83
84 u8 query_802_11_association_information(        _adapter *padapter,PNDIS_802_11_ASSOCIATION_INFORMATION pAssocInfo)
85 {
86         struct wlan_network *tgt_network;
87         struct  mlme_priv       *pmlmepriv = &(padapter->mlmepriv);
88         struct  security_priv  *psecuritypriv=&(padapter->securitypriv);
89         WLAN_BSSID_EX   *psecnetwork=(WLAN_BSSID_EX*)&(psecuritypriv->sec_bss);                                 
90         u8 *    pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
91         unsigned char i,*auth_ie,*supp_ie;
92
93         //NdisZeroMemory(pAssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
94         _rtw_memset(pAssocInfo, 0, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
95         //pAssocInfo->Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
96
97         //------------------------------------------------------
98         // Association Request related information
99         //------------------------------------------------------
100         // Req_1. AvailableRequestFixedIEs
101         if(psecnetwork!=NULL){
102                 
103         pAssocInfo->AvailableRequestFixedIEs |= NDIS_802_11_AI_REQFI_CAPABILITIES|NDIS_802_11_AI_REQFI_CURRENTAPADDRESS;
104         pAssocInfo->RequestFixedIEs.Capabilities = (unsigned short)* & psecnetwork->IEs[10];
105         _rtw_memcpy(pAssocInfo->RequestFixedIEs.CurrentAPAddress,
106                 & psecnetwork->MacAddress, 6);
107
108         pAssocInfo->OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
109
110         if(check_fwstate( pmlmepriv, _FW_UNDER_LINKING|_FW_LINKED)==_TRUE)
111         {
112                 
113                 if(psecuritypriv->ndisauthtype>=Ndis802_11AuthModeWPA2)
114                         pDest[0] =48;           //RSN Information Element
115                 else 
116                         pDest[0] =221;  //WPA(SSN) Information Element
117                 
118                 RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n Adapter->ndisauthtype==Ndis802_11AuthModeWPA)?0xdd:0x30 [%d]",pDest[0]));
119                 supp_ie=&psecuritypriv->supplicant_ie[0];
120                 for(i=0;i<supp_ie[0];i++)
121                 {
122                         RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("IEs [%d] = 0x%x \n\n", i,supp_ie[i]));
123                 }
124
125                 i=13;   //0~11 is fixed information element             
126                 RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("i= %d tgt_network->network.IELength=%d\n\n", i,(int)psecnetwork->IELength));
127                 while((i<supp_ie[0]) && (i<256)){
128                         if((unsigned char)supp_ie[i]==pDest[0]){
129                                                 _rtw_memcpy((u8 *)(pDest),
130                                                         &supp_ie[i], 
131                                                         supp_ie[1+i]+2);
132                         
133                                 break;
134                         }
135                         
136                         i=i+supp_ie[i+1]+2;
137                         if(supp_ie[1+i]==0)
138                                 i=i+1;
139                         RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("iteration i=%d IEs [%d] = 0x%x \n\n", i,i,supp_ie[i+1]));
140                         
141                 }
142                 
143
144                 pAssocInfo->RequestIELength += (2 + supp_ie[1+i]);// (2 + psecnetwork->IEs[1+i]+4);
145
146         }
147         
148
149                 RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n psecnetwork != NULL,fwstate==_FW_UNDER_LINKING \n"));
150
151         }
152         
153
154         //------------------------------------------------------
155         // Association Response related information
156         //------------------------------------------------------
157
158         if(check_fwstate( pmlmepriv, _FW_LINKED)==_TRUE)
159         {
160                 tgt_network =&(pmlmepriv->cur_network);
161                 if(tgt_network!=NULL){
162                 pAssocInfo->AvailableResponseFixedIEs =
163                                 NDIS_802_11_AI_RESFI_CAPABILITIES
164                                 |NDIS_802_11_AI_RESFI_ASSOCIATIONID
165                                 ;
166
167                 pAssocInfo->ResponseFixedIEs.Capabilities =(unsigned short)* & tgt_network->network.IEs[10];
168                 pAssocInfo->ResponseFixedIEs.StatusCode = 0;
169                 pAssocInfo->ResponseFixedIEs.AssociationId =(unsigned short) tgt_network->aid;
170
171                 pDest = (u8 *)pAssocInfo + sizeof(NDIS_802_11_ASSOCIATION_INFORMATION)+pAssocInfo->RequestIELength;
172                 auth_ie=&psecuritypriv->authenticator_ie[0];
173
174                 for(i=0;i<auth_ie[0];i++)
175                         RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("IEs [%d] = 0x%x \n\n", i,auth_ie[i]));
176
177                 i=auth_ie[0]-12;
178                 if(i>0){
179                         _rtw_memcpy((u8 *)&pDest[0],&auth_ie[1],i);
180                         pAssocInfo->ResponseIELength =i; 
181                 }
182
183
184                 pAssocInfo->OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAssocInfo->RequestIELength;  
185
186
187                 RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n tgt_network != NULL,fwstate==_FW_LINKED \n"));
188                 }
189         }                                                                                                       
190         RT_TRACE(_module_rtl871x_ioctl_query_c_,_drv_info_,("\n exit query_802_11_association_information \n"));
191 _func_exit_;
192
193         return _TRUE;
194 }
195 #endif
196