cfg.c 103 KB

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