cfg.c 95 KB

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