Advertiser#
Modules#
sl_bt_evt_advertiser_timeout
Indicates that the advertiser has completed the configured number of advertising events in the advertising set and advertising has stopped.
sl_bt_evt_advertiser_scan_request
Reports any scan request received in advertising mode if the scan request notification is enabled.
Enumerations#
enum advertiser_connectable_mode_t { advertiser_non_connectable = 0x0, advertiser_directed_connectable = 0x1, advertiser_connectable_scannable = 0x2, advertiser_scannable_non_connectable = 0x3, advertiser_connectable_non_scannable = 0x4 }\ Advertiser Connectable Mode.
enum advertiser_discoverable_mode_t { advertiser_non_discoverable = 0x0, advertiser_limited_discoverable = 0x1, advertiser_general_discoverable = 0x2, advertiser_broadcast = 0x3, advertiser_user_data = 0x4 }\ Advertiser Discoverable Mode.
enum advertiser_adv_address_type_t { advertiser_identity_address = 0x0, advertiser_non_resolvable = 0x1 }\ Advertising Address Type.
Functions#
sl_status_t sl_bt_advertiser_create_set (uint8_t *handle)
sl_status_t sl_bt_advertiser_set_timing (uint8_t handle, uint32_t interval_min, uint32_t interval_max, uint16_t duration, uint8_t maxevents)
sl_status_t sl_bt_advertiser_set_phy (uint8_t handle, uint8_t primary_phy, uint8_t secondary_phy)
sl_status_t sl_bt_advertiser_set_channel_map (uint8_t handle, uint8_t channel_map)
sl_status_t sl_bt_advertiser_set_tx_power (uint8_t handle, int16_t power, int16_t *set_power)
sl_status_t sl_bt_advertiser_set_report_scan_request (uint8_t handle, uint8_t report_scan_req)
sl_status_t sl_bt_advertiser_set_random_address (uint8_t handle, uint8_t addr_type, bd_addr address, bd_addr *address_out)
sl_status_t sl_bt_advertiser_clear_random_address (uint8_t handle)
sl_status_t sl_bt_advertiser_set_configuration (uint8_t handle, uint32_t configurations)
sl_status_t sl_bt_advertiser_clear_configuration (uint8_t handle, uint32_t configurations)
sl_status_t sl_bt_advertiser_set_data (uint8_t handle, uint8_t packet_type, size_t adv_data_len, const uint8_t *adv_data)
sl_status_t sl_bt_advertiser_set_long_data (uint8_t handle, uint8_t packet_type)
sl_status_t sl_bt_advertiser_start (uint8_t handle, uint8_t discover, uint8_t connect)
sl_status_t sl_bt_advertiser_stop (uint8_t handle)
sl_status_t sl_bt_advertiser_start_periodic_advertising (uint8_t handle, uint16_t interval_min, uint16_t interval_max, uint32_t flags)
sl_status_t sl_bt_advertiser_stop_periodic_advertising (uint8_t handle)
sl_status_t sl_bt_advertiser_delete_set (uint8_t handle)
Detailed Description#
Advertiser.
The commands and events in this class are related to advertising functionalities in GAP peripheral and broadcaster roles.
Enumeration Type Documentation#
advertiser_connectable_mode_t#
enum advertiser_connectable_mode_t
Advertiser Connectable Mode.
Enumerator | |
---|---|
advertiser_non_connectable | (0x0) Non-connectable non-scannable. |
advertiser_directed_connectable | (0x1) Directed connectable (RESERVED, DO NOT USE) |
advertiser_connectable_scannable | (0x2) Undirected connectable scannable. This mode can only be used in legacy advertising PDUs. |
advertiser_scannable_non_connectable | (0x3) Undirected scannable (Non-connectable but responds to scan requests) |
advertiser_connectable_non_scannable | (0x4) Undirected connectable non-scannable. This mode can only be used in extended advertising PDUs. |
advertiser_discoverable_mode_t#
enum advertiser_discoverable_mode_t
Advertiser Discoverable Mode.
Enumerator | |
---|---|
advertiser_non_discoverable | (0x0) Not discoverable |
advertiser_limited_discoverable | (0x1) Discoverable using both limited and general discovery procedures |
advertiser_general_discoverable | (0x2) Discoverable using general discovery procedure |
advertiser_broadcast | (0x3) Device is not discoverable in either limited or generic discovery procedure but may be discovered using the Observation procedure. |
advertiser_user_data | (0x4) Send advertising and/or scan response data defined by the user. The limited/general discoverable flags are defined by the user. |
advertiser_adv_address_type_t#
enum advertiser_adv_address_type_t
Advertising Address Type.
Enumerator | |
---|---|
advertiser_identity_address | (0x0) Use public or static device address, or an identity address if privacy mode is enabled. |
advertiser_non_resolvable | (0x1) Use non resolvable address type; advertising mode must also be non-connectable. |
Function Documentation#
sl_bt_advertiser_create_set()#
sl_status_t sl_bt_advertiser_create_set | (uint8_t * |
|
Create an advertising set. The handle of the created advertising set is returned in response.
Parameters | ||
---|---|---|
[out] |
| Advertising set handle |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_timing()#
sl_status_t sl_bt_advertiser_set_timing | ( | uint8_t |
|
uint32_t |
| ||
uint32_t |
| ||
uint16_t |
| ||
uint8_t |
| ||
) |
Set the advertising timing parameters of the given advertising set. This setting will take effect next time that advertising is enabled.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| Minimum advertising interval. Value in units of 0.625 ms
|
[in] |
| Maximum advertising interval. Value in units of 0.625 ms
|
[in] |
| Advertising duration for this advertising set. Value 0 indicates no advertising duration limit and advertising continues until it is disabled. A non-zero value sets the duration in units of 10 ms. The duration begins at the start of the first advertising event of this advertising set.
|
[in] |
|
|
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_phy()#
sl_status_t sl_bt_advertiser_set_phy | ( | uint8_t |
|
uint8_t |
| ||
uint8_t |
| ||
) |
Set advertising PHYs of the given advertising set. This setting will take effect next time that advertising is enabled. The invalid parameter error is returned if a PHY value is invalid or the device does not support a given PHY.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| Enum gap_phy_type_t. The PHY on which the advertising packets are transmitted on the primary advertising channel. If legacy advertising PDUs are used, 1M PHY must be used. Values:
|
[in] |
| Enum gap_phy_type_t. The PHY on which the advertising packets are transmitted on the secondary advertising channel. Values:
|
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_channel_map()#
sl_status_t sl_bt_advertiser_set_channel_map | ( | uint8_t |
|
uint8_t |
| ||
) |
Set the primary advertising channel map of the given advertising set. This setting will take effect next time that advertising is enabled.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| Advertising channel map which determines which of the three channels will be used for advertising. This value is given as a bitmask. Values:
|
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_tx_power()#
sl_status_t sl_bt_advertiser_set_tx_power | ( | uint8_t |
|
int16_t |
| ||
int16_t * |
| ||
) |
Limit the maximum advertising TX power on the given advertising set. If the value goes over the global value that was set using sl_bt_system_set_max_tx_power command, the global value will be the maximum limit. The maximum TX power of legacy advertising is further constrained to be less than +10 dBm. Extended advertising TX power can be +10 dBm and over if Adaptive Frequency Hopping is enabled.
This setting will take effect next time advertising is enabled.
By default, maximum advertising TX power is limited by the global value.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| TX power in 0.1 dBm steps. For example, the value of 10 is 1 dBm and 55 is 5.5 dBm. |
[out] |
| The selected maximum advertising TX power |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_report_scan_request()#
sl_status_t sl_bt_advertiser_set_report_scan_request | ( | uint8_t |
|
uint8_t |
| ||
) |
Enable or disable the scan request notification of a given advertising set. This setting will take effect next time that advertising is enabled.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| If non-zero, enables scan request notification and scan requests will be reported as events. Default value: 0 |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
Events#
sl_bt_evt_advertiser_scan_request - Triggered when a scan request is received during advertising if the scan request notification is enabled by this command.
sl_bt_advertiser_set_random_address()#
sl_status_t sl_bt_advertiser_set_random_address | ( | uint8_t |
|
uint8_t |
| ||
| |||
bd_addr * |
| ||
) |
Set the advertiser on an advertising set to use a random address. This overrides the default advertiser address which is either the public device address programmed at production or the address written into persistent storage using sl_bt_system_set_identity_address command. This setting is stored in RAM only and does not change the identity address in persistent storage.
When setting a resolvable random address, the address parameter is ignored. The stack generates a private resolvable random address and set it as the advertiser address. The generated address is returned in the response.
To use the default advertiser address, remove this setting using sl_bt_advertiser_clear_random_address command.
Wrong state error is returned if advertising has been enabled on the advertising set. Invalid parameter error is returned if the advertising set handle is invalid or the address does not conforms to the Bluetooth specification.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| Address type:
|
[in] |
| The random address to set. Ignore this field when setting a resolvable random address. |
[out] |
| The resolvable random address set for the advetiser. Ignore this field when setting other types of random address. |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_clear_random_address()#
sl_status_t sl_bt_advertiser_clear_random_address | ( | uint8_t |
| ) |
Clear the random address previously set for the advertiser address on an advertising set. A random address can be set using sl_bt_advertiser_set_random_address command. The default advertiser address will be used after this operation.
Wrong state error is returned if advertising has been enabled on the advertising set. Invalid parameter error is returned if the advertising set handle is invalid.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_configuration()#
sl_status_t sl_bt_advertiser_set_configuration | ( | uint8_t |
|
uint32_t |
| ||
) |
Enable advertising configuration flags on the given advertising set. The configuration change will take effect next time that advertising is enabled.
These configuration flags can be disabled using sl_bt_advertiser_clear_configuration.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| Advertising configuration flags to enable. This value can be a bitmask of multiple flags. Flags:
|
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_clear_configuration()#
sl_status_t sl_bt_advertiser_clear_configuration | ( | uint8_t |
|
uint32_t |
| ||
) |
Disable advertising configuration flags on the given advertising set. The configuration change will take effect next time that advertising is enabled.
These configuration flags can be enabled using sl_bt_advertiser_set_configuration.
Parameters
[in] |
| Advertising set handle |
[in] |
| Advertising configuration flags to disable. This value can be a bitmask of multiple flags. See sl_bt_advertiser_set_configuration for possible flags. |
ReturnsSL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_data()#
sl_status_t sl_bt_advertiser_set_data | ( | uint8_t |
|
uint8_t |
| ||
size_t |
| ||
const uint8_t * |
| ||
) |
Set user-defined data in advertising packets, scan response packets, or periodic advertising packets. Maximum 31 bytes of data can be set for legacy advertising. Maximum 191 bytes of data can be set for connectable extended advertising. Maximum 253 bytes of data can be set for periodic and non-connectable extended advertising. For setting longer advertising data, use command sl_bt_advertiser_set_long_data.
If advertising mode is currently enabled, the new advertising data will be used immediately. Advertising mode can be enabled using command sl_bt_advertiser_start. Periodic advertising mode can be enabled using command sl_bt_advertiser_start_periodic_advertising.
The invalid parameter error will be returned in the following situations:
Data length is more than 31 bytes but the advertiser can only advertise using legacy advertising PDUs.
Data is too long to fit into a single advertisement.
Set data of the advertising data packet when the advertiser is advertising in scannable mode using extended advertising PDUs.
Set data of the scan response data packet when the advertiser is advertising in connectable mode using extended advertising PDUs.
Note that the user-defined data may be overwritten by the system when the advertising is later enabled in a discoverable mode other than user_data.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| This value selects whether data is intended for advertising packets, scan response packets or periodic advertising packets.
|
[in] |
| Array length |
[in] |
| Data to be set |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_set_long_data()#
sl_status_t sl_bt_advertiser_set_long_data | ( | uint8_t |
|
uint8_t |
| ||
) |
Set advertising data for a specified packet type and advertising set. Data currently in the system data buffer will be extracted as the advertising data. The buffer will be emptied after this command regardless of the completion status.
Prior to calling this command, add data to the buffer with one or multiple calls of sl_bt_system_data_buffer_write.
Maximum 31 bytes of data can be set for legacy advertising. Maximum 191 bytes of data can be set for connectable extended advertising. Maximum 1650 bytes of data can be set for periodic and non-connectable extended advertising, but advertising parameters may limit the amount of data that can be sent in a single advertisement.
See sl_bt_advertiser_set_data for more details on advertising data.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| This value selects whether data is intended for advertising packets, scan response packets, or periodic advertising packets. Values:
|
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_start()#
sl_status_t sl_bt_advertiser_start | ( | uint8_t |
|
uint8_t |
| ||
uint8_t |
| ||
) |
Start advertising of a given advertising set with specified discoverable and connectable modes.
The number of concurrent advertising is limited by MAX_ADVERTISERS configuration.
The number of concurrent connectable advertising is also limited by MAX_CONNECTIONS configuration. For example, only one connectable advertising can be enabled if the device has (MAX_CONNECTIONS - 1) connections when this command is called. The limitation does not apply to non-connectable advertising.
The default advertising configuration in the stack is set to using legacy advertising PDUs on 1M PHY. The stack will automatically select extended advertising PDUs if either of the following has occurred with the default configuration:
The connectable mode is set to advertiser_connectable_non_scannable.
The primary advertising PHY is set to Coded PHY by sl_bt_advertiser_set_phy.
The user advertising data length is more than 31 bytes.
Periodic advertising is enabled.
If currently set parameters can't be used, an error is returned. Specifically, this command fails with the connection limit exceeded error if it causes the number of connections exceeding the configured MAX_CONNECTIONS value. It fails with the invalid parameter error if one of the following use cases occurs:
Non-resolvable random address is used but the connectable mode is advertiser_connectable_scannable or advertiser_connectable_non_scannable.
advertiser_connectable_non_scannable is the connectable mode but using legacy advertising PDUs has been explicitly enabled with command sl_bt_advertiser_set_configuration.
Coded PHY is the primary advertising PHY but using legacy advertising PDUs has been explicitly enabled with command sl_bt_advertiser_set_configuration.
advertiser_connectable_scannable is the connectable mode but using extended advertising PDUs has been explicitly enabled or the primary advertising PHY is set to Coded PHY.
If advertising is enabled in user_data mode, use sl_bt_advertiser_set_data to set advertising and scan response data before issuing this command. When advertising is enabled in modes other than user_data, advertising and scan response data is generated by the stack using the following procedure:
Add a flags field to advertising data.
Add a TX power level field to advertising data if the TX power service exists in the local GATT database.
Add a slave connection interval range field to advertising data if the GAP peripheral preferred connection parameters characteristic exists in the local GATT database.
Add a list of 16-bit service UUIDs to advertising data if there are one or more 16-bit service UUIDs to advertise. The list is complete if all advertised 16-bit UUIDs are in advertising data. Otherwise, the list is incomplete.
Add a list of 128-bit service UUIDs to advertising data if there are one or more 128-bit service UUIDs to advertise and there is still free space for this field. The list is complete if all advertised 128-bit UUIDs are in advertising data. Otherwise, the list is incomplete. Note that an advertising data packet can contain at most one 128-bit service UUID.
Try to add the full local name to advertising data if the device is not in privacy mode. If the full local name does not fit into the remaining free space, the advertised name is a shortened version by cutting off the end if the free space has at least 6 bytes. Otherwise, the local name is added to scan response data.
Event sl_bt_evt_connection_opened will be received when a remote device opens a connection to the advertiser on this advertising set and also advertising on the given set stops.
Event sl_bt_evt_advertiser_timeout will be received when the number of advertising events set by sl_bt_advertiser_set_timing command is done and advertising with the current set has stopped.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| Enum advertiser_discoverable_mode_t. Discoverable mode. Values:
|
[in] |
| Enum advertiser_connectable_mode_t. Connectable mode. Values:
|
Returns#
SL_STATUS_OK if successful. Error code otherwise. Events
sl_bt_evt_advertiser_timeout - Triggered when the number of advertising events set by sl_bt_advertiser_set_timing command is done and advertising has stopped on the given advertising set.
sl_bt_evt_connection_opened - Triggered when a remote device opens a connection to the advertiser on the specified advertising set and also advertising with the current set stops.
sl_bt_advertiser_stop()#
sl_status_t sl_bt_advertiser_stop | ( | uint8_t |
| ) |
Stop the advertising of the given advertising set. Counterpart with sl_bt_advertiser_start.
This command does not affect the enable state of the periodic advertising set, i.e., periodic advertising is not stopped.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_start_periodic_advertising()#
sl_status_t sl_bt_advertiser_start_periodic_advertising | ( | uint8_t |
|
uint16_t |
| ||
uint16_t |
| ||
uint32_t |
| ||
) |
Start periodic advertising on the given advertising set. The stack enables the advertising set automatically if the set was not enabled and the set can advertise using extended advertising PDUs beside the syncInfo (which is needed for the periodic advertising).
The invalid parameter error is returned if the application has configured legacy advertising PDUs or anonymous advertising, or the advertising set is enabled using legacy advertising PDUs.
To stop periodic advertising, use sl_bt_advertiser_stop_periodic_advertising command with the handle received in response from this command.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
[in] |
| Minimum periodic advertising interval. Value in units of 1.25 ms
|
[in] |
| Maximum periodic advertising interval. Value in units of 1.25 ms
|
[in] |
| Periodic advertising configurations. Bitmask of the following:
|
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_stop_periodic_advertising()#
sl_status_t sl_bt_advertiser_stop_periodic_advertising | ( | uint8_t |
| ) |
Stop the periodic advertising on the given advertising set. Counterpart with sl_bt_advertiser_start_periodic_advertising.
This command does not affect the enable state of the advertising set, i.e., legacy or extended advertising is not stopped.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
Returns#
SL_STATUS_OK if successful. Error code otherwise.
sl_bt_advertiser_delete_set()#
sl_status_t sl_bt_advertiser_delete_set | ( | uint8_t |
| ) |
Delete an advertising set.
Parameters | ||
---|---|---|
[in] |
| Advertising set handle |
Returns#
SL_STATUS_OK if successful. Error code otherwise.