cfg.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006-2010 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 <linux/slab.h>
  12. #include <net/net_namespace.h>
  13. #include <linux/rcupdate.h>
  14. #include <net/cfg80211.h>
  15. #include "ieee80211_i.h"
  16. #include "driver-ops.h"
  17. #include "cfg.h"
  18. #include "rate.h"
  19. #include "mesh.h"
  20. static bool nl80211_type_check(enum nl80211_iftype type)
  21. {
  22. switch (type) {
  23. case NL80211_IFTYPE_ADHOC:
  24. case NL80211_IFTYPE_STATION:
  25. case NL80211_IFTYPE_MONITOR:
  26. #ifdef CONFIG_MAC80211_MESH
  27. case NL80211_IFTYPE_MESH_POINT:
  28. #endif
  29. case NL80211_IFTYPE_AP:
  30. case NL80211_IFTYPE_AP_VLAN:
  31. case NL80211_IFTYPE_WDS:
  32. return true;
  33. default:
  34. return false;
  35. }
  36. }
  37. static bool nl80211_params_check(enum nl80211_iftype type,
  38. struct vif_params *params)
  39. {
  40. if (!nl80211_type_check(type))
  41. return false;
  42. return true;
  43. }
  44. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  45. enum nl80211_iftype type, u32 *flags,
  46. struct vif_params *params)
  47. {
  48. struct ieee80211_local *local = wiphy_priv(wiphy);
  49. struct net_device *dev;
  50. struct ieee80211_sub_if_data *sdata;
  51. int err;
  52. if (!nl80211_params_check(type, params))
  53. return -EINVAL;
  54. err = ieee80211_if_add(local, name, &dev, type, params);
  55. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  56. return err;
  57. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  58. sdata->u.mntr_flags = *flags;
  59. return 0;
  60. }
  61. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  62. {
  63. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  64. return 0;
  65. }
  66. static int ieee80211_change_iface(struct wiphy *wiphy,
  67. struct net_device *dev,
  68. enum nl80211_iftype type, u32 *flags,
  69. struct vif_params *params)
  70. {
  71. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  72. int ret;
  73. if (ieee80211_sdata_running(sdata))
  74. return -EBUSY;
  75. if (!nl80211_params_check(type, params))
  76. return -EINVAL;
  77. ret = ieee80211_if_change_type(sdata, type);
  78. if (ret)
  79. return ret;
  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 (type == NL80211_IFTYPE_AP_VLAN &&
  85. params && params->use_4addr == 0)
  86. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  87. else if (type == NL80211_IFTYPE_STATION &&
  88. params && params->use_4addr >= 0)
  89. sdata->u.mgd.use_4addr = params->use_4addr;
  90. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags)
  91. sdata->u.mntr_flags = *flags;
  92. return 0;
  93. }
  94. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  95. u8 key_idx, const u8 *mac_addr,
  96. struct key_params *params)
  97. {
  98. struct ieee80211_sub_if_data *sdata;
  99. struct sta_info *sta = NULL;
  100. struct ieee80211_key *key;
  101. int err;
  102. if (!netif_running(dev))
  103. return -ENETDOWN;
  104. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  105. /* reject WEP and TKIP keys if WEP failed to initialize */
  106. switch (params->cipher) {
  107. case WLAN_CIPHER_SUITE_WEP40:
  108. case WLAN_CIPHER_SUITE_TKIP:
  109. case WLAN_CIPHER_SUITE_WEP104:
  110. if (IS_ERR(sdata->local->wep_tx_tfm))
  111. return -EINVAL;
  112. break;
  113. default:
  114. break;
  115. }
  116. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  117. params->key, params->seq_len, params->seq);
  118. if (IS_ERR(key))
  119. return PTR_ERR(key);
  120. mutex_lock(&sdata->local->sta_mtx);
  121. if (mac_addr) {
  122. sta = sta_info_get_bss(sdata, mac_addr);
  123. if (!sta) {
  124. ieee80211_key_free(sdata->local, key);
  125. err = -ENOENT;
  126. goto out_unlock;
  127. }
  128. }
  129. ieee80211_key_link(key, sdata, sta);
  130. err = 0;
  131. out_unlock:
  132. mutex_unlock(&sdata->local->sta_mtx);
  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. mutex_lock(&sdata->local->sta_mtx);
  143. if (mac_addr) {
  144. ret = -ENOENT;
  145. sta = sta_info_get_bss(sdata, mac_addr);
  146. if (!sta)
  147. goto out_unlock;
  148. if (sta->key) {
  149. ieee80211_key_free(sdata->local, 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->local, sdata->keys[key_idx]);
  160. WARN_ON(sdata->keys[key_idx]);
  161. ret = 0;
  162. out_unlock:
  163. mutex_unlock(&sdata->local->sta_mtx);
  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_bss(sdata, 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. params.cipher = key->conf.cipher;
  192. switch (key->conf.cipher) {
  193. case 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 WLAN_CIPHER_SUITE_CCMP:
  210. seq[0] = key->u.ccmp.tx_pn[5];
  211. seq[1] = key->u.ccmp.tx_pn[4];
  212. seq[2] = key->u.ccmp.tx_pn[3];
  213. seq[3] = key->u.ccmp.tx_pn[2];
  214. seq[4] = key->u.ccmp.tx_pn[1];
  215. seq[5] = key->u.ccmp.tx_pn[0];
  216. params.seq = seq;
  217. params.seq_len = 6;
  218. break;
  219. case WLAN_CIPHER_SUITE_AES_CMAC:
  220. seq[0] = key->u.aes_cmac.tx_pn[5];
  221. seq[1] = key->u.aes_cmac.tx_pn[4];
  222. seq[2] = key->u.aes_cmac.tx_pn[3];
  223. seq[3] = key->u.aes_cmac.tx_pn[2];
  224. seq[4] = key->u.aes_cmac.tx_pn[1];
  225. seq[5] = key->u.aes_cmac.tx_pn[0];
  226. params.seq = seq;
  227. params.seq_len = 6;
  228. break;
  229. }
  230. params.key = key->conf.key;
  231. params.key_len = key->conf.keylen;
  232. callback(cookie, &params);
  233. err = 0;
  234. out:
  235. rcu_read_unlock();
  236. return err;
  237. }
  238. static int ieee80211_config_default_key(struct wiphy *wiphy,
  239. struct net_device *dev,
  240. u8 key_idx)
  241. {
  242. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  243. ieee80211_set_default_key(sdata, key_idx);
  244. return 0;
  245. }
  246. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  247. struct net_device *dev,
  248. u8 key_idx)
  249. {
  250. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  251. ieee80211_set_default_mgmt_key(sdata, key_idx);
  252. return 0;
  253. }
  254. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  255. {
  256. struct ieee80211_sub_if_data *sdata = sta->sdata;
  257. sinfo->generation = sdata->local->sta_generation;
  258. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  259. STATION_INFO_RX_BYTES |
  260. STATION_INFO_TX_BYTES |
  261. STATION_INFO_RX_PACKETS |
  262. STATION_INFO_TX_PACKETS |
  263. STATION_INFO_TX_BITRATE;
  264. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  265. sinfo->rx_bytes = sta->rx_bytes;
  266. sinfo->tx_bytes = sta->tx_bytes;
  267. sinfo->rx_packets = sta->rx_packets;
  268. sinfo->tx_packets = sta->tx_packets;
  269. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  270. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  271. sinfo->filled |= STATION_INFO_SIGNAL;
  272. sinfo->signal = (s8)sta->last_signal;
  273. }
  274. sinfo->txrate.flags = 0;
  275. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  276. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  277. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  278. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  279. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  280. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  281. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  282. struct ieee80211_supported_band *sband;
  283. sband = sta->local->hw.wiphy->bands[
  284. sta->local->hw.conf.channel->band];
  285. sinfo->txrate.legacy =
  286. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  287. } else
  288. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  289. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  290. #ifdef CONFIG_MAC80211_MESH
  291. sinfo->filled |= STATION_INFO_LLID |
  292. STATION_INFO_PLID |
  293. STATION_INFO_PLINK_STATE;
  294. sinfo->llid = le16_to_cpu(sta->llid);
  295. sinfo->plid = le16_to_cpu(sta->plid);
  296. sinfo->plink_state = sta->plink_state;
  297. #endif
  298. }
  299. }
  300. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  301. int idx, u8 *mac, struct station_info *sinfo)
  302. {
  303. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  304. struct sta_info *sta;
  305. int ret = -ENOENT;
  306. rcu_read_lock();
  307. sta = sta_info_get_by_idx(sdata, idx);
  308. if (sta) {
  309. ret = 0;
  310. memcpy(mac, sta->sta.addr, ETH_ALEN);
  311. sta_set_sinfo(sta, sinfo);
  312. }
  313. rcu_read_unlock();
  314. return ret;
  315. }
  316. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  317. int idx, struct survey_info *survey)
  318. {
  319. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  320. return drv_get_survey(local, idx, survey);
  321. }
  322. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  323. u8 *mac, struct station_info *sinfo)
  324. {
  325. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  326. struct sta_info *sta;
  327. int ret = -ENOENT;
  328. rcu_read_lock();
  329. sta = sta_info_get_bss(sdata, mac);
  330. if (sta) {
  331. ret = 0;
  332. sta_set_sinfo(sta, sinfo);
  333. }
  334. rcu_read_unlock();
  335. return ret;
  336. }
  337. /*
  338. * This handles both adding a beacon and setting new beacon info
  339. */
  340. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  341. struct beacon_parameters *params)
  342. {
  343. struct beacon_data *new, *old;
  344. int new_head_len, new_tail_len;
  345. int size;
  346. int err = -EINVAL;
  347. old = sdata->u.ap.beacon;
  348. /* head must not be zero-length */
  349. if (params->head && !params->head_len)
  350. return -EINVAL;
  351. /*
  352. * This is a kludge. beacon interval should really be part
  353. * of the beacon information.
  354. */
  355. if (params->interval &&
  356. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  357. sdata->vif.bss_conf.beacon_int = params->interval;
  358. ieee80211_bss_info_change_notify(sdata,
  359. BSS_CHANGED_BEACON_INT);
  360. }
  361. /* Need to have a beacon head if we don't have one yet */
  362. if (!params->head && !old)
  363. return err;
  364. /* sorry, no way to start beaconing without dtim period */
  365. if (!params->dtim_period && !old)
  366. return err;
  367. /* new or old head? */
  368. if (params->head)
  369. new_head_len = params->head_len;
  370. else
  371. new_head_len = old->head_len;
  372. /* new or old tail? */
  373. if (params->tail || !old)
  374. /* params->tail_len will be zero for !params->tail */
  375. new_tail_len = params->tail_len;
  376. else
  377. new_tail_len = old->tail_len;
  378. size = sizeof(*new) + new_head_len + new_tail_len;
  379. new = kzalloc(size, GFP_KERNEL);
  380. if (!new)
  381. return -ENOMEM;
  382. /* start filling the new info now */
  383. /* new or old dtim period? */
  384. if (params->dtim_period)
  385. new->dtim_period = params->dtim_period;
  386. else
  387. new->dtim_period = old->dtim_period;
  388. /*
  389. * pointers go into the block we allocated,
  390. * memory is | beacon_data | head | tail |
  391. */
  392. new->head = ((u8 *) new) + sizeof(*new);
  393. new->tail = new->head + new_head_len;
  394. new->head_len = new_head_len;
  395. new->tail_len = new_tail_len;
  396. /* copy in head */
  397. if (params->head)
  398. memcpy(new->head, params->head, new_head_len);
  399. else
  400. memcpy(new->head, old->head, new_head_len);
  401. /* copy in optional tail */
  402. if (params->tail)
  403. memcpy(new->tail, params->tail, new_tail_len);
  404. else
  405. if (old)
  406. memcpy(new->tail, old->tail, new_tail_len);
  407. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  408. rcu_assign_pointer(sdata->u.ap.beacon, new);
  409. synchronize_rcu();
  410. kfree(old);
  411. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  412. BSS_CHANGED_BEACON);
  413. return 0;
  414. }
  415. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  416. struct beacon_parameters *params)
  417. {
  418. struct ieee80211_sub_if_data *sdata;
  419. struct beacon_data *old;
  420. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  421. old = sdata->u.ap.beacon;
  422. if (old)
  423. return -EALREADY;
  424. return ieee80211_config_beacon(sdata, params);
  425. }
  426. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  427. struct beacon_parameters *params)
  428. {
  429. struct ieee80211_sub_if_data *sdata;
  430. struct beacon_data *old;
  431. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  432. old = sdata->u.ap.beacon;
  433. if (!old)
  434. return -ENOENT;
  435. return ieee80211_config_beacon(sdata, params);
  436. }
  437. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  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. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  446. synchronize_rcu();
  447. kfree(old);
  448. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  449. return 0;
  450. }
  451. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  452. struct iapp_layer2_update {
  453. u8 da[ETH_ALEN]; /* broadcast */
  454. u8 sa[ETH_ALEN]; /* STA addr */
  455. __be16 len; /* 6 */
  456. u8 dsap; /* 0 */
  457. u8 ssap; /* 0 */
  458. u8 control;
  459. u8 xid_info[3];
  460. } __packed;
  461. static void ieee80211_send_layer2_update(struct sta_info *sta)
  462. {
  463. struct iapp_layer2_update *msg;
  464. struct sk_buff *skb;
  465. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  466. * bridge devices */
  467. skb = dev_alloc_skb(sizeof(*msg));
  468. if (!skb)
  469. return;
  470. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  471. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  472. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  473. memset(msg->da, 0xff, ETH_ALEN);
  474. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  475. msg->len = htons(6);
  476. msg->dsap = 0;
  477. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  478. msg->control = 0xaf; /* XID response lsb.1111F101.
  479. * F=0 (no poll command; unsolicited frame) */
  480. msg->xid_info[0] = 0x81; /* XID format identifier */
  481. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  482. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  483. skb->dev = sta->sdata->dev;
  484. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  485. memset(skb->cb, 0, sizeof(skb->cb));
  486. netif_rx_ni(skb);
  487. }
  488. static void sta_apply_parameters(struct ieee80211_local *local,
  489. struct sta_info *sta,
  490. struct station_parameters *params)
  491. {
  492. u32 rates;
  493. int i, j;
  494. struct ieee80211_supported_band *sband;
  495. struct ieee80211_sub_if_data *sdata = sta->sdata;
  496. u32 mask, set;
  497. sband = local->hw.wiphy->bands[local->oper_channel->band];
  498. spin_lock_bh(&sta->lock);
  499. mask = params->sta_flags_mask;
  500. set = params->sta_flags_set;
  501. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  502. sta->flags &= ~WLAN_STA_AUTHORIZED;
  503. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  504. sta->flags |= WLAN_STA_AUTHORIZED;
  505. }
  506. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  507. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  508. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  509. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  510. }
  511. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  512. sta->flags &= ~WLAN_STA_WME;
  513. if (set & BIT(NL80211_STA_FLAG_WME))
  514. sta->flags |= WLAN_STA_WME;
  515. }
  516. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  517. sta->flags &= ~WLAN_STA_MFP;
  518. if (set & BIT(NL80211_STA_FLAG_MFP))
  519. sta->flags |= WLAN_STA_MFP;
  520. }
  521. spin_unlock_bh(&sta->lock);
  522. /*
  523. * cfg80211 validates this (1-2007) and allows setting the AID
  524. * only when creating a new station entry
  525. */
  526. if (params->aid)
  527. sta->sta.aid = params->aid;
  528. /*
  529. * FIXME: updating the following information is racy when this
  530. * function is called from ieee80211_change_station().
  531. * However, all this information should be static so
  532. * maybe we should just reject attemps to change it.
  533. */
  534. if (params->listen_interval >= 0)
  535. sta->listen_interval = params->listen_interval;
  536. if (params->supported_rates) {
  537. rates = 0;
  538. for (i = 0; i < params->supported_rates_len; i++) {
  539. int rate = (params->supported_rates[i] & 0x7f) * 5;
  540. for (j = 0; j < sband->n_bitrates; j++) {
  541. if (sband->bitrates[j].bitrate == rate)
  542. rates |= BIT(j);
  543. }
  544. }
  545. sta->sta.supp_rates[local->oper_channel->band] = rates;
  546. }
  547. if (params->ht_capa)
  548. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  549. params->ht_capa,
  550. &sta->sta.ht_cap);
  551. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  552. switch (params->plink_action) {
  553. case PLINK_ACTION_OPEN:
  554. mesh_plink_open(sta);
  555. break;
  556. case PLINK_ACTION_BLOCK:
  557. mesh_plink_block(sta);
  558. break;
  559. }
  560. }
  561. }
  562. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  563. u8 *mac, struct station_parameters *params)
  564. {
  565. struct ieee80211_local *local = wiphy_priv(wiphy);
  566. struct sta_info *sta;
  567. struct ieee80211_sub_if_data *sdata;
  568. int err;
  569. int layer2_update;
  570. if (params->vlan) {
  571. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  572. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  573. sdata->vif.type != NL80211_IFTYPE_AP)
  574. return -EINVAL;
  575. } else
  576. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  577. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  578. return -EINVAL;
  579. if (is_multicast_ether_addr(mac))
  580. return -EINVAL;
  581. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  582. if (!sta)
  583. return -ENOMEM;
  584. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  585. sta_apply_parameters(local, sta, params);
  586. rate_control_rate_init(sta);
  587. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  588. sdata->vif.type == NL80211_IFTYPE_AP;
  589. err = sta_info_insert_rcu(sta);
  590. if (err) {
  591. rcu_read_unlock();
  592. return err;
  593. }
  594. if (layer2_update)
  595. ieee80211_send_layer2_update(sta);
  596. rcu_read_unlock();
  597. return 0;
  598. }
  599. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  600. u8 *mac)
  601. {
  602. struct ieee80211_local *local = wiphy_priv(wiphy);
  603. struct ieee80211_sub_if_data *sdata;
  604. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  605. if (mac)
  606. return sta_info_destroy_addr_bss(sdata, mac);
  607. sta_info_flush(local, sdata);
  608. return 0;
  609. }
  610. static int ieee80211_change_station(struct wiphy *wiphy,
  611. struct net_device *dev,
  612. u8 *mac,
  613. struct station_parameters *params)
  614. {
  615. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  616. struct ieee80211_local *local = wiphy_priv(wiphy);
  617. struct sta_info *sta;
  618. struct ieee80211_sub_if_data *vlansdata;
  619. rcu_read_lock();
  620. sta = sta_info_get_bss(sdata, mac);
  621. if (!sta) {
  622. rcu_read_unlock();
  623. return -ENOENT;
  624. }
  625. if (params->vlan && params->vlan != sta->sdata->dev) {
  626. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  627. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  628. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  629. rcu_read_unlock();
  630. return -EINVAL;
  631. }
  632. if (params->vlan->ieee80211_ptr->use_4addr) {
  633. if (vlansdata->u.vlan.sta) {
  634. rcu_read_unlock();
  635. return -EBUSY;
  636. }
  637. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  638. }
  639. sta->sdata = vlansdata;
  640. ieee80211_send_layer2_update(sta);
  641. }
  642. sta_apply_parameters(local, sta, params);
  643. rcu_read_unlock();
  644. return 0;
  645. }
  646. #ifdef CONFIG_MAC80211_MESH
  647. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  648. u8 *dst, u8 *next_hop)
  649. {
  650. struct ieee80211_sub_if_data *sdata;
  651. struct mesh_path *mpath;
  652. struct sta_info *sta;
  653. int err;
  654. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  655. rcu_read_lock();
  656. sta = sta_info_get(sdata, next_hop);
  657. if (!sta) {
  658. rcu_read_unlock();
  659. return -ENOENT;
  660. }
  661. err = mesh_path_add(dst, sdata);
  662. if (err) {
  663. rcu_read_unlock();
  664. return err;
  665. }
  666. mpath = mesh_path_lookup(dst, sdata);
  667. if (!mpath) {
  668. rcu_read_unlock();
  669. return -ENXIO;
  670. }
  671. mesh_path_fix_nexthop(mpath, sta);
  672. rcu_read_unlock();
  673. return 0;
  674. }
  675. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  676. u8 *dst)
  677. {
  678. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  679. if (dst)
  680. return mesh_path_del(dst, sdata);
  681. mesh_path_flush(sdata);
  682. return 0;
  683. }
  684. static int ieee80211_change_mpath(struct wiphy *wiphy,
  685. struct net_device *dev,
  686. u8 *dst, u8 *next_hop)
  687. {
  688. struct ieee80211_sub_if_data *sdata;
  689. struct mesh_path *mpath;
  690. struct sta_info *sta;
  691. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  692. rcu_read_lock();
  693. sta = sta_info_get(sdata, next_hop);
  694. if (!sta) {
  695. rcu_read_unlock();
  696. return -ENOENT;
  697. }
  698. mpath = mesh_path_lookup(dst, sdata);
  699. if (!mpath) {
  700. rcu_read_unlock();
  701. return -ENOENT;
  702. }
  703. mesh_path_fix_nexthop(mpath, sta);
  704. rcu_read_unlock();
  705. return 0;
  706. }
  707. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  708. struct mpath_info *pinfo)
  709. {
  710. if (mpath->next_hop)
  711. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  712. else
  713. memset(next_hop, 0, ETH_ALEN);
  714. pinfo->generation = mesh_paths_generation;
  715. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  716. MPATH_INFO_SN |
  717. MPATH_INFO_METRIC |
  718. MPATH_INFO_EXPTIME |
  719. MPATH_INFO_DISCOVERY_TIMEOUT |
  720. MPATH_INFO_DISCOVERY_RETRIES |
  721. MPATH_INFO_FLAGS;
  722. pinfo->frame_qlen = mpath->frame_queue.qlen;
  723. pinfo->sn = mpath->sn;
  724. pinfo->metric = mpath->metric;
  725. if (time_before(jiffies, mpath->exp_time))
  726. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  727. pinfo->discovery_timeout =
  728. jiffies_to_msecs(mpath->discovery_timeout);
  729. pinfo->discovery_retries = mpath->discovery_retries;
  730. pinfo->flags = 0;
  731. if (mpath->flags & MESH_PATH_ACTIVE)
  732. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  733. if (mpath->flags & MESH_PATH_RESOLVING)
  734. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  735. if (mpath->flags & MESH_PATH_SN_VALID)
  736. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  737. if (mpath->flags & MESH_PATH_FIXED)
  738. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  739. if (mpath->flags & MESH_PATH_RESOLVING)
  740. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  741. pinfo->flags = mpath->flags;
  742. }
  743. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  744. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  745. {
  746. struct ieee80211_sub_if_data *sdata;
  747. struct mesh_path *mpath;
  748. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  749. rcu_read_lock();
  750. mpath = mesh_path_lookup(dst, sdata);
  751. if (!mpath) {
  752. rcu_read_unlock();
  753. return -ENOENT;
  754. }
  755. memcpy(dst, mpath->dst, ETH_ALEN);
  756. mpath_set_pinfo(mpath, next_hop, pinfo);
  757. rcu_read_unlock();
  758. return 0;
  759. }
  760. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  761. int idx, u8 *dst, u8 *next_hop,
  762. struct mpath_info *pinfo)
  763. {
  764. struct ieee80211_sub_if_data *sdata;
  765. struct mesh_path *mpath;
  766. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  767. rcu_read_lock();
  768. mpath = mesh_path_lookup_by_idx(idx, sdata);
  769. if (!mpath) {
  770. rcu_read_unlock();
  771. return -ENOENT;
  772. }
  773. memcpy(dst, mpath->dst, ETH_ALEN);
  774. mpath_set_pinfo(mpath, next_hop, pinfo);
  775. rcu_read_unlock();
  776. return 0;
  777. }
  778. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  779. struct net_device *dev,
  780. struct mesh_config *conf)
  781. {
  782. struct ieee80211_sub_if_data *sdata;
  783. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  784. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  785. return 0;
  786. }
  787. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  788. {
  789. return (mask >> (parm-1)) & 0x1;
  790. }
  791. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  792. struct net_device *dev,
  793. const struct mesh_config *nconf, u32 mask)
  794. {
  795. struct mesh_config *conf;
  796. struct ieee80211_sub_if_data *sdata;
  797. struct ieee80211_if_mesh *ifmsh;
  798. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  799. ifmsh = &sdata->u.mesh;
  800. /* Set the config options which we are interested in setting */
  801. conf = &(sdata->u.mesh.mshcfg);
  802. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  803. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  804. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  805. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  806. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  807. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  808. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  809. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  810. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  811. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  812. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  813. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  814. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  815. conf->auto_open_plinks = nconf->auto_open_plinks;
  816. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  817. conf->dot11MeshHWMPmaxPREQretries =
  818. nconf->dot11MeshHWMPmaxPREQretries;
  819. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  820. conf->path_refresh_time = nconf->path_refresh_time;
  821. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  822. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  823. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  824. conf->dot11MeshHWMPactivePathTimeout =
  825. nconf->dot11MeshHWMPactivePathTimeout;
  826. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  827. conf->dot11MeshHWMPpreqMinInterval =
  828. nconf->dot11MeshHWMPpreqMinInterval;
  829. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  830. mask))
  831. conf->dot11MeshHWMPnetDiameterTraversalTime =
  832. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  833. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  834. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  835. ieee80211_mesh_root_setup(ifmsh);
  836. }
  837. return 0;
  838. }
  839. #endif
  840. static int ieee80211_change_bss(struct wiphy *wiphy,
  841. struct net_device *dev,
  842. struct bss_parameters *params)
  843. {
  844. struct ieee80211_sub_if_data *sdata;
  845. u32 changed = 0;
  846. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  847. if (params->use_cts_prot >= 0) {
  848. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  849. changed |= BSS_CHANGED_ERP_CTS_PROT;
  850. }
  851. if (params->use_short_preamble >= 0) {
  852. sdata->vif.bss_conf.use_short_preamble =
  853. params->use_short_preamble;
  854. changed |= BSS_CHANGED_ERP_PREAMBLE;
  855. }
  856. if (!sdata->vif.bss_conf.use_short_slot &&
  857. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  858. sdata->vif.bss_conf.use_short_slot = true;
  859. changed |= BSS_CHANGED_ERP_SLOT;
  860. }
  861. if (params->use_short_slot_time >= 0) {
  862. sdata->vif.bss_conf.use_short_slot =
  863. params->use_short_slot_time;
  864. changed |= BSS_CHANGED_ERP_SLOT;
  865. }
  866. if (params->basic_rates) {
  867. int i, j;
  868. u32 rates = 0;
  869. struct ieee80211_local *local = wiphy_priv(wiphy);
  870. struct ieee80211_supported_band *sband =
  871. wiphy->bands[local->oper_channel->band];
  872. for (i = 0; i < params->basic_rates_len; i++) {
  873. int rate = (params->basic_rates[i] & 0x7f) * 5;
  874. for (j = 0; j < sband->n_bitrates; j++) {
  875. if (sband->bitrates[j].bitrate == rate)
  876. rates |= BIT(j);
  877. }
  878. }
  879. sdata->vif.bss_conf.basic_rates = rates;
  880. changed |= BSS_CHANGED_BASIC_RATES;
  881. }
  882. if (params->ap_isolate >= 0) {
  883. if (params->ap_isolate)
  884. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  885. else
  886. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  887. }
  888. ieee80211_bss_info_change_notify(sdata, changed);
  889. return 0;
  890. }
  891. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  892. struct ieee80211_txq_params *params)
  893. {
  894. struct ieee80211_local *local = wiphy_priv(wiphy);
  895. struct ieee80211_tx_queue_params p;
  896. if (!local->ops->conf_tx)
  897. return -EOPNOTSUPP;
  898. memset(&p, 0, sizeof(p));
  899. p.aifs = params->aifs;
  900. p.cw_max = params->cwmax;
  901. p.cw_min = params->cwmin;
  902. p.txop = params->txop;
  903. /*
  904. * Setting tx queue params disables u-apsd because it's only
  905. * called in master mode.
  906. */
  907. p.uapsd = false;
  908. if (drv_conf_tx(local, params->queue, &p)) {
  909. printk(KERN_DEBUG "%s: failed to set TX queue "
  910. "parameters for queue %d\n",
  911. wiphy_name(local->hw.wiphy), params->queue);
  912. return -EINVAL;
  913. }
  914. return 0;
  915. }
  916. static int ieee80211_set_channel(struct wiphy *wiphy,
  917. struct net_device *netdev,
  918. struct ieee80211_channel *chan,
  919. enum nl80211_channel_type channel_type)
  920. {
  921. struct ieee80211_local *local = wiphy_priv(wiphy);
  922. struct ieee80211_sub_if_data *sdata = NULL;
  923. if (netdev)
  924. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  925. switch (ieee80211_get_channel_mode(local, NULL)) {
  926. case CHAN_MODE_HOPPING:
  927. return -EBUSY;
  928. case CHAN_MODE_FIXED:
  929. if (local->oper_channel != chan)
  930. return -EBUSY;
  931. if (!sdata && local->_oper_channel_type == channel_type)
  932. return 0;
  933. break;
  934. case CHAN_MODE_UNDEFINED:
  935. break;
  936. }
  937. local->oper_channel = chan;
  938. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  939. return -EBUSY;
  940. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  941. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
  942. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  943. return 0;
  944. }
  945. #ifdef CONFIG_PM
  946. static int ieee80211_suspend(struct wiphy *wiphy)
  947. {
  948. return __ieee80211_suspend(wiphy_priv(wiphy));
  949. }
  950. static int ieee80211_resume(struct wiphy *wiphy)
  951. {
  952. return __ieee80211_resume(wiphy_priv(wiphy));
  953. }
  954. #else
  955. #define ieee80211_suspend NULL
  956. #define ieee80211_resume NULL
  957. #endif
  958. static int ieee80211_scan(struct wiphy *wiphy,
  959. struct net_device *dev,
  960. struct cfg80211_scan_request *req)
  961. {
  962. struct ieee80211_sub_if_data *sdata;
  963. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  964. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  965. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  966. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  967. (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
  968. return -EOPNOTSUPP;
  969. return ieee80211_request_scan(sdata, req);
  970. }
  971. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  972. struct cfg80211_auth_request *req)
  973. {
  974. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  975. }
  976. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  977. struct cfg80211_assoc_request *req)
  978. {
  979. struct ieee80211_local *local = wiphy_priv(wiphy);
  980. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  981. switch (ieee80211_get_channel_mode(local, sdata)) {
  982. case CHAN_MODE_HOPPING:
  983. return -EBUSY;
  984. case CHAN_MODE_FIXED:
  985. if (local->oper_channel == req->bss->channel)
  986. break;
  987. return -EBUSY;
  988. case CHAN_MODE_UNDEFINED:
  989. break;
  990. }
  991. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  992. }
  993. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  994. struct cfg80211_deauth_request *req,
  995. void *cookie)
  996. {
  997. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  998. req, cookie);
  999. }
  1000. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1001. struct cfg80211_disassoc_request *req,
  1002. void *cookie)
  1003. {
  1004. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1005. req, cookie);
  1006. }
  1007. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1008. struct cfg80211_ibss_params *params)
  1009. {
  1010. struct ieee80211_local *local = wiphy_priv(wiphy);
  1011. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1012. switch (ieee80211_get_channel_mode(local, sdata)) {
  1013. case CHAN_MODE_HOPPING:
  1014. return -EBUSY;
  1015. case CHAN_MODE_FIXED:
  1016. if (!params->channel_fixed)
  1017. return -EBUSY;
  1018. if (local->oper_channel == params->channel)
  1019. break;
  1020. return -EBUSY;
  1021. case CHAN_MODE_UNDEFINED:
  1022. break;
  1023. }
  1024. return ieee80211_ibss_join(sdata, params);
  1025. }
  1026. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1027. {
  1028. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1029. return ieee80211_ibss_leave(sdata);
  1030. }
  1031. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1032. {
  1033. struct ieee80211_local *local = wiphy_priv(wiphy);
  1034. int err;
  1035. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1036. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1037. if (err)
  1038. return err;
  1039. }
  1040. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1041. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1042. if (err)
  1043. return err;
  1044. }
  1045. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1046. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1047. if (changed & WIPHY_PARAM_RETRY_LONG)
  1048. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1049. if (changed &
  1050. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1051. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1052. return 0;
  1053. }
  1054. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1055. enum nl80211_tx_power_setting type, int mbm)
  1056. {
  1057. struct ieee80211_local *local = wiphy_priv(wiphy);
  1058. struct ieee80211_channel *chan = local->hw.conf.channel;
  1059. u32 changes = 0;
  1060. switch (type) {
  1061. case NL80211_TX_POWER_AUTOMATIC:
  1062. local->user_power_level = -1;
  1063. break;
  1064. case NL80211_TX_POWER_LIMITED:
  1065. if (mbm < 0 || (mbm % 100))
  1066. return -EOPNOTSUPP;
  1067. local->user_power_level = MBM_TO_DBM(mbm);
  1068. break;
  1069. case NL80211_TX_POWER_FIXED:
  1070. if (mbm < 0 || (mbm % 100))
  1071. return -EOPNOTSUPP;
  1072. /* TODO: move to cfg80211 when it knows the channel */
  1073. if (MBM_TO_DBM(mbm) > chan->max_power)
  1074. return -EINVAL;
  1075. local->user_power_level = MBM_TO_DBM(mbm);
  1076. break;
  1077. }
  1078. ieee80211_hw_config(local, changes);
  1079. return 0;
  1080. }
  1081. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1082. {
  1083. struct ieee80211_local *local = wiphy_priv(wiphy);
  1084. *dbm = local->hw.conf.power_level;
  1085. return 0;
  1086. }
  1087. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1088. u8 *addr)
  1089. {
  1090. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1091. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1092. return 0;
  1093. }
  1094. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1095. {
  1096. struct ieee80211_local *local = wiphy_priv(wiphy);
  1097. drv_rfkill_poll(local);
  1098. }
  1099. #ifdef CONFIG_NL80211_TESTMODE
  1100. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1101. {
  1102. struct ieee80211_local *local = wiphy_priv(wiphy);
  1103. if (!local->ops->testmode_cmd)
  1104. return -EOPNOTSUPP;
  1105. return local->ops->testmode_cmd(&local->hw, data, len);
  1106. }
  1107. #endif
  1108. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1109. enum ieee80211_smps_mode smps_mode)
  1110. {
  1111. const u8 *ap;
  1112. enum ieee80211_smps_mode old_req;
  1113. int err;
  1114. old_req = sdata->u.mgd.req_smps;
  1115. sdata->u.mgd.req_smps = smps_mode;
  1116. if (old_req == smps_mode &&
  1117. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1118. return 0;
  1119. /*
  1120. * If not associated, or current association is not an HT
  1121. * association, there's no need to send an action frame.
  1122. */
  1123. if (!sdata->u.mgd.associated ||
  1124. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1125. mutex_lock(&sdata->local->iflist_mtx);
  1126. ieee80211_recalc_smps(sdata->local, sdata);
  1127. mutex_unlock(&sdata->local->iflist_mtx);
  1128. return 0;
  1129. }
  1130. ap = sdata->u.mgd.associated->bssid;
  1131. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1132. if (sdata->u.mgd.powersave)
  1133. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1134. else
  1135. smps_mode = IEEE80211_SMPS_OFF;
  1136. }
  1137. /* send SM PS frame to AP */
  1138. err = ieee80211_send_smps_action(sdata, smps_mode,
  1139. ap, ap);
  1140. if (err)
  1141. sdata->u.mgd.req_smps = old_req;
  1142. return err;
  1143. }
  1144. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1145. bool enabled, int timeout)
  1146. {
  1147. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1148. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1149. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1150. return -EOPNOTSUPP;
  1151. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1152. return -EOPNOTSUPP;
  1153. if (enabled == sdata->u.mgd.powersave &&
  1154. timeout == local->dynamic_ps_forced_timeout)
  1155. return 0;
  1156. sdata->u.mgd.powersave = enabled;
  1157. local->dynamic_ps_forced_timeout = timeout;
  1158. /* no change, but if automatic follow powersave */
  1159. mutex_lock(&sdata->u.mgd.mtx);
  1160. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1161. mutex_unlock(&sdata->u.mgd.mtx);
  1162. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1163. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1164. ieee80211_recalc_ps(local, -1);
  1165. return 0;
  1166. }
  1167. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1168. struct net_device *dev,
  1169. s32 rssi_thold, u32 rssi_hyst)
  1170. {
  1171. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1172. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1173. struct ieee80211_vif *vif = &sdata->vif;
  1174. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1175. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1176. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1177. return 0;
  1178. bss_conf->cqm_rssi_thold = rssi_thold;
  1179. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1180. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1181. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1182. return -EOPNOTSUPP;
  1183. return 0;
  1184. }
  1185. /* tell the driver upon association, unless already associated */
  1186. if (sdata->u.mgd.associated)
  1187. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1188. return 0;
  1189. }
  1190. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1191. struct net_device *dev,
  1192. const u8 *addr,
  1193. const struct cfg80211_bitrate_mask *mask)
  1194. {
  1195. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1196. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1197. int i;
  1198. /*
  1199. * This _could_ be supported by providing a hook for
  1200. * drivers for this function, but at this point it
  1201. * doesn't seem worth bothering.
  1202. */
  1203. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  1204. return -EOPNOTSUPP;
  1205. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1206. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1207. return 0;
  1208. }
  1209. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1210. struct net_device *dev,
  1211. struct ieee80211_channel *chan,
  1212. enum nl80211_channel_type channel_type,
  1213. unsigned int duration,
  1214. u64 *cookie)
  1215. {
  1216. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1217. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1218. duration, cookie);
  1219. }
  1220. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1221. struct net_device *dev,
  1222. u64 cookie)
  1223. {
  1224. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1225. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1226. }
  1227. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1228. struct ieee80211_channel *chan,
  1229. enum nl80211_channel_type channel_type,
  1230. bool channel_type_valid,
  1231. const u8 *buf, size_t len, u64 *cookie)
  1232. {
  1233. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1234. struct ieee80211_local *local = sdata->local;
  1235. struct sk_buff *skb;
  1236. struct sta_info *sta;
  1237. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1238. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1239. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1240. /* Check that we are on the requested channel for transmission */
  1241. if (chan != local->tmp_channel &&
  1242. chan != local->oper_channel)
  1243. return -EBUSY;
  1244. if (channel_type_valid &&
  1245. (channel_type != local->tmp_channel_type &&
  1246. channel_type != local->_oper_channel_type))
  1247. return -EBUSY;
  1248. switch (sdata->vif.type) {
  1249. case NL80211_IFTYPE_ADHOC:
  1250. if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1251. break;
  1252. rcu_read_lock();
  1253. sta = sta_info_get(sdata, mgmt->da);
  1254. rcu_read_unlock();
  1255. if (!sta)
  1256. return -ENOLINK;
  1257. break;
  1258. case NL80211_IFTYPE_STATION:
  1259. break;
  1260. default:
  1261. return -EOPNOTSUPP;
  1262. }
  1263. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1264. if (!skb)
  1265. return -ENOMEM;
  1266. skb_reserve(skb, local->hw.extra_tx_headroom);
  1267. memcpy(skb_put(skb, len), buf, len);
  1268. IEEE80211_SKB_CB(skb)->flags = flags;
  1269. skb->dev = sdata->dev;
  1270. ieee80211_tx_skb(sdata, skb);
  1271. *cookie = (unsigned long) skb;
  1272. return 0;
  1273. }
  1274. struct cfg80211_ops mac80211_config_ops = {
  1275. .add_virtual_intf = ieee80211_add_iface,
  1276. .del_virtual_intf = ieee80211_del_iface,
  1277. .change_virtual_intf = ieee80211_change_iface,
  1278. .add_key = ieee80211_add_key,
  1279. .del_key = ieee80211_del_key,
  1280. .get_key = ieee80211_get_key,
  1281. .set_default_key = ieee80211_config_default_key,
  1282. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1283. .add_beacon = ieee80211_add_beacon,
  1284. .set_beacon = ieee80211_set_beacon,
  1285. .del_beacon = ieee80211_del_beacon,
  1286. .add_station = ieee80211_add_station,
  1287. .del_station = ieee80211_del_station,
  1288. .change_station = ieee80211_change_station,
  1289. .get_station = ieee80211_get_station,
  1290. .dump_station = ieee80211_dump_station,
  1291. .dump_survey = ieee80211_dump_survey,
  1292. #ifdef CONFIG_MAC80211_MESH
  1293. .add_mpath = ieee80211_add_mpath,
  1294. .del_mpath = ieee80211_del_mpath,
  1295. .change_mpath = ieee80211_change_mpath,
  1296. .get_mpath = ieee80211_get_mpath,
  1297. .dump_mpath = ieee80211_dump_mpath,
  1298. .set_mesh_params = ieee80211_set_mesh_params,
  1299. .get_mesh_params = ieee80211_get_mesh_params,
  1300. #endif
  1301. .change_bss = ieee80211_change_bss,
  1302. .set_txq_params = ieee80211_set_txq_params,
  1303. .set_channel = ieee80211_set_channel,
  1304. .suspend = ieee80211_suspend,
  1305. .resume = ieee80211_resume,
  1306. .scan = ieee80211_scan,
  1307. .auth = ieee80211_auth,
  1308. .assoc = ieee80211_assoc,
  1309. .deauth = ieee80211_deauth,
  1310. .disassoc = ieee80211_disassoc,
  1311. .join_ibss = ieee80211_join_ibss,
  1312. .leave_ibss = ieee80211_leave_ibss,
  1313. .set_wiphy_params = ieee80211_set_wiphy_params,
  1314. .set_tx_power = ieee80211_set_tx_power,
  1315. .get_tx_power = ieee80211_get_tx_power,
  1316. .set_wds_peer = ieee80211_set_wds_peer,
  1317. .rfkill_poll = ieee80211_rfkill_poll,
  1318. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1319. .set_power_mgmt = ieee80211_set_power_mgmt,
  1320. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1321. .remain_on_channel = ieee80211_remain_on_channel,
  1322. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1323. .mgmt_tx = ieee80211_mgmt_tx,
  1324. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1325. };