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] 15*c442c7c2S[email protected] static const uint16_t max_mtu = 23; 16*c442c7c2S[email protected] static uint8_t l2cap_stack_buffer[max_mtu]; 174f5e8608S[email protected] 189638642bS[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] 239638642bS[email protected] void mock_simulate_hci_state_working(){ 249638642bS[email protected] uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING}; 259638642bS[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, 3); 269638642bS[email protected] } 279638642bS[email protected] 28*c442c7c2S[email protected] void mock_simulate_connected(){ 29*c442c7c2S[email protected] uint8_t packet[] = {0x3E, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05}; 304f5e8608S[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 314f5e8608S[email protected] } 32f45e14b1S[email protected] 33*c442c7c2S[email protected] 34*c442c7c2S[email protected] void mock_simulate_scan_response(){ 35*c442c7c2S[email protected] uint8_t packet[] = {0x3E, 0x0F, 0x02, 0x01, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x03, 0x02, 0x01, 0x05, 0xBC}; 36*c442c7c2S[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 37*c442c7c2S[email protected] } 38*c442c7c2S[email protected] 39*c442c7c2S[email protected] void mock_simulate_exchange_mtu(){ 40*c442c7c2S[email protected] printf("mock_simulate_exchange_mtu\n"); 41*c442c7c2S[email protected] uint8_t packet[] = {0x03, 0x17, 0x00}; 42*c442c7c2S[email protected] att_packet_handler(ATT_DATA_PACKET, 0x40, (uint8_t *)&packet, sizeof(packet)); 43*c442c7c2S[email protected] } 44*c442c7c2S[email protected] 45f45e14b1S[email protected] int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ 46f45e14b1S[email protected] return 1; 47f45e14b1S[email protected] } 48f45e14b1S[email protected] 494f5e8608S[email protected] int l2cap_can_send_connectionless_packet_now(void){ 504f5e8608S[email protected] return 1; 51f45e14b1S[email protected] } 52f45e14b1S[email protected] 53f45e14b1S[email protected] int hci_send_cmd(const hci_cmd_t *cmd, ...){ 54*c442c7c2S[email protected] printf("hci_send_cmd opcode 0x%02x\n", cmd->opcode); 55f45e14b1S[email protected] return 0; 56f45e14b1S[email protected] } 57f45e14b1S[email protected] 58f45e14b1S[email protected] 59f45e14b1S[email protected] uint8_t *l2cap_get_outgoing_buffer(void){ 60f45e14b1S[email protected] printf("l2cap_get_outgoing_buffer\n"); 61f45e14b1S[email protected] return (uint8_t *)&l2cap_stack_buffer; // 8 bytes 62f45e14b1S[email protected] } 63f45e14b1S[email protected] 64f45e14b1S[email protected] uint16_t l2cap_max_mtu(void){ 65f45e14b1S[email protected] printf("l2cap_max_mtu\n"); 66*c442c7c2S[email protected] return max_mtu; 67f45e14b1S[email protected] } 68f45e14b1S[email protected] 69f45e14b1S[email protected] 70f45e14b1S[email protected] void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id) { 714f5e8608S[email protected] att_packet_handler = packet_handler; 72f45e14b1S[email protected] } 73f45e14b1S[email protected] 74f45e14b1S[email protected] void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){ 754f5e8608S[email protected] gatt_central_packet_handler = handler; 76f45e14b1S[email protected] } 77f45e14b1S[email protected] 78f45e14b1S[email protected] int l2cap_reserve_packet_buffer(void){ 79f45e14b1S[email protected] printf("l2cap_reserve_packet_buffer\n"); 80*c442c7c2S[email protected] return 1; 81f45e14b1S[email protected] } 82f45e14b1S[email protected] 83f45e14b1S[email protected] int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ 84f45e14b1S[email protected] printf("l2cap_send_prepared_connectionless\n"); 85f45e14b1S[email protected] return 0; 86f45e14b1S[email protected] } 87f45e14b1S[email protected] 88f45e14b1S[email protected] 894f5e8608S[email protected] void hci_disconnect_security_block(hci_con_handle_t con_handle){ 904f5e8608S[email protected] printf("hci_disconnect_security_block \n"); 914f5e8608S[email protected] } 924f5e8608S[email protected] 934f5e8608S[email protected] void hci_dump_log(const char * format, ...){ 944f5e8608S[email protected] printf("hci_disconnect_security_block \n"); 954f5e8608S[email protected] } 964f5e8608S[email protected] 97f45e14b1S[email protected] void l2cap_run(void){ 98f45e14b1S[email protected] } 99