[RFC] Add country parameter for wpa_supplicant.conf

Dan Williams dcbw
Tue Nov 25 06:38:56 PST 2008


On Mon, 2008-11-24 at 17:15 -0800, Luis R. Rodriguez wrote:
> Users can now select the country they are in as part of nl80211.
> Since this is configurable it seems the supplicant should be the one
> to set this rather than expecting the user to always set this him/herself
> or having Network Manager do it independently. As such I'd like to see
> if a country= parameter can be mergable for wpa_supplicant and if its
> desirable.
> 
> I just started reviewing wpa_supplicant code and configuration stuff and
> found where to define parameters for each 'network' and also globally
> but am not yet if this should be a global parameter or per network.
> Perhaps we should allow one global definition and use a local network
> value if defined to override the global?

I'd go with a global plus country-per-network-block override, or simply
just country-per-network-block.  That's the most flexible, and I can
think of configurations where a global country simply wouldn't work with
how people use wpa_supplicant.  Automated tools like NetworkManager have
control over the options they add to network block anyway and can insert
the current timezone country or whatever if they like.

Dan

> I also am unsure of how to hook yet nl80211_driver stuff to
> wpa_supplicant. Pointers in the right direction appreciated.
> 
> So to recap:
> 
>  - Is this desirable? Or is there a better way?
>  - What to do we do for other OSes? Or will the driver (nl80211 in
>    Linux's case) handle that?
>  - Global or per network or both?
> 
>   Luis
> 
> diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
> index 7037dcd..7c498b3 100644
> --- a/src/drivers/driver_nl80211.c
> +++ b/src/drivers/driver_nl80211.c
> @@ -957,6 +957,36 @@ static int wpa_driver_nl80211_set_ifflags(struct wpa_driver_nl80211_data *drv,
>  	return wpa_driver_nl80211_set_ifflags_ifname(drv, drv->ifname, flags);
>  }
>  
> +/**
> + * nl80211_set_country - ask nl80211 to set the regulatory domain
> + * @drv: driver_nl80211 private data
> + * This asks nl80211 to set the regulatory domain for given
> + * country ISO / IEC alpha2.
> + * Returns: 0 on success, -1 on failure
> + */
> +static int nl80211_set_country(struct wpa_driver_nl80211_data *drv)
> +{
> +	char alpha2[3];
> +	struct nl_msg *msg;
> +
> +	msg = nlmsg_alloc();
> +	if (!msg)
> +		goto nla_put_failure;
> +
> +	/* XXX: where do I get the configured alpha2 ? */
> +	alpha2[0] = drv->config->alpha2[0];
> +	alpha2[1] = drv->config->alpha2[0];
> +	alpha2[2] = '\0';
> +
> +	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
> +		    0, NL80211_CMD_REQ_SET_REG, 0);
> +
> +	NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2);
> +	if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
> +		return;
> +nla_put_failure:
> +	wpa_printf(MSG_ERROR, "nl80211: Failed to country.");
> +}
>  
>  #ifdef CONFIG_CLIENT_MLME
>  
> diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
> index c5e300e..a6c97fc 100644
> --- a/wpa_supplicant/config.c
> +++ b/wpa_supplicant/config.c
> @@ -1306,6 +1306,7 @@ static const struct parse_data ssid_fields[] = {
>  	{ FUNC(pairwise) },
>  	{ FUNC(group) },
>  	{ FUNC(auth_alg) },
> +	{ STR_RANGE(country, 2, 2) },
>  #ifdef IEEE8021X_EAPOL
>  	{ FUNC(eap) },
>  	{ STR_LENe(identity) },
> diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
> index 3153214..ed07034 100644
> --- a/wpa_supplicant/config_file.c
> +++ b/wpa_supplicant/config_file.c
> @@ -268,6 +268,14 @@ static int wpa_config_process_blob(struct wpa_config *config, FILE *f,
>  }
>  #endif /* CONFIG_NO_CONFIG_BLOBS */
>  
> +static int wpa_config_process_country(struct wpa_config *config,
> +					   char *pos)
> +{
> +	config->alpha2[0] = pos[0];
> +	config->alpha2[1] = pos[2];
> +	wpa_printf(MSG_DEBUG, "country='%c%c'", config->alpha2[0], alpha2[1]);
> +	return 0;
> +}
>  
>  #ifdef CONFIG_CTRL_IFACE
>  static int wpa_config_process_ctrl_interface(struct wpa_config *config,
> @@ -430,6 +438,9 @@ static int wpa_config_process_load_dynamic_eap(int line, char *so)
>  static int wpa_config_process_global(struct wpa_config *config, char *pos,
>  				     int line)
>  {
> +	if (os_strncmp(pos, "country=", 8) == 0)
> +		return wpa_config_process_country(config, pos + 8);
> +
>  #ifdef CONFIG_CTRL_IFACE
>  	if (os_strncmp(pos, "ctrl_interface=", 15) == 0)
>  		return wpa_config_process_ctrl_interface(config, pos + 15);




More information about the Hostap mailing list