cfg.c 55 KB

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