wpa_supplicant: Add support for setting of a regulatory domain
authorLuis R. Rodriguez <lrodriguez@Atheros.com>
Tue, 9 Dec 2008 20:11:14 +0000 (22:11 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 9 Dec 2008 20:11:14 +0000 (22:11 +0200)
This adds support for setting of a regulatory domain to wpa_supplicant
drivers. It also adds regulatory domain setting for the nl80211 driver.
We expect an ISO / IEC 3166 alpha2 in the wpa configuration file as a
global.

src/drivers/driver.h
src/drivers/driver_ndis.c
src/drivers/driver_nl80211.c
src/drivers/driver_privsep.c
src/drivers/driver_test.c
wpa_supplicant/config.h
wpa_supplicant/config_file.c
wpa_supplicant/wpa_supplicant.c
wpa_supplicant/wpa_supplicant_i.h

index 5357598..9037c20 100644 (file)
@@ -945,6 +945,17 @@ struct wpa_driver_ops {
         * Returns: 0 on success, -1 on failure
         */
        int (*set_mode)(void *priv, int mode);
+
+       /**
+        * set_country - Set country
+        * @priv: Private driver interface data
+        * @alpha2: country to which to switch to
+        * Returns: 0 on success, -1 on failure
+        *
+        * This function is for drivers which support some form
+        * of setting a regulatory domain.
+        */
+       int (*set_country)(void *priv, const char *alpha2);
 };
 
 /* Function to check whether a driver is for wired connections */
index e245b30..a702b6c 100644 (file)
@@ -2872,5 +2872,6 @@ const struct wpa_driver_ops wpa_driver_ndis_ops = {
        NULL /* send_ft_action */,
        wpa_driver_ndis_get_scan_results,
        NULL /* set_probe_req_ie */,
-       NULL /* set_mode */
+       NULL /* set_mode */,
+       NULL /* set_country */
 };
index 59ef1d7..1887692 100644 (file)
@@ -958,6 +958,41 @@ static int wpa_driver_nl80211_set_ifflags(struct wpa_driver_nl80211_data *drv,
 }
 
 
+/**
+ * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
+ * @priv: driver_nl80211 private data
+ * @alpha2_arg: country to which to switch to
+ * Returns: 0 on success, -1 on failure
+ *
+ * This asks nl80211 to set the regulatory domain for given
+ * country ISO / IEC alpha2.
+ */
+static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
+{
+       struct wpa_driver_nl80211_data *drv = priv;
+       char alpha2[3];
+       struct nl_msg *msg;
+
+       msg = nlmsg_alloc();
+       if (!msg)
+               goto nla_put_failure;
+
+       alpha2[0] = alpha2_arg[0];
+       alpha2[1] = alpha2_arg[1];
+       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))
+               return -EINVAL;
+       return 0;
+nla_put_failure:
+       return -EINVAL;
+}
+
+
 #ifdef CONFIG_CLIENT_MLME
 
 static int nl80211_set_vif(struct wpa_driver_nl80211_data *drv,
@@ -2858,6 +2893,7 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
        .flush_pmkid = wpa_driver_nl80211_flush_pmkid,
        .get_capa = wpa_driver_nl80211_get_capa,
        .set_operstate = wpa_driver_nl80211_set_operstate,
+       .set_country = wpa_driver_nl80211_set_country,
 #ifdef CONFIG_CLIENT_MLME
        .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data,
        .set_channel = wpa_driver_nl80211_set_channel,
index 4e0a36f..9c98ed3 100644 (file)
@@ -774,7 +774,8 @@ struct wpa_driver_ops wpa_driver_privsep_ops = {
        NULL /* send_ft_action */,
        wpa_driver_privsep_get_scan_results2,
        NULL /* set_probe_req_ie */,
-       wpa_driver_privsep_set_mode
+       wpa_driver_privsep_set_mode,
+       NULL /* set_country */
 };
 
 
index 2e293ae..f10c062 100644 (file)
@@ -1026,5 +1026,6 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
        NULL /* send_ft_action */,
        wpa_driver_test_get_scan_results2,
        wpa_driver_set_probe_req_ie,
-       NULL /* set_mode */
+       NULL /* set_mode */,
+       NULL /* set_country */
 };
index b05576d..3ec2a01 100644 (file)
@@ -252,6 +252,14 @@ struct wpa_config {
         * uuid - Universally Unique IDentifier (UUID; see RFC 4122) for WPS
         */
        u8 uuid[16];
+
+       /**
+        * alpha2 - Country code
+        *
+        * This is the ISO/IEC alpha2 country code for which we are operating
+        * in
+        */
+       char alpha2[2];
 };
 
 
index acc9ee5..09d6a67 100644 (file)
@@ -270,6 +270,20 @@ 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)
+{
+       if (!pos[0] || !pos[1]) {
+               wpa_printf(MSG_DEBUG, "Invalid country set");
+               return -1;
+       }
+       config->alpha2[0] = pos[0];
+       config->alpha2[1] = pos[1];
+       wpa_printf(MSG_DEBUG, "country='%c%c'",
+                  config->alpha2[0], config->alpha2[1]);
+       return 0;
+}
+
+
 #ifdef CONFIG_CTRL_IFACE
 static int wpa_config_process_ctrl_interface(struct wpa_config *config,
                                             char *pos)
@@ -503,6 +517,9 @@ static int wpa_config_process_global(struct wpa_config *config, char *pos,
                return wpa_config_process_uuid(config, line, pos + 5);
 #endif /* CONFIG_WPS */
 
+       if (os_strncmp(pos, "country=", 8) == 0)
+               return wpa_config_process_country(config, pos + 8);
+
        return -1;
 }
 
@@ -874,6 +891,10 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
                fprintf(f, "uuid=%s\n", buf);
        }
 #endif /* CONFIG_WPS */
+       if (config->alpha2[0] && config->alpha2[1]) {
+               fprintf(f, "country=%c%c\n",
+                       config->alpha2[0], config->alpha2[1]);
+       }
 }
 
 #endif /* CONFIG_NO_CONFIG_WRITE */
index 00d20c9..c3e7dbd 100644 (file)
@@ -1790,6 +1790,12 @@ static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s)
        if (wpa_supplicant_driver_init(wpa_s) < 0)
                return -1;
 
+       if (wpa_s->conf->alpha2[0] && wpa_s->conf->alpha2[1] &&
+           wpa_drv_set_country(wpa_s, wpa_s->conf->alpha2)) {
+               wpa_printf(MSG_DEBUG, "Failed to set country");
+               return -1;
+       }
+
        wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
 
        if (wpas_wps_init(wpa_s))
index ab7aa94..3232198 100644 (file)
@@ -676,6 +676,14 @@ static inline int wpa_drv_set_bssid(struct wpa_supplicant *wpa_s,
        return -1;
 }
 
+static inline int wpa_drv_set_country(struct wpa_supplicant *wpa_s,
+                                     const char *alpha2)
+{
+       if (wpa_s->driver->set_country)
+               return wpa_s->driver->set_country(wpa_s->drv_priv, alpha2);
+       return 0;
+}
+
 static inline int wpa_drv_send_mlme(struct wpa_supplicant *wpa_s,
                                    const u8 *data, size_t data_len)
 {