cfg.c 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2015 Intel Mobile Communications GmbH
  6. * Copyright (C) 2015-2017 Intel Deutschland GmbH
  7. * Copyright (C) 2018 Intel Corporation
  8. *
  9. * This file is GPLv2 as found in COPYING.
  10. */
  11. #include <linux/ieee80211.h>
  12. #include <linux/nl80211.h>
  13. #include <linux/rtnetlink.h>
  14. #include <linux/slab.h>
  15. #include <net/net_namespace.h>
  16. #include <linux/rcupdate.h>
  17. #include <linux/if_ether.h>
  18. #include <net/cfg80211.h>
  19. #include "ieee80211_i.h"
  20. #include "driver-ops.h"
  21. #include "rate.h"
  22. #include "mesh.h"
  23. #include "wme.h"
  24. static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
  25. struct vif_params *params)
  26. {
  27. bool mu_mimo_groups = false;
  28. bool mu_mimo_follow = false;
  29. if (params->vht_mumimo_groups) {
  30. u64 membership;
  31. BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
  32. memcpy(sdata->vif.bss_conf.mu_group.membership,
  33. params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
  34. memcpy(sdata->vif.bss_conf.mu_group.position,
  35. params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
  36. WLAN_USER_POSITION_LEN);
  37. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
  38. /* don't care about endianness - just check for 0 */
  39. memcpy(&membership, params->vht_mumimo_groups,
  40. WLAN_MEMBERSHIP_LEN);
  41. mu_mimo_groups = membership != 0;
  42. }
  43. if (params->vht_mumimo_follow_addr) {
  44. mu_mimo_follow =
  45. is_valid_ether_addr(params->vht_mumimo_follow_addr);
  46. ether_addr_copy(sdata->u.mntr.mu_follow_addr,
  47. params->vht_mumimo_follow_addr);
  48. }
  49. sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
  50. }
  51. static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
  52. struct vif_params *params)
  53. {
  54. struct ieee80211_local *local = sdata->local;
  55. struct ieee80211_sub_if_data *monitor_sdata;
  56. /* check flags first */
  57. if (params->flags && ieee80211_sdata_running(sdata)) {
  58. u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
  59. /*
  60. * Prohibit MONITOR_FLAG_COOK_FRAMES and
  61. * MONITOR_FLAG_ACTIVE to be changed while the
  62. * interface is up.
  63. * Else we would need to add a lot of cruft
  64. * to update everything:
  65. * cooked_mntrs, monitor and all fif_* counters
  66. * reconfigure hardware
  67. */
  68. if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
  69. return -EBUSY;
  70. }
  71. /* also validate MU-MIMO change */
  72. monitor_sdata = rtnl_dereference(local->monitor_sdata);
  73. if (!monitor_sdata &&
  74. (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
  75. return -EOPNOTSUPP;
  76. /* apply all changes now - no failures allowed */
  77. if (monitor_sdata)
  78. ieee80211_set_mu_mimo_follow(monitor_sdata, params);
  79. if (params->flags) {
  80. if (ieee80211_sdata_running(sdata)) {
  81. ieee80211_adjust_monitor_flags(sdata, -1);
  82. sdata->u.mntr.flags = params->flags;
  83. ieee80211_adjust_monitor_flags(sdata, 1);
  84. ieee80211_configure_filter(local);
  85. } else {
  86. /*
  87. * Because the interface is down, ieee80211_do_stop
  88. * and ieee80211_do_open take care of "everything"
  89. * mentioned in the comment above.
  90. */
  91. sdata->u.mntr.flags = params->flags;
  92. }
  93. }
  94. return 0;
  95. }
  96. static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
  97. const char *name,
  98. unsigned char name_assign_type,
  99. enum nl80211_iftype type,
  100. struct vif_params *params)
  101. {
  102. struct ieee80211_local *local = wiphy_priv(wiphy);
  103. struct wireless_dev *wdev;
  104. struct ieee80211_sub_if_data *sdata;
  105. int err;
  106. err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
  107. if (err)
  108. return ERR_PTR(err);
  109. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  110. if (type == NL80211_IFTYPE_MONITOR) {
  111. err = ieee80211_set_mon_options(sdata, params);
  112. if (err) {
  113. ieee80211_if_remove(sdata);
  114. return NULL;
  115. }
  116. }
  117. return wdev;
  118. }
  119. static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
  120. {
  121. ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
  122. return 0;
  123. }
  124. static int ieee80211_change_iface(struct wiphy *wiphy,
  125. struct net_device *dev,
  126. enum nl80211_iftype type,
  127. struct vif_params *params)
  128. {
  129. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  130. int ret;
  131. ret = ieee80211_if_change_type(sdata, type);
  132. if (ret)
  133. return ret;
  134. if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
  135. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  136. ieee80211_check_fast_rx_iface(sdata);
  137. } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
  138. sdata->u.mgd.use_4addr = params->use_4addr;
  139. }
  140. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  141. ret = ieee80211_set_mon_options(sdata, params);
  142. if (ret)
  143. return ret;
  144. }
  145. return 0;
  146. }
  147. static int ieee80211_start_p2p_device(struct wiphy *wiphy,
  148. struct wireless_dev *wdev)
  149. {
  150. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  151. int ret;
  152. mutex_lock(&sdata->local->chanctx_mtx);
  153. ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
  154. mutex_unlock(&sdata->local->chanctx_mtx);
  155. if (ret < 0)
  156. return ret;
  157. return ieee80211_do_open(wdev, true);
  158. }
  159. static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
  160. struct wireless_dev *wdev)
  161. {
  162. ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
  163. }
  164. static int ieee80211_start_nan(struct wiphy *wiphy,
  165. struct wireless_dev *wdev,
  166. struct cfg80211_nan_conf *conf)
  167. {
  168. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  169. int ret;
  170. mutex_lock(&sdata->local->chanctx_mtx);
  171. ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
  172. mutex_unlock(&sdata->local->chanctx_mtx);
  173. if (ret < 0)
  174. return ret;
  175. ret = ieee80211_do_open(wdev, true);
  176. if (ret)
  177. return ret;
  178. ret = drv_start_nan(sdata->local, sdata, conf);
  179. if (ret)
  180. ieee80211_sdata_stop(sdata);
  181. sdata->u.nan.conf = *conf;
  182. return ret;
  183. }
  184. static void ieee80211_stop_nan(struct wiphy *wiphy,
  185. struct wireless_dev *wdev)
  186. {
  187. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  188. drv_stop_nan(sdata->local, sdata);
  189. ieee80211_sdata_stop(sdata);
  190. }
  191. static int ieee80211_nan_change_conf(struct wiphy *wiphy,
  192. struct wireless_dev *wdev,
  193. struct cfg80211_nan_conf *conf,
  194. u32 changes)
  195. {
  196. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  197. struct cfg80211_nan_conf new_conf;
  198. int ret = 0;
  199. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  200. return -EOPNOTSUPP;
  201. if (!ieee80211_sdata_running(sdata))
  202. return -ENETDOWN;
  203. new_conf = sdata->u.nan.conf;
  204. if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
  205. new_conf.master_pref = conf->master_pref;
  206. if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
  207. new_conf.bands = conf->bands;
  208. ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
  209. if (!ret)
  210. sdata->u.nan.conf = new_conf;
  211. return ret;
  212. }
  213. static int ieee80211_add_nan_func(struct wiphy *wiphy,
  214. struct wireless_dev *wdev,
  215. struct cfg80211_nan_func *nan_func)
  216. {
  217. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  218. int ret;
  219. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  220. return -EOPNOTSUPP;
  221. if (!ieee80211_sdata_running(sdata))
  222. return -ENETDOWN;
  223. spin_lock_bh(&sdata->u.nan.func_lock);
  224. ret = idr_alloc(&sdata->u.nan.function_inst_ids,
  225. nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
  226. GFP_ATOMIC);
  227. spin_unlock_bh(&sdata->u.nan.func_lock);
  228. if (ret < 0)
  229. return ret;
  230. nan_func->instance_id = ret;
  231. WARN_ON(nan_func->instance_id == 0);
  232. ret = drv_add_nan_func(sdata->local, sdata, nan_func);
  233. if (ret) {
  234. spin_lock_bh(&sdata->u.nan.func_lock);
  235. idr_remove(&sdata->u.nan.function_inst_ids,
  236. nan_func->instance_id);
  237. spin_unlock_bh(&sdata->u.nan.func_lock);
  238. }
  239. return ret;
  240. }
  241. static struct cfg80211_nan_func *
  242. ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
  243. u64 cookie)
  244. {
  245. struct cfg80211_nan_func *func;
  246. int id;
  247. lockdep_assert_held(&sdata->u.nan.func_lock);
  248. idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
  249. if (func->cookie == cookie)
  250. return func;
  251. }
  252. return NULL;
  253. }
  254. static void ieee80211_del_nan_func(struct wiphy *wiphy,
  255. struct wireless_dev *wdev, u64 cookie)
  256. {
  257. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  258. struct cfg80211_nan_func *func;
  259. u8 instance_id = 0;
  260. if (sdata->vif.type != NL80211_IFTYPE_NAN ||
  261. !ieee80211_sdata_running(sdata))
  262. return;
  263. spin_lock_bh(&sdata->u.nan.func_lock);
  264. func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
  265. if (func)
  266. instance_id = func->instance_id;
  267. spin_unlock_bh(&sdata->u.nan.func_lock);
  268. if (instance_id)
  269. drv_del_nan_func(sdata->local, sdata, instance_id);
  270. }
  271. static int ieee80211_set_noack_map(struct wiphy *wiphy,
  272. struct net_device *dev,
  273. u16 noack_map)
  274. {
  275. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  276. sdata->noack_map = noack_map;
  277. ieee80211_check_fast_xmit_iface(sdata);
  278. return 0;
  279. }
  280. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  281. u8 key_idx, bool pairwise, const u8 *mac_addr,
  282. struct key_params *params)
  283. {
  284. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  285. struct ieee80211_local *local = sdata->local;
  286. struct sta_info *sta = NULL;
  287. const struct ieee80211_cipher_scheme *cs = NULL;
  288. struct ieee80211_key *key;
  289. int err;
  290. if (!ieee80211_sdata_running(sdata))
  291. return -ENETDOWN;
  292. /* reject WEP and TKIP keys if WEP failed to initialize */
  293. switch (params->cipher) {
  294. case WLAN_CIPHER_SUITE_WEP40:
  295. case WLAN_CIPHER_SUITE_TKIP:
  296. case WLAN_CIPHER_SUITE_WEP104:
  297. if (IS_ERR(local->wep_tx_tfm))
  298. return -EINVAL;
  299. break;
  300. case WLAN_CIPHER_SUITE_CCMP:
  301. case WLAN_CIPHER_SUITE_CCMP_256:
  302. case WLAN_CIPHER_SUITE_AES_CMAC:
  303. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  304. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  305. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  306. case WLAN_CIPHER_SUITE_GCMP:
  307. case WLAN_CIPHER_SUITE_GCMP_256:
  308. break;
  309. default:
  310. cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
  311. break;
  312. }
  313. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  314. params->key, params->seq_len, params->seq,
  315. cs);
  316. if (IS_ERR(key))
  317. return PTR_ERR(key);
  318. if (pairwise)
  319. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  320. mutex_lock(&local->sta_mtx);
  321. if (mac_addr) {
  322. sta = sta_info_get_bss(sdata, mac_addr);
  323. /*
  324. * The ASSOC test makes sure the driver is ready to
  325. * receive the key. When wpa_supplicant has roamed
  326. * using FT, it attempts to set the key before
  327. * association has completed, this rejects that attempt
  328. * so it will set the key again after association.
  329. *
  330. * TODO: accept the key if we have a station entry and
  331. * add it to the device after the station.
  332. */
  333. if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  334. ieee80211_key_free_unused(key);
  335. err = -ENOENT;
  336. goto out_unlock;
  337. }
  338. }
  339. switch (sdata->vif.type) {
  340. case NL80211_IFTYPE_STATION:
  341. if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
  342. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  343. break;
  344. case NL80211_IFTYPE_AP:
  345. case NL80211_IFTYPE_AP_VLAN:
  346. /* Keys without a station are used for TX only */
  347. if (sta && test_sta_flag(sta, WLAN_STA_MFP))
  348. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  349. break;
  350. case NL80211_IFTYPE_ADHOC:
  351. /* no MFP (yet) */
  352. break;
  353. case NL80211_IFTYPE_MESH_POINT:
  354. #ifdef CONFIG_MAC80211_MESH
  355. if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
  356. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  357. break;
  358. #endif
  359. case NL80211_IFTYPE_WDS:
  360. case NL80211_IFTYPE_MONITOR:
  361. case NL80211_IFTYPE_P2P_DEVICE:
  362. case NL80211_IFTYPE_NAN:
  363. case NL80211_IFTYPE_UNSPECIFIED:
  364. case NUM_NL80211_IFTYPES:
  365. case NL80211_IFTYPE_P2P_CLIENT:
  366. case NL80211_IFTYPE_P2P_GO:
  367. case NL80211_IFTYPE_OCB:
  368. /* shouldn't happen */
  369. WARN_ON_ONCE(1);
  370. break;
  371. }
  372. if (sta)
  373. sta->cipher_scheme = cs;
  374. err = ieee80211_key_link(key, sdata, sta);
  375. out_unlock:
  376. mutex_unlock(&local->sta_mtx);
  377. return err;
  378. }
  379. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  380. u8 key_idx, bool pairwise, const u8 *mac_addr)
  381. {
  382. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  383. struct ieee80211_local *local = sdata->local;
  384. struct sta_info *sta;
  385. struct ieee80211_key *key = NULL;
  386. int ret;
  387. mutex_lock(&local->sta_mtx);
  388. mutex_lock(&local->key_mtx);
  389. if (mac_addr) {
  390. ret = -ENOENT;
  391. sta = sta_info_get_bss(sdata, mac_addr);
  392. if (!sta)
  393. goto out_unlock;
  394. if (pairwise)
  395. key = key_mtx_dereference(local, sta->ptk[key_idx]);
  396. else
  397. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  398. } else
  399. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  400. if (!key) {
  401. ret = -ENOENT;
  402. goto out_unlock;
  403. }
  404. ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
  405. ret = 0;
  406. out_unlock:
  407. mutex_unlock(&local->key_mtx);
  408. mutex_unlock(&local->sta_mtx);
  409. return ret;
  410. }
  411. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  412. u8 key_idx, bool pairwise, const u8 *mac_addr,
  413. void *cookie,
  414. void (*callback)(void *cookie,
  415. struct key_params *params))
  416. {
  417. struct ieee80211_sub_if_data *sdata;
  418. struct sta_info *sta = NULL;
  419. u8 seq[6] = {0};
  420. struct key_params params;
  421. struct ieee80211_key *key = NULL;
  422. u64 pn64;
  423. u32 iv32;
  424. u16 iv16;
  425. int err = -ENOENT;
  426. struct ieee80211_key_seq kseq = {};
  427. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  428. rcu_read_lock();
  429. if (mac_addr) {
  430. sta = sta_info_get_bss(sdata, mac_addr);
  431. if (!sta)
  432. goto out;
  433. if (pairwise && key_idx < NUM_DEFAULT_KEYS)
  434. key = rcu_dereference(sta->ptk[key_idx]);
  435. else if (!pairwise &&
  436. key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  437. key = rcu_dereference(sta->gtk[key_idx]);
  438. } else
  439. key = rcu_dereference(sdata->keys[key_idx]);
  440. if (!key)
  441. goto out;
  442. memset(&params, 0, sizeof(params));
  443. params.cipher = key->conf.cipher;
  444. switch (key->conf.cipher) {
  445. case WLAN_CIPHER_SUITE_TKIP:
  446. pn64 = atomic64_read(&key->conf.tx_pn);
  447. iv32 = TKIP_PN_TO_IV32(pn64);
  448. iv16 = TKIP_PN_TO_IV16(pn64);
  449. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  450. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  451. drv_get_key_seq(sdata->local, key, &kseq);
  452. iv32 = kseq.tkip.iv32;
  453. iv16 = kseq.tkip.iv16;
  454. }
  455. seq[0] = iv16 & 0xff;
  456. seq[1] = (iv16 >> 8) & 0xff;
  457. seq[2] = iv32 & 0xff;
  458. seq[3] = (iv32 >> 8) & 0xff;
  459. seq[4] = (iv32 >> 16) & 0xff;
  460. seq[5] = (iv32 >> 24) & 0xff;
  461. params.seq = seq;
  462. params.seq_len = 6;
  463. break;
  464. case WLAN_CIPHER_SUITE_CCMP:
  465. case WLAN_CIPHER_SUITE_CCMP_256:
  466. case WLAN_CIPHER_SUITE_AES_CMAC:
  467. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  468. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  469. offsetof(typeof(kseq), aes_cmac));
  470. /* fall through */
  471. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  472. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  473. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  474. offsetof(typeof(kseq), aes_gmac));
  475. /* fall through */
  476. case WLAN_CIPHER_SUITE_GCMP:
  477. case WLAN_CIPHER_SUITE_GCMP_256:
  478. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  479. offsetof(typeof(kseq), gcmp));
  480. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  481. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  482. drv_get_key_seq(sdata->local, key, &kseq);
  483. memcpy(seq, kseq.ccmp.pn, 6);
  484. } else {
  485. pn64 = atomic64_read(&key->conf.tx_pn);
  486. seq[0] = pn64;
  487. seq[1] = pn64 >> 8;
  488. seq[2] = pn64 >> 16;
  489. seq[3] = pn64 >> 24;
  490. seq[4] = pn64 >> 32;
  491. seq[5] = pn64 >> 40;
  492. }
  493. params.seq = seq;
  494. params.seq_len = 6;
  495. break;
  496. default:
  497. if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  498. break;
  499. if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
  500. break;
  501. drv_get_key_seq(sdata->local, key, &kseq);
  502. params.seq = kseq.hw.seq;
  503. params.seq_len = kseq.hw.seq_len;
  504. break;
  505. }
  506. params.key = key->conf.key;
  507. params.key_len = key->conf.keylen;
  508. callback(cookie, &params);
  509. err = 0;
  510. out:
  511. rcu_read_unlock();
  512. return err;
  513. }
  514. static int ieee80211_config_default_key(struct wiphy *wiphy,
  515. struct net_device *dev,
  516. u8 key_idx, bool uni,
  517. bool multi)
  518. {
  519. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  520. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  521. return 0;
  522. }
  523. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  524. struct net_device *dev,
  525. u8 key_idx)
  526. {
  527. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  528. ieee80211_set_default_mgmt_key(sdata, key_idx);
  529. return 0;
  530. }
  531. void sta_set_rate_info_tx(struct sta_info *sta,
  532. const struct ieee80211_tx_rate *rate,
  533. struct rate_info *rinfo)
  534. {
  535. rinfo->flags = 0;
  536. if (rate->flags & IEEE80211_TX_RC_MCS) {
  537. rinfo->flags |= RATE_INFO_FLAGS_MCS;
  538. rinfo->mcs = rate->idx;
  539. } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
  540. rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
  541. rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
  542. rinfo->nss = ieee80211_rate_get_vht_nss(rate);
  543. } else {
  544. struct ieee80211_supported_band *sband;
  545. int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
  546. u16 brate;
  547. sband = ieee80211_get_sband(sta->sdata);
  548. if (sband) {
  549. brate = sband->bitrates[rate->idx].bitrate;
  550. rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
  551. }
  552. }
  553. if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  554. rinfo->bw = RATE_INFO_BW_40;
  555. else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  556. rinfo->bw = RATE_INFO_BW_80;
  557. else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  558. rinfo->bw = RATE_INFO_BW_160;
  559. else
  560. rinfo->bw = RATE_INFO_BW_20;
  561. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  562. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  563. }
  564. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  565. int idx, u8 *mac, struct station_info *sinfo)
  566. {
  567. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  568. struct ieee80211_local *local = sdata->local;
  569. struct sta_info *sta;
  570. int ret = -ENOENT;
  571. mutex_lock(&local->sta_mtx);
  572. sta = sta_info_get_by_idx(sdata, idx);
  573. if (sta) {
  574. ret = 0;
  575. memcpy(mac, sta->sta.addr, ETH_ALEN);
  576. sta_set_sinfo(sta, sinfo, true);
  577. }
  578. mutex_unlock(&local->sta_mtx);
  579. return ret;
  580. }
  581. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  582. int idx, struct survey_info *survey)
  583. {
  584. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  585. return drv_get_survey(local, idx, survey);
  586. }
  587. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  588. const u8 *mac, struct station_info *sinfo)
  589. {
  590. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  591. struct ieee80211_local *local = sdata->local;
  592. struct sta_info *sta;
  593. int ret = -ENOENT;
  594. mutex_lock(&local->sta_mtx);
  595. sta = sta_info_get_bss(sdata, mac);
  596. if (sta) {
  597. ret = 0;
  598. sta_set_sinfo(sta, sinfo, true);
  599. }
  600. mutex_unlock(&local->sta_mtx);
  601. return ret;
  602. }
  603. static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  604. struct cfg80211_chan_def *chandef)
  605. {
  606. struct ieee80211_local *local = wiphy_priv(wiphy);
  607. struct ieee80211_sub_if_data *sdata;
  608. int ret = 0;
  609. if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
  610. return 0;
  611. mutex_lock(&local->mtx);
  612. if (local->use_chanctx) {
  613. sdata = rtnl_dereference(local->monitor_sdata);
  614. if (sdata) {
  615. ieee80211_vif_release_channel(sdata);
  616. ret = ieee80211_vif_use_channel(sdata, chandef,
  617. IEEE80211_CHANCTX_EXCLUSIVE);
  618. }
  619. } else if (local->open_count == local->monitors) {
  620. local->_oper_chandef = *chandef;
  621. ieee80211_hw_config(local, 0);
  622. }
  623. if (ret == 0)
  624. local->monitor_chandef = *chandef;
  625. mutex_unlock(&local->mtx);
  626. return ret;
  627. }
  628. static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
  629. const u8 *resp, size_t resp_len,
  630. const struct ieee80211_csa_settings *csa)
  631. {
  632. struct probe_resp *new, *old;
  633. if (!resp || !resp_len)
  634. return 1;
  635. old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
  636. new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
  637. if (!new)
  638. return -ENOMEM;
  639. new->len = resp_len;
  640. memcpy(new->data, resp, resp_len);
  641. if (csa)
  642. memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
  643. csa->n_counter_offsets_presp *
  644. sizeof(new->csa_counter_offsets[0]));
  645. rcu_assign_pointer(sdata->u.ap.probe_resp, new);
  646. if (old)
  647. kfree_rcu(old, rcu_head);
  648. return 0;
  649. }
  650. static int ieee80211_set_ftm_responder_params(
  651. struct ieee80211_sub_if_data *sdata,
  652. const u8 *lci, size_t lci_len,
  653. const u8 *civicloc, size_t civicloc_len)
  654. {
  655. struct ieee80211_ftm_responder_params *new, *old;
  656. struct ieee80211_bss_conf *bss_conf;
  657. u8 *pos;
  658. int len;
  659. if ((!lci || !lci_len) && (!civicloc || !civicloc_len))
  660. return 1;
  661. bss_conf = &sdata->vif.bss_conf;
  662. old = bss_conf->ftmr_params;
  663. len = lci_len + civicloc_len;
  664. new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
  665. if (!new)
  666. return -ENOMEM;
  667. pos = (u8 *)(new + 1);
  668. if (lci_len) {
  669. new->lci_len = lci_len;
  670. new->lci = pos;
  671. memcpy(pos, lci, lci_len);
  672. pos += lci_len;
  673. }
  674. if (civicloc_len) {
  675. new->civicloc_len = civicloc_len;
  676. new->civicloc = pos;
  677. memcpy(pos, civicloc, civicloc_len);
  678. pos += civicloc_len;
  679. }
  680. bss_conf->ftmr_params = new;
  681. kfree(old);
  682. return 0;
  683. }
  684. static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
  685. struct cfg80211_beacon_data *params,
  686. const struct ieee80211_csa_settings *csa)
  687. {
  688. struct beacon_data *new, *old;
  689. int new_head_len, new_tail_len;
  690. int size, err;
  691. u32 changed = BSS_CHANGED_BEACON;
  692. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  693. /* Need to have a beacon head if we don't have one yet */
  694. if (!params->head && !old)
  695. return -EINVAL;
  696. /* new or old head? */
  697. if (params->head)
  698. new_head_len = params->head_len;
  699. else
  700. new_head_len = old->head_len;
  701. /* new or old tail? */
  702. if (params->tail || !old)
  703. /* params->tail_len will be zero for !params->tail */
  704. new_tail_len = params->tail_len;
  705. else
  706. new_tail_len = old->tail_len;
  707. size = sizeof(*new) + new_head_len + new_tail_len;
  708. new = kzalloc(size, GFP_KERNEL);
  709. if (!new)
  710. return -ENOMEM;
  711. /* start filling the new info now */
  712. /*
  713. * pointers go into the block we allocated,
  714. * memory is | beacon_data | head | tail |
  715. */
  716. new->head = ((u8 *) new) + sizeof(*new);
  717. new->tail = new->head + new_head_len;
  718. new->head_len = new_head_len;
  719. new->tail_len = new_tail_len;
  720. if (csa) {
  721. new->csa_current_counter = csa->count;
  722. memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
  723. csa->n_counter_offsets_beacon *
  724. sizeof(new->csa_counter_offsets[0]));
  725. }
  726. /* copy in head */
  727. if (params->head)
  728. memcpy(new->head, params->head, new_head_len);
  729. else
  730. memcpy(new->head, old->head, new_head_len);
  731. /* copy in optional tail */
  732. if (params->tail)
  733. memcpy(new->tail, params->tail, new_tail_len);
  734. else
  735. if (old)
  736. memcpy(new->tail, old->tail, new_tail_len);
  737. err = ieee80211_set_probe_resp(sdata, params->probe_resp,
  738. params->probe_resp_len, csa);
  739. if (err < 0)
  740. return err;
  741. if (err == 0)
  742. changed |= BSS_CHANGED_AP_PROBE_RESP;
  743. if (params->ftm_responder != -1) {
  744. sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
  745. err = ieee80211_set_ftm_responder_params(sdata,
  746. params->lci,
  747. params->lci_len,
  748. params->civicloc,
  749. params->civicloc_len);
  750. if (err < 0)
  751. return err;
  752. changed |= BSS_CHANGED_FTM_RESPONDER;
  753. }
  754. rcu_assign_pointer(sdata->u.ap.beacon, new);
  755. if (old)
  756. kfree_rcu(old, rcu_head);
  757. return changed;
  758. }
  759. static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
  760. struct cfg80211_ap_settings *params)
  761. {
  762. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  763. struct ieee80211_local *local = sdata->local;
  764. struct beacon_data *old;
  765. struct ieee80211_sub_if_data *vlan;
  766. u32 changed = BSS_CHANGED_BEACON_INT |
  767. BSS_CHANGED_BEACON_ENABLED |
  768. BSS_CHANGED_BEACON |
  769. BSS_CHANGED_SSID |
  770. BSS_CHANGED_P2P_PS |
  771. BSS_CHANGED_TXPOWER;
  772. int err;
  773. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  774. if (old)
  775. return -EALREADY;
  776. switch (params->smps_mode) {
  777. case NL80211_SMPS_OFF:
  778. sdata->smps_mode = IEEE80211_SMPS_OFF;
  779. break;
  780. case NL80211_SMPS_STATIC:
  781. sdata->smps_mode = IEEE80211_SMPS_STATIC;
  782. break;
  783. case NL80211_SMPS_DYNAMIC:
  784. sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
  785. break;
  786. default:
  787. return -EINVAL;
  788. }
  789. sdata->u.ap.req_smps = sdata->smps_mode;
  790. sdata->needed_rx_chains = sdata->local->rx_chains;
  791. sdata->vif.bss_conf.beacon_int = params->beacon_interval;
  792. if (params->he_cap)
  793. sdata->vif.bss_conf.he_support = true;
  794. mutex_lock(&local->mtx);
  795. err = ieee80211_vif_use_channel(sdata, &params->chandef,
  796. IEEE80211_CHANCTX_SHARED);
  797. if (!err)
  798. ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
  799. mutex_unlock(&local->mtx);
  800. if (err)
  801. return err;
  802. /*
  803. * Apply control port protocol, this allows us to
  804. * not encrypt dynamic WEP control frames.
  805. */
  806. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  807. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  808. sdata->control_port_over_nl80211 =
  809. params->crypto.control_port_over_nl80211;
  810. sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
  811. &params->crypto,
  812. sdata->vif.type);
  813. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  814. vlan->control_port_protocol =
  815. params->crypto.control_port_ethertype;
  816. vlan->control_port_no_encrypt =
  817. params->crypto.control_port_no_encrypt;
  818. vlan->control_port_over_nl80211 =
  819. params->crypto.control_port_over_nl80211;
  820. vlan->encrypt_headroom =
  821. ieee80211_cs_headroom(sdata->local,
  822. &params->crypto,
  823. vlan->vif.type);
  824. }
  825. sdata->vif.bss_conf.dtim_period = params->dtim_period;
  826. sdata->vif.bss_conf.enable_beacon = true;
  827. sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
  828. sdata->vif.bss_conf.ssid_len = params->ssid_len;
  829. if (params->ssid_len)
  830. memcpy(sdata->vif.bss_conf.ssid, params->ssid,
  831. params->ssid_len);
  832. sdata->vif.bss_conf.hidden_ssid =
  833. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  834. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  835. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  836. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
  837. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  838. if (params->p2p_opp_ps)
  839. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  840. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  841. err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
  842. if (err < 0) {
  843. ieee80211_vif_release_channel(sdata);
  844. return err;
  845. }
  846. changed |= err;
  847. err = drv_start_ap(sdata->local, sdata);
  848. if (err) {
  849. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  850. if (old)
  851. kfree_rcu(old, rcu_head);
  852. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  853. ieee80211_vif_release_channel(sdata);
  854. return err;
  855. }
  856. ieee80211_recalc_dtim(local, sdata);
  857. ieee80211_bss_info_change_notify(sdata, changed);
  858. netif_carrier_on(dev);
  859. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  860. netif_carrier_on(vlan->dev);
  861. return 0;
  862. }
  863. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  864. struct cfg80211_beacon_data *params)
  865. {
  866. struct ieee80211_sub_if_data *sdata;
  867. struct beacon_data *old;
  868. int err;
  869. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  870. sdata_assert_lock(sdata);
  871. /* don't allow changing the beacon while CSA is in place - offset
  872. * of channel switch counter may change
  873. */
  874. if (sdata->vif.csa_active)
  875. return -EBUSY;
  876. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  877. if (!old)
  878. return -ENOENT;
  879. err = ieee80211_assign_beacon(sdata, params, NULL);
  880. if (err < 0)
  881. return err;
  882. ieee80211_bss_info_change_notify(sdata, err);
  883. return 0;
  884. }
  885. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  886. {
  887. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  888. struct ieee80211_sub_if_data *vlan;
  889. struct ieee80211_local *local = sdata->local;
  890. struct beacon_data *old_beacon;
  891. struct probe_resp *old_probe_resp;
  892. struct cfg80211_chan_def chandef;
  893. sdata_assert_lock(sdata);
  894. old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
  895. if (!old_beacon)
  896. return -ENOENT;
  897. old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
  898. /* abort any running channel switch */
  899. mutex_lock(&local->mtx);
  900. sdata->vif.csa_active = false;
  901. if (sdata->csa_block_tx) {
  902. ieee80211_wake_vif_queues(local, sdata,
  903. IEEE80211_QUEUE_STOP_REASON_CSA);
  904. sdata->csa_block_tx = false;
  905. }
  906. mutex_unlock(&local->mtx);
  907. kfree(sdata->u.ap.next_beacon);
  908. sdata->u.ap.next_beacon = NULL;
  909. /* turn off carrier for this interface and dependent VLANs */
  910. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  911. netif_carrier_off(vlan->dev);
  912. netif_carrier_off(dev);
  913. /* remove beacon and probe response */
  914. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  915. RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
  916. kfree_rcu(old_beacon, rcu_head);
  917. if (old_probe_resp)
  918. kfree_rcu(old_probe_resp, rcu_head);
  919. sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
  920. kfree(sdata->vif.bss_conf.ftmr_params);
  921. sdata->vif.bss_conf.ftmr_params = NULL;
  922. __sta_info_flush(sdata, true);
  923. ieee80211_free_keys(sdata, true);
  924. sdata->vif.bss_conf.enable_beacon = false;
  925. sdata->vif.bss_conf.ssid_len = 0;
  926. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  927. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  928. if (sdata->wdev.cac_started) {
  929. chandef = sdata->vif.bss_conf.chandef;
  930. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  931. cfg80211_cac_event(sdata->dev, &chandef,
  932. NL80211_RADAR_CAC_ABORTED,
  933. GFP_KERNEL);
  934. }
  935. drv_stop_ap(sdata->local, sdata);
  936. /* free all potentially still buffered bcast frames */
  937. local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
  938. ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
  939. mutex_lock(&local->mtx);
  940. ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
  941. ieee80211_vif_release_channel(sdata);
  942. mutex_unlock(&local->mtx);
  943. return 0;
  944. }
  945. static int sta_apply_auth_flags(struct ieee80211_local *local,
  946. struct sta_info *sta,
  947. u32 mask, u32 set)
  948. {
  949. int ret;
  950. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  951. set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  952. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  953. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  954. if (ret)
  955. return ret;
  956. }
  957. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  958. set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  959. !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  960. /*
  961. * When peer becomes associated, init rate control as
  962. * well. Some drivers require rate control initialized
  963. * before drv_sta_state() is called.
  964. */
  965. if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  966. rate_control_rate_init(sta);
  967. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  968. if (ret)
  969. return ret;
  970. }
  971. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  972. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  973. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  974. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  975. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  976. else
  977. ret = 0;
  978. if (ret)
  979. return ret;
  980. }
  981. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  982. !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  983. test_sta_flag(sta, WLAN_STA_ASSOC)) {
  984. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  985. if (ret)
  986. return ret;
  987. }
  988. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  989. !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  990. test_sta_flag(sta, WLAN_STA_AUTH)) {
  991. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  992. if (ret)
  993. return ret;
  994. }
  995. return 0;
  996. }
  997. static void sta_apply_mesh_params(struct ieee80211_local *local,
  998. struct sta_info *sta,
  999. struct station_parameters *params)
  1000. {
  1001. #ifdef CONFIG_MAC80211_MESH
  1002. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1003. u32 changed = 0;
  1004. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
  1005. switch (params->plink_state) {
  1006. case NL80211_PLINK_ESTAB:
  1007. if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
  1008. changed = mesh_plink_inc_estab_count(sdata);
  1009. sta->mesh->plink_state = params->plink_state;
  1010. sta->mesh->aid = params->peer_aid;
  1011. ieee80211_mps_sta_status_update(sta);
  1012. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1013. sdata->u.mesh.mshcfg.power_mode);
  1014. break;
  1015. case NL80211_PLINK_LISTEN:
  1016. case NL80211_PLINK_BLOCKED:
  1017. case NL80211_PLINK_OPN_SNT:
  1018. case NL80211_PLINK_OPN_RCVD:
  1019. case NL80211_PLINK_CNF_RCVD:
  1020. case NL80211_PLINK_HOLDING:
  1021. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  1022. changed = mesh_plink_dec_estab_count(sdata);
  1023. sta->mesh->plink_state = params->plink_state;
  1024. ieee80211_mps_sta_status_update(sta);
  1025. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1026. NL80211_MESH_POWER_UNKNOWN);
  1027. break;
  1028. default:
  1029. /* nothing */
  1030. break;
  1031. }
  1032. }
  1033. switch (params->plink_action) {
  1034. case NL80211_PLINK_ACTION_NO_ACTION:
  1035. /* nothing */
  1036. break;
  1037. case NL80211_PLINK_ACTION_OPEN:
  1038. changed |= mesh_plink_open(sta);
  1039. break;
  1040. case NL80211_PLINK_ACTION_BLOCK:
  1041. changed |= mesh_plink_block(sta);
  1042. break;
  1043. }
  1044. if (params->local_pm)
  1045. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1046. params->local_pm);
  1047. ieee80211_mbss_info_change_notify(sdata, changed);
  1048. #endif
  1049. }
  1050. static int sta_apply_parameters(struct ieee80211_local *local,
  1051. struct sta_info *sta,
  1052. struct station_parameters *params)
  1053. {
  1054. int ret = 0;
  1055. struct ieee80211_supported_band *sband;
  1056. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1057. u32 mask, set;
  1058. sband = ieee80211_get_sband(sdata);
  1059. if (!sband)
  1060. return -EINVAL;
  1061. mask = params->sta_flags_mask;
  1062. set = params->sta_flags_set;
  1063. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1064. /*
  1065. * In mesh mode, ASSOCIATED isn't part of the nl80211
  1066. * API but must follow AUTHENTICATED for driver state.
  1067. */
  1068. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1069. mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1070. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1071. set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1072. } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1073. /*
  1074. * TDLS -- everything follows authorized, but
  1075. * only becoming authorized is possible, not
  1076. * going back
  1077. */
  1078. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1079. set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1080. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1081. mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1082. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1083. }
  1084. }
  1085. if (mask & BIT(NL80211_STA_FLAG_WME) &&
  1086. local->hw.queues >= IEEE80211_NUM_ACS)
  1087. sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
  1088. /* auth flags will be set later for TDLS,
  1089. * and for unassociated stations that move to assocaited */
  1090. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1091. !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  1092. (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
  1093. ret = sta_apply_auth_flags(local, sta, mask, set);
  1094. if (ret)
  1095. return ret;
  1096. }
  1097. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  1098. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  1099. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1100. else
  1101. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1102. }
  1103. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  1104. sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
  1105. if (set & BIT(NL80211_STA_FLAG_MFP))
  1106. set_sta_flag(sta, WLAN_STA_MFP);
  1107. else
  1108. clear_sta_flag(sta, WLAN_STA_MFP);
  1109. }
  1110. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  1111. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1112. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1113. else
  1114. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1115. }
  1116. /* mark TDLS channel switch support, if the AP allows it */
  1117. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1118. !sdata->u.mgd.tdls_chan_switch_prohibited &&
  1119. params->ext_capab_len >= 4 &&
  1120. params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
  1121. set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
  1122. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1123. !sdata->u.mgd.tdls_wider_bw_prohibited &&
  1124. ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
  1125. params->ext_capab_len >= 8 &&
  1126. params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
  1127. set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
  1128. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  1129. sta->sta.uapsd_queues = params->uapsd_queues;
  1130. sta->sta.max_sp = params->max_sp;
  1131. }
  1132. /* The sender might not have sent the last bit, consider it to be 0 */
  1133. if (params->ext_capab_len >= 8) {
  1134. u8 val = (params->ext_capab[7] &
  1135. WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
  1136. /* we did get all the bits, take the MSB as well */
  1137. if (params->ext_capab_len >= 9) {
  1138. u8 val_msb = params->ext_capab[8] &
  1139. WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
  1140. val_msb <<= 1;
  1141. val |= val_msb;
  1142. }
  1143. switch (val) {
  1144. case 1:
  1145. sta->sta.max_amsdu_subframes = 32;
  1146. break;
  1147. case 2:
  1148. sta->sta.max_amsdu_subframes = 16;
  1149. break;
  1150. case 3:
  1151. sta->sta.max_amsdu_subframes = 8;
  1152. break;
  1153. default:
  1154. sta->sta.max_amsdu_subframes = 0;
  1155. }
  1156. }
  1157. /*
  1158. * cfg80211 validates this (1-2007) and allows setting the AID
  1159. * only when creating a new station entry
  1160. */
  1161. if (params->aid)
  1162. sta->sta.aid = params->aid;
  1163. /*
  1164. * Some of the following updates would be racy if called on an
  1165. * existing station, via ieee80211_change_station(). However,
  1166. * all such changes are rejected by cfg80211 except for updates
  1167. * changing the supported rates on an existing but not yet used
  1168. * TDLS peer.
  1169. */
  1170. if (params->listen_interval >= 0)
  1171. sta->listen_interval = params->listen_interval;
  1172. if (params->supported_rates) {
  1173. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1174. sband, params->supported_rates,
  1175. params->supported_rates_len,
  1176. &sta->sta.supp_rates[sband->band]);
  1177. }
  1178. if (params->ht_capa)
  1179. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  1180. params->ht_capa, sta);
  1181. /* VHT can override some HT caps such as the A-MSDU max length */
  1182. if (params->vht_capa)
  1183. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  1184. params->vht_capa, sta);
  1185. if (params->he_capa)
  1186. ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
  1187. (void *)params->he_capa,
  1188. params->he_capa_len, sta);
  1189. if (params->opmode_notif_used) {
  1190. /* returned value is only needed for rc update, but the
  1191. * rc isn't initialized here yet, so ignore it
  1192. */
  1193. __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
  1194. sband->band);
  1195. }
  1196. if (params->support_p2p_ps >= 0)
  1197. sta->sta.support_p2p_ps = params->support_p2p_ps;
  1198. if (ieee80211_vif_is_mesh(&sdata->vif))
  1199. sta_apply_mesh_params(local, sta, params);
  1200. /* set the STA state after all sta info from usermode has been set */
  1201. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
  1202. set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
  1203. ret = sta_apply_auth_flags(local, sta, mask, set);
  1204. if (ret)
  1205. return ret;
  1206. }
  1207. return 0;
  1208. }
  1209. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  1210. const u8 *mac,
  1211. struct station_parameters *params)
  1212. {
  1213. struct ieee80211_local *local = wiphy_priv(wiphy);
  1214. struct sta_info *sta;
  1215. struct ieee80211_sub_if_data *sdata;
  1216. int err;
  1217. int layer2_update;
  1218. if (params->vlan) {
  1219. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1220. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1221. sdata->vif.type != NL80211_IFTYPE_AP)
  1222. return -EINVAL;
  1223. } else
  1224. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1225. if (ether_addr_equal(mac, sdata->vif.addr))
  1226. return -EINVAL;
  1227. if (is_multicast_ether_addr(mac))
  1228. return -EINVAL;
  1229. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  1230. if (!sta)
  1231. return -ENOMEM;
  1232. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1233. sta->sta.tdls = true;
  1234. err = sta_apply_parameters(local, sta, params);
  1235. if (err) {
  1236. sta_info_free(local, sta);
  1237. return err;
  1238. }
  1239. /*
  1240. * for TDLS and for unassociated station, rate control should be
  1241. * initialized only when rates are known and station is marked
  1242. * authorized/associated
  1243. */
  1244. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1245. test_sta_flag(sta, WLAN_STA_ASSOC))
  1246. rate_control_rate_init(sta);
  1247. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1248. sdata->vif.type == NL80211_IFTYPE_AP;
  1249. err = sta_info_insert_rcu(sta);
  1250. if (err) {
  1251. rcu_read_unlock();
  1252. return err;
  1253. }
  1254. if (layer2_update)
  1255. cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
  1256. rcu_read_unlock();
  1257. return 0;
  1258. }
  1259. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1260. struct station_del_parameters *params)
  1261. {
  1262. struct ieee80211_sub_if_data *sdata;
  1263. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1264. if (params->mac)
  1265. return sta_info_destroy_addr_bss(sdata, params->mac);
  1266. sta_info_flush(sdata);
  1267. return 0;
  1268. }
  1269. static int ieee80211_change_station(struct wiphy *wiphy,
  1270. struct net_device *dev, const u8 *mac,
  1271. struct station_parameters *params)
  1272. {
  1273. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1274. struct ieee80211_local *local = wiphy_priv(wiphy);
  1275. struct sta_info *sta;
  1276. struct ieee80211_sub_if_data *vlansdata;
  1277. enum cfg80211_station_type statype;
  1278. int err;
  1279. mutex_lock(&local->sta_mtx);
  1280. sta = sta_info_get_bss(sdata, mac);
  1281. if (!sta) {
  1282. err = -ENOENT;
  1283. goto out_err;
  1284. }
  1285. switch (sdata->vif.type) {
  1286. case NL80211_IFTYPE_MESH_POINT:
  1287. if (sdata->u.mesh.user_mpm)
  1288. statype = CFG80211_STA_MESH_PEER_USER;
  1289. else
  1290. statype = CFG80211_STA_MESH_PEER_KERNEL;
  1291. break;
  1292. case NL80211_IFTYPE_ADHOC:
  1293. statype = CFG80211_STA_IBSS;
  1294. break;
  1295. case NL80211_IFTYPE_STATION:
  1296. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1297. statype = CFG80211_STA_AP_STA;
  1298. break;
  1299. }
  1300. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1301. statype = CFG80211_STA_TDLS_PEER_ACTIVE;
  1302. else
  1303. statype = CFG80211_STA_TDLS_PEER_SETUP;
  1304. break;
  1305. case NL80211_IFTYPE_AP:
  1306. case NL80211_IFTYPE_AP_VLAN:
  1307. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  1308. statype = CFG80211_STA_AP_CLIENT;
  1309. else
  1310. statype = CFG80211_STA_AP_CLIENT_UNASSOC;
  1311. break;
  1312. default:
  1313. err = -EOPNOTSUPP;
  1314. goto out_err;
  1315. }
  1316. err = cfg80211_check_station_change(wiphy, params, statype);
  1317. if (err)
  1318. goto out_err;
  1319. if (params->vlan && params->vlan != sta->sdata->dev) {
  1320. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1321. if (params->vlan->ieee80211_ptr->use_4addr) {
  1322. if (vlansdata->u.vlan.sta) {
  1323. err = -EBUSY;
  1324. goto out_err;
  1325. }
  1326. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1327. __ieee80211_check_fast_rx_iface(vlansdata);
  1328. }
  1329. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1330. sta->sdata->u.vlan.sta)
  1331. RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
  1332. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1333. ieee80211_vif_dec_num_mcast(sta->sdata);
  1334. sta->sdata = vlansdata;
  1335. ieee80211_check_fast_xmit(sta);
  1336. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1337. ieee80211_vif_inc_num_mcast(sta->sdata);
  1338. cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
  1339. }
  1340. err = sta_apply_parameters(local, sta, params);
  1341. if (err)
  1342. goto out_err;
  1343. mutex_unlock(&local->sta_mtx);
  1344. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1345. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1346. sta->known_smps_mode != sta->sdata->bss->req_smps &&
  1347. test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
  1348. sta_info_tx_streams(sta) != 1) {
  1349. ht_dbg(sta->sdata,
  1350. "%pM just authorized and MIMO capable - update SMPS\n",
  1351. sta->sta.addr);
  1352. ieee80211_send_smps_action(sta->sdata,
  1353. sta->sdata->bss->req_smps,
  1354. sta->sta.addr,
  1355. sta->sdata->vif.bss_conf.bssid);
  1356. }
  1357. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1358. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1359. ieee80211_recalc_ps(local);
  1360. ieee80211_recalc_ps_vif(sdata);
  1361. }
  1362. return 0;
  1363. out_err:
  1364. mutex_unlock(&local->sta_mtx);
  1365. return err;
  1366. }
  1367. #ifdef CONFIG_MAC80211_MESH
  1368. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1369. const u8 *dst, const u8 *next_hop)
  1370. {
  1371. struct ieee80211_sub_if_data *sdata;
  1372. struct mesh_path *mpath;
  1373. struct sta_info *sta;
  1374. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1375. rcu_read_lock();
  1376. sta = sta_info_get(sdata, next_hop);
  1377. if (!sta) {
  1378. rcu_read_unlock();
  1379. return -ENOENT;
  1380. }
  1381. mpath = mesh_path_add(sdata, dst);
  1382. if (IS_ERR(mpath)) {
  1383. rcu_read_unlock();
  1384. return PTR_ERR(mpath);
  1385. }
  1386. mesh_path_fix_nexthop(mpath, sta);
  1387. rcu_read_unlock();
  1388. return 0;
  1389. }
  1390. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1391. const u8 *dst)
  1392. {
  1393. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1394. if (dst)
  1395. return mesh_path_del(sdata, dst);
  1396. mesh_path_flush_by_iface(sdata);
  1397. return 0;
  1398. }
  1399. static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
  1400. const u8 *dst, const u8 *next_hop)
  1401. {
  1402. struct ieee80211_sub_if_data *sdata;
  1403. struct mesh_path *mpath;
  1404. struct sta_info *sta;
  1405. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1406. rcu_read_lock();
  1407. sta = sta_info_get(sdata, next_hop);
  1408. if (!sta) {
  1409. rcu_read_unlock();
  1410. return -ENOENT;
  1411. }
  1412. mpath = mesh_path_lookup(sdata, dst);
  1413. if (!mpath) {
  1414. rcu_read_unlock();
  1415. return -ENOENT;
  1416. }
  1417. mesh_path_fix_nexthop(mpath, sta);
  1418. rcu_read_unlock();
  1419. return 0;
  1420. }
  1421. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1422. struct mpath_info *pinfo)
  1423. {
  1424. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1425. if (next_hop_sta)
  1426. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1427. else
  1428. eth_zero_addr(next_hop);
  1429. memset(pinfo, 0, sizeof(*pinfo));
  1430. pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
  1431. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1432. MPATH_INFO_SN |
  1433. MPATH_INFO_METRIC |
  1434. MPATH_INFO_EXPTIME |
  1435. MPATH_INFO_DISCOVERY_TIMEOUT |
  1436. MPATH_INFO_DISCOVERY_RETRIES |
  1437. MPATH_INFO_FLAGS;
  1438. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1439. pinfo->sn = mpath->sn;
  1440. pinfo->metric = mpath->metric;
  1441. if (time_before(jiffies, mpath->exp_time))
  1442. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1443. pinfo->discovery_timeout =
  1444. jiffies_to_msecs(mpath->discovery_timeout);
  1445. pinfo->discovery_retries = mpath->discovery_retries;
  1446. if (mpath->flags & MESH_PATH_ACTIVE)
  1447. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1448. if (mpath->flags & MESH_PATH_RESOLVING)
  1449. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1450. if (mpath->flags & MESH_PATH_SN_VALID)
  1451. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1452. if (mpath->flags & MESH_PATH_FIXED)
  1453. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1454. if (mpath->flags & MESH_PATH_RESOLVED)
  1455. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  1456. }
  1457. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1458. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1459. {
  1460. struct ieee80211_sub_if_data *sdata;
  1461. struct mesh_path *mpath;
  1462. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1463. rcu_read_lock();
  1464. mpath = mesh_path_lookup(sdata, dst);
  1465. if (!mpath) {
  1466. rcu_read_unlock();
  1467. return -ENOENT;
  1468. }
  1469. memcpy(dst, mpath->dst, ETH_ALEN);
  1470. mpath_set_pinfo(mpath, next_hop, pinfo);
  1471. rcu_read_unlock();
  1472. return 0;
  1473. }
  1474. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1475. int idx, u8 *dst, u8 *next_hop,
  1476. struct mpath_info *pinfo)
  1477. {
  1478. struct ieee80211_sub_if_data *sdata;
  1479. struct mesh_path *mpath;
  1480. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1481. rcu_read_lock();
  1482. mpath = mesh_path_lookup_by_idx(sdata, idx);
  1483. if (!mpath) {
  1484. rcu_read_unlock();
  1485. return -ENOENT;
  1486. }
  1487. memcpy(dst, mpath->dst, ETH_ALEN);
  1488. mpath_set_pinfo(mpath, next_hop, pinfo);
  1489. rcu_read_unlock();
  1490. return 0;
  1491. }
  1492. static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
  1493. struct mpath_info *pinfo)
  1494. {
  1495. memset(pinfo, 0, sizeof(*pinfo));
  1496. memcpy(mpp, mpath->mpp, ETH_ALEN);
  1497. pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
  1498. }
  1499. static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
  1500. u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  1501. {
  1502. struct ieee80211_sub_if_data *sdata;
  1503. struct mesh_path *mpath;
  1504. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1505. rcu_read_lock();
  1506. mpath = mpp_path_lookup(sdata, dst);
  1507. if (!mpath) {
  1508. rcu_read_unlock();
  1509. return -ENOENT;
  1510. }
  1511. memcpy(dst, mpath->dst, ETH_ALEN);
  1512. mpp_set_pinfo(mpath, mpp, pinfo);
  1513. rcu_read_unlock();
  1514. return 0;
  1515. }
  1516. static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
  1517. int idx, u8 *dst, u8 *mpp,
  1518. struct mpath_info *pinfo)
  1519. {
  1520. struct ieee80211_sub_if_data *sdata;
  1521. struct mesh_path *mpath;
  1522. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1523. rcu_read_lock();
  1524. mpath = mpp_path_lookup_by_idx(sdata, idx);
  1525. if (!mpath) {
  1526. rcu_read_unlock();
  1527. return -ENOENT;
  1528. }
  1529. memcpy(dst, mpath->dst, ETH_ALEN);
  1530. mpp_set_pinfo(mpath, mpp, pinfo);
  1531. rcu_read_unlock();
  1532. return 0;
  1533. }
  1534. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  1535. struct net_device *dev,
  1536. struct mesh_config *conf)
  1537. {
  1538. struct ieee80211_sub_if_data *sdata;
  1539. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1540. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  1541. return 0;
  1542. }
  1543. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  1544. {
  1545. return (mask >> (parm-1)) & 0x1;
  1546. }
  1547. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  1548. const struct mesh_setup *setup)
  1549. {
  1550. u8 *new_ie;
  1551. const u8 *old_ie;
  1552. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  1553. struct ieee80211_sub_if_data, u.mesh);
  1554. /* allocate information elements */
  1555. new_ie = NULL;
  1556. old_ie = ifmsh->ie;
  1557. if (setup->ie_len) {
  1558. new_ie = kmemdup(setup->ie, setup->ie_len,
  1559. GFP_KERNEL);
  1560. if (!new_ie)
  1561. return -ENOMEM;
  1562. }
  1563. ifmsh->ie_len = setup->ie_len;
  1564. ifmsh->ie = new_ie;
  1565. kfree(old_ie);
  1566. /* now copy the rest of the setup parameters */
  1567. ifmsh->mesh_id_len = setup->mesh_id_len;
  1568. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  1569. ifmsh->mesh_sp_id = setup->sync_method;
  1570. ifmsh->mesh_pp_id = setup->path_sel_proto;
  1571. ifmsh->mesh_pm_id = setup->path_metric;
  1572. ifmsh->user_mpm = setup->user_mpm;
  1573. ifmsh->mesh_auth_id = setup->auth_id;
  1574. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  1575. ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
  1576. if (setup->is_authenticated)
  1577. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  1578. if (setup->is_secure)
  1579. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  1580. /* mcast rate setting in Mesh Node */
  1581. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  1582. sizeof(setup->mcast_rate));
  1583. sdata->vif.bss_conf.basic_rates = setup->basic_rates;
  1584. sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
  1585. sdata->vif.bss_conf.dtim_period = setup->dtim_period;
  1586. return 0;
  1587. }
  1588. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  1589. struct net_device *dev, u32 mask,
  1590. const struct mesh_config *nconf)
  1591. {
  1592. struct mesh_config *conf;
  1593. struct ieee80211_sub_if_data *sdata;
  1594. struct ieee80211_if_mesh *ifmsh;
  1595. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1596. ifmsh = &sdata->u.mesh;
  1597. /* Set the config options which we are interested in setting */
  1598. conf = &(sdata->u.mesh.mshcfg);
  1599. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  1600. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  1601. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  1602. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  1603. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  1604. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  1605. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  1606. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  1607. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  1608. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  1609. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  1610. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  1611. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  1612. conf->element_ttl = nconf->element_ttl;
  1613. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
  1614. if (ifmsh->user_mpm)
  1615. return -EBUSY;
  1616. conf->auto_open_plinks = nconf->auto_open_plinks;
  1617. }
  1618. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  1619. conf->dot11MeshNbrOffsetMaxNeighbor =
  1620. nconf->dot11MeshNbrOffsetMaxNeighbor;
  1621. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  1622. conf->dot11MeshHWMPmaxPREQretries =
  1623. nconf->dot11MeshHWMPmaxPREQretries;
  1624. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1625. conf->path_refresh_time = nconf->path_refresh_time;
  1626. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1627. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1628. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1629. conf->dot11MeshHWMPactivePathTimeout =
  1630. nconf->dot11MeshHWMPactivePathTimeout;
  1631. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1632. conf->dot11MeshHWMPpreqMinInterval =
  1633. nconf->dot11MeshHWMPpreqMinInterval;
  1634. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  1635. conf->dot11MeshHWMPperrMinInterval =
  1636. nconf->dot11MeshHWMPperrMinInterval;
  1637. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1638. mask))
  1639. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1640. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1641. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1642. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1643. ieee80211_mesh_root_setup(ifmsh);
  1644. }
  1645. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1646. /* our current gate announcement implementation rides on root
  1647. * announcements, so require this ifmsh to also be a root node
  1648. * */
  1649. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1650. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  1651. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  1652. ieee80211_mesh_root_setup(ifmsh);
  1653. }
  1654. conf->dot11MeshGateAnnouncementProtocol =
  1655. nconf->dot11MeshGateAnnouncementProtocol;
  1656. }
  1657. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  1658. conf->dot11MeshHWMPRannInterval =
  1659. nconf->dot11MeshHWMPRannInterval;
  1660. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  1661. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  1662. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  1663. /* our RSSI threshold implementation is supported only for
  1664. * devices that report signal in dBm.
  1665. */
  1666. if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
  1667. return -ENOTSUPP;
  1668. conf->rssi_threshold = nconf->rssi_threshold;
  1669. }
  1670. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  1671. conf->ht_opmode = nconf->ht_opmode;
  1672. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  1673. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1674. }
  1675. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  1676. conf->dot11MeshHWMPactivePathToRootTimeout =
  1677. nconf->dot11MeshHWMPactivePathToRootTimeout;
  1678. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  1679. conf->dot11MeshHWMProotInterval =
  1680. nconf->dot11MeshHWMProotInterval;
  1681. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  1682. conf->dot11MeshHWMPconfirmationInterval =
  1683. nconf->dot11MeshHWMPconfirmationInterval;
  1684. if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
  1685. conf->power_mode = nconf->power_mode;
  1686. ieee80211_mps_local_status_update(sdata);
  1687. }
  1688. if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
  1689. conf->dot11MeshAwakeWindowDuration =
  1690. nconf->dot11MeshAwakeWindowDuration;
  1691. if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
  1692. conf->plink_timeout = nconf->plink_timeout;
  1693. ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  1694. return 0;
  1695. }
  1696. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1697. const struct mesh_config *conf,
  1698. const struct mesh_setup *setup)
  1699. {
  1700. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1701. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1702. int err;
  1703. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1704. err = copy_mesh_setup(ifmsh, setup);
  1705. if (err)
  1706. return err;
  1707. sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
  1708. /* can mesh use other SMPS modes? */
  1709. sdata->smps_mode = IEEE80211_SMPS_OFF;
  1710. sdata->needed_rx_chains = sdata->local->rx_chains;
  1711. mutex_lock(&sdata->local->mtx);
  1712. err = ieee80211_vif_use_channel(sdata, &setup->chandef,
  1713. IEEE80211_CHANCTX_SHARED);
  1714. mutex_unlock(&sdata->local->mtx);
  1715. if (err)
  1716. return err;
  1717. return ieee80211_start_mesh(sdata);
  1718. }
  1719. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1720. {
  1721. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1722. ieee80211_stop_mesh(sdata);
  1723. mutex_lock(&sdata->local->mtx);
  1724. ieee80211_vif_release_channel(sdata);
  1725. mutex_unlock(&sdata->local->mtx);
  1726. return 0;
  1727. }
  1728. #endif
  1729. static int ieee80211_change_bss(struct wiphy *wiphy,
  1730. struct net_device *dev,
  1731. struct bss_parameters *params)
  1732. {
  1733. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1734. struct ieee80211_supported_band *sband;
  1735. u32 changed = 0;
  1736. if (!sdata_dereference(sdata->u.ap.beacon, sdata))
  1737. return -ENOENT;
  1738. sband = ieee80211_get_sband(sdata);
  1739. if (!sband)
  1740. return -EINVAL;
  1741. if (params->use_cts_prot >= 0) {
  1742. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1743. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1744. }
  1745. if (params->use_short_preamble >= 0) {
  1746. sdata->vif.bss_conf.use_short_preamble =
  1747. params->use_short_preamble;
  1748. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1749. }
  1750. if (!sdata->vif.bss_conf.use_short_slot &&
  1751. sband->band == NL80211_BAND_5GHZ) {
  1752. sdata->vif.bss_conf.use_short_slot = true;
  1753. changed |= BSS_CHANGED_ERP_SLOT;
  1754. }
  1755. if (params->use_short_slot_time >= 0) {
  1756. sdata->vif.bss_conf.use_short_slot =
  1757. params->use_short_slot_time;
  1758. changed |= BSS_CHANGED_ERP_SLOT;
  1759. }
  1760. if (params->basic_rates) {
  1761. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1762. wiphy->bands[sband->band],
  1763. params->basic_rates,
  1764. params->basic_rates_len,
  1765. &sdata->vif.bss_conf.basic_rates);
  1766. changed |= BSS_CHANGED_BASIC_RATES;
  1767. ieee80211_check_rate_mask(sdata);
  1768. }
  1769. if (params->ap_isolate >= 0) {
  1770. if (params->ap_isolate)
  1771. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1772. else
  1773. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1774. ieee80211_check_fast_rx_iface(sdata);
  1775. }
  1776. if (params->ht_opmode >= 0) {
  1777. sdata->vif.bss_conf.ht_operation_mode =
  1778. (u16) params->ht_opmode;
  1779. changed |= BSS_CHANGED_HT;
  1780. }
  1781. if (params->p2p_ctwindow >= 0) {
  1782. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1783. ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1784. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1785. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1786. changed |= BSS_CHANGED_P2P_PS;
  1787. }
  1788. if (params->p2p_opp_ps > 0) {
  1789. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1790. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1791. changed |= BSS_CHANGED_P2P_PS;
  1792. } else if (params->p2p_opp_ps == 0) {
  1793. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1794. ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1795. changed |= BSS_CHANGED_P2P_PS;
  1796. }
  1797. ieee80211_bss_info_change_notify(sdata, changed);
  1798. return 0;
  1799. }
  1800. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1801. struct net_device *dev,
  1802. struct ieee80211_txq_params *params)
  1803. {
  1804. struct ieee80211_local *local = wiphy_priv(wiphy);
  1805. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1806. struct ieee80211_tx_queue_params p;
  1807. if (!local->ops->conf_tx)
  1808. return -EOPNOTSUPP;
  1809. if (local->hw.queues < IEEE80211_NUM_ACS)
  1810. return -EOPNOTSUPP;
  1811. memset(&p, 0, sizeof(p));
  1812. p.aifs = params->aifs;
  1813. p.cw_max = params->cwmax;
  1814. p.cw_min = params->cwmin;
  1815. p.txop = params->txop;
  1816. /*
  1817. * Setting tx queue params disables u-apsd because it's only
  1818. * called in master mode.
  1819. */
  1820. p.uapsd = false;
  1821. ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
  1822. sdata->tx_conf[params->ac] = p;
  1823. if (drv_conf_tx(local, sdata, params->ac, &p)) {
  1824. wiphy_debug(local->hw.wiphy,
  1825. "failed to set TX queue parameters for AC %d\n",
  1826. params->ac);
  1827. return -EINVAL;
  1828. }
  1829. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  1830. return 0;
  1831. }
  1832. #ifdef CONFIG_PM
  1833. static int ieee80211_suspend(struct wiphy *wiphy,
  1834. struct cfg80211_wowlan *wowlan)
  1835. {
  1836. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1837. }
  1838. static int ieee80211_resume(struct wiphy *wiphy)
  1839. {
  1840. return __ieee80211_resume(wiphy_priv(wiphy));
  1841. }
  1842. #else
  1843. #define ieee80211_suspend NULL
  1844. #define ieee80211_resume NULL
  1845. #endif
  1846. static int ieee80211_scan(struct wiphy *wiphy,
  1847. struct cfg80211_scan_request *req)
  1848. {
  1849. struct ieee80211_sub_if_data *sdata;
  1850. sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
  1851. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1852. case NL80211_IFTYPE_STATION:
  1853. case NL80211_IFTYPE_ADHOC:
  1854. case NL80211_IFTYPE_MESH_POINT:
  1855. case NL80211_IFTYPE_P2P_CLIENT:
  1856. case NL80211_IFTYPE_P2P_DEVICE:
  1857. break;
  1858. case NL80211_IFTYPE_P2P_GO:
  1859. if (sdata->local->ops->hw_scan)
  1860. break;
  1861. /*
  1862. * FIXME: implement NoA while scanning in software,
  1863. * for now fall through to allow scanning only when
  1864. * beaconing hasn't been configured yet
  1865. */
  1866. /* fall through */
  1867. case NL80211_IFTYPE_AP:
  1868. /*
  1869. * If the scan has been forced (and the driver supports
  1870. * forcing), don't care about being beaconing already.
  1871. * This will create problems to the attached stations (e.g. all
  1872. * the frames sent while scanning on other channel will be
  1873. * lost)
  1874. */
  1875. if (sdata->u.ap.beacon &&
  1876. (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
  1877. !(req->flags & NL80211_SCAN_FLAG_AP)))
  1878. return -EOPNOTSUPP;
  1879. break;
  1880. case NL80211_IFTYPE_NAN:
  1881. default:
  1882. return -EOPNOTSUPP;
  1883. }
  1884. return ieee80211_request_scan(sdata, req);
  1885. }
  1886. static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
  1887. {
  1888. ieee80211_scan_cancel(wiphy_priv(wiphy));
  1889. }
  1890. static int
  1891. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1892. struct net_device *dev,
  1893. struct cfg80211_sched_scan_request *req)
  1894. {
  1895. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1896. if (!sdata->local->ops->sched_scan_start)
  1897. return -EOPNOTSUPP;
  1898. return ieee80211_request_sched_scan_start(sdata, req);
  1899. }
  1900. static int
  1901. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
  1902. u64 reqid)
  1903. {
  1904. struct ieee80211_local *local = wiphy_priv(wiphy);
  1905. if (!local->ops->sched_scan_stop)
  1906. return -EOPNOTSUPP;
  1907. return ieee80211_request_sched_scan_stop(local);
  1908. }
  1909. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1910. struct cfg80211_auth_request *req)
  1911. {
  1912. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1913. }
  1914. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1915. struct cfg80211_assoc_request *req)
  1916. {
  1917. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1918. }
  1919. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1920. struct cfg80211_deauth_request *req)
  1921. {
  1922. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1923. }
  1924. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1925. struct cfg80211_disassoc_request *req)
  1926. {
  1927. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1928. }
  1929. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1930. struct cfg80211_ibss_params *params)
  1931. {
  1932. return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
  1933. }
  1934. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1935. {
  1936. return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1937. }
  1938. static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
  1939. struct ocb_setup *setup)
  1940. {
  1941. return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
  1942. }
  1943. static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
  1944. {
  1945. return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1946. }
  1947. static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
  1948. int rate[NUM_NL80211_BANDS])
  1949. {
  1950. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1951. memcpy(sdata->vif.bss_conf.mcast_rate, rate,
  1952. sizeof(int) * NUM_NL80211_BANDS);
  1953. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
  1954. return 0;
  1955. }
  1956. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1957. {
  1958. struct ieee80211_local *local = wiphy_priv(wiphy);
  1959. int err;
  1960. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1961. ieee80211_check_fast_xmit_all(local);
  1962. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1963. if (err) {
  1964. ieee80211_check_fast_xmit_all(local);
  1965. return err;
  1966. }
  1967. }
  1968. if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
  1969. (changed & WIPHY_PARAM_DYN_ACK)) {
  1970. s16 coverage_class;
  1971. coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
  1972. wiphy->coverage_class : -1;
  1973. err = drv_set_coverage_class(local, coverage_class);
  1974. if (err)
  1975. return err;
  1976. }
  1977. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1978. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1979. if (err)
  1980. return err;
  1981. }
  1982. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  1983. if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
  1984. return -EINVAL;
  1985. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1986. }
  1987. if (changed & WIPHY_PARAM_RETRY_LONG) {
  1988. if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
  1989. return -EINVAL;
  1990. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1991. }
  1992. if (changed &
  1993. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1994. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1995. if (changed & (WIPHY_PARAM_TXQ_LIMIT |
  1996. WIPHY_PARAM_TXQ_MEMORY_LIMIT |
  1997. WIPHY_PARAM_TXQ_QUANTUM))
  1998. ieee80211_txq_set_params(local);
  1999. return 0;
  2000. }
  2001. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  2002. struct wireless_dev *wdev,
  2003. enum nl80211_tx_power_setting type, int mbm)
  2004. {
  2005. struct ieee80211_local *local = wiphy_priv(wiphy);
  2006. struct ieee80211_sub_if_data *sdata;
  2007. enum nl80211_tx_power_setting txp_type = type;
  2008. bool update_txp_type = false;
  2009. bool has_monitor = false;
  2010. if (wdev) {
  2011. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2012. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2013. sdata = rtnl_dereference(local->monitor_sdata);
  2014. if (!sdata)
  2015. return -EOPNOTSUPP;
  2016. }
  2017. switch (type) {
  2018. case NL80211_TX_POWER_AUTOMATIC:
  2019. sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  2020. txp_type = NL80211_TX_POWER_LIMITED;
  2021. break;
  2022. case NL80211_TX_POWER_LIMITED:
  2023. case NL80211_TX_POWER_FIXED:
  2024. if (mbm < 0 || (mbm % 100))
  2025. return -EOPNOTSUPP;
  2026. sdata->user_power_level = MBM_TO_DBM(mbm);
  2027. break;
  2028. }
  2029. if (txp_type != sdata->vif.bss_conf.txpower_type) {
  2030. update_txp_type = true;
  2031. sdata->vif.bss_conf.txpower_type = txp_type;
  2032. }
  2033. ieee80211_recalc_txpower(sdata, update_txp_type);
  2034. return 0;
  2035. }
  2036. switch (type) {
  2037. case NL80211_TX_POWER_AUTOMATIC:
  2038. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  2039. txp_type = NL80211_TX_POWER_LIMITED;
  2040. break;
  2041. case NL80211_TX_POWER_LIMITED:
  2042. case NL80211_TX_POWER_FIXED:
  2043. if (mbm < 0 || (mbm % 100))
  2044. return -EOPNOTSUPP;
  2045. local->user_power_level = MBM_TO_DBM(mbm);
  2046. break;
  2047. }
  2048. mutex_lock(&local->iflist_mtx);
  2049. list_for_each_entry(sdata, &local->interfaces, list) {
  2050. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2051. has_monitor = true;
  2052. continue;
  2053. }
  2054. sdata->user_power_level = local->user_power_level;
  2055. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2056. update_txp_type = true;
  2057. sdata->vif.bss_conf.txpower_type = txp_type;
  2058. }
  2059. list_for_each_entry(sdata, &local->interfaces, list) {
  2060. if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
  2061. continue;
  2062. ieee80211_recalc_txpower(sdata, update_txp_type);
  2063. }
  2064. mutex_unlock(&local->iflist_mtx);
  2065. if (has_monitor) {
  2066. sdata = rtnl_dereference(local->monitor_sdata);
  2067. if (sdata) {
  2068. sdata->user_power_level = local->user_power_level;
  2069. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2070. update_txp_type = true;
  2071. sdata->vif.bss_conf.txpower_type = txp_type;
  2072. ieee80211_recalc_txpower(sdata, update_txp_type);
  2073. }
  2074. }
  2075. return 0;
  2076. }
  2077. static int ieee80211_get_tx_power(struct wiphy *wiphy,
  2078. struct wireless_dev *wdev,
  2079. int *dbm)
  2080. {
  2081. struct ieee80211_local *local = wiphy_priv(wiphy);
  2082. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2083. if (local->ops->get_txpower)
  2084. return drv_get_txpower(local, sdata, dbm);
  2085. if (!local->use_chanctx)
  2086. *dbm = local->hw.conf.power_level;
  2087. else
  2088. *dbm = sdata->vif.bss_conf.txpower;
  2089. return 0;
  2090. }
  2091. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  2092. const u8 *addr)
  2093. {
  2094. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2095. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  2096. return 0;
  2097. }
  2098. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  2099. {
  2100. struct ieee80211_local *local = wiphy_priv(wiphy);
  2101. drv_rfkill_poll(local);
  2102. }
  2103. #ifdef CONFIG_NL80211_TESTMODE
  2104. static int ieee80211_testmode_cmd(struct wiphy *wiphy,
  2105. struct wireless_dev *wdev,
  2106. void *data, int len)
  2107. {
  2108. struct ieee80211_local *local = wiphy_priv(wiphy);
  2109. struct ieee80211_vif *vif = NULL;
  2110. if (!local->ops->testmode_cmd)
  2111. return -EOPNOTSUPP;
  2112. if (wdev) {
  2113. struct ieee80211_sub_if_data *sdata;
  2114. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2115. if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
  2116. vif = &sdata->vif;
  2117. }
  2118. return local->ops->testmode_cmd(&local->hw, vif, data, len);
  2119. }
  2120. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  2121. struct sk_buff *skb,
  2122. struct netlink_callback *cb,
  2123. void *data, int len)
  2124. {
  2125. struct ieee80211_local *local = wiphy_priv(wiphy);
  2126. if (!local->ops->testmode_dump)
  2127. return -EOPNOTSUPP;
  2128. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  2129. }
  2130. #endif
  2131. int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
  2132. enum ieee80211_smps_mode smps_mode)
  2133. {
  2134. struct sta_info *sta;
  2135. enum ieee80211_smps_mode old_req;
  2136. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
  2137. return -EINVAL;
  2138. if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2139. return 0;
  2140. old_req = sdata->u.ap.req_smps;
  2141. sdata->u.ap.req_smps = smps_mode;
  2142. /* AUTOMATIC doesn't mean much for AP - don't allow it */
  2143. if (old_req == smps_mode ||
  2144. smps_mode == IEEE80211_SMPS_AUTOMATIC)
  2145. return 0;
  2146. ht_dbg(sdata,
  2147. "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
  2148. smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
  2149. mutex_lock(&sdata->local->sta_mtx);
  2150. list_for_each_entry(sta, &sdata->local->sta_list, list) {
  2151. /*
  2152. * Only stations associated to our AP and
  2153. * associated VLANs
  2154. */
  2155. if (sta->sdata->bss != &sdata->u.ap)
  2156. continue;
  2157. /* This station doesn't support MIMO - skip it */
  2158. if (sta_info_tx_streams(sta) == 1)
  2159. continue;
  2160. /*
  2161. * Don't wake up a STA just to send the action frame
  2162. * unless we are getting more restrictive.
  2163. */
  2164. if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
  2165. !ieee80211_smps_is_restrictive(sta->known_smps_mode,
  2166. smps_mode)) {
  2167. ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
  2168. sta->sta.addr);
  2169. continue;
  2170. }
  2171. /*
  2172. * If the STA is not authorized, wait until it gets
  2173. * authorized and the action frame will be sent then.
  2174. */
  2175. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2176. continue;
  2177. ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
  2178. ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
  2179. sdata->vif.bss_conf.bssid);
  2180. }
  2181. mutex_unlock(&sdata->local->sta_mtx);
  2182. sdata->smps_mode = smps_mode;
  2183. ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
  2184. return 0;
  2185. }
  2186. int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
  2187. enum ieee80211_smps_mode smps_mode)
  2188. {
  2189. const u8 *ap;
  2190. enum ieee80211_smps_mode old_req;
  2191. int err;
  2192. struct sta_info *sta;
  2193. bool tdls_peer_found = false;
  2194. lockdep_assert_held(&sdata->wdev.mtx);
  2195. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
  2196. return -EINVAL;
  2197. old_req = sdata->u.mgd.req_smps;
  2198. sdata->u.mgd.req_smps = smps_mode;
  2199. if (old_req == smps_mode &&
  2200. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  2201. return 0;
  2202. /*
  2203. * If not associated, or current association is not an HT
  2204. * association, there's no need to do anything, just store
  2205. * the new value until we associate.
  2206. */
  2207. if (!sdata->u.mgd.associated ||
  2208. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2209. return 0;
  2210. ap = sdata->u.mgd.associated->bssid;
  2211. rcu_read_lock();
  2212. list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
  2213. if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
  2214. !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2215. continue;
  2216. tdls_peer_found = true;
  2217. break;
  2218. }
  2219. rcu_read_unlock();
  2220. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  2221. if (tdls_peer_found || !sdata->u.mgd.powersave)
  2222. smps_mode = IEEE80211_SMPS_OFF;
  2223. else
  2224. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2225. }
  2226. /* send SM PS frame to AP */
  2227. err = ieee80211_send_smps_action(sdata, smps_mode,
  2228. ap, ap);
  2229. if (err)
  2230. sdata->u.mgd.req_smps = old_req;
  2231. else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
  2232. ieee80211_teardown_tdls_peers(sdata);
  2233. return err;
  2234. }
  2235. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2236. bool enabled, int timeout)
  2237. {
  2238. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2239. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2240. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2241. return -EOPNOTSUPP;
  2242. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
  2243. return -EOPNOTSUPP;
  2244. if (enabled == sdata->u.mgd.powersave &&
  2245. timeout == local->dynamic_ps_forced_timeout)
  2246. return 0;
  2247. sdata->u.mgd.powersave = enabled;
  2248. local->dynamic_ps_forced_timeout = timeout;
  2249. /* no change, but if automatic follow powersave */
  2250. sdata_lock(sdata);
  2251. __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
  2252. sdata_unlock(sdata);
  2253. if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  2254. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2255. ieee80211_recalc_ps(local);
  2256. ieee80211_recalc_ps_vif(sdata);
  2257. ieee80211_check_fast_rx_iface(sdata);
  2258. return 0;
  2259. }
  2260. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  2261. struct net_device *dev,
  2262. s32 rssi_thold, u32 rssi_hyst)
  2263. {
  2264. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2265. struct ieee80211_vif *vif = &sdata->vif;
  2266. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  2267. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  2268. rssi_hyst == bss_conf->cqm_rssi_hyst)
  2269. return 0;
  2270. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
  2271. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
  2272. return -EOPNOTSUPP;
  2273. bss_conf->cqm_rssi_thold = rssi_thold;
  2274. bss_conf->cqm_rssi_hyst = rssi_hyst;
  2275. bss_conf->cqm_rssi_low = 0;
  2276. bss_conf->cqm_rssi_high = 0;
  2277. sdata->u.mgd.last_cqm_event_signal = 0;
  2278. /* tell the driver upon association, unless already associated */
  2279. if (sdata->u.mgd.associated &&
  2280. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  2281. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  2282. return 0;
  2283. }
  2284. static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
  2285. struct net_device *dev,
  2286. s32 rssi_low, s32 rssi_high)
  2287. {
  2288. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2289. struct ieee80211_vif *vif = &sdata->vif;
  2290. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  2291. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  2292. return -EOPNOTSUPP;
  2293. bss_conf->cqm_rssi_low = rssi_low;
  2294. bss_conf->cqm_rssi_high = rssi_high;
  2295. bss_conf->cqm_rssi_thold = 0;
  2296. bss_conf->cqm_rssi_hyst = 0;
  2297. sdata->u.mgd.last_cqm_event_signal = 0;
  2298. /* tell the driver upon association, unless already associated */
  2299. if (sdata->u.mgd.associated &&
  2300. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  2301. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  2302. return 0;
  2303. }
  2304. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  2305. struct net_device *dev,
  2306. const u8 *addr,
  2307. const struct cfg80211_bitrate_mask *mask)
  2308. {
  2309. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2310. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2311. int i, ret;
  2312. if (!ieee80211_sdata_running(sdata))
  2313. return -ENETDOWN;
  2314. /*
  2315. * If active validate the setting and reject it if it doesn't leave
  2316. * at least one basic rate usable, since we really have to be able
  2317. * to send something, and if we're an AP we have to be able to do
  2318. * so at a basic rate so that all clients can receive it.
  2319. */
  2320. if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
  2321. sdata->vif.bss_conf.chandef.chan) {
  2322. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  2323. enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
  2324. if (!(mask->control[band].legacy & basic_rates))
  2325. return -EINVAL;
  2326. }
  2327. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
  2328. ret = drv_set_bitrate_mask(local, sdata, mask);
  2329. if (ret)
  2330. return ret;
  2331. }
  2332. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  2333. struct ieee80211_supported_band *sband = wiphy->bands[i];
  2334. int j;
  2335. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  2336. memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
  2337. sizeof(mask->control[i].ht_mcs));
  2338. memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
  2339. mask->control[i].vht_mcs,
  2340. sizeof(mask->control[i].vht_mcs));
  2341. sdata->rc_has_mcs_mask[i] = false;
  2342. sdata->rc_has_vht_mcs_mask[i] = false;
  2343. if (!sband)
  2344. continue;
  2345. for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
  2346. if (~sdata->rc_rateidx_mcs_mask[i][j]) {
  2347. sdata->rc_has_mcs_mask[i] = true;
  2348. break;
  2349. }
  2350. }
  2351. for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
  2352. if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
  2353. sdata->rc_has_vht_mcs_mask[i] = true;
  2354. break;
  2355. }
  2356. }
  2357. }
  2358. return 0;
  2359. }
  2360. static int ieee80211_start_radar_detection(struct wiphy *wiphy,
  2361. struct net_device *dev,
  2362. struct cfg80211_chan_def *chandef,
  2363. u32 cac_time_ms)
  2364. {
  2365. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2366. struct ieee80211_local *local = sdata->local;
  2367. int err;
  2368. mutex_lock(&local->mtx);
  2369. if (!list_empty(&local->roc_list) || local->scanning) {
  2370. err = -EBUSY;
  2371. goto out_unlock;
  2372. }
  2373. /* whatever, but channel contexts should not complain about that one */
  2374. sdata->smps_mode = IEEE80211_SMPS_OFF;
  2375. sdata->needed_rx_chains = local->rx_chains;
  2376. err = ieee80211_vif_use_channel(sdata, chandef,
  2377. IEEE80211_CHANCTX_SHARED);
  2378. if (err)
  2379. goto out_unlock;
  2380. ieee80211_queue_delayed_work(&sdata->local->hw,
  2381. &sdata->dfs_cac_timer_work,
  2382. msecs_to_jiffies(cac_time_ms));
  2383. out_unlock:
  2384. mutex_unlock(&local->mtx);
  2385. return err;
  2386. }
  2387. static struct cfg80211_beacon_data *
  2388. cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
  2389. {
  2390. struct cfg80211_beacon_data *new_beacon;
  2391. u8 *pos;
  2392. int len;
  2393. len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
  2394. beacon->proberesp_ies_len + beacon->assocresp_ies_len +
  2395. beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
  2396. new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
  2397. if (!new_beacon)
  2398. return NULL;
  2399. pos = (u8 *)(new_beacon + 1);
  2400. if (beacon->head_len) {
  2401. new_beacon->head_len = beacon->head_len;
  2402. new_beacon->head = pos;
  2403. memcpy(pos, beacon->head, beacon->head_len);
  2404. pos += beacon->head_len;
  2405. }
  2406. if (beacon->tail_len) {
  2407. new_beacon->tail_len = beacon->tail_len;
  2408. new_beacon->tail = pos;
  2409. memcpy(pos, beacon->tail, beacon->tail_len);
  2410. pos += beacon->tail_len;
  2411. }
  2412. if (beacon->beacon_ies_len) {
  2413. new_beacon->beacon_ies_len = beacon->beacon_ies_len;
  2414. new_beacon->beacon_ies = pos;
  2415. memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
  2416. pos += beacon->beacon_ies_len;
  2417. }
  2418. if (beacon->proberesp_ies_len) {
  2419. new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
  2420. new_beacon->proberesp_ies = pos;
  2421. memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
  2422. pos += beacon->proberesp_ies_len;
  2423. }
  2424. if (beacon->assocresp_ies_len) {
  2425. new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
  2426. new_beacon->assocresp_ies = pos;
  2427. memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
  2428. pos += beacon->assocresp_ies_len;
  2429. }
  2430. if (beacon->probe_resp_len) {
  2431. new_beacon->probe_resp_len = beacon->probe_resp_len;
  2432. new_beacon->probe_resp = pos;
  2433. memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
  2434. pos += beacon->probe_resp_len;
  2435. }
  2436. /* might copy -1, meaning no changes requested */
  2437. new_beacon->ftm_responder = beacon->ftm_responder;
  2438. if (beacon->lci) {
  2439. new_beacon->lci_len = beacon->lci_len;
  2440. new_beacon->lci = pos;
  2441. memcpy(pos, beacon->lci, beacon->lci_len);
  2442. pos += beacon->lci_len;
  2443. }
  2444. if (beacon->civicloc) {
  2445. new_beacon->civicloc_len = beacon->civicloc_len;
  2446. new_beacon->civicloc = pos;
  2447. memcpy(pos, beacon->civicloc, beacon->civicloc_len);
  2448. pos += beacon->civicloc_len;
  2449. }
  2450. return new_beacon;
  2451. }
  2452. void ieee80211_csa_finish(struct ieee80211_vif *vif)
  2453. {
  2454. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2455. ieee80211_queue_work(&sdata->local->hw,
  2456. &sdata->csa_finalize_work);
  2457. }
  2458. EXPORT_SYMBOL(ieee80211_csa_finish);
  2459. static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
  2460. u32 *changed)
  2461. {
  2462. int err;
  2463. switch (sdata->vif.type) {
  2464. case NL80211_IFTYPE_AP:
  2465. err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
  2466. NULL);
  2467. kfree(sdata->u.ap.next_beacon);
  2468. sdata->u.ap.next_beacon = NULL;
  2469. if (err < 0)
  2470. return err;
  2471. *changed |= err;
  2472. break;
  2473. case NL80211_IFTYPE_ADHOC:
  2474. err = ieee80211_ibss_finish_csa(sdata);
  2475. if (err < 0)
  2476. return err;
  2477. *changed |= err;
  2478. break;
  2479. #ifdef CONFIG_MAC80211_MESH
  2480. case NL80211_IFTYPE_MESH_POINT:
  2481. err = ieee80211_mesh_finish_csa(sdata);
  2482. if (err < 0)
  2483. return err;
  2484. *changed |= err;
  2485. break;
  2486. #endif
  2487. default:
  2488. WARN_ON(1);
  2489. return -EINVAL;
  2490. }
  2491. return 0;
  2492. }
  2493. static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
  2494. {
  2495. struct ieee80211_local *local = sdata->local;
  2496. u32 changed = 0;
  2497. int err;
  2498. sdata_assert_lock(sdata);
  2499. lockdep_assert_held(&local->mtx);
  2500. lockdep_assert_held(&local->chanctx_mtx);
  2501. /*
  2502. * using reservation isn't immediate as it may be deferred until later
  2503. * with multi-vif. once reservation is complete it will re-schedule the
  2504. * work with no reserved_chanctx so verify chandef to check if it
  2505. * completed successfully
  2506. */
  2507. if (sdata->reserved_chanctx) {
  2508. /*
  2509. * with multi-vif csa driver may call ieee80211_csa_finish()
  2510. * many times while waiting for other interfaces to use their
  2511. * reservations
  2512. */
  2513. if (sdata->reserved_ready)
  2514. return 0;
  2515. return ieee80211_vif_use_reserved_context(sdata);
  2516. }
  2517. if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
  2518. &sdata->csa_chandef))
  2519. return -EINVAL;
  2520. sdata->vif.csa_active = false;
  2521. err = ieee80211_set_after_csa_beacon(sdata, &changed);
  2522. if (err)
  2523. return err;
  2524. ieee80211_bss_info_change_notify(sdata, changed);
  2525. if (sdata->csa_block_tx) {
  2526. ieee80211_wake_vif_queues(local, sdata,
  2527. IEEE80211_QUEUE_STOP_REASON_CSA);
  2528. sdata->csa_block_tx = false;
  2529. }
  2530. err = drv_post_channel_switch(sdata);
  2531. if (err)
  2532. return err;
  2533. cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
  2534. return 0;
  2535. }
  2536. static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
  2537. {
  2538. if (__ieee80211_csa_finalize(sdata)) {
  2539. sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
  2540. cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
  2541. GFP_KERNEL);
  2542. }
  2543. }
  2544. void ieee80211_csa_finalize_work(struct work_struct *work)
  2545. {
  2546. struct ieee80211_sub_if_data *sdata =
  2547. container_of(work, struct ieee80211_sub_if_data,
  2548. csa_finalize_work);
  2549. struct ieee80211_local *local = sdata->local;
  2550. sdata_lock(sdata);
  2551. mutex_lock(&local->mtx);
  2552. mutex_lock(&local->chanctx_mtx);
  2553. /* AP might have been stopped while waiting for the lock. */
  2554. if (!sdata->vif.csa_active)
  2555. goto unlock;
  2556. if (!ieee80211_sdata_running(sdata))
  2557. goto unlock;
  2558. ieee80211_csa_finalize(sdata);
  2559. unlock:
  2560. mutex_unlock(&local->chanctx_mtx);
  2561. mutex_unlock(&local->mtx);
  2562. sdata_unlock(sdata);
  2563. }
  2564. static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
  2565. struct cfg80211_csa_settings *params,
  2566. u32 *changed)
  2567. {
  2568. struct ieee80211_csa_settings csa = {};
  2569. int err;
  2570. switch (sdata->vif.type) {
  2571. case NL80211_IFTYPE_AP:
  2572. sdata->u.ap.next_beacon =
  2573. cfg80211_beacon_dup(&params->beacon_after);
  2574. if (!sdata->u.ap.next_beacon)
  2575. return -ENOMEM;
  2576. /*
  2577. * With a count of 0, we don't have to wait for any
  2578. * TBTT before switching, so complete the CSA
  2579. * immediately. In theory, with a count == 1 we
  2580. * should delay the switch until just before the next
  2581. * TBTT, but that would complicate things so we switch
  2582. * immediately too. If we would delay the switch
  2583. * until the next TBTT, we would have to set the probe
  2584. * response here.
  2585. *
  2586. * TODO: A channel switch with count <= 1 without
  2587. * sending a CSA action frame is kind of useless,
  2588. * because the clients won't know we're changing
  2589. * channels. The action frame must be implemented
  2590. * either here or in the userspace.
  2591. */
  2592. if (params->count <= 1)
  2593. break;
  2594. if ((params->n_counter_offsets_beacon >
  2595. IEEE80211_MAX_CSA_COUNTERS_NUM) ||
  2596. (params->n_counter_offsets_presp >
  2597. IEEE80211_MAX_CSA_COUNTERS_NUM))
  2598. return -EINVAL;
  2599. csa.counter_offsets_beacon = params->counter_offsets_beacon;
  2600. csa.counter_offsets_presp = params->counter_offsets_presp;
  2601. csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
  2602. csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
  2603. csa.count = params->count;
  2604. err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
  2605. if (err < 0) {
  2606. kfree(sdata->u.ap.next_beacon);
  2607. return err;
  2608. }
  2609. *changed |= err;
  2610. break;
  2611. case NL80211_IFTYPE_ADHOC:
  2612. if (!sdata->vif.bss_conf.ibss_joined)
  2613. return -EINVAL;
  2614. if (params->chandef.width != sdata->u.ibss.chandef.width)
  2615. return -EINVAL;
  2616. switch (params->chandef.width) {
  2617. case NL80211_CHAN_WIDTH_40:
  2618. if (cfg80211_get_chandef_type(&params->chandef) !=
  2619. cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
  2620. return -EINVAL;
  2621. case NL80211_CHAN_WIDTH_5:
  2622. case NL80211_CHAN_WIDTH_10:
  2623. case NL80211_CHAN_WIDTH_20_NOHT:
  2624. case NL80211_CHAN_WIDTH_20:
  2625. break;
  2626. default:
  2627. return -EINVAL;
  2628. }
  2629. /* changes into another band are not supported */
  2630. if (sdata->u.ibss.chandef.chan->band !=
  2631. params->chandef.chan->band)
  2632. return -EINVAL;
  2633. /* see comments in the NL80211_IFTYPE_AP block */
  2634. if (params->count > 1) {
  2635. err = ieee80211_ibss_csa_beacon(sdata, params);
  2636. if (err < 0)
  2637. return err;
  2638. *changed |= err;
  2639. }
  2640. ieee80211_send_action_csa(sdata, params);
  2641. break;
  2642. #ifdef CONFIG_MAC80211_MESH
  2643. case NL80211_IFTYPE_MESH_POINT: {
  2644. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2645. if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
  2646. return -EINVAL;
  2647. /* changes into another band are not supported */
  2648. if (sdata->vif.bss_conf.chandef.chan->band !=
  2649. params->chandef.chan->band)
  2650. return -EINVAL;
  2651. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
  2652. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
  2653. if (!ifmsh->pre_value)
  2654. ifmsh->pre_value = 1;
  2655. else
  2656. ifmsh->pre_value++;
  2657. }
  2658. /* see comments in the NL80211_IFTYPE_AP block */
  2659. if (params->count > 1) {
  2660. err = ieee80211_mesh_csa_beacon(sdata, params);
  2661. if (err < 0) {
  2662. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
  2663. return err;
  2664. }
  2665. *changed |= err;
  2666. }
  2667. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
  2668. ieee80211_send_action_csa(sdata, params);
  2669. break;
  2670. }
  2671. #endif
  2672. default:
  2673. return -EOPNOTSUPP;
  2674. }
  2675. return 0;
  2676. }
  2677. static int
  2678. __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  2679. struct cfg80211_csa_settings *params)
  2680. {
  2681. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2682. struct ieee80211_local *local = sdata->local;
  2683. struct ieee80211_channel_switch ch_switch;
  2684. struct ieee80211_chanctx_conf *conf;
  2685. struct ieee80211_chanctx *chanctx;
  2686. u32 changed = 0;
  2687. int err;
  2688. sdata_assert_lock(sdata);
  2689. lockdep_assert_held(&local->mtx);
  2690. if (!list_empty(&local->roc_list) || local->scanning)
  2691. return -EBUSY;
  2692. if (sdata->wdev.cac_started)
  2693. return -EBUSY;
  2694. if (cfg80211_chandef_identical(&params->chandef,
  2695. &sdata->vif.bss_conf.chandef))
  2696. return -EINVAL;
  2697. /* don't allow another channel switch if one is already active. */
  2698. if (sdata->vif.csa_active)
  2699. return -EBUSY;
  2700. mutex_lock(&local->chanctx_mtx);
  2701. conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  2702. lockdep_is_held(&local->chanctx_mtx));
  2703. if (!conf) {
  2704. err = -EBUSY;
  2705. goto out;
  2706. }
  2707. chanctx = container_of(conf, struct ieee80211_chanctx, conf);
  2708. ch_switch.timestamp = 0;
  2709. ch_switch.device_timestamp = 0;
  2710. ch_switch.block_tx = params->block_tx;
  2711. ch_switch.chandef = params->chandef;
  2712. ch_switch.count = params->count;
  2713. err = drv_pre_channel_switch(sdata, &ch_switch);
  2714. if (err)
  2715. goto out;
  2716. err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
  2717. chanctx->mode,
  2718. params->radar_required);
  2719. if (err)
  2720. goto out;
  2721. /* if reservation is invalid then this will fail */
  2722. err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
  2723. if (err) {
  2724. ieee80211_vif_unreserve_chanctx(sdata);
  2725. goto out;
  2726. }
  2727. err = ieee80211_set_csa_beacon(sdata, params, &changed);
  2728. if (err) {
  2729. ieee80211_vif_unreserve_chanctx(sdata);
  2730. goto out;
  2731. }
  2732. sdata->csa_chandef = params->chandef;
  2733. sdata->csa_block_tx = params->block_tx;
  2734. sdata->vif.csa_active = true;
  2735. if (sdata->csa_block_tx)
  2736. ieee80211_stop_vif_queues(local, sdata,
  2737. IEEE80211_QUEUE_STOP_REASON_CSA);
  2738. cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
  2739. params->count);
  2740. if (changed) {
  2741. ieee80211_bss_info_change_notify(sdata, changed);
  2742. drv_channel_switch_beacon(sdata, &params->chandef);
  2743. } else {
  2744. /* if the beacon didn't change, we can finalize immediately */
  2745. ieee80211_csa_finalize(sdata);
  2746. }
  2747. out:
  2748. mutex_unlock(&local->chanctx_mtx);
  2749. return err;
  2750. }
  2751. int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  2752. struct cfg80211_csa_settings *params)
  2753. {
  2754. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2755. struct ieee80211_local *local = sdata->local;
  2756. int err;
  2757. mutex_lock(&local->mtx);
  2758. err = __ieee80211_channel_switch(wiphy, dev, params);
  2759. mutex_unlock(&local->mtx);
  2760. return err;
  2761. }
  2762. u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
  2763. {
  2764. lockdep_assert_held(&local->mtx);
  2765. local->roc_cookie_counter++;
  2766. /* wow, you wrapped 64 bits ... more likely a bug */
  2767. if (WARN_ON(local->roc_cookie_counter == 0))
  2768. local->roc_cookie_counter++;
  2769. return local->roc_cookie_counter;
  2770. }
  2771. int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
  2772. u64 *cookie, gfp_t gfp)
  2773. {
  2774. unsigned long spin_flags;
  2775. struct sk_buff *ack_skb;
  2776. int id;
  2777. ack_skb = skb_copy(skb, gfp);
  2778. if (!ack_skb)
  2779. return -ENOMEM;
  2780. spin_lock_irqsave(&local->ack_status_lock, spin_flags);
  2781. id = idr_alloc(&local->ack_status_frames, ack_skb,
  2782. 1, 0x10000, GFP_ATOMIC);
  2783. spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
  2784. if (id < 0) {
  2785. kfree_skb(ack_skb);
  2786. return -ENOMEM;
  2787. }
  2788. IEEE80211_SKB_CB(skb)->ack_frame_id = id;
  2789. *cookie = ieee80211_mgmt_tx_cookie(local);
  2790. IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
  2791. return 0;
  2792. }
  2793. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  2794. struct wireless_dev *wdev,
  2795. u16 frame_type, bool reg)
  2796. {
  2797. struct ieee80211_local *local = wiphy_priv(wiphy);
  2798. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2799. switch (frame_type) {
  2800. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
  2801. if (reg) {
  2802. local->probe_req_reg++;
  2803. sdata->vif.probe_req_reg++;
  2804. } else {
  2805. if (local->probe_req_reg)
  2806. local->probe_req_reg--;
  2807. if (sdata->vif.probe_req_reg)
  2808. sdata->vif.probe_req_reg--;
  2809. }
  2810. if (!local->open_count)
  2811. break;
  2812. if (sdata->vif.probe_req_reg == 1)
  2813. drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
  2814. FIF_PROBE_REQ);
  2815. else if (sdata->vif.probe_req_reg == 0)
  2816. drv_config_iface_filter(local, sdata, 0,
  2817. FIF_PROBE_REQ);
  2818. ieee80211_configure_filter(local);
  2819. break;
  2820. default:
  2821. break;
  2822. }
  2823. }
  2824. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  2825. {
  2826. struct ieee80211_local *local = wiphy_priv(wiphy);
  2827. if (local->started)
  2828. return -EOPNOTSUPP;
  2829. return drv_set_antenna(local, tx_ant, rx_ant);
  2830. }
  2831. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  2832. {
  2833. struct ieee80211_local *local = wiphy_priv(wiphy);
  2834. return drv_get_antenna(local, tx_ant, rx_ant);
  2835. }
  2836. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  2837. struct net_device *dev,
  2838. struct cfg80211_gtk_rekey_data *data)
  2839. {
  2840. struct ieee80211_local *local = wiphy_priv(wiphy);
  2841. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2842. if (!local->ops->set_rekey_data)
  2843. return -EOPNOTSUPP;
  2844. drv_set_rekey_data(local, sdata, data);
  2845. return 0;
  2846. }
  2847. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2848. const u8 *peer, u64 *cookie)
  2849. {
  2850. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2851. struct ieee80211_local *local = sdata->local;
  2852. struct ieee80211_qos_hdr *nullfunc;
  2853. struct sk_buff *skb;
  2854. int size = sizeof(*nullfunc);
  2855. __le16 fc;
  2856. bool qos;
  2857. struct ieee80211_tx_info *info;
  2858. struct sta_info *sta;
  2859. struct ieee80211_chanctx_conf *chanctx_conf;
  2860. enum nl80211_band band;
  2861. int ret;
  2862. /* the lock is needed to assign the cookie later */
  2863. mutex_lock(&local->mtx);
  2864. rcu_read_lock();
  2865. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2866. if (WARN_ON(!chanctx_conf)) {
  2867. ret = -EINVAL;
  2868. goto unlock;
  2869. }
  2870. band = chanctx_conf->def.chan->band;
  2871. sta = sta_info_get_bss(sdata, peer);
  2872. if (sta) {
  2873. qos = sta->sta.wme;
  2874. } else {
  2875. ret = -ENOLINK;
  2876. goto unlock;
  2877. }
  2878. if (qos) {
  2879. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2880. IEEE80211_STYPE_QOS_NULLFUNC |
  2881. IEEE80211_FCTL_FROMDS);
  2882. } else {
  2883. size -= 2;
  2884. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2885. IEEE80211_STYPE_NULLFUNC |
  2886. IEEE80211_FCTL_FROMDS);
  2887. }
  2888. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2889. if (!skb) {
  2890. ret = -ENOMEM;
  2891. goto unlock;
  2892. }
  2893. skb->dev = dev;
  2894. skb_reserve(skb, local->hw.extra_tx_headroom);
  2895. nullfunc = skb_put(skb, size);
  2896. nullfunc->frame_control = fc;
  2897. nullfunc->duration_id = 0;
  2898. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2899. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2900. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2901. nullfunc->seq_ctrl = 0;
  2902. info = IEEE80211_SKB_CB(skb);
  2903. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2904. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2905. info->band = band;
  2906. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2907. skb->priority = 7;
  2908. if (qos)
  2909. nullfunc->qos_ctrl = cpu_to_le16(7);
  2910. ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
  2911. if (ret) {
  2912. kfree_skb(skb);
  2913. goto unlock;
  2914. }
  2915. local_bh_disable();
  2916. ieee80211_xmit(sdata, sta, skb, 0);
  2917. local_bh_enable();
  2918. ret = 0;
  2919. unlock:
  2920. rcu_read_unlock();
  2921. mutex_unlock(&local->mtx);
  2922. return ret;
  2923. }
  2924. static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  2925. struct wireless_dev *wdev,
  2926. struct cfg80211_chan_def *chandef)
  2927. {
  2928. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2929. struct ieee80211_local *local = wiphy_priv(wiphy);
  2930. struct ieee80211_chanctx_conf *chanctx_conf;
  2931. int ret = -ENODATA;
  2932. rcu_read_lock();
  2933. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2934. if (chanctx_conf) {
  2935. *chandef = sdata->vif.bss_conf.chandef;
  2936. ret = 0;
  2937. } else if (local->open_count > 0 &&
  2938. local->open_count == local->monitors &&
  2939. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2940. if (local->use_chanctx)
  2941. *chandef = local->monitor_chandef;
  2942. else
  2943. *chandef = local->_oper_chandef;
  2944. ret = 0;
  2945. }
  2946. rcu_read_unlock();
  2947. return ret;
  2948. }
  2949. #ifdef CONFIG_PM
  2950. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  2951. {
  2952. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  2953. }
  2954. #endif
  2955. static int ieee80211_set_qos_map(struct wiphy *wiphy,
  2956. struct net_device *dev,
  2957. struct cfg80211_qos_map *qos_map)
  2958. {
  2959. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2960. struct mac80211_qos_map *new_qos_map, *old_qos_map;
  2961. if (qos_map) {
  2962. new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
  2963. if (!new_qos_map)
  2964. return -ENOMEM;
  2965. memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
  2966. } else {
  2967. /* A NULL qos_map was passed to disable QoS mapping */
  2968. new_qos_map = NULL;
  2969. }
  2970. old_qos_map = sdata_dereference(sdata->qos_map, sdata);
  2971. rcu_assign_pointer(sdata->qos_map, new_qos_map);
  2972. if (old_qos_map)
  2973. kfree_rcu(old_qos_map, rcu_head);
  2974. return 0;
  2975. }
  2976. static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
  2977. struct net_device *dev,
  2978. struct cfg80211_chan_def *chandef)
  2979. {
  2980. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2981. int ret;
  2982. u32 changed = 0;
  2983. ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
  2984. if (ret == 0)
  2985. ieee80211_bss_info_change_notify(sdata, changed);
  2986. return ret;
  2987. }
  2988. static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  2989. u8 tsid, const u8 *peer, u8 up,
  2990. u16 admitted_time)
  2991. {
  2992. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2993. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2994. int ac = ieee802_1d_to_ac[up];
  2995. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2996. return -EOPNOTSUPP;
  2997. if (!(sdata->wmm_acm & BIT(up)))
  2998. return -EINVAL;
  2999. if (ifmgd->tx_tspec[ac].admitted_time)
  3000. return -EBUSY;
  3001. if (admitted_time) {
  3002. ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
  3003. ifmgd->tx_tspec[ac].tsid = tsid;
  3004. ifmgd->tx_tspec[ac].up = up;
  3005. }
  3006. return 0;
  3007. }
  3008. static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  3009. u8 tsid, const u8 *peer)
  3010. {
  3011. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3012. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3013. struct ieee80211_local *local = wiphy_priv(wiphy);
  3014. int ac;
  3015. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  3016. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  3017. /* skip unused entries */
  3018. if (!tx_tspec->admitted_time)
  3019. continue;
  3020. if (tx_tspec->tsid != tsid)
  3021. continue;
  3022. /* due to this new packets will be reassigned to non-ACM ACs */
  3023. tx_tspec->up = -1;
  3024. /* Make sure that all packets have been sent to avoid to
  3025. * restore the QoS params on packets that are still on the
  3026. * queues.
  3027. */
  3028. synchronize_net();
  3029. ieee80211_flush_queues(local, sdata, false);
  3030. /* restore the normal QoS parameters
  3031. * (unconditionally to avoid races)
  3032. */
  3033. tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
  3034. tx_tspec->downgraded = false;
  3035. ieee80211_sta_handle_tspec_ac_params(sdata);
  3036. /* finally clear all the data */
  3037. memset(tx_tspec, 0, sizeof(*tx_tspec));
  3038. return 0;
  3039. }
  3040. return -ENOENT;
  3041. }
  3042. void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
  3043. u8 inst_id,
  3044. enum nl80211_nan_func_term_reason reason,
  3045. gfp_t gfp)
  3046. {
  3047. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3048. struct cfg80211_nan_func *func;
  3049. u64 cookie;
  3050. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  3051. return;
  3052. spin_lock_bh(&sdata->u.nan.func_lock);
  3053. func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
  3054. if (WARN_ON(!func)) {
  3055. spin_unlock_bh(&sdata->u.nan.func_lock);
  3056. return;
  3057. }
  3058. cookie = func->cookie;
  3059. idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
  3060. spin_unlock_bh(&sdata->u.nan.func_lock);
  3061. cfg80211_free_nan_func(func);
  3062. cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
  3063. reason, cookie, gfp);
  3064. }
  3065. EXPORT_SYMBOL(ieee80211_nan_func_terminated);
  3066. void ieee80211_nan_func_match(struct ieee80211_vif *vif,
  3067. struct cfg80211_nan_match_params *match,
  3068. gfp_t gfp)
  3069. {
  3070. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3071. struct cfg80211_nan_func *func;
  3072. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  3073. return;
  3074. spin_lock_bh(&sdata->u.nan.func_lock);
  3075. func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
  3076. if (WARN_ON(!func)) {
  3077. spin_unlock_bh(&sdata->u.nan.func_lock);
  3078. return;
  3079. }
  3080. match->cookie = func->cookie;
  3081. spin_unlock_bh(&sdata->u.nan.func_lock);
  3082. cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
  3083. }
  3084. EXPORT_SYMBOL(ieee80211_nan_func_match);
  3085. static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
  3086. struct net_device *dev,
  3087. const bool enabled)
  3088. {
  3089. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3090. sdata->u.ap.multicast_to_unicast = enabled;
  3091. return 0;
  3092. }
  3093. void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
  3094. struct txq_info *txqi)
  3095. {
  3096. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
  3097. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
  3098. txqstats->backlog_bytes = txqi->tin.backlog_bytes;
  3099. }
  3100. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
  3101. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
  3102. txqstats->backlog_packets = txqi->tin.backlog_packets;
  3103. }
  3104. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
  3105. txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
  3106. txqstats->flows = txqi->tin.flows;
  3107. }
  3108. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
  3109. txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
  3110. txqstats->drops = txqi->cstats.drop_count;
  3111. }
  3112. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
  3113. txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
  3114. txqstats->ecn_marks = txqi->cstats.ecn_mark;
  3115. }
  3116. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
  3117. txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
  3118. txqstats->overlimit = txqi->tin.overlimit;
  3119. }
  3120. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
  3121. txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
  3122. txqstats->collisions = txqi->tin.collisions;
  3123. }
  3124. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
  3125. txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
  3126. txqstats->tx_bytes = txqi->tin.tx_bytes;
  3127. }
  3128. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
  3129. txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
  3130. txqstats->tx_packets = txqi->tin.tx_packets;
  3131. }
  3132. }
  3133. static int ieee80211_get_txq_stats(struct wiphy *wiphy,
  3134. struct wireless_dev *wdev,
  3135. struct cfg80211_txq_stats *txqstats)
  3136. {
  3137. struct ieee80211_local *local = wiphy_priv(wiphy);
  3138. struct ieee80211_sub_if_data *sdata;
  3139. int ret = 0;
  3140. if (!local->ops->wake_tx_queue)
  3141. return 1;
  3142. spin_lock_bh(&local->fq.lock);
  3143. rcu_read_lock();
  3144. if (wdev) {
  3145. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  3146. if (!sdata->vif.txq) {
  3147. ret = 1;
  3148. goto out;
  3149. }
  3150. ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
  3151. } else {
  3152. /* phy stats */
  3153. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
  3154. BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
  3155. BIT(NL80211_TXQ_STATS_OVERLIMIT) |
  3156. BIT(NL80211_TXQ_STATS_OVERMEMORY) |
  3157. BIT(NL80211_TXQ_STATS_COLLISIONS) |
  3158. BIT(NL80211_TXQ_STATS_MAX_FLOWS);
  3159. txqstats->backlog_packets = local->fq.backlog;
  3160. txqstats->backlog_bytes = local->fq.memory_usage;
  3161. txqstats->overlimit = local->fq.overlimit;
  3162. txqstats->overmemory = local->fq.overmemory;
  3163. txqstats->collisions = local->fq.collisions;
  3164. txqstats->max_flows = local->fq.flows_cnt;
  3165. }
  3166. out:
  3167. rcu_read_unlock();
  3168. spin_unlock_bh(&local->fq.lock);
  3169. return ret;
  3170. }
  3171. static int
  3172. ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
  3173. struct net_device *dev,
  3174. struct cfg80211_ftm_responder_stats *ftm_stats)
  3175. {
  3176. struct ieee80211_local *local = wiphy_priv(wiphy);
  3177. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3178. return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
  3179. }
  3180. const struct cfg80211_ops mac80211_config_ops = {
  3181. .add_virtual_intf = ieee80211_add_iface,
  3182. .del_virtual_intf = ieee80211_del_iface,
  3183. .change_virtual_intf = ieee80211_change_iface,
  3184. .start_p2p_device = ieee80211_start_p2p_device,
  3185. .stop_p2p_device = ieee80211_stop_p2p_device,
  3186. .add_key = ieee80211_add_key,
  3187. .del_key = ieee80211_del_key,
  3188. .get_key = ieee80211_get_key,
  3189. .set_default_key = ieee80211_config_default_key,
  3190. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  3191. .start_ap = ieee80211_start_ap,
  3192. .change_beacon = ieee80211_change_beacon,
  3193. .stop_ap = ieee80211_stop_ap,
  3194. .add_station = ieee80211_add_station,
  3195. .del_station = ieee80211_del_station,
  3196. .change_station = ieee80211_change_station,
  3197. .get_station = ieee80211_get_station,
  3198. .dump_station = ieee80211_dump_station,
  3199. .dump_survey = ieee80211_dump_survey,
  3200. #ifdef CONFIG_MAC80211_MESH
  3201. .add_mpath = ieee80211_add_mpath,
  3202. .del_mpath = ieee80211_del_mpath,
  3203. .change_mpath = ieee80211_change_mpath,
  3204. .get_mpath = ieee80211_get_mpath,
  3205. .dump_mpath = ieee80211_dump_mpath,
  3206. .get_mpp = ieee80211_get_mpp,
  3207. .dump_mpp = ieee80211_dump_mpp,
  3208. .update_mesh_config = ieee80211_update_mesh_config,
  3209. .get_mesh_config = ieee80211_get_mesh_config,
  3210. .join_mesh = ieee80211_join_mesh,
  3211. .leave_mesh = ieee80211_leave_mesh,
  3212. #endif
  3213. .join_ocb = ieee80211_join_ocb,
  3214. .leave_ocb = ieee80211_leave_ocb,
  3215. .change_bss = ieee80211_change_bss,
  3216. .set_txq_params = ieee80211_set_txq_params,
  3217. .set_monitor_channel = ieee80211_set_monitor_channel,
  3218. .suspend = ieee80211_suspend,
  3219. .resume = ieee80211_resume,
  3220. .scan = ieee80211_scan,
  3221. .abort_scan = ieee80211_abort_scan,
  3222. .sched_scan_start = ieee80211_sched_scan_start,
  3223. .sched_scan_stop = ieee80211_sched_scan_stop,
  3224. .auth = ieee80211_auth,
  3225. .assoc = ieee80211_assoc,
  3226. .deauth = ieee80211_deauth,
  3227. .disassoc = ieee80211_disassoc,
  3228. .join_ibss = ieee80211_join_ibss,
  3229. .leave_ibss = ieee80211_leave_ibss,
  3230. .set_mcast_rate = ieee80211_set_mcast_rate,
  3231. .set_wiphy_params = ieee80211_set_wiphy_params,
  3232. .set_tx_power = ieee80211_set_tx_power,
  3233. .get_tx_power = ieee80211_get_tx_power,
  3234. .set_wds_peer = ieee80211_set_wds_peer,
  3235. .rfkill_poll = ieee80211_rfkill_poll,
  3236. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  3237. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  3238. .set_power_mgmt = ieee80211_set_power_mgmt,
  3239. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  3240. .remain_on_channel = ieee80211_remain_on_channel,
  3241. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  3242. .mgmt_tx = ieee80211_mgmt_tx,
  3243. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  3244. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  3245. .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
  3246. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  3247. .set_antenna = ieee80211_set_antenna,
  3248. .get_antenna = ieee80211_get_antenna,
  3249. .set_rekey_data = ieee80211_set_rekey_data,
  3250. .tdls_oper = ieee80211_tdls_oper,
  3251. .tdls_mgmt = ieee80211_tdls_mgmt,
  3252. .tdls_channel_switch = ieee80211_tdls_channel_switch,
  3253. .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
  3254. .probe_client = ieee80211_probe_client,
  3255. .set_noack_map = ieee80211_set_noack_map,
  3256. #ifdef CONFIG_PM
  3257. .set_wakeup = ieee80211_set_wakeup,
  3258. #endif
  3259. .get_channel = ieee80211_cfg_get_channel,
  3260. .start_radar_detection = ieee80211_start_radar_detection,
  3261. .channel_switch = ieee80211_channel_switch,
  3262. .set_qos_map = ieee80211_set_qos_map,
  3263. .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
  3264. .add_tx_ts = ieee80211_add_tx_ts,
  3265. .del_tx_ts = ieee80211_del_tx_ts,
  3266. .start_nan = ieee80211_start_nan,
  3267. .stop_nan = ieee80211_stop_nan,
  3268. .nan_change_conf = ieee80211_nan_change_conf,
  3269. .add_nan_func = ieee80211_add_nan_func,
  3270. .del_nan_func = ieee80211_del_nan_func,
  3271. .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
  3272. .tx_control_port = ieee80211_tx_control_port,
  3273. .get_txq_stats = ieee80211_get_txq_stats,
  3274. .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
  3275. };