#include "includes.h"
-#include "hostapd.h"
-#include "driver_i.h"
+#include "common.h"
#include "eloop.h"
#include "uuid.h"
-#include "wpa_ctrl.h"
-#include "ieee802_11_defs.h"
-#include "ieee802_11_common.h"
-#include "sta_info.h"
-#include "eapol_sm.h"
+#include "crypto/dh_groups.h"
+#include "common/wpa_ctrl.h"
+#include "common/ieee802_11_defs.h"
+#include "common/ieee802_11_common.h"
+#include "eapol_auth/eapol_auth_sm.h"
+#include "eapol_auth/eapol_auth_sm_i.h"
#include "wps/wps.h"
#include "wps/wps_defs.h"
#include "wps/wps_dev_attr.h"
+#include "hostapd.h"
+#include "config.h"
+#include "sta_info.h"
#include "wps_hostapd.h"
-#include "dh_groups.h"
#ifdef CONFIG_WPS_UPNP
}
-static int hostapd_wps_set_ie_cb(void *ctx, const u8 *beacon_ie,
- size_t beacon_ie_len, const u8 *probe_resp_ie,
- size_t probe_resp_ie_len)
+static int hostapd_wps_set_ie_cb(void *ctx, struct wpabuf *beacon_ie,
+ struct wpabuf *probe_resp_ie)
{
struct hostapd_data *hapd = ctx;
-
- os_free(hapd->wps_beacon_ie);
- if (beacon_ie_len == 0) {
- hapd->wps_beacon_ie = NULL;
- hapd->wps_beacon_ie_len = 0;
- } else {
- hapd->wps_beacon_ie = os_malloc(beacon_ie_len);
- if (hapd->wps_beacon_ie == NULL) {
- hapd->wps_beacon_ie_len = 0;
- return -1;
- }
- os_memcpy(hapd->wps_beacon_ie, beacon_ie, beacon_ie_len);
- hapd->wps_beacon_ie_len = beacon_ie_len;
- }
- hostapd_set_wps_beacon_ie(hapd, hapd->wps_beacon_ie,
- hapd->wps_beacon_ie_len);
-
- os_free(hapd->wps_probe_resp_ie);
- if (probe_resp_ie_len == 0) {
- hapd->wps_probe_resp_ie = NULL;
- hapd->wps_probe_resp_ie_len = 0;
- } else {
- hapd->wps_probe_resp_ie = os_malloc(probe_resp_ie_len);
- if (hapd->wps_probe_resp_ie == NULL) {
- hapd->wps_probe_resp_ie_len = 0;
- return -1;
- }
- os_memcpy(hapd->wps_probe_resp_ie, probe_resp_ie,
- probe_resp_ie_len);
- hapd->wps_probe_resp_ie_len = probe_resp_ie_len;
- }
- hostapd_set_wps_probe_resp_ie(hapd, hapd->wps_probe_resp_ie,
- hapd->wps_probe_resp_ie_len);
-
- return 0;
+ wpabuf_free(hapd->wps_beacon_ie);
+ hapd->wps_beacon_ie = beacon_ie;
+ wpabuf_free(hapd->wps_probe_resp_ie);
+ hapd->wps_probe_resp_ie = probe_resp_ie;
+ return hapd->drv.set_ap_wps_ie(hapd, hapd->wps_beacon_ie,
+ hapd->wps_probe_resp_ie);
}
struct hostapd_data *hapd = ctx;
char uuid[40], txt[400];
int len;
+ char devtype[WPS_DEV_TYPE_BUFSIZE];
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
return;
wpa_printf(MSG_DEBUG, "WPS: PIN needed for E-UUID %s", uuid);
len = os_snprintf(txt, sizeof(txt), WPS_EVENT_PIN_NEEDED
- "%s " MACSTR " [%s|%s|%s|%s|%s|%d-%08X-%d]",
+ "%s " MACSTR " [%s|%s|%s|%s|%s|%s]",
uuid, MAC2STR(dev->mac_addr), dev->device_name,
dev->manufacturer, dev->model_name,
dev->model_number, dev->serial_number,
- dev->categ, dev->oui, dev->sub_categ);
+ wps_dev_type_bin2str(dev->pri_dev_type, devtype,
+ sizeof(devtype)));
if (len > 0 && len < (int) sizeof(txt))
wpa_msg(hapd->msg_ctx, MSG_INFO, "%s", txt);
return;
os_get_time(&t);
fprintf(f, "%ld\t%s\t" MACSTR "\t%s\t%s\t%s\t%s\t%s"
- "\t%d-%08X-%d\n",
+ "\t%s\n",
t.sec, uuid, MAC2STR(dev->mac_addr), dev->device_name,
dev->manufacturer, dev->model_name, dev->model_number,
dev->serial_number,
- dev->categ, dev->oui, dev->sub_categ);
+ wps_dev_type_bin2str(dev->pri_dev_type, devtype,
+ sizeof(devtype)));
fclose(f);
}
}
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) {
+ if (cred->key_len == 0) {
os_free(hapd->wps->network_key);
hapd->wps->network_key = NULL;
hapd->wps->network_key_len = 0;
static void hostapd_wps_clear_ies(struct hostapd_data *hapd)
{
- os_free(hapd->wps_beacon_ie);
+ wpabuf_free(hapd->wps_beacon_ie);
hapd->wps_beacon_ie = NULL;
- hapd->wps_beacon_ie_len = 0;
- hostapd_set_wps_beacon_ie(hapd, NULL, 0);
- os_free(hapd->wps_probe_resp_ie);
+ wpabuf_free(hapd->wps_probe_resp_ie);
hapd->wps_probe_resp_ie = NULL;
- hapd->wps_probe_resp_ie_len = 0;
- hostapd_set_wps_probe_resp_ie(hapd, NULL, 0);
+
+ hapd->drv.set_ap_wps_ie(hapd, NULL, NULL);
}
os_strdup(hapd->conf->model_number) : NULL;
wps->dev.serial_number = hapd->conf->serial_number ?
os_strdup(hapd->conf->serial_number) : NULL;
- if (hapd->conf->config_methods) {
- char *m = hapd->conf->config_methods;
- if (os_strstr(m, "label"))
- wps->config_methods |= WPS_CONFIG_LABEL;
- if (os_strstr(m, "display"))
- wps->config_methods |= WPS_CONFIG_DISPLAY;
- if (os_strstr(m, "push_button"))
- wps->config_methods |= WPS_CONFIG_PUSHBUTTON;
- if (os_strstr(m, "keypad"))
- wps->config_methods |= WPS_CONFIG_KEYPAD;
- }
- if (hapd->conf->device_type) {
- char *pos;
- u8 oui[4];
- /* <categ>-<OUI>-<subcateg> */
- wps->dev.categ = atoi(hapd->conf->device_type);
- pos = os_strchr(hapd->conf->device_type, '-');
- if (pos == NULL) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
- os_free(wps);
- return -1;
- }
- pos++;
- if (hexstr2bin(pos, oui, 4)) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
- os_free(wps);
- return -1;
- }
- wps->dev.oui = WPA_GET_BE32(oui);
- pos = os_strchr(pos, '-');
- if (pos == NULL) {
- wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
- os_free(wps);
- return -1;
- }
- pos++;
- wps->dev.sub_categ = atoi(pos);
+ wps->config_methods =
+ wps_config_methods_str2bin(hapd->conf->config_methods);
+ if (hapd->conf->device_type &&
+ wps_dev_type_str2bin(hapd->conf->device_type,
+ wps->dev.pri_dev_type) < 0) {
+ wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
+ os_free(wps);
+ return -1;
}
wps->dev.os_version = WPA_GET_BE32(hapd->conf->os_version);
wps->dev.rf_bands = hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211A ?
wps->network_key_len = conf->ssid.wep.len[0];
}
+ if (conf->ssid.wpa_psk) {
+ os_memcpy(wps->psk, conf->ssid.wpa_psk->psk, PMK_LEN);
+ wps->psk_set = 1;
+ }
+
if (conf->wps_state == WPS_STATE_NOT_CONFIGURED) {
/* Override parameters to enable security by default */
wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
#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 struct wpabuf *
-hostapd_rx_req_get_ap_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return NULL;
-}
-
-
-static int hostapd_rx_req_set_ap_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_del_ap_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static struct wpabuf *
-hostapd_rx_req_get_sta_settings(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return NULL;
-}
-
-
-static int hostapd_rx_req_set_sta_settings(void *priv,
- const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_del_sta_settings(void *priv,
- const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
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,
wpa_printf(MSG_DEBUG, "WPS UPnP: PutWLANResponse ev_type=%d mac_addr="
MACSTR, ev_type, MAC2STR(mac_addr));
- wpa_hexdump_ascii(MSG_MSGDUMP, "WPS UPnP: PutWLANResponse NewMessage",
- wpabuf_head(msg), wpabuf_len(msg));
+ wpa_hexdump(MSG_MSGDUMP, "WPS UPnP: PutWLANResponse NewMessage",
+ wpabuf_head(msg), wpabuf_len(msg));
if (ev_type != UPNP_WPS_WLANEVENT_TYPE_EAP) {
wpa_printf(MSG_DEBUG, "WPS UPnP: Ignored unexpected "
"PutWLANResponse WLANEventType %d", ev_type);
}
-static int hostapd_rx_req_set_selected_registrar(void *priv,
- const struct wpabuf *msg)
-{
- struct hostapd_data *hapd = priv;
- return wps_registrar_set_selected_registrar(hapd->wps->registrar, msg);
-}
-
-
-static int hostapd_rx_req_reboot_ap(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_reset_ap(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_reboot_sta(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
-static int hostapd_rx_req_reset_sta(void *priv, const struct wpabuf *msg)
-{
- wpa_printf(MSG_DEBUG, "WPS UPnP: TODO %s", __func__);
- return -1;
-}
-
-
static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
struct wps_context *wps)
{
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_get_ap_settings = hostapd_rx_req_get_ap_settings;
- ctx->rx_req_set_ap_settings = hostapd_rx_req_set_ap_settings;
- ctx->rx_req_del_ap_settings = hostapd_rx_req_del_ap_settings;
- 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_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;
- ctx->rx_req_reset_ap = hostapd_rx_req_reset_ap;
- ctx->rx_req_reboot_sta = hostapd_rx_req_reboot_sta;
- ctx->rx_req_reset_sta = hostapd_rx_req_reset_sta;
+ 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) {