+int nl80211_get_country(const char *ifname, char *buf)
+{
+ int rv = -1;
+ struct nl80211_msg_conveyor *req, *res;
+
+ req = nl80211_msg(ifname, NL80211_CMD_GET_REG, 0);
+ if( req )
+ {
+ res = nl80211_send(req);
+ if( res )
+ {
+ if( res->attr[NL80211_ATTR_REG_ALPHA2] )
+ {
+ memcpy(buf, nla_data(res->attr[NL80211_ATTR_REG_ALPHA2]), 2);
+ rv = 0;
+ }
+ nl80211_free(res);
+ }
+ nl80211_free(req);
+ }
+
+ return rv;
+}
+
+int nl80211_get_countrylist(const char *ifname, char *buf, int *len)
+{
+ int i, count;
+ struct iwinfo_iso3166_label *l;
+ struct iwinfo_country_entry *e = (struct iwinfo_country_entry *)buf;
+
+ for( l = ISO3166_Names, count = 0; l->iso3166; l++, e++, count++ )
+ {
+ e->iso3166 = l->iso3166;
+ e->ccode[0] = (l->iso3166 / 256);
+ e->ccode[1] = (l->iso3166 % 256);
+ }
+
+ *len = (count * sizeof(struct iwinfo_country_entry));
+ return 0;
+}
+