ukBaz / python-bluezero

A simple Python interface to Bluez
MIT License
387 stars 112 forks source link

iOS and MTU #346

Closed p30arena closed 2 years ago

p30arena commented 2 years ago

iOS doesn't support "Request MTU" and negotiates MTU on the connection stage. how can I set the MTU to 512 in bluezero?

ukBaz commented 2 years ago

Bluezero is built on top of the BlueZ D-Bus API which is documented at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

If you know how BlueZ gets access to that information then I can tell you how to do it in Bluezero. If you don't know how to do it with BlueZ then I'll need to know a little bit more about what your are doing. GATT central? GATT peripheral? Read? Write? Notify? For example.

p30arena commented 2 years ago

can I share with you a Qt code so you can better understand what I mean?

QLowEnergyController *leController = NULL;
...
leController->setProperty("MTU", 512);
...

If I don't set the MTU to 512, the iPhone selects 23 as preferred MTU and it is not negotiable after connection.

I think it is ATT MTU that should be changed, am a bit confused.

p30arena commented 2 years ago

iOS will not allow that you request the MTU size, but will always try to negotiate the highest possible MTU (iOS supports up to MTU size 185)

So there must be a way to tell the iOS that our MTU is higher than the default. Qt is also using Bluez.

ukBaz commented 2 years ago

MTU values are set in the GATT api if it is a GATT Server (peripheral) you are creating.

p30arena commented 2 years ago

sorry didn't mention it earlier! yes, it is GATT Server (peripheral).

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt#n297

so the MTU must be set on every characteristic?

p30arena commented 2 years ago

Qt seems to be ignoring

https://code.qt.io/cgit/qt/qtconnectivity.git/tree/src/bluetooth/qlowenergycontroller_bluez.cpp#n797

    case QBluezConst::AttCommand::ATT_OP_EXCHANGE_MTU_REQUEST:
        handleExchangeMtuRequest(incomingPacket);
        return;

https://code.qt.io/cgit/qt/qtconnectivity.git/tree/src/bluetooth/bluez

Qt is not using dbus to communicate with BlueZ.

p30arena commented 2 years ago

@ukBaz can I add it here?

https://github.com/ukBaz/python-bluezero/blob/main/bluezero/localGATT.py#L243 'MTU': 512

p30arena commented 2 years ago

I checked and saw that MTU is 182 so BlueZ does that automatically on a Bluetooth v5