core: use GAP_SUBEVENT_LE_CONNECTION_COMPLETE instead of HCI_SUBEVENT_LE_CONNECTION_COMPLETE

This commit is contained in:
Matthias Ringwald 2023-11-22 18:10:09 +01:00
parent ebd1b97964
commit 9d1eff910d
5 changed files with 67 additions and 52 deletions

View File

@ -303,16 +303,16 @@ static void att_server_event_packet_handler (uint8_t packet_type, uint16_t chann
case HCI_EVENT_PACKET:
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_LE_META:
switch (packet[2]) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
con_handle = little_endian_read_16(packet, 4);
case HCI_EVENT_META_GAP:
switch (hci_event_gap_meta_get_subevent_code(packet)) {
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
hci_connection = hci_connection_for_handle(con_handle);
if (!hci_connection) break;
att_server = &hci_connection->att_server;
// store connection info
att_server->peer_addr_type = packet[7];
reverse_bd_addr(&packet[8], att_server->peer_address);
att_server->peer_addr_type = gap_subevent_le_connection_complete_get_peer_address_type(packet);
gap_subevent_le_connection_complete_get_peer_address(packet, att_server->peer_address);
att_connection = &hci_connection->att_connection;
att_connection->con_handle = con_handle;
// reset connection properties
@ -335,7 +335,6 @@ static void att_server_event_packet_handler (uint8_t packet_type, uint16_t chann
// notify all - new
att_emit_connected_event(att_server, att_connection);
break;
default:
break;
}

View File

@ -326,10 +326,10 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
// handle connect / disconncet events first
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_LE_META:
switch (packet[2]) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
gc_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
case HCI_EVENT_META_GAP:
switch (hci_event_gap_meta_get_subevent_code(packet)) {
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
gc_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
log_info("Connection handle 0x%04x, request encryption", gc_handle);
// we need to be paired to enable notifications

View File

@ -921,15 +921,26 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
if (packet_type != HCI_EVENT_PACKET) return;
switch (event_type){
case HCI_EVENT_META_GAP:
switch (hci_event_gap_meta_get_subevent_code(packet)) {
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
switch (hci_event_gap_meta_get_subevent_code(packet)) {
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
instance->con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
// print connection parameters (without using float operations)
instance->con_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
instance->con_interval_status = CP_CONNECTION_INTERVAL_STATUS_RECEIVED;
break;
default:
break;
}
break;
default:
break;
}
break;
case HCI_EVENT_LE_META:
switch (hci_event_le_meta_get_subevent_code(packet)){
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
instance->con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
// print connection parameters (without using float operations)
instance->con_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
instance->con_interval_status = CP_CONNECTION_INTERVAL_STATUS_RECEIVED;
break;
#ifdef ENABLE_ATT_DELAYED_RESPONSE
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
if (instance->con_interval_status != CP_CONNECTION_INTERVAL_STATUS_W4_UPDATE) return;

View File

@ -3898,43 +3898,48 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
break;
#endif
case HCI_EVENT_LE_META:
switch (packet[2]) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
// ignore if connection failed
if (packet[3]) return;
case HCI_EVENT_META_GAP:
switch (hci_event_gap_meta_get_subevent_code(packet)) {
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
// ignore if connection failed
if (gap_subevent_le_connection_complete_get_status(packet) != ERROR_CODE_SUCCESS) break;
con_handle = little_endian_read_16(packet, 4);
sm_conn = sm_get_connection_for_handle(con_handle);
if (!sm_conn) break;
con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
sm_conn = sm_get_connection_for_handle(con_handle);
if (!sm_conn) break;
hci_subevent_le_connection_complete_get_peer_address(packet, addr);
sm_connection_init(sm_conn,
gap_subevent_le_connection_complete_get_peer_address(packet, addr);
sm_connection_init(sm_conn,
con_handle,
hci_subevent_le_connection_complete_get_role(packet),
hci_subevent_le_connection_complete_get_peer_address_type(packet),
gap_subevent_le_connection_complete_get_role(packet),
gap_subevent_le_connection_complete_get_peer_address_type(packet),
addr);
sm_conn->sm_cid = L2CAP_CID_SECURITY_MANAGER_PROTOCOL;
// track our addr used for this connection and set state
#ifdef ENABLE_LE_PERIPHERAL
if (hci_subevent_le_connection_complete_get_role(packet) != 0){
// responder - use own address from advertisements
gap_le_get_own_advertisements_address(&sm_conn->sm_own_addr_type, sm_conn->sm_own_address);
sm_conn->sm_engine_state = SM_RESPONDER_IDLE;
}
#endif
#ifdef ENABLE_LE_CENTRAL
if (hci_subevent_le_connection_complete_get_role(packet) == 0){
// initiator - use own address from create connection
gap_le_get_own_connection_address(&sm_conn->sm_own_addr_type, sm_conn->sm_own_address);
sm_conn->sm_engine_state = SM_INITIATOR_CONNECTED;
}
#endif
break;
sm_conn->sm_cid = L2CAP_CID_SECURITY_MANAGER_PROTOCOL;
// track our addr used for this connection and set state
#ifdef ENABLE_LE_PERIPHERAL
if (gap_subevent_le_connection_complete_get_role(packet) != 0){
// responder - use own address from advertisements
gap_le_get_own_advertisements_address(&sm_conn->sm_own_addr_type, sm_conn->sm_own_address);
sm_conn->sm_engine_state = SM_RESPONDER_IDLE;
}
#endif
#ifdef ENABLE_LE_CENTRAL
if (gap_subevent_le_connection_complete_get_role(packet) == 0){
// initiator - use own address from create connection
gap_le_get_own_connection_address(&sm_conn->sm_own_addr_type, sm_conn->sm_own_address);
sm_conn->sm_engine_state = SM_INITIATOR_CONNECTED;
}
#endif
break;
default:
break;
}
break;
case HCI_EVENT_LE_META:
switch (hci_event_le_meta_get_subevent_code(packet)) {
case HCI_SUBEVENT_LE_LONG_TERM_KEY_REQUEST:
con_handle = little_endian_read_16(packet, 3);
con_handle = hci_subevent_le_long_term_key_request_get_connection_handle(packet);
sm_conn = sm_get_connection_for_handle(con_handle);
if (!sm_conn) break;
@ -3951,7 +3956,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
// store rand and ediv
reverse_64(&packet[5], sm_conn->sm_local_rand);
sm_conn->sm_local_ediv = little_endian_read_16(packet, 13);
sm_conn->sm_local_ediv = hci_subevent_le_long_term_key_request_get_encryption_diversifier(packet);
// For Legacy Pairing (<=> EDIV != 0 || RAND != NULL), we need to recalculated our LTK as a
// potentially stored LTK is from the master

View File

@ -324,8 +324,8 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
}
break;
case HCI_EVENT_LE_META:
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
case HCI_EVENT_META_GAP:
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
// disable PB_GATT
mesh_proxy_stop_advertising_unprovisioned_device();
break;