diff --git a/test/Makefile b/test/Makefile index f8332df32..aa167b3eb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -11,12 +11,13 @@ SUBDIRS = \ crypto \ des_iterator \ flash_tlv \ - gatt_client \ gap \ + gatt_client \ + gatt_server \ hfp \ hid_parser \ - linked_list \ le_device_db_tlv \ + linked_list \ map_test \ mesh \ obex \ @@ -40,12 +41,13 @@ SUBDIRS_BLE = \ att_db \ ble_client \ crypto \ - gatt_client \ gap \ + gatt_client \ hid_parser \ le_device_db_tlv \ linked_list \ ring_buffer \ + gatt_server \ security_manager \ # test fails diff --git a/test/gatt_server/Makefile b/test/gatt_server/Makefile index 23eb996b7..4632a187b 100644 --- a/test/gatt_server/Makefile +++ b/test/gatt_server/Makefile @@ -4,7 +4,9 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null -I. -I../ -I${BTSTACK_ROOT}/src +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null -I. -I../ +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I${BTSTACK_ROOT}/3rd-party/rijndael CFLAGS += -fprofile-arcs -ftest-coverage LDFLAGS += -lCppUTest -lCppUTestExt @@ -12,28 +14,32 @@ VPATH += ${BTSTACK_ROOT}/src VPATH += ${BTSTACK_ROOT}/src/ble VPATH += ${BTSTACK_ROOT}/src/ble/gatt-service VPATH += ${BTSTACK_ROOT}/platform/posix +VPATH += ${BTSTACK_ROOT}/3rd-party/rijndael COMMON = \ ad_parser.c \ - att_server.c \ att_db.c \ + att_db_util.c \ att_dispatch.c \ + att_server.c \ + battery_service_server.c \ + btstack_crypto.c \ btstack_linked_list.c \ btstack_memory.c \ btstack_memory_pool.c \ - btstack_util.c \ - hci_cmd.c \ - hci_dump.c \ - le_device_db_memory.c \ - mock.c \ btstack_tlv.c \ - battery_service_server.c \ + btstack_util.c \ cycling_power_service_server.c \ cycling_speed_and_cadence_service_server.c \ device_information_service_server.c \ + hci_cmd.c \ + hci_dump.c \ heart_rate_service_server.c \ hids_device.c \ + le_device_db_memory.c \ + mock.c \ nordic_spp_service_server.c \ + rijndael.c \ ublox_spp_service_server.c \ COMMON_OBJ = $(COMMON:.c=.o) diff --git a/test/gatt_server/btstack_config.h b/test/gatt_server/btstack_config.h index d70a1631e..d77c6b83d 100644 --- a/test/gatt_server/btstack_config.h +++ b/test/gatt_server/btstack_config.h @@ -10,6 +10,7 @@ #define HAVE_POSIX_TIME #define HAVE_POSIX_FILE_IO #define HAVE_BTSTACK_STDIN +#define HAVE_ASSERT // BTstack features that can be enabled #define ENABLE_BLE @@ -26,6 +27,7 @@ #define ENABLE_SDP_EXTRA_QUERIES #define ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE #define ENABLE_ATT_DELAYED_RESPONSE +#define ENABLE_SOFTWARE_AES128 // BTstack configuration. buffers, sizes, ... #define HCI_ACL_PAYLOAD_SIZE 52 diff --git a/test/gatt_server/gatt_server_test.c b/test/gatt_server/gatt_server_test.c index 99db94cd3..7b62b16ff 100644 --- a/test/gatt_server/gatt_server_test.c +++ b/test/gatt_server/gatt_server_test.c @@ -14,14 +14,76 @@ #include "CppUTest/TestHarness.h" #include "CppUTest/CommandLineTestRunner.h" -#include "hci_cmd.h" - -#include "btstack_memory.h" #include "hci.h" -#include "hci_dump.h" -#include "ble/att_server.h" #include "ble/att_db.h" -#include "profile.h" +#include "ble/att_db_util.h" +#include "ble/att_server.h" +#include "btstack_util.h" +#include "bluetooth.h" + +#include "bluetooth_gatt.h" + +static uint8_t battery_level = 100; + +static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){ + UNUSED(connection_handle); + UNUSED(att_handle); + UNUSED(offset); + UNUSED(buffer); + UNUSED(buffer_size); + + return 0; +} + +static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){ + UNUSED(connection_handle); + UNUSED(att_handle); + UNUSED(transaction_mode); + UNUSED(offset); + UNUSED(buffer); + UNUSED(buffer_size); + + return 0; +} + +TEST_GROUP(ATT_SERVER){ + + void setup(void){ + // init att db util and add a service and characteristic + att_db_util_init(); + // 0x180F + att_db_util_add_service_uuid16(ORG_BLUETOOTH_SERVICE_BATTERY_SERVICE); + // 0x2A19 + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL, ATT_PROPERTY_WRITE | ATT_PROPERTY_READ | ATT_PROPERTY_NOTIFY, ATT_SECURITY_NONE, ATT_SECURITY_NONE, &battery_level, 1); + // 0x2A1B + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_LEVEL_STATE, ATT_PROPERTY_NOTIFY, ATT_SECURITY_NONE, ATT_SECURITY_NONE, &battery_level, 1); + // 0x2A1A + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_BATTERY_POWER_STATE, ATT_PROPERTY_READ | ATT_PROPERTY_NOTIFY, ATT_SECURITY_AUTHENTICATED, ATT_SECURITY_AUTHENTICATED, &battery_level, 1); + // 0x2A49 + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_BLOOD_PRESSURE_FEATURE, ATT_PROPERTY_DYNAMIC | ATT_PROPERTY_READ | ATT_PROPERTY_NOTIFY, ATT_SECURITY_NONE, ATT_SECURITY_NONE, &battery_level, 1); + // 0x2A35 + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_BLOOD_PRESSURE_MEASUREMENT, ATT_PROPERTY_WRITE | ATT_PROPERTY_DYNAMIC, ATT_SECURITY_AUTHENTICATED, ATT_SECURITY_AUTHENTICATED, &battery_level, 1); + // 0x2A38 + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_BODY_SENSOR_LOCATION, ATT_PROPERTY_WRITE | ATT_PROPERTY_DYNAMIC | ATT_PROPERTY_NOTIFY, ATT_SECURITY_NONE, ATT_SECURITY_NONE, &battery_level, 1); + + const uint8_t uuid128[] = {0x00, 0x00, 0xFF, 0x11, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB}; + att_db_util_add_characteristic_uuid128(uuid128, ATT_PROPERTY_WRITE | ATT_PROPERTY_DYNAMIC | ATT_PROPERTY_NOTIFY, ATT_SECURITY_NONE, ATT_SECURITY_NONE, &battery_level, 1); + + // 0x2AA7 + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_CGM_MEASUREMENT, ATT_PROPERTY_WRITE_WITHOUT_RESPONSE | ATT_PROPERTY_DYNAMIC | ATT_PROPERTY_NOTIFY, ATT_SECURITY_AUTHENTICATED, ATT_SECURITY_AUTHENTICATED, &battery_level, 1); + + // 0x2AAB + att_db_util_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_CGM_SESSION_RUN_TIME, ATT_PROPERTY_WRITE_WITHOUT_RESPONSE | ATT_PROPERTY_DYNAMIC | ATT_PROPERTY_NOTIFY, ATT_SECURITY_NONE, ATT_SECURITY_NONE, &battery_level, 1); + + // setup ATT server + att_server_init(att_db_util_get_address(), att_read_callback, att_write_callback); + } +}; + +TEST(ATT_SERVER, test){ + +} + int main (int argc, const char * argv[]){ return CommandLineTestRunner::RunAllTests(argc, argv); diff --git a/test/gatt_server/mock.c b/test/gatt_server/mock.c index 7cd705337..77f178279 100644 --- a/test/gatt_server/mock.c +++ b/test/gatt_server/mock.c @@ -11,6 +11,8 @@ #include "ble/gatt_client.h" #include "ble/sm.h" +#include "btstack_debug.h" + static btstack_packet_handler_t att_packet_handler; static void (*registered_hci_event_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL; @@ -71,6 +73,22 @@ int hci_can_send_acl_le_packet_now(void){ return 1; } +int hci_can_send_command_packet_now(void){ + return 1; +} + +HCI_STATE hci_get_state(void){ + return HCI_STATE_WORKING; +} + +int hci_send_cmd(const hci_cmd_t *cmd, ...){ + btstack_assert(false); + return 0; +} + +void hci_halting_defer(void){ +} + int l2cap_can_send_connectionless_packet_now(void){ return 1; }