From 039df0a51d51d79b42461f916bc36a50723f1ac8 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 14 Nov 2020 14:05:47 +0000 Subject: [PATCH 1/3] Allocate dyamic sized arrays --- src/utility/HCI.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 773f4f18..583b5c5b 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -630,7 +630,7 @@ int HCIClass::sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data) uint16_t cid; } aclHdr = { HCI_ACLDATA_PKT, handle, uint8_t(plen + 4), plen, cid }; - uint8_t txBuffer[sizeof(aclHdr) + plen]; + uint8_t *txBuffer = uint8_t*malloc(sizeof(aclHdr) + plen); memcpy(txBuffer, &aclHdr, sizeof(aclHdr)); memcpy(&txBuffer[sizeof(aclHdr)], data, plen); @@ -648,7 +648,8 @@ int HCIClass::sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data) _pendingPkt++; HCITransport.write(txBuffer, sizeof(aclHdr) + plen); - + free(txBuffer); + return 0; } @@ -680,7 +681,7 @@ int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters) uint8_t plen; } pktHdr = {HCI_COMMAND_PKT, opcode, plen}; - uint8_t txBuffer[sizeof(pktHdr) + plen]; + uint8_t *txBuffer = uint8_t*malloc(sizeof(pktHdr) + plen); memcpy(txBuffer, &pktHdr, sizeof(pktHdr)); memcpy(&txBuffer[sizeof(pktHdr)], parameters, plen); @@ -705,6 +706,8 @@ int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters) poll(); } + free(txBuffer); + return _cmdCompleteStatus; } From 509dbafacb64f8386e64a55c87e3abffeff0c362 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 14 Nov 2020 14:17:48 +0000 Subject: [PATCH 2/3] Silly typo --- src/utility/HCI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 583b5c5b..a99ffaf1 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -630,7 +630,7 @@ int HCIClass::sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data) uint16_t cid; } aclHdr = { HCI_ACLDATA_PKT, handle, uint8_t(plen + 4), plen, cid }; - uint8_t *txBuffer = uint8_t*malloc(sizeof(aclHdr) + plen); + uint8_t* txBuffer = (uint8_t*)malloc(sizeof(aclHdr) + plen); memcpy(txBuffer, &aclHdr, sizeof(aclHdr)); memcpy(&txBuffer[sizeof(aclHdr)], data, plen); @@ -681,7 +681,7 @@ int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters) uint8_t plen; } pktHdr = {HCI_COMMAND_PKT, opcode, plen}; - uint8_t *txBuffer = uint8_t*malloc(sizeof(pktHdr) + plen); + uint8_t* txBuffer = (uint8_t*)malloc(sizeof(pktHdr) + plen); memcpy(txBuffer, &pktHdr, sizeof(pktHdr)); memcpy(&txBuffer[sizeof(pktHdr)], parameters, plen); From b9c1358b8b057cdd41361151057b3d6b50df2f70 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 14 Nov 2020 14:28:33 +0000 Subject: [PATCH 3/3] const corectness, and nullptr instead of NULL --- src/utility/HCI.cpp | 4 ++-- src/utility/HCI.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index a99ffaf1..6101a6c9 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -616,7 +616,7 @@ int HCIClass::tryResolveAddress(uint8_t* BDAddr, uint8_t* address){ return 0; } -int HCIClass::sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data) +int HCIClass::sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, const void* data) { while (_pendingPkt >= _maxPkt) { poll(); @@ -673,7 +673,7 @@ void HCIClass::noDebug() _debug = NULL; } -int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters) +int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, const void* parameters) { struct __attribute__ ((packed)) { uint8_t pktType; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index b8f88538..f07ed3d7 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -110,7 +110,7 @@ class HCIClass { virtual int writeLK(uint8_t peerAddress[], uint8_t LK[]); virtual int tryResolveAddress(uint8_t* BDAddr, uint8_t* address); - virtual int sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data); + virtual int sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, const void* data); virtual int disconnect(uint16_t handle); @@ -118,7 +118,7 @@ class HCIClass { virtual void noDebug(); // TODO: Send command be private again & use ATT implementation of send command within ATT. - virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); + virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, const void* parameters = nullptr); uint8_t remotePublicKeyBuffer[64]; uint8_t localPublicKeyBuffer[64]; uint8_t remoteDHKeyCheckBuffer[16];