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

Lines changed: 30 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy