scan.c 60 KB

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