@@ -38,6 +38,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
38
38
#define WAIT_TIME 120 /*seconds*/
39
39
#define IS_RPR_PRESENT (CONFIG_BT_MESH_RPR_SRV && CONFIG_BT_MESH_RPR_CLI)
40
40
#define IMPOSTER_MODEL_ID 0xe000
41
+ /* Rough estimate of the time it should take the provisionee to stop sending unprov beacons. */
42
+ #define PROV_DELTA_THRESH_MS 100
41
43
42
44
enum test_flags {
43
45
IS_PROVISIONER ,
@@ -97,17 +99,26 @@ static uint32_t link_close_timestamp;
97
99
98
100
/* Set prov_bearer to non-zero invalid value. */
99
101
static bt_mesh_prov_bearer_t prov_bearer = 0xF8 ;
102
+ static bt_mesh_prov_bearer_t prov_to_use ;
100
103
101
104
static void test_args_parse (int argc , char * argv [])
102
105
{
103
106
bs_args_struct_t args_struct [] = {
104
107
{
105
108
.dest = & prov_bearer ,
106
109
.type = 'i' ,
107
- .name = "{invalid, PB-ADV, PB-GATT}" ,
110
+ .name = "{invalid, PB-ADV, PB-GATT, (PB-ADV | PB-GATT) }" ,
108
111
.option = "prov-bearer" ,
109
112
.descript = "Provisioning bearer that is to be used."
110
113
},
114
+ {
115
+ .dest = & prov_to_use ,
116
+ .type = 'i' ,
117
+ .name = "{PB-ADV, PB-GATT}" ,
118
+ .option = "prov-to-use" ,
119
+ .descript = "Provisioning bearer that is to be used in the case that "
120
+ "multiple provisioning bearers are enabled in prov_bearer."
121
+ },
111
122
};
112
123
113
124
bs_args_parse_all_cmd_line (argc , argv , args_struct );
@@ -275,6 +286,42 @@ static void test_terminate(void)
275
286
}
276
287
}
277
288
289
+ static uint64_t prov_started_time_ms ;
290
+ static uint8_t prov_uuid [16 ];
291
+
292
+ static void provision (uint8_t uuid [16 ], bt_mesh_prov_bearer_t bearer )
293
+ {
294
+ int err ;
295
+
296
+ switch (bearer ) {
297
+ case BT_MESH_PROV_ADV :
298
+ err = bt_mesh_provision_adv (uuid , 0 , prov_addr , 0 );
299
+ break ;
300
+ case BT_MESH_PROV_GATT :
301
+ err = bt_mesh_provision_gatt (uuid , 0 , prov_addr , 0 );
302
+ break ;
303
+ default :
304
+ err = - ENOTSUP ;
305
+ }
306
+
307
+ if (!err ) {
308
+ LOG_INF ("Provisioning over %s started." ,
309
+ bearer == BT_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT" );
310
+ prov_started_time_ms = k_uptime_get ();
311
+ memcpy (prov_uuid , uuid , 16 );
312
+ }
313
+ }
314
+
315
+ static void provisionee_beacon_check (uint8_t uuid [16 ], bt_mesh_prov_bearer_t bearer )
316
+ {
317
+ if (memcmp (uuid , prov_uuid , 16 ) == 0 ) {
318
+ ASSERT_FALSE_MSG ((prov_started_time_ms &&
319
+ (k_uptime_delta (& prov_started_time_ms ) > PROV_DELTA_THRESH_MS )),
320
+ "Received %s beacon from provisionee after provisioning started." ,
321
+ bearer == BT_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT" );
322
+ }
323
+ }
324
+
278
325
static void unprovisioned_beacon (uint8_t uuid [16 ],
279
326
bt_mesh_prov_oob_info_t oob_info ,
280
327
uint32_t * uri_hash )
@@ -286,7 +333,12 @@ static void unprovisioned_beacon(uint8_t uuid[16],
286
333
if (uuid_to_provision && memcmp (uuid , uuid_to_provision , 16 )) {
287
334
return ;
288
335
}
289
- bt_mesh_provision_adv (uuid , 0 , prov_addr , 0 );
336
+
337
+ provisionee_beacon_check (uuid , BT_MESH_PROV_ADV );
338
+
339
+ if (!prov_to_use || prov_to_use == BT_MESH_PROV_ADV ) {
340
+ provision (uuid , BT_MESH_PROV_ADV );
341
+ }
290
342
}
291
343
292
344
static void unprovisioned_beacon_gatt (uint8_t uuid [16 ], bt_mesh_prov_oob_info_t oob_info )
@@ -299,7 +351,11 @@ static void unprovisioned_beacon_gatt(uint8_t uuid[16], bt_mesh_prov_oob_info_t
299
351
return ;
300
352
}
301
353
302
- bt_mesh_provision_gatt (uuid , 0 , prov_addr , 0 );
354
+ provisionee_beacon_check (uuid , BT_MESH_PROV_GATT );
355
+
356
+ if (!prov_to_use || prov_to_use == BT_MESH_PROV_GATT ) {
357
+ provision (uuid , BT_MESH_PROV_GATT );
358
+ }
303
359
}
304
360
305
361
static void prov_complete (uint16_t net_idx , uint16_t addr )
@@ -324,6 +380,8 @@ static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr,
324
380
{
325
381
LOG_INF ("Device 0x%04x provisioned" , prov_addr );
326
382
current_dev_addr = prov_addr ++ ;
383
+ prov_started_time_ms = 0 ;
384
+ memset (prov_uuid , 0 , 16 );
327
385
k_sem_give (& prov_sem );
328
386
}
329
387
@@ -340,6 +398,7 @@ static void prov_reset(void)
340
398
341
399
static bt_mesh_input_action_t gact ;
342
400
static uint8_t gsize ;
401
+ static bool oob_wait_unprov_int ;
343
402
static int input (bt_mesh_input_action_t act , uint8_t size )
344
403
{
345
404
/* The test system requests the input OOB data earlier than
@@ -350,7 +409,9 @@ static int input(bt_mesh_input_action_t act, uint8_t size)
350
409
gact = act ;
351
410
gsize = size ;
352
411
353
- k_work_reschedule (& oob_timer , K_SECONDS (1 ));
412
+ k_work_reschedule (& oob_timer , oob_wait_unprov_int
413
+ ? K_SECONDS (CONFIG_BT_MESH_UNPROV_BEACON_INT + 1 )
414
+ : K_SECONDS (1 ));
354
415
355
416
return 0 ;
356
417
}
@@ -734,6 +795,49 @@ static void test_provisioner_oob_auth_no_oob_public_key(void)
734
795
PASS ();
735
796
}
736
797
798
+ static void test_provisioner_pb_cancel (void )
799
+ {
800
+ k_sem_init (& prov_sem , 0 , 1 );
801
+
802
+ bt_mesh_device_setup (& prov , & comp );
803
+
804
+ ASSERT_OK (bt_mesh_cdb_create (test_net_key ));
805
+
806
+ ASSERT_OK (bt_mesh_provision (test_net_key , 0 , 0 , 0 , 0x0001 , dev_key ));
807
+
808
+ prov .static_val = 0 ;
809
+ prov .static_val_len = 0 ;
810
+ prov .output_size = 0 ;
811
+ prov .output_actions = 0 ;
812
+ prov .input_size = 8 ;
813
+ prov .input_actions = BT_MESH_ENTER_NUMBER ;
814
+
815
+ ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (20 )));
816
+
817
+ PASS ();
818
+ }
819
+
820
+ static void test_device_pb_cancel (void )
821
+ {
822
+ oob_wait_unprov_int = true;
823
+ k_sem_init (& prov_sem , 0 , 1 );
824
+
825
+ bt_mesh_device_setup (& prov , & comp );
826
+
827
+ prov .static_val = 0 ;
828
+ prov .static_val_len = 0 ;
829
+ prov .output_size = 0 ;
830
+ prov .output_actions = 0 ;
831
+ prov .input_size = 8 ;
832
+ prov .input_actions = BT_MESH_ENTER_NUMBER ;
833
+
834
+ ASSERT_OK (bt_mesh_prov_enable (prov_bearer ));
835
+
836
+ ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (20 )));
837
+
838
+ PASS ();
839
+ }
840
+
737
841
/** @brief Verify that the provisioner can provision multiple devices in a row
738
842
*/
739
843
static void test_provisioner_multi (void )
@@ -1798,6 +1902,7 @@ static const struct bst_test_instance test_connect[] = {
1798
1902
TEST_CASE_WBACKCHANNEL (device , oob_public_key ,
1799
1903
"Device: provisioning use oob public key" ),
1800
1904
TEST_CASE (device , reprovision , "Device: provisioning, reprovision" ),
1905
+ TEST_CASE_WBACKCHANNEL (device , pb_cancel , "Device: provisioning, cancel prov bearers." ),
1801
1906
#if IS_RPR_PRESENT
1802
1907
TEST_CASE (device , pb_remote_server_unproved ,
1803
1908
"Device: used for remote provisioning, starts unprovisioned" ),
@@ -1828,6 +1933,8 @@ static const struct bst_test_instance test_connect[] = {
1828
1933
TEST_CASE (
1829
1934
provisioner , reprovision ,
1830
1935
"Provisioner: provisioning, resetting and reprovisioning multiple times." ),
1936
+ TEST_CASE_WBACKCHANNEL (
1937
+ provisioner , pb_cancel , "Provisioner: provisioning, cancel prov bearers." ),
1831
1938
#if IS_RPR_PRESENT
1832
1939
TEST_CASE (provisioner , pb_remote_client_reprovision ,
1833
1940
"Provisioner: pb-remote provisioning, resetting and reprov-ing multiple times." ),
0 commit comments