cfg.c 102 KB

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