summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-08-24 05:50:00 +0200
committerSven Gothel <[email protected]>2020-08-24 05:50:00 +0200
commitf9f54887a7d1db59e2ead858274bdaa89c82956c (patch)
tree70de5fcd869ec6d6338a0bf1c827c1f985c9eb7b /src
parent2c5ff9fe582b56889d7cfc0f26b82b501354c215 (diff)
Adapt to new DBG_PRINT(..) semantics, reduce verbosity, use specific macros for special cases (e.g. GATT_PRINT, ..)
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/BTTypes.cpp7
-rw-r--r--src/direct_bt/BasicTypes.cpp4
-rw-r--r--src/direct_bt/DBTAdapter.cpp35
-rw-r--r--src/direct_bt/DBTDevice.cpp15
-rw-r--r--src/direct_bt/DBTManager.cpp36
-rw-r--r--src/direct_bt/GATTHandler.cpp65
-rw-r--r--src/direct_bt/L2CAPComm.cpp12
7 files changed, 79 insertions, 95 deletions
diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp
index 5a6df8ba..9a1ccf92 100644
--- a/src/direct_bt/BTTypes.cpp
+++ b/src/direct_bt/BTTypes.cpp
@@ -534,8 +534,6 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) {
while( 0 < ( offset = next_data_elem( &elem_len, &elem_type, &elem_data, data, offset, data_length ) ) )
{
- DBG_PRINT("%s-Element[%d] @ [%d/%d]: type 0x%.2X with %d bytes net",
- getSourceString().c_str(), count, offset, data_length, elem_type, elem_len);
count++;
// Guaranteed: elem_len >= 0!
@@ -683,10 +681,7 @@ std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t c
const int bytes_left = limes - i_octets;
if( segment_count != read_segments ) {
- fprintf(stderr, "AD-Reports: Warning: Incomplete %d reports within %d bytes: Segment read %d < %d, data-ptr %d bytes to limes\n",
- num_reports, data_length, read_segments, segment_count, bytes_left);
- } else {
- DBG_PRINT("AD-Reports: Completed %d reports within %d bytes: Segment read %d == %d, data-ptr %d bytes to limes",
+ WARN_PRINT("AD-Reports: Incomplete %d reports within %d bytes: Segment read %d < %d, data-ptr %d bytes to limes\n",
num_reports, data_length, read_segments, segment_count, bytes_left);
}
return ad_reports;
diff --git a/src/direct_bt/BasicTypes.cpp b/src/direct_bt/BasicTypes.cpp
index 87a517d8..f1aea683 100644
--- a/src/direct_bt/BasicTypes.cpp
+++ b/src/direct_bt/BasicTypes.cpp
@@ -23,8 +23,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "BasicTypes.hpp"
-
#include <cstdint>
#include <cinttypes>
@@ -38,7 +36,7 @@ extern "C" {
#endif
}
-#include <dbt_debug.hpp>
+#include "direct_bt/BasicTypes.hpp"
using namespace direct_bt;
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index a586b2c9..c9d478df 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -49,6 +49,13 @@ extern "C" {
#include <poll.h>
}
+// #define EVENT_PRINT_ON 1
+#ifdef EVENT_PRINT_ON
+ #define EVENT_PRINT(...) PLAIN_PRINT(__VA_ARGS__)
+#else
+ #define EVENT_PRINT(...)
+#endif
+
using namespace direct_bt;
int DBTAdapter::findDeviceIdx(std::vector<std::shared_ptr<DBTDevice>> & devices, EUI48 const & mac, const BDAddressType macType) {
@@ -632,7 +639,7 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringMgmt(std::shared_ptr<MgmtEvent> e) {
currentMetaScanType = ScanType::NONE;
}
}
- DBG_PRINT("DBTAdapter::EventCB:DeviceDiscovering(dev_id %d, keepDiscoveringAlive %d, currentScanType[native %s, meta %s]): %s",
+ EVENT_PRINT("DBTAdapter::EventCB:DeviceDiscovering(dev_id %d, keepDiscoveringAlive %d, currentScanType[native %s, meta %s]): %s",
dev_id, keepDiscoveringAlive.load(),
getScanTypeString(currentNativeScanType).c_str(), getScanTypeString(currentMetaScanType).c_str(),
e->toString().c_str());
@@ -657,11 +664,11 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringMgmt(std::shared_ptr<MgmtEvent> e) {
}
bool DBTAdapter::mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e) {
- DBG_PRINT("DBTAdapter::EventCB:NewSettings: %s", e->toString().c_str());
+ EVENT_PRINT("DBTAdapter::EventCB:NewSettings: %s", e->toString().c_str());
const MgmtEvtNewSettings &event = *static_cast<const MgmtEvtNewSettings *>(e.get());
AdapterSetting old_setting = adapterInfo->getCurrentSetting();
AdapterSetting changes = adapterInfo->setCurrentSetting(event.getSettings());
- DBG_PRINT("DBTAdapter::EventCB:NewSettings: %s -> %s, changes %s",
+ EVENT_PRINT("DBTAdapter::EventCB:NewSettings: %s -> %s, changes %s",
getAdapterSettingsString(old_setting).c_str(),
getAdapterSettingsString(adapterInfo->getCurrentSetting()).c_str(),
getAdapterSettingsString(changes).c_str() );
@@ -682,7 +689,7 @@ bool DBTAdapter::mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e) {
}
bool DBTAdapter::mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e) {
- DBG_PRINT("DBTAdapter::EventCB:LocalNameChanged: %s", e->toString().c_str());
+ EVENT_PRINT("DBTAdapter::EventCB:LocalNameChanged: %s", e->toString().c_str());
const MgmtEvtLocalNameChanged &event = *static_cast<const MgmtEvtLocalNameChanged *>(e.get());
std::string old_name = localName.getName();
std::string old_shortName = localName.getShortName();
@@ -694,7 +701,7 @@ bool DBTAdapter::mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e) {
if( shortNameChanged ) {
localName.setShortName(event.getShortName());
}
- DBG_PRINT("DBTAdapter::EventCB:LocalNameChanged: Local name: %d: '%s' -> '%s'; short_name: %d: '%s' -> '%s'",
+ EVENT_PRINT("DBTAdapter::EventCB:LocalNameChanged: Local name: %d: '%s' -> '%s'; short_name: %d: '%s' -> '%s'",
nameChanged, old_name.c_str(), localName.getName().c_str(),
shortNameChanged, old_shortName.c_str(), localName.getShortName().c_str());
(void)nameChanged;
@@ -765,7 +772,7 @@ bool DBTAdapter::mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e) {
ad_report.toString().c_str(),
device->toString().c_str());
} else {
- DBG_PRINT("DBTAdapter::EventHCI:DeviceConnected(dev_id %d, new_connect %d, updated %s): %s, handle %s -> %s,\n %s,\n -> %s",
+ EVENT_PRINT("DBTAdapter::EventHCI:DeviceConnected(dev_id %d, new_connect %d, updated %s): %s, handle %s -> %s,\n %s,\n -> %s",
dev_id, new_connect, getEIRDataMaskString(updateMask).c_str(), event.toString().c_str(),
uint16HexString(device->getConnectionHandle()).c_str(), uint16HexString(event.getHCIHandle()).c_str(),
ad_report.toString().c_str(),
@@ -796,12 +803,12 @@ bool DBTAdapter::mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e) {
}
bool DBTAdapter::mgmtEvConnectFailedHCI(std::shared_ptr<MgmtEvent> e) {
- DBG_PRINT("DBTAdapter::EventHCI:ConnectFailed: %s", e->toString().c_str());
+ EVENT_PRINT("DBTAdapter::EventHCI:ConnectFailed: %s", e->toString().c_str());
const MgmtEvtDeviceConnectFailed &event = *static_cast<const MgmtEvtDeviceConnectFailed *>(e.get());
std::shared_ptr<DBTDevice> device = findConnectedDevice(event.getAddress(), event.getAddressType());
if( nullptr != device ) {
const uint16_t handle = device->getConnectionHandle();
- DBG_PRINT("DBTAdapter::EventHCI:ConnectFailed(dev_id %d): %s, handle %s -> zero,\n -> %s",
+ EVENT_PRINT("DBTAdapter::EventHCI:ConnectFailed(dev_id %d): %s, handle %s -> zero,\n -> %s",
dev_id, event.toString().c_str(), uint16HexString(handle).c_str(),
device->toString().c_str());
@@ -838,7 +845,7 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) {
dev_id, event.toString().c_str(), device->toString().c_str());
return true;
}
- DBG_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s, handle %s -> zero,\n -> %s",
+ EVENT_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s, handle %s -> zero,\n -> %s",
dev_id, event.toString().c_str(), uint16HexString(event.getHCIHandle()).c_str(),
device->toString().c_str());
@@ -867,14 +874,14 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) {
}
bool DBTAdapter::mgmtEvDeviceDisconnectedMgmt(std::shared_ptr<MgmtEvent> e) {
- DBG_PRINT("DBTAdapter::EventCB:DeviceDisconnected: %s", e->toString().c_str());
+ EVENT_PRINT("DBTAdapter::EventCB:DeviceDisconnected: %s", e->toString().c_str());
const MgmtEvtDeviceDisconnected &event = *static_cast<const MgmtEvtDeviceDisconnected *>(e.get());
(void)event;
return true;
}
bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) {
- DBG_PRINT("DBTAdapter::EventCB:DeviceFound(dev_id %d): %s", dev_id, e->toString().c_str());
+ EVENT_PRINT("DBTAdapter::EventCB:DeviceFound(dev_id %d): %s", dev_id, e->toString().c_str());
const MgmtEvtDeviceFound &deviceFoundEvent = *static_cast<const MgmtEvtDeviceFound *>(e.get());
std::shared_ptr<EInfoReport> eir = deviceFoundEvent.getEIR();
@@ -901,7 +908,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) {
// drop existing device
//
EIRDataType updateMask = dev->update(*eir);
- DBG_PRINT("DBTAdapter::EventCB:DeviceFound: Drop already discovered %s, %s",
+ EVENT_PRINT("DBTAdapter::EventCB:DeviceFound: Drop already discovered %s, %s",
dev->getAddressString().c_str(), eir->toString().c_str());
if( EIRDataType::NONE != updateMask ) {
sendDeviceUpdated("DiscoveredDeviceFound", dev, eir->getTimestamp(), updateMask);
@@ -920,7 +927,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) {
EIRDataType updateMask = dev->update(*eir);
addDiscoveredDevice(dev); // re-add to discovered devices!
dev->ts_last_discovery = eir->getTimestamp();
- DBG_PRINT("DBTAdapter::EventCB:DeviceFound: Use already shared %s, %s",
+ EVENT_PRINT("DBTAdapter::EventCB:DeviceFound: Use already shared %s, %s",
dev->getAddressString().c_str(), eir->toString().c_str());
int i=0;
@@ -948,7 +955,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) {
dev = std::shared_ptr<DBTDevice>(new DBTDevice(*this, *eir));
addDiscoveredDevice(dev);
addSharedDevice(dev);
- DBG_PRINT("DBTAdapter::EventCB:DeviceFound: Use new %s, %s",
+ EVENT_PRINT("DBTAdapter::EventCB:DeviceFound: Use new %s, %s",
dev->getAddressString().c_str(), eir->toString().c_str());
int i=0;
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index 1a07eca5..435701f8 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -431,7 +431,7 @@ HCIStatusCode DBTDevice::disconnect(const bool fromDisconnectCB, const bool ioEr
// Lock to avoid other threads connecting while disconnecting
const std::lock_guard<std::recursive_mutex> lock_conn(mtx_connect); // RAII-style acquire and relinquish via destructor
- DBG_PRINT("DBTDevice::disconnect: Start: isConnected %d/%d, fromDisconnectCB %d, ioError %d, reason 0x%X (%s), gattHandler %d, hciConnHandle %s",
+ INFO_PRINT("DBTDevice::disconnect: Start: isConnected %d/%d, fromDisconnectCB %d, ioError %d, reason 0x%X (%s), gattHandler %d, hciConnHandle %s",
allowDisconnect.load(), isConnected.load(), fromDisconnectCB, ioErrorCause,
static_cast<uint8_t>(reason), getHCIStatusCodeString(reason).c_str(),
(nullptr != gattHandler), uint16HexString(hciConnHandle).c_str());
@@ -457,12 +457,19 @@ HCIStatusCode DBTDevice::disconnect(const bool fromDisconnectCB, const bool ioEr
res = hci->disconnect(ioErrorCause, hciConnHandle.load(), address, addressType, reason);
if( HCIStatusCode::SUCCESS != res ) {
- DBG_PRINT("DBTDevice::disconnect: handle 0x%X, errno %d %s", hciConnHandle.load(), errno, strerror(errno));
+ ERR_PRINT("DBTDevice::disconnect: status %s, handle 0x%X, isConnected %d/%d, fromDisconnectCB %d, ioError %d: errno %d %s on %s",
+ getHCIStatusCodeString(res).c_str(), hciConnHandle.load(),
+ allowDisconnect.load(), isConnected.load(), fromDisconnectCB, ioErrorCause,
+ errno, strerror(errno),
+ toString(false).c_str());
}
exit:
- DBG_PRINT("DBTDevice::disconnect: End: isConnected %d/%d, fromDisconnectCB %d, ioError %d",
- allowDisconnect.load(), isConnected.load(), fromDisconnectCB, ioErrorCause);
+ INFO_PRINT("DBTDevice::disconnect: End: status %s, handle 0x%X, isConnected %d/%d, fromDisconnectCB %d, ioError %d on %s",
+ getHCIStatusCodeString(res).c_str(), hciConnHandle.load(),
+ allowDisconnect.load(), isConnected.load(), fromDisconnectCB, ioErrorCause,
+ toString(false).c_str());
+
return res;
}
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index 0818455b..19bfae6e 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -60,7 +60,7 @@ void DBTManager::mgmtReaderThreadImpl() {
const std::lock_guard<std::mutex> lock(mtx_mgmtReaderInit); // RAII-style acquire and relinquish via destructor
mgmtReaderShallStop = false;
mgmtReaderRunning = true;
- INFO_PRINT("DBTManager::reader: Started");
+ DBG_PRINT("DBTManager::reader: Started");
cv_mgmtReaderInit.notify_all();
}
@@ -83,29 +83,10 @@ void DBTManager::mgmtReaderThreadImpl() {
std::shared_ptr<MgmtEvent> event( MgmtEvent::getSpecialized(rbuffer.get_ptr(), len) );
const MgmtEvent::Opcode opc = event->getOpcode();
if( MgmtEvent::Opcode::CMD_COMPLETE == opc || MgmtEvent::Opcode::CMD_STATUS == opc ) {
- DBG_PRINT("DBTManager::reader: CmdResult %s", event->toString().c_str());
mgmtEventRing.putBlocking( event );
} else {
// issue a callback
- const std::lock_guard<std::recursive_mutex> lock(mtx_callbackLists); // RAII-style acquire and relinquish via destructor
- const int dev_id = event->getDevID();
- MgmtAdapterEventCallbackList & mgmtEventCallbackList = mgmtAdapterEventCallbackLists[static_cast<uint16_t>(opc)];
- int invokeCount = 0;
- for (auto it = mgmtEventCallbackList.begin(); it != mgmtEventCallbackList.end(); ++it) {
- if( 0 > it->getDevID() || dev_id == it->getDevID() ) {
- try {
- it->getCallback().invoke(event);
- } catch (std::exception &e) {
- ERR_PRINT("DBTManager::fwdPacketReceived-CBs %d/%zd: MgmtAdapterEventCallback %s : Caught exception %s",
- invokeCount+1, mgmtEventCallbackList.size(),
- it->toString().c_str(), e.what());
- }
- invokeCount++;
- }
- }
- DBG_PRINT("DBTManager::reader: Event %s -> %d/%zd callbacks",
- event->toString().c_str(), invokeCount, mgmtEventCallbackList.size());
- (void)invokeCount;
+ sendMgmtEvent(event);
}
} else if( ETIMEDOUT != errno && !mgmtReaderShallStop ) { // expected exits
ERR_PRINT("DBTManager::reader: HCIComm error");
@@ -120,8 +101,7 @@ void DBTManager::mgmtReaderThreadImpl() {
void DBTManager::sendMgmtEvent(std::shared_ptr<MgmtEvent> event) {
const std::lock_guard<std::recursive_mutex> lock(mtx_callbackLists); // RAII-style acquire and relinquish via destructor
const int dev_id = event->getDevID();
- const MgmtEvent::Opcode opc = event->getOpcode();
- MgmtAdapterEventCallbackList & mgmtEventCallbackList = mgmtAdapterEventCallbackLists[static_cast<uint16_t>(opc)];
+ MgmtAdapterEventCallbackList & mgmtEventCallbackList = mgmtAdapterEventCallbackLists[static_cast<uint16_t>(event->getOpcode())];
int invokeCount = 0;
for (auto it = mgmtEventCallbackList.begin(); it != mgmtEventCallbackList.end(); ++it) {
if( 0 > it->getDevID() || dev_id == it->getDevID() ) {
@@ -135,8 +115,7 @@ void DBTManager::sendMgmtEvent(std::shared_ptr<MgmtEvent> event) {
invokeCount++;
}
}
- DBG_PRINT("DBTManager::sendMgmtEvent: Event %s -> %d/%zd callbacks",
- event->toString().c_str(), invokeCount, mgmtEventCallbackList.size());
+ // DBG_PRINT("DBTManager::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size());
(void)invokeCount;
}
@@ -171,7 +150,6 @@ std::shared_ptr<MgmtEvent> DBTManager::sendWithReply(MgmtCommand &req) {
const std::lock_guard<std::recursive_mutex> lock(mtx_sendReply); // RAII-style acquire and relinquish via destructor
{
const std::lock_guard<std::recursive_mutex> lock(comm.mutex()); // RAII-style acquire and relinquish via destructor
- DBG_PRINT("DBTManager::sendWithReply.0: req %s", req.toString().c_str());
TROOctets & pdu = req.getPDU();
if ( comm.write( pdu.get_ptr(), pdu.getSize() ) < 0 ) {
ERR_PRINT("DBTManager::sendWithReply: HCIComm write error, req %s", req.toString().c_str());
@@ -190,11 +168,10 @@ std::shared_ptr<MgmtEvent> DBTManager::sendWithReply(MgmtCommand &req) {
} else if( !res->validate(req) ) {
// This could occur due to an earlier timeout w/ a nullptr == res (see above),
// i.e. the pending reply processed here and naturally not-matching.
- WARN_PRINT("DBTManager::sendWithReply: res mismatch (drop evt, continue retry %d): res %s; req %s",
+ DBG_PRINT("DBTManager::sendWithReply: res mismatch (drop evt, continue retry %d): res %s; req %s",
retry, res->toString().c_str(), req.toString().c_str());
retry--;
} else {
- DBG_PRINT("DBTManager::sendWithReply.X: res: %s, req %s", res->toString().c_str(), req.toString().c_str());
return res;
}
}
@@ -282,7 +259,6 @@ DBTManager::DBTManager(const BTMode btMode)
while( false == mgmtReaderRunning ) {
cv_mgmtReaderInit.wait(lock);
}
- DBG_PRINT("DBTManager::ctor: Reader Started");
}
PERF_TS_T0();
@@ -304,7 +280,7 @@ DBTManager::DBTManager(const BTMode btMode)
const uint16_t revision = get_uint16(data, 1, true /* littleEndian */);
INFO_PRINT("Bluetooth version %d.%d", version, revision);
if( version < 1 ) {
- ERR_PRINT("Bluetooth version >= 1.0 required")
+ ERR_PRINT("Bluetooth version >= 1.0 required");
goto fail;
}
}
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index 70efdba3..bfd24530 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -53,6 +53,13 @@ extern "C" {
#define PERF2_TS_TD(m)
#endif
+// #define GATT_PRINT_ON 1
+#ifdef GATT_PRINT_ON
+ #define GATT_PRINT(...) PLAIN_PRINT(__VA_ARGS__)
+#else
+ #define GATT_PRINT(...)
+#endif
+
#include "BasicAlgos.hpp"
#include "L2CAPIoctl.hpp"
@@ -171,7 +178,7 @@ void GATTHandler::l2capReaderThreadImpl() {
const std::lock_guard<std::mutex> lock(mtx_l2capReaderInit); // RAII-style acquire and relinquish via destructor
l2capReaderShallStop = false;
l2capReaderRunning = true;
- INFO_PRINT("l2capReaderThreadImpl Started");
+ DBG_PRINT("l2capReaderThreadImpl Started");
cv_l2capReaderInit.notify_all();
}
@@ -190,7 +197,7 @@ void GATTHandler::l2capReaderThreadImpl() {
if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_NTF == opc ) {
const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU);
- DBG_PRINT("GATTHandler: NTF: %s, listener %zd", a->toString().c_str(), characteristicListenerList.size());
+ GATT_PRINT("GATTHandler: NTF: %s, listener %zd", a->toString().c_str(), characteristicListenerList.size());
GATTCharacteristicRef decl = findCharacterisicsByValueHandle(a->getHandle());
const std::shared_ptr<TROOctets> data(new POctets(a->getValue()));
const uint64_t timestamp = a->ts_creation;
@@ -210,14 +217,12 @@ void GATTHandler::l2capReaderThreadImpl() {
attPDU = nullptr;
} else if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_IND == opc ) {
const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU);
- DBG_PRINT("GATTHandler: IND: %s, sendIndicationConfirmation %d, listener %zd", a->toString().c_str(),
- sendIndicationConfirmation, characteristicListenerList.size());
+ GATT_PRINT("GATTHandler: IND: %s, sendIndicationConfirmation %d, listener %zd", a->toString().c_str(), sendIndicationConfirmation, characteristicListenerList.size());
bool cfmSent = false;
if( sendIndicationConfirmation ) {
AttHandleValueCfm cfm;
send(cfm);
cfmSent = true;
- DBG_PRINT("GATTHandler: CFM send: %s, confirmationSent %d", cfm.toString().c_str(), cfmSent);
}
GATTCharacteristicRef decl = findCharacterisicsByValueHandle(a->getHandle());
const std::shared_ptr<TROOctets> data(new POctets(a->getValue()));
@@ -310,7 +315,6 @@ bool GATTHandler::connect() {
while( false == l2capReaderRunning ) {
cv_l2capReaderInit.wait(lock);
}
- DBG_PRINT("GATTHandler::connect: Reader Started");
}
// First point of failure if device exposes no GATT functionality. Allow a longer timeout!
@@ -435,7 +439,6 @@ uint16_t GATTHandler::exchangeMTU(const uint16_t clientMaxMTU, const int timeout
std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, timeout);
if( nullptr != pdu ) {
- DBG_PRINT("GATT recv: %s", pdu->toString().c_str());
if( pdu->getOpcode() == AttPDUMsg::ATT_EXCHANGE_MTU_RSP ) {
const AttExchangeMTU * p = static_cast<const AttExchangeMTU*>(pdu.get());
mtu = p->getMTUSize();
@@ -508,11 +511,11 @@ bool GATTHandler::discoverPrimaryServices(std::vector<GATTServiceRef> & result)
result.clear();
while(!done) {
const AttReadByNTypeReq req(true /* group */, startHandle, 0xffff, groupType);
- DBG_PRINT("GATT PRIM SRV discover send: %s", req.toString().c_str());
+ GATT_PRINT("GATT PRIM SRV discover send: %s", req.toString().c_str());
std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS);
if( nullptr != pdu ) {
- DBG_PRINT("GATT PRIM SRV discover recv: %s", pdu->toString().c_str());
+ GATT_PRINT("GATT PRIM SRV discover recv: %s", pdu->toString().c_str());
if( pdu->getOpcode() == AttPDUMsg::ATT_READ_BY_GROUP_TYPE_RSP ) {
const AttReadByGroupTypeRsp * p = static_cast<const AttReadByGroupTypeRsp*>(pdu.get());
const int count = p->getElementCount();
@@ -525,7 +528,7 @@ bool GATTHandler::discoverPrimaryServices(std::vector<GATTServiceRef> & result)
p->pdu.get_uint16(ePDUOffset + 2), // end-handle
p->pdu.get_uuid( ePDUOffset + 2 + 2, uuid_t::toTypeSize(esz-2-2) ) // uuid
) ) );
- DBG_PRINT("GATT PRIM SRV discovered[%d/%d]: %s", i, count, result.at(result.size()-1)->toString().c_str());
+ GATT_PRINT("GATT PRIM SRV discovered[%d/%d]: %s", i, count, result.at(result.size()-1)->toString().c_str());
}
startHandle = p->getElementEndHandle(count-1);
if( startHandle < 0xffff ) {
@@ -561,7 +564,7 @@ bool GATTHandler::discoverCharacteristics(GATTServiceRef & service) {
*/
const uuid16_t characteristicTypeReq = uuid16_t(GattAttributeType::CHARACTERISTIC);
const std::lock_guard<std::recursive_mutex> lock(mtx_command); // RAII-style acquire and relinquish via destructor
- DBG_PRINT("GATT discoverCharacteristics Service: %s", service->toString().c_str());
+ GATT_PRINT("GATT discoverCharacteristics Service: %s", service->toString().c_str());
PERF_TS_T0();
@@ -570,11 +573,11 @@ bool GATTHandler::discoverCharacteristics(GATTServiceRef & service) {
service->characteristicList.clear();
while(!done) {
const AttReadByNTypeReq req(false /* group */, handle, service->endHandle, characteristicTypeReq);
- DBG_PRINT("GATT C discover send: %s", req.toString().c_str());
+ GATT_PRINT("GATT C discover send: %s", req.toString().c_str());
std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS);
if( nullptr != pdu ) {
- DBG_PRINT("GATT C discover recv: %s", pdu->toString().c_str());
+ GATT_PRINT("GATT C discover recv: %s", pdu->toString().c_str());
if( pdu->getOpcode() == AttPDUMsg::ATT_READ_BY_TYPE_RSP ) {
const AttReadByTypeRsp * p = static_cast<const AttReadByTypeRsp*>(pdu.get());
const int e_count = p->getElementCount();
@@ -591,7 +594,7 @@ bool GATTHandler::discoverCharacteristics(GATTServiceRef & service) {
static_cast<GATTCharacteristic::PropertyBitVal>(p->pdu.get_uint8(ePDUOffset + 2)), // Characteristics Property
p->pdu.get_uint16(ePDUOffset + 2 + 1), // Characteristics Value Handle
p->pdu.get_uuid(ePDUOffset + 2 + 1 + 2, uuid_t::toTypeSize(esz-2-1-2) ) ) ) ); // Characteristics Value Type UUID
- DBG_PRINT("GATT C discovered[%d/%d]: %s", e_iter, e_count, service->characteristicList.at(service->characteristicList.size()-1)->toString().c_str());
+ GATT_PRINT("GATT C discovered[%d/%d]: %s", e_iter, e_count, service->characteristicList.at(service->characteristicList.size()-1)->toString().c_str());
}
handle = p->getElementHandle(e_count-1); // Last Characteristic Handle
if( handle < service->endHandle ) {
@@ -624,7 +627,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) {
* BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1 Characteristic Declaration Attribute Value
* </p>
*/
- DBG_PRINT("GATT discoverDescriptors Service: %s", service->toString().c_str());
+ GATT_PRINT("GATT discoverDescriptors Service: %s", service->toString().c_str());
const std::lock_guard<std::recursive_mutex> lock(mtx_command); // RAII-style acquire and relinquish via destructor
PERF_TS_T0();
@@ -633,7 +636,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) {
for(int charIter=0; !done && charIter < charCount; charIter++ ) {
GATTCharacteristicRef charDecl = service->characteristicList[charIter];
charDecl->clearDescriptors();
- DBG_PRINT("GATT discoverDescriptors Characteristic[%d/%d]: %s", charIter, charCount, charDecl->toString().c_str());
+ GATT_PRINT("GATT discoverDescriptors Characteristic[%d/%d]: %s", charIter, charCount, charDecl->toString().c_str());
uint16_t cd_handle_iter = charDecl->value_handle + 1; // Start @ Characteristic Value Handle + 1
uint16_t cd_handle_end;
@@ -645,7 +648,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) {
while( !done && cd_handle_iter <= cd_handle_end ) {
const AttFindInfoReq req(cd_handle_iter, cd_handle_end);
- DBG_PRINT("GATT CD discover send: %s", req.toString().c_str());
+ GATT_PRINT("GATT CD discover send: %s", req.toString().c_str());
std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS);
if( nullptr == pdu ) {
@@ -653,7 +656,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) {
done = true;
break;
}
- DBG_PRINT("GATT CD discover recv: %s", pdu->toString().c_str());
+ GATT_PRINT("GATT CD discover recv: %s", pdu->toString().c_str());
if( pdu->getOpcode() == AttPDUMsg::ATT_FIND_INFORMATION_RSP ) {
const AttFindInfoRsp * p = static_cast<const AttFindInfoRsp*>(pdu.get());
@@ -685,7 +688,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) {
charDecl->clientCharacteristicsConfigIndex = charDecl->descriptorList.size();
}
charDecl->descriptorList.push_back(cd);
- DBG_PRINT("GATT CD discovered[%d/%d]: %s", e_iter, e_count, cd->toString().c_str());
+ GATT_PRINT("GATT CD discovered[%d/%d]: %s", e_iter, e_count, cd->toString().c_str());
}
cd_handle_iter = p->getElementHandle(e_count-1); // Last Descriptor Handle
if( cd_handle_iter < cd_handle_end ) {
@@ -707,12 +710,12 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) {
}
bool GATTHandler::readDescriptorValue(GATTDescriptor & desc, int expectedLength) {
- DBG_PRINT("GATTHandler::readDescriptorValue expLen %d, desc %s", expectedLength, desc.toString().c_str());
+ GATT_PRINT("GATTHandler::readDescriptorValue expLen %d, desc %s", expectedLength, desc.toString().c_str());
return readValue(desc.handle, desc.value, expectedLength);
}
bool GATTHandler::readCharacteristicValue(const GATTCharacteristic & decl, POctets & res, int expectedLength) {
- DBG_PRINT("GATTHandler::readCharacteristicValue expLen %d, decl %s", expectedLength, decl.toString().c_str());
+ GATT_PRINT("GATTHandler::readCharacteristicValue expLen %d, decl %s", expectedLength, decl.toString().c_str());
return readValue(decl.value_handle, res, expectedLength);
}
@@ -725,7 +728,7 @@ bool GATTHandler::readValue(const uint16_t handle, POctets & res, int expectedLe
bool done=false;
int offset=0;
- DBG_PRINT("GATTHandler::readValue expLen %d, handle %s", expectedLength, uint16HexString(handle).c_str());
+ GATT_PRINT("GATTHandler::readValue expLen %d, handle %s", expectedLength, uint16HexString(handle).c_str());
while(!done) {
if( 0 < expectedLength && expectedLength <= offset ) {
@@ -738,16 +741,16 @@ bool GATTHandler::readValue(const uint16_t handle, POctets & res, int expectedLe
if( 0 == offset ) {
const AttReadReq req (handle);
- DBG_PRINT("GATT RV send: %s", req.toString().c_str());
+ GATT_PRINT("GATT RV send: %s", req.toString().c_str());
pdu = sendWithReply(req, replyTimeoutMS);
} else {
const AttReadBlobReq req (handle, offset);
- DBG_PRINT("GATT RV send: %s", req.toString().c_str());
+ GATT_PRINT("GATT RV send: %s", req.toString().c_str());
pdu = sendWithReply(req, replyTimeoutMS);
}
if( nullptr != pdu ) {
- DBG_PRINT("GATT RV recv: %s", pdu->toString().c_str());
+ GATT_PRINT("GATT RV recv: %s", pdu->toString().c_str());
if( pdu->getOpcode() == AttPDUMsg::ATT_READ_RSP ) {
const AttReadRsp * p = static_cast<const AttReadRsp*>(pdu.get());
const TOctetSlice & v = p->getValue();
@@ -803,18 +806,18 @@ bool GATTHandler::writeDescriptorValue(const GATTDescriptor & cd) {
/* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value */
/* BT Core Spec v5.2: Vol 3, Part G GATT: 4.11 Characteristic Value Indication */
/* BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.3 Write Characteristic Descriptor */
- DBG_PRINT("GATTHandler::writeDesccriptorValue desc %s", cd.toString().c_str());
+ GATT_PRINT("GATTHandler::writeDesccriptorValue desc %s", cd.toString().c_str());
return writeValue(cd.handle, cd.value, true);
}
bool GATTHandler::writeCharacteristicValue(const GATTCharacteristic & c, const TROOctets & value) {
/* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value */
- DBG_PRINT("GATTHandler::writeCharacteristicValue desc %s, value %s", c.toString().c_str(), value.toString().c_str());
+ GATT_PRINT("GATTHandler::writeCharacteristicValue desc %s, value %s", c.toString().c_str(), value.toString().c_str());
return writeValue(c.value_handle, value, true);
}
bool GATTHandler::writeCharacteristicValueNoResp(const GATTCharacteristic & c, const TROOctets & value) {
- DBG_PRINT("GATT writeCharacteristicValueNoResp decl %s, value %s", c.toString().c_str(), value.toString().c_str());
+ GATT_PRINT("GATT writeCharacteristicValueNoResp decl %s, value %s", c.toString().c_str(), value.toString().c_str());
return writeValue(c.value_handle, value, false);
}
@@ -834,7 +837,7 @@ bool GATTHandler::writeValue(const uint16_t handle, const TROOctets & value, con
PERF2_TS_T0();
AttWriteReq req(handle, value);
- DBG_PRINT("GATT WV send(resp %d): %s", expResponse, req.toString().c_str());
+ GATT_PRINT("GATT WV send(resp %d): %s", expResponse, req.toString().c_str());
if( !expResponse ) {
send( req );
@@ -844,7 +847,7 @@ bool GATTHandler::writeValue(const uint16_t handle, const TROOctets & value, con
bool res = false;
std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS);
if( nullptr != pdu ) {
- DBG_PRINT("GATT WV recv: %s", pdu->toString().c_str());
+ GATT_PRINT("GATT WV recv: %s", pdu->toString().c_str());
if( pdu->getOpcode() == AttPDUMsg::ATT_WRITE_RSP ) {
// OK
res = true;
@@ -867,7 +870,7 @@ bool GATTHandler::configNotificationIndication(GATTDescriptor & cccd, const bool
}
/* BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration */
const uint16_t ccc_value = enableNotification | ( enableIndication << 1 );
- DBG_PRINT("GATTHandler::configNotificationIndication decl %s, enableNotification %d, enableIndication %d",
+ GATT_PRINT("GATTHandler::configNotificationIndication decl %s, enableNotification %d, enableIndication %d",
cccd.toString().c_str(), enableNotification, enableIndication);
cccd.value.resize(2, 2);
cccd.value.put_uint16(0, ccc_value);
diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp
index b7054f67..e0a37338 100644
--- a/src/direct_bt/L2CAPComm.cpp
+++ b/src/direct_bt/L2CAPComm.cpp
@@ -47,7 +47,6 @@ extern "C" {
#include <signal.h>
}
-// #define VERBOSE_ON 1
#include <dbt_debug.hpp>
using namespace direct_bt;
@@ -108,12 +107,12 @@ bool L2CAPComm::connect() {
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(), deviceString.c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, true);
return true;
}
hasIOError = false;
DBG_PRINT("L2CAPComm::connect: Start: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, true);
sockaddr_l2 req;
int err, res;
@@ -138,8 +137,7 @@ bool L2CAPComm::connect() {
// blocking
res = ::connect(_dd, (struct sockaddr*)&req, sizeof(req));
- DBG_PRINT("L2CAPComm::connect: Result %d, errno 0%X %s, %s",
- res, errno, strerror(errno), deviceString.c_str().c_str());
+ DBG_PRINT("L2CAPComm::connect: Result %d, errno 0%X %s, %s", res, errno, strerror(errno), deviceString.c_str());
if( !res )
{
@@ -177,12 +175,12 @@ bool L2CAPComm::disconnect() {
bool expConn = true; // C++11, exp as value since C++20
if( !isConnected.compare_exchange_strong(expConn, false) ) {
DBG_PRINT("L2CAPComm::disconnect: Not connected: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, true);
return false;
}
hasIOError = false;
DBG_PRINT("L2CAPComm::disconnect: Start: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), deviceString.c_str(), psm, cid, true);
interruptFlag = true;
// interrupt L2CAP ::connect(..), avoiding prolonged hang