cfg.c 38 KB

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