From a2489f29b69b390e439f0c4b7625d1ea183bde18 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 1 Oct 2020 17:51:13 +0200 Subject: [PATCH] gatt-services: use assert to check service found in att db --- src/ble/gatt-service/battery_service_server.c | 3 ++- src/ble/gatt-service/cycling_power_service_server.c | 7 +++---- .../cycling_speed_and_cadence_service_server.c | 7 +++---- src/ble/gatt-service/heart_rate_service_server.c | 3 ++- src/ble/gatt-service/hids_device.c | 3 ++- src/ble/gatt-service/mesh_provisioning_service_server.c | 4 ++-- src/ble/gatt-service/mesh_proxy_service_server.c | 4 ++-- src/ble/gatt-service/nordic_spp_service_server.c | 3 ++- src/ble/gatt-service/ublox_spp_service_server.c | 3 ++- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/ble/gatt-service/battery_service_server.c b/src/ble/gatt-service/battery_service_server.c index 03d24c885..af6512a01 100644 --- a/src/ble/gatt-service/battery_service_server.c +++ b/src/ble/gatt-service/battery_service_server.c @@ -100,7 +100,8 @@ void battery_service_server_init(uint8_t value){ uint16_t start_handle = 0; uint16_t end_handle = 0xfff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE, &start_handle, &end_handle); - btstack_assert(service_found); + btstack_assert(service_found != 0); + UNUSED(service_found); // get characteristic value handle and client configuration handle battery_value_handle_value = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL); diff --git a/src/ble/gatt-service/cycling_power_service_server.c b/src/ble/gatt-service/cycling_power_service_server.c index 9ea15add9..990239676 100644 --- a/src/ble/gatt-service/cycling_power_service_server.c +++ b/src/ble/gatt-service/cycling_power_service_server.c @@ -1030,10 +1030,9 @@ void cycling_power_service_server_init(uint32_t feature_flags, uint16_t start_handle = 0; uint16_t end_handle = 0xffff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_CYCLING_POWER, &start_handle, &end_handle); - if (!service_found){ - log_error("no service found\n"); - return; - } + btstack_assert(service_found != 0); + UNUSED(service_found); + // get CP Mesurement characteristic value handle and client configuration handle instance->measurement_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_CYCLING_POWER_MEASUREMENT); instance->measurement_client_configuration_descriptor_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_CYCLING_POWER_MEASUREMENT); diff --git a/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c b/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c index 259295dad..320660444 100644 --- a/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c +++ b/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c @@ -305,10 +305,9 @@ void cycling_speed_and_cadence_service_server_init(uint32_t supported_sensor_loc uint16_t start_handle = 0; uint16_t end_handle = 0xffff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_CYCLING_SPEED_AND_CADENCE, &start_handle, &end_handle); - if (!service_found){ - // printf("no service found\n"); - return; - } + btstack_assert(service_found != 0); + UNUSED(service_found); + // // get CSC Mesurement characteristic value handle and client configuration handle instance->measurement_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_CSC_MEASUREMENT); instance->measurement_client_configuration_descriptor_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_CSC_MEASUREMENT); diff --git a/src/ble/gatt-service/heart_rate_service_server.c b/src/ble/gatt-service/heart_rate_service_server.c index 7c34b1a8c..91f50abfb 100644 --- a/src/ble/gatt-service/heart_rate_service_server.c +++ b/src/ble/gatt-service/heart_rate_service_server.c @@ -150,7 +150,8 @@ void heart_rate_service_server_init(heart_rate_service_body_sensor_location_t lo uint16_t start_handle = 0; uint16_t end_handle = 0xffff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_HEART_RATE, &start_handle, &end_handle); - if (!service_found) return; + btstack_assert(service_found != 0); + UNUSED(service_found); // get Heart Rate Mesurement characteristic value handle and client configuration handle instance->measurement_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_HEART_RATE_MEASUREMENT); diff --git a/src/ble/gatt-service/hids_device.c b/src/ble/gatt-service/hids_device.c index 0abb921dd..415e9591c 100644 --- a/src/ble/gatt-service/hids_device.c +++ b/src/ble/gatt-service/hids_device.c @@ -288,7 +288,8 @@ void hids_device_init(uint8_t country_code, const uint8_t * descriptor, uint16_t uint16_t start_handle = 0; uint16_t end_handle = 0xfff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE, &start_handle, &end_handle); - if (!service_found) return; + btstack_assert(service_found != 0); + UNUSED(service_found); // get report map handle instance->hid_report_map_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT_MAP); diff --git a/src/ble/gatt-service/mesh_provisioning_service_server.c b/src/ble/gatt-service/mesh_provisioning_service_server.c index 48c978bc2..20413d80d 100644 --- a/src/ble/gatt-service/mesh_provisioning_service_server.c +++ b/src/ble/gatt-service/mesh_provisioning_service_server.c @@ -197,8 +197,8 @@ void mesh_provisioning_service_server_init(void){ uint16_t start_handle = 0; uint16_t end_handle = 0xffff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_MESH_PROVISIONING, &start_handle, &end_handle); - - if (!service_found) return; + btstack_assert(service_found != 0); + UNUSED(service_found); instance->data_in_client_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_MESH_PROVISIONING_DATA_IN); instance->data_out_client_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_MESH_PROVISIONING_DATA_OUT); diff --git a/src/ble/gatt-service/mesh_proxy_service_server.c b/src/ble/gatt-service/mesh_proxy_service_server.c index 08f5770b3..116f0f55f 100644 --- a/src/ble/gatt-service/mesh_proxy_service_server.c +++ b/src/ble/gatt-service/mesh_proxy_service_server.c @@ -160,8 +160,8 @@ void mesh_proxy_service_server_init(void){ uint16_t start_handle = 0; uint16_t end_handle = 0xffff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_MESH_PROXY, &start_handle, &end_handle); - - if (!service_found) return; + btstack_assert(service_found != 0); + UNUSED(service_found); instance->data_in_client_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_MESH_PROXY_DATA_IN); instance->data_out_client_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_MESH_PROXY_DATA_OUT); diff --git a/src/ble/gatt-service/nordic_spp_service_server.c b/src/ble/gatt-service/nordic_spp_service_server.c index 94c6ef1b1..a08016430 100644 --- a/src/ble/gatt-service/nordic_spp_service_server.c +++ b/src/ble/gatt-service/nordic_spp_service_server.c @@ -113,7 +113,8 @@ void nordic_spp_service_server_init(void (*callback)(hci_con_handle_t con_handle uint16_t start_handle = 0; uint16_t end_handle = 0xffff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid128(nordic_spp_profile_uuid128, &start_handle, &end_handle); - if (!service_found) return; + btstack_assert(service_found != 0); + UNUSED(service_found); // get characteristic value handle and client configuration handle nordic_spp_rx_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid128(start_handle, end_handle, nordic_spp_rx_uuid128); diff --git a/src/ble/gatt-service/ublox_spp_service_server.c b/src/ble/gatt-service/ublox_spp_service_server.c index 63580629e..017316aa3 100644 --- a/src/ble/gatt-service/ublox_spp_service_server.c +++ b/src/ble/gatt-service/ublox_spp_service_server.c @@ -221,7 +221,8 @@ void ublox_spp_service_server_init(void (*client_data_callback)(hci_con_handle_t uint16_t start_handle = 0; uint16_t end_handle = 0xfff; int service_found = gatt_server_get_get_handle_range_for_service_with_uuid128(ublox_spp_profile_uuid128, &start_handle, &end_handle); - if (!service_found) return; + btstack_assert(service_found != 0); + UNUSED(service_found); // get characteristic value handle and client configuration handle // FIFO