static void wpa_init_conf(struct wpa_supplicant *wpa_s, const char *authsrv, const char *secret) { struct hostapd_radius_server *as; int res; wpa_s->bssid[5] = 1; wpa_s->own_addr[5] = 2; wpa_s->own_ip_addr.s_addr = htonl((127 << 24) | 1); wpa_s->num_auth_servers = 1; as = malloc(sizeof(struct hostapd_radius_server)); assert(as != NULL); inet_aton(authsrv, &as->addr); as->port = 1812; as->shared_secret = strdup(secret); as->shared_secret_len = strlen(secret); wpa_s->auth_server = wpa_s->auth_servers = as; res = radius_client_init(wpa_s); assert(res == 0); res = radius_client_register(wpa_s, RADIUS_AUTH, ieee802_1x_receive_auth, NULL); assert(res == 0); }
int main(int argc, char *argv[]) { struct radius_ctx ctx; struct hostapd_radius_server *srv; if (os_program_init()) return -1; hostapd_logger_register_cb(hostapd_logger_cb); os_memset(&ctx, 0, sizeof(ctx)); inet_aton("127.0.0.1", &ctx.own_ip_addr); if (eloop_init()) { printf("Failed to initialize event loop\n"); return -1; } srv = os_zalloc(sizeof(*srv)); if (srv == NULL) return -1; srv->addr.af = AF_INET; srv->port = 1812; if (hostapd_parse_ip_addr("127.0.0.1", &srv->addr) < 0) { printf("Failed to parse IP address\n"); return -1; } srv->shared_secret = (u8 *) os_strdup("radius"); srv->shared_secret_len = 6; ctx.conf.auth_server = ctx.conf.auth_servers = srv; ctx.conf.num_auth_servers = 1; ctx.conf.msg_dumps = 1; ctx.radius = radius_client_init(&ctx, &ctx.conf); if (ctx.radius == NULL) { printf("Failed to initialize RADIUS client\n"); return -1; } if (radius_client_register(ctx.radius, RADIUS_AUTH, receive_auth, &ctx) < 0) { printf("Failed to register RADIUS authentication handler\n"); return -1; } eloop_register_timeout(0, 0, start_example, &ctx, NULL); eloop_run(); radius_client_deinit(ctx.radius); os_free(srv->shared_secret); os_free(srv); eloop_destroy(); os_program_deinit(); return 0; }
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; }
static void wpa_init_conf(struct eapol_test_data *e, struct wpa_supplicant *wpa_s, const char *authsrv, int port, const char *secret, const char *cli_addr) { struct hostapd_radius_server *as; int res; wpa_s->bssid[5] = 1; os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN); e->own_ip_addr.s_addr = htonl((127 << 24) | 1); os_strlcpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname)); e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers)); assert(e->radius_conf != NULL); e->radius_conf->num_auth_servers = 1; as = os_zalloc(sizeof(struct hostapd_radius_server)); assert(as != NULL); #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA) { int a[4]; u8 *pos; sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]); pos = (u8 *) &as->addr.u.v4; *pos++ = a[0]; *pos++ = a[1]; *pos++ = a[2]; *pos++ = a[3]; } #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */ inet_aton(authsrv, &as->addr.u.v4); #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */ as->addr.af = AF_INET; as->port = port; as->shared_secret = (u8 *) os_strdup(secret); as->shared_secret_len = os_strlen(secret); e->radius_conf->auth_server = as; e->radius_conf->auth_servers = as; e->radius_conf->msg_dumps = 1; if (cli_addr) { if (hostapd_parse_ip_addr(cli_addr, &e->radius_conf->client_addr) == 0) e->radius_conf->force_client_addr = 1; else { wpa_printf(MSG_ERROR, "Invalid IP address '%s'", cli_addr); assert(0); } } e->radius = radius_client_init(wpa_s, e->radius_conf); assert(e->radius != NULL); res = radius_client_register(e->radius, RADIUS_AUTH, ieee802_1x_receive_auth, e); assert(res == 0); }
static void wpa_init_conf(struct eapol_test_data *e, struct wpa_supplicant *wpa_s, const char *authsrv, int port, const char *secret) { struct hostapd_radius_server *as; int res; wpa_s->bssid[5] = 1; wpa_s->own_addr[5] = 2; e->own_ip_addr.s_addr = htonl((127 << 24) | 1); strncpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname)); e->radius_conf = malloc(sizeof(struct hostapd_radius_servers)); assert(e->radius_conf != NULL); memset(e->radius_conf, 0, sizeof(struct hostapd_radius_servers)); e->radius_conf->num_auth_servers = 1; as = malloc(sizeof(struct hostapd_radius_server)); assert(as != NULL); memset(as, 0, sizeof(*as)); #ifdef CONFIG_NATIVE_WINDOWS { int a[4]; u8 *pos; sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]); pos = (u8 *) &as->addr.u.v4; *pos++ = a[0]; *pos++ = a[1]; *pos++ = a[2]; *pos++ = a[3]; } #else /* CONFIG_NATIVE_WINDOWS */ inet_aton(authsrv, &as->addr.u.v4); #endif /* CONFIG_NATIVE_WINDOWS */ as->addr.af = AF_INET; as->port = port; as->shared_secret = (u8 *) strdup(secret); as->shared_secret_len = strlen(secret); e->radius_conf->auth_server = as; e->radius_conf->auth_servers = as; e->radius_conf->msg_dumps = 1; e->radius = radius_client_init(wpa_s, e->radius_conf); assert(e->radius != NULL); res = radius_client_register(e->radius, RADIUS_AUTH, ieee802_1x_receive_auth, e); assert(res == 0); }
struct radius_client_data * radius_client_reconfig(struct radius_client_data *old, void *ctx, struct hostapd_radius_servers *oldconf, struct hostapd_radius_servers *newconf) { radius_client_flush(old, 0); if (newconf->retry_primary_interval != oldconf->retry_primary_interval || newconf->num_auth_servers != oldconf->num_auth_servers || newconf->num_acct_servers != oldconf->num_acct_servers || radius_servers_diff(newconf->auth_servers, oldconf->auth_servers, newconf->num_auth_servers) || radius_servers_diff(newconf->acct_servers, oldconf->acct_servers, newconf->num_acct_servers)) { hostapd_logger(ctx, NULL, HOSTAPD_MODULE_RADIUS, HOSTAPD_LEVEL_DEBUG, "Reconfiguring RADIUS client"); radius_client_deinit(old); return radius_client_init(ctx, newconf); } return old; }
static int hostapd_setup_bss_dynamically(struct hostapd_data *hapd) { struct hostapd_bss_config *conf = hapd->conf; if (conf->wmm_enabled < 0) conf->wmm_enabled = hapd->iconf->ieee80211n; if (hostapd_setup_wpa_psk(conf)) { wpa_printf(MSG_ERROR, "WPA-PSK setup failed."); return -1; } if (wpa_debug_level == MSG_MSGDUMP) conf->radius->msg_dumps = 1; #ifndef CONFIG_NO_RADIUS hapd->radius = radius_client_init(hapd, conf->radius); if (hapd->radius == NULL) { wpa_printf(MSG_ERROR, "RADIUS client initialization failed."); return -1; } if (hapd->conf->radius_das_port) { struct radius_das_conf das_conf; os_memset(&das_conf, 0, sizeof(das_conf)); das_conf.port = hapd->conf->radius_das_port; das_conf.shared_secret = hapd->conf->radius_das_shared_secret; das_conf.shared_secret_len = hapd->conf->radius_das_shared_secret_len; das_conf.client_addr = &hapd->conf->radius_das_client_addr; das_conf.time_window = hapd->conf->radius_das_time_window; das_conf.require_event_timestamp = hapd->conf->radius_das_require_event_timestamp; das_conf.ctx = hapd; das_conf.disconnect = hostapd_das_disconnect; hapd->radius_das = radius_das_init(&das_conf); if (hapd->radius_das == NULL) { wpa_printf(MSG_ERROR, "RADIUS DAS initialization " "failed."); return -1; } } #endif /* CONFIG_NO_RADIUS */ if (hostapd_acl_init(hapd)) { wpa_printf(MSG_ERROR, "ACL initialization failed."); return -1; } if (hostapd_init_wps(hapd, conf)) return -1; if (authsrv_init(hapd) < 0) return -1; if (ieee802_1x_init(hapd)) { wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed."); return -1; } if (hapd->conf->wpa && hostapd_setup_wpa(hapd)) return -1; if (accounting_init(hapd)) { wpa_printf(MSG_ERROR, "Accounting initialization failed."); return -1; } if (hapd->conf->ieee802_11f && (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) { wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization " "failed."); return -1; } #ifdef CONFIG_INTERWORKING if (gas_serv_init(hapd)) { wpa_printf(MSG_ERROR, "GAS server initialization failed"); return -1; } #endif /* CONFIG_INTERWORKING */ if (hapd->iface->interfaces && hapd->iface->interfaces->ctrl_iface_init && hapd->iface->interfaces->ctrl_iface_init(hapd)) { wpa_printf(MSG_ERROR, "Failed to setup control interface"); return -1; } if (!hostapd_drv_none(hapd) && vlan_init(hapd)) { wpa_printf(MSG_ERROR, "VLAN initialization failed."); return -1; } if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0) return -1; if (hapd->driver && hapd->driver->set_operstate) hapd->driver->set_operstate(hapd->drv_priv, 1); return 0; }
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; }