hci: prepare connection struct if advertisement set terminated arrives before le connection complete

This commit is contained in:
Matthias Ringwald 2024-05-22 12:20:11 +02:00
parent 138e942eff
commit f7043595f8
2 changed files with 23 additions and 2 deletions

View File

@ -3446,7 +3446,15 @@ static void hci_handle_le_connection_complete_event(const uint8_t * hci_event){
#ifdef ENABLE_LE_PERIPHERAL
#ifdef ENABLE_LE_EXTENDED_ADVERTISING
if (hci_le_extended_advertising_supported()) {
// handled with HCI_SUBEVENT_LE_ADVERTISING_SET_TERMINATED
// advertisement state managed with HCI_SUBEVENT_LE_ADVERTISING_SET_TERMINATED
// if advertisement set terminated event arrives before connection complete, connection struct has been prepared
// set missing peer address + address type
conn = hci_connection_for_handle(con_handle);
if (conn != NULL){
memcpy(conn->address, addr, 6);
conn->address_type = addr_type;
}
}
else
#endif
@ -4407,6 +4415,18 @@ static void event_handler(uint8_t *packet, uint16_t size){
hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE;
hci_update_advertisements_enabled_for_current_roles();
}
// event may come before le connection complete and announces new connection
if (hci_subevent_le_advertising_set_terminated_get_status(packet) == ERROR_CODE_SUCCESS){
handle = hci_subevent_le_advertising_set_terminated_get_connection_handle(packet);
conn = hci_connection_for_handle(handle);
if (conn == NULL){
conn = create_connection_for_bd_addr_and_type(addr, BD_ADDR_TYPE_LE_PUBLIC, HCI_ROLE_SLAVE);
if (conn != NULL){
conn->state = ANNOUNCED;
conn->con_handle = handle;
}
}
}
break;
#endif
#endif

View File

@ -248,7 +248,8 @@ typedef enum {
OPEN,
SEND_DISCONNECT,
SENT_DISCONNECT,
RECEIVED_DISCONNECTION_COMPLETE
RECEIVED_DISCONNECTION_COMPLETE,
ANNOUNCED // connection handle announced in advertisement set terminated event
} CONNECTION_STATE;
// bonding flags