cfg.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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. * cfg80211 validates this (1-2007) and allows setting the AID
  534. * only when creating a new station entry
  535. */
  536. if (params->aid)
  537. sta->sta.aid = params->aid;
  538. /*
  539. * FIXME: updating the following information is racy when this
  540. * function is called from ieee80211_change_station().
  541. * However, all this information should be static so
  542. * maybe we should just reject attemps to change it.
  543. */
  544. if (params->listen_interval >= 0)
  545. sta->listen_interval = params->listen_interval;
  546. if (params->supported_rates) {
  547. rates = 0;
  548. for (i = 0; i < params->supported_rates_len; i++) {
  549. int rate = (params->supported_rates[i] & 0x7f) * 5;
  550. for (j = 0; j < sband->n_bitrates; j++) {
  551. if (sband->bitrates[j].bitrate == rate)
  552. rates |= BIT(j);
  553. }
  554. }
  555. sta->sta.supp_rates[local->oper_channel->band] = rates;
  556. }
  557. if (params->ht_capa)
  558. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  559. params->ht_capa,
  560. &sta->sta.ht_cap);
  561. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  562. switch (params->plink_action) {
  563. case PLINK_ACTION_OPEN:
  564. mesh_plink_open(sta);
  565. break;
  566. case PLINK_ACTION_BLOCK:
  567. mesh_plink_block(sta);
  568. break;
  569. }
  570. }
  571. }
  572. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  573. u8 *mac, struct station_parameters *params)
  574. {
  575. struct ieee80211_local *local = wiphy_priv(wiphy);
  576. struct sta_info *sta;
  577. struct ieee80211_sub_if_data *sdata;
  578. int err;
  579. int layer2_update;
  580. if (params->vlan) {
  581. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  582. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  583. sdata->vif.type != NL80211_IFTYPE_AP)
  584. return -EINVAL;
  585. } else
  586. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  587. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  588. return -EINVAL;
  589. if (is_multicast_ether_addr(mac))
  590. return -EINVAL;
  591. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  592. if (!sta)
  593. return -ENOMEM;
  594. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  595. sta_apply_parameters(local, sta, params);
  596. rate_control_rate_init(sta);
  597. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  598. sdata->vif.type == NL80211_IFTYPE_AP;
  599. rcu_read_lock();
  600. err = sta_info_insert(sta);
  601. if (err) {
  602. /* STA has been freed */
  603. if (err == -EEXIST && layer2_update) {
  604. /* Need to update layer 2 devices on reassociation */
  605. sta = sta_info_get(local, mac);
  606. if (sta)
  607. ieee80211_send_layer2_update(sta);
  608. }
  609. rcu_read_unlock();
  610. return err;
  611. }
  612. if (layer2_update)
  613. ieee80211_send_layer2_update(sta);
  614. rcu_read_unlock();
  615. return 0;
  616. }
  617. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  618. u8 *mac)
  619. {
  620. struct ieee80211_local *local = wiphy_priv(wiphy);
  621. struct ieee80211_sub_if_data *sdata;
  622. struct sta_info *sta;
  623. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  624. if (mac) {
  625. rcu_read_lock();
  626. /* XXX: get sta belonging to dev */
  627. sta = sta_info_get(local, mac);
  628. if (!sta) {
  629. rcu_read_unlock();
  630. return -ENOENT;
  631. }
  632. sta_info_unlink(&sta);
  633. rcu_read_unlock();
  634. sta_info_destroy(sta);
  635. } else
  636. sta_info_flush(local, sdata);
  637. return 0;
  638. }
  639. static int ieee80211_change_station(struct wiphy *wiphy,
  640. struct net_device *dev,
  641. u8 *mac,
  642. struct station_parameters *params)
  643. {
  644. struct ieee80211_local *local = wiphy_priv(wiphy);
  645. struct sta_info *sta;
  646. struct ieee80211_sub_if_data *vlansdata;
  647. rcu_read_lock();
  648. /* XXX: get sta belonging to dev */
  649. sta = sta_info_get(local, mac);
  650. if (!sta) {
  651. rcu_read_unlock();
  652. return -ENOENT;
  653. }
  654. if (params->vlan && params->vlan != sta->sdata->dev) {
  655. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  656. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  657. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  658. rcu_read_unlock();
  659. return -EINVAL;
  660. }
  661. sta->sdata = vlansdata;
  662. ieee80211_send_layer2_update(sta);
  663. }
  664. sta_apply_parameters(local, sta, params);
  665. rcu_read_unlock();
  666. return 0;
  667. }
  668. #ifdef CONFIG_MAC80211_MESH
  669. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  670. u8 *dst, u8 *next_hop)
  671. {
  672. struct ieee80211_local *local = wiphy_priv(wiphy);
  673. struct ieee80211_sub_if_data *sdata;
  674. struct mesh_path *mpath;
  675. struct sta_info *sta;
  676. int err;
  677. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  678. rcu_read_lock();
  679. sta = sta_info_get(local, next_hop);
  680. if (!sta) {
  681. rcu_read_unlock();
  682. return -ENOENT;
  683. }
  684. err = mesh_path_add(dst, sdata);
  685. if (err) {
  686. rcu_read_unlock();
  687. return err;
  688. }
  689. mpath = mesh_path_lookup(dst, sdata);
  690. if (!mpath) {
  691. rcu_read_unlock();
  692. return -ENXIO;
  693. }
  694. mesh_path_fix_nexthop(mpath, sta);
  695. rcu_read_unlock();
  696. return 0;
  697. }
  698. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  699. u8 *dst)
  700. {
  701. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  702. if (dst)
  703. return mesh_path_del(dst, sdata);
  704. mesh_path_flush(sdata);
  705. return 0;
  706. }
  707. static int ieee80211_change_mpath(struct wiphy *wiphy,
  708. struct net_device *dev,
  709. u8 *dst, u8 *next_hop)
  710. {
  711. struct ieee80211_local *local = wiphy_priv(wiphy);
  712. struct ieee80211_sub_if_data *sdata;
  713. struct mesh_path *mpath;
  714. struct sta_info *sta;
  715. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  716. rcu_read_lock();
  717. sta = sta_info_get(local, next_hop);
  718. if (!sta) {
  719. rcu_read_unlock();
  720. return -ENOENT;
  721. }
  722. mpath = mesh_path_lookup(dst, sdata);
  723. if (!mpath) {
  724. rcu_read_unlock();
  725. return -ENOENT;
  726. }
  727. mesh_path_fix_nexthop(mpath, sta);
  728. rcu_read_unlock();
  729. return 0;
  730. }
  731. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  732. struct mpath_info *pinfo)
  733. {
  734. if (mpath->next_hop)
  735. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  736. else
  737. memset(next_hop, 0, ETH_ALEN);
  738. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  739. MPATH_INFO_DSN |
  740. MPATH_INFO_METRIC |
  741. MPATH_INFO_EXPTIME |
  742. MPATH_INFO_DISCOVERY_TIMEOUT |
  743. MPATH_INFO_DISCOVERY_RETRIES |
  744. MPATH_INFO_FLAGS;
  745. pinfo->frame_qlen = mpath->frame_queue.qlen;
  746. pinfo->dsn = mpath->dsn;
  747. pinfo->metric = mpath->metric;
  748. if (time_before(jiffies, mpath->exp_time))
  749. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  750. pinfo->discovery_timeout =
  751. jiffies_to_msecs(mpath->discovery_timeout);
  752. pinfo->discovery_retries = mpath->discovery_retries;
  753. pinfo->flags = 0;
  754. if (mpath->flags & MESH_PATH_ACTIVE)
  755. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  756. if (mpath->flags & MESH_PATH_RESOLVING)
  757. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  758. if (mpath->flags & MESH_PATH_DSN_VALID)
  759. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  760. if (mpath->flags & MESH_PATH_FIXED)
  761. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  762. if (mpath->flags & MESH_PATH_RESOLVING)
  763. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  764. pinfo->flags = mpath->flags;
  765. }
  766. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  767. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  768. {
  769. struct ieee80211_sub_if_data *sdata;
  770. struct mesh_path *mpath;
  771. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  772. rcu_read_lock();
  773. mpath = mesh_path_lookup(dst, sdata);
  774. if (!mpath) {
  775. rcu_read_unlock();
  776. return -ENOENT;
  777. }
  778. memcpy(dst, mpath->dst, ETH_ALEN);
  779. mpath_set_pinfo(mpath, next_hop, pinfo);
  780. rcu_read_unlock();
  781. return 0;
  782. }
  783. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  784. int idx, u8 *dst, u8 *next_hop,
  785. struct mpath_info *pinfo)
  786. {
  787. struct ieee80211_sub_if_data *sdata;
  788. struct mesh_path *mpath;
  789. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  790. rcu_read_lock();
  791. mpath = mesh_path_lookup_by_idx(idx, sdata);
  792. if (!mpath) {
  793. rcu_read_unlock();
  794. return -ENOENT;
  795. }
  796. memcpy(dst, mpath->dst, ETH_ALEN);
  797. mpath_set_pinfo(mpath, next_hop, pinfo);
  798. rcu_read_unlock();
  799. return 0;
  800. }
  801. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  802. struct net_device *dev,
  803. struct mesh_config *conf)
  804. {
  805. struct ieee80211_sub_if_data *sdata;
  806. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  807. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  808. return 0;
  809. }
  810. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  811. {
  812. return (mask >> (parm-1)) & 0x1;
  813. }
  814. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  815. struct net_device *dev,
  816. const struct mesh_config *nconf, u32 mask)
  817. {
  818. struct mesh_config *conf;
  819. struct ieee80211_sub_if_data *sdata;
  820. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  821. /* Set the config options which we are interested in setting */
  822. conf = &(sdata->u.mesh.mshcfg);
  823. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  824. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  825. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  826. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  827. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  828. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  829. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  830. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  831. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  832. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  833. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  834. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  835. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  836. conf->auto_open_plinks = nconf->auto_open_plinks;
  837. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  838. conf->dot11MeshHWMPmaxPREQretries =
  839. nconf->dot11MeshHWMPmaxPREQretries;
  840. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  841. conf->path_refresh_time = nconf->path_refresh_time;
  842. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  843. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  844. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  845. conf->dot11MeshHWMPactivePathTimeout =
  846. nconf->dot11MeshHWMPactivePathTimeout;
  847. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  848. conf->dot11MeshHWMPpreqMinInterval =
  849. nconf->dot11MeshHWMPpreqMinInterval;
  850. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  851. mask))
  852. conf->dot11MeshHWMPnetDiameterTraversalTime =
  853. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  854. return 0;
  855. }
  856. #endif
  857. static int ieee80211_change_bss(struct wiphy *wiphy,
  858. struct net_device *dev,
  859. struct bss_parameters *params)
  860. {
  861. struct ieee80211_sub_if_data *sdata;
  862. u32 changed = 0;
  863. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  864. if (params->use_cts_prot >= 0) {
  865. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  866. changed |= BSS_CHANGED_ERP_CTS_PROT;
  867. }
  868. if (params->use_short_preamble >= 0) {
  869. sdata->vif.bss_conf.use_short_preamble =
  870. params->use_short_preamble;
  871. changed |= BSS_CHANGED_ERP_PREAMBLE;
  872. }
  873. if (params->use_short_slot_time >= 0) {
  874. sdata->vif.bss_conf.use_short_slot =
  875. params->use_short_slot_time;
  876. changed |= BSS_CHANGED_ERP_SLOT;
  877. }
  878. if (params->basic_rates) {
  879. int i, j;
  880. u32 rates = 0;
  881. struct ieee80211_local *local = wiphy_priv(wiphy);
  882. struct ieee80211_supported_band *sband =
  883. wiphy->bands[local->oper_channel->band];
  884. for (i = 0; i < params->basic_rates_len; i++) {
  885. int rate = (params->basic_rates[i] & 0x7f) * 5;
  886. for (j = 0; j < sband->n_bitrates; j++) {
  887. if (sband->bitrates[j].bitrate == rate)
  888. rates |= BIT(j);
  889. }
  890. }
  891. sdata->vif.bss_conf.basic_rates = rates;
  892. changed |= BSS_CHANGED_BASIC_RATES;
  893. }
  894. ieee80211_bss_info_change_notify(sdata, changed);
  895. return 0;
  896. }
  897. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  898. struct ieee80211_txq_params *params)
  899. {
  900. struct ieee80211_local *local = wiphy_priv(wiphy);
  901. struct ieee80211_tx_queue_params p;
  902. if (!local->ops->conf_tx)
  903. return -EOPNOTSUPP;
  904. memset(&p, 0, sizeof(p));
  905. p.aifs = params->aifs;
  906. p.cw_max = params->cwmax;
  907. p.cw_min = params->cwmin;
  908. p.txop = params->txop;
  909. if (drv_conf_tx(local, params->queue, &p)) {
  910. printk(KERN_DEBUG "%s: failed to set TX queue "
  911. "parameters for queue %d\n",
  912. wiphy_name(local->hw.wiphy), params->queue);
  913. return -EINVAL;
  914. }
  915. return 0;
  916. }
  917. static int ieee80211_set_channel(struct wiphy *wiphy,
  918. struct ieee80211_channel *chan,
  919. enum nl80211_channel_type channel_type)
  920. {
  921. struct ieee80211_local *local = wiphy_priv(wiphy);
  922. local->oper_channel = chan;
  923. local->oper_channel_type = channel_type;
  924. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  925. }
  926. #ifdef CONFIG_PM
  927. static int ieee80211_suspend(struct wiphy *wiphy)
  928. {
  929. return __ieee80211_suspend(wiphy_priv(wiphy));
  930. }
  931. static int ieee80211_resume(struct wiphy *wiphy)
  932. {
  933. return __ieee80211_resume(wiphy_priv(wiphy));
  934. }
  935. #else
  936. #define ieee80211_suspend NULL
  937. #define ieee80211_resume NULL
  938. #endif
  939. static int ieee80211_scan(struct wiphy *wiphy,
  940. struct net_device *dev,
  941. struct cfg80211_scan_request *req)
  942. {
  943. struct ieee80211_sub_if_data *sdata;
  944. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  945. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  946. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  947. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  948. (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
  949. return -EOPNOTSUPP;
  950. return ieee80211_request_scan(sdata, req);
  951. }
  952. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  953. struct cfg80211_auth_request *req)
  954. {
  955. struct ieee80211_sub_if_data *sdata;
  956. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  957. switch (req->auth_type) {
  958. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  959. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
  960. break;
  961. case NL80211_AUTHTYPE_SHARED_KEY:
  962. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
  963. break;
  964. case NL80211_AUTHTYPE_FT:
  965. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
  966. break;
  967. case NL80211_AUTHTYPE_NETWORK_EAP:
  968. sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
  969. break;
  970. default:
  971. return -EOPNOTSUPP;
  972. }
  973. memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
  974. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  975. sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
  976. /* TODO: req->chan */
  977. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
  978. if (req->ssid) {
  979. sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
  980. memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
  981. sdata->u.mgd.ssid_len = req->ssid_len;
  982. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  983. }
  984. kfree(sdata->u.mgd.sme_auth_ie);
  985. sdata->u.mgd.sme_auth_ie = NULL;
  986. sdata->u.mgd.sme_auth_ie_len = 0;
  987. if (req->ie) {
  988. sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
  989. if (sdata->u.mgd.sme_auth_ie == NULL)
  990. return -ENOMEM;
  991. memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
  992. sdata->u.mgd.sme_auth_ie_len = req->ie_len;
  993. }
  994. sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
  995. sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
  996. ieee80211_sta_req_auth(sdata);
  997. return 0;
  998. }
  999. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1000. struct cfg80211_assoc_request *req)
  1001. {
  1002. struct ieee80211_sub_if_data *sdata;
  1003. int ret;
  1004. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1005. if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
  1006. !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
  1007. return -ENOLINK; /* not authenticated */
  1008. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  1009. sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
  1010. /* TODO: req->chan */
  1011. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
  1012. if (req->ssid) {
  1013. sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
  1014. memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
  1015. sdata->u.mgd.ssid_len = req->ssid_len;
  1016. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  1017. } else
  1018. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
  1019. ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
  1020. if (ret && ret != -EALREADY)
  1021. return ret;
  1022. if (req->use_mfp) {
  1023. sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
  1024. sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
  1025. } else {
  1026. sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
  1027. sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
  1028. }
  1029. if (req->control_port)
  1030. sdata->u.mgd.flags |= IEEE80211_STA_CONTROL_PORT;
  1031. else
  1032. sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
  1033. sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
  1034. sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
  1035. ieee80211_sta_req_auth(sdata);
  1036. return 0;
  1037. }
  1038. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1039. struct cfg80211_deauth_request *req)
  1040. {
  1041. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1042. /* TODO: req->ie, req->peer_addr */
  1043. return ieee80211_sta_deauthenticate(sdata, req->reason_code);
  1044. }
  1045. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1046. struct cfg80211_disassoc_request *req)
  1047. {
  1048. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1049. /* TODO: req->ie, req->peer_addr */
  1050. return ieee80211_sta_disassociate(sdata, req->reason_code);
  1051. }
  1052. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1053. struct cfg80211_ibss_params *params)
  1054. {
  1055. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1056. return ieee80211_ibss_join(sdata, params);
  1057. }
  1058. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1059. {
  1060. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1061. return ieee80211_ibss_leave(sdata);
  1062. }
  1063. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1064. {
  1065. struct ieee80211_local *local = wiphy_priv(wiphy);
  1066. int err;
  1067. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1068. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1069. if (err)
  1070. return err;
  1071. }
  1072. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1073. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1074. if (changed & WIPHY_PARAM_RETRY_LONG)
  1075. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1076. if (changed &
  1077. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1078. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1079. return 0;
  1080. }
  1081. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1082. enum tx_power_setting type, int dbm)
  1083. {
  1084. struct ieee80211_local *local = wiphy_priv(wiphy);
  1085. struct ieee80211_channel *chan = local->hw.conf.channel;
  1086. u32 changes = 0;
  1087. switch (type) {
  1088. case TX_POWER_AUTOMATIC:
  1089. local->user_power_level = -1;
  1090. break;
  1091. case TX_POWER_LIMITED:
  1092. if (dbm < 0)
  1093. return -EINVAL;
  1094. local->user_power_level = dbm;
  1095. break;
  1096. case TX_POWER_FIXED:
  1097. if (dbm < 0)
  1098. return -EINVAL;
  1099. /* TODO: move to cfg80211 when it knows the channel */
  1100. if (dbm > chan->max_power)
  1101. return -EINVAL;
  1102. local->user_power_level = dbm;
  1103. break;
  1104. }
  1105. ieee80211_hw_config(local, changes);
  1106. return 0;
  1107. }
  1108. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1109. {
  1110. struct ieee80211_local *local = wiphy_priv(wiphy);
  1111. *dbm = local->hw.conf.power_level;
  1112. return 0;
  1113. }
  1114. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1115. {
  1116. struct ieee80211_local *local = wiphy_priv(wiphy);
  1117. drv_rfkill_poll(local);
  1118. }
  1119. struct cfg80211_ops mac80211_config_ops = {
  1120. .add_virtual_intf = ieee80211_add_iface,
  1121. .del_virtual_intf = ieee80211_del_iface,
  1122. .change_virtual_intf = ieee80211_change_iface,
  1123. .add_key = ieee80211_add_key,
  1124. .del_key = ieee80211_del_key,
  1125. .get_key = ieee80211_get_key,
  1126. .set_default_key = ieee80211_config_default_key,
  1127. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1128. .add_beacon = ieee80211_add_beacon,
  1129. .set_beacon = ieee80211_set_beacon,
  1130. .del_beacon = ieee80211_del_beacon,
  1131. .add_station = ieee80211_add_station,
  1132. .del_station = ieee80211_del_station,
  1133. .change_station = ieee80211_change_station,
  1134. .get_station = ieee80211_get_station,
  1135. .dump_station = ieee80211_dump_station,
  1136. #ifdef CONFIG_MAC80211_MESH
  1137. .add_mpath = ieee80211_add_mpath,
  1138. .del_mpath = ieee80211_del_mpath,
  1139. .change_mpath = ieee80211_change_mpath,
  1140. .get_mpath = ieee80211_get_mpath,
  1141. .dump_mpath = ieee80211_dump_mpath,
  1142. .set_mesh_params = ieee80211_set_mesh_params,
  1143. .get_mesh_params = ieee80211_get_mesh_params,
  1144. #endif
  1145. .change_bss = ieee80211_change_bss,
  1146. .set_txq_params = ieee80211_set_txq_params,
  1147. .set_channel = ieee80211_set_channel,
  1148. .suspend = ieee80211_suspend,
  1149. .resume = ieee80211_resume,
  1150. .scan = ieee80211_scan,
  1151. .auth = ieee80211_auth,
  1152. .assoc = ieee80211_assoc,
  1153. .deauth = ieee80211_deauth,
  1154. .disassoc = ieee80211_disassoc,
  1155. .join_ibss = ieee80211_join_ibss,
  1156. .leave_ibss = ieee80211_leave_ibss,
  1157. .set_wiphy_params = ieee80211_set_wiphy_params,
  1158. .set_tx_power = ieee80211_set_tx_power,
  1159. .get_tx_power = ieee80211_get_tx_power,
  1160. .rfkill_poll = ieee80211_rfkill_poll,
  1161. };