[PATCH v4] hostap: Support ht-cap over-rides.
greearb at candelatech.com
greearb
Thu Jan 5 10:53:03 PST 2012
From: Ben Greear <greearb at candelatech.com>
This allows ht-capabilities over-rides on kernels that
support these features.
MCS Rates can be disabled (ie, to force to slower
speeds when using /n). Rates cannot be forced
higher.
HT can be disabled, forcing an /a/b/g/n station to act like
an /a/b/g station.
HT40 can be disabled.
MAX-AMSDU can be disabled
AMPDU-Factor and AMPDU Density can be modified.
Please note that these are suggestions to the kernel. Only
mac80211 drivers will work at all. The AMPDU-Factor
can only be decreased and the AMPDU-Density can only
be increased currently.
Signed-hostap: Ben Greear <greearb at candelatech.com>
---
v4: I believe this addresses all concerns raised in the review
of v3. Rebased against yesterday's top-of-tree as well.
:100644 100644 66801fd... b7e0af7... M src/common/ieee802_11_defs.h
:100644 100644 d72c83b... 03917e3... M src/drivers/driver.h
:100644 100644 6af8cc9... c8a4323... M src/drivers/driver_nl80211.c
:100644 100644 f9261c2... a8028dd... M src/drivers/nl80211_copy.h
:100644 100644 0832f10... 151d879... M wpa_supplicant/Makefile
:100644 100644 0fd1f3e... 6858b28... M wpa_supplicant/config.c
:100644 100644 f9e5043... 4db78e3... M wpa_supplicant/config.h
:100644 100644 8a47c0b... fb3b8a7... M wpa_supplicant/config_ssid.h
:100644 100644 cff25d6... 89bb458... M wpa_supplicant/defconfig
:100644 100644 c5e47d1... 53ed03e... M wpa_supplicant/sme.c
:100644 100644 68b80b9... 6f2ee5d... M wpa_supplicant/wpa_supplicant.c
:100644 100644 3e3b23d... 139426e... M wpa_supplicant/wpa_supplicant_i.h
src/common/ieee802_11_defs.h | 1 +
src/drivers/driver.h | 13 +++
src/drivers/driver_nl80211.c | 18 ++++
src/drivers/nl80211_copy.h | 5 +
wpa_supplicant/Makefile | 4 +
wpa_supplicant/config.c | 18 ++++
wpa_supplicant/config.h | 5 +
wpa_supplicant/config_ssid.h | 49 ++++++++++
wpa_supplicant/defconfig | 3 +
wpa_supplicant/sme.c | 11 +++
wpa_supplicant/wpa_supplicant.c | 178 +++++++++++++++++++++++++++++++++++++
wpa_supplicant/wpa_supplicant_i.h | 4 +
12 files changed, 309 insertions(+), 0 deletions(-)
diff --git a/src/common/ieee802_11_defs.h b/src/common/ieee802_11_defs.h
index 66801fd..b7e0af7 100644
--- a/src/common/ieee802_11_defs.h
+++ b/src/common/ieee802_11_defs.h
@@ -519,6 +519,7 @@ struct ieee80211_mgmt {
} STRUCT_PACKED;
+#define IEEE80211_HT_MCS_MASK_LEN 10
struct ieee80211_ht_capabilities {
le16 ht_capabilities_info;
u8 a_mpdu_params;
diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index d72c83b..03917e3 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -516,6 +516,19 @@ struct wpa_driver_associate_params {
* STA mode: bits 0..3 UAPSD enabled for VO,VI,BK,BE
*/
int uapsd;
+
+ /**
+ * disable_ht - Disable HT (802.11n) for this connection.
+ */
+ int disable_ht;
+
+ /**
+ * HT Capabilities over-rides. Only bits set in the mask will be
+ * used, and not all values are used by the kernel anyway. Currently,
+ * MCS, MPDU and MSDU fields are used.
+ */
+ u8* htcaps; /* struct ieee80211_ht_capabilities* */
+ u8* htcaps_mask; /* struct ieee80211_ht_capabilities* */
};
enum hide_ssid {
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 6af8cc9..c8a4323 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -6618,6 +6618,15 @@ skip_auth_type:
NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt);
}
+ if (params->disable_ht)
+ NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT);
+
+ if (params->htcaps && params->htcaps_mask) {
+ int sz = sizeof(struct ieee80211_ht_capabilities);
+ NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps);
+ NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, params->htcaps_mask);
+ }
+
ret = nl80211_set_conn_keys(params, msg);
if (ret)
goto nla_put_failure;
@@ -6765,6 +6774,15 @@ static int wpa_driver_nl80211_associate(
params->prev_bssid);
}
+ if (params->disable_ht)
+ NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT);
+
+ if (params->htcaps && params->htcaps_mask) {
+ int sz = sizeof(struct ieee80211_ht_capabilities);
+ NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps);
+ NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, params->htcaps_mask);
+ }
+
if (params->p2p)
wpa_printf(MSG_DEBUG, " * P2P group");
diff --git a/src/drivers/nl80211_copy.h b/src/drivers/nl80211_copy.h
index f9261c2..a8028dd 100644
--- a/src/drivers/nl80211_copy.h
+++ b/src/drivers/nl80211_copy.h
@@ -1408,6 +1408,11 @@ enum nl80211_attrs {
NL80211_ATTR_PROBE_RESP,
+ NL80211_ATTR_DFS_REGION,
+
+ NL80211_ATTR_DISABLE_HT,
+ NL80211_ATTR_HT_CAPABILITY_MASK,
+
/* add attributes here, update the policy in nl80211.c */
__NL80211_ATTR_AFTER_LAST,
diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index 0832f10..151d879 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -111,6 +111,10 @@ ifdef CONFIG_EAPOL_TEST
CFLAGS += -Werror -DEAPOL_TEST
endif
+ifdef CONFIG_HT_OVERRIDES
+CFLAGS += -DCONFIG_HT_OVERRIDES
+endif
+
ifndef CONFIG_BACKEND
CONFIG_BACKEND=file
endif
diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
index 0fd1f3e..6858b28 100644
--- a/wpa_supplicant/config.c
+++ b/wpa_supplicant/config.c
@@ -1598,6 +1598,14 @@ static const struct parse_data ssid_fields[] = {
#ifdef CONFIG_P2P
{ FUNC(p2p_client_list) },
#endif /* CONFIG_P2P */
+#ifdef CONFIG_HT_OVERRIDES
+ { INT_RANGE(disable_ht, 0, 1) },
+ { INT_RANGE(disable_ht40, -1, 1) },
+ { INT_RANGE(disable_max_amsdu, -1, 1) },
+ { INT_RANGE(ampdu_factor, -1, 3) },
+ { INT_RANGE(ampdu_density, -1, 7) },
+ { STR(ht_mcs) },
+#endif
};
#undef OFFSET
@@ -1765,6 +1773,9 @@ void wpa_config_free_ssid(struct wpa_ssid *ssid)
os_free(ssid->freq_list);
os_free(ssid->bgscan);
os_free(ssid->p2p_client_list);
+#ifdef CONFIG_HT_OVERRIDES
+ os_free(ssid->ht_mcs);
+#endif
os_free(ssid);
}
@@ -1952,6 +1963,13 @@ void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
#endif /* IEEE8021X_EAPOL */
+#ifdef CONFIG_HT_OVERRIDES
+ ssid->disable_ht = DEFAULT_DISABLE_HT;
+ ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
+ ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
+ ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
+ ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
+#endif
}
diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h
index f9e5043..4db78e3 100644
--- a/wpa_supplicant/config.h
+++ b/wpa_supplicant/config.h
@@ -15,6 +15,11 @@
#ifndef CONFIG_H
#define CONFIG_H
+#define DEFAULT_DISABLE_HT 0
+#define DEFAULT_DISABLE_HT40 0
+#define DEFAULT_DISABLE_MAX_AMSDU -1 /* no change */
+#define DEFAULT_AMPDU_FACTOR -1 /* no change */
+#define DEFAULT_AMPDU_DENSITY -1 /* no change */
#define DEFAULT_EAPOL_VERSION 1
#ifdef CONFIG_NO_SCAN_PROCESSING
#define DEFAULT_AP_SCAN 2
diff --git a/wpa_supplicant/config_ssid.h b/wpa_supplicant/config_ssid.h
index 8a47c0b..fb3b8a7 100644
--- a/wpa_supplicant/config_ssid.h
+++ b/wpa_supplicant/config_ssid.h
@@ -422,6 +422,55 @@ struct wpa_ssid {
* WPS or similar so that they may be exported.
*/
int export_keys;
+
+
+#ifdef CONFIG_HT_OVERRIDES
+ /**
+ * disable_ht - Disable HT (802.11n) for this interface
+ *
+ * By default, use it if it is available, but this can be configured
+ * to 1 to have it disabled.
+ */
+ int disable_ht;
+
+ /**
+ * disable_ht40 - Disable HT-40 for this interface
+ *
+ * By default, use it if it is available, but this can be configured
+ * to 1 to have it disabled.
+ */
+ int disable_ht40;
+
+ /**
+ * disable_max_amsdu - Disable MAX AMSDU
+ *
+ * AMDSU will be 3839 bytes when disabled, or 7935
+ * when enabled (assuming it is otherwise supported)
+ * -1 (default) means do not apply any settings to the kernel.
+ */
+ int disable_max_amsdu;
+
+ /**
+ * ampdu_factor - Maximum A-MPDU Length Exponent
+ *
+ * Value: 0-3, see section 7.3.2.56.3 of the 802.11n-2009 spec.
+ */
+ int ampdu_factor;
+
+ /**
+ * ampdu_density - Minum A-MPDU Start Spacing
+ *
+ * Value: 0-7, see section 7.3.2.56.3 of the 802.11n-2009 spec.
+ */
+ int ampdu_density;
+
+ /**
+ * ht_mcs - Allowed HT-MCS rates, in ascii hex: ffff0000...
+ *
+ * By default (empty string): use whatever the OS has configured.
+ */
+ char *ht_mcs;
+#endif
};
#endif /* CONFIG_SSID_H */
diff --git a/wpa_supplicant/defconfig b/wpa_supplicant/defconfig
index cff25d6..89bb458 100644
--- a/wpa_supplicant/defconfig
+++ b/wpa_supplicant/defconfig
@@ -217,6 +217,9 @@ CONFIG_SMARTCARD=y
# Enable this if EAP-SIM or EAP-AKA is included
#CONFIG_PCSC=y
+# Support HT overrides (disable-ht40, mcs rates, etc)
+# CONFIG_HT_OVERRIDES=y
+
# Development testing
#CONFIG_EAPOL_TEST=y
diff --git a/wpa_supplicant/sme.c b/wpa_supplicant/sme.c
index c5e47d1..53ed03e 100644
--- a/wpa_supplicant/sme.c
+++ b/wpa_supplicant/sme.c
@@ -367,8 +367,18 @@ void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode,
{
struct wpa_driver_associate_params params;
struct ieee802_11_elems elems;
+#ifdef CONFIG_HT_OVERRIDES
+ struct ieee80211_ht_capabilities htcaps;
+ struct ieee80211_ht_capabilities htcaps_mask;
+ os_memset(&htcaps, 0, sizeof(htcaps));
+ os_memset(&htcaps_mask, 0, sizeof(htcaps_mask));
+#endif
os_memset(¶ms, 0, sizeof(params));
+#ifdef CONFIG_HT_OVERRIDES
+ params.htcaps = (u8*)(&htcaps);
+ params.htcaps_mask = (u8*)(&htcaps_mask);
+#endif
params.bssid = bssid;
params.ssid = wpa_s->sme.ssid;
params.ssid_len = wpa_s->sme.ssid_len;
@@ -378,6 +388,7 @@ void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode,
params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len;
params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
params.group_suite = cipher_suite2driver(wpa_s->group_cipher);
+ wpa_supplicant_apply_ht_overrides(wpa_s, ¶ms);
#ifdef CONFIG_IEEE80211R
if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies) {
params.wpa_ie = wpa_s->sme.ft_ies;
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 68b80b9..6f2ee5d 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -1122,6 +1122,13 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
int assoc_failed = 0;
struct wpa_ssid *old_ssid;
+#ifdef CONFIG_HT_OVERRIDES
+ struct ieee80211_ht_capabilities htcaps;
+ struct ieee80211_ht_capabilities htcaps_mask;
+ os_memset(&htcaps, 0, sizeof(htcaps));
+ os_memset(&htcaps_mask, 0, sizeof(htcaps_mask));
+#endif
+
#ifdef CONFIG_IBSS_RSN
ibss_rsn_deinit(wpa_s->ibss_rsn);
wpa_s->ibss_rsn = NULL;
@@ -1157,6 +1164,10 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
}
os_memset(¶ms, 0, sizeof(params));
+#ifdef CONFIG_HT_OVERRIDES
+ params.htcaps = (u8*)(&htcaps);
+ params.htcaps_mask = (u8*)(&htcaps_mask);
+#endif
wpa_s->reassociate = 0;
if (bss && !wpas_driver_bss_selection(wpa_s)) {
#ifdef CONFIG_IEEE80211R
@@ -1415,6 +1426,8 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
else
params.uapsd = -1;
+ wpa_supplicant_apply_ht_overrides(wpa_s, ¶ms);
+
ret = wpa_drv_associate(wpa_s, ¶ms);
if (ret < 0) {
wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
@@ -2166,6 +2179,171 @@ static struct wpa_supplicant * wpa_supplicant_alloc(void)
return wpa_s;
}
+#ifdef CONFIG_HT_OVERRIDES
+static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s,
+ struct ieee80211_ht_capabilities *htcaps,
+ struct ieee80211_ht_capabilities *htcaps_mask,
+ const char *ht_mcs)
+{
+ /* parse ht_mcs into hex array */
+ int i;
+ const char* tmp = ht_mcs;
+ char* end = NULL;
+
+ /* If ht_mcs is null, do not set anything */
+ if (!ht_mcs)
+ return 0;
+
+ /* This is what we are setting in the kernel.. */
+ os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN);
+
+ wpa_msg(wpa_s, MSG_ERROR, "set_htcap, ht_mcs -:%s:-\n", ht_mcs);
+
+ for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
+ errno = 0;
+ long v = strtol(tmp, &end, 16);
+ if (errno == 0) {
+ wpa_msg(wpa_s, MSG_ERROR, "htcap value[%i]: %ld end: %p tmp: %p\n",
+ i, v, end, tmp);
+ if (end == tmp) {
+ break;
+ }
+
+ htcaps->supported_mcs_set[i] = v;
+ tmp = end;
+ }
+ else {
+ wpa_msg(wpa_s, MSG_ERROR,
+ "Failed to parse ht-mcs: %s, error: %s\n",
+ ht_mcs, strerror(errno));
+ return -1;
+ }
+ }
+
+ /* If we were able to parse any values, then set mask for the MCS set. */
+ if (i) {
+ os_memset(&htcaps_mask->supported_mcs_set, 0xff, IEEE80211_HT_MCS_MASK_LEN-1);
+ /* skip the 3 reserved bits */
+ htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN-1] = 0x1f;
+ }
+
+ return 0;
+}
+
+
+static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s,
+ struct ieee80211_ht_capabilities *htcaps,
+ struct ieee80211_ht_capabilities *htcaps_mask,
+ int disabled)
+{
+ wpa_msg(wpa_s, MSG_DEBUG, "wpa: set_disable_max_amsdu: %d\n",
+ disabled);
+
+ if (disabled == -1)
+ return 0;
+
+ u16 msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE);
+ htcaps_mask->ht_capabilities_info |= msk;
+ if (disabled)
+ htcaps->ht_capabilities_info &= msk;
+ else
+ htcaps->ht_capabilities_info |= msk;
+ return 0;
+}
+
+static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s,
+ struct ieee80211_ht_capabilities *htcaps,
+ struct ieee80211_ht_capabilities *htcaps_mask,
+ int factor)
+{
+ wpa_msg(wpa_s, MSG_DEBUG, "wpa: set_ampdu_factor: %d\n",
+ factor);
+
+ if (factor == -1)
+ return 0;
+
+ if (factor < 0 || factor > 3) {
+ wpa_msg(wpa_s, MSG_ERROR,
+ "wpa: ampdu_factor: %d out of range. Must be 0-3 or -1\n",
+ factor);
+ return -EINVAL;
+ }
+
+ htcaps_mask->a_mpdu_params |= 0x3; // 2 bits for factor
+ htcaps->a_mpdu_params &= ~0x3;
+ htcaps->a_mpdu_params |= factor & 0x3;
+ return 0;
+}
+
+static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s,
+ struct ieee80211_ht_capabilities *htcaps,
+ struct ieee80211_ht_capabilities *htcaps_mask,
+ int density)
+{
+ wpa_msg(wpa_s, MSG_DEBUG, "wpa: set_ampdu_density: %d\n",
+ density);
+
+ if (density == -1)
+ return 0;
+
+ if (density < 0 || density > 7) {
+ wpa_msg(wpa_s, MSG_ERROR,
+ "wpa: ampdu_density: %d out of range. Must be 0-7 or -1.\n",
+ density);
+ return -EINVAL;
+ }
+
+ htcaps_mask->a_mpdu_params |= 0x1C;
+ htcaps->a_mpdu_params &= ~(0x1C);
+ htcaps->a_mpdu_params |= (density << 2) & 0x1C;
+ return 0;
+}
+
+static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s,
+ struct ieee80211_ht_capabilities *htcaps,
+ struct ieee80211_ht_capabilities *htcaps_mask,
+ int disabled)
+{
+ /* Masking these out disables HT-40 */
+ u16 msk = host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET |
+ HT_CAP_INFO_SHORT_GI40MHZ);
+
+ wpa_msg(wpa_s, MSG_DEBUG, "wpa: set_disable_ht40: %d\n",
+ disabled);
+
+ if (disabled)
+ htcaps->ht_capabilities_info &= ~msk;
+ else
+ htcaps->ht_capabilities_info |= msk;
+
+ htcaps_mask->ht_capabilities_info |= msk;
+ return 0;
+}
+#endif
+
+
+void wpa_supplicant_apply_ht_overrides(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_associate_params *params)
+{
+#ifdef CONFIG_HT_OVERRIDES
+ struct wpa_ssid *ssid = wpa_s->current_ssid;
+ if (ssid) {
+ params->disable_ht = ssid->disable_ht;
+ if (params->htcaps && params->htcaps_mask) {
+ struct ieee80211_ht_capabilities* htcaps;
+ struct ieee80211_ht_capabilities* htcaps_mask;
+ htcaps = (struct ieee80211_ht_capabilities*)(params->htcaps);
+ htcaps_mask = (struct ieee80211_ht_capabilities*)(params->htcaps_mask);
+
+ wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs);
+ wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask, ssid->disable_max_amsdu);
+ wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor);
+ wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density);
+ wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40);
+ }
+ }
+#endif
+}
static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
struct wpa_interface *iface)
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 3e3b23d..139426e 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -36,6 +36,7 @@ struct scan_info;
struct wpa_bss;
struct wpa_scan_results;
struct hostapd_hw_modes;
+struct wpa_driver_associate_params;
/*
* Forward declarations of private structures used within the ctrl_iface
@@ -525,6 +526,9 @@ struct wpa_supplicant {
/* wpa_supplicant.c */
+void wpa_supplicant_apply_ht_overrides(struct wpa_supplicant *wpa_s,
+ struct wpa_driver_associate_params *params);
+
int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid);
int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
--
1.7.3.4
More information about the Hostap
mailing list