[OTP] Add support for service changed indication 04/142104/1
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 2 Aug 2017 12:07:45 +0000 (17:37 +0530)
committerGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 2 Aug 2017 12:07:45 +0000 (17:37 +0530)
Change-Id: I2a0fe7d3e26904f4d11dbe6a5dc5af0b9a81d199
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
include/bluetooth_private.h
src/bluetooth-common.c
src/bluetooth-otp.c

index f1eab2f3d93ccdb42e6d6af647d457b4d109c813..923fff2e53189b614033b7a5bbfcd49341a49bc4 100644 (file)
@@ -902,6 +902,12 @@ void _bt_otp_client_indication(int result, bluetooth_otp_resp_info_t *info);
  */
 void _bt_otc_connection_state_changed(int result, bluetooth_otc_info_t *otc_info);
 
+/**
+ * @internal
+ * @brief Sends GATT primary service status changed of Remote Server.
+ */
+void _bt_otp_check_service_changed(char *address, bt_gatt_service_change_t *service_change);
+
 typedef enum {
        _PROFILE_UNKNOWN = 0,
        _PROFILE_MOBILE = 0x1,
index a7fb862d5575b6bc584e56f8a655303ed66395d3..48f8f9252f7e7eae5b577381608e76ec0195a063 100644 (file)
@@ -2314,6 +2314,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                /* Check if TDS Service removed */
                _bt_tds_check_service_changed(device_addr, service_change);
 
+               /* Check if OTS Service removed */
+               _bt_otp_check_service_changed(device_addr, service_change);
+
                client = _bt_gatt_get_client(device_addr);
                g_free(device_addr);
                device_addr = NULL;
index dd675717f4d153fa263734ef42541f659db2be8b..8f1f30d7a36f6fb1702e4463a0db6d3131748759 100644 (file)
@@ -700,6 +700,41 @@ fail:
        return ret;
 }
 
+void _bt_otp_check_service_changed(char *address, bt_gatt_service_change_t *service_change)
+{
+       bt_otp_client_s *otp_client_s = NULL;
+       int error_code = BLUETOOTH_ERROR_NONE;
+       bluetooth_device_address_t addr_hex = { {0,} };
+       if (!address) {
+               BT_ERR("Abnormal Result!!");
+               return;
+       }
+       otp_client_s = _bt_otp_client_find(address);
+       BT_DBG("GATT Service state changed [%d]", service_change->change_type);
+       BT_DBG("GATT Service [%s]", service_change->svc_path);
+       if (otp_client_s) {
+               if (service_change->change_type ==  BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_REMOVE) {
+                       if (otp_client_s->otp_service_handle &&
+                                       g_strcmp0(otp_client_s->otp_service_handle, service_change->svc_path) == 0) {
+                               BT_ERR("OTS Primary Service removed abnormally from Remote Server [%s]", address);
+                               __bt_otp_client_reset_server_data(otp_client_s);
+                       }
+               } else {
+                       _bt_convert_address_to_hex(&addr_hex, address);
+
+                       /* Attempt to update OTS Service data if service added is OTS service */
+                       if (__bt_update_otp_server_data(&addr_hex, otp_client_s) == BLUETOOTH_ERROR_NONE) {
+                               BT_INFO("OTS Primary Service added in Remote Server [%s]", address);
+                               /* Set Service changed Watcher */
+                               error_code = bluetooth_gatt_set_service_change_watcher(&addr_hex, true);
+                               if (error_code != BLUETOOTH_ERROR_NONE)
+                                       BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
+                       }
+               }
+       }
+       BT_DBG("-");
+}
+
 void _bt_otp_client_connection_state_changed(int result,
                                        const char *remote_address,
                                        bool connected)
@@ -717,6 +752,7 @@ void _bt_otp_client_connection_state_changed(int result,
                if (result != BT_ERROR_NONE) {
                        BT_ERR("GATT Connect Request failed Address [%s]", remote_address);
                        __bt_otp_client_reset_server_data(otp_client_s);
+                       bluetooth_gatt_set_service_change_watcher(&addr_hex, false);
 
                        if (otp_client_s->connection_callback)
                                ((bt_otp_client_state_changed_cb)otp_client_s->connection_callback)
@@ -731,10 +767,16 @@ void _bt_otp_client_connection_state_changed(int result,
                        error_code = __bt_update_otp_server_data(&addr_hex, otp_client_s);
                        if (error_code != BLUETOOTH_ERROR_NONE)
                                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
+
+                       /* Set Service changed Watcher */
+                       error_code = bluetooth_gatt_set_service_change_watcher(&addr_hex, true);
+                       if (error_code != BLUETOOTH_ERROR_NONE)
+                               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
                } else {
                        BT_DBG("Remote device disconnected successfully");
                        /* Disconnected */
                        __bt_otp_client_reset_server_data(otp_client_s);
+                       bluetooth_gatt_set_service_change_watcher(&addr_hex, false);
                }
                otp_client_s->connected = connected;
 
@@ -795,6 +837,12 @@ int bt_otp_client_create(const char *remote_address, bt_otp_client_h *otp_client
                        g_free(otp_client_s);
                        return BT_ERROR_OPERATION_FAILED;
                }
+               error_code = bluetooth_gatt_set_service_change_watcher(&addr_hex, true);
+               if (error_code != BLUETOOTH_ERROR_NONE) {
+                       __bt_otp_client_reset_server_data(otp_client_s);
+                       g_free(otp_client_s);
+                       return BT_ERROR_OPERATION_FAILED;
+               }
        }
 
        otp_client_s->remote_address = g_strdup(remote_address);