Implement net_get_wifi_state using connman dbus method instead of net-config 51/193151/2
authorNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 30 Jun 2020 11:16:37 +0000 (16:46 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 30 Jun 2020 11:16:37 +0000 (16:46 +0530)
Change-Id: I54348f14c6613a5590ae972a7a776d44d001df69
Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/internal/network-dbus-request.h
include/internal/network-signal-handler.h
src/network-dbus-request.c
src/network-signal-handler.c
src/network-wifi-intf.c

index 6e2bf65..4708a4e 100755 (executable)
@@ -106,7 +106,8 @@ int _net_dbus_set_mesh_property(network_info_t *network_info,
                char* profile_name, const char *property, char *value);
 int _net_dbus_get_network_status(network_info_t *network_info,
                net_device_t device_type, net_cm_network_status_t* network_status);
-int _net_dbus_get_wifi_state(network_info_t *network_info, char **wifi_state);
+int _net_dbus_get_tech_status(network_info_t *network_info, net_device_t device_type,
+               net_tech_info_t *tech_status);
 int _net_dbus_set_profile_ipv4(network_info_t *network_info,
                net_profile_info_t* prof_info, char* profile_name);
 int _net_dbus_set_profile_ipv6(network_info_t *network_info,
index 49003ec..5627f19 100755 (executable)
@@ -43,6 +43,7 @@ void _net_set_wifi_state(net_wifi_state_t state);
 void _net_set_dpm_wifi_profile_state(int state);
 void _net_set_cs_tid(int tid, network_info_t *network_info);
 void _net_unset_cs_tid(int tid, network_info_t *network_info);
+int _net_get_wifi_service_state(network_info_t *network_info);
 
 #ifdef __cplusplus
 }
index 686cdaf..3fdc85a 100755 (executable)
@@ -878,39 +878,45 @@ done:
        return Error;
 }
 
-int _net_dbus_get_wifi_state(network_info_t *network_info, char **wifi_state)
+int _net_dbus_get_tech_status(network_info_t *network_info, net_device_t device_type,
+                       net_tech_info_t *tech_status)
 {
        __NETWORK_FUNC_ENTER__;
 
        net_err_t Error = NET_ERR_NONE;
-       GVariant *message = NULL;
-       const char *method = "GetWifiState";
+       network_tech_state_info_t tech_state = {{0,},};
 
        /* LCOV_EXCL_START */
-       if (NULL == wifi_state) {
-                       NETWORK_LOG(NETWORK_ERROR, "Invalid Parameter");
-                       __NETWORK_FUNC_EXIT__;
-                       return NET_ERR_INVALID_PARAM;
+       if (device_type == NET_DEVICE_WIFI)
+               g_strlcpy(tech_state.technology, "wifi", NET_TECH_LENGTH_MAX);
+       else {
+               Error = NET_ERR_INVALID_PARAM;
+               goto done;
        }
        /* LCOV_EXCL_STOP */
 
-       message = _net_invoke_dbus_method(network_info,
-                       NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
-                       NETCONFIG_WIFI_INTERFACE, method, NULL, &Error);
-
+       Error = _net_dbus_get_technology_state(network_info, &tech_state);
        /* LCOV_EXCL_START */
-       if (message == NULL) {
-               NETWORK_LOG(NETWORK_ERROR, "Failed to get wifi state");
-               __NETWORK_FUNC_EXIT__;
-               return Error;
+       if (Error != NET_ERR_NONE) {
+               NETWORK_LOG(NETWORK_ERROR,
+                               "_net_dbus_get_technology_state() failed. Error [%s]",
+                               _net_print_error(Error));
+               goto done;
        }
        /* LCOV_EXCL_STOP */
 
-       g_variant_get(message, "(s)", wifi_state);
-       g_variant_unref(message);
+       if (tech_state.Powered == TRUE)
+               tech_status->powered = TRUE; //LCOV_EXCL_LINE
+       else
+               tech_status->powered = FALSE; //LCOV_EXCL_LINE
 
-       __NETWORK_FUNC_EXIT__;
+       if (tech_state.Connected == TRUE)
+               tech_status->connected = TRUE; //LCOV_EXCL_LINE
+       else
+               tech_status->connected = FALSE; //LCOV_EXCL_LINE
 
+done:
+       __NETWORK_FUNC_EXIT__;
        return Error;
 }
 
index 28a710f..1c563c2 100755 (executable)
@@ -1165,3 +1165,16 @@ int _net_init_service_state_table(network_info_t *network_info)
        __NETWORK_FUNC_EXIT__;
        return NET_ERR_NONE;
 }
+
+int _net_get_wifi_service_state(network_info_t *network_info)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       if (net_wifi_state == WIFI_ON) {
+               __NETWORK_FUNC_EXIT__;
+               return NET_STATE_TYPE_DISCONNECT;
+       }
+
+       __NETWORK_FUNC_EXIT__;
+       return network_info->state_table[NET_DEVICE_WIFI];
+}
index 891498c..1cbef03 100755 (executable)
@@ -75,48 +75,54 @@ static int __net_check_profile_privilege(void)
  *****************************************************************************/
 static net_wifi_state_t __net_get_wifi_connection_state(network_info_t *network_info, net_err_t *net_error)
 {
-       net_err_t Error = NET_ERR_NONE;
-       char *wifi_state = NULL;
-       net_wifi_state_t current_state = _net_get_wifi_state();
-
        __NETWORK_FUNC_ENTER__;
-       Error = _net_dbus_get_wifi_state(network_info, &wifi_state);
-
-       /* LCOV_EXCL_START */
-       if (Error != NET_ERR_NONE) {
-               NETWORK_LOG(NETWORK_ERROR, "Failed to get wifi state[%s]",
-                               _net_print_error(Error));
 
-               *net_error = Error;
+       net_state_type_t service_state = NET_STATE_TYPE_UNKNOWN;
+       net_wifi_state_t connection_state = WIFI_UNKNOWN;
+       net_tech_info_t status;
 
+       int rv = _net_dbus_get_tech_status(network_info, NET_DEVICE_WIFI, &status);
+       if (rv != NET_ERR_NONE) {
                __NETWORK_FUNC_EXIT__;
-               return current_state;
+               return WIFI_UNKNOWN;
        }
-       /* LCOV_EXCL_STOP */
-
-       if (g_strcmp0(wifi_state, "unknown") == 0)
-               current_state = WIFI_UNKNOWN;
-       else if (g_strcmp0(wifi_state, "deactivated") == 0)
-               current_state = WIFI_OFF;
-       else if (g_strcmp0(wifi_state, "disconnected") == 0)
-               current_state = WIFI_ON;
-       else if (g_strcmp0(wifi_state, "association") == 0)
-               current_state = WIFI_ASSOCIATION;
-       else if (g_strcmp0(wifi_state, "configuration") == 0)
-               current_state = WIFI_CONFIGURATION;
-       else if (g_strcmp0(wifi_state, "connected") == 0)
-               current_state = WIFI_CONNECTED;
 
-       g_free(wifi_state);
+       service_state = _net_get_wifi_service_state(network_info);
 
-       if (current_state == WIFI_CONNECTED &&
-           network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE)
-               current_state = WIFI_DISCONNECTING;
+       /* LCOV_EXCL_START */
+       if (status.powered == FALSE)
+               connection_state = WIFI_OFF;
+       else if (status.connected == TRUE)
+               connection_state = WIFI_CONNECTED;
+       else {
+               switch (service_state) {
+               case NET_STATE_TYPE_ASSOCIATION:
+                       connection_state = WIFI_ASSOCIATION;
+                       break;
+               case NET_STATE_TYPE_CONFIGURATION:
+                       connection_state = WIFI_CONFIGURATION;
+                       break;
+               case NET_STATE_TYPE_READY:
+               case NET_STATE_TYPE_ONLINE:
+                       connection_state = WIFI_CONNECTED;
+                       break;
+               case NET_STATE_TYPE_UNKNOWN:
+                       connection_state = WIFI_UNKNOWN;
+                       break;
+               case NET_STATE_TYPE_FAILURE:
+               case NET_STATE_TYPE_IDLE:
+               default:
+                       connection_state = WIFI_ON;
+               }
+       }
+       /* LCOV_EXCL_STOP */
 
-       *net_error = Error;
+       if (connection_state == WIFI_CONNECTED &&
+                       network_info->request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE)
+               connection_state = WIFI_DISCONNECTING;
 
        __NETWORK_FUNC_EXIT__;
-       return current_state;
+       return connection_state;
 }
 
 /*****************************************************************************