#include "bt-dpm.h"
#endif
-
static bt_user_info_t user_info[BT_MAX_USER_INFO];
-static GDBusConnection *system_gdbus_conn = NULL;
-
+static GDBusConnection *system_shared_conn = NULL;
+static GDBusConnection *system_private_conn = NULL;
static guint bus_id;
-static GDBusConnection *system_gconn = NULL;
-
static gboolean bt_enabled = FALSE;
#define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
-GDBusConnection *g_bus_get_private_conn(void)
+static GDBusConnection *g_bus_get_private_conn(void)
{
GError *error = NULL;
char *address;
return private_gconn;
}
-GDBusConnection *_bt_gdbus_init_system_gconn(void)
+GDBusConnection *_bt_get_system_private_conn(void)
{
- if (system_gconn != NULL)
- return system_gconn;
-
- system_gconn = g_bus_get_private_conn();
+ if (system_private_conn == NULL)
+ system_private_conn = g_bus_get_private_conn();
+ else if (g_dbus_connection_is_closed(system_private_conn))
+ system_private_conn = g_bus_get_private_conn();
- return system_gconn;
+ return system_private_conn;
}
-GDBusConnection *_bt_gdbus_get_system_gconn(void)
+GDBusConnection *_bt_get_system_shared_conn(void)
{
- if (system_gconn == NULL)
- system_gconn = _bt_gdbus_init_system_gconn();
- else if (g_dbus_connection_is_closed(system_gconn))
- system_gconn = g_bus_get_private_conn();
-
- return system_gconn;
+ if (system_shared_conn == NULL) {
+ GError *error = NULL;
+ system_shared_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (error) {
+ BT_ERR("GDBus connection Error : %s \n", error->message);
+ g_clear_error(&error);
+ return NULL;
+ }
+ }
+ return system_shared_conn;
}
void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
{BT_UPDATE_LE_CONNECTION_MODE, "BT_UPDATE_LE_CONNECTION_MODE"},
{BT_SET_PROFILE_TRUSTED, "BT_SET_PROFILE_TRUSTED"},
{BT_GET_PROFILE_TRUSTED, "BT_GET_PROFILE_TRUSTED"},
+ {BT_DISCONNECT_DEVICE, "BT_DISCONNECT_DEVICE"},
{BT_HID_CONNECT, "BT_HID_CONNECT"},
{BT_HID_DISCONNECT, "BT_HID_DISCONNECT"},
{BT_HID_DEVICE_ACTIVATE, "BT_HID_DEVICE_ACTIVATE"},
{BT_AVRCP_TARGET_CONNECT, "BT_AVRCP_TARGET_CONNECT"},
{BT_AVRCP_TARGET_DISCONNECT, "BT_AVRCP_TARGET_DISCONNECT"},
{BT_AVRCP_HANDLE_CONTROL, "BT_AVRCP_HANDLE_CONTROL"},
+ {BT_AVRCP_HANDLE_CONTROL_TO_DEST, "BT_AVRCP_HANDLE_CONTROL_TO_DEST"},
{BT_AVRCP_CONTROL_SET_PROPERTY, "BT_AVRCP_CONTROL_SET_PROPERTY"},
{BT_AVRCP_CONTROL_GET_PROPERTY, "BT_AVRCP_CONTROL_GET_PROPERTY"},
{BT_AVRCP_GET_TRACK_INFO, "BT_AVRCP_GET_TRACK_INFO"},
static GDBusProxy *profile_gproxy;
-static GDBusConnection *gconn;
static int latest_id = -1;
#define BT_RFCOMM_ID_MAX 245
static gboolean id_used[BT_RFCOMM_ID_MAX];
latest_id = id - 1;
}
-static GDBusConnection *__get_gdbus_connection()
-{
- if (gconn == NULL)
- gconn = g_bus_get_private_conn();
-
- return gconn;
-}
-
static GDBusProxy *__bt_gdbus_get_profile_proxy(void)
{
GDBusConnection *gconn;
if (profile_gproxy)
return profile_gproxy;
- gconn = __get_gdbus_connection();
+ /* Shared connection should be used because rfcomm interface was registered
+ * on shared connection not private. Otherwise, dbus rejection is occured
+ * because dbus policy is only applied on shared connection not private. */
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return NULL;
GError *err = NULL;
GDBusProxy *device_gproxy;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_private_conn();
if (gconn == NULL)
return NULL;
{
GDBusConnection *gconn;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return;
g_dbus_connection_unregister_object(gconn, object_id);
+
+ /* TODO: bus_id needs to be un-owned if all of path is unregistered */
+}
+
+static GDBusNodeInfo *_bt_get_gdbus_node(GDBusConnection *gconn, const gchar *xml_data, const char *bus_name)
+{
+ if (bus_id == 0) {
+ char *name = g_strdup(bus_name);
+ BT_DBG("well-known name: %s", name);
+ bus_id = g_bus_own_name_on_connection(gconn,
+ name, G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL, NULL);
+ BT_DBG("Got bus id %d", bus_id);
+ g_free(name);
+ }
+
+ return g_dbus_node_info_new_for_xml(xml_data, NULL);
}
int _bt_register_new_conn(const char *path, bt_new_connection_cb cb)
GDBusNodeInfo *node_info;
int id;
GError *error = NULL;
+ char *bus_name;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return -1;
- node_info = _bt_get_gdbus_node(rfcomm_agent_xml);
- if (node_info == NULL)
+ bus_name = g_strdup_printf("org.bt.frwk.p%d", getpid());
+
+ node_info = _bt_get_gdbus_node(gconn, rfcomm_agent_xml, bus_name);
+ if (node_info == NULL) {
+ g_free(bus_name);
return -1;
+ }
+ g_free(bus_name);
id = g_dbus_connection_register_object(gconn, path,
node_info->interfaces[0],
GVariant *result = NULL;
char *adapter_path = NULL;
- conn = __get_gdbus_connection();
+ conn = _bt_get_system_private_conn();
retv_if(conn == NULL, NULL);
manager_proxy = g_dbus_proxy_new_sync(conn,
int id;
GError *error = NULL;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return -1;
- node_info = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name);
-
+ node_info = _bt_get_gdbus_node(gconn, rfcomm_agent_xml, bus_name);
if (node_info == NULL)
return -1;
NULL, &err);
if (err) {
g_dbus_error_strip_remote_error(err);
- BT_ERR("RegisterProfile failed: %s", err->message);
+ BT_ERR("RegisterProfile2 failed: %s", err->message);
if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
result = BLUETOOTH_ERROR_ACCESS_DENIED;
if (err) {
g_dbus_error_strip_remote_error(err);
- BT_ERR("RegisterProfile failed: %s", err->message);
+ BT_ERR("RegisterProfile1 failed: %s", err->message);
if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
result = BLUETOOTH_ERROR_ACCESS_DENIED;
return;
}
-GDBusNodeInfo * _bt_get_gdbus_node(const gchar *xml_data)
-{
- if (bus_id == 0) {
- char *name = g_strdup_printf("org.bt.frwk.p%d", getpid());
-
- bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- name,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
- BT_DBG("Got bus id %d", bus_id);
- g_free(name);
- }
-
- return g_dbus_node_info_new_for_xml(xml_data, NULL);
-}
-
-GDBusNodeInfo * _bt_get_gdbus_node_ex(const gchar *xml_data, const char *bus_name)
-{
- if (bus_id == 0) {
- char *name = g_strdup(bus_name);
- bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- name,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
- BT_DBG("Got bus id %d", bus_id);
- g_free(name);
- }
-
- return g_dbus_node_info_new_for_xml(xml_data, NULL);
-}
-
int _bt_connect_profile(char *address, char *uuid, void *cb,
gpointer func_data)
{
int result = BLUETOOTH_ERROR_INTERNAL;
BT_INFO("+");
retv_if(remote_uuid == NULL, BLUETOOTH_ERROR_INTERNAL);
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_private_conn();
retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL);
object_path = _bt_get_device_object_path(address);
retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
unsigned int class = 0x00;
int ret = BLUETOOTH_ERROR_NONE;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_private_conn();
retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL);
object_path = _bt_get_device_object_path(address);
GDBusConnection *conn = NULL;
char *object_path = NULL;
- conn = _bt_gdbus_get_system_gconn();
+ conn = _bt_get_system_private_conn();
retv_if(conn == NULL, NULL);
proxy = g_dbus_proxy_new_sync(conn,
return object_path;
}
-GDBusConnection *_bt_init_system_gdbus_conn(void)
-{
- GError *error = NULL;
- if (system_gdbus_conn == NULL) {
- system_gdbus_conn =
- g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (error) {
- BT_ERR("GDBus connection Error : %s \n",
- error->message);
- g_clear_error(&error);
- return NULL;
- }
- }
- return system_gdbus_conn;
-}
-
-
int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
{
int ret;
BT_DBG("+");
- g_conn = _bt_gdbus_get_system_gconn();
+ g_conn = _bt_get_system_private_conn();
retv_if(g_conn == NULL, NULL);
manager_proxy = g_dbus_proxy_new_sync(g_conn,
{
int ret;
- _bt_gdbus_init_system_gconn();
+ _bt_get_system_private_conn();
ret = _bt_init_event_handler();
if (ret != BLUETOOTH_ERROR_NONE &&
_bt_gdbus_deinit_proxys();
- if (system_gconn) {
- g_object_unref(system_gconn);
- system_gconn = NULL;
+ if (system_private_conn) {
+ g_object_unref(system_private_conn);
+ system_private_conn = NULL;
}
return BLUETOOTH_ERROR_NONE;