[PATCH 1/3] Added wpa_config_get_all function

Dan Williams dcbw
Wed Oct 21 10:56:45 PDT 2009


On Sun, 2009-10-18 at 03:55 +0200, Witold Sowa wrote:
> New function returns all parameters of network configuration block.

Cool; we'd use this in NM to retrieve the new security settings after
the supplicant updates the network block with the options received from
a WPS run.

Dan

> ---
>  wpa_supplicant/config.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++
>  wpa_supplicant/config.h |    1 +
>  2 files changed, 56 insertions(+), 0 deletions(-)
> 
> diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
> index 97c303d..2c25c70 100644
> --- a/wpa_supplicant/config.c
> +++ b/wpa_supplicant/config.c
> @@ -1832,6 +1832,61 @@ int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
>  }
>  
> 
> +/**
> + * wpa_config_get_all - Get all options from network configuration
> + * @ssid: Pointer to network configuration data
> + * @get_keys: Determines if keys/passwords will be included in return list
> + * Returns: %NULL terminated list of all set keys and their values in the form
> + * of [key1, val1, key2, val2, ... , NULL]
> + *
> + * This function can be used to get list of all configured network
> + * properties. The caller is responsible for freeing returned list and
> + * all its elements.
> + */
> +char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
> +{
> +	const struct parse_data *field;
> +	char *key, *value;
> +	size_t i;
> +	char **props;
> +	int fields_num;
> +
> +	props = os_zalloc(sizeof(char *) * ((2 * NUM_SSID_FIELDS) + 1));
> +	if (!props)
> +		goto err;
> +
> +	fields_num = 0;
> +	for (i = 0; i < NUM_SSID_FIELDS; i++) {
> +		field = &ssid_fields[i];
> +		if (field->key_data && !get_keys)
> +			continue;
> +		value = field->writer(field, ssid);
> +		if (value == NULL || os_strlen(value) == 0)
> +			continue;
> +
> +		key = os_strdup(field->name);
> +		if (key == NULL)
> +			goto err;
> +
> +		props[fields_num * 2] = key;
> +		props[fields_num * 2 + 1] = value;
> +
> +		fields_num++;
> +	}
> +
> +	return props;
> +
> +err:
> +	if (props) {
> +		char *val = *props;
> +		while (val)
> +			os_free(val++);
> +		os_free(props);
> +	}
> +	return NULL;
> +}
> +
> +
>  #ifndef NO_CONFIG_WRITE
>  /**
>   * wpa_config_get - Get a variable in network configuration
> diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h
> index 4484e91..b9f0da6 100644
> --- a/wpa_supplicant/config.h
> +++ b/wpa_supplicant/config.h
> @@ -336,6 +336,7 @@ int wpa_config_remove_network(struct wpa_config *config, int id);
>  void wpa_config_set_network_defaults(struct wpa_ssid *ssid);
>  int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
>  		   int line);
> +char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys);
>  char * wpa_config_get(struct wpa_ssid *ssid, const char *var);
>  char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var);
>  void wpa_config_update_psk(struct wpa_ssid *ssid);




More information about the Hostap mailing list