From: Gowtham Anandha Babu Date: Wed, 2 Aug 2017 12:07:45 +0000 (+0530) Subject: [OTP] Add support for service changed indication X-Git-Tag: submit/tizen/20170808.020532~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F04%2F142104%2F1;p=platform%2Fcore%2Fapi%2Fbluetooth.git [OTP] Add support for service changed indication Change-Id: I2a0fe7d3e26904f4d11dbe6a5dc5af0b9a81d199 Signed-off-by: Gowtham Anandha Babu --- diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index f1eab2f..923fff2 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -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, diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index a7fb862..48f8f92 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -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; diff --git a/src/bluetooth-otp.c b/src/bluetooth-otp.c index dd67571..8f1f30d 100644 --- a/src/bluetooth-otp.c +++ b/src/bluetooth-otp.c @@ -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);