scan.c 62 KB

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