[connman] Added Tizen Wi-Fi Mesh
[platform/upstream/connman.git] / src / manager.c
index d15ce20..bd44fea 100644 (file)
@@ -41,6 +41,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
        DBusMessageIter array, dict;
        dbus_bool_t offlinemode;
        const char *str;
+#if defined TIZEN_EXT
+       dbus_bool_t autoconnectmode;
+#endif
 
        DBG("conn %p", conn);
 
@@ -63,6 +66,12 @@ static DBusMessage *get_properties(DBusConnection *conn,
        connman_dbus_dict_append_basic(&dict, "SessionMode",
                                        DBUS_TYPE_BOOLEAN,
                                        &sessionmode);
+#if defined TIZEN_EXT
+       autoconnectmode = __connman_service_get_auto_connect_mode();
+       connman_dbus_dict_append_basic(&dict, "AutoConnectMode",
+                                       DBUS_TYPE_BOOLEAN,
+                                       &autoconnectmode);
+#endif
 
        connman_dbus_dict_close(&array, &dict);
 
@@ -102,6 +111,20 @@ static DBusMessage *set_property(DBusConnection *conn,
 
                dbus_message_iter_get_basic(&value, &offlinemode);
 
+               if (offlinemode) {
+                       uid_t uid;
+                       if (connman_dbus_get_connection_unix_user_sync(conn,
+                                               dbus_message_get_sender(msg),
+                                               &uid) < 0) {
+                               DBG("Can not get unix user id!");
+                               return __connman_error_permission_denied(msg);
+                       }
+
+                       if (!__connman_service_is_user_allowed(CONNMAN_SERVICE_TYPE_WIFI, uid)) {
+                               DBG("Not allow this user to turn on offlinemode now!");
+                               return __connman_error_permission_denied(msg);
+                       }
+               }
                __connman_technology_set_offlinemode(offlinemode);
        } else if (g_str_equal(name, "SessionMode")) {
 
@@ -109,8 +132,20 @@ static DBusMessage *set_property(DBusConnection *conn,
                        return __connman_error_invalid_arguments(msg);
 
                dbus_message_iter_get_basic(&value, &sessionmode);
+       }
+#if defined TIZEN_EXT
+       else if (g_str_equal(name, "AutoConnectMode") == TRUE) {
+               bool automode;
+
+               if (type != DBUS_TYPE_BOOLEAN)
+                       return __connman_error_invalid_arguments(msg);
+
+               dbus_message_iter_get_basic(&value, &automode);
 
-       } else
+               __connman_service_set_auto_connect_mode(automode);
+       }
+#endif
+       else
                return __connman_error_invalid_property(msg);
 
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
@@ -126,7 +161,9 @@ static DBusMessage *get_technologies(DBusConnection *conn,
 {
        DBusMessage *reply;
 
+#if !defined TIZEN_EXT
        DBG("");
+#endif
 
        reply = dbus_message_new_method_return(msg);
        if (!reply)
@@ -500,6 +537,114 @@ error:
 
 }
 
+#if defined TIZEN_EXT_WIFI_MESH
+static void append_mesh_peer_structs(DBusMessageIter *iter, void *user_data)
+{
+       __connman_mesh_peer_list_struct(iter);
+}
+
+static DBusMessage *get_mesh_peers(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       DBusMessage *reply;
+
+       reply = dbus_message_new_method_return(msg);
+       if (!reply)
+               return NULL;
+
+       __connman_dbus_append_objpath_dict_array(reply,
+                                       append_mesh_peer_structs, NULL);
+       return reply;
+}
+
+static DBusMessage *get_connected_mesh_peers(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       DBusMessage *reply;
+       DBusMessageIter iter, array;
+
+       reply = dbus_message_new_method_return(msg);
+       if (!reply)
+               return NULL;
+
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+                       DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+                       DBUS_TYPE_ARRAY_AS_STRING
+                               DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                                       DBUS_TYPE_STRING_AS_STRING
+                                       DBUS_TYPE_VARIANT_AS_STRING
+                               DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+                       DBUS_STRUCT_END_CHAR_AS_STRING, &array);
+
+       __connman_mesh_connected_peer_list_struct(&array);
+       dbus_message_iter_close_container(&iter, &array);
+       return reply;
+}
+
+static DBusMessage *get_disconnected_mesh_peers(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       DBusMessage *reply;
+       DBusMessageIter iter, array;
+
+       reply = dbus_message_new_method_return(msg);
+       if (!reply)
+               return NULL;
+
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+                       DBUS_STRUCT_BEGIN_CHAR_AS_STRING
+                       DBUS_TYPE_ARRAY_AS_STRING
+                               DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                                       DBUS_TYPE_STRING_AS_STRING
+                                       DBUS_TYPE_VARIANT_AS_STRING
+                               DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+                       DBUS_STRUCT_END_CHAR_AS_STRING, &array);
+
+       __connman_mesh_disconnected_peer_list_struct(&array);
+       dbus_message_iter_close_container(&iter, &array);
+       return reply;
+}
+
+static DBusMessage *mesh_add_peer(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       const char *addr;
+       int err;
+
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr,
+                                                       DBUS_TYPE_INVALID);
+
+       DBG("Address %s", addr);
+
+       err = __connman_mesh_change_peer_status(msg, addr, CONNMAN_MESH_PEER_ADD);
+       if (err < 0)
+               return __connman_error_failed(msg, -err);
+
+       return NULL;
+}
+
+static DBusMessage *mesh_remove_peer(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       const char *addr;
+       int err;
+
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr,
+                                                       DBUS_TYPE_INVALID);
+
+       DBG("Address %s", addr);
+
+       err = __connman_mesh_change_peer_status(msg, addr,
+                                                                               CONNMAN_MESH_PEER_REMOVE);
+       if (err < 0)
+               return __connman_error_failed(msg, -err);
+
+       return NULL;
+}
+#endif
+
 static const GDBusMethodTable manager_methods[] = {
        { GDBUS_METHOD("GetProperties",
                        NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
@@ -559,6 +704,21 @@ static const GDBusMethodTable manager_methods[] = {
        { GDBUS_METHOD("UnregisterPeerService",
                        GDBUS_ARGS({ "specification", "a{sv}" }), NULL,
                        unregister_peer_service) },
+#if defined TIZEN_EXT_WIFI_MESH
+       { GDBUS_METHOD("GetMeshPeers",
+                       NULL, GDBUS_ARGS({ "peers", "a(oa{sv})" }),
+                       get_mesh_peers) },
+       { GDBUS_METHOD("GetConnectedMeshPeers",
+                       NULL, GDBUS_ARGS({ "peers", "a(a{sv})" }),
+                       get_connected_mesh_peers) },
+       { GDBUS_METHOD("GetDisconnectedMeshPeers",
+                       NULL, GDBUS_ARGS({ "peers", "a(a{sv})" }),
+                       get_disconnected_mesh_peers) },
+       { GDBUS_ASYNC_METHOD("MeshAddPeer", GDBUS_ARGS({ "address", "s" }), NULL,
+                                  mesh_add_peer) },
+       { GDBUS_ASYNC_METHOD("MeshRemovePeer", GDBUS_ARGS({ "address", "s" }), NULL,
+                                  mesh_remove_peer) },
+#endif
        { },
 };