aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2008-01-06 16:43:19 (GMT)
committerJouni Malinen <j@w1.fi>2008-01-06 16:43:19 (GMT)
commit627583bda727bbb482d1b4c278b356e48c714c53 (patch)
treed0c655cbfc88771b3b013493001ce870de0e6f43 /hostapd
parentdbc2d266b68c8eca3572e37ee123534ddf439485 (diff)
downloadhostap-history-627583bda727bbb482d1b4c278b356e48c714c53.zip
hostap-history-627583bda727bbb482d1b4c278b356e48c714c53.tar.gz
hostap-history-627583bda727bbb482d1b4c278b356e48c714c53.tar.bz2
Cleaned up hostapd_setup_bss() a bit by moving larger setup routines into
separate functions.
Diffstat (limited to 'hostapd')
-rw-r--r--hostapd/hostapd.c199
1 files changed, 115 insertions, 84 deletions
diff --git a/hostapd/hostapd.c b/hostapd/hostapd.c
index 1511ea8..90b3c6c 100644
--- a/hostapd/hostapd.c
+++ b/hostapd/hostapd.c
@@ -1074,6 +1074,113 @@ static int mac_in_conf(struct hostapd_config *conf, const void *a)
}
+static int hostapd_setup_wpa(struct hostapd_data *hapd)
+{
+ struct wpa_auth_config _conf;
+ struct wpa_auth_callbacks cb;
+ const u8 *wpa_ie;
+ size_t wpa_ie_len;
+
+ hostapd_wpa_auth_conf(hapd->conf, &_conf);
+ os_memset(&cb, 0, sizeof(cb));
+ cb.ctx = hapd;
+ cb.logger = hostapd_wpa_auth_logger;
+ cb.disconnect = hostapd_wpa_auth_disconnect;
+ cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
+ cb.set_eapol = hostapd_wpa_auth_set_eapol;
+ cb.get_eapol = hostapd_wpa_auth_get_eapol;
+ cb.get_psk = hostapd_wpa_auth_get_psk;
+ cb.get_msk = hostapd_wpa_auth_get_msk;
+ cb.set_key = hostapd_wpa_auth_set_key;
+ cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
+ cb.get_seqnum_igtk = hostapd_wpa_auth_get_seqnum_igtk;
+ cb.send_eapol = hostapd_wpa_auth_send_eapol;
+ cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
+ cb.send_ether = hostapd_wpa_auth_send_ether;
+#ifdef CONFIG_IEEE80211R
+ cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
+ cb.add_sta = hostapd_wpa_auth_add_sta;
+#endif /* CONFIG_IEEE80211R */
+ hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
+ if (hapd->wpa_auth == NULL) {
+ printf("WPA initialization failed.\n");
+ return -1;
+ }
+
+ if (hostapd_set_privacy(hapd, 1)) {
+ wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
+ "for interface %s", hapd->conf->iface);
+ return -1;
+ }
+
+ wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
+ if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
+ wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
+ "the kernel driver.");
+ return -1;
+ }
+
+ if (rsn_preauth_iface_init(hapd)) {
+ printf("Initialization of RSN pre-authentication "
+ "failed.\n");
+ return -1;
+ }
+
+ return 0;
+
+}
+
+
+static int hostapd_setup_radius_srv(struct hostapd_data *hapd,
+ struct hostapd_bss_config *conf)
+{
+ struct radius_server_conf srv;
+ os_memset(&srv, 0, sizeof(srv));
+ srv.client_file = conf->radius_server_clients;
+ srv.auth_port = conf->radius_server_auth_port;
+ srv.conf_ctx = conf;
+ srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
+ srv.ssl_ctx = hapd->ssl_ctx;
+ srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
+ srv.eap_fast_a_id = conf->eap_fast_a_id;
+ srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
+ srv.wps_registrar = hapd->wps_registrar;
+ srv.ipv6 = conf->radius_server_ipv6;
+ srv.get_eap_user = hostapd_radius_get_eap_user;
+
+ hapd->radius_srv = radius_server_init(&srv);
+ if (hapd->radius_srv == NULL) {
+ printf("RADIUS server initialization failed.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+#ifdef CONFIG_WPS
+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;
+
+ 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
@@ -1195,57 +1302,8 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
return -1;
}
- if (hapd->conf->wpa) {
- struct wpa_auth_config _conf;
- struct wpa_auth_callbacks cb;
- const u8 *wpa_ie;
- size_t wpa_ie_len;
-
- hostapd_wpa_auth_conf(hapd->conf, &_conf);
- os_memset(&cb, 0, sizeof(cb));
- cb.ctx = hapd;
- cb.logger = hostapd_wpa_auth_logger;
- cb.disconnect = hostapd_wpa_auth_disconnect;
- cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
- cb.set_eapol = hostapd_wpa_auth_set_eapol;
- cb.get_eapol = hostapd_wpa_auth_get_eapol;
- cb.get_psk = hostapd_wpa_auth_get_psk;
- cb.get_msk = hostapd_wpa_auth_get_msk;
- cb.set_key = hostapd_wpa_auth_set_key;
- cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
- cb.get_seqnum_igtk = hostapd_wpa_auth_get_seqnum_igtk;
- cb.send_eapol = hostapd_wpa_auth_send_eapol;
- cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
- cb.send_ether = hostapd_wpa_auth_send_ether;
-#ifdef CONFIG_IEEE80211R
- cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
- cb.add_sta = hostapd_wpa_auth_add_sta;
-#endif /* CONFIG_IEEE80211R */
- hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
- if (hapd->wpa_auth == NULL) {
- printf("WPA initialization failed.\n");
- return -1;
- }
-
- if (hostapd_set_privacy(hapd, 1)) {
- wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
- "for interface %s", hapd->conf->iface);
- return -1;
- }
-
- wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
- if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
- wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
- "the kernel driver.");
- return -1;
- }
-
- if (rsn_preauth_iface_init(hapd)) {
- printf("Initialization of RSN pre-authentication "
- "failed.\n");
- return -1;
- }
- }
+ if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
+ return -1;
if (accounting_init(hapd)) {
printf("Accounting initialization failed.\n");
@@ -1281,41 +1339,14 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
#endif /* CONFIG_IEEE80211R */
#ifdef CONFIG_WPS
- if (hapd->conf->wps_state) {
- 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;
- hapd->wps_registrar = wps_registrar_init(&cfg);
- if (hapd->wps_registrar == NULL) {
- printf("Failed to initialize WPS Registrar\n");
- return -1;
- }
- }
+ if (hapd->conf->wps_state &&
+ hostapd_setup_wps(hapd, conf))
+ return -1;
#endif /* CONFIG_WPS */
- if (conf->radius_server_clients) {
- struct radius_server_conf srv;
- os_memset(&srv, 0, sizeof(srv));
- srv.client_file = conf->radius_server_clients;
- srv.auth_port = conf->radius_server_auth_port;
- srv.conf_ctx = conf;
- srv.eap_sim_db_priv = hapd->eap_sim_db_priv;
- srv.ssl_ctx = hapd->ssl_ctx;
- srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
- srv.eap_fast_a_id = conf->eap_fast_a_id;
- srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
- srv.wps_registrar = hapd->wps_registrar;
- srv.ipv6 = conf->radius_server_ipv6;
- srv.get_eap_user = hostapd_radius_get_eap_user;
- hapd->radius_srv = radius_server_init(&srv);
- if (hapd->radius_srv == NULL) {
- printf("RADIUS server initialization failed.\n");
- return -1;
- }
- }
+ if (conf->radius_server_clients &&
+ hostapd_setup_radius_srv(hapd, conf))
+ return -1;
return 0;
}