cfg.c 34 KB

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