.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /****************************************************************************** |
---|
2 | 3 | * ieee80211.c |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. |
---|
5 | 6 | * Linux device driver for RTL8192SU |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify it |
---|
8 | | - * under the terms of version 2 of the GNU General Public License as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
12 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
13 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
14 | | - * more details. |
---|
15 | 7 | * |
---|
16 | 8 | * Modifications for inclusion into the Linux staging tree are |
---|
17 | 9 | * Copyright(c) 2010 Larry Finger. All rights reserved. |
---|
.. | .. |
---|
164 | 156 | return i; |
---|
165 | 157 | } |
---|
166 | 158 | |
---|
167 | | -int r8712_generate_ie(struct registry_priv *pregistrypriv) |
---|
| 159 | +int r8712_generate_ie(struct registry_priv *registrypriv) |
---|
168 | 160 | { |
---|
169 | 161 | int rate_len; |
---|
170 | 162 | uint sz = 0; |
---|
171 | | - struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network; |
---|
172 | | - u8 *ie = pdev_network->IEs; |
---|
173 | | - u16 beaconPeriod = (u16)pdev_network->Configuration.BeaconPeriod; |
---|
| 163 | + struct wlan_bssid_ex *dev_network = ®istrypriv->dev_network; |
---|
| 164 | + u8 *ie = dev_network->IEs; |
---|
| 165 | + u16 beaconPeriod = (u16)dev_network->Configuration.BeaconPeriod; |
---|
174 | 166 | |
---|
175 | 167 | /*timestamp will be inserted by hardware*/ |
---|
176 | 168 | sz += 8; |
---|
.. | .. |
---|
182 | 174 | /*capability info*/ |
---|
183 | 175 | *(u16 *)ie = 0; |
---|
184 | 176 | *(__le16 *)ie |= cpu_to_le16(cap_IBSS); |
---|
185 | | - if (pregistrypriv->preamble == PREAMBLE_SHORT) |
---|
| 177 | + if (registrypriv->preamble == PREAMBLE_SHORT) |
---|
186 | 178 | *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble); |
---|
187 | | - if (pdev_network->Privacy) |
---|
| 179 | + if (dev_network->Privacy) |
---|
188 | 180 | *(__le16 *)ie |= cpu_to_le16(cap_Privacy); |
---|
189 | 181 | sz += 2; |
---|
190 | 182 | ie += 2; |
---|
191 | 183 | /*SSID*/ |
---|
192 | | - ie = r8712_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, |
---|
193 | | - pdev_network->Ssid.Ssid, &sz); |
---|
| 184 | + ie = r8712_set_ie(ie, WLAN_EID_SSID, dev_network->Ssid.SsidLength, |
---|
| 185 | + dev_network->Ssid.Ssid, &sz); |
---|
194 | 186 | /*supported rates*/ |
---|
195 | | - set_supported_rate(pdev_network->rates, pregistrypriv->wireless_mode); |
---|
196 | | - rate_len = r8712_get_rateset_len(pdev_network->rates); |
---|
| 187 | + set_supported_rate(dev_network->rates, registrypriv->wireless_mode); |
---|
| 188 | + rate_len = r8712_get_rateset_len(dev_network->rates); |
---|
197 | 189 | if (rate_len > 8) { |
---|
198 | | - ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, 8, |
---|
199 | | - pdev_network->rates, &sz); |
---|
200 | | - ie = r8712_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), |
---|
201 | | - (pdev_network->rates + 8), &sz); |
---|
| 190 | + ie = r8712_set_ie(ie, WLAN_EID_SUPP_RATES, 8, |
---|
| 191 | + dev_network->rates, &sz); |
---|
| 192 | + ie = r8712_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rate_len - 8), |
---|
| 193 | + (dev_network->rates + 8), &sz); |
---|
202 | 194 | } else { |
---|
203 | | - ie = r8712_set_ie(ie, _SUPPORTEDRATES_IE_, |
---|
204 | | - rate_len, pdev_network->rates, &sz); |
---|
| 195 | + ie = r8712_set_ie(ie, WLAN_EID_SUPP_RATES, |
---|
| 196 | + rate_len, dev_network->rates, &sz); |
---|
205 | 197 | } |
---|
206 | 198 | /*DS parameter set*/ |
---|
207 | | - ie = r8712_set_ie(ie, _DSSET_IE_, 1, |
---|
208 | | - (u8 *)&pdev_network->Configuration.DSConfig, &sz); |
---|
| 199 | + ie = r8712_set_ie(ie, WLAN_EID_DS_PARAMS, 1, |
---|
| 200 | + (u8 *)&dev_network->Configuration.DSConfig, &sz); |
---|
209 | 201 | /*IBSS Parameter Set*/ |
---|
210 | | - ie = r8712_set_ie(ie, _IBSS_PARA_IE_, 2, |
---|
211 | | - (u8 *)&pdev_network->Configuration.ATIMWindow, &sz); |
---|
| 202 | + ie = r8712_set_ie(ie, WLAN_EID_IBSS_PARAMS, 2, |
---|
| 203 | + (u8 *)&dev_network->Configuration.ATIMWindow, &sz); |
---|
212 | 204 | return sz; |
---|
213 | 205 | } |
---|
214 | 206 | |
---|
215 | | -unsigned char *r8712_get_wpa_ie(unsigned char *pie, uint *wpa_ie_len, int limit) |
---|
| 207 | +unsigned char *r8712_get_wpa_ie(unsigned char *ie, uint *wpa_ie_len, int limit) |
---|
216 | 208 | { |
---|
217 | 209 | u32 len; |
---|
218 | 210 | u16 val16; |
---|
219 | 211 | unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01}; |
---|
220 | | - u8 *pbuf = pie; |
---|
| 212 | + u8 *buf = ie; |
---|
221 | 213 | |
---|
222 | 214 | while (1) { |
---|
223 | | - pbuf = r8712_get_ie(pbuf, _WPA_IE_ID_, &len, limit); |
---|
224 | | - if (pbuf) { |
---|
| 215 | + buf = r8712_get_ie(buf, _WPA_IE_ID_, &len, limit); |
---|
| 216 | + if (buf) { |
---|
225 | 217 | /*check if oui matches...*/ |
---|
226 | | - if (memcmp((pbuf + 2), wpa_oui_type, |
---|
| 218 | + if (memcmp((buf + 2), wpa_oui_type, |
---|
227 | 219 | sizeof(wpa_oui_type))) |
---|
228 | 220 | goto check_next_ie; |
---|
229 | 221 | /*check version...*/ |
---|
230 | | - memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16)); |
---|
| 222 | + memcpy((u8 *)&val16, (buf + 6), sizeof(val16)); |
---|
231 | 223 | le16_to_cpus(&val16); |
---|
232 | 224 | if (val16 != 0x0001) |
---|
233 | 225 | goto check_next_ie; |
---|
234 | | - *wpa_ie_len = *(pbuf + 1); |
---|
235 | | - return pbuf; |
---|
| 226 | + *wpa_ie_len = *(buf + 1); |
---|
| 227 | + return buf; |
---|
236 | 228 | } |
---|
237 | 229 | *wpa_ie_len = 0; |
---|
238 | 230 | return NULL; |
---|
239 | 231 | check_next_ie: |
---|
240 | | - limit = limit - (pbuf - pie) - 2 - len; |
---|
| 232 | + limit = limit - (buf - ie) - 2 - len; |
---|
241 | 233 | if (limit <= 0) |
---|
242 | 234 | break; |
---|
243 | | - pbuf += (2 + len); |
---|
| 235 | + buf += (2 + len); |
---|
244 | 236 | } |
---|
245 | 237 | *wpa_ie_len = 0; |
---|
246 | 238 | return NULL; |
---|
247 | 239 | } |
---|
248 | 240 | |
---|
249 | | -unsigned char *r8712_get_wpa2_ie(unsigned char *pie, uint *rsn_ie_len, int limit) |
---|
| 241 | +unsigned char *r8712_get_wpa2_ie(unsigned char *pie, uint *rsn_ie_len, |
---|
| 242 | + int limit) |
---|
250 | 243 | { |
---|
251 | 244 | return r8712_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit); |
---|
252 | 245 | } |
---|
.. | .. |
---|
290 | 283 | |
---|
291 | 284 | if (wpa_ie_len <= 0) { |
---|
292 | 285 | /* No WPA IE - fail silently */ |
---|
293 | | - return _FAIL; |
---|
| 286 | + return -EINVAL; |
---|
294 | 287 | } |
---|
295 | 288 | if ((*wpa_ie != _WPA_IE_ID_) || |
---|
296 | 289 | (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) || |
---|
297 | 290 | (memcmp(wpa_ie + 2, (void *)WPA_OUI_TYPE, WPA_SELECTOR_LEN))) |
---|
298 | | - return _FAIL; |
---|
| 291 | + return -EINVAL; |
---|
299 | 292 | pos = wpa_ie; |
---|
300 | 293 | pos += 8; |
---|
301 | 294 | left = wpa_ie_len - 8; |
---|
.. | .. |
---|
305 | 298 | pos += WPA_SELECTOR_LEN; |
---|
306 | 299 | left -= WPA_SELECTOR_LEN; |
---|
307 | 300 | } else if (left > 0) { |
---|
308 | | - return _FAIL; |
---|
| 301 | + return -EINVAL; |
---|
309 | 302 | } |
---|
310 | 303 | /*pairwise_cipher*/ |
---|
311 | 304 | if (left >= 2) { |
---|
.. | .. |
---|
313 | 306 | pos += 2; |
---|
314 | 307 | left -= 2; |
---|
315 | 308 | if (count == 0 || left < count * WPA_SELECTOR_LEN) |
---|
316 | | - return _FAIL; |
---|
| 309 | + return -EINVAL; |
---|
317 | 310 | for (i = 0; i < count; i++) { |
---|
318 | 311 | *pairwise_cipher |= r8712_get_wpa_cipher_suite(pos); |
---|
319 | 312 | pos += WPA_SELECTOR_LEN; |
---|
320 | 313 | left -= WPA_SELECTOR_LEN; |
---|
321 | 314 | } |
---|
322 | 315 | } else if (left == 1) { |
---|
323 | | - return _FAIL; |
---|
| 316 | + return -EINVAL; |
---|
324 | 317 | } |
---|
325 | | - return _SUCCESS; |
---|
| 318 | + return 0; |
---|
326 | 319 | } |
---|
327 | 320 | |
---|
328 | 321 | int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, |
---|
.. | .. |
---|
334 | 327 | |
---|
335 | 328 | if (rsn_ie_len <= 0) { |
---|
336 | 329 | /* No RSN IE - fail silently */ |
---|
337 | | - return _FAIL; |
---|
| 330 | + return -EINVAL; |
---|
338 | 331 | } |
---|
339 | 332 | if ((*rsn_ie != _WPA2_IE_ID_) || |
---|
340 | 333 | (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2))) |
---|
341 | | - return _FAIL; |
---|
| 334 | + return -EINVAL; |
---|
342 | 335 | pos = rsn_ie; |
---|
343 | 336 | pos += 4; |
---|
344 | 337 | left = rsn_ie_len - 4; |
---|
.. | .. |
---|
348 | 341 | pos += RSN_SELECTOR_LEN; |
---|
349 | 342 | left -= RSN_SELECTOR_LEN; |
---|
350 | 343 | } else if (left > 0) { |
---|
351 | | - return _FAIL; |
---|
| 344 | + return -EINVAL; |
---|
352 | 345 | } |
---|
353 | 346 | /*pairwise_cipher*/ |
---|
354 | 347 | if (left >= 2) { |
---|
.. | .. |
---|
356 | 349 | pos += 2; |
---|
357 | 350 | left -= 2; |
---|
358 | 351 | if (count == 0 || left < count * RSN_SELECTOR_LEN) |
---|
359 | | - return _FAIL; |
---|
| 352 | + return -EINVAL; |
---|
360 | 353 | for (i = 0; i < count; i++) { |
---|
361 | 354 | *pairwise_cipher |= r8712_get_wpa2_cipher_suite(pos); |
---|
362 | 355 | pos += RSN_SELECTOR_LEN; |
---|
363 | 356 | left -= RSN_SELECTOR_LEN; |
---|
364 | 357 | } |
---|
365 | 358 | } else if (left == 1) { |
---|
366 | | - return _FAIL; |
---|
| 359 | + return -EINVAL; |
---|
367 | 360 | } |
---|
368 | | - return _SUCCESS; |
---|
| 361 | + return 0; |
---|
369 | 362 | } |
---|
370 | 363 | |
---|
371 | 364 | int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, |
---|
.. | .. |
---|
416 | 409 | match = true; |
---|
417 | 410 | break; |
---|
418 | 411 | } |
---|
419 | | - cnt += in_ie[cnt + 1] + 2; /* goto next */ |
---|
| 412 | + cnt += in_ie[cnt + 1] + 2; /* goto next */ |
---|
420 | 413 | } |
---|
421 | 414 | return match; |
---|
422 | 415 | } |
---|