Direct Advertisements

8 views
Skip to first unread message

Sven Krauss

unread,
Apr 24, 2026, 10:21:56 AM (2 days ago) Apr 24
to btstack-dev
I'm experimenting with direct advertisements. For that i'm using the first entry of the le_device_db, extracting address and type and configuring the advertisements_params. It looks like this:

  uint16_t adv_int_min = 400;
  uint16_t adv_int_max = 800;
  uint8_t adv_type = 0;
  uint8_t adv_addr_type = BD_ADDR_TYPE_LE_PUBLIC;
  bd_addr_t adv_addr;
  memset(adv_addr, 0, 6);

  if (le_device_db_max_count() == 1){
    int addr_type;
    bd_addr_t addr;
    le_device_db_info(0, &addr_type, addr, NULL);
    if ((addr_type == BD_ADDR_TYPE_LE_PUBLIC) || ((addr_type == BD_ADDR_TYPE_LE_RANDOM))){
      memcpy(adv_addr, addr, sizeof(bd_addr_t));
      adv_addr_type = (uint8_t)addr_type;
      adv_type = 0x01; //ADV_TYPE_DIRECT_IND
      Logger_logData(Logger_E_Type_Info, adv_addr, sizeof(bd_addr_t), "Setup direct advertising \n");
    }
  }


  gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, adv_addr_type, adv_addr, 0x07, 0x00);
  gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
  gap_advertisements_enable(1);


Trying this results in a weared connection. 

0000145 I Setup direct advertising
 dc e5 5b 1c 2f 78
0000145 D Packet t:1 in:0
 0a 20 01 00
0000145 I hci.c.1740: Num LE Peripheral roles: 0 of 1
0000145 D Packet t:4 in:1
 0e 04 01 0a 20 00
0000145 D Packet t:1 in:0
 06 20 0f 90 01 20 03 01 00 00 78 2f 1c 5b e5 dc 07 00
0000145 D Packet t:4 in:1
 0e 04 01 06 20 00
0000145 D Packet t:1 in:0
 08 20 20 1f 02 01 06 09 08 46 41 42 30 30 30 30 30 11 07 02 00 12 ac 42 02 eb a1 ed 11 8b 96 70 07 06 65
0000145 D Packet t:4 in:1
 0e 04 01 08 20 00
0000145 D Packet t:1 in:0
 0a 20 01 01
0000145 D Packet t:4 in:1
 0e 04 01 0a 20 00
0000146 D Packet t:4 in:1
 3e 13 01 3c ff ff 01 00 78 2f 1c 5b e5 dc 00 00 00 00 00 00 00
0000146 I hci.c.3544: LE Connection_complete (status=60) type 0, DC:E5:5B:1C:2F:78
0000146 I hci.c.328: create_connection_for_addr DC:E5:5B:1C:2F:78, type 0
0000146 I hci.c.1734: state 4, role 1, le_con 1
0000146 I hci.c.1740: Num LE Peripheral roles: 1 of 1
0000146 I hci.c.3680: New connection: handle 65535, DC:E5:5B:1C:2F:78
0000146 I hci.c.8600: BTSTACK_EVENT_NR_CONNECTIONS_CHANGED 1
0000146 I LE Connection - Connection Interval: 0.00 ms
0000146 I LE Connection - Connection Latency: 0

What is wrong here?

Matthias Ringwald

unread,
Apr 25, 2026, 3:42:38 PM (21 hours ago) Apr 25
to btsta...@googlegroups.com
Hi Sven

Direct advertisements are a bit special. Please post HCI logs in the default format to make it easier to analyse in Wireshark.

After starting the advertising, you get a LE Connection Event with Status 60 = 0x3c. The Core spec tells us:

2.57 Advertising Timeout (0x3C)
The Advertising Timeout error code indicates that advertising for a fixed duration
completed or, for directed advertising, that advertising completed without a connection
being created.

Directed advertisements have a rather short timeout, I think it's 1.28 seconds. If it didn't result in a connection, you'll get this error.
So far so good. However, BTstack then seems to set up a connection, which is wrong.

Do you have ENABLE_LE_CENTRAL set? if yes, it should bail out, but it doesn't.
We'll look into this.

What's youruse-case for directed advertisement?

Cheers
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/ebaf4c16-054b-4276-a8f6-b18997f84d40n%40googlegroups.com.

Sven Krauss

unread,
Apr 25, 2026, 5:33:35 PM (19 hours ago) Apr 25
to btstack-dev
Hi Matthias,

maybe my understanding of the intended used of direct advertisements is wrong. I have a LE peripheral. If no device is bonded to the peripheral, casual (broadcast) advertising shall be performed. Once bonded, direct advertising to the bonded central shall be performed. Only the bonded central shall be able to connect to the peripheral. I'm not sure if this is the right approach. 

I've played around with claude and the conclusion was, that the advertising timeout event isn't handled correctly in event_handle_le_connection_complete(). I've tested the suggested fix from claude and got an timeout around every second which is consistent with your excerpt from the core spec. I picture in my head is clearer now. If the peripheral uses direct advertising, the adv packets will be sent frequently and the expected result is a connection. This is not what I want.

I've read about whitelisting. Is this the way to go? Roughly like this:
- read the addresses from le device db and put it to the white list with gap_whitelist_add()
- gap_advertisements_set_params() with ADV_IND and filter_policy=1 ?

Kind regards

Sven
Reply all
Reply to author
Forward
0 new messages