/*
- * 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.
#include <stdio.h>
#include <string.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus-glib.h>
+#include <glib.h>
+#include <dlog.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <termios.h>
+#include <net_connection.h>
#include <dbus/dbus.h>
#include <glib.h>
#include <dlog.h>
#include <errno.h>
#include <termios.h>
#include <net_connection.h>
+#include <bundle.h>
+#include <eventsystem.h>
#include "bluetooth-api.h"
#include "bt-service-common.h"
#include "bt-service-agent.h"
-static DBusGConnection *system_conn;
-static DBusGConnection *session_conn;
-static DBusGProxy *manager_proxy;
-static DBusGProxy *adapter_proxy;
+static GDBusConnection *system_conn;
+static GDBusConnection *session_conn;
+static GDBusProxy *manager_proxy;
+static GDBusProxy *adapter_proxy;
static void *net_conn;
-static DBusGProxy *adapter_properties_proxy;
+static GDBusProxy *adapter_properties_proxy;
-static DBusGProxy *__bt_init_manager_proxy(void)
+GDBusConnection *_bt_gdbus_init_system_gconn(void)
{
- DBusGProxy *proxy;
+ GError *error = NULL;
+
+ dbus_threads_init_default();
+
+ if (system_conn != NULL)
+ return system_conn;
- g_type_init();
+ system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+
+ if (!system_conn) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+
+ return system_conn;
+}
+
+GDBusConnection *_bt_gdbus_get_system_gconn(void)
+{
+ GDBusConnection *local_system_gconn = NULL;
+ GError *error = NULL;
if (system_conn == NULL) {
- system_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(system_conn == NULL, 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) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+
+ system_conn = local_system_gconn;
}
- proxy = dbus_g_proxy_new_for_name(system_conn, BT_BLUEZ_NAME,
- BT_MANAGER_PATH, BT_MANAGER_INTERFACE);
+ return system_conn;
+}
- retv_if(proxy == NULL, NULL);
+GDBusConnection *_bt_gdbus_init_session_gconn(void)
+{
+ GError *error = NULL;
- manager_proxy = proxy;
+ dbus_threads_init_default();
- return proxy;
+ 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;
}
-static DBusGProxy *__bt_init_adapter_proxy(void)
+GDBusConnection *_bt_gdbus_get_session_gconn(void)
{
- DBusGProxy *manager_proxy;
- DBusGProxy *proxy;
+ GDBusConnection *local_session_gconn = NULL;
+ GError *error = NULL;
- if (system_conn == NULL) {
- system_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- retv_if(system_conn == NULL, 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;
}
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, NULL);
+ return session_conn;
+}
- proxy = dbus_g_proxy_new_for_name(system_conn, BT_BLUEZ_NAME,
- BT_BLUEZ_HCI_PATH, BT_ADAPTER_INTERFACE);
+static GDBusProxy *__bt_init_manager_proxy(void)
+{
+ GDBusConnection *g_conn;
+ GDBusProxy *proxy;
- retv_if(proxy == NULL, NULL);
+ dbus_threads_init_default();
- adapter_proxy = 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_BLUEZ_NAME,
+ BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
+
+ if (!proxy) {
+ BT_ERR("Unable to get proxy");
+ return NULL;
+ }
+
+ manager_proxy = proxy;
return proxy;
}
-static DBusGProxy *__bt_init_adapter_properties_proxy(void)
+static GDBusProxy *__bt_init_adapter_proxy(void)
{
- DBusGProxy *manager_proxy;
- DBusGProxy *proxy;
+ 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 = dbus_g_bus_get(DBUS_BUS_SYSTEM, 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);
- proxy = dbus_g_proxy_new_for_name(system_conn, BT_BLUEZ_NAME,
- BT_BLUEZ_HCI_PATH, BT_PROPERTIES_INTERFACE);
+ adapter_path = _bt_get_adapter_path();
+ retv_if(adapter_path == NULL, NULL);
+
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
+
+ g_free(adapter_path);
retv_if(proxy == NULL, NULL);
- adapter_properties_proxy = proxy;
+ adapter_proxy = proxy;
return proxy;
}
-DBusGConnection *__bt_init_system_gconn(void)
+static GDBusProxy *__bt_init_adapter_properties_proxy(void)
{
- g_type_init();
-
- if (system_conn == NULL)
- system_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
+ GDBusConnection *g_conn;
+ GDBusProxy *manager_proxy;
+ GDBusProxy *proxy;
+ char *adapter_path = NULL;
- return system_conn;
-}
+ dbus_threads_init_default();
-DBusGConnection *__bt_init_session_conn(void)
-{
- if (session_conn == NULL)
- session_conn = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+ g_conn = _bt_gdbus_get_system_gconn();
+ retv_if(g_conn == NULL, NULL);
- return session_conn;
-}
+ manager_proxy = _bt_get_manager_proxy();
+ retv_if(manager_proxy == NULL, NULL);
-DBusGConnection *_bt_get_session_gconn(void)
-{
- return (session_conn) ? session_conn : __bt_init_session_conn();
-}
+ adapter_path = _bt_get_adapter_path();
+ retv_if(adapter_path == NULL, NULL);
-DBusGConnection *_bt_get_system_gconn(void)
-{
- return (system_conn) ? system_conn : __bt_init_system_gconn();
-}
+ proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-DBusConnection *_bt_get_system_conn(void)
-{
- DBusGConnection *g_conn;
+ g_free(adapter_path);
- if (system_conn == NULL) {
- g_conn = __bt_init_system_gconn();
- } else {
- g_conn = system_conn;
- }
+ retv_if(proxy == NULL, NULL);
- retv_if(g_conn == NULL, NULL);
+ adapter_properties_proxy = proxy;
- return dbus_g_connection_get_connection(g_conn);
+ return proxy;
}
-DBusGProxy *_bt_get_manager_proxy(void)
+GDBusProxy *_bt_get_manager_proxy(void)
{
if (manager_proxy) {
- const char *path = dbus_g_proxy_get_path(manager_proxy);
+ const gchar *path = g_dbus_proxy_get_object_path(manager_proxy);
if (path == NULL) {
BT_ERR("Already proxy released hence creating new proxy");
return __bt_init_manager_proxy();
return (net_conn) ? net_conn : __bt_init_net_conn();
}
-gboolean _bt_get_adapter_power(void)
-{
- DBusGProxy *proxy = NULL;
- gboolean powered;
- GValue powered_v = { 0 };
- GError *err = NULL;
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, FALSE);
-
- if (!dbus_g_proxy_call(proxy, "Get", &err,
- G_TYPE_STRING, BT_ADAPTER_INTERFACE,
- G_TYPE_STRING, "Powered",
- G_TYPE_INVALID,
- G_TYPE_VALUE, &powered_v,
- G_TYPE_INVALID)) {
- if (err != NULL) {
- BT_ERR("Getting property failed: [%s]\n", err->message);
- g_error_free(err);
- }
- return FALSE;
- }
-
- powered = (gboolean)g_value_get_boolean(&powered_v);
-
- BT_DBG("powered = %d", powered);
-
- return powered;
-}
-
-DBusGProxy *_bt_get_adapter_proxy(void)
+GDBusProxy *_bt_get_adapter_proxy(void)
{
if (adapter_proxy) {
- const char *path = dbus_g_proxy_get_path(adapter_proxy);
+ const char *path = g_dbus_proxy_get_object_path(adapter_proxy);
if (path == NULL) {
BT_ERR("Already proxy released hence creating new proxy");
return __bt_init_adapter_proxy();
}
-DBusGProxy *_bt_get_adapter_properties_proxy(void)
+GDBusProxy *_bt_get_adapter_properties_proxy(void)
{
return (adapter_properties_proxy) ? adapter_properties_proxy :
__bt_init_adapter_properties_proxy();
}
-static char *__bt_extract_adapter_path(DBusMessageIter *msg_iter)
+static char *__bt_extract_adapter_path(GVariantIter *iter)
{
char *object_path = NULL;
- DBusMessageIter value_iter;
-
- /* Parse the signature: oa{sa{sv}}} */
- retv_if(dbus_message_iter_get_arg_type(msg_iter) !=
- DBUS_TYPE_OBJECT_PATH, NULL);
+ GVariantIter *interface_iter;
+ GVariantIter *svc_iter;
+ char *interface_str = NULL;
- dbus_message_iter_get_basic(msg_iter, &object_path);
- retv_if(object_path == NULL, NULL);
+ /* Parse the signature: oa{sa{sv}}} */
+ while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
+ &interface_iter)) {
- /* object array (oa) */
- retv_if(dbus_message_iter_next(msg_iter) == FALSE, NULL);
- retv_if(dbus_message_iter_get_arg_type(msg_iter) !=
- DBUS_TYPE_ARRAY, NULL);
+ if (object_path == NULL)
+ continue;
- dbus_message_iter_recurse(msg_iter, &value_iter);
+ while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
+ &interface_str, &svc_iter)) {
+ if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
+ continue;
- /* string array (sa) */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- char *interface_name = NULL;
- DBusMessageIter interface_iter;
-
- dbus_message_iter_recurse(&value_iter, &interface_iter);
-
- retv_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_STRING, NULL);
-
- dbus_message_iter_get_basic(&interface_iter, &interface_name);
-
- if (g_strcmp0(interface_name, "org.bluez.Adapter1") == 0) {
- /* Tizen don't allow the multi-adapter */
- BT_DBG("Found an adapter: %s", object_path);
+ BT_DBG("Object Path: %s", object_path);
+ g_variant_iter_free(svc_iter);
+ g_variant_iter_free(interface_iter);
return g_strdup(object_path);
}
-
- dbus_message_iter_next(&value_iter);
}
-
- BT_DBG("There is no adapter");
-
return NULL;
}
char *_bt_get_adapter_path(void)
{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusMessageIter reply_iter;
- DBusMessageIter value_iter;
- DBusError err;
- DBusConnection *conn;
+ GDBusConnection *conn;
+ GDBusProxy *manager_proxy;
+ GVariant *result = NULL;
+ GVariantIter *iter = NULL;
char *adapter_path = NULL;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
- msg = dbus_message_new_method_call(BT_BLUEZ_NAME, BT_MANAGER_PATH,
- BT_MANAGER_INTERFACE,
- "GetManagedObjects");
-
- retv_if(msg == NULL, NULL);
-
- /* Synchronous call */
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(
- conn, msg,
- -1, &err);
- dbus_message_unref(msg);
+ manager_proxy = _bt_get_manager_proxy();
+ retv_if(manager_proxy == NULL, NULL);
- if (!reply) {
+ result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+ if (!result) {
BT_ERR("Can't get managed objects");
-
- if (dbus_error_is_set(&err)) {
- BT_ERR("%s", err.message);
- dbus_error_free(&err);
- }
- return NULL;
- }
-
- if (dbus_message_iter_init(reply, &reply_iter) == FALSE) {
- BT_ERR("Fail to iterate the reply");
- dbus_message_unref(reply);
return NULL;
}
- dbus_message_iter_recurse(&reply_iter, &value_iter);
-
/* signature of GetManagedObjects: a{oa{sa{sv}}} */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter msg_iter;
-
- dbus_message_iter_recurse(&value_iter, &msg_iter);
-
- adapter_path = __bt_extract_adapter_path(&msg_iter);
- if (adapter_path != NULL) {
- BT_DBG("Found the adapter path");
- break;
- }
-
- dbus_message_iter_next(&value_iter);
- }
- dbus_message_unref(reply);
+ g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
+ adapter_path = __bt_extract_adapter_path(iter);
+ g_variant_iter_free(iter);
+ g_variant_unref(result);
return adapter_path;
}
_bt_deinit_bluez_proxy();
if (system_conn) {
- dbus_g_connection_unref(system_conn);
+ g_object_unref(system_conn);
system_conn = NULL;
}
if (session_conn) {
- dbus_g_connection_unref(session_conn);
+ g_object_unref(session_conn);
session_conn = NULL;
}
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);
+
+ strncpy(addr, address, len);
- address = ptr + 1;
- }
- }
+ addr[len-1] = 'X';
+ addr[len-2] = 'X';
+
+ return;
}
void _bt_convert_addr_type_to_string(char *address,
g_free(dev_info->manufacturer_data);
if (dev_info->uuids) {
- for (i = 0; dev_info->uuids[i] != NULL; i++)
+ for (i = 0; i < dev_info->uuid_count && dev_info->uuids[i]; i++)
g_free(dev_info->uuids[i]);
g_free(dev_info->uuids);
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)
{
- if (!_bt_agent_register_osp_server( type, uuid, path, fd))
+ BT_DBG("+");
+ 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)
{
- if (!_bt_agent_unregister_osp_server( type, uuid))
+ BT_DBG("+");
+ 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;
return BLUETOOTH_ERROR_NONE;
}
-static char *__bt_extract_device_path(DBusMessageIter *msg_iter, char *address)
+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}}} */
- retv_if(dbus_message_iter_get_arg_type(msg_iter) !=
- DBUS_TYPE_OBJECT_PATH, NULL);
-
- dbus_message_iter_get_basic(msg_iter, &object_path);
- retv_if(object_path == NULL, NULL);
-
- _bt_convert_device_path_to_address(object_path, device_address);
+ /* 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);
- 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)
{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusMessageIter reply_iter;
- DBusMessageIter value_iter;
- DBusError err;
- DBusConnection *conn;
char *object_path = NULL;
+ GDBusConnection *conn;
+ GDBusProxy *manager_proxy;
+ GVariant *result = NULL;
+ GVariantIter *iter = NULL;
- conn = _bt_get_system_conn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, NULL);
- msg = dbus_message_new_method_call(BT_BLUEZ_NAME, BT_MANAGER_PATH,
- BT_MANAGER_INTERFACE,
- "GetManagedObjects");
-
- retv_if(msg == NULL, NULL);
-
- /* Synchronous call */
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(
- conn, msg,
- -1, &err);
- dbus_message_unref(msg);
+ manager_proxy = _bt_get_manager_proxy();
+ retv_if(manager_proxy == NULL, NULL);
- if (!reply) {
+ result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+ if (!result) {
BT_ERR("Can't get managed objects");
-
- if (dbus_error_is_set(&err)) {
- BT_ERR("%s", err.message);
- dbus_error_free(&err);
- }
- return NULL;
- }
-
- if (dbus_message_iter_init(reply, &reply_iter) == FALSE) {
- BT_ERR("Fail to iterate the reply");
- dbus_message_unref(reply);
return NULL;
}
- dbus_message_iter_recurse(&reply_iter, &value_iter);
-
/* signature of GetManagedObjects: a{oa{sa{sv}}} */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter msg_iter;
-
- dbus_message_iter_recurse(&value_iter, &msg_iter);
-
- object_path = __bt_extract_device_path(&msg_iter, address);
- if (object_path != NULL) {
- BT_DBG("Found the device path");
- break;
- }
-
- dbus_message_iter_next(&value_iter);
- }
- dbus_message_unref(reply);
-
+ 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;
}
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(A2DP_SINK_UUID);
+ case BT_PROFILE_CONN_A2DP_SINK:
+ return strdup(A2DP_SOURCE_UUID);
case BT_PROFILE_CONN_HSP:
return strdup(HFP_HS_UUID);
case BT_PROFILE_CONN_HID:
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);
}
+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 < 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)
+{
+ int i;
+
+ retv_if(data1 == NULL, -1);
+ retv_if(data2 == NULL, -1);
+ for (i = 0; i < data_len; i++) {
+ if (data1[i] != data2[i])
+ return data1[i] - data2[i];
+ }
+ return 0;
+}
+int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
+ const char *mask, int data_len)
+{
+ int i;
+ char a, b;
+
+ retv_if(data1 == NULL, -1);
+ retv_if(data2 == NULL, -1);
+ retv_if(mask == NULL, -1);
+ for (i = 0; i < data_len; i++) {
+ a = data1[i] & mask[i];
+ b = data2[i] & mask[i];
+ if (a != b)
+ return (int)(a - b);
+ }
+ 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 */
+
+#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;
+}