WPS 2.0: Add virtual/physical display and pushbutton config methods
[libeap.git] / src / wps / wps_registrar.c
index cbe8a72..dc0dd87 100644 (file)
@@ -420,9 +420,16 @@ static int wps_build_sel_reg_config_methods(struct wps_registrar *reg,
        u16 methods;
        if (!reg->sel_reg_union)
                return 0;
-       methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
-       if (reg->pbc)
+       methods = reg->wps->config_methods &
+               ~(WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
+                 WPS_CONFIG_PHY_PUSHBUTTON);
+       if (reg->pbc) {
                methods |= WPS_CONFIG_PUSHBUTTON;
+               if (reg->wps->config_methods & WPS_CONFIG_VIRT_PUSHBUTTON)
+                       methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
+               if (reg->wps->config_methods & WPS_CONFIG_PHY_PUSHBUTTON)
+                       methods |= WPS_CONFIG_PHY_PUSHBUTTON;
+       }
        if (reg->sel_reg_config_methods_override >= 0)
                methods = reg->sel_reg_config_methods_override;
        wpa_printf(MSG_DEBUG, "WPS:  * Selected Registrar Config Methods (%x)",
@@ -442,7 +449,9 @@ static int wps_build_probe_config_methods(struct wps_registrar *reg,
         * These are the methods that the AP supports as an Enrollee for adding
         * external Registrars.
         */
-       methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
+       methods = reg->wps->config_methods &
+               ~(WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
+                 WPS_CONFIG_PHY_PUSHBUTTON);
        wpa_printf(MSG_DEBUG, "WPS:  * Config Methods (%x)", methods);
        wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
        wpabuf_put_be16(msg, 2);
@@ -455,9 +464,16 @@ static int wps_build_config_methods_r(struct wps_registrar *reg,
                                      struct wpabuf *msg)
 {
        u16 methods;
-       methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
-       if (reg->pbc)
+       methods = reg->wps->config_methods &
+               ~(WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
+                 WPS_CONFIG_PHY_PUSHBUTTON);
+       if (reg->pbc) {
                methods |= WPS_CONFIG_PUSHBUTTON;
+               if (reg->wps->config_methods & WPS_CONFIG_VIRT_PUSHBUTTON)
+                       methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
+               if (reg->wps->config_methods & WPS_CONFIG_PHY_PUSHBUTTON)
+                       methods |= WPS_CONFIG_PHY_PUSHBUTTON;
+       }
        return wps_build_config_methods(msg, methods);
 }
 
@@ -920,9 +936,18 @@ static void wps_cb_set_sel_reg(struct wps_registrar *reg)
                return;
 
        if (reg->selected_registrar) {
-               methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
-               if (reg->pbc)
+               methods = reg->wps->config_methods &
+                       ~(WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
+                         WPS_CONFIG_PHY_PUSHBUTTON);
+               if (reg->pbc) {
                        methods |= WPS_CONFIG_PUSHBUTTON;
+                       if (reg->wps->config_methods &
+                           WPS_CONFIG_VIRT_PUSHBUTTON)
+                               methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
+                       if (reg->wps->config_methods &
+                           WPS_CONFIG_PHY_PUSHBUTTON)
+                               methods |= WPS_CONFIG_PHY_PUSHBUTTON;
+               }
        }
 
        reg->set_sel_reg_cb(reg->cb_ctx, reg->selected_registrar,
@@ -2918,12 +2943,22 @@ void wps_registrar_selected_registrar_changed(struct wps_registrar *reg)
                  WPS_MAX_AUTHORIZED_MACS * ETH_ALEN);
        if (reg->selected_registrar) {
                reg->sel_reg_config_methods_override =
-                       reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
+                       reg->wps->config_methods &
+                       ~(WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
+                         WPS_CONFIG_PHY_PUSHBUTTON);
                if (reg->pbc) {
                        reg->sel_reg_dev_password_id_override =
                                DEV_PW_PUSHBUTTON;
                        reg->sel_reg_config_methods_override |=
                                WPS_CONFIG_PUSHBUTTON;
+                       if (reg->wps->config_methods &
+                           WPS_CONFIG_VIRT_PUSHBUTTON)
+                               reg->sel_reg_config_methods_override |=
+                                       WPS_CONFIG_VIRT_PUSHBUTTON;
+                       if (reg->wps->config_methods &
+                           WPS_CONFIG_PHY_PUSHBUTTON)
+                               reg->sel_reg_config_methods_override |=
+                                       WPS_CONFIG_PHY_PUSHBUTTON;
                }
                wpa_printf(MSG_DEBUG, "WPS: Internal Registrar selected "
                           "(pbc=%d)", reg->pbc);