cfg.c 55 KB

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