ieee802_11_ht.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * hostapd / IEEE 802.11n HT
  3. * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2007-2008, Intel Corporation
  5. *
  6. * This software may be distributed under the terms of the BSD license.
  7. * See README for more details.
  8. */
  9. #include "utils/includes.h"
  10. #include "utils/common.h"
  11. #include "common/ieee802_11_defs.h"
  12. #include "hostapd.h"
  13. #include "ap_config.h"
  14. #include "sta_info.h"
  15. #include "beacon.h"
  16. #include "ieee802_11.h"
  17. u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
  18. {
  19. struct ieee80211_ht_capabilities *cap;
  20. u8 *pos = eid;
  21. if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
  22. hapd->conf->disable_11n)
  23. return eid;
  24. *pos++ = WLAN_EID_HT_CAP;
  25. *pos++ = sizeof(*cap);
  26. cap = (struct ieee80211_ht_capabilities *) pos;
  27. os_memset(cap, 0, sizeof(*cap));
  28. cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
  29. cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
  30. os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
  31. 16);
  32. /* TODO: ht_extended_capabilities (now fully disabled) */
  33. /* TODO: tx_bf_capability_info (now fully disabled) */
  34. /* TODO: asel_capabilities (now fully disabled) */
  35. pos += sizeof(*cap);
  36. if (hapd->iconf->obss_interval) {
  37. struct ieee80211_obss_scan_parameters *scan_params;
  38. *pos++ = WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS;
  39. *pos++ = sizeof(*scan_params);
  40. scan_params = (struct ieee80211_obss_scan_parameters *) pos;
  41. os_memset(scan_params, 0, sizeof(*scan_params));
  42. scan_params->width_trigger_scan_interval =
  43. host_to_le16(hapd->iconf->obss_interval);
  44. /* Fill in default values for remaining parameters
  45. * (IEEE Std 802.11-2012, 8.4.2.61 and MIB defval) */
  46. scan_params->scan_passive_dwell =
  47. host_to_le16(20);
  48. scan_params->scan_active_dwell =
  49. host_to_le16(10);
  50. scan_params->scan_passive_total_per_channel =
  51. host_to_le16(200);
  52. scan_params->scan_active_total_per_channel =
  53. host_to_le16(20);
  54. scan_params->channel_transition_delay_factor =
  55. host_to_le16(5);
  56. scan_params->scan_activity_threshold =
  57. host_to_le16(25);
  58. pos += sizeof(*scan_params);
  59. }
  60. return pos;
  61. }
  62. u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
  63. {
  64. struct ieee80211_ht_operation *oper;
  65. u8 *pos = eid;
  66. if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
  67. return eid;
  68. *pos++ = WLAN_EID_HT_OPERATION;
  69. *pos++ = sizeof(*oper);
  70. oper = (struct ieee80211_ht_operation *) pos;
  71. os_memset(oper, 0, sizeof(*oper));
  72. oper->control_chan = hapd->iconf->channel;
  73. oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
  74. if (hapd->iconf->secondary_channel == 1)
  75. oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
  76. HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
  77. if (hapd->iconf->secondary_channel == -1)
  78. oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
  79. HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
  80. pos += sizeof(*oper);
  81. return pos;
  82. }
  83. /*
  84. op_mode
  85. Set to 0 (HT pure) under the followign conditions
  86. - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
  87. - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
  88. Set to 1 (HT non-member protection) if there may be non-HT STAs
  89. in both the primary and the secondary channel
  90. Set to 2 if only HT STAs are associated in BSS,
  91. however and at least one 20 MHz HT STA is associated
  92. Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
  93. */
  94. int hostapd_ht_operation_update(struct hostapd_iface *iface)
  95. {
  96. u16 cur_op_mode, new_op_mode;
  97. int op_mode_changes = 0;
  98. if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
  99. return 0;
  100. wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
  101. __func__, iface->ht_op_mode);
  102. if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
  103. && iface->num_sta_ht_no_gf) {
  104. iface->ht_op_mode |=
  105. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  106. op_mode_changes++;
  107. } else if ((iface->ht_op_mode &
  108. HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
  109. iface->num_sta_ht_no_gf == 0) {
  110. iface->ht_op_mode &=
  111. ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
  112. op_mode_changes++;
  113. }
  114. if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  115. (iface->num_sta_no_ht || iface->olbc_ht)) {
  116. iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  117. op_mode_changes++;
  118. } else if ((iface->ht_op_mode &
  119. HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
  120. (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
  121. iface->ht_op_mode &=
  122. ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
  123. op_mode_changes++;
  124. }
  125. if (iface->num_sta_no_ht)
  126. new_op_mode = OP_MODE_MIXED;
  127. else if (iface->conf->secondary_channel && iface->num_sta_ht_20mhz)
  128. new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
  129. else if (iface->olbc_ht)
  130. new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
  131. else
  132. new_op_mode = OP_MODE_PURE;
  133. cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  134. if (cur_op_mode != new_op_mode) {
  135. iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
  136. iface->ht_op_mode |= new_op_mode;
  137. op_mode_changes++;
  138. }
  139. wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
  140. __func__, iface->ht_op_mode, op_mode_changes);
  141. return op_mode_changes;
  142. }
  143. u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
  144. const u8 *ht_capab, size_t ht_capab_len)
  145. {
  146. /* Disable HT caps for STAs associated to no-HT BSSes. */
  147. if (!ht_capab ||
  148. ht_capab_len < sizeof(struct ieee80211_ht_capabilities) ||
  149. hapd->conf->disable_11n) {
  150. sta->flags &= ~WLAN_STA_HT;
  151. os_free(sta->ht_capabilities);
  152. sta->ht_capabilities = NULL;
  153. return WLAN_STATUS_SUCCESS;
  154. }
  155. if (sta->ht_capabilities == NULL) {
  156. sta->ht_capabilities =
  157. os_zalloc(sizeof(struct ieee80211_ht_capabilities));
  158. if (sta->ht_capabilities == NULL)
  159. return WLAN_STATUS_UNSPECIFIED_FAILURE;
  160. }
  161. sta->flags |= WLAN_STA_HT;
  162. os_memcpy(sta->ht_capabilities, ht_capab,
  163. sizeof(struct ieee80211_ht_capabilities));
  164. return WLAN_STATUS_SUCCESS;
  165. }
  166. static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
  167. {
  168. u16 ht_capab;
  169. ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
  170. wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
  171. "0x%04x", MAC2STR(sta->addr), ht_capab);
  172. if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
  173. if (!sta->no_ht_gf_set) {
  174. sta->no_ht_gf_set = 1;
  175. hapd->iface->num_sta_ht_no_gf++;
  176. }
  177. wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
  178. "of non-gf stations %d",
  179. __func__, MAC2STR(sta->addr),
  180. hapd->iface->num_sta_ht_no_gf);
  181. }
  182. if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
  183. if (!sta->ht_20mhz_set) {
  184. sta->ht_20mhz_set = 1;
  185. hapd->iface->num_sta_ht_20mhz++;
  186. }
  187. wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
  188. "20MHz HT STAs %d",
  189. __func__, MAC2STR(sta->addr),
  190. hapd->iface->num_sta_ht_20mhz);
  191. }
  192. }
  193. static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
  194. {
  195. if (!sta->no_ht_set) {
  196. sta->no_ht_set = 1;
  197. hapd->iface->num_sta_no_ht++;
  198. }
  199. if (hapd->iconf->ieee80211n) {
  200. wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
  201. "non-HT stations %d",
  202. __func__, MAC2STR(sta->addr),
  203. hapd->iface->num_sta_no_ht);
  204. }
  205. }
  206. void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
  207. {
  208. if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
  209. update_sta_ht(hapd, sta);
  210. else
  211. update_sta_no_ht(hapd, sta);
  212. if (hostapd_ht_operation_update(hapd->iface) > 0)
  213. ieee802_11_set_beacons(hapd->iface);
  214. }
  215. void hostapd_get_ht_capab(struct hostapd_data *hapd,
  216. struct ieee80211_ht_capabilities *ht_cap,
  217. struct ieee80211_ht_capabilities *neg_ht_cap)
  218. {
  219. u16 cap;
  220. if (ht_cap == NULL)
  221. return;
  222. os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
  223. cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
  224. /*
  225. * Mask out HT features we don't support, but don't overwrite
  226. * non-symmetric features like STBC and SMPS. Just because
  227. * we're not in dynamic SMPS mode the STA might still be.
  228. */
  229. cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
  230. HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
  231. /*
  232. * STBC needs to be handled specially
  233. * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
  234. * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
  235. */
  236. if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
  237. cap &= ~HT_CAP_INFO_TX_STBC;
  238. if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
  239. cap &= ~HT_CAP_INFO_RX_STBC_MASK;
  240. neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
  241. }