aboutsummaryrefslogtreecommitdiff
path: root/stack/test/gatt/gatt_sr_test.cc
blob: 95a091a012969b3b82de87f6879bff3e187ee8e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <base/logging.h>
#include <gtest/gtest.h>
#include <stdio.h>
#include <cstdint>

#include "osi/test/AllocationTestHarness.h"
#include "stack/test/common/mock_eatt.h"
#include "stack/gatt/gatt_int.h"
#undef LOG_TAG
#include "stack/gatt/gatt_sr.cc"
#include "types/raw_address.h"

#define MAX_UINT16 ((uint16_t)0xffff)

bool MOCK_bluetooth_shim_is_gd_acl_enabled_ = true;
std::map<std::string, int> mock_function_count_map;

tGATT_CB gatt_cb;

namespace {

struct TestMutables {
  struct {
    uint8_t op_code_;
  } attp_build_sr_msg;
  struct {
    uint16_t conn_id_{0};
    uint32_t trans_id_{0};
    tGATTS_REQ_TYPE type_{0xff};
    tGATTS_DATA data_;
  } application_request_callback;
  struct {
    int access_count_{0};
    tGATT_STATUS return_status_{GATT_SUCCESS};
  } gatts_write_attr_perm_check;
};

TestMutables test_state_;
}  // namespace

namespace connection_manager {
bool background_connect_remove(uint8_t app_id, const RawAddress& address) {
  return false;
}
bool direct_connect_remove(uint8_t app_id, const RawAddress& address) {
  return false;
}
}  // namespace connection_manager

BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code,
                          tGATT_SR_MSG* p_msg) {
  test_state_.attp_build_sr_msg.op_code_ = op_code;
  return nullptr;
}
tGATT_STATUS attp_send_cl_confirmation_msg(tGATT_TCB& tcb, uint16_t cid) {
  return GATT_SUCCESS;
}
tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
                              uint8_t op_code, tGATT_CL_MSG* p_msg) {
  return GATT_SUCCESS;
}
tGATT_STATUS attp_send_sr_msg(tGATT_TCB& tcb, uint16_t cid, BT_HDR* p_msg) {
  return GATT_SUCCESS;
}

tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr, uint16_t length) {
  return BTM_SUCCESS;
}

uint8_t btm_ble_read_sec_key_size(const RawAddress& bd_addr) { return 0; }
bool BTM_GetSecurityFlagsByTransport(const RawAddress& bd_addr,
                                     uint8_t* p_sec_flags,
                                     tBT_TRANSPORT transport) {
  return false;
}
void gatt_act_discovery(tGATT_CLCB* p_clcb) {}
bool gatt_disconnect(tGATT_TCB* p_tcb) { return false; }
tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB* p_tcb) { return GATT_CH_CLOSE; }
tGATT_STATUS gatts_db_read_attr_value_by_type(
    tGATT_TCB& tcb, uint16_t cid, tGATT_SVC_DB* p_db, uint8_t op_code,
    BT_HDR* p_rsp, uint16_t s_handle, uint16_t e_handle, const Uuid& type,
    uint16_t* p_len, tGATT_SEC_FLAG sec_flag, uint8_t key_size,
    uint32_t trans_id, uint16_t* p_cur_handle) {
  return GATT_SUCCESS;
}
void gatt_set_ch_state(tGATT_TCB* p_tcb, tGATT_CH_STATE ch_state) {}
Uuid* gatts_get_service_uuid(tGATT_SVC_DB* p_db) { return nullptr; }
tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle,
                                         uint16_t val_len, uint8_t* p_val) {
  return GATT_SUCCESS;
}
tGATT_STATUS gatts_read_attr_perm_check(tGATT_SVC_DB* p_db, bool is_long,
                                        uint16_t handle,
                                        tGATT_SEC_FLAG sec_flag,
                                        uint8_t key_size) {
  return GATT_SUCCESS;
}
tGATT_STATUS gatts_read_attr_value_by_handle(
    tGATT_TCB& tcb, uint16_t cid, tGATT_SVC_DB* p_db, uint8_t op_code,
    uint16_t handle, uint16_t offset, uint8_t* p_value, uint16_t* p_len,
    uint16_t mtu, tGATT_SEC_FLAG sec_flag, uint8_t key_size,
    uint32_t trans_id) {
  return GATT_SUCCESS;
}
tGATT_STATUS gatts_write_attr_perm_check(tGATT_SVC_DB* p_db, uint8_t op_code,
                                         uint16_t handle, uint16_t offset,
                                         uint8_t* p_data, uint16_t len,
                                         tGATT_SEC_FLAG sec_flag,
                                         uint8_t key_size) {
  test_state_.gatts_write_attr_perm_check.access_count_++;
  return test_state_.gatts_write_attr_perm_check.return_status_;
}
void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
                                   bool is_add, bool check_acl_link) {}
