From ada0651fe8883f1e3d8ad21a41eb34fc48dad4fc Mon Sep 17 00:00:00 2001 From: Luca Niccoli Date: Thu, 6 Apr 2023 20:11:50 +0200 Subject: [PATCH] Expose advertisement flags in NimBLEAdvertisedDevice (#504) --- src/NimBLEAdvertisedDevice.cpp | 19 +++++++++++++++++++ src/NimBLEAdvertisedDevice.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/NimBLEAdvertisedDevice.cpp b/src/NimBLEAdvertisedDevice.cpp index b4fb0f4d..550d8d37 100644 --- a/src/NimBLEAdvertisedDevice.cpp +++ b/src/NimBLEAdvertisedDevice.cpp @@ -62,6 +62,25 @@ uint8_t NimBLEAdvertisedDevice::getAdvType() { } // getAdvType +/** + * @brief Get the advertisement flags. + * @return The advertisement flags, a bitmask of: + * BLE_HS_ADV_F_DISC_LTD (0x01) - limited discoverability + * BLE_HS_ADV_F_DISC_GEN (0x02) - general discoverability + * BLE_HS_ADV_F_BREDR_UNSUP - BR/EDR not supported + */ +uint8_t NimBLEAdvertisedDevice::getAdvFlags() { + size_t data_loc = 0; + + if(findAdvField(BLE_HS_ADV_TYPE_FLAGS, 0, &data_loc) > 0) { + ble_hs_adv_field *field = (ble_hs_adv_field *)&m_payload[data_loc]; + if(field->length == BLE_HS_ADV_FLAGS_LEN + 1) { + return *field->value; + } + } + return 0; +} // getAdvFlags + /** * @brief Get the appearance. * diff --git a/src/NimBLEAdvertisedDevice.h b/src/NimBLEAdvertisedDevice.h index c582a7bd..8b921d77 100644 --- a/src/NimBLEAdvertisedDevice.h +++ b/src/NimBLEAdvertisedDevice.h @@ -45,6 +45,7 @@ class NimBLEAdvertisedDevice { NimBLEAddress getAddress(); uint8_t getAdvType(); + uint8_t getAdvFlags(); uint16_t getAppearance(); uint16_t getAdvInterval(); uint16_t getMinInterval();