cfg.c 65 KB

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