[Adaprt: OAL] Implement create and remove bond 92/78492/1
authorAnupam Roy <anupam.r@samsung.com>
Tue, 5 Jul 2016 16:11:53 +0000 (12:11 -0400)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 5 Jul 2016 16:38:01 +0000 (12:38 -0400)
Change-Id: I3766a1516b9f7f0989d22e51382c181437f51fed
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h
bt-oal/include/oal-device-mgr.h
bt-oal/oal-adapter-mgr.c
bt-oal/oal-device-mgr.c

index 043ff5f..a412b27 100644 (file)
@@ -164,7 +164,7 @@ static int cancel_discovery(void)
 static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
 {
        DBG("+");
-       return _bt_hal_device_create_bond(bd_addr);
+       return _bt_hal_device_create_bond(bd_addr, transport);
 }
 
 static int cancel_bond(const bt_bdaddr_t *bd_addr)
index dc81b70..81199f5 100644 (file)
@@ -55,11 +55,10 @@ static void __bt_hal_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, gpoint
 static void __bt_hal_unbond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                                         gpointer user_data);
 
-int _bt_hal_device_create_bond(const bt_bdaddr_t *bd_addr)
+int _bt_hal_device_create_bond(const bt_bdaddr_t *bd_addr, unsigned short transport)
 {
        GDBusProxy *proxy;
        char address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
-       int transport = 0;
 
        GDBusConnection *conn;
        char *device_path = NULL;
@@ -69,7 +68,7 @@ int _bt_hal_device_create_bond(const bt_bdaddr_t *bd_addr)
        memset(&ev, 0, sizeof(ev));
        DBG("+");
 
-       DBG("Transport [%d] Add[0x%x] [0x%x][0x%x][0x%x][0x%x][0x%x]",
+       DBG("Transport [0x%x] Add[0x%x] [0x%x][0x%x][0x%x][0x%x][0x%x]",
                        transport, bd_addr->address[0], bd_addr->address[1],
                        bd_addr->address[2], bd_addr->address[3],
                        bd_addr->address[4], bd_addr->address[5]);
index 28a0543..8cfcc83 100644 (file)
@@ -36,7 +36,7 @@
 extern "C" {
 #endif
 
-int _bt_hal_device_create_bond(const bt_bdaddr_t *bd_addr);
+int _bt_hal_device_create_bond(const bt_bdaddr_t *bd_addr, unsigned short transport);
 
 int _bt_hal_device_remove_bond(const bt_bdaddr_t *bd_addr);
 
index 63662da..62f4906 100755 (executable)
@@ -30,6 +30,18 @@ extern "C" {
 #endif
 
 /**
+ * @brief Connection type
+ *
+ * @see  device_create_bond
+ */
+
+typedef enum {
+        CONN_TYPE_DEFAULT = 0xFF, /* represents that connection type can both BR/EDR and LE */
+        CONN_TYPE_BREDR = 0x00,
+        CONN_TYPE_LE = 0x01,
+} connection_type_e;
+
+/**
  * @brief Request remote device attributes
  *
  * @details Attibutes such as name, vidpid, bond state etc are requested. remote_device_t is provided
@@ -58,6 +70,56 @@ oal_status_t device_query_attributes(bt_address_t * addr);
 oal_status_t device_set_alias(bt_address_t * addr, char * alias);
 
 
+/**
+ * @brief Initiate bonding with remote device
+ *
+ * @details Based on IO capabilties of 2 devices, different events can be generated
+ *
+ * @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_PIN_REQUEST
+ * @see  OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST
+ * @see  OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST
+ * @see  OAL_EVENT_DEVICE_PASSKEY_DISPLAY
+ * @see  OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST
+ * @see  OAL_EVENT_DEVICE_BONDING_SUCCESS
+ * @see  OAL_EVENT_DEVICE_BONDING_FAILED
+ */
+oal_status_t device_create_bond(bt_address_t * addr, connection_type_e transport);
+
+/**
+ * @brief Cancel already in-progress bonding procedure
+ *
+ * @details Based on current progress different events can be recieved.
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS  Successful
+ *
+ * @pre Bonding must be in progress by calling device_create_bond()
+ *
+ * @see  OAL_EVENT_DEVICE_BONDING_SUCCESS
+ * @see  OAL_EVENT_DEVICE_BONDING_FAILED
+ * @see  OAL_EVENT_DEVICE_BONDING_REMOVED
+ */
+oal_status_t device_stop_bond(bt_address_t * addr);
+
+
+/**
+ * @brief Remove the already created Bond with remote device
+ *
+ * @details Based on current progress different events can be recieved.
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS  Successful
+ *
+ * @pre Bond should exist
+ *
+ * @see  OAL_EVENT_DEVICE_BONDING_REMOVED
+ */
+oal_status_t device_destroy_bond(bt_address_t * addr);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 8a4f8fd..0015e58 100755 (executable)
@@ -57,6 +57,8 @@ 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);
+extern void cb_device_bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
+                                        bt_bond_state_t state);
 
 static bt_callbacks_t callbacks = {
        sizeof(callbacks),
@@ -67,7 +69,7 @@ static bt_callbacks_t callbacks = {
        cb_adapter_discovery_state_changed,
        NULL, /* pin_request_callback */
        NULL, /* ssp_request_callback */
-       NULL, /* bond_state_changed_callback */
+       cb_device_bond_state_changed,
        NULL, /* acl_state_changed_callback */
        NULL, /* callback_thread_event */
        NULL, /* dut_mode_recv_callback */
index ac9135b..54c910c 100755 (executable)
@@ -28,6 +28,7 @@
 #include "oal-common.h"
 #include "oal-manager.h"
 #include "oal-utils.h"
+#include "oal-device-mgr.h"
 
 static const bt_interface_t * blued_api;
 
@@ -87,6 +88,46 @@ oal_status_t device_set_alias(bt_address_t * addr, char * alias)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t device_create_bond(bt_address_t *addr, connection_type_e transport)
+{
+       int res;
+       bdstr_t bdstr;
+
+       CHECK_OAL_INITIALIZED();
+
+       OAL_CHECK_PARAMETER(addr, return);
+
+       API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
+
+       res = blued_api->create_bond((bt_bdaddr_t *)addr, (unsigned char)transport);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("create_bond error: [%s]", status2string(res));
+               return convert_to_oal_status(res);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t device_destroy_bond(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->remove_bond((bt_bdaddr_t *)addr);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("remove_bond 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)
 {
@@ -165,3 +206,42 @@ void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
 
        send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);
 }
+
+void cb_device_bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
+                                        bt_bond_state_t state)
+{
+       bt_address_t * address = g_new0(bt_address_t, 1);
+       oal_event_t event;
+       gsize size = 0;
+
+       BT_DBG("status: %d, state: %d", status, state);
+
+       memcpy(address->addr, bd_addr->address, 6);
+
+       switch(state) {
+               case BT_BOND_STATE_BONDED:
+                       event = OAL_EVENT_DEVICE_BONDING_SUCCESS;
+                       break;
+               case BT_BOND_STATE_NONE:
+                       /* Reaches both when bonding removed or bonding cancelled */
+                       if (BT_STATUS_SUCCESS != status) {
+                               event_dev_bond_failed_t * bond_fail_info = g_new0(event_dev_bond_failed_t, 1);
+                               bond_fail_info->status = convert_to_oal_status(status);
+                               bond_fail_info->address = *address;
+                               size = sizeof(event_dev_bond_failed_t);
+                               send_event_bda_trace(OAL_EVENT_DEVICE_BONDING_FAILED, bond_fail_info, size, (bt_address_t*)bd_addr);
+                               g_free(address);
+                               return;
+                       } else
+                               event = OAL_EVENT_DEVICE_BONDING_REMOVED;
+                       break;
+               case BT_BOND_STATE_BONDING:
+                       g_free(address);
+                       return;
+               default:
+                       BT_ERR("Unexpected Bond state %d", state);
+                       g_free(address);
+                       return;
+       }
+       send_event_bda_trace(event, address, size, (bt_address_t*)bd_addr);
+}