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> 74d890b2dS[email protected] #include "att.h" 8f45e14b1S[email protected] #include "hci.h" 9f45e14b1S[email protected] #include "hci_dump.h" 10f45e14b1S[email protected] #include "l2cap.h" 11567c20c9S[email protected] #include "gatt_client.h" 12567c20c9S[email protected] #include "sm.h" 134f5e8608S[email protected] 144f5e8608S[email protected] static btstack_packet_handler_t att_packet_handler; 154f5e8608S[email protected] static void (*gatt_central_packet_handler) (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL; 164f5e8608S[email protected] 17567c20c9S[email protected] 18c442c7c2S[email protected] static const uint16_t max_mtu = 23; 19c442c7c2S[email protected] static uint8_t l2cap_stack_buffer[max_mtu]; 20ee988ca9S[email protected] uint16_t gatt_client_handle = 0x40; 214f5e8608S[email protected] 22*71de195eSMatthias Ringwald uint16_t get_gatt_client_handle(void){ 23567c20c9S[email protected] return gatt_client_handle; 24567c20c9S[email protected] } 25567c20c9S[email protected] 269638642bS[email protected] void mock_simulate_command_complete(const hci_cmd_t *cmd){ 274f5e8608S[email protected] uint8_t packet[] = {HCI_EVENT_COMMAND_COMPLETE, 4, 1, cmd->opcode & 0xff, cmd->opcode >> 8, 0}; 284f5e8608S[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 294f5e8608S[email protected] } 304f5e8608S[email protected] 31*71de195eSMatthias Ringwald void mock_simulate_hci_state_working(void){ 329638642bS[email protected] uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING}; 339638642bS[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, 3); 349638642bS[email protected] } 359638642bS[email protected] 36*71de195eSMatthias Ringwald void mock_simulate_connected(void){ 37c442c7c2S[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}; 384f5e8608S[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 394f5e8608S[email protected] } 40f45e14b1S[email protected] 41c442c7c2S[email protected] 42*71de195eSMatthias Ringwald void mock_simulate_scan_response(void){ 43c442c7c2S[email protected] uint8_t packet[] = {0x3E, 0x0F, 0x02, 0x01, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x03, 0x02, 0x01, 0x05, 0xBC}; 44c442c7c2S[email protected] gatt_central_packet_handler(NULL, HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet)); 45c442c7c2S[email protected] } 46c442c7c2S[email protected] 474d890b2dS[email protected] static void att_init_connection(att_connection_t * att_connection){ 484d890b2dS[email protected] att_connection->mtu = 23; 494d890b2dS[email protected] att_connection->encryption_key_size = 0; 504d890b2dS[email protected] att_connection->authenticated = 0; 514d890b2dS[email protected] att_connection->authorized = 0; 52c442c7c2S[email protected] } 53c442c7c2S[email protected] 54*71de195eSMatthias Ringwald int l2cap_can_send_connectionless_packet_now(void){ 554f5e8608S[email protected] return 1; 56f45e14b1S[email protected] } 57f45e14b1S[email protected] 58f45e14b1S[email protected] 59f45e14b1S[email protected] uint8_t *l2cap_get_outgoing_buffer(void){ 60f5bdf8a1S[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){ 65f5bdf8a1S[email protected] // printf("l2cap_max_mtu\n"); 66c442c7c2S[email protected] return max_mtu; 67f45e14b1S[email protected] } 68f45e14b1S[email protected] 69567c20c9S[email protected] uint16_t l2cap_max_le_mtu(void){ 70567c20c9S[email protected] // printf("l2cap_max_mtu\n"); 71567c20c9S[email protected] return max_mtu; 72567c20c9S[email protected] } 73f45e14b1S[email protected] 74f45e14b1S[email protected] void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id) { 754f5e8608S[email protected] att_packet_handler = packet_handler; 76f45e14b1S[email protected] } 77f45e14b1S[email protected] 78f45e14b1S[email protected] void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){ 794f5e8608S[email protected] gatt_central_packet_handler = handler; 80f45e14b1S[email protected] } 81f45e14b1S[email protected] 82f45e14b1S[email protected] int l2cap_reserve_packet_buffer(void){ 83567c20c9S[email protected] return 1; 84567c20c9S[email protected] } 85567c20c9S[email protected] 86567c20c9S[email protected] int l2cap_can_send_fixed_channel_packet_now(uint16_t handle){ 87c442c7c2S[email protected] return 1; 88f45e14b1S[email protected] } 89f45e14b1S[email protected] 90f45e14b1S[email protected] int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ 914d890b2dS[email protected] att_connection_t att_connection; 924d890b2dS[email protected] att_init_connection(&att_connection); 934d890b2dS[email protected] uint8_t response[max_mtu]; 944d890b2dS[email protected] uint16_t response_len = att_handle_request(&att_connection, l2cap_get_outgoing_buffer(), len, &response[0]); 95ecedf63aS[email protected] if (response_len){ 96ee988ca9S[email protected] att_packet_handler(ATT_DATA_PACKET, gatt_client_handle, &response[0], response_len); 97ecedf63aS[email protected] } 98f45e14b1S[email protected] return 0; 99f45e14b1S[email protected] } 100f45e14b1S[email protected] 101*71de195eSMatthias Ringwald int sm_cmac_ready(void){ 102567c20c9S[email protected] return 1; 103567c20c9S[email protected] } 104567c20c9S[email protected] void sm_cmac_start(sm_key_t k, uint16_t message_len, uint8_t * message, void (*done_handler)(uint8_t hash[8])){ 105567c20c9S[email protected] //sm_notify_client(SM_IDENTITY_RESOLVING_SUCCEEDED, sm_central_device_addr_type, sm_central_device_address, 0, sm_central_device_matched); 106567c20c9S[email protected] } 107567c20c9S[email protected] 1081bf0402bS[email protected] void run_loop_set_timer(timer_source_t *a, uint32_t timeout_in_ms){ 1091bf0402bS[email protected] } 1101bf0402bS[email protected] 1111bf0402bS[email protected] // Set callback that will be executed when timer expires. 1121bf0402bS[email protected] void run_loop_set_timer_handler(timer_source_t *ts, void (*process)(timer_source_t *_ts)){ 1131bf0402bS[email protected] } 1141bf0402bS[email protected] 1151bf0402bS[email protected] // Add/Remove timer source. 1161bf0402bS[email protected] void run_loop_add_timer(timer_source_t *timer){ 1171bf0402bS[email protected] } 1181bf0402bS[email protected] 1191bf0402bS[email protected] int run_loop_remove_timer(timer_source_t *timer){ 1201bf0402bS[email protected] return 1; 1211bf0402bS[email protected] } 1221bf0402bS[email protected] 123567c20c9S[email protected] 124f6424062S[email protected] // int hci_send_cmd(const hci_cmd_t *cmd, ...){ 125f6424062S[email protected] // // printf("hci_send_cmd opcode 0x%02x\n", cmd->opcode); 126f6424062S[email protected] // return 0; 127f6424062S[email protected] // } 128f45e14b1S[email protected] 129f6424062S[email protected] // int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ 130f6424062S[email protected] // return 1; 131f6424062S[email protected] // } 1324f5e8608S[email protected] 133f6424062S[email protected] // void hci_disconnect_security_block(hci_con_handle_t con_handle){ 134f6424062S[email protected] // printf("hci_disconnect_security_block \n"); 135f6424062S[email protected] // } 136f6424062S[email protected] 137f6424062S[email protected] // void hci_dump_log(const char * format, ...){ 138f6424062S[email protected] // printf("hci_disconnect_security_block \n"); 139f6424062S[email protected] // } 1404f5e8608S[email protected] 141f45e14b1S[email protected] void l2cap_run(void){ 142f45e14b1S[email protected] } 143