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