cfg.c 99 KB

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