From 5a9aa9913b10d5291f67062ef39ca16ea8985b4e Mon Sep 17 00:00:00 2001 From: devgianlu Date: Thu, 21 Aug 2025 19:00:30 +0200 Subject: [PATCH] linux: add MTU accessor --- gatts_linux.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gatts_linux.go b/gatts_linux.go index dad88b1b..4e6ff0d6 100644 --- a/gatts_linux.go +++ b/gatts_linux.go @@ -50,9 +50,17 @@ func (om *objectManager) GetManagedObjects() (map[dbus.ObjectPath]map[string]map type bluezChar struct { props *prop.Properties writeEvent func(client Connection, offset int, value []byte) + + mtu int } func (c *bluezChar) ReadValue(options map[string]dbus.Variant) ([]byte, *dbus.Error) { + if mtu, ok := options["mtu"]; ok { + // Store the MTU, so it can be retrieved later. + mtuValue := mtu.Value().(uint16) + c.mtu = int(mtuValue) + } + // TODO: should we use the offset value? The BlueZ documentation doesn't // clearly specify this. The go-bluetooth library doesn't, but I believe it // should be respected. @@ -61,6 +69,12 @@ func (c *bluezChar) ReadValue(options map[string]dbus.Variant) ([]byte, *dbus.Er } func (c *bluezChar) WriteValue(value []byte, options map[string]dbus.Variant) *dbus.Error { + if mtu, ok := options["mtu"]; ok { + // Store the MTU, so it can be retrieved later. + mtuValue := mtu.Value().(uint16) + c.mtu = int(mtuValue) + } + if c.writeEvent != nil { // BlueZ doesn't seem to tell who did the write, so pass 0 always as the // connection ID. @@ -168,3 +182,8 @@ func (c *Characteristic) Write(p []byte) (n int, err error) { } return len(p), nil } + +// MTU returns the exchanged MTU value, or zero if not available. +func (c *Characteristic) MTU() int { + return c.char.mtu +}