Advertisement or Scan Response Constructor

While developing with Silicon Labs Bluetooth SDK, use the API gecko_cmd_le_gap_bt5_set_adv_data() to set the advertisement and scan response data. Data has a standard format, whereas the data passed to above API is raw data uint8array. This document focuses on adding a middle layer between user application and the Bluetooth stack API to set the advertisement payload, which makes the payload more straightforward, visible, and easier to understand.

Introduction#

Below is the architecture of the advertisement constructor, which is developed on the latest Bluetooth SDK - v2.12.4. It can also be used on other versions of SDK directly or with simple modifications, depending on the specific SDK version.

The app.c and app.h files are in the attachment. You can drag and drop them onto a "soc-empty" example and it should build and work if programming to a board. Two functions are introduced in the files:

  • int construct_adv(const adv_t adv, uint16_terr) --- This function checks the input adv_t structure data, converts it to raw data, and sets the Bluetooth stack.

  • void demo_setup_adv(void) --- This function demonstrates setting advertising data and scan response as shown below. See figure 1, 2, and 3:

    • Advertisement

      • Flags - 0x06

      • Complete local name - "AdvC"

      • More 128 uuids - Silicon Labs OTA Service UUID

    • Scan response

      • Manufacturer-specific data

        • Company ID - 0x02FF, Silicon Labs

        • Data - "KBA-Adv Constructor"

Figure 1. Advertisement DetailsFigure 1. Advertisement Details

Figure 2. Advertisement Payload BreakdownFigure 2. Advertisement Payload Breakdown

Figure 3. Scan Response Payload BreakdownFigure 3. Scan Response Payload Breakdown

Use and Import your Project#

Below steps assume that users need to import the project from scratch. If you already have a project, you will not need to create a new one for importing. You can copy the functions to your project.

  1. Create a "soc-empty" project based on the board you used in Simplicity Studio.

  2. Drag and drop the app.c and app.h in the attachment to overwrite the existing ones in the project.

  3. Build and flash to your board and use a Bluetooth Scanner. You should see the advertisement/scan response with structure mentioned above.

  4. To customize you own advertisement packet, you could take reference of the function "demo_setup_adv" to set up your own advertisement data.

Source#