cfg.c 103 KB

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