[Adapt: OAL] Implement get_bonded device info APIs 19/78119/1
authorAtul Rai <a.rai@samsung.com>
Mon, 4 Jul 2016 10:01:37 +0000 (19:01 +0900)
committerAtul Rai <a.rai@samsung.com>
Mon, 4 Jul 2016 10:04:49 +0000 (19:04 +0900)
This patch adds OAL implementation to retrieve bonded device list
as well as bonded device info.

Change-Id: I02a9788589ca762820d1b0cfc3b2d42fcf9c86b6
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-oal/CMakeLists.txt
bt-oal/common/oal-common.c
bt-oal/common/oal-common.h
bt-oal/include/oal-adapter-mgr.h
bt-oal/include/oal-device-mgr.h [new file with mode: 0755]
bt-oal/include/oal-event.h
bt-oal/oal-adapter-mgr.c
bt-oal/oal-device-mgr.c [new file with mode: 0755]
bt-oal/oal-internal.h
bt-oal/oal-manager.c

index 8f589b2..be80e83 100755 (executable)
@@ -13,6 +13,7 @@ SET(SRCS
 oal-hardware.c
 oal-manager.c
 oal-adapter-mgr.c
+oal-device-mgr.c
 common/oal-utils.c
 common/oal-common.c
 common/oal-event-dispatcher.c
index 3090974..1b79c8b 100755 (executable)
@@ -36,9 +36,7 @@
 #define BT_UUID_LENGTH_MAX 16
 
 void parse_device_properties(int num_properties, bt_property_t *properties,
-               remote_device_t *dev_info,
-               ble_adv_data_t * adv_info,
-               gsize *size)
+               remote_device_t *dev_info, ble_adv_data_t * adv_info)
 {
        int i = 0;
        int uuid_count = 0, table_len = 0;
@@ -56,20 +54,19 @@ void parse_device_properties(int num_properties, bt_property_t *properties,
        for(i=0; i<num_properties; i++) {
                BT_DBG("===>Prop type: %d, Len: %d<===", properties[i].type, properties[i].len);
 
-               switch(properties[i].type)
-               {
+               switch (properties[i].type) {
                case BT_PROPERTY_BDADDR: {
                        addr = (bt_bdaddr_t *)properties[i].val;
                                memcpy(dev_info->address.addr, addr->address, 6);
-                       BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", dev_info->address.addr[0], dev_info->address.addr[1], dev_info->address.addr[2],
-                                       dev_info->address.addr[3], dev_info->address.addr[4], dev_info->address.addr[5]);
-                       *size += properties[i].len;
+                       BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
+                                       dev_info->address.addr[0], dev_info->address.addr[1],
+                                       dev_info->address.addr[2], dev_info->address.addr[3],
+                                       dev_info->address.addr[4], dev_info->address.addr[5]);
                        break;
                }
                case BT_PROPERTY_CLASS_OF_DEVICE: {
                        dev_info->cod = *((int *)properties[i].val);
                        BT_DBG("CLASS: 0x%06x", dev_info->cod);
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_BDNAME: {
@@ -77,7 +74,6 @@ void parse_device_properties(int num_properties, bt_property_t *properties,
 
                        g_strlcpy(dev_info->name, (const gchar *)name->name, BT_DEVICE_NAME_LENGTH_MAX);
                        BT_DBG("NAME: %s", dev_info->name);
-                       *size += properties[i].len;
                        break;
                }
                case  BT_PROPERTY_REMOTE_FRIENDLY_NAME: {
@@ -85,31 +81,26 @@ void parse_device_properties(int num_properties, bt_property_t *properties,
                        if (NULL != name && (0 != properties[i].len))
                                g_strlcpy(dev_info->name, (const gchar *)name->name, BT_DEVICE_NAME_LENGTH_MAX);
                        BT_DBG("FRIENDLY NAME: [%s]", dev_info->name);
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_REMOTE_PAIRED: {
                        dev_info->is_bonded = *((gboolean*)properties[i].val);
                        BT_DBG("BONDED [%d]", dev_info->is_bonded);
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_REMOTE_CONNECTED: {
                        dev_info->is_connected = *((int*)properties[i].val);
                        BT_DBG("CONNECTED [%d]", dev_info->is_connected);
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_REMOTE_TRUST: {
                        dev_info->is_trusted = *((gboolean*)properties[i].val);
                        BT_DBG("TRUSTED [%d]", dev_info->is_trusted);
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_REMOTE_RSSI: {
                        dev_info->rssi = *((int *)properties[i].val);
                        BT_DBG("RSSI: %d", dev_info->rssi);
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_UUIDS: {
@@ -118,15 +109,16 @@ void parse_device_properties(int num_properties, bt_property_t *properties,
                        table_len += uuid_count;
                        for(; tmp_uuid_cnt < table_len; tmp_uuid_cnt++) {
                                uuid_to_string(&uuids[tmp_uuid_cnt], lcl_uuid);
-                               chk = check_duplicate_uuid(dev_info->uuid, uuids[tmp_uuid_cnt], dev_info->uuid_count);
+                               chk = check_duplicate_uuid(dev_info->uuid,
+                                       uuids[tmp_uuid_cnt], dev_info->uuid_count);
                                if(chk != 0) {
-                                       memcpy(&dev_info->uuid[dev_info->uuid_count++].uuid[0], &uuids[tmp_uuid_cnt].uuid[0], 16);
+                                       memcpy(&dev_info->uuid[dev_info->uuid_count++].uuid,
+                                                       &uuids[tmp_uuid_cnt].uuid, 16);
                                } else {
                                        BT_DBG("Duplicate UUID found:%s\n", lcl_uuid);
                                }
                                BT_DBG("%d.BT_PROPERTY_UUIDS:%s", dev_info->uuid_count, lcl_uuid);
                        }
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_TYPE_OF_DEVICE: {
@@ -136,7 +128,6 @@ void parse_device_properties(int num_properties, bt_property_t *properties,
                        else if(dev_type == BT_DEVICE_DEVTYPE_DUAL)
                                BT_DBG("Dual mode BLE Device");
                        dev_info->type = dev_type - 1;//OAL enum starts with 0 and Bluedroid with 1
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_REMOTE_BLE_ADV_DATA: {
@@ -145,17 +136,14 @@ void parse_device_properties(int num_properties, bt_property_t *properties,
                                adv_info->len = properties[i].len;
                        }
                        BT_DBG("----Advertising Data Length: %d",properties[i].len);
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: {
                        BT_INFO("BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP: Not Handled!!");
-                       *size += properties[i].len;
                        break;
                }
                case BT_PROPERTY_SERVICE_RECORD: {
                        BT_INFO("BT_PROPERTY_SERVICE_RECORD: Not Handled!!");
-                       *size += properties[i].len;
                        break;
                }
                default:
@@ -165,7 +153,6 @@ void parse_device_properties(int num_properties, bt_property_t *properties,
        }
 }
 
-
 oal_status_t convert_to_oal_status(bt_status_t status)
 {
        oal_status_t ret = OAL_STATUS_INTERNAL_ERROR;
@@ -220,7 +207,7 @@ static const char * status_str[] = {
 int check_duplicate_uuid(oal_uuid_t *table, oal_uuid_t toMatch, int table_len)
 {
        int i;
-       int ret = 0;
+       int ret = 1;
 
        for (i = 0; i < table_len; i++) {
                ret = memcmp(table[i].uuid, toMatch.uuid, 16);
index 44ed70e..7fc0df0 100644 (file)
@@ -29,8 +29,7 @@
 extern "C" {
 #endif
 void parse_device_properties(int num_properties, bt_property_t *properties,
-                               remote_device_t *dev_info, ble_adv_data_t * adv_info,
-                               gsize *size);
+                               remote_device_t *dev_info, ble_adv_data_t * adv_info);
 oal_status_t convert_to_oal_status(bt_status_t status);
 
 const char * status2string(bt_status_t status);
index 27481f1..9063d3f 100755 (executable)
@@ -173,6 +173,20 @@ oal_status_t adapter_get_discoverable_timeout(int *p_timeout);
  */
 oal_status_t adapter_get_service_uuids(void);
 
+/**
+ * @brief Get list of bonded devices
+ *
+ * @remarks     A list of bt_address_t is provided in the event data.
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS  Successful
+ *
+ * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
+ *
+ * @see OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST
+ */
+oal_status_t adapter_get_bonded_devices(void);
+
 /*
  * @brief Set connectability of adapter
  *
diff --git a/bt-oal/include/oal-device-mgr.h b/bt-oal/include/oal-device-mgr.h
new file mode 100755 (executable)
index 0000000..22b4524
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+ *
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _OAL_DEVICE_MGR_H_
+#define _OAL_DEVICE_MGR_H_
+
+#include <glib.h>
+#include <sys/types.h>
+
+#include <oal-manager.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Request remote device attributes
+ *
+ * @details Attibutes such as name, vidpid, bond state etc are requested. remote_device_t is provided
+ *                with OAL_EVENT_DEVICE_PROPERTIES
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
+ *
+ * @see  OAL_EVENT_DEVICE_PROPERTIES
+ * @see  remote_device_t
+ */
+oal_status_t device_query_attributes(bt_address_t * addr);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_DEVICE_MGR_H_*/
+
index d84accc..e73a760 100755 (executable)
@@ -104,6 +104,11 @@ typedef struct {
        service_uuid_t service_list[0];
 } event_adapter_services_t;
 
+typedef struct {
+       remote_device_t device_info;
+       uint8_t adv_data[62];
+       int adv_len;
+} event_dev_properties_t;
 
 /*********Datastructures for Remote Device events ******************/
 typedef struct {
index c16515e..3b92102 100755 (executable)
@@ -55,12 +55,14 @@ static void cb_adapter_discovery_state_changed(bt_discovery_state_t state);
 static void cb_adapter_device_found(int num_properties, bt_property_t *properties);
 static void cb_adapter_properties (bt_status_t status,
                int num_properties, bt_property_t *properties);
+extern void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
+               int num_properties, bt_property_t *properties);
 
 static bt_callbacks_t callbacks = {
        sizeof(callbacks),
        cb_adapter_state_change,
        cb_adapter_properties,
-       NULL, /* remote_device_properties_callback */
+       cb_device_properties,
        cb_adapter_device_found,
        cb_adapter_discovery_state_changed,
        NULL, /* pin_request_callback */
@@ -311,6 +313,23 @@ oal_status_t adapter_get_service_uuids(void)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t adapter_get_bonded_devices(void)
+{
+       int ret;
+
+       CHECK_OAL_INITIALIZED();
+
+       API_TRACE();
+
+       ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 static oal_status_t set_scan_mode(bt_scan_mode_t mode)
 {
        bt_property_t prop;
@@ -509,7 +528,7 @@ static void cb_adapter_device_found(int num_properties, bt_property_t *propertie
        ble_adv_data_t adv_info;
        oal_event_t event;
        gpointer event_data;
-       gsize properties_size = 0;
+       gsize size = 0;
        BT_DBG("+");
 
        if (num_properties == 0) {
@@ -521,9 +540,9 @@ static void cb_adapter_device_found(int num_properties, bt_property_t *propertie
        memset(&adv_info, 0x00, sizeof(ble_adv_data_t));
 
        print_bt_properties(num_properties, properties);
-       parse_device_properties(num_properties, properties, &dev_info, &adv_info, &properties_size);
+       parse_device_properties(num_properties, properties, &dev_info, &adv_info);
 
-       BT_INFO("number of properties= [%d] total size [%u]", num_properties, properties_size);
+       BT_INFO("number of properties= [%d] ", num_properties, size);
 
        if (dev_info.type != DEV_TYPE_BREDR) {
                /* BLE Single or DUAL mode found, so it should have Adv data */
@@ -540,6 +559,7 @@ static void cb_adapter_device_found(int num_properties, bt_property_t *propertie
                ble_dev_event->device_info = dev_info;
 
                event_data = ble_dev_event;
+               size = sizeof(event_ble_dev_found_t);
                event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE;
        } else {
                /* BREDR device, so No Adv data */
@@ -547,10 +567,11 @@ static void cb_adapter_device_found(int num_properties, bt_property_t *propertie
 
                memcpy(dev_event, &dev_info, sizeof(remote_device_t));
                event_data = dev_event;
+               size = sizeof(remote_device_t);
                event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY;
        }
 
-       send_event(event, event_data, properties_size);
+       send_event(event, event_data, size);
 
        BT_DBG("-");
 }
diff --git a/bt-oal/oal-device-mgr.c b/bt-oal/oal-device-mgr.c
new file mode 100755 (executable)
index 0000000..84218e5
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+ *
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <dlog.h>
+#include <string.h>
+
+#include <bluetooth.h>
+
+#include "oal-event.h"
+#include "oal-internal.h"
+#include "oal-common.h"
+#include "oal-manager.h"
+#include "oal-utils.h"
+
+static const bt_interface_t * blued_api;
+
+void device_mgr_init(const bt_interface_t * stack_if)
+{
+       blued_api = stack_if;
+}
+
+void device_mgr_cleanup(void)
+{
+       BT_DBG();
+       blued_api = NULL;
+}
+
+oal_status_t device_query_attributes(bt_address_t *addr)
+{
+       int res;
+       bdstr_t bdstr;
+
+       CHECK_OAL_INITIALIZED();
+
+       OAL_CHECK_PARAMETER(addr, return);
+
+       API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
+
+       res = blued_api->get_remote_device_properties((bt_bdaddr_t *)addr);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("get_remote_device_properties error: [%s]", status2string(res));
+               return convert_to_oal_status(res);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
+void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
+               int num_properties, bt_property_t *properties)
+{
+       oal_event_t event;
+       gpointer event_data = NULL;
+       remote_device_t *dev_info;
+       ble_adv_data_t adv_info;
+       gsize size = 0;
+       bdstr_t bdstr;
+
+       if(BT_STATUS_SUCCESS != status) {
+               BT_ERR("[%s]status: %d", bdt_bd2str((bt_address_t*)bd_addr, &bdstr), status);
+               return;
+       }
+
+       BT_DBG("[%s]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
+       dev_info = g_new0(remote_device_t, 1);
+       memcpy(dev_info->address.addr, bd_addr->address, 6);
+       parse_device_properties(num_properties, properties, dev_info, &adv_info);
+
+       if(num_properties == 1) {
+               /* For one particular property a dedicated event to be sent */
+               switch(properties[0].type) {
+               case BT_PROPERTY_BDNAME:
+                       event = OAL_EVENT_DEVICE_NAME;
+                       event_data = dev_info;
+                       send_event_trace(event, event_data, sizeof(remote_device_t),
+                               (bt_address_t*)bd_addr, "Name: %s", dev_info->name);
+                       return;
+               case BT_PROPERTY_UUIDS: {
+                       event_dev_services_t *services_info;
+                       bt_uuid_t *uuids = (bt_uuid_t *) properties[0].val;
+
+                       services_info = g_malloc(sizeof(event_dev_services_t) + properties[0].len);
+                       services_info->address = dev_info->address;
+                       memcpy(services_info->service_list, uuids, properties[0].len);
+                       services_info->num = properties[0].len/sizeof(bt_uuid_t);
+                       event = OAL_EVENT_DEVICE_SERVICES;
+                       event_data = services_info;
+                       size = sizeof(event_dev_services_t) + properties[0].len;
+                       g_free(dev_info);
+                       break;
+               }
+               default:
+                       BT_ERR("Single Property [%d] not handled", properties[0].type);
+                       g_free(dev_info);
+                       return;
+               }
+       } else {
+               event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
+               if (dev_info->type != DEV_TYPE_BREDR) {
+                       int i;
+
+                       BT_INFO("BLE Device");
+                       /* BLE Single or DUAL mode found, so it should have Adv data */
+                       dev_props_event->adv_len = adv_info.len;
+                       if(dev_props_event->adv_len > 0)
+                               memcpy(dev_props_event->adv_data,
+                                       adv_info.adv_data, adv_info.len);
+
+                       for (i = 0; i < dev_props_event->adv_len; i++)
+                               BT_INFO("Adv Data[%d] = [0x%x]",
+                                       i, dev_props_event->adv_data[i]);
+                       memcpy(&dev_props_event->device_info,
+                               dev_info, sizeof(remote_device_t));
+               } else {
+                       BT_INFO("BREDR type Device");
+                       memcpy(&dev_props_event->device_info,
+                               dev_info, sizeof(remote_device_t));
+               }
+
+               event_data = dev_props_event;
+               event = OAL_EVENT_DEVICE_PROPERTIES;
+               size = sizeof(event_dev_properties_t);
+       }
+
+       send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);
+}
index eb1b637..eeb820b 100755 (executable)
@@ -115,12 +115,18 @@ typedef struct {
 void oal_mgr_cleanup(void);
 void oal_mgr_stack_reload(void);
 
+/* Device manager */
+void device_mgr_init(const bt_interface_t * stack_if);
+void device_mgr_cleanup(void);
+
 oal_status_t adapter_mgr_init(const bt_interface_t * stack_if);
 
 /* Event Manager */
 /* Use this when Address is to be printed */
 void send_event_bda_trace(oal_event_t event, gpointer event_data, gsize len, bt_address_t *address);
 
+void send_event_no_trace(oal_event_t event, gpointer event_data, gsize len);
+
 /* Use this when no address printing is required */
 #define _bt_dispatch_event send_event
 void send_event(oal_event_t event, gpointer event_data, gsize len);
index a4b5c5b..259e5f6 100755 (executable)
@@ -63,6 +63,8 @@ oal_status_t oal_mgr_init_internal(void)
                return OAL_STATUS_INTERNAL_ERROR;
        }
 
+       device_mgr_init(blued_api);
+
        return adapter_mgr_init(blued_api);
 }