cfg.c 87 KB

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