1. Peer to Peer Extended Profile
The Peer to Peer Extended example referenced on this Wiki page builds upon the foundational Peer to Peer example. For enhanced comprehension, it is advised to first review the following Wiki page: STM32WB0 Bluetooth® LE – Peer 2 Peer Applications
1.1. STM32WB0 Peer to Peer Server Extended application
The table below describes the structure of Peer to Peer service:
Bluetooth® LE Peer to Peer Service specification | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
1.2. STM32WB0 Peer to Peer Client Extended application
It acts as a Central device with the support of GATT Client Layer.
At startup, by pressing the B1 button, Peer To Peer (P2P) Client Extended application:
- Starts scanning to detect the P2P Server Extended application by filtering the Firmware ID of the STMicroelectronics Manufacturer advertising data
- Stops Scanning once P2P server Extended detected
- Connects to the P2P Server Extended to establish the connection.
- Discovers GATT Service & Characteristics of the P2P server Extended
- Enables all GATT server notification characteristics
Once connected, the P2P Client Extended application can:
- Write a message to toggle the Blue LED of the P2P Server Extended by pressing the B1 button.
- Receive notification from remote P2P Server Application to toggle the on board Blue LED.
1.3. On board buttons configuration
Buttons configuration for Bluetooth® Low Energy P2P Extended Application on STM32WB0 Serie Nucleo boards | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2. Requirements
2.1. Software and system requirements
For software and hardware requirements, refer to the STM32WB0 Build BLE Project wiki page.
2.2. Hardware requirements
NUCLEO-WB05KZ[1]/NUCLEO-WB07CC[2]/NUCLEO-WB09KE [3] are necessary to install the application.
Hardware platform illustration | ||
---|---|---|
NUCLEO-WB05KZ | NUCLEO-WB07CC | NUCLEO-WB09KE |
|
2.3. Collector applications compatible
The STM32CubeWB0 Peer To Peer Server Extended project is compatible with the following collectors:
The device running the collector needs to support advertising extended feature.
3. Applications description
Two applications are showing extended advertising features:
- BLE_p2pServer_Ext application
- Acts as a Bluetooth LE peripheral, advertises 4 adverting sets.
- BLE_p2pClient_Ext application
- Acts as a Bluetooth central, scans Bluetooth LE devices around and connects to the P2P server extended application.
3.1. Setup
Projects are available in the STM32CubeWB0[4] package. To run these applications, you need at least a couple of STM32WB0 Series Nucleo boards. Another STM32WB0 Series Nucleo board with the P2P Client application or a smartphone can be used to connect to advertising legacy set.
The full wireless stack is required to have Extended advertising feature available.
Flash applications BLE_p2pServer_Ext and BLE_p2pClient_Ext on your board couple.
3.2. BLE_p2pServer_Ext application
The application is based on BLE_p2pServer application. In this application, you can configure up to eight advertising sets.
Additional files adv_ext_app.c and adv_ext_app.h were added to support the new feature, and are composed of the below functions:
- ADV_EXT_Config() initializes advertising data, using predefined table that can be updated according to your needs.
- builds the data to advertise if no data provided, function ADV_EXT_Build_data()
- ADV_EXT_Start() performs the configuration of advertising sets in several steps, details are displayed in the console.
- reads number of set and memory parameters supported by BLE stack configuration using function hci_le_read_number_of_supported_advertising_sets()
- performs the configuration of each sets using function aci_gap_set_advertising_configuration()
- sets a random address if requested using function hci_le_set_advertising_set_random_address()
- transfers to the stack data to advertise, function ADV_EXT_Set_data()
- aci_gap_set_advertising_data() function is used except for scannable sets where aci_gap_set_scan_response_data() is used
- enables the advertising set with function aci_gap_set_advertising_enable()
3.2.1. Advertising set configuration
A structure of type Adv_Set_Param_t holds parameters to define an advertising set, the following parameters are available:
Type | Name | Description |
---|---|---|
uint8_t | enable | 0 to disable advertising set |
uint8_t | Advertising_Set_Parameters_t->Advertising_Handle | Handle to identify an advertising set |
uint16_t | Advertising_Set_Parameters_t>Duration | Duration for which that advertising set is enabled in 10ms unit, 0 is no duration |
uint8_t | Advertising_Set_Parameters_t->Max_Extended_Advertising_Events | Number of events max, 0 is no maximun.
if non-zero, indicates the maximum number of extended advertising events that shall be sent prior to disabling the extended advertising set even if the Duration[i] parameter has not expired. |
uint8_t* | data | Pointer to the data set in the payload, if null data is generated |
uint16_t | data_len | Number of data to use |
char | username[] | Complete local name |
uint8_t | sid | ID of the advertising set |
uint16_t | property | Mask to define set properties, connectable/scannable/legacy |
uint16_t | interval_min | Low limit of advertising interval |
uint16_t | interval_max | High limit of advertising interval |
int8_t | tx_power | Advertising TX power in dBm |
uint8_t | adv_channels | RF channel map selection |
uint8_t | address_type | Own address type |
uint8_t | peer_address_type | Address type of the peer device |
uint8_t* | p_peer_address | Address of the peer device |
3.3. BLE_p2pClient_Ext application
The application demonstrates scanning of advertising with extended API’s. The output is printed over ST-LINK UART @115200 bauds.
Nucleo buttons offer the following functions:
- SW1: to stop the scan and connect to a server if any detected.
- SW2: to toggle a filter on extended result only.
- SW3: to stop/start scanning, the blue LED reflects scanning status.
Scanning is started using aci_gap_set_scan_configuration() and aci_gap_start_procedure() functions.
Scanning is stopped using aci_gap_terminate_proc() function.
Scan events are received, analyzed, and printed on the console.
- HCI_LE_EXTENDED_ADVERTISING_REPORT_SUBEVT_CODE are received.
- payload is analyzed to print COMPLETE_LOCAL_NAME AD element.
- the Result is printed over the UART and presented in a tab format with the following information:
- BD address
- Advertising PDU Type (Legacy/Extended)
- RSSI
- Advertising event type (connectable, scannable, scan response)
- Data length
- SID
- Data flags (more data, or data truncated).
BLE_p2pClient_Ext console output sample |
---|
4. Feature specific configuration
An application must give some specific parameters to the stack to use extended advertising. These parameters are located in app_conf.h file.
- The define CFG_BLE_CONTROLLER_EXT_ADV_SCAN_ENABLED has to be set to 1.
- This parameter allows to define the capacity of the stack for this feature, transmitted into ble_init_cmd_packet stucture.
The max number of advertising set supported is 8, with a max data length of each advertising set of up to 1650.
Note: The maximum number of simultaneous connections that the device supports (CFG_BLE_NUM_RADIO_TASKS) must be at least equal to the number of advertising set supported (CFG_BLE_NUM_ADV_SETS).
5. Advertising auxiliary packets
The PDU payload of primary advertising channels can vary in length from 6 to 37 bytes (6 bytes for addresses, remaining 31 bytes for data).
In Extended Advertising, secondary advertising channels are used to reach up to 1650 bytes of payload.
The advertising packets on primary channels contain the information in which secondary advertising channel, and the offset to the start time the auxiliary data is transmitted.
Aux packet |
---|
5.1. Not connectable, not scannable
Primary and auxiliary segments: NOT SCANNABLE/NOT CONNECTABLE.
Segments timing implementation:
- Both primary/auxiliary segments belong to the same scheduled slot for all fragmentations policy (length depends on data size)
- Channel of AUX_ADV_IND (+request and response) are randomly selected when set is ACTIVATED
- Chained channels follow a hopping of 1 increment
Example of not scannable/not connectable set |
---|
5.2. Scannable
Primary and auxiliary segments: SCANNABLE.
The scannable undirected event type using the ADV_EXT_IND PDU allows any scanner to respond with a scan request to receive scan response data on the secondary advertising physical channel.
- Only Auxiliary segment could be scanned, and Data could only be contained in the scan response.
- A scanner may send a scan request using the AUX_SCAN_REQ PDU on the same secondary advertising channel index as the received AUX_ADV_IND
Example of scannable set |
---|
5.3. Connectable
Primary and auxiliary segments: CONNECTABLE.
The connectable directed advertising event type using ADV_EXT_IND allows an initiator to respond with a connect request on the secondary advertising physical channel to establish an ACL connection
- After every AUX_ADV_IND PDU related to this event, it sends the advertiser that should listen to AUX_CONNECT_REQ PDUs on the same secondary advertising channel index.
Example of connectable set |
---|
6. Advertising sets building
The creation of an advertising set is done thanks to two new added functions:
- ADV_EXT_Config(): initializes advertising data table (fill adv_set_param[] table to provide advertising data base)
and
- ADV_EXT_Start(): performs the configuration of advertising sets in several steps
- reads the number of supported advertising sets
- reads the advertising sets data length
- sets the extended advertising configuration
- sets the extended advertising random address
- provides default advertising data, if necessary, using ADV_EXT_Build_data()
- transmits advertising data to the stack using ADV_EXT_Set_data()
7. Commands sequence
Commands sequence | Function |
---|---|
ADV_EXT_Config()
|
8. ACI-HCI Messages
A detailed description of all stack messages is available in the wireless stack interface documentation [5]
8.1. Commands
Command | Comment | Use in application |
---|---|---|
aci_gap_set_advertising_configuration() | Set the extended advertising configuration for one advertising set | BLE_p2pServer_Ext |
aci_gap_set_advertising_data() | Set the data used in extended advertising PDUs that have a data field | BLE_p2pServer_Ext |
aci_gap_set_scan_response_data() | Provide scan response data used during extended advertising | BLE_p2pServer_Ext |
aci_gap_set_advertising_enable() | Enable or disable one or more extended advertising sets | BLE_p2pServer_Ext |
hci_le_read_maximum_data_length() | Read the maximum length of data supported by the Controller for use as advertisement data or scan response data in an extended advertising event | BLE_p2pServer_Ext |
hci_le_read_number_of_supported_advertising_sets() | Read the maximum number of advertising sets supported by the Controller at the same time during extended advertising | BLE_p2pServer_Ext |
hci_le_remove_advertising_set() | Remove an advertising set from the controller | Not used |
hci_le_clear_advertising_sets() | It is used to remove all existing advertising sets from the Controller. | Not used |
hci_le_set_extended_scan_parameters() | set the extended scan parameters to be used on the advertising physical channels | BLE_p2pClient_Ext |
hci_le_set_extended_scan_enable() | enable or disable extended scanning | BLE_p2pClient_Ext |
8.2. Events
Event | Comment | Use in applications |
---|---|---|
HCI_LE_EXTENDED_ADVERTISING_REPORT_SUBEVT_CODE | Indicate that a Bluetooth device has responded to an active scan or has broadcast advertisements that were received during a passive scan | BLE_p2pClient_Ext |
HCI_LE_ADVERTISING_SET_TERMINATED_SUBEVT_CODE | Indicate that the Controller has terminated advertising in the advertising sets specified by the Advertising_Handle parameter | Not used |
HCI_LE_SCAN_REQUEST_RECEIVED_SUBEVT_CODE | Indicate that a SCAN_REQ PDU or an AUX_SCAN_REQ PDU has been received by the advertiser | BLE_p2pClient_Ext |
HCI_LE_SCAN_TIMEOUT_SUBEVT_CODE | Indicates that scanning has ended because the duration has expired | Not used |
9. References