cfg.c 36 KB

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