rtw_ap.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_AP_C_
  21. #include <drv_types.h>
  22. #include <hal_data.h>
  23. #ifdef CONFIG_AP_MODE
  24. extern unsigned char RTW_WPA_OUI[];
  25. extern unsigned char WMM_OUI[];
  26. extern unsigned char WPS_OUI[];
  27. extern unsigned char P2P_OUI[];
  28. extern unsigned char WFD_OUI[];
  29. void init_mlme_ap_info(_adapter *padapter)
  30. {
  31. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  32. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  33. _rtw_spinlock_init(&pmlmepriv->bcn_update_lock);
  34. /* pmlmeext->bstart_bss = _FALSE; */
  35. }
  36. void free_mlme_ap_info(_adapter *padapter)
  37. {
  38. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  39. stop_ap_mode(padapter);
  40. _rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
  41. }
  42. static void update_BCNTIM(_adapter *padapter)
  43. {
  44. struct sta_priv *pstapriv = &padapter->stapriv;
  45. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  46. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  47. WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
  48. unsigned char *pie = pnetwork_mlmeext->IEs;
  49. #if 0
  50. /* update TIM IE */
  51. /* if(pstapriv->tim_bitmap) */
  52. #endif
  53. if (_TRUE) {
  54. u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
  55. u16 tim_bitmap_le;
  56. uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
  57. tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
  58. p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
  59. if (p != NULL && tim_ielen > 0) {
  60. tim_ielen += 2;
  61. premainder_ie = p + tim_ielen;
  62. tim_ie_offset = (sint)(p - pie);
  63. remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
  64. /*append TIM IE from dst_ie offset*/
  65. dst_ie = p;
  66. } else {
  67. tim_ielen = 0;
  68. /*calculate head_len*/
  69. offset = _FIXED_IE_LENGTH_;
  70. /* get ssid_ie len */
  71. p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
  72. if (p != NULL)
  73. offset += tmp_len + 2;
  74. /*get supported rates len*/
  75. p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
  76. if (p != NULL)
  77. offset += tmp_len + 2;
  78. /*DS Parameter Set IE, len=3*/
  79. offset += 3;
  80. premainder_ie = pie + offset;
  81. remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
  82. /*append TIM IE from offset*/
  83. dst_ie = pie + offset;
  84. }
  85. if (remainder_ielen > 0) {
  86. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  87. if (pbackup_remainder_ie && premainder_ie)
  88. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  89. }
  90. *dst_ie++ = _TIM_IE_;
  91. if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fe))
  92. tim_ielen = 5;
  93. else
  94. tim_ielen = 4;
  95. *dst_ie++ = tim_ielen;
  96. *dst_ie++ = 0;/*DTIM count*/
  97. *dst_ie++ = 1;/*DTIM period*/
  98. if (pstapriv->tim_bitmap & BIT(0))/*for bc/mc frames*/
  99. *dst_ie++ = BIT(0);/*bitmap ctrl */
  100. else
  101. *dst_ie++ = 0;
  102. if (tim_ielen == 4) {
  103. u8 pvb = 0;
  104. if (pstapriv->tim_bitmap & 0x00fe)
  105. pvb = (u8)tim_bitmap_le;
  106. else if (pstapriv->tim_bitmap & 0xff00)
  107. pvb = (u8)(tim_bitmap_le >> 8);
  108. else
  109. pvb = (u8)tim_bitmap_le;
  110. *dst_ie++ = pvb;
  111. } else if (tim_ielen == 5) {
  112. _rtw_memcpy(dst_ie, &tim_bitmap_le, 2);
  113. dst_ie += 2;
  114. }
  115. /*copy remainder IE*/
  116. if (pbackup_remainder_ie) {
  117. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  118. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  119. }
  120. offset = (uint)(dst_ie - pie);
  121. pnetwork_mlmeext->IELength = offset + remainder_ielen;
  122. }
  123. }
  124. void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
  125. {
  126. PNDIS_802_11_VARIABLE_IEs pIE;
  127. u8 bmatch = _FALSE;
  128. u8 *pie = pnetwork->IEs;
  129. u8 *p = NULL, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
  130. u32 i, offset, ielen, ie_offset, remainder_ielen = 0;
  131. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;) {
  132. pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
  133. if (pIE->ElementID > index)
  134. break;
  135. else if (pIE->ElementID == index) { /* already exist the same IE */
  136. p = (u8 *)pIE;
  137. ielen = pIE->Length;
  138. bmatch = _TRUE;
  139. break;
  140. }
  141. p = (u8 *)pIE;
  142. ielen = pIE->Length;
  143. i += (pIE->Length + 2);
  144. }
  145. if (p != NULL && ielen > 0) {
  146. ielen += 2;
  147. premainder_ie = p + ielen;
  148. ie_offset = (sint)(p - pie);
  149. remainder_ielen = pnetwork->IELength - ie_offset - ielen;
  150. if (bmatch)
  151. dst_ie = p;
  152. else
  153. dst_ie = (p + ielen);
  154. }
  155. if (dst_ie == NULL)
  156. return;
  157. if (remainder_ielen > 0) {
  158. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  159. if (pbackup_remainder_ie && premainder_ie)
  160. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  161. }
  162. *dst_ie++ = index;
  163. *dst_ie++ = len;
  164. _rtw_memcpy(dst_ie, data, len);
  165. dst_ie += len;
  166. /* copy remainder IE */
  167. if (pbackup_remainder_ie) {
  168. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  169. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  170. }
  171. offset = (uint)(dst_ie - pie);
  172. pnetwork->IELength = offset + remainder_ielen;
  173. }
  174. void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
  175. {
  176. u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
  177. uint offset, ielen, ie_offset, remainder_ielen = 0;
  178. u8 *pie = pnetwork->IEs;
  179. p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
  180. if (p != NULL && ielen > 0) {
  181. ielen += 2;
  182. premainder_ie = p + ielen;
  183. ie_offset = (sint)(p - pie);
  184. remainder_ielen = pnetwork->IELength - ie_offset - ielen;
  185. dst_ie = p;
  186. } else
  187. return;
  188. if (remainder_ielen > 0) {
  189. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  190. if (pbackup_remainder_ie && premainder_ie)
  191. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  192. }
  193. /* copy remainder IE */
  194. if (pbackup_remainder_ie) {
  195. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  196. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  197. }
  198. offset = (uint)(dst_ie - pie);
  199. pnetwork->IELength = offset + remainder_ielen;
  200. }
  201. u8 chk_sta_is_alive(struct sta_info *psta);
  202. u8 chk_sta_is_alive(struct sta_info *psta)
  203. {
  204. u8 ret = _FALSE;
  205. #ifdef DBG_EXPIRATION_CHK
  206. RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
  207. , MAC_ARG(psta->hwaddr)
  208. , psta->rssi_stat.undecorated_smoothed_pwdb
  209. /* , STA_RX_PKTS_ARG(psta) */
  210. , STA_RX_PKTS_DIFF_ARG(psta)
  211. , psta->expire_to
  212. , psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
  213. , psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
  214. , psta->sleepq_len
  215. );
  216. #endif
  217. /* if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta)) */
  218. if ((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) == (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts)) {
  219. #if 0
  220. if (psta->state & WIFI_SLEEP_STATE)
  221. ret = _TRUE;
  222. #endif
  223. } else
  224. ret = _TRUE;
  225. sta_update_last_rx_pkts(psta);
  226. return ret;
  227. }
  228. void expire_timeout_chk(_adapter *padapter)
  229. {
  230. _irqL irqL;
  231. _list *phead, *plist;
  232. u8 updated = _FALSE;
  233. struct sta_info *psta = NULL;
  234. struct sta_priv *pstapriv = &padapter->stapriv;
  235. u8 chk_alive_num = 0;
  236. char chk_alive_list[NUM_STA];
  237. int i;
  238. #ifdef CONFIG_MCC_MODE
  239. /* then driver may check fail due to not recv client's frame under sitesurvey,
  240. * don't expire timeout chk under MCC under sitesurvey */
  241. if (rtw_hal_mcc_link_status_chk(padapter, __func__) == _FALSE)
  242. return;
  243. #endif
  244. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  245. phead = &pstapriv->auth_list;
  246. plist = get_next(phead);
  247. /* check auth_queue */
  248. #ifdef DBG_EXPIRATION_CHK
  249. if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  250. RTW_INFO(FUNC_NDEV_FMT" auth_list, cnt:%u\n"
  251. , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->auth_list_cnt);
  252. }
  253. #endif
  254. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  255. psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
  256. plist = get_next(plist);
  257. #ifdef CONFIG_ATMEL_RC_PATCH
  258. if (_TRUE == _rtw_memcmp((void *)(pstapriv->atmel_rc_pattern), (void *)(psta->hwaddr), ETH_ALEN))
  259. continue;
  260. if (psta->flag_atmel_rc)
  261. continue;
  262. #endif
  263. if (psta->expire_to > 0) {
  264. psta->expire_to--;
  265. if (psta->expire_to == 0) {
  266. rtw_list_delete(&psta->auth_list);
  267. pstapriv->auth_list_cnt--;
  268. RTW_INFO("auth expire %02X%02X%02X%02X%02X%02X\n",
  269. psta->hwaddr[0], psta->hwaddr[1], psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4], psta->hwaddr[5]);
  270. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  271. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  272. rtw_free_stainfo(padapter, psta);
  273. /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  274. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  275. }
  276. }
  277. }
  278. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  279. psta = NULL;
  280. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  281. phead = &pstapriv->asoc_list;
  282. plist = get_next(phead);
  283. /* check asoc_queue */
  284. #ifdef DBG_EXPIRATION_CHK
  285. if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  286. RTW_INFO(FUNC_NDEV_FMT" asoc_list, cnt:%u\n"
  287. , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->asoc_list_cnt);
  288. }
  289. #endif
  290. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  291. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  292. plist = get_next(plist);
  293. #ifdef CONFIG_ATMEL_RC_PATCH
  294. RTW_INFO("%s:%d psta=%p, %02x,%02x||%02x,%02x \n\n", __func__, __LINE__,
  295. psta, pstapriv->atmel_rc_pattern[0], pstapriv->atmel_rc_pattern[5], psta->hwaddr[0], psta->hwaddr[5]);
  296. if (_TRUE == _rtw_memcmp((void *)pstapriv->atmel_rc_pattern, (void *)(psta->hwaddr), ETH_ALEN))
  297. continue;
  298. if (psta->flag_atmel_rc)
  299. continue;
  300. RTW_INFO("%s: debug line:%d\n", __func__, __LINE__);
  301. #endif
  302. #ifdef CONFIG_AUTO_AP_MODE
  303. if (psta->isrc)
  304. continue;
  305. #endif
  306. if (chk_sta_is_alive(psta) || !psta->expire_to) {
  307. psta->expire_to = pstapriv->expire_to;
  308. psta->keep_alive_trycnt = 0;
  309. #ifdef CONFIG_TX_MCAST2UNI
  310. psta->under_exist_checking = 0;
  311. #endif /* CONFIG_TX_MCAST2UNI */
  312. } else
  313. psta->expire_to--;
  314. #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  315. #ifdef CONFIG_80211N_HT
  316. #ifdef CONFIG_TX_MCAST2UNI
  317. if ((psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking)) {
  318. /* check sta by delba(addba) for 11n STA */
  319. /* ToDo: use CCX report to check for all STAs */
  320. /* RTW_INFO("asoc check by DELBA/ADDBA! (pstapriv->expire_to=%d s)(psta->expire_to=%d s), [%02x, %d]\n", pstapriv->expire_to*2, psta->expire_to*2, psta->htpriv.agg_enable_bitmap, psta->under_exist_checking); */
  321. if (psta->expire_to <= (pstapriv->expire_to - 50)) {
  322. RTW_INFO("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
  323. psta->under_exist_checking = 0;
  324. psta->expire_to = 0;
  325. } else if (psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking == 0)) {
  326. RTW_INFO("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
  327. psta->under_exist_checking = 1;
  328. /* tear down TX AMPDU */
  329. send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
  330. psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
  331. psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
  332. }
  333. }
  334. #endif /* CONFIG_TX_MCAST2UNI */
  335. #endif /* CONFIG_80211N_HT */
  336. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  337. if (psta->expire_to <= 0) {
  338. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  339. if (padapter->registrypriv.wifi_spec == 1) {
  340. psta->expire_to = pstapriv->expire_to;
  341. continue;
  342. }
  343. #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  344. #ifdef CONFIG_80211N_HT
  345. #define KEEP_ALIVE_TRYCNT (3)
  346. if (psta->keep_alive_trycnt > 0 && psta->keep_alive_trycnt <= KEEP_ALIVE_TRYCNT) {
  347. if (psta->state & WIFI_STA_ALIVE_CHK_STATE)
  348. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  349. else
  350. psta->keep_alive_trycnt = 0;
  351. } else if ((psta->keep_alive_trycnt > KEEP_ALIVE_TRYCNT) && !(psta->state & WIFI_STA_ALIVE_CHK_STATE))
  352. psta->keep_alive_trycnt = 0;
  353. if ((psta->htpriv.ht_option == _TRUE) && (psta->htpriv.ampdu_enable == _TRUE)) {
  354. uint priority = 1; /* test using BK */
  355. u8 issued = 0;
  356. /* issued = (psta->htpriv.agg_enable_bitmap>>priority)&0x1; */
  357. issued |= (psta->htpriv.candidate_tid_bitmap >> priority) & 0x1;
  358. if (0 == issued) {
  359. if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
  360. psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
  361. if (psta->state & WIFI_SLEEP_STATE)
  362. psta->expire_to = 2; /* 2x2=4 sec */
  363. else
  364. psta->expire_to = 1; /* 2 sec */
  365. psta->state |= WIFI_STA_ALIVE_CHK_STATE;
  366. /* add_ba_hdl(padapter, (u8*)paddbareq_parm); */
  367. RTW_INFO("issue addba_req to check if sta alive, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
  368. issue_addba_req(padapter, psta->hwaddr, (u8)priority);
  369. _set_timer(&psta->addba_retry_timer, ADDBA_TO);
  370. psta->keep_alive_trycnt++;
  371. continue;
  372. }
  373. }
  374. }
  375. if (psta->keep_alive_trycnt > 0 && psta->state & WIFI_STA_ALIVE_CHK_STATE) {
  376. psta->keep_alive_trycnt = 0;
  377. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  378. RTW_INFO("change to another methods to check alive if staion is at ps mode\n");
  379. }
  380. #endif /* CONFIG_80211N_HT */
  381. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  382. if (psta->state & WIFI_SLEEP_STATE) {
  383. if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
  384. /* to check if alive by another methods if staion is at ps mode. */
  385. psta->expire_to = pstapriv->expire_to;
  386. psta->state |= WIFI_STA_ALIVE_CHK_STATE;
  387. /* RTW_INFO("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->hwaddr)); */
  388. /* to update bcn with tim_bitmap for this station */
  389. pstapriv->tim_bitmap |= BIT(psta->aid);
  390. update_beacon(padapter, _TIM_IE_, NULL, _TRUE);
  391. if (!pmlmeext->active_keep_alive_check)
  392. continue;
  393. }
  394. }
  395. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  396. if (pmlmeext->active_keep_alive_check) {
  397. int stainfo_offset;
  398. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  399. if (stainfo_offset_valid(stainfo_offset))
  400. chk_alive_list[chk_alive_num++] = stainfo_offset;
  401. continue;
  402. }
  403. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  404. rtw_list_delete(&psta->asoc_list);
  405. pstapriv->asoc_list_cnt--;
  406. RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
  407. updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
  408. } else {
  409. /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
  410. if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
  411. && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)
  412. ) {
  413. RTW_INFO("%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__
  414. , MAC_ARG(psta->hwaddr)
  415. , psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
  416. wakeup_sta_to_xmit(padapter, psta);
  417. }
  418. }
  419. }
  420. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  421. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  422. if (chk_alive_num) {
  423. u8 backup_ch = 0, backup_bw, backup_offset;
  424. u8 union_ch = 0, union_bw, union_offset;
  425. u8 switch_channel = _TRUE;
  426. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  427. if (!rtw_mi_get_ch_setting_union(padapter, &union_ch, &union_bw, &union_offset)
  428. || pmlmeext->cur_channel != union_ch)
  429. goto bypass_active_keep_alive;
  430. #ifdef CONFIG_MCC_MODE
  431. if (MCC_EN(padapter)) {
  432. /* driver doesn't switch channel under MCC */
  433. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
  434. switch_channel = _FALSE;
  435. }
  436. #endif
  437. /* switch to correct channel of current network before issue keep-alive frames */
  438. if (switch_channel == _TRUE && rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
  439. backup_ch = rtw_get_oper_ch(padapter);
  440. backup_bw = rtw_get_oper_bw(padapter);
  441. backup_offset = rtw_get_oper_choffset(padapter);
  442. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  443. }
  444. /* issue null data to check sta alive*/
  445. for (i = 0; i < chk_alive_num; i++) {
  446. int ret = _FAIL;
  447. psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
  448. #ifdef CONFIG_ATMEL_RC_PATCH
  449. if (_TRUE == _rtw_memcmp(pstapriv->atmel_rc_pattern, psta->hwaddr, ETH_ALEN))
  450. continue;
  451. if (psta->flag_atmel_rc)
  452. continue;
  453. #endif
  454. if (!(psta->state & _FW_LINKED))
  455. continue;
  456. if (psta->state & WIFI_SLEEP_STATE)
  457. ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
  458. else
  459. ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
  460. psta->keep_alive_trycnt++;
  461. if (ret == _SUCCESS) {
  462. RTW_INFO("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->hwaddr));
  463. psta->expire_to = pstapriv->expire_to;
  464. psta->keep_alive_trycnt = 0;
  465. continue;
  466. } else if (psta->keep_alive_trycnt <= 3) {
  467. RTW_INFO("ack check for asoc expire, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
  468. psta->expire_to = 1;
  469. continue;
  470. }
  471. psta->keep_alive_trycnt = 0;
  472. RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
  473. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  474. if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
  475. rtw_list_delete(&psta->asoc_list);
  476. pstapriv->asoc_list_cnt--;
  477. updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
  478. }
  479. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  480. }
  481. /* back to the original operation channel */
  482. if (switch_channel && backup_ch > 0)
  483. set_channel_bwmode(padapter, backup_ch, backup_offset, backup_bw);
  484. bypass_active_keep_alive:
  485. ;
  486. }
  487. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  488. associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
  489. }
  490. void add_RATid(_adapter *padapter, struct sta_info *psta, u8 rssi_level, u8 is_update_bw)
  491. {
  492. int i;
  493. u8 rf_type;
  494. unsigned char sta_band = 0;
  495. u64 tx_ra_bitmap = 0;
  496. struct ht_priv *psta_ht = NULL;
  497. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  498. WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  499. #ifdef CONFIG_80211N_HT
  500. if (psta)
  501. psta_ht = &psta->htpriv;
  502. else
  503. return;
  504. #endif /* CONFIG_80211N_HT */
  505. if (!(psta->state & _FW_LINKED))
  506. return;
  507. rtw_hal_update_sta_rate_mask(padapter, psta);
  508. tx_ra_bitmap = psta->ra_mask;
  509. if (pcur_network->Configuration.DSConfig > 14) {
  510. if (tx_ra_bitmap & 0xffff000)
  511. sta_band |= WIRELESS_11_5N ;
  512. if (tx_ra_bitmap & 0xff0)
  513. sta_band |= WIRELESS_11A;
  514. /* 5G band */
  515. #ifdef CONFIG_80211AC_VHT
  516. if (psta->vhtpriv.vht_option)
  517. sta_band = WIRELESS_11_5AC;
  518. #endif
  519. } else {
  520. if (tx_ra_bitmap & 0xffff000)
  521. sta_band |= WIRELESS_11_24N;
  522. if (tx_ra_bitmap & 0xff0)
  523. sta_band |= WIRELESS_11G;
  524. if (tx_ra_bitmap & 0x0f)
  525. sta_band |= WIRELESS_11B;
  526. }
  527. psta->wireless_mode = sta_band;
  528. psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
  529. if (psta->aid < NUM_STA) {
  530. RTW_INFO("%s=> mac_id:%d , raid:%d, tx_ra_bitmap:0x%016llx, networkType:0x%02x\n",
  531. __FUNCTION__, psta->mac_id, psta->raid, tx_ra_bitmap, psta->wireless_mode);
  532. rtw_update_ramask(padapter, psta, psta->mac_id, rssi_level, is_update_bw);
  533. } else
  534. RTW_INFO("station aid %d exceed the max number\n", psta->aid);
  535. }
  536. void update_bmc_sta(_adapter *padapter)
  537. {
  538. _irqL irqL;
  539. unsigned char network_type;
  540. int supportRateNum = 0;
  541. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  542. WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  543. struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
  544. if (psta) {
  545. psta->aid = 0;/* default set to 0 */
  546. psta->qos_option = 0;
  547. #ifdef CONFIG_80211N_HT
  548. psta->htpriv.ht_option = _FALSE;
  549. #endif /* CONFIG_80211N_HT */
  550. psta->ieee8021x_blocked = 0;
  551. _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  552. /* psta->dot118021XPrivacy = _NO_PRIVACY_; */ /* !!! remove it, because it has been set before this. */
  553. /* prepare for add_RATid */
  554. supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
  555. network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, pcur_network->Configuration.DSConfig);
  556. if (IsSupportedTxCCK(network_type))
  557. network_type = WIRELESS_11B;
  558. else if (network_type == WIRELESS_INVALID) { /* error handling */
  559. if (pcur_network->Configuration.DSConfig > 14)
  560. network_type = WIRELESS_11A;
  561. else
  562. network_type = WIRELESS_11B;
  563. }
  564. update_sta_basic_rate(psta, network_type);
  565. psta->wireless_mode = network_type;
  566. rtw_hal_update_sta_rate_mask(padapter, psta);
  567. psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
  568. _enter_critical_bh(&psta->lock, &irqL);
  569. psta->state = _FW_LINKED;
  570. _exit_critical_bh(&psta->lock, &irqL);
  571. rtw_sta_media_status_rpt(padapter, psta, 1);
  572. rtw_hal_update_ra_mask(psta, psta->rssi_level, _TRUE);
  573. } else
  574. RTW_INFO("add_RATid_bmc_sta error!\n");
  575. }
  576. /* notes:
  577. * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
  578. void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
  579. {
  580. _irqL irqL;
  581. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  582. struct security_priv *psecuritypriv = &padapter->securitypriv;
  583. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  584. #ifdef CONFIG_80211N_HT
  585. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  586. struct ht_priv *phtpriv_sta = &psta->htpriv;
  587. #endif /* CONFIG_80211N_HT */
  588. u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0;
  589. /* set intf_tag to if1 */
  590. /* psta->intf_tag = 0; */
  591. RTW_INFO("%s\n", __FUNCTION__);
  592. /*alloc macid when call rtw_alloc_stainfo(),release macid when call rtw_free_stainfo()*/
  593. /* ap mode */
  594. rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _TRUE);
  595. if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
  596. psta->ieee8021x_blocked = _TRUE;
  597. else
  598. psta->ieee8021x_blocked = _FALSE;
  599. /* update sta's cap */
  600. /* ERP */
  601. VCS_update(padapter, psta);
  602. #ifdef CONFIG_80211N_HT
  603. /* HT related cap */
  604. if (phtpriv_sta->ht_option) {
  605. /* check if sta supports rx ampdu */
  606. phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
  607. phtpriv_sta->rx_ampdu_min_spacing = (phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
  608. /* bwmode */
  609. if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
  610. psta->bw_mode = CHANNEL_WIDTH_40;
  611. else
  612. psta->bw_mode = CHANNEL_WIDTH_20;
  613. if (psta->ht_40mhz_intolerant)
  614. psta->bw_mode = CHANNEL_WIDTH_20;
  615. if (pmlmeext->cur_bwmode < psta->bw_mode)
  616. psta->bw_mode = pmlmeext->cur_bwmode;
  617. phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
  618. /* check if sta support s Short GI 20M */
  619. if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
  620. phtpriv_sta->sgi_20m = _TRUE;
  621. /* check if sta support s Short GI 40M */
  622. if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) {
  623. if (psta->bw_mode == CHANNEL_WIDTH_40) /* according to psta->bw_mode */
  624. phtpriv_sta->sgi_40m = _TRUE;
  625. else
  626. phtpriv_sta->sgi_40m = _FALSE;
  627. }
  628. psta->qos_option = _TRUE;
  629. /* B0 Config LDPC Coding Capability */
  630. if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) &&
  631. GET_HT_CAP_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
  632. SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
  633. RTW_INFO("Enable HT Tx LDPC for STA(%d)\n", psta->aid);
  634. }
  635. /* B7 B8 B9 Config STBC setting */
  636. if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) &&
  637. GET_HT_CAP_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) {
  638. SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
  639. RTW_INFO("Enable HT Tx STBC for STA(%d)\n", psta->aid);
  640. }
  641. #ifdef CONFIG_BEAMFORMING
  642. /*Config Tx beamforming setting*/
  643. if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
  644. GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
  645. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
  646. /*Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
  647. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 6);
  648. }
  649. if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
  650. GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
  651. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
  652. /*Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
  653. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 4);
  654. }
  655. if (cur_beamform_cap)
  656. RTW_INFO("Client STA(%d) HT Beamforming Cap = 0x%02X\n", psta->aid, cur_beamform_cap);
  657. #endif /*CONFIG_BEAMFORMING*/
  658. } else {
  659. phtpriv_sta->ampdu_enable = _FALSE;
  660. phtpriv_sta->sgi_20m = _FALSE;
  661. phtpriv_sta->sgi_40m = _FALSE;
  662. psta->bw_mode = CHANNEL_WIDTH_20;
  663. phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  664. }
  665. phtpriv_sta->ldpc_cap = cur_ldpc_cap;
  666. phtpriv_sta->stbc_cap = cur_stbc_cap;
  667. phtpriv_sta->beamform_cap = cur_beamform_cap;
  668. /* Rx AMPDU */
  669. send_delba(padapter, 0, psta->hwaddr);/* recipient */
  670. /* TX AMPDU */
  671. send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
  672. phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
  673. phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
  674. #endif /* CONFIG_80211N_HT */
  675. #ifdef CONFIG_80211AC_VHT
  676. update_sta_vht_info_apmode(padapter, psta);
  677. #endif
  678. update_ldpc_stbc_cap(psta);
  679. /* todo: init other variables */
  680. _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  681. /* add ratid */
  682. /* add_RATid(padapter, psta); */ /* move to ap_sta_info_defer_update() */
  683. _enter_critical_bh(&psta->lock, &irqL);
  684. psta->state |= _FW_LINKED;
  685. _exit_critical_bh(&psta->lock, &irqL);
  686. }
  687. static void update_ap_info(_adapter *padapter, struct sta_info *psta)
  688. {
  689. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  690. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  691. struct security_priv *psecuritypriv = &padapter->securitypriv;
  692. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  693. #ifdef CONFIG_80211N_HT
  694. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  695. #endif /* CONFIG_80211N_HT */
  696. psta->wireless_mode = pmlmeext->cur_wireless_mode;
  697. psta->bssratelen = rtw_get_rateset_len(pnetwork->SupportedRates);
  698. _rtw_memcpy(psta->bssrateset, pnetwork->SupportedRates, psta->bssratelen);
  699. #ifdef CONFIG_80211N_HT
  700. /* HT related cap */
  701. if (phtpriv_ap->ht_option) {
  702. /* check if sta supports rx ampdu */
  703. /* phtpriv_ap->ampdu_enable = phtpriv_ap->ampdu_enable; */
  704. /* check if sta support s Short GI 20M */
  705. if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
  706. phtpriv_ap->sgi_20m = _TRUE;
  707. /* check if sta support s Short GI 40M */
  708. if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40))
  709. phtpriv_ap->sgi_40m = _TRUE;
  710. psta->qos_option = _TRUE;
  711. } else {
  712. phtpriv_ap->ampdu_enable = _FALSE;
  713. phtpriv_ap->sgi_20m = _FALSE;
  714. phtpriv_ap->sgi_40m = _FALSE;
  715. }
  716. psta->bw_mode = pmlmeext->cur_bwmode;
  717. phtpriv_ap->ch_offset = pmlmeext->cur_ch_offset;
  718. phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */
  719. phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */
  720. _rtw_memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv));
  721. #ifdef CONFIG_80211AC_VHT
  722. _rtw_memcpy(&psta->vhtpriv, &pmlmepriv->vhtpriv, sizeof(struct vht_priv));
  723. #endif /* CONFIG_80211AC_VHT */
  724. #endif /* CONFIG_80211N_HT */
  725. psta->state |= WIFI_AP_STATE; /* Aries, add,fix bug of flush_cam_entry at STOP AP mode , 0724 */
  726. }
  727. static void rtw_set_hw_wmm_param(_adapter *padapter)
  728. {
  729. u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
  730. u8 acm_mask;
  731. u16 TXOP;
  732. u32 acParm, i;
  733. u32 edca[4], inx[4];
  734. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  735. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  736. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  737. struct registry_priv *pregpriv = &padapter->registrypriv;
  738. acm_mask = 0;
  739. if (is_supported_5g(pmlmeext->cur_wireless_mode) ||
  740. (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
  741. aSifsTime = 16;
  742. else
  743. aSifsTime = 10;
  744. if (pmlmeinfo->WMM_enable == 0) {
  745. padapter->mlmepriv.acm_mask = 0;
  746. AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
  747. if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11A)) {
  748. ECWMin = 4;
  749. ECWMax = 10;
  750. } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
  751. ECWMin = 5;
  752. ECWMax = 10;
  753. } else {
  754. ECWMin = 4;
  755. ECWMax = 10;
  756. }
  757. TXOP = 0;
  758. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  759. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  760. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  761. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  762. ECWMin = 2;
  763. ECWMax = 3;
  764. TXOP = 0x2f;
  765. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  766. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  767. } else {
  768. edca[0] = edca[1] = edca[2] = edca[3] = 0;
  769. /*TODO:*/
  770. acm_mask = 0;
  771. padapter->mlmepriv.acm_mask = acm_mask;
  772. #if 0
  773. /* BK */
  774. /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
  775. #endif
  776. AIFS = (7 * pmlmeinfo->slotTime) + aSifsTime;
  777. ECWMin = 4;
  778. ECWMax = 10;
  779. TXOP = 0;
  780. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  781. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  782. edca[XMIT_BK_QUEUE] = acParm;
  783. RTW_INFO("WMM(BK): %x\n", acParm);
  784. /* BE */
  785. AIFS = (3 * pmlmeinfo->slotTime) + aSifsTime;
  786. ECWMin = 4;
  787. ECWMax = 6;
  788. TXOP = 0;
  789. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  790. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  791. edca[XMIT_BE_QUEUE] = acParm;
  792. RTW_INFO("WMM(BE): %x\n", acParm);
  793. /* VI */
  794. AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
  795. ECWMin = 3;
  796. ECWMax = 4;
  797. TXOP = 94;
  798. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  799. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  800. edca[XMIT_VI_QUEUE] = acParm;
  801. RTW_INFO("WMM(VI): %x\n", acParm);
  802. /* VO */
  803. AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
  804. ECWMin = 2;
  805. ECWMax = 3;
  806. TXOP = 47;
  807. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  808. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  809. edca[XMIT_VO_QUEUE] = acParm;
  810. RTW_INFO("WMM(VO): %x\n", acParm);
  811. if (padapter->registrypriv.acm_method == 1)
  812. rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
  813. else
  814. padapter->mlmepriv.acm_mask = acm_mask;
  815. inx[0] = 0;
  816. inx[1] = 1;
  817. inx[2] = 2;
  818. inx[3] = 3;
  819. if (pregpriv->wifi_spec == 1) {
  820. u32 j, tmp, change_inx = _FALSE;
  821. /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
  822. for (i = 0 ; i < 4 ; i++) {
  823. for (j = i + 1 ; j < 4 ; j++) {
  824. /* compare CW and AIFS */
  825. if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
  826. change_inx = _TRUE;
  827. else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
  828. /* compare TXOP */
  829. if ((edca[j] >> 16) > (edca[i] >> 16))
  830. change_inx = _TRUE;
  831. }
  832. if (change_inx) {
  833. tmp = edca[i];
  834. edca[i] = edca[j];
  835. edca[j] = tmp;
  836. tmp = inx[i];
  837. inx[i] = inx[j];
  838. inx[j] = tmp;
  839. change_inx = _FALSE;
  840. }
  841. }
  842. }
  843. }
  844. for (i = 0 ; i < 4 ; i++) {
  845. pxmitpriv->wmm_para_seq[i] = inx[i];
  846. RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
  847. }
  848. }
  849. }
  850. static void update_hw_ht_param(_adapter *padapter)
  851. {
  852. unsigned char max_AMPDU_len;
  853. unsigned char min_MPDU_spacing;
  854. struct registry_priv *pregpriv = &padapter->registrypriv;
  855. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  856. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  857. RTW_INFO("%s\n", __FUNCTION__);
  858. /* handle A-MPDU parameter field */
  859. /*
  860. AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
  861. AMPDU_para [4:2]:Min MPDU Start Spacing
  862. */
  863. max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
  864. min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
  865. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
  866. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
  867. /* */
  868. /* Config SM Power Save setting */
  869. /* */
  870. pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
  871. if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC) {
  872. #if 0
  873. u8 i;
  874. /* update the MCS rates */
  875. for (i = 0; i < 16; i++)
  876. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  877. #endif
  878. RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __FUNCTION__);
  879. }
  880. /* */
  881. /* Config current HT Protection mode. */
  882. /* */
  883. /* pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3; */
  884. }
  885. static void rtw_ap_check_scan(_adapter *padapter)
  886. {
  887. _irqL irqL;
  888. _list *plist, *phead;
  889. u32 delta_time, lifetime;
  890. struct wlan_network *pnetwork = NULL;
  891. WLAN_BSSID_EX *pbss = NULL;
  892. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  893. _queue *queue = &(pmlmepriv->scanned_queue);
  894. u8 do_scan = _FALSE;
  895. u8 reason = RTW_AUTO_SCAN_REASON_UNSPECIFIED;
  896. lifetime = SCANQUEUE_LIFETIME; /* 20 sec */
  897. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  898. phead = get_list_head(queue);
  899. if (rtw_end_of_queue_search(phead, get_next(phead)) == _TRUE)
  900. if (padapter->registrypriv.wifi_spec) {
  901. do_scan = _TRUE;
  902. reason |= RTW_AUTO_SCAN_REASON_2040_BSS;
  903. }
  904. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  905. #ifdef CONFIG_AUTO_CHNL_SEL_NHM
  906. if (padapter->registrypriv.acs_auto_scan) {
  907. do_scan = _TRUE;
  908. reason |= RTW_AUTO_SCAN_REASON_ACS;
  909. rtw_acs_start(padapter, _TRUE);
  910. }
  911. #endif
  912. if (_TRUE == do_scan) {
  913. RTW_INFO("%s : drv scans by itself and wait_completed\n", __func__);
  914. rtw_drv_scan_by_self(padapter, reason);
  915. rtw_scan_wait_completed(padapter);
  916. }
  917. #ifdef CONFIG_AUTO_CHNL_SEL_NHM
  918. if (padapter->registrypriv.acs_auto_scan)
  919. rtw_acs_start(padapter, _FALSE);
  920. #endif
  921. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  922. phead = get_list_head(queue);
  923. plist = get_next(phead);
  924. while (1) {
  925. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  926. break;
  927. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  928. if (rtw_chset_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0
  929. && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig) == _TRUE
  930. && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))) {
  931. delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
  932. if (delta_time < lifetime) {
  933. uint ie_len = 0;
  934. u8 *pbuf = NULL;
  935. u8 *ie = NULL;
  936. pbss = &pnetwork->network;
  937. ie = pbss->IEs;
  938. /*check if HT CAP INFO IE exists or not*/
  939. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss->IELength - _BEACON_IE_OFFSET_));
  940. if (pbuf == NULL) {
  941. /* HT CAP INFO IE don't exist, it is b/g mode bss.*/
  942. if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc))
  943. ATOMIC_SET(&pmlmepriv->olbc, _TRUE);
  944. if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc_ht))
  945. ATOMIC_SET(&pmlmepriv->olbc_ht, _TRUE);
  946. if (padapter->registrypriv.wifi_spec)
  947. RTW_INFO("%s: %s is a/b/g ap\n", __func__, pnetwork->network.Ssid.Ssid);
  948. }
  949. }
  950. }
  951. plist = get_next(plist);
  952. }
  953. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  954. pmlmepriv->num_sta_no_ht = 0; /* reset to 0 after ap do scanning*/
  955. }
  956. void rtw_start_bss_hdl_after_chbw_decided(_adapter *adapter)
  957. {
  958. WLAN_BSSID_EX *pnetwork = &(adapter->mlmepriv.cur_network.network);
  959. struct sta_info *sta = NULL;
  960. /* update cur_wireless_mode */
  961. update_wireless_mode(adapter);
  962. /* update RRSR and RTS_INIT_RATE register after set channel and bandwidth */
  963. UpdateBrateTbl(adapter, pnetwork->SupportedRates);
  964. rtw_hal_set_hwreg(adapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
  965. /* update capability after cur_wireless_mode updated */
  966. update_capinfo(adapter, rtw_get_capability(pnetwork));
  967. /* update bc/mc sta_info */
  968. update_bmc_sta(adapter);
  969. /* update AP's sta info */
  970. sta = rtw_get_stainfo(&adapter->stapriv, pnetwork->MacAddress);
  971. if (!sta) {
  972. RTW_INFO(FUNC_ADPT_FMT" !sta for macaddr="MAC_FMT"\n", FUNC_ADPT_ARG(adapter), MAC_ARG(pnetwork->MacAddress));
  973. rtw_warn_on(1);
  974. return;
  975. }
  976. update_ap_info(adapter, sta);
  977. }
  978. void start_bss_network(_adapter *padapter, struct createbss_parm *parm)
  979. {
  980. #define DUMP_ADAPTERS_STATUS 0
  981. u8 val8;
  982. u16 bcn_interval;
  983. u32 acparm;
  984. struct registry_priv *pregpriv = &padapter->registrypriv;
  985. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  986. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  987. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network; /* used as input */
  988. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  989. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  990. WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
  991. struct dvobj_priv *pdvobj = padapter->dvobj;
  992. s16 req_ch = -1, req_bw = -1, req_offset = -1;
  993. bool ch_setting_changed = _FALSE;
  994. u8 ch_to_set = 0, bw_to_set, offset_to_set;
  995. u8 doiqk = _FALSE;
  996. /* use for check ch bw offset can be allowed or not */
  997. u8 chbw_allow = _TRUE;
  998. if (parm->req_ch != 0) {
  999. /* bypass other setting, go checking ch, bw, offset */
  1000. req_ch = parm->req_ch;
  1001. req_bw = parm->req_bw;
  1002. req_offset = parm->req_offset;
  1003. goto chbw_decision;
  1004. } else {
  1005. /* inform this request comes from upper layer */
  1006. req_ch = 0;
  1007. }
  1008. bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
  1009. /* check if there is wps ie, */
  1010. /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
  1011. /* and at first time the security ie ( RSN/WPA IE) will not include in beacon. */
  1012. if (NULL == rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
  1013. pmlmeext->bstart_bss = _TRUE;
  1014. /* todo: update wmm, ht cap */
  1015. /* pmlmeinfo->WMM_enable; */
  1016. /* pmlmeinfo->HT_enable; */
  1017. if (pmlmepriv->qospriv.qos_option)
  1018. pmlmeinfo->WMM_enable = _TRUE;
  1019. #ifdef CONFIG_80211N_HT
  1020. if (pmlmepriv->htpriv.ht_option) {
  1021. pmlmeinfo->WMM_enable = _TRUE;
  1022. pmlmeinfo->HT_enable = _TRUE;
  1023. /* pmlmeinfo->HT_info_enable = _TRUE; */
  1024. /* pmlmeinfo->HT_caps_enable = _TRUE; */
  1025. update_hw_ht_param(padapter);
  1026. }
  1027. #endif /* #CONFIG_80211N_HT */
  1028. #ifdef CONFIG_80211AC_VHT
  1029. if (pmlmepriv->vhtpriv.vht_option) {
  1030. pmlmeinfo->VHT_enable = _TRUE;
  1031. update_hw_vht_param(padapter);
  1032. }
  1033. #endif /* CONFIG_80211AC_VHT */
  1034. if (pmlmepriv->cur_network.join_res != _TRUE) { /* setting only at first time */
  1035. /* WEP Key will be set before this function, do not clear CAM. */
  1036. if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_))
  1037. flush_all_cam_entry(padapter); /* clear CAM */
  1038. }
  1039. /* set MSR to AP_Mode */
  1040. Set_MSR(padapter, _HW_STATE_AP_);
  1041. /* Set BSSID REG */
  1042. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
  1043. /* Set EDCA param reg */
  1044. #ifdef CONFIG_CONCURRENT_MODE
  1045. acparm = 0x005ea42b;
  1046. #else
  1047. acparm = 0x002F3217; /* VO */
  1048. #endif
  1049. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
  1050. acparm = 0x005E4317; /* VI */
  1051. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
  1052. /* acparm = 0x00105320; */ /* BE */
  1053. acparm = 0x005ea42b;
  1054. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
  1055. acparm = 0x0000A444; /* BK */
  1056. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
  1057. /* Set Security */
  1058. val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
  1059. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
  1060. /* Beacon Control related register */
  1061. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
  1062. chbw_decision:
  1063. ch_setting_changed = rtw_ap_chbw_decision(padapter, req_ch, req_bw, req_offset
  1064. , &ch_to_set, &bw_to_set, &offset_to_set, &chbw_allow);
  1065. /* let pnetwork_mlmeext == pnetwork_mlme. */
  1066. _rtw_memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
  1067. rtw_start_bss_hdl_after_chbw_decided(padapter);
  1068. #if defined(CONFIG_DFS_MASTER)
  1069. rtw_dfs_master_status_apply(padapter, MLME_AP_STARTED);
  1070. #endif
  1071. #ifdef CONFIG_MCC_MODE
  1072. if (MCC_EN(padapter)) {
  1073. /*
  1074. * due to check under rtw_ap_chbw_decision
  1075. * if under MCC mode, means req channel setting is the same as current channel setting
  1076. * if not under MCC mode, mean req channel setting is not the same as current channel setting
  1077. */
  1078. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)) {
  1079. RTW_INFO(FUNC_ADPT_FMT": req channel setting is the same as current channel setting, go to update BCN\n"
  1080. , FUNC_ADPT_ARG(padapter));
  1081. goto update_beacon;
  1082. }
  1083. }
  1084. /* issue null data to AP for all interface connecting to AP before switch channel setting for softap */
  1085. rtw_hal_mcc_issue_null_data(padapter, chbw_allow, 1);
  1086. #endif /* CONFIG_MCC_MODE */
  1087. doiqk = _TRUE;
  1088. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  1089. if (ch_to_set != 0) {
  1090. set_channel_bwmode(padapter, ch_to_set, offset_to_set, bw_to_set);
  1091. rtw_mi_update_union_chan_inf(padapter, ch_to_set, offset_to_set, bw_to_set);
  1092. }
  1093. doiqk = _FALSE;
  1094. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  1095. #ifdef CONFIG_MCC_MODE
  1096. /* after set_channel_bwmode for backup IQK */
  1097. rtw_hal_set_mcc_setting_start_bss_network(padapter, chbw_allow);
  1098. #endif
  1099. if (DUMP_ADAPTERS_STATUS) {
  1100. RTW_INFO(FUNC_ADPT_FMT" done\n", FUNC_ADPT_ARG(padapter));
  1101. dump_adapters_status(RTW_DBGDUMP , adapter_to_dvobj(padapter));
  1102. }
  1103. update_beacon:
  1104. /* update beacon content only if bstart_bss is _TRUE */
  1105. if (_TRUE == pmlmeext->bstart_bss) {
  1106. _irqL irqL;
  1107. if ((ATOMIC_READ(&pmlmepriv->olbc) == _TRUE) || (ATOMIC_READ(&pmlmepriv->olbc_ht) == _TRUE)) {
  1108. /* AP is not starting a 40 MHz BSS in presence of an 802.11g BSS. */
  1109. pmlmepriv->ht_op_mode &= (~HT_INFO_OPERATION_MODE_OP_MODE_MASK);
  1110. pmlmepriv->ht_op_mode |= OP_MODE_MAY_BE_LEGACY_STAS;
  1111. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
  1112. }
  1113. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  1114. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  1115. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  1116. if (rtw_is_list_empty(&padapter->list)) {
  1117. rtw_list_insert_tail(&padapter->list, get_list_head(&pdvobj->ap_if_q));
  1118. pdvobj->nr_ap_if++;
  1119. pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
  1120. }
  1121. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  1122. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
  1123. #endif /*CONFIG_SWTIMER_BASED_TXBCN*/
  1124. }
  1125. rtw_scan_wait_completed(padapter);
  1126. /* send beacon */
  1127. if (!rtw_mi_check_fwstate(padapter, _FW_UNDER_SURVEY)) {
  1128. /*update_beacon(padapter, _TIM_IE_, NULL, _TRUE);*/
  1129. #if !defined(CONFIG_INTERRUPT_BASED_TXBCN)
  1130. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1131. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  1132. if (pdvobj->nr_ap_if == 1) {
  1133. RTW_INFO("start SW BCN TIMER!\n");
  1134. _set_timer(&pdvobj->txbcn_timer, bcn_interval);
  1135. }
  1136. #else
  1137. /* other case will tx beacon when bcn interrupt coming in. */
  1138. if (send_beacon(padapter) == _FAIL)
  1139. RTW_INFO("issue_beacon, fail!\n");
  1140. #endif
  1141. #endif
  1142. #endif /* !defined(CONFIG_INTERRUPT_BASED_TXBCN) */
  1143. }
  1144. /*Set EDCA param reg after update cur_wireless_mode & update_capinfo*/
  1145. if (pregpriv->wifi_spec == 1)
  1146. rtw_set_hw_wmm_param(padapter);
  1147. /*pmlmeext->bstart_bss = _TRUE;*/
  1148. }
  1149. int rtw_check_beacon_data(_adapter *padapter, u8 *pbuf, int len)
  1150. {
  1151. int ret = _SUCCESS;
  1152. u8 *p;
  1153. u8 *pHT_caps_ie = NULL;
  1154. u8 *pHT_info_ie = NULL;
  1155. u16 cap, ht_cap = _FALSE;
  1156. uint ie_len = 0;
  1157. int group_cipher, pairwise_cipher;
  1158. u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
  1159. int supportRateNum = 0;
  1160. u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
  1161. u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
  1162. u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
  1163. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1164. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1165. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1166. WLAN_BSSID_EX *pbss_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  1167. struct sta_priv *pstapriv = &padapter->stapriv;
  1168. u8 *ie = pbss_network->IEs;
  1169. u8 vht_cap = _FALSE;
  1170. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1171. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1172. u8 rf_num = 0;
  1173. /* SSID */
  1174. /* Supported rates */
  1175. /* DS Params */
  1176. /* WLAN_EID_COUNTRY */
  1177. /* ERP Information element */
  1178. /* Extended supported rates */
  1179. /* WPA/WPA2 */
  1180. /* Wi-Fi Wireless Multimedia Extensions */
  1181. /* ht_capab, ht_oper */
  1182. /* WPS IE */
  1183. RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
  1184. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  1185. return _FAIL;
  1186. if (len > MAX_IE_SZ)
  1187. return _FAIL;
  1188. pbss_network->IELength = len;
  1189. _rtw_memset(ie, 0, MAX_IE_SZ);
  1190. _rtw_memcpy(ie, pbuf, pbss_network->IELength);
  1191. if (pbss_network->InfrastructureMode != Ndis802_11APMode)
  1192. return _FAIL;
  1193. rtw_ap_check_scan(padapter);
  1194. pbss_network->Rssi = 0;
  1195. _rtw_memcpy(pbss_network->MacAddress, adapter_mac_addr(padapter), ETH_ALEN);
  1196. /* beacon interval */
  1197. p = rtw_get_beacon_interval_from_ie(ie);/* ie + 8; */ /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
  1198. /* pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p); */
  1199. pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
  1200. /* capability */
  1201. /* cap = *(unsigned short *)rtw_get_capability_from_ie(ie); */
  1202. /* cap = le16_to_cpu(cap); */
  1203. cap = RTW_GET_LE16(ie);
  1204. /* SSID */
  1205. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1206. if (p && ie_len > 0) {
  1207. _rtw_memset(&pbss_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
  1208. _rtw_memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
  1209. pbss_network->Ssid.SsidLength = ie_len;
  1210. #ifdef CONFIG_P2P
  1211. _rtw_memcpy(padapter->wdinfo.p2p_group_ssid, pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
  1212. padapter->wdinfo.p2p_group_ssid_len = pbss_network->Ssid.SsidLength;
  1213. #endif
  1214. }
  1215. /* chnnel */
  1216. channel = 0;
  1217. pbss_network->Configuration.Length = 0;
  1218. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1219. if (p && ie_len > 0)
  1220. channel = *(p + 2);
  1221. pbss_network->Configuration.DSConfig = channel;
  1222. _rtw_memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
  1223. /* get supported rates */
  1224. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1225. if (p != NULL) {
  1226. _rtw_memcpy(supportRate, p + 2, ie_len);
  1227. supportRateNum = ie_len;
  1228. }
  1229. /* get ext_supported rates */
  1230. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);
  1231. if (p != NULL) {
  1232. _rtw_memcpy(supportRate + supportRateNum, p + 2, ie_len);
  1233. supportRateNum += ie_len;
  1234. }
  1235. network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
  1236. rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
  1237. /* parsing ERP_IE */
  1238. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1239. if (p && ie_len > 0)
  1240. ERP_IE_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
  1241. /* update privacy/security */
  1242. if (cap & BIT(4))
  1243. pbss_network->Privacy = 1;
  1244. else
  1245. pbss_network->Privacy = 0;
  1246. psecuritypriv->wpa_psk = 0;
  1247. /* wpa2 */
  1248. group_cipher = 0;
  1249. pairwise_cipher = 0;
  1250. psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
  1251. psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
  1252. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1253. if (p && ie_len > 0) {
  1254. if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  1255. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  1256. psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
  1257. psecuritypriv->wpa_psk |= BIT(1);
  1258. psecuritypriv->wpa2_group_cipher = group_cipher;
  1259. psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
  1260. #if 0
  1261. switch (group_cipher) {
  1262. case WPA_CIPHER_NONE:
  1263. psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
  1264. break;
  1265. case WPA_CIPHER_WEP40:
  1266. psecuritypriv->wpa2_group_cipher = _WEP40_;
  1267. break;
  1268. case WPA_CIPHER_TKIP:
  1269. psecuritypriv->wpa2_group_cipher = _TKIP_;
  1270. break;
  1271. case WPA_CIPHER_CCMP:
  1272. psecuritypriv->wpa2_group_cipher = _AES_;
  1273. break;
  1274. case WPA_CIPHER_WEP104:
  1275. psecuritypriv->wpa2_group_cipher = _WEP104_;
  1276. break;
  1277. }
  1278. switch (pairwise_cipher) {
  1279. case WPA_CIPHER_NONE:
  1280. psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
  1281. break;
  1282. case WPA_CIPHER_WEP40:
  1283. psecuritypriv->wpa2_pairwise_cipher = _WEP40_;
  1284. break;
  1285. case WPA_CIPHER_TKIP:
  1286. psecuritypriv->wpa2_pairwise_cipher = _TKIP_;
  1287. break;
  1288. case WPA_CIPHER_CCMP:
  1289. psecuritypriv->wpa2_pairwise_cipher = _AES_;
  1290. break;
  1291. case WPA_CIPHER_WEP104:
  1292. psecuritypriv->wpa2_pairwise_cipher = _WEP104_;
  1293. break;
  1294. }
  1295. #endif
  1296. }
  1297. }
  1298. /* wpa */
  1299. ie_len = 0;
  1300. group_cipher = 0;
  1301. pairwise_cipher = 0;
  1302. psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
  1303. psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
  1304. for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
  1305. p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
  1306. if ((p) && (_rtw_memcmp(p + 2, OUI1, 4))) {
  1307. if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  1308. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  1309. psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
  1310. psecuritypriv->wpa_psk |= BIT(0);
  1311. psecuritypriv->wpa_group_cipher = group_cipher;
  1312. psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
  1313. #if 0
  1314. switch (group_cipher) {
  1315. case WPA_CIPHER_NONE:
  1316. psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
  1317. break;
  1318. case WPA_CIPHER_WEP40:
  1319. psecuritypriv->wpa_group_cipher = _WEP40_;
  1320. break;
  1321. case WPA_CIPHER_TKIP:
  1322. psecuritypriv->wpa_group_cipher = _TKIP_;
  1323. break;
  1324. case WPA_CIPHER_CCMP:
  1325. psecuritypriv->wpa_group_cipher = _AES_;
  1326. break;
  1327. case WPA_CIPHER_WEP104:
  1328. psecuritypriv->wpa_group_cipher = _WEP104_;
  1329. break;
  1330. }
  1331. switch (pairwise_cipher) {
  1332. case WPA_CIPHER_NONE:
  1333. psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
  1334. break;
  1335. case WPA_CIPHER_WEP40:
  1336. psecuritypriv->wpa_pairwise_cipher = _WEP40_;
  1337. break;
  1338. case WPA_CIPHER_TKIP:
  1339. psecuritypriv->wpa_pairwise_cipher = _TKIP_;
  1340. break;
  1341. case WPA_CIPHER_CCMP:
  1342. psecuritypriv->wpa_pairwise_cipher = _AES_;
  1343. break;
  1344. case WPA_CIPHER_WEP104:
  1345. psecuritypriv->wpa_pairwise_cipher = _WEP104_;
  1346. break;
  1347. }
  1348. #endif
  1349. }
  1350. break;
  1351. }
  1352. if ((p == NULL) || (ie_len == 0))
  1353. break;
  1354. }
  1355. /* wmm */
  1356. ie_len = 0;
  1357. pmlmepriv->qospriv.qos_option = 0;
  1358. if (pregistrypriv->wmm_enable) {
  1359. for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
  1360. p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
  1361. if ((p) && _rtw_memcmp(p + 2, WMM_PARA_IE, 6)) {
  1362. pmlmepriv->qospriv.qos_option = 1;
  1363. *(p + 8) |= BIT(7); /* QoS Info, support U-APSD */
  1364. /* disable all ACM bits since the WMM admission control is not supported */
  1365. *(p + 10) &= ~BIT(4); /* BE */
  1366. *(p + 14) &= ~BIT(4); /* BK */
  1367. *(p + 18) &= ~BIT(4); /* VI */
  1368. *(p + 22) &= ~BIT(4); /* VO */
  1369. break;
  1370. }
  1371. if ((p == NULL) || (ie_len == 0))
  1372. break;
  1373. }
  1374. }
  1375. #ifdef CONFIG_80211N_HT
  1376. /* parsing HT_CAP_IE */
  1377. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1378. if (p && ie_len > 0) {
  1379. u8 rf_type = 0;
  1380. HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor = MAX_AMPDU_FACTOR_64K;
  1381. struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
  1382. if (0) {
  1383. RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE from upper layer:\n", FUNC_ADPT_ARG(padapter));
  1384. dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
  1385. }
  1386. pHT_caps_ie = p;
  1387. ht_cap = _TRUE;
  1388. network_type |= WIRELESS_11_24N;
  1389. rtw_ht_use_default_setting(padapter);
  1390. /* Update HT Capabilities Info field */
  1391. if (pmlmepriv->htpriv.sgi_20m == _FALSE)
  1392. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_20);
  1393. if (pmlmepriv->htpriv.sgi_40m == _FALSE)
  1394. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_40);
  1395. if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX))
  1396. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_LDPC_CODING);
  1397. if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
  1398. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_TX_STBC);
  1399. if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX))
  1400. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_RX_STBC_3R);
  1401. /* Update A-MPDU Parameters field */
  1402. pht_cap->ampdu_params_info &= ~(IEEE80211_HT_CAP_AMPDU_FACTOR | IEEE80211_HT_CAP_AMPDU_DENSITY);
  1403. if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
  1404. (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
  1405. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (0x07 << 2));
  1406. else
  1407. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
  1408. rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
  1409. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & max_rx_ampdu_factor); /* set Max Rx AMPDU size to 64K */
  1410. _rtw_memcpy(&(pmlmeinfo->HT_caps), pht_cap, sizeof(struct HT_caps_element));
  1411. /* Update Supported MCS Set field */
  1412. {
  1413. struct hal_spec_t *hal_spec = GET_HAL_SPEC(padapter);
  1414. u8 rx_nss = 0;
  1415. int i;
  1416. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  1417. rx_nss = rtw_min(rf_type_to_rf_rx_cnt(rf_type), hal_spec->rx_nss_num);
  1418. /* RX MCS Bitmask */
  1419. switch (rx_nss) {
  1420. case 1:
  1421. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_1R);
  1422. break;
  1423. case 2:
  1424. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_2R);
  1425. break;
  1426. case 3:
  1427. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_3R);
  1428. break;
  1429. case 4:
  1430. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_4R);
  1431. break;
  1432. default:
  1433. RTW_WARN("rf_type:%d or rx_nss:%u is not expected\n", rf_type, hal_spec->rx_nss_num);
  1434. }
  1435. for (i = 0; i < 10; i++)
  1436. *(HT_CAP_ELE_RX_MCS_MAP(pht_cap) + i) &= padapter->mlmeextpriv.default_supported_mcs_set[i];
  1437. }
  1438. #ifdef CONFIG_BEAMFORMING
  1439. /* Use registry value to enable HT Beamforming. */
  1440. /* ToDo: use configure file to set these capability. */
  1441. pht_cap->tx_BF_cap_info = 0;
  1442. /* HT Beamformer */
  1443. if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
  1444. /* Transmit NDP Capable */
  1445. SET_HT_CAP_TXBF_TRANSMIT_NDP_CAP(pht_cap, 1);
  1446. /* Explicit Compressed Steering Capable */
  1447. SET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pht_cap, 1);
  1448. /* Compressed Steering Number Antennas */
  1449. SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, 1);
  1450. rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMER_CAP, (u8 *)&rf_num);
  1451. SET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pht_cap, rf_num);
  1452. }
  1453. /* HT Beamformee */
  1454. if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
  1455. /* Receive NDP Capable */
  1456. SET_HT_CAP_TXBF_RECEIVE_NDP_CAP(pht_cap, 1);
  1457. /* Explicit Compressed Beamforming Feedback Capable */
  1458. SET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pht_cap, 2);
  1459. rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMEE_CAP, (u8 *)&rf_num);
  1460. SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, rf_num);
  1461. }
  1462. #endif /* CONFIG_BEAMFORMING */
  1463. _rtw_memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
  1464. if (0) {
  1465. RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE driver masked:\n", FUNC_ADPT_ARG(padapter));
  1466. dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
  1467. }
  1468. }
  1469. /* parsing HT_INFO_IE */
  1470. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1471. if (p && ie_len > 0)
  1472. pHT_info_ie = p;
  1473. #endif /* CONFIG_80211N_HT */
  1474. switch (network_type) {
  1475. case WIRELESS_11B:
  1476. pbss_network->NetworkTypeInUse = Ndis802_11DS;
  1477. break;
  1478. case WIRELESS_11G:
  1479. case WIRELESS_11BG:
  1480. case WIRELESS_11G_24N:
  1481. case WIRELESS_11BG_24N:
  1482. pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
  1483. break;
  1484. case WIRELESS_11A:
  1485. pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
  1486. break;
  1487. default:
  1488. pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
  1489. break;
  1490. }
  1491. pmlmepriv->cur_network.network_type = network_type;
  1492. #ifdef CONFIG_80211N_HT
  1493. pmlmepriv->htpriv.ht_option = _FALSE;
  1494. if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
  1495. (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
  1496. /* todo: */
  1497. /* ht_cap = _FALSE; */
  1498. }
  1499. /* ht_cap */
  1500. if (pregistrypriv->ht_enable && ht_cap == _TRUE) {
  1501. pmlmepriv->htpriv.ht_option = _TRUE;
  1502. pmlmepriv->qospriv.qos_option = 1;
  1503. pmlmepriv->htpriv.ampdu_enable = pregistrypriv->ampdu_enable ? _TRUE : _FALSE;
  1504. HT_caps_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_caps_ie);
  1505. HT_info_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_info_ie);
  1506. }
  1507. #endif
  1508. #ifdef CONFIG_80211AC_VHT
  1509. /* Parsing VHT CAP IE */
  1510. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTCapability, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1511. if (p && ie_len > 0)
  1512. vht_cap = _TRUE;
  1513. /* Parsing VHT OPERATION IE */
  1514. pmlmepriv->vhtpriv.vht_option = _FALSE;
  1515. /* if channel in 5G band, then add vht ie . */
  1516. if ((pbss_network->Configuration.DSConfig > 14)
  1517. && (pmlmepriv->htpriv.ht_option == _TRUE)
  1518. && REGSTY_IS_11AC_ENABLE(pregistrypriv)
  1519. && hal_chk_proto_cap(padapter, PROTO_CAP_11AC)
  1520. && (!pmlmepriv->country_ent || COUNTRY_CHPLAN_EN_11AC(pmlmepriv->country_ent))
  1521. ) {
  1522. if (vht_cap == _TRUE)
  1523. pmlmepriv->vhtpriv.vht_option = _TRUE;
  1524. else if (REGSTY_IS_11AC_AUTO(pregistrypriv)) {
  1525. u8 cap_len, operation_len;
  1526. rtw_vht_use_default_setting(padapter);
  1527. {
  1528. /* VHT Operation mode notifiy bit in Extended IE (127) */
  1529. uint len = 0;
  1530. SET_EXT_CAPABILITY_ELE_OP_MODE_NOTIF(pmlmepriv->ext_capab_ie_data, 1);
  1531. pmlmepriv->ext_capab_ie_len = 10;
  1532. rtw_set_ie(pbss_network->IEs + pbss_network->IELength, EID_EXTCapability, 8, pmlmepriv->ext_capab_ie_data, &len);
  1533. pbss_network->IELength += pmlmepriv->ext_capab_ie_len;
  1534. }
  1535. /* VHT Capabilities element */
  1536. cap_len = rtw_build_vht_cap_ie(padapter, pbss_network->IEs + pbss_network->IELength);
  1537. pbss_network->IELength += cap_len;
  1538. /* VHT Operation element */
  1539. operation_len = rtw_build_vht_operation_ie(padapter, pbss_network->IEs + pbss_network->IELength, pbss_network->Configuration.DSConfig);
  1540. pbss_network->IELength += operation_len;
  1541. pmlmepriv->vhtpriv.vht_option = _TRUE;
  1542. }
  1543. }
  1544. #endif /* CONFIG_80211AC_VHT */
  1545. if(pbss_network->Configuration.DSConfig <= 14 && padapter->registrypriv.wifi_spec == 1) {
  1546. uint len = 0;
  1547. SET_EXT_CAPABILITY_ELE_BSS_COEXIST(pmlmepriv->ext_capab_ie_data, 1);
  1548. pmlmepriv->ext_capab_ie_len = 10;
  1549. rtw_set_ie(pbss_network->IEs + pbss_network->IELength, EID_EXTCapability, 8, pmlmepriv->ext_capab_ie_data, &len);
  1550. pbss_network->IELength += pmlmepriv->ext_capab_ie_len;
  1551. }
  1552. pbss_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pbss_network);
  1553. rtw_ies_get_chbw(pbss_network->IEs + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_
  1554. , &pmlmepriv->ori_ch, &pmlmepriv->ori_bw, &pmlmepriv->ori_offset);
  1555. rtw_warn_on(pmlmepriv->ori_ch == 0);
  1556. {
  1557. /* alloc sta_info for ap itself */
  1558. struct sta_info *sta;
  1559. sta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
  1560. if (!sta) {
  1561. sta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
  1562. if (sta == NULL)
  1563. return _FAIL;
  1564. }
  1565. }
  1566. rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK);
  1567. {
  1568. int sk_band = RTW_GET_SCAN_BAND_SKIP(padapter);
  1569. if (sk_band)
  1570. RTW_CLR_SCAN_BAND_SKIP(padapter, sk_band);
  1571. }
  1572. rtw_indicate_connect(padapter);
  1573. pmlmepriv->cur_network.join_res = _TRUE;/* for check if already set beacon */
  1574. /* update bc/mc sta_info */
  1575. /* update_bmc_sta(padapter); */
  1576. return ret;
  1577. }
  1578. #if CONFIG_RTW_MACADDR_ACL
  1579. void rtw_macaddr_acl_init(_adapter *adapter)
  1580. {
  1581. struct sta_priv *stapriv = &adapter->stapriv;
  1582. struct wlan_acl_pool *acl = &stapriv->acl_list;
  1583. _queue *acl_node_q = &acl->acl_node_q;
  1584. int i;
  1585. _irqL irqL;
  1586. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  1587. _rtw_init_listhead(&(acl_node_q->queue));
  1588. acl->num = 0;
  1589. acl->mode = RTW_ACL_MODE_DISABLED;
  1590. for (i = 0; i < NUM_ACL; i++) {
  1591. _rtw_init_listhead(&acl->aclnode[i].list);
  1592. acl->aclnode[i].valid = _FALSE;
  1593. }
  1594. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  1595. }
  1596. void rtw_macaddr_acl_deinit(_adapter *adapter)
  1597. {
  1598. struct sta_priv *stapriv = &adapter->stapriv;
  1599. struct wlan_acl_pool *acl = &stapriv->acl_list;
  1600. _queue *acl_node_q = &acl->acl_node_q;
  1601. _irqL irqL;
  1602. _list *head, *list;
  1603. struct rtw_wlan_acl_node *acl_node;
  1604. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  1605. head = get_list_head(acl_node_q);
  1606. list = get_next(head);
  1607. while (rtw_end_of_queue_search(head, list) == _FALSE) {
  1608. acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
  1609. list = get_next(list);
  1610. if (acl_node->valid == _TRUE) {
  1611. acl_node->valid = _FALSE;
  1612. rtw_list_delete(&acl_node->list);
  1613. acl->num--;
  1614. }
  1615. }
  1616. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  1617. rtw_warn_on(acl->num);
  1618. acl->mode = RTW_ACL_MODE_DISABLED;
  1619. }
  1620. void rtw_set_macaddr_acl(_adapter *adapter, int mode)
  1621. {
  1622. struct sta_priv *stapriv = &adapter->stapriv;
  1623. struct wlan_acl_pool *acl = &stapriv->acl_list;
  1624. RTW_INFO(FUNC_ADPT_FMT" mode=%d\n", FUNC_ADPT_ARG(adapter), mode);
  1625. acl->mode = mode;
  1626. if (mode == RTW_ACL_MODE_DISABLED)
  1627. rtw_macaddr_acl_deinit(adapter);
  1628. }
  1629. int rtw_acl_add_sta(_adapter *adapter, const u8 *addr)
  1630. {
  1631. _irqL irqL;
  1632. _list *list, *head;
  1633. u8 existed = 0;
  1634. int i = -1, ret = 0;
  1635. struct rtw_wlan_acl_node *acl_node;
  1636. struct sta_priv *stapriv = &adapter->stapriv;
  1637. struct wlan_acl_pool *acl = &stapriv->acl_list;
  1638. _queue *acl_node_q = &acl->acl_node_q;
  1639. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  1640. head = get_list_head(acl_node_q);
  1641. list = get_next(head);
  1642. /* search for existed entry */
  1643. while (rtw_end_of_queue_search(head, list) == _FALSE) {
  1644. acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
  1645. list = get_next(list);
  1646. if (_rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
  1647. if (acl_node->valid == _TRUE) {
  1648. existed = 1;
  1649. break;
  1650. }
  1651. }
  1652. }
  1653. if (existed)
  1654. goto release_lock;
  1655. if (acl->num >= NUM_ACL)
  1656. goto release_lock;
  1657. /* find empty one and use */
  1658. for (i = 0; i < NUM_ACL; i++) {
  1659. acl_node = &acl->aclnode[i];
  1660. if (acl_node->valid == _FALSE) {
  1661. _rtw_init_listhead(&acl_node->list);
  1662. _rtw_memcpy(acl_node->addr, addr, ETH_ALEN);
  1663. acl_node->valid = _TRUE;
  1664. rtw_list_insert_tail(&acl_node->list, get_list_head(acl_node_q));
  1665. acl->num++;
  1666. break;
  1667. }
  1668. }
  1669. release_lock:
  1670. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  1671. if (!existed && (i < 0 || i >= NUM_ACL))
  1672. ret = -1;
  1673. RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
  1674. , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
  1675. , (existed ? "existed" : ((i < 0 || i >= NUM_ACL) ? "no room" : "added"))
  1676. , acl->num);
  1677. return ret;
  1678. }
  1679. int rtw_acl_remove_sta(_adapter *adapter, const u8 *addr)
  1680. {
  1681. _irqL irqL;
  1682. _list *list, *head;
  1683. int ret = 0;
  1684. struct rtw_wlan_acl_node *acl_node;
  1685. struct sta_priv *stapriv = &adapter->stapriv;
  1686. struct wlan_acl_pool *acl = &stapriv->acl_list;
  1687. _queue *acl_node_q = &acl->acl_node_q;
  1688. u8 is_baddr = is_broadcast_mac_addr(addr);
  1689. u8 match = 0;
  1690. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  1691. head = get_list_head(acl_node_q);
  1692. list = get_next(head);
  1693. while (rtw_end_of_queue_search(head, list) == _FALSE) {
  1694. acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
  1695. list = get_next(list);
  1696. if (is_baddr || _rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
  1697. if (acl_node->valid == _TRUE) {
  1698. acl_node->valid = _FALSE;
  1699. rtw_list_delete(&acl_node->list);
  1700. acl->num--;
  1701. match = 1;
  1702. }
  1703. }
  1704. }
  1705. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  1706. RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
  1707. , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
  1708. , is_baddr ? "clear all" : (match ? "match" : "no found")
  1709. , acl->num);
  1710. return ret;
  1711. }
  1712. #endif /* CONFIG_RTW_MACADDR_ACL */
  1713. u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
  1714. {
  1715. struct cmd_obj *ph2c;
  1716. struct set_stakey_parm *psetstakey_para;
  1717. struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
  1718. u8 res = _SUCCESS;
  1719. ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  1720. if (ph2c == NULL) {
  1721. res = _FAIL;
  1722. goto exit;
  1723. }
  1724. psetstakey_para = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
  1725. if (psetstakey_para == NULL) {
  1726. rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
  1727. res = _FAIL;
  1728. goto exit;
  1729. }
  1730. init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
  1731. psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy;
  1732. _rtw_memcpy(psetstakey_para->addr, psta->hwaddr, ETH_ALEN);
  1733. _rtw_memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
  1734. res = rtw_enqueue_cmd(pcmdpriv, ph2c);
  1735. exit:
  1736. return res;
  1737. }
  1738. static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
  1739. {
  1740. u8 keylen;
  1741. struct cmd_obj *pcmd;
  1742. struct setkey_parm *psetkeyparm;
  1743. struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
  1744. int res = _SUCCESS;
  1745. /* RTW_INFO("%s\n", __FUNCTION__); */
  1746. pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  1747. if (pcmd == NULL) {
  1748. res = _FAIL;
  1749. goto exit;
  1750. }
  1751. psetkeyparm = (struct setkey_parm *)rtw_zmalloc(sizeof(struct setkey_parm));
  1752. if (psetkeyparm == NULL) {
  1753. rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
  1754. res = _FAIL;
  1755. goto exit;
  1756. }
  1757. _rtw_memset(psetkeyparm, 0, sizeof(struct setkey_parm));
  1758. psetkeyparm->keyid = (u8)keyid;
  1759. if (is_wep_enc(alg))
  1760. padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
  1761. psetkeyparm->algorithm = alg;
  1762. psetkeyparm->set_tx = set_tx;
  1763. switch (alg) {
  1764. case _WEP40_:
  1765. keylen = 5;
  1766. break;
  1767. case _WEP104_:
  1768. keylen = 13;
  1769. break;
  1770. case _TKIP_:
  1771. case _TKIP_WTMIC_:
  1772. case _AES_:
  1773. default:
  1774. keylen = 16;
  1775. }
  1776. _rtw_memcpy(&(psetkeyparm->key[0]), key, keylen);
  1777. pcmd->cmdcode = _SetKey_CMD_;
  1778. pcmd->parmbuf = (u8 *)psetkeyparm;
  1779. pcmd->cmdsz = (sizeof(struct setkey_parm));
  1780. pcmd->rsp = NULL;
  1781. pcmd->rspsz = 0;
  1782. _rtw_init_listhead(&pcmd->list);
  1783. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  1784. exit:
  1785. return res;
  1786. }
  1787. int rtw_ap_set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
  1788. {
  1789. RTW_INFO("%s\n", __FUNCTION__);
  1790. return rtw_ap_set_key(padapter, key, alg, keyid, 1);
  1791. }
  1792. int rtw_ap_set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx)
  1793. {
  1794. u8 alg;
  1795. switch (keylen) {
  1796. case 5:
  1797. alg = _WEP40_;
  1798. break;
  1799. case 13:
  1800. alg = _WEP104_;
  1801. break;
  1802. default:
  1803. alg = _NO_PRIVACY_;
  1804. }
  1805. RTW_INFO("%s\n", __FUNCTION__);
  1806. return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
  1807. }
  1808. u8 rtw_ap_bmc_frames_hdl(_adapter *padapter)
  1809. {
  1810. #define HIQ_XMIT_COUNTS (6)
  1811. _irqL irqL;
  1812. struct sta_info *psta_bmc;
  1813. _list *xmitframe_plist, *xmitframe_phead;
  1814. struct xmit_frame *pxmitframe = NULL;
  1815. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1816. struct sta_priv *pstapriv = &padapter->stapriv;
  1817. bool update_tim = _FALSE;
  1818. if (padapter->registrypriv.wifi_spec != 1)
  1819. return H2C_SUCCESS;
  1820. psta_bmc = rtw_get_bcmc_stainfo(padapter);
  1821. if (!psta_bmc)
  1822. return H2C_SUCCESS;
  1823. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  1824. if ((pstapriv->tim_bitmap & BIT(0)) && (psta_bmc->sleepq_len > 0)) {
  1825. int tx_counts = 0;
  1826. _update_beacon(padapter, _TIM_IE_, NULL, _FALSE, "update TIM with TIB=1");
  1827. RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);
  1828. xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
  1829. xmitframe_plist = get_next(xmitframe_phead);
  1830. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
  1831. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  1832. xmitframe_plist = get_next(xmitframe_plist);
  1833. rtw_list_delete(&pxmitframe->list);
  1834. psta_bmc->sleepq_len--;
  1835. tx_counts++;
  1836. if (psta_bmc->sleepq_len > 0)
  1837. pxmitframe->attrib.mdata = 1;
  1838. else
  1839. pxmitframe->attrib.mdata = 0;
  1840. if (tx_counts == HIQ_XMIT_COUNTS)
  1841. pxmitframe->attrib.mdata = 0;
  1842. pxmitframe->attrib.triggered = 1;
  1843. if (xmitframe_hiq_filter(pxmitframe) == _TRUE)
  1844. pxmitframe->attrib.qsel = QSLT_HIGH;/*HIQ*/
  1845. rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
  1846. if (tx_counts == HIQ_XMIT_COUNTS)
  1847. break;
  1848. }
  1849. } else {
  1850. if (psta_bmc->sleepq_len == 0) {
  1851. /*RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);*/
  1852. if (pstapriv->tim_bitmap & BIT(0))
  1853. update_tim = _TRUE;
  1854. pstapriv->tim_bitmap &= ~BIT(0);
  1855. pstapriv->sta_dz_bitmap &= ~BIT(0);
  1856. if (update_tim == _TRUE) {
  1857. RTW_INFO("clear TIB\n");
  1858. _update_beacon(padapter, _TIM_IE_, NULL, _TRUE, "bmc sleepq and HIQ empty");
  1859. }
  1860. }
  1861. }
  1862. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  1863. #if 0
  1864. /* HIQ Check */
  1865. rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
  1866. while (_FALSE == empty && rtw_get_passing_time_ms(start) < 3000) {
  1867. rtw_msleep_os(100);
  1868. rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
  1869. }
  1870. printk("check if hiq empty=%d\n", empty);
  1871. #endif
  1872. return H2C_SUCCESS;
  1873. }
  1874. #ifdef CONFIG_NATIVEAP_MLME
  1875. static void associated_stainfo_update(_adapter *padapter, struct sta_info *psta, u32 sta_info_type)
  1876. {
  1877. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1878. RTW_INFO("%s: "MAC_FMT", updated_type=0x%x\n", __func__, MAC_ARG(psta->hwaddr), sta_info_type);
  1879. if (sta_info_type & STA_INFO_UPDATE_BW) {
  1880. if ((psta->flags & WLAN_STA_HT) && !psta->ht_20mhz_set) {
  1881. if (pmlmepriv->sw_to_20mhz) {
  1882. psta->bw_mode = CHANNEL_WIDTH_20;
  1883. /*psta->htpriv.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;*/
  1884. psta->htpriv.sgi_40m = _FALSE;
  1885. } else {
  1886. /*TODO: Switch back to 40MHZ?80MHZ*/
  1887. }
  1888. }
  1889. }
  1890. /*
  1891. if (sta_info_type & STA_INFO_UPDATE_RATE) {
  1892. }
  1893. */
  1894. if (sta_info_type & STA_INFO_UPDATE_PROTECTION_MODE)
  1895. VCS_update(padapter, psta);
  1896. /*
  1897. if (sta_info_type & STA_INFO_UPDATE_CAP) {
  1898. }
  1899. if (sta_info_type & STA_INFO_UPDATE_HT_CAP) {
  1900. }
  1901. if (sta_info_type & STA_INFO_UPDATE_VHT_CAP) {
  1902. }
  1903. */
  1904. }
  1905. static void update_bcn_ext_capab_ie(_adapter *padapter)
  1906. {
  1907. sint ie_len = 0;
  1908. unsigned char *pbuf;
  1909. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1910. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1911. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1912. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  1913. u8 *ie = pnetwork->IEs;
  1914. u8 null_extcap_data[8] = {0};
  1915. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_CAP_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  1916. if (pbuf && ie_len > 0)
  1917. rtw_remove_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_);
  1918. if ((pmlmepriv->ext_capab_ie_len > 0) &&
  1919. (_rtw_memcmp(pmlmepriv->ext_capab_ie_data, null_extcap_data, sizeof(null_extcap_data)) == _FALSE))
  1920. rtw_add_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_, pmlmepriv->ext_capab_ie_data, pmlmepriv->ext_capab_ie_len);
  1921. }
  1922. static void update_bcn_fixed_ie(_adapter *padapter)
  1923. {
  1924. RTW_INFO("%s\n", __FUNCTION__);
  1925. }
  1926. static void update_bcn_erpinfo_ie(_adapter *padapter)
  1927. {
  1928. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1929. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1930. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1931. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  1932. unsigned char *p, *ie = pnetwork->IEs;
  1933. u32 len = 0;
  1934. RTW_INFO("%s, ERP_enable=%d\n", __FUNCTION__, pmlmeinfo->ERP_enable);
  1935. if (!pmlmeinfo->ERP_enable)
  1936. return;
  1937. /* parsing ERP_IE */
  1938. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  1939. if (p && len > 0) {
  1940. PNDIS_802_11_VARIABLE_IEs pIE = (PNDIS_802_11_VARIABLE_IEs)p;
  1941. if (pmlmepriv->num_sta_non_erp == 1)
  1942. pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
  1943. else
  1944. pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
  1945. if (pmlmepriv->num_sta_no_short_preamble > 0)
  1946. pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
  1947. else
  1948. pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
  1949. ERP_IE_handler(padapter, pIE);
  1950. }
  1951. }
  1952. static void update_bcn_htcap_ie(_adapter *padapter)
  1953. {
  1954. RTW_INFO("%s\n", __FUNCTION__);
  1955. }
  1956. static void update_bcn_htinfo_ie(_adapter *padapter)
  1957. {
  1958. /*
  1959. u8 beacon_updated = _FALSE;
  1960. u32 sta_info_update_type = STA_INFO_UPDATE_NONE;
  1961. */
  1962. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1963. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1964. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1965. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  1966. unsigned char *p, *ie = pnetwork->IEs;
  1967. u32 len = 0;
  1968. if (pmlmepriv->htpriv.ht_option == _FALSE)
  1969. return;
  1970. if (pmlmeinfo->HT_info_enable != 1)
  1971. return;
  1972. RTW_INFO("%s current operation mode=0x%X\n",
  1973. __FUNCTION__, pmlmepriv->ht_op_mode);
  1974. RTW_INFO("num_sta_40mhz_intolerant(%d), 20mhz_width_req(%d), intolerant_ch_rpt(%d), olbc(%d)\n",
  1975. pmlmepriv->num_sta_40mhz_intolerant, pmlmepriv->ht_20mhz_width_req, pmlmepriv->ht_intolerant_ch_reported, ATOMIC_READ(&pmlmepriv->olbc));
  1976. /*parsing HT_INFO_IE, currently only update ht_op_mode - pht_info->infos[1] & pht_info->infos[2] for wifi logo test*/
  1977. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  1978. if (p && len > 0) {
  1979. struct HT_info_element *pht_info = NULL;
  1980. pht_info = (struct HT_info_element *)(p + 2);
  1981. /* for STA Channel Width/Secondary Channel Offset*/
  1982. if ((pmlmepriv->sw_to_20mhz == 0) && (pmlmeext->cur_channel <= 14)) {
  1983. if ((pmlmepriv->num_sta_40mhz_intolerant > 0) || (pmlmepriv->ht_20mhz_width_req == _TRUE)
  1984. || (pmlmepriv->ht_intolerant_ch_reported == _TRUE) || (ATOMIC_READ(&pmlmepriv->olbc) == _TRUE)) {
  1985. SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info, 0);
  1986. SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 0);
  1987. pmlmepriv->sw_to_20mhz = 1;
  1988. /*
  1989. sta_info_update_type |= STA_INFO_UPDATE_BW;
  1990. beacon_updated = _TRUE;
  1991. */
  1992. RTW_INFO("%s:switching to 20Mhz\n", __FUNCTION__);
  1993. /*TODO : cur_bwmode/cur_ch_offset switches to 20Mhz*/
  1994. }
  1995. } else {
  1996. if ((pmlmepriv->num_sta_40mhz_intolerant == 0) && (pmlmepriv->ht_20mhz_width_req == _FALSE)
  1997. && (pmlmepriv->ht_intolerant_ch_reported == _FALSE) && (ATOMIC_READ(&pmlmepriv->olbc) == _FALSE)) {
  1998. if (pmlmeext->cur_bwmode >= CHANNEL_WIDTH_40) {
  1999. SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 1);
  2000. SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info,
  2001. (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) ?
  2002. HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE : HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW);
  2003. pmlmepriv->sw_to_20mhz = 0;
  2004. /*
  2005. sta_info_update_type |= STA_INFO_UPDATE_BW;
  2006. beacon_updated = _TRUE;
  2007. */
  2008. RTW_INFO("%s:switching back to 40Mhz\n", __FUNCTION__);
  2009. }
  2010. }
  2011. }
  2012. /* to update ht_op_mode*/
  2013. *(u16 *)(pht_info->infos + 1) = cpu_to_le16(pmlmepriv->ht_op_mode);
  2014. }
  2015. /*associated_clients_update(padapter, beacon_updated, sta_info_update_type);*/
  2016. }
  2017. static void update_bcn_rsn_ie(_adapter *padapter)
  2018. {
  2019. RTW_INFO("%s\n", __FUNCTION__);
  2020. }
  2021. static void update_bcn_wpa_ie(_adapter *padapter)
  2022. {
  2023. RTW_INFO("%s\n", __FUNCTION__);
  2024. }
  2025. static void update_bcn_wmm_ie(_adapter *padapter)
  2026. {
  2027. RTW_INFO("%s\n", __FUNCTION__);
  2028. }
  2029. static void update_bcn_wps_ie(_adapter *padapter)
  2030. {
  2031. u8 *pwps_ie = NULL, *pwps_ie_src, *premainder_ie, *pbackup_remainder_ie = NULL;
  2032. uint wps_ielen = 0, wps_offset, remainder_ielen;
  2033. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2034. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2035. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2036. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  2037. unsigned char *ie = pnetwork->IEs;
  2038. u32 ielen = pnetwork->IELength;
  2039. RTW_INFO("%s\n", __FUNCTION__);
  2040. pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
  2041. if (pwps_ie == NULL || wps_ielen == 0)
  2042. return;
  2043. pwps_ie_src = pmlmepriv->wps_beacon_ie;
  2044. if (pwps_ie_src == NULL)
  2045. return;
  2046. wps_offset = (uint)(pwps_ie - ie);
  2047. premainder_ie = pwps_ie + wps_ielen;
  2048. remainder_ielen = ielen - wps_offset - wps_ielen;
  2049. if (remainder_ielen > 0) {
  2050. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  2051. if (pbackup_remainder_ie)
  2052. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  2053. }
  2054. wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
  2055. if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
  2056. _rtw_memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
  2057. pwps_ie += (wps_ielen + 2);
  2058. if (pbackup_remainder_ie)
  2059. _rtw_memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
  2060. /* update IELength */
  2061. pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
  2062. }
  2063. if (pbackup_remainder_ie)
  2064. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  2065. /* deal with the case without set_tx_beacon_cmd() in update_beacon() */
  2066. #if defined(CONFIG_INTERRUPT_BASED_TXBCN) || defined(CONFIG_PCI_HCI)
  2067. if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
  2068. u8 sr = 0;
  2069. rtw_get_wps_attr_content(pwps_ie_src, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
  2070. if (sr) {
  2071. set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
  2072. RTW_INFO("%s, set WIFI_UNDER_WPS\n", __func__);
  2073. } else {
  2074. clr_fwstate(pmlmepriv, WIFI_UNDER_WPS);
  2075. RTW_INFO("%s, clr WIFI_UNDER_WPS\n", __func__);
  2076. }
  2077. }
  2078. #endif
  2079. }
  2080. static void update_bcn_p2p_ie(_adapter *padapter)
  2081. {
  2082. }
  2083. static void update_bcn_vendor_spec_ie(_adapter *padapter, u8 *oui)
  2084. {
  2085. RTW_INFO("%s\n", __FUNCTION__);
  2086. if (_rtw_memcmp(RTW_WPA_OUI, oui, 4))
  2087. update_bcn_wpa_ie(padapter);
  2088. else if (_rtw_memcmp(WMM_OUI, oui, 4))
  2089. update_bcn_wmm_ie(padapter);
  2090. else if (_rtw_memcmp(WPS_OUI, oui, 4))
  2091. update_bcn_wps_ie(padapter);
  2092. else if (_rtw_memcmp(P2P_OUI, oui, 4))
  2093. update_bcn_p2p_ie(padapter);
  2094. else
  2095. RTW_INFO("unknown OUI type!\n");
  2096. }
  2097. void _update_beacon(_adapter *padapter, u8 ie_id, u8 *oui, u8 tx, const char *tag)
  2098. {
  2099. _irqL irqL;
  2100. struct mlme_priv *pmlmepriv;
  2101. struct mlme_ext_priv *pmlmeext;
  2102. /* struct mlme_ext_info *pmlmeinfo; */
  2103. /* RTW_INFO("%s\n", __FUNCTION__); */
  2104. if (!padapter)
  2105. return;
  2106. pmlmepriv = &(padapter->mlmepriv);
  2107. pmlmeext = &(padapter->mlmeextpriv);
  2108. /* pmlmeinfo = &(pmlmeext->mlmext_info); */
  2109. if (_FALSE == pmlmeext->bstart_bss)
  2110. return;
  2111. _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  2112. switch (ie_id) {
  2113. case 0xFF:
  2114. update_bcn_fixed_ie(padapter);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
  2115. break;
  2116. case _TIM_IE_:
  2117. update_BCNTIM(padapter);
  2118. break;
  2119. case _ERPINFO_IE_:
  2120. update_bcn_erpinfo_ie(padapter);
  2121. break;
  2122. case _HT_CAPABILITY_IE_:
  2123. update_bcn_htcap_ie(padapter);
  2124. break;
  2125. case _RSN_IE_2_:
  2126. update_bcn_rsn_ie(padapter);
  2127. break;
  2128. case _HT_ADD_INFO_IE_:
  2129. update_bcn_htinfo_ie(padapter);
  2130. break;
  2131. case _EXT_CAP_IE_:
  2132. update_bcn_ext_capab_ie(padapter);
  2133. break;
  2134. case _VENDOR_SPECIFIC_IE_:
  2135. update_bcn_vendor_spec_ie(padapter, oui);
  2136. break;
  2137. default:
  2138. break;
  2139. }
  2140. pmlmepriv->update_bcn = _TRUE;
  2141. _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  2142. #ifndef CONFIG_INTERRUPT_BASED_TXBCN
  2143. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  2144. if (tx) {
  2145. /* send_beacon(padapter); */ /* send_beacon must execute on TSR level */
  2146. if (0)
  2147. RTW_INFO(FUNC_ADPT_FMT" ie_id:%u - %s\n", FUNC_ADPT_ARG(padapter), ie_id, tag);
  2148. set_tx_beacon_cmd(padapter);
  2149. }
  2150. #else
  2151. {
  2152. /* PCI will issue beacon when BCN interrupt occurs. */
  2153. }
  2154. #endif
  2155. #endif /* !CONFIG_INTERRUPT_BASED_TXBCN */
  2156. }
  2157. #ifdef CONFIG_80211N_HT
  2158. void rtw_process_public_act_bsscoex(_adapter *padapter, u8 *pframe, uint frame_len)
  2159. {
  2160. struct sta_info *psta;
  2161. struct sta_priv *pstapriv = &padapter->stapriv;
  2162. u8 beacon_updated = _FALSE;
  2163. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2164. u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  2165. uint frame_body_len = frame_len - sizeof(struct rtw_ieee80211_hdr_3addr);
  2166. u8 category, action;
  2167. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  2168. if (psta == NULL)
  2169. return;
  2170. category = frame_body[0];
  2171. action = frame_body[1];
  2172. if (frame_body_len > 0) {
  2173. if ((frame_body[2] == EID_BSSCoexistence) && (frame_body[3] > 0)) {
  2174. u8 ie_data = frame_body[4];
  2175. if (ie_data & RTW_WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
  2176. if (psta->ht_40mhz_intolerant == 0) {
  2177. psta->ht_40mhz_intolerant = 1;
  2178. pmlmepriv->num_sta_40mhz_intolerant++;
  2179. beacon_updated = _TRUE;
  2180. }
  2181. } else if (ie_data & RTW_WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ) {
  2182. if (pmlmepriv->ht_20mhz_width_req == _FALSE) {
  2183. pmlmepriv->ht_20mhz_width_req = _TRUE;
  2184. beacon_updated = _TRUE;
  2185. }
  2186. } else
  2187. beacon_updated = _FALSE;
  2188. }
  2189. }
  2190. if (frame_body_len > 8) {
  2191. /* if EID_BSSIntolerantChlReport ie exists */
  2192. if ((frame_body[5] == EID_BSSIntolerantChlReport) && (frame_body[6] > 0)) {
  2193. /*todo:*/
  2194. if (pmlmepriv->ht_intolerant_ch_reported == _FALSE) {
  2195. pmlmepriv->ht_intolerant_ch_reported = _TRUE;
  2196. beacon_updated = _TRUE;
  2197. }
  2198. }
  2199. }
  2200. if (beacon_updated) {
  2201. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
  2202. associated_stainfo_update(padapter, psta, STA_INFO_UPDATE_BW);
  2203. }
  2204. }
  2205. void rtw_process_ht_action_smps(_adapter *padapter, u8 *ta, u8 ctrl_field)
  2206. {
  2207. u8 e_field, m_field;
  2208. struct sta_info *psta;
  2209. struct sta_priv *pstapriv = &padapter->stapriv;
  2210. psta = rtw_get_stainfo(pstapriv, ta);
  2211. if (psta == NULL)
  2212. return;
  2213. e_field = (ctrl_field & BIT(0)) ? 1 : 0;
  2214. m_field = (ctrl_field & BIT(1)) ? 1 : 0;
  2215. if (e_field) {
  2216. /* enable */
  2217. /* 0:static SMPS, 1:dynamic SMPS, 3:SMPS disabled, 2:reserved*/
  2218. if (m_field) /*mode*/
  2219. psta->htpriv.smps_cap = 1;
  2220. else
  2221. psta->htpriv.smps_cap = 0;
  2222. } else {
  2223. /*disable*/
  2224. psta->htpriv.smps_cap = 3;
  2225. }
  2226. rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta);
  2227. }
  2228. /*
  2229. op_mode
  2230. Set to 0 (HT pure) under the followign conditions
  2231. - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
  2232. - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
  2233. Set to 1 (HT non-member protection) if there may be non-HT STAs
  2234. in both the primary and the secondary channel
  2235. Set to 2 if only HT STAs are associated in BSS,
  2236. however and at least one 20 MHz HT STA is associated
  2237. Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
  2238. (currently non-GF HT station is considered as non-HT STA also)
  2239. */
  2240. int rtw_ht_operation_update(_adapter *padapter)
  2241. {
  2242. u16 cur_op_mode, new_op_mode;
  2243. int op_mode_changes = 0;
  2244. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2245. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  2246. if (pmlmepriv->htpriv.ht_option == _FALSE)
  2247. return 0;
  2248. /*if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
  2249. return 0;*/
  2250. RTW_INFO("%s current operation mode=0x%X\n",
  2251. __FUNCTION__, pmlmepriv->ht_op_mode);
  2252. if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
  2253. && pmlmepriv->num_sta_ht_no_gf) {
  2254. pmlmepriv->ht_op_mode |=
  2255. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  2256. op_mode_changes++;
  2257. } else if ((pmlmepriv->ht_op_mode &
  2258. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
  2259. pmlmepriv->num_sta_ht_no_gf == 0) {
  2260. pmlmepriv->ht_op_mode &=
  2261. ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  2262. op_mode_changes++;
  2263. }
  2264. if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  2265. (pmlmepriv->num_sta_no_ht || ATOMIC_READ(&pmlmepriv->olbc_ht))) {
  2266. pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  2267. op_mode_changes++;
  2268. } else if ((pmlmepriv->ht_op_mode &
  2269. HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  2270. (pmlmepriv->num_sta_no_ht == 0 && !ATOMIC_READ(&pmlmepriv->olbc_ht))) {
  2271. pmlmepriv->ht_op_mode &=
  2272. ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  2273. op_mode_changes++;
  2274. }
  2275. /* Note: currently we switch to the MIXED op mode if HT non-greenfield
  2276. * station is associated. Probably it's a theoretical case, since
  2277. * it looks like all known HT STAs support greenfield.
  2278. */
  2279. new_op_mode = 0;
  2280. if (pmlmepriv->num_sta_no_ht /*||
  2281. (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/)
  2282. new_op_mode = OP_MODE_MIXED;
  2283. else if ((phtpriv_ap->ht_cap.cap_info & IEEE80211_HT_CAP_SUP_WIDTH)
  2284. && pmlmepriv->num_sta_ht_20mhz)
  2285. new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
  2286. else if (ATOMIC_READ(&pmlmepriv->olbc_ht))
  2287. new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
  2288. else
  2289. new_op_mode = OP_MODE_PURE;
  2290. cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  2291. if (cur_op_mode != new_op_mode) {
  2292. pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  2293. pmlmepriv->ht_op_mode |= new_op_mode;
  2294. op_mode_changes++;
  2295. }
  2296. RTW_INFO("%s new operation mode=0x%X changes=%d\n",
  2297. __FUNCTION__, pmlmepriv->ht_op_mode, op_mode_changes);
  2298. return op_mode_changes;
  2299. }
  2300. #endif /* CONFIG_80211N_HT */
  2301. void associated_clients_update(_adapter *padapter, u8 updated, u32 sta_info_type)
  2302. {
  2303. /* update associcated stations cap. */
  2304. if (updated == _TRUE) {
  2305. _irqL irqL;
  2306. _list *phead, *plist;
  2307. struct sta_info *psta = NULL;
  2308. struct sta_priv *pstapriv = &padapter->stapriv;
  2309. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2310. phead = &pstapriv->asoc_list;
  2311. plist = get_next(phead);
  2312. /* check asoc_queue */
  2313. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  2314. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2315. plist = get_next(plist);
  2316. associated_stainfo_update(padapter, psta, sta_info_type);
  2317. }
  2318. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2319. }
  2320. }
  2321. /* called > TSR LEVEL for USB or SDIO Interface*/
  2322. void bss_cap_update_on_sta_join(_adapter *padapter, struct sta_info *psta)
  2323. {
  2324. u8 beacon_updated = _FALSE;
  2325. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2326. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2327. #if 0
  2328. if (!(psta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  2329. !psta->no_short_preamble_set) {
  2330. psta->no_short_preamble_set = 1;
  2331. pmlmepriv->num_sta_no_short_preamble++;
  2332. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2333. (pmlmepriv->num_sta_no_short_preamble == 1))
  2334. ieee802_11_set_beacons(hapd->iface);
  2335. }
  2336. #endif
  2337. if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
  2338. if (!psta->no_short_preamble_set) {
  2339. psta->no_short_preamble_set = 1;
  2340. pmlmepriv->num_sta_no_short_preamble++;
  2341. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2342. (pmlmepriv->num_sta_no_short_preamble == 1)) {
  2343. beacon_updated = _TRUE;
  2344. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2345. }
  2346. }
  2347. } else {
  2348. if (psta->no_short_preamble_set) {
  2349. psta->no_short_preamble_set = 0;
  2350. pmlmepriv->num_sta_no_short_preamble--;
  2351. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2352. (pmlmepriv->num_sta_no_short_preamble == 0)) {
  2353. beacon_updated = _TRUE;
  2354. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2355. }
  2356. }
  2357. }
  2358. #if 0
  2359. if (psta->flags & WLAN_STA_NONERP && !psta->nonerp_set) {
  2360. psta->nonerp_set = 1;
  2361. pmlmepriv->num_sta_non_erp++;
  2362. if (pmlmepriv->num_sta_non_erp == 1)
  2363. ieee802_11_set_beacons(hapd->iface);
  2364. }
  2365. #endif
  2366. if (psta->flags & WLAN_STA_NONERP) {
  2367. if (!psta->nonerp_set) {
  2368. psta->nonerp_set = 1;
  2369. pmlmepriv->num_sta_non_erp++;
  2370. if (pmlmepriv->num_sta_non_erp == 1) {
  2371. beacon_updated = _TRUE;
  2372. update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
  2373. }
  2374. }
  2375. } else {
  2376. if (psta->nonerp_set) {
  2377. psta->nonerp_set = 0;
  2378. pmlmepriv->num_sta_non_erp--;
  2379. if (pmlmepriv->num_sta_non_erp == 0) {
  2380. beacon_updated = _TRUE;
  2381. update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
  2382. }
  2383. }
  2384. }
  2385. #if 0
  2386. if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT) &&
  2387. !psta->no_short_slot_time_set) {
  2388. psta->no_short_slot_time_set = 1;
  2389. pmlmepriv->num_sta_no_short_slot_time++;
  2390. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2391. (pmlmepriv->num_sta_no_short_slot_time == 1))
  2392. ieee802_11_set_beacons(hapd->iface);
  2393. }
  2394. #endif
  2395. if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
  2396. if (!psta->no_short_slot_time_set) {
  2397. psta->no_short_slot_time_set = 1;
  2398. pmlmepriv->num_sta_no_short_slot_time++;
  2399. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2400. (pmlmepriv->num_sta_no_short_slot_time == 1)) {
  2401. beacon_updated = _TRUE;
  2402. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2403. }
  2404. }
  2405. } else {
  2406. if (psta->no_short_slot_time_set) {
  2407. psta->no_short_slot_time_set = 0;
  2408. pmlmepriv->num_sta_no_short_slot_time--;
  2409. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2410. (pmlmepriv->num_sta_no_short_slot_time == 0)) {
  2411. beacon_updated = _TRUE;
  2412. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2413. }
  2414. }
  2415. }
  2416. #ifdef CONFIG_80211N_HT
  2417. if (psta->flags & WLAN_STA_HT) {
  2418. u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
  2419. RTW_INFO("HT: STA " MAC_FMT " HT Capabilities "
  2420. "Info: 0x%04x\n", MAC_ARG(psta->hwaddr), ht_capab);
  2421. if (psta->no_ht_set) {
  2422. psta->no_ht_set = 0;
  2423. pmlmepriv->num_sta_no_ht--;
  2424. }
  2425. if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
  2426. if (!psta->no_ht_gf_set) {
  2427. psta->no_ht_gf_set = 1;
  2428. pmlmepriv->num_sta_ht_no_gf++;
  2429. }
  2430. RTW_INFO("%s STA " MAC_FMT " - no "
  2431. "greenfield, num of non-gf stations %d\n",
  2432. __FUNCTION__, MAC_ARG(psta->hwaddr),
  2433. pmlmepriv->num_sta_ht_no_gf);
  2434. }
  2435. if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
  2436. if (!psta->ht_20mhz_set) {
  2437. psta->ht_20mhz_set = 1;
  2438. pmlmepriv->num_sta_ht_20mhz++;
  2439. }
  2440. RTW_INFO("%s STA " MAC_FMT " - 20 MHz HT, "
  2441. "num of 20MHz HT STAs %d\n",
  2442. __FUNCTION__, MAC_ARG(psta->hwaddr),
  2443. pmlmepriv->num_sta_ht_20mhz);
  2444. }
  2445. } else {
  2446. if (!psta->no_ht_set) {
  2447. psta->no_ht_set = 1;
  2448. pmlmepriv->num_sta_no_ht++;
  2449. }
  2450. if (pmlmepriv->htpriv.ht_option == _TRUE) {
  2451. RTW_INFO("%s STA " MAC_FMT
  2452. " - no HT, num of non-HT stations %d\n",
  2453. __FUNCTION__, MAC_ARG(psta->hwaddr),
  2454. pmlmepriv->num_sta_no_ht);
  2455. }
  2456. }
  2457. if (rtw_ht_operation_update(padapter) > 0) {
  2458. update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
  2459. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
  2460. /*beacon_updated = _TRUE;*/
  2461. }
  2462. #endif /* CONFIG_80211N_HT */
  2463. /* update associcated stations cap. */
  2464. associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL);
  2465. RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
  2466. }
  2467. u8 bss_cap_update_on_sta_leave(_adapter *padapter, struct sta_info *psta)
  2468. {
  2469. u8 beacon_updated = _FALSE;
  2470. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2471. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2472. if (!psta)
  2473. return beacon_updated;
  2474. if (psta->no_short_preamble_set) {
  2475. psta->no_short_preamble_set = 0;
  2476. pmlmepriv->num_sta_no_short_preamble--;
  2477. if (pmlmeext->cur_wireless_mode > WIRELESS_11B
  2478. && pmlmepriv->num_sta_no_short_preamble == 0) {
  2479. beacon_updated = _TRUE;
  2480. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2481. }
  2482. }
  2483. if (psta->nonerp_set) {
  2484. psta->nonerp_set = 0;
  2485. pmlmepriv->num_sta_non_erp--;
  2486. if (pmlmepriv->num_sta_non_erp == 0) {
  2487. beacon_updated = _TRUE;
  2488. update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
  2489. }
  2490. }
  2491. if (psta->no_short_slot_time_set) {
  2492. psta->no_short_slot_time_set = 0;
  2493. pmlmepriv->num_sta_no_short_slot_time--;
  2494. if (pmlmeext->cur_wireless_mode > WIRELESS_11B
  2495. && pmlmepriv->num_sta_no_short_slot_time == 0) {
  2496. beacon_updated = _TRUE;
  2497. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2498. }
  2499. }
  2500. #ifdef CONFIG_80211N_HT
  2501. if (psta->no_ht_gf_set) {
  2502. psta->no_ht_gf_set = 0;
  2503. pmlmepriv->num_sta_ht_no_gf--;
  2504. }
  2505. if (psta->no_ht_set) {
  2506. psta->no_ht_set = 0;
  2507. pmlmepriv->num_sta_no_ht--;
  2508. }
  2509. if (psta->ht_20mhz_set) {
  2510. psta->ht_20mhz_set = 0;
  2511. pmlmepriv->num_sta_ht_20mhz--;
  2512. }
  2513. if (rtw_ht_operation_update(padapter) > 0) {
  2514. update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
  2515. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
  2516. }
  2517. #endif /* CONFIG_80211N_HT */
  2518. #if 0
  2519. /* update associated stations cap. */
  2520. associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL); /* move it to avoid deadlock */
  2521. #endif
  2522. RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
  2523. return beacon_updated;
  2524. }
  2525. u8 ap_free_sta(_adapter *padapter, struct sta_info *psta, bool active, u16 reason, bool enqueue)
  2526. {
  2527. _irqL irqL;
  2528. u8 beacon_updated = _FALSE;
  2529. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2530. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2531. struct sta_priv *pstapriv = &padapter->stapriv;
  2532. if (!psta)
  2533. return beacon_updated;
  2534. if (active == _TRUE) {
  2535. #ifdef CONFIG_80211N_HT
  2536. /* tear down Rx AMPDU */
  2537. send_delba(padapter, 0, psta->hwaddr);/* recipient */
  2538. /* tear down TX AMPDU */
  2539. send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
  2540. #endif /* CONFIG_80211N_HT */
  2541. issue_deauth(padapter, psta->hwaddr, reason);
  2542. }
  2543. #ifdef CONFIG_BEAMFORMING
  2544. beamforming_wk_cmd(padapter, BEAMFORMING_CTRL_LEAVE, psta->hwaddr, ETH_ALEN, 1);
  2545. #endif
  2546. psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
  2547. psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
  2548. /* clear cam entry / key */
  2549. rtw_clearstakey_cmd(padapter, psta, enqueue);
  2550. _enter_critical_bh(&psta->lock, &irqL);
  2551. psta->state &= ~_FW_LINKED;
  2552. _exit_critical_bh(&psta->lock, &irqL);
  2553. #ifdef CONFIG_IOCTL_CFG80211
  2554. if (1) {
  2555. #ifdef COMPAT_KERNEL_RELEASE
  2556. rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
  2557. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  2558. rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
  2559. #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
  2560. /* will call rtw_cfg80211_indicate_sta_disassoc() in cmd_thread for old API context */
  2561. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
  2562. } else
  2563. #endif /* CONFIG_IOCTL_CFG80211 */
  2564. {
  2565. rtw_indicate_sta_disassoc_event(padapter, psta);
  2566. }
  2567. report_del_sta_event(padapter, psta->hwaddr, reason, enqueue, _FALSE);
  2568. beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
  2569. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  2570. rtw_free_stainfo(padapter, psta);
  2571. /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  2572. return beacon_updated;
  2573. }
  2574. int rtw_ap_inform_ch_switch(_adapter *padapter, u8 new_ch, u8 ch_offset)
  2575. {
  2576. _irqL irqL;
  2577. _list *phead, *plist;
  2578. int ret = 0;
  2579. struct sta_info *psta = NULL;
  2580. struct sta_priv *pstapriv = &padapter->stapriv;
  2581. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2582. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2583. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2584. if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  2585. return ret;
  2586. RTW_INFO(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
  2587. FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
  2588. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2589. phead = &pstapriv->asoc_list;
  2590. plist = get_next(phead);
  2591. /* for each sta in asoc_queue */
  2592. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  2593. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2594. plist = get_next(plist);
  2595. issue_action_spct_ch_switch(padapter, psta->hwaddr, new_ch, ch_offset);
  2596. psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
  2597. }
  2598. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2599. issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
  2600. return ret;
  2601. }
  2602. int rtw_sta_flush(_adapter *padapter, bool enqueue)
  2603. {
  2604. _irqL irqL;
  2605. _list *phead, *plist;
  2606. int ret = 0;
  2607. struct sta_info *psta = NULL;
  2608. struct sta_priv *pstapriv = &padapter->stapriv;
  2609. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2610. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2611. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2612. u8 flush_num = 0;
  2613. char flush_list[NUM_STA];
  2614. int i;
  2615. if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  2616. return ret;
  2617. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
  2618. /* pick sta from sta asoc_queue */
  2619. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2620. phead = &pstapriv->asoc_list;
  2621. plist = get_next(phead);
  2622. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  2623. int stainfo_offset;
  2624. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2625. plist = get_next(plist);
  2626. rtw_list_delete(&psta->asoc_list);
  2627. pstapriv->asoc_list_cnt--;
  2628. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  2629. if (stainfo_offset_valid(stainfo_offset))
  2630. flush_list[flush_num++] = stainfo_offset;
  2631. else
  2632. rtw_warn_on(1);
  2633. }
  2634. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2635. /* call ap_free_sta() for each sta picked */
  2636. for (i = 0; i < flush_num; i++) {
  2637. psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
  2638. ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, enqueue);
  2639. }
  2640. issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
  2641. associated_clients_update(padapter, _TRUE, STA_INFO_UPDATE_ALL);
  2642. return ret;
  2643. }
  2644. /* called > TSR LEVEL for USB or SDIO Interface*/
  2645. void sta_info_update(_adapter *padapter, struct sta_info *psta)
  2646. {
  2647. int flags = psta->flags;
  2648. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2649. /* update wmm cap. */
  2650. if (WLAN_STA_WME & flags)
  2651. psta->qos_option = 1;
  2652. else
  2653. psta->qos_option = 0;
  2654. if (pmlmepriv->qospriv.qos_option == 0)
  2655. psta->qos_option = 0;
  2656. #ifdef CONFIG_80211N_HT
  2657. /* update 802.11n ht cap. */
  2658. if (WLAN_STA_HT & flags) {
  2659. psta->htpriv.ht_option = _TRUE;
  2660. psta->qos_option = 1;
  2661. psta->htpriv.smps_cap = (psta->htpriv.ht_cap.cap_info & IEEE80211_HT_CAP_SM_PS) >> 2;
  2662. } else
  2663. psta->htpriv.ht_option = _FALSE;
  2664. if (pmlmepriv->htpriv.ht_option == _FALSE)
  2665. psta->htpriv.ht_option = _FALSE;
  2666. #endif
  2667. #ifdef CONFIG_80211AC_VHT
  2668. /* update 802.11AC vht cap. */
  2669. if (WLAN_STA_VHT & flags)
  2670. psta->vhtpriv.vht_option = _TRUE;
  2671. else
  2672. psta->vhtpriv.vht_option = _FALSE;
  2673. if (pmlmepriv->vhtpriv.vht_option == _FALSE)
  2674. psta->vhtpriv.vht_option = _FALSE;
  2675. #endif
  2676. update_sta_info_apmode(padapter, psta);
  2677. }
  2678. /* called >= TSR LEVEL for USB or SDIO Interface*/
  2679. void ap_sta_info_defer_update(_adapter *padapter, struct sta_info *psta)
  2680. {
  2681. if (psta->state & _FW_LINKED)
  2682. rtw_hal_update_ra_mask(psta, psta->rssi_level, _TRUE); /* DM_RATR_STA_INIT */
  2683. }
  2684. /* restore hw setting from sw data structures */
  2685. void rtw_ap_restore_network(_adapter *padapter)
  2686. {
  2687. struct mlme_priv *mlmepriv = &padapter->mlmepriv;
  2688. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2689. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2690. struct sta_priv *pstapriv = &padapter->stapriv;
  2691. struct sta_info *psta;
  2692. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  2693. _irqL irqL;
  2694. _list *phead, *plist;
  2695. u8 chk_alive_num = 0;
  2696. char chk_alive_list[NUM_STA];
  2697. int i;
  2698. rtw_setopmode_cmd(padapter, Ndis802_11APMode, _FALSE);
  2699. set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  2700. rtw_startbss_cmd(padapter, RTW_CMDF_DIRECTLY);
  2701. if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
  2702. (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
  2703. /* restore group key, WEP keys is restored in ips_leave() */
  2704. rtw_set_key(padapter, psecuritypriv, psecuritypriv->dot118021XGrpKeyid, 0, _FALSE);
  2705. }
  2706. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2707. phead = &pstapriv->asoc_list;
  2708. plist = get_next(phead);
  2709. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  2710. int stainfo_offset;
  2711. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2712. plist = get_next(plist);
  2713. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  2714. if (stainfo_offset_valid(stainfo_offset))
  2715. chk_alive_list[chk_alive_num++] = stainfo_offset;
  2716. }
  2717. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2718. for (i = 0; i < chk_alive_num; i++) {
  2719. psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
  2720. if (psta == NULL)
  2721. RTW_INFO(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
  2722. else if (psta->state & _FW_LINKED) {
  2723. rtw_sta_media_status_rpt(padapter, psta, 1);
  2724. Update_RA_Entry(padapter, psta);
  2725. /* pairwise key */
  2726. /* per sta pairwise key and settings */
  2727. if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
  2728. (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
  2729. rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _FALSE);
  2730. }
  2731. }
  2732. }
  2733. void start_ap_mode(_adapter *padapter)
  2734. {
  2735. int i;
  2736. struct sta_info *psta = NULL;
  2737. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2738. struct sta_priv *pstapriv = &padapter->stapriv;
  2739. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2740. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2741. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2742. pmlmepriv->update_bcn = _FALSE;
  2743. /*init_mlme_ap_info(padapter);*/
  2744. pmlmeext->bstart_bss = _FALSE;
  2745. pmlmepriv->num_sta_non_erp = 0;
  2746. pmlmepriv->num_sta_no_short_slot_time = 0;
  2747. pmlmepriv->num_sta_no_short_preamble = 0;
  2748. pmlmepriv->num_sta_ht_no_gf = 0;
  2749. #ifdef CONFIG_80211N_HT
  2750. pmlmepriv->num_sta_no_ht = 0;
  2751. #endif /* CONFIG_80211N_HT */
  2752. pmlmeinfo->HT_info_enable = 0;
  2753. pmlmeinfo->HT_caps_enable = 0;
  2754. pmlmeinfo->HT_enable = 0;
  2755. pmlmepriv->num_sta_ht_20mhz = 0;
  2756. pmlmepriv->num_sta_40mhz_intolerant = 0;
  2757. ATOMIC_SET(&pmlmepriv->olbc, _FALSE);
  2758. ATOMIC_SET(&pmlmepriv->olbc_ht, _FALSE);
  2759. #ifdef CONFIG_80211N_HT
  2760. pmlmepriv->ht_20mhz_width_req = _FALSE;
  2761. pmlmepriv->ht_intolerant_ch_reported = _FALSE;
  2762. pmlmepriv->ht_op_mode = 0;
  2763. pmlmepriv->sw_to_20mhz = 0;
  2764. #endif
  2765. _rtw_memset(pmlmepriv->ext_capab_ie_data, 0, sizeof(pmlmepriv->ext_capab_ie_data));
  2766. pmlmepriv->ext_capab_ie_len = 0;
  2767. #ifdef CONFIG_CONCURRENT_MODE
  2768. psecuritypriv->dot118021x_bmc_cam_id = INVALID_SEC_MAC_CAM_ID;
  2769. #endif
  2770. for (i = 0 ; i < NUM_STA ; i++)
  2771. pstapriv->sta_aid[i] = NULL;
  2772. #if CONFIG_RTW_MACADDR_ACL
  2773. rtw_macaddr_acl_init(padapter);
  2774. #endif
  2775. psta = rtw_get_bcmc_stainfo(padapter);
  2776. /*_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
  2777. if (psta)
  2778. rtw_free_stainfo(padapter, psta);
  2779. /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
  2780. rtw_init_bcmc_stainfo(padapter);
  2781. if (rtw_mi_get_ap_num(padapter))
  2782. RTW_SET_SCAN_BAND_SKIP(padapter, BAND_5G);
  2783. }
  2784. void stop_ap_mode(_adapter *padapter)
  2785. {
  2786. _irqL irqL;
  2787. struct sta_info *psta = NULL;
  2788. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2789. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2790. struct dvobj_priv *pdvobj = padapter->dvobj;
  2791. RTW_INFO("%s -"ADPT_FMT"\n", __func__, ADPT_ARG(padapter));
  2792. pmlmepriv->update_bcn = _FALSE;
  2793. /*pmlmeext->bstart_bss = _FALSE;*/
  2794. padapter->netif_up = _FALSE;
  2795. /* _rtw_spinlock_free(&pmlmepriv->bcn_update_lock); */
  2796. /* reset and init security priv , this can refine with rtw_reset_securitypriv */
  2797. _rtw_memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
  2798. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
  2799. padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
  2800. #ifdef CONFIG_DFS_MASTER
  2801. rtw_dfs_master_status_apply(padapter, MLME_AP_STOPPED);
  2802. #endif
  2803. /* free scan queue */
  2804. rtw_free_network_queue(padapter, _TRUE);
  2805. #if CONFIG_RTW_MACADDR_ACL
  2806. rtw_macaddr_acl_deinit(padapter);
  2807. #endif
  2808. rtw_sta_flush(padapter, _TRUE);
  2809. /* free_assoc_sta_resources */
  2810. rtw_free_all_stainfo(padapter);
  2811. psta = rtw_get_bcmc_stainfo(padapter);
  2812. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  2813. rtw_free_stainfo(padapter, psta);
  2814. /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
  2815. rtw_free_mlme_priv_ie_data(pmlmepriv);
  2816. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  2817. if (pmlmeext->bstart_bss == _TRUE) {
  2818. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  2819. pdvobj->nr_ap_if--;
  2820. if (pdvobj->nr_ap_if > 0)
  2821. pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
  2822. else
  2823. pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL;
  2824. rtw_list_delete(&padapter->list);
  2825. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  2826. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
  2827. if (pdvobj->nr_ap_if == 0)
  2828. _cancel_timer_ex(&pdvobj->txbcn_timer);
  2829. }
  2830. #endif
  2831. pmlmeext->bstart_bss = _FALSE;
  2832. #ifdef CONFIG_BT_COEXIST
  2833. rtw_btcoex_MediaStatusNotify(padapter, 0); /* disconnect */
  2834. #endif
  2835. }
  2836. #endif /* CONFIG_NATIVEAP_MLME */
  2837. void rtw_ap_update_bss_chbw(_adapter *adapter, WLAN_BSSID_EX *bss, u8 ch, u8 bw, u8 offset)
  2838. {
  2839. #define UPDATE_VHT_CAP 1
  2840. #define UPDATE_HT_CAP 1
  2841. #ifdef CONFIG_80211AC_VHT
  2842. {
  2843. struct vht_priv *vhtpriv = &adapter->mlmepriv.vhtpriv;
  2844. u8 *vht_cap_ie, *vht_op_ie;
  2845. int vht_cap_ielen, vht_op_ielen;
  2846. u8 center_freq;
  2847. vht_cap_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_VHTCapability, &vht_cap_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  2848. vht_op_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_VHTOperation, &vht_op_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  2849. center_freq = rtw_get_center_ch(ch, bw, offset);
  2850. /* update vht cap ie */
  2851. if (vht_cap_ie && vht_cap_ielen) {
  2852. #if UPDATE_VHT_CAP
  2853. /* if ((bw == CHANNEL_WIDTH_160 || bw == CHANNEL_WIDTH_80_80) && pvhtpriv->sgi_160m)
  2854. SET_VHT_CAPABILITY_ELE_SHORT_GI160M(pvht_cap_ie + 2, 1);
  2855. else */
  2856. SET_VHT_CAPABILITY_ELE_SHORT_GI160M(vht_cap_ie + 2, 0);
  2857. if (bw >= CHANNEL_WIDTH_80 && vhtpriv->sgi_80m)
  2858. SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 1);
  2859. else
  2860. SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 0);
  2861. #endif
  2862. }
  2863. /* update vht op ie */
  2864. if (vht_op_ie && vht_op_ielen) {
  2865. if (bw < CHANNEL_WIDTH_80) {
  2866. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 0);
  2867. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, 0);
  2868. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
  2869. } else if (bw == CHANNEL_WIDTH_80) {
  2870. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 1);
  2871. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, center_freq);
  2872. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
  2873. } else {
  2874. RTW_ERR(FUNC_ADPT_FMT" unsupported BW:%u\n", FUNC_ADPT_ARG(adapter), bw);
  2875. rtw_warn_on(1);
  2876. }
  2877. }
  2878. }
  2879. #endif /* CONFIG_80211AC_VHT */
  2880. #ifdef CONFIG_80211N_HT
  2881. {
  2882. struct ht_priv *htpriv = &adapter->mlmepriv.htpriv;
  2883. u8 *ht_cap_ie, *ht_op_ie;
  2884. int ht_cap_ielen, ht_op_ielen;
  2885. ht_cap_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_HTCapability, &ht_cap_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  2886. ht_op_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_HTInfo, &ht_op_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  2887. /* update ht cap ie */
  2888. if (ht_cap_ie && ht_cap_ielen) {
  2889. #if UPDATE_HT_CAP
  2890. if (bw >= CHANNEL_WIDTH_40)
  2891. SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 1);
  2892. else
  2893. SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 0);
  2894. if (bw >= CHANNEL_WIDTH_40 && htpriv->sgi_40m)
  2895. SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 1);
  2896. else
  2897. SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 0);
  2898. if (htpriv->sgi_20m)
  2899. SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 1);
  2900. else
  2901. SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 0);
  2902. #endif
  2903. }
  2904. /* update ht op ie */
  2905. if (ht_op_ie && ht_op_ielen) {
  2906. SET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2, ch);
  2907. switch (offset) {
  2908. case HAL_PRIME_CHNL_OFFSET_LOWER:
  2909. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCA);
  2910. break;
  2911. case HAL_PRIME_CHNL_OFFSET_UPPER:
  2912. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCB);
  2913. break;
  2914. case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
  2915. default:
  2916. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCN);
  2917. break;
  2918. }
  2919. if (bw >= CHANNEL_WIDTH_40)
  2920. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 1);
  2921. else
  2922. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 0);
  2923. }
  2924. }
  2925. #endif /* CONFIG_80211N_HT */
  2926. {
  2927. u8 *p;
  2928. int ie_len;
  2929. u8 old_ch = bss->Configuration.DSConfig;
  2930. bool change_band = _FALSE;
  2931. if ((ch <= 14 && old_ch >= 36) || (ch >= 36 && old_ch <= 14))
  2932. change_band = _TRUE;
  2933. /* update channel in IE */
  2934. p = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  2935. if (p && ie_len > 0)
  2936. *(p + 2) = ch;
  2937. bss->Configuration.DSConfig = ch;
  2938. /* band is changed, update ERP, support rate, ext support rate IE */
  2939. if (change_band == _TRUE)
  2940. change_band_update_ie(adapter, bss, ch);
  2941. }
  2942. }
  2943. bool rtw_ap_chbw_decision(_adapter *adapter, s16 req_ch, s8 req_bw, s8 req_offset
  2944. , u8 *ch, u8 *bw, u8 *offset, u8 *chbw_allow)
  2945. {
  2946. u8 cur_ie_ch, cur_ie_bw, cur_ie_offset;
  2947. u8 dec_ch, dec_bw, dec_offset;
  2948. u8 u_ch = 0, u_offset, u_bw;
  2949. bool changed = _FALSE;
  2950. struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
  2951. WLAN_BSSID_EX *network = &(adapter->mlmepriv.cur_network.network);
  2952. struct mi_state mstate;
  2953. bool set_u_ch = _FALSE, set_dec_ch = _FALSE;
  2954. rtw_ies_get_chbw(network->IEs + sizeof(NDIS_802_11_FIXED_IEs)
  2955. , network->IELength - sizeof(NDIS_802_11_FIXED_IEs)
  2956. , &cur_ie_ch, &cur_ie_bw, &cur_ie_offset);
  2957. #ifdef CONFIG_MCC_MODE
  2958. if (MCC_EN(adapter)) {
  2959. if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC)) {
  2960. /* check channel settings are the same */
  2961. if (cur_ie_ch == mlmeext->cur_channel
  2962. && cur_ie_bw == mlmeext->cur_bwmode
  2963. && cur_ie_offset == mlmeext->cur_ch_offset) {
  2964. RTW_INFO(FUNC_ADPT_FMT"req ch settings are the same as current ch setting, go to exit\n"
  2965. , FUNC_ADPT_ARG(adapter));
  2966. *chbw_allow = _FALSE;
  2967. goto exit;
  2968. } else {
  2969. RTW_INFO(FUNC_ADPT_FMT"request channel settings are not the same as current channel setting(%d,%d,%d,%d,%d,%d), restart MCC\n"
  2970. , FUNC_ADPT_ARG(adapter)
  2971. , cur_ie_ch, cur_ie_bw, cur_ie_bw
  2972. , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  2973. rtw_hal_set_mcc_setting_disconnect(adapter);
  2974. }
  2975. }
  2976. }
  2977. #endif /* CONFIG_MCC_MODE */
  2978. /* use chbw of cur_ie updated with specifying req as temporary decision */
  2979. dec_ch = (req_ch <= 0) ? cur_ie_ch : req_ch;
  2980. dec_bw = (req_bw < 0) ? cur_ie_bw : req_bw;
  2981. dec_offset = (req_offset < 0) ? cur_ie_offset : req_offset;
  2982. rtw_mi_status_no_self(adapter, &mstate);
  2983. RTW_INFO(FUNC_ADPT_FMT" ld_sta_num:%u, lg_sta_num%u, ap_num:%u\n"
  2984. , FUNC_ADPT_ARG(adapter), MSTATE_STA_LD_NUM(&mstate), MSTATE_STA_LG_NUM(&mstate), MSTATE_AP_NUM(&mstate));
  2985. if (MSTATE_STA_LD_NUM(&mstate) || MSTATE_AP_NUM(&mstate)) {
  2986. /* has linked STA or AP mode, follow */
  2987. rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
  2988. RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
  2989. RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
  2990. rtw_adjust_chbw(adapter, u_ch, &dec_bw, &dec_offset);
  2991. #ifdef CONFIG_MCC_MODE
  2992. if (MCC_EN(adapter)) {
  2993. if (!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
  2994. mlmeext->cur_channel = *ch = dec_ch;
  2995. mlmeext->cur_bwmode = *bw = dec_bw;
  2996. mlmeext->cur_ch_offset = *offset = dec_offset;
  2997. /* channel bw offset can not be allowed, need MCC */
  2998. *chbw_allow = _FALSE;
  2999. RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
  3000. , *ch, *bw, *offset);
  3001. goto exit;
  3002. } else
  3003. /* channel bw offset can be allowed, not need MCC */
  3004. *chbw_allow = _TRUE;
  3005. }
  3006. #endif /* CONFIG_MCC_MODE */
  3007. rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
  3008. , &u_ch, &u_bw, &u_offset);
  3009. rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
  3010. , dec_ch, dec_bw, dec_offset);
  3011. set_u_ch = _TRUE;
  3012. } else if (MSTATE_STA_LG_NUM(&mstate)) {
  3013. /* has linking STA */
  3014. rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
  3015. RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
  3016. RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
  3017. rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
  3018. if (rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
  3019. rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
  3020. , &u_ch, &u_bw, &u_offset);
  3021. rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
  3022. , dec_ch, dec_bw, dec_offset);
  3023. set_u_ch = _TRUE;
  3024. /* channel bw offset can be allowed, not need MCC */
  3025. *chbw_allow = _TRUE;
  3026. } else {
  3027. #ifdef CONFIG_MCC_MODE
  3028. if (MCC_EN(adapter)) {
  3029. mlmeext->cur_channel = *ch = dec_ch;
  3030. mlmeext->cur_bwmode = *bw = dec_bw;
  3031. mlmeext->cur_ch_offset = *offset = dec_offset;
  3032. /* channel bw offset can not be allowed, need MCC */
  3033. *chbw_allow = _FALSE;
  3034. RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
  3035. , *ch, *bw, *offset);
  3036. goto exit;
  3037. }
  3038. #endif /* CONFIG_MCC_MODE */
  3039. /* set this for possible ch change when join down*/
  3040. set_fwstate(&adapter->mlmepriv, WIFI_OP_CH_SWITCHING);
  3041. }
  3042. } else {
  3043. /* single AP mode */
  3044. RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
  3045. /* check temporary decision first */
  3046. rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
  3047. if (!rtw_get_offset_by_chbw(dec_ch, dec_bw, &dec_offset)) {
  3048. if (req_ch == -1 || req_bw == -1)
  3049. goto choose_chbw;
  3050. RTW_WARN(FUNC_ADPT_FMT" req: %u,%u has no valid offset\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw);
  3051. *chbw_allow = _FALSE;
  3052. goto exit;
  3053. }
  3054. if (!rtw_chset_is_chbw_valid(mlmeext->channel_set, dec_ch, dec_bw, dec_offset)) {
  3055. if (req_ch == -1 || req_bw == -1)
  3056. goto choose_chbw;
  3057. RTW_WARN(FUNC_ADPT_FMT" req: %u,%u,%u doesn't fit in chplan\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
  3058. *chbw_allow = _FALSE;
  3059. goto exit;
  3060. }
  3061. if (rtw_odm_dfs_domain_unknown(adapter) && rtw_is_dfs_chbw(dec_ch, dec_bw, dec_offset)) {
  3062. if (req_ch >= 0)
  3063. RTW_WARN(FUNC_ADPT_FMT" DFS channel %u,%u,%u can't be used\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
  3064. if (req_ch > 0) {
  3065. /* specific channel and not from IE => don't change channel setting */
  3066. *chbw_allow = _FALSE;
  3067. goto exit;
  3068. }
  3069. goto choose_chbw;
  3070. }
  3071. if (rtw_chset_is_ch_non_ocp(mlmeext->channel_set, dec_ch, dec_bw, dec_offset) == _FALSE)
  3072. goto update_bss_chbw;
  3073. choose_chbw:
  3074. if (req_bw < 0)
  3075. req_bw = cur_ie_bw;
  3076. #if defined(CONFIG_DFS_MASTER)
  3077. if (!rtw_odm_dfs_domain_unknown(adapter)) {
  3078. /* choose 5G DFS channel for debug */
  3079. if (adapter_to_rfctl(adapter)->dbg_dfs_master_choose_dfs_ch_first
  3080. && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, RTW_CHF_2G | RTW_CHF_NON_DFS) == _TRUE)
  3081. RTW_INFO(FUNC_ADPT_FMT" choose 5G DFS channel for debug\n", FUNC_ADPT_ARG(adapter));
  3082. else if (adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags
  3083. && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags) == _TRUE)
  3084. RTW_INFO(FUNC_ADPT_FMT" choose with dfs_ch_sel_d_flags:0x%02x for debug\n", FUNC_ADPT_ARG(adapter), adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags);
  3085. else if (rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, 0) == _FALSE) {
  3086. RTW_WARN(FUNC_ADPT_FMT" no available channel\n", FUNC_ADPT_ARG(adapter));
  3087. *chbw_allow = _FALSE;
  3088. goto exit;
  3089. }
  3090. } else
  3091. #endif /* defined(CONFIG_DFS_MASTER) */
  3092. if (rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, RTW_CHF_DFS) == _FALSE) {
  3093. RTW_WARN(FUNC_ADPT_FMT" no available channel\n", FUNC_ADPT_ARG(adapter));
  3094. *chbw_allow = _FALSE;
  3095. goto exit;
  3096. }
  3097. update_bss_chbw:
  3098. rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
  3099. , dec_ch, dec_bw, dec_offset);
  3100. /* channel bw offset can be allowed for single AP, not need MCC */
  3101. *chbw_allow = _TRUE;
  3102. set_dec_ch = _TRUE;
  3103. }
  3104. if (rtw_mi_check_fwstate(adapter, _FW_UNDER_SURVEY)) {
  3105. /* scanning, leave ch setting to scan state machine */
  3106. set_u_ch = set_dec_ch = _FALSE;
  3107. }
  3108. if (mlmeext->cur_channel != dec_ch
  3109. || mlmeext->cur_bwmode != dec_bw
  3110. || mlmeext->cur_ch_offset != dec_offset)
  3111. changed = _TRUE;
  3112. if (changed == _TRUE && rtw_linked_check(adapter) == _TRUE) {
  3113. #ifdef CONFIG_SPCT_CH_SWITCH
  3114. if (1)
  3115. rtw_ap_inform_ch_switch(adapter, dec_ch, dec_offset);
  3116. else
  3117. #endif
  3118. rtw_sta_flush(adapter, _FALSE);
  3119. }
  3120. mlmeext->cur_channel = dec_ch;
  3121. mlmeext->cur_bwmode = dec_bw;
  3122. mlmeext->cur_ch_offset = dec_offset;
  3123. if (u_ch != 0)
  3124. RTW_INFO(FUNC_ADPT_FMT" union: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
  3125. RTW_INFO(FUNC_ADPT_FMT" dec: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
  3126. if (set_u_ch == _TRUE) {
  3127. *ch = u_ch;
  3128. *bw = u_bw;
  3129. *offset = u_offset;
  3130. } else if (set_dec_ch == _TRUE) {
  3131. *ch = dec_ch;
  3132. *bw = dec_bw;
  3133. *offset = dec_offset;
  3134. }
  3135. exit:
  3136. return changed;
  3137. }
  3138. /*#define DBG_SWTIMER_BASED_TXBCN*/
  3139. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  3140. void tx_beacon_handlder(struct dvobj_priv *pdvobj)
  3141. {
  3142. #define BEACON_EARLY_TIME 20 /* unit:TU*/
  3143. _irqL irqL;
  3144. _list *plist, *phead;
  3145. u32 timestamp[2];
  3146. u32 bcn_interval_us; /* unit : usec */
  3147. u64 time;
  3148. u32 cur_tick, time_offset; /* unit : usec */
  3149. u32 inter_bcn_space_us; /* unit : usec */
  3150. int nr_vap, idx, bcn_idx;
  3151. int i;
  3152. u8 val8, late = 0;
  3153. _adapter *padapter = NULL;
  3154. i = 0;
  3155. /* get first ap mode interface */
  3156. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3157. if (rtw_is_list_empty(&pdvobj->ap_if_q.queue) || (pdvobj->nr_ap_if == 0)) {
  3158. RTW_INFO("[%s] ERROR: ap_if_q is empty!or nr_ap = %d\n", __func__, pdvobj->nr_ap_if);
  3159. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3160. return;
  3161. } else
  3162. padapter = LIST_CONTAINOR(get_next(&(pdvobj->ap_if_q.queue)), struct _ADAPTER, list);
  3163. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3164. if (NULL == padapter) {
  3165. RTW_INFO("[%s] ERROR: no any ap interface!\n", __func__);
  3166. return;
  3167. }
  3168. bcn_interval_us = DEFAULT_BCN_INTERVAL * NET80211_TU_TO_US;
  3169. if (0 == bcn_interval_us) {
  3170. RTW_INFO("[%s] ERROR: beacon interval = 0\n", __func__);
  3171. return;
  3172. }
  3173. /* read TSF */
  3174. timestamp[1] = rtw_read32(padapter, 0x560 + 4);
  3175. timestamp[0] = rtw_read32(padapter, 0x560);
  3176. while (timestamp[1]) {
  3177. time = (0xFFFFFFFF % bcn_interval_us + 1) * timestamp[1] + timestamp[0];
  3178. timestamp[0] = (u32)time;
  3179. timestamp[1] = (u32)(time >> 32);
  3180. }
  3181. cur_tick = timestamp[0] % bcn_interval_us;
  3182. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3183. nr_vap = (pdvobj->nr_ap_if - 1);
  3184. if (nr_vap > 0) {
  3185. inter_bcn_space_us = pdvobj->inter_bcn_space * NET80211_TU_TO_US; /* beacon_interval / (nr_vap+1); */
  3186. idx = cur_tick / inter_bcn_space_us;
  3187. if (idx < nr_vap) /* if (idx < (nr_vap+1))*/
  3188. bcn_idx = idx + 1; /* bcn_idx = (idx + 1) % (nr_vap+1);*/
  3189. else
  3190. bcn_idx = 0;
  3191. /* to get padapter based on bcn_idx */
  3192. padapter = NULL;
  3193. phead = get_list_head(&pdvobj->ap_if_q);
  3194. plist = get_next(phead);
  3195. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  3196. padapter = LIST_CONTAINOR(plist, struct _ADAPTER, list);
  3197. plist = get_next(plist);
  3198. if (i == bcn_idx)
  3199. break;
  3200. i++;
  3201. }
  3202. if ((NULL == padapter) || (i > pdvobj->nr_ap_if)) {
  3203. RTW_INFO("[%s] ERROR: nr_ap_if = %d, padapter=%p, bcn_idx=%d, index=%d\n",
  3204. __func__, pdvobj->nr_ap_if, padapter, bcn_idx, i);
  3205. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3206. return;
  3207. }
  3208. #ifdef DBG_SWTIMER_BASED_TXBCN
  3209. RTW_INFO("BCN_IDX=%d, cur_tick=%d, padapter=%p\n", bcn_idx, cur_tick, padapter);
  3210. #endif
  3211. if (((idx + 2 == nr_vap + 1) && (idx < nr_vap + 1)) || (0 == bcn_idx)) {
  3212. time_offset = bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
  3213. if ((s32)time_offset < 0)
  3214. time_offset += inter_bcn_space_us;
  3215. } else {
  3216. time_offset = (idx + 2) * inter_bcn_space_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
  3217. if (time_offset > (inter_bcn_space_us + (inter_bcn_space_us >> 1))) {
  3218. time_offset -= inter_bcn_space_us;
  3219. late = 1;
  3220. }
  3221. }
  3222. } else
  3223. /*#endif*/ { /* MBSSID */
  3224. time_offset = 2 * bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
  3225. if (time_offset > (bcn_interval_us + (bcn_interval_us >> 1))) {
  3226. time_offset -= bcn_interval_us;
  3227. late = 1;
  3228. }
  3229. }
  3230. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3231. #ifdef DBG_SWTIMER_BASED_TXBCN
  3232. RTW_INFO("set sw bcn timer %d us\n", time_offset);
  3233. #endif
  3234. _set_timer(&pdvobj->txbcn_timer, time_offset / NET80211_TU_TO_US);
  3235. if (padapter) {
  3236. #ifdef DBG_SWTIMER_BASED_TXBCN
  3237. RTW_INFO("padapter=%p, PORT=%d\n", padapter, padapter->hw_port);
  3238. #endif
  3239. /* bypass TX BCN queue if op ch is switching/waiting */
  3240. if (!check_fwstate(&padapter->mlmepriv, WIFI_OP_CH_SWITCHING)
  3241. #ifdef CONFIG_DFS_MASTER
  3242. && !IS_CH_WAITING(adapter_to_rfctl(padapter))
  3243. #endif
  3244. ) {
  3245. /*update_beacon(padapter, _TIM_IE_, NULL, _FALSE);*/
  3246. issue_beacon(padapter, 0);
  3247. }
  3248. }
  3249. #if 0
  3250. /* handle any buffered BC/MC frames*/
  3251. /* Don't dynamically change DIS_ATIM due to HW will auto send ACQ after HIQ empty.*/
  3252. val8 = *((unsigned char *)priv->beaconbuf + priv->timoffset + 4);
  3253. if (val8 & 0x01) {
  3254. process_mcast_dzqueue(priv);
  3255. priv->pkt_in_dtimQ = 0;
  3256. }
  3257. #endif
  3258. }
  3259. void tx_beacon_timer_handlder(void *ctx)
  3260. {
  3261. struct dvobj_priv *pdvobj = (struct dvobj_priv *)ctx;
  3262. _adapter *padapter = pdvobj->padapters[0];
  3263. if (padapter)
  3264. set_tx_beacon_cmd(padapter);
  3265. }
  3266. #endif
  3267. #endif /* CONFIG_AP_MODE */