Implement sending 'enable ethernet' to the ConnMan
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 3 Jul 2017 04:38:14 +0000 (13:38 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 17 Jul 2017 02:35:37 +0000 (11:35 +0900)
Fix sending 'enable ethernet' to the ConnMan

Signed-off-by: saerome.kim <saerome.kim@samsung.com>
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
include/mesh-gdbus.h
src/mesh-gdbus.c
src/mesh-peer-monitor.c

index eed8fe9..10a7309 100644 (file)
@@ -56,6 +56,7 @@ int mesh_gdbus_set_passphrase(mesh_service *service, mesh_scan_result_s *info,
 int mesh_gdbus_connect_network(mesh_service *service, mesh_scan_result_s *info);
 int mesh_gdbus_disconnect_network(mesh_service *service, mesh_scan_result_s *info);
 int mesh_gdbus_remove_network(mesh_service *service, mesh_scan_result_s *info);
+int mesh_gdbus_enable_ethernet_interface(mesh_service *service, bool state);
 
 #ifdef __cplusplus
 }
index 82b4af8..ecf4163 100644 (file)
@@ -24,6 +24,7 @@
 static GDBusProxy *_gproxy_connman = NULL;
 static GDBusProxy *_gproxy_connman_mesh = NULL;
 static GDBusProxy *_gproxy_connman_technology = NULL;
+static GDBusProxy *_gproxy_connman_ethernet = NULL;
 
 static int _meshd_close_gdbus_call(mesh_service *service);
 static int _mesh_gdbus_get_mesh_network_property(mesh_service *service,
@@ -107,6 +108,24 @@ static GDBusProxy *_proxy_get_connman_mesh(mesh_service *service)
        return proxy;
 }
 
+static GDBusProxy *_proxy_get_connman_ethernet(mesh_service *service)
+{
+       GDBusProxy *proxy = NULL;
+       meshd_check_null_ret_error("service", service, NULL);
+
+       if (NULL == _gproxy_connman_ethernet) {
+               proxy = g_dbus_proxy_new_sync(service->connection,
+                       G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       CONNMAN_SERVER_NAME, /* Name */
+                       "/net/connman/technology/ethernet", /* Object Path */
+                       CONNMAN_INTERFACE_TECH, /* interface Name */
+                       NULL, NULL);
+       } else
+               proxy = _gproxy_connman_ethernet;
+
+       return proxy;
+}
+
 static GDBusProxy *_proxy_get_connman_technology(mesh_service *service)
 {
        GDBusProxy *proxy = NULL;
@@ -338,6 +357,12 @@ int meshd_dbus_start(mesh_service *service)
        g_dbus_proxy_set_default_timeout(
                        G_DBUS_PROXY(_gproxy_connman_technology), MESH_DBUS_PROXY_TIMEOUT);
 
+       _gproxy_connman_ethernet = _proxy_get_connman_ethernet(service);
+       meshd_check_null_ret_error("_gproxy_connman_ethernet", _gproxy_connman_ethernet,
+                               MESHD_ERROR_IO_ERROR);
+       g_dbus_proxy_set_default_timeout(
+                       G_DBUS_PROXY(_gproxy_connman_ethernet), MESH_DBUS_PROXY_TIMEOUT);
+
        /* Subscribe events */
        _meshd_subscribe_event(service);
 
@@ -542,7 +567,7 @@ int mesh_gdbus_mesh_cancel_scan(mesh_service *service)
                /* Scan is not in progress */
                if (g_strrstr(error->message, "Already exists"))
                        ret = MESHD_ERROR_NONE;
-               
+
                g_error_free(error);
        }
 
@@ -1161,3 +1186,40 @@ int mesh_gdbus_remove_network(mesh_service *service, mesh_scan_result_s *info)
 
        return MESHD_ERROR_NONE;
 }
+
+
+int mesh_gdbus_enable_ethernet_interface(mesh_service *service, bool state)
+{
+       int ret = MESHD_ERROR_NONE;
+       GVariant *variant = NULL;
+       GError *error = NULL;
+       mesh_interface_s *info = NULL;
+
+       meshd_check_null_ret_error("service", service, MESHD_ERROR_INVALID_PARAMETER);
+       meshd_check_null_ret_error("connection", service->connection,
+                       MESHD_ERROR_INVALID_PARAMETER);
+       meshd_check_null_ret_error("_gproxy_connman_technology",
+                       _gproxy_connman_technology, MESHD_ERROR_IO_ERROR);
+
+       info = service->interface_info;
+       meshd_check_null_ret_error("info", info, MESHD_ERROR_INVALID_PARAMETER);
+
+       variant = g_dbus_proxy_call_sync(_gproxy_connman_ethernet, "SetProperty",
+                               g_variant_new("(sv)", "Powered", g_variant_new_boolean(state)),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, &error);
+       if (variant) {
+               MESH_LOGD("Successfully requested. [Powered]");
+       } else if (error) {
+               ret = MESHD_ERROR_IO_ERROR;
+               MESH_LOGE("Failed DBus call [%s]", error->message);
+
+               /* Interface not exists (Not created yet) */
+               if (g_strrstr(error->message, "No such device"))
+                       ret = MESHD_ERROR_NONE;
+               g_error_free(error);
+       }
+
+       return ret;
+}
+
index 535ed40..079087e 100644 (file)
@@ -21,6 +21,7 @@
 #include "mesh.h"
 #include "mesh-log.h"
 #include "mesh-util.h"
+#include "mesh-gdbus.h"
 #include "mesh-request.h"
 #include "mesh-netlink.h"
 #include "mesh-interface.h"
@@ -210,6 +211,7 @@ static gboolean _on_mesh_monitor_cb(gpointer pdata)
                        MESH_LOGE("Status : %d %d %d", ret, info->can_be_gate, state);
                        if (MESHD_ERROR_NONE == ret) {
                                if (info->can_be_gate != state) {
+                                       mesh_gdbus_enable_ethernet_interface(service, state);
                                        /* Detect external network state (i.e. Ethernet)
                                                and decide to make gate enabled */
                                        if (state)
@@ -222,7 +224,11 @@ static gboolean _on_mesh_monitor_cb(gpointer pdata)
                                        MESH_LOGD("External interface state has been changed : [%d]", state);
                                        info->can_be_gate = state;
                                }
+                       } else {
+                               /* In error case, we call enable etheret again for OdroidU3 */
+                               mesh_gdbus_enable_ethernet_interface(service, true);
                        }
+
 #if 0
                        _get_mpath_info(service);
 #endif