#include <sys/types.h>
#include <stdlib.h>
#include <sys/socket.h>
-
+#include<stdio.h>
#include <gio/gunixfdlist.h>
#include "bt-internal-types.h"
#include "bluetooth-ipsp-api.h"
+#ifndef GATT_DIRECT
+#include "bluetooth-gatt-server-api.h"
+#endif
+
+#ifdef TIZEN_GATT_CLIENT
+#include "bluetooth-gatt-client-api.h"
+#endif
+
#include "bt-common.h"
#include "bt-request-sender.h"
#include "bt-event-handler.h"
#include "bt-dpm.h"
#endif
-
static bt_user_info_t user_info[BT_MAX_USER_INFO];
-static GDBusConnection *system_gdbus_conn = NULL;
-
+static GDBusConnection *system_shared_conn = NULL;
+static GDBusConnection *system_private_conn = NULL;
static guint bus_id;
-static GDBusConnection *system_gconn = NULL;
-
static gboolean bt_enabled = FALSE;
#define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
-GDBusConnection *g_bus_get_private_conn(void)
+static GDBusConnection *g_bus_get_private_conn(void)
{
GError *error = NULL;
char *address;
NULL, /* GDBusAuthObserver */
NULL,
&error);
+ g_free(address);
if (!private_gconn) {
if (error) {
BT_ERR("Unable to connect to dbus: %s", error->message);
return private_gconn;
}
-GDBusConnection *_bt_gdbus_init_system_gconn(void)
+GDBusConnection *_bt_get_system_private_conn(void)
{
- dbus_threads_init_default();
+ if (system_private_conn == NULL)
+ system_private_conn = g_bus_get_private_conn();
+ else if (g_dbus_connection_is_closed(system_private_conn))
+ system_private_conn = g_bus_get_private_conn();
- if (system_gconn != NULL)
- return system_gconn;
-
- system_gconn = g_bus_get_private_conn();
-
- return system_gconn;
+ return system_private_conn;
}
-GDBusConnection *_bt_gdbus_get_system_gconn(void)
+GDBusConnection *_bt_get_system_shared_conn(void)
{
- if (system_gconn == NULL)
- system_gconn = _bt_gdbus_init_system_gconn();
- else if (g_dbus_connection_is_closed(system_gconn))
- system_gconn = g_bus_get_private_conn();
-
- return system_gconn;
+ if (system_shared_conn == NULL) {
+ GError *error = NULL;
+ system_shared_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (error) {
+ BT_ERR("GDBus connection Error : %s \n", error->message);
+ g_clear_error(&error);
+ return NULL;
+ }
+ }
+ return system_shared_conn;
}
void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
user_data);
}
+#ifdef TIZEN_GATT_CLIENT
+void _bt_gatt_client_event_cb(int event, int result, void *param,
+ void *callback, void *user_data)
+{
+ BT_DBG("__bt_gatt_client_event_cb");
+ gatt_client_event_param_t bt_event = { 0, 0, NULL, NULL };
+ bt_event.event = event;
+ bt_event.result = result;
+ bt_event.param_data = param;
+ if (callback) {
+ BT_DBG("GATT Client event callback is registered");
+ ((gatt_client_cb_func_ptr)callback)(bt_event.event, &bt_event,
+ user_data);
+ } else {
+ BT_ERR("GATT Client event callback is not registered!!!");
+ }
+}
+#endif
+
+#ifndef GATT_DIRECT
+void _bt_gatt_server_event_cb(int event, int result, void *param,
+ void *callback, void *user_data)
+{
+ BT_INFO("__bt_gatt_server_event_cb");
+ gatt_server_event_param_t bt_event = { 0, 0, NULL, NULL };
+ bt_event.event = event;
+ bt_event.result = result;
+ bt_event.param_data = param;
+ if (callback) {
+ BT_INFO("GATT Server event callback is registered");
+ ((gatt_server_cb_func_ptr)callback)(bt_event.event, &bt_event,
+ user_data);
+ } else {
+ BT_ERR("GATT Server event callback is not registered!!!");
+ }
+}
+#endif
+
void _bt_divide_device_class(bluetooth_device_class_t *device_class,
unsigned int cod)
{
}
}
-void _bt_convert_addr_string_to_type(unsigned char *addr,
- const char *address)
+void _bt_convert_addr_string_to_type(unsigned char *addr, const char *address)
{
int i;
char *ptr = NULL;
}
}
-void _bt_convert_addr_string_to_secure_string(char *addr,
- const char *address)
+void _bt_convert_uuid_type_to_string(char *str, const unsigned char *uuid)
+{
+ if (!str) {
+ BT_ERR("str == NULL");
+ return;
+ }
+
+ if (!uuid) {
+ BT_ERR("uuid == NULL");
+ return;
+ }
+
+ snprintf(str, 37,
+ "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
+ uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
+ uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
+}
+
+void _bt_convert_addr_string_to_secure_string(char *addr, const char *address)
{
int len;
ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
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;
}
-void _bt_convert_addr_type_to_string(char *address,
- unsigned char *addr)
+void _bt_convert_addr_type_to_string(char *address, unsigned char *addr)
{
ret_if(address == NULL);
ret_if(addr == NULL);
addr[3], addr[4], addr[5]);
}
+void _bt_convert_addr_type_to_secure_string(char *address, unsigned char *addr)
+{
+ ret_if(address == NULL);
+ ret_if(addr == NULL);
+
+ g_snprintf(address, BT_ADDRESS_STRING_SIZE,
+ "XX:XX:XX:XX:%2.2X:%2.2X", addr[4], addr[5]);
+}
+
+const char *_bt_convert_error_to_string(int error)
+{
+ switch (error) {
+ case BLUETOOTH_ERROR_CANCEL:
+ return "CANCELLED";
+ case BLUETOOTH_ERROR_INVALID_PARAM:
+ return "INVALID_PARAMETER";
+ case BLUETOOTH_ERROR_INVALID_DATA:
+ return "INVALID DATA";
+ case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
+ case BLUETOOTH_ERROR_OUT_OF_MEMORY:
+ return "OUT_OF_MEMORY";
+ case BLUETOOTH_ERROR_TIMEOUT:
+ return "TIMEOUT";
+ case BLUETOOTH_ERROR_NO_RESOURCES:
+ return "NO_RESOURCES";
+ case BLUETOOTH_ERROR_INTERNAL:
+ return "INTERNAL";
+ case BLUETOOTH_ERROR_NOT_SUPPORT:
+ return "NOT_SUPPORT";
+ case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
+ return "NOT_ENABLED";
+ case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
+ return "ALREADY_ENABLED";
+ case BLUETOOTH_ERROR_DEVICE_BUSY:
+ return "DEVICE_BUSY";
+ case BLUETOOTH_ERROR_ACCESS_DENIED:
+ return "ACCESS_DENIED";
+ case BLUETOOTH_ERROR_MAX_CLIENT:
+ return "MAX_CLIENT";
+ case BLUETOOTH_ERROR_NOT_FOUND:
+ return "NOT_FOUND";
+ case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
+ return "SERVICE_SEARCH_ERROR";
+ case BLUETOOTH_ERROR_PARING_FAILED:
+ return "PARING_FAILED";
+ case BLUETOOTH_ERROR_NOT_PAIRED:
+ return "NOT_PAIRED";
+ case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
+ return "SERVICE_NOT_FOUND";
+ case BLUETOOTH_ERROR_NOT_CONNECTED:
+ return "NOT_CONNECTED";
+ case BLUETOOTH_ERROR_ALREADY_CONNECT:
+ return "ALREADY_CONNECT";
+ case BLUETOOTH_ERROR_CONNECTION_BUSY:
+ return "CONNECTION_BUSY";
+ case BLUETOOTH_ERROR_CONNECTION_ERROR:
+ return "CONNECTION_ERROR";
+ case BLUETOOTH_ERROR_MAX_CONNECTION:
+ return "MAX_CONNECTION";
+ case BLUETOOTH_ERROR_NOT_IN_OPERATION:
+ return "NOT_IN_OPERATION";
+ case BLUETOOTH_ERROR_CANCEL_BY_USER:
+ return "CANCEL_BY_USER";
+ case BLUETOOTH_ERROR_REGISTRATION_FAILED:
+ return "REGISTRATION_FAILED";
+ case BLUETOOTH_ERROR_IN_PROGRESS:
+ return "IN_PROGRESS";
+ case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
+ return "AUTHENTICATION_FAILED";
+ case BLUETOOTH_ERROR_HOST_DOWN:
+ return "HOST_DOWN";
+ case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
+ return "END_OF_DEVICE_LIST";
+ case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
+ return "AGENT_ALREADY_EXIST";
+ case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
+ return "AGENT_DOES_NOT_EXIST";
+ case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
+ return "ALREADY_INITIALIZED";
+ case BLUETOOTH_ERROR_PERMISSION_DEINED:
+ return "PERMISSION_DEINED";
+ case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
+ return "ALREADY_DEACTIVATED";
+ case BLUETOOTH_ERROR_NOT_INITIALIZED:
+ 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_service_function_to_string(int function)
+{
+ int i;
+
+ typedef struct {
+ int function;
+ const char *function_name;
+ } bt_function_name_t;
+
+ const bt_function_name_t bt_functions[] = {
+ {BT_CHECK_ADAPTER, "BT_CHECK_ADAPTER"},
+ {BT_ENABLE_ADAPTER, "BT_ENABLE_ADAPTER"},
+ {BT_DISABLE_ADAPTER, "BT_DISABLE_ADAPTER"},
+ {BT_RECOVER_ADAPTER, "BT_RECOVER_ADAPTER"},
+ {BT_SET_DISCOVERABLE_TIME, "BT_SET_DISCOVERABLE_TIME"},
+ {BT_GET_DISCOVERABLE_TIME, "BT_GET_DISCOVERABLE_TIME"},
+ {BT_IGNORE_AUTO_PAIRING, "BT_IGNORE_AUTO_PAIRING"},
+ {BT_GET_LOCAL_ADDRESS, "BT_GET_LOCAL_ADDRESS"},
+ {BT_GET_LOCAL_VERSION, "BT_GET_LOCAL_VERSION"},
+ {BT_GET_LOCAL_NAME, "BT_GET_LOCAL_NAME"},
+ {BT_SET_LOCAL_NAME, "BT_SET_LOCAL_NAME"},
+ {BT_IS_SERVICE_USED, "BT_IS_SERVICE_USED"},
+ {BT_GET_DISCOVERABLE_MODE, "BT_GET_DISCOVERABLE_MODE"},
+ {BT_SET_DISCOVERABLE_MODE, "BT_SET_DISCOVERABLE_MODE"},
+ {BT_START_DISCOVERY, "BT_START_DISCOVERY"},
+ {BT_START_CUSTOM_DISCOVERY, "BT_START_CUSTOM_DISCOVERY"},
+ {BT_CANCEL_DISCOVERY, "BT_CANCEL_DISCOVERY"},
+ {BT_START_LE_DISCOVERY, "BT_START_LE_DISCOVERY"},
+ {BT_STOP_LE_DISCOVERY, "BT_STOP_LE_DISCOVERY"},
+ {BT_IS_DISCOVERYING, "BT_IS_DISCOVERYING"},
+ {BT_IS_LE_DISCOVERYING, "BT_IS_LE_DISCOVERYING"},
+ {BT_ENABLE_RSSI, "BT_ENABLE_RSSI"},
+ {BT_GET_RSSI, "BT_GET_RSSI"},
+ {BT_IS_CONNECTABLE, "BT_IS_CONNECTABLE"},
+ {BT_SET_CONNECTABLE, "BT_SET_CONNECTABLE"},
+ {BT_GET_BONDED_DEVICES, "BT_GET_BONDED_DEVICES"},
+ {BT_RESET_ADAPTER, "BT_RESET_ADAPTER"},
+ {BT_SET_ADVERTISING, "BT_SET_ADVERTISING"},
+ {BT_SET_CUSTOM_ADVERTISING, "BT_SET_CUSTOM_ADVERTISING"},
+ {BT_SET_ADVERTISING_PARAMETERS, "BT_SET_ADVERTISING_PARAMETERS"},
+ {BT_GET_ADVERTISING_DATA, "BT_GET_ADVERTISING_DATA"},
+ {BT_SET_ADVERTISING_DATA, "BT_SET_ADVERTISING_DATA"},
+ {BT_SET_SCAN_PARAMETERS, "BT_SET_SCAN_PARAMETERS"},
+ {BT_GET_SCAN_RESPONSE_DATA, "BT_GET_SCAN_RESPONSE_DATA"},
+ {BT_SET_SCAN_RESPONSE_DATA, "BT_SET_SCAN_RESPONSE_DATA"},
+ {BT_IS_ADVERTISING, "BT_IS_ADVERTISING"},
+ {BT_SET_MANUFACTURER_DATA, "BT_SET_MANUFACTURER_DATA"},
+ {BT_LE_CONN_UPDATE, "BT_LE_CONN_UPDATE"},
+ {BT_LE_READ_MAXIMUM_DATA_LENGTH, "BT_LE_READ_MAXIMUM_DATA_LENGTH"},
+ {BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH, "BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH"},
+ {BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH, "BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH"},
+ {BT_LE_SET_DATA_LENGTH, "BT_LE_SET_DATA_LENGTH"},
+ {BT_ADD_WHITE_LIST, "BT_ADD_WHITE_LIST"},
+ {BT_REMOVE_WHITE_LIST, "BT_REMOVE_WHITE_LIST"},
+ {BT_CLEAR_WHITE_LIST, "BT_CLEAR_WHITE_LIST"},
+ {BT_REGISTER_SCAN_FILTER, "BT_REGISTER_SCAN_FILTER"},
+ {BT_UNREGISTER_SCAN_FILTER, "BT_UNREGISTER_SCAN_FILTER"},
+ {BT_UNREGISTER_ALL_SCAN_FILTERS, "BT_UNREGISTER_ALL_SCAN_FILTERS"},
+ {BT_IS_SCAN_FILTER_SUPPORTED, "BT_IS_SCAN_FILTER_SUPPORTED"},
+ {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_BOND_DEVICE, "BT_BOND_DEVICE"},
+ {BT_BOND_DEVICE_BY_TYPE, "BT_BOND_DEVICE_BY_TYPE"},
+ {BT_CANCEL_BONDING, "BT_CANCEL_BONDING"},
+ {BT_PASSKEY_REPLY, "BT_PASSKEY_REPLY"},
+ {BT_PASSKEY_CONFIRMATION_REPLY, "BT_PASSKEY_CONFIRMATION_REPLY"},
+ {BT_UNBOND_DEVICE, "BT_UNBOND_DEVICE"},
+ {BT_SEARCH_SERVICE, "BT_SEARCH_SERVICE"},
+ {BT_CANCEL_SEARCH_SERVICE, "BT_CANCEL_SEARCH_SERVICE"},
+ {BT_GET_BONDED_DEVICE, "BT_GET_BONDED_DEVICE"},
+ {BT_GET_IS_ALIAS_SET, "BT_GET_IS_ALIAS_SET"},
+ {BT_SET_ALIAS, "BT_SET_ALIAS"},
+ {BT_SET_AUTHORIZATION, "BT_SET_AUTHORIZATION"},
+ {BT_UNSET_AUTHORIZATION, "BT_UNSET_AUTHORIZATION"},
+ {BT_IS_DEVICE_CONNECTED, "BT_IS_DEVICE_CONNECTED"},
+ {BT_GET_CONNECTED_LINK_TYPE, "BT_GET_CONNECTED_LINK_TYPE"},
+ {BT_SET_PIN_CODE, "BT_SET_PIN_CODE"},
+ {BT_UNSET_PIN_CODE, "BT_UNSET_PIN_CODE"},
+ {BT_UPDATE_LE_CONNECTION_MODE, "BT_UPDATE_LE_CONNECTION_MODE"},
+ {BT_SET_PROFILE_TRUSTED, "BT_SET_PROFILE_TRUSTED"},
+ {BT_GET_PROFILE_TRUSTED, "BT_GET_PROFILE_TRUSTED"},
+ {BT_DISCONNECT_DEVICE, "BT_DISCONNECT_DEVICE"},
+ {BT_HID_CONNECT, "BT_HID_CONNECT"},
+ {BT_HID_DISCONNECT, "BT_HID_DISCONNECT"},
+ {BT_HID_DEVICE_ACTIVATE, "BT_HID_DEVICE_ACTIVATE"},
+ {BT_HID_DEVICE_DEACTIVATE, "BT_HID_DEVICE_DEACTIVATE"},
+ {BT_HID_DEVICE_CONNECT, "BT_HID_DEVICE_CONNECT"},
+ {BT_HID_DEVICE_DISCONNECT, "BT_HID_DEVICE_DISCONNECT"},
+ {BT_HID_DEVICE_SEND_MOUSE_EVENT, "BT_HID_DEVICE_SEND_MOUSE_EVENT"},
+ {BT_HID_DEVICE_SEND_KEY_EVENT, "BT_HID_DEVICE_SEND_KEY_EVENT"},
+ {BT_HID_DEVICE_SEND_CUSTOM_EVENT, "BT_HID_DEVICE_SEND_CUSTOM_EVENT"},
+ {BT_HID_DEVICE_SEND_REPLY_TO_REPORT, "BT_HID_DEVICE_SEND_REPLY_TO_REPORT"},
+ {BT_HID_ENABLE_BARCODE_FEATURE, "BT_HID_ENABLE_BARCODE_FEATURE"},
+ {BT_NETWORK_ACTIVATE, "BT_NETWORK_ACTIVATE"},
+ {BT_NETWORK_DEACTIVATE, "BT_NETWORK_DEACTIVATE"},
+ {BT_NETWORK_CONNECT, "BT_NETWORK_CONNECT"},
+ {BT_NETWORK_DISCONNECT, "BT_NETWORK_DISCONNECT"},
+ {BT_NETWORK_SERVER_DISCONNECT, "BT_NETWORK_SERVER_DISCONNECT"},
+ {BT_AUDIO_CONNECT, "BT_AUDIO_CONNECT"},
+ {BT_AUDIO_DISCONNECT, "BT_AUDIO_DISCONNECT"},
+ {BT_AG_CONNECT, "BT_AG_CONNECT"},
+ {BT_AG_DISCONNECT, "BT_AG_DISCONNECT"},
+ {BT_AV_CONNECT, "BT_AV_CONNECT"},
+ {BT_AV_DISCONNECT, "BT_AV_DISCONNECT"},
+ {BT_AV_SOURCE_CONNECT, "BT_AV_SOURCE_CONNECT"},
+ {BT_AV_SOURCE_DISCONNECT, "BT_AV_SOURCE_DISCONNECT"},
+ {BT_HF_CONNECT, "BT_HF_CONNECT"},
+ {BT_HF_DISCONNECT, "BT_HF_DISCONNECT"},
+ {BT_GET_SPEAKER_GAIN, "BT_GET_SPEAKER_GAIN"},
+ {BT_SET_SPEAKER_GAIN, "BT_SET_SPEAKER_GAIN"},
+ {BT_SET_CONTENT_PROTECT, "BT_SET_CONTENT_PROTECT"},
+ {BT_AUDIO_SELECT_ROLE, "BT_AUDIO_SELECT_ROLE"},
+ {BT_OOB_READ_LOCAL_DATA, "BT_OOB_READ_LOCAL_DATA"},
+ {BT_OOB_ADD_REMOTE_DATA, "BT_OOB_ADD_REMOTE_DATA"},
+ {BT_OOB_REMOVE_REMOTE_DATA, "BT_OOB_REMOVE_REMOTE_DATA"},
+ {BT_AVRCP_SET_TRACK_INFO, "BT_AVRCP_SET_TRACK_INFO"},
+ {BT_AVRCP_SET_PROPERTY, "BT_AVRCP_SET_PROPERTY"},
+ {BT_AVRCP_SET_PROPERTIES, "BT_AVRCP_SET_PROPERTIES"},
+ {BT_AVRCP_CONTROL_CONNECT, "BT_AVRCP_CONTROL_CONNECT"},
+ {BT_AVRCP_CONTROL_DISCONNECT, "BT_AVRCP_CONTROL_DISCONNECT"},
+ {BT_AVRCP_TARGET_CONNECT, "BT_AVRCP_TARGET_CONNECT"},
+ {BT_AVRCP_TARGET_DISCONNECT, "BT_AVRCP_TARGET_DISCONNECT"},
+ {BT_AVRCP_HANDLE_CONTROL, "BT_AVRCP_HANDLE_CONTROL"},
+ {BT_AVRCP_HANDLE_CONTROL_TO_DEST, "BT_AVRCP_HANDLE_CONTROL_TO_DEST"},
+ {BT_AVRCP_CONTROL_SET_PROPERTY, "BT_AVRCP_CONTROL_SET_PROPERTY"},
+ {BT_AVRCP_CONTROL_GET_PROPERTY, "BT_AVRCP_CONTROL_GET_PROPERTY"},
+ {BT_AVRCP_GET_TRACK_INFO, "BT_AVRCP_GET_TRACK_INFO"},
+ {BT_OPP_PUSH_FILES, "BT_OPP_PUSH_FILES"},
+ {BT_OPP_CANCEL_PUSH, "BT_OBT_OPP_IS_PUSHING_FILESPP_CANCEL_PUSH"},
+ {BT_OPP_IS_PUSHING_FILES, "BT_OPP_IS_PUSHING_FILES"},
+ {BT_OPP_GET_TRANSFER_PROGRESS, "BT_OPP_GET_TRANSFER_PROGRESS"},
+ {BT_MAP_CREATE_SESSION, "BT_MAP_CREATE_SESSION"},
+ {BT_MAP_DESTROY_SESSION, "BT_MAP_DESTROY_SESSION"},
+ {BT_MAP_SET_FOLDER, "BT_MAP_SET_FOLDER"},
+ {BT_MAP_LIST_FOLDERS, "BT_MAP_LIST_FOLDERS"},
+ {BT_MAP_LIST_FILTER_FIELDS, "BT_MAP_LIST_FILTER_FIELDS"},
+ {BT_MAP_LIST_MESSAGES, "BT_MAP_LIST_MESSAGES"},
+ {BT_MAP_UPDATE_INBOX, "BT_MAP_UPDATE_INBOX"},
+ {BT_MAP_PUSH_MESSAGE, "BT_MAP_PUSH_MESSAGE"},
+ {BT_MAP_GET_MESSAGE, "BT_MAP_GET_MESSAGE"},
+ {BT_OBEX_SERVER_ALLOCATE, "BT_OBEX_SERVER_ALLOCATE"},
+ {BT_OBEX_SERVER_DEALLOCATE, "BT_OBEX_SERVER_DEALLOCATE"},
+ {BT_OBEX_SERVER_IS_ACTIVATED, "BT_OBEX_SERVER_IS_ACTIVATED"},
+ {BT_OBEX_SERVER_ACCEPT_CONNECTION, "BT_OBEX_SERVER_ACCEPT_CONNECTION"},
+ {BT_OBEX_SERVER_REJECT_CONNECTION, "BT_OBEX_SERVER_REJECT_CONNECTION"},
+ {BT_OBEX_SERVER_ACCEPT_FILE, "BT_OBEX_SERVER_ACCEPT_FILE"},
+ {BT_OBEX_SERVER_REJECT_FILE, "BT_OBEX_SERVER_REJECT_FILE"},
+ {BT_OBEX_SERVER_SET_PATH, "BT_OBEX_SERVER_SET_PATH"},
+ {BT_OBEX_SERVER_SET_ROOT, "BT_OBEX_SERVER_SET_ROOT"},
+ {BT_OBEX_SERVER_CANCEL_TRANSFER, "BT_OBEX_SERVER_CANCEL_TRANSFER"},
+ {BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS, "BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS"},
+ {BT_OBEX_SERVER_IS_RECEIVING, "BT_OBEX_SERVER_IS_RECEIVING"},
+ {BT_RFCOMM_CLIENT_CONNECT, "BT_RFCOMM_CLIENT_CONNECT"},
+ {BT_RFCOMM_CLIENT_CANCEL_CONNECT, "BT_RFCOMM_CLIENT_CANCEL_CONNECT"},
+ {BT_RFCOMM_CLIENT_IS_CONNECTED, "BT_RFCOMM_CLIENT_IS_CONNECTED"},
+ {BT_RFCOMM_SOCKET_DISCONNECT, "BT_RFCOMM_SOCKET_DISCONNECT"},
+ {BT_RFCOMM_SOCKET_WRITE, "BT_RFCOMM_SOCKET_WRITE"},
+ {BT_RFCOMM_CREATE_SOCKET, "BT_RFCOMM_CREATE_SOCKET"},
+ {BT_RFCOMM_REMOVE_SOCKET, "BT_RFCOMM_REMOVE_SOCKET"},
+ {BT_RFCOMM_LISTEN_AND_ACCEPT, "BT_RFCOMM_LISTEN_AND_ACCEPT"},
+ {BT_RFCOMM_LISTEN, "BT_RFCOMM_LISTEN"},
+ {BT_RFCOMM_IS_UUID_AVAILABLE, "BT_RFCOMM_IS_UUID_AVAILABLE"},
+ {BT_RFCOMM_ACCEPT_CONNECTION, "BT_RFCOMM_ACCEPT_CONNECTION"},
+ {BT_RFCOMM_REJECT_CONNECTION, "BT_RFCOMM_REJECT_CONNECTION"},
+ {BT_RFCOMM_CREATE_SOCKET_EX, "BT_RFCOMM_CREATE_SOCKET_EX"},
+ {BT_RFCOMM_REMOVE_SOCKET_EX, "BT_RFCOMM_REMOVE_SOCKET_EX"},
+ {BT_PBAP_CONNECT, "BT_PBAP_CONNECT"},
+ {BT_PBAP_DISCONNECT, "BT_PBAP_DISCONNECT"},
+ {BT_PBAP_GET_PHONEBOOK_SIZE, "BT_PBAP_GET_PHONEBOOK_SIZE"},
+ {BT_PBAP_GET_PHONEBOOK, "BT_PBAP_GET_PHONEBOOK"},
+ {BT_PBAP_GET_LIST, "BT_PBAP_GET_LIST"},
+ {BT_PBAP_PULL_VCARD, "BT_PBAP_PULL_VCARD"},
+ {BT_PBAP_PHONEBOOK_SEARCH, "BT_PBAP_PHONEBOOK_SEARCH"},
+ {BT_ENABLE_ADAPTER_LE, "BT_ENABLE_ADAPTER_LE"},
+ {BT_DISABLE_ADAPTER_LE, "BT_DISABLE_ADAPTER_LE"},
+ {BT_CONNECT_LE, "BT_CONNECT_LE"},
+ {BT_DISCONNECT_LE, "BT_DISCONNECT_LE"},
+ {BT_SET_LE_PRIVACY, "BT_SET_LE_PRIVACY"},
+ {BT_REQ_ATT_MTU, "BT_REQ_ATT_MTU"},
+ {BT_GET_ATT_MTU, "BT_GET_ATT_MTU"},
+ {BT_GATT_ACQUIRE_WRITE, "BT_GATT_ACQUIRE_WRITE"},
+ {BT_GET_DEVICE_IDA, "BT_GET_DEVICE_IDA"},
+ {BT_SET_LE_STATIC_RANDOM_ADDRESS, "BT_SET_LE_STATIC_RANDOM_ADDRESS"},
+ {BT_HDP_CONNECT, "BT_HDP_CONNECT"},
+ {BT_HDP_DISCONNECT, "BT_HDP_DISCONNECT"},
+ {BT_HDP_SEND_DATA, "BT_HDP_SEND_DATA"},
+ {BT_HDP_REGISTER_SINK_APP, "BT_HDP_REGISTER_SINK_APP"},
+ {BT_HDP_UNREGISTER_SINK_APP, "BT_HDP_UNREGISTER_SINK_APP"},
+ {BT_GATT_GET_PRIMARY_SERVICES, "BT_GATT_GET_PRIMARY_SERVICES"},
+ {BT_GATT_DISCOVER_CHARACTERISTICS, "BT_GATT_DISCOVER_CHARACTERISTICS"},
+ {BT_GATT_SET_PROPERTY_REQUEST, "BT_GATT_SET_PROPERTY_REQUEST"},
+ {BT_GATT_READ_CHARACTERISTIC, "BT_GATT_READ_CHARACTERISTIC"},
+ {BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR, "BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR"},
+ {BT_GATT_REGISTER_APPLICATION, "BT_GATT_REGISTER_APPLICATION"},
+ {BT_GATT_REGISTER_SERVICE, "BT_GATT_REGISTER_SERVICE"},
+ {BT_GATT_SEND_RESPONSE, "BT_GATT_SEND_RESPONSE"},
+ {BT_LE_IPSP_INIT, "BT_LE_IPSP_INIT"},
+ {BT_LE_IPSP_DEINIT, "BT_LE_IPSP_DEINIT"},
+ {BT_LE_IPSP_CONNECT, "BT_LE_IPSP_CONNECT"},
+ {BT_LE_IPSP_DISCONNECT, "BT_LE_IPSP_DISCONNECT"},
+ {BT_DPM_SET_ALLOW_BT_MODE, "BT_DPM_SET_ALLOW_BT_MODE"},
+ {BT_DPM_GET_ALLOW_BT_MODE, "BT_DPM_GET_ALLOW_BT_MODE"},
+ {BT_DPM_SET_DEVICE_RESTRITION, "BT_DPM_SET_DEVICE_RESTRITION"},
+ {BT_DPM_GET_DEVICE_RESTRITION, "BT_DPM_GET_DEVICE_RESTRITION"},
+ {BT_DPM_SET_UUID_RESTRITION, "BT_DPM_SET_UUID_RESTRITION"},
+ {BT_DPM_GET_UUID_RESTRITION, "BT_DPM_GET_UUID_RESTRITION"},
+ {BT_DPM_ADD_DEVICES_BLACKLIST, "BT_DPM_ADD_DEVICES_BLACKLIST"},
+ {BT_DPM_ADD_DEVICES_WHITELIST, "BT_DPM_ADD_DEVICES_WHITELIST"},
+ {BT_DPM_ADD_UUIDS_BLACKLIST, "BT_DPM_ADD_UUIDS_BLACKLIST"},
+ {BT_DPM_ADD_UUIDS_WHITELIST, "BT_DPM_ADD_UUIDS_WHITELIST"},
+ {BT_DPM_CLEAR_DEVICES_BLACKLIST, "BT_DPM_CLEAR_DEVICES_BLACKLIST"},
+ {BT_DPM_CLEAR_DEVICES_WHITELIST, "BT_DPM_CLEAR_DEVICES_WHITELIST"},
+ {BT_DPM_CLEAR_UUIDS_BLACKLIST, "BT_DPM_CLEAR_UUIDS_BLACKLIST"},
+ {BT_DPM_CLEAR_UUIDS_WHITELIST, "BT_DPM_CLEAR_UUIDS_WHITELIST"},
+ {BT_DPM_REMOVE_DEVICE_BLACKLIST, "BT_DPM_REMOVE_DEVICE_BLACKLIST"},
+ {BT_DPM_REMOVE_DEVICE_WHITELIST, "BT_DPM_REMOVE_DEVICE_WHITELIST"},
+ {BT_DPM_REMOVE_UUID_BLACKLIST, "BT_DPM_REMOVE_UUID_BLACKLIST"},
+ {BT_DPM_REMOVE_UUID_WHITELIST, "BT_DPM_REMOVE_UUID_WHITELIST"},
+ {BT_DPM_GET_DEVICES_BLACKLIST, "BT_DPM_GET_DEVICES_BLACKLIST"},
+ {BT_DPM_GET_DEVICES_WHITELIST, "BT_DPM_GET_DEVICES_WHITELIST"},
+ {BT_DPM_GET_UUIDS_BLACKLIST, "BT_DPM_GET_UUIDS_BLACKLIST"},
+ {BT_DPM_GET_UUIDS_WHITELIST, "BT_DPM_GET_UUIDS_WHITELIST"},
+ {BT_DPM_SET_ALLOW_OUTGOING_CALL, "BT_DPM_SET_ALLOW_OUTGOING_CALL"},
+ {BT_DPM_GET_ALLOW_OUTGOING_CALL, "BT_DPM_GET_ALLOW_OUTGOING_CALL"},
+ {BT_DPM_SET_PAIRING_STATE, "BT_DPM_SET_PAIRING_STATE"},
+ {BT_DPM_GET_PAIRING_STATE, "BT_DPM_GET_PAIRING_STATE"},
+ {BT_DPM_SET_PROFILE_STATE, "BT_DPM_SET_PROFILE_STATE"},
+ {BT_DPM_GET_PROFILE_STATE, "BT_DPM_GET_PROFILE_STATE"},
+ {BT_DPM_SET_DESKROP_CONNECTIVITY_STATE, "BT_DPM_SET_DESKROP_CONNECTIVITY_STATE"},
+ {BT_DPM_GET_DESKROP_CONNECTIVITY_STATE, "BT_DPM_GET_DESKROP_CONNECTIVITY_STATE"},
+ {BT_DPM_SET_DISCOVERABLE_STATE, "BT_DPM_SET_DISCOVERABLE_STATE"},
+ {BT_DPM_GET_DISCOVERABLE_STATE, "BT_DPM_GET_DISCOVERABLE_STATE"},
+ {BT_DPM_SET_LIMITED_DISCOVERABLE_STATE, "BT_DPM_SET_LIMITED_DISCOVERABLE_STATE"},
+ {BT_DPM_GET_LIMITED_DISCOVERABLE_STATE, "BT_DPM_GET_LIMITED_DISCOVERABLE_STATE"},
+ {BT_DPM_SET_DATA_TRANSFER_STATE, "BT_DPM_SET_DATA_TRANSFER_STATE"},
+ {BT_DPM_GET_DATA_TRANSFER_STATE, "BT_DPM_GET_DATA_TRANSFER_STATE"},
+ {BT_PXP_MONITOR_SET_PROPERTY, "BT_PXP_MONITOR_SET_PROPERTY"},
+ {BT_PXP_MONITOR_GET_PROPERTY, "BT_PXP_MONITOR_GET_PROPERTY"},
+ {BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES, "BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES"},
+ {BT_PXP_REPORTER_REGISTER, "BT_PXP_REPORTER_REGISTER"},
+ {BT_PXP_REPORTER_UNREGISTER, "BT_PXP_REPORTER_UNREGISTER"},
+ {BT_PXP_REPORTER_GET_PROPERTY, "BT_PXP_REPORTER_GET_PROPERTY"},
+ {BT_TDS_PROVIDER_REGISTER, "BT_TDS_PROVIDER_REGISTER"},
+ {BT_TDS_PROVIDER_UNREGISTER, "BT_TDS_PROVIDER_UNREGISTER"},
+ {BT_TDS_PROVIDER_SET_MANUF_DATA, "BT_TDS_PROVIDER_SET_MANUF_DATA"},
+ {BT_TDS_PROVIDER_CREATE, "BT_TDS_PROVIDER_CREATE"},
+ {BT_TDS_PROVIDER_DESTROY, "BT_TDS_PROVIDER_DESTROY"},
+ {BT_TDS_PROVIDER_SET_TRANSPORT_DATA, "BT_TDS_PROVIDER_SET_TRANSPORT_DATA"},
+ {BT_TDS_SEND_ACTIVATION_RESPONSE, "BT_TDS_SEND_ACTIVATION_RESPONSE"},
+ {BT_TDS_READ_TRANSPORT_DATA, "BT_TDS_READ_TRANSPORT_DATA"},
+ {BT_TDS_ENABLE_CONTROL_POINT, "BT_TDS_ENABLE_CONTROL_POINT"},
+ {BT_TDS_ACTIVATE_CONTROL_POINT, "BT_TDS_ACTIVATE_CONTROL_POINT"},
+ {BT_OTP_READ_VALUE, "BT_OTP_READ_VALUE"},
+ {BT_OTP_ENABLE_NOTIFICATION, "BT_OTP_ENABLE_NOTIFICATION"},
+ {BT_OTP_WRITE_VALUE, "BT_OTP_WRITE_VALUE"},
+ {BT_LE_OTC_CONNECT, "BT_LE_OTC_CONNECT"},
+ {BT_LE_OTC_DISCONNECT, "BT_LE_OTC_DISCONNECT"},
+ {-1, ""},
+ };
+
+ for (i = 0; bt_functions[i].function != -1; i++) {
+ if (bt_functions[i].function == function)
+ return bt_functions[i].function_name;
+ }
+
+ return NULL;
+}
+
int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
{
int i;
static GDBusProxy *profile_gproxy;
-static GDBusConnection *gconn;
static int latest_id = -1;
#define BT_RFCOMM_ID_MAX 245
static gboolean id_used[BT_RFCOMM_ID_MAX];
-GDBusNodeInfo *new_conn_node;
static const gchar rfcomm_agent_xml[] =
"<node name='/'>"
"</node>";
static void __new_connection_method(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
BT_DBG("method %s", method_name);
if (g_strcmp0(method_name, "NewConnection") == 0) {
msg = g_dbus_method_invocation_get_message(invocation);
fd_list = g_dbus_message_get_unix_fd_list(msg);
if (fd_list == NULL) {
+ BT_ERR("fd_list is NULL");
GQuark quark = g_quark_from_string("rfcomm-app");
GError *err = g_error_new(quark, 0, "No fd in message");
g_dbus_method_invocation_return_gerror(invocation, err);
latest_id = id - 1;
}
-static GDBusConnection *__get_gdbus_connection()
-{
- if (gconn == NULL)
- gconn = g_bus_get_private_conn();
-
- return gconn;
-}
-
static GDBusProxy *__bt_gdbus_get_profile_proxy(void)
{
GDBusConnection *gconn;
if (profile_gproxy)
return profile_gproxy;
- gconn = __get_gdbus_connection();
+ /* Shared connection should be used because rfcomm interface was registered
+ * on shared connection not private. Otherwise, dbus rejection is occured
+ * because dbus policy is only applied on shared connection not private. */
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return NULL;
- profile_gproxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE,
+ profile_gproxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
NULL, BT_BLUEZ_NAME,
"/org/bluez",
"org.bluez.ProfileManager1",
GError *err = NULL;
GDBusProxy *device_gproxy;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_private_conn();
if (gconn == NULL)
return NULL;
- device_gproxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE,
+ device_gproxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
NULL, BT_BLUEZ_NAME,
object_path,
BT_DEVICE_INTERFACE,
NULL, &err);
- if (err) {
+ if (device_gproxy == NULL && err) {
BT_ERR("Unable to create proxy: %s", err->message);
g_clear_error(&err);
return NULL;
{
GDBusConnection *gconn;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return;
g_dbus_connection_unregister_object(gconn, object_id);
+
+ /* TODO: bus_id needs to be un-owned if all of path is unregistered */
+}
+
+static GDBusNodeInfo *_bt_get_gdbus_node(GDBusConnection *gconn, const gchar *xml_data, const char *bus_name)
+{
+ if (bus_id == 0) {
+ char *name = g_strdup(bus_name);
+ BT_DBG("well-known name: %s", name);
+ bus_id = g_bus_own_name_on_connection(gconn,
+ name, G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL, NULL);
+ BT_DBG("Got bus id %d", bus_id);
+ g_free(name);
+ }
+
+ return g_dbus_node_info_new_for_xml(xml_data, NULL);
}
int _bt_register_new_conn(const char *path, bt_new_connection_cb cb)
{
GDBusConnection *gconn;
+ GDBusNodeInfo *node_info;
int id;
GError *error = NULL;
+ char *bus_name;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return -1;
- if (new_conn_node == NULL)
- new_conn_node = _bt_get_gdbus_node(rfcomm_agent_xml);
+ bus_name = g_strdup_printf("org.bt.frwk.p%d", getpid());
- if (new_conn_node == NULL)
+ node_info = _bt_get_gdbus_node(gconn, rfcomm_agent_xml, bus_name);
+ if (node_info == NULL) {
+ g_free(bus_name);
return -1;
+ }
+ g_free(bus_name);
id = g_dbus_connection_register_object(gconn, path,
- new_conn_node->interfaces[0],
+ node_info->interfaces[0],
&method_table,
cb, NULL, &error);
+ g_dbus_node_info_unref(node_info);
if (id == 0) {
BT_ERR("Failed to register: %s", error->message);
g_error_free(error);
GVariant *result = NULL;
char *adapter_path = NULL;
- conn = __get_gdbus_connection();
+ conn = _bt_get_system_private_conn();
retv_if(conn == NULL, NULL);
manager_proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_BLUEZ_NAME,
BT_MANAGER_PATH,
BT_MANAGER_INTERFACE,
BT_INFO("Adapter Path %s", adapter_path);
adapter_proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_BLUEZ_NAME,
adapter_path,
BT_ADAPTER_INTERFACE,
int _bt_register_new_conn_ex(const char *path, const char *bus_name, bt_new_connection_cb cb)
{
GDBusConnection *gconn;
+ GDBusNodeInfo *node_info;
int id;
GError *error = NULL;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_shared_conn();
if (gconn == NULL)
return -1;
- if (new_conn_node == NULL)
- new_conn_node = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name);
-
- if (new_conn_node == NULL)
+ node_info = _bt_get_gdbus_node(gconn, rfcomm_agent_xml, bus_name);
+ if (node_info == NULL)
return -1;
id = g_dbus_connection_register_object(gconn, path,
- new_conn_node->interfaces[0],
+ node_info->interfaces[0],
&method_table,
cb, NULL, &error);
+ g_dbus_node_info_unref(node_info);
if (id == 0) {
BT_ERR("Failed to register: %s", error->message);
g_error_free(error);
NULL, &err);
if (err) {
g_dbus_error_strip_remote_error(err);
- BT_ERR("RegisterProfile failed: %s", err->message);
+ BT_ERR("RegisterProfile2 failed: %s", err->message);
if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
result = BLUETOOTH_ERROR_ACCESS_DENIED;
if (err) {
g_dbus_error_strip_remote_error(err);
- BT_ERR("RegisterProfile failed: %s", err->message);
+ BT_ERR("RegisterProfile1 failed: %s", err->message);
if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
result = BLUETOOTH_ERROR_ACCESS_DENIED;
return;
}
-GDBusNodeInfo * _bt_get_gdbus_node(const gchar *xml_data)
-{
- if (bus_id == 0) {
- char *name = g_strdup_printf("org.bt.frwk%d", getpid());
-
- bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- name,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
- BT_DBG("Got bus id %d", bus_id);
- g_free(name);
- }
-
- return g_dbus_node_info_new_for_xml(xml_data, NULL);
-}
-
-GDBusNodeInfo * _bt_get_gdbus_node_ex(const gchar *xml_data, const char *bus_name)
-{
- if (bus_id == 0) {
- char *name = g_strdup(bus_name);
- bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- name,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
- BT_DBG("Got bus id %d", bus_id);
- g_free(name);
- }
-
- return g_dbus_node_info_new_for_xml(xml_data, NULL);
-}
-
int _bt_connect_profile(char *address, char *uuid, void *cb,
gpointer func_data)
{
int result = BLUETOOTH_ERROR_INTERNAL;
BT_INFO("+");
retv_if(remote_uuid == NULL, BLUETOOTH_ERROR_INTERNAL);
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_private_conn();
retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL);
object_path = _bt_get_device_object_path(address);
retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
- proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+ proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL,
&err);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- if (err) {
- BT_ERR("DBus Error: [%s]", err->message);
- g_clear_error(&err);
+ g_free(object_path);
+ if (proxy == NULL) {
+ if (err) {
+ BT_ERR("DBus Error: [%s]", err->message);
+ g_clear_error(&err);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
}
- ret = g_dbus_proxy_call_sync(proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
+ ret = g_dbus_proxy_call_sync(proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "UUIDs"),
+ G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, &err);
if (err) {
result = BLUETOOTH_ERROR_INTERNAL;
BT_ERR("DBus Error : %s", err->message);
g_clear_error(&err);
goto done;
- }
- if (ret == NULL) {
- BT_ERR("g_dbus_proxy_call_sync function return NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- goto done;
+ } else {
+ g_variant_get(ret, "(v)", &value);
+ uuid_value = (char **)g_variant_get_strv(value, &size);
+ BT_DBG("Size items %zd", size);
}
- g_variant_get(ret, "(@a{sv})", &value);
- g_variant_unref(ret);
- if (value) {
- GVariant *temp_value = g_variant_lookup_value(value, "UUIDs",
- G_VARIANT_TYPE_STRING_ARRAY);
-
- if (temp_value) {
- size = g_variant_get_size(temp_value);
- if (size > 0) {
- uuid_value = (char **)g_variant_get_strv(temp_value, &size);
- BT_DBG("Size items %d", size);
-
- if (uuid_value) {
- for (i = 0; uuid_value[i] != NULL; i++) {
- BT_DBG("Remote uuids %s", uuid_value[i]);
- if (strcasecmp(uuid_value[i], remote_uuid) == 0) {
- result = BLUETOOTH_ERROR_NONE;
- g_variant_unref(temp_value);
- goto done;
- }
- }
- }
+ if (uuid_value) {
+ for (i = 0; uuid_value[i] != NULL; i++) {
+ BT_DBG("Remote uuids %s", uuid_value[i]);
+ if (uuid_value[i] == NULL) {
+ BT_ERR("_bt_discover_service_uuids Error Parameter are NULL..\n");
+ continue;
+ } else if (g_ascii_strcasecmp(uuid_value[i], remote_uuid) == 0) {
+ result = BLUETOOTH_ERROR_NONE;
+ goto done;
}
- g_variant_unref(temp_value);
}
}
+
done:
if (proxy)
g_object_unref(proxy);
- if (value)
- g_variant_unref(value);
if (uuid_value)
g_free(uuid_value);
+ if (value)
+ g_variant_unref(value);
+
+ if (ret)
+ g_variant_unref(ret);
+
BT_DBG("-");
return result;
}
GVariant *value = NULL;
GVariant *result = NULL;
unsigned int class = 0x00;
- int ret = BLUETOOTH_ERROR_INTERNAL;
+ int ret = BLUETOOTH_ERROR_NONE;
- gconn = __get_gdbus_connection();
+ gconn = _bt_get_system_private_conn();
retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL);
- object_path = _bt_get_device_object_path(address);
+ object_path = _bt_get_device_object_path(address);
retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
- proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+ proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL,
&err);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- if (err) {
- BT_ERR("DBus Error: [%s]", err->message);
- g_clear_error(&err);
+ if (proxy == NULL) {
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ if (err) {
+ BT_ERR("DBus Error: [%s]", err->message);
+ g_clear_error(&err);
+ }
+ goto done;
}
- result = g_dbus_proxy_call_sync(proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
+ result = g_dbus_proxy_call_sync(proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Class"),
+ G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, &err);
if (err) {
ret = BLUETOOTH_ERROR_INTERNAL;
BT_ERR("DBus Error : %s", err->message);
g_clear_error(&err);
goto done;
- }
- if (result == NULL) {
- BT_ERR("g_dbus_proxy_call_sync function return NULL");
- ret = BLUETOOTH_ERROR_INTERNAL;
- goto done;
- }
- g_variant_get(result, "(@a{sv})", &value);
- g_variant_unref(result);
- if (value) {
- GVariant *temp_value = g_variant_lookup_value(value, "Class",
- G_VARIANT_TYPE_UINT32);
- class = g_variant_get_uint32(temp_value);
+ } else {
+ g_variant_get(result, "(v)", &value);
+ class = g_variant_get_uint32(value);
_bt_divide_device_class(dev_class, class);
- if (temp_value)
- g_variant_unref(temp_value);
+ g_variant_unref(value);
+ g_variant_unref(result);
}
done:
+ g_free(object_path);
if (proxy)
g_object_unref(proxy);
- if (value)
- g_variant_unref(value);
BT_DBG("-");
return ret;
return BLUETOOTH_ERROR_NONE;
}
+int _bt_disconnect_ext_profile(char *address, char *path)
+{
+ GDBusProxy *proxy;
+ char *object_path;
+
+ object_path = _bt_get_device_object_path(address);
+ if (object_path == NULL)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ proxy = __bt_gdbus_get_device_proxy(object_path);
+ g_free(object_path);
+ if (proxy == NULL) {
+ BT_ERR("Error while getting proxy");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_dbus_proxy_call(proxy, "DisconnectExtProfile",
+ g_variant_new("(o)", path),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL, NULL, NULL);
+ BT_DBG("-");
+ return BLUETOOTH_ERROR_NONE;
+}
+
int _bt_get_adapter_path(GDBusConnection *conn, char *path)
{
GError *err = NULL;
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
manager_proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_BLUEZ_NAME,
BT_MANAGER_PATH,
BT_MANAGER_INTERFACE,
}
+void _bt_convert_device_path_to_addr_type(const char *device_path,
+ unsigned char *addr)
+{
+ char *dev_addr;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ int i;
+ char *addr_ptr = address;
+ char *ptr = NULL;
+
+ ret_if(device_path == NULL);
+ ret_if(addr == NULL);
+
+ dev_addr = strstr(device_path, "dev_");
+ if (dev_addr != NULL) {
+ dev_addr += 4;
+ g_strlcpy(addr_ptr, dev_addr, BT_ADDRESS_STRING_SIZE);
+
+ for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
+ addr[i] = strtol(addr_ptr, &ptr, 16);
+ if (ptr[0] != '\0') {
+ if (ptr[0] != '_')
+ return;
+
+ addr_ptr = ptr + 1;
+ }
+ }
+ }
+}
+
void _bt_convert_device_path_to_address(const char *device_path,
char *device_address)
{
GDBusConnection *conn = NULL;
char *object_path = NULL;
- conn = _bt_gdbus_get_system_gconn();
+ conn = _bt_get_system_private_conn();
retv_if(conn == NULL, NULL);
proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_BLUEZ_NAME,
BT_MANAGER_PATH,
BT_MANAGER_INTERFACE,
return object_path;
}
-GDBusConnection *_bt_init_system_gdbus_conn(void)
-{
- GError *error = NULL;
- if (system_gdbus_conn == NULL) {
- system_gdbus_conn =
- g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (error) {
- BT_ERR("GDBus connection Error : %s \n",
- error->message);
- g_clear_error(&error);
- return NULL;
- }
- }
- return system_gdbus_conn;
-}
-
-
int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
{
int ret;
BT_INIT_PARAMS();
BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
- result = _bt_send_request(service_type, service_function,
+ result = _bt_sync_send_request(service_type, service_function,
in_param1, in_param2, in_param3, in_param4, &out_param);
BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
BT_DBG("+");
- g_conn = _bt_gdbus_get_system_gconn();
+ g_conn = _bt_get_system_private_conn();
retv_if(g_conn == NULL, NULL);
manager_proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
BT_BLUEZ_NAME,
BT_MANAGER_PATH,
BT_MANAGER_INTERFACE,
if (error) {
BT_ERR("Unable to create proxy: %s", error->message);
g_clear_error(&error);
+ if (manager_proxy)
+ g_object_unref(manager_proxy);
return NULL;
}
+ if (!manager_proxy)
+ return NULL;
+
result = g_dbus_proxy_call_sync(manager_proxy,
"GetManagedObjects", NULL,
G_DBUS_CALL_FLAGS_NONE, -1,
bt_enabled = enabled;
}
-int _bt_get_uuid_specification_name(const char *uuid, char **name)
+BT_EXPORT_API int bluetooth_get_uuid_name(const char *uuid, char **name)
{
- int i;
+#define SHORT_UUID_COUNT 162
+#define LONG_UUID_COUNT 17
+
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"},
+ {"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"},
{"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"},
{"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"},
{"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 */
- {"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"},
- {NULL, NULL}
+ {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
+ {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
};
+ const uuid_name_s *uuid_name = short_uuid_name;
+ int start = 0;
+ int end = SHORT_UUID_COUNT - 1;
+ int p;
+ int ret;
if (!uuid || !name)
return BLUETOOTH_ERROR_INVALID_PARAM;
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)) {
- *name = g_strdup(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) {
+ *name = g_strdup(uuid_name[p].specification_name);
return BLUETOOTH_ERROR_NONE;
- }
+ } else if (ret < 0)
+ end = p - 1;
+ else
+ start = p + 1;
}
+ BT_INFO("Unknown uuid : %s", uuid);
*name = g_strdup("Unknown");
return BLUETOOTH_ERROR_NONE;
}
+int _bt_get_error_value_from_message(const char *error_message)
+{
+ if (error_message == NULL) {
+ BT_ERR("Error message NULL");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ BT_ERR("Error message = %s", error_message);
+
+ if (g_strrstr(error_message, BT_ERROR_OPERATION_NOT_SUPPORTED))
+ return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+ else if (g_strrstr(error_message, BT_ERROR_OPERATION_NOT_ALLOWED))
+ return BLUETOOTH_ERROR_PERMISSION_DEINED;
+ else if (g_strrstr(error_message, BT_ERROR_ACCESS_DENIED))
+ return BLUETOOTH_ERROR_PERMISSION_DEINED;
+ else
+ return BLUETOOTH_ERROR_INTERNAL;
+}
+
BT_EXPORT_API int bluetooth_is_supported(void)
{
int is_supported = 0;
{
int ret;
- _bt_gdbus_init_system_gconn();
+ _bt_get_system_private_conn();
ret = _bt_init_event_handler();
if (ret != BLUETOOTH_ERROR_NONE &&
if (ret != BLUETOOTH_ERROR_NONE)
goto fail;
#endif
+ ret = _bt_register_event(BT_TDS_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
+ ret = _bt_register_event(BT_OTP_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
+ ret = _bt_register_event(BT_HDP_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
}
_bt_register_name_owner_changed();
_bt_set_user_data(BT_COMMON, NULL, NULL);
- if (system_gconn) {
- g_object_unref(system_gconn);
- system_gconn = NULL;
+ _bt_set_obex_server_id(BT_NO_SERVER);
+
+ _bt_gdbus_deinit_proxys();
+
+ if (system_private_conn) {
+ g_object_unref(system_private_conn);
+ system_private_conn = NULL;
}
+
return BLUETOOTH_ERROR_NONE;
}