cfg.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106
  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 <net/cfg80211.h>
  15. #include "ieee80211_i.h"
  16. #include "driver-ops.h"
  17. #include "cfg.h"
  18. #include "rate.h"
  19. #include "mesh.h"
  20. static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
  21. enum nl80211_iftype type,
  22. u32 *flags,
  23. struct vif_params *params)
  24. {
  25. struct ieee80211_local *local = wiphy_priv(wiphy);
  26. struct net_device *dev;
  27. struct ieee80211_sub_if_data *sdata;
  28. int err;
  29. err = ieee80211_if_add(local, name, &dev, type, params);
  30. if (err)
  31. return ERR_PTR(err);
  32. if (type == NL80211_IFTYPE_MONITOR && flags) {
  33. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  34. sdata->u.mntr_flags = *flags;
  35. }
  36. return dev;
  37. }
  38. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  39. {
  40. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  41. return 0;
  42. }
  43. static int ieee80211_change_iface(struct wiphy *wiphy,
  44. struct net_device *dev,
  45. enum nl80211_iftype type, u32 *flags,
  46. struct vif_params *params)
  47. {
  48. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  49. int ret;
  50. ret = ieee80211_if_change_type(sdata, type);
  51. if (ret)
  52. return ret;
  53. if (type == NL80211_IFTYPE_AP_VLAN &&
  54. params && params->use_4addr == 0)
  55. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  56. else if (type == NL80211_IFTYPE_STATION &&
  57. params && params->use_4addr >= 0)
  58. sdata->u.mgd.use_4addr = params->use_4addr;
  59. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
  60. struct ieee80211_local *local = sdata->local;
  61. if (ieee80211_sdata_running(sdata)) {
  62. /*
  63. * Prohibit MONITOR_FLAG_COOK_FRAMES to be
  64. * changed while the interface is up.
  65. * Else we would need to add a lot of cruft
  66. * to update everything:
  67. * cooked_mntrs, monitor and all fif_* counters
  68. * reconfigure hardware
  69. */
  70. if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
  71. (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  72. return -EBUSY;
  73. ieee80211_adjust_monitor_flags(sdata, -1);
  74. sdata->u.mntr_flags = *flags;
  75. ieee80211_adjust_monitor_flags(sdata, 1);
  76. ieee80211_configure_filter(local);
  77. } else {
  78. /*
  79. * Because the interface is down, ieee80211_do_stop
  80. * and ieee80211_do_open take care of "everything"
  81. * mentioned in the comment above.
  82. */
  83. sdata->u.mntr_flags = *flags;
  84. }
  85. }
  86. return 0;
  87. }
  88. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  89. u8 key_idx, bool pairwise, const u8 *mac_addr,
  90. struct key_params *params)
  91. {
  92. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  93. struct sta_info *sta = NULL;
  94. struct ieee80211_key *key;
  95. int err;
  96. if (!ieee80211_sdata_running(sdata))
  97. return -ENETDOWN;
  98. /* reject WEP and TKIP keys if WEP failed to initialize */
  99. switch (params->cipher) {
  100. case WLAN_CIPHER_SUITE_WEP40:
  101. case WLAN_CIPHER_SUITE_TKIP:
  102. case WLAN_CIPHER_SUITE_WEP104:
  103. if (IS_ERR(sdata->local->wep_tx_tfm))
  104. return -EINVAL;
  105. break;
  106. default:
  107. break;
  108. }
  109. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  110. params->key, params->seq_len, params->seq);
  111. if (IS_ERR(key))
  112. return PTR_ERR(key);
  113. if (pairwise)
  114. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  115. mutex_lock(&sdata->local->sta_mtx);
  116. if (mac_addr) {
  117. sta = sta_info_get_bss(sdata, mac_addr);
  118. if (!sta) {
  119. ieee80211_key_free(sdata->local, key);
  120. err = -ENOENT;
  121. goto out_unlock;
  122. }
  123. }
  124. err = ieee80211_key_link(key, sdata, sta);
  125. if (err)
  126. ieee80211_key_free(sdata->local, key);
  127. out_unlock:
  128. mutex_unlock(&sdata->local->sta_mtx);
  129. return err;
  130. }
  131. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  132. u8 key_idx, bool pairwise, const u8 *mac_addr)
  133. {
  134. struct ieee80211_sub_if_data *sdata;
  135. struct sta_info *sta;
  136. int ret;
  137. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  138. mutex_lock(&sdata->local->sta_mtx);
  139. if (mac_addr) {
  140. ret = -ENOENT;
  141. sta = sta_info_get_bss(sdata, mac_addr);
  142. if (!sta)
  143. goto out_unlock;
  144. if (pairwise) {
  145. if (sta->ptk) {
  146. ieee80211_key_free(sdata->local, sta->ptk);
  147. ret = 0;
  148. }
  149. } else {
  150. if (sta->gtk[key_idx]) {
  151. ieee80211_key_free(sdata->local,
  152. sta->gtk[key_idx]);
  153. ret = 0;
  154. }
  155. }
  156. goto out_unlock;
  157. }
  158. if (!sdata->keys[key_idx]) {
  159. ret = -ENOENT;
  160. goto out_unlock;
  161. }
  162. ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
  163. WARN_ON(sdata->keys[key_idx]);
  164. ret = 0;
  165. out_unlock:
  166. mutex_unlock(&sdata->local->sta_mtx);
  167. return ret;
  168. }
  169. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  170. u8 key_idx, bool pairwise, const u8 *mac_addr,
  171. void *cookie,
  172. void (*callback)(void *cookie,
  173. struct key_params *params))
  174. {
  175. struct ieee80211_sub_if_data *sdata;
  176. struct sta_info *sta = NULL;
  177. u8 seq[6] = {0};
  178. struct key_params params;
  179. struct ieee80211_key *key = NULL;
  180. u32 iv32;
  181. u16 iv16;
  182. int err = -ENOENT;
  183. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  184. rcu_read_lock();
  185. if (mac_addr) {
  186. sta = sta_info_get_bss(sdata, mac_addr);
  187. if (!sta)
  188. goto out;
  189. if (pairwise)
  190. key = sta->ptk;
  191. else if (key_idx < NUM_DEFAULT_KEYS)
  192. key = sta->gtk[key_idx];
  193. } else
  194. key = sdata->keys[key_idx];
  195. if (!key)
  196. goto out;
  197. memset(&params, 0, sizeof(params));
  198. params.cipher = key->conf.cipher;
  199. switch (key->conf.cipher) {
  200. case WLAN_CIPHER_SUITE_TKIP:
  201. iv32 = key->u.tkip.tx.iv32;
  202. iv16 = key->u.tkip.tx.iv16;
  203. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  204. drv_get_tkip_seq(sdata->local,
  205. key->conf.hw_key_idx,
  206. &iv32, &iv16);
  207. seq[0] = iv16 & 0xff;
  208. seq[1] = (iv16 >> 8) & 0xff;
  209. seq[2] = iv32 & 0xff;
  210. seq[3] = (iv32 >> 8) & 0xff;
  211. seq[4] = (iv32 >> 16) & 0xff;
  212. seq[5] = (iv32 >> 24) & 0xff;
  213. params.seq = seq;
  214. params.seq_len = 6;
  215. break;
  216. case WLAN_CIPHER_SUITE_CCMP:
  217. seq[0] = key->u.ccmp.tx_pn[5];
  218. seq[1] = key->u.ccmp.tx_pn[4];
  219. seq[2] = key->u.ccmp.tx_pn[3];
  220. seq[3] = key->u.ccmp.tx_pn[2];
  221. seq[4] = key->u.ccmp.tx_pn[1];
  222. seq[5] = key->u.ccmp.tx_pn[0];
  223. params.seq = seq;
  224. params.seq_len = 6;
  225. break;
  226. case WLAN_CIPHER_SUITE_AES_CMAC:
  227. seq[0] = key->u.aes_cmac.tx_pn[5];
  228. seq[1] = key->u.aes_cmac.tx_pn[4];
  229. seq[2] = key->u.aes_cmac.tx_pn[3];
  230. seq[3] = key->u.aes_cmac.tx_pn[2];
  231. seq[4] = key->u.aes_cmac.tx_pn[1];
  232. seq[5] = key->u.aes_cmac.tx_pn[0];
  233. params.seq = seq;
  234. params.seq_len = 6;
  235. break;
  236. }
  237. params.key = key->conf.key;
  238. params.key_len = key->conf.keylen;
  239. callback(cookie, &params);
  240. err = 0;
  241. out:
  242. rcu_read_unlock();
  243. return err;
  244. }
  245. static int ieee80211_config_default_key(struct wiphy *wiphy,
  246. struct net_device *dev,
  247. u8 key_idx, bool uni,
  248. bool multi)
  249. {
  250. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  251. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  252. return 0;
  253. }
  254. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  255. struct net_device *dev,
  256. u8 key_idx)
  257. {
  258. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  259. ieee80211_set_default_mgmt_key(sdata, key_idx);
  260. return 0;
  261. }
  262. static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
  263. {
  264. if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
  265. struct ieee80211_supported_band *sband;
  266. sband = sta->local->hw.wiphy->bands[
  267. sta->local->hw.conf.channel->band];
  268. rate->legacy = sband->bitrates[idx].bitrate;
  269. } else
  270. rate->mcs = idx;
  271. }
  272. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  273. {
  274. struct ieee80211_sub_if_data *sdata = sta->sdata;
  275. sinfo->generation = sdata->local->sta_generation;
  276. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  277. STATION_INFO_RX_BYTES |
  278. STATION_INFO_TX_BYTES |
  279. STATION_INFO_RX_PACKETS |
  280. STATION_INFO_TX_PACKETS |
  281. STATION_INFO_TX_RETRIES |
  282. STATION_INFO_TX_FAILED |
  283. STATION_INFO_TX_BITRATE |
  284. STATION_INFO_RX_BITRATE |
  285. STATION_INFO_RX_DROP_MISC |
  286. STATION_INFO_BSS_PARAM;
  287. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  288. sinfo->rx_bytes = sta->rx_bytes;
  289. sinfo->tx_bytes = sta->tx_bytes;
  290. sinfo->rx_packets = sta->rx_packets;
  291. sinfo->tx_packets = sta->tx_packets;
  292. sinfo->tx_retries = sta->tx_retry_count;
  293. sinfo->tx_failed = sta->tx_retry_failed;
  294. sinfo->rx_dropped_misc = sta->rx_dropped;
  295. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  296. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  297. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  298. sinfo->signal = (s8)sta->last_signal;
  299. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  300. }
  301. sinfo->txrate.flags = 0;
  302. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  303. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  304. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  305. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  306. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  307. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  308. rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
  309. sinfo->rxrate.flags = 0;
  310. if (sta->last_rx_rate_flag & RX_FLAG_HT)
  311. sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
  312. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  313. sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  314. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  315. sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  316. rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
  317. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  318. #ifdef CONFIG_MAC80211_MESH
  319. sinfo->filled |= STATION_INFO_LLID |
  320. STATION_INFO_PLID |
  321. STATION_INFO_PLINK_STATE;
  322. sinfo->llid = le16_to_cpu(sta->llid);
  323. sinfo->plid = le16_to_cpu(sta->plid);
  324. sinfo->plink_state = sta->plink_state;
  325. #endif
  326. }
  327. sinfo->bss_param.flags = 0;
  328. if (sdata->vif.bss_conf.use_cts_prot)
  329. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  330. if (sdata->vif.bss_conf.use_short_preamble)
  331. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  332. if (sdata->vif.bss_conf.use_short_slot)
  333. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  334. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  335. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  336. }
  337. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  338. int idx, u8 *mac, struct station_info *sinfo)
  339. {
  340. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  341. struct sta_info *sta;
  342. int ret = -ENOENT;
  343. rcu_read_lock();
  344. sta = sta_info_get_by_idx(sdata, idx);
  345. if (sta) {
  346. ret = 0;
  347. memcpy(mac, sta->sta.addr, ETH_ALEN);
  348. sta_set_sinfo(sta, sinfo);
  349. }
  350. rcu_read_unlock();
  351. return ret;
  352. }
  353. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  354. int idx, struct survey_info *survey)
  355. {
  356. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  357. return drv_get_survey(local, idx, survey);
  358. }
  359. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  360. u8 *mac, struct station_info *sinfo)
  361. {
  362. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  363. struct sta_info *sta;
  364. int ret = -ENOENT;
  365. rcu_read_lock();
  366. sta = sta_info_get_bss(sdata, mac);
  367. if (sta) {
  368. ret = 0;
  369. sta_set_sinfo(sta, sinfo);
  370. }
  371. rcu_read_unlock();
  372. return ret;
  373. }
  374. /*
  375. * This handles both adding a beacon and setting new beacon info
  376. */
  377. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  378. struct beacon_parameters *params)
  379. {
  380. struct beacon_data *new, *old;
  381. int new_head_len, new_tail_len;
  382. int size;
  383. int err = -EINVAL;
  384. old = sdata->u.ap.beacon;
  385. /* head must not be zero-length */
  386. if (params->head && !params->head_len)
  387. return -EINVAL;
  388. /*
  389. * This is a kludge. beacon interval should really be part
  390. * of the beacon information.
  391. */
  392. if (params->interval &&
  393. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  394. sdata->vif.bss_conf.beacon_int = params->interval;
  395. ieee80211_bss_info_change_notify(sdata,
  396. BSS_CHANGED_BEACON_INT);
  397. }
  398. /* Need to have a beacon head if we don't have one yet */
  399. if (!params->head && !old)
  400. return err;
  401. /* sorry, no way to start beaconing without dtim period */
  402. if (!params->dtim_period && !old)
  403. return err;
  404. /* new or old head? */
  405. if (params->head)
  406. new_head_len = params->head_len;
  407. else
  408. new_head_len = old->head_len;
  409. /* new or old tail? */
  410. if (params->tail || !old)
  411. /* params->tail_len will be zero for !params->tail */
  412. new_tail_len = params->tail_len;
  413. else
  414. new_tail_len = old->tail_len;
  415. size = sizeof(*new) + new_head_len + new_tail_len;
  416. new = kzalloc(size, GFP_KERNEL);
  417. if (!new)
  418. return -ENOMEM;
  419. /* start filling the new info now */
  420. /* new or old dtim period? */
  421. if (params->dtim_period)
  422. new->dtim_period = params->dtim_period;
  423. else
  424. new->dtim_period = old->dtim_period;
  425. /*
  426. * pointers go into the block we allocated,
  427. * memory is | beacon_data | head | tail |
  428. */
  429. new->head = ((u8 *) new) + sizeof(*new);
  430. new->tail = new->head + new_head_len;
  431. new->head_len = new_head_len;
  432. new->tail_len = new_tail_len;
  433. /* copy in head */
  434. if (params->head)
  435. memcpy(new->head, params->head, new_head_len);
  436. else
  437. memcpy(new->head, old->head, new_head_len);
  438. /* copy in optional tail */
  439. if (params->tail)
  440. memcpy(new->tail, params->tail, new_tail_len);
  441. else
  442. if (old)
  443. memcpy(new->tail, old->tail, new_tail_len);
  444. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  445. rcu_assign_pointer(sdata->u.ap.beacon, new);
  446. synchronize_rcu();
  447. kfree(old);
  448. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  449. BSS_CHANGED_BEACON);
  450. return 0;
  451. }
  452. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  453. struct beacon_parameters *params)
  454. {
  455. struct ieee80211_sub_if_data *sdata;
  456. struct beacon_data *old;
  457. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  458. old = sdata->u.ap.beacon;
  459. if (old)
  460. return -EALREADY;
  461. return ieee80211_config_beacon(sdata, params);
  462. }
  463. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  464. struct beacon_parameters *params)
  465. {
  466. struct ieee80211_sub_if_data *sdata;
  467. struct beacon_data *old;
  468. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  469. old = sdata->u.ap.beacon;
  470. if (!old)
  471. return -ENOENT;
  472. return ieee80211_config_beacon(sdata, params);
  473. }
  474. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  475. {
  476. struct ieee80211_sub_if_data *sdata;
  477. struct beacon_data *old;
  478. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  479. old = sdata->u.ap.beacon;
  480. if (!old)
  481. return -ENOENT;
  482. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  483. synchronize_rcu();
  484. kfree(old);
  485. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  486. return 0;
  487. }
  488. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  489. struct iapp_layer2_update {
  490. u8 da[ETH_ALEN]; /* broadcast */
  491. u8 sa[ETH_ALEN]; /* STA addr */
  492. __be16 len; /* 6 */
  493. u8 dsap; /* 0 */
  494. u8 ssap; /* 0 */
  495. u8 control;
  496. u8 xid_info[3];
  497. } __packed;
  498. static void ieee80211_send_layer2_update(struct sta_info *sta)
  499. {
  500. struct iapp_layer2_update *msg;
  501. struct sk_buff *skb;
  502. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  503. * bridge devices */
  504. skb = dev_alloc_skb(sizeof(*msg));
  505. if (!skb)
  506. return;
  507. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  508. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  509. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  510. memset(msg->da, 0xff, ETH_ALEN);
  511. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  512. msg->len = htons(6);
  513. msg->dsap = 0;
  514. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  515. msg->control = 0xaf; /* XID response lsb.1111F101.
  516. * F=0 (no poll command; unsolicited frame) */
  517. msg->xid_info[0] = 0x81; /* XID format identifier */
  518. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  519. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  520. skb->dev = sta->sdata->dev;
  521. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  522. memset(skb->cb, 0, sizeof(skb->cb));
  523. netif_rx_ni(skb);
  524. }
  525. static void sta_apply_parameters(struct ieee80211_local *local,
  526. struct sta_info *sta,
  527. struct station_parameters *params)
  528. {
  529. unsigned long flags;
  530. u32 rates;
  531. int i, j;
  532. struct ieee80211_supported_band *sband;
  533. struct ieee80211_sub_if_data *sdata = sta->sdata;
  534. u32 mask, set;
  535. sband = local->hw.wiphy->bands[local->oper_channel->band];
  536. spin_lock_irqsave(&sta->flaglock, flags);
  537. mask = params->sta_flags_mask;
  538. set = params->sta_flags_set;
  539. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  540. sta->flags &= ~WLAN_STA_AUTHORIZED;
  541. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  542. sta->flags |= WLAN_STA_AUTHORIZED;
  543. }
  544. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  545. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  546. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  547. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  548. }
  549. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  550. sta->flags &= ~WLAN_STA_WME;
  551. if (set & BIT(NL80211_STA_FLAG_WME))
  552. sta->flags |= WLAN_STA_WME;
  553. }
  554. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  555. sta->flags &= ~WLAN_STA_MFP;
  556. if (set & BIT(NL80211_STA_FLAG_MFP))
  557. sta->flags |= WLAN_STA_MFP;
  558. }
  559. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  560. sta->flags &= ~WLAN_STA_AUTH;
  561. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  562. sta->flags |= WLAN_STA_AUTH;
  563. }
  564. spin_unlock_irqrestore(&sta->flaglock, flags);
  565. /*
  566. * cfg80211 validates this (1-2007) and allows setting the AID
  567. * only when creating a new station entry
  568. */
  569. if (params->aid)
  570. sta->sta.aid = params->aid;
  571. /*
  572. * FIXME: updating the following information is racy when this
  573. * function is called from ieee80211_change_station().
  574. * However, all this information should be static so
  575. * maybe we should just reject attemps to change it.
  576. */
  577. if (params->listen_interval >= 0)
  578. sta->listen_interval = params->listen_interval;
  579. if (params->supported_rates) {
  580. rates = 0;
  581. for (i = 0; i < params->supported_rates_len; i++) {
  582. int rate = (params->supported_rates[i] & 0x7f) * 5;
  583. for (j = 0; j < sband->n_bitrates; j++) {
  584. if (sband->bitrates[j].bitrate == rate)
  585. rates |= BIT(j);
  586. }
  587. }
  588. sta->sta.supp_rates[local->oper_channel->band] = rates;
  589. }
  590. if (params->ht_capa)
  591. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  592. params->ht_capa,
  593. &sta->sta.ht_cap);
  594. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  595. switch (params->plink_action) {
  596. case PLINK_ACTION_OPEN:
  597. mesh_plink_open(sta);
  598. break;
  599. case PLINK_ACTION_BLOCK:
  600. mesh_plink_block(sta);
  601. break;
  602. }
  603. }
  604. }
  605. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  606. u8 *mac, struct station_parameters *params)
  607. {
  608. struct ieee80211_local *local = wiphy_priv(wiphy);
  609. struct sta_info *sta;
  610. struct ieee80211_sub_if_data *sdata;
  611. int err;
  612. int layer2_update;
  613. if (params->vlan) {
  614. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  615. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  616. sdata->vif.type != NL80211_IFTYPE_AP)
  617. return -EINVAL;
  618. } else
  619. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  620. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  621. return -EINVAL;
  622. if (is_multicast_ether_addr(mac))
  623. return -EINVAL;
  624. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  625. if (!sta)
  626. return -ENOMEM;
  627. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  628. sta_apply_parameters(local, sta, params);
  629. rate_control_rate_init(sta);
  630. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  631. sdata->vif.type == NL80211_IFTYPE_AP;
  632. err = sta_info_insert_rcu(sta);
  633. if (err) {
  634. rcu_read_unlock();
  635. return err;
  636. }
  637. if (layer2_update)
  638. ieee80211_send_layer2_update(sta);
  639. rcu_read_unlock();
  640. return 0;
  641. }
  642. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  643. u8 *mac)
  644. {
  645. struct ieee80211_local *local = wiphy_priv(wiphy);
  646. struct ieee80211_sub_if_data *sdata;
  647. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  648. if (mac)
  649. return sta_info_destroy_addr_bss(sdata, mac);
  650. sta_info_flush(local, sdata);
  651. return 0;
  652. }
  653. static int ieee80211_change_station(struct wiphy *wiphy,
  654. struct net_device *dev,
  655. u8 *mac,
  656. struct station_parameters *params)
  657. {
  658. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  659. struct ieee80211_local *local = wiphy_priv(wiphy);
  660. struct sta_info *sta;
  661. struct ieee80211_sub_if_data *vlansdata;
  662. rcu_read_lock();
  663. sta = sta_info_get_bss(sdata, mac);
  664. if (!sta) {
  665. rcu_read_unlock();
  666. return -ENOENT;
  667. }
  668. if (params->vlan && params->vlan != sta->sdata->dev) {
  669. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  670. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  671. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  672. rcu_read_unlock();
  673. return -EINVAL;
  674. }
  675. if (params->vlan->ieee80211_ptr->use_4addr) {
  676. if (vlansdata->u.vlan.sta) {
  677. rcu_read_unlock();
  678. return -EBUSY;
  679. }
  680. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  681. }
  682. sta->sdata = vlansdata;
  683. ieee80211_send_layer2_update(sta);
  684. }
  685. sta_apply_parameters(local, sta, params);
  686. rcu_read_unlock();
  687. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  688. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  689. ieee80211_recalc_ps(local, -1);
  690. return 0;
  691. }
  692. #ifdef CONFIG_MAC80211_MESH
  693. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  694. u8 *dst, u8 *next_hop)
  695. {
  696. struct ieee80211_sub_if_data *sdata;
  697. struct mesh_path *mpath;
  698. struct sta_info *sta;
  699. int err;
  700. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  701. rcu_read_lock();
  702. sta = sta_info_get(sdata, next_hop);
  703. if (!sta) {
  704. rcu_read_unlock();
  705. return -ENOENT;
  706. }
  707. err = mesh_path_add(dst, sdata);
  708. if (err) {
  709. rcu_read_unlock();
  710. return err;
  711. }
  712. mpath = mesh_path_lookup(dst, sdata);
  713. if (!mpath) {
  714. rcu_read_unlock();
  715. return -ENXIO;
  716. }
  717. mesh_path_fix_nexthop(mpath, sta);
  718. rcu_read_unlock();
  719. return 0;
  720. }
  721. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  722. u8 *dst)
  723. {
  724. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  725. if (dst)
  726. return mesh_path_del(dst, sdata);
  727. mesh_path_flush(sdata);
  728. return 0;
  729. }
  730. static int ieee80211_change_mpath(struct wiphy *wiphy,
  731. struct net_device *dev,
  732. u8 *dst, u8 *next_hop)
  733. {
  734. struct ieee80211_sub_if_data *sdata;
  735. struct mesh_path *mpath;
  736. struct sta_info *sta;
  737. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  738. rcu_read_lock();
  739. sta = sta_info_get(sdata, next_hop);
  740. if (!sta) {
  741. rcu_read_unlock();
  742. return -ENOENT;
  743. }
  744. mpath = mesh_path_lookup(dst, sdata);
  745. if (!mpath) {
  746. rcu_read_unlock();
  747. return -ENOENT;
  748. }
  749. mesh_path_fix_nexthop(mpath, sta);
  750. rcu_read_unlock();
  751. return 0;
  752. }
  753. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  754. struct mpath_info *pinfo)
  755. {
  756. if (mpath->next_hop)
  757. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  758. else
  759. memset(next_hop, 0, ETH_ALEN);
  760. pinfo->generation = mesh_paths_generation;
  761. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  762. MPATH_INFO_SN |
  763. MPATH_INFO_METRIC |
  764. MPATH_INFO_EXPTIME |
  765. MPATH_INFO_DISCOVERY_TIMEOUT |
  766. MPATH_INFO_DISCOVERY_RETRIES |
  767. MPATH_INFO_FLAGS;
  768. pinfo->frame_qlen = mpath->frame_queue.qlen;
  769. pinfo->sn = mpath->sn;
  770. pinfo->metric = mpath->metric;
  771. if (time_before(jiffies, mpath->exp_time))
  772. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  773. pinfo->discovery_timeout =
  774. jiffies_to_msecs(mpath->discovery_timeout);
  775. pinfo->discovery_retries = mpath->discovery_retries;
  776. pinfo->flags = 0;
  777. if (mpath->flags & MESH_PATH_ACTIVE)
  778. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  779. if (mpath->flags & MESH_PATH_RESOLVING)
  780. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  781. if (mpath->flags & MESH_PATH_SN_VALID)
  782. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  783. if (mpath->flags & MESH_PATH_FIXED)
  784. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  785. if (mpath->flags & MESH_PATH_RESOLVING)
  786. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  787. pinfo->flags = mpath->flags;
  788. }
  789. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  790. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  791. {
  792. struct ieee80211_sub_if_data *sdata;
  793. struct mesh_path *mpath;
  794. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  795. rcu_read_lock();
  796. mpath = mesh_path_lookup(dst, sdata);
  797. if (!mpath) {
  798. rcu_read_unlock();
  799. return -ENOENT;
  800. }
  801. memcpy(dst, mpath->dst, ETH_ALEN);
  802. mpath_set_pinfo(mpath, next_hop, pinfo);
  803. rcu_read_unlock();
  804. return 0;
  805. }
  806. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  807. int idx, u8 *dst, u8 *next_hop,
  808. struct mpath_info *pinfo)
  809. {
  810. struct ieee80211_sub_if_data *sdata;
  811. struct mesh_path *mpath;
  812. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  813. rcu_read_lock();
  814. mpath = mesh_path_lookup_by_idx(idx, sdata);
  815. if (!mpath) {
  816. rcu_read_unlock();
  817. return -ENOENT;
  818. }
  819. memcpy(dst, mpath->dst, ETH_ALEN);
  820. mpath_set_pinfo(mpath, next_hop, pinfo);
  821. rcu_read_unlock();
  822. return 0;
  823. }
  824. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  825. struct net_device *dev,
  826. struct mesh_config *conf)
  827. {
  828. struct ieee80211_sub_if_data *sdata;
  829. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  830. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  831. return 0;
  832. }
  833. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  834. {
  835. return (mask >> (parm-1)) & 0x1;
  836. }
  837. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  838. const struct mesh_setup *setup)
  839. {
  840. u8 *new_ie;
  841. const u8 *old_ie;
  842. /* allocate information elements */
  843. new_ie = NULL;
  844. old_ie = ifmsh->ie;
  845. if (setup->ie_len) {
  846. new_ie = kmemdup(setup->ie, setup->ie_len,
  847. GFP_KERNEL);
  848. if (!new_ie)
  849. return -ENOMEM;
  850. }
  851. ifmsh->ie_len = setup->ie_len;
  852. ifmsh->ie = new_ie;
  853. kfree(old_ie);
  854. /* now copy the rest of the setup parameters */
  855. ifmsh->mesh_id_len = setup->mesh_id_len;
  856. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  857. ifmsh->mesh_pp_id = setup->path_sel_proto;
  858. ifmsh->mesh_pm_id = setup->path_metric;
  859. ifmsh->is_secure = setup->is_secure;
  860. return 0;
  861. }
  862. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  863. struct net_device *dev, u32 mask,
  864. const struct mesh_config *nconf)
  865. {
  866. struct mesh_config *conf;
  867. struct ieee80211_sub_if_data *sdata;
  868. struct ieee80211_if_mesh *ifmsh;
  869. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  870. ifmsh = &sdata->u.mesh;
  871. /* Set the config options which we are interested in setting */
  872. conf = &(sdata->u.mesh.mshcfg);
  873. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  874. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  875. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  876. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  877. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  878. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  879. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  880. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  881. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  882. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  883. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  884. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  885. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  886. conf->dot11MeshTTL = nconf->element_ttl;
  887. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  888. conf->auto_open_plinks = nconf->auto_open_plinks;
  889. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  890. conf->dot11MeshHWMPmaxPREQretries =
  891. nconf->dot11MeshHWMPmaxPREQretries;
  892. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  893. conf->path_refresh_time = nconf->path_refresh_time;
  894. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  895. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  896. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  897. conf->dot11MeshHWMPactivePathTimeout =
  898. nconf->dot11MeshHWMPactivePathTimeout;
  899. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  900. conf->dot11MeshHWMPpreqMinInterval =
  901. nconf->dot11MeshHWMPpreqMinInterval;
  902. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  903. mask))
  904. conf->dot11MeshHWMPnetDiameterTraversalTime =
  905. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  906. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  907. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  908. ieee80211_mesh_root_setup(ifmsh);
  909. }
  910. return 0;
  911. }
  912. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  913. const struct mesh_config *conf,
  914. const struct mesh_setup *setup)
  915. {
  916. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  917. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  918. int err;
  919. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  920. err = copy_mesh_setup(ifmsh, setup);
  921. if (err)
  922. return err;
  923. ieee80211_start_mesh(sdata);
  924. return 0;
  925. }
  926. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  927. {
  928. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  929. ieee80211_stop_mesh(sdata);
  930. return 0;
  931. }
  932. #endif
  933. static int ieee80211_change_bss(struct wiphy *wiphy,
  934. struct net_device *dev,
  935. struct bss_parameters *params)
  936. {
  937. struct ieee80211_sub_if_data *sdata;
  938. u32 changed = 0;
  939. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  940. if (params->use_cts_prot >= 0) {
  941. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  942. changed |= BSS_CHANGED_ERP_CTS_PROT;
  943. }
  944. if (params->use_short_preamble >= 0) {
  945. sdata->vif.bss_conf.use_short_preamble =
  946. params->use_short_preamble;
  947. changed |= BSS_CHANGED_ERP_PREAMBLE;
  948. }
  949. if (!sdata->vif.bss_conf.use_short_slot &&
  950. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  951. sdata->vif.bss_conf.use_short_slot = true;
  952. changed |= BSS_CHANGED_ERP_SLOT;
  953. }
  954. if (params->use_short_slot_time >= 0) {
  955. sdata->vif.bss_conf.use_short_slot =
  956. params->use_short_slot_time;
  957. changed |= BSS_CHANGED_ERP_SLOT;
  958. }
  959. if (params->basic_rates) {
  960. int i, j;
  961. u32 rates = 0;
  962. struct ieee80211_local *local = wiphy_priv(wiphy);
  963. struct ieee80211_supported_band *sband =
  964. wiphy->bands[local->oper_channel->band];
  965. for (i = 0; i < params->basic_rates_len; i++) {
  966. int rate = (params->basic_rates[i] & 0x7f) * 5;
  967. for (j = 0; j < sband->n_bitrates; j++) {
  968. if (sband->bitrates[j].bitrate == rate)
  969. rates |= BIT(j);
  970. }
  971. }
  972. sdata->vif.bss_conf.basic_rates = rates;
  973. changed |= BSS_CHANGED_BASIC_RATES;
  974. }
  975. if (params->ap_isolate >= 0) {
  976. if (params->ap_isolate)
  977. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  978. else
  979. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  980. }
  981. if (params->ht_opmode >= 0) {
  982. sdata->vif.bss_conf.ht_operation_mode =
  983. (u16) params->ht_opmode;
  984. changed |= BSS_CHANGED_HT;
  985. }
  986. ieee80211_bss_info_change_notify(sdata, changed);
  987. return 0;
  988. }
  989. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  990. struct ieee80211_txq_params *params)
  991. {
  992. struct ieee80211_local *local = wiphy_priv(wiphy);
  993. struct ieee80211_tx_queue_params p;
  994. if (!local->ops->conf_tx)
  995. return -EOPNOTSUPP;
  996. memset(&p, 0, sizeof(p));
  997. p.aifs = params->aifs;
  998. p.cw_max = params->cwmax;
  999. p.cw_min = params->cwmin;
  1000. p.txop = params->txop;
  1001. /*
  1002. * Setting tx queue params disables u-apsd because it's only
  1003. * called in master mode.
  1004. */
  1005. p.uapsd = false;
  1006. if (drv_conf_tx(local, params->queue, &p)) {
  1007. wiphy_debug(local->hw.wiphy,
  1008. "failed to set TX queue parameters for queue %d\n",
  1009. params->queue);
  1010. return -EINVAL;
  1011. }
  1012. return 0;
  1013. }
  1014. static int ieee80211_set_channel(struct wiphy *wiphy,
  1015. struct net_device *netdev,
  1016. struct ieee80211_channel *chan,
  1017. enum nl80211_channel_type channel_type)
  1018. {
  1019. struct ieee80211_local *local = wiphy_priv(wiphy);
  1020. struct ieee80211_sub_if_data *sdata = NULL;
  1021. struct ieee80211_channel *old_oper;
  1022. enum nl80211_channel_type old_oper_type;
  1023. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1024. if (netdev)
  1025. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1026. switch (ieee80211_get_channel_mode(local, NULL)) {
  1027. case CHAN_MODE_HOPPING:
  1028. return -EBUSY;
  1029. case CHAN_MODE_FIXED:
  1030. if (local->oper_channel != chan)
  1031. return -EBUSY;
  1032. if (!sdata && local->_oper_channel_type == channel_type)
  1033. return 0;
  1034. break;
  1035. case CHAN_MODE_UNDEFINED:
  1036. break;
  1037. }
  1038. if (sdata)
  1039. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1040. old_oper_type = local->_oper_channel_type;
  1041. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1042. return -EBUSY;
  1043. old_oper = local->oper_channel;
  1044. local->oper_channel = chan;
  1045. /* Update driver if changes were actually made. */
  1046. if ((old_oper != local->oper_channel) ||
  1047. (old_oper_type != local->_oper_channel_type))
  1048. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1049. if ((sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR) &&
  1050. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1051. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1052. return 0;
  1053. }
  1054. #ifdef CONFIG_PM
  1055. static int ieee80211_suspend(struct wiphy *wiphy)
  1056. {
  1057. return __ieee80211_suspend(wiphy_priv(wiphy));
  1058. }
  1059. static int ieee80211_resume(struct wiphy *wiphy)
  1060. {
  1061. return __ieee80211_resume(wiphy_priv(wiphy));
  1062. }
  1063. #else
  1064. #define ieee80211_suspend NULL
  1065. #define ieee80211_resume NULL
  1066. #endif
  1067. static int ieee80211_scan(struct wiphy *wiphy,
  1068. struct net_device *dev,
  1069. struct cfg80211_scan_request *req)
  1070. {
  1071. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1072. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1073. case NL80211_IFTYPE_STATION:
  1074. case NL80211_IFTYPE_ADHOC:
  1075. case NL80211_IFTYPE_MESH_POINT:
  1076. case NL80211_IFTYPE_P2P_CLIENT:
  1077. break;
  1078. case NL80211_IFTYPE_P2P_GO:
  1079. if (sdata->local->ops->hw_scan)
  1080. break;
  1081. /*
  1082. * FIXME: implement NoA while scanning in software,
  1083. * for now fall through to allow scanning only when
  1084. * beaconing hasn't been configured yet
  1085. */
  1086. case NL80211_IFTYPE_AP:
  1087. if (sdata->u.ap.beacon)
  1088. return -EOPNOTSUPP;
  1089. break;
  1090. default:
  1091. return -EOPNOTSUPP;
  1092. }
  1093. return ieee80211_request_scan(sdata, req);
  1094. }
  1095. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1096. struct cfg80211_auth_request *req)
  1097. {
  1098. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1099. }
  1100. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1101. struct cfg80211_assoc_request *req)
  1102. {
  1103. struct ieee80211_local *local = wiphy_priv(wiphy);
  1104. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1105. switch (ieee80211_get_channel_mode(local, sdata)) {
  1106. case CHAN_MODE_HOPPING:
  1107. return -EBUSY;
  1108. case CHAN_MODE_FIXED:
  1109. if (local->oper_channel == req->bss->channel)
  1110. break;
  1111. return -EBUSY;
  1112. case CHAN_MODE_UNDEFINED:
  1113. break;
  1114. }
  1115. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1116. }
  1117. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1118. struct cfg80211_deauth_request *req,
  1119. void *cookie)
  1120. {
  1121. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1122. req, cookie);
  1123. }
  1124. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1125. struct cfg80211_disassoc_request *req,
  1126. void *cookie)
  1127. {
  1128. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1129. req, cookie);
  1130. }
  1131. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1132. struct cfg80211_ibss_params *params)
  1133. {
  1134. struct ieee80211_local *local = wiphy_priv(wiphy);
  1135. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1136. switch (ieee80211_get_channel_mode(local, sdata)) {
  1137. case CHAN_MODE_HOPPING:
  1138. return -EBUSY;
  1139. case CHAN_MODE_FIXED:
  1140. if (!params->channel_fixed)
  1141. return -EBUSY;
  1142. if (local->oper_channel == params->channel)
  1143. break;
  1144. return -EBUSY;
  1145. case CHAN_MODE_UNDEFINED:
  1146. break;
  1147. }
  1148. return ieee80211_ibss_join(sdata, params);
  1149. }
  1150. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1151. {
  1152. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1153. return ieee80211_ibss_leave(sdata);
  1154. }
  1155. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1156. {
  1157. struct ieee80211_local *local = wiphy_priv(wiphy);
  1158. int err;
  1159. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1160. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1161. if (err)
  1162. return err;
  1163. }
  1164. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1165. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1166. if (err)
  1167. return err;
  1168. }
  1169. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1170. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1171. if (err)
  1172. return err;
  1173. }
  1174. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1175. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1176. if (changed & WIPHY_PARAM_RETRY_LONG)
  1177. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1178. if (changed &
  1179. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1180. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1181. return 0;
  1182. }
  1183. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1184. enum nl80211_tx_power_setting type, int mbm)
  1185. {
  1186. struct ieee80211_local *local = wiphy_priv(wiphy);
  1187. struct ieee80211_channel *chan = local->hw.conf.channel;
  1188. u32 changes = 0;
  1189. switch (type) {
  1190. case NL80211_TX_POWER_AUTOMATIC:
  1191. local->user_power_level = -1;
  1192. break;
  1193. case NL80211_TX_POWER_LIMITED:
  1194. if (mbm < 0 || (mbm % 100))
  1195. return -EOPNOTSUPP;
  1196. local->user_power_level = MBM_TO_DBM(mbm);
  1197. break;
  1198. case NL80211_TX_POWER_FIXED:
  1199. if (mbm < 0 || (mbm % 100))
  1200. return -EOPNOTSUPP;
  1201. /* TODO: move to cfg80211 when it knows the channel */
  1202. if (MBM_TO_DBM(mbm) > chan->max_power)
  1203. return -EINVAL;
  1204. local->user_power_level = MBM_TO_DBM(mbm);
  1205. break;
  1206. }
  1207. ieee80211_hw_config(local, changes);
  1208. return 0;
  1209. }
  1210. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1211. {
  1212. struct ieee80211_local *local = wiphy_priv(wiphy);
  1213. *dbm = local->hw.conf.power_level;
  1214. return 0;
  1215. }
  1216. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1217. const u8 *addr)
  1218. {
  1219. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1220. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1221. return 0;
  1222. }
  1223. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1224. {
  1225. struct ieee80211_local *local = wiphy_priv(wiphy);
  1226. drv_rfkill_poll(local);
  1227. }
  1228. #ifdef CONFIG_NL80211_TESTMODE
  1229. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1230. {
  1231. struct ieee80211_local *local = wiphy_priv(wiphy);
  1232. if (!local->ops->testmode_cmd)
  1233. return -EOPNOTSUPP;
  1234. return local->ops->testmode_cmd(&local->hw, data, len);
  1235. }
  1236. #endif
  1237. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1238. enum ieee80211_smps_mode smps_mode)
  1239. {
  1240. const u8 *ap;
  1241. enum ieee80211_smps_mode old_req;
  1242. int err;
  1243. old_req = sdata->u.mgd.req_smps;
  1244. sdata->u.mgd.req_smps = smps_mode;
  1245. if (old_req == smps_mode &&
  1246. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1247. return 0;
  1248. /*
  1249. * If not associated, or current association is not an HT
  1250. * association, there's no need to send an action frame.
  1251. */
  1252. if (!sdata->u.mgd.associated ||
  1253. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1254. mutex_lock(&sdata->local->iflist_mtx);
  1255. ieee80211_recalc_smps(sdata->local);
  1256. mutex_unlock(&sdata->local->iflist_mtx);
  1257. return 0;
  1258. }
  1259. ap = sdata->u.mgd.associated->bssid;
  1260. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1261. if (sdata->u.mgd.powersave)
  1262. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1263. else
  1264. smps_mode = IEEE80211_SMPS_OFF;
  1265. }
  1266. /* send SM PS frame to AP */
  1267. err = ieee80211_send_smps_action(sdata, smps_mode,
  1268. ap, ap);
  1269. if (err)
  1270. sdata->u.mgd.req_smps = old_req;
  1271. return err;
  1272. }
  1273. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1274. bool enabled, int timeout)
  1275. {
  1276. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1277. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1278. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1279. return -EOPNOTSUPP;
  1280. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1281. return -EOPNOTSUPP;
  1282. if (enabled == sdata->u.mgd.powersave &&
  1283. timeout == local->dynamic_ps_forced_timeout)
  1284. return 0;
  1285. sdata->u.mgd.powersave = enabled;
  1286. local->dynamic_ps_forced_timeout = timeout;
  1287. /* no change, but if automatic follow powersave */
  1288. mutex_lock(&sdata->u.mgd.mtx);
  1289. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1290. mutex_unlock(&sdata->u.mgd.mtx);
  1291. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1292. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1293. ieee80211_recalc_ps(local, -1);
  1294. return 0;
  1295. }
  1296. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1297. struct net_device *dev,
  1298. s32 rssi_thold, u32 rssi_hyst)
  1299. {
  1300. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1301. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1302. struct ieee80211_vif *vif = &sdata->vif;
  1303. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1304. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1305. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1306. return 0;
  1307. bss_conf->cqm_rssi_thold = rssi_thold;
  1308. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1309. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1310. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1311. return -EOPNOTSUPP;
  1312. return 0;
  1313. }
  1314. /* tell the driver upon association, unless already associated */
  1315. if (sdata->u.mgd.associated)
  1316. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1317. return 0;
  1318. }
  1319. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1320. struct net_device *dev,
  1321. const u8 *addr,
  1322. const struct cfg80211_bitrate_mask *mask)
  1323. {
  1324. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1325. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1326. int i;
  1327. /*
  1328. * This _could_ be supported by providing a hook for
  1329. * drivers for this function, but at this point it
  1330. * doesn't seem worth bothering.
  1331. */
  1332. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  1333. return -EOPNOTSUPP;
  1334. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1335. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1336. return 0;
  1337. }
  1338. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1339. struct net_device *dev,
  1340. struct ieee80211_channel *chan,
  1341. enum nl80211_channel_type chantype,
  1342. unsigned int duration, u64 *cookie)
  1343. {
  1344. int ret;
  1345. u32 random_cookie;
  1346. lockdep_assert_held(&local->mtx);
  1347. if (local->hw_roc_cookie)
  1348. return -EBUSY;
  1349. /* must be nonzero */
  1350. random_cookie = random32() | 1;
  1351. *cookie = random_cookie;
  1352. local->hw_roc_dev = dev;
  1353. local->hw_roc_cookie = random_cookie;
  1354. local->hw_roc_channel = chan;
  1355. local->hw_roc_channel_type = chantype;
  1356. local->hw_roc_duration = duration;
  1357. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1358. if (ret) {
  1359. local->hw_roc_channel = NULL;
  1360. local->hw_roc_cookie = 0;
  1361. }
  1362. return ret;
  1363. }
  1364. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1365. struct net_device *dev,
  1366. struct ieee80211_channel *chan,
  1367. enum nl80211_channel_type channel_type,
  1368. unsigned int duration,
  1369. u64 *cookie)
  1370. {
  1371. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1372. struct ieee80211_local *local = sdata->local;
  1373. if (local->ops->remain_on_channel) {
  1374. int ret;
  1375. mutex_lock(&local->mtx);
  1376. ret = ieee80211_remain_on_channel_hw(local, dev,
  1377. chan, channel_type,
  1378. duration, cookie);
  1379. local->hw_roc_for_tx = false;
  1380. mutex_unlock(&local->mtx);
  1381. return ret;
  1382. }
  1383. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1384. duration, cookie);
  1385. }
  1386. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1387. u64 cookie)
  1388. {
  1389. int ret;
  1390. lockdep_assert_held(&local->mtx);
  1391. if (local->hw_roc_cookie != cookie)
  1392. return -ENOENT;
  1393. ret = drv_cancel_remain_on_channel(local);
  1394. if (ret)
  1395. return ret;
  1396. local->hw_roc_cookie = 0;
  1397. local->hw_roc_channel = NULL;
  1398. ieee80211_recalc_idle(local);
  1399. return 0;
  1400. }
  1401. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1402. struct net_device *dev,
  1403. u64 cookie)
  1404. {
  1405. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1406. struct ieee80211_local *local = sdata->local;
  1407. if (local->ops->cancel_remain_on_channel) {
  1408. int ret;
  1409. mutex_lock(&local->mtx);
  1410. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1411. mutex_unlock(&local->mtx);
  1412. return ret;
  1413. }
  1414. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1415. }
  1416. static enum work_done_result
  1417. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1418. {
  1419. /*
  1420. * Use the data embedded in the work struct for reporting
  1421. * here so if the driver mangled the SKB before dropping
  1422. * it (which is the only way we really should get here)
  1423. * then we don't report mangled data.
  1424. *
  1425. * If there was no wait time, then by the time we get here
  1426. * the driver will likely not have reported the status yet,
  1427. * so in that case userspace will have to deal with it.
  1428. */
  1429. if (wk->offchan_tx.wait && wk->offchan_tx.frame)
  1430. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1431. (unsigned long) wk->offchan_tx.frame,
  1432. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1433. return WORK_DONE_DESTROY;
  1434. }
  1435. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1436. struct ieee80211_channel *chan, bool offchan,
  1437. enum nl80211_channel_type channel_type,
  1438. bool channel_type_valid, unsigned int wait,
  1439. const u8 *buf, size_t len, u64 *cookie)
  1440. {
  1441. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1442. struct ieee80211_local *local = sdata->local;
  1443. struct sk_buff *skb;
  1444. struct sta_info *sta;
  1445. struct ieee80211_work *wk;
  1446. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1447. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1448. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1449. bool is_offchan = false;
  1450. /* Check that we are on the requested channel for transmission */
  1451. if (chan != local->tmp_channel &&
  1452. chan != local->oper_channel)
  1453. is_offchan = true;
  1454. if (channel_type_valid &&
  1455. (channel_type != local->tmp_channel_type &&
  1456. channel_type != local->_oper_channel_type))
  1457. is_offchan = true;
  1458. if (chan == local->hw_roc_channel) {
  1459. /* TODO: check channel type? */
  1460. is_offchan = false;
  1461. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1462. }
  1463. if (is_offchan && !offchan)
  1464. return -EBUSY;
  1465. switch (sdata->vif.type) {
  1466. case NL80211_IFTYPE_ADHOC:
  1467. case NL80211_IFTYPE_AP:
  1468. case NL80211_IFTYPE_AP_VLAN:
  1469. case NL80211_IFTYPE_P2P_GO:
  1470. case NL80211_IFTYPE_MESH_POINT:
  1471. if (!ieee80211_is_action(mgmt->frame_control) ||
  1472. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1473. break;
  1474. rcu_read_lock();
  1475. sta = sta_info_get(sdata, mgmt->da);
  1476. rcu_read_unlock();
  1477. if (!sta)
  1478. return -ENOLINK;
  1479. break;
  1480. case NL80211_IFTYPE_STATION:
  1481. case NL80211_IFTYPE_P2P_CLIENT:
  1482. break;
  1483. default:
  1484. return -EOPNOTSUPP;
  1485. }
  1486. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1487. if (!skb)
  1488. return -ENOMEM;
  1489. skb_reserve(skb, local->hw.extra_tx_headroom);
  1490. memcpy(skb_put(skb, len), buf, len);
  1491. IEEE80211_SKB_CB(skb)->flags = flags;
  1492. skb->dev = sdata->dev;
  1493. *cookie = (unsigned long) skb;
  1494. if (is_offchan && local->ops->offchannel_tx) {
  1495. int ret;
  1496. IEEE80211_SKB_CB(skb)->band = chan->band;
  1497. mutex_lock(&local->mtx);
  1498. if (local->hw_offchan_tx_cookie) {
  1499. mutex_unlock(&local->mtx);
  1500. return -EBUSY;
  1501. }
  1502. /* TODO: bitrate control, TX processing? */
  1503. ret = drv_offchannel_tx(local, skb, chan, channel_type, wait);
  1504. if (ret == 0)
  1505. local->hw_offchan_tx_cookie = *cookie;
  1506. mutex_unlock(&local->mtx);
  1507. /*
  1508. * Allow driver to return 1 to indicate it wants to have the
  1509. * frame transmitted with a remain_on_channel + regular TX.
  1510. */
  1511. if (ret != 1)
  1512. return ret;
  1513. }
  1514. if (is_offchan && local->ops->remain_on_channel) {
  1515. unsigned int duration;
  1516. int ret;
  1517. mutex_lock(&local->mtx);
  1518. /*
  1519. * If the duration is zero, then the driver
  1520. * wouldn't actually do anything. Set it to
  1521. * 100 for now.
  1522. *
  1523. * TODO: cancel the off-channel operation
  1524. * when we get the SKB's TX status and
  1525. * the wait time was zero before.
  1526. */
  1527. duration = 100;
  1528. if (wait)
  1529. duration = wait;
  1530. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1531. channel_type,
  1532. duration, cookie);
  1533. if (ret) {
  1534. kfree_skb(skb);
  1535. mutex_unlock(&local->mtx);
  1536. return ret;
  1537. }
  1538. local->hw_roc_for_tx = true;
  1539. local->hw_roc_duration = wait;
  1540. /*
  1541. * queue up frame for transmission after
  1542. * ieee80211_ready_on_channel call
  1543. */
  1544. /* modify cookie to prevent API mismatches */
  1545. *cookie ^= 2;
  1546. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1547. local->hw_roc_skb = skb;
  1548. local->hw_roc_skb_for_status = skb;
  1549. mutex_unlock(&local->mtx);
  1550. return 0;
  1551. }
  1552. /*
  1553. * Can transmit right away if the channel was the
  1554. * right one and there's no wait involved... If a
  1555. * wait is involved, we might otherwise not be on
  1556. * the right channel for long enough!
  1557. */
  1558. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1559. ieee80211_tx_skb(sdata, skb);
  1560. return 0;
  1561. }
  1562. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1563. if (!wk) {
  1564. kfree_skb(skb);
  1565. return -ENOMEM;
  1566. }
  1567. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1568. wk->chan = chan;
  1569. wk->chan_type = channel_type;
  1570. wk->sdata = sdata;
  1571. wk->done = ieee80211_offchan_tx_done;
  1572. wk->offchan_tx.frame = skb;
  1573. wk->offchan_tx.wait = wait;
  1574. wk->ie_len = len;
  1575. memcpy(wk->ie, buf, len);
  1576. ieee80211_add_work(wk);
  1577. return 0;
  1578. }
  1579. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1580. struct net_device *dev,
  1581. u64 cookie)
  1582. {
  1583. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1584. struct ieee80211_local *local = sdata->local;
  1585. struct ieee80211_work *wk;
  1586. int ret = -ENOENT;
  1587. mutex_lock(&local->mtx);
  1588. if (local->ops->offchannel_tx_cancel_wait &&
  1589. local->hw_offchan_tx_cookie == cookie) {
  1590. ret = drv_offchannel_tx_cancel_wait(local);
  1591. if (!ret)
  1592. local->hw_offchan_tx_cookie = 0;
  1593. mutex_unlock(&local->mtx);
  1594. return ret;
  1595. }
  1596. if (local->ops->cancel_remain_on_channel) {
  1597. cookie ^= 2;
  1598. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1599. if (ret == 0) {
  1600. kfree_skb(local->hw_roc_skb);
  1601. local->hw_roc_skb = NULL;
  1602. local->hw_roc_skb_for_status = NULL;
  1603. }
  1604. mutex_unlock(&local->mtx);
  1605. return ret;
  1606. }
  1607. list_for_each_entry(wk, &local->work_list, list) {
  1608. if (wk->sdata != sdata)
  1609. continue;
  1610. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1611. continue;
  1612. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1613. continue;
  1614. wk->timeout = jiffies;
  1615. ieee80211_queue_work(&local->hw, &local->work_work);
  1616. ret = 0;
  1617. break;
  1618. }
  1619. mutex_unlock(&local->mtx);
  1620. return ret;
  1621. }
  1622. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1623. struct net_device *dev,
  1624. u16 frame_type, bool reg)
  1625. {
  1626. struct ieee80211_local *local = wiphy_priv(wiphy);
  1627. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1628. return;
  1629. if (reg)
  1630. local->probe_req_reg++;
  1631. else
  1632. local->probe_req_reg--;
  1633. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1634. }
  1635. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1636. {
  1637. struct ieee80211_local *local = wiphy_priv(wiphy);
  1638. if (local->started)
  1639. return -EOPNOTSUPP;
  1640. return drv_set_antenna(local, tx_ant, rx_ant);
  1641. }
  1642. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1643. {
  1644. struct ieee80211_local *local = wiphy_priv(wiphy);
  1645. return drv_get_antenna(local, tx_ant, rx_ant);
  1646. }
  1647. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1648. {
  1649. struct ieee80211_local *local = wiphy_priv(wiphy);
  1650. return drv_set_ringparam(local, tx, rx);
  1651. }
  1652. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1653. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1654. {
  1655. struct ieee80211_local *local = wiphy_priv(wiphy);
  1656. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1657. }
  1658. struct cfg80211_ops mac80211_config_ops = {
  1659. .add_virtual_intf = ieee80211_add_iface,
  1660. .del_virtual_intf = ieee80211_del_iface,
  1661. .change_virtual_intf = ieee80211_change_iface,
  1662. .add_key = ieee80211_add_key,
  1663. .del_key = ieee80211_del_key,
  1664. .get_key = ieee80211_get_key,
  1665. .set_default_key = ieee80211_config_default_key,
  1666. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1667. .add_beacon = ieee80211_add_beacon,
  1668. .set_beacon = ieee80211_set_beacon,
  1669. .del_beacon = ieee80211_del_beacon,
  1670. .add_station = ieee80211_add_station,
  1671. .del_station = ieee80211_del_station,
  1672. .change_station = ieee80211_change_station,
  1673. .get_station = ieee80211_get_station,
  1674. .dump_station = ieee80211_dump_station,
  1675. .dump_survey = ieee80211_dump_survey,
  1676. #ifdef CONFIG_MAC80211_MESH
  1677. .add_mpath = ieee80211_add_mpath,
  1678. .del_mpath = ieee80211_del_mpath,
  1679. .change_mpath = ieee80211_change_mpath,
  1680. .get_mpath = ieee80211_get_mpath,
  1681. .dump_mpath = ieee80211_dump_mpath,
  1682. .update_mesh_config = ieee80211_update_mesh_config,
  1683. .get_mesh_config = ieee80211_get_mesh_config,
  1684. .join_mesh = ieee80211_join_mesh,
  1685. .leave_mesh = ieee80211_leave_mesh,
  1686. #endif
  1687. .change_bss = ieee80211_change_bss,
  1688. .set_txq_params = ieee80211_set_txq_params,
  1689. .set_channel = ieee80211_set_channel,
  1690. .suspend = ieee80211_suspend,
  1691. .resume = ieee80211_resume,
  1692. .scan = ieee80211_scan,
  1693. .auth = ieee80211_auth,
  1694. .assoc = ieee80211_assoc,
  1695. .deauth = ieee80211_deauth,
  1696. .disassoc = ieee80211_disassoc,
  1697. .join_ibss = ieee80211_join_ibss,
  1698. .leave_ibss = ieee80211_leave_ibss,
  1699. .set_wiphy_params = ieee80211_set_wiphy_params,
  1700. .set_tx_power = ieee80211_set_tx_power,
  1701. .get_tx_power = ieee80211_get_tx_power,
  1702. .set_wds_peer = ieee80211_set_wds_peer,
  1703. .rfkill_poll = ieee80211_rfkill_poll,
  1704. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1705. .set_power_mgmt = ieee80211_set_power_mgmt,
  1706. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1707. .remain_on_channel = ieee80211_remain_on_channel,
  1708. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1709. .mgmt_tx = ieee80211_mgmt_tx,
  1710. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  1711. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1712. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  1713. .set_antenna = ieee80211_set_antenna,
  1714. .get_antenna = ieee80211_get_antenna,
  1715. .set_ringparam = ieee80211_set_ringparam,
  1716. .get_ringparam = ieee80211_get_ringparam,
  1717. };