cfg.c 34 KB

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