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 Reply Children
No Data
Related