aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2008-01-06 18:21:23 (GMT)
committerJouni Malinen <j@w1.fi>2008-01-06 18:21:23 (GMT)
commit9964ef2b6aeff0d82c749cabb11c67f10df3e0e7 (patch)
treea2e80580076b3a00eaa9bac531dc711b811206c6
parenta0859cdf79cb99e866f72ba7b40ae49db9c69a91 (diff)
downloadhostap-history-9964ef2b6aeff0d82c749cabb11c67f10df3e0e7.zip
hostap-history-9964ef2b6aeff0d82c749cabb11c67f10df3e0e7.tar.gz
hostap-history-9964ef2b6aeff0d82c749cabb11c67f10df3e0e7.tar.bz2
Moved hostapd WPS integration code into a new file (wps_hostapd.c)
-rw-r--r--hostapd/Makefile1
-rw-r--r--hostapd/hostapd.c135
-rw-r--r--hostapd/wps_hostapd.c150
-rw-r--r--hostapd/wps_hostapd.h38
4 files changed, 192 insertions, 132 deletions
diff --git a/hostapd/Makefile b/hostapd/Makefile
index 340faed..ec73300 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -253,6 +253,7 @@ endif
ifdef CONFIG_WPS
CFLAGS += -DCONFIG_WPS -DEAP_WSC
OBJS += ../src/utils/uuid.o
+OBJS += wps_hostapd.o
OBJS += ../src/eap_server/eap_wsc.o ../src/eap_common/eap_wsc_common.o
OBJS += ../src/wps/wps.o
OBJS += ../src/wps/wps_common.o
diff --git a/hostapd/hostapd.c b/hostapd/hostapd.c
index 79391bd..ea07f26 100644
--- a/hostapd/hostapd.c
+++ b/hostapd/hostapd.c
@@ -43,8 +43,7 @@
#include "eap_server/eap.h"
#include "version.h"
#include "l2_packet/l2_packet.h"
-#include "wps/wps.h"
-#include "wps/wps_defs.h"
+#include "wps_hostapd.h"
static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
@@ -584,9 +583,7 @@ static void hostapd_cleanup(struct hostapd_data *hapd)
l2_packet_deinit(hapd->l2);
#endif /* CONFIG_IEEE80211R */
-#ifdef CONFIG_WPS
- wps_registrar_deinit(hapd->wps_registrar);
-#endif /* CONFIG_WPS */
+ hostapd_deinit_wps(hapd);
hostapd_wireless_event_deinit(hapd);
@@ -1159,129 +1156,6 @@ static int hostapd_setup_radius_srv(struct hostapd_data *hapd,
}
-#ifdef CONFIG_WPS
-static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
- size_t psk_len)
-{
- struct hostapd_data *hapd = ctx;
- struct hostapd_wpa_psk *p;
- struct hostapd_ssid *ssid = &hapd->conf->ssid;
-
- wpa_printf(MSG_DEBUG, "Received new WPA/WPA2-PSK from WPS for STA "
- MACSTR, MAC2STR(mac_addr));
- wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
-
- if (psk_len != PMK_LEN) {
- wpa_printf(MSG_DEBUG, "Unexpected PSK length %d", psk_len);
- return -1;
- }
-
- /* Add the new PSK to runtime PSK list */
- p = os_zalloc(sizeof(*p));
- if (p == NULL)
- return -1;
- os_memcpy(p->addr, mac_addr, ETH_ALEN);
- os_memcpy(p->psk, psk, PMK_LEN);
-
- p->next = ssid->wpa_psk;
- ssid->wpa_psk = p;
-
- if (ssid->wpa_psk_file) {
- FILE *f;
- char hex[PMK_LEN * 2 + 1];
- /* Add the new PSK to PSK list file */
- f = fopen(ssid->wpa_psk_file, "a");
- if (f == NULL) {
- wpa_printf(MSG_DEBUG, "Failed to add the PSK to "
- "'%s'", ssid->wpa_psk_file);
- return -1;
- }
-
- wpa_snprintf_hex(hex, sizeof(hex), psk, psk_len);
- fprintf(f, MACSTR " %s\n", MAC2STR(mac_addr), hex);
- fclose(f);
- }
-
- return 0;
-}
-
-
-static int hostapd_setup_wps(struct hostapd_data *hapd,
- struct hostapd_bss_config *conf)
-{
- struct wps_registrar_config cfg;
-
- os_memset(&cfg, 0, sizeof(cfg));
- cfg.wps_state = hapd->conf->wps_state;
- cfg.uuid = hapd->conf->uuid;
- cfg.ssid = (const u8 *) hapd->conf->ssid.ssid;
- cfg.ssid_len = hapd->conf->ssid.ssid_len;
-
- if (conf->wpa & WPA_PROTO_RSN) {
- if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
- cfg.auth_types |= WPS_AUTH_WPA2PSK;
- if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
- cfg.auth_types |= WPS_AUTH_WPA2;
-
- if (conf->rsn_pairwise & WPA_CIPHER_CCMP)
- cfg.encr_types |= WPS_ENCR_AES;
- if (conf->rsn_pairwise & WPA_CIPHER_TKIP)
- cfg.encr_types |= WPS_ENCR_TKIP;
- }
-
- if (conf->wpa & WPA_PROTO_WPA) {
- if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
- cfg.auth_types |= WPS_AUTH_WPAPSK;
- if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
- cfg.auth_types |= WPS_AUTH_WPA;
-
- if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
- cfg.encr_types |= WPS_ENCR_AES;
- if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
- cfg.encr_types |= WPS_ENCR_TKIP;
- }
-
- if (conf->ssid.security_policy == SECURITY_PLAINTEXT) {
- cfg.encr_types |= WPS_ENCR_NONE;
- cfg.auth_types |= WPS_AUTH_OPEN;
- } else if (conf->ssid.security_policy == SECURITY_STATIC_WEP) {
- cfg.encr_types |= WPS_ENCR_WEP;
- if (conf->auth_algs & WPA_AUTH_ALG_OPEN)
- cfg.auth_types |= WPS_AUTH_OPEN;
- if (conf->auth_algs & WPA_AUTH_ALG_SHARED)
- cfg.auth_types |= WPS_AUTH_SHARED;
- } else if (conf->ssid.security_policy == SECURITY_IEEE_802_1X) {
- cfg.auth_types |= WPS_AUTH_OPEN;
- if (conf->default_wep_key_len)
- cfg.encr_types |= WPS_ENCR_WEP;
- else
- cfg.encr_types |= WPS_ENCR_NONE;
- }
-
- if (conf->ssid.wpa_psk_file) {
- /* Use per-device PSKs */
- } else if (conf->ssid.wpa_psk) {
- cfg.network_key = conf->ssid.wpa_psk->psk;
- cfg.network_key_len = PMK_LEN;
- } else if (conf->ssid.wep.keys_set && conf->ssid.wep.key[0]) {
- cfg.network_key = conf->ssid.wep.key[0];
- cfg.network_key_len = conf->ssid.wep.len[0];
- }
-
- cfg.new_psk_cb = hostapd_wps_new_psk_cb;
- cfg.cb_ctx = hapd;
-
- hapd->wps_registrar = wps_registrar_init(&cfg);
- if (hapd->wps_registrar == NULL) {
- printf("Failed to initialize WPS Registrar\n");
- return -1;
- }
-
- return 0;
-}
-#endif /* CONFIG_WPS */
-
-
/**
* hostapd_setup_bss - Per-BSS setup (initialization)
* @hapd: Pointer to BSS data
@@ -1439,11 +1313,8 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
}
#endif /* CONFIG_IEEE80211R */
-#ifdef CONFIG_WPS
- if (hapd->conf->wps_state &&
- hostapd_setup_wps(hapd, conf))
+ if (hostapd_init_wps(hapd, conf))
return -1;
-#endif /* CONFIG_WPS */
if (conf->radius_server_clients &&
hostapd_setup_radius_srv(hapd, conf))
diff --git a/hostapd/wps_hostapd.c b/hostapd/wps_hostapd.c
new file mode 100644
index 0000000..5d6b2a9
--- /dev/null
+++ b/hostapd/wps_hostapd.c
@@ -0,0 +1,150 @@
+/*
+ * hostapd / WPS integration
+ * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "hostapd.h"
+#include "wps/wps.h"
+#include "wps/wps_defs.h"
+#include "wps_hostapd.h"
+
+
+static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
+ size_t psk_len)
+{
+ struct hostapd_data *hapd = ctx;
+ struct hostapd_wpa_psk *p;
+ struct hostapd_ssid *ssid = &hapd->conf->ssid;
+
+ wpa_printf(MSG_DEBUG, "Received new WPA/WPA2-PSK from WPS for STA "
+ MACSTR, MAC2STR(mac_addr));
+ wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
+
+ if (psk_len != PMK_LEN) {
+ wpa_printf(MSG_DEBUG, "Unexpected PSK length %d", psk_len);
+ return -1;
+ }
+
+ /* Add the new PSK to runtime PSK list */
+ p = os_zalloc(sizeof(*p));
+ if (p == NULL)
+ return -1;
+ os_memcpy(p->addr, mac_addr, ETH_ALEN);
+ os_memcpy(p->psk, psk, PMK_LEN);
+
+ p->next = ssid->wpa_psk;
+ ssid->wpa_psk = p;
+
+ if (ssid->wpa_psk_file) {
+ FILE *f;
+ char hex[PMK_LEN * 2 + 1];
+ /* Add the new PSK to PSK list file */
+ f = fopen(ssid->wpa_psk_file, "a");
+ if (f == NULL) {
+ wpa_printf(MSG_DEBUG, "Failed to add the PSK to "
+ "'%s'", ssid->wpa_psk_file);
+ return -1;
+ }
+
+ wpa_snprintf_hex(hex, sizeof(hex), psk, psk_len);
+ fprintf(f, MACSTR " %s\n", MAC2STR(mac_addr), hex);
+ fclose(f);
+ }
+
+ return 0;
+}
+
+
+int hostapd_init_wps(struct hostapd_data *hapd,
+ struct hostapd_bss_config *conf)
+{
+ struct wps_registrar_config cfg;
+
+ if (conf->wps_state == 0)
+ return 0;
+
+ os_memset(&cfg, 0, sizeof(cfg));
+ cfg.wps_state = hapd->conf->wps_state;
+ cfg.uuid = hapd->conf->uuid;
+ cfg.ssid = (const u8 *) hapd->conf->ssid.ssid;
+ cfg.ssid_len = hapd->conf->ssid.ssid_len;
+
+ if (conf->wpa & WPA_PROTO_RSN) {
+ if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
+ cfg.auth_types |= WPS_AUTH_WPA2PSK;
+ if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
+ cfg.auth_types |= WPS_AUTH_WPA2;
+
+ if (conf->rsn_pairwise & WPA_CIPHER_CCMP)
+ cfg.encr_types |= WPS_ENCR_AES;
+ if (conf->rsn_pairwise & WPA_CIPHER_TKIP)
+ cfg.encr_types |= WPS_ENCR_TKIP;
+ }
+
+ if (conf->wpa & WPA_PROTO_WPA) {
+ if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
+ cfg.auth_types |= WPS_AUTH_WPAPSK;
+ if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
+ cfg.auth_types |= WPS_AUTH_WPA;
+
+ if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
+ cfg.encr_types |= WPS_ENCR_AES;
+ if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
+ cfg.encr_types |= WPS_ENCR_TKIP;
+ }
+
+ if (conf->ssid.security_policy == SECURITY_PLAINTEXT) {
+ cfg.encr_types |= WPS_ENCR_NONE;
+ cfg.auth_types |= WPS_AUTH_OPEN;
+ } else if (conf->ssid.security_policy == SECURITY_STATIC_WEP) {
+ cfg.encr_types |= WPS_ENCR_WEP;
+ if (conf->auth_algs & WPA_AUTH_ALG_OPEN)
+ cfg.auth_types |= WPS_AUTH_OPEN;
+ if (conf->auth_algs & WPA_AUTH_ALG_SHARED)
+ cfg.auth_types |= WPS_AUTH_SHARED;
+ } else if (conf->ssid.security_policy == SECURITY_IEEE_802_1X) {
+ cfg.auth_types |= WPS_AUTH_OPEN;
+ if (conf->default_wep_key_len)
+ cfg.encr_types |= WPS_ENCR_WEP;
+ else
+ cfg.encr_types |= WPS_ENCR_NONE;
+ }
+
+ if (conf->ssid.wpa_psk_file) {
+ /* Use per-device PSKs */
+ } else if (conf->ssid.wpa_psk) {
+ cfg.network_key = conf->ssid.wpa_psk->psk;
+ cfg.network_key_len = PMK_LEN;
+ } else if (conf->ssid.wep.keys_set && conf->ssid.wep.key[0]) {
+ cfg.network_key = conf->ssid.wep.key[0];
+ cfg.network_key_len = conf->ssid.wep.len[0];
+ }
+
+ cfg.new_psk_cb = hostapd_wps_new_psk_cb;
+ cfg.cb_ctx = hapd;
+
+ hapd->wps_registrar = wps_registrar_init(&cfg);
+ if (hapd->wps_registrar == NULL) {
+ printf("Failed to initialize WPS Registrar\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+void hostapd_deinit_wps(struct hostapd_data *hapd)
+{
+ wps_registrar_deinit(hapd->wps_registrar);
+}
diff --git a/hostapd/wps_hostapd.h b/hostapd/wps_hostapd.h
new file mode 100644
index 0000000..02d8a70
--- /dev/null
+++ b/hostapd/wps_hostapd.h
@@ -0,0 +1,38 @@
+/*
+ * hostapd / WPS integration
+ * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef WPS_HOSTAPD_H
+#define WPS_HOSTAPD_H
+
+#ifdef CONFIG_WPS
+
+int hostapd_init_wps(struct hostapd_data *hapd,
+ struct hostapd_bss_config *conf);
+void hostapd_deinit_wps(struct hostapd_data *hapd);
+
+#else /* CONFIG_WPS */
+
+static inline int hostapd_init_wps(struct hostapd_data *hapd,
+ struct hostapd_bss_config *conf)
+{
+ return 0;
+}
+
+static inline void hostapd_deinit_wps(struct hostapd_data *hapd)
+{
+}
+
+#endif /* CONFIG_WPS */
+
+#endif /* WPS_HOSTAPD_H */