return att_result;
}
-static void __bt_gatt_close_gdbus_connection(void)
-{
- GError *err = NULL;
-
- BT_DBG("+");
-
- ret_if(g_conn == NULL);
-
- if (!g_dbus_connection_flush_sync(g_conn, NULL, &err)) {
- BT_ERR("Fail to flush the connection: %s", err->message);
- g_error_free(err);
- err = NULL;
- }
-
- if (!g_dbus_connection_close_sync(g_conn, NULL, &err)) {
- if (err) {
- BT_ERR("Fail to close the dbus connection: %s", err->message);
- g_error_free(err);
- }
- }
-
- g_object_unref(g_conn);
-
- g_conn = NULL;
-
- BT_DBG("-");
-}
-
#ifdef TIZEN_FEATURE_BT_HPS
static int __bt_send_event_to_hps(int event, GVariant *var)
{
GDBusProxy *proxy;
GError *err = NULL;
- if (g_conn == NULL)
- g_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM,
- NULL, &err);
-
+ g_conn = _bt_init_system_gdbus_conn();
if (!g_conn) {
- if (err) {
- BT_ERR("Unable to connect to gdbus: %s", err->message);
- g_clear_error(&err);
- }
+ BT_ERR("Unable to get connection");
return NULL;
}
return BLUETOOTH_ERROR_NONE;
}
-static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
-{
- GDBusConnection *local_system_gconn = NULL;
- char *address;
- GError *err = NULL;
-
- if (g_conn == NULL) {
- address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (address == NULL) {
- if (err) {
- BT_ERR("Failed to get bus address: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
-
- g_conn = g_dbus_connection_new_for_address_sync(address,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- NULL, /* GDBusAuthObserver */
- NULL,
- &err);
- g_free(address);
- if (!g_conn) {
- if (err) {
- BT_ERR("Unable to connect to dbus: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
- } else if (g_dbus_connection_is_closed(g_conn)) {
- address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (address == NULL) {
- if (err) {
- BT_ERR("Failed to get bus address: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
-
- local_system_gconn = g_dbus_connection_new_for_address_sync(address,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- NULL, /* GDBusAuthObserver */
- NULL,
- &err);
- g_free(address);
- if (!local_system_gconn) {
- BT_ERR("Unable to connect to dbus: %s", err->message);
- g_clear_error(&err);
- }
-
- g_conn = local_system_gconn;
- }
-
- return g_conn;
-}
-
BT_EXPORT_API int bluetooth_gatt_init(void)
{
- GDBusConnection *conn;
GError *error = NULL;
GDBusNodeInfo *node_info = NULL;
return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
}
+ g_conn = _bt_init_system_gdbus_conn();
+ if (!g_conn) {
+ BT_ERR("Unable to get connection");
+ goto failed;
+ }
+
if (owner_id == 0) {
- owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- BT_GATT_SERVICE_NAME,
+ gchar *name = g_strdup_printf("%s.p%d", BT_GATT_SERVICE_NAME, getpid());
+ BT_DBG("well-known name: %s", name);
+
+ owner_id = g_bus_own_name_on_connection(g_conn, name,
G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL);
+ g_free(name);
}
-
BT_DBG("owner_id is [%d]", owner_id);
+
app_path = g_strdup_printf("/com/%d", getpid());
serv_id = 1;
- conn = __bt_gatt_get_gdbus_connection();
- if (!conn) {
- BT_ERR("Unable to get connection");
- goto failed;
- }
-
/* Register ObjectManager interface */
node_info = __bt_gatt_create_method_node_info(
manager_introspection_xml);
app_path = NULL;
owner_id = 0;
- __bt_gatt_close_gdbus_connection();
-
return BLUETOOTH_ERROR_INTERNAL;
}
if (owner_id == 0) {
BT_ERR("owner_id is zero");
- __bt_gatt_close_gdbus_connection();
return BLUETOOTH_ERROR_NOT_FOUND;
}
manager_gproxy = NULL;
}
- __bt_gatt_close_gdbus_connection();
-
BT_DBG("-");
return ret;
}
<allow own_prefix="org.bt.frwk"/>
<allow send_interface="org.bluez.Profile1" send_member="NewConnection"/>
<allow send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
- <!-- No send_destination because private connection does not have well-known service name -->
- <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
- <allow send_interface="org.bluez.GattCharacteristic1"/>
- <allow send_interface="org.bluez.GattDescriptor1"/>
+ <allow own_prefix="org.frwk.gatt_service"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.Properties"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.ObjectManager"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattCharacteristic1"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattDescriptor1"/>
</policy>
<policy group="network_fw">
<!-- service name(org.bt.frwk.p<pid>) is changeable by pid -->
<allow own_prefix="org.bt.frwk"/>
<allow send_interface="org.bluez.Profile1" send_member="NewConnection"/>
<allow send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
- <!-- No send_destination because private connection does not have well-known service name -->
- <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
- <allow send_interface="org.bluez.GattCharacteristic1"/>
- <allow send_interface="org.bluez.GattDescriptor1"/>
+ <allow own_prefix="org.frwk.gatt_service"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.Properties"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.freedesktop.DBus.ObjectManager"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattCharacteristic1"/>
+ <allow send_destination_prefix="org.frwk.gatt_service" send_interface="org.bluez.GattDescriptor1"/>
</policy>
<policy context="default">
<deny own_prefix="org.bt.frwk"/>
<deny send_interface="org.bluez.Profile1" send_member="NewConnection"/>
<deny send_interface="org.bluez.Profile1" send_member="RequestDisconnection"/>
+ <deny own_prefix="org.frwk.gatt_service"/>
+ <deny send_destination_prefix="org.frwk.gatt_service"/>
</policy>
</busconfig>
return BT_STATUS_SUCCESS;
}
-static void __bt_gatt_close_gdbus_connection(void)
-{
- GError *err = NULL;
- DBG("+");
-
- if (g_conn == NULL)
- return;
-
- if (!g_dbus_connection_flush_sync(g_conn, NULL, &err)) {
- ERR("Fail to flush the connection: %s", err->message);
- g_error_free(err);
- err = NULL;
- }
-
- if (!g_dbus_connection_close_sync(g_conn, NULL, &err)) {
- if (err) {
- ERR("Fail to close the dbus connection: %s", err->message);
- g_error_free(err);
- }
- }
-
- g_object_unref(g_conn);
- g_conn = NULL;
- DBG("-");
-}
-
-static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
-{
- GDBusConnection *local_system_gconn = NULL;
- char *address;
- GError *err = NULL;
-
- if (g_conn == NULL) {
- address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (address == NULL) {
- if (err) {
- ERR("Failed to get bus address: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
-
- g_conn = g_dbus_connection_new_for_address_sync(address,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- NULL, /* GDBusAuthObserver */
- NULL,
- &err);
- if (!g_conn) {
- if (err) {
- ERR("Unable to connect to dbus: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
- } else if (g_dbus_connection_is_closed(g_conn)) {
- address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (address == NULL) {
- if (err) {
- ERR("Failed to get bus address: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
-
- local_system_gconn = g_dbus_connection_new_for_address_sync(address,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- NULL, /* GDBusAuthObserver */
- NULL,
- &err);
-
- if (!local_system_gconn) {
- ERR("Unable to connect to dbus: %s", err->message);
- g_clear_error(&err);
- }
-
- g_conn = local_system_gconn;
- }
-
- return g_conn;
-}
-
static char* __bt_hal_convert_uuid_to_string(bt_uuid_t *srvc_id)
{
char uuid_buf[5];
if (gatt_server_apps == NULL) {
INFO("All GATT servers are removed, clean all DBUS resources");
if (owner_id) {
- /* unregister the exported interface for object manager
- g_conn and manager_id are common for all GATT servers */
- g_dbus_connection_unregister_object(g_conn,
- manager_id);
+ /* unregister the exported interface for object manager */
+ g_dbus_connection_unregister_object(g_conn, manager_id);
manager_id = 0;
g_bus_unown_name(owner_id);
owner_id = 0;
g_object_unref(manager_gproxy);
manager_gproxy = NULL;
-
- /* Close the GDBUS connection */
- __bt_gatt_close_gdbus_connection();
}
}
INFO("-");
}
-int __bt_hal_gatt_init(void)
+static int __bt_hal_gatt_init(void)
{
- GDBusConnection *conn = NULL;
DBG("+");
+
/* Only once for ALL GATT Servers */
if (owner_id == 0) {
- owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- BT_GATT_SERVICE_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL, NULL);
- }
- INFO("Owner ID [%d]", owner_id);
+ GError *err = NULL;
+ gchar *name = NULL;
- /* Only once for ALL GATT Servers conn = g_conn(global)*/
- conn = __bt_gatt_get_gdbus_connection();
- if (!conn) {
- ERR("Unable to get connection");
- return BT_STATUS_FAIL;
+ g_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (!g_conn) {
+ if (err) {
+ ERR("Unable to connect to gdbus: %s", err->message);
+ g_clear_error(&err);
+ }
+ return BT_STATUS_FAIL;
+ }
+
+ name = g_strdup_printf("%s.p%d", BT_GATT_SERVICE_NAME, getpid());
+ INFO("well-known name: %s", name);
+
+ owner_id = g_bus_own_name_on_connection(g_conn, name,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL, NULL);
}
+ INFO("Owner ID [%d]", owner_id);
/* Only once for ALL GATT Servers */
if (manager_node_info == NULL) {
char *app_path = NULL;
GError *error = NULL;
int *app_id = NULL;
- guint manager_id;
int result = BT_STATUS_SUCCESS;
g_error_free(error);
goto failed;
}
+ INFO("manager_id [%d]", manager_id);
/* For current GATT Server, app_path is created, save it in Table */
_bt_hal_update_gatt_server_path(server_if, app_path);