1 /******************************************************************************
2  *
3  *  Copyright 2016 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 #include <stdarg.h>
21 
22 #include <string>
23 
24 #include "crypto_toolbox/crypto_toolbox.h"
25 #include "hci/include/packet_fragmenter.h"
26 #include "internal_include/stack_config.h"
27 #include "stack/btm/btm_int_types.h"
28 #include "stack/include/acl_api.h"
29 #include "stack/include/bt_octets.h"
30 #include "stack/include/btm_ble_api.h"
31 #include "stack/include/smp_status.h"
32 #include "stack/smp/p_256_ecc_pp.h"
33 #include "stack/smp/smp_int.h"
34 #include "test/mock/mock_stack_acl.h"
35 #include "types/hci_role.h"
36 #include "types/raw_address.h"
37 
38 using testing::StrEq;
39 
40 tBTM_CB btm_cb;
41 
42 const std::string kSmpOptions("mock smp options");
43 const std::string kBroadcastAudioConfigOptions(
44     "mock broadcast audio config options");
get_pts_avrcp_test(void)45 bool get_pts_avrcp_test(void) { return false; }
get_pts_secure_only_mode(void)46 bool get_pts_secure_only_mode(void) { return false; }
get_pts_conn_updates_disabled(void)47 bool get_pts_conn_updates_disabled(void) { return false; }
get_pts_crosskey_sdp_disable(void)48 bool get_pts_crosskey_sdp_disable(void) { return false; }
get_pts_smp_options(void)49 const std::string* get_pts_smp_options(void) { return &kSmpOptions; }
get_pts_smp_failure_case(void)50 int get_pts_smp_failure_case(void) { return 123; }
get_pts_force_eatt_for_notifications(void)51 bool get_pts_force_eatt_for_notifications(void) { return false; }
get_pts_connect_eatt_unconditionally(void)52 bool get_pts_connect_eatt_unconditionally(void) { return false; }
get_pts_connect_eatt_before_encryption(void)53 bool get_pts_connect_eatt_before_encryption(void) { return false; }
get_pts_unencrypt_broadcast(void)54 bool get_pts_unencrypt_broadcast(void) { return false; }
get_pts_eatt_peripheral_collision_support(void)55 bool get_pts_eatt_peripheral_collision_support(void) { return false; }
get_pts_use_eatt_for_all_services(void)56 bool get_pts_use_eatt_for_all_services(void) { return false; }
get_pts_force_le_audio_multiple_contexts_metadata(void)57 bool get_pts_force_le_audio_multiple_contexts_metadata(void) { return false; }
get_pts_l2cap_ecoc_upper_tester(void)58 bool get_pts_l2cap_ecoc_upper_tester(void) { return false; }
get_pts_l2cap_ecoc_min_key_size(void)59 int get_pts_l2cap_ecoc_min_key_size(void) { return -1; }
get_pts_l2cap_ecoc_initial_chan_cnt(void)60 int get_pts_l2cap_ecoc_initial_chan_cnt(void) { return -1; }
get_pts_l2cap_ecoc_connect_remaining(void)61 bool get_pts_l2cap_ecoc_connect_remaining(void) { return false; }
get_pts_l2cap_ecoc_send_num_of_sdu(void)62 int get_pts_l2cap_ecoc_send_num_of_sdu(void) { return -1; }
get_pts_l2cap_ecoc_reconfigure(void)63 bool get_pts_l2cap_ecoc_reconfigure(void) { return false; }
get_pts_broadcast_audio_config_options(void)64 const std::string* get_pts_broadcast_audio_config_options(void) {
65   return &kBroadcastAudioConfigOptions;
66 }
get_pts_le_audio_disable_ases_before_stopping(void)67 bool get_pts_le_audio_disable_ases_before_stopping(void) { return false; }
get_all(void)68 config_t* get_all(void) { return nullptr; }
packet_fragmenter_get_interface()69 const packet_fragmenter_t* packet_fragmenter_get_interface() { return nullptr; }
70 
71 stack_config_t mock_stack_config{
72     .get_pts_avrcp_test = get_pts_avrcp_test,
73     .get_pts_secure_only_mode = get_pts_secure_only_mode,
74     .get_pts_conn_updates_disabled = get_pts_conn_updates_disabled,
75     .get_pts_crosskey_sdp_disable = get_pts_crosskey_sdp_disable,
76     .get_pts_smp_options = get_pts_smp_options,
77     .get_pts_smp_failure_case = get_pts_smp_failure_case,
78     .get_pts_force_eatt_for_notifications =
79         get_pts_force_eatt_for_notifications,
80     .get_pts_connect_eatt_unconditionally =
81         get_pts_connect_eatt_unconditionally,
82     .get_pts_connect_eatt_before_encryption =
83         get_pts_connect_eatt_before_encryption,
84     .get_pts_unencrypt_broadcast = get_pts_unencrypt_broadcast,
85     .get_pts_eatt_peripheral_collision_support =
86         get_pts_eatt_peripheral_collision_support,
87     .get_pts_use_eatt_for_all_services = get_pts_use_eatt_for_all_services,
88     .get_pts_force_le_audio_multiple_contexts_metadata =
89         get_pts_force_le_audio_multiple_contexts_metadata,
90     .get_pts_l2cap_ecoc_upper_tester = get_pts_l2cap_ecoc_upper_tester,
91     .get_pts_l2cap_ecoc_min_key_size = get_pts_l2cap_ecoc_min_key_size,
92     .get_pts_l2cap_ecoc_initial_chan_cnt = get_pts_l2cap_ecoc_initial_chan_cnt,
93     .get_pts_l2cap_ecoc_connect_remaining =
94         get_pts_l2cap_ecoc_connect_remaining,
95     .get_pts_l2cap_ecoc_send_num_of_sdu = get_pts_l2cap_ecoc_send_num_of_sdu,
96     .get_pts_l2cap_ecoc_reconfigure = get_pts_l2cap_ecoc_reconfigure,
97     .get_pts_broadcast_audio_config_options =
98         get_pts_broadcast_audio_config_options,
99     .get_pts_le_audio_disable_ases_before_stopping =
100         get_pts_le_audio_disable_ases_before_stopping,
101     .get_all = get_all,
102 };
stack_config_get_interface(void)103 const stack_config_t* stack_config_get_interface(void) {
104   return &mock_stack_config;
105 }
106 
107 /*
108  * This test verifies various key distribution methods in SMP works using the
109  * following parameter set:
110  *
111  * When testing target as Central (Initiator is local, Responder is remote)
112  *
113  * Initiator's Pairing Request: 0x070710000001(01)
114  * Responder's Pairing Response: 0x050008000003(02)
115  * Initiator's Bluetooth Address: 0xA1A2A3A4A5A6
116  * Initiator's Bluetooth Address Type: 0x01
117  * Responder's Bluetooth Address: 0xB1B2B3B4B5B6
118  * Responder's Bluetooth Address Type: 0x00
119  * Initiator's Random Number: 0x5783D52156AD6F0E6388274EC6702EE0
120  * TK Encryption Key: 0x0
121  *
122  * Correct values:
123  *
124  * p1: 0x05000800000302070710000001010001
125  * p1 XOR r: 0x5283dd2156ae6d096498274ec7712ee1
126  * p1 prime: 0x02c7aa2a9857ac866ff91232df0e3c95
127  * p2: 0x00000000a1a2a3a4a5a6b1b2b3b4b5b6
128  * MConfirm (c1): 0x1e1e3fef878988ead2a74dc5bef13b86
129  *
130  * NOTE: All these values are presented in mathematical reasonable canonical
131  * form that has MSB on the left and LSB on the right. In Bluetooth packets,
132  * they are mostly reversed to be Little Endian which have LSB on the left and
133  * MSB on the right.
134  */
135 
136 Octet16 smp_gen_p1_4_confirm(tSMP_CB* p_cb, tBLE_ADDR_TYPE remote_bd_addr_type);
137 
138 Octet16 smp_gen_p2_4_confirm(tSMP_CB* p_cb, const RawAddress& remote_bda);
139 
140 tSMP_STATUS smp_calculate_comfirm(tSMP_CB* p_cb, const Octet16& rand,
141                                   Octet16* output);
142 
dump_uint128(const Octet16 & a,char * buffer)143 void dump_uint128(const Octet16& a, char* buffer) {
144   for (unsigned int i = 0; i < OCTET16_LEN; ++i) {
145     snprintf(buffer, 3, "%02x", a[i]);
146     buffer += 2;
147   }
148   *buffer = '\0';
149 }
150 
dump_uint128_reverse(const Octet16 & a,char * buffer)151 void dump_uint128_reverse(const Octet16& a, char* buffer) {
152   for (int i = (int)(OCTET16_LEN - 1); i >= 0; --i) {
153     snprintf(buffer, 3, "%02x", a[i]);
154     buffer += 2;
155   }
156   *buffer = '\0';
157 }
158 
print_uint128(const Octet16 & a)159 void print_uint128(const Octet16& a) {
160   for (unsigned int i = 0; i < OCTET16_LEN; ++i) {
161     printf("%02x", a[i]);
162   }
163   printf("\n");
164 }
165 
parse_uint128(const char * input)166 Octet16 parse_uint128(const char* input) {
167   Octet16 output{0};
168   for (unsigned int count = 0; count < OCTET16_LEN; count++) {
169     sscanf(input, "%2hhx", &output[count]);
170     input += 2;
171   }
172   return output;
173 }
174 
175 class SmpCalculateConfirmTest : public testing::Test {
176  protected:
177   tSMP_CB p_cb_;
178   // Set random to 0x5783D52156AD6F0E6388274EC6702EE0
179   Octet16 rand_{0x57, 0x83, 0xD5, 0x21, 0x56, 0xAD, 0x6F, 0x0E,
180                 0x63, 0x88, 0x27, 0x4E, 0xC6, 0x70, 0x2E, 0xE0};
181 
SetUp()182   void SetUp() override {
183     p_cb_.tk = {0};
184     // Set pairing request packet to 0x070710000001(01)
185     p_cb_.local_io_capability = 0x01;
186     p_cb_.loc_oob_flag = 0x00;
187     p_cb_.loc_auth_req = 0x00;
188     p_cb_.loc_enc_size = 0x10;
189     p_cb_.local_i_key = 0x07;
190     p_cb_.local_r_key = 0x07;
191     // Set pairing response packet to 0x050008000003(02)
192     p_cb_.peer_io_caps = 0x03;
193     p_cb_.peer_oob_flag = 0x00;
194     p_cb_.peer_auth_req = 0x00;
195     p_cb_.peer_enc_size = 0x08;
196     p_cb_.peer_i_key = 0x00;
197     p_cb_.peer_r_key = 0x05;
198     // Set role to central
199     p_cb_.role = HCI_ROLE_CENTRAL;
200     std::reverse(rand_.begin(), rand_.end());
201   }
TearDown()202   void TearDown() override {}
203 
204  public:
205 };
206 
207 // Test smp_gen_p2_4_confirm function implementation
TEST_F(SmpCalculateConfirmTest,test_smp_gen_p2_4_confirm_as_central)208 TEST_F(SmpCalculateConfirmTest, test_smp_gen_p2_4_confirm_as_central) {
209   // Set local_bda to 0xA1A2A3A4A5A6
210   test::mock::stack_acl::BTM_ReadConnectionAddr.body =
211       [](const RawAddress& remote_bda, RawAddress& local_conn_addr,
212          tBLE_ADDR_TYPE* p_addr_type, bool ota_address) {
213         local_conn_addr = RawAddress({0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6});
214         *p_addr_type = BLE_ADDR_RANDOM;
215       };
216 
217   // Set remote bda to 0xB1B2B3B4B5B6
218   test::mock::stack_acl::BTM_ReadRemoteConnectionAddr.body =
219       [](const RawAddress& pseudo_addr, RawAddress& conn_addr,
220          tBLE_ADDR_TYPE* p_addr_type, bool ota_address) {
221         conn_addr = RawAddress({0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6});
222         *p_addr_type = BLE_ADDR_PUBLIC;
223         return true;
224       };
225 
226   RawAddress remote_bda;
227   tBLE_ADDR_TYPE remote_bd_addr_type = BLE_ADDR_PUBLIC;
228   BTM_ReadRemoteConnectionAddr(p_cb_.pairing_bda, remote_bda,
229                                &remote_bd_addr_type, true);
230   BTM_ReadConnectionAddr(p_cb_.pairing_bda, p_cb_.local_bda, &p_cb_.addr_type,
231                          true);
232   Octet16 p2 = smp_gen_p2_4_confirm(&p_cb_, remote_bda);
233   // Correct p2 is 0x00000000a1a2a3a4a5a6b1b2b3b4b5b6
234   const char expected_p2_str[] = "00000000a1a2a3a4a5a6b1b2b3b4b5b6";
235   char p2_str[2 * OCTET16_LEN + 1];
236   dump_uint128_reverse(p2, p2_str);
237   ASSERT_THAT(p2_str, StrEq(expected_p2_str));
238 
239   test::mock::stack_acl::BTM_ReadConnectionAddr = {};
240   test::mock::stack_acl::BTM_ReadRemoteConnectionAddr = {};
241 }
242 
243 // Test smp_gen_p1_4_confirm and aes_128 function implementation
TEST_F(SmpCalculateConfirmTest,test_aes_128_as_central)244 TEST_F(SmpCalculateConfirmTest, test_aes_128_as_central) {
245   // Set local_bda to 0xA1A2A3A4A5A6
246   test::mock::stack_acl::BTM_ReadConnectionAddr.body =
247       [](const RawAddress& remote_bda, RawAddress& local_conn_addr,
248          tBLE_ADDR_TYPE* p_addr_type, bool ota_address) {
249         local_conn_addr = RawAddress({0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6});
250         *p_addr_type = BLE_ADDR_RANDOM;
251       };
252 
253   // Set remote bda to 0xB1B2B3B4B5B6
254   test::mock::stack_acl::BTM_ReadRemoteConnectionAddr.body =
255       [](const RawAddress& pseudo_addr, RawAddress& conn_addr,
256          tBLE_ADDR_TYPE* p_addr_type, bool ota_address) {
257         conn_addr = RawAddress({0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6});
258         *p_addr_type = BLE_ADDR_PUBLIC;
259         return true;
260       };
261 
262   RawAddress remote_bda;
263   tBLE_ADDR_TYPE remote_bd_addr_type = BLE_ADDR_PUBLIC;
264   BTM_ReadRemoteConnectionAddr(p_cb_.pairing_bda, remote_bda,
265                                &remote_bd_addr_type, true);
266   BTM_ReadConnectionAddr(p_cb_.pairing_bda, p_cb_.local_bda, &p_cb_.addr_type,
267                          true);
268   Octet16 p1 = smp_gen_p1_4_confirm(&p_cb_, remote_bd_addr_type);
269   // Correct p1 is 0x05000800000302070710000001010001
270   const char expected_p1_str[] = "05000800000302070710000001010001";
271   char p1_str[2 * OCTET16_LEN + 1];
272   dump_uint128_reverse(p1, p1_str);
273   ASSERT_THAT(p1_str, StrEq(expected_p1_str));
274   smp_xor_128(&p1, rand_);
275   // Correct p1 xor r is 0x5283dd2156ae6d096498274ec7712ee1
276   const char expected_p1_xor_r_str[] = "5283dd2156ae6d096498274ec7712ee1";
277   char p1_xor_r_str[2 * OCTET16_LEN + 1];
278   dump_uint128_reverse(p1, p1_xor_r_str);
279   ASSERT_THAT(p1_xor_r_str, StrEq(expected_p1_xor_r_str));
280   Octet16 output = crypto_toolbox::aes_128(p_cb_.tk, p1);
281   const char expected_p1_prime_str[] = "02c7aa2a9857ac866ff91232df0e3c95";
282   char p1_prime_str[2 * OCTET16_LEN + 1];
283   dump_uint128_reverse(output, p1_prime_str);
284   ASSERT_THAT(p1_prime_str, StrEq(expected_p1_prime_str));
285 
286   test::mock::stack_acl::BTM_ReadConnectionAddr = {};
287   test::mock::stack_acl::BTM_ReadRemoteConnectionAddr = {};
288 }
289 
290 // Test smp_calculate_comfirm function implementation
TEST_F(SmpCalculateConfirmTest,test_smp_calculate_comfirm_as_central)291 TEST_F(SmpCalculateConfirmTest, test_smp_calculate_comfirm_as_central) {
292   // Set local_bda to 0xA1A2A3A4A5A6
293   test::mock::stack_acl::BTM_ReadConnectionAddr.body =
294       [](const RawAddress& remote_bda, RawAddress& local_conn_addr,
295          tBLE_ADDR_TYPE* p_addr_type, bool ota_address) {
296         local_conn_addr = RawAddress({0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6});
297         *p_addr_type = BLE_ADDR_RANDOM;
298       };
299 
300   // Set remote bda to 0xB1B2B3B4B5B6
301   test::mock::stack_acl::BTM_ReadRemoteConnectionAddr.body =
302       [](const RawAddress& pseudo_addr, RawAddress& conn_addr,
303          tBLE_ADDR_TYPE* p_addr_type, bool ota_address) {
304         conn_addr = RawAddress({0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6});
305         *p_addr_type = BLE_ADDR_PUBLIC;
306         return true;
307       };
308 
309   Octet16 output;
310   tSMP_STATUS status = smp_calculate_comfirm(&p_cb_, rand_, &output);
311   EXPECT_EQ(status, SMP_SUCCESS);
312   // Correct MConfirm is 0x1e1e3fef878988ead2a74dc5bef13b86
313   const char expected_confirm_str[] = "1e1e3fef878988ead2a74dc5bef13b86";
314   char confirm_str[2 * OCTET16_LEN + 1];
315   dump_uint128_reverse(output, confirm_str);
316   ASSERT_THAT(confirm_str, StrEq(expected_confirm_str));
317 
318   test::mock::stack_acl::BTM_ReadConnectionAddr = {};
319   test::mock::stack_acl::BTM_ReadRemoteConnectionAddr = {};
320 }
321 
322 // Test ECC point validation
TEST(SmpEccValidationTest,test_valid_points)323 TEST(SmpEccValidationTest, test_valid_points) {
324   Point p;
325 
326   // Test data from Bluetooth Core Specification
327   // Version 5.0 | Vol 2, Part G | 7.1.2
328 
329   // Sample 1
330   p.x[7] = 0x20b003d2;
331   p.x[6] = 0xf297be2c;
332   p.x[5] = 0x5e2c83a7;
333   p.x[4] = 0xe9f9a5b9;
334   p.x[3] = 0xeff49111;
335   p.x[2] = 0xacf4fddb;
336   p.x[1] = 0xcc030148;
337   p.x[0] = 0x0e359de6;
338 
339   p.y[7] = 0xdc809c49;
340   p.y[6] = 0x652aeb6d;
341   p.y[5] = 0x63329abf;
342   p.y[4] = 0x5a52155c;
343   p.y[3] = 0x766345c2;
344   p.y[2] = 0x8fed3024;
345   p.y[1] = 0x741c8ed0;
346   p.y[0] = 0x1589d28b;
347 
348   EXPECT_TRUE(ECC_ValidatePoint(p));
349 
350   // Sample 2
351   p.x[7] = 0x2c31a47b;
352   p.x[6] = 0x5779809e;
353   p.x[5] = 0xf44cb5ea;
354   p.x[4] = 0xaf5c3e43;
355   p.x[3] = 0xd5f8faad;
356   p.x[2] = 0x4a8794cb;
357   p.x[1] = 0x987e9b03;
358   p.x[0] = 0x745c78dd;
359 
360   p.y[7] = 0x91951218;
361   p.y[6] = 0x3898dfbe;
362   p.y[5] = 0xcd52e240;
363   p.y[4] = 0x8e43871f;
364   p.y[3] = 0xd0211091;
365   p.y[2] = 0x17bd3ed4;
366   p.y[1] = 0xeaf84377;
367   p.y[0] = 0x43715d4f;
368 
369   EXPECT_TRUE(ECC_ValidatePoint(p));
370 }
371 
TEST(SmpEccValidationTest,test_invalid_points)372 TEST(SmpEccValidationTest, test_invalid_points) {
373   Point p;
374   multiprecision_init(p.x);
375   multiprecision_init(p.y);
376 
377   EXPECT_FALSE(ECC_ValidatePoint(p));
378 
379   // Sample 1
380   p.x[7] = 0x20b003d2;
381   p.x[6] = 0xf297be2c;
382   p.x[5] = 0x5e2c83a7;
383   p.x[4] = 0xe9f9a5b9;
384   p.x[3] = 0xeff49111;
385   p.x[2] = 0xacf4fddb;
386   p.x[1] = 0xcc030148;
387   p.x[0] = 0x0e359de6;
388 
389   EXPECT_FALSE(ECC_ValidatePoint(p));
390 
391   p.y[7] = 0xdc809c49;
392   p.y[6] = 0x652aeb6d;
393   p.y[5] = 0x63329abf;
394   p.y[4] = 0x5a52155c;
395   p.y[3] = 0x766345c2;
396   p.y[2] = 0x8fed3024;
397   p.y[1] = 0x741c8ed0;
398   p.y[0] = 0x1589d28b;
399 
400   p.y[0]--;
401 
402   EXPECT_FALSE(ECC_ValidatePoint(p));
403 }
404 
TEST(SmpStatusText,smp_status_text)405 TEST(SmpStatusText, smp_status_text) {
406   std::vector<std::pair<tSMP_STATUS, std::string>> status = {
407       std::make_pair(SMP_SUCCESS, "SMP_SUCCESS"),
408       std::make_pair(SMP_PASSKEY_ENTRY_FAIL, "SMP_PASSKEY_ENTRY_FAIL"),
409       std::make_pair(SMP_OOB_FAIL, "SMP_OOB_FAIL"),
410       std::make_pair(SMP_PAIR_AUTH_FAIL, "SMP_PAIR_AUTH_FAIL"),
411       std::make_pair(SMP_CONFIRM_VALUE_ERR, "SMP_CONFIRM_VALUE_ERR"),
412       std::make_pair(SMP_PAIR_NOT_SUPPORT, "SMP_PAIR_NOT_SUPPORT"),
413       std::make_pair(SMP_ENC_KEY_SIZE, "SMP_ENC_KEY_SIZE"),
414       std::make_pair(SMP_INVALID_CMD, "SMP_INVALID_CMD"),
415       std::make_pair(SMP_PAIR_FAIL_UNKNOWN, "SMP_PAIR_FAIL_UNKNOWN"),
416       std::make_pair(SMP_REPEATED_ATTEMPTS, "SMP_REPEATED_ATTEMPTS"),
417       std::make_pair(SMP_INVALID_PARAMETERS, "SMP_INVALID_PARAMETERS"),
418       std::make_pair(SMP_DHKEY_CHK_FAIL, "SMP_DHKEY_CHK_FAIL"),
419       std::make_pair(SMP_NUMERIC_COMPAR_FAIL, "SMP_NUMERIC_COMPAR_FAIL"),
420       std::make_pair(SMP_BR_PARING_IN_PROGR, "SMP_BR_PARING_IN_PROGR"),
421       std::make_pair(SMP_XTRANS_DERIVE_NOT_ALLOW,
422                      "SMP_XTRANS_DERIVE_NOT_ALLOW"),
423       std::make_pair(SMP_MAX_FAIL_RSN_PER_SPEC,
424                      "SMP_XTRANS_DERIVE_NOT_ALLOW"),  // NOTE: Dup
425       std::make_pair(SMP_PAIR_INTERNAL_ERR, "SMP_PAIR_INTERNAL_ERR"),
426       std::make_pair(SMP_UNKNOWN_IO_CAP, "SMP_UNKNOWN_IO_CAP"),
427       std::make_pair(SMP_BUSY, "SMP_BUSY"),
428       std::make_pair(SMP_ENC_FAIL, "SMP_ENC_FAIL"),
429       std::make_pair(SMP_STARTED, "SMP_STARTED"),
430       std::make_pair(SMP_RSP_TIMEOUT, "SMP_RSP_TIMEOUT"),
431       std::make_pair(SMP_FAIL, "SMP_FAIL"),
432       std::make_pair(SMP_CONN_TOUT, "SMP_CONN_TOUT"),
433   };
434   for (const auto& stat : status) {
435     ASSERT_STREQ(stat.second.c_str(), smp_status_text(stat.first).c_str());
436   }
437   auto unknown =
438       base::StringPrintf("UNKNOWN[%hhu]", std::numeric_limits<uint8_t>::max());
439   ASSERT_STREQ(unknown.c_str(),
440                smp_status_text(static_cast<tSMP_STATUS>(
441                                    std::numeric_limits<uint8_t>::max()))
442                    .c_str());
443 }
444