[PATCH 11/13] WMM AC: add wmm ac status command

Ilan Peer ilan.peer
Tue Oct 21 05:16:50 PDT 2014


From: Moshe Benji <Moshe.Benji at intel.com>

This wmm_ac_status command will show the current status
for WMM AC.

Signed-off-by: Moshe Benji <moshe.benji at intel.com>
Signed-off-by: Eliad Peller <eliad at wizery.com>
---
 src/utils/common.c          | 30 ++++++++++++++++
 src/utils/common.h          |  1 +
 wpa_supplicant/ctrl_iface.c |  2 ++
 wpa_supplicant/wmm_ac.c     | 87 +++++++++++++++++++++++++++++++++++++++++++++
 wpa_supplicant/wmm_ac.h     |  1 +
 wpa_supplicant/wpa_cli.c    | 10 ++++++
 6 files changed, 131 insertions(+)

diff --git a/src/utils/common.c b/src/utils/common.c
index e19bd3e..eca1b67 100644
--- a/src/utils/common.c
+++ b/src/utils/common.c
@@ -183,6 +183,36 @@ void wpa_get_ntp_timestamp(u8 *buf)
 	os_memcpy(buf + 4, (u8 *) &tmp, 4);
 }
 
+/**
+ * wpa_scnprintf - simpler-to-use snprintf function
+ * @buf: output buffer
+ * @size: buffer size
+ * @fmt: format
+ *
+ * Simpler snprintf version that doesn't require further
+ * error checks - the return value only indicates how many
+ * bytes were actually written, excluding the NULL byte
+ * (i.e. 0 on error, size-1 if buffer is not big enough).
+ */
+inline int wpa_scnprintf(char *buf, size_t size, const char *fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	if (!size)
+		return 0;
+
+	va_start(ap, fmt);
+	ret = vsnprintf(buf, size, fmt, ap);
+	va_end(ap);
+
+	if (ret < 0)
+		return 0;
+	if ((size_t)ret >= size)
+		return size - 1;
+
+	return ret;
+}
 
 static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data,
 				    size_t len, int uppercase)
diff --git a/src/utils/common.h b/src/utils/common.h
index b245244..bcff32c 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -474,6 +474,7 @@ int hex2byte(const char *hex);
 int hexstr2bin(const char *hex, u8 *buf, size_t len);
 void inc_byte_array(u8 *counter, size_t len);
 void wpa_get_ntp_timestamp(u8 *buf);
+int wpa_scnprintf(char *buf, size_t size, const char *fmt, ...);
 int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len);
 int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data,
 			       size_t len);
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 721143c..de6789e 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -7216,6 +7216,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 		if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
 			reply_len = -1;
 #endif /* CONFIG_TDLS */
+	} else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
+		reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
 	} else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
 		if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
 			reply_len = -1;
diff --git a/wpa_supplicant/wmm_ac.c b/wpa_supplicant/wmm_ac.c
index ed8627d..c499598 100644
--- a/wpa_supplicant/wmm_ac.c
+++ b/wpa_supplicant/wmm_ac.c
@@ -799,3 +799,90 @@ void wmm_ac_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
 		break;
 	}
 }
