Patchwork wpa_supplicant: Add get_capability freq

login
register
mail settings
Submitter Bruno Randolf
Date April 5, 2013, 3:54 p.m.
Message ID <1365177270-13207-1-git-send-email-br1@einfach.org>
Download mbox | patch
Permalink /patch/234188/
State Accepted
Commit 060605226fb7fe0b2e3eec234b842c7ee8c4fcb0
Headers show

Comments

Bruno Randolf - April 5, 2013, 3:54 p.m.
Add "get_capability freq" command to print a more verbose list of channels and
frequencies in MHz. The tag "NO_IBSS" is added, if IBSS mode is not allowed on
a channel. This allows userspace programs to get the frequencies and
limitations associated with each channel.

This extends the information already provided in "get_capability channel" but a
new interface is chosen because of backwards compatibility considerations.

Signed-hostap: Bruno Randolf <br1@einfach.org>
---
 wpa_supplicant/ctrl_iface.c |   55 +++++++++++++++++++++++++++++++++++++++++++
 wpa_supplicant/wpa_cli.c    |    2 +-
 2 files changed, 56 insertions(+), 1 deletion(-)
Jouni Malinen - April 23, 2013, 1:57 p.m.
On Fri, Apr 05, 2013 at 04:54:30PM +0100, Bruno Randolf wrote:
> Add "get_capability freq" command to print a more verbose list of channels and
> frequencies in MHz. The tag "NO_IBSS" is added, if IBSS mode is not allowed on
> a channel. This allows userspace programs to get the frequencies and
> limitations associated with each channel.
> 
> This extends the information already provided in "get_capability channel" but a
> new interface is chosen because of backwards compatibility considerations.

Thanks, applied.

Patch

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 27220a9..44d3f6c 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -2944,6 +2944,58 @@  static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
 }
 
 
+static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
+					      char *buf, size_t buflen)
+{
+	struct hostapd_channel_data *chnl;
+	int ret, i, j;
+	char *pos, *end, *hmode;
+
+	pos = buf;
+	end = pos + buflen;
+
+	for (j = 0; j < wpa_s->hw.num_modes; j++) {
+		switch (wpa_s->hw.modes[j].mode) {
+		case HOSTAPD_MODE_IEEE80211B:
+			hmode = "B";
+			break;
+		case HOSTAPD_MODE_IEEE80211G:
+			hmode = "G";
+			break;
+		case HOSTAPD_MODE_IEEE80211A:
+			hmode = "A";
+			break;
+		case HOSTAPD_MODE_IEEE80211AD:
+			hmode = "AD";
+			break;
+		default:
+			continue;
+		}
+		ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n", hmode);
+		if (ret < 0 || ret >= end - pos)
+			return pos - buf;
+		pos += ret;
+		chnl = wpa_s->hw.modes[j].channels;
+		for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
+			if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
+				continue;
+			ret = os_snprintf(pos, end - pos, " %d = %d MHz%s\n",
+					  chnl[i].chan, chnl[i].freq,
+					  chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ? " (NO_IBSS)" : "");
+			if (ret < 0 || ret >= end - pos)
+				return pos - buf;
+			pos += ret;
+		}
+		ret = os_snprintf(pos, end - pos, "\n");
+		if (ret < 0 || ret >= end - pos)
+			return pos - buf;
+		pos += ret;
+	}
+
+	return pos - buf;
+}
+
+
 static int wpa_supplicant_ctrl_iface_get_capability(
 	struct wpa_supplicant *wpa_s, const char *_field, char *buf,
 	size_t buflen)
@@ -3001,6 +3053,9 @@  static int wpa_supplicant_ctrl_iface_get_capability(
 	if (os_strcmp(field, "channels") == 0)
 		return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
 
+	if (os_strcmp(field, "freq") == 0)
+		return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
+
 	wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
 		   field);
 
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 3765c4e..87d7928 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -2445,7 +2445,7 @@  static struct wpa_cli_cmd wpa_cli_commands[] = {
 	  "<<idx> | <bssid>> = get detailed scan result info" },
 	{ "get_capability", wpa_cli_cmd_get_capability, NULL,
 	  cli_cmd_flag_none,
-	  "<eap/pairwise/group/key_mgmt/proto/auth_alg/channels/modes> "
+	  "<eap/pairwise/group/key_mgmt/proto/auth_alg/channels/freq/modes> "
 	  "= get capabilies" },
 	{ "reconfigure", wpa_cli_cmd_reconfigure, NULL,
 	  cli_cmd_flag_none,