From fb06915413a8e0deb6c8ec06051f2a38ca073606 Mon Sep 17 00:00:00 2001 From: Abhishek Chandra Date: Thu, 2 Aug 2018 14:03:11 +0530 Subject: [PATCH] Added Event Handling in HAL [Problem] Start/Stop notify ,Gatt Connected and disconnected event was not received till bt-service . [Solution] Added Event handling for Notification change, Gatt Connected and Disconnected was missing in the HAL layer . Change-Id: I72112ace1ed56d711e5a95e799cf2d27989f38ae Signed-off-by: Abhishek Chandra --- bt-oal/bluez_hal/src/bt-hal-gatt.c | 16 ++++++++++++++++ bt-service-adaptation/services/bt-service-event-sender.c | 3 +++ bt-service-adaptation/services/gatt/bt-service-gatt.c | 11 ++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt.c b/bt-oal/bluez_hal/src/bt-hal-gatt.c index ec529ee..e6004d5 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt.c @@ -209,6 +209,18 @@ static void __bt_hal_handle_gatt_server_connected(void *buf, uint16_t len) ev->connected, &bd_addr); } +static void __bt_hal_handle_gatt_server_notification_changed(void *buf, uint16_t len) +{ + struct hal_ev_gatt_server_notifcation_change *ev = buf; + bt_bdaddr_t bd_addr; + + memcpy(bd_addr.address, ev->bdaddr, 6); + + if (bt_gatt_callbacks->server->notif_enabled_cb) + bt_gatt_callbacks->server->notif_enabled_cb(ev->conn_id, ev->trans_id, + ev->att_handle, ev->notify, &bd_addr); +} + static void __bt_hal_handle_gatt_server_read_requested(void *buf, uint16_t len) { struct hal_ev_gatt_server_read_req *ev = buf; @@ -308,6 +320,10 @@ static void __bt_hal_gatt_events(int message, void *buf, uint16_t len) __bt_hal_handle_gatt_server_connected(buf, len); break; } + case HAL_EV_GATT_NOTIFICATION_CHANGE: { + __bt_hal_handle_gatt_server_notification_changed(buf, len); + break; + } case HAL_EV_GATT_READ_REQUESTED: { __bt_hal_handle_gatt_server_read_requested(buf, len); break; diff --git a/bt-service-adaptation/services/bt-service-event-sender.c b/bt-service-adaptation/services/bt-service-event-sender.c index b2e97fd..d21bb72 100644 --- a/bt-service-adaptation/services/bt-service-event-sender.c +++ b/bt-service-adaptation/services/bt-service-event-sender.c @@ -479,6 +479,9 @@ int _bt_send_event(int event_type, int event, GVariant *param) case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED: signal = BT_GATT_SERVER_NOTIFICATION_COMPLETED; break; + case BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED: + signal = BT_GATT_SERVER_NOTIFICATION_CHANGED; + break; #endif #ifdef TIZEN_GATT_CLIENT case BLUETOOTH_EVENT_GATT_READ_CHAR: /* GATT Client */ diff --git a/bt-service-adaptation/services/gatt/bt-service-gatt.c b/bt-service-adaptation/services/gatt/bt-service-gatt.c index cb9e919..abcba75 100644 --- a/bt-service-adaptation/services/gatt/bt-service-gatt.c +++ b/bt-service-adaptation/services/gatt/bt-service-gatt.c @@ -1444,6 +1444,7 @@ static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event) int result = BLUETOOTH_ERROR_NONE; struct gatt_client_info_t *conn_info = NULL; bluetooth_device_address_t dev_addr; + GVariant *param = NULL; char *address = g_malloc0(BT_ADDRESS_STRING_SIZE); @@ -1465,14 +1466,14 @@ static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event) if (!conn_info) { BT_INFO("Conn Info absent: But no need to Send Local GATT Server Connected event to apps"); -#if 0 + param = g_variant_new("(is)", result, address); /* Send event to application */ _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_GATT_SERVER_CONNECTED, /* Local device is GATT server */ param); -#endif + /* Save Connection info */ conn_info = g_new0(struct gatt_client_info_t, 1); conn_info->addr = g_strdup(address); @@ -1492,7 +1493,7 @@ static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *even int result = BLUETOOTH_ERROR_NONE; struct gatt_client_info_t *conn_info = NULL; bluetooth_device_address_t dev_addr; - + GVariant *param = NULL; char address[BT_ADDRESS_STRING_SIZE]; memcpy(dev_addr.addr, event->address.addr, 6); @@ -1523,13 +1524,13 @@ static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *even conn_info = __bt_find_remote_gatt_client_info(address); if (conn_info) { BT_INFO("No need to Send Local GATT Server Disconnected event to apps, just remove remote client info"); -#if 0 + param = g_variant_new("(is)", result, address); /* Send event to application */ _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED, /* Local device is GATT server */ param); -#endif + /* Remove info from List */ gatt_client_info_list = g_slist_remove(gatt_client_info_list, conn_info); BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list)); -- 2.7.4