1 #include <stdint.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 6 #include <btstack/btstack.h> 7 #include "hci.h" 8 #include "hci_dump.h" 9 #include "l2cap.h" 10 #include "ble_client.h" 11 12 static btstack_packet_handler_t att_packet_handler; 13 static void (*gatt_central_packet_handler) (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL; 14 15 static uint8_t l2cap_stack_buffer[20]; 16 static uint16_t max_l2cap_data_packet_length = 20; 17 18 void mock_simulate_command_complete(const hci_cmd_t *cmd){ 19 uint8_t packet[] = {HCI_EVENT_COMMAND_COMPLETE, 4, 1, cmd->opcode & 0xff, cmd->opcode >> 8, 0}; 20 gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 21 } 22 23 void mock_simulate_hci_state_working(){ 24 uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING}; 25 gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, 3); 26 } 27 28 void mock_simulate_scan_response(){ 29 uint8_t packet[] = {0x3E, 0x0F, 0x02, 0x01, 0x00, 0x01, 0x71, 0xA1, 0xE6, 0x80, 0x48, 0x61, 0x03, 0x02, 0x01, 0x1A, 0xB7}; 30 gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 31 } 32 33 int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ 34 return 1; 35 } 36 37 int l2cap_can_send_connectionless_packet_now(void){ 38 return 1; 39 } 40 41 int hci_send_cmd(const hci_cmd_t *cmd, ...){ 42 // printf("hci_send_cmd \n"); 43 44 if (cmd == &hci_le_set_scan_enable){ 45 mock_simulate_command_complete(cmd); 46 mock_simulate_scan_response(); 47 } 48 return 0; 49 } 50 51 52 uint8_t *l2cap_get_outgoing_buffer(void){ 53 printf("l2cap_get_outgoing_buffer \n"); 54 return (uint8_t *)&l2cap_stack_buffer; // 8 bytes 55 } 56 57 58 uint16_t l2cap_max_mtu(void){ 59 printf("l2cap_max_mtu \n"); 60 return max_l2cap_data_packet_length; 61 } 62 63 64 void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id) { 65 att_packet_handler = packet_handler; 66 } 67 68 void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){ 69 gatt_central_packet_handler = handler; 70 } 71 72 int hci_reserve_packet_buffer(void){ 73 printf("hci_reserve_packet_buffer \n"); 74 return 1; 75 } 76 77 int l2cap_reserve_packet_buffer(void){ 78 printf("l2cap_reserve_packet_buffer \n"); 79 return hci_reserve_packet_buffer(); 80 } 81 82 int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ 83 printf("l2cap_send_prepared_connectionless \n"); 84 return 0; 85 } 86 87 88 void hci_disconnect_security_block(hci_con_handle_t con_handle){ 89 printf("hci_disconnect_security_block \n"); 90 } 91 92 void hci_dump_log(const char * format, ...){ 93 printf("hci_disconnect_security_block \n"); 94 } 95 96 void l2cap_run(void){ 97 } 98