1 2 // ***************************************************************************** 3 // 4 // test rfcomm query tests 5 // 6 // ***************************************************************************** 7 8 9 #include <stdint.h> 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <string.h> 13 14 #include "CppUTest/TestHarness.h" 15 #include "CppUTest/CommandLineTestRunner.h" 16 17 #include "hci_cmd.h" 18 19 #include "btstack_memory.h" 20 #include "hci.h" 21 #include "hci_dump.h" 22 #include "ble/gatt_client.h" 23 #include "ble/att_db.h" 24 #include "profile.h" 25 #include "expected_results.h" 26 27 extern "C" void hci_setup_le_connection(uint16_t con_handle); 28 29 static uint16_t gatt_client_handle = 0x40; 30 static int gatt_query_complete = 0; 31 32 typedef enum { 33 IDLE, 34 DISCOVER_PRIMARY_SERVICES, 35 DISCOVER_PRIMARY_SERVICE_WITH_UUID16, 36 DISCOVER_PRIMARY_SERVICE_WITH_UUID128, 37 38 DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID16, 39 DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID128, 40 41 DISCOVER_CHARACTERISTICS_FOR_SERVICE_WITH_UUID16, 42 DISCOVER_CHARACTERISTICS_FOR_SERVICE_WITH_UUID128, 43 DISCOVER_CHARACTERISTICS_BY_UUID16, 44 DISCOVER_CHARACTERISTICS_BY_UUID128, 45 DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID, 46 47 READ_CHARACTERISTIC_VALUE, 48 READ_LONG_CHARACTERISTIC_VALUE, 49 WRITE_CHARACTERISTIC_VALUE, 50 WRITE_LONG_CHARACTERISTIC_VALUE, 51 52 DISCOVER_CHARACTERISTIC_DESCRIPTORS, 53 READ_CHARACTERISTIC_DESCRIPTOR, 54 WRITE_CHARACTERISTIC_DESCRIPTOR, 55 WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, 56 READ_LONG_CHARACTERISTIC_DESCRIPTOR, 57 WRITE_LONG_CHARACTERISTIC_DESCRIPTOR, 58 WRITE_RELIABLE_LONG_CHARACTERISTIC_VALUE, 59 WRITE_CHARACTERISTIC_VALUE_WITHOUT_RESPONSE 60 } current_test_t; 61 62 current_test_t test = IDLE; 63 64 uint8_t characteristic_uuid128[] = {0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; 65 uint16_t characteristic_uuid16 = 0xF000; 66 67 static int result_index; 68 static uint8_t result_counter; 69 70 static gatt_client_service_t services[50]; 71 static gatt_client_service_t included_services[50]; 72 73 static gatt_client_characteristic_t characteristics[50]; 74 static gatt_client_characteristic_descriptor_t descriptors[50]; 75 76 void mock_simulate_discover_primary_services_response(void); 77 void mock_simulate_att_exchange_mtu_response(void); 78 79 void CHECK_EQUAL_ARRAY(const uint8_t * expected, uint8_t * actual, int size){ 80 for (int i=0; i<size; i++){ 81 BYTES_EQUAL(expected[i], actual[i]); 82 } 83 } 84 85 void pUUID128(const uint8_t *uuid) { 86 printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", 87 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], 88 uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); 89 } 90 91 //static int counter = 0; 92 void CHECK_EQUAL_GATT_ATTRIBUTE(const uint8_t * exp_uuid, const uint8_t * exp_handles, uint8_t * uuid, uint16_t start_handle, uint16_t end_handle){ 93 CHECK_EQUAL_ARRAY(exp_uuid, uuid, 16); 94 if (!exp_handles) return; 95 CHECK_EQUAL(exp_handles[0], start_handle); 96 CHECK_EQUAL(exp_handles[1], end_handle); 97 } 98 99 // ----------------------------------------------------- 100 101 static void verify_primary_services_with_uuid16(void){ 102 CHECK_EQUAL(1, result_index); 103 CHECK_EQUAL_GATT_ATTRIBUTE(primary_service_uuid16, primary_service_uuid16_handles, services[0].uuid128, services[0].start_group_handle, services[0].end_group_handle); 104 } 105 106 107 static void verify_primary_services_with_uuid128(void){ 108 CHECK_EQUAL(1, result_index); 109 CHECK_EQUAL_GATT_ATTRIBUTE(primary_service_uuid128, primary_service_uuid128_handles, services[0].uuid128, services[0].start_group_handle, services[0].end_group_handle); 110 } 111 112 static void verify_primary_services(void){ 113 CHECK_EQUAL(6, result_index); 114 for (int i=0; i<result_index; i++){ 115 CHECK_EQUAL_GATT_ATTRIBUTE(primary_service_uuids[i], NULL, services[i].uuid128, services[i].start_group_handle, services[i].end_group_handle); 116 } 117 } 118 119 static void verify_included_services_uuid16(void){ 120 CHECK_EQUAL(1, result_index); 121 CHECK_EQUAL_GATT_ATTRIBUTE(included_services_uuid16, included_services_uuid16_handles, included_services[0].uuid128, included_services[0].start_group_handle, included_services[0].end_group_handle); 122 } 123 124 static void verify_included_services_uuid128(void){ 125 CHECK_EQUAL(2, result_index); 126 for (int i=0; i<result_index; i++){ 127 CHECK_EQUAL_GATT_ATTRIBUTE(included_services_uuid128[i], included_services_uuid128_handles[i], included_services[i].uuid128, included_services[i].start_group_handle, included_services[i].end_group_handle); 128 } 129 } 130 131 static void verify_charasteristics(void){ 132 CHECK_EQUAL(15, result_index); 133 for (int i=0; i<result_index; i++){ 134 CHECK_EQUAL_GATT_ATTRIBUTE(characteristic_uuids[i], characteristic_handles[i], characteristics[i].uuid128, characteristics[i].start_handle, characteristics[i].end_handle); 135 } 136 } 137 138 static void verify_blob(uint16_t value_length, uint16_t value_offset, uint8_t * value){ 139 uint8_t * expected_value = (uint8_t*)&long_value[value_offset]; 140 CHECK(value_length); 141 CHECK_EQUAL_ARRAY(expected_value, value, value_length); 142 if (value_offset + value_length != sizeof(long_value)) return; 143 result_counter++; 144 } 145 146 static void handle_ble_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 147 if (packet_type != HCI_EVENT_PACKET) return; 148 uint8_t status; 149 gatt_client_service_t service; 150 gatt_client_characteristic_t characteristic; 151 gatt_client_characteristic_descriptor_t descriptor; 152 switch (packet[0]){ 153 case GATT_EVENT_QUERY_COMPLETE: 154 status = packet[4]; 155 gatt_query_complete = 1; 156 if (status){ 157 gatt_query_complete = 0; 158 printf("GATT_EVENT_QUERY_COMPLETE failed with status 0x%02X\n", status); 159 } 160 break; 161 case GATT_EVENT_SERVICE_QUERY_RESULT: 162 service.start_group_handle = little_endian_read_16(packet, 4); 163 service.end_group_handle = little_endian_read_16(packet, 6); 164 service.uuid16 = 0; 165 reverse_128(&packet[8], service.uuid128); 166 if (uuid_has_bluetooth_prefix(service.uuid128)){ 167 service.uuid16 = big_endian_read_32(service.uuid128, 0); 168 } 169 services[result_index++] = service; 170 result_counter++; 171 break; 172 case GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT: 173 service.start_group_handle = little_endian_read_16(packet, 6); 174 service.end_group_handle = little_endian_read_16(packet, 8); 175 service.uuid16 = 0; 176 reverse_128(&packet[10], service.uuid128); 177 if (uuid_has_bluetooth_prefix(service.uuid128)){ 178 service.uuid16 = big_endian_read_32(service.uuid128, 0); 179 } 180 included_services[result_index++] = service; 181 result_counter++; 182 break; 183 case GATT_EVENT_CHARACTERISTIC_QUERY_RESULT: 184 characteristic.start_handle = little_endian_read_16(packet, 4); 185 characteristic.value_handle = little_endian_read_16(packet, 6); 186 characteristic.end_handle = little_endian_read_16(packet, 8); 187 characteristic.properties = little_endian_read_16(packet, 10); 188 characteristic.uuid16 = 0; 189 reverse_128(&packet[12], characteristic.uuid128); 190 if (uuid_has_bluetooth_prefix(characteristic.uuid128)){ 191 characteristic.uuid16 = big_endian_read_32(characteristic.uuid128, 0); 192 } 193 characteristics[result_index++] = characteristic; 194 result_counter++; 195 break; 196 case GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT: 197 descriptor.handle = little_endian_read_16(packet, 4); 198 reverse_128(&packet[6], descriptor.uuid128); 199 if (uuid_has_bluetooth_prefix(descriptor.uuid128)){ 200 descriptor.uuid16 = big_endian_read_32(descriptor.uuid128, 0); 201 } 202 descriptors[result_index++] = descriptor; 203 result_counter++; 204 break; 205 case GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT: 206 case GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT: 207 CHECK_EQUAL(short_value_length, little_endian_read_16(packet, 6)); 208 CHECK_EQUAL_ARRAY((uint8_t*)short_value, &packet[8], short_value_length); 209 result_counter++; 210 break; 211 case GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT: 212 case GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT: 213 verify_blob(little_endian_read_16(packet, 8), little_endian_read_16(packet, 6), &packet[10]); 214 result_counter++; 215 break; 216 } 217 } 218 219 extern "C" int att_write_callback(hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){ 220 switch(test){ 221 case WRITE_CHARACTERISTIC_DESCRIPTOR: 222 case WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION: 223 CHECK_EQUAL(ATT_TRANSACTION_MODE_NONE, transaction_mode); 224 CHECK_EQUAL(0, offset); 225 CHECK_EQUAL_ARRAY(indication, buffer, 2); 226 result_counter++; 227 break; 228 case WRITE_CHARACTERISTIC_VALUE: 229 CHECK_EQUAL(ATT_TRANSACTION_MODE_NONE, transaction_mode); 230 CHECK_EQUAL(0, offset); 231 CHECK_EQUAL_ARRAY((uint8_t *)short_value, buffer, short_value_length); 232 result_counter++; 233 break; 234 case WRITE_LONG_CHARACTERISTIC_DESCRIPTOR: 235 case WRITE_LONG_CHARACTERISTIC_VALUE: 236 case WRITE_RELIABLE_LONG_CHARACTERISTIC_VALUE: 237 if (transaction_mode == ATT_TRANSACTION_MODE_VALIDATE) break; 238 if (transaction_mode == ATT_TRANSACTION_MODE_EXECUTE) break; 239 CHECK_EQUAL(ATT_TRANSACTION_MODE_ACTIVE, transaction_mode); 240 CHECK_EQUAL_ARRAY((uint8_t *)&long_value[offset], buffer, buffer_size); 241 if (offset + buffer_size != sizeof(long_value)) break; 242 result_counter++; 243 break; 244 default: 245 break; 246 } 247 return 0; 248 } 249 250 int copy_bytes(uint8_t * value, uint16_t value_length, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){ 251 int blob_length = value_length - offset; 252 if (blob_length >= buffer_size) blob_length = buffer_size; 253 254 memcpy(buffer, &value[offset], blob_length); 255 return blob_length; 256 } 257 258 extern "C" uint16_t att_read_callback(uint16_t handle, uint16_t attribute_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){ 259 //printf("gatt client test, att_read_callback_t handle 0x%04x, offset %u, buffer %p, buffer_size %u\n", handle, offset, buffer, buffer_size); 260 switch(test){ 261 case READ_CHARACTERISTIC_DESCRIPTOR: 262 case READ_CHARACTERISTIC_VALUE: 263 result_counter++; 264 if (buffer){ 265 return copy_bytes((uint8_t *)short_value, short_value_length, offset, buffer, buffer_size); 266 } 267 return short_value_length; 268 case READ_LONG_CHARACTERISTIC_DESCRIPTOR: 269 case READ_LONG_CHARACTERISTIC_VALUE: 270 result_counter++; 271 if (buffer) { 272 return copy_bytes((uint8_t *)long_value, long_value_length, offset, buffer, buffer_size); 273 } 274 return long_value_length; 275 default: 276 break; 277 } 278 return 0; 279 } 280 281 // static const char * decode_status(uint8_t status){ 282 // switch (status){ 283 // case 0: return "0"; 284 // case GATT_CLIENT_IN_WRONG_STATE: return "GATT_CLIENT_IN_WRONG_STATE"; 285 // case GATT_CLIENT_DIFFERENT_CONTEXT_FOR_ADDRESS_ALREADY_EXISTS: return "GATT_CLIENT_DIFFERENT_CONTEXT_FOR_ADDRESS_ALREADY_EXISTS"; 286 // case GATT_CLIENT_NOT_CONNECTED: return "GATT_CLIENT_NOT_CONNECTED"; 287 // case GATT_CLIENT_VALUE_TOO_LONG: return "GATT_CLIENT_VALUE_TOO_LONG"; 288 // case GATT_CLIENT_BUSY: return "GATT_CLIENT_BUSY"; 289 // case GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED: return "GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED"; 290 // case GATT_CLIENTCHARACTERISTIC_INDICATION_NOT_SUPPORTED: return "GATT_CLIENTCHARACTERISTIC_INDICATION_NOT_SUPPORTED"; 291 // } 292 // } 293 294 TEST_GROUP(GATTClient){ 295 int acl_buffer_size; 296 uint8_t acl_buffer[27]; 297 uint8_t status; 298 299 void setup(void){ 300 result_counter = 0; 301 result_index = 0; 302 test = IDLE; 303 hci_setup_le_connection(gatt_client_handle); 304 } 305 306 gatt_client_t * get_gatt_client(hci_con_handle_t con_handle){ 307 gatt_client_t * gatt_client; 308 (void) gatt_client_get_client(gatt_client_handle, &gatt_client); 309 return gatt_client; 310 } 311 312 void reset_query_state(void){ 313 gatt_client_t * gatt_client = get_gatt_client(gatt_client_handle); 314 gatt_client->state = P_READY; 315 316 gatt_client_set_required_security_level(LEVEL_0); 317 gatt_client_mtu_enable_auto_negotiation(1); 318 319 gatt_query_complete = 0; 320 result_counter = 0; 321 result_index = 0; 322 } 323 324 void set_wrong_gatt_client_state(void){ 325 gatt_client_t * gatt_client = get_gatt_client(gatt_client_handle); 326 CHECK_TRUE(gatt_client != NULL); 327 gatt_client->state = P_W2_SEND_SERVICE_QUERY; 328 } 329 }; 330 331 TEST(GATTClient, gatt_client_setters){ 332 gatt_client_set_required_security_level(LEVEL_4); 333 gatt_client_mtu_enable_auto_negotiation(0); 334 } 335 336 TEST(GATTClient, gatt_client_is_ready_mtu_exchange_disabled){ 337 gatt_client_mtu_enable_auto_negotiation(0); 338 int status = gatt_client_is_ready(gatt_client_handle); 339 CHECK_EQUAL(1, status); 340 } 341 342 TEST(GATTClient, TestDiscoverPrimaryServices){ 343 test = DISCOVER_PRIMARY_SERVICES; 344 status = gatt_client_discover_primary_services(handle_ble_client_event, HCI_CON_HANDLE_INVALID); 345 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 346 347 set_wrong_gatt_client_state(); 348 status = gatt_client_discover_primary_services(handle_ble_client_event, gatt_client_handle); 349 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 350 351 reset_query_state(); 352 status = gatt_client_discover_primary_services(handle_ble_client_event, gatt_client_handle); 353 CHECK_EQUAL(0, status); 354 CHECK_EQUAL(1, gatt_query_complete); 355 verify_primary_services(); 356 CHECK_EQUAL(1, gatt_query_complete); 357 } 358 359 TEST(GATTClient, TestDiscoverPrimaryServicesByUUID16){ 360 test = DISCOVER_PRIMARY_SERVICE_WITH_UUID16; 361 reset_query_state(); 362 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 363 CHECK_EQUAL(0, status); 364 CHECK_EQUAL(1, result_counter); 365 verify_primary_services_with_uuid16(); 366 CHECK_EQUAL(1, gatt_query_complete); 367 } 368 369 TEST(GATTClient, TestDiscoverPrimaryServicesByUUID128){ 370 test = DISCOVER_PRIMARY_SERVICE_WITH_UUID128; 371 status = gatt_client_discover_primary_services_by_uuid128(handle_ble_client_event, gatt_client_handle, primary_service_uuid128); 372 CHECK_EQUAL(0, status); 373 CHECK_EQUAL(1, result_counter); 374 verify_primary_services_with_uuid128(); 375 CHECK_EQUAL(1, gatt_query_complete); 376 377 // invalid con handle 378 status = gatt_client_discover_primary_services_by_uuid128(handle_ble_client_event, HCI_CON_HANDLE_INVALID, primary_service_uuid128); 379 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 380 381 set_wrong_gatt_client_state(); 382 status = gatt_client_discover_primary_services_by_uuid128(handle_ble_client_event, gatt_client_handle, primary_service_uuid128); 383 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 384 } 385 386 TEST(GATTClient, TestFindIncludedServicesForServiceWithUUID16){ 387 test = DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID16; 388 reset_query_state(); 389 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 390 CHECK_EQUAL(0, status); 391 CHECK_EQUAL(1, gatt_query_complete); 392 393 reset_query_state(); 394 status = gatt_client_find_included_services_for_service(handle_ble_client_event, gatt_client_handle, &services[0]); 395 CHECK_EQUAL(0, status); 396 CHECK_EQUAL(1, gatt_query_complete); 397 verify_included_services_uuid16(); 398 } 399 400 TEST(GATTClient, TestFindIncludedServicesForServiceWithUUID128){ 401 test = DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID128; 402 reset_query_state(); 403 status = gatt_client_discover_primary_services_by_uuid128(handle_ble_client_event, gatt_client_handle, primary_service_uuid128); 404 CHECK_EQUAL(0, status); 405 CHECK_EQUAL(1, gatt_query_complete); 406 407 reset_query_state(); 408 status = gatt_client_find_included_services_for_service(handle_ble_client_event, gatt_client_handle, &services[0]); 409 CHECK_EQUAL(0, status); 410 CHECK_EQUAL(1, gatt_query_complete); 411 verify_included_services_uuid128(); 412 413 // invalid con handle 414 status = gatt_client_find_included_services_for_service(handle_ble_client_event, HCI_CON_HANDLE_INVALID, &services[0]); 415 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 416 417 set_wrong_gatt_client_state(); 418 status = gatt_client_find_included_services_for_service(handle_ble_client_event, gatt_client_handle, &services[0]); 419 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 420 } 421 422 TEST(GATTClient, TestDiscoverCharacteristicsForService){ 423 test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_WITH_UUID16; 424 reset_query_state(); 425 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 426 CHECK_EQUAL(0, status); 427 CHECK_EQUAL(1, gatt_query_complete); 428 429 reset_query_state(); 430 status = gatt_client_discover_characteristics_for_service(handle_ble_client_event, gatt_client_handle, &services[0]); 431 CHECK_EQUAL(0, status); 432 CHECK_EQUAL(1, gatt_query_complete); 433 verify_charasteristics(); 434 435 // invalid con handle 436 status = gatt_client_discover_characteristics_for_service(handle_ble_client_event, HCI_CON_HANDLE_INVALID, &services[0]); 437 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 438 439 set_wrong_gatt_client_state(); 440 status = gatt_client_discover_characteristics_for_service(handle_ble_client_event, gatt_client_handle, &services[0]); 441 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 442 } 443 444 TEST(GATTClient, TestDiscoverCharacteristicsByUUID16){ 445 test = DISCOVER_CHARACTERISTICS_BY_UUID16; 446 reset_query_state(); 447 status = gatt_client_discover_characteristics_for_handle_range_by_uuid16(handle_ble_client_event, gatt_client_handle, 0x30, 0x32, 0xF102); 448 CHECK_EQUAL(0, status); 449 CHECK_EQUAL(1, gatt_query_complete); 450 CHECK_EQUAL(1, result_counter); 451 452 // invalid con handle 453 status = gatt_client_discover_characteristics_for_handle_range_by_uuid16(handle_ble_client_event, HCI_CON_HANDLE_INVALID, 0x30, 0x32, 0xF102); 454 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 455 456 set_wrong_gatt_client_state(); 457 status = gatt_client_discover_characteristics_for_handle_range_by_uuid16(handle_ble_client_event, gatt_client_handle, 0x30, 0x32, 0xF102); 458 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 459 } 460 461 TEST(GATTClient, TestDiscoverCharacteristicsByUUID128){ 462 test = DISCOVER_CHARACTERISTICS_BY_UUID128; 463 reset_query_state(); 464 status = gatt_client_discover_characteristics_for_handle_range_by_uuid128(handle_ble_client_event, gatt_client_handle, characteristic_handles[1][0], characteristic_handles[1][1], characteristic_uuids[1]); 465 CHECK_EQUAL(0, status); 466 CHECK_EQUAL(1, gatt_query_complete); 467 CHECK_EQUAL(1, result_counter); 468 469 // invalid con handle 470 status = gatt_client_discover_characteristics_for_handle_range_by_uuid128(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristic_handles[1][0], characteristic_handles[1][1], characteristic_uuids[1]); 471 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 472 473 set_wrong_gatt_client_state(); 474 status = gatt_client_discover_characteristics_for_handle_range_by_uuid128(handle_ble_client_event, gatt_client_handle, characteristic_handles[1][0], characteristic_handles[1][1], characteristic_uuids[1]); 475 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 476 } 477 478 TEST(GATTClient, TestDiscoverCharacteristics4ServiceByUUID128){ 479 test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID; 480 reset_query_state(); 481 status = gatt_client_discover_primary_services_by_uuid128(handle_ble_client_event, gatt_client_handle, primary_service_uuid128); 482 CHECK_EQUAL(0, status); 483 CHECK_EQUAL(1, gatt_query_complete); 484 CHECK_EQUAL(1, result_counter); 485 486 reset_query_state(); 487 uint8_t characteristic_uuid[] = {0x00, 0x00, 0xF2, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB}; 488 status = gatt_client_discover_characteristics_for_service_by_uuid128(handle_ble_client_event, gatt_client_handle, &services[0], characteristic_uuid); 489 CHECK_EQUAL(0, status); 490 CHECK_EQUAL(1, gatt_query_complete); 491 CHECK_EQUAL(1, result_counter); 492 493 reset_query_state(); 494 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF200); 495 CHECK_EQUAL(0, status); 496 CHECK_EQUAL(1, gatt_query_complete); 497 CHECK_EQUAL(1, result_counter); 498 } 499 500 TEST(GATTClient, TestDiscoverCharacteristics4ServiceByUUID16){ 501 test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID; 502 reset_query_state(); 503 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 504 CHECK_EQUAL(0, status); 505 CHECK_EQUAL(1, gatt_query_complete); 506 CHECK_EQUAL(1, result_counter); 507 508 reset_query_state(); 509 uint8_t characteristic_uuid[]= { 0x00, 0x00, 0xF1, 0x05, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB}; 510 status = gatt_client_discover_characteristics_for_service_by_uuid128(handle_ble_client_event, gatt_client_handle, &services[0], characteristic_uuid); 511 CHECK_EQUAL(0, status); 512 CHECK_EQUAL(1, gatt_query_complete); 513 CHECK_EQUAL(1, result_counter); 514 515 reset_query_state(); 516 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 517 CHECK_EQUAL(0, status); 518 CHECK_EQUAL(1, gatt_query_complete); 519 CHECK_EQUAL(1, result_counter); 520 } 521 522 TEST(GATTClient, TestDiscoverCharacteristicDescriptor){ 523 test = DISCOVER_CHARACTERISTIC_DESCRIPTORS; 524 525 reset_query_state(); 526 // invalid con handle 527 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, HCI_CON_HANDLE_INVALID, service_uuid16); 528 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 529 530 set_wrong_gatt_client_state(); 531 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 532 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 533 534 reset_query_state(); 535 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 536 CHECK_EQUAL(0, status); 537 CHECK_EQUAL(1, gatt_query_complete); 538 CHECK_EQUAL(1, result_counter); 539 540 reset_query_state(); 541 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 542 CHECK_EQUAL(0, status); 543 CHECK_EQUAL(1, gatt_query_complete); 544 CHECK_EQUAL(1, result_counter); 545 546 reset_query_state(); 547 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 548 CHECK_EQUAL(0, status); 549 CHECK_EQUAL(1, gatt_query_complete); 550 CHECK(result_counter); 551 CHECK_EQUAL(3, result_index); 552 CHECK_EQUAL(0x2902, descriptors[0].uuid16); 553 CHECK_EQUAL(0x2900, descriptors[1].uuid16); 554 CHECK_EQUAL(0x2901, descriptors[2].uuid16); 555 } 556 557 TEST(GATTClient, TestWriteClientCharacteristicConfiguration){ 558 test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION; 559 reset_query_state(); 560 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 561 CHECK_EQUAL(0, status); 562 CHECK_EQUAL(1, gatt_query_complete); 563 CHECK_EQUAL(1, result_counter); 564 565 reset_query_state(); 566 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 567 CHECK_EQUAL(0, status); 568 CHECK_EQUAL(1, gatt_query_complete); 569 CHECK_EQUAL(1, result_counter); 570 571 // invalid con handle 572 status = gatt_client_write_client_characteristic_configuration(handle_ble_client_event, HCI_CON_HANDLE_INVALID, &characteristics[0], GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); 573 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 574 575 set_wrong_gatt_client_state(); 576 status = gatt_client_write_client_characteristic_configuration(handle_ble_client_event, gatt_client_handle, &characteristics[0], GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); 577 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 578 579 reset_query_state(); 580 status = gatt_client_write_client_characteristic_configuration(handle_ble_client_event, gatt_client_handle, &characteristics[0], GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); 581 CHECK_EQUAL(0, status); 582 CHECK_EQUAL(1, gatt_query_complete); 583 CHECK_EQUAL(1, result_counter); 584 585 reset_query_state(); 586 characteristics->properties = 0; 587 status = gatt_client_write_client_characteristic_configuration(handle_ble_client_event, gatt_client_handle, &characteristics[0], GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); 588 CHECK_EQUAL(GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED, status); 589 590 reset_query_state(); 591 characteristics->properties = 0; 592 status = gatt_client_write_client_characteristic_configuration(handle_ble_client_event, gatt_client_handle, &characteristics[0], GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION); 593 CHECK_EQUAL(GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED, status); 594 } 595 596 TEST(GATTClient, TestReadCharacteristicDescriptor){ 597 test = READ_CHARACTERISTIC_DESCRIPTOR; 598 reset_query_state(); 599 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 600 CHECK_EQUAL(0, status); 601 CHECK_EQUAL(1, gatt_query_complete); 602 CHECK_EQUAL(1, result_counter); 603 604 reset_query_state(); 605 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 606 CHECK_EQUAL(0, status); 607 CHECK_EQUAL(1, gatt_query_complete); 608 CHECK_EQUAL(1, result_counter); 609 610 reset_query_state(); 611 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 612 CHECK_EQUAL(0, status); 613 CHECK_EQUAL(1, gatt_query_complete); 614 CHECK_EQUAL(3, result_counter); 615 616 // invalid con handle 617 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, HCI_CON_HANDLE_INVALID, &characteristics[0]); 618 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 619 620 set_wrong_gatt_client_state(); 621 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 622 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 623 624 reset_query_state(); 625 uint16_t end_handle = characteristics[0].end_handle; 626 characteristics[0].end_handle = characteristics[0].value_handle; 627 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 628 CHECK_EQUAL(0, status); 629 characteristics[0].end_handle = end_handle; 630 631 reset_query_state(); 632 status = gatt_client_read_characteristic_descriptor(handle_ble_client_event, gatt_client_handle, &descriptors[0]); 633 CHECK_EQUAL(0, status); 634 CHECK_EQUAL(1, gatt_query_complete); 635 CHECK_EQUAL(3, result_counter); 636 637 // invalid con handle 638 status = gatt_client_read_characteristic_descriptor(handle_ble_client_event, HCI_CON_HANDLE_INVALID, &descriptors[0]); 639 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 640 641 set_wrong_gatt_client_state(); 642 status = gatt_client_read_characteristic_descriptor(handle_ble_client_event, gatt_client_handle, &descriptors[0]); 643 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 644 } 645 646 TEST(GATTClient, gatt_client_read_value_of_characteristic_using_value_handle){ 647 test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION; 648 reset_query_state(); 649 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 650 CHECK_EQUAL(0, status); 651 CHECK_EQUAL(1, gatt_query_complete); 652 CHECK_EQUAL(1, result_counter); 653 654 reset_query_state(); 655 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 656 CHECK_EQUAL(0, status); 657 CHECK_EQUAL(1, gatt_query_complete); 658 CHECK_EQUAL(1, result_counter); 659 660 // invalid con handle 661 status = gatt_client_read_value_of_characteristic_using_value_handle(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].value_handle); 662 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 663 664 set_wrong_gatt_client_state(); 665 status = gatt_client_read_value_of_characteristic_using_value_handle(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle); 666 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 667 reset_query_state(); 668 } 669 670 TEST(GATTClient, gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset){ 671 test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION; 672 reset_query_state(); 673 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 674 CHECK_EQUAL(0, status); 675 CHECK_EQUAL(1, gatt_query_complete); 676 CHECK_EQUAL(1, result_counter); 677 678 reset_query_state(); 679 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 680 CHECK_EQUAL(0, status); 681 CHECK_EQUAL(1, gatt_query_complete); 682 CHECK_EQUAL(1, result_counter); 683 684 // invalid con handle 685 status = gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].value_handle, 0); 686 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 687 688 set_wrong_gatt_client_state(); 689 status = gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, 0); 690 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 691 reset_query_state(); 692 } 693 694 695 TEST(GATTClient, gatt_client_read_value_of_characteristics_by_uuid16){ 696 test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION; 697 reset_query_state(); 698 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 699 CHECK_EQUAL(0, status); 700 CHECK_EQUAL(1, gatt_query_complete); 701 CHECK_EQUAL(1, result_counter); 702 703 reset_query_state(); 704 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 705 CHECK_EQUAL(0, status); 706 CHECK_EQUAL(1, gatt_query_complete); 707 CHECK_EQUAL(1, result_counter); 708 709 reset_query_state(); 710 status = gatt_client_read_value_of_characteristics_by_uuid16(handle_ble_client_event, gatt_client_handle, characteristics[0].start_handle, characteristics[0].end_handle, characteristics[0].uuid16); 711 CHECK_EQUAL(0, status); 712 CHECK_EQUAL(1, gatt_query_complete); 713 714 // invalid con handle 715 status = gatt_client_read_value_of_characteristics_by_uuid16(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].start_handle, characteristics[0].end_handle, characteristics[0].uuid16); 716 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 717 718 set_wrong_gatt_client_state(); 719 status = gatt_client_read_value_of_characteristics_by_uuid16(handle_ble_client_event, gatt_client_handle, characteristics[0].start_handle, characteristics[0].end_handle, characteristics[0].uuid16); 720 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 721 reset_query_state(); 722 } 723 724 TEST(GATTClient, gatt_client_read_value_of_characteristics_by_uuid128){ 725 test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION; 726 reset_query_state(); 727 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 728 CHECK_EQUAL(0, status); 729 CHECK_EQUAL(1, gatt_query_complete); 730 CHECK_EQUAL(1, result_counter); 731 732 reset_query_state(); 733 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 734 CHECK_EQUAL(0, status); 735 CHECK_EQUAL(1, gatt_query_complete); 736 CHECK_EQUAL(1, result_counter); 737 738 reset_query_state(); 739 status = gatt_client_read_value_of_characteristics_by_uuid128(handle_ble_client_event, gatt_client_handle, characteristics[0].start_handle, characteristics[0].end_handle, characteristics[0].uuid128); 740 CHECK_EQUAL(0, status); 741 CHECK_EQUAL(1, gatt_query_complete); 742 743 // invalid con handle 744 status = gatt_client_read_value_of_characteristics_by_uuid128(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].start_handle, characteristics[0].end_handle, characteristics[0].uuid128); 745 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 746 747 set_wrong_gatt_client_state(); 748 status = gatt_client_read_value_of_characteristics_by_uuid128(handle_ble_client_event, gatt_client_handle, characteristics[0].start_handle, characteristics[0].end_handle, characteristics[0].uuid128); 749 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 750 reset_query_state(); 751 } 752 753 TEST(GATTClient, gatt_client_write_characteristic_descriptor_using_descriptor_handle){ 754 test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION; 755 reset_query_state(); 756 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 757 CHECK_EQUAL(0, status); 758 CHECK_EQUAL(1, gatt_query_complete); 759 CHECK_EQUAL(1, result_counter); 760 761 reset_query_state(); 762 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 763 CHECK_EQUAL(0, status); 764 CHECK_EQUAL(1, gatt_query_complete); 765 CHECK_EQUAL(1, result_counter); 766 767 768 reset_query_state(); 769 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 770 CHECK_EQUAL(0, status); 771 CHECK_EQUAL(1, gatt_query_complete); 772 CHECK_EQUAL(3, result_counter); 773 774 reset_query_state(); 775 status = gatt_client_write_characteristic_descriptor_using_descriptor_handle(handle_ble_client_event, gatt_client_handle, descriptors[0].handle, characteristics[0].end_handle, characteristics[0].uuid128); 776 CHECK_EQUAL(0, status); 777 778 // invalid con handle 779 status = gatt_client_write_characteristic_descriptor_using_descriptor_handle(handle_ble_client_event, HCI_CON_HANDLE_INVALID, descriptors[0].handle, characteristics[0].end_handle, characteristics[0].uuid128); 780 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 781 782 set_wrong_gatt_client_state(); 783 status = gatt_client_write_characteristic_descriptor_using_descriptor_handle(handle_ble_client_event, gatt_client_handle, descriptors[0].handle, characteristics[0].end_handle, characteristics[0].uuid128); 784 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 785 reset_query_state(); 786 } 787 788 TEST(GATTClient, gatt_client_prepare_write){ 789 reset_query_state(); 790 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 791 CHECK_EQUAL(0, status); 792 CHECK_EQUAL(1, gatt_query_complete); 793 CHECK_EQUAL(1, result_counter); 794 795 reset_query_state(); 796 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 797 CHECK_EQUAL(0, status); 798 CHECK_EQUAL(1, gatt_query_complete); 799 CHECK_EQUAL(1, result_counter); 800 801 reset_query_state(); 802 status = gatt_client_prepare_write(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, 0, short_value_length, (uint8_t*)short_value); 803 CHECK_EQUAL(0, status); 804 805 // invalid con handle 806 status = gatt_client_prepare_write(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].value_handle, 0, short_value_length, (uint8_t*)short_value); 807 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 808 809 set_wrong_gatt_client_state(); 810 status = gatt_client_prepare_write(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, 0, short_value_length, (uint8_t*)short_value); 811 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 812 reset_query_state(); 813 } 814 815 TEST(GATTClient, gatt_client_execute_write){ 816 reset_query_state(); 817 status = gatt_client_execute_write(handle_ble_client_event, gatt_client_handle); 818 CHECK_EQUAL(0, status); 819 820 // invalid con handle 821 status = gatt_client_execute_write(handle_ble_client_event, HCI_CON_HANDLE_INVALID); 822 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 823 824 set_wrong_gatt_client_state(); 825 status = gatt_client_execute_write(handle_ble_client_event, gatt_client_handle); 826 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 827 reset_query_state(); 828 } 829 830 TEST(GATTClient, gatt_client_cancel_write){ 831 reset_query_state(); 832 status = gatt_client_cancel_write(handle_ble_client_event, gatt_client_handle); 833 CHECK_EQUAL(0, status); 834 835 // invalid con handle 836 status = gatt_client_cancel_write(handle_ble_client_event, HCI_CON_HANDLE_INVALID); 837 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 838 839 set_wrong_gatt_client_state(); 840 status = gatt_client_cancel_write(handle_ble_client_event, gatt_client_handle); 841 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 842 reset_query_state(); 843 } 844 845 TEST(GATTClient, TestReadCharacteristicValue){ 846 test = READ_CHARACTERISTIC_VALUE; 847 reset_query_state(); 848 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 849 CHECK_EQUAL(0, status); 850 CHECK_EQUAL(1, gatt_query_complete); 851 CHECK_EQUAL(1, result_counter); 852 853 reset_query_state(); 854 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 855 CHECK_EQUAL(0, status); 856 CHECK_EQUAL(1, gatt_query_complete); 857 CHECK_EQUAL(1, result_counter); 858 859 reset_query_state(); 860 status = gatt_client_read_value_of_characteristic(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 861 CHECK_EQUAL(0, status); 862 CHECK_EQUAL(1, gatt_query_complete); 863 CHECK_EQUAL(3, result_counter); 864 } 865 866 TEST(GATTClient, TestWriteCharacteristicValue){ 867 test = WRITE_CHARACTERISTIC_VALUE; 868 reset_query_state(); 869 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 870 CHECK_EQUAL(0, status); 871 CHECK_EQUAL(1, gatt_query_complete); 872 CHECK_EQUAL(1, result_counter); 873 874 reset_query_state(); 875 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 876 CHECK_EQUAL(0, status); 877 CHECK_EQUAL(1, gatt_query_complete); 878 CHECK_EQUAL(1, result_counter); 879 880 // invalid con handle 881 status = gatt_client_write_value_of_characteristic(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].value_handle, short_value_length, (uint8_t*)short_value); 882 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 883 884 set_wrong_gatt_client_state(); 885 status = gatt_client_write_value_of_characteristic(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, short_value_length, (uint8_t*)short_value); 886 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 887 888 889 reset_query_state(); 890 status = gatt_client_write_value_of_characteristic(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, short_value_length, (uint8_t*)short_value); 891 CHECK_EQUAL(0, status); 892 CHECK_EQUAL(1, gatt_query_complete); 893 } 894 895 TEST(GATTClient, TestWriteCharacteristicDescriptor){ 896 test = WRITE_CHARACTERISTIC_DESCRIPTOR; 897 reset_query_state(); 898 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 899 CHECK_EQUAL(0, status); 900 CHECK_EQUAL(1, gatt_query_complete); 901 CHECK_EQUAL(1, result_counter); 902 903 reset_query_state(); 904 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 905 CHECK_EQUAL(0, status); 906 CHECK_EQUAL(1, gatt_query_complete); 907 CHECK_EQUAL(1, result_counter); 908 909 reset_query_state(); 910 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 911 CHECK_EQUAL(0, status); 912 CHECK_EQUAL(1, gatt_query_complete); 913 CHECK_EQUAL(3, result_counter); 914 915 reset_query_state(); 916 status = gatt_client_write_characteristic_descriptor(handle_ble_client_event, gatt_client_handle, &descriptors[0], sizeof(indication), indication); 917 CHECK_EQUAL(0, status); 918 CHECK_EQUAL(1, gatt_query_complete); 919 } 920 921 TEST(GATTClient, TestReadLongCharacteristicValue){ 922 test = READ_LONG_CHARACTERISTIC_VALUE; 923 reset_query_state(); 924 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 925 CHECK_EQUAL(0, status); 926 CHECK_EQUAL(1, gatt_query_complete); 927 CHECK_EQUAL(1, result_counter); 928 929 reset_query_state(); 930 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 931 CHECK_EQUAL(0, status); 932 CHECK_EQUAL(1, gatt_query_complete); 933 CHECK_EQUAL(1, result_counter); 934 935 reset_query_state(); 936 status = gatt_client_read_long_value_of_characteristic(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 937 CHECK_EQUAL(0, status); 938 CHECK_EQUAL(1, gatt_query_complete); 939 CHECK_EQUAL(4, result_counter); 940 } 941 942 TEST(GATTClient, TestReadLongCharacteristicDescriptor){ 943 test = READ_LONG_CHARACTERISTIC_DESCRIPTOR; 944 reset_query_state(); 945 status = gatt_client_discover_primary_services_by_uuid128(handle_ble_client_event, gatt_client_handle, primary_service_uuid128); 946 CHECK_EQUAL(0, status); 947 CHECK_EQUAL(1, gatt_query_complete); 948 CHECK_EQUAL(1, result_counter); 949 950 reset_query_state(); 951 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF200); 952 CHECK_EQUAL(0, status); 953 CHECK_EQUAL(1, gatt_query_complete); 954 CHECK_EQUAL(1, result_counter); 955 956 reset_query_state(); 957 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 958 CHECK_EQUAL(0, status); 959 CHECK_EQUAL(1, gatt_query_complete); 960 CHECK_EQUAL(3, result_counter); 961 962 reset_query_state(); 963 result_counter = 0; 964 status = gatt_client_read_long_characteristic_descriptor(handle_ble_client_event, gatt_client_handle, &descriptors[0]); 965 CHECK_EQUAL(0, status); 966 CHECK_EQUAL(1, gatt_query_complete); 967 CHECK_EQUAL(4, result_counter); 968 } 969 970 971 TEST(GATTClient, TestWriteLongCharacteristicDescriptor){ 972 test = WRITE_LONG_CHARACTERISTIC_DESCRIPTOR; 973 reset_query_state(); 974 status = gatt_client_discover_primary_services_by_uuid128(handle_ble_client_event, gatt_client_handle, primary_service_uuid128); 975 CHECK_EQUAL(0, status); 976 CHECK_EQUAL(1, gatt_query_complete); 977 CHECK_EQUAL(1, result_counter); 978 979 reset_query_state(); 980 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF200); 981 CHECK_EQUAL(0, status); 982 CHECK_EQUAL(1, gatt_query_complete); 983 CHECK_EQUAL(1, result_counter); 984 985 reset_query_state(); 986 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 987 CHECK_EQUAL(0, status); 988 CHECK_EQUAL(1, gatt_query_complete); 989 CHECK_EQUAL(3, result_counter); 990 991 result_counter = 0; 992 status = gatt_client_write_long_characteristic_descriptor(handle_ble_client_event, gatt_client_handle, &descriptors[0], sizeof(long_value), (uint8_t *)long_value); 993 CHECK_EQUAL(0, status); 994 CHECK_EQUAL(1, gatt_query_complete); 995 CHECK_EQUAL(1, result_counter); 996 } 997 998 TEST(GATTClient, TestWriteLongCharacteristicValue){ 999 test = WRITE_LONG_CHARACTERISTIC_VALUE; 1000 reset_query_state(); 1001 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1002 CHECK_EQUAL(0, status); 1003 CHECK_EQUAL(1, gatt_query_complete); 1004 CHECK_EQUAL(1, result_counter); 1005 1006 reset_query_state(); 1007 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 1008 CHECK_EQUAL(0, status); 1009 CHECK_EQUAL(1, gatt_query_complete); 1010 CHECK_EQUAL(1, result_counter); 1011 1012 1013 reset_query_state(); 1014 status = gatt_client_write_long_value_of_characteristic(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1015 CHECK_EQUAL(0, status); 1016 CHECK_EQUAL(1, gatt_query_complete); 1017 } 1018 1019 TEST(GATTClient, TestWriteReliableLongCharacteristicValue){ 1020 test = WRITE_RELIABLE_LONG_CHARACTERISTIC_VALUE; 1021 reset_query_state(); 1022 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1023 CHECK_EQUAL(0, status); 1024 CHECK_EQUAL(1, gatt_query_complete); 1025 CHECK_EQUAL(1, result_counter); 1026 1027 reset_query_state(); 1028 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 1029 CHECK_EQUAL(0, status); 1030 CHECK_EQUAL(1, gatt_query_complete); 1031 CHECK_EQUAL(1, result_counter); 1032 1033 // invalid con handle 1034 status = gatt_client_reliable_write_long_value_of_characteristic(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1035 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1036 1037 set_wrong_gatt_client_state(); 1038 status = gatt_client_reliable_write_long_value_of_characteristic(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1039 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1040 1041 reset_query_state(); 1042 status = gatt_client_reliable_write_long_value_of_characteristic(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1043 CHECK_EQUAL(0, status); 1044 CHECK_EQUAL(1, gatt_query_complete); 1045 } 1046 1047 TEST(GATTClient, gatt_client_write_long_value_of_characteristic_with_offset){ 1048 reset_query_state(); 1049 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1050 CHECK_EQUAL(0, status); 1051 CHECK_EQUAL(1, gatt_query_complete); 1052 CHECK_EQUAL(1, result_counter); 1053 1054 reset_query_state(); 1055 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 1056 CHECK_EQUAL(0, status); 1057 CHECK_EQUAL(1, gatt_query_complete); 1058 CHECK_EQUAL(1, result_counter); 1059 1060 reset_query_state(); 1061 status = gatt_client_write_long_value_of_characteristic_with_offset(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, 0, long_value_length, (uint8_t*)long_value); 1062 CHECK_EQUAL(0, status); 1063 1064 reset_query_state(); 1065 // invalid con handle 1066 status = gatt_client_write_long_value_of_characteristic_with_offset(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].value_handle, 0, long_value_length, (uint8_t*)long_value); 1067 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1068 1069 reset_query_state(); 1070 set_wrong_gatt_client_state(); 1071 status = gatt_client_write_long_value_of_characteristic_with_offset(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, 0, long_value_length, (uint8_t*)long_value); 1072 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1073 } 1074 1075 TEST(GATTClient, gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset){ 1076 reset_query_state(); 1077 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1078 CHECK_EQUAL(0, status); 1079 CHECK_EQUAL(1, gatt_query_complete); 1080 CHECK_EQUAL(1, result_counter); 1081 1082 reset_query_state(); 1083 status = gatt_client_discover_characteristic_descriptors(handle_ble_client_event, gatt_client_handle, &characteristics[0]); 1084 CHECK_EQUAL(0, status); 1085 CHECK_EQUAL(1, gatt_query_complete); 1086 CHECK(result_counter); 1087 CHECK_EQUAL(3, result_index); 1088 CHECK_EQUAL(0x2902, descriptors[0].uuid16); 1089 CHECK_EQUAL(0x2900, descriptors[1].uuid16); 1090 CHECK_EQUAL(0x2901, descriptors[2].uuid16); 1091 1092 reset_query_state(); 1093 status = gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(handle_ble_client_event, gatt_client_handle, descriptors[0].handle, 0); 1094 CHECK_EQUAL(0, status); 1095 1096 reset_query_state(); 1097 // invalid con handle 1098 status = gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(handle_ble_client_event, HCI_CON_HANDLE_INVALID, descriptors[0].handle, 0); 1099 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1100 1101 reset_query_state(); 1102 set_wrong_gatt_client_state(); 1103 status = gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(handle_ble_client_event, gatt_client_handle, descriptors[0].handle, 0); 1104 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1105 } 1106 1107 TEST(GATTClient, gatt_client_read_multiple_characteristic_values){ 1108 reset_query_state(); 1109 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1110 CHECK_EQUAL(0, status); 1111 CHECK_EQUAL(1, gatt_query_complete); 1112 CHECK_EQUAL(1, result_counter); 1113 1114 reset_query_state(); 1115 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 1116 CHECK_EQUAL(0, status); 1117 CHECK_EQUAL(1, gatt_query_complete); 1118 CHECK_EQUAL(1, result_counter); 1119 1120 uint16_t value_handles[] = {characteristics[0].value_handle}; 1121 1122 reset_query_state(); 1123 status = gatt_client_read_multiple_characteristic_values(handle_ble_client_event, gatt_client_handle, 1, value_handles); 1124 CHECK_EQUAL(0, status); 1125 1126 reset_query_state(); 1127 // invalid con handle 1128 status = gatt_client_read_multiple_characteristic_values(handle_ble_client_event, HCI_CON_HANDLE_INVALID, 1, value_handles); 1129 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1130 1131 reset_query_state(); 1132 set_wrong_gatt_client_state(); 1133 status = gatt_client_read_multiple_characteristic_values(handle_ble_client_event, gatt_client_handle, 1, value_handles); 1134 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1135 } 1136 1137 TEST(GATTClient, gatt_client_write_value_of_characteristic_without_response){ 1138 reset_query_state(); 1139 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1140 CHECK_EQUAL(0, status); 1141 CHECK_EQUAL(1, gatt_query_complete); 1142 CHECK_EQUAL(1, result_counter); 1143 1144 reset_query_state(); 1145 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 1146 CHECK_EQUAL(0, status); 1147 CHECK_EQUAL(1, gatt_query_complete); 1148 CHECK_EQUAL(1, result_counter); 1149 1150 reset_query_state(); 1151 // invalid con handle 1152 status = gatt_client_write_value_of_characteristic_without_response(HCI_CON_HANDLE_INVALID, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1153 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1154 1155 reset_query_state(); 1156 set_wrong_gatt_client_state(); 1157 status = gatt_client_write_value_of_characteristic_without_response(gatt_client_handle, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1158 CHECK_EQUAL(GATT_CLIENT_VALUE_TOO_LONG, status); 1159 1160 reset_query_state(); 1161 1162 status = gatt_client_write_value_of_characteristic_without_response(gatt_client_handle, characteristics[0].value_handle, 19, (uint8_t*)long_value); 1163 CHECK_EQUAL(0, status); 1164 } 1165 1166 TEST(GATTClient, gatt_client_is_ready){ 1167 int status = gatt_client_is_ready(HCI_CON_HANDLE_INVALID); 1168 CHECK_EQUAL(0, status); 1169 1170 status = gatt_client_is_ready(gatt_client_handle); 1171 CHECK_EQUAL(1, status); 1172 } 1173 1174 1175 TEST(GATTClient, register_for_notification){ 1176 reset_query_state(); 1177 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1178 CHECK_EQUAL(0, status); 1179 CHECK_EQUAL(1, gatt_query_complete); 1180 CHECK_EQUAL(1, result_counter); 1181 1182 reset_query_state(); 1183 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 1184 CHECK_EQUAL(0, status); 1185 CHECK_EQUAL(1, gatt_query_complete); 1186 CHECK_EQUAL(1, result_counter); 1187 1188 gatt_client_notification_t notification; 1189 1190 gatt_client_listen_for_characteristic_value_updates(¬ification, handle_ble_client_event, gatt_client_handle, &characteristics[0]); 1191 gatt_client_stop_listening_for_characteristic_value_updates(¬ification); 1192 1193 gatt_client_listen_for_characteristic_value_updates(¬ification, handle_ble_client_event, gatt_client_handle, NULL); 1194 gatt_client_stop_listening_for_characteristic_value_updates(¬ification); 1195 } 1196 1197 TEST(GATTClient, gatt_client_signed_write_without_response){ 1198 reset_query_state(); 1199 status = gatt_client_discover_primary_services_by_uuid16(handle_ble_client_event, gatt_client_handle, service_uuid16); 1200 CHECK_EQUAL(0, status); 1201 CHECK_EQUAL(1, gatt_query_complete); 1202 CHECK_EQUAL(1, result_counter); 1203 1204 reset_query_state(); 1205 status = gatt_client_discover_characteristics_for_service_by_uuid16(handle_ble_client_event, gatt_client_handle, &services[0], 0xF100); 1206 CHECK_EQUAL(0, status); 1207 CHECK_EQUAL(1, gatt_query_complete); 1208 CHECK_EQUAL(1, result_counter); 1209 1210 reset_query_state(); 1211 // invalid con handle 1212 status = gatt_client_signed_write_without_response(handle_ble_client_event, HCI_CON_HANDLE_INVALID, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1213 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1214 1215 reset_query_state(); 1216 set_wrong_gatt_client_state(); 1217 status = gatt_client_signed_write_without_response(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1218 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1219 1220 reset_query_state(); 1221 1222 status = gatt_client_signed_write_without_response(handle_ble_client_event, gatt_client_handle, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value); 1223 CHECK_EQUAL(0, status); 1224 } 1225 1226 TEST(GATTClient, gatt_client_discover_secondary_services){ 1227 reset_query_state(); 1228 // invalid con handle 1229 status = gatt_client_discover_secondary_services(handle_ble_client_event, HCI_CON_HANDLE_INVALID); 1230 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1231 1232 reset_query_state(); 1233 set_wrong_gatt_client_state(); 1234 status = gatt_client_discover_secondary_services(handle_ble_client_event, gatt_client_handle); 1235 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1236 1237 reset_query_state(); 1238 1239 status = gatt_client_discover_secondary_services(handle_ble_client_event, gatt_client_handle); 1240 CHECK_EQUAL(0, status); 1241 } 1242 1243 TEST(GATTClient, gatt_client_request_can_write_without_response_event){ 1244 uint8_t status = gatt_client_request_can_write_without_response_event(handle_ble_client_event, HCI_CON_HANDLE_INVALID); 1245 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1246 1247 gatt_client_t * gatt_client = get_gatt_client(gatt_client_handle); 1248 CHECK_TRUE(gatt_client != NULL); 1249 gatt_client->write_without_response_callback = handle_ble_client_event; 1250 status = gatt_client_request_can_write_without_response_event(handle_ble_client_event, gatt_client_handle); 1251 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1252 1253 gatt_client->write_without_response_callback = NULL; 1254 status = gatt_client_request_can_write_without_response_event(handle_ble_client_event, gatt_client_handle); 1255 CHECK_EQUAL(ERROR_CODE_SUCCESS, status); 1256 } 1257 1258 TEST(GATTClient, gatt_client_request_to_write_without_response){ 1259 btstack_context_callback_registration_t callback_registration = { 0 }; 1260 uint8_t status = gatt_client_request_to_write_without_response(&callback_registration, HCI_CON_HANDLE_INVALID); 1261 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1262 1263 status = gatt_client_request_can_write_without_response_event(handle_ble_client_event, gatt_client_handle); 1264 CHECK_EQUAL(ERROR_CODE_SUCCESS, status); 1265 } 1266 1267 static void dummy_callback(void * context){ 1268 (void) context; 1269 } 1270 TEST(GATTClient, gatt_client_request_to_send_gatt_query){ 1271 btstack_context_callback_registration_t callback_registration = { 0 }; 1272 callback_registration.callback = &dummy_callback; 1273 1274 uint8_t status = gatt_client_request_to_send_gatt_query(&callback_registration, HCI_CON_HANDLE_INVALID); 1275 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1276 1277 status = gatt_client_request_to_send_gatt_query(&callback_registration, gatt_client_handle); 1278 CHECK_EQUAL(ERROR_CODE_SUCCESS, status); 1279 } 1280 1281 TEST(GATTClient, gatt_client_send_mtu_negotiation){ 1282 gatt_client_send_mtu_negotiation(handle_ble_client_event, HCI_CON_HANDLE_INVALID); 1283 1284 gatt_client_send_mtu_negotiation(handle_ble_client_event, gatt_client_handle); 1285 1286 gatt_client_t * gatt_client = get_gatt_client(gatt_client_handle); 1287 CHECK_TRUE(gatt_client != NULL); 1288 gatt_client->mtu_state = MTU_AUTO_EXCHANGE_DISABLED; 1289 gatt_client_send_mtu_negotiation(handle_ble_client_event, gatt_client_handle); 1290 1291 gatt_client->mtu_state = SEND_MTU_EXCHANGE; 1292 } 1293 1294 TEST(GATTClient, gatt_client_get_mtu){ 1295 reset_query_state(); 1296 uint16_t mtu; 1297 int status = gatt_client_get_mtu(HCI_CON_HANDLE_INVALID, &mtu); 1298 CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status); 1299 1300 status = gatt_client_get_mtu(gatt_client_handle, &mtu); 1301 CHECK_EQUAL(GATT_CLIENT_IN_WRONG_STATE, status); 1302 CHECK_EQUAL(ATT_DEFAULT_MTU, mtu); 1303 1304 gatt_client_t * gatt_client = get_gatt_client(gatt_client_handle); 1305 CHECK_TRUE(gatt_client != NULL); 1306 gatt_client->mtu = 30; 1307 1308 gatt_client->mtu_state = MTU_EXCHANGED; 1309 status = gatt_client_get_mtu(gatt_client_handle, &mtu); 1310 CHECK_EQUAL(0, status); 1311 CHECK_EQUAL(gatt_client->mtu, mtu); 1312 1313 gatt_client->mtu_state = MTU_AUTO_EXCHANGE_DISABLED; 1314 status = gatt_client_get_mtu(gatt_client_handle, &mtu); 1315 CHECK_EQUAL(0, status); 1316 CHECK_EQUAL(gatt_client->mtu, mtu); 1317 1318 gatt_client->mtu_state = SEND_MTU_EXCHANGE; 1319 } 1320 1321 1322 int main (int argc, const char * argv[]){ 1323 att_set_db(profile_data); 1324 att_set_write_callback(&att_write_callback); 1325 att_set_read_callback(&att_read_callback); 1326 1327 gatt_client_init(); 1328 1329 return CommandLineTestRunner::RunAllTests(argc, argv); 1330 } 1331