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

fix: ensure HCI send/receive buffers for ATT are large enough for max MTU length #323

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
15 changes: 10 additions & 5 deletions att_hci.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const (
gattClientCharacteristicConfigUUID = 0x2902
)

const (
maximumMTU = 248
maximumMTUBufferLen = maximumMTU + 8
)

var (
ErrATTTimeout = errors.New("bluetooth: ATT timeout")
ErrATTUnknownEvent = errors.New("bluetooth: ATT unknown event")
Expand Down Expand Up @@ -292,7 +297,7 @@ func newATT(hci *hci) *att {
lastHandle: 0x0001,
attributes: []rawAttribute{},
localServices: []rawService{},
maxMTU: 248,
maxMTU: maximumMTU,
}
}

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

func (a *att) handleReadByGroupReq(handle, start, end uint16, uuid shortUUID) error {
var response [64]byte
var response [maximumMTUBufferLen]byte
response[0] = attOpReadByGroupResponse
response[1] = 0x0 // length per service
pos := 2
Expand Down Expand Up @@ -818,7 +823,7 @@ func (a *att) handleReadByGroupReq(handle, start, end uint16, uuid shortUUID) er
}

func (a *att) handleReadByTypeReq(handle, start, end uint16, uuid shortUUID) error {
var response [64]byte
var response [maximumMTUBufferLen]byte
response[0] = attOpReadByTypeResponse
pos := 0

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

func (a *att) handleFindInfoReq(handle, start, end uint16) error {
var response [64]byte
var response [maximumMTUBufferLen]byte
response[0] = attOpFindInfoResponse
pos := 0

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

var response [64]byte
var response [maximumMTUBufferLen]byte
response[0] = attOpReadResponse
pos := 1

Expand Down
Loading