Beispiel #1
0
static hostapd * hostapd_init(const char *config_file)
{
	hostapd *hapd;

	hapd = malloc(sizeof(*hapd));
	if (hapd == NULL) {
		printf("Could not allocate memory for hostapd data\n");
		exit(1);
	}
	memset(hapd, 0, sizeof(*hapd));

	hapd->config_fname = strdup(config_file);
	if (hapd->config_fname == NULL) {
		printf("Could not allocate memory for config_fname\n");
		exit(1);
	}

	hapd->conf = hostapd_config_read(hapd->config_fname);
	if (hapd->conf == NULL) {
		free(hapd->config_fname);
		exit(1);
	}

	if (hapd->conf->individual_wep_key_len > 0) {
		/* use key0 in individual key and key1 in broadcast key */
		hapd->default_wep_key_idx = 1;
	}

	if (hapd->conf->assoc_ap)
		hapd->assoc_ap_state = WAIT_BEACON;

	return hapd;
}
Beispiel #2
0
static void handle_reload(int sig, void *eloop_ctx, void *signal_ctx)
{
	struct hapd_interfaces *hapds = (struct hapd_interfaces *) eloop_ctx;
	struct hostapd_config *newconf;
	int i;

	printf("Signal %d received - reloading configuration\n", sig);

	for (i = 0; i < hapds->count; i++) {
		hostapd *hapd = hapds->hapd[i];
		newconf = hostapd_config_read(hapd->config_fname);
		if (newconf == NULL) {
			printf("Failed to read new configuration file - "
			       "continuing with old.\n");
			continue;
		}
		/* TODO: update dynamic data based on changed configuration
		 * items (e.g., open/close sockets, remove stations added to
		 * deny list, etc.) */
		radius_client_flush(hapd->radius);
		hostapd_config_free(hapd->conf);
		hapd->conf = newconf;
#ifdef JUMPSTART
		hostapd_setup_interface(hapd);
#endif /* JUMSTART */
	}
}
Beispiel #3
0
/**
 * hostapd_init - Allocate and initialize per-interface data
 * @config_file: Path to the configuration file
 * Returns: Pointer to the allocated interface data or %NULL on failure
 *
 * This function is used to allocate main data structures for per-interface
 * data. The allocated data buffer will be freed by calling
 * hostapd_cleanup_iface().
 */
static struct hostapd_iface * hostapd_init(const char *config_file)
{
	struct hostapd_iface *hapd_iface = NULL;
	struct hostapd_config *conf = NULL;
	struct hostapd_data *hapd;
	size_t i;

	hapd_iface = os_zalloc(sizeof(*hapd_iface));
	if (hapd_iface == NULL)
		goto fail;

	hapd_iface->reload_config = hostapd_reload_config;
	hapd_iface->config_read_cb = hostapd_config_read;
	hapd_iface->config_fname = os_strdup(config_file);
	if (hapd_iface->config_fname == NULL)
		goto fail;
	hapd_iface->ctrl_iface_init = hostapd_ctrl_iface_init;
	hapd_iface->ctrl_iface_deinit = hostapd_ctrl_iface_deinit;
	hapd_iface->for_each_interface = hostapd_for_each_interface;

	conf = hostapd_config_read(hapd_iface->config_fname);
	if (conf == NULL)
		goto fail;
	hapd_iface->conf = conf;

	hapd_iface->num_bss = conf->num_bss;
	hapd_iface->bss = os_zalloc(conf->num_bss *
				    sizeof(struct hostapd_data *));
	if (hapd_iface->bss == NULL)
		goto fail;

	for (i = 0; i < conf->num_bss; i++) {
		hapd = hapd_iface->bss[i] =
			hostapd_alloc_bss_data(hapd_iface, conf,
					       &conf->bss[i]);
		if (hapd == NULL)
			goto fail;
		hapd->msg_ctx = hapd;
	}

	return hapd_iface;

fail:
	if (conf)
		hostapd_config_free(conf);
	if (hapd_iface) {
		os_free(hapd_iface->config_fname);
		os_free(hapd_iface->bss);
		os_free(hapd_iface);
	}
	return NULL;
}
Beispiel #4
0
/**
 * hostapd_init - Allocate and initialize per-interface data
 * @config_file: Path to the configuration file
 * Returns: Pointer to the allocated interface data or %NULL on failure
 *
 * This function is used to allocate main data structures for per-interface
 * data. The allocated data buffer will be freed by calling
 * hostapd_cleanup_iface().
 */
