Fix: advertisinog stopped suddenly
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / gatt / bt-service-gatt.c
index 824d50e..18798a4 100644 (file)
@@ -133,8 +133,39 @@ struct gatt_server_info_t {
        char *addr;                                      /* Remote GATT Server address */
 };
 
+struct gatt_client_info_t {
+       int connection_id;                               /* This value will uniquely identify a GATT client-server connection */
+       int instance_id;                                 /* This value unique identifies a GATT server instance */
+       char *addr;                                      /* Remote GATT client address */
+};
+
+/* TODO:
+ * Remove this feature if code is verified
+ * Remove gatt_client/server_info_t and use gatt_conn_info_t
+ * Remove gatt_client/server_info_list and use gatt_conn_info_list
+ */
+#define __INTEGRATE_GATT_INFO__
+#ifndef __INTEGRATE_GATT_INFO__
 /* Linked List of connected Remote GATT Servers */
 static GSList *gatt_server_info_list = NULL;
+/* Linked List of connected Remote GATT clients */
+static GSList *gatt_client_info_list = NULL;
+#else
+/* GATT Connection Info List Structure */
+struct gatt_conn_info_t {
+       char *addr;        /* Remote GATT address */
+       int connection_id; /* This value will uniquely identify a GATT client-server connection */
+       int client_id;     /* This value unique identifies a GATT Client instance */
+       int instance_id;   /* This value unique identifies a GATT Server instance */
+};
+
+/* Linked List of connected Remote GATT info */
+static GSList *gatt_conn_info_list = NULL;
+#define gatt_server_info_t gatt_conn_info_t
+#define gatt_client_info_t gatt_conn_info_t
+#define gatt_server_info_list gatt_conn_info_list
+#define gatt_client_info_list gatt_conn_info_list
+#endif
 
 typedef struct {
        gboolean is_changed;
@@ -180,8 +211,7 @@ typedef struct {
        int inst_id;
 } bt_gatt_included_service_info_t;
 
-GSList *list_gatt_info;
-
+static GSList *list_gatt_info = NULL;
 
 #endif
 
@@ -215,13 +245,6 @@ struct gatt_server_req_info {
        char *addr;                                      /* Remote GATT client address */
 };
 
-/* GATT Client Info List Structure */
-struct gatt_client_info_t {
-       int connection_id;                               /* This value will uniquely identify a GATT client-server connection */
-       int instance_id;                                 /* This value unique identifies a GATT server instance */
-       char *addr;                                      /* Remote GATT client address */
-};
-
 /* GATT Indicate confirm result  */
 struct gatt_indicate_cfm_result_info_t {
        int result;                                      /* Result of event */
@@ -264,9 +287,10 @@ static void __bt_handle_client_notification_registered(event_gattc_regdereg_noti
 static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data);
 static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data);
 static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data);
-
 #endif
+
 static int __bt_unregister_gatt_server_instance(int server_instance);
