1 #include <stdint.h> 2 #include <stdio.h> 3 #include <string.h> 4 5 #include "mock_gatt_client.h" 6 7 #include "CppUTest/TestHarness.h" 8 #include "CppUTestExt/MockSupport.h" 9 10 static btstack_timer_source_t * btstack_timer = NULL; 11 12 void mock_gatt_client_reset(void){ 13 } 14 void mock_gatt_client_add_primary_service(uint16_t service_uuid){ 15 } 16 void mock_gatt_client_add_characteristic(uint16_t characteristic_uuid){ 17 } 18 void mock_gatt_client_add_characteristic_descriptor(uint16_t descriptor_uuid){ 19 } 20 21 uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){ 22 return ERROR_CODE_SUCCESS; 23 } 24 25 uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16){ 26 return ERROR_CODE_SUCCESS; 27 } 28 29 uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16){ 30 return ERROR_CODE_SUCCESS; 31 } 32 33 uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){ 34 return ERROR_CODE_SUCCESS; 35 } 36 37 uint8_t gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle){ 38 return ERROR_CODE_SUCCESS; 39 } 40 41 uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic, uint16_t configuration){ 42 return ERROR_CODE_SUCCESS; 43 } 44 45 void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){ 46 } 47 48 // copied from gatt_client.c 49 void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service){ 50 service->start_group_handle = little_endian_read_16(packet, offset); 51 service->end_group_handle = little_endian_read_16(packet, offset + 2); 52 reverse_128(&packet[offset + 4], service->uuid128); 53 if (uuid_has_bluetooth_prefix(service->uuid128)){ 54 service->uuid16 = big_endian_read_32(service->uuid128, 0); 55 } else { 56 service->uuid16 = 0; 57 } 58 } 59 60 // copied from gatt_client.c 61 void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic){ 62 characteristic->start_handle = little_endian_read_16(packet, offset); 63 characteristic->value_handle = little_endian_read_16(packet, offset + 2); 64 characteristic->end_handle = little_endian_read_16(packet, offset + 4); 65 characteristic->properties = little_endian_read_16(packet, offset + 6); 66 reverse_128(&packet[offset+8], characteristic->uuid128); 67 if (uuid_has_bluetooth_prefix(characteristic->uuid128)){ 68 characteristic->uuid16 = big_endian_read_32(characteristic->uuid128, 0); 69 } else { 70 characteristic->uuid16 = 0; 71 } 72 } 73 74 // copied from gatt_client.c 75 void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor){ 76 descriptor->handle = little_endian_read_16(packet, offset); 77 reverse_128(&packet[offset+2], descriptor->uuid128); 78 if (uuid_has_bluetooth_prefix(descriptor->uuid128)){ 79 descriptor->uuid16 = big_endian_read_32(descriptor->uuid128, 0); 80 } else { 81 descriptor->uuid16 = 0; 82 } 83 } 84 85 void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification){ 86 } 87 88 void btstack_run_loop_add_timer(btstack_timer_source_t * timer){ 89 btstack_timer = timer; 90 } 91 92 void * btstack_run_loop_get_timer_context(btstack_timer_source_t * timer){ 93 return btstack_timer; 94 } 95 96 int btstack_run_loop_remove_timer(btstack_timer_source_t * timer){ 97 btstack_timer = NULL; 98 return 1; 99 } 100 101 void btstack_run_loop_set_timer(btstack_timer_source_t * timer, uint32_t timeout_in_ms){ 102 } 103 104 void btstack_run_loop_set_timer_context(btstack_timer_source_t * timer, void * context){ 105 } 106 107 void btstack_run_loop_set_timer_handler(btstack_timer_source_t * timer, void (*process)(btstack_timer_source_t * _timer)){ 108 } 109 110