wl_cfgscan.c 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802
  1. /*
  2. * Linux cfg80211 driver scan related code
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id$
  30. */
  31. /* */
  32. #include <typedefs.h>
  33. #include <linuxver.h>
  34. #include <osl.h>
  35. #include <linux/kernel.h>
  36. #include <bcmutils.h>
  37. #include <bcmstdlib_s.h>
  38. #include <bcmwifi_channels.h>
  39. #include <bcmendian.h>
  40. #include <ethernet.h>
  41. #include <802.11.h>
  42. #include <bcmiov.h>
  43. #include <linux/if_arp.h>
  44. #include <asm/uaccess.h>
  45. #include <ethernet.h>
  46. #include <linux/kernel.h>
  47. #include <linux/kthread.h>
  48. #include <linux/netdevice.h>
  49. #include <linux/sched.h>
  50. #include <linux/etherdevice.h>
  51. #include <linux/wireless.h>
  52. #include <linux/ieee80211.h>
  53. #include <linux/wait.h>
  54. #include <net/cfg80211.h>
  55. #include <net/rtnetlink.h>
  56. #include <wlioctl.h>
  57. #include <bcmevent.h>
  58. #include <wldev_common.h>
  59. #include <wl_cfg80211.h>
  60. #include <wl_cfgscan.h>
  61. #include <wl_cfgp2p.h>
  62. #include <bcmdevs.h>
  63. #ifdef OEM_ANDROID
  64. #include <wl_android.h>
  65. #endif // endif
  66. #include <dngl_stats.h>
  67. #include <dhd.h>
  68. #include <dhd_linux.h>
  69. #include <dhd_debug.h>
  70. #include <dhdioctl.h>
  71. #include <wlioctl.h>
  72. #include <dhd_cfg80211.h>
  73. #include <dhd_bus.h>
  74. #include <wl_cfgvendor.h>
  75. #ifdef BCMPCIE
  76. #include <dhd_flowring.h>
  77. #endif // endif
  78. #ifdef PNO_SUPPORT
  79. #include <dhd_pno.h>
  80. #endif /* PNO_SUPPORT */
  81. #ifdef RTT_SUPPORT
  82. #include "dhd_rtt.h"
  83. #endif /* RTT_SUPPORT */
  84. #define ACTIVE_SCAN 1
  85. #define PASSIVE_SCAN 0
  86. #define MIN_P2P_IE_LEN 8 /* p2p_ie->OUI(3) + p2p_ie->oui_type(1) +
  87. * Attribute ID(1) + Length(2) + 1(Mininum length:1)
  88. */
  89. #define MAX_P2P_IE_LEN 251 /* Up To 251 */
  90. #define WPS_ATTR_REQ_TYPE 0x103a
  91. #define WPS_REQ_TYPE_ENROLLEE 0x01
  92. #if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
  93. #define FIRST_SCAN_ACTIVE_DWELL_TIME_MS 40
  94. bool g_first_broadcast_scan = TRUE;
  95. #endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
  96. #ifdef CUSTOMER_HW4_DEBUG
  97. bool wl_scan_timeout_dbg_enabled = 0;
  98. #endif /* CUSTOMER_HW4_DEBUG */
  99. #ifdef P2P_LISTEN_OFFLOADING
  100. void wl_cfg80211_cancel_p2plo(struct bcm_cfg80211 *cfg);
  101. #endif /* P2P_LISTEN_OFFLOADING */
  102. static void _wl_notify_scan_done(struct bcm_cfg80211 *cfg, bool aborted);
  103. extern int passive_channel_skip;
  104. #ifdef WL11U
  105. bcm_tlv_t *
  106. wl_cfg80211_find_interworking_ie(const u8 *parse, u32 len)
  107. {
  108. bcm_tlv_t *ie;
  109. /* unfortunately it's too much work to dispose the const cast - bcm_parse_tlvs
  110. * is used everywhere and changing its prototype to take const qualifier needs
  111. * a massive change to all its callers...
  112. */
  113. if ((ie = bcm_parse_tlvs(parse, len, DOT11_MNG_INTERWORKING_ID))) {
  114. return ie;
  115. }
  116. return NULL;
  117. }
  118. s32
  119. wl_cfg80211_clear_iw_ie(struct bcm_cfg80211 *cfg, struct net_device *ndev, s32 bssidx)
  120. {
  121. ie_setbuf_t ie_setbuf;
  122. WL_DBG(("clear interworking IE\n"));
  123. bzero(&ie_setbuf, sizeof(ie_setbuf_t));
  124. ie_setbuf.ie_buffer.iecount = htod32(1);
  125. ie_setbuf.ie_buffer.ie_list[0].ie_data.id = DOT11_MNG_INTERWORKING_ID;
  126. ie_setbuf.ie_buffer.ie_list[0].ie_data.len = 0;
  127. return wldev_iovar_setbuf_bsscfg(ndev, "ie", &ie_setbuf, sizeof(ie_setbuf),
  128. cfg->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &cfg->ioctl_buf_sync);
  129. }
  130. s32
  131. wl_cfg80211_add_iw_ie(struct bcm_cfg80211 *cfg, struct net_device *ndev, s32 bssidx, s32 pktflag,
  132. uint8 ie_id, uint8 *data, uint8 data_len)
  133. {
  134. s32 err = BCME_OK;
  135. s32 buf_len;
  136. ie_setbuf_t *ie_setbuf;
  137. ie_getbuf_t ie_getbufp;
  138. char getbuf[WLC_IOCTL_SMLEN];
  139. u32 iw_ie_len = 0;
  140. u8 iw_ie[IW_IES_MAX_BUF_LEN];
  141. if (ie_id != DOT11_MNG_INTERWORKING_ID) {
  142. WL_ERR(("unsupported (id=%d)\n", ie_id));
  143. return BCME_UNSUPPORTED;
  144. }
  145. /* access network options (1 octet) is the mandatory field */
  146. if (!data || data_len == 0 || data_len > IW_IES_MAX_BUF_LEN) {
  147. WL_ERR(("wrong interworking IE (len=%d)\n", data_len));
  148. return BCME_BADARG;
  149. }
  150. /* Validate the pktflag parameter */
  151. if ((pktflag & ~(VNDR_IE_BEACON_FLAG | VNDR_IE_PRBRSP_FLAG |
  152. VNDR_IE_ASSOCRSP_FLAG | VNDR_IE_AUTHRSP_FLAG |
  153. VNDR_IE_PRBREQ_FLAG | VNDR_IE_ASSOCREQ_FLAG|
  154. VNDR_IE_CUSTOM_FLAG))) {
  155. WL_ERR(("invalid packet flag 0x%x\n", pktflag));
  156. return BCME_BADARG;
  157. }
  158. wl_get_iwdata_by_netdev(cfg, ndev, iw_ie, &iw_ie_len);
  159. if (iw_ie_len == data_len && !memcmp(iw_ie, data, data_len)) {
  160. WL_ERR(("Previous IW IE is equals to current IE\n"));
  161. return BCME_OK;
  162. }
  163. buf_len = sizeof(ie_setbuf_t) + data_len - 1;
  164. ie_getbufp.id = DOT11_MNG_INTERWORKING_ID;
  165. if (wldev_iovar_getbuf_bsscfg(ndev, "ie", (void *)&ie_getbufp,
  166. sizeof(ie_getbufp), getbuf, WLC_IOCTL_SMLEN, bssidx, &cfg->ioctl_buf_sync)
  167. == BCME_OK) {
  168. if (!memcmp(&getbuf[TLV_HDR_LEN], data, data_len)) {
  169. WL_DBG(("skip to set interworking IE\n"));
  170. return BCME_OK;
  171. }
  172. }
  173. /* if already set with previous values, delete it first */
  174. if (cfg->wl11u) {
  175. if ((err = wl_cfg80211_clear_iw_ie(cfg, ndev, bssidx)) != BCME_OK) {
  176. return err;
  177. }
  178. }
  179. ie_setbuf = (ie_setbuf_t *)MALLOCZ(cfg->osh, buf_len);
  180. if (!ie_setbuf) {
  181. WL_ERR(("Error allocating buffer for IE\n"));
  182. return -ENOMEM;
  183. }
  184. strlcpy(ie_setbuf->cmd, "add", sizeof(ie_setbuf->cmd));
  185. /* Buffer contains only 1 IE */
  186. ie_setbuf->ie_buffer.iecount = htod32(1);
  187. /* use VNDR_IE_CUSTOM_FLAG flags for none vendor IE . currently fixed value */
  188. ie_setbuf->ie_buffer.ie_list[0].pktflag = htod32(pktflag);
  189. /* Now, add the IE to the buffer */
  190. ie_setbuf->ie_buffer.ie_list[0].ie_data.id = DOT11_MNG_INTERWORKING_ID;
  191. ie_setbuf->ie_buffer.ie_list[0].ie_data.len = data_len;
  192. /* Returning void here as max data_len can be 8 */
  193. (void)memcpy_s((uchar *)&ie_setbuf->ie_buffer.ie_list[0].ie_data.data[0], sizeof(uint8),
  194. data, data_len);
  195. if ((err = wldev_iovar_setbuf_bsscfg(ndev, "ie", ie_setbuf, buf_len,
  196. cfg->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &cfg->ioctl_buf_sync))
  197. == BCME_OK) {
  198. WL_DBG(("set interworking IE\n"));
  199. cfg->wl11u = TRUE;
  200. wl_set_iwdata_by_netdev(cfg, ndev, data, data_len);
  201. err = wldev_iovar_setint_bsscfg(ndev, "grat_arp", 1, bssidx);
  202. }
  203. MFREE(cfg->osh, ie_setbuf, buf_len);
  204. return err;
  205. }
  206. #endif /* WL11U */
  207. #ifdef WL_BCNRECV
  208. /* Beacon recv results handler sending to upper layer */
  209. static s32
  210. wl_bcnrecv_result_handler(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
  211. wl_bss_info_v109_2_t *bi, uint32 scan_status)
  212. {
  213. s32 err = BCME_OK;
  214. struct wiphy *wiphy = NULL;
  215. wl_bcnrecv_result_t *bcn_recv = NULL;
  216. struct timespec ts;
  217. if (!bi) {
  218. WL_ERR(("%s: bi is NULL\n", __func__));
  219. err = BCME_NORESOURCE;
  220. goto exit;
  221. }
  222. if ((bi->length - bi->ie_length) < sizeof(wl_bss_info_v109_2_t)) {
  223. WL_ERR(("bi info version doesn't support bcn_recv attributes\n"));
  224. goto exit;
  225. }
  226. if (scan_status == WLC_E_STATUS_RXBCN) {
  227. wiphy = cfg->wdev->wiphy;
  228. if (!wiphy) {
  229. WL_ERR(("wiphy is NULL\n"));
  230. err = BCME_NORESOURCE;
  231. goto exit;
  232. }
  233. bcn_recv = (wl_bcnrecv_result_t *)MALLOCZ(cfg->osh, sizeof(*bcn_recv));
  234. if (unlikely(!bcn_recv)) {
  235. WL_ERR(("Failed to allocate memory\n"));
  236. return -ENOMEM;
  237. }
  238. /* Returning void here as copy size does not exceed dest size of SSID */
  239. (void)memcpy_s((char *)bcn_recv->SSID, DOT11_MAX_SSID_LEN,
  240. (char *)bi->SSID, DOT11_MAX_SSID_LEN);
  241. /* Returning void here as copy size does not exceed dest size of ETH_LEN */
  242. (void)memcpy_s(&bcn_recv->BSSID, ETHER_ADDR_LEN, &bi->BSSID, ETH_ALEN);
  243. bcn_recv->channel = wf_chspec_ctlchan(
  244. wl_chspec_driver_to_host(bi->chanspec));
  245. bcn_recv->beacon_interval = bi->beacon_period;
  246. /* kernal timestamp */
  247. get_monotonic_boottime(&ts);
  248. bcn_recv->system_time = ((u64)ts.tv_sec*1000000)
  249. + ts.tv_nsec / 1000;
  250. bcn_recv->timestamp[0] = bi->timestamp[0];
  251. bcn_recv->timestamp[1] = bi->timestamp[1];
  252. if ((err = wl_android_bcnrecv_event(cfgdev_to_wlc_ndev(cfgdev, cfg),
  253. BCNRECV_ATTR_BCNINFO, 0, 0,
  254. (uint8 *)bcn_recv, sizeof(*bcn_recv)))
  255. != BCME_OK) {
  256. WL_ERR(("failed to send bcnrecv event, error:%d\n", err));
  257. }
  258. } else {
  259. WL_DBG(("Ignoring Escan Event:%d \n", scan_status));
  260. }
  261. exit:
  262. if (bcn_recv) {
  263. MFREE(cfg->osh, bcn_recv, sizeof(*bcn_recv));
  264. }
  265. return err;
  266. }
  267. #endif /* WL_BCNRECV */
  268. #ifdef ESCAN_BUF_OVERFLOW_MGMT
  269. #ifndef WL_DRV_AVOID_SCANCACHE
  270. static void
  271. wl_cfg80211_find_removal_candidate(wl_bss_info_t *bss, removal_element_t *candidate)
  272. {
  273. int idx;
  274. for (idx = 0; idx < BUF_OVERFLOW_MGMT_COUNT; idx++) {
  275. int len = BUF_OVERFLOW_MGMT_COUNT - idx - 1;
  276. if (bss->RSSI < candidate[idx].RSSI) {
  277. if (len) {
  278. /* In the below memcpy operation the candidate array always has the
  279. * buffer space available to max 'len' calculated in the for loop.
  280. */
  281. (void)memcpy_s(&candidate[idx + 1],
  282. (sizeof(removal_element_t) * len),
  283. &candidate[idx], sizeof(removal_element_t) * len);
  284. }
  285. candidate[idx].RSSI = bss->RSSI;
  286. candidate[idx].length = bss->length;
  287. (void)memcpy_s(&candidate[idx].BSSID, ETHER_ADDR_LEN,
  288. &bss->BSSID, ETHER_ADDR_LEN);
  289. return;
  290. }
  291. }
  292. }
  293. static void
  294. wl_cfg80211_remove_lowRSSI_info(wl_scan_results_t *list, removal_element_t *candidate,
  295. wl_bss_info_t *bi)
  296. {
  297. int idx1, idx2;
  298. int total_delete_len = 0;
  299. for (idx1 = 0; idx1 < BUF_OVERFLOW_MGMT_COUNT; idx1++) {
  300. int cur_len = WL_SCAN_RESULTS_FIXED_SIZE;
  301. wl_bss_info_t *bss = NULL;
  302. if (candidate[idx1].RSSI >= bi->RSSI)
  303. continue;
  304. for (idx2 = 0; idx2 < list->count; idx2++) {
  305. bss = bss ? (wl_bss_info_t *)((uintptr)bss + dtoh32(bss->length)) :
  306. list->bss_info;
  307. if (!bcmp(&candidate[idx1].BSSID, &bss->BSSID, ETHER_ADDR_LEN) &&
  308. candidate[idx1].RSSI == bss->RSSI &&
  309. candidate[idx1].length == dtoh32(bss->length)) {
  310. u32 delete_len = dtoh32(bss->length);
  311. WL_DBG(("delete scan info of " MACDBG " to add new AP\n",
  312. MAC2STRDBG(bss->BSSID.octet)));
  313. if (idx2 < list->count -1) {
  314. memmove((u8 *)bss, (u8 *)bss + delete_len,
  315. list->buflen - cur_len - delete_len);
  316. }
  317. list->buflen -= delete_len;
  318. list->count--;
  319. total_delete_len += delete_len;
  320. /* if delete_len is greater than or equal to result length */
  321. if (total_delete_len >= bi->length) {
  322. return;
  323. }
  324. break;
  325. }
  326. cur_len += dtoh32(bss->length);
  327. }
  328. }
  329. }
  330. #endif /* WL_DRV_AVOID_SCANCACHE */
  331. #endif /* ESCAN_BUF_OVERFLOW_MGMT */
  332. s32
  333. wl_escan_handler(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
  334. const wl_event_msg_t *e, void *data)
  335. {
  336. s32 err = BCME_OK;
  337. s32 status = ntoh32(e->status);
  338. wl_escan_result_t *escan_result;
  339. struct net_device *ndev = NULL;
  340. #ifndef WL_DRV_AVOID_SCANCACHE
  341. wl_bss_info_t *bi;
  342. u32 bi_length;
  343. const wifi_p2p_ie_t * p2p_ie;
  344. const u8 *p2p_dev_addr = NULL;
  345. wl_scan_results_t *list;
  346. wl_bss_info_t *bss = NULL;
  347. u32 i;
  348. #endif /* WL_DRV_AVOID_SCANCACHE */
  349. WL_DBG((" enter event type : %d, status : %d \n",
  350. ntoh32(e->event_type), ntoh32(e->status)));
  351. ndev = cfgdev_to_wlc_ndev(cfgdev, cfg);
  352. mutex_lock(&cfg->scan_sync);
  353. /* P2P SCAN is coming from primary interface */
  354. if (wl_get_p2p_status(cfg, SCANNING)) {
  355. if (wl_get_drv_status_all(cfg, SENDING_ACT_FRM))
  356. ndev = cfg->afx_hdl->dev;
  357. else
  358. ndev = cfg->escan_info.ndev;
  359. }
  360. escan_result = (wl_escan_result_t *)data;
  361. #ifdef WL_BCNRECV
  362. if (cfg->bcnrecv_info.bcnrecv_state == BEACON_RECV_STARTED &&
  363. status == WLC_E_STATUS_RXBCN) {
  364. /* handle beacon recv scan results */
  365. wl_bss_info_v109_2_t *bi_info;
  366. bi_info = (wl_bss_info_v109_2_t *)escan_result->bss_info;
  367. err = wl_bcnrecv_result_handler(cfg, cfgdev, bi_info, status);
  368. goto exit;
  369. }
  370. #endif /* WL_BCNRECV */
  371. if (!ndev || (!wl_get_drv_status(cfg, SCANNING, ndev) && !cfg->sched_scan_running)) {
  372. WL_ERR_RLMT(("escan is not ready. drv_scan_status 0x%x"
  373. " e_type %d e_states %d\n",
  374. wl_get_drv_status(cfg, SCANNING, ndev),
  375. ntoh32(e->event_type), ntoh32(e->status)));
  376. goto exit;
  377. }
  378. #ifndef WL_DRV_AVOID_SCANCACHE
  379. if (status == WLC_E_STATUS_PARTIAL) {
  380. WL_DBG(("WLC_E_STATUS_PARTIAL \n"));
  381. DBG_EVENT_LOG((dhd_pub_t *)cfg->pub, WIFI_EVENT_DRIVER_SCAN_RESULT_FOUND);
  382. if (!escan_result) {
  383. WL_ERR(("Invalid escan result (NULL pointer)\n"));
  384. goto exit;
  385. }
  386. if ((dtoh32(escan_result->buflen) > (int)ESCAN_BUF_SIZE) ||
  387. (dtoh32(escan_result->buflen) < sizeof(wl_escan_result_t))) {
  388. WL_ERR(("Invalid escan buffer len:%d\n", dtoh32(escan_result->buflen)));
  389. goto exit;
  390. }
  391. if (dtoh16(escan_result->bss_count) != 1) {
  392. WL_ERR(("Invalid bss_count %d: ignoring\n", escan_result->bss_count));
  393. goto exit;
  394. }
  395. bi = escan_result->bss_info;
  396. if (!bi) {
  397. WL_ERR(("Invalid escan bss info (NULL pointer)\n"));
  398. goto exit;
  399. }
  400. bi_length = dtoh32(bi->length);
  401. if (bi_length != (dtoh32(escan_result->buflen) - WL_ESCAN_RESULTS_FIXED_SIZE)) {
  402. WL_ERR(("Invalid bss_info length %d: ignoring\n", bi_length));
  403. goto exit;
  404. }
  405. if (wl_escan_check_sync_id(status, escan_result->sync_id,
  406. cfg->escan_info.cur_sync_id) < 0)
  407. goto exit;
  408. if (!(bcmcfg_to_wiphy(cfg)->interface_modes & BIT(NL80211_IFTYPE_ADHOC))) {
  409. if (dtoh16(bi->capability) & DOT11_CAP_IBSS) {
  410. WL_DBG(("Ignoring IBSS result\n"));
  411. goto exit;
  412. }
  413. }
  414. if (wl_get_drv_status_all(cfg, FINDING_COMMON_CHANNEL)) {
  415. p2p_dev_addr = wl_cfgp2p_retreive_p2p_dev_addr(bi, bi_length);
  416. if (p2p_dev_addr && !memcmp(p2p_dev_addr,
  417. cfg->afx_hdl->tx_dst_addr.octet, ETHER_ADDR_LEN)) {
  418. s32 channel = wf_chspec_ctlchan(
  419. wl_chspec_driver_to_host(bi->chanspec));
  420. if ((channel > MAXCHANNEL) || (channel <= 0))
  421. channel = WL_INVALID;
  422. else
  423. WL_ERR(("ACTION FRAME SCAN : Peer " MACDBG " found,"
  424. " channel : %d\n",
  425. MAC2STRDBG(cfg->afx_hdl->tx_dst_addr.octet),
  426. channel));
  427. wl_clr_p2p_status(cfg, SCANNING);
  428. cfg->afx_hdl->peer_chan = channel;
  429. complete(&cfg->act_frm_scan);
  430. goto exit;
  431. }
  432. } else {
  433. int cur_len = WL_SCAN_RESULTS_FIXED_SIZE;
  434. #ifdef ESCAN_BUF_OVERFLOW_MGMT
  435. removal_element_t candidate[BUF_OVERFLOW_MGMT_COUNT];
  436. int remove_lower_rssi = FALSE;
  437. bzero(candidate, sizeof(removal_element_t)*BUF_OVERFLOW_MGMT_COUNT);
  438. #endif /* ESCAN_BUF_OVERFLOW_MGMT */
  439. list = wl_escan_get_buf(cfg, FALSE);
  440. if (scan_req_match(cfg)) {
  441. #ifdef WL_HOST_BAND_MGMT
  442. s32 channel_band = 0;
  443. chanspec_t chspec;
  444. #endif /* WL_HOST_BAND_MGMT */
  445. /* p2p scan && allow only probe response */
  446. if ((cfg->p2p->search_state != WL_P2P_DISC_ST_SCAN) &&
  447. (bi->flags & WL_BSS_FLAGS_FROM_BEACON))
  448. goto exit;
  449. if ((p2p_ie = wl_cfgp2p_find_p2pie(((u8 *) bi) + bi->ie_offset,
  450. bi->ie_length)) == NULL) {
  451. WL_ERR(("Couldn't find P2PIE in probe"
  452. " response/beacon\n"));
  453. goto exit;
  454. }
  455. #ifdef WL_HOST_BAND_MGMT
  456. chspec = wl_chspec_driver_to_host(bi->chanspec);
  457. channel_band = CHSPEC2WLC_BAND(chspec);
  458. if ((cfg->curr_band == WLC_BAND_5G) &&
  459. (channel_band == WLC_BAND_2G)) {
  460. /* Avoid sending the GO results in band conflict */
  461. if (wl_cfgp2p_retreive_p2pattrib(p2p_ie,
  462. P2P_SEID_GROUP_ID) != NULL)
  463. goto exit;
  464. }
  465. #endif /* WL_HOST_BAND_MGMT */
  466. }
  467. #ifdef ESCAN_BUF_OVERFLOW_MGMT
  468. if (bi_length > ESCAN_BUF_SIZE - list->buflen)
  469. remove_lower_rssi = TRUE;
  470. #endif /* ESCAN_BUF_OVERFLOW_MGMT */
  471. for (i = 0; i < list->count; i++) {
  472. bss = bss ? (wl_bss_info_t *)((uintptr)bss + dtoh32(bss->length))
  473. : list->bss_info;
  474. if (!bss) {
  475. WL_ERR(("bss is NULL\n"));
  476. goto exit;
  477. }
  478. #ifdef ESCAN_BUF_OVERFLOW_MGMT
  479. WL_TRACE(("%s("MACDBG"), i=%d bss: RSSI %d list->count %d\n",
  480. bss->SSID, MAC2STRDBG(bss->BSSID.octet),
  481. i, bss->RSSI, list->count));
  482. if (remove_lower_rssi)
  483. wl_cfg80211_find_removal_candidate(bss, candidate);
  484. #endif /* ESCAN_BUF_OVERFLOW_MGMT */
  485. if (!bcmp(&bi->BSSID, &bss->BSSID, ETHER_ADDR_LEN) &&
  486. (CHSPEC_BAND(wl_chspec_driver_to_host(bi->chanspec))
  487. == CHSPEC_BAND(wl_chspec_driver_to_host(bss->chanspec))) &&
  488. bi->SSID_len == bss->SSID_len &&
  489. !bcmp(bi->SSID, bss->SSID, bi->SSID_len)) {
  490. /* do not allow beacon data to update
  491. *the data recd from a probe response
  492. */
  493. if (!(bss->flags & WL_BSS_FLAGS_FROM_BEACON) &&
  494. (bi->flags & WL_BSS_FLAGS_FROM_BEACON))
  495. goto exit;
  496. WL_DBG(("%s("MACDBG"), i=%d prev: RSSI %d"
  497. " flags 0x%x, new: RSSI %d flags 0x%x\n",
  498. bss->SSID, MAC2STRDBG(bi->BSSID.octet), i,
  499. bss->RSSI, bss->flags, bi->RSSI, bi->flags));
  500. if ((bss->flags & WL_BSS_FLAGS_RSSI_ONCHANNEL) ==
  501. (bi->flags & WL_BSS_FLAGS_RSSI_ONCHANNEL)) {
  502. /* preserve max RSSI if the measurements are
  503. * both on-channel or both off-channel
  504. */
  505. WL_SCAN(("%s("MACDBG"), same onchan"
  506. ", RSSI: prev %d new %d\n",
  507. bss->SSID, MAC2STRDBG(bi->BSSID.octet),
  508. bss->RSSI, bi->RSSI));
  509. bi->RSSI = MAX(bss->RSSI, bi->RSSI);
  510. } else if ((bss->flags & WL_BSS_FLAGS_RSSI_ONCHANNEL) &&
  511. (bi->flags & WL_BSS_FLAGS_RSSI_ONCHANNEL) == 0) {
  512. /* preserve the on-channel rssi measurement
  513. * if the new measurement is off channel
  514. */
  515. WL_SCAN(("%s("MACDBG"), prev onchan"
  516. ", RSSI: prev %d new %d\n",
  517. bss->SSID, MAC2STRDBG(bi->BSSID.octet),
  518. bss->RSSI, bi->RSSI));
  519. bi->RSSI = bss->RSSI;
  520. bi->flags |= WL_BSS_FLAGS_RSSI_ONCHANNEL;
  521. }
  522. if (dtoh32(bss->length) != bi_length) {
  523. u32 prev_len = dtoh32(bss->length);
  524. WL_SCAN(("bss info replacement"
  525. " is occured(bcast:%d->probresp%d)\n",
  526. bss->ie_length, bi->ie_length));
  527. WL_DBG(("%s("MACDBG"), replacement!(%d -> %d)\n",
  528. bss->SSID, MAC2STRDBG(bi->BSSID.octet),
  529. prev_len, bi_length));
  530. if ((list->buflen - prev_len) + bi_length
  531. > ESCAN_BUF_SIZE) {
  532. WL_ERR(("Buffer is too small: keep the"
  533. " previous result of this AP\n"));
  534. /* Only update RSSI */
  535. bss->RSSI = bi->RSSI;
  536. bss->flags |= (bi->flags
  537. & WL_BSS_FLAGS_RSSI_ONCHANNEL);
  538. goto exit;
  539. }
  540. if (i < list->count - 1) {
  541. /* memory copy required by this case only */
  542. memmove((u8 *)bss + bi_length,
  543. (u8 *)bss + prev_len,
  544. list->buflen - cur_len - prev_len);
  545. }
  546. list->buflen -= prev_len;
  547. list->buflen += bi_length;
  548. }
  549. list->version = dtoh32(bi->version);
  550. /* In the above code under check
  551. * '(dtoh32(bss->length) != bi_length)'
  552. * buffer overflow is avoided. bi_length
  553. * is already accounted in list->buflen
  554. */
  555. if ((err = memcpy_s((u8 *)bss,
  556. (ESCAN_BUF_SIZE - (list->buflen - bi_length)),
  557. (u8 *)bi, bi_length)) != BCME_OK) {
  558. WL_ERR(("Failed to copy the recent bss_info."
  559. "err:%d recv_len:%d bi_len:%d\n", err,
  560. ESCAN_BUF_SIZE - (list->buflen - bi_length),
  561. bi_length));
  562. /* This scenario should never happen. If it happens,
  563. * set list->count to zero for recovery
  564. */
  565. list->count = 0;
  566. list->buflen = 0;
  567. ASSERT(0);
  568. }
  569. goto exit;
  570. }
  571. cur_len += dtoh32(bss->length);
  572. }
  573. if (bi_length > ESCAN_BUF_SIZE - list->buflen) {
  574. #ifdef ESCAN_BUF_OVERFLOW_MGMT
  575. wl_cfg80211_remove_lowRSSI_info(list, candidate, bi);
  576. if (bi_length > ESCAN_BUF_SIZE - list->buflen) {
  577. WL_DBG(("RSSI(" MACDBG ") is too low(%d) to add Buffer\n",
  578. MAC2STRDBG(bi->BSSID.octet), bi->RSSI));
  579. goto exit;
  580. }
  581. #else
  582. WL_ERR(("Buffer is too small: ignoring\n"));
  583. goto exit;
  584. #endif /* ESCAN_BUF_OVERFLOW_MGMT */
  585. }
  586. /* In the previous step check is added to ensure the bi_legth does not
  587. * exceed the ESCAN_BUF_SIZE
  588. */
  589. (void)memcpy_s(&(((char *)list)[list->buflen]),
  590. (ESCAN_BUF_SIZE - list->buflen), bi, bi_length);
  591. list->version = dtoh32(bi->version);
  592. list->buflen += bi_length;
  593. list->count++;
  594. /*
  595. * !Broadcast && number of ssid = 1 && number of channels =1
  596. * means specific scan to association
  597. */
  598. if (wl_cfgp2p_is_p2p_specific_scan(cfg->scan_request)) {
  599. WL_ERR(("P2P assoc scan fast aborted.\n"));
  600. wl_notify_escan_complete(cfg, cfg->escan_info.ndev, false, true);
  601. goto exit;
  602. }
  603. }
  604. }
  605. else if (status == WLC_E_STATUS_SUCCESS) {
  606. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  607. wl_escan_print_sync_id(status, cfg->escan_info.cur_sync_id,
  608. escan_result->sync_id);
  609. if (wl_get_drv_status_all(cfg, FINDING_COMMON_CHANNEL)) {
  610. WL_DBG(("ACTION FRAME SCAN DONE\n"));
  611. wl_clr_p2p_status(cfg, SCANNING);
  612. wl_clr_drv_status(cfg, SCANNING, cfg->afx_hdl->dev);
  613. if (cfg->afx_hdl->peer_chan == WL_INVALID)
  614. complete(&cfg->act_frm_scan);
  615. } else if ((likely(cfg->scan_request)) || (cfg->sched_scan_running)) {
  616. WL_INFORM_MEM(("ESCAN COMPLETED\n"));
  617. DBG_EVENT_LOG((dhd_pub_t *)cfg->pub, WIFI_EVENT_DRIVER_SCAN_COMPLETE);
  618. cfg->bss_list = wl_escan_get_buf(cfg, FALSE);
  619. if (!scan_req_match(cfg)) {
  620. WL_TRACE_HW4(("SCAN COMPLETED: scanned AP count=%d\n",
  621. cfg->bss_list->count));
  622. }
  623. wl_inform_bss(cfg);
  624. wl_notify_escan_complete(cfg, ndev, false, false);
  625. }
  626. wl_escan_increment_sync_id(cfg, SCAN_BUF_NEXT);
  627. #ifdef CUSTOMER_HW4_DEBUG
  628. if (wl_scan_timeout_dbg_enabled)
  629. wl_scan_timeout_dbg_clear();
  630. #endif /* CUSTOMER_HW4_DEBUG */
  631. } else if ((status == WLC_E_STATUS_ABORT) || (status == WLC_E_STATUS_NEWSCAN) ||
  632. (status == WLC_E_STATUS_11HQUIET) || (status == WLC_E_STATUS_CS_ABORT) ||
  633. (status == WLC_E_STATUS_NEWASSOC)) {
  634. /* Dump FW preserve buffer content */
  635. if (status == WLC_E_STATUS_ABORT) {
  636. wl_flush_fw_log_buffer(ndev, FW_LOGSET_MASK_ALL);
  637. }
  638. /* Handle all cases of scan abort */
  639. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  640. wl_escan_print_sync_id(status, escan_result->sync_id,
  641. cfg->escan_info.cur_sync_id);
  642. WL_DBG(("ESCAN ABORT reason: %d\n", status));
  643. if (wl_get_drv_status_all(cfg, FINDING_COMMON_CHANNEL)) {
  644. WL_DBG(("ACTION FRAME SCAN DONE\n"));
  645. wl_clr_drv_status(cfg, SCANNING, cfg->afx_hdl->dev);
  646. wl_clr_p2p_status(cfg, SCANNING);
  647. if (cfg->afx_hdl->peer_chan == WL_INVALID)
  648. complete(&cfg->act_frm_scan);
  649. } else if ((likely(cfg->scan_request)) || (cfg->sched_scan_running)) {
  650. WL_INFORM_MEM(("ESCAN ABORTED\n"));
  651. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  652. if (p2p_scan(cfg) && cfg->scan_request &&
  653. (cfg->scan_request->flags & NL80211_SCAN_FLAG_FLUSH)) {
  654. WL_ERR(("scan list is changed"));
  655. cfg->bss_list = wl_escan_get_buf(cfg, FALSE);
  656. } else
  657. #endif // endif
  658. cfg->bss_list = wl_escan_get_buf(cfg, TRUE);
  659. if (!scan_req_match(cfg)) {
  660. WL_TRACE_HW4(("SCAN ABORTED: scanned AP count=%d\n",
  661. cfg->bss_list->count));
  662. }
  663. #ifdef DUAL_ESCAN_RESULT_BUFFER
  664. if (escan_result->sync_id != cfg->escan_info.cur_sync_id) {
  665. /* If sync_id is not matching, then the abort might have
  666. * come for the old scan req or for the in-driver initiated
  667. * scan. So do abort for scan_req for which sync_id is
  668. * matching.
  669. */
  670. WL_INFORM_MEM(("sync_id mismatch (%d != %d). "
  671. "Ignore the scan abort event.\n",
  672. escan_result->sync_id, cfg->escan_info.cur_sync_id));
  673. goto exit;
  674. } else {
  675. /* sync id is matching, abort the scan */
  676. WL_INFORM_MEM(("scan aborted for sync_id: %d \n",
  677. cfg->escan_info.cur_sync_id));
  678. wl_inform_bss(cfg);
  679. wl_notify_escan_complete(cfg, ndev, true, false);
  680. }
  681. #else
  682. wl_inform_bss(cfg);
  683. wl_notify_escan_complete(cfg, ndev, true, false);
  684. #endif /* DUAL_ESCAN_RESULT_BUFFER */
  685. } else {
  686. /* If there is no pending host initiated scan, do nothing */
  687. WL_DBG(("ESCAN ABORT: No pending scans. Ignoring event.\n"));
  688. }
  689. wl_escan_increment_sync_id(cfg, SCAN_BUF_CNT);
  690. } else if (status == WLC_E_STATUS_TIMEOUT) {
  691. WL_ERR(("WLC_E_STATUS_TIMEOUT : scan_request[%p]\n", cfg->scan_request));
  692. WL_ERR(("reason[0x%x]\n", e->reason));
  693. if (e->reason == 0xFFFFFFFF) {
  694. wl_notify_escan_complete(cfg, cfg->escan_info.ndev, true, true);
  695. }
  696. } else {
  697. WL_ERR(("unexpected Escan Event %d : abort\n", status));
  698. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  699. wl_escan_print_sync_id(status, escan_result->sync_id,
  700. cfg->escan_info.cur_sync_id);
  701. if (wl_get_drv_status_all(cfg, FINDING_COMMON_CHANNEL)) {
  702. WL_DBG(("ACTION FRAME SCAN DONE\n"));
  703. wl_clr_p2p_status(cfg, SCANNING);
  704. wl_clr_drv_status(cfg, SCANNING, cfg->afx_hdl->dev);
  705. if (cfg->afx_hdl->peer_chan == WL_INVALID)
  706. complete(&cfg->act_frm_scan);
  707. } else if ((likely(cfg->scan_request)) || (cfg->sched_scan_running)) {
  708. cfg->bss_list = wl_escan_get_buf(cfg, TRUE);
  709. if (!scan_req_match(cfg)) {
  710. WL_TRACE_HW4(("SCAN ABORTED(UNEXPECTED): "
  711. "scanned AP count=%d\n",
  712. cfg->bss_list->count));
  713. }
  714. wl_inform_bss(cfg);
  715. wl_notify_escan_complete(cfg, ndev, true, false);
  716. }
  717. wl_escan_increment_sync_id(cfg, 2);
  718. }
  719. #else /* WL_DRV_AVOID_SCANCACHE */
  720. err = wl_escan_without_scan_cache(cfg, escan_result, ndev, e, status);
  721. #endif /* WL_DRV_AVOID_SCANCACHE */
  722. exit:
  723. mutex_unlock(&cfg->scan_sync);
  724. return err;
  725. }
  726. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && \
  727. defined(SUPPORT_RANDOM_MAC_SCAN)
  728. static const u8 *
  729. wl_retrieve_wps_attribute(const u8 *buf, u16 element_id)
  730. {
  731. const wl_wps_ie_t *ie = NULL;
  732. u16 len = 0;
  733. const u8 *attrib;
  734. if (!buf) {
  735. WL_ERR(("WPS IE not present"));
  736. return 0;
  737. }
  738. ie = (const wl_wps_ie_t*) buf;
  739. len = ie->len;
  740. /* Point subel to the P2P IE's subelt field.
  741. * Subtract the preceding fields (id, len, OUI, oui_type) from the length.
  742. */
  743. attrib = ie->attrib;
  744. len -= 4; /* exclude OUI + OUI_TYPE */
  745. /* Search for attrib */
  746. return wl_find_attribute(attrib, len, element_id);
  747. }
  748. static bool
  749. wl_is_wps_enrollee_active(struct net_device *ndev, const u8 *ie_ptr, u16 len)
  750. {
  751. const u8 *ie;
  752. const u8 *attrib;
  753. if ((ie = (const u8 *)wl_cfgp2p_find_wpsie(ie_ptr, len)) == NULL) {
  754. WL_DBG(("WPS IE not present. Do nothing.\n"));
  755. return false;
  756. }
  757. if ((attrib = wl_retrieve_wps_attribute(ie, WPS_ATTR_REQ_TYPE)) == NULL) {
  758. WL_DBG(("WPS_ATTR_REQ_TYPE not found!\n"));
  759. return false;
  760. }
  761. if (*attrib == WPS_REQ_TYPE_ENROLLEE) {
  762. WL_INFORM_MEM(("WPS Enrolle Active\n"));
  763. return true;
  764. } else {
  765. WL_DBG(("WPS_REQ_TYPE:%d\n", *attrib));
  766. }
  767. return false;
  768. }
  769. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) && defined(SUPPORT_RANDOM_MAC_SCAN) */
  770. /* Find listen channel */
  771. static s32 wl_find_listen_channel(struct bcm_cfg80211 *cfg,
  772. const u8 *ie, u32 ie_len)
  773. {
  774. const wifi_p2p_ie_t *p2p_ie;
  775. const u8 *end, *pos;
  776. s32 listen_channel;
  777. pos = (const u8 *)ie;
  778. p2p_ie = wl_cfgp2p_find_p2pie(pos, ie_len);
  779. if (p2p_ie == NULL) {
  780. return 0;
  781. }
  782. if (p2p_ie->len < MIN_P2P_IE_LEN || p2p_ie->len > MAX_P2P_IE_LEN) {
  783. CFGP2P_ERR(("p2p_ie->len out of range - %d\n", p2p_ie->len));
  784. return 0;
  785. }
  786. pos = p2p_ie->subelts;
  787. end = p2p_ie->subelts + (p2p_ie->len - 4);
  788. CFGP2P_DBG((" found p2p ie ! lenth %d \n",
  789. p2p_ie->len));
  790. while (pos < end) {
  791. uint16 attr_len;
  792. if (pos + 2 >= end) {
  793. CFGP2P_DBG((" -- Invalid P2P attribute"));
  794. return 0;
  795. }
  796. attr_len = ((uint16) (((pos + 1)[1] << 8) | (pos + 1)[0]));
  797. if (pos + 3 + attr_len > end) {
  798. CFGP2P_DBG(("P2P: Attribute underflow "
  799. "(len=%u left=%d)",
  800. attr_len, (int) (end - pos - 3)));
  801. return 0;
  802. }
  803. /* if Listen Channel att id is 6 and the vailue is valid,
  804. * return the listen channel
  805. */
  806. if (pos[0] == 6) {
  807. /* listen channel subel length format
  808. * 1(id) + 2(len) + 3(country) + 1(op. class) + 1(chan num)
  809. */
  810. listen_channel = pos[1 + 2 + 3 + 1];
  811. if (listen_channel == SOCIAL_CHAN_1 ||
  812. listen_channel == SOCIAL_CHAN_2 ||
  813. listen_channel == SOCIAL_CHAN_3) {
  814. CFGP2P_DBG((" Found my Listen Channel %d \n", listen_channel));
  815. return listen_channel;
  816. }
  817. }
  818. pos += 3 + attr_len;
  819. }
  820. return 0;
  821. }
  822. #ifdef WL_SCAN_TYPE
  823. static u32
  824. wl_cfgscan_map_nl80211_scan_type(struct bcm_cfg80211 *cfg, struct cfg80211_scan_request *request)
  825. {
  826. u32 scan_flags = 0;
  827. if (!request) {
  828. return scan_flags;
  829. }
  830. if (request->flags & NL80211_SCAN_FLAG_LOW_SPAN) {
  831. scan_flags |= WL_SCANFLAGS_LOW_SPAN;
  832. }
  833. if (request->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) {
  834. scan_flags |= WL_SCANFLAGS_HIGH_ACCURACY;
  835. }
  836. if (request->flags & NL80211_SCAN_FLAG_LOW_POWER) {
  837. scan_flags |= WL_SCANFLAGS_LOW_POWER_SCAN;
  838. }
  839. if (request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) {
  840. scan_flags |= WL_SCANFLAGS_LOW_PRIO;
  841. }
  842. WL_INFORM(("scan flags. wl:%x cfg80211:%x\n", scan_flags, request->flags));
  843. return scan_flags;
  844. }
  845. #endif /* WL_SCAN_TYPE */
  846. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
  847. #define IS_RADAR_CHAN(flags) (flags & (IEEE80211_CHAN_RADAR | IEEE80211_CHAN_PASSIVE_SCAN))
  848. #else
  849. #define IS_RADAR_CHAN(flags) (flags & (IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IR))
  850. #endif // endif
  851. static void
  852. wl_cfgscan_populate_scan_channels(struct bcm_cfg80211 *cfg, u16 *channel_list,
  853. struct cfg80211_scan_request *request, u32 *num_channels)
  854. {
  855. u32 i = 0, j = 0;
  856. u32 channel;
  857. u32 n_channels = 0;
  858. u32 chanspec = 0;
  859. if (!request || !request->n_channels) {
  860. /* Do full channel scan */
  861. return;
  862. }
  863. n_channels = request->n_channels;
  864. for (i = 0; i < n_channels; i++) {
  865. channel = ieee80211_frequency_to_channel(request->channels[i]->center_freq);
  866. /* SKIP DFS channels for Secondary interface */
  867. if ((cfg->escan_info.ndev != bcmcfg_to_prmry_ndev(cfg)) &&
  868. (IS_RADAR_CHAN(request->channels[i]->flags)))
  869. continue;
  870. chanspec = WL_CHANSPEC_BW_20;
  871. if (chanspec == INVCHANSPEC) {
  872. WL_ERR(("Invalid chanspec! Skipping channel\n"));
  873. continue;
  874. }
  875. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  876. if (request->channels[i]->band == IEEE80211_BAND_60GHZ) {
  877. /* Not supported */
  878. continue;
  879. }
  880. #endif /* LINUX_VER >= 3.6 */
  881. if (request->channels[i]->band == IEEE80211_BAND_2GHZ) {
  882. #ifdef WL_HOST_BAND_MGMT
  883. if (cfg->curr_band == WLC_BAND_5G) {
  884. WL_DBG(("In 5G only mode, omit 2G channel:%d\n", channel));
  885. continue;
  886. }
  887. #endif /* WL_HOST_BAND_MGMT */
  888. chanspec |= WL_CHANSPEC_BAND_2G;
  889. } else {
  890. #ifdef WL_HOST_BAND_MGMT
  891. if (cfg->curr_band == WLC_BAND_2G) {
  892. WL_DBG(("In 2G only mode, omit 5G channel:%d\n", channel));
  893. continue;
  894. }
  895. #endif /* WL_HOST_BAND_MGMT */
  896. chanspec |= WL_CHANSPEC_BAND_5G;
  897. }
  898. channel_list[j] = channel;
  899. channel_list[j] &= WL_CHANSPEC_CHAN_MASK;
  900. channel_list[j] |= chanspec;
  901. WL_SCAN(("Chan : %d, Channel spec: %x \n",
  902. channel, channel_list[j]));
  903. channel_list[j] = wl_chspec_host_to_driver(channel_list[j]);
  904. j++;
  905. }
  906. *num_channels = j;
  907. }
  908. static void
  909. wl_cfgscan_populate_scan_ssids(struct bcm_cfg80211 *cfg, u8 *buf_ptr, u32 buf_len,
  910. struct cfg80211_scan_request *request, u32 *ssid_num)
  911. {
  912. u32 n_ssids;
  913. wlc_ssid_t ssid;
  914. int i, j = 0;
  915. if (!request || !buf_ptr) {
  916. /* Do full channel scan */
  917. return;
  918. }
  919. n_ssids = request->n_ssids;
  920. if (n_ssids > 0) {
  921. if (buf_len < (n_ssids * sizeof(wlc_ssid_t))) {
  922. WL_ERR(("buf len not sufficient for scan ssids\n"));
  923. return;
  924. }
  925. for (i = 0; i < n_ssids; i++) {
  926. bzero(&ssid, sizeof(wlc_ssid_t));
  927. ssid.SSID_len = MIN(request->ssids[i].ssid_len, DOT11_MAX_SSID_LEN);
  928. /* Returning void here, as per previous line copy length does not exceed
  929. * DOT11_MAX_SSID_LEN
  930. */
  931. (void)memcpy_s(ssid.SSID, DOT11_MAX_SSID_LEN, request->ssids[i].ssid,
  932. ssid.SSID_len);
  933. if (!ssid.SSID_len) {
  934. WL_SCAN(("%d: Broadcast scan\n", i));
  935. } else {
  936. WL_SCAN(("%d: scan for %s size =%d\n", i,
  937. ssid.SSID, ssid.SSID_len));
  938. }
  939. /* For multiple ssid case copy the each SSID info the ptr below corresponds
  940. * to that so dest is of type wlc_ssid_t
  941. */
  942. (void)memcpy_s(buf_ptr, sizeof(wlc_ssid_t), &ssid, sizeof(wlc_ssid_t));
  943. buf_ptr += sizeof(wlc_ssid_t);
  944. j++;
  945. }
  946. } else {
  947. WL_SCAN(("Broadcast scan\n"));
  948. }
  949. *ssid_num = j;
  950. }
  951. static s32
  952. wl_scan_prep(struct bcm_cfg80211 *cfg, void *scan_params, u32 len,
  953. struct cfg80211_scan_request *request)
  954. {
  955. wl_scan_params_t *params = NULL;
  956. wl_scan_params_v2_t *params_v2 = NULL;
  957. u32 scan_type = 0;
  958. u32 scan_param_size = 0;
  959. u32 n_channels = 0;
  960. u32 n_ssids = 0;
  961. uint16 *chan_list = NULL;
  962. u32 channel_offset = 0;
  963. u32 cur_offset;
  964. if (!scan_params) {
  965. return BCME_ERROR;
  966. }
  967. if (cfg->active_scan == PASSIVE_SCAN) {
  968. WL_INFORM_MEM(("Enforcing passive scan\n"));
  969. scan_type = WL_SCANFLAGS_PASSIVE;
  970. }
  971. WL_DBG(("Preparing Scan request\n"));
  972. if (cfg->scan_params_v2) {
  973. params_v2 = (wl_scan_params_v2_t *)scan_params;
  974. scan_param_size = sizeof(wl_scan_params_v2_t);
  975. channel_offset = offsetof(wl_scan_params_v2_t, channel_list);
  976. } else {
  977. params = (wl_scan_params_t *)scan_params;
  978. scan_param_size = sizeof(wl_scan_params_t);
  979. channel_offset = offsetof(wl_scan_params_t, channel_list);
  980. }
  981. if (params_v2) {
  982. /* scan params ver2 */
  983. #if defined(WL_SCAN_TYPE)
  984. scan_type += wl_cfgscan_map_nl80211_scan_type(cfg, request);
  985. #endif /* WL_SCAN_TYPE */
  986. (void)memcpy_s(&params_v2->bssid, ETHER_ADDR_LEN, &ether_bcast, ETHER_ADDR_LEN);
  987. params_v2->version = htod16(WL_SCAN_PARAMS_VERSION_V2);
  988. params_v2->length = htod16(sizeof(wl_scan_params_v2_t));
  989. params_v2->bss_type = DOT11_BSSTYPE_ANY;
  990. params_v2->scan_type = htod32(scan_type);
  991. params_v2->nprobes = htod32(-1);
  992. params_v2->active_time = htod32(-1);
  993. params_v2->passive_time = htod32(-1);
  994. params_v2->home_time = htod32(-1);
  995. params_v2->channel_num = 0;
  996. bzero(&params_v2->ssid, sizeof(wlc_ssid_t));
  997. chan_list = params_v2->channel_list;
  998. } else {
  999. /* scan params ver 1 */
  1000. if (!params) {
  1001. ASSERT(0);
  1002. return BCME_ERROR;
  1003. }
  1004. (void)memcpy_s(&params->bssid, ETHER_ADDR_LEN, &ether_bcast, ETHER_ADDR_LEN);
  1005. params->bss_type = DOT11_BSSTYPE_ANY;
  1006. params->scan_type = 0;
  1007. params->nprobes = htod32(-1);
  1008. params->active_time = htod32(-1);
  1009. params->passive_time = htod32(-1);
  1010. params->home_time = htod32(-1);
  1011. params->channel_num = 0;
  1012. bzero(&params->ssid, sizeof(wlc_ssid_t));
  1013. chan_list = params->channel_list;
  1014. }
  1015. if (!request) {
  1016. /* scan_request null, do scan based on base config */
  1017. WL_DBG(("scan_request is null\n"));
  1018. return BCME_OK;
  1019. }
  1020. WL_INFORM(("n_channels:%d n_ssids:%d\n", request->n_channels, request->n_ssids));
  1021. cur_offset = channel_offset;
  1022. /* Copy channel array if applicable */
  1023. if ((request->n_channels > 0) && chan_list) {
  1024. if (len >= (scan_param_size + (request->n_channels * sizeof(u16)))) {
  1025. wl_cfgscan_populate_scan_channels(cfg,
  1026. chan_list, request, &n_channels);
  1027. cur_offset += (n_channels * (sizeof(u16)));
  1028. }
  1029. }
  1030. /* Copy ssid array if applicable */
  1031. if (request->n_ssids > 0) {
  1032. cur_offset = roundup(cur_offset, sizeof(u32));
  1033. if (len > (cur_offset + (request->n_ssids * sizeof(wlc_ssid_t)))) {
  1034. u32 rem_len = len - cur_offset;
  1035. wl_cfgscan_populate_scan_ssids(cfg,
  1036. ((u8 *)scan_params + cur_offset), rem_len, request, &n_ssids);
  1037. }
  1038. }
  1039. if (n_ssids || n_channels) {
  1040. u32 channel_num =
  1041. htod32((n_ssids << WL_SCAN_PARAMS_NSSID_SHIFT) |
  1042. (n_channels & WL_SCAN_PARAMS_COUNT_MASK));
  1043. if (params_v2) {
  1044. params_v2->channel_num = channel_num;
  1045. if (n_channels == 1) {
  1046. params_v2->active_time = htod32(WL_SCAN_CONNECT_DWELL_TIME_MS);
  1047. params_v2->nprobes = htod32(
  1048. params_v2->active_time / WL_SCAN_JOIN_PROBE_INTERVAL_MS);
  1049. }
  1050. } else {
  1051. params->channel_num = channel_num;
  1052. if (n_channels == 1) {
  1053. params->active_time = htod32(WL_SCAN_CONNECT_DWELL_TIME_MS);
  1054. params->nprobes = htod32(
  1055. params->active_time / WL_SCAN_JOIN_PROBE_INTERVAL_MS);
  1056. }
  1057. }
  1058. }
  1059. WL_INFORM(("scan_prep done. n_channels:%d n_ssids:%d\n", n_channels, n_ssids));
  1060. return BCME_OK;
  1061. }
  1062. static s32
  1063. wl_get_valid_channels(struct net_device *ndev, u8 *valid_chan_list, s32 size)
  1064. {
  1065. wl_uint32_list_t *list;
  1066. s32 err = BCME_OK;
  1067. if (valid_chan_list == NULL || size <= 0)
  1068. return -ENOMEM;
  1069. bzero(valid_chan_list, size);
  1070. list = (wl_uint32_list_t *)(void *) valid_chan_list;
  1071. list->count = htod32(WL_NUMCHANNELS);
  1072. err = wldev_ioctl_get(ndev, WLC_GET_VALID_CHANNELS, valid_chan_list, size);
  1073. if (err != 0) {
  1074. WL_ERR(("get channels failed with %d\n", err));
  1075. }
  1076. return err;
  1077. }
  1078. static s32
  1079. wl_run_escan(struct bcm_cfg80211 *cfg, struct net_device *ndev,
  1080. struct cfg80211_scan_request *request, uint16 action)
  1081. {
  1082. s32 err = BCME_OK;
  1083. u32 n_channels;
  1084. u32 n_ssids;
  1085. s32 params_size;
  1086. wl_escan_params_t *eparams = NULL;
  1087. wl_escan_params_v2_t *eparams_v2 = NULL;
  1088. u8 *scan_params = NULL;
  1089. u8 *params = NULL;
  1090. u8 chan_buf[sizeof(u32)*(WL_NUMCHANNELS + 1)];
  1091. u32 num_chans = 0;
  1092. s32 channel;
  1093. u32 n_valid_chan;
  1094. s32 search_state = WL_P2P_DISC_ST_SCAN;
  1095. u32 i, j, n_nodfs = 0;
  1096. u16 *default_chan_list = NULL;
  1097. wl_uint32_list_t *list;
  1098. s32 bssidx = -1;
  1099. struct net_device *dev = NULL;
  1100. #if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
  1101. bool is_first_init_2g_scan = false;
  1102. #endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
  1103. p2p_scan_purpose_t p2p_scan_purpose = P2P_SCAN_PURPOSE_MIN;
  1104. u32 chan_mem = 0;
  1105. u32 sync_id = 0;
  1106. WL_DBG(("Enter \n"));
  1107. /* scan request can come with empty request : perform all default scan */
  1108. if (!cfg) {
  1109. err = -EINVAL;
  1110. goto exit;
  1111. }
  1112. if (cfg->scan_params_v2) {
  1113. params_size = (WL_SCAN_PARAMS_V2_FIXED_SIZE +
  1114. OFFSETOF(wl_escan_params_v2_t, params));
  1115. } else {
  1116. params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_escan_params_t, params));
  1117. }
  1118. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && \
  1119. defined(SUPPORT_RANDOM_MAC_SCAN)
  1120. if ((request != NULL) && !ETHER_ISNULLADDR(request->mac_addr) &&
  1121. !ETHER_ISNULLADDR(request->mac_addr_mask) &&
  1122. !wl_is_wps_enrollee_active(ndev, request->ie, request->ie_len)) {
  1123. /* Call scanmac only for valid configuration */
  1124. err = wl_cfg80211_scan_mac_enable(ndev, request->mac_addr,
  1125. request->mac_addr_mask);
  1126. if (err < 0) {
  1127. if (err == BCME_UNSUPPORTED) {
  1128. /* Ignore if chip doesnt support the feature */
  1129. err = BCME_OK;
  1130. } else {
  1131. /* For errors other than unsupported fail the scan */
  1132. WL_ERR(("%s : failed to set random mac for host scan, %d\n",
  1133. __FUNCTION__, err));
  1134. err = -EAGAIN;
  1135. goto exit;
  1136. }
  1137. }
  1138. }
  1139. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) && defined(SUPPORT_RANDOM_MAC_SCAN) */
  1140. if (!cfg->p2p_supported || !p2p_scan(cfg)) {
  1141. /* LEGACY SCAN TRIGGER */
  1142. WL_SCAN((" LEGACY E-SCAN START\n"));
  1143. #if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
  1144. if (!request) {
  1145. err = -EINVAL;
  1146. goto exit;
  1147. }
  1148. if (ndev == bcmcfg_to_prmry_ndev(cfg) && g_first_broadcast_scan == true) {
  1149. #ifdef USE_INITIAL_2G_SCAN
  1150. struct ieee80211_channel tmp_channel_list[CH_MAX_2G_CHANNEL];
  1151. /* allow one 5G channel to add previous connected channel in 5G */
  1152. bool allow_one_5g_channel = TRUE;
  1153. j = 0;
  1154. for (i = 0; i < request->n_channels; i++) {
  1155. int tmp_chan = ieee80211_frequency_to_channel
  1156. (request->channels[i]->center_freq);
  1157. if (tmp_chan > CH_MAX_2G_CHANNEL) {
  1158. if (allow_one_5g_channel)
  1159. allow_one_5g_channel = FALSE;
  1160. else
  1161. continue;
  1162. }
  1163. if (j > CH_MAX_2G_CHANNEL) {
  1164. WL_ERR(("Index %d exceeds max 2.4GHz channels %d"
  1165. " and previous 5G connected channel\n",
  1166. j, CH_MAX_2G_CHANNEL));
  1167. break;
  1168. }
  1169. bcopy(request->channels[i], &tmp_channel_list[j],
  1170. sizeof(struct ieee80211_channel));
  1171. WL_SCAN(("channel of request->channels[%d]=%d\n", i, tmp_chan));
  1172. j++;
  1173. }
  1174. if ((j > 0) && (j <= CH_MAX_2G_CHANNEL)) {
  1175. for (i = 0; i < j; i++)
  1176. bcopy(&tmp_channel_list[i], request->channels[i],
  1177. sizeof(struct ieee80211_channel));
  1178. request->n_channels = j;
  1179. is_first_init_2g_scan = true;
  1180. }
  1181. else
  1182. WL_ERR(("Invalid number of 2.4GHz channels %d\n", j));
  1183. WL_SCAN(("request->n_channels=%d\n", request->n_channels));
  1184. #else /* USE_INITIAL_SHORT_DWELL_TIME */
  1185. is_first_init_2g_scan = true;
  1186. #endif /* USE_INITIAL_2G_SCAN */
  1187. g_first_broadcast_scan = false;
  1188. }
  1189. #endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
  1190. /* if scan request is not empty parse scan request paramters */
  1191. if (request != NULL) {
  1192. n_channels = request->n_channels;
  1193. n_ssids = request->n_ssids;
  1194. if (n_channels % 2)
  1195. /* If n_channels is odd, add a padd of u16 */
  1196. params_size += sizeof(u16) * (n_channels + 1);
  1197. else
  1198. params_size += sizeof(u16) * n_channels;
  1199. /* Allocate space for populating ssids in wl_escan_params_t struct */
  1200. params_size += sizeof(struct wlc_ssid) * n_ssids;
  1201. }
  1202. params = MALLOCZ(cfg->osh, params_size);
  1203. if (params == NULL) {
  1204. err = -ENOMEM;
  1205. goto exit;
  1206. }
  1207. wl_escan_set_sync_id(sync_id, cfg);
  1208. if (cfg->scan_params_v2) {
  1209. eparams_v2 = (wl_escan_params_v2_t *)params;
  1210. scan_params = (u8 *)&eparams_v2->params;
  1211. eparams_v2->version = htod32(ESCAN_REQ_VERSION_V2);
  1212. eparams_v2->action = htod16(action);
  1213. eparams_v2->sync_id = sync_id;
  1214. } else {
  1215. eparams = (wl_escan_params_t *)params;
  1216. scan_params = (u8 *)&eparams->params;
  1217. eparams->version = htod32(ESCAN_REQ_VERSION);
  1218. eparams->action = htod16(action);
  1219. eparams->sync_id = sync_id;
  1220. }
  1221. if (wl_scan_prep(cfg, scan_params, params_size, request) < 0) {
  1222. WL_ERR(("scan_prep failed\n"));
  1223. err = -EINVAL;
  1224. goto exit;
  1225. }
  1226. #if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
  1227. /* Override active_time to reduce scan time if it's first bradcast scan. */
  1228. if (is_first_init_2g_scan) {
  1229. if (eparams_v2) {
  1230. eparams_v2->params.active_time = FIRST_SCAN_ACTIVE_DWELL_TIME_MS;
  1231. } else {
  1232. eparams->params.active_time = FIRST_SCAN_ACTIVE_DWELL_TIME_MS;
  1233. }
  1234. }
  1235. #endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
  1236. wl_escan_set_type(cfg, WL_SCANTYPE_LEGACY);
  1237. if (params_size + sizeof("escan") >= WLC_IOCTL_MEDLEN) {
  1238. WL_ERR(("ioctl buffer length not sufficient\n"));
  1239. MFREE(cfg->osh, params, params_size);
  1240. err = -ENOMEM;
  1241. goto exit;
  1242. }
  1243. bssidx = wl_get_bssidx_by_wdev(cfg, ndev->ieee80211_ptr);
  1244. err = wldev_iovar_setbuf(ndev, "escan", params, params_size,
  1245. cfg->escan_ioctl_buf, WLC_IOCTL_MEDLEN, NULL);
  1246. WL_INFORM_MEM(("LEGACY_SCAN sync ID: %d, bssidx: %d\n", sync_id, bssidx));
  1247. if (unlikely(err)) {
  1248. if (err == BCME_EPERM)
  1249. /* Scan Not permitted at this point of time */
  1250. WL_DBG((" Escan not permitted at this time (%d)\n", err));
  1251. else
  1252. WL_ERR((" Escan set error (%d)\n", err));
  1253. } else {
  1254. DBG_EVENT_LOG((dhd_pub_t *)cfg->pub, WIFI_EVENT_DRIVER_SCAN_REQUESTED);
  1255. }
  1256. MFREE(cfg->osh, params, params_size);
  1257. }
  1258. else if (p2p_is_on(cfg) && p2p_scan(cfg)) {
  1259. /* P2P SCAN TRIGGER */
  1260. s32 _freq = 0;
  1261. n_nodfs = 0;
  1262. if (request && request->n_channels) {
  1263. num_chans = request->n_channels;
  1264. WL_SCAN((" chann number : %d\n", num_chans));
  1265. chan_mem = (u32)(num_chans * sizeof(*default_chan_list));
  1266. default_chan_list = MALLOCZ(cfg->osh, chan_mem);
  1267. if (default_chan_list == NULL) {
  1268. WL_ERR(("channel list allocation failed \n"));
  1269. err = -ENOMEM;
  1270. goto exit;
  1271. }
  1272. if (!wl_get_valid_channels(ndev, chan_buf, sizeof(chan_buf))) {
  1273. #ifdef P2P_SKIP_DFS
  1274. int is_printed = false;
  1275. #endif /* P2P_SKIP_DFS */
  1276. list = (wl_uint32_list_t *) chan_buf;
  1277. n_valid_chan = dtoh32(list->count);
  1278. if (n_valid_chan > WL_NUMCHANNELS) {
  1279. WL_ERR(("wrong n_valid_chan:%d\n", n_valid_chan));
  1280. MFREE(cfg->osh, default_chan_list, chan_mem);
  1281. err = -EINVAL;
  1282. goto exit;
  1283. }
  1284. for (i = 0; i < num_chans; i++)
  1285. {
  1286. #ifdef WL_HOST_BAND_MGMT
  1287. int channel_band = 0;
  1288. #endif /* WL_HOST_BAND_MGMT */
  1289. _freq = request->channels[i]->center_freq;
  1290. channel = ieee80211_frequency_to_channel(_freq);
  1291. #ifdef WL_HOST_BAND_MGMT
  1292. channel_band = (channel > CH_MAX_2G_CHANNEL) ?
  1293. WLC_BAND_5G : WLC_BAND_2G;
  1294. if ((cfg->curr_band != WLC_BAND_AUTO) &&
  1295. (cfg->curr_band != channel_band) &&
  1296. !IS_P2P_SOCIAL_CHANNEL(channel))
  1297. continue;
  1298. #endif /* WL_HOST_BAND_MGMT */
  1299. /* ignore DFS channels */
  1300. if (request->channels[i]->flags &
  1301. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
  1302. (IEEE80211_CHAN_NO_IR
  1303. | IEEE80211_CHAN_RADAR))
  1304. #else
  1305. (IEEE80211_CHAN_RADAR
  1306. | IEEE80211_CHAN_PASSIVE_SCAN))
  1307. #endif // endif
  1308. continue;
  1309. #ifdef P2P_SKIP_DFS
  1310. if (channel >= 52 && channel <= 144) {
  1311. if (is_printed == false) {
  1312. WL_ERR(("SKIP DFS CHANs(52~144)\n"));
  1313. is_printed = true;
  1314. }
  1315. continue;
  1316. }
  1317. #endif /* P2P_SKIP_DFS */
  1318. for (j = 0; j < n_valid_chan; j++) {
  1319. /* allows only supported channel on
  1320. * current reguatory
  1321. */
  1322. if (n_nodfs >= num_chans) {
  1323. break;
  1324. }
  1325. if (channel == (dtoh32(list->element[j]))) {
  1326. default_chan_list[n_nodfs++] =
  1327. channel;
  1328. }
  1329. }
  1330. }
  1331. }
  1332. if (num_chans == SOCIAL_CHAN_CNT && (
  1333. (default_chan_list[0] == SOCIAL_CHAN_1) &&
  1334. (default_chan_list[1] == SOCIAL_CHAN_2) &&
  1335. (default_chan_list[2] == SOCIAL_CHAN_3))) {
  1336. /* SOCIAL CHANNELS 1, 6, 11 */
  1337. search_state = WL_P2P_DISC_ST_SEARCH;
  1338. p2p_scan_purpose = P2P_SCAN_SOCIAL_CHANNEL;
  1339. WL_DBG(("P2P SEARCH PHASE START \n"));
  1340. } else if (((dev = wl_to_p2p_bss_ndev(cfg, P2PAPI_BSSCFG_CONNECTION1)) &&
  1341. (wl_get_mode_by_netdev(cfg, dev) == WL_MODE_AP)) ||
  1342. ((dev = wl_to_p2p_bss_ndev(cfg, P2PAPI_BSSCFG_CONNECTION2)) &&
  1343. (wl_get_mode_by_netdev(cfg, dev) == WL_MODE_AP))) {
  1344. /* If you are already a GO, then do SEARCH only */
  1345. WL_DBG(("Already a GO. Do SEARCH Only"));
  1346. search_state = WL_P2P_DISC_ST_SEARCH;
  1347. num_chans = n_nodfs;
  1348. p2p_scan_purpose = P2P_SCAN_NORMAL;
  1349. } else if (num_chans == 1) {
  1350. p2p_scan_purpose = P2P_SCAN_CONNECT_TRY;
  1351. WL_INFORM_MEM(("Trigger p2p join scan\n"));
  1352. } else if (num_chans == SOCIAL_CHAN_CNT + 1) {
  1353. /* SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan supported by
  1354. * the supplicant
  1355. */
  1356. p2p_scan_purpose = P2P_SCAN_SOCIAL_CHANNEL;
  1357. } else {
  1358. WL_DBG(("P2P SCAN STATE START \n"));
  1359. num_chans = n_nodfs;
  1360. p2p_scan_purpose = P2P_SCAN_NORMAL;
  1361. }
  1362. } else {
  1363. err = -EINVAL;
  1364. goto exit;
  1365. }
  1366. err = wl_cfgp2p_escan(cfg, ndev, ACTIVE_SCAN, num_chans, default_chan_list,
  1367. search_state, action,
  1368. wl_to_p2p_bss_bssidx(cfg, P2PAPI_BSSCFG_DEVICE), NULL,
  1369. p2p_scan_purpose);
  1370. if (!err)
  1371. cfg->p2p->search_state = search_state;
  1372. MFREE(cfg->osh, default_chan_list, chan_mem);
  1373. }
  1374. exit:
  1375. if (unlikely(err)) {
  1376. /* Don't print Error incase of Scan suppress */
  1377. if ((err == BCME_EPERM) && cfg->scan_suppressed)
  1378. WL_DBG(("Escan failed: Scan Suppressed \n"));
  1379. else
  1380. WL_ERR(("scan error (%d)\n", err));
  1381. }
  1382. return err;
  1383. }
  1384. s32
  1385. wl_do_escan(struct bcm_cfg80211 *cfg, struct wiphy *wiphy, struct net_device *ndev,
  1386. struct cfg80211_scan_request *request)
  1387. {
  1388. s32 err = BCME_OK;
  1389. s32 passive_scan;
  1390. s32 passive_scan_time;
  1391. s32 passive_scan_time_org;
  1392. wl_scan_results_t *results;
  1393. WL_SCAN(("Enter \n"));
  1394. results = wl_escan_get_buf(cfg, FALSE);
  1395. results->version = 0;
  1396. results->count = 0;
  1397. results->buflen = WL_SCAN_RESULTS_FIXED_SIZE;
  1398. cfg->escan_info.ndev = ndev;
  1399. cfg->escan_info.wiphy = wiphy;
  1400. cfg->escan_info.escan_state = WL_ESCAN_STATE_SCANING;
  1401. passive_scan = cfg->active_scan ? 0 : 1;
  1402. err = wldev_ioctl_set(ndev, WLC_SET_PASSIVE_SCAN,
  1403. &passive_scan, sizeof(passive_scan));
  1404. if (unlikely(err)) {
  1405. WL_ERR(("error (%d)\n", err));
  1406. goto exit;
  1407. }
  1408. if (passive_channel_skip) {
  1409. err = wldev_ioctl_get(ndev, WLC_GET_SCAN_PASSIVE_TIME,
  1410. &passive_scan_time_org, sizeof(passive_scan_time_org));
  1411. if (unlikely(err)) {
  1412. WL_ERR(("== error (%d)\n", err));
  1413. goto exit;
  1414. }
  1415. WL_SCAN(("PASSIVE SCAN time : %d \n", passive_scan_time_org));
  1416. passive_scan_time = 0;
  1417. err = wldev_ioctl_set(ndev, WLC_SET_SCAN_PASSIVE_TIME,
  1418. &passive_scan_time, sizeof(passive_scan_time));
  1419. if (unlikely(err)) {
  1420. WL_ERR(("== error (%d)\n", err));
  1421. goto exit;
  1422. }
  1423. WL_SCAN(("PASSIVE SCAN SKIPED!! (passive_channel_skip:%d) \n",
  1424. passive_channel_skip));
  1425. }
  1426. err = wl_run_escan(cfg, ndev, request, WL_SCAN_ACTION_START);
  1427. if (passive_channel_skip) {
  1428. err = wldev_ioctl_set(ndev, WLC_SET_SCAN_PASSIVE_TIME,
  1429. &passive_scan_time_org, sizeof(passive_scan_time_org));
  1430. if (unlikely(err)) {
  1431. WL_ERR(("== error (%d)\n", err));
  1432. goto exit;
  1433. }
  1434. WL_SCAN(("PASSIVE SCAN RECOVERED!! (passive_scan_time_org:%d) \n",
  1435. passive_scan_time_org));
  1436. }
  1437. exit:
  1438. return err;
  1439. }
  1440. static s32
  1441. wl_get_scan_timeout_val(struct bcm_cfg80211 *cfg)
  1442. {
  1443. u32 scan_timer_interval_ms = WL_SCAN_TIMER_INTERVAL_MS;
  1444. #ifdef WES_SUPPORT
  1445. #ifdef CUSTOMER_SCAN_TIMEOUT_SETTING
  1446. if ((cfg->custom_scan_channel_time > DHD_SCAN_ASSOC_ACTIVE_TIME) |
  1447. (cfg->custom_scan_unassoc_time > DHD_SCAN_UNASSOC_ACTIVE_TIME) |
  1448. (cfg->custom_scan_passive_time > DHD_SCAN_PASSIVE_TIME) |
  1449. (cfg->custom_scan_home_time > DHD_SCAN_HOME_TIME) |
  1450. (cfg->custom_scan_home_away_time > DHD_SCAN_HOME_AWAY_TIME)) {
  1451. scan_timer_interval_ms = CUSTOMER_WL_SCAN_TIMER_INTERVAL_MS;
  1452. }
  1453. #endif /* CUSTOMER_SCAN_TIMEOUT_SETTING */
  1454. #endif /* WES_SUPPORT */
  1455. /* If NAN is enabled adding +10 sec to the existing timeout value */
  1456. #ifdef WL_NAN
  1457. if (cfg->nan_enable) {
  1458. scan_timer_interval_ms += WL_SCAN_TIMER_INTERVAL_MS_NAN;
  1459. }
  1460. #endif /* WL_NAN */
  1461. WL_MEM(("scan_timer_interval_ms %d\n", scan_timer_interval_ms));
  1462. return scan_timer_interval_ms;
  1463. }
  1464. #define SCAN_EBUSY_RETRY_LIMIT 20
  1465. static s32
  1466. wl_cfgscan_handle_scanbusy(struct bcm_cfg80211 *cfg, struct net_device *ndev, s32 err)
  1467. {
  1468. s32 scanbusy_err = 0;
  1469. static u32 busy_count = 0;
  1470. if (!err) {
  1471. busy_count = 0;
  1472. return scanbusy_err;
  1473. }
  1474. if (err == BCME_BUSY || err == BCME_NOTREADY) {
  1475. WL_ERR(("Scan err = (%d), busy?%d", err, -EBUSY));
  1476. scanbusy_err = -EBUSY;
  1477. } else if ((err == BCME_EPERM) && cfg->scan_suppressed) {
  1478. WL_ERR(("Scan not permitted due to scan suppress\n"));
  1479. scanbusy_err = -EPERM;
  1480. } else {
  1481. /* For all other fw errors, use a generic error code as return
  1482. * value to cfg80211 stack
  1483. */
  1484. scanbusy_err = -EAGAIN;
  1485. }
  1486. if (scanbusy_err == -EBUSY) {
  1487. /* Flush FW preserve buffer logs for checking failure */
  1488. if (busy_count++ > (SCAN_EBUSY_RETRY_LIMIT/5)) {
  1489. wl_flush_fw_log_buffer(ndev, FW_LOGSET_MASK_ALL);
  1490. }
  1491. if (busy_count > SCAN_EBUSY_RETRY_LIMIT) {
  1492. struct ether_addr bssid;
  1493. s32 ret = 0;
  1494. dhd_pub_t *dhdp = (dhd_pub_t *)(cfg->pub);
  1495. if (dhd_query_bus_erros(dhdp)) {
  1496. return BCME_NOTREADY;
  1497. }
  1498. dhdp->scan_busy_occurred = TRUE;
  1499. busy_count = 0;
  1500. WL_ERR(("Unusual continuous EBUSY error, %d %d %d %d %d %d %d %d %d\n",
  1501. wl_get_drv_status(cfg, SCANNING, ndev),
  1502. wl_get_drv_status(cfg, SCAN_ABORTING, ndev),
  1503. wl_get_drv_status(cfg, CONNECTING, ndev),
  1504. wl_get_drv_status(cfg, CONNECTED, ndev),
  1505. wl_get_drv_status(cfg, DISCONNECTING, ndev),
  1506. wl_get_drv_status(cfg, AP_CREATING, ndev),
  1507. wl_get_drv_status(cfg, AP_CREATED, ndev),
  1508. wl_get_drv_status(cfg, SENDING_ACT_FRM, ndev),
  1509. wl_get_drv_status(cfg, SENDING_ACT_FRM, ndev)));
  1510. #if defined(DHD_DEBUG) && defined(DHD_FW_COREDUMP)
  1511. if (dhdp->memdump_enabled) {
  1512. dhdp->memdump_type = DUMP_TYPE_SCAN_BUSY;
  1513. dhd_bus_mem_dump(dhdp);
  1514. }
  1515. #endif /* DHD_DEBUG && DHD_FW_COREDUMP */
  1516. bzero(&bssid, sizeof(bssid));
  1517. if ((ret = wldev_ioctl_get(ndev, WLC_GET_BSSID,
  1518. &bssid, ETHER_ADDR_LEN)) == 0) {
  1519. WL_ERR(("FW is connected with " MACDBG "/n",
  1520. MAC2STRDBG(bssid.octet)));
  1521. } else {
  1522. WL_ERR(("GET BSSID failed with %d\n", ret));
  1523. }
  1524. wl_cfg80211_scan_abort(cfg);
  1525. } else {
  1526. /* Hold the context for 400msec, so that 10 subsequent scans
  1527. * can give a buffer of 4sec which is enough to
  1528. * cover any on-going scan in the firmware
  1529. */
  1530. WL_DBG(("Enforcing delay for EBUSY case \n"));
  1531. msleep(400);
  1532. }
  1533. } else {
  1534. busy_count = 0;
  1535. }
  1536. return scanbusy_err;
  1537. }
  1538. s32
  1539. __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
  1540. struct cfg80211_scan_request *request,
  1541. struct cfg80211_ssid *this_ssid)
  1542. {
  1543. struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
  1544. struct cfg80211_ssid *ssids;
  1545. struct ether_addr primary_mac;
  1546. bool p2p_ssid;
  1547. #ifdef WL11U
  1548. bcm_tlv_t *interworking_ie;
  1549. u8 iw_ie[IW_IES_MAX_BUF_LEN];
  1550. u32 iw_ie_len = 0;
  1551. #endif // endif
  1552. s32 err = 0;
  1553. s32 bssidx = -1;
  1554. s32 i;
  1555. bool escan_req_failed = false;
  1556. s32 scanbusy_err = 0;
  1557. unsigned long flags;
  1558. #ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
  1559. struct net_device *remain_on_channel_ndev = NULL;
  1560. #endif // endif
  1561. /*
  1562. * Hostapd triggers scan before starting automatic channel selection
  1563. * to collect channel characteristics. However firmware scan engine
  1564. * doesn't support any channel characteristics collection along with
  1565. * scan. Hence return scan success.
  1566. */
  1567. #ifndef IGUANA_LEGACY_CHIPS
  1568. if (request && (scan_req_iftype(request) == NL80211_IFTYPE_AP)) {
  1569. WL_DBG(("Scan Command on SoftAP Interface. Ignoring...\n"));
  1570. return 0;
  1571. }
  1572. #endif // endif
  1573. ndev = ndev_to_wlc_ndev(ndev, cfg);
  1574. if (WL_DRV_STATUS_SENDING_AF_FRM_EXT(cfg)) {
  1575. WL_ERR(("Sending Action Frames. Try it again.\n"));
  1576. return -EAGAIN;
  1577. }
  1578. WL_DBG(("Enter wiphy (%p)\n", wiphy));
  1579. if (wl_get_drv_status_all(cfg, SCANNING)) {
  1580. if (cfg->scan_request == NULL) {
  1581. wl_clr_drv_status_all(cfg, SCANNING);
  1582. WL_DBG(("<<<<<<<<<<<Force Clear Scanning Status>>>>>>>>>>>\n"));
  1583. } else {
  1584. WL_ERR(("Scanning already\n"));
  1585. return -EAGAIN;
  1586. }
  1587. }
  1588. if (wl_get_drv_status(cfg, SCAN_ABORTING, ndev)) {
  1589. WL_ERR(("Scanning being aborted\n"));
  1590. return -EAGAIN;
  1591. }
  1592. if (request && request->n_ssids > WL_SCAN_PARAMS_SSID_MAX) {
  1593. WL_ERR(("request null or n_ssids > WL_SCAN_PARAMS_SSID_MAX\n"));
  1594. return -EOPNOTSUPP;
  1595. }
  1596. #ifdef WL_BCNRECV
  1597. /* check fakeapscan in progress then abort */
  1598. wl_android_bcnrecv_stop(ndev, WL_BCNRECV_SCANBUSY);
  1599. #endif /* WL_BCNRECV */
  1600. #ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
  1601. mutex_lock(&cfg->scan_sync);
  1602. remain_on_channel_ndev = wl_cfg80211_get_remain_on_channel_ndev(cfg);
  1603. if (remain_on_channel_ndev) {
  1604. WL_DBG(("Remain_on_channel bit is set, somehow it didn't get cleared\n"));
  1605. wl_notify_escan_complete(cfg, remain_on_channel_ndev, true, true);
  1606. }
  1607. mutex_unlock(&cfg->scan_sync);
  1608. #endif /* WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST */
  1609. #ifdef P2P_LISTEN_OFFLOADING
  1610. wl_cfg80211_cancel_p2plo(cfg);
  1611. #endif /* P2P_LISTEN_OFFLOADING */
  1612. if (request) { /* scan bss */
  1613. ssids = request->ssids;
  1614. p2p_ssid = false;
  1615. for (i = 0; i < request->n_ssids; i++) {
  1616. if (ssids[i].ssid_len &&
  1617. IS_P2P_SSID(ssids[i].ssid, ssids[i].ssid_len)) {
  1618. /* P2P Scan */
  1619. #ifdef WL_BLOCK_P2P_SCAN_ON_STA
  1620. if (!(IS_P2P_IFACE(request->wdev))) {
  1621. /* P2P scan on non-p2p iface. Fail scan */
  1622. WL_ERR(("p2p_search on non p2p iface\n"));
  1623. goto scan_out;
  1624. }
  1625. #endif /* WL_BLOCK_P2P_SCAN_ON_STA */
  1626. p2p_ssid = true;
  1627. break;
  1628. }
  1629. }
  1630. if (p2p_ssid) {
  1631. if (cfg->p2p_supported) {
  1632. /* p2p scan trigger */
  1633. if (p2p_on(cfg) == false) {
  1634. /* p2p on at the first time */
  1635. p2p_on(cfg) = true;
  1636. wl_cfgp2p_set_firm_p2p(cfg);
  1637. get_primary_mac(cfg, &primary_mac);
  1638. wl_cfgp2p_generate_bss_mac(cfg, &primary_mac);
  1639. #if defined(P2P_IE_MISSING_FIX)
  1640. cfg->p2p_prb_noti = false;
  1641. #endif // endif
  1642. }
  1643. wl_clr_p2p_status(cfg, GO_NEG_PHASE);
  1644. WL_DBG(("P2P: GO_NEG_PHASE status cleared \n"));
  1645. p2p_scan(cfg) = true;
  1646. }
  1647. } else {
  1648. /* legacy scan trigger
  1649. * So, we have to disable p2p discovery if p2p discovery is on
  1650. */
  1651. if (cfg->p2p_supported) {
  1652. p2p_scan(cfg) = false;
  1653. /* If Netdevice is not equals to primary and p2p is on
  1654. * , we will do p2p scan using P2PAPI_BSSCFG_DEVICE.
  1655. */
  1656. if (p2p_scan(cfg) == false) {
  1657. if (wl_get_p2p_status(cfg, DISCOVERY_ON)) {
  1658. err = wl_cfgp2p_discover_enable_search(cfg,
  1659. false);
  1660. if (unlikely(err)) {
  1661. goto scan_out;
  1662. }
  1663. }
  1664. }
  1665. }
  1666. if (!cfg->p2p_supported || !p2p_scan(cfg)) {
  1667. if ((bssidx = wl_get_bssidx_by_wdev(cfg,
  1668. ndev->ieee80211_ptr)) < 0) {
  1669. WL_ERR(("Find p2p index from ndev(%p) failed\n",
  1670. ndev));
  1671. err = BCME_ERROR;
  1672. goto scan_out;
  1673. }
  1674. #ifdef WL11U
  1675. wl_get_iwdata_by_netdev(cfg, ndev, iw_ie, &iw_ie_len);
  1676. if (request && (interworking_ie = wl_cfg80211_find_interworking_ie(
  1677. request->ie, request->ie_len)) != NULL) {
  1678. if ((err = wl_cfg80211_add_iw_ie(cfg, ndev, bssidx,
  1679. VNDR_IE_CUSTOM_FLAG, interworking_ie->id,
  1680. interworking_ie->data,
  1681. interworking_ie->len)) != BCME_OK) {
  1682. WL_ERR(("Failed to add interworking IE"));
  1683. }
  1684. } else if (iw_ie_len != 0) {
  1685. /* we have to clear IW IE and disable gratuitous APR */
  1686. wl_cfg80211_clear_iw_ie(cfg, ndev, bssidx);
  1687. err = wldev_iovar_setint_bsscfg(ndev, "grat_arp",
  1688. 0, bssidx);
  1689. /* we don't care about error here
  1690. * because the only failure case is unsupported,
  1691. * which is fine
  1692. */
  1693. if (unlikely(err)) {
  1694. WL_ERR(("Set grat_arp failed:(%d) Ignore!\n", err));
  1695. }
  1696. wl_clear_iwdata_by_netdev(cfg, ndev);
  1697. cfg->wl11u = FALSE;
  1698. }
  1699. #endif /* WL11U */
  1700. if (request) {
  1701. err = wl_cfg80211_set_mgmt_vndr_ies(cfg,
  1702. ndev_to_cfgdev(ndev), bssidx, VNDR_IE_PRBREQ_FLAG,
  1703. request->ie, request->ie_len);
  1704. }
  1705. if (unlikely(err)) {
  1706. goto scan_out;
  1707. }
  1708. }
  1709. }
  1710. } else { /* scan in ibss */
  1711. ssids = this_ssid;
  1712. }
  1713. if (request && cfg->p2p_supported) {
  1714. WL_TRACE_HW4(("START SCAN\n"));
  1715. #if defined(OEM_ANDROID)
  1716. DHD_OS_SCAN_WAKE_LOCK_TIMEOUT((dhd_pub_t *)(cfg->pub),
  1717. SCAN_WAKE_LOCK_TIMEOUT);
  1718. DHD_DISABLE_RUNTIME_PM((dhd_pub_t *)(cfg->pub));
  1719. #endif // endif
  1720. }
  1721. if (cfg->p2p_supported) {
  1722. if (request && p2p_on(cfg) && p2p_scan(cfg)) {
  1723. /* find my listen channel */
  1724. cfg->afx_hdl->my_listen_chan =
  1725. wl_find_listen_channel(cfg, request->ie,
  1726. request->ie_len);
  1727. err = wl_cfgp2p_enable_discovery(cfg, ndev,
  1728. request->ie, request->ie_len);
  1729. if (unlikely(err)) {
  1730. goto scan_out;
  1731. }
  1732. }
  1733. }
  1734. mutex_lock(&cfg->scan_sync);
  1735. err = wl_do_escan(cfg, wiphy, ndev, request);
  1736. if (likely(!err)) {
  1737. goto scan_success;
  1738. } else {
  1739. escan_req_failed = true;
  1740. goto scan_out;
  1741. }
  1742. scan_success:
  1743. wl_cfgscan_handle_scanbusy(cfg, ndev, BCME_OK);
  1744. cfg->scan_request = request;
  1745. wl_set_drv_status(cfg, SCANNING, ndev);
  1746. /* Arm the timer */
  1747. mod_timer(&cfg->scan_timeout,
  1748. jiffies + msecs_to_jiffies(wl_get_scan_timeout_val(cfg)));
  1749. mutex_unlock(&cfg->scan_sync);
  1750. return 0;
  1751. scan_out:
  1752. if (escan_req_failed) {
  1753. WL_CFG_DRV_LOCK(&cfg->cfgdrv_lock, flags);
  1754. cfg->scan_request = NULL;
  1755. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  1756. mutex_unlock(&cfg->scan_sync);
  1757. /* Handling for scan busy errors */
  1758. scanbusy_err = wl_cfgscan_handle_scanbusy(cfg, ndev, err);
  1759. if (scanbusy_err == BCME_NOTREADY) {
  1760. /* In case of bus failures avoid ioctl calls */
  1761. #if defined(OEM_ANDROID)
  1762. DHD_OS_SCAN_WAKE_UNLOCK((dhd_pub_t *)(cfg->pub));
  1763. #endif // endif
  1764. return -ENODEV;
  1765. }
  1766. err = scanbusy_err;
  1767. }
  1768. #if defined(OEM_ANDROID)
  1769. DHD_OS_SCAN_WAKE_UNLOCK((dhd_pub_t *)(cfg->pub));
  1770. #endif // endif
  1771. return err;
  1772. }
  1773. #if defined(WL_CFG80211_P2P_DEV_IF)
  1774. s32
  1775. wl_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
  1776. #else
  1777. s32
  1778. wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
  1779. struct cfg80211_scan_request *request)
  1780. #endif /* WL_CFG80211_P2P_DEV_IF */
  1781. {
  1782. s32 err = 0;
  1783. struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
  1784. #if defined(WL_CFG80211_P2P_DEV_IF)
  1785. struct net_device *ndev = wdev_to_wlc_ndev(request->wdev, cfg);
  1786. #endif /* WL_CFG80211_P2P_DEV_IF */
  1787. WL_DBG(("Enter\n"));
  1788. RETURN_EIO_IF_NOT_UP(cfg);
  1789. #ifdef DHD_IFDEBUG
  1790. #ifdef WL_CFG80211_P2P_DEV_IF
  1791. PRINT_WDEV_INFO(request->wdev);
  1792. #else
  1793. PRINT_WDEV_INFO(ndev);
  1794. #endif /* WL_CFG80211_P2P_DEV_IF */
  1795. #endif /* DHD_IFDEBUG */
  1796. #ifndef IGUANA_LEGACY_CHIPS
  1797. if (ndev == bcmcfg_to_prmry_ndev(cfg)) {
  1798. if (wl_cfg_multip2p_operational(cfg)) {
  1799. WL_ERR(("wlan0 scan failed, p2p devices are operational"));
  1800. return -ENODEV;
  1801. }
  1802. }
  1803. #endif // endif
  1804. err = __wl_cfg80211_scan(wiphy, ndev, request, NULL);
  1805. if (unlikely(err)) {
  1806. WL_ERR(("scan error (%d)\n", err));
  1807. }
  1808. #ifdef WL_DRV_AVOID_SCANCACHE
  1809. /* Reset roam cache after successful scan request */
  1810. #ifdef ROAM_CHANNEL_CACHE
  1811. if (!err) {
  1812. reset_roam_cache(cfg);
  1813. }
  1814. #endif /* ROAM_CHANNEL_CACHE */
  1815. #endif /* WL_DRV_AVOID_SCANCACHE */
  1816. return err;
  1817. }
  1818. /* Note: This API should be invoked with scan_sync mutex
  1819. * held so that scan_request data structures doesn't
  1820. * get modified in between.
  1821. */
  1822. struct wireless_dev *
  1823. wl_get_scan_wdev(struct bcm_cfg80211 *cfg)
  1824. {
  1825. struct wireless_dev *wdev = NULL;
  1826. if (!cfg) {
  1827. WL_ERR(("cfg ptr null\n"));
  1828. return NULL;
  1829. }
  1830. if (!cfg->scan_request && !cfg->sched_scan_req) {
  1831. /* No scans in progress */
  1832. WL_MEM(("no scan in progress \n"));
  1833. return NULL;
  1834. }
  1835. if (cfg->scan_request) {
  1836. wdev = GET_SCAN_WDEV(cfg->scan_request);
  1837. #ifdef WL_SCHED_SCAN
  1838. } else if (cfg->sched_scan_req) {
  1839. wdev = GET_SCHED_SCAN_WDEV(cfg->sched_scan_req);
  1840. #endif /* WL_SCHED_SCAN */
  1841. } else {
  1842. WL_MEM(("no scan in progress \n"));
  1843. }
  1844. return wdev;
  1845. }
  1846. void wl_cfg80211_cancel_scan(struct bcm_cfg80211 *cfg)
  1847. {
  1848. struct wireless_dev *wdev = NULL;
  1849. struct net_device *ndev = NULL;
  1850. mutex_lock(&cfg->scan_sync);
  1851. if (!cfg->scan_request && !cfg->sched_scan_req) {
  1852. /* No scans in progress */
  1853. WL_INFORM_MEM(("No scan in progress\n"));
  1854. goto exit;
  1855. }
  1856. wdev = wl_get_scan_wdev(cfg);
  1857. if (!wdev) {
  1858. WL_ERR(("No wdev present\n"));
  1859. goto exit;
  1860. }
  1861. ndev = wdev_to_wlc_ndev(wdev, cfg);
  1862. wl_notify_escan_complete(cfg, ndev, true, true);
  1863. WL_INFORM_MEM(("Scan aborted! \n"));
  1864. exit:
  1865. mutex_unlock(&cfg->scan_sync);
  1866. }
  1867. void wl_cfg80211_scan_abort(struct bcm_cfg80211 *cfg)
  1868. {
  1869. void *params = NULL;
  1870. s32 params_size = 0;
  1871. s32 err = BCME_OK;
  1872. struct net_device *dev = bcmcfg_to_prmry_ndev(cfg);
  1873. u32 channel, channel_num;
  1874. if (!in_atomic()) {
  1875. /* Abort scan params only need space for 1 channel and 0 ssids */
  1876. if (cfg->scan_params_v2) {
  1877. params_size = WL_SCAN_PARAMS_V2_FIXED_SIZE + 1 * sizeof(uint16);
  1878. } else {
  1879. params_size = WL_SCAN_PARAMS_FIXED_SIZE + 1 * sizeof(uint16);
  1880. }
  1881. params = MALLOCZ(cfg->osh, params_size);
  1882. if (params == NULL) {
  1883. WL_ERR(("mem alloc failed (%d bytes)\n", params_size));
  1884. return;
  1885. }
  1886. /* Use magic value of channel=-1 to abort scan */
  1887. channel = htodchanspec(-1);
  1888. channel_num = htod32((0 << WL_SCAN_PARAMS_NSSID_SHIFT) |
  1889. (1 & WL_SCAN_PARAMS_COUNT_MASK));
  1890. if (cfg->scan_params_v2) {
  1891. wl_scan_params_v2_t *params_v2 = (wl_scan_params_v2_t *)params;
  1892. params_v2->channel_list[0] = channel;
  1893. params_v2->channel_num = channel_num;
  1894. } else {
  1895. wl_scan_params_t *params_v1 = (wl_scan_params_t *)params;
  1896. params_v1->channel_list[0] = channel;
  1897. params_v1->channel_num = channel_num;
  1898. }
  1899. /* Do a scan abort to stop the driver's scan engine */
  1900. err = wldev_ioctl_set(dev, WLC_SCAN, params, params_size);
  1901. if (err < 0) {
  1902. /* scan abort can fail if there is no outstanding scan */
  1903. WL_DBG(("scan abort failed. ret:%d\n", err));
  1904. }
  1905. MFREE(cfg->osh, params, params_size);
  1906. }
  1907. #ifdef WLTDLS
  1908. if (cfg->tdls_mgmt_frame) {
  1909. MFREE(cfg->osh, cfg->tdls_mgmt_frame, cfg->tdls_mgmt_frame_len);
  1910. cfg->tdls_mgmt_frame = NULL;
  1911. cfg->tdls_mgmt_frame_len = 0;
  1912. }
  1913. #endif /* WLTDLS */
  1914. }
  1915. s32 wl_notify_escan_complete(struct bcm_cfg80211 *cfg,
  1916. struct net_device *ndev,
  1917. bool aborted, bool fw_abort)
  1918. {
  1919. s32 err = BCME_OK;
  1920. unsigned long flags;
  1921. struct net_device *dev;
  1922. dhd_pub_t *dhdp = (dhd_pub_t *)(cfg->pub);
  1923. WL_DBG(("Enter \n"));
  1924. BCM_REFERENCE(dhdp);
  1925. if (!ndev) {
  1926. WL_ERR(("ndev is null\n"));
  1927. err = BCME_ERROR;
  1928. goto out;
  1929. }
  1930. if (cfg->escan_info.ndev != ndev) {
  1931. WL_ERR(("Outstanding scan req ndev not matching (%p:%p)\n",
  1932. cfg->escan_info.ndev, ndev));
  1933. err = BCME_ERROR;
  1934. goto out;
  1935. }
  1936. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && \
  1937. defined(SUPPORT_RANDOM_MAC_SCAN)
  1938. /* Disable scanmac if enabled */
  1939. if (cfg->scanmac_enabled) {
  1940. wl_cfg80211_scan_mac_disable(ndev);
  1941. }
  1942. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) && defined(SUPPORT_RANDOM_MAC_SCAN) */
  1943. if (cfg->scan_request) {
  1944. dev = bcmcfg_to_prmry_ndev(cfg);
  1945. #if defined(WL_ENABLE_P2P_IF)
  1946. if (cfg->scan_request->dev != cfg->p2p_net)
  1947. dev = cfg->scan_request->dev;
  1948. #elif defined(WL_CFG80211_P2P_DEV_IF)
  1949. if (cfg->scan_request->wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
  1950. dev = cfg->scan_request->wdev->netdev;
  1951. #endif /* WL_ENABLE_P2P_IF */
  1952. }
  1953. else {
  1954. WL_DBG(("cfg->scan_request is NULL. Internal scan scenario."
  1955. "doing scan_abort for ndev %p primary %p",
  1956. ndev, bcmcfg_to_prmry_ndev(cfg)));
  1957. dev = ndev;
  1958. }
  1959. if (fw_abort && !in_atomic())
  1960. wl_cfg80211_scan_abort(cfg);
  1961. if (timer_pending(&cfg->scan_timeout))
  1962. del_timer_sync(&cfg->scan_timeout);
  1963. cfg->scan_enq_time = 0;
  1964. #if defined(ESCAN_RESULT_PATCH)
  1965. if (likely(cfg->scan_request)) {
  1966. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  1967. if (aborted && p2p_scan(cfg) &&
  1968. (cfg->scan_request->flags & NL80211_SCAN_FLAG_FLUSH)) {
  1969. WL_ERR(("scan list is changed"));
  1970. cfg->bss_list = wl_escan_get_buf(cfg, !aborted);
  1971. } else
  1972. #endif // endif
  1973. cfg->bss_list = wl_escan_get_buf(cfg, aborted);
  1974. wl_inform_bss(cfg);
  1975. }
  1976. #endif /* ESCAN_RESULT_PATCH */
  1977. WL_CFG_DRV_LOCK(&cfg->cfgdrv_lock, flags);
  1978. #ifdef WL_SCHED_SCAN
  1979. if (cfg->sched_scan_req && !cfg->scan_request) {
  1980. if (!aborted) {
  1981. WL_INFORM_MEM(("[%s] Report sched scan done.\n", dev->name));
  1982. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
  1983. cfg80211_sched_scan_results(cfg->sched_scan_req->wiphy,
  1984. cfg->sched_scan_req->reqid);
  1985. #else
  1986. cfg80211_sched_scan_results(cfg->sched_scan_req->wiphy);
  1987. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) */
  1988. }
  1989. DBG_EVENT_LOG(dhdp, WIFI_EVENT_DRIVER_PNO_SCAN_COMPLETE);
  1990. cfg->sched_scan_running = FALSE;
  1991. cfg->sched_scan_req = NULL;
  1992. }
  1993. #endif /* WL_SCHED_SCAN */
  1994. if (likely(cfg->scan_request)) {
  1995. WL_INFORM_MEM(("[%s] Report scan done.\n", dev->name));
  1996. /* scan_sync mutex is already held */
  1997. _wl_notify_scan_done(cfg, aborted);
  1998. cfg->scan_request = NULL;
  1999. }
  2000. if (p2p_is_on(cfg))
  2001. wl_clr_p2p_status(cfg, SCANNING);
  2002. wl_clr_drv_status(cfg, SCANNING, dev);
  2003. #if defined(OEM_ANDROID)
  2004. DHD_OS_SCAN_WAKE_UNLOCK((dhd_pub_t *)(cfg->pub));
  2005. DHD_ENABLE_RUNTIME_PM((dhd_pub_t *)(cfg->pub));
  2006. #endif // endif
  2007. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  2008. out:
  2009. return err;
  2010. }
  2011. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0))
  2012. void
  2013. wl_cfg80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
  2014. {
  2015. struct bcm_cfg80211 *cfg;
  2016. WL_DBG(("Enter wl_cfg80211_abort_scan\n"));
  2017. cfg = wiphy_priv(wdev->wiphy);
  2018. /* Check if any scan in progress only then abort */
  2019. if (wl_get_drv_status_all(cfg, SCANNING)) {
  2020. wl_cfg80211_scan_abort(cfg);
  2021. /* Only scan abort is issued here. As per the expectation of abort_scan
  2022. * the status of abort is needed to be communicated using cfg80211_scan_done call.
  2023. * Here we just issue abort request and let the scan complete path to indicate
  2024. * abort to cfg80211 layer.
  2025. */
  2026. WL_DBG(("wl_cfg80211_abort_scan: Scan abort issued to FW\n"));
  2027. }
  2028. }
  2029. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)) */
  2030. int wl_cfg80211_scan_stop(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev)
  2031. {
  2032. int ret = 0;
  2033. WL_TRACE(("Enter\n"));
  2034. if (!cfg || !cfgdev) {
  2035. return -EINVAL;
  2036. }
  2037. /* cancel scan and notify scan status */
  2038. wl_cfg80211_cancel_scan(cfg);
  2039. return ret;
  2040. }
  2041. /* This API is just meant as a wrapper for cfg80211_scan_done
  2042. * API. This doesn't do state mgmt. For cancelling scan,
  2043. * please use wl_cfg80211_cancel_scan API.
  2044. */
  2045. static void
  2046. _wl_notify_scan_done(struct bcm_cfg80211 *cfg, bool aborted)
  2047. {
  2048. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
  2049. struct cfg80211_scan_info info;
  2050. #endif // endif
  2051. if (!cfg->scan_request) {
  2052. return;
  2053. }
  2054. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
  2055. memset_s(&info, sizeof(struct cfg80211_scan_info), 0, sizeof(struct cfg80211_scan_info));
  2056. info.aborted = aborted;
  2057. cfg80211_scan_done(cfg->scan_request, &info);
  2058. #else
  2059. cfg80211_scan_done(cfg->scan_request, aborted);
  2060. #endif // endif
  2061. cfg->scan_request = NULL;
  2062. }
  2063. #ifdef WL_DRV_AVOID_SCANCACHE
  2064. static u32 wl_p2p_find_peer_channel(struct bcm_cfg80211 *cfg, s32 status, wl_bss_info_t *bi,
  2065. u32 bi_length)
  2066. {
  2067. u32 ret;
  2068. u8 *p2p_dev_addr = NULL;
  2069. ret = wl_get_drv_status_all(cfg, FINDING_COMMON_CHANNEL);
  2070. if (!ret) {
  2071. return ret;
  2072. }
  2073. if (status == WLC_E_STATUS_PARTIAL) {
  2074. p2p_dev_addr = wl_cfgp2p_retreive_p2p_dev_addr(bi, bi_length);
  2075. if (p2p_dev_addr && !memcmp(p2p_dev_addr,
  2076. cfg->afx_hdl->tx_dst_addr.octet, ETHER_ADDR_LEN)) {
  2077. s32 channel = wf_chspec_ctlchan(
  2078. wl_chspec_driver_to_host(bi->chanspec));
  2079. if ((channel > MAXCHANNEL) || (channel <= 0)) {
  2080. channel = WL_INVALID;
  2081. } else {
  2082. WL_ERR(("ACTION FRAME SCAN : Peer " MACDBG " found,"
  2083. " channel : %d\n",
  2084. MAC2STRDBG(cfg->afx_hdl->tx_dst_addr.octet),
  2085. channel));
  2086. }
  2087. wl_clr_p2p_status(cfg, SCANNING);
  2088. cfg->afx_hdl->peer_chan = channel;
  2089. complete(&cfg->act_frm_scan);
  2090. }
  2091. } else {
  2092. WL_INFORM_MEM(("ACTION FRAME SCAN DONE\n"));
  2093. wl_clr_p2p_status(cfg, SCANNING);
  2094. wl_clr_drv_status(cfg, SCANNING, cfg->afx_hdl->dev);
  2095. if (cfg->afx_hdl->peer_chan == WL_INVALID)
  2096. complete(&cfg->act_frm_scan);
  2097. }
  2098. return ret;
  2099. }
  2100. static s32 wl_escan_without_scan_cache(struct bcm_cfg80211 *cfg, wl_escan_result_t *escan_result,
  2101. struct net_device *ndev, const wl_event_msg_t *e, s32 status)
  2102. {
  2103. s32 err = BCME_OK;
  2104. wl_bss_info_t *bi;
  2105. u32 bi_length;
  2106. bool aborted = false;
  2107. bool fw_abort = false;
  2108. bool notify_escan_complete = false;
  2109. if (wl_escan_check_sync_id(status, escan_result->sync_id,
  2110. cfg->escan_info.cur_sync_id) < 0) {
  2111. goto exit;
  2112. }
  2113. wl_escan_print_sync_id(status, escan_result->sync_id,
  2114. cfg->escan_info.cur_sync_id);
  2115. if (!(status == WLC_E_STATUS_TIMEOUT) || !(status == WLC_E_STATUS_PARTIAL)) {
  2116. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  2117. }
  2118. if ((likely(cfg->scan_request)) || (cfg->sched_scan_running)) {
  2119. notify_escan_complete = true;
  2120. }
  2121. if (status == WLC_E_STATUS_PARTIAL) {
  2122. WL_DBG(("WLC_E_STATUS_PARTIAL \n"));
  2123. DBG_EVENT_LOG((dhd_pub_t *)cfg->pub, WIFI_EVENT_DRIVER_SCAN_RESULT_FOUND);
  2124. if ((!escan_result) || (dtoh16(escan_result->bss_count) != 1)) {
  2125. WL_ERR(("Invalid escan result (NULL pointer) or invalid bss_count\n"));
  2126. goto exit;
  2127. }
  2128. bi = escan_result->bss_info;
  2129. bi_length = dtoh32(bi->length);
  2130. if ((!bi) ||
  2131. (bi_length != (dtoh32(escan_result->buflen) - WL_ESCAN_RESULTS_FIXED_SIZE))) {
  2132. WL_ERR(("Invalid escan bss info (NULL pointer)"
  2133. "or invalid bss_info length\n"));
  2134. goto exit;
  2135. }
  2136. if (!(bcmcfg_to_wiphy(cfg)->interface_modes & BIT(NL80211_IFTYPE_ADHOC))) {
  2137. if (dtoh16(bi->capability) & DOT11_CAP_IBSS) {
  2138. WL_DBG(("Ignoring IBSS result\n"));
  2139. goto exit;
  2140. }
  2141. }
  2142. if (wl_p2p_find_peer_channel(cfg, status, bi, bi_length)) {
  2143. goto exit;
  2144. } else {
  2145. if (scan_req_match(cfg)) {
  2146. /* p2p scan && allow only probe response */
  2147. if ((cfg->p2p->search_state != WL_P2P_DISC_ST_SCAN) &&
  2148. (bi->flags & WL_BSS_FLAGS_FROM_BEACON))
  2149. goto exit;
  2150. }
  2151. #ifdef ROAM_CHANNEL_CACHE
  2152. add_roam_cache(cfg, bi);
  2153. #endif /* ROAM_CHANNEL_CACHE */
  2154. err = wl_inform_single_bss(cfg, bi, false);
  2155. #ifdef ROAM_CHANNEL_CACHE
  2156. /* print_roam_cache(); */
  2157. update_roam_cache(cfg, ioctl_version);
  2158. #endif /* ROAM_CHANNEL_CACHE */
  2159. /*
  2160. * !Broadcast && number of ssid = 1 && number of channels =1
  2161. * means specific scan to association
  2162. */
  2163. if (wl_cfgp2p_is_p2p_specific_scan(cfg->scan_request)) {
  2164. WL_ERR(("P2P assoc scan fast aborted.\n"));
  2165. aborted = false;
  2166. fw_abort = true;
  2167. }
  2168. /* Directly exit from function here and
  2169. * avoid sending notify completion to cfg80211
  2170. */
  2171. goto exit;
  2172. }
  2173. } else if (status == WLC_E_STATUS_SUCCESS) {
  2174. if (wl_p2p_find_peer_channel(cfg, status, NULL, 0)) {
  2175. goto exit;
  2176. }
  2177. WL_INFORM_MEM(("ESCAN COMPLETED\n"));
  2178. DBG_EVENT_LOG((dhd_pub_t *)cfg->pub, WIFI_EVENT_DRIVER_SCAN_COMPLETE);
  2179. /* Update escan complete status */
  2180. aborted = false;
  2181. fw_abort = false;
  2182. #ifdef CUSTOMER_HW4_DEBUG
  2183. if (wl_scan_timeout_dbg_enabled)
  2184. wl_scan_timeout_dbg_clear();
  2185. #endif /* CUSTOMER_HW4_DEBUG */
  2186. } else if ((status == WLC_E_STATUS_ABORT) || (status == WLC_E_STATUS_NEWSCAN) ||
  2187. (status == WLC_E_STATUS_11HQUIET) || (status == WLC_E_STATUS_CS_ABORT) ||
  2188. (status == WLC_E_STATUS_NEWASSOC)) {
  2189. /* Handle all cases of scan abort */
  2190. WL_DBG(("ESCAN ABORT reason: %d\n", status));
  2191. if (wl_p2p_find_peer_channel(cfg, status, NULL, 0)) {
  2192. goto exit;
  2193. }
  2194. WL_INFORM_MEM(("ESCAN ABORTED\n"));
  2195. /* Update escan complete status */
  2196. aborted = true;
  2197. fw_abort = false;
  2198. } else if (status == WLC_E_STATUS_TIMEOUT) {
  2199. WL_ERR(("WLC_E_STATUS_TIMEOUT : scan_request[%p]\n", cfg->scan_request));
  2200. WL_ERR(("reason[0x%x]\n", e->reason));
  2201. if (e->reason == 0xFFFFFFFF) {
  2202. /* Update escan complete status */
  2203. aborted = true;
  2204. fw_abort = true;
  2205. }
  2206. } else {
  2207. WL_ERR(("unexpected Escan Event %d : abort\n", status));
  2208. if (wl_p2p_find_peer_channel(cfg, status, NULL, 0)) {
  2209. goto exit;
  2210. }
  2211. /* Update escan complete status */
  2212. aborted = true;
  2213. fw_abort = false;
  2214. }
  2215. /* Notify escan complete status */
  2216. if (notify_escan_complete) {
  2217. wl_notify_escan_complete(cfg, ndev, aborted, fw_abort);
  2218. }
  2219. exit:
  2220. return err;
  2221. }
  2222. #endif /* WL_DRV_AVOID_SCANCACHE */
  2223. s32
  2224. wl_notify_scan_status(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
  2225. const wl_event_msg_t *e, void *data)
  2226. {
  2227. struct channel_info channel_inform;
  2228. struct wl_scan_results *bss_list;
  2229. struct net_device *ndev = NULL;
  2230. u32 len = WL_SCAN_BUF_MAX;
  2231. s32 err = 0;
  2232. unsigned long flags;
  2233. WL_DBG(("Enter \n"));
  2234. if (!wl_get_drv_status(cfg, SCANNING, ndev)) {
  2235. WL_DBG(("scan is not ready \n"));
  2236. return err;
  2237. }
  2238. ndev = cfgdev_to_wlc_ndev(cfgdev, cfg);
  2239. mutex_lock(&cfg->scan_sync);
  2240. wl_clr_drv_status(cfg, SCANNING, ndev);
  2241. bzero(&channel_inform, sizeof(channel_inform));
  2242. err = wldev_ioctl_get(ndev, WLC_GET_CHANNEL, &channel_inform,
  2243. sizeof(channel_inform));
  2244. if (unlikely(err)) {
  2245. WL_ERR(("scan busy (%d)\n", err));
  2246. goto scan_done_out;
  2247. }
  2248. channel_inform.scan_channel = dtoh32(channel_inform.scan_channel);
  2249. if (unlikely(channel_inform.scan_channel)) {
  2250. WL_DBG(("channel_inform.scan_channel (%d)\n",
  2251. channel_inform.scan_channel));
  2252. }
  2253. cfg->bss_list = cfg->scan_results;
  2254. bss_list = cfg->bss_list;
  2255. bzero(bss_list, len);
  2256. bss_list->buflen = htod32(len);
  2257. err = wldev_ioctl_get(ndev, WLC_SCAN_RESULTS, bss_list, len);
  2258. if (unlikely(err) && unlikely(!cfg->scan_suppressed)) {
  2259. WL_ERR(("%s Scan_results error (%d)\n", ndev->name, err));
  2260. err = -EINVAL;
  2261. goto scan_done_out;
  2262. }
  2263. bss_list->buflen = dtoh32(bss_list->buflen);
  2264. bss_list->version = dtoh32(bss_list->version);
  2265. bss_list->count = dtoh32(bss_list->count);
  2266. err = wl_inform_bss(cfg);
  2267. scan_done_out:
  2268. del_timer_sync(&cfg->scan_timeout);
  2269. WL_CFG_DRV_LOCK(&cfg->cfgdrv_lock, flags);
  2270. if (cfg->scan_request) {
  2271. _wl_notify_scan_done(cfg, false);
  2272. cfg->scan_request = NULL;
  2273. }
  2274. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  2275. WL_DBG(("cfg80211_scan_done\n"));
  2276. mutex_unlock(&cfg->scan_sync);
  2277. return err;
  2278. }
  2279. void wl_notify_scan_done(struct bcm_cfg80211 *cfg, bool aborted)
  2280. {
  2281. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
  2282. struct cfg80211_scan_info info;
  2283. bzero(&info, sizeof(struct cfg80211_scan_info));
  2284. info.aborted = aborted;
  2285. cfg80211_scan_done(cfg->scan_request, &info);
  2286. #else
  2287. cfg80211_scan_done(cfg->scan_request, aborted);
  2288. #endif // endif
  2289. }
  2290. #if defined(SUPPORT_RANDOM_MAC_SCAN)
  2291. int
  2292. wl_cfg80211_set_random_mac(struct net_device *dev, bool enable)
  2293. {
  2294. struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
  2295. int ret;
  2296. if (cfg->random_mac_enabled == enable) {
  2297. WL_ERR(("Random MAC already %s\n", enable ? "Enabled" : "Disabled"));
  2298. return BCME_OK;
  2299. }
  2300. if (enable) {
  2301. ret = wl_cfg80211_random_mac_enable(dev);
  2302. } else {
  2303. ret = wl_cfg80211_random_mac_disable(dev);
  2304. }
  2305. if (!ret) {
  2306. cfg->random_mac_enabled = enable;
  2307. }
  2308. return ret;
  2309. }
  2310. int
  2311. wl_cfg80211_random_mac_enable(struct net_device *dev)
  2312. {
  2313. u8 random_mac[ETH_ALEN] = {0, };
  2314. u8 rand_bytes[3] = {0, };
  2315. s32 err = BCME_ERROR;
  2316. struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
  2317. #if !defined(LEGACY_RANDOM_MAC)
  2318. uint8 buffer[WLC_IOCTL_SMLEN] = {0, };
  2319. wl_scanmac_t *sm = NULL;
  2320. int len = 0;
  2321. wl_scanmac_enable_t *sm_enable = NULL;
  2322. wl_scanmac_config_t *sm_config = NULL;
  2323. #endif /* !LEGACY_RANDOM_MAC */
  2324. if (wl_get_drv_status_all(cfg, CONNECTED) || wl_get_drv_status_all(cfg, CONNECTING) ||
  2325. wl_get_drv_status_all(cfg, AP_CREATED) || wl_get_drv_status_all(cfg, AP_CREATING)) {
  2326. WL_ERR(("fail to Set random mac, current state is wrong\n"));
  2327. return err;
  2328. }
  2329. (void)memcpy_s(random_mac, ETH_ALEN, bcmcfg_to_prmry_ndev(cfg)->dev_addr, ETH_ALEN);
  2330. get_random_bytes(&rand_bytes, sizeof(rand_bytes));
  2331. if (rand_bytes[2] == 0x0 || rand_bytes[2] == 0xff) {
  2332. rand_bytes[2] = 0xf0;
  2333. }
  2334. #if defined(LEGACY_RANDOM_MAC)
  2335. /* of the six bytes of random_mac the bytes 3, 4, 5 are copied with contents of rand_bytes
  2336. * So while copying 3 bytes of content no overflow would be seen. Hence returning void.
  2337. */
  2338. (void)memcpy_s(&random_mac[3], (sizeof(u8) * 3), rand_bytes, sizeof(rand_bytes));
  2339. err = wldev_iovar_setbuf_bsscfg(bcmcfg_to_prmry_ndev(cfg), "cur_etheraddr",
  2340. random_mac, ETH_ALEN, cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2341. if (err != BCME_OK) {
  2342. WL_ERR(("failed to set random generate MAC address\n"));
  2343. } else {
  2344. WL_ERR(("set mac " MACDBG " to " MACDBG "\n",
  2345. MAC2STRDBG((const u8 *)bcmcfg_to_prmry_ndev(cfg)->dev_addr),
  2346. MAC2STRDBG((const u8 *)&random_mac)));
  2347. WL_ERR(("random MAC enable done"));
  2348. }
  2349. #else
  2350. /* Enable scan mac */
  2351. sm = (wl_scanmac_t *)buffer;
  2352. sm_enable = (wl_scanmac_enable_t *)sm->data;
  2353. sm->len = sizeof(*sm_enable);
  2354. sm_enable->enable = 1;
  2355. len = OFFSETOF(wl_scanmac_t, data) + sm->len;
  2356. sm->subcmd_id = WL_SCANMAC_SUBCMD_ENABLE;
  2357. err = wldev_iovar_setbuf_bsscfg(dev, "scanmac",
  2358. sm, len, cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2359. /* For older chip which which does not have scanmac support can still use
  2360. * cur_etheraddr to set the randmac. rand_mask and rand_mac comes from upper
  2361. * cfg80211 layer. If rand_mask and rand_mac is not passed then fallback
  2362. * to default cur_etheraddr and default mask.
  2363. */
  2364. if (err == BCME_UNSUPPORTED) {
  2365. /* In case of host based legacy randomization, random address is
  2366. * generated by mixing 3 bytes of cur_etheraddr and 3 bytes of
  2367. * random bytes generated.In that case rand_mask is nothing but
  2368. * random bytes.
  2369. */
  2370. (void)memcpy_s(&random_mac[3], (sizeof(u8) * 3), rand_bytes, sizeof(rand_bytes));
  2371. err = wldev_iovar_setbuf_bsscfg(bcmcfg_to_prmry_ndev(cfg), "cur_etheraddr",
  2372. random_mac, ETH_ALEN, cfg->ioctl_buf,
  2373. WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2374. if (err != BCME_OK) {
  2375. WL_ERR(("failed to set random generate MAC address\n"));
  2376. } else {
  2377. WL_ERR(("set mac " MACDBG " to " MACDBG "\n",
  2378. MAC2STRDBG((const u8 *)bcmcfg_to_prmry_ndev(cfg)->dev_addr),
  2379. MAC2STRDBG((const u8 *)&random_mac)));
  2380. WL_ERR(("random MAC enable done using legacy randmac"));
  2381. }
  2382. } else if (err == BCME_OK) {
  2383. /* Configure scanmac */
  2384. (void)memset_s(buffer, sizeof(buffer), 0x0, sizeof(buffer));
  2385. sm_config = (wl_scanmac_config_t *)sm->data;
  2386. sm->len = sizeof(*sm_config);
  2387. sm->subcmd_id = WL_SCANMAC_SUBCMD_CONFIG;
  2388. sm_config->scan_bitmap = WL_SCANMAC_SCAN_UNASSOC;
  2389. /* Set randomize mac address recv from upper layer */
  2390. (void)memcpy_s(&sm_config->mac.octet, ETH_ALEN, random_mac, ETH_ALEN);
  2391. /* Set randomize mask recv from upper layer */
  2392. /* Currently in samsung case, upper layer does not provide
  2393. * variable randmask and its using fixed 3 byte randomization
  2394. */
  2395. (void)memset_s(&sm_config->random_mask.octet, ETH_ALEN, 0x0, ETH_ALEN);
  2396. /* Memsetting the remaining octets 3, 4, 5. So remaining dest length is 3 */
  2397. (void)memset_s(&sm_config->random_mask.octet[3], 3, 0xFF, 3);
  2398. WL_DBG(("recv random mac addr " MACDBG " recv rand mask" MACDBG "\n",
  2399. MAC2STRDBG((const u8 *)&sm_config->mac.octet),
  2400. MAC2STRDBG((const u8 *)&sm_config->random_mask)));
  2401. len = OFFSETOF(wl_scanmac_t, data) + sm->len;
  2402. err = wldev_iovar_setbuf_bsscfg(dev, "scanmac",
  2403. sm, len, cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2404. if (err != BCME_OK) {
  2405. WL_ERR(("failed scanmac configuration\n"));
  2406. /* Disable scan mac for clean-up */
  2407. wl_cfg80211_random_mac_disable(dev);
  2408. return err;
  2409. }
  2410. WL_DBG(("random MAC enable done using scanmac"));
  2411. } else {
  2412. WL_ERR(("failed to enable scanmac, err=%d\n", err));
  2413. }
  2414. #endif /* LEGACY_RANDOM_MAC */
  2415. return err;
  2416. }
  2417. int
  2418. wl_cfg80211_random_mac_disable(struct net_device *dev)
  2419. {
  2420. s32 err = BCME_ERROR;
  2421. struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
  2422. #if !defined(LEGACY_RANDOM_MAC)
  2423. uint8 buffer[WLC_IOCTL_SMLEN] = {0, };
  2424. wl_scanmac_t *sm = NULL;
  2425. int len = 0;
  2426. wl_scanmac_enable_t *sm_enable = NULL;
  2427. #endif /* !LEGACY_RANDOM_MAC */
  2428. #if defined(LEGACY_RANDOM_MAC)
  2429. WL_ERR(("set original mac " MACDBG "\n",
  2430. MAC2STRDBG((const u8 *)bcmcfg_to_prmry_ndev(cfg)->dev_addr)));
  2431. err = wldev_iovar_setbuf_bsscfg(bcmcfg_to_prmry_ndev(cfg), "cur_etheraddr",
  2432. bcmcfg_to_prmry_ndev(cfg)->dev_addr, ETH_ALEN,
  2433. cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2434. if (err != BCME_OK) {
  2435. WL_ERR(("failed to set original MAC address\n"));
  2436. } else {
  2437. WL_ERR(("legacy random MAC disable done \n"));
  2438. }
  2439. #else
  2440. sm = (wl_scanmac_t *)buffer;
  2441. sm_enable = (wl_scanmac_enable_t *)sm->data;
  2442. sm->len = sizeof(*sm_enable);
  2443. /* Disable scanmac */
  2444. sm_enable->enable = 0;
  2445. len = OFFSETOF(wl_scanmac_t, data) + sm->len;
  2446. sm->subcmd_id = WL_SCANMAC_SUBCMD_ENABLE;
  2447. err = wldev_iovar_setbuf_bsscfg(dev, "scanmac",
  2448. sm, len, cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2449. if (err != BCME_OK) {
  2450. WL_ERR(("failed to disable scanmac, err=%d\n", err));
  2451. return err;
  2452. }
  2453. /* Clear scanmac enabled status */
  2454. cfg->scanmac_enabled = 0;
  2455. WL_DBG(("random MAC disable done\n"));
  2456. #endif /* LEGACY_RANDOM_MAC */
  2457. return err;
  2458. }
  2459. /*
  2460. * This is new interface for mac randomization. It takes randmac and randmask
  2461. * as arg and it uses scanmac iovar to offload the mac randomization to firmware.
  2462. */
  2463. int wl_cfg80211_scan_mac_enable(struct net_device *dev, uint8 *rand_mac, uint8 *rand_mask)
  2464. {
  2465. int byte_index = 0;
  2466. s32 err = BCME_ERROR;
  2467. uint8 buffer[WLC_IOCTL_SMLEN] = {0, };
  2468. wl_scanmac_t *sm = NULL;
  2469. int len = 0;
  2470. wl_scanmac_enable_t *sm_enable = NULL;
  2471. wl_scanmac_config_t *sm_config = NULL;
  2472. struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
  2473. if ((rand_mac == NULL) || (rand_mask == NULL)) {
  2474. err = BCME_BADARG;
  2475. WL_ERR(("fail to Set random mac, bad argument\n"));
  2476. /* Disable the current scanmac config */
  2477. wl_cfg80211_scan_mac_disable(dev);
  2478. return err;
  2479. }
  2480. if (ETHER_ISNULLADDR(rand_mac)) {
  2481. WL_DBG(("fail to Set random mac, Invalid rand mac\n"));
  2482. /* Disable the current scanmac config */
  2483. wl_cfg80211_scan_mac_disable(dev);
  2484. return err;
  2485. }
  2486. if (wl_get_drv_status_all(cfg, CONNECTED) || wl_get_drv_status_all(cfg, CONNECTING) ||
  2487. wl_get_drv_status_all(cfg, AP_CREATED) || wl_get_drv_status_all(cfg, AP_CREATING)) {
  2488. WL_ERR(("fail to Set random mac, current state is wrong\n"));
  2489. return BCME_UNSUPPORTED;
  2490. }
  2491. /* Enable scan mac */
  2492. sm = (wl_scanmac_t *)buffer;
  2493. sm_enable = (wl_scanmac_enable_t *)sm->data;
  2494. sm->len = sizeof(*sm_enable);
  2495. sm_enable->enable = 1;
  2496. len = OFFSETOF(wl_scanmac_t, data) + sm->len;
  2497. sm->subcmd_id = WL_SCANMAC_SUBCMD_ENABLE;
  2498. err = wldev_iovar_setbuf_bsscfg(dev, "scanmac",
  2499. sm, len, cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2500. if (err == BCME_OK) {
  2501. /* Configure scanmac */
  2502. (void)memset_s(buffer, sizeof(buffer), 0x0, sizeof(buffer));
  2503. sm_config = (wl_scanmac_config_t *)sm->data;
  2504. sm->len = sizeof(*sm_config);
  2505. sm->subcmd_id = WL_SCANMAC_SUBCMD_CONFIG;
  2506. sm_config->scan_bitmap = WL_SCANMAC_SCAN_UNASSOC;
  2507. /* Set randomize mac address recv from upper layer */
  2508. (void)memcpy_s(&sm_config->mac.octet, ETH_ALEN, rand_mac, ETH_ALEN);
  2509. /* Set randomize mask recv from upper layer */
  2510. /* There is a difference in how to interpret rand_mask between
  2511. * upperlayer and firmware. If the byte is set as FF then for
  2512. * upper layer it means keep that byte and do not randomize whereas
  2513. * for firmware it means randomize those bytes and vice versa. Hence
  2514. * conversion is needed before setting the iovar
  2515. */
  2516. (void)memset_s(&sm_config->random_mask.octet, ETH_ALEN, 0x0, ETH_ALEN);
  2517. /* Only byte randomization is supported currently. If mask recv is 0x0F
  2518. * for a particular byte then it will be treated as no randomization
  2519. * for that byte.
  2520. */
  2521. while (byte_index < ETH_ALEN) {
  2522. if (rand_mask[byte_index] == 0xFF) {
  2523. sm_config->random_mask.octet[byte_index] = 0x00;
  2524. } else if (rand_mask[byte_index] == 0x00) {
  2525. sm_config->random_mask.octet[byte_index] = 0xFF;
  2526. }
  2527. byte_index++;
  2528. }
  2529. WL_DBG(("recv random mac addr " MACDBG "recv rand mask" MACDBG "\n",
  2530. MAC2STRDBG((const u8 *)&sm_config->mac.octet),
  2531. MAC2STRDBG((const u8 *)&sm_config->random_mask)));
  2532. len = OFFSETOF(wl_scanmac_t, data) + sm->len;
  2533. err = wldev_iovar_setbuf_bsscfg(dev, "scanmac",
  2534. sm, len, cfg->ioctl_buf, WLC_IOCTL_SMLEN, 0, &cfg->ioctl_buf_sync);
  2535. if (err != BCME_OK) {
  2536. WL_ERR(("failed scanmac configuration\n"));
  2537. /* Disable scan mac for clean-up */
  2538. wl_cfg80211_random_mac_disable(dev);
  2539. return err;
  2540. }
  2541. /* Mark scanmac enabled */
  2542. cfg->scanmac_enabled = 1;
  2543. WL_DBG(("scanmac enable done"));
  2544. } else {
  2545. WL_ERR(("failed to enable scanmac, err=%d\n", err));
  2546. }
  2547. return err;
  2548. }
  2549. int
  2550. wl_cfg80211_scan_mac_disable(struct net_device *dev)
  2551. {
  2552. s32 err = BCME_ERROR;
  2553. err = wl_cfg80211_random_mac_disable(dev);
  2554. return err;
  2555. }
  2556. #endif /* SUPPORT_RANDOM_MAC_SCAN */
  2557. #ifdef WL_SCHED_SCAN
  2558. #define PNO_TIME 30
  2559. #define PNO_REPEAT 4
  2560. #define PNO_FREQ_EXPO_MAX 2
  2561. static bool
  2562. is_ssid_in_list(struct cfg80211_ssid *ssid, struct cfg80211_ssid *ssid_list, int count)
  2563. {
  2564. int i;
  2565. if (!ssid || !ssid_list)
  2566. return FALSE;
  2567. for (i = 0; i < count; i++) {
  2568. if (ssid->ssid_len == ssid_list[i].ssid_len) {
  2569. if (strncmp(ssid->ssid, ssid_list[i].ssid, ssid->ssid_len) == 0)
  2570. return TRUE;
  2571. }
  2572. }
  2573. return FALSE;
  2574. }
  2575. int
  2576. wl_cfg80211_sched_scan_start(struct wiphy *wiphy,
  2577. struct net_device *dev,
  2578. struct cfg80211_sched_scan_request *request)
  2579. {
  2580. ushort pno_time = PNO_TIME;
  2581. int pno_repeat = PNO_REPEAT;
  2582. int pno_freq_expo_max = PNO_FREQ_EXPO_MAX;
  2583. wlc_ssid_ext_t ssids_local[MAX_PFN_LIST_COUNT];
  2584. struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
  2585. dhd_pub_t *dhdp = (dhd_pub_t *)(cfg->pub);
  2586. struct cfg80211_ssid *ssid = NULL;
  2587. struct cfg80211_ssid *hidden_ssid_list = NULL;
  2588. log_conn_event_t *event_data = NULL;
  2589. tlv_log *tlv_data = NULL;
  2590. u32 alloc_len, tlv_len;
  2591. u32 payload_len;
  2592. int ssid_cnt = 0;
  2593. int i;
  2594. int ret = 0;
  2595. unsigned long flags;
  2596. if (!request) {
  2597. WL_ERR(("Sched scan request was NULL\n"));
  2598. return -EINVAL;
  2599. }
  2600. WL_DBG(("Enter \n"));
  2601. WL_PNO((">>> SCHED SCAN START\n"));
  2602. WL_PNO(("Enter n_match_sets:%d n_ssids:%d \n",
  2603. request->n_match_sets, request->n_ssids));
  2604. WL_PNO(("ssids:%d pno_time:%d pno_repeat:%d pno_freq:%d \n",
  2605. request->n_ssids, pno_time, pno_repeat, pno_freq_expo_max));
  2606. if (!request->n_ssids || !request->n_match_sets) {
  2607. WL_ERR(("Invalid sched scan req!! n_ssids:%d \n", request->n_ssids));
  2608. return -EINVAL;
  2609. }
  2610. bzero(&ssids_local, sizeof(ssids_local));
  2611. if (request->n_ssids > 0) {
  2612. hidden_ssid_list = request->ssids;
  2613. }
  2614. if (DBG_RING_ACTIVE(dhdp, DHD_EVENT_RING_ID)) {
  2615. alloc_len = sizeof(log_conn_event_t) + DOT11_MAX_SSID_LEN;
  2616. event_data = (log_conn_event_t *)MALLOC(cfg->osh, alloc_len);
  2617. if (!event_data) {
  2618. WL_ERR(("%s: failed to allocate log_conn_event_t with "
  2619. "length(%d)\n", __func__, alloc_len));
  2620. return -ENOMEM;
  2621. }
  2622. bzero(event_data, alloc_len);
  2623. event_data->tlvs = NULL;
  2624. tlv_len = sizeof(tlv_log);
  2625. event_data->tlvs = (tlv_log *)MALLOC(cfg->osh, tlv_len);
  2626. if (!event_data->tlvs) {
  2627. WL_ERR(("%s: failed to allocate log_tlv with "
  2628. "length(%d)\n", __func__, tlv_len));
  2629. MFREE(cfg->osh, event_data, alloc_len);
  2630. return -ENOMEM;
  2631. }
  2632. }
  2633. for (i = 0; i < request->n_match_sets && ssid_cnt < MAX_PFN_LIST_COUNT; i++) {
  2634. ssid = &request->match_sets[i].ssid;
  2635. /* No need to include null ssid */
  2636. if (ssid->ssid_len) {
  2637. ssids_local[ssid_cnt].SSID_len = MIN(ssid->ssid_len,
  2638. (uint32)DOT11_MAX_SSID_LEN);
  2639. /* In previous step max SSID_len is limited to DOT11_MAX_SSID_LEN,
  2640. * returning void
  2641. */
  2642. (void)memcpy_s(ssids_local[ssid_cnt].SSID, DOT11_MAX_SSID_LEN, ssid->ssid,
  2643. ssids_local[ssid_cnt].SSID_len);
  2644. if (is_ssid_in_list(ssid, hidden_ssid_list, request->n_ssids)) {
  2645. ssids_local[ssid_cnt].hidden = TRUE;
  2646. WL_PNO((">>> PNO hidden SSID (%s) \n", ssid->ssid));
  2647. } else {
  2648. ssids_local[ssid_cnt].hidden = FALSE;
  2649. WL_PNO((">>> PNO non-hidden SSID (%s) \n", ssid->ssid));
  2650. }
  2651. #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 15, 0))
  2652. if (request->match_sets[i].rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
  2653. ssids_local[ssid_cnt].rssi_thresh =
  2654. (int8)request->match_sets[i].rssi_thold;
  2655. }
  2656. #endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(3, 15, 0)) */
  2657. ssid_cnt++;
  2658. }
  2659. }
  2660. if (ssid_cnt) {
  2661. if ((ret = dhd_dev_pno_set_for_ssid(dev, ssids_local, ssid_cnt,
  2662. pno_time, pno_repeat, pno_freq_expo_max, NULL, 0)) < 0) {
  2663. WL_ERR(("PNO setup failed!! ret=%d \n", ret));
  2664. ret = -EINVAL;
  2665. goto exit;
  2666. }
  2667. if (DBG_RING_ACTIVE(dhdp, DHD_EVENT_RING_ID)) {
  2668. for (i = 0; i < ssid_cnt; i++) {
  2669. payload_len = sizeof(log_conn_event_t);
  2670. event_data->event = WIFI_EVENT_DRIVER_PNO_ADD;
  2671. tlv_data = event_data->tlvs;
  2672. /* ssid */
  2673. tlv_data->tag = WIFI_TAG_SSID;
  2674. tlv_data->len = ssids_local[i].SSID_len;
  2675. (void)memcpy_s(tlv_data->value, DOT11_MAX_SSID_LEN,
  2676. ssids_local[i].SSID, ssids_local[i].SSID_len);
  2677. payload_len += TLV_LOG_SIZE(tlv_data);
  2678. dhd_os_push_push_ring_data(dhdp, DHD_EVENT_RING_ID,
  2679. event_data, payload_len);
  2680. }
  2681. }
  2682. WL_CFG_DRV_LOCK(&cfg->cfgdrv_lock, flags);
  2683. cfg->sched_scan_req = request;
  2684. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  2685. } else {
  2686. ret = -EINVAL;
  2687. }
  2688. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && \
  2689. defined(SUPPORT_RANDOM_MAC_SCAN)
  2690. if (!ETHER_ISNULLADDR(request->mac_addr) && !ETHER_ISNULLADDR(request->mac_addr_mask)) {
  2691. ret = wl_cfg80211_scan_mac_enable(dev, request->mac_addr, request->mac_addr_mask);
  2692. /* Ignore if chip doesnt support the feature */
  2693. if (ret < 0) {
  2694. if (ret == BCME_UNSUPPORTED) {
  2695. /* If feature is not supported, ignore the error (legacy chips) */
  2696. ret = BCME_OK;
  2697. } else {
  2698. WL_ERR(("set random mac failed (%d). Ignore.\n", ret));
  2699. /* Cleanup the states and stop the pno */
  2700. if (dhd_dev_pno_stop_for_ssid(dev) < 0) {
  2701. WL_ERR(("PNO Stop for SSID failed"));
  2702. }
  2703. WL_CFG_DRV_LOCK(&cfg->cfgdrv_lock, flags);
  2704. cfg->sched_scan_req = NULL;
  2705. cfg->sched_scan_running = FALSE;
  2706. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  2707. }
  2708. }
  2709. }
  2710. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && (defined(SUPPORT_RANDOM_MAC_SCAN)) */
  2711. exit:
  2712. if (event_data) {
  2713. MFREE(cfg->osh, event_data->tlvs, tlv_len);
  2714. MFREE(cfg->osh, event_data, alloc_len);
  2715. }
  2716. return ret;
  2717. }
  2718. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
  2719. int
  2720. wl_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev, u64 reqid)
  2721. #else
  2722. int
  2723. wl_cfg80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  2724. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) */
  2725. {
  2726. struct bcm_cfg80211 *cfg = wiphy_priv(wiphy);
  2727. dhd_pub_t *dhdp = (dhd_pub_t *)(cfg->pub);
  2728. unsigned long flags;
  2729. WL_DBG(("Enter \n"));
  2730. WL_PNO((">>> SCHED SCAN STOP\n"));
  2731. if (dhd_dev_pno_stop_for_ssid(dev) < 0) {
  2732. WL_ERR(("PNO Stop for SSID failed"));
  2733. } else {
  2734. DBG_EVENT_LOG(dhdp, WIFI_EVENT_DRIVER_PNO_REMOVE);
  2735. }
  2736. if (cfg->sched_scan_req || cfg->sched_scan_running) {
  2737. WL_PNO((">>> Sched scan running. Aborting it..\n"));
  2738. wl_cfg80211_cancel_scan(cfg);
  2739. }
  2740. WL_CFG_DRV_LOCK(&cfg->cfgdrv_lock, flags);
  2741. cfg->sched_scan_req = NULL;
  2742. cfg->sched_scan_running = FALSE;
  2743. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  2744. return 0;
  2745. }
  2746. #endif /* WL_SCHED_SCAN */
  2747. #ifdef WES_SUPPORT
  2748. #ifdef CUSTOMER_SCAN_TIMEOUT_SETTING
  2749. s32 wl_cfg80211_custom_scan_time(struct net_device *dev,
  2750. enum wl_custom_scan_time_type type, int time)
  2751. {
  2752. struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
  2753. if (cfg == NULL) {
  2754. return FALSE;
  2755. }
  2756. switch (type) {
  2757. case WL_CUSTOM_SCAN_CHANNEL_TIME :
  2758. WL_ERR(("Scan Channel Time %d\n", time));
  2759. cfg->custom_scan_channel_time = time;
  2760. break;
  2761. case WL_CUSTOM_SCAN_UNASSOC_TIME :
  2762. WL_ERR(("Scan Unassoc Time %d\n", time));
  2763. cfg->custom_scan_unassoc_time = time;
  2764. break;
  2765. case WL_CUSTOM_SCAN_PASSIVE_TIME :
  2766. WL_ERR(("Scan Passive Time %d\n", time));
  2767. cfg->custom_scan_passive_time = time;
  2768. break;
  2769. case WL_CUSTOM_SCAN_HOME_TIME :
  2770. WL_ERR(("Scan Home Time %d\n", time));
  2771. cfg->custom_scan_home_time = time;
  2772. break;
  2773. case WL_CUSTOM_SCAN_HOME_AWAY_TIME :
  2774. WL_ERR(("Scan Home Away Time %d\n", time));
  2775. cfg->custom_scan_home_away_time = time;
  2776. break;
  2777. default:
  2778. return FALSE;
  2779. }
  2780. return TRUE;
  2781. }
  2782. #endif /* CUSTOMER_SCAN_TIMEOUT_SETTING */
  2783. #endif /* WES_SUPPORT */
  2784. #ifdef CUSTOMER_HW4_DEBUG
  2785. uint prev_dhd_console_ms = 0;
  2786. u32 prev_wl_dbg_level = 0;
  2787. static void wl_scan_timeout_dbg_set(void);
  2788. static void wl_scan_timeout_dbg_set(void)
  2789. {
  2790. WL_ERR(("Enter \n"));
  2791. prev_dhd_console_ms = dhd_console_ms;
  2792. prev_wl_dbg_level = wl_dbg_level;
  2793. dhd_console_ms = 1;
  2794. wl_dbg_level |= (WL_DBG_ERR | WL_DBG_P2P_ACTION | WL_DBG_SCAN);
  2795. wl_scan_timeout_dbg_enabled = 1;
  2796. }
  2797. void wl_scan_timeout_dbg_clear(void)
  2798. {
  2799. WL_ERR(("Enter \n"));
  2800. dhd_console_ms = prev_dhd_console_ms;
  2801. wl_dbg_level = prev_wl_dbg_level;
  2802. wl_scan_timeout_dbg_enabled = 0;
  2803. }
  2804. #endif /* CUSTOMER_HW4_DEBUG */
  2805. static void wl_scan_timeout(unsigned long data)
  2806. {
  2807. wl_event_msg_t msg;
  2808. struct bcm_cfg80211 *cfg = (struct bcm_cfg80211 *)data;
  2809. struct wireless_dev *wdev = NULL;
  2810. struct net_device *ndev = NULL;
  2811. struct wl_scan_results *bss_list;
  2812. wl_bss_info_t *bi = NULL;
  2813. s32 i;
  2814. u32 channel;
  2815. u64 cur_time = OSL_LOCALTIME_NS();
  2816. dhd_pub_t *dhdp = (dhd_pub_t *)(cfg->pub);
  2817. unsigned long flags;
  2818. #ifdef RTT_SUPPORT
  2819. rtt_status_info_t *rtt_status = NULL;
  2820. UNUSED_PARAMETER(rtt_status);
  2821. #endif /* RTT_SUPPORT */
  2822. UNUSED_PARAMETER(cur_time);
  2823. WL_CFG_DRV_LOCK(&cfg->cfgdrv_lock, flags);
  2824. if (!(cfg->scan_request)) {
  2825. WL_ERR(("timer expired but no scan request\n"));
  2826. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  2827. return;
  2828. }
  2829. wdev = GET_SCAN_WDEV(cfg->scan_request);
  2830. WL_CFG_DRV_UNLOCK(&cfg->cfgdrv_lock, flags);
  2831. if (!wdev) {
  2832. WL_ERR(("No wireless_dev present\n"));
  2833. return;
  2834. }
  2835. if (dhd_query_bus_erros(dhdp)) {
  2836. return;
  2837. }
  2838. #if defined(DHD_KERNEL_SCHED_DEBUG) && defined(DHD_FW_COREDUMP)
  2839. if (dhdp->memdump_enabled == DUMP_MEMFILE_BUGON &&
  2840. ((cfg->scan_deq_time < cfg->scan_enq_time) ||
  2841. dhd_bus_query_dpc_sched_errors(dhdp))) {
  2842. WL_ERR(("****SCAN event timeout due to scheduling problem\n"));
  2843. /* change g_assert_type to trigger Kernel panic */
  2844. g_assert_type = 2;
  2845. #ifdef RTT_SUPPORT
  2846. rtt_status = GET_RTTSTATE(dhdp);
  2847. #endif /* RTT_SUPPORT */
  2848. WL_ERR(("***SCAN event timeout. WQ state:0x%x scan_enq_time:"SEC_USEC_FMT
  2849. " evt_hdlr_entry_time:"SEC_USEC_FMT" evt_deq_time:"SEC_USEC_FMT
  2850. "\nscan_deq_time:"SEC_USEC_FMT" scan_hdlr_cmplt_time:"SEC_USEC_FMT
  2851. " scan_cmplt_time:"SEC_USEC_FMT" evt_hdlr_exit_time:"SEC_USEC_FMT
  2852. "\ncurrent_time:"SEC_USEC_FMT"\n", work_busy(&cfg->event_work),
  2853. GET_SEC_USEC(cfg->scan_enq_time), GET_SEC_USEC(cfg->wl_evt_hdlr_entry_time),
  2854. GET_SEC_USEC(cfg->wl_evt_deq_time), GET_SEC_USEC(cfg->scan_deq_time),
  2855. GET_SEC_USEC(cfg->scan_hdlr_cmplt_time), GET_SEC_USEC(cfg->scan_cmplt_time),
  2856. GET_SEC_USEC(cfg->wl_evt_hdlr_exit_time), GET_SEC_USEC(cur_time)));
  2857. if (cfg->scan_enq_time) {
  2858. WL_ERR(("Elapsed time(ns): %llu\n", (cur_time - cfg->scan_enq_time)));
  2859. }
  2860. WL_ERR(("lock_states:[%d:%d:%d:%d:%d:%d]\n",
  2861. mutex_is_locked(&cfg->if_sync),
  2862. mutex_is_locked(&cfg->usr_sync),
  2863. mutex_is_locked(&cfg->pm_sync),
  2864. mutex_is_locked(&cfg->scan_sync),
  2865. spin_is_locked(&cfg->cfgdrv_lock),
  2866. spin_is_locked(&cfg->eq_lock)));
  2867. #ifdef RTT_SUPPORT
  2868. WL_ERR(("RTT lock_state:[%d]\n",
  2869. mutex_is_locked(&rtt_status->rtt_mutex)));
  2870. #ifdef WL_NAN
  2871. WL_ERR(("RTT and Geofence lock_states:[%d:%d]\n",
  2872. mutex_is_locked(&cfg->nancfg.nan_sync),
  2873. mutex_is_locked(&(rtt_status)->geofence_mutex)));
  2874. #endif /* WL_NAN */
  2875. #endif /* RTT_SUPPORT */
  2876. /* use ASSERT() to trigger panic */
  2877. ASSERT(0);
  2878. }
  2879. #endif /* DHD_KERNEL_SCHED_DEBUG && DHD_FW_COREDUMP */
  2880. dhd_bus_intr_count_dump(dhdp);
  2881. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)) && !defined(CONFIG_MODULES)
  2882. /* Print WQ states. Enable only for in-built drivers as the symbol is not exported */
  2883. show_workqueue_state();
  2884. #endif /* LINUX_VER >= 4.1 && !CONFIG_MODULES */
  2885. bss_list = wl_escan_get_buf(cfg, FALSE);
  2886. if (!bss_list) {
  2887. WL_ERR(("bss_list is null. Didn't receive any partial scan results\n"));
  2888. } else {
  2889. WL_ERR(("Dump scan buffer:\n"
  2890. "scanned AP count (%d)\n", bss_list->count));
  2891. bi = next_bss(bss_list, bi);
  2892. for_each_bss(bss_list, bi, i) {
  2893. channel = wf_chspec_ctlchan(wl_chspec_driver_to_host(bi->chanspec));
  2894. WL_ERR(("SSID :%s Channel :%d\n", bi->SSID, channel));
  2895. }
  2896. }
  2897. ndev = wdev_to_wlc_ndev(wdev, cfg);
  2898. bzero(&msg, sizeof(wl_event_msg_t));
  2899. WL_ERR(("timer expired\n"));
  2900. dhdp->scan_timeout_occurred = TRUE;
  2901. #ifdef BCMPCIE
  2902. (void)dhd_pcie_dump_int_regs(dhdp);
  2903. dhd_pcie_dump_rc_conf_space_cap(dhdp);
  2904. #endif /* BCMPCIE */
  2905. #ifdef DHD_FW_COREDUMP
  2906. if (dhdp->memdump_enabled) {
  2907. dhdp->memdump_type = DUMP_TYPE_SCAN_TIMEOUT;
  2908. dhd_bus_mem_dump(dhdp);
  2909. }
  2910. #endif /* DHD_FW_COREDUMP */
  2911. msg.event_type = hton32(WLC_E_ESCAN_RESULT);
  2912. msg.status = hton32(WLC_E_STATUS_TIMEOUT);
  2913. msg.reason = 0xFFFFFFFF;
  2914. wl_cfg80211_event(ndev, &msg, NULL);
  2915. #ifdef CUSTOMER_HW4_DEBUG
  2916. if (!wl_scan_timeout_dbg_enabled)
  2917. wl_scan_timeout_dbg_set();
  2918. #endif /* CUSTOMER_HW4_DEBUG */
  2919. }
  2920. s32 wl_init_scan(struct bcm_cfg80211 *cfg)
  2921. {
  2922. int err = 0;
  2923. cfg->evt_handler[WLC_E_ESCAN_RESULT] = wl_escan_handler;
  2924. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  2925. wl_escan_init_sync_id(cfg);
  2926. /* Init scan_timeout timer */
  2927. init_timer_compat(&cfg->scan_timeout, wl_scan_timeout, cfg);
  2928. wl_cfg80211_set_bcmcfg(cfg);
  2929. return err;
  2930. }
  2931. #ifdef WL_SCHED_SCAN
  2932. /* If target scan is not reliable, set the below define to "1" to do a
  2933. * full escan
  2934. */
  2935. #define FULL_ESCAN_ON_PFN_NET_FOUND 0
  2936. static s32
  2937. wl_notify_sched_scan_results(struct bcm_cfg80211 *cfg, struct net_device *ndev,
  2938. const wl_event_msg_t *e, void *data)
  2939. {
  2940. wl_pfn_net_info_v1_t *netinfo, *pnetinfo;
  2941. wl_pfn_net_info_v2_t *netinfo_v2, *pnetinfo_v2;
  2942. struct wiphy *wiphy = bcmcfg_to_wiphy(cfg);
  2943. dhd_pub_t *dhdp = (dhd_pub_t *)(cfg->pub);
  2944. int err = 0;
  2945. struct cfg80211_scan_request *request = NULL;
  2946. struct cfg80211_ssid ssid[MAX_PFN_LIST_COUNT];
  2947. struct ieee80211_channel *channel = NULL;
  2948. int channel_req = 0;
  2949. int band = 0;
  2950. wl_pfn_scanresults_v1_t *pfn_result_v1 = (wl_pfn_scanresults_v1_t *)data;
  2951. wl_pfn_scanresults_v2_t *pfn_result_v2 = (wl_pfn_scanresults_v2_t *)data;
  2952. int n_pfn_results = 0;
  2953. log_conn_event_t *event_data = NULL;
  2954. tlv_log *tlv_data = NULL;
  2955. u32 alloc_len, tlv_len;
  2956. u32 payload_len;
  2957. u8 tmp_buf[DOT11_MAX_SSID_LEN + 1];
  2958. WL_DBG(("Enter\n"));
  2959. /* These static asserts guarantee v1/v2 net_info and subnet_info are compatible
  2960. * in size and SSID offset, allowing v1 to be used below except for the results
  2961. * fields themselves (status, count, offset to netinfo).
  2962. */
  2963. STATIC_ASSERT(sizeof(wl_pfn_net_info_v1_t) == sizeof(wl_pfn_net_info_v2_t));
  2964. STATIC_ASSERT(sizeof(wl_pfn_lnet_info_v1_t) == sizeof(wl_pfn_lnet_info_v2_t));
  2965. STATIC_ASSERT(sizeof(wl_pfn_subnet_info_v1_t) == sizeof(wl_pfn_subnet_info_v2_t));
  2966. STATIC_ASSERT(OFFSETOF(wl_pfn_subnet_info_v1_t, SSID) ==
  2967. OFFSETOF(wl_pfn_subnet_info_v2_t, u.SSID));
  2968. /* Extract the version-specific items */
  2969. if (pfn_result_v1->version == PFN_SCANRESULT_VERSION_V1) {
  2970. n_pfn_results = pfn_result_v1->count;
  2971. pnetinfo = pfn_result_v1->netinfo;
  2972. WL_INFORM_MEM(("PFN NET FOUND event. count:%d \n", n_pfn_results));
  2973. if (n_pfn_results > 0) {
  2974. int i;
  2975. if (n_pfn_results > MAX_PFN_LIST_COUNT)
  2976. n_pfn_results = MAX_PFN_LIST_COUNT;
  2977. bzero(&ssid, sizeof(ssid));
  2978. request = (struct cfg80211_scan_request *)MALLOCZ(cfg->osh,
  2979. sizeof(*request) + sizeof(*request->channels) * n_pfn_results);
  2980. channel = (struct ieee80211_channel *)MALLOCZ(cfg->osh,
  2981. (sizeof(struct ieee80211_channel) * n_pfn_results));
  2982. if (!request || !channel) {
  2983. WL_ERR(("No memory"));
  2984. err = -ENOMEM;
  2985. goto out_err;
  2986. }
  2987. request->wiphy = wiphy;
  2988. if (DBG_RING_ACTIVE(dhdp, DHD_EVENT_RING_ID)) {
  2989. alloc_len = sizeof(log_conn_event_t) + DOT11_MAX_SSID_LEN +
  2990. sizeof(uint16) + sizeof(int16);
  2991. event_data = (log_conn_event_t *)MALLOC(cfg->osh, alloc_len);
  2992. if (!event_data) {
  2993. WL_ERR(("%s: failed to allocate the log_conn_event_t with "
  2994. "length(%d)\n", __func__, alloc_len));
  2995. goto out_err;
  2996. }
  2997. tlv_len = 3 * sizeof(tlv_log);
  2998. event_data->tlvs = (tlv_log *)MALLOC(cfg->osh, tlv_len);
  2999. if (!event_data->tlvs) {
  3000. WL_ERR(("%s: failed to allocate the tlv_log with "
  3001. "length(%d)\n", __func__, tlv_len));
  3002. goto out_err;
  3003. }
  3004. }
  3005. for (i = 0; i < n_pfn_results; i++) {
  3006. netinfo = &pnetinfo[i];
  3007. if (!netinfo) {
  3008. WL_ERR(("Invalid netinfo ptr. index:%d", i));
  3009. err = -EINVAL;
  3010. goto out_err;
  3011. }
  3012. if (netinfo->pfnsubnet.SSID_len > DOT11_MAX_SSID_LEN) {
  3013. WL_ERR(("Wrong SSID length:%d\n",
  3014. netinfo->pfnsubnet.SSID_len));
  3015. err = -EINVAL;
  3016. goto out_err;
  3017. }
  3018. /* In previous step max SSID_len limited to DOT11_MAX_SSID_LEN
  3019. * and tmp_buf size is DOT11_MAX_SSID_LEN+1
  3020. */
  3021. (void)memcpy_s(tmp_buf, DOT11_MAX_SSID_LEN,
  3022. netinfo->pfnsubnet.SSID, netinfo->pfnsubnet.SSID_len);
  3023. tmp_buf[netinfo->pfnsubnet.SSID_len] = '\0';
  3024. WL_PNO((">>> SSID:%s Channel:%d \n",
  3025. tmp_buf, netinfo->pfnsubnet.channel));
  3026. /* PFN result doesn't have all the info which are required by
  3027. * the supplicant. (For e.g IEs) Do a target Escan so that
  3028. * sched scan results are reported via wl_inform_single_bss in
  3029. * the required format. Escan does require the scan request in
  3030. * the form of cfg80211_scan_request. For timebeing, create
  3031. * cfg80211_scan_request one out of the received PNO event.
  3032. */
  3033. ssid[i].ssid_len = netinfo->pfnsubnet.SSID_len;
  3034. /* Returning void as ssid[i].ssid_len is limited to max of
  3035. * DOT11_MAX_SSID_LEN
  3036. */
  3037. (void)memcpy_s(ssid[i].ssid, IEEE80211_MAX_SSID_LEN,
  3038. netinfo->pfnsubnet.SSID, ssid[i].ssid_len);
  3039. request->n_ssids++;
  3040. channel_req = netinfo->pfnsubnet.channel;
  3041. band = (channel_req <= CH_MAX_2G_CHANNEL) ? NL80211_BAND_2GHZ
  3042. : NL80211_BAND_5GHZ;
  3043. channel[i].center_freq =
  3044. ieee80211_channel_to_frequency(channel_req, band);
  3045. channel[i].band = band;
  3046. channel[i].flags |= IEEE80211_CHAN_NO_HT40;
  3047. request->channels[i] = &channel[i];
  3048. request->n_channels++;
  3049. if (DBG_RING_ACTIVE(dhdp, DHD_EVENT_RING_ID)) {
  3050. payload_len = sizeof(log_conn_event_t);
  3051. event_data->event = WIFI_EVENT_DRIVER_PNO_NETWORK_FOUND;
  3052. tlv_data = event_data->tlvs;
  3053. /* ssid */
  3054. tlv_data->tag = WIFI_TAG_SSID;
  3055. tlv_data->len = ssid[i].ssid_len;
  3056. (void)memcpy_s(tlv_data->value, DOT11_MAX_SSID_LEN,
  3057. ssid[i].ssid, ssid[i].ssid_len);
  3058. payload_len += TLV_LOG_SIZE(tlv_data);
  3059. tlv_data = TLV_LOG_NEXT(tlv_data);
  3060. /* channel */
  3061. tlv_data->tag = WIFI_TAG_CHANNEL;
  3062. tlv_data->len = sizeof(uint16);
  3063. (void)memcpy_s(tlv_data->value, sizeof(uint16),
  3064. &channel_req, sizeof(uint16));
  3065. payload_len += TLV_LOG_SIZE(tlv_data);
  3066. tlv_data = TLV_LOG_NEXT(tlv_data);
  3067. /* rssi */
  3068. tlv_data->tag = WIFI_TAG_RSSI;
  3069. tlv_data->len = sizeof(int16);
  3070. (void)memcpy_s(tlv_data->value, sizeof(int16),
  3071. &netinfo->RSSI, sizeof(int16));
  3072. payload_len += TLV_LOG_SIZE(tlv_data);
  3073. tlv_data = TLV_LOG_NEXT(tlv_data);
  3074. dhd_os_push_push_ring_data(dhdp, DHD_EVENT_RING_ID,
  3075. &event_data->event, payload_len);
  3076. }
  3077. }
  3078. /* assign parsed ssid array */
  3079. if (request->n_ssids)
  3080. request->ssids = &ssid[0];
  3081. if (wl_get_drv_status_all(cfg, SCANNING)) {
  3082. /* Abort any on-going scan */
  3083. wl_cfg80211_cancel_scan(cfg);
  3084. }
  3085. if (wl_get_p2p_status(cfg, DISCOVERY_ON)) {
  3086. WL_PNO((">>> P2P discovery was ON. Disabling it\n"));
  3087. err = wl_cfgp2p_discover_enable_search(cfg, false);
  3088. if (unlikely(err)) {
  3089. wl_clr_drv_status(cfg, SCANNING, ndev);
  3090. goto out_err;
  3091. }
  3092. p2p_scan(cfg) = false;
  3093. }
  3094. wl_set_drv_status(cfg, SCANNING, ndev);
  3095. #if FULL_ESCAN_ON_PFN_NET_FOUND
  3096. WL_PNO((">>> Doing Full ESCAN on PNO event\n"));
  3097. err = wl_do_escan(cfg, wiphy, ndev, NULL);
  3098. #else
  3099. WL_PNO((">>> Doing targeted ESCAN on PNO event\n"));
  3100. err = wl_do_escan(cfg, wiphy, ndev, request);
  3101. #endif // endif
  3102. if (err) {
  3103. wl_clr_drv_status(cfg, SCANNING, ndev);
  3104. goto out_err;
  3105. }
  3106. DBG_EVENT_LOG(dhdp, WIFI_EVENT_DRIVER_PNO_SCAN_REQUESTED);
  3107. cfg->sched_scan_running = TRUE;
  3108. }
  3109. else {
  3110. WL_ERR(("FALSE PNO Event. (pfn_count == 0) \n"));
  3111. }
  3112. } else if (pfn_result_v2->version == PFN_SCANRESULT_VERSION_V2) {
  3113. n_pfn_results = pfn_result_v2->count;
  3114. pnetinfo_v2 = (wl_pfn_net_info_v2_t *)pfn_result_v2->netinfo;
  3115. if (e->event_type == WLC_E_PFN_NET_LOST) {
  3116. WL_PNO(("Do Nothing %d\n", e->event_type));
  3117. return 0;
  3118. }
  3119. WL_INFORM_MEM(("PFN NET FOUND event. count:%d \n", n_pfn_results));
  3120. if (n_pfn_results > 0) {
  3121. int i;
  3122. if (n_pfn_results > MAX_PFN_LIST_COUNT)
  3123. n_pfn_results = MAX_PFN_LIST_COUNT;
  3124. bzero(&ssid, sizeof(ssid));
  3125. request = (struct cfg80211_scan_request *)MALLOCZ(cfg->osh,
  3126. sizeof(*request) + sizeof(*request->channels) * n_pfn_results);
  3127. channel = (struct ieee80211_channel *)MALLOCZ(cfg->osh,
  3128. (sizeof(struct ieee80211_channel) * n_pfn_results));
  3129. if (!request || !channel) {
  3130. WL_ERR(("No memory"));
  3131. err = -ENOMEM;
  3132. goto out_err;
  3133. }
  3134. request->wiphy = wiphy;
  3135. if (DBG_RING_ACTIVE(dhdp, DHD_EVENT_RING_ID)) {
  3136. alloc_len = sizeof(log_conn_event_t) + DOT11_MAX_SSID_LEN +
  3137. sizeof(uint16) + sizeof(int16);
  3138. event_data = (log_conn_event_t *)MALLOC(cfg->osh, alloc_len);
  3139. if (!event_data) {
  3140. WL_ERR(("%s: failed to allocate the log_conn_event_t with "
  3141. "length(%d)\n", __func__, alloc_len));
  3142. goto out_err;
  3143. }
  3144. tlv_len = 3 * sizeof(tlv_log);
  3145. event_data->tlvs = (tlv_log *)MALLOC(cfg->osh, tlv_len);
  3146. if (!event_data->tlvs) {
  3147. WL_ERR(("%s: failed to allocate the tlv_log with "
  3148. "length(%d)\n", __func__, tlv_len));
  3149. goto out_err;
  3150. }
  3151. }
  3152. for (i = 0; i < n_pfn_results; i++) {
  3153. netinfo_v2 = &pnetinfo_v2[i];
  3154. if (!netinfo_v2) {
  3155. WL_ERR(("Invalid netinfo ptr. index:%d", i));
  3156. err = -EINVAL;
  3157. goto out_err;
  3158. }
  3159. WL_PNO((">>> SSID:%s Channel:%d \n",
  3160. netinfo_v2->pfnsubnet.u.SSID,
  3161. netinfo_v2->pfnsubnet.channel));
  3162. /* PFN result doesn't have all the info which are required by the
  3163. * supplicant. (For e.g IEs) Do a target Escan so that sched scan
  3164. * results are reported via wl_inform_single_bss in the required
  3165. * format. Escan does require the scan request in the form of
  3166. * cfg80211_scan_request. For timebeing, create
  3167. * cfg80211_scan_request one out of the received PNO event.
  3168. */
  3169. ssid[i].ssid_len = MIN(DOT11_MAX_SSID_LEN,
  3170. netinfo_v2->pfnsubnet.SSID_len);
  3171. /* max ssid_len as in previous step DOT11_MAX_SSID_LEN is same
  3172. * as DOT11_MAX_SSID_LEN = 32
  3173. */
  3174. (void)memcpy_s(ssid[i].ssid, IEEE80211_MAX_SSID_LEN,
  3175. netinfo_v2->pfnsubnet.u.SSID, ssid[i].ssid_len);
  3176. request->n_ssids++;
  3177. channel_req = netinfo_v2->pfnsubnet.channel;
  3178. band = (channel_req <= CH_MAX_2G_CHANNEL) ? NL80211_BAND_2GHZ
  3179. : NL80211_BAND_5GHZ;
  3180. channel[i].center_freq =
  3181. ieee80211_channel_to_frequency(channel_req, band);
  3182. channel[i].band = band;
  3183. channel[i].flags |= IEEE80211_CHAN_NO_HT40;
  3184. request->channels[i] = &channel[i];
  3185. request->n_channels++;
  3186. if (DBG_RING_ACTIVE(dhdp, DHD_EVENT_RING_ID)) {
  3187. payload_len = sizeof(log_conn_event_t);
  3188. event_data->event = WIFI_EVENT_DRIVER_PNO_NETWORK_FOUND;
  3189. tlv_data = event_data->tlvs;
  3190. /* ssid */
  3191. tlv_data->tag = WIFI_TAG_SSID;
  3192. tlv_data->len = netinfo_v2->pfnsubnet.SSID_len;
  3193. (void)memcpy_s(tlv_data->value, DOT11_MAX_SSID_LEN,
  3194. ssid[i].ssid, ssid[i].ssid_len);
  3195. payload_len += TLV_LOG_SIZE(tlv_data);
  3196. tlv_data = TLV_LOG_NEXT(tlv_data);
  3197. /* channel */
  3198. tlv_data->tag = WIFI_TAG_CHANNEL;
  3199. tlv_data->len = sizeof(uint16);
  3200. (void)memcpy_s(tlv_data->value, sizeof(uint16),
  3201. &channel_req, sizeof(uint16));
  3202. payload_len += TLV_LOG_SIZE(tlv_data);
  3203. tlv_data = TLV_LOG_NEXT(tlv_data);
  3204. /* rssi */
  3205. tlv_data->tag = WIFI_TAG_RSSI;
  3206. tlv_data->len = sizeof(int16);
  3207. (void)memcpy_s(tlv_data->value, sizeof(uint16),
  3208. &netinfo_v2->RSSI, sizeof(int16));
  3209. payload_len += TLV_LOG_SIZE(tlv_data);
  3210. tlv_data = TLV_LOG_NEXT(tlv_data);
  3211. dhd_os_push_push_ring_data(dhdp, DHD_EVENT_RING_ID,
  3212. &event_data->event, payload_len);
  3213. }
  3214. }
  3215. /* assign parsed ssid array */
  3216. if (request->n_ssids)
  3217. request->ssids = &ssid[0];
  3218. if (wl_get_drv_status_all(cfg, SCANNING)) {
  3219. /* Abort any on-going scan */
  3220. wl_cfg80211_cancel_scan(cfg);
  3221. }
  3222. if (wl_get_p2p_status(cfg, DISCOVERY_ON)) {
  3223. WL_PNO((">>> P2P discovery was ON. Disabling it\n"));
  3224. err = wl_cfgp2p_discover_enable_search(cfg, false);
  3225. if (unlikely(err)) {
  3226. wl_clr_drv_status(cfg, SCANNING, ndev);
  3227. goto out_err;
  3228. }
  3229. p2p_scan(cfg) = false;
  3230. }
  3231. wl_set_drv_status(cfg, SCANNING, ndev);
  3232. #if FULL_ESCAN_ON_PFN_NET_FOUND
  3233. WL_PNO((">>> Doing Full ESCAN on PNO event\n"));
  3234. err = wl_do_escan(cfg, wiphy, ndev, NULL);
  3235. #else
  3236. WL_PNO((">>> Doing targeted ESCAN on PNO event\n"));
  3237. err = wl_do_escan(cfg, wiphy, ndev, request);
  3238. #endif // endif
  3239. if (err) {
  3240. wl_clr_drv_status(cfg, SCANNING, ndev);
  3241. goto out_err;
  3242. }
  3243. DBG_EVENT_LOG(dhdp, WIFI_EVENT_DRIVER_PNO_SCAN_REQUESTED);
  3244. cfg->sched_scan_running = TRUE;
  3245. }
  3246. else {
  3247. WL_ERR(("FALSE PNO Event. (pfn_count == 0) \n"));
  3248. }
  3249. } else {
  3250. WL_ERR(("Unsupported version %d, expected %d or %d\n", pfn_result_v1->version,
  3251. PFN_SCANRESULT_VERSION_V1, PFN_SCANRESULT_VERSION_V2));
  3252. return 0;
  3253. }
  3254. out_err:
  3255. if (request) {
  3256. MFREE(cfg->osh, request,
  3257. sizeof(*request) + sizeof(*request->channels) * n_pfn_results);
  3258. }
  3259. if (channel) {
  3260. MFREE(cfg->osh, channel,
  3261. (sizeof(struct ieee80211_channel) * n_pfn_results));
  3262. }
  3263. if (event_data) {
  3264. if (event_data->tlvs) {
  3265. MFREE(cfg->osh, event_data->tlvs, tlv_len);
  3266. }
  3267. MFREE(cfg->osh, event_data, alloc_len);
  3268. }
  3269. return err;
  3270. }
  3271. #endif /* WL_SCHED_SCAN */
  3272. #ifdef PNO_SUPPORT
  3273. s32
  3274. wl_notify_pfn_status(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
  3275. const wl_event_msg_t *e, void *data)
  3276. {
  3277. struct net_device *ndev = NULL;
  3278. #ifdef GSCAN_SUPPORT
  3279. void *ptr;
  3280. int send_evt_bytes = 0;
  3281. u32 event = be32_to_cpu(e->event_type);
  3282. struct wiphy *wiphy = bcmcfg_to_wiphy(cfg);
  3283. #endif /* GSCAN_SUPPORT */
  3284. WL_INFORM_MEM((">>> PNO Event\n"));
  3285. if (!data) {
  3286. WL_ERR(("Data received is NULL!\n"));
  3287. return 0;
  3288. }
  3289. ndev = cfgdev_to_wlc_ndev(cfgdev, cfg);
  3290. #ifdef GSCAN_SUPPORT
  3291. ptr = dhd_dev_process_epno_result(ndev, data, event, &send_evt_bytes);
  3292. if (ptr) {
  3293. wl_cfgvendor_send_async_event(wiphy, ndev,
  3294. GOOGLE_SCAN_EPNO_EVENT, ptr, send_evt_bytes);
  3295. MFREE(cfg->osh, ptr, send_evt_bytes);
  3296. }
  3297. if (!dhd_dev_is_legacy_pno_enabled(ndev))
  3298. return 0;
  3299. #endif /* GSCAN_SUPPORT */
  3300. #ifndef WL_SCHED_SCAN
  3301. mutex_lock(&cfg->usr_sync);
  3302. /* TODO: Use cfg80211_sched_scan_results(wiphy); */
  3303. CFG80211_DISCONNECTED(ndev, 0, NULL, 0, false, GFP_KERNEL);
  3304. mutex_unlock(&cfg->usr_sync);
  3305. #else
  3306. /* If cfg80211 scheduled scan is supported, report the pno results via sched
  3307. * scan results
  3308. */
  3309. wl_notify_sched_scan_results(cfg, ndev, e, data);
  3310. #endif /* WL_SCHED_SCAN */
  3311. return 0;
  3312. }
  3313. #endif /* PNO_SUPPORT */
  3314. #ifdef GSCAN_SUPPORT
  3315. s32
  3316. wl_notify_gscan_event(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
  3317. const wl_event_msg_t *e, void *data)
  3318. {
  3319. s32 err = 0;
  3320. u32 event = be32_to_cpu(e->event_type);
  3321. void *ptr = NULL;
  3322. int send_evt_bytes = 0;
  3323. int event_type;
  3324. struct net_device *ndev = cfgdev_to_wlc_ndev(cfgdev, cfg);
  3325. struct wiphy *wiphy = bcmcfg_to_wiphy(cfg);
  3326. u32 len = ntoh32(e->datalen);
  3327. u32 buf_len = 0;
  3328. switch (event) {
  3329. case WLC_E_PFN_BEST_BATCHING:
  3330. err = dhd_dev_retrieve_batch_scan(ndev);
  3331. if (err < 0) {
  3332. WL_ERR(("Batch retrieval already in progress %d\n", err));
  3333. } else {
  3334. event_type = WIFI_SCAN_THRESHOLD_NUM_SCANS;
  3335. if (data && len) {
  3336. event_type = *((int *)data);
  3337. }
  3338. wl_cfgvendor_send_async_event(wiphy, ndev,
  3339. GOOGLE_GSCAN_BATCH_SCAN_EVENT,
  3340. &event_type, sizeof(int));
  3341. }
  3342. break;
  3343. case WLC_E_PFN_SCAN_COMPLETE:
  3344. event_type = WIFI_SCAN_COMPLETE;
  3345. wl_cfgvendor_send_async_event(wiphy, ndev,
  3346. GOOGLE_SCAN_COMPLETE_EVENT,
  3347. &event_type, sizeof(int));
  3348. break;
  3349. case WLC_E_PFN_BSSID_NET_FOUND:
  3350. ptr = dhd_dev_hotlist_scan_event(ndev, data, &send_evt_bytes,
  3351. HOTLIST_FOUND, &buf_len);
  3352. if (ptr) {
  3353. wl_cfgvendor_send_hotlist_event(wiphy, ndev,
  3354. ptr, send_evt_bytes, GOOGLE_GSCAN_GEOFENCE_FOUND_EVENT);
  3355. dhd_dev_gscan_hotlist_cache_cleanup(ndev, HOTLIST_FOUND);
  3356. } else {
  3357. err = -ENOMEM;
  3358. }
  3359. break;
  3360. case WLC_E_PFN_BSSID_NET_LOST:
  3361. /* WLC_E_PFN_BSSID_NET_LOST is conflict shared with WLC_E_PFN_SCAN_ALLGONE
  3362. * We currently do not use WLC_E_PFN_SCAN_ALLGONE, so if we get it, ignore
  3363. */
  3364. if (len) {
  3365. ptr = dhd_dev_hotlist_scan_event(ndev, data, &send_evt_bytes,
  3366. HOTLIST_LOST, &buf_len);
  3367. if (ptr) {
  3368. wl_cfgvendor_send_hotlist_event(wiphy, ndev,
  3369. ptr, send_evt_bytes, GOOGLE_GSCAN_GEOFENCE_LOST_EVENT);
  3370. dhd_dev_gscan_hotlist_cache_cleanup(ndev, HOTLIST_LOST);
  3371. MFREE(cfg->osh, ptr, buf_len);
  3372. } else {
  3373. err = -ENOMEM;
  3374. }
  3375. } else {
  3376. err = -EINVAL;
  3377. }
  3378. break;
  3379. case WLC_E_PFN_GSCAN_FULL_RESULT:
  3380. ptr = dhd_dev_process_full_gscan_result(ndev, data, len, &send_evt_bytes);
  3381. if (ptr) {
  3382. wl_cfgvendor_send_async_event(wiphy, ndev,
  3383. GOOGLE_SCAN_FULL_RESULTS_EVENT, ptr, send_evt_bytes);
  3384. MFREE(cfg->osh, ptr, send_evt_bytes);
  3385. } else {
  3386. err = -ENOMEM;
  3387. }
  3388. break;
  3389. case WLC_E_PFN_SSID_EXT:
  3390. ptr = dhd_dev_process_epno_result(ndev, data, event, &send_evt_bytes);
  3391. if (ptr) {
  3392. wl_cfgvendor_send_async_event(wiphy, ndev,
  3393. GOOGLE_SCAN_EPNO_EVENT, ptr, send_evt_bytes);
  3394. MFREE(cfg->osh, ptr, send_evt_bytes);
  3395. } else {
  3396. err = -ENOMEM;
  3397. }
  3398. break;
  3399. default:
  3400. WL_ERR(("Unknown event %d\n", event));
  3401. break;
  3402. }
  3403. return err;
  3404. }
  3405. #endif /* GSCAN_SUPPORT */
  3406. void wl_cfg80211_set_passive_scan(struct net_device *dev, char *command)
  3407. {
  3408. struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
  3409. if (strcmp(command, "SCAN-ACTIVE") == 0) {
  3410. cfg->active_scan = 1;
  3411. } else if (strcmp(command, "SCAN-PASSIVE") == 0) {
  3412. cfg->active_scan = 0;
  3413. } else
  3414. WL_ERR(("Unknown command \n"));
  3415. return;
  3416. }