[Adapt] Implement Cancel Bonding API 54/78854/1
authorAnupam Roy <anupam.r@samsung.com>
Thu, 7 Jul 2016 06:58:44 +0000 (02:58 -0400)
committerAnupam Roy <anupam.r@samsung.com>
Thu, 7 Jul 2016 06:58:44 +0000 (02:58 -0400)
This patch implements Cancel bonding
in bt-service, OAL and Bluez HAL

Change-Id: Ie63dcd195fc7cb09acd0dd58ef54758057543db4
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/bluez_hal/src/bt-hal-agent.c
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/oal-device-mgr.c
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/device/bt-service-core-device.c
bt-service-adaptation/services/include/bt-service-core-device.h

index 80f50de..34ad1e5 100644 (file)
@@ -166,8 +166,14 @@ int _bt_hal_agent_reply_cancellation(void)
        void *agent = _bt_hal_get_adapter_agent();
        if (!agent)
                return BT_STATUS_FAIL;
-       /* TODO Handle GAP Agent Cancel */
+
+       if (gap_agent_reply_confirmation(agent, GAP_AGENT_CANCEL, NULL) != TRUE) {
+               ERR("Fail to reply agent");
+               return BT_STATUS_FAIL;
+       }
+       DBG("gap agent cancellation done successfully!");
        return BT_STATUS_SUCCESS;
+
 }
 
 void _bt_hal_agent_set_canceled(gboolean value)
index cb6acb8..1f05da8 100644 (file)
@@ -173,7 +173,7 @@ static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
 
 static int cancel_bond(const bt_bdaddr_t *bd_addr)
 {
-       return BT_STATUS_UNSUPPORTED;
+       return _bt_hal_device_cancel_bond(bd_addr);
 }
 
 static int remove_bond(const bt_bdaddr_t *bd_addr)
index ae17c9d..fd1a486 100644 (file)
@@ -227,6 +227,21 @@ int _bt_hal_device_remove_bond(const bt_bdaddr_t *bd_addr)
        return BT_STATUS_SUCCESS;
 }
 
+int _bt_hal_device_cancel_bond(const bt_bdaddr_t *bd_addr)
+{
+       int result = BT_STATUS_SUCCESS;
+       DBG("+");
+
+       result = _bt_hal_agent_reply_cancellation();
+       if (result != BT_HAL_ERROR_NONE){
+               ERR("Fail to call reply cancellation");
+               return BT_STATUS_FAIL;
+       }
+
+       _bt_hal_agent_set_canceled(TRUE);
+       return result;
+}
+
 int _bt_hal_device_legacy_pin_reply(const bt_bdaddr_t *bd_addr,
                                 gboolean accept, uint8_t pin_len, char *pincode)
 {
index 87e7089..880e150 100644 (file)
@@ -40,6 +40,8 @@ int _bt_hal_device_create_bond(const bt_bdaddr_t *bd_addr, unsigned short transp
 
 int _bt_hal_device_remove_bond(const bt_bdaddr_t *bd_addr);
 
+int _bt_hal_device_cancel_bond(const bt_bdaddr_t *bd_addr);
+
 int _bt_hal_dbus_get_remote_device_properties(bt_bdaddr_t *remote_addr);
 
 int _bt_hal_dbus_set_remote_device_property(
index 4bce2e8..97919e4 100755 (executable)
@@ -128,6 +128,26 @@ oal_status_t device_destroy_bond(bt_address_t * addr)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t device_stop_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->cancel_bond((bt_bdaddr_t *)addr);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("cancel_bond error: [%s]", status2string(res));
+               return convert_to_oal_status(res);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t device_accept_pin_request(bt_address_t * addr, const char * pin)
 {
        int res;
index 6776f73..87f1618 100644 (file)
@@ -569,6 +569,10 @@ int __bt_bluez_request(int function_name,
                       }
                       break;
        }
+       case BT_CANCEL_BONDING:{
+                      result = _bt_cancel_bonding();
+                      break;
+       }
        case BT_PASSKEY_REPLY: {
                       const char *passkey = NULL;
                       gboolean authentication_reply = FALSE;
index e7451aa..23c7df7 100644 (file)
@@ -610,6 +610,7 @@ static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
                _bt_set_autopair_status_in_bonding_info(TRUE);
                device_accept_pin_request(&pin_req_event->address, "0000");
        } else if (_bt_agent_is_hid_keyboard(pin_req_event->cod)) {
+               BT_DBG("Remote Device is HID keyboard Type..");
                char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
 
                if (_bt_agent_generate_passkey(str_passkey,
@@ -1140,6 +1141,21 @@ fail:
        return result;
 }
 
+int _bt_cancel_bonding(void)
+{
+       int result = OAL_STATUS_SUCCESS;
+       BT_INFO("+");
+
+       retv_if(trigger_bond_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
+
+       result = device_stop_bond((bt_address_t *)trigger_bond_info->dev_addr);
+
+       if (result == OAL_STATUS_SUCCESS)
+               trigger_bond_info->is_cancelled_by_user = TRUE;
+
+       return result;
+}
+
 int _bt_passkey_reply(const char *passkey, gboolean cnfm_reply)
 {
        bluetooth_device_address_t device_address;
index 47138be..219f39b 100755 (executable)
@@ -38,6 +38,8 @@ int _bt_bond_device(bluetooth_device_address_t *device_address,
 int _bt_unbond_device(bluetooth_device_address_t *device_address,
                         GArray **out_param1);
 
+int _bt_cancel_bonding(void);
+
 gboolean _bt_is_bonding_device_address(const char *address);
 
 gboolean _bt_device_is_bonding(void);