ht.c 7.5 KB

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