Skip to content

Commit 31e1365

Browse files
committed
fix: ensure HCI send/receive buffers for ATT are large enough for maximum MTU length
Signed-off-by: deadprogram <[email protected]>
1 parent 62565e6 commit 31e1365

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

att_hci.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const (
6666
gattClientCharacteristicConfigUUID = 0x2902
6767
)
6868

69+
const (
70+
maximumMTU = 248
71+
maximumMTUBufferLen = maximumMTU + 8
72+
)
73+
6974
var (
7075
ErrATTTimeout = errors.New("bluetooth: ATT timeout")
7176
ErrATTUnknownEvent = errors.New("bluetooth: ATT unknown event")
@@ -292,7 +297,7 @@ func newATT(hci *hci) *att {
292297
lastHandle: 0x0001,
293298
attributes: []rawAttribute{},
294299
localServices: []rawService{},
295-
maxMTU: 248,
300+
maxMTU: maximumMTU,
296301
}
297302
}
298303

@@ -758,7 +763,7 @@ func (a *att) handleData(handle uint16, buf []byte) error {
758763
}
759764

760765
func (a *att) handleReadByGroupReq(handle, start, end uint16, uuid shortUUID) error {
761-
var response [64]byte
766+
var response [maximumMTUBufferLen]byte
762767
response[0] = attOpReadByGroupResponse
763768
response[1] = 0x0 // length per service
764769
pos := 2
@@ -818,7 +823,7 @@ func (a *att) handleReadByGroupReq(handle, start, end uint16, uuid shortUUID) er
818823
}
819824

820825
func (a *att) handleReadByTypeReq(handle, start, end uint16, uuid shortUUID) error {
821-
var response [64]byte
826+
var response [maximumMTUBufferLen]byte
822827
response[0] = attOpReadByTypeResponse
823828
pos := 0
824829

@@ -883,7 +888,7 @@ func (a *att) handleReadByTypeReq(handle, start, end uint16, uuid shortUUID) err
883888
}
884889

885890
func (a *att) handleFindInfoReq(handle, start, end uint16) error {
886-
var response [64]byte
891+
var response [maximumMTUBufferLen]byte
887892
response[0] = attOpFindInfoResponse
888893
pos := 0
889894

@@ -946,7 +951,7 @@ func (a *att) handleReadReq(handle, attrHandle uint16) error {
946951
return a.sendError(handle, attOpReadReq, attrHandle, attErrorAttrNotFound)
947952
}
948953

949-
var response [64]byte
954+
var response [maximumMTUBufferLen]byte
950955
response[0] = attOpReadResponse
951956
pos := 1
952957

0 commit comments

Comments
 (0)