+static void __bt_cleanup_remote_services(struct gatt_server_info_t *conn_info);
 
 /*mtu device list*/
 struct gatt_mtu_info_t {
@@ -284,9 +308,6 @@ static void __bt_update_mtu_gatt_device(char *address, int mtu);
 /* Linked List of GATT requests from Remote GATT Clients */
 static GSList *gatt_server_requests = NULL;
 
-/* Linked List of connected Remote GATT clients */
-static GSList *gatt_client_info_list = NULL;
-
 /* Number of clients to be notified to */
 static int num_indicate_clients;
 
@@ -319,8 +340,8 @@ void _bt_check_adv_app_termination(const char *name)
                app = &numapps[k];
 
                /* Search for a app which has same sender and stop adv is running */
-               if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) {
-                       BT_DBG("Match found, name: %s", name);
+               if (strcasecmp(app->sender, name) == 0 && app->is_initialized == TRUE) {
+                       BT_DBG("numapps[%d] Match found, name: %s", k, name);
 
                        /* TODO 2: Need to manage app info as list, not array.
                                   This loop always run for MAX count if any apps are terminated.
@@ -333,7 +354,7 @@ void _bt_check_adv_app_termination(const char *name)
                                __bt_remove_all_service_handles(app);
 
                                /* If Advertising is enabled, stop it */
-                               if (app->adv_handle > 0) {
+                               if (app->adv_handle != 0) {
                                        BT_INFO("Stop advertising on instance ID [%d]", app->instance_id);
                                        /* Disable adv if running */
                                        BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
@@ -579,7 +600,7 @@ char * _bt_get_sender_and_handle(int server_instance, int *adv_handle)
        for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
                info = &numapps[k];
 
-               if (info->instance_id == server_instance && info->adv_handle != -1) {
+               if (info->instance_id == server_instance && info->adv_handle != 0) {
                        *adv_handle = info->adv_handle;
                        BT_DBG("Server instance [%d] Adv handle [%d] Sender [%s]", server_instance, *adv_handle, info->sender);
                        return g_strdup(info->sender);
@@ -825,13 +846,13 @@ int _bt_register_server_instance(const char *sender, int adv_handle)
        int k;
        oal_uuid_t uuid;
 
-       BT_INFO("###Check on which instance Server instance can be initialized....");
+       BT_INFO("Check on which instance Server instance can be initialized....");
        for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
                if (numapps[k].is_initialized == 1) {
-                       BT_INFO("Instance ID [%d] is already in use..Check next slot", numapps[k].instance_id);
+                       BT_DBG("Instance ID [%d] is already in use..Check next slot", numapps[k].instance_id);
                } else {
                        slot = k;
-                       BT_INFO("Time to register GATT Server..UUID to be used is [%s] slot [%d]", uuid_list[slot-1], slot);
+                       BT_DBG("Time to register GATT Server..UUID to be used is [%s] slot [%d]", uuid_list[slot-1], slot);
                        break;
                }
        }
@@ -853,7 +874,7 @@ int _bt_register_server_instance(const char *sender, int adv_handle)
                g_free(uuid_string);
                return BLUETOOTH_ERROR_INTERNAL;
        }
-       BT_INFO("GATT Server registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
+       BT_DBG("GATT Server registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
        /* Return & wait for GATT Server Instance Initialization event */
        memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
        memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
@@ -887,7 +908,7 @@ static void __bt_gatt_handle_pending_request_info(int result,
 #ifndef GATT_DIRECT
                case BT_GATT_SERVER_REGISTER: {
                        bt_service_app_info_t *param = (bt_service_app_info_t*)data;
-                       BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
+
                        if (!g_strcmp0(req_info->sender, param->sender)) {
                                BT_DBG("GATT Server app found [%s]", req_info->sender);
 
@@ -904,7 +925,6 @@ static void __bt_gatt_handle_pending_request_info(int result,
                case BT_GATT_SERVER_START_SERVICE:
                case BT_GATT_SERVER_DELETE_SERVICE: {
                        bt_service_app_info_t *param = (bt_service_app_info_t*)data;
-                       BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
 
                        int *saved_instance_id = (int*)req_info->user_data;
                        if (!g_strcmp0(req_info->sender, param->sender) && param->instance_id == *saved_instance_id) {
@@ -974,7 +994,7 @@ static void __bt_gatt_handle_pending_request_info(int result,
 #ifdef TIZEN_GATT_CLIENT
                case BT_GATT_CLIENT_REGISTER: {
                        bt_service_app_info_t *param = (bt_service_app_info_t*)data;
-                       BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
+
                        if (!g_strcmp0(req_info->sender, param->sender)) {
                                BT_DBG("GATT Client app found [%s] created client ID [%d]",
                                                req_info->sender, param->client_id);
@@ -995,8 +1015,6 @@ static void __bt_gatt_handle_pending_request_info(int result,
                        _bt_convert_addr_type_to_string(address,
                                        (unsigned char *)(&param->device_addr.addr));
 
-                       BT_DBG("Request Sender [%s] address [%s]", req_info->sender, address);
-
                        /* Match address to determine same request */
                        if (!g_strcmp0((char*)req_info->user_data, address)) {
                                BT_DBG("GATT Client app found [%s] Remote address [%s]",
@@ -1020,7 +1038,7 @@ static void __bt_gatt_handle_pending_request_info(int result,
                        bt_char_browse_info_t param;
                        memcpy((void*)&param, data, sizeof(bt_char_browse_info_t));
                        //bt_char_browse_info_t *param = (bt_char_browse_info_t*)data;
-                       BT_DBG("Request Sender [%s]", req_info->sender);
+
                        bluetooth_gatt_client_svc_prop_info_t *prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
 
                        /* Match both address and service properties to determine same request */
@@ -1044,7 +1062,6 @@ static void __bt_gatt_handle_pending_request_info(int result,
                case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
                        bt_descriptor_browse_info_t *param = (bt_descriptor_browse_info_t*)data;
 
-                       BT_DBG("Request Sender [%s]", req_info->sender);
                        bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
 
                        /* Match both address, service properties &char properties to determine same request */
@@ -1069,7 +1086,7 @@ static void __bt_gatt_handle_pending_request_info(int result,
                case BT_GATT_WATCH_CHARACTERISTIC: {
                        bt_gatt_notif_reg_info_t *param = (bt_gatt_notif_reg_info_t*)data;
                        bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
-                       BT_DBG("Request Sender [%s]", req_info->sender);
+
                        /* Match both address, service properties &char properties to determine same request */
                        if (!memcmp(param->addr.addr,
                                        prop->device_address.addr,
@@ -1092,7 +1109,6 @@ static void __bt_gatt_handle_pending_request_info(int result,
                case BT_GATT_READ_CHARACTERISTIC:
                case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
                         bluetooth_gatt_client_char_prop_info_t *param = (bluetooth_gatt_client_char_prop_info_t*)data;
-                        BT_DBG("Request Sender [%s]", req_info->sender);
 
                         char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
                         bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
@@ -1114,7 +1130,6 @@ static void __bt_gatt_handle_pending_request_info(int result,
                case BT_GATT_READ_DESCRIPTOR_VALUE:
                case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
                         bluetooth_gatt_client_desc_prop_info_t *param = (bluetooth_gatt_client_desc_prop_info_t*)data;
-                        BT_DBG("Request Sender [%s]", req_info->sender);
 
                         char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
                         bluetooth_gatt_client_desc_prop_info_t *prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
@@ -1214,7 +1229,7 @@ static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
                info = &numapps[k];
 
                if (info->instance_id == event->gatt_srvc_stat.server_inst) {
-                       BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
+                       BT_INFO("numapps[%d] Found GATT Server.. UUID [%s], sender [%s]", k, info->uuid, info->sender);
                        __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_SERVICE,
                                        (int*)&svc_handle, sizeof(int));
 
@@ -1222,8 +1237,8 @@ static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
                        if (svc_handle > 0) {
                                handle = g_malloc0(sizeof(int));
                                *handle = svc_handle;
-                               numapps[event->gatt_srvc_stat.server_inst].service_handles = g_slist_append(numapps[event->gatt_srvc_stat.server_inst].service_handles, handle);
-                               count = g_slist_length(numapps[event->gatt_srvc_stat.server_inst].service_handles);
+                               numapps[k].service_handles = g_slist_append(numapps[k].service_handles, handle);
+                               count = g_slist_length(numapps[k].service_handles);
                                BT_INFO("Added Service handle [%d] to list..current count [%d]", svc_handle, count);
                        }
                        break;
@@ -1470,35 +1485,16 @@ 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)
 {
        int result = BLUETOOTH_ERROR_NONE;
        struct gatt_client_info_t *client_info = NULL;
+#ifndef __INTEGRATE_GATT_INFO__
        struct gatt_server_info_t *server_info = NULL;
+#endif
        bluetooth_device_address_t dev_addr;
        GVariant *param = NULL;
        int ret;
@@ -1540,10 +1536,14 @@ static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
                client_info->addr = g_strdup(address);
                BT_INFO("Added GATT client addr[%s]", client_info->addr);
                client_info->connection_id = event->conn_id;
+#ifdef __INTEGRATE_GATT_INFO__
+               client_info->client_id = -1;
+#endif
                client_info->instance_id = event->server_inst;
                gatt_client_info_list = g_slist_append(gatt_client_info_list, client_info);
                BT_INFO("Total num of connected Remote GATT Clients [%d]", g_slist_length(gatt_client_info_list));
 
+#ifndef __INTEGRATE_GATT_INFO__
                /* Save server connection info */
                server_info = g_new0(struct gatt_server_info_t, 1);
                server_info->addr = g_strdup(address);
@@ -1552,6 +1552,7 @@ static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
                server_info->connection_id = event->conn_id;
                gatt_server_info_list = g_slist_append(gatt_server_info_list, server_info);
                BT_INFO("Total num of connected Remote GATT Servers [%d]", g_slist_length(gatt_server_info_list));
+#endif
 
                ret = gattc_add_connection_info((bt_address_t *)&dev_addr, event->conn_id, event->server_inst);
                if (ret != OAL_STATUS_SUCCESS) {
@@ -1569,7 +1570,9 @@ static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *even
 {
        int result = BLUETOOTH_ERROR_NONE;
        struct gatt_client_info_t *client_info = NULL;
+#ifndef __INTEGRATE_GATT_INFO__
        struct gatt_server_info_t *server_info = NULL;
+#endif
        bluetooth_device_address_t dev_addr;
        GVariant *param = NULL;
        char address[BT_ADDRESS_STRING_SIZE];
@@ -1612,6 +1615,7 @@ static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *even
                                BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED, /* Local device is GATT server */
                                param);
 
+#ifndef __INTEGRATE_GATT_INFO__
                /* Remove server info from list */
                server_info = _bt_find_remote_gatt_server_info(address);
                if (server_info)
@@ -1619,6 +1623,13 @@ static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *even
                else
                        BT_INFO("Can not find conn info, already removed!");
 
+               /* Remove all services from info list_gatt_info */
+               __bt_cleanup_remote_services(server_info);
+#else
+               /* Remove all services from info list_gatt_info */
+               __bt_cleanup_remote_services(client_info);
+#endif
+
                /* Remove client info from List */
                gatt_client_info_list = g_slist_remove(gatt_client_info_list, client_info);
                BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
@@ -2164,7 +2175,7 @@ static void __bt_gatt_event_handler(int event_type, gpointer event_data)
                break;
        }
        case OAL_EVENT_GATTC_SERVICE_SEARCH_RESULT: {
-               BT_INFO("OAL Event: GATT Client Service Search Result");
+               BT_DBG("OAL Event: GATT Client Service Search Result");
                __bt_handle_client_service_search_result((event_gattc_service_result_t *) event_data);
                break;
        }
@@ -2174,32 +2185,32 @@ static void __bt_gatt_event_handler(int event_type, gpointer event_data)
                break;
        }
        case OAL_EVENT_GATTC_CHARAC_SERACH_RESULT: {
-               BT_INFO("OAL Event: GATT Client Characteristic Search Result");
+               BT_DBG("OAL Event: GATT Client Characteristic Search Result");
                __bt_handle_client_characteristic_search_result((event_gattc_characteristic_result_t *) event_data);
                break;
        }
        case OAL_EVENT_GATTC_DESC_SERACH_RESULT: {
-               BT_INFO("OAL Event: GATT Client Descriptor Search Result");
+               BT_DBG("OAL Event: GATT Client Descriptor Search Result");
                __bt_handle_client_descriptor_search_result((event_gattc_descriptor_result_t *) event_data);
                break;
        }
        case OAL_EVENT_GATTC_READ_CHARAC: {
-               BT_INFO("OAL Event: GATT Client Characteristic Read Data");
+               BT_DBG("OAL Event: GATT Client Characteristic Read Data");
                __bt_handle_client_characteristic_read_data((event_gattc_read_data *) event_data);
                break;
        }
        case OAL_EVENT_GATTC_READ_DESCR: {
-               BT_INFO("OAL Event: GATT Client Descriptor Read Data");
+               BT_DBG("OAL Event: GATT Client Descriptor Read Data");
                __bt_handle_client_descriptor_read_data((event_gattc_read_data *) event_data);
                break;
        }
        case OAL_EVENT_GATTC_WRITE_CHARAC: {
-               BT_INFO("OAL Event: GATT Client Characteristic Write Data");
+               BT_DBG("OAL Event: GATT Client Characteristic Write Data");
                __bt_handle_client_characteristic_write_data((event_gattc_write_data *) event_data);
                break;
        }
        case OAL_EVENT_GATTC_WRITE_DESCR: {
-               BT_INFO("OAL Event: GATT Client Descriptor Write Data");
+               BT_DBG("OAL Event: GATT Client Descriptor Write Data");
                __bt_handle_client_descriptor_write_data((event_gattc_write_data *) event_data);
                break;
        }
@@ -2219,7 +2230,7 @@ static void __bt_gatt_event_handler(int event_type, gpointer event_data)
                break;
        }
        case OAL_EVENT_GATTC_NOTIFY_DATA: {
-               BT_INFO("OAL Event: GATT Client Notification Data");
+               BT_DBG("OAL Event: GATT Client Notification Data");
                __bt_handle_client_notification_data((event_gattc_notify_data *) event_data);
                break;
        }
@@ -3028,7 +3039,7 @@ int _bt_register_gatt_client_instance(const char *sender,
        oal_uuid_t uuid;
 
        /* App should ensure that it should not send */
-       BT_INFO("### Check on which instance GATT Client instance can be initialized....");
+       BT_INFO("Check on which instance GATT Client instance can be initialized....");
        for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
                if (numapps[k].is_initialized == 1) {
                        BT_INFO("Instance ID [%d] is already in use..Check next slot",
@@ -3153,6 +3164,9 @@ static void __bt_handle_client_connected(event_gattc_conn_t *event_data)
                        conn_info = g_new0(struct gatt_server_info_t, 1);
                        conn_info->addr = g_strdup(address);
                        conn_info->client_id = event_data->client_if;
+#ifdef __INTEGRATE_GATT_INFO__
+                       conn_info->instance_id = -1;
+#endif
                        conn_info->connection_id = event_data->conn_id;
                        gatt_server_info_list = g_slist_append(gatt_server_info_list, conn_info);
                        BT_DBG("Total num of connected Remote GATT server devices [%d]",
@@ -3457,7 +3471,7 @@ static void __bt_handle_client_descriptor_search_result(
        bt_gatt_descriptor_info_t *desc_info;
        bt_descriptor_browse_info_t browse_info;
 
-       BT_INFO("descriptor search result status [%d]", event_data->conn_status.status);
+       BT_DBG("descriptor search result status [%d]", event_data->conn_status.status);
 
        memset(&browse_info, 0x00, sizeof(bt_descriptor_browse_info_t));
 
@@ -4019,20 +4033,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,
@@ -4340,10 +4350,6 @@ int _bt_gatt_get_primary_services(char *address)
                return BLUETOOTH_ERROR_NOT_CONNECTED;
        }
 
-       BT_INFO("Remove GATT server info from List..");
-       /* Remove all services from info list_gatt_info */
-       __bt_cleanup_remote_services(conn_info);
-
        /* Send Primary Service Browsing request to stack */
        ret = gattc_search_service(conn_info->connection_id, NULL);
        if (ret != OAL_STATUS_SUCCESS) {
@@ -4368,7 +4374,7 @@ int _bt_gatt_get_all_characteristic(bluetooth_gatt_client_svc_prop_info_t *svc)
        if (req_info) {
                prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
                if (prop && !memcmp(svc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t))
-                               && memcmp(prop->svc.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
+                               && !memcmp(prop->svc.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
                                && prop->svc.instance_id == svc->svc.instance_id) {
                        BT_INFO("Already Properties browsing for Primary Service ongoing for same remote GATT Server");
                        /* Return and wait for events to be sent to all apps */
@@ -4424,9 +4430,9 @@ int _bt_gatt_get_all_characteristic_properties(
        if (req_info) {
                prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
                if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
-                               && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
+                               && !memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
                                && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
-                               && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
+                               && !memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
                                && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
                        BT_INFO("Already Properties browsing for Characteristic ongoing for same remote GATT Server");
                        /* Return and wait for events to be sent to all apps */
@@ -4880,11 +4886,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);
 
@@ -4994,7 +5000,7 @@ int _bt_unregister_gatt_client_instance(const char *sender, int client_id)
        bt_service_app_info_t *info = NULL;
        int k, ret;
 
-       BT_INFO("Unregister Allocated GATT Client instance [%s] Client ID [%d]", sender, client_id);
+       BT_DBG("Unregister Allocated GATT Client instance [%s] Client ID [%d]", sender, client_id);
 
        /* Unregister CLient instance associated with address X. It is possible that another app still
           has client_id valid for same remote address */
@@ -5003,7 +5009,6 @@ int _bt_unregister_gatt_client_instance(const char *sender, int client_id)
 
                /* Exact matching of sender */
                if (!g_strcmp0(info->sender, sender) && info->client_id == client_id) {  /* Check for only valid GATT client Instance */
-                       BT_INFO("Unregister GATT client instance [%d]", info->client_id);
                        numapps[k].client_id = -1;
                        numapps[k].is_initialized = FALSE;
                        memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
@@ -5140,5 +5145,70 @@ static void __bt_update_mtu_gatt_device(char *address, int mtu)
        }
 }
 
+int _bt_gatt_get_data_batching_available_packets(
+               guint *available_packets)
+{
+       int ret = OAL_STATUS_SUCCESS;
+
+       BT_CHECK_PARAMETER(available_packets, return);
+
+       ret = gatt_get_data_batching_available_packets(available_packets);
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               if (ret == OAL_STATUS_NOT_SUPPORT)
+                       return BLUETOOTH_ERROR_NOT_SUPPORT;
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_gatt_enable_data_batching(bluetooth_device_address_t *address,
+               int packet_threshold, int timeout)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       char remote_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+       BT_CHECK_PARAMETER(address, return);
+
+       _bt_convert_addr_type_to_string(remote_address, address->addr);
+       BT_INFO("Enable GATT data batching. address[%s] packet_threshold[%d] timeout[%d]",
+                       remote_address, packet_threshold, timeout);
+
+       ret = gatt_enable_data_batching((bt_address_t*)(address), packet_threshold, timeout);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               if (ret == OAL_STATUS_INVALID_PARAM)
+                       return BLUETOOTH_ERROR_INVALID_PARAM;
+               else if (ret == OAL_STATUS_NOT_SUPPORT)
+                       return BLUETOOTH_ERROR_NOT_SUPPORT;
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_gatt_disable_data_batching(bluetooth_device_address_t *address)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       char remote_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+       BT_CHECK_PARAMETER(address, return);
+
+       _bt_convert_addr_type_to_string(remote_address, address->addr);
+       BT_INFO("Disable GATT data batching. address[%s]", remote_address);
+
+       ret = gatt_disable_data_batching((bt_address_t*)(address));
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               if (ret == OAL_STATUS_NOT_SUPPORT)
+                       return BLUETOOTH_ERROR_NOT_SUPPORT;
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
 
 #endif