aboutsummaryrefslogtreecommitdiffstats
path: root/src/direct_bt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-26 07:35:38 +0200
committerSven Gothel <[email protected]>2020-06-26 07:35:38 +0200
commit25df14701cc9b43ee656beab915de619c2054a3f (patch)
tree8045efbdddb8fcf8501224f6486963fe6e89261b /src/direct_bt
parentaa912027163e577336b235220a8a237bd466b2da (diff)
L2CAPComm/GATTHandler: Use prefetched 'deviceString' for verbose output
This potentially avoid a SIGSEGV in case of an error, i.e. destructed device instance.
Diffstat (limited to 'src/direct_bt')
-rw-r--r--src/direct_bt/GATTHandler.cpp10
-rw-r--r--src/direct_bt/L2CAPComm.cpp15
2 files changed, 15 insertions, 10 deletions
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index f44feedf..2f393c82 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -263,12 +263,12 @@ bool GATTHandler::connect() {
if( !isConnected.compare_exchange_strong(expConn, true) ) {
// already connected
INFO_PRINT("GATTHandler::connect: Already connected: GattHandler[%s], l2cap[%s]: %s",
- getStateString().c_str(), l2cap.getStateString().c_str(), device->toString().c_str());
+ getStateString().c_str(), l2cap.getStateString().c_str(), deviceString.c_str());
return true;
}
hasIOError = false;
INFO_PRINT("GATTHandler::connect: Start: GattHandler[%s], l2cap[%s]: %s",
- getStateString().c_str(), l2cap.getStateString().c_str(), device->toString().c_str());
+ getStateString().c_str(), l2cap.getStateString().c_str(), deviceString.c_str());
if( !l2cap.connect() || !validateConnected() ) {
DBG_PRINT("GATTHandler.connect: Could not connect");
@@ -309,13 +309,13 @@ bool GATTHandler::disconnect(const bool disconnectDevice, const bool ioErrorCaus
if( !isConnected.compare_exchange_strong(expConn, false) ) {
// not connected
INFO_PRINT("GATTHandler::disconnect: Not connected: disconnectDevice %d, ioErrorCause %d: GattHandler[%s], l2cap[%s]: %s",
- disconnectDevice, ioErrorCause, getStateString().c_str(), l2cap.getStateString().c_str(), device->toString().c_str());
+ disconnectDevice, ioErrorCause, getStateString().c_str(), l2cap.getStateString().c_str(), deviceString.c_str());
l2cap.disconnect(); // interrupt GATT's L2CAP ::connect(..), avoiding prolonged hang
return false;
}
hasIOError = false;
INFO_PRINT("GATTHandler::disconnect: Start: disconnectDevice %d, ioErrorCause %d: GattHandler[%s], l2cap[%s]: %s",
- disconnectDevice, ioErrorCause, getStateString().c_str(), l2cap.getStateString().c_str(), device->toString().c_str());
+ disconnectDevice, ioErrorCause, getStateString().c_str(), l2cap.getStateString().c_str(), deviceString.c_str());
l2cap.disconnect(); // interrupt GATT's L2CAP ::connect(..), avoiding prolonged hang
@@ -344,7 +344,7 @@ bool GATTHandler::disconnect(const bool disconnectDevice, const bool ioErrorCaus
device->disconnect(false /* sentFromManager */, ioErrorCause, reason);
}
- INFO_PRINT("GATTHandler::disconnect: End");
+ INFO_PRINT("GATTHandler::disconnect: End: %s", deviceString.c_str());
return true;
}
diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp
index e5e5fce1..c5e06891 100644
--- a/src/direct_bt/L2CAPComm.cpp
+++ b/src/direct_bt/L2CAPComm.cpp
@@ -97,18 +97,23 @@ int L2CAPComm::l2cap_close_dev(int dd)
// *************************************************
// *************************************************
+L2CAPComm::L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, const uint16_t cid, const bool pubaddr=true)
+: device(device), deviceString(device->getAddressString()), psm(psm), cid(cid), pubaddr(pubaddr),
+ _dd(-1), isConnected(false), hasIOError(false), interruptFlag(false), tid_connect(0)
+{ }
+
bool L2CAPComm::connect() {
/** BT Core Spec v5.2: Vol 3, Part A: L2CAP_CONNECTION_REQ */
bool expConn = false; // C++11, exp as value since C++20
if( !isConnected.compare_exchange_strong(expConn, true) ) {
// already connected
DBG_PRINT("L2CAPComm::connect: Already connected: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, pubaddr);
return true;
}
hasIOError = false;
DBG_PRINT("L2CAPComm::connect: Start: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, pubaddr);
sockaddr_l2 req;
int err, res;
@@ -134,7 +139,7 @@ bool L2CAPComm::connect() {
res = ::connect(_dd, (struct sockaddr*)&req, sizeof(req));
DBG_PRINT("L2CAPComm::connect: Result %d, errno 0%X %s, %s",
- res, errno, strerror(errno), device->getAddress().toString().c_str());
+ res, errno, strerror(errno), deviceString.c_str().c_str());
if( !res )
{
@@ -172,12 +177,12 @@ bool L2CAPComm::disconnect() {
bool expConn = true; // C++11, exp as value since C++20
if( !isConnected.compare_exchange_strong(expConn, false) ) {
INFO_PRINT("L2CAPComm::disconnect: Not connected: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, pubaddr);
return false;
}
hasIOError = false;
INFO_PRINT("L2CAPComm::disconnect: Start: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, pubaddr);
interruptFlag = true;
// interrupt L2CAP ::connect(..), avoiding prolonged hang