cfg.c 107 KB

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