This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Directed Advertising not seen by the addressed device

Hi,

I am testing direct advertising with two nRF52-DK. One performs a direct advertising and the other scans for the directed adverts. Unfortunately, the scanning device cannot see the directed advertising packages.

For simplicty and to reduce variables, I have set a test where I use the below code on a nRF52 dk (nRF52832) and the BLE tool on the nRF Connect SDK for Desktop (using a nRF52840-donge). I have hardcoded the dongle address on the directed advertiser code. Unfortunately, I still cannot see the directed advertising packages. Why is that? Any help most welcome.

#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(11_directed_adv)

# NORDIC SDK APP START
target_sources(app PRIVATE
  src/main.c
)
# NORDIC SDK APP END

prj.conf file:

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
#CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_BOARD_ENABLE_DCDC=n

CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_DEVICE_NAME="directed_adv"
CONFIG_BT_PRIVACY=n
CONFIG_BT_EXT_ADV_MAX_ADV_SET=1

CONFIG_BT_GATT_CLIENT=y

CONFIG_BT_SETTINGS=y

CONFIG_HEAP_MEM_POOL_SIZE=1024

CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y


# RTT Log Enanble
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_RTT_CONSOLE=y
CONFIG_PRINTK=y

/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

/** @file
 *  @brief Nordic Battery Service Client sample
 */

#include <zephyr/types.h>

#include <errno.h>
#include <sys/printk.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/gatt.h>
//#include <bluetooth/gatt_dm.h>
#include <bluetooth/uuid.h>

#include <settings/settings.h>

#include <logging/log.h>


#define BT_GAP_ADV_INT_MIN        0x0020  /* 20 ms */
#define BT_GAP_ADV_INT_MAX        0x0020  /* 20 ms */

#define BT_ADV_5S_TIMEOUT         0x01F4  /* N=500 ;  Time = N * 10ms = 5s */
#define BT_ADV_30S_TIMEOUT        0x0BB8  /* N=3000 ; Time = N * 10ms = 30s */
#define BT_ADV_60S_TIMEOUT        0x1770  /* N=6000 ; Time = N * 10ms = 60s */


static uint8_t manu_data[7] = {   0xff, 0x3a,   /* Manufacturer */
                                  0x00, 0x00,   /* Major */
                                  0x00, 0x00,   /* Minor */
                                  0x00};        /* Nb of hops */

static const struct bt_data directed_b2b_ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_LIMITED | BT_LE_AD_NO_BREDR)),
        BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(0xFFFE)),
        BT_DATA(BT_DATA_MANUFACTURER_DATA, &manu_data, sizeof(manu_data)),
};

static bt_addr_le_t connecting_peer_addr;

static struct bt_le_adv_param directed_b2b_param =
                                      BT_LE_ADV_PARAM_INIT( BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_USE_NAME |
                                                            BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY,
                                      BT_GAP_ADV_FAST_INT_MIN_2, \
                                      BT_GAP_ADV_FAST_INT_MAX_2, &connecting_peer_addr);


static struct bt_le_ext_adv *directed_b2b_adv;

//==============================================================================
// advertising: directed
//==============================================================================

static void directed_b2b_adv_sent(struct bt_le_ext_adv *adv,
                     struct bt_le_ext_adv_sent_info *info)
{
  printk("Directed B2B adv timeout\n");
}

static void directed_b2b_adv_connected(struct bt_le_ext_adv *adv,
			  struct bt_le_ext_adv_connected_info *info)
{
  printk("Directed B2B Connected\n");
}

static struct bt_le_ext_adv_cb directed_b2b_adv_callbacks =
{
  .sent = directed_b2b_adv_sent,
  .connected = directed_b2b_adv_connected,
  .scanned = NULL
};
      
//==============================================================================
// bt_ready bluetooth init
//==============================================================================

static void bt_ready(int err)
{
  // TODO: Handle  init errors
  if (err) {
    printk("Bluetooth init failed (err %d)\n", err);
    return;
  }

  printk("Bluetooth initialized\n");

  if (IS_ENABLED(CONFIG_SETTINGS)) {
          settings_load();
  }

  // Directed B2B Advetising Create
  err = bt_le_ext_adv_create(&directed_b2b_param, &directed_b2b_adv_callbacks, &directed_b2b_adv);
  if (err)
  {
    printk("Failed to create directed advertiser set (%d)", err);
    return;
  }

  // set extended directed B2B advertising data
  err = bt_le_ext_adv_set_data(directed_b2b_adv, directed_b2b_ad, ARRAY_SIZE(directed_b2b_ad), NULL, 0);
  if (err)
  {
    printk("Failed to set directed advertising data (%d)", err);
    return;
  }
  
  struct bt_le_ext_adv_start_param directed_b2b_adv_start_param = {
                                    .timeout = BT_ADV_30S_TIMEOUT, 
                                    .num_events = 0};
   
  connecting_peer_addr.type = 0x01;
  connecting_peer_addr.a.val[0] = 0xf0;
  connecting_peer_addr.a.val[1] = 0x0f;
  connecting_peer_addr.a.val[2] = 0x34;
  connecting_peer_addr.a.val[3] = 0x56;
  connecting_peer_addr.a.val[4] = 0x45;
  connecting_peer_addr.a.val[5] = 0xc7;

  directed_b2b_param.peer = &connecting_peer_addr;
  err = bt_le_ext_adv_update_param(directed_b2b_adv, &directed_b2b_param);
  if (err)
  {
    printk("Failed to update directed advertising data (%d)", err);
    return;
  }
  
  err = bt_le_ext_adv_start(directed_b2b_adv, &directed_b2b_adv_start_param);
  if (err)
  {
    printk("Failed to start Directed advertising(%d)\n", err);
    return;
  }
  
  char addr[BT_ADDR_LE_STR_LEN];
  bt_addr_le_to_str(directed_b2b_param.peer, addr, sizeof(addr));
  printk("Directed B2B Advertising Started addr: %s\n", addr);

}

//==============================================================================
// main
//==============================================================================

void main(void)
{
  int err;

  printk("11-directed_adv init\n");

  err = bt_enable(bt_ready);
  if (err) {
          printk("Bluetooth init failed (err %d)\n", err);
          return;
  }
}

Direct Advertiser logs

*** Booting Zephyr OS build v2.7.0-ncs1  ***
11-directed_adv init
[00:00:01.327,239] <inf> fs_nvs: 6 Sectors of 4096 bytes
[00:00:01.327,270] <inf> fs_nvs: alloc wra: 0, f70
[00:00:01.327,270] <inf> fs_nvs: data wra: 0, 118
[00:00:01.327,392] <inf> sdc_hci_driver: SoftDevice Controller build revision: 
                                         df c0 4e d6 1f 7c 66 09  0a f5 2b a0 98 f2 43 64 |..N..|f. ..+...Cd
                                         62 c5 a6 2a                                      |b..*             
[00:00:01.330,413] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:01.330,413] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
[00:00:01.330,413] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 223.20160 Build 1719410646
[00:00:01.330,718] <inf> bt_hci_core: No ID address. App must call settings_load()
Bluetooth initialized
[00:00:01.330,902] <err> settings: set-value failure. key: bt/keys/e394a91ee9ef1 error(-2)
[00:00:01.331,634] <inf> bt_hci_core: Identity: F2:A4:36:CA:06:73 (random)
[00:00:01.331,634] <inf> bt_hci_core: HCI: version 5.2 (0x0b) revision 0x12b0, manufacturer 0x0059
[00:00:01.331,634] <inf> bt_hci_core: LMP: version 5.2 (0x0b) subver 0x12b0
Directed B2B Advertising Started addr: C7:45:56:34:0F:F0 (random)

BLE Tool

Parents
  • Hi Armand

    I don't think the Bluetooth application in nRF Connect for Desktop will show anything if a directed advertising packet is received. These packet doesn't really contain any data to show, just the peer address. 
    The same goes for extended advertise packets, I will need to check with the developers if this is supported. 
    I will get this confirmed during office hours tomorrow. 

    Have you tried to set up the other board to run a scanner example instead? 
    This should work, as long as you use comparable settings. 

    Best regards
    Torbjørn

