From dce2054780e8142aebe5a7d11c4751040437f7ec Mon Sep 17 00:00:00 2001 From: Mayank Haarit Date: Wed, 18 Apr 2018 19:59:49 +0530 Subject: [PATCH] Added logic to get country code of APs It also includes parsing country code from IEs received from the supplicant Change-Id: Iea5f8b2ea7cc8fefe07591cc4d636d27b015d427 Signed-off-by: Mayank Haarit --- gsupplicant/gsupplicant.h | 2 ++ gsupplicant/supplicant.c | 23 +++++++++++++++++++++++ include/network.h | 3 +++ plugins/wifi.c | 6 ++++++ src/connman.h | 3 +++ src/network.c | 24 ++++++++++++++++++++++++ src/service.c | 10 ++++++++++ 7 files changed, 71 insertions(+) diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h index ead619c..0a28dbf 100755 --- a/gsupplicant/gsupplicant.h +++ b/gsupplicant/gsupplicant.h @@ -397,6 +397,8 @@ const char *g_supplicant_network_get_identity(GSupplicantNetwork *network); const char *g_supplicant_network_get_phase2(GSupplicantNetwork *network); unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network); void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network); +const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork + *network); #endif struct _GSupplicantCallbacks { diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c index 92efbc9..fbfa6c7 100644 --- a/gsupplicant/supplicant.c +++ b/gsupplicant/supplicant.c @@ -44,6 +44,10 @@ #define IEEE80211_CAP_IBSS 0x0002 #define IEEE80211_CAP_PRIVACY 0x0010 +#if defined TIZEN_EXT +#define COUNTRY_CODE_LENGTH 2 +#endif + #define BSS_UNKNOWN_STRENGTH -90 static DBusConnection *connection; @@ -223,6 +227,7 @@ struct g_supplicant_bss { dbus_bool_t ft_ieee8021x; GSList *vsie_list; dbus_bool_t hs20; + unsigned char country_code[COUNTRY_CODE_LENGTH]; #endif unsigned int wps_capabilities; }; @@ -250,6 +255,7 @@ struct _GSupplicantNetwork { char *phase2; unsigned int keymgmt; GSList *vsie_list; + unsigned char country_code[COUNTRY_CODE_LENGTH]; #endif }; @@ -1408,6 +1414,15 @@ unsigned int g_supplicant_network_get_keymgmt(GSupplicantNetwork *network) return network->keymgmt; } + +const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork + *network) +{ + if (!network) + return NULL; + + return network->country_code; +} #endif const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer, @@ -1876,6 +1891,7 @@ static int add_or_replace_bss_to_network(struct g_supplicant_bss *bss) } network->isHS20AP = bss->hs20; + memcpy(network->country_code, bss->country_code, COUNTRY_CODE_LENGTH); #endif SUPPLICANT_DBG("New network %s created", network->name); @@ -2079,6 +2095,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data) #define WPS_CONFIGURED 0x02 #if defined TIZEN_EXT #define VENDOR_SPECIFIC_INFO 0xDD +#define WLAN_EID_COUNTRY 7 #endif dbus_message_iter_recurse(iter, &array); @@ -2089,6 +2106,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data) bss->wps_capabilities = 0; bss->keymgmt = 0; + memset(bss->country_code, 0, COUNTRY_CODE_LENGTH); for (ie_end = ie + ie_len; ie < ie_end && ie + ie[1] + 1 <= ie_end; ie += ie[1] + 2) { @@ -2108,6 +2126,11 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data) SUPPLICANT_DBG("Failed to allocate memory"); continue; } + + if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) { + memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH); + continue; + } #endif if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN || memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) diff --git a/include/network.h b/include/network.h index baf1c01..63c4e44 100755 --- a/include/network.h +++ b/include/network.h @@ -157,6 +157,9 @@ int connman_network_get_disconnect_reason(struct connman_network *network); int connman_network_get_assoc_status_code(struct connman_network *network); int connman_network_set_assoc_status_code(struct connman_network *network, int assoc_status_code); +int connman_network_set_countrycode(struct connman_network *network, const + unsigned char *country_code); +unsigned char *connman_network_get_countrycode(struct connman_network *network); #endif int connman_network_set_name(struct connman_network *network, diff --git a/plugins/wifi.c b/plugins/wifi.c index a9ffad0..91732bd 100755 --- a/plugins/wifi.c +++ b/plugins/wifi.c @@ -3417,6 +3417,7 @@ static void network_added(GSupplicantNetwork *supplicant_network) #if defined TIZEN_EXT GSList *vsie_list = NULL; + const unsigned char *country_code; #endif mode = g_supplicant_network_get_mode(supplicant_network); @@ -3472,6 +3473,8 @@ static void network_added(GSupplicantNetwork *supplicant_network) connman_network_set_vsie_list(network, vsie_list); else DBG("vsie_list is NULL"); + country_code = g_supplicant_network_get_countrycode(supplicant_network); + connman_network_set_countrycode(network, country_code); #endif connman_network_set_string(network, "WiFi.Security", security); connman_network_set_strength(network, @@ -3593,6 +3596,7 @@ static void network_changed(GSupplicantNetwork *network, const char *property) unsigned int maxrate; uint16_t frequency; bool wps; + const unsigned char *country_code; #endif interface = g_supplicant_network_get_interface(network); @@ -3625,6 +3629,8 @@ static void network_changed(GSupplicantNetwork *network, const char *property) connman_network_set_maxrate(connman_network, maxrate); connman_network_set_frequency(connman_network, frequency); connman_network_set_bool(connman_network, "WiFi.WPS", wps); + country_code = g_supplicant_network_get_countrycode(network); + connman_network_set_countrycode(connman_network, country_code); #endif } diff --git a/src/connman.h b/src/connman.h index a5977b8..d1069b9 100755 --- a/src/connman.h +++ b/src/connman.h @@ -24,6 +24,9 @@ #include #define CONNMAN_API_SUBJECT_TO_CHANGE +#if defined TIZEN_EXT +#define WIFI_COUNTRY_CODE_LEN 2 +#endif #include diff --git a/src/network.c b/src/network.c index 0e3d4b3..eb2d039 100755 --- a/src/network.c +++ b/src/network.c @@ -119,6 +119,7 @@ struct connman_network { * Only for EAP-FAST */ char *phase1; + unsigned char country_code[WIFI_COUNTRY_CODE_LEN]; #endif } wifi; @@ -2076,6 +2077,29 @@ int connman_network_get_assoc_status_code(struct connman_network *network) return network->wifi.assoc_status_code; } + +int connman_network_set_countrycode(struct connman_network *network, + const unsigned char *country_code) +{ + int i = 0; + + if (country_code == NULL) + return -EINVAL; + + DBG("network %p Country Code %02x:%02x",network, + country_code[0],country_code[1]); + + for (; i < WIFI_COUNTRY_CODE_LEN; i++) + network->wifi.country_code[i] = country_code[i]; + + return 0; +} + +unsigned char *connman_network_get_countrycode(struct connman_network *network) +{ + return (unsigned char *)network->wifi.country_code; +} + #endif int connman_network_set_nameservers(struct connman_network *network, diff --git a/src/service.c b/src/service.c index c3bdc0e..b533dcd 100755 --- a/src/service.c +++ b/src/service.c @@ -3230,6 +3230,9 @@ static void append_wifi_ext_info(DBusMessageIter *dict, const char *enc_mode; const char *str; gboolean passpoint; + char country_code_buff[WIFI_COUNTRY_CODE_LEN + 1] = {0,}; + char *country_code_str = country_code_buff; + unsigned char *country_code; ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len); bssid = connman_network_get_bssid(network); @@ -3238,11 +3241,16 @@ static void append_wifi_ext_info(DBusMessageIter *dict, enc_mode = connman_network_get_enc_mode(network); passpoint = connman_network_get_bool(network, "WiFi.HS20AP"); keymgmt = connman_network_get_keymgmt(network); + country_code = connman_network_get_countrycode(network); snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x", bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]); + snprintf(country_code_str, (WIFI_COUNTRY_CODE_LEN + 1), "%c%c", + country_code[0], country_code[1]); + + connman_dbus_dict_append_fixed_array(dict, "SSID", DBUS_TYPE_BYTE, &ssid, ssid_len); connman_dbus_dict_append_basic(dict, "BSSID", @@ -3257,6 +3265,8 @@ static void append_wifi_ext_info(DBusMessageIter *dict, DBUS_TYPE_BOOLEAN, &passpoint); connman_dbus_dict_append_basic(dict, "Keymgmt", DBUS_TYPE_UINT32, &keymgmt); + connman_dbus_dict_append_basic(dict, "Country", DBUS_TYPE_STRING, + &country_code_str); str = connman_network_get_string(network, "WiFi.Security"); if (str != NULL && g_str_equal(str, "ieee8021x") == TRUE) { -- 2.7.4