Fix gatt client char value changed cb issue 42/227142/1
authorWootak Jung <wootak.jung@samsung.com>
Tue, 10 Mar 2020 04:20:29 +0000 (13:20 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 10 Mar 2020 04:22:07 +0000 (13:22 +0900)
gatt client char value changed cb setting failed on below scenario-
Server Connected > Add Thermometer Service(remote) > Client Create >
client char value changed cb > failed

Change-Id: Icf6dfeeeefb6fcc72c3bb82ee6eb0d88869af219

bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/src/bt-hal-gatt-client.c
bt-oal/bluez_hal/src/bt-hal-gatt.c
bt-oal/hardware/bt_gatt_client.h
bt-oal/include/oal-event.h
bt-oal/include/oal-gatt.h
bt-oal/oal-gatt.c
bt-service-adaptation/services/gatt/bt-service-gatt.c

index af9675b..aef24bb 100644 (file)
@@ -733,7 +733,7 @@ struct hal_ev_gatt_client_write_result {
 
 #define HAL_EV_GATT_CLIENT_WATCH_NOTIFICATION  0XC7
 struct hal_ev_gatt_client_watch_notification {
-       int32_t client_if;
+       int32_t conn_id;
        int32_t registered;
        int32_t status;
        int32_t is_primary;
index 0b213fd..f0c82ec 100644 (file)
@@ -2311,7 +2311,7 @@ static gboolean _hal_watch_register_notifi_cb(gpointer user_data)
        DBG("sending the watch register notification event");
        /* send the event */
        memset(&ev, 0, sizeof(ev));
-       ev.client_if = resp_data->conn_id; /* conn_id is saved with client_if */
+       ev.conn_id = resp_data->conn_id;
        ev.registered = 1;
        ev.status = resp_data->result;
 
@@ -2331,7 +2331,7 @@ static gboolean _hal_watch_register_notifi_cb(gpointer user_data)
        return FALSE;
 }
 
-static bt_status_t _hal_register_for_notification(int client_if,
+static bt_status_t _hal_register_for_notification(int conn_id,
                bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
                btgatt_gatt_id_t *char_id)
 {
@@ -2355,8 +2355,8 @@ static bt_status_t _hal_register_for_notification(int client_if,
                return BT_STATUS_FAIL;
        }
 
-       if (gattc_client->client_if != client_if) {
-               ERR("could not find the gatt client for client id[%d]", client_if);
+       if (gattc_client->conn_id != conn_id) {
+               ERR("could not find the gatt client for client id[%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -2438,7 +2438,7 @@ static bt_status_t _hal_register_for_notification(int client_if,
                g_clear_error(&error);
        }
 
-       resp_data->conn_id = gattc_client->client_if; /* saving client_if instead of conn_id */
+       resp_data->conn_id = gattc_client->conn_id;
        resp_data->result = result;
        memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t));
        memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t));
@@ -2454,13 +2454,13 @@ static bt_status_t _hal_register_for_notification(int client_if,
  * Register to receive notifications or indications for a given
  * characteristic
  */
-bt_status_t btif_register_for_notification(int client_if,
+bt_status_t btif_register_for_notification(int conn_id,
                const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
                btgatt_gatt_id_t *char_id)
 {
        CHECK_BTGATT_INIT();
 
-       return _hal_register_for_notification(client_if, (bt_bdaddr_t *)bd_addr, srvc_id, char_id);
+       return _hal_register_for_notification(conn_id, (bt_bdaddr_t *)bd_addr, srvc_id, char_id);
 }
 
 static gboolean _hal_watch_deregister_notifi_cb(gpointer user_data)
@@ -2471,7 +2471,7 @@ static gboolean _hal_watch_deregister_notifi_cb(gpointer user_data)
        DBG("sending the watch deregister notification event");
        /* send the event */
        memset(&ev, 0, sizeof(ev));
-       ev.client_if = resp_data->conn_id; /* conn_id is saved with client_if */
+       ev.conn_id = resp_data->conn_id;
        ev.registered = 0;
        ev.status = resp_data->result;
 
@@ -2491,7 +2491,7 @@ static gboolean _hal_watch_deregister_notifi_cb(gpointer user_data)
        return FALSE;
 }
 
-static bt_status_t _hal_deregister_for_notification(int client_if,
+static bt_status_t _hal_deregister_for_notification(int conn_id,
                bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
                btgatt_gatt_id_t *char_id)
 {
@@ -2515,8 +2515,8 @@ static bt_status_t _hal_deregister_for_notification(int client_if,
                return BT_STATUS_FAIL;
        }
 
-       if (gattc_client->client_if != client_if) {
-               ERR("could not find the gatt client for client id[%d]", client_if);
+       if (gattc_client->conn_id != conn_id) {
+               ERR("could not find the gatt client for client id[%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -2580,7 +2580,7 @@ static bt_status_t _hal_deregister_for_notification(int client_if,
                result = BT_STATUS_FAIL;
        }
 
-       resp_data->conn_id = gattc_client->client_if; /* saving client_if instead of conn_id */
+       resp_data->conn_id = gattc_client->conn_id;
        resp_data->result = result;
        memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t));
        memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t));
@@ -2592,12 +2592,12 @@ static bt_status_t _hal_deregister_for_notification(int client_if,
        return BT_STATUS_SUCCESS;
 }
 /** Deregister a previous request for notifications/indications */
-bt_status_t btif_deregister_for_notification(int client_if,
+bt_status_t btif_deregister_for_notification(int conn_id,
                const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
                btgatt_gatt_id_t *char_id)
 {
        CHECK_BTGATT_INIT();
-       return _hal_deregister_for_notification(client_if, (bt_bdaddr_t *)bd_addr, srvc_id, char_id);
+       return _hal_deregister_for_notification(conn_id, (bt_bdaddr_t *)bd_addr, srvc_id, char_id);
 }
 
 /** Request RSSI for a given remote device */
index 2e959af..2d789e4 100644 (file)
@@ -659,7 +659,7 @@ static void __bt_handle_gatt_client_watch_notification(void *buf, uint16_t len)
        gatt_char_id.inst_id = ev->inst_id;
 
        if (bt_gatt_callbacks->client->register_for_notification_cb)
-               bt_gatt_callbacks->client->register_for_notification_cb(ev->client_if,
+               bt_gatt_callbacks->client->register_for_notification_cb(ev->conn_id,
                                ev->registered, ev->status, &gatt_srvc_id, &gatt_char_id);
 }
 
index ed445c6..e879aa7 100644 (file)
@@ -316,12 +316,12 @@ typedef struct {
         * Register to receive notifications or indications for a given
         * characteristic
         */
-       bt_status_t (*register_for_notification)(int client_if,
+       bt_status_t (*register_for_notification)(int conn_id,
                        const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
                        btgatt_gatt_id_t *char_id);
 
        /** Deregister a previous request for notifications/indications */
-       bt_status_t (*deregister_for_notification)(int client_if,
+       bt_status_t (*deregister_for_notification)(int conn_id,
                        const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
                        btgatt_gatt_id_t *char_id);
 
index 6f4c45a..26d6c7d 100644 (file)
@@ -478,7 +478,7 @@ typedef struct {
 
 typedef struct {
        oal_status_t status;
-       int client_if;
+       int conn_id;
        oal_gatt_id_t char_id;
        oal_gatt_srvc_id_t srvc_id;
 } event_gattc_regdereg_notify_t;
index 06c4a8e..d6844c4 100644 (file)
@@ -514,10 +514,10 @@ oal_status_t gattc_register_service_changed_cb(bt_address_t *device_address);
 
 oal_status_t gattc_unregister_service_changed_cb(bt_address_t *device_address);
 
-oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
+oal_status_t gattc_register_for_notification(int conn_id, bt_address_t * address,
                                oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
 
-oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
+oal_status_t gattc_deregister_for_notification(int conn_id, bt_address_t * address,
                                oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
 
 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
index c41085f..f98a4e0 100644 (file)
@@ -1554,12 +1554,12 @@ static void cb_gattc_get_descriptor(int conn_id, int status, btgatt_srvc_id_t *s
        send_event(OAL_EVENT_GATTC_DESC_SERACH_RESULT, event, sizeof(*event));
 }
 
-static void cb_gattc_register_for_notification(int client_if, int registered, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id)
+static void cb_gattc_register_for_notification(int conn_id, int registered, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id)
 {
        char uuid_str1[2*BT_UUID_STRING_MAX];
        char uuid_str2[2*BT_UUID_STRING_MAX];
-       BT_INFO("BTGATT Client Register For Notification Callback, client_if:%d, status:%d, registered: %s",
-               client_if, status, registered == 1 ? "REGISTERED" : "DEREGISTERED");
+       BT_INFO("BTGATT Client Register For Notification Callback, conn_id:%d, status:%d, registered: %s",
+               conn_id, status, registered == 1 ? "REGISTERED" : "DEREGISTERED");
        uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
        uuid_to_stringname((oal_uuid_t *)&(char_id->uuid), uuid_str2);
        BT_INFO("Service=> [%s], Inst_id [%u], Type [%s]", uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
@@ -1567,7 +1567,7 @@ static void cb_gattc_register_for_notification(int client_if, int registered, in
 
        event_gattc_regdereg_notify_t *event = g_new0(event_gattc_regdereg_notify_t, 1);
        oal_event_t event_type = (registered == 1 ? OAL_EVENT_GATTC_NOTIFICATION_REGISTERED : OAL_EVENT_GATTC_NOTIFICATION_DEREGISTERED);
-       event->client_if = client_if;
+       event->conn_id = conn_id;
        event->status = convert_to_oal_status(status);
        memcpy(&(event->srvc_id), srvc_id, sizeof(oal_gatt_srvc_id_t));
        memcpy(&(event->char_id), char_id, sizeof(oal_gatt_id_t));
@@ -1966,7 +1966,7 @@ oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id,
        return OAL_STATUS_SUCCESS;
 }
 
-oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
+oal_status_t gattc_register_for_notification(int conn_id, bt_address_t * address,
                        oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
        int ret = OAL_STATUS_SUCCESS;
        char uuid_str1[2*BT_UUID_STRING_MAX];
@@ -1980,9 +1980,9 @@ oal_status_t gattc_register_for_notification(int client_id, bt_address_t * addre
        uuid_to_stringname(&(char_id->uuid), uuid_str2);
        API_TRACE("Client Register Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
        CHECK_OAL_GATT_ENABLED();
-       CHECK_CLIENT_REGISTRATION(client_id);
+       CHECK_CLIENT_CONNECTION(conn_id);
 
-       ret = gatt_api->client->register_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
+       ret = gatt_api->client->register_for_notification(conn_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
        if (ret != BT_STATUS_SUCCESS) {
                BT_ERR("GATT client register notification failed: %s", status2string(ret));
                return convert_to_oal_status(ret);
@@ -1991,7 +1991,7 @@ oal_status_t gattc_register_for_notification(int client_id, bt_address_t * addre
        return OAL_STATUS_SUCCESS;
 }
 
-oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
+oal_status_t gattc_deregister_for_notification(int conn_id, bt_address_t * address,
                        oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
        int ret = OAL_STATUS_SUCCESS;
        char uuid_str1[2*BT_UUID_STRING_MAX];
@@ -2005,9 +2005,9 @@ oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * add
        uuid_to_stringname(&(char_id->uuid), uuid_str2);
        API_TRACE("Client Deregister Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
        CHECK_OAL_GATT_ENABLED();
-       CHECK_CLIENT_REGISTRATION(client_id);
+       CHECK_CLIENT_CONNECTION(conn_id);
 
-       ret = gatt_api->client->deregister_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
+       ret = gatt_api->client->deregister_for_notification(conn_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
        if (ret != BT_STATUS_SUCCESS) {
                BT_ERR("GATT client deregister notification failed: %s", status2string(ret));
                return convert_to_oal_status(ret);
index 824d50e..5491f5d 100644 (file)
@@ -1470,29 +1470,8 @@ static struct gatt_out_conn_info_t* __bt_find_gatt_outgoing_conn_info(char *addr
        }
        return NULL;
 }
-
-static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_client_if(int client_if)
-{
-       GSList *l;
-       struct gatt_server_info_t *info = NULL;
-
-       for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
-               info = (struct gatt_server_info_t*)l->data;
-               if (info == NULL)
-                       continue;
-
-               if (info->client_id == client_if) {
-                       BT_INFO("Remote GATT server found addr[%s]", info->addr);
-                       return info;
-               }
-       }
-       return NULL;
-}
 #endif
 
-
-
-
 #ifdef TIZEN_GATT_CLIENT
 static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
 {
@@ -4019,20 +3998,16 @@ static void __bt_handle_client_notification_registered(
        memset(&notif_info, 0x00, sizeof(bt_gatt_notif_reg_info_t));
 
        BT_INFO("Client Interface [%d] status [%d]",
-                       event_data->client_if,
+                       event_data->conn_id,
                        event_data->status);
 
        /* Extract Address from conn_id of event data */
-       conn_info = __bt_find_remote_gatt_server_info_from_client_if(
-                       event_data->client_if);
-
+       conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
        if (!conn_info) {
                BT_INFO("Connection Info is not present, return");
                return;
        }
-       BT_INFO("Notification Registered for addr [%s]",
-                       conn_info->addr);
-
+       BT_INFO("Notification Registered for addr [%s]", conn_info->addr);
 
        /* Fill svc informations in buffer */
        memcpy(&notif_info.svc_uuid,
@@ -4880,11 +4855,11 @@ int _bt_gatt_watch_characteristic(
 
        /* Register or unregister Notification characteristic */
        if (is_notify)
-               ret = gattc_register_for_notification(conn_info->client_id,
+               ret = gattc_register_for_notification(conn_info->connection_id,
                                (bt_address_t*)&(chr->device_address),
                                &srvc_id, &char_id);
        else
-               ret = gattc_deregister_for_notification(conn_info->client_id,
+               ret = gattc_deregister_for_notification(conn_info->connection_id,
                                (bt_address_t*)&(chr->device_address),
                                &srvc_id, &char_id);