cfg.c 33 KB

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