diff options
author | Sven Gothel <[email protected]> | 2020-08-28 01:21:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-08-28 01:21:03 +0200 |
commit | 0a0b3285f6790914dc06a02b642c9539701222c5 (patch) | |
tree | c1030094bfb41f79e3d4e8d41b7f3a43b0195664 | |
parent | 7d855e9503729bf1b433e4aa91a8ca869119653a (diff) |
DBTManager, HCIHandler, GATTHandler: Move local environment debug flags to their respective singleton holder for efficacy
This avoids retrieving the property more than once, thanks to the new singleton environment holder
-rw-r--r-- | api/direct_bt/DBTManager.hpp | 8 | ||||
-rw-r--r-- | api/direct_bt/GATTHandler.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/HCIHandler.hpp | 4 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 20 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 59 | ||||
-rw-r--r-- | src/direct_bt/HCIHandler.cpp | 21 |
6 files changed, 63 insertions, 53 deletions
diff --git a/api/direct_bt/DBTManager.hpp b/api/direct_bt/DBTManager.hpp index 1ef938d6..9fca40f9 100644 --- a/api/direct_bt/DBTManager.hpp +++ b/api/direct_bt/DBTManager.hpp @@ -57,6 +57,9 @@ namespace direct_bt { MgmtEnv(); public: + /** Global Debug flag, retrieved first to triggers DBTEnv initialization. */ + const bool DEBUG_GLOBAL; + /** Poll timeout for mgmt reader thread, defaults to 10s. */ const int32_t MGMT_READER_THREAD_POLL_TIMEOUT; /** Timeout for mgmt command replies, defaults to 3s. */ @@ -65,6 +68,9 @@ namespace direct_bt { /** Small ringbuffer capacity for synchronized commands, defaults to 64 messages. */ const int32_t MGMT_EVT_RING_CAPACITY; + /** Debug all Mgmt event communication */ + const bool DEBUG_EVENT; + private: /** Maximum number of packets to wait for until matching a sequential command. Won't block as timeout will limit. */ const int32_t MGMT_READ_PACKET_MAX_RETRY; @@ -119,8 +125,6 @@ namespace direct_bt { std::vector<std::shared_ptr<WhitelistElem>> whitelist; const MgmtEnv & env; - const bool debug_global; // only to trigger DBTEnv initialization first - const bool debug_event; const BTMode btMode; POctets rbuffer; HCIComm comm; diff --git a/api/direct_bt/GATTHandler.hpp b/api/direct_bt/GATTHandler.hpp index 009d431b..90f22eac 100644 --- a/api/direct_bt/GATTHandler.hpp +++ b/api/direct_bt/GATTHandler.hpp @@ -76,6 +76,9 @@ namespace direct_bt { /** Medium ringbuffer capacity, defaults to 128 messages. */ const int32_t ATTPDU_RING_CAPACITY; + /** Debug all GATT Data communication */ + const bool DEBUG_DATA; + public: static GATTEnv& get() { /** @@ -118,7 +121,6 @@ namespace direct_bt { private: const GATTEnv & env; - const bool debug_data; /** GATTHandle's device weak back-reference */ std::weak_ptr<DBTDevice> wbr_device; diff --git a/api/direct_bt/HCIHandler.hpp b/api/direct_bt/HCIHandler.hpp index 6790740b..9c53caac 100644 --- a/api/direct_bt/HCIHandler.hpp +++ b/api/direct_bt/HCIHandler.hpp @@ -112,6 +112,9 @@ namespace direct_bt { /** Small ringbuffer capacity for synchronized commands, defaults to 64 messages. */ const int32_t HCI_EVT_RING_CAPACITY; + /** Debug all HCI event communication */ + const bool DEBUG_EVENT; + private: /** Maximum number of packets to wait for until matching a sequential command. Won't block as timeout will limit. */ const int32_t HCI_READ_PACKET_MAX_RETRY; @@ -157,7 +160,6 @@ namespace direct_bt { static MgmtEvent::Opcode translate(HCIEventType evt, HCIMetaEventType met); const HCIEnv & env; - const bool debug_event; const BTMode btMode; const uint16_t dev_id; POctets rbuffer; diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index 0a708a16..3cd35ddb 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -52,9 +52,11 @@ extern "C" { using namespace direct_bt; MgmtEnv::MgmtEnv() -: MGMT_READER_THREAD_POLL_TIMEOUT( DBTEnv::getInt32Property("direct_bt.mgmt.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ), +: DEBUG_GLOBAL( DBTEnv::get().DEBUG ), + MGMT_READER_THREAD_POLL_TIMEOUT( DBTEnv::getInt32Property("direct_bt.mgmt.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ), MGMT_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.mgmt.cmd.timeout", 3000, 1500 /* min */, INT32_MAX /* max */) ), MGMT_EVT_RING_CAPACITY( DBTEnv::getInt32Property("direct_bt.mgmt.ringsize", 64, 64 /* min */, 1024 /* max */) ), + DEBUG_EVENT( DBTEnv::getBooleanProperty("direct_bt.debug.manager.event", false) ), MGMT_READ_PACKET_MAX_RETRY( MGMT_EVT_RING_CAPACITY ) { } @@ -90,7 +92,7 @@ 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 ) { - COND_PRINT(debug_event, "DBTManager-IO RECV (CMD) %s", event->toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "DBTManager-IO RECV (CMD) %s", event->toString().c_str()); if( mgmtEventRing.isFull() ) { const int dropCount = mgmtEventRing.capacity()/4; mgmtEventRing.drop(dropCount); @@ -99,7 +101,7 @@ void DBTManager::mgmtReaderThreadImpl() { mgmtEventRing.putBlocking( event ); } else { // issue a callback - COND_PRINT(debug_event, "DBTManager-IO RECV (CB) %s", event->toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "DBTManager-IO RECV (CB) %s", event->toString().c_str()); sendMgmtEvent(event); } } else if( ETIMEDOUT != errno && !mgmtReaderShallStop ) { // expected exits @@ -129,7 +131,7 @@ void DBTManager::sendMgmtEvent(std::shared_ptr<MgmtEvent> event) { invokeCount++; } } - COND_PRINT(debug_event, "DBTManager::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); + COND_PRINT(env.DEBUG_EVENT, "DBTManager::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); (void)invokeCount; } @@ -163,7 +165,7 @@ static void mgmthandler_sigaction(int sig, siginfo_t *info, void *ucontext) { 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 { - COND_PRINT(debug_event, "DBTManager-IO SENT %s", req.toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "DBTManager-IO SENT %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()); @@ -183,11 +185,11 @@ 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. - COND_PRINT(debug_event, "DBTManager-IO RECV sendWithReply: res mismatch (drop evt, retryCount %d): res %s; req %s", + COND_PRINT(env.DEBUG_EVENT, "DBTManager-IO RECV sendWithReply: res mismatch (drop evt, retryCount %d): res %s; req %s", retryCount, res->toString().c_str(), req.toString().c_str()); retryCount++; } else { - COND_PRINT(debug_event, "DBTManager-IO RECV sendWithReply: res %s; req %s", res->toString().c_str(), req.toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "DBTManager-IO RECV sendWithReply: res %s; req %s", res->toString().c_str(), req.toString().c_str()); return res; } } @@ -251,8 +253,6 @@ void DBTManager::shutdownAdapter(const uint16_t dev_id) { DBTManager::DBTManager(const BTMode btMode) : env(MgmtEnv::get()), - debug_global(DBTEnv::get().DEBUG), - debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.manager.event", false)), btMode(btMode), rbuffer(ClientMaxMTU), comm(HCI_DEV_NONE, HCI_CHANNEL_CONTROL), mgmtEventRing(env.MGMT_EVT_RING_CAPACITY), mgmtReaderRunning(false), mgmtReaderShallStop(false) { @@ -374,7 +374,7 @@ next1: } if( ok ) { - if( debug_event ) { + if( env.DEBUG_EVENT ) { addMgmtEventCallback(-1, MgmtEvent::Opcode::CLASS_OF_DEV_CHANGED, bindMemberFunc(this, &DBTManager::mgmtEvClassOfDeviceChangedCB)); addMgmtEventCallback(-1, MgmtEvent::Opcode::DISCOVERING, bindMemberFunc(this, &DBTManager::mgmtEvDeviceDiscoveringCB)); addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_FOUND, bindMemberFunc(this, &DBTManager::mgmtEvDeviceFoundCB)); diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index ccdf2f82..cc2efc60 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -70,7 +70,8 @@ GATTEnv::GATTEnv() GATT_READ_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.gatt.cmd.read.timeout", 500, 250 /* min */, INT32_MAX /* max */) ), GATT_WRITE_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.gatt.cmd.write.timeout", 500, 250 /* min */, INT32_MAX /* max */) ), GATT_INITIAL_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.gatt.cmd.init.timeout", 2500, 2000 /* min */, INT32_MAX /* max */) ), - ATTPDU_RING_CAPACITY( DBTEnv::getInt32Property("direct_bt.gatt.ringsize", 128, 64 /* min */, 1024 /* max */) ) + ATTPDU_RING_CAPACITY( DBTEnv::getInt32Property("direct_bt.gatt.ringsize", 128, 64 /* min */, 1024 /* max */) ), + DEBUG_DATA( DBTEnv::getBooleanProperty("direct_bt.debug.gatt.data", false) ) { } @@ -198,7 +199,7 @@ void GATTHandler::l2capReaderThreadImpl() { if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_NTF == opc ) { const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU); - COND_PRINT(debug_data, "GATTHandler: NTF: %s, listener %zd", a->toString().c_str(), characteristicListenerList.size()); + COND_PRINT(env.DEBUG_DATA, "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; @@ -218,7 +219,7 @@ void GATTHandler::l2capReaderThreadImpl() { attPDU = nullptr; } else if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_IND == opc ) { const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU); - COND_PRINT(debug_data, "GATTHandler: IND: %s, sendIndicationConfirmation %d, listener %zd", a->toString().c_str(), sendIndicationConfirmation, characteristicListenerList.size()); + COND_PRINT(env.DEBUG_DATA, "GATTHandler: IND: %s, sendIndicationConfirmation %d, listener %zd", a->toString().c_str(), sendIndicationConfirmation, characteristicListenerList.size()); bool cfmSent = false; if( sendIndicationConfirmation ) { AttHandleValueCfm cfm; @@ -266,7 +267,7 @@ void GATTHandler::l2capReaderThreadImpl() { } GATTHandler::GATTHandler(const std::shared_ptr<DBTDevice> &device) -: env(GATTEnv::get()), debug_data(DBTEnv::getBooleanProperty("direct_bt.debug.gatt.data", false)), +: env(GATTEnv::get()), wbr_device(device), deviceString(device->getAddressString()), rbuffer(number(Defaults::MAX_ATT_MTU)), l2cap(device, L2CAP_PSM_UNDEF, L2CAP_CID_ATT), isConnected(false), hasIOError(false), @@ -511,11 +512,11 @@ bool GATTHandler::discoverPrimaryServices(std::vector<GATTServiceRef> & result) result.clear(); while(!done) { const AttReadByNTypeReq req(true /* group */, startHandle, 0xffff, groupType); - COND_PRINT(debug_data, "GATT PRIM SRV discover send: %s", req.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT PRIM SRV discover send: %s", req.toString().c_str()); std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, env.GATT_READ_COMMAND_REPLY_TIMEOUT); if( nullptr != pdu ) { - COND_PRINT(debug_data, "GATT PRIM SRV discover recv: %s", pdu->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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(); @@ -528,7 +529,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 ) ) ); - COND_PRINT(debug_data, "GATT PRIM SRV discovered[%d/%d]: %s", i, count, result.at(result.size()-1)->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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 ) { @@ -564,7 +565,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 - COND_PRINT(debug_data, "GATT discoverCharacteristics Service: %s", service->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT discoverCharacteristics Service: %s", service->toString().c_str()); PERF_TS_T0(); @@ -573,11 +574,11 @@ bool GATTHandler::discoverCharacteristics(GATTServiceRef & service) { service->characteristicList.clear(); while(!done) { const AttReadByNTypeReq req(false /* group */, handle, service->endHandle, characteristicTypeReq); - COND_PRINT(debug_data, "GATT C discover send: %s", req.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT C discover send: %s", req.toString().c_str()); std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, env.GATT_READ_COMMAND_REPLY_TIMEOUT); if( nullptr != pdu ) { - COND_PRINT(debug_data, "GATT C discover recv: %s", pdu->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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(); @@ -594,7 +595,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 - COND_PRINT(debug_data, "GATT C discovered[%d/%d]: %s", e_iter, e_count, service->characteristicList.at(service->characteristicList.size()-1)->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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 ) { @@ -627,7 +628,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { * BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1 Characteristic Declaration Attribute Value * </p> */ - COND_PRINT(debug_data, "GATT discoverDescriptors Service: %s", service->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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(); @@ -636,7 +637,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { for(int charIter=0; !done && charIter < charCount; charIter++ ) { GATTCharacteristicRef charDecl = service->characteristicList[charIter]; charDecl->clearDescriptors(); - COND_PRINT(debug_data, "GATT discoverDescriptors Characteristic[%d/%d]: %s", charIter, charCount, charDecl->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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; @@ -648,7 +649,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { while( !done && cd_handle_iter <= cd_handle_end ) { const AttFindInfoReq req(cd_handle_iter, cd_handle_end); - COND_PRINT(debug_data, "GATT CD discover send: %s", req.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT CD discover send: %s", req.toString().c_str()); std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, env.GATT_READ_COMMAND_REPLY_TIMEOUT); if( nullptr == pdu ) { @@ -656,7 +657,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { done = true; break; } - COND_PRINT(debug_data, "GATT CD discover recv: %s", pdu->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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()); @@ -688,7 +689,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { charDecl->clientCharacteristicsConfigIndex = charDecl->descriptorList.size(); } charDecl->descriptorList.push_back(cd); - COND_PRINT(debug_data, "GATT CD discovered[%d/%d]: %s", e_iter, e_count, cd->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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 ) { @@ -710,12 +711,12 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { } bool GATTHandler::readDescriptorValue(GATTDescriptor & desc, int expectedLength) { - COND_PRINT(debug_data, "GATTHandler::readDescriptorValue expLen %d, desc %s", expectedLength, desc.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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) { - COND_PRINT(debug_data, "GATTHandler::readCharacteristicValue expLen %d, decl %s", expectedLength, decl.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATTHandler::readCharacteristicValue expLen %d, decl %s", expectedLength, decl.toString().c_str()); return readValue(decl.value_handle, res, expectedLength); } @@ -728,7 +729,7 @@ bool GATTHandler::readValue(const uint16_t handle, POctets & res, int expectedLe bool done=false; int offset=0; - COND_PRINT(debug_data, "GATTHandler::readValue expLen %d, handle %s", expectedLength, uint16HexString(handle).c_str()); + COND_PRINT(env.DEBUG_DATA, "GATTHandler::readValue expLen %d, handle %s", expectedLength, uint16HexString(handle).c_str()); while(!done) { if( 0 < expectedLength && expectedLength <= offset ) { @@ -741,16 +742,16 @@ bool GATTHandler::readValue(const uint16_t handle, POctets & res, int expectedLe if( 0 == offset ) { const AttReadReq req (handle); - COND_PRINT(debug_data, "GATT RV send: %s", req.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT RV send: %s", req.toString().c_str()); pdu = sendWithReply(req, env.GATT_READ_COMMAND_REPLY_TIMEOUT); } else { const AttReadBlobReq req (handle, offset); - COND_PRINT(debug_data, "GATT RV send: %s", req.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT RV send: %s", req.toString().c_str()); pdu = sendWithReply(req, env.GATT_READ_COMMAND_REPLY_TIMEOUT); } if( nullptr != pdu ) { - COND_PRINT(debug_data, "GATT RV recv: %s", pdu->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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(); @@ -806,19 +807,19 @@ 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 */ - COND_PRINT(debug_data, "GATTHandler::writeDesccriptorValue desc %s", cd.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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 */ - COND_PRINT(debug_data, "GATTHandler::writeCharacteristicValue desc %s, value %s", c.toString().c_str(), value.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "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) { /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response */ - COND_PRINT(debug_data, "GATT writeCharacteristicValueNoResp decl %s, value %s", c.toString().c_str(), value.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT writeCharacteristicValueNoResp decl %s, value %s", c.toString().c_str(), value.toString().c_str()); return writeValue(c.value_handle, value, false); } @@ -839,7 +840,7 @@ bool GATTHandler::writeValue(const uint16_t handle, const TROOctets & value, con if( !withResponse ) { AttWriteCmd req(handle, value); - COND_PRINT(debug_data, "GATT WV send(resp %d): %s", withResponse, req.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT WV send(resp %d): %s", withResponse, req.toString().c_str()); send( req ); PERF2_TS_TD("GATT writeValue (no-resp)"); @@ -847,12 +848,12 @@ bool GATTHandler::writeValue(const uint16_t handle, const TROOctets & value, con } AttWriteReq req(handle, value); - COND_PRINT(debug_data, "GATT WV send(resp %d): %s", withResponse, req.toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT WV send(resp %d): %s", withResponse, req.toString().c_str()); bool res = false; std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, env.GATT_WRITE_COMMAND_REPLY_TIMEOUT); if( nullptr != pdu ) { - COND_PRINT(debug_data, "GATT WV recv: %s", pdu->toString().c_str()); + COND_PRINT(env.DEBUG_DATA, "GATT WV recv: %s", pdu->toString().c_str()); if( pdu->getOpcode() == AttPDUMsg::ATT_WRITE_RSP ) { // OK res = true; @@ -875,7 +876,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 ); - COND_PRINT(debug_data, "GATTHandler::configNotificationIndication decl %s, enableNotification %d, enableIndication %d", + COND_PRINT(env.DEBUG_DATA, "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/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp index 1ab32e69..24a8be32 100644 --- a/src/direct_bt/HCIHandler.cpp +++ b/src/direct_bt/HCIHandler.cpp @@ -59,6 +59,7 @@ HCIEnv::HCIEnv() HCI_COMMAND_STATUS_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.hci.cmd.status.timeout", 3000, 1500 /* min */, INT32_MAX /* max */) ), HCI_COMMAND_COMPLETE_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.hci.cmd.complete.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ), HCI_EVT_RING_CAPACITY( DBTEnv::getInt32Property("direct_bt.hci.ringsize", 64, 64 /* min */, 1024 /* max */) ), + DEBUG_EVENT( DBTEnv::getBooleanProperty("direct_bt.debug.hci.event", false) ), HCI_READ_PACKET_MAX_RETRY( HCI_EVT_RING_CAPACITY ) { } @@ -273,13 +274,13 @@ void HCIHandler::hciReaderThreadImpl() { const HCIMetaEventType mec = event->getMetaEventType(); if( HCIMetaEventType::INVALID != mec && !filter_test_metaev(mec) ) { // DROP - COND_PRINT(debug_event, "HCIHandler-IO RECV Drop (meta filter) %s", event->toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV Drop (meta filter) %s", event->toString().c_str()); continue; // next packet } if( event->isEvent(HCIEventType::CMD_STATUS) || event->isEvent(HCIEventType::CMD_COMPLETE) ) { - COND_PRINT(debug_event, "HCIHandler-IO RECV (CMD) %s", event->toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV (CMD) %s", event->toString().c_str()); if( hciEventRing.isFull() ) { const int dropCount = hciEventRing.capacity()/4; hciEventRing.drop(dropCount); @@ -291,7 +292,7 @@ void HCIHandler::hciReaderThreadImpl() { std::vector<std::shared_ptr<EInfoReport>> eirlist = EInfoReport::read_ad_reports(event->getParam(), event->getParamSize()); int i=0; for_each_idx(eirlist, [&](std::shared_ptr<EInfoReport> &eir) { - // COND_PRINT(debug_event, "HCIHandler-IO RECV (AD EIR) %s", eir->toString().c_str()); + // COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV (AD EIR) %s", eir->toString().c_str()); std::shared_ptr<MgmtEvent> mevent( new MgmtEvtDeviceFound(dev_id, eir) ); sendMgmtEvent( mevent ); i++; @@ -300,10 +301,10 @@ void HCIHandler::hciReaderThreadImpl() { // issue a callback for the translated event std::shared_ptr<MgmtEvent> mevent = translate(event); if( nullptr != mevent ) { - COND_PRINT(debug_event, "HCIHandler-IO RECV (CB) %s", event->toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV (CB) %s", event->toString().c_str()); sendMgmtEvent( mevent ); } else { - COND_PRINT(debug_event, "HCIHandler-IO RECV Drop (no translation) %s", event->toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV Drop (no translation) %s", event->toString().c_str()); } } } else if( ETIMEDOUT != errno && !hciReaderShallStop ) { // expected exits @@ -331,12 +332,12 @@ void HCIHandler::sendMgmtEvent(std::shared_ptr<MgmtEvent> event) { invokeCount++; } } - COND_PRINT(debug_event, "HCIHandler::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); + COND_PRINT(env.DEBUG_EVENT, "HCIHandler::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); (void)invokeCount; } bool HCIHandler::sendCommand(HCICommand &req) { - COND_PRINT(debug_event, "HCIHandler-IO SENT %s", req.toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO SENT %s", req.toString().c_str()); TROOctets & pdu = req.getPDU(); if ( comm.write( pdu.get_ptr(), pdu.getSize() ) < 0 ) { @@ -360,10 +361,10 @@ std::shared_ptr<HCIEvent> HCIHandler::getNextReply(HCICommand &req, int32_t & re // 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. retryCount++; - COND_PRINT(debug_event, "HCIHandler-IO RECV getNextReply: res mismatch (drop, retry %d): res %s; req %s", + COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV getNextReply: res mismatch (drop, retry %d): res %s; req %s", retryCount, ev->toString().c_str(), req.toString().c_str()); } else { - COND_PRINT(debug_event, "HCIHandler-IO RECV getNextReply: res %s; req %s", ev->toString().c_str(), req.toString().c_str()); + COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV getNextReply: res %s; req %s", ev->toString().c_str(), req.toString().c_str()); return ev; } } @@ -419,7 +420,7 @@ exit: } HCIHandler::HCIHandler(const BTMode btMode, const uint16_t dev_id) -: env(HCIEnv::get()), debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.hci.event", false)), +: env(HCIEnv::get()), btMode(btMode), dev_id(dev_id), rbuffer(HCI_MAX_MTU), comm(dev_id, HCI_CHANNEL_RAW), hciEventRing(env.HCI_EVT_RING_CAPACITY), hciReaderRunning(false), hciReaderShallStop(false) |