bluetooth::common::MessageLoopThread* get_main_thread() { return nullptr; }
void l2cble_set_fixed_channel_tx_data_length(const RawAddress& remote_bda,
                                             uint16_t fix_cid,
                                             uint16_t tx_mtu) {}
void L2CA_SetLeFixedChannelTxDataLength(const RawAddress& remote_bda,
                                        uint16_t fix_cid,
                                        uint16_t tx_mtu) {}
bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type,
                      uint32_t attr_len, uint8_t* p_val) {
  return false;
}
bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem,
                         tSDP_PROTOCOL_ELEM* p_elem_list) {
  return false;
}
bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services,
                               uint16_t* p_service_uuids) {
  return false;
}
bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids,
                         uint16_t* p_uuids) {
  return false;
}
uint32_t SDP_CreateRecord(void) { return 0; }

void ApplicationRequestCallback(uint16_t conn_id, uint32_t trans_id,
                                tGATTS_REQ_TYPE type, tGATTS_DATA* p_data) {
  test_state_.application_request_callback.conn_id_ = conn_id;
  test_state_.application_request_callback.trans_id_ = trans_id;
  test_state_.application_request_callback.type_ = type;
  test_state_.application_request_callback.data_ = *p_data;
}

bool gatt_sr_is_cl_change_aware(tGATT_TCB& tcb) { return false; }
void gatt_sr_init_cl_status(tGATT_TCB& p_tcb) {}
void gatt_sr_update_cl_status(tGATT_TCB& p_tcb, bool chg_aware) {
  p_tcb.is_robust_cache_change_aware = chg_aware;
}

/**
 * Test class to test selected functionality in stack/gatt/gatt_sr.cc
 */
extern void allocation_tracker_uninit(void);
namespace {
uint16_t kHandle = 1;
bt_gatt_db_attribute_type_t kGattCharacteristicType = BTGATT_DB_CHARACTERISTIC;
}  // namespace
class GattSrTest : public AllocationTestHarness {
 protected:
  void SetUp() override {
    AllocationTestHarness::SetUp();
    // Disable our allocation tracker to allow ASAN full range
    allocation_tracker_uninit();
    memset(&tcb_, 0, sizeof(tcb_));
    memset(&el_, 0, sizeof(el_));

    tcb_.trans_id = 0x12345677;
    tcb_.att_lcid = L2CAP_ATT_CID;
    el_.gatt_if = 1;
    gatt_cb.cl_rcb[el_.gatt_if - 1].in_use = true;
    gatt_cb.cl_rcb[el_.gatt_if - 1].app_cb.p_req_cb =
        ApplicationRequestCallback;

    test_state_ = TestMutables();
  }

  void TearDown() override { AllocationTestHarness::TearDown(); }

  tGATT_TCB tcb_;
  tGATT_SRV_LIST_ELEM el_;
};

/* Server Robust Caching Test */
class GattSrRobustCachingTest : public AllocationTestHarness {
 protected:
  void SetUp() override {
    AllocationTestHarness::SetUp();
    memset(&tcb_, 0, sizeof(tcb_));

    default_length_ = 2;
    memset(default_data_, 0, sizeof(default_data_));

    gatt_cb.handle_of_database_hash = 0x0010;
  }

  void TearDown() override { AllocationTestHarness::TearDown(); }

  tGATT_TCB tcb_;
  uint16_t default_length_;
  uint8_t default_data_[2];
};

TEST_F(GattSrTest, gatts_process_write_req_request_prepare_write_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_REQ_PREPARE_WRITE, 0, nullptr,
                          kGattCharacteristicType);
}

TEST_F(GattSrTest,
       gatts_process_write_req_request_prepare_write_max_len_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_REQ_PREPARE_WRITE, MAX_UINT16, nullptr,
                          kGattCharacteristicType);
}

