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

Function to collate data from Advertisement and Scan Response packets?

If I understand correctly, a peripheral can distribute data such as UUID, device name, flags, appearance etc. between advertisement and scan response packets. To gather all the data provided by an advertising peripheral it is necessary to receive both packets and then extract and store this information.

Before I write my own function to do this, are there any existing functions (or examples) in the SDK to perform the task of collating data from advertisement and scan response packets?

  • Hi Chris,

    When scanning for devices using the S120 or S130, the SoftDevice provides an advertising report as a callback. I'm not 100% sure, but I believe scanning with automatically request a scan response from the device. If it provides one, then the scan response data will be provided as an additional advertising report event with its scan_rsp bit set to 1 indicating scan response data. You can check out this structure here: infocenter.nordicsemi.com/.../structble__gap__evt__adv__report__t.html

    I think you'll have to write your own structure to contain these bits of information but it could be something simple such as:

    struct advertising_data_s {
        uint8_t adv_data[32];
        uint8_t scn_data[32];
    }
    

    Then you can copy the data into the structure based on that scan_rsp parameter of the event and process it later.

    Hope this helps,

    Eric

  • The thing is that various possible items of data - UUID, flags, name etc. - can appear in either (or neither) structure, plus there may be advertisements and scan response reports coming in from various devices with different MAC addresses. It would be nice to have a function that automatically takes each report, detects and extracts whatever information is available, collates it with the MAC address of the source, and stores it. Then, at the end of a period of scanning, it would be easy to see what peripherals are present and the data provided by each.

  • AFAIK, there is only a function to encode advertising data in ble_advdata.c. The processing of reported data will have to be handled by your firmware. The advertising report does provide the MAC address though it could be a random private address so you'll need to check the address type for the MAC. The advertising packet has a very specific structure specified in the BT Core Specification but it is, annoyingly, spread across 3 different documents... I'd recommend looking at how the ble_advdata.c module encodes advertising data to get some sense of how to decode it. You also might check out the central examples to see how they process incoming advertising packets.

  • Yes, as EricS says, you could take a look at the central examples, there is a simple (adv_report_parse) parser used to determine what device to connect to or not. This is in on_ble_evt -> case BLE_GAP_EVT_ADV_REPORT.

    Note that you have to set the active bit when scanning to do active scanning (ask for scan response packet).

Related