test: use GAP_SUBEVENT_LE_CONNECTION_COMPLETE

This commit is contained in:
Matthias Ringwald 2023-12-05 17:45:32 +01:00
parent d8586c7d00
commit 38e85ba13b
4 changed files with 97 additions and 18 deletions

View File

@ -47,21 +47,48 @@ static void hci_emit_event(uint8_t * event, uint16_t size, int dump){
(*ancs_callback_registration->callback)(HCI_EVENT_PACKET, 0, event, size); (*ancs_callback_registration->callback)(HCI_EVENT_PACKET, 0, event, size);
} }
static void hci_create_gap_connection_complete_event(const uint8_t * hci_event, uint8_t * gap_event) {
gap_event[0] = HCI_EVENT_META_GAP;
gap_event[1] = 36 - 2;
gap_event[2] = GAP_SUBEVENT_LE_CONNECTION_COMPLETE;
switch (hci_event[2]){
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
memcpy(&gap_event[3], &hci_event[3], 11);
memset(&gap_event[14], 0, 12);
memcpy(&gap_event[26], &hci_event[14], 7);
memset(&gap_event[33], 0xff, 3);
break;
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE_V1:
memcpy(&gap_event[3], &hci_event[3], 30);
memset(&gap_event[33], 0xff, 3);
break;
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE_V2:
memcpy(&gap_event[3], &hci_event[3], 33);
break;
default:
btstack_unreachable();
break;
}
}
static void hci_emit_le_connection_complete(uint8_t address_type, const bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){ static void hci_emit_le_connection_complete(uint8_t address_type, const bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){
uint8_t event[21]; uint8_t hci_event[21];
event[0] = HCI_EVENT_LE_META; hci_event[0] = HCI_EVENT_LE_META;
event[1] = sizeof(event) - 2u; hci_event[1] = sizeof(hci_event) - 2u;
event[2] = HCI_SUBEVENT_LE_CONNECTION_COMPLETE; hci_event[2] = HCI_SUBEVENT_LE_CONNECTION_COMPLETE;
event[3] = status; hci_event[3] = status;
little_endian_store_16(event, 4, con_handle); little_endian_store_16(hci_event, 4, con_handle);
event[6] = 0; // TODO: role hci_event[6] = 0; // TODO: role
event[7] = address_type; hci_event[7] = address_type;
reverse_bd_addr(address, &event[8]); reverse_bd_addr(address, &hci_event[8]);
little_endian_store_16(event, 14, 0); // interval little_endian_store_16(hci_event, 14, 0); // interval
little_endian_store_16(event, 16, 0); // latency little_endian_store_16(hci_event, 16, 0); // latency
little_endian_store_16(event, 18, 0); // supervision timeout little_endian_store_16(hci_event, 18, 0); // supervision timeout
event[20] = 0; // master clock accuracy hci_event[20] = 0; // master clock accuracy
hci_emit_event(event, sizeof(event), 1); // emit GAP event, too
uint8_t gap_event[36];
hci_create_gap_connection_complete_event(hci_event, gap_event);
hci_emit_event(gap_event, sizeof(gap_event), 1);
} }
static void hci_emit_connection_encrypted(hci_con_handle_t con_handle, uint8_t encrypted){ static void hci_emit_connection_encrypted(hci_con_handle_t con_handle, uint8_t encrypted){

View File

@ -53,9 +53,9 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
gap_connect(address, (bd_addr_type_t)packet[3]); gap_connect(address, (bd_addr_type_t)packet[3]);
break; break;
} }
case HCI_EVENT_LE_META: case HCI_EVENT_META_GAP:
// wait for connection complete // wait for connection complete
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break; if (hci_event_le_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
connected = 1; connected = 1;
break; break;
case HCI_EVENT_DISCONNECTION_COMPLETE: case HCI_EVENT_DISCONNECTION_COMPLETE:

View File

@ -39,9 +39,35 @@ void mock_simulate_hci_state_working(void){
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, 3); registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, 3);
} }
static void hci_create_gap_connection_complete_event(const uint8_t * hci_event, uint8_t * gap_event) {
gap_event[0] = HCI_EVENT_META_GAP;
gap_event[1] = 36 - 2;
gap_event[2] = GAP_SUBEVENT_LE_CONNECTION_COMPLETE;
switch (hci_event[2]){
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
memcpy(&gap_event[3], &hci_event[3], 11);
memset(&gap_event[14], 0, 12);
memcpy(&gap_event[26], &hci_event[14], 7);
memset(&gap_event[33], 0xff, 3);
break;
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE_V1:
memcpy(&gap_event[3], &hci_event[3], 30);
memset(&gap_event[33], 0xff, 3);
break;
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE_V2:
memcpy(&gap_event[3], &hci_event[3], 33);
break;
default:
btstack_unreachable();
break;
}
}
void mock_simulate_connected(void){ void mock_simulate_connected(void){
uint8_t packet[] = {HCI_EVENT_LE_META, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05}; uint8_t packet[] = {HCI_EVENT_LE_META, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05};
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, sizeof(packet)); uint8_t gap_event[36];
hci_create_gap_connection_complete_event(packet, gap_event);
registered_hci_event_handler(HCI_EVENT_PACKET, 0, gap_event, sizeof(gap_event));
} }
void mock_simulate_scan_response(void){ void mock_simulate_scan_response(void){

View File

@ -37,9 +37,35 @@ void mock_simulate_hci_state_working(void){
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, 3); registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, 3);
} }
static void hci_create_gap_connection_complete_event(const uint8_t * hci_event, uint8_t * gap_event) {
gap_event[0] = HCI_EVENT_META_GAP;
gap_event[1] = 36 - 2;
gap_event[2] = GAP_SUBEVENT_LE_CONNECTION_COMPLETE;
switch (hci_event[2]){
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
memcpy(&gap_event[3], &hci_event[3], 11);
memset(&gap_event[14], 0, 12);
memcpy(&gap_event[26], &hci_event[14], 7);
memset(&gap_event[33], 0xff, 3);
break;
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE_V1:
memcpy(&gap_event[3], &hci_event[3], 30);
memset(&gap_event[33], 0xff, 3);
break;
case HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE_V2:
memcpy(&gap_event[3], &hci_event[3], 33);
break;
default:
btstack_unreachable();
break;
}
}
void mock_simulate_connected(void){ void mock_simulate_connected(void){
uint8_t packet[] = {0x3E, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05}; uint8_t packet[] = {0x3E, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05};
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, sizeof(packet)); uint8_t gap_event[36];
hci_create_gap_connection_complete_event(packet, gap_event);
registered_hci_event_handler(HCI_EVENT_PACKET, 0, gap_event, sizeof(gap_event));
} }
void mock_simulate_scan_response(void){ void mock_simulate_scan_response(void){