[PATCH] Add get_country op for nl80211 drivers

Bartosz.Markowski at tieto.com Bartosz.Markowski
Tue Jul 19 03:03:18 PDT 2011


Signed-off-by: Bartosz Markowski <bartosz.markowski at tieto.com<mailto:guy at wizery.com>>
---
 src/drivers/driver.h         |   11 +++++++++++
 src/drivers/driver_nl80211.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 wpa_supplicant/driver_i.h    |    9 +++++++++
 3 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 92951ae..968022f 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -1219,6 +1219,17 @@ struct wpa_driver_ops {
        int (*set_country)(void *priv, const char *alpha2);

        /**
+        * get_country - Get country
+        * @priv: Private driver interface data
+        * @alpha2: pointer to country code
+        * Returns: 0 on success, -1 on failure
+        *
+        * This function is for drivers which support some form
+        * of setting a regulatory domain.
+        */
+       int (*get_country)(void *priv, char *alpha2);
+
+       /**
         * global_init - Global driver initialization
         * Returns: Pointer to private data (global), %NULL on failure
         *
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 87d474e..dd435cb 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1626,6 +1626,47 @@ nla_put_failure:
        return -EINVAL;
 }

+static int get_country_handler(struct nl_msg *msg, void *arg)
+{
+       struct nlattr *tb[NL80211_ATTR_MAX + 1];
+       struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+       char *cc;
+
+       nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+                               genlmsg_attrlen(gnlh, 0), NULL);
+
+       if (!tb[NL80211_ATTR_REG_ALPHA2]) {
+               printf("No alpha2\n");
+               return NL_SKIP;
+    }
+
+       cc = nla_data(tb[NL80211_ATTR_REG_ALPHA2]);
+       os_memcpy(arg, cc, 2);
+
+       return NL_OK;
+}
+
+static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
+{
+       struct i802_bss *bss = priv;
+       struct wpa_driver_nl80211_data *drv = bss->drv;
+       struct nl_msg *msg;
+
+       msg = nlmsg_alloc();
+       if (!msg)
+               return -ENOMEM;
+
+       genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
+                       0, NL80211_CMD_GET_REG, 0);
+
+       NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
+
+       return send_and_recv_msgs(drv, msg, get_country_handler, alpha2);
+
+nla_put_failure:
+       nlmsg_free(msg);
+       return -ENOBUFS;
+}

 struct wiphy_info_data {
        int max_scan_ssids;
@@ -6806,6 +6847,7 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
        .set_operstate = wpa_driver_nl80211_set_operstate,
        .set_supp_port = wpa_driver_nl80211_set_supp_port,
        .set_country = wpa_driver_nl80211_set_country,
+       .get_country = wpa_driver_nl80211_get_country,
        .set_beacon = wpa_driver_nl80211_set_beacon,
        .if_add = wpa_driver_nl80211_if_add,
        .if_remove = wpa_driver_nl80211_if_remove,
diff --git a/wpa_supplicant/driver_i.h b/wpa_supplicant/driver_i.h
index 8637754..5947814 100644
--- a/wpa_supplicant/driver_i.h
+++ b/wpa_supplicant/driver_i.h
@@ -273,6 +273,15 @@ static inline int wpa_drv_set_country(struct wpa_supplicant *wpa_s,
        return 0;
 }

+static inline int wpa_drv_get_country(struct wpa_supplicant *wpa_s,
+                                     char *alpha2)
+{
+       if (wpa_s->driver->get_country)
+               return wpa_s->driver->get_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)
 {
--
1.7.0.4




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.shmoo.com/pipermail/hostap/attachments/20110719/885084d7/attachment-0001.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-get_country-op-for-nl80211-drivers.patch
Type: application/octet-stream
Size: 3420 bytes
Desc: 0001-Add-get_country-op-for-nl80211-drivers.patch
Url : http://lists.shmoo.com/pipermail/hostap/attachments/20110719/885084d7/attachment-0001.obj 



More information about the Hostap mailing list