cfg.c 77 KB

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