1f45e14b1S[email protected] #include <stdint.h> 2f45e14b1S[email protected] #include <stdio.h> 3f45e14b1S[email protected] #include <stdlib.h> 4f45e14b1S[email protected] #include <string.h> 5f45e14b1S[email protected] 6f45e14b1S[email protected] #include <btstack/btstack.h> 7f45e14b1S[email protected] #include "hci.h" 8f45e14b1S[email protected] #include "hci_dump.h" 9f45e14b1S[email protected] #include "l2cap.h" 104f5e8608S[email protected] #include "ble_client.h" 114f5e8608S[email protected] 124f5e8608S[email protected] static btstack_packet_handler_t att_packet_handler; 134f5e8608S[email protected] static void (*gatt_central_packet_handler) (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL; 144f5e8608S[email protected] 154f5e8608S[email protected] static uint8_t l2cap_stack_buffer[20]; 164f5e8608S[email protected] static uint16_t max_l2cap_data_packet_length = 20; 174f5e8608S[email protected] 18*9638642bS[email protected] void mock_simulate_command_complete(const hci_cmd_t *cmd){ 194f5e8608S[email protected] uint8_t packet[] = {HCI_EVENT_COMMAND_COMPLETE, 4, 1, cmd->opcode & 0xff, cmd->opcode >> 8, 0}; 204f5e8608S[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 214f5e8608S[email protected] } 224f5e8608S[email protected] 23*9638642bS[email protected] void mock_simulate_hci_state_working(){ 24*9638642bS[email protected] uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING}; 25*9638642bS[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, 3); 26*9638642bS[email protected] } 27*9638642bS[email protected] 284f5e8608S[email protected] void mock_simulate_scan_response(){ 294f5e8608S[email protected] uint8_t packet[] = {0x3E, 0x0F, 0x02, 0x01, 0x00, 0x01, 0x71, 0xA1, 0xE6, 0x80, 0x48, 0x61, 0x03, 0x02, 0x01, 0x1A, 0xB7}; 304f5e8608S[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 314f5e8608S[email protected] } 32f45e14b1S[email protected] 33f45e14b1S[email protected] int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ 34f45e14b1S[email protected] return 1; 35f45e14b1S[email protected] } 36f45e14b1S[email protected] 374f5e8608S[email protected] int l2cap_can_send_connectionless_packet_now(void){ 384f5e8608S[email protected] return 1; 39f45e14b1S[email protected] } 40f45e14b1S[email protected] 41f45e14b1S[email protected] int hci_send_cmd(const hci_cmd_t *cmd, ...){ 42*9638642bS[email protected] // printf("hci_send_cmd \n"); 434f5e8608S[email protected] 444f5e8608S[email protected] if (cmd == &hci_le_set_scan_enable){ 45*9638642bS[email protected] mock_simulate_command_complete(cmd); 464f5e8608S[email protected] mock_simulate_scan_response(); 474f5e8608S[email protected] } 48f45e14b1S[email protected] return 0; 49f45e14b1S[email protected] } 50f45e14b1S[email protected] 51f45e14b1S[email protected] 52f45e14b1S[email protected] uint8_t *l2cap_get_outgoing_buffer(void){ 53f45e14b1S[email protected] printf("l2cap_get_outgoing_buffer \n"); 54f45e14b1S[email protected] return (uint8_t *)&l2cap_stack_buffer; // 8 bytes 55f45e14b1S[email protected] } 56f45e14b1S[email protected] 57f45e14b1S[email protected] 58f45e14b1S[email protected] uint16_t l2cap_max_mtu(void){ 59f45e14b1S[email protected] printf("l2cap_max_mtu \n"); 60f45e14b1S[email protected] return max_l2cap_data_packet_length; 61f45e14b1S[email protected] } 62f45e14b1S[email protected] 63f45e14b1S[email protected] 64f45e14b1S[email protected] void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id) { 654f5e8608S[email protected] att_packet_handler = packet_handler; 66f45e14b1S[email protected] } 67f45e14b1S[email protected] 68f45e14b1S[email protected] void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){ 694f5e8608S[email protected] gatt_central_packet_handler = handler; 70f45e14b1S[email protected] } 71f45e14b1S[email protected] 72f45e14b1S[email protected] int hci_reserve_packet_buffer(void){ 73f45e14b1S[email protected] printf("hci_reserve_packet_buffer \n"); 74f45e14b1S[email protected] return 1; 75f45e14b1S[email protected] } 76f45e14b1S[email protected] 77f45e14b1S[email protected] int l2cap_reserve_packet_buffer(void){ 78f45e14b1S[email protected] printf("l2cap_reserve_packet_buffer \n"); 79f45e14b1S[email protected] return hci_reserve_packet_buffer(); 80f45e14b1S[email protected] } 81f45e14b1S[email protected] 82f45e14b1S[email protected] int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ 83f45e14b1S[email protected] printf("l2cap_send_prepared_connectionless \n"); 84f45e14b1S[email protected] return 0; 85f45e14b1S[email protected] } 86f45e14b1S[email protected] 87f45e14b1S[email protected] 884f5e8608S[email protected] void hci_disconnect_security_block(hci_con_handle_t con_handle){ 894f5e8608S[email protected] printf("hci_disconnect_security_block \n"); 904f5e8608S[email protected] } 914f5e8608S[email protected] 924f5e8608S[email protected] void hci_dump_log(const char * format, ...){ 934f5e8608S[email protected] printf("hci_disconnect_security_block \n"); 944f5e8608S[email protected] } 954f5e8608S[email protected] 96f45e14b1S[email protected] void l2cap_run(void){ 97f45e14b1S[email protected] } 98