test/gatt_client: add tests

This commit is contained in:
Milanka Ringwald 2023-01-06 23:10:25 +01:00
parent 7deeca1c39
commit 617a25959b

View File

@ -64,132 +64,6 @@ current_test_t test = IDLE;
uint8_t characteristic_uuid128[] = {0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb};
uint16_t characteristic_uuid16 = 0xF000;
static const uint8_t service_data_uuid128[] = {
// 0x0056 PRIMARY_SERVICE-0x34FB with Bluetooth prefix
0x18, 0x00, 0x02, 0x00, 0x56, 0x00, 0x00, 0x28, 0xFB, 0x34, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB,
// 0x0057 INCLUDE_SERVICE-0000FF10-0000-1000-8000-00805F9B34FB
0x0c, 0x00, 0x02, 0x00, 0x57, 0x00, 0x02, 0x28, 0x0f, 0x00, 0x11, 0x00,
// 0x0058 INCLUDE_SERVICE-0000FF11-0000-1000-8000-00805F9B34FB
0x0c, 0x00, 0x02, 0x00, 0x58, 0x00, 0x02, 0x28, 0x12, 0x00, 0x14, 0x00,
// Characteristics 16 and 128 bit with different authoriztion/authentication/encryption requirements and read/write flags
// - no requirements
// 0x0059 CHARACTERISTIC-F200-READ | WRITE | DYNAMIC | NOTIFY | INDICATE | RELIABLE_WRITE | WRITE_WITHOUT_RESPONSE
0x0d, 0x00, 0x02, 0x00, 0x59, 0x00, 0x03, 0x28, 0xbe, 0x5a, 0x00, 0x00, 0xf2,
// 0x005a VALUE-F200-READ | WRITE | DYNAMIC | NOTIFY | INDICATE | RELIABLE_WRITE | WRITE_WITHOUT_RESPONSE-''
// READ_ANYBODY, WRITE_ANYBODY
0x08, 0x00, 0x8e, 0x01, 0x5a, 0x00, 0x00, 0xf2,
// 0x005b CLIENT_CHARACTERISTIC_CONFIGURATION
// READ_ANYBODY, WRITE_ANYBODY
0x0a, 0x00, 0x0e, 0x01, 0x5b, 0x00, 0x02, 0x29, 0x00, 0x00,
// 0x005c CHARACTERISTIC_EXTENDED_PROPERTIES
0x0a, 0x00, 0x02, 0x00, 0x5c, 0x00, 0x00, 0x29, 0x01, 0x00,
// 0x005d CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC-
// READ_ANYBODY, WRITE_ANYBODY
0x08, 0x00, 0x0a, 0x00, 0x5d, 0x00, 0x01, 0x29,
// 0x005e CHARACTERISTIC-0000F201-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | NOTIFY | INDICATE | RELIABLE_WRITE
0x1b, 0x00, 0x02, 0x00, 0x5e, 0x00, 0x03, 0x28, 0xba, 0x5f, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x01, 0xf2, 0x00, 0x00,
// 0x005f VALUE-0000F201-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | NOTIFY | INDICATE | RELIABLE_WRITE-''
// READ_ANYBODY, WRITE_ANYBODY
0x16, 0x00, 0x8a, 0x03, 0x5f, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x01, 0xf2, 0x00, 0x00,
// 0x0060 CLIENT_CHARACTERISTIC_CONFIGURATION
// READ_ANYBODY, WRITE_ANYBODY
0x0a, 0x00, 0x0e, 0x01, 0x60, 0x00, 0x02, 0x29, 0x00, 0x00,
// 0x0061 CHARACTERISTIC_EXTENDED_PROPERTIES
0x0a, 0x00, 0x02, 0x00, 0x61, 0x00, 0x00, 0x29, 0x01, 0x00,
// 0x0062 CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC-
// READ_ANYBODY, WRITE_ANYBODY
0x08, 0x00, 0x0a, 0x00, 0x62, 0x00, 0x01, 0x29,
// - neither read nor writable
// 0x0063 CHARACTERISTIC-F202-DYNAMIC
0x0d, 0x00, 0x02, 0x00, 0x63, 0x00, 0x03, 0x28, 0x00, 0x64, 0x00, 0x02, 0xf2,
// 0x0064 VALUE-F202-DYNAMIC-''
//
0x08, 0x00, 0x00, 0x01, 0x64, 0x00, 0x02, 0xf2,
// 0x0065 CHARACTERISTIC_USER_DESCRIPTION-DYNAMIC-
// READ_ANYBODY
0x08, 0x00, 0x02, 0x00, 0x65, 0x00, 0x01, 0x29,
// 0x0066 CHARACTERISTIC-0000F203-0000-1000-8000-00805F9B34FB-DYNAMIC
0x1b, 0x00, 0x02, 0x00, 0x66, 0x00, 0x03, 0x28, 0x00, 0x67, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x03, 0xf2, 0x00, 0x00,
// 0x0067 VALUE-0000F203-0000-1000-8000-00805F9B34FB-DYNAMIC-''
//
0x16, 0x00, 0x00, 0x03, 0x67, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x03, 0xf2, 0x00, 0x00,
// 0x0068 CHARACTERISTIC_USER_DESCRIPTION-DYNAMIC-
// READ_ANYBODY
0x08, 0x00, 0x02, 0x00, 0x68, 0x00, 0x01, 0x29,
// - authorization required
// 0x0069 CHARACTERISTIC-F204-READ | WRITE | DYNAMIC | AUTHORIZATION_REQUIRED
0x0d, 0x00, 0x02, 0x00, 0x69, 0x00, 0x03, 0x28, 0x0a, 0x6a, 0x00, 0x04, 0xf2,
// 0x006a VALUE-F204-READ | WRITE | DYNAMIC | AUTHORIZATION_REQUIRED-''
// READ_AUTHORIZED, WRITE_AUTHORIZED
0x08, 0x00, 0x1b, 0x0d, 0x6a, 0x00, 0x04, 0xf2,
// 0x006b CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC | AUTHORIZATION_REQUIRED-
// READ_ANYBODY, WRITE_AUTHORIZED
0x08, 0x00, 0x1b, 0x00, 0x6b, 0x00, 0x01, 0x29,
// 0x006c CHARACTERISTIC-0000F205-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | AUTHORIZATION_REQUIRED
0x1b, 0x00, 0x02, 0x00, 0x6c, 0x00, 0x03, 0x28, 0x0a, 0x6d, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x05, 0xf2, 0x00, 0x00,
// 0x006d VALUE-0000F205-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | AUTHORIZATION_REQUIRED-''
// READ_AUTHORIZED, WRITE_AUTHORIZED
0x16, 0x00, 0x1b, 0x0f, 0x6d, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x05, 0xf2, 0x00, 0x00,
// 0x006e CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC | AUTHORIZATION_REQUIRED-
// READ_ANYBODY, WRITE_AUTHORIZED
0x08, 0x00, 0x1b, 0x00, 0x6e, 0x00, 0x01, 0x29,
// - authenthication required
// 0x006f CHARACTERISTIC-F206-READ | WRITE | DYNAMIC | AUTHENTICATION_REQUIRED
0x0d, 0x00, 0x02, 0x00, 0x6f, 0x00, 0x03, 0x28, 0x0a, 0x70, 0x00, 0x06, 0xf2,
// 0x0070 VALUE-F206-READ | WRITE | DYNAMIC | AUTHENTICATION_REQUIRED-''
// READ_AUTHENTICATED, WRITE_AUTHENTICATED
0x08, 0x00, 0x1a, 0x09, 0x70, 0x00, 0x06, 0xf2,
// 0x0071 CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC | AUTHENTICATION_REQUIRED-
// READ_ANYBODY, WRITE_AUTHENTICATED
0x08, 0x00, 0x1a, 0x00, 0x71, 0x00, 0x01, 0x29,
// 0x0072 CHARACTERISTIC-0000F207-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | AUTHENTICATION_REQUIRED
0x1b, 0x00, 0x02, 0x00, 0x72, 0x00, 0x03, 0x28, 0x0a, 0x73, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x07, 0xf2, 0x00, 0x00,
// 0x0073 VALUE-0000F207-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | AUTHENTICATION_REQUIRED-''
// READ_AUTHENTICATED, WRITE_AUTHENTICATED
0x16, 0x00, 0x1a, 0x0b, 0x73, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x07, 0xf2, 0x00, 0x00,
// 0x0074 CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC | AUTHENTICATION_REQUIRED-
// READ_ANYBODY, WRITE_AUTHENTICATED
0x08, 0x00, 0x1a, 0x00, 0x74, 0x00, 0x01, 0x29,
// - encryptiont with 128 bit key required
// 0x0075 CHARACTERISTIC-F208-READ | WRITE | DYNAMIC | ENCRYPTION_KEY_SIZE_16
0x0d, 0x00, 0x02, 0x00, 0x75, 0x00, 0x03, 0x28, 0x0a, 0x76, 0x00, 0x08, 0xf2,
// 0x0076 VALUE-F208-READ | WRITE | DYNAMIC | ENCRYPTION_KEY_SIZE_16-''
// READ_ENCRYPTED, WRITE_ENCRYPTED, ENCRYPTION_KEY_SIZE=16
0x08, 0x00, 0x0b, 0xf5, 0x76, 0x00, 0x08, 0xf2,
// 0x0077 CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC | ENCRYPTION_KEY_SIZE_16-
// READ_ANYBODY, WRITE_ENCRYPTED, ENCRYPTION_KEY_SIZE=16
0x08, 0x00, 0x0b, 0xf0, 0x77, 0x00, 0x01, 0x29,
// 0x0078 CHARACTERISTIC-0000F209-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | ENCRYPTION_KEY_SIZE_16
0x1b, 0x00, 0x02, 0x00, 0x78, 0x00, 0x03, 0x28, 0x0a, 0x79, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x09, 0xf2, 0x00, 0x00,
// 0x0079 VALUE-0000F209-0000-1000-8000-00805F9B34FB-READ | WRITE | DYNAMIC | ENCRYPTION_KEY_SIZE_16-''
// READ_ENCRYPTED, WRITE_ENCRYPTED, ENCRYPTION_KEY_SIZE=16
0x16, 0x00, 0x0b, 0xf7, 0x79, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x09, 0xf2, 0x00, 0x00,
// 0x007a CHARACTERISTIC_USER_DESCRIPTION-READ | WRITE | DYNAMIC | ENCRYPTION_KEY_SIZE_16-
// READ_ANYBODY, WRITE_ENCRYPTED, ENCRYPTION_KEY_SIZE=16
0x08, 0x00, 0x0b, 0xf0, 0x7a, 0x00, 0x01, 0x29
};
static const uint8_t service_data_uuid16[] = {
// 0x0015 PRIMARY_SERVICE-FFFF
0x0a, 0x00, 0x02, 0x00, 0x15, 0x00, 0x00, 0x28, 0xff, 0xff,
// 0x0016 CHARACTERISTIC-FFFD-READ | WRITE | DYNAMIC
0x0d, 0x00, 0x02, 0x00, 0x16, 0x00, 0x03, 0x28, 0x0a, 0x17, 0x00, 0xfd, 0xff,
// 0x0017 VALUE-FFFD-READ | WRITE | DYNAMIC-''
// READ_ANYBODY, WRITE_ANYBODY
0x08, 0x00, 0x0a, 0x01, 0x17, 0x00, 0xfd, 0xff,
// 0x0018 CHARACTERISTIC-FFFE-READ | WRITE | DYNAMIC
0x0d, 0x00, 0x02, 0x00, 0x18, 0x00, 0x03, 0x28, 0x0a, 0x19, 0x00, 0xfe, 0xff,
// 0x0019 VALUE-FFFE-READ | WRITE | DYNAMIC-''
// READ_ANYBODY, WRITE_ANYBODY
0x08, 0x00, 0x0a, 0x01, 0x19, 0x00, 0xfe, 0xff,
};
static const uint8_t characteristic_data_uuid128[] = {};
static const uint8_t characteristic_data_uuid16[] = {};
static const uint8_t characteristic_descriptor_data_uuid128[] = {};
static const uint8_t characteristic_descriptor_data_uuid16[] = {};
static int result_index;
static uint8_t result_counter;
@ -452,6 +326,12 @@ TEST(GATTClient, gatt_client_setters){
gatt_client_mtu_enable_auto_negotiation(0);
}
TEST(GATTClient, gatt_client_is_ready_mtu_exchange_disabled){
gatt_client_mtu_enable_auto_negotiation(0);
int status = gatt_client_is_ready(gatt_client_handle);
CHECK_EQUAL(1, status);
}
TEST(GATTClient, TestDiscoverPrimaryServices){
test = DISCOVER_PRIMARY_SERVICES;
status = gatt_client_discover_primary_services(handle_ble_client_event, HCI_CON_HANDLE_INVALID);
@ -955,24 +835,6 @@ TEST(GATTClient, gatt_client_cancel_write){
reset_query_state();
}
TEST(GATTClient, gatt_client_deserialize_service){
gatt_client_service_t service;
gatt_client_deserialize_service(service_data_uuid16, 0, &service);
gatt_client_deserialize_service(service_data_uuid128, 0, &service);
}
// TEST(GATTClient, gatt_client_deserialize_characteristic){
// gatt_client_characteristic_t characteristic;
// gatt_client_deserialize_characteristic(characteristic_data_uuid16, 0, &characteristic);
// gatt_client_deserialize_characteristic(characteristic_data_uuid128, 0, &characteristic);
// }
// TEST(GATTClient, gatt_client_deserialize_characteristic_descriptor){
// gatt_client_characteristic_descriptor_t characteristic_descriptor;
// gatt_client_deserialize_characteristic_descriptor(characteristic_descriptor_data_uuid16, 0, &characteristic_descriptor);
// gatt_client_deserialize_characteristic_descriptor(characteristic_descriptor_data_uuid128, 0, &characteristic_descriptor);
// }
TEST(GATTClient, TestReadCharacteristicValue){
test = READ_CHARACTERISTIC_VALUE;
reset_query_state();
@ -1373,7 +1235,34 @@ TEST(GATTClient, gatt_client_discover_secondary_services){
CHECK_EQUAL(0, status);
}
TEST(GATTClient, gatt_client_request_can_write_without_response_event){
int status = gatt_client_request_can_write_without_response_event(handle_ble_client_event, HCI_CON_HANDLE_INVALID);
CHECK_EQUAL(BTSTACK_MEMORY_ALLOC_FAILED, status);
gatt_client_t * gatt_client = gatt_client_get_client(gatt_client_handle);
CHECK_TRUE(gatt_client != NULL);
btstack_packet_handler_t write_without_response_callback;
gatt_client->write_without_response_callback = write_without_response_callback;
status = gatt_client_request_can_write_without_response_event(handle_ble_client_event, gatt_client_handle);
CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status);
gatt_client->write_without_response_callback = NULL;
status = gatt_client_request_can_write_without_response_event(handle_ble_client_event, gatt_client_handle);
CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
}
TEST(GATTClient, gatt_client_send_mtu_negotiation){
gatt_client_send_mtu_negotiation(handle_ble_client_event, HCI_CON_HANDLE_INVALID);
gatt_client_send_mtu_negotiation(handle_ble_client_event, gatt_client_handle);
gatt_client_t * gatt_client = gatt_client_get_client(gatt_client_handle);
CHECK_TRUE(gatt_client != NULL);
gatt_client->mtu_state = MTU_AUTO_EXCHANGE_DISABLED;
gatt_client_send_mtu_negotiation(handle_ble_client_event, gatt_client_handle);
gatt_client->mtu_state = SEND_MTU_EXCHANGE;
}
TEST(GATTClient, gatt_client_get_mtu){
reset_query_state();