Fix: advertisinog stopped suddenly
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / gatt / bt-service-gatt.c
index 3067535..18798a4 100644 (file)
@@ -340,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.
@@ -1229,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));
 
@@ -1237,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;
@@ -5145,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