gatt-service/bass_server: update internal function names

This commit is contained in:
Milanka Ringwald 2023-01-27 15:46:54 +01:00 committed by Matthias Ringwald
parent d13efa9465
commit c4f227df18

View File

@ -58,7 +58,7 @@
#define BASS_INVALID_SOURCE_INDEX 0xFF
static att_service_handler_t broadcast_audio_scan_service;
static btstack_packet_handler_t bass_event_callback;
static btstack_packet_handler_t bass_server_event_callback;
// characteristic: AUDIO_SCAN_CONTROL_POINT
static uint16_t bass_audio_scan_control_point_handle;
@ -71,7 +71,7 @@ static broadcast_audio_scan_service_server_t * bass_clients;
static uint8_t bass_clients_num = 0;
static btstack_context_callback_registration_t scheduled_tasks_callback;
static uint8_t bass_get_next_update_counter(void){
static uint8_t bass_server_get_next_update_counter(void){
uint8_t next_update_counter;
if (bass_logic_time == 0xff) {
next_update_counter = 0;
@ -83,11 +83,11 @@ static uint8_t bass_get_next_update_counter(void){
}
// returns positive number if counter a > b
static int8_t bass_counter_delta(uint8_t counter_a, uint8_t counter_b){
static int8_t bass_server_counter_delta(uint8_t counter_a, uint8_t counter_b){
return (int8_t)(counter_a - counter_b);
}
static uint8_t bass_find_empty_or_last_used_source_index(void){
static uint8_t bass_server_find_empty_or_last_used_source_index(void){
bass_server_source_t * last_used_source = NULL;
uint8_t last_used_source_index = BASS_INVALID_SOURCE_INDEX;
@ -101,7 +101,7 @@ static uint8_t bass_find_empty_or_last_used_source_index(void){
last_used_source_index = i;
continue;
}
if (bass_counter_delta(bass_sources[i].update_counter, last_used_source->update_counter) < 0 ){
if (bass_server_counter_delta(bass_sources[i].update_counter, last_used_source->update_counter) < 0 ){
last_used_source = &bass_sources[i];
last_used_source_index = i;
}
@ -109,15 +109,15 @@ static uint8_t bass_find_empty_or_last_used_source_index(void){
return last_used_source_index;
}
static bass_server_source_t * bass_find_empty_or_last_used_source(void){
uint8_t last_used_source_index = bass_find_empty_or_last_used_source_index();
static bass_server_source_t * bass_server_find_empty_or_last_used_source(void){
uint8_t last_used_source_index = bass_server_find_empty_or_last_used_source_index();
if (last_used_source_index == BASS_INVALID_SOURCE_INDEX){
return NULL;
}
return &bass_sources[last_used_source_index];
}
static bass_server_source_t * bass_find_receive_state_for_value_handle(uint16_t attribute_handle){
static bass_server_source_t * bass_server_find_receive_state_for_value_handle(uint16_t attribute_handle){
uint16_t i;
for (i = 0; i < bass_sources_num; i++){
if (attribute_handle == bass_sources[i].bass_receive_state_handle){
@ -127,7 +127,7 @@ static bass_server_source_t * bass_find_receive_state_for_value_handle(uint16_t
return NULL;
}
static bass_server_source_t * bass_find_receive_state_for_client_configuration_handle(uint16_t attribute_handle){
static bass_server_source_t * bass_server_find_receive_state_for_client_configuration_handle(uint16_t attribute_handle){
if (attribute_handle == 0){
return NULL;
}
@ -140,14 +140,14 @@ static bass_server_source_t * bass_find_receive_state_for_client_configuration_h
return NULL;
}
static bass_server_source_t * bass_find_source_for_source_id(uint8_t source_id){
static bass_server_source_t * bass_server_find_source_for_source_id(uint8_t source_id){
if (source_id < bass_sources_num){
return &bass_sources[source_id];
}
return NULL;
}
static broadcast_audio_scan_service_server_t * bass_find_client_for_con_handle(hci_con_handle_t con_handle){
static broadcast_audio_scan_service_server_t * bass_server_find_client_for_con_handle(hci_con_handle_t con_handle){
uint16_t i;
for (i = 0; i < bass_clients_num; i++){
if (bass_clients[i].con_handle == con_handle) {
@ -157,10 +157,10 @@ static broadcast_audio_scan_service_server_t * bass_find_client_for_con_handle(h
return NULL;
}
static void bass_register_con_handle(hci_con_handle_t con_handle, uint16_t client_configuration){
broadcast_audio_scan_service_server_t * client = bass_find_client_for_con_handle(con_handle);
static void bass_server_register_con_handle(hci_con_handle_t con_handle, uint16_t client_configuration){
broadcast_audio_scan_service_server_t * client = bass_server_find_client_for_con_handle(con_handle);
if (client == NULL){
client = bass_find_client_for_con_handle(HCI_CON_HANDLE_INVALID);
client = bass_server_find_client_for_con_handle(HCI_CON_HANDLE_INVALID);
if (client == NULL){
return;
}
@ -169,8 +169,8 @@ static void bass_register_con_handle(hci_con_handle_t con_handle, uint16_t clien
client->con_handle = (client_configuration == 0) ? HCI_CON_HANDLE_INVALID : con_handle;
}
static void bass_emit_scan_stoped(hci_con_handle_t con_handle){
btstack_assert(bass_event_callback != NULL);
static void bass_server_source_emit_scan_stoped(hci_con_handle_t con_handle){
btstack_assert(bass_server_event_callback != NULL);
uint8_t event[5];
uint8_t pos = 0;
@ -179,11 +179,11 @@ static void bass_emit_scan_stoped(hci_con_handle_t con_handle){
event[pos++] = GATTSERVICE_SUBEVENT_BASS_SERVER_SCAN_STOPPED;
little_endian_store_16(event, pos, con_handle);
pos += 2;
(*bass_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
(*bass_server_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void bass_emit_scan_started(hci_con_handle_t con_handle){
btstack_assert(bass_event_callback != NULL);
static void bass_server_source_emit_scan_started(hci_con_handle_t con_handle){
btstack_assert(bass_server_event_callback != NULL);
uint8_t event[5];
uint8_t pos = 0;
@ -192,12 +192,12 @@ static void bass_emit_scan_started(hci_con_handle_t con_handle){
event[pos++] = GATTSERVICE_SUBEVENT_BASS_SERVER_SCAN_STARTED;
little_endian_store_16(event, pos, con_handle);
pos += 2;
(*bass_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
(*bass_server_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void bass_emit_source_state_changed(uint8_t subevent_id, hci_con_handle_t con_handle, uint8_t source_id, le_audio_pa_sync_t pa_sync){
btstack_assert(bass_event_callback != NULL);
static void bass_server_source_emit_source_state_changed(uint8_t subevent_id, hci_con_handle_t con_handle, uint8_t source_id, le_audio_pa_sync_t pa_sync){
btstack_assert(bass_server_event_callback != NULL);
uint8_t event[7];
uint8_t pos = 0;
@ -208,23 +208,23 @@ static void bass_emit_source_state_changed(uint8_t subevent_id, hci_con_handle_t
pos += 2;
event[pos++] = source_id;
event[pos++] = (uint8_t)pa_sync;
(*bass_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
(*bass_server_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void bass_emit_source_added(hci_con_handle_t con_handle, bass_server_source_t * source){
bass_emit_source_state_changed(GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_ADDED, con_handle, source->source_id, source->data.pa_sync);
static void bass_server_source_emit_source_added(hci_con_handle_t con_handle, bass_server_source_t * source){
bass_server_source_emit_source_state_changed(GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_ADDED, con_handle, source->source_id, source->data.pa_sync);
}
static void bass_emit_source_modified(hci_con_handle_t con_handle, bass_server_source_t * source){
bass_emit_source_state_changed(GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_MODIFIED, con_handle, source->source_id, source->data.pa_sync);
static void bass_server_source_emit_source_modified(hci_con_handle_t con_handle, bass_server_source_t * source){
bass_server_source_emit_source_state_changed(GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_MODIFIED, con_handle, source->source_id, source->data.pa_sync);
}
static void bass_emit_source_deleted(hci_con_handle_t con_handle, bass_server_source_t * source){
bass_emit_source_state_changed(GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_DELETED, con_handle, source->source_id, LE_AUDIO_PA_SYNC_DO_NOT_SYNCHRONIZE_TO_PA);
static void bass_server_source_emit_source_deleted(hci_con_handle_t con_handle, bass_server_source_t * source){
bass_server_source_emit_source_state_changed(GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_DELETED, con_handle, source->source_id, LE_AUDIO_PA_SYNC_DO_NOT_SYNCHRONIZE_TO_PA);
}
static void bass_emit_broadcast_code(hci_con_handle_t con_handle, uint8_t source_id, const uint8_t * broadcast_code){
btstack_assert(bass_event_callback != NULL);
static void bass_server_source_emit_broadcast_code(hci_con_handle_t con_handle, uint8_t source_id, const uint8_t * broadcast_code){
btstack_assert(bass_server_event_callback != NULL);
uint8_t event[22];
uint8_t pos = 0;
@ -236,7 +236,7 @@ static void bass_emit_broadcast_code(hci_con_handle_t con_handle, uint8_t source
event[pos++] = source_id;
reverse_128(broadcast_code, &event[pos]);
pos += 16;
(*bass_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
(*bass_server_event_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
// offset gives position into fully serialized bass record
@ -280,16 +280,16 @@ static uint16_t bass_server_copy_source_to_buffer(bass_server_source_t * source,
return stored_bytes;
}
static uint16_t broadcast_audio_scan_service_read_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
static uint16_t bass_server_read_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
UNUSED(con_handle);
bass_server_source_t * source;
source = bass_find_receive_state_for_value_handle(attribute_handle);
source = bass_server_find_receive_state_for_value_handle(attribute_handle);
if (source){
return bass_server_copy_source_to_buffer(source, offset, buffer, buffer_size);
}
source = bass_find_receive_state_for_client_configuration_handle(attribute_handle);
source = bass_server_find_receive_state_for_client_configuration_handle(attribute_handle);
if (source){
return att_read_callback_handle_little_endian_16(source->bass_receive_state_client_configuration, offset, buffer, buffer_size);
}
@ -297,7 +297,7 @@ static uint16_t broadcast_audio_scan_service_read_callback(hci_con_handle_t con_
return 0;
}
static bool bass_source_remote_modify_source_buffer_valid(uint8_t *buffer, uint16_t buffer_size){
static bool bass_server_source_remote_modify_source_buffer_valid(uint8_t *buffer, uint16_t buffer_size){
if (buffer_size < 10){
log_info("Modify Source opcode, buffer too small");
return false;
@ -310,18 +310,18 @@ static bool bass_source_remote_modify_source_buffer_valid(uint8_t *buffer, uint1
static void bass_server_add_source_from_buffer(uint8_t *buffer, uint16_t buffer_size, bass_server_source_t * source){
UNUSED(buffer_size);
source->update_counter = bass_get_next_update_counter();
source->update_counter = bass_server_get_next_update_counter();
source->in_use = true;
bass_util_source_data_parse(buffer, buffer_size, &source->data, false);
}
static bool bass_pa_synchronized(bass_server_source_t * source){
static bool bass_server_pa_synchronized(bass_server_source_t * source){
return source->data.pa_sync_state == LE_AUDIO_PA_SYNC_STATE_SYNCHRONIZED_TO_PA;
}
static bool bass_bis_synchronized(bass_server_source_t * source){
static bool bass_server_bis_synchronized(bass_server_source_t * source){
uint8_t i;
for (i = 0; i < source->data.subgroups_num; i++){
if ((source->data.subgroups[i].bis_sync_state > 0) && (source->data.subgroups[i].bis_sync_state < 0xFFFFFFFF)){
@ -332,7 +332,7 @@ static bool bass_bis_synchronized(bass_server_source_t * source){
}
static void bass_reset_source(bass_server_source_t * source){
static void bass_server_reset_source(bass_server_source_t * source){
source->in_use = false;
source->data.address_type = BD_ADDR_TYPE_LE_PUBLIC;
memset(source->data.address, 0, sizeof(source->data.address));
@ -347,25 +347,25 @@ static void bass_reset_source(bass_server_source_t * source){
memset(source->data.subgroups, 0, sizeof(source->data.subgroups));
}
static void bass_reset_client_long_write_buffer(broadcast_audio_scan_service_server_t * client){
static void bass_server_reset_client_long_write_buffer(broadcast_audio_scan_service_server_t * client){
memset(client->long_write_buffer, 0, sizeof(client->long_write_buffer));
client->long_write_value_size = 0;
}
static int broadcast_audio_scan_service_write_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){
// printf("broadcast_audio_scan_service_write_callback con_handle 0x%02x, attr_handle 0x%02x \n", con_handle, attribute_handle);
static int bass_server_write_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){
// printf("bass_server_write_callback con_handle 0x%02x, attr_handle 0x%02x \n", con_handle, attribute_handle);
if (attribute_handle != 0 && attribute_handle != bass_audio_scan_control_point_handle){
bass_server_source_t * source = bass_find_receive_state_for_client_configuration_handle(attribute_handle);
bass_server_source_t * source = bass_server_find_receive_state_for_client_configuration_handle(attribute_handle);
if (source){
source->bass_receive_state_client_configuration = little_endian_read_16(buffer, 0);
bass_register_con_handle(con_handle, source->bass_receive_state_client_configuration);
bass_server_register_con_handle(con_handle, source->bass_receive_state_client_configuration);
}
return 0;
}
broadcast_audio_scan_service_server_t * client = bass_find_client_for_con_handle(con_handle);
broadcast_audio_scan_service_server_t * client = bass_server_find_client_for_con_handle(con_handle);
if (client == NULL){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
@ -375,7 +375,7 @@ static int broadcast_audio_scan_service_write_callback(hci_con_handle_t con_hand
switch (transaction_mode){
case ATT_TRANSACTION_MODE_NONE:
if (buffer_size > sizeof(client->long_write_buffer)){
bass_reset_client_long_write_buffer(client);
bass_server_reset_client_long_write_buffer(client);
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
memcpy(&client->long_write_buffer[0], buffer, buffer_size);
@ -384,7 +384,7 @@ static int broadcast_audio_scan_service_write_callback(hci_con_handle_t con_hand
case ATT_TRANSACTION_MODE_ACTIVE:
if (total_value_len > sizeof(client->long_write_buffer)){
bass_reset_client_long_write_buffer(client);
bass_server_reset_client_long_write_buffer(client);
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
// allow overlapped and/or mixed order chunks
@ -423,39 +423,39 @@ static int broadcast_audio_scan_service_write_callback(hci_con_handle_t con_hand
if (remote_data_size != 1){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
bass_emit_scan_stoped(con_handle);
bass_server_source_emit_scan_stoped(con_handle);
break;
case BASS_OPCODE_REMOTE_SCAN_STARTED:
if (remote_data_size != 1){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
bass_emit_scan_started(con_handle);
bass_server_source_emit_scan_started(con_handle);
break;
case BASS_OPCODE_ADD_SOURCE:
if (!bass_util_source_buffer_in_valid_range(remote_data, remote_data_size)){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
source = bass_find_empty_or_last_used_source();
source = bass_server_find_empty_or_last_used_source();
btstack_assert(source != NULL);
log_info("add source %d", source->source_id);
bass_server_add_source_from_buffer(remote_data, remote_data_size, source);
bass_emit_source_added(con_handle, source);
bass_server_source_emit_source_added(con_handle, source);
// server needs to trigger notification
break;
case BASS_OPCODE_MODIFY_SOURCE:
if (!bass_source_remote_modify_source_buffer_valid(remote_data, remote_data_size)){
if (!bass_server_source_remote_modify_source_buffer_valid(remote_data, remote_data_size)){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
source = bass_find_source_for_source_id(remote_data[0]);
source = bass_server_find_source_for_source_id(remote_data[0]);
if (source == NULL){
return BASS_ERROR_CODE_INVALID_SOURCE_ID;
}
bass_util_pa_info_and_subgroups_parse(remote_data + 1, remote_data_size - 1, &source->data, false);
bass_emit_source_modified(con_handle, source);
bass_server_source_emit_source_modified(con_handle, source);
// server needs to trigger notification
break;
@ -464,48 +464,48 @@ static int broadcast_audio_scan_service_write_callback(hci_con_handle_t con_hand
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
source = bass_find_source_for_source_id(remote_data[0]);
source = bass_server_find_source_for_source_id(remote_data[0]);
if (source == NULL){
return BASS_ERROR_CODE_INVALID_SOURCE_ID;
}
reverse_128(&remote_data[1], broadcast_code);
bass_emit_broadcast_code(con_handle, source->source_id, broadcast_code);
bass_server_source_emit_broadcast_code(con_handle, source->source_id, broadcast_code);
break;
case BASS_OPCODE_REMOVE_SOURCE:
if (remote_data_size != 1){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
source = bass_find_source_for_source_id(remote_data[0]);
source = bass_server_find_source_for_source_id(remote_data[0]);
if (source == NULL){
return BASS_ERROR_CODE_INVALID_SOURCE_ID;
}
if (bass_pa_synchronized(source)){
if (bass_server_pa_synchronized(source)){
log_info("remove source %d rejected, PA synchronised", source->source_id);
return 0;
}
if (bass_bis_synchronized(source)){
if (bass_server_bis_synchronized(source)){
log_info("remove source %d rejected, BIS synchronised", source->source_id);
return 0;
}
bass_reset_source(source);
bass_server_reset_source(source);
broadcast_audio_scan_service_server_set_pa_sync_state(source->source_id, LE_AUDIO_PA_SYNC_STATE_NOT_SYNCHRONIZED_TO_PA);
bass_emit_source_deleted(con_handle, source);
bass_server_source_emit_source_deleted(con_handle, source);
break;
default:
bass_reset_client_long_write_buffer(client);
bass_server_reset_client_long_write_buffer(client);
return BASS_ERROR_CODE_OPCODE_NOT_SUPPORTED;
}
bass_reset_client_long_write_buffer(client);
bass_server_reset_client_long_write_buffer(client);
}
return 0;
}
static void broadcast_audio_scan_service_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
static void bass_server_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(channel);
UNUSED(packet);
UNUSED(size);
@ -521,7 +521,7 @@ static void broadcast_audio_scan_service_packet_handler(uint8_t packet_type, uin
case HCI_EVENT_DISCONNECTION_COMPLETE:
con_handle = hci_event_disconnection_complete_get_connection_handle(packet);
client = bass_find_client_for_con_handle(con_handle);
client = bass_server_find_client_for_con_handle(con_handle);
if (client == NULL){
break;
}
@ -563,10 +563,10 @@ void broadcast_audio_scan_service_server_init(const uint8_t sources_num, bass_se
break;
}
bass_server_source_t * source = &bass_sources[bass_sources_num];
bass_reset_source(source);
bass_server_reset_source(source);
source->source_id = bass_sources_num;
source->update_counter = bass_get_next_update_counter();
source->update_counter = bass_server_get_next_update_counter();
source->bass_receive_state_client_configuration = 0;
source->bass_receive_state_handle = chr_value_handle;
@ -594,15 +594,15 @@ void broadcast_audio_scan_service_server_init(const uint8_t sources_num, bass_se
// register service with ATT Server
broadcast_audio_scan_service.start_handle = start_handle;
broadcast_audio_scan_service.end_handle = end_handle;
broadcast_audio_scan_service.read_callback = &broadcast_audio_scan_service_read_callback;
broadcast_audio_scan_service.write_callback = &broadcast_audio_scan_service_write_callback;
broadcast_audio_scan_service.packet_handler = broadcast_audio_scan_service_packet_handler;
broadcast_audio_scan_service.read_callback = &bass_server_read_callback;
broadcast_audio_scan_service.write_callback = &bass_server_write_callback;
broadcast_audio_scan_service.packet_handler = bass_server_packet_handler;
att_server_register_service_handler(&broadcast_audio_scan_service);
}
void broadcast_audio_scan_service_server_register_packet_handler(btstack_packet_handler_t packet_handler){
btstack_assert(packet_handler != NULL);
bass_event_callback = packet_handler;
bass_server_event_callback = packet_handler;
}
static void bass_service_can_send_now(void * context){
@ -634,7 +634,7 @@ static void bass_service_can_send_now(void * context){
}
}
static void bass_set_callback(uint8_t source_index){
static void bass_server_set_callback(uint8_t source_index){
// there is only one type of task: notify on source state change
// as task we register which source is changed, and the change will be propagated to all clients
uint8_t i;
@ -668,17 +668,17 @@ void broadcast_audio_scan_service_server_set_pa_sync_state(uint8_t source_index,
source->data.pa_sync_state = sync_state;
if (source->bass_receive_state_client_configuration != 0){
bass_set_callback(source_index);
bass_server_set_callback(source_index);
}
}
void broadcast_audio_scan_service_server_add_source(bass_source_data_t source_data, uint8_t * source_index){
*source_index = bass_find_empty_or_last_used_source_index();
*source_index = bass_server_find_empty_or_last_used_source_index();
if (*source_index == BASS_INVALID_SOURCE_INDEX){
return;
}
bass_server_source_t * last_used_source = &bass_sources[*source_index];
last_used_source->update_counter = bass_get_next_update_counter();
last_used_source->update_counter = bass_server_get_next_update_counter();
last_used_source->in_use = true;
last_used_source->source_id = *source_index;
memcpy(&last_used_source->data, &source_data, sizeof(bass_source_data_t));