From fb3860dd05ee0fed03e6531dfe31872b2a98eb97 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 3 Aug 2021 12:05:15 +0200 Subject: [PATCH] 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 --- pkg/nimble/autoadv/README.md | 15 +++++++++++++++ pkg/nimble/autoadv/include/nimble_autoadv.h | 11 +++++++++++ pkg/nimble/autoadv/nimble_autoadv.c | 10 ++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pkg/nimble/autoadv/README.md b/pkg/nimble/autoadv/README.md index 2a15468094..a040125204 100644 --- a/pkg/nimble/autoadv/README.md +++ b/pkg/nimble/autoadv/README.md @@ -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. diff --git a/pkg/nimble/autoadv/include/nimble_autoadv.h b/pkg/nimble/autoadv/include/nimble_autoadv.h index 38f1d1f1f2..6aee64a5bd 100644 --- a/pkg/nimble/autoadv/include/nimble_autoadv.h +++ b/pkg/nimble/autoadv/include/nimble_autoadv.h @@ -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. */ diff --git a/pkg/nimble/autoadv/nimble_autoadv.c b/pkg/nimble/autoadv/nimble_autoadv.c index 5ece78d1c8..a2f0213665 100644 --- a/pkg/nimble/autoadv/nimble_autoadv.c +++ b/pkg/nimble/autoadv/nimble_autoadv.c @@ -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);