cfg.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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 int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  21. enum nl80211_iftype type, u32 *flags,
  22. struct vif_params *params)
  23. {
  24. struct ieee80211_local *local = wiphy_priv(wiphy);
  25. struct net_device *dev;
  26. struct ieee80211_sub_if_data *sdata;
  27. int err;
  28. err = ieee80211_if_add(local, name, &dev, type, params);
  29. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  30. return err;
  31. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  32. sdata->u.mntr_flags = *flags;
  33. return 0;
  34. }
  35. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  36. {
  37. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  38. return 0;
  39. }
  40. static int ieee80211_change_iface(struct wiphy *wiphy,
  41. struct net_device *dev,
  42. enum nl80211_iftype type, u32 *flags,
  43. struct vif_params *params)
  44. {
  45. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  46. int ret;
  47. ret = ieee80211_if_change_type(sdata, type);
  48. if (ret)
  49. return ret;
  50. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  51. ieee80211_sdata_set_mesh_id(sdata,
  52. params->mesh_id_len,
  53. params->mesh_id);
  54. if (type == NL80211_IFTYPE_AP_VLAN &&
  55. params && params->use_4addr == 0)
  56. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  57. else if (type == NL80211_IFTYPE_STATION &&
  58. params && params->use_4addr >= 0)
  59. sdata->u.mgd.use_4addr = params->use_4addr;
  60. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
  61. struct ieee80211_local *local = sdata->local;
  62. if (ieee80211_sdata_running(sdata)) {
  63. /*
  64. * Prohibit MONITOR_FLAG_COOK_FRAMES to be
  65. * changed while the interface is up.
  66. * Else we would need to add a lot of cruft
  67. * to update everything:
  68. * cooked_mntrs, monitor and all fif_* counters
  69. * reconfigure hardware
  70. */
  71. if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
  72. (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  73. return -EBUSY;
  74. ieee80211_adjust_monitor_flags(sdata, -1);
  75. sdata->u.mntr_flags = *flags;
  76. ieee80211_adjust_monitor_flags(sdata, 1);
  77. ieee80211_configure_filter(local);
  78. } else {
  79. /*
  80. * Because the interface is down, ieee80211_do_stop
  81. * and ieee80211_do_open take care of "everything"
  82. * mentioned in the comment above.
  83. */
  84. sdata->u.mntr_flags = *flags;
  85. }
  86. }
  87. return 0;
  88. }
  89. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  90. u8 key_idx, bool pairwise, const u8 *mac_addr,
  91. struct key_params *params)
  92. {
  93. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  94. struct sta_info *sta = NULL;
  95. struct ieee80211_key *key;
  96. int err;
  97. if (!ieee80211_sdata_running(sdata))
  98. return -ENETDOWN;
  99. /* reject WEP and TKIP keys if WEP failed to initialize */
  100. switch (params->cipher) {
  101. case WLAN_CIPHER_SUITE_WEP40:
  102. case WLAN_CIPHER_SUITE_TKIP:
  103. case WLAN_CIPHER_SUITE_WEP104:
  104. if (IS_ERR(sdata->local->wep_tx_tfm))
  105. return -EINVAL;
  106. break;
  107. default:
  108. break;
  109. }
  110. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  111. params->key, params->seq_len, params->seq);
  112. if (IS_ERR(key))
  113. return PTR_ERR(key);
  114. if (pairwise)
  115. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  116. mutex_lock(&sdata->local->sta_mtx);
  117. if (mac_addr) {
  118. sta = sta_info_get_bss(sdata, mac_addr);
  119. if (!sta) {
  120. ieee80211_key_free(sdata->local, key);
  121. err = -ENOENT;
  122. goto out_unlock;
  123. }
  124. }
  125. err = ieee80211_key_link(key, sdata, sta);
  126. if (err)
  127. ieee80211_key_free(sdata->local, key);
  128. out_unlock:
  129. mutex_unlock(&sdata->local->sta_mtx);
  130. return err;
  131. }
  132. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  133. u8 key_idx, bool pairwise, const u8 *mac_addr)
  134. {
  135. struct ieee80211_sub_if_data *sdata;
  136. struct sta_info *sta;
  137. int ret;
  138. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  139. mutex_lock(&sdata->local->sta_mtx);
  140. if (mac_addr) {
  141. ret = -ENOENT;
  142. sta = sta_info_get_bss(sdata, mac_addr);
  143. if (!sta)
  144. goto out_unlock;
  145. if (pairwise) {
  146. if (sta->ptk) {
  147. ieee80211_key_free(sdata->local, sta->ptk);
  148. ret = 0;
  149. }
  150. } else {
  151. if (sta->gtk[key_idx]) {
  152. ieee80211_key_free(sdata->local,
  153. sta->gtk[key_idx]);
  154. ret = 0;
  155. }
  156. }
  157. goto out_unlock;
  158. }
  159. if (!sdata->keys[key_idx]) {
  160. ret = -ENOENT;
  161. goto out_unlock;
  162. }
  163. ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
  164. WARN_ON(sdata->keys[key_idx]);
  165. ret = 0;
  166. out_unlock:
  167. mutex_unlock(&sdata->local->sta_mtx);
  168. return ret;
  169. }
  170. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  171. u8 key_idx, bool pairwise, const u8 *mac_addr,
  172. void *cookie,
  173. void (*callback)(void *cookie,
  174. struct key_params *params))
  175. {
  176. struct ieee80211_sub_if_data *sdata;
  177. struct sta_info *sta = NULL;
  178. u8 seq[6] = {0};
  179. struct key_params params;
  180. struct ieee80211_key *key = NULL;
  181. u32 iv32;
  182. u16 iv16;
  183. int err = -ENOENT;
  184. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  185. rcu_read_lock();
  186. if (mac_addr) {
  187. sta = sta_info_get_bss(sdata, mac_addr);
  188. if (!sta)
  189. goto out;
  190. if (pairwise)
  191. key = sta->ptk;
  192. else if (key_idx < NUM_DEFAULT_KEYS)
  193. key = sta->gtk[key_idx];
  194. } else
  195. key = sdata->keys[key_idx];
  196. if (!key)
  197. goto out;
  198. memset(&params, 0, sizeof(params));
  199. params.cipher = key->conf.cipher;
  200. switch (key->conf.cipher) {
  201. case WLAN_CIPHER_SUITE_TKIP:
  202. iv32 = key->u.tkip.tx.iv32;
  203. iv16 = key->u.tkip.tx.iv16;
  204. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  205. drv_get_tkip_seq(sdata->local,
  206. key->conf.hw_key_idx,
  207. &iv32, &iv16);
  208. seq[0] = iv16 & 0xff;
  209. seq[1] = (iv16 >> 8) & 0xff;
  210. seq[2] = iv32 & 0xff;
  211. seq[3] = (iv32 >> 8) & 0xff;
  212. seq[4] = (iv32 >> 16) & 0xff;
  213. seq[5] = (iv32 >> 24) & 0xff;
  214. params.seq = seq;
  215. params.seq_len = 6;
  216. break;
  217. case WLAN_CIPHER_SUITE_CCMP:
  218. seq[0] = key->u.ccmp.tx_pn[5];
  219. seq[1] = key->u.ccmp.tx_pn[4];
  220. seq[2] = key->u.ccmp.tx_pn[3];
  221. seq[3] = key->u.ccmp.tx_pn[2];
  222. seq[4] = key->u.ccmp.tx_pn[1];
  223. seq[5] = key->u.ccmp.tx_pn[0];
  224. params.seq = seq;
  225. params.seq_len = 6;
  226. break;
  227. case WLAN_CIPHER_SUITE_AES_CMAC:
  228. seq[0] = key->u.aes_cmac.tx_pn[5];
  229. seq[1] = key->u.aes_cmac.tx_pn[4];
  230. seq[2] = key->u.aes_cmac.tx_pn[3];
  231. seq[3] = key->u.aes_cmac.tx_pn[2];
  232. seq[4] = key->u.aes_cmac.tx_pn[1];
  233. seq[5] = key->u.aes_cmac.tx_pn[0];
  234. params.seq = seq;
  235. params.seq_len = 6;
  236. break;
  237. }
  238. params.key = key->conf.key;
  239. params.key_len = key->conf.keylen;
  240. callback(cookie, &params);
  241. err = 0;
  242. out:
  243. rcu_read_unlock();
  244. return err;
  245. }
  246. static int ieee80211_config_default_key(struct wiphy *wiphy,
  247. struct net_device *dev,
  248. u8 key_idx)
  249. {
  250. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  251. ieee80211_set_default_key(sdata, key_idx);
  252. return 0;
  253. }
  254. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  255. struct net_device *dev,
  256. u8 key_idx)
  257. {
  258. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  259. ieee80211_set_default_mgmt_key(sdata, key_idx);
  260. return 0;
  261. }
  262. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  263. {
  264. struct ieee80211_sub_if_data *sdata = sta->sdata;
  265. sinfo->generation = sdata->local->sta_generation;
  266. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  267. STATION_INFO_RX_BYTES |
  268. STATION_INFO_TX_BYTES |
  269. STATION_INFO_RX_PACKETS |
  270. STATION_INFO_TX_PACKETS |
  271. STATION_INFO_TX_RETRIES |
  272. STATION_INFO_TX_FAILED |
  273. STATION_INFO_TX_BITRATE;
  274. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  275. sinfo->rx_bytes = sta->rx_bytes;
  276. sinfo->tx_bytes = sta->tx_bytes;
  277. sinfo->rx_packets = sta->rx_packets;
  278. sinfo->tx_packets = sta->tx_packets;
  279. sinfo->tx_retries = sta->tx_retry_count;
  280. sinfo->tx_failed = sta->tx_retry_failed;
  281. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  282. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  283. sinfo->filled |= STATION_INFO_SIGNAL;
  284. sinfo->signal = (s8)sta->last_signal;
  285. }
  286. sinfo->txrate.flags = 0;
  287. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  288. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  289. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  290. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  291. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  292. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  293. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  294. struct ieee80211_supported_band *sband;
  295. sband = sta->local->hw.wiphy->bands[
  296. sta->local->hw.conf.channel->band];
  297. sinfo->txrate.legacy =
  298. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  299. } else
  300. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  301. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  302. #ifdef CONFIG_MAC80211_MESH
  303. sinfo->filled |= STATION_INFO_LLID |
  304. STATION_INFO_PLID |
  305. STATION_INFO_PLINK_STATE;
  306. sinfo->llid = le16_to_cpu(sta->llid);
  307. sinfo->plid = le16_to_cpu(sta->plid);
  308. sinfo->plink_state = sta->plink_state;
  309. #endif
  310. }
  311. }
  312. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  313. int idx, u8 *mac, struct station_info *sinfo)
  314. {
  315. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  316. struct sta_info *sta;
  317. int ret = -ENOENT;
  318. rcu_read_lock();
  319. sta = sta_info_get_by_idx(sdata, idx);
  320. if (sta) {
  321. ret = 0;
  322. memcpy(mac, sta->sta.addr, ETH_ALEN);
  323. sta_set_sinfo(sta, sinfo);
  324. }
  325. rcu_read_unlock();
  326. return ret;
  327. }
  328. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  329. int idx, struct survey_info *survey)
  330. {
  331. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  332. return drv_get_survey(local, idx, survey);
  333. }
  334. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  335. u8 *mac, struct station_info *sinfo)
  336. {
  337. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  338. struct sta_info *sta;
  339. int ret = -ENOENT;
  340. rcu_read_lock();
  341. sta = sta_info_get_bss(sdata, mac);
  342. if (sta) {
  343. ret = 0;
  344. sta_set_sinfo(sta, sinfo);
  345. }
  346. rcu_read_unlock();
  347. return ret;
  348. }
  349. /*
  350. * This handles both adding a beacon and setting new beacon info
  351. */
  352. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  353. struct beacon_parameters *params)
  354. {
  355. struct beacon_data *new, *old;
  356. int new_head_len, new_tail_len;
  357. int size;
  358. int err = -EINVAL;
  359. old = sdata->u.ap.beacon;
  360. /* head must not be zero-length */
  361. if (params->head && !params->head_len)
  362. return -EINVAL;
  363. /*
  364. * This is a kludge. beacon interval should really be part
  365. * of the beacon information.
  366. */
  367. if (params->interval &&
  368. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  369. sdata->vif.bss_conf.beacon_int = params->interval;
  370. ieee80211_bss_info_change_notify(sdata,
  371. BSS_CHANGED_BEACON_INT);
  372. }
  373. /* Need to have a beacon head if we don't have one yet */
  374. if (!params->head && !old)
  375. return err;
  376. /* sorry, no way to start beaconing without dtim period */
  377. if (!params->dtim_period && !old)
  378. return err;
  379. /* new or old head? */
  380. if (params->head)
  381. new_head_len = params->head_len;
  382. else
  383. new_head_len = old->head_len;
  384. /* new or old tail? */
  385. if (params->tail || !old)
  386. /* params->tail_len will be zero for !params->tail */
  387. new_tail_len = params->tail_len;
  388. else
  389. new_tail_len = old->tail_len;
  390. size = sizeof(*new) + new_head_len + new_tail_len;
  391. new = kzalloc(size, GFP_KERNEL);
  392. if (!new)
  393. return -ENOMEM;
  394. /* start filling the new info now */
  395. /* new or old dtim period? */
  396. if (params->dtim_period)
  397. new->dtim_period = params->dtim_period;
  398. else
  399. new->dtim_period = old->dtim_period;
  400. /*
  401. * pointers go into the block we allocated,
  402. * memory is | beacon_data | head | tail |
  403. */
  404. new->head = ((u8 *) new) + sizeof(*new);
  405. new->tail = new->head + new_head_len;
  406. new->head_len = new_head_len;
  407. new->tail_len = new_tail_len;
  408. /* copy in head */
  409. if (params->head)
  410. memcpy(new->head, params->head, new_head_len);
  411. else
  412. memcpy(new->head, old->head, new_head_len);
  413. /* copy in optional tail */
  414. if (params->tail)
  415. memcpy(new->tail, params->tail, new_tail_len);
  416. else
  417. if (old)
  418. memcpy(new->tail, old->tail, new_tail_len);
  419. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  420. rcu_assign_pointer(sdata->u.ap.beacon, new);
  421. synchronize_rcu();
  422. kfree(old);
  423. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  424. BSS_CHANGED_BEACON);
  425. return 0;
  426. }
  427. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  428. struct beacon_parameters *params)
  429. {
  430. struct ieee80211_sub_if_data *sdata;
  431. struct beacon_data *old;
  432. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  433. old = sdata->u.ap.beacon;
  434. if (old)
  435. return -EALREADY;
  436. return ieee80211_config_beacon(sdata, params);
  437. }
  438. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  439. struct beacon_parameters *params)
  440. {
  441. struct ieee80211_sub_if_data *sdata;
  442. struct beacon_data *old;
  443. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  444. old = sdata->u.ap.beacon;
  445. if (!old)
  446. return -ENOENT;
  447. return ieee80211_config_beacon(sdata, params);
  448. }
  449. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  450. {
  451. struct ieee80211_sub_if_data *sdata;
  452. struct beacon_data *old;
  453. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  454. old = sdata->u.ap.beacon;
  455. if (!old)
  456. return -ENOENT;
  457. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  458. synchronize_rcu();
  459. kfree(old);
  460. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  461. return 0;
  462. }
  463. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  464. struct iapp_layer2_update {
  465. u8 da[ETH_ALEN]; /* broadcast */
  466. u8 sa[ETH_ALEN]; /* STA addr */
  467. __be16 len; /* 6 */
  468. u8 dsap; /* 0 */
  469. u8 ssap; /* 0 */
  470. u8 control;
  471. u8 xid_info[3];
  472. } __packed;
  473. static void ieee80211_send_layer2_update(struct sta_info *sta)
  474. {
  475. struct iapp_layer2_update *msg;
  476. struct sk_buff *skb;
  477. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  478. * bridge devices */
  479. skb = dev_alloc_skb(sizeof(*msg));
  480. if (!skb)
  481. return;
  482. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  483. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  484. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  485. memset(msg->da, 0xff, ETH_ALEN);
  486. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  487. msg->len = htons(6);
  488. msg->dsap = 0;
  489. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  490. msg->control = 0xaf; /* XID response lsb.1111F101.
  491. * F=0 (no poll command; unsolicited frame) */
  492. msg->xid_info[0] = 0x81; /* XID format identifier */
  493. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  494. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  495. skb->dev = sta->sdata->dev;
  496. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  497. memset(skb->cb, 0, sizeof(skb->cb));
  498. netif_rx_ni(skb);
  499. }
  500. static void sta_apply_parameters(struct ieee80211_local *local,
  501. struct sta_info *sta,
  502. struct station_parameters *params)
  503. {
  504. unsigned long flags;
  505. u32 rates;
  506. int i, j;
  507. struct ieee80211_supported_band *sband;
  508. struct ieee80211_sub_if_data *sdata = sta->sdata;
  509. u32 mask, set;
  510. sband = local->hw.wiphy->bands[local->oper_channel->band];
  511. spin_lock_irqsave(&sta->flaglock, flags);
  512. mask = params->sta_flags_mask;
  513. set = params->sta_flags_set;
  514. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  515. sta->flags &= ~WLAN_STA_AUTHORIZED;
  516. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  517. sta->flags |= WLAN_STA_AUTHORIZED;
  518. }
  519. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  520. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  521. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  522. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  523. }
  524. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  525. sta->flags &= ~WLAN_STA_WME;
  526. if (set & BIT(NL80211_STA_FLAG_WME))
  527. sta->flags |= WLAN_STA_WME;
  528. }
  529. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  530. sta->flags &= ~WLAN_STA_MFP;
  531. if (set & BIT(NL80211_STA_FLAG_MFP))
  532. sta->flags |= WLAN_STA_MFP;
  533. }
  534. spin_unlock_irqrestore(&sta->flaglock, flags);
  535. /*
  536. * cfg80211 validates this (1-2007) and allows setting the AID
  537. * only when creating a new station entry
  538. */
  539. if (params->aid)
  540. sta->sta.aid = params->aid;
  541. /*
  542. * FIXME: updating the following information is racy when this
  543. * function is called from ieee80211_change_station().
  544. * However, all this information should be static so
  545. * maybe we should just reject attemps to change it.
  546. */
  547. if (params->listen_interval >= 0)
  548. sta->listen_interval = params->listen_interval;
  549. if (params->supported_rates) {
  550. rates = 0;
  551. for (i = 0; i < params->supported_rates_len; i++) {
  552. int rate = (params->supported_rates[i] & 0x7f) * 5;
  553. for (j = 0; j < sband->n_bitrates; j++) {
  554. if (sband->bitrates[j].bitrate == rate)
  555. rates |= BIT(j);
  556. }
  557. }
  558. sta->sta.supp_rates[local->oper_channel->band] = rates;
  559. }
  560. if (params->ht_capa)
  561. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  562. params->ht_capa,
  563. &sta->sta.ht_cap);
  564. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  565. switch (params->plink_action) {
  566. case PLINK_ACTION_OPEN:
  567. mesh_plink_open(sta);
  568. break;
  569. case PLINK_ACTION_BLOCK:
  570. mesh_plink_block(sta);
  571. break;
  572. }
  573. }
  574. }
  575. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  576. u8 *mac, struct station_parameters *params)
  577. {
  578. struct ieee80211_local *local = wiphy_priv(wiphy);
  579. struct sta_info *sta;
  580. struct ieee80211_sub_if_data *sdata;
  581. int err;
  582. int layer2_update;
  583. if (params->vlan) {
  584. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  585. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  586. sdata->vif.type != NL80211_IFTYPE_AP)
  587. return -EINVAL;
  588. } else
  589. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  590. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  591. return -EINVAL;
  592. if (is_multicast_ether_addr(mac))
  593. return -EINVAL;
  594. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  595. if (!sta)
  596. return -ENOMEM;
  597. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  598. sta_apply_parameters(local, sta, params);
  599. rate_control_rate_init(sta);
  600. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  601. sdata->vif.type == NL80211_IFTYPE_AP;
  602. err = sta_info_insert_rcu(sta);
  603. if (err) {
  604. rcu_read_unlock();
  605. return err;
  606. }
  607. if (layer2_update)
  608. ieee80211_send_layer2_update(sta);
  609. rcu_read_unlock();
  610. return 0;
  611. }
  612. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  613. u8 *mac)
  614. {
  615. struct ieee80211_local *local = wiphy_priv(wiphy);
  616. struct ieee80211_sub_if_data *sdata;
  617. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  618. if (mac)
  619. return sta_info_destroy_addr_bss(sdata, mac);
  620. sta_info_flush(local, sdata);
  621. return 0;
  622. }
  623. static int ieee80211_change_station(struct wiphy *wiphy,
  624. struct net_device *dev,
  625. u8 *mac,
  626. struct station_parameters *params)
  627. {
  628. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  629. struct ieee80211_local *local = wiphy_priv(wiphy);
  630. struct sta_info *sta;
  631. struct ieee80211_sub_if_data *vlansdata;
  632. rcu_read_lock();
  633. sta = sta_info_get_bss(sdata, mac);
  634. if (!sta) {
  635. rcu_read_unlock();
  636. return -ENOENT;
  637. }
  638. if (params->vlan && params->vlan != sta->sdata->dev) {
  639. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  640. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  641. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  642. rcu_read_unlock();
  643. return -EINVAL;
  644. }
  645. if (params->vlan->ieee80211_ptr->use_4addr) {
  646. if (vlansdata->u.vlan.sta) {
  647. rcu_read_unlock();
  648. return -EBUSY;
  649. }
  650. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  651. }
  652. sta->sdata = vlansdata;
  653. ieee80211_send_layer2_update(sta);
  654. }
  655. sta_apply_parameters(local, sta, params);
  656. rcu_read_unlock();
  657. return 0;
  658. }
  659. #ifdef CONFIG_MAC80211_MESH
  660. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  661. u8 *dst, u8 *next_hop)
  662. {
  663. struct ieee80211_sub_if_data *sdata;
  664. struct mesh_path *mpath;
  665. struct sta_info *sta;
  666. int err;
  667. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  668. rcu_read_lock();
  669. sta = sta_info_get(sdata, next_hop);
  670. if (!sta) {
  671. rcu_read_unlock();
  672. return -ENOENT;
  673. }
  674. err = mesh_path_add(dst, sdata);
  675. if (err) {
  676. rcu_read_unlock();
  677. return err;
  678. }
  679. mpath = mesh_path_lookup(dst, sdata);
  680. if (!mpath) {
  681. rcu_read_unlock();
  682. return -ENXIO;
  683. }
  684. mesh_path_fix_nexthop(mpath, sta);
  685. rcu_read_unlock();
  686. return 0;
  687. }
  688. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  689. u8 *dst)
  690. {
  691. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  692. if (dst)
  693. return mesh_path_del(dst, sdata);
  694. mesh_path_flush(sdata);
  695. return 0;
  696. }
  697. static int ieee80211_change_mpath(struct wiphy *wiphy,
  698. struct net_device *dev,
  699. u8 *dst, u8 *next_hop)
  700. {
  701. struct ieee80211_sub_if_data *sdata;
  702. struct mesh_path *mpath;
  703. struct sta_info *sta;
  704. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  705. rcu_read_lock();
  706. sta = sta_info_get(sdata, next_hop);
  707. if (!sta) {
  708. rcu_read_unlock();
  709. return -ENOENT;
  710. }
  711. mpath = mesh_path_lookup(dst, sdata);
  712. if (!mpath) {
  713. rcu_read_unlock();
  714. return -ENOENT;
  715. }
  716. mesh_path_fix_nexthop(mpath, sta);
  717. rcu_read_unlock();
  718. return 0;
  719. }
  720. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  721. struct mpath_info *pinfo)
  722. {
  723. if (mpath->next_hop)
  724. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  725. else
  726. memset(next_hop, 0, ETH_ALEN);
  727. pinfo->generation = mesh_paths_generation;
  728. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  729. MPATH_INFO_SN |
  730. MPATH_INFO_METRIC |
  731. MPATH_INFO_EXPTIME |
  732. MPATH_INFO_DISCOVERY_TIMEOUT |
  733. MPATH_INFO_DISCOVERY_RETRIES |
  734. MPATH_INFO_FLAGS;
  735. pinfo->frame_qlen = mpath->frame_queue.qlen;
  736. pinfo->sn = mpath->sn;
  737. pinfo->metric = mpath->metric;
  738. if (time_before(jiffies, mpath->exp_time))
  739. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  740. pinfo->discovery_timeout =
  741. jiffies_to_msecs(mpath->discovery_timeout);
  742. pinfo->discovery_retries = mpath->discovery_retries;
  743. pinfo->flags = 0;
  744. if (mpath->flags & MESH_PATH_ACTIVE)
  745. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  746. if (mpath->flags & MESH_PATH_RESOLVING)
  747. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  748. if (mpath->flags & MESH_PATH_SN_VALID)
  749. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  750. if (mpath->flags & MESH_PATH_FIXED)
  751. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  752. if (mpath->flags & MESH_PATH_RESOLVING)
  753. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  754. pinfo->flags = mpath->flags;
  755. }
  756. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  757. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  758. {
  759. struct ieee80211_sub_if_data *sdata;
  760. struct mesh_path *mpath;
  761. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  762. rcu_read_lock();
  763. mpath = mesh_path_lookup(dst, sdata);
  764. if (!mpath) {
  765. rcu_read_unlock();
  766. return -ENOENT;
  767. }
  768. memcpy(dst, mpath->dst, ETH_ALEN);
  769. mpath_set_pinfo(mpath, next_hop, pinfo);
  770. rcu_read_unlock();
  771. return 0;
  772. }
  773. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  774. int idx, u8 *dst, u8 *next_hop,
  775. struct mpath_info *pinfo)
  776. {
  777. struct ieee80211_sub_if_data *sdata;
  778. struct mesh_path *mpath;
  779. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  780. rcu_read_lock();
  781. mpath = mesh_path_lookup_by_idx(idx, sdata);
  782. if (!mpath) {
  783. rcu_read_unlock();
  784. return -ENOENT;
  785. }
  786. memcpy(dst, mpath->dst, ETH_ALEN);
  787. mpath_set_pinfo(mpath, next_hop, pinfo);
  788. rcu_read_unlock();
  789. return 0;
  790. }
  791. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  792. struct net_device *dev,
  793. struct mesh_config *conf)
  794. {
  795. struct ieee80211_sub_if_data *sdata;
  796. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  797. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  798. return 0;
  799. }
  800. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  801. {
  802. return (mask >> (parm-1)) & 0x1;
  803. }
  804. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  805. struct net_device *dev,
  806. const struct mesh_config *nconf, u32 mask)
  807. {
  808. struct mesh_config *conf;
  809. struct ieee80211_sub_if_data *sdata;
  810. struct ieee80211_if_mesh *ifmsh;
  811. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  812. ifmsh = &sdata->u.mesh;
  813. /* Set the config options which we are interested in setting */
  814. conf = &(sdata->u.mesh.mshcfg);
  815. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  816. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  817. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  818. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  819. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  820. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  821. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  822. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  823. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  824. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  825. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  826. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  827. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  828. conf->auto_open_plinks = nconf->auto_open_plinks;
  829. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  830. conf->dot11MeshHWMPmaxPREQretries =
  831. nconf->dot11MeshHWMPmaxPREQretries;
  832. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  833. conf->path_refresh_time = nconf->path_refresh_time;
  834. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  835. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  836. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  837. conf->dot11MeshHWMPactivePathTimeout =
  838. nconf->dot11MeshHWMPactivePathTimeout;
  839. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  840. conf->dot11MeshHWMPpreqMinInterval =
  841. nconf->dot11MeshHWMPpreqMinInterval;
  842. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  843. mask))
  844. conf->dot11MeshHWMPnetDiameterTraversalTime =
  845. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  846. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  847. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  848. ieee80211_mesh_root_setup(ifmsh);
  849. }
  850. return 0;
  851. }
  852. #endif
  853. static int ieee80211_change_bss(struct wiphy *wiphy,
  854. struct net_device *dev,
  855. struct bss_parameters *params)
  856. {
  857. struct ieee80211_sub_if_data *sdata;
  858. u32 changed = 0;
  859. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  860. if (params->use_cts_prot >= 0) {
  861. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  862. changed |= BSS_CHANGED_ERP_CTS_PROT;
  863. }
  864. if (params->use_short_preamble >= 0) {
  865. sdata->vif.bss_conf.use_short_preamble =
  866. params->use_short_preamble;
  867. changed |= BSS_CHANGED_ERP_PREAMBLE;
  868. }
  869. if (!sdata->vif.bss_conf.use_short_slot &&
  870. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  871. sdata->vif.bss_conf.use_short_slot = true;
  872. changed |= BSS_CHANGED_ERP_SLOT;
  873. }
  874. if (params->use_short_slot_time >= 0) {
  875. sdata->vif.bss_conf.use_short_slot =
  876. params->use_short_slot_time;
  877. changed |= BSS_CHANGED_ERP_SLOT;
  878. }
  879. if (params->basic_rates) {
  880. int i, j;
  881. u32 rates = 0;
  882. struct ieee80211_local *local = wiphy_priv(wiphy);
  883. struct ieee80211_supported_band *sband =
  884. wiphy->bands[local->oper_channel->band];
  885. for (i = 0; i < params->basic_rates_len; i++) {
  886. int rate = (params->basic_rates[i] & 0x7f) * 5;
  887. for (j = 0; j < sband->n_bitrates; j++) {
  888. if (sband->bitrates[j].bitrate == rate)
  889. rates |= BIT(j);
  890. }
  891. }
  892. sdata->vif.bss_conf.basic_rates = rates;
  893. changed |= BSS_CHANGED_BASIC_RATES;
  894. }
  895. if (params->ap_isolate >= 0) {
  896. if (params->ap_isolate)
  897. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  898. else
  899. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  900. }
  901. ieee80211_bss_info_change_notify(sdata, changed);
  902. return 0;
  903. }
  904. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  905. struct ieee80211_txq_params *params)
  906. {
  907. struct ieee80211_local *local = wiphy_priv(wiphy);
  908. struct ieee80211_tx_queue_params p;
  909. if (!local->ops->conf_tx)
  910. return -EOPNOTSUPP;
  911. memset(&p, 0, sizeof(p));
  912. p.aifs = params->aifs;
  913. p.cw_max = params->cwmax;
  914. p.cw_min = params->cwmin;
  915. p.txop = params->txop;
  916. /*
  917. * Setting tx queue params disables u-apsd because it's only
  918. * called in master mode.
  919. */
  920. p.uapsd = false;
  921. if (drv_conf_tx(local, params->queue, &p)) {
  922. wiphy_debug(local->hw.wiphy,
  923. "failed to set TX queue parameters for queue %d\n",
  924. params->queue);
  925. return -EINVAL;
  926. }
  927. return 0;
  928. }
  929. static int ieee80211_set_channel(struct wiphy *wiphy,
  930. struct net_device *netdev,
  931. struct ieee80211_channel *chan,
  932. enum nl80211_channel_type channel_type)
  933. {
  934. struct ieee80211_local *local = wiphy_priv(wiphy);
  935. struct ieee80211_sub_if_data *sdata = NULL;
  936. if (netdev)
  937. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  938. switch (ieee80211_get_channel_mode(local, NULL)) {
  939. case CHAN_MODE_HOPPING:
  940. return -EBUSY;
  941. case CHAN_MODE_FIXED:
  942. if (local->oper_channel != chan)
  943. return -EBUSY;
  944. if (!sdata && local->_oper_channel_type == channel_type)
  945. return 0;
  946. break;
  947. case CHAN_MODE_UNDEFINED:
  948. break;
  949. }
  950. local->oper_channel = chan;
  951. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  952. return -EBUSY;
  953. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  954. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
  955. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  956. return 0;
  957. }
  958. #ifdef CONFIG_PM
  959. static int ieee80211_suspend(struct wiphy *wiphy)
  960. {
  961. return __ieee80211_suspend(wiphy_priv(wiphy));
  962. }
  963. static int ieee80211_resume(struct wiphy *wiphy)
  964. {
  965. return __ieee80211_resume(wiphy_priv(wiphy));
  966. }
  967. #else
  968. #define ieee80211_suspend NULL
  969. #define ieee80211_resume NULL
  970. #endif
  971. static int ieee80211_scan(struct wiphy *wiphy,
  972. struct net_device *dev,
  973. struct cfg80211_scan_request *req)
  974. {
  975. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  976. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  977. case NL80211_IFTYPE_STATION:
  978. case NL80211_IFTYPE_ADHOC:
  979. case NL80211_IFTYPE_MESH_POINT:
  980. case NL80211_IFTYPE_P2P_CLIENT:
  981. break;
  982. case NL80211_IFTYPE_P2P_GO:
  983. if (sdata->local->ops->hw_scan)
  984. break;
  985. /* FIXME: implement NoA while scanning in software */
  986. return -EOPNOTSUPP;
  987. case NL80211_IFTYPE_AP:
  988. if (sdata->u.ap.beacon)
  989. return -EOPNOTSUPP;
  990. break;
  991. default:
  992. return -EOPNOTSUPP;
  993. }
  994. return ieee80211_request_scan(sdata, req);
  995. }
  996. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  997. struct cfg80211_auth_request *req)
  998. {
  999. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1000. }
  1001. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1002. struct cfg80211_assoc_request *req)
  1003. {
  1004. struct ieee80211_local *local = wiphy_priv(wiphy);
  1005. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1006. switch (ieee80211_get_channel_mode(local, sdata)) {
  1007. case CHAN_MODE_HOPPING:
  1008. return -EBUSY;
  1009. case CHAN_MODE_FIXED:
  1010. if (local->oper_channel == req->bss->channel)
  1011. break;
  1012. return -EBUSY;
  1013. case CHAN_MODE_UNDEFINED:
  1014. break;
  1015. }
  1016. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1017. }
  1018. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1019. struct cfg80211_deauth_request *req,
  1020. void *cookie)
  1021. {
  1022. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1023. req, cookie);
  1024. }
  1025. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1026. struct cfg80211_disassoc_request *req,
  1027. void *cookie)
  1028. {
  1029. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1030. req, cookie);
  1031. }
  1032. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1033. struct cfg80211_ibss_params *params)
  1034. {
  1035. struct ieee80211_local *local = wiphy_priv(wiphy);
  1036. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1037. switch (ieee80211_get_channel_mode(local, sdata)) {
  1038. case CHAN_MODE_HOPPING:
  1039. return -EBUSY;
  1040. case CHAN_MODE_FIXED:
  1041. if (!params->channel_fixed)
  1042. return -EBUSY;
  1043. if (local->oper_channel == params->channel)
  1044. break;
  1045. return -EBUSY;
  1046. case CHAN_MODE_UNDEFINED:
  1047. break;
  1048. }
  1049. return ieee80211_ibss_join(sdata, params);
  1050. }
  1051. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1052. {
  1053. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1054. return ieee80211_ibss_leave(sdata);
  1055. }
  1056. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1057. {
  1058. struct ieee80211_local *local = wiphy_priv(wiphy);
  1059. int err;
  1060. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1061. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1062. if (err)
  1063. return err;
  1064. }
  1065. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1066. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1067. if (err)
  1068. return err;
  1069. }
  1070. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1071. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1072. if (changed & WIPHY_PARAM_RETRY_LONG)
  1073. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1074. if (changed &
  1075. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1076. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1077. return 0;
  1078. }
  1079. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1080. enum nl80211_tx_power_setting type, int mbm)
  1081. {
  1082. struct ieee80211_local *local = wiphy_priv(wiphy);
  1083. struct ieee80211_channel *chan = local->hw.conf.channel;
  1084. u32 changes = 0;
  1085. switch (type) {
  1086. case NL80211_TX_POWER_AUTOMATIC:
  1087. local->user_power_level = -1;
  1088. break;
  1089. case NL80211_TX_POWER_LIMITED:
  1090. if (mbm < 0 || (mbm % 100))
  1091. return -EOPNOTSUPP;
  1092. local->user_power_level = MBM_TO_DBM(mbm);
  1093. break;
  1094. case NL80211_TX_POWER_FIXED:
  1095. if (mbm < 0 || (mbm % 100))
  1096. return -EOPNOTSUPP;
  1097. /* TODO: move to cfg80211 when it knows the channel */
  1098. if (MBM_TO_DBM(mbm) > chan->max_power)
  1099. return -EINVAL;
  1100. local->user_power_level = MBM_TO_DBM(mbm);
  1101. break;
  1102. }
  1103. ieee80211_hw_config(local, changes);
  1104. return 0;
  1105. }
  1106. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1107. {
  1108. struct ieee80211_local *local = wiphy_priv(wiphy);
  1109. *dbm = local->hw.conf.power_level;
  1110. return 0;
  1111. }
  1112. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1113. const u8 *addr)
  1114. {
  1115. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1116. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1117. return 0;
  1118. }
  1119. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1120. {
  1121. struct ieee80211_local *local = wiphy_priv(wiphy);
  1122. drv_rfkill_poll(local);
  1123. }
  1124. #ifdef CONFIG_NL80211_TESTMODE
  1125. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1126. {
  1127. struct ieee80211_local *local = wiphy_priv(wiphy);
  1128. if (!local->ops->testmode_cmd)
  1129. return -EOPNOTSUPP;
  1130. return local->ops->testmode_cmd(&local->hw, data, len);
  1131. }
  1132. #endif
  1133. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1134. enum ieee80211_smps_mode smps_mode)
  1135. {
  1136. const u8 *ap;
  1137. enum ieee80211_smps_mode old_req;
  1138. int err;
  1139. old_req = sdata->u.mgd.req_smps;
  1140. sdata->u.mgd.req_smps = smps_mode;
  1141. if (old_req == smps_mode &&
  1142. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1143. return 0;
  1144. /*
  1145. * If not associated, or current association is not an HT
  1146. * association, there's no need to send an action frame.
  1147. */
  1148. if (!sdata->u.mgd.associated ||
  1149. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1150. mutex_lock(&sdata->local->iflist_mtx);
  1151. ieee80211_recalc_smps(sdata->local);
  1152. mutex_unlock(&sdata->local->iflist_mtx);
  1153. return 0;
  1154. }
  1155. ap = sdata->u.mgd.associated->bssid;
  1156. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1157. if (sdata->u.mgd.powersave)
  1158. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1159. else
  1160. smps_mode = IEEE80211_SMPS_OFF;
  1161. }
  1162. /* send SM PS frame to AP */
  1163. err = ieee80211_send_smps_action(sdata, smps_mode,
  1164. ap, ap);
  1165. if (err)
  1166. sdata->u.mgd.req_smps = old_req;
  1167. return err;
  1168. }
  1169. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1170. bool enabled, int timeout)
  1171. {
  1172. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1173. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1174. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1175. return -EOPNOTSUPP;
  1176. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1177. return -EOPNOTSUPP;
  1178. if (enabled == sdata->u.mgd.powersave &&
  1179. timeout == local->dynamic_ps_forced_timeout)
  1180. return 0;
  1181. sdata->u.mgd.powersave = enabled;
  1182. local->dynamic_ps_forced_timeout = timeout;
  1183. /* no change, but if automatic follow powersave */
  1184. mutex_lock(&sdata->u.mgd.mtx);
  1185. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1186. mutex_unlock(&sdata->u.mgd.mtx);
  1187. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1188. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1189. ieee80211_recalc_ps(local, -1);
  1190. return 0;
  1191. }
  1192. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1193. struct net_device *dev,
  1194. s32 rssi_thold, u32 rssi_hyst)
  1195. {
  1196. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1197. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1198. struct ieee80211_vif *vif = &sdata->vif;
  1199. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1200. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1201. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1202. return 0;
  1203. bss_conf->cqm_rssi_thold = rssi_thold;
  1204. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1205. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1206. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1207. return -EOPNOTSUPP;
  1208. return 0;
  1209. }
  1210. /* tell the driver upon association, unless already associated */
  1211. if (sdata->u.mgd.associated)
  1212. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1213. return 0;
  1214. }
  1215. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1216. struct net_device *dev,
  1217. const u8 *addr,
  1218. const struct cfg80211_bitrate_mask *mask)
  1219. {
  1220. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1221. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1222. int i;
  1223. /*
  1224. * This _could_ be supported by providing a hook for
  1225. * drivers for this function, but at this point it
  1226. * doesn't seem worth bothering.
  1227. */
  1228. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  1229. return -EOPNOTSUPP;
  1230. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1231. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1232. return 0;
  1233. }
  1234. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1235. struct net_device *dev,
  1236. struct ieee80211_channel *chan,
  1237. enum nl80211_channel_type channel_type,
  1238. unsigned int duration,
  1239. u64 *cookie)
  1240. {
  1241. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1242. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1243. duration, cookie);
  1244. }
  1245. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1246. struct net_device *dev,
  1247. u64 cookie)
  1248. {
  1249. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1250. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1251. }
  1252. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1253. struct ieee80211_channel *chan,
  1254. enum nl80211_channel_type channel_type,
  1255. bool channel_type_valid,
  1256. const u8 *buf, size_t len, u64 *cookie)
  1257. {
  1258. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1259. struct ieee80211_local *local = sdata->local;
  1260. struct sk_buff *skb;
  1261. struct sta_info *sta;
  1262. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1263. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1264. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1265. /* Check that we are on the requested channel for transmission */
  1266. if (chan != local->tmp_channel &&
  1267. chan != local->oper_channel)
  1268. return -EBUSY;
  1269. if (channel_type_valid &&
  1270. (channel_type != local->tmp_channel_type &&
  1271. channel_type != local->_oper_channel_type))
  1272. return -EBUSY;
  1273. switch (sdata->vif.type) {
  1274. case NL80211_IFTYPE_ADHOC:
  1275. case NL80211_IFTYPE_AP:
  1276. case NL80211_IFTYPE_AP_VLAN:
  1277. case NL80211_IFTYPE_P2P_GO:
  1278. if (!ieee80211_is_action(mgmt->frame_control) ||
  1279. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1280. break;
  1281. rcu_read_lock();
  1282. sta = sta_info_get(sdata, mgmt->da);
  1283. rcu_read_unlock();
  1284. if (!sta)
  1285. return -ENOLINK;
  1286. break;
  1287. case NL80211_IFTYPE_STATION:
  1288. case NL80211_IFTYPE_P2P_CLIENT:
  1289. break;
  1290. default:
  1291. return -EOPNOTSUPP;
  1292. }
  1293. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1294. if (!skb)
  1295. return -ENOMEM;
  1296. skb_reserve(skb, local->hw.extra_tx_headroom);
  1297. memcpy(skb_put(skb, len), buf, len);
  1298. IEEE80211_SKB_CB(skb)->flags = flags;
  1299. skb->dev = sdata->dev;
  1300. ieee80211_tx_skb(sdata, skb);
  1301. *cookie = (unsigned long) skb;
  1302. return 0;
  1303. }
  1304. struct cfg80211_ops mac80211_config_ops = {
  1305. .add_virtual_intf = ieee80211_add_iface,
  1306. .del_virtual_intf = ieee80211_del_iface,
  1307. .change_virtual_intf = ieee80211_change_iface,
  1308. .add_key = ieee80211_add_key,
  1309. .del_key = ieee80211_del_key,
  1310. .get_key = ieee80211_get_key,
  1311. .set_default_key = ieee80211_config_default_key,
  1312. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1313. .add_beacon = ieee80211_add_beacon,
  1314. .set_beacon = ieee80211_set_beacon,
  1315. .del_beacon = ieee80211_del_beacon,
  1316. .add_station = ieee80211_add_station,
  1317. .del_station = ieee80211_del_station,
  1318. .change_station = ieee80211_change_station,
  1319. .get_station = ieee80211_get_station,
  1320. .dump_station = ieee80211_dump_station,
  1321. .dump_survey = ieee80211_dump_survey,
  1322. #ifdef CONFIG_MAC80211_MESH
  1323. .add_mpath = ieee80211_add_mpath,
  1324. .del_mpath = ieee80211_del_mpath,
  1325. .change_mpath = ieee80211_change_mpath,
  1326. .get_mpath = ieee80211_get_mpath,
  1327. .dump_mpath = ieee80211_dump_mpath,
  1328. .set_mesh_params = ieee80211_set_mesh_params,
  1329. .get_mesh_params = ieee80211_get_mesh_params,
  1330. #endif
  1331. .change_bss = ieee80211_change_bss,
  1332. .set_txq_params = ieee80211_set_txq_params,
  1333. .set_channel = ieee80211_set_channel,
  1334. .suspend = ieee80211_suspend,
  1335. .resume = ieee80211_resume,
  1336. .scan = ieee80211_scan,
  1337. .auth = ieee80211_auth,
  1338. .assoc = ieee80211_assoc,
  1339. .deauth = ieee80211_deauth,
  1340. .disassoc = ieee80211_disassoc,
  1341. .join_ibss = ieee80211_join_ibss,
  1342. .leave_ibss = ieee80211_leave_ibss,
  1343. .set_wiphy_params = ieee80211_set_wiphy_params,
  1344. .set_tx_power = ieee80211_set_tx_power,
  1345. .get_tx_power = ieee80211_get_tx_power,
  1346. .set_wds_peer = ieee80211_set_wds_peer,
  1347. .rfkill_poll = ieee80211_rfkill_poll,
  1348. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1349. .set_power_mgmt = ieee80211_set_power_mgmt,
  1350. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1351. .remain_on_channel = ieee80211_remain_on_channel,
  1352. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1353. .mgmt_tx = ieee80211_mgmt_tx,
  1354. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1355. };