scan.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/scan.c#4
  3. */
  4. /*! \file "scan.c"
  5. \brief This file defines the scan profile and the processing function of
  6. scan result for SCAN Module.
  7. The SCAN Profile selection is part of SCAN MODULE and responsible for defining
  8. SCAN Parameters - e.g. MIN_CHANNEL_TIME, number of scan channels.
  9. In this file we also define the process of SCAN Result including adding, searching
  10. and removing SCAN record from the list.
  11. */
  12. /*
  13. ** Log: scan.c
  14. **
  15. ** 04 15 2014 eason.tsai
  16. ** [ALPS01510349] [6595][KK][HotKnot][Reboot][KE][p2pDevFsmRunEventScanDone]
  17. ** Sender reboot automatically with KE about p2pDevFsmRunEventScanDone.
  18. ** add debug msg for scan
  19. **
  20. ** 03 12 2014 eason.tsai
  21. ** [ALPS01070904] [Need Patch] [Volunteer Patch][MT6630][Driver]MT6630 Wi-Fi Patch
  22. ** revise for cfg80211 disconnect because of timeout
  23. **
  24. ** 08 09 2013 cp.wu
  25. ** [BORA00002253] [MT6630 Wi-Fi][Driver][Firmware] Add NLO and timeout mechanism to SCN module
  26. ** 1. integrate scheduled scan functionality
  27. ** 2. condition compilation for linux-3.4 & linux-3.8 compatibility
  28. ** 3. correct CMD queue access to reduce lock scope
  29. **
  30. ** 08 05 2013 terry.wu
  31. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  32. ** 1. Add SW rate definition
  33. ** 2. Add HW default rate selection logic from FW
  34. **
  35. ** 04 30 2013 eason.tsai
  36. ** [BORA00002255] [MT6630 Wi-Fi][Driver] develop
  37. ** update 11ac channel setting
  38. **
  39. ** 03 12 2013 tsaiyuan.hsu
  40. ** [BORA00002222] MT6630 unified MAC RXM
  41. ** remove hif_rx_hdr usage.
  42. **
  43. ** 03 08 2013 wh.su
  44. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  45. ** Remove non-used compiling flag and code
  46. **
  47. ** 02 19 2013 cp.wu
  48. ** [BORA00002227] [MT6630 Wi-Fi][Driver] Update for Makefile and HIFSYS modifications
  49. ** take use of GET_BSS_INFO_BY_INDEX() and MAX_BSS_INDEX macros
  50. ** for correctly indexing of BSS-INFO pointers
  51. **
  52. ** 01 30 2013 yuche.tsai
  53. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  54. ** Code first update.
  55. **
  56. ** 01 22 2013 cp.wu
  57. ** [BORA00002253] [MT6630 Wi-Fi][Driver][Firmware] Add NLO and timeout mechanism to SCN module
  58. ** modification for ucBssIndex migration
  59. **
  60. ** 01 16 2013 cp.wu
  61. ** [BORA00002253] [MT6630 Wi-Fi][Driver][Firmware] Add NLO and timeout mechanism to SCN module
  62. ** sync for MT6620/MT6628 main trunk change
  63. **
  64. ** 12 27 2012 cp.wu
  65. ** [BORA00002253] [MT6630 Wi-Fi][Driver][Firmware] Add NLO and timeout mechanism to SCN module
  66. ** sync. for AP timestamp reset detection
  67. **
  68. ** 10 25 2012 cp.wu
  69. ** [BORA00002227] [MT6630 Wi-Fi][Driver] Update for Makefile and HIFSYS modifications
  70. ** sync with MT6630 HIFSYS update.
  71. **
  72. ** 09 17 2012 cm.chang
  73. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  74. ** Duplicate source from MT6620 v2.3 driver branch
  75. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  76. **
  77. ** 08 24 2012 cp.wu
  78. ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
  79. ** .
  80. **
  81. ** 08 24 2012 cp.wu
  82. ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
  83. ** cfg80211 support merge back from ALPS.JB to DaVinci - MT6620 Driver v2.3 branch.
  84. *
  85. * 07 17 2012 yuche.tsai
  86. * NULL
  87. * Let netdev bring up.
  88. *
  89. * 07 17 2012 yuche.tsai
  90. * NULL
  91. * Compile no error before trial run.
  92. *
  93. * 06 25 2012 cp.wu
  94. * [WCXRP00001258] [MT6620][MT5931][MT6628][Driver] Do not use stale scan result for deciding connection target
  95. * drop off scan result which is older than 5 seconds when choosing which BSS to join
  96. *
  97. * 03 02 2012 terry.wu
  98. * NULL
  99. * Sync CFG80211 modification from branch 2,2.
  100. *
  101. * 01 16 2012 cp.wu
  102. * [WCXRP00001169] [MT6620 Wi-Fi][Driver] API and behavior modification for preferred band
  103. * configuration with corresponding network configuration
  104. * correct typo.
  105. *
  106. * 01 16 2012 cp.wu
  107. * [MT6620 Wi-Fi][Driver] API and behavior modification for preferred band configuration
  108. * with corresponding network configuration
  109. * add wlanSetPreferBandByNetwork() for glue layer to invoke for setting preferred
  110. * band configuration corresponding to network type.
  111. *
  112. * 12 05 2011 cp.wu
  113. * [WCXRP00001131] [MT6620 Wi-Fi][Driver][AIS] Implement connect-by-BSSID path
  114. * add CONNECT_BY_BSSID policy
  115. *
  116. * 11 23 2011 cp.wu
  117. * [WCXRP00001123] [MT6620 Wi-Fi][Driver] Add option to disable beacon content change detection
  118. * add compile option to disable beacon content change detection.
  119. *
  120. * 11 04 2011 cp.wu
  121. * [WCXRP00001085] [MT6628 Wi-Fi][Driver] deprecate old BSS-DESC if timestamp
  122. * is reset with received beacon/probe response frames
  123. * deprecate old BSS-DESC when timestamp in received beacon/probe response frames showed a smaller value than before
  124. *
  125. * 10 11 2011 cm.chang
  126. * [WCXRP00001031] [All Wi-Fi][Driver] Check HT IE length to avoid wrong SCO parameter
  127. * Ignore HT OP IE if its length field is not valid
  128. *
  129. * 09 30 2011 cp.wu
  130. * [WCXRP00001021] [MT5931][Driver] Correct scan result generation for conversion between BSS type and operation mode
  131. * correct type casting issue.
  132. *
  133. * 08 23 2011 yuche.tsai
  134. * NULL
  135. * Fix multicast address list issue.
  136. *
  137. * 08 11 2011 cp.wu
  138. * [WCXRP00000830] [MT6620 Wi-Fi][Firmware] Use MDRDY counter to detect empty channel for shortening scan time
  139. * sparse channel detection:
  140. * driver: collect sparse channel information with scan-done event
  141. *
  142. * 08 10 2011 cp.wu
  143. * [WCXRP00000922] [MT6620 Wi-Fi][Driver] traverse whole BSS-DESC list for removing
  144. * traverse whole BSS-DESC list because BSSID is not unique anymore.
  145. *
  146. * 07 12 2011 cp.wu
  147. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple
  148. * SSID settings to work around some tricky AP which use space character as hidden SSID
  149. * for multiple BSS descriptior detecting issue:
  150. * 1) check BSSID for infrastructure network
  151. * 2) check SSID for AdHoc network
  152. *
  153. * 07 12 2011 cp.wu
  154. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple
  155. * SSID settings to work around some tricky AP which use space character as hidden SSID
  156. * check for BSSID for beacons used to update DTIM
  157. *
  158. * 07 12 2011 cp.wu
  159. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple
  160. * SSID settings to work around some tricky AP which use space character as hidden SSID
  161. * do not check BSS descriptor for connected flag due to linksys's hidden
  162. * SSID will use another BSS descriptor and never connected
  163. *
  164. * 07 11 2011 cp.wu
  165. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple
  166. * SSID settings to work around some tricky AP which use space character as hidden SSID
  167. * just pass beacons with the same BSSID.
  168. *
  169. * 07 11 2011 wh.su
  170. * [WCXRP00000849] [MT6620 Wi-Fi][Driver] Remove some of the WAPI define
  171. * for make sure the value is initialize, for customer not enable WAPI
  172. * For make sure wapi initial value is set.
  173. *
  174. * 06 28 2011 cp.wu
  175. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple
  176. * SSID settings to work around some tricky AP which use space character as hidden SSID
  177. * Do not check for SSID as beacon content change due to the existence of
  178. * single BSSID with multiple SSID AP configuration
  179. *
  180. * 06 27 2011 cp.wu
  181. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple
  182. * SSID settings to work around some tricky AP which use space character as hidden SSID
  183. * 1. correct logic
  184. * 2. replace only BSS-DESC which doesn't have a valid SSID.
  185. *
  186. * 06 27 2011 cp.wu
  187. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple SSID
  188. * settings to work around some tricky AP which use space character as hidden SSID
  189. * remove unused temporal variable reference.
  190. *
  191. * 06 27 2011 cp.wu
  192. * [WCXRP00000815] [MT6620 Wi-Fi][Driver] allow single BSSID with multiple SSID
  193. * settings to work around some tricky AP which use space character as hidden SSID
  194. * allow to have a single BSSID with multiple SSID to be presented in scanning result
  195. *
  196. * 06 02 2011 cp.wu
  197. * [WCXRP00000757] [MT6620 Wi-Fi][Driver][SCN] take use of RLM API to filter out BSS in disallowed channels
  198. * filter out BSS in disallowed channel by
  199. * 1. do not add to scan result array if BSS is at disallowed channel
  200. * 2. do not allow to search for BSS-DESC in disallowed channels
  201. *
  202. * 05 02 2011 cm.chang
  203. * [WCXRP00000691] [MT6620 Wi-Fi][Driver] Workaround about AP's wrong HT capability IE to have wrong channel number
  204. * Refine range of valid channel number
  205. *
  206. * 05 02 2011 cp.wu
  207. * [MT6620 Wi-Fi][Driver] Take parsed result for channel information instead of
  208. * hardware channel number passed from firmware domain
  209. * take parsed result for generating scanning result with channel information.
  210. *
  211. * 05 02 2011 cm.chang
  212. * [WCXRP00000691] [MT6620 Wi-Fi][Driver] Workaround about AP's wrong HT capability IE to have wrong channel number
  213. * Check if channel is valided before record ing BSS channel
  214. *
  215. * 04 18 2011 terry.wu
  216. * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
  217. * Remove flag CFG_WIFI_DIRECT_MOVED.
  218. *
  219. * 04 14 2011 cm.chang
  220. * [WCXRP00000634] [MT6620 Wi-Fi][Driver][FW] 2nd BSS will not support 40MHz bandwidth for concurrency
  221. * .
  222. *
  223. * 04 12 2011 eddie.chen
  224. * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
  225. * Fix the sta index in processing security frame
  226. * Simple flow control for TC4 to avoid mgt frames for PS STA to occupy the TC4
  227. * Add debug message.
  228. *
  229. * 03 25 2011 yuche.tsai
  230. * NULL
  231. * Always update Bss Type, for Bss Type for P2P Network is changing every time.
  232. *
  233. * 03 23 2011 yuche.tsai
  234. * NULL
  235. * Fix concurrent issue when AIS scan result would overwrite p2p scan result.
  236. *
  237. * 03 14 2011 cp.wu
  238. * [WCXRP00000535] [MT6620 Wi-Fi][Driver] Fixed channel operation when AIS and Tethering are operating concurrently
  239. * filtering out other BSS coming from adjacent channels
  240. *
  241. * 03 11 2011 chinglan.wang
  242. * [WCXRP00000537] [MT6620 Wi-Fi][Driver] Can not connect to 802.11b/g/n mixed AP with WEP security.
  243. * .
  244. *
  245. * 03 11 2011 cp.wu
  246. * [WCXRP00000535] [MT6620 Wi-Fi][Driver] Fixed channel operation when AIS and Tethering are operating concurrently
  247. * When fixed channel operation is necessary, AIS-FSM would scan and only connect for BSS on the specific channel
  248. *
  249. * 02 24 2011 cp.wu
  250. * [WCXRP00000490] [MT6620 Wi-Fi][Driver][Win32] modify kalMsleep() implementation because NdisMSleep()
  251. * won't sleep long enough for specified interval such as 500ms
  252. * implement beacon change detection by checking SSID and supported rate.
  253. *
  254. * 02 22 2011 yuche.tsai
  255. * [WCXRP00000480] [Volunteer Patch][MT6620][Driver] WCS IE format issue
  256. * Fix WSC big endian issue.
  257. *
  258. * 02 21 2011 terry.wu
  259. * [WCXRP00000476] [MT6620 Wi-Fi][Driver] Clean P2P scan list while removing P2P
  260. * Clean P2P scan list while removing P2P.
  261. *
  262. * 01 27 2011 yuche.tsai
  263. * [WCXRP00000399] [Volunteer Patch][MT6620/MT5931][Driver] Fix scan side effect after P2P module separate.
  264. * Fix scan channel extension issue when p2p module is not registered.
  265. *
  266. * 01 26 2011 cm.chang
  267. * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
  268. * .
  269. *
  270. * 01 21 2011 cp.wu
  271. * [WCXRP00000380] [MT6620 Wi-Fi][Driver] SSID information should come from buffered
  272. * BSS_DESC_T rather than using beacon-carried information
  273. * SSID should come from buffered prBssDesc rather than beacon-carried information
  274. *
  275. * 01 14 2011 yuche.tsai
  276. * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
  277. * Fix compile error.
  278. *
  279. * 01 14 2011 yuche.tsai
  280. * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
  281. * Memfree for P2P Descriptor & P2P Descriptor List.
  282. *
  283. * 01 14 2011 yuche.tsai
  284. * [WCXRP00000352] [Volunteer Patch][MT6620][Driver] P2P Statsion Record Client List Issue
  285. * Free P2P Descriptor List & Descriptor under BSS Descriptor.
  286. *
  287. * 01 04 2011 cp.wu
  288. * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc
  289. * and vmalloc implementations to ease physically continuous memory demands
  290. * 1) correct typo in scan.c
  291. * 2) TX descriptors, RX descriptos and management buffer should use virtually
  292. * continuous buffer instead of physically contineous one
  293. *
  294. * 01 04 2011 cp.wu
  295. * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc
  296. * and vmalloc implementations to ease physically continuous memory demands
  297. * separate kalMemAlloc() into virtually-continuous and physically-continuous type to ease slab system pressure
  298. *
  299. * 12 31 2010 cp.wu
  300. * [WCXRP00000327] [MT6620 Wi-Fi][Driver] Improve HEC WHQA 6972 workaround coverage in driver side
  301. * while being unloaded, clear all pending interrupt then set LP-own to firmware
  302. *
  303. * 12 21 2010 cp.wu
  304. * [WCXRP00000280] [MT6620 Wi-Fi][Driver] Enable BSS selection with best RCPI policy in SCN module
  305. * SCN: enable BEST RSSI selection policy support
  306. *
  307. * 11 29 2010 cp.wu
  308. * [WCXRP00000210] [MT6620 Wi-Fi][Driver][FW] Set RCPI value in STA_REC
  309. * for initial TX rate selection of auto-rate algorithm
  310. * update ucRcpi of STA_RECORD_T for AIS when
  311. * 1) Beacons for IBSS merge is received
  312. * 2) Associate Response for a connecting peer is received
  313. *
  314. * 11 03 2010 wh.su
  315. * [WCXRP00000124] [MT6620 Wi-Fi] [Driver] Support the dissolve P2P Group
  316. * Refine the HT rate disallow TKIP pairwise cipher .
  317. *
  318. * 10 12 2010 cp.wu
  319. * [WCXRP00000091] [MT6620 Wi-Fi][Driver] Add scanning logic to filter out
  320. * beacons which is received on the folding frequency
  321. * trust HT IE if available for 5GHz band
  322. *
  323. * 10 11 2010 cp.wu
  324. * [WCXRP00000091] [MT6620 Wi-Fi][Driver] Add scanning logic to filter out
  325. * beacons which is received on the folding frequency
  326. * add timing and strenght constraint for filtering out beacons with same SSID/TA but received on different channels
  327. *
  328. * 10 08 2010 wh.su
  329. * [WCXRP00000085] [MT6620 Wif-Fi] [Driver] update the modified p2p state machine
  330. * update the frog's new p2p state machine.
  331. *
  332. * 10 01 2010 yuche.tsai
  333. * NULL
  334. * [MT6620 P2P] Fix Big Endian Issue when parse P2P device name TLV.
  335. *
  336. * 09 24 2010 cp.wu
  337. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  338. * eliminate unused variables which lead gcc to argue
  339. *
  340. * 09 08 2010 cp.wu
  341. * NULL
  342. * use static memory pool for storing IEs of scanning result.
  343. *
  344. * 09 07 2010 yuche.tsai
  345. * NULL
  346. * When indicate scan result, append IE buffer information in the scan result.
  347. *
  348. * 09 03 2010 yuche.tsai
  349. * NULL
  350. * 1. Update Beacon RX count when running SLT.
  351. * 2. Ignore Beacon when running SLT, would not update information from Beacon.
  352. *
  353. * 09 03 2010 kevin.huang
  354. * NULL
  355. * Refine #include sequence and solve recursive/nested #include issue
  356. *
  357. * 08 31 2010 kevin.huang
  358. * NULL
  359. * Use LINK LIST operation to process SCAN result
  360. *
  361. * 08 29 2010 yuche.tsai
  362. * NULL
  363. * 1. Fix P2P Descriptor List to be a link list, to avoid link corrupt after Bss Descriptor Free.
  364. * 2.. Fix P2P Device Name Length BE issue.
  365. *
  366. * 08 23 2010 yuche.tsai
  367. * NULL
  368. * Add P2P Device Found Indication to supplicant
  369. *
  370. * 08 20 2010 cp.wu
  371. * NULL
  372. * reset BSS_DESC_T variables before parsing IE due to peer might have been reconfigured.
  373. *
  374. * 08 20 2010 yuche.tsai
  375. * NULL
  376. * Workaround for P2P Descriptor Infinite loop issue.
  377. *
  378. * 08 16 2010 cp.wu
  379. * NULL
  380. * Replace CFG_SUPPORT_BOW by CFG_ENABLE_BT_OVER_WIFI.
  381. * There is no CFG_SUPPORT_BOW in driver domain source.
  382. *
  383. * 08 16 2010 yuche.tsai
  384. * NULL
  385. * Modify code of processing Probe Resonse frame for P2P.
  386. *
  387. * 08 12 2010 yuche.tsai
  388. * NULL
  389. * Add function to get P2P descriptor of BSS descriptor directly.
  390. *
  391. * 08 11 2010 yuche.tsai
  392. * NULL
  393. * Modify Scan result processing for P2P module.
  394. *
  395. * 08 05 2010 yuche.tsai
  396. * NULL
  397. * Update P2P Device Discovery result add function.
  398. *
  399. * 08 03 2010 cp.wu
  400. * NULL
  401. * surpress compilation warning.
  402. *
  403. * 07 26 2010 yuche.tsai
  404. *
  405. * Add support for Probe Request & Response parsing.
  406. *
  407. * 07 21 2010 cp.wu
  408. *
  409. * 1) change BG_SCAN to ONLINE_SCAN for consistent term
  410. * 2) only clear scanning result when scan is permitted to do
  411. *
  412. * 07 21 2010 yuche.tsai
  413. *
  414. * Fix compile error for SCAN module while disabling P2P feature.
  415. *
  416. * 07 21 2010 yuche.tsai
  417. *
  418. * Add P2P Scan & Scan Result Parsing & Saving.
  419. *
  420. * 07 19 2010 wh.su
  421. *
  422. * update for security supporting.
  423. *
  424. * 07 19 2010 cp.wu
  425. *
  426. * [WPD00003833] [MT6620 and MT5931] Driver migration.
  427. * Add Ad-Hoc support to AIS-FSM
  428. *
  429. * 07 19 2010 cp.wu
  430. *
  431. * [WPD00003833] [MT6620 and MT5931] Driver migration.
  432. * SCN module is now able to handle multiple concurrent scanning requests
  433. *
  434. * 07 15 2010 cp.wu
  435. *
  436. * [WPD00003833] [MT6620 and MT5931] Driver migration.
  437. * driver no longer generates probe request frames
  438. *
  439. * 07 14 2010 cp.wu
  440. *
  441. * [WPD00003833] [MT6620 and MT5931] Driver migration.
  442. * remove timer in DRV-SCN.
  443. *
  444. * 07 09 2010 cp.wu
  445. *
  446. * 1) separate AIS_FSM state for two kinds of scanning. (OID triggered scan, and scan-for-connection)
  447. * 2) eliminate PRE_BSS_DESC_T, Beacon/PrebResp is now parsed in single pass
  448. * 3) implment DRV-SCN module, currently only accepts single scan request,
  449. * other request will be directly dropped by returning BUSY
  450. *
  451. * 07 08 2010 cp.wu
  452. *
  453. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  454. *
  455. * 07 08 2010 cp.wu
  456. * [WPD00003833][MT6620 and MT5931] Driver migration
  457. * take use of RLM module for parsing/generating HT IEs for 11n capability
  458. *
  459. * 07 05 2010 cp.wu
  460. * [WPD00003833][MT6620 and MT5931] Driver migration
  461. * 1) ignore RSN checking when RSN is not turned on.
  462. * 2) set STA-REC deactivation callback as NULL
  463. * 3) add variable initialization API based on PHY configuration
  464. *
  465. * 07 05 2010 cp.wu
  466. * [WPD00003833][MT6620 and MT5931] Driver migration
  467. * correct BSS_DESC_T initialization after allocated.
  468. *
  469. * 07 02 2010 cp.wu
  470. * [WPD00003833][MT6620 and MT5931] Driver migration
  471. * 1) for event packet, no need to fill RFB.
  472. * 2) when wlanAdapterStart() failed, no need to initialize state machines
  473. * 3) after Beacon/ProbeResp parsing, corresponding BSS_DESC_T should be marked as IE-parsed
  474. *
  475. * 07 01 2010 cp.wu
  476. * [WPD00003833][MT6620 and MT5931] Driver migration
  477. * add scan uninitialization procedure
  478. *
  479. * 06 30 2010 cp.wu
  480. * [WPD00003833][MT6620 and MT5931] Driver migration
  481. * if beacon/probe-resp is received in 2.4GHz bands and there is ELEM_ID_DS_PARAM_SET IE available,
  482. * trust IE instead of RMAC information
  483. *
  484. * 06 29 2010 cp.wu
  485. * [WPD00003833][MT6620 and MT5931] Driver migration
  486. * 1) sync to. CMD/EVENT document v0.03
  487. * 2) simplify DTIM period parsing in scan.c only, bss.c no longer parses it again.
  488. * 3) send command packet to indicate FW-PM after
  489. * a) 1st beacon is received after AIS has connected to an AP
  490. * b) IBSS-ALONE has been created
  491. * c) IBSS-MERGE has occurred
  492. *
  493. * 06 28 2010 cp.wu
  494. * [WPD00003833][MT6620 and MT5931] Driver migration
  495. * send MMPDU in basic rate.
  496. *
  497. * 06 25 2010 cp.wu
  498. * [WPD00003833][MT6620 and MT5931] Driver migration
  499. * modify Beacon/ProbeResp to complete parsing,
  500. * because host software has looser memory usage restriction
  501. *
  502. * 06 23 2010 cp.wu
  503. * [WPD00003833][MT6620 and MT5931] Driver migration
  504. * integrate .
  505. *
  506. * 06 22 2010 cp.wu
  507. * [WPD00003833][MT6620 and MT5931] Driver migration
  508. * comment out RLM APIs by CFG_RLM_MIGRATION.
  509. *
  510. * 06 21 2010 yuche.tsai
  511. * [WPD00003839][MT6620 5931][P2P] Feature migration
  512. * Update P2P Function call.
  513. *
  514. * 06 21 2010 cp.wu
  515. * [WPD00003833][MT6620 and MT5931] Driver migration
  516. * RSN/PRIVACY compilation flag awareness correction
  517. *
  518. * 06 21 2010 cp.wu
  519. * [WPD00003833][MT6620 and MT5931] Driver migration
  520. * specify correct value for management frames.
  521. *
  522. * 06 18 2010 cm.chang
  523. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  524. * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
  525. *
  526. * 06 18 2010 wh.su
  527. * [WPD00003840][MT6620 5931] Security migration
  528. * migration from MT6620 firmware.
  529. *
  530. * 06 17 2010 yuche.tsai
  531. * [WPD00003839][MT6620 5931][P2P] Feature migration
  532. * Fix compile error when enable P2P function.
  533. *
  534. * 06 15 2010 cp.wu
  535. * [WPD00003833][MT6620 and MT5931] Driver migration
  536. * correct when ADHOC support is turned on.
  537. *
  538. * 06 15 2010 cp.wu
  539. * [WPD00003833][MT6620 and MT5931] Driver migration
  540. * add scan.c.
  541. *
  542. * 06 04 2010 george.huang
  543. * [BORA00000678][MT6620]WiFi LP integration
  544. * [PM] Support U-APSD for STA mode
  545. *
  546. * 05 28 2010 wh.su
  547. * [BORA00000680][MT6620] Support the statistic for Microsoft os query
  548. * adding the TKIP disallow join a HT AP code.
  549. *
  550. * 05 14 2010 kevin.huang
  551. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  552. * Add more chance of JOIN retry for BG_SCAN
  553. *
  554. * 05 12 2010 kevin.huang
  555. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  556. * Add Power Management - Legacy PS-POLL support.
  557. *
  558. * 04 29 2010 wh.su
  559. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  560. * adjsut the pre-authentication code.
  561. *
  562. * 04 27 2010 kevin.huang
  563. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  564. * Add Set Slot Time and Beacon Timeout Support for AdHoc Mode
  565. *
  566. * 04 24 2010 cm.chang
  567. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  568. * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
  569. *
  570. * 04 19 2010 kevin.huang
  571. * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
  572. * Add Beacon Timeout Support and will send Null frame to diagnose connection
  573. *
  574. * 04 13 2010 kevin.huang
  575. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  576. * Add new HW CH macro support
  577. *
  578. * 04 06 2010 wh.su
  579. * [BORA00000680][MT6620] Support the statistic for Microsoft os query
  580. * fixed the firmware return the broadcast frame at wrong tc.
  581. *
  582. * 03 29 2010 wh.su
  583. * [BORA00000605][WIFISYS] Phase3 Integration
  584. * let the rsn wapi IE always parsing.
  585. *
  586. * 03 24 2010 cm.chang
  587. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  588. * Not carry HT cap when being associated with b/g only AP
  589. *
  590. * 03 18 2010 kevin.huang
  591. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  592. * Solve the compile warning for 'return non-void' function
  593. *
  594. * 03 16 2010 kevin.huang
  595. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  596. * Add AdHoc Mode
  597. *
  598. * 03 10 2010 kevin.huang
  599. * [BORA00000654][WIFISYS][New Feature] CNM Module - Ch Manager Support
  600. *
  601. * * * * * * * * * * * * * * * * Add Channel Manager for arbitration of JOIN and SCAN Req
  602. *
  603. * 03 03 2010 wh.su
  604. * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
  605. * move the AIS specific variable for security to AIS specific structure.
  606. *
  607. * 03 01 2010 wh.su
  608. * [BORA00000605][WIFISYS] Phase3 Integration
  609. * Refine the variable and parameter for security.
  610. *
  611. * 02 26 2010 kevin.huang
  612. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  613. * Fix No PKT_INFO_T issue
  614. *
  615. * 02 26 2010 kevin.huang
  616. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  617. * Update outgoing ProbeRequest Frame's TX data rate
  618. *
  619. * 02 23 2010 wh.su
  620. * [BORA00000592][MT6620 Wi-Fi] Adding the security related code for driver
  621. * refine the scan procedure, reduce the WPA and WAPI IE parsing, and move the parsing to the time for join.
  622. *
  623. * 02 23 2010 kevin.huang
  624. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  625. * Add support scan channel 1~14 and update scan result's frequency infou1rwduu`wvpghlqg|n`slk+mpdkb
  626. *
  627. * 02 04 2010 kevin.huang
  628. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  629. * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
  630. *
  631. * 01 27 2010 wh.su
  632. * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
  633. * add and fixed some security function.
  634. *
  635. * 01 22 2010 cm.chang
  636. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  637. * Support protection and bandwidth switch
  638. *
  639. * 01 20 2010 kevin.huang
  640. * [BORA00000569][WIFISYS] Phase 2 Integration Test
  641. * Add PHASE_2_INTEGRATION_WORK_AROUND and CFG_SUPPORT_BCM flags
  642. *
  643. * 01 11 2010 kevin.huang
  644. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  645. * Add Deauth and Disassoc Handler
  646. *
  647. * 01 08 2010 kevin.huang
  648. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  649. *
  650. * Refine Beacon processing, add read RF channel from RX Status
  651. *
  652. * 01 04 2010 tehuang.liu
  653. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  654. * For working out the first connection Chariot-verified version
  655. *
  656. * 12 18 2009 cm.chang
  657. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  658. * .
  659. *
  660. * Dec 12 2009 mtk01104
  661. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  662. * Modify u2EstimatedExtraIELen for probe request
  663. *
  664. * Dec 9 2009 mtk01104
  665. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  666. * Add HT cap IE to probe request
  667. *
  668. * Dec 7 2009 mtk01461
  669. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  670. * Fix lint warning
  671. *
  672. *
  673. * Dec 3 2009 mtk01461
  674. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  675. * Update the process of SCAN Result by adding more Phy Attributes
  676. *
  677. * Dec 1 2009 mtk01088
  678. * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
  679. * adjust the function and code for meet the new define
  680. *
  681. * Nov 30 2009 mtk01461
  682. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  683. * Rename u4RSSI to i4RSSI
  684. *
  685. * Nov 30 2009 mtk01461
  686. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  687. * Report event of scan result to host
  688. *
  689. * Nov 26 2009 mtk01461
  690. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  691. * Fix SCAN Record update
  692. *
  693. * Nov 24 2009 mtk01461
  694. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  695. * Revise MGMT Handler with Retain Status and Integrate with TXM
  696. *
  697. * Nov 23 2009 mtk01461
  698. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  699. * Add (Ext)Support Rate Set IE to ProbeReq
  700. *
  701. * Nov 20 2009 mtk02468
  702. * [BORA00000337] To check in codes for FPGA emulation
  703. * Removed the use of SW_RFB->u2FrameLength
  704. *
  705. * Nov 20 2009 mtk01461
  706. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  707. * Fix uninitial aucMacAddress[] for ProbeReq
  708. *
  709. * Nov 16 2009 mtk01461
  710. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  711. * Add scanSearchBssDescByPolicy()
  712. *
  713. * Nov 5 2009 mtk01461
  714. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  715. * Add Send Probe Request Frame
  716. *
  717. * Oct 30 2009 mtk01461
  718. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  719. *
  720. */
  721. /*******************************************************************************
  722. * C O M P I L E R F L A G S
  723. ********************************************************************************
  724. */
  725. /*******************************************************************************
  726. * E X T E R N A L R E F E R E N C E S
  727. ********************************************************************************
  728. */
  729. #include "precomp.h"
  730. /*******************************************************************************
  731. * C O N S T A N T S
  732. ********************************************************************************
  733. */
  734. #define REPLICATED_BEACON_TIME_THRESHOLD (3000)
  735. #define REPLICATED_BEACON_FRESH_PERIOD (10000)
  736. #define REPLICATED_BEACON_STRENGTH_THRESHOLD (32)
  737. #define ROAMING_NO_SWING_RCPI_STEP (10)
  738. /*******************************************************************************
  739. * D A T A T Y P E S
  740. ********************************************************************************
  741. */
  742. /*******************************************************************************
  743. * P U B L I C D A T A
  744. ********************************************************************************
  745. */
  746. /*******************************************************************************
  747. * P R I V A T E D A T A
  748. ********************************************************************************
  749. */
  750. /*******************************************************************************
  751. * M A C R O S
  752. ********************************************************************************
  753. */
  754. /*******************************************************************************
  755. * F U N C T I O N D E C L A R A T I O N S
  756. ********************************************************************************
  757. */
  758. /*******************************************************************************
  759. * F U N C T I O N S
  760. ********************************************************************************
  761. */
  762. /*----------------------------------------------------------------------------*/
  763. /*!
  764. * @brief This function is used by SCN to initialize its variables
  765. *
  766. * @param (none)
  767. *
  768. * @return (none)
  769. */
  770. /*----------------------------------------------------------------------------*/
  771. VOID scnInit(IN P_ADAPTER_T prAdapter)
  772. {
  773. P_SCAN_INFO_T prScanInfo;
  774. P_BSS_DESC_T prBSSDesc;
  775. PUINT_8 pucBSSBuff;
  776. UINT_32 i;
  777. ASSERT(prAdapter);
  778. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  779. pucBSSBuff = &prScanInfo->aucScanBuffer[0];
  780. DBGLOG(SCN, INFO, "->scnInit()\n");
  781. /* 4 <1> Reset STATE and Message List */
  782. prScanInfo->eCurrentState = SCAN_STATE_IDLE;
  783. prScanInfo->rLastScanCompletedTime = (OS_SYSTIME) 0;
  784. LINK_INITIALIZE(&prScanInfo->rPendingMsgList);
  785. /* 4 <2> Reset link list of BSS_DESC_T */
  786. kalMemZero((PVOID) pucBSSBuff, SCN_MAX_BUFFER_SIZE);
  787. LINK_INITIALIZE(&prScanInfo->rFreeBSSDescList);
  788. LINK_INITIALIZE(&prScanInfo->rBSSDescList);
  789. for (i = 0; i < CFG_MAX_NUM_BSS_LIST; i++) {
  790. prBSSDesc = (P_BSS_DESC_T) pucBSSBuff;
  791. LINK_INSERT_TAIL(&prScanInfo->rFreeBSSDescList, &prBSSDesc->rLinkEntry);
  792. pucBSSBuff += ALIGN_4(sizeof(BSS_DESC_T));
  793. }
  794. /* Check if the memory allocation consist with this initialization function */
  795. ASSERT(((ULONG) pucBSSBuff - (ULONG)&prScanInfo->aucScanBuffer[0]) == SCN_MAX_BUFFER_SIZE);
  796. /* reset freest channel information */
  797. prScanInfo->fgIsSparseChannelValid = FALSE;
  798. /* reset NLO state */
  799. prScanInfo->fgNloScanning = FALSE;
  800. #if CFG_SUPPORT_SCN_PSCN
  801. prScanInfo->fgPscnOnnning = FALSE;
  802. prScanInfo->prPscnParam = NULL;
  803. prScanInfo->fgGScnConfigSet = FALSE;
  804. prScanInfo->fgGscnGetResWaiting = FALSE;
  805. prScanInfo->fgGScnParamSet = FALSE;
  806. prScanInfo->prPscnParam = kalMemAlloc(sizeof(PSCN_PARAM_T), VIR_MEM_TYPE);
  807. kalMemZero(prScanInfo->prPscnParam, sizeof(PSCN_PARAM_T));
  808. prScanInfo->eCurrentPSCNState = PSCN_IDLE;
  809. cnmTimerInitTimer(prAdapter,
  810. &prScanInfo->rWaitForGscanResutsTimer,
  811. (PFN_MGMT_TIMEOUT_FUNC) scnGscnGetResultReplyCheckTimeout, (ULONG) NULL);
  812. #endif
  813. cnmTimerInitTimer(prAdapter,
  814. &prScanInfo->rScanDoneTimer, (PFN_MGMT_TIMEOUT_FUNC) scnScanDoneTimeout, (ULONG) NULL);
  815. prScanInfo->ucScanDoneTimeoutCnt = 0;
  816. } /* end of scnInit() */
  817. VOID scnFreeAllPendingScanRquests(IN P_ADAPTER_T prAdapter)
  818. {
  819. P_SCAN_INFO_T prScanInfo;
  820. P_MSG_HDR_T prMsgHdr;
  821. P_MSG_SCN_SCAN_REQ prScanReqMsg;
  822. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  823. /* check for pending scanning requests */
  824. while (!LINK_IS_EMPTY(&(prScanInfo->rPendingMsgList))) {
  825. /* load next message from pending list as scan parameters */
  826. LINK_REMOVE_HEAD(&(prScanInfo->rPendingMsgList), prMsgHdr, P_MSG_HDR_T);
  827. if (prMsgHdr) {
  828. prScanReqMsg = (P_MSG_SCN_SCAN_REQ) prMsgHdr;
  829. DBGLOG(SCN, INFO,
  830. "free scan request eMsgId[%d] ucSeqNum [%d] BSSID[%d]!!\n", prMsgHdr->eMsgId,
  831. prScanReqMsg->ucSeqNum, prScanReqMsg->ucBssIndex);
  832. cnmMemFree(prAdapter, prMsgHdr);
  833. } else {
  834. /* should not deliver to this function */
  835. ASSERT(0);
  836. }
  837. /* switch to next state */
  838. }
  839. }
  840. /*----------------------------------------------------------------------------*/
  841. /*!
  842. * @brief This function is used by SCN to uninitialize its variables
  843. *
  844. * @param (none)
  845. *
  846. * @return (none)
  847. */
  848. /*----------------------------------------------------------------------------*/
  849. VOID scnUninit(IN P_ADAPTER_T prAdapter)
  850. {
  851. P_SCAN_INFO_T prScanInfo;
  852. ASSERT(prAdapter);
  853. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  854. DBGLOG(SCN, INFO, "->scnUninit()\n");
  855. scnFreeAllPendingScanRquests(prAdapter);
  856. DBGLOG(SCN, INFO, "scnFreeAllPendingScanrRquests !!\n");
  857. /* 4 <1> Reset STATE and Message List */
  858. prScanInfo->eCurrentState = SCAN_STATE_IDLE;
  859. prScanInfo->rLastScanCompletedTime = (OS_SYSTIME) 0;
  860. /* NOTE(Kevin): Check rPendingMsgList ? */
  861. /* 4 <2> Reset link list of BSS_DESC_T */
  862. LINK_INITIALIZE(&prScanInfo->rFreeBSSDescList);
  863. LINK_INITIALIZE(&prScanInfo->rBSSDescList);
  864. } /* end of scnUninit() */
  865. /*----------------------------------------------------------------------------*/
  866. /*!
  867. * @brief Find the corresponding BSS Descriptor according to given BSSID
  868. *
  869. * @param[in] prAdapter Pointer to the Adapter structure.
  870. * @param[in] aucBSSID Given BSSID.
  871. *
  872. * @return Pointer to BSS Descriptor, if found. NULL, if not found
  873. */
  874. /*----------------------------------------------------------------------------*/
  875. P_BSS_DESC_T scanSearchBssDescByBssid(IN P_ADAPTER_T prAdapter, IN UINT_8 aucBSSID[])
  876. {
  877. return scanSearchBssDescByBssidAndSsid(prAdapter, aucBSSID, FALSE, NULL);
  878. }
  879. /*----------------------------------------------------------------------------*/
  880. /*!
  881. * @brief Find the corresponding BSS Descriptor according to given BSSID
  882. *
  883. * @param[in] prAdapter Pointer to the Adapter structure.
  884. * @param[in] aucBSSID Given BSSID.
  885. * @param[in] fgCheckSsid Need to check SSID or not. (for multiple SSID with single BSSID cases)
  886. * @param[in] prSsid Specified SSID
  887. *
  888. * @return Pointer to BSS Descriptor, if found. NULL, if not found
  889. */
  890. /*----------------------------------------------------------------------------*/
  891. P_BSS_DESC_T
  892. scanSearchBssDescByBssidAndSsid(IN P_ADAPTER_T prAdapter,
  893. IN UINT_8 aucBSSID[], IN BOOLEAN fgCheckSsid, IN P_PARAM_SSID_T prSsid)
  894. {
  895. P_SCAN_INFO_T prScanInfo;
  896. P_LINK_T prBSSDescList;
  897. P_BSS_DESC_T prBssDesc;
  898. P_BSS_DESC_T prDstBssDesc = (P_BSS_DESC_T) NULL;
  899. ASSERT(prAdapter);
  900. ASSERT(aucBSSID);
  901. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  902. prBSSDescList = &prScanInfo->rBSSDescList;
  903. /* Search BSS Desc from current SCAN result list. */
  904. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  905. if (EQUAL_MAC_ADDR(prBssDesc->aucBSSID, aucBSSID)) {
  906. if (fgCheckSsid == FALSE || prSsid == NULL)
  907. return prBssDesc;
  908. if (EQUAL_SSID(prBssDesc->aucSSID,
  909. prBssDesc->ucSSIDLen, prSsid->aucSsid, prSsid->u4SsidLen)) {
  910. return prBssDesc;
  911. } else if (prDstBssDesc == NULL && prBssDesc->fgIsHiddenSSID == TRUE) {
  912. prDstBssDesc = prBssDesc;
  913. } else if (prBssDesc->eBSSType == BSS_TYPE_P2P_DEVICE) {
  914. /* 20120206 frog: Equal BSSID but not SSID,
  915. * SSID not hidden, SSID must be updated. */
  916. COPY_SSID(prBssDesc->aucSSID,
  917. prBssDesc->ucSSIDLen, prSsid->aucSsid, (UINT_8) (prSsid->u4SsidLen));
  918. return prBssDesc;
  919. }
  920. }
  921. }
  922. return prDstBssDesc;
  923. } /* end of scanSearchBssDescByBssid() */
  924. /*----------------------------------------------------------------------------*/
  925. /*!
  926. * @brief Find the corresponding BSS Descriptor according to given Transmitter Address.
  927. *
  928. * @param[in] prAdapter Pointer to the Adapter structure.
  929. * @param[in] aucSrcAddr Given Source Address(TA).
  930. *
  931. * @return Pointer to BSS Descriptor, if found. NULL, if not found
  932. */
  933. /*----------------------------------------------------------------------------*/
  934. P_BSS_DESC_T scanSearchBssDescByTA(IN P_ADAPTER_T prAdapter, IN UINT_8 aucSrcAddr[])
  935. {
  936. return scanSearchBssDescByTAAndSsid(prAdapter, aucSrcAddr, FALSE, NULL);
  937. }
  938. /*----------------------------------------------------------------------------*/
  939. /*!
  940. * @brief Find the corresponding BSS Descriptor according to given Transmitter Address.
  941. *
  942. * @param[in] prAdapter Pointer to the Adapter structure.
  943. * @param[in] aucSrcAddr Given Source Address(TA).
  944. * @param[in] fgCheckSsid Need to check SSID or not. (for multiple SSID with single BSSID cases)
  945. * @param[in] prSsid Specified SSID
  946. *
  947. * @return Pointer to BSS Descriptor, if found. NULL, if not found
  948. */
  949. /*----------------------------------------------------------------------------*/
  950. P_BSS_DESC_T
  951. scanSearchBssDescByTAAndSsid(IN P_ADAPTER_T prAdapter,
  952. IN UINT_8 aucSrcAddr[], IN BOOLEAN fgCheckSsid, IN P_PARAM_SSID_T prSsid)
  953. {
  954. P_SCAN_INFO_T prScanInfo;
  955. P_LINK_T prBSSDescList;
  956. P_BSS_DESC_T prBssDesc;
  957. P_BSS_DESC_T prDstBssDesc = (P_BSS_DESC_T) NULL;
  958. ASSERT(prAdapter);
  959. ASSERT(aucSrcAddr);
  960. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  961. prBSSDescList = &prScanInfo->rBSSDescList;
  962. /* Search BSS Desc from current SCAN result list. */
  963. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  964. if (EQUAL_MAC_ADDR(prBssDesc->aucSrcAddr, aucSrcAddr)) {
  965. if (fgCheckSsid == FALSE || prSsid == NULL)
  966. return prBssDesc;
  967. if (EQUAL_SSID(prBssDesc->aucSSID,
  968. prBssDesc->ucSSIDLen, prSsid->aucSsid, prSsid->u4SsidLen)) {
  969. return prBssDesc;
  970. } else if (prDstBssDesc == NULL && prBssDesc->fgIsHiddenSSID == TRUE) {
  971. prDstBssDesc = prBssDesc;
  972. }
  973. }
  974. }
  975. return prDstBssDesc;
  976. } /* end of scanSearchBssDescByTA() */
  977. /*----------------------------------------------------------------------------*/
  978. /*!
  979. * @brief Find the corresponding BSS Descriptor according to
  980. * given eBSSType, BSSID and Transmitter Address
  981. *
  982. * @param[in] prAdapter Pointer to the Adapter structure.
  983. * @param[in] eBSSType BSS Type of incoming Beacon/ProbeResp frame.
  984. * @param[in] aucBSSID Given BSSID of Beacon/ProbeResp frame.
  985. * @param[in] aucSrcAddr Given source address (TA) of Beacon/ProbeResp frame.
  986. *
  987. * @return Pointer to BSS Descriptor, if found. NULL, if not found
  988. */
  989. /*----------------------------------------------------------------------------*/
  990. P_BSS_DESC_T
  991. scanSearchExistingBssDesc(IN P_ADAPTER_T prAdapter,
  992. IN ENUM_BSS_TYPE_T eBSSType, IN UINT_8 aucBSSID[], IN UINT_8 aucSrcAddr[])
  993. {
  994. return scanSearchExistingBssDescWithSsid(prAdapter, eBSSType, aucBSSID, aucSrcAddr, FALSE, NULL);
  995. }
  996. /*----------------------------------------------------------------------------*/
  997. /*!
  998. * @brief Find the corresponding BSS Descriptor according to
  999. * given eBSSType, BSSID and Transmitter Address
  1000. *
  1001. * @param[in] prAdapter Pointer to the Adapter structure.
  1002. * @param[in] eBSSType BSS Type of incoming Beacon/ProbeResp frame.
  1003. * @param[in] aucBSSID Given BSSID of Beacon/ProbeResp frame.
  1004. * @param[in] aucSrcAddr Given source address (TA) of Beacon/ProbeResp frame.
  1005. * @param[in] fgCheckSsid Need to check SSID or not. (for multiple SSID with single BSSID cases)
  1006. * @param[in] prSsid Specified SSID
  1007. *
  1008. * @return Pointer to BSS Descriptor, if found. NULL, if not found
  1009. */
  1010. /*----------------------------------------------------------------------------*/
  1011. P_BSS_DESC_T
  1012. scanSearchExistingBssDescWithSsid(IN P_ADAPTER_T prAdapter,
  1013. IN ENUM_BSS_TYPE_T eBSSType,
  1014. IN UINT_8 aucBSSID[],
  1015. IN UINT_8 aucSrcAddr[], IN BOOLEAN fgCheckSsid, IN P_PARAM_SSID_T prSsid)
  1016. {
  1017. P_SCAN_INFO_T prScanInfo;
  1018. P_BSS_DESC_T prBssDesc, prIBSSBssDesc;
  1019. ASSERT(prAdapter);
  1020. ASSERT(aucSrcAddr);
  1021. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1022. switch (eBSSType) {
  1023. case BSS_TYPE_P2P_DEVICE:
  1024. fgCheckSsid = FALSE;
  1025. case BSS_TYPE_INFRASTRUCTURE:
  1026. case BSS_TYPE_BOW_DEVICE:
  1027. {
  1028. prBssDesc = scanSearchBssDescByBssidAndSsid(prAdapter, aucBSSID, fgCheckSsid, prSsid);
  1029. /* if (eBSSType == prBssDesc->eBSSType) */
  1030. return prBssDesc;
  1031. }
  1032. case BSS_TYPE_IBSS:
  1033. {
  1034. prIBSSBssDesc = scanSearchBssDescByBssidAndSsid(prAdapter, aucBSSID, fgCheckSsid, prSsid);
  1035. prBssDesc = scanSearchBssDescByTAAndSsid(prAdapter, aucSrcAddr, fgCheckSsid, prSsid);
  1036. /* NOTE(Kevin):
  1037. * Rules to maintain the SCAN Result:
  1038. * For AdHoc -
  1039. * CASE I We have TA1(BSSID1), but it change its BSSID to BSSID2
  1040. * -> Update TA1 entry's BSSID.
  1041. * CASE II We have TA1(BSSID1), and get TA1(BSSID1) again
  1042. * -> Update TA1 entry's contain.
  1043. * CASE III We have a SCAN result TA1(BSSID1), and TA2(BSSID2). Sooner or
  1044. * later, TA2 merge into TA1, we get TA2(BSSID1)
  1045. * -> Remove TA2 first and then replace TA1 entry's TA with TA2,
  1046. * Still have only one entry of BSSID.
  1047. * CASE IV We have a SCAN result TA1(BSSID1), and another TA2 also merge into BSSID1.
  1048. * -> Replace TA1 entry's TA with TA2, Still have only one entry.
  1049. * CASE V New IBSS
  1050. * -> Add this one to SCAN result.
  1051. */
  1052. if (prBssDesc) {
  1053. P_LINK_T prBSSDescList;
  1054. P_LINK_T prFreeBSSDescList;
  1055. if ((!prIBSSBssDesc) || /* CASE I */
  1056. (prBssDesc == prIBSSBssDesc)) { /* CASE II */
  1057. return prBssDesc;
  1058. }
  1059. /* CASE III */
  1060. prBSSDescList = &prScanInfo->rBSSDescList;
  1061. prFreeBSSDescList = &prScanInfo->rFreeBSSDescList;
  1062. /* Remove this BSS Desc from the BSS Desc list */
  1063. LINK_REMOVE_KNOWN_ENTRY(prBSSDescList, prBssDesc);
  1064. /* Return this BSS Desc to the free BSS Desc list. */
  1065. LINK_INSERT_TAIL(prFreeBSSDescList, &prBssDesc->rLinkEntry);
  1066. return prIBSSBssDesc;
  1067. }
  1068. if (prIBSSBssDesc) { /* CASE IV */
  1069. return prIBSSBssDesc;
  1070. }
  1071. /* CASE V */
  1072. break; /* Return NULL; */
  1073. }
  1074. default:
  1075. break;
  1076. }
  1077. return (P_BSS_DESC_T) NULL;
  1078. } /* end of scanSearchExistingBssDesc() */
  1079. /*----------------------------------------------------------------------------*/
  1080. /*!
  1081. * @brief Delete BSS Descriptors from current list according to given Remove Policy.
  1082. *
  1083. * @param[in] u4RemovePolicy Remove Policy.
  1084. *
  1085. * @return (none)
  1086. */
  1087. /*----------------------------------------------------------------------------*/
  1088. VOID scanRemoveBssDescsByPolicy(IN P_ADAPTER_T prAdapter, IN UINT_32 u4RemovePolicy)
  1089. {
  1090. P_CONNECTION_SETTINGS_T prConnSettings;
  1091. P_SCAN_INFO_T prScanInfo;
  1092. P_LINK_T prBSSDescList;
  1093. P_LINK_T prFreeBSSDescList;
  1094. P_BSS_DESC_T prBssDesc;
  1095. ASSERT(prAdapter);
  1096. prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
  1097. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1098. prBSSDescList = &prScanInfo->rBSSDescList;
  1099. prFreeBSSDescList = &prScanInfo->rFreeBSSDescList;
  1100. /* DBGLOG(SCN, TRACE, ("Before Remove - Number Of SCAN Result = %ld\n", */
  1101. /* prBSSDescList->u4NumElem)); */
  1102. if (u4RemovePolicy & SCN_RM_POLICY_TIMEOUT) {
  1103. P_BSS_DESC_T prBSSDescNext;
  1104. OS_SYSTIME rCurrentTime;
  1105. GET_CURRENT_SYSTIME(&rCurrentTime);
  1106. /* Search BSS Desc from current SCAN result list. */
  1107. LINK_FOR_EACH_ENTRY_SAFE(prBssDesc, prBSSDescNext, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  1108. if ((u4RemovePolicy & SCN_RM_POLICY_EXCLUDE_CONNECTED) &&
  1109. (prBssDesc->fgIsConnected || prBssDesc->fgIsConnecting)) {
  1110. /* Don't remove the one currently we are connected. */
  1111. continue;
  1112. }
  1113. if (CHECK_FOR_TIMEOUT(rCurrentTime, prBssDesc->rUpdateTime,
  1114. SEC_TO_SYSTIME(SCN_BSS_DESC_REMOVE_TIMEOUT_SEC))) {
  1115. /* DBGLOG(SCN, TRACE, ("Remove TIMEOUT BSS DESC(%#x):
  1116. * MAC: "MACSTR", Current Time = %08lx, Update Time = %08lx\n", */
  1117. /* prBssDesc, MAC2STR(prBssDesc->aucBSSID), rCurrentTime, prBssDesc->rUpdateTime)); */
  1118. /* Remove this BSS Desc from the BSS Desc list */
  1119. LINK_REMOVE_KNOWN_ENTRY(prBSSDescList, prBssDesc);
  1120. /* Return this BSS Desc to the free BSS Desc list. */
  1121. LINK_INSERT_TAIL(prFreeBSSDescList, &prBssDesc->rLinkEntry);
  1122. }
  1123. }
  1124. } else if (u4RemovePolicy & SCN_RM_POLICY_OLDEST_HIDDEN) {
  1125. P_BSS_DESC_T prBssDescOldest = (P_BSS_DESC_T) NULL;
  1126. /* Search BSS Desc from current SCAN result list. */
  1127. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  1128. if ((u4RemovePolicy & SCN_RM_POLICY_EXCLUDE_CONNECTED) &&
  1129. (prBssDesc->fgIsConnected || prBssDesc->fgIsConnecting)) {
  1130. /* Don't remove the one currently we are connected. */
  1131. continue;
  1132. }
  1133. if (!prBssDesc->fgIsHiddenSSID)
  1134. continue;
  1135. if (!prBssDescOldest) { /* 1st element */
  1136. prBssDescOldest = prBssDesc;
  1137. continue;
  1138. }
  1139. if (TIME_BEFORE(prBssDesc->rUpdateTime, prBssDescOldest->rUpdateTime))
  1140. prBssDescOldest = prBssDesc;
  1141. }
  1142. if (prBssDescOldest) {
  1143. /* DBGLOG(SCN, TRACE,
  1144. * ("Remove OLDEST HIDDEN BSS DESC(%#x): MAC: "MACSTR", Update Time = %08lx\n", */
  1145. /* prBssDescOldest, MAC2STR(prBssDescOldest->aucBSSID), prBssDescOldest->rUpdateTime)); */
  1146. /* Remove this BSS Desc from the BSS Desc list */
  1147. LINK_REMOVE_KNOWN_ENTRY(prBSSDescList, prBssDescOldest);
  1148. /* Return this BSS Desc to the free BSS Desc list. */
  1149. LINK_INSERT_TAIL(prFreeBSSDescList, &prBssDescOldest->rLinkEntry);
  1150. }
  1151. } else if (u4RemovePolicy & SCN_RM_POLICY_SMART_WEAKEST) {
  1152. P_BSS_DESC_T prBssDescWeakest = (P_BSS_DESC_T) NULL;
  1153. P_BSS_DESC_T prBssDescWeakestSameSSID = (P_BSS_DESC_T) NULL;
  1154. UINT_32 u4SameSSIDCount = 0;
  1155. /* Search BSS Desc from current SCAN result list. */
  1156. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  1157. if ((u4RemovePolicy & SCN_RM_POLICY_EXCLUDE_CONNECTED) &&
  1158. (prBssDesc->fgIsConnected || prBssDesc->fgIsConnecting)) {
  1159. /* Don't remove the one currently we are connected. */
  1160. continue;
  1161. }
  1162. if ((!prBssDesc->fgIsHiddenSSID) &&
  1163. (EQUAL_SSID(prBssDesc->aucSSID,
  1164. prBssDesc->ucSSIDLen, prConnSettings->aucSSID, prConnSettings->ucSSIDLen))) {
  1165. u4SameSSIDCount++;
  1166. if (!prBssDescWeakestSameSSID)
  1167. prBssDescWeakestSameSSID = prBssDesc;
  1168. else if (prBssDesc->ucRCPI < prBssDescWeakestSameSSID->ucRCPI)
  1169. prBssDescWeakestSameSSID = prBssDesc;
  1170. }
  1171. if (!prBssDescWeakest) { /* 1st element */
  1172. prBssDescWeakest = prBssDesc;
  1173. continue;
  1174. }
  1175. if (prBssDesc->ucRCPI < prBssDescWeakest->ucRCPI)
  1176. prBssDescWeakest = prBssDesc;
  1177. }
  1178. if ((u4SameSSIDCount >= SCN_BSS_DESC_SAME_SSID_THRESHOLD) && (prBssDescWeakestSameSSID))
  1179. prBssDescWeakest = prBssDescWeakestSameSSID;
  1180. if (prBssDescWeakest) {
  1181. /* DBGLOG(SCN, TRACE, ("Remove WEAKEST BSS DESC(%#x): MAC: "MACSTR", Update Time = %08lx\n", */
  1182. /* prBssDescOldest, MAC2STR(prBssDescOldest->aucBSSID), prBssDescOldest->rUpdateTime)); */
  1183. /* Remove this BSS Desc from the BSS Desc list */
  1184. LINK_REMOVE_KNOWN_ENTRY(prBSSDescList, prBssDescWeakest);
  1185. /* Return this BSS Desc to the free BSS Desc list. */
  1186. LINK_INSERT_TAIL(prFreeBSSDescList, &prBssDescWeakest->rLinkEntry);
  1187. }
  1188. } else if (u4RemovePolicy & SCN_RM_POLICY_ENTIRE) {
  1189. P_BSS_DESC_T prBSSDescNext;
  1190. LINK_FOR_EACH_ENTRY_SAFE(prBssDesc, prBSSDescNext, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  1191. if ((u4RemovePolicy & SCN_RM_POLICY_EXCLUDE_CONNECTED) &&
  1192. (prBssDesc->fgIsConnected || prBssDesc->fgIsConnecting)) {
  1193. /* Don't remove the one currently we are connected. */
  1194. continue;
  1195. }
  1196. /* Remove this BSS Desc from the BSS Desc list */
  1197. LINK_REMOVE_KNOWN_ENTRY(prBSSDescList, prBssDesc);
  1198. /* Return this BSS Desc to the free BSS Desc list. */
  1199. LINK_INSERT_TAIL(prFreeBSSDescList, &prBssDesc->rLinkEntry);
  1200. }
  1201. }
  1202. return;
  1203. } /* end of scanRemoveBssDescsByPolicy() */
  1204. /*----------------------------------------------------------------------------*/
  1205. /*!
  1206. * @brief Delete BSS Descriptors from current list according to given BSSID.
  1207. *
  1208. * @param[in] prAdapter Pointer to the Adapter structure.
  1209. * @param[in] aucBSSID Given BSSID.
  1210. *
  1211. * @return (none)
  1212. */
  1213. /*----------------------------------------------------------------------------*/
  1214. VOID scanRemoveBssDescByBssid(IN P_ADAPTER_T prAdapter, IN UINT_8 aucBSSID[])
  1215. {
  1216. P_SCAN_INFO_T prScanInfo;
  1217. P_LINK_T prBSSDescList;
  1218. P_LINK_T prFreeBSSDescList;
  1219. P_BSS_DESC_T prBssDesc = (P_BSS_DESC_T) NULL;
  1220. P_BSS_DESC_T prBSSDescNext;
  1221. ASSERT(prAdapter);
  1222. ASSERT(aucBSSID);
  1223. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1224. prBSSDescList = &prScanInfo->rBSSDescList;
  1225. prFreeBSSDescList = &prScanInfo->rFreeBSSDescList;
  1226. /* Check if such BSS Descriptor exists in a valid list */
  1227. LINK_FOR_EACH_ENTRY_SAFE(prBssDesc, prBSSDescNext, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  1228. if (EQUAL_MAC_ADDR(prBssDesc->aucBSSID, aucBSSID)) {
  1229. /* Remove this BSS Desc from the BSS Desc list */
  1230. LINK_REMOVE_KNOWN_ENTRY(prBSSDescList, prBssDesc);
  1231. /* Return this BSS Desc to the free BSS Desc list. */
  1232. LINK_INSERT_TAIL(prFreeBSSDescList, &prBssDesc->rLinkEntry);
  1233. /* BSSID is not unique, so need to traverse whols link-list */
  1234. }
  1235. }
  1236. } /* end of scanRemoveBssDescByBssid() */
  1237. /*----------------------------------------------------------------------------*/
  1238. /*!
  1239. * @brief Delete BSS Descriptors from current list according to given band configuration
  1240. *
  1241. * @param[in] prAdapter Pointer to the Adapter structure.
  1242. * @param[in] eBand Given band
  1243. * @param[in] ucBssIndex AIS - Remove IBSS/Infrastructure BSS
  1244. * BOW - Remove BOW BSS
  1245. * P2P - Remove P2P BSS
  1246. *
  1247. * @return (none)
  1248. */
  1249. /*----------------------------------------------------------------------------*/
  1250. VOID scanRemoveBssDescByBandAndNetwork(IN P_ADAPTER_T prAdapter, IN ENUM_BAND_T eBand, IN UINT_8 ucBssIndex)
  1251. {
  1252. P_SCAN_INFO_T prScanInfo;
  1253. P_LINK_T prBSSDescList;
  1254. P_LINK_T prFreeBSSDescList;
  1255. P_BSS_DESC_T prBssDesc = (P_BSS_DESC_T) NULL;
  1256. P_BSS_DESC_T prBSSDescNext;
  1257. BOOLEAN fgToRemove;
  1258. ASSERT(prAdapter);
  1259. ASSERT(eBand <= BAND_NUM);
  1260. ASSERT(ucBssIndex <= MAX_BSS_INDEX);
  1261. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1262. prBSSDescList = &prScanInfo->rBSSDescList;
  1263. prFreeBSSDescList = &prScanInfo->rFreeBSSDescList;
  1264. if (eBand == BAND_NULL)
  1265. return; /* no need to do anything, keep all scan result */
  1266. /* Check if such BSS Descriptor exists in a valid list */
  1267. LINK_FOR_EACH_ENTRY_SAFE(prBssDesc, prBSSDescNext, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  1268. fgToRemove = FALSE;
  1269. if (prBssDesc->eBand == eBand) {
  1270. switch (GET_BSS_INFO_BY_INDEX(prAdapter, ucBssIndex)->eNetworkType) {
  1271. case NETWORK_TYPE_AIS:
  1272. if ((prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE)
  1273. || (prBssDesc->eBSSType == BSS_TYPE_IBSS)) {
  1274. fgToRemove = TRUE;
  1275. }
  1276. break;
  1277. case NETWORK_TYPE_P2P:
  1278. if (prBssDesc->eBSSType == BSS_TYPE_P2P_DEVICE)
  1279. fgToRemove = TRUE;
  1280. break;
  1281. case NETWORK_TYPE_BOW:
  1282. if (prBssDesc->eBSSType == BSS_TYPE_BOW_DEVICE)
  1283. fgToRemove = TRUE;
  1284. break;
  1285. default:
  1286. ASSERT(0);
  1287. break;
  1288. }
  1289. }
  1290. if (fgToRemove == TRUE) {
  1291. /* Remove this BSS Desc from the BSS Desc list */
  1292. LINK_REMOVE_KNOWN_ENTRY(prBSSDescList, prBssDesc);
  1293. /* Return this BSS Desc to the free BSS Desc list. */
  1294. LINK_INSERT_TAIL(prFreeBSSDescList, &prBssDesc->rLinkEntry);
  1295. }
  1296. }
  1297. } /* end of scanRemoveBssDescByBand() */
  1298. /*----------------------------------------------------------------------------*/
  1299. /*!
  1300. * @brief Clear the CONNECTION FLAG of a specified BSS Descriptor.
  1301. *
  1302. * @param[in] aucBSSID Given BSSID.
  1303. *
  1304. * @return (none)
  1305. */
  1306. /*----------------------------------------------------------------------------*/
  1307. VOID scanRemoveConnFlagOfBssDescByBssid(IN P_ADAPTER_T prAdapter, IN UINT_8 aucBSSID[])
  1308. {
  1309. P_SCAN_INFO_T prScanInfo;
  1310. P_LINK_T prBSSDescList;
  1311. P_BSS_DESC_T prBssDesc = (P_BSS_DESC_T) NULL;
  1312. ASSERT(prAdapter);
  1313. ASSERT(aucBSSID);
  1314. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1315. prBSSDescList = &prScanInfo->rBSSDescList;
  1316. /* Search BSS Desc from current SCAN result list. */
  1317. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  1318. if (EQUAL_MAC_ADDR(prBssDesc->aucBSSID, aucBSSID)) {
  1319. prBssDesc->fgIsConnected = FALSE;
  1320. prBssDesc->fgIsConnecting = FALSE;
  1321. /* BSSID is not unique, so need to traverse whols link-list */
  1322. }
  1323. }
  1324. return;
  1325. } /* end of scanRemoveConnectionFlagOfBssDescByBssid() */
  1326. /*----------------------------------------------------------------------------*/
  1327. /*!
  1328. * @brief Allocate new BSS_DESC_T
  1329. *
  1330. * @param[in] prAdapter Pointer to the Adapter structure.
  1331. *
  1332. * @return Pointer to BSS Descriptor, if has free space. NULL, if has no space.
  1333. */
  1334. /*----------------------------------------------------------------------------*/
  1335. P_BSS_DESC_T scanAllocateBssDesc(IN P_ADAPTER_T prAdapter)
  1336. {
  1337. P_SCAN_INFO_T prScanInfo;
  1338. P_LINK_T prFreeBSSDescList;
  1339. P_BSS_DESC_T prBssDesc;
  1340. ASSERT(prAdapter);
  1341. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1342. prFreeBSSDescList = &prScanInfo->rFreeBSSDescList;
  1343. LINK_REMOVE_HEAD(prFreeBSSDescList, prBssDesc, P_BSS_DESC_T);
  1344. if (prBssDesc) {
  1345. P_LINK_T prBSSDescList;
  1346. kalMemZero(prBssDesc, sizeof(BSS_DESC_T));
  1347. #if CFG_ENABLE_WIFI_DIRECT
  1348. LINK_INITIALIZE(&(prBssDesc->rP2pDeviceList));
  1349. prBssDesc->fgIsP2PPresent = FALSE;
  1350. #endif /* CFG_ENABLE_WIFI_DIRECT */
  1351. prBSSDescList = &prScanInfo->rBSSDescList;
  1352. /* NOTE(Kevin): In current design, this new empty BSS_DESC_T will be
  1353. * inserted to BSSDescList immediately.
  1354. */
  1355. LINK_INSERT_TAIL(prBSSDescList, &prBssDesc->rLinkEntry);
  1356. }
  1357. return prBssDesc;
  1358. } /* end of scanAllocateBssDesc() */
  1359. /*----------------------------------------------------------------------------*/
  1360. /*!
  1361. * @brief This API parses Beacon/ProbeResp frame and insert extracted BSS_DESC_T
  1362. * with IEs into prAdapter->rWifiVar.rScanInfo.aucScanBuffer
  1363. *
  1364. * @param[in] prAdapter Pointer to the Adapter structure.
  1365. * @param[in] prSwRfb Pointer to the receiving frame buffer.
  1366. *
  1367. * @return Pointer to BSS Descriptor
  1368. * NULL if the Beacon/ProbeResp frame is invalid
  1369. */
  1370. /*----------------------------------------------------------------------------*/
  1371. P_BSS_DESC_T scanAddToBssDesc(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  1372. {
  1373. P_BSS_DESC_T prBssDesc = NULL;
  1374. UINT_16 u2CapInfo;
  1375. ENUM_BSS_TYPE_T eBSSType = BSS_TYPE_INFRASTRUCTURE;
  1376. PUINT_8 pucIE;
  1377. UINT_16 u2IELength;
  1378. UINT_16 u2Offset = 0;
  1379. P_WLAN_BEACON_FRAME_T prWlanBeaconFrame = (P_WLAN_BEACON_FRAME_T) NULL;
  1380. P_IE_SSID_T prIeSsid = (P_IE_SSID_T) NULL;
  1381. P_IE_SUPPORTED_RATE_T prIeSupportedRate = (P_IE_SUPPORTED_RATE_T) NULL;
  1382. P_IE_EXT_SUPPORTED_RATE_T prIeExtSupportedRate = (P_IE_EXT_SUPPORTED_RATE_T) NULL;
  1383. UINT_8 ucHwChannelNum = 0;
  1384. UINT_8 ucIeDsChannelNum = 0;
  1385. UINT_8 ucIeHtChannelNum = 0;
  1386. BOOLEAN fgIsValidSsid = FALSE, fgEscape = FALSE;
  1387. PARAM_SSID_T rSsid;
  1388. UINT_64 u8Timestamp;
  1389. BOOLEAN fgIsNewBssDesc = FALSE;
  1390. UINT_32 i;
  1391. UINT_8 ucSSIDChar;
  1392. ASSERT(prAdapter);
  1393. ASSERT(prSwRfb);
  1394. prWlanBeaconFrame = (P_WLAN_BEACON_FRAME_T) prSwRfb->pvHeader;
  1395. WLAN_GET_FIELD_16(&prWlanBeaconFrame->u2CapInfo, &u2CapInfo);
  1396. WLAN_GET_FIELD_64(&prWlanBeaconFrame->au4Timestamp[0], &u8Timestamp);
  1397. /* decide BSS type */
  1398. switch (u2CapInfo & CAP_INFO_BSS_TYPE) {
  1399. case CAP_INFO_ESS:
  1400. /* It can also be Group Owner of P2P Group. */
  1401. eBSSType = BSS_TYPE_INFRASTRUCTURE;
  1402. break;
  1403. case CAP_INFO_IBSS:
  1404. eBSSType = BSS_TYPE_IBSS;
  1405. break;
  1406. case 0:
  1407. /* The P2P Device shall set the ESS bit of the Capabilities field
  1408. * in the Probe Response fame to 0 and IBSS bit to 0. (3.1.2.1.1) */
  1409. eBSSType = BSS_TYPE_P2P_DEVICE;
  1410. break;
  1411. #if CFG_ENABLE_BT_OVER_WIFI
  1412. /* @TODO: add rule to identify BOW beacons */
  1413. #endif
  1414. default:
  1415. return NULL;
  1416. }
  1417. /* 4 <1.1> Pre-parse SSID IE */
  1418. pucIE = prWlanBeaconFrame->aucInfoElem;
  1419. u2IELength = (prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) -
  1420. (UINT_16) OFFSET_OF(WLAN_BEACON_FRAME_BODY_T, aucInfoElem[0]);
  1421. if (u2IELength > CFG_IE_BUFFER_SIZE)
  1422. u2IELength = CFG_IE_BUFFER_SIZE;
  1423. IE_FOR_EACH(pucIE, u2IELength, u2Offset) {
  1424. switch (IE_ID(pucIE)) {
  1425. case ELEM_ID_SSID:
  1426. if (IE_LEN(pucIE) <= ELEM_MAX_LEN_SSID) {
  1427. ucSSIDChar = '\0';
  1428. /* D-Link DWL-900AP+ */
  1429. if (IE_LEN(pucIE) == 0)
  1430. fgIsValidSsid = FALSE;
  1431. /* Cisco AP1230A - (IE_LEN(pucIE) == 1) && (SSID_IE(pucIE)->aucSSID[0] == '\0') */
  1432. /* Linksys WRK54G/WL520g - (IE_LEN(pucIE) == n) &&
  1433. * (SSID_IE(pucIE)->aucSSID[0~(n-1)] == '\0') */
  1434. else {
  1435. for (i = 0; i < IE_LEN(pucIE); i++)
  1436. ucSSIDChar |= SSID_IE(pucIE)->aucSSID[i];
  1437. if (ucSSIDChar)
  1438. fgIsValidSsid = TRUE;
  1439. }
  1440. /* Update SSID to BSS Descriptor only if SSID is not hidden. */
  1441. if (fgIsValidSsid == TRUE) {
  1442. COPY_SSID(rSsid.aucSsid,
  1443. rSsid.u4SsidLen, SSID_IE(pucIE)->aucSSID, SSID_IE(pucIE)->ucLength);
  1444. }
  1445. }
  1446. fgEscape = TRUE;
  1447. break;
  1448. default:
  1449. break;
  1450. }
  1451. if (fgEscape == TRUE)
  1452. break;
  1453. }
  1454. /* 4 <1.2> Replace existing BSS_DESC_T or allocate a new one */
  1455. prBssDesc = scanSearchExistingBssDescWithSsid(prAdapter,
  1456. eBSSType,
  1457. (PUINT_8) prWlanBeaconFrame->aucBSSID,
  1458. (PUINT_8) prWlanBeaconFrame->aucSrcAddr,
  1459. fgIsValidSsid, fgIsValidSsid == TRUE ? &rSsid : NULL);
  1460. if (prBssDesc == (P_BSS_DESC_T) NULL) {
  1461. fgIsNewBssDesc = TRUE;
  1462. do {
  1463. /* 4 <1.2.1> First trial of allocation */
  1464. prBssDesc = scanAllocateBssDesc(prAdapter);
  1465. if (prBssDesc)
  1466. break;
  1467. /* 4 <1.2.2> Hidden is useless, remove the oldest hidden ssid. (for passive scan) */
  1468. scanRemoveBssDescsByPolicy(prAdapter,
  1469. (SCN_RM_POLICY_EXCLUDE_CONNECTED |
  1470. SCN_RM_POLICY_OLDEST_HIDDEN | SCN_RM_POLICY_TIMEOUT));
  1471. /* 4 <1.2.3> Second tail of allocation */
  1472. prBssDesc = scanAllocateBssDesc(prAdapter);
  1473. if (prBssDesc)
  1474. break;
  1475. /* 4 <1.2.4> Remove the weakest one */
  1476. /* If there are more than half of BSS which has the same ssid as connection
  1477. * setting, remove the weakest one from them.
  1478. * Else remove the weakest one.
  1479. */
  1480. scanRemoveBssDescsByPolicy(prAdapter,
  1481. (SCN_RM_POLICY_EXCLUDE_CONNECTED | SCN_RM_POLICY_SMART_WEAKEST));
  1482. /* 4 <1.2.5> reallocation */
  1483. prBssDesc = scanAllocateBssDesc(prAdapter);
  1484. if (prBssDesc)
  1485. break;
  1486. /* 4 <1.2.6> no space, should not happen */
  1487. /* ASSERT(0); // still no space available ? */
  1488. return NULL;
  1489. } while (FALSE);
  1490. } else {
  1491. OS_SYSTIME rCurrentTime;
  1492. /* WCXRP00000091 */
  1493. /* if the received strength is much weaker than the original one, */
  1494. /* ignore it due to it might be received on the folding frequency */
  1495. GET_CURRENT_SYSTIME(&rCurrentTime);
  1496. ASSERT(prSwRfb->prRxStatusGroup3);
  1497. if (prBssDesc->eBSSType != eBSSType) {
  1498. prBssDesc->eBSSType = eBSSType;
  1499. } else if (HAL_RX_STATUS_GET_CHNL_NUM(prSwRfb->prRxStatus) !=
  1500. prBssDesc->ucChannelNum
  1501. && prBssDesc->ucRCPI > HAL_RX_STATUS_GET_RCPI(prSwRfb->prRxStatusGroup3)) {
  1502. /* for signal strength is too much weaker and previous beacon is not stale */
  1503. ASSERT(prSwRfb->prRxStatusGroup3);
  1504. if ((prBssDesc->ucRCPI -
  1505. HAL_RX_STATUS_GET_RCPI(prSwRfb->prRxStatusGroup3)) >=
  1506. REPLICATED_BEACON_STRENGTH_THRESHOLD
  1507. && rCurrentTime - prBssDesc->rUpdateTime <= REPLICATED_BEACON_FRESH_PERIOD) {
  1508. return prBssDesc;
  1509. }
  1510. /* for received beacons too close in time domain */
  1511. else if (rCurrentTime - prBssDesc->rUpdateTime <= REPLICATED_BEACON_TIME_THRESHOLD)
  1512. return prBssDesc;
  1513. }
  1514. /* if Timestamp has been reset, re-generate BSS DESC 'cause AP should have reset itself */
  1515. if (prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE && u8Timestamp < prBssDesc->u8TimeStamp.QuadPart) {
  1516. BOOLEAN fgIsConnected, fgIsConnecting;
  1517. /* set flag for indicating this is a new BSS-DESC */
  1518. fgIsNewBssDesc = TRUE;
  1519. /* backup 2 flags for APs which reset timestamp unexpectedly */
  1520. fgIsConnected = prBssDesc->fgIsConnected;
  1521. fgIsConnecting = prBssDesc->fgIsConnecting;
  1522. scanRemoveBssDescByBssid(prAdapter, prBssDesc->aucBSSID);
  1523. prBssDesc = scanAllocateBssDesc(prAdapter);
  1524. if (!prBssDesc)
  1525. return NULL;
  1526. /* restore */
  1527. prBssDesc->fgIsConnected = fgIsConnected;
  1528. prBssDesc->fgIsConnecting = fgIsConnecting;
  1529. }
  1530. }
  1531. #if 1
  1532. prBssDesc->u2RawLength = prSwRfb->u2PacketLen;
  1533. kalMemCopy(prBssDesc->aucRawBuf, prWlanBeaconFrame, prBssDesc->u2RawLength);
  1534. #endif
  1535. /* NOTE: Keep consistency of Scan Record during JOIN process */
  1536. if (fgIsNewBssDesc == FALSE && prBssDesc->fgIsConnecting)
  1537. return prBssDesc;
  1538. /* 4 <2> Get information from Fixed Fields */
  1539. prBssDesc->eBSSType = eBSSType; /* Update the latest BSS type information. */
  1540. COPY_MAC_ADDR(prBssDesc->aucSrcAddr, prWlanBeaconFrame->aucSrcAddr);
  1541. COPY_MAC_ADDR(prBssDesc->aucBSSID, prWlanBeaconFrame->aucBSSID);
  1542. prBssDesc->u8TimeStamp.QuadPart = u8Timestamp;
  1543. WLAN_GET_FIELD_16(&prWlanBeaconFrame->u2BeaconInterval, &prBssDesc->u2BeaconInterval);
  1544. prBssDesc->u2CapInfo = u2CapInfo;
  1545. /* 4 <2.1> Retrieve IEs for later parsing */
  1546. u2IELength = (prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) -
  1547. (UINT_16) OFFSET_OF(WLAN_BEACON_FRAME_BODY_T, aucInfoElem[0]);
  1548. if (u2IELength > CFG_IE_BUFFER_SIZE) {
  1549. u2IELength = CFG_IE_BUFFER_SIZE;
  1550. prBssDesc->fgIsIEOverflow = TRUE;
  1551. } else {
  1552. prBssDesc->fgIsIEOverflow = FALSE;
  1553. }
  1554. prBssDesc->u2IELength = u2IELength;
  1555. kalMemCopy(prBssDesc->aucIEBuf, prWlanBeaconFrame->aucInfoElem, u2IELength);
  1556. /* 4 <2.2> reset prBssDesc variables in case that AP has been reconfigured */
  1557. prBssDesc->fgIsERPPresent = FALSE;
  1558. prBssDesc->fgIsHTPresent = FALSE;
  1559. prBssDesc->eSco = CHNL_EXT_SCN;
  1560. prBssDesc->fgIEWAPI = FALSE;
  1561. prBssDesc->fgIERSN = FALSE;
  1562. prBssDesc->fgIEWPA = FALSE;
  1563. prBssDesc->eChannelWidth = CW_20_40MHZ; /*Reset VHT OP IE relative settings */
  1564. prBssDesc->ucCenterFreqS1 = 0;
  1565. prBssDesc->ucCenterFreqS2 = 0;
  1566. /* 4 <3.1> Full IE parsing on SW_RFB_T */
  1567. pucIE = prWlanBeaconFrame->aucInfoElem;
  1568. IE_FOR_EACH(pucIE, u2IELength, u2Offset) {
  1569. switch (IE_ID(pucIE)) {
  1570. case ELEM_ID_SSID:
  1571. if ((!prIeSsid) && /* NOTE(Kevin): for Atheros IOT #1 */
  1572. (IE_LEN(pucIE) <= ELEM_MAX_LEN_SSID)) {
  1573. BOOLEAN fgIsHiddenSSID = FALSE;
  1574. ucSSIDChar = '\0';
  1575. prIeSsid = (P_IE_SSID_T) pucIE;
  1576. /* D-Link DWL-900AP+ */
  1577. if (IE_LEN(pucIE) == 0)
  1578. fgIsHiddenSSID = TRUE;
  1579. /* Cisco AP1230A - (IE_LEN(pucIE) == 1) && (SSID_IE(pucIE)->aucSSID[0] == '\0') */
  1580. /* Linksys WRK54G/WL520g - (IE_LEN(pucIE) == n) &&
  1581. * (SSID_IE(pucIE)->aucSSID[0~(n-1)] == '\0') */
  1582. else {
  1583. for (i = 0; i < IE_LEN(pucIE); i++)
  1584. ucSSIDChar |= SSID_IE(pucIE)->aucSSID[i];
  1585. if (!ucSSIDChar)
  1586. fgIsHiddenSSID = TRUE;
  1587. }
  1588. /* Update SSID to BSS Descriptor only if SSID is not hidden. */
  1589. if (!fgIsHiddenSSID) {
  1590. COPY_SSID(prBssDesc->aucSSID,
  1591. prBssDesc->ucSSIDLen,
  1592. SSID_IE(pucIE)->aucSSID, SSID_IE(pucIE)->ucLength);
  1593. }
  1594. }
  1595. break;
  1596. case ELEM_ID_SUP_RATES:
  1597. /* NOTE(Kevin): Buffalo WHR-G54S's supported rate set IE exceed 8.
  1598. * IE_LEN(pucIE) == 12, "1(B), 2(B), 5.5(B), 6(B), 9(B), 11(B),
  1599. * 12(B), 18(B), 24(B), 36(B), 48(B), 54(B)"
  1600. */
  1601. /* TP-LINK will set extra and incorrect ie with ELEM_ID_SUP_RATES */
  1602. if ((!prIeSupportedRate) && (IE_LEN(pucIE) <= RATE_NUM_SW))
  1603. prIeSupportedRate = SUP_RATES_IE(pucIE);
  1604. break;
  1605. case ELEM_ID_DS_PARAM_SET:
  1606. if (IE_LEN(pucIE) == ELEM_MAX_LEN_DS_PARAMETER_SET)
  1607. ucIeDsChannelNum = DS_PARAM_IE(pucIE)->ucCurrChnl;
  1608. break;
  1609. case ELEM_ID_TIM:
  1610. if (IE_LEN(pucIE) <= ELEM_MAX_LEN_TIM)
  1611. prBssDesc->ucDTIMPeriod = TIM_IE(pucIE)->ucDTIMPeriod;
  1612. break;
  1613. case ELEM_ID_IBSS_PARAM_SET:
  1614. if (IE_LEN(pucIE) == ELEM_MAX_LEN_IBSS_PARAMETER_SET)
  1615. prBssDesc->u2ATIMWindow = IBSS_PARAM_IE(pucIE)->u2ATIMWindow;
  1616. break;
  1617. #if 0 /* CFG_SUPPORT_802_11D */
  1618. case ELEM_ID_COUNTRY_INFO:
  1619. prBssDesc->prIECountry = (P_IE_COUNTRY_T) pucIE;
  1620. break;
  1621. #endif
  1622. case ELEM_ID_ERP_INFO:
  1623. if (IE_LEN(pucIE) == ELEM_MAX_LEN_ERP)
  1624. prBssDesc->fgIsERPPresent = TRUE;
  1625. break;
  1626. case ELEM_ID_EXTENDED_SUP_RATES:
  1627. if (!prIeExtSupportedRate)
  1628. prIeExtSupportedRate = EXT_SUP_RATES_IE(pucIE);
  1629. break;
  1630. case ELEM_ID_RSN:
  1631. if (rsnParseRsnIE(prAdapter, RSN_IE(pucIE), &prBssDesc->rRSNInfo)) {
  1632. prBssDesc->fgIERSN = TRUE;
  1633. prBssDesc->u2RsnCap = prBssDesc->rRSNInfo.u2RsnCap;
  1634. if (prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA2)
  1635. rsnCheckPmkidCache(prAdapter, prBssDesc);
  1636. }
  1637. break;
  1638. case ELEM_ID_HT_CAP:
  1639. prBssDesc->fgIsHTPresent = TRUE;
  1640. break;
  1641. case ELEM_ID_HT_OP:
  1642. if (IE_LEN(pucIE) != (sizeof(IE_HT_OP_T) - 2))
  1643. break;
  1644. if ((((P_IE_HT_OP_T) pucIE)->ucInfo1 & HT_OP_INFO1_SCO) != CHNL_EXT_RES) {
  1645. prBssDesc->eSco = (ENUM_CHNL_EXT_T)
  1646. (((P_IE_HT_OP_T) pucIE)->ucInfo1 & HT_OP_INFO1_SCO);
  1647. }
  1648. ucIeHtChannelNum = ((P_IE_HT_OP_T) pucIE)->ucPrimaryChannel;
  1649. break;
  1650. case ELEM_ID_VHT_CAP:
  1651. prBssDesc->fgIsVHTPresent = TRUE;
  1652. break;
  1653. case ELEM_ID_VHT_OP:
  1654. if (IE_LEN(pucIE) != (sizeof(IE_VHT_OP_T) - 2))
  1655. break;
  1656. prBssDesc->eChannelWidth = (ENUM_CHANNEL_WIDTH_T) (((P_IE_VHT_OP_T) pucIE)->ucVhtOperation[0]);
  1657. prBssDesc->ucCenterFreqS1 = (ENUM_CHANNEL_WIDTH_T) (((P_IE_VHT_OP_T) pucIE)->ucVhtOperation[1]);
  1658. prBssDesc->ucCenterFreqS2 = (ENUM_CHANNEL_WIDTH_T) (((P_IE_VHT_OP_T) pucIE)->ucVhtOperation[2]);
  1659. break;
  1660. #if CFG_SUPPORT_WAPI
  1661. case ELEM_ID_WAPI:
  1662. if (wapiParseWapiIE(WAPI_IE(pucIE), &prBssDesc->rIEWAPI))
  1663. prBssDesc->fgIEWAPI = TRUE;
  1664. break;
  1665. #endif
  1666. case ELEM_ID_VENDOR: /* ELEM_ID_P2P, ELEM_ID_WMM */
  1667. {
  1668. UINT_8 ucOuiType;
  1669. UINT_16 u2SubTypeVersion;
  1670. if (rsnParseCheckForWFAInfoElem(prAdapter, pucIE, &ucOuiType, &u2SubTypeVersion)) {
  1671. if ((ucOuiType == VENDOR_OUI_TYPE_WPA)
  1672. && (u2SubTypeVersion == VERSION_WPA)
  1673. && (rsnParseWpaIE(prAdapter, WPA_IE(pucIE), &prBssDesc->rWPAInfo))) {
  1674. prBssDesc->fgIEWPA = TRUE;
  1675. }
  1676. }
  1677. #if CFG_ENABLE_WIFI_DIRECT
  1678. if (prAdapter->fgIsP2PRegistered) {
  1679. if ((p2pFuncParseCheckForP2PInfoElem(prAdapter, pucIE, &ucOuiType))
  1680. && (ucOuiType == VENDOR_OUI_TYPE_P2P)) {
  1681. prBssDesc->fgIsP2PPresent = TRUE;
  1682. }
  1683. }
  1684. #endif /* CFG_ENABLE_WIFI_DIRECT */
  1685. }
  1686. break;
  1687. /* no default */
  1688. }
  1689. }
  1690. /* 4 <3.2> Save information from IEs - SSID */
  1691. /* Update Flag of Hidden SSID for used in SEARCH STATE. */
  1692. /* NOTE(Kevin): in current driver, the ucSSIDLen == 0 represent
  1693. * all cases of hidden SSID.
  1694. * If the fgIsHiddenSSID == TRUE, it means we didn't get the ProbeResp with
  1695. * valid SSID.
  1696. */
  1697. if (prBssDesc->ucSSIDLen == 0)
  1698. prBssDesc->fgIsHiddenSSID = TRUE;
  1699. else
  1700. prBssDesc->fgIsHiddenSSID = FALSE;
  1701. /* 4 <3.3> Check rate information in related IEs. */
  1702. if (prIeSupportedRate || prIeExtSupportedRate) {
  1703. rateGetRateSetFromIEs(prIeSupportedRate,
  1704. prIeExtSupportedRate,
  1705. &prBssDesc->u2OperationalRateSet,
  1706. &prBssDesc->u2BSSBasicRateSet, &prBssDesc->fgIsUnknownBssBasicRate);
  1707. }
  1708. /* 4 <4> Update information from HIF RX Header */
  1709. {
  1710. P_HW_MAC_RX_DESC_T prRxStatus;
  1711. UINT_8 ucRxRCPI;
  1712. prRxStatus = prSwRfb->prRxStatus;
  1713. ASSERT(prRxStatus);
  1714. /* 4 <4.1> Get TSF comparison result */
  1715. prBssDesc->fgIsLargerTSF = HAL_RX_STATUS_GET_TCL(prRxStatus);
  1716. /* 4 <4.2> Get Band information */
  1717. prBssDesc->eBand = HAL_RX_STATUS_GET_RF_BAND(prRxStatus);
  1718. /* 4 <4.2> Get channel and RCPI information */
  1719. ucHwChannelNum = HAL_RX_STATUS_GET_CHNL_NUM(prRxStatus);
  1720. ASSERT(prSwRfb->prRxStatusGroup3);
  1721. ucRxRCPI = (UINT_8) HAL_RX_STATUS_GET_RCPI(prSwRfb->prRxStatusGroup3);
  1722. if (BAND_2G4 == prBssDesc->eBand) {
  1723. /* Update RCPI if in right channel */
  1724. if (ucIeDsChannelNum >= 1 && ucIeDsChannelNum <= 14) {
  1725. /* Receive Beacon/ProbeResp frame from adjacent channel. */
  1726. if ((ucIeDsChannelNum == ucHwChannelNum) || (ucRxRCPI > prBssDesc->ucRCPI))
  1727. prBssDesc->ucRCPI = ucRxRCPI;
  1728. /* trust channel information brought by IE */
  1729. prBssDesc->ucChannelNum = ucIeDsChannelNum;
  1730. } else if (ucIeHtChannelNum >= 1 && ucIeHtChannelNum <= 14) {
  1731. /* Receive Beacon/ProbeResp frame from adjacent channel. */
  1732. if ((ucIeHtChannelNum == ucHwChannelNum) || (ucRxRCPI > prBssDesc->ucRCPI))
  1733. prBssDesc->ucRCPI = ucRxRCPI;
  1734. /* trust channel information brought by IE */
  1735. prBssDesc->ucChannelNum = ucIeHtChannelNum;
  1736. } else {
  1737. prBssDesc->ucRCPI = ucRxRCPI;
  1738. prBssDesc->ucChannelNum = ucHwChannelNum;
  1739. }
  1740. }
  1741. /* 5G Band */
  1742. else {
  1743. if (ucIeHtChannelNum >= 1 && ucIeHtChannelNum < 200) {
  1744. /* Receive Beacon/ProbeResp frame from adjacent channel. */
  1745. if ((ucIeHtChannelNum == ucHwChannelNum) || (ucRxRCPI > prBssDesc->ucRCPI))
  1746. prBssDesc->ucRCPI = ucRxRCPI;
  1747. /* trust channel information brought by IE */
  1748. prBssDesc->ucChannelNum = ucIeHtChannelNum;
  1749. } else {
  1750. /* Always update RCPI */
  1751. prBssDesc->ucRCPI = ucRxRCPI;
  1752. prBssDesc->ucChannelNum = ucHwChannelNum;
  1753. }
  1754. }
  1755. }
  1756. /* 4 <5> Check IE information corret or not */
  1757. if (!rlmDomainIsValidRfSetting(prAdapter, prBssDesc->eBand, prBssDesc->ucChannelNum, prBssDesc->eSco,
  1758. prBssDesc->eChannelWidth, prBssDesc->ucCenterFreqS1,
  1759. prBssDesc->ucCenterFreqS2)) {
  1760. /*Dump IE Inforamtion */
  1761. PUINT_8 pucDumpIE;
  1762. pucDumpIE = (PUINT_8) ((ULONG) pucIE - u2IELength);
  1763. DBGLOG(RLM, WARN, "ScanAddToBssDesc IE Information\n");
  1764. DBGLOG(RLM, WARN, "IE Length = %d\n", u2IELength);
  1765. DBGLOG_MEM8(RLM, WARN, pucDumpIE, u2IELength);
  1766. /*Error Handling for Non-predicted IE - Fixed to set 20MHz */
  1767. prBssDesc->eChannelWidth = CW_20_40MHZ;
  1768. prBssDesc->ucCenterFreqS1 = 0;
  1769. prBssDesc->ucCenterFreqS2 = 0;
  1770. prBssDesc->eSco = CHNL_EXT_SCN;
  1771. }
  1772. /* 4 <6> PHY type setting */
  1773. prBssDesc->ucPhyTypeSet = 0;
  1774. if (BAND_2G4 == prBssDesc->eBand) {
  1775. /* check if support 11n */
  1776. if (prBssDesc->fgIsHTPresent)
  1777. prBssDesc->ucPhyTypeSet |= PHY_TYPE_BIT_HT;
  1778. /* if not 11n only */
  1779. if (!(prBssDesc->u2BSSBasicRateSet & RATE_SET_BIT_HT_PHY)) {
  1780. /* check if support 11g */
  1781. if ((prBssDesc->u2OperationalRateSet & RATE_SET_OFDM) || prBssDesc->fgIsERPPresent)
  1782. prBssDesc->ucPhyTypeSet |= PHY_TYPE_BIT_ERP;
  1783. /* if not 11g only */
  1784. if (!(prBssDesc->u2BSSBasicRateSet & RATE_SET_OFDM)) {
  1785. /* check if support 11b */
  1786. if ((prBssDesc->u2OperationalRateSet & RATE_SET_HR_DSSS))
  1787. prBssDesc->ucPhyTypeSet |= PHY_TYPE_BIT_HR_DSSS;
  1788. }
  1789. }
  1790. } else { /* (BAND_5G == prBssDesc->eBande) */
  1791. /* check if support 11n */
  1792. if (prBssDesc->fgIsVHTPresent)
  1793. prBssDesc->ucPhyTypeSet |= PHY_TYPE_BIT_VHT;
  1794. if (prBssDesc->fgIsHTPresent)
  1795. prBssDesc->ucPhyTypeSet |= PHY_TYPE_BIT_HT;
  1796. /* if not 11n only */
  1797. if (!(prBssDesc->u2BSSBasicRateSet & RATE_SET_BIT_HT_PHY)) {
  1798. /* Support 11a definitely */
  1799. prBssDesc->ucPhyTypeSet |= PHY_TYPE_BIT_OFDM;
  1800. /* ASSERT(!(prBssDesc->u2OperationalRateSet & RATE_SET_HR_DSSS)); */
  1801. }
  1802. }
  1803. /* 4 <7> Update BSS_DESC_T's Last Update TimeStamp. */
  1804. GET_CURRENT_SYSTIME(&prBssDesc->rUpdateTime);
  1805. return prBssDesc;
  1806. }
  1807. /*----------------------------------------------------------------------------*/
  1808. /*!
  1809. * @brief Convert the Beacon or ProbeResp Frame in SW_RFB_T to scan result for query
  1810. *
  1811. * @param[in] prSwRfb Pointer to the receiving SW_RFB_T structure.
  1812. *
  1813. * @retval WLAN_STATUS_SUCCESS It is a valid Scan Result and been sent to the host.
  1814. * @retval WLAN_STATUS_FAILURE It is not a valid Scan Result.
  1815. */
  1816. /*----------------------------------------------------------------------------*/
  1817. WLAN_STATUS scanAddScanResult(IN P_ADAPTER_T prAdapter, IN P_BSS_DESC_T prBssDesc, IN P_SW_RFB_T prSwRfb)
  1818. {
  1819. P_SCAN_INFO_T prScanInfo;
  1820. UINT_8 aucRatesEx[PARAM_MAX_LEN_RATES_EX];
  1821. P_WLAN_BEACON_FRAME_T prWlanBeaconFrame;
  1822. PARAM_MAC_ADDRESS rMacAddr;
  1823. PARAM_SSID_T rSsid;
  1824. ENUM_PARAM_NETWORK_TYPE_T eNetworkType;
  1825. PARAM_802_11_CONFIG_T rConfiguration;
  1826. ENUM_PARAM_OP_MODE_T eOpMode;
  1827. UINT_8 ucRateLen = 0;
  1828. UINT_32 i;
  1829. ASSERT(prAdapter);
  1830. ASSERT(prSwRfb);
  1831. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1832. if (prBssDesc->eBand == BAND_2G4) {
  1833. if ((prBssDesc->u2OperationalRateSet & RATE_SET_OFDM)
  1834. || prBssDesc->fgIsERPPresent) {
  1835. eNetworkType = PARAM_NETWORK_TYPE_OFDM24;
  1836. } else {
  1837. eNetworkType = PARAM_NETWORK_TYPE_DS;
  1838. }
  1839. } else {
  1840. ASSERT(prBssDesc->eBand == BAND_5G);
  1841. eNetworkType = PARAM_NETWORK_TYPE_OFDM5;
  1842. }
  1843. if (prBssDesc->eBSSType == BSS_TYPE_P2P_DEVICE) {
  1844. /* NOTE(Kevin): Not supported by WZC(TBD) */
  1845. return WLAN_STATUS_FAILURE;
  1846. }
  1847. prWlanBeaconFrame = (P_WLAN_BEACON_FRAME_T) prSwRfb->pvHeader;
  1848. COPY_MAC_ADDR(rMacAddr, prWlanBeaconFrame->aucBSSID);
  1849. COPY_SSID(rSsid.aucSsid, rSsid.u4SsidLen, prBssDesc->aucSSID, prBssDesc->ucSSIDLen);
  1850. rConfiguration.u4Length = sizeof(PARAM_802_11_CONFIG_T);
  1851. rConfiguration.u4BeaconPeriod = (UINT_32) prWlanBeaconFrame->u2BeaconInterval;
  1852. rConfiguration.u4ATIMWindow = prBssDesc->u2ATIMWindow;
  1853. rConfiguration.u4DSConfig = nicChannelNum2Freq(prBssDesc->ucChannelNum);
  1854. rConfiguration.rFHConfig.u4Length = sizeof(PARAM_802_11_CONFIG_FH_T);
  1855. rateGetDataRatesFromRateSet(prBssDesc->u2OperationalRateSet, 0, aucRatesEx, &ucRateLen);
  1856. /* NOTE(Kevin): Set unused entries, if any, at the end of the array to 0.
  1857. * from OID_802_11_BSSID_LIST
  1858. */
  1859. for (i = ucRateLen; i < sizeof(aucRatesEx) / sizeof(aucRatesEx[0]); i++)
  1860. aucRatesEx[i] = 0;
  1861. switch (prBssDesc->eBSSType) {
  1862. case BSS_TYPE_IBSS:
  1863. eOpMode = NET_TYPE_IBSS;
  1864. break;
  1865. case BSS_TYPE_INFRASTRUCTURE:
  1866. case BSS_TYPE_P2P_DEVICE:
  1867. case BSS_TYPE_BOW_DEVICE:
  1868. default:
  1869. eOpMode = NET_TYPE_INFRA;
  1870. break;
  1871. }
  1872. DBGLOG(SCN, TRACE, "ind %s %d %d\n", prBssDesc->aucSSID, prBssDesc->ucChannelNum, prBssDesc->ucRCPI);
  1873. kalIndicateBssInfo(prAdapter->prGlueInfo,
  1874. (PUINT_8) prSwRfb->pvHeader,
  1875. prSwRfb->u2PacketLen, prBssDesc->ucChannelNum, RCPI_TO_dBm(prBssDesc->ucRCPI));
  1876. nicAddScanResult(prAdapter,
  1877. rMacAddr,
  1878. &rSsid,
  1879. prWlanBeaconFrame->u2CapInfo & CAP_INFO_PRIVACY ? 1 : 0,
  1880. RCPI_TO_dBm(prBssDesc->ucRCPI),
  1881. eNetworkType,
  1882. &rConfiguration,
  1883. eOpMode,
  1884. aucRatesEx,
  1885. prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen,
  1886. (PUINT_8) ((ULONG) (prSwRfb->pvHeader) + WLAN_MAC_MGMT_HEADER_LEN));
  1887. return WLAN_STATUS_SUCCESS;
  1888. } /* end of scanAddScanResult() */
  1889. BOOLEAN scanCheckBssIsLegal(IN P_ADAPTER_T prAdapter, P_BSS_DESC_T prBssDesc)
  1890. {
  1891. BOOLEAN fgAddToScanResult = FALSE;
  1892. ENUM_BAND_T eBand;
  1893. UINT_8 ucChannel;
  1894. ASSERT(prAdapter);
  1895. /* check the channel is in the legal doamin */
  1896. if (rlmDomainIsLegalChannel(prAdapter, prBssDesc->eBand, prBssDesc->ucChannelNum) == TRUE) {
  1897. /* check ucChannelNum/eBand for adjacement channel filtering */
  1898. if (cnmAisInfraChannelFixed(prAdapter, &eBand, &ucChannel) == TRUE &&
  1899. (eBand != prBssDesc->eBand || ucChannel != prBssDesc->ucChannelNum)) {
  1900. fgAddToScanResult = FALSE;
  1901. } else {
  1902. fgAddToScanResult = TRUE;
  1903. }
  1904. }
  1905. return fgAddToScanResult;
  1906. }
  1907. /*----------------------------------------------------------------------------*/
  1908. /*!
  1909. * @brief Parse the content of given Beacon or ProbeResp Frame.
  1910. *
  1911. * @param[in] prSwRfb Pointer to the receiving SW_RFB_T structure.
  1912. *
  1913. * @retval WLAN_STATUS_SUCCESS if not report this SW_RFB_T to host
  1914. * @retval WLAN_STATUS_PENDING if report this SW_RFB_T to host as scan result
  1915. */
  1916. /*----------------------------------------------------------------------------*/
  1917. WLAN_STATUS scanProcessBeaconAndProbeResp(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  1918. {
  1919. P_SCAN_INFO_T prScanInfo;
  1920. P_CONNECTION_SETTINGS_T prConnSettings;
  1921. P_BSS_DESC_T prBssDesc = (P_BSS_DESC_T) NULL;
  1922. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  1923. P_BSS_INFO_T prAisBssInfo;
  1924. P_WLAN_BEACON_FRAME_T prWlanBeaconFrame = (P_WLAN_BEACON_FRAME_T) NULL;
  1925. #if CFG_SLT_SUPPORT
  1926. P_SLT_INFO_T prSltInfo = (P_SLT_INFO_T) NULL;
  1927. #endif
  1928. ASSERT(prAdapter);
  1929. ASSERT(prSwRfb);
  1930. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  1931. /* 4 <0> Ignore invalid Beacon Frame */
  1932. if ((prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) <
  1933. (TIMESTAMP_FIELD_LEN + BEACON_INTERVAL_FIELD_LEN + CAP_INFO_FIELD_LEN)) {
  1934. #ifndef _lint
  1935. ASSERT(0);
  1936. #endif /* _lint */
  1937. return rStatus;
  1938. }
  1939. #if CFG_SLT_SUPPORT
  1940. prSltInfo = &prAdapter->rWifiVar.rSltInfo;
  1941. if (prSltInfo->fgIsDUT) {
  1942. DBGLOG(P2P, INFO, "\n\rBCN: RX\n");
  1943. prSltInfo->u4BeaconReceiveCnt++;
  1944. return WLAN_STATUS_SUCCESS;
  1945. } else {
  1946. return WLAN_STATUS_SUCCESS;
  1947. }
  1948. #endif
  1949. prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
  1950. prAisBssInfo = prAdapter->prAisBssInfo;
  1951. prWlanBeaconFrame = (P_WLAN_BEACON_FRAME_T) prSwRfb->pvHeader;
  1952. /* 4 <1> Parse and add into BSS_DESC_T */
  1953. prBssDesc = scanAddToBssDesc(prAdapter, prSwRfb);
  1954. if (prBssDesc) {
  1955. /* 4 <1.1> Beacon Change Detection for Connected BSS */
  1956. if (prAisBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED &&
  1957. ((prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE && prConnSettings->eOPMode != NET_TYPE_IBSS)
  1958. || (prBssDesc->eBSSType == BSS_TYPE_IBSS && prConnSettings->eOPMode != NET_TYPE_INFRA))
  1959. && EQUAL_MAC_ADDR(prBssDesc->aucBSSID, prAisBssInfo->aucBSSID)
  1960. && EQUAL_SSID(prBssDesc->aucSSID, prBssDesc->ucSSIDLen, prAisBssInfo->aucSSID,
  1961. prAisBssInfo->ucSSIDLen)) {
  1962. BOOLEAN fgNeedDisconnect = FALSE;
  1963. #if CFG_SUPPORT_BEACON_CHANGE_DETECTION
  1964. /* <1.1.2> check if supported rate differs */
  1965. if (prAisBssInfo->u2OperationalRateSet != prBssDesc->u2OperationalRateSet)
  1966. fgNeedDisconnect = TRUE;
  1967. #endif
  1968. /* <1.1.3> beacon content change detected, disconnect immediately */
  1969. if (fgNeedDisconnect == TRUE)
  1970. aisBssBeaconTimeout(prAdapter);
  1971. }
  1972. /* 4 <1.1> Update AIS_BSS_INFO */
  1973. if (((prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE && prConnSettings->eOPMode != NET_TYPE_IBSS)
  1974. || (prBssDesc->eBSSType == BSS_TYPE_IBSS && prConnSettings->eOPMode != NET_TYPE_INFRA))) {
  1975. if (prAisBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED) {
  1976. /* *not* checking prBssDesc->fgIsConnected anymore,
  1977. * due to Linksys AP uses " " as hidden SSID, and would have different BSS descriptor */
  1978. if ((!prAisBssInfo->ucDTIMPeriod) &&
  1979. EQUAL_MAC_ADDR(prBssDesc->aucBSSID, prAisBssInfo->aucBSSID) &&
  1980. (prAisBssInfo->eCurrentOPMode == OP_MODE_INFRASTRUCTURE) &&
  1981. ((prWlanBeaconFrame->u2FrameCtrl & MASK_FRAME_TYPE) == MAC_FRAME_BEACON)) {
  1982. prAisBssInfo->ucDTIMPeriod = prBssDesc->ucDTIMPeriod;
  1983. /* sync with firmware for beacon information */
  1984. nicPmIndicateBssConnected(prAdapter, prAisBssInfo->ucBssIndex);
  1985. }
  1986. }
  1987. #if CFG_SUPPORT_ADHOC
  1988. if (EQUAL_SSID(prBssDesc->aucSSID,
  1989. prBssDesc->ucSSIDLen,
  1990. prConnSettings->aucSSID,
  1991. prConnSettings->ucSSIDLen) &&
  1992. (prBssDesc->eBSSType == BSS_TYPE_IBSS) && (prAisBssInfo->eCurrentOPMode == OP_MODE_IBSS)) {
  1993. ibssProcessMatchedBeacon(prAdapter, prAisBssInfo, prBssDesc,
  1994. (UINT_8) HAL_RX_STATUS_GET_RCPI(prSwRfb->prRxStatusGroup3));
  1995. }
  1996. #endif /* CFG_SUPPORT_ADHOC */
  1997. }
  1998. rlmProcessBcn(prAdapter,
  1999. prSwRfb,
  2000. ((P_WLAN_BEACON_FRAME_T) (prSwRfb->pvHeader))->aucInfoElem,
  2001. (prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) -
  2002. (UINT_16) (OFFSET_OF(WLAN_BEACON_FRAME_BODY_T, aucInfoElem[0])));
  2003. mqmProcessBcn(prAdapter,
  2004. prSwRfb,
  2005. ((P_WLAN_BEACON_FRAME_T) (prSwRfb->pvHeader))->aucInfoElem,
  2006. (prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen) -
  2007. (UINT_16) (OFFSET_OF(WLAN_BEACON_FRAME_BODY_T, aucInfoElem[0])));
  2008. /* 4 <3> Send SW_RFB_T to HIF when we perform SCAN for HOST */
  2009. if (prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE || prBssDesc->eBSSType == BSS_TYPE_IBSS) {
  2010. /* for AIS, send to host */
  2011. if (prConnSettings->fgIsScanReqIssued) {
  2012. BOOLEAN fgAddToScanResult;
  2013. fgAddToScanResult = scanCheckBssIsLegal(prAdapter, prBssDesc);
  2014. if (fgAddToScanResult == TRUE)
  2015. rStatus = scanAddScanResult(prAdapter, prBssDesc, prSwRfb);
  2016. }
  2017. }
  2018. #if CFG_ENABLE_WIFI_DIRECT
  2019. if (prAdapter->fgIsP2PRegistered)
  2020. scanP2pProcessBeaconAndProbeResp(prAdapter, prSwRfb, &rStatus, prBssDesc, prWlanBeaconFrame);
  2021. #endif
  2022. }
  2023. return rStatus;
  2024. } /* end of scanProcessBeaconAndProbeResp() */
  2025. /*----------------------------------------------------------------------------*/
  2026. /*!
  2027. * \brief Search the Candidate of BSS Descriptor for JOIN(Infrastructure) or
  2028. * MERGE(AdHoc) according to current Connection Policy.
  2029. *
  2030. * \return Pointer to BSS Descriptor, if found. NULL, if not found
  2031. */
  2032. /*----------------------------------------------------------------------------*/
  2033. P_BSS_DESC_T scanSearchBssDescByPolicy(IN P_ADAPTER_T prAdapter, IN UINT_8 ucBssIndex)
  2034. {
  2035. P_CONNECTION_SETTINGS_T prConnSettings;
  2036. P_BSS_INFO_T prBssInfo;
  2037. P_AIS_SPECIFIC_BSS_INFO_T prAisSpecBssInfo;
  2038. P_SCAN_INFO_T prScanInfo;
  2039. P_LINK_T prBSSDescList;
  2040. P_BSS_DESC_T prBssDesc = (P_BSS_DESC_T) NULL;
  2041. P_BSS_DESC_T prPrimaryBssDesc = (P_BSS_DESC_T) NULL;
  2042. P_BSS_DESC_T prCandidateBssDesc = (P_BSS_DESC_T) NULL;
  2043. P_STA_RECORD_T prStaRec = (P_STA_RECORD_T) NULL;
  2044. P_STA_RECORD_T prPrimaryStaRec;
  2045. P_STA_RECORD_T prCandidateStaRec = (P_STA_RECORD_T) NULL;
  2046. OS_SYSTIME rCurrentTime;
  2047. /* The first one reach the check point will be our candidate */
  2048. BOOLEAN fgIsFindFirst = (BOOLEAN) FALSE;
  2049. BOOLEAN fgIsFindBestRSSI = (BOOLEAN) FALSE;
  2050. BOOLEAN fgIsFindBestEncryptionLevel = (BOOLEAN) FALSE;
  2051. /* BOOLEAN fgIsFindMinChannelLoad = (BOOLEAN)FALSE; */
  2052. /* TODO(Kevin): Support Min Channel Load */
  2053. /* UINT_8 aucChannelLoad[CHANNEL_NUM] = {0}; */
  2054. BOOLEAN fgIsFixedChannel;
  2055. ENUM_BAND_T eBand;
  2056. UINT_8 ucChannel;
  2057. ASSERT(prAdapter);
  2058. prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
  2059. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, ucBssIndex);
  2060. prAisSpecBssInfo = &(prAdapter->rWifiVar.rAisSpecificBssInfo);
  2061. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  2062. prBSSDescList = &prScanInfo->rBSSDescList;
  2063. GET_CURRENT_SYSTIME(&rCurrentTime);
  2064. /* check for fixed channel operation */
  2065. if (prBssInfo->eNetworkType == NETWORK_TYPE_AIS) {
  2066. #if CFG_SUPPORT_CHNL_CONFLICT_REVISE
  2067. fgIsFixedChannel = cnmAisDetectP2PChannel(prAdapter, &eBand, &ucChannel);
  2068. #else
  2069. fgIsFixedChannel = cnmAisInfraChannelFixed(prAdapter, &eBand, &ucChannel);
  2070. #endif
  2071. } else
  2072. fgIsFixedChannel = FALSE;
  2073. #if DBG
  2074. if (prConnSettings->ucSSIDLen < ELEM_MAX_LEN_SSID)
  2075. prConnSettings->aucSSID[prConnSettings->ucSSIDLen] = '\0';
  2076. #endif
  2077. DBGLOG(SCN, INFO, "SEARCH: Num Of BSS_DESC_T = %d, Look for SSID: %s\n",
  2078. prBSSDescList->u4NumElem, prConnSettings->aucSSID);
  2079. /* 4 <1> The outer loop to search for a candidate. */
  2080. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  2081. /* TODO(Kevin): Update Minimum Channel Load Information here */
  2082. #if 0
  2083. DBGLOG(SCN, INFO, "SEARCH: [" MACSTR "], SSID:%s\n", MAC2STR(prBssDesc->aucBSSID), prBssDesc->aucSSID);
  2084. #endif
  2085. /* 4 <2> Check PHY Type and attributes */
  2086. /* 4 <2.1> Check Unsupported BSS PHY Type */
  2087. if (!(prBssDesc->ucPhyTypeSet & (prAdapter->rWifiVar.ucAvailablePhyTypeSet))) {
  2088. DBGLOG(SCN, INFO, "SEARCH: Ignore unsupported ucPhyTypeSet = %x\n", prBssDesc->ucPhyTypeSet);
  2089. continue;
  2090. }
  2091. /* 4 <2.2> Check if has unknown NonHT BSS Basic Rate Set. */
  2092. if (prBssDesc->fgIsUnknownBssBasicRate)
  2093. continue;
  2094. /* 4 <2.3> Check if fixed operation cases should be aware */
  2095. if (fgIsFixedChannel == TRUE && (prBssDesc->eBand != eBand || prBssDesc->ucChannelNum != ucChannel))
  2096. continue;
  2097. /* 4 <2.4> Check if the channel is legal under regulatory domain */
  2098. if (rlmDomainIsLegalChannel(prAdapter, prBssDesc->eBand, prBssDesc->ucChannelNum) == FALSE)
  2099. continue;
  2100. /* 4 <2.5> Check if this BSS_DESC_T is stale */
  2101. if (CHECK_FOR_TIMEOUT(rCurrentTime, prBssDesc->rUpdateTime, SEC_TO_SYSTIME(SCN_BSS_DESC_STALE_SEC)))
  2102. continue;
  2103. /* 4 <3> Check if reach the excessive join retry limit */
  2104. /* NOTE(Kevin): STA_RECORD_T is recorded by TA. */
  2105. prStaRec = cnmGetStaRecByAddress(prAdapter, ucBssIndex, prBssDesc->aucSrcAddr);
  2106. if (prStaRec) {
  2107. /* NOTE(Kevin):
  2108. * The Status Code is the result of a Previous Connection Request,
  2109. * we use this as SCORE for choosing a proper
  2110. * candidate (Also used for compare see <6>)
  2111. * The Reason Code is an indication of the reason why AP reject us,
  2112. * we use this Code for "Reject"
  2113. * a SCAN result to become our candidate(Like a blacklist).
  2114. */
  2115. #if 0 /* TODO(Kevin): */
  2116. if (prStaRec->u2ReasonCode != REASON_CODE_RESERVED) {
  2117. DBGLOG(SCN, INFO,
  2118. "SEARCH: Ignore BSS with previous Reason Code = %d\n", prStaRec->u2ReasonCode);
  2119. continue;
  2120. } else
  2121. #endif
  2122. if (prStaRec->u2StatusCode != STATUS_CODE_SUCCESSFUL) {
  2123. /* NOTE(Kevin): greedy association - after timeout, we'll still
  2124. * try to associate to the AP whose STATUS of conection attempt
  2125. * was not success.
  2126. * We may also use (ucJoinFailureCount x JOIN_RETRY_INTERVAL_SEC) for
  2127. * time bound.
  2128. */
  2129. if ((prStaRec->ucJoinFailureCount < JOIN_MAX_RETRY_FAILURE_COUNT) ||
  2130. (CHECK_FOR_TIMEOUT(rCurrentTime,
  2131. prStaRec->rLastJoinTime,
  2132. SEC_TO_SYSTIME(JOIN_RETRY_INTERVAL_SEC)))) {
  2133. /* NOTE(Kevin): Every JOIN_RETRY_INTERVAL_SEC interval, we can retry
  2134. * JOIN_MAX_RETRY_FAILURE_COUNT times.
  2135. */
  2136. if (prStaRec->ucJoinFailureCount >= JOIN_MAX_RETRY_FAILURE_COUNT)
  2137. prStaRec->ucJoinFailureCount = 0;
  2138. DBGLOG(SCN, INFO,
  2139. "SEARCH:Try to join BSS again,Status Code=%d(Curr=%ld/Last Join=%ld)\n",
  2140. prStaRec->u2StatusCode, rCurrentTime, prStaRec->rLastJoinTime);
  2141. } else {
  2142. DBGLOG(SCN, INFO,
  2143. "SEARCH: Ignore BSS which reach maximum Join Retry Count = %d\n",
  2144. JOIN_MAX_RETRY_FAILURE_COUNT);
  2145. continue;
  2146. }
  2147. }
  2148. }
  2149. /* 4 <4> Check for various NETWORK conditions */
  2150. if (prBssInfo->eNetworkType == NETWORK_TYPE_AIS) {
  2151. /* 4 <4.1> Check BSS Type for the corresponding Operation Mode in Connection Setting */
  2152. /* NOTE(Kevin): For NET_TYPE_AUTO_SWITCH, we will always pass following check. */
  2153. if (((prConnSettings->eOPMode == NET_TYPE_INFRA) &&
  2154. (prBssDesc->eBSSType != BSS_TYPE_INFRASTRUCTURE)) ||
  2155. ((prConnSettings->eOPMode == NET_TYPE_IBSS
  2156. || prConnSettings->eOPMode == NET_TYPE_DEDICATED_IBSS)
  2157. && (prBssDesc->eBSSType != BSS_TYPE_IBSS))) {
  2158. DBGLOG(SCN, INFO, "SEARCH: Ignore eBSSType = %s\n",
  2159. ((prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE) ? "INFRASTRUCTURE" : "IBSS"));
  2160. continue;
  2161. }
  2162. /* 4 <4.2> Check AP's BSSID if OID_802_11_BSSID has been set. */
  2163. if ((prConnSettings->fgIsConnByBssidIssued) &&
  2164. (prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE)) {
  2165. if (UNEQUAL_MAC_ADDR(prConnSettings->aucBSSID, prBssDesc->aucBSSID)) {
  2166. DBGLOG(SCN, LOUD, "SEARCH: Ignore due to BSSID was not matched!\n");
  2167. continue;
  2168. }
  2169. }
  2170. #if CFG_SUPPORT_ADHOC
  2171. /* 4 <4.3> Check for AdHoc Mode */
  2172. if (prBssDesc->eBSSType == BSS_TYPE_IBSS) {
  2173. OS_SYSTIME rCurrentTime;
  2174. /* 4 <4.3.1> Check if this SCAN record has been updated recently for IBSS. */
  2175. /* NOTE(Kevin): Because some STA may change its BSSID frequently after it
  2176. * create the IBSS - e.g. IPN2220, so we need to make sure we get the new one.
  2177. * For BSS, if the old record was matched, however it won't be able to pass
  2178. * the Join Process later.
  2179. */
  2180. GET_CURRENT_SYSTIME(&rCurrentTime);
  2181. if (CHECK_FOR_TIMEOUT(rCurrentTime, prBssDesc->rUpdateTime,
  2182. SEC_TO_SYSTIME(SCN_ADHOC_BSS_DESC_TIMEOUT_SEC))) {
  2183. DBGLOG(SCN, LOUD,
  2184. "SEARCH: Skip old record of BSS Descriptor - BSSID:["
  2185. MACSTR "]\n\n", MAC2STR(prBssDesc->aucBSSID));
  2186. continue;
  2187. }
  2188. /* 4 <4.3.2> Check Peer's capability */
  2189. if (ibssCheckCapabilityForAdHocMode(prAdapter, prBssDesc) == WLAN_STATUS_FAILURE) {
  2190. DBGLOG(SCN, INFO,
  2191. "SEARCH: Ignore BSS DESC MAC: " MACSTR
  2192. ", Capability is not supported for current AdHoc Mode.\n",
  2193. MAC2STR(prPrimaryBssDesc->aucBSSID));
  2194. continue;
  2195. }
  2196. /* 4 <4.3.3> Compare TSF */
  2197. if (prBssInfo->fgIsBeaconActivated &&
  2198. UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prBssDesc->aucBSSID)) {
  2199. DBGLOG(SCN, LOUD,
  2200. "SEARCH: prBssDesc->fgIsLargerTSF = %d\n", prBssDesc->fgIsLargerTSF);
  2201. if (!prBssDesc->fgIsLargerTSF) {
  2202. DBGLOG(SCN, INFO,
  2203. "SEARCH: Ignore BSS DESC MAC: [" MACSTR
  2204. "], Smaller TSF\n", MAC2STR(prBssDesc->aucBSSID));
  2205. continue;
  2206. }
  2207. }
  2208. }
  2209. #endif /* CFG_SUPPORT_ADHOC */
  2210. }
  2211. #if 0 /* TODO(Kevin): For IBSS */
  2212. /* 4 <2.c> Check if this SCAN record has been updated recently for IBSS. */
  2213. /* NOTE(Kevin): Because some STA may change its BSSID frequently after it
  2214. * create the IBSS, so we need to make sure we get the new one.
  2215. * For BSS, if the old record was matched, however it won't be able to pass
  2216. * the Join Process later.
  2217. */
  2218. if (prBssDesc->eBSSType == BSS_TYPE_IBSS) {
  2219. OS_SYSTIME rCurrentTime;
  2220. GET_CURRENT_SYSTIME(&rCurrentTime);
  2221. if (CHECK_FOR_TIMEOUT(rCurrentTime, prBssDesc->rUpdateTime,
  2222. SEC_TO_SYSTIME(BSS_DESC_TIMEOUT_SEC))) {
  2223. DBGLOG(SCAN, TRACE,
  2224. "Skip old record of BSS Descriptor - BSSID:[" MACSTR
  2225. "]\n\n", MAC2STR(prBssDesc->aucBSSID));
  2226. continue;
  2227. }
  2228. }
  2229. if ((prBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE) &&
  2230. (prAdapter->eConnectionState == MEDIA_STATE_CONNECTED)) {
  2231. OS_SYSTIME rCurrentTime;
  2232. GET_CURRENT_SYSTIME(&rCurrentTime);
  2233. if (CHECK_FOR_TIMEOUT(rCurrentTime, prBssDesc->rUpdateTime,
  2234. SEC_TO_SYSTIME(BSS_DESC_TIMEOUT_SEC))) {
  2235. DBGLOG(SCAN, TRACE,
  2236. "Skip old record of BSS Descriptor - BSSID:[" MACSTR
  2237. "]\n\n", MAC2STR(prBssDesc->aucBSSID));
  2238. continue;
  2239. }
  2240. }
  2241. /* 4 <4B> Check for IBSS AdHoc Mode. */
  2242. /* Skip if one or more BSS Basic Rate are not supported by current AdHocMode */
  2243. if (prPrimaryBssDesc->eBSSType == BSS_TYPE_IBSS) {
  2244. /* 4 <4B.1> Check if match the Capability of current IBSS AdHoc Mode. */
  2245. if (ibssCheckCapabilityForAdHocMode(prAdapter, prPrimaryBssDesc) == WLAN_STATUS_FAILURE) {
  2246. DBGLOG(SCAN, TRACE,
  2247. "Ignore BSS DESC MAC: " MACSTR
  2248. ", Capability is not supported for current AdHoc Mode.\n",
  2249. MAC2STR(prPrimaryBssDesc->aucBSSID));
  2250. continue;
  2251. }
  2252. /* 4 <4B.2> IBSS Merge Decision Flow for SEARCH STATE. */
  2253. if (prAdapter->fgIsIBSSActive &&
  2254. UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prPrimaryBssDesc->aucBSSID)) {
  2255. if (!fgIsLocalTSFRead) {
  2256. NIC_GET_CURRENT_TSF(prAdapter, &rCurrentTsf);
  2257. DBGLOG(SCAN, TRACE,
  2258. "\n\nCurrent TSF : %08lx-%08lx\n\n",
  2259. rCurrentTsf.u.HighPart, rCurrentTsf.u.LowPart);
  2260. }
  2261. if (rCurrentTsf.QuadPart > prPrimaryBssDesc->u8TimeStamp.QuadPart) {
  2262. DBGLOG(SCAN, TRACE,
  2263. "Ignore BSS DESC MAC: [" MACSTR
  2264. "], Current BSSID: [" MACSTR "].\n",
  2265. MAC2STR(prPrimaryBssDesc->aucBSSID), MAC2STR(prBssInfo->aucBSSID));
  2266. DBGLOG(SCAN, TRACE,
  2267. "\n\nBSS's TSF : %08lx-%08lx\n\n",
  2268. prPrimaryBssDesc->u8TimeStamp.u.HighPart,
  2269. prPrimaryBssDesc->u8TimeStamp.u.LowPart);
  2270. prPrimaryBssDesc->fgIsLargerTSF = FALSE;
  2271. continue;
  2272. } else {
  2273. prPrimaryBssDesc->fgIsLargerTSF = TRUE;
  2274. }
  2275. }
  2276. }
  2277. /* 4 <5> Check the Encryption Status. */
  2278. if (rsnPerformPolicySelection(prPrimaryBssDesc)) {
  2279. if (prPrimaryBssDesc->ucEncLevel > 0) {
  2280. fgIsFindBestEncryptionLevel = TRUE;
  2281. fgIsFindFirst = FALSE;
  2282. }
  2283. } else {
  2284. /* Can't pass the Encryption Status Check, get next one */
  2285. continue;
  2286. }
  2287. /* For RSN Pre-authentication, update the PMKID canidate list for
  2288. same SSID and encrypt status */
  2289. /* Update PMKID candicate list. */
  2290. if (prAdapter->rWifiVar.rConnSettings.eAuthMode == AUTH_MODE_WPA2) {
  2291. rsnUpdatePmkidCandidateList(prPrimaryBssDesc);
  2292. if (prAdapter->rWifiVar.rAisBssInfo.u4PmkidCandicateCount)
  2293. prAdapter->rWifiVar.rAisBssInfo.fgIndicatePMKID = rsnCheckPmkidCandicate();
  2294. }
  2295. #endif
  2296. prPrimaryBssDesc = (P_BSS_DESC_T) NULL;
  2297. /* 4 <6> Check current Connection Policy. */
  2298. switch (prConnSettings->eConnectionPolicy) {
  2299. case CONNECT_BY_SSID_BEST_RSSI:
  2300. /* Choose Hidden SSID to join only if the `fgIsEnableJoin...` is TRUE */
  2301. if (prAdapter->rWifiVar.fgEnableJoinToHiddenSSID && prBssDesc->fgIsHiddenSSID) {
  2302. /* NOTE(Kevin): following if () statement means that
  2303. * If Target is hidden, then we won't connect when user specify SSID_ANY policy.
  2304. */
  2305. if (prConnSettings->ucSSIDLen) {
  2306. prPrimaryBssDesc = prBssDesc;
  2307. fgIsFindBestRSSI = TRUE;
  2308. }
  2309. } else if (EQUAL_SSID(prBssDesc->aucSSID,
  2310. prBssDesc->ucSSIDLen,
  2311. prConnSettings->aucSSID, prConnSettings->ucSSIDLen)) {
  2312. prPrimaryBssDesc = prBssDesc;
  2313. fgIsFindBestRSSI = TRUE;
  2314. }
  2315. break;
  2316. case CONNECT_BY_SSID_ANY:
  2317. /* NOTE(Kevin): In this policy, we don't know the desired
  2318. * SSID from user, so we should exclude the Hidden SSID from scan list.
  2319. * And because we refuse to connect to Hidden SSID node at the beginning, so
  2320. * when the JOIN Module deal with a BSS_DESC_T which has fgIsHiddenSSID == TRUE,
  2321. * then the Connection Settings must be valid without doubt.
  2322. */
  2323. if (!prBssDesc->fgIsHiddenSSID) {
  2324. prPrimaryBssDesc = prBssDesc;
  2325. fgIsFindFirst = TRUE;
  2326. }
  2327. break;
  2328. case CONNECT_BY_BSSID:
  2329. if (EQUAL_MAC_ADDR(prBssDesc->aucBSSID, prConnSettings->aucBSSID))
  2330. prPrimaryBssDesc = prBssDesc;
  2331. break;
  2332. default:
  2333. break;
  2334. }
  2335. /* Primary Candidate was not found */
  2336. if (prPrimaryBssDesc == NULL)
  2337. continue;
  2338. /* 4 <7> Check the Encryption Status. */
  2339. if (prPrimaryBssDesc->eBSSType == BSS_TYPE_INFRASTRUCTURE) {
  2340. #if CFG_SUPPORT_WAPI
  2341. if (prAdapter->rWifiVar.rConnSettings.fgWapiMode) {
  2342. if (wapiPerformPolicySelection(prAdapter, prPrimaryBssDesc)) {
  2343. fgIsFindFirst = TRUE;
  2344. } else {
  2345. /* Can't pass the Encryption Status Check, get next one */
  2346. continue;
  2347. }
  2348. } else
  2349. #endif
  2350. if (rsnPerformPolicySelection(prAdapter, prPrimaryBssDesc)) {
  2351. if (prAisSpecBssInfo->fgCounterMeasure) {
  2352. DBGLOG(RSN, INFO, "Skip while at counter measure period!!!\n");
  2353. continue;
  2354. }
  2355. if (prPrimaryBssDesc->ucEncLevel > 0) {
  2356. fgIsFindBestEncryptionLevel = TRUE;
  2357. fgIsFindFirst = FALSE;
  2358. }
  2359. } else {
  2360. /* Can't pass the Encryption Status Check, get next one */
  2361. continue;
  2362. }
  2363. } else {
  2364. /* Todo:: P2P and BOW Policy Selection */
  2365. }
  2366. prPrimaryStaRec = prStaRec;
  2367. /* 4 <8> Compare the Candidate and the Primary Scan Record. */
  2368. if (!prCandidateBssDesc) {
  2369. prCandidateBssDesc = prPrimaryBssDesc;
  2370. prCandidateStaRec = prPrimaryStaRec;
  2371. /* 4 <8.1> Condition - Get the first matched one. */
  2372. if (fgIsFindFirst)
  2373. break;
  2374. } else {
  2375. /* 4 <6D> Condition - Visible SSID win Hidden SSID. */
  2376. if (prCandidateBssDesc->fgIsHiddenSSID) {
  2377. if (!prPrimaryBssDesc->fgIsHiddenSSID) {
  2378. prCandidateBssDesc = prPrimaryBssDesc; /* The non Hidden SSID win. */
  2379. prCandidateStaRec = prPrimaryStaRec;
  2380. continue;
  2381. }
  2382. } else {
  2383. if (prPrimaryBssDesc->fgIsHiddenSSID)
  2384. continue;
  2385. }
  2386. /* 4 <6E> Condition - Choose the one with better RCPI(RSSI). */
  2387. if (fgIsFindBestRSSI) {
  2388. /* TODO(Kevin): We shouldn't compare the actual value, we should
  2389. * allow some acceptable tolerance of some RSSI percentage here.
  2390. */
  2391. DBGLOG(SCN, TRACE,
  2392. "Candidate [" MACSTR "]: RCPI = %d, joinFailCnt=%d, Primary [" MACSTR
  2393. "]: RCPI = %d, joinFailCnt=%d\n", MAC2STR(prCandidateBssDesc->aucBSSID),
  2394. prCandidateBssDesc->ucRCPI, prCandidateBssDesc->ucJoinFailureCount,
  2395. MAC2STR(prPrimaryBssDesc->aucBSSID),
  2396. prPrimaryBssDesc->ucRCPI,
  2397. prPrimaryBssDesc->ucJoinFailureCount);
  2398. ASSERT(!(prCandidateBssDesc->fgIsConnected && prPrimaryBssDesc->fgIsConnected));
  2399. if (prPrimaryBssDesc->ucJoinFailureCount >= SCN_BSS_JOIN_FAIL_THRESOLD) {
  2400. /* give a chance to do join if join fail before
  2401. * SCN_BSS_DECRASE_JOIN_FAIL_CNT_SEC seconds */
  2402. if (CHECK_FOR_TIMEOUT(rCurrentTime, prBssDesc->rJoinFailTime,
  2403. SEC_TO_SYSTIME(SCN_BSS_JOIN_FAIL_CNT_RESET_SEC))) {
  2404. prBssDesc->ucJoinFailureCount -= SCN_BSS_JOIN_FAIL_RESET_STEP;
  2405. DBGLOG(AIS, INFO,
  2406. "decrease join fail count for Bss " MACSTR
  2407. " to %u, timeout second %d\n", MAC2STR(prBssDesc->aucBSSID),
  2408. prBssDesc->ucJoinFailureCount, SCN_BSS_JOIN_FAIL_CNT_RESET_SEC);
  2409. }
  2410. }
  2411. /* NOTE: To prevent SWING, we do roaming only if target AP
  2412. * has at least 5dBm larger than us. */
  2413. if (prCandidateBssDesc->fgIsConnected) {
  2414. if ((prCandidateBssDesc->ucRCPI + ROAMING_NO_SWING_RCPI_STEP <=
  2415. prPrimaryBssDesc->ucRCPI)
  2416. && prPrimaryBssDesc->ucJoinFailureCount < SCN_BSS_JOIN_FAIL_THRESOLD) {
  2417. prCandidateBssDesc = prPrimaryBssDesc;
  2418. prCandidateStaRec = prPrimaryStaRec;
  2419. continue;
  2420. }
  2421. } else if (prPrimaryBssDesc->fgIsConnected) {
  2422. if ((prCandidateBssDesc->ucRCPI <
  2423. prPrimaryBssDesc->ucRCPI + ROAMING_NO_SWING_RCPI_STEP)
  2424. || (prCandidateBssDesc->ucJoinFailureCount >= SCN_BSS_JOIN_FAIL_THRESOLD)) {
  2425. prCandidateBssDesc = prPrimaryBssDesc;
  2426. prCandidateStaRec = prPrimaryStaRec;
  2427. continue;
  2428. }
  2429. } else if (prPrimaryBssDesc->ucJoinFailureCount >= SCN_BSS_JOIN_FAIL_THRESOLD)
  2430. continue;
  2431. else if (prCandidateBssDesc->ucJoinFailureCount >= SCN_BSS_JOIN_FAIL_THRESOLD ||
  2432. prCandidateBssDesc->ucRCPI < prPrimaryBssDesc->ucRCPI) {
  2433. prCandidateBssDesc = prPrimaryBssDesc;
  2434. prCandidateStaRec = prPrimaryStaRec;
  2435. continue;
  2436. }
  2437. }
  2438. #if 0
  2439. /* If reach here, that means they have the same Encryption Score, and
  2440. * both RSSI value are close too.
  2441. */
  2442. /* 4 <6F> Seek the minimum Channel Load for less interference. */
  2443. if (fgIsFindMinChannelLoad) {
  2444. /* ToDo:: Nothing */
  2445. /* TODO(Kevin): Check which one has minimum channel load in its channel */
  2446. }
  2447. #endif
  2448. }
  2449. }
  2450. return prCandidateBssDesc;
  2451. } /* end of scanSearchBssDescByPolicy() */
  2452. VOID scanReportBss2Cfg80211(IN P_ADAPTER_T prAdapter, IN ENUM_BSS_TYPE_T eBSSType, IN P_BSS_DESC_T SpecificprBssDesc)
  2453. {
  2454. P_SCAN_INFO_T prScanInfo = NULL;
  2455. P_LINK_T prBSSDescList = NULL;
  2456. P_BSS_DESC_T prBssDesc = NULL;
  2457. RF_CHANNEL_INFO_T rChannelInfo;
  2458. ASSERT(prAdapter);
  2459. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  2460. prBSSDescList = &prScanInfo->rBSSDescList;
  2461. DBGLOG(SCN, TRACE, "scanReportBss2Cfg80211\n");
  2462. if (SpecificprBssDesc) {
  2463. {
  2464. /* check BSSID is legal channel */
  2465. if (!scanCheckBssIsLegal(prAdapter, SpecificprBssDesc))
  2466. return;
  2467. DBGLOG(SCN, TRACE, "Report Specific SSID[%s]\n", SpecificprBssDesc->aucSSID);
  2468. if (eBSSType == BSS_TYPE_INFRASTRUCTURE) {
  2469. kalIndicateBssInfo(prAdapter->prGlueInfo,
  2470. (PUINT_8) SpecificprBssDesc->aucRawBuf,
  2471. SpecificprBssDesc->u2RawLength,
  2472. SpecificprBssDesc->ucChannelNum,
  2473. RCPI_TO_dBm(SpecificprBssDesc->ucRCPI));
  2474. } else {
  2475. rChannelInfo.ucChannelNum = SpecificprBssDesc->ucChannelNum;
  2476. rChannelInfo.eBand = SpecificprBssDesc->eBand;
  2477. kalP2PIndicateBssInfo(prAdapter->prGlueInfo,
  2478. (PUINT_8) SpecificprBssDesc->aucRawBuf,
  2479. SpecificprBssDesc->u2RawLength,
  2480. &rChannelInfo, RCPI_TO_dBm(SpecificprBssDesc->ucRCPI));
  2481. }
  2482. #if CFG_ENABLE_WIFI_DIRECT
  2483. SpecificprBssDesc->fgIsP2PReport = FALSE;
  2484. #endif
  2485. }
  2486. } else {
  2487. /* Search BSS Desc from current SCAN result list. */
  2488. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  2489. #if CFG_AUTO_CHANNEL_SEL_SUPPORT
  2490. /* Auto Channel Selection:Record the AP Number */
  2491. P_PARAM_CHN_LOAD_INFO prChnLoad = NULL;
  2492. if ((prBssDesc->ucChannelNum <= 48) && (prBssDesc->ucChannelNum >= 1)) {
  2493. if (prBssDesc->ucChannelNum <= 14)
  2494. prChnLoad =
  2495. (P_PARAM_CHN_LOAD_INFO)&(prAdapter->rWifiVar.
  2496. rChnLoadInfo.rEachChnLoad[prBssDesc->
  2497. ucChannelNum - 1]);
  2498. else
  2499. prChnLoad =
  2500. (P_PARAM_CHN_LOAD_INFO)&(prAdapter->rWifiVar.
  2501. rChnLoadInfo.rEachChnLoad[(prBssDesc->
  2502. ucChannelNum / 4) +
  2503. 5]);
  2504. prChnLoad->u2APNum++;
  2505. prChnLoad->ucChannel = prBssDesc->ucChannelNum;
  2506. }
  2507. if (prChnLoad)
  2508. DBGLOG(SCN, TRACE, "chNum=%d,apNum=%d\n", prBssDesc->ucChannelNum, prChnLoad->u2APNum);
  2509. #endif
  2510. /* check BSSID is legal channel */
  2511. if (!scanCheckBssIsLegal(prAdapter, prBssDesc)) {
  2512. DBGLOG(SCN, TRACE, "Remove SSID[%s %d]\n", prBssDesc->aucSSID, prBssDesc->ucChannelNum);
  2513. continue;
  2514. }
  2515. if ((prBssDesc->eBSSType == eBSSType)
  2516. #if CFG_ENABLE_WIFI_DIRECT
  2517. || ((eBSSType == BSS_TYPE_P2P_DEVICE) && (prBssDesc->fgIsP2PReport == TRUE))
  2518. #endif
  2519. ) {
  2520. DBGLOG(SCN, TRACE, "Report ALL SSID[%s %d]\n",
  2521. prBssDesc->aucSSID, prBssDesc->ucChannelNum);
  2522. if (eBSSType == BSS_TYPE_INFRASTRUCTURE) {
  2523. if (prBssDesc->u2RawLength != 0) {
  2524. kalIndicateBssInfo(prAdapter->prGlueInfo,
  2525. (PUINT_8) prBssDesc->aucRawBuf,
  2526. prBssDesc->u2RawLength,
  2527. prBssDesc->ucChannelNum,
  2528. RCPI_TO_dBm(prBssDesc->ucRCPI));
  2529. kalMemZero(prBssDesc->aucRawBuf, CFG_RAW_BUFFER_SIZE);
  2530. prBssDesc->u2RawLength = 0;
  2531. #if CFG_ENABLE_WIFI_DIRECT
  2532. prBssDesc->fgIsP2PReport = FALSE;
  2533. #endif
  2534. }
  2535. } else {
  2536. #if CFG_ENABLE_WIFI_DIRECT
  2537. if (prBssDesc->fgIsP2PReport == TRUE) {
  2538. #endif
  2539. rChannelInfo.ucChannelNum = prBssDesc->ucChannelNum;
  2540. rChannelInfo.eBand = prBssDesc->eBand;
  2541. kalP2PIndicateBssInfo(prAdapter->prGlueInfo,
  2542. (PUINT_8) prBssDesc->aucRawBuf,
  2543. prBssDesc->u2RawLength,
  2544. &rChannelInfo, RCPI_TO_dBm(prBssDesc->ucRCPI));
  2545. /* do not clear it then we can pass the bss in Specific report */
  2546. /* kalMemZero(prBssDesc->aucRawBuf,CFG_RAW_BUFFER_SIZE); */
  2547. /*
  2548. the BSS entry will not be cleared after scan done.
  2549. So if we dont receive the BSS in next scan, we cannot
  2550. pass it. We use u2RawLength for the purpose.
  2551. */
  2552. /* prBssDesc->u2RawLength=0; */
  2553. #if CFG_ENABLE_WIFI_DIRECT
  2554. prBssDesc->fgIsP2PReport = FALSE;
  2555. }
  2556. #endif
  2557. }
  2558. }
  2559. }
  2560. #if CFG_AUTO_CHANNEL_SEL_SUPPORT
  2561. prAdapter->rWifiVar.rChnLoadInfo.fgDataReadyBit = TRUE;
  2562. #endif
  2563. }
  2564. }
  2565. #if CFG_SUPPORT_PASSPOINT
  2566. /*----------------------------------------------------------------------------*/
  2567. /*!
  2568. * @brief Find the corresponding BSS Descriptor according to given BSSID
  2569. *
  2570. * @param[in] prAdapter Pointer to the Adapter structure.
  2571. * @param[in] aucBSSID Given BSSID.
  2572. * @param[in] fgCheckSsid Need to check SSID or not. (for multiple SSID with single BSSID cases)
  2573. * @param[in] prSsid Specified SSID
  2574. *
  2575. * @return Pointer to BSS Descriptor, if found. NULL, if not found
  2576. */
  2577. /*----------------------------------------------------------------------------*/
  2578. P_BSS_DESC_T scanSearchBssDescByBssidAndLatestUpdateTime(IN P_ADAPTER_T prAdapter, IN UINT_8 aucBSSID[])
  2579. {
  2580. P_SCAN_INFO_T prScanInfo;
  2581. P_LINK_T prBSSDescList;
  2582. P_BSS_DESC_T prBssDesc;
  2583. P_BSS_DESC_T prDstBssDesc = (P_BSS_DESC_T) NULL;
  2584. OS_SYSTIME rLatestUpdateTime = 0;
  2585. ASSERT(prAdapter);
  2586. ASSERT(aucBSSID);
  2587. prScanInfo = &(prAdapter->rWifiVar.rScanInfo);
  2588. prBSSDescList = &prScanInfo->rBSSDescList;
  2589. /* Search BSS Desc from current SCAN result list. */
  2590. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  2591. if (EQUAL_MAC_ADDR(prBssDesc->aucBSSID, aucBSSID)) {
  2592. if (!rLatestUpdateTime || CHECK_FOR_EXPIRATION(prBssDesc->rUpdateTime, rLatestUpdateTime)) {
  2593. prDstBssDesc = prBssDesc;
  2594. COPY_SYSTIME(rLatestUpdateTime, prBssDesc->rUpdateTime);
  2595. }
  2596. }
  2597. }
  2598. return prDstBssDesc;
  2599. } /* end of scanSearchBssDescByBssid() */
  2600. #endif /* CFG_SUPPORT_PASSPOINT */
  2601. #if CFG_SUPPORT_AGPS_ASSIST
  2602. VOID scanReportScanResultToAgps(P_ADAPTER_T prAdapter)
  2603. {
  2604. P_LINK_T prBSSDescList = &prAdapter->rWifiVar.rScanInfo.rBSSDescList;
  2605. P_BSS_DESC_T prBssDesc = NULL;
  2606. P_SCAN_INFO_T prScanInfo = &prAdapter->rWifiVar.rScanInfo;
  2607. UINT_8 ucIndex = 0;
  2608. P_AGPS_AP_LIST_T prAgpsApList = kalMemAlloc(sizeof(AGPS_AP_LIST_T), VIR_MEM_TYPE);
  2609. P_AGPS_AP_INFO_T prAgpsInfo = &prAgpsApList->arApInfo[0];
  2610. if (prAgpsApList == NULL)
  2611. return;
  2612. LINK_FOR_EACH_ENTRY(prBssDesc, prBSSDescList, rLinkEntry, BSS_DESC_T) {
  2613. if (prBssDesc->rUpdateTime < prScanInfo->rLastScanCompletedTime)
  2614. continue;
  2615. COPY_MAC_ADDR(prAgpsInfo->aucBSSID, prBssDesc->aucBSSID);
  2616. prAgpsInfo->ePhyType = AGPS_PHY_G;
  2617. prAgpsInfo->u2Channel = prBssDesc->ucChannelNum;
  2618. prAgpsInfo->i2ApRssi = RCPI_TO_dBm(prBssDesc->ucRCPI);
  2619. prAgpsInfo++;
  2620. ucIndex++;
  2621. if (ucIndex == SCN_AGPS_AP_LIST_MAX_NUM)
  2622. break;
  2623. }
  2624. prAgpsApList->ucNum = ucIndex;
  2625. GET_CURRENT_SYSTIME(&prScanInfo->rLastScanCompletedTime);
  2626. /* DBGLOG(SCN, INFO, ("num of scan list:%d\n", ucIndex)); */
  2627. kalIndicateAgpsNotify(prAdapter, AGPS_EVENT_WLAN_AP_LIST, (PUINT_8) prAgpsApList, sizeof(AGPS_AP_LIST_T));
  2628. kalMemFree(prAgpsApList, VIR_MEM_TYPE, sizeof(AGPS_AP_LIST_T));
  2629. }
  2630. #endif /* CFG_SUPPORT_AGPS_ASSIST */