hci: extract handle_command_complete_event

This commit is contained in:
Matthias Ringwald 2020-07-07 17:51:03 +02:00
parent 2c31d7721e
commit 4f7810264d

View File

@ -1979,37 +1979,16 @@ static void hci_handle_read_encryption_key_size_complete(hci_connection_t * conn
}
#endif
static void event_handler(uint8_t *packet, int size){
static void handle_command_complete_event(uint8_t * packet, uint16_t size){
uint16_t event_length = packet[1];
// assert packet is complete
if (size != (event_length + 2)){
log_error("event_handler called with packet of wrong size %d, expected %u => dropping packet", size, event_length + 2);
return;
}
bd_addr_t addr;
bd_addr_type_t addr_type;
hci_con_handle_t handle;
hci_connection_t * conn;
int i;
int create_connection_cmd;
#ifdef ENABLE_CLASSIC
uint8_t link_type;
#endif
// log_info("HCI:EVENT:%02x", hci_event_packet_get_type(packet));
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_COMMAND_COMPLETE:
// get num cmd packets - limit to 1 to reduce complexity
hci_stack->num_cmd_packets = packet[2] ? 1 : 0;
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_name)){
if (packet[5]) break;
if (packet[5]) return;
// terminate, name 248 chars
packet[6+248] = 0;
log_info("local name: %s", &packet[6]);
@ -2033,14 +2012,13 @@ static void event_handler(uint8_t *packet, int size){
}
}
else if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_rssi)){
if (packet[5] == 0){
if (packet[5]) return;
uint8_t event[5];
event[0] = GAP_EVENT_RSSI_MEASUREMENT;
event[1] = 3;
(void)memcpy(&event[2], &packet[6], 3);
hci_emit_event(event, sizeof(event), 1);
}
}
#ifdef ENABLE_BLE
else if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_le_read_buffer_size)){
hci_stack->le_data_packets_length = little_endian_read_16(packet, 6);
@ -2091,9 +2069,7 @@ static void event_handler(uint8_t *packet, int size){
// Note: HCI init checks
else if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_supported_features)){
(void)memcpy(hci_stack->local_supported_features,
&packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1],
8);
(void)memcpy(hci_stack->local_supported_features, &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], 8);
#ifdef ENABLE_CLASSIC
// determine usable ACL packet types based on host buffer size and supported features
@ -2135,15 +2111,14 @@ static void event_handler(uint8_t *packet, int size){
}
#ifdef ENABLE_CLASSIC
else if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_write_synchronous_flow_control_enable)){
if (packet[5] == 0){
if (packet[5]) return;
hci_stack->synchronous_flow_control_enabled = 1;
}
}
else if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_encryption_key_size)){
uint8_t status = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE];
handle = little_endian_read_16(packet, OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1);
conn = hci_connection_for_handle(handle);
if (!conn) break;
if (!conn) return;
uint8_t key_size = 0;
if (status == 0){
key_size = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+3];
@ -2154,6 +2129,35 @@ static void event_handler(uint8_t *packet, int size){
hci_handle_read_encryption_key_size_complete(conn, key_size);
}
#endif
}
static void event_handler(uint8_t *packet, int size){
uint16_t event_length = packet[1];
// assert packet is complete
if (size != (event_length + 2)){
log_error("event_handler called with packet of wrong size %d, expected %u => dropping packet", size, event_length + 2);
return;
}
bd_addr_t addr;
bd_addr_type_t addr_type;
hci_con_handle_t handle;
hci_connection_t * conn;
int i;
int create_connection_cmd;
#ifdef ENABLE_CLASSIC
uint8_t link_type;
#endif
// log_info("HCI:EVENT:%02x", hci_event_packet_get_type(packet));
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_COMMAND_COMPLETE:
handle_command_complete_event(packet, size);
break;
case HCI_EVENT_COMMAND_STATUS: