Adjust dbus interface between API and connman
authorJiwan Kim <ji-wan.kim@samsung.com>
Mon, 29 May 2017 09:52:42 +0000 (18:52 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 17 Jul 2017 02:35:36 +0000 (11:35 +0900)
- Add to get current mesh network / to create mesh network
- Adjust the name of DBus interfaces

include/mesh-gdbus.h
include/mesh-request.h
introspection/mesh.xml
src/mesh-gdbus.c
src/mesh-request.c
src/mesh-service-interface.c

index 1e4a1ce..7207086 100644 (file)
@@ -46,7 +46,10 @@ int mesh_ipc_mesh_specific_scan(mesh_service *service, gchar *mesh_id,
         gint channel);
 int mesh_ipc_mesh_cancel_scan(mesh_service *service);
 int mesh_ipc_get_mesh_peers(mesh_service *service);
+int mesh_ipc_get_joined_mesh_network(mesh_service *service);
 
+int mesh_ipc_create_network(mesh_service *service, gchar *mesh_id, gint channel,
+        gint security);
 int mesh_ipc_connect_network(mesh_service *service, mesh_scan_result_s *info);
 int mesh_ipc_disconnect_network(mesh_service *service, mesh_scan_result_s *info);
 int mesh_ipc_remove_network(mesh_service *service, mesh_scan_result_s *info);
index 2f02972..1cb8565 100644 (file)
@@ -30,6 +30,10 @@ int mesh_request_ipc_mesh_specific_scan(mesh_service *service, gchar *mesh_id,
         gint channel);
 int mesh_request_ipc_mesh_cancel_scan(mesh_service *service);
 int mesh_request_ipc_mesh_get_peers(mesh_service *service);
+int mesh_request_ipc_get_joined_network(mesh_service *service);
+
+int mesh_request_ipc_create_mesh_network(mesh_service *service, gchar *mesh_id,
+               gint channel, gint security);
 int mesh_request_ipc_connect_mesh_network(mesh_service *service, gchar *mesh_id,
                gint channel, gint security);
 int mesh_request_ipc_disconnect_mesh_network(mesh_service *service,
index da6ff4d..b0b852b 100644 (file)
                <method name="disable_softap">\r
                        <arg type="u" name="result" direction="out"/>\r
                </method>\r
-               <method name="add_mesh_network">\r
+               <method name="create_mesh_network">\r
                        <arg type="s" name="mesh_id" direction="in"/>\r
                        <arg type="i" name="channel" direction="in"/>\r
                        <arg type="i" name="security" direction="in"/>\r
                        <arg type="u" name="result" direction="out"/>\r
                </method>\r
-               <method name="get_saved_mesh_network">\r
-                       <arg type="aa{sv}" name="list" direction="out"/>\r
-                       <arg type="u" name="result" direction="out"/>\r
-               </method>\r
-               <method name="select_saved_mesh_network">\r
+               <method name="connect_mesh_network">\r
                        <arg type="s" name="mesh_id" direction="in"/>\r
                        <arg type="i" name="channel" direction="in"/>\r
                        <arg type="i" name="security" direction="in"/>\r
                        <arg type="u" name="result" direction="out"/>\r
                </method>\r
-               <method name="forget_saved_mesh_network">\r
+               <method name="forget_mesh_network">\r
                        <arg type="s" name="mesh_id" direction="in"/>\r
                        <arg type="i" name="channel" direction="in"/>\r
                        <arg type="i" name="security" direction="in"/>\r
index 7b6a2d4..68e6db0 100644 (file)
@@ -415,6 +415,37 @@ int mesh_ipc_mesh_specific_scan(mesh_service *service, gchar *mesh_id,
        return MESHD_ERROR_NONE;
 }
 
+int mesh_ipc_mesh_cancel_scan(mesh_service *service)
+{
+       GVariant *variant = NULL;
+       GError *error = NULL;
+       GVariant *var_dict = NULL;
+       GVariantDict dict;
+
+       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);
+
+       g_variant_dict_init(&dict, NULL);
+       var_dict = g_variant_dict_end(&dict);
+
+       variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
+                               g_variant_new("(sv)", "AbortScan", var_dict),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, &error);
+       if (variant) {
+               MESH_LOGD("Successfully requested. [AbortScan]");
+       } else if (error) {
+               MESH_LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MESHD_ERROR_IO_ERROR;
+       }
+
+       return MESHD_ERROR_NONE;
+}
+
 static void _on_scan_result_destroy(gpointer data)
 {
        mesh_scan_result_s *scan_item = (mesh_scan_result_s *)data;
@@ -426,6 +457,70 @@ static void _on_scan_result_destroy(gpointer data)
        }
 }
 
