WPS: Send AP Settings as a wrapped Credential attribute to ctrl_iface

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.
This commit is contained in:
Zhi Chen 2011-09-30 22:26:37 +03:00 committed by Jouni Malinen
parent 7d232e23e2
commit 56aa082a1d
3 changed files with 45 additions and 9 deletions

View 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) static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
{ {
const struct wps_credential *cred = 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 || if ((hapd->conf->wps_cred_processing == 1 ||
hapd->conf->wps_cred_processing == 2) && cred->cred_attr) { hapd->conf->wps_cred_processing == 2) && cred->cred_attr) {
size_t blen = cred->cred_attr_len * 2 + 1; hapd_new_ap_event(hapd, cred->cred_attr, cred->cred_attr_len);
char *_buf = os_malloc(blen); } else if (hapd->conf->wps_cred_processing == 1 ||
if (_buf) { hapd->conf->wps_cred_processing == 2) {
wpa_snprintf_hex(_buf, blen, struct wpabuf *attr;
cred->cred_attr, cred->cred_attr_len); attr = wpabuf_alloc(200);
wpa_msg(hapd->msg_ctx, MSG_INFO, "%s%s", if (attr && wps_build_credential_wrap(attr, cred) == 0)
WPS_EVENT_NEW_AP_SETTINGS, _buf); hapd_new_ap_event(hapd, wpabuf_head_u8(attr),
os_free(_buf); wpabuf_len(attr));
} wpabuf_free(attr);
} else } else
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS); wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS);

View 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, int wps_registrar_config_ap(struct wps_registrar *reg,
struct wps_credential *cred); 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_checksum(unsigned int pin);
unsigned int wps_pin_valid(unsigned int pin); unsigned int wps_pin_valid(unsigned int pin);
unsigned int wps_generate_pin(void); unsigned int wps_generate_pin(void);

View 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) int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
{ {
struct wpabuf *cred; struct wpabuf *cred;