#include <errno.h>
#include <termios.h>
#include <net_connection.h>
+#include <dbus/dbus.h>
#include <glib.h>
#include <dlog.h>
#include <fcntl.h>
#include "bluetooth-api.h"
#include "bt-service-common.h"
#include "bt-service-agent.h"
-#include "bt-internal-types.h"
static GDBusConnection *system_conn;
static GDBusConnection *session_conn;
static GDBusProxy *manager_proxy;
static GDBusProxy *adapter_proxy;
-static GDBusProxy *ipsp_proxy;
static void *net_conn;
static GDBusProxy *adapter_properties_proxy;
{
GError *error = NULL;
+ dbus_threads_init_default();
+
if (system_conn != NULL)
return system_conn;
{
GError *error = NULL;
+ if (!g_thread_supported())
+ g_thread_init(NULL);
+
+ dbus_threads_init_default();
+
if (session_conn != NULL)
return session_conn;
GDBusConnection *g_conn;
GDBusProxy *proxy;
+ dbus_threads_init_default();
+
g_conn = _bt_gdbus_get_system_gconn();
retv_if(g_conn == NULL, NULL);
GDBusProxy *proxy;
char *adapter_path = NULL;
+ dbus_threads_init_default();
+
g_conn = _bt_gdbus_get_system_gconn();
retv_if(g_conn == NULL, NULL);
return proxy;
}
-static GDBusProxy *__bt_init_ipsp_proxy(void)
-{
- BT_DBG("+");
-
- GDBusConnection *g_conn;
- GDBusProxy *proxy;
-
-
- g_conn = _bt_gdbus_get_system_gconn();
- retv_if(g_conn == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_IPSP_NAME,
- "/org/projectx/bt_ipsp", BT_IPSP_INTERFACE, NULL, NULL);
-
- if (!proxy) {
- BT_ERR("Unable to get proxy");
- return NULL;
- }
-
- ipsp_proxy = proxy;
-
- BT_DBG("-");
- return proxy;
-}
-
static GDBusProxy *__bt_init_adapter_properties_proxy(void)
{
GDBusConnection *g_conn;
GDBusProxy *proxy;
char *adapter_path = NULL;
+ dbus_threads_init_default();
+
g_conn = _bt_gdbus_get_system_gconn();
retv_if(g_conn == NULL, NULL);
return __bt_init_manager_proxy();
}
-GDBusProxy *_bt_get_ipsp_proxy(void)
-{
- if (ipsp_proxy) {
- const char *path = g_dbus_proxy_get_object_path(ipsp_proxy);
- if (path == NULL) {
- BT_ERR("Already proxy released hence creating new proxy");
- return __bt_init_ipsp_proxy();
- }
-
- return ipsp_proxy;
- }
- return __bt_init_ipsp_proxy();
-
-}
-
static void *__bt_init_net_conn(void)
{
int result;
}
}
-GDBusProxy *_bt_gdbus_get_hid_agent_proxy(void)
-{
- GDBusConnection *conn;
- GDBusProxy *proxy;
- GError *err = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_HID_SERVICE_NAME, BT_HID_AGENT_OBJECT_PATH,
- BT_HID_SERVICE_INTERFACE, NULL, &err);
- if (proxy == NULL) {
- if (err != NULL) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
- return NULL;
- }
-
- return proxy;
-}
-
void _bt_convert_device_path_to_address(const char *device_path,
char *device_address)
{
strncpy(addr, address, len);
addr[len] = '\0';
- addr[len-1] = 'X';
- addr[len-2] = 'X';
+ addr[len-7] = 'X';
+ addr[len-8] = 'X';
+ addr[len-10] = 'X';
+ addr[len-11] = 'X';
+ addr[len-13] = 'X';
+ addr[len-14] = 'X';
+ addr[len-16] = 'X';
+ addr[len-17] = 'X';
return;
}
return BLUETOOTH_ERROR_NONE;
}
+static char *__bt_extract_device_path(GVariantIter *iter, char *address)
+{
+ char *object_path = NULL;
+ char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ /* Parse the signature: oa{sa{sv}}} */
+ while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
+ NULL)) {
+ if (!object_path) {
+ BT_ERR("Unable to get object path");
+ return NULL;
+ }
+ _bt_convert_device_path_to_address(object_path, device_address);
+ if (g_strcmp0(address, device_address) == 0)
+ return g_strdup(object_path);
+
+ }
+
+ BT_ERR("Unable to get object path");
+ return NULL;
+}
+
char *_bt_get_device_object_path(char *address)
{
char *object_path = NULL;
+ GDBusConnection *conn;
+ GDBusProxy *manager_proxy;
GVariant *result = NULL;
- GDBusProxy *proxy;
- GError *error = NULL;
+ GVariantIter *iter = NULL;
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, NULL);
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, NULL);
- result = g_dbus_proxy_call_sync(proxy, "FindDevice",
- g_variant_new("(s)", address),
+ manager_proxy = _bt_get_manager_proxy();
+ retv_if(manager_proxy == NULL, NULL);
+
+ result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+ NULL,
G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
- if (result == NULL) {
- if (error) {
- BT_ERR("FindDevice Fail: %s", error->message);
- g_clear_error(&error);
- }
+ -1,
+ NULL,
+ NULL);
+ if (!result) {
+ BT_ERR("Can't get managed objects");
return NULL;
}
- g_variant_get(result, "(o)", &object_path);
-
+ /* signature of GetManagedObjects: a{oa{sa{sv}}} */
+ g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
+ object_path = __bt_extract_device_path(iter, address);
+ g_variant_iter_free(iter);
g_variant_unref(result);
return object_path;
}
const char *_bt_convert_uuid_to_string(const char *uuid)
{
+#define SHORT_UUID_COUNT 162
+#define LONG_UUID_COUNT 17
+
if (!uuid)
return NULL;
- int i;
int offset = 0;
int uuid_len = 4;
- static struct {
+ typedef struct {
const char *uuid;
const char *specification_name;
- } bt_uuid_name[] = {
+ } uuid_name_s;
+ static uuid_name_s short_uuid_name[SHORT_UUID_COUNT] = {
+ // List should be sorted by UUID
/* BT Classic Services */
{"1101", "Serial Port Service"},
{"1102", "LAN Access Using PPP Service"},
{"2A68", "Navigation"},
{"2A6D", "Pressure"},
{"2A6E", "Temperature"},
-
+ };
+ static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
+ // List should be sorted by UUID
/* Custom uuids */
- {"7905F431-B5CE-4E99-A40F-4B1E122D00D0", "Apple Notification Center Service"},
- {"9FBF120D-6301-42D9-8C58-25E699A21DBD", "Notifications Source"},
- {"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9", "Control Point"},
+ {"1AB7C24D-185A-45B9-90D4-F7AB1A71949A", "Samsung Health Service"},
{"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB", "Data Source"},
+ {"2F7CABCE-808D-411F-9A0C-BB92BA96C102", "Entity Update"},
+ {"32D1955A-E5AA-4A96-9A49-08538DA8B8F6", "Samsung Gear Fit Manager Service"},
+ {"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9", "Control Point"},
+ {"7905F431-B5CE-4E99-A40F-4B1E122D00D0", "Apple Notification Center Service"},
{"89D3502B-0F36-433A-8EF4-C502AD55F8DC", "Apple Media Service"},
+ {"9A3F68E0-86CE-11E5-A309-0002A5D5C51B", "Samsung Gear Manager Service"},
{"9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2", "Remote Command"},
- {"2F7CABCE-808D-411F-9A0C-BB92BA96C102", "Entity Update"},
+ {"9FBF120D-6301-42D9-8C58-25E699A21DBD", "Notifications Source"},
+ {"A49EB41E-CB06-495C-9F4F-BB80A90CDF00", "Samsung Gear Manager Service"},
+ {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"},
+ {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"},
+ {"C2F2CC0F-C085-4DD4-BE5A-ACA3074BBC72", "Control Point"},
{"C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7", "Entity Attribute"},
- {"9A3F68E0-86CE-11E5-A309-0002A5D5C51B", "Samsung Gear Manager Service"},
- {"c2f2cc0f-c085-4dd4-be5a-aca3074bbc72", "Control Point"},
- {"cece518b-28d7-4171-92d5-76a1e249a3b9", "Notifications Source"},
- {"32D1955A-E5AA-4A96-9A49-08538DA8B8F6", "Samsung Gear Fit Manager Service"},
+ {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
{"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
- {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"},
- {"1ab7c24d-185a-45b9-90d4-f7ab1a71949a", "Samsung Health Service"},
- {NULL, NULL}
};
+ const uuid_name_s *uuid_name = short_uuid_name;
+ static const char *unknown_name = "Unknown";
+ int start = 0;
+ int end = SHORT_UUID_COUNT - 1;
+ int p;
+ int ret;
if (strlen(uuid) == 36) {
if (!g_ascii_strncasecmp(uuid + 9, "0000-1000-8000-00805F9B34FB", 27))
else {
offset = 0;
uuid_len = 36;
+ end = LONG_UUID_COUNT - 1;
+ uuid_name = long_uuid_name;
}
} else if (strlen(uuid) >= 8)
offset = 4;
- for (i = 0; bt_uuid_name[i].uuid; i++) {
- if (!g_ascii_strncasecmp(uuid + offset, bt_uuid_name[i].uuid, uuid_len))
- return (char *)bt_uuid_name[i].specification_name;
+ while (start <= end) {
+ p = start + (end - start) / 2;
+ ret = g_ascii_strncasecmp(uuid + offset, uuid_name[p].uuid, uuid_len);
+ if (ret == 0)
+ return uuid_name[p].specification_name;
+ else if (ret < 0)
+ end = p - 1;
+ else
+ start = p + 1;
}
- return "Unknown";
+ BT_INFO("Unknown uuid : %s", uuid);
+ return unknown_name;
}
const char *_bt_convert_error_to_string(int error)
return "NOT_INITIALIZED";
case BLUETOOTH_ERROR_AUTHENTICATION_REJECTED:
return "AUTHENTICATION REJECTED";
+ case BLUETOOTH_ERROR_AUTHORIZATION_REJECTED:
+ return "AUTHORIZATION REJECTED";
default:
return "UNKNOWN";
}
}
}
+const char *_bt_convert_profile_state_to_string(bt_profile_state_t state)
+{
+ switch (state) {
+ case BT_PROFILE_STATE_UNAVAILABLE:
+ return "UNAVAILABLE";
+ case BT_PROFILE_STATE_DISCONNECTED:
+ return "DISCONNECTED";
+ case BT_PROFILE_STATE_CONNECTING:
+ return "CONNECTING";
+ case BT_PROFILE_STATE_CONNECTED:
+ return "CONNECTED";
+ case BT_PROFILE_STATE_DISCONNECTING:
+ return "DISCONNECTING";
+ }
+
+ return NULL;
+}
+
const char *_bt_convert_service_function_to_string(int function)
{
int i;
{BT_GET_PROFILE_CONNECTED_DEVICES, "BT_GET_PROFILE_CONNECTED_DEVICES"},
{BT_ENABLE_FORCE_HCI_DUMP, "BT_ENABLE_FORCE_HCI_DUMP"},
{BT_SET_PASSKEY_NOTIFICATION, "BT_SET_PASSKEY_NOTIFICATION"},
+ {BT_DISCONNECT_DEVICE, "BT_DISCONNECT_DEVICE"},
{BT_BOND_DEVICE, "BT_BOND_DEVICE"},
{BT_BOND_DEVICE_BY_TYPE, "BT_BOND_DEVICE_BY_TYPE"},
{BT_CANCEL_BONDING, "BT_CANCEL_BONDING"},
{
int ret = ES_R_OK;
/* Send event system event in bt-core process because bt-service's permission is not system in now */
+
#if 0
bundle *b = NULL;
is_alias_set = FALSE;
}
if (is_alias_set == FALSE) {
- tmp_value = g_variant_lookup_value(reply, "ManufacturerDataLen",
+ tmp_value = g_variant_lookup_value(reply, "LegacyManufacturerDataLen",
G_VARIANT_TYPE_UINT16);
if (tmp_value) {
manufacturer_data_len = g_variant_get_uint16(tmp_value);
} else
manufacturer_data_len = 0;
- tmp_value = g_variant_lookup_value(reply, "ManufacturerData",
+ tmp_value = g_variant_lookup_value(reply, "LegacyManufacturerData",
G_VARIANT_TYPE_ARRAY);
if (tmp_value) {
if ((manufacturer_data_len == 0) ||