scan.c 72 KB

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