Skip to content

Handle ACL RX packet fragementation via buffer #16

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

Merged
Merged
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
31 changes: 30 additions & 1 deletion src/utility/HCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,37 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[])
uint16_t cid;
} *aclHdr = (HCIACLHdr*)pdata;

uint16_t aclFlags = (aclHdr->handle & 0xf000) >> 12;

if ((aclHdr->dlen - 4) != aclHdr->len) {
// packet is fragmented
if (aclFlags != 0x01) {
// copy into ACL buffer
memcpy(_aclPktBuffer, &_recvBuffer[1], sizeof(HCIACLHdr) + aclHdr->dlen - 4);
} else {
// copy next chunk into the buffer
HCIACLHdr* aclBufferHeader = (HCIACLHdr*)_aclPktBuffer;

memcpy(&_aclPktBuffer[sizeof(HCIACLHdr) + aclBufferHeader->dlen - 4], &_recvBuffer[1 + sizeof(aclHdr->handle) + sizeof(aclHdr->dlen)], aclHdr->dlen);

aclBufferHeader->dlen += aclHdr->dlen;
aclHdr = aclBufferHeader;
}
}

if ((aclHdr->dlen - 4) != aclHdr->len) {
// don't have the full packet yet
return;
}

if (aclHdr->cid == ATT_CID) {
ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
if (aclFlags == 0x01) {
// use buffered packet
ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_aclPktBuffer[sizeof(HCIACLHdr)]);
} else {
// use the recv buffer
ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
}
} else if (aclHdr->cid == SIGNALING_CID) {
L2CAPSignaling.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/utility/HCI.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class HCIClass {

uint8_t _maxPkt;
uint8_t _pendingPkt;

uint8_t _aclPktBuffer[255];
};

extern HCIClass HCI;
Expand Down