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)
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)
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;
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);