/*
- * bluetooth-frwk
- *
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ * 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.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
+#include <sys/socket.h>
+
+
+#include <gio/gunixfdlist.h>
+
#include "bluetooth-api.h"
#include "bluetooth-audio-api.h"
#include "bluetooth-hid-api.h"
#include "bluetooth-media-control.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"
+#ifdef TIZEN_FEATURE_BT_DPM
+#include "bt-dpm.h"
+#endif
+
+
static bt_user_info_t user_info[BT_MAX_USER_INFO];
-static DBusGConnection *system_conn = NULL;
+static GDBusConnection *system_gdbus_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)
+{
+ GError *error = NULL;
+ char *address;
+ GDBusConnection *private_gconn = NULL;
+
+ address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (address == NULL) {
+ if (error) {
+ BT_ERR("Failed to get bus address: %s", error->message);
+ g_clear_error(&error);
+ }
+ return NULL;
+ }
+
+ private_gconn = g_dbus_connection_new_for_address_sync(address,
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+ NULL, /* GDBusAuthObserver */
+ NULL,
+ &error);
+ g_free(address);
+ if (!private_gconn) {
+ if (error) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+ return NULL;
+ }
+
+ return private_gconn;
+}
+
+GDBusConnection *_bt_gdbus_init_system_gconn(void)
+{
+ if (system_gconn != NULL)
+ return system_gconn;
+
+ system_gconn = g_bus_get_private_conn();
+
+ return system_gconn;
+}
+
+GDBusConnection *_bt_gdbus_get_system_gconn(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;
+}
void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
{
user_data);
}
+void _bt_a2dp_source_event_cb(int event, int result, void *param,
+ void *callback, void *user_data)
+{
+ bt_audio_event_param_t bt_event = { 0, };
+ bt_event.event = event;
+ bt_event.result = result;
+ bt_event.param_data = param;
+ if (callback)
+ ((bt_audio_func_ptr)callback)(bt_event.event, &bt_event,
+ user_data);
+}
+
+void _bt_hf_event_cb(int event, int result, void *param,
+ void *callback, void *user_data)
+{
+ bt_hf_event_param_t bt_event = { 0, };
+ bt_event.event = event;
+ bt_event.result = result;
+ bt_event.param_data = param;
+
+ if (callback)
+ ((bt_hf_func_ptr)callback)(bt_event.event, &bt_event,
+ user_data);
+}
+
+
void _bt_avrcp_event_cb(int event, int result, void *param,
void *callback, void *user_data)
{
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;
+
+ 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 i;
- char *ptr = NULL;
+ 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 != NULL) {
- if (ptr[0] != ':')
- return;
+ len = strlen(address);
+ ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
+
+ strncpy(addr, address, len);
+ addr[len] = '\0';
- address = ptr + 1;
- }
- }
+ 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_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_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, "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_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;
- char *p = src;
+ const char *p = src;
char *next;
int count;
while (count > 0 && ((i + count) < length)) {
dest[i++] = *p;
p++;
- count --;
+ count--;
}
p = next;
}
return BLUETOOTH_ERROR_NONE;
}
-int _bt_get_adapter_path(DBusGConnection *conn, char *path)
+gboolean _bt_utf8_validate(char *name)
+{
+ BT_DBG("+");
+ gunichar2 *u16;
+ glong items_written = 0;
+
+ if (FALSE == g_utf8_validate(name, -1, NULL))
+ return FALSE;
+
+ u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
+ if (u16 == NULL)
+ return FALSE;
+
+ g_free(u16);
+
+ if (items_written != g_utf8_strlen(name, -1))
+ return FALSE;
+
+ BT_DBG("-");
+ return TRUE;
+}
+
+
+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];
+
+static const gchar rfcomm_agent_xml[] =
+"<node name='/'>"
+" <interface name='org.bluez.Profile1'>"
+" <method name='NewConnection'>"
+" <arg type='o' name='object' direction='in'/>"
+" <arg type='h' name='fd' direction='in'/>"
+" <arg type='a{sv}' name='properties' direction='in'/>"
+" </method>"
+" <method name='RequestDisconnection'>"
+" <arg type='o' name='device' direction='in'/>"
+" </method>"
+" </interface>"
+"</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)
+{
+ BT_DBG("method %s", method_name);
+ if (g_strcmp0(method_name, "NewConnection") == 0) {
+ int index;
+ GDBusMessage *msg;
+ GUnixFDList *fd_list;
+ GVariantBuilder *properties;
+ char *obj_path;
+ char addr[20];
+ bluetooth_device_address_t remote_addr1;
+ bt_new_connection_cb cb = user_data;
+ char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ int fd;
+
+ g_variant_get(parameters, "(oha{sv})", &obj_path, &index,
+ &properties);
+
+ 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);
+ g_error_free(err);
+ return;
+ }
+
+
+ fd = g_unix_fd_list_get(fd_list, index, NULL);
+ if (fd == -1) {
+ BT_ERR("Invalid fd return");
+ GQuark quark = g_quark_from_string("rfcomm-app");
+ GError *err = g_error_new(quark, 0, "Invalid FD return");
+ g_dbus_method_invocation_return_gerror(invocation, err);
+ g_error_free(err);
+ return;
+ }
+
+ _bt_convert_device_path_to_address(obj_path, addr);
+ _bt_convert_addr_string_to_type(remote_addr1.addr, (const char *)addr);
+
+ _bt_convert_addr_string_to_secure_string(secure_address, addr);
+ BT_INFO("fd: %d, address %s", fd, secure_address);
+
+ g_dbus_method_invocation_return_value(invocation, NULL);
+
+ if (cb)
+ cb(object_path, fd, &remote_addr1);
+ } else if (g_strcmp0(method_name, "RequestDisconnection") == 0) {
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+}
+
+
+static const GDBusInterfaceVTable method_table = {
+ __new_connection_method,
+ NULL,
+ NULL,
+};
+
+void _bt_swap_addr(unsigned char *dst, const unsigned char *src)
+{
+ int i;
+
+ for (i = 0; i < 6; i++)
+ dst[i] = src[5-i];
+}
+
+int __rfcomm_assign_id(void)
+{
+ int index;
+
+ BT_DBG("latest_id: %d", latest_id);
+
+ index = latest_id + 1;
+
+ if (index >= BT_RFCOMM_ID_MAX)
+ index = 0;
+
+ BT_DBG("index: %d", index);
+
+ while (id_used[index] == TRUE) {
+ if (index == latest_id) {
+ /* No available ID */
+ BT_ERR("All request ID is used");
+ return -1;
+ }
+
+ index++;
+
+ if (index >= BT_RFCOMM_ID_MAX)
+ index = 0;
+ }
+
+ latest_id = index;
+ id_used[index] = TRUE;
+
+ BT_DBG("Assigned Id: %d", latest_id);
+
+ return latest_id;
+}
+
+void __rfcomm_delete_id(int id)
+{
+ ret_if(id >= BT_RFCOMM_ID_MAX);
+ ret_if(id < 0);
+
+ id_used[id] = FALSE;
+
+ /* Next server will use this ID */
+ 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;
+ GError *err = NULL;
+
+ if (profile_gproxy)
+ return profile_gproxy;
+
+ gconn = __get_gdbus_connection();
+ if (gconn == NULL)
+ return NULL;
+
+ profile_gproxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ "/org/bluez",
+ "org.bluez.ProfileManager1",
+ NULL, &err);
+ if (err) {
+ BT_ERR("Unable to create proxy: %s", err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
+ return profile_gproxy;
+}
+
+static GDBusProxy *__bt_gdbus_get_device_proxy(char *object_path)
+{
+ GDBusConnection *gconn;
+ GError *err = NULL;
+ GDBusProxy *device_gproxy;
+
+ gconn = __get_gdbus_connection();
+ if (gconn == NULL)
+ return NULL;
+
+ device_gproxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path,
+ BT_DEVICE_INTERFACE,
+ NULL, &err);
+
+ if (device_gproxy == NULL && err) {
+ BT_ERR("Unable to create proxy: %s", err->message);
+ g_clear_error(&err);
+ return NULL;
+ }
+
+ return device_gproxy;
+}
+
+void _bt_unregister_gdbus(int object_id)
+{
+ GDBusConnection *gconn;
+
+ gconn = __get_gdbus_connection();
+ if (gconn == NULL)
+ return;
+
+ g_dbus_connection_unregister_object(gconn, object_id);
+}
+
+int _bt_register_new_conn(const char *path, bt_new_connection_cb cb)
+{
+ GDBusConnection *gconn;
+ GDBusNodeInfo *node_info;
+ int id;
+ GError *error = NULL;
+
+ gconn = __get_gdbus_connection();
+ if (gconn == NULL)
+ return -1;
+
+ node_info = _bt_get_gdbus_node(rfcomm_agent_xml);
+ if (node_info == NULL)
+ return -1;
+
+ id = g_dbus_connection_register_object(gconn, path,
+ 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);
+ return -1;
+ }
+
+ BT_DBG("NEW CONNECTION ID %d", id);
+
+ return id;
+}
+
+static GDBusProxy * __bt_gdbus_get_adapter_proxy()
{
GError *err = NULL;
- DBusGProxy *manager_proxy = NULL;
+ GDBusProxy *manager_proxy = NULL;
+ GDBusProxy *adapter_proxy = NULL;
+ GDBusConnection *conn;
+ GVariant *result = NULL;
char *adapter_path = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+ conn = __get_gdbus_connection();
+ retv_if(conn == NULL, NULL);
+
+ manager_proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME,
+ BT_MANAGER_PATH,
+ BT_MANAGER_INTERFACE,
+ NULL, &err);
+
+ if (!manager_proxy) {
+ BT_ERR("Unable to create proxy: %s", err->message);
+ goto fail;
+ }
+
+ result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (!result) {
+ if (err != NULL)
+ BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
+ else
+ BT_ERR("Fail to get DefaultAdapter");
+
+ goto fail;
+ }
+
+ if (g_strcmp0(g_variant_get_type_string(result), "(o)")) {
+ BT_ERR("Incorrect result\n");
+ goto fail;
+ }
+
+ g_variant_get(result, "(&o)", &adapter_path);
+
+ if (adapter_path == NULL ||
+ strlen(adapter_path) >= BT_ADAPTER_OBJECT_PATH_MAX) {
+ BT_ERR("Adapter path is inproper\n");
+ goto fail;
+ }
+
+ BT_INFO("Adapter Path %s", adapter_path);
+
+ adapter_proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME,
+ adapter_path,
+ BT_ADAPTER_INTERFACE,
+ NULL, &err);
+ if (err) {
+ BT_ERR("DBus Error message: [%s]", err->message);
+ g_clear_error(&err);
+ }
+
+fail:
+ if (manager_proxy)
+ g_object_unref(manager_proxy);
+ if (result)
+ g_variant_unref(result);
+ return adapter_proxy;
+}
+
+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();
+ if (gconn == NULL)
+ return -1;
+
+ node_info = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name);
+
+ if (node_info == NULL)
+ return -1;
+
+ id = g_dbus_connection_register_object(gconn, path,
+ 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);
+ return -1;
+ }
+
+ BT_DBG("NEW CONNECTION ID %d", id);
+
+ return id;
+}
+
+int _bt_register_profile(bt_register_profile_info_t *info, gboolean use_default_rfcomm)
+{
+ GVariantBuilder *option_builder;
+ GVariant *ret;
+ GDBusProxy *proxy;
+ GError *err = NULL;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ proxy = __bt_gdbus_get_profile_proxy();
+ if (proxy == NULL) {
+ BT_ERR("Getting profile proxy failed");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ option_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ if (info->authentication)
+ g_variant_builder_add(option_builder, "{sv}",
+ "RequireAuthentication",
+ g_variant_new_boolean(TRUE));
+ if (info->authorization)
+ g_variant_builder_add(option_builder, "{sv}",
+ "RequireAuthorization",
+ g_variant_new_boolean(TRUE));
+ if (info->role)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Role",
+ g_variant_new_string(info->role));
+
+ /* Setting RFCOMM channel to default value 0; would allow bluez to assign
+ * RFCOMM channels based on the availability when two services want
+ * to use the RFCOMM along with SPP. Hence bluez makes sure that no
+ * two services use the same SPP RFCOMM channel. */
+ if (use_default_rfcomm)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Channel",
+ g_variant_new_uint16(RFCOMM_DEFAULT_PROFILE_CHANNEL));
+ if (info->service)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Service",
+ g_variant_new_string(info->service));
+
+ ret = g_dbus_proxy_call_sync(proxy, "RegisterProfile",
+ g_variant_new("(osa{sv})", info->obj_path,
+ info->uuid,
+ option_builder),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ BT_ERR("RegisterProfile failed: %s", err->message);
+
+ if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
+ result = BLUETOOTH_ERROR_ACCESS_DENIED;
+ else
+ result = BLUETOOTH_ERROR_INTERNAL;
+
+ g_clear_error(&err);
+ }
+
+ g_variant_builder_unref(option_builder);
+
+ if (ret)
+ g_variant_unref(ret);
+
+ return result;
+}
+
+int _bt_register_profile_ex(bt_register_profile_info_t *info, gboolean use_default_rfcomm, const char *name, const char *path)
+{
+ GVariantBuilder *option_builder;
+ GVariant *ret;
+ GDBusProxy *proxy;
+ GError *err = NULL;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ proxy = __bt_gdbus_get_profile_proxy();
+ if (proxy == NULL) {
+ BT_ERR("Getting profile proxy failed");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ option_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ if (info->authentication)
+ g_variant_builder_add(option_builder, "{sv}",
+ "RequireAuthentication",
+ g_variant_new_boolean(TRUE));
+ if (info->authorization)
+ g_variant_builder_add(option_builder, "{sv}",
+ "RequireAuthorization",
+ g_variant_new_boolean(TRUE));
+ if (info->role)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Role",
+ g_variant_new_string(info->role));
+
+ /* Setting RFCOMM channel to default value 0; would allow bluez to assign
+ * RFCOMM channels based on the availability when two services want
+ * to use the RFCOMM along with SPP. Hence bluez makes sure that no
+ * two services use the same SPP RFCOMM channel. */
+ if (use_default_rfcomm)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Channel",
+ g_variant_new_uint16(RFCOMM_DEFAULT_PROFILE_CHANNEL));
+ if (info->service)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Service",
+ g_variant_new_string(info->service));
+
+ ret = g_dbus_proxy_call_sync(proxy, "RegisterProfile2",
+ g_variant_new("(osssa{sv})", info->obj_path,
+ info->uuid,
+ name,
+ path,
+ option_builder),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ BT_ERR("RegisterProfile failed: %s", err->message);
+
+ if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
+ result = BLUETOOTH_ERROR_ACCESS_DENIED;
+ else
+ result = BLUETOOTH_ERROR_INTERNAL;
+
+ g_clear_error(&err);
+ }
+
+ g_variant_builder_unref(option_builder);
+
+ if (ret)
+ g_variant_unref(ret);
+
+ return result;
+}
+
+int _bt_register_profile_platform(bt_register_profile_info_t *info, gboolean use_default_rfcomm)
+{
+ GVariantBuilder *option_builder;
+ GVariant *ret;
+ GDBusProxy *proxy;
+ GError *err = NULL;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ proxy = __bt_gdbus_get_profile_proxy();
+ if (proxy == NULL) {
+ BT_ERR("Getting profile proxy failed");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ option_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ if (info->authentication)
+ g_variant_builder_add(option_builder, "{sv}",
+ "RequireAuthentication",
+ g_variant_new_boolean(TRUE));
+ if (info->authorization)
+ g_variant_builder_add(option_builder, "{sv}",
+ "RequireAuthorization",
+ g_variant_new_boolean(TRUE));
+ if (info->role)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Role",
+ g_variant_new_string(info->role));
+
+ /* Setting RFCOMM channel to default value 0; would allow bluez to assign
+ * RFCOMM channels based on the availability when two services want
+ * to use the RFCOMM along with SPP. Hence bluez makes sure that no
+ * two services use the same SPP RFCOMM channel. */
+ if (use_default_rfcomm)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Channel",
+ g_variant_new_uint16(RFCOMM_DEFAULT_PROFILE_CHANNEL));
+ if (info->service)
+ g_variant_builder_add(option_builder, "{sv}",
+ "Service",
+ g_variant_new_string(info->service));
+
+ ret = g_dbus_proxy_call_sync(proxy, "RegisterProfile1",
+ g_variant_new("(osa{sv})", info->obj_path,
+ info->uuid,
+ option_builder),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ BT_ERR("RegisterProfile failed: %s", err->message);
+
+ if (g_strrstr(err->message, BT_ACCESS_DENIED_MSG))
+ result = BLUETOOTH_ERROR_ACCESS_DENIED;
+ else
+ result = BLUETOOTH_ERROR_INTERNAL;
+
+ g_clear_error(&err);
+ }
- manager_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- BT_MANAGER_PATH, BT_MANAGER_INTERFACE);
+ g_variant_builder_unref(option_builder);
- retv_if(manager_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ if (ret)
+ g_variant_unref(ret);
+
+ return result;
+}
+
+
+void _bt_unregister_profile(char *path)
+{
+ GVariant *ret;
+ GDBusProxy *proxy;
+ GError *err = NULL;
+
+ proxy = __bt_gdbus_get_profile_proxy();
+ if (proxy == NULL) {
+ BT_ERR("Getting profile proxy failed");
+ return;
+ }
+
+ ret = g_dbus_proxy_call_sync(proxy, "UnregisterProfile",
+ g_variant_new("(o)", path),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+ if (err) {
+ BT_ERR("UnregisterProfile failed : %s", err->message);
+ g_clear_error(&err);
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ return;
+}
+
+GDBusNodeInfo * _bt_get_gdbus_node(const gchar *xml_data)
+{
+ if (bus_id == 0) {
+ char *name = g_strdup_printf("org.bt.frwk.p%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)
+{
+ GDBusProxy *proxy;
+ GDBusProxy *adapter_proxy;
+ char *object_path;
+ GError *err = NULL;
+
+ object_path = _bt_get_device_object_path(address);
+
+ if (object_path == NULL) {
+ GVariant *ret = NULL;
+ BT_ERR("No searched device");
+ adapter_proxy = __bt_gdbus_get_adapter_proxy();
+
+ if (adapter_proxy == NULL) {
+ BT_ERR("adapter proxy is NULL");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
- if (!dbus_g_proxy_call(manager_proxy, "DefaultAdapter", &err,
- G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH,
- &adapter_path,
- G_TYPE_INVALID)) {
if (err != NULL) {
- BT_ERR("Getting DefaultAdapter failed: [%s]\n", err->message);
- g_error_free(err);
+ BT_ERR("CreateDevice Failed: %s", err->message);
+ g_clear_error(&err);
}
- g_object_unref(manager_proxy);
+ if (ret)
+ g_variant_unref(ret);
+ g_object_unref(adapter_proxy);
+ 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;
}
- if (adapter_path == NULL || strlen(adapter_path) >= BT_ADAPTER_OBJECT_PATH_MAX) {
- BT_ERR("Adapter path is inproper\n");
+ g_dbus_proxy_call(proxy, "ConnectProfile",
+ g_variant_new("(s)", uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ (GAsyncReadyCallback)cb,
+ func_data);
+ BT_DBG("-");
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_discover_services(char *address, char *uuid, void *cb,
+ gpointer func_data)
+{
+ char *object_path;
+ GDBusProxy *proxy;
+ GDBusProxy *adapter_proxy;
+ GError *err = NULL;
+ object_path = _bt_get_device_object_path(address);
+ if (object_path == NULL) {
+ GVariant *ret = NULL;
+ BT_ERR("No searched device");
+ adapter_proxy = __bt_gdbus_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
+ if (err != NULL) {
+ BT_ERR("CreateDevice Failed: %s", err->message);
+ g_clear_error(&err);
+ }
+ if (ret)
+ g_variant_unref(ret);
+ g_object_unref(adapter_proxy);
+ 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, "DiscoverServices",
+ g_variant_new("(s)", uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ (GAsyncReadyCallback)cb,
+ func_data);
+ BT_DBG("-");
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_cancel_discovers(char *address)
+{
+ char *object_path;
+ GDBusProxy *proxy;
+ GDBusProxy *adapter_proxy;
+ GVariant *ret = NULL;
+ GError *err = NULL;
+ object_path = _bt_get_device_object_path(address);
+ if (object_path == NULL) {
+ GVariant *ret = NULL;
+ BT_ERR("No searched device");
+ adapter_proxy = __bt_gdbus_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
+ if (err != NULL) {
+ BT_ERR("CreateDevice Failed: %s", err->message);
+ g_clear_error(&err);
+ }
+ if (ret)
+ g_variant_unref(ret);
+ g_object_unref(adapter_proxy);
+ 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);
+ ret = g_dbus_proxy_call_sync(proxy, "CancelDiscovery",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
+ if (err) {
+ BT_ERR("DBus Error message: [%s]", err->message);
+ g_clear_error(&err);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ if (ret)
+ g_variant_unref(ret);
+ if (proxy)
+ g_object_unref(proxy);
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_discover_service_uuids(char *address, char *remote_uuid)
+{
+ char *object_path;
+ GDBusProxy *proxy;
+ GDBusConnection *gconn;
+ GError *err = NULL;
+ char **uuid_value = NULL;
+ gsize size = 0;
+ int i = 0;
+ GVariant *value = NULL;
+ GVariant *ret = NULL;
+ int result = BLUETOOTH_ERROR_INTERNAL;
+ BT_INFO("+");
+ retv_if(remote_uuid == NULL, BLUETOOTH_ERROR_INTERNAL);
+ gconn = __get_gdbus_connection();
+ 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,
+ BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL,
+ &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, "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;
+ } else {
+ g_variant_get(ret, "(v)", &value);
+ uuid_value = (char **)g_variant_get_strv(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 (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;
+ }
+ }
+ }
+
+done:
+ if (proxy)
+ g_object_unref(proxy);
+ if (uuid_value)
+ g_free(uuid_value);
+
+ if (value)
+ g_variant_unref(value);
+
+ if (ret)
+ g_variant_unref(ret);
+
+ BT_DBG("-");
+ return result;
+}
+
+int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class)
+{
+ char *object_path;
+ GDBusProxy *proxy;
+ GDBusConnection *gconn;
+ GError *err = NULL;
+ GVariant *value = NULL;
+ GVariant *result = NULL;
+ unsigned int class = 0x00;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ gconn = __get_gdbus_connection();
+ 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,
+ BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL,
+ &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, "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;
+ } else {
+ g_variant_get(result, "(v)", &value);
+ class = g_variant_get_uint32(value);
+ _bt_divide_device_class(dev_class, class);
+ g_variant_unref(value);
+ g_variant_unref(result);
}
- if (path)
- g_strlcpy(path, adapter_path, BT_ADAPTER_OBJECT_PATH_MAX);
done:
- g_free(adapter_path);
- g_object_unref(manager_proxy);
+ g_free(object_path);
+ if (proxy)
+ g_object_unref(proxy);
+ BT_DBG("-");
return ret;
}
-DBusGProxy *_bt_get_adapter_proxy(DBusGConnection *conn)
+int _bt_disconnect_profile(char *address, char *uuid, void *cb,
+ gpointer func_data)
{
+ GDBusProxy *proxy;
+ char *object_path;
GError *err = NULL;
- DBusGProxy *manager_proxy = NULL;
- DBusGProxy *adapter_proxy = NULL;
+ GDBusProxy *adapter_proxy;
+ object_path = _bt_get_device_object_path(address);
+ if (object_path == NULL) {
+ GVariant *ret = NULL;
+ BT_ERR("No searched device");
+ adapter_proxy = __bt_gdbus_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
+ if (err != NULL) {
+ BT_ERR("CreateDevice Failed: %s", err->message);
+ g_error_free(err);
+ }
+ if (ret)
+ g_variant_unref(ret);
+ g_object_unref(adapter_proxy);
+ 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, "DisconnectProfile",
+ g_variant_new("(s)", uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ (GAsyncReadyCallback)cb,
+ func_data);
+ BT_DBG("-");
+ 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;
+ GDBusProxy *manager_proxy = NULL;
+ GVariant *result = NULL;
char *adapter_path = NULL;
- retv_if(conn == NULL, NULL);
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- manager_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- BT_MANAGER_PATH, BT_MANAGER_INTERFACE);
+ manager_proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME,
+ BT_MANAGER_PATH,
+ BT_MANAGER_INTERFACE,
+ NULL, &err);
- retv_if(manager_proxy == NULL, NULL);
+ if (!manager_proxy) {
+ BT_ERR("Unable to create proxy: %s", err->message);
+ goto fail;
+ }
- if (!dbus_g_proxy_call(manager_proxy, "DefaultAdapter", &err,
- G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH,
- &adapter_path,
- G_TYPE_INVALID)) {
+ result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (!result) {
if (err != NULL) {
- BT_ERR("Getting DefaultAdapter failed: [%s]\n", err->message);
- g_error_free(err);
+ if (!g_strrstr(err->message, "ServiceUnknown"))
+ BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
+ } else {
+ BT_ERR("Fail to get DefaultAdapter");
}
- g_object_unref(manager_proxy);
- return NULL;
+
+ goto fail;
}
- if (adapter_path == NULL || strlen(adapter_path) >= BT_ADAPTER_OBJECT_PATH_MAX) {
+ if (g_strcmp0(g_variant_get_type_string(result), "(o)")) {
+ BT_ERR("Incorrect result\n");
+ goto fail;
+ }
+
+ g_variant_get(result, "(&o)", &adapter_path);
+
+ if (adapter_path == NULL ||
+ strlen(adapter_path) >= BT_ADAPTER_OBJECT_PATH_MAX) {
BT_ERR("Adapter path is inproper\n");
- g_free(adapter_path);
- g_object_unref(manager_proxy);
- return NULL;
+ goto fail;
}
- adapter_proxy = dbus_g_proxy_new_for_name(conn,
- BT_BLUEZ_NAME,
- adapter_path,
- BT_ADAPTER_INTERFACE);
- g_free(adapter_path);
+ if (path)
+ g_strlcpy(path, adapter_path, BT_ADAPTER_OBJECT_PATH_MAX);
+
+ g_variant_unref(result);
g_object_unref(manager_proxy);
- return adapter_proxy;
+ return BLUETOOTH_ERROR_NONE;
+
+fail:
+ g_clear_error(&err);
+
+ if (result)
+ g_variant_unref(result);
+
+ if (manager_proxy)
+ g_object_unref(manager_proxy);
+
+ return BLUETOOTH_ERROR_INTERNAL;
+
+}
+
+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_device_path_to_address(const char *device_path, char *device_address)
+void _bt_convert_device_path_to_address(const char *device_path,
+ char *device_address)
{
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *dev_addr = NULL;
+ char *dev_addr;
- if (!device_path || !device_address)
- return;
+ ret_if(device_path == NULL);
+ ret_if(device_address == NULL);
dev_addr = strstr(device_path, "dev_");
if (dev_addr != 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);
}
}
-DBusGConnection *__bt_init_system_gconn(void)
+static char *__bt_extract_device_path(GVariantIter *iter, char *address)
{
- g_type_init();
+ char *object_path = NULL;
+ char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ /* Parse the signature: oa{sa{sv}}} */
+ while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
+ NULL)) {
+ retv_if(object_path == NULL, NULL);
+ _bt_convert_device_path_to_address(object_path, device_address);
+
+ if (g_strcmp0(address, device_address) == 0)
+ return g_strdup(object_path);
+ }
+ return NULL;
+}
+
+char *_bt_get_device_object_path(char *address)
+{
+ GError *err = NULL;
+ GDBusProxy *proxy = NULL;
+ GVariant *result = NULL;
+ GVariantIter *iter = NULL;
+ GDBusConnection *conn = NULL;
+ char *object_path = NULL;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, NULL);
+
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME,
+ BT_MANAGER_PATH,
+ BT_MANAGER_INTERFACE,
+ NULL, &err);
+
+ if (!proxy) {
+ BT_ERR("Unable to create proxy: %s", err->message);
+ goto fail;
+ }
+
+ result = g_dbus_proxy_call_sync(proxy, "GetManagedObjects", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (!result) {
+ if (err != NULL)
+ BT_ERR("Fail to get GetManagedObjects (Error: %s)", err->message);
+ else
+ BT_ERR("Fail to get GetManagedObjects");
+
+ goto fail;
+ }
+
+ g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
+ object_path = __bt_extract_device_path(iter, address);
+
+ g_variant_unref(result);
+ g_object_unref(proxy);
+ g_variant_iter_free(iter);
+ return object_path;
+
+fail:
+ g_clear_error(&err);
- if (system_conn == NULL)
- system_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (proxy)
+ g_object_unref(proxy);
- return system_conn;
+ return object_path;
}
-DBusGConnection *_bt_get_system_gconn(void)
+GDBusConnection *_bt_init_system_gdbus_conn(void)
{
- return (system_conn) ? system_conn : __bt_init_system_gconn();
+ 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;
}
-DBusConnection *_bt_get_system_conn(void)
+
+int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
{
- DBusGConnection *g_conn;
+ int ret;
+ char uuid_str[BLUETOOTH_UUID_STRING_MAX] = { 0, };
+ char path_str[BLUETOOTH_PATH_STRING] = { 0, };
- if (system_conn == NULL) {
- g_conn = __bt_init_system_gconn();
- } else {
- g_conn = system_conn;
- }
+ BT_DBG("+");
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ g_array_append_vals(in_param1, &type, sizeof(int));
+ g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
+ g_array_append_vals(in_param2, &uuid_str, BLUETOOTH_UUID_STRING_MAX);
+ g_strlcpy(path_str, path, sizeof(path_str));
+ g_array_append_vals(in_param3, &path_str, BLUETOOTH_PATH_STRING);
+ g_array_append_vals(in_param4, &fd, sizeof(int));
+
+ ret = _bt_send_request(BT_AGENT_SERVICE, BT_SET_AUTHORIZATION,
+ 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("-");
+ return ret;
+}
+
+int _bt_unregister_osp_server_in_agent(int type, char *uuid)
+{
+ int ret;
+ char uuid_str[BLUETOOTH_UUID_STRING_MAX] = { 0, };
+
+ BT_DBG("+");
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+ g_array_append_vals(in_param1, &type, sizeof(int));
+ g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
+ g_array_append_vals(in_param2, &uuid_str, BLUETOOTH_UUID_STRING_MAX);
+
+ ret = _bt_send_request(BT_AGENT_SERVICE, BT_UNSET_AUTHORIZATION,
+ 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("-");
+ return ret;
+}
+
+int _bt_check_privilege(int service_type, int service_function)
+{
+ int result;
+
+ BT_CHECK_ENABLED(return);
+
+ BT_INIT_PARAMS();
+ BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+ 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);
+
+ return result;
+}
+
+GVariant *_bt_get_managed_objects(void)
+{
+ GDBusConnection *g_conn;
+ GDBusProxy *manager_proxy = NULL;
+ GVariant *result = NULL;
+ GError *error = NULL;
+
+ BT_DBG("+");
+
+ g_conn = _bt_gdbus_get_system_gconn();
retv_if(g_conn == NULL, NULL);
- return dbus_g_connection_get_connection(g_conn);
+ manager_proxy = g_dbus_proxy_new_sync(g_conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME,
+ BT_MANAGER_PATH,
+ BT_MANAGER_INTERFACE,
+ NULL, &error);
+
+ 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,
+ NULL, &error);
+
+ if (error) {
+ BT_ERR("Fail to get ManagedObjects (Error: %s)", error->message);
+ g_clear_error(&error);
+ }
+
+ g_object_unref(manager_proxy);
+
+ BT_DBG("-");
+ return result;
+}
+
+gboolean _bt_check_enabled_internal(void)
+{
+ if (bt_enabled == TRUE)
+ return TRUE;
+
+ if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_ENABLED)
+ bt_enabled = TRUE;
+
+ return bt_enabled;
+}
+
+void _bt_set_adapter_internal_status(gboolean enabled)
+{
+ bt_enabled = enabled;
+}
+
+BT_EXPORT_API int bluetooth_get_uuid_name(const char *uuid, char **name)
+{
+#define SHORT_UUID_COUNT 162
+#define LONG_UUID_COUNT 17
+
+ 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;
+ int start = 0;
+ int end = SHORT_UUID_COUNT - 1;
+ int p;
+ int ret;
+
+ if (!uuid || !name)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ 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) {
+ *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)
fd = open(RFKILL_NODE, O_RDONLY);
if (fd < 0) {
- BT_DBG("Fail to open RFKILL node");
+ BT_ERR("Fail to open RFKILL node");
return BLUETOOTH_ERROR_INTERNAL;
}
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
- BT_DBG("Fail to set RFKILL node to non-blocking");
+ BT_ERR("Fail to set RFKILL node to non-blocking");
close(fd);
return BLUETOOTH_ERROR_INTERNAL;
}
while (1) {
len = read(fd, &event, sizeof(event));
if (len < 0) {
- BT_DBG("Fail to read events");
+ BT_ERR("Fail to read events");
break;
}
if (len != RFKILL_EVENT_SIZE) {
- BT_DBG("The size is wrong\n");
+ BT_ERR("The size is wrong\n");
continue;
}
{
int ret;
- __bt_init_system_gconn();
+ _bt_gdbus_init_system_gconn();
ret = _bt_init_event_handler();
-
if (ret != BLUETOOTH_ERROR_NONE &&
ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
BT_ERR("Fail to init the event handler");
return ret;
}
+
_bt_set_user_data(BT_COMMON, (void *)callback_ptr, user_data);
/* Register All events */
- _bt_register_event(BT_ADAPTER_EVENT, (void *)callback_ptr, user_data);
- _bt_register_event(BT_DEVICE_EVENT, (void *)callback_ptr, user_data);
- _bt_register_event(BT_NETWORK_EVENT, (void *)callback_ptr, user_data);
- _bt_register_event(BT_RFCOMM_CLIENT_EVENT, (void *)callback_ptr, user_data);
- _bt_register_event(BT_RFCOMM_SERVER_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
+ ret = _bt_register_event(BT_ADAPTER_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
+ ret = _bt_register_event(BT_DEVICE_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
+ ret = _bt_register_event(BT_NETWORK_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
+ ret = _bt_register_event(BT_RFCOMM_CLIENT_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
+ ret = _bt_register_event(BT_RFCOMM_SERVER_EVENT, (void *)callback_ptr, user_data);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ goto fail;
+
+#ifdef GATT_NO_RELAY
+ ret = _bt_register_event(BT_GATT_BLUEZ_EVENT, (void *)callback_ptr, user_data);
+ 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();
return BLUETOOTH_ERROR_NONE;
+fail:
+ BT_ERR("Fail to do _bt_register_event()");
+ bluetooth_unregister_callback();
+ return ret;
}
BT_EXPORT_API int bluetooth_unregister_callback(void)
{
- _bt_unregister_event(BT_ADAPTER_EVENT);
- _bt_unregister_event(BT_DEVICE_EVENT);
- _bt_unregister_event(BT_NETWORK_EVENT);
- _bt_unregister_event(BT_RFCOMM_CLIENT_EVENT);
- _bt_unregister_event(BT_RFCOMM_SERVER_EVENT);
+ int ret;
+
+
+ ret = _bt_deinit_event_handler();
+ if (ret != BLUETOOTH_ERROR_NONE)
+ BT_ERR("Fail to deinit the event handler");
+
+ _bt_unregister_name_owner_changed();
_bt_set_user_data(BT_COMMON, NULL, NULL);
- if (system_conn) {
- dbus_g_connection_unref(system_conn);
- system_conn = NULL;
+ _bt_set_obex_server_id(BT_NO_SERVER);
+
+ _bt_gdbus_deinit_proxys();
+
+ if (system_gconn) {
+ g_object_unref(system_gconn);
+ system_gconn = NULL;
}
return BLUETOOTH_ERROR_NONE;