xref: /btstack/test/mock/mock_att_server.c (revision a8d51f092f1b660d0f6921369ad2bc3f9368296c)
1 #include <stdint.h>
2 #include <stdio.h>
3 #include <string.h>
4 
5 #include "hci.h"
6 #include "l2cap.h"
7 
8 #include "ble/att_db.h"
9 #include "ble/att_server.h"
10 #include "btstack_debug.h"
11 #include "bluetooth.h"
12 
13 #include "mock_att_server.h"
14 
15 #include "CppUTest/TestHarness.h"
16 #include "CppUTestExt/MockSupport.h"
17 
18 static att_service_handler_t * service;
19 
20 att_service_handler_t * mock_att_server_get_service(void){
21     return service;
22 }
23 
24 uint16_t mock_att_service_read_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
25     btstack_assert(service != NULL);
26     btstack_assert(service->read_callback != NULL);
27     return (service->read_callback)(con_handle, attribute_handle, offset, buffer, buffer_size);
28 }
29 
30 uint16_t mock_att_service_write_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t transaction_mode, uint16_t offset, const uint8_t *buffer, uint16_t buffer_size){
31     btstack_assert(service != NULL);
32     btstack_assert(service->write_callback != NULL);
33     return (service->write_callback)(con_handle, attribute_handle, transaction_mode, offset, (uint8_t *) buffer, buffer_size);
34 }
35 
36 void att_server_register_service_handler(att_service_handler_t * handler){
37     service = handler;
38 }
39 
40 uint16_t att_server_get_mtu(hci_con_handle_t con_handle){
41     UNUSED(con_handle);
42     mock().actualCall("att_server_get_mtu");
43     return ATT_DEFAULT_MTU;
44 }
45 
46 int att_server_indicate(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len){
47     UNUSED(con_handle);
48     UNUSED(attribute_handle);
49     UNUSED(value);
50     UNUSED(value_len);
51     mock().actualCall("att_server_indicate");
52     return ERROR_CODE_SUCCESS;
53 }
54 
55 int att_server_notify(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len){
56     UNUSED(con_handle);
57     UNUSED(attribute_handle);
58     UNUSED(value);
59     UNUSED(value_len);
60     mock().actualCall("att_server_notify");
61     return ERROR_CODE_SUCCESS;
62 }
63 
64 int att_server_register_can_send_now_callback(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle){
65     UNUSED(callback_registration);
66     UNUSED(con_handle);
67     mock().actualCall("att_server_register_can_send_now_callback");
68     return ERROR_CODE_SUCCESS;
69 }
70 
71 int att_server_request_to_send_notification(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle){
72     UNUSED(callback_registration);
73     UNUSED(con_handle);
74     mock().actualCall("att_server_request_to_send_notification");
75     return ERROR_CODE_SUCCESS;
76 }
77 
78 void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){
79     UNUSED(callback_handler);
80 }
81 
82 uint16_t l2cap_max_mtu(void){
83     return HCI_ACL_PAYLOAD_SIZE - L2CAP_HEADER_SIZE;
84 }
85 
86 void l2cap_register_packet_handler(void (*handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)){
87 }