Reply
  • Hi Armand

    I don't think the Bluetooth application in nRF Connect for Desktop will show anything if a directed advertising packet is received. These packet doesn't really contain any data to show, just the peer address. 
    The same goes for extended advertise packets, I will need to check with the developers if this is supported. 
    I will get this confirmed during office hours tomorrow. 

    Have you tried to set up the other board to run a scanner example instead? 
    This should work, as long as you use comparable settings. 

    Best regards
    Torbjørn

Children
  • Hi Armand

    The software developers confirmed that the nRF Connect for Desktop Bluetooth application doesn't support directed advertising or extended advertising, so you can't really use this tool to test your application. 

    The nRF Sniffer should be able to show the directed advertising packets though, if you are able to set that up?

    Otherwise you would need to configure your second board as a scanner, as I mentioned in my previous reply. 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    As stated I did initally test with two nRF52 dev kits (nRF52832). I am going to share here my code for the scanner and the logs on both devices. I cannot get to see any directed advertisement package on the scanner side. Could you run on your side both codes on nRF52dk? Thanks

    #
    # Copyright (c) 2021 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(12_directed_adv_scanner)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE
      src/main.c
    )
    # NORDIC SDK APP END
    

    1768.prj.conf

    /*
     * Copyright (c) 2019 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    /** @file
     *  @brief Nordic Battery Service Client sample
     */
    
    #include <zephyr/types.h>
    #include <stddef.h>
    #include <inttypes.h>
    #include <errno.h>
    #include <zephyr.h>
    #include <sys/printk.h>
    
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/hci.h>
    #include <bluetooth/conn.h>
    #include <bluetooth/uuid.h>
    #include <bluetooth/gatt.h>
    #include <bluetooth/gatt_dm.h>
    #include <bluetooth/scan.h>
    #include <bluetooth/services/bas_client.h>
    #include <dk_buttons_and_leds.h>
    
    #include <settings/settings.h>
    
    #include <logging/log.h>
    
    /**
     * Button to read the battery value
     */
    
    static void scan_filter_match(struct bt_scan_device_info *device_info,
    			      struct bt_scan_filter_match *filter_match,
    			      bool connectable)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
    
    	printk("Filters matched. Address: %s connectable: %s\n",
    		addr, connectable ? "yes" : "no");
    }
    
    
    static void scan_filter_no_match(struct bt_scan_device_info *device_info,
    				 bool connectable)
    {
    	//int err;
    	char addr[BT_ADDR_LE_STR_LEN];
    
            printk("No Match. Adv Type: 0x%02X Props: 0x%04X\n", device_info->recv_info->adv_type, device_info->recv_info->adv_props);
    
    	if (device_info->recv_info->adv_type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND) {
    		bt_addr_le_to_str(device_info->recv_info->addr, addr,
    				  sizeof(addr));
    		printk("Direct advertising received from %s\n", addr);
    		//bt_scan_stop();
    
    	}
    }
    
    BT_SCAN_CB_INIT(scan_cb, scan_filter_match, scan_filter_no_match,
    		NULL, NULL);
    
    static void scan_init(void)
    {
    	int err;
    
    	struct bt_scan_init_param scan_init = {
    		.connect_if_match = 0,
    		.scan_param = NULL,
    		.conn_param = BT_LE_CONN_PARAM_DEFAULT
    	};
    
    	bt_scan_init(&scan_init);
    	bt_scan_cb_register(&scan_cb);
    }
    
    static void bt_ready(int err)
    {
      char addr_s[BT_ADDR_LE_STR_LEN];
      bt_addr_le_t addr = {0};
      size_t count = 1;
    
      if (IS_ENABLED(CONFIG_SETTINGS)) {
              settings_load();
      }
      bt_id_get(&addr, &count);
      bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s));
    
    
      printk("Starting 12 - Directed Advertising Scanner\n");
      printk("Addr: %s\n", addr_s);
    
      printk("Bluetooth initialized\n");
    
      scan_init();
    
      err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
      if (err) {
              printk("Scanning failed to start (err %d)\n", err);
              return;
      }
    
      printk("Scanning successfully started\n");
    }
    
    void main(void)
    {
      int err;
    
      err = bt_enable(bt_ready);
      if (err) {
              printk("Bluetooth init failed (err %d)\n", err);
              return;
      }
    }
    
    

    LOGS

    Direct advertiser

    *** Booting Zephyr OS build v2.7.0-ncs1  ***
    11-directed_adv init
    [00:00:01.915,771] <inf> fs_nvs: 6 Sectors of 4096 bytes
    [00:00:01.915,802] <inf> fs_nvs: alloc wra: 2, fb0
    [00:00:01.915,802] <inf> fs_nvs: data wra: 2, 448
    [00:00:01.915,924] <inf> sdc_hci_driver: SoftDevice Controller build revision: 
                                             df c0 4e d6 1f 7c 66 09  0a f5 2b a0 98 f2 43 64 |..N..|f. ..+...Cd
                                             62 c5 a6 2a                                      |b..*             
    [00:00:01.918,914] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:01.918,914] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:01.918,945] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 223.20160 Build 1719410646
    [00:00:01.919,219] <inf> bt_hci_core: No ID address. App must call settings_load()
    Bluetooth initialized
    [00:00:01.919,952] <inf> bt_hci_core: Identity: F2:A4:36:CA:06:73 (random)
    [00:00:01.919,952] <inf> bt_hci_core: HCI: version 5.2 (0x0b) revision 0x12b0, manufacturer 0x0059
    [00:00:01.919,952] <inf> bt_hci_core: LMP: version 5.2 (0x0b) subver 0x12b0
    Directed B2B Advertising Started addr: C1:F9:D7:24:F3:A6 (random)
    Directed B2B adv timeout

    Scanner logs:

    *** Booting Zephyr OS build v2.7.0-ncs1  ***
    [00:00:02.586,242] <inf> fs_nvs: 6 Sectors of 4096 bytes
    [00:00:02.586,242] <inf> fs_nvs: alloc wra: 3, e78
    [00:00:02.586,242] <inf> fs_nvs: data wra: 3, 20c
    [00:00:02.586,395] <inf> sdc_hci_driver: SoftDevice Controller build revision: 
                                             df c0 4e d6 1f 7c 66 09  0a f5 2b a0 98 f2 43 64 |..N..|f. ..+...Cd
                                             62 c5 a6 2a                                      |b..*             
    [00:00:02.589,202] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:02.589,202] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:02.589,202] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 223.20160 Build 1719410646
    [00:00:02.589,477] <inf> bt_hci_core: No ID address. App must call settings_load()
    [00:00:02.589,660] <err> settings: set-value failure. key: bt/name error(-2)
    [00:00:02.589,904] <err> settings: set-value failure. key: bt/mesh/s/2/bind error(-2)
    [00:00:02.590,179] <err> settings: set-value failure. key: bt/mesh/AppKey/0 error(-2)
    [00:00:02.590,423] <err> settings: set-value failure. key: bt/mesh/RPL/1 error(-2)
    [00:00:02.590,698] <err> settings: set-value failure. key: bt/mesh/Seq error(-2)
    [00:00:02.591,064] <err> settings: set-value failure. key: bt/mesh/IV error(-2)
    [00:00:02.591,491] <err> settings: set-value failure. key: bt/mesh/NetKey/0 error(-2)
    [00:00:02.591,918] <err> settings: set-value failure. key: bt/mesh/Net error(-2)
    [00:00:02.592,742] <inf> bt_hci_core: Identity: <log_strdup alloc failed>
    [00:00:02.592,773] <inf> bt_hci_core: HCI: version 5.2 (0x0b) revision 0x12b0, manufacturer 0x0059
    [00:00:02.592,773] <inf> bt_hci_core: LMP: version 5.2 (0x0b) subver 0x12b0
    Starting 12 - Directed Advertising Scanner
    Addr: C1:F9:D7:24:F3:A6 (random)
    Bluetooth initialized
    Scanning successfully started
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x00 Props: 0x0003
    No Match. Adv Type: 0x04 Props: 0x000A
    No Match. Adv Type: 0x00 Props: 0x0003
    

  • Hi Torbjørn, Any chance to test this? Thanks

  • Hi Armand

    My apologies, I had back to back meetings today and didn't get time. I will do my best to test this tomorrow and get back to you. 

    Best regards
    Torbjørn

Related