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_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_scan_response(){ 24 uint8_t packet[] = { 0x3E, 0x0F, 0x02, 0x01, 0x00, 0x01, 0x71, 0xA1, 0xE6, 0x80, 0x48, 0x61, 0x03, 0x02, 0x01, 0x1A, 0xB7}; 25 gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 26 } 27 28 int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ 29 return 1; 30 } 31 32 int l2cap_can_send_connectionless_packet_now(void){ 33 return 1; 34 } 35 36 int hci_send_cmd(const hci_cmd_t *cmd, ...){ 37 printf("hci_send_cmd \n"); 38 39 if (cmd == &hci_le_set_scan_enable){ 40 mock_command_complete(cmd); 41 mock_simulate_scan_response(); 42 } 43 return 0; 44 } 45 46 47 uint8_t *l2cap_get_outgoing_buffer(void){ 48 printf("l2cap_get_outgoing_buffer \n"); 49 return (uint8_t *)&l2cap_stack_buffer; // 8 bytes 50 } 51 52 53 uint16_t l2cap_max_mtu(void){ 54 printf("l2cap_max_mtu \n"); 55 return max_l2cap_data_packet_length; 56 } 57 58 59 void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id) { 60 att_packet_handler = packet_handler; 61 } 62 63 void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){ 64 gatt_central_packet_handler = handler; 65 uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING}; 66 gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, 3); 67 } 68 69 int hci_reserve_packet_buffer(void){ 70 printf("hci_reserve_packet_buffer \n"); 71 return 1; 72 } 73 74 int l2cap_reserve_packet_buffer(void){ 75 printf("l2cap_reserve_packet_buffer \n"); 76 return hci_reserve_packet_buffer(); 77 } 78 79 int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ 80 printf("l2cap_send_prepared_connectionless \n"); 81 return 0; 82 } 83 84 85 void hci_disconnect_security_block(hci_con_handle_t con_handle){ 86 printf("hci_disconnect_security_block \n"); 87 } 88 89 void hci_dump_log(const char * format, ...){ 90 printf("hci_disconnect_security_block \n"); 91 } 92 93 void l2cap_run(void){ 94 } 95