diff options
author | Sven Gothel <[email protected]> | 2021-07-28 11:15:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-07-28 11:15:31 +0200 |
commit | 3c751f101a021bc74979f2f7817d6189c6670689 (patch) | |
tree | aae8d1305289f759930c54bf40c93dd2e345d845 | |
parent | b6a3dbb038f51c248cb8f5762482252fb0a36caa (diff) |
Add EIR GAPFlags definition and string presentation for EInfoReport
-rw-r--r-- | api/direct_bt/BTTypes0.hpp | 35 | ||||
-rw-r--r-- | api/direct_bt/MgmtTypes.hpp | 2 | ||||
-rw-r--r-- | src/direct_bt/BTTypes0.cpp | 49 |
3 files changed, 75 insertions, 11 deletions
diff --git a/api/direct_bt/BTTypes0.hpp b/api/direct_bt/BTTypes0.hpp index fe56c986..f5f3de4d 100644 --- a/api/direct_bt/BTTypes0.hpp +++ b/api/direct_bt/BTTypes0.hpp @@ -581,6 +581,27 @@ namespace direct_bt { // ************************************************* /** + * GAP Flags values, see Bluetooth Core Specification Supplement V9, Part A: 1.3, p 12 pp + */ + enum class GAPFlags : uint8_t { + NONE = 0, + LE_Ltd_Discoverable = (1 << 0), + LE_Gen_Discoverable = (1 << 1), + BREDR_UNSUPPORTED = (1 << 2), + DUAL_LE_BREDR_SameCtrl = (1 << 3), + DUAL_LE_BREDR_SameHost = (1 << 4), + RESERVED1 = (1 << 5), + RESERVED2 = (1 << 6), + RESERVED3 = (1 << 7) + }; + constexpr uint8_t number(const GAPFlags rhs) noexcept { return static_cast<uint8_t>(rhs); } + std::string to_string(const GAPFlags v) noexcept; + + // ************************************************* + // ************************************************* + // ************************************************* + + /** * Bit mask of 'Extended Inquiry Response' (EIR) data fields, * indicating a set of related data. */ @@ -647,7 +668,7 @@ namespace direct_bt { BDAddressType addressType = BDAddressType::BDADDR_UNDEFINED; EUI48 address; - uint8_t flags = 0; + GAPFlags flags = GAPFlags::NONE; std::string name; std::string name_short; int8_t rssi = 127; // The core spec defines 127 as the "not available" value @@ -664,7 +685,7 @@ namespace direct_bt { uint16_t did_version = 0; void set(EIRDataType bit) noexcept { eir_data_mask = eir_data_mask | bit; } - void setFlags(uint8_t f) noexcept { flags = f; set(EIRDataType::FLAGS); } + void setFlags(GAPFlags f) noexcept { flags = f; set(EIRDataType::FLAGS); } void setName(const uint8_t *buffer, int buffer_len) noexcept; void setShortName(const uint8_t *buffer, int buffer_len) noexcept; void setTxPower(int8_t v) noexcept { tx_power = v; set(EIRDataType::TX_POWER); } @@ -717,10 +738,10 @@ namespace direct_bt { * </pre> * </p> * <p> - * See Bluetooth Core Specification V5.2 [Vol. 3, Part C, 11, p 1392] - * and Bluetooth Core Specification Supplement V9, Part A: 1, p 9 + 2 Examples, p25.. - * and "Assigned Numbers - Generic Access Profile" - * <https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/> + * * See Bluetooth Core Specification V5.2 [Vol. 3, Part C, Section 8] + * * and Bluetooth Core Specification V5.2 [Vol. 3, Part C, Section 11] + * * and Bluetooth Core Specification Supplement V9, Part A: Section 1 + 2 Examples, p25.. + * * and [Assigned Numbers - Generic Access Profile](https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/) * </p> * <p> * https://www.bluetooth.com/specifications/archived-specifications/ @@ -734,7 +755,7 @@ namespace direct_bt { EIRDataType getEIRDataMask() const noexcept { return eir_data_mask; } AD_PDU_Type getEvtType() const noexcept { return evt_type; } - uint8_t getFlags() const noexcept { return flags; } + GAPFlags getFlags() const noexcept { return flags; } uint8_t getADAddressType() const noexcept { return ad_address_type; } BDAddressType getAddressType() const noexcept { return addressType; } EUI48 const & getAddress() const noexcept { return address; } diff --git a/api/direct_bt/MgmtTypes.hpp b/api/direct_bt/MgmtTypes.hpp index 0dd79ff6..7f31bfb2 100644 --- a/api/direct_bt/MgmtTypes.hpp +++ b/api/direct_bt/MgmtTypes.hpp @@ -1795,7 +1795,7 @@ namespace direct_bt { pdu.put_eui48_nc(MGMT_HEADER_SIZE, eireport->getAddress()); pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, direct_bt::number(eireport->getAddressType())); pdu.put_int8_nc(MGMT_HEADER_SIZE+6+1, eireport->getRSSI()); - pdu.put_uint32_nc(MGMT_HEADER_SIZE+6+1+1, eireport->getFlags()); // EIR flags only 8bit, Mgmt uses 32bit? + pdu.put_uint32_nc(MGMT_HEADER_SIZE+6+1+1, direct_bt::number(eireport->getFlags())); // EIR flags only 8bit, Mgmt uses 32bit? pdu.put_uint16_nc(MGMT_HEADER_SIZE+6+1+1+4, 0); // eir_len } diff --git a/src/direct_bt/BTTypes0.cpp b/src/direct_bt/BTTypes0.cpp index 1e7a2400..d68d65cc 100644 --- a/src/direct_bt/BTTypes0.cpp +++ b/src/direct_bt/BTTypes0.cpp @@ -541,6 +541,45 @@ std::string ManufactureSpecificData::toString() const noexcept { // ************************************************* // ************************************************* +#define GAPFLAGS_ENUM(X) \ + X(GAPFlags,NONE) \ + X(GAPFlags,LE_Ltd_Discoverable) \ + X(GAPFlags,LE_Gen_Discoverable) \ + X(GAPFlags,BREDR_UNSUPPORTED) \ + X(GAPFlags,DUAL_LE_BREDR_SameCtrl) \ + X(GAPFlags,DUAL_LE_BREDR_SameHost) \ + X(GAPFlags,RESERVED1) \ + X(GAPFlags,RESERVED2) \ + X(GAPFlags,RESERVED3) + +static std::string _getGAPFlagBitStr(const GAPFlags bit) noexcept { + switch(bit) { + GAPFLAGS_ENUM(CASE2_TO_STRING) + default: ; // fall through intended + } + return "Unknown GAP_Flags Bit "+jau::to_hexstring(number(bit)); +} + +std::string direct_bt::to_string(const GAPFlags v) noexcept { + const int v_i = static_cast<int>(v); + bool has_pre = false; + std::string out("["); + for(int i=0; i<8; i++) { + const int settingBit = ( 1 << i ); + if( 0 != ( v_i & settingBit ) ) { + if( has_pre ) { out.append(", "); } + out.append( _getGAPFlagBitStr( static_cast<GAPFlags>(settingBit) ) ); + has_pre = true; + } + } + out.append("]"); + return out; +} + +// ************************************************* +// ************************************************* +// ************************************************* + #define EIRDATATYPE_ENUM(X) \ X(EIRDataType,NONE) \ X(EIRDataType,EVT_TYPE) \ @@ -666,7 +705,9 @@ std::string EInfoReport::toString(const bool includeServices) const noexcept { std::string out("EInfoReport::"+to_string(source)+ "[address["+address.toString()+", "+to_string(getAddressType())+"/"+std::to_string(ad_address_type)+ "], name['"+name+"'/'"+name_short+"'], "+eirDataMaskToString()+ - ", evt-type "+to_string(evt_type)+", rssi "+std::to_string(rssi)+ + ", evt-type "+to_string(evt_type)+ + ", flags"+to_string(flags)+ + ", rssi "+std::to_string(rssi)+ ", tx-power "+std::to_string(tx_power)+ ", dev-class "+jau::to_hexstring(device_class)+ ", appearance "+jau::to_hexstring(static_cast<uint16_t>(appearance))+" ("+to_string(appearance)+ @@ -755,7 +796,7 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex switch ( static_cast<GAP_T>(elem_type) ) { case GAP_T::FLAGS: if( 1 <= elem_len ) { - setFlags(*const_uint8_to_const_int8_ptr(elem_data)); + setFlags(static_cast<GAPFlags>(*elem_data)); } break; case GAP_T::UUID16_INCOMPLETE: @@ -780,6 +821,8 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex } break; case GAP_T::NAME_LOCAL_SHORT: + // INFO: Bluetooth Core Specification V5.2 [Vol. 3, Part C, 8, p 1341] + // INFO: A remote name request is required to obtain the full name, if needed. setShortName(elem_data, elem_len); break; case GAP_T::NAME_LOCAL_COMPLETE: @@ -840,7 +883,7 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex break; default: // FIXME: Use a data blob!!!! - fprintf(stderr, "%s-Element @ [%d/%d]: Warning: Unhandled type 0x%.2X with %d bytes net\n", + WARN_PRINT("%s-Element @ [%d/%d]: Unhandled type 0x%.2X with %d bytes net\n", to_string(source).c_str(), offset, data_length, elem_type, elem_len); break; } |