Fix wpa_supplicant AP mode with WPS not to crash
[libeap.git] / src / ap / wps_hostapd.c
index f1ad1df..0b9c2af 100644 (file)
@@ -540,6 +540,8 @@ static int count_interface_cb(struct hostapd_iface *iface, void *ctx)
 static int interface_count(struct hostapd_iface *iface)
 {
        int count = 0;
+       if (iface->for_each_interface == NULL)
+               return 0;
        iface->for_each_interface(iface->interfaces, count_interface_cb,
                                  &count);
        return count;
@@ -601,6 +603,22 @@ int hostapd_init_wps(struct hostapd_data *hapd,
                os_strdup(hapd->conf->serial_number) : NULL;
        wps->config_methods =
                wps_config_methods_str2bin(hapd->conf->config_methods);
+#ifdef CONFIG_WPS2
+       if ((wps->config_methods &
+            (WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY |
+             WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) {
+               wpa_printf(MSG_INFO, "WPS: Converting display to "
+                          "virtual_display for WPS 2.0 compliance");
+               wps->config_methods |= WPS_CONFIG_VIRT_DISPLAY;
+       }
+       if ((wps->config_methods &
+            (WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
+             WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) {
+               wpa_printf(MSG_INFO, "WPS: Converting push_button to "
+                          "virtual_push_button for WPS 2.0 compliance");
+               wps->config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
+       }
+#endif /* CONFIG_WPS2 */
        if (hapd->conf->device_type &&
            wps_dev_type_str2bin(hapd->conf->device_type,
                                 wps->dev.pri_dev_type) < 0) {
@@ -768,6 +786,15 @@ void hostapd_update_wps(struct hostapd_data *hapd)
 {
        if (hapd->wps == NULL)
                return;
+
+#ifdef CONFIG_WPS_UPNP
+       hapd->wps->friendly_name = hapd->conf->friendly_name;
+       hapd->wps->manufacturer_url = hapd->conf->manufacturer_url;
+       hapd->wps->model_description = hapd->conf->model_description;
+       hapd->wps->model_url = hapd->conf->model_url;
+       hapd->wps->upc = hapd->conf->upc;
+#endif /* CONFIG_WPS_UPNP */
+
        if (hapd->conf->wps_state)
                wps_registrar_update_ie(hapd->wps->registrar);
        else