From 18d0ae06005e216287d6cf0d97897cfdab97d29c Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 23 Apr 2020 23:34:03 +0200 Subject: [PATCH] mesh: send invite only in provisioner role if provisioning was started with provisioning_provisioner_start_provisioning --- src/mesh/provisioning_provisioner.c | 3 +++ test/mesh/mesh_pts.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mesh/provisioning_provisioner.c b/src/mesh/provisioning_provisioner.c index 9abc62223..76445a822 100644 --- a/src/mesh/provisioning_provisioner.c +++ b/src/mesh/provisioning_provisioner.c @@ -234,6 +234,7 @@ static void provisioning_send_data(uint16_t the_pb_adv_cid){ typedef enum { PROVISIONER_IDLE, + PROVISIONER_W4_LINK_OPENED, PROVISIONER_SEND_INVITE, PROVISIONER_W4_CAPABILITIES, PROVISIONER_W4_AUTH_CONFIGURATION, @@ -646,6 +647,7 @@ static void provisioning_handle_pdu(uint8_t packet_type, uint16_t channel, uint8 if (packet[0] != HCI_EVENT_MESH_META) break; switch (packet[2]){ case MESH_SUBEVENT_PB_TRANSPORT_LINK_OPEN: + if (provisioner_state != PROVISIONER_W4_LINK_OPENED) break; switch (mesh_subevent_pb_transport_link_open_get_status(packet)) { case ERROR_CODE_SUCCESS: printf("Link opened, sending Invite\n"); @@ -744,6 +746,7 @@ uint16_t provisioning_provisioner_start_provisioning(const uint8_t * device_uuid btstack_crypto_ecc_p256_generate_key(&prov_ecc_p256_request, prov_ec_q, &prov_key_generated, NULL); if (pb_adv_cid == MESH_PB_TRANSPORT_INVALID_CID) { + provisioner_state = PROVISIONER_W4_LINK_OPENED; pb_adv_cid = pb_adv_create_link(device_uuid); } return pb_adv_cid; diff --git a/test/mesh/mesh_pts.c b/test/mesh/mesh_pts.c index 4ee57e747..7f90190fe 100644 --- a/test/mesh/mesh_pts.c +++ b/test/mesh/mesh_pts.c @@ -324,7 +324,7 @@ static void mesh_unprovisioned_beacon_handler(uint8_t packet_type, uint16_t chan oob = big_endian_read_16(packet, 17); printf("received unprovisioned device beacon, oob data %x, device uuid: ", oob); printf_hexdump(device_uuid, 16); - pb_adv_create_link(device_uuid); + provisioning_provisioner_start_provisioning(device_uuid); } static int scan_hex_byte(const char * byte_string){