static struct hostapd_iface * hostapd_init(const char *config_file)
{
	struct hostapd_iface *hapd_iface = NULL;
	struct hostapd_config *conf = NULL;
	struct hostapd_data *hapd;
	size_t i;

	hapd_iface = os_zalloc(sizeof(*hapd_iface));
	if (hapd_iface == NULL)
		goto fail;

	hapd_iface->config_fname = os_strdup(config_file);
	if (hapd_iface->config_fname == NULL)
		goto fail;

	conf = hostapd_config_read(hapd_iface->config_fname);
	if (conf == NULL)
		goto fail;
	hapd_iface->conf = conf;

	hapd_iface->num_bss = conf->num_bss;
	hapd_iface->bss = os_calloc(conf->num_bss,
				    sizeof(struct hostapd_data *));
	if (hapd_iface->bss == NULL)
		goto fail;

	for (i = 0; i < conf->num_bss; i++) {
		hapd = hapd_iface->bss[i] =
			hostapd_alloc_bss_data(hapd_iface, conf,
					       &conf->bss[i]);
		if (hapd == NULL)
			goto fail;
		hapd->msg_ctx = hapd;
		hapd->setup_complete_cb = hostapd_setup_complete_cb;
	}

	return hapd_iface;

fail:
	wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
		   config_file);
	if (conf)
		hostapd_config_free(conf);
	if (hapd_iface) {
		os_free(hapd_iface->config_fname);
		os_free(hapd_iface->bss);
		os_free(hapd_iface);
	}
	return NULL;
}
/**
 * hostapd_config_reload_start - Start reconfiguration of an interface
 * @hapd_iface: Pointer to hostapd interface data
 * @cb: Function to be called back when done.
 *      The status indicates:
 *       0 = success, new configuration in use;
 *      -1 = failed to update configuraiton, old configuration in use;
 *      -2 = failed to update configuration and failed to recover; caller
 *           should cleanup and terminate hostapd
 * Returns:
 *  0 = reconfiguration started;
 * -1 = failed to update configuration, old configuration in use;
 * -2 = failed to update configuration and failed to recover; caller
 *      should cleanup and terminate hostapd
 */
