[PATCH] iwinfo: expose country code in Lua scanlist

hasbaddana at outlook.com hasbaddana at outlook.com
Sat Dec 11 07:27:26 PST 2021


From: Тјеu Кауim <hasbaddana at outlook.com>

Adds a new field `iwinfo_scanlist_entry.country_code` for the ISO 3166
alpha2 of the regulatory domain, extracted from an information element.
It is left zero when the IE is not present, or when a different driver
than nl80211 is used. Also updates the Lua interface to expose it.

Signed-off-by: Тјеu Кауim <hasbaddana at outlook.com>
---
 include/iwinfo.h | 1 +
 iwinfo_lua.c     | 7 +++++++
 iwinfo_nl80211.c | 5 +++++
 3 files changed, 13 insertions(+)

diff --git a/include/iwinfo.h b/include/iwinfo.h
index 8469ee7..9e9a2c4 100644
--- a/include/iwinfo.h
+++ b/include/iwinfo.h
@@ -223,6 +223,7 @@ struct iwinfo_scanlist_entry {
 	struct iwinfo_crypto_entry crypto;
 	struct iwinfo_scanlist_ht_chan_entry ht_chan_info;
 	struct iwinfo_scanlist_vht_chan_entry vht_chan_info;
+	char country_code[2];
 };
 
 struct iwinfo_country_entry {
diff --git a/iwinfo_lua.c b/iwinfo_lua.c
index e49e454..03b6467 100644
--- a/iwinfo_lua.c
+++ b/iwinfo_lua.c
@@ -454,6 +454,13 @@ static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int
 			iwinfo_L_cryptotable(L, &e->crypto);
 			lua_setfield(L, -2, "encryption");
 
+			/* Country */
+			if (e->country_code[0])
+			{
+				lua_pushlstring(L, e->country_code, 2);
+				lua_setfield(L, -2, "country_code");
+			}
+
 			lua_rawseti(L, -2, x);
 		}
 	}
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index c4b0ee2..af1e579 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -2463,6 +2463,11 @@ static void nl80211_get_scanlist_ie(struct nlattr **bss,
 				e->vht_chan_info.center_chan_2 = ie[4];
 			}
 			break;
+
+		case 7: /* Country */
+			if (ie[1] >= 3)
+				memcpy(e->country_code, ie + 2, 2);
+			break;
 		}
 
 		ielen -= ie[1] + 2;
-- 
2.25.1




More information about the openwrt-devel mailing list