*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <config.h>
#endif
+#include <errno.h>
+
#include <gdbus.h>
+#include <connman/agent.h>
+
#include "connman.h"
+static bool connman_state_idle;
+static dbus_bool_t sessionmode;
+
static DBusMessage *get_properties(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
DBusMessageIter array, dict;
- connman_bool_t offlinemode;
+ dbus_bool_t offlinemode;
const char *str;
+#if defined TIZEN_EXT
+ dbus_bool_t autoconnectmode;
+#endif
DBG("conn %p", conn);
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
- return __connman_error_permission_denied(msg);
-
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
connman_dbus_dict_open(&array, &dict);
- str = __connman_profile_active_path();
- if (str != NULL)
- connman_dbus_dict_append_basic(&dict, "ActiveProfile",
- DBUS_TYPE_OBJECT_PATH, &str);
-
- connman_dbus_dict_append_array(&dict, "Profiles",
- DBUS_TYPE_OBJECT_PATH, __connman_profile_list, NULL);
- connman_dbus_dict_append_array(&dict, "Services",
- DBUS_TYPE_OBJECT_PATH, __connman_service_list, NULL);
- connman_dbus_dict_append_array(&dict, "Providers",
- DBUS_TYPE_OBJECT_PATH, __connman_provider_list, NULL);
- connman_dbus_dict_append_array(&dict, "Technologies",
- DBUS_TYPE_OBJECT_PATH, __connman_technology_list, NULL);
-
str = __connman_notifier_get_state();
connman_dbus_dict_append_basic(&dict, "State",
DBUS_TYPE_STRING, &str);
- offlinemode = __connman_profile_get_offlinemode();
+ offlinemode = __connman_technology_get_offlinemode();
connman_dbus_dict_append_basic(&dict, "OfflineMode",
DBUS_TYPE_BOOLEAN, &offlinemode);
- connman_dbus_dict_append_array(&dict, "AvailableTechnologies",
- DBUS_TYPE_STRING, __connman_notifier_list_registered, NULL);
- connman_dbus_dict_append_array(&dict, "EnabledTechnologies",
- DBUS_TYPE_STRING, __connman_notifier_list_enabled, NULL);
- connman_dbus_dict_append_array(&dict, "ConnectedTechnologies",
- DBUS_TYPE_STRING, __connman_notifier_list_connected, NULL);
-
- str = __connman_service_default();
- if (str != NULL)
- connman_dbus_dict_append_basic(&dict, "DefaultTechnology",
- DBUS_TYPE_STRING, &str);
-
- connman_dbus_dict_append_array(&dict, "AvailableDebugs",
- DBUS_TYPE_STRING, __connman_debug_list_available, NULL);
- connman_dbus_dict_append_array(&dict, "EnabledDebugs",
- DBUS_TYPE_STRING, __connman_debug_list_enabled, NULL);
+ 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);
DBG("conn %p", conn);
- if (dbus_message_iter_init(msg, &iter) == FALSE)
+ if (!dbus_message_iter_init(msg, &iter))
+ return __connman_error_invalid_arguments(msg);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
return __connman_error_invalid_arguments(msg);
dbus_message_iter_get_basic(&iter, &name);
dbus_message_iter_next(&iter);
- dbus_message_iter_recurse(&iter, &value);
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
- return __connman_error_permission_denied(msg);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+ return __connman_error_invalid_arguments(msg);
+
+ dbus_message_iter_recurse(&iter, &value);
type = dbus_message_iter_get_arg_type(&value);
- if (g_str_equal(name, "OfflineMode") == TRUE) {
- connman_bool_t offlinemode;
+ if (g_str_equal(name, "OfflineMode")) {
+ dbus_bool_t offlinemode;
if (type != DBUS_TYPE_BOOLEAN)
return __connman_error_invalid_arguments(msg);
dbus_message_iter_get_basic(&value, &offlinemode);
- __connman_profile_set_offlinemode(offlinemode);
+ __connman_technology_set_offlinemode(offlinemode);
+ } else if (g_str_equal(name, "SessionMode")) {
- __connman_profile_save_default();
- } else if (g_str_equal(name, "ActiveProfile") == TRUE) {
- const char *str;
+ if (type != DBUS_TYPE_BOOLEAN)
+ 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, &str);
+ dbus_message_iter_get_basic(&value, &automode);
- return __connman_error_not_supported(msg);
+ __connman_service_set_auto_connect_mode(automode);
+#endif
} else
return __connman_error_invalid_property(msg);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
-static DBusMessage *get_state(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static void append_technology_structs(DBusMessageIter *iter, void *user_data)
{
- const char *str;
-
- DBG("conn %p", conn);
-
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
- return __connman_error_permission_denied(msg);
-
- str = __connman_notifier_get_state();
-
- return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INVALID);
+ __connman_technology_list_struct(iter);
}
-static DBusMessage *create_profile(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static DBusMessage *get_technologies(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
- const char *name, *path;
- int err;
-
- DBG("conn %p", conn);
+ DBusMessage *reply;
- dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
+#if !defined TIZEN_EXT
+ DBG("");
+#endif
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
- return __connman_error_permission_denied(msg);
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return NULL;
- err = __connman_profile_create(name, &path);
- if (err < 0)
- return __connman_error_failed(msg, -err);
+ __connman_dbus_append_objpath_dict_array(reply,
+ append_technology_structs, NULL);
- return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
+ return reply;
}
-static DBusMessage *remove_profile(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static DBusMessage *remove_provider(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
const char *path;
int err;
dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
- return __connman_error_permission_denied(msg);
-
- err = __connman_profile_remove(path);
+ err = __connman_provider_remove_by_path(path);
if (err < 0)
return __connman_error_failed(msg, -err);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
-static DBusMessage *remove_provider(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static DBusConnection *connection = NULL;
+
+static void idle_state(bool idle)
{
- const char *path;
- int err;
- DBG("conn %p", conn);
+ DBG("idle %d", idle);
- dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path,
- DBUS_TYPE_INVALID);
+ connman_state_idle = idle;
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
- return __connman_error_permission_denied(msg);
+ if (!connman_state_idle)
+ return;
+}
- err = __connman_provider_remove(path);
- if (err < 0)
- return __connman_error_failed(msg, -err);
+static const struct connman_notifier technology_notifier = {
+ .name = "manager",
+ .priority = CONNMAN_NOTIFIER_PRIORITY_HIGH,
+ .idle_state = idle_state,
+};
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+static void append_service_structs(DBusMessageIter *iter, void *user_data)
+{
+ __connman_service_list_struct(iter);
}
-static DBusMessage *request_scan(DBusConnection *conn,
+static DBusMessage *get_services(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- enum connman_service_type type;
- const char *str;
- int err;
-
- DBG("conn %p", conn);
-
- dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INVALID);
-
- if (g_strcmp0(str, "") == 0)
- type = CONNMAN_SERVICE_TYPE_UNKNOWN;
- else if (g_strcmp0(str, "wifi") == 0)
- type = CONNMAN_SERVICE_TYPE_WIFI;
- else if (g_strcmp0(str, "wimax") == 0)
- type = CONNMAN_SERVICE_TYPE_WIMAX;
- else
- return __connman_error_invalid_arguments(msg);
+ DBusMessage *reply;
- err = __connman_element_request_scan(type);
- if (err < 0) {
- if (err == -EINPROGRESS) {
- connman_error("Invalid return code from scan");
- err = -EINVAL;
- }
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return NULL;
- return __connman_error_failed(msg, -err);
- }
+ __connman_dbus_append_objpath_dict_array(reply,
+ append_service_structs, NULL);
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+ return reply;
}
-static DBusConnection *connection = NULL;
-
-static enum connman_service_type technology_type;
-static connman_bool_t technology_enabled;
-static DBusMessage *technology_pending = NULL;
-static guint technology_timeout = 0;
-
-static void technology_reply(int error)
+#if defined TIZEN_EXT
+static DBusMessage *get_interfaces(DBusConnection *conn, DBusMessage *msg, void *data)
{
- DBG("");
-
- if (technology_timeout > 0) {
- g_source_remove(technology_timeout);
- technology_timeout = 0;
- }
-
- if (technology_pending != NULL) {
- if (error > 0) {
- DBusMessage *reply;
-
- reply = __connman_error_failed(technology_pending,
- error);
- if (reply != NULL)
- g_dbus_send_message(connection, reply);
- } else
- g_dbus_send_reply(connection, technology_pending,
- DBUS_TYPE_INVALID);
+ DBusMessage *reply;
+ DBusMessageIter iter, array;
+ const char *default_interface = connman_option_get_string("DefaultWifiInterface");
- dbus_message_unref(technology_pending);
- technology_pending = NULL;
- }
+ DBG("DefaultWifiInterface %s", default_interface);
- technology_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
-}
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return NULL;
-static gboolean technology_abort(gpointer user_data)
-{
- DBG("");
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &array);
- technology_timeout = 0;
+ dbus_message_iter_append_basic(&array,
+ DBUS_TYPE_STRING, &default_interface);
- technology_reply(ETIMEDOUT);
+ __connman_technology_append_interfaces(&array,
+ CONNMAN_SERVICE_TYPE_WIFI, default_interface);
- return FALSE;
+ dbus_message_iter_close_container(&iter, &array);
+ return reply;
}
-static void technology_notify(enum connman_service_type type,
- connman_bool_t enabled)
+static DBusMessage *get_default_service(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
- DBG("type %d enabled %d", type, enabled);
+ struct connman_service *service = connman_service_get_default_connection();
+ DBG("service %p", service);
- if (type == technology_type && enabled == technology_enabled)
- technology_reply(0);
+ return connman_service_create_dbus_service_reply(msg, service);
}
-static struct connman_notifier technology_notifier = {
- .name = "manager",
- .priority = CONNMAN_NOTIFIER_PRIORITY_HIGH,
- .service_enabled= technology_notify,
-};
-
-static DBusMessage *enable_technology(DBusConnection *conn,
+static DBusMessage *get_connected_service(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- enum connman_service_type type;
- const char *str;
- int err;
-
- DBG("conn %p", conn);
-
- if (technology_pending != NULL)
- return __connman_error_in_progress(msg);
+ const char *ifname;
+ struct connman_service *service;
- dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
+ dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ifname,
DBUS_TYPE_INVALID);
- if (g_strcmp0(str, "ethernet") == 0)
- type = CONNMAN_SERVICE_TYPE_ETHERNET;
- else if (g_strcmp0(str, "wifi") == 0)
- type = CONNMAN_SERVICE_TYPE_WIFI;
- else if (g_strcmp0(str, "wimax") == 0)
- type = CONNMAN_SERVICE_TYPE_WIMAX;
- else if (g_strcmp0(str, "bluetooth") == 0)
- type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
- else if (g_strcmp0(str, "cellular") == 0)
- type = CONNMAN_SERVICE_TYPE_CELLULAR;
- else
- return __connman_error_invalid_arguments(msg);
-
- if (__connman_notifier_is_registered(type) == FALSE)
- return __connman_error_not_registered(msg);
+ service = connman_service_get_connected_service(ifname);
+ DBG("Interface Name %s, service %p", ifname, service);
- if (__connman_notifier_is_enabled(type) == TRUE)
- return __connman_error_already_enabled(msg);
-
- technology_type = type;
- technology_enabled = TRUE;
- technology_pending = dbus_message_ref(msg);
-
- err = __connman_element_enable_technology(type);
- if (err < 0 && err != -EINPROGRESS)
- technology_reply(-err);
- else
- technology_timeout = g_timeout_add_seconds(15,
- technology_abort, NULL);
+ return connman_service_create_dbus_service_reply(msg, service);
+}
+#endif
- return NULL;
+#if defined TIZEN_EXT_INS
+static void append_ins_structs(DBusMessageIter *iter, void *user_data)
+{
+ __connman_ins_list_struct(iter);
}
-static DBusMessage *disable_technology(DBusConnection *conn,
+static DBusMessage *get_ins(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- enum connman_service_type type;
- const char *str;
- int err;
-
- DBG("conn %p", conn);
-
- if (technology_pending != NULL)
- return __connman_error_in_progress(msg);
+ DBusMessage *reply;
- dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INVALID);
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return NULL;
- if (g_strcmp0(str, "ethernet") == 0)
- type = CONNMAN_SERVICE_TYPE_ETHERNET;
- else if (g_strcmp0(str, "wifi") == 0)
- type = CONNMAN_SERVICE_TYPE_WIFI;
- else if (g_strcmp0(str, "wimax") == 0)
- type = CONNMAN_SERVICE_TYPE_WIMAX;
- else if (g_strcmp0(str, "bluetooth") == 0)
- type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
- else if (g_strcmp0(str, "cellular") == 0)
- type = CONNMAN_SERVICE_TYPE_CELLULAR;
- else
- return __connman_error_invalid_arguments(msg);
+ __connman_dbus_append_objpath_dict_array(reply,
+ append_ins_structs, NULL);
- if (__connman_notifier_is_registered(type) == FALSE)
- return __connman_error_not_registered(msg);
+ return reply;
+}
+#endif
- if (__connman_notifier_is_enabled(type) == FALSE)
- return __connman_error_already_disabled(msg);
+static void append_peer_structs(DBusMessageIter *iter, void *user_data)
+{
+ __connman_peer_list_struct(iter);
+}
- technology_type = type;
- technology_enabled = FALSE;
- technology_pending = dbus_message_ref(msg);
+static DBusMessage *get_peers(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
- err = __connman_element_disable_technology(type);
- if (err < 0 && err != -EINPROGRESS)
- technology_reply(-err);
- else
- technology_timeout = g_timeout_add_seconds(10,
- technology_abort, NULL);
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return NULL;
- return NULL;
+ __connman_dbus_append_objpath_dict_array(reply,
+ append_peer_structs, NULL);
+ return reply;
}
-static DBusMessage *connect_service(DBusConnection *conn,
+static DBusMessage *get_tethering_clients(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- int err;
+ DBusMessage *reply;
+ DBusMessageIter iter, array;
- DBG("conn %p", conn);
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return NULL;
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
- return __connman_error_permission_denied(msg);
+ dbus_message_iter_init_append(reply, &iter);
- err = __connman_service_create_and_connect(msg);
- if (err < 0) {
- if (err == -EINPROGRESS) {
- connman_error("Invalid return code from connect");
- err = -EINVAL;
- }
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &array);
- return __connman_error_failed(msg, -err);
- }
+ __connman_tethering_list_clients(&array);
- return NULL;
+ dbus_message_iter_close_container(&iter, &array);
+ return reply;
}
-
static DBusMessage *connect_provider(DBusConnection *conn,
- DBusMessage *msg, void *data)
+ DBusMessage *msg, void *data)
{
int err;
DBG("conn %p", conn);
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
- return __connman_error_permission_denied(msg);
-
err = __connman_provider_create_and_connect(msg);
- if (err < 0) {
- if (err == -EINPROGRESS) {
- connman_error("Invalid return code from connect");
- err = -EINVAL;
- }
-
+ if (err < 0)
return __connman_error_failed(msg, -err);
- }
return NULL;
}
dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- err = __connman_agent_register(sender, path);
+ err = connman_agent_register(sender, path);
if (err < 0)
return __connman_error_failed(msg, -err);
dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- err = __connman_agent_unregister(sender, path);
+ err = connman_agent_unregister(sender, path);
if (err < 0)
return __connman_error_failed(msg, -err);
DBusMessage *msg, void *data)
{
const char *sender, *path;
- unsigned int interval;
+ unsigned int accuracy, period;
int err;
DBG("conn %p", conn);
sender = dbus_message_get_sender(msg);
dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_UINT32, &interval,
+ DBUS_TYPE_UINT32, &accuracy,
+ DBUS_TYPE_UINT32, &period,
DBUS_TYPE_INVALID);
- err = __connman_counter_register(sender, path, interval);
+ /* FIXME: add handling of accuracy parameter */
+
+ err = __connman_counter_register(sender, path, period);
if (err < 0)
return __connman_error_failed(msg, -err);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
-static DBusMessage *request_session(DBusConnection *conn,
+static DBusMessage *create_session(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- const char *bearer, *sender, *service_path;
- struct connman_service *service;
+ int err;
DBG("conn %p", conn);
- sender = dbus_message_get_sender(msg);
+ err = __connman_session_create(msg);
+ if (err < 0) {
+ if (err == -EINPROGRESS)
+ return NULL;
- dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &bearer,
- DBUS_TYPE_INVALID);
+ return __connman_error_failed(msg, -err);
+ }
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
- service = __connman_session_request(bearer, sender);
- if (service == NULL)
- return __connman_error_failed(msg, EINVAL);
+static DBusMessage *destroy_session(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ int err;
- service_path = __connman_service_get_path(service);
+ DBG("conn %p", conn);
- return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &service_path,
- DBUS_TYPE_INVALID);
+ err = __connman_session_destroy(msg);
+ if (err < 0)
+ return __connman_error_failed(msg, -err);
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
-static DBusMessage *release_session(DBusConnection *conn,
+static DBusMessage *request_private_network(DBusConnection *conn,
DBusMessage *msg, void *data)
{
const char *sender;
- int err;
+ int err;
DBG("conn %p", conn);
sender = dbus_message_get_sender(msg);
- err = __connman_session_release(sender);
+ err = __connman_private_network_request(msg, sender);
+ if (err < 0)
+ return __connman_error_failed(msg, -err);
+
+ return NULL;
+}
+
+static DBusMessage *release_private_network(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const char *path;
+ int err;
+
+ DBG("conn %p", conn);
+
+ dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
+
+ err = __connman_private_network_release(path);
if (err < 0)
return __connman_error_failed(msg, -err);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
-static GDBusMethodTable manager_methods[] = {
- { "GetProperties", "", "a{sv}", get_properties },
- { "SetProperty", "sv", "", set_property },
- { "GetState", "", "s", get_state },
- { "CreateProfile", "s", "o", create_profile },
- { "RemoveProfile", "o", "", remove_profile },
- { "RemoveProvider", "s", "", remove_provider },
- { "RequestScan", "s", "", request_scan },
- { "EnableTechnology", "s", "", enable_technology,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "DisableTechnology", "s", "", disable_technology,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "ConnectService", "a{sv}", "o", connect_service,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "ConnectProvider", "a{sv}", "o", connect_provider,
- G_DBUS_METHOD_FLAG_ASYNC },
- { "RegisterAgent", "o", "", register_agent },
- { "UnregisterAgent", "o", "", unregister_agent },
- { "RegisterCounter", "ou", "", register_counter },
- { "UnregisterCounter", "o", "", unregister_counter },
- { "RequestSession", "s", "o", request_session },
- { "ReleaseSession", "s", "", release_session },
- { },
-};
+static int parse_peers_service_specs(DBusMessageIter *array,
+ const unsigned char **spec, int *spec_len,
+ const unsigned char **query, int *query_len,
+ int *version)
+{
+ *spec = *query = NULL;
+ *spec_len = *query_len = *version = 0;
+
+ while (dbus_message_iter_get_arg_type(array) ==
+ DBUS_TYPE_DICT_ENTRY) {
+ DBusMessageIter entry, inter, value;
+ const char *key;
+
+ dbus_message_iter_recurse(array, &entry);
+ dbus_message_iter_get_basic(&entry, &key);
+
+ dbus_message_iter_next(&entry);
+
+ dbus_message_iter_recurse(&entry, &inter);
+
+ if (!g_strcmp0(key, "BonjourResponse")) {
+ dbus_message_iter_recurse(&inter, &value);
+ dbus_message_iter_get_fixed_array(&value,
+ spec, spec_len);
+ } else if (!g_strcmp0(key, "BonjourQuery")) {
+ dbus_message_iter_recurse(&inter, &value);
+ dbus_message_iter_get_fixed_array(&value,
+ query, query_len);
+ } else if (!g_strcmp0(key, "UpnpService")) {
+ dbus_message_iter_get_basic(&inter, spec);
+ *spec_len = strlen((const char *)*spec)+1;
+ } else if (!g_strcmp0(key, "UpnpVersion")) {
+ dbus_message_iter_get_basic(&inter, version);
+ } else if (!g_strcmp0(key, "WiFiDisplayIEs")) {
+ if (*spec || *query)
+ return -EINVAL;
+
+ dbus_message_iter_recurse(&inter, &value);
+ dbus_message_iter_get_fixed_array(&value,
+ spec, spec_len);
+ } else
+ return -EINVAL;
-static GDBusSignalTable manager_signals[] = {
- { "PropertyChanged", "sv" },
- { "StateChanged", "s" },
- { },
-};
+ dbus_message_iter_next(array);
+ }
+
+ if ((*query && !*spec && !*version) ||
+ (!*spec && !*query) || (!*spec && *version))
+ return -EINVAL;
+
+ return 0;
+}
+
+static DBusMessage *register_peer_service(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const unsigned char *spec, *query;
+ DBusMessageIter iter, array;
+ int spec_len, query_len;
+ dbus_bool_t master;
+ const char *owner;
+ int version;
+ int ret;
-static DBusMessage *nm_sleep(DBusConnection *conn,
+ DBG("");
+
+ owner = dbus_message_get_sender(msg);
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_recurse(&iter, &array);
+
+ ret = parse_peers_service_specs(&array, &spec, &spec_len,
+ &query, &query_len, &version);
+ if (ret)
+ goto error;
+
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &master);
+
+ ret = __connman_peer_service_register(owner, msg, spec, spec_len,
+ query, query_len, version,master);
+ if (!ret)
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+ if (ret == -EINPROGRESS)
+ return NULL;
+error:
+ return __connman_error_failed(msg, -ret);
+}
+
+static DBusMessage *unregister_peer_service(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const unsigned char *spec, *query;
+ DBusMessageIter iter, array;
+ int spec_len, query_len;
+ const char *owner;
+ int version;
+ int ret;
+
+ DBG("");
+
+ owner = dbus_message_get_sender(msg);
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_recurse(&iter, &array);
+
+ ret = parse_peers_service_specs(&array, &spec, &spec_len,
+ &query, &query_len, &version);
+ if (ret)
+ goto error;
+
+ ret = __connman_peer_service_unregister(owner, spec, spec_len,
+ query, query_len, version);
+ if (!ret)
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+error:
+ return __connman_error_failed(msg, -ret);
+
+}
+
+#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;
- DBG("conn %p", conn);
-
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
- dbus_message_append_args(reply, DBUS_TYPE_INVALID);
-
+ __connman_dbus_append_objpath_dict_array(reply,
+ append_mesh_peer_structs, NULL);
return reply;
}
-static DBusMessage *nm_wake(DBusConnection *conn,
+static DBusMessage *get_connected_mesh_peers(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
-
- DBG("conn %p", conn);
+ DBusMessageIter iter, array;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
- dbus_message_append_args(reply, DBUS_TYPE_INVALID);
-
+ 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;
}
-enum {
- NM_STATE_UNKNOWN = 0,
- NM_STATE_ASLEEP,
- NM_STATE_CONNECTING,
- NM_STATE_CONNECTED,
- NM_STATE_DISCONNECTED
-};
-
-static DBusMessage *nm_state(DBusConnection *conn,
+static DBusMessage *get_disconnected_mesh_peers(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- dbus_uint32_t state;
-
- DBG("conn %p", conn);
+ DBusMessageIter iter, array;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
- if (__connman_notifier_count_connected() > 0)
- state = NM_STATE_CONNECTED;
- else
- state = NM_STATE_DISCONNECTED;
+ 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_append_args(reply, DBUS_TYPE_UINT32, &state,
+ dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr,
DBUS_TYPE_INVALID);
- return reply;
+ 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 GDBusMethodTable nm_methods[] = {
- { "sleep", "", "", nm_sleep },
- { "wake", "", "", nm_wake },
- { "state", "", "u", nm_state },
+static const GDBusMethodTable manager_methods[] = {
+ { GDBUS_METHOD("GetProperties",
+ NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+ get_properties) },
+ { GDBUS_ASYNC_METHOD("SetProperty",
+ GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
+ NULL, set_property) },
+ { GDBUS_METHOD("GetTechnologies",
+ NULL, GDBUS_ARGS({ "technologies", "a(oa{sv})" }),
+ get_technologies) },
+ { GDBUS_DEPRECATED_METHOD("RemoveProvider",
+ GDBUS_ARGS({ "provider", "o" }), NULL,
+ remove_provider) },
+ { GDBUS_METHOD("GetServices",
+ NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
+ get_services) },
+#if defined TIZEN_EXT
+ { GDBUS_METHOD("GetInterfaces",
+ NULL, GDBUS_ARGS({ "interface_list", "as" }),
+ get_interfaces) },
+ { GDBUS_METHOD("GetDefaultService",
+ NULL, GDBUS_ARGS({ "service", "oa{sv}" }),
+ get_default_service) },
+ { GDBUS_METHOD("GetConnectedService",
+ GDBUS_ARGS({ "ifname", "s" }),
+ GDBUS_ARGS({ "service", "oa{sv}" }),
+ get_connected_service) },
+#endif
+#if defined TIZEN_EXT_INS
+ { GDBUS_METHOD("GetINS",
+ NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }),
+ get_ins) },
+#endif
+ { GDBUS_METHOD("GetPeers",
+ NULL, GDBUS_ARGS({ "peers", "a(oa{sv})" }),
+ get_peers) },
+ { GDBUS_METHOD("GetTetheringClients",
+ NULL, GDBUS_ARGS({ "tethering_clients", "as" }),
+ get_tethering_clients) },
+ { GDBUS_DEPRECATED_ASYNC_METHOD("ConnectProvider",
+ GDBUS_ARGS({ "provider", "a{sv}" }),
+ GDBUS_ARGS({ "path", "o" }),
+ connect_provider) },
+ { GDBUS_METHOD("RegisterAgent",
+ GDBUS_ARGS({ "path", "o" }), NULL,
+ register_agent) },
+ { GDBUS_METHOD("UnregisterAgent",
+ GDBUS_ARGS({ "path", "o" }), NULL,
+ unregister_agent) },
+ { GDBUS_METHOD("RegisterCounter",
+ GDBUS_ARGS({ "path", "o" }, { "accuracy", "u" },
+ { "period", "u" }),
+ NULL, register_counter) },
+ { GDBUS_METHOD("UnregisterCounter",
+ GDBUS_ARGS({ "path", "o" }), NULL,
+ unregister_counter) },
+ { GDBUS_ASYNC_METHOD("CreateSession",
+ GDBUS_ARGS({ "settings", "a{sv}" },
+ { "notifier", "o" }),
+ GDBUS_ARGS({ "session", "o" }),
+ create_session) },
+ { GDBUS_METHOD("DestroySession",
+ GDBUS_ARGS({ "session", "o" }), NULL,
+ destroy_session) },
+ { GDBUS_ASYNC_METHOD("RequestPrivateNetwork",
+ NULL, GDBUS_ARGS({ "path", "o" },
+ { "settings", "a{sv}" },
+ { "socket", "h" }),
+ request_private_network) },
+ { GDBUS_METHOD("ReleasePrivateNetwork",
+ GDBUS_ARGS({ "path", "o" }), NULL,
+ release_private_network) },
+ { GDBUS_ASYNC_METHOD("RegisterPeerService",
+ GDBUS_ARGS({ "specification", "a{sv}" },
+ { "master", "b" }), NULL,
+ register_peer_service) },
+ { 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
{ },
};
-static gboolean nm_compat = FALSE;
+static const GDBusSignalTable manager_signals[] = {
+ { GDBUS_SIGNAL("PropertyChanged",
+ GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+ { GDBUS_SIGNAL("TechnologyAdded",
+ GDBUS_ARGS({ "path", "o" },
+ { "properties", "a{sv}" })) },
+ { GDBUS_SIGNAL("TechnologyRemoved",
+ GDBUS_ARGS({ "path", "o" })) },
+ { GDBUS_SIGNAL("ServicesChanged",
+ GDBUS_ARGS({ "changed", "a(oa{sv})" },
+ { "removed", "ao" })) },
+ { GDBUS_SIGNAL("PeersChanged",
+ GDBUS_ARGS({ "changed", "a(oa{sv})" },
+ { "removed", "ao" })) },
+ { },
+};
-int __connman_manager_init(gboolean compat)
+int __connman_manager_init(void)
{
DBG("");
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -1;
if (connman_notifier_register(&technology_notifier) < 0)
manager_methods,
manager_signals, NULL, NULL, NULL);
- if (compat == TRUE) {
- g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
- nm_methods, NULL, NULL, NULL, NULL);
-
- nm_compat = TRUE;
- }
+ connman_state_idle = true;
return 0;
}
{
DBG("");
- connman_notifier_unregister(&technology_notifier);
-
- if (connection == NULL)
+ if (!connection)
return;
- if (nm_compat == TRUE) {
- g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
- }
+ connman_notifier_unregister(&technology_notifier);
g_dbus_unregister_interface(connection, CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE);