/*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- * Girishashok Joshi <girish.joshi@samsung.com>
- * Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static GDBusProxy *adapter_properties_proxy;
-static GDBusConnection *system_gconn = NULL;
-
GDBusConnection *_bt_gdbus_init_system_gconn(void)
{
GError *error = NULL;
dbus_threads_init_default();
- g_type_init();
+ if (system_conn != NULL)
+ return system_conn;
- if (system_gconn != NULL)
- return system_gconn;
+ system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-
- if (!system_gconn) {
+ if (!system_conn) {
BT_ERR("Unable to connect to dbus: %s", error->message);
g_clear_error(&error);
}
- return system_gconn;
+ return system_conn;
}
GDBusConnection *_bt_gdbus_get_system_gconn(void)
GDBusConnection *local_system_gconn = NULL;
GError *error = NULL;
- if (system_gconn == NULL) {
- system_gconn = _bt_gdbus_init_system_gconn();
- } else if (g_dbus_connection_is_closed(system_gconn)){
-
+ if (system_conn == NULL) {
+ system_conn = _bt_gdbus_init_system_gconn();
+ } else if (g_dbus_connection_is_closed(system_conn)) {
local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!local_system_gconn) {
g_clear_error(&error);
}
- system_gconn = local_system_gconn;
+ system_conn = local_system_gconn;
+ }
+
+ return system_conn;
+}
+
+GDBusConnection *_bt_gdbus_init_session_gconn(void)
+{
+ GError *error = NULL;
+
+ if (!g_thread_supported())
+ g_thread_init(NULL);
+
+ dbus_threads_init_default();
+
+ if (session_conn != NULL)
+ return session_conn;
+
+ session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+ if (!session_conn) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+
+ return session_conn;
+}
+
+GDBusConnection *_bt_gdbus_get_session_gconn(void)
+{
+ GDBusConnection *local_session_gconn = NULL;
+ GError *error = NULL;
+
+ if (session_conn == NULL) {
+ session_conn = _bt_gdbus_init_session_gconn();
+ } else if (g_dbus_connection_is_closed(session_conn)) {
+ local_session_gconn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+ if (!local_session_gconn) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+
+ session_conn = local_session_gconn;
}
- return system_gconn;
+ return session_conn;
}
static GDBusProxy *__bt_init_manager_proxy(void)
{
+ GDBusConnection *g_conn;
GDBusProxy *proxy;
- g_type_init();
+ dbus_threads_init_default();
- if (system_conn == NULL) {
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
- retv_if(system_conn == NULL, NULL);
- }
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, NULL);
- proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_BLUEZ_NAME,
BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
- retv_if(proxy == NULL, NULL);
+ if (!proxy) {
+ BT_ERR("Unable to get proxy");
+ return NULL;
+ }
manager_proxy = proxy;
static GDBusProxy *__bt_init_adapter_proxy(void)
{
+ GDBusConnection *g_conn;
GDBusProxy *manager_proxy;
GDBusProxy *proxy;
char *adapter_path = NULL;
- g_type_init();
+ dbus_threads_init_default();
- if (system_conn == NULL) {
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
- retv_if(system_conn == NULL, NULL);
- }
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
retv_if(manager_proxy == NULL, NULL);
adapter_path = _bt_get_adapter_path();
retv_if(adapter_path == NULL, NULL);
- proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_BLUEZ_NAME,
adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
static GDBusProxy *__bt_init_adapter_properties_proxy(void)
{
+ GDBusConnection *g_conn;
GDBusProxy *manager_proxy;
GDBusProxy *proxy;
char *adapter_path = NULL;
- g_type_init();
+ dbus_threads_init_default();
- if (system_conn == NULL) {
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
- retv_if(system_conn == NULL, NULL);
- }
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
retv_if(manager_proxy == NULL, NULL);
adapter_path = _bt_get_adapter_path();
retv_if(adapter_path == NULL, NULL);
- proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
NULL, BT_BLUEZ_NAME,
adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
return proxy;
}
-GDBusConnection *__bt_init_system_gconn(void)
-{
- g_type_init();
-
- if (system_conn == NULL)
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-
- return system_conn;
-}
-
-GDBusConnection *__bt_init_session_conn(void)
-{
- if (session_conn == NULL)
- session_conn =g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
-
- return session_conn;
-}
-
-GDBusConnection *_bt_get_session_gconn(void)
-{
- return (session_conn) ? session_conn : __bt_init_session_conn();
-}
-
-GDBusConnection *_bt_get_system_gconn(void)
-{
- return (system_conn) ? system_conn : __bt_init_system_gconn();
-}
-
-GDBusConnection *_bt_get_system_conn(void)
-{
- GDBusConnection *g_conn;
-
- if (system_conn == NULL) {
- g_conn = __bt_init_system_gconn();
- } else {
- g_conn = system_conn;
- }
-
- retv_if(g_conn == NULL, NULL);
-
- return g_conn;
-}
-
GDBusProxy *_bt_get_manager_proxy(void)
{
if (manager_proxy) {
GVariantIter *iter = NULL;
char *adapter_path = NULL;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
dev_addr += 4;
g_strlcpy(address, dev_addr, sizeof(address));
- while ((pos = strchr(address, '_')) != NULL) {
+ while ((pos = strchr(address, '_')) != NULL)
*pos = ':';
- }
g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
}
void _bt_convert_addr_string_to_type(unsigned char *addr,
const char *address)
{
- int i;
- char *ptr = NULL;
+ int i;
+ char *ptr = NULL;
+
+ ret_if(address == NULL);
+ ret_if(addr == NULL);
+
+ for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
+ addr[i] = strtol(address, &ptr, 16);
+ if (ptr[0] != '\0') {
+ if (ptr[0] != ':')
+ return;
+
+ address = ptr + 1;
+ }
+ }
+}
+
+void _bt_convert_addr_string_to_secure_string(char *addr,
+ const char *address)
+{
+ int len;
ret_if(address == NULL);
ret_if(addr == NULL);
- for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
- addr[i] = strtol(address, &ptr, 16);
- if (ptr[0] != '\0') {
- if (ptr[0] != ':')
- return;
+ len = strlen(address);
+ ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
- address = ptr + 1;
- }
- }
+ strncpy(addr, address, len);
+
+ addr[len-1] = 'X';
+ addr[len-2] = 'X';
+
+ return;
}
void _bt_convert_addr_type_to_string(char *address,
while (count > 0 && ((i + count) < length)) {
dest[i++] = *p;
p++;
- count --;
+ count--;
}
p = next;
}
int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
{
BT_DBG("+");
- if (!_bt_agent_register_osp_server( type, uuid, path, fd))
+ if (!_bt_agent_register_osp_server(type, uuid, path, fd))
return BLUETOOTH_ERROR_INTERNAL;
return BLUETOOTH_ERROR_NONE;
int _bt_unregister_osp_server_in_agent(int type, char *uuid)
{
BT_DBG("+");
- if (!_bt_agent_unregister_osp_server( type, uuid))
+ if (!_bt_agent_unregister_osp_server(type, uuid))
return BLUETOOTH_ERROR_INTERNAL;
return BLUETOOTH_ERROR_NONE;
if (arg < 0)
return -errno;
- if (arg & O_NONBLOCK) {
+ if (arg & O_NONBLOCK)
BT_ERR("Already Non-blocking \n");
- }
arg |= O_NONBLOCK;
/* Parse the signature: oa{sa{sv}}} */
while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
NULL)) {
- retv_if(object_path == NULL, 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) {
+ if (g_strcmp0(address, device_address) == 0)
return g_strdup(object_path);
- }
+
}
+
+ BT_ERR("Unable to get object path");
return NULL;
}
GVariant *result = NULL;
GVariantIter *iter = NULL;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
manager_proxy = _bt_get_manager_proxy();
char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
{
- switch(profile_type) {
+ switch (profile_type) {
case BT_PROFILE_CONN_RFCOMM:
return strdup(RFCOMM_UUID_STR);
case BT_PROFILE_CONN_A2DP:
return strdup(NAP_UUID);
case BT_PROFILE_CONN_HFG:
return strdup(HFP_AG_UUID);
+ case BT_PROFILE_CONN_PBAP:
+ return strdup(PBAP_UUID);
case BT_PROFILE_CONN_GATT:
case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
default:
return "ALREADY_DEACTIVATED";
case BLUETOOTH_ERROR_NOT_INITIALIZED:
return "NOT_INITIALIZED";
+ case BLUETOOTH_ERROR_AUTHENTICATION_REJECTED:
+ return "AUTHENTICATION REJECTED";
default:
return "UNKNOWN";
}
char * _bt_convert_disc_reason_to_string(int reason)
{
- switch(reason) {
- case 1:
+ switch (reason) {
+ case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
+ return "Page timeout";
+ case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
return "Link loss";
- case 2:
+ case (int)BLUETOOTH_ERROR_PIN_OR_KEY_MISSING:
+ return "PIN or Key missing";
+ case (int)BLUETOOTH_ERROR_LOCAL_HOST_TERM:
return "Connection terminated by local host";
- case 3:
+ case (int)BLUETOOTH_ERROR_REMOTE_USER_TERM:
+ case (int)BLUETOOTH_ERROR_REMOTE_LOW_RESOURCES:
+ case (int)BLUETOOTH_ERROR_REMOTE_POWER_OFF:
return "Remote user terminated connection";
- case 0:
+ case (int)BLUETOOTH_ERROR_AUTH_FAILURE:
+ return "Authentication Failure";
+ case (int)BLUETOOTH_ERROR_REPEATED_ATTEMPTS:
+ return "Repeated attempts";
+ case (int)BLUETOOTH_ERROR_LMP_RESPONSE_TIMEOUT:
+ return "LMP response timeout";
+ case (int)BLUETOOTH_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED:
+ return "Connection failed to be established";
default:
return "Unknown";
}
le_conn, le_disc, edr_conn, edr_disc);
}
-int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
-{
- int ret;
- bundle *b = NULL;
-
- b = bundle_create();
-
- bundle_add_str(b, key, value);
-
- ret = eventsystem_send_system_event(event, b);
-
- BT_DBG("eventsystem_send_system_event result: %d", ret);
-
- bundle_free(b);
-
- return ret;
-}
-
void _bt_swap_byte_ordering(char *data, int data_len)
{
char temp;
int i, j;
+ int half = data_len / 2;
ret_if(data == NULL);
/* Swap to opposite endian */
- for (i = 0, j = data_len - 1; i < data_len; i++, j--) {
+ for (i = 0, j = data_len - 1; i < half; i++, j--) {
temp = data[i];
data[i] = data[j];
data[j] = temp;
- }
+ }
}
int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
}
return 0;
}
+
+int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
+{
+ int ret = ES_R_OK;
+/* Send event system event in bt-core process because bt-service's permission is not system in now */
+\r#if 0
+ bundle *b = NULL;
+
+ b = bundle_create();
+
+ bundle_add_str(b, key, value);
+
+ ret = eventsystem_send_system_event(event, b);
+
+ BT_DBG("eventsystem_send_system_event result: %d", ret);
+
+ bundle_free(b);
+#endif
+ return ret;
+}
+
+void __bt_get_auth_info(GVariant *reply, char *auth_info)
+{
+ int cursor;
+ GVariant *tmp_value;
+ char *manufacturer_data = NULL;
+ int manufacturer_data_len;
+ gboolean is_alias_set;
+ GVariantIter *value_iter;
+ guint8 m_value;
+ int i = 0;
+
+ tmp_value = g_variant_lookup_value(reply, "IsAliasSet",
+ G_VARIANT_TYPE_BOOLEAN);
+ if (tmp_value) {
+ is_alias_set = g_variant_get_boolean(tmp_value);
+ g_variant_unref(tmp_value);
+ } else {
+ is_alias_set = FALSE;
+ }
+ if (is_alias_set == FALSE) {
+ tmp_value = g_variant_lookup_value(reply, "ManufacturerDataLen",
+ G_VARIANT_TYPE_UINT16);
+ if (tmp_value) {
+ manufacturer_data_len = g_variant_get_uint16(tmp_value);
+ if (manufacturer_data_len >
+ BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
+ BT_ERR("manufacturer_data_len is too long");
+ manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
+ }
+ g_variant_unref(tmp_value);
+ } else
+ manufacturer_data_len = 0;
+
+ tmp_value = g_variant_lookup_value(reply, "ManufacturerData",
+ G_VARIANT_TYPE_ARRAY);
+ if (tmp_value) {
+ if ((manufacturer_data_len == 0) ||
+ manufacturer_data_len != g_variant_get_size(tmp_value)) {
+ BT_ERR("manufacturer data length doesn't match");
+ manufacturer_data_len = 0;
+ manufacturer_data = NULL;
+ } else {
+ manufacturer_data = g_malloc0(manufacturer_data_len);
+ g_variant_get(tmp_value, "ay", &value_iter);
+ while (g_variant_iter_loop(value_iter, "y", &m_value))
+ manufacturer_data[i++] = m_value;
+ }
+ g_variant_unref(tmp_value);
+ } else {
+ BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
+ manufacturer_data_len = 0;
+ manufacturer_data = NULL;
+ }
+ /*minimum Size of the samsung specific manufacturer data is greater than 30 */
+ if (manufacturer_data_len < 30) {
+ g_free(manufacturer_data);
+ return;
+ }
+ if (manufacturer_data[0] != 0x00 || manufacturer_data[1] != 0x75) {
+ BT_DBG("This is not a samsung specific manufaturer data");
+ g_free(manufacturer_data);
+ return;
+ }
+
+ /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
+ 1 (discovery version) + 1 (associated service ID)
+ 2 (Proxamity and locality) + 2 (Device type and icon) */
+
+ cursor = 10;
+
+ memcpy(auth_info, &(manufacturer_data[cursor]), 5);
+ }
+ g_free(manufacturer_data);
+}
+
+int _bt_convert_gerror(GError *g_error)
+{
+ int ret = BLUETOOTH_ERROR_INTERNAL;
+ gchar *str;
+
+ if (!g_dbus_error_strip_remote_error(g_error))
+ return ret;
+
+ str = g_error->message;
+
+ if (g_strcmp0(str, "Connection refused") == 0)
+ ret = BLUETOOTH_ERROR_AUTHENTICATION_REJECTED;
+ else if (g_strcmp0(str, "Connection timed out") == 0)
+ ret = BLUETOOTH_ERROR_TIMEOUT;
+ else if (g_strcmp0(str, "In Progress") == 0)
+ ret = BLUETOOTH_ERROR_IN_PROGRESS;
+
+ return ret;
+}