cfg.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  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 bool nl80211_params_check(enum nl80211_iftype type,
  37. struct vif_params *params)
  38. {
  39. if (!nl80211_type_check(type))
  40. return false;
  41. return true;
  42. }
  43. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  44. enum nl80211_iftype type, u32 *flags,
  45. struct vif_params *params)
  46. {
  47. struct ieee80211_local *local = wiphy_priv(wiphy);
  48. struct net_device *dev;
  49. struct ieee80211_sub_if_data *sdata;
  50. int err;
  51. if (!nl80211_params_check(type, params))
  52. return -EINVAL;
  53. err = ieee80211_if_add(local, name, &dev, type, params);
  54. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  55. return err;
  56. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  57. sdata->u.mntr_flags = *flags;
  58. return 0;
  59. }
  60. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  61. {
  62. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  63. return 0;
  64. }
  65. static int ieee80211_change_iface(struct wiphy *wiphy,
  66. struct net_device *dev,
  67. enum nl80211_iftype type, u32 *flags,
  68. struct vif_params *params)
  69. {
  70. struct ieee80211_sub_if_data *sdata;
  71. int ret;
  72. if (netif_running(dev))
  73. return -EBUSY;
  74. if (!nl80211_params_check(type, params))
  75. return -EINVAL;
  76. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  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(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(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(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. sinfo->filled |= STATION_INFO_SIGNAL;
  291. sinfo->signal = (s8)sta->last_signal;
  292. }
  293. sinfo->txrate.flags = 0;
  294. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  295. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  296. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  297. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  298. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  299. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  300. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  301. struct ieee80211_supported_band *sband;
  302. sband = sta->local->hw.wiphy->bands[
  303. sta->local->hw.conf.channel->band];
  304. sinfo->txrate.legacy =
  305. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  306. } else
  307. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  308. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  309. #ifdef CONFIG_MAC80211_MESH
  310. sinfo->filled |= STATION_INFO_LLID |
  311. STATION_INFO_PLID |
  312. STATION_INFO_PLINK_STATE;
  313. sinfo->llid = le16_to_cpu(sta->llid);
  314. sinfo->plid = le16_to_cpu(sta->plid);
  315. sinfo->plink_state = sta->plink_state;
  316. #endif
  317. }
  318. }
  319. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  320. int idx, u8 *mac, struct station_info *sinfo)
  321. {
  322. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  323. struct sta_info *sta;
  324. int ret = -ENOENT;
  325. rcu_read_lock();
  326. sta = sta_info_get_by_idx(sdata, idx);
  327. if (sta) {
  328. ret = 0;
  329. memcpy(mac, sta->sta.addr, ETH_ALEN);
  330. sta_set_sinfo(sta, sinfo);
  331. }
  332. rcu_read_unlock();
  333. return ret;
  334. }
  335. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  336. u8 *mac, struct station_info *sinfo)
  337. {
  338. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  339. struct sta_info *sta;
  340. int ret = -ENOENT;
  341. rcu_read_lock();
  342. sta = sta_info_get(sdata, mac);
  343. if (sta) {
  344. ret = 0;
  345. sta_set_sinfo(sta, sinfo);
  346. }
  347. rcu_read_unlock();
  348. return ret;
  349. }
  350. /*
  351. * This handles both adding a beacon and setting new beacon info
  352. */
  353. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  354. struct beacon_parameters *params)
  355. {
  356. struct beacon_data *new, *old;
  357. int new_head_len, new_tail_len;
  358. int size;
  359. int err = -EINVAL;
  360. old = sdata->u.ap.beacon;
  361. /* head must not be zero-length */
  362. if (params->head && !params->head_len)
  363. return -EINVAL;
  364. /*
  365. * This is a kludge. beacon interval should really be part
  366. * of the beacon information.
  367. */
  368. if (params->interval &&
  369. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  370. sdata->vif.bss_conf.beacon_int = params->interval;
  371. ieee80211_bss_info_change_notify(sdata,
  372. BSS_CHANGED_BEACON_INT);
  373. }
  374. /* Need to have a beacon head if we don't have one yet */
  375. if (!params->head && !old)
  376. return err;
  377. /* sorry, no way to start beaconing without dtim period */
  378. if (!params->dtim_period && !old)
  379. return err;
  380. /* new or old head? */
  381. if (params->head)
  382. new_head_len = params->head_len;
  383. else
  384. new_head_len = old->head_len;
  385. /* new or old tail? */
  386. if (params->tail || !old)
  387. /* params->tail_len will be zero for !params->tail */
  388. new_tail_len = params->tail_len;
  389. else
  390. new_tail_len = old->tail_len;
  391. size = sizeof(*new) + new_head_len + new_tail_len;
  392. new = kzalloc(size, GFP_KERNEL);
  393. if (!new)
  394. return -ENOMEM;
  395. /* start filling the new info now */
  396. /* new or old dtim period? */
  397. if (params->dtim_period)
  398. new->dtim_period = params->dtim_period;
  399. else
  400. new->dtim_period = old->dtim_period;
  401. /*
  402. * pointers go into the block we allocated,
  403. * memory is | beacon_data | head | tail |
  404. */
  405. new->head = ((u8 *) new) + sizeof(*new);
  406. new->tail = new->head + new_head_len;
  407. new->head_len = new_head_len;
  408. new->tail_len = new_tail_len;
  409. /* copy in head */
  410. if (params->head)
  411. memcpy(new->head, params->head, new_head_len);
  412. else
  413. memcpy(new->head, old->head, new_head_len);
  414. /* copy in optional tail */
  415. if (params->tail)
  416. memcpy(new->tail, params->tail, new_tail_len);
  417. else
  418. if (old)
  419. memcpy(new->tail, old->tail, new_tail_len);
  420. rcu_assign_pointer(sdata->u.ap.beacon, new);
  421. synchronize_rcu();
  422. kfree(old);
  423. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  424. BSS_CHANGED_BEACON);
  425. return 0;
  426. }
  427. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  428. struct beacon_parameters *params)
  429. {
  430. struct ieee80211_sub_if_data *sdata;
  431. struct beacon_data *old;
  432. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  433. old = sdata->u.ap.beacon;
  434. if (old)
  435. return -EALREADY;
  436. return ieee80211_config_beacon(sdata, params);
  437. }
  438. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  439. struct beacon_parameters *params)
  440. {
  441. struct ieee80211_sub_if_data *sdata;
  442. struct beacon_data *old;
  443. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  444. old = sdata->u.ap.beacon;
  445. if (!old)
  446. return -ENOENT;
  447. return ieee80211_config_beacon(sdata, params);
  448. }
  449. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  450. {
  451. struct ieee80211_sub_if_data *sdata;
  452. struct beacon_data *old;
  453. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  454. old = sdata->u.ap.beacon;
  455. if (!old)
  456. return -ENOENT;
  457. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  458. synchronize_rcu();
  459. kfree(old);
  460. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  461. return 0;
  462. }
  463. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  464. struct iapp_layer2_update {
  465. u8 da[ETH_ALEN]; /* broadcast */
  466. u8 sa[ETH_ALEN]; /* STA addr */
  467. __be16 len; /* 6 */
  468. u8 dsap; /* 0 */
  469. u8 ssap; /* 0 */
  470. u8 control;
  471. u8 xid_info[3];
  472. } __attribute__ ((packed));
  473. static void ieee80211_send_layer2_update(struct sta_info *sta)
  474. {
  475. struct iapp_layer2_update *msg;
  476. struct sk_buff *skb;
  477. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  478. * bridge devices */
  479. skb = dev_alloc_skb(sizeof(*msg));
  480. if (!skb)
  481. return;
  482. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  483. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  484. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  485. memset(msg->da, 0xff, ETH_ALEN);
  486. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  487. msg->len = htons(6);
  488. msg->dsap = 0;
  489. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  490. msg->control = 0xaf; /* XID response lsb.1111F101.
  491. * F=0 (no poll command; unsolicited frame) */
  492. msg->xid_info[0] = 0x81; /* XID format identifier */
  493. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  494. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  495. skb->dev = sta->sdata->dev;
  496. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  497. memset(skb->cb, 0, sizeof(skb->cb));
  498. netif_rx(skb);
  499. }
  500. static void sta_apply_parameters(struct ieee80211_local *local,
  501. struct sta_info *sta,
  502. struct station_parameters *params)
  503. {
  504. u32 rates;
  505. int i, j;
  506. struct ieee80211_supported_band *sband;
  507. struct ieee80211_sub_if_data *sdata = sta->sdata;
  508. u32 mask, set;
  509. sband = local->hw.wiphy->bands[local->oper_channel->band];
  510. spin_lock_bh(&sta->lock);
  511. mask = params->sta_flags_mask;
  512. set = params->sta_flags_set;
  513. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  514. sta->flags &= ~WLAN_STA_AUTHORIZED;
  515. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  516. sta->flags |= WLAN_STA_AUTHORIZED;
  517. }
  518. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  519. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  520. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  521. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  522. }
  523. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  524. sta->flags &= ~WLAN_STA_WME;
  525. if (set & BIT(NL80211_STA_FLAG_WME))
  526. sta->flags |= WLAN_STA_WME;
  527. }
  528. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  529. sta->flags &= ~WLAN_STA_MFP;
  530. if (set & BIT(NL80211_STA_FLAG_MFP))
  531. sta->flags |= WLAN_STA_MFP;
  532. }
  533. spin_unlock_bh(&sta->lock);
  534. /*
  535. * cfg80211 validates this (1-2007) and allows setting the AID
  536. * only when creating a new station entry
  537. */
  538. if (params->aid)
  539. sta->sta.aid = params->aid;
  540. /*
  541. * FIXME: updating the following information is racy when this
  542. * function is called from ieee80211_change_station().
  543. * However, all this information should be static so
  544. * maybe we should just reject attemps to change it.
  545. */
  546. if (params->listen_interval >= 0)
  547. sta->listen_interval = params->listen_interval;
  548. if (params->supported_rates) {
  549. rates = 0;
  550. for (i = 0; i < params->supported_rates_len; i++) {
  551. int rate = (params->supported_rates[i] & 0x7f) * 5;
  552. for (j = 0; j < sband->n_bitrates; j++) {
  553. if (sband->bitrates[j].bitrate == rate)
  554. rates |= BIT(j);
  555. }
  556. }
  557. sta->sta.supp_rates[local->oper_channel->band] = rates;
  558. }
  559. if (params->ht_capa)
  560. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  561. params->ht_capa,
  562. &sta->sta.ht_cap);
  563. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  564. switch (params->plink_action) {
  565. case PLINK_ACTION_OPEN:
  566. mesh_plink_open(sta);
  567. break;
  568. case PLINK_ACTION_BLOCK:
  569. mesh_plink_block(sta);
  570. break;
  571. }
  572. }
  573. }
  574. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  575. u8 *mac, struct station_parameters *params)
  576. {
  577. struct ieee80211_local *local = wiphy_priv(wiphy);
  578. struct sta_info *sta;
  579. struct ieee80211_sub_if_data *sdata;
  580. int err;
  581. int layer2_update;
  582. if (params->vlan) {
  583. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  584. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  585. sdata->vif.type != NL80211_IFTYPE_AP)
  586. return -EINVAL;
  587. } else
  588. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  589. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  590. return -EINVAL;
  591. if (is_multicast_ether_addr(mac))
  592. return -EINVAL;
  593. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  594. if (!sta)
  595. return -ENOMEM;
  596. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  597. sta_apply_parameters(local, sta, params);
  598. rate_control_rate_init(sta);
  599. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  600. sdata->vif.type == NL80211_IFTYPE_AP;
  601. rcu_read_lock();
  602. err = sta_info_insert(sta);
  603. if (err) {
  604. rcu_read_unlock();
  605. return err;
  606. }
  607. if (layer2_update)
  608. ieee80211_send_layer2_update(sta);
  609. rcu_read_unlock();
  610. return 0;
  611. }
  612. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  613. u8 *mac)
  614. {
  615. struct ieee80211_local *local = wiphy_priv(wiphy);
  616. struct ieee80211_sub_if_data *sdata;
  617. struct sta_info *sta;
  618. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  619. if (mac) {
  620. rcu_read_lock();
  621. sta = sta_info_get(sdata, mac);
  622. if (!sta) {
  623. rcu_read_unlock();
  624. return -ENOENT;
  625. }
  626. sta_info_unlink(&sta);
  627. rcu_read_unlock();
  628. sta_info_destroy(sta);
  629. } else
  630. sta_info_flush(local, sdata);
  631. return 0;
  632. }
  633. static int ieee80211_change_station(struct wiphy *wiphy,
  634. struct net_device *dev,
  635. u8 *mac,
  636. struct station_parameters *params)
  637. {
  638. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  639. struct ieee80211_local *local = wiphy_priv(wiphy);
  640. struct sta_info *sta;
  641. struct ieee80211_sub_if_data *vlansdata;
  642. rcu_read_lock();
  643. sta = sta_info_get(sdata, mac);
  644. if (!sta) {
  645. rcu_read_unlock();
  646. return -ENOENT;
  647. }
  648. if (params->vlan && params->vlan != sta->sdata->dev) {
  649. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  650. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  651. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  652. rcu_read_unlock();
  653. return -EINVAL;
  654. }
  655. if (params->vlan->ieee80211_ptr->use_4addr) {
  656. if (vlansdata->u.vlan.sta) {
  657. rcu_read_unlock();
  658. return -EBUSY;
  659. }
  660. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  661. }
  662. sta->sdata = vlansdata;
  663. ieee80211_send_layer2_update(sta);
  664. }
  665. sta_apply_parameters(local, sta, params);
  666. rcu_read_unlock();
  667. return 0;
  668. }
  669. #ifdef CONFIG_MAC80211_MESH
  670. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  671. u8 *dst, u8 *next_hop)
  672. {
  673. struct ieee80211_sub_if_data *sdata;
  674. struct mesh_path *mpath;
  675. struct sta_info *sta;
  676. int err;
  677. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  678. rcu_read_lock();
  679. sta = sta_info_get(sdata, next_hop);
  680. if (!sta) {
  681. rcu_read_unlock();
  682. return -ENOENT;
  683. }
  684. err = mesh_path_add(dst, sdata);
  685. if (err) {
  686. rcu_read_unlock();
  687. return err;
  688. }
  689. mpath = mesh_path_lookup(dst, sdata);
  690. if (!mpath) {
  691. rcu_read_unlock();
  692. return -ENXIO;
  693. }
  694. mesh_path_fix_nexthop(mpath, sta);
  695. rcu_read_unlock();
  696. return 0;
  697. }
  698. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  699. u8 *dst)
  700. {
  701. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  702. if (dst)
  703. return mesh_path_del(dst, sdata);
  704. mesh_path_flush(sdata);
  705. return 0;
  706. }
  707. static int ieee80211_change_mpath(struct wiphy *wiphy,
  708. struct net_device *dev,
  709. u8 *dst, u8 *next_hop)
  710. {
  711. struct ieee80211_sub_if_data *sdata;
  712. struct mesh_path *mpath;
  713. struct sta_info *sta;
  714. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  715. rcu_read_lock();
  716. sta = sta_info_get(sdata, next_hop);
  717. if (!sta) {
  718. rcu_read_unlock();
  719. return -ENOENT;
  720. }
  721. mpath = mesh_path_lookup(dst, sdata);
  722. if (!mpath) {
  723. rcu_read_unlock();
  724. return -ENOENT;
  725. }
  726. mesh_path_fix_nexthop(mpath, sta);
  727. rcu_read_unlock();
  728. return 0;
  729. }
  730. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  731. struct mpath_info *pinfo)
  732. {
  733. if (mpath->next_hop)
  734. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  735. else
  736. memset(next_hop, 0, ETH_ALEN);
  737. pinfo->generation = mesh_paths_generation;
  738. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  739. MPATH_INFO_SN |
  740. MPATH_INFO_METRIC |
  741. MPATH_INFO_EXPTIME |
  742. MPATH_INFO_DISCOVERY_TIMEOUT |
  743. MPATH_INFO_DISCOVERY_RETRIES |
  744. MPATH_INFO_FLAGS;
  745. pinfo->frame_qlen = mpath->frame_queue.qlen;
  746. pinfo->sn = mpath->sn;
  747. pinfo->metric = mpath->metric;
  748. if (time_before(jiffies, mpath->exp_time))
  749. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  750. pinfo->discovery_timeout =
  751. jiffies_to_msecs(mpath->discovery_timeout);
  752. pinfo->discovery_retries = mpath->discovery_retries;
  753. pinfo->flags = 0;
  754. if (mpath->flags & MESH_PATH_ACTIVE)
  755. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  756. if (mpath->flags & MESH_PATH_RESOLVING)
  757. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  758. if (mpath->flags & MESH_PATH_SN_VALID)
  759. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  760. if (mpath->flags & MESH_PATH_FIXED)
  761. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  762. if (mpath->flags & MESH_PATH_RESOLVING)
  763. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  764. pinfo->flags = mpath->flags;
  765. }
  766. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  767. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  768. {
  769. struct ieee80211_sub_if_data *sdata;
  770. struct mesh_path *mpath;
  771. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  772. rcu_read_lock();
  773. mpath = mesh_path_lookup(dst, sdata);
  774. if (!mpath) {
  775. rcu_read_unlock();
  776. return -ENOENT;
  777. }
  778. memcpy(dst, mpath->dst, ETH_ALEN);
  779. mpath_set_pinfo(mpath, next_hop, pinfo);
  780. rcu_read_unlock();
  781. return 0;
  782. }
  783. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  784. int idx, u8 *dst, u8 *next_hop,
  785. struct mpath_info *pinfo)
  786. {
  787. struct ieee80211_sub_if_data *sdata;
  788. struct mesh_path *mpath;
  789. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  790. rcu_read_lock();
  791. mpath = mesh_path_lookup_by_idx(idx, sdata);
  792. if (!mpath) {
  793. rcu_read_unlock();
  794. return -ENOENT;
  795. }
  796. memcpy(dst, mpath->dst, ETH_ALEN);
  797. mpath_set_pinfo(mpath, next_hop, pinfo);
  798. rcu_read_unlock();
  799. return 0;
  800. }
  801. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  802. struct net_device *dev,
  803. struct mesh_config *conf)
  804. {
  805. struct ieee80211_sub_if_data *sdata;
  806. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  807. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  808. return 0;
  809. }
  810. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  811. {
  812. return (mask >> (parm-1)) & 0x1;
  813. }
  814. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  815. struct net_device *dev,
  816. const struct mesh_config *nconf, u32 mask)
  817. {
  818. struct mesh_config *conf;
  819. struct ieee80211_sub_if_data *sdata;
  820. struct ieee80211_if_mesh *ifmsh;
  821. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  822. ifmsh = &sdata->u.mesh;
  823. /* Set the config options which we are interested in setting */
  824. conf = &(sdata->u.mesh.mshcfg);
  825. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  826. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  827. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  828. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  829. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  830. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  831. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  832. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  833. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  834. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  835. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  836. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  837. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  838. conf->auto_open_plinks = nconf->auto_open_plinks;
  839. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  840. conf->dot11MeshHWMPmaxPREQretries =
  841. nconf->dot11MeshHWMPmaxPREQretries;
  842. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  843. conf->path_refresh_time = nconf->path_refresh_time;
  844. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  845. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  846. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  847. conf->dot11MeshHWMPactivePathTimeout =
  848. nconf->dot11MeshHWMPactivePathTimeout;
  849. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  850. conf->dot11MeshHWMPpreqMinInterval =
  851. nconf->dot11MeshHWMPpreqMinInterval;
  852. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  853. mask))
  854. conf->dot11MeshHWMPnetDiameterTraversalTime =
  855. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  856. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  857. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  858. ieee80211_mesh_root_setup(ifmsh);
  859. }
  860. return 0;
  861. }
  862. #endif
  863. static int ieee80211_change_bss(struct wiphy *wiphy,
  864. struct net_device *dev,
  865. struct bss_parameters *params)
  866. {
  867. struct ieee80211_sub_if_data *sdata;
  868. u32 changed = 0;
  869. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  870. if (params->use_cts_prot >= 0) {
  871. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  872. changed |= BSS_CHANGED_ERP_CTS_PROT;
  873. }
  874. if (params->use_short_preamble >= 0) {
  875. sdata->vif.bss_conf.use_short_preamble =
  876. params->use_short_preamble;
  877. changed |= BSS_CHANGED_ERP_PREAMBLE;
  878. }
  879. if (params->use_short_slot_time >= 0) {
  880. sdata->vif.bss_conf.use_short_slot =
  881. params->use_short_slot_time;
  882. changed |= BSS_CHANGED_ERP_SLOT;
  883. }
  884. if (params->basic_rates) {
  885. int i, j;
  886. u32 rates = 0;
  887. struct ieee80211_local *local = wiphy_priv(wiphy);
  888. struct ieee80211_supported_band *sband =
  889. wiphy->bands[local->oper_channel->band];
  890. for (i = 0; i < params->basic_rates_len; i++) {
  891. int rate = (params->basic_rates[i] & 0x7f) * 5;
  892. for (j = 0; j < sband->n_bitrates; j++) {
  893. if (sband->bitrates[j].bitrate == rate)
  894. rates |= BIT(j);
  895. }
  896. }
  897. sdata->vif.bss_conf.basic_rates = rates;
  898. changed |= BSS_CHANGED_BASIC_RATES;
  899. }
  900. ieee80211_bss_info_change_notify(sdata, changed);
  901. return 0;
  902. }
  903. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  904. struct ieee80211_txq_params *params)
  905. {
  906. struct ieee80211_local *local = wiphy_priv(wiphy);
  907. struct ieee80211_tx_queue_params p;
  908. if (!local->ops->conf_tx)
  909. return -EOPNOTSUPP;
  910. memset(&p, 0, sizeof(p));
  911. p.aifs = params->aifs;
  912. p.cw_max = params->cwmax;
  913. p.cw_min = params->cwmin;
  914. p.txop = params->txop;
  915. if (drv_conf_tx(local, params->queue, &p)) {
  916. printk(KERN_DEBUG "%s: failed to set TX queue "
  917. "parameters for queue %d\n",
  918. wiphy_name(local->hw.wiphy), params->queue);
  919. return -EINVAL;
  920. }
  921. return 0;
  922. }
  923. static int ieee80211_set_channel(struct wiphy *wiphy,
  924. struct ieee80211_channel *chan,
  925. enum nl80211_channel_type channel_type)
  926. {
  927. struct ieee80211_local *local = wiphy_priv(wiphy);
  928. local->oper_channel = chan;
  929. local->oper_channel_type = channel_type;
  930. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  931. }
  932. #ifdef CONFIG_PM
  933. static int ieee80211_suspend(struct wiphy *wiphy)
  934. {
  935. return __ieee80211_suspend(wiphy_priv(wiphy));
  936. }
  937. static int ieee80211_resume(struct wiphy *wiphy)
  938. {
  939. return __ieee80211_resume(wiphy_priv(wiphy));
  940. }
  941. #else
  942. #define ieee80211_suspend NULL
  943. #define ieee80211_resume NULL
  944. #endif
  945. static int ieee80211_scan(struct wiphy *wiphy,
  946. struct net_device *dev,
  947. struct cfg80211_scan_request *req)
  948. {
  949. struct ieee80211_sub_if_data *sdata;
  950. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  951. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  952. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  953. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  954. (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
  955. return -EOPNOTSUPP;
  956. return ieee80211_request_scan(sdata, req);
  957. }
  958. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  959. struct cfg80211_auth_request *req)
  960. {
  961. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  962. }
  963. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  964. struct cfg80211_assoc_request *req)
  965. {
  966. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  967. }
  968. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  969. struct cfg80211_deauth_request *req,
  970. void *cookie)
  971. {
  972. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  973. req, cookie);
  974. }
  975. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  976. struct cfg80211_disassoc_request *req,
  977. void *cookie)
  978. {
  979. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  980. req, cookie);
  981. }
  982. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  983. struct cfg80211_ibss_params *params)
  984. {
  985. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  986. return ieee80211_ibss_join(sdata, params);
  987. }
  988. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  989. {
  990. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  991. return ieee80211_ibss_leave(sdata);
  992. }
  993. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  994. {
  995. struct ieee80211_local *local = wiphy_priv(wiphy);
  996. int err;
  997. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  998. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  999. if (err)
  1000. return err;
  1001. }
  1002. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1003. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1004. if (changed & WIPHY_PARAM_RETRY_LONG)
  1005. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1006. if (changed &
  1007. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1008. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1009. return 0;
  1010. }
  1011. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1012. enum tx_power_setting type, int dbm)
  1013. {
  1014. struct ieee80211_local *local = wiphy_priv(wiphy);
  1015. struct ieee80211_channel *chan = local->hw.conf.channel;
  1016. u32 changes = 0;
  1017. switch (type) {
  1018. case TX_POWER_AUTOMATIC:
  1019. local->user_power_level = -1;
  1020. break;
  1021. case TX_POWER_LIMITED:
  1022. if (dbm < 0)
  1023. return -EINVAL;
  1024. local->user_power_level = dbm;
  1025. break;
  1026. case TX_POWER_FIXED:
  1027. if (dbm < 0)
  1028. return -EINVAL;
  1029. /* TODO: move to cfg80211 when it knows the channel */
  1030. if (dbm > chan->max_power)
  1031. return -EINVAL;
  1032. local->user_power_level = dbm;
  1033. break;
  1034. }
  1035. ieee80211_hw_config(local, changes);
  1036. return 0;
  1037. }
  1038. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1039. {
  1040. struct ieee80211_local *local = wiphy_priv(wiphy);
  1041. *dbm = local->hw.conf.power_level;
  1042. return 0;
  1043. }
  1044. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1045. u8 *addr)
  1046. {
  1047. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1048. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1049. return 0;
  1050. }
  1051. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1052. {
  1053. struct ieee80211_local *local = wiphy_priv(wiphy);
  1054. drv_rfkill_poll(local);
  1055. }
  1056. #ifdef CONFIG_NL80211_TESTMODE
  1057. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1058. {
  1059. struct ieee80211_local *local = wiphy_priv(wiphy);
  1060. if (!local->ops->testmode_cmd)
  1061. return -EOPNOTSUPP;
  1062. return local->ops->testmode_cmd(&local->hw, data, len);
  1063. }
  1064. #endif
  1065. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1066. enum ieee80211_smps_mode smps_mode)
  1067. {
  1068. const u8 *ap;
  1069. enum ieee80211_smps_mode old_req;
  1070. int err;
  1071. old_req = sdata->u.mgd.req_smps;
  1072. sdata->u.mgd.req_smps = smps_mode;
  1073. if (old_req == smps_mode &&
  1074. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1075. return 0;
  1076. /*
  1077. * If not associated, or current association is not an HT
  1078. * association, there's no need to send an action frame.
  1079. */
  1080. if (!sdata->u.mgd.associated ||
  1081. sdata->local->oper_channel_type == NL80211_CHAN_NO_HT) {
  1082. mutex_lock(&sdata->local->iflist_mtx);
  1083. ieee80211_recalc_smps(sdata->local, sdata);
  1084. mutex_unlock(&sdata->local->iflist_mtx);
  1085. return 0;
  1086. }
  1087. ap = sdata->u.mgd.associated->cbss.bssid;
  1088. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1089. if (sdata->u.mgd.powersave)
  1090. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1091. else
  1092. smps_mode = IEEE80211_SMPS_OFF;
  1093. }
  1094. /* send SM PS frame to AP */
  1095. err = ieee80211_send_smps_action(sdata, smps_mode,
  1096. ap, ap);
  1097. if (err)
  1098. sdata->u.mgd.req_smps = old_req;
  1099. return err;
  1100. }
  1101. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1102. bool enabled, int timeout)
  1103. {
  1104. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1105. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1106. struct ieee80211_conf *conf = &local->hw.conf;
  1107. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1108. return -EOPNOTSUPP;
  1109. if (enabled == sdata->u.mgd.powersave &&
  1110. timeout == conf->dynamic_ps_timeout)
  1111. return 0;
  1112. sdata->u.mgd.powersave = enabled;
  1113. conf->dynamic_ps_timeout = timeout;
  1114. /* no change, but if automatic follow powersave */
  1115. mutex_lock(&sdata->u.mgd.mtx);
  1116. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1117. mutex_unlock(&sdata->u.mgd.mtx);
  1118. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1119. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1120. ieee80211_recalc_ps(local, -1);
  1121. return 0;
  1122. }
  1123. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1124. struct net_device *dev,
  1125. const u8 *addr,
  1126. const struct cfg80211_bitrate_mask *mask)
  1127. {
  1128. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1129. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1130. int i, err = -EINVAL;
  1131. u32 target_rate;
  1132. struct ieee80211_supported_band *sband;
  1133. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1134. /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
  1135. * target_rate = X, rate->fixed = 1 means only rate X
  1136. * target_rate = X, rate->fixed = 0 means all rates <= X */
  1137. sdata->max_ratectrl_rateidx = -1;
  1138. sdata->force_unicast_rateidx = -1;
  1139. if (mask->fixed)
  1140. target_rate = mask->fixed / 100;
  1141. else if (mask->maxrate)
  1142. target_rate = mask->maxrate / 100;
  1143. else
  1144. return 0;
  1145. for (i=0; i< sband->n_bitrates; i++) {
  1146. struct ieee80211_rate *brate = &sband->bitrates[i];
  1147. int this_rate = brate->bitrate;
  1148. if (target_rate == this_rate) {
  1149. sdata->max_ratectrl_rateidx = i;
  1150. if (mask->fixed)
  1151. sdata->force_unicast_rateidx = i;
  1152. err = 0;
  1153. break;
  1154. }
  1155. }
  1156. return err;
  1157. }
  1158. struct cfg80211_ops mac80211_config_ops = {
  1159. .add_virtual_intf = ieee80211_add_iface,
  1160. .del_virtual_intf = ieee80211_del_iface,
  1161. .change_virtual_intf = ieee80211_change_iface,
  1162. .add_key = ieee80211_add_key,
  1163. .del_key = ieee80211_del_key,
  1164. .get_key = ieee80211_get_key,
  1165. .set_default_key = ieee80211_config_default_key,
  1166. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1167. .add_beacon = ieee80211_add_beacon,
  1168. .set_beacon = ieee80211_set_beacon,
  1169. .del_beacon = ieee80211_del_beacon,
  1170. .add_station = ieee80211_add_station,
  1171. .del_station = ieee80211_del_station,
  1172. .change_station = ieee80211_change_station,
  1173. .get_station = ieee80211_get_station,
  1174. .dump_station = ieee80211_dump_station,
  1175. #ifdef CONFIG_MAC80211_MESH
  1176. .add_mpath = ieee80211_add_mpath,
  1177. .del_mpath = ieee80211_del_mpath,
  1178. .change_mpath = ieee80211_change_mpath,
  1179. .get_mpath = ieee80211_get_mpath,
  1180. .dump_mpath = ieee80211_dump_mpath,
  1181. .set_mesh_params = ieee80211_set_mesh_params,
  1182. .get_mesh_params = ieee80211_get_mesh_params,
  1183. #endif
  1184. .change_bss = ieee80211_change_bss,
  1185. .set_txq_params = ieee80211_set_txq_params,
  1186. .set_channel = ieee80211_set_channel,
  1187. .suspend = ieee80211_suspend,
  1188. .resume = ieee80211_resume,
  1189. .scan = ieee80211_scan,
  1190. .auth = ieee80211_auth,
  1191. .assoc = ieee80211_assoc,
  1192. .deauth = ieee80211_deauth,
  1193. .disassoc = ieee80211_disassoc,
  1194. .join_ibss = ieee80211_join_ibss,
  1195. .leave_ibss = ieee80211_leave_ibss,
  1196. .set_wiphy_params = ieee80211_set_wiphy_params,
  1197. .set_tx_power = ieee80211_set_tx_power,
  1198. .get_tx_power = ieee80211_get_tx_power,
  1199. .set_wds_peer = ieee80211_set_wds_peer,
  1200. .rfkill_poll = ieee80211_rfkill_poll,
  1201. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1202. .set_power_mgmt = ieee80211_set_power_mgmt,
  1203. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1204. };