return BT_STATUS_SUCCESS;
}
+static void __le_disconnection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *g_error = NULL;
+ GVariant *reply = NULL;
+
+ DBG("+");
+
+ reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
+ g_object_unref(proxy);
+ if (reply == NULL) {
+ ERR("Disconnect LE Dbus Call Error");
+ if (g_error) {
+ ERR("Error: %s\n", g_error->message);
+ g_clear_error(&g_error);
+ }
+ }
+ g_variant_unref(reply);
+}
+
+
static bt_status_t gatt_server_close(int server_if, const bt_bdaddr_t *bd_addr, int conn_id)
{
CHECK_BTGATT_INIT();
+
+ char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path;
+ GDBusProxy *device_proxy;
+ GDBusConnection *g_conn;
+ struct gatt_client_info_t *conn_info = NULL;
+
+ INFO("+");
+
+ if (NULL == bd_addr) {
+ ERR("bd_addr is NULL");
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ /* GDBUS Connection Info validate */
+ g_conn = _bt_hal_get_system_gconn();
+ if (g_conn == NULL) {
+ ERR("Could not get System DBUS Connection");
+ return BT_STATUS_FAIL;
+ }
+
+ /* Connection Info validate */
+ conn_info = __bt_find_remote_gatt_client_info_from_conn(conn_id);
+ if (conn_info == NULL) {
+ ERR("No Connection Inforamtion!!!");
+ return BT_STATUS_FAIL;
+ }
+
+ _bt_hal_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->address);
+
+ //check if connection has the same device address
+ if (g_strcmp0(conn_info->addr, device_address) != 0) {
+ ERR("device address [%s] does not match", device_address);
+ return BT_STATUS_FAIL;
+ }
+
+ device_path = _bt_hal_get_device_object_path(conn_info->addr);
+ if (device_path == NULL) {
+ ERR("device_path is NULL");
+ return BT_STATUS_PARM_INVALID;
+ }
+
+ device_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_HAL_BLUEZ_NAME,
+ device_path, BT_HAL_DEVICE_INTERFACE, NULL, NULL);
+
+
+ g_free(device_path);
+ if (device_proxy == NULL)
+ return BT_STATUS_FAIL;
+
+ INFO("Disconnect LE [%s]", device_address);
+
+ g_dbus_proxy_call(device_proxy, "DisconnectLE",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_HAL_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__le_disconnection_req_cb, conn_info);
+
+ INFO("-");
return BT_STATUS_SUCCESS;
}
int server_inst;
int conn_id;
bt_address_t address;
+ int status;
} event_gatts_conn_t;
typedef struct {
*/
oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response);
+oal_status_t gatts_disconnect(int Ins_id, bt_address_t *device_address, int conId);
+
/**
* @brief Start LE Device discovery
*
return OAL_STATUS_SUCCESS;
}
+oal_status_t gatts_disconnect(int instance_id, bt_address_t *device_address, int conn_id)
+{
+ int ret = OAL_STATUS_SUCCESS;
+ bdstr_t bdstr;
+
+ API_TRACE("Server Disonnect: instance_id = %d, conn_id = %d", instance_id, conn_id);
+
+ CHECK_OAL_GATT_ENABLED();
+ CHECK_SERVER_INSTANCE(instance_id);
+ CHECK_SERVER_REGISTRATION(instance_id);
+
+ API_TRACE("[%s]", bdt_bd2str(device_address, &bdstr));
+
+ ret = gatt_api->server->disconnect(gatt_servers[instance_id - 1].server_id, (bt_bdaddr_t *) device_address, conn_id);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT Server disconnect failed: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+ return OAL_STATUS_SUCCESS;
+}
+
+
/************************************GATT Server Functions*************************************/
/*Server Callbacks*/
static void cb_gatts_register_app(int status, int server_if, bt_uuid_t *uuid)
memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
event->conn_id = conn_id;
event_type = ((connected == TRUE) ? OAL_EVENT_GATTS_CONNECTION_COMPLETED : OAL_EVENT_GATTS_DISCONNECTION_COMPLETED);
+ event->status = OAL_STATUS_SUCCESS;
send_event(event_type, event, sizeof(event_gatts_conn_t));
}
in this event */
_bt_convert_addr_type_to_string(address,
(unsigned char *)dev_addr.addr);
+
+ if (event->status != OAL_STATUS_SUCCESS)
+ result = BLUETOOTH_ERROR_INTERNAL;
+
__bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
address, BT_ADDRESS_STRING_SIZE);
_bt_convert_addr_type_to_string(address,
(unsigned char *)dev_addr.addr);
+ if (event->status != OAL_STATUS_SUCCESS)
+ result = BLUETOOTH_ERROR_INTERNAL;
+
if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
result = BLUETOOTH_ERROR_INTERNAL;
int client_id)
{
struct gatt_server_info_t *conn_info = NULL;
+ struct gatt_client_info_t *rem_client_conn_info = NULL;
invocation_info_t *req_info = NULL;
int ret = OAL_STATUS_SUCCESS;
char *addr;
}
/* Check if remote GATT Server is connected or not */
conn_info = __bt_find_remote_gatt_server_info(addr);
- if (!conn_info) {
- BT_ERR("GATT Server is not connected..");
- g_free(addr);
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
- }
+ if (conn_info) {
+ /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */
+ if (client_id == 0) {
+ BT_INFO("GATT CLient Disconnect request sent by an app without any client instance [%d]",
+ client_id);
+ BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
+ client_id = gatt_default_client;
+ }
- /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */
- if (client_id == 0) {
- BT_INFO("GATT CLient Disconnect request sent by an app without any client instance [%d]",
- client_id);
- BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
- client_id = gatt_default_client;
- }
+ BT_INFO("Disconnect remote gatt server using CLient ID [%d] Connection ID [%d]", client_id, conn_info->connection_id);
+ ret = gattc_disconnect(client_id, (bt_address_t*)(address),
+ conn_info->connection_id);
+ } else {
+ /* check if remote client is connected */
+ rem_client_conn_info = __bt_find_remote_gatt_client_info(addr);
- BT_INFO("Disconnect using CLient ID [%d] Connection ID [%d]", client_id, conn_info->connection_id);
- ret = gattc_disconnect(client_id, (bt_address_t*)(address),
- conn_info->connection_id);
+ if (!rem_client_conn_info || client_id != 0) {
+ BT_ERR("GATT device is not connected..");
+ g_free(addr);
+ return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+ }
+
+ BT_INFO("Disconnect remote gatt client ");
+
+ ret = gatts_disconnect(rem_client_conn_info->instance_id,
+ (bt_address_t*)(address), rem_client_conn_info->connection_id);
+ }
if (ret != OAL_STATUS_SUCCESS) {
BT_ERR("ret: %d", ret);