#include "wps/wps_defs.h"
#include "wps/wps_dev_attr.h"
#include "wps_hostapd.h"
+#include "dh_groups.h"
#ifdef CONFIG_WPS_UPNP
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,
+ char *_buf = os_malloc(blen);
+ if (_buf) {
+ wpa_snprintf_hex(_buf, blen,
cred->cred_attr, cred->cred_attr_len);
wpa_msg(hapd, MSG_INFO, "%s%s",
- WPS_EVENT_NEW_AP_SETTINGS, buf);
- os_free(buf);
+ WPS_EVENT_NEW_AP_SETTINGS, _buf);
+ os_free(_buf);
}
} else
wpa_msg(hapd, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS);
if (hapd->conf->wps_cred_processing == 1)
return 0;
+ os_memcpy(hapd->wps->ssid, cred->ssid, cred->ssid_len);
+ hapd->wps->ssid_len = cred->ssid_len;
+ hapd->wps->encr_types = cred->encr_type;
+ hapd->wps->auth_types = cred->auth_type;
+ if (cred->key == NULL) {
+ os_free(hapd->wps->network_key);
+ hapd->wps->network_key = NULL;
+ hapd->wps->network_key_len = 0;
+ } else {
+ if (hapd->wps->network_key == NULL ||
+ hapd->wps->network_key_len < cred->key_len) {
+ hapd->wps->network_key_len = 0;
+ os_free(hapd->wps->network_key);
+ hapd->wps->network_key = os_malloc(cred->key_len);
+ if (hapd->wps->network_key == NULL)
+ return -1;
+ }
+ hapd->wps->network_key_len = cred->key_len;
+ os_memcpy(hapd->wps->network_key, cred->key, cred->key_len);
+ }
+ hapd->wps->wps_state = WPS_STATE_CONFIGURED;
+
len = os_strlen(hapd->iface->config_fname) + 5;
tmp_fname = os_malloc(len);
if (tmp_fname == NULL)
else
fprintf(nconf, "auth_algs=1\n");
- if (cred->encr_type & WPS_ENCR_WEP && cred->key_idx < 4) {
- fprintf(nconf, "wep_default_key=%d\n", cred->key_idx);
- fprintf(nconf, "wep_key%d=", cred->key_idx);
- if (cred->key_len != 10 && cred->key_len != 26)
- fputc('"', nconf);
- for (i = 0; i < cred->key_len; i++)
- fputc(cred->key[i], nconf);
- if (cred->key_len != 10 && cred->key_len != 26)
- fputc('"', nconf);
+ if (cred->encr_type & WPS_ENCR_WEP && cred->key_idx <= 4) {
+ int key_idx = cred->key_idx;
+ if (key_idx)
+ key_idx--;
+ fprintf(nconf, "wep_default_key=%d\n", key_idx);
+ fprintf(nconf, "wep_key%d=", key_idx);
+ if (cred->key_len == 10 || cred->key_len == 26) {
+ /* WEP key as a hex string */
+ for (i = 0; i < cred->key_len; i++)
+ fputc(cred->key[i], nconf);
+ } else {
+ /* Raw WEP key; convert to hex */
+ for (i = 0; i < cred->key_len; i++)
+ fprintf(nconf, "%02x", cred->key[i]);
+ }
fprintf(nconf, "\n");
}
}
cfg.extra_cred_len = conf->extra_cred_len;
cfg.disable_auto_conf = (hapd->conf->wps_cred_processing == 1) &&
conf->skip_cred_build;
+ if (conf->ssid.security_policy == SECURITY_STATIC_WEP)
+ cfg.static_wep_only = 1;
wps->registrar = wps_registrar_init(wps, &cfg);
if (wps->registrar == NULL) {
wps_registrar_deinit(hapd->wps->registrar);
os_free(hapd->wps->network_key);
wps_device_data_free(&hapd->wps->dev);
- wpabuf_free(hapd->wps->upnp_msg);
+ wpabuf_free(hapd->wps->dh_pubkey);
+ wpabuf_free(hapd->wps->dh_privkey);
+ wpabuf_free(hapd->wps->oob_conf.pubkey_hash);
+ wpabuf_free(hapd->wps->oob_conf.dev_password);
+ wps_free_pending_msgs(hapd->wps->upnp_msgs);
os_free(hapd->wps);
hapd->wps = NULL;
hostapd_wps_clear_ies(hapd);
int hostapd_wps_add_pin(struct hostapd_data *hapd, const char *uuid,
- const char *pin)
+ const char *pin, int timeout)
{
u8 u[UUID_LEN];
int any = 0;
else if (uuid_str2bin(uuid, u))
return -1;
return wps_registrar_add_pin(hapd->wps->registrar, any ? NULL : u,
- (const u8 *) pin, os_strlen(pin));
+ (const u8 *) pin, os_strlen(pin),
+ timeout);
}
}
+#ifdef CONFIG_WPS_OOB
+int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type,
+ char *path, char *method, char *name)
+{
+ struct wps_context *wps = hapd->wps;
+ struct oob_device_data *oob_dev;
+
+ oob_dev = wps_get_oob_device(device_type);
+ if (oob_dev == NULL)
+ return -1;
+ oob_dev->device_path = path;
+ oob_dev->device_name = name;
+ wps->oob_conf.oob_method = wps_get_oob_method(method);
+
+ if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) {
+ /*
+ * Use pre-configured DH keys in order to be able to write the
+ * key hash into the OOB file.
+ */
+ wpabuf_free(wps->dh_pubkey);
+ wpabuf_free(wps->dh_privkey);
+ wps->dh_privkey = NULL;
+ wps->dh_pubkey = dh_init(dh_groups_get(WPS_DH_GROUP),
+ &wps->dh_privkey);
+ wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
+ if (wps->dh_pubkey == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
+ "Diffie-Hellman handshake");
+ return -1;
+ }
+ }
+
+ if (wps_process_oob(wps, oob_dev, 1) < 0)
+ goto error;
+
+ if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
+ wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
+ hostapd_wps_add_pin(hapd, "any",
+ wpabuf_head(wps->oob_conf.dev_password), 0) <
+ 0)
+ goto error;
+
+ return 0;
+
+error:
+ wpabuf_free(wps->dh_pubkey);
+ wps->dh_pubkey = NULL;
+ wpabuf_free(wps->dh_privkey);
+ wps->dh_privkey = NULL;
+ return -1;
+}
+#endif /* CONFIG_WPS_OOB */
+
+
void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
const u8 *ie, size_t ie_len)
{
}
-static int hostapd_rx_req_put_wlan_event_response(
+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)
+ const u8 *mac_addr, const struct wpabuf *msg,
+ enum wps_msg_type msg_type)
{
struct hostapd_data *hapd = priv;
struct sta_info *sta;
+ struct upnp_pending_message *p;
wpa_printf(MSG_DEBUG, "WPS UPnP: PutWLANResponse ev_type=%d mac_addr="
MACSTR, ev_type, MAC2STR(mac_addr));
* server implementation for delivery to the peer.
*/
- /* TODO: support multiple pending UPnP messages */
- os_memcpy(hapd->wps->upnp_msg_addr, mac_addr, ETH_ALEN);
- wpabuf_free(hapd->wps->upnp_msg);
- hapd->wps->upnp_msg = wpabuf_dup(msg);
-
sta = ap_get_sta(hapd, mac_addr);
- if (sta)
- return eapol_auth_eap_pending_cb(sta->eapol_sm,
- hapd->wps->pending_session);
+ if (!sta) {
+ /*
+ * Workaround - Intel wsccmd uses bogus NewWLANEventMAC:
+ * Pick STA that is in an ongoing WPS registration without
+ * checking the MAC address.
+ */
+ wpa_printf(MSG_DEBUG, "WPS UPnP: No matching STA found based "
+ "on NewWLANEventMAC; try wildcard match");
+ for (sta = hapd->sta_list; sta; sta = sta->next) {
+ if (sta->eapol_sm && (sta->flags & WLAN_STA_WPS))
+ break;
+ }
+ }
- return 0;
+ if (!sta) {
+ wpa_printf(MSG_DEBUG, "WPS UPnP: No matching STA found");
+ return 0;
+ }
+
+ p = os_zalloc(sizeof(*p));
+ if (p == NULL)
+ return -1;
+ os_memcpy(p->addr, sta->addr, ETH_ALEN);
+ p->msg = wpabuf_dup(msg);
+ p->type = msg_type;
+ p->next = hapd->wps->upnp_msgs;
+ hapd->wps->upnp_msgs = p;
+
+ return eapol_auth_eap_pending_cb(sta->eapol_sm, sta->eapol_sm->eap);
}
ctx->rx_req_get_sta_settings = hostapd_rx_req_get_sta_settings;
ctx->rx_req_set_sta_settings = hostapd_rx_req_set_sta_settings;
ctx->rx_req_del_sta_settings = hostapd_rx_req_del_sta_settings;
- ctx->rx_req_put_wlan_event_response =
- hostapd_rx_req_put_wlan_event_response;
+ ctx->rx_req_put_wlan_response = hostapd_rx_req_put_wlan_response;
ctx->rx_req_set_selected_registrar =
hostapd_rx_req_set_selected_registrar;
ctx->rx_req_reboot_ap = hostapd_rx_req_reboot_ap;