ht.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * HT handling
  3. *
  4. * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
  5. * Copyright 2002-2005, Instant802 Networks, Inc.
  6. * Copyright 2005-2006, Devicescape Software, Inc.
  7. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  8. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  9. * Copyright 2007-2008, Intel Corporation
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/ieee80211.h>
  16. #include <net/wireless.h>
  17. #include <net/mac80211.h>
  18. #include "ieee80211_i.h"
  19. void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
  20. struct ieee80211_ht_cap *ht_cap_ie,
  21. struct ieee80211_sta_ht_cap *ht_cap)
  22. {
  23. u8 ampdu_info, tx_mcs_set_cap;
  24. int i, max_tx_streams;
  25. BUG_ON(!ht_cap);
  26. memset(ht_cap, 0, sizeof(*ht_cap));
  27. if (!ht_cap_ie)
  28. return;
  29. ht_cap->ht_supported = true;
  30. ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info) & sband->ht_cap.cap;
  31. ht_cap->cap &= ~IEEE80211_HT_CAP_SM_PS;
  32. ht_cap->cap |= sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS;
  33. ampdu_info = ht_cap_ie->ampdu_params_info;
  34. ht_cap->ampdu_factor =
  35. ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
  36. ht_cap->ampdu_density =
  37. (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
  38. /* own MCS TX capabilities */
  39. tx_mcs_set_cap = sband->ht_cap.mcs.tx_params;
  40. /* can we TX with MCS rates? */
  41. if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
  42. return;
  43. /* Counting from 0, therefore +1 */
  44. if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
  45. max_tx_streams =
  46. ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  47. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
  48. else
  49. max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
  50. /*
  51. * 802.11n D5.0 20.3.5 / 20.6 says:
  52. * - indices 0 to 7 and 32 are single spatial stream
  53. * - 8 to 31 are multiple spatial streams using equal modulation
  54. * [8..15 for two streams, 16..23 for three and 24..31 for four]
  55. * - remainder are multiple spatial streams using unequal modulation
  56. */
  57. for (i = 0; i < max_tx_streams; i++)
  58. ht_cap->mcs.rx_mask[i] =
  59. sband->ht_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
  60. if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
  61. for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
  62. i < IEEE80211_HT_MCS_MASK_LEN; i++)
  63. ht_cap->mcs.rx_mask[i] =
  64. sband->ht_cap.mcs.rx_mask[i] &
  65. ht_cap_ie->mcs.rx_mask[i];
  66. /* handle MCS rate 32 too */
  67. if (sband->ht_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
  68. ht_cap->mcs.rx_mask[32/8] |= 1;
  69. }
  70. /*
  71. * ieee80211_enable_ht should be called only after the operating band
  72. * has been determined as ht configuration depends on the hw's
  73. * HT abilities for a specific band.
  74. */
  75. u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
  76. struct ieee80211_ht_info *hti,
  77. u16 ap_ht_cap_flags)
  78. {
  79. struct ieee80211_local *local = sdata->local;
  80. struct ieee80211_supported_band *sband;
  81. struct ieee80211_bss_ht_conf ht;
  82. u32 changed = 0;
  83. bool enable_ht = true, ht_changed;
  84. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  85. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  86. memset(&ht, 0, sizeof(ht));
  87. /* HT is not supported */
  88. if (!sband->ht_cap.ht_supported)
  89. enable_ht = false;
  90. /* check that channel matches the right operating channel */
  91. if (local->hw.conf.channel->center_freq !=
  92. ieee80211_channel_to_frequency(hti->control_chan))
  93. enable_ht = false;
  94. if (enable_ht) {
  95. channel_type = NL80211_CHAN_HT20;
  96. if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
  97. (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
  98. (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
  99. switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  100. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  101. channel_type = NL80211_CHAN_HT40PLUS;
  102. break;
  103. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  104. channel_type = NL80211_CHAN_HT40MINUS;
  105. break;
  106. }
  107. }
  108. }
  109. ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
  110. channel_type != local->hw.conf.channel_type;
  111. local->oper_channel_type = channel_type;
  112. if (ht_changed) {
  113. /* channel_type change automatically detected */
  114. ieee80211_hw_config(local, 0);
  115. }
  116. /* disable HT */
  117. if (!enable_ht)
  118. return 0;
  119. ht.operation_mode = le16_to_cpu(hti->operation_mode);
  120. /* if bss configuration changed store the new one */
  121. if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
  122. changed |= BSS_CHANGED_HT;
  123. sdata->vif.bss_conf.ht = ht;
  124. }
  125. return changed;
  126. }
  127. void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta)
  128. {
  129. int i;
  130. for (i = 0; i < STA_TID_NUM; i++) {
  131. __ieee80211_stop_tx_ba_session(sta, i, WLAN_BACK_INITIATOR);
  132. __ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT,
  133. WLAN_REASON_QSTA_LEAVE_QBSS);
  134. }
  135. }
  136. void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
  137. const u8 *da, u16 tid,
  138. u16 initiator, u16 reason_code)
  139. {
  140. struct ieee80211_local *local = sdata->local;
  141. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  142. struct sk_buff *skb;
  143. struct ieee80211_mgmt *mgmt;
  144. u16 params;
  145. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  146. if (!skb) {
  147. printk(KERN_ERR "%s: failed to allocate buffer "
  148. "for delba frame\n", sdata->dev->name);
  149. return;
  150. }
  151. skb_reserve(skb, local->hw.extra_tx_headroom);
  152. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  153. memset(mgmt, 0, 24);
  154. memcpy(mgmt->da, da, ETH_ALEN);
  155. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  156. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  157. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  158. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  159. else
  160. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  161. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  162. IEEE80211_STYPE_ACTION);
  163. skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
  164. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  165. mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  166. params = (u16)(initiator << 11); /* bit 11 initiator */
  167. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  168. mgmt->u.action.u.delba.params = cpu_to_le16(params);
  169. mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
  170. ieee80211_tx_skb(sdata, skb, 1);
  171. }
  172. void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
  173. struct sta_info *sta,
  174. struct ieee80211_mgmt *mgmt, size_t len)
  175. {
  176. struct ieee80211_local *local = sdata->local;
  177. u16 tid, params;
  178. u16 initiator;
  179. params = le16_to_cpu(mgmt->u.action.u.delba.params);
  180. tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
  181. initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
  182. #ifdef CONFIG_MAC80211_HT_DEBUG
  183. if (net_ratelimit())
  184. printk(KERN_DEBUG "delba from %pM (%s) tid %d reason code %d\n",
  185. mgmt->sa, initiator ? "initiator" : "recipient", tid,
  186. mgmt->u.action.u.delba.reason_code);
  187. #endif /* CONFIG_MAC80211_HT_DEBUG */
  188. if (initiator == WLAN_BACK_INITIATOR)
  189. ieee80211_sta_stop_rx_ba_session(sdata, sta->sta.addr, tid,
  190. WLAN_BACK_INITIATOR, 0);
  191. else { /* WLAN_BACK_RECIPIENT */
  192. spin_lock_bh(&sta->lock);
  193. sta->ampdu_mlme.tid_state_tx[tid] =
  194. HT_AGG_STATE_OPERATIONAL;
  195. spin_unlock_bh(&sta->lock);
  196. ieee80211_stop_tx_ba_session(&local->hw, sta->sta.addr, tid,
  197. WLAN_BACK_RECIPIENT);
  198. }
  199. }