+
+static const char *get_ac_str(u8 ac)
+{
+	switch (ac) {
+	case WMM_AC_BE:
+		return "BE";
+	case WMM_AC_BK:
+		return "BK";
+	case WMM_AC_VI:
+		return "VI";
+	case WMM_AC_VO:
+		return "VO";
+	default:
+		return "N/A";
+	}
+}
+
+static const char *get_direction_str(u8 direction)
+{
+	switch (direction) {
+	case WMM_AC_DIR_DOWNLINK:
+		return "Downlink";
+	case WMM_AC_DIR_UPLINK:
+		return "Uplink";
+	case WMM_AC_DIR_BIDIRECTIONAL:
+		return "Bi-directional";
+	default:
+		return "N/A";
+	}
+}
+
+int wpas_wmm_ac_status(struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
+{
+	struct wmm_tspec_element *tspec;
+	struct wmm_ac_assoc_data *assoc_info = wpa_s->wmm_ac_assoc_info;
+	enum ts_dir_idx idx;
+	int pos = 0;
+	u8 ac;
+
+	if (!assoc_info)
+		return wpa_scnprintf(buf, buflen - pos,
+				     "Not associated to a WMM AP, WMM AC is Disabled");
+
+	pos += wpa_scnprintf(buf + pos, buflen - pos, "WMM AC is Enabled\n");
+
+	for (ac = 0; ac < WMM_AC_NUM; ac++) {
+		int ts_count = 0;
+
+		pos += wpa_scnprintf(buf + pos, buflen - pos,
+				     "%s: acm=%d uapsd=%d\n",
+				     get_ac_str(ac),
+				     assoc_info->ac_params[ac].acm,
+				     assoc_info->ac_params[ac].uapsd);
+
+
+		for (idx = 0; idx < TS_DIR_IDX_COUNT; idx++) {
+			tspec = wpa_s->tspecs[ac][idx];
+			u8 dir, tsid;
+			const char *dir_str;
+
+			if (!tspec)
+				continue;
+
+			ts_count++;
+
+			dir = wmm_ac_get_direction(tspec);
+			dir_str = get_direction_str(dir);
+			tsid = wmm_ac_get_tsid(tspec);
+
+			pos += wpa_scnprintf(buf + pos, buflen - pos,
+					     "\tTSID = %u\n"
+					     "\tAddress = "MACSTR"\n"
+					     "\tWMM AC dir = %s\n"
+					     "\tTotal admitted time = %u\n\n",
+					     tsid,
+					     MAC2STR(wpa_s->bssid),
+					     dir_str,
+					     le_to_host16(tspec->medium_time));
+		}
+
+		if (!ts_count)
+			pos += wpa_scnprintf(buf + pos, buflen - pos,
+					     "\t(No Traffic Stream)\n\n");
+	}
+
+	return pos;
+}
diff --git a/wpa_supplicant/wmm_ac.h b/wpa_supplicant/wmm_ac.h
index 4a5995f..99ce810 100644
--- a/wpa_supplicant/wmm_ac.h
+++ b/wpa_supplicant/wmm_ac.h
@@ -166,6 +166,7 @@ void wmm_ac_notify_disassoc(struct wpa_supplicant *wpa_s);
 int wpas_wmm_ac_addts(struct wpa_supplicant *wpa_s,
 		      struct wmm_ac_ts_setup_params *params);
 int wpas_wmm_ac_delts(struct wpa_supplicant *wpa_s, u8 tsid);
+int wpas_wmm_ac_status(struct wpa_supplicant *wpa_s, char *buf, size_t buflen);
 void wmm_ac_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
 			const u8 *sa, const u8 *data, size_t len);
 #endif /* WMM_AC_H */
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 38a531a..163875e 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -2394,6 +2394,13 @@ static int wpa_cli_cmd_wmm_ac_delts(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static int wpa_cli_cmd_wmm_ac_status(struct wpa_ctrl *ctrl, int argc,
+				    char *argv[])
+{
+	return wpa_ctrl_command(ctrl, "WMM_AC_STATUS");
+}
+
+
 static int wpa_cli_cmd_signal_poll(struct wpa_ctrl *ctrl, int argc,
 				   char *argv[])
 {
@@ -2943,6 +2950,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
 	{ "wmm_ac_delts", wpa_cli_cmd_wmm_ac_delts, NULL,
 	  cli_cmd_flag_none,
 	  "<tsid> = delete WMM-AC traffic stream" },
+	{ "wmm_ac_status", wpa_cli_cmd_wmm_ac_status, NULL,
+	  cli_cmd_flag_none,
+	  "= show status for Wireless Multi-Media Admission-Control" },
 	{ "signal_poll", wpa_cli_cmd_signal_poll, NULL,
 	  cli_cmd_flag_none,
 	  "= get signal parameters" },
-- 
1.8.3.2




More information about the Hostap mailing list