cfg.c 35 KB

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