mac80211-ops.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /*-
  2. * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  3. * Copyright (c) 2004-2005 Atheros Communications, Inc.
  4. * Copyright (c) 2006 Devicescape Software, Inc.
  5. * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
  6. * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
  7. * Copyright (c) 2010 Bruno Randolf <br1@einfach.org>
  8. *
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
  19. * redistribution must be conditioned upon including a substantially
  20. * similar Disclaimer requirement for further binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
  33. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  34. * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
  35. * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  36. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  37. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  38. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  39. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  40. * THE POSSIBILITY OF SUCH DAMAGES.
  41. *
  42. */
  43. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  44. #include <net/mac80211.h>
  45. #include <asm/unaligned.h>
  46. #include "ath5k.h"
  47. #include "base.h"
  48. #include "reg.h"
  49. /********************\
  50. * Mac80211 functions *
  51. \********************/
  52. static void
  53. ath5k_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
  54. struct sk_buff *skb)
  55. {
  56. struct ath5k_hw *ah = hw->priv;
  57. u16 qnum = skb_get_queue_mapping(skb);
  58. if (WARN_ON(qnum >= ah->ah_capabilities.cap_queues.q_tx_num)) {
  59. ieee80211_free_txskb(hw, skb);
  60. return;
  61. }
  62. ath5k_tx_queue(hw, skb, &ah->txqs[qnum]);
  63. }
  64. static int
  65. ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  66. {
  67. struct ath5k_hw *ah = hw->priv;
  68. int ret;
  69. struct ath5k_vif *avf = (void *)vif->drv_priv;
  70. mutex_lock(&ah->lock);
  71. if ((vif->type == NL80211_IFTYPE_AP ||
  72. vif->type == NL80211_IFTYPE_ADHOC)
  73. && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) {
  74. ret = -ELNRNG;
  75. goto end;
  76. }
  77. /* Don't allow other interfaces if one ad-hoc is configured.
  78. * TODO: Fix the problems with ad-hoc and multiple other interfaces.
  79. * We would need to operate the HW in ad-hoc mode to allow TSF updates
  80. * for the IBSS, but this breaks with additional AP or STA interfaces
  81. * at the moment. */
  82. if (ah->num_adhoc_vifs ||
  83. (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
  84. ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n");
  85. ret = -ELNRNG;
  86. goto end;
  87. }
  88. switch (vif->type) {
  89. case NL80211_IFTYPE_AP:
  90. case NL80211_IFTYPE_STATION:
  91. case NL80211_IFTYPE_ADHOC:
  92. case NL80211_IFTYPE_MESH_POINT:
  93. avf->opmode = vif->type;
  94. break;
  95. default:
  96. ret = -EOPNOTSUPP;
  97. goto end;
  98. }
  99. ah->nvifs++;
  100. ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
  101. /* Assign the vap/adhoc to a beacon xmit slot. */
  102. if ((avf->opmode == NL80211_IFTYPE_AP) ||
  103. (avf->opmode == NL80211_IFTYPE_ADHOC) ||
  104. (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
  105. int slot;
  106. WARN_ON(list_empty(&ah->bcbuf));
  107. avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf,
  108. list);
  109. list_del(&avf->bbuf->list);
  110. avf->bslot = 0;
  111. for (slot = 0; slot < ATH_BCBUF; slot++) {
  112. if (!ah->bslot[slot]) {
  113. avf->bslot = slot;
  114. break;
  115. }
  116. }
  117. BUG_ON(ah->bslot[avf->bslot] != NULL);
  118. ah->bslot[avf->bslot] = vif;
  119. if (avf->opmode == NL80211_IFTYPE_AP)
  120. ah->num_ap_vifs++;
  121. else if (avf->opmode == NL80211_IFTYPE_ADHOC)
  122. ah->num_adhoc_vifs++;
  123. else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
  124. ah->num_mesh_vifs++;
  125. }
  126. /* Any MAC address is fine, all others are included through the
  127. * filter.
  128. */
  129. ath5k_hw_set_lladdr(ah, vif->addr);
  130. ath5k_update_bssid_mask_and_opmode(ah, vif);
  131. ret = 0;
  132. end:
  133. mutex_unlock(&ah->lock);
  134. return ret;
  135. }
  136. static void
  137. ath5k_remove_interface(struct ieee80211_hw *hw,
  138. struct ieee80211_vif *vif)
  139. {
  140. struct ath5k_hw *ah = hw->priv;
  141. struct ath5k_vif *avf = (void *)vif->drv_priv;
  142. unsigned int i;
  143. mutex_lock(&ah->lock);
  144. ah->nvifs--;
  145. if (avf->bbuf) {
  146. ath5k_txbuf_free_skb(ah, avf->bbuf);
  147. list_add_tail(&avf->bbuf->list, &ah->bcbuf);
  148. for (i = 0; i < ATH_BCBUF; i++) {
  149. if (ah->bslot[i] == vif) {
  150. ah->bslot[i] = NULL;
  151. break;
  152. }
  153. }
  154. avf->bbuf = NULL;
  155. }
  156. if (avf->opmode == NL80211_IFTYPE_AP)
  157. ah->num_ap_vifs--;
  158. else if (avf->opmode == NL80211_IFTYPE_ADHOC)
  159. ah->num_adhoc_vifs--;
  160. else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
  161. ah->num_mesh_vifs--;
  162. ath5k_update_bssid_mask_and_opmode(ah, NULL);
  163. mutex_unlock(&ah->lock);
  164. }
  165. /*
  166. * TODO: Phy disable/diversity etc
  167. */
  168. static int
  169. ath5k_config(struct ieee80211_hw *hw, u32 changed)
  170. {
  171. struct ath5k_hw *ah = hw->priv;
  172. struct ieee80211_conf *conf = &hw->conf;
  173. int ret = 0;
  174. int i;
  175. mutex_lock(&ah->lock);
  176. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  177. ret = ath5k_chan_set(ah, conf->channel);
  178. if (ret < 0)
  179. goto unlock;
  180. }
  181. if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
  182. (ah->ah_txpower.txp_requested != conf->power_level)) {
  183. ah->ah_txpower.txp_requested = conf->power_level;
  184. /* Half dB steps */
  185. ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
  186. }
  187. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
  188. ah->ah_retry_long = conf->long_frame_max_tx_count;
  189. ah->ah_retry_short = conf->short_frame_max_tx_count;
  190. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
  191. ath5k_hw_set_tx_retry_limits(ah, i);
  192. }
  193. /* TODO:
  194. * 1) Move this on config_interface and handle each case
  195. * separately eg. when we have only one STA vif, use
  196. * AR5K_ANTMODE_SINGLE_AP
  197. *
  198. * 2) Allow the user to change antenna mode eg. when only
  199. * one antenna is present
  200. *
  201. * 3) Allow the user to set default/tx antenna when possible
  202. *
  203. * 4) Default mode should handle 90% of the cases, together
  204. * with fixed a/b and single AP modes we should be able to
  205. * handle 99%. Sectored modes are extreme cases and i still
  206. * haven't found a usage for them. If we decide to support them,
  207. * then we must allow the user to set how many tx antennas we
  208. * have available
  209. */
  210. ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
  211. unlock:
  212. mutex_unlock(&ah->lock);
  213. return ret;
  214. }
  215. static void
  216. ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  217. struct ieee80211_bss_conf *bss_conf, u32 changes)
  218. {
  219. struct ath5k_vif *avf = (void *)vif->drv_priv;
  220. struct ath5k_hw *ah = hw->priv;
  221. struct ath_common *common = ath5k_hw_common(ah);
  222. mutex_lock(&ah->lock);
  223. if (changes & BSS_CHANGED_BSSID) {
  224. /* Cache for later use during resets */
  225. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  226. common->curaid = 0;
  227. ath5k_hw_set_bssid(ah);
  228. mmiowb();
  229. }
  230. if (changes & BSS_CHANGED_BEACON_INT)
  231. ah->bintval = bss_conf->beacon_int;
  232. if (changes & BSS_CHANGED_ERP_SLOT) {
  233. int slot_time;
  234. ah->ah_short_slot = bss_conf->use_short_slot;
  235. slot_time = ath5k_hw_get_default_slottime(ah) +
  236. 3 * ah->ah_coverage_class;
  237. ath5k_hw_set_ifs_intervals(ah, slot_time);
  238. }
  239. if (changes & BSS_CHANGED_ASSOC) {
  240. avf->assoc = bss_conf->assoc;
  241. if (bss_conf->assoc)
  242. ah->assoc = bss_conf->assoc;
  243. else
  244. ah->assoc = ath5k_any_vif_assoc(ah);
  245. if (ah->opmode == NL80211_IFTYPE_STATION)
  246. ath5k_set_beacon_filter(hw, ah->assoc);
  247. ath5k_hw_set_ledstate(ah, ah->assoc ?
  248. AR5K_LED_ASSOC : AR5K_LED_INIT);
  249. if (bss_conf->assoc) {
  250. ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
  251. "Bss Info ASSOC %d, bssid: %pM\n",
  252. bss_conf->aid, common->curbssid);
  253. common->curaid = bss_conf->aid;
  254. ath5k_hw_set_bssid(ah);
  255. /* Once ANI is available you would start it here */
  256. }
  257. }
  258. if (changes & BSS_CHANGED_BEACON) {
  259. spin_lock_bh(&ah->block);
  260. ath5k_beacon_update(hw, vif);
  261. spin_unlock_bh(&ah->block);
  262. }
  263. if (changes & BSS_CHANGED_BEACON_ENABLED)
  264. ah->enable_beacon = bss_conf->enable_beacon;
  265. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
  266. BSS_CHANGED_BEACON_INT))
  267. ath5k_beacon_config(ah);
  268. mutex_unlock(&ah->lock);
  269. }
  270. static u64
  271. ath5k_prepare_multicast(struct ieee80211_hw *hw,
  272. struct netdev_hw_addr_list *mc_list)
  273. {
  274. u32 mfilt[2], val;
  275. u8 pos;
  276. struct netdev_hw_addr *ha;
  277. mfilt[0] = 0;
  278. mfilt[1] = 1;
  279. netdev_hw_addr_list_for_each(ha, mc_list) {
  280. /* calculate XOR of eight 6-bit values */
  281. val = get_unaligned_le32(ha->addr + 0);
  282. pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  283. val = get_unaligned_le32(ha->addr + 3);
  284. pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  285. pos &= 0x3f;
  286. mfilt[pos / 32] |= (1 << (pos % 32));
  287. /* XXX: we might be able to just do this instead,
  288. * but not sure, needs testing, if we do use this we'd
  289. * need to inform below not to reset the mcast */
  290. /* ath5k_hw_set_mcast_filterindex(ah,
  291. * ha->addr[5]); */
  292. }
  293. return ((u64)(mfilt[1]) << 32) | mfilt[0];
  294. }
  295. /*
  296. * o always accept unicast, broadcast, and multicast traffic
  297. * o multicast traffic for all BSSIDs will be enabled if mac80211
  298. * says it should be
  299. * o maintain current state of phy ofdm or phy cck error reception.
  300. * If the hardware detects any of these type of errors then
  301. * ath5k_hw_get_rx_filter() will pass to us the respective
  302. * hardware filters to be able to receive these type of frames.
  303. * o probe request frames are accepted only when operating in
  304. * hostap, adhoc, or monitor modes
  305. * o enable promiscuous mode according to the interface state
  306. * o accept beacons:
  307. * - when operating in adhoc mode so the 802.11 layer creates
  308. * node table entries for peers,
  309. * - when operating in station mode for collecting rssi data when
  310. * the station is otherwise quiet, or
  311. * - when scanning
  312. */
  313. static void
  314. ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  315. unsigned int *new_flags, u64 multicast)
  316. {
  317. #define SUPPORTED_FIF_FLAGS \
  318. (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
  319. FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
  320. FIF_BCN_PRBRESP_PROMISC)
  321. struct ath5k_hw *ah = hw->priv;
  322. u32 mfilt[2], rfilt;
  323. struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
  324. mutex_lock(&ah->lock);
  325. mfilt[0] = multicast;
  326. mfilt[1] = multicast >> 32;
  327. /* Only deal with supported flags */
  328. changed_flags &= SUPPORTED_FIF_FLAGS;
  329. *new_flags &= SUPPORTED_FIF_FLAGS;
  330. /* If HW detects any phy or radar errors, leave those filters on.
  331. * Also, always enable Unicast, Broadcasts and Multicast
  332. * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
  333. rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
  334. (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
  335. AR5K_RX_FILTER_MCAST);
  336. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  337. if (*new_flags & FIF_PROMISC_IN_BSS)
  338. __set_bit(ATH_STAT_PROMISC, ah->status);
  339. else
  340. __clear_bit(ATH_STAT_PROMISC, ah->status);
  341. }
  342. if (test_bit(ATH_STAT_PROMISC, ah->status))
  343. rfilt |= AR5K_RX_FILTER_PROM;
  344. /* Note, AR5K_RX_FILTER_MCAST is already enabled */
  345. if (*new_flags & FIF_ALLMULTI) {
  346. mfilt[0] = ~0;
  347. mfilt[1] = ~0;
  348. }
  349. /* This is the best we can do */
  350. if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
  351. rfilt |= AR5K_RX_FILTER_PHYERR;
  352. /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
  353. * and probes for any BSSID */
  354. if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1))
  355. rfilt |= AR5K_RX_FILTER_BEACON;
  356. /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
  357. * set we should only pass on control frames for this
  358. * station. This needs testing. I believe right now this
  359. * enables *all* control frames, which is OK.. but
  360. * but we should see if we can improve on granularity */
  361. if (*new_flags & FIF_CONTROL)
  362. rfilt |= AR5K_RX_FILTER_CONTROL;
  363. /* Additional settings per mode -- this is per ath5k */
  364. /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
  365. switch (ah->opmode) {
  366. case NL80211_IFTYPE_MESH_POINT:
  367. rfilt |= AR5K_RX_FILTER_CONTROL |
  368. AR5K_RX_FILTER_BEACON |
  369. AR5K_RX_FILTER_PROBEREQ |
  370. AR5K_RX_FILTER_PROM;
  371. break;
  372. case NL80211_IFTYPE_AP:
  373. case NL80211_IFTYPE_ADHOC:
  374. rfilt |= AR5K_RX_FILTER_PROBEREQ |
  375. AR5K_RX_FILTER_BEACON;
  376. break;
  377. case NL80211_IFTYPE_STATION:
  378. if (ah->assoc)
  379. rfilt |= AR5K_RX_FILTER_BEACON;
  380. default:
  381. break;
  382. }
  383. iter_data.hw_macaddr = NULL;
  384. iter_data.n_stas = 0;
  385. iter_data.need_set_hw_addr = false;
  386. ieee80211_iterate_active_interfaces_atomic(
  387. ah->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  388. ath5k_vif_iter, &iter_data);
  389. /* Set up RX Filter */
  390. if (iter_data.n_stas > 1) {
  391. /* If you have multiple STA interfaces connected to
  392. * different APs, ARPs are not received (most of the time?)
  393. * Enabling PROMISC appears to fix that problem.
  394. */
  395. rfilt |= AR5K_RX_FILTER_PROM;
  396. }
  397. /* Set filters */
  398. ath5k_hw_set_rx_filter(ah, rfilt);
  399. /* Set multicast bits */
  400. ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
  401. /* Set the cached hw filter flags, this will later actually
  402. * be set in HW */
  403. ah->filter_flags = rfilt;
  404. mutex_unlock(&ah->lock);
  405. }
  406. static int
  407. ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  408. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  409. struct ieee80211_key_conf *key)
  410. {
  411. struct ath5k_hw *ah = hw->priv;
  412. struct ath_common *common = ath5k_hw_common(ah);
  413. int ret = 0;
  414. if (ath5k_modparam_nohwcrypt)
  415. return -EOPNOTSUPP;
  416. if (key->flags & IEEE80211_KEY_FLAG_RX_MGMT)
  417. return -EOPNOTSUPP;
  418. if (vif->type == NL80211_IFTYPE_ADHOC &&
  419. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  420. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  421. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  422. /* don't program group keys when using IBSS_RSN */
  423. return -EOPNOTSUPP;
  424. }
  425. switch (key->cipher) {
  426. case WLAN_CIPHER_SUITE_WEP40:
  427. case WLAN_CIPHER_SUITE_WEP104:
  428. case WLAN_CIPHER_SUITE_TKIP:
  429. break;
  430. case WLAN_CIPHER_SUITE_CCMP:
  431. if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
  432. break;
  433. return -EOPNOTSUPP;
  434. default:
  435. WARN_ON(1);
  436. return -EINVAL;
  437. }
  438. mutex_lock(&ah->lock);
  439. switch (cmd) {
  440. case SET_KEY:
  441. ret = ath_key_config(common, vif, sta, key);
  442. if (ret >= 0) {
  443. key->hw_key_idx = ret;
  444. /* push IV and Michael MIC generation to stack */
  445. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  446. if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
  447. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  448. if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
  449. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  450. ret = 0;
  451. }
  452. break;
  453. case DISABLE_KEY:
  454. ath_key_delete(common, key);
  455. break;
  456. default:
  457. ret = -EINVAL;
  458. }
  459. mmiowb();
  460. mutex_unlock(&ah->lock);
  461. return ret;
  462. }
  463. static void
  464. ath5k_sw_scan_start(struct ieee80211_hw *hw)
  465. {
  466. struct ath5k_hw *ah = hw->priv;
  467. if (!ah->assoc)
  468. ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN);
  469. }
  470. static void
  471. ath5k_sw_scan_complete(struct ieee80211_hw *hw)
  472. {
  473. struct ath5k_hw *ah = hw->priv;
  474. ath5k_hw_set_ledstate(ah, ah->assoc ?
  475. AR5K_LED_ASSOC : AR5K_LED_INIT);
  476. }
  477. static int
  478. ath5k_get_stats(struct ieee80211_hw *hw,
  479. struct ieee80211_low_level_stats *stats)
  480. {
  481. struct ath5k_hw *ah = hw->priv;
  482. /* Force update */
  483. ath5k_hw_update_mib_counters(ah);
  484. stats->dot11ACKFailureCount = ah->stats.ack_fail;
  485. stats->dot11RTSFailureCount = ah->stats.rts_fail;
  486. stats->dot11RTSSuccessCount = ah->stats.rts_ok;
  487. stats->dot11FCSErrorCount = ah->stats.fcs_error;
  488. return 0;
  489. }
  490. static int
  491. ath5k_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
  492. const struct ieee80211_tx_queue_params *params)
  493. {
  494. struct ath5k_hw *ah = hw->priv;
  495. struct ath5k_txq_info qi;
  496. int ret = 0;
  497. if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
  498. return 0;
  499. mutex_lock(&ah->lock);
  500. ath5k_hw_get_tx_queueprops(ah, queue, &qi);
  501. qi.tqi_aifs = params->aifs;
  502. qi.tqi_cw_min = params->cw_min;
  503. qi.tqi_cw_max = params->cw_max;
  504. qi.tqi_burst_time = params->txop * 32;
  505. ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
  506. "Configure tx [queue %d], "
  507. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  508. queue, params->aifs, params->cw_min,
  509. params->cw_max, params->txop);
  510. if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
  511. ATH5K_ERR(ah,
  512. "Unable to update hardware queue %u!\n", queue);
  513. ret = -EIO;
  514. } else
  515. ath5k_hw_reset_tx_queue(ah, queue);
  516. mutex_unlock(&ah->lock);
  517. return ret;
  518. }
  519. static u64
  520. ath5k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  521. {
  522. struct ath5k_hw *ah = hw->priv;
  523. return ath5k_hw_get_tsf64(ah);
  524. }
  525. static void
  526. ath5k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf)
  527. {
  528. struct ath5k_hw *ah = hw->priv;
  529. ath5k_hw_set_tsf64(ah, tsf);
  530. }
  531. static void
  532. ath5k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  533. {
  534. struct ath5k_hw *ah = hw->priv;
  535. /*
  536. * in IBSS mode we need to update the beacon timers too.
  537. * this will also reset the TSF if we call it with 0
  538. */
  539. if (ah->opmode == NL80211_IFTYPE_ADHOC)
  540. ath5k_beacon_update_timers(ah, 0);
  541. else
  542. ath5k_hw_reset_tsf(ah);
  543. }
  544. static int
  545. ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
  546. {
  547. struct ath5k_hw *ah = hw->priv;
  548. struct ieee80211_conf *conf = &hw->conf;
  549. struct ath_common *common = ath5k_hw_common(ah);
  550. struct ath_cycle_counters *cc = &common->cc_survey;
  551. unsigned int div = common->clockrate * 1000;
  552. if (idx != 0)
  553. return -ENOENT;
  554. spin_lock_bh(&common->cc_lock);
  555. ath_hw_cycle_counters_update(common);
  556. if (cc->cycles > 0) {
  557. ah->survey.channel_time += cc->cycles / div;
  558. ah->survey.channel_time_busy += cc->rx_busy / div;
  559. ah->survey.channel_time_rx += cc->rx_frame / div;
  560. ah->survey.channel_time_tx += cc->tx_frame / div;
  561. }
  562. memset(cc, 0, sizeof(*cc));
  563. spin_unlock_bh(&common->cc_lock);
  564. memcpy(survey, &ah->survey, sizeof(*survey));
  565. survey->channel = conf->channel;
  566. survey->noise = ah->ah_noise_floor;
  567. survey->filled = SURVEY_INFO_NOISE_DBM |
  568. SURVEY_INFO_CHANNEL_TIME |
  569. SURVEY_INFO_CHANNEL_TIME_BUSY |
  570. SURVEY_INFO_CHANNEL_TIME_RX |
  571. SURVEY_INFO_CHANNEL_TIME_TX;
  572. return 0;
  573. }
  574. /**
  575. * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
  576. *
  577. * @hw: struct ieee80211_hw pointer
  578. * @coverage_class: IEEE 802.11 coverage class number
  579. *
  580. * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
  581. * coverage class. The values are persistent, they are restored after device
  582. * reset.
  583. */
  584. static void
  585. ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  586. {
  587. struct ath5k_hw *ah = hw->priv;
  588. mutex_lock(&ah->lock);
  589. ath5k_hw_set_coverage_class(ah, coverage_class);
  590. mutex_unlock(&ah->lock);
  591. }
  592. static int
  593. ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  594. {
  595. struct ath5k_hw *ah = hw->priv;
  596. if (tx_ant == 1 && rx_ant == 1)
  597. ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
  598. else if (tx_ant == 2 && rx_ant == 2)
  599. ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
  600. else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
  601. ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
  602. else
  603. return -EINVAL;
  604. return 0;
  605. }
  606. static int
  607. ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  608. {
  609. struct ath5k_hw *ah = hw->priv;
  610. switch (ah->ah_ant_mode) {
  611. case AR5K_ANTMODE_FIXED_A:
  612. *tx_ant = 1; *rx_ant = 1; break;
  613. case AR5K_ANTMODE_FIXED_B:
  614. *tx_ant = 2; *rx_ant = 2; break;
  615. case AR5K_ANTMODE_DEFAULT:
  616. *tx_ant = 3; *rx_ant = 3; break;
  617. }
  618. return 0;
  619. }
  620. static void ath5k_get_ringparam(struct ieee80211_hw *hw,
  621. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  622. {
  623. struct ath5k_hw *ah = hw->priv;
  624. *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
  625. *tx_max = ATH5K_TXQ_LEN_MAX;
  626. *rx = *rx_max = ATH_RXBUF;
  627. }
  628. static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
  629. {
  630. struct ath5k_hw *ah = hw->priv;
  631. u16 qnum;
  632. /* only support setting tx ring size for now */
  633. if (rx != ATH_RXBUF)
  634. return -EINVAL;
  635. /* restrict tx ring size min/max */
  636. if (!tx || tx > ATH5K_TXQ_LEN_MAX)
  637. return -EINVAL;
  638. for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) {
  639. if (!ah->txqs[qnum].setup)
  640. continue;
  641. if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
  642. ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
  643. continue;
  644. ah->txqs[qnum].txq_max = tx;
  645. if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max)
  646. ieee80211_stop_queue(hw, ah->txqs[qnum].qnum);
  647. }
  648. return 0;
  649. }
  650. const struct ieee80211_ops ath5k_hw_ops = {
  651. .tx = ath5k_tx,
  652. .start = ath5k_start,
  653. .stop = ath5k_stop,
  654. .add_interface = ath5k_add_interface,
  655. /* .change_interface = not implemented */
  656. .remove_interface = ath5k_remove_interface,
  657. .config = ath5k_config,
  658. .bss_info_changed = ath5k_bss_info_changed,
  659. .prepare_multicast = ath5k_prepare_multicast,
  660. .configure_filter = ath5k_configure_filter,
  661. /* .set_tim = not implemented */
  662. .set_key = ath5k_set_key,
  663. /* .update_tkip_key = not implemented */
  664. /* .hw_scan = not implemented */
  665. .sw_scan_start = ath5k_sw_scan_start,
  666. .sw_scan_complete = ath5k_sw_scan_complete,
  667. .get_stats = ath5k_get_stats,
  668. /* .get_tkip_seq = not implemented */
  669. /* .set_frag_threshold = not implemented */
  670. /* .set_rts_threshold = not implemented */
  671. /* .sta_add = not implemented */
  672. /* .sta_remove = not implemented */
  673. /* .sta_notify = not implemented */
  674. .conf_tx = ath5k_conf_tx,
  675. .get_tsf = ath5k_get_tsf,
  676. .set_tsf = ath5k_set_tsf,
  677. .reset_tsf = ath5k_reset_tsf,
  678. /* .tx_last_beacon = not implemented */
  679. /* .ampdu_action = not needed */
  680. .get_survey = ath5k_get_survey,
  681. .set_coverage_class = ath5k_set_coverage_class,
  682. /* .rfkill_poll = not implemented */
  683. /* .flush = not implemented */
  684. /* .channel_switch = not implemented */
  685. /* .napi_poll = not implemented */
  686. .set_antenna = ath5k_set_antenna,
  687. .get_antenna = ath5k_get_antenna,
  688. .set_ringparam = ath5k_set_ringparam,
  689. .get_ringparam = ath5k_get_ringparam,
  690. };