TEST_F(GattSrTest,
       gatts_process_write_req_request_prepare_write_zero_len_max_data) {
  uint8_t max_mem[MAX_UINT16];
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_REQ_PREPARE_WRITE, 0, max_mem,
                          kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_request_prepare_write_typical) {
  uint8_t p_data[2] = {0x34, 0x12};
  uint16_t length = static_cast<uint16_t>(sizeof(p_data) / sizeof(p_data[0]));
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_REQ_PREPARE_WRITE, length, p_data,
                          kGattCharacteristicType);

  CHECK(test_state_.gatts_write_attr_perm_check.access_count_ == 1);
  CHECK(test_state_.application_request_callback.conn_id_ == el_.gatt_if);
  CHECK(test_state_.application_request_callback.trans_id_ == 0x12345678);
  CHECK(test_state_.application_request_callback.type_ ==
        GATTS_REQ_TYPE_WRITE_CHARACTERISTIC);
  CHECK(test_state_.application_request_callback.data_.write_req.offset ==
        0x1234);
  CHECK(test_state_.application_request_callback.data_.write_req.is_prep ==
        true);
  CHECK(test_state_.application_request_callback.data_.write_req.len == 0);
}

TEST_F(GattSrTest, gatts_process_write_req_signed_command_write_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_SIGN_CMD_WRITE, 0, nullptr,
                          kGattCharacteristicType);
}

TEST_F(GattSrTest,
       gatts_process_write_req_signed_command_write_max_len_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_SIGN_CMD_WRITE, MAX_UINT16, nullptr,
                          kGattCharacteristicType);
}

TEST_F(GattSrTest,
       gatts_process_write_req_signed_command_write_zero_len_max_data) {
  uint8_t max_mem[MAX_UINT16];
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_SIGN_CMD_WRITE, 0, max_mem,
                          kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_signed_command_write_typical) {
  static constexpr size_t kDataLength = 4;
  uint8_t p_data[GATT_AUTH_SIGN_LEN + kDataLength] = {
      0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
      0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01};
  uint16_t length = static_cast<uint16_t>(sizeof(p_data) / sizeof(p_data[0]));
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle,
                          GATT_SIGN_CMD_WRITE, length, p_data,
                          kGattCharacteristicType);

  CHECK(test_state_.gatts_write_attr_perm_check.access_count_ == 1);
  CHECK(test_state_.application_request_callback.conn_id_ == el_.gatt_if);
  CHECK(test_state_.application_request_callback.trans_id_ == 0x12345678);
  CHECK(test_state_.application_request_callback.type_ ==
        GATTS_REQ_TYPE_WRITE_CHARACTERISTIC);
  CHECK(test_state_.application_request_callback.data_.write_req.offset == 0x0);
  CHECK(test_state_.application_request_callback.data_.write_req.is_prep ==
        false);
  CHECK(test_state_.application_request_callback.data_.write_req.len ==
        kDataLength);
}

TEST_F(GattSrTest, gatts_process_write_req_command_write_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_CMD_WRITE, 0,
                          nullptr, kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_command_write_max_len_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_CMD_WRITE,
                          MAX_UINT16, nullptr, kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_command_write_zero_len_max_data) {
  uint8_t max_mem[MAX_UINT16];
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_CMD_WRITE, 0,
                          max_mem, kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_command_write_typical) {
  uint8_t p_data[16] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
                        0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01};
  uint16_t length = static_cast<uint16_t>(sizeof(p_data) / sizeof(p_data[0]));
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_CMD_WRITE,
                          length, p_data, kGattCharacteristicType);

  CHECK(test_state_.gatts_write_attr_perm_check.access_count_ == 1);
  CHECK(test_state_.application_request_callback.conn_id_ == el_.gatt_if);
  CHECK(test_state_.application_request_callback.trans_id_ == 0x12345678);
  CHECK(test_state_.application_request_callback.type_ ==
        GATTS_REQ_TYPE_WRITE_CHARACTERISTIC);
  CHECK(test_state_.application_request_callback.data_.write_req.offset == 0x0);
  CHECK(test_state_.application_request_callback.data_.write_req.is_prep ==
        false);
  CHECK(test_state_.application_request_callback.data_.write_req.len == length);
}

TEST_F(GattSrTest, gatts_process_write_req_request_write_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_REQ_WRITE, 0,
                          nullptr, kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_request_write_max_len_no_data) {
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_REQ_WRITE,
                          MAX_UINT16, nullptr, kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_request_write_zero_len_max_data) {
  uint8_t max_mem[MAX_UINT16];
  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_REQ_WRITE, 0,
                          max_mem, kGattCharacteristicType);
}

