bss.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/bss.c#3
  3. */
  4. /*! \file "bss.c"
  5. \brief This file contains the functions for creating BSS(AP)/IBSS(AdHoc).
  6. This file contains the functions for BSS(AP)/IBSS(AdHoc). We may create a BSS/IBSS
  7. network, or merge with exist IBSS network and sending Beacon Frame or reply
  8. the Probe Response Frame for received Probe Request Frame.
  9. */
  10. /*
  11. ** Log: bss.c
  12. **
  13. ** 09 03 2013 cp.wu
  14. ** add path for reassociation
  15. **
  16. ** 08 30 2012 chinglan.wang
  17. ** [ALPS00349664] [6577JB][WIFI] Phone can not connect to AP secured with AES via WPS in 802.11n Only
  18. ** .
  19. **
  20. ** 07 26 2012 yuche.tsai
  21. ** [ALPS00324337] [ALPS.JB][Hot-Spot] Driver update for Hot-Spot
  22. ** Update driver code of ALPS.JB for hot-spot.
  23. *
  24. * 07 17 2012 yuche.tsai
  25. * NULL
  26. * Let netdev bring up.
  27. *
  28. * 07 17 2012 yuche.tsai
  29. * NULL
  30. * Compile no error before trial run.
  31. *
  32. * 06 14 2012 chinglan.wang
  33. * NULL
  34. * Fix the losing of the HT IE in assoc request..
  35. *
  36. * 06 13 2012 yuche.tsai
  37. * NULL
  38. * Update maintrunk driver.
  39. * Add support for driver compose assoc request frame.
  40. *
  41. * 03 08 2012 yuche.tsai
  42. * NULL
  43. * Fix FW assert when start Hot-Spot.
  44. *
  45. * 03 02 2012 terry.wu
  46. * NULL
  47. * Snc CFG80211 modification for ICS migration from branch 2.2.
  48. *
  49. * 01 20 2012 chinglan.wang
  50. * 03 02 2012 terry.wu
  51. * NULL
  52. * Fix the WPA-PSK TKIP and WPA2-PSK AES security mode bug.
  53. *
  54. * NULL
  55. * Sync CFG80211 modification from branch 2,2.
  56. *
  57. * 01 15 2012 yuche.tsai
  58. * NULL
  59. * Fix wrong basic rate issue.
  60. *
  61. * 01 13 2012 yuche.tsai
  62. * NULL
  63. * WiFi Hot Spot Tethering for ICS ALPHA testing version.
  64. *
  65. * 11 03 2011 cm.chang
  66. * [WCXRP00000997] [MT6620 Wi-Fi][Driver][FW] Handle change of BSS preamble type and slot time
  67. * Always set short slot time to TRUE initially in AP mode
  68. *
  69. * 11 03 2011 wh.su
  70. * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
  71. * change the DBGLOG for "\n" and "\r\n". LABEL to LOUD for XLOG
  72. *
  73. * 09 14 2011 yuche.tsai
  74. * NULL
  75. * Add P2P IE in assoc response.
  76. *
  77. * 04 18 2011 terry.wu
  78. * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
  79. * Remove flag CFG_WIFI_DIRECT_MOVED.
  80. *
  81. * 04 12 2011 eddie.chen
  82. * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
  83. * Fix the sta index in processing security frame
  84. * Simple flow control for TC4 to avoid mgt frames for PS STA to occupy the TC4
  85. * Add debug message.
  86. *
  87. * 04 08 2011 eddie.chen
  88. * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
  89. * Fix for sigma
  90. *
  91. * 03 29 2011 eddie.chen
  92. * [WCXRP00000608] [MT6620 Wi-Fi][DRV] Change wmm parameters in beacon
  93. * Change wmm parameters in beacon.
  94. *
  95. * 03 29 2011 yuche.tsai
  96. * [WCXRP00000607] [Volunteer Patch][MT6620][Driver] Coding Style Fix for klocwork scan.
  97. * Fix klocwork issue.
  98. *
  99. * 03 19 2011 yuche.tsai
  100. * [WCXRP00000581] [Volunteer Patch][MT6620][Driver] P2P IE in Assoc Req Issue
  101. * Make assoc req to append P2P IE if wifi direct is enabled.
  102. *
  103. * 03 11 2011 chinglan.wang
  104. * [WCXRP00000537] [MT6620 Wi-Fi][Driver] Can not connect to 802.11b/g/n mixed AP with WEP security.
  105. * .
  106. *
  107. * 03 03 2011 george.huang
  108. * [WCXRP00000508] [MT6620 Wi-Fi][Driver] aware of beacon MSDU will be free, after BSS deactivated
  109. * .
  110. *
  111. * 03 03 2011 george.huang
  112. * [WCXRP00000508] [MT6620 Wi-Fi][Driver] aware of beacon MSDU will be free, after BSS deactivated
  113. * modify to handle if beacon MSDU been released when BSS deactivated
  114. *
  115. * 03 02 2011 wh.su
  116. * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
  117. * add code to let the beacon and probe response for Auto GO WSC .
  118. *
  119. * 03 02 2011 wh.su
  120. * [WCXRP00000448] [MT6620 Wi-Fi][Driver] Fixed WSC IE not send out at probe request
  121. * Add code to send beacon and probe response WSC IE at Auto GO.
  122. *
  123. * 02 17 2011 eddie.chen
  124. * [WCXRP00000458] [MT6620 Wi-Fi][Driver] BOW Concurrent - ProbeResp was exist in other channel
  125. * 1) Change GetFrameAction decision when BSS is absent.
  126. * 2) Check channel and resource in processing ProbeRequest
  127. *
  128. * 02 12 2011 yuche.tsai
  129. * [WCXRP00000441] [Volunteer Patch][MT6620][Driver] BoW can not create desired station type when Hot Spot is enabled.
  130. * bss should create station record type according to callers input.
  131. *
  132. * 02 11 2011 terry.wu
  133. * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
  134. * In p2p link function, check networktype before calling p2p function.
  135. *
  136. * 02 11 2011 terry.wu
  137. * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
  138. * Modify p2p link function to avoid assert.
  139. *
  140. * 01 26 2011 cm.chang
  141. * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
  142. * .
  143. *
  144. * 01 25 2011 yuche.tsai
  145. * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
  146. * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
  147. *
  148. * 01 25 2011 eddie.chen
  149. * [WCXRP00000385] [MT6620 Wi-Fi][DRV] Add destination decision for forwarding packets
  150. * Fix the compile error in windows.
  151. *
  152. * 01 24 2011 eddie.chen
  153. * [WCXRP00000385] [MT6620 Wi-Fi][DRV] Add destination decision for forwarding packets
  154. * Add destination decision in AP mode.
  155. *
  156. * 01 24 2011 terry.wu
  157. * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
  158. * .Fix typo and missing entry
  159. *
  160. * 12 30 2010 eddie.chen
  161. * [WCXRP00000322] Add WMM IE in beacon,
  162. Add per station flow control when STA is in PS
  163. * Fix prBssInfo->aucCWminLog to prBssInfo->aucCWminLogForBcast
  164. *
  165. * 12 29 2010 eddie.chen
  166. * [WCXRP00000322] Add WMM IE in beacon,
  167. Add per station flow control when STA is in PS
  168. * Add WMM parameter for broadcast.
  169. *
  170. * 12 29 2010 eddie.chen
  171. * [WCXRP00000322] Add WMM IE in beacon,
  172. Add per station flow control when STA is in PS
  173. * 1) PS flow control event
  174. *
  175. * 2) WMM IE in beacon, assoc resp, probe resp
  176. *
  177. * 11 29 2010 cp.wu
  178. * [WCXRP00000210] [MT6620 Wi-Fi][Driver][FW] Set RCPI value in STA_REC
  179. * for initial TX rate selection of auto-rate algorithm
  180. * update ucRcpi of STA_RECORD_T for AIS when
  181. * 1) Beacons for IBSS merge is received
  182. * 2) Associate Response for a connecting peer is received
  183. *
  184. * 10 18 2010 cp.wu
  185. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  186. * use definition macro to replace hard-coded constant
  187. *
  188. * 10 08 2010 wh.su
  189. * [WCXRP00000085] [MT6620 Wif-Fi] [Driver] update the modified p2p state machine
  190. * update the frog's new p2p state machine.
  191. *
  192. * 09 28 2010 wh.su
  193. * NULL
  194. * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
  195. *
  196. * 09 27 2010 chinghwa.yu
  197. * [WCXRP00000063] Update BCM CoEx design and settings[WCXRP00000065] Update BoW design and settings
  198. * Update BCM/BoW design and settings.
  199. *
  200. * 09 16 2010 cm.chang
  201. * NULL
  202. * Change conditional compiling options for BOW
  203. *
  204. * 09 10 2010 cm.chang
  205. * NULL
  206. * Always update Beacon content if FW sync OBSS info
  207. *
  208. * 09 07 2010 wh.su
  209. * NULL
  210. * adding the code for beacon/probe req/ probe rsp wsc ie at p2p.
  211. *
  212. * 09 03 2010 kevin.huang
  213. * NULL
  214. * Refine #include sequence and solve recursive/nested #include issue
  215. *
  216. * 08 31 2010 kevin.huang
  217. * NULL
  218. * Use LINK LIST operation to process SCAN result
  219. *
  220. * 08 30 2010 cp.wu
  221. * NULL
  222. * eliminate klockwork errors
  223. *
  224. * 08 29 2010 yuche.tsai
  225. * NULL
  226. * Finish SLT TX/RX & Rate Changing Support.
  227. *
  228. * 08 24 2010 cm.chang
  229. * NULL
  230. * Support RLM initail channel of Ad-hoc, P2P and BOW
  231. *
  232. * 08 16 2010 yuche.tsai
  233. * NULL
  234. * Before composing Beacon IE, assign network type index for msdu info,
  235. * this information is needed by RLM module while composing some RLM related IE field.
  236. *
  237. * 08 16 2010 cp.wu
  238. * NULL
  239. * Replace CFG_SUPPORT_BOW by CFG_ENABLE_BT_OVER_WIFI.
  240. * There is no CFG_SUPPORT_BOW in driver domain source.
  241. *
  242. * 08 16 2010 kevin.huang
  243. * NULL
  244. * Refine AAA functions
  245. *
  246. * 08 12 2010 kevin.huang
  247. * NULL
  248. * Fix undefined pucDestAddr in bssUpdateBeaconContent()
  249. *
  250. * 08 12 2010 kevin.huang
  251. * NULL
  252. * Refine bssProcessProbeRequest() and bssSendBeaconProbeResponse()
  253. *
  254. * 08 11 2010 cp.wu
  255. * NULL
  256. * 1) do not use in-stack variable for beacon updating. (for MAUI porting)
  257. * 2) extending scanning result to 64 instead of 48
  258. *
  259. * 08 02 2010 yuche.tsai
  260. * NULL
  261. * P2P Group Negotiation Code Check in.
  262. *
  263. * 08 02 2010 george.huang
  264. * NULL
  265. * add WMM-PS test related OID/ CMD handlers
  266. *
  267. * 07 26 2010 yuche.tsai
  268. *
  269. * Add support to RX probe response for P2P.
  270. *
  271. * 07 20 2010 cp.wu
  272. *
  273. * 1) bugfix: do not stop timer for join after switched into normal_tr state, for providing chance for DHCP handshasking
  274. * 2) modify rsnPerformPolicySelection() invoking
  275. *
  276. * 07 19 2010 wh.su
  277. *
  278. * update for security supporting.
  279. *
  280. * 07 19 2010 cp.wu
  281. *
  282. * [WPD00003833] [MT6620 and MT5931] Driver migration.
  283. * when IBSS is being merged-in, send command packet to PM for connected indication
  284. *
  285. * 07 19 2010 cp.wu
  286. *
  287. * [WPD00003833] [MT6620 and MT5931] Driver migration.
  288. * Add Ad-Hoc support to AIS-FSM
  289. *
  290. * 07 14 2010 yarco.yang
  291. *
  292. * 1. Remove CFG_MQM_MIGRATION
  293. * 2. Add CMD_UPDATE_WMM_PARMS command
  294. *
  295. * 07 08 2010 cp.wu
  296. *
  297. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  298. *
  299. * 07 06 2010 george.huang
  300. * [WPD00001556]Basic power managemenet function
  301. * Update arguments for nicUpdateBeaconIETemplate()
  302. *
  303. * 06 29 2010 cp.wu
  304. * [WPD00003833][MT6620 and MT5931] Driver migration
  305. * 1) sync to. CMD/EVENT document v0.03
  306. * 2) simplify DTIM period parsing in scan.c only, bss.c no longer parses it again.
  307. * 3) send command packet to indicate FW-PM after
  308. * a) 1st beacon is received after AIS has connected to an AP
  309. * b) IBSS-ALONE has been created
  310. * c) IBSS-MERGE has occurred
  311. *
  312. * 06 28 2010 cp.wu
  313. * [WPD00003833][MT6620 and MT5931] Driver migration
  314. * send MMPDU in basic rate.
  315. *
  316. * 06 25 2010 george.huang
  317. * [WPD00001556]Basic power managemenet function
  318. * Create beacon update path, with expose bssUpdateBeaconContent()
  319. *
  320. * 06 21 2010 yuche.tsai
  321. * [WPD00003839][MT6620 5931][P2P] Feature migration
  322. * Fix compile error while enable WIFI_DIRECT support.
  323. *
  324. * 06 21 2010 yarco.yang
  325. * [WPD00003837][MT6620]Data Path Refine
  326. * Support CFG_MQM_MIGRATION flag
  327. *
  328. * 06 21 2010 cp.wu
  329. * [WPD00003833][MT6620 and MT5931] Driver migration
  330. * enable RX management frame handling.
  331. *
  332. * 06 21 2010 cp.wu
  333. * [WPD00003833][MT6620 and MT5931] Driver migration
  334. * specify correct value for management frames.
  335. *
  336. * 06 18 2010 cm.chang
  337. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  338. * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
  339. *
  340. * 06 15 2010 cp.wu
  341. * [WPD00003833][MT6620 and MT5931] Driver migration
  342. * correct when ADHOC support is turned on.
  343. *
  344. * 06 15 2010 cp.wu
  345. * [WPD00003833][MT6620 and MT5931] Driver migration
  346. * add scan.c.
  347. *
  348. * 06 14 2010 cp.wu
  349. * [WPD00003833][MT6620 and MT5931] Driver migration
  350. * add management dispatching function table.
  351. *
  352. * 06 11 2010 cp.wu
  353. * [WPD00003833][MT6620 and MT5931] Driver migration
  354. * auth.c is migrated.
  355. *
  356. * 06 11 2010 cp.wu
  357. * [WPD00003833][MT6620 and MT5931] Driver migration
  358. * fix compilation error when WIFI_DIRECT is turned on
  359. *
  360. * 06 11 2010 cp.wu
  361. * [WPD00003833][MT6620 and MT5931] Driver migration
  362. * add bss.c.
  363. *
  364. * 06 04 2010 george.huang
  365. * [BORA00000678][MT6620]WiFi LP integration
  366. * [PM] Support U-APSD for STA mode
  367. *
  368. * 05 28 2010 kevin.huang
  369. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  370. * Add ClientList handling API - bssClearClientList, bssAddStaRecToClientList
  371. *
  372. * 05 24 2010 kevin.huang
  373. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  374. * Update bssProcessProbeRequest() to avoid redundant SSID IE {0,0} for IOT.
  375. *
  376. * 05 21 2010 kevin.huang
  377. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  378. * Refine txmInitWtblTxRateTable() - set TX initial rate according to AP's operation rate set
  379. *
  380. * 05 18 2010 cm.chang
  381. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  382. * Ad-hoc Beacon should not carry HT OP and OBSS IEs
  383. *
  384. * 05 14 2010 kevin.huang
  385. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  386. * Use TX MGMT Frame API for sending PS NULL frame to avoid the TX Burst Mechanism in TX FW Frame API
  387. *
  388. * 05 14 2010 kevin.huang
  389. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  390. * Separate Beacon and ProbeResp IE array
  391. *
  392. * 05 12 2010 kevin.huang
  393. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  394. * Add Power Management - Legacy PS-POLL support.
  395. *
  396. * 04 28 2010 tehuang.liu
  397. * [BORA00000605][WIFISYS] Phase3 Integration
  398. * Removed the use of compiling flag MQM_WMM_PARSING
  399. *
  400. * 04 27 2010 kevin.huang
  401. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  402. * Add Set Slot Time and Beacon Timeout Support for AdHoc Mode
  403. *
  404. * 04 24 2010 cm.chang
  405. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  406. * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
  407. *
  408. * 04 22 2010 cm.chang
  409. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  410. * First draft code to support protection in AP mode
  411. *
  412. * 04 20 2010 kevin.huang
  413. * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
  414. * Fix restart Beacon Timeout Func after connection diagnosis
  415. *
  416. * 04 19 2010 kevin.huang
  417. * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
  418. * Add Beacon Timeout Support and will send Null frame to diagnose connection
  419. *
  420. * 04 16 2010 wh.su
  421. * [BORA00000680][MT6620] Support the statistic for Micxxsoft os query
  422. * adding the wpa-none for ibss beacon.
  423. *
  424. * 04 15 2010 wh.su
  425. * [BORA00000680][MT6620] Support the statistic for Micxxsoft os query
  426. * fixed the protected bit at cap info for ad-hoc.
  427. *
  428. * 03 18 2010 kevin.huang
  429. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  430. * Rename the CFG flags
  431. *
  432. * 03 16 2010 kevin.huang
  433. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  434. * Add AdHoc Mode
  435. *
  436. * 02 26 2010 kevin.huang
  437. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  438. * Update outgoing beacon's TX data rate
  439. *
  440. * 02 23 2010 kevin.huang
  441. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  442. * Add DTIM count update while TX Beacon
  443. *
  444. * 02 05 2010 kevin.huang
  445. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  446. * Modify code due to define - BAND_24G and specific BSS_INFO_T was changed
  447. *
  448. * 02 05 2010 kevin.huang
  449. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  450. * Revise data structure to share the same BSS_INFO_T for avoiding coding error
  451. *
  452. * 02 04 2010 kevin.huang
  453. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  454. * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
  455. */
  456. /*******************************************************************************
  457. * C O M P I L E R F L A G S
  458. ********************************************************************************
  459. */
  460. /*******************************************************************************
  461. * E X T E R N A L R E F E R E N C E S
  462. ********************************************************************************
  463. */
  464. #include "precomp.h"
  465. /*******************************************************************************
  466. * C O N S T A N T S
  467. ********************************************************************************
  468. */
  469. /*******************************************************************************
  470. * D A T A T Y P E S
  471. ********************************************************************************
  472. */
  473. /*******************************************************************************
  474. * P U B L I C D A T A
  475. ********************************************************************************
  476. */
  477. #if (CFG_SUPPORT_ADHOC) || (CFG_SUPPORT_AAA)
  478. APPEND_VAR_IE_ENTRY_T txBcnIETable[] = {
  479. {(ELEM_HDR_LEN + (RATE_NUM - ELEM_MAX_LEN_SUP_RATES)), NULL, bssGenerateExtSuppRate_IE}, /* 50 */
  480. {(ELEM_HDR_LEN + ELEM_MAX_LEN_ERP), NULL, rlmRspGenerateErpIE}, /* 42 */
  481. {(ELEM_HDR_LEN + ELEM_MAX_LEN_HT_CAP), NULL, rlmRspGenerateHtCapIE}, /* 45 */
  482. {(ELEM_HDR_LEN + ELEM_MAX_LEN_HT_OP), NULL, rlmRspGenerateHtOpIE}, /* 61 */
  483. #if CFG_ENABLE_WIFI_DIRECT
  484. {(ELEM_HDR_LEN + ELEM_MAX_LEN_OBSS_SCAN), NULL, rlmRspGenerateObssScanIE}, /* 74 */
  485. #endif
  486. {(ELEM_HDR_LEN + ELEM_MAX_LEN_EXT_CAP), NULL, rlmRspGenerateExtCapIE}, /* 127 */
  487. {(ELEM_HDR_LEN + ELEM_MAX_LEN_WPA), NULL, rsnGenerateWpaNoneIE}, /* 221 */
  488. {(ELEM_HDR_LEN + ELEM_MAX_LEN_WMM_PARAM), NULL, mqmGenerateWmmParamIE}, /* 221 */
  489. #if CFG_ENABLE_WIFI_DIRECT
  490. {(ELEM_HDR_LEN + ELEM_MAX_LEN_WPA), NULL, rsnGenerateWPAIE}, /* 221 */
  491. {(ELEM_HDR_LEN + ELEM_MAX_LEN_RSN), NULL, rsnGenerateRSNIE}, /* 48 */
  492. #if 0 /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0) */
  493. {0, p2pFuncCalculateExtra_IELenForBeacon, p2pFuncGenerateExtra_IEForBeacon}, /* 221 */
  494. #else
  495. {0, p2pFuncCalculateP2p_IELenForBeacon, p2pFuncGenerateP2p_IEForBeacon}, /* 221 */
  496. {0, p2pFuncCalculateWSC_IELenForBeacon, p2pFuncGenerateWSC_IEForBeacon}, /* 221 */
  497. {0, p2pFuncCalculateP2P_IE_NoA, p2pFuncGenerateP2P_IE_NoA}, /* 221 */
  498. #endif
  499. #endif /* CFG_ENABLE_WIFI_DIRECT */
  500. };
  501. APPEND_VAR_IE_ENTRY_T txProbRspIETable[] = {
  502. {(ELEM_HDR_LEN + (RATE_NUM - ELEM_MAX_LEN_SUP_RATES)), NULL, bssGenerateExtSuppRate_IE}, /* 50 */
  503. {(ELEM_HDR_LEN + ELEM_MAX_LEN_ERP), NULL, rlmRspGenerateErpIE}, /* 42 */
  504. {(ELEM_HDR_LEN + ELEM_MAX_LEN_HT_CAP), NULL, rlmRspGenerateHtCapIE}, /* 45 */
  505. {(ELEM_HDR_LEN + ELEM_MAX_LEN_HT_OP), NULL, rlmRspGenerateHtOpIE}, /* 61 */
  506. #if CFG_ENABLE_WIFI_DIRECT
  507. {(ELEM_HDR_LEN + ELEM_MAX_LEN_RSN), NULL, rsnGenerateRSNIE}, /* 48 */
  508. {(ELEM_HDR_LEN + ELEM_MAX_LEN_OBSS_SCAN), NULL, rlmRspGenerateObssScanIE}, /* 74 */
  509. #endif
  510. {(ELEM_HDR_LEN + ELEM_MAX_LEN_EXT_CAP), NULL, rlmRspGenerateExtCapIE}, /* 127 */
  511. {(ELEM_HDR_LEN + ELEM_MAX_LEN_WPA), NULL, rsnGenerateWpaNoneIE}, /* 221 */
  512. {(ELEM_HDR_LEN + ELEM_MAX_LEN_WMM_PARAM), NULL, mqmGenerateWmmParamIE} /* 221 */
  513. };
  514. #endif /* CFG_SUPPORT_ADHOC || CFG_SUPPORT_AAA */
  515. /*******************************************************************************
  516. * P R I V A T E D A T A
  517. ********************************************************************************
  518. */
  519. /*******************************************************************************
  520. * M A C R O S
  521. ********************************************************************************
  522. */
  523. /*******************************************************************************
  524. * F U N C T I O N D E C L A R A T I O N S
  525. ********************************************************************************
  526. */
  527. /*******************************************************************************
  528. * F U N C T I O N S
  529. ********************************************************************************
  530. */
  531. /*----------------------------------------------------------------------------*/
  532. /* Routines for all Operation Modes */
  533. /*----------------------------------------------------------------------------*/
  534. /*----------------------------------------------------------------------------*/
  535. /*!
  536. * @brief This function will create or reset a STA_RECORD_T by given BSS_DESC_T for
  537. * Infrastructure or AdHoc Mode.
  538. *
  539. * @param[in] prAdapter Pointer to the Adapter structure.
  540. * @param[in] eStaType Assign STA Type for this STA_RECORD_T
  541. * @param[in] eNetTypeIndex Assign Net Type Index for this STA_RECORD_T
  542. * @param[in] prBssDesc Received Beacon/ProbeResp from this STA
  543. *
  544. * @retval Pointer to STA_RECORD_T
  545. */
  546. /*----------------------------------------------------------------------------*/
  547. P_STA_RECORD_T
  548. bssCreateStaRecFromBssDesc(IN P_ADAPTER_T prAdapter,
  549. IN ENUM_STA_TYPE_T eStaType,
  550. IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex, IN P_BSS_DESC_T prBssDesc)
  551. {
  552. P_STA_RECORD_T prStaRec;
  553. UINT_8 ucNonHTPhyTypeSet;
  554. ASSERT(prBssDesc);
  555. /* 4 <1> Get a valid STA_RECORD_T */
  556. prStaRec = cnmGetStaRecByAddress(prAdapter, (UINT_8) eNetTypeIndex, prBssDesc->aucSrcAddr);
  557. if (!prStaRec) {
  558. prStaRec = cnmStaRecAlloc(prAdapter, (UINT_8) eNetTypeIndex);
  559. /* TODO(Kevin): Error handling of allocation of STA_RECORD_T for
  560. * exhausted case and do removal of unused STA_RECORD_T.
  561. */
  562. if (!prStaRec) {
  563. ASSERT(FALSE);
  564. return NULL;
  565. }
  566. ASSERT(prStaRec);
  567. prStaRec->ucStaState = STA_STATE_1;
  568. prStaRec->ucJoinFailureCount = 0;
  569. /* TODO(Kevin): If this is an old entry, we may also reset the ucJoinFailureCount to 0.
  570. */
  571. COPY_MAC_ADDR(prStaRec->aucMacAddr, prBssDesc->aucSrcAddr);
  572. }
  573. /* 4 <2> Setup STA TYPE and NETWORK */
  574. prStaRec->eStaType = eStaType;
  575. prStaRec->ucNetTypeIndex = eNetTypeIndex;
  576. /* 4 <3> Update information from BSS_DESC_T to current P_STA_RECORD_T */
  577. prStaRec->u2CapInfo = prBssDesc->u2CapInfo;
  578. prStaRec->u2OperationalRateSet = prBssDesc->u2OperationalRateSet;
  579. prStaRec->u2BSSBasicRateSet = prBssDesc->u2BSSBasicRateSet;
  580. prStaRec->ucPhyTypeSet = prBssDesc->ucPhyTypeSet;
  581. if (IS_STA_IN_AIS(prStaRec)) {
  582. if (!((prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION3_ENABLED) ||
  583. (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION3_KEY_ABSENT) ||
  584. (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION_DISABLED) ||
  585. (prAdapter->prGlueInfo->u2WSCAssocInfoIELen) || (prAdapter->prGlueInfo->u2WapiAssocInfoIESz))) {
  586. DBGLOG(BSS, TRACE, "Ignore the HT Bit for TKIP as pairwise cipher configured!\n");
  587. prStaRec->ucPhyTypeSet &= ~PHY_TYPE_BIT_HT;
  588. }
  589. } else {
  590. DBGLOG(BSS, TRACE, "P2P skip TKIP limitation for HT Hit!\n");
  591. }
  592. prStaRec->ucDesiredPhyTypeSet = prStaRec->ucPhyTypeSet & prAdapter->rWifiVar.ucAvailablePhyTypeSet;
  593. ucNonHTPhyTypeSet = prStaRec->ucDesiredPhyTypeSet & PHY_TYPE_SET_802_11ABG;
  594. /* Check for Target BSS's non HT Phy Types */
  595. if (ucNonHTPhyTypeSet) {
  596. if (ucNonHTPhyTypeSet & PHY_TYPE_BIT_ERP) {
  597. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_ERP_INDEX;
  598. } else if (ucNonHTPhyTypeSet & PHY_TYPE_BIT_OFDM) {
  599. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_OFDM_INDEX;
  600. } else { /* if (ucNonHTPhyTypeSet & PHY_TYPE_HR_DSSS_INDEX) */
  601. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_HR_DSSS_INDEX;
  602. }
  603. prStaRec->fgHasBasicPhyType = TRUE;
  604. } else {
  605. /* Use mandatory for 11N only BSS */
  606. ASSERT(prStaRec->ucPhyTypeSet & PHY_TYPE_SET_802_11N);
  607. {
  608. /* TODO(Kevin): which value should we set for 11n ? ERP ? */
  609. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_HR_DSSS_INDEX;
  610. }
  611. prStaRec->fgHasBasicPhyType = FALSE;
  612. }
  613. /* Update non HT Desired Rate Set */
  614. {
  615. P_CONNECTION_SETTINGS_T prConnSettings;
  616. prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
  617. prStaRec->u2DesiredNonHTRateSet =
  618. (prStaRec->u2OperationalRateSet & prConnSettings->u2DesiredNonHTRateSet);
  619. }
  620. /* 4 <4> Update information from BSS_DESC_T to current P_STA_RECORD_T */
  621. if (IS_AP_STA(prStaRec)) {
  622. /* do not need to parse IE for DTIM,
  623. * which have been parsed before inserting into BSS_DESC_T
  624. */
  625. if (prBssDesc->ucDTIMPeriod)
  626. prStaRec->ucDTIMPeriod = prBssDesc->ucDTIMPeriod;
  627. else
  628. prStaRec->ucDTIMPeriod = 0; /* Means that TIM was not parsed. */
  629. }
  630. /* 4 <5> Update default value */
  631. prStaRec->fgDiagnoseConnection = FALSE;
  632. /* 4 <6> Update default value for other Modules */
  633. /* Determine fgIsWmmSupported and fgIsUapsdSupported in STA_REC */
  634. mqmProcessScanResult(prAdapter, prBssDesc, prStaRec);
  635. return prStaRec;
  636. } /* end of bssCreateStaRecFromBssDesc() */
  637. /*----------------------------------------------------------------------------*/
  638. /*!
  639. * @brief This function will compose the Null Data frame.
  640. *
  641. * @param[in] prAdapter Pointer to the Adapter structure.
  642. * @param[in] pucBuffer Pointer to the frame buffer.
  643. * @param[in] prStaRec Pointer to the STA_RECORD_T.
  644. *
  645. * @return (none)
  646. */
  647. /*----------------------------------------------------------------------------*/
  648. VOID bssComposeNullFrame(IN P_ADAPTER_T prAdapter, IN PUINT_8 pucBuffer, IN P_STA_RECORD_T prStaRec)
  649. {
  650. P_WLAN_MAC_HEADER_T prNullFrame;
  651. P_BSS_INFO_T prBssInfo;
  652. UINT_16 u2FrameCtrl;
  653. ASSERT(pucBuffer);
  654. ASSERT(prStaRec);
  655. ASSERT(prStaRec->ucNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
  656. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex]);
  657. ASSERT(prBssInfo);
  658. prNullFrame = (P_WLAN_MAC_HEADER_T) pucBuffer;
  659. /* 4 <1> Decide the Frame Control Field */
  660. u2FrameCtrl = MAC_FRAME_NULL;
  661. if (IS_AP_STA(prStaRec)) {
  662. u2FrameCtrl |= MASK_FC_TO_DS;
  663. if (prStaRec->fgSetPwrMgtBit)
  664. u2FrameCtrl |= MASK_FC_PWR_MGT;
  665. } else if (IS_CLIENT_STA(prStaRec)) {
  666. u2FrameCtrl |= MASK_FC_FROM_DS;
  667. } else if (IS_DLS_STA(prStaRec)) {
  668. /* TODO(Kevin) */
  669. } else {
  670. /* NOTE(Kevin): We won't send Null frame for IBSS */
  671. ASSERT(0);
  672. return;
  673. }
  674. /* 4 <2> Compose the Null frame */
  675. /* Fill the Frame Control field. */
  676. /* WLAN_SET_FIELD_16(&prNullFrame->u2FrameCtrl, u2FrameCtrl); */
  677. prNullFrame->u2FrameCtrl = u2FrameCtrl; /* NOTE(Kevin): Optimized for ARM */
  678. /* Fill the Address 1 field with Target Peer Address. */
  679. COPY_MAC_ADDR(prNullFrame->aucAddr1, prStaRec->aucMacAddr);
  680. /* Fill the Address 2 field with our MAC Address. */
  681. COPY_MAC_ADDR(prNullFrame->aucAddr2, prBssInfo->aucOwnMacAddr);
  682. /* Fill the Address 3 field with Target BSSID. */
  683. COPY_MAC_ADDR(prNullFrame->aucAddr3, prBssInfo->aucBSSID);
  684. /* Clear the SEQ/FRAG_NO field(HW won't overide the FRAG_NO, so we need to clear it). */
  685. prNullFrame->u2SeqCtrl = 0;
  686. return;
  687. } /* end of bssComposeNullFrameHeader() */
  688. /*----------------------------------------------------------------------------*/
  689. /*!
  690. * @brief This function will compose the QoS Null Data frame.
  691. *
  692. * @param[in] prAdapter Pointer to the Adapter structure.
  693. * @param[in] pucBuffer Pointer to the frame buffer.
  694. * @param[in] prStaRec Pointer to the STA_RECORD_T.
  695. * @param[in] ucUP User Priority.
  696. * @param[in] fgSetEOSP Set the EOSP bit.
  697. *
  698. * @return (none)
  699. */
  700. /*----------------------------------------------------------------------------*/
  701. VOID
  702. bssComposeQoSNullFrame(IN P_ADAPTER_T prAdapter,
  703. IN PUINT_8 pucBuffer, IN P_STA_RECORD_T prStaRec, IN UINT_8 ucUP, IN BOOLEAN fgSetEOSP)
  704. {
  705. P_WLAN_MAC_HEADER_QOS_T prQoSNullFrame;
  706. P_BSS_INFO_T prBssInfo;
  707. UINT_16 u2FrameCtrl;
  708. UINT_16 u2QosControl;
  709. ASSERT(pucBuffer);
  710. ASSERT(prStaRec);
  711. ASSERT(prStaRec->ucNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
  712. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex]);
  713. ASSERT(prBssInfo);
  714. prQoSNullFrame = (P_WLAN_MAC_HEADER_QOS_T) pucBuffer;
  715. /* 4 <1> Decide the Frame Control Field */
  716. u2FrameCtrl = MAC_FRAME_QOS_NULL;
  717. if (IS_AP_STA(prStaRec)) {
  718. u2FrameCtrl |= MASK_FC_TO_DS;
  719. if (prStaRec->fgSetPwrMgtBit)
  720. u2FrameCtrl |= MASK_FC_PWR_MGT;
  721. } else if (IS_CLIENT_STA(prStaRec)) {
  722. u2FrameCtrl |= MASK_FC_FROM_DS;
  723. } else if (IS_DLS_STA(prStaRec)) {
  724. /* TODO(Kevin) */
  725. } else {
  726. /* NOTE(Kevin): We won't send QoS Null frame for IBSS */
  727. ASSERT(0);
  728. return;
  729. }
  730. /* 4 <2> Compose the QoS Null frame */
  731. /* Fill the Frame Control field. */
  732. /* WLAN_SET_FIELD_16(&prQoSNullFrame->u2FrameCtrl, u2FrameCtrl); */
  733. prQoSNullFrame->u2FrameCtrl = u2FrameCtrl; /* NOTE(Kevin): Optimized for ARM */
  734. /* Fill the Address 1 field with Target Peer Address. */
  735. COPY_MAC_ADDR(prQoSNullFrame->aucAddr1, prStaRec->aucMacAddr);
  736. /* Fill the Address 2 field with our MAC Address. */
  737. COPY_MAC_ADDR(prQoSNullFrame->aucAddr2, prBssInfo->aucOwnMacAddr);
  738. /* Fill the Address 3 field with Target BSSID. */
  739. COPY_MAC_ADDR(prQoSNullFrame->aucAddr3, prBssInfo->aucBSSID);
  740. /* Clear the SEQ/FRAG_NO field(HW won't overide the FRAG_NO, so we need to clear it). */
  741. prQoSNullFrame->u2SeqCtrl = 0;
  742. u2QosControl = (UINT_16) (ucUP & WMM_QC_UP_MASK);
  743. if (fgSetEOSP)
  744. u2QosControl |= WMM_QC_EOSP;
  745. /* WLAN_SET_FIELD_16(&prQoSNullFrame->u2QosCtrl, u2QosControl); */
  746. prQoSNullFrame->u2QosCtrl = u2QosControl; /* NOTE(Kevin): Optimized for ARM */
  747. return;
  748. } /* end of bssComposeQoSNullFrameHeader() */
  749. /*----------------------------------------------------------------------------*/
  750. /*!
  751. * @brief Send the Null Frame
  752. *
  753. * @param[in] prAdapter Pointer to the Adapter structure.
  754. * @param[in] prStaRec Pointer to the STA_RECORD_T
  755. * @param[in] pfTxDoneHandler TX Done call back function
  756. *
  757. * @retval WLAN_STATUS_RESOURCE No available resources to send frame.
  758. * @retval WLAN_STATUS_SUCCESS Succe]ss.
  759. */
  760. /*----------------------------------------------------------------------------*/
  761. WLAN_STATUS
  762. bssSendNullFrame(IN P_ADAPTER_T prAdapter, IN P_STA_RECORD_T prStaRec, IN PFN_TX_DONE_HANDLER pfTxDoneHandler)
  763. {
  764. P_MSDU_INFO_T prMsduInfo;
  765. UINT_16 u2EstimatedFrameLen;
  766. /* 4 <1> Allocate a PKT_INFO_T for Null Frame */
  767. /* Init with MGMT Header Length */
  768. u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD + WLAN_MAC_HEADER_LEN;
  769. /* Allocate a MSDU_INFO_T */
  770. prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen);
  771. if (prMsduInfo == NULL) {
  772. DBGLOG(BSS, WARN, "No PKT_INFO_T for sending Null Frame.\n");
  773. return WLAN_STATUS_RESOURCES;
  774. }
  775. /* 4 <2> Compose Null frame in MSDU_INfO_T. */
  776. bssComposeNullFrame(prAdapter, (PUINT_8) ((ULONG) prMsduInfo->prPacket + MAC_TX_RESERVED_FIELD), prStaRec);
  777. #if 0
  778. /* 4 <3> Update information of MSDU_INFO_T */
  779. TXM_SET_DATA_PACKET(
  780. /* STA_REC ptr */ prStaRec,
  781. /* MSDU_INFO ptr */ prMsduInfo,
  782. /* MAC HDR ptr */ (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD),
  783. /* MAC HDR length */ WLAN_MAC_HEADER_LEN,
  784. /* PAYLOAD ptr */
  785. (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD + WLAN_MAC_HEADER_LEN),
  786. /* PAYLOAD length */ 0,
  787. /* Network Type Index */ (UINT_8) prStaRec->ucNetTypeIndex,
  788. /* TID */ 0 /* BE: AC1 */ ,
  789. /* Flag 802.11 */ TRUE,
  790. /* Pkt arrival time */ 0 /* TODO: Obtain the system time */ ,
  791. /* Resource TC */ 0 /* Irrelevant */ ,
  792. /* Flag 802.1x */ FALSE,
  793. /* TX-done callback */ pfTxDoneHandler,
  794. /* PS forwarding type */ PS_FORWARDING_TYPE_NON_PS,
  795. /* PS Session ID */ 0 /* Irrelevant */ ,
  796. /* Flag fixed rate */ TRUE,
  797. /* Fixed tx rate */ g_aprBssInfo[prStaRec->ucNetTypeIndex]->ucHwDefaultFixedRateCode,
  798. /* Fixed-rate retry */ BSS_DEFAULT_CONN_TEST_NULL_FRAME_RETRY_LIMIT,
  799. /* PAL LLH */ 0 /* Irrelevant */ ,
  800. /* ACL SN */ 0 /* Irrelevant */ ,
  801. /* Flag No Ack */ FALSE
  802. );
  803. /* Terminate with a NULL pointer */
  804. NIC_HIF_TX_SET_NEXT_MSDU_INFO(prMsduInfo, NULL);
  805. /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
  806. /* Indicate the packet to TXM */
  807. /* 4 <4> Inform TXM to send this Null frame. */
  808. txmSendFwDataPackets(prMsduInfo);
  809. #endif
  810. prMsduInfo->eSrc = TX_PACKET_MGMT;
  811. prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_DATA;
  812. prMsduInfo->ucStaRecIndex = prStaRec->ucIndex;
  813. prMsduInfo->ucNetworkType = prStaRec->ucNetTypeIndex;
  814. prMsduInfo->ucMacHeaderLength = WLAN_MAC_HEADER_LEN;
  815. prMsduInfo->fgIs802_1x = FALSE;
  816. prMsduInfo->fgIs802_11 = TRUE;
  817. prMsduInfo->u2FrameLength = WLAN_MAC_HEADER_LEN;
  818. prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
  819. prMsduInfo->pfTxDoneHandler = pfTxDoneHandler;
  820. prMsduInfo->fgIsBasicRate = FALSE;
  821. /* 4 <4> Inform TXM to send this Null frame. */
  822. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  823. return WLAN_STATUS_SUCCESS;
  824. } /* end of bssSendNullFrame() */
  825. /*----------------------------------------------------------------------------*/
  826. /*!
  827. * @brief Send the QoS Null Frame
  828. *
  829. * @param[in] prAdapter Pointer to the Adapter structure.
  830. * @param[in] prStaRec Pointer to the STA_RECORD_T
  831. * @param[in] pfTxDoneHandler TX Done call back function
  832. *
  833. * @retval WLAN_STATUS_RESOURCE No available resources to send frame.
  834. * @retval WLAN_STATUS_SUCCESS Success.
  835. */
  836. /*----------------------------------------------------------------------------*/
  837. WLAN_STATUS
  838. bssSendQoSNullFrame(IN P_ADAPTER_T prAdapter,
  839. IN P_STA_RECORD_T prStaRec, IN UINT_8 ucUP, IN PFN_TX_DONE_HANDLER pfTxDoneHandler)
  840. {
  841. P_MSDU_INFO_T prMsduInfo;
  842. UINT_16 u2EstimatedFrameLen;
  843. /* 4 <1> Allocate a PKT_INFO_T for Null Frame */
  844. /* Init with MGMT Header Length */
  845. u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD + WLAN_MAC_HEADER_QOS_LEN;
  846. /* Allocate a MSDU_INFO_T */
  847. prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen);
  848. if (prMsduInfo == NULL) {
  849. DBGLOG(BSS, WARN, "No PKT_INFO_T for sending Null Frame.\n");
  850. return WLAN_STATUS_RESOURCES;
  851. }
  852. /* 4 <2> Compose Null frame in MSDU_INfO_T. */
  853. bssComposeQoSNullFrame(prAdapter,
  854. (PUINT_8) ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
  855. prStaRec, ucUP, FALSE);
  856. #if 0
  857. /* 4 <3> Update information of MSDU_INFO_T */
  858. TXM_SET_DATA_PACKET(
  859. /* STA_REC ptr */ prStaRec,
  860. /* MSDU_INFO ptr */ prMsduInfo,
  861. /* MAC HDR ptr */ (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD),
  862. /* MAC HDR length */ WLAN_MAC_HEADER_QOS_LEN,
  863. /* PAYLOAD ptr */
  864. (prMsduInfo->pucBuffer + MAC_TX_RESERVED_FIELD + WLAN_MAC_HEADER_QOS_LEN),
  865. /* PAYLOAD length */ 0,
  866. /* Network Type Index */ (UINT_8) prStaRec->ucNetTypeIndex,
  867. /* TID */ 0 /* BE: AC1 */ ,
  868. /* Flag 802.11 */ TRUE,
  869. /* Pkt arrival time */ 0 /* TODO: Obtain the system time */ ,
  870. /* Resource TC */ 0 /* Irrelevant */ ,
  871. /* Flag 802.1x */ FALSE,
  872. /* TX-done callback */ pfTxDoneHandler,
  873. /* PS forwarding type */ PS_FORWARDING_TYPE_NON_PS,
  874. /* PS Session ID */ 0 /* Irrelevant */ ,
  875. /* Flag fixed rate */ TRUE,
  876. /* Fixed tx rate */ g_aprBssInfo[prStaRec->ucNetTypeIndex]->ucHwDefaultFixedRateCode,
  877. /* Fixed-rate retry */ TXM_DEFAULT_DATA_FRAME_RETRY_LIMIT,
  878. /* PAL LLH */ 0 /* Irrelevant */ ,
  879. /* ACL SN */ 0 /* Irrelevant */ ,
  880. /* Flag No Ack */ FALSE
  881. );
  882. /* Terminate with a NULL pointer */
  883. NIC_HIF_TX_SET_NEXT_MSDU_INFO(prMsduInfo, NULL);
  884. /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
  885. /* Indicate the packet to TXM */
  886. /* 4 <4> Inform TXM to send this Null frame. */
  887. txmSendFwDataPackets(prMsduInfo);
  888. #endif
  889. prMsduInfo->eSrc = TX_PACKET_MGMT;
  890. prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_MGMT;
  891. prMsduInfo->ucStaRecIndex = prStaRec->ucIndex;
  892. prMsduInfo->ucNetworkType = prStaRec->ucNetTypeIndex;
  893. prMsduInfo->ucMacHeaderLength = WLAN_MAC_HEADER_QOS_LEN;
  894. prMsduInfo->fgIs802_1x = FALSE;
  895. prMsduInfo->fgIs802_11 = TRUE;
  896. prMsduInfo->u2FrameLength = WLAN_MAC_HEADER_QOS_LEN;
  897. prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
  898. prMsduInfo->pfTxDoneHandler = pfTxDoneHandler;
  899. prMsduInfo->fgIsBasicRate = TRUE;
  900. /* 4 <4> Inform TXM to send this Null frame. */
  901. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  902. return WLAN_STATUS_SUCCESS;
  903. } /* end of bssSendQoSNullFrame() */
  904. #if (CFG_SUPPORT_ADHOC) || (CFG_SUPPORT_AAA)
  905. /*----------------------------------------------------------------------------*/
  906. /* Routines for both IBSS(AdHoc) and BSS(AP) */
  907. /*----------------------------------------------------------------------------*/
  908. /*----------------------------------------------------------------------------*/
  909. /*!
  910. * @brief This function is used to generate Information Elements of Extended
  911. * Support Rate
  912. *
  913. * @param[in] prAdapter Pointer to the Adapter structure.
  914. * @param[in] prMsduInfo Pointer to the composed MSDU_INFO_T.
  915. *
  916. * @return (none)
  917. */
  918. /*----------------------------------------------------------------------------*/
  919. VOID bssGenerateExtSuppRate_IE(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfo)
  920. {
  921. P_BSS_INFO_T prBssInfo;
  922. PUINT_8 pucBuffer;
  923. UINT_8 ucExtSupRatesLen;
  924. ASSERT(prMsduInfo);
  925. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[prMsduInfo->ucNetworkType]);
  926. ASSERT(prBssInfo);
  927. pucBuffer = (PUINT_8) ((ULONG) prMsduInfo->prPacket + (UINT_32) prMsduInfo->u2FrameLength);
  928. ASSERT(pucBuffer);
  929. if (prBssInfo->ucAllSupportedRatesLen > ELEM_MAX_LEN_SUP_RATES)
  930. ucExtSupRatesLen = prBssInfo->ucAllSupportedRatesLen - ELEM_MAX_LEN_SUP_RATES;
  931. else
  932. ucExtSupRatesLen = 0;
  933. /* Fill the Extended Supported Rates element. */
  934. if (ucExtSupRatesLen) {
  935. EXT_SUP_RATES_IE(pucBuffer)->ucId = ELEM_ID_EXTENDED_SUP_RATES;
  936. EXT_SUP_RATES_IE(pucBuffer)->ucLength = ucExtSupRatesLen;
  937. kalMemCopy(EXT_SUP_RATES_IE(pucBuffer)->aucExtSupportedRates,
  938. &prBssInfo->aucAllSupportedRates[ELEM_MAX_LEN_SUP_RATES], ucExtSupRatesLen);
  939. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  940. }
  941. } /* end of bssGenerateExtSuppRate_IE() */
  942. /*----------------------------------------------------------------------------*/
  943. /*!
  944. * @brief This function is used to compose Common Information Elements for Beacon
  945. * or Probe Response Frame.
  946. *
  947. * @param[in] prMsduInfo Pointer to the composed MSDU_INFO_T.
  948. * @param[in] prBssInfo Pointer to the BSS_INFO_T.
  949. * @param[in] pucDestAddr Pointer to the Destination Address, if NULL, means Beacon.
  950. *
  951. * @return (none)
  952. */
  953. /*----------------------------------------------------------------------------*/
  954. VOID
  955. bssBuildBeaconProbeRespFrameCommonIEs(IN P_MSDU_INFO_T prMsduInfo, IN P_BSS_INFO_T prBssInfo, IN PUINT_8 pucDestAddr)
  956. {
  957. PUINT_8 pucBuffer;
  958. UINT_8 ucSupRatesLen;
  959. ASSERT(prMsduInfo);
  960. ASSERT(prBssInfo);
  961. pucBuffer = (PUINT_8) ((ULONG) prMsduInfo->prPacket + (UINT_32) prMsduInfo->u2FrameLength);
  962. ASSERT(pucBuffer);
  963. /* Compose the frame body of the Probe Response frame. */
  964. /* 4 <1> Fill the SSID element. */
  965. SSID_IE(pucBuffer)->ucId = ELEM_ID_SSID;
  966. if (prBssInfo->eHiddenSsidType == ENUM_HIDDEN_SSID_LEN) {
  967. if ((!pucDestAddr) && /* For Beacon only */
  968. (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)) {
  969. SSID_IE(pucBuffer)->ucLength = 0;
  970. } else { /* Probe response */
  971. SSID_IE(pucBuffer)->ucLength = prBssInfo->ucSSIDLen;
  972. if (prBssInfo->ucSSIDLen)
  973. kalMemCopy(SSID_IE(pucBuffer)->aucSSID, prBssInfo->aucSSID, prBssInfo->ucSSIDLen);
  974. }
  975. } else {
  976. SSID_IE(pucBuffer)->ucLength = prBssInfo->ucSSIDLen;
  977. if (prBssInfo->ucSSIDLen)
  978. kalMemCopy(SSID_IE(pucBuffer)->aucSSID, prBssInfo->aucSSID, prBssInfo->ucSSIDLen);
  979. }
  980. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  981. pucBuffer += IE_SIZE(pucBuffer);
  982. /* 4 <2> Fill the Supported Rates element. */
  983. if (prBssInfo->ucAllSupportedRatesLen > ELEM_MAX_LEN_SUP_RATES)
  984. ucSupRatesLen = ELEM_MAX_LEN_SUP_RATES;
  985. else
  986. ucSupRatesLen = prBssInfo->ucAllSupportedRatesLen;
  987. if (ucSupRatesLen) {
  988. SUP_RATES_IE(pucBuffer)->ucId = ELEM_ID_SUP_RATES;
  989. SUP_RATES_IE(pucBuffer)->ucLength = ucSupRatesLen;
  990. kalMemCopy(SUP_RATES_IE(pucBuffer)->aucSupportedRates, prBssInfo->aucAllSupportedRates, ucSupRatesLen);
  991. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  992. pucBuffer += IE_SIZE(pucBuffer);
  993. }
  994. /* 4 <3> Fill the DS Parameter Set element. */
  995. if (prBssInfo->eBand == BAND_2G4) {
  996. DS_PARAM_IE(pucBuffer)->ucId = ELEM_ID_DS_PARAM_SET;
  997. DS_PARAM_IE(pucBuffer)->ucLength = ELEM_MAX_LEN_DS_PARAMETER_SET;
  998. DS_PARAM_IE(pucBuffer)->ucCurrChnl = prBssInfo->ucPrimaryChannel;
  999. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  1000. pucBuffer += IE_SIZE(pucBuffer);
  1001. }
  1002. /* 4 <4> IBSS Parameter Set element, ID: 6 */
  1003. if (prBssInfo->eCurrentOPMode == OP_MODE_IBSS) {
  1004. IBSS_PARAM_IE(pucBuffer)->ucId = ELEM_ID_IBSS_PARAM_SET;
  1005. IBSS_PARAM_IE(pucBuffer)->ucLength = ELEM_MAX_LEN_IBSS_PARAMETER_SET;
  1006. WLAN_SET_FIELD_16(&(IBSS_PARAM_IE(pucBuffer)->u2ATIMWindow), prBssInfo->u2ATIMWindow);
  1007. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  1008. pucBuffer += IE_SIZE(pucBuffer);
  1009. }
  1010. /* 4 <5> TIM element, ID: 5 */
  1011. if ((!pucDestAddr) && /* For Beacon only. */
  1012. (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)) {
  1013. #if CFG_ENABLE_WIFI_DIRECT
  1014. /*no fgIsP2PRegistered protect */
  1015. if (prBssInfo->ucNetTypeIndex == NETWORK_TYPE_P2P_INDEX) {
  1016. #if 0
  1017. P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo;
  1018. UINT_8 ucBitmapControl = 0;
  1019. UINT_32 u4N1, u4N2;
  1020. prP2pSpecificBssInfo = &(prAdapter->rWifiVar.rP2pSpecificBssInfo);
  1021. /* Clear existing value. */
  1022. prP2pSpecificBssInfo->ucBitmapCtrl = 0;
  1023. kalMemZero(prP2pSpecificBssInfo->aucPartialVirtualBitmap,
  1024. sizeof(prP2pSpecificBssInfo->aucPartialVirtualBitmap));
  1025. /* IEEE 802.11 2007 - 7.3.2.6 */
  1026. TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
  1027. TIM_IE(pucBuffer)->ucDTIMCount = prBssInfo->ucDTIMCount;
  1028. TIM_IE(pucBuffer)->ucDTIMPeriod = prBssInfo->ucDTIMPeriod;
  1029. /* Setup DTIM Count for next TBTT. */
  1030. if (prBssInfo->ucDTIMCount == 0) {
  1031. /*Do nothing*/
  1032. /* 3 *** pmQueryBufferedBCAST(); */
  1033. }
  1034. /* 3 *** pmQueryBufferedPSNode(); */
  1035. /* TODO(Kevin): Call PM Module here to loop all STA_RECORD_Ts and it
  1036. * will call bssSetTIMBitmap to toggle the Bitmap.
  1037. */
  1038. /* Set Virtual Bitmap for UCAST */
  1039. u4N1 = (prP2pSpecificBssInfo->u2SmallestAID >> 4) << 1; /* Find the largest even number. */
  1040. u4N2 = prP2pSpecificBssInfo->u2LargestAID >> 3; /* Find the smallest number. */
  1041. ASSERT(u4N2 >= u4N1);
  1042. kalMemCopy(TIM_IE(pucBuffer)->aucPartialVirtualMap,
  1043. &prP2pSpecificBssInfo->aucPartialVirtualBitmap[u4N1], ((u4N2 - u4N1) + 1));
  1044. /* Set Virtual Bitmap for BMCAST */
  1045. /* BMC bit only indicated when DTIM count == 0. */
  1046. if (prBssInfo->ucDTIMCount == 0)
  1047. ucBitmapControl = prP2pSpecificBssInfo->ucBitmapCtrl;
  1048. TIM_IE(pucBuffer)->ucBitmapControl = ucBitmapControl | (UINT_8) u4N1;
  1049. TIM_IE(pucBuffer)->ucLength = ((u4N2 - u4N1) + 4);
  1050. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  1051. #else
  1052. /* IEEE 802.11 2007 - 7.3.2.6 */
  1053. TIM_IE(pucBuffer)->ucId = ELEM_ID_TIM;
  1054. /* NOTE: fixed PVB length (AID is allocated from 8 ~ 15 only) */
  1055. TIM_IE(pucBuffer)->ucLength = (3 + MAX_LEN_TIM_PARTIAL_BMP); /*((u4N2 - u4N1) + 4) */
  1056. /* will be overwrite by FW */
  1057. TIM_IE(pucBuffer)->ucDTIMCount = 0; /*prBssInfo->ucDTIMCount */
  1058. TIM_IE(pucBuffer)->ucDTIMPeriod = prBssInfo->ucDTIMPeriod;
  1059. /* will be overwrite by FW */
  1060. TIM_IE(pucBuffer)->ucBitmapControl = 0; /*ucBitmapControl | (UINT_8)u4N1 */
  1061. prMsduInfo->u2FrameLength += IE_SIZE(pucBuffer);
  1062. #endif
  1063. } else
  1064. #endif /* CFG_ENABLE_WIFI_DIRECT */
  1065. {
  1066. /* NOTE(Kevin): 1. AIS - Didn't Support AP Mode.
  1067. * 2. BOW - Didn't Support BCAST and PS.
  1068. */
  1069. }
  1070. }
  1071. } /* end of bssBuildBeaconProbeRespFrameCommonIEs() */
  1072. /*----------------------------------------------------------------------------*/
  1073. /*!
  1074. * @brief This function will compose the Beacon/Probe Response frame header and
  1075. * its fixed fields.
  1076. *
  1077. * @param[in] pucBuffer Pointer to the frame buffer.
  1078. * @param[in] pucDestAddr Pointer to the Destination Address, if NULL, means Beacon.
  1079. * @param[in] pucOwnMACAddress Given Our MAC Address.
  1080. * @param[in] pucBSSID Given BSSID of the BSS.
  1081. * @param[in] u2BeaconInterval Given Beacon Interval.
  1082. * @param[in] u2CapInfo Given Capability Info.
  1083. *
  1084. * @return (none)
  1085. */
  1086. /*----------------------------------------------------------------------------*/
  1087. VOID
  1088. bssComposeBeaconProbeRespFrameHeaderAndFF(IN PUINT_8 pucBuffer,
  1089. IN PUINT_8 pucDestAddr,
  1090. IN PUINT_8 pucOwnMACAddress,
  1091. IN PUINT_8 pucBSSID, IN UINT_16 u2BeaconInterval, IN UINT_16 u2CapInfo)
  1092. {
  1093. P_WLAN_BEACON_FRAME_T prBcnProbRspFrame;
  1094. UINT_8 aucBCAddr[] = BC_MAC_ADDR;
  1095. UINT_16 u2FrameCtrl;
  1096. DEBUGFUNC("bssComposeBeaconProbeRespFrameHeaderAndFF");
  1097. /* DBGLOG(INIT, LOUD, ("\n")); */
  1098. ASSERT(pucBuffer);
  1099. ASSERT(pucOwnMACAddress);
  1100. ASSERT(pucBSSID);
  1101. prBcnProbRspFrame = (P_WLAN_BEACON_FRAME_T) pucBuffer;
  1102. /* 4 <1> Compose the frame header of the Beacon /ProbeResp frame. */
  1103. /* Fill the Frame Control field. */
  1104. if (pucDestAddr) {
  1105. u2FrameCtrl = MAC_FRAME_PROBE_RSP;
  1106. } else {
  1107. u2FrameCtrl = MAC_FRAME_BEACON;
  1108. pucDestAddr = aucBCAddr;
  1109. }
  1110. /* WLAN_SET_FIELD_16(&prBcnProbRspFrame->u2FrameCtrl, u2FrameCtrl); */
  1111. prBcnProbRspFrame->u2FrameCtrl = u2FrameCtrl; /* NOTE(Kevin): Optimized for ARM */
  1112. /* Fill the DA field with BCAST MAC ADDR or TA of ProbeReq. */
  1113. COPY_MAC_ADDR(prBcnProbRspFrame->aucDestAddr, pucDestAddr);
  1114. /* Fill the SA field with our MAC Address. */
  1115. COPY_MAC_ADDR(prBcnProbRspFrame->aucSrcAddr, pucOwnMACAddress);
  1116. /* Fill the BSSID field with current BSSID. */
  1117. COPY_MAC_ADDR(prBcnProbRspFrame->aucBSSID, pucBSSID);
  1118. /* Clear the SEQ/FRAG_NO field(HW won't overide the FRAG_NO, so we need to clear it). */
  1119. prBcnProbRspFrame->u2SeqCtrl = 0;
  1120. /* 4 <2> Compose the frame body's common fixed field part of the Beacon /ProbeResp frame. */
  1121. /* MAC will update TimeStamp field */
  1122. /* Fill the Beacon Interval field. */
  1123. /* WLAN_SET_FIELD_16(&prBcnProbRspFrame->u2BeaconInterval, u2BeaconInterval); */
  1124. prBcnProbRspFrame->u2BeaconInterval = u2BeaconInterval; /* NOTE(Kevin): Optimized for ARM */
  1125. /* Fill the Capability Information field. */
  1126. /* WLAN_SET_FIELD_16(&prBcnProbRspFrame->u2CapInfo, u2CapInfo); */
  1127. prBcnProbRspFrame->u2CapInfo = u2CapInfo; /* NOTE(Kevin): Optimized for ARM */
  1128. } /* end of bssComposeBeaconProbeRespFrameHeaderAndFF() */
  1129. /*----------------------------------------------------------------------------*/
  1130. /*!
  1131. * @brief Update the Beacon Frame Template to FW for AIS AdHoc and P2P GO.
  1132. *
  1133. * @param[in] prAdapter Pointer to the Adapter structure.
  1134. * @param[in] eNetTypeIndex Specify which network reply the Probe Response.
  1135. *
  1136. * @retval WLAN_STATUS_SUCCESS Success.
  1137. */
  1138. /*----------------------------------------------------------------------------*/
  1139. WLAN_STATUS bssUpdateBeaconContent(IN P_ADAPTER_T prAdapter, IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex)
  1140. {
  1141. P_BSS_INFO_T prBssInfo;
  1142. P_MSDU_INFO_T prMsduInfo;
  1143. P_WLAN_BEACON_FRAME_T prBcnFrame;
  1144. UINT_32 i;
  1145. DEBUGFUNC("bssUpdateBeaconContent");
  1146. DBGLOG(BSS, LOUD, "\n");
  1147. ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
  1148. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
  1149. /* 4 <1> Allocate a PKT_INFO_T for Beacon Frame */
  1150. /* Allocate a MSDU_INFO_T */
  1151. /* For Beacon */
  1152. prMsduInfo = prBssInfo->prBeacon;
  1153. /* beacon prMsduInfo will be NULLify once BSS deactivated, so skip if it is */
  1154. if (prMsduInfo == NULL)
  1155. return WLAN_STATUS_SUCCESS;
  1156. /* 4 <2> Compose header */
  1157. bssComposeBeaconProbeRespFrameHeaderAndFF((PUINT_8) ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
  1158. NULL,
  1159. prBssInfo->aucOwnMacAddr,
  1160. prBssInfo->aucBSSID,
  1161. prBssInfo->u2BeaconInterval, prBssInfo->u2CapInfo);
  1162. prMsduInfo->u2FrameLength = (WLAN_MAC_MGMT_HEADER_LEN +
  1163. (TIMESTAMP_FIELD_LEN + BEACON_INTERVAL_FIELD_LEN + CAP_INFO_FIELD_LEN));
  1164. prMsduInfo->ucNetworkType = eNetTypeIndex;
  1165. /* 4 <3> Compose the frame body's Common IEs of the Beacon frame. */
  1166. bssBuildBeaconProbeRespFrameCommonIEs(prMsduInfo, prBssInfo, NULL);
  1167. /* 4 <4> Compose IEs in MSDU_INFO_T */
  1168. /* Append IE for Beacon */
  1169. for (i = 0; i < sizeof(txBcnIETable) / sizeof(APPEND_VAR_IE_ENTRY_T); i++) {
  1170. if (txBcnIETable[i].pfnAppendIE)
  1171. txBcnIETable[i].pfnAppendIE(prAdapter, prMsduInfo);
  1172. }
  1173. prBcnFrame = (P_WLAN_BEACON_FRAME_T) prMsduInfo->prPacket;
  1174. return nicUpdateBeaconIETemplate(prAdapter,
  1175. IE_UPD_METHOD_UPDATE_ALL,
  1176. eNetTypeIndex,
  1177. prBssInfo->u2CapInfo,
  1178. (PUINT_8) prBcnFrame->aucInfoElem,
  1179. prMsduInfo->u2FrameLength - OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem));
  1180. } /* end of bssUpdateBeaconContent() */
  1181. /*----------------------------------------------------------------------------*/
  1182. /*!
  1183. * @brief Send the Beacon Frame(for BOW) or Probe Response Frame according to the given
  1184. * Destination Address.
  1185. *
  1186. * @param[in] prAdapter Pointer to the Adapter structure.
  1187. * @param[in] eNetTypeIndex Specify which network reply the Probe Response.
  1188. * @param[in] pucDestAddr Pointer to the Destination Address to reply
  1189. * @param[in] u4ControlFlags Control flags for information on Probe Response.
  1190. *
  1191. * @retval WLAN_STATUS_RESOURCE No available resources to send frame.
  1192. * @retval WLAN_STATUS_SUCCESS Success.
  1193. */
  1194. /*----------------------------------------------------------------------------*/
  1195. WLAN_STATUS
  1196. bssSendBeaconProbeResponse(IN P_ADAPTER_T prAdapter,
  1197. IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex,
  1198. IN PUINT_8 pucDestAddr, IN UINT_32 u4ControlFlags)
  1199. {
  1200. P_BSS_INFO_T prBssInfo;
  1201. P_MSDU_INFO_T prMsduInfo;
  1202. UINT_16 u2EstimatedFrameLen;
  1203. UINT_16 u2EstimatedFixedIELen;
  1204. UINT_16 u2EstimatedExtraIELen;
  1205. P_APPEND_VAR_IE_ENTRY_T prIeArray = NULL;
  1206. UINT_32 u4IeArraySize = 0;
  1207. UINT_32 i;
  1208. ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
  1209. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
  1210. if (!pucDestAddr) { /* For Beacon */
  1211. prIeArray = &txBcnIETable[0];
  1212. u4IeArraySize = sizeof(txBcnIETable) / sizeof(APPEND_VAR_IE_ENTRY_T);
  1213. } else {
  1214. prIeArray = &txProbRspIETable[0];
  1215. u4IeArraySize = sizeof(txProbRspIETable) / sizeof(APPEND_VAR_IE_ENTRY_T);
  1216. }
  1217. /* 4 <1> Allocate a PKT_INFO_T for Beacon /Probe Response Frame */
  1218. /* Allocate a MSDU_INFO_T */
  1219. /* Init with MGMT Header Length + Length of Fixed Fields + Common IE Fields */
  1220. u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD +
  1221. WLAN_MAC_MGMT_HEADER_LEN +
  1222. TIMESTAMP_FIELD_LEN +
  1223. BEACON_INTERVAL_FIELD_LEN +
  1224. CAP_INFO_FIELD_LEN +
  1225. (ELEM_HDR_LEN + ELEM_MAX_LEN_SSID) +
  1226. (ELEM_HDR_LEN + ELEM_MAX_LEN_SUP_RATES) +
  1227. (ELEM_HDR_LEN + ELEM_MAX_LEN_DS_PARAMETER_SET) +
  1228. (ELEM_HDR_LEN + ELEM_MAX_LEN_IBSS_PARAMETER_SET) + (ELEM_HDR_LEN + (3 + MAX_LEN_TIM_PARTIAL_BMP));
  1229. /* + Extra IE Length */
  1230. u2EstimatedExtraIELen = 0;
  1231. for (i = 0; i < u4IeArraySize; i++) {
  1232. u2EstimatedFixedIELen = prIeArray[i].u2EstimatedFixedIELen;
  1233. if (u2EstimatedFixedIELen) {
  1234. u2EstimatedExtraIELen += u2EstimatedFixedIELen;
  1235. } else {
  1236. ASSERT(prIeArray[i].pfnCalculateVariableIELen);
  1237. u2EstimatedExtraIELen += (UINT_16)
  1238. prIeArray[i].pfnCalculateVariableIELen(prAdapter, eNetTypeIndex, NULL);
  1239. }
  1240. }
  1241. u2EstimatedFrameLen += u2EstimatedExtraIELen;
  1242. prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen);
  1243. if (prMsduInfo == NULL) {
  1244. DBGLOG(BSS, WARN, "No PKT_INFO_T for sending %s.\n", ((!pucDestAddr) ? "Beacon" : "Probe Response"));
  1245. return WLAN_STATUS_RESOURCES;
  1246. }
  1247. /* 4 <2> Compose Beacon/Probe Response frame header and fixed fields in MSDU_INfO_T. */
  1248. /* Compose Header and Fixed Field */
  1249. #if CFG_ENABLE_WIFI_DIRECT
  1250. if (u4ControlFlags & BSS_PROBE_RESP_USE_P2P_DEV_ADDR) {
  1251. if (prAdapter->fgIsP2PRegistered) {
  1252. bssComposeBeaconProbeRespFrameHeaderAndFF((PUINT_8)
  1253. ((ULONG) (prMsduInfo->prPacket) +
  1254. MAC_TX_RESERVED_FIELD), pucDestAddr,
  1255. prAdapter->rWifiVar.aucDeviceAddress,
  1256. prAdapter->rWifiVar.aucDeviceAddress,
  1257. DOT11_BEACON_PERIOD_DEFAULT,
  1258. (prBssInfo->u2CapInfo &
  1259. ~(CAP_INFO_ESS | CAP_INFO_IBSS)));
  1260. }
  1261. } else
  1262. #endif /* CFG_ENABLE_WIFI_DIRECT */
  1263. {
  1264. bssComposeBeaconProbeRespFrameHeaderAndFF((PUINT_8)
  1265. ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
  1266. pucDestAddr, prBssInfo->aucOwnMacAddr, prBssInfo->aucBSSID,
  1267. prBssInfo->u2BeaconInterval, prBssInfo->u2CapInfo);
  1268. }
  1269. /* 4 <3> Update information of MSDU_INFO_T */
  1270. prMsduInfo->eSrc = TX_PACKET_MGMT;
  1271. prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_MGMT;
  1272. prMsduInfo->ucStaRecIndex = 0xFF;
  1273. prMsduInfo->ucNetworkType = (UINT_8) eNetTypeIndex;
  1274. prMsduInfo->ucMacHeaderLength = WLAN_MAC_MGMT_HEADER_LEN;
  1275. prMsduInfo->fgIs802_1x = FALSE;
  1276. prMsduInfo->fgIs802_11 = TRUE;
  1277. prMsduInfo->u2FrameLength = (WLAN_MAC_MGMT_HEADER_LEN +
  1278. TIMESTAMP_FIELD_LEN + BEACON_INTERVAL_FIELD_LEN + CAP_INFO_FIELD_LEN);
  1279. prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
  1280. prMsduInfo->pfTxDoneHandler = NULL;
  1281. prMsduInfo->fgIsBasicRate = TRUE;
  1282. /* 4 <4> Compose the frame body's Common IEs of the Beacon/ProbeResp frame. */
  1283. bssBuildBeaconProbeRespFrameCommonIEs(prMsduInfo, prBssInfo, pucDestAddr);
  1284. /* 4 <5> Compose IEs in MSDU_INFO_T */
  1285. /* Append IE */
  1286. for (i = 0; i < u4IeArraySize; i++) {
  1287. if (prIeArray[i].pfnAppendIE)
  1288. prIeArray[i].pfnAppendIE(prAdapter, prMsduInfo);
  1289. }
  1290. /* TODO(Kevin): Also release the unused tail room of the composed MMPDU */
  1291. /* 4 <6> Inform TXM to send this Beacon /Probe Response frame. */
  1292. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  1293. return WLAN_STATUS_SUCCESS;
  1294. } /* end of bssSendBeaconProbeResponse() */
  1295. /*----------------------------------------------------------------------------*/
  1296. /*!
  1297. * @brief This function will process the Rx Probe Request Frame and then send
  1298. * back the corresponding Probe Response Frame if the specified conditions
  1299. * were matched.
  1300. *
  1301. * @param[in] prAdapter Pointer to the Adapter structure.
  1302. * @param[in] prSwRfb Pointer to SW RFB data structure.
  1303. *
  1304. * @retval WLAN_STATUS_SUCCESS Always return success
  1305. */
  1306. /*----------------------------------------------------------------------------*/
  1307. WLAN_STATUS bssProcessProbeRequest(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  1308. {
  1309. P_WLAN_MAC_MGMT_HEADER_T prMgtHdr;
  1310. P_BSS_INFO_T prBssInfo;
  1311. ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex;
  1312. UINT_8 aucBCBSSID[] = BC_BSSID;
  1313. BOOLEAN fgIsBcBssid;
  1314. BOOLEAN fgReplyProbeResp;
  1315. UINT_32 u4CtrlFlagsForProbeResp = 0;
  1316. ENUM_BAND_T eBand;
  1317. UINT_8 ucHwChannelNum;
  1318. ASSERT(prSwRfb);
  1319. /* 4 <1> Parse Probe Req and Get BSSID */
  1320. prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T) prSwRfb->pvHeader;
  1321. if (EQUAL_MAC_ADDR(aucBCBSSID, prMgtHdr->aucBSSID))
  1322. fgIsBcBssid = TRUE;
  1323. else
  1324. fgIsBcBssid = FALSE;
  1325. /* 4 <2> Check network conditions before reply Probe Response Frame (Consider Concurrent) */
  1326. for (eNetTypeIndex = NETWORK_TYPE_AIS_INDEX; eNetTypeIndex < NETWORK_TYPE_INDEX_NUM; eNetTypeIndex++) {
  1327. if (!IS_NET_ACTIVE(prAdapter, eNetTypeIndex))
  1328. continue;
  1329. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
  1330. if ((!fgIsBcBssid) && UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prMgtHdr->aucBSSID))
  1331. continue;
  1332. eBand = HIF_RX_HDR_GET_RF_BAND(prSwRfb->prHifRxHdr);
  1333. ucHwChannelNum = HIF_RX_HDR_GET_CHNL_NUM(prSwRfb->prHifRxHdr);
  1334. if (prBssInfo->eBand != eBand)
  1335. continue;
  1336. if (prBssInfo->ucPrimaryChannel != ucHwChannelNum)
  1337. continue;
  1338. fgReplyProbeResp = FALSE;
  1339. if (NETWORK_TYPE_AIS_INDEX == eNetTypeIndex) {
  1340. #if CFG_SUPPORT_ADHOC
  1341. fgReplyProbeResp = aisValidateProbeReq(prAdapter, prSwRfb, &u4CtrlFlagsForProbeResp);
  1342. #endif
  1343. }
  1344. #if CFG_ENABLE_WIFI_DIRECT
  1345. else if ((prAdapter->fgIsP2PRegistered) && (NETWORK_TYPE_P2P_INDEX == eNetTypeIndex)) {
  1346. if (nicTxGetFreeCmdCount(prAdapter) > (CFG_TX_MAX_CMD_PKT_NUM / 2)) {
  1347. /* Resource margin is enough */
  1348. fgReplyProbeResp =
  1349. p2pFuncValidateProbeReq(prAdapter, prSwRfb, &u4CtrlFlagsForProbeResp);
  1350. }
  1351. }
  1352. #endif
  1353. #if CFG_ENABLE_BT_OVER_WIFI
  1354. else if (NETWORK_TYPE_BOW_INDEX == eNetTypeIndex)
  1355. fgReplyProbeResp = bowValidateProbeReq(prAdapter, prSwRfb, &u4CtrlFlagsForProbeResp);
  1356. #endif
  1357. if (fgReplyProbeResp) {
  1358. if (nicTxGetFreeCmdCount(prAdapter) > (CFG_TX_MAX_CMD_PKT_NUM / 2)) {
  1359. /* Resource margin is enough */
  1360. bssSendBeaconProbeResponse(prAdapter, eNetTypeIndex, prMgtHdr->aucSrcAddr,
  1361. u4CtrlFlagsForProbeResp);
  1362. }
  1363. }
  1364. }
  1365. return WLAN_STATUS_SUCCESS;
  1366. } /* end of bssProcessProbeRequest() */
  1367. #if 0 /* NOTE(Kevin): condition check should move to P2P_FSM.c */
  1368. /*----------------------------------------------------------------------------*/
  1369. /*!
  1370. * @brief This function will process the Rx Probe Request Frame and then send
  1371. * back the corresponding Probe Response Frame if the specified conditions
  1372. * were matched.
  1373. *
  1374. * @param[in] prSwRfb Pointer to SW RFB data structure.
  1375. *
  1376. * @retval WLAN_STATUS_SUCCESS Always return success
  1377. */
  1378. /*----------------------------------------------------------------------------*/
  1379. WLAN_STATUS bssProcessProbeRequest(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfb)
  1380. {
  1381. P_WLAN_MAC_MGMT_HEADER_T prMgtHdr;
  1382. P_BSS_INFO_T prBssInfo;
  1383. P_IE_SSID_T prIeSsid = (P_IE_SSID_T) NULL;
  1384. P_IE_SUPPORTED_RATE_T prIeSupportedRate = (P_IE_SUPPORTED_RATE_T) NULL;
  1385. P_IE_EXT_SUPPORTED_RATE_T prIeExtSupportedRate = (P_IE_EXT_SUPPORTED_RATE_T) NULL;
  1386. PUINT_8 pucIE;
  1387. UINT_16 u2IELength;
  1388. UINT_16 u2Offset = 0;
  1389. UINT_8 aucBCBSSID[] = BC_BSSID;
  1390. ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex;
  1391. BOOLEAN fgReplyProbeResp;
  1392. #if CFG_ENABLE_WIFI_DIRECT
  1393. BOOLEAN fgP2PTargetDeviceFound;
  1394. UINT_8 aucP2PWildcardSSID[] = P2P_WILDCARD_SSID;
  1395. #endif
  1396. ASSERT(prSwRfb);
  1397. /* 4 <1> Parse Probe Req and Get SSID IE ptr */
  1398. prMgtHdr = (P_WLAN_MAC_MGMT_HEADER_T) prSwRfb->pvHeader;
  1399. u2IELength = prSwRfb->u2PacketLen - prSwRfb->u2HeaderLen;
  1400. pucIE = (PUINT_8) ((UINT_32) prSwRfb->pvHeader + prSwRfb->u2HeaderLen);
  1401. prIeSsid = (P_IE_SSID_T) NULL;
  1402. IE_FOR_EACH(pucIE, u2IELength, u2Offset) {
  1403. switch (IE_ID(pucIE)) {
  1404. case ELEM_ID_SSID:
  1405. if ((!prIeSsid) && (IE_LEN(pucIE) <= ELEM_MAX_LEN_SSID))
  1406. prIeSsid = (P_IE_SSID_T) pucIE;
  1407. break;
  1408. case ELEM_ID_SUP_RATES:
  1409. /* NOTE(Kevin): Buffalo WHR-G54S's supported rate set IE exceed 8.
  1410. * IE_LEN(pucIE) == 12, "1(B), 2(B), 5.5(B), 6(B), 9(B), 11(B),
  1411. * 12(B), 18(B), 24(B), 36(B), 48(B), 54(B)"
  1412. */
  1413. /* if (IE_LEN(pucIE) <= ELEM_MAX_LEN_SUP_RATES) { */
  1414. if (IE_LEN(pucIE) <= RATE_NUM)
  1415. prIeSupportedRate = SUP_RATES_IE(pucIE);
  1416. break;
  1417. case ELEM_ID_EXTENDED_SUP_RATES:
  1418. prIeExtSupportedRate = EXT_SUP_RATES_IE(pucIE);
  1419. break;
  1420. #if CFG_ENABLE_WIFI_DIRECT
  1421. /* TODO: P2P IE & WCS IE parsing for P2P. */
  1422. case ELEM_ID_P2P:
  1423. break;
  1424. #endif
  1425. /* no default */
  1426. }
  1427. } /* end of IE_FOR_EACH */
  1428. /* 4 <2> Check network conditions before reply Probe Response Frame (Consider Concurrent) */
  1429. for (eNetTypeIndex = NETWORK_TYPE_AIS_INDEX; eNetTypeIndex < NETWORK_TYPE_INDEX_NUM; eNetTypeIndex++) {
  1430. if (!IS_NET_ACTIVE(prAdapter, eNetTypeIndex))
  1431. continue;
  1432. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
  1433. if (UNEQUAL_MAC_ADDR(aucBCBSSID, prMgtHdr->aucBSSID) &&
  1434. UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prMgtHdr->aucBSSID)) {
  1435. /* BSSID not Wildcard BSSID. */
  1436. continue;
  1437. }
  1438. fgReplyProbeResp = FALSE;
  1439. if (NETWORK_TYPE_AIS_INDEX == eNetTypeIndex) {
  1440. if (prBssInfo->eCurrentOPMode == OP_MODE_IBSS) {
  1441. /* TODO(Kevin): Check if we are IBSS Master. */
  1442. if (TRUE && prIeSsid) {
  1443. if ((prIeSsid->ucLength == BC_SSID_LEN) || /* WILDCARD SSID */
  1444. EQUAL_SSID(prBssInfo->aucSSID, prBssInfo->ucSSIDLen,
  1445. prIeSsid->aucSSID, prIeSsid->ucLength)) {
  1446. fgReplyProbeResp = TRUE;
  1447. }
  1448. }
  1449. }
  1450. }
  1451. #if CFG_ENABLE_WIFI_DIRECT
  1452. else if (NETWORK_TYPE_P2P_INDEX == eNetTypeIndex) {
  1453. /* TODO(Kevin): Move following lines to p2p_fsm.c */
  1454. if ((prIeSsid) &&
  1455. ((prIeSsid->ucLength == BC_SSID_LEN) ||
  1456. (EQUAL_SSID(aucP2PWildcardSSID,
  1457. P2P_WILDCARD_SSID_LEN, prIeSsid->aucSSID, prIeSsid->ucLength)))) {
  1458. /* if (p2pFsmRunEventRxProbeRequestFrame(prAdapter, prMgtHdr->aucSrcAddr,
  1459. pucIE, u2IELength)) { */
  1460. if (p2pFsmRunEventRxProbeRequestFrame(prAdapter, prSwRfb)) {
  1461. /* Extand channel request time & cancel scan request. */
  1462. P_P2P_FSM_INFO_T prP2pFsmInfo = (P_P2P_FSM_INFO_T) NULL;
  1463. /* TODO: RX probe request may not caused by LISTEN state. */
  1464. /* TODO: It can be GO. */
  1465. /* Generally speaking, cancel a non-exist scan request is fine.
  1466. * We can check P2P FSM here for only LISTEN state.
  1467. */
  1468. P_MSG_SCN_SCAN_CANCEL prScanCancelMsg;
  1469. prP2pFsmInfo = prAdapter->rWifiVar.prP2pFsmInfo;
  1470. /* Abort JOIN process. */
  1471. prScanCancelMsg =
  1472. (P_MSG_SCN_SCAN_CANCEL) cnmMemAlloc(prAdapter, RAM_TYPE_MSG,
  1473. sizeof(MSG_SCN_SCAN_CANCEL));
  1474. if (!prScanCancelMsg) {
  1475. ASSERT(0); /* Can't abort SCN FSM */
  1476. continue;
  1477. }
  1478. prScanCancelMsg->rMsgHdr.eMsgId = MID_P2P_SCN_SCAN_CANCEL;
  1479. prScanCancelMsg->ucSeqNum = prP2pFsmInfo->ucSeqNumOfScnMsg;
  1480. prScanCancelMsg->ucNetTypeIndex = (UINT_8) NETWORK_TYPE_P2P_INDEX;
  1481. prScanCancelMsg->fgIsChannelExt = TRUE;
  1482. mboxSendMsg(prAdapter,
  1483. MBOX_ID_0, (P_MSG_HDR_T) prScanCancelMsg, MSG_SEND_METHOD_BUF);
  1484. }
  1485. } else {
  1486. /* 1. Probe Request without SSID.
  1487. * 2. Probe Request with SSID not Wildcard SSID & not P2P Wildcard SSID.
  1488. */
  1489. continue;
  1490. }
  1491. #if 0 /* Frog */
  1492. if (prAdapter->rWifiVar.prP2pFsmInfo->eCurrentState == P2P_STATE_LISTEN) {
  1493. /* P2P 2.4.1 - P2P Devices shall not respond to Probe Request frames
  1494. which only contain 11b rates only. */
  1495. if (prIeSupportedRate || prIeExtSupportedRate) {
  1496. UINT_16 u2OperationalRateSet, u2BSSBasicRateSet;
  1497. BOOLEAN fgIsUnknownBssBasicRate;
  1498. rateGetRateSetFromIEs(prIeSupportedRate, prIeExtSupportedRate,
  1499. &u2OperationalRateSet,
  1500. &u2BSSBasicRateSet, /* Ignore any Basic Bit */
  1501. &fgIsUnknownBssBasicRate);
  1502. if (u2OperationalRateSet & ~RATE_SET_HR_DSSS)
  1503. continue;
  1504. }
  1505. }
  1506. /* TODO: Check channel time before first check point to: */
  1507. /* If Target device is selected:
  1508. * 1. Send XXXX request frame.
  1509. * else
  1510. * 1. Send Probe Response frame.
  1511. */
  1512. if (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) {
  1513. /* TODO(Kevin): During PROVISION state, can we reply Probe Response ? */
  1514. /* TODO(Kevin):
  1515. * If we are GO, accept legacy client --> accept Wildcard SSID
  1516. * If we are in Listen State, accept only P2P Device --> check P2P IE and WPS IE
  1517. */
  1518. if (TRUE /* We are GO */ && prIeSsid) {
  1519. UINT_8 aucSSID[] = P2P_WILDCARD_SSID;
  1520. if ((prIeSsid->ucLength == BC_SSID_LEN) || /* WILDCARD SSID */
  1521. EQUAL_SSID(prBssInfo->aucSSID, prBssInfo->ucSSIDLen,
  1522. prIeSsid->aucSSID, prIeSsid->ucLength) ||
  1523. EQUAL_SSID(aucSSID, P2P_WILDCARD_SSID_LEN,
  1524. prIeSsid->aucSSID, prIeSsid->ucLength)) {
  1525. fgReplyProbeResp = TRUE;
  1526. }
  1527. }
  1528. /* else if (FALSE) { */ /* We are in Listen State */
  1529. /* } */
  1530. /* TODO(Kevin): Check P2P IE and WPS IE */
  1531. }
  1532. #endif
  1533. }
  1534. #endif
  1535. #if CFG_ENABLE_BT_OVER_WIFI
  1536. else if (NETWORK_TYPE_BOW_INDEX == eNetTypeIndex) {
  1537. if (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) {
  1538. /* Do nothing */
  1539. /* TODO(Kevin): TBD */
  1540. }
  1541. }
  1542. #endif
  1543. else
  1544. ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
  1545. if (fgReplyProbeResp)
  1546. bssSendBeaconProbeResponse(prAdapter, eNetTypeIndex, prMgtHdr->aucSrcAddr);
  1547. }
  1548. return WLAN_STATUS_SUCCESS;
  1549. } /* end of bssProcessProbeRequest() */
  1550. #endif
  1551. /*----------------------------------------------------------------------------*/
  1552. /*!
  1553. * @brief This function is used to clear the client list for AdHoc or AP Mode
  1554. *
  1555. * @param[in] prAdapter Pointer to the Adapter structure.
  1556. * @param[in] prBssInfo Given related BSS_INFO_T.
  1557. *
  1558. * @return (none)
  1559. */
  1560. /*----------------------------------------------------------------------------*/
  1561. VOID bssClearClientList(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo)
  1562. {
  1563. P_LINK_T prStaRecOfClientList;
  1564. ASSERT(prBssInfo);
  1565. prStaRecOfClientList = &prBssInfo->rStaRecOfClientList;
  1566. if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
  1567. P_STA_RECORD_T prPeerStaRec;
  1568. LINK_FOR_EACH_ENTRY(prPeerStaRec, prStaRecOfClientList, rLinkEntry, STA_RECORD_T) {
  1569. cnmStaRecChangeState(prAdapter, prPeerStaRec, STA_STATE_1);
  1570. }
  1571. LINK_INITIALIZE(prStaRecOfClientList);
  1572. }
  1573. } /* end of bssClearClientList() */
  1574. /*----------------------------------------------------------------------------*/
  1575. /*!
  1576. * @brief This function is used to Add a STA_RECORD_T to the client list for AdHoc or AP Mode
  1577. *
  1578. * @param[in] prAdapter Pointer to the Adapter structure.
  1579. * @param[in] prBssInfo Given related BSS_INFO_T.
  1580. * @param[in] prStaRec Pointer to the STA_RECORD_T
  1581. *
  1582. * @return (none)
  1583. */
  1584. /*----------------------------------------------------------------------------*/
  1585. VOID bssAddStaRecToClientList(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo, IN P_STA_RECORD_T prStaRec)
  1586. {
  1587. P_LINK_T prStaRecOfClientList;
  1588. ASSERT(prBssInfo);
  1589. prStaRecOfClientList = &prBssInfo->rStaRecOfClientList;
  1590. if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
  1591. P_STA_RECORD_T prCurrStaRec;
  1592. LINK_FOR_EACH_ENTRY(prCurrStaRec, prStaRecOfClientList, rLinkEntry, STA_RECORD_T) {
  1593. if (prCurrStaRec == prStaRec) {
  1594. DBGLOG(BSS, WARN,
  1595. "Current Client List already contains that STA_RECORD_T[%pM]\n",
  1596. prStaRec->aucMacAddr);
  1597. return;
  1598. }
  1599. }
  1600. }
  1601. LINK_INSERT_TAIL(prStaRecOfClientList, &prStaRec->rLinkEntry);
  1602. } /* end of bssAddStaRecToClientList() */
  1603. /*----------------------------------------------------------------------------*/
  1604. /*!
  1605. * @brief This function is used to Remove a STA_RECORD_T from the client list for AdHoc or AP Mode
  1606. *
  1607. * @param[in] prAdapter Pointer to the Adapter structure.
  1608. * @param[in] prStaRec Pointer to the STA_RECORD_T
  1609. *
  1610. * @return (none)
  1611. */
  1612. /*----------------------------------------------------------------------------*/
  1613. VOID bssRemoveStaRecFromClientList(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo, IN P_STA_RECORD_T prStaRec)
  1614. {
  1615. P_LINK_T prStaRecOfClientList;
  1616. ASSERT(prBssInfo);
  1617. prStaRecOfClientList = &prBssInfo->rStaRecOfClientList;
  1618. #if 0
  1619. if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
  1620. P_STA_RECORD_T prCurrStaRec;
  1621. LINK_FOR_EACH_ENTRY(prCurrStaRec, prStaRecOfClientList, rLinkEntry, STA_RECORD_T) {
  1622. if (prCurrStaRec == prStaRec) {
  1623. LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prStaRec->rLinkEntry);
  1624. return;
  1625. }
  1626. }
  1627. }
  1628. #endif
  1629. if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
  1630. P_LINK_ENTRY_T prLinkEntry = (P_LINK_ENTRY_T) NULL;
  1631. LINK_FOR_EACH(prLinkEntry, prStaRecOfClientList) {
  1632. if ((ULONG) prStaRec == (ULONG) prLinkEntry) {
  1633. LINK_REMOVE_KNOWN_ENTRY(prStaRecOfClientList, &prStaRec->rLinkEntry);
  1634. return;
  1635. }
  1636. }
  1637. }
  1638. DBGLOG(BSS, INFO, "Current Client List didn't contain that STA_RECORD_T[%pM] before removing.\n",
  1639. prStaRec->aucMacAddr);
  1640. } /* end of bssRemoveStaRecFromClientList() */
  1641. #endif /* CFG_SUPPORT_ADHOC || CFG_SUPPORT_AAA */
  1642. /*----------------------------------------------------------------------------*/
  1643. /*!
  1644. * @brief Get station record by Address for AP mode
  1645. *
  1646. * @param[in] prBssInfo Pointer to BSS_INFO_T.
  1647. * @param[in] pucMacAddr Pointer to target mac address
  1648. *
  1649. * @return pointer of STA_RECORD_T if found, otherwise, return NULL
  1650. */
  1651. /*----------------------------------------------------------------------------*/
  1652. P_STA_RECORD_T bssGetClientByAddress(IN P_BSS_INFO_T prBssInfo, PUINT_8 pucMacAddr)
  1653. {
  1654. P_LINK_T prStaRecOfClientList;
  1655. ASSERT(prBssInfo);
  1656. ASSERT(pucMacAddr);
  1657. prStaRecOfClientList = &prBssInfo->rStaRecOfClientList;
  1658. if (!LINK_IS_EMPTY(prStaRecOfClientList)) {
  1659. P_STA_RECORD_T prCurrStaRec;
  1660. LINK_FOR_EACH_ENTRY(prCurrStaRec, prStaRecOfClientList, rLinkEntry, STA_RECORD_T) {
  1661. if (EQUAL_MAC_ADDR(prCurrStaRec->aucMacAddr, pucMacAddr))
  1662. return prCurrStaRec;
  1663. }
  1664. }
  1665. return NULL;
  1666. }
  1667. #if CFG_SUPPORT_ADHOC
  1668. /*----------------------------------------------------------------------------*/
  1669. /* Routines for IBSS(AdHoc) only */
  1670. /*----------------------------------------------------------------------------*/
  1671. /*----------------------------------------------------------------------------*/
  1672. /*!
  1673. * @brief This function is used to process Beacons from current Ad-Hoc network peers.
  1674. * We also process Beacons from other Ad-Hoc network during SCAN. If it has
  1675. * the same SSID and we'll decide to merge into it if it has a larger TSF.
  1676. *
  1677. * @param[in] prAdapter Pointer to the Adapter structure.
  1678. * @param[in] prBssInfo Pointer to the BSS_INFO_T.
  1679. * @param[in] prBSSDesc Pointer to the BSS Descriptor.
  1680. *
  1681. * @return (none)
  1682. */
  1683. /*----------------------------------------------------------------------------*/
  1684. VOID
  1685. ibssProcessMatchedBeacon(IN P_ADAPTER_T prAdapter,
  1686. IN P_BSS_INFO_T prBssInfo, IN P_BSS_DESC_T prBssDesc, IN UINT_8 ucRCPI)
  1687. {
  1688. P_STA_RECORD_T prStaRec = NULL;
  1689. BOOLEAN fgIsCheckCapability = FALSE;
  1690. BOOLEAN fgIsCheckTSF = FALSE;
  1691. BOOLEAN fgIsGoingMerging = FALSE;
  1692. BOOLEAN fgIsSameBSSID;
  1693. ASSERT(prBssInfo);
  1694. ASSERT(prBssDesc);
  1695. /* 4 <1> Process IBSS Beacon only after we create or merge with other IBSS. */
  1696. if (!prBssInfo->fgIsBeaconActivated)
  1697. return;
  1698. /* 4 <2> Get the STA_RECORD_T of TA. */
  1699. prStaRec = cnmGetStaRecByAddress(prAdapter, (UINT_8) NETWORK_TYPE_AIS_INDEX, prBssDesc->aucSrcAddr);
  1700. fgIsSameBSSID = UNEQUAL_MAC_ADDR(prBssInfo->aucBSSID, prBssDesc->aucBSSID) ? FALSE : TRUE;
  1701. /* 4 <3> IBSS Merge Decision Flow for Processing Beacon. */
  1702. if (fgIsSameBSSID) {
  1703. /* Same BSSID:
  1704. * Case I. This is a new TA and it has decide to merged with us.
  1705. * a) If fgIsMerging == FALSE - we will send msg to notify AIS.
  1706. * b) If fgIsMerging == TRUE - already notify AIS.
  1707. * Case II. This is an old TA and we've already merged together.
  1708. */
  1709. if (!prStaRec) {
  1710. /* For Case I - Check this IBSS's capability first before adding this Sta Record. */
  1711. fgIsCheckCapability = TRUE;
  1712. /* If check is passed, then we perform merging with this new IBSS */
  1713. fgIsGoingMerging = TRUE;
  1714. } else {
  1715. ASSERT((prStaRec->ucNetTypeIndex == NETWORK_TYPE_AIS_INDEX) && IS_ADHOC_STA(prStaRec));
  1716. if (prStaRec->ucStaState != STA_STATE_3) {
  1717. if (!prStaRec->fgIsMerging) {
  1718. /* For Case I - Check this IBSS's capability first
  1719. * before adding this Sta Record. */
  1720. fgIsCheckCapability = TRUE;
  1721. /* If check is passed, then we perform merging with this new IBSS */
  1722. fgIsGoingMerging = TRUE;
  1723. } else {
  1724. /* For Case II - Update rExpirationTime of Sta Record */
  1725. GET_CURRENT_SYSTIME(&prStaRec->rUpdateTime);
  1726. }
  1727. } else {
  1728. /* For Case II - Update rExpirationTime of Sta Record */
  1729. GET_CURRENT_SYSTIME(&prStaRec->rUpdateTime);
  1730. }
  1731. }
  1732. } else {
  1733. /* Unequal BSSID:
  1734. * Case III. This is a new TA and we need to compare the TSF and get the winner.
  1735. * Case IV. This is an old TA and it merge into a new IBSS before we do the same thing.
  1736. * We need to compare the TSF to get the winner.
  1737. * Case V. This is an old TA and it restart a new IBSS. We also need to
  1738. * compare the TSF to get the winner.
  1739. */
  1740. /* For Case III, IV & V - We'll always check this new IBSS's capability first
  1741. * before merging into new IBSS.
  1742. */
  1743. fgIsCheckCapability = TRUE;
  1744. /* If check is passed, we need to perform TSF check to decide the major BSSID */
  1745. fgIsCheckTSF = TRUE;
  1746. /* For Case IV & V - We won't update rExpirationTime of Sta Record */
  1747. }
  1748. /* 4 <7> Check this BSS_DESC_T's capability. */
  1749. if (fgIsCheckCapability) {
  1750. BOOLEAN fgIsCapabilityMatched = FALSE;
  1751. do {
  1752. if (!(prBssDesc->ucPhyTypeSet & (prAdapter->rWifiVar.ucAvailablePhyTypeSet))) {
  1753. DBGLOG(BSS, LOUD,
  1754. "IBSS MERGE: Ignore Peer MAC: %pM - Unsupported Phy.\n",
  1755. prBssDesc->aucSrcAddr);
  1756. break;
  1757. }
  1758. if (prBssDesc->fgIsUnknownBssBasicRate) {
  1759. DBGLOG(BSS, LOUD,
  1760. "IBSS MERGE: Ignore Peer MAC: %pM - Unknown Basic Rate.\n",
  1761. prBssDesc->aucSrcAddr);
  1762. break;
  1763. }
  1764. if (ibssCheckCapabilityForAdHocMode(prAdapter, prBssDesc) == WLAN_STATUS_FAILURE) {
  1765. DBGLOG(BSS, LOUD,
  1766. "IBSS MERGE: Ignore Peer MAC: %pM - Capability is not matched.\n",
  1767. prBssDesc->aucSrcAddr);
  1768. break;
  1769. }
  1770. fgIsCapabilityMatched = TRUE;
  1771. } while (FALSE);
  1772. if (!fgIsCapabilityMatched) {
  1773. if (prStaRec) {
  1774. /* For Case II - We merge this STA_RECORD in RX Path.
  1775. * Case IV & V - They change their BSSID after we merge with them.
  1776. */
  1777. DBGLOG(BSS, LOUD,
  1778. "IBSS MERGE: Ignore Peer MAC: %pM - Capability is not matched.\n",
  1779. prBssDesc->aucSrcAddr);
  1780. }
  1781. return;
  1782. }
  1783. DBGLOG(BSS, LOUD,
  1784. "IBSS MERGE: Peer MAC: %pM - Check capability was passed.\n",
  1785. prBssDesc->aucSrcAddr);
  1786. }
  1787. if (fgIsCheckTSF) {
  1788. #if CFG_SLT_SUPPORT
  1789. fgIsGoingMerging = TRUE;
  1790. #else
  1791. if (prBssDesc->fgIsLargerTSF)
  1792. fgIsGoingMerging = TRUE;
  1793. else
  1794. return;
  1795. #endif
  1796. }
  1797. if (fgIsGoingMerging) {
  1798. P_MSG_AIS_IBSS_PEER_FOUND_T prAisIbssPeerFoundMsg;
  1799. /* 4 <1> We will merge with to this BSS immediately. */
  1800. prBssDesc->fgIsConnecting = TRUE;
  1801. prBssDesc->fgIsConnected = FALSE;
  1802. /* 4 <2> Setup corresponding STA_RECORD_T */
  1803. prStaRec = bssCreateStaRecFromBssDesc(prAdapter,
  1804. STA_TYPE_ADHOC_PEER, NETWORK_TYPE_AIS_INDEX, prBssDesc);
  1805. if (!prStaRec) {
  1806. /* no memory ? */
  1807. return;
  1808. }
  1809. prStaRec->fgIsMerging = TRUE;
  1810. /* update RCPI */
  1811. prStaRec->ucRCPI = ucRCPI;
  1812. /* 4 <3> Send Merge Msg to CNM to obtain the channel privilege. */
  1813. prAisIbssPeerFoundMsg = (P_MSG_AIS_IBSS_PEER_FOUND_T)
  1814. cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_AIS_IBSS_PEER_FOUND_T));
  1815. if (!prAisIbssPeerFoundMsg) {
  1816. ASSERT(0); /* Can't send Merge Msg */
  1817. return;
  1818. }
  1819. prAisIbssPeerFoundMsg->rMsgHdr.eMsgId = MID_SCN_AIS_FOUND_IBSS;
  1820. prAisIbssPeerFoundMsg->ucNetTypeIndex = (UINT_8) NETWORK_TYPE_AIS_INDEX;
  1821. prAisIbssPeerFoundMsg->prStaRec = prStaRec;
  1822. /* Inform AIS to do STATE TRANSITION
  1823. * For Case I - If AIS in IBSS_ALONE, let it jump to NORMAL_TR after we know the new member.
  1824. * For Case III, IV - Now this new BSSID wins the TSF, follow it.
  1825. */
  1826. if (fgIsSameBSSID) {
  1827. prAisIbssPeerFoundMsg->fgIsMergeIn = TRUE;
  1828. } else {
  1829. #if CFG_SLT_SUPPORT
  1830. prAisIbssPeerFoundMsg->fgIsMergeIn = TRUE;
  1831. #else
  1832. prAisIbssPeerFoundMsg->fgIsMergeIn = (prBssDesc->fgIsLargerTSF) ? FALSE : TRUE;
  1833. #endif
  1834. }
  1835. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prAisIbssPeerFoundMsg, MSG_SEND_METHOD_BUF);
  1836. }
  1837. } /* end of ibssProcessMatchedBeacon() */
  1838. /*----------------------------------------------------------------------------*/
  1839. /*!
  1840. * @brief This function will check the Capability for Ad-Hoc to decide if we are
  1841. * able to merge with(same capability).
  1842. *
  1843. * @param[in] prBSSDesc Pointer to the BSS Descriptor.
  1844. *
  1845. * @retval WLAN_STATUS_FAILURE Can't pass the check of Capability.
  1846. * @retval WLAN_STATUS_SUCCESS Pass the check of Capability.
  1847. */
  1848. /*----------------------------------------------------------------------------*/
  1849. WLAN_STATUS ibssCheckCapabilityForAdHocMode(IN P_ADAPTER_T prAdapter, IN P_BSS_DESC_T prBssDesc)
  1850. {
  1851. P_CONNECTION_SETTINGS_T prConnSettings;
  1852. WLAN_STATUS rStatus = WLAN_STATUS_FAILURE;
  1853. ASSERT(prBssDesc);
  1854. prConnSettings = &(prAdapter->rWifiVar.rConnSettings);
  1855. do {
  1856. /* 4 <1> Check the BSS Basic Rate Set for current AdHoc Mode */
  1857. if ((prConnSettings->eAdHocMode == AD_HOC_MODE_11B) &&
  1858. (prBssDesc->u2BSSBasicRateSet & ~RATE_SET_HR_DSSS)) {
  1859. break;
  1860. } else if ((prConnSettings->eAdHocMode == AD_HOC_MODE_11A) &&
  1861. (prBssDesc->u2BSSBasicRateSet & ~RATE_SET_OFDM)) {
  1862. break;
  1863. }
  1864. /* 4 <2> Check the Short Slot Time. */
  1865. #if 0 /* Do not check ShortSlotTime until Wi-Fi define such policy */
  1866. if (prConnSettings->eAdHocMode == AD_HOC_MODE_11G) {
  1867. if (((prConnSettings->fgIsShortSlotTimeOptionEnable) &&
  1868. !(prBssDesc->u2CapInfo & CAP_INFO_SHORT_SLOT_TIME)) ||
  1869. (!(prConnSettings->fgIsShortSlotTimeOptionEnable) &&
  1870. (prBssDesc->u2CapInfo & CAP_INFO_SHORT_SLOT_TIME))) {
  1871. break;
  1872. }
  1873. }
  1874. #endif
  1875. /* 4 <3> Check the ATIM window setting. */
  1876. if (prBssDesc->u2ATIMWindow) {
  1877. DBGLOG(BSS, INFO, "AdHoc PS was not supported(ATIM Window: %d)\n", prBssDesc->u2ATIMWindow);
  1878. break;
  1879. }
  1880. #if CFG_RSN_MIGRATION
  1881. /* 4 <4> Check the Security setting. */
  1882. if (!rsnPerformPolicySelection(prAdapter, prBssDesc))
  1883. break;
  1884. #endif
  1885. rStatus = WLAN_STATUS_SUCCESS;
  1886. } while (FALSE);
  1887. return rStatus;
  1888. } /* end of ibssCheckCapabilityForAdHocMode() */
  1889. /*----------------------------------------------------------------------------*/
  1890. /*!
  1891. * @brief This function will initial the BSS_INFO_T for IBSS Mode.
  1892. *
  1893. * @param[in] prBssInfo Pointer to the BSS_INFO_T.
  1894. *
  1895. * @return (none)
  1896. */
  1897. /*----------------------------------------------------------------------------*/
  1898. VOID ibssInitForAdHoc(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo)
  1899. {
  1900. UINT_8 ucLowestBasicRateIndex;
  1901. UINT_8 aucBSSID[MAC_ADDR_LEN];
  1902. PUINT_16 pu2BSSID = (PUINT_16) &aucBSSID[0];
  1903. UINT_32 i;
  1904. ASSERT(prBssInfo);
  1905. ASSERT(prBssInfo->eCurrentOPMode == OP_MODE_IBSS);
  1906. /* 4 <1> Setup PHY Attributes and Basic Rate Set/Operational Rate Set */
  1907. prBssInfo->ucNonHTBasicPhyType = (UINT_8)
  1908. rNonHTAdHocModeAttributes[prBssInfo->ucConfigAdHocAPMode].ePhyTypeIndex;
  1909. prBssInfo->u2BSSBasicRateSet = rNonHTAdHocModeAttributes[prBssInfo->ucConfigAdHocAPMode].u2BSSBasicRateSet;
  1910. prBssInfo->u2OperationalRateSet = rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].u2SupportedRateSet;
  1911. rateGetDataRatesFromRateSet(prBssInfo->u2OperationalRateSet,
  1912. prBssInfo->u2BSSBasicRateSet,
  1913. prBssInfo->aucAllSupportedRates, &prBssInfo->ucAllSupportedRatesLen);
  1914. /* 4 <2> Setup BSSID */
  1915. if (!prBssInfo->fgHoldSameBssidForIBSS) {
  1916. for (i = 0; i < sizeof(aucBSSID) / sizeof(UINT_16); i++)
  1917. pu2BSSID[i] = (UINT_16) (kalRandomNumber() & 0xFFFF);
  1918. aucBSSID[0] &= ~0x01; /* 7.1.3.3.3 - The individual/group bit of the address is set to 0. */
  1919. aucBSSID[0] |= 0x02; /* 7.1.3.3.3 - The universal/local bit of the address is set to 1. */
  1920. COPY_MAC_ADDR(prBssInfo->aucBSSID, aucBSSID);
  1921. }
  1922. /* 4 <3> Setup Capability - Short Preamble */
  1923. if (rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].fgIsShortPreambleOptionImplemented &&
  1924. ((prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_SHORT) || /* Short Preamble Option Enable is TRUE */
  1925. (prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_AUTO))) {
  1926. prBssInfo->fgIsShortPreambleAllowed = TRUE;
  1927. prBssInfo->fgUseShortPreamble = TRUE;
  1928. } else {
  1929. prBssInfo->fgIsShortPreambleAllowed = FALSE;
  1930. prBssInfo->fgUseShortPreamble = FALSE;
  1931. }
  1932. /* 4 <4> Setup Capability - Short Slot Time */
  1933. /* 7.3.1.4 For IBSS, the Short Slot Time subfield shall be set to 0. */
  1934. prBssInfo->fgUseShortSlotTime = FALSE; /* Set to FALSE for AdHoc */
  1935. /* 4 <5> Compoase Capability */
  1936. prBssInfo->u2CapInfo = CAP_INFO_IBSS;
  1937. if (prBssInfo->fgIsProtection)
  1938. prBssInfo->u2CapInfo |= CAP_INFO_PRIVACY;
  1939. if (prBssInfo->fgIsShortPreambleAllowed)
  1940. prBssInfo->u2CapInfo |= CAP_INFO_SHORT_PREAMBLE;
  1941. if (prBssInfo->fgUseShortSlotTime)
  1942. prBssInfo->u2CapInfo |= CAP_INFO_SHORT_SLOT_TIME;
  1943. /* 4 <6> Find Lowest Basic Rate Index for default TX Rate of MMPDU */
  1944. rateGetLowestRateIndexFromRateSet(prBssInfo->u2BSSBasicRateSet, &ucLowestBasicRateIndex);
  1945. prBssInfo->ucHwDefaultFixedRateCode = aucRateIndex2RateCode[PREAMBLE_DEFAULT_LONG_NONE][ucLowestBasicRateIndex];
  1946. } /* end of ibssInitForAdHoc() */
  1947. #endif /* CFG_SUPPORT_ADHOC */
  1948. #if CFG_SUPPORT_AAA
  1949. /*----------------------------------------------------------------------------*/
  1950. /* Routines for BSS(AP) only */
  1951. /*----------------------------------------------------------------------------*/
  1952. /*----------------------------------------------------------------------------*/
  1953. /*!
  1954. * @brief This function will initial the BSS_INFO_T for AP Mode.
  1955. *
  1956. * @param[in] prBssInfo Given related BSS_INFO_T.
  1957. *
  1958. * @return (none)
  1959. */
  1960. /*----------------------------------------------------------------------------*/
  1961. VOID bssInitForAP(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo, IN BOOLEAN fgIsRateUpdate)
  1962. {
  1963. UINT_8 ucLowestBasicRateIndex;
  1964. P_AC_QUE_PARMS_T prACQueParms;
  1965. ENUM_WMM_ACI_T eAci;
  1966. UINT_8 auCWminLog2ForBcast[WMM_AC_INDEX_NUM] = { 4 /*BE*/, 4 /*BK*/, 3 /*VO*/, 2 /*VI*/ };
  1967. UINT_8 auCWmaxLog2ForBcast[WMM_AC_INDEX_NUM] = { 10, 10, 4, 3 };
  1968. UINT_8 auAifsForBcast[WMM_AC_INDEX_NUM] = { 3, 7, 2, 2 };
  1969. UINT_8 auTxopForBcast[WMM_AC_INDEX_NUM] = { 0, 0, 94, 47 }; /* If the AP is OFDM */
  1970. UINT_8 auCWminLog2[WMM_AC_INDEX_NUM] = { 4 /*BE*/, 4 /*BK*/, 3 /*VO*/, 2 /*VI*/ };
  1971. UINT_8 auCWmaxLog2[WMM_AC_INDEX_NUM] = { 7, 10, 4, 3 };
  1972. UINT_8 auAifs[WMM_AC_INDEX_NUM] = { 3, 7, 1, 1 };
  1973. UINT_8 auTxop[WMM_AC_INDEX_NUM] = { 0, 0, 94, 47 }; /* If the AP is OFDM */
  1974. DEBUGFUNC("bssInitForAP");
  1975. DBGLOG(BSS, LOUD, "\n");
  1976. ASSERT(prBssInfo);
  1977. ASSERT((prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) || (prBssInfo->eCurrentOPMode == OP_MODE_BOW));
  1978. #if 0
  1979. prAdapter->rWifiVar.rConnSettings.fgRxShortGIDisabled = TRUE;
  1980. prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode = CONFIG_BW_20M;
  1981. prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode = CONFIG_BW_20M;
  1982. #endif
  1983. /* 4 <1> Setup PHY Attributes and Basic Rate Set/Operational Rate Set */
  1984. prBssInfo->ucNonHTBasicPhyType = (UINT_8)
  1985. rNonHTApModeAttributes[prBssInfo->ucConfigAdHocAPMode].ePhyTypeIndex;
  1986. prBssInfo->u2BSSBasicRateSet = rNonHTApModeAttributes[prBssInfo->ucConfigAdHocAPMode].u2BSSBasicRateSet;
  1987. prBssInfo->u2OperationalRateSet = rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].u2SupportedRateSet;
  1988. if (fgIsRateUpdate) {
  1989. rateGetDataRatesFromRateSet(prBssInfo->u2OperationalRateSet,
  1990. prBssInfo->u2BSSBasicRateSet,
  1991. prBssInfo->aucAllSupportedRates, &prBssInfo->ucAllSupportedRatesLen);
  1992. }
  1993. /* 4 <2> Setup BSSID */
  1994. COPY_MAC_ADDR(prBssInfo->aucBSSID, prBssInfo->aucOwnMacAddr);
  1995. /* 4 <3> Setup Capability - Short Preamble */
  1996. if (rNonHTPhyAttributes[prBssInfo->ucNonHTBasicPhyType].fgIsShortPreambleOptionImplemented &&
  1997. ((prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_SHORT) || /* Short Preamble Option Enable is TRUE */
  1998. (prAdapter->rWifiVar.ePreambleType == PREAMBLE_TYPE_AUTO))) {
  1999. prBssInfo->fgIsShortPreambleAllowed = TRUE;
  2000. prBssInfo->fgUseShortPreamble = TRUE;
  2001. } else {
  2002. prBssInfo->fgIsShortPreambleAllowed = FALSE;
  2003. prBssInfo->fgUseShortPreamble = FALSE;
  2004. }
  2005. /* 4 <4> Setup Capability - Short Slot Time */
  2006. prBssInfo->fgUseShortSlotTime = TRUE;
  2007. /* 4 <5> Compoase Capability */
  2008. prBssInfo->u2CapInfo = CAP_INFO_ESS;
  2009. if (prBssInfo->fgIsProtection)
  2010. prBssInfo->u2CapInfo |= CAP_INFO_PRIVACY;
  2011. if (prBssInfo->fgIsShortPreambleAllowed)
  2012. prBssInfo->u2CapInfo |= CAP_INFO_SHORT_PREAMBLE;
  2013. if (prBssInfo->fgUseShortSlotTime)
  2014. prBssInfo->u2CapInfo |= CAP_INFO_SHORT_SLOT_TIME;
  2015. /* 4 <6> Find Lowest Basic Rate Index for default TX Rate of MMPDU */
  2016. rateGetLowestRateIndexFromRateSet(prBssInfo->u2BSSBasicRateSet, &ucLowestBasicRateIndex);
  2017. prBssInfo->ucHwDefaultFixedRateCode = aucRateIndex2RateCode[PREAMBLE_DEFAULT_LONG_NONE][ucLowestBasicRateIndex];
  2018. /* 4 <7> Fill the EDCA */
  2019. prACQueParms = prBssInfo->arACQueParmsForBcast;
  2020. for (eAci = 0; eAci < WMM_AC_INDEX_NUM; eAci++) {
  2021. prACQueParms[eAci].fgIsACMSet = FALSE;
  2022. prACQueParms[eAci].u2Aifsn = auAifsForBcast[eAci];
  2023. prACQueParms[eAci].u2CWmin = BIT(auCWminLog2ForBcast[eAci]) - 1;
  2024. prACQueParms[eAci].u2CWmax = BIT(auCWmaxLog2ForBcast[eAci]) - 1;
  2025. prACQueParms[eAci].u2TxopLimit = auTxopForBcast[eAci];
  2026. prBssInfo->aucCWminLog2ForBcast[eAci] = auCWminLog2ForBcast[eAci]; /* used to send WMM IE */
  2027. prBssInfo->aucCWmaxLog2ForBcast[eAci] = auCWmaxLog2ForBcast[eAci];
  2028. DBGLOG(BSS, INFO, "Bcast: eAci = %d, ACM = %d, Aifsn = %d, CWmin = %d, CWmax = %d, TxopLimit = %d\n",
  2029. eAci, prACQueParms[eAci].fgIsACMSet,
  2030. prACQueParms[eAci].u2Aifsn,
  2031. prACQueParms[eAci].u2CWmin,
  2032. prACQueParms[eAci].u2CWmax, prACQueParms[eAci].u2TxopLimit);
  2033. }
  2034. prACQueParms = prBssInfo->arACQueParms;
  2035. for (eAci = 0; eAci < WMM_AC_INDEX_NUM; eAci++) {
  2036. prACQueParms[eAci].fgIsACMSet = FALSE;
  2037. prACQueParms[eAci].u2Aifsn = auAifs[eAci];
  2038. prACQueParms[eAci].u2CWmin = BIT(auCWminLog2[eAci]) - 1;
  2039. prACQueParms[eAci].u2CWmax = BIT(auCWmaxLog2[eAci]) - 1;
  2040. prACQueParms[eAci].u2TxopLimit = auTxop[eAci];
  2041. DBGLOG(BSS, INFO, "eAci = %d, ACM = %d, Aifsn = %d, CWmin = %d, CWmax = %d, TxopLimit = %d\n",
  2042. eAci, prACQueParms[eAci].fgIsACMSet,
  2043. prACQueParms[eAci].u2Aifsn,
  2044. prACQueParms[eAci].u2CWmin,
  2045. prACQueParms[eAci].u2CWmax, prACQueParms[eAci].u2TxopLimit);
  2046. }
  2047. /* Note: Caller should update the EDCA setting to HW by nicQmUpdateWmmParms() it there is no AIS network */
  2048. /* Note: In E2, only 4 HW queues. The the Edca parameters should be folow by AIS network */
  2049. /* Note: In E3, 8 HW queues. the Wmm parameters should be updated to right queues according to BSS */
  2050. } /* end of bssInitForAP() */
  2051. #if 0
  2052. /*----------------------------------------------------------------------------*/
  2053. /*!
  2054. * @brief Update DTIM Count
  2055. *
  2056. * @param[in] eNetTypeIndex Specify which network to update
  2057. *
  2058. * @return (none)
  2059. */
  2060. /*----------------------------------------------------------------------------*/
  2061. VOID bssUpdateDTIMCount(IN P_ADAPTER_T prAdapter, IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex)
  2062. {
  2063. P_BSS_INFO_T prBssInfo;
  2064. ASSERT(eNetTypeIndex < NETWORK_TYPE_INDEX_NUM);
  2065. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
  2066. if (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT) {
  2067. /* Setup DTIM Count for next TBTT. */
  2068. if (prBssInfo->ucDTIMCount > 0) {
  2069. prBssInfo->ucDTIMCount--;
  2070. } else {
  2071. ASSERT(prBssInfo->ucDTIMPeriod > 0);
  2072. prBssInfo->ucDTIMCount = prBssInfo->ucDTIMPeriod - 1;
  2073. }
  2074. }
  2075. } /* end of bssUpdateDTIMIE() */
  2076. /*----------------------------------------------------------------------------*/
  2077. /*!
  2078. * @brief This function is used to set the Virtual Bitmap in TIM Information Elements
  2079. *
  2080. * @param[in] prBssInfo Pointer to the BSS_INFO_T.
  2081. * @param[in] u2AssocId The association id to set in Virtual Bitmap.
  2082. *
  2083. * @return (none)
  2084. */
  2085. /*----------------------------------------------------------------------------*/
  2086. VOID bssSetTIMBitmap(IN P_ADAPTER_T prAdapter, IN P_BSS_INFO_T prBssInfo, IN UINT_16 u2AssocId)
  2087. {
  2088. ASSERT(prBssInfo);
  2089. if (prBssInfo->ucNetTypeIndex == NETWORK_TYPE_P2P_INDEX) {
  2090. P_P2P_SPECIFIC_BSS_INFO_T prP2pSpecificBssInfo;
  2091. prP2pSpecificBssInfo = &(prAdapter->rWifiVar.rP2pSpecificBssInfo);
  2092. /* Use Association ID == 0 for BMCAST indication */
  2093. if (u2AssocId == 0) {
  2094. prP2pSpecificBssInfo->ucBitmapCtrl |= (UINT_8) BIT(0);
  2095. } else {
  2096. PUINT_8 pucPartialVirtualBitmap;
  2097. UINT_8 ucBitmapToSet;
  2098. /* (u2AssocId / 8) */
  2099. pucPartialVirtualBitmap = &prP2pSpecificBssInfo->aucPartialVirtualBitmap[(u2AssocId >> 3)];
  2100. ucBitmapToSet = (UINT_8) BIT((u2AssocId % 8));
  2101. if (*pucPartialVirtualBitmap & ucBitmapToSet) {
  2102. /* The virtual bitmap has been set */
  2103. return;
  2104. }
  2105. *pucPartialVirtualBitmap |= ucBitmapToSet;
  2106. /* Update u2SmallestAID and u2LargestAID */
  2107. if ((u2AssocId < prP2pSpecificBssInfo->u2SmallestAID) ||
  2108. (prP2pSpecificBssInfo->u2SmallestAID == 0)) {
  2109. prP2pSpecificBssInfo->u2SmallestAID = u2AssocId;
  2110. }
  2111. if ((u2AssocId > prP2pSpecificBssInfo->u2LargestAID) ||
  2112. (prP2pSpecificBssInfo->u2LargestAID == 0)) {
  2113. prP2pSpecificBssInfo->u2LargestAID = u2AssocId;
  2114. }
  2115. }
  2116. }
  2117. } /* end of bssSetTIMBitmap() */
  2118. #endif
  2119. #endif /* CFG_SUPPORT_AAA */
  2120. VOID bssCreateStaRecFromAuth(IN P_ADAPTER_T prAdapter)
  2121. {
  2122. }
  2123. VOID bssUpdateStaRecFromAssocReq(IN P_ADAPTER_T prAdapter)
  2124. {
  2125. }