gatt-service/bass-server: update struct name

This commit is contained in:
Milanka Ringwald 2023-01-27 16:38:28 +01:00 committed by Matthias Ringwald
parent 374a3da36f
commit 7f95ef04c3
2 changed files with 43 additions and 45 deletions

View File

@ -67,7 +67,7 @@ static uint8_t bass_logic_time = 0;
static bass_server_source_t * bass_sources;
static uint8_t bass_sources_num = 0;
static broadcast_audio_scan_service_server_t * bass_clients;
static bass_server_connection_t * bass_clients;
static uint8_t bass_clients_num = 0;
static btstack_context_callback_registration_t scheduled_tasks_callback;
@ -147,7 +147,7 @@ static bass_server_source_t * bass_server_find_source_for_source_id(uint8_t sour
return NULL;
}
static broadcast_audio_scan_service_server_t * bass_server_find_client_for_con_handle(hci_con_handle_t con_handle){
static bass_server_connection_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) {
@ -158,7 +158,7 @@ static broadcast_audio_scan_service_server_t * bass_server_find_client_for_con_h
}
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);
bass_server_connection_t * client = bass_server_find_client_for_con_handle(con_handle);
if (client == NULL){
client = bass_server_find_client_for_con_handle(HCI_CON_HANDLE_INVALID);
if (client == NULL){
@ -283,8 +283,7 @@ static uint16_t bass_server_copy_source_to_buffer(bass_server_source_t * source,
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_server_find_receive_state_for_value_handle(attribute_handle);
bass_server_source_t * 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);
}
@ -347,7 +346,7 @@ static void bass_server_reset_source(bass_server_source_t * source){
memset(source->data.subgroups, 0, sizeof(source->data.subgroups));
}
static void bass_server_reset_client_long_write_buffer(broadcast_audio_scan_service_server_t * client){
static void bass_server_reset_client_long_write_buffer(bass_server_connection_t * client){
memset(client->long_write_buffer, 0, sizeof(client->long_write_buffer));
client->long_write_value_size = 0;
}
@ -355,7 +354,6 @@ static void bass_server_reset_client_long_write_buffer(broadcast_audio_scan_serv
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_server_find_receive_state_for_client_configuration_handle(attribute_handle);
if (source){
source->bass_receive_state_client_configuration = little_endian_read_16(buffer, 0);
@ -364,9 +362,8 @@ static int bass_server_write_callback(hci_con_handle_t con_handle, uint16_t attr
return 0;
}
broadcast_audio_scan_service_server_t * client = bass_server_find_client_for_con_handle(con_handle);
if (client == NULL){
bass_server_connection_t * connection = bass_server_find_client_for_con_handle(con_handle);
if (connection == NULL){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
@ -374,25 +371,25 @@ static int bass_server_write_callback(hci_con_handle_t con_handle, uint16_t attr
switch (transaction_mode){
case ATT_TRANSACTION_MODE_NONE:
if (buffer_size > sizeof(client->long_write_buffer)){
bass_server_reset_client_long_write_buffer(client);
if (buffer_size > sizeof(connection->long_write_buffer)){
bass_server_reset_client_long_write_buffer(connection);
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
memcpy(&client->long_write_buffer[0], buffer, buffer_size);
client->long_write_value_size = total_value_len;
memcpy(&connection->long_write_buffer[0], buffer, buffer_size);
connection->long_write_value_size = total_value_len;
break;
case ATT_TRANSACTION_MODE_ACTIVE:
if (total_value_len > sizeof(client->long_write_buffer)){
bass_server_reset_client_long_write_buffer(client);
if (total_value_len > sizeof(connection->long_write_buffer)){
bass_server_reset_client_long_write_buffer(connection);
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
// allow overlapped and/or mixed order chunks
client->long_write_attribute_handle = attribute_handle;
connection->long_write_attribute_handle = attribute_handle;
memcpy(&client->long_write_buffer[offset], buffer, buffer_size);
if (total_value_len > client->long_write_value_size){
client->long_write_value_size = total_value_len;
memcpy(&connection->long_write_buffer[offset], buffer, buffer_size);
if (total_value_len > connection->long_write_value_size){
connection->long_write_value_size = total_value_len;
}
return 0;
@ -400,7 +397,7 @@ static int bass_server_write_callback(hci_con_handle_t con_handle, uint16_t attr
return 0;
case ATT_TRANSACTION_MODE_EXECUTE:
attribute_handle = client->long_write_attribute_handle;
attribute_handle = connection->long_write_attribute_handle;
break;
default:
@ -408,13 +405,13 @@ static int bass_server_write_callback(hci_con_handle_t con_handle, uint16_t attr
}
if (attribute_handle == bass_audio_scan_control_point_handle){
if (client->long_write_value_size < 2){
if (connection->long_write_value_size < 2){
return ATT_ERROR_WRITE_REQUEST_REJECTED;
}
bass_opcode_t opcode = (bass_opcode_t)client->long_write_buffer[0];
uint8_t *remote_data = &client->long_write_buffer[1];
uint16_t remote_data_size = client->long_write_value_size - 1;
bass_opcode_t opcode = (bass_opcode_t)connection->long_write_buffer[0];
uint8_t *remote_data = &connection->long_write_buffer[1];
uint16_t remote_data_size = connection->long_write_value_size - 1;
bass_server_source_t * source;
uint8_t broadcast_code[16];
@ -497,10 +494,10 @@ static int bass_server_write_callback(hci_con_handle_t con_handle, uint16_t attr
break;
default:
bass_server_reset_client_long_write_buffer(client);
bass_server_reset_client_long_write_buffer(connection);
return BASS_ERROR_CODE_OPCODE_NOT_SUPPORTED;
}
bass_server_reset_client_long_write_buffer(client);
bass_server_reset_client_long_write_buffer(connection);
}
return 0;
}
@ -515,26 +512,26 @@ static void bass_server_packet_handler(uint8_t packet_type, uint16_t channel, ui
}
hci_con_handle_t con_handle;
broadcast_audio_scan_service_server_t * client;
bass_server_connection_t * connection;
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_DISCONNECTION_COMPLETE:
con_handle = hci_event_disconnection_complete_get_connection_handle(packet);
client = bass_server_find_client_for_con_handle(con_handle);
if (client == NULL){
connection = bass_server_find_client_for_con_handle(con_handle);
if (connection == NULL){
break;
}
memset(client, 0, sizeof(broadcast_audio_scan_service_server_t));
client->con_handle = HCI_CON_HANDLE_INVALID;
memset(connection, 0, sizeof(bass_server_connection_t));
connection->con_handle = HCI_CON_HANDLE_INVALID;
break;
default:
break;
}
}
void broadcast_audio_scan_service_server_init(const uint8_t sources_num, bass_server_source_t * sources, const uint8_t clients_num, broadcast_audio_scan_service_server_t * clients){
void broadcast_audio_scan_service_server_init(const uint8_t sources_num, bass_server_source_t * sources, const uint8_t clients_num, bass_server_connection_t * clients){
// get service handle range
btstack_assert(sources_num != 0);
btstack_assert(clients_num != 0);
@ -583,7 +580,7 @@ void broadcast_audio_scan_service_server_init(const uint8_t sources_num, bass_se
bass_clients_num = clients_num;
bass_clients = clients;
memset(bass_clients, 0, sizeof(broadcast_audio_scan_service_server_t) * bass_clients_num);
memset(bass_clients, 0, sizeof(bass_server_connection_t) * bass_clients_num);
uint8_t i;
for (i = 0; i < bass_clients_num; i++){
bass_clients[i].con_handle = HCI_CON_HANDLE_INVALID;
@ -606,7 +603,7 @@ void broadcast_audio_scan_service_server_register_packet_handler(btstack_packet_
}
static void bass_service_can_send_now(void * context){
broadcast_audio_scan_service_server_t * client = (broadcast_audio_scan_service_server_t *) context;
bass_server_connection_t * client = (bass_server_connection_t *) context;
btstack_assert(client != NULL);
uint8_t source_index;
@ -643,20 +640,20 @@ static void bass_server_set_callback(uint8_t source_index){
uint8_t scheduled_tasks = 0;
for (i = 0; i < bass_clients_num; i++){
broadcast_audio_scan_service_server_t * client = &bass_clients[i];
bass_server_connection_t * connection = &bass_clients[i];
if (client->con_handle == HCI_CON_HANDLE_INVALID){
client->sources_to_notify &= ~task;
if (connection->con_handle == HCI_CON_HANDLE_INVALID){
connection->sources_to_notify &= ~task;
return;
}
scheduled_tasks |= client->sources_to_notify;
client->sources_to_notify |= task;
scheduled_tasks |= connection->sources_to_notify;
connection->sources_to_notify |= task;
if (scheduled_tasks == 0){
scheduled_tasks_callback.callback = &bass_service_can_send_now;
scheduled_tasks_callback.context = (void*) client;
att_server_register_can_send_now_callback(&scheduled_tasks_callback, client->con_handle);
scheduled_tasks_callback.context = (void*) connection;
att_server_register_can_send_now_callback(&scheduled_tasks_callback, connection->con_handle);
}
}
}
@ -685,4 +682,5 @@ void broadcast_audio_scan_service_server_add_source(bass_source_data_t source_da
}
void broadcast_audio_scan_service_server_deinit(void){
bass_server_event_callback = NULL;
}

View File

@ -86,7 +86,7 @@ typedef struct {
uint8_t long_write_buffer[512];
uint16_t long_write_value_size;
uint16_t long_write_attribute_handle;
} broadcast_audio_scan_service_server_t;
} bass_server_connection_t;
/**
* @brief Init Broadcast Audio Scan Service Server with ATT DB
@ -95,7 +95,7 @@ typedef struct {
* @param clients_num
* @param clients
*/
void broadcast_audio_scan_service_server_init(uint8_t const sources_num, bass_server_source_t * sources, uint8_t const clients_num, broadcast_audio_scan_service_server_t * clients);
void broadcast_audio_scan_service_server_init(uint8_t const sources_num, bass_server_source_t * sources, uint8_t const clients_num, bass_server_connection_t * clients);
/**
* @brief Register packet handler to receive events: