Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate dyamic sized arrays #141

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/utility/HCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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;
}

Expand All @@ -672,15 +673,15 @@ 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;
uint16_t opcode;
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);

Expand All @@ -705,6 +706,8 @@ int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters)
poll();
}

free(txBuffer);

return _cmdCompleteStatus;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utility/HCI.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ 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);

virtual void debug(Stream& stream);
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];
Expand Down