+static void _get_joined_network(mesh_service *service, GVariant *variant)
+{
+       GVariantIter *peer = NULL;
+       GVariantIter *property = NULL;
+       GVariant *val = NULL;
+       gsize len = 0;
+       GVariant *child;
+       gchar *var_string = NULL;
+       const gchar* obj_path = NULL;
+       const gchar* buf = NULL;
+
+       g_variant_get(variant, "(a(oa{sv}))", &peer);
+       while ((child = g_variant_iter_next_value(peer))) {
+               GVariantDict *dict = NULL;
+               GVariant *tmp = NULL;
+               mesh_network_info_s *joined_info = NULL;
+
+               MESH_LOGD("    Child : [%s]", g_variant_get_type_string(child));
+               var_string = g_variant_print(child, FALSE);
+               MESH_LOGD("    %s", var_string);
+               g_free(var_string);
+
+               g_variant_get(child, "(oa{sv})", &obj_path, &dict);
+               if (NULL == obj_path) {
+                       MESH_LOGE("Null object");
+                       continue;
+               }
+
+               tmp = g_variant_dict_lookup_value(dict, "State", G_VARIANT_TYPE_STRING);
+               if (NULL == tmp) continue;
+               buf = g_variant_get_string(tmp, &len);
+               if (g_strcmp0(buf, "association") != 0 && g_strcmp0(buf, "connected") != 0)
+                       continue;
+
+               /* Create an information structure for joined network */
+               joined_info = g_try_new0(mesh_network_info_s, 1);
+               if (NULL == joined_info) {
+                       MESH_LOGE("Failed to allocate !");
+                       return;
+               }
+
+               tmp = g_variant_dict_lookup_value(dict, "Name", G_VARIANT_TYPE_STRING);
+               if (NULL == tmp) continue;
+               buf = g_variant_get_string(tmp, &len);
+               joined_info->mesh_id = g_strdup(buf);
+               MESH_LOGD("    Mesh ID : %s", joined_info->mesh_id);
+
+               tmp = g_variant_dict_lookup_value(dict, "Address", G_VARIANT_TYPE_STRING);
+               if (NULL == tmp) continue;
+               buf = g_variant_get_string(tmp, &len);
+               joined_info->bssid = g_strdup(buf);
+               MESH_LOGD("    BSSID : %s", joined_info->bssid);
+
+               tmp = g_variant_dict_lookup_value(dict, "Frequency", G_VARIANT_TYPE_UINT16);
+               joined_info->channel = __frequency_to_channel(g_variant_get_uint16(val));
+               MESH_LOGD("    Channel : %d", joined_info->channel);
+
+               service->joined_network = joined_info;
+
+               g_variant_iter_free(property);
+       }
+       g_variant_iter_free(peer);
+}
+
 static void _get_mesh_peers(mesh_service *service, GVariant *variant)
 {
        GVariantIter *peer = NULL;
@@ -527,6 +622,80 @@ int mesh_ipc_get_mesh_peers(mesh_service *service)
        return MESHD_ERROR_NONE;
 }
 
