gatt-services/battery_service_client: validate that services contain battery level characteristic

This commit is contained in:
Milanka Ringwald 2021-06-08 10:36:21 +02:00
parent 1287373805
commit 4436e8564b

View File

@ -285,6 +285,21 @@ static void battery_service_poll_timer_start(battery_service_client_t * client){
btstack_run_loop_add_timer(&client->poll_timer);
}
static void battery_service_client_validate_service(battery_service_client_t * client){
// remove all services without characteristic (array in-place)
uint8_t src_index = 0; // next entry to check
uint8_t dest_index = 0; // to store entry
for (src_index = 0; src_index < client->num_instances; src_index++){
if (client->services[src_index].value_handle != 0){
if (src_index != dest_index) {
client->services[dest_index] = client->services[src_index];
}
dest_index++;
}
}
client->num_instances = dest_index;
}
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(packet_type);
UNUSED(channel);
@ -448,6 +463,14 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
break;
}
battery_service_client_validate_service(client);
if (client->num_instances == 0){
battery_service_emit_connection_established(client, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
battery_service_finalize_client(client);
return;
}
// we are done with quering all services
client->service_index = 0;