This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Change Advertising mask

Hello,

I  want to change the channel mask of the advertising channels like this

m_advertising.adv_params.channel_mask[4] = 0xC0;  // only Channel 37

and sniff it.

I can compile and flash the code but on sniffer the advertiser still send on the three advertising channels. Is there another place where I have to change the mask?

Software: nRF5_SDK_15.0.0 with + S140

Hardware: nRF52840-DK

Code of the advertising init.

static void advertising_init(void)
{
    ret_code_t             err_code;
    ble_advertising_init_t init;

    memset(&init, 0, sizeof(init));

    ble_advdata_manuf_data_t                  manuf_data; //Variable to hold manufacturer specific data
    memset(&manuf_data, 0, sizeof(manuf_data));
    uint8_t data[]                            = "Test"; //Our data to advertise
    manuf_data.company_identifier             =  0x0059; //Nordics company ID
    manuf_data.data.p_data                    = data;
    manuf_data.data.size                      = sizeof(data);
    init.advdata.p_manuf_specific_data = &manuf_data;

    init.advdata.name_type               = BLE_ADVDATA_SHORT_NAME;
    init.advdata.short_name_len          = 6;
    init.advdata.include_appearance      = true;
    init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;

    init.evt_handler = on_adv_evt;

    m_advertising.adv_params.channel_mask[4] = 0xC0;  //Channel 37
    NRF_LOG_INFO("duration: %d", m_advertising.adv_params.duration);

    

    err_code = ble_advertising_init(&m_advertising, &init);
    if(err_code != 0)
      NRF_LOG_INFO("Errorcode advertising_init: %d", err_code);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

The m_advertising is an BLE_ADVERTISING_DEF(m_advertising); instance.

Thanks

  • Hi,

    SDK library manages adv_params on its own, resetting any values you set before. And there's no handling for channel map in ble_advertising.c. You have to set up advertising directly with softdevice API.

  • Hello,

    I see that you set channel_mask[4] = 0xC0;

    The channel mask is set up like this (each channel contains 8 bits) :

    channel_mask[0] = [ch 07, ch 06, ch 05, ch 04, ch 03, ch 02, ch 01, ch 00]
    channel_mask[1] = [ch 15, ch 14, ch 13, ch 12, ch 11, ch 10, ch 09, ch 08]
    channel_mask[2] = [ch 23, ch 22, ch 21, ch 20, ch 19, ch 18, ch 17, ch 16]
    channel_mask[3] = [ch 31, ch 30, ch 29, ch 28, ch 27, ch 26, ch 25, ch 24]
    channel_mask[4] = [ch 39, ch 38, ch 37, ch 36, ch 35, ch 34, ch 33, ch 32]

    So if you set channel_mask[4] = 0xC0 = 0b 1100 0000. As you say, this means that channel 39 and 38 is not used, while 37 and the rest of the channels are used.

    So far so good.

    The issue is that you set

    m_advertising.adv_params.channel_mask[4] = 0xC0;

    And later you call ble_advertising_start();

    If you peek into ble_advertising_start(), you will see that there is a line saying:

    memset(&p_advertising->adv_params, 0, sizeof(p_advertising->adv_params));

    This will erase all settings you have written to m_advertising->adv_params, including the channel_map.

    Try to either comment out that line, but then remember to call this before you set the channel map, e.g. in advertising_init, or you can set the channel map after the call to

    memset(&p_advertising->adv_params, 0, sizeof(p_advertising->adv_params));

    in the ble_advertising_start() function.

    I tested it now, and it seems to work.

    Please note that I only picked up one packet using the nrf sniffer, but it seems like it is looking for the next advertisement on channel 38. I then tried to program another DK with a central looking for this device, and it was able to connect to the peripheral.

    Best regards,

    Edvin

Related