return result;
}
+int _bt_adapter_get_bonded_devices(void)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+
+ BT_DBG("+");
+ result = adapter_get_bonded_devices();
+ if (result != OAL_STATUS_SUCCESS) {
+ BT_ERR("adapter_get_bonded_devices failed: %d", result);
+ result = BLUETOOTH_ERROR_INTERNAL;
+ } else
+ result = BLUETOOTH_ERROR_NONE;
+
+ BT_DBG("-");
+ return result;
+}
+
static void __bt_adapter_event_handler(int event_type, gpointer event_data)
{
- BT_DBG("+");
+ BT_DBG("+");
switch(event_type) {
case OAL_EVENT_OAL_INITIALISED_SUCCESS:
case OAL_EVENT_ADAPTER_INQUIRY_STARTED:
__bt_adapter_discovery_state_change_callback(ADAPTER_DISCOVERY_STARTED);
break;
- case OAL_EVENT_ADAPTER_INQUIRY_FINISHED:
- __bt_adapter_discovery_state_change_callback(ADAPTER_DISCOVERY_STOPPED);
+ case OAL_EVENT_ADAPTER_INQUIRY_FINISHED:
+ __bt_adapter_discovery_state_change_callback(ADAPTER_DISCOVERY_STOPPED);
break;
case OAL_EVENT_ADAPTER_PROPERTY_ADDRESS: {
bt_address_t *bd_addr = event_data;
gboolean connectable = FALSE;
BT_INFO("Adapter discoverable mode:"
- " BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE");
+ " BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE");
_bt_send_event(BT_ADAPTER_EVENT,
BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
g_variant_new("(b)", connectable));
gboolean connectable = TRUE;
BT_INFO("Adapter discoverable mode:"
- " BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE");
+ " BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE");
_bt_send_event(BT_ADAPTER_EVENT,
BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
g_variant_new("(b)", connectable));
}
case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE: {
BT_INFO("Adapter discoverable mode:"
- " BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE");
+ " BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE");
break;
}
case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT: {
__bt_adapter_handle_pending_requests(BT_IS_SERVICE_USED, service_list, count);
break;
}
+ case OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST: {
+ int i;
+ int count;
+ bluetooth_device_address_t *addr_list;
+
+ event_device_list_t *bonded_device_list = event_data;
+ count = bonded_device_list->num;
+
+ addr_list = g_malloc0(count * sizeof(bluetooth_device_address_t));
+ for (i = 0; i < count; i++) {
+ memcpy(addr_list[i].addr,
+ bonded_device_list->devices[i].addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+ }
+
+ __bt_adapter_handle_pending_requests(BT_GET_BONDED_DEVICES,
+ (void *)addr_list, bonded_device_list->num);
+ break;
+ }
default:
BT_ERR("Unhandled event..");
break;
g_array_append_vals(out_param, &used, sizeof(gboolean));
break;
}
+ case BT_GET_BONDED_DEVICES: {
+ bluetooth_device_address_t *addr_list = user_data;
+ bonded_devices_req_info_t *bonded_devices_req_info;
+ char address[BT_ADDRESS_STRING_SIZE];
+ int count = size;
+ int res = BLUETOOTH_ERROR_NONE;
+
+ /*
+ * BT_GET_BONDED_DEVICES is already processed for this request,
+ * continue for next BT_GET_BONDED_DEVICES request if any
+ */
+ if (NULL != req_info->user_data)
+ continue;
+
+ BT_DBG("BT_GET_BONDED_DEVICES: count = [%d]", count);
+ /* No bonded devices, return method invocation */
+ if (0 == count || !addr_list)
+ break;
+
+ /* Save address list in user data for futur reference. */
+ bonded_devices_req_info = g_malloc0(sizeof(bonded_devices_req_info));
+ if (!bonded_devices_req_info) {
+ BT_ERR("Memory allocation failed");
+ req_info->result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+ g_free(addr_list);
+ break;
+ }
+
+ bonded_devices_req_info->count = count;
+ bonded_devices_req_info->addr_list = addr_list;
+ bonded_devices_req_info->out_param = out_param;
+ req_info->user_data = bonded_devices_req_info;
+
+ while (bonded_devices_req_info->count > 0) {
+ bonded_devices_req_info->count -= 1;
+ res = _bt_device_get_bonded_device_info(
+ &addr_list[bonded_devices_req_info->count]);
+ if (BLUETOOTH_ERROR_NONE == res)
+ return;
+ else {
+ _bt_convert_addr_type_to_string((char *)address,
+ addr_list[bonded_devices_req_info->count].addr);
+ BT_ERR("_bt_device_get_bonded_device_info Failed for [%s]", address);
+ if (bonded_devices_req_info->count == 0) {
+ g_free(bonded_devices_req_info->addr_list);
+ g_free(bonded_devices_req_info);
+ req_info->user_data = NULL;
+ }
+ }
+ }
+ break;
+ }
default:
BT_ERR("Unknown service function[%d]", service_function);
}
#include "bt-service-util.h"
#include "bt-service-core-adapter.h"
+#include "bt-service-core-device.h"
/* For maintaining Application Sync API call requests */
GSList *invocation_list = NULL;
break;
}
case BT_CANCEL_DISCOVERY:
- result = _bt_cancel_discovery();
- break;
+ result = _bt_cancel_discovery();
+ break;
case BT_IS_DISCOVERYING: {
- gboolean discovering = FALSE;
- discovering = _bt_is_discovering();
- g_array_append_vals(*out_param1,
- &discovering, sizeof(gboolean));
- break;
- }
+ gboolean discovering = FALSE;
+ discovering = _bt_is_discovering();
+ g_array_append_vals(*out_param1,
+ &discovering, sizeof(gboolean));
+ break;
+ }
case BT_GET_LOCAL_ADDRESS: {
result = _bt_get_local_address();
}
break;
}
+ case BT_GET_BONDED_DEVICES: {
+ result = _bt_adapter_get_bonded_devices();
+ /* Save invocation */
+ if (result == BLUETOOTH_ERROR_NONE) {
+ sender = (char*)g_dbus_method_invocation_get_sender(context);
+ _bt_save_invocation_context(context, result, sender,
+ function_name, NULL);
+ }
+ break;
+ }
+ case BT_GET_BONDED_DEVICE: {
+ bluetooth_device_address_t address = { {0} };
+
+ __bt_service_get_parameters(in_param1,
+ &address, sizeof(bluetooth_device_address_t));
+
+ result = _bt_device_get_bonded_device_info(&address);
+ /* Save invocation */
+ if (result == BLUETOOTH_ERROR_NONE) {
+ char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
+ if (!addr) {
+ result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+ break;
+ }
+
+ _bt_convert_addr_type_to_string(addr, address.addr);
+ sender = (char*)g_dbus_method_invocation_get_sender(context);
+ _bt_save_invocation_context(context, result, sender,
+ function_name, addr);
+ }
+ break;
+ }
default:
BT_INFO("UnSupported function [%d]", function_name);
result = BLUETOOTH_ERROR_NOT_SUPPORT;
void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
{
- BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", addr->addr[0], addr->addr[1], addr->addr[2],
- addr->addr[3], addr->addr[4], addr->addr[5]);
+ BT_INFO("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
+ addr->addr[0], addr->addr[1], addr->addr[2],
+ addr->addr[3], addr->addr[4], addr->addr[5]);
}
void _bt_divide_device_class(bluetooth_device_class_t *device_class,
BT_INFO("-");
}
+static void __bt_get_service_list(bt_remote_dev_info_t *info, bluetooth_device_info_t *dev)
+{
+ int i;
+ char **uuids;
+ char **parts;
+
+ BT_DBG("+");
+
+ ret_if(info == NULL);
+ ret_if(dev == NULL);
+
+ uuids = info->uuids;
+ if(uuids == NULL) {
+ BT_ERR("No UUID's");
+ return;
+ }
+
+ dev->service_index = 0;
+ BT_DBG("Total UUID count [%d]", info->uuid_count);
+ for (i = 0; i < info->uuid_count; i++) {
+ BT_DBG("UUID count [%d]", i);
+ g_strlcpy(dev->uuids[i], uuids[i], BLUETOOTH_UUID_STRING_MAX);
+
+ parts = g_strsplit(uuids[i], "-", -1);
+
+ if (parts == NULL || parts[0] == NULL)
+ break;
+
+ dev->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
+ g_strfreev(parts);
+
+ dev->service_index++;
+ }
+
+ BT_DBG("-");
+}
+
+void _bt_copy_remote_device(bt_remote_dev_info_t *rem_dev, bluetooth_device_info_t *dev)
+{
+ BT_DBG("+");
+
+ memset(dev, 0x00, sizeof(bluetooth_device_info_t));
+ __bt_get_service_list(rem_dev, dev);
+ _bt_convert_addr_string_to_type(dev->device_address.addr, rem_dev->address);
+ _bt_divide_device_class(&dev->device_class, rem_dev->class);
+ g_strlcpy(dev->device_name.name, rem_dev->name,
+ BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
+ dev->rssi = rem_dev->rssi;
+ dev->trust = rem_dev->trust;
+ dev->paired = rem_dev->paired;
+ dev->connected = rem_dev->connected;
+
+ /* Fill Manufacturer data */
+ if (rem_dev->manufacturer_data_len > 0) {
+ dev->manufacturer_data.data_len = rem_dev->manufacturer_data_len;
+ memcpy(dev->manufacturer_data.data,
+ rem_dev->manufacturer_data, rem_dev->manufacturer_data_len);
+ } else {
+ dev->manufacturer_data.data_len = 0;
+ }
+ BT_DBG("-");
+}
+
+void _bt_service_print_dev_info(bluetooth_device_info_t *dev_info)
+{
+ int i;
+
+ ret_if(dev_info == NULL);
+
+ _bt_print_device_address_t(&(dev_info->device_address));
+ BT_INFO("Device Name:[%s]", dev_info->device_name.name);
+ BT_INFO("Device Major Class:[0x%X]", dev_info->device_class.major_class);
+ BT_INFO("Device Minor Class:[0x%X]", dev_info->device_class.minor_class);
+ BT_INFO("Device Service Class:[0x%X]", dev_info->device_class.minor_class);
+ BT_INFO("Device Paired:[%s]", (dev_info->paired?"TRUE":"FALSE"));
+ BT_INFO("Device Trusted:[%s]", (dev_info->trust?"TRUE":"FALSE"));
+ BT_INFO("Device Connected:[%d]", dev_info->connected);
+ BT_INFO("Device Service index:[%d]", dev_info->service_index);
+ for (i = 0; i < dev_info->service_index; i++) {
+ BT_INFO("Device Service List:[%d]", dev_info->service_list_array[i]);
+ BT_INFO("Device UUID:[%s]", dev_info->uuids[i]);
+ }
+
+ BT_INFO("Device manufacturer data len:[%d]", dev_info->manufacturer_data.data_len);
+ for (i = 0; i < dev_info->manufacturer_data.data_len; i++)
+ BT_INFO("%2.2X", dev_info->manufacturer_data.data[i]);
+}
+
void _bt_uuid_to_string(service_uuid_t *p_uuid, char *str)
{
uint32_t uuid0, uuid4;
case OAL_EVENT_ADAPTER_PROPERTY_NAME:
case OAL_EVENT_ADAPTER_PROPERTY_VERSION:
case OAL_EVENT_ADAPTER_PROPERTY_SERVICES:
+ case OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST:
case OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE:
case OAL_EVENT_ADAPTER_MODE_CONNECTABLE:
case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE:
case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT:
case OAL_EVENT_ADAPTER_INQUIRY_STARTED:
case OAL_EVENT_ADAPTER_INQUIRY_FINISHED:
- case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY:
- case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE:
if (adapter_cb)
adapter_cb(event_type, event_data);
+ break;
+ case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY:
+ case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE:
+ case OAL_EVENT_DEVICE_PROPERTIES:
if (device_cb)
device_cb(event_type, event_data);
break;
#include <oal-event.h>
#include <oal-manager.h>
#include <oal-adapter-mgr.h>
+#include <oal-device-mgr.h>
/* Forward declaration */
static void __bt_device_event_handler(int event_type, gpointer event_data);
BT_DEVICE_MODULE, __bt_device_event_handler);
}
+void __bt_device_handle_pending_requests(int result, int service_function,
+ void *user_data, unsigned int size)
+{
+ GSList *l;
+ GArray *out_param;
+ invocation_info_t *req_info = NULL;
+
+ BT_DBG("+");
+
+ /* Get method invocation context */
+ for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+ req_info = l->data;
+ if (req_info == NULL || req_info->service_function != service_function)
+ continue;
+
+ switch (service_function) {
+ case BT_GET_BONDED_DEVICE: {
+ char rem_addr[BT_ADDRESS_STRING_SIZE];
+ char *address = req_info->user_data;
+ bluetooth_device_info_t *dev_info = user_data;
+
+ ret_if(dev_info == NULL);
+
+ _bt_convert_addr_type_to_string(rem_addr, dev_info->device_address.addr);
+ if (strncasecmp(address, rem_addr, BT_ADDRESS_STRING_SIZE))
+ break;
+
+ out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+ g_array_append_vals(out_param, dev_info,
+ sizeof(bluetooth_device_info_t));
+
+ _bt_service_method_return(req_info->context, out_param, result);
+ _bt_free_info_from_invocation_list(req_info);
+ g_array_free(out_param, TRUE);
+ break;
+ }
+ case BT_GET_BONDED_DEVICES: {
+ char rem_addr[BT_ADDRESS_STRING_SIZE];
+ char req_addr[BT_ADDRESS_STRING_SIZE];
+ bluetooth_device_address_t *addr_list;
+ bluetooth_device_info_t *dev_info = user_data;
+ bonded_devices_req_info_t *list_info = req_info->user_data;
+
+ ret_if (list_info == NULL);
+ ret_if(dev_info == NULL);
+
+ addr_list = list_info->addr_list;
+ _bt_convert_addr_type_to_string(rem_addr, dev_info->device_address.addr);
+ _bt_convert_addr_type_to_string(req_addr, addr_list[list_info->count].addr);
+
+ BT_DBG("rem_addr: [%s]", rem_addr);
+ BT_DBG("req_addr: [%s]", req_addr);
+ if (strncasecmp(req_addr, rem_addr, BT_ADDRESS_STRING_SIZE))
+ break;
+
+ if (dev_info->paired == TRUE)
+ g_array_append_vals(list_info->out_param,
+ dev_info, sizeof(bluetooth_device_info_t));
+
+ if (list_info->count == 0) {
+ BT_DBG("Device info for all the paired devices is received");
+ /*
+ * Device info for all the paired devices is received,
+ * Send reply to get_bonded_devices request.
+ */
+ _bt_service_method_return(req_info->context,
+ list_info->out_param, req_info->result);
+
+ g_free(list_info->addr_list);
+ g_array_free(list_info->out_param, TRUE);
+ g_free(list_info);
+ req_info->user_data = NULL;
+ _bt_free_info_from_invocation_list(req_info);
+ break;
+ }
+
+ while (list_info->count > 0) {
+ BT_DBG("list_info->count: %d", list_info->count);
+ list_info->count -= 1;
+ result = _bt_device_get_bonded_device_info(&addr_list[list_info->count]);
+ if (BLUETOOTH_ERROR_NONE == result)
+ break;
+ else if (list_info->count == 0) {
+ BT_DBG("Send reply to get_bonded_devices request");
+ /* Send reply to get_bonded_devices request */
+ _bt_service_method_return(req_info->context,
+ list_info->out_param, req_info->result);
+
+ g_free(list_info->addr_list);
+ g_array_free(list_info->out_param, TRUE);
+ g_free(list_info);
+ req_info->user_data = NULL;
+ _bt_free_info_from_invocation_list(req_info);
+ }
+ }
+ break;
+ }
+ default:
+ BT_ERR("Unhandled case");
+ break;
+ }
+ }
+ BT_INFO("-");
+}
+
+/*
+ * Remote device properties are received on all following conditions
+ * a. When Bonding in on-going
+ * b. When device properties are updated\changed for a connected device
+ * (due to SDP or any other reason)
+ * c. When app requests for GET_BONDED_DEVICE\GET_BONDED_DEVICES info
+ */
+static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_dev_props)
+{
+ bluetooth_device_info_t dev_info;
+ bt_remote_dev_info_t *rem_info = NULL;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ BT_DBG("+");
+ rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
+ memset(rem_info, 0x00, sizeof(bt_remote_dev_info_t));
+ _bt_copy_remote_dev(rem_info, &(oal_dev_props->device_info));
+
+ if (oal_dev_props->adv_len > 0) {
+ int k;
+
+ rem_info->manufacturer_data_len = oal_dev_props->adv_len;
+ rem_info->manufacturer_data =
+ g_memdup(oal_dev_props->adv_data,
+ oal_dev_props->adv_len);
+ BT_DBG("----Advertising Data Length: %d",
+ rem_info->manufacturer_data_len);
+
+ for(k=0; k < rem_info->manufacturer_data_len; k++) {
+ BT_INFO("Check data[%d] = [[0x%x]",
+ k, oal_dev_props->adv_data[k]);
+ }
+ } else {
+ rem_info->manufacturer_data = NULL;
+ rem_info->manufacturer_data_len = 0;
+ }
+
+ _bt_copy_remote_device(rem_info, &dev_info);
+ _bt_service_print_dev_info(&dev_info);
+
+ /* Check if app has requested for device info for already bonded devices */
+ __bt_device_handle_pending_requests(result, BT_GET_BONDED_DEVICES,
+ (void *)&dev_info, sizeof(bluetooth_device_info_t));
+ __bt_device_handle_pending_requests(result, BT_GET_BONDED_DEVICE,
+ (void *)&dev_info, sizeof(bluetooth_device_info_t));
+
+ BT_DBG("-");
+}
+
static void __bt_device_event_handler(int event_type, gpointer event_data)
{
int eventcheck = OAL_EVENT_DEVICE_PROPERTIES;
BT_INFO("event [%d] Event check = [%d]", event_type, eventcheck);
- switch(event_type) {
- case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY:
- {
- BT_INFO("BREDR Device Found");
- __bt_device_remote_device_found_callback(event_data, FALSE);
- break;
- }
- case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE:
- {
- BT_INFO("Dual Device Found");
- __bt_device_remote_device_found_callback(event_data, FALSE);
- break;
- }
- default:
+ switch(event_type) {
+ case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY: {
+ BT_INFO("BREDR Device Found");
+ __bt_device_remote_device_found_callback(event_data, FALSE);
+ break;
+ }
+ case OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE: {
+ BT_INFO("Dual Device Found");
+ __bt_device_remote_device_found_callback(event_data, FALSE);
+ break;
+ }
+ case OAL_EVENT_DEVICE_PROPERTIES: {
+ BT_INFO("Remote Device properties Received");
+ __bt_device_remote_properties_callback((event_dev_properties_t *)event_data);
+ break;
+ }
+ default:
BT_INFO("Unhandled event..");
}
}
}
BT_DBG("-");
}
+
+int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr)
+{
+ int result;
+ bt_address_t bd_addr;
+
+ BT_DBG("+");
+
+ retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
+
+ memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
+ result = device_query_attributes(&bd_addr);
+ if (result != OAL_STATUS_SUCCESS) {
+ BT_ERR("device_query_attributes error: [%d]", result);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ BT_DBG("-");
+ return BLUETOOTH_ERROR_NONE;
+}
char *address;
} bt_function_data_t;
+typedef struct {
+ int count;
+ bluetooth_device_address_t *addr_list;
+ GArray *out_param;
+} bonded_devices_req_info_t;
+
GDBusConnection *_bt_get_system_conn(void);
GDBusConnection *_bt_get_system_gconn(void);
void _bt_truncate_non_utf8_chars(char * str);
+void _bt_copy_remote_device(bt_remote_dev_info_t *rem_dev, bluetooth_device_info_t *dev);
+
+void _bt_service_print_dev_info(bluetooth_device_info_t *dev_info);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
int _bt_set_connectable(gboolean connectable);
+int _bt_adapter_get_bonded_devices(void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
void _bt_device_state_handle_callback_set_request(void);
+int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */