cfg80211.c 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371
  1. /*
  2. * Marvell Wireless LAN device driver: CFG80211
  3. *
  4. * Copyright (C) 2011-2014, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "cfg80211.h"
  20. #include "main.h"
  21. #include "11n.h"
  22. #include "wmm.h"
  23. static char *reg_alpha2;
  24. module_param(reg_alpha2, charp, 0);
  25. static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
  26. {
  27. .max = 3, .types = BIT(NL80211_IFTYPE_STATION) |
  28. BIT(NL80211_IFTYPE_P2P_GO) |
  29. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  30. BIT(NL80211_IFTYPE_AP),
  31. },
  32. };
  33. static const struct ieee80211_iface_combination
  34. mwifiex_iface_comb_ap_sta = {
  35. .limits = mwifiex_ap_sta_limits,
  36. .num_different_channels = 1,
  37. .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
  38. .max_interfaces = MWIFIEX_MAX_BSS_NUM,
  39. .beacon_int_infra_match = true,
  40. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  41. BIT(NL80211_CHAN_WIDTH_20) |
  42. BIT(NL80211_CHAN_WIDTH_40),
  43. };
  44. static const struct ieee80211_iface_combination
  45. mwifiex_iface_comb_ap_sta_vht = {
  46. .limits = mwifiex_ap_sta_limits,
  47. .num_different_channels = 1,
  48. .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
  49. .max_interfaces = MWIFIEX_MAX_BSS_NUM,
  50. .beacon_int_infra_match = true,
  51. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  52. BIT(NL80211_CHAN_WIDTH_20) |
  53. BIT(NL80211_CHAN_WIDTH_40) |
  54. BIT(NL80211_CHAN_WIDTH_80),
  55. };
  56. static const struct
  57. ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
  58. .limits = mwifiex_ap_sta_limits,
  59. .num_different_channels = 2,
  60. .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
  61. .max_interfaces = MWIFIEX_MAX_BSS_NUM,
  62. .beacon_int_infra_match = true,
  63. };
  64. /*
  65. * This function maps the nl802.11 channel type into driver channel type.
  66. *
  67. * The mapping is as follows -
  68. * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  69. * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  70. * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
  71. * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
  72. * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE
  73. */
  74. u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
  75. {
  76. switch (chan_type) {
  77. case NL80211_CHAN_NO_HT:
  78. case NL80211_CHAN_HT20:
  79. return IEEE80211_HT_PARAM_CHA_SEC_NONE;
  80. case NL80211_CHAN_HT40PLUS:
  81. return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  82. case NL80211_CHAN_HT40MINUS:
  83. return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  84. default:
  85. return IEEE80211_HT_PARAM_CHA_SEC_NONE;
  86. }
  87. }
  88. /* This function maps IEEE HT secondary channel type to NL80211 channel type
  89. */
  90. u8 mwifiex_sec_chan_offset_to_chan_type(u8 second_chan_offset)
  91. {
  92. switch (second_chan_offset) {
  93. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  94. return NL80211_CHAN_HT20;
  95. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  96. return NL80211_CHAN_HT40PLUS;
  97. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  98. return NL80211_CHAN_HT40MINUS;
  99. default:
  100. return NL80211_CHAN_HT20;
  101. }
  102. }
  103. /*
  104. * This function checks whether WEP is set.
  105. */
  106. static int
  107. mwifiex_is_alg_wep(u32 cipher)
  108. {
  109. switch (cipher) {
  110. case WLAN_CIPHER_SUITE_WEP40:
  111. case WLAN_CIPHER_SUITE_WEP104:
  112. return 1;
  113. default:
  114. break;
  115. }
  116. return 0;
  117. }
  118. /*
  119. * This function retrieves the private structure from kernel wiphy structure.
  120. */
  121. static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
  122. {
  123. return (void *) (*(unsigned long *) wiphy_priv(wiphy));
  124. }
  125. /*
  126. * CFG802.11 operation handler to delete a network key.
  127. */
  128. static int
  129. mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
  130. u8 key_index, bool pairwise, const u8 *mac_addr)
  131. {
  132. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  133. const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  134. const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
  135. if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
  136. mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
  137. return -EFAULT;
  138. }
  139. mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
  140. return 0;
  141. }
  142. /*
  143. * This function forms an skb for management frame.
  144. */
  145. static int
  146. mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
  147. {
  148. u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  149. u16 pkt_len;
  150. u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
  151. pkt_len = len + ETH_ALEN;
  152. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
  153. MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  154. memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
  155. memcpy(skb_push(skb, sizeof(tx_control)),
  156. &tx_control, sizeof(tx_control));
  157. memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
  158. /* Add packet data and address4 */
  159. memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
  160. sizeof(struct ieee80211_hdr_3addr));
  161. memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
  162. memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
  163. buf + sizeof(struct ieee80211_hdr_3addr),
  164. len - sizeof(struct ieee80211_hdr_3addr));
  165. skb->priority = LOW_PRIO_TID;
  166. __net_timestamp(skb);
  167. return 0;
  168. }
  169. /*
  170. * CFG802.11 operation handler to transmit a management frame.
  171. */
  172. static int
  173. mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  174. struct cfg80211_mgmt_tx_params *params, u64 *cookie)
  175. {
  176. const u8 *buf = params->buf;
  177. size_t len = params->len;
  178. struct sk_buff *skb;
  179. u16 pkt_len;
  180. const struct ieee80211_mgmt *mgmt;
  181. struct mwifiex_txinfo *tx_info;
  182. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  183. if (!buf || !len) {
  184. mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
  185. return -EFAULT;
  186. }
  187. mgmt = (const struct ieee80211_mgmt *)buf;
  188. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
  189. ieee80211_is_probe_resp(mgmt->frame_control)) {
  190. /* Since we support offload probe resp, we need to skip probe
  191. * resp in AP or GO mode */
  192. mwifiex_dbg(priv->adapter, INFO,
  193. "info: skip to send probe resp in AP or GO mode\n");
  194. return 0;
  195. }
  196. pkt_len = len + ETH_ALEN;
  197. skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
  198. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  199. pkt_len + sizeof(pkt_len));
  200. if (!skb) {
  201. mwifiex_dbg(priv->adapter, ERROR,
  202. "allocate skb failed for management frame\n");
  203. return -ENOMEM;
  204. }
  205. tx_info = MWIFIEX_SKB_TXCB(skb);
  206. memset(tx_info, 0, sizeof(*tx_info));
  207. tx_info->bss_num = priv->bss_num;
  208. tx_info->bss_type = priv->bss_type;
  209. tx_info->pkt_len = pkt_len;
  210. mwifiex_form_mgmt_frame(skb, buf, len);
  211. *cookie = prandom_u32() | 1;
  212. if (ieee80211_is_action(mgmt->frame_control))
  213. skb = mwifiex_clone_skb_for_tx_status(priv,
  214. skb,
  215. MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
  216. else
  217. cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
  218. GFP_ATOMIC);
  219. mwifiex_queue_tx_pkt(priv, skb);
  220. mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
  221. return 0;
  222. }
  223. /*
  224. * CFG802.11 operation handler to register a mgmt frame.
  225. */
  226. static void
  227. mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
  228. struct wireless_dev *wdev,
  229. u16 frame_type, bool reg)
  230. {
  231. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  232. u32 mask;
  233. if (reg)
  234. mask = priv->mgmt_frame_mask | BIT(frame_type >> 4);
  235. else
  236. mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4);
  237. if (mask != priv->mgmt_frame_mask) {
  238. priv->mgmt_frame_mask = mask;
  239. mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
  240. HostCmd_ACT_GEN_SET, 0,
  241. &priv->mgmt_frame_mask, false);
  242. mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
  243. }
  244. }
  245. /*
  246. * CFG802.11 operation handler to remain on channel.
  247. */
  248. static int
  249. mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
  250. struct wireless_dev *wdev,
  251. struct ieee80211_channel *chan,
  252. unsigned int duration, u64 *cookie)
  253. {
  254. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  255. int ret;
  256. if (!chan || !cookie) {
  257. mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
  258. return -EINVAL;
  259. }
  260. if (priv->roc_cfg.cookie) {
  261. mwifiex_dbg(priv->adapter, INFO,
  262. "info: ongoing ROC, cookie = 0x%llx\n",
  263. priv->roc_cfg.cookie);
  264. return -EBUSY;
  265. }
  266. ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
  267. duration);
  268. if (!ret) {
  269. *cookie = prandom_u32() | 1;
  270. priv->roc_cfg.cookie = *cookie;
  271. priv->roc_cfg.chan = *chan;
  272. cfg80211_ready_on_channel(wdev, *cookie, chan,
  273. duration, GFP_ATOMIC);
  274. mwifiex_dbg(priv->adapter, INFO,
  275. "info: ROC, cookie = 0x%llx\n", *cookie);
  276. }
  277. return ret;
  278. }
  279. /*
  280. * CFG802.11 operation handler to cancel remain on channel.
  281. */
  282. static int
  283. mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
  284. struct wireless_dev *wdev, u64 cookie)
  285. {
  286. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  287. int ret;
  288. if (cookie != priv->roc_cfg.cookie)
  289. return -ENOENT;
  290. ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
  291. &priv->roc_cfg.chan, 0);
  292. if (!ret) {
  293. cfg80211_remain_on_channel_expired(wdev, cookie,
  294. &priv->roc_cfg.chan,
  295. GFP_ATOMIC);
  296. memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
  297. mwifiex_dbg(priv->adapter, INFO,
  298. "info: cancel ROC, cookie = 0x%llx\n", cookie);
  299. }
  300. return ret;
  301. }
  302. /*
  303. * CFG802.11 operation handler to set Tx power.
  304. */
  305. static int
  306. mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
  307. struct wireless_dev *wdev,
  308. enum nl80211_tx_power_setting type,
  309. int mbm)
  310. {
  311. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  312. struct mwifiex_private *priv;
  313. struct mwifiex_power_cfg power_cfg;
  314. int dbm = MBM_TO_DBM(mbm);
  315. if (type == NL80211_TX_POWER_FIXED) {
  316. power_cfg.is_power_auto = 0;
  317. power_cfg.power_level = dbm;
  318. } else {
  319. power_cfg.is_power_auto = 1;
  320. }
  321. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  322. return mwifiex_set_tx_power(priv, &power_cfg);
  323. }
  324. /*
  325. * CFG802.11 operation handler to get Tx power.
  326. */
  327. static int
  328. mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
  329. struct wireless_dev *wdev,
  330. int *dbm)
  331. {
  332. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  333. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  334. MWIFIEX_BSS_ROLE_ANY);
  335. int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
  336. HostCmd_ACT_GEN_GET, 0, NULL, true);
  337. if (ret < 0)
  338. return ret;
  339. /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
  340. *dbm = priv->tx_power_level;
  341. return 0;
  342. }
  343. /*
  344. * CFG802.11 operation handler to set Power Save option.
  345. *
  346. * The timeout value, if provided, is currently ignored.
  347. */
  348. static int
  349. mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  350. struct net_device *dev,
  351. bool enabled, int timeout)
  352. {
  353. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  354. u32 ps_mode;
  355. if (timeout)
  356. mwifiex_dbg(priv->adapter, INFO,
  357. "info: ignore timeout value for IEEE Power Save\n");
  358. ps_mode = enabled;
  359. return mwifiex_drv_set_power(priv, &ps_mode);
  360. }
  361. /*
  362. * CFG802.11 operation handler to set the default network key.
  363. */
  364. static int
  365. mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
  366. u8 key_index, bool unicast,
  367. bool multicast)
  368. {
  369. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  370. /* Return if WEP key not configured */
  371. if (!priv->sec_info.wep_enabled)
  372. return 0;
  373. if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
  374. priv->wep_key_curr_index = key_index;
  375. } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
  376. NULL, 0)) {
  377. mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
  378. return -EFAULT;
  379. }
  380. return 0;
  381. }
  382. /*
  383. * CFG802.11 operation handler to add a network key.
  384. */
  385. static int
  386. mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
  387. u8 key_index, bool pairwise, const u8 *mac_addr,
  388. struct key_params *params)
  389. {
  390. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  391. struct mwifiex_wep_key *wep_key;
  392. const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  393. const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
  394. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
  395. (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  396. params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
  397. if (params->key && params->key_len) {
  398. wep_key = &priv->wep_key[key_index];
  399. memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
  400. memcpy(wep_key->key_material, params->key,
  401. params->key_len);
  402. wep_key->key_index = key_index;
  403. wep_key->key_length = params->key_len;
  404. priv->sec_info.wep_enabled = 1;
  405. }
  406. return 0;
  407. }
  408. if (mwifiex_set_encode(priv, params, params->key, params->key_len,
  409. key_index, peer_mac, 0)) {
  410. mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
  411. return -EFAULT;
  412. }
  413. return 0;
  414. }
  415. /*
  416. * CFG802.11 operation handler to set default mgmt key.
  417. */
  418. static int
  419. mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
  420. struct net_device *netdev,
  421. u8 key_index)
  422. {
  423. struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
  424. struct mwifiex_ds_encrypt_key encrypt_key;
  425. wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
  426. memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
  427. encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
  428. encrypt_key.key_index = key_index;
  429. encrypt_key.is_igtk_def_key = true;
  430. eth_broadcast_addr(encrypt_key.mac_addr);
  431. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
  432. HostCmd_ACT_GEN_SET, true, &encrypt_key, true);
  433. }
  434. /*
  435. * This function sends domain information to the firmware.
  436. *
  437. * The following information are passed to the firmware -
  438. * - Country codes
  439. * - Sub bands (first channel, number of channels, maximum Tx power)
  440. */
  441. int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
  442. {
  443. u8 no_of_triplet = 0;
  444. struct ieee80211_country_ie_triplet *t;
  445. u8 no_of_parsed_chan = 0;
  446. u8 first_chan = 0, next_chan = 0, max_pwr = 0;
  447. u8 i, flag = 0;
  448. enum nl80211_band band;
  449. struct ieee80211_supported_band *sband;
  450. struct ieee80211_channel *ch;
  451. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  452. struct mwifiex_private *priv;
  453. struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
  454. /* Set country code */
  455. domain_info->country_code[0] = adapter->country_code[0];
  456. domain_info->country_code[1] = adapter->country_code[1];
  457. domain_info->country_code[2] = ' ';
  458. band = mwifiex_band_to_radio_type(adapter->config_bands);
  459. if (!wiphy->bands[band]) {
  460. mwifiex_dbg(adapter, ERROR,
  461. "11D: setting domain info in FW\n");
  462. return -1;
  463. }
  464. sband = wiphy->bands[band];
  465. for (i = 0; i < sband->n_channels ; i++) {
  466. ch = &sband->channels[i];
  467. if (ch->flags & IEEE80211_CHAN_DISABLED)
  468. continue;
  469. if (!flag) {
  470. flag = 1;
  471. first_chan = (u32) ch->hw_value;
  472. next_chan = first_chan;
  473. max_pwr = ch->max_power;
  474. no_of_parsed_chan = 1;
  475. continue;
  476. }
  477. if (ch->hw_value == next_chan + 1 &&
  478. ch->max_power == max_pwr) {
  479. next_chan++;
  480. no_of_parsed_chan++;
  481. } else {
  482. t = &domain_info->triplet[no_of_triplet];
  483. t->chans.first_channel = first_chan;
  484. t->chans.num_channels = no_of_parsed_chan;
  485. t->chans.max_power = max_pwr;
  486. no_of_triplet++;
  487. first_chan = (u32) ch->hw_value;
  488. next_chan = first_chan;
  489. max_pwr = ch->max_power;
  490. no_of_parsed_chan = 1;
  491. }
  492. }
  493. if (flag) {
  494. t = &domain_info->triplet[no_of_triplet];
  495. t->chans.first_channel = first_chan;
  496. t->chans.num_channels = no_of_parsed_chan;
  497. t->chans.max_power = max_pwr;
  498. no_of_triplet++;
  499. }
  500. domain_info->no_of_triplet = no_of_triplet;
  501. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  502. if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
  503. HostCmd_ACT_GEN_SET, 0, NULL, false)) {
  504. mwifiex_dbg(adapter, INFO,
  505. "11D: setting domain info in FW\n");
  506. return -1;
  507. }
  508. return 0;
  509. }
  510. /*
  511. * CFG802.11 regulatory domain callback function.
  512. *
  513. * This function is called when the regulatory domain is changed due to the
  514. * following reasons -
  515. * - Set by driver
  516. * - Set by system core
  517. * - Set by user
  518. * - Set bt Country IE
  519. */
  520. static void mwifiex_reg_notifier(struct wiphy *wiphy,
  521. struct regulatory_request *request)
  522. {
  523. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  524. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  525. MWIFIEX_BSS_ROLE_ANY);
  526. mwifiex_dbg(adapter, INFO,
  527. "info: cfg80211 regulatory domain callback for %c%c\n",
  528. request->alpha2[0], request->alpha2[1]);
  529. switch (request->initiator) {
  530. case NL80211_REGDOM_SET_BY_DRIVER:
  531. case NL80211_REGDOM_SET_BY_CORE:
  532. case NL80211_REGDOM_SET_BY_USER:
  533. case NL80211_REGDOM_SET_BY_COUNTRY_IE:
  534. break;
  535. default:
  536. mwifiex_dbg(adapter, ERROR,
  537. "unknown regdom initiator: %d\n",
  538. request->initiator);
  539. return;
  540. }
  541. /* Don't send world or same regdom info to firmware */
  542. if (strncmp(request->alpha2, "00", 2) &&
  543. strncmp(request->alpha2, adapter->country_code,
  544. sizeof(request->alpha2))) {
  545. memcpy(adapter->country_code, request->alpha2,
  546. sizeof(request->alpha2));
  547. mwifiex_send_domain_info_cmd_fw(wiphy);
  548. mwifiex_dnld_txpwr_table(priv);
  549. }
  550. }
  551. /*
  552. * This function sets the fragmentation threshold.
  553. *
  554. * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
  555. * and MWIFIEX_FRAG_MAX_VALUE.
  556. */
  557. static int
  558. mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
  559. {
  560. if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
  561. frag_thr > MWIFIEX_FRAG_MAX_VALUE)
  562. frag_thr = MWIFIEX_FRAG_MAX_VALUE;
  563. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  564. HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
  565. &frag_thr, true);
  566. }
  567. /*
  568. * This function sets the RTS threshold.
  569. * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
  570. * and MWIFIEX_RTS_MAX_VALUE.
  571. */
  572. static int
  573. mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
  574. {
  575. if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
  576. rts_thr = MWIFIEX_RTS_MAX_VALUE;
  577. return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  578. HostCmd_ACT_GEN_SET, RTS_THRESH_I,
  579. &rts_thr, true);
  580. }
  581. /*
  582. * CFG802.11 operation handler to set wiphy parameters.
  583. *
  584. * This function can be used to set the RTS threshold and the
  585. * Fragmentation threshold of the driver.
  586. */
  587. static int
  588. mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  589. {
  590. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  591. struct mwifiex_private *priv;
  592. struct mwifiex_uap_bss_param *bss_cfg;
  593. int ret;
  594. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  595. switch (priv->bss_role) {
  596. case MWIFIEX_BSS_ROLE_UAP:
  597. if (priv->bss_started) {
  598. mwifiex_dbg(adapter, ERROR,
  599. "cannot change wiphy params when bss started");
  600. return -EINVAL;
  601. }
  602. bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
  603. if (!bss_cfg)
  604. return -ENOMEM;
  605. mwifiex_set_sys_config_invalid_data(bss_cfg);
  606. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  607. bss_cfg->rts_threshold = wiphy->rts_threshold;
  608. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  609. bss_cfg->frag_threshold = wiphy->frag_threshold;
  610. if (changed & WIPHY_PARAM_RETRY_LONG)
  611. bss_cfg->retry_limit = wiphy->retry_long;
  612. ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  613. HostCmd_ACT_GEN_SET,
  614. UAP_BSS_PARAMS_I, bss_cfg,
  615. false);
  616. kfree(bss_cfg);
  617. if (ret) {
  618. mwifiex_dbg(adapter, ERROR,
  619. "Failed to set wiphy phy params\n");
  620. return ret;
  621. }
  622. break;
  623. case MWIFIEX_BSS_ROLE_STA:
  624. if (priv->media_connected) {
  625. mwifiex_dbg(adapter, ERROR,
  626. "cannot change wiphy params when connected");
  627. return -EINVAL;
  628. }
  629. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  630. ret = mwifiex_set_rts(priv,
  631. wiphy->rts_threshold);
  632. if (ret)
  633. return ret;
  634. }
  635. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  636. ret = mwifiex_set_frag(priv,
  637. wiphy->frag_threshold);
  638. if (ret)
  639. return ret;
  640. }
  641. break;
  642. }
  643. return 0;
  644. }
  645. static int
  646. mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
  647. {
  648. u16 mode = P2P_MODE_DISABLE;
  649. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  650. HostCmd_ACT_GEN_SET, 0, &mode, true))
  651. return -1;
  652. return 0;
  653. }
  654. /*
  655. * This function initializes the functionalities for P2P client.
  656. * The P2P client initialization sequence is:
  657. * disable -> device -> client
  658. */
  659. static int
  660. mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
  661. {
  662. u16 mode;
  663. if (mwifiex_cfg80211_deinit_p2p(priv))
  664. return -1;
  665. mode = P2P_MODE_DEVICE;
  666. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  667. HostCmd_ACT_GEN_SET, 0, &mode, true))
  668. return -1;
  669. mode = P2P_MODE_CLIENT;
  670. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  671. HostCmd_ACT_GEN_SET, 0, &mode, true))
  672. return -1;
  673. return 0;
  674. }
  675. /*
  676. * This function initializes the functionalities for P2P GO.
  677. * The P2P GO initialization sequence is:
  678. * disable -> device -> GO
  679. */
  680. static int
  681. mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
  682. {
  683. u16 mode;
  684. if (mwifiex_cfg80211_deinit_p2p(priv))
  685. return -1;
  686. mode = P2P_MODE_DEVICE;
  687. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  688. HostCmd_ACT_GEN_SET, 0, &mode, true))
  689. return -1;
  690. mode = P2P_MODE_GO;
  691. if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
  692. HostCmd_ACT_GEN_SET, 0, &mode, true))
  693. return -1;
  694. return 0;
  695. }
  696. static int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
  697. {
  698. struct mwifiex_adapter *adapter = priv->adapter;
  699. unsigned long flags;
  700. priv->mgmt_frame_mask = 0;
  701. if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
  702. HostCmd_ACT_GEN_SET, 0,
  703. &priv->mgmt_frame_mask, false)) {
  704. mwifiex_dbg(adapter, ERROR,
  705. "could not unregister mgmt frame rx\n");
  706. return -1;
  707. }
  708. mwifiex_deauthenticate(priv, NULL);
  709. spin_lock_irqsave(&adapter->main_proc_lock, flags);
  710. adapter->main_locked = true;
  711. if (adapter->mwifiex_processing) {
  712. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  713. flush_workqueue(adapter->workqueue);
  714. } else {
  715. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  716. }
  717. spin_lock_irqsave(&adapter->rx_proc_lock, flags);
  718. adapter->rx_locked = true;
  719. if (adapter->rx_processing) {
  720. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  721. flush_workqueue(adapter->rx_workqueue);
  722. } else {
  723. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  724. }
  725. mwifiex_free_priv(priv);
  726. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  727. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  728. priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
  729. return 0;
  730. }
  731. static int
  732. mwifiex_init_new_priv_params(struct mwifiex_private *priv,
  733. struct net_device *dev,
  734. enum nl80211_iftype type)
  735. {
  736. struct mwifiex_adapter *adapter = priv->adapter;
  737. unsigned long flags;
  738. mwifiex_init_priv(priv);
  739. priv->bss_mode = type;
  740. priv->wdev.iftype = type;
  741. mwifiex_init_priv_params(priv, priv->netdev);
  742. priv->bss_started = 0;
  743. switch (type) {
  744. case NL80211_IFTYPE_STATION:
  745. case NL80211_IFTYPE_ADHOC:
  746. priv->bss_num = mwifiex_get_unused_bss_num(adapter,
  747. MWIFIEX_BSS_TYPE_STA);
  748. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  749. priv->bss_type = MWIFIEX_BSS_TYPE_STA;
  750. break;
  751. case NL80211_IFTYPE_P2P_CLIENT:
  752. priv->bss_num = mwifiex_get_unused_bss_num(adapter,
  753. MWIFIEX_BSS_TYPE_P2P);
  754. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  755. priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
  756. break;
  757. case NL80211_IFTYPE_P2P_GO:
  758. priv->bss_num = mwifiex_get_unused_bss_num(adapter,
  759. MWIFIEX_BSS_TYPE_P2P);
  760. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  761. priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
  762. break;
  763. case NL80211_IFTYPE_AP:
  764. priv->bss_num = mwifiex_get_unused_bss_num(adapter,
  765. MWIFIEX_BSS_TYPE_UAP);
  766. priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
  767. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  768. break;
  769. default:
  770. mwifiex_dbg(adapter, ERROR,
  771. "%s: changing to %d not supported\n",
  772. dev->name, type);
  773. return -EOPNOTSUPP;
  774. }
  775. spin_lock_irqsave(&adapter->main_proc_lock, flags);
  776. adapter->main_locked = false;
  777. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  778. spin_lock_irqsave(&adapter->rx_proc_lock, flags);
  779. adapter->rx_locked = false;
  780. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  781. return 0;
  782. }
  783. static int
  784. mwifiex_change_vif_to_p2p(struct net_device *dev,
  785. enum nl80211_iftype curr_iftype,
  786. enum nl80211_iftype type, u32 *flags,
  787. struct vif_params *params)
  788. {
  789. struct mwifiex_private *priv;
  790. struct mwifiex_adapter *adapter;
  791. priv = mwifiex_netdev_get_priv(dev);
  792. if (!priv)
  793. return -1;
  794. adapter = priv->adapter;
  795. if (adapter->curr_iface_comb.p2p_intf ==
  796. adapter->iface_limit.p2p_intf) {
  797. mwifiex_dbg(adapter, ERROR,
  798. "cannot create multiple P2P ifaces\n");
  799. return -1;
  800. }
  801. mwifiex_dbg(adapter, INFO,
  802. "%s: changing role to p2p\n", dev->name);
  803. if (mwifiex_deinit_priv_params(priv))
  804. return -1;
  805. if (mwifiex_init_new_priv_params(priv, dev, type))
  806. return -1;
  807. switch (type) {
  808. case NL80211_IFTYPE_P2P_CLIENT:
  809. if (mwifiex_cfg80211_init_p2p_client(priv))
  810. return -EFAULT;
  811. break;
  812. case NL80211_IFTYPE_P2P_GO:
  813. if (mwifiex_cfg80211_init_p2p_go(priv))
  814. return -EFAULT;
  815. break;
  816. default:
  817. mwifiex_dbg(adapter, ERROR,
  818. "%s: changing to %d not supported\n",
  819. dev->name, type);
  820. return -EOPNOTSUPP;
  821. }
  822. if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  823. HostCmd_ACT_GEN_SET, 0, NULL, true))
  824. return -1;
  825. if (mwifiex_sta_init_cmd(priv, false, false))
  826. return -1;
  827. switch (curr_iftype) {
  828. case NL80211_IFTYPE_STATION:
  829. case NL80211_IFTYPE_ADHOC:
  830. adapter->curr_iface_comb.sta_intf--;
  831. break;
  832. case NL80211_IFTYPE_AP:
  833. adapter->curr_iface_comb.uap_intf--;
  834. break;
  835. default:
  836. break;
  837. }
  838. adapter->curr_iface_comb.p2p_intf++;
  839. dev->ieee80211_ptr->iftype = type;
  840. return 0;
  841. }
  842. static int
  843. mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
  844. enum nl80211_iftype curr_iftype,
  845. enum nl80211_iftype type, u32 *flags,
  846. struct vif_params *params)
  847. {
  848. struct mwifiex_private *priv;
  849. struct mwifiex_adapter *adapter;
  850. priv = mwifiex_netdev_get_priv(dev);
  851. if (!priv)
  852. return -1;
  853. adapter = priv->adapter;
  854. if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
  855. curr_iftype != NL80211_IFTYPE_P2P_GO) &&
  856. (adapter->curr_iface_comb.sta_intf ==
  857. adapter->iface_limit.sta_intf)) {
  858. mwifiex_dbg(adapter, ERROR,
  859. "cannot create multiple station/adhoc ifaces\n");
  860. return -1;
  861. }
  862. if (type == NL80211_IFTYPE_STATION)
  863. mwifiex_dbg(adapter, INFO,
  864. "%s: changing role to station\n", dev->name);
  865. else
  866. mwifiex_dbg(adapter, INFO,
  867. "%s: changing role to adhoc\n", dev->name);
  868. if (mwifiex_deinit_priv_params(priv))
  869. return -1;
  870. if (mwifiex_init_new_priv_params(priv, dev, type))
  871. return -1;
  872. if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  873. HostCmd_ACT_GEN_SET, 0, NULL, true))
  874. return -1;
  875. if (mwifiex_sta_init_cmd(priv, false, false))
  876. return -1;
  877. switch (curr_iftype) {
  878. case NL80211_IFTYPE_P2P_CLIENT:
  879. case NL80211_IFTYPE_P2P_GO:
  880. adapter->curr_iface_comb.p2p_intf--;
  881. break;
  882. case NL80211_IFTYPE_AP:
  883. adapter->curr_iface_comb.uap_intf--;
  884. break;
  885. default:
  886. break;
  887. }
  888. adapter->curr_iface_comb.sta_intf++;
  889. dev->ieee80211_ptr->iftype = type;
  890. return 0;
  891. }
  892. static int
  893. mwifiex_change_vif_to_ap(struct net_device *dev,
  894. enum nl80211_iftype curr_iftype,
  895. enum nl80211_iftype type, u32 *flags,
  896. struct vif_params *params)
  897. {
  898. struct mwifiex_private *priv;
  899. struct mwifiex_adapter *adapter;
  900. priv = mwifiex_netdev_get_priv(dev);
  901. if (!priv)
  902. return -1;
  903. adapter = priv->adapter;
  904. if (adapter->curr_iface_comb.uap_intf ==
  905. adapter->iface_limit.uap_intf) {
  906. mwifiex_dbg(adapter, ERROR,
  907. "cannot create multiple AP ifaces\n");
  908. return -1;
  909. }
  910. mwifiex_dbg(adapter, INFO,
  911. "%s: changing role to AP\n", dev->name);
  912. if (mwifiex_deinit_priv_params(priv))
  913. return -1;
  914. if (mwifiex_init_new_priv_params(priv, dev, type))
  915. return -1;
  916. if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  917. HostCmd_ACT_GEN_SET, 0, NULL, true))
  918. return -1;
  919. if (mwifiex_sta_init_cmd(priv, false, false))
  920. return -1;
  921. switch (curr_iftype) {
  922. case NL80211_IFTYPE_P2P_CLIENT:
  923. case NL80211_IFTYPE_P2P_GO:
  924. adapter->curr_iface_comb.p2p_intf--;
  925. break;
  926. case NL80211_IFTYPE_STATION:
  927. case NL80211_IFTYPE_ADHOC:
  928. adapter->curr_iface_comb.sta_intf--;
  929. break;
  930. default:
  931. break;
  932. }
  933. adapter->curr_iface_comb.uap_intf++;
  934. dev->ieee80211_ptr->iftype = type;
  935. return 0;
  936. }
  937. /*
  938. * CFG802.11 operation handler to change interface type.
  939. */
  940. static int
  941. mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
  942. struct net_device *dev,
  943. enum nl80211_iftype type, u32 *flags,
  944. struct vif_params *params)
  945. {
  946. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  947. enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
  948. if (priv->scan_request) {
  949. mwifiex_dbg(priv->adapter, ERROR,
  950. "change virtual interface: scan in process\n");
  951. return -EBUSY;
  952. }
  953. switch (curr_iftype) {
  954. case NL80211_IFTYPE_ADHOC:
  955. switch (type) {
  956. case NL80211_IFTYPE_STATION:
  957. priv->bss_mode = type;
  958. priv->sec_info.authentication_mode =
  959. NL80211_AUTHTYPE_OPEN_SYSTEM;
  960. dev->ieee80211_ptr->iftype = type;
  961. mwifiex_deauthenticate(priv, NULL);
  962. return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  963. HostCmd_ACT_GEN_SET, 0, NULL,
  964. true);
  965. case NL80211_IFTYPE_P2P_CLIENT:
  966. case NL80211_IFTYPE_P2P_GO:
  967. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  968. type, flags, params);
  969. case NL80211_IFTYPE_AP:
  970. return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
  971. flags, params);
  972. case NL80211_IFTYPE_UNSPECIFIED:
  973. mwifiex_dbg(priv->adapter, INFO,
  974. "%s: kept type as IBSS\n", dev->name);
  975. case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */
  976. return 0;
  977. default:
  978. mwifiex_dbg(priv->adapter, ERROR,
  979. "%s: changing to %d not supported\n",
  980. dev->name, type);
  981. return -EOPNOTSUPP;
  982. }
  983. break;
  984. case NL80211_IFTYPE_STATION:
  985. switch (type) {
  986. case NL80211_IFTYPE_ADHOC:
  987. priv->bss_mode = type;
  988. priv->sec_info.authentication_mode =
  989. NL80211_AUTHTYPE_OPEN_SYSTEM;
  990. dev->ieee80211_ptr->iftype = type;
  991. mwifiex_deauthenticate(priv, NULL);
  992. return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  993. HostCmd_ACT_GEN_SET, 0, NULL,
  994. true);
  995. case NL80211_IFTYPE_P2P_CLIENT:
  996. case NL80211_IFTYPE_P2P_GO:
  997. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  998. type, flags, params);
  999. case NL80211_IFTYPE_AP:
  1000. return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
  1001. flags, params);
  1002. case NL80211_IFTYPE_UNSPECIFIED:
  1003. mwifiex_dbg(priv->adapter, INFO,
  1004. "%s: kept type as STA\n", dev->name);
  1005. case NL80211_IFTYPE_STATION: /* This shouldn't happen */
  1006. return 0;
  1007. default:
  1008. mwifiex_dbg(priv->adapter, ERROR,
  1009. "%s: changing to %d not supported\n",
  1010. dev->name, type);
  1011. return -EOPNOTSUPP;
  1012. }
  1013. break;
  1014. case NL80211_IFTYPE_AP:
  1015. switch (type) {
  1016. case NL80211_IFTYPE_ADHOC:
  1017. case NL80211_IFTYPE_STATION:
  1018. return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
  1019. type, flags,
  1020. params);
  1021. break;
  1022. case NL80211_IFTYPE_P2P_CLIENT:
  1023. case NL80211_IFTYPE_P2P_GO:
  1024. return mwifiex_change_vif_to_p2p(dev, curr_iftype,
  1025. type, flags, params);
  1026. case NL80211_IFTYPE_UNSPECIFIED:
  1027. mwifiex_dbg(priv->adapter, INFO,
  1028. "%s: kept type as AP\n", dev->name);
  1029. case NL80211_IFTYPE_AP: /* This shouldn't happen */
  1030. return 0;
  1031. default:
  1032. mwifiex_dbg(priv->adapter, ERROR,
  1033. "%s: changing to %d not supported\n",
  1034. dev->name, type);
  1035. return -EOPNOTSUPP;
  1036. }
  1037. break;
  1038. case NL80211_IFTYPE_P2P_CLIENT:
  1039. case NL80211_IFTYPE_P2P_GO:
  1040. switch (type) {
  1041. case NL80211_IFTYPE_STATION:
  1042. if (mwifiex_cfg80211_deinit_p2p(priv))
  1043. return -EFAULT;
  1044. priv->adapter->curr_iface_comb.p2p_intf--;
  1045. priv->adapter->curr_iface_comb.sta_intf++;
  1046. dev->ieee80211_ptr->iftype = type;
  1047. break;
  1048. case NL80211_IFTYPE_ADHOC:
  1049. if (mwifiex_cfg80211_deinit_p2p(priv))
  1050. return -EFAULT;
  1051. return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
  1052. type, flags,
  1053. params);
  1054. break;
  1055. case NL80211_IFTYPE_AP:
  1056. if (mwifiex_cfg80211_deinit_p2p(priv))
  1057. return -EFAULT;
  1058. return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
  1059. flags, params);
  1060. case NL80211_IFTYPE_UNSPECIFIED:
  1061. mwifiex_dbg(priv->adapter, INFO,
  1062. "%s: kept type as P2P\n", dev->name);
  1063. case NL80211_IFTYPE_P2P_CLIENT:
  1064. case NL80211_IFTYPE_P2P_GO:
  1065. return 0;
  1066. default:
  1067. mwifiex_dbg(priv->adapter, ERROR,
  1068. "%s: changing to %d not supported\n",
  1069. dev->name, type);
  1070. return -EOPNOTSUPP;
  1071. }
  1072. break;
  1073. default:
  1074. mwifiex_dbg(priv->adapter, ERROR,
  1075. "%s: unknown iftype: %d\n",
  1076. dev->name, dev->ieee80211_ptr->iftype);
  1077. return -EOPNOTSUPP;
  1078. }
  1079. return 0;
  1080. }
  1081. static void
  1082. mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 tx_htinfo,
  1083. struct rate_info *rate)
  1084. {
  1085. struct mwifiex_adapter *adapter = priv->adapter;
  1086. if (adapter->is_hw_11ac_capable) {
  1087. /* bit[1-0]: 00=LG 01=HT 10=VHT */
  1088. if (tx_htinfo & BIT(0)) {
  1089. /* HT */
  1090. rate->mcs = priv->tx_rate;
  1091. rate->flags |= RATE_INFO_FLAGS_MCS;
  1092. }
  1093. if (tx_htinfo & BIT(1)) {
  1094. /* VHT */
  1095. rate->mcs = priv->tx_rate & 0x0F;
  1096. rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
  1097. }
  1098. if (tx_htinfo & (BIT(1) | BIT(0))) {
  1099. /* HT or VHT */
  1100. switch (tx_htinfo & (BIT(3) | BIT(2))) {
  1101. case 0:
  1102. rate->bw = RATE_INFO_BW_20;
  1103. break;
  1104. case (BIT(2)):
  1105. rate->bw = RATE_INFO_BW_40;
  1106. break;
  1107. case (BIT(3)):
  1108. rate->bw = RATE_INFO_BW_80;
  1109. break;
  1110. case (BIT(3) | BIT(2)):
  1111. rate->bw = RATE_INFO_BW_160;
  1112. break;
  1113. }
  1114. if (tx_htinfo & BIT(4))
  1115. rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
  1116. if ((priv->tx_rate >> 4) == 1)
  1117. rate->nss = 2;
  1118. else
  1119. rate->nss = 1;
  1120. }
  1121. } else {
  1122. /*
  1123. * Bit 0 in tx_htinfo indicates that current Tx rate
  1124. * is 11n rate. Valid MCS index values for us are 0 to 15.
  1125. */
  1126. if ((tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
  1127. rate->mcs = priv->tx_rate;
  1128. rate->flags |= RATE_INFO_FLAGS_MCS;
  1129. rate->bw = RATE_INFO_BW_20;
  1130. if (tx_htinfo & BIT(1))
  1131. rate->bw = RATE_INFO_BW_40;
  1132. if (tx_htinfo & BIT(2))
  1133. rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
  1134. }
  1135. }
  1136. }
  1137. /*
  1138. * This function dumps the station information on a buffer.
  1139. *
  1140. * The following information are shown -
  1141. * - Total bytes transmitted
  1142. * - Total bytes received
  1143. * - Total packets transmitted
  1144. * - Total packets received
  1145. * - Signal quality level
  1146. * - Transmission rate
  1147. */
  1148. static int
  1149. mwifiex_dump_station_info(struct mwifiex_private *priv,
  1150. struct mwifiex_sta_node *node,
  1151. struct station_info *sinfo)
  1152. {
  1153. u32 rate;
  1154. sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) | BIT(NL80211_STA_INFO_TX_BYTES) |
  1155. BIT(NL80211_STA_INFO_RX_PACKETS) | BIT(NL80211_STA_INFO_TX_PACKETS) |
  1156. BIT(NL80211_STA_INFO_TX_BITRATE) |
  1157. BIT(NL80211_STA_INFO_SIGNAL) | BIT(NL80211_STA_INFO_SIGNAL_AVG);
  1158. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  1159. if (!node)
  1160. return -ENOENT;
  1161. sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
  1162. BIT(NL80211_STA_INFO_TX_FAILED);
  1163. sinfo->inactive_time =
  1164. jiffies_to_msecs(jiffies - node->stats.last_rx);
  1165. sinfo->signal = node->stats.rssi;
  1166. sinfo->signal_avg = node->stats.rssi;
  1167. sinfo->rx_bytes = node->stats.rx_bytes;
  1168. sinfo->tx_bytes = node->stats.tx_bytes;
  1169. sinfo->rx_packets = node->stats.rx_packets;
  1170. sinfo->tx_packets = node->stats.tx_packets;
  1171. sinfo->tx_failed = node->stats.tx_failed;
  1172. mwifiex_parse_htinfo(priv, node->stats.last_tx_htinfo,
  1173. &sinfo->txrate);
  1174. sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
  1175. return 0;
  1176. }
  1177. /* Get signal information from the firmware */
  1178. if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
  1179. HostCmd_ACT_GEN_GET, 0, NULL, true)) {
  1180. mwifiex_dbg(priv->adapter, ERROR,
  1181. "failed to get signal information\n");
  1182. return -EFAULT;
  1183. }
  1184. if (mwifiex_drv_get_data_rate(priv, &rate)) {
  1185. mwifiex_dbg(priv->adapter, ERROR,
  1186. "getting data rate error\n");
  1187. return -EFAULT;
  1188. }
  1189. /* Get DTIM period information from firmware */
  1190. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  1191. HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
  1192. &priv->dtim_period, true);
  1193. mwifiex_parse_htinfo(priv, priv->tx_htinfo, &sinfo->txrate);
  1194. sinfo->signal_avg = priv->bcn_rssi_avg;
  1195. sinfo->rx_bytes = priv->stats.rx_bytes;
  1196. sinfo->tx_bytes = priv->stats.tx_bytes;
  1197. sinfo->rx_packets = priv->stats.rx_packets;
  1198. sinfo->tx_packets = priv->stats.tx_packets;
  1199. sinfo->signal = priv->bcn_rssi_avg;
  1200. /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
  1201. sinfo->txrate.legacy = rate * 5;
  1202. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  1203. sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
  1204. sinfo->bss_param.flags = 0;
  1205. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  1206. WLAN_CAPABILITY_SHORT_PREAMBLE)
  1207. sinfo->bss_param.flags |=
  1208. BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  1209. if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
  1210. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  1211. sinfo->bss_param.flags |=
  1212. BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  1213. sinfo->bss_param.dtim_period = priv->dtim_period;
  1214. sinfo->bss_param.beacon_interval =
  1215. priv->curr_bss_params.bss_descriptor.beacon_period;
  1216. }
  1217. return 0;
  1218. }
  1219. /*
  1220. * CFG802.11 operation handler to get station information.
  1221. *
  1222. * This function only works in connected mode, and dumps the
  1223. * requested station information, if available.
  1224. */
  1225. static int
  1226. mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  1227. const u8 *mac, struct station_info *sinfo)
  1228. {
  1229. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1230. if (!priv->media_connected)
  1231. return -ENOENT;
  1232. if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
  1233. return -ENOENT;
  1234. return mwifiex_dump_station_info(priv, NULL, sinfo);
  1235. }
  1236. /*
  1237. * CFG802.11 operation handler to dump station information.
  1238. */
  1239. static int
  1240. mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  1241. int idx, u8 *mac, struct station_info *sinfo)
  1242. {
  1243. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1244. static struct mwifiex_sta_node *node;
  1245. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  1246. priv->media_connected && idx == 0) {
  1247. ether_addr_copy(mac, priv->cfg_bssid);
  1248. return mwifiex_dump_station_info(priv, NULL, sinfo);
  1249. } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  1250. mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
  1251. HostCmd_ACT_GEN_GET, 0, NULL, true);
  1252. if (node && (&node->list == &priv->sta_list)) {
  1253. node = NULL;
  1254. return -ENOENT;
  1255. }
  1256. node = list_prepare_entry(node, &priv->sta_list, list);
  1257. list_for_each_entry_continue(node, &priv->sta_list, list) {
  1258. ether_addr_copy(mac, node->mac_addr);
  1259. return mwifiex_dump_station_info(priv, node, sinfo);
  1260. }
  1261. }
  1262. return -ENOENT;
  1263. }
  1264. static int
  1265. mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  1266. int idx, struct survey_info *survey)
  1267. {
  1268. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1269. struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
  1270. enum nl80211_band band;
  1271. mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
  1272. memset(survey, 0, sizeof(struct survey_info));
  1273. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  1274. priv->media_connected && idx == 0) {
  1275. u8 curr_bss_band = priv->curr_bss_params.band;
  1276. u32 chan = priv->curr_bss_params.bss_descriptor.channel;
  1277. band = mwifiex_band_to_radio_type(curr_bss_band);
  1278. survey->channel = ieee80211_get_channel(wiphy,
  1279. ieee80211_channel_to_frequency(chan, band));
  1280. if (priv->bcn_nf_last) {
  1281. survey->filled = SURVEY_INFO_NOISE_DBM;
  1282. survey->noise = priv->bcn_nf_last;
  1283. }
  1284. return 0;
  1285. }
  1286. if (idx >= priv->adapter->num_in_chan_stats)
  1287. return -ENOENT;
  1288. if (!pchan_stats[idx].cca_scan_dur)
  1289. return 0;
  1290. band = pchan_stats[idx].bandcfg;
  1291. survey->channel = ieee80211_get_channel(wiphy,
  1292. ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
  1293. survey->filled = SURVEY_INFO_NOISE_DBM |
  1294. SURVEY_INFO_TIME |
  1295. SURVEY_INFO_TIME_BUSY;
  1296. survey->noise = pchan_stats[idx].noise;
  1297. survey->time = pchan_stats[idx].cca_scan_dur;
  1298. survey->time_busy = pchan_stats[idx].cca_busy_dur;
  1299. return 0;
  1300. }
  1301. /* Supported rates to be advertised to the cfg80211 */
  1302. static struct ieee80211_rate mwifiex_rates[] = {
  1303. {.bitrate = 10, .hw_value = 2, },
  1304. {.bitrate = 20, .hw_value = 4, },
  1305. {.bitrate = 55, .hw_value = 11, },
  1306. {.bitrate = 110, .hw_value = 22, },
  1307. {.bitrate = 60, .hw_value = 12, },
  1308. {.bitrate = 90, .hw_value = 18, },
  1309. {.bitrate = 120, .hw_value = 24, },
  1310. {.bitrate = 180, .hw_value = 36, },
  1311. {.bitrate = 240, .hw_value = 48, },
  1312. {.bitrate = 360, .hw_value = 72, },
  1313. {.bitrate = 480, .hw_value = 96, },
  1314. {.bitrate = 540, .hw_value = 108, },
  1315. };
  1316. /* Channel definitions to be advertised to cfg80211 */
  1317. static struct ieee80211_channel mwifiex_channels_2ghz[] = {
  1318. {.center_freq = 2412, .hw_value = 1, },
  1319. {.center_freq = 2417, .hw_value = 2, },
  1320. {.center_freq = 2422, .hw_value = 3, },
  1321. {.center_freq = 2427, .hw_value = 4, },
  1322. {.center_freq = 2432, .hw_value = 5, },
  1323. {.center_freq = 2437, .hw_value = 6, },
  1324. {.center_freq = 2442, .hw_value = 7, },
  1325. {.center_freq = 2447, .hw_value = 8, },
  1326. {.center_freq = 2452, .hw_value = 9, },
  1327. {.center_freq = 2457, .hw_value = 10, },
  1328. {.center_freq = 2462, .hw_value = 11, },
  1329. {.center_freq = 2467, .hw_value = 12, },
  1330. {.center_freq = 2472, .hw_value = 13, },
  1331. {.center_freq = 2484, .hw_value = 14, },
  1332. };
  1333. static struct ieee80211_supported_band mwifiex_band_2ghz = {
  1334. .channels = mwifiex_channels_2ghz,
  1335. .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
  1336. .bitrates = mwifiex_rates,
  1337. .n_bitrates = ARRAY_SIZE(mwifiex_rates),
  1338. };
  1339. static struct ieee80211_channel mwifiex_channels_5ghz[] = {
  1340. {.center_freq = 5040, .hw_value = 8, },
  1341. {.center_freq = 5060, .hw_value = 12, },
  1342. {.center_freq = 5080, .hw_value = 16, },
  1343. {.center_freq = 5170, .hw_value = 34, },
  1344. {.center_freq = 5190, .hw_value = 38, },
  1345. {.center_freq = 5210, .hw_value = 42, },
  1346. {.center_freq = 5230, .hw_value = 46, },
  1347. {.center_freq = 5180, .hw_value = 36, },
  1348. {.center_freq = 5200, .hw_value = 40, },
  1349. {.center_freq = 5220, .hw_value = 44, },
  1350. {.center_freq = 5240, .hw_value = 48, },
  1351. {.center_freq = 5260, .hw_value = 52, },
  1352. {.center_freq = 5280, .hw_value = 56, },
  1353. {.center_freq = 5300, .hw_value = 60, },
  1354. {.center_freq = 5320, .hw_value = 64, },
  1355. {.center_freq = 5500, .hw_value = 100, },
  1356. {.center_freq = 5520, .hw_value = 104, },
  1357. {.center_freq = 5540, .hw_value = 108, },
  1358. {.center_freq = 5560, .hw_value = 112, },
  1359. {.center_freq = 5580, .hw_value = 116, },
  1360. {.center_freq = 5600, .hw_value = 120, },
  1361. {.center_freq = 5620, .hw_value = 124, },
  1362. {.center_freq = 5640, .hw_value = 128, },
  1363. {.center_freq = 5660, .hw_value = 132, },
  1364. {.center_freq = 5680, .hw_value = 136, },
  1365. {.center_freq = 5700, .hw_value = 140, },
  1366. {.center_freq = 5745, .hw_value = 149, },
  1367. {.center_freq = 5765, .hw_value = 153, },
  1368. {.center_freq = 5785, .hw_value = 157, },
  1369. {.center_freq = 5805, .hw_value = 161, },
  1370. {.center_freq = 5825, .hw_value = 165, },
  1371. };
  1372. static struct ieee80211_supported_band mwifiex_band_5ghz = {
  1373. .channels = mwifiex_channels_5ghz,
  1374. .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
  1375. .bitrates = mwifiex_rates + 4,
  1376. .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
  1377. };
  1378. /* Supported crypto cipher suits to be advertised to cfg80211 */
  1379. static const u32 mwifiex_cipher_suites[] = {
  1380. WLAN_CIPHER_SUITE_WEP40,
  1381. WLAN_CIPHER_SUITE_WEP104,
  1382. WLAN_CIPHER_SUITE_TKIP,
  1383. WLAN_CIPHER_SUITE_CCMP,
  1384. WLAN_CIPHER_SUITE_SMS4,
  1385. WLAN_CIPHER_SUITE_AES_CMAC,
  1386. };
  1387. /* Supported mgmt frame types to be advertised to cfg80211 */
  1388. static const struct ieee80211_txrx_stypes
  1389. mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  1390. [NL80211_IFTYPE_STATION] = {
  1391. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1392. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1393. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1394. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1395. },
  1396. [NL80211_IFTYPE_AP] = {
  1397. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1398. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1399. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1400. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1401. },
  1402. [NL80211_IFTYPE_P2P_CLIENT] = {
  1403. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1404. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1405. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1406. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1407. },
  1408. [NL80211_IFTYPE_P2P_GO] = {
  1409. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1410. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  1411. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  1412. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  1413. },
  1414. };
  1415. /*
  1416. * CFG802.11 operation handler for setting bit rates.
  1417. *
  1418. * Function configures data rates to firmware using bitrate mask
  1419. * provided by cfg80211.
  1420. */
  1421. static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
  1422. struct net_device *dev,
  1423. const u8 *peer,
  1424. const struct cfg80211_bitrate_mask *mask)
  1425. {
  1426. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1427. u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
  1428. enum nl80211_band band;
  1429. struct mwifiex_adapter *adapter = priv->adapter;
  1430. if (!priv->media_connected) {
  1431. mwifiex_dbg(adapter, ERROR,
  1432. "Can not set Tx data rate in disconnected state\n");
  1433. return -EINVAL;
  1434. }
  1435. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  1436. memset(bitmap_rates, 0, sizeof(bitmap_rates));
  1437. /* Fill HR/DSSS rates. */
  1438. if (band == NL80211_BAND_2GHZ)
  1439. bitmap_rates[0] = mask->control[band].legacy & 0x000f;
  1440. /* Fill OFDM rates */
  1441. if (band == NL80211_BAND_2GHZ)
  1442. bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
  1443. else
  1444. bitmap_rates[1] = mask->control[band].legacy;
  1445. /* Fill HT MCS rates */
  1446. bitmap_rates[2] = mask->control[band].ht_mcs[0];
  1447. if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  1448. bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
  1449. /* Fill VHT MCS rates */
  1450. if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
  1451. bitmap_rates[10] = mask->control[band].vht_mcs[0];
  1452. if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
  1453. bitmap_rates[11] = mask->control[band].vht_mcs[1];
  1454. }
  1455. return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
  1456. HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
  1457. }
  1458. /*
  1459. * CFG802.11 operation handler for connection quality monitoring.
  1460. *
  1461. * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
  1462. * events to FW.
  1463. */
  1464. static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1465. struct net_device *dev,
  1466. s32 rssi_thold, u32 rssi_hyst)
  1467. {
  1468. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1469. struct mwifiex_ds_misc_subsc_evt subsc_evt;
  1470. priv->cqm_rssi_thold = rssi_thold;
  1471. priv->cqm_rssi_hyst = rssi_hyst;
  1472. memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
  1473. subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
  1474. /* Subscribe/unsubscribe low and high rssi events */
  1475. if (rssi_thold && rssi_hyst) {
  1476. subsc_evt.action = HostCmd_ACT_BITWISE_SET;
  1477. subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
  1478. subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
  1479. subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
  1480. subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
  1481. return mwifiex_send_cmd(priv,
  1482. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  1483. 0, 0, &subsc_evt, true);
  1484. } else {
  1485. subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
  1486. return mwifiex_send_cmd(priv,
  1487. HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
  1488. 0, 0, &subsc_evt, true);
  1489. }
  1490. return 0;
  1491. }
  1492. /* cfg80211 operation handler for change_beacon.
  1493. * Function retrieves and sets modified management IEs to FW.
  1494. */
  1495. static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
  1496. struct net_device *dev,
  1497. struct cfg80211_beacon_data *data)
  1498. {
  1499. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1500. struct mwifiex_adapter *adapter = priv->adapter;
  1501. mwifiex_cancel_scan(adapter);
  1502. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
  1503. mwifiex_dbg(priv->adapter, ERROR,
  1504. "%s: bss_type mismatched\n", __func__);
  1505. return -EINVAL;
  1506. }
  1507. if (!priv->bss_started) {
  1508. mwifiex_dbg(priv->adapter, ERROR,
  1509. "%s: bss not started\n", __func__);
  1510. return -EINVAL;
  1511. }
  1512. if (mwifiex_set_mgmt_ies(priv, data)) {
  1513. mwifiex_dbg(priv->adapter, ERROR,
  1514. "%s: setting mgmt ies failed\n", __func__);
  1515. return -EFAULT;
  1516. }
  1517. return 0;
  1518. }
  1519. /* cfg80211 operation handler for del_station.
  1520. * Function deauthenticates station which value is provided in mac parameter.
  1521. * If mac is NULL/broadcast, all stations in associated station list are
  1522. * deauthenticated. If bss is not started or there are no stations in
  1523. * associated stations list, no action is taken.
  1524. */
  1525. static int
  1526. mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1527. struct station_del_parameters *params)
  1528. {
  1529. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1530. struct mwifiex_sta_node *sta_node;
  1531. u8 deauth_mac[ETH_ALEN];
  1532. unsigned long flags;
  1533. if (!priv->bss_started && priv->wdev.cac_started) {
  1534. mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
  1535. mwifiex_abort_cac(priv);
  1536. }
  1537. if (list_empty(&priv->sta_list) || !priv->bss_started)
  1538. return 0;
  1539. if (!params->mac || is_broadcast_ether_addr(params->mac))
  1540. return 0;
  1541. mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
  1542. __func__, params->mac);
  1543. eth_zero_addr(deauth_mac);
  1544. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  1545. sta_node = mwifiex_get_sta_entry(priv, params->mac);
  1546. if (sta_node)
  1547. ether_addr_copy(deauth_mac, params->mac);
  1548. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  1549. if (is_valid_ether_addr(deauth_mac)) {
  1550. if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
  1551. HostCmd_ACT_GEN_SET, 0,
  1552. deauth_mac, true))
  1553. return -1;
  1554. }
  1555. return 0;
  1556. }
  1557. static int
  1558. mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1559. {
  1560. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  1561. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  1562. MWIFIEX_BSS_ROLE_ANY);
  1563. struct mwifiex_ds_ant_cfg ant_cfg;
  1564. if (!tx_ant || !rx_ant)
  1565. return -EOPNOTSUPP;
  1566. if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
  1567. /* Not a MIMO chip. User should provide specific antenna number
  1568. * for Tx/Rx path or enable all antennas for diversity
  1569. */
  1570. if (tx_ant != rx_ant)
  1571. return -EOPNOTSUPP;
  1572. if ((tx_ant & (tx_ant - 1)) &&
  1573. (tx_ant != BIT(adapter->number_of_antenna) - 1))
  1574. return -EOPNOTSUPP;
  1575. if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
  1576. (priv->adapter->number_of_antenna > 1)) {
  1577. tx_ant = RF_ANTENNA_AUTO;
  1578. rx_ant = RF_ANTENNA_AUTO;
  1579. }
  1580. } else {
  1581. struct ieee80211_sta_ht_cap *ht_info;
  1582. int rx_mcs_supp;
  1583. enum nl80211_band band;
  1584. if ((tx_ant == 0x1 && rx_ant == 0x1)) {
  1585. adapter->user_dev_mcs_support = HT_STREAM_1X1;
  1586. if (adapter->is_hw_11ac_capable)
  1587. adapter->usr_dot_11ac_mcs_support =
  1588. MWIFIEX_11AC_MCS_MAP_1X1;
  1589. } else {
  1590. adapter->user_dev_mcs_support = HT_STREAM_2X2;
  1591. if (adapter->is_hw_11ac_capable)
  1592. adapter->usr_dot_11ac_mcs_support =
  1593. MWIFIEX_11AC_MCS_MAP_2X2;
  1594. }
  1595. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1596. if (!adapter->wiphy->bands[band])
  1597. continue;
  1598. ht_info = &adapter->wiphy->bands[band]->ht_cap;
  1599. rx_mcs_supp =
  1600. GET_RXMCSSUPP(adapter->user_dev_mcs_support);
  1601. memset(&ht_info->mcs, 0, adapter->number_of_antenna);
  1602. memset(&ht_info->mcs, 0xff, rx_mcs_supp);
  1603. }
  1604. }
  1605. ant_cfg.tx_ant = tx_ant;
  1606. ant_cfg.rx_ant = rx_ant;
  1607. return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
  1608. HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
  1609. }
  1610. static int
  1611. mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1612. {
  1613. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  1614. struct mwifiex_private *priv = mwifiex_get_priv(adapter,
  1615. MWIFIEX_BSS_ROLE_ANY);
  1616. mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
  1617. HostCmd_ACT_GEN_GET, 0, NULL, true);
  1618. *tx_ant = priv->tx_ant;
  1619. *rx_ant = priv->rx_ant;
  1620. return 0;
  1621. }
  1622. /* cfg80211 operation handler for stop ap.
  1623. * Function stops BSS running at uAP interface.
  1624. */
  1625. static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  1626. {
  1627. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1628. mwifiex_abort_cac(priv);
  1629. if (mwifiex_del_mgmt_ies(priv))
  1630. mwifiex_dbg(priv->adapter, ERROR,
  1631. "Failed to delete mgmt IEs!\n");
  1632. priv->ap_11n_enabled = 0;
  1633. memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
  1634. if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
  1635. HostCmd_ACT_GEN_SET, 0, NULL, true)) {
  1636. mwifiex_dbg(priv->adapter, ERROR,
  1637. "Failed to stop the BSS\n");
  1638. return -1;
  1639. }
  1640. if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
  1641. HostCmd_ACT_GEN_SET, 0, NULL, true)) {
  1642. mwifiex_dbg(priv->adapter, ERROR,
  1643. "Failed to reset BSS\n");
  1644. return -1;
  1645. }
  1646. if (netif_carrier_ok(priv->netdev))
  1647. netif_carrier_off(priv->netdev);
  1648. mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
  1649. return 0;
  1650. }
  1651. /* cfg80211 operation handler for start_ap.
  1652. * Function sets beacon period, DTIM period, SSID and security into
  1653. * AP config structure.
  1654. * AP is configured with these settings and BSS is started.
  1655. */
  1656. static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
  1657. struct net_device *dev,
  1658. struct cfg80211_ap_settings *params)
  1659. {
  1660. struct mwifiex_uap_bss_param *bss_cfg;
  1661. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1662. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
  1663. return -1;
  1664. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
  1665. if (!bss_cfg)
  1666. return -ENOMEM;
  1667. mwifiex_set_sys_config_invalid_data(bss_cfg);
  1668. if (params->beacon_interval)
  1669. bss_cfg->beacon_period = params->beacon_interval;
  1670. if (params->dtim_period)
  1671. bss_cfg->dtim_period = params->dtim_period;
  1672. if (params->ssid && params->ssid_len) {
  1673. memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
  1674. bss_cfg->ssid.ssid_len = params->ssid_len;
  1675. }
  1676. if (params->inactivity_timeout > 0) {
  1677. /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
  1678. bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
  1679. bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
  1680. }
  1681. switch (params->hidden_ssid) {
  1682. case NL80211_HIDDEN_SSID_NOT_IN_USE:
  1683. bss_cfg->bcast_ssid_ctl = 1;
  1684. break;
  1685. case NL80211_HIDDEN_SSID_ZERO_LEN:
  1686. bss_cfg->bcast_ssid_ctl = 0;
  1687. break;
  1688. case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
  1689. /* firmware doesn't support this type of hidden SSID */
  1690. default:
  1691. kfree(bss_cfg);
  1692. return -EINVAL;
  1693. }
  1694. mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
  1695. mwifiex_set_uap_rates(bss_cfg, params);
  1696. if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
  1697. mwifiex_dbg(priv->adapter, ERROR,
  1698. "Failed to parse secuirty parameters!\n");
  1699. goto out;
  1700. }
  1701. mwifiex_set_ht_params(priv, bss_cfg, params);
  1702. if (priv->adapter->is_hw_11ac_capable) {
  1703. mwifiex_set_vht_params(priv, bss_cfg, params);
  1704. mwifiex_set_vht_width(priv, params->chandef.width,
  1705. priv->ap_11ac_enabled);
  1706. }
  1707. if (priv->ap_11ac_enabled)
  1708. mwifiex_set_11ac_ba_params(priv);
  1709. else
  1710. mwifiex_set_ba_params(priv);
  1711. mwifiex_set_wmm_params(priv, bss_cfg, params);
  1712. if (mwifiex_is_11h_active(priv))
  1713. mwifiex_set_tpc_params(priv, bss_cfg, params);
  1714. if (mwifiex_is_11h_active(priv) &&
  1715. !cfg80211_chandef_dfs_required(wiphy, &params->chandef,
  1716. priv->bss_mode)) {
  1717. mwifiex_dbg(priv->adapter, INFO,
  1718. "Disable 11h extensions in FW\n");
  1719. if (mwifiex_11h_activate(priv, false)) {
  1720. mwifiex_dbg(priv->adapter, ERROR,
  1721. "Failed to disable 11h extensions!!");
  1722. goto out;
  1723. }
  1724. priv->state_11h.is_11h_active = false;
  1725. }
  1726. if (mwifiex_config_start_uap(priv, bss_cfg)) {
  1727. mwifiex_dbg(priv->adapter, ERROR,
  1728. "Failed to start AP\n");
  1729. goto out;
  1730. }
  1731. if (mwifiex_set_mgmt_ies(priv, &params->beacon))
  1732. goto out;
  1733. if (!netif_carrier_ok(priv->netdev))
  1734. netif_carrier_on(priv->netdev);
  1735. mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
  1736. memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
  1737. kfree(bss_cfg);
  1738. return 0;
  1739. out:
  1740. kfree(bss_cfg);
  1741. return -1;
  1742. }
  1743. /*
  1744. * CFG802.11 operation handler for disconnection request.
  1745. *
  1746. * This function does not work when there is already a disconnection
  1747. * procedure going on.
  1748. */
  1749. static int
  1750. mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
  1751. u16 reason_code)
  1752. {
  1753. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1754. if (!mwifiex_stop_bg_scan(priv))
  1755. cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
  1756. if (mwifiex_deauthenticate(priv, NULL))
  1757. return -EFAULT;
  1758. eth_zero_addr(priv->cfg_bssid);
  1759. priv->hs2_enabled = false;
  1760. return 0;
  1761. }
  1762. /*
  1763. * This function informs the CFG802.11 subsystem of a new IBSS.
  1764. *
  1765. * The following information are sent to the CFG802.11 subsystem
  1766. * to register the new IBSS. If we do not register the new IBSS,
  1767. * a kernel panic will result.
  1768. * - SSID
  1769. * - SSID length
  1770. * - BSSID
  1771. * - Channel
  1772. */
  1773. static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
  1774. {
  1775. struct ieee80211_channel *chan;
  1776. struct mwifiex_bss_info bss_info;
  1777. struct cfg80211_bss *bss;
  1778. int ie_len;
  1779. u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
  1780. enum nl80211_band band;
  1781. if (mwifiex_get_bss_info(priv, &bss_info))
  1782. return -1;
  1783. ie_buf[0] = WLAN_EID_SSID;
  1784. ie_buf[1] = bss_info.ssid.ssid_len;
  1785. memcpy(&ie_buf[sizeof(struct ieee_types_header)],
  1786. &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
  1787. ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
  1788. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  1789. chan = __ieee80211_get_channel(priv->wdev.wiphy,
  1790. ieee80211_channel_to_frequency(bss_info.bss_chan,
  1791. band));
  1792. bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
  1793. CFG80211_BSS_FTYPE_UNKNOWN,
  1794. bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
  1795. 0, ie_buf, ie_len, 0, GFP_KERNEL);
  1796. if (bss) {
  1797. cfg80211_put_bss(priv->wdev.wiphy, bss);
  1798. ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
  1799. }
  1800. return 0;
  1801. }
  1802. /*
  1803. * This function connects with a BSS.
  1804. *
  1805. * This function handles both Infra and Ad-Hoc modes. It also performs
  1806. * validity checking on the provided parameters, disconnects from the
  1807. * current BSS (if any), sets up the association/scan parameters,
  1808. * including security settings, and performs specific SSID scan before
  1809. * trying to connect.
  1810. *
  1811. * For Infra mode, the function returns failure if the specified SSID
  1812. * is not found in scan table. However, for Ad-Hoc mode, it can create
  1813. * the IBSS if it does not exist. On successful completion in either case,
  1814. * the function notifies the CFG802.11 subsystem of the new BSS connection.
  1815. */
  1816. static int
  1817. mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
  1818. const u8 *ssid, const u8 *bssid, int mode,
  1819. struct ieee80211_channel *channel,
  1820. struct cfg80211_connect_params *sme, bool privacy)
  1821. {
  1822. struct cfg80211_ssid req_ssid;
  1823. int ret, auth_type = 0;
  1824. struct cfg80211_bss *bss = NULL;
  1825. u8 is_scanning_required = 0;
  1826. memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
  1827. req_ssid.ssid_len = ssid_len;
  1828. if (ssid_len > IEEE80211_MAX_SSID_LEN) {
  1829. mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
  1830. return -EINVAL;
  1831. }
  1832. memcpy(req_ssid.ssid, ssid, ssid_len);
  1833. if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
  1834. mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
  1835. return -EINVAL;
  1836. }
  1837. /* As this is new association, clear locally stored
  1838. * keys and security related flags */
  1839. priv->sec_info.wpa_enabled = false;
  1840. priv->sec_info.wpa2_enabled = false;
  1841. priv->wep_key_curr_index = 0;
  1842. priv->sec_info.encryption_mode = 0;
  1843. priv->sec_info.is_authtype_auto = 0;
  1844. ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
  1845. if (mode == NL80211_IFTYPE_ADHOC) {
  1846. /* "privacy" is set only for ad-hoc mode */
  1847. if (privacy) {
  1848. /*
  1849. * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
  1850. * the firmware can find a matching network from the
  1851. * scan. The cfg80211 does not give us the encryption
  1852. * mode at this stage so just setting it to WEP here.
  1853. */
  1854. priv->sec_info.encryption_mode =
  1855. WLAN_CIPHER_SUITE_WEP104;
  1856. priv->sec_info.authentication_mode =
  1857. NL80211_AUTHTYPE_OPEN_SYSTEM;
  1858. }
  1859. goto done;
  1860. }
  1861. /* Now handle infra mode. "sme" is valid for infra mode only */
  1862. if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
  1863. auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1864. priv->sec_info.is_authtype_auto = 1;
  1865. } else {
  1866. auth_type = sme->auth_type;
  1867. }
  1868. if (sme->crypto.n_ciphers_pairwise) {
  1869. priv->sec_info.encryption_mode =
  1870. sme->crypto.ciphers_pairwise[0];
  1871. priv->sec_info.authentication_mode = auth_type;
  1872. }
  1873. if (sme->crypto.cipher_group) {
  1874. priv->sec_info.encryption_mode = sme->crypto.cipher_group;
  1875. priv->sec_info.authentication_mode = auth_type;
  1876. }
  1877. if (sme->ie)
  1878. ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
  1879. if (sme->key) {
  1880. if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
  1881. mwifiex_dbg(priv->adapter, INFO,
  1882. "info: setting wep encryption\t"
  1883. "with key len %d\n", sme->key_len);
  1884. priv->wep_key_curr_index = sme->key_idx;
  1885. ret = mwifiex_set_encode(priv, NULL, sme->key,
  1886. sme->key_len, sme->key_idx,
  1887. NULL, 0);
  1888. }
  1889. }
  1890. done:
  1891. /*
  1892. * Scan entries are valid for some time (15 sec). So we can save one
  1893. * active scan time if we just try cfg80211_get_bss first. If it fails
  1894. * then request scan and cfg80211_get_bss() again for final output.
  1895. */
  1896. while (1) {
  1897. if (is_scanning_required) {
  1898. /* Do specific SSID scanning */
  1899. if (mwifiex_request_scan(priv, &req_ssid)) {
  1900. mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
  1901. return -EFAULT;
  1902. }
  1903. }
  1904. /* Find the BSS we want using available scan results */
  1905. if (mode == NL80211_IFTYPE_ADHOC)
  1906. bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
  1907. bssid, ssid, ssid_len,
  1908. IEEE80211_BSS_TYPE_IBSS,
  1909. IEEE80211_PRIVACY_ANY);
  1910. else
  1911. bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
  1912. bssid, ssid, ssid_len,
  1913. IEEE80211_BSS_TYPE_ESS,
  1914. IEEE80211_PRIVACY_ANY);
  1915. if (!bss) {
  1916. if (is_scanning_required) {
  1917. mwifiex_dbg(priv->adapter, WARN,
  1918. "assoc: requested bss not found in scan results\n");
  1919. break;
  1920. }
  1921. is_scanning_required = 1;
  1922. } else {
  1923. mwifiex_dbg(priv->adapter, MSG,
  1924. "info: trying to associate to '%.*s' bssid %pM\n",
  1925. req_ssid.ssid_len, (char *)req_ssid.ssid,
  1926. bss->bssid);
  1927. memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
  1928. break;
  1929. }
  1930. }
  1931. ret = mwifiex_bss_start(priv, bss, &req_ssid);
  1932. if (ret)
  1933. return ret;
  1934. if (mode == NL80211_IFTYPE_ADHOC) {
  1935. /* Inform the BSS information to kernel, otherwise
  1936. * kernel will give a panic after successful assoc */
  1937. if (mwifiex_cfg80211_inform_ibss_bss(priv))
  1938. return -EFAULT;
  1939. }
  1940. return ret;
  1941. }
  1942. /*
  1943. * CFG802.11 operation handler for association request.
  1944. *
  1945. * This function does not work when the current mode is set to Ad-Hoc, or
  1946. * when there is already an association procedure going on. The given BSS
  1947. * information is used to associate.
  1948. */
  1949. static int
  1950. mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
  1951. struct cfg80211_connect_params *sme)
  1952. {
  1953. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1954. struct mwifiex_adapter *adapter = priv->adapter;
  1955. int ret;
  1956. if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
  1957. mwifiex_dbg(adapter, ERROR,
  1958. "%s: reject infra assoc request in non-STA role\n",
  1959. dev->name);
  1960. return -EINVAL;
  1961. }
  1962. if (priv->wdev.current_bss) {
  1963. mwifiex_dbg(adapter, ERROR,
  1964. "%s: already connected\n", dev->name);
  1965. return -EALREADY;
  1966. }
  1967. if (priv->scan_block)
  1968. priv->scan_block = false;
  1969. if (adapter->surprise_removed || adapter->is_cmd_timedout) {
  1970. mwifiex_dbg(adapter, ERROR,
  1971. "%s: Ignore connection.\t"
  1972. "Card removed or FW in bad state\n",
  1973. dev->name);
  1974. return -EFAULT;
  1975. }
  1976. mwifiex_dbg(adapter, INFO,
  1977. "info: Trying to associate to %.*s and bssid %pM\n",
  1978. (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
  1979. if (!mwifiex_stop_bg_scan(priv))
  1980. cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
  1981. ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
  1982. priv->bss_mode, sme->channel, sme, 0);
  1983. if (!ret) {
  1984. cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
  1985. NULL, 0, WLAN_STATUS_SUCCESS,
  1986. GFP_KERNEL);
  1987. mwifiex_dbg(priv->adapter, MSG,
  1988. "info: associated to bssid %pM successfully\n",
  1989. priv->cfg_bssid);
  1990. if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  1991. priv->adapter->auto_tdls &&
  1992. priv->bss_type == MWIFIEX_BSS_TYPE_STA)
  1993. mwifiex_setup_auto_tdls_timer(priv);
  1994. } else {
  1995. mwifiex_dbg(priv->adapter, ERROR,
  1996. "info: association to bssid %pM failed\n",
  1997. priv->cfg_bssid);
  1998. eth_zero_addr(priv->cfg_bssid);
  1999. if (ret > 0)
  2000. cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
  2001. NULL, 0, NULL, 0, ret,
  2002. GFP_KERNEL);
  2003. else
  2004. cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
  2005. NULL, 0, NULL, 0,
  2006. WLAN_STATUS_UNSPECIFIED_FAILURE,
  2007. GFP_KERNEL);
  2008. }
  2009. return 0;
  2010. }
  2011. /*
  2012. * This function sets following parameters for ibss network.
  2013. * - channel
  2014. * - start band
  2015. * - 11n flag
  2016. * - secondary channel offset
  2017. */
  2018. static int mwifiex_set_ibss_params(struct mwifiex_private *priv,
  2019. struct cfg80211_ibss_params *params)
  2020. {
  2021. struct mwifiex_adapter *adapter = priv->adapter;
  2022. int index = 0, i;
  2023. u8 config_bands = 0;
  2024. if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
  2025. if (!params->basic_rates) {
  2026. config_bands = BAND_B | BAND_G;
  2027. } else {
  2028. for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
  2029. /*
  2030. * Rates below 6 Mbps in the table are CCK
  2031. * rates; 802.11b and from 6 they are OFDM;
  2032. * 802.11G
  2033. */
  2034. if (mwifiex_rates[i].bitrate == 60) {
  2035. index = 1 << i;
  2036. break;
  2037. }
  2038. }
  2039. if (params->basic_rates < index) {
  2040. config_bands = BAND_B;
  2041. } else {
  2042. config_bands = BAND_G;
  2043. if (params->basic_rates % index)
  2044. config_bands |= BAND_B;
  2045. }
  2046. }
  2047. if (cfg80211_get_chandef_type(&params->chandef) !=
  2048. NL80211_CHAN_NO_HT)
  2049. config_bands |= BAND_G | BAND_GN;
  2050. } else {
  2051. if (cfg80211_get_chandef_type(&params->chandef) ==
  2052. NL80211_CHAN_NO_HT)
  2053. config_bands = BAND_A;
  2054. else
  2055. config_bands = BAND_AN | BAND_A;
  2056. }
  2057. if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
  2058. adapter->config_bands = config_bands;
  2059. adapter->adhoc_start_band = config_bands;
  2060. if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
  2061. adapter->adhoc_11n_enabled = true;
  2062. else
  2063. adapter->adhoc_11n_enabled = false;
  2064. }
  2065. adapter->sec_chan_offset =
  2066. mwifiex_chan_type_to_sec_chan_offset(
  2067. cfg80211_get_chandef_type(&params->chandef));
  2068. priv->adhoc_channel = ieee80211_frequency_to_channel(
  2069. params->chandef.chan->center_freq);
  2070. mwifiex_dbg(adapter, INFO,
  2071. "info: set ibss band %d, chan %d, chan offset %d\n",
  2072. config_bands, priv->adhoc_channel,
  2073. adapter->sec_chan_offset);
  2074. return 0;
  2075. }
  2076. /*
  2077. * CFG802.11 operation handler to join an IBSS.
  2078. *
  2079. * This function does not work in any mode other than Ad-Hoc, or if
  2080. * a join operation is already in progress.
  2081. */
  2082. static int
  2083. mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  2084. struct cfg80211_ibss_params *params)
  2085. {
  2086. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2087. int ret = 0;
  2088. if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
  2089. mwifiex_dbg(priv->adapter, ERROR,
  2090. "request to join ibss received\t"
  2091. "when station is not in ibss mode\n");
  2092. goto done;
  2093. }
  2094. mwifiex_dbg(priv->adapter, MSG,
  2095. "info: trying to join to %.*s and bssid %pM\n",
  2096. params->ssid_len, (char *)params->ssid, params->bssid);
  2097. mwifiex_set_ibss_params(priv, params);
  2098. ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
  2099. params->bssid, priv->bss_mode,
  2100. params->chandef.chan, NULL,
  2101. params->privacy);
  2102. done:
  2103. if (!ret) {
  2104. cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
  2105. params->chandef.chan, GFP_KERNEL);
  2106. mwifiex_dbg(priv->adapter, MSG,
  2107. "info: joined/created adhoc network with bssid\t"
  2108. "%pM successfully\n", priv->cfg_bssid);
  2109. } else {
  2110. mwifiex_dbg(priv->adapter, ERROR,
  2111. "info: failed creating/joining adhoc network\n");
  2112. }
  2113. return ret;
  2114. }
  2115. /*
  2116. * CFG802.11 operation handler to leave an IBSS.
  2117. *
  2118. * This function does not work if a leave operation is
  2119. * already in progress.
  2120. */
  2121. static int
  2122. mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  2123. {
  2124. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2125. mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
  2126. priv->cfg_bssid);
  2127. if (mwifiex_deauthenticate(priv, NULL))
  2128. return -EFAULT;
  2129. eth_zero_addr(priv->cfg_bssid);
  2130. return 0;
  2131. }
  2132. /*
  2133. * CFG802.11 operation handler for scan request.
  2134. *
  2135. * This function issues a scan request to the firmware based upon
  2136. * the user specified scan configuration. On successful completion,
  2137. * it also informs the results.
  2138. */
  2139. static int
  2140. mwifiex_cfg80211_scan(struct wiphy *wiphy,
  2141. struct cfg80211_scan_request *request)
  2142. {
  2143. struct net_device *dev = request->wdev->netdev;
  2144. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2145. int i, offset, ret;
  2146. struct ieee80211_channel *chan;
  2147. struct ieee_types_header *ie;
  2148. struct mwifiex_user_scan_cfg *user_scan_cfg;
  2149. mwifiex_dbg(priv->adapter, CMD,
  2150. "info: received scan request on %s\n", dev->name);
  2151. /* Block scan request if scan operation or scan cleanup when interface
  2152. * is disabled is in process
  2153. */
  2154. if (priv->scan_request || priv->scan_aborting) {
  2155. mwifiex_dbg(priv->adapter, WARN,
  2156. "cmd: Scan already in process..\n");
  2157. return -EBUSY;
  2158. }
  2159. if (!priv->wdev.current_bss && priv->scan_block)
  2160. priv->scan_block = false;
  2161. if (!mwifiex_stop_bg_scan(priv))
  2162. cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
  2163. user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
  2164. if (!user_scan_cfg)
  2165. return -ENOMEM;
  2166. priv->scan_request = request;
  2167. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  2168. ether_addr_copy(priv->random_mac, request->mac_addr);
  2169. for (i = 0; i < ETH_ALEN; i++) {
  2170. priv->random_mac[i] &= request->mac_addr_mask[i];
  2171. priv->random_mac[i] |= get_random_int() &
  2172. ~(request->mac_addr_mask[i]);
  2173. }
  2174. ether_addr_copy(user_scan_cfg->random_mac, priv->random_mac);
  2175. } else {
  2176. eth_zero_addr(priv->random_mac);
  2177. }
  2178. user_scan_cfg->num_ssids = request->n_ssids;
  2179. user_scan_cfg->ssid_list = request->ssids;
  2180. if (request->ie && request->ie_len) {
  2181. offset = 0;
  2182. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  2183. if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
  2184. continue;
  2185. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
  2186. ie = (struct ieee_types_header *)(request->ie + offset);
  2187. memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
  2188. offset += sizeof(*ie) + ie->len;
  2189. if (offset >= request->ie_len)
  2190. break;
  2191. }
  2192. }
  2193. for (i = 0; i < min_t(u32, request->n_channels,
  2194. MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
  2195. chan = request->channels[i];
  2196. user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
  2197. user_scan_cfg->chan_list[i].radio_type = chan->band;
  2198. if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
  2199. user_scan_cfg->chan_list[i].scan_type =
  2200. MWIFIEX_SCAN_TYPE_PASSIVE;
  2201. else
  2202. user_scan_cfg->chan_list[i].scan_type =
  2203. MWIFIEX_SCAN_TYPE_ACTIVE;
  2204. user_scan_cfg->chan_list[i].scan_time = 0;
  2205. }
  2206. if (priv->adapter->scan_chan_gap_enabled &&
  2207. mwifiex_is_any_intf_active(priv))
  2208. user_scan_cfg->scan_chan_gap =
  2209. priv->adapter->scan_chan_gap_time;
  2210. ret = mwifiex_scan_networks(priv, user_scan_cfg);
  2211. kfree(user_scan_cfg);
  2212. if (ret) {
  2213. mwifiex_dbg(priv->adapter, ERROR,
  2214. "scan failed: %d\n", ret);
  2215. priv->scan_aborting = false;
  2216. priv->scan_request = NULL;
  2217. return ret;
  2218. }
  2219. if (request->ie && request->ie_len) {
  2220. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  2221. if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
  2222. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
  2223. memset(&priv->vs_ie[i].ie, 0,
  2224. MWIFIEX_MAX_VSIE_LEN);
  2225. }
  2226. }
  2227. }
  2228. return 0;
  2229. }
  2230. /* CFG802.11 operation handler for sched_scan_start.
  2231. *
  2232. * This function issues a bgscan config request to the firmware based upon
  2233. * the user specified sched_scan configuration. On successful completion,
  2234. * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
  2235. * query command to get sched_scan results from firmware.
  2236. */
  2237. static int
  2238. mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
  2239. struct net_device *dev,
  2240. struct cfg80211_sched_scan_request *request)
  2241. {
  2242. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2243. int i, offset;
  2244. struct ieee80211_channel *chan;
  2245. struct mwifiex_bg_scan_cfg *bgscan_cfg;
  2246. struct ieee_types_header *ie;
  2247. if (!request || (!request->n_ssids && !request->n_match_sets)) {
  2248. wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
  2249. __func__);
  2250. return -EINVAL;
  2251. }
  2252. wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
  2253. request->n_ssids, request->n_match_sets);
  2254. wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
  2255. request->n_channels, request->scan_plans->interval,
  2256. (int)request->ie_len);
  2257. bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
  2258. if (!bgscan_cfg)
  2259. return -ENOMEM;
  2260. if (priv->scan_request || priv->scan_aborting)
  2261. bgscan_cfg->start_later = true;
  2262. bgscan_cfg->num_ssids = request->n_match_sets;
  2263. bgscan_cfg->ssid_list = request->match_sets;
  2264. if (request->ie && request->ie_len) {
  2265. offset = 0;
  2266. for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
  2267. if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
  2268. continue;
  2269. priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
  2270. ie = (struct ieee_types_header *)(request->ie + offset);
  2271. memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
  2272. offset += sizeof(*ie) + ie->len;
  2273. if (offset >= request->ie_len)
  2274. break;
  2275. }
  2276. }
  2277. for (i = 0; i < min_t(u32, request->n_channels,
  2278. MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
  2279. chan = request->channels[i];
  2280. bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
  2281. bgscan_cfg->chan_list[i].radio_type = chan->band;
  2282. if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
  2283. bgscan_cfg->chan_list[i].scan_type =
  2284. MWIFIEX_SCAN_TYPE_PASSIVE;
  2285. else
  2286. bgscan_cfg->chan_list[i].scan_type =
  2287. MWIFIEX_SCAN_TYPE_ACTIVE;
  2288. bgscan_cfg->chan_list[i].scan_time = 0;
  2289. }
  2290. bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
  2291. MWIFIEX_BG_SCAN_CHAN_MAX);
  2292. /* Use at least 15 second for per scan cycle */
  2293. bgscan_cfg->scan_interval = (request->scan_plans->interval >
  2294. MWIFIEX_BGSCAN_INTERVAL) ?
  2295. request->scan_plans->interval :
  2296. MWIFIEX_BGSCAN_INTERVAL;
  2297. bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
  2298. bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
  2299. MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
  2300. bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
  2301. bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
  2302. bgscan_cfg->enable = true;
  2303. if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
  2304. bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
  2305. bgscan_cfg->rssi_threshold = request->min_rssi_thold;
  2306. }
  2307. if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
  2308. HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
  2309. kfree(bgscan_cfg);
  2310. return -EFAULT;
  2311. }
  2312. priv->sched_scanning = true;
  2313. kfree(bgscan_cfg);
  2314. return 0;
  2315. }
  2316. /* CFG802.11 operation handler for sched_scan_stop.
  2317. *
  2318. * This function issues a bgscan config command to disable
  2319. * previous bgscan configuration in the firmware
  2320. */
  2321. static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
  2322. struct net_device *dev)
  2323. {
  2324. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  2325. wiphy_info(wiphy, "sched scan stop!");
  2326. mwifiex_stop_bg_scan(priv);
  2327. return 0;
  2328. }
  2329. static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
  2330. struct mwifiex_private *priv)
  2331. {
  2332. struct mwifiex_adapter *adapter = priv->adapter;
  2333. vht_info->vht_supported = true;
  2334. vht_info->cap = adapter->hw_dot_11ac_dev_cap;
  2335. /* Update MCS support for VHT */
  2336. vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
  2337. adapter->hw_dot_11ac_mcs_support & 0xFFFF);
  2338. vht_info->vht_mcs.rx_highest = 0;
  2339. vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
  2340. adapter->hw_dot_11ac_mcs_support >> 16);
  2341. vht_info->vht_mcs.tx_highest = 0;
  2342. }
  2343. /*
  2344. * This function sets up the CFG802.11 specific HT capability fields
  2345. * with default values.
  2346. *
  2347. * The following default values are set -
  2348. * - HT Supported = True
  2349. * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
  2350. * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
  2351. * - HT Capabilities supported by firmware
  2352. * - MCS information, Rx mask = 0xff
  2353. * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
  2354. */
  2355. static void
  2356. mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
  2357. struct mwifiex_private *priv)
  2358. {
  2359. int rx_mcs_supp;
  2360. struct ieee80211_mcs_info mcs_set;
  2361. u8 *mcs = (u8 *)&mcs_set;
  2362. struct mwifiex_adapter *adapter = priv->adapter;
  2363. ht_info->ht_supported = true;
  2364. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  2365. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  2366. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  2367. /* Fill HT capability information */
  2368. if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  2369. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2370. else
  2371. ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2372. if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
  2373. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  2374. else
  2375. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
  2376. if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
  2377. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  2378. else
  2379. ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
  2380. if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
  2381. ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
  2382. else
  2383. ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
  2384. if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
  2385. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  2386. else
  2387. ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
  2388. if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
  2389. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  2390. else
  2391. ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
  2392. if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
  2393. ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
  2394. else
  2395. ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
  2396. if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
  2397. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  2398. else
  2399. ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
  2400. ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  2401. ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
  2402. rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
  2403. /* Set MCS for 1x1/2x2 */
  2404. memset(mcs, 0xff, rx_mcs_supp);
  2405. /* Clear all the other values */
  2406. memset(&mcs[rx_mcs_supp], 0,
  2407. sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
  2408. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  2409. ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
  2410. /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
  2411. SETHT_MCS32(mcs_set.rx_mask);
  2412. memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
  2413. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  2414. }
  2415. /*
  2416. * create a new virtual interface with the given name and name assign type
  2417. */
  2418. struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
  2419. const char *name,
  2420. unsigned char name_assign_type,
  2421. enum nl80211_iftype type,
  2422. u32 *flags,
  2423. struct vif_params *params)
  2424. {
  2425. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  2426. struct mwifiex_private *priv;
  2427. struct net_device *dev;
  2428. void *mdev_priv;
  2429. int ret;
  2430. if (!adapter)
  2431. return ERR_PTR(-EFAULT);
  2432. switch (type) {
  2433. case NL80211_IFTYPE_UNSPECIFIED:
  2434. case NL80211_IFTYPE_STATION:
  2435. case NL80211_IFTYPE_ADHOC:
  2436. if (adapter->curr_iface_comb.sta_intf ==
  2437. adapter->iface_limit.sta_intf) {
  2438. mwifiex_dbg(adapter, ERROR,
  2439. "cannot create multiple sta/adhoc ifaces\n");
  2440. return ERR_PTR(-EINVAL);
  2441. }
  2442. priv = mwifiex_get_unused_priv_by_bss_type(
  2443. adapter, MWIFIEX_BSS_TYPE_STA);
  2444. if (!priv) {
  2445. mwifiex_dbg(adapter, ERROR,
  2446. "could not get free private struct\n");
  2447. return ERR_PTR(-EFAULT);
  2448. }
  2449. priv->wdev.wiphy = wiphy;
  2450. priv->wdev.iftype = NL80211_IFTYPE_STATION;
  2451. if (type == NL80211_IFTYPE_UNSPECIFIED)
  2452. priv->bss_mode = NL80211_IFTYPE_STATION;
  2453. else
  2454. priv->bss_mode = type;
  2455. priv->bss_type = MWIFIEX_BSS_TYPE_STA;
  2456. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  2457. priv->bss_priority = 0;
  2458. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  2459. break;
  2460. case NL80211_IFTYPE_AP:
  2461. if (adapter->curr_iface_comb.uap_intf ==
  2462. adapter->iface_limit.uap_intf) {
  2463. mwifiex_dbg(adapter, ERROR,
  2464. "cannot create multiple AP ifaces\n");
  2465. return ERR_PTR(-EINVAL);
  2466. }
  2467. priv = mwifiex_get_unused_priv_by_bss_type(
  2468. adapter, MWIFIEX_BSS_TYPE_UAP);
  2469. if (!priv) {
  2470. mwifiex_dbg(adapter, ERROR,
  2471. "could not get free private struct\n");
  2472. return ERR_PTR(-EFAULT);
  2473. }
  2474. priv->wdev.wiphy = wiphy;
  2475. priv->wdev.iftype = NL80211_IFTYPE_AP;
  2476. priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
  2477. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  2478. priv->bss_priority = 0;
  2479. priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
  2480. priv->bss_started = 0;
  2481. priv->bss_mode = type;
  2482. break;
  2483. case NL80211_IFTYPE_P2P_CLIENT:
  2484. if (adapter->curr_iface_comb.p2p_intf ==
  2485. adapter->iface_limit.p2p_intf) {
  2486. mwifiex_dbg(adapter, ERROR,
  2487. "cannot create multiple P2P ifaces\n");
  2488. return ERR_PTR(-EINVAL);
  2489. }
  2490. priv = mwifiex_get_unused_priv_by_bss_type(
  2491. adapter, MWIFIEX_BSS_TYPE_P2P);
  2492. if (!priv) {
  2493. mwifiex_dbg(adapter, ERROR,
  2494. "could not get free private struct\n");
  2495. return ERR_PTR(-EFAULT);
  2496. }
  2497. priv->wdev.wiphy = wiphy;
  2498. /* At start-up, wpa_supplicant tries to change the interface
  2499. * to NL80211_IFTYPE_STATION if it is not managed mode.
  2500. */
  2501. priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
  2502. priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
  2503. /* Setting bss_type to P2P tells firmware that this interface
  2504. * is receiving P2P peers found during find phase and doing
  2505. * action frame handshake.
  2506. */
  2507. priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
  2508. priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
  2509. priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
  2510. priv->bss_role = MWIFIEX_BSS_ROLE_STA;
  2511. priv->bss_started = 0;
  2512. if (mwifiex_cfg80211_init_p2p_client(priv)) {
  2513. memset(&priv->wdev, 0, sizeof(priv->wdev));
  2514. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2515. return ERR_PTR(-EFAULT);
  2516. }
  2517. break;
  2518. default:
  2519. mwifiex_dbg(adapter, ERROR, "type not supported\n");
  2520. return ERR_PTR(-EINVAL);
  2521. }
  2522. dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
  2523. name_assign_type, ether_setup,
  2524. IEEE80211_NUM_ACS, 1);
  2525. if (!dev) {
  2526. mwifiex_dbg(adapter, ERROR,
  2527. "no memory available for netdevice\n");
  2528. memset(&priv->wdev, 0, sizeof(priv->wdev));
  2529. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2530. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  2531. return ERR_PTR(-ENOMEM);
  2532. }
  2533. mwifiex_init_priv_params(priv, dev);
  2534. priv->netdev = dev;
  2535. ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
  2536. HostCmd_ACT_GEN_SET, 0, NULL, true);
  2537. if (ret)
  2538. return ERR_PTR(ret);
  2539. ret = mwifiex_sta_init_cmd(priv, false, false);
  2540. if (ret)
  2541. return ERR_PTR(ret);
  2542. mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
  2543. if (adapter->is_hw_11ac_capable)
  2544. mwifiex_setup_vht_caps(
  2545. &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
  2546. if (adapter->config_bands & BAND_A)
  2547. mwifiex_setup_ht_caps(
  2548. &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
  2549. if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
  2550. mwifiex_setup_vht_caps(
  2551. &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
  2552. dev_net_set(dev, wiphy_net(wiphy));
  2553. dev->ieee80211_ptr = &priv->wdev;
  2554. dev->ieee80211_ptr->iftype = priv->bss_mode;
  2555. memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
  2556. SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
  2557. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  2558. dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
  2559. dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN;
  2560. dev->ethtool_ops = &mwifiex_ethtool_ops;
  2561. mdev_priv = netdev_priv(dev);
  2562. *((unsigned long *) mdev_priv) = (unsigned long) priv;
  2563. SET_NETDEV_DEV(dev, adapter->dev);
  2564. /* Register network device */
  2565. if (register_netdevice(dev)) {
  2566. mwifiex_dbg(adapter, ERROR,
  2567. "cannot register virtual network device\n");
  2568. free_netdev(dev);
  2569. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  2570. priv->netdev = NULL;
  2571. memset(&priv->wdev, 0, sizeof(priv->wdev));
  2572. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2573. return ERR_PTR(-EFAULT);
  2574. }
  2575. priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
  2576. WQ_HIGHPRI |
  2577. WQ_MEM_RECLAIM |
  2578. WQ_UNBOUND, 1, name);
  2579. if (!priv->dfs_cac_workqueue) {
  2580. mwifiex_dbg(adapter, ERROR,
  2581. "cannot register virtual network device\n");
  2582. free_netdev(dev);
  2583. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  2584. priv->netdev = NULL;
  2585. memset(&priv->wdev, 0, sizeof(priv->wdev));
  2586. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2587. return ERR_PTR(-ENOMEM);
  2588. }
  2589. INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
  2590. priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
  2591. WQ_HIGHPRI | WQ_UNBOUND |
  2592. WQ_MEM_RECLAIM, 1, name);
  2593. if (!priv->dfs_chan_sw_workqueue) {
  2594. mwifiex_dbg(adapter, ERROR,
  2595. "cannot register virtual network device\n");
  2596. free_netdev(dev);
  2597. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  2598. priv->netdev = NULL;
  2599. memset(&priv->wdev, 0, sizeof(priv->wdev));
  2600. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2601. return ERR_PTR(-ENOMEM);
  2602. }
  2603. INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
  2604. mwifiex_dfs_chan_sw_work_queue);
  2605. sema_init(&priv->async_sem, 1);
  2606. mwifiex_dbg(adapter, INFO,
  2607. "info: %s: Marvell 802.11 Adapter\n", dev->name);
  2608. #ifdef CONFIG_DEBUG_FS
  2609. mwifiex_dev_debugfs_init(priv);
  2610. #endif
  2611. switch (type) {
  2612. case NL80211_IFTYPE_UNSPECIFIED:
  2613. case NL80211_IFTYPE_STATION:
  2614. case NL80211_IFTYPE_ADHOC:
  2615. adapter->curr_iface_comb.sta_intf++;
  2616. break;
  2617. case NL80211_IFTYPE_AP:
  2618. adapter->curr_iface_comb.uap_intf++;
  2619. break;
  2620. case NL80211_IFTYPE_P2P_CLIENT:
  2621. adapter->curr_iface_comb.p2p_intf++;
  2622. break;
  2623. default:
  2624. mwifiex_dbg(adapter, ERROR, "type not supported\n");
  2625. return ERR_PTR(-EINVAL);
  2626. }
  2627. return &priv->wdev;
  2628. }
  2629. EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
  2630. /*
  2631. * del_virtual_intf: remove the virtual interface determined by dev
  2632. */
  2633. int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
  2634. {
  2635. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  2636. struct mwifiex_adapter *adapter = priv->adapter;
  2637. struct sk_buff *skb, *tmp;
  2638. #ifdef CONFIG_DEBUG_FS
  2639. mwifiex_dev_debugfs_remove(priv);
  2640. #endif
  2641. if (priv->sched_scanning)
  2642. priv->sched_scanning = false;
  2643. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  2644. skb_queue_walk_safe(&priv->bypass_txq, skb, tmp)
  2645. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  2646. if (netif_carrier_ok(priv->netdev))
  2647. netif_carrier_off(priv->netdev);
  2648. if (wdev->netdev->reg_state == NETREG_REGISTERED)
  2649. unregister_netdevice(wdev->netdev);
  2650. if (priv->dfs_cac_workqueue) {
  2651. flush_workqueue(priv->dfs_cac_workqueue);
  2652. destroy_workqueue(priv->dfs_cac_workqueue);
  2653. priv->dfs_cac_workqueue = NULL;
  2654. }
  2655. if (priv->dfs_chan_sw_workqueue) {
  2656. flush_workqueue(priv->dfs_chan_sw_workqueue);
  2657. destroy_workqueue(priv->dfs_chan_sw_workqueue);
  2658. priv->dfs_chan_sw_workqueue = NULL;
  2659. }
  2660. /* Clear the priv in adapter */
  2661. priv->netdev->ieee80211_ptr = NULL;
  2662. priv->netdev = NULL;
  2663. priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  2664. priv->media_connected = false;
  2665. switch (priv->bss_mode) {
  2666. case NL80211_IFTYPE_UNSPECIFIED:
  2667. case NL80211_IFTYPE_STATION:
  2668. case NL80211_IFTYPE_ADHOC:
  2669. adapter->curr_iface_comb.sta_intf--;
  2670. break;
  2671. case NL80211_IFTYPE_AP:
  2672. adapter->curr_iface_comb.uap_intf--;
  2673. break;
  2674. case NL80211_IFTYPE_P2P_CLIENT:
  2675. case NL80211_IFTYPE_P2P_GO:
  2676. adapter->curr_iface_comb.p2p_intf--;
  2677. break;
  2678. default:
  2679. mwifiex_dbg(adapter, ERROR,
  2680. "del_virtual_intf: type not supported\n");
  2681. break;
  2682. }
  2683. priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
  2684. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
  2685. GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
  2686. kfree(priv->hist_data);
  2687. return 0;
  2688. }
  2689. EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
  2690. static bool
  2691. mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
  2692. u8 max_byte_seq)
  2693. {
  2694. int j, k, valid_byte_cnt = 0;
  2695. bool dont_care_byte = false;
  2696. for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
  2697. for (k = 0; k < 8; k++) {
  2698. if (pat->mask[j] & 1 << k) {
  2699. memcpy(byte_seq + valid_byte_cnt,
  2700. &pat->pattern[j * 8 + k], 1);
  2701. valid_byte_cnt++;
  2702. if (dont_care_byte)
  2703. return false;
  2704. } else {
  2705. if (valid_byte_cnt)
  2706. dont_care_byte = true;
  2707. }
  2708. /* wildcard bytes record as the offset
  2709. * before the valid byte
  2710. */
  2711. if (!valid_byte_cnt && !dont_care_byte)
  2712. pat->pkt_offset++;
  2713. if (valid_byte_cnt > max_byte_seq)
  2714. return false;
  2715. }
  2716. }
  2717. byte_seq[max_byte_seq] = valid_byte_cnt;
  2718. return true;
  2719. }
  2720. #ifdef CONFIG_PM
  2721. static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
  2722. struct mwifiex_mef_entry *mef_entry)
  2723. {
  2724. int i, filt_num = 0, num_ipv4 = 0;
  2725. struct in_device *in_dev;
  2726. struct in_ifaddr *ifa;
  2727. __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
  2728. struct mwifiex_adapter *adapter = priv->adapter;
  2729. mef_entry->mode = MEF_MODE_HOST_SLEEP;
  2730. mef_entry->action = MEF_ACTION_AUTO_ARP;
  2731. /* Enable ARP offload feature */
  2732. memset(ips, 0, sizeof(ips));
  2733. for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
  2734. if (adapter->priv[i]->netdev) {
  2735. in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
  2736. if (!in_dev)
  2737. continue;
  2738. ifa = in_dev->ifa_list;
  2739. if (!ifa || !ifa->ifa_local)
  2740. continue;
  2741. ips[i] = ifa->ifa_local;
  2742. num_ipv4++;
  2743. }
  2744. }
  2745. for (i = 0; i < num_ipv4; i++) {
  2746. if (!ips[i])
  2747. continue;
  2748. mef_entry->filter[filt_num].repeat = 1;
  2749. memcpy(mef_entry->filter[filt_num].byte_seq,
  2750. (u8 *)&ips[i], sizeof(ips[i]));
  2751. mef_entry->filter[filt_num].
  2752. byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
  2753. sizeof(ips[i]);
  2754. mef_entry->filter[filt_num].offset = 46;
  2755. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2756. if (filt_num) {
  2757. mef_entry->filter[filt_num].filt_action =
  2758. TYPE_OR;
  2759. }
  2760. filt_num++;
  2761. }
  2762. mef_entry->filter[filt_num].repeat = 1;
  2763. mef_entry->filter[filt_num].byte_seq[0] = 0x08;
  2764. mef_entry->filter[filt_num].byte_seq[1] = 0x06;
  2765. mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
  2766. mef_entry->filter[filt_num].offset = 20;
  2767. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2768. mef_entry->filter[filt_num].filt_action = TYPE_AND;
  2769. }
  2770. static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
  2771. struct mwifiex_ds_mef_cfg *mef_cfg,
  2772. struct mwifiex_mef_entry *mef_entry,
  2773. struct cfg80211_wowlan *wowlan)
  2774. {
  2775. int i, filt_num = 0, ret = 0;
  2776. bool first_pat = true;
  2777. u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
  2778. const u8 ipv4_mc_mac[] = {0x33, 0x33};
  2779. const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
  2780. mef_entry->mode = MEF_MODE_HOST_SLEEP;
  2781. mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
  2782. for (i = 0; i < wowlan->n_patterns; i++) {
  2783. memset(byte_seq, 0, sizeof(byte_seq));
  2784. if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
  2785. byte_seq,
  2786. MWIFIEX_MEF_MAX_BYTESEQ)) {
  2787. mwifiex_dbg(priv->adapter, ERROR,
  2788. "Pattern not supported\n");
  2789. return -EOPNOTSUPP;
  2790. }
  2791. if (!wowlan->patterns[i].pkt_offset) {
  2792. if (!(byte_seq[0] & 0x01) &&
  2793. (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
  2794. mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
  2795. continue;
  2796. } else if (is_broadcast_ether_addr(byte_seq)) {
  2797. mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
  2798. continue;
  2799. } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
  2800. (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
  2801. (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
  2802. (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
  2803. mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
  2804. continue;
  2805. }
  2806. }
  2807. mef_entry->filter[filt_num].repeat = 1;
  2808. mef_entry->filter[filt_num].offset =
  2809. wowlan->patterns[i].pkt_offset;
  2810. memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
  2811. sizeof(byte_seq));
  2812. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2813. if (first_pat) {
  2814. first_pat = false;
  2815. mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
  2816. } else {
  2817. mef_entry->filter[filt_num].filt_action = TYPE_AND;
  2818. }
  2819. filt_num++;
  2820. }
  2821. if (wowlan->magic_pkt) {
  2822. mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
  2823. mef_entry->filter[filt_num].repeat = 16;
  2824. memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
  2825. ETH_ALEN);
  2826. mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
  2827. ETH_ALEN;
  2828. mef_entry->filter[filt_num].offset = 28;
  2829. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2830. if (filt_num)
  2831. mef_entry->filter[filt_num].filt_action = TYPE_OR;
  2832. filt_num++;
  2833. mef_entry->filter[filt_num].repeat = 16;
  2834. memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
  2835. ETH_ALEN);
  2836. mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
  2837. ETH_ALEN;
  2838. mef_entry->filter[filt_num].offset = 56;
  2839. mef_entry->filter[filt_num].filt_type = TYPE_EQ;
  2840. mef_entry->filter[filt_num].filt_action = TYPE_OR;
  2841. mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
  2842. }
  2843. return ret;
  2844. }
  2845. static int mwifiex_set_mef_filter(struct mwifiex_private *priv,
  2846. struct cfg80211_wowlan *wowlan)
  2847. {
  2848. int ret = 0, num_entries = 1;
  2849. struct mwifiex_ds_mef_cfg mef_cfg;
  2850. struct mwifiex_mef_entry *mef_entry;
  2851. if (wowlan->n_patterns || wowlan->magic_pkt)
  2852. num_entries++;
  2853. mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
  2854. if (!mef_entry)
  2855. return -ENOMEM;
  2856. memset(&mef_cfg, 0, sizeof(mef_cfg));
  2857. mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
  2858. MWIFIEX_CRITERIA_UNICAST;
  2859. mef_cfg.num_entries = num_entries;
  2860. mef_cfg.mef_entry = mef_entry;
  2861. mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
  2862. if (wowlan->n_patterns || wowlan->magic_pkt) {
  2863. ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
  2864. &mef_entry[1], wowlan);
  2865. if (ret)
  2866. goto err;
  2867. }
  2868. if (!mef_cfg.criteria)
  2869. mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
  2870. MWIFIEX_CRITERIA_UNICAST |
  2871. MWIFIEX_CRITERIA_MULTICAST;
  2872. ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
  2873. HostCmd_ACT_GEN_SET, 0,
  2874. &mef_cfg, true);
  2875. err:
  2876. kfree(mef_entry);
  2877. return ret;
  2878. }
  2879. static int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
  2880. struct cfg80211_wowlan *wowlan)
  2881. {
  2882. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  2883. struct mwifiex_ds_hs_cfg hs_cfg;
  2884. int i, ret = 0, retry_num = 10;
  2885. struct mwifiex_private *priv;
  2886. struct mwifiex_private *sta_priv =
  2887. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
  2888. sta_priv->scan_aborting = true;
  2889. for (i = 0; i < adapter->priv_num; i++) {
  2890. priv = adapter->priv[i];
  2891. mwifiex_abort_cac(priv);
  2892. }
  2893. mwifiex_cancel_all_pending_cmd(adapter);
  2894. for (i = 0; i < adapter->priv_num; i++) {
  2895. priv = adapter->priv[i];
  2896. if (priv && priv->netdev) {
  2897. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  2898. if (netif_carrier_ok(priv->netdev))
  2899. netif_carrier_off(priv->netdev);
  2900. }
  2901. }
  2902. for (i = 0; i < retry_num; i++) {
  2903. if (!mwifiex_wmm_lists_empty(adapter) ||
  2904. !mwifiex_bypass_txlist_empty(adapter) ||
  2905. !skb_queue_empty(&adapter->tx_data_q))
  2906. usleep_range(10000, 15000);
  2907. else
  2908. break;
  2909. }
  2910. if (!wowlan) {
  2911. mwifiex_dbg(adapter, ERROR,
  2912. "None of the WOWLAN triggers enabled\n");
  2913. ret = 0;
  2914. goto done;
  2915. }
  2916. if (!sta_priv->media_connected && !wowlan->nd_config) {
  2917. mwifiex_dbg(adapter, ERROR,
  2918. "Can not configure WOWLAN in disconnected state\n");
  2919. ret = 0;
  2920. goto done;
  2921. }
  2922. ret = mwifiex_set_mef_filter(sta_priv, wowlan);
  2923. if (ret) {
  2924. mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
  2925. goto done;
  2926. }
  2927. memset(&hs_cfg, 0, sizeof(hs_cfg));
  2928. hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
  2929. if (wowlan->nd_config) {
  2930. mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
  2931. hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
  2932. mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
  2933. wowlan->nd_config);
  2934. }
  2935. if (wowlan->disconnect) {
  2936. hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
  2937. mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
  2938. }
  2939. hs_cfg.is_invoke_hostcmd = false;
  2940. hs_cfg.gpio = adapter->hs_cfg.gpio;
  2941. hs_cfg.gap = adapter->hs_cfg.gap;
  2942. ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
  2943. MWIFIEX_SYNC_CMD, &hs_cfg);
  2944. if (ret)
  2945. mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
  2946. done:
  2947. sta_priv->scan_aborting = false;
  2948. return ret;
  2949. }
  2950. static int mwifiex_cfg80211_resume(struct wiphy *wiphy)
  2951. {
  2952. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  2953. struct mwifiex_private *priv;
  2954. struct mwifiex_ds_wakeup_reason wakeup_reason;
  2955. struct cfg80211_wowlan_wakeup wakeup_report;
  2956. int i;
  2957. bool report_wakeup_reason = true;
  2958. for (i = 0; i < adapter->priv_num; i++) {
  2959. priv = adapter->priv[i];
  2960. if (priv && priv->netdev) {
  2961. if (!netif_carrier_ok(priv->netdev))
  2962. netif_carrier_on(priv->netdev);
  2963. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  2964. }
  2965. }
  2966. if (!wiphy->wowlan_config)
  2967. goto done;
  2968. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
  2969. mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
  2970. &wakeup_reason);
  2971. memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
  2972. wakeup_report.pattern_idx = -1;
  2973. switch (wakeup_reason.hs_wakeup_reason) {
  2974. case NO_HSWAKEUP_REASON:
  2975. break;
  2976. case BCAST_DATA_MATCHED:
  2977. break;
  2978. case MCAST_DATA_MATCHED:
  2979. break;
  2980. case UCAST_DATA_MATCHED:
  2981. break;
  2982. case MASKTABLE_EVENT_MATCHED:
  2983. break;
  2984. case NON_MASKABLE_EVENT_MATCHED:
  2985. if (wiphy->wowlan_config->disconnect)
  2986. wakeup_report.disconnect = true;
  2987. if (wiphy->wowlan_config->nd_config)
  2988. wakeup_report.net_detect = adapter->nd_info;
  2989. break;
  2990. case NON_MASKABLE_CONDITION_MATCHED:
  2991. break;
  2992. case MAGIC_PATTERN_MATCHED:
  2993. if (wiphy->wowlan_config->magic_pkt)
  2994. wakeup_report.magic_pkt = true;
  2995. if (wiphy->wowlan_config->n_patterns)
  2996. wakeup_report.pattern_idx = 1;
  2997. break;
  2998. case GTK_REKEY_FAILURE:
  2999. if (wiphy->wowlan_config->gtk_rekey_failure)
  3000. wakeup_report.gtk_rekey_failure = true;
  3001. break;
  3002. default:
  3003. report_wakeup_reason = false;
  3004. break;
  3005. }
  3006. if (report_wakeup_reason)
  3007. cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
  3008. GFP_KERNEL);
  3009. done:
  3010. if (adapter->nd_info) {
  3011. for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
  3012. kfree(adapter->nd_info->matches[i]);
  3013. kfree(adapter->nd_info);
  3014. adapter->nd_info = NULL;
  3015. }
  3016. return 0;
  3017. }
  3018. static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
  3019. bool enabled)
  3020. {
  3021. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  3022. device_set_wakeup_enable(adapter->dev, enabled);
  3023. }
  3024. static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
  3025. struct cfg80211_gtk_rekey_data *data)
  3026. {
  3027. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3028. return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
  3029. HostCmd_ACT_GEN_SET, 0, data, true);
  3030. }
  3031. #endif
  3032. static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
  3033. {
  3034. const u8 ipv4_mc_mac[] = {0x33, 0x33};
  3035. const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
  3036. const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
  3037. if ((byte_seq[0] & 0x01) &&
  3038. (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
  3039. return PACKET_TYPE_UNICAST;
  3040. else if (!memcmp(byte_seq, bc_mac, 4))
  3041. return PACKET_TYPE_BROADCAST;
  3042. else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
  3043. byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
  3044. (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
  3045. byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
  3046. return PACKET_TYPE_MULTICAST;
  3047. return 0;
  3048. }
  3049. static int
  3050. mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
  3051. struct cfg80211_coalesce_rules *crule,
  3052. struct mwifiex_coalesce_rule *mrule)
  3053. {
  3054. u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
  3055. struct filt_field_param *param;
  3056. int i;
  3057. mrule->max_coalescing_delay = crule->delay;
  3058. param = mrule->params;
  3059. for (i = 0; i < crule->n_patterns; i++) {
  3060. memset(byte_seq, 0, sizeof(byte_seq));
  3061. if (!mwifiex_is_pattern_supported(&crule->patterns[i],
  3062. byte_seq,
  3063. MWIFIEX_COALESCE_MAX_BYTESEQ)) {
  3064. mwifiex_dbg(priv->adapter, ERROR,
  3065. "Pattern not supported\n");
  3066. return -EOPNOTSUPP;
  3067. }
  3068. if (!crule->patterns[i].pkt_offset) {
  3069. u8 pkt_type;
  3070. pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
  3071. if (pkt_type && mrule->pkt_type) {
  3072. mwifiex_dbg(priv->adapter, ERROR,
  3073. "Multiple packet types not allowed\n");
  3074. return -EOPNOTSUPP;
  3075. } else if (pkt_type) {
  3076. mrule->pkt_type = pkt_type;
  3077. continue;
  3078. }
  3079. }
  3080. if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
  3081. param->operation = RECV_FILTER_MATCH_TYPE_EQ;
  3082. else
  3083. param->operation = RECV_FILTER_MATCH_TYPE_NE;
  3084. param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
  3085. memcpy(param->operand_byte_stream, byte_seq,
  3086. param->operand_len);
  3087. param->offset = crule->patterns[i].pkt_offset;
  3088. param++;
  3089. mrule->num_of_fields++;
  3090. }
  3091. if (!mrule->pkt_type) {
  3092. mwifiex_dbg(priv->adapter, ERROR,
  3093. "Packet type can not be determined\n");
  3094. return -EOPNOTSUPP;
  3095. }
  3096. return 0;
  3097. }
  3098. static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
  3099. struct cfg80211_coalesce *coalesce)
  3100. {
  3101. struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
  3102. int i, ret;
  3103. struct mwifiex_ds_coalesce_cfg coalesce_cfg;
  3104. struct mwifiex_private *priv =
  3105. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
  3106. memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
  3107. if (!coalesce) {
  3108. mwifiex_dbg(adapter, WARN,
  3109. "Disable coalesce and reset all previous rules\n");
  3110. return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
  3111. HostCmd_ACT_GEN_SET, 0,
  3112. &coalesce_cfg, true);
  3113. }
  3114. coalesce_cfg.num_of_rules = coalesce->n_rules;
  3115. for (i = 0; i < coalesce->n_rules; i++) {
  3116. ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
  3117. &coalesce_cfg.rule[i]);
  3118. if (ret) {
  3119. mwifiex_dbg(adapter, ERROR,
  3120. "Recheck the patterns provided for rule %d\n",
  3121. i + 1);
  3122. return ret;
  3123. }
  3124. }
  3125. return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
  3126. HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
  3127. }
  3128. /* cfg80211 ops handler for tdls_mgmt.
  3129. * Function prepares TDLS action frame packets and forwards them to FW
  3130. */
  3131. static int
  3132. mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  3133. const u8 *peer, u8 action_code, u8 dialog_token,
  3134. u16 status_code, u32 peer_capability,
  3135. bool initiator, const u8 *extra_ies,
  3136. size_t extra_ies_len)
  3137. {
  3138. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3139. int ret;
  3140. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  3141. return -ENOTSUPP;
  3142. /* make sure we are in station mode and connected */
  3143. if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
  3144. return -ENOTSUPP;
  3145. switch (action_code) {
  3146. case WLAN_TDLS_SETUP_REQUEST:
  3147. mwifiex_dbg(priv->adapter, MSG,
  3148. "Send TDLS Setup Request to %pM status_code=%d\n",
  3149. peer, status_code);
  3150. mwifiex_add_auto_tdls_peer(priv, peer);
  3151. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3152. dialog_token, status_code,
  3153. extra_ies, extra_ies_len);
  3154. break;
  3155. case WLAN_TDLS_SETUP_RESPONSE:
  3156. mwifiex_add_auto_tdls_peer(priv, peer);
  3157. mwifiex_dbg(priv->adapter, MSG,
  3158. "Send TDLS Setup Response to %pM status_code=%d\n",
  3159. peer, status_code);
  3160. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3161. dialog_token, status_code,
  3162. extra_ies, extra_ies_len);
  3163. break;
  3164. case WLAN_TDLS_SETUP_CONFIRM:
  3165. mwifiex_dbg(priv->adapter, MSG,
  3166. "Send TDLS Confirm to %pM status_code=%d\n", peer,
  3167. status_code);
  3168. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3169. dialog_token, status_code,
  3170. extra_ies, extra_ies_len);
  3171. break;
  3172. case WLAN_TDLS_TEARDOWN:
  3173. mwifiex_dbg(priv->adapter, MSG,
  3174. "Send TDLS Tear down to %pM\n", peer);
  3175. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3176. dialog_token, status_code,
  3177. extra_ies, extra_ies_len);
  3178. break;
  3179. case WLAN_TDLS_DISCOVERY_REQUEST:
  3180. mwifiex_dbg(priv->adapter, MSG,
  3181. "Send TDLS Discovery Request to %pM\n", peer);
  3182. ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
  3183. dialog_token, status_code,
  3184. extra_ies, extra_ies_len);
  3185. break;
  3186. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  3187. mwifiex_dbg(priv->adapter, MSG,
  3188. "Send TDLS Discovery Response to %pM\n", peer);
  3189. ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
  3190. dialog_token, status_code,
  3191. extra_ies, extra_ies_len);
  3192. break;
  3193. default:
  3194. mwifiex_dbg(priv->adapter, ERROR,
  3195. "Unknown TDLS mgmt/action frame %pM\n", peer);
  3196. ret = -EINVAL;
  3197. break;
  3198. }
  3199. return ret;
  3200. }
  3201. static int
  3202. mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  3203. const u8 *peer, enum nl80211_tdls_operation action)
  3204. {
  3205. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3206. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  3207. !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
  3208. return -ENOTSUPP;
  3209. /* make sure we are in station mode and connected */
  3210. if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
  3211. return -ENOTSUPP;
  3212. mwifiex_dbg(priv->adapter, MSG,
  3213. "TDLS peer=%pM, oper=%d\n", peer, action);
  3214. switch (action) {
  3215. case NL80211_TDLS_ENABLE_LINK:
  3216. action = MWIFIEX_TDLS_ENABLE_LINK;
  3217. break;
  3218. case NL80211_TDLS_DISABLE_LINK:
  3219. action = MWIFIEX_TDLS_DISABLE_LINK;
  3220. break;
  3221. case NL80211_TDLS_TEARDOWN:
  3222. /* shouldn't happen!*/
  3223. mwifiex_dbg(priv->adapter, ERROR,
  3224. "tdls_oper: teardown from driver not supported\n");
  3225. return -EINVAL;
  3226. case NL80211_TDLS_SETUP:
  3227. /* shouldn't happen!*/
  3228. mwifiex_dbg(priv->adapter, ERROR,
  3229. "tdls_oper: setup from driver not supported\n");
  3230. return -EINVAL;
  3231. case NL80211_TDLS_DISCOVERY_REQ:
  3232. /* shouldn't happen!*/
  3233. mwifiex_dbg(priv->adapter, ERROR,
  3234. "tdls_oper: discovery from driver not supported\n");
  3235. return -EINVAL;
  3236. default:
  3237. mwifiex_dbg(priv->adapter, ERROR,
  3238. "tdls_oper: operation not supported\n");
  3239. return -ENOTSUPP;
  3240. }
  3241. return mwifiex_tdls_oper(priv, peer, action);
  3242. }
  3243. static int
  3244. mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
  3245. const u8 *addr, u8 oper_class,
  3246. struct cfg80211_chan_def *chandef)
  3247. {
  3248. struct mwifiex_sta_node *sta_ptr;
  3249. unsigned long flags;
  3250. u16 chan;
  3251. u8 second_chan_offset, band;
  3252. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3253. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  3254. sta_ptr = mwifiex_get_sta_entry(priv, addr);
  3255. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  3256. if (!sta_ptr) {
  3257. wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
  3258. __func__, addr);
  3259. return -ENOENT;
  3260. }
  3261. if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
  3262. WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
  3263. wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
  3264. return -ENOENT;
  3265. }
  3266. if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
  3267. sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
  3268. wiphy_err(wiphy, "channel switch is running, abort request\n");
  3269. return -EALREADY;
  3270. }
  3271. chan = chandef->chan->hw_value;
  3272. second_chan_offset = mwifiex_get_sec_chan_offset(chan);
  3273. band = chandef->chan->band;
  3274. mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
  3275. return 0;
  3276. }
  3277. static void
  3278. mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
  3279. struct net_device *dev,
  3280. const u8 *addr)
  3281. {
  3282. struct mwifiex_sta_node *sta_ptr;
  3283. unsigned long flags;
  3284. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3285. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  3286. sta_ptr = mwifiex_get_sta_entry(priv, addr);
  3287. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  3288. if (!sta_ptr) {
  3289. wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
  3290. __func__, addr);
  3291. } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
  3292. sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
  3293. sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
  3294. wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
  3295. addr);
  3296. } else
  3297. mwifiex_stop_tdls_cs(priv, addr);
  3298. }
  3299. static int
  3300. mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  3301. const u8 *mac, struct station_parameters *params)
  3302. {
  3303. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3304. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3305. return -ENOTSUPP;
  3306. /* make sure we are in station mode and connected */
  3307. if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
  3308. return -ENOTSUPP;
  3309. return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
  3310. }
  3311. static int
  3312. mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  3313. struct cfg80211_csa_settings *params)
  3314. {
  3315. struct ieee_types_header *chsw_ie;
  3316. struct ieee80211_channel_sw_ie *channel_sw;
  3317. int chsw_msec;
  3318. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3319. if (priv->adapter->scan_processing) {
  3320. mwifiex_dbg(priv->adapter, ERROR,
  3321. "radar detection: scan in process...\n");
  3322. return -EBUSY;
  3323. }
  3324. if (priv->wdev.cac_started)
  3325. return -EBUSY;
  3326. if (cfg80211_chandef_identical(&params->chandef,
  3327. &priv->dfs_chandef))
  3328. return -EINVAL;
  3329. chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
  3330. params->beacon_csa.tail,
  3331. params->beacon_csa.tail_len);
  3332. if (!chsw_ie) {
  3333. mwifiex_dbg(priv->adapter, ERROR,
  3334. "Could not parse channel switch announcement IE\n");
  3335. return -EINVAL;
  3336. }
  3337. channel_sw = (void *)(chsw_ie + 1);
  3338. if (channel_sw->mode) {
  3339. if (netif_carrier_ok(priv->netdev))
  3340. netif_carrier_off(priv->netdev);
  3341. mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
  3342. }
  3343. if (mwifiex_del_mgmt_ies(priv))
  3344. mwifiex_dbg(priv->adapter, ERROR,
  3345. "Failed to delete mgmt IEs!\n");
  3346. if (mwifiex_set_mgmt_ies(priv, &params->beacon_csa)) {
  3347. mwifiex_dbg(priv->adapter, ERROR,
  3348. "%s: setting mgmt ies failed\n", __func__);
  3349. return -EFAULT;
  3350. }
  3351. memcpy(&priv->dfs_chandef, &params->chandef, sizeof(priv->dfs_chandef));
  3352. memcpy(&priv->beacon_after, &params->beacon_after,
  3353. sizeof(priv->beacon_after));
  3354. chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
  3355. queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
  3356. msecs_to_jiffies(chsw_msec));
  3357. return 0;
  3358. }
  3359. static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
  3360. struct wireless_dev *wdev,
  3361. struct cfg80211_chan_def *chandef)
  3362. {
  3363. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  3364. struct mwifiex_bssdescriptor *curr_bss;
  3365. struct ieee80211_channel *chan;
  3366. u8 second_chan_offset;
  3367. enum nl80211_channel_type chan_type;
  3368. enum nl80211_band band;
  3369. int freq;
  3370. int ret = -ENODATA;
  3371. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
  3372. cfg80211_chandef_valid(&priv->bss_chandef)) {
  3373. *chandef = priv->bss_chandef;
  3374. ret = 0;
  3375. } else if (priv->media_connected) {
  3376. curr_bss = &priv->curr_bss_params.bss_descriptor;
  3377. band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  3378. freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
  3379. chan = ieee80211_get_channel(wiphy, freq);
  3380. if (priv->ht_param_present) {
  3381. second_chan_offset = priv->assoc_resp_ht_param &
  3382. IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
  3383. chan_type = mwifiex_sec_chan_offset_to_chan_type
  3384. (second_chan_offset);
  3385. cfg80211_chandef_create(chandef, chan, chan_type);
  3386. } else {
  3387. cfg80211_chandef_create(chandef, chan,
  3388. NL80211_CHAN_NO_HT);
  3389. }
  3390. ret = 0;
  3391. }
  3392. return ret;
  3393. }
  3394. #ifdef CONFIG_NL80211_TESTMODE
  3395. enum mwifiex_tm_attr {
  3396. __MWIFIEX_TM_ATTR_INVALID = 0,
  3397. MWIFIEX_TM_ATTR_CMD = 1,
  3398. MWIFIEX_TM_ATTR_DATA = 2,
  3399. /* keep last */
  3400. __MWIFIEX_TM_ATTR_AFTER_LAST,
  3401. MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
  3402. };
  3403. static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
  3404. [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 },
  3405. [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY,
  3406. .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
  3407. };
  3408. enum mwifiex_tm_command {
  3409. MWIFIEX_TM_CMD_HOSTCMD = 0,
  3410. };
  3411. static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
  3412. void *data, int len)
  3413. {
  3414. struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
  3415. struct mwifiex_ds_misc_cmd *hostcmd;
  3416. struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
  3417. struct mwifiex_adapter *adapter;
  3418. struct sk_buff *skb;
  3419. int err;
  3420. if (!priv)
  3421. return -EINVAL;
  3422. adapter = priv->adapter;
  3423. err = nla_parse(tb, MWIFIEX_TM_ATTR_MAX, data, len,
  3424. mwifiex_tm_policy);
  3425. if (err)
  3426. return err;
  3427. if (!tb[MWIFIEX_TM_ATTR_CMD])
  3428. return -EINVAL;
  3429. switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
  3430. case MWIFIEX_TM_CMD_HOSTCMD:
  3431. if (!tb[MWIFIEX_TM_ATTR_DATA])
  3432. return -EINVAL;
  3433. hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
  3434. if (!hostcmd)
  3435. return -ENOMEM;
  3436. hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
  3437. memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
  3438. hostcmd->len);
  3439. if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
  3440. dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
  3441. return -EFAULT;
  3442. }
  3443. /* process hostcmd response*/
  3444. skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
  3445. if (!skb)
  3446. return -ENOMEM;
  3447. err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
  3448. hostcmd->len, hostcmd->cmd);
  3449. if (err) {
  3450. kfree_skb(skb);
  3451. return -EMSGSIZE;
  3452. }
  3453. err = cfg80211_testmode_reply(skb);
  3454. kfree(hostcmd);
  3455. return err;
  3456. default:
  3457. return -EOPNOTSUPP;
  3458. }
  3459. }
  3460. #endif
  3461. static int
  3462. mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
  3463. struct net_device *dev,
  3464. struct cfg80211_chan_def *chandef,
  3465. u32 cac_time_ms)
  3466. {
  3467. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3468. struct mwifiex_radar_params radar_params;
  3469. if (priv->adapter->scan_processing) {
  3470. mwifiex_dbg(priv->adapter, ERROR,
  3471. "radar detection: scan already in process...\n");
  3472. return -EBUSY;
  3473. }
  3474. if (!mwifiex_is_11h_active(priv)) {
  3475. mwifiex_dbg(priv->adapter, INFO,
  3476. "Enable 11h extensions in FW\n");
  3477. if (mwifiex_11h_activate(priv, true)) {
  3478. mwifiex_dbg(priv->adapter, ERROR,
  3479. "Failed to activate 11h extensions!!");
  3480. return -1;
  3481. }
  3482. priv->state_11h.is_11h_active = true;
  3483. }
  3484. memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
  3485. radar_params.chandef = chandef;
  3486. radar_params.cac_time_ms = cac_time_ms;
  3487. memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
  3488. if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
  3489. HostCmd_ACT_GEN_SET, 0, &radar_params, true))
  3490. return -1;
  3491. queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
  3492. msecs_to_jiffies(cac_time_ms));
  3493. return 0;
  3494. }
  3495. static int
  3496. mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
  3497. const u8 *mac,
  3498. struct station_parameters *params)
  3499. {
  3500. int ret;
  3501. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  3502. /* we support change_station handler only for TDLS peers*/
  3503. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3504. return -ENOTSUPP;
  3505. /* make sure we are in station mode and connected */
  3506. if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
  3507. return -ENOTSUPP;
  3508. priv->sta_params = params;
  3509. ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
  3510. priv->sta_params = NULL;
  3511. return ret;
  3512. }
  3513. /* station cfg80211 operations */
  3514. static struct cfg80211_ops mwifiex_cfg80211_ops = {
  3515. .add_virtual_intf = mwifiex_add_virtual_intf,
  3516. .del_virtual_intf = mwifiex_del_virtual_intf,
  3517. .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
  3518. .scan = mwifiex_cfg80211_scan,
  3519. .connect = mwifiex_cfg80211_connect,
  3520. .disconnect = mwifiex_cfg80211_disconnect,
  3521. .get_station = mwifiex_cfg80211_get_station,
  3522. .dump_station = mwifiex_cfg80211_dump_station,
  3523. .dump_survey = mwifiex_cfg80211_dump_survey,
  3524. .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
  3525. .join_ibss = mwifiex_cfg80211_join_ibss,
  3526. .leave_ibss = mwifiex_cfg80211_leave_ibss,
  3527. .add_key = mwifiex_cfg80211_add_key,
  3528. .del_key = mwifiex_cfg80211_del_key,
  3529. .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
  3530. .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
  3531. .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
  3532. .remain_on_channel = mwifiex_cfg80211_remain_on_channel,
  3533. .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
  3534. .set_default_key = mwifiex_cfg80211_set_default_key,
  3535. .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
  3536. .set_tx_power = mwifiex_cfg80211_set_tx_power,
  3537. .get_tx_power = mwifiex_cfg80211_get_tx_power,
  3538. .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
  3539. .start_ap = mwifiex_cfg80211_start_ap,
  3540. .stop_ap = mwifiex_cfg80211_stop_ap,
  3541. .change_beacon = mwifiex_cfg80211_change_beacon,
  3542. .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
  3543. .set_antenna = mwifiex_cfg80211_set_antenna,
  3544. .get_antenna = mwifiex_cfg80211_get_antenna,
  3545. .del_station = mwifiex_cfg80211_del_station,
  3546. .sched_scan_start = mwifiex_cfg80211_sched_scan_start,
  3547. .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
  3548. #ifdef CONFIG_PM
  3549. .suspend = mwifiex_cfg80211_suspend,
  3550. .resume = mwifiex_cfg80211_resume,
  3551. .set_wakeup = mwifiex_cfg80211_set_wakeup,
  3552. .set_rekey_data = mwifiex_set_rekey_data,
  3553. #endif
  3554. .set_coalesce = mwifiex_cfg80211_set_coalesce,
  3555. .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
  3556. .tdls_oper = mwifiex_cfg80211_tdls_oper,
  3557. .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
  3558. .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
  3559. .add_station = mwifiex_cfg80211_add_station,
  3560. .change_station = mwifiex_cfg80211_change_station,
  3561. CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
  3562. .get_channel = mwifiex_cfg80211_get_channel,
  3563. .start_radar_detection = mwifiex_cfg80211_start_radar_detection,
  3564. .channel_switch = mwifiex_cfg80211_channel_switch,
  3565. };
  3566. #ifdef CONFIG_PM
  3567. static const struct wiphy_wowlan_support mwifiex_wowlan_support = {
  3568. .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
  3569. WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  3570. WIPHY_WOWLAN_GTK_REKEY_FAILURE,
  3571. .n_patterns = MWIFIEX_MEF_MAX_FILTERS,
  3572. .pattern_min_len = 1,
  3573. .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
  3574. .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
  3575. .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
  3576. };
  3577. #endif
  3578. static bool mwifiex_is_valid_alpha2(const char *alpha2)
  3579. {
  3580. if (!alpha2 || strlen(alpha2) != 2)
  3581. return false;
  3582. if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
  3583. return true;
  3584. return false;
  3585. }
  3586. static const struct wiphy_coalesce_support mwifiex_coalesce_support = {
  3587. .n_rules = MWIFIEX_COALESCE_MAX_RULES,
  3588. .max_delay = MWIFIEX_MAX_COALESCING_DELAY,
  3589. .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
  3590. .pattern_min_len = 1,
  3591. .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
  3592. .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
  3593. };
  3594. int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
  3595. {
  3596. u32 n_channels_bg, n_channels_a = 0;
  3597. n_channels_bg = mwifiex_band_2ghz.n_channels;
  3598. if (adapter->config_bands & BAND_A)
  3599. n_channels_a = mwifiex_band_5ghz.n_channels;
  3600. adapter->num_in_chan_stats = n_channels_bg + n_channels_a;
  3601. adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
  3602. adapter->num_in_chan_stats);
  3603. if (!adapter->chan_stats)
  3604. return -ENOMEM;
  3605. return 0;
  3606. }
  3607. /*
  3608. * This function registers the device with CFG802.11 subsystem.
  3609. *
  3610. * The function creates the wireless device/wiphy, populates it with
  3611. * default parameters and handler function pointers, and finally
  3612. * registers the device.
  3613. */
  3614. int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
  3615. {
  3616. int ret;
  3617. void *wdev_priv;
  3618. struct wiphy *wiphy;
  3619. struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
  3620. u8 *country_code;
  3621. u32 thr, retry;
  3622. /* create a new wiphy for use with cfg80211 */
  3623. wiphy = wiphy_new(&mwifiex_cfg80211_ops,
  3624. sizeof(struct mwifiex_adapter *));
  3625. if (!wiphy) {
  3626. mwifiex_dbg(adapter, ERROR,
  3627. "%s: creating new wiphy\n", __func__);
  3628. return -ENOMEM;
  3629. }
  3630. wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
  3631. wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
  3632. wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
  3633. wiphy->max_remain_on_channel_duration = 5000;
  3634. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  3635. BIT(NL80211_IFTYPE_ADHOC) |
  3636. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  3637. BIT(NL80211_IFTYPE_P2P_GO) |
  3638. BIT(NL80211_IFTYPE_AP);
  3639. wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
  3640. if (adapter->config_bands & BAND_A)
  3641. wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
  3642. else
  3643. wiphy->bands[NL80211_BAND_5GHZ] = NULL;
  3644. if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
  3645. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
  3646. else if (adapter->is_hw_11ac_capable)
  3647. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
  3648. else
  3649. wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
  3650. wiphy->n_iface_combinations = 1;
  3651. /* Initialize cipher suits */
  3652. wiphy->cipher_suites = mwifiex_cipher_suites;
  3653. wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
  3654. if (adapter->regd) {
  3655. wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
  3656. REGULATORY_DISABLE_BEACON_HINTS |
  3657. REGULATORY_COUNTRY_IE_IGNORE;
  3658. wiphy_apply_custom_regulatory(wiphy, adapter->regd);
  3659. }
  3660. ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
  3661. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  3662. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  3663. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
  3664. WIPHY_FLAG_AP_UAPSD |
  3665. WIPHY_FLAG_SUPPORTS_SCHED_SCAN |
  3666. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  3667. WIPHY_FLAG_HAS_CHANNEL_SWITCH |
  3668. WIPHY_FLAG_PS_ON_BY_DEFAULT;
  3669. if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
  3670. wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
  3671. WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  3672. #ifdef CONFIG_PM
  3673. wiphy->wowlan = &mwifiex_wowlan_support;
  3674. #endif
  3675. wiphy->coalesce = &mwifiex_coalesce_support;
  3676. wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  3677. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  3678. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  3679. wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
  3680. wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
  3681. wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
  3682. wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
  3683. wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
  3684. wiphy->features |= NL80211_FEATURE_HT_IBSS |
  3685. NL80211_FEATURE_INACTIVITY_TIMER |
  3686. NL80211_FEATURE_LOW_PRIORITY_SCAN |
  3687. NL80211_FEATURE_NEED_OBSS_SCAN |
  3688. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
  3689. NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
  3690. NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  3691. if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
  3692. wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
  3693. if (adapter->fw_api_ver == MWIFIEX_FW_V15)
  3694. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  3695. /* Reserve space for mwifiex specific private data for BSS */
  3696. wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
  3697. wiphy->reg_notifier = mwifiex_reg_notifier;
  3698. /* Set struct mwifiex_adapter pointer in wiphy_priv */
  3699. wdev_priv = wiphy_priv(wiphy);
  3700. *(unsigned long *)wdev_priv = (unsigned long)adapter;
  3701. set_wiphy_dev(wiphy, priv->adapter->dev);
  3702. ret = wiphy_register(wiphy);
  3703. if (ret < 0) {
  3704. mwifiex_dbg(adapter, ERROR,
  3705. "%s: wiphy_register failed: %d\n", __func__, ret);
  3706. wiphy_free(wiphy);
  3707. return ret;
  3708. }
  3709. if (!adapter->regd) {
  3710. if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
  3711. mwifiex_dbg(adapter, INFO,
  3712. "driver hint alpha2: %2.2s\n", reg_alpha2);
  3713. regulatory_hint(wiphy, reg_alpha2);
  3714. } else {
  3715. if (adapter->region_code == 0x00) {
  3716. mwifiex_dbg(adapter, WARN,
  3717. "Ignore world regulatory domain\n");
  3718. } else {
  3719. wiphy->regulatory_flags |=
  3720. REGULATORY_DISABLE_BEACON_HINTS |
  3721. REGULATORY_COUNTRY_IE_IGNORE;
  3722. country_code =
  3723. mwifiex_11d_code_2_region(
  3724. adapter->region_code);
  3725. if (country_code &&
  3726. regulatory_hint(wiphy, country_code))
  3727. mwifiex_dbg(priv->adapter, ERROR,
  3728. "regulatory_hint() failed\n");
  3729. }
  3730. }
  3731. }
  3732. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3733. HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
  3734. wiphy->frag_threshold = thr;
  3735. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3736. HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
  3737. wiphy->rts_threshold = thr;
  3738. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3739. HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
  3740. wiphy->retry_short = (u8) retry;
  3741. mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  3742. HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
  3743. wiphy->retry_long = (u8) retry;
  3744. adapter->wiphy = wiphy;
  3745. return ret;
  3746. }