+int mesh_ipc_get_joined_mesh_network(mesh_service *service)
+{
+       GVariant *variant = NULL;
+       GError *error = 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",
+                       _gproxy_connman, MESHD_ERROR_IO_ERROR);
+
+       variant = g_dbus_proxy_call_sync(_gproxy_connman, "GetMeshPeers",
+                               NULL,
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, &error);
+       if (variant) {
+               MESH_LOGD("Successfully requested. [GetMeshPeers]");
+
+               if (service->joined_network) {
+                       g_free(service->joined_network->mesh_id);
+                       g_free(service->joined_network->bssid);
+                       g_free(service->joined_network);
+                       service->joined_network = NULL;
+               }
+
+               _get_joined_network(service, variant);
+       } else if (error) {
+               MESH_LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MESHD_ERROR_IO_ERROR;
+       }
+
+       return MESHD_ERROR_NONE;
+}
+
+int mesh_ipc_create_network(mesh_service *service, gchar *mesh_id, gint channel,
+        gint security)
+{
+       GVariant *variant = NULL;
+       GError *error = NULL;
+       GVariant *var_dict = NULL;
+       GVariantDict dict;
+       const gchar* secu = (security == 0) ? "none" : "SAE";
+
+       enum nl80211_band band = (channel <= 14) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
+       gushort freq = __channel_to_frequency(channel, band);
+
+       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);
+
+       g_variant_dict_init(&dict, NULL);
+       g_variant_dict_insert(&dict, "Name", "s", mesh_id);
+       g_variant_dict_insert(&dict, "Frequency", "q", freq);
+       g_variant_dict_insert(&dict, "Security", "s", secu);
+       var_dict = g_variant_dict_end(&dict);
+
+       variant = g_dbus_proxy_call_sync(_gproxy_connman_technology, "MeshCommands",
+                               g_variant_new("(sv)", "MeshCreateNetwork", var_dict),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, &error);
+       if (variant) {
+               MESH_LOGD("Successfully requested. [MeshCreateNetwork]");
+       } else if (error) {
+               MESH_LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return MESHD_ERROR_IO_ERROR;
+       }
+
+       return MESHD_ERROR_NONE;
+}
+
 int mesh_ipc_connect_network(mesh_service *service, mesh_scan_result_s *info)
 {
        GVariant *variant = NULL;
index 464edc4..c8719f5 100644 (file)
@@ -770,7 +770,7 @@ int mesh_request_ipc_mesh_cancel_scan(mesh_service *service)
 
        MESH_LOGD("[IPC] Cancel scan for mesh network");
 
-       ret = mesh_ipc_mesh_scan(service);
+       ret = mesh_ipc_mesh_cancel_scan(service);
        if(MESHD_ERROR_NONE != ret) {
                MESH_LOGE("Failed to cancel scan for mesh network");
                return ret;
@@ -833,6 +833,47 @@ static int _select_matched_network(GList *scanned_network,
        return ret;
 }
 
+int mesh_request_ipc_get_joined_network(mesh_service *service)
+{
+       int ret;
+
+       if (NULL == service) {
+               MESH_LOGE("Invalid parameter");
+               return MESHD_ERROR_INVALID_PARAMETER;
+       }
+
+       MESH_LOGD("[IPC] Get joined mesh network");
+
+       ret = mesh_ipc_get_joined_mesh_network(service);
+       if(MESHD_ERROR_NONE != ret) {
+               MESH_LOGE("Failed to get joined mesh network");
+               return ret;
+       }
+
+       return MESHD_ERROR_NONE;
+}
+
+int mesh_request_ipc_create_mesh_network(mesh_service *service, gchar *mesh_id,
+               gint channel, gint security)
+{
+       int ret;
+
+       if (NULL == service) {
+               MESH_LOGE("Invalid parameter");
+               return MESHD_ERROR_INVALID_PARAMETER;
+       }
+
+       MESH_LOGD("[IPC] Create a new mesh network");
+
+       ret = mesh_ipc_create_network(service, mesh_id, channel, security);
+       if(MESHD_ERROR_NONE != ret) {
+               MESH_LOGE("Failed to create mesh network");
+               return ret;
+       }
+
+       return MESHD_ERROR_NONE;
+}
+
 int mesh_request_ipc_connect_mesh_network(mesh_service *service, gchar *mesh_id,
                gint channel, gint security)
 {
index f81efe8..b30d111 100644 (file)
@@ -289,11 +289,10 @@ static gboolean _meshd_dbus_handle_cancel_scan(NetMesh *object,
 {
        int ret = MESHD_ERROR_NONE;
        mesh_service *service = (mesh_service *)user_data;
-       mesh_interface_s *info = service->interface_info;
 
-       ret = mesh_request_cancel_scan(info->mesh_interface);
+       ret = mesh_request_ipc_mesh_cancel_scan(service);
        if (MESHD_ERROR_NONE != ret) {
-               MESH_LOGE("Failed to mesh_request_cancel_scan");
+               MESH_LOGE("Failed to mesh_request_ipc_mesh_cancel_scan");
        }
 
        net_mesh_complete_cancel_scan(object, invocation, ret);
@@ -524,19 +523,25 @@ static gboolean _meshd_dbus_handle_get_joined_mesh_network(NetMesh *object,
 {
        int ret = MESHD_ERROR_NONE;
        mesh_service *service = (mesh_service *)user_data;
-       mesh_network_info_s *joined = service->joined_network;
+       mesh_network_info_s *joined = NULL;
 
        //gchar *meshid = strdup("meshnet");
        //gchar *bssid = strdup("7c:dd:90:d8:2a:64");
        //gint channel = 161;
        //gint max_speed = 866;
-
-       if (joined) {
-               net_mesh_complete_get_joined_mesh_network(object, invocation,
-                       joined->mesh_id, joined->bssid, joined->channel, ret);
+       ret = mesh_request_ipc_get_joined_network(service);
+       if (MESHD_ERROR_NONE == ret) {
+               joined = service->joined_network;
+               if (joined) {
+                       net_mesh_complete_get_joined_mesh_network(object, invocation,
+                               joined->mesh_id, joined->bssid, joined->channel, ret);
+               } else {
+                       net_mesh_complete_get_joined_mesh_network(object, invocation,
+                               "", "", 0, MESHD_ERROR_NO_DATA);
+               }
        } else {
                net_mesh_complete_get_joined_mesh_network(object, invocation,
-                       "", "", 0, MESHD_ERROR_NO_DATA);
+                       "", "", 0, ret);
        }
 
        return TRUE;
@@ -649,7 +654,7 @@ static gboolean _meshd_dbus_handle_disable_softap(NetMesh *object,
        return TRUE;
 }
 
-static gboolean _meshd_dbus_handle_add_mesh_network(NetMesh *object,
+static gboolean _meshd_dbus_handle_create_mesh_network(NetMesh *object,
                GDBusMethodInvocation *invocation,
                gchar *mesh_id, gint channel, gint security,
                gpointer user_data)
@@ -657,14 +662,15 @@ static gboolean _meshd_dbus_handle_add_mesh_network(NetMesh *object,
        int ret = MESHD_ERROR_NONE;
        mesh_service *service = (mesh_service *)user_data;
 
-       ret = mesh_request_add_mesh_network(&service->saved_mesh_network,
-                       mesh_id, channel, security);
+       //ret = mesh_request_add_mesh_network(&service->saved_mesh_network,
+       //              mesh_id, channel, security);
+       ret = mesh_request_ipc_create_mesh_network(service, mesh_id, channel, security);
 
-       net_mesh_complete_add_mesh_network(object, invocation, ret);
+       net_mesh_complete_create_mesh_network(object, invocation, ret);
 
        return TRUE;
 }
-
+#if 0
 static gboolean _meshd_dbus_handle_get_saved_mesh_network(NetMesh *object,
                GDBusMethodInvocation *invocation,
                gpointer user_data)
@@ -708,8 +714,8 @@ static gboolean _meshd_dbus_handle_get_saved_mesh_network(NetMesh *object,
 
        return TRUE;
 }
-
-static gboolean _meshd_dbus_handle_select_saved_mesh_network(NetMesh *object,
+#endif
+static gboolean _meshd_dbus_handle_connect_mesh_network(NetMesh *object,
                GDBusMethodInvocation *invocation,
                gchar *mesh_id, gint channel, gint security,
                gpointer user_data)
@@ -724,12 +730,12 @@ static gboolean _meshd_dbus_handle_select_saved_mesh_network(NetMesh *object,
        ret = mesh_request_ipc_connect_mesh_network(service, mesh_id, channel, security);
 /* ADDED */
 
-       net_mesh_complete_select_saved_mesh_network(object, invocation, ret);
+       net_mesh_complete_connect_mesh_network(object, invocation, ret);
 
        return TRUE;
 }
 
-static gboolean _meshd_dbus_handle_forget_saved_mesh_network(NetMesh *object,
+static gboolean _meshd_dbus_handle_forget_mesh_network(NetMesh *object,
                GDBusMethodInvocation *invocation,
                gchar *mesh_id, gint channel, gint security,
                gpointer user_data)
@@ -742,7 +748,7 @@ static gboolean _meshd_dbus_handle_forget_saved_mesh_network(NetMesh *object,
        ret = mesh_request_ipc_disconnect_mesh_network(service,
                        mesh_id, channel, security);
 
-       net_mesh_complete_forget_saved_mesh_network(object, invocation, ret);
+       net_mesh_complete_forget_mesh_network(object, invocation, ret);
 
        return TRUE;
 }
@@ -1095,14 +1101,12 @@ static void _meshd_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name
                        G_CALLBACK(_meshd_dbus_handle_enable_softap), service);
        g_signal_connect(meshd_dbus_object, "handle-disable-softap",
                        G_CALLBACK(_meshd_dbus_handle_disable_softap), service);
-       g_signal_connect(meshd_dbus_object, "handle-add-mesh-network",
-                       G_CALLBACK(_meshd_dbus_handle_add_mesh_network), service);
-       g_signal_connect(meshd_dbus_object, "handle-get-saved-mesh-network",
-                       G_CALLBACK(_meshd_dbus_handle_get_saved_mesh_network), service);
-       g_signal_connect(meshd_dbus_object, "handle-select-saved-mesh-network",
-                       G_CALLBACK(_meshd_dbus_handle_select_saved_mesh_network), service);
-       g_signal_connect(meshd_dbus_object, "handle-forget-saved-mesh-network",
-                       G_CALLBACK(_meshd_dbus_handle_forget_saved_mesh_network), service);
+       g_signal_connect(meshd_dbus_object, "handle-create-mesh-network",
+                       G_CALLBACK(_meshd_dbus_handle_create_mesh_network), service);
+       g_signal_connect(meshd_dbus_object, "handle-connect-mesh-network",
+                       G_CALLBACK(_meshd_dbus_handle_connect_mesh_network), service);
+       g_signal_connect(meshd_dbus_object, "handle-forget-mesh-network",
+                       G_CALLBACK(_meshd_dbus_handle_forget_mesh_network), service);
        g_signal_connect(meshd_dbus_object, "handle-set-interfaces",
                        G_CALLBACK(_meshd_dbus_handle_set_interfaces), service);
        g_signal_connect(meshd_dbus_object, "handle-get-station-info",