cfg.c 84 KB

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