Lines Matching full:beacon
10 #include "mesh/beacon.h"
70 /* Setting for scanner defining what beacon is expected next, SNB as default */
110 .descript = "Random interval to be set for Private Beacon" in test_args_parse()
336 } beacon; variable
357 beacon.flags = net_buf_simple_pull_u8(buf); in beacon_scan_cb()
359 beacon.iv_index = net_buf_simple_pull_be32(buf); in beacon_scan_cb()
365 memcpy(beacon.random, buf->data, 13); in beacon_scan_cb()
366 bt_addr_le_copy(&beacon.adv_addr, addr); in beacon_scan_cb()
370 beacon.flags = private_beacon_data[0]; in beacon_scan_cb()
371 beacon.iv_index = sys_get_be32(&private_beacon_data[1]); in beacon_scan_cb()
374 if (!beacon.process_cb || beacon.process_cb(net_id, beacon.user_ctx)) { in beacon_scan_cb()
383 beacon.process_cb = process_cb; in wait_for_beacon()
384 beacon.user_ctx = ctx; in wait_for_beacon()
386 /* Listen to beacons ONLY for one beacon interval. in wait_for_beacon()
387 * Tests start quite often the waiting for the next beacon after in wait_for_beacon()
390 * the beacon happen about the same time. That is possible unstable behavior in wait_for_beacon()
392 * waiting time (BEACON_INTERVAL + 1) to guarantee that beacon comes in wait_for_beacon()
397 /* Sleep a little to get to the next beacon interval. Otherwise, calling this function in wait_for_beacon()
398 * again will catch the old beacon. This happens due to a known bug in legacy advertiser, in wait_for_beacon()
447 FAIL("Unable to generate beacon key"); in beacon_create()
457 FAIL("Unable to destroy beacon key"); in beacon_create()
481 ASSERT_EQUAL(0x00, beacon.flags); in corrupted_beacon_test()
482 ASSERT_EQUAL(0x0000, beacon.iv_index); in corrupted_beacon_test()
485 /* Now the beacon payload is valid and it shall trigger IV Update on the node. It shall also in corrupted_beacon_test()
486 * increase the beacon interval. We delay the outgoing beacon for a couple of seconds to in corrupted_beacon_test()
487 * avoid near perfect syncing with the beacon interval cycle of the device we just received in corrupted_beacon_test()
488 * a beacon from. in corrupted_beacon_test()
493 /* The beacon interval shall be changed and the node shall skip transmission of the next in corrupted_beacon_test()
494 * beacon. in corrupted_beacon_test()
498 ASSERT_EQUAL(0x02, beacon.flags); in corrupted_beacon_test()
499 ASSERT_EQUAL(0x0001, beacon.iv_index); in corrupted_beacon_test()
521 /* Let the rx node send the first beacon. */ in test_tx_invalid()
524 /* Create a valid beacon with IV Update Flag set to 1 and new IV Index. */ in test_tx_invalid()
548 /* Only the last beacon shall change IV Update state. */ in test_rx_invalid()
573 /* Let the rx node send the first beacon. */ in test_tx_kr_old_key()
578 /* Send a beacon with Key Refresh flag set to 1, but secured with the old Net Key. The in test_tx_kr_old_key()
579 * beacon shall not change Key Refresh phase, but should still be processed. The beacon in test_tx_kr_old_key()
586 ASSERT_EQUAL(0x00, beacon.flags); in test_tx_kr_old_key()
587 ASSERT_EQUAL(0x0000, beacon.iv_index); in test_tx_kr_old_key()
594 ASSERT_EQUAL(0x02, beacon.flags); in test_tx_kr_old_key()
595 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_tx_kr_old_key()
597 /* Send beacon with Key Refresh flag set to 1, IV Update flag set to 1, but secured with in test_tx_kr_old_key()
598 * the new Net Key. The node shall set Key Refresh phase to 2. The beacon interval shall in test_tx_kr_old_key()
605 ASSERT_EQUAL(0x03, beacon.flags); in test_tx_kr_old_key()
606 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_tx_kr_old_key()
608 /* Send beacon with Key Refresh flag set to 1, IV Update flag set to 0, but secured with in test_tx_kr_old_key()
609 * the old Net Key. The beacon shall be rejected. The beacon interval shall not be changed. in test_tx_kr_old_key()
615 ASSERT_EQUAL(0x03, beacon.flags); in test_tx_kr_old_key()
616 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_tx_kr_old_key()
619 * beacon interval shall be increased. in test_tx_kr_old_key()
625 ASSERT_EQUAL(0x02, beacon.flags); in test_tx_kr_old_key()
626 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_tx_kr_old_key()
628 /* Send beacon with IV Update flag set to 0 and secured with the old Net Key. The beacon in test_tx_kr_old_key()
629 * shall be ignored. The beacon interval shall not be changed. in test_tx_kr_old_key()
635 ASSERT_EQUAL(0x02, beacon.flags); in test_tx_kr_old_key()
636 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_tx_kr_old_key()
638 /* Do the same, but secure beacon with the new Net Key. Now the node shall change IV Update in test_tx_kr_old_key()
639 * flag to 0. The beacon interval shall be increased. in test_tx_kr_old_key()
645 ASSERT_EQUAL(0x00, beacon.flags); in test_tx_kr_old_key()
646 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_tx_kr_old_key()
728 LOG_INF("Received beacon for Net Key Idx %d", (i + 1)); in beacon_confirm_all_subnets()
731 ASSERT_EQUAL(0x00, beacon.flags); in beacon_confirm_all_subnets()
732 ASSERT_EQUAL(0x0000, beacon.iv_index); in beacon_confirm_all_subnets()
762 /* Let the rx node send the first beacon. */ in test_tx_multiple_netkeys()
775 /* Send beacon with Key Refresh flag set to 1, but secured with the old Net Key. in test_tx_multiple_netkeys()
776 * The beacon shall be processed, but shall not change Key Refresh phase. in test_tx_multiple_netkeys()
784 ASSERT_EQUAL(0x00, beacon.flags); in test_tx_multiple_netkeys()
785 ASSERT_EQUAL(0x0000, beacon.iv_index); in test_tx_multiple_netkeys()
787 /* Wait for end of sending all beacons from the rx node before sending beacon back in test_tx_multiple_netkeys()
788 * to prevent beacon collision. in test_tx_multiple_netkeys()
792 /* Do the same, but secure beacon with the new Net Key. The node shall set Key in test_tx_multiple_netkeys()
801 ASSERT_EQUAL(0x01, beacon.flags); in test_tx_multiple_netkeys()
802 ASSERT_EQUAL(0x0000, beacon.iv_index); in test_tx_multiple_netkeys()
804 /* Wait for end of sending all beacons from the rx node before sending beacon back in test_tx_multiple_netkeys()
805 * to prevent beacon collision. in test_tx_multiple_netkeys()
809 /* Send beacon with Key Refresh flag set to 0, but secured with the old Net Key. in test_tx_multiple_netkeys()
810 * The beacon shall be rejected. The beacon interval shall not be changed. in test_tx_multiple_netkeys()
818 ASSERT_EQUAL(0x01, beacon.flags); in test_tx_multiple_netkeys()
819 ASSERT_EQUAL(0x0000, beacon.iv_index); in test_tx_multiple_netkeys()
821 /* Wait for end of sending all beacons from the rx node before sending beacon back in test_tx_multiple_netkeys()
822 * to prevent beacon collision. in test_tx_multiple_netkeys()
827 * to 0. The beacon interval shall be increased. in test_tx_multiple_netkeys()
835 ASSERT_EQUAL(0x00, beacon.flags); in test_tx_multiple_netkeys()
836 ASSERT_EQUAL(0x0000, beacon.iv_index); in test_tx_multiple_netkeys()
838 /* Wait for end of sending all beacons from the rx node before sending beacon back in test_tx_multiple_netkeys()
839 * to prevent beacon collision. in test_tx_multiple_netkeys()
844 /* Create a valid beacon secured with unknown Net Key. The node shall ignore the beacon and in test_tx_multiple_netkeys()
922 * Sending SNB(secure network beacon) faster to guarantee in secure_beacon_send()
923 * at least one beacon is received by tx node in 10s period. in secure_beacon_send()
955 /*wait provisioned tx node to send the first beacon*/ in test_rx_secure_beacon_interval()
989 * Sending beacon with 2sec interval. in test_rx_secure_beacon_interval()
1079 if (memcmp(beacon.adv_addr.a.val, last_beacon_adv_addr.a.val, BT_ADDR_SIZE) == 0) { in private_beacon_check()
1083 memcpy(&last_beacon_adv_addr.a.val, beacon.adv_addr.a.val, BT_ADDR_SIZE); in private_beacon_check()
1086 ret = memcmp(beacon.random, last_random, 13) == 0; in private_beacon_check()
1088 ret = memcmp(beacon.random, last_random, 13) != 0; in private_beacon_check()
1091 memcpy(&last_random, beacon.random, 13); in private_beacon_check()
1121 FAIL("Beacon set failed (err %d, status %u)", err, status); in tx_priv_setup()
1126 FAIL("Failed to enable Private Beacon (err=%d)", err); in tx_priv_setup()
1156 FAIL("Beacon set failed (err %d, status %u)", err, status); in test_tx_priv_adv()
1164 FAIL("Failed to enable Private Beacon (err=%d)", err); in test_tx_priv_adv()
1173 FAIL("Failed to enable Private Beacon (err=%d)", err); in test_tx_priv_adv()
1182 FAIL("Failed to enable Private Beacon (err=%d)", err); in test_tx_priv_adv()
1191 FAIL("Failed to enable Private Beacon (err=%d)", err); in test_tx_priv_adv()
1232 /* Beacon random should change here */ in test_rx_priv_adv()
1257 FAIL("Unable to generate beacon key"); in private_beacon_create()
1289 /* Let the rx node send the first beacon. */ in test_tx_priv_invalid()
1292 /* Create a valid beacon with IV Update Flag set to 1 and new IV Index. */ in test_tx_priv_invalid()
1318 FAIL("Beacon set failed (err %d, status %u)", err, status); in test_rx_priv_invalid()
1323 FAIL("Failed to enable Private Beacon (err=%d)", err); in test_rx_priv_invalid()
1333 /* Only the last beacon shall change IV Update state. */ in test_rx_priv_invalid()
1348 FAIL("Beacon set failed (err %d, status %u)", err, status); in toggle_priv_beacon()
1356 FAIL("Failed to enable Private Beacon (err=%d)", err); in toggle_priv_beacon()
1384 /* Wait for SNB being advertised and switch beacon type between Beacon Intervals */ in test_tx_priv_interleave()
1396 /* Switch beacon type between Beacon Intervals */ in test_tx_priv_interleave()
1433 FAIL("Unable to generate beacon key"); in test_rx_priv_interleave()
1451 ASSERT_EQUAL(0x02, beacon.flags); in test_rx_priv_interleave()
1452 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_rx_priv_interleave()
1454 memset(&beacon, 0, sizeof(beacon)); in test_rx_priv_interleave()
1458 ASSERT_EQUAL(0x02, beacon.flags); in test_rx_priv_interleave()
1459 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_rx_priv_interleave()
1463 ASSERT_EQUAL(0x03, beacon.flags); in test_rx_priv_interleave()
1464 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_rx_priv_interleave()
1472 ASSERT_EQUAL(0x03, beacon.flags); in test_rx_priv_interleave()
1473 ASSERT_EQUAL(0x0001, beacon.iv_index); in test_rx_priv_interleave()
1502 /* Wait for secondary private beacon to end test. */ in test_rx_priv_beacon_cache()
1504 "Didn't receive private beacon in time"); in test_rx_priv_beacon_cache()
1506 /* Verify that only one private beacon for IV_idx=1 was handled. */ in test_rx_priv_beacon_cache()
1522 /* Send two copies of the same private beacon. */ in test_tx_priv_beacon_cache()
1528 /* Send secondary private beacon to mark end of test. */ in test_tx_priv_beacon_cache()
1624 ASSERT_EQUAL(beacon.pp_hash, in pp_beacon_check()
1625 proxy_adv_hash_calc(&pp_net0, beacon.pp_random, test_ctx->node_id_addr, true)); in pp_beacon_check()
1627 if (memcmp(beacon.adv_addr.a.val, last_beacon_adv_addr.a.val, BT_ADDR_SIZE) == 0) { in pp_beacon_check()
1631 memcpy(&last_beacon_adv_addr.a.val, beacon.adv_addr.a.val, BT_ADDR_SIZE); in pp_beacon_check()
1639 struct priv_test_ctx *ctx = (struct priv_test_ctx *)beacon.user_ctx; in priv_scan_cb()
1646 bt_addr_le_copy(&beacon.adv_addr, addr); in priv_scan_cb()
1649 beacon.net_id = net_buf_simple_pull_le64(buf); in priv_scan_cb()
1651 beacon.pp_hash = net_buf_simple_pull_le64(buf); in priv_scan_cb()
1652 beacon.pp_random = net_buf_simple_pull_le64(buf); in priv_scan_cb()
1655 if (!beacon.process_cb || beacon.process_cb(NULL, beacon.user_ctx)) { in priv_scan_cb()
1676 struct proxy_adv_beacon *beac = (struct proxy_adv_beacon *)beacon.user_ctx; in proxy_adv_scan_all_cb()
1680 /* Not a related beacon type */ in proxy_adv_scan_all_cb()
1684 bt_addr_le_copy(&beacon.adv_addr, addr); in proxy_adv_scan_all_cb()
1694 if (!beacon.process_cb || beacon.process_cb(NULL, beacon.user_ctx)) { in proxy_adv_scan_all_cb()
1743 uint64_t last_pp_random = beacon.pp_random; in test_rx_priv_net_id()
1746 * ID beacon and verify that random field has changed in test_rx_priv_net_id()
1751 ASSERT_FALSE(beacon.pp_random == last_pp_random); in test_rx_priv_net_id()
1797 uint64_t last_pp_random = beacon.pp_random; in test_rx_priv_node_id()
1806 ASSERT_FALSE(beacon.pp_random == last_pp_random); in test_rx_priv_node_id()
1864 FAIL("Unexpected beacon type"); in proxy_adv_subnet_find()
1869 FAIL("Could not find matching subnet for incoming proxy adv beacon"); in proxy_adv_subnet_find()
2098 if (beacon.pp_hash == in test_rx_priv_multi_net_id()
2099 proxy_adv_hash_calc(net_ctx[i].net, beacon.pp_random, NULL, true)) { in test_rx_priv_multi_net_id()
2187 * beacon arrived successfully over the GATT connection. in test_rx_priv_gatt_proxy()
2207 TEST_CASE(tx, on_iv_update, "Beacon: send on IV update"),
2208 TEST_CASE(tx, on_key_refresh, "Beacon: send on key refresh"),
2209 TEST_CASE(tx, invalid, "Beacon: send invalid beacon"),
2210 TEST_CASE(tx, kr_old_key, "Beacon: send old Net Key"),
2211 TEST_CASE(tx, multiple_netkeys, "Beacon: multiple Net Keys"),
2212 TEST_CASE(tx, secure_beacon_interval, "Beacon: send secure beacons"),
2213 TEST_CASE(tx, beacon_cache, "Beacon: advertise duplicate SNBs"),
2214 TEST_CASE(tx, priv_on_iv_update, "Private Beacon: send on IV update"),
2215 TEST_CASE(tx, priv_on_key_refresh, "Private Beacon: send on Key Refresh"),
2216 TEST_CASE(tx, priv_adv, "Private Beacon: advertise Private Beacons"),
2217 TEST_CASE(tx, priv_invalid, "Private Beacon: advertise invalid beacons"),
2218 TEST_CASE(tx, priv_interleave, "Private Beacon: advertise interleaved with SNB"),
2219 TEST_CASE(tx, priv_beacon_cache, "Private Beacon: advertise duplicate Private Beacons"),
2229 TEST_CASE(rx, on_iv_update, "Beacon: receive with IV update flag"),
2230 TEST_CASE(rx, on_key_refresh, "Beacon: receive with key refresh flag"),
2231 TEST_CASE(rx, invalid, "Beacon: receive invalid beacon"),
2232 TEST_CASE(rx, kr_old_key, "Beacon: receive old Net Key"),
2233 TEST_CASE(rx, multiple_netkeys, "Beacon: multiple Net Keys"),
2234 TEST_CASE(rx, secure_beacon_interval, "Beacon: receive and send secure beacons"),
2235 TEST_CASE(rx, beacon_cache, "Beacon: receive duplicate SNBs"),
2236 TEST_CASE(rx, priv_adv, "Private Beacon: verify random regeneration"),
2237 TEST_CASE(rx, priv_invalid, "Private Beacon: receive invalid beacons"),
2238 TEST_CASE(rx, priv_interleave, "Private Beacon: interleaved with SNB"),
2239 TEST_CASE(rx, priv_beacon_cache, "Private Beacon: receive duplicate Private Beacons"),