Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 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 | ******************************************************************************/ |
| 15 | #define _IEEE80211_C |
| 16 | |
| 17 | #include <drv_types.h> |
| 18 | #include <linux/ieee80211.h> |
| 19 | #include <ieee80211.h> |
| 20 | #include <wifi.h> |
| 21 | #include <osdep_service.h> |
| 22 | #include <wlan_bssdef.h> |
| 23 | |
| 24 | u8 RTW_WPA_OUI23A_TYPE[] = { 0x00, 0x50, 0xf2, 1 }; |
| 25 | u16 RTW_WPA_VERSION23A = 1; |
| 26 | u8 WPA_AUTH_KEY_MGMT_NONE23A[] = { 0x00, 0x50, 0xf2, 0 }; |
| 27 | u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X23A[] = { 0x00, 0x50, 0xf2, 1 }; |
| 28 | u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X23A[] = { 0x00, 0x50, 0xf2, 2 }; |
| 29 | u8 WPA_CIPHER_SUITE_NONE23A[] = { 0x00, 0x50, 0xf2, 0 }; |
| 30 | u8 WPA_CIPHER_SUITE_WEP4023A[] = { 0x00, 0x50, 0xf2, 1 }; |
| 31 | u8 WPA_CIPHER_SUITE_TKIP23A[] = { 0x00, 0x50, 0xf2, 2 }; |
| 32 | u8 WPA_CIPHER_SUITE_WRAP23A[] = { 0x00, 0x50, 0xf2, 3 }; |
| 33 | u8 WPA_CIPHER_SUITE_CCMP23A[] = { 0x00, 0x50, 0xf2, 4 }; |
| 34 | u8 WPA_CIPHER_SUITE_WEP10423A[] = { 0x00, 0x50, 0xf2, 5 }; |
| 35 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 36 | u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X23A[] = { 0x00, 0x0f, 0xac, 1 }; |
| 37 | u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X23A[] = { 0x00, 0x0f, 0xac, 2 }; |
| 38 | u8 RSN_CIPHER_SUITE_NONE23A[] = { 0x00, 0x0f, 0xac, 0 }; |
| 39 | u8 RSN_CIPHER_SUITE_WEP4023A[] = { 0x00, 0x0f, 0xac, 1 }; |
| 40 | u8 RSN_CIPHER_SUITE_TKIP23A[] = { 0x00, 0x0f, 0xac, 2 }; |
| 41 | u8 RSN_CIPHER_SUITE_WRAP23A[] = { 0x00, 0x0f, 0xac, 3 }; |
| 42 | u8 RSN_CIPHER_SUITE_CCMP23A[] = { 0x00, 0x0f, 0xac, 4 }; |
| 43 | u8 RSN_CIPHER_SUITE_WEP10423A[] = { 0x00, 0x0f, 0xac, 5 }; |
| 44 | /* */ |
| 45 | /* for adhoc-master to generate ie and provide supported-rate to fw */ |
| 46 | /* */ |
| 47 | |
Jes Sorensen | ea0c927 | 2014-05-09 15:03:09 +0200 | [diff] [blame] | 48 | static u8 WIFI_CCKRATES[] = { |
| 49 | IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, |
| 50 | IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK, |
| 51 | IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, |
| 52 | IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK |
| 53 | }; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 54 | |
Jes Sorensen | ea0c927 | 2014-05-09 15:03:09 +0200 | [diff] [blame] | 55 | static u8 WIFI_OFDMRATES[] = { |
| 56 | IEEE80211_OFDM_RATE_6MB, |
| 57 | IEEE80211_OFDM_RATE_9MB, |
| 58 | IEEE80211_OFDM_RATE_12MB, |
| 59 | IEEE80211_OFDM_RATE_18MB, |
| 60 | IEEE80211_OFDM_RATE_24MB, |
| 61 | IEEE80211_OFDM_RATE_36MB, |
| 62 | IEEE80211_OFDM_RATE_48MB, |
| 63 | IEEE80211_OFDM_RATE_54MB |
| 64 | }; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 65 | |
| 66 | int rtw_get_bit_value_from_ieee_value23a(u8 val) |
| 67 | { |
| 68 | unsigned char dot11_rate_table[]= |
| 69 | {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0}; |
| 70 | |
| 71 | int i = 0; |
Yeliz Taneroglu | 99ea15d | 2014-10-09 01:22:12 +0300 | [diff] [blame^] | 72 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 73 | while (dot11_rate_table[i] != 0) { |
| 74 | if (dot11_rate_table[i] == val) |
| 75 | return BIT(i); |
| 76 | i++; |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
Jes Sorensen | b34a643 | 2014-05-09 15:03:08 +0200 | [diff] [blame] | 81 | static bool rtw_is_cckrates_included(u8 *rate) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 82 | { |
| 83 | u32 i = 0; |
| 84 | |
Jes Sorensen | ea0c927 | 2014-05-09 15:03:09 +0200 | [diff] [blame] | 85 | while (rate[i]) { |
| 86 | if ((rate[i] & 0x7f) == 2 || (rate[i] & 0x7f) == 4 || |
| 87 | (rate[i] & 0x7f) == 11 || (rate[i] & 0x7f) == 22) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 88 | return true; |
| 89 | i++; |
| 90 | } |
| 91 | |
| 92 | return false; |
| 93 | } |
| 94 | |
Jes Sorensen | b34a643 | 2014-05-09 15:03:08 +0200 | [diff] [blame] | 95 | static bool rtw_is_cckratesonly_included(u8 *rate) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 96 | { |
| 97 | u32 i = 0; |
| 98 | |
Jes Sorensen | ea0c927 | 2014-05-09 15:03:09 +0200 | [diff] [blame] | 99 | while (rate[i]) { |
| 100 | if ((rate[i] & 0x7f) != 2 && (rate[i] & 0x7f) != 4 && |
| 101 | (rate[i] & 0x7f) != 11 && (rate[i] & 0x7f) != 22) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 102 | return false; |
| 103 | |
| 104 | i++; |
| 105 | } |
| 106 | |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | int rtw_check_network_type23a(unsigned char *rate, int ratelen, int channel) |
| 111 | { |
| 112 | if (channel > 14) { |
Jes Sorensen | b34a643 | 2014-05-09 15:03:08 +0200 | [diff] [blame] | 113 | if (rtw_is_cckrates_included(rate)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 114 | return WIRELESS_INVALID; |
| 115 | else |
| 116 | return WIRELESS_11A; |
| 117 | } else { /* could be pure B, pure G, or B/G */ |
Jes Sorensen | b34a643 | 2014-05-09 15:03:08 +0200 | [diff] [blame] | 118 | if (rtw_is_cckratesonly_included(rate)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 119 | return WIRELESS_11B; |
Jes Sorensen | b34a643 | 2014-05-09 15:03:08 +0200 | [diff] [blame] | 120 | else if (rtw_is_cckrates_included(rate)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 121 | return WIRELESS_11BG; |
| 122 | else |
| 123 | return WIRELESS_11G; |
| 124 | } |
| 125 | } |
| 126 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 127 | /* rtw_set_ie23a will update frame length */ |
Jes Sorensen | 7a65382 | 2014-04-15 19:43:23 +0200 | [diff] [blame] | 128 | u8 *rtw_set_ie23a(u8 *pbuf, int index, uint len, const u8 *source, uint *frlen) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 129 | { |
| 130 | |
| 131 | *pbuf = (u8)index; |
| 132 | |
| 133 | *(pbuf + 1) = (u8)len; |
| 134 | |
| 135 | if (len > 0) |
| 136 | memcpy((void *)(pbuf + 2), (void *)source, len); |
| 137 | |
| 138 | *frlen = *frlen + (len + 2); |
| 139 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 140 | return pbuf + len + 2; |
| 141 | } |
| 142 | |
| 143 | inline u8 *rtw_set_ie23a_ch_switch (u8 *buf, u32 *buf_len, u8 ch_switch_mode, |
| 144 | u8 new_ch, u8 ch_switch_cnt) |
| 145 | { |
| 146 | u8 ie_data[3]; |
| 147 | |
| 148 | ie_data[0] = ch_switch_mode; |
| 149 | ie_data[1] = new_ch; |
| 150 | ie_data[2] = ch_switch_cnt; |
| 151 | return rtw_set_ie23a(buf, WLAN_EID_CHANNEL_SWITCH, 3, ie_data, buf_len); |
| 152 | } |
| 153 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 154 | inline u8 hal_ch_offset_to_secondary_ch_offset23a(u8 ch_offset) |
| 155 | { |
Jes Sorensen | bf51cb6 | 2014-06-09 15:16:21 +0200 | [diff] [blame] | 156 | if (ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) |
| 157 | return IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 158 | else if (ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER) |
Jes Sorensen | bf51cb6 | 2014-06-09 15:16:21 +0200 | [diff] [blame] | 159 | return IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 160 | |
Jes Sorensen | bf51cb6 | 2014-06-09 15:16:21 +0200 | [diff] [blame] | 161 | return IEEE80211_HT_PARAM_CHA_SEC_NONE; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | inline u8 *rtw_set_ie23a_secondary_ch_offset(u8 *buf, u32 *buf_len, |
| 165 | u8 secondary_ch_offset) |
| 166 | { |
| 167 | return rtw_set_ie23a(buf, WLAN_EID_SECONDARY_CHANNEL_OFFSET, |
| 168 | 1, &secondary_ch_offset, buf_len); |
| 169 | } |
| 170 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 171 | /*---------------------------------------------------------------------------- |
| 172 | index: the information element id index, limit is the limit for search |
| 173 | -----------------------------------------------------------------------------*/ |
| 174 | u8 *rtw_get_ie23a(u8 *pbuf, int index, int *len, int limit) |
| 175 | { |
| 176 | int tmp, i; |
| 177 | u8 *p; |
| 178 | |
| 179 | if (limit < 1) { |
| 180 | |
| 181 | return NULL; |
| 182 | } |
| 183 | |
| 184 | p = pbuf; |
| 185 | i = 0; |
| 186 | *len = 0; |
| 187 | while (1) { |
| 188 | if (*p == index) { |
| 189 | *len = *(p + 1); |
| 190 | return p; |
| 191 | } else { |
| 192 | tmp = *(p + 1); |
| 193 | p += (tmp + 2); |
| 194 | i += (tmp + 2); |
| 195 | } |
| 196 | if (i >= limit) |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * rtw_get_ie23a_ex - Search specific IE from a series of IEs |
| 205 | * @in_ie: Address of IEs to search |
| 206 | * @in_len: Length limit from in_ie |
| 207 | * @eid: Element ID to match |
| 208 | * @oui: OUI to match |
| 209 | * @oui_len: OUI length |
| 210 | * @ie: If not NULL and the specific IE is found, the IE will be copied |
| 211 | * to the buf starting from the specific IE |
| 212 | * @ielen: If not NULL and the specific IE is found, will set to the length |
| 213 | * of the entire IE |
| 214 | * |
| 215 | * Returns: The address of the specific IE found, or NULL |
| 216 | */ |
| 217 | u8 *rtw_get_ie23a_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, |
| 218 | u8 *ie, uint *ielen) |
| 219 | { |
| 220 | uint cnt; |
| 221 | u8 *target_ie = NULL; |
| 222 | |
| 223 | if (ielen) |
| 224 | *ielen = 0; |
| 225 | |
| 226 | if (!in_ie || in_len <= 0) |
| 227 | return target_ie; |
| 228 | |
| 229 | cnt = 0; |
| 230 | |
| 231 | while (cnt < in_len) { |
| 232 | if (eid == in_ie[cnt] && |
| 233 | (!oui || !memcmp(&in_ie[cnt+2], oui, oui_len))) { |
| 234 | target_ie = &in_ie[cnt]; |
| 235 | |
| 236 | if (ie) |
| 237 | memcpy(ie, &in_ie[cnt], in_ie[cnt+1]+2); |
| 238 | |
| 239 | if (ielen) |
| 240 | *ielen = in_ie[cnt+1]+2; |
| 241 | break; |
| 242 | } else { |
| 243 | cnt += in_ie[cnt + 1] + 2; /* goto next */ |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | return target_ie; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * rtw_ies_remove_ie23a - Find matching IEs and remove |
| 252 | * @ies: Address of IEs to search |
| 253 | * @ies_len: Pointer of length of ies, will update to new length |
Masanari Iida | 808bcb4 | 2014-07-22 23:42:53 +0900 | [diff] [blame] | 254 | * @offset: The offset to start search |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 255 | * @eid: Element ID to match |
| 256 | * @oui: OUI to match |
| 257 | * @oui_len: OUI length |
| 258 | * |
| 259 | * Returns: _SUCCESS: ies is updated, _FAIL: not updated |
| 260 | */ |
| 261 | int rtw_ies_remove_ie23a(u8 *ies, uint *ies_len, uint offset, u8 eid, |
| 262 | u8 *oui, u8 oui_len) |
| 263 | { |
| 264 | int ret = _FAIL; |
| 265 | u8 *target_ie; |
| 266 | u32 target_ielen; |
| 267 | u8 *start; |
| 268 | uint search_len; |
| 269 | |
| 270 | if (!ies || !ies_len || *ies_len <= offset) |
| 271 | goto exit; |
| 272 | |
| 273 | start = ies + offset; |
| 274 | search_len = *ies_len - offset; |
| 275 | |
| 276 | while (1) { |
| 277 | target_ie = rtw_get_ie23a_ex(start, search_len, eid, oui, oui_len, |
| 278 | NULL, &target_ielen); |
| 279 | if (target_ie && target_ielen) { |
| 280 | u8 buf[MAX_IE_SZ] = {0}; |
| 281 | u8 *remain_ies = target_ie + target_ielen; |
| 282 | uint remain_len = search_len - (remain_ies - start); |
| 283 | |
| 284 | memcpy(buf, remain_ies, remain_len); |
| 285 | memcpy(target_ie, buf, remain_len); |
| 286 | *ies_len = *ies_len - target_ielen; |
| 287 | ret = _SUCCESS; |
| 288 | |
| 289 | start = target_ie; |
| 290 | search_len = remain_len; |
| 291 | } else { |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | exit: |
| 296 | return ret; |
| 297 | } |
| 298 | |
Greg Donald | 4e66cf0 | 2014-08-22 10:57:49 -0500 | [diff] [blame] | 299 | void rtw_set_supported_rate23a(u8 *SupportedRates, uint mode) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 300 | { |
| 301 | |
| 302 | |
| 303 | memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX); |
| 304 | |
| 305 | switch (mode) |
| 306 | { |
| 307 | case WIRELESS_11B: |
| 308 | memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN); |
| 309 | break; |
| 310 | |
| 311 | case WIRELESS_11G: |
| 312 | case WIRELESS_11A: |
| 313 | case WIRELESS_11_5N: |
| 314 | case WIRELESS_11A_5N:/* Todo: no basic rate for ofdm ? */ |
| 315 | memcpy(SupportedRates, WIFI_OFDMRATES, |
| 316 | IEEE80211_NUM_OFDM_RATESLEN); |
| 317 | break; |
| 318 | |
| 319 | case WIRELESS_11BG: |
| 320 | case WIRELESS_11G_24N: |
| 321 | case WIRELESS_11_24N: |
| 322 | case WIRELESS_11BG_24N: |
| 323 | memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN); |
| 324 | memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, |
| 325 | IEEE80211_NUM_OFDM_RATESLEN); |
| 326 | break; |
| 327 | } |
| 328 | |
| 329 | } |
| 330 | |
| 331 | uint rtw_get_rateset_len23a(u8 *rateset) |
| 332 | { |
| 333 | uint i = 0; |
| 334 | |
| 335 | while(1) { |
Jes Sorensen | ea0c927 | 2014-05-09 15:03:09 +0200 | [diff] [blame] | 336 | if (rateset[i] == 0) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 337 | break; |
| 338 | |
| 339 | if (i > 12) |
| 340 | break; |
| 341 | |
| 342 | i++; |
| 343 | } |
| 344 | |
| 345 | return i; |
| 346 | } |
| 347 | |
| 348 | int rtw_generate_ie23a(struct registry_priv *pregistrypriv) |
| 349 | { |
| 350 | u8 wireless_mode; |
| 351 | int sz = 0, rateLen; |
| 352 | struct wlan_bssid_ex* pdev_network = &pregistrypriv->dev_network; |
| 353 | u8* ie = pdev_network->IEs; |
Jes Sorensen | a4cf0d6 | 2014-06-24 15:03:28 +0200 | [diff] [blame] | 354 | u16 cap; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 355 | |
Jes Sorensen | a4cf0d6 | 2014-06-24 15:03:28 +0200 | [diff] [blame] | 356 | pdev_network->tsf = 0; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 357 | |
Jes Sorensen | a4cf0d6 | 2014-06-24 15:03:28 +0200 | [diff] [blame] | 358 | cap = WLAN_CAPABILITY_IBSS; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 359 | |
Jes Sorensen | 68e6c79 | 2014-06-24 15:03:29 +0200 | [diff] [blame] | 360 | if (pregistrypriv->preamble == PREAMBLE_SHORT) |
Jes Sorensen | a4cf0d6 | 2014-06-24 15:03:28 +0200 | [diff] [blame] | 361 | cap |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 362 | |
Jes Sorensen | 68e6c79 | 2014-06-24 15:03:29 +0200 | [diff] [blame] | 363 | if (pdev_network->Privacy) |
Jes Sorensen | a4cf0d6 | 2014-06-24 15:03:28 +0200 | [diff] [blame] | 364 | cap |= WLAN_CAPABILITY_PRIVACY; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 365 | |
Jes Sorensen | a4cf0d6 | 2014-06-24 15:03:28 +0200 | [diff] [blame] | 366 | pdev_network->capability = cap; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 367 | |
| 368 | /* SSID */ |
Jes Sorensen | 4323b04 | 2014-04-15 19:43:28 +0200 | [diff] [blame] | 369 | ie = rtw_set_ie23a(ie, WLAN_EID_SSID, pdev_network->Ssid.ssid_len, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 370 | pdev_network->Ssid.ssid, &sz); |
| 371 | |
| 372 | /* supported rates */ |
| 373 | if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) { |
Jes Sorensen | 37cb982 | 2014-05-21 09:37:40 +0200 | [diff] [blame] | 374 | if (pdev_network->DSConfig > 14) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 375 | wireless_mode = WIRELESS_11A_5N; |
| 376 | else |
| 377 | wireless_mode = WIRELESS_11BG_24N; |
| 378 | } else { |
| 379 | wireless_mode = pregistrypriv->wireless_mode; |
| 380 | } |
| 381 | |
| 382 | rtw_set_supported_rate23a(pdev_network->SupportedRates, wireless_mode) ; |
| 383 | |
| 384 | rateLen = rtw_get_rateset_len23a(pdev_network->SupportedRates); |
| 385 | |
| 386 | if (rateLen > 8) { |
Jes Sorensen | 4323b04 | 2014-04-15 19:43:28 +0200 | [diff] [blame] | 387 | ie = rtw_set_ie23a(ie, WLAN_EID_SUPP_RATES, 8, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 388 | pdev_network->SupportedRates, &sz); |
| 389 | /* ie = rtw_set_ie23a(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */ |
| 390 | } else { |
Jes Sorensen | 4323b04 | 2014-04-15 19:43:28 +0200 | [diff] [blame] | 391 | ie = rtw_set_ie23a(ie, WLAN_EID_SUPP_RATES, rateLen, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 392 | pdev_network->SupportedRates, &sz); |
| 393 | } |
| 394 | |
| 395 | /* DS parameter set */ |
Jes Sorensen | 4323b04 | 2014-04-15 19:43:28 +0200 | [diff] [blame] | 396 | ie = rtw_set_ie23a(ie, WLAN_EID_DS_PARAMS, 1, |
Jes Sorensen | 37cb982 | 2014-05-21 09:37:40 +0200 | [diff] [blame] | 397 | (u8 *)&pdev_network->DSConfig, &sz); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 398 | |
| 399 | /* IBSS Parameter Set */ |
| 400 | |
Jes Sorensen | 4323b04 | 2014-04-15 19:43:28 +0200 | [diff] [blame] | 401 | ie = rtw_set_ie23a(ie, WLAN_EID_IBSS_PARAMS, 2, |
Jes Sorensen | 37cb982 | 2014-05-21 09:37:40 +0200 | [diff] [blame] | 402 | (u8 *)&pdev_network->ATIMWindow, &sz); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 403 | |
| 404 | if (rateLen > 8) { |
Jes Sorensen | 4323b04 | 2014-04-15 19:43:28 +0200 | [diff] [blame] | 405 | ie = rtw_set_ie23a(ie, WLAN_EID_EXT_SUPP_RATES, (rateLen - 8), |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 406 | (pdev_network->SupportedRates + 8), &sz); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | |
| 411 | /* return _SUCCESS; */ |
| 412 | |
| 413 | return sz; |
| 414 | } |
| 415 | |
Jes Sorensen | 0cac3f9 | 2014-06-09 15:16:02 +0200 | [diff] [blame] | 416 | static int rtw_get_wpa_cipher_suite(const u8 *s) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 417 | { |
| 418 | if (!memcmp(s, WPA_CIPHER_SUITE_NONE23A, WPA_SELECTOR_LEN)) |
| 419 | return WPA_CIPHER_NONE; |
| 420 | if (!memcmp(s, WPA_CIPHER_SUITE_WEP4023A, WPA_SELECTOR_LEN)) |
| 421 | return WPA_CIPHER_WEP40; |
| 422 | if (!memcmp(s, WPA_CIPHER_SUITE_TKIP23A, WPA_SELECTOR_LEN)) |
| 423 | return WPA_CIPHER_TKIP; |
| 424 | if (!memcmp(s, WPA_CIPHER_SUITE_CCMP23A, WPA_SELECTOR_LEN)) |
| 425 | return WPA_CIPHER_CCMP; |
| 426 | if (!memcmp(s, WPA_CIPHER_SUITE_WEP10423A, WPA_SELECTOR_LEN)) |
| 427 | return WPA_CIPHER_WEP104; |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
Jes Sorensen | 0cac3f9 | 2014-06-09 15:16:02 +0200 | [diff] [blame] | 432 | static int rtw_get_wpa2_cipher_suite(const u8 *s) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 433 | { |
| 434 | if (!memcmp(s, RSN_CIPHER_SUITE_NONE23A, RSN_SELECTOR_LEN)) |
| 435 | return WPA_CIPHER_NONE; |
| 436 | if (!memcmp(s, RSN_CIPHER_SUITE_WEP4023A, RSN_SELECTOR_LEN)) |
| 437 | return WPA_CIPHER_WEP40; |
| 438 | if (!memcmp(s, RSN_CIPHER_SUITE_TKIP23A, RSN_SELECTOR_LEN)) |
| 439 | return WPA_CIPHER_TKIP; |
| 440 | if (!memcmp(s, RSN_CIPHER_SUITE_CCMP23A, RSN_SELECTOR_LEN)) |
| 441 | return WPA_CIPHER_CCMP; |
| 442 | if (!memcmp(s, RSN_CIPHER_SUITE_WEP10423A, RSN_SELECTOR_LEN)) |
| 443 | return WPA_CIPHER_WEP104; |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
Jes Sorensen | 95c4345a | 2014-04-15 19:44:03 +0200 | [diff] [blame] | 448 | int rtw_parse_wpa_ie23a(const u8* wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 449 | { |
| 450 | int i, ret = _SUCCESS; |
| 451 | int left, count; |
Jes Sorensen | 95c4345a | 2014-04-15 19:44:03 +0200 | [diff] [blame] | 452 | const u8 *pos; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 453 | |
| 454 | if (wpa_ie_len <= 0) { |
| 455 | /* No WPA IE - fail silently */ |
| 456 | return _FAIL; |
| 457 | } |
| 458 | |
Jes Sorensen | 1ffc762 | 2014-04-26 18:55:45 +0200 | [diff] [blame] | 459 | if (wpa_ie[1] != (u8)(wpa_ie_len - 2)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 460 | return _FAIL; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 461 | |
| 462 | pos = wpa_ie; |
| 463 | |
| 464 | pos += 8; |
| 465 | left = wpa_ie_len - 8; |
| 466 | |
| 467 | /* group_cipher */ |
| 468 | if (left >= WPA_SELECTOR_LEN) { |
| 469 | |
Jes Sorensen | 0cac3f9 | 2014-06-09 15:16:02 +0200 | [diff] [blame] | 470 | *group_cipher = rtw_get_wpa_cipher_suite(pos); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 471 | |
| 472 | pos += WPA_SELECTOR_LEN; |
| 473 | left -= WPA_SELECTOR_LEN; |
| 474 | } else if (left > 0) { |
| 475 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, |
| 476 | ("%s: ie length mismatch, %u too much", |
| 477 | __func__, left)); |
| 478 | |
| 479 | return _FAIL; |
| 480 | } |
| 481 | |
| 482 | /* pairwise_cipher */ |
| 483 | if (left >= 2) { |
| 484 | /* count = le16_to_cpu(*(u16*)pos); */ |
Larry Finger | c17416e | 2014-03-28 21:37:42 -0500 | [diff] [blame] | 485 | count = get_unaligned_le16(pos); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 486 | pos += 2; |
| 487 | left -= 2; |
| 488 | |
| 489 | if (count == 0 || left < count * WPA_SELECTOR_LEN) { |
| 490 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, |
| 491 | ("%s: ie count botch (pairwise), " |
| 492 | "count %u left %u", __func__, |
| 493 | count, left)); |
| 494 | return _FAIL; |
| 495 | } |
| 496 | |
| 497 | for (i = 0; i < count; i++) { |
Jes Sorensen | 0cac3f9 | 2014-06-09 15:16:02 +0200 | [diff] [blame] | 498 | *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 499 | |
| 500 | pos += WPA_SELECTOR_LEN; |
| 501 | left -= WPA_SELECTOR_LEN; |
| 502 | } |
| 503 | } else if (left == 1) { |
| 504 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, |
| 505 | ("%s: ie too short (for key mgmt)", __func__)); |
| 506 | return _FAIL; |
| 507 | } |
| 508 | |
| 509 | if (is_8021x) { |
| 510 | if (left >= 6) { |
| 511 | pos += 2; |
Jes Sorensen | 7964eba0 | 2014-04-15 19:44:11 +0200 | [diff] [blame] | 512 | if (!memcmp(pos, RTW_WPA_OUI23A_TYPE, 4)) { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 513 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
| 514 | ("%s : there has 802.1x auth\n", |
| 515 | __func__)); |
| 516 | *is_8021x = 1; |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | return ret; |
| 522 | } |
| 523 | |
Greg Donald | 4e66cf0 | 2014-08-22 10:57:49 -0500 | [diff] [blame] | 524 | int rtw_parse_wpa2_ie23a(const u8 *rsn_ie, int rsn_ie_len, int *group_cipher, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 525 | int *pairwise_cipher, int *is_8021x) |
| 526 | { |
| 527 | int i, ret = _SUCCESS; |
| 528 | int left, count; |
Jes Sorensen | 95c4345a | 2014-04-15 19:44:03 +0200 | [diff] [blame] | 529 | const u8 *pos; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 530 | u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01}; |
| 531 | |
| 532 | if (rsn_ie_len <= 0) { |
| 533 | /* No RSN IE - fail silently */ |
| 534 | return _FAIL; |
| 535 | } |
| 536 | |
Jes Sorensen | a131aac | 2014-06-21 16:50:15 +0200 | [diff] [blame] | 537 | if (*rsn_ie != WLAN_EID_RSN || *(rsn_ie+1) != (u8)(rsn_ie_len - 2)) { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 538 | return _FAIL; |
| 539 | } |
| 540 | |
| 541 | pos = rsn_ie; |
| 542 | pos += 4; |
| 543 | left = rsn_ie_len - 4; |
| 544 | |
| 545 | /* group_cipher */ |
| 546 | if (left >= RSN_SELECTOR_LEN) { |
Jes Sorensen | 0cac3f9 | 2014-06-09 15:16:02 +0200 | [diff] [blame] | 547 | *group_cipher = rtw_get_wpa2_cipher_suite(pos); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 548 | |
| 549 | pos += RSN_SELECTOR_LEN; |
| 550 | left -= RSN_SELECTOR_LEN; |
| 551 | } else if (left > 0) { |
| 552 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, |
| 553 | ("%s: ie length mismatch, %u too much", |
| 554 | __func__, left)); |
| 555 | return _FAIL; |
| 556 | } |
| 557 | |
| 558 | /* pairwise_cipher */ |
| 559 | if (left >= 2) { |
| 560 | /* count = le16_to_cpu(*(u16*)pos); */ |
Larry Finger | c17416e | 2014-03-28 21:37:42 -0500 | [diff] [blame] | 561 | count = get_unaligned_le16(pos); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 562 | pos += 2; |
| 563 | left -= 2; |
| 564 | |
| 565 | if (count == 0 || left < count * RSN_SELECTOR_LEN) { |
| 566 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, |
| 567 | ("%s: ie count botch (pairwise), " |
| 568 | "count %u left %u", |
| 569 | __func__, count, left)); |
| 570 | return _FAIL; |
| 571 | } |
| 572 | |
| 573 | for (i = 0; i < count; i++) { |
Jes Sorensen | 0cac3f9 | 2014-06-09 15:16:02 +0200 | [diff] [blame] | 574 | *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 575 | |
| 576 | pos += RSN_SELECTOR_LEN; |
| 577 | left -= RSN_SELECTOR_LEN; |
| 578 | } |
| 579 | } else if (left == 1) { |
| 580 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, |
| 581 | ("%s: ie too short (for key mgmt)", __func__)); |
| 582 | |
| 583 | return _FAIL; |
| 584 | } |
| 585 | |
| 586 | if (is_8021x) { |
| 587 | if (left >= 6) { |
| 588 | pos += 2; |
| 589 | if (!memcmp(pos, SUITE_1X, 4)) { |
| 590 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
| 591 | ("%s (): there has 802.1x auth\n", |
| 592 | __func__)); |
| 593 | *is_8021x = 1; |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | return ret; |
| 599 | } |
| 600 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 601 | /** |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 602 | * rtw_get_wps_attr23a - Search a specific WPS attribute from a given WPS IE |
| 603 | * @wps_ie: Address of WPS IE to search |
| 604 | * @wps_ielen: Length limit from wps_ie |
| 605 | * @target_attr_id: The attribute ID of WPS attribute to search |
| 606 | * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute |
| 607 | * will be copied to the buf starting from buf_attr |
| 608 | * @len_attr: If not NULL and the WPS attribute is found, will set to the |
| 609 | * length of the entire WPS attribute |
| 610 | * |
| 611 | * Returns: the address of the specific WPS attribute found, or NULL |
| 612 | */ |
Jes Sorensen | 6e5e418 | 2014-06-09 15:15:54 +0200 | [diff] [blame] | 613 | const u8 *rtw_get_wps_attr23a(const u8 *wps_ie, uint wps_ielen, |
| 614 | u16 target_attr_id, u8 *buf_attr, u32 *len_attr) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 615 | { |
Jes Sorensen | 6e5e418 | 2014-06-09 15:15:54 +0200 | [diff] [blame] | 616 | const u8 *attr_ptr = NULL; |
| 617 | const u8 *target_attr_ptr = NULL; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 618 | u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04}; |
| 619 | |
| 620 | if (len_attr) |
| 621 | *len_attr = 0; |
| 622 | |
Jes Sorensen | ea0c927 | 2014-05-09 15:03:09 +0200 | [diff] [blame] | 623 | if (wps_ie[0] != WLAN_EID_VENDOR_SPECIFIC || |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 624 | memcmp(wps_ie + 2, wps_oui, 4)) { |
| 625 | return attr_ptr; |
| 626 | } |
| 627 | |
| 628 | /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */ |
| 629 | attr_ptr = wps_ie + 6; /* goto first attr */ |
| 630 | |
| 631 | while (attr_ptr - wps_ie < wps_ielen) { |
| 632 | /* 4 = 2(Attribute ID) + 2(Length) */ |
Larry Finger | c17416e | 2014-03-28 21:37:42 -0500 | [diff] [blame] | 633 | u16 attr_id = get_unaligned_be16(attr_ptr); |
| 634 | u16 attr_data_len = get_unaligned_be16(attr_ptr + 2); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 635 | u16 attr_len = attr_data_len + 4; |
| 636 | |
| 637 | /* DBG_8723A("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len); */ |
| 638 | if (attr_id == target_attr_id) { |
| 639 | target_attr_ptr = attr_ptr; |
| 640 | |
| 641 | if (buf_attr) |
| 642 | memcpy(buf_attr, attr_ptr, attr_len); |
| 643 | |
| 644 | if (len_attr) |
| 645 | *len_attr = attr_len; |
| 646 | |
| 647 | break; |
| 648 | } else { |
| 649 | attr_ptr += attr_len; /* goto next */ |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | return target_attr_ptr; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * rtw_get_wps_attr_content23a - Search a specific WPS attribute content |
| 658 | * from a given WPS IE |
| 659 | * @wps_ie: Address of WPS IE to search |
| 660 | * @wps_ielen: Length limit from wps_ie |
| 661 | * @target_attr_id: The attribute ID of WPS attribute to search |
| 662 | * @buf_content: If not NULL and the WPS attribute is found, WPS attribute |
| 663 | * content will be copied to the buf starting from buf_content |
| 664 | * @len_content: If not NULL and the WPS attribute is found, will set to the |
| 665 | * length of the WPS attribute content |
| 666 | * |
| 667 | * Returns: the address of the specific WPS attribute content found, or NULL |
| 668 | */ |
Jes Sorensen | 6e5e418 | 2014-06-09 15:15:54 +0200 | [diff] [blame] | 669 | const u8 *rtw_get_wps_attr_content23a(const u8 *wps_ie, uint wps_ielen, |
Jes Sorensen | c250e07 | 2014-06-24 15:03:33 +0200 | [diff] [blame] | 670 | u16 target_attr_id, u8 *buf_content) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 671 | { |
Jes Sorensen | 6e5e418 | 2014-06-09 15:15:54 +0200 | [diff] [blame] | 672 | const u8 *attr_ptr; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 673 | u32 attr_len; |
| 674 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 675 | attr_ptr = rtw_get_wps_attr23a(wps_ie, wps_ielen, target_attr_id, |
| 676 | NULL, &attr_len); |
| 677 | |
| 678 | if (attr_ptr && attr_len) { |
| 679 | if (buf_content) |
| 680 | memcpy(buf_content, attr_ptr + 4, attr_len - 4); |
| 681 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 682 | return attr_ptr + 4; |
| 683 | } |
| 684 | |
| 685 | return NULL; |
| 686 | } |
| 687 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 688 | static int rtw_get_cipher_info(struct wlan_network *pnetwork) |
| 689 | { |
Jes Sorensen | 95c4345a | 2014-04-15 19:44:03 +0200 | [diff] [blame] | 690 | const u8 *pbuf; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 691 | int group_cipher = 0, pairwise_cipher = 0, is8021x = 0; |
| 692 | int ret = _FAIL; |
Jes Sorensen | 68e6c79 | 2014-06-24 15:03:29 +0200 | [diff] [blame] | 693 | int r, plen; |
Jes Sorensen | d7f0369 | 2014-04-15 19:44:04 +0200 | [diff] [blame] | 694 | char *pie; |
Jes Sorensen | 95c4345a | 2014-04-15 19:44:03 +0200 | [diff] [blame] | 695 | |
Jes Sorensen | 68e6c79 | 2014-06-24 15:03:29 +0200 | [diff] [blame] | 696 | pie = pnetwork->network.IEs; |
| 697 | plen = pnetwork->network.IELength; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 698 | |
Jes Sorensen | d7f0369 | 2014-04-15 19:44:04 +0200 | [diff] [blame] | 699 | pbuf = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
| 700 | WLAN_OUI_TYPE_MICROSOFT_WPA, pie, plen); |
| 701 | |
| 702 | if (pbuf && pbuf[1] > 0) { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 703 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
Jes Sorensen | d7f0369 | 2014-04-15 19:44:04 +0200 | [diff] [blame] | 704 | ("rtw_get_cipher_info: wpa_ielen: %d", pbuf[1])); |
| 705 | r = rtw_parse_wpa_ie23a(pbuf, pbuf[1] + 2, &group_cipher, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 706 | &pairwise_cipher, &is8021x); |
| 707 | if (r == _SUCCESS) { |
| 708 | pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher; |
| 709 | pnetwork->BcnInfo.group_cipher = group_cipher; |
| 710 | pnetwork->BcnInfo.is_8021x = is8021x; |
| 711 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
| 712 | ("%s: pnetwork->pairwise_cipher: %d, is_" |
| 713 | "8021x is %d", __func__, |
| 714 | pnetwork->BcnInfo.pairwise_cipher, |
| 715 | pnetwork->BcnInfo.is_8021x)); |
| 716 | ret = _SUCCESS; |
| 717 | } |
| 718 | } else { |
Jes Sorensen | d7f0369 | 2014-04-15 19:44:04 +0200 | [diff] [blame] | 719 | pbuf = cfg80211_find_ie(WLAN_EID_RSN, pie, plen); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 720 | |
Jes Sorensen | d7f0369 | 2014-04-15 19:44:04 +0200 | [diff] [blame] | 721 | if (pbuf && pbuf[1] > 0) { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 722 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
| 723 | ("get RSN IE\n")); |
Jes Sorensen | d7f0369 | 2014-04-15 19:44:04 +0200 | [diff] [blame] | 724 | r = rtw_parse_wpa2_ie23a(pbuf, pbuf[1] + 2, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 725 | &group_cipher, &pairwise_cipher, |
| 726 | &is8021x); |
| 727 | if (r == _SUCCESS) { |
| 728 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
| 729 | ("get RSN IE OK!!!\n")); |
| 730 | pnetwork->BcnInfo.pairwise_cipher = |
| 731 | pairwise_cipher; |
| 732 | pnetwork->BcnInfo.group_cipher = group_cipher; |
| 733 | pnetwork->BcnInfo.is_8021x = is8021x; |
| 734 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
| 735 | ("%s: pnetwork->pairwise_cipher: %d," |
| 736 | "pnetwork->group_cipher is %d, " |
| 737 | "is_8021x is %d", __func__, |
| 738 | pnetwork->BcnInfo.pairwise_cipher, |
| 739 | pnetwork->BcnInfo.group_cipher, |
| 740 | pnetwork->BcnInfo.is_8021x)); |
| 741 | ret = _SUCCESS; |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | void rtw_get_bcn_info23a(struct wlan_network *pnetwork) |
| 750 | { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 751 | u8 bencrypt = 0; |
Jes Sorensen | 68e6c79 | 2014-06-24 15:03:29 +0200 | [diff] [blame] | 752 | int pie_len; |
Jes Sorensen | 54ddd22 | 2014-06-09 15:15:59 +0200 | [diff] [blame] | 753 | u8 *pie; |
| 754 | const u8 *p; |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 755 | |
Jes Sorensen | 9ce73e2 | 2014-06-19 11:37:32 +0200 | [diff] [blame] | 756 | if (pnetwork->network.capability & WLAN_CAPABILITY_PRIVACY) { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 757 | bencrypt = 1; |
| 758 | pnetwork->network.Privacy = 1; |
Jes Sorensen | 56b8412 | 2014-05-21 09:38:30 +0200 | [diff] [blame] | 759 | } else |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 760 | pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS; |
Jes Sorensen | 56b8412 | 2014-05-21 09:38:30 +0200 | [diff] [blame] | 761 | |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 762 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
Jes Sorensen | 0396416 | 2014-06-19 11:37:33 +0200 | [diff] [blame] | 763 | ("%s: ssid =%s\n", __func__, pnetwork->network.Ssid.ssid)); |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 764 | |
Jes Sorensen | 68e6c79 | 2014-06-24 15:03:29 +0200 | [diff] [blame] | 765 | pie = pnetwork->network.IEs; |
| 766 | pie_len = pnetwork->network.IELength; |
Jes Sorensen | 54ddd22 | 2014-06-09 15:15:59 +0200 | [diff] [blame] | 767 | |
| 768 | p = cfg80211_find_ie(WLAN_EID_RSN, pie, pie_len); |
| 769 | if (p && p[1]) { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 770 | pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2; |
Jes Sorensen | 54ddd22 | 2014-06-09 15:15:59 +0200 | [diff] [blame] | 771 | } else if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
| 772 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 773 | pie, pie_len)) { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 774 | pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA; |
Jes Sorensen | 54ddd22 | 2014-06-09 15:15:59 +0200 | [diff] [blame] | 775 | } else { |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 776 | if (bencrypt) |
| 777 | pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP; |
| 778 | } |
| 779 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
Jes Sorensen | 0396416 | 2014-06-19 11:37:33 +0200 | [diff] [blame] | 780 | ("%s: pnetwork->encryp_protocol is %x\n", __func__, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 781 | pnetwork->BcnInfo.encryp_protocol)); |
| 782 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, |
Jes Sorensen | 0396416 | 2014-06-19 11:37:33 +0200 | [diff] [blame] | 783 | ("%s: pnetwork->encryp_protocol is %x\n", __func__, |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 784 | pnetwork->BcnInfo.encryp_protocol)); |
| 785 | rtw_get_cipher_info(pnetwork); |
| 786 | |
| 787 | /* get bwmode and ch_offset */ |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /* show MCS rate, unit: 100Kbps */ |
| 791 | u16 rtw_mcs_rate23a(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 792 | struct ieee80211_mcs_info *mcs) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 793 | { |
| 794 | u16 max_rate = 0; |
| 795 | |
| 796 | if (rf_type == RF_1T1R) { |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 797 | if (mcs->rx_mask[0] & BIT(7)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 798 | max_rate = (bw_40MHz) ? ((short_GI_40)?1500:1350): |
| 799 | ((short_GI_20)?722:650); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 800 | else if (mcs->rx_mask[0] & BIT(6)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 801 | max_rate = (bw_40MHz) ? ((short_GI_40)?1350:1215): |
| 802 | ((short_GI_20)?650:585); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 803 | else if (mcs->rx_mask[0] & BIT(5)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 804 | max_rate = (bw_40MHz) ? ((short_GI_40)?1200:1080): |
| 805 | ((short_GI_20)?578:520); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 806 | else if (mcs->rx_mask[0] & BIT(4)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 807 | max_rate = (bw_40MHz) ? ((short_GI_40)?900:810): |
| 808 | ((short_GI_20)?433:390); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 809 | else if (mcs->rx_mask[0] & BIT(3)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 810 | max_rate = (bw_40MHz) ? ((short_GI_40)?600:540): |
| 811 | ((short_GI_20)?289:260); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 812 | else if (mcs->rx_mask[0] & BIT(2)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 813 | max_rate = (bw_40MHz) ? ((short_GI_40)?450:405): |
| 814 | ((short_GI_20)?217:195); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 815 | else if (mcs->rx_mask[0] & BIT(1)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 816 | max_rate = (bw_40MHz) ? ((short_GI_40)?300:270): |
| 817 | ((short_GI_20)?144:130); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 818 | else if (mcs->rx_mask[0] & BIT(0)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 819 | max_rate = (bw_40MHz) ? ((short_GI_40)?150:135): |
| 820 | ((short_GI_20)?72:65); |
| 821 | } else { |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 822 | if (mcs->rx_mask[1]) { |
| 823 | if (mcs->rx_mask[1] & BIT(7)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 824 | max_rate = (bw_40MHz) ? ((short_GI_40)?3000:2700):((short_GI_20)?1444:1300); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 825 | else if (mcs->rx_mask[1] & BIT(6)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 826 | max_rate = (bw_40MHz) ? ((short_GI_40)?2700:2430):((short_GI_20)?1300:1170); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 827 | else if (mcs->rx_mask[1] & BIT(5)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 828 | max_rate = (bw_40MHz) ? ((short_GI_40)?2400:2160):((short_GI_20)?1156:1040); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 829 | else if (mcs->rx_mask[1] & BIT(4)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 830 | max_rate = (bw_40MHz) ? ((short_GI_40)?1800:1620):((short_GI_20)?867:780); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 831 | else if (mcs->rx_mask[1] & BIT(3)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 832 | max_rate = (bw_40MHz) ? ((short_GI_40)?1200:1080):((short_GI_20)?578:520); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 833 | else if (mcs->rx_mask[1] & BIT(2)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 834 | max_rate = (bw_40MHz) ? ((short_GI_40)?900:810):((short_GI_20)?433:390); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 835 | else if (mcs->rx_mask[1] & BIT(1)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 836 | max_rate = (bw_40MHz) ? ((short_GI_40)?600:540):((short_GI_20)?289:260); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 837 | else if (mcs->rx_mask[1] & BIT(0)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 838 | max_rate = (bw_40MHz) ? ((short_GI_40)?300:270):((short_GI_20)?144:130); |
| 839 | } else { |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 840 | if (mcs->rx_mask[0] & BIT(7)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 841 | max_rate = (bw_40MHz) ? ((short_GI_40)?1500:1350):((short_GI_20)?722:650); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 842 | else if (mcs->rx_mask[0] & BIT(6)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 843 | max_rate = (bw_40MHz) ? ((short_GI_40)?1350:1215):((short_GI_20)?650:585); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 844 | else if (mcs->rx_mask[0] & BIT(5)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 845 | max_rate = (bw_40MHz) ? ((short_GI_40)?1200:1080):((short_GI_20)?578:520); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 846 | else if (mcs->rx_mask[0] & BIT(4)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 847 | max_rate = (bw_40MHz) ? ((short_GI_40)?900:810):((short_GI_20)?433:390); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 848 | else if (mcs->rx_mask[0] & BIT(3)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 849 | max_rate = (bw_40MHz) ? ((short_GI_40)?600:540):((short_GI_20)?289:260); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 850 | else if (mcs->rx_mask[0] & BIT(2)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 851 | max_rate = (bw_40MHz) ? ((short_GI_40)?450:405):((short_GI_20)?217:195); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 852 | else if (mcs->rx_mask[0] & BIT(1)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 853 | max_rate = (bw_40MHz) ? ((short_GI_40)?300:270):((short_GI_20)?144:130); |
Jes Sorensen | 198e95d | 2014-05-31 18:05:10 +0200 | [diff] [blame] | 854 | else if (mcs->rx_mask[0] & BIT(0)) |
Larry Finger | 5e93f35 | 2014-03-28 21:37:38 -0500 | [diff] [blame] | 855 | max_rate = (bw_40MHz) ? ((short_GI_40)?150:135):((short_GI_20)?72:65); |
| 856 | } |
| 857 | } |
| 858 | return max_rate; |
| 859 | } |