static int hostapd_setup_interface(hostapd *hapd) { if (hostapd_driver_init(hapd)) { printf("Host AP driver initialization failed.\n"); return -1; } printf("Using interface %sap with hwaddr " MACSTR " and ssid '%s'\n", hapd->conf->iface, MAC2STR(hapd->own_addr), hapd->conf->ssid); /* Set SSID for the kernel driver (to be used in beacon and probe * response frames) */ if (hostap_ioctl_setiwessid(hapd->driver.data, hapd->conf->ssid, hapd->conf->ssid_len)) { printf("Could not set SSID for kernel driver\n"); return -1; } if (radius_client_init(hapd)) { printf("RADIUS client initialization failed.\n"); return -1; } if (hostapd_acl_init(hapd)) { printf("ACL initialization failed.\n"); return -1; } if (ieee802_1x_init(hapd)) { printf("IEEE 802.1X initialization failed.\n"); return -1; } if (hapd->conf->wpa && wpa_init(hapd)) { printf("WPA initialization failed.\n"); return -1; } if (accounting_init(hapd)) { printf("Accounting initialization failed.\n"); return -1; } if (hapd->conf->ieee802_11f && iapp_init(hapd)) { printf("IEEE 802.11f (IAPP) initialization failed.\n"); return -1; } if (hostapd_wireless_event_init(hapd->driver.data) < 0) return -1; if (hapd->default_wep_key && hostapd_setup_encryption(hapd)) return -1; if (hostapd_flush_old_stations(hapd)) return -1; return 0; }
int hostapd_reload_config(struct hostapd_iface *iface) { struct hostapd_data *hapd = iface->bss[0]; struct hostapd_config *newconf, *oldconf; size_t j; if (iface->interfaces == NULL || iface->interfaces->config_read_cb == NULL) return -1; newconf = iface->interfaces->config_read_cb(iface->config_fname); if (newconf == NULL) return -1; /* * Deauthenticate all stations since the new configuration may not * allow them to use the BSS anymore. */ for (j = 0; j < iface->num_bss; j++) { hostapd_flush_old_stations(iface->bss[j], WLAN_REASON_PREV_AUTH_NOT_VALID); hostapd_broadcast_wep_clear(iface->bss[j]); #ifndef CONFIG_NO_RADIUS /* TODO: update dynamic data based on changed configuration * items (e.g., open/close sockets, etc.) */ radius_client_flush(iface->bss[j]->radius, 0); #endif /* CONFIG_NO_RADIUS */ } oldconf = hapd->iconf; iface->conf = newconf; hostapd_select_hw_mode(iface); iface->freq = hostapd_hw_get_freq(hapd, newconf->channel); if (hostapd_set_freq(hapd, newconf->hw_mode, iface->freq, newconf->channel, newconf->ieee80211n, newconf->secondary_channel)) { wpa_printf(MSG_ERROR, "Could not set channel for " "kernel driver"); } if (iface->current_mode) hostapd_prepare_rates(iface, iface->current_mode); for (j = 0; j < iface->num_bss; j++) { hapd = iface->bss[j]; hapd->iconf = newconf; hapd->conf = &newconf->bss[j]; hostapd_reload_bss(hapd); } hostapd_config_free(oldconf); return 0; }
int hostapd_reload_config(struct hostapd_iface *iface) { struct hostapd_data *hapd = iface->bss[0]; struct hostapd_config *newconf, *oldconf; size_t j; if (iface->config_read_cb == NULL) return -1; newconf = iface->config_read_cb(iface->config_fname); if (newconf == NULL) return -1; /* * Deauthenticate all stations since the new configuration may not * allow them to use the BSS anymore. */ for (j = 0; j < iface->num_bss; j++) { hostapd_flush_old_stations(iface->bss[j], WLAN_REASON_PREV_AUTH_NOT_VALID); hostapd_broadcast_wep_clear(iface->bss[j]); #ifndef CONFIG_NO_RADIUS /* TODO: update dynamic data based on changed configuration * items (e.g., open/close sockets, etc.) */ radius_client_flush(iface->bss[j]->radius, 0); #endif /* CONFIG_NO_RADIUS */ } oldconf = hapd->iconf; iface->conf = newconf; for (j = 0; j < iface->num_bss; j++) { hapd = iface->bss[j]; hapd->iconf = newconf; hapd->conf = &newconf->bss[j]; hostapd_reload_bss(hapd); } hostapd_config_free(oldconf); return 0; }
static void hostapd_clear_old(struct hostapd_iface *iface) { size_t j; /* * Deauthenticate all stations since the new configuration may not * allow them to use the BSS anymore. */ for (j = 0; j < iface->num_bss; j++) { hostapd_flush_old_stations(iface->bss[j], WLAN_REASON_PREV_AUTH_NOT_VALID); hostapd_broadcast_wep_clear(iface->bss[j]); #ifndef CONFIG_NO_RADIUS /* TODO: update dynamic data based on changed configuration * items (e.g., open/close sockets, etc.) */ radius_client_flush(iface->bss[j]->radius, 0); #endif /* CONFIG_NO_RADIUS */ } }
int main(int argc, char *argv[]) { struct hapd_interfaces interfaces; int ret = 1, i, j; int c, debug = 0, daemonize = 0; for (;;) { c = getopt(argc, argv, "Bdh"); if (c < 0) break; switch (c) { case 'h': usage(); break; case 'd': debug++; break; case 'B': daemonize++; break; default: usage(); break; } } if (optind == argc) usage(); interfaces.count = argc - optind; interfaces.hapd = malloc(interfaces.count * sizeof(hostapd *)); if (interfaces.hapd == NULL) { printf("malloc failed\n"); exit(1); } eloop_init(&interfaces); eloop_register_signal(SIGHUP, handle_reload, NULL); eloop_register_signal(SIGINT, handle_term, NULL); eloop_register_signal(SIGTERM, handle_term, NULL); eloop_register_signal(SIGUSR1, handle_dump_state, NULL); for (i = 0; i < interfaces.count; i++) { printf("Configuration file: %s\n", argv[optind + i]); interfaces.hapd[i] = hostapd_init(argv[optind + i]); if (!interfaces.hapd[i]) goto out; for (j = 0; j < debug; j++) { if (interfaces.hapd[i]->conf->logger_stdout_level > 0) interfaces.hapd[i]->conf-> logger_stdout_level--; interfaces.hapd[i]->conf->debug++; } hostapd_set_broadcast_wep(interfaces.hapd[i]); if (hostapd_setup_interface(interfaces.hapd[i])) goto out; } if (daemonize && daemon(0, 0)) { perror("daemon"); goto out; } openlog("hostapd", 0, LOG_DAEMON); eloop_run(); for (i = 0; i < interfaces.count; i++) { hostapd_free_stas(interfaces.hapd[i]); hostapd_flush_old_stations(interfaces.hapd[i]); } ret = 0; out: for (i = 0; i < interfaces.count; i++) { if (!interfaces.hapd[i]) continue; hostapd_cleanup(interfaces.hapd[i]); free(interfaces.hapd[i]); } free(interfaces.hapd); eloop_destroy(); closelog(); return ret; }
static int hostapd_setup_interface(struct hostapd_data *hapd) { struct hostapd_config *conf = hapd->conf; u8 ssid[HOSTAPD_SSID_LEN + 1]; int ssid_len, set_ssid; int ret = 0; if (hostapd_driver_init(hapd)) { printf("%s driver initialization failed.\n", hapd->driver ? hapd->driver->name : "Unknown"); hapd->driver = NULL; return -1; } /* * Fetch the SSID from the system and use it or, * if one was specified in the config file, verify they * match. */ ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid)); if (ssid_len < 0) { printf("Could not read SSID from system\n"); return -1; } if (conf->ssid_set) { /* * If SSID is specified in the config file and it differs * from what is being used then force installation of the * new SSID. */ set_ssid = (conf->ssid_len != ssid_len || memcmp(conf->ssid, ssid, ssid_len) != 0); } else { /* * No SSID in the config file; just use the one we got * from the system. */ set_ssid = 0; conf->ssid_len = ssid_len; memcpy(conf->ssid, ssid, conf->ssid_len); conf->ssid[conf->ssid_len] = '\0'; } printf("Using interface %s with hwaddr " MACSTR " and ssid '%s'\n", hapd->conf->iface, MAC2STR(hapd->own_addr), hapd->conf->ssid); if (hostapd_setup_wpa_psk(conf)) { printf("WPA-PSK setup failed.\n"); return -1; } /* Set SSID for the kernel driver (to be used in beacon and probe * response frames) */ if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid, conf->ssid_len)) { printf("Could not set SSID for kernel driver\n"); return -1; } if (HOSTAPD_DEBUG_COND(HOSTAPD_DEBUG_MSGDUMPS)) conf->radius->msg_dumps = 1; hapd->radius = radius_client_init(hapd, conf->radius); if (hapd->radius == NULL) { printf("RADIUS client initialization failed.\n"); return -1; } if (conf->radius_server_clients) { struct radius_server_conf srv; memset(&srv, 0, sizeof(srv)); srv.client_file = conf->radius_server_clients; srv.auth_port = conf->radius_server_auth_port; srv.hostapd_conf = conf; srv.eap_sim_db_priv = hapd->eap_sim_db_priv; srv.ssl_ctx = hapd->ssl_ctx; srv.ipv6 = conf->radius_server_ipv6; hapd->radius_srv = radius_server_init(&srv); if (hapd->radius_srv == NULL) { printf("RADIUS server initialization failed.\n"); return -1; } } if (hostapd_acl_init(hapd)) { printf("ACL initialization failed.\n"); return -1; } if (ieee802_1x_init(hapd)) { printf("IEEE 802.1X initialization failed.\n"); return -1; } if (hapd->conf->wpa && wpa_init(hapd)) { printf("WPA initialization failed.\n"); return -1; } #ifdef SIMPLE_CONFIG if (wsc_ie_init(hapd) < 0) { printf("WSC IE initialization failed.\n"); return -1; } #endif if (accounting_init(hapd)) { printf("Accounting initialization failed.\n"); return -1; } if (hapd->conf->ieee802_11f && (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) { printf("IEEE 802.11F (IAPP) initialization failed.\n"); return -1; } if (hostapd_wireless_event_init(hapd) < 0) return -1; if (hostapd_flush_old_stations(hapd)) return -1; if (hostapd_ctrl_iface_init(hapd)) { printf("Failed to setup control interface\n"); ret = -1; } return ret; }
int main(int argc, char *argv[]) { struct hapd_interfaces interfaces; int ret = 1, i, j; int c, debug = 0, daemonize = 0; #ifdef JUMPSTART char *js_passwd = NULL; #endif for (;;) { c = getopt(argc, argv, "BdhKtvj:"); if (c < 0) break; switch (c) { case 'h': usage(); break; case 'd': debug++; break; case 'B': daemonize++; break; case 'K': wpa_debug_show_keys++; break; case 't': wpa_debug_timestamp++; break; case 'v': show_version(); exit(1); break; #ifdef JUMPSTART case 'j': js_passwd = optarg; break; #endif default: usage(); break; } } if (optind == argc) usage(); register_drivers(); /* NB: generated by Makefile */ interfaces.count = argc - optind; interfaces.hapd = malloc(interfaces.count * sizeof(hostapd *)); if (interfaces.hapd == NULL) { printf("malloc failed\n"); exit(1); } eloop_init(&interfaces); eloop_register_signal(SIGHUP, handle_reload, NULL); eloop_register_signal(SIGINT, handle_term, NULL); eloop_register_signal(SIGTERM, handle_term, NULL); eloop_register_signal(SIGUSR1, handle_dump_state, NULL); for (i = 0; i < interfaces.count; i++) { printf("Configuration file: %s\n", argv[optind + i]); #ifdef JUMPSTART interfaces.hapd[i] = hostapd_init(argv[optind + i], js_passwd); #else interfaces.hapd[i] = hostapd_init(argv[optind + i]); #endif if (!interfaces.hapd[i]) goto out; for (j = 0; j < debug; j++) { if (interfaces.hapd[i]->conf->logger_stdout_level > 0) interfaces.hapd[i]->conf-> logger_stdout_level--; interfaces.hapd[i]->conf->debug++; } if (hostapd_setup_interface(interfaces.hapd[i])) goto out; wpa_debug_level -= interfaces.hapd[0]->conf->debug; } if (daemonize && daemon(0, 0)) { perror("daemon"); goto out; } openlog("hostapd", 0, LOG_DAEMON); eloop_run(); for (i = 0; i < interfaces.count; i++) { hostapd_free_stas(interfaces.hapd[i]); hostapd_flush_old_stations(interfaces.hapd[i]); } ret = 0; out: for (i = 0; i < interfaces.count; i++) { if (!interfaces.hapd[i]) continue; hostapd_cleanup(interfaces.hapd[i]); free(interfaces.hapd[i]); } free(interfaces.hapd); eloop_destroy(); closelog(); driver_unregister_all(); return ret; }