Fragmented advertising in legacy mode (BLE 4.2)

Hello.

I have a requirement to encrypt the scan response from my device. This means I will have to split my data in 4 packets to fit within the 27 byte limit.

Is there any way of telling if an advertisement has been sent in legacy mode? I know there are callbacks for this when using extended advertising. I have this with legacy support but the callback is never triggered when advertising in legacy mode.

Please let me know if you need any more information on my setup.

Device: nRF 52840

nRF Connect SDK version 2.1.0 / Zephyr.

Parents
  • Hi,

    I know there are callbacks for this when using extended advertising.

    Have you tried using the "bt_le_ext_adv" API to set a legacy advertising set?

  • Hi Sigurd,

    Yes I have tried that.

    I added this to my proj.conf file:

    CONFIG_BT_EXT_ADV_LEGACY_SUPPORT=y
    CONFIG_BT_EXT_ADV=y

    Then I added the cb function and necessary things for bt:

    void on_scanned(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_scanned_info *info)
    {
        printk("on_scanned");
    }
    void on_sent(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_sent_info *info)
    {
        printk("on_sent");
    }

    struct bt_le_ext_adv_cb cb =
    {
       .sent = on_sent,
    .scanned = on_scanned
    };

    static struct bt_le_adv_param *connectable_adv_param =
        BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_CONNECTABLE,
                1600,
                2400,
                NULL);
    struct bt_le_ext_adv *adv;
    static struct bt_le_ext_adv_start_param extAdvStartParams
    {
        .timeout = 0,
        .num_events = 0,
    };
    static bt_data sr_data;
    static uint8_t srd[13] = { 0 };

    static const struct bt_data advertisement_data[] = {
        BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR))
    };

    Then i my main function:

    int res = bt_le_ext_adv_create(connectable_adv_param, &cb, &adv);
        if (res == 0)
        {
            printk("starting legacy advertisement");
            // Setup the scan response data
            sr_data.data = srd;
            sr_data.data_len = sizeof(srd);
            sr_data.type = BT_DATA_MANUFACTURER_DATA;

            bt_data sr[1] = {sr_data};
            int set_data_res = bt_le_ext_adv_set_data(adv, advertisement_data, ARRAY_SIZE(advertisement_data), sr, ARRAY_SIZE(sr));
            if (set_data_res == 0)
            {
                int start_res = bt_le_ext_adv_start(adv, &extAdvStartParams);
                printk("bt_le_ext_adv_start res: %d", start_res);
            }
        }

    I see the scan response data using the nRF sniffer plugin in Wireshark but on_sent and on_scanned are never invoked.

    Am I missing something obvious?

    Have a nice weekend!

  • Hi!

    1)

    To get the on_scanned callback, you need to add this flag:

    BT_LE_ADV_OPT_NOTIFY_SCAN_REQ
    snippet:
    	struct bt_le_adv_param param =
    		BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_NOTIFY_SCAN_REQ,
    				     BT_GAP_ADV_FAST_INT_MIN_2,
    				     BT_GAP_ADV_FAST_INT_MAX_2,
    				     NULL);

    2)

    You get the on_sent callback when either timeout occurs, or the number of advertising events specified have occurred. If both are set to 0, you don't get any callback. Advertising stops when either occurs.

    https://docs.zephyrproject.org/latest/connectivity/bluetooth/api/gap.html#c.bt_le_ext_adv_cb.sent

    https://docs.zephyrproject.org/latest/connectivity/bluetooth/api/gap.html#c.bt_le_ext_adv_start

    BR,

    Sigurd

  • Thank you Sigurd,

    adding the

    BT_LE_ADV_OPT_NOTIFY_SCAN_REQ

    flag solved the issue. Also setting .num_events > 0 in the

    bt_le_ext_adv_start_param

    struct causes .sent to be triggered.

Reply Children
No Data
Related