77#include "mocks/crypto.h"
88#include "mocks/scan.h"
99#include "mocks/scan_expects.h"
10+ #include "mocks/hci_core.h"
11+ #include "mocks/hci_core_expects.h"
12+ #include "mocks/net_buf.h"
13+ #include "mocks/net_buf_expects.h"
1014#include "testing_common_defs.h"
1115
1216#include <zephyr/bluetooth/hci.h>
@@ -24,6 +28,7 @@ static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixt
2428 memset (& bt_dev , 0x00 , sizeof (struct bt_dev ));
2529
2630 CRYPTO_FFF_FAKES_LIST (RESET_FAKE );
31+ HCI_CORE_FFF_FAKES_LIST (RESET_FAKE );
2732}
2833
2934ZTEST_RULE (fff_reset_rule , fff_reset_rule_before , NULL );
@@ -232,6 +237,7 @@ ZTEST(bt_id_set_adv_own_addr, test_observer_scanning_re_enabled_after_updating_a
232237
233238 Z_TEST_SKIP_IFDEF (CONFIG_BT_PRIVACY );
234239 Z_TEST_SKIP_IFDEF (CONFIG_BT_EXT_ADV );
240+ Z_TEST_SKIP_IFDEF (CONFIG_BT_SCAN_WITH_IDENTITY );
235241 Z_TEST_SKIP_IFNDEF (CONFIG_BT_OBSERVER );
236242
237243 options &= ~BT_LE_ADV_OPT_CONN ;
@@ -241,6 +247,102 @@ ZTEST(bt_id_set_adv_own_addr, test_observer_scanning_re_enabled_after_updating_a
241247 atomic_set_bit (bt_dev .flags , BT_DEV_SCANNING );
242248
243249 bt_id_set_adv_own_addr (& adv , options , true, & own_addr_type );
250+ zassert_true (own_addr_type == BT_HCI_OWN_ADDR_RANDOM ,
251+ "Address type reference was incorrectly set" );
244252
245253 expect_call_count_bt_le_scan_set_enable (2 , expected_args_history );
246254}
255+
256+ /*
257+ * Test setting the advertiser address while 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled
258+ * and scanning is ongoing. The scanner is using a random identity address.
259+ *
260+ * Constraints:
261+ * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set
262+ *
263+ * Expected behaviour:
264+ * - Scanning is not disabled.
265+ * - The advertiser doesn't attempt to change the identity addr with bt_id_set_adv_private_addr()
266+ * - The advertiser uses the same identity address as the scanner.
267+ */
268+ ZTEST (bt_id_set_adv_own_addr , test_set_adv_own_addr_while_scanning_with_identity_random )
269+ {
270+ uint32_t options = 0 ;
271+ struct bt_le_ext_adv adv = {0 };
272+ struct net_buf net_buff ;
273+ int err ;
274+ uint8_t scan_own_addr_type = BT_ADDR_LE_ANONYMOUS ;
275+ uint8_t adv_own_addr_type = BT_ADDR_LE_ANONYMOUS ;
276+
277+ Z_TEST_SKIP_IFDEF (CONFIG_BT_PRIVACY );
278+ Z_TEST_SKIP_IFDEF (CONFIG_BT_EXT_ADV );
279+ Z_TEST_SKIP_IFNDEF (CONFIG_BT_OBSERVER );
280+ Z_TEST_SKIP_IFNDEF (CONFIG_BT_SCAN_WITH_IDENTITY );
281+
282+ bt_hci_cmd_alloc_fake .return_val = & net_buff ;
283+ bt_hci_cmd_send_sync_fake .return_val = 0 ;
284+
285+ options &= ~BT_LE_ADV_OPT_CONN ;
286+ bt_addr_le_copy (& bt_dev .id_addr [BT_ID_DEFAULT ], BT_STATIC_RANDOM_LE_ADDR_1 );
287+
288+ err = bt_id_set_scan_own_addr (false, & scan_own_addr_type );
289+
290+ expect_single_call_bt_hci_cmd_alloc ();
291+ expect_single_call_bt_hci_cmd_send_sync (BT_HCI_OP_LE_SET_RANDOM_ADDRESS );
292+
293+ zassert_ok (err , "Unexpected error code '%d' was returned" , err );
294+ zassert_true (scan_own_addr_type == BT_HCI_OWN_ADDR_RANDOM ,
295+ "Address type reference was incorrectly set" );
296+
297+ atomic_set_bit (bt_dev .flags , BT_DEV_SCANNING );
298+
299+ bt_id_set_adv_own_addr (& adv , options , true, & adv_own_addr_type );
300+ zassert_true (adv_own_addr_type == BT_HCI_OWN_ADDR_RANDOM ,
301+ "Address type reference was incorrectly set" );
302+
303+ expect_call_count_bt_le_scan_set_enable (0 , NULL );
304+ }
305+
306+ /*
307+ * Test setting the advertiser address while 'CONFIG_BT_SCAN_WITH_IDENTITY' is enabled
308+ * and scanning is ongoing. The scanner is using a public identity address.
309+ *
310+ * Constraints:
311+ * - Options 'BT_LE_ADV_OPT_CONN' bit isn't set
312+ *
313+ * Expected behaviour:
314+ * - Scanning is not disabled.
315+ * - The advertiser doesn't attempt to change the identity addr with bt_id_set_adv_private_addr()
316+ * - The advertiser uses the same identity address as the scanner.
317+ */
318+ ZTEST (bt_id_set_adv_own_addr , test_set_adv_own_addr_while_scanning_with_identity_public )
319+ {
320+ uint32_t options = 0 ;
321+ struct bt_le_ext_adv adv = {0 };
322+ int err ;
323+ uint8_t scan_own_addr_type = BT_ADDR_LE_ANONYMOUS ;
324+ uint8_t adv_own_addr_type = BT_ADDR_LE_ANONYMOUS ;
325+
326+ Z_TEST_SKIP_IFDEF (CONFIG_BT_PRIVACY );
327+ Z_TEST_SKIP_IFDEF (CONFIG_BT_EXT_ADV );
328+ Z_TEST_SKIP_IFNDEF (CONFIG_BT_OBSERVER );
329+ Z_TEST_SKIP_IFNDEF (CONFIG_BT_SCAN_WITH_IDENTITY );
330+
331+ options &= ~BT_LE_ADV_OPT_CONN ;
332+
333+ bt_addr_le_copy (& bt_dev .id_addr [BT_ID_DEFAULT ], BT_LE_ADDR );
334+
335+ err = bt_id_set_scan_own_addr (false, & scan_own_addr_type );
336+
337+ zassert_ok (err , "Unexpected error code '%d' was returned" , err );
338+ zassert_true (scan_own_addr_type == BT_HCI_OWN_ADDR_PUBLIC ,
339+ "Address type reference was incorrectly set" );
340+
341+ atomic_set_bit (bt_dev .flags , BT_DEV_SCANNING );
342+
343+ bt_id_set_adv_own_addr (& adv , options , true, & adv_own_addr_type );
344+ zassert_true (adv_own_addr_type == BT_HCI_OWN_ADDR_PUBLIC ,
345+ "Address type reference was incorrectly set" );
346+
347+ expect_call_count_bt_le_scan_set_enable (0 , NULL );
348+ }
0 commit comments