int hostapd_config_reload_start(struct hostapd_iface *hapd_iface,
				hostapd_iface_cb cb)
{
	struct hostapd_config *newconf, *oldconf;
	struct hostapd_config_change *change;
	struct hostapd_data *hapd = NULL;
	struct hostapd_data **old_hapd, **new_hapd;
	int num_old_hapd;

	if (hapd_iface->config_reload_cb) {
		wpa_printf(MSG_DEBUG, "%s: Config reload already in progress.",
			   hapd_iface->bss[0]->conf->iface);
		return -1;
	}

	newconf = hostapd_config_read(hapd_iface->config_fname);
	if (newconf == NULL) {
		printf("Failed to read new configuration file - continuing "
		       "with old.\n");
		return -1;
	}

	if (strcmp(newconf->bss[0].iface, hapd_iface->conf->bss[0].iface) !=
	    0) {
		printf("Interface name changing is not allowed in "
		       "configuration reloading (%s -> %s).\n",
		       hapd_iface->conf->bss[0].iface,  newconf->bss[0].iface);
		hostapd_config_free(newconf);
		return -1;
	}

	new_hapd = wpa_zalloc(newconf->num_bss *
			      sizeof(struct hostapd_data *));
	if (new_hapd == NULL) {
		hostapd_config_free(newconf);
		return -1;
	}
	old_hapd = hapd_iface->bss;
	num_old_hapd = hapd_iface->num_bss;

	hapd_iface->bss = new_hapd;
	hapd_iface->num_bss = newconf->num_bss;
	/*
	 * First BSS remains the same since interface name changing was
	 * prohibited above. Now, this is only used in
	 * hostapd_config_reload_iface() and following loop will anyway set
	 * this again.
	 */
	hapd = hapd_iface->bss[0] = old_hapd[0];

	oldconf = hapd_iface->conf;
	hapd->iconf = hapd_iface->conf = newconf;
	hapd->conf = &newconf->bss[0];

	change = wpa_zalloc(sizeof(struct hostapd_config_change));
	if (change == NULL) {
		hostapd_config_free(newconf);
		return -1;
	}

	change->hapd = hapd;
	change->newconf = newconf;
	change->oldconf = oldconf;
	change->beacon_changed = 0;
	change->hapd_iface = hapd_iface;
	change->new_hapd = new_hapd;
	change->old_hapd = old_hapd;
	change->num_old_hapd = num_old_hapd;

	hapd_iface->config_reload_cb = cb;
	hapd_iface->change = change;
	if (hostapd_config_reload_iface_start(hapd_iface, config_reload2)) {
		printf("Failed to start setup of new interface config\n");

		hapd_iface->config_reload_cb = NULL;
		free(change);
		hapd_iface->change = NULL;

		/* Invalid configuration - cleanup and terminate hostapd */
		hapd_iface->bss = old_hapd;
		hapd_iface->num_bss = num_old_hapd;
		hapd_iface->conf = hapd->iconf = oldconf;
		hapd->conf = &oldconf->bss[0];
		hostapd_config_free(newconf);
		free(new_hapd);
		return -2;
	}

	return 0;
}
static hostapd * hostapd_init(const char *config_file)
{
	hostapd *hapd;

	hapd = malloc(sizeof(*hapd));
	if (hapd == NULL) {
		printf("Could not allocate memory for hostapd data\n");
		goto fail;
	}
	memset(hapd, 0, sizeof(*hapd));

	hapd->config_fname = strdup(config_file);
	if (hapd->config_fname == NULL) {
		printf("Could not allocate memory for config_fname\n");
		goto fail;
	}

	hapd->conf = hostapd_config_read(hapd->config_fname);
	if (hapd->conf == NULL) {
		goto fail;
	}

	if (hapd->conf->individual_wep_key_len > 0) {
		/* use key0 in individual key and key1 in broadcast key */
		hapd->default_wep_key_idx = 1;
	}

#ifdef EAP_TLS_FUNCS
	if (hapd->conf->eap_server &&
	    (hapd->conf->ca_cert || hapd->conf->server_cert)) {
		hapd->ssl_ctx = tls_init(NULL);
		if (hapd->ssl_ctx == NULL) {
			printf("Failed to initialize TLS\n");
			goto fail;
		}
		if (tls_global_ca_cert(hapd->ssl_ctx, hapd->conf->ca_cert)) {
			printf("Failed to load CA certificate (%s)\n",
				hapd->conf->ca_cert);
			goto fail;
		}
		if (tls_global_client_cert(hapd->ssl_ctx,
					   hapd->conf->server_cert)) {
			printf("Failed to load server certificate (%s)\n",
				hapd->conf->server_cert);
			goto fail;
		}
		if (tls_global_private_key(hapd->ssl_ctx,
					   hapd->conf->private_key,
					   hapd->conf->private_key_passwd)) {
			printf("Failed to load private key (%s)\n",
			       hapd->conf->private_key);
			goto fail;
		}
		if (tls_global_set_verify(hapd->ssl_ctx,
					  hapd->conf->check_crl)) {
			printf("Failed to enable check_crl\n");
			goto fail;
		}
	}
#endif /* EAP_TLS_FUNCS */

	if (hapd->conf->eap_sim_db) {
		hapd->eap_sim_db_priv =
			eap_sim_db_init(hapd->conf->eap_sim_db);
		if (hapd->eap_sim_db_priv == NULL) {
			printf("Failed to initialize EAP-SIM database "
			       "interface\n");
			goto fail;
		}
	}

	if (hapd->conf->assoc_ap)
		hapd->assoc_ap_state = WAIT_BEACON;

	/* FIX: need to fix this const vs. not */
	hapd->driver = (struct driver_ops *) hapd->conf->driver;

	return hapd;

fail:
	if (hapd) {
		if (hapd->ssl_ctx)
			tls_deinit(hapd->ssl_ctx);
		if (hapd->conf)
			hostapd_config_free(hapd->conf);
		free(hapd->config_fname);
		free(hapd);
	}
	return NULL;
}