cfg.c 107 KB

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