cfg.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006, 2007 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 <net/net_namespace.h>
  12. #include <linux/rcupdate.h>
  13. #include <net/cfg80211.h>
  14. #include "ieee80211_i.h"
  15. #include "cfg.h"
  16. #include "rate.h"
  17. #include "mesh.h"
  18. static bool nl80211_type_check(enum nl80211_iftype type)
  19. {
  20. switch (type) {
  21. case NL80211_IFTYPE_ADHOC:
  22. case NL80211_IFTYPE_STATION:
  23. case NL80211_IFTYPE_MONITOR:
  24. #ifdef CONFIG_MAC80211_MESH
  25. case NL80211_IFTYPE_MESH_POINT:
  26. #endif
  27. case NL80211_IFTYPE_AP:
  28. case NL80211_IFTYPE_AP_VLAN:
  29. case NL80211_IFTYPE_WDS:
  30. return true;
  31. default:
  32. return false;
  33. }
  34. }
  35. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  36. enum nl80211_iftype type, u32 *flags,
  37. struct vif_params *params)
  38. {
  39. struct ieee80211_local *local = wiphy_priv(wiphy);
  40. struct net_device *dev;
  41. struct ieee80211_sub_if_data *sdata;
  42. int err;
  43. if (!nl80211_type_check(type))
  44. return -EINVAL;
  45. err = ieee80211_if_add(local, name, &dev, type, params);
  46. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  47. return err;
  48. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  49. sdata->u.mntr_flags = *flags;
  50. return 0;
  51. }
  52. static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
  53. {
  54. struct net_device *dev;
  55. struct ieee80211_sub_if_data *sdata;
  56. /* we're under RTNL */
  57. dev = __dev_get_by_index(&init_net, ifindex);
  58. if (!dev)
  59. return -ENODEV;
  60. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  61. ieee80211_if_remove(sdata);
  62. return 0;
  63. }
  64. static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
  65. enum nl80211_iftype type, u32 *flags,
  66. struct vif_params *params)
  67. {
  68. struct net_device *dev;
  69. struct ieee80211_sub_if_data *sdata;
  70. int ret;
  71. /* we're under RTNL */
  72. dev = __dev_get_by_index(&init_net, ifindex);
  73. if (!dev)
  74. return -ENODEV;
  75. if (!nl80211_type_check(type))
  76. return -EINVAL;
  77. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  78. ret = ieee80211_if_change_type(sdata, type);
  79. if (ret)
  80. return ret;
  81. if (netif_running(sdata->dev))
  82. return -EBUSY;
  83. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  84. ieee80211_sdata_set_mesh_id(sdata,
  85. params->mesh_id_len,
  86. params->mesh_id);
  87. if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
  88. return 0;
  89. sdata->u.mntr_flags = *flags;
  90. return 0;
  91. }
  92. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  93. u8 key_idx, u8 *mac_addr,
  94. struct key_params *params)
  95. {
  96. struct ieee80211_sub_if_data *sdata;
  97. struct sta_info *sta = NULL;
  98. enum ieee80211_key_alg alg;
  99. struct ieee80211_key *key;
  100. int err;
  101. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  102. switch (params->cipher) {
  103. case WLAN_CIPHER_SUITE_WEP40:
  104. case WLAN_CIPHER_SUITE_WEP104:
  105. alg = ALG_WEP;
  106. break;
  107. case WLAN_CIPHER_SUITE_TKIP:
  108. alg = ALG_TKIP;
  109. break;
  110. case WLAN_CIPHER_SUITE_CCMP:
  111. alg = ALG_CCMP;
  112. break;
  113. case WLAN_CIPHER_SUITE_AES_CMAC:
  114. alg = ALG_AES_CMAC;
  115. break;
  116. default:
  117. return -EINVAL;
  118. }
  119. key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
  120. if (!key)
  121. return -ENOMEM;
  122. rcu_read_lock();
  123. if (mac_addr) {
  124. sta = sta_info_get(sdata->local, mac_addr);
  125. if (!sta) {
  126. ieee80211_key_free(key);
  127. err = -ENOENT;
  128. goto out_unlock;
  129. }
  130. }
  131. ieee80211_key_link(key, sdata, sta);
  132. err = 0;
  133. out_unlock:
  134. rcu_read_unlock();
  135. return err;
  136. }
  137. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  138. u8 key_idx, u8 *mac_addr)
  139. {
  140. struct ieee80211_sub_if_data *sdata;
  141. struct sta_info *sta;
  142. int ret;
  143. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  144. rcu_read_lock();
  145. if (mac_addr) {
  146. ret = -ENOENT;
  147. sta = sta_info_get(sdata->local, mac_addr);
  148. if (!sta)
  149. goto out_unlock;
  150. if (sta->key) {
  151. ieee80211_key_free(sta->key);
  152. WARN_ON(sta->key);
  153. ret = 0;
  154. }
  155. goto out_unlock;
  156. }
  157. if (!sdata->keys[key_idx]) {
  158. ret = -ENOENT;
  159. goto out_unlock;
  160. }
  161. ieee80211_key_free(sdata->keys[key_idx]);
  162. WARN_ON(sdata->keys[key_idx]);
  163. ret = 0;
  164. out_unlock:
  165. rcu_read_unlock();
  166. return ret;
  167. }
  168. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  169. u8 key_idx, u8 *mac_addr, void *cookie,
  170. void (*callback)(void *cookie,
  171. struct key_params *params))
  172. {
  173. struct ieee80211_sub_if_data *sdata;
  174. struct sta_info *sta = NULL;
  175. u8 seq[6] = {0};
  176. struct key_params params;
  177. struct ieee80211_key *key;
  178. u32 iv32;
  179. u16 iv16;
  180. int err = -ENOENT;
  181. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  182. rcu_read_lock();
  183. if (mac_addr) {
  184. sta = sta_info_get(sdata->local, mac_addr);
  185. if (!sta)
  186. goto out;
  187. key = sta->key;
  188. } else
  189. key = sdata->keys[key_idx];
  190. if (!key)
  191. goto out;
  192. memset(&params, 0, sizeof(params));
  193. switch (key->conf.alg) {
  194. case ALG_TKIP:
  195. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  196. iv32 = key->u.tkip.tx.iv32;
  197. iv16 = key->u.tkip.tx.iv16;
  198. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  199. sdata->local->ops->get_tkip_seq)
  200. sdata->local->ops->get_tkip_seq(
  201. local_to_hw(sdata->local),
  202. key->conf.hw_key_idx,
  203. &iv32, &iv16);
  204. seq[0] = iv16 & 0xff;
  205. seq[1] = (iv16 >> 8) & 0xff;
  206. seq[2] = iv32 & 0xff;
  207. seq[3] = (iv32 >> 8) & 0xff;
  208. seq[4] = (iv32 >> 16) & 0xff;
  209. seq[5] = (iv32 >> 24) & 0xff;
  210. params.seq = seq;
  211. params.seq_len = 6;
  212. break;
  213. case ALG_CCMP:
  214. params.cipher = WLAN_CIPHER_SUITE_CCMP;
  215. seq[0] = key->u.ccmp.tx_pn[5];
  216. seq[1] = key->u.ccmp.tx_pn[4];
  217. seq[2] = key->u.ccmp.tx_pn[3];
  218. seq[3] = key->u.ccmp.tx_pn[2];
  219. seq[4] = key->u.ccmp.tx_pn[1];
  220. seq[5] = key->u.ccmp.tx_pn[0];
  221. params.seq = seq;
  222. params.seq_len = 6;
  223. break;
  224. case ALG_WEP:
  225. if (key->conf.keylen == 5)
  226. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  227. else
  228. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  229. break;
  230. case ALG_AES_CMAC:
  231. params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  232. seq[0] = key->u.aes_cmac.tx_pn[5];
  233. seq[1] = key->u.aes_cmac.tx_pn[4];
  234. seq[2] = key->u.aes_cmac.tx_pn[3];
  235. seq[3] = key->u.aes_cmac.tx_pn[2];
  236. seq[4] = key->u.aes_cmac.tx_pn[1];
  237. seq[5] = key->u.aes_cmac.tx_pn[0];
  238. params.seq = seq;
  239. params.seq_len = 6;
  240. break;
  241. }
  242. params.key = key->conf.key;
  243. params.key_len = key->conf.keylen;
  244. callback(cookie, &params);
  245. err = 0;
  246. out:
  247. rcu_read_unlock();
  248. return err;
  249. }
  250. static int ieee80211_config_default_key(struct wiphy *wiphy,
  251. struct net_device *dev,
  252. u8 key_idx)
  253. {
  254. struct ieee80211_sub_if_data *sdata;
  255. rcu_read_lock();
  256. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  257. ieee80211_set_default_key(sdata, key_idx);
  258. rcu_read_unlock();
  259. return 0;
  260. }
  261. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  262. struct net_device *dev,
  263. u8 key_idx)
  264. {
  265. struct ieee80211_sub_if_data *sdata;
  266. rcu_read_lock();
  267. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  268. ieee80211_set_default_mgmt_key(sdata, key_idx);
  269. rcu_read_unlock();
  270. return 0;
  271. }
  272. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  273. {
  274. struct ieee80211_sub_if_data *sdata = sta->sdata;
  275. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  276. STATION_INFO_RX_BYTES |
  277. STATION_INFO_TX_BYTES |
  278. STATION_INFO_RX_PACKETS |
  279. STATION_INFO_TX_PACKETS |
  280. STATION_INFO_TX_BITRATE;
  281. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  282. sinfo->rx_bytes = sta->rx_bytes;
  283. sinfo->tx_bytes = sta->tx_bytes;
  284. sinfo->rx_packets = sta->rx_packets;
  285. sinfo->tx_packets = sta->tx_packets;
  286. if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  287. sinfo->filled |= STATION_INFO_SIGNAL;
  288. sinfo->signal = (s8)sta->last_signal;
  289. }
  290. sinfo->txrate.flags = 0;
  291. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  292. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  293. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  294. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  295. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  296. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  297. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  298. struct ieee80211_supported_band *sband;
  299. sband = sta->local->hw.wiphy->bands[
  300. sta->local->hw.conf.channel->band];
  301. sinfo->txrate.legacy =
  302. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  303. } else
  304. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  305. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  306. #ifdef CONFIG_MAC80211_MESH
  307. sinfo->filled |= STATION_INFO_LLID |
  308. STATION_INFO_PLID |
  309. STATION_INFO_PLINK_STATE;
  310. sinfo->llid = le16_to_cpu(sta->llid);
  311. sinfo->plid = le16_to_cpu(sta->plid);
  312. sinfo->plink_state = sta->plink_state;
  313. #endif
  314. }
  315. }
  316. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  317. int idx, u8 *mac, struct station_info *sinfo)
  318. {
  319. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  320. struct sta_info *sta;
  321. int ret = -ENOENT;
  322. rcu_read_lock();
  323. sta = sta_info_get_by_idx(local, idx, dev);
  324. if (sta) {
  325. ret = 0;
  326. memcpy(mac, sta->sta.addr, ETH_ALEN);
  327. sta_set_sinfo(sta, sinfo);
  328. }
  329. rcu_read_unlock();
  330. return ret;
  331. }
  332. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  333. u8 *mac, struct station_info *sinfo)
  334. {
  335. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  336. struct sta_info *sta;
  337. int ret = -ENOENT;
  338. rcu_read_lock();
  339. /* XXX: verify sta->dev == dev */
  340. sta = sta_info_get(local, mac);
  341. if (sta) {
  342. ret = 0;
  343. sta_set_sinfo(sta, sinfo);
  344. }
  345. rcu_read_unlock();
  346. return ret;
  347. }
  348. /*
  349. * This handles both adding a beacon and setting new beacon info
  350. */
  351. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  352. struct beacon_parameters *params)
  353. {
  354. struct beacon_data *new, *old;
  355. int new_head_len, new_tail_len;
  356. int size;
  357. int err = -EINVAL;
  358. old = sdata->u.ap.beacon;
  359. /* head must not be zero-length */
  360. if (params->head && !params->head_len)
  361. return -EINVAL;
  362. /*
  363. * This is a kludge. beacon interval should really be part
  364. * of the beacon information.
  365. */
  366. if (params->interval) {
  367. sdata->local->hw.conf.beacon_int = params->interval;
  368. err = ieee80211_hw_config(sdata->local,
  369. IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
  370. if (err < 0)
  371. return err;
  372. /*
  373. * We updated some parameter so if below bails out
  374. * it's not an error.
  375. */
  376. err = 0;
  377. }
  378. /* Need to have a beacon head if we don't have one yet */
  379. if (!params->head && !old)
  380. return err;
  381. /* sorry, no way to start beaconing without dtim period */
  382. if (!params->dtim_period && !old)
  383. return err;
  384. /* new or old head? */
  385. if (params->head)
  386. new_head_len = params->head_len;
  387. else
  388. new_head_len = old->head_len;
  389. /* new or old tail? */
  390. if (params->tail || !old)
  391. /* params->tail_len will be zero for !params->tail */
  392. new_tail_len = params->tail_len;
  393. else
  394. new_tail_len = old->tail_len;
  395. size = sizeof(*new) + new_head_len + new_tail_len;
  396. new = kzalloc(size, GFP_KERNEL);
  397. if (!new)
  398. return -ENOMEM;
  399. /* start filling the new info now */
  400. /* new or old dtim period? */
  401. if (params->dtim_period)
  402. new->dtim_period = params->dtim_period;
  403. else
  404. new->dtim_period = old->dtim_period;
  405. /*
  406. * pointers go into the block we allocated,
  407. * memory is | beacon_data | head | tail |
  408. */
  409. new->head = ((u8 *) new) + sizeof(*new);
  410. new->tail = new->head + new_head_len;
  411. new->head_len = new_head_len;
  412. new->tail_len = new_tail_len;
  413. /* copy in head */
  414. if (params->head)
  415. memcpy(new->head, params->head, new_head_len);
  416. else
  417. memcpy(new->head, old->head, new_head_len);
  418. /* copy in optional tail */
  419. if (params->tail)
  420. memcpy(new->tail, params->tail, new_tail_len);
  421. else
  422. if (old)
  423. memcpy(new->tail, old->tail, new_tail_len);
  424. rcu_assign_pointer(sdata->u.ap.beacon, new);
  425. synchronize_rcu();
  426. kfree(old);
  427. return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON |
  428. IEEE80211_IFCC_BEACON_ENABLED);
  429. }
  430. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  431. struct beacon_parameters *params)
  432. {
  433. struct ieee80211_sub_if_data *sdata;
  434. struct beacon_data *old;
  435. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  436. if (sdata->vif.type != NL80211_IFTYPE_AP)
  437. return -EINVAL;
  438. old = sdata->u.ap.beacon;
  439. if (old)
  440. return -EALREADY;
  441. return ieee80211_config_beacon(sdata, params);
  442. }
  443. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  444. struct beacon_parameters *params)
  445. {
  446. struct ieee80211_sub_if_data *sdata;
  447. struct beacon_data *old;
  448. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  449. if (sdata->vif.type != NL80211_IFTYPE_AP)
  450. return -EINVAL;
  451. old = sdata->u.ap.beacon;
  452. if (!old)
  453. return -ENOENT;
  454. return ieee80211_config_beacon(sdata, params);
  455. }
  456. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  457. {
  458. struct ieee80211_sub_if_data *sdata;
  459. struct beacon_data *old;
  460. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  461. if (sdata->vif.type != NL80211_IFTYPE_AP)
  462. return -EINVAL;
  463. old = sdata->u.ap.beacon;
  464. if (!old)
  465. return -ENOENT;
  466. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  467. synchronize_rcu();
  468. kfree(old);
  469. return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED);
  470. }
  471. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  472. struct iapp_layer2_update {
  473. u8 da[ETH_ALEN]; /* broadcast */
  474. u8 sa[ETH_ALEN]; /* STA addr */
  475. __be16 len; /* 6 */
  476. u8 dsap; /* 0 */
  477. u8 ssap; /* 0 */
  478. u8 control;
  479. u8 xid_info[3];
  480. } __attribute__ ((packed));
  481. static void ieee80211_send_layer2_update(struct sta_info *sta)
  482. {
  483. struct iapp_layer2_update *msg;
  484. struct sk_buff *skb;
  485. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  486. * bridge devices */
  487. skb = dev_alloc_skb(sizeof(*msg));
  488. if (!skb)
  489. return;
  490. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  491. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  492. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  493. memset(msg->da, 0xff, ETH_ALEN);
  494. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  495. msg->len = htons(6);
  496. msg->dsap = 0;
  497. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  498. msg->control = 0xaf; /* XID response lsb.1111F101.
  499. * F=0 (no poll command; unsolicited frame) */
  500. msg->xid_info[0] = 0x81; /* XID format identifier */
  501. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  502. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  503. skb->dev = sta->sdata->dev;
  504. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  505. memset(skb->cb, 0, sizeof(skb->cb));
  506. netif_rx(skb);
  507. }
  508. static void sta_apply_parameters(struct ieee80211_local *local,
  509. struct sta_info *sta,
  510. struct station_parameters *params)
  511. {
  512. u32 rates;
  513. int i, j;
  514. struct ieee80211_supported_band *sband;
  515. struct ieee80211_sub_if_data *sdata = sta->sdata;
  516. sband = local->hw.wiphy->bands[local->oper_channel->band];
  517. /*
  518. * FIXME: updating the flags is racy when this function is
  519. * called from ieee80211_change_station(), this will
  520. * be resolved in a future patch.
  521. */
  522. if (params->station_flags & STATION_FLAG_CHANGED) {
  523. spin_lock_bh(&sta->lock);
  524. sta->flags &= ~WLAN_STA_AUTHORIZED;
  525. if (params->station_flags & STATION_FLAG_AUTHORIZED)
  526. sta->flags |= WLAN_STA_AUTHORIZED;
  527. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  528. if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
  529. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  530. sta->flags &= ~WLAN_STA_WME;
  531. if (params->station_flags & STATION_FLAG_WME)
  532. sta->flags |= WLAN_STA_WME;
  533. sta->flags &= ~WLAN_STA_MFP;
  534. if (params->station_flags & STATION_FLAG_MFP)
  535. sta->flags |= WLAN_STA_MFP;
  536. spin_unlock_bh(&sta->lock);
  537. }
  538. /*
  539. * FIXME: updating the following information is racy when this
  540. * function is called from ieee80211_change_station().
  541. * However, all this information should be static so
  542. * maybe we should just reject attemps to change it.
  543. */
  544. if (params->aid) {
  545. sta->sta.aid = params->aid;
  546. if (sta->sta.aid > IEEE80211_MAX_AID)
  547. sta->sta.aid = 0; /* XXX: should this be an error? */
  548. }
  549. if (params->listen_interval >= 0)
  550. sta->listen_interval = params->listen_interval;
  551. if (params->supported_rates) {
  552. rates = 0;
  553. for (i = 0; i < params->supported_rates_len; i++) {
  554. int rate = (params->supported_rates[i] & 0x7f) * 5;
  555. for (j = 0; j < sband->n_bitrates; j++) {
  556. if (sband->bitrates[j].bitrate == rate)
  557. rates |= BIT(j);
  558. }
  559. }
  560. sta->sta.supp_rates[local->oper_channel->band] = rates;
  561. }
  562. if (params->ht_capa)
  563. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  564. params->ht_capa,
  565. &sta->sta.ht_cap);
  566. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  567. switch (params->plink_action) {
  568. case PLINK_ACTION_OPEN:
  569. mesh_plink_open(sta);
  570. break;
  571. case PLINK_ACTION_BLOCK:
  572. mesh_plink_block(sta);
  573. break;
  574. }
  575. }
  576. }
  577. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  578. u8 *mac, struct station_parameters *params)
  579. {
  580. struct ieee80211_local *local = wiphy_priv(wiphy);
  581. struct sta_info *sta;
  582. struct ieee80211_sub_if_data *sdata;
  583. int err;
  584. int layer2_update;
  585. /* Prevent a race with changing the rate control algorithm */
  586. if (!netif_running(dev))
  587. return -ENETDOWN;
  588. if (params->vlan) {
  589. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  590. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  591. sdata->vif.type != NL80211_IFTYPE_AP)
  592. return -EINVAL;
  593. } else
  594. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  595. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  596. return -EINVAL;
  597. if (is_multicast_ether_addr(mac))
  598. return -EINVAL;
  599. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  600. if (!sta)
  601. return -ENOMEM;
  602. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  603. sta_apply_parameters(local, sta, params);
  604. rate_control_rate_init(sta);
  605. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  606. sdata->vif.type == NL80211_IFTYPE_AP;
  607. rcu_read_lock();
  608. err = sta_info_insert(sta);
  609. if (err) {
  610. /* STA has been freed */
  611. if (err == -EEXIST && layer2_update) {
  612. /* Need to update layer 2 devices on reassociation */
  613. sta = sta_info_get(local, mac);
  614. if (sta)
  615. ieee80211_send_layer2_update(sta);
  616. }
  617. rcu_read_unlock();
  618. return err;
  619. }
  620. if (layer2_update)
  621. ieee80211_send_layer2_update(sta);
  622. rcu_read_unlock();
  623. return 0;
  624. }
  625. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  626. u8 *mac)
  627. {
  628. struct ieee80211_local *local = wiphy_priv(wiphy);
  629. struct ieee80211_sub_if_data *sdata;
  630. struct sta_info *sta;
  631. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  632. if (mac) {
  633. rcu_read_lock();
  634. /* XXX: get sta belonging to dev */
  635. sta = sta_info_get(local, mac);
  636. if (!sta) {
  637. rcu_read_unlock();
  638. return -ENOENT;
  639. }
  640. sta_info_unlink(&sta);
  641. rcu_read_unlock();
  642. sta_info_destroy(sta);
  643. } else
  644. sta_info_flush(local, sdata);
  645. return 0;
  646. }
  647. static int ieee80211_change_station(struct wiphy *wiphy,
  648. struct net_device *dev,
  649. u8 *mac,
  650. struct station_parameters *params)
  651. {
  652. struct ieee80211_local *local = wiphy_priv(wiphy);
  653. struct sta_info *sta;
  654. struct ieee80211_sub_if_data *vlansdata;
  655. rcu_read_lock();
  656. /* XXX: get sta belonging to dev */
  657. sta = sta_info_get(local, mac);
  658. if (!sta) {
  659. rcu_read_unlock();
  660. return -ENOENT;
  661. }
  662. if (params->vlan && params->vlan != sta->sdata->dev) {
  663. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  664. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  665. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  666. rcu_read_unlock();
  667. return -EINVAL;
  668. }
  669. sta->sdata = vlansdata;
  670. ieee80211_send_layer2_update(sta);
  671. }
  672. sta_apply_parameters(local, sta, params);
  673. rcu_read_unlock();
  674. return 0;
  675. }
  676. #ifdef CONFIG_MAC80211_MESH
  677. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  678. u8 *dst, u8 *next_hop)
  679. {
  680. struct ieee80211_local *local = wiphy_priv(wiphy);
  681. struct ieee80211_sub_if_data *sdata;
  682. struct mesh_path *mpath;
  683. struct sta_info *sta;
  684. int err;
  685. if (!netif_running(dev))
  686. return -ENETDOWN;
  687. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  688. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  689. return -ENOTSUPP;
  690. rcu_read_lock();
  691. sta = sta_info_get(local, next_hop);
  692. if (!sta) {
  693. rcu_read_unlock();
  694. return -ENOENT;
  695. }
  696. err = mesh_path_add(dst, sdata);
  697. if (err) {
  698. rcu_read_unlock();
  699. return err;
  700. }
  701. mpath = mesh_path_lookup(dst, sdata);
  702. if (!mpath) {
  703. rcu_read_unlock();
  704. return -ENXIO;
  705. }
  706. mesh_path_fix_nexthop(mpath, sta);
  707. rcu_read_unlock();
  708. return 0;
  709. }
  710. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  711. u8 *dst)
  712. {
  713. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  714. if (dst)
  715. return mesh_path_del(dst, sdata);
  716. mesh_path_flush(sdata);
  717. return 0;
  718. }
  719. static int ieee80211_change_mpath(struct wiphy *wiphy,
  720. struct net_device *dev,
  721. u8 *dst, u8 *next_hop)
  722. {
  723. struct ieee80211_local *local = wiphy_priv(wiphy);
  724. struct ieee80211_sub_if_data *sdata;
  725. struct mesh_path *mpath;
  726. struct sta_info *sta;
  727. if (!netif_running(dev))
  728. return -ENETDOWN;
  729. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  730. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  731. return -ENOTSUPP;
  732. rcu_read_lock();
  733. sta = sta_info_get(local, next_hop);
  734. if (!sta) {
  735. rcu_read_unlock();
  736. return -ENOENT;
  737. }
  738. mpath = mesh_path_lookup(dst, sdata);
  739. if (!mpath) {
  740. rcu_read_unlock();
  741. return -ENOENT;
  742. }
  743. mesh_path_fix_nexthop(mpath, sta);
  744. rcu_read_unlock();
  745. return 0;
  746. }
  747. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  748. struct mpath_info *pinfo)
  749. {
  750. if (mpath->next_hop)
  751. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  752. else
  753. memset(next_hop, 0, ETH_ALEN);
  754. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  755. MPATH_INFO_DSN |
  756. MPATH_INFO_METRIC |
  757. MPATH_INFO_EXPTIME |
  758. MPATH_INFO_DISCOVERY_TIMEOUT |
  759. MPATH_INFO_DISCOVERY_RETRIES |
  760. MPATH_INFO_FLAGS;
  761. pinfo->frame_qlen = mpath->frame_queue.qlen;
  762. pinfo->dsn = mpath->dsn;
  763. pinfo->metric = mpath->metric;
  764. if (time_before(jiffies, mpath->exp_time))
  765. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  766. pinfo->discovery_timeout =
  767. jiffies_to_msecs(mpath->discovery_timeout);
  768. pinfo->discovery_retries = mpath->discovery_retries;
  769. pinfo->flags = 0;
  770. if (mpath->flags & MESH_PATH_ACTIVE)
  771. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  772. if (mpath->flags & MESH_PATH_RESOLVING)
  773. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  774. if (mpath->flags & MESH_PATH_DSN_VALID)
  775. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  776. if (mpath->flags & MESH_PATH_FIXED)
  777. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  778. if (mpath->flags & MESH_PATH_RESOLVING)
  779. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  780. pinfo->flags = mpath->flags;
  781. }
  782. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  783. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  784. {
  785. struct ieee80211_sub_if_data *sdata;
  786. struct mesh_path *mpath;
  787. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  788. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  789. return -ENOTSUPP;
  790. rcu_read_lock();
  791. mpath = mesh_path_lookup(dst, sdata);
  792. if (!mpath) {
  793. rcu_read_unlock();
  794. return -ENOENT;
  795. }
  796. memcpy(dst, mpath->dst, ETH_ALEN);
  797. mpath_set_pinfo(mpath, next_hop, pinfo);
  798. rcu_read_unlock();
  799. return 0;
  800. }
  801. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  802. int idx, u8 *dst, u8 *next_hop,
  803. struct mpath_info *pinfo)
  804. {
  805. struct ieee80211_sub_if_data *sdata;
  806. struct mesh_path *mpath;
  807. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  808. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  809. return -ENOTSUPP;
  810. rcu_read_lock();
  811. mpath = mesh_path_lookup_by_idx(idx, sdata);
  812. if (!mpath) {
  813. rcu_read_unlock();
  814. return -ENOENT;
  815. }
  816. memcpy(dst, mpath->dst, ETH_ALEN);
  817. mpath_set_pinfo(mpath, next_hop, pinfo);
  818. rcu_read_unlock();
  819. return 0;
  820. }
  821. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  822. struct net_device *dev,
  823. struct mesh_config *conf)
  824. {
  825. struct ieee80211_sub_if_data *sdata;
  826. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  827. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  828. return -ENOTSUPP;
  829. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  830. return 0;
  831. }
  832. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  833. {
  834. return (mask >> (parm-1)) & 0x1;
  835. }
  836. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  837. struct net_device *dev,
  838. const struct mesh_config *nconf, u32 mask)
  839. {
  840. struct mesh_config *conf;
  841. struct ieee80211_sub_if_data *sdata;
  842. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  843. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  844. return -ENOTSUPP;
  845. /* Set the config options which we are interested in setting */
  846. conf = &(sdata->u.mesh.mshcfg);
  847. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  848. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  849. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  850. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  851. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  852. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  853. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  854. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  855. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  856. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  857. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  858. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  859. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  860. conf->auto_open_plinks = nconf->auto_open_plinks;
  861. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  862. conf->dot11MeshHWMPmaxPREQretries =
  863. nconf->dot11MeshHWMPmaxPREQretries;
  864. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  865. conf->path_refresh_time = nconf->path_refresh_time;
  866. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  867. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  868. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  869. conf->dot11MeshHWMPactivePathTimeout =
  870. nconf->dot11MeshHWMPactivePathTimeout;
  871. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  872. conf->dot11MeshHWMPpreqMinInterval =
  873. nconf->dot11MeshHWMPpreqMinInterval;
  874. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  875. mask))
  876. conf->dot11MeshHWMPnetDiameterTraversalTime =
  877. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  878. return 0;
  879. }
  880. #endif
  881. static int ieee80211_change_bss(struct wiphy *wiphy,
  882. struct net_device *dev,
  883. struct bss_parameters *params)
  884. {
  885. struct ieee80211_sub_if_data *sdata;
  886. u32 changed = 0;
  887. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  888. if (sdata->vif.type != NL80211_IFTYPE_AP)
  889. return -EINVAL;
  890. if (params->use_cts_prot >= 0) {
  891. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  892. changed |= BSS_CHANGED_ERP_CTS_PROT;
  893. }
  894. if (params->use_short_preamble >= 0) {
  895. sdata->vif.bss_conf.use_short_preamble =
  896. params->use_short_preamble;
  897. changed |= BSS_CHANGED_ERP_PREAMBLE;
  898. }
  899. if (params->use_short_slot_time >= 0) {
  900. sdata->vif.bss_conf.use_short_slot =
  901. params->use_short_slot_time;
  902. changed |= BSS_CHANGED_ERP_SLOT;
  903. }
  904. if (params->basic_rates) {
  905. int i, j;
  906. u32 rates = 0;
  907. struct ieee80211_local *local = wiphy_priv(wiphy);
  908. struct ieee80211_supported_band *sband =
  909. wiphy->bands[local->oper_channel->band];
  910. for (i = 0; i < params->basic_rates_len; i++) {
  911. int rate = (params->basic_rates[i] & 0x7f) * 5;
  912. for (j = 0; j < sband->n_bitrates; j++) {
  913. if (sband->bitrates[j].bitrate == rate)
  914. rates |= BIT(j);
  915. }
  916. }
  917. sdata->vif.bss_conf.basic_rates = rates;
  918. changed |= BSS_CHANGED_BASIC_RATES;
  919. }
  920. ieee80211_bss_info_change_notify(sdata, changed);
  921. return 0;
  922. }
  923. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  924. struct ieee80211_txq_params *params)
  925. {
  926. struct ieee80211_local *local = wiphy_priv(wiphy);
  927. struct ieee80211_tx_queue_params p;
  928. if (!local->ops->conf_tx)
  929. return -EOPNOTSUPP;
  930. memset(&p, 0, sizeof(p));
  931. p.aifs = params->aifs;
  932. p.cw_max = params->cwmax;
  933. p.cw_min = params->cwmin;
  934. p.txop = params->txop;
  935. if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
  936. printk(KERN_DEBUG "%s: failed to set TX queue "
  937. "parameters for queue %d\n", local->mdev->name,
  938. params->queue);
  939. return -EINVAL;
  940. }
  941. return 0;
  942. }
  943. static int ieee80211_set_channel(struct wiphy *wiphy,
  944. struct ieee80211_channel *chan,
  945. enum nl80211_channel_type channel_type)
  946. {
  947. struct ieee80211_local *local = wiphy_priv(wiphy);
  948. local->oper_channel = chan;
  949. local->oper_channel_type = channel_type;
  950. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  951. }
  952. static int set_mgmt_extra_ie_sta(struct ieee80211_sub_if_data *sdata,
  953. u8 subtype, u8 *ies, size_t ies_len)
  954. {
  955. struct ieee80211_local *local = sdata->local;
  956. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  957. switch (subtype) {
  958. case IEEE80211_STYPE_PROBE_REQ >> 4:
  959. if (local->ops->hw_scan)
  960. break;
  961. kfree(ifmgd->ie_probereq);
  962. ifmgd->ie_probereq = ies;
  963. ifmgd->ie_probereq_len = ies_len;
  964. return 0;
  965. case IEEE80211_STYPE_PROBE_RESP >> 4:
  966. kfree(ifmgd->ie_proberesp);
  967. ifmgd->ie_proberesp = ies;
  968. ifmgd->ie_proberesp_len = ies_len;
  969. return 0;
  970. case IEEE80211_STYPE_AUTH >> 4:
  971. kfree(ifmgd->ie_auth);
  972. ifmgd->ie_auth = ies;
  973. ifmgd->ie_auth_len = ies_len;
  974. return 0;
  975. case IEEE80211_STYPE_ASSOC_REQ >> 4:
  976. kfree(ifmgd->ie_assocreq);
  977. ifmgd->ie_assocreq = ies;
  978. ifmgd->ie_assocreq_len = ies_len;
  979. return 0;
  980. case IEEE80211_STYPE_REASSOC_REQ >> 4:
  981. kfree(ifmgd->ie_reassocreq);
  982. ifmgd->ie_reassocreq = ies;
  983. ifmgd->ie_reassocreq_len = ies_len;
  984. return 0;
  985. case IEEE80211_STYPE_DEAUTH >> 4:
  986. kfree(ifmgd->ie_deauth);
  987. ifmgd->ie_deauth = ies;
  988. ifmgd->ie_deauth_len = ies_len;
  989. return 0;
  990. case IEEE80211_STYPE_DISASSOC >> 4:
  991. kfree(ifmgd->ie_disassoc);
  992. ifmgd->ie_disassoc = ies;
  993. ifmgd->ie_disassoc_len = ies_len;
  994. return 0;
  995. }
  996. return -EOPNOTSUPP;
  997. }
  998. static int ieee80211_set_mgmt_extra_ie(struct wiphy *wiphy,
  999. struct net_device *dev,
  1000. struct mgmt_extra_ie_params *params)
  1001. {
  1002. struct ieee80211_sub_if_data *sdata;
  1003. u8 *ies;
  1004. size_t ies_len;
  1005. int ret = -EOPNOTSUPP;
  1006. if (params->ies) {
  1007. ies = kmemdup(params->ies, params->ies_len, GFP_KERNEL);
  1008. if (ies == NULL)
  1009. return -ENOMEM;
  1010. ies_len = params->ies_len;
  1011. } else {
  1012. ies = NULL;
  1013. ies_len = 0;
  1014. }
  1015. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1016. switch (sdata->vif.type) {
  1017. case NL80211_IFTYPE_STATION:
  1018. ret = set_mgmt_extra_ie_sta(sdata, params->subtype,
  1019. ies, ies_len);
  1020. break;
  1021. default:
  1022. ret = -EOPNOTSUPP;
  1023. break;
  1024. }
  1025. if (ret)
  1026. kfree(ies);
  1027. return ret;
  1028. }
  1029. #ifdef CONFIG_PM
  1030. static int ieee80211_suspend(struct wiphy *wiphy)
  1031. {
  1032. return __ieee80211_suspend(wiphy_priv(wiphy));
  1033. }
  1034. static int ieee80211_resume(struct wiphy *wiphy)
  1035. {
  1036. return __ieee80211_resume(wiphy_priv(wiphy));
  1037. }
  1038. #else
  1039. #define ieee80211_suspend NULL
  1040. #define ieee80211_resume NULL
  1041. #endif
  1042. static int ieee80211_scan(struct wiphy *wiphy,
  1043. struct net_device *dev,
  1044. struct cfg80211_scan_request *req)
  1045. {
  1046. struct ieee80211_sub_if_data *sdata;
  1047. if (!netif_running(dev))
  1048. return -ENETDOWN;
  1049. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1050. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1051. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1052. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  1053. return -EOPNOTSUPP;
  1054. return ieee80211_request_scan(sdata, req);
  1055. }
  1056. struct cfg80211_ops mac80211_config_ops = {
  1057. .add_virtual_intf = ieee80211_add_iface,
  1058. .del_virtual_intf = ieee80211_del_iface,
  1059. .change_virtual_intf = ieee80211_change_iface,
  1060. .add_key = ieee80211_add_key,
  1061. .del_key = ieee80211_del_key,
  1062. .get_key = ieee80211_get_key,
  1063. .set_default_key = ieee80211_config_default_key,
  1064. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1065. .add_beacon = ieee80211_add_beacon,
  1066. .set_beacon = ieee80211_set_beacon,
  1067. .del_beacon = ieee80211_del_beacon,
  1068. .add_station = ieee80211_add_station,
  1069. .del_station = ieee80211_del_station,
  1070. .change_station = ieee80211_change_station,
  1071. .get_station = ieee80211_get_station,
  1072. .dump_station = ieee80211_dump_station,
  1073. #ifdef CONFIG_MAC80211_MESH
  1074. .add_mpath = ieee80211_add_mpath,
  1075. .del_mpath = ieee80211_del_mpath,
  1076. .change_mpath = ieee80211_change_mpath,
  1077. .get_mpath = ieee80211_get_mpath,
  1078. .dump_mpath = ieee80211_dump_mpath,
  1079. .set_mesh_params = ieee80211_set_mesh_params,
  1080. .get_mesh_params = ieee80211_get_mesh_params,
  1081. #endif
  1082. .change_bss = ieee80211_change_bss,
  1083. .set_txq_params = ieee80211_set_txq_params,
  1084. .set_channel = ieee80211_set_channel,
  1085. .set_mgmt_extra_ie = ieee80211_set_mgmt_extra_ie,
  1086. .suspend = ieee80211_suspend,
  1087. .resume = ieee80211_resume,
  1088. .scan = ieee80211_scan,
  1089. };