rt2x00mac.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00mac
  19. Abstract: rt2x00 generic mac80211 routines.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include "rt2x00.h"
  24. #include "rt2x00lib.h"
  25. static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
  26. struct data_queue *queue,
  27. struct sk_buff *frag_skb)
  28. {
  29. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(frag_skb);
  30. struct ieee80211_tx_info *rts_info;
  31. struct sk_buff *skb;
  32. unsigned int data_length;
  33. int retval = 0;
  34. if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  35. data_length = sizeof(struct ieee80211_cts);
  36. else
  37. data_length = sizeof(struct ieee80211_rts);
  38. skb = dev_alloc_skb(data_length + rt2x00dev->hw->extra_tx_headroom);
  39. if (unlikely(!skb)) {
  40. WARNING(rt2x00dev, "Failed to create RTS/CTS frame.\n");
  41. return -ENOMEM;
  42. }
  43. skb_reserve(skb, rt2x00dev->hw->extra_tx_headroom);
  44. skb_put(skb, data_length);
  45. /*
  46. * Copy TX information over from original frame to
  47. * RTS/CTS frame. Note that we set the no encryption flag
  48. * since we don't want this frame to be encrypted.
  49. * RTS frames should be acked, while CTS-to-self frames
  50. * should not. The ready for TX flag is cleared to prevent
  51. * it being automatically send when the descriptor is
  52. * written to the hardware.
  53. */
  54. memcpy(skb->cb, frag_skb->cb, sizeof(skb->cb));
  55. rts_info = IEEE80211_SKB_CB(skb);
  56. rts_info->control.rates[0].flags &= ~IEEE80211_TX_RC_USE_RTS_CTS;
  57. rts_info->control.rates[0].flags &= ~IEEE80211_TX_RC_USE_CTS_PROTECT;
  58. rts_info->flags &= ~IEEE80211_TX_CTL_REQ_TX_STATUS;
  59. if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  60. rts_info->flags |= IEEE80211_TX_CTL_NO_ACK;
  61. else
  62. rts_info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
  63. skb->do_not_encrypt = 1;
  64. /*
  65. * RTS/CTS frame should use the length of the frame plus any
  66. * encryption overhead that will be added by the hardware.
  67. */
  68. if (!frag_skb->do_not_encrypt)
  69. data_length += rt2x00crypto_tx_overhead(tx_info);
  70. if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  71. ieee80211_ctstoself_get(rt2x00dev->hw, tx_info->control.vif,
  72. frag_skb->data, data_length, tx_info,
  73. (struct ieee80211_cts *)(skb->data));
  74. else
  75. ieee80211_rts_get(rt2x00dev->hw, tx_info->control.vif,
  76. frag_skb->data, data_length, tx_info,
  77. (struct ieee80211_rts *)(skb->data));
  78. retval = rt2x00queue_write_tx_frame(queue, skb);
  79. if (retval) {
  80. dev_kfree_skb_any(skb);
  81. WARNING(rt2x00dev, "Failed to send RTS/CTS frame.\n");
  82. }
  83. return retval;
  84. }
  85. int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  86. {
  87. struct rt2x00_dev *rt2x00dev = hw->priv;
  88. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  89. struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data;
  90. enum data_queue_qid qid = skb_get_queue_mapping(skb);
  91. struct data_queue *queue;
  92. u16 frame_control;
  93. /*
  94. * Mac80211 might be calling this function while we are trying
  95. * to remove the device or perhaps suspending it.
  96. * Note that we can only stop the TX queues inside the TX path
  97. * due to possible race conditions in mac80211.
  98. */
  99. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  100. goto exit_fail;
  101. /*
  102. * Determine which queue to put packet on.
  103. */
  104. if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM &&
  105. test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags))
  106. queue = rt2x00queue_get_queue(rt2x00dev, QID_ATIM);
  107. else
  108. queue = rt2x00queue_get_queue(rt2x00dev, qid);
  109. if (unlikely(!queue)) {
  110. ERROR(rt2x00dev,
  111. "Attempt to send packet over invalid queue %d.\n"
  112. "Please file bug report to %s.\n", qid, DRV_PROJECT);
  113. goto exit_fail;
  114. }
  115. /*
  116. * If CTS/RTS is required. create and queue that frame first.
  117. * Make sure we have at least enough entries available to send
  118. * this CTS/RTS frame as well as the data frame.
  119. * Note that when the driver has set the set_rts_threshold()
  120. * callback function it doesn't need software generation of
  121. * either RTS or CTS-to-self frame and handles everything
  122. * inside the hardware.
  123. */
  124. frame_control = le16_to_cpu(ieee80211hdr->frame_control);
  125. if ((tx_info->control.rates[0].flags & (IEEE80211_TX_RC_USE_RTS_CTS |
  126. IEEE80211_TX_RC_USE_CTS_PROTECT)) &&
  127. !rt2x00dev->ops->hw->set_rts_threshold) {
  128. if (rt2x00queue_available(queue) <= 1)
  129. goto exit_fail;
  130. if (rt2x00mac_tx_rts_cts(rt2x00dev, queue, skb))
  131. goto exit_fail;
  132. }
  133. if (rt2x00queue_write_tx_frame(queue, skb))
  134. goto exit_fail;
  135. if (rt2x00queue_threshold(queue))
  136. ieee80211_stop_queue(rt2x00dev->hw, qid);
  137. return NETDEV_TX_OK;
  138. exit_fail:
  139. ieee80211_stop_queue(rt2x00dev->hw, qid);
  140. dev_kfree_skb_any(skb);
  141. return NETDEV_TX_OK;
  142. }
  143. EXPORT_SYMBOL_GPL(rt2x00mac_tx);
  144. int rt2x00mac_start(struct ieee80211_hw *hw)
  145. {
  146. struct rt2x00_dev *rt2x00dev = hw->priv;
  147. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  148. return 0;
  149. return rt2x00lib_start(rt2x00dev);
  150. }
  151. EXPORT_SYMBOL_GPL(rt2x00mac_start);
  152. void rt2x00mac_stop(struct ieee80211_hw *hw)
  153. {
  154. struct rt2x00_dev *rt2x00dev = hw->priv;
  155. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  156. return;
  157. rt2x00lib_stop(rt2x00dev);
  158. }
  159. EXPORT_SYMBOL_GPL(rt2x00mac_stop);
  160. int rt2x00mac_add_interface(struct ieee80211_hw *hw,
  161. struct ieee80211_if_init_conf *conf)
  162. {
  163. struct rt2x00_dev *rt2x00dev = hw->priv;
  164. struct rt2x00_intf *intf = vif_to_intf(conf->vif);
  165. struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, QID_BEACON);
  166. struct queue_entry *entry = NULL;
  167. unsigned int i;
  168. /*
  169. * Don't allow interfaces to be added
  170. * the device has disappeared.
  171. */
  172. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
  173. !test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags))
  174. return -ENODEV;
  175. switch (conf->type) {
  176. case NL80211_IFTYPE_AP:
  177. /*
  178. * We don't support mixed combinations of
  179. * sta and ap interfaces.
  180. */
  181. if (rt2x00dev->intf_sta_count)
  182. return -ENOBUFS;
  183. /*
  184. * Check if we exceeded the maximum amount
  185. * of supported interfaces.
  186. */
  187. if (rt2x00dev->intf_ap_count >= rt2x00dev->ops->max_ap_intf)
  188. return -ENOBUFS;
  189. break;
  190. case NL80211_IFTYPE_STATION:
  191. case NL80211_IFTYPE_ADHOC:
  192. /*
  193. * We don't support mixed combinations of
  194. * sta and ap interfaces.
  195. */
  196. if (rt2x00dev->intf_ap_count)
  197. return -ENOBUFS;
  198. /*
  199. * Check if we exceeded the maximum amount
  200. * of supported interfaces.
  201. */
  202. if (rt2x00dev->intf_sta_count >= rt2x00dev->ops->max_sta_intf)
  203. return -ENOBUFS;
  204. break;
  205. default:
  206. return -EINVAL;
  207. }
  208. /*
  209. * Loop through all beacon queues to find a free
  210. * entry. Since there are as much beacon entries
  211. * as the maximum interfaces, this search shouldn't
  212. * fail.
  213. */
  214. for (i = 0; i < queue->limit; i++) {
  215. entry = &queue->entries[i];
  216. if (!test_and_set_bit(ENTRY_BCN_ASSIGNED, &entry->flags))
  217. break;
  218. }
  219. if (unlikely(i == queue->limit))
  220. return -ENOBUFS;
  221. /*
  222. * We are now absolutely sure the interface can be created,
  223. * increase interface count and start initialization.
  224. */
  225. if (conf->type == NL80211_IFTYPE_AP)
  226. rt2x00dev->intf_ap_count++;
  227. else
  228. rt2x00dev->intf_sta_count++;
  229. spin_lock_init(&intf->lock);
  230. spin_lock_init(&intf->seqlock);
  231. intf->beacon = entry;
  232. if (conf->type == NL80211_IFTYPE_AP)
  233. memcpy(&intf->bssid, conf->mac_addr, ETH_ALEN);
  234. memcpy(&intf->mac, conf->mac_addr, ETH_ALEN);
  235. /*
  236. * The MAC adddress must be configured after the device
  237. * has been initialized. Otherwise the device can reset
  238. * the MAC registers.
  239. */
  240. rt2x00lib_config_intf(rt2x00dev, intf, conf->type, intf->mac, NULL);
  241. /*
  242. * Some filters depend on the current working mode. We can force
  243. * an update during the next configure_filter() run by mac80211 by
  244. * resetting the current packet_filter state.
  245. */
  246. rt2x00dev->packet_filter = 0;
  247. return 0;
  248. }
  249. EXPORT_SYMBOL_GPL(rt2x00mac_add_interface);
  250. void rt2x00mac_remove_interface(struct ieee80211_hw *hw,
  251. struct ieee80211_if_init_conf *conf)
  252. {
  253. struct rt2x00_dev *rt2x00dev = hw->priv;
  254. struct rt2x00_intf *intf = vif_to_intf(conf->vif);
  255. /*
  256. * Don't allow interfaces to be remove while
  257. * either the device has disappeared or when
  258. * no interface is present.
  259. */
  260. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) ||
  261. (conf->type == NL80211_IFTYPE_AP && !rt2x00dev->intf_ap_count) ||
  262. (conf->type != NL80211_IFTYPE_AP && !rt2x00dev->intf_sta_count))
  263. return;
  264. if (conf->type == NL80211_IFTYPE_AP)
  265. rt2x00dev->intf_ap_count--;
  266. else
  267. rt2x00dev->intf_sta_count--;
  268. /*
  269. * Release beacon entry so it is available for
  270. * new interfaces again.
  271. */
  272. clear_bit(ENTRY_BCN_ASSIGNED, &intf->beacon->flags);
  273. /*
  274. * Make sure the bssid and mac address registers
  275. * are cleared to prevent false ACKing of frames.
  276. */
  277. rt2x00lib_config_intf(rt2x00dev, intf,
  278. NL80211_IFTYPE_UNSPECIFIED, NULL, NULL);
  279. }
  280. EXPORT_SYMBOL_GPL(rt2x00mac_remove_interface);
  281. int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed)
  282. {
  283. struct rt2x00_dev *rt2x00dev = hw->priv;
  284. struct ieee80211_conf *conf = &hw->conf;
  285. int status;
  286. /*
  287. * Mac80211 might be calling this function while we are trying
  288. * to remove the device or perhaps suspending it.
  289. */
  290. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  291. return 0;
  292. /*
  293. * Only change device state when the radio is enabled. It does not
  294. * matter what parameters we have configured when the radio is disabled
  295. * because we won't be able to send or receive anyway. Also note that
  296. * some configuration parameters (e.g. channel and antenna values) can
  297. * only be set when the radio is enabled.
  298. */
  299. if (conf->radio_enabled) {
  300. /* For programming the values, we have to turn RX off */
  301. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
  302. /* Enable the radio */
  303. status = rt2x00lib_enable_radio(rt2x00dev);
  304. if (unlikely(status))
  305. return status;
  306. /*
  307. * When we've just turned on the radio, we want to reprogram
  308. * everything to ensure a consistent state
  309. */
  310. rt2x00lib_config(rt2x00dev, conf, changed);
  311. /*
  312. * The radio was enabled, configure the antenna to the
  313. * default settings, the link tuner will later start
  314. * continue configuring the antenna based on the software
  315. * diversity. But for non-diversity configurations, we need
  316. * to have configured the correct state now.
  317. */
  318. if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED)
  319. rt2x00lib_config_antenna(rt2x00dev,
  320. &rt2x00dev->default_ant);
  321. /* Turn RX back on */
  322. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
  323. } else {
  324. /* Disable the radio */
  325. rt2x00lib_disable_radio(rt2x00dev);
  326. }
  327. return 0;
  328. }
  329. EXPORT_SYMBOL_GPL(rt2x00mac_config);
  330. int rt2x00mac_config_interface(struct ieee80211_hw *hw,
  331. struct ieee80211_vif *vif,
  332. struct ieee80211_if_conf *conf)
  333. {
  334. struct rt2x00_dev *rt2x00dev = hw->priv;
  335. struct rt2x00_intf *intf = vif_to_intf(vif);
  336. int update_bssid = 0;
  337. int status = 0;
  338. /*
  339. * Mac80211 might be calling this function while we are trying
  340. * to remove the device or perhaps suspending it.
  341. */
  342. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  343. return 0;
  344. spin_lock(&intf->lock);
  345. /*
  346. * conf->bssid can be NULL if coming from the internal
  347. * beacon update routine.
  348. */
  349. if (conf->changed & IEEE80211_IFCC_BSSID && conf->bssid) {
  350. update_bssid = 1;
  351. memcpy(&intf->bssid, conf->bssid, ETH_ALEN);
  352. }
  353. spin_unlock(&intf->lock);
  354. /*
  355. * Call rt2x00_config_intf() outside of the spinlock context since
  356. * the call will sleep for USB drivers. By using the ieee80211_if_conf
  357. * values as arguments we make keep access to rt2x00_intf thread safe
  358. * even without the lock.
  359. */
  360. rt2x00lib_config_intf(rt2x00dev, intf, vif->type, NULL,
  361. update_bssid ? conf->bssid : NULL);
  362. /*
  363. * Update the beacon.
  364. */
  365. if (conf->changed & IEEE80211_IFCC_BEACON)
  366. status = rt2x00queue_update_beacon(rt2x00dev, vif);
  367. return status;
  368. }
  369. EXPORT_SYMBOL_GPL(rt2x00mac_config_interface);
  370. void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
  371. unsigned int changed_flags,
  372. unsigned int *total_flags,
  373. int mc_count, struct dev_addr_list *mc_list)
  374. {
  375. struct rt2x00_dev *rt2x00dev = hw->priv;
  376. /*
  377. * Mask off any flags we are going to ignore
  378. * from the total_flags field.
  379. */
  380. *total_flags &=
  381. FIF_ALLMULTI |
  382. FIF_FCSFAIL |
  383. FIF_PLCPFAIL |
  384. FIF_CONTROL |
  385. FIF_OTHER_BSS |
  386. FIF_PROMISC_IN_BSS;
  387. /*
  388. * Apply some rules to the filters:
  389. * - Some filters imply different filters to be set.
  390. * - Some things we can't filter out at all.
  391. * - Multicast filter seems to kill broadcast traffic so never use it.
  392. */
  393. *total_flags |= FIF_ALLMULTI;
  394. if (*total_flags & FIF_OTHER_BSS ||
  395. *total_flags & FIF_PROMISC_IN_BSS)
  396. *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
  397. /*
  398. * Check if there is any work left for us.
  399. */
  400. if (rt2x00dev->packet_filter == *total_flags)
  401. return;
  402. rt2x00dev->packet_filter = *total_flags;
  403. if (!test_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags))
  404. rt2x00dev->ops->lib->config_filter(rt2x00dev, *total_flags);
  405. else
  406. queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work);
  407. }
  408. EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter);
  409. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  410. int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  411. const u8 *local_address, const u8 *address,
  412. struct ieee80211_key_conf *key)
  413. {
  414. struct rt2x00_dev *rt2x00dev = hw->priv;
  415. struct ieee80211_sta *sta;
  416. int (*set_key) (struct rt2x00_dev *rt2x00dev,
  417. struct rt2x00lib_crypto *crypto,
  418. struct ieee80211_key_conf *key);
  419. struct rt2x00lib_crypto crypto;
  420. if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
  421. return 0;
  422. else if (!test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags))
  423. return -EOPNOTSUPP;
  424. else if (key->keylen > 32)
  425. return -ENOSPC;
  426. memset(&crypto, 0, sizeof(crypto));
  427. /*
  428. * When in STA mode, bssidx is always 0 otherwise local_address[5]
  429. * contains the bss number, see BSS_ID_MASK comments for details.
  430. */
  431. if (rt2x00dev->intf_sta_count)
  432. crypto.bssidx = 0;
  433. else
  434. crypto.bssidx =
  435. local_address[5] & (rt2x00dev->ops->max_ap_intf - 1);
  436. crypto.cipher = rt2x00crypto_key_to_cipher(key);
  437. if (crypto.cipher == CIPHER_NONE)
  438. return -EOPNOTSUPP;
  439. crypto.cmd = cmd;
  440. crypto.address = address;
  441. if (crypto.cipher == CIPHER_TKIP) {
  442. if (key->keylen > NL80211_TKIP_DATA_OFFSET_ENCR_KEY)
  443. memcpy(&crypto.key,
  444. &key->key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY],
  445. sizeof(crypto.key));
  446. if (key->keylen > NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY)
  447. memcpy(&crypto.tx_mic,
  448. &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
  449. sizeof(crypto.tx_mic));
  450. if (key->keylen > NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY)
  451. memcpy(&crypto.rx_mic,
  452. &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
  453. sizeof(crypto.rx_mic));
  454. } else
  455. memcpy(&crypto.key, &key->key[0], key->keylen);
  456. /*
  457. * Discover the Association ID from mac80211.
  458. * Some drivers need this information when updating the
  459. * hardware key (either adding or removing).
  460. */
  461. rcu_read_lock();
  462. sta = ieee80211_find_sta(hw, address);
  463. if (sta)
  464. crypto.aid = sta->aid;
  465. rcu_read_unlock();
  466. /*
  467. * Each BSS has a maximum of 4 shared keys.
  468. * Shared key index values:
  469. * 0) BSS0 key0
  470. * 1) BSS0 key1
  471. * ...
  472. * 4) BSS1 key0
  473. * ...
  474. * 8) BSS2 key0
  475. * ...
  476. * Both pairwise as shared key indeces are determined by
  477. * driver. This is required because the hardware requires
  478. * keys to be assigned in correct order (When key 1 is
  479. * provided but key 0 is not, then the key is not found
  480. * by the hardware during RX).
  481. */
  482. if (cmd == SET_KEY)
  483. key->hw_key_idx = 0;
  484. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  485. set_key = rt2x00dev->ops->lib->config_pairwise_key;
  486. else
  487. set_key = rt2x00dev->ops->lib->config_shared_key;
  488. if (!set_key)
  489. return -EOPNOTSUPP;
  490. return set_key(rt2x00dev, &crypto, key);
  491. }
  492. EXPORT_SYMBOL_GPL(rt2x00mac_set_key);
  493. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  494. int rt2x00mac_get_stats(struct ieee80211_hw *hw,
  495. struct ieee80211_low_level_stats *stats)
  496. {
  497. struct rt2x00_dev *rt2x00dev = hw->priv;
  498. /*
  499. * The dot11ACKFailureCount, dot11RTSFailureCount and
  500. * dot11RTSSuccessCount are updated in interrupt time.
  501. * dot11FCSErrorCount is updated in the link tuner.
  502. */
  503. memcpy(stats, &rt2x00dev->low_level_stats, sizeof(*stats));
  504. return 0;
  505. }
  506. EXPORT_SYMBOL_GPL(rt2x00mac_get_stats);
  507. int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
  508. struct ieee80211_tx_queue_stats *stats)
  509. {
  510. struct rt2x00_dev *rt2x00dev = hw->priv;
  511. unsigned int i;
  512. for (i = 0; i < rt2x00dev->ops->tx_queues; i++) {
  513. stats[i].len = rt2x00dev->tx[i].length;
  514. stats[i].limit = rt2x00dev->tx[i].limit;
  515. stats[i].count = rt2x00dev->tx[i].count;
  516. }
  517. return 0;
  518. }
  519. EXPORT_SYMBOL_GPL(rt2x00mac_get_tx_stats);
  520. void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
  521. struct ieee80211_vif *vif,
  522. struct ieee80211_bss_conf *bss_conf,
  523. u32 changes)
  524. {
  525. struct rt2x00_dev *rt2x00dev = hw->priv;
  526. struct rt2x00_intf *intf = vif_to_intf(vif);
  527. unsigned int delayed = 0;
  528. /*
  529. * When the association status has changed we must reset the link
  530. * tuner counter. This is because some drivers determine if they
  531. * should perform link tuning based on the number of seconds
  532. * while associated or not associated.
  533. */
  534. if (changes & BSS_CHANGED_ASSOC) {
  535. rt2x00dev->link.count = 0;
  536. if (bss_conf->assoc)
  537. rt2x00dev->intf_associated++;
  538. else
  539. rt2x00dev->intf_associated--;
  540. if (!test_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags))
  541. rt2x00leds_led_assoc(rt2x00dev,
  542. !!rt2x00dev->intf_associated);
  543. else
  544. delayed |= DELAYED_LED_ASSOC;
  545. }
  546. /*
  547. * When the erp information has changed, we should perform
  548. * additional configuration steps. For all other changes we are done.
  549. */
  550. if (changes & ~(BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
  551. if (!test_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags))
  552. rt2x00lib_config_erp(rt2x00dev, intf, bss_conf);
  553. else
  554. delayed |= DELAYED_CONFIG_ERP;
  555. }
  556. spin_lock(&intf->lock);
  557. if (delayed) {
  558. intf->delayed_flags |= delayed;
  559. schedule_work(&rt2x00dev->intf_work);
  560. }
  561. spin_unlock(&intf->lock);
  562. }
  563. EXPORT_SYMBOL_GPL(rt2x00mac_bss_info_changed);
  564. int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  565. const struct ieee80211_tx_queue_params *params)
  566. {
  567. struct rt2x00_dev *rt2x00dev = hw->priv;
  568. struct data_queue *queue;
  569. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  570. if (unlikely(!queue))
  571. return -EINVAL;
  572. /*
  573. * The passed variables are stored as real value ((2^n)-1).
  574. * Ralink registers require to know the bit number 'n'.
  575. */
  576. if (params->cw_min > 0)
  577. queue->cw_min = fls(params->cw_min);
  578. else
  579. queue->cw_min = 5; /* cw_min: 2^5 = 32. */
  580. if (params->cw_max > 0)
  581. queue->cw_max = fls(params->cw_max);
  582. else
  583. queue->cw_max = 10; /* cw_min: 2^10 = 1024. */
  584. queue->aifs = params->aifs;
  585. queue->txop = params->txop;
  586. INFO(rt2x00dev,
  587. "Configured TX queue %d - CWmin: %d, CWmax: %d, Aifs: %d, TXop: %d.\n",
  588. queue_idx, queue->cw_min, queue->cw_max, queue->aifs, queue->txop);
  589. return 0;
  590. }
  591. EXPORT_SYMBOL_GPL(rt2x00mac_conf_tx);