|
7 | 7 | #include "mocks/crypto.h"
|
8 | 8 | #include "mocks/hci_core.h"
|
9 | 9 | #include "mocks/rpa.h"
|
| 10 | +#include "mocks/adv.h" |
| 11 | +#include "mocks/adv_expects.h" |
10 | 12 | #include "testing_common_defs.h"
|
11 | 13 |
|
12 | 14 | #include <zephyr/bluetooth/hci.h>
|
@@ -75,6 +77,81 @@ ZTEST(bt_id_set_scan_own_addr, test_set_nrpa_scan_address_no_privacy)
|
75 | 77 | "Address type reference was incorrectly set");
|
76 | 78 | }
|
77 | 79 |
|
| 80 | +/* |
| 81 | + * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. |
| 82 | + * Advertising is ongoing and uses a random device address. |
| 83 | + * |
| 84 | + * Constraints: |
| 85 | + * - bt_id_set_private_addr() succeeds and returns 0 |
| 86 | + * - 'CONFIG_BT_SCAN_WITH_IDENTITY' isn't enabled |
| 87 | + * - 'CONFIG_BT_PRIVACY' isn't enabled |
| 88 | + * |
| 89 | + * Expected behaviour: |
| 90 | + * - bt_id_set_scan_own_addr() returns 0 |
| 91 | + * - Address type reference is updated |
| 92 | + */ |
| 93 | +ZTEST(bt_id_set_scan_own_addr, test_set_nrpa_scan_address_no_privacy_adv_ongoing_random_identity) |
| 94 | +{ |
| 95 | + int err; |
| 96 | + struct bt_le_ext_adv *adv = &bt_dev.adv; |
| 97 | + uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; |
| 98 | + |
| 99 | + Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); |
| 100 | + Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); |
| 101 | + Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); |
| 102 | + |
| 103 | + bt_rand_fake.custom_fake = bt_rand_custom_fake; |
| 104 | + bt_le_adv_lookup_legacy_fake.return_val = adv; |
| 105 | + |
| 106 | + bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_STATIC_RANDOM_LE_ADDR_1); |
| 107 | + |
| 108 | + atomic_set_bit(adv->flags, BT_ADV_ENABLED); |
| 109 | + |
| 110 | + err = bt_id_set_scan_own_addr(false, &own_addr_type); |
| 111 | + |
| 112 | + zassert_ok(err, "Unexpected error code '%d' was returned", err); |
| 113 | + zassert_true(own_addr_type == BT_HCI_OWN_ADDR_RANDOM, |
| 114 | + "Address type reference was incorrectly set"); |
| 115 | +} |
| 116 | + |
| 117 | +/* |
| 118 | + * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled. |
| 119 | + * Advertising is ongoing and uses a public device address. |
| 120 | + * |
| 121 | + * Constraints: |
| 122 | + * - bt_id_set_private_addr() succeeds and returns 0 |
| 123 | + * - 'CONFIG_BT_SCAN_WITH_IDENTITY' isn't enabled |
| 124 | + * - 'CONFIG_BT_PRIVACY' isn't enabled |
| 125 | + * |
| 126 | + * Expected behaviour: |
| 127 | + * - bt_id_set_scan_own_addr() returns 0 |
| 128 | + * - Address type reference is updated |
| 129 | + */ |
| 130 | +ZTEST(bt_id_set_scan_own_addr, test_set_nrpa_scan_address_no_privacy_adv_ongoing_public_identity) |
| 131 | +{ |
| 132 | + int err; |
| 133 | + struct bt_le_ext_adv *adv = &bt_dev.adv; |
| 134 | + uint8_t own_addr_type = BT_ADDR_LE_ANONYMOUS; |
| 135 | + |
| 136 | + Z_TEST_SKIP_IFDEF(CONFIG_BT_PRIVACY); |
| 137 | + Z_TEST_SKIP_IFDEF(CONFIG_BT_SCAN_WITH_IDENTITY); |
| 138 | + Z_TEST_SKIP_IFNDEF(CONFIG_BT_BROADCASTER); |
| 139 | + |
| 140 | + bt_rand_fake.custom_fake = bt_rand_custom_fake; |
| 141 | + bt_le_adv_lookup_legacy_fake.return_val = adv; |
| 142 | + |
| 143 | + bt_addr_le_copy(&bt_dev.id_addr[BT_ID_DEFAULT], BT_LE_ADDR); |
| 144 | + |
| 145 | + atomic_set_bit(adv->flags, BT_ADV_ENABLED); |
| 146 | + atomic_set_bit(adv->flags, BT_ADV_USE_IDENTITY); |
| 147 | + |
| 148 | + err = bt_id_set_scan_own_addr(false, &own_addr_type); |
| 149 | + |
| 150 | + zassert_ok(err, "Unexpected error code '%d' was returned", err); |
| 151 | + zassert_true(own_addr_type == BT_HCI_OWN_ADDR_PUBLIC, |
| 152 | + "Address type reference was incorrectly set"); |
| 153 | +} |
| 154 | + |
78 | 155 | /*
|
79 | 156 | * Test setting scan own address while 'CONFIG_BT_PRIVACY' isn't enabled.
|
80 | 157 | * If 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled and the default identity has an RPA address of type
|
|
0 commit comments