mock.c (7b4ad03738650365063b2f91f2fee6d1906647f3) | mock.c (f959ac69f5a39efe9c954f67c7df09bb7c45dab8) |
---|---|
1#include <stdint.h> 2#include <stdio.h> 3#include <stdlib.h> 4#include <string.h> 5 6#include "hci.h" 7#include "hci_dump.h" 8#include "l2cap.h" 9 10#include "ble/att_db.h" 11#include "ble/gatt_client.h" 12#include "ble/sm.h" 13 | 1#include <stdint.h> 2#include <stdio.h> 3#include <stdlib.h> 4#include <string.h> 5 6#include "hci.h" 7#include "hci_dump.h" 8#include "l2cap.h" 9 10#include "ble/att_db.h" 11#include "ble/gatt_client.h" 12#include "ble/sm.h" 13 |
14#define PREBUFFER_SIZE (HCI_INCOMING_PRE_BUFFER_SIZE + 8) 15 |
|
14static btstack_packet_handler_t att_packet_handler; 15static void (*registered_hci_event_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL; 16 17static btstack_linked_list_t connections; 18static const uint16_t max_mtu = 23; | 16static btstack_packet_handler_t att_packet_handler; 17static void (*registered_hci_event_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL; 18 19static btstack_linked_list_t connections; 20static const uint16_t max_mtu = 23; |
19static uint8_t l2cap_stack_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 8 + max_mtu]; // pre buffer + HCI Header + L2CAP header | 21static uint8_t l2cap_stack_buffer[PREBUFFER_SIZE + max_mtu]; // pre buffer + HCI Header + L2CAP header |
20static uint16_t gatt_client_handle = 0x40; 21static hci_connection_t hci_connection; 22 23uint16_t get_gatt_client_handle(void){ 24 return gatt_client_handle; 25} 26 27void mock_simulate_command_complete(const hci_cmd_t *cmd){ --- 43 unchanged lines hidden (view full) --- 71 return 1; 72} 73 74int l2cap_can_send_connectionless_packet_now(void){ 75 return 1; 76} 77 78uint8_t *l2cap_get_outgoing_buffer(void){ | 22static uint16_t gatt_client_handle = 0x40; 23static hci_connection_t hci_connection; 24 25uint16_t get_gatt_client_handle(void){ 26 return gatt_client_handle; 27} 28 29void mock_simulate_command_complete(const hci_cmd_t *cmd){ --- 43 unchanged lines hidden (view full) --- 73 return 1; 74} 75 76int l2cap_can_send_connectionless_packet_now(void){ 77 return 1; 78} 79 80uint8_t *l2cap_get_outgoing_buffer(void){ |
79 // printf("l2cap_get_outgoing_buffer\n"); 80 return (uint8_t *)&l2cap_stack_buffer; // 8 bytes | 81 return (uint8_t *)&l2cap_stack_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 8]; |
81} 82 83uint16_t l2cap_max_mtu(void){ 84 // printf("l2cap_max_mtu\n"); 85 return max_mtu; 86} 87 88uint16_t l2cap_max_le_mtu(void){ --- 22 unchanged lines hidden (view full) --- 111void l2cap_request_can_send_fix_channel_now_event(uint16_t handle, uint16_t channel_id){ 112 uint8_t event[] = { L2CAP_EVENT_CAN_SEND_NOW, 2, 1, 0}; 113 att_packet_handler(HCI_EVENT_PACKET, 0, (uint8_t*)event, sizeof(event)); 114} 115 116int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ 117 att_connection_t att_connection; 118 att_init_connection(&att_connection); | 82} 83 84uint16_t l2cap_max_mtu(void){ 85 // printf("l2cap_max_mtu\n"); 86 return max_mtu; 87} 88 89uint16_t l2cap_max_le_mtu(void){ --- 22 unchanged lines hidden (view full) --- 112void l2cap_request_can_send_fix_channel_now_event(uint16_t handle, uint16_t channel_id){ 113 uint8_t event[] = { L2CAP_EVENT_CAN_SEND_NOW, 2, 1, 0}; 114 att_packet_handler(HCI_EVENT_PACKET, 0, (uint8_t*)event, sizeof(event)); 115} 116 117int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){ 118 att_connection_t att_connection; 119 att_init_connection(&att_connection); |
119 uint8_t response[max_mtu]; 120 uint16_t response_len = att_handle_request(&att_connection, l2cap_get_outgoing_buffer(), len, &response[0]); | 120 uint8_t response_buffer[PREBUFFER_SIZE + max_mtu]; 121 uint8_t * response = &response_buffer[PREBUFFER_SIZE]; 122 uint16_t response_len = att_handle_request(&att_connection, l2cap_get_outgoing_buffer(), len, response); |
121 if (response_len){ 122 att_packet_handler(ATT_DATA_PACKET, gatt_client_handle, &response[0], response_len); 123 } 124 return 0; 125} 126 127void sm_add_event_handler(btstack_packet_callback_registration_t * callback_handler){ 128} --- 63 unchanged lines hidden --- | 123 if (response_len){ 124 att_packet_handler(ATT_DATA_PACKET, gatt_client_handle, &response[0], response_len); 125 } 126 return 0; 127} 128 129void sm_add_event_handler(btstack_packet_callback_registration_t * callback_handler){ 130} --- 63 unchanged lines hidden --- |