Adapt device disconnect to BT HAL framework 28/215928/2
authorAmit Purwar <amit.purwar@samsung.com>
Thu, 17 Oct 2019 11:53:53 +0000 (17:23 +0530)
committerAmit Purwar <amit.purwar@samsung.com>
Fri, 18 Oct 2019 03:45:08 +0000 (09:15 +0530)
Change-Id: I6fdb276b120ae1f0a14b5e1c8c2dbb74fb720080
Signed-off-by: Amit Purwar <amit.purwar@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/hardware/bluetooth.h
bt-oal/include/oal-device-mgr.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 547a613..fa31d3d 100644 (file)
@@ -399,6 +399,12 @@ static int set_hal_le_request_state(int enable)
        _bt_hal_set_le_request_state(enable);
        return BT_STATUS_SUCCESS;
 }
+
+static int dev_disconnect(const bt_bdaddr_t *bd_addr)
+{
+       DBG("+");
+       return _bt_hal_device_disconnect(bd_addr);
+}
 #endif
 
 static const bt_interface_t bluetooth_if = {
@@ -463,6 +469,7 @@ static const bt_interface_t bluetooth_if = {
        .set_hal_le_request_state = set_hal_le_request_state,
        .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
        .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
+       .device_disconnect = dev_disconnect,
 #endif
 };
 
index 3ffb6a7..f659ad8 100644 (file)
@@ -1675,4 +1675,59 @@ int _bt_hal_device_get_connected_link_rssi_strength(const bt_bdaddr_t *bd_addr,
        DBG("-");
        return BT_STATUS_SUCCESS;
 }
+
+
+int _bt_hal_device_disconnect(const bt_bdaddr_t *bd_addr)
+{
+       GDBusProxy *proxy;
+       char address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+       GError *error = NULL;
+       GVariant *result = NULL;
+       GDBusConnection *conn;
+       char *device_path = NULL;
+       DBG("+");
+
+       conn = _bt_hal_get_system_gconn();
+       if (!conn) {
+               DBG("Could not get DBUS connection!");
+               return BT_STATUS_FAIL;
+       }
+
+       _bt_hal_convert_addr_type_to_string(address, bd_addr->address);
+       device_path = _bt_hal_get_device_object_path(address);
+
+       if (device_path == NULL) {
+               ERR("No created device with address:[%s] in statck", address);
+               return BT_STATUS_FAIL;
+       }
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_HAL_BLUEZ_NAME,
+                       device_path, BT_HAL_DEVICE_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       if (proxy == NULL) {
+               ERR("Could not get Device Proxy");
+               return BT_STATUS_FAIL;
+       }
+
+       result = g_dbus_proxy_call_sync(proxy, "Disconnect",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1, NULL,
+                       &error);
+
+       if (error != NULL) {
+               ERR("Dbus Call Error:[%s]", error->message);
+               g_clear_error(&error);
+               g_object_unref(proxy);
+               return BT_STATUS_FAIL;
+       }
+
+       g_object_unref(proxy);
+       if (result)
+               g_variant_unref(result);
+
+       DBG("-");
+       return BT_STATUS_SUCCESS;
+}
 #endif
index ec3ba36..b393709 100644 (file)
@@ -79,6 +79,8 @@ int _bt_hal_device_enable_rssi_monitoring(bt_bdaddr_t *bd_addr, uint32_t conn_li
                    int low_threshold, int in_range_threshold, int high_threshold);
 
 int _bt_hal_device_get_connected_link_rssi_strength(const bt_bdaddr_t *bd_addr, uint32_t link_type);
+
+int _bt_hal_device_disconnect(const bt_bdaddr_t *bd_addr);
 #endif
 
 #ifdef __cplusplus
index 5e2eda9..fb9d3c3 100644 (file)
@@ -881,6 +881,11 @@ typedef struct {
        * Sets the privacy functionality of the adapter
        */
        int (*adapter_le_set_privacy)(uint8_t set_privacy);
+
+       /*
+       * disconnect the device
+       */
+       int (*device_disconnect)(const bt_bdaddr_t *bd_addr);
 #endif
 } bt_interface_t;
 
index cf493ad..025c761 100755 (executable)
@@ -425,6 +425,19 @@ oal_status_t device_enable_rssi_monitoring(bt_address_t *addr, unsigned int link
  */
 oal_status_t device_enable_gap_auth_notifications(oal_gap_auth_type_e type, gboolean enable);
 
+/**
+ * @brief Disconnect the device
+ *
+ * @details This API is used to ACL disconnect the device
+ *
+ * @param[in] addr: Remote device address.
+ *
+ * @return TRUE if adapter has accepted the ACL Disconnect request FALSE otherwise.
+ *
+ * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
+ */
+oal_status_t device_disconnect(bt_address_t * addr);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 1ddacc9..df06cee 100755 (executable)
@@ -547,6 +547,26 @@ oal_status_t device_enable_gap_auth_notifications(oal_gap_auth_type_e type, gboo
 #endif
 }
 
+oal_status_t device_disconnect(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->device_disconnect((bt_bdaddr_t *)addr);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("device_disconnect 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)
 {
@@ -936,4 +956,5 @@ void cb_raw_rssi_received(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t rssi)
                        ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);
        BT_DBG("-");
 }
+
 #endif
index ee36a0f..80ffd76 100644 (file)
@@ -3088,6 +3088,15 @@ normal:
                g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
                break;
        }
+       case BT_DISCONNECT_DEVICE: {
+               bluetooth_device_address_t address = { {0} };
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_disconnect_device(&address);
+               break;
+       }
        default:
                BT_INFO("UnSupported function [%d]", function_name);
                result = BLUETOOTH_ERROR_NOT_SUPPORT;
@@ -3932,6 +3941,7 @@ gboolean __bt_service_check_privilege(int function_name,
 
        case BT_CANCEL_SEARCH_SERVICE:
        case BT_ENABLE_RSSI:
+       case BT_DISCONNECT_DEVICE:
 
        case BT_RFCOMM_ACCEPT_CONNECTION:
        case BT_RFCOMM_REJECT_CONNECTION:
index 3ba947a..dc7337d 100644 (file)
@@ -2494,4 +2494,22 @@ fail:
        return ret;
 }
 
+int _bt_disconnect_device(bluetooth_device_address_t *device_address)
+{
+       int result = OAL_STATUS_SUCCESS;
+
+       BT_DBG("+");
+
+       retv_if(!device_address, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       result = device_disconnect((bt_address_t *)device_address);
+       if (result != OAL_STATUS_SUCCESS) {
+               BT_DBG("Failed to disconnect device");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
+
 #endif
index 59c605f..a5b0ac7 100755 (executable)
@@ -119,6 +119,8 @@ int _bt_set_pin_code(bluetooth_device_address_t *device_address,
 
 int _bt_unset_pin_code(bluetooth_device_address_t *device_address);
 
+int _bt_disconnect_device(bluetooth_device_address_t *device_addr);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */