cfg.c 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948
  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_flag & RX_FLAG_80MHZ)
  388. rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
  389. if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
  390. rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
  391. if (sta->last_rx_rate_flag & RX_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. sdata->radar_required = params->radar_required;
  824. mutex_lock(&local->mtx);
  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. ieee80211_vif_release_channel(sdata);
  869. return err;
  870. }
  871. changed |= err;
  872. err = drv_start_ap(sdata->local, sdata);
  873. if (err) {
  874. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  875. if (old)
  876. kfree_rcu(old, rcu_head);
  877. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  878. ieee80211_vif_release_channel(sdata);
  879. return err;
  880. }
  881. ieee80211_recalc_dtim(local, sdata);
  882. ieee80211_bss_info_change_notify(sdata, changed);
  883. netif_carrier_on(dev);
  884. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  885. netif_carrier_on(vlan->dev);
  886. return 0;
  887. }
  888. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  889. struct cfg80211_beacon_data *params)
  890. {
  891. struct ieee80211_sub_if_data *sdata;
  892. struct beacon_data *old;
  893. int err;
  894. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  895. /* don't allow changing the beacon while CSA is in place - offset
  896. * of channel switch counter may change
  897. */
  898. if (sdata->vif.csa_active)
  899. return -EBUSY;
  900. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  901. if (!old)
  902. return -ENOENT;
  903. err = ieee80211_assign_beacon(sdata, params);
  904. if (err < 0)
  905. return err;
  906. ieee80211_bss_info_change_notify(sdata, err);
  907. return 0;
  908. }
  909. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  910. {
  911. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  912. struct ieee80211_sub_if_data *vlan;
  913. struct ieee80211_local *local = sdata->local;
  914. struct beacon_data *old_beacon;
  915. struct probe_resp *old_probe_resp;
  916. struct cfg80211_chan_def chandef;
  917. old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
  918. if (!old_beacon)
  919. return -ENOENT;
  920. old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
  921. /* abort any running channel switch */
  922. sdata->vif.csa_active = false;
  923. kfree(sdata->u.ap.next_beacon);
  924. sdata->u.ap.next_beacon = NULL;
  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. sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
  936. __sta_info_flush(sdata, true);
  937. ieee80211_free_keys(sdata, true);
  938. sdata->vif.bss_conf.enable_beacon = false;
  939. sdata->vif.bss_conf.ssid_len = 0;
  940. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  941. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  942. if (sdata->wdev.cac_started) {
  943. chandef = sdata->vif.bss_conf.chandef;
  944. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  945. cfg80211_cac_event(sdata->dev, &chandef,
  946. NL80211_RADAR_CAC_ABORTED,
  947. GFP_KERNEL);
  948. }
  949. drv_stop_ap(sdata->local, sdata);
  950. /* free all potentially still buffered bcast frames */
  951. local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
  952. skb_queue_purge(&sdata->u.ap.ps.bc_buf);
  953. ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
  954. mutex_lock(&local->mtx);
  955. ieee80211_vif_release_channel(sdata);
  956. mutex_unlock(&local->mtx);
  957. return 0;
  958. }
  959. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  960. struct iapp_layer2_update {
  961. u8 da[ETH_ALEN]; /* broadcast */
  962. u8 sa[ETH_ALEN]; /* STA addr */
  963. __be16 len; /* 6 */
  964. u8 dsap; /* 0 */
  965. u8 ssap; /* 0 */
  966. u8 control;
  967. u8 xid_info[3];
  968. } __packed;
  969. static void ieee80211_send_layer2_update(struct sta_info *sta)
  970. {
  971. struct iapp_layer2_update *msg;
  972. struct sk_buff *skb;
  973. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  974. * bridge devices */
  975. skb = dev_alloc_skb(sizeof(*msg));
  976. if (!skb)
  977. return;
  978. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  979. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  980. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  981. eth_broadcast_addr(msg->da);
  982. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  983. msg->len = htons(6);
  984. msg->dsap = 0;
  985. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  986. msg->control = 0xaf; /* XID response lsb.1111F101.
  987. * F=0 (no poll command; unsolicited frame) */
  988. msg->xid_info[0] = 0x81; /* XID format identifier */
  989. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  990. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  991. skb->dev = sta->sdata->dev;
  992. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  993. memset(skb->cb, 0, sizeof(skb->cb));
  994. netif_rx_ni(skb);
  995. }
  996. static int sta_apply_auth_flags(struct ieee80211_local *local,
  997. struct sta_info *sta,
  998. u32 mask, u32 set)
  999. {
  1000. int ret;
  1001. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  1002. set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  1003. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  1004. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  1005. if (ret)
  1006. return ret;
  1007. }
  1008. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  1009. set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  1010. !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  1011. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  1012. if (ret)
  1013. return ret;
  1014. }
  1015. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1016. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  1017. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  1018. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1019. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  1020. else
  1021. ret = 0;
  1022. if (ret)
  1023. return ret;
  1024. }
  1025. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  1026. !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  1027. test_sta_flag(sta, WLAN_STA_ASSOC)) {
  1028. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  1029. if (ret)
  1030. return ret;
  1031. }
  1032. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  1033. !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  1034. test_sta_flag(sta, WLAN_STA_AUTH)) {
  1035. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  1036. if (ret)
  1037. return ret;
  1038. }
  1039. return 0;
  1040. }
  1041. static int sta_apply_parameters(struct ieee80211_local *local,
  1042. struct sta_info *sta,
  1043. struct station_parameters *params)
  1044. {
  1045. int ret = 0;
  1046. struct ieee80211_supported_band *sband;
  1047. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1048. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  1049. u32 mask, set;
  1050. sband = local->hw.wiphy->bands[band];
  1051. mask = params->sta_flags_mask;
  1052. set = params->sta_flags_set;
  1053. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1054. /*
  1055. * In mesh mode, ASSOCIATED isn't part of the nl80211
  1056. * API but must follow AUTHENTICATED for driver state.
  1057. */
  1058. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1059. mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1060. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1061. set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1062. } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1063. /*
  1064. * TDLS -- everything follows authorized, but
  1065. * only becoming authorized is possible, not
  1066. * going back
  1067. */
  1068. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1069. set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1070. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1071. mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1072. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1073. }
  1074. }
  1075. ret = sta_apply_auth_flags(local, sta, mask, set);
  1076. if (ret)
  1077. return ret;
  1078. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  1079. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  1080. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1081. else
  1082. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1083. }
  1084. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  1085. if (set & BIT(NL80211_STA_FLAG_WME)) {
  1086. set_sta_flag(sta, WLAN_STA_WME);
  1087. sta->sta.wme = true;
  1088. } else {
  1089. clear_sta_flag(sta, WLAN_STA_WME);
  1090. sta->sta.wme = false;
  1091. }
  1092. }
  1093. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  1094. if (set & BIT(NL80211_STA_FLAG_MFP))
  1095. set_sta_flag(sta, WLAN_STA_MFP);
  1096. else
  1097. clear_sta_flag(sta, WLAN_STA_MFP);
  1098. }
  1099. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  1100. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1101. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1102. else
  1103. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1104. }
  1105. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  1106. sta->sta.uapsd_queues = params->uapsd_queues;
  1107. sta->sta.max_sp = params->max_sp;
  1108. }
  1109. /*
  1110. * cfg80211 validates this (1-2007) and allows setting the AID
  1111. * only when creating a new station entry
  1112. */
  1113. if (params->aid)
  1114. sta->sta.aid = params->aid;
  1115. /*
  1116. * Some of the following updates would be racy if called on an
  1117. * existing station, via ieee80211_change_station(). However,
  1118. * all such changes are rejected by cfg80211 except for updates
  1119. * changing the supported rates on an existing but not yet used
  1120. * TDLS peer.
  1121. */
  1122. if (params->listen_interval >= 0)
  1123. sta->listen_interval = params->listen_interval;
  1124. if (params->supported_rates) {
  1125. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1126. sband, params->supported_rates,
  1127. params->supported_rates_len,
  1128. &sta->sta.supp_rates[band]);
  1129. }
  1130. if (params->ht_capa)
  1131. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  1132. params->ht_capa, sta);
  1133. if (params->vht_capa)
  1134. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  1135. params->vht_capa, sta);
  1136. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1137. #ifdef CONFIG_MAC80211_MESH
  1138. u32 changed = 0;
  1139. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
  1140. switch (params->plink_state) {
  1141. case NL80211_PLINK_ESTAB:
  1142. if (sta->plink_state != NL80211_PLINK_ESTAB)
  1143. changed = mesh_plink_inc_estab_count(
  1144. sdata);
  1145. sta->plink_state = params->plink_state;
  1146. ieee80211_mps_sta_status_update(sta);
  1147. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1148. sdata->u.mesh.mshcfg.power_mode);
  1149. break;
  1150. case NL80211_PLINK_LISTEN:
  1151. case NL80211_PLINK_BLOCKED:
  1152. case NL80211_PLINK_OPN_SNT:
  1153. case NL80211_PLINK_OPN_RCVD:
  1154. case NL80211_PLINK_CNF_RCVD:
  1155. case NL80211_PLINK_HOLDING:
  1156. if (sta->plink_state == NL80211_PLINK_ESTAB)
  1157. changed = mesh_plink_dec_estab_count(
  1158. sdata);
  1159. sta->plink_state = params->plink_state;
  1160. ieee80211_mps_sta_status_update(sta);
  1161. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1162. NL80211_MESH_POWER_UNKNOWN);
  1163. break;
  1164. default:
  1165. /* nothing */
  1166. break;
  1167. }
  1168. }
  1169. switch (params->plink_action) {
  1170. case NL80211_PLINK_ACTION_NO_ACTION:
  1171. /* nothing */
  1172. break;
  1173. case NL80211_PLINK_ACTION_OPEN:
  1174. changed |= mesh_plink_open(sta);
  1175. break;
  1176. case NL80211_PLINK_ACTION_BLOCK:
  1177. changed |= mesh_plink_block(sta);
  1178. break;
  1179. }
  1180. if (params->local_pm)
  1181. changed |=
  1182. ieee80211_mps_set_sta_local_pm(sta,
  1183. params->local_pm);
  1184. ieee80211_mbss_info_change_notify(sdata, changed);
  1185. #endif
  1186. }
  1187. return 0;
  1188. }
  1189. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  1190. u8 *mac, struct station_parameters *params)
  1191. {
  1192. struct ieee80211_local *local = wiphy_priv(wiphy);
  1193. struct sta_info *sta;
  1194. struct ieee80211_sub_if_data *sdata;
  1195. int err;
  1196. int layer2_update;
  1197. if (params->vlan) {
  1198. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1199. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1200. sdata->vif.type != NL80211_IFTYPE_AP)
  1201. return -EINVAL;
  1202. } else
  1203. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1204. if (ether_addr_equal(mac, sdata->vif.addr))
  1205. return -EINVAL;
  1206. if (is_multicast_ether_addr(mac))
  1207. return -EINVAL;
  1208. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  1209. if (!sta)
  1210. return -ENOMEM;
  1211. /*
  1212. * defaults -- if userspace wants something else we'll
  1213. * change it accordingly in sta_apply_parameters()
  1214. */
  1215. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
  1216. sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
  1217. sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
  1218. }
  1219. err = sta_apply_parameters(local, sta, params);
  1220. if (err) {
  1221. sta_info_free(local, sta);
  1222. return err;
  1223. }
  1224. /*
  1225. * for TDLS, rate control should be initialized only when
  1226. * rates are known and station is marked authorized
  1227. */
  1228. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  1229. rate_control_rate_init(sta);
  1230. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1231. sdata->vif.type == NL80211_IFTYPE_AP;
  1232. err = sta_info_insert_rcu(sta);
  1233. if (err) {
  1234. rcu_read_unlock();
  1235. return err;
  1236. }
  1237. if (layer2_update)
  1238. ieee80211_send_layer2_update(sta);
  1239. rcu_read_unlock();
  1240. return 0;
  1241. }
  1242. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1243. u8 *mac)
  1244. {
  1245. struct ieee80211_sub_if_data *sdata;
  1246. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1247. if (mac)
  1248. return sta_info_destroy_addr_bss(sdata, mac);
  1249. sta_info_flush(sdata);
  1250. return 0;
  1251. }
  1252. static int ieee80211_change_station(struct wiphy *wiphy,
  1253. struct net_device *dev, u8 *mac,
  1254. struct station_parameters *params)
  1255. {
  1256. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1257. struct ieee80211_local *local = wiphy_priv(wiphy);
  1258. struct sta_info *sta;
  1259. struct ieee80211_sub_if_data *vlansdata;
  1260. enum cfg80211_station_type statype;
  1261. int err;
  1262. mutex_lock(&local->sta_mtx);
  1263. sta = sta_info_get_bss(sdata, mac);
  1264. if (!sta) {
  1265. err = -ENOENT;
  1266. goto out_err;
  1267. }
  1268. switch (sdata->vif.type) {
  1269. case NL80211_IFTYPE_MESH_POINT:
  1270. if (sdata->u.mesh.user_mpm)
  1271. statype = CFG80211_STA_MESH_PEER_USER;
  1272. else
  1273. statype = CFG80211_STA_MESH_PEER_KERNEL;
  1274. break;
  1275. case NL80211_IFTYPE_ADHOC:
  1276. statype = CFG80211_STA_IBSS;
  1277. break;
  1278. case NL80211_IFTYPE_STATION:
  1279. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1280. statype = CFG80211_STA_AP_STA;
  1281. break;
  1282. }
  1283. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1284. statype = CFG80211_STA_TDLS_PEER_ACTIVE;
  1285. else
  1286. statype = CFG80211_STA_TDLS_PEER_SETUP;
  1287. break;
  1288. case NL80211_IFTYPE_AP:
  1289. case NL80211_IFTYPE_AP_VLAN:
  1290. statype = CFG80211_STA_AP_CLIENT;
  1291. break;
  1292. default:
  1293. err = -EOPNOTSUPP;
  1294. goto out_err;
  1295. }
  1296. err = cfg80211_check_station_change(wiphy, params, statype);
  1297. if (err)
  1298. goto out_err;
  1299. if (params->vlan && params->vlan != sta->sdata->dev) {
  1300. bool prev_4addr = false;
  1301. bool new_4addr = false;
  1302. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1303. if (params->vlan->ieee80211_ptr->use_4addr) {
  1304. if (vlansdata->u.vlan.sta) {
  1305. err = -EBUSY;
  1306. goto out_err;
  1307. }
  1308. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1309. new_4addr = true;
  1310. }
  1311. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1312. sta->sdata->u.vlan.sta) {
  1313. rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
  1314. prev_4addr = true;
  1315. }
  1316. sta->sdata = vlansdata;
  1317. if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
  1318. prev_4addr != new_4addr) {
  1319. if (new_4addr)
  1320. atomic_dec(&sta->sdata->bss->num_mcast_sta);
  1321. else
  1322. atomic_inc(&sta->sdata->bss->num_mcast_sta);
  1323. }
  1324. ieee80211_send_layer2_update(sta);
  1325. }
  1326. err = sta_apply_parameters(local, sta, params);
  1327. if (err)
  1328. goto out_err;
  1329. /* When peer becomes authorized, init rate control as well */
  1330. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1331. test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1332. rate_control_rate_init(sta);
  1333. mutex_unlock(&local->sta_mtx);
  1334. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1335. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1336. sta->known_smps_mode != sta->sdata->bss->req_smps &&
  1337. test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
  1338. sta_info_tx_streams(sta) != 1) {
  1339. ht_dbg(sta->sdata,
  1340. "%pM just authorized and MIMO capable - update SMPS\n",
  1341. sta->sta.addr);
  1342. ieee80211_send_smps_action(sta->sdata,
  1343. sta->sdata->bss->req_smps,
  1344. sta->sta.addr,
  1345. sta->sdata->vif.bss_conf.bssid);
  1346. }
  1347. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1348. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1349. ieee80211_recalc_ps(local, -1);
  1350. ieee80211_recalc_ps_vif(sdata);
  1351. }
  1352. return 0;
  1353. out_err:
  1354. mutex_unlock(&local->sta_mtx);
  1355. return err;
  1356. }
  1357. #ifdef CONFIG_MAC80211_MESH
  1358. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1359. u8 *dst, u8 *next_hop)
  1360. {
  1361. struct ieee80211_sub_if_data *sdata;
  1362. struct mesh_path *mpath;
  1363. struct sta_info *sta;
  1364. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1365. rcu_read_lock();
  1366. sta = sta_info_get(sdata, next_hop);
  1367. if (!sta) {
  1368. rcu_read_unlock();
  1369. return -ENOENT;
  1370. }
  1371. mpath = mesh_path_add(sdata, dst);
  1372. if (IS_ERR(mpath)) {
  1373. rcu_read_unlock();
  1374. return PTR_ERR(mpath);
  1375. }
  1376. mesh_path_fix_nexthop(mpath, sta);
  1377. rcu_read_unlock();
  1378. return 0;
  1379. }
  1380. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1381. u8 *dst)
  1382. {
  1383. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1384. if (dst)
  1385. return mesh_path_del(sdata, dst);
  1386. mesh_path_flush_by_iface(sdata);
  1387. return 0;
  1388. }
  1389. static int ieee80211_change_mpath(struct wiphy *wiphy,
  1390. struct net_device *dev,
  1391. u8 *dst, u8 *next_hop)
  1392. {
  1393. struct ieee80211_sub_if_data *sdata;
  1394. struct mesh_path *mpath;
  1395. struct sta_info *sta;
  1396. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1397. rcu_read_lock();
  1398. sta = sta_info_get(sdata, next_hop);
  1399. if (!sta) {
  1400. rcu_read_unlock();
  1401. return -ENOENT;
  1402. }
  1403. mpath = mesh_path_lookup(sdata, dst);
  1404. if (!mpath) {
  1405. rcu_read_unlock();
  1406. return -ENOENT;
  1407. }
  1408. mesh_path_fix_nexthop(mpath, sta);
  1409. rcu_read_unlock();
  1410. return 0;
  1411. }
  1412. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1413. struct mpath_info *pinfo)
  1414. {
  1415. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1416. if (next_hop_sta)
  1417. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1418. else
  1419. memset(next_hop, 0, ETH_ALEN);
  1420. memset(pinfo, 0, sizeof(*pinfo));
  1421. pinfo->generation = mesh_paths_generation;
  1422. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1423. MPATH_INFO_SN |
  1424. MPATH_INFO_METRIC |
  1425. MPATH_INFO_EXPTIME |
  1426. MPATH_INFO_DISCOVERY_TIMEOUT |
  1427. MPATH_INFO_DISCOVERY_RETRIES |
  1428. MPATH_INFO_FLAGS;
  1429. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1430. pinfo->sn = mpath->sn;
  1431. pinfo->metric = mpath->metric;
  1432. if (time_before(jiffies, mpath->exp_time))
  1433. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1434. pinfo->discovery_timeout =
  1435. jiffies_to_msecs(mpath->discovery_timeout);
  1436. pinfo->discovery_retries = mpath->discovery_retries;
  1437. if (mpath->flags & MESH_PATH_ACTIVE)
  1438. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1439. if (mpath->flags & MESH_PATH_RESOLVING)
  1440. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1441. if (mpath->flags & MESH_PATH_SN_VALID)
  1442. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1443. if (mpath->flags & MESH_PATH_FIXED)
  1444. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1445. if (mpath->flags & MESH_PATH_RESOLVED)
  1446. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  1447. }
  1448. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1449. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1450. {
  1451. struct ieee80211_sub_if_data *sdata;
  1452. struct mesh_path *mpath;
  1453. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1454. rcu_read_lock();
  1455. mpath = mesh_path_lookup(sdata, dst);
  1456. if (!mpath) {
  1457. rcu_read_unlock();
  1458. return -ENOENT;
  1459. }
  1460. memcpy(dst, mpath->dst, ETH_ALEN);
  1461. mpath_set_pinfo(mpath, next_hop, pinfo);
  1462. rcu_read_unlock();
  1463. return 0;
  1464. }
  1465. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1466. int idx, u8 *dst, u8 *next_hop,
  1467. struct mpath_info *pinfo)
  1468. {
  1469. struct ieee80211_sub_if_data *sdata;
  1470. struct mesh_path *mpath;
  1471. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1472. rcu_read_lock();
  1473. mpath = mesh_path_lookup_by_idx(sdata, idx);
  1474. if (!mpath) {
  1475. rcu_read_unlock();
  1476. return -ENOENT;
  1477. }
  1478. memcpy(dst, mpath->dst, ETH_ALEN);
  1479. mpath_set_pinfo(mpath, next_hop, pinfo);
  1480. rcu_read_unlock();
  1481. return 0;
  1482. }
  1483. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  1484. struct net_device *dev,
  1485. struct mesh_config *conf)
  1486. {
  1487. struct ieee80211_sub_if_data *sdata;
  1488. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1489. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  1490. return 0;
  1491. }
  1492. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  1493. {
  1494. return (mask >> (parm-1)) & 0x1;
  1495. }
  1496. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  1497. const struct mesh_setup *setup)
  1498. {
  1499. u8 *new_ie;
  1500. const u8 *old_ie;
  1501. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  1502. struct ieee80211_sub_if_data, u.mesh);
  1503. /* allocate information elements */
  1504. new_ie = NULL;
  1505. old_ie = ifmsh->ie;
  1506. if (setup->ie_len) {
  1507. new_ie = kmemdup(setup->ie, setup->ie_len,
  1508. GFP_KERNEL);
  1509. if (!new_ie)
  1510. return -ENOMEM;
  1511. }
  1512. ifmsh->ie_len = setup->ie_len;
  1513. ifmsh->ie = new_ie;
  1514. kfree(old_ie);
  1515. /* now copy the rest of the setup parameters */
  1516. ifmsh->mesh_id_len = setup->mesh_id_len;
  1517. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  1518. ifmsh->mesh_sp_id = setup->sync_method;
  1519. ifmsh->mesh_pp_id = setup->path_sel_proto;
  1520. ifmsh->mesh_pm_id = setup->path_metric;
  1521. ifmsh->user_mpm = setup->user_mpm;
  1522. ifmsh->mesh_auth_id = setup->auth_id;
  1523. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  1524. if (setup->is_authenticated)
  1525. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  1526. if (setup->is_secure)
  1527. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  1528. /* mcast rate setting in Mesh Node */
  1529. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  1530. sizeof(setup->mcast_rate));
  1531. sdata->vif.bss_conf.basic_rates = setup->basic_rates;
  1532. sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
  1533. sdata->vif.bss_conf.dtim_period = setup->dtim_period;
  1534. return 0;
  1535. }
  1536. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  1537. struct net_device *dev, u32 mask,
  1538. const struct mesh_config *nconf)
  1539. {
  1540. struct mesh_config *conf;
  1541. struct ieee80211_sub_if_data *sdata;
  1542. struct ieee80211_if_mesh *ifmsh;
  1543. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1544. ifmsh = &sdata->u.mesh;
  1545. /* Set the config options which we are interested in setting */
  1546. conf = &(sdata->u.mesh.mshcfg);
  1547. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  1548. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  1549. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  1550. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  1551. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  1552. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  1553. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  1554. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  1555. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  1556. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  1557. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  1558. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  1559. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  1560. conf->element_ttl = nconf->element_ttl;
  1561. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
  1562. if (ifmsh->user_mpm)
  1563. return -EBUSY;
  1564. conf->auto_open_plinks = nconf->auto_open_plinks;
  1565. }
  1566. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  1567. conf->dot11MeshNbrOffsetMaxNeighbor =
  1568. nconf->dot11MeshNbrOffsetMaxNeighbor;
  1569. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  1570. conf->dot11MeshHWMPmaxPREQretries =
  1571. nconf->dot11MeshHWMPmaxPREQretries;
  1572. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1573. conf->path_refresh_time = nconf->path_refresh_time;
  1574. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1575. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1576. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1577. conf->dot11MeshHWMPactivePathTimeout =
  1578. nconf->dot11MeshHWMPactivePathTimeout;
  1579. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1580. conf->dot11MeshHWMPpreqMinInterval =
  1581. nconf->dot11MeshHWMPpreqMinInterval;
  1582. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  1583. conf->dot11MeshHWMPperrMinInterval =
  1584. nconf->dot11MeshHWMPperrMinInterval;
  1585. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1586. mask))
  1587. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1588. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1589. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1590. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1591. ieee80211_mesh_root_setup(ifmsh);
  1592. }
  1593. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1594. /* our current gate announcement implementation rides on root
  1595. * announcements, so require this ifmsh to also be a root node
  1596. * */
  1597. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1598. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  1599. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  1600. ieee80211_mesh_root_setup(ifmsh);
  1601. }
  1602. conf->dot11MeshGateAnnouncementProtocol =
  1603. nconf->dot11MeshGateAnnouncementProtocol;
  1604. }
  1605. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  1606. conf->dot11MeshHWMPRannInterval =
  1607. nconf->dot11MeshHWMPRannInterval;
  1608. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  1609. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  1610. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  1611. /* our RSSI threshold implementation is supported only for
  1612. * devices that report signal in dBm.
  1613. */
  1614. if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
  1615. return -ENOTSUPP;
  1616. conf->rssi_threshold = nconf->rssi_threshold;
  1617. }
  1618. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  1619. conf->ht_opmode = nconf->ht_opmode;
  1620. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  1621. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1622. }
  1623. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  1624. conf->dot11MeshHWMPactivePathToRootTimeout =
  1625. nconf->dot11MeshHWMPactivePathToRootTimeout;
  1626. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  1627. conf->dot11MeshHWMProotInterval =
  1628. nconf->dot11MeshHWMProotInterval;
  1629. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  1630. conf->dot11MeshHWMPconfirmationInterval =
  1631. nconf->dot11MeshHWMPconfirmationInterval;
  1632. if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
  1633. conf->power_mode = nconf->power_mode;
  1634. ieee80211_mps_local_status_update(sdata);
  1635. }
  1636. if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
  1637. conf->dot11MeshAwakeWindowDuration =
  1638. nconf->dot11MeshAwakeWindowDuration;
  1639. if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
  1640. conf->plink_timeout = nconf->plink_timeout;
  1641. ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  1642. return 0;
  1643. }
  1644. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1645. const struct mesh_config *conf,
  1646. const struct mesh_setup *setup)
  1647. {
  1648. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1649. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1650. int err;
  1651. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1652. err = copy_mesh_setup(ifmsh, setup);
  1653. if (err)
  1654. return err;
  1655. /* can mesh use other SMPS modes? */
  1656. sdata->smps_mode = IEEE80211_SMPS_OFF;
  1657. sdata->needed_rx_chains = sdata->local->rx_chains;
  1658. mutex_lock(&sdata->local->mtx);
  1659. err = ieee80211_vif_use_channel(sdata, &setup->chandef,
  1660. IEEE80211_CHANCTX_SHARED);
  1661. mutex_unlock(&sdata->local->mtx);
  1662. if (err)
  1663. return err;
  1664. return ieee80211_start_mesh(sdata);
  1665. }
  1666. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1667. {
  1668. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1669. ieee80211_stop_mesh(sdata);
  1670. mutex_lock(&sdata->local->mtx);
  1671. ieee80211_vif_release_channel(sdata);
  1672. mutex_unlock(&sdata->local->mtx);
  1673. return 0;
  1674. }
  1675. #endif
  1676. static int ieee80211_change_bss(struct wiphy *wiphy,
  1677. struct net_device *dev,
  1678. struct bss_parameters *params)
  1679. {
  1680. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1681. enum ieee80211_band band;
  1682. u32 changed = 0;
  1683. if (!sdata_dereference(sdata->u.ap.beacon, sdata))
  1684. return -ENOENT;
  1685. band = ieee80211_get_sdata_band(sdata);
  1686. if (params->use_cts_prot >= 0) {
  1687. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1688. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1689. }
  1690. if (params->use_short_preamble >= 0) {
  1691. sdata->vif.bss_conf.use_short_preamble =
  1692. params->use_short_preamble;
  1693. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1694. }
  1695. if (!sdata->vif.bss_conf.use_short_slot &&
  1696. band == IEEE80211_BAND_5GHZ) {
  1697. sdata->vif.bss_conf.use_short_slot = true;
  1698. changed |= BSS_CHANGED_ERP_SLOT;
  1699. }
  1700. if (params->use_short_slot_time >= 0) {
  1701. sdata->vif.bss_conf.use_short_slot =
  1702. params->use_short_slot_time;
  1703. changed |= BSS_CHANGED_ERP_SLOT;
  1704. }
  1705. if (params->basic_rates) {
  1706. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1707. wiphy->bands[band],
  1708. params->basic_rates,
  1709. params->basic_rates_len,
  1710. &sdata->vif.bss_conf.basic_rates);
  1711. changed |= BSS_CHANGED_BASIC_RATES;
  1712. }
  1713. if (params->ap_isolate >= 0) {
  1714. if (params->ap_isolate)
  1715. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1716. else
  1717. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1718. }
  1719. if (params->ht_opmode >= 0) {
  1720. sdata->vif.bss_conf.ht_operation_mode =
  1721. (u16) params->ht_opmode;
  1722. changed |= BSS_CHANGED_HT;
  1723. }
  1724. if (params->p2p_ctwindow >= 0) {
  1725. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1726. ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1727. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1728. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1729. changed |= BSS_CHANGED_P2P_PS;
  1730. }
  1731. if (params->p2p_opp_ps > 0) {
  1732. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1733. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1734. changed |= BSS_CHANGED_P2P_PS;
  1735. } else if (params->p2p_opp_ps == 0) {
  1736. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1737. ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1738. changed |= BSS_CHANGED_P2P_PS;
  1739. }
  1740. ieee80211_bss_info_change_notify(sdata, changed);
  1741. return 0;
  1742. }
  1743. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1744. struct net_device *dev,
  1745. struct ieee80211_txq_params *params)
  1746. {
  1747. struct ieee80211_local *local = wiphy_priv(wiphy);
  1748. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1749. struct ieee80211_tx_queue_params p;
  1750. if (!local->ops->conf_tx)
  1751. return -EOPNOTSUPP;
  1752. if (local->hw.queues < IEEE80211_NUM_ACS)
  1753. return -EOPNOTSUPP;
  1754. memset(&p, 0, sizeof(p));
  1755. p.aifs = params->aifs;
  1756. p.cw_max = params->cwmax;
  1757. p.cw_min = params->cwmin;
  1758. p.txop = params->txop;
  1759. /*
  1760. * Setting tx queue params disables u-apsd because it's only
  1761. * called in master mode.
  1762. */
  1763. p.uapsd = false;
  1764. sdata->tx_conf[params->ac] = p;
  1765. if (drv_conf_tx(local, sdata, params->ac, &p)) {
  1766. wiphy_debug(local->hw.wiphy,
  1767. "failed to set TX queue parameters for AC %d\n",
  1768. params->ac);
  1769. return -EINVAL;
  1770. }
  1771. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  1772. return 0;
  1773. }
  1774. #ifdef CONFIG_PM
  1775. static int ieee80211_suspend(struct wiphy *wiphy,
  1776. struct cfg80211_wowlan *wowlan)
  1777. {
  1778. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1779. }
  1780. static int ieee80211_resume(struct wiphy *wiphy)
  1781. {
  1782. return __ieee80211_resume(wiphy_priv(wiphy));
  1783. }
  1784. #else
  1785. #define ieee80211_suspend NULL
  1786. #define ieee80211_resume NULL
  1787. #endif
  1788. static int ieee80211_scan(struct wiphy *wiphy,
  1789. struct cfg80211_scan_request *req)
  1790. {
  1791. struct ieee80211_sub_if_data *sdata;
  1792. sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
  1793. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1794. case NL80211_IFTYPE_STATION:
  1795. case NL80211_IFTYPE_ADHOC:
  1796. case NL80211_IFTYPE_MESH_POINT:
  1797. case NL80211_IFTYPE_P2P_CLIENT:
  1798. case NL80211_IFTYPE_P2P_DEVICE:
  1799. break;
  1800. case NL80211_IFTYPE_P2P_GO:
  1801. if (sdata->local->ops->hw_scan)
  1802. break;
  1803. /*
  1804. * FIXME: implement NoA while scanning in software,
  1805. * for now fall through to allow scanning only when
  1806. * beaconing hasn't been configured yet
  1807. */
  1808. case NL80211_IFTYPE_AP:
  1809. /*
  1810. * If the scan has been forced (and the driver supports
  1811. * forcing), don't care about being beaconing already.
  1812. * This will create problems to the attached stations (e.g. all
  1813. * the frames sent while scanning on other channel will be
  1814. * lost)
  1815. */
  1816. if (sdata->u.ap.beacon &&
  1817. (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
  1818. !(req->flags & NL80211_SCAN_FLAG_AP)))
  1819. return -EOPNOTSUPP;
  1820. break;
  1821. default:
  1822. return -EOPNOTSUPP;
  1823. }
  1824. return ieee80211_request_scan(sdata, req);
  1825. }
  1826. static int
  1827. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1828. struct net_device *dev,
  1829. struct cfg80211_sched_scan_request *req)
  1830. {
  1831. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1832. if (!sdata->local->ops->sched_scan_start)
  1833. return -EOPNOTSUPP;
  1834. return ieee80211_request_sched_scan_start(sdata, req);
  1835. }
  1836. static int
  1837. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1838. {
  1839. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1840. if (!sdata->local->ops->sched_scan_stop)
  1841. return -EOPNOTSUPP;
  1842. return ieee80211_request_sched_scan_stop(sdata);
  1843. }
  1844. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1845. struct cfg80211_auth_request *req)
  1846. {
  1847. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1848. }
  1849. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1850. struct cfg80211_assoc_request *req)
  1851. {
  1852. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1853. }
  1854. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1855. struct cfg80211_deauth_request *req)
  1856. {
  1857. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1858. }
  1859. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1860. struct cfg80211_disassoc_request *req)
  1861. {
  1862. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1863. }
  1864. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1865. struct cfg80211_ibss_params *params)
  1866. {
  1867. return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
  1868. }
  1869. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1870. {
  1871. return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1872. }
  1873. static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
  1874. int rate[IEEE80211_NUM_BANDS])
  1875. {
  1876. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1877. memcpy(sdata->vif.bss_conf.mcast_rate, rate,
  1878. sizeof(int) * IEEE80211_NUM_BANDS);
  1879. return 0;
  1880. }
  1881. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1882. {
  1883. struct ieee80211_local *local = wiphy_priv(wiphy);
  1884. int err;
  1885. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1886. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1887. if (err)
  1888. return err;
  1889. }
  1890. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1891. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1892. if (err)
  1893. return err;
  1894. }
  1895. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1896. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1897. if (err)
  1898. return err;
  1899. }
  1900. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  1901. if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
  1902. return -EINVAL;
  1903. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1904. }
  1905. if (changed & WIPHY_PARAM_RETRY_LONG) {
  1906. if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
  1907. return -EINVAL;
  1908. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1909. }
  1910. if (changed &
  1911. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1912. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1913. return 0;
  1914. }
  1915. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1916. struct wireless_dev *wdev,
  1917. enum nl80211_tx_power_setting type, int mbm)
  1918. {
  1919. struct ieee80211_local *local = wiphy_priv(wiphy);
  1920. struct ieee80211_sub_if_data *sdata;
  1921. if (wdev) {
  1922. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1923. switch (type) {
  1924. case NL80211_TX_POWER_AUTOMATIC:
  1925. sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1926. break;
  1927. case NL80211_TX_POWER_LIMITED:
  1928. case NL80211_TX_POWER_FIXED:
  1929. if (mbm < 0 || (mbm % 100))
  1930. return -EOPNOTSUPP;
  1931. sdata->user_power_level = MBM_TO_DBM(mbm);
  1932. break;
  1933. }
  1934. ieee80211_recalc_txpower(sdata);
  1935. return 0;
  1936. }
  1937. switch (type) {
  1938. case NL80211_TX_POWER_AUTOMATIC:
  1939. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1940. break;
  1941. case NL80211_TX_POWER_LIMITED:
  1942. case NL80211_TX_POWER_FIXED:
  1943. if (mbm < 0 || (mbm % 100))
  1944. return -EOPNOTSUPP;
  1945. local->user_power_level = MBM_TO_DBM(mbm);
  1946. break;
  1947. }
  1948. mutex_lock(&local->iflist_mtx);
  1949. list_for_each_entry(sdata, &local->interfaces, list)
  1950. sdata->user_power_level = local->user_power_level;
  1951. list_for_each_entry(sdata, &local->interfaces, list)
  1952. ieee80211_recalc_txpower(sdata);
  1953. mutex_unlock(&local->iflist_mtx);
  1954. return 0;
  1955. }
  1956. static int ieee80211_get_tx_power(struct wiphy *wiphy,
  1957. struct wireless_dev *wdev,
  1958. int *dbm)
  1959. {
  1960. struct ieee80211_local *local = wiphy_priv(wiphy);
  1961. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1962. if (!local->use_chanctx)
  1963. *dbm = local->hw.conf.power_level;
  1964. else
  1965. *dbm = sdata->vif.bss_conf.txpower;
  1966. return 0;
  1967. }
  1968. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1969. const u8 *addr)
  1970. {
  1971. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1972. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1973. return 0;
  1974. }
  1975. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1976. {
  1977. struct ieee80211_local *local = wiphy_priv(wiphy);
  1978. drv_rfkill_poll(local);
  1979. }
  1980. #ifdef CONFIG_NL80211_TESTMODE
  1981. static int ieee80211_testmode_cmd(struct wiphy *wiphy,
  1982. struct wireless_dev *wdev,
  1983. void *data, int len)
  1984. {
  1985. struct ieee80211_local *local = wiphy_priv(wiphy);
  1986. struct ieee80211_vif *vif = NULL;
  1987. if (!local->ops->testmode_cmd)
  1988. return -EOPNOTSUPP;
  1989. if (wdev) {
  1990. struct ieee80211_sub_if_data *sdata;
  1991. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1992. if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
  1993. vif = &sdata->vif;
  1994. }
  1995. return local->ops->testmode_cmd(&local->hw, vif, data, len);
  1996. }
  1997. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1998. struct sk_buff *skb,
  1999. struct netlink_callback *cb,
  2000. void *data, int len)
  2001. {
  2002. struct ieee80211_local *local = wiphy_priv(wiphy);
  2003. if (!local->ops->testmode_dump)
  2004. return -EOPNOTSUPP;
  2005. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  2006. }
  2007. #endif
  2008. int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
  2009. enum ieee80211_smps_mode smps_mode)
  2010. {
  2011. struct sta_info *sta;
  2012. enum ieee80211_smps_mode old_req;
  2013. int i;
  2014. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
  2015. return -EINVAL;
  2016. if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2017. return 0;
  2018. old_req = sdata->u.ap.req_smps;
  2019. sdata->u.ap.req_smps = smps_mode;
  2020. /* AUTOMATIC doesn't mean much for AP - don't allow it */
  2021. if (old_req == smps_mode ||
  2022. smps_mode == IEEE80211_SMPS_AUTOMATIC)
  2023. return 0;
  2024. /* If no associated stations, there's no need to do anything */
  2025. if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
  2026. sdata->smps_mode = smps_mode;
  2027. ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
  2028. return 0;
  2029. }
  2030. ht_dbg(sdata,
  2031. "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
  2032. smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
  2033. mutex_lock(&sdata->local->sta_mtx);
  2034. for (i = 0; i < STA_HASH_SIZE; i++) {
  2035. for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
  2036. lockdep_is_held(&sdata->local->sta_mtx));
  2037. sta;
  2038. sta = rcu_dereference_protected(sta->hnext,
  2039. lockdep_is_held(&sdata->local->sta_mtx))) {
  2040. /*
  2041. * Only stations associated to our AP and
  2042. * associated VLANs
  2043. */
  2044. if (sta->sdata->bss != &sdata->u.ap)
  2045. continue;
  2046. /* This station doesn't support MIMO - skip it */
  2047. if (sta_info_tx_streams(sta) == 1)
  2048. continue;
  2049. /*
  2050. * Don't wake up a STA just to send the action frame
  2051. * unless we are getting more restrictive.
  2052. */
  2053. if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
  2054. !ieee80211_smps_is_restrictive(sta->known_smps_mode,
  2055. smps_mode)) {
  2056. ht_dbg(sdata,
  2057. "Won't send SMPS to sleeping STA %pM\n",
  2058. sta->sta.addr);
  2059. continue;
  2060. }
  2061. /*
  2062. * If the STA is not authorized, wait until it gets
  2063. * authorized and the action frame will be sent then.
  2064. */
  2065. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2066. continue;
  2067. ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
  2068. ieee80211_send_smps_action(sdata, smps_mode,
  2069. sta->sta.addr,
  2070. sdata->vif.bss_conf.bssid);
  2071. }
  2072. }
  2073. mutex_unlock(&sdata->local->sta_mtx);
  2074. sdata->smps_mode = smps_mode;
  2075. ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
  2076. return 0;
  2077. }
  2078. int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
  2079. enum ieee80211_smps_mode smps_mode)
  2080. {
  2081. const u8 *ap;
  2082. enum ieee80211_smps_mode old_req;
  2083. int err;
  2084. lockdep_assert_held(&sdata->wdev.mtx);
  2085. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
  2086. return -EINVAL;
  2087. old_req = sdata->u.mgd.req_smps;
  2088. sdata->u.mgd.req_smps = smps_mode;
  2089. if (old_req == smps_mode &&
  2090. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  2091. return 0;
  2092. /*
  2093. * If not associated, or current association is not an HT
  2094. * association, there's no need to do anything, just store
  2095. * the new value until we associate.
  2096. */
  2097. if (!sdata->u.mgd.associated ||
  2098. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2099. return 0;
  2100. ap = sdata->u.mgd.associated->bssid;
  2101. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  2102. if (sdata->u.mgd.powersave)
  2103. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2104. else
  2105. smps_mode = IEEE80211_SMPS_OFF;
  2106. }
  2107. /* send SM PS frame to AP */
  2108. err = ieee80211_send_smps_action(sdata, smps_mode,
  2109. ap, ap);
  2110. if (err)
  2111. sdata->u.mgd.req_smps = old_req;
  2112. return err;
  2113. }
  2114. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2115. bool enabled, int timeout)
  2116. {
  2117. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2118. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2119. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2120. return -EOPNOTSUPP;
  2121. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  2122. return -EOPNOTSUPP;
  2123. if (enabled == sdata->u.mgd.powersave &&
  2124. timeout == local->dynamic_ps_forced_timeout)
  2125. return 0;
  2126. sdata->u.mgd.powersave = enabled;
  2127. local->dynamic_ps_forced_timeout = timeout;
  2128. /* no change, but if automatic follow powersave */
  2129. sdata_lock(sdata);
  2130. __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
  2131. sdata_unlock(sdata);
  2132. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  2133. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2134. ieee80211_recalc_ps(local, -1);
  2135. ieee80211_recalc_ps_vif(sdata);
  2136. return 0;
  2137. }
  2138. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  2139. struct net_device *dev,
  2140. s32 rssi_thold, u32 rssi_hyst)
  2141. {
  2142. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2143. struct ieee80211_vif *vif = &sdata->vif;
  2144. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  2145. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  2146. rssi_hyst == bss_conf->cqm_rssi_hyst)
  2147. return 0;
  2148. bss_conf->cqm_rssi_thold = rssi_thold;
  2149. bss_conf->cqm_rssi_hyst = rssi_hyst;
  2150. /* tell the driver upon association, unless already associated */
  2151. if (sdata->u.mgd.associated &&
  2152. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  2153. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  2154. return 0;
  2155. }
  2156. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  2157. struct net_device *dev,
  2158. const u8 *addr,
  2159. const struct cfg80211_bitrate_mask *mask)
  2160. {
  2161. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2162. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2163. int i, ret;
  2164. if (!ieee80211_sdata_running(sdata))
  2165. return -ENETDOWN;
  2166. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  2167. ret = drv_set_bitrate_mask(local, sdata, mask);
  2168. if (ret)
  2169. return ret;
  2170. }
  2171. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  2172. struct ieee80211_supported_band *sband = wiphy->bands[i];
  2173. int j;
  2174. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  2175. memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
  2176. sizeof(mask->control[i].ht_mcs));
  2177. sdata->rc_has_mcs_mask[i] = false;
  2178. if (!sband)
  2179. continue;
  2180. for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
  2181. if (~sdata->rc_rateidx_mcs_mask[i][j]) {
  2182. sdata->rc_has_mcs_mask[i] = true;
  2183. break;
  2184. }
  2185. }
  2186. return 0;
  2187. }
  2188. static int ieee80211_start_roc_work(struct ieee80211_local *local,
  2189. struct ieee80211_sub_if_data *sdata,
  2190. struct ieee80211_channel *channel,
  2191. unsigned int duration, u64 *cookie,
  2192. struct sk_buff *txskb,
  2193. enum ieee80211_roc_type type)
  2194. {
  2195. struct ieee80211_roc_work *roc, *tmp;
  2196. bool queued = false;
  2197. int ret;
  2198. lockdep_assert_held(&local->mtx);
  2199. if (local->use_chanctx && !local->ops->remain_on_channel)
  2200. return -EOPNOTSUPP;
  2201. roc = kzalloc(sizeof(*roc), GFP_KERNEL);
  2202. if (!roc)
  2203. return -ENOMEM;
  2204. roc->chan = channel;
  2205. roc->duration = duration;
  2206. roc->req_duration = duration;
  2207. roc->frame = txskb;
  2208. roc->type = type;
  2209. roc->mgmt_tx_cookie = (unsigned long)txskb;
  2210. roc->sdata = sdata;
  2211. INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
  2212. INIT_LIST_HEAD(&roc->dependents);
  2213. /*
  2214. * cookie is either the roc cookie (for normal roc)
  2215. * or the SKB (for mgmt TX)
  2216. */
  2217. if (!txskb) {
  2218. /* local->mtx protects this */
  2219. local->roc_cookie_counter++;
  2220. roc->cookie = local->roc_cookie_counter;
  2221. /* wow, you wrapped 64 bits ... more likely a bug */
  2222. if (WARN_ON(roc->cookie == 0)) {
  2223. roc->cookie = 1;
  2224. local->roc_cookie_counter++;
  2225. }
  2226. *cookie = roc->cookie;
  2227. } else {
  2228. *cookie = (unsigned long)txskb;
  2229. }
  2230. /* if there's one pending or we're scanning, queue this one */
  2231. if (!list_empty(&local->roc_list) ||
  2232. local->scanning || local->radar_detect_enabled)
  2233. goto out_check_combine;
  2234. /* if not HW assist, just queue & schedule work */
  2235. if (!local->ops->remain_on_channel) {
  2236. ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
  2237. goto out_queue;
  2238. }
  2239. /* otherwise actually kick it off here (for error handling) */
  2240. /*
  2241. * If the duration is zero, then the driver
  2242. * wouldn't actually do anything. Set it to
  2243. * 10 for now.
  2244. *
  2245. * TODO: cancel the off-channel operation
  2246. * when we get the SKB's TX status and
  2247. * the wait time was zero before.
  2248. */
  2249. if (!duration)
  2250. duration = 10;
  2251. ret = drv_remain_on_channel(local, sdata, channel, duration, type);
  2252. if (ret) {
  2253. kfree(roc);
  2254. return ret;
  2255. }
  2256. roc->started = true;
  2257. goto out_queue;
  2258. out_check_combine:
  2259. list_for_each_entry(tmp, &local->roc_list, list) {
  2260. if (tmp->chan != channel || tmp->sdata != sdata)
  2261. continue;
  2262. /*
  2263. * Extend this ROC if possible:
  2264. *
  2265. * If it hasn't started yet, just increase the duration
  2266. * and add the new one to the list of dependents.
  2267. * If the type of the new ROC has higher priority, modify the
  2268. * type of the previous one to match that of the new one.
  2269. */
  2270. if (!tmp->started) {
  2271. list_add_tail(&roc->list, &tmp->dependents);
  2272. tmp->duration = max(tmp->duration, roc->duration);
  2273. tmp->type = max(tmp->type, roc->type);
  2274. queued = true;
  2275. break;
  2276. }
  2277. /* If it has already started, it's more difficult ... */
  2278. if (local->ops->remain_on_channel) {
  2279. unsigned long j = jiffies;
  2280. /*
  2281. * In the offloaded ROC case, if it hasn't begun, add
  2282. * this new one to the dependent list to be handled
  2283. * when the master one begins. If it has begun,
  2284. * check that there's still a minimum time left and
  2285. * if so, start this one, transmitting the frame, but
  2286. * add it to the list directly after this one with
  2287. * a reduced time so we'll ask the driver to execute
  2288. * it right after finishing the previous one, in the
  2289. * hope that it'll also be executed right afterwards,
  2290. * effectively extending the old one.
  2291. * If there's no minimum time left, just add it to the
  2292. * normal list.
  2293. * TODO: the ROC type is ignored here, assuming that it
  2294. * is better to immediately use the current ROC.
  2295. */
  2296. if (!tmp->hw_begun) {
  2297. list_add_tail(&roc->list, &tmp->dependents);
  2298. queued = true;
  2299. break;
  2300. }
  2301. if (time_before(j + IEEE80211_ROC_MIN_LEFT,
  2302. tmp->hw_start_time +
  2303. msecs_to_jiffies(tmp->duration))) {
  2304. int new_dur;
  2305. ieee80211_handle_roc_started(roc);
  2306. new_dur = roc->duration -
  2307. jiffies_to_msecs(tmp->hw_start_time +
  2308. msecs_to_jiffies(
  2309. tmp->duration) -
  2310. j);
  2311. if (new_dur > 0) {
  2312. /* add right after tmp */
  2313. list_add(&roc->list, &tmp->list);
  2314. } else {
  2315. list_add_tail(&roc->list,
  2316. &tmp->dependents);
  2317. }
  2318. queued = true;
  2319. }
  2320. } else if (del_timer_sync(&tmp->work.timer)) {
  2321. unsigned long new_end;
  2322. /*
  2323. * In the software ROC case, cancel the timer, if
  2324. * that fails then the finish work is already
  2325. * queued/pending and thus we queue the new ROC
  2326. * normally, if that succeeds then we can extend
  2327. * the timer duration and TX the frame (if any.)
  2328. */
  2329. list_add_tail(&roc->list, &tmp->dependents);
  2330. queued = true;
  2331. new_end = jiffies + msecs_to_jiffies(roc->duration);
  2332. /* ok, it was started & we canceled timer */
  2333. if (time_after(new_end, tmp->work.timer.expires))
  2334. mod_timer(&tmp->work.timer, new_end);
  2335. else
  2336. add_timer(&tmp->work.timer);
  2337. ieee80211_handle_roc_started(roc);
  2338. }
  2339. break;
  2340. }
  2341. out_queue:
  2342. if (!queued)
  2343. list_add_tail(&roc->list, &local->roc_list);
  2344. return 0;
  2345. }
  2346. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  2347. struct wireless_dev *wdev,
  2348. struct ieee80211_channel *chan,
  2349. unsigned int duration,
  2350. u64 *cookie)
  2351. {
  2352. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2353. struct ieee80211_local *local = sdata->local;
  2354. int ret;
  2355. mutex_lock(&local->mtx);
  2356. ret = ieee80211_start_roc_work(local, sdata, chan,
  2357. duration, cookie, NULL,
  2358. IEEE80211_ROC_TYPE_NORMAL);
  2359. mutex_unlock(&local->mtx);
  2360. return ret;
  2361. }
  2362. static int ieee80211_cancel_roc(struct ieee80211_local *local,
  2363. u64 cookie, bool mgmt_tx)
  2364. {
  2365. struct ieee80211_roc_work *roc, *tmp, *found = NULL;
  2366. int ret;
  2367. mutex_lock(&local->mtx);
  2368. list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
  2369. struct ieee80211_roc_work *dep, *tmp2;
  2370. list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
  2371. if (!mgmt_tx && dep->cookie != cookie)
  2372. continue;
  2373. else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
  2374. continue;
  2375. /* found dependent item -- just remove it */
  2376. list_del(&dep->list);
  2377. mutex_unlock(&local->mtx);
  2378. ieee80211_roc_notify_destroy(dep, true);
  2379. return 0;
  2380. }
  2381. if (!mgmt_tx && roc->cookie != cookie)
  2382. continue;
  2383. else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
  2384. continue;
  2385. found = roc;
  2386. break;
  2387. }
  2388. if (!found) {
  2389. mutex_unlock(&local->mtx);
  2390. return -ENOENT;
  2391. }
  2392. /*
  2393. * We found the item to cancel, so do that. Note that it
  2394. * may have dependents, which we also cancel (and send
  2395. * the expired signal for.) Not doing so would be quite
  2396. * tricky here, but we may need to fix it later.
  2397. */
  2398. if (local->ops->remain_on_channel) {
  2399. if (found->started) {
  2400. ret = drv_cancel_remain_on_channel(local);
  2401. if (WARN_ON_ONCE(ret)) {
  2402. mutex_unlock(&local->mtx);
  2403. return ret;
  2404. }
  2405. }
  2406. list_del(&found->list);
  2407. if (found->started)
  2408. ieee80211_start_next_roc(local);
  2409. mutex_unlock(&local->mtx);
  2410. ieee80211_roc_notify_destroy(found, true);
  2411. } else {
  2412. /* work may be pending so use it all the time */
  2413. found->abort = true;
  2414. ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
  2415. mutex_unlock(&local->mtx);
  2416. /* work will clean up etc */
  2417. flush_delayed_work(&found->work);
  2418. WARN_ON(!found->to_be_freed);
  2419. kfree(found);
  2420. }
  2421. return 0;
  2422. }
  2423. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  2424. struct wireless_dev *wdev,
  2425. u64 cookie)
  2426. {
  2427. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2428. struct ieee80211_local *local = sdata->local;
  2429. return ieee80211_cancel_roc(local, cookie, false);
  2430. }
  2431. static int ieee80211_start_radar_detection(struct wiphy *wiphy,
  2432. struct net_device *dev,
  2433. struct cfg80211_chan_def *chandef)
  2434. {
  2435. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2436. struct ieee80211_local *local = sdata->local;
  2437. unsigned long timeout;
  2438. int err;
  2439. mutex_lock(&local->mtx);
  2440. if (!list_empty(&local->roc_list) || local->scanning) {
  2441. err = -EBUSY;
  2442. goto out_unlock;
  2443. }
  2444. /* whatever, but channel contexts should not complain about that one */
  2445. sdata->smps_mode = IEEE80211_SMPS_OFF;
  2446. sdata->needed_rx_chains = local->rx_chains;
  2447. sdata->radar_required = true;
  2448. err = ieee80211_vif_use_channel(sdata, chandef,
  2449. IEEE80211_CHANCTX_SHARED);
  2450. if (err)
  2451. goto out_unlock;
  2452. timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
  2453. ieee80211_queue_delayed_work(&sdata->local->hw,
  2454. &sdata->dfs_cac_timer_work, timeout);
  2455. out_unlock:
  2456. mutex_unlock(&local->mtx);
  2457. return err;
  2458. }
  2459. static struct cfg80211_beacon_data *
  2460. cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
  2461. {
  2462. struct cfg80211_beacon_data *new_beacon;
  2463. u8 *pos;
  2464. int len;
  2465. len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
  2466. beacon->proberesp_ies_len + beacon->assocresp_ies_len +
  2467. beacon->probe_resp_len;
  2468. new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
  2469. if (!new_beacon)
  2470. return NULL;
  2471. pos = (u8 *)(new_beacon + 1);
  2472. if (beacon->head_len) {
  2473. new_beacon->head_len = beacon->head_len;
  2474. new_beacon->head = pos;
  2475. memcpy(pos, beacon->head, beacon->head_len);
  2476. pos += beacon->head_len;
  2477. }
  2478. if (beacon->tail_len) {
  2479. new_beacon->tail_len = beacon->tail_len;
  2480. new_beacon->tail = pos;
  2481. memcpy(pos, beacon->tail, beacon->tail_len);
  2482. pos += beacon->tail_len;
  2483. }
  2484. if (beacon->beacon_ies_len) {
  2485. new_beacon->beacon_ies_len = beacon->beacon_ies_len;
  2486. new_beacon->beacon_ies = pos;
  2487. memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
  2488. pos += beacon->beacon_ies_len;
  2489. }
  2490. if (beacon->proberesp_ies_len) {
  2491. new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
  2492. new_beacon->proberesp_ies = pos;
  2493. memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
  2494. pos += beacon->proberesp_ies_len;
  2495. }
  2496. if (beacon->assocresp_ies_len) {
  2497. new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
  2498. new_beacon->assocresp_ies = pos;
  2499. memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
  2500. pos += beacon->assocresp_ies_len;
  2501. }
  2502. if (beacon->probe_resp_len) {
  2503. new_beacon->probe_resp_len = beacon->probe_resp_len;
  2504. beacon->probe_resp = pos;
  2505. memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
  2506. pos += beacon->probe_resp_len;
  2507. }
  2508. return new_beacon;
  2509. }
  2510. void ieee80211_csa_finalize_work(struct work_struct *work)
  2511. {
  2512. struct ieee80211_sub_if_data *sdata =
  2513. container_of(work, struct ieee80211_sub_if_data,
  2514. csa_finalize_work);
  2515. struct ieee80211_local *local = sdata->local;
  2516. int err, changed = 0;
  2517. sdata_lock(sdata);
  2518. /* AP might have been stopped while waiting for the lock. */
  2519. if (!sdata->vif.csa_active)
  2520. goto unlock;
  2521. if (!ieee80211_sdata_running(sdata))
  2522. goto unlock;
  2523. sdata->radar_required = sdata->csa_radar_required;
  2524. mutex_lock(&local->mtx);
  2525. err = ieee80211_vif_change_channel(sdata, &changed);
  2526. mutex_unlock(&local->mtx);
  2527. if (WARN_ON(err < 0))
  2528. goto unlock;
  2529. if (!local->use_chanctx) {
  2530. local->_oper_chandef = sdata->csa_chandef;
  2531. ieee80211_hw_config(local, 0);
  2532. }
  2533. ieee80211_bss_info_change_notify(sdata, changed);
  2534. sdata->vif.csa_active = false;
  2535. switch (sdata->vif.type) {
  2536. case NL80211_IFTYPE_AP:
  2537. err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
  2538. if (err < 0)
  2539. goto unlock;
  2540. changed |= err;
  2541. kfree(sdata->u.ap.next_beacon);
  2542. sdata->u.ap.next_beacon = NULL;
  2543. ieee80211_bss_info_change_notify(sdata, err);
  2544. break;
  2545. case NL80211_IFTYPE_ADHOC:
  2546. ieee80211_ibss_finish_csa(sdata);
  2547. break;
  2548. #ifdef CONFIG_MAC80211_MESH
  2549. case NL80211_IFTYPE_MESH_POINT:
  2550. err = ieee80211_mesh_finish_csa(sdata);
  2551. if (err < 0)
  2552. goto unlock;
  2553. break;
  2554. #endif
  2555. default:
  2556. WARN_ON(1);
  2557. goto unlock;
  2558. }
  2559. ieee80211_wake_queues_by_reason(&sdata->local->hw,
  2560. IEEE80211_MAX_QUEUE_MAP,
  2561. IEEE80211_QUEUE_STOP_REASON_CSA);
  2562. cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
  2563. unlock:
  2564. sdata_unlock(sdata);
  2565. }
  2566. int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  2567. struct cfg80211_csa_settings *params)
  2568. {
  2569. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2570. struct ieee80211_local *local = sdata->local;
  2571. struct ieee80211_chanctx_conf *chanctx_conf;
  2572. struct ieee80211_chanctx *chanctx;
  2573. struct ieee80211_if_mesh __maybe_unused *ifmsh;
  2574. int err, num_chanctx;
  2575. lockdep_assert_held(&sdata->wdev.mtx);
  2576. if (!list_empty(&local->roc_list) || local->scanning)
  2577. return -EBUSY;
  2578. if (sdata->wdev.cac_started)
  2579. return -EBUSY;
  2580. if (cfg80211_chandef_identical(&params->chandef,
  2581. &sdata->vif.bss_conf.chandef))
  2582. return -EINVAL;
  2583. rcu_read_lock();
  2584. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2585. if (!chanctx_conf) {
  2586. rcu_read_unlock();
  2587. return -EBUSY;
  2588. }
  2589. /* don't handle for multi-VIF cases */
  2590. chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
  2591. if (chanctx->refcount > 1) {
  2592. rcu_read_unlock();
  2593. return -EBUSY;
  2594. }
  2595. num_chanctx = 0;
  2596. list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
  2597. num_chanctx++;
  2598. rcu_read_unlock();
  2599. if (num_chanctx > 1)
  2600. return -EBUSY;
  2601. /* don't allow another channel switch if one is already active. */
  2602. if (sdata->vif.csa_active)
  2603. return -EBUSY;
  2604. switch (sdata->vif.type) {
  2605. case NL80211_IFTYPE_AP:
  2606. sdata->csa_counter_offset_beacon =
  2607. params->counter_offset_beacon;
  2608. sdata->csa_counter_offset_presp = params->counter_offset_presp;
  2609. sdata->u.ap.next_beacon =
  2610. cfg80211_beacon_dup(&params->beacon_after);
  2611. if (!sdata->u.ap.next_beacon)
  2612. return -ENOMEM;
  2613. err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
  2614. if (err < 0) {
  2615. kfree(sdata->u.ap.next_beacon);
  2616. return err;
  2617. }
  2618. break;
  2619. case NL80211_IFTYPE_ADHOC:
  2620. if (!sdata->vif.bss_conf.ibss_joined)
  2621. return -EINVAL;
  2622. if (params->chandef.width != sdata->u.ibss.chandef.width)
  2623. return -EINVAL;
  2624. switch (params->chandef.width) {
  2625. case NL80211_CHAN_WIDTH_40:
  2626. if (cfg80211_get_chandef_type(&params->chandef) !=
  2627. cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
  2628. return -EINVAL;
  2629. case NL80211_CHAN_WIDTH_5:
  2630. case NL80211_CHAN_WIDTH_10:
  2631. case NL80211_CHAN_WIDTH_20_NOHT:
  2632. case NL80211_CHAN_WIDTH_20:
  2633. break;
  2634. default:
  2635. return -EINVAL;
  2636. }
  2637. /* changes into another band are not supported */
  2638. if (sdata->u.ibss.chandef.chan->band !=
  2639. params->chandef.chan->band)
  2640. return -EINVAL;
  2641. err = ieee80211_ibss_csa_beacon(sdata, params);
  2642. if (err < 0)
  2643. return err;
  2644. break;
  2645. #ifdef CONFIG_MAC80211_MESH
  2646. case NL80211_IFTYPE_MESH_POINT:
  2647. ifmsh = &sdata->u.mesh;
  2648. if (!ifmsh->mesh_id)
  2649. return -EINVAL;
  2650. if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
  2651. return -EINVAL;
  2652. /* changes into another band are not supported */
  2653. if (sdata->vif.bss_conf.chandef.chan->band !=
  2654. params->chandef.chan->band)
  2655. return -EINVAL;
  2656. ifmsh->chsw_init = true;
  2657. if (!ifmsh->pre_value)
  2658. ifmsh->pre_value = 1;
  2659. else
  2660. ifmsh->pre_value++;
  2661. err = ieee80211_mesh_csa_beacon(sdata, params, true);
  2662. if (err < 0) {
  2663. ifmsh->chsw_init = false;
  2664. return err;
  2665. }
  2666. break;
  2667. #endif
  2668. default:
  2669. return -EOPNOTSUPP;
  2670. }
  2671. sdata->csa_radar_required = params->radar_required;
  2672. if (params->block_tx)
  2673. ieee80211_stop_queues_by_reason(&local->hw,
  2674. IEEE80211_MAX_QUEUE_MAP,
  2675. IEEE80211_QUEUE_STOP_REASON_CSA);
  2676. sdata->csa_chandef = params->chandef;
  2677. sdata->vif.csa_active = true;
  2678. ieee80211_bss_info_change_notify(sdata, err);
  2679. drv_channel_switch_beacon(sdata, &params->chandef);
  2680. return 0;
  2681. }
  2682. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  2683. struct cfg80211_mgmt_tx_params *params,
  2684. u64 *cookie)
  2685. {
  2686. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2687. struct ieee80211_local *local = sdata->local;
  2688. struct sk_buff *skb;
  2689. struct sta_info *sta;
  2690. const struct ieee80211_mgmt *mgmt = (void *)params->buf;
  2691. bool need_offchan = false;
  2692. u32 flags;
  2693. int ret;
  2694. if (params->dont_wait_for_ack)
  2695. flags = IEEE80211_TX_CTL_NO_ACK;
  2696. else
  2697. flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  2698. IEEE80211_TX_CTL_REQ_TX_STATUS;
  2699. if (params->no_cck)
  2700. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  2701. switch (sdata->vif.type) {
  2702. case NL80211_IFTYPE_ADHOC:
  2703. if (!sdata->vif.bss_conf.ibss_joined)
  2704. need_offchan = true;
  2705. /* fall through */
  2706. #ifdef CONFIG_MAC80211_MESH
  2707. case NL80211_IFTYPE_MESH_POINT:
  2708. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  2709. !sdata->u.mesh.mesh_id_len)
  2710. need_offchan = true;
  2711. /* fall through */
  2712. #endif
  2713. case NL80211_IFTYPE_AP:
  2714. case NL80211_IFTYPE_AP_VLAN:
  2715. case NL80211_IFTYPE_P2P_GO:
  2716. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2717. !ieee80211_vif_is_mesh(&sdata->vif) &&
  2718. !rcu_access_pointer(sdata->bss->beacon))
  2719. need_offchan = true;
  2720. if (!ieee80211_is_action(mgmt->frame_control) ||
  2721. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
  2722. mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
  2723. mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
  2724. break;
  2725. rcu_read_lock();
  2726. sta = sta_info_get(sdata, mgmt->da);
  2727. rcu_read_unlock();
  2728. if (!sta)
  2729. return -ENOLINK;
  2730. break;
  2731. case NL80211_IFTYPE_STATION:
  2732. case NL80211_IFTYPE_P2P_CLIENT:
  2733. if (!sdata->u.mgd.associated)
  2734. need_offchan = true;
  2735. break;
  2736. case NL80211_IFTYPE_P2P_DEVICE:
  2737. need_offchan = true;
  2738. break;
  2739. default:
  2740. return -EOPNOTSUPP;
  2741. }
  2742. /* configurations requiring offchan cannot work if no channel has been
  2743. * specified
  2744. */
  2745. if (need_offchan && !params->chan)
  2746. return -EINVAL;
  2747. mutex_lock(&local->mtx);
  2748. /* Check if the operating channel is the requested channel */
  2749. if (!need_offchan) {
  2750. struct ieee80211_chanctx_conf *chanctx_conf;
  2751. rcu_read_lock();
  2752. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2753. if (chanctx_conf) {
  2754. need_offchan = params->chan &&
  2755. (params->chan !=
  2756. chanctx_conf->def.chan);
  2757. } else if (!params->chan) {
  2758. ret = -EINVAL;
  2759. rcu_read_unlock();
  2760. goto out_unlock;
  2761. } else {
  2762. need_offchan = true;
  2763. }
  2764. rcu_read_unlock();
  2765. }
  2766. if (need_offchan && !params->offchan) {
  2767. ret = -EBUSY;
  2768. goto out_unlock;
  2769. }
  2770. skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
  2771. if (!skb) {
  2772. ret = -ENOMEM;
  2773. goto out_unlock;
  2774. }
  2775. skb_reserve(skb, local->hw.extra_tx_headroom);
  2776. memcpy(skb_put(skb, params->len), params->buf, params->len);
  2777. IEEE80211_SKB_CB(skb)->flags = flags;
  2778. skb->dev = sdata->dev;
  2779. if (!need_offchan) {
  2780. *cookie = (unsigned long) skb;
  2781. ieee80211_tx_skb(sdata, skb);
  2782. ret = 0;
  2783. goto out_unlock;
  2784. }
  2785. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
  2786. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  2787. if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
  2788. IEEE80211_SKB_CB(skb)->hw_queue =
  2789. local->hw.offchannel_tx_hw_queue;
  2790. /* This will handle all kinds of coalescing and immediate TX */
  2791. ret = ieee80211_start_roc_work(local, sdata, params->chan,
  2792. params->wait, cookie, skb,
  2793. IEEE80211_ROC_TYPE_MGMT_TX);
  2794. if (ret)
  2795. kfree_skb(skb);
  2796. out_unlock:
  2797. mutex_unlock(&local->mtx);
  2798. return ret;
  2799. }
  2800. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  2801. struct wireless_dev *wdev,
  2802. u64 cookie)
  2803. {
  2804. struct ieee80211_local *local = wiphy_priv(wiphy);
  2805. return ieee80211_cancel_roc(local, cookie, true);
  2806. }
  2807. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  2808. struct wireless_dev *wdev,
  2809. u16 frame_type, bool reg)
  2810. {
  2811. struct ieee80211_local *local = wiphy_priv(wiphy);
  2812. switch (frame_type) {
  2813. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
  2814. if (reg)
  2815. local->probe_req_reg++;
  2816. else
  2817. local->probe_req_reg--;
  2818. if (!local->open_count)
  2819. break;
  2820. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  2821. break;
  2822. default:
  2823. break;
  2824. }
  2825. }
  2826. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  2827. {
  2828. struct ieee80211_local *local = wiphy_priv(wiphy);
  2829. if (local->started)
  2830. return -EOPNOTSUPP;
  2831. return drv_set_antenna(local, tx_ant, rx_ant);
  2832. }
  2833. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  2834. {
  2835. struct ieee80211_local *local = wiphy_priv(wiphy);
  2836. return drv_get_antenna(local, tx_ant, rx_ant);
  2837. }
  2838. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  2839. {
  2840. struct ieee80211_local *local = wiphy_priv(wiphy);
  2841. return drv_set_ringparam(local, tx, rx);
  2842. }
  2843. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  2844. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  2845. {
  2846. struct ieee80211_local *local = wiphy_priv(wiphy);
  2847. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  2848. }
  2849. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  2850. struct net_device *dev,
  2851. struct cfg80211_gtk_rekey_data *data)
  2852. {
  2853. struct ieee80211_local *local = wiphy_priv(wiphy);
  2854. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2855. if (!local->ops->set_rekey_data)
  2856. return -EOPNOTSUPP;
  2857. drv_set_rekey_data(local, sdata, data);
  2858. return 0;
  2859. }
  2860. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  2861. {
  2862. u8 *pos = (void *)skb_put(skb, 7);
  2863. *pos++ = WLAN_EID_EXT_CAPABILITY;
  2864. *pos++ = 5; /* len */
  2865. *pos++ = 0x0;
  2866. *pos++ = 0x0;
  2867. *pos++ = 0x0;
  2868. *pos++ = 0x0;
  2869. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  2870. }
  2871. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  2872. {
  2873. struct ieee80211_local *local = sdata->local;
  2874. u16 capab;
  2875. capab = 0;
  2876. if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
  2877. return capab;
  2878. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  2879. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  2880. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  2881. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  2882. return capab;
  2883. }
  2884. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  2885. u8 *peer, u8 *bssid)
  2886. {
  2887. struct ieee80211_tdls_lnkie *lnkid;
  2888. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  2889. lnkid->ie_type = WLAN_EID_LINK_ID;
  2890. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  2891. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  2892. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  2893. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  2894. }
  2895. static int
  2896. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  2897. u8 *peer, u8 action_code, u8 dialog_token,
  2898. u16 status_code, struct sk_buff *skb)
  2899. {
  2900. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2901. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  2902. struct ieee80211_tdls_data *tf;
  2903. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  2904. memcpy(tf->da, peer, ETH_ALEN);
  2905. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  2906. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  2907. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  2908. switch (action_code) {
  2909. case WLAN_TDLS_SETUP_REQUEST:
  2910. tf->category = WLAN_CATEGORY_TDLS;
  2911. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  2912. skb_put(skb, sizeof(tf->u.setup_req));
  2913. tf->u.setup_req.dialog_token = dialog_token;
  2914. tf->u.setup_req.capability =
  2915. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2916. ieee80211_add_srates_ie(sdata, skb, false, band);
  2917. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2918. ieee80211_tdls_add_ext_capab(skb);
  2919. break;
  2920. case WLAN_TDLS_SETUP_RESPONSE:
  2921. tf->category = WLAN_CATEGORY_TDLS;
  2922. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  2923. skb_put(skb, sizeof(tf->u.setup_resp));
  2924. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  2925. tf->u.setup_resp.dialog_token = dialog_token;
  2926. tf->u.setup_resp.capability =
  2927. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2928. ieee80211_add_srates_ie(sdata, skb, false, band);
  2929. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2930. ieee80211_tdls_add_ext_capab(skb);
  2931. break;
  2932. case WLAN_TDLS_SETUP_CONFIRM:
  2933. tf->category = WLAN_CATEGORY_TDLS;
  2934. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  2935. skb_put(skb, sizeof(tf->u.setup_cfm));
  2936. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  2937. tf->u.setup_cfm.dialog_token = dialog_token;
  2938. break;
  2939. case WLAN_TDLS_TEARDOWN:
  2940. tf->category = WLAN_CATEGORY_TDLS;
  2941. tf->action_code = WLAN_TDLS_TEARDOWN;
  2942. skb_put(skb, sizeof(tf->u.teardown));
  2943. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  2944. break;
  2945. case WLAN_TDLS_DISCOVERY_REQUEST:
  2946. tf->category = WLAN_CATEGORY_TDLS;
  2947. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  2948. skb_put(skb, sizeof(tf->u.discover_req));
  2949. tf->u.discover_req.dialog_token = dialog_token;
  2950. break;
  2951. default:
  2952. return -EINVAL;
  2953. }
  2954. return 0;
  2955. }
  2956. static int
  2957. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  2958. u8 *peer, u8 action_code, u8 dialog_token,
  2959. u16 status_code, struct sk_buff *skb)
  2960. {
  2961. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2962. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  2963. struct ieee80211_mgmt *mgmt;
  2964. mgmt = (void *)skb_put(skb, 24);
  2965. memset(mgmt, 0, 24);
  2966. memcpy(mgmt->da, peer, ETH_ALEN);
  2967. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  2968. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  2969. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2970. IEEE80211_STYPE_ACTION);
  2971. switch (action_code) {
  2972. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2973. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  2974. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  2975. mgmt->u.action.u.tdls_discover_resp.action_code =
  2976. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  2977. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  2978. dialog_token;
  2979. mgmt->u.action.u.tdls_discover_resp.capability =
  2980. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  2981. ieee80211_add_srates_ie(sdata, skb, false, band);
  2982. ieee80211_add_ext_srates_ie(sdata, skb, false, band);
  2983. ieee80211_tdls_add_ext_capab(skb);
  2984. break;
  2985. default:
  2986. return -EINVAL;
  2987. }
  2988. return 0;
  2989. }
  2990. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2991. u8 *peer, u8 action_code, u8 dialog_token,
  2992. u16 status_code, const u8 *extra_ies,
  2993. size_t extra_ies_len)
  2994. {
  2995. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2996. struct ieee80211_local *local = sdata->local;
  2997. struct sk_buff *skb = NULL;
  2998. bool send_direct;
  2999. int ret;
  3000. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  3001. return -ENOTSUPP;
  3002. /* make sure we are in managed mode, and associated */
  3003. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  3004. !sdata->u.mgd.associated)
  3005. return -EINVAL;
  3006. tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
  3007. action_code, peer);
  3008. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  3009. max(sizeof(struct ieee80211_mgmt),
  3010. sizeof(struct ieee80211_tdls_data)) +
  3011. 50 + /* supported rates */
  3012. 7 + /* ext capab */
  3013. extra_ies_len +
  3014. sizeof(struct ieee80211_tdls_lnkie));
  3015. if (!skb)
  3016. return -ENOMEM;
  3017. skb_reserve(skb, local->hw.extra_tx_headroom);
  3018. switch (action_code) {
  3019. case WLAN_TDLS_SETUP_REQUEST:
  3020. case WLAN_TDLS_SETUP_RESPONSE:
  3021. case WLAN_TDLS_SETUP_CONFIRM:
  3022. case WLAN_TDLS_TEARDOWN:
  3023. case WLAN_TDLS_DISCOVERY_REQUEST:
  3024. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  3025. action_code, dialog_token,
  3026. status_code, skb);
  3027. send_direct = false;
  3028. break;
  3029. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  3030. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  3031. dialog_token, status_code,
  3032. skb);
  3033. send_direct = true;
  3034. break;
  3035. default:
  3036. ret = -ENOTSUPP;
  3037. break;
  3038. }
  3039. if (ret < 0)
  3040. goto fail;
  3041. if (extra_ies_len)
  3042. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  3043. /* the TDLS link IE is always added last */
  3044. switch (action_code) {
  3045. case WLAN_TDLS_SETUP_REQUEST:
  3046. case WLAN_TDLS_SETUP_CONFIRM:
  3047. case WLAN_TDLS_TEARDOWN:
  3048. case WLAN_TDLS_DISCOVERY_REQUEST:
  3049. /* we are the initiator */
  3050. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  3051. sdata->u.mgd.bssid);
  3052. break;
  3053. case WLAN_TDLS_SETUP_RESPONSE:
  3054. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  3055. /* we are the responder */
  3056. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  3057. sdata->u.mgd.bssid);
  3058. break;
  3059. default:
  3060. ret = -ENOTSUPP;
  3061. goto fail;
  3062. }
  3063. if (send_direct) {
  3064. ieee80211_tx_skb(sdata, skb);
  3065. return 0;
  3066. }
  3067. /*
  3068. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  3069. * we should default to AC_VI.
  3070. */
  3071. switch (action_code) {
  3072. case WLAN_TDLS_SETUP_REQUEST:
  3073. case WLAN_TDLS_SETUP_RESPONSE:
  3074. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  3075. skb->priority = 2;
  3076. break;
  3077. default:
  3078. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  3079. skb->priority = 5;
  3080. break;
  3081. }
  3082. /* disable bottom halves when entering the Tx path */
  3083. local_bh_disable();
  3084. ret = ieee80211_subif_start_xmit(skb, dev);
  3085. local_bh_enable();
  3086. return ret;
  3087. fail:
  3088. dev_kfree_skb(skb);
  3089. return ret;
  3090. }
  3091. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  3092. u8 *peer, enum nl80211_tdls_operation oper)
  3093. {
  3094. struct sta_info *sta;
  3095. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3096. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  3097. return -ENOTSUPP;
  3098. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3099. return -EINVAL;
  3100. tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
  3101. switch (oper) {
  3102. case NL80211_TDLS_ENABLE_LINK:
  3103. rcu_read_lock();
  3104. sta = sta_info_get(sdata, peer);
  3105. if (!sta) {
  3106. rcu_read_unlock();
  3107. return -ENOLINK;
  3108. }
  3109. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  3110. rcu_read_unlock();
  3111. break;
  3112. case NL80211_TDLS_DISABLE_LINK:
  3113. return sta_info_destroy_addr(sdata, peer);
  3114. case NL80211_TDLS_TEARDOWN:
  3115. case NL80211_TDLS_SETUP:
  3116. case NL80211_TDLS_DISCOVERY_REQ:
  3117. /* We don't support in-driver setup/teardown/discovery */
  3118. return -ENOTSUPP;
  3119. default:
  3120. return -ENOTSUPP;
  3121. }
  3122. return 0;
  3123. }
  3124. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  3125. const u8 *peer, u64 *cookie)
  3126. {
  3127. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3128. struct ieee80211_local *local = sdata->local;
  3129. struct ieee80211_qos_hdr *nullfunc;
  3130. struct sk_buff *skb;
  3131. int size = sizeof(*nullfunc);
  3132. __le16 fc;
  3133. bool qos;
  3134. struct ieee80211_tx_info *info;
  3135. struct sta_info *sta;
  3136. struct ieee80211_chanctx_conf *chanctx_conf;
  3137. enum ieee80211_band band;
  3138. rcu_read_lock();
  3139. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  3140. if (WARN_ON(!chanctx_conf)) {
  3141. rcu_read_unlock();
  3142. return -EINVAL;
  3143. }
  3144. band = chanctx_conf->def.chan->band;
  3145. sta = sta_info_get_bss(sdata, peer);
  3146. if (sta) {
  3147. qos = test_sta_flag(sta, WLAN_STA_WME);
  3148. } else {
  3149. rcu_read_unlock();
  3150. return -ENOLINK;
  3151. }
  3152. if (qos) {
  3153. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  3154. IEEE80211_STYPE_QOS_NULLFUNC |
  3155. IEEE80211_FCTL_FROMDS);
  3156. } else {
  3157. size -= 2;
  3158. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  3159. IEEE80211_STYPE_NULLFUNC |
  3160. IEEE80211_FCTL_FROMDS);
  3161. }
  3162. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  3163. if (!skb) {
  3164. rcu_read_unlock();
  3165. return -ENOMEM;
  3166. }
  3167. skb->dev = dev;
  3168. skb_reserve(skb, local->hw.extra_tx_headroom);
  3169. nullfunc = (void *) skb_put(skb, size);
  3170. nullfunc->frame_control = fc;
  3171. nullfunc->duration_id = 0;
  3172. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  3173. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  3174. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  3175. nullfunc->seq_ctrl = 0;
  3176. info = IEEE80211_SKB_CB(skb);
  3177. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  3178. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  3179. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  3180. skb->priority = 7;
  3181. if (qos)
  3182. nullfunc->qos_ctrl = cpu_to_le16(7);
  3183. local_bh_disable();
  3184. ieee80211_xmit(sdata, skb, band);
  3185. local_bh_enable();
  3186. rcu_read_unlock();
  3187. *cookie = (unsigned long) skb;
  3188. return 0;
  3189. }
  3190. static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  3191. struct wireless_dev *wdev,
  3192. struct cfg80211_chan_def *chandef)
  3193. {
  3194. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  3195. struct ieee80211_local *local = wiphy_priv(wiphy);
  3196. struct ieee80211_chanctx_conf *chanctx_conf;
  3197. int ret = -ENODATA;
  3198. rcu_read_lock();
  3199. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  3200. if (chanctx_conf) {
  3201. *chandef = chanctx_conf->def;
  3202. ret = 0;
  3203. } else if (local->open_count > 0 &&
  3204. local->open_count == local->monitors &&
  3205. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  3206. if (local->use_chanctx)
  3207. *chandef = local->monitor_chandef;
  3208. else
  3209. *chandef = local->_oper_chandef;
  3210. ret = 0;
  3211. }
  3212. rcu_read_unlock();
  3213. return ret;
  3214. }
  3215. #ifdef CONFIG_PM
  3216. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  3217. {
  3218. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  3219. }
  3220. #endif
  3221. static int ieee80211_set_qos_map(struct wiphy *wiphy,
  3222. struct net_device *dev,
  3223. struct cfg80211_qos_map *qos_map)
  3224. {
  3225. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3226. struct mac80211_qos_map *new_qos_map, *old_qos_map;
  3227. if (qos_map) {
  3228. new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
  3229. if (!new_qos_map)
  3230. return -ENOMEM;
  3231. memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
  3232. } else {
  3233. /* A NULL qos_map was passed to disable QoS mapping */
  3234. new_qos_map = NULL;
  3235. }
  3236. old_qos_map = sdata_dereference(sdata->qos_map, sdata);
  3237. rcu_assign_pointer(sdata->qos_map, new_qos_map);
  3238. if (old_qos_map)
  3239. kfree_rcu(old_qos_map, rcu_head);
  3240. return 0;
  3241. }
  3242. struct cfg80211_ops mac80211_config_ops = {
  3243. .add_virtual_intf = ieee80211_add_iface,
  3244. .del_virtual_intf = ieee80211_del_iface,
  3245. .change_virtual_intf = ieee80211_change_iface,
  3246. .start_p2p_device = ieee80211_start_p2p_device,
  3247. .stop_p2p_device = ieee80211_stop_p2p_device,
  3248. .add_key = ieee80211_add_key,
  3249. .del_key = ieee80211_del_key,
  3250. .get_key = ieee80211_get_key,
  3251. .set_default_key = ieee80211_config_default_key,
  3252. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  3253. .start_ap = ieee80211_start_ap,
  3254. .change_beacon = ieee80211_change_beacon,
  3255. .stop_ap = ieee80211_stop_ap,
  3256. .add_station = ieee80211_add_station,
  3257. .del_station = ieee80211_del_station,
  3258. .change_station = ieee80211_change_station,
  3259. .get_station = ieee80211_get_station,
  3260. .dump_station = ieee80211_dump_station,
  3261. .dump_survey = ieee80211_dump_survey,
  3262. #ifdef CONFIG_MAC80211_MESH
  3263. .add_mpath = ieee80211_add_mpath,
  3264. .del_mpath = ieee80211_del_mpath,
  3265. .change_mpath = ieee80211_change_mpath,
  3266. .get_mpath = ieee80211_get_mpath,
  3267. .dump_mpath = ieee80211_dump_mpath,
  3268. .update_mesh_config = ieee80211_update_mesh_config,
  3269. .get_mesh_config = ieee80211_get_mesh_config,
  3270. .join_mesh = ieee80211_join_mesh,
  3271. .leave_mesh = ieee80211_leave_mesh,
  3272. #endif
  3273. .change_bss = ieee80211_change_bss,
  3274. .set_txq_params = ieee80211_set_txq_params,
  3275. .set_monitor_channel = ieee80211_set_monitor_channel,
  3276. .suspend = ieee80211_suspend,
  3277. .resume = ieee80211_resume,
  3278. .scan = ieee80211_scan,
  3279. .sched_scan_start = ieee80211_sched_scan_start,
  3280. .sched_scan_stop = ieee80211_sched_scan_stop,
  3281. .auth = ieee80211_auth,
  3282. .assoc = ieee80211_assoc,
  3283. .deauth = ieee80211_deauth,
  3284. .disassoc = ieee80211_disassoc,
  3285. .join_ibss = ieee80211_join_ibss,
  3286. .leave_ibss = ieee80211_leave_ibss,
  3287. .set_mcast_rate = ieee80211_set_mcast_rate,
  3288. .set_wiphy_params = ieee80211_set_wiphy_params,
  3289. .set_tx_power = ieee80211_set_tx_power,
  3290. .get_tx_power = ieee80211_get_tx_power,
  3291. .set_wds_peer = ieee80211_set_wds_peer,
  3292. .rfkill_poll = ieee80211_rfkill_poll,
  3293. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  3294. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  3295. .set_power_mgmt = ieee80211_set_power_mgmt,
  3296. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  3297. .remain_on_channel = ieee80211_remain_on_channel,
  3298. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  3299. .mgmt_tx = ieee80211_mgmt_tx,
  3300. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  3301. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  3302. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  3303. .set_antenna = ieee80211_set_antenna,
  3304. .get_antenna = ieee80211_get_antenna,
  3305. .set_ringparam = ieee80211_set_ringparam,
  3306. .get_ringparam = ieee80211_get_ringparam,
  3307. .set_rekey_data = ieee80211_set_rekey_data,
  3308. .tdls_oper = ieee80211_tdls_oper,
  3309. .tdls_mgmt = ieee80211_tdls_mgmt,
  3310. .probe_client = ieee80211_probe_client,
  3311. .set_noack_map = ieee80211_set_noack_map,
  3312. #ifdef CONFIG_PM
  3313. .set_wakeup = ieee80211_set_wakeup,
  3314. #endif
  3315. .get_et_sset_count = ieee80211_get_et_sset_count,
  3316. .get_et_stats = ieee80211_get_et_stats,
  3317. .get_et_strings = ieee80211_get_et_strings,
  3318. .get_channel = ieee80211_cfg_get_channel,
  3319. .start_radar_detection = ieee80211_start_radar_detection,
  3320. .channel_switch = ieee80211_channel_switch,
  3321. .set_qos_map = ieee80211_set_qos_map,
  3322. };