]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add parsed information from WPS IE(s) into scan results
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 11 Sep 2009 14:14:49 +0000 (17:14 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 11 Sep 2009 14:14:49 +0000 (17:14 +0300)
This makes it easier for external programs to show WPS information
since they do not need to parse the WPS IE themselves anymore.

src/wps/wps.c
src/wps/wps.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/wps_supplicant.c
wpa_supplicant/wps_supplicant.h

index cc8a45be290d919183b83168259bcfd54eead1b8..870a4932e5bf9786c1f2cd39688ba61e20e95b8c 100644 (file)
@@ -356,3 +356,104 @@ void wps_free_pending_msgs(struct upnp_pending_message *msgs)
                os_free(prev);
        }
 }
+
+
+int wps_attr_text(struct wpabuf *data, char *buf, char *end)
+{
+       struct wps_parse_attr attr;
+       char *pos = buf;
+       int ret;
+
+       if (wps_parse_msg(data, &attr) < 0)
+               return -1;
+
+       if (attr.wps_state) {
+               if (*attr.wps_state == WPS_STATE_NOT_CONFIGURED)
+                       ret = os_snprintf(pos, end - pos,
+                                         "wps_state=unconfigured\n");
+               else if (*attr.wps_state == WPS_STATE_CONFIGURED)
+                       ret = os_snprintf(pos, end - pos,
+                                         "wps_state=configured\n");
+               else
+                       ret = 0;
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.ap_setup_locked && *attr.ap_setup_locked) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_ap_setup_locked=1\n");
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.selected_registrar && *attr.selected_registrar) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_selected_registrar=1\n");
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.dev_password_id) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_device_password_id=%u\n",
+                                 WPA_GET_BE16(attr.dev_password_id));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.sel_reg_config_methods) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_selected_registrar_config_methods="
+                                 "0x%04x\n",
+                                 WPA_GET_BE16(attr.sel_reg_config_methods));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.primary_dev_type) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_primary_device_type=%u-%08x-%u\n",
+                                 WPA_GET_BE16(attr.primary_dev_type),
+                                 WPA_GET_BE32(&attr.primary_dev_type[2]),
+                                 WPA_GET_BE16(&attr.primary_dev_type[6]));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.dev_name) {
+               char *str = os_malloc(attr.dev_name_len + 1);
+               size_t i;
+               if (str == NULL)
+                       return pos - buf;
+               for (i = 0; i < attr.dev_name_len; i++) {
+                       if (attr.dev_name[i] < 32)
+                               str[i] = '_';
+                       else
+                               str[i] = attr.dev_name[i];
+               }
+               str[i] = '\0';
+               ret = os_snprintf(pos, end - pos, "wps_device_name=%s\n", str);
+               os_free(str);
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.config_methods) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_config_methods=0x%04x\n",
+                                 WPA_GET_BE16(attr.config_methods));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       return pos - buf;
+}
index 446ff4f167d6012813a8fde6bef13cf98f1493d4..22fa5eaad9c9b6acd925713b870e9b0dadd3095e 100644 (file)
@@ -589,5 +589,6 @@ struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
 int wps_get_oob_method(char *method);
 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
                    int registrar);
+int wps_attr_text(struct wpabuf *data, char *buf, char *end);
 
 #endif /* WPS_H */
index f1362b5327306c020dcd29e3dfee72dcc36a4230..8d6d02dc6cef83cb6d9229f0122f1720e1628412 100644 (file)
@@ -1547,6 +1547,14 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
                return pos - buf;
        pos += ret;
 
+#ifdef CONFIG_WPS
+       ie = (const u8 *) (bss + 1);
+       ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
+       if (ret < 0 || ret >= end - pos)
+               return pos - buf;
+       pos += ret;
+#endif /* CONFIG_WPS */
+
        return pos - buf;
 }
 
index 0ca67459df340007477d0e8425811b4501ffa574..b80c2de75341faabb073302f648bb23830531041 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "common.h"
 #include "ieee802_11_defs.h"
+#include "ieee802_11_common.h"
 #include "wpa_common.h"
 #include "config.h"
 #include "eap_peer/eap.h"
@@ -983,3 +984,19 @@ int wpas_wps_searching(struct wpa_supplicant *wpa_s)
 
        return 0;
 }
+
+
+int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
+                             char *end)
+{
+       struct wpabuf *wps_ie;
+       int ret;
+
+       wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
+       if (wps_ie == NULL)
+               return 0;
+
+       ret = wps_attr_text(wps_ie, buf, end);
+       wpabuf_free(wps_ie);
+       return ret;
+}
index 47253126fa8d500901ad390e99332ab15eb7eff0..0f239554501b14cca996f9cedf157af57fab957c 100644 (file)
@@ -47,6 +47,8 @@ int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
                              struct wpa_ssid *ssid);
 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s);
 int wpas_wps_searching(struct wpa_supplicant *wpa_s);
+int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *pos,
+                             char *end);
 
 #else /* CONFIG_WPS */