diff options
-rw-r--r-- | api/direct_bt/BasicTypes.hpp | 24 | ||||
-rw-r--r-- | api/direct_bt/HCIHandler.hpp | 10 | ||||
-rw-r--r-- | api/direct_bt/HCITypes.hpp | 33 | ||||
-rw-r--r-- | src/direct_bt/HCIHandler.cpp | 13 |
4 files changed, 76 insertions, 4 deletions
diff --git a/api/direct_bt/BasicTypes.hpp b/api/direct_bt/BasicTypes.hpp index ef492d3a..5460d025 100644 --- a/api/direct_bt/BasicTypes.hpp +++ b/api/direct_bt/BasicTypes.hpp @@ -309,24 +309,42 @@ namespace direct_bt { return littleEndian ? le_to_cpu(*p) : be_to_cpu(*p); } - inline void set_bit_uint32(const int nr, uint32_t &mask) + inline void set_bit_uint32(const uint8_t nr, uint32_t &mask) { if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, 32, E_FILE_LINE); } mask |= 1 << (nr & 31); } - inline void clear_bit_uint32(const int nr, uint32_t &mask) + inline void clear_bit_uint32(const uint8_t nr, uint32_t &mask) { if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, 32, E_FILE_LINE); } mask |= ~(1 << (nr & 31)); } - inline uint32_t test_bit_uint32(const int nr, const uint32_t mask) + inline uint32_t test_bit_uint32(const uint8_t nr, const uint32_t mask) { if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, 32, E_FILE_LINE); } return mask & (1 << (nr & 31)); } + inline void set_bit_uint64(const uint8_t nr, uint64_t &mask) + { + if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, 64, E_FILE_LINE); } + mask |= 1 << (nr & 63); + } + + inline void clear_bit_uint64(const uint8_t nr, uint64_t &mask) + { + if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, 64, E_FILE_LINE); } + mask |= ~(1 << (nr & 63)); + } + + inline uint64_t test_bit_uint64(const uint8_t nr, const uint64_t mask) + { + if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, 64, E_FILE_LINE); } + return mask & (1 << (nr & 63)); + } + /** * Returns a C++ String taken from buffer with maximum length of min(max_len, max_len). * <p> diff --git a/api/direct_bt/HCIHandler.hpp b/api/direct_bt/HCIHandler.hpp index 05416816..412c1345 100644 --- a/api/direct_bt/HCIHandler.hpp +++ b/api/direct_bt/HCIHandler.hpp @@ -127,14 +127,22 @@ namespace direct_bt { std::recursive_mutex mtx; hci_ufilter filter_mask; std::atomic<uint32_t> metaev_filter_mask; + std::atomic<uint64_t> opcbit_filter_mask; inline bool filter_test_metaev(HCIMetaEventType mec) { return 0 != test_bit_uint32(number(mec)-1, metaev_filter_mask); } inline void filter_put_metaevs(const uint32_t mask) { metaev_filter_mask=mask; } inline static void filter_clear_metaevs(uint32_t &mask) { mask=0; } - inline static void filter_all_metaevs(uint32_t &mask) { mask=0xffff; } + inline static void filter_all_metaevs(uint32_t &mask) { mask=0xffffffffU; } inline static void filter_set_metaev(HCIMetaEventType mec, uint32_t &mask) { set_bit_uint32(number(mec)-1, mask); } + inline bool filter_test_opcbit(HCIOpcodeBit opcbit) { return 0 != test_bit_uint64(number(opcbit), opcbit_filter_mask); } + inline void filter_put_opcbit(const uint64_t mask) { opcbit_filter_mask=mask; } + + inline static void filter_clear_opcbit(uint64_t &mask) { mask=0; } + inline static void filter_all_opcbit(uint64_t &mask) { mask=0xffffffffffffffffUL; } + inline static void filter_set_opcbit(HCIOpcodeBit opcbit, uint64_t &mask) { set_bit_uint64(number(opcbit), mask); } + LFRingbuffer<std::shared_ptr<HCIEvent>, nullptr> hciEventRing; std::atomic<pthread_t> hciReaderThreadId; std::atomic<bool> hciReaderRunning; diff --git a/api/direct_bt/HCITypes.hpp b/api/direct_bt/HCITypes.hpp index 3c06443c..68f8816d 100644 --- a/api/direct_bt/HCITypes.hpp +++ b/api/direct_bt/HCITypes.hpp @@ -348,6 +348,39 @@ namespace direct_bt { } std::string getHCIOpcodeString(const HCIOpcode op); + enum class HCIOpcodeBit : uint8_t { + SPECIAL = 0, + CREATE_CONN = 3, + DISCONNECT = 4, + SET_EVENT_MASK = 6, + RESET = 7, + READ_LOCAL_VERSION = 10, + LE_SET_EVENT_MASK = 20, + LE_READ_BUFFER_SIZE = 21, + LE_READ_LOCAL_FEATURES = 22, + LE_SET_RANDOM_ADDR = 23, + LE_SET_ADV_PARAM = 24, + LE_READ_ADV_TX_POWER = 25, + LE_SET_ADV_DATA = 26, + LE_SET_SCAN_RSP_DATA = 27, + LE_SET_ADV_ENABLE = 28, + LE_SET_SCAN_PARAM = 29, + LE_SET_SCAN_ENABLE = 30, + LE_CREATE_CONN = 31, + LE_CREATE_CONN_CANCEL = 32, + LE_READ_WHITE_LIST_SIZE = 33, + LE_CLEAR_WHITE_LIST = 34, + LE_ADD_TO_WHITE_LIST = 35, + LE_DEL_FROM_WHITE_LIST = 36, + LE_CONN_UPDATE = 37, + LE_READ_REMOTE_FEATURES = 38, + LE_START_ENC = 39 + // etc etc - incomplete + }; + inline uint8_t number(const HCIOpcodeBit rhs) { + return static_cast<uint8_t>(rhs); + } + /** * BT Core Spec v5.2: Vol 4, Part E HCI: 5.4 Exchange of HCI-specific information * <p> diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp index 400828c5..48b7d08c 100644 --- a/src/direct_bt/HCIHandler.cpp +++ b/src/direct_bt/HCIHandler.cpp @@ -481,6 +481,19 @@ HCIHandler::HCIHandler(const BTMode btMode, const uint16_t dev_id, filter_set_metaev(HCIMetaEventType::LE_ADVERTISING_REPORT, mask); filter_put_metaevs(mask); } + // Mandatory own HCIOpcodeBit/HCIOpcode filter + { + uint64_t mask = 0; + // filter_all_opcbit(mask); + filter_set_opcbit(HCIOpcodeBit::CREATE_CONN, mask); + filter_set_opcbit(HCIOpcodeBit::DISCONNECT, mask); + filter_set_opcbit(HCIOpcodeBit::RESET, mask); + filter_set_opcbit(HCIOpcodeBit::READ_LOCAL_VERSION, mask); + filter_set_opcbit(HCIOpcodeBit::LE_SET_SCAN_PARAM, mask); + filter_set_opcbit(HCIOpcodeBit::LE_SET_SCAN_ENABLE, mask); + filter_set_opcbit(HCIOpcodeBit::LE_CREATE_CONN, mask); + filter_put_opcbit(mask); + } { HCICommand req0(HCIOpcode::READ_LOCAL_VERSION, 0); const hci_rp_read_local_version * ev_lv; |