summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaehyun Kim <jeik01.kim@samsung.com>2024-08-20 14:27:33 +0900
committerJaehyun Kim <jeik01.kim@samsung.com>2024-08-20 17:07:07 +0900
commit081e3a5fa55d56c100bf1675449097335d4dac27 (patch)
tree0454626c850badc80465f38b65e9465d0e6b7210
parenta0c21eabcf3994537ca506b788acebc26862f2e8 (diff)
downloadconnman-081e3a5fa55d56c100bf1675449097335d4dac27.tar.gz
connman-081e3a5fa55d56c100bf1675449097335d4dac27.tar.bz2
connman-081e3a5fa55d56c100bf1675449097335d4dac27.zip
Support Wi-Fi band selection for scanning
Change-Id: I6215077d2cb467df4e56039491146062f9aca6e9 Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
-rwxr-xr-xgsupplicant/gsupplicant.h1
-rwxr-xr-xgsupplicant/supplicant.c126
-rwxr-xr-xinclude/device.h1
-rwxr-xr-xinclude/setting.h8
-rwxr-xr-xinclude/technology.h4
-rw-r--r--plugins/ethernet.c2
-rwxr-xr-xplugins/wifi.c3
-rwxr-xr-xsrc/device.c4
-rw-r--r--src/technology.c69
9 files changed, 214 insertions, 4 deletions
diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 4e841df0..f7a59d3a 100755
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -353,6 +353,7 @@ int g_supplicant_interface_create(const char *ifname, const char *driver,
unsigned int mac_policy,
unsigned int preassoc_mac_policy,
unsigned int random_mac_lifetime,
+ int wifi_scan_band,
#endif /* TIZEN_EXT */
GSupplicantInterfaceCallback callback,
void *user_data);
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 723f2cfb..5233fab3 100755
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -193,6 +193,18 @@ static struct _GSupplicantINSSettings ins_settings;
static unsigned char invalid_bssid[WIFI_BSSID_LEN_MAX] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
+
+static const uint16_t wifi_band_freqs_2_4ghz[] = {
+ 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457,
+ 2462, 2467, 2472, 0,
+};
+
+static const uint16_t wifi_band_freqs_5ghz[] = {
+ 5180, 5200, 5220, 5240, 5260, 5280, 5300, 5320, 5500, 5520,
+ 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, 5700, 0,
+};
+
+static int wifi_band_selection_method = WIFI_BAND_SELECTION_ALL;
#endif /* defined TIZEN_EXT */
static GHashTable *interface_table;
@@ -6211,6 +6223,7 @@ int g_supplicant_interface_create(const char *ifname, const char *driver,
unsigned int mac_policy,
unsigned int preassoc_mac_policy,
unsigned int random_mac_lifetime,
+ int wifi_scan_band,
#endif /* TIZEN_EXT */
GSupplicantInterfaceCallback callback,
void *user_data)
@@ -6230,6 +6243,11 @@ int g_supplicant_interface_create(const char *ifname, const char *driver,
if (!data)
return -ENOMEM;
+#ifdef TIZEN_EXT
+ if (wifi_scan_band >= 0)
+ wifi_band_selection_method = wifi_scan_band;
+#endif
+
data->ifname = g_strdup(ifname);
data->driver = g_strdup(driver);
data->bridge = g_strdup(bridge);
@@ -6577,6 +6595,108 @@ int g_supplicant_interface_abort_scan(GSupplicantInterface *interface,
}
#endif
+#if defined TIZEN_EXT
+static void print_scan_freqs(GSupplicantScanParams *scan_data)
+{
+ if (!scan_data || scan_data->num_freqs == 0)
+ return;
+
+ GString *str;
+
+ str = g_string_new("Scan freqs: ");
+ if (!str)
+ return;
+
+ for (int i = 0; i < scan_data->num_freqs; i++)
+ g_string_append_printf(str, " %d", scan_data->freqs[i]);
+
+ gchar *freqs_str = g_string_free(str, FALSE);
+ SUPPLICANT_DBG("%s", freqs_str);
+
+ g_free(freqs_str);
+}
+
+static bool set_band_freqs_2_4ghz(GSupplicantScanParams *scan_data)
+{
+ int count = 0;
+
+ while (wifi_band_freqs_2_4ghz[count])
+ count++;
+
+ scan_data->freqs = g_try_new0(uint16_t, count);
+ if (!scan_data->freqs) {
+ SUPPLICANT_DBG("Failed to allocate memory.");
+ return false;
+ }
+
+ scan_data->num_freqs = count;
+ for (int i = 0; i < count; i++)
+ scan_data->freqs[i] = wifi_band_freqs_2_4ghz[i];
+
+ return true;
+}
+
+static bool set_band_freqs_5ghz(GSupplicantScanParams *scan_data)
+{
+ int count = 0;
+
+ while (wifi_band_freqs_5ghz[count])
+ count++;
+
+ scan_data->freqs = g_try_new0(uint16_t, count);
+ if (!scan_data->freqs) {
+ SUPPLICANT_DBG("Failed to allocate memory.");
+ return false;
+ }
+
+ scan_data->num_freqs = count;
+ for (int i = 0; i < count; i++)
+ scan_data->freqs[i] = wifi_band_freqs_5ghz[i];
+
+ return true;
+}
+
+static void set_band_freqs(GSupplicantScanParams **scan_data)
+{
+ GSupplicantScanParams *scan_data_local = NULL;
+
+ if (*scan_data && ((*scan_data)->num_ssids != 0 || (*scan_data)->num_freqs != 0))
+ return;
+
+ scan_data_local = g_try_malloc0(sizeof(GSupplicantScanParams));
+ if (!scan_data_local) {
+ SUPPLICANT_DBG("Failed to allocate memory.");
+ return;
+ }
+
+ switch (wifi_band_selection_method) {
+ case WIFI_BAND_SELECTION_2_4GHZ:
+ if (!set_band_freqs_2_4ghz(scan_data_local)) {
+ g_free(scan_data_local);
+ return;
+ }
+ break;
+ case WIFI_BAND_SELECTION_5GHZ:
+ if (!set_band_freqs_5ghz(scan_data_local)) {
+ g_free(scan_data_local);
+ return;
+ }
+ break;
+ case WIFI_BAND_SELECTION_6GHZ:
+ /* Currently not supported */
+ /* fall through */
+ default:
+ g_free(scan_data_local);
+ return;
+ }
+
+ if (*scan_data)
+ g_supplicant_free_scan_params(*scan_data);
+
+ *scan_data = scan_data_local;
+}
+#endif
+
int g_supplicant_interface_scan(GSupplicantInterface *interface,
GSupplicantScanParams *scan_data,
GSupplicantInterfaceCallback callback,
@@ -6598,14 +6718,16 @@ int g_supplicant_interface_scan(GSupplicantInterface *interface,
#if defined TIZEN_EXT
data->interface->scan_callback = data->callback = callback;
data->interface->scan_data = data->user_data = user_data;
+ set_band_freqs(&scan_data);
+ print_scan_freqs(scan_data);
#else
data->callback = callback;
data->user_data = user_data;
#endif
data->scan_params = scan_data;
- interface->scan_callback = callback;
- interface->scan_data = user_data;
+ interface->scan_callback = callback;
+ interface->scan_data = user_data;
ret = supplicant_dbus_method_call(interface->path,
SUPPLICANT_INTERFACE ".Interface", "Scan",
diff --git a/include/device.h b/include/device.h
index acbd1d54..b2d9bb10 100755
--- a/include/device.h
+++ b/include/device.h
@@ -170,6 +170,7 @@ void connman_device_random_mac_lifetime_notify(struct connman_device *device,
int connman_device_set_random_mac_lifetime(struct connman_device *device,
unsigned int lifetime);
unsigned int connman_device_get_random_mac_lifetime(struct connman_device *device);
+int connman_device_get_wifi_scan_band(struct connman_device *device);
#endif
struct connman_device_driver {
diff --git a/include/setting.h b/include/setting.h
index 4fb4957b..14f05f0f 100755
--- a/include/setting.h
+++ b/include/setting.h
@@ -35,6 +35,14 @@ typedef enum {
AP_SELECTION_METHOD_INS = 1,
} ap_selection_method_e;
+/* Wi-Fi band to scan */
+typedef enum {
+ WIFI_BAND_SELECTION_ALL = 0,
+ WIFI_BAND_SELECTION_2_4GHZ = 1,
+ WIFI_BAND_SELECTION_5GHZ = 2,
+ WIFI_BAND_SELECTION_6GHZ = 3,
+} wifi_band_selection_e;
+
#define TIZEN_INS_ENABLED \
(connman_setting_get_int("ApSelectionMethod") == AP_SELECTION_METHOD_INS)
diff --git a/include/technology.h b/include/technology.h
index c7898396..1eafb6d6 100755
--- a/include/technology.h
+++ b/include/technology.h
@@ -23,6 +23,9 @@
#define __CONNMAN_TECHNOLOGY_H
#include <connman/service.h>
+#if defined TIZEN_EXT
+#include <connman/device.h>
+#endif
#ifdef __cplusplus
extern "C" {
@@ -91,6 +94,7 @@ struct connman_technology_driver {
int connman_technology_driver_register(struct connman_technology_driver *driver);
void connman_technology_driver_unregister(struct connman_technology_driver *driver);
#if defined TIZEN_EXT
+int connman_technology_get_wifi_scan_band(struct connman_device *device);
const char *connman_techonology_get_path(enum connman_service_type type);
void __connman_technology_notify_scan_done(const char *ifname, int val);
void __connman_technology_append_interfaces(DBusMessageIter *array,
diff --git a/plugins/ethernet.c b/plugins/ethernet.c
index 9d64abe4..e4bfeb28 100644
--- a/plugins/ethernet.c
+++ b/plugins/ethernet.c
@@ -253,7 +253,7 @@ static int eapol_interface_create(void)
* already created interface will not start EAP handshake.
*/
return g_supplicant_interface_create(ifname, driver, NULL,
- 0, 0, 60, interface_create_callback, ethernet);
+ 0, 0, 60, -1, interface_create_callback, ethernet);
}
static void enable_eapol_reply(DBusPendingCall *call, void *user_data)
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 5980703c..836a540b 100755
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2794,6 +2794,7 @@ static int wifi_enable(struct connman_device *device)
connman_device_get_mac_policy(device),
connman_device_get_preassoc_mac_policy(device),
connman_device_get_random_mac_lifetime(device),
+ connman_device_get_wifi_scan_band(device),
#endif /* TIZEN_EXT */
interface_create_callback,
wifi);
@@ -6630,7 +6631,7 @@ static void sta_remove_callback(int result,
g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
#ifdef TIZEN_EXT
- 0, 0, 60,
+ 0, 0, 60, -1,
#endif /* TIZEN_EXT */
ap_create_callback,
info);
diff --git a/src/device.c b/src/device.c
index da86084f..580e325d 100755
--- a/src/device.c
+++ b/src/device.c
@@ -2324,4 +2324,8 @@ unsigned int connman_device_get_random_mac_lifetime(struct connman_device *devic
return device->random_mac_lifetime;
}
+int connman_device_get_wifi_scan_band(struct connman_device *device)
+{
+ return connman_technology_get_wifi_scan_band(device);
+}
#endif
diff --git a/src/technology.c b/src/technology.c
index d21d790f..1b17db2f 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -104,6 +104,7 @@ struct connman_technology {
unsigned int mac_policy;
unsigned int preassoc_mac_policy;
unsigned int random_mac_lifetime;
+ char *wifi_band_selection;
#endif
#if defined TIZEN_EXT_WIFI_MESH
DBusMessage *mesh_dbus_msg;
@@ -234,6 +235,11 @@ static void technology_save(struct connman_technology *technology)
g_key_file_set_uint64(keyfile, identifier, "RandomMacLifetime",
technology->random_mac_lifetime);
+
+ if (technology->wifi_band_selection)
+ g_key_file_set_string(keyfile, identifier,
+ "WifiBandSelection",
+ technology->wifi_band_selection);
}
#endif /* TIZEN_EXT */
if (technology->tethering_freq == 0)
@@ -397,6 +403,47 @@ static struct connman_technology *technology_find(enum connman_service_type type
return NULL;
}
+#if defined TIZEN_EXT
+static void connman_technology_set_wifi_scan_band(
+ struct connman_technology *technology, const char *band)
+{
+ if (!band)
+ return;
+
+ if (technology->wifi_band_selection)
+ g_free(technology->wifi_band_selection);
+
+ technology->wifi_band_selection = g_strdup(band);
+
+ technology_save(technology);
+}
+
+int connman_technology_get_wifi_scan_band(struct connman_device *device)
+{
+ struct connman_technology *technology;
+ enum connman_service_type type;
+
+ DBG("device %p", device);
+
+ type = __connman_device_get_service_type(device);
+
+ technology = technology_find(type);
+ if (!technology || !technology->wifi_band_selection)
+ return WIFI_BAND_SELECTION_ALL;
+
+ if (g_str_equal(technology->wifi_band_selection, "all"))
+ return WIFI_BAND_SELECTION_ALL;
+ else if (g_str_equal(technology->wifi_band_selection, "2.4GHz"))
+ return WIFI_BAND_SELECTION_2_4GHZ;
+ else if (g_str_equal(technology->wifi_band_selection, "5GHz"))
+ return WIFI_BAND_SELECTION_5GHZ;
+ else if (g_str_equal(technology->wifi_band_selection, "6GHz"))
+ return WIFI_BAND_SELECTION_6GHZ;
+
+ return WIFI_BAND_SELECTION_ALL;
+}
+#endif
+
enum connman_service_type connman_technology_get_type
(struct connman_technology *technology)
{
@@ -529,6 +576,7 @@ static void technology_load(struct connman_technology *technology)
#ifdef TIZEN_EXT
if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
unsigned int val = 0;
+ char *scan_band = NULL;
val = g_key_file_get_uint64(keyfile,
identifier, "MacPolicy", NULL);
@@ -550,6 +598,13 @@ static void technology_load(struct connman_technology *technology)
technology->random_mac_lifetime = val;
else
technology->random_mac_lifetime = 60;
+
+ scan_band = g_key_file_get_string(keyfile,
+ identifier, "WifiBandSelection", NULL);
+ if (scan_band)
+ technology->wifi_band_selection = scan_band;
+ else
+ technology->wifi_band_selection = g_strdup("all");
}
#endif /* TIZEN_EXT */
@@ -754,10 +809,16 @@ static void append_properties(DBusMessageIter *iter,
if (technology->type == CONNMAN_SERVICE_TYPE_WIFI)
connman_dbus_dict_append_dict(&dict, "Device.List",
append_devices, technology);
+
if (technology->regdom)
connman_dbus_dict_append_basic(&dict, "CountryCode",
DBUS_TYPE_STRING,
&technology->regdom);
+
+ if (technology->wifi_band_selection)
+ connman_dbus_dict_append_basic(&dict, "WifiBandSelection",
+ DBUS_TYPE_STRING,
+ &technology->wifi_band_selection);
#endif
connman_dbus_dict_append_basic(&dict, "TetheringFreq",
DBUS_TYPE_INT32,
@@ -1553,6 +1614,13 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(&value, &str);
DBG("country code %s", str);
connman_technology_set_regdom(str);
+ } else if (g_str_equal(name, "WifiBandSelection")) {
+ const char *str;
+
+ dbus_message_iter_get_basic(&value, &str);
+ DBG("WifiBandSelection %s", str);
+
+ connman_technology_set_wifi_scan_band(technology, str);
#endif
} else
return __connman_error_invalid_property(msg);
@@ -3032,6 +3100,7 @@ static void technology_put(struct connman_technology *technology)
}
#ifdef TIZEN_EXT
g_strfreev(technology->enabled_devices);
+ g_free(technology->wifi_band_selection);
#endif
g_free(technology->path);
g_free(technology->regdom);