xref: /btstack/test/gatt_client/gatt_client_crypto_test.cpp (revision b14d59d74da769ef36f7d77b5a0910ed3a74157b)
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 "btstack_event.h"
21 
22 #include "hci.h"
23 #include "hci_dump.h"
24 #include "ble/gatt_client.h"
25 #include "ble/att_db.h"
26 // #include "profile.h"
27 #include "le-audio/gatt-service/coordinated_set_identification_service_client.h"
28 
29 static uint16_t gatt_client_handle = 0x40;
30 
31 typedef enum {
32     IDLE,
33     SIRK_CONTAINS_RSI,
34     SIRK_DOES_NOT_CONTAIN_RSI
35 } current_test_t;
36 
37 current_test_t test = IDLE;
38 
39 static uint8_t sirk[] = {
40     0x83, 0x8E, 0x68, 0x05, 0x53, 0xF1, 0x41, 0x5A,
41     0xA2, 0x65, 0xBB, 0xAF, 0xC6, 0xEA, 0x03, 0xB8
42 };
43 
44 
45 void mock_simulate_discover_primary_services_response(void);
46 void mock_simulate_att_exchange_mtu_response(void);
47 
csis_handle_client_event(uint8_t packet_type,uint16_t channel,uint8_t * packet,uint16_t size)48 static void csis_handle_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
49     UNUSED(channel);
50     UNUSED(size);
51 
52     if (packet_type != HCI_EVENT_PACKET) return;
53     if (hci_event_packet_get_type(packet) != HCI_EVENT_GATTSERVICE_META) return;
54 
55     uint8_t status;
56     bd_addr_t rsi;
57 
58     switch (hci_event_gattservice_meta_get_subevent_code(packet)){
59         case GATTSERVICE_SUBEVENT_CSIS_RSI_MATCH:
60             // printf("GATTSERVICE_SUBEVENT_CSIS_RSI_MATCH %u\n", gattservice_subevent_csis_rsi_match_get_match(packet));
61             switch(test){
62                 case SIRK_CONTAINS_RSI:
63                     CHECK_EQUAL(1, gattservice_subevent_csis_rsi_match_get_match(packet));
64                     break;
65                 case SIRK_DOES_NOT_CONTAIN_RSI:
66                     CHECK_EQUAL(0, gattservice_subevent_csis_rsi_match_get_match(packet));
67                     break;
68                 default:
69                     break;
70             }
71             break;
72         default:
73             break;
74      }
75 }
76 
TEST_GROUP(GATTClientCrypto)77 TEST_GROUP(GATTClientCrypto){
78     void setup(void){
79         test = IDLE;
80         coordinated_set_identification_service_client_init(csis_handle_client_event);
81     }
82 
83     void reset_query_state(void){
84     }
85 };
86 
TEST(GATTClientCrypto,sirk_contains_rsi_test)87 TEST(GATTClientCrypto, sirk_contains_rsi_test){
88     test = SIRK_CONTAINS_RSI;
89     uint8_t rsi[] = {0x6F, 0x6C, 0x99, 0x62, 0xCC, 0x86};
90     coordinated_set_identification_service_client_check_rsi(rsi, sirk);
91 }
92 
TEST(GATTClientCrypto,sirk_does_not_contain_rsi_test)93 TEST(GATTClientCrypto, sirk_does_not_contain_rsi_test){
94     test = SIRK_DOES_NOT_CONTAIN_RSI;
95     uint8_t rsi[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
96     coordinated_set_identification_service_client_check_rsi(rsi, sirk);
97 }
98 
main(int argc,const char * argv[])99 int main (int argc, const char * argv[]){
100     gatt_client_init();
101     return CommandLineTestRunner::RunAllTests(argc, argv);
102 }
103