Skip to content

Commit 631f807

Browse files
committed
Handle ACL RX packet fragementation via buffer
1 parent 2eed8a5 commit 631f807

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/utility/HCI.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,37 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[])
498498
uint16_t cid;
499499
} *aclHdr = (HCIACLHdr*)pdata;
500500

501+
uint16_t aclFlags = (aclHdr->handle & 0xf000) >> 12;
502+
503+
if ((aclHdr->dlen - 4) != aclHdr->len) {
504+
// packet is fragmented
505+
if (aclFlags != 0x01) {
506+
// copy into ACL buffer
507+
memcpy(_aclPktBuffer, &_recvBuffer[1], sizeof(HCIACLHdr) + aclHdr->dlen - 4);
508+
} else {
509+
// copy next chunk into the buffer
510+
HCIACLHdr* aclBufferHeader = (HCIACLHdr*)_aclPktBuffer;
511+
512+
memcpy(&_aclPktBuffer[sizeof(HCIACLHdr) + aclBufferHeader->dlen - 4], &_recvBuffer[1 + sizeof(aclHdr->handle) + sizeof(aclHdr->dlen)], aclHdr->dlen);
513+
514+
aclBufferHeader->dlen += aclHdr->dlen;
515+
aclHdr = aclBufferHeader;
516+
}
517+
}
518+
519+
if ((aclHdr->dlen - 4) != aclHdr->len) {
520+
// don't have the full packet yet
521+
return;
522+
}
523+
501524
if (aclHdr->cid == ATT_CID) {
502-
ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
525+
if (aclFlags == 0x01) {
526+
// use buffered packet
527+
ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_aclPktBuffer[sizeof(HCIACLHdr)]);
528+
} else {
529+
// use the recv buffer
530+
ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
531+
}
503532
} else if (aclHdr->cid == SIGNALING_CID) {
504533
L2CAPSignaling.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
505534
} else {

src/utility/HCI.h

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class HCIClass {
9292

9393
uint8_t _maxPkt;
9494
uint8_t _pendingPkt;
95+
96+
uint8_t _aclPktBuffer[255];
9597
};
9698

9799
extern HCIClass HCI;

0 commit comments

Comments
 (0)