cfg.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130
  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;
  138. struct sta_info *sta;
  139. int ret;
  140. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  141. mutex_lock(&sdata->local->sta_mtx);
  142. if (mac_addr) {
  143. ret = -ENOENT;
  144. sta = sta_info_get_bss(sdata, mac_addr);
  145. if (!sta)
  146. goto out_unlock;
  147. if (pairwise) {
  148. if (sta->ptk) {
  149. ieee80211_key_free(sdata->local, sta->ptk);
  150. ret = 0;
  151. }
  152. } else {
  153. if (sta->gtk[key_idx]) {
  154. ieee80211_key_free(sdata->local,
  155. sta->gtk[key_idx]);
  156. ret = 0;
  157. }
  158. }
  159. goto out_unlock;
  160. }
  161. if (!sdata->keys[key_idx]) {
  162. ret = -ENOENT;
  163. goto out_unlock;
  164. }
  165. ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
  166. WARN_ON(sdata->keys[key_idx]);
  167. ret = 0;
  168. out_unlock:
  169. mutex_unlock(&sdata->local->sta_mtx);
  170. return ret;
  171. }
  172. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  173. u8 key_idx, bool pairwise, const u8 *mac_addr,
  174. void *cookie,
  175. void (*callback)(void *cookie,
  176. struct key_params *params))
  177. {
  178. struct ieee80211_sub_if_data *sdata;
  179. struct sta_info *sta = NULL;
  180. u8 seq[6] = {0};
  181. struct key_params params;
  182. struct ieee80211_key *key = NULL;
  183. u32 iv32;
  184. u16 iv16;
  185. int err = -ENOENT;
  186. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  187. rcu_read_lock();
  188. if (mac_addr) {
  189. sta = sta_info_get_bss(sdata, mac_addr);
  190. if (!sta)
  191. goto out;
  192. if (pairwise)
  193. key = sta->ptk;
  194. else if (key_idx < NUM_DEFAULT_KEYS)
  195. key = sta->gtk[key_idx];
  196. } else
  197. key = sdata->keys[key_idx];
  198. if (!key)
  199. goto out;
  200. memset(&params, 0, sizeof(params));
  201. params.cipher = key->conf.cipher;
  202. switch (key->conf.cipher) {
  203. case WLAN_CIPHER_SUITE_TKIP:
  204. iv32 = key->u.tkip.tx.iv32;
  205. iv16 = key->u.tkip.tx.iv16;
  206. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  207. drv_get_tkip_seq(sdata->local,
  208. key->conf.hw_key_idx,
  209. &iv32, &iv16);
  210. seq[0] = iv16 & 0xff;
  211. seq[1] = (iv16 >> 8) & 0xff;
  212. seq[2] = iv32 & 0xff;
  213. seq[3] = (iv32 >> 8) & 0xff;
  214. seq[4] = (iv32 >> 16) & 0xff;
  215. seq[5] = (iv32 >> 24) & 0xff;
  216. params.seq = seq;
  217. params.seq_len = 6;
  218. break;
  219. case WLAN_CIPHER_SUITE_CCMP:
  220. seq[0] = key->u.ccmp.tx_pn[5];
  221. seq[1] = key->u.ccmp.tx_pn[4];
  222. seq[2] = key->u.ccmp.tx_pn[3];
  223. seq[3] = key->u.ccmp.tx_pn[2];
  224. seq[4] = key->u.ccmp.tx_pn[1];
  225. seq[5] = key->u.ccmp.tx_pn[0];
  226. params.seq = seq;
  227. params.seq_len = 6;
  228. break;
  229. case WLAN_CIPHER_SUITE_AES_CMAC:
  230. seq[0] = key->u.aes_cmac.tx_pn[5];
  231. seq[1] = key->u.aes_cmac.tx_pn[4];
  232. seq[2] = key->u.aes_cmac.tx_pn[3];
  233. seq[3] = key->u.aes_cmac.tx_pn[2];
  234. seq[4] = key->u.aes_cmac.tx_pn[1];
  235. seq[5] = key->u.aes_cmac.tx_pn[0];
  236. params.seq = seq;
  237. params.seq_len = 6;
  238. break;
  239. }
  240. params.key = key->conf.key;
  241. params.key_len = key->conf.keylen;
  242. callback(cookie, &params);
  243. err = 0;
  244. out:
  245. rcu_read_unlock();
  246. return err;
  247. }
  248. static int ieee80211_config_default_key(struct wiphy *wiphy,
  249. struct net_device *dev,
  250. u8 key_idx, bool uni,
  251. bool multi)
  252. {
  253. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  254. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  255. return 0;
  256. }
  257. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  258. struct net_device *dev,
  259. u8 key_idx)
  260. {
  261. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  262. ieee80211_set_default_mgmt_key(sdata, key_idx);
  263. return 0;
  264. }
  265. static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
  266. {
  267. if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
  268. struct ieee80211_supported_band *sband;
  269. sband = sta->local->hw.wiphy->bands[
  270. sta->local->hw.conf.channel->band];
  271. rate->legacy = sband->bitrates[idx].bitrate;
  272. } else
  273. rate->mcs = idx;
  274. }
  275. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  276. {
  277. struct ieee80211_sub_if_data *sdata = sta->sdata;
  278. struct timespec uptime;
  279. sinfo->generation = sdata->local->sta_generation;
  280. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  281. STATION_INFO_RX_BYTES |
  282. STATION_INFO_TX_BYTES |
  283. STATION_INFO_RX_PACKETS |
  284. STATION_INFO_TX_PACKETS |
  285. STATION_INFO_TX_RETRIES |
  286. STATION_INFO_TX_FAILED |
  287. STATION_INFO_TX_BITRATE |
  288. STATION_INFO_RX_BITRATE |
  289. STATION_INFO_RX_DROP_MISC |
  290. STATION_INFO_BSS_PARAM |
  291. STATION_INFO_CONNECTED_TIME;
  292. do_posix_clock_monotonic_gettime(&uptime);
  293. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  294. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  295. sinfo->rx_bytes = sta->rx_bytes;
  296. sinfo->tx_bytes = sta->tx_bytes;
  297. sinfo->rx_packets = sta->rx_packets;
  298. sinfo->tx_packets = sta->tx_packets;
  299. sinfo->tx_retries = sta->tx_retry_count;
  300. sinfo->tx_failed = sta->tx_retry_failed;
  301. sinfo->rx_dropped_misc = sta->rx_dropped;
  302. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  303. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  304. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  305. sinfo->signal = (s8)sta->last_signal;
  306. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  307. }
  308. sinfo->txrate.flags = 0;
  309. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  310. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  311. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  312. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  313. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  314. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  315. rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
  316. sinfo->rxrate.flags = 0;
  317. if (sta->last_rx_rate_flag & RX_FLAG_HT)
  318. sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
  319. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  320. sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  321. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  322. sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  323. rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
  324. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  325. #ifdef CONFIG_MAC80211_MESH
  326. sinfo->filled |= STATION_INFO_LLID |
  327. STATION_INFO_PLID |
  328. STATION_INFO_PLINK_STATE;
  329. sinfo->llid = le16_to_cpu(sta->llid);
  330. sinfo->plid = le16_to_cpu(sta->plid);
  331. sinfo->plink_state = sta->plink_state;
  332. #endif
  333. }
  334. sinfo->bss_param.flags = 0;
  335. if (sdata->vif.bss_conf.use_cts_prot)
  336. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  337. if (sdata->vif.bss_conf.use_short_preamble)
  338. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  339. if (sdata->vif.bss_conf.use_short_slot)
  340. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  341. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  342. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  343. }
  344. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  345. int idx, u8 *mac, struct station_info *sinfo)
  346. {
  347. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  348. struct sta_info *sta;
  349. int ret = -ENOENT;
  350. rcu_read_lock();
  351. sta = sta_info_get_by_idx(sdata, idx);
  352. if (sta) {
  353. ret = 0;
  354. memcpy(mac, sta->sta.addr, ETH_ALEN);
  355. sta_set_sinfo(sta, sinfo);
  356. }
  357. rcu_read_unlock();
  358. return ret;
  359. }
  360. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  361. int idx, struct survey_info *survey)
  362. {
  363. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  364. return drv_get_survey(local, idx, survey);
  365. }
  366. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  367. u8 *mac, struct station_info *sinfo)
  368. {
  369. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  370. struct sta_info *sta;
  371. int ret = -ENOENT;
  372. rcu_read_lock();
  373. sta = sta_info_get_bss(sdata, mac);
  374. if (sta) {
  375. ret = 0;
  376. sta_set_sinfo(sta, sinfo);
  377. }
  378. rcu_read_unlock();
  379. return ret;
  380. }
  381. /*
  382. * This handles both adding a beacon and setting new beacon info
  383. */
  384. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  385. struct beacon_parameters *params)
  386. {
  387. struct beacon_data *new, *old;
  388. int new_head_len, new_tail_len;
  389. int size;
  390. int err = -EINVAL;
  391. old = sdata->u.ap.beacon;
  392. /* head must not be zero-length */
  393. if (params->head && !params->head_len)
  394. return -EINVAL;
  395. /*
  396. * This is a kludge. beacon interval should really be part
  397. * of the beacon information.
  398. */
  399. if (params->interval &&
  400. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  401. sdata->vif.bss_conf.beacon_int = params->interval;
  402. ieee80211_bss_info_change_notify(sdata,
  403. BSS_CHANGED_BEACON_INT);
  404. }
  405. /* Need to have a beacon head if we don't have one yet */
  406. if (!params->head && !old)
  407. return err;
  408. /* sorry, no way to start beaconing without dtim period */
  409. if (!params->dtim_period && !old)
  410. return err;
  411. /* new or old head? */
  412. if (params->head)
  413. new_head_len = params->head_len;
  414. else
  415. new_head_len = old->head_len;
  416. /* new or old tail? */
  417. if (params->tail || !old)
  418. /* params->tail_len will be zero for !params->tail */
  419. new_tail_len = params->tail_len;
  420. else
  421. new_tail_len = old->tail_len;
  422. size = sizeof(*new) + new_head_len + new_tail_len;
  423. new = kzalloc(size, GFP_KERNEL);
  424. if (!new)
  425. return -ENOMEM;
  426. /* start filling the new info now */
  427. /* new or old dtim period? */
  428. if (params->dtim_period)
  429. new->dtim_period = params->dtim_period;
  430. else
  431. new->dtim_period = old->dtim_period;
  432. /*
  433. * pointers go into the block we allocated,
  434. * memory is | beacon_data | head | tail |
  435. */
  436. new->head = ((u8 *) new) + sizeof(*new);
  437. new->tail = new->head + new_head_len;
  438. new->head_len = new_head_len;
  439. new->tail_len = new_tail_len;
  440. /* copy in head */
  441. if (params->head)
  442. memcpy(new->head, params->head, new_head_len);
  443. else
  444. memcpy(new->head, old->head, new_head_len);
  445. /* copy in optional tail */
  446. if (params->tail)
  447. memcpy(new->tail, params->tail, new_tail_len);
  448. else
  449. if (old)
  450. memcpy(new->tail, old->tail, new_tail_len);
  451. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  452. rcu_assign_pointer(sdata->u.ap.beacon, new);
  453. synchronize_rcu();
  454. kfree(old);
  455. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  456. BSS_CHANGED_BEACON);
  457. return 0;
  458. }
  459. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  460. struct beacon_parameters *params)
  461. {
  462. struct ieee80211_sub_if_data *sdata;
  463. struct beacon_data *old;
  464. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  465. old = sdata->u.ap.beacon;
  466. if (old)
  467. return -EALREADY;
  468. return ieee80211_config_beacon(sdata, params);
  469. }
  470. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  471. struct beacon_parameters *params)
  472. {
  473. struct ieee80211_sub_if_data *sdata;
  474. struct beacon_data *old;
  475. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  476. old = sdata->u.ap.beacon;
  477. if (!old)
  478. return -ENOENT;
  479. return ieee80211_config_beacon(sdata, params);
  480. }
  481. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  482. {
  483. struct ieee80211_sub_if_data *sdata;
  484. struct beacon_data *old;
  485. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  486. old = sdata->u.ap.beacon;
  487. if (!old)
  488. return -ENOENT;
  489. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  490. synchronize_rcu();
  491. kfree(old);
  492. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  493. return 0;
  494. }
  495. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  496. struct iapp_layer2_update {
  497. u8 da[ETH_ALEN]; /* broadcast */
  498. u8 sa[ETH_ALEN]; /* STA addr */
  499. __be16 len; /* 6 */
  500. u8 dsap; /* 0 */
  501. u8 ssap; /* 0 */
  502. u8 control;
  503. u8 xid_info[3];
  504. } __packed;
  505. static void ieee80211_send_layer2_update(struct sta_info *sta)
  506. {
  507. struct iapp_layer2_update *msg;
  508. struct sk_buff *skb;
  509. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  510. * bridge devices */
  511. skb = dev_alloc_skb(sizeof(*msg));
  512. if (!skb)
  513. return;
  514. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  515. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  516. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  517. memset(msg->da, 0xff, ETH_ALEN);
  518. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  519. msg->len = htons(6);
  520. msg->dsap = 0;
  521. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  522. msg->control = 0xaf; /* XID response lsb.1111F101.
  523. * F=0 (no poll command; unsolicited frame) */
  524. msg->xid_info[0] = 0x81; /* XID format identifier */
  525. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  526. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  527. skb->dev = sta->sdata->dev;
  528. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  529. memset(skb->cb, 0, sizeof(skb->cb));
  530. netif_rx_ni(skb);
  531. }
  532. static void sta_apply_parameters(struct ieee80211_local *local,
  533. struct sta_info *sta,
  534. struct station_parameters *params)
  535. {
  536. unsigned long flags;
  537. u32 rates;
  538. int i, j;
  539. struct ieee80211_supported_band *sband;
  540. struct ieee80211_sub_if_data *sdata = sta->sdata;
  541. u32 mask, set;
  542. sband = local->hw.wiphy->bands[local->oper_channel->band];
  543. spin_lock_irqsave(&sta->flaglock, flags);
  544. mask = params->sta_flags_mask;
  545. set = params->sta_flags_set;
  546. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  547. sta->flags &= ~WLAN_STA_AUTHORIZED;
  548. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  549. sta->flags |= WLAN_STA_AUTHORIZED;
  550. }
  551. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  552. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  553. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  554. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  555. }
  556. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  557. sta->flags &= ~WLAN_STA_WME;
  558. if (set & BIT(NL80211_STA_FLAG_WME))
  559. sta->flags |= WLAN_STA_WME;
  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. /*
  573. * cfg80211 validates this (1-2007) and allows setting the AID
  574. * only when creating a new station entry
  575. */
  576. if (params->aid)
  577. sta->sta.aid = params->aid;
  578. /*
  579. * FIXME: updating the following information is racy when this
  580. * function is called from ieee80211_change_station().
  581. * However, all this information should be static so
  582. * maybe we should just reject attemps to change it.
  583. */
  584. if (params->listen_interval >= 0)
  585. sta->listen_interval = params->listen_interval;
  586. if (params->supported_rates) {
  587. rates = 0;
  588. for (i = 0; i < params->supported_rates_len; i++) {
  589. int rate = (params->supported_rates[i] & 0x7f) * 5;
  590. for (j = 0; j < sband->n_bitrates; j++) {
  591. if (sband->bitrates[j].bitrate == rate)
  592. rates |= BIT(j);
  593. }
  594. }
  595. sta->sta.supp_rates[local->oper_channel->band] = rates;
  596. }
  597. if (params->ht_capa)
  598. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  599. params->ht_capa,
  600. &sta->sta.ht_cap);
  601. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  602. if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
  603. switch (params->plink_state) {
  604. case PLINK_LISTEN:
  605. case PLINK_ESTAB:
  606. case PLINK_BLOCKED:
  607. sta->plink_state = params->plink_state;
  608. break;
  609. default:
  610. /* nothing */
  611. break;
  612. }
  613. else
  614. switch (params->plink_action) {
  615. case PLINK_ACTION_OPEN:
  616. mesh_plink_open(sta);
  617. break;
  618. case PLINK_ACTION_BLOCK:
  619. mesh_plink_block(sta);
  620. break;
  621. }
  622. }
  623. }
  624. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  625. u8 *mac, struct station_parameters *params)
  626. {
  627. struct ieee80211_local *local = wiphy_priv(wiphy);
  628. struct sta_info *sta;
  629. struct ieee80211_sub_if_data *sdata;
  630. int err;
  631. int layer2_update;
  632. if (params->vlan) {
  633. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  634. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  635. sdata->vif.type != NL80211_IFTYPE_AP)
  636. return -EINVAL;
  637. } else
  638. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  639. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  640. return -EINVAL;
  641. if (is_multicast_ether_addr(mac))
  642. return -EINVAL;
  643. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  644. if (!sta)
  645. return -ENOMEM;
  646. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  647. sta_apply_parameters(local, sta, params);
  648. rate_control_rate_init(sta);
  649. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  650. sdata->vif.type == NL80211_IFTYPE_AP;
  651. err = sta_info_insert_rcu(sta);
  652. if (err) {
  653. rcu_read_unlock();
  654. return err;
  655. }
  656. if (layer2_update)
  657. ieee80211_send_layer2_update(sta);
  658. rcu_read_unlock();
  659. return 0;
  660. }
  661. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  662. u8 *mac)
  663. {
  664. struct ieee80211_local *local = wiphy_priv(wiphy);
  665. struct ieee80211_sub_if_data *sdata;
  666. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  667. if (mac)
  668. return sta_info_destroy_addr_bss(sdata, mac);
  669. sta_info_flush(local, sdata);
  670. return 0;
  671. }
  672. static int ieee80211_change_station(struct wiphy *wiphy,
  673. struct net_device *dev,
  674. u8 *mac,
  675. struct station_parameters *params)
  676. {
  677. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  678. struct ieee80211_local *local = wiphy_priv(wiphy);
  679. struct sta_info *sta;
  680. struct ieee80211_sub_if_data *vlansdata;
  681. rcu_read_lock();
  682. sta = sta_info_get_bss(sdata, mac);
  683. if (!sta) {
  684. rcu_read_unlock();
  685. return -ENOENT;
  686. }
  687. if (params->vlan && params->vlan != sta->sdata->dev) {
  688. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  689. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  690. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  691. rcu_read_unlock();
  692. return -EINVAL;
  693. }
  694. if (params->vlan->ieee80211_ptr->use_4addr) {
  695. if (vlansdata->u.vlan.sta) {
  696. rcu_read_unlock();
  697. return -EBUSY;
  698. }
  699. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  700. }
  701. sta->sdata = vlansdata;
  702. ieee80211_send_layer2_update(sta);
  703. }
  704. sta_apply_parameters(local, sta, params);
  705. rcu_read_unlock();
  706. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  707. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  708. ieee80211_recalc_ps(local, -1);
  709. return 0;
  710. }
  711. #ifdef CONFIG_MAC80211_MESH
  712. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  713. u8 *dst, u8 *next_hop)
  714. {
  715. struct ieee80211_sub_if_data *sdata;
  716. struct mesh_path *mpath;
  717. struct sta_info *sta;
  718. int err;
  719. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  720. rcu_read_lock();
  721. sta = sta_info_get(sdata, next_hop);
  722. if (!sta) {
  723. rcu_read_unlock();
  724. return -ENOENT;
  725. }
  726. err = mesh_path_add(dst, sdata);
  727. if (err) {
  728. rcu_read_unlock();
  729. return err;
  730. }
  731. mpath = mesh_path_lookup(dst, sdata);
  732. if (!mpath) {
  733. rcu_read_unlock();
  734. return -ENXIO;
  735. }
  736. mesh_path_fix_nexthop(mpath, sta);
  737. rcu_read_unlock();
  738. return 0;
  739. }
  740. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  741. u8 *dst)
  742. {
  743. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  744. if (dst)
  745. return mesh_path_del(dst, sdata);
  746. mesh_path_flush(sdata);
  747. return 0;
  748. }
  749. static int ieee80211_change_mpath(struct wiphy *wiphy,
  750. struct net_device *dev,
  751. u8 *dst, u8 *next_hop)
  752. {
  753. struct ieee80211_sub_if_data *sdata;
  754. struct mesh_path *mpath;
  755. struct sta_info *sta;
  756. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  757. rcu_read_lock();
  758. sta = sta_info_get(sdata, next_hop);
  759. if (!sta) {
  760. rcu_read_unlock();
  761. return -ENOENT;
  762. }
  763. mpath = mesh_path_lookup(dst, sdata);
  764. if (!mpath) {
  765. rcu_read_unlock();
  766. return -ENOENT;
  767. }
  768. mesh_path_fix_nexthop(mpath, sta);
  769. rcu_read_unlock();
  770. return 0;
  771. }
  772. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  773. struct mpath_info *pinfo)
  774. {
  775. if (mpath->next_hop)
  776. memcpy(next_hop, mpath->next_hop->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 ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1120. struct cfg80211_auth_request *req)
  1121. {
  1122. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1123. }
  1124. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1125. struct cfg80211_assoc_request *req)
  1126. {
  1127. struct ieee80211_local *local = wiphy_priv(wiphy);
  1128. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1129. switch (ieee80211_get_channel_mode(local, sdata)) {
  1130. case CHAN_MODE_HOPPING:
  1131. return -EBUSY;
  1132. case CHAN_MODE_FIXED:
  1133. if (local->oper_channel == req->bss->channel)
  1134. break;
  1135. return -EBUSY;
  1136. case CHAN_MODE_UNDEFINED:
  1137. break;
  1138. }
  1139. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1140. }
  1141. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1142. struct cfg80211_deauth_request *req,
  1143. void *cookie)
  1144. {
  1145. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1146. req, cookie);
  1147. }
  1148. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1149. struct cfg80211_disassoc_request *req,
  1150. void *cookie)
  1151. {
  1152. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1153. req, cookie);
  1154. }
  1155. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1156. struct cfg80211_ibss_params *params)
  1157. {
  1158. struct ieee80211_local *local = wiphy_priv(wiphy);
  1159. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1160. switch (ieee80211_get_channel_mode(local, sdata)) {
  1161. case CHAN_MODE_HOPPING:
  1162. return -EBUSY;
  1163. case CHAN_MODE_FIXED:
  1164. if (!params->channel_fixed)
  1165. return -EBUSY;
  1166. if (local->oper_channel == params->channel)
  1167. break;
  1168. return -EBUSY;
  1169. case CHAN_MODE_UNDEFINED:
  1170. break;
  1171. }
  1172. return ieee80211_ibss_join(sdata, params);
  1173. }
  1174. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1175. {
  1176. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1177. return ieee80211_ibss_leave(sdata);
  1178. }
  1179. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1180. {
  1181. struct ieee80211_local *local = wiphy_priv(wiphy);
  1182. int err;
  1183. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1184. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1185. if (err)
  1186. return err;
  1187. }
  1188. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1189. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1190. if (err)
  1191. return err;
  1192. }
  1193. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1194. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1195. if (err)
  1196. return err;
  1197. }
  1198. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1199. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1200. if (changed & WIPHY_PARAM_RETRY_LONG)
  1201. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1202. if (changed &
  1203. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1204. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1205. return 0;
  1206. }
  1207. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1208. enum nl80211_tx_power_setting type, int mbm)
  1209. {
  1210. struct ieee80211_local *local = wiphy_priv(wiphy);
  1211. struct ieee80211_channel *chan = local->hw.conf.channel;
  1212. u32 changes = 0;
  1213. switch (type) {
  1214. case NL80211_TX_POWER_AUTOMATIC:
  1215. local->user_power_level = -1;
  1216. break;
  1217. case NL80211_TX_POWER_LIMITED:
  1218. if (mbm < 0 || (mbm % 100))
  1219. return -EOPNOTSUPP;
  1220. local->user_power_level = MBM_TO_DBM(mbm);
  1221. break;
  1222. case NL80211_TX_POWER_FIXED:
  1223. if (mbm < 0 || (mbm % 100))
  1224. return -EOPNOTSUPP;
  1225. /* TODO: move to cfg80211 when it knows the channel */
  1226. if (MBM_TO_DBM(mbm) > chan->max_power)
  1227. return -EINVAL;
  1228. local->user_power_level = MBM_TO_DBM(mbm);
  1229. break;
  1230. }
  1231. ieee80211_hw_config(local, changes);
  1232. return 0;
  1233. }
  1234. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1235. {
  1236. struct ieee80211_local *local = wiphy_priv(wiphy);
  1237. *dbm = local->hw.conf.power_level;
  1238. return 0;
  1239. }
  1240. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1241. const u8 *addr)
  1242. {
  1243. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1244. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1245. return 0;
  1246. }
  1247. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1248. {
  1249. struct ieee80211_local *local = wiphy_priv(wiphy);
  1250. drv_rfkill_poll(local);
  1251. }
  1252. #ifdef CONFIG_NL80211_TESTMODE
  1253. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1254. {
  1255. struct ieee80211_local *local = wiphy_priv(wiphy);
  1256. if (!local->ops->testmode_cmd)
  1257. return -EOPNOTSUPP;
  1258. return local->ops->testmode_cmd(&local->hw, data, len);
  1259. }
  1260. #endif
  1261. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1262. enum ieee80211_smps_mode smps_mode)
  1263. {
  1264. const u8 *ap;
  1265. enum ieee80211_smps_mode old_req;
  1266. int err;
  1267. lockdep_assert_held(&sdata->u.mgd.mtx);
  1268. old_req = sdata->u.mgd.req_smps;
  1269. sdata->u.mgd.req_smps = smps_mode;
  1270. if (old_req == smps_mode &&
  1271. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1272. return 0;
  1273. /*
  1274. * If not associated, or current association is not an HT
  1275. * association, there's no need to send an action frame.
  1276. */
  1277. if (!sdata->u.mgd.associated ||
  1278. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1279. mutex_lock(&sdata->local->iflist_mtx);
  1280. ieee80211_recalc_smps(sdata->local);
  1281. mutex_unlock(&sdata->local->iflist_mtx);
  1282. return 0;
  1283. }
  1284. ap = sdata->u.mgd.associated->bssid;
  1285. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1286. if (sdata->u.mgd.powersave)
  1287. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1288. else
  1289. smps_mode = IEEE80211_SMPS_OFF;
  1290. }
  1291. /* send SM PS frame to AP */
  1292. err = ieee80211_send_smps_action(sdata, smps_mode,
  1293. ap, ap);
  1294. if (err)
  1295. sdata->u.mgd.req_smps = old_req;
  1296. return err;
  1297. }
  1298. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1299. bool enabled, int timeout)
  1300. {
  1301. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1302. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1303. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1304. return -EOPNOTSUPP;
  1305. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1306. return -EOPNOTSUPP;
  1307. if (enabled == sdata->u.mgd.powersave &&
  1308. timeout == local->dynamic_ps_forced_timeout)
  1309. return 0;
  1310. sdata->u.mgd.powersave = enabled;
  1311. local->dynamic_ps_forced_timeout = timeout;
  1312. /* no change, but if automatic follow powersave */
  1313. mutex_lock(&sdata->u.mgd.mtx);
  1314. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1315. mutex_unlock(&sdata->u.mgd.mtx);
  1316. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1317. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1318. ieee80211_recalc_ps(local, -1);
  1319. return 0;
  1320. }
  1321. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1322. struct net_device *dev,
  1323. s32 rssi_thold, u32 rssi_hyst)
  1324. {
  1325. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1326. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1327. struct ieee80211_vif *vif = &sdata->vif;
  1328. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1329. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1330. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1331. return 0;
  1332. bss_conf->cqm_rssi_thold = rssi_thold;
  1333. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1334. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1335. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1336. return -EOPNOTSUPP;
  1337. return 0;
  1338. }
  1339. /* tell the driver upon association, unless already associated */
  1340. if (sdata->u.mgd.associated)
  1341. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1342. return 0;
  1343. }
  1344. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1345. struct net_device *dev,
  1346. const u8 *addr,
  1347. const struct cfg80211_bitrate_mask *mask)
  1348. {
  1349. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1350. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1351. int i, ret;
  1352. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1353. ret = drv_set_bitrate_mask(local, sdata, mask);
  1354. if (ret)
  1355. return ret;
  1356. }
  1357. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1358. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1359. return 0;
  1360. }
  1361. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1362. struct net_device *dev,
  1363. struct ieee80211_channel *chan,
  1364. enum nl80211_channel_type chantype,
  1365. unsigned int duration, u64 *cookie)
  1366. {
  1367. int ret;
  1368. u32 random_cookie;
  1369. lockdep_assert_held(&local->mtx);
  1370. if (local->hw_roc_cookie)
  1371. return -EBUSY;
  1372. /* must be nonzero */
  1373. random_cookie = random32() | 1;
  1374. *cookie = random_cookie;
  1375. local->hw_roc_dev = dev;
  1376. local->hw_roc_cookie = random_cookie;
  1377. local->hw_roc_channel = chan;
  1378. local->hw_roc_channel_type = chantype;
  1379. local->hw_roc_duration = duration;
  1380. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1381. if (ret) {
  1382. local->hw_roc_channel = NULL;
  1383. local->hw_roc_cookie = 0;
  1384. }
  1385. return ret;
  1386. }
  1387. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1388. struct net_device *dev,
  1389. struct ieee80211_channel *chan,
  1390. enum nl80211_channel_type channel_type,
  1391. unsigned int duration,
  1392. u64 *cookie)
  1393. {
  1394. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1395. struct ieee80211_local *local = sdata->local;
  1396. if (local->ops->remain_on_channel) {
  1397. int ret;
  1398. mutex_lock(&local->mtx);
  1399. ret = ieee80211_remain_on_channel_hw(local, dev,
  1400. chan, channel_type,
  1401. duration, cookie);
  1402. local->hw_roc_for_tx = false;
  1403. mutex_unlock(&local->mtx);
  1404. return ret;
  1405. }
  1406. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1407. duration, cookie);
  1408. }
  1409. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1410. u64 cookie)
  1411. {
  1412. int ret;
  1413. lockdep_assert_held(&local->mtx);
  1414. if (local->hw_roc_cookie != cookie)
  1415. return -ENOENT;
  1416. ret = drv_cancel_remain_on_channel(local);
  1417. if (ret)
  1418. return ret;
  1419. local->hw_roc_cookie = 0;
  1420. local->hw_roc_channel = NULL;
  1421. ieee80211_recalc_idle(local);
  1422. return 0;
  1423. }
  1424. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1425. struct net_device *dev,
  1426. u64 cookie)
  1427. {
  1428. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1429. struct ieee80211_local *local = sdata->local;
  1430. if (local->ops->cancel_remain_on_channel) {
  1431. int ret;
  1432. mutex_lock(&local->mtx);
  1433. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1434. mutex_unlock(&local->mtx);
  1435. return ret;
  1436. }
  1437. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1438. }
  1439. static enum work_done_result
  1440. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1441. {
  1442. /*
  1443. * Use the data embedded in the work struct for reporting
  1444. * here so if the driver mangled the SKB before dropping
  1445. * it (which is the only way we really should get here)
  1446. * then we don't report mangled data.
  1447. *
  1448. * If there was no wait time, then by the time we get here
  1449. * the driver will likely not have reported the status yet,
  1450. * so in that case userspace will have to deal with it.
  1451. */
  1452. if (wk->offchan_tx.wait && wk->offchan_tx.frame)
  1453. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1454. (unsigned long) wk->offchan_tx.frame,
  1455. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1456. return WORK_DONE_DESTROY;
  1457. }
  1458. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1459. struct ieee80211_channel *chan, bool offchan,
  1460. enum nl80211_channel_type channel_type,
  1461. bool channel_type_valid, unsigned int wait,
  1462. const u8 *buf, size_t len, u64 *cookie)
  1463. {
  1464. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1465. struct ieee80211_local *local = sdata->local;
  1466. struct sk_buff *skb;
  1467. struct sta_info *sta;
  1468. struct ieee80211_work *wk;
  1469. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1470. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1471. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1472. bool is_offchan = false;
  1473. /* Check that we are on the requested channel for transmission */
  1474. if (chan != local->tmp_channel &&
  1475. chan != local->oper_channel)
  1476. is_offchan = true;
  1477. if (channel_type_valid &&
  1478. (channel_type != local->tmp_channel_type &&
  1479. channel_type != local->_oper_channel_type))
  1480. is_offchan = true;
  1481. if (chan == local->hw_roc_channel) {
  1482. /* TODO: check channel type? */
  1483. is_offchan = false;
  1484. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1485. }
  1486. if (is_offchan && !offchan)
  1487. return -EBUSY;
  1488. switch (sdata->vif.type) {
  1489. case NL80211_IFTYPE_ADHOC:
  1490. case NL80211_IFTYPE_AP:
  1491. case NL80211_IFTYPE_AP_VLAN:
  1492. case NL80211_IFTYPE_P2P_GO:
  1493. case NL80211_IFTYPE_MESH_POINT:
  1494. if (!ieee80211_is_action(mgmt->frame_control) ||
  1495. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1496. break;
  1497. rcu_read_lock();
  1498. sta = sta_info_get(sdata, mgmt->da);
  1499. rcu_read_unlock();
  1500. if (!sta)
  1501. return -ENOLINK;
  1502. break;
  1503. case NL80211_IFTYPE_STATION:
  1504. case NL80211_IFTYPE_P2P_CLIENT:
  1505. break;
  1506. default:
  1507. return -EOPNOTSUPP;
  1508. }
  1509. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1510. if (!skb)
  1511. return -ENOMEM;
  1512. skb_reserve(skb, local->hw.extra_tx_headroom);
  1513. memcpy(skb_put(skb, len), buf, len);
  1514. IEEE80211_SKB_CB(skb)->flags = flags;
  1515. skb->dev = sdata->dev;
  1516. *cookie = (unsigned long) skb;
  1517. if (is_offchan && local->ops->offchannel_tx) {
  1518. int ret;
  1519. IEEE80211_SKB_CB(skb)->band = chan->band;
  1520. mutex_lock(&local->mtx);
  1521. if (local->hw_offchan_tx_cookie) {
  1522. mutex_unlock(&local->mtx);
  1523. return -EBUSY;
  1524. }
  1525. /* TODO: bitrate control, TX processing? */
  1526. ret = drv_offchannel_tx(local, skb, chan, channel_type, wait);
  1527. if (ret == 0)
  1528. local->hw_offchan_tx_cookie = *cookie;
  1529. mutex_unlock(&local->mtx);
  1530. /*
  1531. * Allow driver to return 1 to indicate it wants to have the
  1532. * frame transmitted with a remain_on_channel + regular TX.
  1533. */
  1534. if (ret != 1)
  1535. return ret;
  1536. }
  1537. if (is_offchan && local->ops->remain_on_channel) {
  1538. unsigned int duration;
  1539. int ret;
  1540. mutex_lock(&local->mtx);
  1541. /*
  1542. * If the duration is zero, then the driver
  1543. * wouldn't actually do anything. Set it to
  1544. * 100 for now.
  1545. *
  1546. * TODO: cancel the off-channel operation
  1547. * when we get the SKB's TX status and
  1548. * the wait time was zero before.
  1549. */
  1550. duration = 100;
  1551. if (wait)
  1552. duration = wait;
  1553. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1554. channel_type,
  1555. duration, cookie);
  1556. if (ret) {
  1557. kfree_skb(skb);
  1558. mutex_unlock(&local->mtx);
  1559. return ret;
  1560. }
  1561. local->hw_roc_for_tx = true;
  1562. local->hw_roc_duration = wait;
  1563. /*
  1564. * queue up frame for transmission after
  1565. * ieee80211_ready_on_channel call
  1566. */
  1567. /* modify cookie to prevent API mismatches */
  1568. *cookie ^= 2;
  1569. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1570. local->hw_roc_skb = skb;
  1571. local->hw_roc_skb_for_status = skb;
  1572. mutex_unlock(&local->mtx);
  1573. return 0;
  1574. }
  1575. /*
  1576. * Can transmit right away if the channel was the
  1577. * right one and there's no wait involved... If a
  1578. * wait is involved, we might otherwise not be on
  1579. * the right channel for long enough!
  1580. */
  1581. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1582. ieee80211_tx_skb(sdata, skb);
  1583. return 0;
  1584. }
  1585. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1586. if (!wk) {
  1587. kfree_skb(skb);
  1588. return -ENOMEM;
  1589. }
  1590. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1591. wk->chan = chan;
  1592. wk->chan_type = channel_type;
  1593. wk->sdata = sdata;
  1594. wk->done = ieee80211_offchan_tx_done;
  1595. wk->offchan_tx.frame = skb;
  1596. wk->offchan_tx.wait = wait;
  1597. wk->ie_len = len;
  1598. memcpy(wk->ie, buf, len);
  1599. ieee80211_add_work(wk);
  1600. return 0;
  1601. }
  1602. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1603. struct net_device *dev,
  1604. u64 cookie)
  1605. {
  1606. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1607. struct ieee80211_local *local = sdata->local;
  1608. struct ieee80211_work *wk;
  1609. int ret = -ENOENT;
  1610. mutex_lock(&local->mtx);
  1611. if (local->ops->offchannel_tx_cancel_wait &&
  1612. local->hw_offchan_tx_cookie == cookie) {
  1613. ret = drv_offchannel_tx_cancel_wait(local);
  1614. if (!ret)
  1615. local->hw_offchan_tx_cookie = 0;
  1616. mutex_unlock(&local->mtx);
  1617. return ret;
  1618. }
  1619. if (local->ops->cancel_remain_on_channel) {
  1620. cookie ^= 2;
  1621. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1622. if (ret == 0) {
  1623. kfree_skb(local->hw_roc_skb);
  1624. local->hw_roc_skb = NULL;
  1625. local->hw_roc_skb_for_status = NULL;
  1626. }
  1627. mutex_unlock(&local->mtx);
  1628. return ret;
  1629. }
  1630. list_for_each_entry(wk, &local->work_list, list) {
  1631. if (wk->sdata != sdata)
  1632. continue;
  1633. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1634. continue;
  1635. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1636. continue;
  1637. wk->timeout = jiffies;
  1638. ieee80211_queue_work(&local->hw, &local->work_work);
  1639. ret = 0;
  1640. break;
  1641. }
  1642. mutex_unlock(&local->mtx);
  1643. return ret;
  1644. }
  1645. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1646. struct net_device *dev,
  1647. u16 frame_type, bool reg)
  1648. {
  1649. struct ieee80211_local *local = wiphy_priv(wiphy);
  1650. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1651. return;
  1652. if (reg)
  1653. local->probe_req_reg++;
  1654. else
  1655. local->probe_req_reg--;
  1656. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1657. }
  1658. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1659. {
  1660. struct ieee80211_local *local = wiphy_priv(wiphy);
  1661. if (local->started)
  1662. return -EOPNOTSUPP;
  1663. return drv_set_antenna(local, tx_ant, rx_ant);
  1664. }
  1665. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1666. {
  1667. struct ieee80211_local *local = wiphy_priv(wiphy);
  1668. return drv_get_antenna(local, tx_ant, rx_ant);
  1669. }
  1670. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1671. {
  1672. struct ieee80211_local *local = wiphy_priv(wiphy);
  1673. return drv_set_ringparam(local, tx, rx);
  1674. }
  1675. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1676. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1677. {
  1678. struct ieee80211_local *local = wiphy_priv(wiphy);
  1679. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1680. }
  1681. struct cfg80211_ops mac80211_config_ops = {
  1682. .add_virtual_intf = ieee80211_add_iface,
  1683. .del_virtual_intf = ieee80211_del_iface,
  1684. .change_virtual_intf = ieee80211_change_iface,
  1685. .add_key = ieee80211_add_key,
  1686. .del_key = ieee80211_del_key,
  1687. .get_key = ieee80211_get_key,
  1688. .set_default_key = ieee80211_config_default_key,
  1689. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1690. .add_beacon = ieee80211_add_beacon,
  1691. .set_beacon = ieee80211_set_beacon,
  1692. .del_beacon = ieee80211_del_beacon,
  1693. .add_station = ieee80211_add_station,
  1694. .del_station = ieee80211_del_station,
  1695. .change_station = ieee80211_change_station,
  1696. .get_station = ieee80211_get_station,
  1697. .dump_station = ieee80211_dump_station,
  1698. .dump_survey = ieee80211_dump_survey,
  1699. #ifdef CONFIG_MAC80211_MESH
  1700. .add_mpath = ieee80211_add_mpath,
  1701. .del_mpath = ieee80211_del_mpath,
  1702. .change_mpath = ieee80211_change_mpath,
  1703. .get_mpath = ieee80211_get_mpath,
  1704. .dump_mpath = ieee80211_dump_mpath,
  1705. .update_mesh_config = ieee80211_update_mesh_config,
  1706. .get_mesh_config = ieee80211_get_mesh_config,
  1707. .join_mesh = ieee80211_join_mesh,
  1708. .leave_mesh = ieee80211_leave_mesh,
  1709. #endif
  1710. .change_bss = ieee80211_change_bss,
  1711. .set_txq_params = ieee80211_set_txq_params,
  1712. .set_channel = ieee80211_set_channel,
  1713. .suspend = ieee80211_suspend,
  1714. .resume = ieee80211_resume,
  1715. .scan = ieee80211_scan,
  1716. .auth = ieee80211_auth,
  1717. .assoc = ieee80211_assoc,
  1718. .deauth = ieee80211_deauth,
  1719. .disassoc = ieee80211_disassoc,
  1720. .join_ibss = ieee80211_join_ibss,
  1721. .leave_ibss = ieee80211_leave_ibss,
  1722. .set_wiphy_params = ieee80211_set_wiphy_params,
  1723. .set_tx_power = ieee80211_set_tx_power,
  1724. .get_tx_power = ieee80211_get_tx_power,
  1725. .set_wds_peer = ieee80211_set_wds_peer,
  1726. .rfkill_poll = ieee80211_rfkill_poll,
  1727. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1728. .set_power_mgmt = ieee80211_set_power_mgmt,
  1729. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1730. .remain_on_channel = ieee80211_remain_on_channel,
  1731. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1732. .mgmt_tx = ieee80211_mgmt_tx,
  1733. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  1734. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1735. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  1736. .set_antenna = ieee80211_set_antenna,
  1737. .get_antenna = ieee80211_get_antenna,
  1738. .set_ringparam = ieee80211_set_ringparam,
  1739. .get_ringparam = ieee80211_get_ringparam,
  1740. };