From: Niraj Kumar Goit Date: Thu, 5 Apr 2018 06:27:15 +0000 (+0530) Subject: Add SSID and Frequency mixed scan. X-Git-Tag: accepted/tizen/unified/20180417.173158^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fupstream%2Fconnman.git;a=commitdiff_plain;h=22367513ced9ff5921eb6b1dd7b65c5d108b2a99 Add SSID and Frequency mixed scan. Change-Id: I6ca91a5f073c11712a936844589aa72c27c0145e Signed-off-by: Niraj Kumar Goit --- diff --git a/include/technology.h b/include/technology.h index 55bb3dd..73cd8e7 100755 --- a/include/technology.h +++ b/include/technology.h @@ -34,6 +34,19 @@ extern "C" { * @short_description: Functions for handling technology details */ +#if defined TIZEN_EXT +typedef enum { + CONNMAN_MULTI_SCAN_SSID = 0x01, + CONNMAN_MULTI_SCAN_FREQ, + CONNMAN_MULTI_SCAN_SSID_FREQ, +} connman_multi_scan_type_e; + +typedef struct { + char str[128]; + gboolean flag; +} connman_multi_scan_ap_s; +#endif + struct connman_technology; int connman_technology_tethering_add_station(enum connman_service_type type, diff --git a/plugins/wifi.c b/plugins/wifi.c index 3135484..a9ffad0 100755 --- a/plugins/wifi.c +++ b/plugins/wifi.c @@ -2075,7 +2075,7 @@ static int wifi_specific_scan(enum connman_service_type type, return -EALREADY; DBG("scan_type: %d", scan_type); - if (scan_type == 1) { /* ssid based scan */ + if (scan_type == CONNMAN_MULTI_SCAN_SSID) { /* ssid based scan */ scan_params = g_try_malloc0(sizeof(GSupplicantScanParams)); if (!scan_params) { DBG("Failed to allocate memory."); @@ -2101,7 +2101,7 @@ static int wifi_specific_scan(enum connman_service_type type, } scan_params->num_ssids = count; - } else if (scan_type == 2) { /* frequency based scan */ + } else if (scan_type == CONNMAN_MULTI_SCAN_FREQ) { /* frequency based scan */ scan_params = g_try_malloc0(sizeof(GSupplicantScanParams)); if (!scan_params) { @@ -2129,6 +2129,51 @@ static int wifi_specific_scan(enum connman_service_type type, } scan_params->num_freqs = count; + } else if (scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { /* SSID & Frequency mixed scan */ + int freq_count, ap_count; + scan_params = g_try_malloc0(sizeof(GSupplicantScanParams)); + if (!scan_params) { + DBG("Failed to allocate memory."); + return -ENOMEM; + } + + guint size = g_slist_length(specific_scan_list); + + scan_params->freqs = g_try_new0(uint16_t, size/2); + if (!scan_params->freqs) { + DBG("Failed to allocate memory."); + g_free(scan_params); + return -ENOMEM; + } + + ap_count = freq_count = 0; + for (list = specific_scan_list; list; list = list->next) { + if (((connman_multi_scan_ap_s *)list->data)->flag == true) { /** ssid */ + ssid = ((connman_multi_scan_ap_s *)list->data)->str; + int ssid_len = strlen(ssid); + + scan_ssid = g_try_new0(struct scan_ssid, 1); + if (!scan_ssid) { + DBG("Failed to allocate memory."); + g_supplicant_free_scan_params(scan_params); + return -ENOMEM; + } + + memcpy(scan_ssid->ssid, ssid, (ssid_len + 1)); + DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); + scan_ssid->ssid_len = ssid_len; + scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid); + ap_count++; + + } else { /* freq */ + freq = atoi(((connman_multi_scan_ap_s *)list->data)->str); + scan_params->freqs[freq_count] = freq; + DBG("scan_params->freqs[%d]: %d", freq_count, scan_params->freqs[freq_count]); + freq_count++; + } + } + scan_params->num_ssids = ap_count; + scan_params->num_freqs = freq_count; } else { DBG("Invalid scan"); return -EINVAL; diff --git a/src/technology.c b/src/technology.c index 5d5b70f..57ab8e1 100755 --- a/src/technology.c +++ b/src/technology.c @@ -27,6 +27,7 @@ #include #if defined TIZEN_EXT #include +#include #endif #include @@ -1280,7 +1281,7 @@ static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void * GSList *specific_scan_list = NULL; int scan_type = 0; const char *name = NULL; - unsigned int freq = 0; + const char *freq = NULL; DBusMessageIter iter, dict; int err; @@ -1321,20 +1322,53 @@ static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void * return __connman_error_invalid_arguments(msg); } - scan_type = 1; /* SSID based scan */ + scan_type = CONNMAN_MULTI_SCAN_SSID; /* SSID based scan */ dbus_message_iter_get_basic(&value2, &name); DBG("name %s", name); specific_scan_list = g_slist_append(specific_scan_list, g_strdup(name)); } else if (g_str_equal(key, "Frequency")) { - if (type != DBUS_TYPE_UINT16) { + if (type != DBUS_TYPE_STRING) { + g_slist_free_full(specific_scan_list, g_free); + return __connman_error_invalid_arguments(msg); + } + + scan_type = CONNMAN_MULTI_SCAN_FREQ; /* Frequency based scan */ + dbus_message_iter_get_basic(&value2, &freq); + DBG("freq %s", freq); + specific_scan_list = g_slist_append(specific_scan_list, GINT_TO_POINTER(atoi(freq))); + } else if (g_str_equal(key, "SSID_Mixed")) { + if (type != DBUS_TYPE_STRING) { + g_slist_free_full(specific_scan_list, g_free); + return __connman_error_invalid_arguments(msg); + } + + scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */ + dbus_message_iter_get_basic(&value2, &name); + + connman_multi_scan_ap_s *ap = (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s)); + if (ap) { + g_strlcpy(ap->str, name, strlen(name) + 1); + ap->flag = true; + specific_scan_list = g_slist_append(specific_scan_list, ap); + } else + DBG("Failed to allocate memory"); + + } else if (g_str_equal(key, "Frequency_Mixed")) { + if (type != DBUS_TYPE_STRING) { g_slist_free_full(specific_scan_list, g_free); return __connman_error_invalid_arguments(msg); } - scan_type = 2; /* Frequency based scan */ + scan_type = CONNMAN_MULTI_SCAN_SSID_FREQ; /* SSID & Frequency mixed scan */ dbus_message_iter_get_basic(&value2, &freq); - DBG("freq %d", freq); - specific_scan_list = g_slist_append(specific_scan_list, GINT_TO_POINTER(freq)); + + connman_multi_scan_ap_s *ap = (connman_multi_scan_ap_s*)g_try_malloc0(sizeof(connman_multi_scan_ap_s)); + if (ap) { + g_strlcpy(ap->str, freq, strlen(freq) + 1); + ap->flag = false; + specific_scan_list = g_slist_append(specific_scan_list, ap); + } else + DBG("Failed to allocate memory"); } dbus_message_iter_next(&dict); } @@ -1356,7 +1390,8 @@ static DBusMessage *specific_scan(DBusConnection *conn, DBusMessage *msg, void * technology->scan_pending = g_slist_prepend(technology->scan_pending, msg); - if (scan_type == 1) { + if (scan_type == CONNMAN_MULTI_SCAN_SSID || + scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { g_slist_free_full(specific_scan_list, g_free); scan_type = 0; }