cfg.c 37 KB

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