Add STATUS command to global control interface
authorJouni Malinen <j@w1.fi>
Sun, 25 Aug 2013 17:53:58 +0000 (20:53 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 25 Aug 2013 17:53:58 +0000 (20:53 +0300)
This provides global status information that is applicable to all
interfaces (e.g., P2P state). In addition, ifname/address pairs are
listed to get information of all the interfaces that are currently
managed through this wpa_supplicant instance.

Signed-hostap: Jouni Malinen <j@w1.fi>

wpa_supplicant/ctrl_iface.c

index 1a42ae3..1064f1d 100644 (file)
@@ -6036,6 +6036,47 @@ static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
 #endif /* CONFIG_NO_CONFIG_WRITE */
 
 
+static int wpas_global_ctrl_iface_status(struct wpa_global *global,
+                                        char *buf, size_t buflen)
+{
+       char *pos, *end;
+       int ret;
+       struct wpa_supplicant *wpa_s;
+
+       pos = buf;
+       end = buf + buflen;
+
+#ifdef CONFIG_P2P
+       if (global->p2p) {
+               ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
+                                 "\n", MAC2STR(global->p2p_dev_addr));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+#endif /* CONFIG_P2P */
+
+#ifdef CONFIG_WIFI_DISPLAY
+       ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
+                         !!global->wifi_display);
+       if (ret < 0 || ret >= end - pos)
+               return pos - buf;
+       pos += ret;
+#endif /* CONFIG_WIFI_DISPLAY */
+
+       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               ret = os_snprintf(pos, end - pos, "ifname=%s\n"
+                                 "address=" MACSTR "\n",
+                                 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       return pos - buf;
+}
+
+
 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
                                                char *buf, size_t *resp_len)
 {
@@ -6101,6 +6142,9 @@ char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
                if (wpas_global_ctrl_iface_save_config(global))
                        reply_len = -1;
 #endif /* CONFIG_NO_CONFIG_WRITE */
+       } else if (os_strcmp(buf, "STATUS") == 0) {
+               reply_len = wpas_global_ctrl_iface_status(global, reply,
+                                                         reply_size);
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;