cfg.c 103 KB

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