cfg.c 84 KB

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