1*af7c3ae6SMatthias Ringwald 2*af7c3ae6SMatthias Ringwald // hal_cpu 3*af7c3ae6SMatthias Ringwald #include "hal_cpu.h" 4*af7c3ae6SMatthias Ringwald void hal_cpu_disable_irqs(void){} 5*af7c3ae6SMatthias Ringwald void hal_cpu_enable_irqs(void){} 6*af7c3ae6SMatthias Ringwald void hal_cpu_enable_irqs_and_sleep(void){} 7*af7c3ae6SMatthias Ringwald 8*af7c3ae6SMatthias Ringwald // mock_sm.c 9*af7c3ae6SMatthias Ringwald #include "ble/sm.h" 10*af7c3ae6SMatthias Ringwald void sm_add_event_handler(btstack_packet_callback_registration_t * callback_handler){} 11*af7c3ae6SMatthias Ringwald void sm_request_pairing(hci_con_handle_t con_handle){} 12*af7c3ae6SMatthias Ringwald 13*af7c3ae6SMatthias Ringwald // mock_hci_transport.h 14*af7c3ae6SMatthias Ringwald #include "hci_transport.h" 15*af7c3ae6SMatthias Ringwald void mock_hci_transport_receive_packet(uint8_t packet_type, uint8_t * packet, uint16_t size); 16*af7c3ae6SMatthias Ringwald const hci_transport_t * mock_hci_transport_mock_get_instance(void); 17*af7c3ae6SMatthias Ringwald 18*af7c3ae6SMatthias Ringwald // mock_hci_transport.c 19*af7c3ae6SMatthias Ringwald #include <stddef.h> 20*af7c3ae6SMatthias Ringwald static uint8_t mock_hci_transport_outgoing_packet_buffer[HCI_ACL_PAYLOAD_SIZE]; 21*af7c3ae6SMatthias Ringwald static uint16_t mock_hci_transport_outgoing_packet_size; 22*af7c3ae6SMatthias Ringwald static uint8_t mock_hci_transport_outgoing_packet_type; 23*af7c3ae6SMatthias Ringwald 24*af7c3ae6SMatthias Ringwald static void (*mock_hci_transport_packet_handler)(uint8_t packet_type, uint8_t * packet, uint16_t size); 25*af7c3ae6SMatthias Ringwald static void mock_hci_transport_register_packet_handler(void (*packet_handler)(uint8_t packet_type, uint8_t * packet, uint16_t size)){ 26*af7c3ae6SMatthias Ringwald mock_hci_transport_packet_handler = packet_handler; 27*af7c3ae6SMatthias Ringwald } 28*af7c3ae6SMatthias Ringwald static int mock_hci_transport_send_packet(uint8_t packet_type, uint8_t *packet, int size){ 29*af7c3ae6SMatthias Ringwald mock_hci_transport_outgoing_packet_type = packet_type; 30*af7c3ae6SMatthias Ringwald mock_hci_transport_outgoing_packet_size = size; 31*af7c3ae6SMatthias Ringwald memcpy(mock_hci_transport_outgoing_packet_buffer, packet, size); 32*af7c3ae6SMatthias Ringwald return 0; 33*af7c3ae6SMatthias Ringwald } 34*af7c3ae6SMatthias Ringwald const hci_transport_t * mock_hci_transport_mock_get_instance(void){ 35*af7c3ae6SMatthias Ringwald static hci_transport_t mock_hci_transport = { 36*af7c3ae6SMatthias Ringwald /* .transport.name = */ "mock", 37*af7c3ae6SMatthias Ringwald /* .transport.init = */ NULL, 38*af7c3ae6SMatthias Ringwald /* .transport.open = */ NULL, 39*af7c3ae6SMatthias Ringwald /* .transport.close = */ NULL, 40*af7c3ae6SMatthias Ringwald /* .transport.register_packet_handler = */ &mock_hci_transport_register_packet_handler, 41*af7c3ae6SMatthias Ringwald /* .transport.can_send_packet_now = */ NULL, 42*af7c3ae6SMatthias Ringwald /* .transport.send_packet = */ &mock_hci_transport_send_packet, 43*af7c3ae6SMatthias Ringwald /* .transport.set_baudrate = */ NULL, 44*af7c3ae6SMatthias Ringwald }; 45*af7c3ae6SMatthias Ringwald return &mock_hci_transport; 46*af7c3ae6SMatthias Ringwald } 47*af7c3ae6SMatthias Ringwald void mock_hci_transport_receive_packet(uint8_t packet_type, const uint8_t * packet, uint16_t size){ 48*af7c3ae6SMatthias Ringwald (*mock_hci_transport_packet_handler)(packet_type, (uint8_t *) packet, size); 49*af7c3ae6SMatthias Ringwald } 50*af7c3ae6SMatthias Ringwald 51*af7c3ae6SMatthias Ringwald // 52*af7c3ae6SMatthias Ringwald 53*af7c3ae6SMatthias Ringwald #include <stdint.h> 54*af7c3ae6SMatthias Ringwald #include <stdio.h> 55*af7c3ae6SMatthias Ringwald #include <stdlib.h> 56*af7c3ae6SMatthias Ringwald #include <string.h> 57*af7c3ae6SMatthias Ringwald 58*af7c3ae6SMatthias Ringwald #include "CppUTest/TestHarness.h" 59*af7c3ae6SMatthias Ringwald #include "CppUTest/CommandLineTestRunner.h" 60*af7c3ae6SMatthias Ringwald #include "CppUTestExt/MockSupport.h" 61*af7c3ae6SMatthias Ringwald 62*af7c3ae6SMatthias Ringwald #include "hci_dump.h" 63*af7c3ae6SMatthias Ringwald #include "btstack_debug.h" 64*af7c3ae6SMatthias Ringwald #include "l2cap.h" 65*af7c3ae6SMatthias Ringwald #include "btstack_memory.h" 66*af7c3ae6SMatthias Ringwald #include "btstack_run_loop_embedded.h" 67*af7c3ae6SMatthias Ringwald #include "hci_dump_posix_stdout.h" 68*af7c3ae6SMatthias Ringwald #include "btstack_event.h" 69*af7c3ae6SMatthias Ringwald 70*af7c3ae6SMatthias Ringwald #define TEST_PACKET_SIZE 100 71*af7c3ae6SMatthias Ringwald #define HCI_CON_HANDLE_TEST_LE 0x0005 72*af7c3ae6SMatthias Ringwald #define TEST_PSM 0x1001 73*af7c3ae6SMatthias Ringwald 74*af7c3ae6SMatthias Ringwald static bool l2cap_channel_accept_incoming; 75*af7c3ae6SMatthias Ringwald static uint16_t initial_credits = L2CAP_LE_AUTOMATIC_CREDITS; 76*af7c3ae6SMatthias Ringwald static uint8_t data_channel_buffer[TEST_PACKET_SIZE]; 77*af7c3ae6SMatthias Ringwald static uint16_t l2cap_cid; 78*af7c3ae6SMatthias Ringwald static bool l2cap_channel_opened; 79*af7c3ae6SMatthias Ringwald static btstack_packet_callback_registration_t l2cap_event_callback_registration; 80*af7c3ae6SMatthias Ringwald 81*af7c3ae6SMatthias Ringwald const uint8_t le_data_channel_conn_request_1[] = { 82*af7c3ae6SMatthias Ringwald 0x05, 0x20, 0x12, 0x00, 0x0e, 0x00, 0x05, 0x00, 0x14, 0x01, 0x0a, 0x00, 0x01, 0x10, 0x41, 0x00, 83*af7c3ae6SMatthias Ringwald 0x64, 0x00, 0x30, 0x00, 0xff, 0xff 84*af7c3ae6SMatthias Ringwald }; 85*af7c3ae6SMatthias Ringwald 86*af7c3ae6SMatthias Ringwald const uint8_t le_data_channel_invalid_pdu[] = { 87*af7c3ae6SMatthias Ringwald 0x05, 0x20, 0x12, 0x00, 0x0e, 0x00, 0x05, 0x00, 0x11, 0x01, 0x0a, 0x00, 0x01, 0x10, 0x41, 0x00, 88*af7c3ae6SMatthias Ringwald 0x64, 0x00, 0x30, 0x00, 0xff, 0xff 89*af7c3ae6SMatthias Ringwald }; 90*af7c3ae6SMatthias Ringwald 91*af7c3ae6SMatthias Ringwald const uint8_t le_data_channel_conn_response_1[] = { 92*af7c3ae6SMatthias Ringwald 0x05, 0x20, 0x12, 0x00, 0x0e, 0x00, 0x05, 0x00, 0x15, 0x01, 0x0a, 0x00, 0x41, 0x00, 0x64, 0x00, 93*af7c3ae6SMatthias Ringwald 0x30, 0x00, 0xff, 0xff, 0x00, 0x00 94*af7c3ae6SMatthias Ringwald }; 95*af7c3ae6SMatthias Ringwald 96*af7c3ae6SMatthias Ringwald const uint8_t le_data_channel_data_1[] = { 97*af7c3ae6SMatthias Ringwald 0x05, 0x20, 0x04, 0x00, 0x00, 0x00, 0x41, 0x00 98*af7c3ae6SMatthias Ringwald }; 99*af7c3ae6SMatthias Ringwald 100*af7c3ae6SMatthias Ringwald static void fix_boundary_flags(uint8_t * packet, uint16_t size){ 101*af7c3ae6SMatthias Ringwald uint8_t acl_flags = packet[1] >> 4; 102*af7c3ae6SMatthias Ringwald if (acl_flags == 0){ 103*af7c3ae6SMatthias Ringwald acl_flags = 2; // first fragment 104*af7c3ae6SMatthias Ringwald } 105*af7c3ae6SMatthias Ringwald packet[1] = (packet[1] & 0x0f) | (acl_flags << 4); 106*af7c3ae6SMatthias Ringwald } 107*af7c3ae6SMatthias Ringwald 108*af7c3ae6SMatthias Ringwald static void print_acl(const char * name, const uint8_t * packet, uint16_t size){ 109*af7c3ae6SMatthias Ringwald printf("const uint8_t %s[] = {", name); 110*af7c3ae6SMatthias Ringwald uint16_t i; 111*af7c3ae6SMatthias Ringwald for (i=0;i<size;i++){ 112*af7c3ae6SMatthias Ringwald if (i != 0){ 113*af7c3ae6SMatthias Ringwald printf(", "); 114*af7c3ae6SMatthias Ringwald } 115*af7c3ae6SMatthias Ringwald if ((i % 16) == 0){ 116*af7c3ae6SMatthias Ringwald printf("\n "); 117*af7c3ae6SMatthias Ringwald } 118*af7c3ae6SMatthias Ringwald printf("0x%02x", packet[i]); 119*af7c3ae6SMatthias Ringwald } 120*af7c3ae6SMatthias Ringwald printf("\n};\n"); 121*af7c3ae6SMatthias Ringwald } 122*af7c3ae6SMatthias Ringwald 123*af7c3ae6SMatthias Ringwald static void l2cap_channel_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 124*af7c3ae6SMatthias Ringwald UNUSED(channel); 125*af7c3ae6SMatthias Ringwald UNUSED(size); 126*af7c3ae6SMatthias Ringwald uint16_t psm; 127*af7c3ae6SMatthias Ringwald uint16_t cid; 128*af7c3ae6SMatthias Ringwald switch (packet_type) { 129*af7c3ae6SMatthias Ringwald case HCI_EVENT_PACKET: 130*af7c3ae6SMatthias Ringwald switch (hci_event_packet_get_type(packet)) { 131*af7c3ae6SMatthias Ringwald case L2CAP_EVENT_CBM_INCOMING_CONNECTION: 132*af7c3ae6SMatthias Ringwald psm = l2cap_event_cbm_incoming_connection_get_psm(packet); 133*af7c3ae6SMatthias Ringwald cid = l2cap_event_cbm_incoming_connection_get_local_cid(packet); 134*af7c3ae6SMatthias Ringwald if (l2cap_channel_accept_incoming){ 135*af7c3ae6SMatthias Ringwald l2cap_cbm_accept_connection(cid, data_channel_buffer, sizeof(data_channel_buffer), initial_credits); 136*af7c3ae6SMatthias Ringwald } else { 137*af7c3ae6SMatthias Ringwald l2cap_cbm_decline_connection(cid, L2CAP_CBM_CONNECTION_RESULT_NO_RESOURCES_AVAILABLE); 138*af7c3ae6SMatthias Ringwald } 139*af7c3ae6SMatthias Ringwald break; 140*af7c3ae6SMatthias Ringwald case L2CAP_EVENT_CBM_CHANNEL_OPENED: 141*af7c3ae6SMatthias Ringwald l2cap_channel_opened = true; 142*af7c3ae6SMatthias Ringwald break; 143*af7c3ae6SMatthias Ringwald default: 144*af7c3ae6SMatthias Ringwald break; 145*af7c3ae6SMatthias Ringwald } 146*af7c3ae6SMatthias Ringwald break; 147*af7c3ae6SMatthias Ringwald default: 148*af7c3ae6SMatthias Ringwald break; 149*af7c3ae6SMatthias Ringwald } 150*af7c3ae6SMatthias Ringwald } 151*af7c3ae6SMatthias Ringwald 152*af7c3ae6SMatthias Ringwald TEST_GROUP(L2CAP_CHANNELS){ 153*af7c3ae6SMatthias Ringwald const hci_transport_t * hci_transport; 154*af7c3ae6SMatthias Ringwald void setup(void){ 155*af7c3ae6SMatthias Ringwald btstack_memory_init(); 156*af7c3ae6SMatthias Ringwald btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); 157*af7c3ae6SMatthias Ringwald hci_transport = mock_hci_transport_mock_get_instance(); 158*af7c3ae6SMatthias Ringwald hci_init(hci_transport, NULL); 159*af7c3ae6SMatthias Ringwald l2cap_init(); 160*af7c3ae6SMatthias Ringwald l2cap_event_callback_registration.callback = &l2cap_channel_packet_handler; 161*af7c3ae6SMatthias Ringwald l2cap_add_event_handler(&l2cap_event_callback_registration); 162*af7c3ae6SMatthias Ringwald l2cap_register_fixed_channel(&l2cap_channel_packet_handler, L2CAP_CID_ATTRIBUTE_PROTOCOL); 163*af7c3ae6SMatthias Ringwald hci_dump_init(hci_dump_posix_stdout_get_instance()); 164*af7c3ae6SMatthias Ringwald l2cap_channel_opened = false; 165*af7c3ae6SMatthias Ringwald } 166*af7c3ae6SMatthias Ringwald void teardown(void){ 167*af7c3ae6SMatthias Ringwald l2cap_deinit(); 168*af7c3ae6SMatthias Ringwald hci_deinit(); 169*af7c3ae6SMatthias Ringwald btstack_memory_deinit(); 170*af7c3ae6SMatthias Ringwald btstack_run_loop_deinit(); 171*af7c3ae6SMatthias Ringwald } 172*af7c3ae6SMatthias Ringwald }; 173*af7c3ae6SMatthias Ringwald 174*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, fixed_channel){ 175*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 176*af7c3ae6SMatthias Ringwald // channel does not exist 177*af7c3ae6SMatthias Ringwald l2cap_request_can_send_fix_channel_now_event(HCI_CON_HANDLE_TEST_LE, 0x003f); 178*af7c3ae6SMatthias Ringwald // att 179*af7c3ae6SMatthias Ringwald l2cap_request_can_send_fix_channel_now_event(HCI_CON_HANDLE_TEST_LE, L2CAP_CID_ATTRIBUTE_PROTOCOL); 180*af7c3ae6SMatthias Ringwald // 181*af7c3ae6SMatthias Ringwald (void) l2cap_can_send_fixed_channel_packet_now(HCI_CON_HANDLE_TEST_LE, L2CAP_CID_ATTRIBUTE_PROTOCOL); 182*af7c3ae6SMatthias Ringwald // packet buffer not reserved 183*af7c3ae6SMatthias Ringwald log_info("ignore error in next line (calling .. without reserving buffer first"); 184*af7c3ae6SMatthias Ringwald l2cap_send_prepared_connectionless(HCI_CON_HANDLE_TEST_LE, L2CAP_CID_ATTRIBUTE_PROTOCOL, 5); 185*af7c3ae6SMatthias Ringwald // packet buffer reserved 186*af7c3ae6SMatthias Ringwald l2cap_reserve_packet_buffer(); 187*af7c3ae6SMatthias Ringwald l2cap_send_prepared_connectionless(HCI_CON_HANDLE_TEST_LE, L2CAP_CID_ATTRIBUTE_PROTOCOL, 5); 188*af7c3ae6SMatthias Ringwald // 189*af7c3ae6SMatthias Ringwald l2cap_send_connectionless(HCI_CON_HANDLE_TEST_LE, L2CAP_CID_ATTRIBUTE_PROTOCOL, (uint8_t *) "hallo", 5); 190*af7c3ae6SMatthias Ringwald } 191*af7c3ae6SMatthias Ringwald 192*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, some_functions){ 193*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 194*af7c3ae6SMatthias Ringwald l2cap_reserve_packet_buffer(); 195*af7c3ae6SMatthias Ringwald (void) l2cap_get_outgoing_buffer(); 196*af7c3ae6SMatthias Ringwald l2cap_release_packet_buffer(); 197*af7c3ae6SMatthias Ringwald l2cap_set_max_le_mtu(30); 198*af7c3ae6SMatthias Ringwald l2cap_set_max_le_mtu(30); 199*af7c3ae6SMatthias Ringwald l2cap_cbm_unregister_service(TEST_PSM); 200*af7c3ae6SMatthias Ringwald l2cap_cbm_accept_connection(0X01, NULL, 0, 0); 201*af7c3ae6SMatthias Ringwald l2cap_cbm_decline_connection(0x01, L2CAP_CBM_CONNECTION_RESULT_NO_RESOURCES_AVAILABLE); 202*af7c3ae6SMatthias Ringwald l2cap_disconnect(0x01); 203*af7c3ae6SMatthias Ringwald } 204*af7c3ae6SMatthias Ringwald 205*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, outgoing_no_connection){ 206*af7c3ae6SMatthias Ringwald l2cap_cbm_create_channel(&l2cap_channel_packet_handler, HCI_CON_HANDLE_TEST_LE, TEST_PSM, data_channel_buffer, 207*af7c3ae6SMatthias Ringwald sizeof(data_channel_buffer), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &l2cap_cid); 208*af7c3ae6SMatthias Ringwald } 209*af7c3ae6SMatthias Ringwald 210*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, outgoing_security_1){ 211*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 212*af7c3ae6SMatthias Ringwald l2cap_cbm_create_channel(&l2cap_channel_packet_handler, HCI_CON_HANDLE_TEST_LE, TEST_PSM, data_channel_buffer, 213*af7c3ae6SMatthias Ringwald sizeof(data_channel_buffer), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_2, NULL); 214*af7c3ae6SMatthias Ringwald l2cap_cbm_create_channel(&l2cap_channel_packet_handler, HCI_CON_HANDLE_TEST_LE, TEST_PSM, data_channel_buffer, 215*af7c3ae6SMatthias Ringwald sizeof(data_channel_buffer), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_2, &l2cap_cid); 216*af7c3ae6SMatthias Ringwald } 217*af7c3ae6SMatthias Ringwald 218*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, outgoing_1){ 219*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 220*af7c3ae6SMatthias Ringwald l2cap_cbm_create_channel(&l2cap_channel_packet_handler, HCI_CON_HANDLE_TEST_LE, TEST_PSM, data_channel_buffer, 221*af7c3ae6SMatthias Ringwald sizeof(data_channel_buffer), L2CAP_LE_AUTOMATIC_CREDITS, LEVEL_0, &l2cap_cid); 222*af7c3ae6SMatthias Ringwald // fix_boundary_flags(mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 223*af7c3ae6SMatthias Ringwald // print_acl("le_data_channel_conn_request_1", mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 224*af7c3ae6SMatthias Ringwald // simulate conn response 225*af7c3ae6SMatthias Ringwald mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, le_data_channel_conn_response_1, sizeof(le_data_channel_conn_response_1)); 226*af7c3ae6SMatthias Ringwald CHECK(l2cap_channel_opened); 227*af7c3ae6SMatthias Ringwald CHECK(hci_number_free_acl_slots_for_handle(HCI_CON_HANDLE_TEST_LE) > 0); 228*af7c3ae6SMatthias Ringwald bool can_send_now = l2cap_can_send_packet_now(l2cap_cid); 229*af7c3ae6SMatthias Ringwald CHECK(can_send_now); 230*af7c3ae6SMatthias Ringwald l2cap_request_can_send_now_event(l2cap_cid); 231*af7c3ae6SMatthias Ringwald CHECK(hci_number_free_acl_slots_for_handle(HCI_CON_HANDLE_TEST_LE) > 0); 232*af7c3ae6SMatthias Ringwald l2cap_send(l2cap_cid, (uint8_t *) "hallo", 5); 233*af7c3ae6SMatthias Ringwald // CHECK(hci_number_free_acl_slots_for_handle(HCI_CON_HANDLE_TEST) > 0); 234*af7c3ae6SMatthias Ringwald // fix_boundary_flags(mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 235*af7c3ae6SMatthias Ringwald // print_acl("le_data_channel_data_1", mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 236*af7c3ae6SMatthias Ringwald // simulate data 237*af7c3ae6SMatthias Ringwald mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, le_data_channel_data_1, sizeof(le_data_channel_data_1)); 238*af7c3ae6SMatthias Ringwald l2cap_disconnect(l2cap_cid); 239*af7c3ae6SMatthias Ringwald } 240*af7c3ae6SMatthias Ringwald 241*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, incoming_1){ 242*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 243*af7c3ae6SMatthias Ringwald l2cap_cbm_register_service(&l2cap_channel_packet_handler, TEST_PSM, LEVEL_0); 244*af7c3ae6SMatthias Ringwald // simulate conn request 245*af7c3ae6SMatthias Ringwald l2cap_channel_accept_incoming = true; 246*af7c3ae6SMatthias Ringwald mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, le_data_channel_conn_request_1, sizeof(le_data_channel_conn_request_1)); 247*af7c3ae6SMatthias Ringwald // fix_boundary_flags(mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 248*af7c3ae6SMatthias Ringwald // print_acl("le_data_channel_conn_response_1", mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 249*af7c3ae6SMatthias Ringwald // TODO: verify data 250*af7c3ae6SMatthias Ringwald l2cap_cbm_unregister_service(TEST_PSM); 251*af7c3ae6SMatthias Ringwald } 252*af7c3ae6SMatthias Ringwald 253*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, incoming_2){ 254*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 255*af7c3ae6SMatthias Ringwald l2cap_cbm_register_service(&l2cap_channel_packet_handler, TEST_PSM, LEVEL_2); 256*af7c3ae6SMatthias Ringwald // simulate conn request 257*af7c3ae6SMatthias Ringwald l2cap_channel_accept_incoming = true; 258*af7c3ae6SMatthias Ringwald mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, le_data_channel_conn_request_1, sizeof(le_data_channel_conn_request_1)); 259*af7c3ae6SMatthias Ringwald } 260*af7c3ae6SMatthias Ringwald 261*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, incoming_3){ 262*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 263*af7c3ae6SMatthias Ringwald l2cap_cbm_register_service(&l2cap_channel_packet_handler, TEST_PSM, LEVEL_0); 264*af7c3ae6SMatthias Ringwald // simulate conn request 265*af7c3ae6SMatthias Ringwald l2cap_channel_accept_incoming = true; 266*af7c3ae6SMatthias Ringwald mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, le_data_channel_invalid_pdu, sizeof(le_data_channel_invalid_pdu)); 267*af7c3ae6SMatthias Ringwald } 268*af7c3ae6SMatthias Ringwald 269*af7c3ae6SMatthias Ringwald TEST(L2CAP_CHANNELS, incoming_decline){ 270*af7c3ae6SMatthias Ringwald hci_setup_test_connections_fuzz(); 271*af7c3ae6SMatthias Ringwald l2cap_cbm_register_service(&l2cap_channel_packet_handler, TEST_PSM, LEVEL_0); 272*af7c3ae6SMatthias Ringwald // simulate conn request 273*af7c3ae6SMatthias Ringwald l2cap_channel_accept_incoming = false; 274*af7c3ae6SMatthias Ringwald mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, le_data_channel_conn_request_1, sizeof(le_data_channel_conn_request_1)); 275*af7c3ae6SMatthias Ringwald // fix_boundary_flags(mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 276*af7c3ae6SMatthias Ringwald // print_acl("le_data_channel_conn_response_1", mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); 277*af7c3ae6SMatthias Ringwald // TODO: verify data 278*af7c3ae6SMatthias Ringwald } 279*af7c3ae6SMatthias Ringwald 280*af7c3ae6SMatthias Ringwald int main (int argc, const char * argv[]){ 281*af7c3ae6SMatthias Ringwald return CommandLineTestRunner::RunAllTests(argc, argv); 282*af7c3ae6SMatthias Ringwald } 283