cfg.c 92 KB

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