Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
Public Types | Public Member Functions | Static Public Member Functions | List of all members
direct_bt::L2CAPComm Class Reference

Read/Write L2CAP communication channel. More...

#include <L2CAPComm.hpp>

Collaboration diagram for direct_bt::L2CAPComm:

Public Types

enum  Defaults : int { Defaults::L2CAP_CONNECT_MAX_RETRY = 3 }
 

Public Member Functions

 L2CAPComm (const BDAddressAndType &adapterAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid)
 Constructing a non connected L2CAP channel instance for the pre-defined PSM and CID. More...
 
 L2CAPComm (const L2CAPComm &)=delete
 
void operator= (const L2CAPComm &)=delete
 
 ~L2CAPComm () noexcept
 Destructor closing the L2CAP channel, see disconnect(). More...
 
bool open (const BTDevice &device, const BTSecurityLevel sec_level=BTSecurityLevel::NONE)
 Opens and connects the L2CAP channel, locking mutex_write(). More...
 
bool isOpen () const
 
bool close () noexcept
 Closing the L2CAP channel, locking mutex_write(). More...
 
int getSocketDescriptor () const noexcept
 Return this L2CAP socket descriptor. More...
 
bool hasIOError () const
 
std::string getStateString () const
 
std::recursive_mutex & mutex_write ()
 Return the recursive write mutex for multithreading access. More...
 
bool setBTSecurityLevel (const BTSecurityLevel sec_level)
 If sec_level > BTSecurityLevel::UNSET, sets the BlueZ's L2CAP socket BT_SECURITY sec_level, determining the SMP security mode per connection. More...
 
BTSecurityLevel getBTSecurityLevel ()
 Fetches the current BlueZ's L2CAP socket BT_SECURITY sec_level. More...
 
jau::snsize_t read (uint8_t *buffer, const jau::nsize_t capacity)
 Generic read, w/o locking suitable for a unique ringbuffer sink. More...
 
jau::snsize_t write (const uint8_t *buffer, const jau::nsize_t length)
 Generic write, locking mutex_write(). More...
 

Static Public Member Functions

static constexpr int number (const Defaults d)
 
static std::string getStateString (bool isConnected, bool hasIOError)
 

Detailed Description

Read/Write L2CAP communication channel.

Definition at line 113 of file L2CAPComm.hpp.

Member Enumeration Documentation

◆ Defaults

enum direct_bt::L2CAPComm::Defaults : int
strong
Enumerator
L2CAP_CONNECT_MAX_RETRY 

Definition at line 115 of file L2CAPComm.hpp.

Constructor & Destructor Documentation

◆ L2CAPComm() [1/2]

L2CAPComm::L2CAPComm ( const BDAddressAndType adapterAddressAndType,
const L2CAP_PSM  psm,
const L2CAP_CID  cid 
)

Constructing a non connected L2CAP channel instance for the pre-defined PSM and CID.

Definition at line 109 of file L2CAPComm.cpp.

◆ L2CAPComm() [2/2]

direct_bt::L2CAPComm::L2CAPComm ( const L2CAPComm )
delete

◆ ~L2CAPComm()

direct_bt::L2CAPComm::~L2CAPComm ( )
inlinenoexcept

Destructor closing the L2CAP channel, see disconnect().

Definition at line 155 of file L2CAPComm.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ close()

bool L2CAPComm::close ( )
noexcept

Closing the L2CAP channel, locking mutex_write().

Definition at line 241 of file L2CAPComm.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBTSecurityLevel()

BTSecurityLevel L2CAPComm::getBTSecurityLevel ( )

Fetches the current BlueZ's L2CAP socket BT_SECURITY sec_level.

Returns
BTSecurityLevel sec_level value, BTSecurityLevel::UNSET if failure

Definition at line 336 of file L2CAPComm.cpp.

Here is the call graph for this function:

◆ getSocketDescriptor()

int direct_bt::L2CAPComm::getSocketDescriptor ( ) const
inlinenoexcept

Return this L2CAP socket descriptor.

Definition at line 175 of file L2CAPComm.hpp.

◆ getStateString() [1/2]

std::string direct_bt::L2CAPComm::getStateString ( ) const
inline

Definition at line 178 of file L2CAPComm.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStateString() [2/2]

static std::string direct_bt::L2CAPComm::getStateString ( bool  isConnected,
bool  hasIOError 
)
inlinestatic

Definition at line 120 of file L2CAPComm.hpp.

Here is the call graph for this function:

◆ hasIOError()

bool direct_bt::L2CAPComm::hasIOError ( ) const
inline

Definition at line 177 of file L2CAPComm.hpp.

Here is the caller graph for this function:

◆ isOpen()

bool direct_bt::L2CAPComm::isOpen ( ) const
inline

Definition at line 169 of file L2CAPComm.hpp.

◆ mutex_write()

std::recursive_mutex& direct_bt::L2CAPComm::mutex_write ( )
inline

Return the recursive write mutex for multithreading access.

Definition at line 181 of file L2CAPComm.hpp.

◆ number()

static constexpr int direct_bt::L2CAPComm::number ( const Defaults  d)
inlinestaticconstexpr

Definition at line 118 of file L2CAPComm.hpp.

Here is the caller graph for this function:

◆ open()

bool L2CAPComm::open ( const BTDevice device,
const BTSecurityLevel  sec_level = BTSecurityLevel::NONE 
)

Opens and connects the L2CAP channel, locking mutex_write().

BT Core Spec v5.2: Vol 3, Part A: L2CAP_CONNECTION_REQ

Parameters
devicethe remote device to establish this L2CAP connection
sec_levelsec_level < BTSecurityLevel::NONE will not set security level
Returns
true if connection has been established, otherwise false

Definition at line 130 of file L2CAPComm.cpp.

Here is the call graph for this function:

◆ operator=()

void direct_bt::L2CAPComm::operator= ( const L2CAPComm )
delete

◆ read()

jau::snsize_t L2CAPComm::read ( uint8_t *  buffer,
const jau::nsize_t  capacity 
)

Generic read, w/o locking suitable for a unique ringbuffer sink.

Using L2CAPEnv::L2CAP_READER_POLL_TIMEOUT.

Definition at line 374 of file L2CAPComm.cpp.

Here is the call graph for this function:

◆ setBTSecurityLevel()

bool L2CAPComm::setBTSecurityLevel ( const BTSecurityLevel  sec_level)

If sec_level > BTSecurityLevel::UNSET, sets the BlueZ's L2CAP socket BT_SECURITY sec_level, determining the SMP security mode per connection.

To unset security, the L2CAP socket should be closed and opened again.

Parameters
sec_levelsec_level < BTSecurityLevel::NONE will not set security level and returns false.
Returns
true if a security level > BTSecurityLevel::UNSET has been set successfully, false if no security level has been set or if it failed.

Definition at line 289 of file L2CAPComm.cpp.

Here is the call graph for this function:

◆ write()

jau::snsize_t L2CAPComm::write ( const uint8_t *  buffer,
const jau::nsize_t  length 
)

Generic write, locking mutex_write().

Definition at line 441 of file L2CAPComm.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: