From 6c73f51b34fa18a1a9b4582f0e1dfcaee8f2fa5e Mon Sep 17 00:00:00 2001 From: Mayank Haarit Date: Fri, 20 Apr 2018 20:57:32 +0530 Subject: [PATCH] Add BSSID , signal strength and frequency list of the APs This patch sends the list of BSSID, signal strength and frequency of an APs having same SSID and Security type. Change-Id: I368d37de310687ca173418dfad91fae7082b2357 Signed-off-by: Mayank Haarit --- gsupplicant/gsupplicant.h | 1 + gsupplicant/supplicant.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ include/network.h | 11 +++++++++++ plugins/wifi.c | 5 +++++ src/network.c | 14 ++++++++++++++ src/service.c | 32 ++++++++++++++++++++++++++++++- 6 files changed, 110 insertions(+), 1 deletion(-) diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h index 0a28dbf..3dff2b4 100755 --- a/gsupplicant/gsupplicant.h +++ b/gsupplicant/gsupplicant.h @@ -399,6 +399,7 @@ 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); +void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network); #endif struct _GSupplicantCallbacks { diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c index fbfa6c7..c154a0e 100644 --- a/gsupplicant/supplicant.c +++ b/gsupplicant/supplicant.c @@ -321,6 +321,14 @@ struct interface_scan_data { void *user_data; }; +#if defined TIZEN_EXT +struct g_connman_bssids { + char bssid[18]; + uint16_t strength; + uint16_t frequency; +}; +#endif + static int network_remove(struct interface_data *data); static inline void debug(const char *format, ...) @@ -1595,6 +1603,46 @@ void *g_supplicant_network_get_wifi_vsie(GSupplicantNetwork *network) return vsie_list; } + +static void update_bssid_list(gpointer key, gpointer value, gpointer user_data) +{ + struct g_supplicant_bss *bss = value; + struct g_connman_bssids *bssids = NULL; + char buff[18]; + GSList **list = (GSList **)user_data; + + bssids = (struct g_connman_bssids *)g_try_malloc0(sizeof(struct g_connman_bssids)); + + if (bssids) { + g_snprintf(buff, 18, "%02x:%02x:%02x:%02x:%02x:%02x", + bss->bssid[0], bss->bssid[1], bss->bssid[2], bss->bssid[3], + bss->bssid[4], bss->bssid[5]); + + memcpy(bssids->bssid, buff, 18); + bssids->bssid[17] = '\0'; + bssids->strength = bss->signal; + bssids->strength += 120; + + if (bssids->strength > 100) + bssids->strength = 100; + + bssids->frequency = bss->frequency; + *list = g_slist_append(*list, bssids); + } else + SUPPLICANT_DBG("Failed to allocate memory"); +} + +void *g_supplicant_network_get_bssid_list(GSupplicantNetwork *network) +{ + GSList *bssid_list = NULL; + + if (g_hash_table_size(network->bss_table) < 1) + return NULL; + + g_hash_table_foreach(network->bss_table, update_bssid_list, &bssid_list); + + return bssid_list; +} #endif static void merge_network(GSupplicantNetwork *network) diff --git a/include/network.h b/include/network.h index 63c4e44..98fa7d7 100755 --- a/include/network.h +++ b/include/network.h @@ -62,6 +62,14 @@ enum connman_network_error { }; +#if defined TIZEN_EXT +struct connman_bssids { + char bssid[18]; + uint16_t strength; + uint16_t frequency; +}; +#endif + #define CONNMAN_NETWORK_PRIORITY_LOW -100 #define CONNMAN_NETWORK_PRIORITY_DEFAULT 0 #define CONNMAN_NETWORK_PRIORITY_HIGH 100 @@ -160,6 +168,9 @@ int connman_network_set_assoc_status_code(struct connman_network *network, int connman_network_set_countrycode(struct connman_network *network, const unsigned char *country_code); unsigned char *connman_network_get_countrycode(struct connman_network *network); +int connman_network_set_bssid_list(struct connman_network *network, + GSList *bssids); +void *connman_network_get_bssid_list(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 91732bd..aad3b2c 100755 --- a/plugins/wifi.c +++ b/plugins/wifi.c @@ -3509,6 +3509,8 @@ static void network_added(GSupplicantNetwork *supplicant_network) g_supplicant_network_get_keymgmt(supplicant_network)); connman_network_set_bool(network, "WiFi.HS20AP", g_supplicant_network_is_hs20AP(supplicant_network)); + connman_network_set_bssid_list(network, + (GSList *)g_supplicant_network_get_bssid_list(supplicant_network)); #endif connman_network_set_available(network, true); connman_network_set_string(network, "WiFi.Mode", mode); @@ -3597,6 +3599,7 @@ static void network_changed(GSupplicantNetwork *network, const char *property) uint16_t frequency; bool wps; const unsigned char *country_code; + GSList *bssid_list; #endif interface = g_supplicant_network_get_interface(network); @@ -3631,6 +3634,8 @@ static void network_changed(GSupplicantNetwork *network, const char *property) 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); + bssid_list = (GSList *)g_supplicant_network_get_bssid_list(network); + connman_network_set_bssid_list(connman_network, bssid_list); #endif } diff --git a/src/network.c b/src/network.c index eb2d039..c5b5c97 100755 --- a/src/network.c +++ b/src/network.c @@ -120,6 +120,7 @@ struct connman_network { */ char *phase1; unsigned char country_code[WIFI_COUNTRY_CODE_LEN]; + GSList *bssid_list; #endif } wifi; @@ -985,6 +986,7 @@ static void network_destruct(struct connman_network *network) g_free(network->wifi.pin_wps); #if defined TIZEN_EXT g_slist_free_full(network->wifi.vsie_list, g_free); + g_slist_free_full(network->wifi.bssid_list, g_free); #endif g_free(network->path); g_free(network->group); @@ -2100,6 +2102,18 @@ unsigned char *connman_network_get_countrycode(struct connman_network *network) return (unsigned char *)network->wifi.country_code; } +int connman_network_set_bssid_list(struct connman_network *network, + GSList *bssids) +{ + network->wifi.bssid_list = bssids; + + return 0; +} + +void *connman_network_get_bssid_list(struct connman_network *network) +{ + return network->wifi.bssid_list; +} #endif int connman_network_set_nameservers(struct connman_network *network, diff --git a/src/service.c b/src/service.c index b533dcd..b042461 100755 --- a/src/service.c +++ b/src/service.c @@ -3303,6 +3303,33 @@ static void append_wifi_ext_info(DBusMessageIter *dict, DBUS_TYPE_STRING, &str); } } + +static void append_bssid_info(DBusMessageIter *iter, void *user_data) +{ + GSList *bssid_list = NULL; + struct connman_network *network = user_data; + struct connman_bssids *bssids; + char bssid_buf[18] = {0,}; + char *bssid_str = bssid_buf; + + bssid_list = (GSList *)connman_network_get_bssid_list(network); + if(bssid_list) { + GSList *list; + for (list = bssid_list; list; list = list->next) { + bssids = (struct connman_bssids *)list->data; + memcpy(bssid_str, bssids->bssid, 18); + + connman_dbus_dict_append_basic(iter, "BSSID", + DBUS_TYPE_STRING, &bssid_str); + + connman_dbus_dict_append_basic(iter, "Strength", + DBUS_TYPE_UINT16, &bssids->strength); + + connman_dbus_dict_append_basic(iter, "Frequency", + DBUS_TYPE_UINT16, &bssids->frequency); + } + } +} #endif static void append_properties(DBusMessageIter *dict, dbus_bool_t limited, @@ -3406,8 +3433,11 @@ static void append_properties(DBusMessageIter *dict, dbus_bool_t limited, break; case CONNMAN_SERVICE_TYPE_WIFI: #if defined TIZEN_EXT - if (service->network != NULL) + if (service->network != NULL) { append_wifi_ext_info(dict, service->network); + connman_dbus_dict_append_dict(dict, "BSSID.List", + append_bssid_info, service->network); + } connman_dbus_dict_append_dict(dict, "Ethernet", append_ethernet, service); -- 2.7.4