rtw_ap.c 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  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. *****************************************************************************/
  15. #define _RTW_AP_C_
  16. #include <drv_types.h>
  17. #include <hal_data.h>
  18. #ifdef CONFIG_AP_MODE
  19. extern unsigned char RTW_WPA_OUI[];
  20. extern unsigned char WMM_OUI[];
  21. extern unsigned char WPS_OUI[];
  22. extern unsigned char P2P_OUI[];
  23. extern unsigned char WFD_OUI[];
  24. void init_mlme_ap_info(_adapter *padapter)
  25. {
  26. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  27. _rtw_spinlock_init(&pmlmepriv->bcn_update_lock);
  28. /* pmlmeext->bstart_bss = _FALSE; */
  29. }
  30. void free_mlme_ap_info(_adapter *padapter)
  31. {
  32. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  33. stop_ap_mode(padapter);
  34. _rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
  35. }
  36. /*
  37. * Set TIM IE
  38. * return length of total TIM IE
  39. */
  40. u8 rtw_set_tim_ie(u8 dtim_cnt, u8 dtim_period
  41. , const u8 *tim_bmp, u8 tim_bmp_len, u8 *tim_ie)
  42. {
  43. u8 *p = tim_ie;
  44. u8 i, n1, n2;
  45. u8 bmp_len;
  46. if (rtw_bmp_not_empty(tim_bmp, tim_bmp_len)) {
  47. /* find the first nonzero octet in tim_bitmap */
  48. for (i = 0; i < tim_bmp_len; i++)
  49. if (tim_bmp[i])
  50. break;
  51. n1 = i & 0xFE;
  52. /* find the last nonzero octet in tim_bitmap, except octet 0 */
  53. for (i = tim_bmp_len - 1; i > 0; i--)
  54. if (tim_bmp[i])
  55. break;
  56. n2 = i;
  57. bmp_len = n2 - n1 + 1;
  58. } else {
  59. n1 = n2 = 0;
  60. bmp_len = 1;
  61. }
  62. *p++ = WLAN_EID_TIM;
  63. *p++ = 2 + 1 + bmp_len;
  64. *p++ = dtim_cnt;
  65. *p++ = dtim_period;
  66. *p++ = (rtw_bmp_is_set(tim_bmp, tim_bmp_len, 0) ? BIT0 : 0) | n1;
  67. _rtw_memcpy(p, tim_bmp + n1, bmp_len);
  68. #if 0
  69. RTW_INFO("n1:%u, n2:%u, bmp_offset:%u, bmp_len:%u\n", n1, n2, n1 / 2, bmp_len);
  70. RTW_INFO_DUMP("tim_ie: ", tim_ie + 2, 2 + 1 + bmp_len);
  71. #endif
  72. return 2 + 2 + 1 + bmp_len;
  73. }
  74. static void update_BCNTIM(_adapter *padapter)
  75. {
  76. struct sta_priv *pstapriv = &padapter->stapriv;
  77. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  78. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  79. WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
  80. unsigned char *pie = pnetwork_mlmeext->IEs;
  81. #if 0
  82. /* update TIM IE */
  83. /* if(rtw_tim_map_anyone_be_set(padapter, pstapriv->tim_bitmap)) */
  84. #endif
  85. if (_TRUE) {
  86. u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
  87. uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
  88. p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
  89. if (p != NULL && tim_ielen > 0) {
  90. tim_ielen += 2;
  91. premainder_ie = p + tim_ielen;
  92. tim_ie_offset = (sint)(p - pie);
  93. remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
  94. /*append TIM IE from dst_ie offset*/
  95. dst_ie = p;
  96. } else {
  97. tim_ielen = 0;
  98. /*calculate head_len*/
  99. offset = _FIXED_IE_LENGTH_;
  100. /* get ssid_ie len */
  101. p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
  102. if (p != NULL)
  103. offset += tmp_len + 2;
  104. /*get supported rates len*/
  105. p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
  106. if (p != NULL)
  107. offset += tmp_len + 2;
  108. /*DS Parameter Set IE, len=3*/
  109. offset += 3;
  110. premainder_ie = pie + offset;
  111. remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
  112. /*append TIM IE from offset*/
  113. dst_ie = pie + offset;
  114. }
  115. if (remainder_ielen > 0) {
  116. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  117. if (pbackup_remainder_ie && premainder_ie)
  118. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  119. }
  120. /* append TIM IE */
  121. dst_ie += rtw_set_tim_ie(0, 1, pstapriv->tim_bitmap, pstapriv->aid_bmp_len, dst_ie);
  122. /*copy remainder IE*/
  123. if (pbackup_remainder_ie) {
  124. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  125. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  126. }
  127. offset = (uint)(dst_ie - pie);
  128. pnetwork_mlmeext->IELength = offset + remainder_ielen;
  129. }
  130. }
  131. void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
  132. {
  133. PNDIS_802_11_VARIABLE_IEs pIE;
  134. u8 bmatch = _FALSE;
  135. u8 *pie = pnetwork->IEs;
  136. u8 *p = NULL, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
  137. u32 i = 0, offset = 0, ielen = 0, ie_offset = 0, remainder_ielen = 0;
  138. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;) {
  139. pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
  140. if (pIE->ElementID > index)
  141. break;
  142. else if (pIE->ElementID == index) { /* already exist the same IE */
  143. p = (u8 *)pIE;
  144. ielen = pIE->Length;
  145. bmatch = _TRUE;
  146. break;
  147. }
  148. p = (u8 *)pIE;
  149. ielen = pIE->Length;
  150. i += (pIE->Length + 2);
  151. }
  152. if (p != NULL && ielen > 0) {
  153. ielen += 2;
  154. premainder_ie = p + ielen;
  155. ie_offset = (sint)(p - pie);
  156. remainder_ielen = pnetwork->IELength - ie_offset - ielen;
  157. if (bmatch)
  158. dst_ie = p;
  159. else
  160. dst_ie = (p + ielen);
  161. }
  162. if (dst_ie == NULL)
  163. return;
  164. if (remainder_ielen > 0) {
  165. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  166. if (pbackup_remainder_ie && premainder_ie)
  167. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  168. }
  169. *dst_ie++ = index;
  170. *dst_ie++ = len;
  171. _rtw_memcpy(dst_ie, data, len);
  172. dst_ie += len;
  173. /* copy remainder IE */
  174. if (pbackup_remainder_ie) {
  175. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  176. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  177. }
  178. offset = (uint)(dst_ie - pie);
  179. pnetwork->IELength = offset + remainder_ielen;
  180. }
  181. void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
  182. {
  183. u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
  184. uint offset, ielen, ie_offset, remainder_ielen = 0;
  185. u8 *pie = pnetwork->IEs;
  186. p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
  187. if (p != NULL && ielen > 0) {
  188. ielen += 2;
  189. premainder_ie = p + ielen;
  190. ie_offset = (sint)(p - pie);
  191. remainder_ielen = pnetwork->IELength - ie_offset - ielen;
  192. dst_ie = p;
  193. } else
  194. return;
  195. if (remainder_ielen > 0) {
  196. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  197. if (pbackup_remainder_ie && premainder_ie)
  198. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  199. }
  200. /* copy remainder IE */
  201. if (pbackup_remainder_ie) {
  202. _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
  203. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  204. }
  205. offset = (uint)(dst_ie - pie);
  206. pnetwork->IELength = offset + remainder_ielen;
  207. }
  208. u8 chk_sta_is_alive(struct sta_info *psta);
  209. u8 chk_sta_is_alive(struct sta_info *psta)
  210. {
  211. u8 ret = _FALSE;
  212. #ifdef DBG_EXPIRATION_CHK
  213. RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
  214. , MAC_ARG(psta->cmn.mac_addr)
  215. , psta->cmn.rssi_stat.rssi
  216. /* , STA_RX_PKTS_ARG(psta) */
  217. , STA_RX_PKTS_DIFF_ARG(psta)
  218. , psta->expire_to
  219. , psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
  220. , psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
  221. , psta->sleepq_len
  222. );
  223. #endif
  224. /* if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta)) */
  225. 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)) {
  226. #if 0
  227. if (psta->state & WIFI_SLEEP_STATE)
  228. ret = _TRUE;
  229. #endif
  230. #ifdef CONFIG_RTW_MESH
  231. if (MLME_IS_MESH(psta->padapter) &&
  232. (psta->sta_stats.last_rx_hwmp_pkts !=
  233. psta->sta_stats.rx_hwmp_pkts))
  234. ret = _TRUE;
  235. #endif
  236. } else
  237. ret = _TRUE;
  238. sta_update_last_rx_pkts(psta);
  239. return ret;
  240. }
  241. /**
  242. * issue_aka_chk_frame - issue active keep alive check frame
  243. * aka = active keep alive
  244. */
  245. static int issue_aka_chk_frame(_adapter *adapter, struct sta_info *psta)
  246. {
  247. int ret = _FAIL;
  248. u8 *target_addr = psta->cmn.mac_addr;
  249. if (MLME_IS_AP(adapter)) {
  250. /* issue null data to check sta alive */
  251. if (psta->state & WIFI_SLEEP_STATE)
  252. ret = issue_nulldata(adapter, target_addr, 0, 1, 50);
  253. else
  254. ret = issue_nulldata(adapter, target_addr, 0, 3, 50);
  255. }
  256. #ifdef CONFIG_RTW_MESH
  257. if (MLME_IS_MESH(adapter)) {
  258. struct rtw_mesh_path *mpath;
  259. rtw_rcu_read_lock();
  260. mpath = rtw_mesh_path_lookup(adapter, target_addr);
  261. if (!mpath) {
  262. mpath = rtw_mesh_path_add(adapter, target_addr);
  263. if (IS_ERR(mpath)) {
  264. rtw_rcu_read_unlock();
  265. RTW_ERR(FUNC_ADPT_FMT" rtw_mesh_path_add for "MAC_FMT" fail.\n",
  266. FUNC_ADPT_ARG(adapter), MAC_ARG(target_addr));
  267. return _FAIL;
  268. }
  269. }
  270. if (mpath->flags & RTW_MESH_PATH_ACTIVE)
  271. ret = _SUCCESS;
  272. else {
  273. u8 flags = RTW_PREQ_Q_F_START | RTW_PREQ_Q_F_PEER_AKA;
  274. /* issue PREQ to check peer alive */
  275. rtw_mesh_queue_preq(mpath, flags);
  276. ret = _FALSE;
  277. }
  278. rtw_rcu_read_unlock();
  279. }
  280. #endif
  281. return ret;
  282. }
  283. void expire_timeout_chk(_adapter *padapter)
  284. {
  285. _irqL irqL;
  286. _list *phead, *plist;
  287. u8 updated = _FALSE;
  288. struct sta_info *psta = NULL;
  289. struct sta_priv *pstapriv = &padapter->stapriv;
  290. u8 chk_alive_num = 0;
  291. char chk_alive_list[NUM_STA];
  292. int i;
  293. #ifdef CONFIG_RTW_MESH
  294. if (MLME_IS_MESH(padapter)
  295. && check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)
  296. ) {
  297. struct rtw_mesh_cfg *mcfg = &padapter->mesh_cfg;
  298. rtw_mesh_path_expire(padapter);
  299. /* TBD: up layer timeout mechanism */
  300. /* if (!mcfg->plink_timeout)
  301. return; */
  302. #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  303. return;
  304. #endif
  305. }
  306. #endif
  307. #ifdef CONFIG_MCC_MODE
  308. /* then driver may check fail due to not recv client's frame under sitesurvey,
  309. * don't expire timeout chk under MCC under sitesurvey */
  310. if (rtw_hal_mcc_link_status_chk(padapter, __func__) == _FALSE)
  311. return;
  312. #endif
  313. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  314. phead = &pstapriv->auth_list;
  315. plist = get_next(phead);
  316. /* check auth_queue */
  317. #ifdef DBG_EXPIRATION_CHK
  318. if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  319. RTW_INFO(FUNC_ADPT_FMT" auth_list, cnt:%u\n"
  320. , FUNC_ADPT_ARG(padapter), pstapriv->auth_list_cnt);
  321. }
  322. #endif
  323. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  324. psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
  325. plist = get_next(plist);
  326. #ifdef CONFIG_ATMEL_RC_PATCH
  327. if (_rtw_memcmp((void *)(pstapriv->atmel_rc_pattern), (void *)(psta->cmn.mac_addr), ETH_ALEN) == _TRUE)
  328. continue;
  329. if (psta->flag_atmel_rc)
  330. continue;
  331. #endif
  332. if (psta->expire_to > 0) {
  333. psta->expire_to--;
  334. if (psta->expire_to == 0) {
  335. rtw_list_delete(&psta->auth_list);
  336. pstapriv->auth_list_cnt--;
  337. RTW_INFO(FUNC_ADPT_FMT" auth expire "MAC_FMT"\n"
  338. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  339. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  340. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  341. rtw_free_stainfo(padapter, psta);
  342. /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  343. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
  344. }
  345. }
  346. }
  347. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
  348. psta = NULL;
  349. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  350. phead = &pstapriv->asoc_list;
  351. plist = get_next(phead);
  352. /* check asoc_queue */
  353. #ifdef DBG_EXPIRATION_CHK
  354. if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  355. RTW_INFO(FUNC_ADPT_FMT" asoc_list, cnt:%u\n"
  356. , FUNC_ADPT_ARG(padapter), pstapriv->asoc_list_cnt);
  357. }
  358. #endif
  359. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  360. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  361. plist = get_next(plist);
  362. #ifdef CONFIG_ATMEL_RC_PATCH
  363. RTW_INFO("%s:%d psta=%p, %02x,%02x||%02x,%02x \n\n", __func__, __LINE__,
  364. psta, pstapriv->atmel_rc_pattern[0], pstapriv->atmel_rc_pattern[5], psta->cmn.mac_addr[0], psta->cmn.mac_addr[5]);
  365. if (_rtw_memcmp((void *)pstapriv->atmel_rc_pattern, (void *)(psta->cmn.mac_addr), ETH_ALEN) == _TRUE)
  366. continue;
  367. if (psta->flag_atmel_rc)
  368. continue;
  369. RTW_INFO("%s: debug line:%d\n", __func__, __LINE__);
  370. #endif
  371. #ifdef CONFIG_AUTO_AP_MODE
  372. if (psta->isrc)
  373. continue;
  374. #endif
  375. if (chk_sta_is_alive(psta) || !psta->expire_to) {
  376. psta->expire_to = pstapriv->expire_to;
  377. psta->keep_alive_trycnt = 0;
  378. #ifdef CONFIG_TX_MCAST2UNI
  379. psta->under_exist_checking = 0;
  380. #endif /* CONFIG_TX_MCAST2UNI */
  381. } else
  382. psta->expire_to--;
  383. #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  384. #ifdef CONFIG_80211N_HT
  385. #ifdef CONFIG_TX_MCAST2UNI
  386. if ((psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking)) {
  387. /* check sta by delba(addba) for 11n STA */
  388. /* ToDo: use CCX report to check for all STAs */
  389. /* 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); */
  390. if (psta->expire_to <= (pstapriv->expire_to - 50)) {
  391. RTW_INFO("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
  392. psta->under_exist_checking = 0;
  393. psta->expire_to = 0;
  394. } else if (psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking == 0)) {
  395. RTW_INFO("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
  396. psta->under_exist_checking = 1;
  397. /* tear down TX AMPDU */
  398. send_delba(padapter, 1, psta->cmn.mac_addr);/* */ /* originator */
  399. psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
  400. psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
  401. }
  402. }
  403. #endif /* CONFIG_TX_MCAST2UNI */
  404. #endif /* CONFIG_80211N_HT */
  405. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  406. if (psta->expire_to <= 0) {
  407. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  408. if (padapter->registrypriv.wifi_spec == 1) {
  409. psta->expire_to = pstapriv->expire_to;
  410. continue;
  411. }
  412. #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  413. #ifdef CONFIG_80211N_HT
  414. #define KEEP_ALIVE_TRYCNT (3)
  415. if (psta->keep_alive_trycnt > 0 && psta->keep_alive_trycnt <= KEEP_ALIVE_TRYCNT) {
  416. if (psta->state & WIFI_STA_ALIVE_CHK_STATE)
  417. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  418. else
  419. psta->keep_alive_trycnt = 0;
  420. } else if ((psta->keep_alive_trycnt > KEEP_ALIVE_TRYCNT) && !(psta->state & WIFI_STA_ALIVE_CHK_STATE))
  421. psta->keep_alive_trycnt = 0;
  422. if ((psta->htpriv.ht_option == _TRUE) && (psta->htpriv.ampdu_enable == _TRUE)) {
  423. uint priority = 1; /* test using BK */
  424. u8 issued = 0;
  425. /* issued = (psta->htpriv.agg_enable_bitmap>>priority)&0x1; */
  426. issued |= (psta->htpriv.candidate_tid_bitmap >> priority) & 0x1;
  427. if (0 == issued) {
  428. if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
  429. psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
  430. if (psta->state & WIFI_SLEEP_STATE)
  431. psta->expire_to = 2; /* 2x2=4 sec */
  432. else
  433. psta->expire_to = 1; /* 2 sec */
  434. psta->state |= WIFI_STA_ALIVE_CHK_STATE;
  435. /* add_ba_hdl(padapter, (u8*)paddbareq_parm); */
  436. RTW_INFO("issue addba_req to check if sta alive, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
  437. issue_addba_req(padapter, psta->cmn.mac_addr, (u8)priority);
  438. _set_timer(&psta->addba_retry_timer, ADDBA_TO);
  439. psta->keep_alive_trycnt++;
  440. continue;
  441. }
  442. }
  443. }
  444. if (psta->keep_alive_trycnt > 0 && psta->state & WIFI_STA_ALIVE_CHK_STATE) {
  445. psta->keep_alive_trycnt = 0;
  446. psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
  447. RTW_INFO("change to another methods to check alive if staion is at ps mode\n");
  448. }
  449. #endif /* CONFIG_80211N_HT */
  450. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  451. if (psta->state & WIFI_SLEEP_STATE) {
  452. if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
  453. /* to check if alive by another methods if staion is at ps mode. */
  454. psta->expire_to = pstapriv->expire_to;
  455. psta->state |= WIFI_STA_ALIVE_CHK_STATE;
  456. /* RTW_INFO("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->cmn.mac_addr)); */
  457. /* to update bcn with tim_bitmap for this station */
  458. rtw_tim_map_set(padapter, pstapriv->tim_bitmap, psta->cmn.aid);
  459. update_beacon(padapter, _TIM_IE_, NULL, _TRUE);
  460. if (!pmlmeext->active_keep_alive_check)
  461. continue;
  462. }
  463. }
  464. {
  465. int stainfo_offset;
  466. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  467. if (stainfo_offset_valid(stainfo_offset))
  468. chk_alive_list[chk_alive_num++] = stainfo_offset;
  469. continue;
  470. }
  471. } else {
  472. /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
  473. if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
  474. && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)
  475. ) {
  476. RTW_INFO(FUNC_ADPT_FMT" sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n"
  477. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  478. , psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
  479. wakeup_sta_to_xmit(padapter, psta);
  480. }
  481. }
  482. }
  483. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  484. if (chk_alive_num) {
  485. #if defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK)
  486. u8 backup_ch = 0, backup_bw = 0, backup_offset = 0;
  487. u8 union_ch = 0, union_bw = 0, union_offset = 0;
  488. u8 switch_channel_by_drv = _TRUE;
  489. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  490. #endif
  491. char del_asoc_list[NUM_STA];
  492. _rtw_memset(del_asoc_list, NUM_STA, NUM_STA);
  493. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  494. if (pmlmeext->active_keep_alive_check) {
  495. #ifdef CONFIG_MCC_MODE
  496. if (MCC_EN(padapter)) {
  497. /* driver doesn't switch channel under MCC */
  498. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
  499. switch_channel_by_drv = _FALSE;
  500. }
  501. #endif
  502. if (!rtw_mi_get_ch_setting_union(padapter, &union_ch, &union_bw, &union_offset)
  503. || pmlmeext->cur_channel != union_ch)
  504. switch_channel_by_drv = _FALSE;
  505. /* switch to correct channel of current network before issue keep-alive frames */
  506. if (switch_channel_by_drv == _TRUE && rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
  507. backup_ch = rtw_get_oper_ch(padapter);
  508. backup_bw = rtw_get_oper_bw(padapter);
  509. backup_offset = rtw_get_oper_choffset(padapter);
  510. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  511. }
  512. }
  513. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  514. /* check loop */
  515. for (i = 0; i < chk_alive_num; i++) {
  516. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  517. int ret = _FAIL;
  518. #endif
  519. psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
  520. #ifdef CONFIG_ATMEL_RC_PATCH
  521. if (_rtw_memcmp(pstapriv->atmel_rc_pattern, psta->cmn.mac_addr, ETH_ALEN) == _TRUE)
  522. continue;
  523. if (psta->flag_atmel_rc)
  524. continue;
  525. #endif
  526. if (!(psta->state & _FW_LINKED))
  527. continue;
  528. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  529. if (pmlmeext->active_keep_alive_check) {
  530. /* issue active keep alive frame to check */
  531. ret = issue_aka_chk_frame(padapter, psta);
  532. psta->keep_alive_trycnt++;
  533. if (ret == _SUCCESS) {
  534. RTW_INFO(FUNC_ADPT_FMT" asoc check, "MAC_FMT" is alive\n"
  535. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  536. psta->expire_to = pstapriv->expire_to;
  537. psta->keep_alive_trycnt = 0;
  538. continue;
  539. } else if (psta->keep_alive_trycnt <= 3) {
  540. RTW_INFO(FUNC_ADPT_FMT" asoc check, "MAC_FMT" keep_alive_trycnt=%d\n"
  541. , FUNC_ADPT_ARG(padapter) , MAC_ARG(psta->cmn.mac_addr), psta->keep_alive_trycnt);
  542. psta->expire_to = 1;
  543. continue;
  544. }
  545. }
  546. #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
  547. psta->keep_alive_trycnt = 0;
  548. del_asoc_list[i] = chk_alive_list[i];
  549. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  550. if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
  551. rtw_list_delete(&psta->asoc_list);
  552. pstapriv->asoc_list_cnt--;
  553. STA_SET_MESH_PLINK(psta, NULL);
  554. }
  555. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  556. }
  557. /* delete loop */
  558. for (i = 0; i < chk_alive_num; i++) {
  559. u8 sta_addr[ETH_ALEN];
  560. if (del_asoc_list[i] >= NUM_STA)
  561. continue;
  562. psta = rtw_get_stainfo_by_offset(pstapriv, del_asoc_list[i]);
  563. _rtw_memcpy(sta_addr, psta->cmn.mac_addr, ETH_ALEN);
  564. RTW_INFO(FUNC_ADPT_FMT" asoc expire "MAC_FMT", state=0x%x\n"
  565. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr), psta->state);
  566. updated |= ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _FALSE);
  567. #ifdef CONFIG_RTW_MESH
  568. if (MLME_IS_MESH(padapter))
  569. rtw_mesh_expire_peer(padapter, sta_addr);
  570. #endif
  571. }
  572. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  573. if (pmlmeext->active_keep_alive_check) {
  574. /* back to the original operation channel */
  575. if (switch_channel_by_drv == _TRUE && backup_ch > 0)
  576. set_channel_bwmode(padapter, backup_ch, backup_offset, backup_bw);
  577. }
  578. #endif
  579. }
  580. associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
  581. }
  582. void rtw_ap_update_sta_ra_info(_adapter *padapter, struct sta_info *psta)
  583. {
  584. unsigned char sta_band = 0;
  585. u64 tx_ra_bitmap = 0;
  586. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  587. WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  588. if (!psta)
  589. return;
  590. if (!(psta->state & _FW_LINKED))
  591. return;
  592. rtw_hal_update_sta_ra_info(padapter, psta);
  593. tx_ra_bitmap = psta->cmn.ra_info.ramask;
  594. if (pcur_network->Configuration.DSConfig > 14) {
  595. if (tx_ra_bitmap & 0xffff000)
  596. sta_band |= WIRELESS_11_5N;
  597. if (tx_ra_bitmap & 0xff0)
  598. sta_band |= WIRELESS_11A;
  599. /* 5G band */
  600. #ifdef CONFIG_80211AC_VHT
  601. if (psta->vhtpriv.vht_option)
  602. sta_band = WIRELESS_11_5AC;
  603. #endif
  604. } else {
  605. if (tx_ra_bitmap & 0xffff000)
  606. sta_band |= WIRELESS_11_24N;
  607. if (tx_ra_bitmap & 0xff0)
  608. sta_band |= WIRELESS_11G;
  609. if (tx_ra_bitmap & 0x0f)
  610. sta_band |= WIRELESS_11B;
  611. }
  612. psta->wireless_mode = sta_band;
  613. rtw_hal_update_sta_wset(padapter, psta);
  614. RTW_INFO("%s=> mac_id:%d , tx_ra_bitmap:0x%016llx, networkType:0x%02x\n",
  615. __FUNCTION__, psta->cmn.mac_id, tx_ra_bitmap, psta->wireless_mode);
  616. }
  617. #ifdef CONFIG_BMC_TX_RATE_SELECT
  618. u8 rtw_ap_find_mini_tx_rate(_adapter *adapter)
  619. {
  620. _irqL irqL;
  621. _list *phead, *plist;
  622. u8 miini_tx_rate = ODM_RATEVHTSS4MCS9, sta_tx_rate;
  623. struct sta_info *psta = NULL;
  624. struct sta_priv *pstapriv = &adapter->stapriv;
  625. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  626. phead = &pstapriv->asoc_list;
  627. plist = get_next(phead);
  628. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  629. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  630. plist = get_next(plist);
  631. sta_tx_rate = psta->cmn.ra_info.curr_tx_rate & 0x7F;
  632. if (sta_tx_rate < miini_tx_rate)
  633. miini_tx_rate = sta_tx_rate;
  634. }
  635. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  636. return miini_tx_rate;
  637. }
  638. u8 rtw_ap_find_bmc_rate(_adapter *adapter, u8 tx_rate)
  639. {
  640. PHAL_DATA_TYPE hal_data = GET_HAL_DATA(adapter);
  641. u8 tx_ini_rate = ODM_RATE6M;
  642. switch (tx_rate) {
  643. case ODM_RATEVHTSS3MCS9:
  644. case ODM_RATEVHTSS3MCS8:
  645. case ODM_RATEVHTSS3MCS7:
  646. case ODM_RATEVHTSS3MCS6:
  647. case ODM_RATEVHTSS3MCS5:
  648. case ODM_RATEVHTSS3MCS4:
  649. case ODM_RATEVHTSS3MCS3:
  650. case ODM_RATEVHTSS2MCS9:
  651. case ODM_RATEVHTSS2MCS8:
  652. case ODM_RATEVHTSS2MCS7:
  653. case ODM_RATEVHTSS2MCS6:
  654. case ODM_RATEVHTSS2MCS5:
  655. case ODM_RATEVHTSS2MCS4:
  656. case ODM_RATEVHTSS2MCS3:
  657. case ODM_RATEVHTSS1MCS9:
  658. case ODM_RATEVHTSS1MCS8:
  659. case ODM_RATEVHTSS1MCS7:
  660. case ODM_RATEVHTSS1MCS6:
  661. case ODM_RATEVHTSS1MCS5:
  662. case ODM_RATEVHTSS1MCS4:
  663. case ODM_RATEVHTSS1MCS3:
  664. case ODM_RATEMCS15:
  665. case ODM_RATEMCS14:
  666. case ODM_RATEMCS13:
  667. case ODM_RATEMCS12:
  668. case ODM_RATEMCS11:
  669. case ODM_RATEMCS7:
  670. case ODM_RATEMCS6:
  671. case ODM_RATEMCS5:
  672. case ODM_RATEMCS4:
  673. case ODM_RATEMCS3:
  674. case ODM_RATE54M:
  675. case ODM_RATE48M:
  676. case ODM_RATE36M:
  677. case ODM_RATE24M:
  678. tx_ini_rate = ODM_RATE24M;
  679. break;
  680. case ODM_RATEVHTSS3MCS2:
  681. case ODM_RATEVHTSS3MCS1:
  682. case ODM_RATEVHTSS2MCS2:
  683. case ODM_RATEVHTSS2MCS1:
  684. case ODM_RATEVHTSS1MCS2:
  685. case ODM_RATEVHTSS1MCS1:
  686. case ODM_RATEMCS10:
  687. case ODM_RATEMCS9:
  688. case ODM_RATEMCS2:
  689. case ODM_RATEMCS1:
  690. case ODM_RATE18M:
  691. case ODM_RATE12M:
  692. tx_ini_rate = ODM_RATE12M;
  693. break;
  694. case ODM_RATEVHTSS3MCS0:
  695. case ODM_RATEVHTSS2MCS0:
  696. case ODM_RATEVHTSS1MCS0:
  697. case ODM_RATEMCS8:
  698. case ODM_RATEMCS0:
  699. case ODM_RATE9M:
  700. case ODM_RATE6M:
  701. tx_ini_rate = ODM_RATE6M;
  702. break;
  703. case ODM_RATE11M:
  704. case ODM_RATE5_5M:
  705. case ODM_RATE2M:
  706. case ODM_RATE1M:
  707. tx_ini_rate = ODM_RATE1M;
  708. break;
  709. default:
  710. tx_ini_rate = ODM_RATE6M;
  711. break;
  712. }
  713. if (hal_data->current_band_type == BAND_ON_5G)
  714. if (tx_ini_rate < ODM_RATE6M)
  715. tx_ini_rate = ODM_RATE6M;
  716. return tx_ini_rate;
  717. }
  718. void rtw_update_bmc_sta_tx_rate(_adapter *adapter)
  719. {
  720. struct sta_info *psta = NULL;
  721. u8 tx_rate;
  722. psta = rtw_get_bcmc_stainfo(adapter);
  723. if (psta == NULL) {
  724. RTW_ERR(ADPT_FMT "could not get bmc_sta !!\n", ADPT_ARG(adapter));
  725. return;
  726. }
  727. if (adapter->bmc_tx_rate != MGN_UNKNOWN) {
  728. psta->init_rate = adapter->bmc_tx_rate;
  729. goto _exit;
  730. }
  731. if (adapter->stapriv.asoc_sta_count <= 2)
  732. goto _exit;
  733. tx_rate = rtw_ap_find_mini_tx_rate(adapter);
  734. #ifdef CONFIG_BMC_TX_LOW_RATE
  735. tx_rate = rtw_ap_find_bmc_rate(adapter, tx_rate);
  736. #endif
  737. psta->init_rate = hw_rate_to_m_rate(tx_rate);
  738. _exit:
  739. RTW_INFO(ADPT_FMT" BMC Tx rate - %s\n", ADPT_ARG(adapter), MGN_RATE_STR(psta->init_rate));
  740. }
  741. #endif
  742. void rtw_init_bmc_sta_tx_rate(_adapter *padapter, struct sta_info *psta)
  743. {
  744. #ifdef CONFIG_BMC_TX_LOW_RATE
  745. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  746. #endif
  747. u8 rate_idx = 0;
  748. u8 brate_table[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M,
  749. MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
  750. if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
  751. return;
  752. if (padapter->bmc_tx_rate != MGN_UNKNOWN)
  753. psta->init_rate = padapter->bmc_tx_rate;
  754. else {
  755. #ifdef CONFIG_BMC_TX_LOW_RATE
  756. if (IsEnableHWOFDM(pmlmeext->cur_wireless_mode) && (psta->cmn.ra_info.ramask && 0xFF0))
  757. rate_idx = get_lowest_rate_idx_ex(psta->cmn.ra_info.ramask, 4); /*from basic rate*/
  758. else
  759. rate_idx = get_lowest_rate_idx(psta->cmn.ra_info.ramask); /*from basic rate*/
  760. #else
  761. rate_idx = get_highest_rate_idx(psta->cmn.ra_info.ramask); /*from basic rate*/
  762. #endif
  763. if (rate_idx < 12)
  764. psta->init_rate = brate_table[rate_idx];
  765. else
  766. psta->init_rate = MGN_1M;
  767. }
  768. RTW_INFO(ADPT_FMT" BMC Init Tx rate - %s\n", ADPT_ARG(padapter), MGN_RATE_STR(psta->init_rate));
  769. }
  770. void update_bmc_sta(_adapter *padapter)
  771. {
  772. _irqL irqL;
  773. unsigned char network_type;
  774. int supportRateNum = 0;
  775. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  776. WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  777. struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
  778. if (psta) {
  779. psta->cmn.aid = 0;/* default set to 0 */
  780. #ifdef CONFIG_RTW_MESH
  781. if (MLME_IS_MESH(padapter))
  782. psta->qos_option = 1;
  783. else
  784. #endif
  785. psta->qos_option = 0;
  786. #ifdef CONFIG_80211N_HT
  787. psta->htpriv.ht_option = _FALSE;
  788. #endif /* CONFIG_80211N_HT */
  789. psta->ieee8021x_blocked = 0;
  790. _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  791. /* psta->dot118021XPrivacy = _NO_PRIVACY_; */ /* !!! remove it, because it has been set before this. */
  792. supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
  793. network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, pcur_network->Configuration.DSConfig);
  794. if (IsSupportedTxCCK(network_type))
  795. network_type = WIRELESS_11B;
  796. else if (network_type == WIRELESS_INVALID) { /* error handling */
  797. if (pcur_network->Configuration.DSConfig > 14)
  798. network_type = WIRELESS_11A;
  799. else
  800. network_type = WIRELESS_11B;
  801. }
  802. update_sta_basic_rate(psta, network_type);
  803. psta->wireless_mode = network_type;
  804. rtw_hal_update_sta_ra_info(padapter, psta);
  805. _enter_critical_bh(&psta->lock, &irqL);
  806. psta->state = _FW_LINKED;
  807. _exit_critical_bh(&psta->lock, &irqL);
  808. rtw_sta_media_status_rpt(padapter, psta, 1);
  809. rtw_init_bmc_sta_tx_rate(padapter, psta);
  810. } else
  811. RTW_INFO("add_RATid_bmc_sta error!\n");
  812. }
  813. #if defined(CONFIG_80211N_HT) && defined(CONFIG_BEAMFORMING)
  814. void update_sta_info_apmode_ht_bf_cap(_adapter *padapter, struct sta_info *psta)
  815. {
  816. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  817. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  818. struct ht_priv *phtpriv_sta = &psta->htpriv;
  819. u8 cur_beamform_cap = 0;
  820. /*Config Tx beamforming setting*/
  821. if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
  822. GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
  823. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
  824. /*Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
  825. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 6);
  826. }
  827. if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
  828. GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
  829. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
  830. /*Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
  831. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 4);
  832. }
  833. if (cur_beamform_cap)
  834. RTW_INFO("Client STA(%d) HT Beamforming Cap = 0x%02X\n", psta->cmn.aid, cur_beamform_cap);
  835. phtpriv_sta->beamform_cap = cur_beamform_cap;
  836. psta->cmn.bf_info.ht_beamform_cap = cur_beamform_cap;
  837. }
  838. #endif /*CONFIG_80211N_HT && CONFIG_BEAMFORMING*/
  839. /* notes:
  840. * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
  841. void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
  842. {
  843. _irqL irqL;
  844. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  845. struct security_priv *psecuritypriv = &padapter->securitypriv;
  846. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  847. #ifdef CONFIG_80211N_HT
  848. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  849. struct ht_priv *phtpriv_sta = &psta->htpriv;
  850. #endif /* CONFIG_80211N_HT */
  851. u8 cur_ldpc_cap = 0, cur_stbc_cap = 0;
  852. /* set intf_tag to if1 */
  853. /* psta->intf_tag = 0; */
  854. RTW_INFO("%s\n", __FUNCTION__);
  855. /*alloc macid when call rtw_alloc_stainfo(),release macid when call rtw_free_stainfo()*/
  856. if (!MLME_IS_MESH(padapter) && psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
  857. psta->ieee8021x_blocked = _TRUE;
  858. else
  859. psta->ieee8021x_blocked = _FALSE;
  860. /* update sta's cap */
  861. /* ERP */
  862. VCS_update(padapter, psta);
  863. #ifdef CONFIG_80211N_HT
  864. /* HT related cap */
  865. if (phtpriv_sta->ht_option) {
  866. /* check if sta supports rx ampdu */
  867. phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
  868. phtpriv_sta->rx_ampdu_min_spacing = (phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
  869. /* bwmode */
  870. if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
  871. psta->cmn.bw_mode = CHANNEL_WIDTH_40;
  872. else
  873. psta->cmn.bw_mode = CHANNEL_WIDTH_20;
  874. if (phtpriv_sta->op_present
  875. && !GET_HT_OP_ELE_STA_CHL_WIDTH(phtpriv_sta->ht_op))
  876. psta->cmn.bw_mode = CHANNEL_WIDTH_20;
  877. if (psta->ht_40mhz_intolerant)
  878. psta->cmn.bw_mode = CHANNEL_WIDTH_20;
  879. if (pmlmeext->cur_bwmode < psta->cmn.bw_mode)
  880. psta->cmn.bw_mode = pmlmeext->cur_bwmode;
  881. phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
  882. /* check if sta support s Short GI 20M */
  883. if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
  884. phtpriv_sta->sgi_20m = _TRUE;
  885. /* check if sta support s Short GI 40M */
  886. if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) {
  887. if (psta->cmn.bw_mode == CHANNEL_WIDTH_40) /* according to psta->bw_mode */
  888. phtpriv_sta->sgi_40m = _TRUE;
  889. else
  890. phtpriv_sta->sgi_40m = _FALSE;
  891. }
  892. psta->qos_option = _TRUE;
  893. /* B0 Config LDPC Coding Capability */
  894. if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) &&
  895. GET_HT_CAP_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
  896. SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
  897. RTW_INFO("Enable HT Tx LDPC for STA(%d)\n", psta->cmn.aid);
  898. }
  899. /* B7 B8 B9 Config STBC setting */
  900. if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) &&
  901. GET_HT_CAP_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) {
  902. SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
  903. RTW_INFO("Enable HT Tx STBC for STA(%d)\n", psta->cmn.aid);
  904. }
  905. #ifdef CONFIG_BEAMFORMING
  906. update_sta_info_apmode_ht_bf_cap(padapter, psta);
  907. #endif
  908. } else {
  909. phtpriv_sta->ampdu_enable = _FALSE;
  910. phtpriv_sta->sgi_20m = _FALSE;
  911. phtpriv_sta->sgi_40m = _FALSE;
  912. psta->cmn.bw_mode = CHANNEL_WIDTH_20;
  913. phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  914. }
  915. phtpriv_sta->ldpc_cap = cur_ldpc_cap;
  916. phtpriv_sta->stbc_cap = cur_stbc_cap;
  917. /* Rx AMPDU */
  918. send_delba(padapter, 0, psta->cmn.mac_addr);/* recipient */
  919. /* TX AMPDU */
  920. send_delba(padapter, 1, psta->cmn.mac_addr);/* */ /* originator */
  921. phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
  922. phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
  923. #endif /* CONFIG_80211N_HT */
  924. #ifdef CONFIG_80211AC_VHT
  925. update_sta_vht_info_apmode(padapter, psta);
  926. #endif
  927. psta->cmn.ra_info.is_support_sgi = query_ra_short_GI(psta, rtw_get_tx_bw_mode(padapter, psta));
  928. update_ldpc_stbc_cap(psta);
  929. /* todo: init other variables */
  930. _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  931. /* add ratid */
  932. /* add_RATid(padapter, psta); */ /* move to ap_sta_info_defer_update() */
  933. /* ap mode */
  934. rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _TRUE);
  935. _enter_critical_bh(&psta->lock, &irqL);
  936. /* Check encryption */
  937. if (!MLME_IS_MESH(padapter) && psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
  938. psta->state |= WIFI_UNDER_KEY_HANDSHAKE;
  939. psta->state |= _FW_LINKED;
  940. _exit_critical_bh(&psta->lock, &irqL);
  941. }
  942. static void update_ap_info(_adapter *padapter, struct sta_info *psta)
  943. {
  944. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  945. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  946. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  947. #ifdef CONFIG_80211N_HT
  948. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  949. #endif /* CONFIG_80211N_HT */
  950. psta->wireless_mode = pmlmeext->cur_wireless_mode;
  951. psta->bssratelen = rtw_get_rateset_len(pnetwork->SupportedRates);
  952. _rtw_memcpy(psta->bssrateset, pnetwork->SupportedRates, psta->bssratelen);
  953. #ifdef CONFIG_80211N_HT
  954. /* HT related cap */
  955. if (phtpriv_ap->ht_option) {
  956. /* check if sta supports rx ampdu */
  957. /* phtpriv_ap->ampdu_enable = phtpriv_ap->ampdu_enable; */
  958. /* check if sta support s Short GI 20M */
  959. if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
  960. phtpriv_ap->sgi_20m = _TRUE;
  961. /* check if sta support s Short GI 40M */
  962. if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40))
  963. phtpriv_ap->sgi_40m = _TRUE;
  964. psta->qos_option = _TRUE;
  965. } else {
  966. phtpriv_ap->ampdu_enable = _FALSE;
  967. phtpriv_ap->sgi_20m = _FALSE;
  968. phtpriv_ap->sgi_40m = _FALSE;
  969. }
  970. psta->cmn.bw_mode = pmlmeext->cur_bwmode;
  971. phtpriv_ap->ch_offset = pmlmeext->cur_ch_offset;
  972. phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */
  973. phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */
  974. _rtw_memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv));
  975. #ifdef CONFIG_80211AC_VHT
  976. _rtw_memcpy(&psta->vhtpriv, &pmlmepriv->vhtpriv, sizeof(struct vht_priv));
  977. #endif /* CONFIG_80211AC_VHT */
  978. #endif /* CONFIG_80211N_HT */
  979. psta->state |= WIFI_AP_STATE; /* Aries, add,fix bug of flush_cam_entry at STOP AP mode , 0724 */
  980. }
  981. static void rtw_set_hw_wmm_param(_adapter *padapter)
  982. {
  983. u8 AIFS, ECWMin, ECWMax, aSifsTime;
  984. u8 acm_mask;
  985. u16 TXOP;
  986. u32 acParm, i;
  987. u32 edca[4], inx[4];
  988. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  989. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  990. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  991. struct registry_priv *pregpriv = &padapter->registrypriv;
  992. acm_mask = 0;
  993. #ifdef CONFIG_80211N_HT
  994. if (pregpriv->ht_enable &&
  995. (is_supported_5g(pmlmeext->cur_wireless_mode) ||
  996. (pmlmeext->cur_wireless_mode & WIRELESS_11_24N)))
  997. aSifsTime = 16;
  998. else
  999. #endif /* CONFIG_80211N_HT */
  1000. aSifsTime = 10;
  1001. if (pmlmeinfo->WMM_enable == 0) {
  1002. padapter->mlmepriv.acm_mask = 0;
  1003. AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
  1004. if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11A)) {
  1005. ECWMin = 4;
  1006. ECWMax = 10;
  1007. } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
  1008. ECWMin = 5;
  1009. ECWMax = 10;
  1010. } else {
  1011. ECWMin = 4;
  1012. ECWMax = 10;
  1013. }
  1014. TXOP = 0;
  1015. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1016. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  1017. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  1018. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  1019. ECWMin = 2;
  1020. ECWMax = 3;
  1021. TXOP = 0x2f;
  1022. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1023. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  1024. } else {
  1025. edca[0] = edca[1] = edca[2] = edca[3] = 0;
  1026. /*TODO:*/
  1027. acm_mask = 0;
  1028. padapter->mlmepriv.acm_mask = acm_mask;
  1029. #if 0
  1030. /* BK */
  1031. /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
  1032. #endif
  1033. AIFS = (7 * pmlmeinfo->slotTime) + aSifsTime;
  1034. ECWMin = 4;
  1035. ECWMax = 10;
  1036. TXOP = 0;
  1037. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1038. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  1039. edca[XMIT_BK_QUEUE] = acParm;
  1040. RTW_INFO("WMM(BK): %x\n", acParm);
  1041. /* BE */
  1042. AIFS = (3 * pmlmeinfo->slotTime) + aSifsTime;
  1043. ECWMin = 4;
  1044. ECWMax = 6;
  1045. TXOP = 0;
  1046. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1047. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  1048. edca[XMIT_BE_QUEUE] = acParm;
  1049. RTW_INFO("WMM(BE): %x\n", acParm);
  1050. /* VI */
  1051. AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
  1052. ECWMin = 3;
  1053. ECWMax = 4;
  1054. TXOP = 94;
  1055. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1056. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  1057. edca[XMIT_VI_QUEUE] = acParm;
  1058. RTW_INFO("WMM(VI): %x\n", acParm);
  1059. /* VO */
  1060. AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
  1061. ECWMin = 2;
  1062. ECWMax = 3;
  1063. TXOP = 47;
  1064. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1065. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  1066. edca[XMIT_VO_QUEUE] = acParm;
  1067. RTW_INFO("WMM(VO): %x\n", acParm);
  1068. if (padapter->registrypriv.acm_method == 1)
  1069. rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
  1070. else
  1071. padapter->mlmepriv.acm_mask = acm_mask;
  1072. inx[0] = 0;
  1073. inx[1] = 1;
  1074. inx[2] = 2;
  1075. inx[3] = 3;
  1076. if (pregpriv->wifi_spec == 1) {
  1077. u32 j, tmp, change_inx = _FALSE;
  1078. /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
  1079. for (i = 0 ; i < 4 ; i++) {
  1080. for (j = i + 1 ; j < 4 ; j++) {
  1081. /* compare CW and AIFS */
  1082. if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
  1083. change_inx = _TRUE;
  1084. else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
  1085. /* compare TXOP */
  1086. if ((edca[j] >> 16) > (edca[i] >> 16))
  1087. change_inx = _TRUE;
  1088. }
  1089. if (change_inx) {
  1090. tmp = edca[i];
  1091. edca[i] = edca[j];
  1092. edca[j] = tmp;
  1093. tmp = inx[i];
  1094. inx[i] = inx[j];
  1095. inx[j] = tmp;
  1096. change_inx = _FALSE;
  1097. }
  1098. }
  1099. }
  1100. }
  1101. for (i = 0 ; i < 4 ; i++) {
  1102. pxmitpriv->wmm_para_seq[i] = inx[i];
  1103. RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
  1104. }
  1105. }
  1106. }
  1107. #ifdef CONFIG_80211N_HT
  1108. static void update_hw_ht_param(_adapter *padapter)
  1109. {
  1110. unsigned char max_AMPDU_len;
  1111. unsigned char min_MPDU_spacing;
  1112. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1113. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1114. RTW_INFO("%s\n", __FUNCTION__);
  1115. /* handle A-MPDU parameter field */
  1116. /*
  1117. AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
  1118. AMPDU_para [4:2]:Min MPDU Start Spacing
  1119. */
  1120. max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
  1121. min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
  1122. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
  1123. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
  1124. /* */
  1125. /* Config SM Power Save setting */
  1126. /* */
  1127. pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
  1128. if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC) {
  1129. #if 0
  1130. u8 i;
  1131. /* update the MCS rates */
  1132. for (i = 0; i < 16; i++)
  1133. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  1134. #endif
  1135. RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __FUNCTION__);
  1136. }
  1137. /* */
  1138. /* Config current HT Protection mode. */
  1139. /* */
  1140. /* pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3; */
  1141. }
  1142. #endif /* CONFIG_80211N_HT */
  1143. static void rtw_ap_check_scan(_adapter *padapter)
  1144. {
  1145. _irqL irqL;
  1146. _list *plist, *phead;
  1147. u32 delta_time, lifetime;
  1148. struct wlan_network *pnetwork = NULL;
  1149. WLAN_BSSID_EX *pbss = NULL;
  1150. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1151. _queue *queue = &(pmlmepriv->scanned_queue);
  1152. u8 do_scan = _FALSE;
  1153. u8 reason = RTW_AUTO_SCAN_REASON_UNSPECIFIED;
  1154. lifetime = SCANQUEUE_LIFETIME; /* 20 sec */
  1155. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1156. phead = get_list_head(queue);
  1157. if (rtw_end_of_queue_search(phead, get_next(phead)) == _TRUE)
  1158. if (padapter->registrypriv.wifi_spec) {
  1159. do_scan = _TRUE;
  1160. reason |= RTW_AUTO_SCAN_REASON_2040_BSS;
  1161. }
  1162. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1163. #ifdef CONFIG_RTW_ACS
  1164. if (padapter->registrypriv.acs_auto_scan) {
  1165. do_scan = _TRUE;
  1166. reason |= RTW_AUTO_SCAN_REASON_ACS;
  1167. rtw_acs_start(padapter);
  1168. }
  1169. #endif/*CONFIG_RTW_ACS*/
  1170. if (_TRUE == do_scan) {
  1171. RTW_INFO("%s : drv scans by itself and wait_completed\n", __func__);
  1172. rtw_drv_scan_by_self(padapter, reason);
  1173. rtw_scan_wait_completed(padapter);
  1174. }
  1175. #ifdef CONFIG_RTW_ACS
  1176. if (padapter->registrypriv.acs_auto_scan)
  1177. rtw_acs_stop(padapter);
  1178. #endif
  1179. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1180. phead = get_list_head(queue);
  1181. plist = get_next(phead);
  1182. while (1) {
  1183. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  1184. break;
  1185. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  1186. if (rtw_chset_search_ch(adapter_to_chset(padapter), pnetwork->network.Configuration.DSConfig) >= 0
  1187. && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig) == _TRUE
  1188. && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))) {
  1189. delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
  1190. if (delta_time < lifetime) {
  1191. uint ie_len = 0;
  1192. u8 *pbuf = NULL;
  1193. u8 *ie = NULL;
  1194. pbss = &pnetwork->network;
  1195. ie = pbss->IEs;
  1196. /*check if HT CAP INFO IE exists or not*/
  1197. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss->IELength - _BEACON_IE_OFFSET_));
  1198. if (pbuf == NULL) {
  1199. /* HT CAP INFO IE don't exist, it is b/g mode bss.*/
  1200. if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc))
  1201. ATOMIC_SET(&pmlmepriv->olbc, _TRUE);
  1202. if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc_ht))
  1203. ATOMIC_SET(&pmlmepriv->olbc_ht, _TRUE);
  1204. if (padapter->registrypriv.wifi_spec)
  1205. RTW_INFO("%s: %s is a/b/g ap\n", __func__, pnetwork->network.Ssid.Ssid);
  1206. }
  1207. }
  1208. }
  1209. plist = get_next(plist);
  1210. }
  1211. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1212. #ifdef CONFIG_80211N_HT
  1213. pmlmepriv->num_sta_no_ht = 0; /* reset to 0 after ap do scanning*/
  1214. #endif
  1215. }
  1216. void rtw_start_bss_hdl_after_chbw_decided(_adapter *adapter)
  1217. {
  1218. WLAN_BSSID_EX *pnetwork = &(adapter->mlmepriv.cur_network.network);
  1219. struct sta_info *sta = NULL;
  1220. /* update cur_wireless_mode */
  1221. update_wireless_mode(adapter);
  1222. /* update RRSR and RTS_INIT_RATE register after set channel and bandwidth */
  1223. UpdateBrateTbl(adapter, pnetwork->SupportedRates);
  1224. rtw_hal_set_hwreg(adapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
  1225. /* update capability after cur_wireless_mode updated */
  1226. update_capinfo(adapter, rtw_get_capability(pnetwork));
  1227. /* update bc/mc sta_info */
  1228. update_bmc_sta(adapter);
  1229. /* update AP's sta info */
  1230. sta = rtw_get_stainfo(&adapter->stapriv, pnetwork->MacAddress);
  1231. if (!sta) {
  1232. RTW_INFO(FUNC_ADPT_FMT" !sta for macaddr="MAC_FMT"\n", FUNC_ADPT_ARG(adapter), MAC_ARG(pnetwork->MacAddress));
  1233. rtw_warn_on(1);
  1234. return;
  1235. }
  1236. update_ap_info(adapter, sta);
  1237. }
  1238. #ifdef CONFIG_FW_HANDLE_TXBCN
  1239. bool rtw_ap_nums_check(_adapter *adapter)
  1240. {
  1241. if (rtw_ap_get_nums(adapter) < CONFIG_LIMITED_AP_NUM)
  1242. return _TRUE;
  1243. return _FALSE;
  1244. }
  1245. u8 rtw_ap_allocate_vapid(struct dvobj_priv *dvobj)
  1246. {
  1247. u8 vap_id;
  1248. for (vap_id = 0; vap_id < CONFIG_LIMITED_AP_NUM; vap_id++) {
  1249. if (!(dvobj->vap_map & BIT(vap_id)))
  1250. break;
  1251. }
  1252. if (vap_id < CONFIG_LIMITED_AP_NUM)
  1253. dvobj->vap_map |= BIT(vap_id);
  1254. return vap_id;
  1255. }
  1256. u8 rtw_ap_release_vapid(struct dvobj_priv *dvobj, u8 vap_id)
  1257. {
  1258. if (vap_id >= CONFIG_LIMITED_AP_NUM) {
  1259. RTW_ERR("%s - vapid(%d) failed\n", __func__, vap_id);
  1260. rtw_warn_on(1);
  1261. return _FAIL;
  1262. }
  1263. dvobj->vap_map &= ~ BIT(vap_id);
  1264. return _SUCCESS;
  1265. }
  1266. #endif
  1267. static void _rtw_iface_undersurvey_chk(const char *func, _adapter *adapter)
  1268. {
  1269. int i;
  1270. _adapter *iface;
  1271. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1272. struct mlme_priv *pmlmepriv;
  1273. for (i = 0; i < dvobj->iface_nums; i++) {
  1274. iface = dvobj->padapters[i];
  1275. if ((iface) && rtw_is_adapter_up(iface)) {
  1276. pmlmepriv = &iface->mlmepriv;
  1277. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
  1278. RTW_ERR("%s ("ADPT_FMT") under survey\n", func, ADPT_ARG(iface));
  1279. }
  1280. }
  1281. }
  1282. void start_bss_network(_adapter *padapter, struct createbss_parm *parm)
  1283. {
  1284. #define DUMP_ADAPTERS_STATUS 0
  1285. u8 mlme_act = MLME_ACTION_UNKNOWN;
  1286. u8 val8;
  1287. u16 bcn_interval;
  1288. u32 acparm;
  1289. struct registry_priv *pregpriv = &padapter->registrypriv;
  1290. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1291. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  1292. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network; /* used as input */
  1293. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1294. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1295. WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
  1296. struct dvobj_priv *pdvobj = padapter->dvobj;
  1297. s16 req_ch = REQ_CH_NONE, req_bw = REQ_BW_NONE, req_offset = REQ_OFFSET_NONE;
  1298. u8 ch_to_set = 0, bw_to_set, offset_to_set;
  1299. u8 doiqk = _FALSE;
  1300. /* use for check ch bw offset can be allowed or not */
  1301. u8 chbw_allow = _TRUE;
  1302. int i;
  1303. u8 ifbmp_ch_changed = 0;
  1304. if (parm->req_ch != 0) {
  1305. /* bypass other setting, go checking ch, bw, offset */
  1306. mlme_act = MLME_OPCH_SWITCH;
  1307. req_ch = parm->req_ch;
  1308. req_bw = parm->req_bw;
  1309. req_offset = parm->req_offset;
  1310. goto chbw_decision;
  1311. } else {
  1312. /* request comes from upper layer */
  1313. if (MLME_IS_AP(padapter))
  1314. mlme_act = MLME_AP_STARTED;
  1315. else if (MLME_IS_MESH(padapter))
  1316. mlme_act = MLME_MESH_STARTED;
  1317. else
  1318. rtw_warn_on(1);
  1319. req_ch = 0;
  1320. _rtw_memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
  1321. }
  1322. bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
  1323. /* check if there is wps ie, */
  1324. /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
  1325. /* and at first time the security ie ( RSN/WPA IE) will not include in beacon. */
  1326. if (NULL == rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
  1327. pmlmeext->bstart_bss = _TRUE;
  1328. /* todo: update wmm, ht cap */
  1329. /* pmlmeinfo->WMM_enable; */
  1330. /* pmlmeinfo->HT_enable; */
  1331. if (pmlmepriv->qospriv.qos_option)
  1332. pmlmeinfo->WMM_enable = _TRUE;
  1333. #ifdef CONFIG_80211N_HT
  1334. if (pmlmepriv->htpriv.ht_option) {
  1335. pmlmeinfo->WMM_enable = _TRUE;
  1336. pmlmeinfo->HT_enable = _TRUE;
  1337. /* pmlmeinfo->HT_info_enable = _TRUE; */
  1338. /* pmlmeinfo->HT_caps_enable = _TRUE; */
  1339. update_hw_ht_param(padapter);
  1340. }
  1341. #endif /* #CONFIG_80211N_HT */
  1342. #ifdef CONFIG_80211AC_VHT
  1343. if (pmlmepriv->vhtpriv.vht_option) {
  1344. pmlmeinfo->VHT_enable = _TRUE;
  1345. update_hw_vht_param(padapter);
  1346. }
  1347. #endif /* CONFIG_80211AC_VHT */
  1348. if (pmlmepriv->cur_network.join_res != _TRUE) { /* setting only at first time */
  1349. /* WEP Key will be set before this function, do not clear CAM. */
  1350. if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
  1351. && !MLME_IS_MESH(padapter) /* mesh group key is set before this function */
  1352. )
  1353. flush_all_cam_entry(padapter); /* clear CAM */
  1354. }
  1355. /* set MSR to AP_Mode */
  1356. Set_MSR(padapter, _HW_STATE_AP_);
  1357. /* Set BSSID REG */
  1358. rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
  1359. /* Set Security */
  1360. val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
  1361. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
  1362. /* Beacon Control related register */
  1363. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
  1364. rtw_hal_rcr_set_chk_bssid(padapter, mlme_act);
  1365. chbw_decision:
  1366. ifbmp_ch_changed = rtw_ap_chbw_decision(padapter, parm->ifbmp, parm->excl_ifbmp
  1367. , req_ch, req_bw, req_offset
  1368. , &ch_to_set, &bw_to_set, &offset_to_set, &chbw_allow);
  1369. for (i = 0; i < pdvobj->iface_nums; i++) {
  1370. if (!(parm->ifbmp & BIT(i)) || !pdvobj->padapters[i])
  1371. continue;
  1372. /* let pnetwork_mlme == pnetwork_mlmeext */
  1373. _rtw_memcpy(&(pdvobj->padapters[i]->mlmepriv.cur_network.network)
  1374. , &(pdvobj->padapters[i]->mlmeextpriv.mlmext_info.network)
  1375. , pdvobj->padapters[i]->mlmeextpriv.mlmext_info.network.Length);
  1376. rtw_start_bss_hdl_after_chbw_decided(pdvobj->padapters[i]);
  1377. /* Set EDCA param reg after update cur_wireless_mode & update_capinfo */
  1378. if (pregpriv->wifi_spec == 1)
  1379. rtw_set_hw_wmm_param(pdvobj->padapters[i]);
  1380. }
  1381. #if defined(CONFIG_DFS_MASTER)
  1382. rtw_dfs_rd_en_decision(padapter, mlme_act, parm->excl_ifbmp);
  1383. #endif
  1384. #ifdef CONFIG_MCC_MODE
  1385. if (MCC_EN(padapter)) {
  1386. /*
  1387. * due to check under rtw_ap_chbw_decision
  1388. * if under MCC mode, means req channel setting is the same as current channel setting
  1389. * if not under MCC mode, mean req channel setting is not the same as current channel setting
  1390. */
  1391. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)) {
  1392. RTW_INFO(FUNC_ADPT_FMT": req channel setting is the same as current channel setting, go to update BCN\n"
  1393. , FUNC_ADPT_ARG(padapter));
  1394. goto update_beacon;
  1395. }
  1396. }
  1397. /* issue null data to AP for all interface connecting to AP before switch channel setting for softap */
  1398. rtw_hal_mcc_issue_null_data(padapter, chbw_allow, 1);
  1399. #endif /* CONFIG_MCC_MODE */
  1400. if (!IS_CH_WAITING(adapter_to_rfctl(padapter))) {
  1401. doiqk = _TRUE;
  1402. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  1403. }
  1404. if (ch_to_set != 0) {
  1405. set_channel_bwmode(padapter, ch_to_set, offset_to_set, bw_to_set);
  1406. rtw_mi_update_union_chan_inf(padapter, ch_to_set, offset_to_set, bw_to_set);
  1407. }
  1408. doiqk = _FALSE;
  1409. rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
  1410. #ifdef CONFIG_MCC_MODE
  1411. /* after set_channel_bwmode for backup IQK */
  1412. rtw_hal_set_mcc_setting_start_bss_network(padapter, chbw_allow);
  1413. #endif
  1414. #if defined(CONFIG_IOCTL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  1415. for (i = 0; i < pdvobj->iface_nums; i++) {
  1416. if (!(ifbmp_ch_changed & BIT(i)) || !pdvobj->padapters[i])
  1417. continue;
  1418. /* pure AP is not needed*/
  1419. if (MLME_IS_GO(pdvobj->padapters[i])
  1420. || MLME_IS_MESH(pdvobj->padapters[i])
  1421. ) {
  1422. u8 ht_option = 0;
  1423. #ifdef CONFIG_80211N_HT
  1424. ht_option = pdvobj->padapters[i]->mlmepriv.htpriv.ht_option;
  1425. #endif
  1426. rtw_cfg80211_ch_switch_notify(pdvobj->padapters[i]
  1427. , pdvobj->padapters[i]->mlmeextpriv.cur_channel
  1428. , pdvobj->padapters[i]->mlmeextpriv.cur_bwmode
  1429. , pdvobj->padapters[i]->mlmeextpriv.cur_ch_offset
  1430. , ht_option);
  1431. }
  1432. }
  1433. #endif /* defined(CONFIG_IOCTL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) */
  1434. if (DUMP_ADAPTERS_STATUS) {
  1435. RTW_INFO(FUNC_ADPT_FMT" done\n", FUNC_ADPT_ARG(padapter));
  1436. dump_adapters_status(RTW_DBGDUMP , adapter_to_dvobj(padapter));
  1437. }
  1438. #ifdef CONFIG_MCC_MODE
  1439. update_beacon:
  1440. #endif
  1441. for (i = 0; i < pdvobj->iface_nums; i++) {
  1442. struct mlme_priv *mlme;
  1443. if (!(parm->ifbmp & BIT(i)) || !pdvobj->padapters[i])
  1444. continue;
  1445. /* update beacon content only if bstart_bss is _TRUE */
  1446. if (pdvobj->padapters[i]->mlmeextpriv.bstart_bss != _TRUE)
  1447. continue;
  1448. mlme = &(pdvobj->padapters[i]->mlmepriv);
  1449. #ifdef CONFIG_80211N_HT
  1450. if ((ATOMIC_READ(&mlme->olbc) == _TRUE) || (ATOMIC_READ(&mlme->olbc_ht) == _TRUE)) {
  1451. /* AP is not starting a 40 MHz BSS in presence of an 802.11g BSS. */
  1452. mlme->ht_op_mode &= (~HT_INFO_OPERATION_MODE_OP_MODE_MASK);
  1453. mlme->ht_op_mode |= OP_MODE_MAY_BE_LEGACY_STAS;
  1454. update_beacon(pdvobj->padapters[i], _HT_ADD_INFO_IE_, NULL, _FALSE);
  1455. }
  1456. #endif
  1457. update_beacon(pdvobj->padapters[i], _TIM_IE_, NULL, _FALSE);
  1458. }
  1459. if (mlme_act != MLME_OPCH_SWITCH
  1460. && pmlmeext->bstart_bss == _TRUE
  1461. ) {
  1462. #ifdef CONFIG_SUPPORT_MULTI_BCN
  1463. _irqL irqL;
  1464. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  1465. if (rtw_is_list_empty(&padapter->list)) {
  1466. #ifdef CONFIG_FW_HANDLE_TXBCN
  1467. padapter->vap_id = rtw_ap_allocate_vapid(pdvobj);
  1468. #endif
  1469. rtw_list_insert_tail(&padapter->list, get_list_head(&pdvobj->ap_if_q));
  1470. pdvobj->nr_ap_if++;
  1471. pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
  1472. }
  1473. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  1474. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  1475. rtw_ap_set_mbid_num(padapter, pdvobj->nr_ap_if);
  1476. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
  1477. #endif /*CONFIG_SWTIMER_BASED_TXBCN*/
  1478. #endif /*CONFIG_SUPPORT_MULTI_BCN*/
  1479. #ifdef CONFIG_HW_P0_TSF_SYNC
  1480. correct_TSF(padapter, mlme_act);
  1481. #endif
  1482. }
  1483. rtw_scan_wait_completed(padapter);
  1484. _rtw_iface_undersurvey_chk(__func__, padapter);
  1485. /* send beacon */
  1486. ResumeTxBeacon(padapter);
  1487. {
  1488. #if !defined(CONFIG_INTERRUPT_BASED_TXBCN)
  1489. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  1490. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  1491. if (pdvobj->nr_ap_if == 1
  1492. && mlme_act != MLME_OPCH_SWITCH
  1493. ) {
  1494. RTW_INFO("start SW BCN TIMER!\n");
  1495. _set_timer(&pdvobj->txbcn_timer, bcn_interval);
  1496. }
  1497. #else
  1498. for (i = 0; i < pdvobj->iface_nums; i++) {
  1499. if (!(parm->ifbmp & BIT(i)) || !pdvobj->padapters[i])
  1500. continue;
  1501. if (send_beacon(pdvobj->padapters[i]) == _FAIL)
  1502. RTW_INFO(ADPT_FMT" issue_beacon, fail!\n", ADPT_ARG(pdvobj->padapters[i]));
  1503. }
  1504. #endif
  1505. #endif
  1506. #endif /* !defined(CONFIG_INTERRUPT_BASED_TXBCN) */
  1507. #ifdef CONFIG_FW_HANDLE_TXBCN
  1508. if (mlme_act != MLME_OPCH_SWITCH)
  1509. rtw_ap_mbid_bcn_en(padapter, padapter->vap_id);
  1510. #endif
  1511. }
  1512. }
  1513. int rtw_check_beacon_data(_adapter *padapter, u8 *pbuf, int len)
  1514. {
  1515. int ret = _SUCCESS;
  1516. u8 *p;
  1517. u8 *pHT_caps_ie = NULL;
  1518. u8 *pHT_info_ie = NULL;
  1519. u16 cap, ht_cap = _FALSE;
  1520. uint ie_len = 0;
  1521. int group_cipher, pairwise_cipher;
  1522. u8 mfp_opt = MFP_NO;
  1523. u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
  1524. int supportRateNum = 0;
  1525. u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
  1526. u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
  1527. HT_CAP_AMPDU_DENSITY best_ampdu_density;
  1528. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1529. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1530. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1531. WLAN_BSSID_EX *pbss_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
  1532. u8 *ie = pbss_network->IEs;
  1533. u8 vht_cap = _FALSE;
  1534. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1535. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1536. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  1537. u8 rf_num = 0;
  1538. int ret_rm;
  1539. /* SSID */
  1540. /* Supported rates */
  1541. /* DS Params */
  1542. /* WLAN_EID_COUNTRY */
  1543. /* ERP Information element */
  1544. /* Extended supported rates */
  1545. /* WPA/WPA2 */
  1546. /* Wi-Fi Wireless Multimedia Extensions */
  1547. /* ht_capab, ht_oper */
  1548. /* WPS IE */
  1549. RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
  1550. if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
  1551. return _FAIL;
  1552. if (len > MAX_IE_SZ)
  1553. return _FAIL;
  1554. pbss_network->IELength = len;
  1555. _rtw_memset(ie, 0, MAX_IE_SZ);
  1556. _rtw_memcpy(ie, pbuf, pbss_network->IELength);
  1557. if (pbss_network->InfrastructureMode != Ndis802_11APMode
  1558. && pbss_network->InfrastructureMode != Ndis802_11_mesh
  1559. ) {
  1560. rtw_warn_on(1);
  1561. return _FAIL;
  1562. }
  1563. rtw_ap_check_scan(padapter);
  1564. pbss_network->Rssi = 0;
  1565. _rtw_memcpy(pbss_network->MacAddress, adapter_mac_addr(padapter), ETH_ALEN);
  1566. /* beacon interval */
  1567. p = rtw_get_beacon_interval_from_ie(ie);/* ie + 8; */ /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
  1568. /* pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p); */
  1569. pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
  1570. /* capability */
  1571. /* cap = *(unsigned short *)rtw_get_capability_from_ie(ie); */
  1572. /* cap = le16_to_cpu(cap); */
  1573. cap = RTW_GET_LE16(ie);
  1574. /* SSID */
  1575. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1576. if (p && ie_len > 0) {
  1577. _rtw_memset(&pbss_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
  1578. _rtw_memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
  1579. pbss_network->Ssid.SsidLength = ie_len;
  1580. #ifdef CONFIG_P2P
  1581. _rtw_memcpy(padapter->wdinfo.p2p_group_ssid, pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
  1582. padapter->wdinfo.p2p_group_ssid_len = pbss_network->Ssid.SsidLength;
  1583. #endif
  1584. }
  1585. #ifdef CONFIG_RTW_MESH
  1586. /* Mesh ID */
  1587. if (MLME_IS_MESH(padapter)) {
  1588. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_MESH_ID, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1589. if (p && ie_len > 0) {
  1590. _rtw_memset(&pbss_network->mesh_id, 0, sizeof(NDIS_802_11_SSID));
  1591. _rtw_memcpy(pbss_network->mesh_id.Ssid, (p + 2), ie_len);
  1592. pbss_network->mesh_id.SsidLength = ie_len;
  1593. }
  1594. }
  1595. #endif
  1596. /* chnnel */
  1597. channel = 0;
  1598. pbss_network->Configuration.Length = 0;
  1599. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1600. if (p && ie_len > 0)
  1601. channel = *(p + 2);
  1602. pbss_network->Configuration.DSConfig = channel;
  1603. _rtw_memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
  1604. /* get supported rates */
  1605. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1606. if (p != NULL) {
  1607. if (padapter->registrypriv.wireless_mode == WIRELESS_11B) {
  1608. ret_rm = rtw_remove_ie_g_rate(ie , &len, _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_);
  1609. RTW_DBG("%s, rtw_remove_ie_g_rate=%d\n", __FUNCTION__,ret_rm);
  1610. ie_len = ie_len - ret_rm;
  1611. pbss_network->IELength=pbss_network->IELength - ret_rm;
  1612. }
  1613. RTW_DBG("%s, ie_len=%u\n", __FUNCTION__, ie_len);
  1614. _rtw_memcpy(supportRate, p + 2, ie_len);
  1615. supportRateNum = ie_len;
  1616. }
  1617. /* get ext_supported rates */
  1618. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);
  1619. if (p != NULL) {
  1620. if (padapter->registrypriv.wireless_mode == WIRELESS_11B) {
  1621. pbss_network->IELength = pbss_network->IELength-*(p+1) -2;
  1622. ret_rm = rtw_ies_remove_ie(ie , &len,_BEACON_IE_OFFSET_,
  1623. _EXT_SUPPORTEDRATES_IE_,NULL,0);
  1624. RTW_DBG("%s, remove_ie of ext_supported rates =%d\n", __FUNCTION__, ret_rm);
  1625. } else {
  1626. _rtw_memcpy(supportRate + supportRateNum, p + 2, ie_len);
  1627. supportRateNum += ie_len;
  1628. }
  1629. }
  1630. network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
  1631. rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
  1632. /* parsing ERP_IE */
  1633. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1634. if (p && ie_len > 0) {
  1635. if(padapter->registrypriv.wireless_mode == WIRELESS_11B ) {
  1636. pbss_network->IELength = pbss_network->IELength - *(p+1) - 2;
  1637. ret_rm = rtw_ies_remove_ie(ie , &len, _BEACON_IE_OFFSET_, _ERPINFO_IE_,NULL,0);
  1638. RTW_DBG("%s, remove_ie of ERP_IE=%d\n", __FUNCTION__, ret_rm);
  1639. } else
  1640. ERP_IE_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
  1641. }
  1642. /* update privacy/security */
  1643. if (cap & BIT(4))
  1644. pbss_network->Privacy = 1;
  1645. else
  1646. pbss_network->Privacy = 0;
  1647. psecuritypriv->wpa_psk = 0;
  1648. /* wpa2 */
  1649. group_cipher = 0;
  1650. pairwise_cipher = 0;
  1651. psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
  1652. psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
  1653. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1654. if (p && ie_len > 0) {
  1655. if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL, &mfp_opt) == _SUCCESS) {
  1656. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  1657. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  1658. psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
  1659. psecuritypriv->wpa_psk |= BIT(1);
  1660. psecuritypriv->wpa2_group_cipher = group_cipher;
  1661. psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
  1662. #if 0
  1663. switch (group_cipher) {
  1664. case WPA_CIPHER_NONE:
  1665. psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
  1666. break;
  1667. case WPA_CIPHER_WEP40:
  1668. psecuritypriv->wpa2_group_cipher = _WEP40_;
  1669. break;
  1670. case WPA_CIPHER_TKIP:
  1671. psecuritypriv->wpa2_group_cipher = _TKIP_;
  1672. break;
  1673. case WPA_CIPHER_CCMP:
  1674. psecuritypriv->wpa2_group_cipher = _AES_;
  1675. break;
  1676. case WPA_CIPHER_WEP104:
  1677. psecuritypriv->wpa2_group_cipher = _WEP104_;
  1678. break;
  1679. }
  1680. switch (pairwise_cipher) {
  1681. case WPA_CIPHER_NONE:
  1682. psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
  1683. break;
  1684. case WPA_CIPHER_WEP40:
  1685. psecuritypriv->wpa2_pairwise_cipher = _WEP40_;
  1686. break;
  1687. case WPA_CIPHER_TKIP:
  1688. psecuritypriv->wpa2_pairwise_cipher = _TKIP_;
  1689. break;
  1690. case WPA_CIPHER_CCMP:
  1691. psecuritypriv->wpa2_pairwise_cipher = _AES_;
  1692. break;
  1693. case WPA_CIPHER_WEP104:
  1694. psecuritypriv->wpa2_pairwise_cipher = _WEP104_;
  1695. break;
  1696. }
  1697. #endif
  1698. }
  1699. }
  1700. /* wpa */
  1701. ie_len = 0;
  1702. group_cipher = 0;
  1703. pairwise_cipher = 0;
  1704. psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
  1705. psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
  1706. for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
  1707. p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
  1708. if ((p) && (_rtw_memcmp(p + 2, OUI1, 4))) {
  1709. if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  1710. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  1711. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
  1712. psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
  1713. psecuritypriv->wpa_psk |= BIT(0);
  1714. psecuritypriv->wpa_group_cipher = group_cipher;
  1715. psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
  1716. #if 0
  1717. switch (group_cipher) {
  1718. case WPA_CIPHER_NONE:
  1719. psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
  1720. break;
  1721. case WPA_CIPHER_WEP40:
  1722. psecuritypriv->wpa_group_cipher = _WEP40_;
  1723. break;
  1724. case WPA_CIPHER_TKIP:
  1725. psecuritypriv->wpa_group_cipher = _TKIP_;
  1726. break;
  1727. case WPA_CIPHER_CCMP:
  1728. psecuritypriv->wpa_group_cipher = _AES_;
  1729. break;
  1730. case WPA_CIPHER_WEP104:
  1731. psecuritypriv->wpa_group_cipher = _WEP104_;
  1732. break;
  1733. }
  1734. switch (pairwise_cipher) {
  1735. case WPA_CIPHER_NONE:
  1736. psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
  1737. break;
  1738. case WPA_CIPHER_WEP40:
  1739. psecuritypriv->wpa_pairwise_cipher = _WEP40_;
  1740. break;
  1741. case WPA_CIPHER_TKIP:
  1742. psecuritypriv->wpa_pairwise_cipher = _TKIP_;
  1743. break;
  1744. case WPA_CIPHER_CCMP:
  1745. psecuritypriv->wpa_pairwise_cipher = _AES_;
  1746. break;
  1747. case WPA_CIPHER_WEP104:
  1748. psecuritypriv->wpa_pairwise_cipher = _WEP104_;
  1749. break;
  1750. }
  1751. #endif
  1752. }
  1753. break;
  1754. }
  1755. if ((p == NULL) || (ie_len == 0))
  1756. break;
  1757. }
  1758. #ifdef CONFIG_RTW_MESH
  1759. if (MLME_IS_MESH(padapter)) {
  1760. /* MFP is mandatory for secure mesh */
  1761. if (padapter->mesh_info.mesh_auth_id)
  1762. mfp_opt = MFP_REQUIRED;
  1763. } else
  1764. #endif
  1765. if (mfp_opt == MFP_INVALID) {
  1766. RTW_INFO(FUNC_ADPT_FMT" invalid MFP setting\n", FUNC_ADPT_ARG(padapter));
  1767. return _FAIL;
  1768. }
  1769. psecuritypriv->mfp_opt = mfp_opt;
  1770. /* wmm */
  1771. ie_len = 0;
  1772. pmlmepriv->qospriv.qos_option = 0;
  1773. #ifdef CONFIG_RTW_MESH
  1774. if (MLME_IS_MESH(padapter))
  1775. pmlmepriv->qospriv.qos_option = 1;
  1776. #endif
  1777. if (pregistrypriv->wmm_enable) {
  1778. for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
  1779. p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
  1780. if ((p) && _rtw_memcmp(p + 2, WMM_PARA_IE, 6)) {
  1781. pmlmepriv->qospriv.qos_option = 1;
  1782. *(p + 8) |= BIT(7); /* QoS Info, support U-APSD */
  1783. /* disable all ACM bits since the WMM admission control is not supported */
  1784. *(p + 10) &= ~BIT(4); /* BE */
  1785. *(p + 14) &= ~BIT(4); /* BK */
  1786. *(p + 18) &= ~BIT(4); /* VI */
  1787. *(p + 22) &= ~BIT(4); /* VO */
  1788. WMM_param_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
  1789. break;
  1790. }
  1791. if ((p == NULL) || (ie_len == 0))
  1792. break;
  1793. }
  1794. }
  1795. #ifdef CONFIG_80211N_HT
  1796. if(padapter->registrypriv.ht_enable &&
  1797. is_supported_ht(padapter->registrypriv.wireless_mode)) {
  1798. /* parsing HT_CAP_IE */
  1799. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1800. if (p && ie_len > 0) {
  1801. u8 rf_type = 0;
  1802. HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor = MAX_AMPDU_FACTOR_64K;
  1803. struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
  1804. if (0) {
  1805. RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE from upper layer:\n", FUNC_ADPT_ARG(padapter));
  1806. dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
  1807. }
  1808. pHT_caps_ie = p;
  1809. ht_cap = _TRUE;
  1810. network_type |= WIRELESS_11_24N;
  1811. rtw_ht_use_default_setting(padapter);
  1812. /* Update HT Capabilities Info field */
  1813. if (pmlmepriv->htpriv.sgi_20m == _FALSE)
  1814. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_20);
  1815. if (pmlmepriv->htpriv.sgi_40m == _FALSE)
  1816. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_40);
  1817. if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX))
  1818. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_LDPC_CODING);
  1819. if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
  1820. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_TX_STBC);
  1821. if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX))
  1822. pht_cap->cap_info &= ~(IEEE80211_HT_CAP_RX_STBC_3R);
  1823. /* Update A-MPDU Parameters field */
  1824. pht_cap->ampdu_params_info &= ~(IEEE80211_HT_CAP_AMPDU_FACTOR | IEEE80211_HT_CAP_AMPDU_DENSITY);
  1825. if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
  1826. (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP)) {
  1827. rtw_hal_get_def_var(padapter, HW_VAR_BEST_AMPDU_DENSITY, &best_ampdu_density);
  1828. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (best_ampdu_density << 2));
  1829. } else
  1830. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
  1831. rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
  1832. pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & max_rx_ampdu_factor); /* set Max Rx AMPDU size to 64K */
  1833. _rtw_memcpy(&(pmlmeinfo->HT_caps), pht_cap, sizeof(struct HT_caps_element));
  1834. /* Update Supported MCS Set field */
  1835. {
  1836. struct hal_spec_t *hal_spec = GET_HAL_SPEC(padapter);
  1837. u8 rx_nss = 0;
  1838. int i;
  1839. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  1840. rx_nss = rtw_min(rf_type_to_rf_rx_cnt(rf_type), hal_spec->rx_nss_num);
  1841. /* RX MCS Bitmask */
  1842. switch (rx_nss) {
  1843. case 1:
  1844. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_1R);
  1845. break;
  1846. case 2:
  1847. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_2R);
  1848. break;
  1849. case 3:
  1850. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_3R);
  1851. break;
  1852. case 4:
  1853. set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_4R);
  1854. break;
  1855. default:
  1856. RTW_WARN("rf_type:%d or rx_nss:%u is not expected\n", rf_type, hal_spec->rx_nss_num);
  1857. }
  1858. for (i = 0; i < 10; i++)
  1859. *(HT_CAP_ELE_RX_MCS_MAP(pht_cap) + i) &= padapter->mlmeextpriv.default_supported_mcs_set[i];
  1860. }
  1861. #ifdef CONFIG_BEAMFORMING
  1862. /* Use registry value to enable HT Beamforming. */
  1863. /* ToDo: use configure file to set these capability. */
  1864. pht_cap->tx_BF_cap_info = 0;
  1865. /* HT Beamformer */
  1866. if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
  1867. /* Transmit NDP Capable */
  1868. SET_HT_CAP_TXBF_TRANSMIT_NDP_CAP(pht_cap, 1);
  1869. /* Explicit Compressed Steering Capable */
  1870. SET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pht_cap, 1);
  1871. /* Compressed Steering Number Antennas */
  1872. SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, 1);
  1873. rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMER_CAP, (u8 *)&rf_num);
  1874. SET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pht_cap, rf_num);
  1875. }
  1876. /* HT Beamformee */
  1877. if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
  1878. /* Receive NDP Capable */
  1879. SET_HT_CAP_TXBF_RECEIVE_NDP_CAP(pht_cap, 1);
  1880. /* Explicit Compressed Beamforming Feedback Capable */
  1881. SET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pht_cap, 2);
  1882. rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMEE_CAP, (u8 *)&rf_num);
  1883. SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, rf_num);
  1884. }
  1885. #endif /* CONFIG_BEAMFORMING */
  1886. _rtw_memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
  1887. if (0) {
  1888. RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE driver masked:\n", FUNC_ADPT_ARG(padapter));
  1889. dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
  1890. }
  1891. }
  1892. /* parsing HT_INFO_IE */
  1893. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1894. if (p && ie_len > 0) {
  1895. pHT_info_ie = p;
  1896. if (channel == 0)
  1897. pbss_network->Configuration.DSConfig = GET_HT_OP_ELE_PRI_CHL(pHT_info_ie + 2);
  1898. else if (channel != GET_HT_OP_ELE_PRI_CHL(pHT_info_ie + 2)) {
  1899. RTW_INFO(FUNC_ADPT_FMT" ch inconsistent, DSSS:%u, HT primary:%u\n"
  1900. , FUNC_ADPT_ARG(padapter), channel, GET_HT_OP_ELE_PRI_CHL(pHT_info_ie + 2));
  1901. }
  1902. }
  1903. }
  1904. #endif /* CONFIG_80211N_HT */
  1905. switch (network_type) {
  1906. case WIRELESS_11B:
  1907. pbss_network->NetworkTypeInUse = Ndis802_11DS;
  1908. break;
  1909. case WIRELESS_11G:
  1910. case WIRELESS_11BG:
  1911. case WIRELESS_11G_24N:
  1912. case WIRELESS_11BG_24N:
  1913. pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
  1914. break;
  1915. case WIRELESS_11A:
  1916. pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
  1917. break;
  1918. default:
  1919. pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
  1920. break;
  1921. }
  1922. pmlmepriv->cur_network.network_type = network_type;
  1923. #ifdef CONFIG_80211N_HT
  1924. pmlmepriv->htpriv.ht_option = _FALSE;
  1925. if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
  1926. (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
  1927. /* todo: */
  1928. /* ht_cap = _FALSE; */
  1929. }
  1930. /* ht_cap */
  1931. if (padapter->registrypriv.ht_enable &&
  1932. is_supported_ht(padapter->registrypriv.wireless_mode) && ht_cap == _TRUE) {
  1933. pmlmepriv->htpriv.ht_option = _TRUE;
  1934. pmlmepriv->qospriv.qos_option = 1;
  1935. pmlmepriv->htpriv.ampdu_enable = pregistrypriv->ampdu_enable ? _TRUE : _FALSE;
  1936. HT_caps_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_caps_ie);
  1937. HT_info_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_info_ie);
  1938. }
  1939. #endif
  1940. #ifdef CONFIG_80211AC_VHT
  1941. pmlmepriv->ori_vht_en = 0;
  1942. pmlmepriv->vhtpriv.vht_option = _FALSE;
  1943. if (pmlmepriv->htpriv.ht_option == _TRUE
  1944. && pbss_network->Configuration.DSConfig > 14
  1945. && REGSTY_IS_11AC_ENABLE(pregistrypriv)
  1946. && is_supported_vht(pregistrypriv->wireless_mode)
  1947. && (!rfctl->country_ent || COUNTRY_CHPLAN_EN_11AC(rfctl->country_ent))
  1948. ) {
  1949. /* Parsing VHT CAP IE */
  1950. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTCapability, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
  1951. if (p && ie_len > 0)
  1952. vht_cap = _TRUE;
  1953. /* Parsing VHT OPERATION IE */
  1954. if (vht_cap == _TRUE
  1955. && MLME_IS_MESH(padapter) /* allow only mesh temporarily before VHT IE checking is ready */
  1956. ) {
  1957. rtw_check_for_vht20(padapter, ie + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_);
  1958. pmlmepriv->ori_vht_en = 1;
  1959. pmlmepriv->vhtpriv.vht_option = _TRUE;
  1960. } else if (REGSTY_IS_11AC_AUTO(pregistrypriv)) {
  1961. rtw_vht_ies_detach(padapter, pbss_network);
  1962. rtw_vht_ies_attach(padapter, pbss_network);
  1963. }
  1964. }
  1965. if (pmlmepriv->vhtpriv.vht_option == _FALSE)
  1966. rtw_vht_ies_detach(padapter, pbss_network);
  1967. #endif /* CONFIG_80211AC_VHT */
  1968. #ifdef CONFIG_80211N_HT
  1969. if(padapter->registrypriv.ht_enable &&
  1970. is_supported_ht(padapter->registrypriv.wireless_mode) &&
  1971. pbss_network->Configuration.DSConfig <= 14 && padapter->registrypriv.wifi_spec == 1 &&
  1972. pbss_network->IELength + 10 <= MAX_IE_SZ) {
  1973. uint len = 0;
  1974. SET_EXT_CAPABILITY_ELE_BSS_COEXIST(pmlmepriv->ext_capab_ie_data, 1);
  1975. pmlmepriv->ext_capab_ie_len = 10;
  1976. rtw_set_ie(pbss_network->IEs + pbss_network->IELength, EID_EXTCapability, 8, pmlmepriv->ext_capab_ie_data, &len);
  1977. pbss_network->IELength += pmlmepriv->ext_capab_ie_len;
  1978. }
  1979. #endif /* CONFIG_80211N_HT */
  1980. pbss_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pbss_network);
  1981. rtw_ies_get_chbw(pbss_network->IEs + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_
  1982. , &pmlmepriv->ori_ch, &pmlmepriv->ori_bw, &pmlmepriv->ori_offset, 1, 1);
  1983. rtw_warn_on(pmlmepriv->ori_ch == 0);
  1984. {
  1985. /* alloc sta_info for ap itself */
  1986. struct sta_info *sta;
  1987. sta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
  1988. if (!sta) {
  1989. sta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
  1990. if (sta == NULL)
  1991. return _FAIL;
  1992. }
  1993. }
  1994. rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK);
  1995. {
  1996. int sk_band = RTW_GET_SCAN_BAND_SKIP(padapter);
  1997. if (sk_band)
  1998. RTW_CLR_SCAN_BAND_SKIP(padapter, sk_band);
  1999. }
  2000. rtw_indicate_connect(padapter);
  2001. pmlmepriv->cur_network.join_res = _TRUE;/* for check if already set beacon */
  2002. /* update bc/mc sta_info */
  2003. /* update_bmc_sta(padapter); */
  2004. return ret;
  2005. }
  2006. #if CONFIG_RTW_MACADDR_ACL
  2007. void rtw_macaddr_acl_init(_adapter *adapter, u8 period)
  2008. {
  2009. struct sta_priv *stapriv = &adapter->stapriv;
  2010. struct wlan_acl_pool *acl;
  2011. _queue *acl_node_q;
  2012. int i;
  2013. _irqL irqL;
  2014. if (period >= RTW_ACL_PERIOD_NUM) {
  2015. rtw_warn_on(1);
  2016. return;
  2017. }
  2018. acl = &stapriv->acl_list[period];
  2019. acl_node_q = &acl->acl_node_q;
  2020. _rtw_spinlock_init(&(acl_node_q->lock));
  2021. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  2022. _rtw_init_listhead(&(acl_node_q->queue));
  2023. acl->num = 0;
  2024. acl->mode = RTW_ACL_MODE_DISABLED;
  2025. for (i = 0; i < NUM_ACL; i++) {
  2026. _rtw_init_listhead(&acl->aclnode[i].list);
  2027. acl->aclnode[i].valid = _FALSE;
  2028. }
  2029. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  2030. }
  2031. static void _rtw_macaddr_acl_deinit(_adapter *adapter, u8 period, bool clear_only)
  2032. {
  2033. struct sta_priv *stapriv = &adapter->stapriv;
  2034. struct wlan_acl_pool *acl;
  2035. _queue *acl_node_q;
  2036. _irqL irqL;
  2037. _list *head, *list;
  2038. struct rtw_wlan_acl_node *acl_node;
  2039. if (period >= RTW_ACL_PERIOD_NUM) {
  2040. rtw_warn_on(1);
  2041. return;
  2042. }
  2043. acl = &stapriv->acl_list[period];
  2044. acl_node_q = &acl->acl_node_q;
  2045. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  2046. head = get_list_head(acl_node_q);
  2047. list = get_next(head);
  2048. while (rtw_end_of_queue_search(head, list) == _FALSE) {
  2049. acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
  2050. list = get_next(list);
  2051. if (acl_node->valid == _TRUE) {
  2052. acl_node->valid = _FALSE;
  2053. rtw_list_delete(&acl_node->list);
  2054. acl->num--;
  2055. }
  2056. }
  2057. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  2058. if (!clear_only)
  2059. _rtw_spinlock_free(&(acl_node_q->lock));
  2060. rtw_warn_on(acl->num);
  2061. acl->mode = RTW_ACL_MODE_DISABLED;
  2062. }
  2063. void rtw_macaddr_acl_deinit(_adapter *adapter, u8 period)
  2064. {
  2065. _rtw_macaddr_acl_deinit(adapter, period, 0);
  2066. }
  2067. void rtw_macaddr_acl_clear(_adapter *adapter, u8 period)
  2068. {
  2069. _rtw_macaddr_acl_deinit(adapter, period, 1);
  2070. }
  2071. void rtw_set_macaddr_acl(_adapter *adapter, u8 period, int mode)
  2072. {
  2073. struct sta_priv *stapriv = &adapter->stapriv;
  2074. struct wlan_acl_pool *acl;
  2075. if (period >= RTW_ACL_PERIOD_NUM) {
  2076. rtw_warn_on(1);
  2077. return;
  2078. }
  2079. acl = &stapriv->acl_list[period];
  2080. RTW_INFO(FUNC_ADPT_FMT" p=%u, mode=%d\n"
  2081. , FUNC_ADPT_ARG(adapter), period, mode);
  2082. acl->mode = mode;
  2083. }
  2084. int rtw_acl_add_sta(_adapter *adapter, u8 period, const u8 *addr)
  2085. {
  2086. _irqL irqL;
  2087. _list *list, *head;
  2088. u8 existed = 0;
  2089. int i = -1, ret = 0;
  2090. struct rtw_wlan_acl_node *acl_node;
  2091. struct sta_priv *stapriv = &adapter->stapriv;
  2092. struct wlan_acl_pool *acl;
  2093. _queue *acl_node_q;
  2094. if (period >= RTW_ACL_PERIOD_NUM) {
  2095. rtw_warn_on(1);
  2096. ret = -1;
  2097. goto exit;
  2098. }
  2099. acl = &stapriv->acl_list[period];
  2100. acl_node_q = &acl->acl_node_q;
  2101. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  2102. head = get_list_head(acl_node_q);
  2103. list = get_next(head);
  2104. /* search for existed entry */
  2105. while (rtw_end_of_queue_search(head, list) == _FALSE) {
  2106. acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
  2107. list = get_next(list);
  2108. if (_rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
  2109. if (acl_node->valid == _TRUE) {
  2110. existed = 1;
  2111. break;
  2112. }
  2113. }
  2114. }
  2115. if (existed)
  2116. goto release_lock;
  2117. if (acl->num >= NUM_ACL)
  2118. goto release_lock;
  2119. /* find empty one and use */
  2120. for (i = 0; i < NUM_ACL; i++) {
  2121. acl_node = &acl->aclnode[i];
  2122. if (acl_node->valid == _FALSE) {
  2123. _rtw_init_listhead(&acl_node->list);
  2124. _rtw_memcpy(acl_node->addr, addr, ETH_ALEN);
  2125. acl_node->valid = _TRUE;
  2126. rtw_list_insert_tail(&acl_node->list, get_list_head(acl_node_q));
  2127. acl->num++;
  2128. break;
  2129. }
  2130. }
  2131. release_lock:
  2132. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  2133. if (!existed && (i < 0 || i >= NUM_ACL))
  2134. ret = -1;
  2135. RTW_INFO(FUNC_ADPT_FMT" p=%u "MAC_FMT" %s (acl_num=%d)\n"
  2136. , FUNC_ADPT_ARG(adapter), period, MAC_ARG(addr)
  2137. , (existed ? "existed" : ((i < 0 || i >= NUM_ACL) ? "no room" : "added"))
  2138. , acl->num);
  2139. exit:
  2140. return ret;
  2141. }
  2142. int rtw_acl_remove_sta(_adapter *adapter, u8 period, const u8 *addr)
  2143. {
  2144. _irqL irqL;
  2145. _list *list, *head;
  2146. int ret = 0;
  2147. struct rtw_wlan_acl_node *acl_node;
  2148. struct sta_priv *stapriv = &adapter->stapriv;
  2149. struct wlan_acl_pool *acl;
  2150. _queue *acl_node_q;
  2151. u8 is_baddr = is_broadcast_mac_addr(addr);
  2152. u8 match = 0;
  2153. if (period >= RTW_ACL_PERIOD_NUM) {
  2154. rtw_warn_on(1);
  2155. goto exit;
  2156. }
  2157. acl = &stapriv->acl_list[period];
  2158. acl_node_q = &acl->acl_node_q;
  2159. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  2160. head = get_list_head(acl_node_q);
  2161. list = get_next(head);
  2162. while (rtw_end_of_queue_search(head, list) == _FALSE) {
  2163. acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
  2164. list = get_next(list);
  2165. if (is_baddr || _rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
  2166. if (acl_node->valid == _TRUE) {
  2167. acl_node->valid = _FALSE;
  2168. rtw_list_delete(&acl_node->list);
  2169. acl->num--;
  2170. match = 1;
  2171. }
  2172. }
  2173. }
  2174. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  2175. RTW_INFO(FUNC_ADPT_FMT" p=%u "MAC_FMT" %s (acl_num=%d)\n"
  2176. , FUNC_ADPT_ARG(adapter), period, MAC_ARG(addr)
  2177. , is_baddr ? "clear all" : (match ? "match" : "no found")
  2178. , acl->num);
  2179. exit:
  2180. return ret;
  2181. }
  2182. #endif /* CONFIG_RTW_MACADDR_ACL */
  2183. u8 rtw_ap_set_sta_key(_adapter *adapter, const u8 *addr, u8 alg, const u8 *key, u8 keyid, u8 gk)
  2184. {
  2185. struct cmd_priv *cmdpriv = &adapter->cmdpriv;
  2186. struct cmd_obj *cmd;
  2187. struct set_stakey_parm *param;
  2188. u8 res = _SUCCESS;
  2189. cmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  2190. if (cmd == NULL) {
  2191. res = _FAIL;
  2192. goto exit;
  2193. }
  2194. param = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
  2195. if (param == NULL) {
  2196. rtw_mfree((u8 *) cmd, sizeof(struct cmd_obj));
  2197. res = _FAIL;
  2198. goto exit;
  2199. }
  2200. init_h2fwcmd_w_parm_no_rsp(cmd, param, _SetStaKey_CMD_);
  2201. _rtw_memcpy(param->addr, addr, ETH_ALEN);
  2202. param->algorithm = alg;
  2203. param->keyid = keyid;
  2204. _rtw_memcpy(param->key, key, 16);
  2205. param->gk = gk;
  2206. res = rtw_enqueue_cmd(cmdpriv, cmd);
  2207. exit:
  2208. return res;
  2209. }
  2210. u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
  2211. {
  2212. return rtw_ap_set_sta_key(padapter
  2213. , psta->cmn.mac_addr
  2214. , psta->dot118021XPrivacy
  2215. , psta->dot118021x_UncstKey.skey
  2216. , 0
  2217. , 0
  2218. );
  2219. }
  2220. static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
  2221. {
  2222. u8 keylen;
  2223. struct cmd_obj *pcmd;
  2224. struct setkey_parm *psetkeyparm;
  2225. struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
  2226. int res = _SUCCESS;
  2227. /* RTW_INFO("%s\n", __FUNCTION__); */
  2228. pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  2229. if (pcmd == NULL) {
  2230. res = _FAIL;
  2231. goto exit;
  2232. }
  2233. psetkeyparm = (struct setkey_parm *)rtw_zmalloc(sizeof(struct setkey_parm));
  2234. if (psetkeyparm == NULL) {
  2235. rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
  2236. res = _FAIL;
  2237. goto exit;
  2238. }
  2239. _rtw_memset(psetkeyparm, 0, sizeof(struct setkey_parm));
  2240. psetkeyparm->keyid = (u8)keyid;
  2241. if (is_wep_enc(alg))
  2242. padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
  2243. psetkeyparm->algorithm = alg;
  2244. psetkeyparm->set_tx = set_tx;
  2245. switch (alg) {
  2246. case _WEP40_:
  2247. keylen = 5;
  2248. break;
  2249. case _WEP104_:
  2250. keylen = 13;
  2251. break;
  2252. case _TKIP_:
  2253. case _TKIP_WTMIC_:
  2254. case _AES_:
  2255. default:
  2256. keylen = 16;
  2257. }
  2258. _rtw_memcpy(&(psetkeyparm->key[0]), key, keylen);
  2259. pcmd->cmdcode = _SetKey_CMD_;
  2260. pcmd->parmbuf = (u8 *)psetkeyparm;
  2261. pcmd->cmdsz = (sizeof(struct setkey_parm));
  2262. pcmd->rsp = NULL;
  2263. pcmd->rspsz = 0;
  2264. _rtw_init_listhead(&pcmd->list);
  2265. res = rtw_enqueue_cmd(pcmdpriv, pcmd);
  2266. exit:
  2267. return res;
  2268. }
  2269. int rtw_ap_set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
  2270. {
  2271. RTW_INFO("%s\n", __FUNCTION__);
  2272. return rtw_ap_set_key(padapter, key, alg, keyid, 1);
  2273. }
  2274. int rtw_ap_set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx)
  2275. {
  2276. u8 alg;
  2277. switch (keylen) {
  2278. case 5:
  2279. alg = _WEP40_;
  2280. break;
  2281. case 13:
  2282. alg = _WEP104_;
  2283. break;
  2284. default:
  2285. alg = _NO_PRIVACY_;
  2286. }
  2287. RTW_INFO("%s\n", __FUNCTION__);
  2288. return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
  2289. }
  2290. u8 rtw_ap_bmc_frames_hdl(_adapter *padapter)
  2291. {
  2292. #define HIQ_XMIT_COUNTS (6)
  2293. _irqL irqL;
  2294. struct sta_info *psta_bmc;
  2295. _list *xmitframe_plist, *xmitframe_phead;
  2296. struct xmit_frame *pxmitframe = NULL;
  2297. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  2298. struct sta_priv *pstapriv = &padapter->stapriv;
  2299. bool update_tim = _FALSE;
  2300. if (padapter->registrypriv.wifi_spec != 1)
  2301. return H2C_SUCCESS;
  2302. psta_bmc = rtw_get_bcmc_stainfo(padapter);
  2303. if (!psta_bmc)
  2304. return H2C_SUCCESS;
  2305. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  2306. if ((rtw_tim_map_is_set(padapter, pstapriv->tim_bitmap, 0)) && (psta_bmc->sleepq_len > 0)) {
  2307. int tx_counts = 0;
  2308. _update_beacon(padapter, _TIM_IE_, NULL, _FALSE, "update TIM with TIB=1");
  2309. RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);
  2310. xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
  2311. xmitframe_plist = get_next(xmitframe_phead);
  2312. while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
  2313. pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
  2314. xmitframe_plist = get_next(xmitframe_plist);
  2315. rtw_list_delete(&pxmitframe->list);
  2316. psta_bmc->sleepq_len--;
  2317. tx_counts++;
  2318. if (psta_bmc->sleepq_len > 0)
  2319. pxmitframe->attrib.mdata = 1;
  2320. else
  2321. pxmitframe->attrib.mdata = 0;
  2322. if (tx_counts == HIQ_XMIT_COUNTS)
  2323. pxmitframe->attrib.mdata = 0;
  2324. pxmitframe->attrib.triggered = 1;
  2325. if (xmitframe_hiq_filter(pxmitframe) == _TRUE)
  2326. pxmitframe->attrib.qsel = QSLT_HIGH;/*HIQ*/
  2327. rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
  2328. if (tx_counts == HIQ_XMIT_COUNTS)
  2329. break;
  2330. }
  2331. } else {
  2332. if (psta_bmc->sleepq_len == 0) {
  2333. /*RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);*/
  2334. if (rtw_tim_map_is_set(padapter, pstapriv->tim_bitmap, 0))
  2335. update_tim = _TRUE;
  2336. rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, 0);
  2337. rtw_tim_map_clear(padapter, pstapriv->sta_dz_bitmap, 0);
  2338. if (update_tim == _TRUE) {
  2339. RTW_INFO("clear TIB\n");
  2340. _update_beacon(padapter, _TIM_IE_, NULL, _TRUE, "bmc sleepq and HIQ empty");
  2341. }
  2342. }
  2343. }
  2344. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  2345. #if 0
  2346. /* HIQ Check */
  2347. rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
  2348. while (_FALSE == empty && rtw_get_passing_time_ms(start) < 3000) {
  2349. rtw_msleep_os(100);
  2350. rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
  2351. }
  2352. printk("check if hiq empty=%d\n", empty);
  2353. #endif
  2354. return H2C_SUCCESS;
  2355. }
  2356. #ifdef CONFIG_NATIVEAP_MLME
  2357. static void associated_stainfo_update(_adapter *padapter, struct sta_info *psta, u32 sta_info_type)
  2358. {
  2359. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2360. RTW_INFO("%s: "MAC_FMT", updated_type=0x%x\n", __func__, MAC_ARG(psta->cmn.mac_addr), sta_info_type);
  2361. #ifdef CONFIG_80211N_HT
  2362. if (sta_info_type & STA_INFO_UPDATE_BW) {
  2363. if ((psta->flags & WLAN_STA_HT) && !psta->ht_20mhz_set) {
  2364. if (pmlmepriv->sw_to_20mhz) {
  2365. psta->cmn.bw_mode = CHANNEL_WIDTH_20;
  2366. /*psta->htpriv.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;*/
  2367. psta->htpriv.sgi_40m = _FALSE;
  2368. } else {
  2369. /*TODO: Switch back to 40MHZ?80MHZ*/
  2370. }
  2371. }
  2372. }
  2373. #endif /* CONFIG_80211N_HT */
  2374. /*
  2375. if (sta_info_type & STA_INFO_UPDATE_RATE) {
  2376. }
  2377. */
  2378. if (sta_info_type & STA_INFO_UPDATE_PROTECTION_MODE)
  2379. VCS_update(padapter, psta);
  2380. /*
  2381. if (sta_info_type & STA_INFO_UPDATE_CAP) {
  2382. }
  2383. if (sta_info_type & STA_INFO_UPDATE_HT_CAP) {
  2384. }
  2385. if (sta_info_type & STA_INFO_UPDATE_VHT_CAP) {
  2386. }
  2387. */
  2388. }
  2389. static void update_bcn_ext_capab_ie(_adapter *padapter)
  2390. {
  2391. sint ie_len = 0;
  2392. unsigned char *pbuf;
  2393. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2394. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2395. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2396. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  2397. u8 *ie = pnetwork->IEs;
  2398. u8 null_extcap_data[8] = {0};
  2399. pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_CAP_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  2400. if (pbuf && ie_len > 0)
  2401. rtw_remove_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_);
  2402. if ((pmlmepriv->ext_capab_ie_len > 0) &&
  2403. (_rtw_memcmp(pmlmepriv->ext_capab_ie_data, null_extcap_data, sizeof(null_extcap_data)) == _FALSE))
  2404. rtw_add_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_, pmlmepriv->ext_capab_ie_data, pmlmepriv->ext_capab_ie_len);
  2405. }
  2406. static void update_bcn_erpinfo_ie(_adapter *padapter)
  2407. {
  2408. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2409. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2410. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2411. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  2412. unsigned char *p, *ie = pnetwork->IEs;
  2413. u32 len = 0;
  2414. RTW_INFO("%s, ERP_enable=%d\n", __FUNCTION__, pmlmeinfo->ERP_enable);
  2415. if (!pmlmeinfo->ERP_enable)
  2416. return;
  2417. /* parsing ERP_IE */
  2418. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  2419. if (p && len > 0) {
  2420. PNDIS_802_11_VARIABLE_IEs pIE = (PNDIS_802_11_VARIABLE_IEs)p;
  2421. if (pmlmepriv->num_sta_non_erp == 1)
  2422. pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
  2423. else
  2424. pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
  2425. if (pmlmepriv->num_sta_no_short_preamble > 0)
  2426. pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
  2427. else
  2428. pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
  2429. ERP_IE_handler(padapter, pIE);
  2430. }
  2431. }
  2432. static void update_bcn_htcap_ie(_adapter *padapter)
  2433. {
  2434. RTW_INFO("%s\n", __FUNCTION__);
  2435. }
  2436. static void update_bcn_htinfo_ie(_adapter *padapter)
  2437. {
  2438. #ifdef CONFIG_80211N_HT
  2439. /*
  2440. u8 beacon_updated = _FALSE;
  2441. u32 sta_info_update_type = STA_INFO_UPDATE_NONE;
  2442. */
  2443. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2444. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2445. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2446. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  2447. unsigned char *p, *ie = pnetwork->IEs;
  2448. u32 len = 0;
  2449. if (pmlmepriv->htpriv.ht_option == _FALSE)
  2450. return;
  2451. if (pmlmeinfo->HT_info_enable != 1)
  2452. return;
  2453. RTW_INFO("%s current operation mode=0x%X\n",
  2454. __FUNCTION__, pmlmepriv->ht_op_mode);
  2455. RTW_INFO("num_sta_40mhz_intolerant(%d), 20mhz_width_req(%d), intolerant_ch_rpt(%d), olbc(%d)\n",
  2456. pmlmepriv->num_sta_40mhz_intolerant, pmlmepriv->ht_20mhz_width_req, pmlmepriv->ht_intolerant_ch_reported, ATOMIC_READ(&pmlmepriv->olbc));
  2457. /*parsing HT_INFO_IE, currently only update ht_op_mode - pht_info->infos[1] & pht_info->infos[2] for wifi logo test*/
  2458. p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
  2459. if (p && len > 0) {
  2460. struct HT_info_element *pht_info = NULL;
  2461. pht_info = (struct HT_info_element *)(p + 2);
  2462. /* for STA Channel Width/Secondary Channel Offset*/
  2463. if ((pmlmepriv->sw_to_20mhz == 0) && (pmlmeext->cur_channel <= 14)) {
  2464. if ((pmlmepriv->num_sta_40mhz_intolerant > 0) || (pmlmepriv->ht_20mhz_width_req == _TRUE)
  2465. || (pmlmepriv->ht_intolerant_ch_reported == _TRUE) || (ATOMIC_READ(&pmlmepriv->olbc) == _TRUE)) {
  2466. SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info, 0);
  2467. SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 0);
  2468. pmlmepriv->sw_to_20mhz = 1;
  2469. /*
  2470. sta_info_update_type |= STA_INFO_UPDATE_BW;
  2471. beacon_updated = _TRUE;
  2472. */
  2473. RTW_INFO("%s:switching to 20Mhz\n", __FUNCTION__);
  2474. /*TODO : cur_bwmode/cur_ch_offset switches to 20Mhz*/
  2475. }
  2476. } else {
  2477. if ((pmlmepriv->num_sta_40mhz_intolerant == 0) && (pmlmepriv->ht_20mhz_width_req == _FALSE)
  2478. && (pmlmepriv->ht_intolerant_ch_reported == _FALSE) && (ATOMIC_READ(&pmlmepriv->olbc) == _FALSE)) {
  2479. if (pmlmeext->cur_bwmode >= CHANNEL_WIDTH_40) {
  2480. SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 1);
  2481. SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info,
  2482. (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) ?
  2483. HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE : HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW);
  2484. pmlmepriv->sw_to_20mhz = 0;
  2485. /*
  2486. sta_info_update_type |= STA_INFO_UPDATE_BW;
  2487. beacon_updated = _TRUE;
  2488. */
  2489. RTW_INFO("%s:switching back to 40Mhz\n", __FUNCTION__);
  2490. }
  2491. }
  2492. }
  2493. /* to update ht_op_mode*/
  2494. *(u16 *)(pht_info->infos + 1) = cpu_to_le16(pmlmepriv->ht_op_mode);
  2495. }
  2496. /*associated_clients_update(padapter, beacon_updated, sta_info_update_type);*/
  2497. #endif /* CONFIG_80211N_HT */
  2498. }
  2499. static void update_bcn_rsn_ie(_adapter *padapter)
  2500. {
  2501. RTW_INFO("%s\n", __FUNCTION__);
  2502. }
  2503. static void update_bcn_wpa_ie(_adapter *padapter)
  2504. {
  2505. RTW_INFO("%s\n", __FUNCTION__);
  2506. }
  2507. static void update_bcn_wmm_ie(_adapter *padapter)
  2508. {
  2509. RTW_INFO("%s\n", __FUNCTION__);
  2510. }
  2511. static void update_bcn_wps_ie(_adapter *padapter)
  2512. {
  2513. u8 *pwps_ie = NULL, *pwps_ie_src, *premainder_ie, *pbackup_remainder_ie = NULL;
  2514. uint wps_ielen = 0, wps_offset, remainder_ielen;
  2515. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2516. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2517. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2518. WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
  2519. unsigned char *ie = pnetwork->IEs;
  2520. u32 ielen = pnetwork->IELength;
  2521. RTW_INFO("%s\n", __FUNCTION__);
  2522. pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
  2523. if (pwps_ie == NULL || wps_ielen == 0)
  2524. return;
  2525. pwps_ie_src = pmlmepriv->wps_beacon_ie;
  2526. if (pwps_ie_src == NULL)
  2527. return;
  2528. wps_offset = (uint)(pwps_ie - ie);
  2529. premainder_ie = pwps_ie + wps_ielen;
  2530. remainder_ielen = ielen - wps_offset - wps_ielen;
  2531. if (remainder_ielen > 0) {
  2532. pbackup_remainder_ie = rtw_malloc(remainder_ielen);
  2533. if (pbackup_remainder_ie)
  2534. _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
  2535. }
  2536. wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
  2537. if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
  2538. _rtw_memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
  2539. pwps_ie += (wps_ielen + 2);
  2540. if (pbackup_remainder_ie)
  2541. _rtw_memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
  2542. /* update IELength */
  2543. pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
  2544. }
  2545. if (pbackup_remainder_ie)
  2546. rtw_mfree(pbackup_remainder_ie, remainder_ielen);
  2547. /* deal with the case without set_tx_beacon_cmd() in update_beacon() */
  2548. #if defined(CONFIG_INTERRUPT_BASED_TXBCN) || defined(CONFIG_PCI_HCI)
  2549. if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
  2550. u8 sr = 0;
  2551. rtw_get_wps_attr_content(pwps_ie_src, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
  2552. if (sr) {
  2553. set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
  2554. RTW_INFO("%s, set WIFI_UNDER_WPS\n", __func__);
  2555. } else {
  2556. clr_fwstate(pmlmepriv, WIFI_UNDER_WPS);
  2557. RTW_INFO("%s, clr WIFI_UNDER_WPS\n", __func__);
  2558. }
  2559. }
  2560. #endif
  2561. }
  2562. static void update_bcn_p2p_ie(_adapter *padapter)
  2563. {
  2564. }
  2565. static void update_bcn_vendor_spec_ie(_adapter *padapter, u8 *oui)
  2566. {
  2567. RTW_INFO("%s\n", __FUNCTION__);
  2568. if (_rtw_memcmp(RTW_WPA_OUI, oui, 4))
  2569. update_bcn_wpa_ie(padapter);
  2570. else if (_rtw_memcmp(WMM_OUI, oui, 4))
  2571. update_bcn_wmm_ie(padapter);
  2572. else if (_rtw_memcmp(WPS_OUI, oui, 4))
  2573. update_bcn_wps_ie(padapter);
  2574. else if (_rtw_memcmp(P2P_OUI, oui, 4))
  2575. update_bcn_p2p_ie(padapter);
  2576. else
  2577. RTW_INFO("unknown OUI type!\n");
  2578. }
  2579. void _update_beacon(_adapter *padapter, u8 ie_id, u8 *oui, u8 tx, const char *tag)
  2580. {
  2581. _irqL irqL;
  2582. struct mlme_priv *pmlmepriv;
  2583. struct mlme_ext_priv *pmlmeext;
  2584. bool updated = 1; /* treat as upadated by default */
  2585. if (!padapter)
  2586. return;
  2587. pmlmepriv = &(padapter->mlmepriv);
  2588. pmlmeext = &(padapter->mlmeextpriv);
  2589. if (pmlmeext->bstart_bss == _FALSE)
  2590. return;
  2591. _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  2592. switch (ie_id) {
  2593. case _TIM_IE_:
  2594. update_BCNTIM(padapter);
  2595. break;
  2596. case _ERPINFO_IE_:
  2597. update_bcn_erpinfo_ie(padapter);
  2598. break;
  2599. case _HT_CAPABILITY_IE_:
  2600. update_bcn_htcap_ie(padapter);
  2601. break;
  2602. case _RSN_IE_2_:
  2603. update_bcn_rsn_ie(padapter);
  2604. break;
  2605. case _HT_ADD_INFO_IE_:
  2606. update_bcn_htinfo_ie(padapter);
  2607. break;
  2608. case _EXT_CAP_IE_:
  2609. update_bcn_ext_capab_ie(padapter);
  2610. break;
  2611. #ifdef CONFIG_RTW_MESH
  2612. case WLAN_EID_MESH_CONFIG:
  2613. updated = rtw_mesh_update_bss_peering_status(padapter, &(pmlmeext->mlmext_info.network));
  2614. updated |= rtw_mesh_update_bss_formation_info(padapter, &(pmlmeext->mlmext_info.network));
  2615. updated |= rtw_mesh_update_bss_forwarding_state(padapter, &(pmlmeext->mlmext_info.network));
  2616. break;
  2617. #endif
  2618. case _VENDOR_SPECIFIC_IE_:
  2619. update_bcn_vendor_spec_ie(padapter, oui);
  2620. break;
  2621. case 0xFF:
  2622. default:
  2623. break;
  2624. }
  2625. if (updated)
  2626. pmlmepriv->update_bcn = _TRUE;
  2627. _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
  2628. #ifndef CONFIG_INTERRUPT_BASED_TXBCN
  2629. #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  2630. if (tx && updated) {
  2631. /* send_beacon(padapter); */ /* send_beacon must execute on TSR level */
  2632. if (0)
  2633. RTW_INFO(FUNC_ADPT_FMT" ie_id:%u - %s\n", FUNC_ADPT_ARG(padapter), ie_id, tag);
  2634. set_tx_beacon_cmd(padapter);
  2635. }
  2636. #else
  2637. {
  2638. /* PCI will issue beacon when BCN interrupt occurs. */
  2639. }
  2640. #endif
  2641. #endif /* !CONFIG_INTERRUPT_BASED_TXBCN */
  2642. }
  2643. #ifdef CONFIG_80211N_HT
  2644. void rtw_process_public_act_bsscoex(_adapter *padapter, u8 *pframe, uint frame_len)
  2645. {
  2646. struct sta_info *psta;
  2647. struct sta_priv *pstapriv = &padapter->stapriv;
  2648. u8 beacon_updated = _FALSE;
  2649. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2650. u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  2651. uint frame_body_len = frame_len - sizeof(struct rtw_ieee80211_hdr_3addr);
  2652. u8 category, action;
  2653. psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
  2654. if (psta == NULL)
  2655. return;
  2656. category = frame_body[0];
  2657. action = frame_body[1];
  2658. if (frame_body_len > 0) {
  2659. if ((frame_body[2] == EID_BSSCoexistence) && (frame_body[3] > 0)) {
  2660. u8 ie_data = frame_body[4];
  2661. if (ie_data & RTW_WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
  2662. if (psta->ht_40mhz_intolerant == 0) {
  2663. psta->ht_40mhz_intolerant = 1;
  2664. pmlmepriv->num_sta_40mhz_intolerant++;
  2665. beacon_updated = _TRUE;
  2666. }
  2667. } else if (ie_data & RTW_WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ) {
  2668. if (pmlmepriv->ht_20mhz_width_req == _FALSE) {
  2669. pmlmepriv->ht_20mhz_width_req = _TRUE;
  2670. beacon_updated = _TRUE;
  2671. }
  2672. } else
  2673. beacon_updated = _FALSE;
  2674. }
  2675. }
  2676. if (frame_body_len > 8) {
  2677. /* if EID_BSSIntolerantChlReport ie exists */
  2678. if ((frame_body[5] == EID_BSSIntolerantChlReport) && (frame_body[6] > 0)) {
  2679. /*todo:*/
  2680. if (pmlmepriv->ht_intolerant_ch_reported == _FALSE) {
  2681. pmlmepriv->ht_intolerant_ch_reported = _TRUE;
  2682. beacon_updated = _TRUE;
  2683. }
  2684. }
  2685. }
  2686. if (beacon_updated) {
  2687. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
  2688. associated_stainfo_update(padapter, psta, STA_INFO_UPDATE_BW);
  2689. }
  2690. }
  2691. void rtw_process_ht_action_smps(_adapter *padapter, u8 *ta, u8 ctrl_field)
  2692. {
  2693. u8 e_field, m_field;
  2694. struct sta_info *psta;
  2695. struct sta_priv *pstapriv = &padapter->stapriv;
  2696. psta = rtw_get_stainfo(pstapriv, ta);
  2697. if (psta == NULL)
  2698. return;
  2699. e_field = (ctrl_field & BIT(0)) ? 1 : 0;
  2700. m_field = (ctrl_field & BIT(1)) ? 1 : 0;
  2701. if (e_field) {
  2702. /* enable */
  2703. /* 0:static SMPS, 1:dynamic SMPS, 3:SMPS disabled, 2:reserved*/
  2704. if (m_field) /*mode*/
  2705. psta->htpriv.smps_cap = 1;
  2706. else
  2707. psta->htpriv.smps_cap = 0;
  2708. } else {
  2709. /*disable*/
  2710. psta->htpriv.smps_cap = 3;
  2711. }
  2712. rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta);
  2713. }
  2714. /*
  2715. op_mode
  2716. Set to 0 (HT pure) under the followign conditions
  2717. - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
  2718. - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
  2719. Set to 1 (HT non-member protection) if there may be non-HT STAs
  2720. in both the primary and the secondary channel
  2721. Set to 2 if only HT STAs are associated in BSS,
  2722. however and at least one 20 MHz HT STA is associated
  2723. Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
  2724. (currently non-GF HT station is considered as non-HT STA also)
  2725. */
  2726. int rtw_ht_operation_update(_adapter *padapter)
  2727. {
  2728. u16 cur_op_mode, new_op_mode;
  2729. int op_mode_changes = 0;
  2730. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2731. struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
  2732. if (pmlmepriv->htpriv.ht_option == _FALSE)
  2733. return 0;
  2734. /*if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
  2735. return 0;*/
  2736. RTW_INFO("%s current operation mode=0x%X\n",
  2737. __FUNCTION__, pmlmepriv->ht_op_mode);
  2738. if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
  2739. && pmlmepriv->num_sta_ht_no_gf) {
  2740. pmlmepriv->ht_op_mode |=
  2741. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  2742. op_mode_changes++;
  2743. } else if ((pmlmepriv->ht_op_mode &
  2744. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
  2745. pmlmepriv->num_sta_ht_no_gf == 0) {
  2746. pmlmepriv->ht_op_mode &=
  2747. ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  2748. op_mode_changes++;
  2749. }
  2750. if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  2751. (pmlmepriv->num_sta_no_ht || ATOMIC_READ(&pmlmepriv->olbc_ht))) {
  2752. pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  2753. op_mode_changes++;
  2754. } else if ((pmlmepriv->ht_op_mode &
  2755. HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  2756. (pmlmepriv->num_sta_no_ht == 0 && !ATOMIC_READ(&pmlmepriv->olbc_ht))) {
  2757. pmlmepriv->ht_op_mode &=
  2758. ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  2759. op_mode_changes++;
  2760. }
  2761. /* Note: currently we switch to the MIXED op mode if HT non-greenfield
  2762. * station is associated. Probably it's a theoretical case, since
  2763. * it looks like all known HT STAs support greenfield.
  2764. */
  2765. new_op_mode = 0;
  2766. if (pmlmepriv->num_sta_no_ht /*||
  2767. (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/)
  2768. new_op_mode = OP_MODE_MIXED;
  2769. else if ((phtpriv_ap->ht_cap.cap_info & IEEE80211_HT_CAP_SUP_WIDTH)
  2770. && pmlmepriv->num_sta_ht_20mhz)
  2771. new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
  2772. else if (ATOMIC_READ(&pmlmepriv->olbc_ht))
  2773. new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
  2774. else
  2775. new_op_mode = OP_MODE_PURE;
  2776. cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  2777. if (cur_op_mode != new_op_mode) {
  2778. pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  2779. pmlmepriv->ht_op_mode |= new_op_mode;
  2780. op_mode_changes++;
  2781. }
  2782. RTW_INFO("%s new operation mode=0x%X changes=%d\n",
  2783. __FUNCTION__, pmlmepriv->ht_op_mode, op_mode_changes);
  2784. return op_mode_changes;
  2785. }
  2786. #endif /* CONFIG_80211N_HT */
  2787. void associated_clients_update(_adapter *padapter, u8 updated, u32 sta_info_type)
  2788. {
  2789. /* update associcated stations cap. */
  2790. if (updated == _TRUE) {
  2791. _irqL irqL;
  2792. _list *phead, *plist;
  2793. struct sta_info *psta = NULL;
  2794. struct sta_priv *pstapriv = &padapter->stapriv;
  2795. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2796. phead = &pstapriv->asoc_list;
  2797. plist = get_next(phead);
  2798. /* check asoc_queue */
  2799. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  2800. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  2801. plist = get_next(plist);
  2802. associated_stainfo_update(padapter, psta, sta_info_type);
  2803. }
  2804. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  2805. }
  2806. }
  2807. /* called > TSR LEVEL for USB or SDIO Interface*/
  2808. void bss_cap_update_on_sta_join(_adapter *padapter, struct sta_info *psta)
  2809. {
  2810. u8 beacon_updated = _FALSE;
  2811. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2812. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2813. #if 0
  2814. if (!(psta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
  2815. !psta->no_short_preamble_set) {
  2816. psta->no_short_preamble_set = 1;
  2817. pmlmepriv->num_sta_no_short_preamble++;
  2818. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2819. (pmlmepriv->num_sta_no_short_preamble == 1))
  2820. ieee802_11_set_beacons(hapd->iface);
  2821. }
  2822. #endif
  2823. if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
  2824. if (!psta->no_short_preamble_set) {
  2825. psta->no_short_preamble_set = 1;
  2826. pmlmepriv->num_sta_no_short_preamble++;
  2827. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2828. (pmlmepriv->num_sta_no_short_preamble == 1))
  2829. beacon_updated = _TRUE;
  2830. }
  2831. } else {
  2832. if (psta->no_short_preamble_set) {
  2833. psta->no_short_preamble_set = 0;
  2834. pmlmepriv->num_sta_no_short_preamble--;
  2835. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2836. (pmlmepriv->num_sta_no_short_preamble == 0))
  2837. beacon_updated = _TRUE;
  2838. }
  2839. }
  2840. #if 0
  2841. if (psta->flags & WLAN_STA_NONERP && !psta->nonerp_set) {
  2842. psta->nonerp_set = 1;
  2843. pmlmepriv->num_sta_non_erp++;
  2844. if (pmlmepriv->num_sta_non_erp == 1)
  2845. ieee802_11_set_beacons(hapd->iface);
  2846. }
  2847. #endif
  2848. if (psta->flags & WLAN_STA_NONERP) {
  2849. if (!psta->nonerp_set) {
  2850. psta->nonerp_set = 1;
  2851. pmlmepriv->num_sta_non_erp++;
  2852. if (pmlmepriv->num_sta_non_erp == 1) {
  2853. beacon_updated = _TRUE;
  2854. update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE);
  2855. }
  2856. }
  2857. } else {
  2858. if (psta->nonerp_set) {
  2859. psta->nonerp_set = 0;
  2860. pmlmepriv->num_sta_non_erp--;
  2861. if (pmlmepriv->num_sta_non_erp == 0) {
  2862. beacon_updated = _TRUE;
  2863. update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE);
  2864. }
  2865. }
  2866. }
  2867. #if 0
  2868. if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT) &&
  2869. !psta->no_short_slot_time_set) {
  2870. psta->no_short_slot_time_set = 1;
  2871. pmlmepriv->num_sta_no_short_slot_time++;
  2872. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2873. (pmlmepriv->num_sta_no_short_slot_time == 1))
  2874. ieee802_11_set_beacons(hapd->iface);
  2875. }
  2876. #endif
  2877. if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
  2878. if (!psta->no_short_slot_time_set) {
  2879. psta->no_short_slot_time_set = 1;
  2880. pmlmepriv->num_sta_no_short_slot_time++;
  2881. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2882. (pmlmepriv->num_sta_no_short_slot_time == 1))
  2883. beacon_updated = _TRUE;
  2884. }
  2885. } else {
  2886. if (psta->no_short_slot_time_set) {
  2887. psta->no_short_slot_time_set = 0;
  2888. pmlmepriv->num_sta_no_short_slot_time--;
  2889. if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
  2890. (pmlmepriv->num_sta_no_short_slot_time == 0))
  2891. beacon_updated = _TRUE;
  2892. }
  2893. }
  2894. #ifdef CONFIG_80211N_HT
  2895. if(padapter->registrypriv.ht_enable &&
  2896. is_supported_ht(padapter->registrypriv.wireless_mode)) {
  2897. if (psta->flags & WLAN_STA_HT) {
  2898. u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
  2899. RTW_INFO("HT: STA " MAC_FMT " HT Capabilities Info: 0x%04x\n",
  2900. MAC_ARG(psta->cmn.mac_addr), ht_capab);
  2901. if (psta->no_ht_set) {
  2902. psta->no_ht_set = 0;
  2903. pmlmepriv->num_sta_no_ht--;
  2904. }
  2905. if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
  2906. if (!psta->no_ht_gf_set) {
  2907. psta->no_ht_gf_set = 1;
  2908. pmlmepriv->num_sta_ht_no_gf++;
  2909. }
  2910. RTW_INFO("%s STA " MAC_FMT " - no "
  2911. "greenfield, num of non-gf stations %d\n",
  2912. __FUNCTION__, MAC_ARG(psta->cmn.mac_addr),
  2913. pmlmepriv->num_sta_ht_no_gf);
  2914. }
  2915. if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
  2916. if (!psta->ht_20mhz_set) {
  2917. psta->ht_20mhz_set = 1;
  2918. pmlmepriv->num_sta_ht_20mhz++;
  2919. }
  2920. RTW_INFO("%s STA " MAC_FMT " - 20 MHz HT, "
  2921. "num of 20MHz HT STAs %d\n",
  2922. __FUNCTION__, MAC_ARG(psta->cmn.mac_addr),
  2923. pmlmepriv->num_sta_ht_20mhz);
  2924. }
  2925. if (((ht_capab & RTW_IEEE80211_HT_CAP_40MHZ_INTOLERANT) != 0) &&
  2926. (psta->ht_40mhz_intolerant == 0)) {
  2927. psta->ht_40mhz_intolerant = 1;
  2928. pmlmepriv->num_sta_40mhz_intolerant++;
  2929. RTW_INFO("%s STA " MAC_FMT " - 40MHZ_INTOLERANT, ",
  2930. __FUNCTION__, MAC_ARG(psta->cmn.mac_addr));
  2931. }
  2932. } else {
  2933. if (!psta->no_ht_set) {
  2934. psta->no_ht_set = 1;
  2935. pmlmepriv->num_sta_no_ht++;
  2936. }
  2937. if (pmlmepriv->htpriv.ht_option == _TRUE) {
  2938. RTW_INFO("%s STA " MAC_FMT
  2939. " - no HT, num of non-HT stations %d\n",
  2940. __FUNCTION__, MAC_ARG(psta->cmn.mac_addr),
  2941. pmlmepriv->num_sta_no_ht);
  2942. }
  2943. }
  2944. if (rtw_ht_operation_update(padapter) > 0) {
  2945. update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
  2946. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
  2947. beacon_updated = _TRUE;
  2948. }
  2949. }
  2950. #endif /* CONFIG_80211N_HT */
  2951. #ifdef CONFIG_RTW_MESH
  2952. if (MLME_IS_MESH(padapter)) {
  2953. struct sta_priv *pstapriv = &padapter->stapriv;
  2954. update_beacon(padapter, WLAN_EID_MESH_CONFIG, NULL, _FALSE);
  2955. if (pstapriv->asoc_list_cnt == 1)
  2956. _set_timer(&padapter->mesh_atlm_param_req_timer, 0);
  2957. beacon_updated = _TRUE;
  2958. }
  2959. #endif
  2960. if (beacon_updated)
  2961. update_beacon(padapter, 0xFF, NULL, _TRUE);
  2962. /* update associcated stations cap. */
  2963. associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL);
  2964. RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
  2965. }
  2966. u8 bss_cap_update_on_sta_leave(_adapter *padapter, struct sta_info *psta)
  2967. {
  2968. u8 beacon_updated = _FALSE;
  2969. struct sta_priv *pstapriv = &padapter->stapriv;
  2970. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2971. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  2972. if (!psta)
  2973. return beacon_updated;
  2974. if (rtw_tim_map_is_set(padapter, pstapriv->tim_bitmap, psta->cmn.aid)) {
  2975. rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, psta->cmn.aid);
  2976. beacon_updated = _TRUE;
  2977. update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
  2978. }
  2979. if (psta->no_short_preamble_set) {
  2980. psta->no_short_preamble_set = 0;
  2981. pmlmepriv->num_sta_no_short_preamble--;
  2982. if (pmlmeext->cur_wireless_mode > WIRELESS_11B
  2983. && pmlmepriv->num_sta_no_short_preamble == 0)
  2984. beacon_updated = _TRUE;
  2985. }
  2986. if (psta->nonerp_set) {
  2987. psta->nonerp_set = 0;
  2988. pmlmepriv->num_sta_non_erp--;
  2989. if (pmlmepriv->num_sta_non_erp == 0) {
  2990. beacon_updated = _TRUE;
  2991. update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE);
  2992. }
  2993. }
  2994. if (psta->no_short_slot_time_set) {
  2995. psta->no_short_slot_time_set = 0;
  2996. pmlmepriv->num_sta_no_short_slot_time--;
  2997. if (pmlmeext->cur_wireless_mode > WIRELESS_11B
  2998. && pmlmepriv->num_sta_no_short_slot_time == 0)
  2999. beacon_updated = _TRUE;
  3000. }
  3001. #ifdef CONFIG_80211N_HT
  3002. if (psta->no_ht_gf_set) {
  3003. psta->no_ht_gf_set = 0;
  3004. pmlmepriv->num_sta_ht_no_gf--;
  3005. }
  3006. if (psta->no_ht_set) {
  3007. psta->no_ht_set = 0;
  3008. pmlmepriv->num_sta_no_ht--;
  3009. }
  3010. if (psta->ht_20mhz_set) {
  3011. psta->ht_20mhz_set = 0;
  3012. pmlmepriv->num_sta_ht_20mhz--;
  3013. }
  3014. if (psta->ht_40mhz_intolerant) {
  3015. psta->ht_40mhz_intolerant = 0;
  3016. if (pmlmepriv->num_sta_40mhz_intolerant > 0)
  3017. pmlmepriv->num_sta_40mhz_intolerant--;
  3018. else
  3019. rtw_warn_on(1);
  3020. }
  3021. if (rtw_ht_operation_update(padapter) > 0) {
  3022. update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
  3023. update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
  3024. }
  3025. #endif /* CONFIG_80211N_HT */
  3026. #ifdef CONFIG_RTW_MESH
  3027. if (MLME_IS_MESH(padapter)) {
  3028. update_beacon(padapter, WLAN_EID_MESH_CONFIG, NULL, _FALSE);
  3029. if (pstapriv->asoc_list_cnt == 0)
  3030. _cancel_timer_ex(&padapter->mesh_atlm_param_req_timer);
  3031. beacon_updated = _TRUE;
  3032. }
  3033. #endif
  3034. if (beacon_updated == _TRUE)
  3035. update_beacon(padapter, 0xFF, NULL, _TRUE);
  3036. #if 0
  3037. /* update associated stations cap. */
  3038. associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL); /* move it to avoid deadlock */
  3039. #endif
  3040. RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
  3041. return beacon_updated;
  3042. }
  3043. u8 ap_free_sta(_adapter *padapter, struct sta_info *psta, bool active, u16 reason, bool enqueue)
  3044. {
  3045. _irqL irqL;
  3046. u8 beacon_updated = _FALSE;
  3047. if (!psta)
  3048. return beacon_updated;
  3049. if (active == _TRUE) {
  3050. #ifdef CONFIG_80211N_HT
  3051. /* tear down Rx AMPDU */
  3052. send_delba(padapter, 0, psta->cmn.mac_addr);/* recipient */
  3053. /* tear down TX AMPDU */
  3054. send_delba(padapter, 1, psta->cmn.mac_addr);/* */ /* originator */
  3055. #endif /* CONFIG_80211N_HT */
  3056. if (!MLME_IS_MESH(padapter))
  3057. issue_deauth(padapter, psta->cmn.mac_addr, reason);
  3058. }
  3059. #ifdef CONFIG_RTW_MESH
  3060. if (MLME_IS_MESH(padapter))
  3061. rtw_mesh_path_flush_by_nexthop(psta);
  3062. #endif
  3063. #ifdef CONFIG_BEAMFORMING
  3064. beamforming_wk_cmd(padapter, BEAMFORMING_CTRL_LEAVE, psta->cmn.mac_addr, ETH_ALEN, 1);
  3065. #endif
  3066. #ifdef CONFIG_80211N_HT
  3067. psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
  3068. psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
  3069. #endif
  3070. /* clear cam entry / key */
  3071. rtw_clearstakey_cmd(padapter, psta, enqueue);
  3072. _enter_critical_bh(&psta->lock, &irqL);
  3073. psta->state &= ~(_FW_LINKED | WIFI_UNDER_KEY_HANDSHAKE);
  3074. _exit_critical_bh(&psta->lock, &irqL);
  3075. if (!MLME_IS_MESH(padapter)) {
  3076. #ifdef CONFIG_IOCTL_CFG80211
  3077. #ifdef COMPAT_KERNEL_RELEASE
  3078. rtw_cfg80211_indicate_sta_disassoc(padapter, psta->cmn.mac_addr, reason);
  3079. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  3080. rtw_cfg80211_indicate_sta_disassoc(padapter, psta->cmn.mac_addr, reason);
  3081. #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
  3082. /* will call rtw_cfg80211_indicate_sta_disassoc() in cmd_thread for old API context */
  3083. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
  3084. #else
  3085. rtw_indicate_sta_disassoc_event(padapter, psta);
  3086. #endif
  3087. }
  3088. beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
  3089. report_del_sta_event(padapter, psta->cmn.mac_addr, reason, enqueue, _FALSE);
  3090. return beacon_updated;
  3091. }
  3092. int rtw_ap_inform_ch_switch(_adapter *padapter, u8 new_ch, u8 ch_offset)
  3093. {
  3094. _irqL irqL;
  3095. _list *phead, *plist;
  3096. int ret = 0;
  3097. struct sta_info *psta = NULL;
  3098. struct sta_priv *pstapriv = &padapter->stapriv;
  3099. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3100. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3101. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  3102. if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
  3103. return ret;
  3104. RTW_INFO(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
  3105. FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
  3106. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3107. phead = &pstapriv->asoc_list;
  3108. plist = get_next(phead);
  3109. /* for each sta in asoc_queue */
  3110. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  3111. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  3112. plist = get_next(plist);
  3113. issue_action_spct_ch_switch(padapter, psta->cmn.mac_addr, new_ch, ch_offset);
  3114. psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
  3115. }
  3116. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3117. issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
  3118. return ret;
  3119. }
  3120. int rtw_sta_flush(_adapter *padapter, bool enqueue)
  3121. {
  3122. _irqL irqL;
  3123. _list *phead, *plist;
  3124. int ret = 0;
  3125. struct sta_info *psta = NULL;
  3126. struct sta_priv *pstapriv = &padapter->stapriv;
  3127. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  3128. u8 flush_num = 0;
  3129. char flush_list[NUM_STA];
  3130. int i;
  3131. if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
  3132. return ret;
  3133. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
  3134. /* pick sta from sta asoc_queue */
  3135. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3136. phead = &pstapriv->asoc_list;
  3137. plist = get_next(phead);
  3138. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  3139. int stainfo_offset;
  3140. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  3141. plist = get_next(plist);
  3142. rtw_list_delete(&psta->asoc_list);
  3143. pstapriv->asoc_list_cnt--;
  3144. STA_SET_MESH_PLINK(psta, NULL);
  3145. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  3146. if (stainfo_offset_valid(stainfo_offset))
  3147. flush_list[flush_num++] = stainfo_offset;
  3148. else
  3149. rtw_warn_on(1);
  3150. }
  3151. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3152. /* call ap_free_sta() for each sta picked */
  3153. for (i = 0; i < flush_num; i++) {
  3154. u8 sta_addr[ETH_ALEN];
  3155. psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
  3156. _rtw_memcpy(sta_addr, psta->cmn.mac_addr, ETH_ALEN);
  3157. ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, enqueue);
  3158. #ifdef CONFIG_RTW_MESH
  3159. if (MLME_IS_MESH(padapter))
  3160. rtw_mesh_expire_peer(padapter, sta_addr);
  3161. #endif
  3162. }
  3163. if (!MLME_IS_MESH(padapter))
  3164. issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
  3165. associated_clients_update(padapter, _TRUE, STA_INFO_UPDATE_ALL);
  3166. return ret;
  3167. }
  3168. /* called > TSR LEVEL for USB or SDIO Interface*/
  3169. void sta_info_update(_adapter *padapter, struct sta_info *psta)
  3170. {
  3171. int flags = psta->flags;
  3172. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3173. /* update wmm cap. */
  3174. if (WLAN_STA_WME & flags)
  3175. psta->qos_option = 1;
  3176. else
  3177. psta->qos_option = 0;
  3178. if (pmlmepriv->qospriv.qos_option == 0)
  3179. psta->qos_option = 0;
  3180. #ifdef CONFIG_80211N_HT
  3181. /* update 802.11n ht cap. */
  3182. if (WLAN_STA_HT & flags) {
  3183. psta->htpriv.ht_option = _TRUE;
  3184. psta->qos_option = 1;
  3185. psta->htpriv.smps_cap = (psta->htpriv.ht_cap.cap_info & IEEE80211_HT_CAP_SM_PS) >> 2;
  3186. } else
  3187. psta->htpriv.ht_option = _FALSE;
  3188. if (pmlmepriv->htpriv.ht_option == _FALSE)
  3189. psta->htpriv.ht_option = _FALSE;
  3190. #endif
  3191. #ifdef CONFIG_80211AC_VHT
  3192. /* update 802.11AC vht cap. */
  3193. if (WLAN_STA_VHT & flags)
  3194. psta->vhtpriv.vht_option = _TRUE;
  3195. else
  3196. psta->vhtpriv.vht_option = _FALSE;
  3197. if (pmlmepriv->vhtpriv.vht_option == _FALSE)
  3198. psta->vhtpriv.vht_option = _FALSE;
  3199. #endif
  3200. update_sta_info_apmode(padapter, psta);
  3201. }
  3202. /* called >= TSR LEVEL for USB or SDIO Interface*/
  3203. void ap_sta_info_defer_update(_adapter *padapter, struct sta_info *psta)
  3204. {
  3205. if (psta->state & _FW_LINKED)
  3206. rtw_hal_update_ra_mask(psta); /* DM_RATR_STA_INIT */
  3207. }
  3208. /* restore hw setting from sw data structures */
  3209. void rtw_ap_restore_network(_adapter *padapter)
  3210. {
  3211. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3212. struct sta_priv *pstapriv = &padapter->stapriv;
  3213. struct sta_info *psta;
  3214. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  3215. _irqL irqL;
  3216. _list *phead, *plist;
  3217. u8 chk_alive_num = 0;
  3218. char chk_alive_list[NUM_STA];
  3219. int i;
  3220. rtw_setopmode_cmd(padapter
  3221. , MLME_IS_AP(padapter) ? Ndis802_11APMode : Ndis802_11_mesh
  3222. , RTW_CMDF_DIRECTLY
  3223. );
  3224. set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  3225. rtw_startbss_cmd(padapter, RTW_CMDF_DIRECTLY);
  3226. if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
  3227. (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
  3228. /* restore group key, WEP keys is restored in ips_leave() */
  3229. rtw_set_key(padapter, psecuritypriv, psecuritypriv->dot118021XGrpKeyid, 0, _FALSE);
  3230. }
  3231. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3232. phead = &pstapriv->asoc_list;
  3233. plist = get_next(phead);
  3234. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  3235. int stainfo_offset;
  3236. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  3237. plist = get_next(plist);
  3238. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  3239. if (stainfo_offset_valid(stainfo_offset))
  3240. chk_alive_list[chk_alive_num++] = stainfo_offset;
  3241. }
  3242. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3243. for (i = 0; i < chk_alive_num; i++) {
  3244. psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
  3245. if (psta == NULL)
  3246. RTW_INFO(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
  3247. else if (psta->state & _FW_LINKED) {
  3248. rtw_sta_media_status_rpt(padapter, psta, 1);
  3249. Update_RA_Entry(padapter, psta);
  3250. /* pairwise key */
  3251. /* per sta pairwise key and settings */
  3252. if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
  3253. (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
  3254. rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _FALSE);
  3255. }
  3256. }
  3257. }
  3258. void start_ap_mode(_adapter *padapter)
  3259. {
  3260. int i;
  3261. struct sta_info *psta = NULL;
  3262. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3263. struct sta_priv *pstapriv = &padapter->stapriv;
  3264. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3265. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3266. #ifdef CONFIG_CONCURRENT_MODE
  3267. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3268. #endif
  3269. pmlmepriv->update_bcn = _FALSE;
  3270. /*init_mlme_ap_info(padapter);*/
  3271. pmlmeext->bstart_bss = _FALSE;
  3272. pmlmepriv->num_sta_non_erp = 0;
  3273. pmlmepriv->num_sta_no_short_slot_time = 0;
  3274. pmlmepriv->num_sta_no_short_preamble = 0;
  3275. pmlmepriv->num_sta_ht_no_gf = 0;
  3276. #ifdef CONFIG_80211N_HT
  3277. pmlmepriv->num_sta_no_ht = 0;
  3278. #endif /* CONFIG_80211N_HT */
  3279. pmlmeinfo->HT_info_enable = 0;
  3280. pmlmeinfo->HT_caps_enable = 0;
  3281. pmlmeinfo->HT_enable = 0;
  3282. pmlmepriv->num_sta_ht_20mhz = 0;
  3283. pmlmepriv->num_sta_40mhz_intolerant = 0;
  3284. ATOMIC_SET(&pmlmepriv->olbc, _FALSE);
  3285. ATOMIC_SET(&pmlmepriv->olbc_ht, _FALSE);
  3286. #ifdef CONFIG_80211N_HT
  3287. pmlmepriv->ht_20mhz_width_req = _FALSE;
  3288. pmlmepriv->ht_intolerant_ch_reported = _FALSE;
  3289. pmlmepriv->ht_op_mode = 0;
  3290. pmlmepriv->sw_to_20mhz = 0;
  3291. #endif
  3292. _rtw_memset(pmlmepriv->ext_capab_ie_data, 0, sizeof(pmlmepriv->ext_capab_ie_data));
  3293. pmlmepriv->ext_capab_ie_len = 0;
  3294. #ifdef CONFIG_CONCURRENT_MODE
  3295. psecuritypriv->dot118021x_bmc_cam_id = INVALID_SEC_MAC_CAM_ID;
  3296. #endif
  3297. for (i = 0 ; i < pstapriv->max_aid; i++)
  3298. pstapriv->sta_aid[i] = NULL;
  3299. psta = rtw_get_bcmc_stainfo(padapter);
  3300. /*_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
  3301. if (psta)
  3302. rtw_free_stainfo(padapter, psta);
  3303. /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
  3304. rtw_init_bcmc_stainfo(padapter);
  3305. if (rtw_mi_get_ap_num(padapter))
  3306. RTW_SET_SCAN_BAND_SKIP(padapter, BAND_5G);
  3307. }
  3308. void rtw_ap_bcmc_sta_flush(_adapter *padapter)
  3309. {
  3310. #ifdef CONFIG_CONCURRENT_MODE
  3311. int cam_id = -1;
  3312. u8 *addr = adapter_mac_addr(padapter);
  3313. cam_id = rtw_iface_bcmc_id_get(padapter);
  3314. if (cam_id != INVALID_SEC_MAC_CAM_ID) {
  3315. RTW_PRINT("clear group key for "ADPT_FMT" addr:"MAC_FMT", camid:%d\n",
  3316. ADPT_ARG(padapter), MAC_ARG(addr), cam_id);
  3317. clear_cam_entry(padapter, cam_id);
  3318. rtw_camid_free(padapter, cam_id);
  3319. rtw_iface_bcmc_id_set(padapter, INVALID_SEC_MAC_CAM_ID); /*init default value*/
  3320. }
  3321. #else
  3322. invalidate_cam_all(padapter);
  3323. #endif
  3324. }
  3325. void stop_ap_mode(_adapter *padapter)
  3326. {
  3327. u8 self_action = MLME_ACTION_UNKNOWN;
  3328. struct sta_info *psta = NULL;
  3329. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3330. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3331. #ifdef CONFIG_SUPPORT_MULTI_BCN
  3332. struct dvobj_priv *pdvobj = padapter->dvobj;
  3333. _irqL irqL;
  3334. #endif
  3335. RTW_INFO("%s -"ADPT_FMT"\n", __func__, ADPT_ARG(padapter));
  3336. if (MLME_IS_AP(padapter))
  3337. self_action = MLME_AP_STOPPED;
  3338. else if (MLME_IS_MESH(padapter))
  3339. self_action = MLME_MESH_STOPPED;
  3340. else
  3341. rtw_warn_on(1);
  3342. pmlmepriv->update_bcn = _FALSE;
  3343. /*pmlmeext->bstart_bss = _FALSE;*/
  3344. padapter->netif_up = _FALSE;
  3345. /* _rtw_spinlock_free(&pmlmepriv->bcn_update_lock); */
  3346. /* reset and init security priv , this can refine with rtw_reset_securitypriv */
  3347. _rtw_memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
  3348. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
  3349. padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
  3350. #ifdef CONFIG_DFS_MASTER
  3351. rtw_dfs_rd_en_decision(padapter, self_action, 0);
  3352. #endif
  3353. /* free scan queue */
  3354. rtw_free_network_queue(padapter, _TRUE);
  3355. #if CONFIG_RTW_MACADDR_ACL
  3356. rtw_macaddr_acl_clear(padapter, RTW_ACL_PERIOD_BSS);
  3357. #endif
  3358. rtw_sta_flush(padapter, _TRUE);
  3359. rtw_ap_bcmc_sta_flush(padapter);
  3360. /* free_assoc_sta_resources */
  3361. rtw_free_all_stainfo(padapter);
  3362. psta = rtw_get_bcmc_stainfo(padapter);
  3363. if (psta) {
  3364. rtw_sta_mstatus_disc_rpt(padapter, psta->cmn.mac_id);
  3365. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  3366. rtw_free_stainfo(padapter, psta);
  3367. /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
  3368. }
  3369. rtw_free_mlme_priv_ie_data(pmlmepriv);
  3370. #ifdef CONFIG_SUPPORT_MULTI_BCN
  3371. if (pmlmeext->bstart_bss == _TRUE) {
  3372. #ifdef CONFIG_FW_HANDLE_TXBCN
  3373. u8 free_apid = CONFIG_LIMITED_AP_NUM;
  3374. #endif
  3375. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3376. pdvobj->nr_ap_if--;
  3377. if (pdvobj->nr_ap_if > 0)
  3378. pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
  3379. else
  3380. pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL;
  3381. #ifdef CONFIG_FW_HANDLE_TXBCN
  3382. rtw_ap_release_vapid(pdvobj, padapter->vap_id);
  3383. free_apid = padapter->vap_id;
  3384. padapter->vap_id = CONFIG_LIMITED_AP_NUM;
  3385. #endif
  3386. rtw_list_delete(&padapter->list);
  3387. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  3388. #ifdef CONFIG_FW_HANDLE_TXBCN
  3389. rtw_ap_mbid_bcn_dis(padapter, free_apid);
  3390. #endif
  3391. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  3392. rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
  3393. if (pdvobj->nr_ap_if == 0)
  3394. _cancel_timer_ex(&pdvobj->txbcn_timer);
  3395. #endif
  3396. }
  3397. #endif
  3398. pmlmeext->bstart_bss = _FALSE;
  3399. rtw_hal_rcr_set_chk_bssid(padapter, self_action);
  3400. #ifdef CONFIG_HW_P0_TSF_SYNC
  3401. correct_TSF(padapter, self_action);
  3402. #endif
  3403. #ifdef CONFIG_BT_COEXIST
  3404. rtw_btcoex_MediaStatusNotify(padapter, 0); /* disconnect */
  3405. #endif
  3406. }
  3407. #endif /* CONFIG_NATIVEAP_MLME */
  3408. void rtw_ap_update_bss_chbw(_adapter *adapter, WLAN_BSSID_EX *bss, u8 ch, u8 bw, u8 offset)
  3409. {
  3410. #define UPDATE_VHT_CAP 1
  3411. #define UPDATE_HT_CAP 1
  3412. #ifdef CONFIG_80211AC_VHT
  3413. struct vht_priv *vhtpriv = &adapter->mlmepriv.vhtpriv;
  3414. #endif
  3415. {
  3416. u8 *p;
  3417. int ie_len;
  3418. u8 old_ch = bss->Configuration.DSConfig;
  3419. bool change_band = _FALSE;
  3420. if ((ch <= 14 && old_ch >= 36) || (ch >= 36 && old_ch <= 14))
  3421. change_band = _TRUE;
  3422. /* update channel in IE */
  3423. p = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
  3424. if (p && ie_len > 0)
  3425. *(p + 2) = ch;
  3426. bss->Configuration.DSConfig = ch;
  3427. /* band is changed, update ERP, support rate, ext support rate IE */
  3428. if (change_band == _TRUE)
  3429. change_band_update_ie(adapter, bss, ch);
  3430. }
  3431. #ifdef CONFIG_80211AC_VHT
  3432. if (vhtpriv->vht_option == _TRUE) {
  3433. u8 *vht_cap_ie, *vht_op_ie;
  3434. int vht_cap_ielen, vht_op_ielen;
  3435. u8 center_freq;
  3436. 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)));
  3437. 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)));
  3438. center_freq = rtw_get_center_ch(ch, bw, offset);
  3439. /* update vht cap ie */
  3440. if (vht_cap_ie && vht_cap_ielen) {
  3441. #if UPDATE_VHT_CAP
  3442. /* if ((bw == CHANNEL_WIDTH_160 || bw == CHANNEL_WIDTH_80_80) && pvhtpriv->sgi_160m)
  3443. SET_VHT_CAPABILITY_ELE_SHORT_GI160M(pvht_cap_ie + 2, 1);
  3444. else */
  3445. SET_VHT_CAPABILITY_ELE_SHORT_GI160M(vht_cap_ie + 2, 0);
  3446. if (bw >= CHANNEL_WIDTH_80 && vhtpriv->sgi_80m)
  3447. SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 1);
  3448. else
  3449. SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 0);
  3450. #endif
  3451. }
  3452. /* update vht op ie */
  3453. if (vht_op_ie && vht_op_ielen) {
  3454. if (bw < CHANNEL_WIDTH_80) {
  3455. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 0);
  3456. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, 0);
  3457. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
  3458. } else if (bw == CHANNEL_WIDTH_80) {
  3459. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 1);
  3460. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, center_freq);
  3461. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
  3462. } else {
  3463. RTW_ERR(FUNC_ADPT_FMT" unsupported BW:%u\n", FUNC_ADPT_ARG(adapter), bw);
  3464. rtw_warn_on(1);
  3465. }
  3466. }
  3467. }
  3468. #endif /* CONFIG_80211AC_VHT */
  3469. #ifdef CONFIG_80211N_HT
  3470. {
  3471. struct ht_priv *htpriv = &adapter->mlmepriv.htpriv;
  3472. u8 *ht_cap_ie, *ht_op_ie;
  3473. int ht_cap_ielen, ht_op_ielen;
  3474. 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)));
  3475. 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)));
  3476. /* update ht cap ie */
  3477. if (ht_cap_ie && ht_cap_ielen) {
  3478. #if UPDATE_HT_CAP
  3479. if (bw >= CHANNEL_WIDTH_40)
  3480. SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 1);
  3481. else
  3482. SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 0);
  3483. if (bw >= CHANNEL_WIDTH_40 && htpriv->sgi_40m)
  3484. SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 1);
  3485. else
  3486. SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 0);
  3487. if (htpriv->sgi_20m)
  3488. SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 1);
  3489. else
  3490. SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 0);
  3491. #endif
  3492. }
  3493. /* update ht op ie */
  3494. if (ht_op_ie && ht_op_ielen) {
  3495. SET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2, ch);
  3496. switch (offset) {
  3497. case HAL_PRIME_CHNL_OFFSET_LOWER:
  3498. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCA);
  3499. break;
  3500. case HAL_PRIME_CHNL_OFFSET_UPPER:
  3501. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCB);
  3502. break;
  3503. case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
  3504. default:
  3505. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCN);
  3506. break;
  3507. }
  3508. if (bw >= CHANNEL_WIDTH_40)
  3509. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 1);
  3510. else
  3511. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 0);
  3512. }
  3513. }
  3514. #endif /* CONFIG_80211N_HT */
  3515. }
  3516. static u8 rtw_ap_update_chbw_by_ifbmp(struct dvobj_priv *dvobj, u8 ifbmp
  3517. , u8 cur_ie_ch[], u8 cur_ie_bw[], u8 cur_ie_offset[]
  3518. , u8 dec_ch[], u8 dec_bw[], u8 dec_offset[]
  3519. , const char *caller)
  3520. {
  3521. _adapter *iface;
  3522. struct mlme_ext_priv *mlmeext;
  3523. WLAN_BSSID_EX *network;
  3524. u8 ifbmp_ch_changed = 0;
  3525. int i;
  3526. for (i = 0; i < dvobj->iface_nums; i++) {
  3527. if (!(ifbmp & BIT(i)) || !dvobj->padapters)
  3528. continue;
  3529. iface = dvobj->padapters[i];
  3530. mlmeext = &(iface->mlmeextpriv);
  3531. if (MLME_IS_ASOC(iface)) {
  3532. RTW_INFO(FUNC_ADPT_FMT" %u,%u,%u => %u,%u,%u%s\n", caller, ADPT_ARG(iface)
  3533. , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset
  3534. , dec_ch[i], dec_bw[i], dec_offset[i]
  3535. , MLME_IS_OPCH_SW(iface) ? " OPCH_SW" : "");
  3536. } else {
  3537. RTW_INFO(FUNC_ADPT_FMT" %u,%u,%u => %u,%u,%u%s\n", caller, ADPT_ARG(iface)
  3538. , cur_ie_ch[i], cur_ie_bw[i], cur_ie_offset[i]
  3539. , dec_ch[i], dec_bw[i], dec_offset[i]
  3540. , MLME_IS_OPCH_SW(iface) ? " OPCH_SW" : "");
  3541. }
  3542. }
  3543. for (i = 0; i < dvobj->iface_nums; i++) {
  3544. if (!(ifbmp & BIT(i)) || !dvobj->padapters)
  3545. continue;
  3546. iface = dvobj->padapters[i];
  3547. mlmeext = &(iface->mlmeextpriv);
  3548. network = &(mlmeext->mlmext_info.network);
  3549. /* ch setting differs from mlmeext.network IE */
  3550. if (cur_ie_ch[i] != dec_ch[i]
  3551. || cur_ie_bw[i] != dec_bw[i]
  3552. || cur_ie_offset[i] != dec_offset[i])
  3553. ifbmp_ch_changed |= BIT(i);
  3554. /* ch setting differs from existing one */
  3555. if (MLME_IS_ASOC(iface)
  3556. && (mlmeext->cur_channel != dec_ch[i]
  3557. || mlmeext->cur_bwmode != dec_bw[i]
  3558. || mlmeext->cur_ch_offset != dec_offset[i])
  3559. ) {
  3560. if (rtw_linked_check(iface) == _TRUE) {
  3561. #ifdef CONFIG_SPCT_CH_SWITCH
  3562. if (1)
  3563. rtw_ap_inform_ch_switch(iface, dec_ch[i], dec_offset[i]);
  3564. else
  3565. #endif
  3566. rtw_sta_flush(iface, _FALSE);
  3567. }
  3568. }
  3569. mlmeext->cur_channel = dec_ch[i];
  3570. mlmeext->cur_bwmode = dec_bw[i];
  3571. mlmeext->cur_ch_offset = dec_offset[i];
  3572. rtw_ap_update_bss_chbw(iface, network, dec_ch[i], dec_bw[i], dec_offset[i]);
  3573. }
  3574. return ifbmp_ch_changed;
  3575. }
  3576. static u8 rtw_ap_ch_specific_chk(_adapter *adapter, u8 ch, u8 *bw, u8 *offset, const char *caller)
  3577. {
  3578. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  3579. RT_CHANNEL_INFO *chset = adapter_to_chset(adapter);
  3580. u8 ret = _SUCCESS;
  3581. if (rtw_chset_search_ch(chset, ch) < 0) {
  3582. RTW_WARN("%s ch:%u doesn't fit in chplan\n", caller, ch);
  3583. ret = _FAIL;
  3584. goto exit;
  3585. }
  3586. rtw_adjust_chbw(adapter, ch, bw, offset);
  3587. if (!rtw_get_offset_by_chbw(ch, *bw, offset)) {
  3588. RTW_WARN("%s %u,%u has no valid offset\n", caller, ch, *bw);
  3589. ret = _FAIL;
  3590. goto exit;
  3591. }
  3592. while (!rtw_chset_is_chbw_valid(chset, ch, *bw, *offset)
  3593. || (rtw_odm_dfs_domain_unknown(dvobj) && rtw_is_dfs_chbw(ch, *bw, *offset))
  3594. ) {
  3595. if (*bw > CHANNEL_WIDTH_20)
  3596. (*bw)--;
  3597. if (*bw == CHANNEL_WIDTH_20) {
  3598. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  3599. break;
  3600. }
  3601. }
  3602. if (rtw_odm_dfs_domain_unknown(dvobj) && rtw_is_dfs_chbw(ch, *bw, *offset)) {
  3603. RTW_WARN("%s DFS channel %u can't be used\n", caller, ch);
  3604. ret = _FAIL;
  3605. goto exit;
  3606. }
  3607. exit:
  3608. return ret;
  3609. }
  3610. static bool rtw_ap_choose_chbw(_adapter *adapter, u8 sel_ch, u8 max_bw, u8 cur_ch
  3611. , u8 *ch, u8 *bw, u8 *offset, u8 mesh_only, const char *caller)
  3612. {
  3613. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  3614. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  3615. bool ch_avail = _FALSE;
  3616. #if defined(CONFIG_DFS_MASTER)
  3617. if (!rtw_odm_dfs_domain_unknown(dvobj)) {
  3618. if (rfctl->radar_detected
  3619. && rfctl->dbg_dfs_choose_dfs_ch_first
  3620. ) {
  3621. ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
  3622. , ch, bw, offset
  3623. , RTW_CHF_2G | RTW_CHF_NON_DFS
  3624. , cur_ch
  3625. , rfctl->ch_sel_same_band_prefer, mesh_only);
  3626. if (ch_avail == _TRUE) {
  3627. RTW_INFO("%s choose 5G DFS channel for debug\n", caller);
  3628. goto exit;
  3629. }
  3630. }
  3631. if (rfctl->radar_detected
  3632. && rfctl->dfs_ch_sel_d_flags
  3633. ) {
  3634. ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
  3635. , ch, bw, offset
  3636. , rfctl->dfs_ch_sel_d_flags
  3637. , cur_ch
  3638. , rfctl->ch_sel_same_band_prefer, mesh_only);
  3639. if (ch_avail == _TRUE) {
  3640. RTW_INFO("%s choose with dfs_ch_sel_d_flags:0x%02x for debug\n"
  3641. , caller, rfctl->dfs_ch_sel_d_flags);
  3642. goto exit;
  3643. }
  3644. }
  3645. ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
  3646. , ch, bw, offset
  3647. , 0
  3648. , cur_ch
  3649. , rfctl->ch_sel_same_band_prefer, mesh_only);
  3650. } else
  3651. #endif /* defined(CONFIG_DFS_MASTER) */
  3652. {
  3653. ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
  3654. , ch, bw, offset
  3655. , RTW_CHF_DFS
  3656. , cur_ch
  3657. , rfctl->ch_sel_same_band_prefer, mesh_only);
  3658. }
  3659. exit:
  3660. if (ch_avail == _FALSE)
  3661. RTW_WARN("%s no available channel\n", caller);
  3662. return ch_avail;
  3663. }
  3664. u8 rtw_ap_chbw_decision(_adapter *adapter, u8 ifbmp, u8 excl_ifbmp
  3665. , s16 req_ch, s8 req_bw, s8 req_offset
  3666. , u8 *ch, u8 *bw, u8 *offset, u8 *chbw_allow)
  3667. {
  3668. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  3669. RT_CHANNEL_INFO *chset = adapter_to_chset(adapter);
  3670. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  3671. bool ch_avail = _FALSE;
  3672. u8 cur_ie_ch[CONFIG_IFACE_NUMBER] = {0};
  3673. u8 cur_ie_bw[CONFIG_IFACE_NUMBER] = {0};
  3674. u8 cur_ie_offset[CONFIG_IFACE_NUMBER] = {0};
  3675. u8 dec_ch[CONFIG_IFACE_NUMBER] = {0};
  3676. u8 dec_bw[CONFIG_IFACE_NUMBER] = {0};
  3677. u8 dec_offset[CONFIG_IFACE_NUMBER] = {0};
  3678. u8 u_ch = 0, u_bw = 0, u_offset = 0;
  3679. struct mlme_ext_priv *mlmeext;
  3680. WLAN_BSSID_EX *network;
  3681. struct mi_state mstate;
  3682. struct mi_state mstate_others;
  3683. bool set_u_ch = _FALSE;
  3684. u8 ifbmp_others = 0xFF & ~ifbmp & ~excl_ifbmp;
  3685. u8 ifbmp_ch_changed = 0;
  3686. bool ifbmp_all_mesh = 0;
  3687. _adapter *iface;
  3688. int i;
  3689. #ifdef CONFIG_RTW_MESH
  3690. for (i = 0; i < dvobj->iface_nums; i++)
  3691. if ((ifbmp & BIT(i)) && dvobj->padapters)
  3692. if (!MLME_IS_MESH(dvobj->padapters[i]))
  3693. break;
  3694. ifbmp_all_mesh = i >= dvobj->iface_nums ? 1 : 0;
  3695. #endif
  3696. RTW_INFO("%s ifbmp:0x%02x excl_ifbmp:0x%02x req:%d,%d,%d\n", __func__
  3697. , ifbmp, excl_ifbmp, req_ch, req_bw, req_offset);
  3698. rtw_mi_status_by_ifbmp(dvobj, ifbmp, &mstate);
  3699. rtw_mi_status_by_ifbmp(dvobj, ifbmp_others, &mstate_others);
  3700. RTW_INFO("%s others ld_sta_num:%u, lg_sta_num:%u, ap_num:%u, mesh_num:%u\n"
  3701. , __func__, MSTATE_STA_LD_NUM(&mstate_others), MSTATE_STA_LG_NUM(&mstate_others)
  3702. , MSTATE_AP_NUM(&mstate_others), MSTATE_MESH_NUM(&mstate_others));
  3703. for (i = 0; i < dvobj->iface_nums; i++) {
  3704. if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
  3705. continue;
  3706. iface = dvobj->padapters[i];
  3707. mlmeext = &(iface->mlmeextpriv);
  3708. network = &(mlmeext->mlmext_info.network);
  3709. /* get current IE channel settings */
  3710. rtw_ies_get_chbw(BSS_EX_TLV_IES(network), BSS_EX_TLV_IES_LEN(network)
  3711. , &cur_ie_ch[i], &cur_ie_bw[i], &cur_ie_offset[i], 1, 1);
  3712. /* prepare temporary channel setting decision */
  3713. if (req_ch == 0) {
  3714. /* request comes from upper layer, use cur_ie values */
  3715. dec_ch[i] = cur_ie_ch[i];
  3716. dec_bw[i] = cur_ie_bw[i];
  3717. dec_offset[i] = cur_ie_offset[i];
  3718. } else {
  3719. /* use chbw of cur_ie updated with specifying req as temporary decision */
  3720. dec_ch[i] = (req_ch <= REQ_CH_NONE) ? cur_ie_ch[i] : req_ch;
  3721. if (req_bw <= REQ_BW_NONE) {
  3722. if (req_bw == REQ_BW_ORI)
  3723. dec_bw[i] = iface->mlmepriv.ori_bw;
  3724. else
  3725. dec_bw[i] = cur_ie_bw[i];
  3726. } else
  3727. dec_bw[i] = req_bw;
  3728. dec_offset[i] = (req_offset <= REQ_OFFSET_NONE) ? cur_ie_offset[i] : req_offset;
  3729. }
  3730. }
  3731. if (MSTATE_STA_LD_NUM(&mstate_others) || MSTATE_STA_LG_NUM(&mstate_others)
  3732. || MSTATE_AP_NUM(&mstate_others) || MSTATE_MESH_NUM(&mstate_others)
  3733. ) {
  3734. /* has linked/linking STA or has AP/Mesh mode */
  3735. rtw_warn_on(!rtw_mi_get_ch_setting_union_by_ifbmp(dvobj, ifbmp_others, &u_ch, &u_bw, &u_offset));
  3736. RTW_INFO("%s others union:%u,%u,%u\n", __func__, u_ch, u_bw, u_offset);
  3737. }
  3738. #ifdef CONFIG_MCC_MODE
  3739. if (MCC_EN(adapter) && req_ch == 0) {
  3740. if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC)) {
  3741. u8 if_id = adapter->iface_id;
  3742. mlmeext = &(adapter->mlmeextpriv);
  3743. /* check channel settings are the same */
  3744. if (cur_ie_ch[if_id] == mlmeext->cur_channel
  3745. && cur_ie_bw[if_id] == mlmeext->cur_bwmode
  3746. && cur_ie_offset[if_id] == mlmeext->cur_ch_offset) {
  3747. RTW_INFO(FUNC_ADPT_FMT"req ch settings are the same as current ch setting, go to exit\n"
  3748. , FUNC_ADPT_ARG(adapter));
  3749. *chbw_allow = _FALSE;
  3750. goto exit;
  3751. } else {
  3752. 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"
  3753. , FUNC_ADPT_ARG(adapter)
  3754. , cur_ie_ch[if_id], cur_ie_bw[if_id], cur_ie_offset[if_id]
  3755. , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  3756. rtw_hal_set_mcc_setting_disconnect(adapter);
  3757. }
  3758. }
  3759. }
  3760. #endif /* CONFIG_MCC_MODE */
  3761. if (MSTATE_STA_LG_NUM(&mstate_others) && !MSTATE_STA_LD_NUM(&mstate_others)) {
  3762. /* has linking STA but no linked STA */
  3763. for (i = 0; i < dvobj->iface_nums; i++) {
  3764. if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
  3765. continue;
  3766. iface = dvobj->padapters[i];
  3767. rtw_adjust_chbw(iface, dec_ch[i], &dec_bw[i], &dec_offset[i]);
  3768. #ifdef CONFIG_RTW_MESH
  3769. if (MLME_IS_MESH(iface))
  3770. rtw_mesh_adjust_chbw(dec_ch[i], &dec_bw[i], &dec_offset[i]);
  3771. #endif
  3772. if (rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch[i], dec_bw[i], dec_offset[i])) {
  3773. rtw_chset_sync_chbw(chset
  3774. , &dec_ch[i], &dec_bw[i], &dec_offset[i]
  3775. , &u_ch, &u_bw, &u_offset);
  3776. set_u_ch = _TRUE;
  3777. /* channel bw offset can be allowed, not need MCC */
  3778. *chbw_allow = _TRUE;
  3779. } else {
  3780. #ifdef CONFIG_MCC_MODE
  3781. if (MCC_EN(iface)) {
  3782. mlmeext = &(iface->mlmeextpriv);
  3783. mlmeext->cur_channel = *ch = dec_ch[i];
  3784. mlmeext->cur_bwmode = *bw = dec_bw[i];
  3785. mlmeext->cur_ch_offset = *offset = dec_offset[i];
  3786. /* channel bw offset can not be allowed, need MCC */
  3787. *chbw_allow = _FALSE;
  3788. RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(iface)
  3789. , *ch, *bw, *offset);
  3790. goto exit;
  3791. }
  3792. #endif /* CONFIG_MCC_MODE */
  3793. /* set this for possible ch change when join down*/
  3794. set_fwstate(&iface->mlmepriv, WIFI_OP_CH_SWITCHING);
  3795. }
  3796. }
  3797. } else if (MSTATE_STA_LD_NUM(&mstate_others)
  3798. || MSTATE_AP_NUM(&mstate_others) || MSTATE_MESH_NUM(&mstate_others)
  3799. ) {
  3800. /* has linked STA mode or AP/Mesh mode */
  3801. for (i = 0; i < dvobj->iface_nums; i++) {
  3802. if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
  3803. continue;
  3804. iface = dvobj->padapters[i];
  3805. rtw_adjust_chbw(iface, u_ch, &dec_bw[i], &dec_offset[i]);
  3806. #ifdef CONFIG_RTW_MESH
  3807. if (MLME_IS_MESH(iface))
  3808. rtw_mesh_adjust_chbw(u_ch, &dec_bw[i], &dec_offset[i]);
  3809. #endif
  3810. #ifdef CONFIG_MCC_MODE
  3811. if (MCC_EN(iface)) {
  3812. if (!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch[i], dec_bw[i], dec_offset[i])) {
  3813. mlmeext = &(iface->mlmeextpriv);
  3814. mlmeext->cur_channel = *ch = dec_ch[i] = cur_ie_ch[i];
  3815. mlmeext->cur_bwmode = *bw = dec_bw[i] = cur_ie_bw[i];
  3816. mlmeext->cur_ch_offset = *offset = dec_offset[i] = cur_ie_offset[i];
  3817. /* channel bw offset can not be allowed, need MCC */
  3818. *chbw_allow = _FALSE;
  3819. RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(iface)
  3820. , *ch, *bw, *offset);
  3821. goto exit;
  3822. } else
  3823. /* channel bw offset can be allowed, not need MCC */
  3824. *chbw_allow = _TRUE;
  3825. }
  3826. #endif /* CONFIG_MCC_MODE */
  3827. if (req_ch == 0 && dec_bw[i] > u_bw
  3828. && rtw_is_dfs_chbw(u_ch, u_bw, u_offset)
  3829. ) {
  3830. /* request comes from upper layer, prevent from additional channel waiting */
  3831. dec_bw[i] = u_bw;
  3832. if (dec_bw[i] == CHANNEL_WIDTH_20)
  3833. dec_offset[i] = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  3834. }
  3835. /* follow */
  3836. rtw_chset_sync_chbw(chset
  3837. , &dec_ch[i], &dec_bw[i], &dec_offset[i]
  3838. , &u_ch, &u_bw, &u_offset);
  3839. }
  3840. set_u_ch = _TRUE;
  3841. } else {
  3842. /* autonomous decision */
  3843. u8 ori_ch = 0;
  3844. u8 max_bw;
  3845. /* autonomous decision, not need MCC */
  3846. *chbw_allow = _TRUE;
  3847. if (req_ch <= REQ_CH_NONE) /* channel is not specified */
  3848. goto choose_chbw;
  3849. /* get tmp dec union of ifbmp */
  3850. for (i = 0; i < dvobj->iface_nums; i++) {
  3851. if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
  3852. continue;
  3853. if (u_ch == 0) {
  3854. u_ch = dec_ch[i];
  3855. u_bw = dec_bw[i];
  3856. u_offset = dec_offset[i];
  3857. rtw_adjust_chbw(adapter, u_ch, &u_bw, &u_offset);
  3858. rtw_get_offset_by_chbw(u_ch, u_bw, &u_offset);
  3859. } else {
  3860. u8 tmp_ch = dec_ch[i];
  3861. u8 tmp_bw = dec_bw[i];
  3862. u8 tmp_offset = dec_offset[i];
  3863. rtw_adjust_chbw(adapter, tmp_ch, &tmp_bw, &tmp_offset);
  3864. rtw_get_offset_by_chbw(tmp_ch, tmp_bw, &tmp_offset);
  3865. rtw_warn_on(!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, tmp_ch, tmp_bw, tmp_offset));
  3866. rtw_sync_chbw(&tmp_ch, &tmp_bw, &tmp_offset, &u_ch, &u_bw, &u_offset);
  3867. }
  3868. }
  3869. #ifdef CONFIG_RTW_MESH
  3870. /* if ifbmp are all mesh, apply bw restriction */
  3871. if (ifbmp_all_mesh)
  3872. rtw_mesh_adjust_chbw(u_ch, &u_bw, &u_offset);
  3873. #endif
  3874. RTW_INFO("%s ifbmp:0x%02x tmp union:%u,%u,%u\n", __func__, ifbmp, u_ch, u_bw, u_offset);
  3875. /* check if tmp dec union is usable */
  3876. if (rtw_ap_ch_specific_chk(adapter, u_ch, &u_bw, &u_offset, __func__) == _FAIL) {
  3877. /* channel can't be used */
  3878. if (req_ch > 0) {
  3879. /* specific channel and not from IE => don't change channel setting */
  3880. goto exit;
  3881. }
  3882. goto choose_chbw;
  3883. } else if (rtw_chset_is_chbw_non_ocp(chset, u_ch, u_bw, u_offset)) {
  3884. RTW_WARN("%s DFS channel %u,%u under non ocp\n", __func__, u_ch, u_bw);
  3885. if (req_ch > 0 && req_bw > REQ_BW_NONE) {
  3886. /* change_chbw with specific channel and specific bw, goto update_bss_chbw directly */
  3887. goto update_bss_chbw;
  3888. }
  3889. } else
  3890. goto update_bss_chbw;
  3891. choose_chbw:
  3892. req_ch = req_ch > 0 ? req_ch : 0;
  3893. max_bw = req_bw > REQ_BW_NONE ? req_bw : CHANNEL_WIDTH_20;
  3894. for (i = 0; i < dvobj->iface_nums; i++) {
  3895. if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
  3896. continue;
  3897. iface = dvobj->padapters[i];
  3898. mlmeext = &(iface->mlmeextpriv);
  3899. if (req_bw <= REQ_BW_NONE) {
  3900. if (req_bw == REQ_BW_ORI) {
  3901. if (max_bw < iface->mlmepriv.ori_bw)
  3902. max_bw = iface->mlmepriv.ori_bw;
  3903. } else {
  3904. if (max_bw < cur_ie_bw[i])
  3905. max_bw = cur_ie_bw[i];
  3906. }
  3907. }
  3908. if (MSTATE_AP_NUM(&mstate) || MSTATE_MESH_NUM(&mstate)) {
  3909. if (ori_ch == 0)
  3910. ori_ch = mlmeext->cur_channel;
  3911. else if (ori_ch != mlmeext->cur_channel)
  3912. rtw_warn_on(1);
  3913. } else {
  3914. if (ori_ch == 0)
  3915. ori_ch = cur_ie_ch[i];
  3916. else if (ori_ch != cur_ie_ch[i])
  3917. rtw_warn_on(1);
  3918. }
  3919. }
  3920. ch_avail = rtw_ap_choose_chbw(adapter, req_ch, max_bw
  3921. , ori_ch, &u_ch, &u_bw, &u_offset, ifbmp_all_mesh, __func__);
  3922. if (ch_avail == _FALSE)
  3923. goto exit;
  3924. update_bss_chbw:
  3925. for (i = 0; i < dvobj->iface_nums; i++) {
  3926. if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
  3927. continue;
  3928. iface = dvobj->padapters[i];
  3929. dec_ch[i] = u_ch;
  3930. if (dec_bw[i] > u_bw)
  3931. dec_bw[i] = u_bw;
  3932. if (dec_bw[i] == CHANNEL_WIDTH_20)
  3933. dec_offset[i] = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  3934. else
  3935. dec_offset[i] = u_offset;
  3936. #ifdef CONFIG_RTW_MESH
  3937. if (MLME_IS_MESH(iface))
  3938. rtw_mesh_adjust_chbw(dec_ch[i], &dec_bw[i], &dec_offset[i]);
  3939. #endif
  3940. }
  3941. set_u_ch = _TRUE;
  3942. }
  3943. ifbmp_ch_changed = rtw_ap_update_chbw_by_ifbmp(dvobj, ifbmp
  3944. , cur_ie_ch, cur_ie_bw, cur_ie_offset
  3945. , dec_ch, dec_bw, dec_offset
  3946. , __func__);
  3947. if (u_ch != 0)
  3948. RTW_INFO("%s union:%u,%u,%u\n", __func__, u_ch, u_bw, u_offset);
  3949. if (rtw_mi_check_fwstate(adapter, _FW_UNDER_SURVEY)) {
  3950. /* scanning, leave ch setting to scan state machine */
  3951. set_u_ch = _FALSE;
  3952. }
  3953. if (set_u_ch == _TRUE) {
  3954. *ch = u_ch;
  3955. *bw = u_bw;
  3956. *offset = u_offset;
  3957. }
  3958. exit:
  3959. return ifbmp_ch_changed;
  3960. }
  3961. u8 rtw_ap_sta_states_check(_adapter *adapter)
  3962. {
  3963. struct sta_info *psta;
  3964. struct sta_priv *pstapriv = &adapter->stapriv;
  3965. _list *plist, *phead;
  3966. _irqL irqL;
  3967. u8 rst = _FALSE;
  3968. if (!MLME_IS_AP(adapter) && !MLME_IS_MESH(adapter))
  3969. return _FALSE;
  3970. if (pstapriv->auth_list_cnt !=0)
  3971. return _TRUE;
  3972. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3973. phead = &pstapriv->asoc_list;
  3974. plist = get_next(phead);
  3975. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  3976. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  3977. plist = get_next(plist);
  3978. if (!(psta->state & _FW_LINKED)) {
  3979. RTW_INFO(ADPT_FMT"- SoftAP/Mesh - sta under linking, its state = 0x%x\n", ADPT_ARG(adapter), psta->state);
  3980. rst = _TRUE;
  3981. break;
  3982. } else if (psta->state & WIFI_UNDER_KEY_HANDSHAKE) {
  3983. RTW_INFO(ADPT_FMT"- SoftAP/Mesh - sta under key handshaking, its state = 0x%x\n", ADPT_ARG(adapter), psta->state);
  3984. rst = _TRUE;
  3985. break;
  3986. }
  3987. }
  3988. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  3989. return rst;
  3990. }
  3991. /*#define DBG_SWTIMER_BASED_TXBCN*/
  3992. #ifdef CONFIG_SWTIMER_BASED_TXBCN
  3993. void tx_beacon_handlder(struct dvobj_priv *pdvobj)
  3994. {
  3995. #define BEACON_EARLY_TIME 20 /* unit:TU*/
  3996. _irqL irqL;
  3997. _list *plist, *phead;
  3998. u32 timestamp[2];
  3999. u32 bcn_interval_us; /* unit : usec */
  4000. u64 time;
  4001. u32 cur_tick, time_offset; /* unit : usec */
  4002. u32 inter_bcn_space_us; /* unit : usec */
  4003. u32 txbcn_timer_ms; /* unit : ms */
  4004. int nr_vap, idx, bcn_idx;
  4005. int i;
  4006. u8 val8, late = 0;
  4007. _adapter *padapter = NULL;
  4008. i = 0;
  4009. /* get first ap mode interface */
  4010. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  4011. if (rtw_is_list_empty(&pdvobj->ap_if_q.queue) || (pdvobj->nr_ap_if == 0)) {
  4012. RTW_INFO("[%s] ERROR: ap_if_q is empty!or nr_ap = %d\n", __func__, pdvobj->nr_ap_if);
  4013. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  4014. return;
  4015. } else
  4016. padapter = LIST_CONTAINOR(get_next(&(pdvobj->ap_if_q.queue)), struct _ADAPTER, list);
  4017. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  4018. if (NULL == padapter) {
  4019. RTW_INFO("[%s] ERROR: no any ap interface!\n", __func__);
  4020. return;
  4021. }
  4022. bcn_interval_us = DEFAULT_BCN_INTERVAL * NET80211_TU_TO_US;
  4023. if (0 == bcn_interval_us) {
  4024. RTW_INFO("[%s] ERROR: beacon interval = 0\n", __func__);
  4025. return;
  4026. }
  4027. /* read TSF */
  4028. timestamp[1] = rtw_read32(padapter, 0x560 + 4);
  4029. timestamp[0] = rtw_read32(padapter, 0x560);
  4030. while (timestamp[1]) {
  4031. time = (0xFFFFFFFF % bcn_interval_us + 1) * timestamp[1] + timestamp[0];
  4032. timestamp[0] = (u32)time;
  4033. timestamp[1] = (u32)(time >> 32);
  4034. }
  4035. cur_tick = timestamp[0] % bcn_interval_us;
  4036. _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  4037. nr_vap = (pdvobj->nr_ap_if - 1);
  4038. if (nr_vap > 0) {
  4039. inter_bcn_space_us = pdvobj->inter_bcn_space * NET80211_TU_TO_US; /* beacon_interval / (nr_vap+1); */
  4040. idx = cur_tick / inter_bcn_space_us;
  4041. if (idx < nr_vap) /* if (idx < (nr_vap+1))*/
  4042. bcn_idx = idx + 1; /* bcn_idx = (idx + 1) % (nr_vap+1);*/
  4043. else
  4044. bcn_idx = 0;
  4045. /* to get padapter based on bcn_idx */
  4046. padapter = NULL;
  4047. phead = get_list_head(&pdvobj->ap_if_q);
  4048. plist = get_next(phead);
  4049. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  4050. padapter = LIST_CONTAINOR(plist, struct _ADAPTER, list);
  4051. plist = get_next(plist);
  4052. if (i == bcn_idx)
  4053. break;
  4054. i++;
  4055. }
  4056. if ((NULL == padapter) || (i > pdvobj->nr_ap_if)) {
  4057. RTW_INFO("[%s] ERROR: nr_ap_if = %d, padapter=%p, bcn_idx=%d, index=%d\n",
  4058. __func__, pdvobj->nr_ap_if, padapter, bcn_idx, i);
  4059. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  4060. return;
  4061. }
  4062. #ifdef DBG_SWTIMER_BASED_TXBCN
  4063. RTW_INFO("BCN_IDX=%d, cur_tick=%d, padapter=%p\n", bcn_idx, cur_tick, padapter);
  4064. #endif
  4065. if (((idx + 2 == nr_vap + 1) && (idx < nr_vap + 1)) || (0 == bcn_idx)) {
  4066. time_offset = bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
  4067. if ((s32)time_offset < 0)
  4068. time_offset += inter_bcn_space_us;
  4069. } else {
  4070. time_offset = (idx + 2) * inter_bcn_space_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
  4071. if (time_offset > (inter_bcn_space_us + (inter_bcn_space_us >> 1))) {
  4072. time_offset -= inter_bcn_space_us;
  4073. late = 1;
  4074. }
  4075. }
  4076. } else
  4077. /*#endif*/ { /* MBSSID */
  4078. time_offset = 2 * bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
  4079. if (time_offset > (bcn_interval_us + (bcn_interval_us >> 1))) {
  4080. time_offset -= bcn_interval_us;
  4081. late = 1;
  4082. }
  4083. }
  4084. _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
  4085. #ifdef DBG_SWTIMER_BASED_TXBCN
  4086. RTW_INFO("set sw bcn timer %d us\n", time_offset);
  4087. #endif
  4088. txbcn_timer_ms = time_offset / NET80211_TU_TO_US;
  4089. _set_timer(&pdvobj->txbcn_timer, txbcn_timer_ms);
  4090. if (padapter) {
  4091. #ifdef CONFIG_BCN_RECOVERY
  4092. rtw_ap_bcn_recovery(padapter);
  4093. #endif /*CONFIG_BCN_RECOVERY*/
  4094. #ifdef CONFIG_BCN_XMIT_PROTECT
  4095. rtw_ap_bcn_queue_empty_check(padapter, txbcn_timer_ms);
  4096. #endif /*CONFIG_BCN_XMIT_PROTECT*/
  4097. #ifdef DBG_SWTIMER_BASED_TXBCN
  4098. RTW_INFO("padapter=%p, PORT=%d\n", padapter, padapter->hw_port);
  4099. #endif
  4100. /* bypass TX BCN queue if op ch is switching/waiting */
  4101. if (!check_fwstate(&padapter->mlmepriv, WIFI_OP_CH_SWITCHING)
  4102. && !IS_CH_WAITING(adapter_to_rfctl(padapter))
  4103. ) {
  4104. /*update_beacon(padapter, _TIM_IE_, NULL, _FALSE);*/
  4105. /*issue_beacon(padapter, 0);*/
  4106. send_beacon(padapter);
  4107. }
  4108. }
  4109. #if 0
  4110. /* handle any buffered BC/MC frames*/
  4111. /* Don't dynamically change DIS_ATIM due to HW will auto send ACQ after HIQ empty.*/
  4112. val8 = *((unsigned char *)priv->beaconbuf + priv->timoffset + 4);
  4113. if (val8 & 0x01) {
  4114. process_mcast_dzqueue(priv);
  4115. priv->pkt_in_dtimQ = 0;
  4116. }
  4117. #endif
  4118. }
  4119. void tx_beacon_timer_handlder(void *ctx)
  4120. {
  4121. struct dvobj_priv *pdvobj = (struct dvobj_priv *)ctx;
  4122. _adapter *padapter = pdvobj->padapters[0];
  4123. if (padapter)
  4124. set_tx_beacon_cmd(padapter);
  4125. }
  4126. #endif
  4127. void rtw_ap_parse_sta_capability(_adapter *adapter, struct sta_info *sta, u8 *cap)
  4128. {
  4129. sta->capability = RTW_GET_LE16(cap);
  4130. if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  4131. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  4132. else
  4133. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  4134. }
  4135. u16 rtw_ap_parse_sta_supported_rates(_adapter *adapter, struct sta_info *sta, u8 *tlv_ies, u16 tlv_ies_len)
  4136. {
  4137. u8 rate_set[12];
  4138. u8 rate_num;
  4139. int i;
  4140. u16 status = _STATS_SUCCESSFUL_;
  4141. rtw_ies_get_supported_rate(tlv_ies, tlv_ies_len, rate_set, &rate_num);
  4142. if (rate_num == 0) {
  4143. RTW_INFO(FUNC_ADPT_FMT" sta "MAC_FMT" with no supported rate\n"
  4144. , FUNC_ADPT_ARG(adapter), MAC_ARG(sta->cmn.mac_addr));
  4145. status = _STATS_FAILURE_;
  4146. goto exit;
  4147. }
  4148. _rtw_memcpy(sta->bssrateset, rate_set, rate_num);
  4149. sta->bssratelen = rate_num;
  4150. if (MLME_IS_AP(adapter)) {
  4151. /* this function force only CCK rates to be bassic rate... */
  4152. UpdateBrateTblForSoftAP(sta->bssrateset, sta->bssratelen);
  4153. }
  4154. /* if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) */ /* ? */
  4155. sta->flags |= WLAN_STA_NONERP;
  4156. for (i = 0; i < sta->bssratelen; i++) {
  4157. if ((sta->bssrateset[i] & 0x7f) > 22) {
  4158. sta->flags &= ~WLAN_STA_NONERP;
  4159. break;
  4160. }
  4161. }
  4162. exit:
  4163. return status;
  4164. }
  4165. u16 rtw_ap_parse_sta_security_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
  4166. {
  4167. struct security_priv *sec = &adapter->securitypriv;
  4168. u8 *wpa_ie;
  4169. int wpa_ie_len;
  4170. int group_cipher = 0, pairwise_cipher = 0;
  4171. u8 mfp_opt = MFP_NO;
  4172. u16 status = _STATS_SUCCESSFUL_;
  4173. sta->dot8021xalg = 0;
  4174. sta->wpa_psk = 0;
  4175. sta->wpa_group_cipher = 0;
  4176. sta->wpa2_group_cipher = 0;
  4177. sta->wpa_pairwise_cipher = 0;
  4178. sta->wpa2_pairwise_cipher = 0;
  4179. _rtw_memset(sta->wpa_ie, 0, sizeof(sta->wpa_ie));
  4180. if ((sec->wpa_psk & BIT(1)) && elems->rsn_ie) {
  4181. wpa_ie = elems->rsn_ie;
  4182. wpa_ie_len = elems->rsn_ie_len;
  4183. if (rtw_parse_wpa2_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, NULL, &mfp_opt) == _SUCCESS) {
  4184. sta->dot8021xalg = 1;/* psk, todo:802.1x */
  4185. sta->wpa_psk |= BIT(1);
  4186. sta->wpa2_group_cipher = group_cipher & sec->wpa2_group_cipher;
  4187. sta->wpa2_pairwise_cipher = pairwise_cipher & sec->wpa2_pairwise_cipher;
  4188. if (!sta->wpa2_group_cipher)
  4189. status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  4190. if (!sta->wpa2_pairwise_cipher)
  4191. status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  4192. } else
  4193. status = WLAN_STATUS_INVALID_IE;
  4194. }
  4195. else if ((sec->wpa_psk & BIT(0)) && elems->wpa_ie) {
  4196. wpa_ie = elems->wpa_ie;
  4197. wpa_ie_len = elems->wpa_ie_len;
  4198. if (rtw_parse_wpa_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  4199. sta->dot8021xalg = 1;/* psk, todo:802.1x */
  4200. sta->wpa_psk |= BIT(0);
  4201. sta->wpa_group_cipher = group_cipher & sec->wpa_group_cipher;
  4202. sta->wpa_pairwise_cipher = pairwise_cipher & sec->wpa_pairwise_cipher;
  4203. if (!sta->wpa_group_cipher)
  4204. status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
  4205. if (!sta->wpa_pairwise_cipher)
  4206. status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
  4207. } else
  4208. status = WLAN_STATUS_INVALID_IE;
  4209. } else {
  4210. wpa_ie = NULL;
  4211. wpa_ie_len = 0;
  4212. }
  4213. #ifdef CONFIG_RTW_MESH
  4214. if (MLME_IS_MESH(adapter)) {
  4215. /* MFP is mandatory for secure mesh */
  4216. if (adapter->mesh_info.mesh_auth_id)
  4217. sta->flags |= WLAN_STA_MFP;
  4218. } else
  4219. #endif
  4220. if ((sec->mfp_opt == MFP_REQUIRED && mfp_opt == MFP_NO) || mfp_opt == MFP_INVALID)
  4221. status = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
  4222. else if (sec->mfp_opt >= MFP_OPTIONAL && mfp_opt >= MFP_OPTIONAL)
  4223. sta->flags |= WLAN_STA_MFP;
  4224. if (status != _STATS_SUCCESSFUL_)
  4225. goto exit;
  4226. if (!MLME_IS_AP(adapter))
  4227. goto exit;
  4228. sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
  4229. /* if (hapd->conf->wps_state && wpa_ie == NULL) { */ /* todo: to check ap if supporting WPS */
  4230. if (wpa_ie == NULL) {
  4231. if (elems->wps_ie) {
  4232. RTW_INFO("STA included WPS IE in "
  4233. "(Re)Association Request - assume WPS is "
  4234. "used\n");
  4235. sta->flags |= WLAN_STA_WPS;
  4236. /* wpabuf_free(sta->wps_ie); */
  4237. /* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
  4238. /* elems.wps_ie_len - 4); */
  4239. } else {
  4240. RTW_INFO("STA did not include WPA/RSN IE "
  4241. "in (Re)Association Request - possible WPS "
  4242. "use\n");
  4243. sta->flags |= WLAN_STA_MAYBE_WPS;
  4244. }
  4245. /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
  4246. /* that the selected registrar of AP is _FLASE */
  4247. if ((sec->wpa_psk > 0)
  4248. && (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))
  4249. ) {
  4250. struct mlme_priv *mlme = &adapter->mlmepriv;
  4251. if (mlme->wps_beacon_ie) {
  4252. u8 selected_registrar = 0;
  4253. rtw_get_wps_attr_content(mlme->wps_beacon_ie, mlme->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR, &selected_registrar, NULL);
  4254. if (!selected_registrar) {
  4255. RTW_INFO("selected_registrar is _FALSE , or AP is not ready to do WPS\n");
  4256. status = _STATS_UNABLE_HANDLE_STA_;
  4257. goto exit;
  4258. }
  4259. }
  4260. }
  4261. } else {
  4262. int copy_len;
  4263. if (sec->wpa_psk == 0) {
  4264. RTW_INFO("STA " MAC_FMT
  4265. ": WPA/RSN IE in association request, but AP don't support WPA/RSN\n",
  4266. MAC_ARG(sta->cmn.mac_addr));
  4267. status = WLAN_STATUS_INVALID_IE;
  4268. goto exit;
  4269. }
  4270. if (elems->wps_ie) {
  4271. RTW_INFO("STA included WPS IE in "
  4272. "(Re)Association Request - WPS is "
  4273. "used\n");
  4274. sta->flags |= WLAN_STA_WPS;
  4275. copy_len = 0;
  4276. } else
  4277. copy_len = ((wpa_ie_len + 2) > sizeof(sta->wpa_ie)) ? (sizeof(sta->wpa_ie)) : (wpa_ie_len + 2);
  4278. if (copy_len > 0)
  4279. _rtw_memcpy(sta->wpa_ie, wpa_ie - 2, copy_len);
  4280. }
  4281. exit:
  4282. return status;
  4283. }
  4284. void rtw_ap_parse_sta_wmm_ie(_adapter *adapter, struct sta_info *sta, u8 *tlv_ies, u16 tlv_ies_len)
  4285. {
  4286. struct mlme_priv *mlme = &adapter->mlmepriv;
  4287. unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
  4288. u8 *p;
  4289. sta->flags &= ~WLAN_STA_WME;
  4290. sta->qos_option = 0;
  4291. sta->qos_info = 0;
  4292. sta->has_legacy_ac = _TRUE;
  4293. sta->uapsd_vo = 0;
  4294. sta->uapsd_vi = 0;
  4295. sta->uapsd_be = 0;
  4296. sta->uapsd_bk = 0;
  4297. if (!mlme->qospriv.qos_option)
  4298. goto exit;
  4299. #ifdef CONFIG_RTW_MESH
  4300. if (MLME_IS_MESH(adapter)) {
  4301. /* QoS is mandatory in mesh */
  4302. sta->flags |= WLAN_STA_WME;
  4303. }
  4304. #endif
  4305. p = rtw_get_ie_ex(tlv_ies, tlv_ies_len, WLAN_EID_VENDOR_SPECIFIC, WMM_IE, 6, NULL, NULL);
  4306. if (!p)
  4307. goto exit;
  4308. sta->flags |= WLAN_STA_WME;
  4309. sta->qos_option = 1;
  4310. sta->qos_info = *(p + 8);
  4311. sta->max_sp_len = (sta->qos_info >> 5) & 0x3;
  4312. if ((sta->qos_info & 0xf) != 0xf)
  4313. sta->has_legacy_ac = _TRUE;
  4314. else
  4315. sta->has_legacy_ac = _FALSE;
  4316. if (sta->qos_info & 0xf) {
  4317. if (sta->qos_info & BIT(0))
  4318. sta->uapsd_vo = BIT(0) | BIT(1);
  4319. else
  4320. sta->uapsd_vo = 0;
  4321. if (sta->qos_info & BIT(1))
  4322. sta->uapsd_vi = BIT(0) | BIT(1);
  4323. else
  4324. sta->uapsd_vi = 0;
  4325. if (sta->qos_info & BIT(2))
  4326. sta->uapsd_bk = BIT(0) | BIT(1);
  4327. else
  4328. sta->uapsd_bk = 0;
  4329. if (sta->qos_info & BIT(3))
  4330. sta->uapsd_be = BIT(0) | BIT(1);
  4331. else
  4332. sta->uapsd_be = 0;
  4333. }
  4334. exit:
  4335. return;
  4336. }
  4337. void rtw_ap_parse_sta_ht_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
  4338. {
  4339. struct mlme_priv *mlme = &adapter->mlmepriv;
  4340. sta->flags &= ~WLAN_STA_HT;
  4341. #ifdef CONFIG_80211N_HT
  4342. if (mlme->htpriv.ht_option == _FALSE)
  4343. goto exit;
  4344. /* save HT capabilities in the sta object */
  4345. _rtw_memset(&sta->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
  4346. if (elems->ht_capabilities && elems->ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap)) {
  4347. sta->flags |= WLAN_STA_HT;
  4348. sta->flags |= WLAN_STA_WME;
  4349. _rtw_memcpy(&sta->htpriv.ht_cap, elems->ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
  4350. if (elems->ht_operation && elems->ht_operation_len == HT_OP_IE_LEN) {
  4351. _rtw_memcpy(sta->htpriv.ht_op, elems->ht_operation, HT_OP_IE_LEN);
  4352. sta->htpriv.op_present = 1;
  4353. }
  4354. }
  4355. exit:
  4356. #endif
  4357. return;
  4358. }
  4359. void rtw_ap_parse_sta_vht_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
  4360. {
  4361. struct mlme_priv *mlme = &adapter->mlmepriv;
  4362. sta->flags &= ~WLAN_STA_VHT;
  4363. #ifdef CONFIG_80211AC_VHT
  4364. if (mlme->vhtpriv.vht_option == _FALSE)
  4365. goto exit;
  4366. _rtw_memset(&sta->vhtpriv, 0, sizeof(struct vht_priv));
  4367. if (elems->vht_capabilities && elems->vht_capabilities_len == VHT_CAP_IE_LEN) {
  4368. sta->flags |= WLAN_STA_VHT;
  4369. _rtw_memcpy(sta->vhtpriv.vht_cap, elems->vht_capabilities, VHT_CAP_IE_LEN);
  4370. if (elems->vht_operation && elems->vht_operation_len== VHT_OP_IE_LEN) {
  4371. _rtw_memcpy(sta->vhtpriv.vht_op, elems->vht_operation, VHT_OP_IE_LEN);
  4372. sta->vhtpriv.op_present = 1;
  4373. }
  4374. if (elems->vht_op_mode_notify && elems->vht_op_mode_notify_len == 1) {
  4375. _rtw_memcpy(&sta->vhtpriv.vht_op_mode_notify, elems->vht_op_mode_notify, 1);
  4376. sta->vhtpriv.notify_present = 1;
  4377. }
  4378. }
  4379. exit:
  4380. #endif
  4381. return;
  4382. }
  4383. #endif /* CONFIG_AP_MODE */