PageRenderTime 57ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/wireless/mwifiex/scan.c

http://github.com/mirrors/linux
C | 2132 lines | 1448 code | 259 blank | 425 comment | 214 complexity | 4c3120a82507d13bbd66d183bc574351 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /*
  2. * Marvell Wireless LAN device driver: scan ioctl and command handling
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "11n.h"
  25. #include "cfg80211.h"
  26. /* The maximum number of channels the firmware can scan per command */
  27. #define MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN 14
  28. #define MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD 4
  29. #define MWIFIEX_LIMIT_1_CHANNEL_PER_SCAN_CMD 15
  30. #define MWIFIEX_LIMIT_2_CHANNELS_PER_SCAN_CMD 27
  31. #define MWIFIEX_LIMIT_3_CHANNELS_PER_SCAN_CMD 35
  32. /* Memory needed to store a max sized Channel List TLV for a firmware scan */
  33. #define CHAN_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_header) \
  34. + (MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN \
  35. *sizeof(struct mwifiex_chan_scan_param_set)))
  36. /* Memory needed to store supported rate */
  37. #define RATE_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_rates_param_set) \
  38. + HOSTCMD_SUPPORTED_RATES)
  39. /* Memory needed to store a max number/size WildCard SSID TLV for a firmware
  40. scan */
  41. #define WILDCARD_SSID_TLV_MAX_SIZE \
  42. (MWIFIEX_MAX_SSID_LIST_LENGTH * \
  43. (sizeof(struct mwifiex_ie_types_wildcard_ssid_params) \
  44. + IEEE80211_MAX_SSID_LEN))
  45. /* Maximum memory needed for a mwifiex_scan_cmd_config with all TLVs at max */
  46. #define MAX_SCAN_CFG_ALLOC (sizeof(struct mwifiex_scan_cmd_config) \
  47. + sizeof(struct mwifiex_ie_types_num_probes) \
  48. + sizeof(struct mwifiex_ie_types_htcap) \
  49. + CHAN_TLV_MAX_SIZE \
  50. + RATE_TLV_MAX_SIZE \
  51. + WILDCARD_SSID_TLV_MAX_SIZE)
  52. union mwifiex_scan_cmd_config_tlv {
  53. /* Scan configuration (variable length) */
  54. struct mwifiex_scan_cmd_config config;
  55. /* Max allocated block */
  56. u8 config_alloc_buf[MAX_SCAN_CFG_ALLOC];
  57. };
  58. enum cipher_suite {
  59. CIPHER_SUITE_TKIP,
  60. CIPHER_SUITE_CCMP,
  61. CIPHER_SUITE_MAX
  62. };
  63. static u8 mwifiex_wpa_oui[CIPHER_SUITE_MAX][4] = {
  64. { 0x00, 0x50, 0xf2, 0x02 }, /* TKIP */
  65. { 0x00, 0x50, 0xf2, 0x04 }, /* AES */
  66. };
  67. static u8 mwifiex_rsn_oui[CIPHER_SUITE_MAX][4] = {
  68. { 0x00, 0x0f, 0xac, 0x02 }, /* TKIP */
  69. { 0x00, 0x0f, 0xac, 0x04 }, /* AES */
  70. };
  71. /*
  72. * This function parses a given IE for a given OUI.
  73. *
  74. * This is used to parse a WPA/RSN IE to find if it has
  75. * a given oui in PTK.
  76. */
  77. static u8
  78. mwifiex_search_oui_in_ie(struct ie_body *iebody, u8 *oui)
  79. {
  80. u8 count;
  81. count = iebody->ptk_cnt[0];
  82. /* There could be multiple OUIs for PTK hence
  83. 1) Take the length.
  84. 2) Check all the OUIs for AES.
  85. 3) If one of them is AES then pass success. */
  86. while (count) {
  87. if (!memcmp(iebody->ptk_body, oui, sizeof(iebody->ptk_body)))
  88. return MWIFIEX_OUI_PRESENT;
  89. --count;
  90. if (count)
  91. iebody = (struct ie_body *) ((u8 *) iebody +
  92. sizeof(iebody->ptk_body));
  93. }
  94. pr_debug("info: %s: OUI is not found in PTK\n", __func__);
  95. return MWIFIEX_OUI_NOT_PRESENT;
  96. }
  97. /*
  98. * This function checks if a given OUI is present in a RSN IE.
  99. *
  100. * The function first checks if a RSN IE is present or not in the
  101. * BSS descriptor. It tries to locate the OUI only if such an IE is
  102. * present.
  103. */
  104. static u8
  105. mwifiex_is_rsn_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
  106. {
  107. u8 *oui;
  108. struct ie_body *iebody;
  109. u8 ret = MWIFIEX_OUI_NOT_PRESENT;
  110. if (((bss_desc->bcn_rsn_ie) && ((*(bss_desc->bcn_rsn_ie)).
  111. ieee_hdr.element_id == WLAN_EID_RSN))) {
  112. iebody = (struct ie_body *)
  113. (((u8 *) bss_desc->bcn_rsn_ie->data) +
  114. RSN_GTK_OUI_OFFSET);
  115. oui = &mwifiex_rsn_oui[cipher][0];
  116. ret = mwifiex_search_oui_in_ie(iebody, oui);
  117. if (ret)
  118. return ret;
  119. }
  120. return ret;
  121. }
  122. /*
  123. * This function checks if a given OUI is present in a WPA IE.
  124. *
  125. * The function first checks if a WPA IE is present or not in the
  126. * BSS descriptor. It tries to locate the OUI only if such an IE is
  127. * present.
  128. */
  129. static u8
  130. mwifiex_is_wpa_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
  131. {
  132. u8 *oui;
  133. struct ie_body *iebody;
  134. u8 ret = MWIFIEX_OUI_NOT_PRESENT;
  135. if (((bss_desc->bcn_wpa_ie) &&
  136. ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id ==
  137. WLAN_EID_VENDOR_SPECIFIC))) {
  138. iebody = (struct ie_body *) bss_desc->bcn_wpa_ie->data;
  139. oui = &mwifiex_wpa_oui[cipher][0];
  140. ret = mwifiex_search_oui_in_ie(iebody, oui);
  141. if (ret)
  142. return ret;
  143. }
  144. return ret;
  145. }
  146. /*
  147. * This function compares two SSIDs and checks if they match.
  148. */
  149. s32
  150. mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2)
  151. {
  152. if (!ssid1 || !ssid2 || (ssid1->ssid_len != ssid2->ssid_len))
  153. return -1;
  154. return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssid_len);
  155. }
  156. /*
  157. * This function checks if wapi is enabled in driver and scanned network is
  158. * compatible with it.
  159. */
  160. static bool
  161. mwifiex_is_bss_wapi(struct mwifiex_private *priv,
  162. struct mwifiex_bssdescriptor *bss_desc)
  163. {
  164. if (priv->sec_info.wapi_enabled &&
  165. (bss_desc->bcn_wapi_ie &&
  166. ((*(bss_desc->bcn_wapi_ie)).ieee_hdr.element_id ==
  167. WLAN_EID_BSS_AC_ACCESS_DELAY))) {
  168. return true;
  169. }
  170. return false;
  171. }
  172. /*
  173. * This function checks if driver is configured with no security mode and
  174. * scanned network is compatible with it.
  175. */
  176. static bool
  177. mwifiex_is_bss_no_sec(struct mwifiex_private *priv,
  178. struct mwifiex_bssdescriptor *bss_desc)
  179. {
  180. if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
  181. !priv->sec_info.wpa2_enabled && ((!bss_desc->bcn_wpa_ie) ||
  182. ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id !=
  183. WLAN_EID_VENDOR_SPECIFIC)) &&
  184. ((!bss_desc->bcn_rsn_ie) ||
  185. ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id !=
  186. WLAN_EID_RSN)) &&
  187. !priv->sec_info.encryption_mode && !bss_desc->privacy) {
  188. return true;
  189. }
  190. return false;
  191. }
  192. /*
  193. * This function checks if static WEP is enabled in driver and scanned network
  194. * is compatible with it.
  195. */
  196. static bool
  197. mwifiex_is_bss_static_wep(struct mwifiex_private *priv,
  198. struct mwifiex_bssdescriptor *bss_desc)
  199. {
  200. if (priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
  201. !priv->sec_info.wpa2_enabled && bss_desc->privacy) {
  202. return true;
  203. }
  204. return false;
  205. }
  206. /*
  207. * This function checks if wpa is enabled in driver and scanned network is
  208. * compatible with it.
  209. */
  210. static bool
  211. mwifiex_is_bss_wpa(struct mwifiex_private *priv,
  212. struct mwifiex_bssdescriptor *bss_desc)
  213. {
  214. if (!priv->sec_info.wep_enabled && priv->sec_info.wpa_enabled &&
  215. !priv->sec_info.wpa2_enabled && ((bss_desc->bcn_wpa_ie) &&
  216. ((*(bss_desc->bcn_wpa_ie)).
  217. vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC))
  218. /*
  219. * Privacy bit may NOT be set in some APs like
  220. * LinkSys WRT54G && bss_desc->privacy
  221. */
  222. ) {
  223. dev_dbg(priv->adapter->dev, "info: %s: WPA:"
  224. " wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
  225. "EncMode=%#x privacy=%#x\n", __func__,
  226. (bss_desc->bcn_wpa_ie) ?
  227. (*(bss_desc->bcn_wpa_ie)).
  228. vend_hdr.element_id : 0,
  229. (bss_desc->bcn_rsn_ie) ?
  230. (*(bss_desc->bcn_rsn_ie)).
  231. ieee_hdr.element_id : 0,
  232. (priv->sec_info.wep_enabled) ? "e" : "d",
  233. (priv->sec_info.wpa_enabled) ? "e" : "d",
  234. (priv->sec_info.wpa2_enabled) ? "e" : "d",
  235. priv->sec_info.encryption_mode,
  236. bss_desc->privacy);
  237. return true;
  238. }
  239. return false;
  240. }
  241. /*
  242. * This function checks if wpa2 is enabled in driver and scanned network is
  243. * compatible with it.
  244. */
  245. static bool
  246. mwifiex_is_bss_wpa2(struct mwifiex_private *priv,
  247. struct mwifiex_bssdescriptor *bss_desc)
  248. {
  249. if (!priv->sec_info.wep_enabled &&
  250. !priv->sec_info.wpa_enabled &&
  251. priv->sec_info.wpa2_enabled &&
  252. ((bss_desc->bcn_rsn_ie) &&
  253. ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id == WLAN_EID_RSN))) {
  254. /*
  255. * Privacy bit may NOT be set in some APs like
  256. * LinkSys WRT54G && bss_desc->privacy
  257. */
  258. dev_dbg(priv->adapter->dev, "info: %s: WPA2: "
  259. " wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
  260. "EncMode=%#x privacy=%#x\n", __func__,
  261. (bss_desc->bcn_wpa_ie) ?
  262. (*(bss_desc->bcn_wpa_ie)).
  263. vend_hdr.element_id : 0,
  264. (bss_desc->bcn_rsn_ie) ?
  265. (*(bss_desc->bcn_rsn_ie)).
  266. ieee_hdr.element_id : 0,
  267. (priv->sec_info.wep_enabled) ? "e" : "d",
  268. (priv->sec_info.wpa_enabled) ? "e" : "d",
  269. (priv->sec_info.wpa2_enabled) ? "e" : "d",
  270. priv->sec_info.encryption_mode,
  271. bss_desc->privacy);
  272. return true;
  273. }
  274. return false;
  275. }
  276. /*
  277. * This function checks if adhoc AES is enabled in driver and scanned network is
  278. * compatible with it.
  279. */
  280. static bool
  281. mwifiex_is_bss_adhoc_aes(struct mwifiex_private *priv,
  282. struct mwifiex_bssdescriptor *bss_desc)
  283. {
  284. if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
  285. !priv->sec_info.wpa2_enabled &&
  286. ((!bss_desc->bcn_wpa_ie) ||
  287. ((*(bss_desc->bcn_wpa_ie)).
  288. vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
  289. ((!bss_desc->bcn_rsn_ie) ||
  290. ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
  291. !priv->sec_info.encryption_mode && bss_desc->privacy) {
  292. return true;
  293. }
  294. return false;
  295. }
  296. /*
  297. * This function checks if dynamic WEP is enabled in driver and scanned network
  298. * is compatible with it.
  299. */
  300. static bool
  301. mwifiex_is_bss_dynamic_wep(struct mwifiex_private *priv,
  302. struct mwifiex_bssdescriptor *bss_desc)
  303. {
  304. if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
  305. !priv->sec_info.wpa2_enabled &&
  306. ((!bss_desc->bcn_wpa_ie) ||
  307. ((*(bss_desc->bcn_wpa_ie)).
  308. vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
  309. ((!bss_desc->bcn_rsn_ie) ||
  310. ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
  311. priv->sec_info.encryption_mode && bss_desc->privacy) {
  312. dev_dbg(priv->adapter->dev, "info: %s: dynamic "
  313. "WEP: wpa_ie=%#x wpa2_ie=%#x "
  314. "EncMode=%#x privacy=%#x\n",
  315. __func__,
  316. (bss_desc->bcn_wpa_ie) ?
  317. (*(bss_desc->bcn_wpa_ie)).
  318. vend_hdr.element_id : 0,
  319. (bss_desc->bcn_rsn_ie) ?
  320. (*(bss_desc->bcn_rsn_ie)).
  321. ieee_hdr.element_id : 0,
  322. priv->sec_info.encryption_mode,
  323. bss_desc->privacy);
  324. return true;
  325. }
  326. return false;
  327. }
  328. /*
  329. * This function checks if a scanned network is compatible with the driver
  330. * settings.
  331. *
  332. * WEP WPA WPA2 ad-hoc encrypt Network
  333. * enabled enabled enabled AES mode Privacy WPA WPA2 Compatible
  334. * 0 0 0 0 NONE 0 0 0 yes No security
  335. * 0 1 0 0 x 1x 1 x yes WPA (disable
  336. * HT if no AES)
  337. * 0 0 1 0 x 1x x 1 yes WPA2 (disable
  338. * HT if no AES)
  339. * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
  340. * 1 0 0 0 NONE 1 0 0 yes Static WEP
  341. * (disable HT)
  342. * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
  343. *
  344. * Compatibility is not matched while roaming, except for mode.
  345. */
  346. static s32
  347. mwifiex_is_network_compatible(struct mwifiex_private *priv,
  348. struct mwifiex_bssdescriptor *bss_desc, u32 mode)
  349. {
  350. struct mwifiex_adapter *adapter = priv->adapter;
  351. bss_desc->disable_11n = false;
  352. /* Don't check for compatibility if roaming */
  353. if (priv->media_connected &&
  354. (priv->bss_mode == NL80211_IFTYPE_STATION) &&
  355. (bss_desc->bss_mode == NL80211_IFTYPE_STATION))
  356. return 0;
  357. if (priv->wps.session_enable) {
  358. dev_dbg(adapter->dev,
  359. "info: return success directly in WPS period\n");
  360. return 0;
  361. }
  362. if (bss_desc->chan_sw_ie_present) {
  363. dev_err(adapter->dev,
  364. "Don't connect to AP with WLAN_EID_CHANNEL_SWITCH\n");
  365. return -1;
  366. }
  367. if (mwifiex_is_bss_wapi(priv, bss_desc)) {
  368. dev_dbg(adapter->dev, "info: return success for WAPI AP\n");
  369. return 0;
  370. }
  371. if (bss_desc->bss_mode == mode) {
  372. if (mwifiex_is_bss_no_sec(priv, bss_desc)) {
  373. /* No security */
  374. return 0;
  375. } else if (mwifiex_is_bss_static_wep(priv, bss_desc)) {
  376. /* Static WEP enabled */
  377. dev_dbg(adapter->dev, "info: Disable 11n in WEP mode.\n");
  378. bss_desc->disable_11n = true;
  379. return 0;
  380. } else if (mwifiex_is_bss_wpa(priv, bss_desc)) {
  381. /* WPA enabled */
  382. if (((priv->adapter->config_bands & BAND_GN ||
  383. priv->adapter->config_bands & BAND_AN) &&
  384. bss_desc->bcn_ht_cap) &&
  385. !mwifiex_is_wpa_oui_present(bss_desc,
  386. CIPHER_SUITE_CCMP)) {
  387. if (mwifiex_is_wpa_oui_present
  388. (bss_desc, CIPHER_SUITE_TKIP)) {
  389. dev_dbg(adapter->dev,
  390. "info: Disable 11n if AES "
  391. "is not supported by AP\n");
  392. bss_desc->disable_11n = true;
  393. } else {
  394. return -1;
  395. }
  396. }
  397. return 0;
  398. } else if (mwifiex_is_bss_wpa2(priv, bss_desc)) {
  399. /* WPA2 enabled */
  400. if (((priv->adapter->config_bands & BAND_GN ||
  401. priv->adapter->config_bands & BAND_AN) &&
  402. bss_desc->bcn_ht_cap) &&
  403. !mwifiex_is_rsn_oui_present(bss_desc,
  404. CIPHER_SUITE_CCMP)) {
  405. if (mwifiex_is_rsn_oui_present
  406. (bss_desc, CIPHER_SUITE_TKIP)) {
  407. dev_dbg(adapter->dev,
  408. "info: Disable 11n if AES "
  409. "is not supported by AP\n");
  410. bss_desc->disable_11n = true;
  411. } else {
  412. return -1;
  413. }
  414. }
  415. return 0;
  416. } else if (mwifiex_is_bss_adhoc_aes(priv, bss_desc)) {
  417. /* Ad-hoc AES enabled */
  418. return 0;
  419. } else if (mwifiex_is_bss_dynamic_wep(priv, bss_desc)) {
  420. /* Dynamic WEP enabled */
  421. return 0;
  422. }
  423. /* Security doesn't match */
  424. dev_dbg(adapter->dev,
  425. "info: %s: failed: wpa_ie=%#x wpa2_ie=%#x WEP=%s "
  426. "WPA=%s WPA2=%s EncMode=%#x privacy=%#x\n", __func__,
  427. (bss_desc->bcn_wpa_ie) ?
  428. (*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id : 0,
  429. (bss_desc->bcn_rsn_ie) ?
  430. (*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id : 0,
  431. (priv->sec_info.wep_enabled) ? "e" : "d",
  432. (priv->sec_info.wpa_enabled) ? "e" : "d",
  433. (priv->sec_info.wpa2_enabled) ? "e" : "d",
  434. priv->sec_info.encryption_mode, bss_desc->privacy);
  435. return -1;
  436. }
  437. /* Mode doesn't match */
  438. return -1;
  439. }
  440. /*
  441. * This function creates a channel list for the driver to scan, based
  442. * on region/band information.
  443. *
  444. * This routine is used for any scan that is not provided with a
  445. * specific channel list to scan.
  446. */
  447. static int
  448. mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
  449. const struct mwifiex_user_scan_cfg
  450. *user_scan_in,
  451. struct mwifiex_chan_scan_param_set
  452. *scan_chan_list,
  453. u8 filtered_scan)
  454. {
  455. enum ieee80211_band band;
  456. struct ieee80211_supported_band *sband;
  457. struct ieee80211_channel *ch;
  458. struct mwifiex_adapter *adapter = priv->adapter;
  459. int chan_idx = 0, i;
  460. for (band = 0; (band < IEEE80211_NUM_BANDS) ; band++) {
  461. if (!priv->wdev->wiphy->bands[band])
  462. continue;
  463. sband = priv->wdev->wiphy->bands[band];
  464. for (i = 0; (i < sband->n_channels) ; i++) {
  465. ch = &sband->channels[i];
  466. if (ch->flags & IEEE80211_CHAN_DISABLED)
  467. continue;
  468. scan_chan_list[chan_idx].radio_type = band;
  469. if (user_scan_in &&
  470. user_scan_in->chan_list[0].scan_time)
  471. scan_chan_list[chan_idx].max_scan_time =
  472. cpu_to_le16((u16) user_scan_in->
  473. chan_list[0].scan_time);
  474. else if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  475. scan_chan_list[chan_idx].max_scan_time =
  476. cpu_to_le16(adapter->passive_scan_time);
  477. else
  478. scan_chan_list[chan_idx].max_scan_time =
  479. cpu_to_le16(adapter->active_scan_time);
  480. if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  481. scan_chan_list[chan_idx].chan_scan_mode_bitmap
  482. |= MWIFIEX_PASSIVE_SCAN;
  483. else
  484. scan_chan_list[chan_idx].chan_scan_mode_bitmap
  485. &= ~MWIFIEX_PASSIVE_SCAN;
  486. scan_chan_list[chan_idx].chan_number =
  487. (u32) ch->hw_value;
  488. if (filtered_scan) {
  489. scan_chan_list[chan_idx].max_scan_time =
  490. cpu_to_le16(adapter->specific_scan_time);
  491. scan_chan_list[chan_idx].chan_scan_mode_bitmap
  492. |= MWIFIEX_DISABLE_CHAN_FILT;
  493. }
  494. chan_idx++;
  495. }
  496. }
  497. return chan_idx;
  498. }
  499. /* This function appends rate TLV to scan config command. */
  500. static int
  501. mwifiex_append_rate_tlv(struct mwifiex_private *priv,
  502. struct mwifiex_scan_cmd_config *scan_cfg_out,
  503. u8 radio)
  504. {
  505. struct mwifiex_ie_types_rates_param_set *rates_tlv;
  506. u8 rates[MWIFIEX_SUPPORTED_RATES], *tlv_pos;
  507. u32 rates_size;
  508. memset(rates, 0, sizeof(rates));
  509. tlv_pos = (u8 *)scan_cfg_out->tlv_buf + scan_cfg_out->tlv_buf_len;
  510. if (priv->scan_request)
  511. rates_size = mwifiex_get_rates_from_cfg80211(priv, rates,
  512. radio);
  513. else
  514. rates_size = mwifiex_get_supported_rates(priv, rates);
  515. dev_dbg(priv->adapter->dev, "info: SCAN_CMD: Rates size = %d\n",
  516. rates_size);
  517. rates_tlv = (struct mwifiex_ie_types_rates_param_set *)tlv_pos;
  518. rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
  519. rates_tlv->header.len = cpu_to_le16((u16) rates_size);
  520. memcpy(rates_tlv->rates, rates, rates_size);
  521. scan_cfg_out->tlv_buf_len += sizeof(rates_tlv->header) + rates_size;
  522. return rates_size;
  523. }
  524. /*
  525. * This function constructs and sends multiple scan config commands to
  526. * the firmware.
  527. *
  528. * Previous routines in the code flow have created a scan command configuration
  529. * with any requested TLVs. This function splits the channel TLV into maximum
  530. * channels supported per scan lists and sends the portion of the channel TLV,
  531. * along with the other TLVs, to the firmware.
  532. */
  533. static int
  534. mwifiex_scan_channel_list(struct mwifiex_private *priv,
  535. u32 max_chan_per_scan, u8 filtered_scan,
  536. struct mwifiex_scan_cmd_config *scan_cfg_out,
  537. struct mwifiex_ie_types_chan_list_param_set
  538. *chan_tlv_out,
  539. struct mwifiex_chan_scan_param_set *scan_chan_list)
  540. {
  541. int ret = 0;
  542. struct mwifiex_chan_scan_param_set *tmp_chan_list;
  543. struct mwifiex_chan_scan_param_set *start_chan;
  544. u32 tlv_idx, rates_size;
  545. u32 total_scan_time;
  546. u32 done_early;
  547. u8 radio_type;
  548. if (!scan_cfg_out || !chan_tlv_out || !scan_chan_list) {
  549. dev_dbg(priv->adapter->dev,
  550. "info: Scan: Null detect: %p, %p, %p\n",
  551. scan_cfg_out, chan_tlv_out, scan_chan_list);
  552. return -1;
  553. }
  554. /* Check csa channel expiry before preparing scan list */
  555. mwifiex_11h_get_csa_closed_channel(priv);
  556. chan_tlv_out->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  557. /* Set the temp channel struct pointer to the start of the desired
  558. list */
  559. tmp_chan_list = scan_chan_list;
  560. /* Loop through the desired channel list, sending a new firmware scan
  561. commands for each max_chan_per_scan channels (or for 1,6,11
  562. individually if configured accordingly) */
  563. while (tmp_chan_list->chan_number) {
  564. tlv_idx = 0;
  565. total_scan_time = 0;
  566. radio_type = 0;
  567. chan_tlv_out->header.len = 0;
  568. start_chan = tmp_chan_list;
  569. done_early = false;
  570. /*
  571. * Construct the Channel TLV for the scan command. Continue to
  572. * insert channel TLVs until:
  573. * - the tlv_idx hits the maximum configured per scan command
  574. * - the next channel to insert is 0 (end of desired channel
  575. * list)
  576. * - done_early is set (controlling individual scanning of
  577. * 1,6,11)
  578. */
  579. while (tlv_idx < max_chan_per_scan &&
  580. tmp_chan_list->chan_number && !done_early) {
  581. if (tmp_chan_list->chan_number == priv->csa_chan) {
  582. tmp_chan_list++;
  583. continue;
  584. }
  585. radio_type = tmp_chan_list->radio_type;
  586. dev_dbg(priv->adapter->dev,
  587. "info: Scan: Chan(%3d), Radio(%d),"
  588. " Mode(%d, %d), Dur(%d)\n",
  589. tmp_chan_list->chan_number,
  590. tmp_chan_list->radio_type,
  591. tmp_chan_list->chan_scan_mode_bitmap
  592. & MWIFIEX_PASSIVE_SCAN,
  593. (tmp_chan_list->chan_scan_mode_bitmap
  594. & MWIFIEX_DISABLE_CHAN_FILT) >> 1,
  595. le16_to_cpu(tmp_chan_list->max_scan_time));
  596. /* Copy the current channel TLV to the command being
  597. prepared */
  598. memcpy(chan_tlv_out->chan_scan_param + tlv_idx,
  599. tmp_chan_list,
  600. sizeof(chan_tlv_out->chan_scan_param));
  601. /* Increment the TLV header length by the size
  602. appended */
  603. le16_add_cpu(&chan_tlv_out->header.len,
  604. sizeof(chan_tlv_out->chan_scan_param));
  605. /*
  606. * The tlv buffer length is set to the number of bytes
  607. * of the between the channel tlv pointer and the start
  608. * of the tlv buffer. This compensates for any TLVs
  609. * that were appended before the channel list.
  610. */
  611. scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
  612. scan_cfg_out->tlv_buf);
  613. /* Add the size of the channel tlv header and the data
  614. length */
  615. scan_cfg_out->tlv_buf_len +=
  616. (sizeof(chan_tlv_out->header)
  617. + le16_to_cpu(chan_tlv_out->header.len));
  618. /* Increment the index to the channel tlv we are
  619. constructing */
  620. tlv_idx++;
  621. /* Count the total scan time per command */
  622. total_scan_time +=
  623. le16_to_cpu(tmp_chan_list->max_scan_time);
  624. done_early = false;
  625. /* Stop the loop if the *current* channel is in the
  626. 1,6,11 set and we are not filtering on a BSSID
  627. or SSID. */
  628. if (!filtered_scan &&
  629. (tmp_chan_list->chan_number == 1 ||
  630. tmp_chan_list->chan_number == 6 ||
  631. tmp_chan_list->chan_number == 11))
  632. done_early = true;
  633. /* Increment the tmp pointer to the next channel to
  634. be scanned */
  635. tmp_chan_list++;
  636. /* Stop the loop if the *next* channel is in the 1,6,11
  637. set. This will cause it to be the only channel
  638. scanned on the next interation */
  639. if (!filtered_scan &&
  640. (tmp_chan_list->chan_number == 1 ||
  641. tmp_chan_list->chan_number == 6 ||
  642. tmp_chan_list->chan_number == 11))
  643. done_early = true;
  644. }
  645. /* The total scan time should be less than scan command timeout
  646. value */
  647. if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
  648. dev_err(priv->adapter->dev, "total scan time %dms"
  649. " is over limit (%dms), scan skipped\n",
  650. total_scan_time, MWIFIEX_MAX_TOTAL_SCAN_TIME);
  651. ret = -1;
  652. break;
  653. }
  654. rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out,
  655. radio_type);
  656. priv->adapter->scan_channels = start_chan;
  657. /* Send the scan command to the firmware with the specified
  658. cfg */
  659. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SCAN,
  660. HostCmd_ACT_GEN_SET, 0,
  661. scan_cfg_out);
  662. /* rate IE is updated per scan command but same starting
  663. * pointer is used each time so that rate IE from earlier
  664. * scan_cfg_out->buf is overwritten with new one.
  665. */
  666. scan_cfg_out->tlv_buf_len -=
  667. sizeof(struct mwifiex_ie_types_header) + rates_size;
  668. if (ret)
  669. break;
  670. }
  671. if (ret)
  672. return -1;
  673. return 0;
  674. }
  675. /*
  676. * This function constructs a scan command configuration structure to use
  677. * in scan commands.
  678. *
  679. * Application layer or other functions can invoke network scanning
  680. * with a scan configuration supplied in a user scan configuration structure.
  681. * This structure is used as the basis of one or many scan command configuration
  682. * commands that are sent to the command processing module and eventually to the
  683. * firmware.
  684. *
  685. * This function creates a scan command configuration structure based on the
  686. * following user supplied parameters (if present):
  687. * - SSID filter
  688. * - BSSID filter
  689. * - Number of Probes to be sent
  690. * - Channel list
  691. *
  692. * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
  693. * If the number of probes is not set, adapter default setting is used.
  694. */
  695. static void
  696. mwifiex_config_scan(struct mwifiex_private *priv,
  697. const struct mwifiex_user_scan_cfg *user_scan_in,
  698. struct mwifiex_scan_cmd_config *scan_cfg_out,
  699. struct mwifiex_ie_types_chan_list_param_set **chan_list_out,
  700. struct mwifiex_chan_scan_param_set *scan_chan_list,
  701. u8 *max_chan_per_scan, u8 *filtered_scan,
  702. u8 *scan_current_only)
  703. {
  704. struct mwifiex_adapter *adapter = priv->adapter;
  705. struct mwifiex_ie_types_num_probes *num_probes_tlv;
  706. struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
  707. u8 *tlv_pos;
  708. u32 num_probes;
  709. u32 ssid_len;
  710. u32 chan_idx;
  711. u32 chan_num;
  712. u32 scan_type;
  713. u16 scan_dur;
  714. u8 channel;
  715. u8 radio_type;
  716. int i;
  717. u8 ssid_filter;
  718. struct mwifiex_ie_types_htcap *ht_cap;
  719. /* The tlv_buf_len is calculated for each scan command. The TLVs added
  720. in this routine will be preserved since the routine that sends the
  721. command will append channelTLVs at *chan_list_out. The difference
  722. between the *chan_list_out and the tlv_buf start will be used to
  723. calculate the size of anything we add in this routine. */
  724. scan_cfg_out->tlv_buf_len = 0;
  725. /* Running tlv pointer. Assigned to chan_list_out at end of function
  726. so later routines know where channels can be added to the command
  727. buf */
  728. tlv_pos = scan_cfg_out->tlv_buf;
  729. /* Initialize the scan as un-filtered; the flag is later set to TRUE
  730. below if a SSID or BSSID filter is sent in the command */
  731. *filtered_scan = false;
  732. /* Initialize the scan as not being only on the current channel. If
  733. the channel list is customized, only contains one channel, and is
  734. the active channel, this is set true and data flow is not halted. */
  735. *scan_current_only = false;
  736. if (user_scan_in) {
  737. /* Default the ssid_filter flag to TRUE, set false under
  738. certain wildcard conditions and qualified by the existence
  739. of an SSID list before marking the scan as filtered */
  740. ssid_filter = true;
  741. /* Set the BSS type scan filter, use Adapter setting if
  742. unset */
  743. scan_cfg_out->bss_mode =
  744. (user_scan_in->bss_mode ? (u8) user_scan_in->
  745. bss_mode : (u8) adapter->scan_mode);
  746. /* Set the number of probes to send, use Adapter setting
  747. if unset */
  748. num_probes =
  749. (user_scan_in->num_probes ? user_scan_in->
  750. num_probes : adapter->scan_probes);
  751. /*
  752. * Set the BSSID filter to the incoming configuration,
  753. * if non-zero. If not set, it will remain disabled
  754. * (all zeros).
  755. */
  756. memcpy(scan_cfg_out->specific_bssid,
  757. user_scan_in->specific_bssid,
  758. sizeof(scan_cfg_out->specific_bssid));
  759. for (i = 0; i < user_scan_in->num_ssids; i++) {
  760. ssid_len = user_scan_in->ssid_list[i].ssid_len;
  761. wildcard_ssid_tlv =
  762. (struct mwifiex_ie_types_wildcard_ssid_params *)
  763. tlv_pos;
  764. wildcard_ssid_tlv->header.type =
  765. cpu_to_le16(TLV_TYPE_WILDCARDSSID);
  766. wildcard_ssid_tlv->header.len = cpu_to_le16(
  767. (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
  768. max_ssid_length)));
  769. /*
  770. * max_ssid_length = 0 tells firmware to perform
  771. * specific scan for the SSID filled, whereas
  772. * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
  773. * wildcard scan.
  774. */
  775. if (ssid_len)
  776. wildcard_ssid_tlv->max_ssid_length = 0;
  777. else
  778. wildcard_ssid_tlv->max_ssid_length =
  779. IEEE80211_MAX_SSID_LEN;
  780. memcpy(wildcard_ssid_tlv->ssid,
  781. user_scan_in->ssid_list[i].ssid, ssid_len);
  782. tlv_pos += (sizeof(wildcard_ssid_tlv->header)
  783. + le16_to_cpu(wildcard_ssid_tlv->header.len));
  784. dev_dbg(adapter->dev, "info: scan: ssid[%d]: %s, %d\n",
  785. i, wildcard_ssid_tlv->ssid,
  786. wildcard_ssid_tlv->max_ssid_length);
  787. /* Empty wildcard ssid with a maxlen will match many or
  788. potentially all SSIDs (maxlen == 32), therefore do
  789. not treat the scan as
  790. filtered. */
  791. if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
  792. ssid_filter = false;
  793. }
  794. /*
  795. * The default number of channels sent in the command is low to
  796. * ensure the response buffer from the firmware does not
  797. * truncate scan results. That is not an issue with an SSID
  798. * or BSSID filter applied to the scan results in the firmware.
  799. */
  800. if ((i && ssid_filter) ||
  801. !is_zero_ether_addr(scan_cfg_out->specific_bssid))
  802. *filtered_scan = true;
  803. } else {
  804. scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
  805. num_probes = adapter->scan_probes;
  806. }
  807. /*
  808. * If a specific BSSID or SSID is used, the number of channels in the
  809. * scan command will be increased to the absolute maximum.
  810. */
  811. if (*filtered_scan)
  812. *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
  813. else
  814. *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
  815. /* If the input config or adapter has the number of Probes set,
  816. add tlv */
  817. if (num_probes) {
  818. dev_dbg(adapter->dev, "info: scan: num_probes = %d\n",
  819. num_probes);
  820. num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
  821. num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
  822. num_probes_tlv->header.len =
  823. cpu_to_le16(sizeof(num_probes_tlv->num_probes));
  824. num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
  825. tlv_pos += sizeof(num_probes_tlv->header) +
  826. le16_to_cpu(num_probes_tlv->header.len);
  827. }
  828. if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
  829. (priv->adapter->config_bands & BAND_GN ||
  830. priv->adapter->config_bands & BAND_AN)) {
  831. ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
  832. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  833. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  834. ht_cap->header.len =
  835. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  836. radio_type =
  837. mwifiex_band_to_radio_type(priv->adapter->config_bands);
  838. mwifiex_fill_cap_info(priv, radio_type, ht_cap);
  839. tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
  840. }
  841. /* Append vendor specific IE TLV */
  842. mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
  843. /*
  844. * Set the output for the channel TLV to the address in the tlv buffer
  845. * past any TLVs that were added in this function (SSID, num_probes).
  846. * Channel TLVs will be added past this for each scan command,
  847. * preserving the TLVs that were previously added.
  848. */
  849. *chan_list_out =
  850. (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
  851. if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
  852. dev_dbg(adapter->dev, "info: Scan: Using supplied channel list\n");
  853. for (chan_idx = 0;
  854. chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX &&
  855. user_scan_in->chan_list[chan_idx].chan_number;
  856. chan_idx++) {
  857. channel = user_scan_in->chan_list[chan_idx].chan_number;
  858. (scan_chan_list + chan_idx)->chan_number = channel;
  859. radio_type =
  860. user_scan_in->chan_list[chan_idx].radio_type;
  861. (scan_chan_list + chan_idx)->radio_type = radio_type;
  862. scan_type = user_scan_in->chan_list[chan_idx].scan_type;
  863. if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
  864. (scan_chan_list +
  865. chan_idx)->chan_scan_mode_bitmap
  866. |= MWIFIEX_PASSIVE_SCAN;
  867. else
  868. (scan_chan_list +
  869. chan_idx)->chan_scan_mode_bitmap
  870. &= ~MWIFIEX_PASSIVE_SCAN;
  871. if (*filtered_scan)
  872. (scan_chan_list +
  873. chan_idx)->chan_scan_mode_bitmap
  874. |= MWIFIEX_DISABLE_CHAN_FILT;
  875. if (user_scan_in->chan_list[chan_idx].scan_time) {
  876. scan_dur = (u16) user_scan_in->
  877. chan_list[chan_idx].scan_time;
  878. } else {
  879. if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
  880. scan_dur = adapter->passive_scan_time;
  881. else if (*filtered_scan)
  882. scan_dur = adapter->specific_scan_time;
  883. else
  884. scan_dur = adapter->active_scan_time;
  885. }
  886. (scan_chan_list + chan_idx)->min_scan_time =
  887. cpu_to_le16(scan_dur);
  888. (scan_chan_list + chan_idx)->max_scan_time =
  889. cpu_to_le16(scan_dur);
  890. }
  891. /* Check if we are only scanning the current channel */
  892. if ((chan_idx == 1) &&
  893. (user_scan_in->chan_list[0].chan_number ==
  894. priv->curr_bss_params.bss_descriptor.channel)) {
  895. *scan_current_only = true;
  896. dev_dbg(adapter->dev,
  897. "info: Scan: Scanning current channel only\n");
  898. }
  899. chan_num = chan_idx;
  900. } else {
  901. dev_dbg(adapter->dev,
  902. "info: Scan: Creating full region channel list\n");
  903. chan_num = mwifiex_scan_create_channel_list(priv, user_scan_in,
  904. scan_chan_list,
  905. *filtered_scan);
  906. }
  907. /*
  908. * In associated state we will reduce the number of channels scanned per
  909. * scan command to avoid any traffic delay/loss. This number is decided
  910. * based on total number of channels to be scanned due to constraints
  911. * of command buffers.
  912. */
  913. if (priv->media_connected) {
  914. if (chan_num < MWIFIEX_LIMIT_1_CHANNEL_PER_SCAN_CMD)
  915. *max_chan_per_scan = 1;
  916. else if (chan_num < MWIFIEX_LIMIT_2_CHANNELS_PER_SCAN_CMD)
  917. *max_chan_per_scan = 2;
  918. else if (chan_num < MWIFIEX_LIMIT_3_CHANNELS_PER_SCAN_CMD)
  919. *max_chan_per_scan = 3;
  920. else
  921. *max_chan_per_scan = 4;
  922. }
  923. }
  924. /*
  925. * This function inspects the scan response buffer for pointers to
  926. * expected TLVs.
  927. *
  928. * TLVs can be included at the end of the scan response BSS information.
  929. *
  930. * Data in the buffer is parsed pointers to TLVs that can potentially
  931. * be passed back in the response.
  932. */
  933. static void
  934. mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
  935. struct mwifiex_ie_types_data *tlv,
  936. u32 tlv_buf_size, u32 req_tlv_type,
  937. struct mwifiex_ie_types_data **tlv_data)
  938. {
  939. struct mwifiex_ie_types_data *current_tlv;
  940. u32 tlv_buf_left;
  941. u32 tlv_type;
  942. u32 tlv_len;
  943. current_tlv = tlv;
  944. tlv_buf_left = tlv_buf_size;
  945. *tlv_data = NULL;
  946. dev_dbg(adapter->dev, "info: SCAN_RESP: tlv_buf_size = %d\n",
  947. tlv_buf_size);
  948. while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
  949. tlv_type = le16_to_cpu(current_tlv->header.type);
  950. tlv_len = le16_to_cpu(current_tlv->header.len);
  951. if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
  952. dev_err(adapter->dev, "SCAN_RESP: TLV buffer corrupt\n");
  953. break;
  954. }
  955. if (req_tlv_type == tlv_type) {
  956. switch (tlv_type) {
  957. case TLV_TYPE_TSFTIMESTAMP:
  958. dev_dbg(adapter->dev, "info: SCAN_RESP: TSF "
  959. "timestamp TLV, len = %d\n", tlv_len);
  960. *tlv_data = current_tlv;
  961. break;
  962. case TLV_TYPE_CHANNELBANDLIST:
  963. dev_dbg(adapter->dev, "info: SCAN_RESP: channel"
  964. " band list TLV, len = %d\n", tlv_len);
  965. *tlv_data = current_tlv;
  966. break;
  967. default:
  968. dev_err(adapter->dev,
  969. "SCAN_RESP: unhandled TLV = %d\n",
  970. tlv_type);
  971. /* Give up, this seems corrupted */
  972. return;
  973. }
  974. }
  975. if (*tlv_data)
  976. break;
  977. tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
  978. current_tlv =
  979. (struct mwifiex_ie_types_data *) (current_tlv->data +
  980. tlv_len);
  981. } /* while */
  982. }
  983. /*
  984. * This function parses provided beacon buffer and updates
  985. * respective fields in bss descriptor structure.
  986. */
  987. int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
  988. struct mwifiex_bssdescriptor *bss_entry)
  989. {
  990. int ret = 0;
  991. u8 element_id;
  992. struct ieee_types_fh_param_set *fh_param_set;
  993. struct ieee_types_ds_param_set *ds_param_set;
  994. struct ieee_types_cf_param_set *cf_param_set;
  995. struct ieee_types_ibss_param_set *ibss_param_set;
  996. u8 *current_ptr;
  997. u8 *rate;
  998. u8 element_len;
  999. u16 total_ie_len;
  1000. u8 bytes_to_copy;
  1001. u8 rate_size;
  1002. u8 found_data_rate_ie;
  1003. u32 bytes_left;
  1004. struct ieee_types_vendor_specific *vendor_ie;
  1005. const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
  1006. const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
  1007. found_data_rate_ie = false;
  1008. rate_size = 0;
  1009. current_ptr = bss_entry->beacon_buf;
  1010. bytes_left = bss_entry->beacon_buf_size;
  1011. /* Process variable IE */
  1012. while (bytes_left >= 2) {
  1013. element_id = *current_ptr;
  1014. element_len = *(current_ptr + 1);
  1015. total_ie_len = element_len + sizeof(struct ieee_types_header);
  1016. if (bytes_left < total_ie_len) {
  1017. dev_err(adapter->dev, "err: InterpretIE: in processing"
  1018. " IE, bytes left < IE length\n");
  1019. return -1;
  1020. }
  1021. switch (element_id) {
  1022. case WLAN_EID_SSID:
  1023. bss_entry->ssid.ssid_len = element_len;
  1024. memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
  1025. element_len);
  1026. dev_dbg(adapter->dev,
  1027. "info: InterpretIE: ssid: %-32s\n",
  1028. bss_entry->ssid.ssid);
  1029. break;
  1030. case WLAN_EID_SUPP_RATES:
  1031. memcpy(bss_entry->data_rates, current_ptr + 2,
  1032. element_len);
  1033. memcpy(bss_entry->supported_rates, current_ptr + 2,
  1034. element_len);
  1035. rate_size = element_len;
  1036. found_data_rate_ie = true;
  1037. break;
  1038. case WLAN_EID_FH_PARAMS:
  1039. fh_param_set =
  1040. (struct ieee_types_fh_param_set *) current_ptr;
  1041. memcpy(&bss_entry->phy_param_set.fh_param_set,
  1042. fh_param_set,
  1043. sizeof(struct ieee_types_fh_param_set));
  1044. break;
  1045. case WLAN_EID_DS_PARAMS:
  1046. ds_param_set =
  1047. (struct ieee_types_ds_param_set *) current_ptr;
  1048. bss_entry->channel = ds_param_set->current_chan;
  1049. memcpy(&bss_entry->phy_param_set.ds_param_set,
  1050. ds_param_set,
  1051. sizeof(struct ieee_types_ds_param_set));
  1052. break;
  1053. case WLAN_EID_CF_PARAMS:
  1054. cf_param_set =
  1055. (struct ieee_types_cf_param_set *) current_ptr;
  1056. memcpy(&bss_entry->ss_param_set.cf_param_set,
  1057. cf_param_set,
  1058. sizeof(struct ieee_types_cf_param_set));
  1059. break;
  1060. case WLAN_EID_IBSS_PARAMS:
  1061. ibss_param_set =
  1062. (struct ieee_types_ibss_param_set *)
  1063. current_ptr;
  1064. memcpy(&bss_entry->ss_param_set.ibss_param_set,
  1065. ibss_param_set,
  1066. sizeof(struct ieee_types_ibss_param_set));
  1067. break;
  1068. case WLAN_EID_ERP_INFO:
  1069. bss_entry->erp_flags = *(current_ptr + 2);
  1070. break;
  1071. case WLAN_EID_PWR_CONSTRAINT:
  1072. bss_entry->local_constraint = *(current_ptr + 2);
  1073. bss_entry->sensed_11h = true;
  1074. break;
  1075. case WLAN_EID_CHANNEL_SWITCH:
  1076. bss_entry->chan_sw_ie_present = true;
  1077. case WLAN_EID_PWR_CAPABILITY:
  1078. case WLAN_EID_TPC_REPORT:
  1079. case WLAN_EID_QUIET:
  1080. bss_entry->sensed_11h = true;
  1081. break;
  1082. case WLAN_EID_EXT_SUPP_RATES:
  1083. /*
  1084. * Only process extended supported rate
  1085. * if data rate is already found.
  1086. * Data rate IE should come before
  1087. * extended supported rate IE
  1088. */
  1089. if (found_data_rate_ie) {
  1090. if ((element_len + rate_size) >
  1091. MWIFIEX_SUPPORTED_RATES)
  1092. bytes_to_copy =
  1093. (MWIFIEX_SUPPORTED_RATES -
  1094. rate_size);
  1095. else
  1096. bytes_to_copy = element_len;
  1097. rate = (u8 *) bss_entry->data_rates;
  1098. rate += rate_size;
  1099. memcpy(rate, current_ptr + 2, bytes_to_copy);
  1100. rate = (u8 *) bss_entry->supported_rates;
  1101. rate += rate_size;
  1102. memcpy(rate, current_ptr + 2, bytes_to_copy);
  1103. }
  1104. break;
  1105. case WLAN_EID_VENDOR_SPECIFIC:
  1106. vendor_ie = (struct ieee_types_vendor_specific *)
  1107. current_ptr;
  1108. if (!memcmp
  1109. (vendor_ie->vend_hdr.oui, wpa_oui,
  1110. sizeof(wpa_oui))) {
  1111. bss_entry->bcn_wpa_ie =
  1112. (struct ieee_types_vendor_specific *)
  1113. current_ptr;
  1114. bss_entry->wpa_offset = (u16)
  1115. (current_ptr - bss_entry->beacon_buf);
  1116. } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui,
  1117. sizeof(wmm_oui))) {
  1118. if (total_ie_len ==
  1119. sizeof(struct ieee_types_wmm_parameter) ||
  1120. total_ie_len ==
  1121. sizeof(struct ieee_types_wmm_info))
  1122. /*
  1123. * Only accept and copy the WMM IE if
  1124. * it matches the size expected for the
  1125. * WMM Info IE or the WMM Parameter IE.
  1126. */
  1127. memcpy((u8 *) &bss_entry->wmm_ie,
  1128. current_ptr, total_ie_len);
  1129. }
  1130. break;
  1131. case WLAN_EID_RSN:
  1132. bss_entry->bcn_rsn_ie =
  1133. (struct ieee_types_generic *) current_ptr;
  1134. bss_entry->rsn_offset = (u16) (current_ptr -
  1135. bss_entry->beacon_buf);
  1136. break;
  1137. case WLAN_EID_BSS_AC_ACCESS_DELAY:
  1138. bss_entry->bcn_wapi_ie =
  1139. (struct ieee_types_generic *) current_ptr;
  1140. bss_entry->wapi_offset = (u16) (current_ptr -
  1141. bss_entry->beacon_buf);
  1142. break;
  1143. case WLAN_EID_HT_CAPABILITY:
  1144. bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
  1145. (current_ptr +
  1146. sizeof(struct ieee_types_header));
  1147. bss_entry->ht_cap_offset = (u16) (current_ptr +
  1148. sizeof(struct ieee_types_header) -
  1149. bss_entry->beacon_buf);
  1150. break;
  1151. case WLAN_EID_HT_OPERATION:
  1152. bss_entry->bcn_ht_oper =
  1153. (struct ieee80211_ht_operation *)(current_ptr +
  1154. sizeof(struct ieee_types_header));
  1155. bss_entry->ht_info_offset = (u16) (current_ptr +
  1156. sizeof(struct ieee_types_header) -
  1157. bss_entry->beacon_buf);
  1158. break;
  1159. case WLAN_EID_VHT_CAPABILITY:
  1160. bss_entry->disable_11ac = false;
  1161. bss_entry->bcn_vht_cap =
  1162. (void *)(current_ptr +
  1163. sizeof(struct ieee_types_header));
  1164. bss_entry->vht_cap_offset =
  1165. (u16)((u8 *)bss_entry->bcn_vht_cap -
  1166. bss_entry->beacon_buf);
  1167. break;
  1168. case WLAN_EID_VHT_OPERATION:
  1169. bss_entry->bcn_vht_oper =
  1170. (void *)(current_ptr +
  1171. sizeof(struct ieee_types_header));
  1172. bss_entry->vht_info_offset =
  1173. (u16)((u8 *)bss_entry->bcn_vht_oper -
  1174. bss_entry->beacon_buf);
  1175. break;
  1176. case WLAN_EID_BSS_COEX_2040:
  1177. bss_entry->bcn_bss_co_2040 = current_ptr +
  1178. sizeof(struct ieee_types_header);
  1179. bss_entry->bss_co_2040_offset = (u16) (current_ptr +
  1180. sizeof(struct ieee_types_header) -
  1181. bss_entry->beacon_buf);
  1182. break;
  1183. case WLAN_EID_EXT_CAPABILITY:
  1184. bss_entry->bcn_ext_cap = current_ptr +
  1185. sizeof(struct ieee_types_header);
  1186. bss_entry->ext_cap_offset = (u16) (current_ptr +
  1187. sizeof(struct ieee_types_header) -
  1188. bss_entry->beacon_buf);
  1189. break;
  1190. case WLAN_EID_OPMODE_NOTIF:
  1191. bss_entry->oper_mode =
  1192. (void *)(current_ptr +
  1193. sizeof(struct ieee_types_header));
  1194. bss_entry->oper_mode_offset =
  1195. (u16)((u8 *)bss_entry->oper_mode -
  1196. bss_entry->beacon_buf);
  1197. break;
  1198. default:
  1199. break;
  1200. }
  1201. current_ptr += element_len + 2;
  1202. /* Need to account for IE ID and IE Len */
  1203. bytes_left -= (element_len + 2);
  1204. } /* while (bytes_left > 2) */
  1205. return ret;
  1206. }
  1207. /*
  1208. * This function converts radio type scan parameter to a band configuration
  1209. * to be used in join command.
  1210. */
  1211. static u8
  1212. mwifiex_radio_type_to_band(u8 radio_type)
  1213. {
  1214. switch (radio_type) {
  1215. case HostCmd_SCAN_RADIO_TYPE_A:
  1216. return BAND_A;
  1217. case HostCmd_SCAN_RADIO_TYPE_BG:
  1218. default:
  1219. return BAND_G;
  1220. }
  1221. }
  1222. /*
  1223. * This is an internal function used to start a scan based on an input
  1224. * configuration.
  1225. *
  1226. * This uses the input user scan configuration information when provided in
  1227. * order to send the appropriate scan commands to firmware to populate or
  1228. * update the internal driver scan table.
  1229. */
  1230. int mwifiex_scan_networks(struct mwifiex_private *priv,
  1231. const struct mwifiex_user_scan_cfg *user_scan_in)
  1232. {
  1233. int ret;
  1234. struct mwifiex_adapter *adapter = priv->adapter;
  1235. struct cmd_ctrl_node *cmd_node;
  1236. union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
  1237. struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
  1238. struct mwifiex_chan_scan_param_set *scan_chan_list;
  1239. u8 filtered_scan;
  1240. u8 scan_current_chan_only;
  1241. u8 max_chan_per_scan;
  1242. unsigned long flags;
  1243. if (adapter->scan_processing) {
  1244. dev_err(adapter->dev, "cmd: Scan already in process...\n");
  1245. return -EBUSY;
  1246. }
  1247. if (priv->scan_block) {
  1248. dev_err(adapter->dev,
  1249. "cmd: Scan is blocked during association...\n");
  1250. return -EBUSY;
  1251. }
  1252. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  1253. adapter->scan_processing = true;
  1254. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  1255. scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
  1256. GFP_KERNEL);
  1257. if (!scan_cfg_out) {
  1258. ret = -ENOMEM;
  1259. goto done;
  1260. }
  1261. scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
  1262. sizeof(struct mwifiex_chan_scan_param_set),
  1263. GFP_KERNEL);
  1264. if (!scan_chan_list) {
  1265. kfree(scan_cfg_out);
  1266. ret = -ENOMEM;
  1267. goto done;
  1268. }
  1269. mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config,
  1270. &chan_list_out, scan_chan_list, &max_chan_per_scan,
  1271. &filtered_scan, &scan_current_chan_only);
  1272. ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
  1273. &scan_cfg_out->config, chan_list_out,
  1274. scan_chan_list);
  1275. /* Get scan command from scan_pending_q and put to cmd_pending_q */
  1276. if (!ret) {
  1277. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  1278. if (!list_empty(&adapter->scan_pending_q)) {
  1279. cmd_node = list_first_entry(&adapter->scan_pending_q,
  1280. struct cmd_ctrl_node, list);
  1281. list_del(&cmd_node->list);
  1282. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  1283. flags);
  1284. mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
  1285. true);
  1286. queue_work(adapter->workqueue, &adapter->main_work);
  1287. /* Perform internal scan synchronously */
  1288. if (!priv->scan_request) {
  1289. dev_dbg(adapter->dev, "wait internal scan\n");
  1290. mwifiex_wait_queue_complete(adapter, cmd_node);
  1291. }
  1292. } else {
  1293. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  1294. flags);
  1295. }
  1296. }
  1297. kfree(scan_cfg_out);
  1298. kfree(scan_chan_list);
  1299. done:
  1300. if (ret) {
  1301. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  1302. adapter->scan_processing = false;
  1303. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  1304. }
  1305. return ret;
  1306. }
  1307. /*
  1308. * This function prepares a scan command to be sent to the firmware.
  1309. *
  1310. * This uses the scan command configuration sent to the command processing
  1311. * module in command preparation stage to configure a scan command structure
  1312. * to send to firmware.
  1313. *
  1314. * The fixed fields specifying the BSS type and BSSID filters as well as a
  1315. * variable number/length of TLVs are sent in the command to firmware.
  1316. *
  1317. * Preparation also includes -
  1318. * - Setting command ID, and proper size
  1319. * - Ensuring correct endian-ness
  1320. */
  1321. int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
  1322. struct mwifiex_scan_cmd_config *scan_cfg)
  1323. {
  1324. struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
  1325. /* Set fixed field variables in scan command */
  1326. scan_cmd->bss_mode = scan_cfg->bss_mode;
  1327. memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
  1328. sizeof(scan_cmd->bssid));
  1329. memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
  1330. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
  1331. /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
  1332. cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
  1333. + sizeof(scan_cmd->bssid)
  1334. + scan_cfg->tlv_buf_len + S_DS_GEN));
  1335. return 0;
  1336. }
  1337. /*
  1338. * This function checks compatibility of requested network with current
  1339. * driver settings.
  1340. */
  1341. int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
  1342. struct mwifiex_bssdescriptor *bss_desc)
  1343. {
  1344. int ret = -1;
  1345. if (!bss_desc)
  1346. return -1;
  1347. if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
  1348. (u16) bss_desc->channel, 0))) {
  1349. switch (priv->bss_mode) {
  1350. case NL80211_IFTYPE_STATION:
  1351. case NL80211_IFTYPE_ADHOC:
  1352. ret = mwifiex_is_network_compatible(priv, bss_desc,
  1353. priv->bss_mode);
  1354. if (ret)
  1355. dev_err(priv->adapter->dev,
  1356. "Incompatible network settings\n");
  1357. break;
  1358. default:
  1359. ret = 0;
  1360. }
  1361. }
  1362. return ret;
  1363. }
  1364. static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
  1365. struct cfg80211_bss *bss)
  1366. {
  1367. struct mwifiex_bssdescriptor *bss_desc;
  1368. int ret;
  1369. unsigned long flags;
  1370. /* Allocate and fill new bss descriptor */
  1371. bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
  1372. if (!bss_desc)
  1373. return -ENOMEM;
  1374. ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
  1375. if (ret)
  1376. goto done;
  1377. ret = mwifiex_check_network_compatibility(priv, bss_desc);
  1378. if (ret)
  1379. goto done;
  1380. spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
  1381. /* Make a copy of current BSSID descriptor */
  1382. memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
  1383. sizeof(priv->curr_bss_params.bss_descriptor));
  1384. /* The contents of beacon_ie will be copied to its own buffer
  1385. * in mwifiex_save_curr_bcn()
  1386. */
  1387. mwifiex_save_curr_bcn(priv);
  1388. spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
  1389. done:
  1390. /* beacon_ie buffer was allocated in function
  1391. * mwifiex_fill_new_bss_desc(). Free it now.
  1392. */
  1393. kfree(bss_desc->beacon_buf);
  1394. kfree(bss_desc);
  1395. return 0;
  1396. }
  1397. /*
  1398. * This function handles the command response of scan.
  1399. *
  1400. * The response buffer for the scan command has the following
  1401. * memory layout:
  1402. *
  1403. * .-------------------------------------------------------------.
  1404. * | Header (4 * sizeof(t_u16)): Standard command response hdr |
  1405. * .-------------------------------------------------------------.
  1406. * | BufSize (t_u16) : sizeof the BSS Description data |
  1407. * .-------------------------------------------------------------.
  1408. * | NumOfSet (t_u8) : Number of BSS Descs returned |
  1409. * .-------------------------------------------------------------.
  1410. * | BSSDescription data (variable, size given in BufSize) |
  1411. * .-------------------------------------------------------------.
  1412. * | TLV data (variable, size calculated using Header->Size, |
  1413. * | BufSize and sizeof the fixed fields above) |
  1414. * .-------------------------------------------------------------.
  1415. */
  1416. int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
  1417. struct host_cmd_ds_command *resp)
  1418. {
  1419. int ret = 0;
  1420. struct mwifiex_adapter *adapter = priv->adapter;
  1421. struct cmd_ctrl_node *cmd_node;
  1422. struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
  1423. struct mwifiex_ie_types_data *tlv_data;
  1424. struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
  1425. u8 *bss_info;
  1426. u32 scan_resp_size;
  1427. u32 bytes_left;
  1428. u32 idx;
  1429. u32 tlv_buf_size;
  1430. struct mwifiex_chan_freq_power *cfp;
  1431. struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
  1432. struct chan_band_param_set *chan_band;
  1433. u8 is_bgscan_resp;
  1434. unsigned long flags;
  1435. struct cfg80211_bss *bss;
  1436. is_bgscan_resp = (le16_to_cpu(resp->command)
  1437. == HostCmd_CMD_802_11_BG_SCAN_QUERY);
  1438. if (is_bgscan_resp)
  1439. scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
  1440. else
  1441. scan_rsp = &resp->params.scan_resp;
  1442. if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
  1443. dev_err(adapter->dev, "SCAN_RESP: too many AP returned (%d)\n",
  1444. scan_rsp->number_of_sets);
  1445. ret = -1;
  1446. goto check_next_scan;
  1447. }
  1448. /* Check csa channel expiry before parsing scan response */
  1449. mwifiex_11h_get_csa_closed_channel(priv);
  1450. bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
  1451. dev_dbg(adapter->dev, "info: SCAN_RESP: bss_descript_size %d\n",
  1452. bytes_left);
  1453. scan_resp_size = le16_to_cpu(resp->size);
  1454. dev_dbg(adapter->dev,
  1455. "info: SCAN_RESP: returned %d APs before parsing\n",
  1456. scan_rsp->number_of_sets);
  1457. bss_info = scan_rsp->bss_desc_and_tlv_buffer;
  1458. /*
  1459. * The size of the TLV buffer is equal to the entire command response
  1460. * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
  1461. * BSS Descriptions (bss_descript_size as bytesLef) and the command
  1462. * response header (S_DS_GEN)
  1463. */
  1464. tlv_buf_size = scan_resp_size - (bytes_left
  1465. + sizeof(scan_rsp->bss_descript_size)
  1466. + sizeof(scan_rsp->number_of_sets)
  1467. + S_DS_GEN);
  1468. tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
  1469. bss_desc_and_tlv_buffer +
  1470. bytes_left);
  1471. /* Search the TLV buffer space in the scan response for any valid
  1472. TLVs */
  1473. mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
  1474. TLV_TYPE_TSFTIMESTAMP,
  1475. (struct mwifiex_ie_types_data **)
  1476. &tsf_tlv);
  1477. /* Search the TLV buffer space in the scan response for any valid
  1478. TLVs */
  1479. mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
  1480. TLV_TYPE_CHANNELBANDLIST,
  1481. (struct mwifiex_ie_types_data **)
  1482. &chan_band_tlv);
  1483. for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
  1484. u8 bssid[ETH_ALEN];
  1485. s32 rssi;
  1486. const u8 *ie_buf;
  1487. size_t ie_len;
  1488. u16 channel = 0;
  1489. u64 fw_tsf = 0;
  1490. u16 beacon_size = 0;
  1491. u32 curr_bcn_bytes;
  1492. u32 freq;
  1493. u16 beacon_period;
  1494. u16 cap_info_bitmap;
  1495. u8 *current_ptr;
  1496. u64 timestamp;
  1497. struct mwifiex_bcn_param *bcn_param;
  1498. struct mwifiex_bss_priv *bss_priv;
  1499. if (bytes_left >= sizeof(beacon_size)) {
  1500. /* Extract & convert beacon size from command buffer */
  1501. memcpy(&beacon_size, bss_info, sizeof(beacon_size));
  1502. bytes_left -= sizeof(beacon_size);
  1503. bss_info += sizeof(beacon_size);
  1504. }
  1505. if (!beacon_size || beacon_size > bytes_left) {
  1506. bss_info += bytes_left;
  1507. bytes_left = 0;
  1508. ret = -1;
  1509. goto check_next_scan;
  1510. }
  1511. /* Initialize the current working beacon pointer for this BSS
  1512. * iteration */
  1513. current_ptr = bss_info;
  1514. /* Advance the return beacon pointer past the current beacon */
  1515. bss_info += beacon_size;
  1516. bytes_left -= beacon_size;
  1517. curr_bcn_bytes = beacon_size;
  1518. /*
  1519. * First 5 fields are bssid, RSSI, time stamp, beacon interval,
  1520. * and capability information
  1521. */
  1522. if (curr_bcn_bytes < sizeof(struct mwifiex_bcn_param)) {
  1523. dev_err(adapter->dev,
  1524. "InterpretIE: not enough bytes left\n");
  1525. continue;
  1526. }
  1527. bcn_param = (struct mwifiex_bcn_param *)current_ptr;
  1528. current_ptr += sizeof(*bcn_param);
  1529. curr_bcn_bytes -= sizeof(*bcn_param);
  1530. memcpy(bssid, bcn_param->bssid, ETH_ALEN);
  1531. rssi = (s32) bcn_param->rssi;
  1532. rssi = (-rssi) * 100; /* Convert dBm to mBm */
  1533. dev_dbg(adapter->dev, "info: InterpretIE: RSSI=%d\n", rssi);
  1534. timestamp = le64_to_cpu(bcn_param->timestamp);
  1535. beacon_period = le16_to_cpu(bcn_param->beacon_period);
  1536. cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
  1537. dev_dbg(adapter->dev, "info: InterpretIE: capabilities=0x%X\n",
  1538. cap_info_bitmap);
  1539. /* Rest of the current buffer are IE's */
  1540. ie_buf = current_ptr;
  1541. ie_len = curr_bcn_bytes;
  1542. dev_dbg(adapter->dev,
  1543. "info: InterpretIE: IELength for this AP = %d\n",
  1544. curr_bcn_bytes);
  1545. while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) {
  1546. u8 element_id, element_len;
  1547. element_id = *current_ptr;
  1548. element_len = *(current_ptr + 1);
  1549. if (curr_bcn_bytes < element_len +
  1550. sizeof(struct ieee_types_header)) {
  1551. dev_err(priv->adapter->dev,
  1552. "%s: bytes left < IE length\n",
  1553. __func__);
  1554. goto check_next_scan;
  1555. }
  1556. if (element_id == WLAN_EID_DS_PARAMS) {
  1557. channel = *(current_ptr + sizeof(struct ieee_types_header));
  1558. break;
  1559. }
  1560. current_ptr += element_len +
  1561. sizeof(struct ieee_types_header);
  1562. curr_bcn_bytes -= element_len +
  1563. sizeof(struct ieee_types_header);
  1564. }
  1565. /*
  1566. * If the TSF TLV was appended to the scan results, save this
  1567. * entry's TSF value in the fw_tsf field. It is the firmware's
  1568. * TSF value at the time the beacon or probe response was
  1569. * received.
  1570. */
  1571. if (tsf_tlv)
  1572. memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
  1573. sizeof(fw_tsf));
  1574. if (channel) {
  1575. struct ieee80211_channel *chan;
  1576. u8 band;
  1577. /* Skip entry if on csa closed channel */
  1578. if (channel == priv->csa_chan) {
  1579. dev_dbg(adapter->dev,
  1580. "Dropping entry on csa closed channel\n");
  1581. continue;
  1582. }
  1583. band = BAND_G;
  1584. if (chan_band_tlv) {
  1585. chan_band =
  1586. &chan_band_tlv->chan_band_param[idx];
  1587. band = mwifiex_radio_type_to_band(
  1588. chan_band->radio_type
  1589. & (BIT(0) | BIT(1)));
  1590. }
  1591. cfp = mwifiex_get_cfp(priv, band, channel, 0);
  1592. freq = cfp ? cfp->freq : 0;
  1593. chan = ieee80211_get_channel(priv->wdev->wiphy, freq);
  1594. if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
  1595. bss = cfg80211_inform_bss(priv->wdev->wiphy,
  1596. chan, bssid, timestamp,
  1597. cap_info_bitmap, beacon_period,
  1598. ie_buf, ie_len, rssi, GFP_KERNEL);
  1599. bss_priv = (struct mwifiex_bss_priv *)bss->priv;
  1600. bss_priv->band = band;
  1601. bss_priv->fw_tsf = fw_tsf;
  1602. if (priv->media_connected &&
  1603. !memcmp(bssid,
  1604. priv->curr_bss_params.bss_descriptor
  1605. .mac_address, ETH_ALEN))
  1606. mwifiex_update_curr_bss_params(priv,
  1607. bss);
  1608. cfg80211_put_bss(priv->wdev->wiphy, bss);
  1609. }
  1610. } else {
  1611. dev_dbg(adapter->dev, "missing BSS channel IE\n");
  1612. }
  1613. }
  1614. check_next_scan:
  1615. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  1616. if (list_empty(&adapter->scan_pending_q)) {
  1617. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  1618. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  1619. adapter->scan_processing = false;
  1620. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  1621. /* Need to indicate IOCTL complete */
  1622. if (adapter->curr_cmd->wait_q_enabled) {
  1623. adapter->cmd_wait_q.status = 0;
  1624. if (!priv->scan_request) {
  1625. dev_dbg(adapter->dev,
  1626. "complete internal scan\n");
  1627. mwifiex_complete_cmd(adapter,
  1628. adapter->curr_cmd);
  1629. }
  1630. }
  1631. if (priv->report_scan_result)
  1632. priv->report_scan_result = false;
  1633. if (priv->scan_request) {
  1634. dev_dbg(adapter->dev, "info: notifying scan done\n");
  1635. cfg80211_scan_done(priv->scan_request, 0);
  1636. priv->scan_request = NULL;
  1637. } else {
  1638. priv->scan_aborting = false;
  1639. dev_dbg(adapter->dev, "info: scan already aborted\n");
  1640. }
  1641. } else {
  1642. if ((priv->scan_aborting && !priv->scan_request) ||
  1643. priv->scan_block) {
  1644. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  1645. flags);
  1646. adapter->scan_delay_cnt = MWIFIEX_MAX_SCAN_DELAY_CNT;
  1647. mod_timer(&priv->scan_delay_timer, jiffies);
  1648. dev_dbg(priv->adapter->dev,
  1649. "info: %s: triggerring scan abort\n", __func__);
  1650. } else if (!mwifiex_wmm_lists_empty(adapter) &&
  1651. (priv->scan_request && (priv->scan_request->flags &
  1652. NL80211_SCAN_FLAG_LOW_PRIORITY))) {
  1653. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  1654. flags);
  1655. adapter->scan_delay_cnt = 1;
  1656. mod_timer(&priv->scan_delay_timer, jiffies +
  1657. msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
  1658. dev_dbg(priv->adapter->dev,
  1659. "info: %s: deferring scan\n", __func__);
  1660. } else {
  1661. /* Get scan command from scan_pending_q and put to
  1662. cmd_pending_q */
  1663. cmd_node = list_first_entry(&adapter->scan_pending_q,
  1664. struct cmd_ctrl_node, list);
  1665. list_del(&cmd_node->list);
  1666. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  1667. flags);
  1668. mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
  1669. true);
  1670. }
  1671. }
  1672. return ret;
  1673. }
  1674. /*
  1675. * This function prepares command for background scan query.
  1676. *
  1677. * Preparation includes -
  1678. * - Setting command ID and proper size
  1679. * - Setting background scan flush parameter
  1680. * - Ensuring correct endian-ness
  1681. */
  1682. int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
  1683. {
  1684. struct host_cmd_ds_802_11_bg_scan_query *bg_query =
  1685. &cmd->params.bg_scan_query;
  1686. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
  1687. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
  1688. + S_DS_GEN);
  1689. bg_query->flush = 1;
  1690. return 0;
  1691. }
  1692. /*
  1693. * This function inserts scan command node to the scan pending queue.
  1694. */
  1695. void
  1696. mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
  1697. struct cmd_ctrl_node *cmd_node)
  1698. {
  1699. struct mwifiex_adapter *adapter = priv->adapter;
  1700. unsigned long flags;
  1701. cmd_node->wait_q_enabled = true;
  1702. cmd_node->condition = &adapter->scan_wait_q_woken;
  1703. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  1704. list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
  1705. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  1706. }
  1707. /*
  1708. * This function sends a scan command for all available channels to the
  1709. * firmware, filtered on a specific SSID.
  1710. */
  1711. static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
  1712. struct cfg80211_ssid *req_ssid)
  1713. {
  1714. struct mwifiex_adapter *adapter = priv->adapter;
  1715. int ret;
  1716. struct mwifiex_user_scan_cfg *scan_cfg;
  1717. if (adapter->scan_processing) {
  1718. dev_err(adapter->dev, "cmd: Scan already in process...\n");
  1719. return -EBUSY;
  1720. }
  1721. if (priv->scan_block) {
  1722. dev_err(adapter->dev,
  1723. "cmd: Scan is blocked during association...\n");
  1724. return -EBUSY;
  1725. }
  1726. scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
  1727. if (!scan_cfg)
  1728. return -ENOMEM;
  1729. scan_cfg->ssid_list = req_ssid;
  1730. scan_cfg->num_ssids = 1;
  1731. ret = mwifiex_scan_networks(priv, scan_cfg);
  1732. kfree(scan_cfg);
  1733. return ret;
  1734. }
  1735. /*
  1736. * Sends IOCTL request to start a scan.
  1737. *
  1738. * This function allocates the IOCTL request buffer, fills it
  1739. * with requisite parameters and calls the IOCTL handler.
  1740. *
  1741. * Scan command can be issued for both normal scan and specific SSID
  1742. * scan, depending upon whether an SSID is provided or not.
  1743. */
  1744. int mwifiex_request_scan(struct mwifiex_private *priv,
  1745. struct cfg80211_ssid *req_ssid)
  1746. {
  1747. int ret;
  1748. if (down_interruptible(&priv->async_sem)) {
  1749. dev_err(priv->adapter->dev, "%s: acquire semaphore\n",
  1750. __func__);
  1751. return -1;
  1752. }
  1753. priv->adapter->scan_wait_q_woken = false;
  1754. if (req_ssid && req_ssid->ssid_len != 0)
  1755. /* Specific SSID scan */
  1756. ret = mwifiex_scan_specific_ssid(priv, req_ssid);
  1757. else
  1758. /* Normal scan */
  1759. ret = mwifiex_scan_networks(priv, NULL);
  1760. up(&priv->async_sem);
  1761. return ret;
  1762. }
  1763. /*
  1764. * This function appends the vendor specific IE TLV to a buffer.
  1765. */
  1766. int
  1767. mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
  1768. u16 vsie_mask, u8 **buffer)
  1769. {
  1770. int id, ret_len = 0;
  1771. struct mwifiex_ie_types_vendor_param_set *vs_param_set;
  1772. if (!buffer)
  1773. return 0;
  1774. if (!(*buffer))
  1775. return 0;
  1776. /*
  1777. * Traverse through the saved vendor specific IE array and append
  1778. * the selected(scan/assoc/adhoc) IE as TLV to the command
  1779. */
  1780. for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
  1781. if (priv->vs_ie[id].mask & vsie_mask) {
  1782. vs_param_set =
  1783. (struct mwifiex_ie_types_vendor_param_set *)
  1784. *buffer;
  1785. vs_param_set->header.type =
  1786. cpu_to_le16(TLV_TYPE_PASSTHROUGH);
  1787. vs_param_set->header.len =
  1788. cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
  1789. & 0x00FF) + 2);
  1790. memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
  1791. le16_to_cpu(vs_param_set->header.len));
  1792. *buffer += le16_to_cpu(vs_param_set->header.len) +
  1793. sizeof(struct mwifiex_ie_types_header);
  1794. ret_len += le16_to_cpu(vs_param_set->header.len) +
  1795. sizeof(struct mwifiex_ie_types_header);
  1796. }
  1797. }
  1798. return ret_len;
  1799. }
  1800. /*
  1801. * This function saves a beacon buffer of the current BSS descriptor.
  1802. *
  1803. * The current beacon buffer is saved so that it can be restored in the
  1804. * following cases that makes the beacon buffer not to contain the current
  1805. * ssid's beacon buffer.
  1806. * - The current ssid was not found somehow in the last scan.
  1807. * - The current ssid was the last entry of the scan table and overloaded.
  1808. */
  1809. void
  1810. mwifiex_save_curr_bcn(struct mwifiex_private *priv)
  1811. {
  1812. struct mwifiex_bssdescriptor *curr_bss =
  1813. &priv->curr_bss_params.bss_descriptor;
  1814. if (!curr_bss->beacon_buf_size)
  1815. return;
  1816. /* allocate beacon buffer at 1st time; or if it's size has changed */
  1817. if (!priv->curr_bcn_buf ||
  1818. priv->curr_bcn_size != curr_bss->beacon_buf_size) {
  1819. priv->curr_bcn_size = curr_bss->beacon_buf_size;
  1820. kfree(priv->curr_bcn_buf);
  1821. priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
  1822. GFP_ATOMIC);
  1823. if (!priv->curr_bcn_buf)
  1824. return;
  1825. }
  1826. memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
  1827. curr_bss->beacon_buf_size);
  1828. dev_dbg(priv->adapter->dev, "info: current beacon saved %d\n",
  1829. priv->curr_bcn_size);
  1830. curr_bss->beacon_buf = priv->curr_bcn_buf;
  1831. /* adjust the pointers in the current BSS descriptor */
  1832. if (curr_bss->bcn_wpa_ie)
  1833. curr_bss->bcn_wpa_ie =
  1834. (struct ieee_types_vendor_specific *)
  1835. (curr_bss->beacon_buf +
  1836. curr_bss->wpa_offset);
  1837. if (curr_bss->bcn_rsn_ie)
  1838. curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
  1839. (curr_bss->beacon_buf +
  1840. curr_bss->rsn_offset);
  1841. if (curr_bss->bcn_ht_cap)
  1842. curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
  1843. (curr_bss->beacon_buf +
  1844. curr_bss->ht_cap_offset);
  1845. if (curr_bss->bcn_ht_oper)
  1846. curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
  1847. (curr_bss->beacon_buf +
  1848. curr_bss->ht_info_offset);
  1849. if (curr_bss->bcn_vht_cap)
  1850. curr_bss->bcn_ht_cap = (void *)(curr_bss->beacon_buf +
  1851. curr_bss->vht_cap_offset);
  1852. if (curr_bss->bcn_vht_oper)
  1853. curr_bss->bcn_ht_oper = (void *)(curr_bss->beacon_buf +
  1854. curr_bss->vht_info_offset);
  1855. if (curr_bss->bcn_bss_co_2040)
  1856. curr_bss->bcn_bss_co_2040 =
  1857. (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
  1858. if (curr_bss->bcn_ext_cap)
  1859. curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
  1860. curr_bss->ext_cap_offset;
  1861. if (curr_bss->oper_mode)
  1862. curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
  1863. curr_bss->oper_mode_offset);
  1864. }
  1865. /*
  1866. * This function frees the current BSS descriptor beacon buffer.
  1867. */
  1868. void
  1869. mwifiex_free_curr_bcn(struct mwifiex_private *priv)
  1870. {
  1871. kfree(priv->curr_bcn_buf);
  1872. priv->curr_bcn_buf = NULL;
  1873. }