cnm_mem.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/cnm_mem.c#2
  3. */
  4. /*! \file "cnm_mem.c"
  5. \brief This file contain the management function of packet buffers and
  6. generic memory alloc/free functioin for mailbox message.
  7. A data packet has a fixed size of buffer, but a management
  8. packet can be equipped with a variable size of buffer.
  9. */
  10. /*
  11. ** Log: cnm_mem.c
  12. **
  13. ** 04 17 2014 eason.tsai
  14. ** [ALPS01525263] [6595][6630][WiFi][Certification]11n AP 4.2.26-The HT Protection Field is not 3 in beacon
  15. ** fix certification HT!=3 issue
  16. **
  17. ** 08 05 2013 terry.wu
  18. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  19. ** 1. Add SW rate definition
  20. ** 2. Add HW default rate selection logic from FW
  21. **
  22. ** 07 26 2013 terry.wu
  23. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  24. ** 1. Reduce extra Tx frame header parsing
  25. ** 2. Add TX port control
  26. ** 3. Add net interface to BSS binding
  27. **
  28. ** 07 04 2013 terry.wu
  29. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  30. ** Update for 1st Connection.
  31. **
  32. ** 07 03 2013 wh.su
  33. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  34. ** Refine some normal security code
  35. **
  36. ** 07 02 2013 wh.su
  37. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  38. ** Refine some secutity code
  39. **
  40. ** 07 02 2013 wh.su
  41. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  42. ** Refine security BMC wlan index assign
  43. ** Fix some compiling warning
  44. **
  45. ** 06 14 2013 eddie.chen
  46. ** [BORA00002450] [WIFISYS][MT6630] New design for mt6630
  47. ** Add full mcsset. Add more vht info in sta update
  48. **
  49. ** 04 17 2013 cm.chang
  50. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  51. ** Mgt buffer allocated by physical instead of virtual
  52. **
  53. ** 04 12 2013 wh.su
  54. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  55. ** update some normal security code
  56. **
  57. ** 03 29 2013 wh.su
  58. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  59. ** Do more sta record free mechanism check
  60. ** remove non-used code
  61. **
  62. ** 03 20 2013 tsaiyuan.hsu
  63. ** [BORA00002222] MT6630 unified MAC RXM
  64. ** add rx duplicate check.
  65. **
  66. ** 03 20 2013 wh.su
  67. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  68. ** Add the security code for wlan table assign operation
  69. **
  70. ** 03 08 2013 wh.su
  71. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  72. ** Modify code for security design
  73. **
  74. ** 03 06 2013 wh.su
  75. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  76. ** submit some code related with security.
  77. **
  78. ** 02 18 2013 cm.chang
  79. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  80. ** New feature to remove all sta records by BssIndex
  81. **
  82. ** 01 17 2013 cm.chang
  83. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  84. ** Use ucBssIndex to replace eNetworkTypeIndex
  85. **
  86. ** 09 17 2012 cm.chang
  87. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  88. ** Duplicate source from MT6620 v2.3 driver branch
  89. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  90. *
  91. * 07 17 2012 yuche.tsai
  92. * NULL
  93. * Compile no error before trial run.
  94. *
  95. * 03 14 2012 wh.su
  96. * [WCXRP00001173] [MT6620 Wi-Fi][Driver] Adding the ICS Tethering WPA2-PSK supporting
  97. * Add code from 2.2
  98. *
  99. * 11 17 2011 tsaiyuan.hsu
  100. * [WCXRP00001115] [MT6620 Wi-Fi][DRV] avoid deactivating staRec when changing state 3 to 3.
  101. * initialize fgNeedResp.
  102. *
  103. * 11 17 2011 tsaiyuan.hsu
  104. * [WCXRP00001115] [MT6620 Wi-Fi][DRV] avoid deactivating staRec when changing state 3 to 3.
  105. * avoid deactivating staRec when changing state from 3 to 3.
  106. *
  107. * 02 01 2011 cm.chang
  108. * [WCXRP00000415] [MT6620 Wi-Fi][Driver] Check if any memory leakage happens when uninitializing in DGB mode
  109. * .
  110. *
  111. * 01 26 2011 cm.chang
  112. * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
  113. * Allocate system RAM if fixed message or mgmt buffer is not available
  114. *
  115. * 01 26 2011 cm.chang
  116. * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
  117. * .
  118. *
  119. * 01 25 2011 yuche.tsai
  120. * [WCXRP00000388] [Volunteer Patch][MT6620][Driver/Fw] change Station Type in station record.
  121. * Change Station Type in Station Record, Modify MACRO definition for getting station type & network type index & Role.
  122. *
  123. * 12 13 2010 cp.wu
  124. * [WCXRP00000260] [MT6620 Wi-Fi][Driver][Firmware] Create V1.1 branch for both firmware and driver
  125. * create branch for Wi-Fi driver v1.1
  126. *
  127. * 12 07 2010 cm.chang
  128. * [WCXRP00000239] MT6620 Wi-Fi][Driver][FW] Merge concurrent branch back to maintrunk
  129. * 1. BSSINFO include RLM parameter
  130. * 2. free all sta records when network is disconnected
  131. *
  132. * 11 29 2010 cm.chang
  133. * [WCXRP00000210] [MT6620 Wi-Fi][Driver][FW] Set RCPI value in STA_REC
  134. * for initial TX rate selection of auto-rate algorithm
  135. * Sync RCPI of STA_REC to FW as reference of initial TX rate
  136. *
  137. * 11 25 2010 yuche.tsai
  138. * NULL
  139. * Update SLT Function for QoS Support and not be affected by fixed rate function.
  140. *
  141. * 10 18 2010 cp.wu
  142. * [WCXRP00000053] [MT6620 Wi-Fi][Driver] Reset incomplete
  143. * and might leads to BSOD when entering RF test with AIS associated
  144. * 1. remove redundant variables in STA_REC structure
  145. * 2. add STA-REC uninitialization routine for clearing pending events
  146. *
  147. * 10 13 2010 cm.chang
  148. * [WCXRP00000094] [MT6620 Wi-Fi][Driver] Connect to 2.4GHz AP, Driver crash.
  149. * Add exception handle when cmd buffer is not available
  150. *
  151. * 10 12 2010 cp.wu
  152. * [WCXRP00000084] [MT6620 Wi-Fi][Driver][FW] Add fixed rate support for distance test
  153. * add HT (802.11n) fixed rate support.
  154. *
  155. * 10 08 2010 cp.wu
  156. * [WCXRP00000084] [MT6620 Wi-Fi][Driver][FW] Add fixed rate support for distance test
  157. * adding fixed rate support for distance test. (from registry setting)
  158. *
  159. * 09 24 2010 wh.su
  160. * NULL
  161. * [WCXRP00005002][MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning.
  162. *
  163. * 09 21 2010 cp.wu
  164. * [WCXRP00000053] [MT6620 Wi-Fi][Driver] Reset incomplete and might leads to BSOD
  165. * when entering RF test with AIS associated
  166. * Do a complete reset with STA-REC null checking for RF test re-entry
  167. *
  168. * 09 16 2010 cm.chang
  169. * NULL
  170. * Change conditional compiling options for BOW
  171. *
  172. * 09 10 2010 cm.chang
  173. * NULL
  174. * Always update Beacon content if FW sync OBSS info
  175. *
  176. * 08 24 2010 cm.chang
  177. * NULL
  178. * Support RLM initail channel of Ad-hoc, P2P and BOW
  179. *
  180. * 08 23 2010 chinghwa.yu
  181. * NULL
  182. * Update for BOW.
  183. *
  184. * 08 20 2010 cm.chang
  185. * NULL
  186. * Migrate RLM code to host from FW
  187. *
  188. * 08 19 2010 wh.su
  189. * NULL
  190. * adding the tx pkt call back handle for countermeasure.
  191. *
  192. * 07 08 2010 cp.wu
  193. *
  194. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  195. *
  196. * 07 08 2010 cm.chang
  197. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  198. * Check draft RLM code for HT cap
  199. *
  200. * 07 07 2010 cm.chang
  201. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  202. * Support state of STA record change from 1 to 1
  203. *
  204. * 07 05 2010 cm.chang
  205. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  206. * Fix correct structure size in cnmStaSendDeactivateCmd()
  207. *
  208. * 07 05 2010 cp.wu
  209. * [WPD00003833][MT6620 and MT5931] Driver migration
  210. * 1) ignore RSN checking when RSN is not turned on.
  211. * 2) set STA-REC deactivation callback as NULL
  212. * 3) add variable initialization API based on PHY configuration
  213. *
  214. * 07 02 2010 cp.wu
  215. * [WPD00003833][MT6620 and MT5931] Driver migration
  216. * spin lock target revised
  217. *
  218. * 07 02 2010 cp.wu
  219. * [WPD00003833][MT6620 and MT5931] Driver migration
  220. * change inner loop index from i to k.
  221. *
  222. * 07 01 2010 cm.chang
  223. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  224. * Support sync command of STA_REC
  225. *
  226. * 06 23 2010 yarco.yang
  227. * [WPD00003837][MT6620]Data Path Refine
  228. * Merge g_arStaRec[] into adapter->arStaRec[]
  229. *
  230. * 06 18 2010 cm.chang
  231. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  232. * Provide cnmMgtPktAlloc() and alloc/free function of msg/buf
  233. *
  234. * 05 31 2010 yarco.yang
  235. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  236. * Add RX TSF Log Feature and ADDBA Rsp with DECLINE handling
  237. *
  238. * 05 28 2010 cm.chang
  239. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  240. * Support checking of duplicated buffer free
  241. *
  242. * 05 28 2010 wh.su
  243. * [BORA00000626][MT6620] Refine the remove key flow for WHQL testing
  244. * fixed the ad-hoc wpa-none send non-encrypted frame issue.
  245. *
  246. * 05 28 2010 kevin.huang
  247. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  248. * Move define of STA_REC_NUM to config.h and rename to CFG_STA_REC_NUM
  249. *
  250. * 05 12 2010 kevin.huang
  251. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  252. * Add Power Management - Legacy PS-POLL support.
  253. *
  254. * 04 28 2010 tehuang.liu
  255. * [BORA00000605][WIFISYS] Phase3 Integration
  256. * Modified some MQM-related data structures (SN counter, TX/RX BA table)
  257. *
  258. * 04 27 2010 tehuang.liu
  259. * [BORA00000605][WIFISYS] Phase3 Integration
  260. * Added new TX/RX BA tables in STA_REC
  261. *
  262. * 04 27 2010 tehuang.liu
  263. * [BORA00000605][WIFISYS] Phase3 Integration
  264. * Notify MQM, TXM, and RXM upon disconnection .
  265. *
  266. * 04 26 2010 tehuang.liu
  267. * [BORA00000605][WIFISYS] Phase3 Integration
  268. * Call mqm, txm, rxm functions upon disconnection
  269. *
  270. * 04 24 2010 cm.chang
  271. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  272. * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
  273. *
  274. * 04 22 2010 cm.chang
  275. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  276. * First draft code to support protection in AP mode
  277. *
  278. * 04 19 2010 kevin.huang
  279. * [BORA00000714][WIFISYS][New Feature]Beacon Timeout Support
  280. * Add Beacon Timeout Support
  281. * * * * * * * * * * and will send Null frame to diagnose connection
  282. *
  283. * 04 09 2010 tehuang.liu
  284. * [BORA00000605][WIFISYS] Phase3 Integration
  285. * [BORA00000644] WiFi phase 4 integration
  286. * * Added per-TID SN cache in STA_REC
  287. *
  288. * 04 07 2010 cm.chang
  289. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  290. * Different invoking order for WTBL entry of associated AP
  291. *
  292. * 03 29 2010 wh.su
  293. * [BORA00000605][WIFISYS] Phase3 Integration
  294. * move the wlan table alloc / free to change state function.
  295. *
  296. * 03 24 2010 cm.chang
  297. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  298. * Support power control
  299. *
  300. * 03 03 2010 tehuang.liu
  301. * [BORA00000569][WIFISYS] Phase 2 Integration Test
  302. * Initialize StaRec->arStaWaitQueue
  303. *
  304. * 03 03 2010 cm.chang
  305. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  306. * Add debug message when no available pkt buffer
  307. *
  308. * 03 01 2010 tehuang.liu
  309. * [BORA00000569][WIFISYS] Phase 2 Integration Test
  310. * Fixed STA_REC initialization bug: prStaRec->au2CachedSeqCtrl[k]
  311. *
  312. * 02 26 2010 tehuang.liu
  313. * [BORA00000569][WIFISYS] Phase 2 Integration Test
  314. * Added fgIsWmmSupported in STA_RECORD_T.
  315. *
  316. * 02 26 2010 tehuang.liu
  317. * [BORA00000569][WIFISYS] Phase 2 Integration Test
  318. * Added fgIsUapsdSupported in STA_RECORD_T
  319. *
  320. * 02 26 2010 kevin.huang
  321. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  322. * add support of Driver STA_RECORD_T activation
  323. *
  324. * 02 13 2010 tehuang.liu
  325. * [BORA00000569][WIFISYS] Phase 2 Integration Test
  326. * Added arTspecTable in STA_REC for TSPEC management
  327. *
  328. * 02 12 2010 cm.chang
  329. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  330. * Enable mgmt buffer debug by default
  331. *
  332. * 02 12 2010 tehuang.liu
  333. * [BORA00000569][WIFISYS] Phase 2 Integration Test
  334. * Added BUFFER_SOURCE_BCN
  335. *
  336. * 02 04 2010 kevin.huang
  337. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  338. * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
  339. *
  340. * 01 11 2010 kevin.huang
  341. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  342. * Add Deauth and Disassoc Handler
  343. *
  344. * 01 08 2010 cp.wu
  345. * [BORA00000368]Integrate HIF part into BORA
  346. * 1) separate wifi_var_emu.c/.h from wifi_var.c/.h
  347. * * * * * * * * * 2) eliminate HIF_EMULATION code sections appeared in wifi_var/cnm_mem
  348. * * * * * * * * * 3) use cnmMemAlloc() instead to allocate SRAM buffer
  349. *
  350. * 12 25 2009 tehuang.liu
  351. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  352. * Integrated modifications for 1st connection (mainly on FW modules MQM, TXM, and RXM)
  353. * * * * * * * MQM: BA handling
  354. * * * * * * * TXM: Macros updates
  355. * * * * * * * RXM: Macros/Duplicate Removal updates
  356. *
  357. * 12 24 2009 yarco.yang
  358. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  359. * .
  360. *
  361. * 12 21 2009 cm.chang
  362. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  363. * Support several data buffer banks.
  364. *
  365. * 12 18 2009 cm.chang
  366. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  367. * .For new FPGA memory size
  368. *
  369. * Dec 9 2009 MTK02468
  370. * [BORA00000337] To check in codes for FPGA emulation
  371. * Removed DBGPRINT
  372. *
  373. * Dec 9 2009 mtk02752
  374. * [BORA00000368] Integrate HIF part into BORA
  375. * add cnmDataPktFree() for emulation loopback purpose
  376. *
  377. * Dec 3 2009 mtk01461
  378. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  379. * Fix warning of null pointer
  380. *
  381. * Dec 3 2009 mtk01461
  382. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  383. * Add cnmGetStaRecByAddress() and add fgIsInUse flag in STA_RECORD_T
  384. *
  385. * Nov 23 2009 mtk01104
  386. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  387. * Assign ucBufferSource in function cnmMgtPktAlloc()
  388. *
  389. * Nov 23 2009 mtk02468
  390. * [BORA00000337] To check in codes for FPGA emulation
  391. * Added packet redispatch function calls
  392. *
  393. * Nov 13 2009 mtk01084
  394. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  395. * enable packet re-usable in current emulation driver
  396. *
  397. * Nov 12 2009 mtk01104
  398. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  399. * 1. Add new function cnmGetStaRecByIndex()
  400. * 2. Rename STA_REC_T to STA_RECORD_T
  401. *
  402. * Nov 9 2009 mtk01104
  403. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  404. * Call cnmDataPktDispatch() in cnmPktFree()
  405. *
  406. * Nov 2 2009 mtk01104
  407. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  408. * Remove definition of pragma section code
  409. *
  410. * Oct 28 2009 mtk01104
  411. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  412. *
  413. *
  414. * Oct 23 2009 mtk01461
  415. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  416. * Fix lint warning
  417. *
  418. * Oct 23 2009 mtk01461
  419. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  420. * Fix typo
  421. *
  422. * Oct 12 2009 mtk01104
  423. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  424. *
  425. *
  426. * Oct 8 2009 mtk01104
  427. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  428. *
  429. **
  430. */
  431. /*******************************************************************************
  432. * C O M P I L E R F L A G S
  433. ********************************************************************************
  434. */
  435. /*******************************************************************************
  436. * E X T E R N A L R E F E R E N C E S
  437. ********************************************************************************
  438. */
  439. #include "precomp.h"
  440. /*******************************************************************************
  441. * C O N S T A N T S
  442. ********************************************************************************
  443. */
  444. /*******************************************************************************
  445. * D A T A T Y P E S
  446. ********************************************************************************
  447. */
  448. /*******************************************************************************
  449. * P U B L I C D A T A
  450. ********************************************************************************
  451. */
  452. /*******************************************************************************
  453. * P R I V A T E D A T A
  454. ********************************************************************************
  455. */
  456. static PUINT_8 apucStaRecType[STA_TYPE_INDEX_NUM] = {
  457. (PUINT_8) "LEGACY",
  458. (PUINT_8) "P2P",
  459. (PUINT_8) "BOW"
  460. };
  461. static PUINT_8 apucStaRecRole[STA_ROLE_INDEX_NUM] = {
  462. (PUINT_8) "ADHOC",
  463. (PUINT_8) "CLIENT",
  464. (PUINT_8) "AP",
  465. (PUINT_8) "DLS"
  466. };
  467. #if CFG_SUPPORT_TDLS
  468. /* The list of valid data rates. */
  469. const UINT_8 aucValidDataRate[] = {
  470. RATE_1M, /* RATE_1M_INDEX = 0 */
  471. RATE_2M, /* RATE_2M_INDEX */
  472. RATE_5_5M, /* RATE_5_5M_INDEX */
  473. RATE_11M, /* RATE_11M_INDEX */
  474. RATE_22M, /* RATE_22M_INDEX */
  475. RATE_33M, /* RATE_33M_INDEX */
  476. RATE_6M, /* RATE_6M_INDEX */
  477. RATE_9M, /* RATE_9M_INDEX */
  478. RATE_12M, /* RATE_12M_INDEX */
  479. RATE_18M, /* RATE_18M_INDEX */
  480. RATE_24M, /* RATE_24M_INDEX */
  481. RATE_36M, /* RATE_36M_INDEX */
  482. RATE_48M, /* RATE_48M_INDEX */
  483. RATE_54M, /* RATE_54M_INDEX */
  484. RATE_VHT_PHY, /* RATE_VHT_PHY_INDEX */
  485. RATE_HT_PHY /* RATE_HT_PHY_INDEX */
  486. };
  487. #endif
  488. /*******************************************************************************
  489. * M A C R O S
  490. ********************************************************************************
  491. */
  492. /*******************************************************************************
  493. * F U N C T I O N D E C L A R A T I O N S
  494. ********************************************************************************
  495. */
  496. static VOID cnmStaRoutinesForAbort(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec);
  497. static VOID cnmStaRecHandleEventPkt(P_ADAPTER_T prAdapter, P_CMD_INFO_T prCmdInfo, PUINT_8 pucEventBuf);
  498. static VOID cnmStaSendUpdateCmd(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec, BOOLEAN fgNeedResp);
  499. static VOID
  500. cnmStaSendRemoveCmd(P_ADAPTER_T prAdapter,
  501. ENUM_STA_REC_CMD_ACTION_T eActionType, UINT_8 ucStaRecIndex, UINT_8 ucBssIndex);
  502. /*******************************************************************************
  503. * F U N C T I O N S
  504. ********************************************************************************
  505. */
  506. /*----------------------------------------------------------------------------*/
  507. /*!
  508. * \brief
  509. *
  510. * \param[in]
  511. *
  512. * \return none
  513. */
  514. /*----------------------------------------------------------------------------*/
  515. P_MSDU_INFO_T cnmPktAllocWrapper(P_ADAPTER_T prAdapter, UINT_32 u4Length, PUINT_8 pucStr)
  516. {
  517. P_MSDU_INFO_T prMsduInfo;
  518. prMsduInfo = cnmPktAlloc(prAdapter, u4Length);
  519. DBGLOG(MEM, LOUD, "Alloc MSDU_INFO[0x%p] by [%s]\n", prMsduInfo, pucStr);
  520. return prMsduInfo;
  521. }
  522. /*----------------------------------------------------------------------------*/
  523. /*!
  524. * \brief
  525. *
  526. * \param[in]
  527. *
  528. * \return none
  529. */
  530. /*----------------------------------------------------------------------------*/
  531. VOID cnmPktFreeWrapper(P_ADAPTER_T prAdapter, P_MSDU_INFO_T prMsduInfo, PUINT_8 pucStr)
  532. {
  533. DBGLOG(MEM, LOUD, "Free MSDU_INFO[0x%p] by [%s]\n", prMsduInfo, pucStr);
  534. cnmPktFree(prAdapter, prMsduInfo);
  535. }
  536. /*----------------------------------------------------------------------------*/
  537. /*!
  538. * \brief
  539. *
  540. * \param[in]
  541. *
  542. * \return none
  543. */
  544. /*----------------------------------------------------------------------------*/
  545. P_MSDU_INFO_T cnmPktAlloc(P_ADAPTER_T prAdapter, UINT_32 u4Length)
  546. {
  547. P_MSDU_INFO_T prMsduInfo;
  548. P_QUE_T prQueList;
  549. KAL_SPIN_LOCK_DECLARATION();
  550. ASSERT(prAdapter);
  551. prQueList = &prAdapter->rTxCtrl.rFreeMsduInfoList;
  552. /* Get a free MSDU_INFO_T */
  553. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  554. QUEUE_REMOVE_HEAD(prQueList, prMsduInfo, P_MSDU_INFO_T);
  555. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  556. if (prMsduInfo) {
  557. if (u4Length) {
  558. prMsduInfo->prPacket = cnmMemAlloc(prAdapter, RAM_TYPE_BUF, u4Length);
  559. prMsduInfo->eSrc = TX_PACKET_MGMT;
  560. if (prMsduInfo->prPacket == NULL) {
  561. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  562. QUEUE_INSERT_TAIL(prQueList, &prMsduInfo->rQueEntry);
  563. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  564. prMsduInfo = NULL;
  565. }
  566. } else {
  567. prMsduInfo->prPacket = NULL;
  568. }
  569. }
  570. #if DBG
  571. if (prMsduInfo == NULL) {
  572. DBGLOG(MEM, TRACE, "MgtDesc#=%ld\n", prQueList->u4NumElem);
  573. #if CFG_DBG_MGT_BUF
  574. DBGLOG(MEM, TRACE, "rMgtBufInfo: alloc#=%ld, free#=%ld, null#=%ld\n",
  575. prAdapter->rMgtBufInfo.u4AllocCount,
  576. prAdapter->rMgtBufInfo.u4FreeCount, prAdapter->rMgtBufInfo.u4AllocNullCount);
  577. #endif
  578. }
  579. #endif
  580. return prMsduInfo;
  581. }
  582. /*----------------------------------------------------------------------------*/
  583. /*!
  584. * \brief
  585. *
  586. * \param[in]
  587. *
  588. * \return none
  589. */
  590. /*----------------------------------------------------------------------------*/
  591. VOID cnmPktFree(P_ADAPTER_T prAdapter, P_MSDU_INFO_T prMsduInfo)
  592. {
  593. P_QUE_T prQueList;
  594. KAL_SPIN_LOCK_DECLARATION();
  595. ASSERT(prAdapter);
  596. if (!prMsduInfo)
  597. return;
  598. prQueList = &prAdapter->rTxCtrl.rFreeMsduInfoList;
  599. /* ASSERT(prMsduInfo->prPacket); */
  600. if (prMsduInfo->prPacket) {
  601. cnmMemFree(prAdapter, prMsduInfo->prPacket);
  602. prMsduInfo->prPacket = NULL;
  603. }
  604. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  605. QUEUE_INSERT_TAIL(prQueList, &prMsduInfo->rQueEntry);
  606. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  607. }
  608. /*----------------------------------------------------------------------------*/
  609. /*!
  610. * \brief This function is used to initial the MGMT/MSG memory pool.
  611. *
  612. * \param (none)
  613. *
  614. * \return (none)
  615. */
  616. /*----------------------------------------------------------------------------*/
  617. VOID cnmMemInit(P_ADAPTER_T prAdapter)
  618. {
  619. P_BUF_INFO_T prBufInfo;
  620. /* Initialize Management buffer pool */
  621. prBufInfo = &prAdapter->rMgtBufInfo;
  622. kalMemZero(prBufInfo, sizeof(prAdapter->rMgtBufInfo));
  623. prBufInfo->pucBuf = prAdapter->pucMgtBufCached;
  624. /* Setup available memory blocks. 1 indicates FREE */
  625. prBufInfo->rFreeBlocksBitmap = (BUF_BITMAP) BITS(0, MAX_NUM_OF_BUF_BLOCKS - 1);
  626. /* Initialize Message buffer pool */
  627. prBufInfo = &prAdapter->rMsgBufInfo;
  628. kalMemZero(prBufInfo, sizeof(prAdapter->rMsgBufInfo));
  629. prBufInfo->pucBuf = &prAdapter->aucMsgBuf[0];
  630. /* Setup available memory blocks. 1 indicates FREE */
  631. prBufInfo->rFreeBlocksBitmap = (BUF_BITMAP) BITS(0, MAX_NUM_OF_BUF_BLOCKS - 1);
  632. } /* end of cnmMemInit() */
  633. /*----------------------------------------------------------------------------*/
  634. /*!
  635. * \brief Allocate MGMT/MSG memory pool.
  636. *
  637. * \param[in] eRamType Target RAM type.
  638. * TCM blk_sz= 16bytes, BUF blk_sz= 256bytes
  639. * \param[in] u4Length Length of the buffer to allocate.
  640. *
  641. * \retval !NULL Pointer to the start address of allocated memory.
  642. * \retval NULL Fail to allocat memory
  643. */
  644. /*----------------------------------------------------------------------------*/
  645. PVOID cnmMemAlloc(IN P_ADAPTER_T prAdapter, IN ENUM_RAM_TYPE_T eRamType, IN UINT_32 u4Length)
  646. {
  647. P_BUF_INFO_T prBufInfo;
  648. BUF_BITMAP rRequiredBitmap;
  649. UINT_32 u4BlockNum;
  650. UINT_32 i, u4BlkSzInPower;
  651. PVOID pvMemory;
  652. KAL_SPIN_LOCK_DECLARATION();
  653. ASSERT(prAdapter);
  654. if (u4Length == 0) {
  655. DBGLOG(MEM, WARN, "%s: Length to be allocated is ZERO, skip!\n", __func__);
  656. return NULL;
  657. }
  658. if (eRamType == RAM_TYPE_MSG && u4Length <= 256) {
  659. prBufInfo = &prAdapter->rMsgBufInfo;
  660. u4BlkSzInPower = MSG_BUF_BLOCK_SIZE_IN_POWER_OF_2;
  661. u4BlockNum = (u4Length + MSG_BUF_BLOCK_SIZE - 1)
  662. >> MSG_BUF_BLOCK_SIZE_IN_POWER_OF_2;
  663. ASSERT(u4BlockNum <= MAX_NUM_OF_BUF_BLOCKS);
  664. } else {
  665. eRamType = RAM_TYPE_BUF;
  666. prBufInfo = &prAdapter->rMgtBufInfo;
  667. u4BlkSzInPower = MGT_BUF_BLOCK_SIZE_IN_POWER_OF_2;
  668. u4BlockNum = (u4Length + MGT_BUF_BLOCK_SIZE - 1)
  669. >> MGT_BUF_BLOCK_SIZE_IN_POWER_OF_2;
  670. ASSERT(u4BlockNum <= MAX_NUM_OF_BUF_BLOCKS);
  671. }
  672. #if CFG_DBG_MGT_BUF
  673. prBufInfo->u4AllocCount++;
  674. #endif
  675. KAL_ACQUIRE_SPIN_LOCK(prAdapter, eRamType == RAM_TYPE_MSG ? SPIN_LOCK_MSG_BUF : SPIN_LOCK_MGT_BUF);
  676. if ((u4BlockNum > 0) && (u4BlockNum <= MAX_NUM_OF_BUF_BLOCKS)) {
  677. /* Convert number of block into bit cluster */
  678. rRequiredBitmap = BITS(0, u4BlockNum - 1);
  679. for (i = 0; i <= (MAX_NUM_OF_BUF_BLOCKS - u4BlockNum); i++) {
  680. /* Have available memory blocks */
  681. if ((prBufInfo->rFreeBlocksBitmap & rRequiredBitmap)
  682. == rRequiredBitmap) {
  683. /* Clear corresponding bits of allocated memory blocks */
  684. prBufInfo->rFreeBlocksBitmap &= ~rRequiredBitmap;
  685. /* Store how many blocks be allocated */
  686. prBufInfo->aucAllocatedBlockNum[i] = (UINT_8) u4BlockNum;
  687. KAL_RELEASE_SPIN_LOCK(prAdapter,
  688. eRamType == RAM_TYPE_MSG ? SPIN_LOCK_MSG_BUF : SPIN_LOCK_MGT_BUF);
  689. /* Return the start address of allocated memory */
  690. return (PVOID) (prBufInfo->pucBuf + (i << u4BlkSzInPower));
  691. }
  692. rRequiredBitmap <<= 1;
  693. }
  694. }
  695. /* kalMemAlloc() shall not included in spin_lock */
  696. KAL_RELEASE_SPIN_LOCK(prAdapter, eRamType == RAM_TYPE_MSG ? SPIN_LOCK_MSG_BUF : SPIN_LOCK_MGT_BUF);
  697. #ifdef LINUX
  698. pvMemory = (PVOID) kalMemAlloc(u4Length, PHY_MEM_TYPE);
  699. if (pvMemory)
  700. kalMemZero(pvMemory, u4Length);
  701. #else
  702. pvMemory = (PVOID) NULL;
  703. #endif
  704. #if CFG_DBG_MGT_BUF
  705. prBufInfo->u4AllocNullCount++;
  706. if (pvMemory)
  707. prAdapter->u4MemAllocDynamicCount++;
  708. #endif
  709. return pvMemory;
  710. } /* end of cnmMemAlloc() */
  711. /*----------------------------------------------------------------------------*/
  712. /*!
  713. * \brief Release memory to MGT/MSG memory pool.
  714. *
  715. * \param pucMemory Start address of previous allocated memory
  716. *
  717. * \return (none)
  718. */
  719. /*----------------------------------------------------------------------------*/
  720. VOID cnmMemFree(IN P_ADAPTER_T prAdapter, IN PVOID pvMemory)
  721. {
  722. P_BUF_INFO_T prBufInfo;
  723. UINT_32 u4BlockIndex;
  724. BUF_BITMAP rAllocatedBlocksBitmap;
  725. ENUM_RAM_TYPE_T eRamType;
  726. KAL_SPIN_LOCK_DECLARATION();
  727. ASSERT(prAdapter);
  728. if (!pvMemory)
  729. return;
  730. /* Judge it belongs to which RAM type */
  731. if (((ULONG) pvMemory >= (ULONG)&prAdapter->aucMsgBuf[0]) &&
  732. ((ULONG) pvMemory <= (ULONG)&prAdapter->aucMsgBuf[MSG_BUFFER_SIZE - 1])) {
  733. prBufInfo = &prAdapter->rMsgBufInfo;
  734. u4BlockIndex = ((ULONG) pvMemory - (ULONG) prBufInfo->pucBuf)
  735. >> MSG_BUF_BLOCK_SIZE_IN_POWER_OF_2;
  736. ASSERT(u4BlockIndex < MAX_NUM_OF_BUF_BLOCKS);
  737. eRamType = RAM_TYPE_MSG;
  738. } else if (((ULONG) pvMemory >= (ULONG) prAdapter->pucMgtBufCached) &&
  739. ((ULONG) pvMemory <= ((ULONG) prAdapter->pucMgtBufCached + MGT_BUFFER_SIZE - 1))) {
  740. prBufInfo = &prAdapter->rMgtBufInfo;
  741. u4BlockIndex = ((ULONG) pvMemory - (ULONG) prBufInfo->pucBuf)
  742. >> MGT_BUF_BLOCK_SIZE_IN_POWER_OF_2;
  743. ASSERT(u4BlockIndex < MAX_NUM_OF_BUF_BLOCKS);
  744. eRamType = RAM_TYPE_BUF;
  745. } else {
  746. #ifdef LINUX
  747. /* For Linux, it is supported because size is not needed */
  748. kalMemFree(pvMemory, PHY_MEM_TYPE, 0);
  749. #else
  750. /* For Windows, it is not supported because of no size argument */
  751. ASSERT(0);
  752. #endif
  753. #if CFG_DBG_MGT_BUF
  754. prAdapter->u4MemFreeDynamicCount++;
  755. #endif
  756. return;
  757. }
  758. KAL_ACQUIRE_SPIN_LOCK(prAdapter, eRamType == RAM_TYPE_MSG ? SPIN_LOCK_MSG_BUF : SPIN_LOCK_MGT_BUF);
  759. #if CFG_DBG_MGT_BUF
  760. prBufInfo->u4FreeCount++;
  761. #endif
  762. /* Convert number of block into bit cluster */
  763. ASSERT(prBufInfo->aucAllocatedBlockNum[u4BlockIndex] > 0);
  764. rAllocatedBlocksBitmap = BITS(0, prBufInfo->aucAllocatedBlockNum[u4BlockIndex] - 1);
  765. rAllocatedBlocksBitmap <<= u4BlockIndex;
  766. /* Clear saved block count for this memory segment */
  767. prBufInfo->aucAllocatedBlockNum[u4BlockIndex] = 0;
  768. /* Set corresponding bit of released memory block */
  769. prBufInfo->rFreeBlocksBitmap |= rAllocatedBlocksBitmap;
  770. KAL_RELEASE_SPIN_LOCK(prAdapter, eRamType == RAM_TYPE_MSG ? SPIN_LOCK_MSG_BUF : SPIN_LOCK_MGT_BUF);
  771. return;
  772. } /* end of cnmMemFree() */
  773. /*----------------------------------------------------------------------------*/
  774. /*!
  775. * \brief
  776. *
  777. * \param[in]
  778. *
  779. * \return none
  780. */
  781. /*----------------------------------------------------------------------------*/
  782. VOID cnmStaRecInit(P_ADAPTER_T prAdapter)
  783. {
  784. P_STA_RECORD_T prStaRec;
  785. UINT_16 i;
  786. for (i = 0; i < CFG_STA_REC_NUM; i++) {
  787. prStaRec = &prAdapter->arStaRec[i];
  788. prStaRec->ucIndex = (UINT_8) i;
  789. prStaRec->fgIsInUse = FALSE;
  790. }
  791. }
  792. /*----------------------------------------------------------------------------*/
  793. /*!
  794. * \brief
  795. *
  796. * \param[in]
  797. *
  798. * \return none
  799. */
  800. /*----------------------------------------------------------------------------*/
  801. P_STA_RECORD_T cnmStaRecAlloc(P_ADAPTER_T prAdapter, ENUM_STA_TYPE_T eStaType, UINT_8 ucBssIndex, PUINT_8 pucMacAddr)
  802. {
  803. P_STA_RECORD_T prStaRec;
  804. UINT_16 i, k;
  805. ASSERT(prAdapter);
  806. for (i = 0; i < CFG_STA_REC_NUM; i++) {
  807. prStaRec = &prAdapter->arStaRec[i];
  808. if (!prStaRec->fgIsInUse) {
  809. kalMemZero(prStaRec, sizeof(STA_RECORD_T));
  810. prStaRec->ucIndex = (UINT_8) i;
  811. prStaRec->ucBssIndex = ucBssIndex;
  812. prStaRec->fgIsInUse = TRUE;
  813. prStaRec->eStaType = eStaType;
  814. prStaRec->ucBssIndex = ucBssIndex;
  815. prStaRec->ucCurrentGtkId = 255;
  816. /* Initialize the SN caches for duplicate detection */
  817. for (k = 0; k < TID_NUM + 1; k++) {
  818. prStaRec->au2CachedSeqCtrl[k] = 0xFFFF;
  819. prStaRec->afgIsIgnoreAmsduDuplicate[k] = FALSE;
  820. }
  821. /* Initialize SW TX queues in STA_REC */
  822. for (k = 0; k < STA_WAIT_QUEUE_NUM; k++)
  823. LINK_INITIALIZE(&prStaRec->arStaWaitQueue[k]);
  824. #if CFG_ENABLE_PER_STA_STATISTICS && CFG_ENABLE_PKT_LIFETIME_PROFILE
  825. prStaRec->u4TotalTxPktsNumber = 0;
  826. prStaRec->u4TotalTxPktsTime = 0;
  827. prStaRec->u4TotalRxPktsNumber = 0;
  828. prStaRec->u4MaxTxPktsTime = 0;
  829. #endif
  830. for (k = 0; k < NUM_OF_PER_STA_TX_QUEUES; k++)
  831. QUEUE_INITIALIZE(&prStaRec->arTxQueue[k]);
  832. break;
  833. }
  834. }
  835. /* Sync to chip to allocate WTBL resource */
  836. if (i < CFG_STA_REC_NUM) {
  837. COPY_MAC_ADDR(prStaRec->aucMacAddr, pucMacAddr);
  838. prStaRec->ucBMCWlanIndex = WTBL_RESERVED_ENTRY;
  839. if (secPrivacySeekForEntry(prAdapter, prStaRec))
  840. cnmStaSendUpdateCmd(prAdapter, prStaRec, FALSE);
  841. #if DBG
  842. else {
  843. prStaRec->fgIsInUse = FALSE;
  844. prStaRec = NULL;
  845. ASSERT(FALSE);
  846. }
  847. #endif
  848. } else {
  849. prStaRec = NULL;
  850. }
  851. return prStaRec;
  852. }
  853. /*----------------------------------------------------------------------------*/
  854. /*!
  855. * \brief
  856. *
  857. * \param[in]
  858. *
  859. * \return none
  860. */
  861. /*----------------------------------------------------------------------------*/
  862. VOID cnmStaRecFree(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec)
  863. {
  864. UINT_8 ucStaRecIndex, ucBssIndex;
  865. ASSERT(prAdapter);
  866. if (!prStaRec)
  867. return;
  868. ucStaRecIndex = prStaRec->ucIndex;
  869. ucBssIndex = prStaRec->ucBssIndex;
  870. cnmStaRoutinesForAbort(prAdapter, prStaRec);
  871. cnmStaSendRemoveCmd(prAdapter, STA_REC_CMD_ACTION_STA, ucStaRecIndex, ucBssIndex);
  872. }
  873. /*----------------------------------------------------------------------------*/
  874. /*!
  875. * \brief
  876. *
  877. * \param[in]
  878. *
  879. * \return none
  880. */
  881. /*----------------------------------------------------------------------------*/
  882. static VOID cnmStaRoutinesForAbort(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec)
  883. {
  884. ASSERT(prAdapter);
  885. if (!prStaRec)
  886. return;
  887. /* To do: free related resources, e.g. timers, buffers, etc */
  888. cnmTimerStopTimer(prAdapter, &prStaRec->rTxReqDoneOrRxRespTimer);
  889. prStaRec->fgTransmitKeyExist = FALSE;
  890. prStaRec->ucCurrentGtkId = 0;
  891. prStaRec->fgSetPwrMgtBit = FALSE;
  892. if (prStaRec->pucAssocReqIe) {
  893. kalMemFree(prStaRec->pucAssocReqIe, VIR_MEM_TYPE, prStaRec->u2AssocReqIeLen);
  894. prStaRec->pucAssocReqIe = NULL;
  895. prStaRec->u2AssocReqIeLen = 0;
  896. }
  897. qmDeactivateStaRec(prAdapter, prStaRec);
  898. /* Update the driver part table setting */
  899. secPrivacyFreeSta(prAdapter, prStaRec);
  900. prStaRec->fgIsInUse = FALSE;
  901. }
  902. /*----------------------------------------------------------------------------*/
  903. /*!
  904. * \brief
  905. *
  906. * \param[in]
  907. *
  908. * \return none
  909. */
  910. /*----------------------------------------------------------------------------*/
  911. VOID cnmStaFreeAllStaByNetwork(P_ADAPTER_T prAdapter, UINT_8 ucBssIndex, UINT_8 ucStaRecIndexExcluded)
  912. {
  913. #if CFG_ENABLE_WIFI_DIRECT
  914. P_BSS_INFO_T prBssInfo;
  915. #endif
  916. P_STA_RECORD_T prStaRec;
  917. UINT_16 i;
  918. if (ucBssIndex > MAX_BSS_INDEX)
  919. return;
  920. for (i = 0; i < CFG_STA_REC_NUM; i++) {
  921. prStaRec = (P_STA_RECORD_T) &prAdapter->arStaRec[i];
  922. if (prStaRec->fgIsInUse && prStaRec->ucBssIndex == ucBssIndex && i != ucStaRecIndexExcluded)
  923. cnmStaRoutinesForAbort(prAdapter, prStaRec);
  924. } /* end of for loop */
  925. cnmStaSendRemoveCmd(prAdapter,
  926. (ucStaRecIndexExcluded < CFG_STA_REC_NUM) ?
  927. STA_REC_CMD_ACTION_BSS_EXCLUDE_STA : STA_REC_CMD_ACTION_BSS,
  928. ucStaRecIndexExcluded, ucBssIndex);
  929. #if CFG_ENABLE_WIFI_DIRECT
  930. /* To do: Confirm if it is invoked here or other location, but it should
  931. * be invoked after state sync of STA_REC
  932. * Update system operation parameters for AP mode
  933. */
  934. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, ucBssIndex);
  935. if (prAdapter->fgIsP2PRegistered && prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)
  936. rlmUpdateParamsForAP(prAdapter, prBssInfo, FALSE);
  937. #endif
  938. }
  939. /*----------------------------------------------------------------------------*/
  940. /*!
  941. * \brief
  942. *
  943. * \param[in]
  944. *
  945. * \return none
  946. */
  947. /*----------------------------------------------------------------------------*/
  948. P_STA_RECORD_T cnmGetStaRecByIndex(P_ADAPTER_T prAdapter, UINT_8 ucIndex)
  949. {
  950. P_STA_RECORD_T prStaRec;
  951. ASSERT(prAdapter);
  952. prStaRec = (ucIndex < CFG_STA_REC_NUM) ? &prAdapter->arStaRec[ucIndex] : NULL;
  953. if (prStaRec && prStaRec->fgIsInUse == FALSE)
  954. prStaRec = NULL;
  955. return prStaRec;
  956. }
  957. /*----------------------------------------------------------------------------*/
  958. /*!
  959. * @brief Get STA_RECORD_T by Peer MAC Address(Usually TA).
  960. *
  961. * @param[in] pucPeerMacAddr Given Peer MAC Address.
  962. *
  963. * @retval Pointer to STA_RECORD_T, if found. NULL, if not found
  964. */
  965. /*----------------------------------------------------------------------------*/
  966. P_STA_RECORD_T cnmGetStaRecByAddress(P_ADAPTER_T prAdapter, UINT_8 ucBssIndex, PUINT_8 pucPeerMacAddr)
  967. {
  968. P_STA_RECORD_T prStaRec;
  969. UINT_16 i;
  970. ASSERT(prAdapter);
  971. if (!pucPeerMacAddr)
  972. return NULL;
  973. for (i = 0; i < CFG_STA_REC_NUM; i++) {
  974. prStaRec = &prAdapter->arStaRec[i];
  975. if (prStaRec->fgIsInUse &&
  976. prStaRec->ucBssIndex == ucBssIndex && EQUAL_MAC_ADDR(prStaRec->aucMacAddr, pucPeerMacAddr)) {
  977. break;
  978. }
  979. }
  980. return (i < CFG_STA_REC_NUM) ? prStaRec : NULL;
  981. }
  982. /*----------------------------------------------------------------------------*/
  983. /*!
  984. * @brief This function will change the ucStaState of STA_RECORD_T and also do
  985. * event indication to HOST to sync the STA_RECORD_T in driver.
  986. *
  987. * @param[in] prStaRec Pointer to the STA_RECORD_T
  988. * @param[in] u4NewState New STATE to change.
  989. *
  990. * @return (none)
  991. */
  992. /*----------------------------------------------------------------------------*/
  993. VOID cnmStaRecChangeState(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec, UINT_8 ucNewState)
  994. {
  995. BOOLEAN fgNeedResp;
  996. if (!prAdapter)
  997. return;
  998. if (!prStaRec) {
  999. DBGLOG(MEM, WARN, "%s: StaRec is NULL, skip!\n", __func__);
  1000. return;
  1001. }
  1002. if (!prStaRec->fgIsInUse) {
  1003. DBGLOG(MEM, WARN, "%s: StaRec[%u] is not in use, skip!\n", __func__, prStaRec->ucIndex);
  1004. return;
  1005. }
  1006. /* Do nothing when following state transitions happen,
  1007. * other 6 conditions should be sync to FW, including 1-->1, 3-->3
  1008. */
  1009. if ((ucNewState == STA_STATE_2 && prStaRec->ucStaState != STA_STATE_3) ||
  1010. (ucNewState == STA_STATE_1 && prStaRec->ucStaState == STA_STATE_2)) {
  1011. prStaRec->ucStaState = ucNewState;
  1012. return;
  1013. }
  1014. fgNeedResp = FALSE;
  1015. if (ucNewState == STA_STATE_3) {
  1016. /* secFsmEventStart(prAdapter, prStaRec); */
  1017. if (ucNewState != prStaRec->ucStaState) {
  1018. fgNeedResp = TRUE;
  1019. cnmDumpStaRec(prAdapter, prStaRec->ucIndex);
  1020. }
  1021. } else {
  1022. if (ucNewState != prStaRec->ucStaState && prStaRec->ucStaState == STA_STATE_3)
  1023. qmDeactivateStaRec(prAdapter, prStaRec);
  1024. fgNeedResp = FALSE;
  1025. }
  1026. prStaRec->ucStaState = ucNewState;
  1027. cnmStaSendUpdateCmd(prAdapter, prStaRec, fgNeedResp);
  1028. #if 1 /* Marked for MT6630 */
  1029. #if CFG_ENABLE_WIFI_DIRECT
  1030. /* To do: Confirm if it is invoked here or other location, but it should
  1031. * be invoked after state sync of STA_REC
  1032. * Update system operation parameters for AP mode
  1033. */
  1034. if (prAdapter->fgIsP2PRegistered && (IS_STA_IN_P2P(prStaRec))) {
  1035. P_BSS_INFO_T prBssInfo;
  1036. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prStaRec->ucBssIndex);
  1037. if (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)
  1038. rlmUpdateParamsForAP(prAdapter, prBssInfo, FALSE);
  1039. }
  1040. #endif
  1041. #endif
  1042. }
  1043. /*----------------------------------------------------------------------------*/
  1044. /*!
  1045. * @brief
  1046. *
  1047. * @param[in]
  1048. *
  1049. * @return (none)
  1050. */
  1051. /*----------------------------------------------------------------------------*/
  1052. static VOID cnmStaRecHandleEventPkt(P_ADAPTER_T prAdapter, P_CMD_INFO_T prCmdInfo, PUINT_8 pucEventBuf)
  1053. {
  1054. P_EVENT_ACTIVATE_STA_REC_T prEventContent;
  1055. P_STA_RECORD_T prStaRec;
  1056. prEventContent = (P_EVENT_ACTIVATE_STA_REC_T) pucEventBuf;
  1057. prStaRec = cnmGetStaRecByIndex(prAdapter, prEventContent->ucStaRecIdx);
  1058. if (prStaRec && prStaRec->ucStaState == STA_STATE_3 &&
  1059. !kalMemCmp(&prStaRec->aucMacAddr[0], &prEventContent->aucMacAddr[0], MAC_ADDR_LEN)) {
  1060. qmActivateStaRec(prAdapter, prStaRec);
  1061. }
  1062. }
  1063. /*----------------------------------------------------------------------------*/
  1064. /*!
  1065. * @brief
  1066. *
  1067. * @param[in]
  1068. *
  1069. * @return (none)
  1070. */
  1071. /*----------------------------------------------------------------------------*/
  1072. static VOID cnmStaSendUpdateCmd(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec, BOOLEAN fgNeedResp)
  1073. {
  1074. P_CMD_UPDATE_STA_RECORD_T prCmdContent;
  1075. WLAN_STATUS rStatus;
  1076. if (!prAdapter)
  1077. return;
  1078. if (!prStaRec) {
  1079. DBGLOG(MEM, WARN, "%s: StaRec is NULL, skip!\n", __func__);
  1080. return;
  1081. }
  1082. if (!prStaRec->fgIsInUse) {
  1083. DBGLOG(MEM, WARN, "%s: StaRec[%u] is not in use, skip!\n", __func__, prStaRec->ucIndex);
  1084. return;
  1085. }
  1086. /* To do: come out a mechanism to limit one STA_REC sync once for AP mode
  1087. * to avoid buffer empty case when many STAs are associated
  1088. * simultaneously.
  1089. */
  1090. /* To do: how to avoid 2 times of allocated memory. Use Stack?
  1091. * One is here, the other is in wlanSendQueryCmd()
  1092. */
  1093. prCmdContent = cnmMemAlloc(prAdapter, RAM_TYPE_BUF, sizeof(CMD_UPDATE_STA_RECORD_T));
  1094. /* To do: exception handle */
  1095. if (!prCmdContent) {
  1096. DBGLOG(MEM, WARN, "%s: CMD_ID_UPDATE_STA_RECORD command allocation failed\n", __func__);
  1097. return;
  1098. }
  1099. /* Reset command buffer */
  1100. kalMemZero(prCmdContent, sizeof(CMD_UPDATE_STA_RECORD_T));
  1101. prCmdContent->ucStaIndex = prStaRec->ucIndex;
  1102. prCmdContent->ucStaType = (UINT_8) prStaRec->eStaType;
  1103. kalMemCopy(&prCmdContent->aucMacAddr[0], &prStaRec->aucMacAddr[0], MAC_ADDR_LEN);
  1104. prCmdContent->u2AssocId = prStaRec->u2AssocId;
  1105. prCmdContent->u2ListenInterval = prStaRec->u2ListenInterval;
  1106. prCmdContent->ucBssIndex = prStaRec->ucBssIndex;
  1107. prCmdContent->ucDesiredPhyTypeSet = prStaRec->ucDesiredPhyTypeSet;
  1108. prCmdContent->u2DesiredNonHTRateSet = prStaRec->u2DesiredNonHTRateSet;
  1109. prCmdContent->u2BSSBasicRateSet = prStaRec->u2BSSBasicRateSet;
  1110. prCmdContent->ucMcsSet = prStaRec->ucMcsSet;
  1111. prCmdContent->ucSupMcs32 = (UINT_8) prStaRec->fgSupMcs32;
  1112. prCmdContent->u2HwDefaultFixedRateCode = prStaRec->u2HwDefaultFixedRateCode;
  1113. kalMemCopy(prCmdContent->aucRxMcsBitmask, prStaRec->aucRxMcsBitmask,
  1114. sizeof(prCmdContent->aucRxMcsBitmask) /*SUP_MCS_RX_BITMASK_OCTET_NUM */);
  1115. prCmdContent->u2RxHighestSupportedRate = prStaRec->u2RxHighestSupportedRate;
  1116. prCmdContent->u4TxRateInfo = prStaRec->u4TxRateInfo;
  1117. prCmdContent->u2HtCapInfo = prStaRec->u2HtCapInfo;
  1118. prCmdContent->ucNeedResp = (UINT_8) fgNeedResp;
  1119. #if !CFG_SLT_SUPPORT
  1120. if (prAdapter->rWifiVar.eRateSetting != FIXED_RATE_NONE) {
  1121. /* override rate configuration */
  1122. nicUpdateRateParams(prAdapter,
  1123. prAdapter->rWifiVar.eRateSetting,
  1124. &(prCmdContent->ucDesiredPhyTypeSet),
  1125. &(prCmdContent->u2DesiredNonHTRateSet),
  1126. &(prCmdContent->u2BSSBasicRateSet),
  1127. &(prCmdContent->ucMcsSet),
  1128. &(prCmdContent->ucSupMcs32), &(prCmdContent->u2HtCapInfo));
  1129. }
  1130. #endif
  1131. prCmdContent->ucIsQoS = prStaRec->fgIsQoS;
  1132. prCmdContent->ucIsUapsdSupported = prStaRec->fgIsUapsdSupported;
  1133. prCmdContent->ucStaState = prStaRec->ucStaState;
  1134. prCmdContent->ucAmpduParam = prStaRec->ucAmpduParam;
  1135. prCmdContent->u2HtExtendedCap = prStaRec->u2HtExtendedCap;
  1136. prCmdContent->u4TxBeamformingCap = prStaRec->u4TxBeamformingCap;
  1137. prCmdContent->ucAselCap = prStaRec->ucAselCap;
  1138. prCmdContent->ucRCPI = prStaRec->ucRCPI;
  1139. prCmdContent->u4VhtCapInfo = prStaRec->u4VhtCapInfo;
  1140. prCmdContent->u2VhtRxMcsMap = prStaRec->u2VhtRxMcsMap;
  1141. prCmdContent->u2VhtRxHighestSupportedDataRate = prStaRec->u2VhtRxHighestSupportedDataRate;
  1142. prCmdContent->u2VhtTxMcsMap = prStaRec->u2VhtTxMcsMap;
  1143. prCmdContent->u2VhtTxHighestSupportedDataRate = prStaRec->u2VhtTxHighestSupportedDataRate;
  1144. prCmdContent->ucUapsdAc = prStaRec->ucBmpTriggerAC | (prStaRec->ucBmpDeliveryAC << 4);
  1145. prCmdContent->ucUapsdSp = prStaRec->ucUapsdSp;
  1146. prCmdContent->ucWlanIndex = prStaRec->ucWlanIndex;
  1147. prCmdContent->ucBMCWlanIndex = prStaRec->ucBMCWlanIndex;
  1148. prCmdContent->ucTrafficDataType = prStaRec->ucTrafficDataType;
  1149. prCmdContent->ucTxGfMode = prStaRec->ucTxGfMode;
  1150. prCmdContent->ucTxSgiMode = prStaRec->ucTxSgiMode;
  1151. prCmdContent->ucTxStbcMode = prStaRec->ucTxStbcMode;
  1152. prCmdContent->u4FixedPhyRate = prStaRec->u4FixedPhyRate;
  1153. prCmdContent->u2MaxLinkSpeed = prStaRec->u2MaxLinkSpeed;
  1154. prCmdContent->u2MinLinkSpeed = prStaRec->u2MinLinkSpeed;
  1155. prCmdContent->u4Flags = prStaRec->u4Flags;
  1156. prCmdContent->ucTxAmpdu = FEATURE_OPT_IN_COMMAND(prAdapter->rWifiVar.ucAmpduTx);
  1157. prCmdContent->ucRxAmpdu = FEATURE_OPT_IN_COMMAND(prAdapter->rWifiVar.ucAmpduRx);
  1158. prCmdContent->ucTxBaSize = prAdapter->rWifiVar.ucTxBaSize;
  1159. if (prStaRec->ucDesiredPhyTypeSet & PHY_TYPE_SET_802_11AC)
  1160. prCmdContent->ucRxBaSize = prAdapter->rWifiVar.ucRxVhtBaSize;
  1161. else
  1162. prCmdContent->ucRxBaSize = prAdapter->rWifiVar.ucRxHtBaSize;
  1163. /* RTS Policy */
  1164. if (IS_FEATURE_ENABLED(prAdapter->rWifiVar.ucSigTaRts)) {
  1165. if (IS_FEATURE_ENABLED(prAdapter->rWifiVar.ucDynBwRts))
  1166. prCmdContent->ucRtsPolicy = RTS_POLICY_DYNAMIC_BW;
  1167. else
  1168. prCmdContent->ucRtsPolicy = RTS_POLICY_STATIC_BW;
  1169. } else
  1170. prCmdContent->ucRtsPolicy = RTS_POLICY_LEGACY;
  1171. DBGLOG(REQ, TRACE, "Update StaRec[%u] WIDX[%u] State[%u] Type[%u] BssIdx[%u] AID[%u]\n",
  1172. prCmdContent->ucStaIndex,
  1173. prCmdContent->ucWlanIndex,
  1174. prCmdContent->ucStaState,
  1175. prCmdContent->ucStaType, prCmdContent->ucBssIndex, prCmdContent->u2AssocId);
  1176. DBGLOG(REQ, TRACE, "Update StaRec[%u] QoS[%u] UAPSD[%u] BMCWIDX[%u]\n",
  1177. prCmdContent->ucStaIndex,
  1178. prCmdContent->ucIsQoS, prCmdContent->ucIsUapsdSupported, prCmdContent->ucBMCWlanIndex);
  1179. rStatus = wlanSendSetQueryCmd(prAdapter, /* prAdapter */
  1180. CMD_ID_UPDATE_STA_RECORD, /* ucCID */
  1181. TRUE, /* fgSetQuery */
  1182. fgNeedResp, /* fgNeedResp */
  1183. FALSE, /* fgIsOid */
  1184. fgNeedResp ? cnmStaRecHandleEventPkt : NULL, NULL, /* pfCmdTimeoutHandler */
  1185. sizeof(CMD_UPDATE_STA_RECORD_T), /* u4SetQueryInfoLen */
  1186. (PUINT_8) prCmdContent, /* pucInfoBuffer */
  1187. NULL, /* pvSetQueryBuffer */
  1188. 0 /* u4SetQueryBufferLen */
  1189. );
  1190. cnmMemFree(prAdapter, prCmdContent);
  1191. if (rStatus != WLAN_STATUS_PENDING)
  1192. DBGLOG(MEM, WARN, "%s: CMD_ID_UPDATE_STA_RECORD result 0x%08x\n", __func__, rStatus);
  1193. }
  1194. /*----------------------------------------------------------------------------*/
  1195. /*!
  1196. * @brief
  1197. *
  1198. * @param[in]
  1199. *
  1200. * @return (none)
  1201. */
  1202. /*----------------------------------------------------------------------------*/
  1203. static VOID
  1204. cnmStaSendRemoveCmd(P_ADAPTER_T prAdapter,
  1205. ENUM_STA_REC_CMD_ACTION_T eActionType, UINT_8 ucStaRecIndex, UINT_8 ucBssIndex)
  1206. {
  1207. CMD_REMOVE_STA_RECORD_T rCmdContent;
  1208. WLAN_STATUS rStatus;
  1209. ASSERT(prAdapter);
  1210. rCmdContent.ucActionType = (UINT_8) eActionType;
  1211. rCmdContent.ucStaIndex = ucStaRecIndex;
  1212. rCmdContent.ucBssIndex = ucBssIndex;
  1213. rCmdContent.ucReserved = 0;
  1214. rStatus = wlanSendSetQueryCmd(prAdapter, /* prAdapter */
  1215. CMD_ID_REMOVE_STA_RECORD, /* ucCID */
  1216. TRUE, /* fgSetQuery */
  1217. FALSE, /* fgNeedResp */
  1218. FALSE, /* fgIsOid */
  1219. NULL, /* pfCmdDoneHandler */
  1220. NULL, /* pfCmdTimeoutHandler */
  1221. sizeof(CMD_REMOVE_STA_RECORD_T), /* u4SetQueryInfoLen */
  1222. (PUINT_8) &rCmdContent, /* pucInfoBuffer */
  1223. NULL, /* pvSetQueryBuffer */
  1224. 0 /* u4SetQueryBufferLen */
  1225. );
  1226. if (rStatus != WLAN_STATUS_PENDING)
  1227. DBGLOG(MEM, WARN, "%s: CMD_ID_UPDATE_STA_RECORD result 0x%08x\n", __func__, rStatus);
  1228. }
  1229. PUINT_8 cnmStaRecGetTypeString(ENUM_STA_TYPE_T eStaType)
  1230. {
  1231. PUINT_8 pucTypeString = NULL;
  1232. if (eStaType & STA_TYPE_LEGACY_MASK)
  1233. pucTypeString = apucStaRecType[STA_TYPE_LEGACY_INDEX];
  1234. if (eStaType & STA_TYPE_P2P_MASK)
  1235. pucTypeString = apucStaRecType[STA_TYPE_P2P_INDEX];
  1236. if (eStaType & STA_TYPE_BOW_MASK)
  1237. pucTypeString = apucStaRecType[STA_TYPE_BOW_INDEX];
  1238. return pucTypeString;
  1239. }
  1240. PUINT_8 cnmStaRecGetRoleString(ENUM_STA_TYPE_T eStaType)
  1241. {
  1242. PUINT_8 pucRoleString = NULL;
  1243. if (eStaType & STA_TYPE_ADHOC_MASK)
  1244. pucRoleString = apucStaRecRole[STA_ROLE_ADHOC_INDEX - STA_ROLE_BASE_INDEX];
  1245. if (eStaType & STA_TYPE_CLIENT_MASK)
  1246. pucRoleString = apucStaRecRole[STA_ROLE_CLIENT_INDEX - STA_ROLE_BASE_INDEX];
  1247. if (eStaType & STA_TYPE_AP_MASK)
  1248. pucRoleString = apucStaRecRole[STA_ROLE_AP_INDEX - STA_ROLE_BASE_INDEX];
  1249. if (eStaType & STA_TYPE_DLS_MASK)
  1250. pucRoleString = apucStaRecRole[STA_ROLE_DLS_INDEX - STA_ROLE_BASE_INDEX];
  1251. return pucRoleString;
  1252. }
  1253. /*----------------------------------------------------------------------------*/
  1254. /*!
  1255. * @brief
  1256. *
  1257. * @param[in]
  1258. *
  1259. * @return (none)
  1260. */
  1261. /*----------------------------------------------------------------------------*/
  1262. VOID cnmDumpStaRec(IN P_ADAPTER_T prAdapter, IN UINT_8 ucStaRecIdx)
  1263. {
  1264. UINT_8 ucWTEntry;
  1265. UINT_32 i;
  1266. P_BSS_INFO_T prBssInfo;
  1267. P_STA_RECORD_T prStaRec;
  1268. DEBUGFUNC("cnmDumpStaRec");
  1269. prStaRec = cnmGetStaRecByIndex(prAdapter, ucStaRecIdx);
  1270. if (!prStaRec) {
  1271. DBGLOG(SW4, TRACE, "Invalid StaRec index[%u], skip dump!\n", ucStaRecIdx);
  1272. return;
  1273. }
  1274. ucWTEntry = prStaRec->ucWlanIndex;
  1275. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prStaRec->ucBssIndex);
  1276. ASSERT(prBssInfo);
  1277. DBGLOG(SW4, TRACE, "============= DUMP STA[%u] ===========\n", ucStaRecIdx);
  1278. DBGLOG(SW4, TRACE,
  1279. "STA_IDX[%u] BSS_IDX[%u] MAC[" MACSTR "] TYPE[%s %s] WTBL[%u] USED[%u] State[%u]\n",
  1280. prStaRec->ucIndex, prStaRec->ucBssIndex, MAC2STR(prStaRec->aucMacAddr),
  1281. cnmStaRecGetTypeString(prStaRec->eStaType),
  1282. cnmStaRecGetRoleString(prStaRec->eStaType), ucWTEntry, prStaRec->fgIsInUse, prStaRec->ucStaState);
  1283. DBGLOG(SW4, TRACE, "QoS[%u] HT/VHT[%u/%u] AID[%u] WMM[%u] UAPSD[%u] SEC[%u]\n",
  1284. prStaRec->fgIsQoS,
  1285. (prStaRec->ucDesiredPhyTypeSet & PHY_TYPE_SET_802_11N) ? TRUE : FALSE,
  1286. (prStaRec->ucDesiredPhyTypeSet & PHY_TYPE_SET_802_11AC) ? TRUE : FALSE,
  1287. prStaRec->u2AssocId,
  1288. prStaRec->fgIsWmmSupported,
  1289. prStaRec->fgIsUapsdSupported, secIsProtectedBss(prAdapter, prBssInfo));
  1290. DBGLOG(SW4, TRACE, "PhyTypeSet: BSS[0x%02x] Desired[0x%02x] NonHtBasic[0x%02x]\n",
  1291. prBssInfo->ucPhyTypeSet, prStaRec->ucDesiredPhyTypeSet, prStaRec->ucNonHTBasicPhyType);
  1292. DBGLOG(SW4, TRACE,
  1293. "RateSet: BssBasic[0x%04x] Operational[0x%04x] DesiredNonHT[0x%02x] DeafultFixedRate[0x%02x]\n",
  1294. prBssInfo->u2BSSBasicRateSet, prStaRec->u2OperationalRateSet,
  1295. prStaRec->u2DesiredNonHTRateSet, prStaRec->u2HwDefaultFixedRateCode);
  1296. DBGLOG(SW4, TRACE, "HT Cap[0x%04x] ExtCap[0x%04x] BeemCap[0x%08x] MCS[0x%02x] MCS32[%u]\n",
  1297. prStaRec->u2HtCapInfo,
  1298. prStaRec->u2HtExtendedCap,
  1299. prStaRec->u4TxBeamformingCap, prStaRec->ucMcsSet, prStaRec->fgSupMcs32);
  1300. DBGLOG(SW4, TRACE, "VHT Cap[0x%08x] TxMCS[0x%04x] RxMCS[0x%04x]\n",
  1301. prStaRec->u4VhtCapInfo, prStaRec->u2VhtTxMcsMap, prStaRec->u2VhtRxMcsMap);
  1302. DBGLOG(SW4, TRACE, "RCPI[%u] InPS[%u] TxAllowed[%u] KeyRdy[%u] AMPDU T/R[%u/%u]\n",
  1303. prStaRec->ucRCPI,
  1304. prStaRec->fgIsInPS,
  1305. prStaRec->fgIsTxAllowed,
  1306. prStaRec->fgIsTxKeyReady, prStaRec->fgTxAmpduEn, prStaRec->fgRxAmpduEn);
  1307. DBGLOG(SW4, TRACE, "TxQ LEN TC[0~5] [%03u:%03u:%03u:%03u:%03u:%03u]\n",
  1308. prStaRec->arTxQueue[0].u4NumElem,
  1309. prStaRec->arTxQueue[1].u4NumElem,
  1310. prStaRec->arTxQueue[2].u4NumElem,
  1311. prStaRec->arTxQueue[3].u4NumElem,
  1312. prStaRec->arTxQueue[4].u4NumElem, prStaRec->arTxQueue[5].u4NumElem);
  1313. DBGLOG(SW4, TRACE, "BMP AC Delivery/Trigger[%02x/%02x]\n",
  1314. prStaRec->ucBmpDeliveryAC, prStaRec->ucBmpTriggerAC);
  1315. DBGLOG(SW4, TRACE, "FreeQuota: Total[%u] Delivery/NonDelivery[%u/%u]\n",
  1316. prStaRec->ucFreeQuota,
  1317. prStaRec->ucFreeQuotaForDelivery, prStaRec->ucFreeQuotaForNonDelivery);
  1318. for (i = 0; i < CFG_RX_MAX_BA_TID_NUM; i++) {
  1319. if (prStaRec->aprRxReorderParamRefTbl[i]) {
  1320. DBGLOG(SW4, TRACE, "<Rx BA Entry TID[%u]>\n", prStaRec->aprRxReorderParamRefTbl[i]->ucTid);
  1321. DBGLOG(SW4, TRACE,
  1322. " Valid[%u] WinStart/End[%u/%u] WinSize[%u] ReOrderQueLen[%u]\n",
  1323. prStaRec->aprRxReorderParamRefTbl[i]->fgIsValid,
  1324. prStaRec->aprRxReorderParamRefTbl[i]->u2WinStart,
  1325. prStaRec->aprRxReorderParamRefTbl[i]->u2WinEnd,
  1326. prStaRec->aprRxReorderParamRefTbl[i]->u2WinSize,
  1327. prStaRec->aprRxReorderParamRefTbl[i]->rReOrderQue.u4NumElem);
  1328. DBGLOG(SW4, TRACE,
  1329. " Bubble Exist[%u] SN[%u]\n",
  1330. prStaRec->aprRxReorderParamRefTbl[i]->fgHasBubble,
  1331. prStaRec->aprRxReorderParamRefTbl[i]->u2FirstBubbleSn);
  1332. }
  1333. }
  1334. DBGLOG(SW4, TRACE, "============= DUMP END ===========\n");
  1335. }
  1336. VOID cnmDumpMemoryStatus(IN P_ADAPTER_T prAdapter)
  1337. {
  1338. P_BUF_INFO_T prBufInfo;
  1339. #if CFG_DBG_MGT_BUF
  1340. DBGLOG(SW4, TRACE, "============= DUMP Memory Status =============\n");
  1341. DBGLOG(SW4, TRACE, "Dynamic alloc OS memory count: alloc[%u] free[%u]\n",
  1342. prAdapter->u4MemAllocDynamicCount, prAdapter->u4MemFreeDynamicCount);
  1343. prBufInfo = &prAdapter->rMsgBufInfo;
  1344. DBGLOG(SW4, TRACE, "MSG memory count: alloc[%u] free[%u] null[%u] bitmap[0x%08x]\n",
  1345. prBufInfo->u4AllocCount, prBufInfo->u4FreeCount,
  1346. prBufInfo->u4AllocNullCount, (UINT_32) prBufInfo->rFreeBlocksBitmap);
  1347. prBufInfo = &prAdapter->rMgtBufInfo;
  1348. DBGLOG(SW4, TRACE, "MGT memory count: alloc[%u] free[%u] null[%u] bitmap[0x%08x]\n",
  1349. prBufInfo->u4AllocCount, prBufInfo->u4FreeCount,
  1350. prBufInfo->u4AllocNullCount, (UINT_32) prBufInfo->rFreeBlocksBitmap);
  1351. DBGLOG(SW4, TRACE, "============= DUMP END =============\n");
  1352. #endif
  1353. }
  1354. #if CFG_SUPPORT_TDLS
  1355. /*----------------------------------------------------------------------------*/
  1356. /*!
  1357. * \brief This routine is called to add a peer record.
  1358. *
  1359. * \param[in] pvAdapter Pointer to the Adapter structure.
  1360. * \param[out] pvQueryBuf A pointer to the buffer that holds the result of
  1361. * the query.
  1362. * \param[in] u4QueryBufLen The length of the query buffer.
  1363. * \param[out] pu4QueryInfoLen If the call is successful, returns the number of
  1364. * bytes written into the query buffer. If the call
  1365. * failed due to invalid length of the query buffer,
  1366. * returns the amount of storage needed.
  1367. *
  1368. * \retval WLAN_STATUS_SUCCESS
  1369. * \retval WLAN_STATUS_INVALID_LENGTH
  1370. */
  1371. /*----------------------------------------------------------------------------*/
  1372. WLAN_STATUS /* TDLS_STATUS //prStaRec->ucNetTypeIndex */
  1373. cnmPeerAdd(P_ADAPTER_T prAdapter, PVOID pvSetBuffer, UINT_32 u4SetBufferLen, PUINT_32 pu4SetInfoLen)
  1374. {
  1375. CMD_PEER_ADD_T *prCmd;
  1376. BSS_INFO_T *prAisBssInfo;
  1377. STA_RECORD_T *prStaRec;
  1378. /* sanity check */
  1379. if ((prAdapter == NULL) || (pvSetBuffer == NULL) || (pu4SetInfoLen == NULL))
  1380. return TDLS_STATUS_FAIL;
  1381. /* init */
  1382. *pu4SetInfoLen = sizeof(CMD_PEER_ADD_T);
  1383. prCmd = (CMD_PEER_ADD_T *) pvSetBuffer;
  1384. prAisBssInfo = prAdapter->prAisBssInfo; /* for AIS only test */
  1385. prStaRec = cnmGetStaRecByAddress(prAdapter, (UINT_8) prAdapter->prAisBssInfo->ucBssIndex, prCmd->aucPeerMac);
  1386. if (prStaRec == NULL) {
  1387. prStaRec =
  1388. cnmStaRecAlloc(prAdapter, STA_TYPE_DLS_PEER,
  1389. (UINT_8) prAdapter->prAisBssInfo->ucBssIndex, prCmd->aucPeerMac);
  1390. if (prStaRec == NULL)
  1391. return TDLS_STATUS_RESOURCES;
  1392. if (prAisBssInfo) {
  1393. if (prAisBssInfo->ucBssIndex)
  1394. prStaRec->ucBssIndex = prAisBssInfo->ucBssIndex;
  1395. }
  1396. /* init the prStaRec */
  1397. /* prStaRec will be zero first in cnmStaRecAlloc() */
  1398. COPY_MAC_ADDR(prStaRec->aucMacAddr, prCmd->aucPeerMac);
  1399. prStaRec->u2BSSBasicRateSet = prAisBssInfo->u2BSSBasicRateSet;
  1400. prStaRec->u2DesiredNonHTRateSet = prAdapter->rWifiVar.ucAvailablePhyTypeSet;
  1401. prStaRec->u2OperationalRateSet = prAisBssInfo->u2OperationalRateSet;
  1402. prStaRec->ucPhyTypeSet = prAisBssInfo->ucPhyTypeSet;
  1403. prStaRec->eStaType = prCmd->eStaType;
  1404. /* NOTE(Kevin): Better to change state here, not at TX Done */
  1405. cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_1);
  1406. } else {
  1407. if ((prStaRec->ucStaState > STA_STATE_1) && (IS_DLS_STA(prStaRec))) {
  1408. /* TODO: Teardown the peer */
  1409. cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_1);
  1410. }
  1411. }
  1412. return TDLS_STATUS_SUCCESS;
  1413. }
  1414. /*----------------------------------------------------------------------------*/
  1415. /*!
  1416. * \brief This routine is called to update a peer record.
  1417. *
  1418. * \param[in] pvAdapter Pointer to the Adapter structure.
  1419. * \param[out] pvQueryBuf A pointer to the buffer that holds the result of
  1420. * the query.
  1421. * \param[in] u4QueryBufLen The length of the query buffer.
  1422. * \param[out] pu4QueryInfoLen If the call is successful, returns the number of
  1423. * bytes written into the query buffer. If the call
  1424. * failed due to invalid length of the query buffer,
  1425. * returns the amount of storage needed.
  1426. *
  1427. * \retval WLAN_STATUS_SUCCESS
  1428. * \retval WLAN_STATUS_INVALID_LENGTH
  1429. */
  1430. /*----------------------------------------------------------------------------*/
  1431. WLAN_STATUS /* TDLS_STATUS */
  1432. cnmPeerUpdate(P_ADAPTER_T prAdapter, PVOID pvSetBuffer, UINT_32 u4SetBufferLen, PUINT_32 pu4SetInfoLen)
  1433. {
  1434. CMD_PEER_UPDATE_T *prCmd;
  1435. BSS_INFO_T *prAisBssInfo;
  1436. STA_RECORD_T *prStaRec;
  1437. UINT_8 ucNonHTPhyTypeSet;
  1438. UINT_16 u2OperationalRateSet = 0;
  1439. UINT_8 ucRate;
  1440. UINT_16 i, j;
  1441. /* sanity check */
  1442. if ((!prAdapter) || (!pvSetBuffer) || (!pu4SetInfoLen))
  1443. return TDLS_STATUS_FAIL;
  1444. /* init */
  1445. *pu4SetInfoLen = sizeof(CMD_PEER_ADD_T);
  1446. prCmd = (CMD_PEER_UPDATE_T *) pvSetBuffer;
  1447. prAisBssInfo = prAdapter->prAisBssInfo;
  1448. if (!prAisBssInfo)
  1449. return TDLS_STATUS_FAIL;
  1450. prStaRec = cnmGetStaRecByAddress(prAdapter, (UINT_8) prAdapter->prAisBssInfo->ucBssIndex, prCmd->aucPeerMac);
  1451. if ((!prStaRec) || !(prStaRec->fgIsInUse))
  1452. return TDLS_STATUS_FAIL;
  1453. if (!IS_DLS_STA(prStaRec))
  1454. return TDLS_STATUS_FAIL;
  1455. if (prAisBssInfo) {
  1456. if (prAisBssInfo->ucBssIndex)
  1457. prStaRec->ucBssIndex = prAisBssInfo->ucBssIndex;
  1458. }
  1459. /* update the record join time. */
  1460. GET_CURRENT_SYSTIME(&prStaRec->rUpdateTime);
  1461. /* update Station Record - Status/Reason Code */
  1462. prStaRec->u2StatusCode = prCmd->u2StatusCode;
  1463. prStaRec->u2AssocId = 0; /* no use */
  1464. prStaRec->u2ListenInterval = 0; /* unknown */
  1465. prStaRec->fgIsQoS = TRUE;
  1466. prStaRec->fgIsUapsdSupported = (prCmd->UapsdBitmap == 0) ? FALSE : TRUE;
  1467. prStaRec->u4TxBeamformingCap = 0; /* no use */
  1468. prStaRec->ucAselCap = 0; /* no use */
  1469. prStaRec->ucRCPI = 0;
  1470. prStaRec->ucBmpTriggerAC = prCmd->UapsdBitmap;
  1471. prStaRec->ucBmpDeliveryAC = prCmd->UapsdBitmap;
  1472. prStaRec->ucUapsdSp = prCmd->UapsdMaxSp;
  1473. prStaRec->eStaType = prCmd->eStaType;
  1474. /* ++ support rate */
  1475. if (prCmd->aucSupRate) {
  1476. for (i = 0; i < prCmd->u2SupRateLen; i++) {
  1477. if (prCmd->aucSupRate[i]) {
  1478. ucRate = prCmd->aucSupRate[i] & RATE_MASK;
  1479. /* Search all valid data rates */
  1480. for (j = 0; j < sizeof(aucValidDataRate) / sizeof(UINT_8); j++) {
  1481. if (ucRate == aucValidDataRate[j]) {
  1482. u2OperationalRateSet |= BIT(j);
  1483. break;
  1484. }
  1485. }
  1486. }
  1487. }
  1488. prStaRec->u2OperationalRateSet = u2OperationalRateSet;
  1489. prStaRec->u2BSSBasicRateSet = prAisBssInfo->u2BSSBasicRateSet;
  1490. /* 4 <5> PHY type setting */
  1491. prStaRec->ucPhyTypeSet = 0;
  1492. if (BAND_2G4 == prAisBssInfo->eBand) {
  1493. if (prCmd->rHtCap.rMCS.arRxMask)
  1494. prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_HT;
  1495. /* if not 11n only */
  1496. if (!(prStaRec->u2BSSBasicRateSet & RATE_SET_BIT_HT_PHY)) {
  1497. /* check if support 11g */
  1498. if ((prStaRec->u2OperationalRateSet & RATE_SET_OFDM))
  1499. prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_ERP;
  1500. /* if not 11g only */
  1501. if (!(prStaRec->u2BSSBasicRateSet & RATE_SET_OFDM)) {
  1502. /* check if support 11b */
  1503. if ((prStaRec->u2OperationalRateSet & RATE_SET_HR_DSSS))
  1504. prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_HR_DSSS;
  1505. }
  1506. }
  1507. } else {
  1508. if (prCmd->rVHtCap.u2CapInfo)
  1509. prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_VHT;
  1510. if (prCmd->rHtCap.rMCS.arRxMask)
  1511. prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_HT;
  1512. /* if not 11n only */
  1513. if (!(prStaRec->u2BSSBasicRateSet & RATE_SET_BIT_HT_PHY)) {
  1514. /* Support 11a definitely */
  1515. prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_OFDM;
  1516. }
  1517. }
  1518. if (IS_STA_IN_AIS(prStaRec)) {
  1519. if (!((prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION3_ENABLED)
  1520. || (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION3_KEY_ABSENT)
  1521. || (prAdapter->rWifiVar.rConnSettings.eEncStatus == ENUM_ENCRYPTION_DISABLED)
  1522. || (prAdapter->prGlueInfo->u2WSCAssocInfoIELen)
  1523. #if CFG_SUPPORT_WAPI
  1524. || (prAdapter->prGlueInfo->u2WapiAssocInfoIESz)
  1525. #endif
  1526. )) {
  1527. prStaRec->ucPhyTypeSet &= ~PHY_TYPE_BIT_HT;
  1528. }
  1529. }
  1530. prStaRec->ucDesiredPhyTypeSet = prStaRec->ucPhyTypeSet & prAdapter->rWifiVar.ucAvailablePhyTypeSet;
  1531. ucNonHTPhyTypeSet = prStaRec->ucDesiredPhyTypeSet & PHY_TYPE_SET_802_11ABG;
  1532. /* Check for Target BSS's non HT Phy Types */
  1533. if (ucNonHTPhyTypeSet) {
  1534. if (ucNonHTPhyTypeSet & PHY_TYPE_BIT_ERP)
  1535. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_ERP_INDEX;
  1536. else if (ucNonHTPhyTypeSet & PHY_TYPE_BIT_OFDM)
  1537. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_OFDM_INDEX;
  1538. else
  1539. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_HR_DSSS_INDEX;
  1540. prStaRec->fgHasBasicPhyType = TRUE;
  1541. } else {
  1542. /* Use mandatory for 11N only BSS */
  1543. ASSERT(prStaRec->ucPhyTypeSet & PHY_TYPE_SET_802_11N);
  1544. {
  1545. /* TODO(Kevin): which value should we set for 11n ? ERP ? */
  1546. prStaRec->ucNonHTBasicPhyType = PHY_TYPE_HR_DSSS_INDEX;
  1547. }
  1548. prStaRec->fgHasBasicPhyType = FALSE;
  1549. }
  1550. }
  1551. /* ++HT capability */
  1552. if (prCmd->rHtCap.rMCS.arRxMask) {
  1553. prAdapter->rWifiVar.eRateSetting = FIXED_RATE_NONE;
  1554. prStaRec->ucDesiredPhyTypeSet |= PHY_TYPE_BIT_HT;
  1555. prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_HT;
  1556. prStaRec->u2HtCapInfo = prCmd->rHtCap.u2CapInfo;
  1557. prStaRec->ucAmpduParam = prCmd->rHtCap.ucAmpduParamsInfo;
  1558. prStaRec->u2HtExtendedCap = prCmd->rHtCap.u2ExtHtCapInfo;
  1559. prStaRec->u4TxBeamformingCap = prCmd->rHtCap.u4TxBfCapInfo;
  1560. prStaRec->ucAselCap = prCmd->rHtCap.ucAntennaSelInfo;
  1561. prStaRec->ucMcsSet = prCmd->rHtCap.rMCS.arRxMask[0];
  1562. prStaRec->fgSupMcs32 = (prCmd->rHtCap.rMCS.arRxMask[32 / 8] & BIT(0)) ? TRUE : FALSE;
  1563. kalMemCopy(prStaRec->aucRxMcsBitmask, prCmd->rHtCap.rMCS.arRxMask, sizeof(prStaRec->aucRxMcsBitmask));
  1564. }
  1565. /* TODO ++VHT */
  1566. cnmStaRecChangeState(prAdapter, prStaRec, STA_STATE_3);
  1567. return TDLS_STATUS_SUCCESS;
  1568. }
  1569. /*----------------------------------------------------------------------------*/
  1570. /*!
  1571. * @brief Get TDLS peer STA_RECORD_T by Peer MAC Address(Usually TA).
  1572. *
  1573. * @param[in] pucPeerMacAddr Given Peer MAC Address.
  1574. *
  1575. * @retval Pointer to STA_RECORD_T, if found. NULL, if not found
  1576. */
  1577. /*----------------------------------------------------------------------------*/
  1578. P_STA_RECORD_T cnmGetTdlsPeerByAddress(P_ADAPTER_T prAdapter, UINT_8 ucBssIndex, UINT_8 aucPeerMACAddress[])
  1579. {
  1580. P_STA_RECORD_T prStaRec;
  1581. UINT_16 i;
  1582. ASSERT(prAdapter);
  1583. ASSERT(aucPeerMACAddress);
  1584. for (i = 0; i < CFG_STA_REC_NUM; i++) {
  1585. prStaRec = &prAdapter->arStaRec[i];
  1586. if (prStaRec) {
  1587. if (prStaRec->fgIsInUse &&
  1588. prStaRec->eStaType == STA_TYPE_DLS_PEER &&
  1589. EQUAL_MAC_ADDR(prStaRec->aucMacAddr, aucPeerMACAddress)) {
  1590. break;
  1591. }
  1592. }
  1593. }
  1594. return prStaRec;
  1595. }
  1596. #endif