scan.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098
  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 = NULL;
  105. struct ie_body *iebody = NULL;
  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 = NULL;
  130. struct ie_body *iebody = NULL;
  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 mwifiex_802_11_ssid *ssid1,
  147. struct mwifiex_802_11_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. * Sends IOCTL request to get the best BSS.
  155. *
  156. * This function allocates the IOCTL request buffer, fills it
  157. * with requisite parameters and calls the IOCTL handler.
  158. */
  159. int mwifiex_find_best_bss(struct mwifiex_private *priv,
  160. u8 wait_option, struct mwifiex_ssid_bssid *ssid_bssid)
  161. {
  162. struct mwifiex_wait_queue *wait = NULL;
  163. struct mwifiex_ssid_bssid tmp_ssid_bssid;
  164. int ret = 0;
  165. u8 *mac = NULL;
  166. if (!ssid_bssid)
  167. return -1;
  168. /* Allocate wait request buffer */
  169. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  170. if (!wait)
  171. return -ENOMEM;
  172. memcpy(&tmp_ssid_bssid, ssid_bssid,
  173. sizeof(struct mwifiex_ssid_bssid));
  174. ret = mwifiex_bss_ioctl_find_bss(priv, wait, &tmp_ssid_bssid);
  175. if (!ret) {
  176. memcpy(ssid_bssid, &tmp_ssid_bssid,
  177. sizeof(struct mwifiex_ssid_bssid));
  178. mac = (u8 *) &ssid_bssid->bssid;
  179. dev_dbg(priv->adapter->dev, "cmd: found network: ssid=%s,"
  180. " %pM\n", ssid_bssid->ssid.ssid, mac);
  181. }
  182. kfree(wait);
  183. return ret;
  184. }
  185. /*
  186. * Sends IOCTL request to start a scan with user configurations.
  187. *
  188. * This function allocates the IOCTL request buffer, fills it
  189. * with requisite parameters and calls the IOCTL handler.
  190. *
  191. * Upon completion, it also generates a wireless event to notify
  192. * applications.
  193. */
  194. int mwifiex_set_user_scan_ioctl(struct mwifiex_private *priv,
  195. struct mwifiex_user_scan_cfg *scan_req)
  196. {
  197. struct mwifiex_wait_queue *wait = NULL;
  198. int status = 0;
  199. u8 wait_option = MWIFIEX_IOCTL_WAIT;
  200. /* Allocate an IOCTL request buffer */
  201. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  202. if (!wait)
  203. return -ENOMEM;
  204. status = mwifiex_scan_networks(priv, wait, HostCmd_ACT_GEN_SET,
  205. scan_req, NULL);
  206. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  207. if (wait && (status != -EINPROGRESS))
  208. kfree(wait);
  209. return status;
  210. }
  211. /*
  212. * This function checks if wapi is enabled in driver and scanned network is
  213. * compatible with it.
  214. */
  215. static bool
  216. mwifiex_is_network_compatible_for_wapi(struct mwifiex_private *priv,
  217. struct mwifiex_bssdescriptor *bss_desc)
  218. {
  219. if (priv->sec_info.wapi_enabled &&
  220. (bss_desc->bcn_wapi_ie &&
  221. ((*(bss_desc->bcn_wapi_ie)).ieee_hdr.element_id ==
  222. WLAN_EID_BSS_AC_ACCESS_DELAY))) {
  223. return true;
  224. }
  225. return false;
  226. }
  227. /*
  228. * This function checks if driver is configured with no security mode and
  229. * scanned network is compatible with it.
  230. */
  231. static bool
  232. mwifiex_is_network_compatible_for_no_sec(struct mwifiex_private *priv,
  233. struct mwifiex_bssdescriptor *bss_desc)
  234. {
  235. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED
  236. && !priv->sec_info.wpa_enabled && !priv->sec_info.wpa2_enabled
  237. && ((!bss_desc->bcn_wpa_ie) ||
  238. ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id !=
  239. WLAN_EID_WPA))
  240. && ((!bss_desc->bcn_rsn_ie) ||
  241. ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id !=
  242. WLAN_EID_RSN))
  243. && priv->sec_info.encryption_mode ==
  244. MWIFIEX_ENCRYPTION_MODE_NONE && !bss_desc->privacy) {
  245. return true;
  246. }
  247. return false;
  248. }
  249. /*
  250. * This function checks if static WEP is enabled in driver and scanned network
  251. * is compatible with it.
  252. */
  253. static bool
  254. mwifiex_is_network_compatible_for_static_wep(struct mwifiex_private *priv,
  255. struct mwifiex_bssdescriptor *bss_desc)
  256. {
  257. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED
  258. && !priv->sec_info.wpa_enabled && !priv->sec_info.wpa2_enabled
  259. && bss_desc->privacy) {
  260. return true;
  261. }
  262. return false;
  263. }
  264. /*
  265. * This function checks if wpa is enabled in driver and scanned network is
  266. * compatible with it.
  267. */
  268. static bool
  269. mwifiex_is_network_compatible_for_wpa(struct mwifiex_private *priv,
  270. struct mwifiex_bssdescriptor *bss_desc,
  271. int index)
  272. {
  273. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED
  274. && priv->sec_info.wpa_enabled && !priv->sec_info.wpa2_enabled
  275. && ((bss_desc->bcn_wpa_ie) && ((*(bss_desc->bcn_wpa_ie)).vend_hdr.
  276. element_id == WLAN_EID_WPA))
  277. /*
  278. * Privacy bit may NOT be set in some APs like
  279. * LinkSys WRT54G && bss_desc->privacy
  280. */
  281. ) {
  282. dev_dbg(priv->adapter->dev, "info: %s: WPA: index=%d"
  283. " wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
  284. "EncMode=%#x privacy=%#x\n", __func__, index,
  285. (bss_desc->bcn_wpa_ie) ?
  286. (*(bss_desc->bcn_wpa_ie)).
  287. vend_hdr.element_id : 0,
  288. (bss_desc->bcn_rsn_ie) ?
  289. (*(bss_desc->bcn_rsn_ie)).
  290. ieee_hdr.element_id : 0,
  291. (priv->sec_info.wep_status ==
  292. MWIFIEX_802_11_WEP_ENABLED) ? "e" : "d",
  293. (priv->sec_info.wpa_enabled) ? "e" : "d",
  294. (priv->sec_info.wpa2_enabled) ? "e" : "d",
  295. priv->sec_info.encryption_mode,
  296. bss_desc->privacy);
  297. return true;
  298. }
  299. return false;
  300. }
  301. /*
  302. * This function checks if wpa2 is enabled in driver and scanned network is
  303. * compatible with it.
  304. */
  305. static bool
  306. mwifiex_is_network_compatible_for_wpa2(struct mwifiex_private *priv,
  307. struct mwifiex_bssdescriptor *bss_desc,
  308. int index)
  309. {
  310. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED
  311. && !priv->sec_info.wpa_enabled && priv->sec_info.wpa2_enabled
  312. && ((bss_desc->bcn_rsn_ie) && ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.
  313. element_id == WLAN_EID_RSN))
  314. /*
  315. * Privacy bit may NOT be set in some APs like
  316. * LinkSys WRT54G && bss_desc->privacy
  317. */
  318. ) {
  319. dev_dbg(priv->adapter->dev, "info: %s: WPA2: index=%d"
  320. " wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
  321. "EncMode=%#x privacy=%#x\n", __func__, index,
  322. (bss_desc->bcn_wpa_ie) ?
  323. (*(bss_desc->bcn_wpa_ie)).
  324. vend_hdr.element_id : 0,
  325. (bss_desc->bcn_rsn_ie) ?
  326. (*(bss_desc->bcn_rsn_ie)).
  327. ieee_hdr.element_id : 0,
  328. (priv->sec_info.wep_status ==
  329. MWIFIEX_802_11_WEP_ENABLED) ? "e" : "d",
  330. (priv->sec_info.wpa_enabled) ? "e" : "d",
  331. (priv->sec_info.wpa2_enabled) ? "e" : "d",
  332. priv->sec_info.encryption_mode,
  333. bss_desc->privacy);
  334. return true;
  335. }
  336. return false;
  337. }
  338. /*
  339. * This function checks if adhoc AES is enabled in driver and scanned network is
  340. * compatible with it.
  341. */
  342. static bool
  343. mwifiex_is_network_compatible_for_adhoc_aes(struct mwifiex_private *priv,
  344. struct mwifiex_bssdescriptor *bss_desc)
  345. {
  346. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED
  347. && !priv->sec_info.wpa_enabled && !priv->sec_info.wpa2_enabled
  348. && ((!bss_desc->bcn_wpa_ie) || ((*(bss_desc->bcn_wpa_ie)).vend_hdr.
  349. element_id != WLAN_EID_WPA))
  350. && ((!bss_desc->bcn_rsn_ie) || ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.
  351. element_id != WLAN_EID_RSN))
  352. && priv->sec_info.encryption_mode ==
  353. MWIFIEX_ENCRYPTION_MODE_NONE && bss_desc->privacy) {
  354. return true;
  355. }
  356. return false;
  357. }
  358. /*
  359. * This function checks if dynamic WEP is enabled in driver and scanned network
  360. * is compatible with it.
  361. */
  362. static bool
  363. mwifiex_is_network_compatible_for_dynamic_wep(struct mwifiex_private *priv,
  364. struct mwifiex_bssdescriptor *bss_desc,
  365. int index)
  366. {
  367. if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_DISABLED
  368. && !priv->sec_info.wpa_enabled && !priv->sec_info.wpa2_enabled
  369. && ((!bss_desc->bcn_wpa_ie) || ((*(bss_desc->bcn_wpa_ie)).vend_hdr.
  370. element_id != WLAN_EID_WPA))
  371. && ((!bss_desc->bcn_rsn_ie) || ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.
  372. element_id != WLAN_EID_RSN))
  373. && priv->sec_info.encryption_mode !=
  374. MWIFIEX_ENCRYPTION_MODE_NONE && bss_desc->privacy) {
  375. dev_dbg(priv->adapter->dev, "info: %s: dynamic "
  376. "WEP: index=%d wpa_ie=%#x wpa2_ie=%#x "
  377. "EncMode=%#x privacy=%#x\n",
  378. __func__, index,
  379. (bss_desc->bcn_wpa_ie) ?
  380. (*(bss_desc->bcn_wpa_ie)).
  381. vend_hdr.element_id : 0,
  382. (bss_desc->bcn_rsn_ie) ?
  383. (*(bss_desc->bcn_rsn_ie)).
  384. ieee_hdr.element_id : 0,
  385. priv->sec_info.encryption_mode,
  386. bss_desc->privacy);
  387. return true;
  388. }
  389. return false;
  390. }
  391. /*
  392. * This function checks if a scanned network is compatible with the driver
  393. * settings.
  394. *
  395. * WEP WPA WPA2 ad-hoc encrypt Network
  396. * enabled enabled enabled AES mode Privacy WPA WPA2 Compatible
  397. * 0 0 0 0 NONE 0 0 0 yes No security
  398. * 0 1 0 0 x 1x 1 x yes WPA (disable
  399. * HT if no AES)
  400. * 0 0 1 0 x 1x x 1 yes WPA2 (disable
  401. * HT if no AES)
  402. * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
  403. * 1 0 0 0 NONE 1 0 0 yes Static WEP
  404. * (disable HT)
  405. * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
  406. *
  407. * Compatibility is not matched while roaming, except for mode.
  408. */
  409. static s32
  410. mwifiex_is_network_compatible(struct mwifiex_private *priv, u32 index, u32 mode)
  411. {
  412. struct mwifiex_adapter *adapter = priv->adapter;
  413. struct mwifiex_bssdescriptor *bss_desc;
  414. bss_desc = &adapter->scan_table[index];
  415. bss_desc->disable_11n = false;
  416. /* Don't check for compatibility if roaming */
  417. if (priv->media_connected && (priv->bss_mode == MWIFIEX_BSS_MODE_INFRA)
  418. && (bss_desc->bss_mode == MWIFIEX_BSS_MODE_INFRA))
  419. return index;
  420. if (priv->wps.session_enable) {
  421. dev_dbg(adapter->dev,
  422. "info: return success directly in WPS period\n");
  423. return index;
  424. }
  425. if (mwifiex_is_network_compatible_for_wapi(priv, bss_desc)) {
  426. dev_dbg(adapter->dev, "info: return success for WAPI AP\n");
  427. return index;
  428. }
  429. if (bss_desc->bss_mode == mode) {
  430. if (mwifiex_is_network_compatible_for_no_sec(priv, bss_desc)) {
  431. /* No security */
  432. return index;
  433. } else if (mwifiex_is_network_compatible_for_static_wep(priv,
  434. bss_desc)) {
  435. /* Static WEP enabled */
  436. dev_dbg(adapter->dev, "info: Disable 11n in WEP mode.\n");
  437. bss_desc->disable_11n = true;
  438. return index;
  439. } else if (mwifiex_is_network_compatible_for_wpa(priv, bss_desc,
  440. index)) {
  441. /* WPA enabled */
  442. if (((priv->adapter->config_bands & BAND_GN
  443. || priv->adapter->config_bands & BAND_AN)
  444. && bss_desc->bcn_ht_cap)
  445. && !mwifiex_is_wpa_oui_present(bss_desc,
  446. CIPHER_SUITE_CCMP)) {
  447. if (mwifiex_is_wpa_oui_present(bss_desc,
  448. CIPHER_SUITE_TKIP)) {
  449. dev_dbg(adapter->dev,
  450. "info: Disable 11n if AES "
  451. "is not supported by AP\n");
  452. bss_desc->disable_11n = true;
  453. } else {
  454. return -1;
  455. }
  456. }
  457. return index;
  458. } else if (mwifiex_is_network_compatible_for_wpa2(priv,
  459. bss_desc, index)) {
  460. /* WPA2 enabled */
  461. if (((priv->adapter->config_bands & BAND_GN
  462. || priv->adapter->config_bands & BAND_AN)
  463. && bss_desc->bcn_ht_cap)
  464. && !mwifiex_is_rsn_oui_present(bss_desc,
  465. CIPHER_SUITE_CCMP)) {
  466. if (mwifiex_is_rsn_oui_present(bss_desc,
  467. CIPHER_SUITE_TKIP)) {
  468. dev_dbg(adapter->dev,
  469. "info: Disable 11n if AES "
  470. "is not supported by AP\n");
  471. bss_desc->disable_11n = true;
  472. } else {
  473. return -1;
  474. }
  475. }
  476. return index;
  477. } else if (mwifiex_is_network_compatible_for_adhoc_aes(priv,
  478. bss_desc)) {
  479. /* Ad-hoc AES enabled */
  480. return index;
  481. } else if (mwifiex_is_network_compatible_for_dynamic_wep(priv,
  482. bss_desc, index)) {
  483. /* Dynamic WEP enabled */
  484. return index;
  485. }
  486. /* Security doesn't match */
  487. dev_dbg(adapter->dev, "info: %s: failed: index=%d "
  488. "wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s EncMode"
  489. "=%#x privacy=%#x\n",
  490. __func__, index,
  491. (bss_desc->bcn_wpa_ie) ?
  492. (*(bss_desc->bcn_wpa_ie)).vend_hdr.
  493. element_id : 0,
  494. (bss_desc->bcn_rsn_ie) ?
  495. (*(bss_desc->bcn_rsn_ie)).ieee_hdr.
  496. element_id : 0,
  497. (priv->sec_info.wep_status ==
  498. MWIFIEX_802_11_WEP_ENABLED) ? "e" : "d",
  499. (priv->sec_info.wpa_enabled) ? "e" : "d",
  500. (priv->sec_info.wpa2_enabled) ? "e" : "d",
  501. priv->sec_info.encryption_mode, bss_desc->privacy);
  502. return -1;
  503. }
  504. /* Mode doesn't match */
  505. return -1;
  506. }
  507. /*
  508. * This function finds the best SSID in the scan list.
  509. *
  510. * It searches the scan table for the best SSID that also matches the current
  511. * adapter network preference (mode, security etc.).
  512. */
  513. static s32
  514. mwifiex_find_best_network_in_list(struct mwifiex_private *priv)
  515. {
  516. struct mwifiex_adapter *adapter = priv->adapter;
  517. u32 mode = priv->bss_mode;
  518. s32 best_net = -1;
  519. s32 best_rssi = 0;
  520. u32 i;
  521. dev_dbg(adapter->dev, "info: num of BSSIDs = %d\n",
  522. adapter->num_in_scan_table);
  523. for (i = 0; i < adapter->num_in_scan_table; i++) {
  524. switch (mode) {
  525. case MWIFIEX_BSS_MODE_INFRA:
  526. case MWIFIEX_BSS_MODE_IBSS:
  527. if (mwifiex_is_network_compatible(priv, i, mode) >= 0) {
  528. if (SCAN_RSSI(adapter->scan_table[i].rssi) >
  529. best_rssi) {
  530. best_rssi = SCAN_RSSI(adapter->
  531. scan_table[i].rssi);
  532. best_net = i;
  533. }
  534. }
  535. break;
  536. case MWIFIEX_BSS_MODE_AUTO:
  537. default:
  538. if (SCAN_RSSI(adapter->scan_table[i].rssi) >
  539. best_rssi) {
  540. best_rssi = SCAN_RSSI(adapter->scan_table[i].
  541. rssi);
  542. best_net = i;
  543. }
  544. break;
  545. }
  546. }
  547. return best_net;
  548. }
  549. /*
  550. * This function creates a channel list for the driver to scan, based
  551. * on region/band information.
  552. *
  553. * This routine is used for any scan that is not provided with a
  554. * specific channel list to scan.
  555. */
  556. static void
  557. mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
  558. const struct mwifiex_user_scan_cfg
  559. *user_scan_in,
  560. struct mwifiex_chan_scan_param_set
  561. *scan_chan_list,
  562. u8 filtered_scan)
  563. {
  564. enum ieee80211_band band;
  565. struct ieee80211_supported_band *sband;
  566. struct ieee80211_channel *ch;
  567. struct mwifiex_adapter *adapter = priv->adapter;
  568. int chan_idx = 0, i;
  569. u8 scan_type;
  570. for (band = 0; (band < IEEE80211_NUM_BANDS) ; band++) {
  571. if (!priv->wdev->wiphy->bands[band])
  572. continue;
  573. sband = priv->wdev->wiphy->bands[band];
  574. for (i = 0; (i < sband->n_channels) ; i++, chan_idx++) {
  575. ch = &sband->channels[i];
  576. if (ch->flags & IEEE80211_CHAN_DISABLED)
  577. continue;
  578. scan_chan_list[chan_idx].radio_type = band;
  579. scan_type = ch->flags & IEEE80211_CHAN_PASSIVE_SCAN;
  580. if (user_scan_in &&
  581. user_scan_in->chan_list[0].scan_time)
  582. scan_chan_list[chan_idx].max_scan_time =
  583. cpu_to_le16((u16) user_scan_in->
  584. chan_list[0].scan_time);
  585. else if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
  586. scan_chan_list[chan_idx].max_scan_time =
  587. cpu_to_le16(adapter->passive_scan_time);
  588. else
  589. scan_chan_list[chan_idx].max_scan_time =
  590. cpu_to_le16(adapter->active_scan_time);
  591. if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
  592. scan_chan_list[chan_idx].chan_scan_mode_bitmap
  593. |= MWIFIEX_PASSIVE_SCAN;
  594. else
  595. scan_chan_list[chan_idx].chan_scan_mode_bitmap
  596. &= ~MWIFIEX_PASSIVE_SCAN;
  597. scan_chan_list[chan_idx].chan_number =
  598. (u32) ch->hw_value;
  599. if (filtered_scan) {
  600. scan_chan_list[chan_idx].max_scan_time =
  601. cpu_to_le16(adapter->specific_scan_time);
  602. scan_chan_list[chan_idx].chan_scan_mode_bitmap
  603. |= MWIFIEX_DISABLE_CHAN_FILT;
  604. }
  605. }
  606. }
  607. }
  608. /*
  609. * This function constructs and sends multiple scan config commands to
  610. * the firmware.
  611. *
  612. * Previous routines in the code flow have created a scan command configuration
  613. * with any requested TLVs. This function splits the channel TLV into maximum
  614. * channels supported per scan lists and sends the portion of the channel TLV,
  615. * along with the other TLVs, to the firmware.
  616. */
  617. static int
  618. mwifiex_scan_channel_list(struct mwifiex_private *priv, void *wait_buf,
  619. u32 max_chan_per_scan, u8 filtered_scan,
  620. struct mwifiex_scan_cmd_config *scan_cfg_out,
  621. struct mwifiex_ie_types_chan_list_param_set
  622. *chan_tlv_out,
  623. struct mwifiex_chan_scan_param_set *scan_chan_list)
  624. {
  625. int ret = 0;
  626. struct mwifiex_chan_scan_param_set *tmp_chan_list;
  627. struct mwifiex_chan_scan_param_set *start_chan;
  628. u32 tlv_idx;
  629. u32 total_scan_time;
  630. u32 done_early;
  631. if (!scan_cfg_out || !chan_tlv_out || !scan_chan_list) {
  632. dev_dbg(priv->adapter->dev,
  633. "info: Scan: Null detect: %p, %p, %p\n",
  634. scan_cfg_out, chan_tlv_out, scan_chan_list);
  635. return -1;
  636. }
  637. chan_tlv_out->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
  638. /* Set the temp channel struct pointer to the start of the desired
  639. list */
  640. tmp_chan_list = scan_chan_list;
  641. /* Loop through the desired channel list, sending a new firmware scan
  642. commands for each max_chan_per_scan channels (or for 1,6,11
  643. individually if configured accordingly) */
  644. while (tmp_chan_list->chan_number) {
  645. tlv_idx = 0;
  646. total_scan_time = 0;
  647. chan_tlv_out->header.len = 0;
  648. start_chan = tmp_chan_list;
  649. done_early = false;
  650. /*
  651. * Construct the Channel TLV for the scan command. Continue to
  652. * insert channel TLVs until:
  653. * - the tlv_idx hits the maximum configured per scan command
  654. * - the next channel to insert is 0 (end of desired channel
  655. * list)
  656. * - done_early is set (controlling individual scanning of
  657. * 1,6,11)
  658. */
  659. while (tlv_idx < max_chan_per_scan
  660. && tmp_chan_list->chan_number && !done_early) {
  661. dev_dbg(priv->adapter->dev,
  662. "info: Scan: Chan(%3d), Radio(%d),"
  663. " Mode(%d, %d), Dur(%d)\n",
  664. tmp_chan_list->chan_number,
  665. tmp_chan_list->radio_type,
  666. tmp_chan_list->chan_scan_mode_bitmap
  667. & MWIFIEX_PASSIVE_SCAN,
  668. (tmp_chan_list->chan_scan_mode_bitmap
  669. & MWIFIEX_DISABLE_CHAN_FILT) >> 1,
  670. le16_to_cpu(tmp_chan_list->max_scan_time));
  671. /* Copy the current channel TLV to the command being
  672. prepared */
  673. memcpy(chan_tlv_out->chan_scan_param + tlv_idx,
  674. tmp_chan_list,
  675. sizeof(chan_tlv_out->chan_scan_param));
  676. /* Increment the TLV header length by the size
  677. appended */
  678. chan_tlv_out->header.len =
  679. cpu_to_le16(le16_to_cpu(chan_tlv_out->header.len) +
  680. (sizeof(chan_tlv_out->chan_scan_param)));
  681. /*
  682. * The tlv buffer length is set to the number of bytes
  683. * of the between the channel tlv pointer and the start
  684. * of the tlv buffer. This compensates for any TLVs
  685. * that were appended before the channel list.
  686. */
  687. scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
  688. scan_cfg_out->tlv_buf);
  689. /* Add the size of the channel tlv header and the data
  690. length */
  691. scan_cfg_out->tlv_buf_len +=
  692. (sizeof(chan_tlv_out->header)
  693. + le16_to_cpu(chan_tlv_out->header.len));
  694. /* Increment the index to the channel tlv we are
  695. constructing */
  696. tlv_idx++;
  697. /* Count the total scan time per command */
  698. total_scan_time +=
  699. le16_to_cpu(tmp_chan_list->max_scan_time);
  700. done_early = false;
  701. /* Stop the loop if the *current* channel is in the
  702. 1,6,11 set and we are not filtering on a BSSID
  703. or SSID. */
  704. if (!filtered_scan && (tmp_chan_list->chan_number == 1
  705. || tmp_chan_list->chan_number == 6
  706. || tmp_chan_list->chan_number == 11))
  707. done_early = true;
  708. /* Increment the tmp pointer to the next channel to
  709. be scanned */
  710. tmp_chan_list++;
  711. /* Stop the loop if the *next* channel is in the 1,6,11
  712. set. This will cause it to be the only channel
  713. scanned on the next interation */
  714. if (!filtered_scan && (tmp_chan_list->chan_number == 1
  715. || tmp_chan_list->chan_number == 6
  716. || tmp_chan_list->chan_number == 11))
  717. done_early = true;
  718. }
  719. /* The total scan time should be less than scan command timeout
  720. value */
  721. if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
  722. dev_err(priv->adapter->dev, "total scan time %dms"
  723. " is over limit (%dms), scan skipped\n",
  724. total_scan_time, MWIFIEX_MAX_TOTAL_SCAN_TIME);
  725. ret = -1;
  726. break;
  727. }
  728. priv->adapter->scan_channels = start_chan;
  729. /* Send the scan command to the firmware with the specified
  730. cfg */
  731. ret = mwifiex_prepare_cmd(priv, HostCmd_CMD_802_11_SCAN,
  732. HostCmd_ACT_GEN_SET,
  733. 0, wait_buf, scan_cfg_out);
  734. if (ret)
  735. break;
  736. }
  737. if (ret)
  738. return -1;
  739. return 0;
  740. }
  741. /*
  742. * This function constructs a scan command configuration structure to use
  743. * in scan commands.
  744. *
  745. * Application layer or other functions can invoke network scanning
  746. * with a scan configuration supplied in a user scan configuration structure.
  747. * This structure is used as the basis of one or many scan command configuration
  748. * commands that are sent to the command processing module and eventually to the
  749. * firmware.
  750. *
  751. * This function creates a scan command configuration structure based on the
  752. * following user supplied parameters (if present):
  753. * - SSID filter
  754. * - BSSID filter
  755. * - Number of Probes to be sent
  756. * - Channel list
  757. *
  758. * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
  759. * If the number of probes is not set, adapter default setting is used.
  760. */
  761. static void
  762. mwifiex_scan_setup_scan_config(struct mwifiex_private *priv,
  763. const struct mwifiex_user_scan_cfg *user_scan_in,
  764. struct mwifiex_scan_cmd_config *scan_cfg_out,
  765. struct mwifiex_ie_types_chan_list_param_set
  766. **chan_list_out,
  767. struct mwifiex_chan_scan_param_set
  768. *scan_chan_list,
  769. u8 *max_chan_per_scan, u8 *filtered_scan,
  770. u8 *scan_current_only)
  771. {
  772. struct mwifiex_adapter *adapter = priv->adapter;
  773. struct mwifiex_ie_types_num_probes *num_probes_tlv;
  774. struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
  775. struct mwifiex_ie_types_rates_param_set *rates_tlv;
  776. const u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  777. u8 *tlv_pos;
  778. u32 num_probes;
  779. u32 ssid_len;
  780. u32 chan_idx;
  781. u32 scan_type;
  782. u16 scan_dur;
  783. u8 channel;
  784. u8 radio_type;
  785. u32 ssid_idx;
  786. u8 ssid_filter;
  787. u8 rates[MWIFIEX_SUPPORTED_RATES];
  788. u32 rates_size;
  789. struct mwifiex_ie_types_htcap *ht_cap;
  790. /* The tlv_buf_len is calculated for each scan command. The TLVs added
  791. in this routine will be preserved since the routine that sends the
  792. command will append channelTLVs at *chan_list_out. The difference
  793. between the *chan_list_out and the tlv_buf start will be used to
  794. calculate the size of anything we add in this routine. */
  795. scan_cfg_out->tlv_buf_len = 0;
  796. /* Running tlv pointer. Assigned to chan_list_out at end of function
  797. so later routines know where channels can be added to the command
  798. buf */
  799. tlv_pos = scan_cfg_out->tlv_buf;
  800. /* Initialize the scan as un-filtered; the flag is later set to TRUE
  801. below if a SSID or BSSID filter is sent in the command */
  802. *filtered_scan = false;
  803. /* Initialize the scan as not being only on the current channel. If
  804. the channel list is customized, only contains one channel, and is
  805. the active channel, this is set true and data flow is not halted. */
  806. *scan_current_only = false;
  807. if (user_scan_in) {
  808. /* Default the ssid_filter flag to TRUE, set false under
  809. certain wildcard conditions and qualified by the existence
  810. of an SSID list before marking the scan as filtered */
  811. ssid_filter = true;
  812. /* Set the BSS type scan filter, use Adapter setting if
  813. unset */
  814. scan_cfg_out->bss_mode =
  815. (user_scan_in->bss_mode ? (u8) user_scan_in->
  816. bss_mode : (u8) adapter->scan_mode);
  817. /* Set the number of probes to send, use Adapter setting
  818. if unset */
  819. num_probes =
  820. (user_scan_in->num_probes ? user_scan_in->
  821. num_probes : adapter->scan_probes);
  822. /*
  823. * Set the BSSID filter to the incoming configuration,
  824. * if non-zero. If not set, it will remain disabled
  825. * (all zeros).
  826. */
  827. memcpy(scan_cfg_out->specific_bssid,
  828. user_scan_in->specific_bssid,
  829. sizeof(scan_cfg_out->specific_bssid));
  830. for (ssid_idx = 0;
  831. ((ssid_idx < ARRAY_SIZE(user_scan_in->ssid_list))
  832. && (*user_scan_in->ssid_list[ssid_idx].ssid
  833. || user_scan_in->ssid_list[ssid_idx].max_len));
  834. ssid_idx++) {
  835. ssid_len = strlen(user_scan_in->ssid_list[ssid_idx].
  836. ssid) + 1;
  837. wildcard_ssid_tlv =
  838. (struct mwifiex_ie_types_wildcard_ssid_params *)
  839. tlv_pos;
  840. wildcard_ssid_tlv->header.type =
  841. cpu_to_le16(TLV_TYPE_WILDCARDSSID);
  842. wildcard_ssid_tlv->header.len = cpu_to_le16(
  843. (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
  844. max_ssid_length)));
  845. wildcard_ssid_tlv->max_ssid_length =
  846. user_scan_in->ssid_list[ssid_idx].max_len;
  847. memcpy(wildcard_ssid_tlv->ssid,
  848. user_scan_in->ssid_list[ssid_idx].ssid,
  849. ssid_len);
  850. tlv_pos += (sizeof(wildcard_ssid_tlv->header)
  851. + le16_to_cpu(wildcard_ssid_tlv->header.len));
  852. dev_dbg(adapter->dev, "info: scan: ssid_list[%d]: %s, %d\n",
  853. ssid_idx, wildcard_ssid_tlv->ssid,
  854. wildcard_ssid_tlv->max_ssid_length);
  855. /* Empty wildcard ssid with a maxlen will match many or
  856. potentially all SSIDs (maxlen == 32), therefore do
  857. not treat the scan as
  858. filtered. */
  859. if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
  860. ssid_filter = false;
  861. }
  862. /*
  863. * The default number of channels sent in the command is low to
  864. * ensure the response buffer from the firmware does not
  865. * truncate scan results. That is not an issue with an SSID
  866. * or BSSID filter applied to the scan results in the firmware.
  867. */
  868. if ((ssid_idx && ssid_filter)
  869. || memcmp(scan_cfg_out->specific_bssid, &zero_mac,
  870. sizeof(zero_mac)))
  871. *filtered_scan = true;
  872. } else {
  873. scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
  874. num_probes = adapter->scan_probes;
  875. }
  876. /*
  877. * If a specific BSSID or SSID is used, the number of channels in the
  878. * scan command will be increased to the absolute maximum.
  879. */
  880. if (*filtered_scan)
  881. *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
  882. else
  883. *max_chan_per_scan = MWIFIEX_CHANNELS_PER_SCAN_CMD;
  884. /* If the input config or adapter has the number of Probes set,
  885. add tlv */
  886. if (num_probes) {
  887. dev_dbg(adapter->dev, "info: scan: num_probes = %d\n",
  888. num_probes);
  889. num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
  890. num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
  891. num_probes_tlv->header.len =
  892. cpu_to_le16(sizeof(num_probes_tlv->num_probes));
  893. num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
  894. tlv_pos += sizeof(num_probes_tlv->header) +
  895. le16_to_cpu(num_probes_tlv->header.len);
  896. }
  897. /* Append rates tlv */
  898. memset(rates, 0, sizeof(rates));
  899. rates_size = mwifiex_get_supported_rates(priv, rates);
  900. rates_tlv = (struct mwifiex_ie_types_rates_param_set *) tlv_pos;
  901. rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
  902. rates_tlv->header.len = cpu_to_le16((u16) rates_size);
  903. memcpy(rates_tlv->rates, rates, rates_size);
  904. tlv_pos += sizeof(rates_tlv->header) + rates_size;
  905. dev_dbg(adapter->dev, "info: SCAN_CMD: Rates size = %d\n", rates_size);
  906. if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)
  907. && (priv->adapter->config_bands & BAND_GN
  908. || priv->adapter->config_bands & BAND_AN)) {
  909. ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
  910. memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
  911. ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  912. ht_cap->header.len =
  913. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  914. mwifiex_fill_cap_info(priv, ht_cap);
  915. tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
  916. }
  917. /* Append vendor specific IE TLV */
  918. mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
  919. /*
  920. * Set the output for the channel TLV to the address in the tlv buffer
  921. * past any TLVs that were added in this function (SSID, num_probes).
  922. * Channel TLVs will be added past this for each scan command,
  923. * preserving the TLVs that were previously added.
  924. */
  925. *chan_list_out =
  926. (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
  927. if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
  928. dev_dbg(adapter->dev, "info: Scan: Using supplied channel list\n");
  929. for (chan_idx = 0;
  930. chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX
  931. && user_scan_in->chan_list[chan_idx].chan_number;
  932. chan_idx++) {
  933. channel = user_scan_in->chan_list[chan_idx].chan_number;
  934. (scan_chan_list + chan_idx)->chan_number = channel;
  935. radio_type =
  936. user_scan_in->chan_list[chan_idx].radio_type;
  937. (scan_chan_list + chan_idx)->radio_type = radio_type;
  938. scan_type = user_scan_in->chan_list[chan_idx].scan_type;
  939. if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
  940. (scan_chan_list +
  941. chan_idx)->chan_scan_mode_bitmap
  942. |= MWIFIEX_PASSIVE_SCAN;
  943. else
  944. (scan_chan_list +
  945. chan_idx)->chan_scan_mode_bitmap
  946. &= ~MWIFIEX_PASSIVE_SCAN;
  947. if (user_scan_in->chan_list[chan_idx].scan_time) {
  948. scan_dur = (u16) user_scan_in->
  949. chan_list[chan_idx].scan_time;
  950. } else {
  951. if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
  952. scan_dur = adapter->passive_scan_time;
  953. else if (*filtered_scan)
  954. scan_dur = adapter->specific_scan_time;
  955. else
  956. scan_dur = adapter->active_scan_time;
  957. }
  958. (scan_chan_list + chan_idx)->min_scan_time =
  959. cpu_to_le16(scan_dur);
  960. (scan_chan_list + chan_idx)->max_scan_time =
  961. cpu_to_le16(scan_dur);
  962. }
  963. /* Check if we are only scanning the current channel */
  964. if ((chan_idx == 1)
  965. && (user_scan_in->chan_list[0].chan_number
  966. == priv->curr_bss_params.bss_descriptor.channel)) {
  967. *scan_current_only = true;
  968. dev_dbg(adapter->dev,
  969. "info: Scan: Scanning current channel only\n");
  970. }
  971. } else {
  972. dev_dbg(adapter->dev,
  973. "info: Scan: Creating full region channel list\n");
  974. mwifiex_scan_create_channel_list(priv, user_scan_in,
  975. scan_chan_list,
  976. *filtered_scan);
  977. }
  978. }
  979. /*
  980. * This function inspects the scan response buffer for pointers to
  981. * expected TLVs.
  982. *
  983. * TLVs can be included at the end of the scan response BSS information.
  984. *
  985. * Data in the buffer is parsed pointers to TLVs that can potentially
  986. * be passed back in the response.
  987. */
  988. static void
  989. mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
  990. struct mwifiex_ie_types_data *tlv,
  991. u32 tlv_buf_size, u32 req_tlv_type,
  992. struct mwifiex_ie_types_data **tlv_data)
  993. {
  994. struct mwifiex_ie_types_data *current_tlv;
  995. u32 tlv_buf_left;
  996. u32 tlv_type;
  997. u32 tlv_len;
  998. current_tlv = tlv;
  999. tlv_buf_left = tlv_buf_size;
  1000. *tlv_data = NULL;
  1001. dev_dbg(adapter->dev, "info: SCAN_RESP: tlv_buf_size = %d\n",
  1002. tlv_buf_size);
  1003. while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
  1004. tlv_type = le16_to_cpu(current_tlv->header.type);
  1005. tlv_len = le16_to_cpu(current_tlv->header.len);
  1006. if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
  1007. dev_err(adapter->dev, "SCAN_RESP: TLV buffer corrupt\n");
  1008. break;
  1009. }
  1010. if (req_tlv_type == tlv_type) {
  1011. switch (tlv_type) {
  1012. case TLV_TYPE_TSFTIMESTAMP:
  1013. dev_dbg(adapter->dev, "info: SCAN_RESP: TSF "
  1014. "timestamp TLV, len = %d\n", tlv_len);
  1015. *tlv_data = (struct mwifiex_ie_types_data *)
  1016. current_tlv;
  1017. break;
  1018. case TLV_TYPE_CHANNELBANDLIST:
  1019. dev_dbg(adapter->dev, "info: SCAN_RESP: channel"
  1020. " band list TLV, len = %d\n", tlv_len);
  1021. *tlv_data = (struct mwifiex_ie_types_data *)
  1022. current_tlv;
  1023. break;
  1024. default:
  1025. dev_err(adapter->dev,
  1026. "SCAN_RESP: unhandled TLV = %d\n",
  1027. tlv_type);
  1028. /* Give up, this seems corrupted */
  1029. return;
  1030. }
  1031. }
  1032. if (*tlv_data)
  1033. break;
  1034. tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
  1035. current_tlv =
  1036. (struct mwifiex_ie_types_data *) (current_tlv->data +
  1037. tlv_len);
  1038. } /* while */
  1039. }
  1040. /*
  1041. * This function interprets a BSS scan response returned from the firmware.
  1042. *
  1043. * The various fixed fields and IEs are parsed and passed back for a BSS
  1044. * probe response or beacon from scan command. Information is recorded as
  1045. * needed in the scan table for that entry.
  1046. *
  1047. * The following IE types are recognized and parsed -
  1048. * - SSID
  1049. * - Supported rates
  1050. * - FH parameters set
  1051. * - DS parameters set
  1052. * - CF parameters set
  1053. * - IBSS parameters set
  1054. * - ERP information
  1055. * - Extended supported rates
  1056. * - Vendor specific (221)
  1057. * - RSN IE
  1058. * - WAPI IE
  1059. * - HT capability
  1060. * - HT operation
  1061. * - BSS Coexistence 20/40
  1062. * - Extended capability
  1063. * - Overlapping BSS scan parameters
  1064. */
  1065. static int
  1066. mwifiex_interpret_bss_desc_with_ie(struct mwifiex_adapter *adapter,
  1067. struct mwifiex_bssdescriptor *bss_entry,
  1068. u8 **beacon_info, u32 *bytes_left)
  1069. {
  1070. int ret = 0;
  1071. u8 element_id;
  1072. struct ieee_types_fh_param_set *fh_param_set;
  1073. struct ieee_types_ds_param_set *ds_param_set;
  1074. struct ieee_types_cf_param_set *cf_param_set;
  1075. struct ieee_types_ibss_param_set *ibss_param_set;
  1076. struct mwifiex_802_11_fixed_ies fixed_ie;
  1077. u8 *current_ptr;
  1078. u8 *rate;
  1079. u8 element_len;
  1080. u16 total_ie_len;
  1081. u8 bytes_to_copy;
  1082. u8 rate_size;
  1083. u16 beacon_size;
  1084. u8 found_data_rate_ie;
  1085. u32 bytes_left_for_current_beacon;
  1086. struct ieee_types_vendor_specific *vendor_ie;
  1087. const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
  1088. const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
  1089. found_data_rate_ie = false;
  1090. rate_size = 0;
  1091. beacon_size = 0;
  1092. if (*bytes_left >= sizeof(beacon_size)) {
  1093. /* Extract & convert beacon size from the command buffer */
  1094. memcpy(&beacon_size, *beacon_info, sizeof(beacon_size));
  1095. *bytes_left -= sizeof(beacon_size);
  1096. *beacon_info += sizeof(beacon_size);
  1097. }
  1098. if (!beacon_size || beacon_size > *bytes_left) {
  1099. *beacon_info += *bytes_left;
  1100. *bytes_left = 0;
  1101. return -1;
  1102. }
  1103. /* Initialize the current working beacon pointer for this BSS
  1104. iteration */
  1105. current_ptr = *beacon_info;
  1106. /* Advance the return beacon pointer past the current beacon */
  1107. *beacon_info += beacon_size;
  1108. *bytes_left -= beacon_size;
  1109. bytes_left_for_current_beacon = beacon_size;
  1110. memcpy(bss_entry->mac_address, current_ptr, ETH_ALEN);
  1111. dev_dbg(adapter->dev, "info: InterpretIE: AP MAC Addr: %pM\n",
  1112. bss_entry->mac_address);
  1113. current_ptr += ETH_ALEN;
  1114. bytes_left_for_current_beacon -= ETH_ALEN;
  1115. if (bytes_left_for_current_beacon < 12) {
  1116. dev_err(adapter->dev, "InterpretIE: not enough bytes left\n");
  1117. return -1;
  1118. }
  1119. /*
  1120. * Next 4 fields are RSSI, time stamp, beacon interval,
  1121. * and capability information
  1122. */
  1123. /* RSSI is 1 byte long */
  1124. bss_entry->rssi = (s32) (*current_ptr);
  1125. dev_dbg(adapter->dev, "info: InterpretIE: RSSI=%02X\n", *current_ptr);
  1126. current_ptr += 1;
  1127. bytes_left_for_current_beacon -= 1;
  1128. /*
  1129. * The RSSI is not part of the beacon/probe response. After we have
  1130. * advanced current_ptr past the RSSI field, save the remaining
  1131. * data for use at the application layer
  1132. */
  1133. bss_entry->beacon_buf = current_ptr;
  1134. bss_entry->beacon_buf_size = bytes_left_for_current_beacon;
  1135. /* Time stamp is 8 bytes long */
  1136. memcpy(fixed_ie.time_stamp, current_ptr, 8);
  1137. memcpy(bss_entry->time_stamp, current_ptr, 8);
  1138. current_ptr += 8;
  1139. bytes_left_for_current_beacon -= 8;
  1140. /* Beacon interval is 2 bytes long */
  1141. memcpy(&fixed_ie.beacon_interval, current_ptr, 2);
  1142. bss_entry->beacon_period = le16_to_cpu(fixed_ie.beacon_interval);
  1143. current_ptr += 2;
  1144. bytes_left_for_current_beacon -= 2;
  1145. /* Capability information is 2 bytes long */
  1146. memcpy(&fixed_ie.capabilities, current_ptr, 2);
  1147. dev_dbg(adapter->dev, "info: InterpretIE: fixed_ie.capabilities=0x%X\n",
  1148. fixed_ie.capabilities);
  1149. bss_entry->cap_info_bitmap = le16_to_cpu(fixed_ie.capabilities);
  1150. current_ptr += 2;
  1151. bytes_left_for_current_beacon -= 2;
  1152. /* Rest of the current buffer are IE's */
  1153. dev_dbg(adapter->dev, "info: InterpretIE: IELength for this AP = %d\n",
  1154. bytes_left_for_current_beacon);
  1155. if (bss_entry->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
  1156. dev_dbg(adapter->dev, "info: InterpretIE: AP WEP enabled\n");
  1157. bss_entry->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
  1158. } else {
  1159. bss_entry->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
  1160. }
  1161. if (bss_entry->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
  1162. bss_entry->bss_mode = MWIFIEX_BSS_MODE_IBSS;
  1163. else
  1164. bss_entry->bss_mode = MWIFIEX_BSS_MODE_INFRA;
  1165. /* Process variable IE */
  1166. while (bytes_left_for_current_beacon >= 2) {
  1167. element_id = *current_ptr;
  1168. element_len = *(current_ptr + 1);
  1169. total_ie_len = element_len + sizeof(struct ieee_types_header);
  1170. if (bytes_left_for_current_beacon < total_ie_len) {
  1171. dev_err(adapter->dev, "err: InterpretIE: in processing"
  1172. " IE, bytes left < IE length\n");
  1173. bytes_left_for_current_beacon = 0;
  1174. ret = -1;
  1175. continue;
  1176. }
  1177. switch (element_id) {
  1178. case WLAN_EID_SSID:
  1179. bss_entry->ssid.ssid_len = element_len;
  1180. memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
  1181. element_len);
  1182. dev_dbg(adapter->dev, "info: InterpretIE: ssid: %-32s\n",
  1183. bss_entry->ssid.ssid);
  1184. break;
  1185. case WLAN_EID_SUPP_RATES:
  1186. memcpy(bss_entry->data_rates, current_ptr + 2,
  1187. element_len);
  1188. memcpy(bss_entry->supported_rates, current_ptr + 2,
  1189. element_len);
  1190. rate_size = element_len;
  1191. found_data_rate_ie = true;
  1192. break;
  1193. case WLAN_EID_FH_PARAMS:
  1194. fh_param_set =
  1195. (struct ieee_types_fh_param_set *) current_ptr;
  1196. memcpy(&bss_entry->phy_param_set.fh_param_set,
  1197. fh_param_set,
  1198. sizeof(struct ieee_types_fh_param_set));
  1199. break;
  1200. case WLAN_EID_DS_PARAMS:
  1201. ds_param_set =
  1202. (struct ieee_types_ds_param_set *) current_ptr;
  1203. bss_entry->channel = ds_param_set->current_chan;
  1204. memcpy(&bss_entry->phy_param_set.ds_param_set,
  1205. ds_param_set,
  1206. sizeof(struct ieee_types_ds_param_set));
  1207. break;
  1208. case WLAN_EID_CF_PARAMS:
  1209. cf_param_set =
  1210. (struct ieee_types_cf_param_set *) current_ptr;
  1211. memcpy(&bss_entry->ss_param_set.cf_param_set,
  1212. cf_param_set,
  1213. sizeof(struct ieee_types_cf_param_set));
  1214. break;
  1215. case WLAN_EID_IBSS_PARAMS:
  1216. ibss_param_set =
  1217. (struct ieee_types_ibss_param_set *)
  1218. current_ptr;
  1219. memcpy(&bss_entry->ss_param_set.ibss_param_set,
  1220. ibss_param_set,
  1221. sizeof(struct ieee_types_ibss_param_set));
  1222. break;
  1223. case WLAN_EID_ERP_INFO:
  1224. bss_entry->erp_flags = *(current_ptr + 2);
  1225. break;
  1226. case WLAN_EID_EXT_SUPP_RATES:
  1227. /*
  1228. * Only process extended supported rate
  1229. * if data rate is already found.
  1230. * Data rate IE should come before
  1231. * extended supported rate IE
  1232. */
  1233. if (found_data_rate_ie) {
  1234. if ((element_len + rate_size) >
  1235. MWIFIEX_SUPPORTED_RATES)
  1236. bytes_to_copy =
  1237. (MWIFIEX_SUPPORTED_RATES -
  1238. rate_size);
  1239. else
  1240. bytes_to_copy = element_len;
  1241. rate = (u8 *) bss_entry->data_rates;
  1242. rate += rate_size;
  1243. memcpy(rate, current_ptr + 2, bytes_to_copy);
  1244. rate = (u8 *) bss_entry->supported_rates;
  1245. rate += rate_size;
  1246. memcpy(rate, current_ptr + 2, bytes_to_copy);
  1247. }
  1248. break;
  1249. case WLAN_EID_VENDOR_SPECIFIC:
  1250. vendor_ie = (struct ieee_types_vendor_specific *)
  1251. current_ptr;
  1252. if (!memcmp
  1253. (vendor_ie->vend_hdr.oui, wpa_oui,
  1254. sizeof(wpa_oui))) {
  1255. bss_entry->bcn_wpa_ie =
  1256. (struct ieee_types_vendor_specific *)
  1257. current_ptr;
  1258. bss_entry->wpa_offset = (u16) (current_ptr -
  1259. bss_entry->beacon_buf);
  1260. } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui,
  1261. sizeof(wmm_oui))) {
  1262. if (total_ie_len ==
  1263. sizeof(struct ieee_types_wmm_parameter)
  1264. || total_ie_len ==
  1265. sizeof(struct ieee_types_wmm_info))
  1266. /*
  1267. * Only accept and copy the WMM IE if
  1268. * it matches the size expected for the
  1269. * WMM Info IE or the WMM Parameter IE.
  1270. */
  1271. memcpy((u8 *) &bss_entry->wmm_ie,
  1272. current_ptr, total_ie_len);
  1273. }
  1274. break;
  1275. case WLAN_EID_RSN:
  1276. bss_entry->bcn_rsn_ie =
  1277. (struct ieee_types_generic *) current_ptr;
  1278. bss_entry->rsn_offset = (u16) (current_ptr -
  1279. bss_entry->beacon_buf);
  1280. break;
  1281. case WLAN_EID_BSS_AC_ACCESS_DELAY:
  1282. bss_entry->bcn_wapi_ie =
  1283. (struct ieee_types_generic *) current_ptr;
  1284. bss_entry->wapi_offset = (u16) (current_ptr -
  1285. bss_entry->beacon_buf);
  1286. break;
  1287. case WLAN_EID_HT_CAPABILITY:
  1288. bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
  1289. (current_ptr +
  1290. sizeof(struct ieee_types_header));
  1291. bss_entry->ht_cap_offset = (u16) (current_ptr +
  1292. sizeof(struct ieee_types_header) -
  1293. bss_entry->beacon_buf);
  1294. break;
  1295. case WLAN_EID_HT_INFORMATION:
  1296. bss_entry->bcn_ht_info = (struct ieee80211_ht_info *)
  1297. (current_ptr +
  1298. sizeof(struct ieee_types_header));
  1299. bss_entry->ht_info_offset = (u16) (current_ptr +
  1300. sizeof(struct ieee_types_header) -
  1301. bss_entry->beacon_buf);
  1302. break;
  1303. case WLAN_EID_BSS_COEX_2040:
  1304. bss_entry->bcn_bss_co_2040 = (u8 *) (current_ptr +
  1305. sizeof(struct ieee_types_header));
  1306. bss_entry->bss_co_2040_offset = (u16) (current_ptr +
  1307. sizeof(struct ieee_types_header) -
  1308. bss_entry->beacon_buf);
  1309. break;
  1310. case WLAN_EID_EXT_CAPABILITY:
  1311. bss_entry->bcn_ext_cap = (u8 *) (current_ptr +
  1312. sizeof(struct ieee_types_header));
  1313. bss_entry->ext_cap_offset = (u16) (current_ptr +
  1314. sizeof(struct ieee_types_header) -
  1315. bss_entry->beacon_buf);
  1316. break;
  1317. case WLAN_EID_OVERLAP_BSS_SCAN_PARAM:
  1318. bss_entry->bcn_obss_scan =
  1319. (struct ieee_types_obss_scan_param *)
  1320. current_ptr;
  1321. bss_entry->overlap_bss_offset = (u16) (current_ptr -
  1322. bss_entry->beacon_buf);
  1323. break;
  1324. default:
  1325. break;
  1326. }
  1327. current_ptr += element_len + 2;
  1328. /* Need to account for IE ID and IE Len */
  1329. bytes_left_for_current_beacon -= (element_len + 2);
  1330. } /* while (bytes_left_for_current_beacon > 2) */
  1331. return ret;
  1332. }
  1333. /*
  1334. * This function adjusts the pointers used in beacon buffers to reflect
  1335. * shifts.
  1336. *
  1337. * The memory allocated for beacon buffers is of fixed sizes where all the
  1338. * saved beacons must be stored. New beacons are added in the free portion
  1339. * of this memory, space permitting; while duplicate beacon buffers are
  1340. * placed at the same start location. However, since duplicate beacon
  1341. * buffers may not match the size of the old one, all the following buffers
  1342. * in the memory must be shifted to either make space, or to fill up freed
  1343. * up space.
  1344. *
  1345. * This function is used to update the beacon buffer pointers that are past
  1346. * an existing beacon buffer that is updated with a new one of different
  1347. * size. The pointers are shifted by a fixed amount, either forward or
  1348. * backward.
  1349. *
  1350. * the following pointers in every affected beacon buffers are changed, if
  1351. * present -
  1352. * - WPA IE pointer
  1353. * - RSN IE pointer
  1354. * - WAPI IE pointer
  1355. * - HT capability IE pointer
  1356. * - HT information IE pointer
  1357. * - BSS coexistence 20/40 IE pointer
  1358. * - Extended capability IE pointer
  1359. * - Overlapping BSS scan parameter IE pointer
  1360. */
  1361. static void
  1362. mwifiex_adjust_beacon_buffer_ptrs(struct mwifiex_private *priv, u8 advance,
  1363. u8 *bcn_store, u32 rem_bcn_size,
  1364. u32 num_of_ent)
  1365. {
  1366. struct mwifiex_adapter *adapter = priv->adapter;
  1367. u32 adj_idx;
  1368. for (adj_idx = 0; adj_idx < num_of_ent; adj_idx++) {
  1369. if (adapter->scan_table[adj_idx].beacon_buf > bcn_store) {
  1370. if (advance)
  1371. adapter->scan_table[adj_idx].beacon_buf +=
  1372. rem_bcn_size;
  1373. else
  1374. adapter->scan_table[adj_idx].beacon_buf -=
  1375. rem_bcn_size;
  1376. if (adapter->scan_table[adj_idx].bcn_wpa_ie)
  1377. adapter->scan_table[adj_idx].bcn_wpa_ie =
  1378. (struct ieee_types_vendor_specific *)
  1379. (adapter->scan_table[adj_idx].beacon_buf +
  1380. adapter->scan_table[adj_idx].wpa_offset);
  1381. if (adapter->scan_table[adj_idx].bcn_rsn_ie)
  1382. adapter->scan_table[adj_idx].bcn_rsn_ie =
  1383. (struct ieee_types_generic *)
  1384. (adapter->scan_table[adj_idx].beacon_buf +
  1385. adapter->scan_table[adj_idx].rsn_offset);
  1386. if (adapter->scan_table[adj_idx].bcn_wapi_ie)
  1387. adapter->scan_table[adj_idx].bcn_wapi_ie =
  1388. (struct ieee_types_generic *)
  1389. (adapter->scan_table[adj_idx].beacon_buf +
  1390. adapter->scan_table[adj_idx].wapi_offset);
  1391. if (adapter->scan_table[adj_idx].bcn_ht_cap)
  1392. adapter->scan_table[adj_idx].bcn_ht_cap =
  1393. (struct ieee80211_ht_cap *)
  1394. (adapter->scan_table[adj_idx].beacon_buf +
  1395. adapter->scan_table[adj_idx].ht_cap_offset);
  1396. if (adapter->scan_table[adj_idx].bcn_ht_info)
  1397. adapter->scan_table[adj_idx].bcn_ht_info =
  1398. (struct ieee80211_ht_info *)
  1399. (adapter->scan_table[adj_idx].beacon_buf +
  1400. adapter->scan_table[adj_idx].ht_info_offset);
  1401. if (adapter->scan_table[adj_idx].bcn_bss_co_2040)
  1402. adapter->scan_table[adj_idx].bcn_bss_co_2040 =
  1403. (u8 *)
  1404. (adapter->scan_table[adj_idx].beacon_buf +
  1405. adapter->scan_table[adj_idx].bss_co_2040_offset);
  1406. if (adapter->scan_table[adj_idx].bcn_ext_cap)
  1407. adapter->scan_table[adj_idx].bcn_ext_cap =
  1408. (u8 *)
  1409. (adapter->scan_table[adj_idx].beacon_buf +
  1410. adapter->scan_table[adj_idx].ext_cap_offset);
  1411. if (adapter->scan_table[adj_idx].bcn_obss_scan)
  1412. adapter->scan_table[adj_idx].bcn_obss_scan =
  1413. (struct ieee_types_obss_scan_param *)
  1414. (adapter->scan_table[adj_idx].beacon_buf +
  1415. adapter->scan_table[adj_idx].overlap_bss_offset);
  1416. }
  1417. }
  1418. }
  1419. /*
  1420. * This function updates the pointers used in beacon buffer for given bss
  1421. * descriptor to reflect shifts
  1422. *
  1423. * Following pointers are updated
  1424. * - WPA IE pointer
  1425. * - RSN IE pointer
  1426. * - WAPI IE pointer
  1427. * - HT capability IE pointer
  1428. * - HT information IE pointer
  1429. * - BSS coexistence 20/40 IE pointer
  1430. * - Extended capability IE pointer
  1431. * - Overlapping BSS scan parameter IE pointer
  1432. */
  1433. static void
  1434. mwifiex_update_beacon_buffer_ptrs(struct mwifiex_bssdescriptor *beacon)
  1435. {
  1436. if (beacon->bcn_wpa_ie)
  1437. beacon->bcn_wpa_ie = (struct ieee_types_vendor_specific *)
  1438. (beacon->beacon_buf + beacon->wpa_offset);
  1439. if (beacon->bcn_rsn_ie)
  1440. beacon->bcn_rsn_ie = (struct ieee_types_generic *)
  1441. (beacon->beacon_buf + beacon->rsn_offset);
  1442. if (beacon->bcn_wapi_ie)
  1443. beacon->bcn_wapi_ie = (struct ieee_types_generic *)
  1444. (beacon->beacon_buf + beacon->wapi_offset);
  1445. if (beacon->bcn_ht_cap)
  1446. beacon->bcn_ht_cap = (struct ieee80211_ht_cap *)
  1447. (beacon->beacon_buf + beacon->ht_cap_offset);
  1448. if (beacon->bcn_ht_info)
  1449. beacon->bcn_ht_info = (struct ieee80211_ht_info *)
  1450. (beacon->beacon_buf + beacon->ht_info_offset);
  1451. if (beacon->bcn_bss_co_2040)
  1452. beacon->bcn_bss_co_2040 = (u8 *) (beacon->beacon_buf +
  1453. beacon->bss_co_2040_offset);
  1454. if (beacon->bcn_ext_cap)
  1455. beacon->bcn_ext_cap = (u8 *) (beacon->beacon_buf +
  1456. beacon->ext_cap_offset);
  1457. if (beacon->bcn_obss_scan)
  1458. beacon->bcn_obss_scan = (struct ieee_types_obss_scan_param *)
  1459. (beacon->beacon_buf + beacon->overlap_bss_offset);
  1460. }
  1461. /*
  1462. * This function stores a beacon or probe response for a BSS returned
  1463. * in the scan.
  1464. *
  1465. * This stores a new scan response or an update for a previous scan response.
  1466. * New entries need to verify that they do not exceed the total amount of
  1467. * memory allocated for the table.
  1468. *
  1469. * Replacement entries need to take into consideration the amount of space
  1470. * currently allocated for the beacon/probe response and adjust the entry
  1471. * as needed.
  1472. *
  1473. * A small amount of extra pad (SCAN_BEACON_ENTRY_PAD) is generally reserved
  1474. * for an entry in case it is a beacon since a probe response for the
  1475. * network will by larger per the standard. This helps to reduce the
  1476. * amount of memory copying to fit a new probe response into an entry
  1477. * already occupied by a network's previously stored beacon.
  1478. */
  1479. static void
  1480. mwifiex_ret_802_11_scan_store_beacon(struct mwifiex_private *priv,
  1481. u32 beacon_idx, u32 num_of_ent,
  1482. struct mwifiex_bssdescriptor *new_beacon)
  1483. {
  1484. struct mwifiex_adapter *adapter = priv->adapter;
  1485. u8 *bcn_store;
  1486. u32 new_bcn_size;
  1487. u32 old_bcn_size;
  1488. u32 bcn_space;
  1489. if (adapter->scan_table[beacon_idx].beacon_buf) {
  1490. new_bcn_size = new_beacon->beacon_buf_size;
  1491. old_bcn_size = adapter->scan_table[beacon_idx].beacon_buf_size;
  1492. bcn_space = adapter->scan_table[beacon_idx].beacon_buf_size_max;
  1493. bcn_store = adapter->scan_table[beacon_idx].beacon_buf;
  1494. /* Set the max to be the same as current entry unless changed
  1495. below */
  1496. new_beacon->beacon_buf_size_max = bcn_space;
  1497. if (new_bcn_size == old_bcn_size) {
  1498. /*
  1499. * Beacon is the same size as the previous entry.
  1500. * Replace the previous contents with the scan result
  1501. */
  1502. memcpy(bcn_store, new_beacon->beacon_buf,
  1503. new_beacon->beacon_buf_size);
  1504. } else if (new_bcn_size <= bcn_space) {
  1505. /*
  1506. * New beacon size will fit in the amount of space
  1507. * we have previously allocated for it
  1508. */
  1509. /* Copy the new beacon buffer entry over the old one */
  1510. memcpy(bcn_store, new_beacon->beacon_buf, new_bcn_size);
  1511. /*
  1512. * If the old beacon size was less than the maximum
  1513. * we had alloted for the entry, and the new entry
  1514. * is even smaller, reset the max size to the old
  1515. * beacon entry and compress the storage space
  1516. * (leaving a new pad space of (old_bcn_size -
  1517. * new_bcn_size).
  1518. */
  1519. if (old_bcn_size < bcn_space
  1520. && new_bcn_size <= old_bcn_size) {
  1521. /*
  1522. * Old Beacon size is smaller than the alloted
  1523. * storage size. Shrink the alloted storage
  1524. * space.
  1525. */
  1526. dev_dbg(adapter->dev, "info: AppControl:"
  1527. " smaller duplicate beacon "
  1528. "(%d), old = %d, new = %d, space = %d,"
  1529. "left = %d\n",
  1530. beacon_idx, old_bcn_size, new_bcn_size,
  1531. bcn_space,
  1532. (int)(sizeof(adapter->bcn_buf) -
  1533. (adapter->bcn_buf_end -
  1534. adapter->bcn_buf)));
  1535. /*
  1536. * memmove (since the memory overlaps) the
  1537. * data after the beacon we just stored to the
  1538. * end of the current beacon. This cleans up
  1539. * any unused space the old larger beacon was
  1540. * using in the buffer
  1541. */
  1542. memmove(bcn_store + old_bcn_size,
  1543. bcn_store + bcn_space,
  1544. adapter->bcn_buf_end - (bcn_store +
  1545. bcn_space));
  1546. /*
  1547. * Decrement the end pointer by the difference
  1548. * between the old larger size and the new
  1549. * smaller size since we are using less space
  1550. * due to the new beacon being smaller
  1551. */
  1552. adapter->bcn_buf_end -=
  1553. (bcn_space - old_bcn_size);
  1554. /* Set the maximum storage size to the old
  1555. beacon size */
  1556. new_beacon->beacon_buf_size_max = old_bcn_size;
  1557. /* Adjust beacon buffer pointers that are past
  1558. the current */
  1559. mwifiex_adjust_beacon_buffer_ptrs(priv, 0,
  1560. bcn_store, (bcn_space - old_bcn_size),
  1561. num_of_ent);
  1562. }
  1563. } else if (adapter->bcn_buf_end + (new_bcn_size - bcn_space)
  1564. < (adapter->bcn_buf + sizeof(adapter->bcn_buf))) {
  1565. /*
  1566. * Beacon is larger than space previously allocated
  1567. * (bcn_space) and there is enough space left in the
  1568. * beaconBuffer to store the additional data
  1569. */
  1570. dev_dbg(adapter->dev, "info: AppControl:"
  1571. " larger duplicate beacon (%d), "
  1572. "old = %d, new = %d, space = %d, left = %d\n",
  1573. beacon_idx, old_bcn_size, new_bcn_size,
  1574. bcn_space,
  1575. (int)(sizeof(adapter->bcn_buf) -
  1576. (adapter->bcn_buf_end -
  1577. adapter->bcn_buf)));
  1578. /*
  1579. * memmove (since the memory overlaps) the data
  1580. * after the beacon we just stored to the end of
  1581. * the current beacon. This moves the data for
  1582. * the beacons after this further in memory to
  1583. * make space for the new larger beacon we are
  1584. * about to copy in.
  1585. */
  1586. memmove(bcn_store + new_bcn_size,
  1587. bcn_store + bcn_space,
  1588. adapter->bcn_buf_end - (bcn_store + bcn_space));
  1589. /* Copy the new beacon buffer entry over the old one */
  1590. memcpy(bcn_store, new_beacon->beacon_buf, new_bcn_size);
  1591. /* Move the beacon end pointer by the amount of new
  1592. beacon data we are adding */
  1593. adapter->bcn_buf_end += (new_bcn_size - bcn_space);
  1594. /*
  1595. * This entry is bigger than the alloted max space
  1596. * previously reserved. Increase the max space to
  1597. * be equal to the new beacon size
  1598. */
  1599. new_beacon->beacon_buf_size_max = new_bcn_size;
  1600. /* Adjust beacon buffer pointers that are past the
  1601. current */
  1602. mwifiex_adjust_beacon_buffer_ptrs(priv, 1, bcn_store,
  1603. (new_bcn_size - bcn_space),
  1604. num_of_ent);
  1605. } else {
  1606. /*
  1607. * Beacon is larger than the previously allocated space,
  1608. * but there is not enough free space to store the
  1609. * additional data.
  1610. */
  1611. dev_err(adapter->dev, "AppControl: larger duplicate "
  1612. " beacon (%d), old = %d new = %d, space = %d,"
  1613. " left = %d\n", beacon_idx, old_bcn_size,
  1614. new_bcn_size, bcn_space,
  1615. (int)(sizeof(adapter->bcn_buf) -
  1616. (adapter->bcn_buf_end - adapter->bcn_buf)));
  1617. /* Storage failure, keep old beacon intact */
  1618. new_beacon->beacon_buf_size = old_bcn_size;
  1619. if (new_beacon->bcn_wpa_ie)
  1620. new_beacon->wpa_offset =
  1621. adapter->scan_table[beacon_idx].
  1622. wpa_offset;
  1623. if (new_beacon->bcn_rsn_ie)
  1624. new_beacon->rsn_offset =
  1625. adapter->scan_table[beacon_idx].
  1626. rsn_offset;
  1627. if (new_beacon->bcn_wapi_ie)
  1628. new_beacon->wapi_offset =
  1629. adapter->scan_table[beacon_idx].
  1630. wapi_offset;
  1631. if (new_beacon->bcn_ht_cap)
  1632. new_beacon->ht_cap_offset =
  1633. adapter->scan_table[beacon_idx].
  1634. ht_cap_offset;
  1635. if (new_beacon->bcn_ht_info)
  1636. new_beacon->ht_info_offset =
  1637. adapter->scan_table[beacon_idx].
  1638. ht_info_offset;
  1639. if (new_beacon->bcn_bss_co_2040)
  1640. new_beacon->bss_co_2040_offset =
  1641. adapter->scan_table[beacon_idx].
  1642. bss_co_2040_offset;
  1643. if (new_beacon->bcn_ext_cap)
  1644. new_beacon->ext_cap_offset =
  1645. adapter->scan_table[beacon_idx].
  1646. ext_cap_offset;
  1647. if (new_beacon->bcn_obss_scan)
  1648. new_beacon->overlap_bss_offset =
  1649. adapter->scan_table[beacon_idx].
  1650. overlap_bss_offset;
  1651. }
  1652. /* Point the new entry to its permanent storage space */
  1653. new_beacon->beacon_buf = bcn_store;
  1654. mwifiex_update_beacon_buffer_ptrs(new_beacon);
  1655. } else {
  1656. /*
  1657. * No existing beacon data exists for this entry, check to see
  1658. * if we can fit it in the remaining space
  1659. */
  1660. if (adapter->bcn_buf_end + new_beacon->beacon_buf_size +
  1661. SCAN_BEACON_ENTRY_PAD < (adapter->bcn_buf +
  1662. sizeof(adapter->bcn_buf))) {
  1663. /*
  1664. * Copy the beacon buffer data from the local entry to
  1665. * the adapter dev struct buffer space used to store
  1666. * the raw beacon data for each entry in the scan table
  1667. */
  1668. memcpy(adapter->bcn_buf_end, new_beacon->beacon_buf,
  1669. new_beacon->beacon_buf_size);
  1670. /* Update the beacon ptr to point to the table save
  1671. area */
  1672. new_beacon->beacon_buf = adapter->bcn_buf_end;
  1673. new_beacon->beacon_buf_size_max =
  1674. (new_beacon->beacon_buf_size +
  1675. SCAN_BEACON_ENTRY_PAD);
  1676. mwifiex_update_beacon_buffer_ptrs(new_beacon);
  1677. /* Increment the end pointer by the size reserved */
  1678. adapter->bcn_buf_end += new_beacon->beacon_buf_size_max;
  1679. dev_dbg(adapter->dev, "info: AppControl: beacon[%02d]"
  1680. " sz=%03d, used = %04d, left = %04d\n",
  1681. beacon_idx,
  1682. new_beacon->beacon_buf_size,
  1683. (int)(adapter->bcn_buf_end - adapter->bcn_buf),
  1684. (int)(sizeof(adapter->bcn_buf) -
  1685. (adapter->bcn_buf_end -
  1686. adapter->bcn_buf)));
  1687. } else {
  1688. /* No space for new beacon */
  1689. dev_dbg(adapter->dev, "info: AppControl: no space for"
  1690. " beacon (%d): %pM sz=%03d, left=%03d\n",
  1691. beacon_idx, new_beacon->mac_address,
  1692. new_beacon->beacon_buf_size,
  1693. (int)(sizeof(adapter->bcn_buf) -
  1694. (adapter->bcn_buf_end -
  1695. adapter->bcn_buf)));
  1696. /* Storage failure; clear storage records for this
  1697. bcn */
  1698. new_beacon->beacon_buf = NULL;
  1699. new_beacon->beacon_buf_size = 0;
  1700. new_beacon->beacon_buf_size_max = 0;
  1701. new_beacon->bcn_wpa_ie = NULL;
  1702. new_beacon->wpa_offset = 0;
  1703. new_beacon->bcn_rsn_ie = NULL;
  1704. new_beacon->rsn_offset = 0;
  1705. new_beacon->bcn_wapi_ie = NULL;
  1706. new_beacon->wapi_offset = 0;
  1707. new_beacon->bcn_ht_cap = NULL;
  1708. new_beacon->ht_cap_offset = 0;
  1709. new_beacon->bcn_ht_info = NULL;
  1710. new_beacon->ht_info_offset = 0;
  1711. new_beacon->bcn_bss_co_2040 = NULL;
  1712. new_beacon->bss_co_2040_offset = 0;
  1713. new_beacon->bcn_ext_cap = NULL;
  1714. new_beacon->ext_cap_offset = 0;
  1715. new_beacon->bcn_obss_scan = NULL;
  1716. new_beacon->overlap_bss_offset = 0;
  1717. }
  1718. }
  1719. }
  1720. /*
  1721. * This function restores a beacon buffer of the current BSS descriptor.
  1722. */
  1723. static void mwifiex_restore_curr_bcn(struct mwifiex_private *priv)
  1724. {
  1725. struct mwifiex_adapter *adapter = priv->adapter;
  1726. struct mwifiex_bssdescriptor *curr_bss =
  1727. &priv->curr_bss_params.bss_descriptor;
  1728. unsigned long flags;
  1729. if (priv->curr_bcn_buf &&
  1730. ((adapter->bcn_buf_end + priv->curr_bcn_size) <
  1731. (adapter->bcn_buf + sizeof(adapter->bcn_buf)))) {
  1732. spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
  1733. /* restore the current beacon buffer */
  1734. memcpy(adapter->bcn_buf_end, priv->curr_bcn_buf,
  1735. priv->curr_bcn_size);
  1736. curr_bss->beacon_buf = adapter->bcn_buf_end;
  1737. curr_bss->beacon_buf_size = priv->curr_bcn_size;
  1738. adapter->bcn_buf_end += priv->curr_bcn_size;
  1739. /* adjust the pointers in the current BSS descriptor */
  1740. if (curr_bss->bcn_wpa_ie)
  1741. curr_bss->bcn_wpa_ie =
  1742. (struct ieee_types_vendor_specific *)
  1743. (curr_bss->beacon_buf +
  1744. curr_bss->wpa_offset);
  1745. if (curr_bss->bcn_rsn_ie)
  1746. curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
  1747. (curr_bss->beacon_buf +
  1748. curr_bss->rsn_offset);
  1749. if (curr_bss->bcn_ht_cap)
  1750. curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
  1751. (curr_bss->beacon_buf +
  1752. curr_bss->ht_cap_offset);
  1753. if (curr_bss->bcn_ht_info)
  1754. curr_bss->bcn_ht_info = (struct ieee80211_ht_info *)
  1755. (curr_bss->beacon_buf +
  1756. curr_bss->ht_info_offset);
  1757. if (curr_bss->bcn_bss_co_2040)
  1758. curr_bss->bcn_bss_co_2040 =
  1759. (u8 *) (curr_bss->beacon_buf +
  1760. curr_bss->bss_co_2040_offset);
  1761. if (curr_bss->bcn_ext_cap)
  1762. curr_bss->bcn_ext_cap = (u8 *) (curr_bss->beacon_buf +
  1763. curr_bss->ext_cap_offset);
  1764. if (curr_bss->bcn_obss_scan)
  1765. curr_bss->bcn_obss_scan =
  1766. (struct ieee_types_obss_scan_param *)
  1767. (curr_bss->beacon_buf +
  1768. curr_bss->overlap_bss_offset);
  1769. spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
  1770. dev_dbg(adapter->dev, "info: current beacon restored %d\n",
  1771. priv->curr_bcn_size);
  1772. } else {
  1773. dev_warn(adapter->dev,
  1774. "curr_bcn_buf not saved or bcn_buf has no space\n");
  1775. }
  1776. }
  1777. /*
  1778. * This function post processes the scan table after a new scan command has
  1779. * completed.
  1780. *
  1781. * It inspects each entry of the scan table and tries to find an entry that
  1782. * matches with our current associated/joined network from the scan. If
  1783. * one is found, the stored copy of the BSS descriptor of our current network
  1784. * is updated.
  1785. *
  1786. * It also debug dumps the current scan table contents after processing is over.
  1787. */
  1788. static void
  1789. mwifiex_process_scan_results(struct mwifiex_private *priv)
  1790. {
  1791. struct mwifiex_adapter *adapter = priv->adapter;
  1792. s32 j;
  1793. u32 i;
  1794. unsigned long flags;
  1795. if (priv->media_connected) {
  1796. j = mwifiex_find_ssid_in_list(priv, &priv->curr_bss_params.
  1797. bss_descriptor.ssid,
  1798. priv->curr_bss_params.
  1799. bss_descriptor.mac_address,
  1800. priv->bss_mode);
  1801. if (j >= 0) {
  1802. spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
  1803. priv->curr_bss_params.bss_descriptor.bcn_wpa_ie = NULL;
  1804. priv->curr_bss_params.bss_descriptor.wpa_offset = 0;
  1805. priv->curr_bss_params.bss_descriptor.bcn_rsn_ie = NULL;
  1806. priv->curr_bss_params.bss_descriptor.rsn_offset = 0;
  1807. priv->curr_bss_params.bss_descriptor.bcn_wapi_ie = NULL;
  1808. priv->curr_bss_params.bss_descriptor.wapi_offset = 0;
  1809. priv->curr_bss_params.bss_descriptor.bcn_ht_cap = NULL;
  1810. priv->curr_bss_params.bss_descriptor.ht_cap_offset =
  1811. 0;
  1812. priv->curr_bss_params.bss_descriptor.bcn_ht_info = NULL;
  1813. priv->curr_bss_params.bss_descriptor.ht_info_offset =
  1814. 0;
  1815. priv->curr_bss_params.bss_descriptor.bcn_bss_co_2040 =
  1816. NULL;
  1817. priv->curr_bss_params.bss_descriptor.
  1818. bss_co_2040_offset = 0;
  1819. priv->curr_bss_params.bss_descriptor.bcn_ext_cap = NULL;
  1820. priv->curr_bss_params.bss_descriptor.ext_cap_offset = 0;
  1821. priv->curr_bss_params.bss_descriptor.
  1822. bcn_obss_scan = NULL;
  1823. priv->curr_bss_params.bss_descriptor.
  1824. overlap_bss_offset = 0;
  1825. priv->curr_bss_params.bss_descriptor.beacon_buf = NULL;
  1826. priv->curr_bss_params.bss_descriptor.beacon_buf_size =
  1827. 0;
  1828. priv->curr_bss_params.bss_descriptor.
  1829. beacon_buf_size_max = 0;
  1830. dev_dbg(adapter->dev, "info: Found current ssid/bssid"
  1831. " in list @ index #%d\n", j);
  1832. /* Make a copy of current BSSID descriptor */
  1833. memcpy(&priv->curr_bss_params.bss_descriptor,
  1834. &adapter->scan_table[j],
  1835. sizeof(priv->curr_bss_params.bss_descriptor));
  1836. mwifiex_save_curr_bcn(priv);
  1837. spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
  1838. } else {
  1839. mwifiex_restore_curr_bcn(priv);
  1840. }
  1841. }
  1842. for (i = 0; i < adapter->num_in_scan_table; i++)
  1843. dev_dbg(adapter->dev, "info: scan:(%02d) %pM "
  1844. "RSSI[%03d], SSID[%s]\n",
  1845. i, adapter->scan_table[i].mac_address,
  1846. (s32) adapter->scan_table[i].rssi,
  1847. adapter->scan_table[i].ssid.ssid);
  1848. }
  1849. /*
  1850. * This function converts radio type scan parameter to a band configuration
  1851. * to be used in join command.
  1852. */
  1853. static u8
  1854. mwifiex_radio_type_to_band(u8 radio_type)
  1855. {
  1856. u8 ret_band;
  1857. switch (radio_type) {
  1858. case HostCmd_SCAN_RADIO_TYPE_A:
  1859. ret_band = BAND_A;
  1860. break;
  1861. case HostCmd_SCAN_RADIO_TYPE_BG:
  1862. default:
  1863. ret_band = BAND_G;
  1864. break;
  1865. }
  1866. return ret_band;
  1867. }
  1868. /*
  1869. * This function deletes a specific indexed entry from the scan table.
  1870. *
  1871. * This also compacts the remaining entries and adjusts any buffering
  1872. * of beacon/probe response data if needed.
  1873. */
  1874. static void
  1875. mwifiex_scan_delete_table_entry(struct mwifiex_private *priv, s32 table_idx)
  1876. {
  1877. struct mwifiex_adapter *adapter = priv->adapter;
  1878. u32 del_idx;
  1879. u32 beacon_buf_adj;
  1880. u8 *beacon_buf;
  1881. /*
  1882. * Shift the saved beacon buffer data for the scan table back over the
  1883. * entry being removed. Update the end of buffer pointer. Save the
  1884. * deleted buffer allocation size for pointer adjustments for entries
  1885. * compacted after the deleted index.
  1886. */
  1887. beacon_buf_adj = adapter->scan_table[table_idx].beacon_buf_size_max;
  1888. dev_dbg(adapter->dev, "info: Scan: Delete Entry %d, beacon buffer "
  1889. "removal = %d bytes\n", table_idx, beacon_buf_adj);
  1890. /* Check if the table entry had storage allocated for its beacon */
  1891. if (beacon_buf_adj) {
  1892. beacon_buf = adapter->scan_table[table_idx].beacon_buf;
  1893. /*
  1894. * Remove the entry's buffer space, decrement the table end
  1895. * pointer by the amount we are removing
  1896. */
  1897. adapter->bcn_buf_end -= beacon_buf_adj;
  1898. dev_dbg(adapter->dev, "info: scan: delete entry %d,"
  1899. " compact data: %p <- %p (sz = %d)\n",
  1900. table_idx, beacon_buf,
  1901. beacon_buf + beacon_buf_adj,
  1902. (int)(adapter->bcn_buf_end - beacon_buf));
  1903. /*
  1904. * Compact data storage. Copy all data after the deleted
  1905. * entry's end address (beacon_buf + beacon_buf_adj) back
  1906. * to the original start address (beacon_buf).
  1907. *
  1908. * Scan table entries affected by the move will have their
  1909. * entry pointer adjusted below.
  1910. *
  1911. * Use memmove since the dest/src memory regions overlap.
  1912. */
  1913. memmove(beacon_buf, beacon_buf + beacon_buf_adj,
  1914. adapter->bcn_buf_end - beacon_buf);
  1915. }
  1916. dev_dbg(adapter->dev,
  1917. "info: Scan: Delete Entry %d, num_in_scan_table = %d\n",
  1918. table_idx, adapter->num_in_scan_table);
  1919. /* Shift all of the entries after the table_idx back by one, compacting
  1920. the table and removing the requested entry */
  1921. for (del_idx = table_idx; (del_idx + 1) < adapter->num_in_scan_table;
  1922. del_idx++) {
  1923. /* Copy the next entry over this one */
  1924. memcpy(adapter->scan_table + del_idx,
  1925. adapter->scan_table + del_idx + 1,
  1926. sizeof(struct mwifiex_bssdescriptor));
  1927. /*
  1928. * Adjust this entry's pointer to its beacon buffer based on
  1929. * the removed/compacted entry from the deleted index. Don't
  1930. * decrement if the buffer pointer is NULL (no data stored for
  1931. * this entry).
  1932. */
  1933. if (adapter->scan_table[del_idx].beacon_buf) {
  1934. adapter->scan_table[del_idx].beacon_buf -=
  1935. beacon_buf_adj;
  1936. if (adapter->scan_table[del_idx].bcn_wpa_ie)
  1937. adapter->scan_table[del_idx].bcn_wpa_ie =
  1938. (struct ieee_types_vendor_specific *)
  1939. (adapter->scan_table[del_idx].
  1940. beacon_buf +
  1941. adapter->scan_table[del_idx].
  1942. wpa_offset);
  1943. if (adapter->scan_table[del_idx].bcn_rsn_ie)
  1944. adapter->scan_table[del_idx].bcn_rsn_ie =
  1945. (struct ieee_types_generic *)
  1946. (adapter->scan_table[del_idx].
  1947. beacon_buf +
  1948. adapter->scan_table[del_idx].
  1949. rsn_offset);
  1950. if (adapter->scan_table[del_idx].bcn_wapi_ie)
  1951. adapter->scan_table[del_idx].bcn_wapi_ie =
  1952. (struct ieee_types_generic *)
  1953. (adapter->scan_table[del_idx].beacon_buf
  1954. + adapter->scan_table[del_idx].
  1955. wapi_offset);
  1956. if (adapter->scan_table[del_idx].bcn_ht_cap)
  1957. adapter->scan_table[del_idx].bcn_ht_cap =
  1958. (struct ieee80211_ht_cap *)
  1959. (adapter->scan_table[del_idx].beacon_buf
  1960. + adapter->scan_table[del_idx].
  1961. ht_cap_offset);
  1962. if (adapter->scan_table[del_idx].bcn_ht_info)
  1963. adapter->scan_table[del_idx].bcn_ht_info =
  1964. (struct ieee80211_ht_info *)
  1965. (adapter->scan_table[del_idx].beacon_buf
  1966. + adapter->scan_table[del_idx].
  1967. ht_info_offset);
  1968. if (adapter->scan_table[del_idx].bcn_bss_co_2040)
  1969. adapter->scan_table[del_idx].bcn_bss_co_2040 =
  1970. (u8 *)
  1971. (adapter->scan_table[del_idx].beacon_buf
  1972. + adapter->scan_table[del_idx].
  1973. bss_co_2040_offset);
  1974. if (adapter->scan_table[del_idx].bcn_ext_cap)
  1975. adapter->scan_table[del_idx].bcn_ext_cap =
  1976. (u8 *)
  1977. (adapter->scan_table[del_idx].beacon_buf
  1978. + adapter->scan_table[del_idx].
  1979. ext_cap_offset);
  1980. if (adapter->scan_table[del_idx].bcn_obss_scan)
  1981. adapter->scan_table[del_idx].
  1982. bcn_obss_scan =
  1983. (struct ieee_types_obss_scan_param *)
  1984. (adapter->scan_table[del_idx].beacon_buf
  1985. + adapter->scan_table[del_idx].
  1986. overlap_bss_offset);
  1987. }
  1988. }
  1989. /* The last entry is invalid now that it has been deleted or moved
  1990. back */
  1991. memset(adapter->scan_table + adapter->num_in_scan_table - 1,
  1992. 0x00, sizeof(struct mwifiex_bssdescriptor));
  1993. adapter->num_in_scan_table--;
  1994. }
  1995. /*
  1996. * This function deletes all occurrences of a given SSID from the scan table.
  1997. *
  1998. * This iterates through the scan table and deletes all entries that match
  1999. * the given SSID. It also compacts the remaining scan table entries.
  2000. */
  2001. static int
  2002. mwifiex_scan_delete_ssid_table_entry(struct mwifiex_private *priv,
  2003. struct mwifiex_802_11_ssid *del_ssid)
  2004. {
  2005. int ret = -1;
  2006. s32 table_idx;
  2007. dev_dbg(priv->adapter->dev, "info: scan: delete ssid entry: %-32s\n",
  2008. del_ssid->ssid);
  2009. /* If the requested SSID is found in the table, delete it. Then keep
  2010. searching the table for multiple entires for the SSID until no
  2011. more are found */
  2012. while ((table_idx = mwifiex_find_ssid_in_list(priv, del_ssid, NULL,
  2013. MWIFIEX_BSS_MODE_AUTO)) >=
  2014. 0) {
  2015. dev_dbg(priv->adapter->dev,
  2016. "info: Scan: Delete SSID Entry: Found Idx = %d\n",
  2017. table_idx);
  2018. ret = 0;
  2019. mwifiex_scan_delete_table_entry(priv, table_idx);
  2020. }
  2021. return ret;
  2022. }
  2023. /*
  2024. * This is an internal function used to start a scan based on an input
  2025. * configuration.
  2026. *
  2027. * This uses the input user scan configuration information when provided in
  2028. * order to send the appropriate scan commands to firmware to populate or
  2029. * update the internal driver scan table.
  2030. */
  2031. int mwifiex_scan_networks(struct mwifiex_private *priv,
  2032. void *wait_buf, u16 action,
  2033. const struct mwifiex_user_scan_cfg *user_scan_in,
  2034. struct mwifiex_scan_resp *scan_resp)
  2035. {
  2036. int ret = 0;
  2037. struct mwifiex_adapter *adapter = priv->adapter;
  2038. struct cmd_ctrl_node *cmd_node = NULL;
  2039. union mwifiex_scan_cmd_config_tlv *scan_cfg_out = NULL;
  2040. struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
  2041. u32 buf_size;
  2042. struct mwifiex_chan_scan_param_set *scan_chan_list;
  2043. u8 keep_previous_scan;
  2044. u8 filtered_scan;
  2045. u8 scan_current_chan_only;
  2046. u8 max_chan_per_scan;
  2047. unsigned long flags;
  2048. if (action == HostCmd_ACT_GEN_GET) {
  2049. if (scan_resp) {
  2050. scan_resp->scan_table = (u8 *) adapter->scan_table;
  2051. scan_resp->num_in_scan_table =
  2052. adapter->num_in_scan_table;
  2053. } else {
  2054. ret = -1;
  2055. }
  2056. return ret;
  2057. }
  2058. if (adapter->scan_processing && action == HostCmd_ACT_GEN_SET) {
  2059. dev_dbg(adapter->dev, "cmd: Scan already in process...\n");
  2060. return ret;
  2061. }
  2062. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  2063. adapter->scan_processing = true;
  2064. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  2065. if (priv->scan_block && action == HostCmd_ACT_GEN_SET) {
  2066. dev_dbg(adapter->dev,
  2067. "cmd: Scan is blocked during association...\n");
  2068. return ret;
  2069. }
  2070. scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
  2071. GFP_KERNEL);
  2072. if (!scan_cfg_out) {
  2073. dev_err(adapter->dev, "failed to alloc scan_cfg_out\n");
  2074. return -1;
  2075. }
  2076. buf_size = sizeof(struct mwifiex_chan_scan_param_set) *
  2077. MWIFIEX_USER_SCAN_CHAN_MAX;
  2078. scan_chan_list = kzalloc(buf_size, GFP_KERNEL);
  2079. if (!scan_chan_list) {
  2080. dev_err(adapter->dev, "failed to alloc scan_chan_list\n");
  2081. kfree(scan_cfg_out);
  2082. return -1;
  2083. }
  2084. keep_previous_scan = false;
  2085. mwifiex_scan_setup_scan_config(priv, user_scan_in,
  2086. &scan_cfg_out->config, &chan_list_out,
  2087. scan_chan_list, &max_chan_per_scan,
  2088. &filtered_scan, &scan_current_chan_only);
  2089. if (user_scan_in)
  2090. keep_previous_scan = user_scan_in->keep_previous_scan;
  2091. if (!keep_previous_scan) {
  2092. memset(adapter->scan_table, 0x00,
  2093. sizeof(struct mwifiex_bssdescriptor) * IW_MAX_AP);
  2094. adapter->num_in_scan_table = 0;
  2095. adapter->bcn_buf_end = adapter->bcn_buf;
  2096. }
  2097. ret = mwifiex_scan_channel_list(priv, wait_buf, max_chan_per_scan,
  2098. filtered_scan, &scan_cfg_out->config,
  2099. chan_list_out, scan_chan_list);
  2100. /* Get scan command from scan_pending_q and put to cmd_pending_q */
  2101. if (!ret) {
  2102. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  2103. if (!list_empty(&adapter->scan_pending_q)) {
  2104. cmd_node = list_first_entry(&adapter->scan_pending_q,
  2105. struct cmd_ctrl_node, list);
  2106. list_del(&cmd_node->list);
  2107. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  2108. flags);
  2109. mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
  2110. true);
  2111. } else {
  2112. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  2113. flags);
  2114. }
  2115. ret = -EINPROGRESS;
  2116. } else {
  2117. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  2118. adapter->scan_processing = true;
  2119. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  2120. }
  2121. kfree(scan_cfg_out);
  2122. kfree(scan_chan_list);
  2123. return ret;
  2124. }
  2125. /*
  2126. * This function prepares a scan command to be sent to the firmware.
  2127. *
  2128. * This uses the scan command configuration sent to the command processing
  2129. * module in command preparation stage to configure a scan command structure
  2130. * to send to firmware.
  2131. *
  2132. * The fixed fields specifying the BSS type and BSSID filters as well as a
  2133. * variable number/length of TLVs are sent in the command to firmware.
  2134. *
  2135. * Preparation also includes -
  2136. * - Setting command ID, and proper size
  2137. * - Ensuring correct endian-ness
  2138. */
  2139. int mwifiex_cmd_802_11_scan(struct mwifiex_private *priv,
  2140. struct host_cmd_ds_command *cmd, void *data_buf)
  2141. {
  2142. struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
  2143. struct mwifiex_scan_cmd_config *scan_cfg;
  2144. scan_cfg = (struct mwifiex_scan_cmd_config *) data_buf;
  2145. /* Set fixed field variables in scan command */
  2146. scan_cmd->bss_mode = scan_cfg->bss_mode;
  2147. memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
  2148. sizeof(scan_cmd->bssid));
  2149. memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
  2150. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
  2151. /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
  2152. cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
  2153. + sizeof(scan_cmd->bssid)
  2154. + scan_cfg->tlv_buf_len + S_DS_GEN));
  2155. return 0;
  2156. }
  2157. /*
  2158. * This function handles the command response of scan.
  2159. *
  2160. * The response buffer for the scan command has the following
  2161. * memory layout:
  2162. *
  2163. * .-------------------------------------------------------------.
  2164. * | Header (4 * sizeof(t_u16)): Standard command response hdr |
  2165. * .-------------------------------------------------------------.
  2166. * | BufSize (t_u16) : sizeof the BSS Description data |
  2167. * .-------------------------------------------------------------.
  2168. * | NumOfSet (t_u8) : Number of BSS Descs returned |
  2169. * .-------------------------------------------------------------.
  2170. * | BSSDescription data (variable, size given in BufSize) |
  2171. * .-------------------------------------------------------------.
  2172. * | TLV data (variable, size calculated using Header->Size, |
  2173. * | BufSize and sizeof the fixed fields above) |
  2174. * .-------------------------------------------------------------.
  2175. */
  2176. int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
  2177. struct host_cmd_ds_command *resp, void *wq_buf)
  2178. {
  2179. int ret = 0;
  2180. struct mwifiex_adapter *adapter = priv->adapter;
  2181. struct mwifiex_wait_queue *wait_queue = NULL;
  2182. struct cmd_ctrl_node *cmd_node = NULL;
  2183. struct host_cmd_ds_802_11_scan_rsp *scan_rsp = NULL;
  2184. struct mwifiex_bssdescriptor *bss_new_entry = NULL;
  2185. struct mwifiex_ie_types_data *tlv_data;
  2186. struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
  2187. u8 *bss_info;
  2188. u32 scan_resp_size;
  2189. u32 bytes_left;
  2190. u32 num_in_table;
  2191. u32 bss_idx;
  2192. u32 idx;
  2193. u32 tlv_buf_size;
  2194. long long tsf_val;
  2195. struct mwifiex_chan_freq_power *cfp;
  2196. struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
  2197. struct chan_band_param_set *chan_band;
  2198. u8 band;
  2199. u8 is_bgscan_resp;
  2200. unsigned long flags;
  2201. is_bgscan_resp = (le16_to_cpu(resp->command)
  2202. == HostCmd_CMD_802_11_BG_SCAN_QUERY);
  2203. if (is_bgscan_resp)
  2204. scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
  2205. else
  2206. scan_rsp = &resp->params.scan_resp;
  2207. if (scan_rsp->number_of_sets > IW_MAX_AP) {
  2208. dev_err(adapter->dev, "SCAN_RESP: too many AP returned (%d)\n",
  2209. scan_rsp->number_of_sets);
  2210. ret = -1;
  2211. goto done;
  2212. }
  2213. bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
  2214. dev_dbg(adapter->dev, "info: SCAN_RESP: bss_descript_size %d\n",
  2215. bytes_left);
  2216. scan_resp_size = le16_to_cpu(resp->size);
  2217. dev_dbg(adapter->dev,
  2218. "info: SCAN_RESP: returned %d APs before parsing\n",
  2219. scan_rsp->number_of_sets);
  2220. num_in_table = adapter->num_in_scan_table;
  2221. bss_info = scan_rsp->bss_desc_and_tlv_buffer;
  2222. /*
  2223. * The size of the TLV buffer is equal to the entire command response
  2224. * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
  2225. * BSS Descriptions (bss_descript_size as bytesLef) and the command
  2226. * response header (S_DS_GEN)
  2227. */
  2228. tlv_buf_size = scan_resp_size - (bytes_left
  2229. + sizeof(scan_rsp->bss_descript_size)
  2230. + sizeof(scan_rsp->number_of_sets)
  2231. + S_DS_GEN);
  2232. tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
  2233. bss_desc_and_tlv_buffer +
  2234. bytes_left);
  2235. /* Search the TLV buffer space in the scan response for any valid
  2236. TLVs */
  2237. mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
  2238. TLV_TYPE_TSFTIMESTAMP,
  2239. (struct mwifiex_ie_types_data **)
  2240. &tsf_tlv);
  2241. /* Search the TLV buffer space in the scan response for any valid
  2242. TLVs */
  2243. mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
  2244. TLV_TYPE_CHANNELBANDLIST,
  2245. (struct mwifiex_ie_types_data **)
  2246. &chan_band_tlv);
  2247. /*
  2248. * Process each scan response returned (scan_rsp->number_of_sets).
  2249. * Save the information in the bss_new_entry and then insert into the
  2250. * driver scan table either as an update to an existing entry
  2251. * or as an addition at the end of the table
  2252. */
  2253. bss_new_entry = kzalloc(sizeof(struct mwifiex_bssdescriptor),
  2254. GFP_KERNEL);
  2255. if (!bss_new_entry) {
  2256. dev_err(adapter->dev, " failed to alloc bss_new_entry\n");
  2257. return -1;
  2258. }
  2259. for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
  2260. /* Zero out the bss_new_entry we are about to store info in */
  2261. memset(bss_new_entry, 0x00,
  2262. sizeof(struct mwifiex_bssdescriptor));
  2263. if (mwifiex_interpret_bss_desc_with_ie(adapter, bss_new_entry,
  2264. &bss_info,
  2265. &bytes_left)) {
  2266. /* Error parsing/interpreting scan response, skipped */
  2267. dev_err(adapter->dev, "SCAN_RESP: "
  2268. "mwifiex_interpret_bss_desc_with_ie "
  2269. "returned ERROR\n");
  2270. continue;
  2271. }
  2272. /* Process the data fields and IEs returned for this BSS */
  2273. dev_dbg(adapter->dev, "info: SCAN_RESP: BSSID = %pM\n",
  2274. bss_new_entry->mac_address);
  2275. /* Search the scan table for the same bssid */
  2276. for (bss_idx = 0; bss_idx < num_in_table; bss_idx++) {
  2277. if (memcmp(bss_new_entry->mac_address,
  2278. adapter->scan_table[bss_idx].mac_address,
  2279. sizeof(bss_new_entry->mac_address))) {
  2280. continue;
  2281. }
  2282. /*
  2283. * If the SSID matches as well, it is a
  2284. * duplicate of this entry. Keep the bss_idx
  2285. * set to this entry so we replace the old
  2286. * contents in the table
  2287. */
  2288. if ((bss_new_entry->ssid.ssid_len
  2289. == adapter->scan_table[bss_idx]. ssid.ssid_len)
  2290. && (!memcmp(bss_new_entry->ssid.ssid,
  2291. adapter->scan_table[bss_idx].ssid.ssid,
  2292. bss_new_entry->ssid.ssid_len))) {
  2293. dev_dbg(adapter->dev, "info: SCAN_RESP:"
  2294. " duplicate of index: %d\n", bss_idx);
  2295. break;
  2296. }
  2297. }
  2298. /*
  2299. * If the bss_idx is equal to the number of entries in
  2300. * the table, the new entry was not a duplicate; append
  2301. * it to the scan table
  2302. */
  2303. if (bss_idx == num_in_table) {
  2304. /* Range check the bss_idx, keep it limited to
  2305. the last entry */
  2306. if (bss_idx == IW_MAX_AP)
  2307. bss_idx--;
  2308. else
  2309. num_in_table++;
  2310. }
  2311. /*
  2312. * Save the beacon/probe response returned for later application
  2313. * retrieval. Duplicate beacon/probe responses are updated if
  2314. * possible
  2315. */
  2316. mwifiex_ret_802_11_scan_store_beacon(priv, bss_idx,
  2317. num_in_table, bss_new_entry);
  2318. /*
  2319. * If the TSF TLV was appended to the scan results, save this
  2320. * entry's TSF value in the networkTSF field.The networkTSF is
  2321. * the firmware's TSF value at the time the beacon or probe
  2322. * response was received.
  2323. */
  2324. if (tsf_tlv) {
  2325. memcpy(&tsf_val, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE]
  2326. , sizeof(tsf_val));
  2327. memcpy(&bss_new_entry->network_tsf, &tsf_val,
  2328. sizeof(bss_new_entry->network_tsf));
  2329. }
  2330. band = BAND_G;
  2331. if (chan_band_tlv) {
  2332. chan_band = &chan_band_tlv->chan_band_param[idx];
  2333. band = mwifiex_radio_type_to_band(chan_band->radio_type
  2334. & (BIT(0) | BIT(1)));
  2335. }
  2336. /* Save the band designation for this entry for use in join */
  2337. bss_new_entry->bss_band = band;
  2338. cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv,
  2339. (u8) bss_new_entry->bss_band,
  2340. (u16)bss_new_entry->channel);
  2341. if (cfp)
  2342. bss_new_entry->freq = cfp->freq;
  2343. else
  2344. bss_new_entry->freq = 0;
  2345. /* Copy the locally created bss_new_entry to the scan table */
  2346. memcpy(&adapter->scan_table[bss_idx], bss_new_entry,
  2347. sizeof(adapter->scan_table[bss_idx]));
  2348. }
  2349. dev_dbg(adapter->dev,
  2350. "info: SCAN_RESP: Scanned %2d APs, %d valid, %d total\n",
  2351. scan_rsp->number_of_sets,
  2352. num_in_table - adapter->num_in_scan_table, num_in_table);
  2353. /* Update the total number of BSSIDs in the scan table */
  2354. adapter->num_in_scan_table = num_in_table;
  2355. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  2356. if (list_empty(&adapter->scan_pending_q)) {
  2357. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  2358. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  2359. adapter->scan_processing = false;
  2360. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  2361. /*
  2362. * Process the resulting scan table:
  2363. * - Remove any bad ssids
  2364. * - Update our current BSS information from scan data
  2365. */
  2366. mwifiex_process_scan_results(priv);
  2367. /* Need to indicate IOCTL complete */
  2368. wait_queue = (struct mwifiex_wait_queue *) wq_buf;
  2369. if (wait_queue) {
  2370. wait_queue->status = MWIFIEX_ERROR_NO_ERROR;
  2371. /* Indicate ioctl complete */
  2372. mwifiex_ioctl_complete(adapter,
  2373. (struct mwifiex_wait_queue *) wait_queue, 0);
  2374. }
  2375. if (priv->report_scan_result)
  2376. priv->report_scan_result = false;
  2377. if (priv->scan_pending_on_block) {
  2378. priv->scan_pending_on_block = false;
  2379. up(&priv->async_sem);
  2380. }
  2381. } else {
  2382. /* Get scan command from scan_pending_q and put to
  2383. cmd_pending_q */
  2384. cmd_node = list_first_entry(&adapter->scan_pending_q,
  2385. struct cmd_ctrl_node, list);
  2386. list_del(&cmd_node->list);
  2387. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  2388. mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
  2389. }
  2390. done:
  2391. kfree((u8 *) bss_new_entry);
  2392. return ret;
  2393. }
  2394. /*
  2395. * This function prepares command for background scan query.
  2396. *
  2397. * Preparation includes -
  2398. * - Setting command ID and proper size
  2399. * - Setting background scan flush parameter
  2400. * - Ensuring correct endian-ness
  2401. */
  2402. int mwifiex_cmd_802_11_bg_scan_query(struct mwifiex_private *priv,
  2403. struct host_cmd_ds_command *cmd,
  2404. void *data_buf)
  2405. {
  2406. struct host_cmd_ds_802_11_bg_scan_query *bg_query =
  2407. &cmd->params.bg_scan_query;
  2408. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
  2409. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
  2410. + S_DS_GEN);
  2411. bg_query->flush = 1;
  2412. return 0;
  2413. }
  2414. /*
  2415. * This function finds a SSID in the scan table.
  2416. *
  2417. * A BSSID may optionally be provided to qualify the SSID.
  2418. * For non-Auto mode, further check is made to make sure the
  2419. * BSS found in the scan table is compatible with the current
  2420. * settings of the driver.
  2421. */
  2422. s32
  2423. mwifiex_find_ssid_in_list(struct mwifiex_private *priv,
  2424. struct mwifiex_802_11_ssid *ssid, u8 *bssid,
  2425. u32 mode)
  2426. {
  2427. struct mwifiex_adapter *adapter = priv->adapter;
  2428. s32 net = -1, j;
  2429. u8 best_rssi = 0;
  2430. u32 i;
  2431. dev_dbg(adapter->dev, "info: num of entries in table = %d\n",
  2432. adapter->num_in_scan_table);
  2433. /*
  2434. * Loop through the table until the maximum is reached or until a match
  2435. * is found based on the bssid field comparison
  2436. */
  2437. for (i = 0;
  2438. i < adapter->num_in_scan_table && (!bssid || (bssid && net < 0));
  2439. i++) {
  2440. if (!mwifiex_ssid_cmp(&adapter->scan_table[i].ssid, ssid) &&
  2441. (!bssid
  2442. || !memcmp(adapter->scan_table[i].mac_address, bssid,
  2443. ETH_ALEN))
  2444. &&
  2445. (mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  2446. (priv, (u8) adapter->scan_table[i].bss_band,
  2447. (u16) adapter->scan_table[i].channel))) {
  2448. switch (mode) {
  2449. case MWIFIEX_BSS_MODE_INFRA:
  2450. case MWIFIEX_BSS_MODE_IBSS:
  2451. j = mwifiex_is_network_compatible(priv, i,
  2452. mode);
  2453. if (j >= 0) {
  2454. if (SCAN_RSSI
  2455. (adapter->scan_table[i].rssi) >
  2456. best_rssi) {
  2457. best_rssi = SCAN_RSSI(adapter->
  2458. scan_table
  2459. [i].rssi);
  2460. net = i;
  2461. }
  2462. } else {
  2463. if (net == -1)
  2464. net = j;
  2465. }
  2466. break;
  2467. case MWIFIEX_BSS_MODE_AUTO:
  2468. default:
  2469. /*
  2470. * Do not check compatibility if the mode
  2471. * requested is Auto/Unknown. Allows generic
  2472. * find to work without verifying against the
  2473. * Adapter security settings
  2474. */
  2475. if (SCAN_RSSI(adapter->scan_table[i].rssi) >
  2476. best_rssi) {
  2477. best_rssi = SCAN_RSSI(adapter->
  2478. scan_table[i].rssi);
  2479. net = i;
  2480. }
  2481. break;
  2482. }
  2483. }
  2484. }
  2485. return net;
  2486. }
  2487. /*
  2488. * This function finds a specific compatible BSSID in the scan list.
  2489. *
  2490. * This function loops through the scan table looking for a compatible
  2491. * match. If a BSSID matches, but the BSS is found to be not compatible
  2492. * the function ignores it and continues to search through the rest of
  2493. * the entries in case there is an AP with multiple SSIDs assigned to
  2494. * the same BSSID.
  2495. */
  2496. s32
  2497. mwifiex_find_bssid_in_list(struct mwifiex_private *priv, u8 *bssid,
  2498. u32 mode)
  2499. {
  2500. struct mwifiex_adapter *adapter = priv->adapter;
  2501. s32 net = -1;
  2502. u32 i;
  2503. if (!bssid)
  2504. return -1;
  2505. dev_dbg(adapter->dev, "info: FindBSSID: Num of BSSIDs = %d\n",
  2506. adapter->num_in_scan_table);
  2507. /*
  2508. * Look through the scan table for a compatible match. The ret return
  2509. * variable will be equal to the index in the scan table (greater
  2510. * than zero) if the network is compatible. The loop will continue
  2511. * past a matched bssid that is not compatible in case there is an
  2512. * AP with multiple SSIDs assigned to the same BSSID
  2513. */
  2514. for (i = 0; net < 0 && i < adapter->num_in_scan_table; i++) {
  2515. if (!memcmp
  2516. (adapter->scan_table[i].mac_address, bssid, ETH_ALEN)
  2517. && mwifiex_get_cfp_by_band_and_channel_from_cfg80211
  2518. (priv,
  2519. (u8) adapter->
  2520. scan_table[i].
  2521. bss_band,
  2522. (u16) adapter->
  2523. scan_table[i].
  2524. channel)) {
  2525. switch (mode) {
  2526. case MWIFIEX_BSS_MODE_INFRA:
  2527. case MWIFIEX_BSS_MODE_IBSS:
  2528. net = mwifiex_is_network_compatible(priv, i,
  2529. mode);
  2530. break;
  2531. default:
  2532. net = i;
  2533. break;
  2534. }
  2535. }
  2536. }
  2537. return net;
  2538. }
  2539. /*
  2540. * This function inserts scan command node to the scan pending queue.
  2541. */
  2542. void
  2543. mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
  2544. struct cmd_ctrl_node *cmd_node)
  2545. {
  2546. struct mwifiex_adapter *adapter = priv->adapter;
  2547. unsigned long flags;
  2548. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  2549. list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
  2550. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  2551. }
  2552. /*
  2553. * This function finds an AP with specific ssid in the scan list.
  2554. */
  2555. int mwifiex_find_best_network(struct mwifiex_private *priv,
  2556. struct mwifiex_ssid_bssid *req_ssid_bssid)
  2557. {
  2558. struct mwifiex_adapter *adapter = priv->adapter;
  2559. struct mwifiex_bssdescriptor *req_bss;
  2560. s32 i;
  2561. memset(req_ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
  2562. i = mwifiex_find_best_network_in_list(priv);
  2563. if (i >= 0) {
  2564. req_bss = &adapter->scan_table[i];
  2565. memcpy(&req_ssid_bssid->ssid, &req_bss->ssid,
  2566. sizeof(struct mwifiex_802_11_ssid));
  2567. memcpy((u8 *) &req_ssid_bssid->bssid,
  2568. (u8 *) &req_bss->mac_address, ETH_ALEN);
  2569. /* Make sure we are in the right mode */
  2570. if (priv->bss_mode == MWIFIEX_BSS_MODE_AUTO)
  2571. priv->bss_mode = req_bss->bss_mode;
  2572. }
  2573. if (!req_ssid_bssid->ssid.ssid_len)
  2574. return -1;
  2575. dev_dbg(adapter->dev, "info: Best network found = [%s], "
  2576. "[%pM]\n", req_ssid_bssid->ssid.ssid,
  2577. req_ssid_bssid->bssid);
  2578. return 0;
  2579. }
  2580. /*
  2581. * This function sends a scan command for all available channels to the
  2582. * firmware, filtered on a specific SSID.
  2583. */
  2584. static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
  2585. void *wait_buf, u16 action,
  2586. struct mwifiex_802_11_ssid *req_ssid,
  2587. struct mwifiex_scan_resp *scan_resp)
  2588. {
  2589. struct mwifiex_adapter *adapter = priv->adapter;
  2590. int ret = 0;
  2591. struct mwifiex_user_scan_cfg *scan_cfg;
  2592. if (!req_ssid)
  2593. return -1;
  2594. if (action == HostCmd_ACT_GEN_GET) {
  2595. if (scan_resp) {
  2596. scan_resp->scan_table =
  2597. (u8 *) &priv->curr_bss_params.bss_descriptor;
  2598. scan_resp->num_in_scan_table =
  2599. adapter->num_in_scan_table;
  2600. } else {
  2601. ret = -1;
  2602. }
  2603. return ret;
  2604. }
  2605. if (adapter->scan_processing && action == HostCmd_ACT_GEN_SET) {
  2606. dev_dbg(adapter->dev, "cmd: Scan already in process...\n");
  2607. return ret;
  2608. }
  2609. if (priv->scan_block && action == HostCmd_ACT_GEN_SET) {
  2610. dev_dbg(adapter->dev,
  2611. "cmd: Scan is blocked during association...\n");
  2612. return ret;
  2613. }
  2614. mwifiex_scan_delete_ssid_table_entry(priv, req_ssid);
  2615. scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
  2616. if (!scan_cfg) {
  2617. dev_err(adapter->dev, "failed to alloc scan_cfg\n");
  2618. return -1;
  2619. }
  2620. memcpy(scan_cfg->ssid_list[0].ssid, req_ssid->ssid,
  2621. req_ssid->ssid_len);
  2622. scan_cfg->keep_previous_scan = true;
  2623. ret = mwifiex_scan_networks(priv, wait_buf, action, scan_cfg, NULL);
  2624. kfree(scan_cfg);
  2625. return ret;
  2626. }
  2627. /*
  2628. * Sends IOCTL request to start a scan.
  2629. *
  2630. * This function allocates the IOCTL request buffer, fills it
  2631. * with requisite parameters and calls the IOCTL handler.
  2632. *
  2633. * Scan command can be issued for both normal scan and specific SSID
  2634. * scan, depending upon whether an SSID is provided or not.
  2635. */
  2636. int mwifiex_request_scan(struct mwifiex_private *priv, u8 wait_option,
  2637. struct mwifiex_802_11_ssid *req_ssid)
  2638. {
  2639. int ret = 0;
  2640. struct mwifiex_wait_queue *wait = NULL;
  2641. int status = 0;
  2642. if (down_interruptible(&priv->async_sem)) {
  2643. dev_err(priv->adapter->dev, "%s: acquire semaphore\n",
  2644. __func__);
  2645. return -1;
  2646. }
  2647. priv->scan_pending_on_block = true;
  2648. /* Allocate wait request buffer */
  2649. wait = mwifiex_alloc_fill_wait_queue(priv, wait_option);
  2650. if (!wait) {
  2651. ret = -1;
  2652. goto done;
  2653. }
  2654. if (req_ssid && req_ssid->ssid_len != 0)
  2655. /* Specific SSID scan */
  2656. status = mwifiex_scan_specific_ssid(priv, wait,
  2657. HostCmd_ACT_GEN_SET,
  2658. req_ssid, NULL);
  2659. else
  2660. /* Normal scan */
  2661. status = mwifiex_scan_networks(priv, wait, HostCmd_ACT_GEN_SET,
  2662. NULL, NULL);
  2663. status = mwifiex_request_ioctl(priv, wait, status, wait_option);
  2664. if (status == -1)
  2665. ret = -1;
  2666. done:
  2667. if ((wait) && (status != -EINPROGRESS))
  2668. kfree(wait);
  2669. if (ret == -1) {
  2670. priv->scan_pending_on_block = false;
  2671. up(&priv->async_sem);
  2672. }
  2673. return ret;
  2674. }
  2675. /*
  2676. * This function appends the vendor specific IE TLV to a buffer.
  2677. */
  2678. int
  2679. mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
  2680. u16 vsie_mask, u8 **buffer)
  2681. {
  2682. int id, ret_len = 0;
  2683. struct mwifiex_ie_types_vendor_param_set *vs_param_set;
  2684. if (!buffer)
  2685. return 0;
  2686. if (!(*buffer))
  2687. return 0;
  2688. /*
  2689. * Traverse through the saved vendor specific IE array and append
  2690. * the selected(scan/assoc/adhoc) IE as TLV to the command
  2691. */
  2692. for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
  2693. if (priv->vs_ie[id].mask & vsie_mask) {
  2694. vs_param_set =
  2695. (struct mwifiex_ie_types_vendor_param_set *)
  2696. *buffer;
  2697. vs_param_set->header.type =
  2698. cpu_to_le16(TLV_TYPE_PASSTHROUGH);
  2699. vs_param_set->header.len =
  2700. cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
  2701. & 0x00FF) + 2);
  2702. memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
  2703. le16_to_cpu(vs_param_set->header.len));
  2704. *buffer += le16_to_cpu(vs_param_set->header.len) +
  2705. sizeof(struct mwifiex_ie_types_header);
  2706. ret_len += le16_to_cpu(vs_param_set->header.len) +
  2707. sizeof(struct mwifiex_ie_types_header);
  2708. }
  2709. }
  2710. return ret_len;
  2711. }
  2712. /*
  2713. * This function saves a beacon buffer of the current BSS descriptor.
  2714. *
  2715. * The current beacon buffer is saved so that it can be restored in the
  2716. * following cases that makes the beacon buffer not to contain the current
  2717. * ssid's beacon buffer.
  2718. * - The current ssid was not found somehow in the last scan.
  2719. * - The current ssid was the last entry of the scan table and overloaded.
  2720. */
  2721. void
  2722. mwifiex_save_curr_bcn(struct mwifiex_private *priv)
  2723. {
  2724. struct mwifiex_bssdescriptor *curr_bss =
  2725. &priv->curr_bss_params.bss_descriptor;
  2726. /* save the beacon buffer if it is not saved or updated */
  2727. if ((priv->curr_bcn_buf == NULL) ||
  2728. (priv->curr_bcn_size != curr_bss->beacon_buf_size) ||
  2729. (memcmp(priv->curr_bcn_buf, curr_bss->beacon_buf,
  2730. curr_bss->beacon_buf_size))) {
  2731. kfree(priv->curr_bcn_buf);
  2732. priv->curr_bcn_buf = NULL;
  2733. priv->curr_bcn_size = curr_bss->beacon_buf_size;
  2734. if (!priv->curr_bcn_size)
  2735. return;
  2736. priv->curr_bcn_buf = kzalloc(curr_bss->beacon_buf_size,
  2737. GFP_KERNEL);
  2738. if (!priv->curr_bcn_buf) {
  2739. dev_err(priv->adapter->dev,
  2740. "failed to alloc curr_bcn_buf\n");
  2741. } else {
  2742. memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
  2743. curr_bss->beacon_buf_size);
  2744. dev_dbg(priv->adapter->dev,
  2745. "info: current beacon saved %d\n",
  2746. priv->curr_bcn_size);
  2747. }
  2748. }
  2749. }
  2750. /*
  2751. * This function frees the current BSS descriptor beacon buffer.
  2752. */
  2753. void
  2754. mwifiex_free_curr_bcn(struct mwifiex_private *priv)
  2755. {
  2756. kfree(priv->curr_bcn_buf);
  2757. priv->curr_bcn_buf = NULL;
  2758. }