1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 14:33:52 +01:00

pkg/nimble/autoadv: make AD flag optionnal

These fields can be omitted if all other FLAGS are 0 and the advertising
packets is not connectable, allowing for 3 extra bytes for advertisement
payload.

Co-authored-by: Roudy Dagher <roudy.dagher@inria.fr>
This commit is contained in:
Francisco Molina 2021-08-03 12:05:15 +02:00
parent b062ce8660
commit fb3860dd05
3 changed files with 34 additions and 2 deletions

View File

@ -26,3 +26,18 @@ To specify a device name add the following line to your Makefile:
```
CFLAGS += -DNIMBLE_AUTOADV_DEVICE_NAME='"Riot OS device"'
```
By the default, in the advertised packet, the module includes the advertising
**Flags** data type. According to Bluetooth Core Specification Supplement (see
[§1.3.1](https://www.bluetooth.com/specifications/specs/core-specification-supplement-9/))
> The Flags data type shall be included when any of the Flag bits are non-zero
and the advertising packet is connectable, otherwise the Flags data type may be
omitted.
If your application is not connectable (eg. a temperature sensor advertising
its current value), you might want omit this flag by clearing the
`NIMBLE_AUTOADV_FLAG_FIELD` when including this module:
```
CFLAGS += -DNIMBLE_AUTOADV_FLAG_FIELD=0
```
This will grant three extra bytes in the advertisement packet.

View File

@ -56,6 +56,17 @@ extern "C" {
#define NIMBLE_AUTOADV_START_MANUALLY 0
#endif
/**
* @brief Include the advetisement flag field. If this is not
* defined, it will be defined as 1, resulting in including the field.
* The Flags data type shall be included when any of the Flag bits
* are non-zero and the advertising packet is connectable, otherwise
* the Flags data type may be omitted.
*/
#ifndef NIMBLE_AUTOADV_FLAG_FIELD
#define NIMBLE_AUTOADV_FLAG_FIELD 1
#endif
/**
* @brief Initialize autoadv module.
*/

View File

@ -160,8 +160,14 @@ void nimble_autoadv_reset(void)
int rc = 0;
(void) rc;
rc = bluetil_ad_init_with_flags(&_ad, buf, sizeof(buf), BLUETIL_AD_FLAGS_DEFAULT);
assert(rc == BLUETIL_AD_OK);
if (IS_ACTIVE(NIMBLE_AUTOADV_FLAG_FIELD) && BLUETIL_AD_FLAGS_DEFAULT) {
rc = bluetil_ad_init_with_flags(&_ad, buf, sizeof(buf),
BLUETIL_AD_FLAGS_DEFAULT);
assert(rc == BLUETIL_AD_OK);
}
else {
bluetil_ad_init(&_ad, buf, 0, sizeof(buf));
}
if (NIMBLE_AUTOADV_DEVICE_NAME != NULL) {
rc = bluetil_ad_add_name(&_ad, NIMBLE_AUTOADV_DEVICE_NAME);