diff options
author | Gowtham Anandha Babu <gowtham.ab@samsung.com> | 2017-08-02 17:37:45 +0530 |
---|---|---|
committer | Gowtham Anandha Babu <gowtham.ab@samsung.com> | 2017-08-02 17:37:45 +0530 |
commit | b2a3a66fed84ede3735db47b4784dd25ac36cb8c (patch) | |
tree | f155b1ab692a41de3601eeb741b6d46a406a5557 /src/bluetooth-otp.c | |
parent | 1a55a3b7e4e261161999a7598528899770014e38 (diff) | |
download | bluetooth-b2a3a66fed84ede3735db47b4784dd25ac36cb8c.tar.gz bluetooth-b2a3a66fed84ede3735db47b4784dd25ac36cb8c.tar.bz2 bluetooth-b2a3a66fed84ede3735db47b4784dd25ac36cb8c.zip |
[OTP] Add support for service changed indication
Change-Id: I2a0fe7d3e26904f4d11dbe6a5dc5af0b9a81d199
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
Diffstat (limited to 'src/bluetooth-otp.c')
-rw-r--r-- | src/bluetooth-otp.c | 48 |
1 files changed, 48 insertions, 0 deletions
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); |