diff options
author | Sven Gothel <[email protected]> | 2020-11-08 03:12:19 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-11-08 03:12:19 +0100 |
commit | ba6eb0d9501d6db24257e01d4cc293ff637fb096 (patch) | |
tree | 0a2f9073904d58abe1611e113d91816dbb873aa1 | |
parent | 0353d54718eda6e1dd5dccc43bfbca06b236c6bd (diff) |
BTAddress.hpp: BDAddressType: Promote to scoped enum
-rw-r--r-- | api/direct_bt/BTAddress.hpp | 10 | ||||
-rw-r--r-- | api/direct_bt/BTTypes.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/MgmtTypes.hpp | 20 | ||||
-rw-r--r-- | src/direct_bt/BTTypes.cpp | 22 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 2 | ||||
-rw-r--r-- | src/direct_bt/L2CAPComm.cpp | 4 |
6 files changed, 33 insertions, 29 deletions
diff --git a/api/direct_bt/BTAddress.hpp b/api/direct_bt/BTAddress.hpp index 24dc59c6..b16443c2 100644 --- a/api/direct_bt/BTAddress.hpp +++ b/api/direct_bt/BTAddress.hpp @@ -44,7 +44,7 @@ namespace direct_bt { * 3) BT random address used as BD_ADDR on the LE physical channel is defined in Vol 3, Part C 10.8 * </pre> */ - enum BDAddressType : uint8_t { + enum class BDAddressType : uint8_t { /** Bluetooth BREDR address */ BDADDR_BREDR = 0x00, /** Bluetooth LE public address */ @@ -54,14 +54,18 @@ namespace direct_bt { /** Undefined */ BDADDR_UNDEFINED = 0xff }; - + constexpr uint8_t number(const BDAddressType rhs) noexcept { + return static_cast<uint8_t>(rhs); + } std::string getBDAddressTypeString(const BDAddressType type) noexcept; /** * Returns true if the given BDAddressType is a LE address type. * @param type given BDAddressType */ - constexpr bool isLEAddressType(const BDAddressType type) noexcept { return BDADDR_LE_PUBLIC == type || BDADDR_LE_RANDOM == type; } + constexpr bool isLEAddressType(const BDAddressType type) noexcept { + return BDAddressType::BDADDR_LE_PUBLIC == type || BDAddressType::BDADDR_LE_RANDOM == type; + } /** * Returns true if the given BDAddressType is a BREDR address type. diff --git a/api/direct_bt/BTTypes.hpp b/api/direct_bt/BTTypes.hpp index efcfa8ed..cf8c24ea 100644 --- a/api/direct_bt/BTTypes.hpp +++ b/api/direct_bt/BTTypes.hpp @@ -116,8 +116,8 @@ namespace direct_bt { */ enum class ScanType : uint8_t { NONE = 0, - BREDR = 1 << BDAddressType::BDADDR_BREDR, - LE = ( 1 << BDAddressType::BDADDR_LE_PUBLIC ) | ( 1 << BDAddressType::BDADDR_LE_RANDOM ), + BREDR = 1 << number(BDAddressType::BDADDR_BREDR), + LE = ( 1 << number(BDAddressType::BDADDR_LE_PUBLIC) ) | ( 1 << number(BDAddressType::BDADDR_LE_RANDOM) ), DUAL = BREDR | LE }; constexpr uint8_t number(const ScanType rhs) noexcept { diff --git a/api/direct_bt/MgmtTypes.hpp b/api/direct_bt/MgmtTypes.hpp index 8fe1e630..b387881c 100644 --- a/api/direct_bt/MgmtTypes.hpp +++ b/api/direct_bt/MgmtTypes.hpp @@ -264,7 +264,7 @@ namespace direct_bt { : MgmtCommand(MgmtOpcode::DISCONNECT, dev_id, 6+1) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); } const EUI48 getAddress() const noexcept { return EUI48(pdu.get_ptr_nc(MGMT_HEADER_SIZE)); } // mgmt_addr_info BDAddressType getAddressType() const noexcept { return static_cast<BDAddressType>(pdu.get_uint8_nc(MGMT_HEADER_SIZE+6)); } // mgmt_addr_info @@ -286,7 +286,7 @@ namespace direct_bt { : MgmtCommand(MgmtOpcode::GET_CONN_INFO, dev_id, 6+1) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); } const EUI48 getAddress() const noexcept { return EUI48(pdu.get_ptr_nc(MGMT_HEADER_SIZE)); } // mgmt_addr_info BDAddressType getAddressType() const noexcept { return static_cast<BDAddressType>(pdu.get_uint8_nc(MGMT_HEADER_SIZE+6)); } // mgmt_addr_info @@ -312,7 +312,7 @@ namespace direct_bt { : MgmtCommand(MgmtOpcode::PIN_CODE_REPLY, dev_id, 6+1+1+16) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); pdu.put_uint8_nc(MGMT_HEADER_SIZE+7, pin_len); pdu.put_octets_nc(MGMT_HEADER_SIZE+8, pin_code); } @@ -338,7 +338,7 @@ namespace direct_bt { : MgmtCommand(MgmtOpcode::PIN_CODE_NEG_REPLY, dev_id, 6+1) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); } const EUI48 getAddress() const noexcept { return EUI48(pdu.get_ptr_nc(MGMT_HEADER_SIZE)); } // mgmt_addr_info BDAddressType getAddressType() const noexcept { return static_cast<BDAddressType>(pdu.get_uint8_nc(MGMT_HEADER_SIZE+6)); } // mgmt_addr_info @@ -362,7 +362,7 @@ namespace direct_bt { : MgmtCommand(MgmtOpcode::ADD_DEVICE_WHITELIST, dev_id, 6+1+1) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); pdu.put_uint8_nc(MGMT_HEADER_SIZE+6+1, number(ctype)); } const EUI48 getAddress() const noexcept { return EUI48(pdu.get_ptr_nc(MGMT_HEADER_SIZE)); } // mgmt_addr_info @@ -386,7 +386,7 @@ namespace direct_bt { : MgmtCommand(MgmtOpcode::REMOVE_DEVICE_WHITELIST, dev_id, 6+1) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); } const EUI48 getAddress() const noexcept { return EUI48(pdu.get_ptr_nc(MGMT_HEADER_SIZE)); } // mgmt_addr_info BDAddressType getAddressType() const noexcept { return static_cast<BDAddressType>(pdu.get_uint8_nc(MGMT_HEADER_SIZE+6)); } // mgmt_addr_info @@ -867,7 +867,7 @@ namespace direct_bt { : MgmtEvent(Opcode::DEVICE_FOUND, dev_id, 6+1+1+4+2+0) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, eir->getAddress()); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, eir->getAddressType()); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(eir->getAddressType())); pdu.put_int8_nc(MGMT_HEADER_SIZE+6+1, eir->getRSSI()); pdu.put_uint32_nc(MGMT_HEADER_SIZE+6+1+1, eir->getFlags()); // EIR flags only 8bit, Mgmt uses 32bit? pdu.put_uint16_nc(MGMT_HEADER_SIZE+6+1+1+4, 0); // eir_len @@ -919,7 +919,7 @@ namespace direct_bt { : MgmtEvent(Opcode::DEVICE_CONNECTED, dev_id, 6+1+4+2), hci_conn_handle(hci_conn_handle_) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); pdu.put_uint32_nc(MGMT_HEADER_SIZE+6+1, 0); // flags pdu.put_uint16_nc(MGMT_HEADER_SIZE+6+1+4, 0); // eir-len } @@ -965,7 +965,7 @@ namespace direct_bt { : MgmtEvent(Opcode::CONNECT_FAILED, dev_id, 6+1+1), hciStatus(status) { pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); pdu.put_uint8_nc(MGMT_HEADER_SIZE+6+1, static_cast<uint8_t>(MgmtStatus::CONNECT_FAILED)); } const EUI48 getAddress() const noexcept { return EUI48(pdu.get_ptr_nc(MGMT_HEADER_SIZE)); } // mgmt_addr_info @@ -1038,7 +1038,7 @@ namespace direct_bt { { DisconnectReason disconnectReason = getDisconnectReason(hciReason_); pdu.put_eui48_nc(MGMT_HEADER_SIZE, address); - pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, addressType); + pdu.put_uint8_nc(MGMT_HEADER_SIZE+6, number(addressType)); pdu.put_uint8_nc(MGMT_HEADER_SIZE+6+1, static_cast<uint8_t>(disconnectReason)); } diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp index d37b15cf..fa19de33 100644 --- a/src/direct_bt/BTTypes.cpp +++ b/src/direct_bt/BTTypes.cpp @@ -44,15 +44,15 @@ using namespace direct_bt; BDAddressType direct_bt::getBDAddressType(const HCILEPeerAddressType hciPeerAddrType) noexcept { switch(hciPeerAddrType) { case HCILEPeerAddressType::PUBLIC: - return BDADDR_LE_PUBLIC; + return BDAddressType::BDADDR_LE_PUBLIC; case HCILEPeerAddressType::RANDOM: [[fallthrough]]; case HCILEPeerAddressType::PUBLIC_IDENTITY: [[fallthrough]]; case HCILEPeerAddressType::RANDOM_STATIC_IDENTITY: - return BDADDR_LE_RANDOM; + return BDAddressType::BDADDR_LE_RANDOM; default: - return BDADDR_UNDEFINED; + return BDAddressType::BDADDR_UNDEFINED; } } @@ -74,15 +74,15 @@ std::string direct_bt::getHCILEPeerAddressTypeString(const HCILEPeerAddressType BDAddressType direct_bt::getBDAddressType(const HCILEOwnAddressType hciOwnAddrType) noexcept { switch(hciOwnAddrType) { case HCILEOwnAddressType::PUBLIC: - return BDADDR_LE_PUBLIC; + return BDAddressType::BDADDR_LE_PUBLIC; case HCILEOwnAddressType::RANDOM: [[fallthrough]]; case HCILEOwnAddressType::RESOLVABLE_OR_PUBLIC: [[fallthrough]]; case HCILEOwnAddressType::RESOLVABLE_OR_RANDOM: - return BDADDR_LE_RANDOM; + return BDAddressType::BDADDR_LE_RANDOM; default: - return BDADDR_UNDEFINED; + return BDAddressType::BDADDR_UNDEFINED; } } @@ -103,14 +103,14 @@ std::string direct_bt::getHCILEOwnAddressTypeString(const HCILEOwnAddressType ty #define CHAR_DECL_BDADDRESSTYPE_ENUM(X) \ - X(BDADDR_BREDR) \ - X(BDADDR_LE_PUBLIC) \ - X(BDADDR_LE_RANDOM) \ - X(BDADDR_UNDEFINED) + X(BDAddressType,BDADDR_BREDR) \ + X(BDAddressType,BDADDR_LE_PUBLIC) \ + X(BDAddressType,BDADDR_LE_RANDOM) \ + X(BDAddressType,BDADDR_UNDEFINED) std::string direct_bt::getBDAddressTypeString(const BDAddressType type) noexcept { switch(type) { - CHAR_DECL_BDADDRESSTYPE_ENUM(CASE_TO_STRING) + CHAR_DECL_BDADDRESSTYPE_ENUM(CASE2_TO_STRING) default: ; // fall through intended } return "Unknown BDAddressType"; diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index 7572e4ba..9ad8974a 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -689,7 +689,7 @@ bool DBTManager::stopDiscovery(const uint16_t dev_id, const ScanType type) noexc bool DBTManager::uploadConnParam(const uint16_t dev_id, const EUI48 &address, const BDAddressType address_type, const uint16_t conn_min_interval, const uint16_t conn_max_interval, const uint16_t conn_latency, const uint16_t supervision_timeout) noexcept { - MgmtConnParam connParam{ address, address_type, conn_min_interval, conn_max_interval, conn_latency, supervision_timeout }; + MgmtConnParam connParam{ address, number(address_type), conn_min_interval, conn_max_interval, conn_latency, supervision_timeout }; MgmtLoadConnParamCmd req(dev_id, connParam); std::shared_ptr<MgmtEvent> res = sendWithReply(req); if( nullptr != res && res->getOpcode() == MgmtEvent::Opcode::CMD_COMPLETE ) { diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp index b3493fc6..09b6c3df 100644 --- a/src/direct_bt/L2CAPComm.cpp +++ b/src/direct_bt/L2CAPComm.cpp @@ -80,7 +80,7 @@ int L2CAPComm::l2cap_open_dev(const EUI48 & adapterAddress, const uint16_t psm, a.l2_psm = jau::cpu_to_le(psm); a.l2_bdaddr = adapterAddress; a.l2_cid = jau::cpu_to_le(cid); - a.l2_bdaddr_type = pubaddrAdapter ? BDADDR_LE_PUBLIC : BDADDR_LE_RANDOM; + a.l2_bdaddr_type = pubaddrAdapter ? ::number(BDAddressType::BDADDR_LE_PUBLIC) : ::number(BDAddressType::BDADDR_LE_RANDOM); if ( bind(fd, (struct sockaddr *) &a, sizeof(a)) < 0 ) { ERR_PRINT("L2CAPComm::l2cap_open_dev: bind failed"); goto failed; @@ -130,7 +130,7 @@ L2CAPComm::L2CAPComm(std::shared_ptr<DBTDevice> device_, const uint16_t psm_, co req.l2_psm = jau::cpu_to_le(psm_); req.l2_bdaddr = device_->getAddress(); req.l2_cid = jau::cpu_to_le(cid_); - req.l2_bdaddr_type = device_->getAddressType(); + req.l2_bdaddr_type = ::number(device_->getAddressType()); while( !interrupt_flag ) { // blocking |