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