blob: b4a099169c7c8d1ac4cee68533aa2637cc5e649f [file] [log] [blame]
Michael Straubee24c1f82018-10-03 16:17:16 +02001// SPDX-License-Identifier: GPL-2.0
Larry Finger2865d42c2010-08-20 10:15:30 -05002/******************************************************************************
3 * ieee80211.c
4 *
5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6 * Linux device driver for RTL8192SU
7 *
Larry Finger2865d42c2010-08-20 10:15:30 -05008 * Modifications for inclusion into the Linux staging tree are
9 * Copyright(c) 2010 Larry Finger. All rights reserved.
10 *
11 * Contact information:
12 * WLAN FAE <wlanfae@realtek.com>.
13 * Larry Finger <Larry.Finger@lwfinger.net>
14 *
15 ******************************************************************************/
16
17#define _IEEE80211_C
18
19#include "drv_types.h"
20#include "ieee80211.h"
21#include "wifi.h"
22#include "osdep_service.h"
23#include "wlan_bssdef.h"
24
25static const u8 WPA_OUI_TYPE[] = {0x00, 0x50, 0xf2, 1};
26static const u8 WPA_CIPHER_SUITE_NONE[] = {0x00, 0x50, 0xf2, 0};
27static const u8 WPA_CIPHER_SUITE_WEP40[] = {0x00, 0x50, 0xf2, 1};
28static const u8 WPA_CIPHER_SUITE_TKIP[] = {0x00, 0x50, 0xf2, 2};
29static const u8 WPA_CIPHER_SUITE_CCMP[] = {0x00, 0x50, 0xf2, 4};
30static const u8 WPA_CIPHER_SUITE_WEP104[] = {0x00, 0x50, 0xf2, 5};
31
32static const u8 RSN_CIPHER_SUITE_NONE[] = {0x00, 0x0f, 0xac, 0};
33static const u8 RSN_CIPHER_SUITE_WEP40[] = {0x00, 0x0f, 0xac, 1};
34static const u8 RSN_CIPHER_SUITE_TKIP[] = {0x00, 0x0f, 0xac, 2};
35static const u8 RSN_CIPHER_SUITE_CCMP[] = {0x00, 0x0f, 0xac, 4};
36static const u8 RSN_CIPHER_SUITE_WEP104[] = {0x00, 0x0f, 0xac, 5};
37
38/*-----------------------------------------------------------
39 * for adhoc-master to generate ie and provide supported-rate to fw
40 *-----------------------------------------------------------
41 */
42
43static u8 WIFI_CCKRATES[] = {
44 (IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),
45 (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),
46 (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),
47 (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)
48};
49
50static u8 WIFI_OFDMRATES[] = {
51 (IEEE80211_OFDM_RATE_6MB),
52 (IEEE80211_OFDM_RATE_9MB),
53 (IEEE80211_OFDM_RATE_12MB),
54 (IEEE80211_OFDM_RATE_18MB),
55 (IEEE80211_OFDM_RATE_24MB),
56 (IEEE80211_OFDM_RATE_36MB),
57 (IEEE80211_OFDM_RATE_48MB),
58 (IEEE80211_OFDM_RATE_54MB)
59};
60
61uint r8712_is_cckrates_included(u8 *rate)
62{
63 u32 i = 0;
64
65 while (rate[i] != 0) {
66 if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
67 (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
68 return true;
Dan Carpenter879cb0c2014-03-05 14:26:50 +030069 i++;
70 }
71 return false;
Larry Finger2865d42c2010-08-20 10:15:30 -050072}
73
74uint r8712_is_cckratesonly_included(u8 *rate)
75{
76 u32 i = 0;
77
78 while (rate[i] != 0) {
79 if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
80 (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
81 return false;
82 i++;
83 }
84 return true;
85}
86
87/* r8712_set_ie will update frame length */
88u8 *r8712_set_ie(u8 *pbuf, sint index, uint len, u8 *source, uint *frlen)
89{
90 *pbuf = (u8)index;
91 *(pbuf + 1) = (u8)len;
92 if (len > 0)
93 memcpy((void *)(pbuf + 2), (void *)source, len);
94 *frlen = *frlen + (len + 2);
95 return pbuf + len + 2;
96}
97
Punit Vara4fd8cba2015-10-08 01:25:15 +053098/* ---------------------------------------------------------------------------
99 * index: the information element id index, limit is the limit for search
100 * ---------------------------------------------------------------------------
101 */
Stefano Manni74f15052018-02-18 20:52:12 +0100102u8 *r8712_get_ie(u8 *pbuf, sint index, uint *len, sint limit)
Larry Finger2865d42c2010-08-20 10:15:30 -0500103{
104 sint tmp, i;
105 u8 *p;
106
107 if (limit < 1)
108 return NULL;
109 p = pbuf;
110 i = 0;
111 *len = 0;
112 while (1) {
113 if (*p == index) {
114 *len = *(p + 1);
115 return p;
Larry Finger2865d42c2010-08-20 10:15:30 -0500116 }
Nitin Kuppelure92c3512014-10-01 17:04:27 +0200117 tmp = *(p + 1);
118 p += (tmp + 2);
119 i += (tmp + 2);
Larry Finger2865d42c2010-08-20 10:15:30 -0500120 if (i >= limit)
121 break;
122 }
123 return NULL;
124}
125
Joshua Clayton7fb539e2015-08-05 17:17:21 -0700126static void set_supported_rate(u8 *rates, uint mode)
Larry Finger2865d42c2010-08-20 10:15:30 -0500127{
Joshua Clayton7fb539e2015-08-05 17:17:21 -0700128 memset(rates, 0, NDIS_802_11_LENGTH_RATES_EX);
Larry Finger2865d42c2010-08-20 10:15:30 -0500129 switch (mode) {
130 case WIRELESS_11B:
Joshua Clayton7fb539e2015-08-05 17:17:21 -0700131 memcpy(rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
Larry Finger2865d42c2010-08-20 10:15:30 -0500132 break;
133 case WIRELESS_11G:
134 case WIRELESS_11A:
Joshua Clayton7fb539e2015-08-05 17:17:21 -0700135 memcpy(rates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
Larry Finger2865d42c2010-08-20 10:15:30 -0500136 break;
137 case WIRELESS_11BG:
Joshua Clayton7fb539e2015-08-05 17:17:21 -0700138 memcpy(rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
139 memcpy(rates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES,
Parth Saned25f6582016-06-08 16:57:45 +0530140 IEEE80211_NUM_OFDM_RATESLEN);
Larry Finger2865d42c2010-08-20 10:15:30 -0500141 break;
142 }
143}
144
145static uint r8712_get_rateset_len(u8 *rateset)
146{
147 uint i = 0;
148
149 while (1) {
150 if ((rateset[i]) == 0)
151 break;
152 if (i > 12)
153 break;
154 i++;
155 }
156 return i;
157}
158
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530159int r8712_generate_ie(struct registry_priv *registrypriv)
Larry Finger2865d42c2010-08-20 10:15:30 -0500160{
Stefano Mannifd161c62018-02-18 20:52:13 +0100161 int rate_len;
162 uint sz = 0;
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530163 struct wlan_bssid_ex *dev_network = &registrypriv->dev_network;
164 u8 *ie = dev_network->IEs;
165 u16 beaconPeriod = (u16)dev_network->Configuration.BeaconPeriod;
Larry Finger2865d42c2010-08-20 10:15:30 -0500166
167 /*timestamp will be inserted by hardware*/
168 sz += 8;
169 ie += sz;
170 /*beacon interval : 2bytes*/
Martin Homuth3be4fdf2017-12-19 00:18:43 +0100171 *(__le16 *)ie = cpu_to_le16(beaconPeriod);
Larry Finger2865d42c2010-08-20 10:15:30 -0500172 sz += 2;
173 ie += 2;
174 /*capability info*/
175 *(u16 *)ie = 0;
Jannik Becher56384ad2016-12-20 18:59:48 +0100176 *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530177 if (registrypriv->preamble == PREAMBLE_SHORT)
Jannik Becher56384ad2016-12-20 18:59:48 +0100178 *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530179 if (dev_network->Privacy)
Jannik Becher56384ad2016-12-20 18:59:48 +0100180 *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
Larry Finger2865d42c2010-08-20 10:15:30 -0500181 sz += 2;
182 ie += 2;
183 /*SSID*/
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530184 ie = r8712_set_ie(ie, _SSID_IE_, dev_network->Ssid.SsidLength,
185 dev_network->Ssid.Ssid, &sz);
Larry Finger2865d42c2010-08-20 10:15:30 -0500186 /*supported rates*/
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530187 set_supported_rate(dev_network->rates, registrypriv->wireless_mode);
188 rate_len = r8712_get_rateset_len(dev_network->rates);
Jaya Durga92abe422017-05-07 23:10:14 +0530189 if (rate_len > 8) {
Larry Finger2865d42c2010-08-20 10:15:30 -0500190 ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, 8,
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530191 dev_network->rates, &sz);
Jaya Durga92abe422017-05-07 23:10:14 +0530192 ie = r8712_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8),
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530193 (dev_network->rates + 8), &sz);
Jaya Durga3bca7cf2017-05-05 10:11:54 +0530194 } else {
Larry Finger2865d42c2010-08-20 10:15:30 -0500195 ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_,
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530196 rate_len, dev_network->rates, &sz);
Jaya Durga3bca7cf2017-05-05 10:11:54 +0530197 }
Larry Finger2865d42c2010-08-20 10:15:30 -0500198 /*DS parameter set*/
199 ie = r8712_set_ie(ie, _DSSET_IE_, 1,
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530200 (u8 *)&dev_network->Configuration.DSConfig, &sz);
Larry Finger2865d42c2010-08-20 10:15:30 -0500201 /*IBSS Parameter Set*/
202 ie = r8712_set_ie(ie, _IBSS_PARA_IE_, 2,
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530203 (u8 *)&dev_network->Configuration.ATIMWindow, &sz);
Larry Finger2865d42c2010-08-20 10:15:30 -0500204 return sz;
205}
206
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530207unsigned char *r8712_get_wpa_ie(unsigned char *ie, uint *wpa_ie_len, int limit)
Larry Finger2865d42c2010-08-20 10:15:30 -0500208{
Stefano Manni74f15052018-02-18 20:52:12 +0100209 u32 len;
Larry Finger2865d42c2010-08-20 10:15:30 -0500210 u16 val16;
211 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530212 u8 *buf = ie;
Larry Finger2865d42c2010-08-20 10:15:30 -0500213
214 while (1) {
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530215 buf = r8712_get_ie(buf, _WPA_IE_ID_, &len, limit);
216 if (buf) {
Larry Finger2865d42c2010-08-20 10:15:30 -0500217 /*check if oui matches...*/
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530218 if (memcmp((buf + 2), wpa_oui_type,
Martin Homuth3be4fdf2017-12-19 00:18:43 +0100219 sizeof(wpa_oui_type)))
Larry Finger2865d42c2010-08-20 10:15:30 -0500220 goto check_next_ie;
221 /*check version...*/
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530222 memcpy((u8 *)&val16, (buf + 6), sizeof(val16));
Jannik Becher56384ad2016-12-20 18:59:48 +0100223 le16_to_cpus(&val16);
Larry Finger2865d42c2010-08-20 10:15:30 -0500224 if (val16 != 0x0001)
225 goto check_next_ie;
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530226 *wpa_ie_len = *(buf + 1);
227 return buf;
Larry Finger2865d42c2010-08-20 10:15:30 -0500228 }
Nitin Kuppelure92c3512014-10-01 17:04:27 +0200229 *wpa_ie_len = 0;
230 return NULL;
Larry Finger2865d42c2010-08-20 10:15:30 -0500231check_next_ie:
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530232 limit = limit - (buf - ie) - 2 - len;
Larry Finger2865d42c2010-08-20 10:15:30 -0500233 if (limit <= 0)
234 break;
Nishka Dasgupta7ec3ff62019-05-31 02:33:59 +0530235 buf += (2 + len);
Larry Finger2865d42c2010-08-20 10:15:30 -0500236 }
237 *wpa_ie_len = 0;
238 return NULL;
239}
240
Bhagyashri Digholea77a40c2019-03-12 12:46:55 +0530241unsigned char *r8712_get_wpa2_ie(unsigned char *pie, uint *rsn_ie_len,
242 int limit)
Larry Finger2865d42c2010-08-20 10:15:30 -0500243{
244 return r8712_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
245}
246
247static int r8712_get_wpa_cipher_suite(u8 *s)
248{
249 if (!memcmp(s, (void *)WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
250 return WPA_CIPHER_NONE;
251 if (!memcmp(s, (void *)WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
252 return WPA_CIPHER_WEP40;
253 if (!memcmp(s, (void *)WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
254 return WPA_CIPHER_TKIP;
255 if (!memcmp(s, (void *)WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
256 return WPA_CIPHER_CCMP;
257 if (!memcmp(s, (void *)WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
258 return WPA_CIPHER_WEP104;
259 return 0;
260}
261
262static int r8712_get_wpa2_cipher_suite(u8 *s)
263{
264 if (!memcmp(s, (void *)RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
265 return WPA_CIPHER_NONE;
266 if (!memcmp(s, (void *)RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
267 return WPA_CIPHER_WEP40;
268 if (!memcmp(s, (void *)RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
269 return WPA_CIPHER_TKIP;
270 if (!memcmp(s, (void *)RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
271 return WPA_CIPHER_CCMP;
272 if (!memcmp(s, (void *)RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
273 return WPA_CIPHER_WEP104;
274 return 0;
275}
276
277int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
Parth Saned25f6582016-06-08 16:57:45 +0530278 int *pairwise_cipher)
Larry Finger2865d42c2010-08-20 10:15:30 -0500279{
Peter Senna Tschudin8ffca9e2014-05-20 12:33:41 +0200280 int i;
Larry Finger2865d42c2010-08-20 10:15:30 -0500281 int left, count;
282 u8 *pos;
283
284 if (wpa_ie_len <= 0) {
285 /* No WPA IE - fail silently */
Nishka Dasgupta1ef20d52019-06-26 11:39:34 +0530286 return -EINVAL;
Larry Finger2865d42c2010-08-20 10:15:30 -0500287 }
Varsha Rao95ee7062017-02-17 10:42:38 +0530288 if ((*wpa_ie != _WPA_IE_ID_) ||
289 (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
290 (memcmp(wpa_ie + 2, (void *)WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
Nishka Dasgupta1ef20d52019-06-26 11:39:34 +0530291 return -EINVAL;
Larry Finger2865d42c2010-08-20 10:15:30 -0500292 pos = wpa_ie;
293 pos += 8;
294 left = wpa_ie_len - 8;
295 /*group_cipher*/
296 if (left >= WPA_SELECTOR_LEN) {
297 *group_cipher = r8712_get_wpa_cipher_suite(pos);
298 pos += WPA_SELECTOR_LEN;
299 left -= WPA_SELECTOR_LEN;
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100300 } else if (left > 0) {
Nishka Dasgupta1ef20d52019-06-26 11:39:34 +0530301 return -EINVAL;
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100302 }
Larry Finger2865d42c2010-08-20 10:15:30 -0500303 /*pairwise_cipher*/
304 if (left >= 2) {
Jannik Becher56384ad2016-12-20 18:59:48 +0100305 count = le16_to_cpu(*(__le16 *)pos);
Larry Finger2865d42c2010-08-20 10:15:30 -0500306 pos += 2;
307 left -= 2;
308 if (count == 0 || left < count * WPA_SELECTOR_LEN)
Nishka Dasgupta1ef20d52019-06-26 11:39:34 +0530309 return -EINVAL;
Larry Finger2865d42c2010-08-20 10:15:30 -0500310 for (i = 0; i < count; i++) {
311 *pairwise_cipher |= r8712_get_wpa_cipher_suite(pos);
312 pos += WPA_SELECTOR_LEN;
313 left -= WPA_SELECTOR_LEN;
314 }
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100315 } else if (left == 1) {
Nishka Dasgupta1ef20d52019-06-26 11:39:34 +0530316 return -EINVAL;
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100317 }
Nishka Dasgupta1ef20d52019-06-26 11:39:34 +0530318 return 0;
Larry Finger2865d42c2010-08-20 10:15:30 -0500319}
320
321int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
Parth Saned25f6582016-06-08 16:57:45 +0530322 int *pairwise_cipher)
Larry Finger2865d42c2010-08-20 10:15:30 -0500323{
Peter Senna Tschudin8ffca9e2014-05-20 12:33:41 +0200324 int i;
Larry Finger2865d42c2010-08-20 10:15:30 -0500325 int left, count;
326 u8 *pos;
327
328 if (rsn_ie_len <= 0) {
329 /* No RSN IE - fail silently */
Nishka Dasguptaf5e5eaef2019-06-26 11:39:35 +0530330 return -EINVAL;
Larry Finger2865d42c2010-08-20 10:15:30 -0500331 }
Luis de Bethencourt4ef2de52015-10-19 18:16:01 +0100332 if ((*rsn_ie != _WPA2_IE_ID_) ||
333 (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
Nishka Dasguptaf5e5eaef2019-06-26 11:39:35 +0530334 return -EINVAL;
Larry Finger2865d42c2010-08-20 10:15:30 -0500335 pos = rsn_ie;
336 pos += 4;
337 left = rsn_ie_len - 4;
338 /*group_cipher*/
339 if (left >= RSN_SELECTOR_LEN) {
340 *group_cipher = r8712_get_wpa2_cipher_suite(pos);
341 pos += RSN_SELECTOR_LEN;
342 left -= RSN_SELECTOR_LEN;
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100343 } else if (left > 0) {
Nishka Dasguptaf5e5eaef2019-06-26 11:39:35 +0530344 return -EINVAL;
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100345 }
Larry Finger2865d42c2010-08-20 10:15:30 -0500346 /*pairwise_cipher*/
347 if (left >= 2) {
Jannik Becher56384ad2016-12-20 18:59:48 +0100348 count = le16_to_cpu(*(__le16 *)pos);
Larry Finger2865d42c2010-08-20 10:15:30 -0500349 pos += 2;
350 left -= 2;
351 if (count == 0 || left < count * RSN_SELECTOR_LEN)
Nishka Dasguptaf5e5eaef2019-06-26 11:39:35 +0530352 return -EINVAL;
Larry Finger2865d42c2010-08-20 10:15:30 -0500353 for (i = 0; i < count; i++) {
354 *pairwise_cipher |= r8712_get_wpa2_cipher_suite(pos);
355 pos += RSN_SELECTOR_LEN;
356 left -= RSN_SELECTOR_LEN;
357 }
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100358 } else if (left == 1) {
Nishka Dasguptaf5e5eaef2019-06-26 11:39:35 +0530359 return -EINVAL;
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100360 }
Nishka Dasguptaf5e5eaef2019-06-26 11:39:35 +0530361 return 0;
Larry Finger2865d42c2010-08-20 10:15:30 -0500362}
363
364int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
Parth Saned25f6582016-06-08 16:57:45 +0530365 u8 *wpa_ie, u16 *wpa_len)
Larry Finger2865d42c2010-08-20 10:15:30 -0500366{
Sudip Mukherjeee29d3eb2014-10-27 17:42:25 +0530367 u8 authmode;
Larry Finger2865d42c2010-08-20 10:15:30 -0500368 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
369 uint cnt;
370
371 /*Search required WPA or WPA2 IE and copy to sec_ie[ ]*/
Bhaktipriya Shridharbb106dc2016-02-22 22:39:00 +0530372 cnt = _TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_;
Larry Finger2865d42c2010-08-20 10:15:30 -0500373 while (cnt < in_len) {
374 authmode = in_ie[cnt];
375 if ((authmode == _WPA_IE_ID_) &&
376 (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
377 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
Luis de Bethencourt4ef2de52015-10-19 18:16:01 +0100378 *wpa_len = in_ie[cnt + 1] + 2;
Larry Finger2865d42c2010-08-20 10:15:30 -0500379 cnt += in_ie[cnt + 1] + 2; /*get next */
380 } else {
381 if (authmode == _WPA2_IE_ID_) {
382 memcpy(rsn_ie, &in_ie[cnt],
Parth Saned25f6582016-06-08 16:57:45 +0530383 in_ie[cnt + 1] + 2);
Luis de Bethencourt4ef2de52015-10-19 18:16:01 +0100384 *rsn_len = in_ie[cnt + 1] + 2;
385 cnt += in_ie[cnt + 1] + 2; /*get next*/
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100386 } else {
Luis de Bethencourt4ef2de52015-10-19 18:16:01 +0100387 cnt += in_ie[cnt + 1] + 2; /*get next*/
Luis de Bethencourt168a2c12015-10-19 18:15:29 +0100388 }
Larry Finger2865d42c2010-08-20 10:15:30 -0500389 }
390 }
391 return *rsn_len + *wpa_len;
392}
393
394int r8712_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
395{
396 int match;
397 uint cnt;
398 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
399
400 cnt = 12;
401 match = false;
402 while (cnt < in_len) {
403 eid = in_ie[cnt];
404 if ((eid == _WPA_IE_ID_) &&
Luis de Bethencourt4ef2de52015-10-19 18:16:01 +0100405 (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) {
406 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
407 *wps_ielen = in_ie[cnt + 1] + 2;
408 cnt += in_ie[cnt + 1] + 2;
Larry Finger2865d42c2010-08-20 10:15:30 -0500409 match = true;
410 break;
Nitin Kuppelure92c3512014-10-01 17:04:27 +0200411 }
Colin Ian King41be1dc2019-01-07 23:11:30 +0000412 cnt += in_ie[cnt + 1] + 2; /* goto next */
Larry Finger2865d42c2010-08-20 10:15:30 -0500413 }
414 return match;
415}