]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Send AP Settings as a wrapped Credential attribute to ctrl_iface
authorZhi Chen <zhichen@qca.qualcomm.com>
Fri, 30 Sep 2011 19:26:37 +0000 (22:26 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 30 Sep 2011 19:26:37 +0000 (22:26 +0300)
Wrap self-generated WPS credential for new AP settings and send that to
control interface to provide the needed information in
WPS-NEW-AP-SETTINGS for external processing.

src/ap/wps_hostapd.c
src/wps/wps.h
src/wps/wps_registrar.c

index ebafc8660ff3599c687e74cd86cb13cb8eb1f092..671bc67470e3c03f49983db5b40fd69b81876256 100644 (file)
@@ -242,6 +242,20 @@ static void wps_reload_config(void *eloop_data, void *user_ctx)
 }
 
 
+static void hapd_new_ap_event(struct hostapd_data *hapd, const u8 *attr,
+                             size_t attr_len)
+{
+       size_t blen = attr_len * 2 + 1;
+       char *buf = os_malloc(blen);
+       if (buf) {
+               wpa_snprintf_hex(buf, blen, attr, attr_len);
+               wpa_msg(hapd->msg_ctx, MSG_INFO,
+                       WPS_EVENT_NEW_AP_SETTINGS "%s", buf);
+               os_free(buf);
+       }
+}
+
+
 static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
 {
        const struct wps_credential *cred = ctx;
@@ -271,15 +285,15 @@ static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
 
        if ((hapd->conf->wps_cred_processing == 1 ||
             hapd->conf->wps_cred_processing == 2) && cred->cred_attr) {
-               size_t blen = cred->cred_attr_len * 2 + 1;
-               char *_buf = os_malloc(blen);
-               if (_buf) {
-                       wpa_snprintf_hex(_buf, blen,
-                                        cred->cred_attr, cred->cred_attr_len);
-                       wpa_msg(hapd->msg_ctx, MSG_INFO, "%s%s",
-                               WPS_EVENT_NEW_AP_SETTINGS, _buf);
-                       os_free(_buf);
-               }
+               hapd_new_ap_event(hapd, cred->cred_attr, cred->cred_attr_len);
+       } else if (hapd->conf->wps_cred_processing == 1 ||
+                  hapd->conf->wps_cred_processing == 2) {
+               struct wpabuf *attr;
+               attr = wpabuf_alloc(200);
+               if (attr && wps_build_credential_wrap(attr, cred) == 0)
+                       hapd_new_ap_event(hapd, wpabuf_head_u8(attr),
+                                         wpabuf_len(attr));
+               wpabuf_free(attr);
        } else
                wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS);
 
index e2cd4a7bd13763095ea213c3c728e06ad8afe5e6..cdafc2709ead83067f9445fddca32b23ef3f6694 100644 (file)
@@ -793,6 +793,9 @@ int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
 int wps_registrar_config_ap(struct wps_registrar *reg,
                            struct wps_credential *cred);
 
+int wps_build_credential_wrap(struct wpabuf *msg,
+                             const struct wps_credential *cred);
+
 unsigned int wps_pin_checksum(unsigned int pin);
 unsigned int wps_pin_valid(unsigned int pin);
 unsigned int wps_generate_pin(void);
index 4ce78171e58d4644da575c304dc5f499ce46c113..37b06db33cc3b520802ef34f275be04359a9f74d 100644 (file)
@@ -1410,6 +1410,25 @@ static int wps_build_credential(struct wpabuf *msg,
 }
 
 
+int wps_build_credential_wrap(struct wpabuf *msg,
+                             const struct wps_credential *cred)
+{
+       struct wpabuf *wbuf;
+       wbuf = wpabuf_alloc(200);
+       if (wbuf == NULL)
+               return -1;
+       if (wps_build_credential(wbuf, cred)) {
+               wpabuf_free(wbuf);
+               return -1;
+       }
+       wpabuf_put_be16(msg, ATTR_CRED);
+       wpabuf_put_be16(msg, wpabuf_len(wbuf));
+       wpabuf_put_buf(msg, wbuf);
+       wpabuf_free(wbuf);
+       return 0;
+}
+
+
 int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
 {
        struct wpabuf *cred;