]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Remove unnecessary GetDevice and PutMessage callbacks
authorJouni Malinen <j@w1.fi>
Sat, 12 Dec 2009 14:47:39 +0000 (16:47 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 12 Dec 2009 14:47:39 +0000 (16:47 +0200)
These callbacks can be handled internally within core WPS code, so there
is no need to go through wps_hostapd.c with a callback function that is
just calling back into the core WPS code.

hostapd/wps_hostapd.c
src/wps/wps_upnp.c
src/wps/wps_upnp.h
src/wps/wps_upnp_web.c

index a5a997c955dbb62587aaaeb4772c9211b790af5e..da6c4a5ad8b8f4650ff3bd39cdd999b43bd6ffe9 100644 (file)
@@ -805,61 +805,6 @@ static void hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
 
 #ifdef CONFIG_WPS_UPNP
 
-static struct wpabuf *
-hostapd_rx_req_get_device_info(void *priv, struct upnp_wps_peer *peer)
-{
-       struct hostapd_data *hapd = priv;
-       struct wps_config cfg;
-       struct wps_data *wps;
-       enum wsc_op_code op_code;
-       struct wpabuf *m1;
-
-       /*
-        * Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS
-        * registration over UPnP with the AP acting as an Enrollee. It should
-        * be noted that this is frequently used just to get the device data,
-        * i.e., there may not be any intent to actually complete the
-        * registration.
-        */
-
-       if (peer->wps)
-               wps_deinit(peer->wps);
-
-       os_memset(&cfg, 0, sizeof(cfg));
-       cfg.wps = hapd->wps;
-       cfg.pin = (u8 *) hapd->conf->ap_pin;
-       cfg.pin_len = os_strlen(hapd->conf->ap_pin);
-       wps = wps_init(&cfg);
-       if (wps == NULL)
-               return NULL;
-
-       m1 = wps_get_msg(wps, &op_code);
-       if (m1 == NULL) {
-               wps_deinit(wps);
-               return NULL;
-       }
-
-       peer->wps = wps;
-
-       return m1;
-}
-
-
-static struct wpabuf *
-hostapd_rx_req_put_message(void *priv, struct upnp_wps_peer *peer,
-                          const struct wpabuf *msg)
-{
-       enum wps_process_res res;
-       enum wsc_op_code op_code;
-
-       /* PutMessage: msg = InMessage, return OutMessage */
-       res = wps_process_msg(peer->wps, WSC_UPnP, msg);
-       if (res == WPS_FAILURE)
-               return NULL;
-       return wps_get_msg(peer->wps, &op_code);
-}
-
-
 static int hostapd_rx_req_put_wlan_response(
        void *priv, enum upnp_wps_wlanevent_type ev_type,
        const u8 *mac_addr, const struct wpabuf *msg,
@@ -928,9 +873,9 @@ static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
        if (ctx == NULL)
                return -1;
 
-       ctx->rx_req_get_device_info = hostapd_rx_req_get_device_info;
-       ctx->rx_req_put_message = hostapd_rx_req_put_message;
        ctx->rx_req_put_wlan_response = hostapd_rx_req_put_wlan_response;
+       if (hapd->conf->ap_pin)
+               ctx->ap_pin = os_strdup(hapd->conf->ap_pin);
 
        hapd->wps_upnp = upnp_wps_device_init(ctx, wps, hapd);
        if (hapd->wps_upnp == NULL) {
index 63a1328963b4cf872fb913babb5f57c43a4a5759..0b66ea29fd13f753f3502911759dfff1840b17eb 100644 (file)
@@ -1101,6 +1101,7 @@ void upnp_wps_device_deinit(struct upnp_wps_device_sm *sm)
                wps_deinit(sm->peer.wps);
        os_free(sm->root_dir);
        os_free(sm->desc_url);
+       os_free(sm->ctx->ap_pin);
        os_free(sm->ctx);
        os_free(sm);
 }
index 0b0d2af543e965a2ff217e0a837fbc90deb9ed96..1467db3becccc4acea8c8bb52dae5fdbc1f013dc 100644 (file)
@@ -25,15 +25,12 @@ enum upnp_wps_wlanevent_type {
 };
 
 struct upnp_wps_device_ctx {
-       struct wpabuf * (*rx_req_get_device_info)(
-               void *priv, struct upnp_wps_peer *peer);
-       struct wpabuf * (*rx_req_put_message)(
-               void *priv, struct upnp_wps_peer *peer,
-               const struct wpabuf *msg);
        int (*rx_req_put_wlan_response)(
                void *priv, enum upnp_wps_wlanevent_type ev_type,
                const u8 *mac_addr, const struct wpabuf *msg,
                enum wps_msg_type msg_type);
+
+       char *ap_pin;
 };
 
 struct upnp_wps_device_sm *
index 311a1d9821bb73cce98ddef6a74d4a255aa20cae..dcfd208829d51b9ffca54dc36186cc52f0d6a288 100644 (file)
@@ -407,11 +407,36 @@ web_process_get_device_info(struct upnp_wps_device_sm *sm,
                            struct wpabuf **reply, const char **replyname)
 {
        static const char *name = "NewDeviceInfo";
+       struct wps_config cfg;
+       struct upnp_wps_peer *peer = &sm->peer;
 
        wpa_printf(MSG_DEBUG, "WPS UPnP: GetDeviceInfo");
-       if (sm->ctx->rx_req_get_device_info == NULL)
-               return HTTP_INTERNAL_SERVER_ERROR;
-       *reply = sm->ctx->rx_req_get_device_info(sm->priv, &sm->peer);
+
+       /*
+        * Request for DeviceInfo, i.e., M1 TLVs. This is a start of WPS
+        * registration over UPnP with the AP acting as an Enrollee. It should
+        * be noted that this is frequently used just to get the device data,
+        * i.e., there may not be any intent to actually complete the
+        * registration.
+        */
+
+       if (peer->wps)
+               wps_deinit(peer->wps);
+
+       os_memset(&cfg, 0, sizeof(cfg));
+       cfg.wps = sm->wps;
+       cfg.pin = (u8 *) sm->ctx->ap_pin;
+       cfg.pin_len = os_strlen(sm->ctx->ap_pin);
+       peer->wps = wps_init(&cfg);
+       if (peer->wps) {
+               enum wsc_op_code op_code;
+               *reply = wps_get_msg(peer->wps, &op_code);
+               if (*reply == NULL) {
+                       wps_deinit(peer->wps);
+                       peer->wps = NULL;
+               }
+       } else
+               *reply = NULL;
        if (*reply == NULL) {
                wpa_printf(MSG_INFO, "WPS UPnP: Failed to get DeviceInfo");
                return HTTP_INTERNAL_SERVER_ERROR;
@@ -428,6 +453,8 @@ web_process_put_message(struct upnp_wps_device_sm *sm, char *data,
        struct wpabuf *msg;
        static const char *name = "NewOutMessage";
        enum http_reply_code ret;
+       enum wps_process_res res;
+       enum wsc_op_code op_code;
 
        /*
         * PutMessage is used by external UPnP-based Registrar to perform WPS
@@ -435,12 +462,14 @@ web_process_put_message(struct upnp_wps_device_sm *sm, char *data,
         * PutWLANResponse which is for proxying.
         */
        wpa_printf(MSG_DEBUG, "WPS UPnP: PutMessage");
-       if (sm->ctx->rx_req_put_message == NULL)
-               return HTTP_INTERNAL_SERVER_ERROR;
        msg = xml_get_base64_item(data, "NewInMessage", &ret);
        if (msg == NULL)
                return ret;
-       *reply = sm->ctx->rx_req_put_message(sm->priv, &sm->peer, msg);
+       res = wps_process_msg(sm->peer.wps, WSC_UPnP, msg);
+       if (res == WPS_FAILURE)
+               *reply = NULL;
+       else
+               *reply = wps_get_msg(sm->peer.wps, &op_code);
        wpabuf_free(msg);
        if (*reply == NULL)
                return HTTP_INTERNAL_SERVER_ERROR;