cfg.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  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. params->seq_len, params->seq);
  122. if (!key)
  123. return -ENOMEM;
  124. rcu_read_lock();
  125. if (mac_addr) {
  126. sta = sta_info_get(sdata->local, mac_addr);
  127. if (!sta) {
  128. ieee80211_key_free(key);
  129. err = -ENOENT;
  130. goto out_unlock;
  131. }
  132. }
  133. ieee80211_key_link(key, sdata, sta);
  134. err = 0;
  135. out_unlock:
  136. rcu_read_unlock();
  137. return err;
  138. }
  139. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  140. u8 key_idx, const u8 *mac_addr)
  141. {
  142. struct ieee80211_sub_if_data *sdata;
  143. struct sta_info *sta;
  144. int ret;
  145. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  146. rcu_read_lock();
  147. if (mac_addr) {
  148. ret = -ENOENT;
  149. sta = sta_info_get(sdata->local, mac_addr);
  150. if (!sta)
  151. goto out_unlock;
  152. if (sta->key) {
  153. ieee80211_key_free(sta->key);
  154. WARN_ON(sta->key);
  155. ret = 0;
  156. }
  157. goto out_unlock;
  158. }
  159. if (!sdata->keys[key_idx]) {
  160. ret = -ENOENT;
  161. goto out_unlock;
  162. }
  163. ieee80211_key_free(sdata->keys[key_idx]);
  164. WARN_ON(sdata->keys[key_idx]);
  165. ret = 0;
  166. out_unlock:
  167. rcu_read_unlock();
  168. return ret;
  169. }
  170. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  171. u8 key_idx, const u8 *mac_addr, void *cookie,
  172. void (*callback)(void *cookie,
  173. struct key_params *params))
  174. {
  175. struct ieee80211_sub_if_data *sdata;
  176. struct sta_info *sta = NULL;
  177. u8 seq[6] = {0};
  178. struct key_params params;
  179. struct ieee80211_key *key;
  180. u32 iv32;
  181. u16 iv16;
  182. int err = -ENOENT;
  183. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  184. rcu_read_lock();
  185. if (mac_addr) {
  186. sta = sta_info_get(sdata->local, mac_addr);
  187. if (!sta)
  188. goto out;
  189. key = sta->key;
  190. } else
  191. key = sdata->keys[key_idx];
  192. if (!key)
  193. goto out;
  194. memset(&params, 0, sizeof(params));
  195. switch (key->conf.alg) {
  196. case ALG_TKIP:
  197. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  198. iv32 = key->u.tkip.tx.iv32;
  199. iv16 = key->u.tkip.tx.iv16;
  200. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  201. drv_get_tkip_seq(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 &&
  367. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  368. sdata->vif.bss_conf.beacon_int = params->interval;
  369. ieee80211_bss_info_change_notify(sdata,
  370. BSS_CHANGED_BEACON_INT);
  371. }
  372. /* Need to have a beacon head if we don't have one yet */
  373. if (!params->head && !old)
  374. return err;
  375. /* sorry, no way to start beaconing without dtim period */
  376. if (!params->dtim_period && !old)
  377. return err;
  378. /* new or old head? */
  379. if (params->head)
  380. new_head_len = params->head_len;
  381. else
  382. new_head_len = old->head_len;
  383. /* new or old tail? */
  384. if (params->tail || !old)
  385. /* params->tail_len will be zero for !params->tail */
  386. new_tail_len = params->tail_len;
  387. else
  388. new_tail_len = old->tail_len;
  389. size = sizeof(*new) + new_head_len + new_tail_len;
  390. new = kzalloc(size, GFP_KERNEL);
  391. if (!new)
  392. return -ENOMEM;
  393. /* start filling the new info now */
  394. /* new or old dtim period? */
  395. if (params->dtim_period)
  396. new->dtim_period = params->dtim_period;
  397. else
  398. new->dtim_period = old->dtim_period;
  399. /*
  400. * pointers go into the block we allocated,
  401. * memory is | beacon_data | head | tail |
  402. */
  403. new->head = ((u8 *) new) + sizeof(*new);
  404. new->tail = new->head + new_head_len;
  405. new->head_len = new_head_len;
  406. new->tail_len = new_tail_len;
  407. /* copy in head */
  408. if (params->head)
  409. memcpy(new->head, params->head, new_head_len);
  410. else
  411. memcpy(new->head, old->head, new_head_len);
  412. /* copy in optional tail */
  413. if (params->tail)
  414. memcpy(new->tail, params->tail, new_tail_len);
  415. else
  416. if (old)
  417. memcpy(new->tail, old->tail, new_tail_len);
  418. rcu_assign_pointer(sdata->u.ap.beacon, new);
  419. synchronize_rcu();
  420. kfree(old);
  421. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  422. BSS_CHANGED_BEACON);
  423. return 0;
  424. }
  425. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  426. struct beacon_parameters *params)
  427. {
  428. struct ieee80211_sub_if_data *sdata;
  429. struct beacon_data *old;
  430. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  431. old = sdata->u.ap.beacon;
  432. if (old)
  433. return -EALREADY;
  434. return ieee80211_config_beacon(sdata, params);
  435. }
  436. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  437. struct beacon_parameters *params)
  438. {
  439. struct ieee80211_sub_if_data *sdata;
  440. struct beacon_data *old;
  441. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  442. old = sdata->u.ap.beacon;
  443. if (!old)
  444. return -ENOENT;
  445. return ieee80211_config_beacon(sdata, params);
  446. }
  447. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  448. {
  449. struct ieee80211_sub_if_data *sdata;
  450. struct beacon_data *old;
  451. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  452. old = sdata->u.ap.beacon;
  453. if (!old)
  454. return -ENOENT;
  455. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  456. synchronize_rcu();
  457. kfree(old);
  458. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  459. return 0;
  460. }
  461. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  462. struct iapp_layer2_update {
  463. u8 da[ETH_ALEN]; /* broadcast */
  464. u8 sa[ETH_ALEN]; /* STA addr */
  465. __be16 len; /* 6 */
  466. u8 dsap; /* 0 */
  467. u8 ssap; /* 0 */
  468. u8 control;
  469. u8 xid_info[3];
  470. } __attribute__ ((packed));
  471. static void ieee80211_send_layer2_update(struct sta_info *sta)
  472. {
  473. struct iapp_layer2_update *msg;
  474. struct sk_buff *skb;
  475. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  476. * bridge devices */
  477. skb = dev_alloc_skb(sizeof(*msg));
  478. if (!skb)
  479. return;
  480. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  481. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  482. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  483. memset(msg->da, 0xff, ETH_ALEN);
  484. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  485. msg->len = htons(6);
  486. msg->dsap = 0;
  487. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  488. msg->control = 0xaf; /* XID response lsb.1111F101.
  489. * F=0 (no poll command; unsolicited frame) */
  490. msg->xid_info[0] = 0x81; /* XID format identifier */
  491. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  492. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  493. skb->dev = sta->sdata->dev;
  494. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  495. memset(skb->cb, 0, sizeof(skb->cb));
  496. netif_rx(skb);
  497. }
  498. static void sta_apply_parameters(struct ieee80211_local *local,
  499. struct sta_info *sta,
  500. struct station_parameters *params)
  501. {
  502. u32 rates;
  503. int i, j;
  504. struct ieee80211_supported_band *sband;
  505. struct ieee80211_sub_if_data *sdata = sta->sdata;
  506. u32 mask, set;
  507. sband = local->hw.wiphy->bands[local->oper_channel->band];
  508. spin_lock_bh(&sta->lock);
  509. mask = params->sta_flags_mask;
  510. set = params->sta_flags_set;
  511. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  512. sta->flags &= ~WLAN_STA_AUTHORIZED;
  513. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  514. sta->flags |= WLAN_STA_AUTHORIZED;
  515. }
  516. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  517. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  518. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  519. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  520. }
  521. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  522. sta->flags &= ~WLAN_STA_WME;
  523. if (set & BIT(NL80211_STA_FLAG_WME))
  524. sta->flags |= WLAN_STA_WME;
  525. }
  526. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  527. sta->flags &= ~WLAN_STA_MFP;
  528. if (set & BIT(NL80211_STA_FLAG_MFP))
  529. sta->flags |= WLAN_STA_MFP;
  530. }
  531. spin_unlock_bh(&sta->lock);
  532. /*
  533. * FIXME: updating the following information is racy when this
  534. * function is called from ieee80211_change_station().
  535. * However, all this information should be static so
  536. * maybe we should just reject attemps to change it.
  537. */
  538. if (params->aid) {
  539. sta->sta.aid = params->aid;
  540. if (sta->sta.aid > IEEE80211_MAX_AID)
  541. sta->sta.aid = 0; /* XXX: should this be an error? */
  542. }
  543. if (params->listen_interval >= 0)
  544. sta->listen_interval = params->listen_interval;
  545. if (params->supported_rates) {
  546. rates = 0;
  547. for (i = 0; i < params->supported_rates_len; i++) {
  548. int rate = (params->supported_rates[i] & 0x7f) * 5;
  549. for (j = 0; j < sband->n_bitrates; j++) {
  550. if (sband->bitrates[j].bitrate == rate)
  551. rates |= BIT(j);
  552. }
  553. }
  554. sta->sta.supp_rates[local->oper_channel->band] = rates;
  555. }
  556. if (params->ht_capa)
  557. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  558. params->ht_capa,
  559. &sta->sta.ht_cap);
  560. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  561. switch (params->plink_action) {
  562. case PLINK_ACTION_OPEN:
  563. mesh_plink_open(sta);
  564. break;
  565. case PLINK_ACTION_BLOCK:
  566. mesh_plink_block(sta);
  567. break;
  568. }
  569. }
  570. }
  571. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  572. u8 *mac, struct station_parameters *params)
  573. {
  574. struct ieee80211_local *local = wiphy_priv(wiphy);
  575. struct sta_info *sta;
  576. struct ieee80211_sub_if_data *sdata;
  577. int err;
  578. int layer2_update;
  579. if (params->vlan) {
  580. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  581. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  582. sdata->vif.type != NL80211_IFTYPE_AP)
  583. return -EINVAL;
  584. } else
  585. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  586. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  587. return -EINVAL;
  588. if (is_multicast_ether_addr(mac))
  589. return -EINVAL;
  590. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  591. if (!sta)
  592. return -ENOMEM;
  593. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  594. sta_apply_parameters(local, sta, params);
  595. rate_control_rate_init(sta);
  596. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  597. sdata->vif.type == NL80211_IFTYPE_AP;
  598. rcu_read_lock();
  599. err = sta_info_insert(sta);
  600. if (err) {
  601. /* STA has been freed */
  602. if (err == -EEXIST && layer2_update) {
  603. /* Need to update layer 2 devices on reassociation */
  604. sta = sta_info_get(local, mac);
  605. if (sta)
  606. ieee80211_send_layer2_update(sta);
  607. }
  608. rcu_read_unlock();
  609. return err;
  610. }
  611. if (layer2_update)
  612. ieee80211_send_layer2_update(sta);
  613. rcu_read_unlock();
  614. return 0;
  615. }
  616. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  617. u8 *mac)
  618. {
  619. struct ieee80211_local *local = wiphy_priv(wiphy);
  620. struct ieee80211_sub_if_data *sdata;
  621. struct sta_info *sta;
  622. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  623. if (mac) {
  624. rcu_read_lock();
  625. /* XXX: get sta belonging to dev */
  626. sta = sta_info_get(local, mac);
  627. if (!sta) {
  628. rcu_read_unlock();
  629. return -ENOENT;
  630. }
  631. sta_info_unlink(&sta);
  632. rcu_read_unlock();
  633. sta_info_destroy(sta);
  634. } else
  635. sta_info_flush(local, sdata);
  636. return 0;
  637. }
  638. static int ieee80211_change_station(struct wiphy *wiphy,
  639. struct net_device *dev,
  640. u8 *mac,
  641. struct station_parameters *params)
  642. {
  643. struct ieee80211_local *local = wiphy_priv(wiphy);
  644. struct sta_info *sta;
  645. struct ieee80211_sub_if_data *vlansdata;
  646. rcu_read_lock();
  647. /* XXX: get sta belonging to dev */
  648. sta = sta_info_get(local, mac);
  649. if (!sta) {
  650. rcu_read_unlock();
  651. return -ENOENT;
  652. }
  653. if (params->vlan && params->vlan != sta->sdata->dev) {
  654. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  655. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  656. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  657. rcu_read_unlock();
  658. return -EINVAL;
  659. }
  660. sta->sdata = vlansdata;
  661. ieee80211_send_layer2_update(sta);
  662. }
  663. sta_apply_parameters(local, sta, params);
  664. rcu_read_unlock();
  665. return 0;
  666. }
  667. #ifdef CONFIG_MAC80211_MESH
  668. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  669. u8 *dst, u8 *next_hop)
  670. {
  671. struct ieee80211_local *local = wiphy_priv(wiphy);
  672. struct ieee80211_sub_if_data *sdata;
  673. struct mesh_path *mpath;
  674. struct sta_info *sta;
  675. int err;
  676. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  677. rcu_read_lock();
  678. sta = sta_info_get(local, next_hop);
  679. if (!sta) {
  680. rcu_read_unlock();
  681. return -ENOENT;
  682. }
  683. err = mesh_path_add(dst, sdata);
  684. if (err) {
  685. rcu_read_unlock();
  686. return err;
  687. }
  688. mpath = mesh_path_lookup(dst, sdata);
  689. if (!mpath) {
  690. rcu_read_unlock();
  691. return -ENXIO;
  692. }
  693. mesh_path_fix_nexthop(mpath, sta);
  694. rcu_read_unlock();
  695. return 0;
  696. }
  697. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  698. u8 *dst)
  699. {
  700. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  701. if (dst)
  702. return mesh_path_del(dst, sdata);
  703. mesh_path_flush(sdata);
  704. return 0;
  705. }
  706. static int ieee80211_change_mpath(struct wiphy *wiphy,
  707. struct net_device *dev,
  708. u8 *dst, u8 *next_hop)
  709. {
  710. struct ieee80211_local *local = wiphy_priv(wiphy);
  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(local, 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->filled = MPATH_INFO_FRAME_QLEN |
  738. MPATH_INFO_DSN |
  739. MPATH_INFO_METRIC |
  740. MPATH_INFO_EXPTIME |
  741. MPATH_INFO_DISCOVERY_TIMEOUT |
  742. MPATH_INFO_DISCOVERY_RETRIES |
  743. MPATH_INFO_FLAGS;
  744. pinfo->frame_qlen = mpath->frame_queue.qlen;
  745. pinfo->dsn = mpath->dsn;
  746. pinfo->metric = mpath->metric;
  747. if (time_before(jiffies, mpath->exp_time))
  748. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  749. pinfo->discovery_timeout =
  750. jiffies_to_msecs(mpath->discovery_timeout);
  751. pinfo->discovery_retries = mpath->discovery_retries;
  752. pinfo->flags = 0;
  753. if (mpath->flags & MESH_PATH_ACTIVE)
  754. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  755. if (mpath->flags & MESH_PATH_RESOLVING)
  756. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  757. if (mpath->flags & MESH_PATH_DSN_VALID)
  758. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  759. if (mpath->flags & MESH_PATH_FIXED)
  760. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  761. if (mpath->flags & MESH_PATH_RESOLVING)
  762. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  763. pinfo->flags = mpath->flags;
  764. }
  765. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  766. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  767. {
  768. struct ieee80211_sub_if_data *sdata;
  769. struct mesh_path *mpath;
  770. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  771. rcu_read_lock();
  772. mpath = mesh_path_lookup(dst, sdata);
  773. if (!mpath) {
  774. rcu_read_unlock();
  775. return -ENOENT;
  776. }
  777. memcpy(dst, mpath->dst, ETH_ALEN);
  778. mpath_set_pinfo(mpath, next_hop, pinfo);
  779. rcu_read_unlock();
  780. return 0;
  781. }
  782. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  783. int idx, u8 *dst, u8 *next_hop,
  784. 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. rcu_read_lock();
  790. mpath = mesh_path_lookup_by_idx(idx, sdata);
  791. if (!mpath) {
  792. rcu_read_unlock();
  793. return -ENOENT;
  794. }
  795. memcpy(dst, mpath->dst, ETH_ALEN);
  796. mpath_set_pinfo(mpath, next_hop, pinfo);
  797. rcu_read_unlock();
  798. return 0;
  799. }
  800. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  801. struct net_device *dev,
  802. struct mesh_config *conf)
  803. {
  804. struct ieee80211_sub_if_data *sdata;
  805. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  806. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  807. return 0;
  808. }
  809. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  810. {
  811. return (mask >> (parm-1)) & 0x1;
  812. }
  813. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  814. struct net_device *dev,
  815. const struct mesh_config *nconf, u32 mask)
  816. {
  817. struct mesh_config *conf;
  818. struct ieee80211_sub_if_data *sdata;
  819. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  820. /* Set the config options which we are interested in setting */
  821. conf = &(sdata->u.mesh.mshcfg);
  822. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  823. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  824. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  825. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  826. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  827. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  828. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  829. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  830. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  831. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  832. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  833. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  834. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  835. conf->auto_open_plinks = nconf->auto_open_plinks;
  836. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  837. conf->dot11MeshHWMPmaxPREQretries =
  838. nconf->dot11MeshHWMPmaxPREQretries;
  839. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  840. conf->path_refresh_time = nconf->path_refresh_time;
  841. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  842. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  843. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  844. conf->dot11MeshHWMPactivePathTimeout =
  845. nconf->dot11MeshHWMPactivePathTimeout;
  846. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  847. conf->dot11MeshHWMPpreqMinInterval =
  848. nconf->dot11MeshHWMPpreqMinInterval;
  849. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  850. mask))
  851. conf->dot11MeshHWMPnetDiameterTraversalTime =
  852. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  853. return 0;
  854. }
  855. #endif
  856. static int ieee80211_change_bss(struct wiphy *wiphy,
  857. struct net_device *dev,
  858. struct bss_parameters *params)
  859. {
  860. struct ieee80211_sub_if_data *sdata;
  861. u32 changed = 0;
  862. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  863. if (params->use_cts_prot >= 0) {
  864. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  865. changed |= BSS_CHANGED_ERP_CTS_PROT;
  866. }
  867. if (params->use_short_preamble >= 0) {
  868. sdata->vif.bss_conf.use_short_preamble =
  869. params->use_short_preamble;
  870. changed |= BSS_CHANGED_ERP_PREAMBLE;
  871. }
  872. if (params->use_short_slot_time >= 0) {
  873. sdata->vif.bss_conf.use_short_slot =
  874. params->use_short_slot_time;
  875. changed |= BSS_CHANGED_ERP_SLOT;
  876. }
  877. if (params->basic_rates) {
  878. int i, j;
  879. u32 rates = 0;
  880. struct ieee80211_local *local = wiphy_priv(wiphy);
  881. struct ieee80211_supported_band *sband =
  882. wiphy->bands[local->oper_channel->band];
  883. for (i = 0; i < params->basic_rates_len; i++) {
  884. int rate = (params->basic_rates[i] & 0x7f) * 5;
  885. for (j = 0; j < sband->n_bitrates; j++) {
  886. if (sband->bitrates[j].bitrate == rate)
  887. rates |= BIT(j);
  888. }
  889. }
  890. sdata->vif.bss_conf.basic_rates = rates;
  891. changed |= BSS_CHANGED_BASIC_RATES;
  892. }
  893. ieee80211_bss_info_change_notify(sdata, changed);
  894. return 0;
  895. }
  896. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  897. struct ieee80211_txq_params *params)
  898. {
  899. struct ieee80211_local *local = wiphy_priv(wiphy);
  900. struct ieee80211_tx_queue_params p;
  901. if (!local->ops->conf_tx)
  902. return -EOPNOTSUPP;
  903. memset(&p, 0, sizeof(p));
  904. p.aifs = params->aifs;
  905. p.cw_max = params->cwmax;
  906. p.cw_min = params->cwmin;
  907. p.txop = params->txop;
  908. if (drv_conf_tx(local, params->queue, &p)) {
  909. printk(KERN_DEBUG "%s: failed to set TX queue "
  910. "parameters for queue %d\n", local->mdev->name,
  911. params->queue);
  912. return -EINVAL;
  913. }
  914. return 0;
  915. }
  916. static int ieee80211_set_channel(struct wiphy *wiphy,
  917. struct ieee80211_channel *chan,
  918. enum nl80211_channel_type channel_type)
  919. {
  920. struct ieee80211_local *local = wiphy_priv(wiphy);
  921. local->oper_channel = chan;
  922. local->oper_channel_type = channel_type;
  923. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  924. }
  925. #ifdef CONFIG_PM
  926. static int ieee80211_suspend(struct wiphy *wiphy)
  927. {
  928. return __ieee80211_suspend(wiphy_priv(wiphy));
  929. }
  930. static int ieee80211_resume(struct wiphy *wiphy)
  931. {
  932. return __ieee80211_resume(wiphy_priv(wiphy));
  933. }
  934. #else
  935. #define ieee80211_suspend NULL
  936. #define ieee80211_resume NULL
  937. #endif
  938. static int ieee80211_scan(struct wiphy *wiphy,
  939. struct net_device *dev,
  940. struct cfg80211_scan_request *req)
  941. {
  942. struct ieee80211_sub_if_data *sdata;
  943. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  944. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  945. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  946. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  947. (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
  948. return -EOPNOTSUPP;
  949. return ieee80211_request_scan(sdata, req);
  950. }
  951. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  952. struct cfg80211_auth_request *req)
  953. {
  954. struct ieee80211_sub_if_data *sdata;
  955. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  956. switch (req->auth_type) {
  957. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  958. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
  959. break;
  960. case NL80211_AUTHTYPE_SHARED_KEY:
  961. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
  962. break;
  963. case NL80211_AUTHTYPE_FT:
  964. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
  965. break;
  966. case NL80211_AUTHTYPE_NETWORK_EAP:
  967. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
  968. break;
  969. default:
  970. return -EOPNOTSUPP;
  971. }
  972. memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
  973. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  974. sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
  975. /* TODO: req->chan */
  976. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
  977. if (req->ssid) {
  978. sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
  979. memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
  980. sdata->u.mgd.ssid_len = req->ssid_len;
  981. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  982. }
  983. kfree(sdata->u.mgd.sme_auth_ie);
  984. sdata->u.mgd.sme_auth_ie = NULL;
  985. sdata->u.mgd.sme_auth_ie_len = 0;
  986. if (req->ie) {
  987. sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
  988. if (sdata->u.mgd.sme_auth_ie == NULL)
  989. return -ENOMEM;
  990. memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
  991. sdata->u.mgd.sme_auth_ie_len = req->ie_len;
  992. }
  993. sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
  994. sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
  995. ieee80211_sta_req_auth(sdata);
  996. return 0;
  997. }
  998. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  999. struct cfg80211_assoc_request *req)
  1000. {
  1001. struct ieee80211_sub_if_data *sdata;
  1002. int ret;
  1003. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1004. if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
  1005. !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
  1006. return -ENOLINK; /* not authenticated */
  1007. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  1008. sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
  1009. /* TODO: req->chan */
  1010. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
  1011. if (req->ssid) {
  1012. sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
  1013. memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
  1014. sdata->u.mgd.ssid_len = req->ssid_len;
  1015. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  1016. } else
  1017. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
  1018. ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
  1019. if (ret)
  1020. return ret;
  1021. if (req->use_mfp) {
  1022. sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
  1023. sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
  1024. } else {
  1025. sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
  1026. sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
  1027. }
  1028. if (req->control_port)
  1029. sdata->u.mgd.flags |= IEEE80211_STA_CONTROL_PORT;
  1030. else
  1031. sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
  1032. sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
  1033. sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
  1034. ieee80211_sta_req_auth(sdata);
  1035. return 0;
  1036. }
  1037. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1038. struct cfg80211_deauth_request *req)
  1039. {
  1040. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1041. /* TODO: req->ie, req->peer_addr */
  1042. return ieee80211_sta_deauthenticate(sdata, req->reason_code);
  1043. }
  1044. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1045. struct cfg80211_disassoc_request *req)
  1046. {
  1047. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1048. /* TODO: req->ie, req->peer_addr */
  1049. return ieee80211_sta_disassociate(sdata, req->reason_code);
  1050. }
  1051. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1052. struct cfg80211_ibss_params *params)
  1053. {
  1054. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1055. return ieee80211_ibss_join(sdata, params);
  1056. }
  1057. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1058. {
  1059. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1060. return ieee80211_ibss_leave(sdata);
  1061. }
  1062. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1063. {
  1064. struct ieee80211_local *local = wiphy_priv(wiphy);
  1065. int err;
  1066. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1067. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1068. if (err)
  1069. return err;
  1070. }
  1071. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1072. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1073. if (changed & WIPHY_PARAM_RETRY_LONG)
  1074. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1075. if (changed &
  1076. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1077. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1078. return 0;
  1079. }
  1080. struct cfg80211_ops mac80211_config_ops = {
  1081. .add_virtual_intf = ieee80211_add_iface,
  1082. .del_virtual_intf = ieee80211_del_iface,
  1083. .change_virtual_intf = ieee80211_change_iface,
  1084. .add_key = ieee80211_add_key,
  1085. .del_key = ieee80211_del_key,
  1086. .get_key = ieee80211_get_key,
  1087. .set_default_key = ieee80211_config_default_key,
  1088. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1089. .add_beacon = ieee80211_add_beacon,
  1090. .set_beacon = ieee80211_set_beacon,
  1091. .del_beacon = ieee80211_del_beacon,
  1092. .add_station = ieee80211_add_station,
  1093. .del_station = ieee80211_del_station,
  1094. .change_station = ieee80211_change_station,
  1095. .get_station = ieee80211_get_station,
  1096. .dump_station = ieee80211_dump_station,
  1097. #ifdef CONFIG_MAC80211_MESH
  1098. .add_mpath = ieee80211_add_mpath,
  1099. .del_mpath = ieee80211_del_mpath,
  1100. .change_mpath = ieee80211_change_mpath,
  1101. .get_mpath = ieee80211_get_mpath,
  1102. .dump_mpath = ieee80211_dump_mpath,
  1103. .set_mesh_params = ieee80211_set_mesh_params,
  1104. .get_mesh_params = ieee80211_get_mesh_params,
  1105. #endif
  1106. .change_bss = ieee80211_change_bss,
  1107. .set_txq_params = ieee80211_set_txq_params,
  1108. .set_channel = ieee80211_set_channel,
  1109. .suspend = ieee80211_suspend,
  1110. .resume = ieee80211_resume,
  1111. .scan = ieee80211_scan,
  1112. .auth = ieee80211_auth,
  1113. .assoc = ieee80211_assoc,
  1114. .deauth = ieee80211_deauth,
  1115. .disassoc = ieee80211_disassoc,
  1116. .join_ibss = ieee80211_join_ibss,
  1117. .leave_ibss = ieee80211_leave_ibss,
  1118. .set_wiphy_params = ieee80211_set_wiphy_params,
  1119. };