cfg.c 37 KB

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