rtw_wlan_util.c 123 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_WLAN_UTIL_C_
  21. #include <drv_types.h>
  22. #include <hal_data.h>
  23. #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
  24. #include <linux/inetdevice.h>
  25. #define ETH_TYPE_OFFSET 12
  26. #define PROTOCOL_OFFSET 23
  27. #define IP_OFFSET 30
  28. #endif
  29. unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f};
  30. unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74};
  31. unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18};
  32. unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7};
  33. unsigned char BROADCOM_OUI3[] = {0x00, 0x05, 0xb5};
  34. unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96};
  35. unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43};
  36. unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43};
  37. unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c};
  38. unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5};
  39. unsigned char REALTEK_96B_IE[] = {0x00, 0xe0, 0x4c, 0x02, 0x01, 0x20};
  40. extern unsigned char RTW_WPA_OUI[];
  41. extern unsigned char WPA_TKIP_CIPHER[4];
  42. extern unsigned char RSN_TKIP_CIPHER[4];
  43. #define R2T_PHY_DELAY (0)
  44. /* #define WAIT_FOR_BCN_TO_MIN (3000) */
  45. #define WAIT_FOR_BCN_TO_MIN (6000)
  46. #define WAIT_FOR_BCN_TO_MAX (20000)
  47. #define DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS 1000
  48. #define DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD 3
  49. static u8 rtw_basic_rate_cck[4] = {
  50. IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
  51. IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK
  52. };
  53. static u8 rtw_basic_rate_ofdm[3] = {
  54. IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
  55. IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
  56. };
  57. static u8 rtw_basic_rate_mix[7] = {
  58. IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
  59. IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK,
  60. IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
  61. IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
  62. };
  63. int new_bcn_max = 3;
  64. int cckrates_included(unsigned char *rate, int ratelen)
  65. {
  66. int i;
  67. for (i = 0; i < ratelen; i++) {
  68. if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
  69. (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
  70. return _TRUE;
  71. }
  72. return _FALSE;
  73. }
  74. int cckratesonly_included(unsigned char *rate, int ratelen)
  75. {
  76. int i;
  77. for (i = 0; i < ratelen; i++) {
  78. if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
  79. (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
  80. return _FALSE;
  81. }
  82. return _TRUE;
  83. }
  84. #ifdef CONFIG_GET_RAID_BY_DRV
  85. s8 rtw_get_tx_nss(_adapter *adapter, struct sta_info *psta)
  86. {
  87. struct hal_spec_t *hal_spec = GET_HAL_SPEC(adapter);
  88. u8 rf_type = RF_1T1R, custom_rf_type;
  89. s8 nss = 1;
  90. if (!psta)
  91. return nss;
  92. custom_rf_type = adapter->registrypriv.rf_config;
  93. rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  94. if (RF_TYPE_VALID(custom_rf_type))
  95. rf_type = custom_rf_type;
  96. #ifdef CONFIG_80211AC_VHT
  97. if (psta->vhtpriv.vht_option) {
  98. nss = rtw_min(rf_type_to_rf_tx_cnt(rf_type), hal_spec->tx_nss_num);
  99. nss = rtw_min(nss, rtw_vht_mcsmap_to_nss(psta->vhtpriv.vht_mcs_map));
  100. } else
  101. #endif /* CONFIG_80211AC_VHT */
  102. if (psta->htpriv.ht_option) {
  103. nss = rtw_min(rf_type_to_rf_tx_cnt(rf_type), hal_spec->tx_nss_num);
  104. nss = rtw_min(nss, rtw_ht_mcsset_to_nss(psta->htpriv.ht_cap.supp_mcs_set));
  105. }
  106. RTW_INFO("%s: %d SS\n", __func__, nss);
  107. return nss;
  108. }
  109. u8 networktype_to_raid(_adapter *adapter, struct sta_info *psta)
  110. {
  111. unsigned char raid;
  112. switch (psta->wireless_mode) {
  113. case WIRELESS_11B:
  114. raid = RATR_INX_WIRELESS_B;
  115. break;
  116. case WIRELESS_11A:
  117. case WIRELESS_11G:
  118. raid = RATR_INX_WIRELESS_G;
  119. break;
  120. case WIRELESS_11BG:
  121. raid = RATR_INX_WIRELESS_GB;
  122. break;
  123. case WIRELESS_11_24N:
  124. case WIRELESS_11_5N:
  125. raid = RATR_INX_WIRELESS_N;
  126. break;
  127. case WIRELESS_11A_5N:
  128. case WIRELESS_11G_24N:
  129. raid = RATR_INX_WIRELESS_NG;
  130. break;
  131. case WIRELESS_11BG_24N:
  132. raid = RATR_INX_WIRELESS_NGB;
  133. break;
  134. default:
  135. raid = RATR_INX_WIRELESS_GB;
  136. break;
  137. }
  138. return raid;
  139. }
  140. u8 networktype_to_raid_ex(_adapter *adapter, struct sta_info *psta)
  141. {
  142. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  143. u8 raid = RATEID_IDX_BGN_40M_1SS, cur_rf_type, rf_type, custom_rf_type;
  144. s8 tx_nss;
  145. tx_nss = rtw_get_tx_nss(adapter, psta);
  146. switch (psta->wireless_mode) {
  147. case WIRELESS_11B:
  148. raid = RATEID_IDX_B;
  149. break;
  150. case WIRELESS_11A:
  151. case WIRELESS_11G:
  152. raid = RATEID_IDX_G;
  153. break;
  154. case WIRELESS_11BG:
  155. raid = RATEID_IDX_BG;
  156. break;
  157. case WIRELESS_11_24N:
  158. case WIRELESS_11_5N:
  159. case WIRELESS_11A_5N:
  160. case WIRELESS_11G_24N:
  161. if (tx_nss == 1)
  162. raid = RATEID_IDX_GN_N1SS;
  163. else if (tx_nss == 2)
  164. raid = RATEID_IDX_GN_N2SS;
  165. else if (tx_nss == 3)
  166. raid = RATEID_IDX_BGN_3SS;
  167. else
  168. RTW_INFO("tx_nss error!(tx_nss=%d)\n", tx_nss);
  169. break;
  170. case WIRELESS_11B_24N:
  171. case WIRELESS_11BG_24N:
  172. if (psta->bw_mode == CHANNEL_WIDTH_20) {
  173. if (tx_nss == 1)
  174. raid = RATEID_IDX_BGN_20M_1SS_BN;
  175. else if (tx_nss == 2)
  176. raid = RATEID_IDX_BGN_20M_2SS_BN;
  177. else if (tx_nss == 3)
  178. raid = RATEID_IDX_BGN_3SS;
  179. else
  180. RTW_INFO("tx_nss error!(tx_nss=%d)\n", tx_nss);
  181. } else {
  182. if (tx_nss == 1)
  183. raid = RATEID_IDX_BGN_40M_1SS;
  184. else if (tx_nss == 2)
  185. raid = RATEID_IDX_BGN_40M_2SS;
  186. else if (tx_nss == 3)
  187. raid = RATEID_IDX_BGN_3SS;
  188. else
  189. RTW_INFO("tx_nss error!(tx_nss=%d)\n", tx_nss);
  190. }
  191. break;
  192. #ifdef CONFIG_80211AC_VHT
  193. case WIRELESS_11_5AC:
  194. if (tx_nss == 1)
  195. raid = RATEID_IDX_VHT_1SS;
  196. else if (tx_nss == 2)
  197. raid = RATEID_IDX_VHT_2SS;
  198. else if (tx_nss == 3)
  199. raid = RATEID_IDX_VHT_3SS;
  200. else
  201. RTW_INFO("tx_nss error!(tx_nss=%d)\n", tx_nss);
  202. break;
  203. case WIRELESS_11_24AC:
  204. if (psta->bw_mode >= CHANNEL_WIDTH_80) {
  205. if (tx_nss == 1)
  206. raid = RATEID_IDX_VHT_1SS;
  207. else if (tx_nss == 2)
  208. raid = RATEID_IDX_VHT_2SS;
  209. else if (tx_nss == 3)
  210. raid = RATEID_IDX_VHT_3SS;
  211. else
  212. RTW_INFO("tx_nss error!(tx_nss=%d)\n", tx_nss);
  213. } else {
  214. if (tx_nss == 1)
  215. raid = RATEID_IDX_MIX1;
  216. else if (tx_nss == 2)
  217. raid = RATEID_IDX_MIX2;
  218. else if (tx_nss == 3)
  219. raid = RATEID_IDX_VHT_3SS;
  220. else
  221. RTW_INFO("tx_nss error!(tx_nss=%d)\n", tx_nss);
  222. }
  223. break;
  224. #endif
  225. default:
  226. RTW_INFO("unexpected wireless mode!(psta->wireless_mode=%x)\n", psta->wireless_mode);
  227. break;
  228. }
  229. /* RTW_INFO("psta->wireless_mode=%x, tx_nss=%d\n", psta->wireless_mode, tx_nss); */
  230. return raid;
  231. }
  232. #endif
  233. u8 judge_network_type(_adapter *padapter, unsigned char *rate, int ratelen)
  234. {
  235. u8 network_type = 0;
  236. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  237. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  238. if (pmlmeext->cur_channel > 14) {
  239. if (pmlmeinfo->VHT_enable)
  240. network_type = WIRELESS_11AC;
  241. else if (pmlmeinfo->HT_enable)
  242. network_type = WIRELESS_11_5N;
  243. network_type |= WIRELESS_11A;
  244. } else {
  245. if (pmlmeinfo->HT_enable)
  246. network_type = WIRELESS_11_24N;
  247. if ((cckratesonly_included(rate, ratelen)) == _TRUE)
  248. network_type |= WIRELESS_11B;
  249. else if ((cckrates_included(rate, ratelen)) == _TRUE)
  250. network_type |= WIRELESS_11BG;
  251. else
  252. network_type |= WIRELESS_11G;
  253. }
  254. return network_type;
  255. }
  256. unsigned char ratetbl_val_2wifirate(unsigned char rate);
  257. unsigned char ratetbl_val_2wifirate(unsigned char rate)
  258. {
  259. unsigned char val = 0;
  260. switch (rate & 0x7f) {
  261. case 0:
  262. val = IEEE80211_CCK_RATE_1MB;
  263. break;
  264. case 1:
  265. val = IEEE80211_CCK_RATE_2MB;
  266. break;
  267. case 2:
  268. val = IEEE80211_CCK_RATE_5MB;
  269. break;
  270. case 3:
  271. val = IEEE80211_CCK_RATE_11MB;
  272. break;
  273. case 4:
  274. val = IEEE80211_OFDM_RATE_6MB;
  275. break;
  276. case 5:
  277. val = IEEE80211_OFDM_RATE_9MB;
  278. break;
  279. case 6:
  280. val = IEEE80211_OFDM_RATE_12MB;
  281. break;
  282. case 7:
  283. val = IEEE80211_OFDM_RATE_18MB;
  284. break;
  285. case 8:
  286. val = IEEE80211_OFDM_RATE_24MB;
  287. break;
  288. case 9:
  289. val = IEEE80211_OFDM_RATE_36MB;
  290. break;
  291. case 10:
  292. val = IEEE80211_OFDM_RATE_48MB;
  293. break;
  294. case 11:
  295. val = IEEE80211_OFDM_RATE_54MB;
  296. break;
  297. }
  298. return val;
  299. }
  300. int is_basicrate(_adapter *padapter, unsigned char rate);
  301. int is_basicrate(_adapter *padapter, unsigned char rate)
  302. {
  303. int i;
  304. unsigned char val;
  305. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  306. for (i = 0; i < NumRates; i++) {
  307. val = pmlmeext->basicrate[i];
  308. if ((val != 0xff) && (val != 0xfe)) {
  309. if (rate == ratetbl_val_2wifirate(val))
  310. return _TRUE;
  311. }
  312. }
  313. return _FALSE;
  314. }
  315. unsigned int ratetbl2rateset(_adapter *padapter, unsigned char *rateset);
  316. unsigned int ratetbl2rateset(_adapter *padapter, unsigned char *rateset)
  317. {
  318. int i;
  319. unsigned char rate;
  320. unsigned int len = 0;
  321. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  322. for (i = 0; i < NumRates; i++) {
  323. rate = pmlmeext->datarate[i];
  324. if (rtw_get_oper_ch(padapter) > 14 && rate < _6M_RATE_) /*5G no support CCK rate*/
  325. continue;
  326. switch (rate) {
  327. case 0xff:
  328. return len;
  329. case 0xfe:
  330. continue;
  331. default:
  332. rate = ratetbl_val_2wifirate(rate);
  333. if (is_basicrate(padapter, rate) == _TRUE)
  334. rate |= IEEE80211_BASIC_RATE_MASK;
  335. rateset[len] = rate;
  336. len++;
  337. break;
  338. }
  339. }
  340. return len;
  341. }
  342. void get_rate_set(_adapter *padapter, unsigned char *pbssrate, int *bssrate_len)
  343. {
  344. unsigned char supportedrates[NumRates];
  345. _rtw_memset(supportedrates, 0, NumRates);
  346. *bssrate_len = ratetbl2rateset(padapter, supportedrates);
  347. _rtw_memcpy(pbssrate, supportedrates, *bssrate_len);
  348. }
  349. void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask)
  350. {
  351. u8 mcs_rate_1r = (u8)(mask & 0xff);
  352. u8 mcs_rate_2r = (u8)((mask >> 8) & 0xff);
  353. u8 mcs_rate_3r = (u8)((mask >> 16) & 0xff);
  354. u8 mcs_rate_4r = (u8)((mask >> 24) & 0xff);
  355. mcs_set[0] &= mcs_rate_1r;
  356. mcs_set[1] &= mcs_rate_2r;
  357. mcs_set[2] &= mcs_rate_3r;
  358. mcs_set[3] &= mcs_rate_4r;
  359. }
  360. void UpdateBrateTbl(
  361. IN PADAPTER Adapter,
  362. IN u8 *mBratesOS
  363. )
  364. {
  365. u8 i;
  366. u8 rate;
  367. /* 1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory. */
  368. for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
  369. rate = mBratesOS[i] & 0x7f;
  370. switch (rate) {
  371. case IEEE80211_CCK_RATE_1MB:
  372. case IEEE80211_CCK_RATE_2MB:
  373. case IEEE80211_CCK_RATE_5MB:
  374. case IEEE80211_CCK_RATE_11MB:
  375. case IEEE80211_OFDM_RATE_6MB:
  376. case IEEE80211_OFDM_RATE_12MB:
  377. case IEEE80211_OFDM_RATE_24MB:
  378. mBratesOS[i] |= IEEE80211_BASIC_RATE_MASK;
  379. break;
  380. }
  381. }
  382. }
  383. void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen)
  384. {
  385. u8 i;
  386. u8 rate;
  387. for (i = 0; i < bssratelen; i++) {
  388. rate = bssrateset[i] & 0x7f;
  389. switch (rate) {
  390. case IEEE80211_CCK_RATE_1MB:
  391. case IEEE80211_CCK_RATE_2MB:
  392. case IEEE80211_CCK_RATE_5MB:
  393. case IEEE80211_CCK_RATE_11MB:
  394. bssrateset[i] |= IEEE80211_BASIC_RATE_MASK;
  395. break;
  396. }
  397. }
  398. }
  399. void Set_MSR(_adapter *padapter, u8 type)
  400. {
  401. rtw_hal_set_hwreg(padapter, HW_VAR_MEDIA_STATUS, (u8 *)(&type));
  402. }
  403. inline u8 rtw_get_oper_ch(_adapter *adapter)
  404. {
  405. return adapter_to_dvobj(adapter)->oper_channel;
  406. }
  407. inline void rtw_set_oper_ch(_adapter *adapter, u8 ch)
  408. {
  409. #ifdef DBG_CH_SWITCH
  410. const int len = 128;
  411. char msg[128] = {0};
  412. int cnt = 0;
  413. int i = 0;
  414. #endif /* DBG_CH_SWITCH */
  415. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  416. if (dvobj->oper_channel != ch) {
  417. dvobj->on_oper_ch_time = rtw_get_current_time();
  418. #ifdef DBG_CH_SWITCH
  419. cnt += snprintf(msg + cnt, len - cnt, "switch to ch %3u", ch);
  420. for (i = 0; i < dvobj->iface_nums; i++) {
  421. _adapter *iface = dvobj->padapters[i];
  422. cnt += snprintf(msg + cnt, len - cnt, " ["ADPT_FMT":", ADPT_ARG(iface));
  423. if (iface->mlmeextpriv.cur_channel == ch)
  424. cnt += snprintf(msg + cnt, len - cnt, "C");
  425. else
  426. cnt += snprintf(msg + cnt, len - cnt, "_");
  427. if (iface->wdinfo.listen_channel == ch && !rtw_p2p_chk_state(&iface->wdinfo, P2P_STATE_NONE))
  428. cnt += snprintf(msg + cnt, len - cnt, "L");
  429. else
  430. cnt += snprintf(msg + cnt, len - cnt, "_");
  431. cnt += snprintf(msg + cnt, len - cnt, "]");
  432. }
  433. RTW_INFO(FUNC_ADPT_FMT" %s\n", FUNC_ADPT_ARG(adapter), msg);
  434. #endif /* DBG_CH_SWITCH */
  435. }
  436. dvobj->oper_channel = ch;
  437. }
  438. inline u8 rtw_get_oper_bw(_adapter *adapter)
  439. {
  440. return adapter_to_dvobj(adapter)->oper_bwmode;
  441. }
  442. inline void rtw_set_oper_bw(_adapter *adapter, u8 bw)
  443. {
  444. adapter_to_dvobj(adapter)->oper_bwmode = bw;
  445. }
  446. inline u8 rtw_get_oper_choffset(_adapter *adapter)
  447. {
  448. return adapter_to_dvobj(adapter)->oper_ch_offset;
  449. }
  450. inline void rtw_set_oper_choffset(_adapter *adapter, u8 offset)
  451. {
  452. adapter_to_dvobj(adapter)->oper_ch_offset = offset;
  453. }
  454. u8 rtw_get_offset_by_chbw(u8 ch, u8 bw, u8 *r_offset)
  455. {
  456. u8 valid = 1;
  457. u8 offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  458. if (bw == CHANNEL_WIDTH_20)
  459. goto exit;
  460. if (bw >= CHANNEL_WIDTH_80 && ch <= 14) {
  461. valid = 0;
  462. goto exit;
  463. }
  464. if (ch >= 1 && ch <= 4)
  465. offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  466. else if (ch >= 5 && ch <= 9) {
  467. if (*r_offset == HAL_PRIME_CHNL_OFFSET_LOWER || *r_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
  468. offset = *r_offset; /* both lower and upper is valid, obey input value */
  469. else
  470. offset = HAL_PRIME_CHNL_OFFSET_UPPER; /* default use upper */
  471. } else if (ch >= 10 && ch <= 13)
  472. offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  473. else if (ch == 14) {
  474. valid = 0; /* ch14 doesn't support 40MHz bandwidth */
  475. goto exit;
  476. } else if (ch >= 36 && ch <= 177) {
  477. switch (ch) {
  478. case 36:
  479. case 44:
  480. case 52:
  481. case 60:
  482. case 100:
  483. case 108:
  484. case 116:
  485. case 124:
  486. case 132:
  487. case 140:
  488. case 149:
  489. case 157:
  490. case 165:
  491. case 173:
  492. offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  493. break;
  494. case 40:
  495. case 48:
  496. case 56:
  497. case 64:
  498. case 104:
  499. case 112:
  500. case 120:
  501. case 128:
  502. case 136:
  503. case 144:
  504. case 153:
  505. case 161:
  506. case 169:
  507. case 177:
  508. offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  509. break;
  510. default:
  511. valid = 0;
  512. break;
  513. }
  514. } else
  515. valid = 0;
  516. exit:
  517. if (valid && r_offset)
  518. *r_offset = offset;
  519. return valid;
  520. }
  521. u8 rtw_get_offset_by_ch(u8 channel)
  522. {
  523. u8 offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  524. if (channel >= 1 && channel <= 4)
  525. offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  526. else if (channel >= 5 && channel <= 14)
  527. offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  528. else {
  529. switch (channel) {
  530. case 36:
  531. case 44:
  532. case 52:
  533. case 60:
  534. case 100:
  535. case 108:
  536. case 116:
  537. case 124:
  538. case 132:
  539. case 149:
  540. case 157:
  541. offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  542. break;
  543. case 40:
  544. case 48:
  545. case 56:
  546. case 64:
  547. case 104:
  548. case 112:
  549. case 120:
  550. case 128:
  551. case 136:
  552. case 153:
  553. case 161:
  554. offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  555. break;
  556. default:
  557. offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  558. break;
  559. }
  560. }
  561. return offset;
  562. }
  563. u8 rtw_get_center_ch(u8 channel, u8 chnl_bw, u8 chnl_offset)
  564. {
  565. u8 center_ch = channel;
  566. if (chnl_bw == CHANNEL_WIDTH_80) {
  567. if (channel == 36 || channel == 40 || channel == 44 || channel == 48)
  568. center_ch = 42;
  569. else if (channel == 52 || channel == 56 || channel == 60 || channel == 64)
  570. center_ch = 58;
  571. else if (channel == 100 || channel == 104 || channel == 108 || channel == 112)
  572. center_ch = 106;
  573. else if (channel == 116 || channel == 120 || channel == 124 || channel == 128)
  574. center_ch = 122;
  575. else if (channel == 132 || channel == 136 || channel == 140 || channel == 144)
  576. center_ch = 138;
  577. else if (channel == 149 || channel == 153 || channel == 157 || channel == 161)
  578. center_ch = 155;
  579. else if (channel == 165 || channel == 169 || channel == 173 || channel == 177)
  580. center_ch = 171;
  581. else if (channel <= 14)
  582. center_ch = 7;
  583. } else if (chnl_bw == CHANNEL_WIDTH_40) {
  584. if (chnl_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
  585. center_ch = channel + 2;
  586. else
  587. center_ch = channel - 2;
  588. } else if (chnl_bw == CHANNEL_WIDTH_20)
  589. center_ch = channel;
  590. else
  591. rtw_warn_on(1);
  592. return center_ch;
  593. }
  594. inline u32 rtw_get_on_oper_ch_time(_adapter *adapter)
  595. {
  596. return adapter_to_dvobj(adapter)->on_oper_ch_time;
  597. }
  598. inline u32 rtw_get_on_cur_ch_time(_adapter *adapter)
  599. {
  600. if (adapter->mlmeextpriv.cur_channel == adapter_to_dvobj(adapter)->oper_channel)
  601. return adapter_to_dvobj(adapter)->on_oper_ch_time;
  602. else
  603. return 0;
  604. }
  605. void set_channel_bwmode(_adapter *padapter, unsigned char channel, unsigned char channel_offset, unsigned short bwmode)
  606. {
  607. u8 center_ch, chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  608. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  609. #if (defined(CONFIG_TDLS) && defined(CONFIG_TDLS_CH_SW)) || defined(CONFIG_MCC_MODE)
  610. u8 iqk_info_backup = _FALSE;
  611. #endif
  612. if (padapter->bNotifyChannelChange)
  613. RTW_INFO("[%s] ch = %d, offset = %d, bwmode = %d\n", __FUNCTION__, channel, channel_offset, bwmode);
  614. center_ch = rtw_get_center_ch(channel, bwmode, channel_offset);
  615. if (bwmode == CHANNEL_WIDTH_80) {
  616. if (center_ch > channel)
  617. chnl_offset80 = HAL_PRIME_CHNL_OFFSET_LOWER;
  618. else if (center_ch < channel)
  619. chnl_offset80 = HAL_PRIME_CHNL_OFFSET_UPPER;
  620. else
  621. chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  622. }
  623. _enter_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
  624. #ifdef CONFIG_MCC_MODE
  625. if (MCC_EN(padapter)) {
  626. /* driver doesn't set channel setting reg under MCC */
  627. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)) {
  628. RTW_INFO("Warning: Do not set channel setting reg MCC mode\n");
  629. rtw_warn_on(1);
  630. }
  631. }
  632. #endif
  633. #ifdef CONFIG_DFS_MASTER
  634. {
  635. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  636. bool ori_overlap_radar_detect_ch = rtw_rfctl_overlap_radar_detect_ch(rfctl);
  637. bool new_overlap_radar_detect_ch = _rtw_rfctl_overlap_radar_detect_ch(rfctl, channel, bwmode, channel_offset);
  638. if (new_overlap_radar_detect_ch && IS_CH_WAITING(rfctl)) {
  639. u8 pause = 0xFF;
  640. rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &pause);
  641. }
  642. #endif /* CONFIG_DFS_MASTER */
  643. /* set Channel */
  644. /* saved channel/bw info */
  645. rtw_set_oper_ch(padapter, channel);
  646. rtw_set_oper_bw(padapter, bwmode);
  647. rtw_set_oper_choffset(padapter, channel_offset);
  648. #if (defined(CONFIG_TDLS) && defined(CONFIG_TDLS_CH_SW)) || defined(CONFIG_MCC_MODE)
  649. /* To check if we need to backup iqk info after switch chnl & bw */
  650. {
  651. u8 take_care_iqk, do_iqk;
  652. rtw_hal_get_hwreg(padapter, HW_VAR_CH_SW_NEED_TO_TAKE_CARE_IQK_INFO, &take_care_iqk);
  653. rtw_hal_get_hwreg(padapter, HW_VAR_DO_IQK, &do_iqk);
  654. if ((take_care_iqk == _TRUE) && (do_iqk == _TRUE))
  655. iqk_info_backup = _TRUE;
  656. }
  657. #endif
  658. rtw_hal_set_chnl_bw(padapter, center_ch, bwmode, channel_offset, chnl_offset80); /* set center channel */
  659. #if (defined(CONFIG_TDLS) && defined(CONFIG_TDLS_CH_SW)) || defined(CONFIG_MCC_MODE)
  660. if (iqk_info_backup == _TRUE)
  661. rtw_hal_ch_sw_iqk_info_backup(padapter);
  662. #endif
  663. #ifdef CONFIG_DFS_MASTER
  664. if (new_overlap_radar_detect_ch)
  665. rtw_odm_radar_detect_enable(padapter);
  666. else if (ori_overlap_radar_detect_ch) {
  667. u8 pause = 0x00;
  668. rtw_odm_radar_detect_disable(padapter);
  669. rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, &pause);
  670. }
  671. }
  672. #endif /* CONFIG_DFS_MASTER */
  673. _exit_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
  674. }
  675. int get_bsstype(unsigned short capability)
  676. {
  677. if (capability & BIT(0))
  678. return WIFI_FW_AP_STATE;
  679. else if (capability & BIT(1))
  680. return WIFI_FW_ADHOC_STATE;
  681. else
  682. return 0;
  683. }
  684. __inline u8 *get_my_bssid(WLAN_BSSID_EX *pnetwork)
  685. {
  686. return pnetwork->MacAddress;
  687. }
  688. u16 get_beacon_interval(WLAN_BSSID_EX *bss)
  689. {
  690. unsigned short val;
  691. _rtw_memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2);
  692. return le16_to_cpu(val);
  693. }
  694. int is_client_associated_to_ap(_adapter *padapter)
  695. {
  696. struct mlme_ext_priv *pmlmeext;
  697. struct mlme_ext_info *pmlmeinfo;
  698. if (!padapter)
  699. return _FAIL;
  700. pmlmeext = &padapter->mlmeextpriv;
  701. pmlmeinfo = &(pmlmeext->mlmext_info);
  702. if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
  703. return _TRUE;
  704. else
  705. return _FAIL;
  706. }
  707. int is_client_associated_to_ibss(_adapter *padapter)
  708. {
  709. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  710. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  711. if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
  712. return _TRUE;
  713. else
  714. return _FAIL;
  715. }
  716. int is_IBSS_empty(_adapter *padapter)
  717. {
  718. int i;
  719. struct macid_ctl_t *macid_ctl = &padapter->dvobj->macid_ctl;
  720. for (i = 0; i < macid_ctl->num; i++) {
  721. if (!rtw_macid_is_used(macid_ctl, i))
  722. continue;
  723. if (rtw_macid_get_if_g(macid_ctl, i) != padapter->iface_id)
  724. continue;
  725. if (!GET_H2CCMD_MSRRPT_PARM_OPMODE(&macid_ctl->h2c_msr[i]))
  726. continue;
  727. if (GET_H2CCMD_MSRRPT_PARM_ROLE(&macid_ctl->h2c_msr[i]) == H2C_MSR_ROLE_ADHOC)
  728. return _FAIL;
  729. }
  730. return _TRUE;
  731. }
  732. unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval)
  733. {
  734. if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN)
  735. return WAIT_FOR_BCN_TO_MIN;
  736. else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX)
  737. return WAIT_FOR_BCN_TO_MAX;
  738. else
  739. return bcn_interval << 2;
  740. }
  741. void CAM_empty_entry(
  742. PADAPTER Adapter,
  743. u8 ucIndex
  744. )
  745. {
  746. rtw_hal_set_hwreg(Adapter, HW_VAR_CAM_EMPTY_ENTRY, (u8 *)(&ucIndex));
  747. }
  748. void invalidate_cam_all(_adapter *padapter)
  749. {
  750. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  751. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  752. _irqL irqL;
  753. u8 val8 = 0;
  754. rtw_hal_set_hwreg(padapter, HW_VAR_CAM_INVALID_ALL, &val8);
  755. _enter_critical_bh(&cam_ctl->lock, &irqL);
  756. rtw_sec_cam_map_clr_all(&cam_ctl->used);
  757. _rtw_memset(dvobj->cam_cache, 0, sizeof(struct sec_cam_ent) * SEC_CAM_ENT_NUM_SW_LIMIT);
  758. _exit_critical_bh(&cam_ctl->lock, &irqL);
  759. }
  760. void _clear_cam_entry(_adapter *padapter, u8 entry)
  761. {
  762. unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  763. unsigned char null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  764. rtw_sec_write_cam_ent(padapter, entry, 0, null_sta, null_key);
  765. }
  766. inline void write_cam(_adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key)
  767. {
  768. #ifdef CONFIG_WRITE_CACHE_ONLY
  769. write_cam_cache(adapter, id , ctrl, mac, key);
  770. #else
  771. rtw_sec_write_cam_ent(adapter, id, ctrl, mac, key);
  772. write_cam_cache(adapter, id , ctrl, mac, key);
  773. #endif
  774. }
  775. inline void clear_cam_entry(_adapter *adapter, u8 id)
  776. {
  777. _clear_cam_entry(adapter, id);
  778. clear_cam_cache(adapter, id);
  779. }
  780. inline void write_cam_from_cache(_adapter *adapter, u8 id)
  781. {
  782. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  783. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  784. _irqL irqL;
  785. struct sec_cam_ent cache;
  786. _enter_critical_bh(&cam_ctl->lock, &irqL);
  787. _rtw_memcpy(&cache, &dvobj->cam_cache[id], sizeof(struct sec_cam_ent));
  788. _exit_critical_bh(&cam_ctl->lock, &irqL);
  789. rtw_sec_write_cam_ent(adapter, id, cache.ctrl, cache.mac, cache.key);
  790. }
  791. void write_cam_cache(_adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key)
  792. {
  793. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  794. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  795. _irqL irqL;
  796. _enter_critical_bh(&cam_ctl->lock, &irqL);
  797. dvobj->cam_cache[id].ctrl = ctrl;
  798. _rtw_memcpy(dvobj->cam_cache[id].mac, mac, ETH_ALEN);
  799. _rtw_memcpy(dvobj->cam_cache[id].key, key, 16);
  800. _exit_critical_bh(&cam_ctl->lock, &irqL);
  801. }
  802. void clear_cam_cache(_adapter *adapter, u8 id)
  803. {
  804. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  805. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  806. _irqL irqL;
  807. _enter_critical_bh(&cam_ctl->lock, &irqL);
  808. _rtw_memset(&(dvobj->cam_cache[id]), 0, sizeof(struct sec_cam_ent));
  809. _exit_critical_bh(&cam_ctl->lock, &irqL);
  810. }
  811. inline bool _rtw_camctl_chk_cap(_adapter *adapter, u8 cap)
  812. {
  813. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  814. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  815. if (cam_ctl->sec_cap & cap)
  816. return _TRUE;
  817. return _FALSE;
  818. }
  819. inline void _rtw_camctl_set_flags(_adapter *adapter, u32 flags)
  820. {
  821. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  822. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  823. cam_ctl->flags |= flags;
  824. }
  825. inline void rtw_camctl_set_flags(_adapter *adapter, u32 flags)
  826. {
  827. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  828. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  829. _irqL irqL;
  830. _enter_critical_bh(&cam_ctl->lock, &irqL);
  831. _rtw_camctl_set_flags(adapter, flags);
  832. _exit_critical_bh(&cam_ctl->lock, &irqL);
  833. }
  834. inline void _rtw_camctl_clr_flags(_adapter *adapter, u32 flags)
  835. {
  836. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  837. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  838. cam_ctl->flags &= ~flags;
  839. }
  840. inline void rtw_camctl_clr_flags(_adapter *adapter, u32 flags)
  841. {
  842. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  843. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  844. _irqL irqL;
  845. _enter_critical_bh(&cam_ctl->lock, &irqL);
  846. _rtw_camctl_clr_flags(adapter, flags);
  847. _exit_critical_bh(&cam_ctl->lock, &irqL);
  848. }
  849. inline bool _rtw_camctl_chk_flags(_adapter *adapter, u32 flags)
  850. {
  851. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  852. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  853. if (cam_ctl->flags & flags)
  854. return _TRUE;
  855. return _FALSE;
  856. }
  857. void dump_sec_cam_map(void *sel, struct sec_cam_bmp *map, u8 max_num)
  858. {
  859. RTW_PRINT_SEL(sel, "0x%08x\n", map->m0);
  860. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
  861. if (max_num && max_num > 32)
  862. RTW_PRINT_SEL(sel, "0x%08x\n", map->m1);
  863. #endif
  864. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
  865. if (max_num && max_num > 64)
  866. RTW_PRINT_SEL(sel, "0x%08x\n", map->m2);
  867. #endif
  868. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
  869. if (max_num && max_num > 96)
  870. RTW_PRINT_SEL(sel, "0x%08x\n", map->m3);
  871. #endif
  872. }
  873. inline bool rtw_sec_camid_is_set(struct sec_cam_bmp *map, u8 id)
  874. {
  875. if (id < 32)
  876. return map->m0 & BIT(id);
  877. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
  878. else if (id < 64)
  879. return map->m1 & BIT(id - 32);
  880. #endif
  881. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
  882. else if (id < 96)
  883. return map->m2 & BIT(id - 64);
  884. #endif
  885. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
  886. else if (id < 128)
  887. return map->m3 & BIT(id - 96);
  888. #endif
  889. else
  890. rtw_warn_on(1);
  891. return 0;
  892. }
  893. inline void rtw_sec_cam_map_set(struct sec_cam_bmp *map, u8 id)
  894. {
  895. if (id < 32)
  896. map->m0 |= BIT(id);
  897. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
  898. else if (id < 64)
  899. map->m1 |= BIT(id - 32);
  900. #endif
  901. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
  902. else if (id < 96)
  903. map->m2 |= BIT(id - 64);
  904. #endif
  905. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
  906. else if (id < 128)
  907. map->m3 |= BIT(id - 96);
  908. #endif
  909. else
  910. rtw_warn_on(1);
  911. }
  912. inline void rtw_sec_cam_map_clr(struct sec_cam_bmp *map, u8 id)
  913. {
  914. if (id < 32)
  915. map->m0 &= ~BIT(id);
  916. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
  917. else if (id < 64)
  918. map->m1 &= ~BIT(id - 32);
  919. #endif
  920. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
  921. else if (id < 96)
  922. map->m2 &= ~BIT(id - 64);
  923. #endif
  924. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
  925. else if (id < 128)
  926. map->m3 &= ~BIT(id - 96);
  927. #endif
  928. else
  929. rtw_warn_on(1);
  930. }
  931. inline void rtw_sec_cam_map_clr_all(struct sec_cam_bmp *map)
  932. {
  933. map->m0 = 0;
  934. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
  935. map->m1 = 0;
  936. #endif
  937. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
  938. map->m2 = 0;
  939. #endif
  940. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
  941. map->m3 = 0;
  942. #endif
  943. }
  944. inline bool rtw_sec_camid_is_drv_forbid(struct cam_ctl_t *cam_ctl, u8 id)
  945. {
  946. struct sec_cam_bmp forbid_map;
  947. forbid_map.m0 = 0x00000ff0;
  948. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
  949. forbid_map.m1 = 0x00000000;
  950. #endif
  951. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
  952. forbid_map.m2 = 0x00000000;
  953. #endif
  954. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
  955. forbid_map.m3 = 0x00000000;
  956. #endif
  957. if (id < 32)
  958. return forbid_map.m0 & BIT(id);
  959. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 32)
  960. else if (id < 64)
  961. return forbid_map.m1 & BIT(id - 32);
  962. #endif
  963. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 64)
  964. else if (id < 96)
  965. return forbid_map.m2 & BIT(id - 64);
  966. #endif
  967. #if (SEC_CAM_ENT_NUM_SW_LIMIT > 96)
  968. else if (id < 128)
  969. return forbid_map.m3 & BIT(id - 96);
  970. #endif
  971. else
  972. rtw_warn_on(1);
  973. return 1;
  974. }
  975. bool _rtw_sec_camid_is_used(struct cam_ctl_t *cam_ctl, u8 id)
  976. {
  977. bool ret = _FALSE;
  978. if (id >= cam_ctl->num) {
  979. rtw_warn_on(1);
  980. goto exit;
  981. }
  982. #if 0 /* for testing */
  983. if (rtw_sec_camid_is_drv_forbid(cam_ctl, id)) {
  984. ret = _TRUE;
  985. goto exit;
  986. }
  987. #endif
  988. ret = rtw_sec_camid_is_set(&cam_ctl->used, id);
  989. exit:
  990. return ret;
  991. }
  992. inline bool rtw_sec_camid_is_used(struct cam_ctl_t *cam_ctl, u8 id)
  993. {
  994. _irqL irqL;
  995. bool ret;
  996. _enter_critical_bh(&cam_ctl->lock, &irqL);
  997. ret = _rtw_sec_camid_is_used(cam_ctl, id);
  998. _exit_critical_bh(&cam_ctl->lock, &irqL);
  999. return ret;
  1000. }
  1001. u8 rtw_get_sec_camid(_adapter *adapter, u8 max_bk_key_num, u8 *sec_key_id)
  1002. {
  1003. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1004. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1005. int i;
  1006. _irqL irqL;
  1007. u8 sec_cam_num = 0;
  1008. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1009. for (i = 0; i < cam_ctl->num; i++) {
  1010. if (_rtw_sec_camid_is_used(cam_ctl, i)) {
  1011. sec_key_id[sec_cam_num++] = i;
  1012. if (sec_cam_num == max_bk_key_num)
  1013. break;
  1014. }
  1015. }
  1016. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1017. return sec_cam_num;
  1018. }
  1019. inline bool _rtw_camid_is_gk(_adapter *adapter, u8 cam_id)
  1020. {
  1021. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1022. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1023. bool ret = _FALSE;
  1024. if (cam_id >= cam_ctl->num) {
  1025. rtw_warn_on(1);
  1026. goto exit;
  1027. }
  1028. if (_rtw_sec_camid_is_used(cam_ctl, cam_id) == _FALSE)
  1029. goto exit;
  1030. ret = (dvobj->cam_cache[cam_id].ctrl & BIT6) ? _TRUE : _FALSE;
  1031. exit:
  1032. return ret;
  1033. }
  1034. inline bool rtw_camid_is_gk(_adapter *adapter, u8 cam_id)
  1035. {
  1036. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1037. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1038. _irqL irqL;
  1039. bool ret;
  1040. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1041. ret = _rtw_camid_is_gk(adapter, cam_id);
  1042. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1043. return ret;
  1044. }
  1045. bool cam_cache_chk(_adapter *adapter, u8 id, u8 *addr, s16 kid, s8 gk)
  1046. {
  1047. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1048. bool ret = _FALSE;
  1049. if (addr && _rtw_memcmp(dvobj->cam_cache[id].mac, addr, ETH_ALEN) == _FALSE)
  1050. goto exit;
  1051. if (kid >= 0 && kid != (dvobj->cam_cache[id].ctrl & 0x03))
  1052. goto exit;
  1053. if (gk != -1 && (gk ? _TRUE : _FALSE) != _rtw_camid_is_gk(adapter, id))
  1054. goto exit;
  1055. ret = _TRUE;
  1056. exit:
  1057. return ret;
  1058. }
  1059. s16 _rtw_camid_search(_adapter *adapter, u8 *addr, s16 kid, s8 gk)
  1060. {
  1061. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1062. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1063. int i;
  1064. s16 cam_id = -1;
  1065. for (i = 0; i < cam_ctl->num; i++) {
  1066. if (cam_cache_chk(adapter, i, addr, kid, gk)) {
  1067. cam_id = i;
  1068. break;
  1069. }
  1070. }
  1071. if (0) {
  1072. if (addr)
  1073. RTW_INFO(FUNC_ADPT_FMT" addr:"MAC_FMT" kid:%d, gk:%d, return cam_id:%d\n"
  1074. , FUNC_ADPT_ARG(adapter), MAC_ARG(addr), kid, gk, cam_id);
  1075. else
  1076. RTW_INFO(FUNC_ADPT_FMT" addr:%p kid:%d, gk:%d, return cam_id:%d\n"
  1077. , FUNC_ADPT_ARG(adapter), addr, kid, gk, cam_id);
  1078. }
  1079. return cam_id;
  1080. }
  1081. s16 rtw_camid_search(_adapter *adapter, u8 *addr, s16 kid, s8 gk)
  1082. {
  1083. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1084. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1085. _irqL irqL;
  1086. s16 cam_id = -1;
  1087. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1088. cam_id = _rtw_camid_search(adapter, addr, kid, gk);
  1089. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1090. return cam_id;
  1091. }
  1092. s16 rtw_get_camid(_adapter *adapter, struct sta_info *sta, u8 *addr, s16 kid)
  1093. {
  1094. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1095. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1096. int i;
  1097. #if 0 /* for testing */
  1098. static u8 start_id = 0;
  1099. #else
  1100. u8 start_id = 0;
  1101. #endif
  1102. s16 cam_id = -1;
  1103. if (addr == NULL) {
  1104. RTW_PRINT(FUNC_ADPT_FMT" mac_address is NULL\n"
  1105. , FUNC_ADPT_ARG(adapter));
  1106. rtw_warn_on(1);
  1107. goto _exit;
  1108. }
  1109. /* find cam entry which has the same addr, kid (, gk bit) */
  1110. if (_rtw_camctl_chk_cap(adapter, SEC_CAP_CHK_BMC) == _TRUE)
  1111. i = _rtw_camid_search(adapter, addr, kid, sta ? _FALSE : _TRUE);
  1112. else
  1113. i = _rtw_camid_search(adapter, addr, kid, -1);
  1114. if (i >= 0) {
  1115. cam_id = i;
  1116. goto _exit;
  1117. }
  1118. for (i = 0; i < cam_ctl->num; i++) {
  1119. /* bypass default key which is allocated statically */
  1120. #ifndef CONFIG_CONCURRENT_MODE
  1121. if (((i + start_id) % cam_ctl->num) < 4)
  1122. continue;
  1123. #endif
  1124. if (_rtw_sec_camid_is_used(cam_ctl, ((i + start_id) % cam_ctl->num)) == _FALSE)
  1125. break;
  1126. }
  1127. if (i == cam_ctl->num) {
  1128. if (sta)
  1129. RTW_PRINT(FUNC_ADPT_FMT" pairwise key with "MAC_FMT" id:%u no room\n"
  1130. , FUNC_ADPT_ARG(adapter), MAC_ARG(addr), kid);
  1131. else
  1132. RTW_PRINT(FUNC_ADPT_FMT" group key with "MAC_FMT" id:%u no room\n"
  1133. , FUNC_ADPT_ARG(adapter), MAC_ARG(addr), kid);
  1134. rtw_warn_on(1);
  1135. goto _exit;
  1136. }
  1137. cam_id = ((i + start_id) % cam_ctl->num);
  1138. start_id = ((i + start_id + 1) % cam_ctl->num);
  1139. _exit:
  1140. return cam_id;
  1141. }
  1142. s16 rtw_camid_alloc(_adapter *adapter, struct sta_info *sta, u8 kid, bool *used)
  1143. {
  1144. struct mlme_ext_info *mlmeinfo = &adapter->mlmeextpriv.mlmext_info;
  1145. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1146. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1147. _irqL irqL;
  1148. s16 cam_id = -1;
  1149. *used = _FALSE;
  1150. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1151. if ((((mlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) || ((mlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
  1152. && !sta) {
  1153. #ifndef CONFIG_CONCURRENT_MODE
  1154. /* AP/Ad-hoc mode group key static alloction to default key by key ID on Non-concurrent*/
  1155. if (kid > 3) {
  1156. RTW_PRINT(FUNC_ADPT_FMT" group key with invalid key id:%u\n"
  1157. , FUNC_ADPT_ARG(adapter), kid);
  1158. rtw_warn_on(1);
  1159. goto bitmap_handle;
  1160. }
  1161. cam_id = kid;
  1162. #else
  1163. u8 *addr = adapter_mac_addr(adapter);
  1164. cam_id = rtw_get_camid(adapter, sta, addr, kid);
  1165. if (1)
  1166. RTW_PRINT(FUNC_ADPT_FMT" group key with "MAC_FMT" assigned cam_id:%u\n"
  1167. , FUNC_ADPT_ARG(adapter), MAC_ARG(addr), cam_id);
  1168. #endif
  1169. } else {
  1170. u8 *addr = sta ? sta->hwaddr : NULL;
  1171. if (!sta) {
  1172. if (!(mlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
  1173. /* bypass STA mode group key setting before connected(ex:WEP) because bssid is not ready */
  1174. goto bitmap_handle;
  1175. }
  1176. addr = get_bssid(&adapter->mlmepriv);/*A2*/
  1177. }
  1178. cam_id = rtw_get_camid(adapter, sta, addr, kid);
  1179. }
  1180. bitmap_handle:
  1181. if (cam_id >= 0) {
  1182. *used = _rtw_sec_camid_is_used(cam_ctl, cam_id);
  1183. rtw_sec_cam_map_set(&cam_ctl->used, cam_id);
  1184. }
  1185. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1186. return cam_id;
  1187. }
  1188. void rtw_camid_set(_adapter *adapter, u8 cam_id)
  1189. {
  1190. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1191. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1192. _irqL irqL;
  1193. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1194. if (cam_id < cam_ctl->num)
  1195. rtw_sec_cam_map_set(&cam_ctl->used, cam_id);
  1196. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1197. }
  1198. void rtw_camid_free(_adapter *adapter, u8 cam_id)
  1199. {
  1200. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1201. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1202. _irqL irqL;
  1203. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1204. if (cam_id < cam_ctl->num)
  1205. rtw_sec_cam_map_clr(&cam_ctl->used, cam_id);
  1206. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1207. }
  1208. /*Must pause TX/RX before use this API*/
  1209. inline void rtw_sec_cam_swap(_adapter *adapter, u8 cam_id_a, u8 cam_id_b)
  1210. {
  1211. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1212. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1213. struct sec_cam_ent cache_a, cache_b;
  1214. _irqL irqL;
  1215. bool cam_a_used, cam_b_used;
  1216. if (1)
  1217. RTW_INFO(ADPT_FMT" - sec_cam %d,%d swap\n", ADPT_ARG(adapter), cam_id_a, cam_id_b);
  1218. if (cam_id_a == cam_id_b)
  1219. return;
  1220. #ifdef CONFIG_CONCURRENT_MODE
  1221. rtw_mi_update_ap_bmc_camid(adapter, cam_id_a, cam_id_b);
  1222. #endif
  1223. /*setp-1. backup org cam_info*/
  1224. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1225. cam_a_used = _rtw_sec_camid_is_used(cam_ctl, cam_id_a);
  1226. cam_b_used = _rtw_sec_camid_is_used(cam_ctl, cam_id_b);
  1227. if (cam_a_used)
  1228. _rtw_memcpy(&cache_a, &dvobj->cam_cache[cam_id_a], sizeof(struct sec_cam_ent));
  1229. if (cam_b_used)
  1230. _rtw_memcpy(&cache_b, &dvobj->cam_cache[cam_id_b], sizeof(struct sec_cam_ent));
  1231. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1232. /*setp-2. clean cam_info*/
  1233. if (cam_a_used) {
  1234. rtw_camid_free(adapter, cam_id_a);
  1235. clear_cam_entry(adapter, cam_id_a);
  1236. }
  1237. if (cam_b_used) {
  1238. rtw_camid_free(adapter, cam_id_b);
  1239. clear_cam_entry(adapter, cam_id_b);
  1240. }
  1241. /*setp-3. set cam_info*/
  1242. if (cam_a_used) {
  1243. write_cam(adapter, cam_id_b, cache_a.ctrl, cache_a.mac, cache_a.key);
  1244. rtw_camid_set(adapter, cam_id_b);
  1245. }
  1246. if (cam_b_used) {
  1247. write_cam(adapter, cam_id_a, cache_b.ctrl, cache_b.mac, cache_b.key);
  1248. rtw_camid_set(adapter, cam_id_a);
  1249. }
  1250. }
  1251. s16 rtw_get_empty_cam_entry(_adapter *adapter, u8 start_camid)
  1252. {
  1253. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1254. struct cam_ctl_t *cam_ctl = &dvobj->cam_ctl;
  1255. _irqL irqL;
  1256. int i;
  1257. s16 cam_id = -1;
  1258. _enter_critical_bh(&cam_ctl->lock, &irqL);
  1259. for (i = start_camid; i < cam_ctl->num; i++) {
  1260. if (_FALSE == _rtw_sec_camid_is_used(cam_ctl, i)) {
  1261. cam_id = i;
  1262. break;
  1263. }
  1264. }
  1265. _exit_critical_bh(&cam_ctl->lock, &irqL);
  1266. return cam_id;
  1267. }
  1268. void rtw_clean_dk_section(_adapter *adapter)
  1269. {
  1270. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  1271. struct cam_ctl_t *cam_ctl = dvobj_to_sec_camctl(dvobj);
  1272. s16 ept_cam_id;
  1273. int i;
  1274. for (i = 0; i < 4; i++) {
  1275. if (rtw_sec_camid_is_used(cam_ctl, i)) {
  1276. ept_cam_id = rtw_get_empty_cam_entry(adapter, 4);
  1277. if (ept_cam_id > 0)
  1278. rtw_sec_cam_swap(adapter, i, ept_cam_id);
  1279. }
  1280. }
  1281. }
  1282. void rtw_clean_hw_dk_cam(_adapter *adapter)
  1283. {
  1284. int i;
  1285. for (i = 0; i < 4; i++)
  1286. rtw_sec_clr_cam_ent(adapter, i);
  1287. /*_clear_cam_entry(adapter, i);*/
  1288. }
  1289. void flush_all_cam_entry(_adapter *padapter)
  1290. {
  1291. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1292. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1293. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1294. struct security_priv *psecpriv = &padapter->securitypriv;
  1295. #ifdef CONFIG_CONCURRENT_MODE
  1296. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
  1297. struct sta_priv *pstapriv = &padapter->stapriv;
  1298. struct sta_info *psta;
  1299. psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
  1300. if (psta) {
  1301. if (psta->state & WIFI_AP_STATE) {
  1302. /*clear cam when ap free per sta_info*/
  1303. } else
  1304. rtw_clearstakey_cmd(padapter, psta, _FALSE);
  1305. }
  1306. } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
  1307. #if 1
  1308. int cam_id = -1;
  1309. u8 *addr = adapter_mac_addr(padapter);
  1310. while ((cam_id = rtw_camid_search(padapter, addr, -1, -1)) >= 0) {
  1311. RTW_PRINT("clear wep or group key for addr:"MAC_FMT", camid:%d\n", MAC_ARG(addr), cam_id);
  1312. clear_cam_entry(padapter, cam_id);
  1313. rtw_camid_free(padapter, cam_id);
  1314. }
  1315. #else
  1316. /* clear default key */
  1317. int i, cam_id;
  1318. u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
  1319. for (i = 0; i < 4; i++) {
  1320. cam_id = rtw_camid_search(padapter, null_addr, i, -1);
  1321. if (cam_id >= 0) {
  1322. clear_cam_entry(padapter, cam_id);
  1323. rtw_camid_free(padapter, cam_id);
  1324. }
  1325. }
  1326. /* clear default key related key search setting */
  1327. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8 *)_FALSE);
  1328. #endif
  1329. }
  1330. #else /*NON CONFIG_CONCURRENT_MODE*/
  1331. invalidate_cam_all(padapter);
  1332. /* clear default key related key search setting */
  1333. rtw_hal_set_hwreg(padapter, HW_VAR_SEC_DK_CFG, (u8 *)_FALSE);
  1334. #endif
  1335. }
  1336. #if defined(CONFIG_P2P) && defined(CONFIG_WFD)
  1337. void rtw_process_wfd_ie(_adapter *adapter, u8 *wfd_ie, u8 wfd_ielen, const char *tag)
  1338. {
  1339. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  1340. u8 *attr_content;
  1341. u32 attr_contentlen = 0;
  1342. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  1343. return;
  1344. RTW_INFO("[%s] Found WFD IE\n", tag);
  1345. attr_content = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &attr_contentlen);
  1346. if (attr_content && attr_contentlen) {
  1347. wdinfo->wfd_info->peer_rtsp_ctrlport = RTW_GET_BE16(attr_content + 2);
  1348. RTW_INFO("[%s] Peer PORT NUM = %d\n", tag, wdinfo->wfd_info->peer_rtsp_ctrlport);
  1349. }
  1350. }
  1351. void rtw_process_wfd_ies(_adapter *adapter, u8 *ies, u8 ies_len, const char *tag)
  1352. {
  1353. u8 *wfd_ie;
  1354. u32 wfd_ielen;
  1355. if (!hal_chk_wl_func(adapter, WL_FUNC_MIRACAST))
  1356. return;
  1357. wfd_ie = rtw_get_wfd_ie(ies, ies_len, NULL, &wfd_ielen);
  1358. while (wfd_ie) {
  1359. rtw_process_wfd_ie(adapter, wfd_ie, wfd_ielen, tag);
  1360. wfd_ie = rtw_get_wfd_ie(wfd_ie + wfd_ielen, (ies + ies_len) - (wfd_ie + wfd_ielen), NULL, &wfd_ielen);
  1361. }
  1362. }
  1363. #endif /* defined(CONFIG_P2P) && defined(CONFIG_WFD) */
  1364. int WMM_param_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1365. {
  1366. /* struct registry_priv *pregpriv = &padapter->registrypriv; */
  1367. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1368. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1369. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1370. if (pmlmepriv->qospriv.qos_option == 0) {
  1371. pmlmeinfo->WMM_enable = 0;
  1372. return _FALSE;
  1373. }
  1374. if (_rtw_memcmp(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element)))
  1375. return _FALSE;
  1376. else
  1377. _rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
  1378. pmlmeinfo->WMM_enable = 1;
  1379. return _TRUE;
  1380. #if 0
  1381. if (pregpriv->wifi_spec == 1) {
  1382. if (pmlmeinfo->WMM_enable == 1) {
  1383. /* todo: compare the parameter set count & decide wheher to update or not */
  1384. return _FAIL;
  1385. } else {
  1386. pmlmeinfo->WMM_enable = 1;
  1387. _rtw_rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
  1388. return _TRUE;
  1389. }
  1390. } else {
  1391. pmlmeinfo->WMM_enable = 0;
  1392. return _FAIL;
  1393. }
  1394. #endif
  1395. }
  1396. void WMMOnAssocRsp(_adapter *padapter)
  1397. {
  1398. u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
  1399. u8 acm_mask;
  1400. u16 TXOP;
  1401. u32 acParm, i;
  1402. u32 edca[4], inx[4];
  1403. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1404. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1405. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  1406. struct registry_priv *pregpriv = &padapter->registrypriv;
  1407. acm_mask = 0;
  1408. if (is_supported_5g(pmlmeext->cur_wireless_mode) ||
  1409. (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
  1410. aSifsTime = 16;
  1411. else
  1412. aSifsTime = 10;
  1413. if (pmlmeinfo->WMM_enable == 0) {
  1414. padapter->mlmepriv.acm_mask = 0;
  1415. AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
  1416. if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11A)) {
  1417. ECWMin = 4;
  1418. ECWMax = 10;
  1419. } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
  1420. ECWMin = 5;
  1421. ECWMax = 10;
  1422. } else {
  1423. ECWMin = 4;
  1424. ECWMax = 10;
  1425. }
  1426. TXOP = 0;
  1427. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1428. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  1429. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  1430. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  1431. ECWMin = 2;
  1432. ECWMax = 3;
  1433. TXOP = 0x2f;
  1434. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1435. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  1436. } else {
  1437. edca[0] = edca[1] = edca[2] = edca[3] = 0;
  1438. for (i = 0; i < 4; i++) {
  1439. ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
  1440. ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
  1441. /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
  1442. AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) * pmlmeinfo->slotTime + aSifsTime;
  1443. ECWMin = (pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f);
  1444. ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4;
  1445. TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit);
  1446. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  1447. switch (ACI) {
  1448. case 0x0:
  1449. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  1450. acm_mask |= (ACM ? BIT(1) : 0);
  1451. edca[XMIT_BE_QUEUE] = acParm;
  1452. break;
  1453. case 0x1:
  1454. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  1455. /* acm_mask |= (ACM? BIT(0):0); */
  1456. edca[XMIT_BK_QUEUE] = acParm;
  1457. break;
  1458. case 0x2:
  1459. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  1460. acm_mask |= (ACM ? BIT(2) : 0);
  1461. edca[XMIT_VI_QUEUE] = acParm;
  1462. break;
  1463. case 0x3:
  1464. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  1465. acm_mask |= (ACM ? BIT(3) : 0);
  1466. edca[XMIT_VO_QUEUE] = acParm;
  1467. break;
  1468. }
  1469. RTW_INFO("WMM(%x): %x, %x\n", ACI, ACM, acParm);
  1470. }
  1471. if (padapter->registrypriv.acm_method == 1)
  1472. rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
  1473. else
  1474. padapter->mlmepriv.acm_mask = acm_mask;
  1475. inx[0] = 0;
  1476. inx[1] = 1;
  1477. inx[2] = 2;
  1478. inx[3] = 3;
  1479. if (pregpriv->wifi_spec == 1) {
  1480. u32 j, tmp, change_inx = _FALSE;
  1481. /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
  1482. for (i = 0; i < 4; i++) {
  1483. for (j = i + 1; j < 4; j++) {
  1484. /* compare CW and AIFS */
  1485. if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
  1486. change_inx = _TRUE;
  1487. else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
  1488. /* compare TXOP */
  1489. if ((edca[j] >> 16) > (edca[i] >> 16))
  1490. change_inx = _TRUE;
  1491. }
  1492. if (change_inx) {
  1493. tmp = edca[i];
  1494. edca[i] = edca[j];
  1495. edca[j] = tmp;
  1496. tmp = inx[i];
  1497. inx[i] = inx[j];
  1498. inx[j] = tmp;
  1499. change_inx = _FALSE;
  1500. }
  1501. }
  1502. }
  1503. }
  1504. for (i = 0; i < 4; i++) {
  1505. pxmitpriv->wmm_para_seq[i] = inx[i];
  1506. RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
  1507. }
  1508. #ifdef CONFIG_WMMPS
  1509. if (pmlmeinfo->WMM_param.QoS_info & BIT(7))
  1510. rtw_hal_set_hwreg(padapter, HW_VAR_UAPSD_TID, NULL);
  1511. #endif
  1512. }
  1513. }
  1514. static void bwmode_update_check(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1515. {
  1516. #ifdef CONFIG_80211N_HT
  1517. unsigned char new_bwmode;
  1518. unsigned char new_ch_offset;
  1519. struct HT_info_element *pHT_info;
  1520. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1521. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1522. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1523. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1524. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  1525. u8 cbw40_enable = 0;
  1526. if (!pIE)
  1527. return;
  1528. if (phtpriv->ht_option == _FALSE)
  1529. return;
  1530. if (pmlmeext->cur_bwmode >= CHANNEL_WIDTH_80)
  1531. return;
  1532. if (pIE->Length > sizeof(struct HT_info_element))
  1533. return;
  1534. pHT_info = (struct HT_info_element *)pIE->data;
  1535. if (hal_chk_bw_cap(padapter, BW_CAP_40M)) {
  1536. if (pmlmeext->cur_channel > 14) {
  1537. if (REGSTY_IS_BW_5G_SUPPORT(pregistrypriv, CHANNEL_WIDTH_40))
  1538. cbw40_enable = 1;
  1539. } else {
  1540. if (REGSTY_IS_BW_2G_SUPPORT(pregistrypriv, CHANNEL_WIDTH_40))
  1541. cbw40_enable = 1;
  1542. }
  1543. }
  1544. if ((pHT_info->infos[0] & BIT(2)) && cbw40_enable) {
  1545. new_bwmode = CHANNEL_WIDTH_40;
  1546. switch (pHT_info->infos[0] & 0x3) {
  1547. case 1:
  1548. new_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  1549. break;
  1550. case 3:
  1551. new_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  1552. break;
  1553. default:
  1554. new_bwmode = CHANNEL_WIDTH_20;
  1555. new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1556. break;
  1557. }
  1558. } else {
  1559. new_bwmode = CHANNEL_WIDTH_20;
  1560. new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1561. }
  1562. if ((new_bwmode != pmlmeext->cur_bwmode || new_ch_offset != pmlmeext->cur_ch_offset)
  1563. && new_bwmode < pmlmeext->cur_bwmode
  1564. ) {
  1565. pmlmeinfo->bwmode_updated = _TRUE;
  1566. pmlmeext->cur_bwmode = new_bwmode;
  1567. pmlmeext->cur_ch_offset = new_ch_offset;
  1568. /* update HT info also */
  1569. HT_info_handler(padapter, pIE);
  1570. } else
  1571. pmlmeinfo->bwmode_updated = _FALSE;
  1572. if (_TRUE == pmlmeinfo->bwmode_updated) {
  1573. struct sta_info *psta;
  1574. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  1575. struct sta_priv *pstapriv = &padapter->stapriv;
  1576. /* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
  1577. /* update ap's stainfo */
  1578. psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
  1579. if (psta) {
  1580. struct ht_priv *phtpriv_sta = &psta->htpriv;
  1581. if (phtpriv_sta->ht_option) {
  1582. /* bwmode */
  1583. psta->bw_mode = pmlmeext->cur_bwmode;
  1584. phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
  1585. } else {
  1586. psta->bw_mode = CHANNEL_WIDTH_20;
  1587. phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1588. }
  1589. rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta);
  1590. }
  1591. /* pmlmeinfo->bwmode_updated = _FALSE; */ /* bwmode_updated done, reset it! */
  1592. }
  1593. #endif /* CONFIG_80211N_HT */
  1594. }
  1595. void HT_caps_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1596. {
  1597. #ifdef CONFIG_80211N_HT
  1598. unsigned int i;
  1599. u8 rf_type = RF_1T1R;
  1600. u8 max_AMPDU_len, min_MPDU_spacing;
  1601. u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0, tx_nss = 0;
  1602. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1603. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1604. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1605. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  1606. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  1607. struct hal_spec_t *hal_spec = GET_HAL_SPEC(padapter);
  1608. if (pIE == NULL)
  1609. return;
  1610. if (phtpriv->ht_option == _FALSE)
  1611. return;
  1612. pmlmeinfo->HT_caps_enable = 1;
  1613. for (i = 0; i < (pIE->Length); i++) {
  1614. if (i != 2) {
  1615. /* Commented by Albert 2010/07/12 */
  1616. /* Got the endian issue here. */
  1617. pmlmeinfo->HT_caps.u.HT_cap[i] &= (pIE->data[i]);
  1618. } else {
  1619. /* AMPDU Parameters field */
  1620. /* Get MIN of MAX AMPDU Length Exp */
  1621. if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3) > (pIE->data[i] & 0x3))
  1622. max_AMPDU_len = (pIE->data[i] & 0x3);
  1623. else
  1624. max_AMPDU_len = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3);
  1625. /* Get MAX of MIN MPDU Start Spacing */
  1626. if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) > (pIE->data[i] & 0x1c))
  1627. min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c);
  1628. else
  1629. min_MPDU_spacing = (pIE->data[i] & 0x1c);
  1630. pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para = max_AMPDU_len | min_MPDU_spacing;
  1631. }
  1632. }
  1633. /* Commented by Albert 2010/07/12 */
  1634. /* Have to handle the endian issue after copying. */
  1635. /* HT_ext_caps didn't be used yet. */
  1636. pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info = le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info);
  1637. pmlmeinfo->HT_caps.u.HT_cap_element.HT_ext_caps = le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_ext_caps);
  1638. /* update the MCS set */
  1639. for (i = 0; i < 16; i++)
  1640. pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= pmlmeext->default_supported_mcs_set[i];
  1641. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  1642. tx_nss = rtw_min(rf_type_to_rf_tx_cnt(rf_type), hal_spec->tx_nss_num);
  1643. switch (tx_nss) {
  1644. case 1:
  1645. set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_1R);
  1646. break;
  1647. case 2:
  1648. #ifdef CONFIG_DISABLE_MCS13TO15
  1649. if (pmlmeext->cur_bwmode == CHANNEL_WIDTH_40 && pregistrypriv->wifi_spec != 1)
  1650. set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_2R_13TO15_OFF);
  1651. else
  1652. #endif
  1653. set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_2R);
  1654. break;
  1655. case 3:
  1656. set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_3R);
  1657. break;
  1658. case 4:
  1659. set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_4R);
  1660. break;
  1661. default:
  1662. RTW_WARN("rf_type:%d or tx_nss:%u is not expected\n", rf_type, hal_spec->tx_nss_num);
  1663. }
  1664. if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  1665. /* Config STBC setting */
  1666. if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && GET_HT_CAP_ELE_RX_STBC(pIE->data)) {
  1667. SET_FLAG(cur_stbc_cap, STBC_HT_ENABLE_TX);
  1668. RTW_INFO("Enable HT Tx STBC !\n");
  1669. }
  1670. phtpriv->stbc_cap = cur_stbc_cap;
  1671. #ifdef CONFIG_BEAMFORMING
  1672. /* Config Tx beamforming setting */
  1673. if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
  1674. GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pIE->data)) {
  1675. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
  1676. /* Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
  1677. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pIE->data) << 6);
  1678. }
  1679. if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
  1680. GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pIE->data)) {
  1681. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
  1682. /* Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
  1683. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pIE->data) << 4);
  1684. }
  1685. phtpriv->beamform_cap = cur_beamform_cap;
  1686. if (cur_beamform_cap)
  1687. RTW_INFO("AP HT Beamforming Cap = 0x%02X\n", cur_beamform_cap);
  1688. #endif /*CONFIG_BEAMFORMING*/
  1689. } else {
  1690. /*WIFI_STATION_STATEorI_ADHOC_STATE or WIFI_ADHOC_MASTER_STATE*/
  1691. /* Config LDPC Coding Capability */
  1692. if (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_TX) && GET_HT_CAP_ELE_LDPC_CAP(pIE->data)) {
  1693. SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
  1694. RTW_INFO("Enable HT Tx LDPC!\n");
  1695. }
  1696. phtpriv->ldpc_cap = cur_ldpc_cap;
  1697. /* Config STBC setting */
  1698. if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && GET_HT_CAP_ELE_RX_STBC(pIE->data)) {
  1699. SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
  1700. RTW_INFO("Enable HT Tx STBC!\n");
  1701. }
  1702. phtpriv->stbc_cap = cur_stbc_cap;
  1703. #ifdef CONFIG_BEAMFORMING
  1704. #ifdef RTW_BEAMFORMING_VERSION_2
  1705. /* Config beamforming setting */
  1706. if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
  1707. GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pIE->data)) {
  1708. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
  1709. /* Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
  1710. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pIE->data) << 6);
  1711. }
  1712. if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
  1713. GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pIE->data)) {
  1714. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
  1715. /* Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
  1716. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pIE->data) << 4);
  1717. }
  1718. #else /* !RTW_BEAMFORMING_VERSION_2 */
  1719. /* Config Tx beamforming setting */
  1720. if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
  1721. GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pIE->data)) {
  1722. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
  1723. /* Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
  1724. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pIE->data) << 6);
  1725. }
  1726. if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
  1727. GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pIE->data)) {
  1728. SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
  1729. /* Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
  1730. SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pIE->data) << 4);
  1731. }
  1732. #endif /* !RTW_BEAMFORMING_VERSION_2 */
  1733. phtpriv->beamform_cap = cur_beamform_cap;
  1734. if (cur_beamform_cap)
  1735. RTW_INFO("Client HT Beamforming Cap = 0x%02X\n", cur_beamform_cap);
  1736. #endif /*CONFIG_BEAMFORMING*/
  1737. }
  1738. #endif /* CONFIG_80211N_HT */
  1739. }
  1740. void HT_info_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1741. {
  1742. #ifdef CONFIG_80211N_HT
  1743. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1744. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1745. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1746. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  1747. if (pIE == NULL)
  1748. return;
  1749. if (phtpriv->ht_option == _FALSE)
  1750. return;
  1751. if (pIE->Length > sizeof(struct HT_info_element))
  1752. return;
  1753. pmlmeinfo->HT_info_enable = 1;
  1754. _rtw_memcpy(&(pmlmeinfo->HT_info), pIE->data, pIE->Length);
  1755. #endif /* CONFIG_80211N_HT */
  1756. return;
  1757. }
  1758. void HTOnAssocRsp(_adapter *padapter)
  1759. {
  1760. unsigned char max_AMPDU_len;
  1761. unsigned char min_MPDU_spacing;
  1762. /* struct registry_priv *pregpriv = &padapter->registrypriv; */
  1763. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1764. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1765. RTW_INFO("%s\n", __FUNCTION__);
  1766. if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
  1767. pmlmeinfo->HT_enable = 1;
  1768. else {
  1769. pmlmeinfo->HT_enable = 0;
  1770. /* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
  1771. return;
  1772. }
  1773. /* handle A-MPDU parameter field */
  1774. /*
  1775. AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
  1776. AMPDU_para [4:2]:Min MPDU Start Spacing
  1777. */
  1778. max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
  1779. min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
  1780. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
  1781. rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
  1782. #if 0 /* move to rtw_update_ht_cap() */
  1783. if ((pregpriv->bw_mode > 0) &&
  1784. (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & BIT(1)) &&
  1785. (pmlmeinfo->HT_info.infos[0] & BIT(2))) {
  1786. /* switch to the 40M Hz mode accoring to the AP */
  1787. pmlmeext->cur_bwmode = CHANNEL_WIDTH_40;
  1788. switch ((pmlmeinfo->HT_info.infos[0] & 0x3)) {
  1789. case EXTCHNL_OFFSET_UPPER:
  1790. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  1791. break;
  1792. case EXTCHNL_OFFSET_LOWER:
  1793. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  1794. break;
  1795. default:
  1796. pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1797. break;
  1798. }
  1799. }
  1800. #endif
  1801. /* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
  1802. #if 0 /* move to rtw_update_ht_cap() */
  1803. /* */
  1804. /* Config SM Power Save setting */
  1805. /* */
  1806. pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
  1807. if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC) {
  1808. #if 0
  1809. u8 i;
  1810. /* update the MCS rates */
  1811. for (i = 0; i < 16; i++)
  1812. pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
  1813. #endif
  1814. RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __FUNCTION__);
  1815. }
  1816. /* */
  1817. /* Config current HT Protection mode. */
  1818. /* */
  1819. pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3;
  1820. #endif
  1821. }
  1822. void ERP_IE_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
  1823. {
  1824. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1825. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1826. if (pIE->Length > 1)
  1827. return;
  1828. pmlmeinfo->ERP_enable = 1;
  1829. _rtw_memcpy(&(pmlmeinfo->ERP_IE), pIE->data, pIE->Length);
  1830. }
  1831. void VCS_update(_adapter *padapter, struct sta_info *psta)
  1832. {
  1833. struct registry_priv *pregpriv = &padapter->registrypriv;
  1834. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1835. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1836. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1837. switch (pregpriv->vrtl_carrier_sense) { /* 0:off 1:on 2:auto */
  1838. case 0: /* off */
  1839. psta->rtsen = 0;
  1840. psta->cts2self = 0;
  1841. break;
  1842. case 1: /* on */
  1843. if (pregpriv->vcs_type == 1) { /* 1:RTS/CTS 2:CTS to self */
  1844. psta->rtsen = 1;
  1845. psta->cts2self = 0;
  1846. } else {
  1847. psta->rtsen = 0;
  1848. psta->cts2self = 1;
  1849. }
  1850. break;
  1851. case 2: /* auto */
  1852. default:
  1853. if (((pmlmeinfo->ERP_enable) && (pmlmeinfo->ERP_IE & BIT(1)))
  1854. /*||(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/
  1855. ) {
  1856. if (pregpriv->vcs_type == 1) {
  1857. psta->rtsen = 1;
  1858. psta->cts2self = 0;
  1859. } else {
  1860. psta->rtsen = 0;
  1861. psta->cts2self = 1;
  1862. }
  1863. } else {
  1864. psta->rtsen = 0;
  1865. psta->cts2self = 0;
  1866. }
  1867. break;
  1868. }
  1869. }
  1870. void update_ldpc_stbc_cap(struct sta_info *psta)
  1871. {
  1872. #ifdef CONFIG_80211N_HT
  1873. #ifdef CONFIG_80211AC_VHT
  1874. if (psta->vhtpriv.vht_option) {
  1875. if (TEST_FLAG(psta->vhtpriv.ldpc_cap, LDPC_VHT_ENABLE_TX))
  1876. psta->ldpc = 1;
  1877. if (TEST_FLAG(psta->vhtpriv.stbc_cap, STBC_VHT_ENABLE_TX))
  1878. psta->stbc = 1;
  1879. } else
  1880. #endif /* CONFIG_80211AC_VHT */
  1881. if (psta->htpriv.ht_option) {
  1882. if (TEST_FLAG(psta->htpriv.ldpc_cap, LDPC_HT_ENABLE_TX))
  1883. psta->ldpc = 1;
  1884. if (TEST_FLAG(psta->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
  1885. psta->stbc = 1;
  1886. } else {
  1887. psta->ldpc = 0;
  1888. psta->stbc = 0;
  1889. }
  1890. #endif /* CONFIG_80211N_HT */
  1891. }
  1892. int check_ielen(u8 *start, uint len)
  1893. {
  1894. int left = len;
  1895. u8 *pos = start;
  1896. int unknown = 0;
  1897. u8 id, elen;
  1898. while (left >= 2) {
  1899. id = *pos++;
  1900. elen = *pos++;
  1901. left -= 2;
  1902. if (elen > left) {
  1903. RTW_INFO("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n",
  1904. id, elen, (unsigned long) left);
  1905. return _FALSE;
  1906. }
  1907. if ((id == WLAN_EID_VENDOR_SPECIFIC) && (elen < 4))
  1908. return _FALSE;
  1909. left -= elen;
  1910. pos += elen;
  1911. }
  1912. if (left)
  1913. return _FALSE;
  1914. return _TRUE;
  1915. }
  1916. int validate_beacon_len(u8 *pframe, u32 len)
  1917. {
  1918. u8 ie_offset = _BEACON_IE_OFFSET_ + sizeof(struct rtw_ieee80211_hdr_3addr);
  1919. if (len < ie_offset) {
  1920. RTW_INFO("%s: incorrect beacon length(%d)\n", __func__, len);
  1921. return _FALSE;
  1922. }
  1923. if (check_ielen(pframe + ie_offset, len - ie_offset) == _FALSE)
  1924. return _FALSE;
  1925. return _TRUE;
  1926. }
  1927. /*
  1928. * rtw_get_bcn_keys: get beacon keys from recv frame
  1929. *
  1930. * TODO:
  1931. * WLAN_EID_COUNTRY
  1932. * WLAN_EID_ERP_INFO
  1933. * WLAN_EID_CHANNEL_SWITCH
  1934. * WLAN_EID_PWR_CONSTRAINT
  1935. */
  1936. int rtw_get_bcn_keys(ADAPTER *Adapter, u8 *pframe, u32 packet_len,
  1937. struct beacon_keys *recv_beacon)
  1938. {
  1939. int left;
  1940. u16 capability;
  1941. unsigned char *pos;
  1942. struct rtw_ieee802_11_elems elems;
  1943. struct rtw_ieee80211_ht_cap *pht_cap = NULL;
  1944. struct HT_info_element *pht_info = NULL;
  1945. _rtw_memset(recv_beacon, 0, sizeof(*recv_beacon));
  1946. /* checking capabilities */
  1947. capability = le16_to_cpu(*(unsigned short *)(pframe + WLAN_HDR_A3_LEN + 10));
  1948. /* checking IEs */
  1949. left = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr) - _BEACON_IE_OFFSET_;
  1950. pos = pframe + sizeof(struct rtw_ieee80211_hdr_3addr) + _BEACON_IE_OFFSET_;
  1951. if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed)
  1952. return _FALSE;
  1953. /* check bw and channel offset */
  1954. if (elems.ht_capabilities) {
  1955. if (elems.ht_capabilities_len != sizeof(*pht_cap))
  1956. return _FALSE;
  1957. pht_cap = (struct rtw_ieee80211_ht_cap *) elems.ht_capabilities;
  1958. recv_beacon->ht_cap_info = pht_cap->cap_info;
  1959. }
  1960. if (elems.ht_operation) {
  1961. if (elems.ht_operation_len != sizeof(*pht_info))
  1962. return _FALSE;
  1963. pht_info = (struct HT_info_element *) elems.ht_operation;
  1964. recv_beacon->ht_info_infos_0_sco = pht_info->infos[0] & 0x03;
  1965. }
  1966. /* Checking for channel */
  1967. if (elems.ds_params && elems.ds_params_len == sizeof(recv_beacon->bcn_channel))
  1968. _rtw_memcpy(&recv_beacon->bcn_channel, elems.ds_params,
  1969. sizeof(recv_beacon->bcn_channel));
  1970. else if (pht_info)
  1971. /* In 5G, some ap do not have DSSET IE checking HT info for channel */
  1972. recv_beacon->bcn_channel = pht_info->primary_channel;
  1973. else {
  1974. /* we don't find channel IE, so don't check it */
  1975. /* RTW_INFO("Oops: %s we don't find channel IE, so don't check it\n", __func__); */
  1976. recv_beacon->bcn_channel = Adapter->mlmeextpriv.cur_channel;
  1977. }
  1978. /* checking SSID */
  1979. if (elems.ssid) {
  1980. if (elems.ssid_len > sizeof(recv_beacon->ssid))
  1981. return _FALSE;
  1982. _rtw_memcpy(recv_beacon->ssid, elems.ssid, elems.ssid_len);
  1983. recv_beacon->ssid_len = elems.ssid_len;
  1984. } else
  1985. ; /* means hidden ssid */
  1986. /* checking RSN first */
  1987. if (elems.rsn_ie && elems.rsn_ie_len) {
  1988. recv_beacon->encryp_protocol = ENCRYP_PROTOCOL_WPA2;
  1989. rtw_parse_wpa2_ie(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
  1990. &recv_beacon->group_cipher, &recv_beacon->pairwise_cipher,
  1991. &recv_beacon->is_8021x);
  1992. }
  1993. /* checking WPA secon */
  1994. else if (elems.wpa_ie && elems.wpa_ie_len) {
  1995. recv_beacon->encryp_protocol = ENCRYP_PROTOCOL_WPA;
  1996. rtw_parse_wpa_ie(elems.wpa_ie - 2, elems.wpa_ie_len + 2,
  1997. &recv_beacon->group_cipher, &recv_beacon->pairwise_cipher,
  1998. &recv_beacon->is_8021x);
  1999. } else if (capability & BIT(4))
  2000. recv_beacon->encryp_protocol = ENCRYP_PROTOCOL_WEP;
  2001. return _TRUE;
  2002. }
  2003. void rtw_dump_bcn_keys(struct beacon_keys *recv_beacon)
  2004. {
  2005. int i;
  2006. char *p;
  2007. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  2008. _rtw_memcpy(ssid, recv_beacon->ssid, recv_beacon->ssid_len);
  2009. ssid[recv_beacon->ssid_len] = '\0';
  2010. RTW_INFO("%s: ssid = %s\n", __func__, ssid);
  2011. RTW_INFO("%s: channel = %x\n", __func__, recv_beacon->bcn_channel);
  2012. RTW_INFO("%s: ht_cap = %x\n", __func__, recv_beacon->ht_cap_info);
  2013. RTW_INFO("%s: ht_info_infos_0_sco = %x\n", __func__, recv_beacon->ht_info_infos_0_sco);
  2014. RTW_INFO("%s: sec=%d, group = %x, pair = %x, 8021X = %x\n", __func__,
  2015. recv_beacon->encryp_protocol, recv_beacon->group_cipher,
  2016. recv_beacon->pairwise_cipher, recv_beacon->is_8021x);
  2017. }
  2018. int rtw_check_bcn_info(ADAPTER *Adapter, u8 *pframe, u32 packet_len)
  2019. {
  2020. #if 0
  2021. unsigned int len;
  2022. unsigned char *p;
  2023. unsigned short val16, subtype;
  2024. struct wlan_network *cur_network = &(Adapter->mlmepriv.cur_network);
  2025. /* u8 wpa_ie[255],rsn_ie[255]; */
  2026. u16 wpa_len = 0, rsn_len = 0;
  2027. u8 encryp_protocol = 0;
  2028. WLAN_BSSID_EX *bssid;
  2029. int group_cipher = 0, pairwise_cipher = 0, is_8021x = 0;
  2030. unsigned char *pbuf;
  2031. u32 wpa_ielen = 0;
  2032. u8 *pbssid = GetAddr3Ptr(pframe);
  2033. u32 hidden_ssid = 0;
  2034. u8 cur_network_type, network_type = 0;
  2035. struct HT_info_element *pht_info = NULL;
  2036. struct rtw_ieee80211_ht_cap *pht_cap = NULL;
  2037. u32 bcn_channel;
  2038. unsigned short ht_cap_info;
  2039. unsigned char ht_info_infos_0;
  2040. #endif
  2041. unsigned int len;
  2042. u8 *pbssid = GetAddr3Ptr(pframe);
  2043. struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
  2044. struct wlan_network *cur_network = &(Adapter->mlmepriv.cur_network);
  2045. struct beacon_keys recv_beacon;
  2046. if (is_client_associated_to_ap(Adapter) == _FALSE)
  2047. return _TRUE;
  2048. len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
  2049. if (len > MAX_IE_SZ) {
  2050. RTW_WARN("%s IE too long for survey event\n", __func__);
  2051. return _FAIL;
  2052. }
  2053. if (_rtw_memcmp(cur_network->network.MacAddress, pbssid, 6) == _FALSE) {
  2054. RTW_WARN("Oops: rtw_check_network_encrypt linked but recv other bssid bcn\n" MAC_FMT MAC_FMT,
  2055. MAC_ARG(pbssid), MAC_ARG(cur_network->network.MacAddress));
  2056. return _TRUE;
  2057. }
  2058. if (rtw_get_bcn_keys(Adapter, pframe, packet_len, &recv_beacon) == _FALSE)
  2059. return _TRUE; /* parsing failed => broken IE */
  2060. /* don't care hidden ssid, use current beacon ssid directly */
  2061. if (recv_beacon.ssid_len == 0) {
  2062. _rtw_memcpy(recv_beacon.ssid, pmlmepriv->cur_beacon_keys.ssid,
  2063. pmlmepriv->cur_beacon_keys.ssid_len);
  2064. recv_beacon.ssid_len = pmlmepriv->cur_beacon_keys.ssid_len;
  2065. }
  2066. if (_rtw_memcmp(&recv_beacon, &pmlmepriv->cur_beacon_keys, sizeof(recv_beacon)) == _TRUE)
  2067. pmlmepriv->new_beacon_cnts = 0;
  2068. else if ((pmlmepriv->new_beacon_cnts == 0) ||
  2069. _rtw_memcmp(&recv_beacon, &pmlmepriv->new_beacon_keys, sizeof(recv_beacon)) == _FALSE) {
  2070. RTW_DBG("%s: start new beacon (seq=%d)\n", __func__, GetSequence(pframe));
  2071. if (pmlmepriv->new_beacon_cnts == 0) {
  2072. RTW_ERR("%s: cur beacon key\n", __func__);
  2073. RTW_DBG_EXPR(rtw_dump_bcn_keys(&pmlmepriv->cur_beacon_keys));
  2074. }
  2075. RTW_DBG("%s: new beacon key\n", __func__);
  2076. RTW_DBG_EXPR(rtw_dump_bcn_keys(&recv_beacon));
  2077. memcpy(&pmlmepriv->new_beacon_keys, &recv_beacon, sizeof(recv_beacon));
  2078. pmlmepriv->new_beacon_cnts = 1;
  2079. } else {
  2080. RTW_DBG("%s: new beacon again (seq=%d)\n", __func__, GetSequence(pframe));
  2081. pmlmepriv->new_beacon_cnts++;
  2082. }
  2083. /* if counter >= max, it means beacon is changed really */
  2084. if (pmlmepriv->new_beacon_cnts >= new_bcn_max) {
  2085. /* check bw mode change only? */
  2086. pmlmepriv->cur_beacon_keys.ht_cap_info = recv_beacon.ht_cap_info;
  2087. pmlmepriv->cur_beacon_keys.ht_info_infos_0_sco = recv_beacon.ht_info_infos_0_sco;
  2088. if (_rtw_memcmp(&recv_beacon, &pmlmepriv->cur_beacon_keys,
  2089. sizeof(recv_beacon)) == _FALSE) {
  2090. /* beacon is changed, have to do disconnect/connect */
  2091. RTW_WARN("%s: new beacon occur!!\n", __func__);
  2092. return _FAIL;
  2093. }
  2094. RTW_INFO("%s bw mode change\n", __func__);
  2095. RTW_INFO("%s bcn now: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
  2096. cur_network->BcnInfo.ht_cap_info,
  2097. cur_network->BcnInfo.ht_info_infos_0);
  2098. cur_network->BcnInfo.ht_cap_info = recv_beacon.ht_cap_info;
  2099. cur_network->BcnInfo.ht_info_infos_0 =
  2100. (cur_network->BcnInfo.ht_info_infos_0 & (~0x03)) |
  2101. recv_beacon.ht_info_infos_0_sco;
  2102. RTW_INFO("%s bcn link: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
  2103. cur_network->BcnInfo.ht_cap_info,
  2104. cur_network->BcnInfo.ht_info_infos_0);
  2105. memcpy(&pmlmepriv->cur_beacon_keys, &recv_beacon, sizeof(recv_beacon));
  2106. pmlmepriv->new_beacon_cnts = 0;
  2107. }
  2108. return _SUCCESS;
  2109. #if 0
  2110. bssid = (WLAN_BSSID_EX *)rtw_zmalloc(sizeof(WLAN_BSSID_EX));
  2111. if (bssid == NULL) {
  2112. RTW_INFO("%s rtw_zmalloc fail !!!\n", __func__);
  2113. return _TRUE;
  2114. }
  2115. if ((pmlmepriv->timeBcnInfoChkStart != 0) && (rtw_get_passing_time_ms(pmlmepriv->timeBcnInfoChkStart) > DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS)) {
  2116. pmlmepriv->timeBcnInfoChkStart = 0;
  2117. pmlmepriv->NumOfBcnInfoChkFail = 0;
  2118. }
  2119. subtype = get_frame_sub_type(pframe) >> 4;
  2120. if (subtype == WIFI_BEACON)
  2121. bssid->Reserved[0] = 1;
  2122. bssid->Length = sizeof(WLAN_BSSID_EX) - MAX_IE_SZ + len;
  2123. /* below is to copy the information element */
  2124. bssid->IELength = len;
  2125. _rtw_memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
  2126. /* check bw and channel offset */
  2127. /* parsing HT_CAP_IE */
  2128. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  2129. if (p && len > 0) {
  2130. pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
  2131. ht_cap_info = pht_cap->cap_info;
  2132. } else
  2133. ht_cap_info = 0;
  2134. /* parsing HT_INFO_IE */
  2135. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  2136. if (p && len > 0) {
  2137. pht_info = (struct HT_info_element *)(p + 2);
  2138. ht_info_infos_0 = pht_info->infos[0];
  2139. } else
  2140. ht_info_infos_0 = 0;
  2141. if (ht_cap_info != cur_network->BcnInfo.ht_cap_info ||
  2142. ((ht_info_infos_0 & 0x03) != (cur_network->BcnInfo.ht_info_infos_0 & 0x03))) {
  2143. RTW_INFO("%s bcn now: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
  2144. ht_cap_info, ht_info_infos_0);
  2145. RTW_INFO("%s bcn link: ht_cap_info:%x ht_info_infos_0:%x\n", __func__,
  2146. cur_network->BcnInfo.ht_cap_info, cur_network->BcnInfo.ht_info_infos_0);
  2147. RTW_INFO("%s bw mode change\n", __func__);
  2148. {
  2149. /* bcn_info_update */
  2150. cur_network->BcnInfo.ht_cap_info = ht_cap_info;
  2151. cur_network->BcnInfo.ht_info_infos_0 = ht_info_infos_0;
  2152. /* to do : need to check that whether modify related register of BB or not */
  2153. }
  2154. /* goto _mismatch; */
  2155. }
  2156. /* Checking for channel */
  2157. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _DSSET_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  2158. if (p)
  2159. bcn_channel = *(p + 2);
  2160. else {/* In 5G, some ap do not have DSSET IE checking HT info for channel */
  2161. rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  2162. if (pht_info)
  2163. bcn_channel = pht_info->primary_channel;
  2164. else { /* we don't find channel IE, so don't check it */
  2165. /* RTW_INFO("Oops: %s we don't find channel IE, so don't check it\n", __func__); */
  2166. bcn_channel = Adapter->mlmeextpriv.cur_channel;
  2167. }
  2168. }
  2169. if (bcn_channel != Adapter->mlmeextpriv.cur_channel) {
  2170. RTW_INFO("%s beacon channel:%d cur channel:%d disconnect\n", __func__,
  2171. bcn_channel, Adapter->mlmeextpriv.cur_channel);
  2172. goto _mismatch;
  2173. }
  2174. /* checking SSID */
  2175. p = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _SSID_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
  2176. if (p == NULL) {
  2177. RTW_INFO("%s marc: cannot find SSID for survey event\n", __func__);
  2178. hidden_ssid = _TRUE;
  2179. } else
  2180. hidden_ssid = _FALSE;
  2181. if ((NULL != p) && (_FALSE == hidden_ssid && (*(p + 1)))) {
  2182. _rtw_memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1));
  2183. bssid->Ssid.SsidLength = *(p + 1);
  2184. } else {
  2185. bssid->Ssid.SsidLength = 0;
  2186. bssid->Ssid.Ssid[0] = '\0';
  2187. }
  2188. if (_rtw_memcmp(bssid->Ssid.Ssid, cur_network->network.Ssid.Ssid, 32) == _FALSE ||
  2189. bssid->Ssid.SsidLength != cur_network->network.Ssid.SsidLength) {
  2190. if (bssid->Ssid.Ssid[0] != '\0' && bssid->Ssid.SsidLength != 0) { /* not hidden ssid */
  2191. RTW_INFO("%s(), SSID is not match\n", __func__);
  2192. goto _mismatch;
  2193. }
  2194. }
  2195. /* check encryption info */
  2196. val16 = rtw_get_capability((WLAN_BSSID_EX *)bssid);
  2197. if (val16 & BIT(4))
  2198. bssid->Privacy = 1;
  2199. else
  2200. bssid->Privacy = 0;
  2201. if (cur_network->network.Privacy != bssid->Privacy) {
  2202. RTW_INFO("%s(), privacy is not match\n", __func__);
  2203. goto _mismatch;
  2204. }
  2205. rtw_get_sec_ie(bssid->IEs, bssid->IELength, NULL, &rsn_len, NULL, &wpa_len);
  2206. if (rsn_len > 0)
  2207. encryp_protocol = ENCRYP_PROTOCOL_WPA2;
  2208. else if (wpa_len > 0)
  2209. encryp_protocol = ENCRYP_PROTOCOL_WPA;
  2210. else {
  2211. if (bssid->Privacy)
  2212. encryp_protocol = ENCRYP_PROTOCOL_WEP;
  2213. }
  2214. if (cur_network->BcnInfo.encryp_protocol != encryp_protocol) {
  2215. RTW_INFO("%s(): enctyp is not match\n", __func__);
  2216. goto _mismatch;
  2217. }
  2218. if (encryp_protocol == ENCRYP_PROTOCOL_WPA || encryp_protocol == ENCRYP_PROTOCOL_WPA2) {
  2219. pbuf = rtw_get_wpa_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength - 12);
  2220. if (pbuf && (wpa_ielen > 0)) {
  2221. rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is_8021x);
  2222. } else {
  2223. pbuf = rtw_get_wpa2_ie(&bssid->IEs[12], &wpa_ielen, bssid->IELength - 12);
  2224. if (pbuf && (wpa_ielen > 0)) {
  2225. rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is_8021x);
  2226. }
  2227. }
  2228. if (pairwise_cipher != cur_network->BcnInfo.pairwise_cipher || group_cipher != cur_network->BcnInfo.group_cipher) {
  2229. RTW_INFO("%s pairwise_cipher(%x:%x) or group_cipher(%x:%x) is not match\n", __func__,
  2230. pairwise_cipher, cur_network->BcnInfo.pairwise_cipher,
  2231. group_cipher, cur_network->BcnInfo.group_cipher);
  2232. goto _mismatch;
  2233. }
  2234. if (is_8021x != cur_network->BcnInfo.is_8021x) {
  2235. RTW_INFO("%s authentication is not match\n", __func__);
  2236. goto _mismatch;
  2237. }
  2238. }
  2239. rtw_mfree((u8 *)bssid, sizeof(WLAN_BSSID_EX));
  2240. return _SUCCESS;
  2241. _mismatch:
  2242. rtw_mfree((u8 *)bssid, sizeof(WLAN_BSSID_EX));
  2243. if (pmlmepriv->NumOfBcnInfoChkFail == 0)
  2244. pmlmepriv->timeBcnInfoChkStart = rtw_get_current_time();
  2245. pmlmepriv->NumOfBcnInfoChkFail++;
  2246. RTW_INFO("%s by "ADPT_FMT" - NumOfChkFail = %d (SeqNum of this Beacon frame = %d).\n", __func__, ADPT_ARG(Adapter), pmlmepriv->NumOfBcnInfoChkFail, GetSequence(pframe));
  2247. if ((pmlmepriv->timeBcnInfoChkStart != 0) && (rtw_get_passing_time_ms(pmlmepriv->timeBcnInfoChkStart) <= DISCONNECT_BY_CHK_BCN_FAIL_OBSERV_PERIOD_IN_MS)
  2248. && (pmlmepriv->NumOfBcnInfoChkFail >= DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD)) {
  2249. RTW_INFO("%s by "ADPT_FMT" - NumOfChkFail = %d >= threshold : %d (in %d ms), return FAIL.\n", __func__, ADPT_ARG(Adapter), pmlmepriv->NumOfBcnInfoChkFail,
  2250. DISCONNECT_BY_CHK_BCN_FAIL_THRESHOLD, rtw_get_passing_time_ms(pmlmepriv->timeBcnInfoChkStart));
  2251. pmlmepriv->timeBcnInfoChkStart = 0;
  2252. pmlmepriv->NumOfBcnInfoChkFail = 0;
  2253. return _FAIL;
  2254. }
  2255. return _SUCCESS;
  2256. #endif
  2257. }
  2258. void update_beacon_info(_adapter *padapter, u8 *pframe, uint pkt_len, struct sta_info *psta)
  2259. {
  2260. unsigned int i;
  2261. unsigned int len;
  2262. PNDIS_802_11_VARIABLE_IEs pIE;
  2263. #ifdef CONFIG_TDLS
  2264. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  2265. u8 tdls_prohibited[] = { 0x00, 0x00, 0x00, 0x00, 0x10 }; /* bit(38): TDLS_prohibited */
  2266. #endif /* CONFIG_TDLS */
  2267. len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN);
  2268. for (i = 0; i < len;) {
  2269. pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i);
  2270. switch (pIE->ElementID) {
  2271. case _VENDOR_SPECIFIC_IE_:
  2272. /* to update WMM paramter set while receiving beacon */
  2273. if (_rtw_memcmp(pIE->data, WMM_PARA_OUI, 6) && pIE->Length == WLAN_WMM_LEN) /* WMM */
  2274. (WMM_param_handler(padapter, pIE)) ? report_wmm_edca_update(padapter) : 0;
  2275. break;
  2276. case _HT_EXTRA_INFO_IE_: /* HT info */
  2277. /* HT_info_handler(padapter, pIE); */
  2278. bwmode_update_check(padapter, pIE);
  2279. break;
  2280. #ifdef CONFIG_80211AC_VHT
  2281. case EID_OpModeNotification:
  2282. rtw_process_vht_op_mode_notify(padapter, pIE->data, psta);
  2283. break;
  2284. #endif /* CONFIG_80211AC_VHT */
  2285. case _ERPINFO_IE_:
  2286. ERP_IE_handler(padapter, pIE);
  2287. VCS_update(padapter, psta);
  2288. break;
  2289. #ifdef CONFIG_TDLS
  2290. case _EXT_CAP_IE_:
  2291. if (check_ap_tdls_prohibited(pIE->data, pIE->Length) == _TRUE)
  2292. ptdlsinfo->ap_prohibited = _TRUE;
  2293. if (check_ap_tdls_ch_switching_prohibited(pIE->data, pIE->Length) == _TRUE)
  2294. ptdlsinfo->ch_switch_prohibited = _TRUE;
  2295. break;
  2296. #endif /* CONFIG_TDLS */
  2297. default:
  2298. break;
  2299. }
  2300. i += (pIE->Length + 2);
  2301. }
  2302. }
  2303. #ifdef CONFIG_DFS
  2304. void process_csa_ie(_adapter *padapter, u8 *pframe, uint pkt_len)
  2305. {
  2306. unsigned int i;
  2307. unsigned int len;
  2308. PNDIS_802_11_VARIABLE_IEs pIE;
  2309. u8 new_ch_no = 0;
  2310. if (padapter->mlmepriv.handle_dfs == _TRUE)
  2311. return;
  2312. len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN);
  2313. for (i = 0; i < len;) {
  2314. pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i);
  2315. switch (pIE->ElementID) {
  2316. case _CH_SWTICH_ANNOUNCE_:
  2317. padapter->mlmepriv.handle_dfs = _TRUE;
  2318. _rtw_memcpy(&new_ch_no, pIE->data + 1, 1);
  2319. rtw_set_csa_cmd(padapter, new_ch_no);
  2320. break;
  2321. default:
  2322. break;
  2323. }
  2324. i += (pIE->Length + 2);
  2325. }
  2326. }
  2327. #endif /* CONFIG_DFS */
  2328. unsigned int is_ap_in_tkip(_adapter *padapter)
  2329. {
  2330. u32 i;
  2331. PNDIS_802_11_VARIABLE_IEs pIE;
  2332. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2333. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2334. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  2335. if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
  2336. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;) {
  2337. pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
  2338. switch (pIE->ElementID) {
  2339. case _VENDOR_SPECIFIC_IE_:
  2340. if ((_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4)) && (_rtw_memcmp((pIE->data + 12), WPA_TKIP_CIPHER, 4)))
  2341. return _TRUE;
  2342. break;
  2343. case _RSN_IE_2_:
  2344. if (_rtw_memcmp((pIE->data + 8), RSN_TKIP_CIPHER, 4))
  2345. return _TRUE;
  2346. default:
  2347. break;
  2348. }
  2349. i += (pIE->Length + 2);
  2350. }
  2351. return _FALSE;
  2352. } else
  2353. return _FALSE;
  2354. }
  2355. unsigned int should_forbid_n_rate(_adapter *padapter)
  2356. {
  2357. u32 i;
  2358. PNDIS_802_11_VARIABLE_IEs pIE;
  2359. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2360. WLAN_BSSID_EX *cur_network = &pmlmepriv->cur_network.network;
  2361. if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
  2362. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < cur_network->IELength;) {
  2363. pIE = (PNDIS_802_11_VARIABLE_IEs)(cur_network->IEs + i);
  2364. switch (pIE->ElementID) {
  2365. case _VENDOR_SPECIFIC_IE_:
  2366. if (_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4) &&
  2367. ((_rtw_memcmp((pIE->data + 12), WPA_CIPHER_SUITE_CCMP, 4)) ||
  2368. (_rtw_memcmp((pIE->data + 16), WPA_CIPHER_SUITE_CCMP, 4))))
  2369. return _FALSE;
  2370. break;
  2371. case _RSN_IE_2_:
  2372. if ((_rtw_memcmp((pIE->data + 8), RSN_CIPHER_SUITE_CCMP, 4)) ||
  2373. (_rtw_memcmp((pIE->data + 12), RSN_CIPHER_SUITE_CCMP, 4)))
  2374. return _FALSE;
  2375. default:
  2376. break;
  2377. }
  2378. i += (pIE->Length + 2);
  2379. }
  2380. return _TRUE;
  2381. } else
  2382. return _FALSE;
  2383. }
  2384. unsigned int is_ap_in_wep(_adapter *padapter)
  2385. {
  2386. u32 i;
  2387. PNDIS_802_11_VARIABLE_IEs pIE;
  2388. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2389. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2390. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  2391. if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
  2392. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;) {
  2393. pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
  2394. switch (pIE->ElementID) {
  2395. case _VENDOR_SPECIFIC_IE_:
  2396. if (_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4))
  2397. return _FALSE;
  2398. break;
  2399. case _RSN_IE_2_:
  2400. return _FALSE;
  2401. default:
  2402. break;
  2403. }
  2404. i += (pIE->Length + 2);
  2405. }
  2406. return _TRUE;
  2407. } else
  2408. return _FALSE;
  2409. }
  2410. int wifirate2_ratetbl_inx(unsigned char rate);
  2411. int wifirate2_ratetbl_inx(unsigned char rate)
  2412. {
  2413. int inx = 0;
  2414. rate = rate & 0x7f;
  2415. switch (rate) {
  2416. case 54*2:
  2417. inx = 11;
  2418. break;
  2419. case 48*2:
  2420. inx = 10;
  2421. break;
  2422. case 36*2:
  2423. inx = 9;
  2424. break;
  2425. case 24*2:
  2426. inx = 8;
  2427. break;
  2428. case 18*2:
  2429. inx = 7;
  2430. break;
  2431. case 12*2:
  2432. inx = 6;
  2433. break;
  2434. case 9*2:
  2435. inx = 5;
  2436. break;
  2437. case 6*2:
  2438. inx = 4;
  2439. break;
  2440. case 11*2:
  2441. inx = 3;
  2442. break;
  2443. case 11:
  2444. inx = 2;
  2445. break;
  2446. case 2*2:
  2447. inx = 1;
  2448. break;
  2449. case 1*2:
  2450. inx = 0;
  2451. break;
  2452. }
  2453. return inx;
  2454. }
  2455. unsigned int update_basic_rate(unsigned char *ptn, unsigned int ptn_sz)
  2456. {
  2457. unsigned int i, num_of_rate;
  2458. unsigned int mask = 0;
  2459. num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
  2460. for (i = 0; i < num_of_rate; i++) {
  2461. if ((*(ptn + i)) & 0x80)
  2462. mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
  2463. }
  2464. return mask;
  2465. }
  2466. unsigned int update_supported_rate(unsigned char *ptn, unsigned int ptn_sz)
  2467. {
  2468. unsigned int i, num_of_rate;
  2469. unsigned int mask = 0;
  2470. num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
  2471. for (i = 0; i < num_of_rate; i++)
  2472. mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
  2473. return mask;
  2474. }
  2475. int support_short_GI(_adapter *padapter, struct HT_caps_element *pHT_caps, u8 bwmode)
  2476. {
  2477. unsigned char bit_offset;
  2478. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2479. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2480. if (!(pmlmeinfo->HT_enable))
  2481. return _FAIL;
  2482. bit_offset = (bwmode & CHANNEL_WIDTH_40) ? 6 : 5;
  2483. if (pHT_caps->u.HT_cap_element.HT_caps_info & (0x1 << bit_offset))
  2484. return _SUCCESS;
  2485. else
  2486. return _FAIL;
  2487. }
  2488. unsigned char get_highest_rate_idx(u32 mask)
  2489. {
  2490. int i;
  2491. unsigned char rate_idx = 0;
  2492. for (i = 31; i >= 0; i--) {
  2493. if (mask & BIT(i)) {
  2494. rate_idx = i;
  2495. break;
  2496. }
  2497. }
  2498. return rate_idx;
  2499. }
  2500. void Update_RA_Entry(_adapter *padapter, struct sta_info *psta)
  2501. {
  2502. rtw_hal_update_ra_mask(psta, psta->rssi_level, _TRUE);
  2503. }
  2504. void set_sta_rate(_adapter *padapter, struct sta_info *psta)
  2505. {
  2506. /* rate adaptive */
  2507. rtw_hal_update_ra_mask(psta, psta->rssi_level, _TRUE);
  2508. }
  2509. /* Update RRSR and Rate for USERATE */
  2510. void update_tx_basic_rate(_adapter *padapter, u8 wirelessmode)
  2511. {
  2512. NDIS_802_11_RATES_EX supported_rates;
  2513. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2514. #ifdef CONFIG_P2P
  2515. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  2516. /* Added by Albert 2011/03/22 */
  2517. /* In the P2P mode, the driver should not support the b mode. */
  2518. /* So, the Tx packet shouldn't use the CCK rate */
  2519. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2520. return;
  2521. #endif /* CONFIG_P2P */
  2522. #ifdef CONFIG_INTEL_WIDI
  2523. if (padapter->mlmepriv.widi_state != INTEL_WIDI_STATE_NONE)
  2524. return;
  2525. #endif /* CONFIG_INTEL_WIDI */
  2526. _rtw_memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
  2527. /* clear B mod if current channel is in 5G band, avoid tx cck rate in 5G band. */
  2528. if (pmlmeext->cur_channel > 14)
  2529. wirelessmode &= ~(WIRELESS_11B);
  2530. if ((wirelessmode & WIRELESS_11B) && (wirelessmode == WIRELESS_11B))
  2531. _rtw_memcpy(supported_rates, rtw_basic_rate_cck, 4);
  2532. else if (wirelessmode & WIRELESS_11B)
  2533. _rtw_memcpy(supported_rates, rtw_basic_rate_mix, 7);
  2534. else
  2535. _rtw_memcpy(supported_rates, rtw_basic_rate_ofdm, 3);
  2536. if (wirelessmode & WIRELESS_11B)
  2537. update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
  2538. else
  2539. update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
  2540. rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, supported_rates);
  2541. }
  2542. unsigned char check_assoc_AP(u8 *pframe, uint len)
  2543. {
  2544. unsigned int i;
  2545. PNDIS_802_11_VARIABLE_IEs pIE;
  2546. for (i = sizeof(NDIS_802_11_FIXED_IEs); i < len;) {
  2547. pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + i);
  2548. switch (pIE->ElementID) {
  2549. case _VENDOR_SPECIFIC_IE_:
  2550. if ((_rtw_memcmp(pIE->data, ARTHEROS_OUI1, 3)) || (_rtw_memcmp(pIE->data, ARTHEROS_OUI2, 3))) {
  2551. RTW_INFO("link to Artheros AP\n");
  2552. return HT_IOT_PEER_ATHEROS;
  2553. } else if ((_rtw_memcmp(pIE->data, BROADCOM_OUI1, 3))
  2554. || (_rtw_memcmp(pIE->data, BROADCOM_OUI2, 3))
  2555. || (_rtw_memcmp(pIE->data, BROADCOM_OUI3, 3))) {
  2556. RTW_INFO("link to Broadcom AP\n");
  2557. return HT_IOT_PEER_BROADCOM;
  2558. } else if (_rtw_memcmp(pIE->data, MARVELL_OUI, 3)) {
  2559. RTW_INFO("link to Marvell AP\n");
  2560. return HT_IOT_PEER_MARVELL;
  2561. } else if (_rtw_memcmp(pIE->data, RALINK_OUI, 3)) {
  2562. RTW_INFO("link to Ralink AP\n");
  2563. return HT_IOT_PEER_RALINK;
  2564. } else if (_rtw_memcmp(pIE->data, CISCO_OUI, 3)) {
  2565. RTW_INFO("link to Cisco AP\n");
  2566. return HT_IOT_PEER_CISCO;
  2567. } else if (_rtw_memcmp(pIE->data, REALTEK_OUI, 3)) {
  2568. u32 Vender = HT_IOT_PEER_REALTEK;
  2569. if (pIE->Length >= 5) {
  2570. if (pIE->data[4] == 1) {
  2571. /* if(pIE->data[5] & RT_HT_CAP_USE_LONG_PREAMBLE) */
  2572. /* bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_LONG_PREAMBLE; */
  2573. if (pIE->data[5] & RT_HT_CAP_USE_92SE) {
  2574. /* bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE; */
  2575. Vender = HT_IOT_PEER_REALTEK_92SE;
  2576. }
  2577. }
  2578. if (pIE->data[5] & RT_HT_CAP_USE_SOFTAP)
  2579. Vender = HT_IOT_PEER_REALTEK_SOFTAP;
  2580. if (pIE->data[4] == 2) {
  2581. if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_BCUT) {
  2582. Vender = HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP;
  2583. RTW_INFO("link to Realtek JAGUAR_BCUTAP\n");
  2584. }
  2585. if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_CCUT) {
  2586. Vender = HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP;
  2587. RTW_INFO("link to Realtek JAGUAR_CCUTAP\n");
  2588. }
  2589. }
  2590. }
  2591. RTW_INFO("link to Realtek AP\n");
  2592. return Vender;
  2593. } else if (_rtw_memcmp(pIE->data, AIRGOCAP_OUI, 3)) {
  2594. RTW_INFO("link to Airgo Cap\n");
  2595. return HT_IOT_PEER_AIRGO;
  2596. } else
  2597. break;
  2598. default:
  2599. break;
  2600. }
  2601. i += (pIE->Length + 2);
  2602. }
  2603. RTW_INFO("link to new AP\n");
  2604. return HT_IOT_PEER_UNKNOWN;
  2605. }
  2606. void update_capinfo(PADAPTER Adapter, u16 updateCap)
  2607. {
  2608. struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
  2609. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2610. BOOLEAN ShortPreamble;
  2611. /* Check preamble mode, 2005.01.06, by rcnjko. */
  2612. /* Mark to update preamble value forever, 2008.03.18 by lanhsin */
  2613. /* if( pMgntInfo->RegPreambleMode == PREAMBLE_AUTO ) */
  2614. {
  2615. if (updateCap & cShortPreamble) {
  2616. /* Short Preamble */
  2617. if (pmlmeinfo->preamble_mode != PREAMBLE_SHORT) { /* PREAMBLE_LONG or PREAMBLE_AUTO */
  2618. ShortPreamble = _TRUE;
  2619. pmlmeinfo->preamble_mode = PREAMBLE_SHORT;
  2620. rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
  2621. }
  2622. } else {
  2623. /* Long Preamble */
  2624. if (pmlmeinfo->preamble_mode != PREAMBLE_LONG) { /* PREAMBLE_SHORT or PREAMBLE_AUTO */
  2625. ShortPreamble = _FALSE;
  2626. pmlmeinfo->preamble_mode = PREAMBLE_LONG;
  2627. rtw_hal_set_hwreg(Adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
  2628. }
  2629. }
  2630. }
  2631. if (updateCap & cIBSS) {
  2632. /* Filen: See 802.11-2007 p.91 */
  2633. pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
  2634. } else {
  2635. /* Filen: See 802.11-2007 p.90 */
  2636. if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N | WIRELESS_11A | WIRELESS_11_5N | WIRELESS_11AC))
  2637. pmlmeinfo->slotTime = SHORT_SLOT_TIME;
  2638. else if (pmlmeext->cur_wireless_mode & (WIRELESS_11G)) {
  2639. if ((updateCap & cShortSlotTime) /* && (!(pMgntInfo->pHTInfo->RT2RT_HT_Mode & RT_HT_CAP_USE_LONG_PREAMBLE)) */) {
  2640. /* Short Slot Time */
  2641. pmlmeinfo->slotTime = SHORT_SLOT_TIME;
  2642. } else {
  2643. /* Long Slot Time */
  2644. pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
  2645. }
  2646. } else {
  2647. /* B Mode */
  2648. pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
  2649. }
  2650. }
  2651. rtw_hal_set_hwreg(Adapter, HW_VAR_SLOT_TIME, &pmlmeinfo->slotTime);
  2652. }
  2653. /*
  2654. * set adapter.mlmeextpriv.mlmext_info.HT_enable
  2655. * set adapter.mlmeextpriv.cur_wireless_mode
  2656. * set SIFS register
  2657. * set mgmt tx rate
  2658. */
  2659. void update_wireless_mode(_adapter *padapter)
  2660. {
  2661. int ratelen, network_type = 0;
  2662. u32 SIFS_Timer;
  2663. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2664. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2665. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  2666. unsigned char *rate = cur_network->SupportedRates;
  2667. #ifdef CONFIG_P2P
  2668. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  2669. #endif /* CONFIG_P2P */
  2670. ratelen = rtw_get_rateset_len(cur_network->SupportedRates);
  2671. if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
  2672. pmlmeinfo->HT_enable = 1;
  2673. if (pmlmeext->cur_channel > 14) {
  2674. if (pmlmeinfo->VHT_enable)
  2675. network_type = WIRELESS_11AC;
  2676. else if (pmlmeinfo->HT_enable)
  2677. network_type = WIRELESS_11_5N;
  2678. network_type |= WIRELESS_11A;
  2679. } else {
  2680. if (pmlmeinfo->VHT_enable)
  2681. network_type = WIRELESS_11AC;
  2682. else if (pmlmeinfo->HT_enable)
  2683. network_type = WIRELESS_11_24N;
  2684. if ((cckratesonly_included(rate, ratelen)) == _TRUE)
  2685. network_type |= WIRELESS_11B;
  2686. else if ((cckrates_included(rate, ratelen)) == _TRUE)
  2687. network_type |= WIRELESS_11BG;
  2688. else
  2689. network_type |= WIRELESS_11G;
  2690. }
  2691. pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode;
  2692. /* RTW_INFO("network_type=%02x, padapter->registrypriv.wireless_mode=%02x\n", network_type, padapter->registrypriv.wireless_mode); */
  2693. #if 0
  2694. if ((pmlmeext->cur_wireless_mode == WIRELESS_11G) ||
  2695. (pmlmeext->cur_wireless_mode == WIRELESS_11BG)) /* WIRELESS_MODE_G) */
  2696. SIFS_Timer = 0x0a0a;/* CCK */
  2697. else
  2698. SIFS_Timer = 0x0e0e;/* pHalData->SifsTime; //OFDM */
  2699. #endif
  2700. SIFS_Timer = 0x0a0a0808; /* 0x0808->for CCK, 0x0a0a->for OFDM
  2701. * change this value if having IOT issues. */
  2702. rtw_hal_set_hwreg(padapter, HW_VAR_RESP_SIFS, (u8 *)&SIFS_Timer);
  2703. rtw_hal_set_hwreg(padapter, HW_VAR_WIRELESS_MODE, (u8 *)&(pmlmeext->cur_wireless_mode));
  2704. if ((pmlmeext->cur_wireless_mode & WIRELESS_11B)
  2705. #ifdef CONFIG_P2P
  2706. && (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)
  2707. #ifdef CONFIG_IOCTL_CFG80211
  2708. || !rtw_cfg80211_iface_has_p2p_group_cap(padapter)
  2709. #endif
  2710. )
  2711. #endif
  2712. )
  2713. update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
  2714. else
  2715. update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
  2716. }
  2717. void fire_write_MAC_cmd(_adapter *padapter, unsigned int addr, unsigned int value);
  2718. void fire_write_MAC_cmd(_adapter *padapter, unsigned int addr, unsigned int value)
  2719. {
  2720. #if 0
  2721. struct cmd_obj *ph2c;
  2722. struct reg_rw_parm *pwriteMacPara;
  2723. struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
  2724. ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
  2725. if (ph2c == NULL)
  2726. return;
  2727. pwriteMacPara = (struct reg_rw_parm *)rtw_malloc(sizeof(struct reg_rw_parm));
  2728. if (pwriteMacPara == NULL) {
  2729. rtw_mfree((unsigned char *)ph2c, sizeof(struct cmd_obj));
  2730. return;
  2731. }
  2732. pwriteMacPara->rw = 1;
  2733. pwriteMacPara->addr = addr;
  2734. pwriteMacPara->value = value;
  2735. init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteMacPara, GEN_CMD_CODE(_Write_MACREG));
  2736. rtw_enqueue_cmd(pcmdpriv, ph2c);
  2737. #endif
  2738. }
  2739. void update_sta_basic_rate(struct sta_info *psta, u8 wireless_mode)
  2740. {
  2741. if (IsSupportedTxCCK(wireless_mode)) {
  2742. /* Only B, B/G, and B/G/N AP could use CCK rate */
  2743. _rtw_memcpy(psta->bssrateset, rtw_basic_rate_cck, 4);
  2744. psta->bssratelen = 4;
  2745. } else {
  2746. _rtw_memcpy(psta->bssrateset, rtw_basic_rate_ofdm, 3);
  2747. psta->bssratelen = 3;
  2748. }
  2749. }
  2750. int rtw_ies_get_supported_rate(u8 *ies, uint ies_len, u8 *rate_set, u8 *rate_num)
  2751. {
  2752. u8 *ie;
  2753. unsigned int ie_len;
  2754. if (!rate_set || !rate_num)
  2755. return _FALSE;
  2756. *rate_num = 0;
  2757. ie = rtw_get_ie(ies, _SUPPORTEDRATES_IE_, &ie_len, ies_len);
  2758. if (ie == NULL)
  2759. goto ext_rate;
  2760. _rtw_memcpy(rate_set, ie + 2, ie_len);
  2761. *rate_num = ie_len;
  2762. ext_rate:
  2763. ie = rtw_get_ie(ies, _EXT_SUPPORTEDRATES_IE_, &ie_len, ies_len);
  2764. if (ie) {
  2765. _rtw_memcpy(rate_set + *rate_num, ie + 2, ie_len);
  2766. *rate_num += ie_len;
  2767. }
  2768. if (*rate_num == 0)
  2769. return _FAIL;
  2770. if (0) {
  2771. int i;
  2772. for (i = 0; i < *rate_num; i++)
  2773. RTW_INFO("rate:0x%02x\n", *(rate_set + i));
  2774. }
  2775. return _SUCCESS;
  2776. }
  2777. void process_addba_req(_adapter *padapter, u8 *paddba_req, u8 *addr)
  2778. {
  2779. struct sta_info *psta;
  2780. u16 tid, start_seq, param;
  2781. struct sta_priv *pstapriv = &padapter->stapriv;
  2782. struct ADDBA_request *preq = (struct ADDBA_request *)paddba_req;
  2783. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2784. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2785. u8 size, accept = _FALSE;
  2786. psta = rtw_get_stainfo(pstapriv, addr);
  2787. if (!psta)
  2788. goto exit;
  2789. start_seq = le16_to_cpu(preq->BA_starting_seqctrl) >> 4;
  2790. param = le16_to_cpu(preq->BA_para_set);
  2791. tid = (param >> 2) & 0x0f;
  2792. accept = rtw_rx_ampdu_is_accept(padapter);
  2793. if (padapter->fix_rx_ampdu_size != RX_AMPDU_SIZE_INVALID)
  2794. size = padapter->fix_rx_ampdu_size;
  2795. else {
  2796. size = rtw_rx_ampdu_size(padapter);
  2797. size = rtw_min(size, rx_ampdu_size_sta_limit(padapter, psta));
  2798. }
  2799. if (accept == _TRUE)
  2800. rtw_addbarsp_cmd(padapter, addr, tid, 0, size, start_seq);
  2801. else
  2802. rtw_addbarsp_cmd(padapter, addr, tid, 37, size, start_seq); /* reject ADDBA Req */
  2803. exit:
  2804. return;
  2805. }
  2806. void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
  2807. {
  2808. u8 *pIE;
  2809. u32 *pbuf;
  2810. pIE = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  2811. pbuf = (u32 *)pIE;
  2812. pmlmeext->TSFValue = le32_to_cpu(*(pbuf + 1));
  2813. pmlmeext->TSFValue = pmlmeext->TSFValue << 32;
  2814. pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
  2815. }
  2816. void correct_TSF(_adapter *padapter, struct mlme_ext_priv *pmlmeext)
  2817. {
  2818. rtw_hal_set_hwreg(padapter, HW_VAR_CORRECT_TSF, 0);
  2819. }
  2820. void adaptive_early_32k(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
  2821. {
  2822. int i;
  2823. u8 *pIE;
  2824. u32 *pbuf;
  2825. u64 tsf = 0;
  2826. u32 delay_ms;
  2827. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2828. pmlmeext->bcn_cnt++;
  2829. pIE = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
  2830. pbuf = (u32 *)pIE;
  2831. tsf = le32_to_cpu(*(pbuf + 1));
  2832. tsf = tsf << 32;
  2833. tsf |= le32_to_cpu(*pbuf);
  2834. /* RTW_INFO("%s(): tsf_upper= 0x%08x, tsf_lower=0x%08x\n", __func__, (u32)(tsf>>32), (u32)tsf); */
  2835. /* delay = (timestamp mod 1024*100)/1000 (unit: ms) */
  2836. /* delay_ms = do_div(tsf, (pmlmeinfo->bcn_interval*1024))/1000; */
  2837. delay_ms = rtw_modular64(tsf, (pmlmeinfo->bcn_interval * 1024));
  2838. delay_ms = delay_ms / 1000;
  2839. if (delay_ms >= 8) {
  2840. pmlmeext->bcn_delay_cnt[8]++;
  2841. /* pmlmeext->bcn_delay_ratio[8] = (pmlmeext->bcn_delay_cnt[8] * 100) /pmlmeext->bcn_cnt; */
  2842. } else {
  2843. pmlmeext->bcn_delay_cnt[delay_ms]++;
  2844. /* pmlmeext->bcn_delay_ratio[delay_ms] = (pmlmeext->bcn_delay_cnt[delay_ms] * 100) /pmlmeext->bcn_cnt; */
  2845. }
  2846. /*
  2847. RTW_INFO("%s(): (a)bcn_cnt = %d\n", __func__, pmlmeext->bcn_cnt);
  2848. for(i=0; i<9; i++)
  2849. {
  2850. RTW_INFO("%s():bcn_delay_cnt[%d]=%d, bcn_delay_ratio[%d]=%d\n", __func__, i,
  2851. pmlmeext->bcn_delay_cnt[i] , i, pmlmeext->bcn_delay_ratio[i]);
  2852. }
  2853. */
  2854. /* dump for adaptive_early_32k */
  2855. if (pmlmeext->bcn_cnt > 100 && (pmlmeext->adaptive_tsf_done == _TRUE)) {
  2856. u8 ratio_20_delay, ratio_80_delay;
  2857. u8 DrvBcnEarly, DrvBcnTimeOut;
  2858. ratio_20_delay = 0;
  2859. ratio_80_delay = 0;
  2860. DrvBcnEarly = 0xff;
  2861. DrvBcnTimeOut = 0xff;
  2862. RTW_INFO("%s(): bcn_cnt = %d\n", __func__, pmlmeext->bcn_cnt);
  2863. for (i = 0; i < 9; i++) {
  2864. pmlmeext->bcn_delay_ratio[i] = (pmlmeext->bcn_delay_cnt[i] * 100) / pmlmeext->bcn_cnt;
  2865. /* RTW_INFO("%s():bcn_delay_cnt[%d]=%d, bcn_delay_ratio[%d]=%d\n", __func__, i, */
  2866. /* pmlmeext->bcn_delay_cnt[i] , i, pmlmeext->bcn_delay_ratio[i]); */
  2867. ratio_20_delay += pmlmeext->bcn_delay_ratio[i];
  2868. ratio_80_delay += pmlmeext->bcn_delay_ratio[i];
  2869. if (ratio_20_delay > 20 && DrvBcnEarly == 0xff) {
  2870. DrvBcnEarly = i;
  2871. /* RTW_INFO("%s(): DrvBcnEarly = %d\n", __func__, DrvBcnEarly); */
  2872. }
  2873. if (ratio_80_delay > 80 && DrvBcnTimeOut == 0xff) {
  2874. DrvBcnTimeOut = i;
  2875. /* RTW_INFO("%s(): DrvBcnTimeOut = %d\n", __func__, DrvBcnTimeOut); */
  2876. }
  2877. /* reset adaptive_early_32k cnt */
  2878. pmlmeext->bcn_delay_cnt[i] = 0;
  2879. pmlmeext->bcn_delay_ratio[i] = 0;
  2880. }
  2881. pmlmeext->DrvBcnEarly = DrvBcnEarly;
  2882. pmlmeext->DrvBcnTimeOut = DrvBcnTimeOut;
  2883. pmlmeext->bcn_cnt = 0;
  2884. }
  2885. }
  2886. void beacon_timing_control(_adapter *padapter)
  2887. {
  2888. rtw_hal_bcn_related_reg_setting(padapter);
  2889. }
  2890. #define CONFIG_SHARED_BMC_MACID
  2891. void dump_macid_map(void *sel, struct macid_bmp *map, u8 max_num)
  2892. {
  2893. RTW_PRINT_SEL(sel, "0x%08x\n", map->m0);
  2894. #if (MACID_NUM_SW_LIMIT > 32)
  2895. if (max_num && max_num > 32)
  2896. RTW_PRINT_SEL(sel, "0x%08x\n", map->m1);
  2897. #endif
  2898. #if (MACID_NUM_SW_LIMIT > 64)
  2899. if (max_num && max_num > 64)
  2900. RTW_PRINT_SEL(sel, "0x%08x\n", map->m2);
  2901. #endif
  2902. #if (MACID_NUM_SW_LIMIT > 96)
  2903. if (max_num && max_num > 96)
  2904. RTW_PRINT_SEL(sel, "0x%08x\n", map->m3);
  2905. #endif
  2906. }
  2907. inline bool rtw_macid_is_set(struct macid_bmp *map, u8 id)
  2908. {
  2909. if (id < 32)
  2910. return map->m0 & BIT(id);
  2911. #if (MACID_NUM_SW_LIMIT > 32)
  2912. else if (id < 64)
  2913. return map->m1 & BIT(id - 32);
  2914. #endif
  2915. #if (MACID_NUM_SW_LIMIT > 64)
  2916. else if (id < 96)
  2917. return map->m2 & BIT(id - 64);
  2918. #endif
  2919. #if (MACID_NUM_SW_LIMIT > 96)
  2920. else if (id < 128)
  2921. return map->m3 & BIT(id - 96);
  2922. #endif
  2923. else
  2924. rtw_warn_on(1);
  2925. return 0;
  2926. }
  2927. inline void rtw_macid_map_set(struct macid_bmp *map, u8 id)
  2928. {
  2929. if (id < 32)
  2930. map->m0 |= BIT(id);
  2931. #if (MACID_NUM_SW_LIMIT > 32)
  2932. else if (id < 64)
  2933. map->m1 |= BIT(id - 32);
  2934. #endif
  2935. #if (MACID_NUM_SW_LIMIT > 64)
  2936. else if (id < 96)
  2937. map->m2 |= BIT(id - 64);
  2938. #endif
  2939. #if (MACID_NUM_SW_LIMIT > 96)
  2940. else if (id < 128)
  2941. map->m3 |= BIT(id - 96);
  2942. #endif
  2943. else
  2944. rtw_warn_on(1);
  2945. }
  2946. /*Record bc's mac-id and sec-cam-id*/
  2947. inline void rtw_iface_bcmc_id_set(_adapter *padapter, u8 mac_id)
  2948. {
  2949. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2950. struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
  2951. macid_ctl->iface_bmc[padapter->iface_id] = mac_id;
  2952. }
  2953. inline u8 rtw_iface_bcmc_id_get(_adapter *padapter)
  2954. {
  2955. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2956. struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
  2957. return macid_ctl->iface_bmc[padapter->iface_id];
  2958. }
  2959. inline void rtw_macid_map_clr(struct macid_bmp *map, u8 id)
  2960. {
  2961. if (id < 32)
  2962. map->m0 &= ~BIT(id);
  2963. #if (MACID_NUM_SW_LIMIT > 32)
  2964. else if (id < 64)
  2965. map->m1 &= ~BIT(id - 32);
  2966. #endif
  2967. #if (MACID_NUM_SW_LIMIT > 64)
  2968. else if (id < 96)
  2969. map->m2 &= ~BIT(id - 64);
  2970. #endif
  2971. #if (MACID_NUM_SW_LIMIT > 96)
  2972. else if (id < 128)
  2973. map->m3 &= ~BIT(id - 96);
  2974. #endif
  2975. else
  2976. rtw_warn_on(1);
  2977. }
  2978. inline bool rtw_macid_is_used(struct macid_ctl_t *macid_ctl, u8 id)
  2979. {
  2980. return rtw_macid_is_set(&macid_ctl->used, id);
  2981. }
  2982. inline bool rtw_macid_is_bmc(struct macid_ctl_t *macid_ctl, u8 id)
  2983. {
  2984. return rtw_macid_is_set(&macid_ctl->bmc, id);
  2985. }
  2986. inline s8 rtw_macid_get_if_g(struct macid_ctl_t *macid_ctl, u8 id)
  2987. {
  2988. int i;
  2989. #ifdef CONFIG_SHARED_BMC_MACID
  2990. if (rtw_macid_is_bmc(macid_ctl, id)) {
  2991. for (i = 0; i < CONFIG_IFACE_NUMBER; i++)
  2992. if (macid_ctl->iface_bmc[i] == id)
  2993. return i;
  2994. return -1;
  2995. }
  2996. #endif
  2997. for (i = 0; i < CONFIG_IFACE_NUMBER; i++) {
  2998. if (rtw_macid_is_set(&macid_ctl->if_g[i], id))
  2999. return i;
  3000. }
  3001. return -1;
  3002. }
  3003. inline s8 rtw_macid_get_ch_g(struct macid_ctl_t *macid_ctl, u8 id)
  3004. {
  3005. int i;
  3006. for (i = 0; i < 2; i++) {
  3007. if (rtw_macid_is_set(&macid_ctl->ch_g[i], id))
  3008. return i;
  3009. }
  3010. return -1;
  3011. }
  3012. void rtw_alloc_macid(_adapter *padapter, struct sta_info *psta)
  3013. {
  3014. int i;
  3015. _irqL irqL;
  3016. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  3017. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  3018. struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
  3019. struct macid_bmp *used_map = &macid_ctl->used;
  3020. /* static u8 last_id = 0; for testing */
  3021. u8 last_id = 0;
  3022. u8 is_bc_sta = _FALSE;
  3023. if (_rtw_memcmp(psta->hwaddr, adapter_mac_addr(padapter), ETH_ALEN)) {
  3024. psta->mac_id = macid_ctl->num;
  3025. return;
  3026. }
  3027. if (_rtw_memcmp(psta->hwaddr, bc_addr, ETH_ALEN)) {
  3028. is_bc_sta = _TRUE;
  3029. rtw_iface_bcmc_id_set(padapter, INVALID_SEC_MAC_CAM_ID); /*init default value*/
  3030. }
  3031. #ifdef CONFIG_SHARED_BMC_MACID
  3032. if (is_bc_sta
  3033. #ifdef CONFIG_CONCURRENT_MODE
  3034. && (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) || check_fwstate(&padapter->mlmepriv, WIFI_NULL_STATE))
  3035. #endif
  3036. ) {
  3037. /* use shared broadcast & multicast macid 1 for all ifaces which configure to station mode*/
  3038. _enter_critical_bh(&macid_ctl->lock, &irqL);
  3039. rtw_macid_map_set(used_map, 1);
  3040. rtw_macid_map_set(&macid_ctl->bmc, 1);
  3041. rtw_macid_map_set(&macid_ctl->if_g[padapter->iface_id], 1);
  3042. macid_ctl->sta[1] = psta;
  3043. /* TODO ch_g? */
  3044. _exit_critical_bh(&macid_ctl->lock, &irqL);
  3045. i = 1;
  3046. goto assigned;
  3047. }
  3048. #endif
  3049. #ifdef CONFIG_MCC_MODE
  3050. if (MCC_EN(padapter)) {
  3051. if (MLME_IS_AP(padapter) || MLME_IS_GO(padapter))
  3052. /* GO/AP assign client macid from 8 */
  3053. last_id = 8;
  3054. }
  3055. #endif /* CONFIG_MCC_MODE */
  3056. _enter_critical_bh(&macid_ctl->lock, &irqL);
  3057. for (i = last_id; i < macid_ctl->num; i++) {
  3058. #ifdef CONFIG_SHARED_BMC_MACID
  3059. if (i == 1)
  3060. continue;
  3061. #endif
  3062. #ifdef CONFIG_MCC_MODE
  3063. /* macid 0/1 reserve for mcc for mgnt queue macid */
  3064. if (MCC_EN(padapter)) {
  3065. if (i == MCC_ROLE_STA_GC_MGMT_QUEUE_MACID)
  3066. continue;
  3067. if (i == MCC_ROLE_SOFTAP_GO_MGMT_QUEUE_MACID)
  3068. continue;
  3069. }
  3070. #endif /* CONFIG_MCC_MODE */
  3071. if (is_bc_sta) {/*for SoftAP's Broadcast sta-info*/
  3072. /*TODO:non-security AP may allociated macid = 1*/
  3073. struct cam_ctl_t *cam_ctl = dvobj_to_sec_camctl(dvobj);
  3074. if ((!rtw_macid_is_used(macid_ctl, i)) && (!rtw_sec_camid_is_used(cam_ctl, i)))
  3075. break;
  3076. } else {
  3077. if (!rtw_macid_is_used(macid_ctl, i))
  3078. break;
  3079. }
  3080. }
  3081. if (i < macid_ctl->num) {
  3082. rtw_macid_map_set(used_map, i);
  3083. if (is_bc_sta) {
  3084. struct cam_ctl_t *cam_ctl = dvobj_to_sec_camctl(dvobj);
  3085. rtw_macid_map_set(&macid_ctl->bmc, i);
  3086. rtw_iface_bcmc_id_set(padapter, i);
  3087. rtw_sec_cam_map_set(&cam_ctl->used, i);
  3088. }
  3089. rtw_macid_map_set(&macid_ctl->if_g[padapter->iface_id], i);
  3090. macid_ctl->sta[i] = psta;
  3091. /* TODO ch_g? */
  3092. last_id++;
  3093. last_id %= macid_ctl->num;
  3094. }
  3095. _exit_critical_bh(&macid_ctl->lock, &irqL);
  3096. if (i >= macid_ctl->num) {
  3097. psta->mac_id = macid_ctl->num;
  3098. RTW_ERR(FUNC_ADPT_FMT" if%u, hwaddr:"MAC_FMT" no available macid\n"
  3099. , FUNC_ADPT_ARG(padapter), padapter->iface_id + 1, MAC_ARG(psta->hwaddr));
  3100. rtw_warn_on(1);
  3101. goto exit;
  3102. } else
  3103. goto assigned;
  3104. assigned:
  3105. psta->mac_id = i;
  3106. RTW_INFO(FUNC_ADPT_FMT" if%u, hwaddr:"MAC_FMT" macid:%u\n"
  3107. , FUNC_ADPT_ARG(padapter), padapter->iface_id + 1, MAC_ARG(psta->hwaddr), psta->mac_id);
  3108. exit:
  3109. return;
  3110. }
  3111. void rtw_release_macid(_adapter *padapter, struct sta_info *psta)
  3112. {
  3113. _irqL irqL;
  3114. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  3115. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  3116. struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
  3117. u8 is_bc_sta = _FALSE;
  3118. if (_rtw_memcmp(psta->hwaddr, adapter_mac_addr(padapter), ETH_ALEN))
  3119. return;
  3120. if (_rtw_memcmp(psta->hwaddr, bc_addr, ETH_ALEN))
  3121. is_bc_sta = _TRUE;
  3122. #ifdef CONFIG_SHARED_BMC_MACID
  3123. if (is_bc_sta
  3124. #ifdef CONFIG_CONCURRENT_MODE
  3125. && (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) || check_fwstate(&padapter->mlmepriv, WIFI_NULL_STATE))
  3126. #endif
  3127. )
  3128. return;
  3129. if (psta->mac_id == 1) {
  3130. RTW_ERR(FUNC_ADPT_FMT" if%u, hwaddr:"MAC_FMT" with macid:%u\n"
  3131. , FUNC_ADPT_ARG(padapter), padapter->iface_id + 1, MAC_ARG(psta->hwaddr), psta->mac_id);
  3132. if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) || check_fwstate(&padapter->mlmepriv, WIFI_NULL_STATE))
  3133. rtw_warn_on(1);
  3134. return;
  3135. }
  3136. #endif
  3137. _enter_critical_bh(&macid_ctl->lock, &irqL);
  3138. if (psta->mac_id < macid_ctl->num) {
  3139. int i;
  3140. if (!rtw_macid_is_used(macid_ctl, psta->mac_id)) {
  3141. RTW_ERR(FUNC_ADPT_FMT" if%u, hwaddr:"MAC_FMT" macid:%u not used\n"
  3142. , FUNC_ADPT_ARG(padapter), padapter->iface_id + 1, MAC_ARG(psta->hwaddr), psta->mac_id);
  3143. rtw_warn_on(1);
  3144. }
  3145. rtw_macid_map_clr(&macid_ctl->used, psta->mac_id);
  3146. rtw_macid_map_clr(&macid_ctl->bmc, psta->mac_id);
  3147. if (is_bc_sta) {
  3148. struct cam_ctl_t *cam_ctl = dvobj_to_sec_camctl(dvobj);
  3149. u8 id = rtw_iface_bcmc_id_get(padapter);
  3150. if ((id != INVALID_SEC_MAC_CAM_ID) && (id < cam_ctl->num))
  3151. rtw_sec_cam_map_clr(&cam_ctl->used, id);
  3152. rtw_iface_bcmc_id_set(padapter, INVALID_SEC_MAC_CAM_ID);
  3153. }
  3154. for (i = 0; i < CONFIG_IFACE_NUMBER; i++)
  3155. rtw_macid_map_clr(&macid_ctl->if_g[i], psta->mac_id);
  3156. for (i = 0; i < 2; i++)
  3157. rtw_macid_map_clr(&macid_ctl->ch_g[i], psta->mac_id);
  3158. macid_ctl->sta[psta->mac_id] = NULL;
  3159. }
  3160. _exit_critical_bh(&macid_ctl->lock, &irqL);
  3161. psta->mac_id = macid_ctl->num;
  3162. }
  3163. /* For 8188E RA */
  3164. u8 rtw_search_max_mac_id(_adapter *padapter)
  3165. {
  3166. u8 max_mac_id = 0;
  3167. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  3168. struct macid_ctl_t *macid_ctl = dvobj_to_macidctl(dvobj);
  3169. int i;
  3170. _irqL irqL;
  3171. /* TODO: Only search for connected macid? */
  3172. _enter_critical_bh(&macid_ctl->lock, &irqL);
  3173. for (i = (macid_ctl->num - 1); i > 0 ; i--) {
  3174. if (rtw_macid_is_used(macid_ctl, i))
  3175. break;
  3176. }
  3177. _exit_critical_bh(&macid_ctl->lock, &irqL);
  3178. max_mac_id = i;
  3179. return max_mac_id;
  3180. }
  3181. inline void rtw_macid_ctl_set_h2c_msr(struct macid_ctl_t *macid_ctl, u8 id, u8 h2c_msr)
  3182. {
  3183. if (id >= macid_ctl->num) {
  3184. rtw_warn_on(1);
  3185. return;
  3186. }
  3187. macid_ctl->h2c_msr[id] = h2c_msr;
  3188. if (0)
  3189. RTW_INFO("macid:%u, h2c_msr:"H2C_MSR_FMT"\n", id, H2C_MSR_ARG(&macid_ctl->h2c_msr[id]));
  3190. }
  3191. inline void rtw_macid_ctl_set_bw(struct macid_ctl_t *macid_ctl, u8 id, u8 bw)
  3192. {
  3193. if (id >= macid_ctl->num) {
  3194. rtw_warn_on(1);
  3195. return;
  3196. }
  3197. macid_ctl->bw[id] = bw;
  3198. if (0)
  3199. RTW_INFO("macid:%u, bw:%s\n", id, ch_width_str(macid_ctl->bw[id]));
  3200. }
  3201. inline void rtw_macid_ctl_set_vht_en(struct macid_ctl_t *macid_ctl, u8 id, u8 en)
  3202. {
  3203. if (id >= macid_ctl->num) {
  3204. rtw_warn_on(1);
  3205. return;
  3206. }
  3207. macid_ctl->vht_en[id] = en;
  3208. if (0)
  3209. RTW_INFO("macid:%u, vht_en:%u\n", id, macid_ctl->vht_en[id]);
  3210. }
  3211. inline void rtw_macid_ctl_set_rate_bmp0(struct macid_ctl_t *macid_ctl, u8 id, u32 bmp)
  3212. {
  3213. if (id >= macid_ctl->num) {
  3214. rtw_warn_on(1);
  3215. return;
  3216. }
  3217. macid_ctl->rate_bmp0[id] = bmp;
  3218. if (0)
  3219. RTW_INFO("macid:%u, rate_bmp0:0x%08X\n", id, macid_ctl->rate_bmp0[id]);
  3220. }
  3221. inline void rtw_macid_ctl_set_rate_bmp1(struct macid_ctl_t *macid_ctl, u8 id, u32 bmp)
  3222. {
  3223. if (id >= macid_ctl->num) {
  3224. rtw_warn_on(1);
  3225. return;
  3226. }
  3227. macid_ctl->rate_bmp1[id] = bmp;
  3228. if (0)
  3229. RTW_INFO("macid:%u, rate_bmp1:0x%08X\n", id, macid_ctl->rate_bmp1[id]);
  3230. }
  3231. inline void rtw_macid_ctl_init(struct macid_ctl_t *macid_ctl)
  3232. {
  3233. _rtw_spinlock_init(&macid_ctl->lock);
  3234. }
  3235. inline void rtw_macid_ctl_deinit(struct macid_ctl_t *macid_ctl)
  3236. {
  3237. _rtw_spinlock_free(&macid_ctl->lock);
  3238. }
  3239. #if 0
  3240. unsigned int setup_beacon_frame(_adapter *padapter, unsigned char *beacon_frame)
  3241. {
  3242. unsigned short ATIMWindow;
  3243. unsigned char *pframe;
  3244. struct tx_desc *ptxdesc;
  3245. struct rtw_ieee80211_hdr *pwlanhdr;
  3246. unsigned short *fctrl;
  3247. unsigned int rate_len, len = 0;
  3248. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3249. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3250. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3251. WLAN_BSSID_EX *cur_network = &(pmlmeinfo->network);
  3252. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  3253. _rtw_memset(beacon_frame, 0, 256);
  3254. pframe = beacon_frame + TXDESC_SIZE;
  3255. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  3256. fctrl = &(pwlanhdr->frame_ctl);
  3257. *(fctrl) = 0;
  3258. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  3259. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  3260. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
  3261. set_frame_sub_type(pframe, WIFI_BEACON);
  3262. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  3263. len = sizeof(struct rtw_ieee80211_hdr_3addr);
  3264. /* timestamp will be inserted by hardware */
  3265. pframe += 8;
  3266. len += 8;
  3267. /* beacon interval: 2 bytes */
  3268. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
  3269. pframe += 2;
  3270. len += 2;
  3271. /* capability info: 2 bytes */
  3272. _rtw_memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
  3273. pframe += 2;
  3274. len += 2;
  3275. /* SSID */
  3276. pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &len);
  3277. /* supported rates... */
  3278. rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
  3279. pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &len);
  3280. /* DS parameter set */
  3281. pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &len);
  3282. /* IBSS Parameter Set... */
  3283. /* ATIMWindow = cur->Configuration.ATIMWindow; */
  3284. ATIMWindow = 0;
  3285. pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &len);
  3286. /* todo: ERP IE */
  3287. /* EXTERNDED SUPPORTED RATE */
  3288. if (rate_len > 8)
  3289. pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &len);
  3290. if ((len + TXDESC_SIZE) > 256) {
  3291. /* RTW_INFO("marc: beacon frame too large\n"); */
  3292. return 0;
  3293. }
  3294. /* fill the tx descriptor */
  3295. ptxdesc = (struct tx_desc *)beacon_frame;
  3296. /* offset 0 */
  3297. ptxdesc->txdw0 |= cpu_to_le32(len & 0x0000ffff);
  3298. ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) & 0x00ff0000); /* default = 32 bytes for TX Desc */
  3299. /* offset 4 */
  3300. ptxdesc->txdw1 |= cpu_to_le32((0x10 << QSEL_SHT) & 0x00001f00);
  3301. /* offset 8 */
  3302. ptxdesc->txdw2 |= cpu_to_le32(BMC);
  3303. ptxdesc->txdw2 |= cpu_to_le32(BK);
  3304. /* offset 16 */
  3305. ptxdesc->txdw4 = 0x80000000;
  3306. /* offset 20 */
  3307. ptxdesc->txdw5 = 0x00000000; /* 1M */
  3308. return len + TXDESC_SIZE;
  3309. }
  3310. #endif
  3311. _adapter *dvobj_get_port0_adapter(struct dvobj_priv *dvobj)
  3312. {
  3313. _adapter *port0_iface = NULL;
  3314. int i;
  3315. for (i = 0; i < dvobj->iface_nums; i++) {
  3316. if (get_hw_port(dvobj->padapters[i]) == HW_PORT0)
  3317. break;
  3318. }
  3319. if (i < 0 || i >= dvobj->iface_nums)
  3320. rtw_warn_on(1);
  3321. else
  3322. port0_iface = dvobj->padapters[i];
  3323. return port0_iface;
  3324. }
  3325. _adapter *dvobj_get_unregisterd_adapter(struct dvobj_priv *dvobj)
  3326. {
  3327. _adapter *adapter = NULL;
  3328. int i;
  3329. for (i = 0; i < dvobj->iface_nums; i++) {
  3330. if (dvobj->padapters[i]->registered == 0)
  3331. break;
  3332. }
  3333. if (i < dvobj->iface_nums)
  3334. adapter = dvobj->padapters[i];
  3335. return adapter;
  3336. }
  3337. _adapter *dvobj_get_adapter_by_addr(struct dvobj_priv *dvobj, u8 *addr)
  3338. {
  3339. _adapter *adapter = NULL;
  3340. int i;
  3341. for (i = 0; i < dvobj->iface_nums; i++) {
  3342. if (_rtw_memcmp(dvobj->padapters[i]->mac_addr, addr, ETH_ALEN) == _TRUE)
  3343. break;
  3344. }
  3345. if (i < dvobj->iface_nums)
  3346. adapter = dvobj->padapters[i];
  3347. return adapter;
  3348. }
  3349. #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
  3350. void rtw_get_current_ip_address(PADAPTER padapter, u8 *pcurrentip)
  3351. {
  3352. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3353. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3354. struct in_device *my_ip_ptr = padapter->pnetdev->ip_ptr;
  3355. u8 ipaddress[4];
  3356. if ((pmlmeinfo->state & WIFI_FW_LINKING_STATE) ||
  3357. pmlmeinfo->state & WIFI_FW_AP_STATE) {
  3358. if (my_ip_ptr != NULL) {
  3359. struct in_ifaddr *my_ifa_list = my_ip_ptr->ifa_list ;
  3360. if (my_ifa_list != NULL) {
  3361. ipaddress[0] = my_ifa_list->ifa_address & 0xFF;
  3362. ipaddress[1] = (my_ifa_list->ifa_address >> 8) & 0xFF;
  3363. ipaddress[2] = (my_ifa_list->ifa_address >> 16) & 0xFF;
  3364. ipaddress[3] = my_ifa_list->ifa_address >> 24;
  3365. RTW_INFO("%s: %d.%d.%d.%d ==========\n", __func__,
  3366. ipaddress[0], ipaddress[1], ipaddress[2], ipaddress[3]);
  3367. _rtw_memcpy(pcurrentip, ipaddress, 4);
  3368. }
  3369. }
  3370. }
  3371. }
  3372. #endif
  3373. #ifdef CONFIG_WOWLAN
  3374. bool rtw_wowlan_parser_pattern_cmd(u8 *input, char *pattern,
  3375. int *pattern_len, char *bit_mask)
  3376. {
  3377. char *cp = NULL, *end = NULL;
  3378. size_t len = 0;
  3379. int pos = 0, mask_pos = 0, res = 0;
  3380. u8 member[2] = {0};
  3381. cp = strchr(input, '=');
  3382. if (cp) {
  3383. *cp = 0;
  3384. cp++;
  3385. input = cp;
  3386. }
  3387. while (1) {
  3388. cp = strchr(input, ':');
  3389. if (cp) {
  3390. len = strlen(input) - strlen(cp);
  3391. *cp = 0;
  3392. cp++;
  3393. } else
  3394. len = 2;
  3395. if (bit_mask && (strcmp(input, "-") == 0 ||
  3396. strcmp(input, "xx") == 0 ||
  3397. strcmp(input, "--") == 0)) {
  3398. /* skip this byte and leave mask bit unset */
  3399. } else {
  3400. u8 hex;
  3401. strncpy(member, input, len);
  3402. if (!rtw_check_pattern_valid(member, sizeof(member))) {
  3403. RTW_INFO("%s:[ERROR] pattern is invalid!!\n",
  3404. __func__);
  3405. goto error;
  3406. }
  3407. res = sscanf(member, "%02hhx", &hex);
  3408. pattern[pos] = hex;
  3409. mask_pos = pos / 8;
  3410. if (bit_mask)
  3411. bit_mask[mask_pos] |= 1 << (pos % 8);
  3412. }
  3413. pos++;
  3414. if (!cp)
  3415. break;
  3416. input = cp;
  3417. }
  3418. (*pattern_len) = pos;
  3419. return _TRUE;
  3420. error:
  3421. return _FALSE;
  3422. }
  3423. bool rtw_check_pattern_valid(u8 *input, u8 len)
  3424. {
  3425. int i = 0;
  3426. bool res = _FALSE;
  3427. if (len != 2)
  3428. goto exit;
  3429. for (i = 0 ; i < len ; i++)
  3430. if (IsHexDigit(input[i]) == _FALSE)
  3431. goto exit;
  3432. res = _SUCCESS;
  3433. exit:
  3434. return res;
  3435. }
  3436. void rtw_wow_pattern_sw_reset(_adapter *adapter)
  3437. {
  3438. int i;
  3439. struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(adapter);
  3440. pwrctrlpriv->wowlan_pattern_idx = DEFAULT_PATTERN_NUM;
  3441. for (i = 0 ; i < MAX_WKFM_CAM_NUM; i++) {
  3442. _rtw_memset(pwrctrlpriv->patterns[i].content, '\0', sizeof(pwrctrlpriv->patterns[i].content));
  3443. _rtw_memset(pwrctrlpriv->patterns[i].mask, '\0', sizeof(pwrctrlpriv->patterns[i].mask));
  3444. pwrctrlpriv->patterns[i].len = 0;
  3445. }
  3446. }
  3447. u8 rtw_set_default_pattern(_adapter *adapter)
  3448. {
  3449. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(adapter);
  3450. struct registry_priv *pregistrypriv = &adapter->registrypriv;
  3451. u8 index = 0;
  3452. u8 currentip[4];
  3453. u8 multicast_addr[3] = {0x01, 0x00, 0x5e};
  3454. u8 multicast_ip[4] = {0xe0, 0x28, 0x28, 0x2a};
  3455. u8 unicast_mask[5] = {0x3f, 0x70, 0x80, 0xc0, 0x03};
  3456. u8 multicast_mask[5] = {0x07, 0x70, 0x80, 0xc0, 0x03};
  3457. u8 ip_protocol[3] = {0x08, 0x00, 0x45};
  3458. u8 icmp_protocol[1] = {0x01};
  3459. u8 tcp_protocol[1] = {0x06};
  3460. u8 udp_protocol[1] = {0x11};
  3461. if (pregistrypriv->default_patterns_en == _FALSE)
  3462. return 0;
  3463. for (index = 0 ; index < DEFAULT_PATTERN_NUM ; index++) {
  3464. _rtw_memset(pwrpriv->patterns[index].content, 0,
  3465. sizeof(pwrpriv->patterns[index].content));
  3466. _rtw_memset(pwrpriv->patterns[index].mask, 0,
  3467. sizeof(pwrpriv->patterns[index].mask));
  3468. pwrpriv->patterns[index].len = 0;
  3469. }
  3470. rtw_get_current_ip_address(adapter, currentip);
  3471. /*TCP/ICMP unicast*/
  3472. for (index = 0 ; index < DEFAULT_PATTERN_NUM ; index++) {
  3473. switch (index) {
  3474. case 0:
  3475. _rtw_memcpy(pwrpriv->patterns[index].content,
  3476. adapter_mac_addr(adapter),
  3477. ETH_ALEN);
  3478. _rtw_memcpy(pwrpriv->patterns[index].content + ETH_TYPE_OFFSET,
  3479. &ip_protocol, sizeof(ip_protocol));
  3480. _rtw_memcpy(pwrpriv->patterns[index].content + PROTOCOL_OFFSET,
  3481. &tcp_protocol, sizeof(tcp_protocol));
  3482. _rtw_memcpy(pwrpriv->patterns[index].content + IP_OFFSET,
  3483. &currentip, sizeof(currentip));
  3484. _rtw_memcpy(pwrpriv->patterns[index].mask,
  3485. &unicast_mask, sizeof(unicast_mask));
  3486. pwrpriv->patterns[index].len = IP_OFFSET + sizeof(currentip);
  3487. break;
  3488. case 1:
  3489. _rtw_memcpy(pwrpriv->patterns[index].content,
  3490. adapter_mac_addr(adapter),
  3491. ETH_ALEN);
  3492. _rtw_memcpy(pwrpriv->patterns[index].content + ETH_TYPE_OFFSET,
  3493. &ip_protocol, sizeof(ip_protocol));
  3494. _rtw_memcpy(pwrpriv->patterns[index].content + PROTOCOL_OFFSET,
  3495. &icmp_protocol, sizeof(icmp_protocol));
  3496. _rtw_memcpy(pwrpriv->patterns[index].content + IP_OFFSET,
  3497. &currentip, sizeof(currentip));
  3498. _rtw_memcpy(pwrpriv->patterns[index].mask,
  3499. &unicast_mask, sizeof(unicast_mask));
  3500. pwrpriv->patterns[index].len = IP_OFFSET + sizeof(currentip);
  3501. break;
  3502. case 2:
  3503. _rtw_memcpy(pwrpriv->patterns[index].content, &multicast_addr,
  3504. sizeof(multicast_addr));
  3505. _rtw_memcpy(pwrpriv->patterns[index].content + ETH_TYPE_OFFSET,
  3506. &ip_protocol, sizeof(ip_protocol));
  3507. _rtw_memcpy(pwrpriv->patterns[index].content + PROTOCOL_OFFSET,
  3508. &udp_protocol, sizeof(udp_protocol));
  3509. _rtw_memcpy(pwrpriv->patterns[index].content + IP_OFFSET,
  3510. &multicast_ip, sizeof(multicast_ip));
  3511. _rtw_memcpy(pwrpriv->patterns[index].mask,
  3512. &multicast_mask, sizeof(multicast_mask));
  3513. pwrpriv->patterns[index].len =
  3514. IP_OFFSET + sizeof(multicast_ip);
  3515. break;
  3516. }
  3517. }
  3518. return index;
  3519. }
  3520. void rtw_dump_priv_pattern(_adapter *adapter, u8 idx)
  3521. {
  3522. struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(adapter);
  3523. char str_1[128];
  3524. char *p_str;
  3525. u8 val8 = 0;
  3526. int i = 0, j = 0, len = 0, max_len = 0;
  3527. RTW_INFO("=========[%d]========\n", idx);
  3528. RTW_INFO(">>>priv_pattern_content:\n");
  3529. p_str = str_1;
  3530. max_len = sizeof(str_1);
  3531. for (i = 0 ; i < MAX_WKFM_PATTERN_SIZE / 8 ; i++) {
  3532. _rtw_memset(p_str, 0, max_len);
  3533. len = 0;
  3534. for (j = 0 ; j < 8 ; j++) {
  3535. val8 = pwrctl->patterns[idx].content[i * 8 + j];
  3536. len += snprintf(p_str + len, max_len - len,
  3537. "%02x ", val8);
  3538. }
  3539. RTW_INFO("%s\n", p_str);
  3540. }
  3541. RTW_INFO(">>>priv_pattern_mask:\n");
  3542. for (i = 0 ; i < MAX_WKFM_SIZE / 8 ; i++) {
  3543. _rtw_memset(p_str, 0, max_len);
  3544. len = 0;
  3545. for (j = 0 ; j < 8 ; j++) {
  3546. val8 = pwrctl->patterns[idx].mask[i * 8 + j];
  3547. len += snprintf(p_str + len, max_len - len,
  3548. "%02x ", val8);
  3549. }
  3550. RTW_INFO("%s\n", p_str);
  3551. }
  3552. RTW_INFO(">>>priv_pattern_len:\n");
  3553. RTW_INFO("%s: len: %d\n", __func__, pwrctl->patterns[idx].len);
  3554. }
  3555. void rtw_wow_pattern_sw_dump(_adapter *adapter)
  3556. {
  3557. int i;
  3558. RTW_INFO("********[RTK priv-patterns]*********\n");
  3559. for (i = 0 ; i < MAX_WKFM_CAM_NUM; i++)
  3560. rtw_dump_priv_pattern(adapter, i);
  3561. }
  3562. void rtw_get_sec_iv(PADAPTER padapter, u8 *pcur_dot11txpn, u8 *StaAddr)
  3563. {
  3564. struct sta_info *psta;
  3565. struct security_priv *psecpriv = &padapter->securitypriv;
  3566. _rtw_memset(pcur_dot11txpn, 0, 8);
  3567. if (NULL == StaAddr)
  3568. return;
  3569. psta = rtw_get_stainfo(&padapter->stapriv, StaAddr);
  3570. RTW_INFO("%s(): StaAddr: %02x %02x %02x %02x %02x %02x\n",
  3571. __func__, StaAddr[0], StaAddr[1], StaAddr[2],
  3572. StaAddr[3], StaAddr[4], StaAddr[5]);
  3573. if (psta) {
  3574. if (psecpriv->dot11PrivacyAlgrthm == _AES_)
  3575. AES_IV(pcur_dot11txpn, psta->dot11txpn, 0);
  3576. else if (psecpriv->dot11PrivacyAlgrthm == _TKIP_)
  3577. TKIP_IV(pcur_dot11txpn, psta->dot11txpn, 0);
  3578. RTW_INFO("%s(): CurrentIV: %02x %02x %02x %02x %02x %02x %02x %02x\n"
  3579. , __func__, pcur_dot11txpn[0], pcur_dot11txpn[1],
  3580. pcur_dot11txpn[2], pcur_dot11txpn[3], pcur_dot11txpn[4],
  3581. pcur_dot11txpn[5], pcur_dot11txpn[6], pcur_dot11txpn[7]);
  3582. }
  3583. }
  3584. #endif /* CONFIG_WOWLAN */
  3585. #ifdef CONFIG_PNO_SUPPORT
  3586. #define CSCAN_TLV_TYPE_SSID_IE 'S'
  3587. #define CIPHER_IE "key_mgmt="
  3588. #define CIPHER_NONE "NONE"
  3589. #define CIPHER_WPA_PSK "WPA-PSK"
  3590. #define CIPHER_WPA_EAP "WPA-EAP IEEE8021X"
  3591. /*
  3592. * SSIDs list parsing from cscan tlv list
  3593. */
  3594. int rtw_parse_ssid_list_tlv(char **list_str, pno_ssid_t *ssid,
  3595. int max, int *bytes_left)
  3596. {
  3597. char *str;
  3598. int idx = 0;
  3599. if ((list_str == NULL) || (*list_str == NULL) || (*bytes_left < 0)) {
  3600. RTW_INFO("%s error paramters\n", __func__);
  3601. return -1;
  3602. }
  3603. str = *list_str;
  3604. while (*bytes_left > 0) {
  3605. if (str[0] != CSCAN_TLV_TYPE_SSID_IE) {
  3606. *list_str = str;
  3607. RTW_INFO("nssid=%d left_parse=%d %d\n", idx, *bytes_left, str[0]);
  3608. return idx;
  3609. }
  3610. /* Get proper CSCAN_TLV_TYPE_SSID_IE */
  3611. *bytes_left -= 1;
  3612. str += 1;
  3613. if (str[0] == 0) {
  3614. /* Broadcast SSID */
  3615. ssid[idx].SSID_len = 0;
  3616. memset((char *)ssid[idx].SSID, 0x0, WLAN_SSID_MAXLEN);
  3617. *bytes_left -= 1;
  3618. str += 1;
  3619. RTW_INFO("BROADCAST SCAN left=%d\n", *bytes_left);
  3620. } else if (str[0] <= WLAN_SSID_MAXLEN) {
  3621. /* Get proper SSID size */
  3622. ssid[idx].SSID_len = str[0];
  3623. *bytes_left -= 1;
  3624. str += 1;
  3625. /* Get SSID */
  3626. if (ssid[idx].SSID_len > *bytes_left) {
  3627. RTW_INFO("%s out of memory range len=%d but left=%d\n",
  3628. __func__, ssid[idx].SSID_len, *bytes_left);
  3629. return -1;
  3630. }
  3631. memcpy((char *)ssid[idx].SSID, str, ssid[idx].SSID_len);
  3632. *bytes_left -= ssid[idx].SSID_len;
  3633. str += ssid[idx].SSID_len;
  3634. RTW_INFO("%s :size=%d left=%d\n",
  3635. (char *)ssid[idx].SSID, ssid[idx].SSID_len, *bytes_left);
  3636. } else {
  3637. RTW_INFO("### SSID size more that %d\n", str[0]);
  3638. return -1;
  3639. }
  3640. if (idx++ > max) {
  3641. RTW_INFO("%s number of SSIDs more that %d\n", __func__, idx);
  3642. return -1;
  3643. }
  3644. }
  3645. *list_str = str;
  3646. return idx;
  3647. }
  3648. int rtw_parse_cipher_list(struct pno_nlo_info *nlo_info, char *list_str)
  3649. {
  3650. char *pch, *pnext, *pend;
  3651. u8 key_len = 0, index = 0;
  3652. pch = list_str;
  3653. if (nlo_info == NULL || list_str == NULL) {
  3654. RTW_INFO("%s error paramters\n", __func__);
  3655. return -1;
  3656. }
  3657. while (strlen(pch) != 0) {
  3658. pnext = strstr(pch, "key_mgmt=");
  3659. if (pnext != NULL) {
  3660. pch = pnext + strlen(CIPHER_IE);
  3661. pend = strstr(pch, "}");
  3662. if (strncmp(pch, CIPHER_NONE,
  3663. strlen(CIPHER_NONE)) == 0)
  3664. nlo_info->ssid_cipher_info[index] = 0x00;
  3665. else if (strncmp(pch, CIPHER_WPA_PSK,
  3666. strlen(CIPHER_WPA_PSK)) == 0)
  3667. nlo_info->ssid_cipher_info[index] = 0x66;
  3668. else if (strncmp(pch, CIPHER_WPA_EAP,
  3669. strlen(CIPHER_WPA_EAP)) == 0)
  3670. nlo_info->ssid_cipher_info[index] = 0x01;
  3671. index++;
  3672. pch = pend + 1;
  3673. } else
  3674. break;
  3675. }
  3676. return 0;
  3677. }
  3678. int rtw_dev_nlo_info_set(struct pno_nlo_info *nlo_info, pno_ssid_t *ssid,
  3679. int num, int pno_time, int pno_repeat, int pno_freq_expo_max)
  3680. {
  3681. int i = 0;
  3682. struct file *fp;
  3683. mm_segment_t fs;
  3684. loff_t pos = 0;
  3685. u8 *source = NULL;
  3686. long len = 0;
  3687. RTW_INFO("+%s+\n", __func__);
  3688. nlo_info->fast_scan_period = pno_time;
  3689. nlo_info->ssid_num = num & BIT_LEN_MASK_32(8);
  3690. nlo_info->hidden_ssid_num = num & BIT_LEN_MASK_32(8);
  3691. nlo_info->slow_scan_period = (pno_time * 2);
  3692. nlo_info->fast_scan_iterations = 5;
  3693. if (nlo_info->hidden_ssid_num > 8)
  3694. nlo_info->hidden_ssid_num = 8;
  3695. /* TODO: channel list and probe index is all empty. */
  3696. for (i = 0 ; i < num ; i++) {
  3697. nlo_info->ssid_length[i]
  3698. = ssid[i].SSID_len;
  3699. }
  3700. /* cipher array */
  3701. fp = filp_open("/data/misc/wifi/wpa_supplicant.conf", O_RDONLY, 0644);
  3702. if (IS_ERR(fp)) {
  3703. RTW_INFO("Error, wpa_supplicant.conf doesn't exist.\n");
  3704. RTW_INFO("Error, cipher array using default value.\n");
  3705. return 0;
  3706. }
  3707. len = i_size_read(fp->f_path.dentry->d_inode);
  3708. if (len < 0 || len > 2048) {
  3709. RTW_INFO("Error, file size is bigger than 2048.\n");
  3710. RTW_INFO("Error, cipher array using default value.\n");
  3711. return 0;
  3712. }
  3713. fs = get_fs();
  3714. set_fs(KERNEL_DS);
  3715. source = rtw_zmalloc(2048);
  3716. if (source != NULL) {
  3717. len = vfs_read(fp, source, len, &pos);
  3718. rtw_parse_cipher_list(nlo_info, source);
  3719. rtw_mfree(source, 2048);
  3720. }
  3721. set_fs(fs);
  3722. filp_close(fp, NULL);
  3723. RTW_INFO("-%s-\n", __func__);
  3724. return 0;
  3725. }
  3726. int rtw_dev_ssid_list_set(struct pno_ssid_list *pno_ssid_list,
  3727. pno_ssid_t *ssid, u8 num)
  3728. {
  3729. int i = 0;
  3730. if (num > MAX_PNO_LIST_COUNT)
  3731. num = MAX_PNO_LIST_COUNT;
  3732. for (i = 0 ; i < num ; i++) {
  3733. _rtw_memcpy(&pno_ssid_list->node[i].SSID,
  3734. ssid[i].SSID, ssid[i].SSID_len);
  3735. pno_ssid_list->node[i].SSID_len = ssid[i].SSID_len;
  3736. }
  3737. return 0;
  3738. }
  3739. int rtw_dev_scan_info_set(_adapter *padapter, pno_ssid_t *ssid,
  3740. unsigned char ch, unsigned char ch_offset, unsigned short bw_mode)
  3741. {
  3742. struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
  3743. struct pno_scan_info *scan_info = pwrctl->pscan_info;
  3744. int i;
  3745. scan_info->channel_num = MAX_SCAN_LIST_COUNT;
  3746. scan_info->orig_ch = ch;
  3747. scan_info->orig_bw = bw_mode;
  3748. scan_info->orig_40_offset = ch_offset;
  3749. for (i = 0 ; i < scan_info->channel_num ; i++) {
  3750. if (i < 11)
  3751. scan_info->ssid_channel_info[i].active = 1;
  3752. else
  3753. scan_info->ssid_channel_info[i].active = 0;
  3754. scan_info->ssid_channel_info[i].timeout = 100;
  3755. scan_info->ssid_channel_info[i].tx_power =
  3756. phy_get_tx_power_index(padapter, 0, 0x02, bw_mode, i + 1);
  3757. scan_info->ssid_channel_info[i].channel = i + 1;
  3758. }
  3759. RTW_INFO("%s, channel_num: %d, orig_ch: %d, orig_bw: %d orig_40_offset: %d\n",
  3760. __func__, scan_info->channel_num, scan_info->orig_ch,
  3761. scan_info->orig_bw, scan_info->orig_40_offset);
  3762. return 0;
  3763. }
  3764. int rtw_dev_pno_set(struct net_device *net, pno_ssid_t *ssid, int num,
  3765. int pno_time, int pno_repeat, int pno_freq_expo_max)
  3766. {
  3767. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  3768. struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
  3769. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3770. int ret = -1;
  3771. if (num == 0) {
  3772. RTW_INFO("%s, nssid is zero, no need to setup pno ssid list\n", __func__);
  3773. return 0;
  3774. }
  3775. if (pwrctl == NULL) {
  3776. RTW_INFO("%s, ERROR: pwrctl is NULL\n", __func__);
  3777. return -1;
  3778. } else {
  3779. pwrctl->pnlo_info =
  3780. (pno_nlo_info_t *)rtw_zmalloc(sizeof(pno_nlo_info_t));
  3781. pwrctl->pno_ssid_list =
  3782. (pno_ssid_list_t *)rtw_zmalloc(sizeof(pno_ssid_list_t));
  3783. pwrctl->pscan_info =
  3784. (pno_scan_info_t *)rtw_zmalloc(sizeof(pno_scan_info_t));
  3785. }
  3786. if (pwrctl->pnlo_info == NULL ||
  3787. pwrctl->pscan_info == NULL ||
  3788. pwrctl->pno_ssid_list == NULL) {
  3789. RTW_INFO("%s, ERROR: alloc nlo_info, ssid_list, scan_info fail\n", __func__);
  3790. goto failing;
  3791. }
  3792. pwrctl->wowlan_in_resume = _FALSE;
  3793. pwrctl->pno_inited = _TRUE;
  3794. /* NLO Info */
  3795. ret = rtw_dev_nlo_info_set(pwrctl->pnlo_info, ssid, num,
  3796. pno_time, pno_repeat, pno_freq_expo_max);
  3797. /* SSID Info */
  3798. ret = rtw_dev_ssid_list_set(pwrctl->pno_ssid_list, ssid, num);
  3799. /* SCAN Info */
  3800. ret = rtw_dev_scan_info_set(padapter, ssid, pmlmeext->cur_channel,
  3801. pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
  3802. RTW_INFO("+%s num: %d, pno_time: %d, pno_repeat:%d, pno_freq_expo_max:%d+\n",
  3803. __func__, num, pno_time, pno_repeat, pno_freq_expo_max);
  3804. return 0;
  3805. failing:
  3806. if (pwrctl->pnlo_info) {
  3807. rtw_mfree((u8 *)pwrctl->pnlo_info, sizeof(pno_nlo_info_t));
  3808. pwrctl->pnlo_info = NULL;
  3809. }
  3810. if (pwrctl->pno_ssid_list) {
  3811. rtw_mfree((u8 *)pwrctl->pno_ssid_list, sizeof(pno_ssid_list_t));
  3812. pwrctl->pno_ssid_list = NULL;
  3813. }
  3814. if (pwrctl->pscan_info) {
  3815. rtw_mfree((u8 *)pwrctl->pscan_info, sizeof(pno_scan_info_t));
  3816. pwrctl->pscan_info = NULL;
  3817. }
  3818. return -1;
  3819. }
  3820. #ifdef CONFIG_PNO_SET_DEBUG
  3821. void rtw_dev_pno_debug(struct net_device *net)
  3822. {
  3823. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  3824. struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
  3825. int i = 0, j = 0;
  3826. RTW_INFO("*******NLO_INFO********\n");
  3827. RTW_INFO("ssid_num: %d\n", pwrctl->pnlo_info->ssid_num);
  3828. RTW_INFO("fast_scan_iterations: %d\n",
  3829. pwrctl->pnlo_info->fast_scan_iterations);
  3830. RTW_INFO("fast_scan_period: %d\n", pwrctl->pnlo_info->fast_scan_period);
  3831. RTW_INFO("slow_scan_period: %d\n", pwrctl->pnlo_info->slow_scan_period);
  3832. for (i = 0 ; i < MAX_PNO_LIST_COUNT ; i++) {
  3833. RTW_INFO("%d SSID (%s) length (%d) cipher(%x) channel(%d)\n",
  3834. i, pwrctl->pno_ssid_list->node[i].SSID, pwrctl->pnlo_info->ssid_length[i],
  3835. pwrctl->pnlo_info->ssid_cipher_info[i], pwrctl->pnlo_info->ssid_channel_info[i]);
  3836. }
  3837. RTW_INFO("******SCAN_INFO******\n");
  3838. RTW_INFO("ch_num: %d\n", pwrctl->pscan_info->channel_num);
  3839. RTW_INFO("orig_ch: %d\n", pwrctl->pscan_info->orig_ch);
  3840. RTW_INFO("orig bw: %d\n", pwrctl->pscan_info->orig_bw);
  3841. RTW_INFO("orig 40 offset: %d\n", pwrctl->pscan_info->orig_40_offset);
  3842. for (i = 0 ; i < MAX_SCAN_LIST_COUNT ; i++) {
  3843. RTW_INFO("[%02d] avtive:%d, timeout:%d, tx_power:%d, ch:%02d\n",
  3844. i, pwrctl->pscan_info->ssid_channel_info[i].active,
  3845. pwrctl->pscan_info->ssid_channel_info[i].timeout,
  3846. pwrctl->pscan_info->ssid_channel_info[i].tx_power,
  3847. pwrctl->pscan_info->ssid_channel_info[i].channel);
  3848. }
  3849. RTW_INFO("*****************\n");
  3850. }
  3851. #endif /* CONFIG_PNO_SET_DEBUG */
  3852. #endif /* CONFIG_PNO_SUPPORT */