TEST_F(GattSrTest, gatts_process_write_req_request_write_typical) {
  uint8_t p_data[16] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
                        0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01};
  uint16_t length = static_cast<uint16_t>(sizeof(p_data) / sizeof(p_data[0]));

  gatts_process_write_req(tcb_, L2CAP_ATT_CID, el_, kHandle, GATT_REQ_WRITE,
                          length, p_data, kGattCharacteristicType);

  CHECK(test_state_.gatts_write_attr_perm_check.access_count_ == 1);
  CHECK(test_state_.application_request_callback.conn_id_ == el_.gatt_if);
  CHECK(test_state_.application_request_callback.trans_id_ == 0x12345678);
  CHECK(test_state_.application_request_callback.type_ ==
        GATTS_REQ_TYPE_WRITE_CHARACTERISTIC);
  CHECK(test_state_.application_request_callback.data_.write_req.offset == 0x0);
  CHECK(test_state_.application_request_callback.data_.write_req.is_prep ==
        false);
  CHECK(test_state_.application_request_callback.data_.write_req.len == length);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_by_grp_type) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_READ_BY_GRP_TYPE, default_length_,
      default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_find_type_value) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_FIND_TYPE_VALUE, default_length_,
      default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_find_info) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_FIND_INFO, default_length_, default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_by_type_parse_failed) {
  // INVALID_PDU
  uint16_t len = 4;
  uint8_t p_data[4] = {0x00, 0x02, 0x14, 0x02};
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_READ_BY_TYPE, len, p_data);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_by_type_db_hash_uuid) {
  // ATT_READ_BY_TYPE_REQ(0x0001, 0x0010, 0x2B2A)
  uint16_t len = 6;
  uint8_t p_data[6] = {0x01, 0x00, 0x10, 0x00, 0x2A, 0x2B};
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_READ_BY_TYPE, len, p_data);

  ASSERT_FALSE(should_ignore);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_by_type_wrong_range) {
  // ATT_READ_BY_TYPE_REQ(0x0200, 0x0214, 0x2803)
  uint16_t len = 6;
  uint8_t p_data[6] = {0x00, 0x02, 0x14, 0x02, 0x2A, 0x28};
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_READ_BY_TYPE, len, p_data);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_by_type_other_uuid) {
  // ATT_READ_BY_TYPE_REQ(0x0200, 0x0214, 0x2803)
  uint16_t len = 6;
  uint8_t p_data[6] = {0x00, 0x02, 0x14, 0x02, 0x03, 0x28};
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_READ_BY_TYPE, len, p_data);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_parse_failed) {
  // INVALID_PDU
  uint8_t p_data[1] = {0x02};
  uint16_t len = 1;
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(tcb_, L2CAP_ATT_CID,
                                                    GATT_REQ_READ, len, p_data);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_db_hash_handle) {
  // ATT_READ_REQ(0x0010)
  uint8_t p_data[2] = {0x10, 0x00};
  uint16_t len = 2;
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(tcb_, L2CAP_ATT_CID,
                                                    GATT_REQ_READ, len, p_data);

  ASSERT_FALSE(should_ignore);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_other_handle) {
  // ATT_READ_REQ(0x0002)
  uint8_t p_data[2] = {0x02, 0x00};
  uint16_t len = 2;
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(tcb_, L2CAP_ATT_CID,
                                                    GATT_REQ_READ, len, p_data);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_blob) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_READ_BLOB, default_length_, default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_read_multi) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_READ_MULTI, default_length_, default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_write) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_WRITE, default_length_, default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_cmd_write) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_CMD_WRITE, default_length_, default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_FALSE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_sign_cmd_write) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_SIGN_CMD_WRITE, default_length_, default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_FALSE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_prepare_write) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore =
      gatts_process_db_out_of_sync(tcb_, L2CAP_ATT_CID, GATT_REQ_PREPARE_WRITE,
                                   default_length_, default_data_);

  ASSERT_TRUE(should_ignore);
  ASSERT_TRUE(tcb_.is_robust_cache_change_aware);
}

TEST_F(GattSrRobustCachingTest, gatts_process_db_out_of_sync_for_gatt_req_mtu) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_MTU, default_length_, default_data_);

  ASSERT_FALSE(should_ignore);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_req_exec_write) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore = gatts_process_db_out_of_sync(
      tcb_, L2CAP_ATT_CID, GATT_REQ_EXEC_WRITE, default_length_, default_data_);

  ASSERT_FALSE(should_ignore);
}

TEST_F(GattSrRobustCachingTest,
       gatts_process_db_out_of_sync_for_gatt_handle_value_conf) {
  tcb_.is_robust_cache_change_aware = false;

  bool should_ignore =
      gatts_process_db_out_of_sync(tcb_, L2CAP_ATT_CID, GATT_HANDLE_VALUE_CONF,
                                   default_length_, default_data_);

  ASSERT_FALSE(should_ignore);
}