cfg.c 86 KB

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