btleplug icon indicating copy to clipboard operation
btleplug copied to clipboard

Requesting MTU

Open robbym opened this issue 1 year ago • 5 comments
trafficstars

This PR will include a method to retrieve the negotiated MTU size on each platform.

Info grabbed from: https://github.com/deviceplug/btleplug/issues/246

Windows - GattSession.MaxPduSize Negotiation happens on user's behalf, and a GattSession.MaxPduSizeChanged event is emitted when MTU is updated.

macOS / iOS - CBPeripheral.maximumWriteValueLength Negotiation happens on user's behalf, have used peripheral.maximumWriteValueLength(for: .withoutResponse) reliably in the past. .withResponse has some issues. See here.

Linux Instead of a dedicated MTU property, BlueZ has decided to adopt the newer Bluetooth 5.2 standard. Example here: Link

Android - BluetoothGatt.requestMtu The way I understand it and have used it in the past, you call requestMtu with the largest you can support (e.g. 512), and it will negotiate the min(host.maxMtu, periph.maxMtu) and call onMtuChanged with the new mtu size.

TODO:

  • [x] Windows
  • [x] Linux
  • [ ] Android
  • [ ] macOS/iOS

robbym avatar Nov 12 '24 16:11 robbym

@robbym Hi, have you finish it on bluez?

laxian avatar Dec 11 '24 04:12 laxian

@laxian I just pushed a working bluez implementation. I tested it on one of my BLE devices and it works, but let me know if there is any issues.

@qwandor I added the constant and now moved it to the api namespace so that each implementation can use it. Not really happy with where it currently lives. Maybe move it to common?

robbym avatar Dec 20 '24 20:12 robbym

Windows parts of this are looking good so far. Would like to get all platforms in before we land it (otherwise I will have people on unsupported platforms yelling) but I'm fine to also do a point release whenever we get all the parts in.

qdot avatar Dec 21 '24 21:12 qdot

Converted this to a draft until we get all the platforms in. Just makes my life easier for the little amount of time I actually get to do triage on this project.

qdot avatar Dec 21 '24 22:12 qdot

One more quick update here: I brought us up to bluez-async 0.8.0 in v0.11.7, so mtu() is available now and we can drop that change here (it'll probably just skip the commit on rebase).

qdot avatar Dec 21 '24 22:12 qdot