[PATCH 1/2] hostapd: Add Power Constraint element

Marek Puzyniak marek.puzyniak
Fri Feb 7 13:19:13 PST 2014


From: Srinivasan B <srinivasanb at posedge.com>

Add Power Constraint information element to Beacon and Probe Response
frames when hostapd is configured on 5 GHz band and Country information
element is also added. According to spec IEEE802.11-2012 a STA shall
determine a local maximum transmit power for the current channel based
on information derived from Country and Power Constraint elements.

In order to add Power Constraint element ieee80211d option need to be
enabled and new local_pwr_constraint config option need to be set to
unsigned value in units of decibels. For now this value is statically
configured but the future goal is to implement dynamic TPC algorithm
to control local power constraint.

Signed-hostap: Srinivasan <srinivasanb at posedge.com>
Signed-hostap: Chaitanya T K <chaitanyatk at posedge.com>
Signed-hostap: Marek Puzyniak <marek.puzyniak at tieto.com>
---
 hostapd/config_file.c |  9 +++++++++
 hostapd/hostapd.conf  |  8 ++++++++
 src/ap/ap_config.c    |  9 +++++++++
 src/ap/ap_config.h    |  7 +++++++
 src/ap/beacon.c       | 34 ++++++++++++++++++++++++++++++++++
 5 files changed, 67 insertions(+)

diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index 54e4af9..4f989ac 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -2905,6 +2905,15 @@ static int hostapd_config_fill(struct hostapd_config *conf,
 					   "sae_groups value '%s'", line, pos);
 				return 1;
 			}
+		} else if (os_strcmp(buf, "local_pwr_contraint") == 0) {
+			int val = atoi(pos);
+			if (val < 0 || val > 255) {
+				wpa_printf(MSG_ERROR, "Line %d: invalid "
+					   "local_pwr_constraint %d (expected "
+					   "0..255)", line, val);
+				errors++;
+			} else
+				conf->local_pwr_constraint = val;
 		} else {
 			wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
 				   "item '%s'", line, buf);
diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
index da7817f..1357c03 100644
--- a/hostapd/hostapd.conf
+++ b/hostapd/hostapd.conf
@@ -108,6 +108,14 @@ ssid=test
 # (default: 0 = disabled)
 #ieee80211h=1
 
+# Add Power Constraint element for Beacon and Probe Response frames.
+# This config option adds power constraint information element when available
+# and set to corect value and country information element is added.
+# Power Constraint element is required by Transmit Power Control. This can be
+# used only with ieee80211d=1.
+# Valid values are 0..255.
+#local_pwr_constraint=3
+
 # Operation mode (a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE 802.11g,
 # ad = IEEE 802.11ad (60 GHz); a/g options are used with IEEE 802.11n, too, to
 # specify band)
diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
index 368b202..6c80e48 100644
--- a/src/ap/ap_config.c
+++ b/src/ap/ap_config.c
@@ -154,6 +154,8 @@ struct hostapd_config * hostapd_config_defaults(void)
 	conf->rts_threshold = -1; /* use driver default: 2347 */
 	conf->fragm_threshold = -1; /* user driver default: 2346 */
 	conf->send_probe_response = 1;
+	/* Set to invalid value means do not add Power Constraint IE */
+	conf->local_pwr_constraint = -1;
 
 	conf->wmm_ac_params[0] = ac_be;
 	conf->wmm_ac_params[1] = ac_bk;
@@ -829,6 +831,13 @@ int hostapd_config_check(struct hostapd_config *conf, int full_config)
 		return -1;
 	}
 
+	if (full_config && conf->local_pwr_constraint != -1 &&
+	    !conf->ieee80211d) {
+		wpa_printf(MSG_ERROR, "Cannot add Power Constraint element "
+			   "without Country element");
+		return -1;
+	}
+
 	for (i = 0; i < conf->num_bss; i++) {
 		if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
 			return -1;
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index b4860a0..8c3bddb 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -518,6 +518,13 @@ struct hostapd_config {
 
 	int ieee80211h; /* DFS */
 
+	/*
+	 * Local power constraint is octed coded as an unsigned
+	 * integer in units of decibels. Invalid value -1 indicates
+	 * that Power Constraint element should not be added.
+	 */
+	int local_pwr_constraint;
+
 	struct hostapd_tx_queue_params tx_queue[NUM_TX_QUEUES];
 
 	/*
diff --git a/src/ap/beacon.c b/src/ap/beacon.c
index b1ebf6e..fd7c547 100644
--- a/src/ap/beacon.c
+++ b/src/ap/beacon.c
@@ -102,6 +102,34 @@ static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
 }
 
 
+static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
+{
+	u8 *pos = eid;
+
+	if (hapd->iconf->local_pwr_constraint == -1 ||
+	    hapd->iface->current_mode == NULL ||
+	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
+		return eid;
+
+	/*
+	 * CRDA provides reduced TX power than actual regulatory max TX power.
+	 * Value of 0 to the local power constraint provides an opportunity
+	 * for the client devices to operate at the power limit provided by CRDA
+	 * (for client devices
+	 * "Local max TX pwr" = regulatory max TX pwr - Local pwr constraint)
+	 */
+
+	/* Element ID */
+	*pos++ = WLAN_EID_PWR_CONSTRAINT;
+	/* Length */
+	*pos++ = 1;
+	/* Local Power Constraint */
+	*pos++ = hapd->iconf->local_pwr_constraint;
+
+	return pos;
+}
+
+
 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
 				    struct hostapd_channel_data *start,
 				    struct hostapd_channel_data *prev)
@@ -315,6 +343,9 @@ static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
 
 	pos = hostapd_eid_country(hapd, pos, epos - pos);
 
+	/* Power Constraint element */
+	pos = hostapd_eid_pwr_constraint(hapd, pos);
+
 	/* ERP Information element */
 	pos = hostapd_eid_erp_info(hapd, pos);
 
@@ -721,6 +752,9 @@ int ieee802_11_build_ap_params(struct hostapd_data *hapd,
 	tailpos = hostapd_eid_country(hapd, tailpos,
 				      tail + BEACON_TAIL_BUF_SIZE - tailpos);
 
+	/* Power Constraint element */
+	tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
+
 	/* ERP Information element */
 	tailpos = hostapd_eid_erp_info(hapd, tailpos);
 
-- 
1.8.1.2




More information about the Hostap mailing list