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