[PATCH] add commands to hostapd_cli to dynamically change and clear vendor IE

Adrien Decostre ad.decostre at gmail.com
Thu Jun 6 20:57:24 PDT 2019


The patch below adds 2 commands to hostapd_cli to dynamically change
the vendor specific Information Element of the beacon without
restarting the software access point.

Signed-off-by: Adrien Decostre <adrien.decostre at barco.com>
---
 hostapd/Makefile      |  4 ++++
 hostapd/ctrl_iface.c  | 37 +++++++++++++++++++++++++++++++++++++
 hostapd/defconfig     |  4 ++++
 hostapd/hostapd_cli.c | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+)

diff --git a/hostapd/Makefile b/hostapd/Makefile
index a8d77fe..fef56ec 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -1222,6 +1222,10 @@ OBJS += ../src/ap/acs.o
 LIBS += -lm
 endif

+ifdef CONFIG_DYNAMIC_VENDOR_IE
+CFLAGS += -DCONFIG_DYNAMIC_VENDOR_IE
+endif
+
 ifdef CONFIG_NO_STDOUT_DEBUG
 CFLAGS += -DCONFIG_NO_STDOUT_DEBUG
 endif
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 0f6dfa1..686566e 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -667,6 +667,35 @@ static int
hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data *hapd,

 #endif /* CONFIG_HS20 */

+#ifdef CONFIG_DYNAMIC_VENDOR_IE
+
+static int hostapd_ctrl_iface_clear_vendor_ie(struct hostapd_data *hapd,
+       const char *cmd)
+{
+    wpabuf_free(hapd->conf->vendor_elements);
+    hapd->conf->vendor_elements = NULL;
+    int ret = ieee802_11_set_beacon(hapd);
+
+    return ret;
+}
+
+static int hostapd_ctrl_iface_add_vendor_ie(struct hostapd_data *hapd,
+       const char *cmd)
+{
+    struct wpabuf *elems = wpabuf_parse_bin(cmd);
+    if (!elems) {
+        return -1;
+    }
+
+    wpabuf_free(hapd->conf->vendor_elements);
+    hapd->conf->vendor_elements = elems;
+
+    int ret = ieee802_11_set_beacon(hapd);
+
+    return ret;
+}
+
+#endif /* CONFIG_DYNAMIC_VENDOR_IE */

 #ifdef CONFIG_INTERWORKING

@@ -3095,6 +3124,14 @@ static int
hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
  if (hostapd_ctrl_iface_hs20_deauth_req(hapd, buf + 16))
  reply_len = -1;
 #endif /* CONFIG_HS20 */
+#ifdef CONFIG_DYNAMIC_VENDOR_IE
+    } else if (os_strncmp(buf, "CLEAR_VENDOR_IE ", 16) == 0) {
+        if (hostapd_ctrl_iface_clear_vendor_ie(hapd, buf + 16))
+            reply_len = -1;
+    } else if (os_strncmp(buf, "ADD_VENDOR_IE ", 14) == 0) {
+        if (hostapd_ctrl_iface_add_vendor_ie(hapd, buf + 14))
+            reply_len = -1;
+#endif
 #ifdef CONFIG_WNM_AP
  } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
  if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
diff --git a/hostapd/defconfig b/hostapd/defconfig
index 1f504ad..524aabb 100644
--- a/hostapd/defconfig
+++ b/hostapd/defconfig
@@ -352,6 +352,10 @@ CONFIG_IPV6=y
 #
 #CONFIG_ACS=y

+# Vendor Information Element dynamic control
+# This allows controlling the vendor specific IE from the CLI without
restarting the AP
+#CONFIG_DYNAMIC_VENDOR_IE=y
+
 # Multiband Operation support
 # These extentions facilitate efficient use of multiple frequency bands
 # available to the AP and the devices that may associate with it.
diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index 0460243..dcdf655 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -902,6 +902,37 @@ static int hostapd_cli_cmd_hs20_deauth_req(struct
wpa_ctrl *ctrl, int argc,
  return wpa_ctrl_command(ctrl, buf);
 }

+#ifdef CONFIG_DYNAMIC_VENDOR_IE
+static int hostapd_cli_cmd_add_vendor_ie(struct wpa_ctrl *ctrl, int
argc, char *argv[])
+{
+    int ret;
+    if (argc == 0) {
+        return -1;
+    }
+
+    char cmd[]="ADD_VENDOR_IE";
+    int bufsize = strlen(argv[0]) + strlen(cmd) + 2;
+    char *buf = os_malloc(bufsize);
+    if (buf == NULL) {
+        return -1;
+    }
+
+    snprintf(buf, bufsize, "%s %s", cmd, argv[0]);
+
+    ret = wpa_ctrl_command(ctrl, buf);
+
+    os_free(buf);
+
+    return ret;
+}
+
+static int hostapd_cli_cmd_clear_vendor_ie(struct wpa_ctrl *ctrl, int
argc, char *argv[])
+{
+    char cmd[32];
+    snprintf(cmd, sizeof(cmd), "CLEAR_VENDOR_IE ");
+    return wpa_ctrl_command(ctrl, cmd);
+}
+#endif

 static int hostapd_cli_cmd_quit(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
@@ -1615,6 +1646,13 @@ static const struct hostapd_cli_cmd
hostapd_cli_commands[] = {
  { "hs20_deauth_req", hostapd_cli_cmd_hs20_deauth_req, NULL,
    "<addr> <code (0/1)> <Re-auth-Delay(sec)> [url]\n"
    "  = send WNM-Notification imminent deauthentication indication" },
+#ifdef CONFIG_DYNAMIC_VENDOR_IE
+        { "add_vendor_ie", hostapd_cli_cmd_add_vendor_ie, NULL,
+          "<vendor_ie_data> [<hex formatted data>]\n"
+          "= add a vendor specific IE to beacon" },
+        { "clear_vendor_ie", hostapd_cli_cmd_clear_vendor_ie, NULL,
+          "= clear existing vendor IE from beacon" },
+#endif
  { "vendor", hostapd_cli_cmd_vendor, NULL,
    "<vendor id> <sub command id> [<hex formatted data>]\n"
    "  = send vendor driver command" },
-- 
2.7.4



More information about the Hostap mailing list