cfg.c 88 KB

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