From 491309357f218e77057bfa45be8cefa0523a2b6e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 27 Mar 2019 21:23:47 +0100 Subject: [PATCH] mesh: start unprovisioned device beacon only when unprovisioned --- src/ble/mesh/beacon.c | 18 +++++++++++++++--- src/ble/mesh/beacon.h | 12 +++++++++++- test/mesh/mesh.c | 12 ++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/ble/mesh/beacon.c b/src/ble/mesh/beacon.c index 730175eca..21c48a9ea 100644 --- a/src/ble/mesh/beacon.c +++ b/src/ble/mesh/beacon.c @@ -113,11 +113,15 @@ static void beacon_timer_handler(btstack_timer_source_t * ts){ adv_bearer_request_can_send_now_for_mesh_beacon(); } -void beacon_init(const uint8_t * device_uuid, uint16_t oob_information){ - - beacon_oob_information = oob_information; +void beacon_init(void){ adv_bearer_register_for_mesh_beacon(&beacon_packet_handler); +} +/** + * Start Unprovisioned Device Beacon + */ +void beacon_unprovisioned_device_start(const uint8_t * device_uuid, uint16_t oob_information){ + beacon_oob_information = oob_information; if (device_uuid){ beacon_device_uuid = device_uuid; beacon_timer.process = &beacon_timer_handler; @@ -125,6 +129,14 @@ void beacon_init(const uint8_t * device_uuid, uint16_t oob_information){ } } +/** + * Stop Unprovisioned Device Beacon + */ +void beacon_unprovisioned_device_stop(void){ + btstack_run_loop_remove_timer(&beacon_timer); +} + + void beacon_register_for_unprovisioned_device_beacons(btstack_packet_handler_t packet_handler){ unprovisioned_device_beacon_handler = packet_handler; } diff --git a/src/ble/mesh/beacon.h b/src/ble/mesh/beacon.h index 82bf99443..4e5ac7e3d 100644 --- a/src/ble/mesh/beacon.h +++ b/src/ble/mesh/beacon.h @@ -50,7 +50,17 @@ extern "C" { /** * Initialize Mesh Beacon */ -void beacon_init(const uint8_t * device_uuid, uint16_t oob_information); +void beacon_init(void); + +/** + * Start Unprovisioned Device Beacon + */ +void beacon_unprovisioned_device_start(const uint8_t * device_uuid, uint16_t oob_information); + +/** + * Stop Unprovisioned Device Beacon + */ +void beacon_unprovisioned_device_stop(void); /** * Register Beacon handler for unprovisioned device beacons diff --git a/test/mesh/mesh.c b/test/mesh/mesh.c index 00674a05d..cd04ccef7 100644 --- a/test/mesh/mesh.c +++ b/test/mesh/mesh.c @@ -134,6 +134,7 @@ static void mesh_load_app_keys(void){ } void mesh_store_app_key(uint16_t appkey_index, uint8_t aid, const uint8_t * application_key){ + printf("Store AppKey: AppKey Index 0x%06x, AID %02x: ", appkey_index, aid); uint8_t data[2+1+16]; little_endian_store_16(data, 0, appkey_index); data[2] = aid; @@ -192,6 +193,9 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack printf("Provisioning data available: %u\n", prov_len ? 1 : 0); if (prov_len){ mesh_setup_from_provisioning_data(&provisioning_data); + } else { + printf("Starting Unprovisioned Device Beacon\n"); + beacon_unprovisioned_device_start(device_uuid, 0); } // load app keys mesh_load_app_keys(); @@ -329,7 +333,7 @@ static void load_pts_app_key(void){ const char * application_key_string = "3216D1509884B533248541792B877F98"; btstack_parse_hex(application_key_string, 16, application_key); mesh_application_key_set(0, 0x38, application_key); - printf("PTS Application Key: "); + printf("PTS Application Key (AID %02x): ", 0x38); printf_hexdump(application_key, 16); } @@ -486,6 +490,7 @@ static void show_usage(void){ printf("2 - Send Segmented Access Message - Unicast\n"); printf("3 - Send Segmented Access Message - Group D000\n"); printf("4 - Send Segmented Access Message - Virtual 9779\n"); + printf("7 - Load PTS App key\n"); printf("\n"); } @@ -518,6 +523,9 @@ static void stdin_process(char cmd){ case '4': send_pts_segmented_access_messsage_virtual(); break; + case '7': + load_pts_app_key(); + break; case '8': printf("Creating link to device uuid: "); printf_hexdump(pts_device_uuid, 16); @@ -706,7 +714,7 @@ int btstack_main(void) // mesh adv_bearer_init(); - beacon_init(device_uuid, 0); + beacon_init(); beacon_register_for_unprovisioned_device_beacons(&mesh_unprovisioned_beacon_handler); // Provisioning in device role