Add wifi-manager handle list for managing multiple Wi-Fi interfaces 50/244350/3
authorPrasadam Prashath Kumar <prasadam.p@samsung.com>
Thu, 17 Sep 2020 10:41:36 +0000 (16:11 +0530)
committerPrasadam Prashath Kumar <prasadam.p@samsung.com>
Wed, 23 Sep 2020 09:18:08 +0000 (14:48 +0530)
  - Detect attached wlan interfaces

Change-Id: I0b9eebcc3f2bfda11d4043795f25d28b997e3a5e
Signed-off-by: Prasadam Prashath Kumar <prasadam.p@samsung.com>
common/wlan_connection.c
common/wlan_connection.h
common/wlan_manager.c
common/wlan_manager.h
packaging/wifi-efl-ug.spec
ui-gadget/viewer_manager.c
ui-gadget/wifi-efl-UG.c

index a646ef3..6d6e25f 100644 (file)
@@ -170,10 +170,14 @@ void wlan_connect_next()
        }
 }
 
-int wlan_initialize(wifi_manager_h *wifi)
+int wlan_initialize(wifi_manager_h *wifi, const char *ifname)
 {
        wifi_handle = wifi;
-       return wifi_manager_initialize(wifi);
+       if (!ifname)
+               return wifi_manager_initialize(wifi);
+
+       INFO_LOG(UG_NAME_NORMAL, "Initialize with interface name[%s]", ifname);
+        return wifi_manager_initialize_with_interface_name(wifi, ifname);
 }
 
 
index b474e13..066a03d 100644 (file)
@@ -27,6 +27,7 @@ extern "C"
 
 #include <glib.h>
 #include <wifi-manager.h>
+#include <wifi-manager-extension.h>
 
 typedef enum {
        WPS_PIN,
@@ -34,7 +35,7 @@ typedef enum {
        WPS_NONE
 } wps_type_t;
 
-int wlan_initialize(wifi_manager_h *wifi);
+int wlan_initialize(wifi_manager_h *wifi, const char *ifname);
 int wlan_disconnect(wifi_manager_ap_h ap, wifi_manager_disconnected_cb callback, void *user_data);
 int wlan_connect(wifi_manager_ap_h ap, wifi_manager_connected_cb callback, void *user_data,
                wps_type_t type, const char *pin);
index a8e398b..3bb421a 100644 (file)
@@ -62,6 +62,7 @@ wlan_manager_object *wlan_manager_get_singleton(void)
                manager_object = g_new0(wlan_manager_object, 1);
                manager_object->message_func = NULL;
                manager_object->refresh_func = NULL;
+               manager_object->active_wifi_index = 0;
        }
 
        return manager_object;
@@ -81,7 +82,7 @@ void *wlan_manager_create(void)
 
 int wlan_manager_update_ap(wifi_manager_ap_h ap)
 {
-       int rv = wifi_manager_update_ap(manager_object->wifi, ap);
+       int rv = wifi_manager_update_ap(manager_object->wifi[manager_object->active_wifi_index], ap);
        if (rv != WIFI_MANAGER_ERROR_NONE)
                ERROR_LOG(COMMON_NAME_ERR, "Unable to update ap handle");
        return rv;
@@ -89,7 +90,7 @@ int wlan_manager_update_ap(wifi_manager_ap_h ap)
 
 int wlan_manager_is_activated(bool *activated)
 {
-       return wifi_manager_is_activated(manager_object->wifi, activated);
+       return wifi_manager_is_activated(manager_object->wifi[manager_object->active_wifi_index], activated);
 }
 
 int wlan_manager_destroy(void)
@@ -101,7 +102,7 @@ int wlan_manager_destroy(void)
                return ret;
        }
 
-       wifi_manager_unset_device_state_changed_cb(manager_object->wifi);
+       wifi_manager_unset_device_state_changed_cb(manager_object->wifi[manager_object->active_wifi_index]);
 
        wlan_manager_deregister_cbs();
 
@@ -109,7 +110,7 @@ int wlan_manager_destroy(void)
 
        connection_manager_destroy();
 
