scan.c 60 KB

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