38#include "HCIIoctl.hpp"
70 static int hci_open_dev(
const uint16_t
dev_id,
const uint16_t
channel)
noexcept;
71 static int hci_close_dev(
int dd)
noexcept;
73 std::recursive_mutex mtx_write;
77 std::atomic<::pthread_t> tid_read;
91 bool is_open() const noexcept {
return 0 <= socket_descriptor; }
97 bool interrupted() const noexcept {
return interrupted_intern || ( !is_interrupted_extern.is_null() && is_interrupted_extern(0) ); }
100 void close() noexcept;
103 inline
int socket() const noexcept {
return socket_descriptor; }
106 inline std::recursive_mutex &
mutex_write() noexcept {
return mtx_write; }
115 static inline void setu32_bit(
int nr,
void *addr)
noexcept
117 *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
120 static inline void clearu32_bit(
int nr,
void *addr)
noexcept
122 *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
125 static inline uint32_t testu32_bit(
int nr,
void *addr)
noexcept
127 return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
133 bzero(f,
sizeof(*f));
137 setu32_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
141 clearu32_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
145 return testu32_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
149 memset((
void *) &f->type_mask, 0xff,
sizeof(f->type_mask));
153 setu32_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
157 clearu32_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
161 return testu32_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
165 memset((
void *) f->event_mask, 0xff,
sizeof(f->event_mask));
177 return (f->opcode == opcode);
Read/Write HCI communication channel.
static uint32_t filter_test_ptype(int t, hci_ufilter *f) noexcept
HCIComm(const uint16_t dev_id, const uint16_t channel) noexcept
Constructing a newly opened HCI communication channel instance.
bool is_open() const noexcept
void close() noexcept
Closing the HCI channel, locking mutex_write().
bool interrupted() const noexcept
Returns true if interrupted by internal or external cause, hence shall stop connecting and reading.
static void filter_all_ptypes(hci_ufilter *f) noexcept
std::recursive_mutex & mutex_write() noexcept
Return the recursive write mutex for multithreading access.
static void filter_set_opcode(uint16_t opcode, hci_ufilter *f) noexcept
static void filter_clear_ptype(int t, hci_ufilter *f) noexcept
static int filter_test_opcode(uint16_t opcode, hci_ufilter *f) noexcept
static void filter_clear_opcode(hci_ufilter *f) noexcept
static uint32_t filter_test_event(int e, hci_ufilter *f) noexcept
jau::snsize_t read(uint8_t *buffer, const jau::nsize_t capacity, const jau::fraction_i64 &timeout) noexcept
Generic read w/ own timeout, w/o locking suitable for a unique ringbuffer sink.
void set_interrupted_query(get_boolean_callback_t is_interrupted_cb)
The external is interrupted callback is used until close(), thereafter it is removed.
void operator=(const HCIComm &)=delete
~HCIComm() noexcept
Releases this instance after issuing close().
int socket() const noexcept
Return this HCI socket descriptor.
HCIComm(const HCIComm &)=delete
static void filter_all_events(hci_ufilter *f) noexcept
jau::function< bool(int)> get_boolean_callback_t
Utilized to query for external interruption, whether device is still connected etc.
static void filter_set_event(int e, hci_ufilter *f) noexcept
static void filter_clear(hci_ufilter *f) noexcept
static void filter_clear_event(int e, hci_ufilter *f) noexcept
static void filter_set_ptype(int t, hci_ufilter *f) noexcept
jau::snsize_t write(const uint8_t *buffer, const jau::nsize_t size) noexcept
Generic write, locking mutex_write().
Class template jau::function is a general-purpose static-polymorphic function wrapper.
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.