aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-11-15 06:58:24 +0100
committerSven Gothel <[email protected]>2020-11-15 06:58:24 +0100
commitae9e96dddcf65c4f0547cc5b2ba66306bd2a1412 (patch)
tree154ecad2fb8fd65c3c36679879695b0a903dd751
parent54710af217b8480fd990e21b598a3970f5610464 (diff)
SMPAuthReqs: Ease string representation.. (for viewer)
-rw-r--r--api/direct_bt/SMPTypes.hpp10
-rw-r--r--src/direct_bt/SMPTypes.cpp70
2 files changed, 52 insertions, 28 deletions
diff --git a/api/direct_bt/SMPTypes.hpp b/api/direct_bt/SMPTypes.hpp
index 73987ae7..d5116d70 100644
--- a/api/direct_bt/SMPTypes.hpp
+++ b/api/direct_bt/SMPTypes.hpp
@@ -126,11 +126,11 @@ namespace direct_bt {
*/
FEATURE_EXCHANGE_COMPLETED = 4,
- /** Phase 2: Authentication (MITM) PASSKEY expected, see PairingMode::PASSKEY_ENTRY */
+ /** Phase 2: Authentication (MITM) PASSKEY expected now, see PairingMode::PASSKEY_ENTRY */
PASSKEY_EXPECTED = 5,
- /** Phase 2: Authentication (MITM) Numeric Comparison Reply expected, see PairingMode::NUMERIC_COMPARISON */
+ /** Phase 2: Authentication (MITM) Numeric Comparison Reply expected now, see PairingMode::NUMERIC_COMPARISON */
NUMERIC_COMPARISON_EXPECTED = 6,
- /** Phase 2: Authentication (MITM) OOB data expected, see PairingMode::OUT_OF_BAND */
+ /** Phase 2: Authentication (MITM) OOB data expected now, see PairingMode::OUT_OF_BAND */
OOB_EXPECTED = 7,
/** Phase 2: Pairing process started by SMPPairConfirmMsg or SMPPairPubKeyMsg (LE Secure Connection) exchange between initiating (master) and responding (slave) device. */
@@ -200,7 +200,7 @@ namespace direct_bt {
*/
BONDING = 0b00000001,
/** Reserved for future use */
- BONDING_RESERVED = 0b00000010,
+ BONDING_RFU = 0b00000010,
/**
* A device sets the MITM flag to one to request an Authenticated security property
* for the STK when using LE legacy pairing
@@ -226,7 +226,7 @@ namespace direct_bt {
* then LE Secure Connections pairing shall be used,
* otherwise LE Legacy pairing shall be used.
*/
- LE_SECURE_CONNECTIONS = 0b00001000,
+ SECURE_CONNECTIONS = 0b00001000,
/**
* The keypress field is used only in the Passkey Entry
* protocol and shall be ignored in other protocols.
diff --git a/src/direct_bt/SMPTypes.cpp b/src/direct_bt/SMPTypes.cpp
index 9eb49ccb..b8cf453e 100644
--- a/src/direct_bt/SMPTypes.cpp
+++ b/src/direct_bt/SMPTypes.cpp
@@ -85,38 +85,62 @@ std::string direct_bt::getSMPOOBDataFlagString(const SMPOOBDataFlag v) noexcept
}
-#define AUTHREQ_ENUM(X) \
- X(NONE) \
- X(BONDING) \
- X(BONDING_RESERVED) \
- X(MITM) \
- X(LE_SECURE_CONNECTIONS) \
- X(KEYPRESS) \
- X(CT2_H7_FUNC_SUPPORT) \
- X(RFU_1) \
- X(RFU_2)
-
-#define CASE_TO_STRING_AUTHREQ(V) case SMPAuthReqs::V: return #V;
-
std::string direct_bt::getSMPAuthReqBitString(const SMPAuthReqs bit) noexcept {
switch(bit) {
- AUTHREQ_ENUM(CASE_TO_STRING_AUTHREQ)
+ case SMPAuthReqs::NONE: return "none";
+ case SMPAuthReqs::BONDING: return "Bonding";
+ case SMPAuthReqs::BONDING_RFU: return "Bonding_RFU";
+ case SMPAuthReqs::MITM: return "MITM";
+ case SMPAuthReqs::SECURE_CONNECTIONS: return "SC";
+ case SMPAuthReqs::KEYPRESS: return "Keypresses";
+ case SMPAuthReqs::CT2_H7_FUNC_SUPPORT: return "CT2_H7";
+ case SMPAuthReqs::RFU_1: return "RFU_1";
+ case SMPAuthReqs::RFU_2: return "RFU_2";
default: ; // fall through intended
}
return "Unknown AuthRequirements bit";
}
std::string direct_bt::getSMPAuthReqMaskString(const SMPAuthReqs mask) noexcept {
- const uint8_t one = 1;
- bool has_pre = false;
std::string out("[");
- for(int i=0; i<8; i++) {
- const uint8_t settingBit = one << i;
- if( 0 != ( static_cast<uint8_t>(mask) & settingBit ) ) {
- if( has_pre ) { out.append(", "); }
- out.append( getSMPAuthReqBitString( static_cast<SMPAuthReqs>(settingBit) ) );
- has_pre = true;
- }
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::BONDING) ) {
+ out.append("Bonding");
+ } else {
+ out.append("No bonding");
+ }
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::BONDING_RFU) ) {
+ out.append(", ");
+ out.append("Bonding Reserved");
+ }
+ out.append(", ");
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::MITM) ) {
+ out.append("MITM");
+ } else {
+ out.append("No MITM");
+ }
+ out.append(", ");
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::SECURE_CONNECTIONS) ) {
+ out.append("SC");
+ } else {
+ out.append("Legacy");
+ }
+ out.append(", ");
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::KEYPRESS) ) {
+ out.append("Keypresses");
+ } else {
+ out.append("No keypresses");
+ }
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::CT2_H7_FUNC_SUPPORT) ) {
+ out.append(", ");
+ out.append("CT2_H7");
+ }
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::RFU_1) ) {
+ out.append(", ");
+ out.append("RFU_1");
+ }
+ if( isSMPAuthReqBitSet(mask, SMPAuthReqs::RFU_2) ) {
+ out.append(", ");
+ out.append("RFU_2");
}
out.append("]");
return out;