/*
- * 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 <errno.h>
#include <termios.h>
#include <net_connection.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus-glib.h>
#include <dbus/dbus.h>
#include <glib.h>
#include <dlog.h>
#include <termios.h>
#include <net_connection.h>
#include <bundle.h>
-#if 0
#include <eventsystem.h>
-#endif
#include "bluetooth-api.h"
#include "bt-service-common.h"
static GDBusProxy *adapter_properties_proxy;
-static GDBusConnection *system_gconn = NULL;
-
GDBusConnection *_bt_gdbus_init_system_gconn(void)
{
GError *error = NULL;
- if (!g_thread_supported()) {
- g_thread_init(NULL);
- }
-
-// dbus_g_thread_init();
-
- g_type_init();
+ dbus_threads_init_default();
- if (system_gconn != NULL)
- return system_gconn;
+ if (system_conn != NULL)
+ return system_conn;
- system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ system_conn = 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_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 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) {
if (object_path == NULL)
continue;
- while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
+ while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
&interface_str, &svc_iter)) {
if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
continue;
BT_DBG("Object Path: %s", object_path);
- g_free(interface_str);
g_variant_iter_free(svc_iter);
g_variant_iter_free(interface_iter);
return g_strdup(object_path);
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;
+ 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;
- }
- }
+ 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);
+
+ len = strlen(address);
+ ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
+
+ strncpy(addr, address, len);
+ addr[len] = '\0';
+
+ 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;
}
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:
};
}
-char *_bt_convert_error_to_string(int error)
+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 offset = 0;
+ int uuid_len = 4;
+ typedef struct {
+ const char *uuid;
+ const char *specification_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"},
+ {"1103", "Dialup Networking Service"},
+ {"1104", "IrMCSync Service"},
+ {"1105", "OBEX Object Push Service"},
+ {"1106", "OBEX File Transfer Service"},
+ {"1107", "IrMC Sync Command Service"},
+ {"1108", "Headset Service"},
+ {"1109", "Cordless Telephony Service"},
+ {"110A", "Audio Source Service"},
+ {"110B", "Audio Sink Service"},
+ {"110C", "AV Remote Control Target Service"},
+ {"110D", "Advanced Audio Distribution Profile"},
+ {"110E", "AV Remote Control Service"},
+ {"110F", "Video Conferencing Service"},
+ {"1110", "Intercom Service"},
+ {"1111", "Fax Service"},
+ {"1112", "Headset Audio Gateway Service"},
+ {"1113", "WAP Service"},
+ {"1114", "WAP Client Service"},
+ {"1115", "PANU Service"},
+ {"1116", "NAP Service"},
+ {"1117", "GN Service"},
+ {"1118", "Direct Printing Service"},
+ {"1119", "Reference Printing Service"},
+ {"111A", "Basic Imaging Profile"},
+ {"111B", "Imaging Responder Service"},
+ {"111C", "Imaging Automatic Archive Service"},
+ {"111D", "Imaging Reference Objects Service"},
+ {"111E", "Handsfree Service"},
+ {"111F", "Handsfree Audio Gateway Service"},
+ {"1120", "Direct Printing Reference Objects Service"},
+ {"1121", "Reflected UI Service"},
+ {"1122", "Basic Printing Profile"},
+ {"1123", "Printing Status Service"},
+ {"1124", "Human Interface Device Service"},
+ {"1125", "Hardcopy Cable Replacement Profile"},
+ {"1126", "HCR Print Service"},
+ {"1127", "HCR Scan Service"},
+ {"112D", "SIM Access Service"},
+ {"112E", "Phonebook Access PCE Service"},
+ {"112F", "Phonebook Access PSE Service"},
+ {"1130", "Phonebook Access Profile"},
+ {"1132", "Message Access Server Service"},
+ {"1133", "Message Notification Server Service"},
+ {"1134", "Message Access Profile"},
+ {"1200", "PnP Information Service"},
+ {"1201", "Generic Networking Service"},
+ {"1202", "Generic File Transfer Service"},
+ {"1203", "Generic Audio Service"},
+ {"1204", "Generic Telephony Service"},
+ {"1205", "UPnP Service"},
+ {"1206", "UPnP Ip Service"},
+ {"1303", "Video Source Service"},
+ {"1304", "Video Sink Service"},
+ {"1305", "Video Distribution Profile"},
+ {"1400", "Health Device Profile"},
+ {"1401", "HDP Source Service"},
+ {"1402", "HDP Sink Service"},
+
+ /* GATT Services */
+ {"1800", "Generic Access"},
+ {"1801", "Generic Attribute"},
+ {"1802", "Immediate Alert"},
+ {"1803", "Link Loss"},
+ {"1804", "Tx Power"},
+ {"1805", "Current Time Service"},
+ {"1806", "Reference Time Update Service"},
+ {"1807", "Next DST Change Service"},
+ {"1808", "Glucose"},
+ {"1809", "Health Thermometer"},
+ {"180A", "Device Information"},
+ {"180D", "Heart Rate"},
+ {"180F", "Battery Service"},
+ {"1810", "Blood Pressure"},
+ {"1811", "Alert Notification Service"},
+ {"1812", "Human Interface Device"},
+ {"1813", "Scan Parameters"},
+ {"1814", "Running Speed and Cadence"},
+ {"1815", "Automation IO"},
+ {"1816", "Cycling Speed and Cadence"},
+ {"1818", "Cycling Power"},
+ {"1819", "Location and Navigation"},
+ {"181A", "Environmental Sensing"},
+ {"181B", "Body Composition"},
+ {"181C", "User Data"},
+ {"181D", "Weight Scale"},
+ {"181E", "Bond Management"},
+ {"181F", "Continuous Glucose Monitoring"},
+
+ /* GATT Declarations */
+ {"2800", "Primary Service Declaration"},
+ {"2801", "Secondary Service Declaration"},
+ {"2802", "Include Declaration"},
+ {"2803", "Characteristic Declaration"},
+
+ /* GATT Descriptors */
+ {"2900", "Characteristic Extended Properties"},
+ {"2901", "Characteristic User Description"},
+ {"2902", "Client Characteristic Configuration"},
+ {"2903", "Server Characteristic Configuration"},
+ {"2904", "Characteristic Format"},
+ {"2905", "Characteristic Aggregate Formate"},
+ {"2906", "Valid Range"},
+ {"2907", "External Report Reference"},
+ {"2908", "Report Reference"},
+
+ /* GATT Characteristics */
+ {"2A00", "Device Name"},
+ {"2A01", "Appearance"},
+ {"2A02", "Peripheral Privacy Flag"},
+ {"2A03", "Reconnection Address"},
+ {"2A04", "Peripheral Preferred Connection Parameters"},
+ {"2A05", "Service Changed"},
+ {"2A06", "Alert Level"},
+ {"2A07", "Tx Power Level"},
+ {"2A08", "Date Time"},
+ {"2A09", "Day of Week"},
+ {"2A0A", "Day Date Time"},
+ {"2A11", "Time with DST"},
+ {"2A12", "Time Accuracy"},
+ {"2A13", "Time Source"},
+ {"2A14", "Reference Time Information"},
+ {"2A16", "Time Update Control Point"},
+ {"2A17", "Time Update State"},
+ {"2A18", "Glucose Measurement"},
+ {"2A19", "Battery Level"},
+ {"2A1C", "Temperature Measurement"},
+ {"2A1D", "Temperature Type"},
+ {"2A1E", "Intermediate Temperature"},
+ {"2A21", "Measurement Interval"},
+ {"2A23", "System ID"},
+ {"2A24", "Model Number String"},
+ {"2A25", "Serial Number String"},
+ {"2A26", "Firmware Revision String"},
+ {"2A27", "Hardware Revision String"},
+ {"2A28", "Software Revision String"},
+ {"2A29", "Manufacturer Name String"},
+ {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"},
+ {"2A2B", "Current Time"},
+ {"2A34", "Glucose Measurement Context"},
+ {"2A35", "Blood Pressure Measurement"},
+ {"2A37", "Heart Rate Measurement"},
+ {"2A38", "Body Sensor Location"},
+ {"2A39", "Heart Rate Control Point"},
+ {"2A3F", "Alert Status"},
+ {"2A46", "New Alert"},
+ {"2A49", "Blood Pressure Feature"},
+ {"2A4A", "HID Information"},
+ {"2A4C", "HID Control Point"},
+ {"2A50", "PnP ID"},
+ {"2A51", "Glucose Feature"},
+ {"2A52", "Record Access Control Point"},
+ {"2A53", "RSC Measurement"},
+ {"2A54", "RSC Feature"},
+ {"2A55", "SC Control Point"},
+ {"2A56", "Digital"},
+ {"2A58", "Analog"},
+ {"2A5A", "Aggregate"},
+ {"2A5B", "CSC Measurement"},
+ {"2A5C", "CSC Feature"},
+ {"2A5D", "Sensor Location"},
+ {"2A63", "Cycling Power Measurement"},
+ {"2A64", "Cycling Power Vector"},
+ {"2A65", "Cycling Power Feature"},
+ {"2A66", "Cycling Power Control Point"},
+ {"2A67", "Location and Speed"},
+ {"2A68", "Navigation"},
+ {"2A6D", "Pressure"},
+ {"2A6E", "Temperature"},
+ };
+ static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
+ // List should be sorted by UUID
+ /* Custom uuids */
+ {"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"},
+ {"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"},
+ {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
+ {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
+ };
+ 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))
+ offset = 4;
+ else {
+ offset = 0;
+ uuid_len = 36;
+ end = LONG_UUID_COUNT - 1;
+ uuid_name = long_uuid_name;
+ }
+ } else if (strlen(uuid) >= 8)
+ offset = 4;
+
+ 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;
+ }
+
+ BT_INFO("Unknown uuid : %s", uuid);
+ return unknown_name;
+}
+
+const char *_bt_convert_error_to_string(int error)
{
switch (error) {
case BLUETOOTH_ERROR_CANCEL:
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)
+const 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_LMP_TRANSACTION_COLLISION:
+ return "LMP transaction collision";
+ case (int)BLUETOOTH_ERROR_INSTANT_PASSED:
+ return "Instant passed";
+ case (int)BLUETOOTH_ERROR_INSUFFICIENT_SECURITY:
+ return "Insufficient security";
+ case (int)BLUETOOTH_ERROR_CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE:
+ return "Connection terminated due to MIC failure";
+ case (int)BLUETOOTH_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED:
+ return "Connection failed to be established";
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;
+}
+
void _bt_logging_connection(gboolean connect, int addr_type)
{
static int le_conn = 0;
BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
le_conn, le_disc, edr_conn, edr_disc);
}
-#if 0
-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_request_sending_system_event(event, b);
-
- BT_DBG("request_sending_system_event result: %d", ret);
- bundle_free(b);
-
- return ret;
-}
-#endif
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 */
+
+#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, "LegacyManufacturerDataLen",
+ 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, "LegacyManufacturerData",
+ 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;
+}