-       ret = wifi_manager_deinitialize(manager_object->wifi);
+       ret = wifi_manager_deinitialize(manager_object->wifi[manager_object->active_wifi_index]);
 
        if (manager_object != NULL) {
                g_free(manager_object);
@@ -125,7 +126,14 @@ int wlan_manager_start(void)
 
        int ret = WLAN_MANAGER_ERR_NONE;
 
-       switch (wlan_initialize(&(manager_object->wifi))) {
+       if (!manager_object->ifname[manager_object->active_wifi_index]) {
+               ret = wlan_initialize(&(manager_object->wifi[manager_object->active_wifi_index]), NULL);
+               if (ret == WIFI_MANAGER_ERROR_NONE)
+                       INFO_LOG(UG_NAME_NORMAL, "Initialize success and return");
+               return ret;
+       }
+
+       switch (wlan_initialize(&(manager_object->wifi[manager_object->active_wifi_index]), manager_object->ifname[manager_object->active_wifi_index])) {
        case WIFI_MANAGER_ERROR_NONE:
                /* Register the callbacks */
                wlan_manager_register_cbs();
@@ -149,7 +157,7 @@ int wlan_manager_start(void)
 
 int wlan_manager_forget(wifi_manager_ap_h ap)
 {
-       return wifi_manager_forget_ap(manager_object->wifi, ap);
+       return wifi_manager_forget_ap(manager_object->wifi[manager_object->active_wifi_index], ap);
 }
 
 static void wlan_manager_network_event_cb(
@@ -433,13 +441,13 @@ static void wlan_manager_register_cbs(void)
 {
        __COMMON_FUNC_ENTER__;
 
-       wifi_manager_set_device_state_changed_cb(manager_object->wifi, wlan_manager_device_state_changed_cb, NULL);
-       wifi_manager_set_connection_state_changed_cb(manager_object->wifi, wlan_manager_connection_state_changed_cb, NULL);
-       wifi_manager_set_rssi_level_changed_cb(manager_object->wifi, wlan_manager_rssi_level_changed_cb, NULL);
+       wifi_manager_set_device_state_changed_cb(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_device_state_changed_cb, NULL);
+       wifi_manager_set_connection_state_changed_cb(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_connection_state_changed_cb, NULL);
+       wifi_manager_set_rssi_level_changed_cb(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_rssi_level_changed_cb, NULL);
 
        memset(&scan_req_data, 0, sizeof(scan_req_data));
        scan_req_data.req_type = WLAN_MANAGER_REQ_TYPE_SCAN_RESULT;
-       wifi_manager_set_background_scan_cb(manager_object->wifi, wlan_manager_network_event_cb, &scan_req_data);
+       wifi_manager_set_background_scan_cb(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_network_event_cb, &scan_req_data);
 
        __COMMON_FUNC_EXIT__;
 }
@@ -458,9 +466,9 @@ static void wlan_manager_deregister_cbs(void)
         * detsroy.
         */
 
-       wifi_manager_unset_background_scan_cb(manager_object->wifi);
-       wifi_manager_unset_connection_state_changed_cb(manager_object->wifi);
-       wifi_manager_unset_rssi_level_changed_cb(manager_object->wifi);
+       wifi_manager_unset_background_scan_cb(manager_object->wifi[manager_object->active_wifi_index]);
+       wifi_manager_unset_connection_state_changed_cb(manager_object->wifi[manager_object->active_wifi_index]);
+       wifi_manager_unset_rssi_level_changed_cb(manager_object->wifi[manager_object->active_wifi_index]);
 
        __COMMON_FUNC_EXIT__;
 }
@@ -524,7 +532,7 @@ wifi_manager_ap_h wlan_manager_get_ap_with_state(int ap_state)
        ap_state_info.state = ap_state;
        ap_state_info.ap = &ap;
 
-       ret_val = wifi_manager_foreach_found_ap(manager_object->wifi, wifi_found_ap_with_state_cb, &ap_state_info);
+       ret_val = wifi_manager_foreach_found_ap(manager_object->wifi[manager_object->active_wifi_index], wifi_found_ap_with_state_cb, &ap_state_info);
        if (ret_val != WIFI_MANAGER_ERROR_NONE)
                return NULL;
 
@@ -533,7 +541,7 @@ wifi_manager_ap_h wlan_manager_get_ap_with_state(int ap_state)
 
 int wlan_manager_get_connected_ap(wifi_manager_ap_h *ap)
 {
-       return wifi_manager_get_connected_ap(manager_object->wifi, ap);
+       return wifi_manager_get_connected_ap(manager_object->wifi[manager_object->active_wifi_index], ap);
 }
 
 int wlan_manager_state_get(void)
@@ -560,7 +568,7 @@ int wlan_manager_state_get(void)
                wifi_manager_connection_state_e connection_state;
                bool activated;
 
-               if (WIFI_MANAGER_ERROR_NONE != wifi_manager_is_activated(manager_object->wifi, &activated)) {
+               if (WIFI_MANAGER_ERROR_NONE != wifi_manager_is_activated(manager_object->wifi[manager_object->active_wifi_index], &activated)) {
                        return WLAN_MANAGER_ERROR;
                } else if (false == activated) {
                        INFO_LOG(COMMON_NAME_LIB, "STATE: WIFI_OFF");
@@ -568,7 +576,7 @@ int wlan_manager_state_get(void)
                        return WLAN_MANAGER_OFF;
                }
 
-               ret_val = wifi_manager_get_connection_state(manager_object->wifi, &connection_state);
+               ret_val = wifi_manager_get_connection_state(manager_object->wifi[manager_object->active_wifi_index], &connection_state);
                if (WIFI_MANAGER_ERROR_NONE != ret_val)
                        return WLAN_MANAGER_ERROR;
 
@@ -630,7 +638,7 @@ int wlan_manager_power_on(void)
                int ret = 0;
                wlan_mgr_req_data_t *req_data = g_new0(wlan_mgr_req_data_t, 1);
                req_data->req_type = WLAN_MANAGER_REQ_TYPE_ACTIVATE;
-               ret = wifi_manager_activate(manager_object->wifi, wlan_manager_network_event_cb, req_data);
+               ret = wifi_manager_activate(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_network_event_cb, req_data);
                if (WIFI_MANAGER_ERROR_NONE != ret && WIFI_MANAGER_ERROR_ALREADY_EXISTS != ret) {
                        ERROR_LOG(UG_NAME_REQ, "Power on request. Error Reason [%d]", ret);
                        g_free(req_data);
@@ -658,7 +666,7 @@ int wlan_manager_power_off(void)
                wlan_mgr_req_data_t *req_data = g_new0(wlan_mgr_req_data_t, 1);
                req_data->req_type = WLAN_MANAGER_REQ_TYPE_DEACTIVATE;
 
-               int ret = wifi_manager_deactivate(manager_object->wifi, wlan_manager_network_event_cb, req_data);
+               int ret = wifi_manager_deactivate(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_network_event_cb, req_data);
                if (WIFI_MANAGER_ERROR_NONE != ret && WIFI_MANAGER_ERROR_ALREADY_EXISTS != ret) {
                        ERROR_LOG(UG_NAME_REQ, "Power off request. Error Reason [%d]", ret);
 
@@ -751,7 +759,7 @@ void wlan_manager_ap_hidden_create(char *ssid, wifi_manager_ap_h *hidden_ap)
 {
        __COMMON_FUNC_ENTER__;
 
-       wifi_manager_ap_hidden_create(manager_object->wifi, ssid, hidden_ap);
+       wifi_manager_ap_hidden_create(manager_object->wifi[manager_object->active_wifi_index], ssid, hidden_ap);
 
        __COMMON_FUNC_EXIT__;
        return;
@@ -760,7 +768,7 @@ int wlan_manager_ap_create(const char *essid, wifi_manager_ap_h *ap)
 {
        __COMMON_FUNC_ENTER__;
 
-       return wifi_manager_ap_create(manager_object->wifi, essid, ap);
+       return wifi_manager_ap_create(manager_object->wifi[manager_object->active_wifi_index], essid, ap);
 
        __COMMON_FUNC_EXIT__;
 }
@@ -849,7 +857,7 @@ int wlan_manager_foreach_found_ap(wifi_manager_found_ap_cb callback, int *profil
 {
        __COMMON_FUNC_ENTER__;
 
-       return wifi_manager_foreach_found_ap(manager_object->wifi, callback, profiles_list_size);
+       return wifi_manager_foreach_found_ap(manager_object->wifi[manager_object->active_wifi_index], callback, profiles_list_size);
 
        __COMMON_FUNC_EXIT__;
 }
@@ -862,7 +870,7 @@ int wlan_manager_scan(void)
        req_data->req_type = WLAN_MANAGER_REQ_TYPE_SCAN;
 
        manager_object->b_scan_blocked = TRUE;
-       int ret = wifi_manager_scan(manager_object->wifi, wlan_manager_network_event_cb, req_data);
+       int ret = wifi_manager_scan(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_network_event_cb, req_data);
        if (ret != WLAN_MANAGER_ERR_NONE) {
                ERROR_LOG(UG_NAME_REQ, "Scan failed. Ret: %d", ret);
 
@@ -885,7 +893,7 @@ int wlan_manager_scan_with_ssid(const char *ssid, void *user_data)
 {
        __COMMON_FUNC_ENTER__;
 
-       int ret = wifi_manager_scan_specific_ap(manager_object->wifi,
+       int ret = wifi_manager_scan_specific_ap(manager_object->wifi[manager_object->active_wifi_index],
                        ssid, wlan_manager_specific_scan_finished_cb, user_data);
        if (ret != WIFI_MANAGER_ERROR_NONE) {
                ERROR_LOG(UG_NAME_REQ, "Specific Scan failed. Ret: %d", ret);
@@ -982,7 +990,7 @@ int wlan_manager_get_connection_state(wifi_manager_connection_state_e *state)
 {
        __COMMON_FUNC_ENTER__;
 
-       return wifi_manager_get_connection_state(manager_object->wifi, state);
+       return wifi_manager_get_connection_state(manager_object->wifi[manager_object->active_wifi_index], state);
 
        __COMMON_FUNC_EXIT__;
 }
@@ -1031,12 +1039,12 @@ void wlan_validate_alt_connection(void)
        case WIFI_MANAGER_CONNECTION_STATE_FAILURE:
        case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
        case WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED:
-               wlan_connect_next(manager_object->wifi);
+               wlan_connect_next(manager_object->wifi[manager_object->active_wifi_index]);
                break;
 
        case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
        case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
-               wlan_go_fast_next(manager_object->wifi);
+               wlan_go_fast_next(manager_object->wifi[manager_object->active_wifi_index]);
                break;
        default:
                break;
@@ -1045,9 +1053,63 @@ void wlan_validate_alt_connection(void)
 
 int wlan_manager_set_autoscan_mode(wlan_manager_autoscan_mode_e mode)
 {
-       int ret = wifi_manager_set_autoscan_mode(manager_object->wifi, mode);
+       int ret = wifi_manager_set_autoscan_mode(manager_object->wifi[manager_object->active_wifi_index], mode);
        if (ret == WIFI_MANAGER_ERROR_NONE)
                return WLAN_MANAGER_ERR_NONE;
        else
                return WLAN_MANAGER_ERR_OPERATION_FAILED;
 }
+
+void wlan_manager_set_active_wifi_index(wlan_manager_wifi_iface_index_e index)
+{
+       manager_object->active_wifi_index = index;
+}
+
+int wlan_mgr_get_index_from_ifname(const char *ifname)
+{
+       if (!ifname)
+               return WLAN_MANAGER_WIFI_IFACE_MAX;
+       if (strncmp(ifname, WLAN_MANAGER_WIFI_WLAN0, strlen(ifname)) == 0)
+               return WLAN_MANAGER_WIFI_IFACE_WLAN0;
+       else if (strncmp(ifname, WLAN_MANAGER_WIFI_WLAN1, strlen(ifname)) == 0)
+               return WLAN_MANAGER_WIFI_IFACE_WLAN1;
+       else if (strncmp(ifname, WLAN_MANAGER_WIFI_WLAN2, strlen(ifname)) == 0)
+               return WLAN_MANAGER_WIFI_IFACE_WLAN2;
+       else if (strncmp(ifname, WLAN_MANAGER_WIFI_WLAN3, strlen(ifname)) == 0)
+               return WLAN_MANAGER_WIFI_IFACE_WLAN3;
+       return WLAN_MANAGER_WIFI_IFACE_MAX;
+}
+
+bool wlan_manager_interface_cb(char *ifname, void *user_data)
+{
+       int index = wlan_mgr_get_index_from_ifname(ifname);
+       if(index >= WLAN_MANAGER_WIFI_IFACE_MAX)
+               return TRUE;
+       manager_object->ifname[index] = g_strdup((char*)ifname);
+       INFO_LOG(UG_NAME_NORMAL, "Avalable ifname[%s] index[%d]", manager_object->ifname[manager_object->interface_count], index);
+       manager_object->interface_count++;
+       return TRUE;
+}
+
+int wlan_manager_get_available_interface(void)
+{
+       __COMMON_FUNC_ENTER__;
+       int ret = WLAN_MANAGER_ERR_NONE;
+
+       switch (wlan_manager_start()) {
+               case WLAN_MANAGER_ERR_NONE:
+                       break;
+
+               case WLAN_MANAGER_ERR_ALREADY_REGISTERED:
+                       break;
+
+               default:
+                       ERROR_LOG(UG_NAME_NORMAL, "Cannot start wlan_manager");
+                       return WLAN_MANAGER_ERR_UNKNOWN;
+       }
+       ret = wifi_manager_foreach_available_interface(manager_object->wifi[manager_object->active_wifi_index], wlan_manager_interface_cb, NULL );
+       wifi_manager_deinitialize(manager_object->wifi[manager_object->active_wifi_index]);
+       manager_object->wifi[manager_object->active_wifi_index] = NULL;
+       __COMMON_FUNC_EXIT__;
+       return ret;
+}
index 409f974..17cdc0a 100644 (file)
@@ -30,6 +30,14 @@ extern "C"
 #include <wifi-manager-extension.h>
 
 typedef enum {
+       WLAN_MANAGER_WIFI_IFACE_WLAN0,
+       WLAN_MANAGER_WIFI_IFACE_WLAN1,
+       WLAN_MANAGER_WIFI_IFACE_WLAN2,
+       WLAN_MANAGER_WIFI_IFACE_WLAN3,
+       WLAN_MANAGER_WIFI_IFACE_MAX
+} wlan_manager_wifi_iface_index_e;
+
+typedef enum {
        WLAN_MANAGER_ERR_NONE = 0x00,
        WLAN_MANAGER_ERR_UNKNOWN,
        WLAN_MANAGER_ERR_INVALID_PARAM,
@@ -131,7 +139,7 @@ typedef enum {
        WLAN_MANAGER_RESPONSE_TYPE_UPDATE_WIFI_RSSI                                     = 0x1C,
        WLAN_MANAGER_RESPONSE_TYPE_CONFIGURATION                                        = 0x1D,
        WLAN_MANAGER_RESPONSE_TYPE_DHCP_FAILED                                          = 0x1E,
-       WLAN_MANAGER_RESPONSE_TYPE_MAX                                                          = 0x1F,
+       WLAN_MANAGER_RESPONSE_TYPE_MAX                                                  = 0x1F,
 } WLAN_MANAGER_RESPONSE_TYPES;
 
 typedef enum {
@@ -200,13 +208,22 @@ typedef struct {
 
 typedef void (*wlan_event_handler)(wlan_mgr_event_info_t *event_info, void *user_data);
 
+#define WLAN_IFACE_MAX_LEN   16
+#define WLAN_MANAGER_WIFI_WLAN0        "wlan0"
+#define WLAN_MANAGER_WIFI_WLAN1        "wlan1"
+#define WLAN_MANAGER_WIFI_WLAN2        "wlan2"
+#define WLAN_MANAGER_WIFI_WLAN3        "wlan3"
+
 /** It should be hide to others */
 typedef struct wlan_manager_object {
        wlan_event_handler message_func;
        wlan_manager_ui_refresh_func_t refresh_func;
        gboolean b_scan_blocked;
        gboolean b_ui_refresh;
-       wifi_manager_h wifi;
+       unsigned int active_wifi_index;
+       wifi_manager_h wifi[WLAN_MANAGER_WIFI_IFACE_MAX];
+        char *ifname[WLAN_IFACE_MAX_LEN];
+       int interface_count;
 } wlan_manager_object;
 
 /////////////////////////////////////////////////////////////////
@@ -251,6 +268,10 @@ int wlan_manager_scan_with_ssid(const char *ssid, void *data);
 gboolean wlan_manager_is_same_network(wifi_manager_ap_h ap1, wifi_manager_ap_h ap2);
 STRENGTH_TYPES wlan_manager_get_signal_strength(int rssi);
 int wlan_manager_set_autoscan_mode(wlan_manager_autoscan_mode_e mode);
+void wlan_manager_set_active_wifi_index(wlan_manager_wifi_iface_index_e index);
+int wlan_manager_get_available_interface(void);
+bool wlan_manager_interface_cb(char *ifname, void *user_data);
+int wlan_mgr_get_index_from_ifname(const char *ifname);
 
 //// profile refresh /////////////////////////////////////////////
 void wlan_manager_scanned_profile_refresh(void);
index 1eb9380..20ec30b 100644 (file)
@@ -1,6 +1,6 @@
 Name:          wifi-efl-ug
 Summary:       Wi-Fi UI Gadget for TIZEN
-Version:       1.1.1
+Version:       1.1.2
 Release:       1
 Group:         App/Network
 License:       Flora-1.1
index 1258a22..6a6cd83 100644 (file)
@@ -53,6 +53,8 @@ typedef struct viewer_manager_object {
        Evas_Object *sw_hidden_btn;
        Evas_Object *sw_scan_btn;
 
+       char *ifname[WLAN_MANAGER_WIFI_IFACE_MAX];
+
        Elm_Object_Item *item_wifi_onoff;
        char *item_wifi_onoff_text;
 
index e780ab1..7c861d3 100644 (file)
@@ -181,6 +181,9 @@ static void *on_create(ui_gadget_h ug, enum ug_mode mode,
        wlan_manager_set_message_callback(wlan_engine_callback);
        wlan_manager_set_refresh_callback(wlan_engine_refresh_callback);
 
+       //Finds the number of wifi devices attached
+       wlan_manager_get_available_interface();
+
        switch (wlan_manager_start()) {
        case WLAN_MANAGER_ERR_NONE:
                break;