cfg.c 33 KB

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