From 67224888f47ce8bbaa1dc26488f46e96b3213dd0 Mon Sep 17 00:00:00 2001 From: Amit Purwar Date: Mon, 28 Jan 2019 10:49:15 +0530 Subject: [PATCH] Fixed disable notification for acquire notification Change-Id: I8b870f29ec3c71d6a0b75e915307b76e57d33ad7 Signed-off-by: Amit Purwar --- bt-api/bt-event-handler.c | 3 +++ bt-api/bt-gatt-service.c | 20 ++++++++++++++++++++ bt-api/include/bt-gatt-server.h | 3 +++ 3 files changed, 26 insertions(+) diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index 47acff3..105d1cc 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -3898,6 +3898,9 @@ static void __bt_gatt_server_event_filter(GDBusConnection *connection, BT_INFO("GATT Server: Notification Enabled?? Handle: [%d] address [%s] Is Enabled [%d] result [%d]", info.handle, address, info.notification, result); + if (info.notification == FALSE) + cleanup_gatt_acquire_fd(info.handle); + _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, result, &info, event_info->cb, event_info->user_data); diff --git a/bt-api/bt-gatt-service.c b/bt-api/bt-gatt-service.c index 0f0f906..91149a8 100644 --- a/bt-api/bt-gatt-service.c +++ b/bt-api/bt-gatt-service.c @@ -3272,6 +3272,7 @@ void bluetooth_gatt_server_send_acquire_notify_response(GVariant * parameters, chr_info->write_fd = fd; + BT_INFO("setting up g_io channel"); channel = g_io_channel_unix_new(fd); g_io_channel_set_encoding(channel, NULL, NULL); g_io_channel_set_buffered(channel, FALSE); @@ -3313,6 +3314,7 @@ void bluetooth_gatt_server_send_acquire_notify_response(GVariant * parameters, dev_address.addr, BLUETOOTH_ADDRESS_LENGTH); info.handle = att_han; + info.notification = TRUE; _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, result, &info, @@ -3320,3 +3322,21 @@ void bluetooth_gatt_server_send_acquire_notify_response(GVariant * parameters, } } + +void cleanup_gatt_acquire_fd(int handle) +{ + bluetooth_gatt_acquire_notify_info_t *chr_info = NULL; + + BT_INFO("+"); + + chr_info = bluetooth_get_characteristic_info_from_path(handle); + + if (chr_info != NULL) { + BT_INFO("GATT Server: acquire notification char info found"); + + if (chr_info->write_fd >= 0) { + BT_INFO("closing fd"); + close(chr_info->write_fd); + } + } +} diff --git a/bt-api/include/bt-gatt-server.h b/bt-api/include/bt-gatt-server.h index 0877e90..89c9b86 100644 --- a/bt-api/include/bt-gatt-server.h +++ b/bt-api/include/bt-gatt-server.h @@ -11,6 +11,9 @@ void bluetooth_gatt_server_send_acquire_write_response(GVariant * parameter); void bluetooth_gatt_server_send_acquire_notify_response(GVariant * parameter, bt_event_info_t *event_info); +void cleanup_gatt_acquire_fd(int handle); + + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.7.4