* 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 */
NULL /* send_ft_action */,
wpa_driver_ndis_get_scan_results,
NULL /* set_probe_req_ie */,
- NULL /* set_mode */
+ NULL /* set_mode */,
+ NULL /* set_country */
};
}
+/**
+ * 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,
.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,
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 */
};
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 */
};
* 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];
};
#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)
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;
}
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 */
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))
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)
{