diff options
author | Jouni Malinen <jouni.malinen@atheros.com> | 2009-09-11 17:14:49 +0300 |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2009-09-11 17:14:49 +0300 |
commit | 611ed4911846f25c07a4a41fe1006df9da923d78 (patch) | |
tree | 9efe574681aa2b7324487b7cad2eb316f76aabe9 | |
parent | e9a2bca6f5e5dd7ef7aa62f6954b3877f41a1e34 (diff) | |
download | external_wpa_supplicant_8_ti-611ed4911846f25c07a4a41fe1006df9da923d78.zip external_wpa_supplicant_8_ti-611ed4911846f25c07a4a41fe1006df9da923d78.tar.gz external_wpa_supplicant_8_ti-611ed4911846f25c07a4a41fe1006df9da923d78.tar.bz2 |
Add parsed information from WPS IE(s) into scan results
This makes it easier for external programs to show WPS information
since they do not need to parse the WPS IE themselves anymore.
-rw-r--r-- | src/wps/wps.c | 101 | ||||
-rw-r--r-- | src/wps/wps.h | 1 | ||||
-rw-r--r-- | wpa_supplicant/ctrl_iface.c | 8 | ||||
-rw-r--r-- | wpa_supplicant/wps_supplicant.c | 17 | ||||
-rw-r--r-- | wpa_supplicant/wps_supplicant.h | 2 |
5 files changed, 129 insertions, 0 deletions
diff --git a/src/wps/wps.c b/src/wps/wps.c index cc8a45b..870a493 100644 --- a/src/wps/wps.c +++ b/src/wps/wps.c @@ -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; +} diff --git a/src/wps/wps.h b/src/wps/wps.h index 446ff4f..22fa5ea 100644 --- a/src/wps/wps.h +++ b/src/wps/wps.h @@ -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 */ diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index f1362b5..8d6d02d 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -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; } diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index 0ca6745..b80c2de 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -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; +} diff --git a/wpa_supplicant/wps_supplicant.h b/wpa_supplicant/wps_supplicant.h index 4725312..0f23955 100644 --- a/wpa_supplicant/wps_supplicant.h +++ b/wpa_supplicant/wps_supplicant.h @@ -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 */ |