--- answer for GATT only ---
the two option from hciconfig
cmd not for gatt mtu.
//meaning not very sure, practice does not work
一. api or cli
gatt mtu can be set in (by programing api, or cli)
- server: btgatt-server,
- client: btgatt-client, gatttool
//they all work as a demo instance, only set current instance, not global settings.
//cli
btgatt-server, btgatt-client
//only set in cmdline args
tools/btgatt-server --mtu 123 ..
tools/btgatt-client --mtu 123
//btgatt-server can seen mtu change, passively
[GATT server]# att: > 02 7b 00
[GATT server]# att: ATT PDU received: 0x02
server: MTU exchange complete, with MTU: 123
[GATT server]# att: ATT op 0x03
[GATT server]# att: < 03 05 02
gatttool
//gatttool (only set with result, no interface do query only)
//in cmdline arg
tools/gatttool --mtu 123 ..
//in runtime
tools/gatttool --interactive
[XX:XX:XX:XX:XX:XX][LE]> mtu 123
MTU was exchanged successfully: 123
[XX:XX:XX:XX:XX:XX][LE]> mtu 122
Command Failed: MTU exchange can only occur once per connection.
//in other app, it can be set many times.
//mtu <value> Exchange MTU for GATT/ATT
they all not provided query only interface yet (bluez-5.53),
you can change code implement one.
c api
//api
int mtu = 123;
server->gatt = bt_gatt_server_new(server->db, server->att, mtu, 0);
mtu = bt_att_get_mtu(server->att);
printf("--- get mtu: %d\n", mtu); // got 672 // wrong from L2CAP (on my test device
bt_att_set_mtu(server->att, 23); // conservative size
二. communication
or by communication
- gatt negotiation by
exchange mtu
// client send mtu req(with client mtu), server replay (with server mtu): then they use MIN of them.
// by default it's 23
// some ble test app, can change mtu in need at runtime.
- from link layer, L2CAP negotiate mtu.
NOTE:
in bluez, mtu from link layer (L2CAP) may overide mtu from gatt api.
and for BR/EDR link device, exchange mtu is disabled.
so, if L2CAP got wrong mtu, the communication may be abnormal.
三. Typical value
- 23 //min, default
- 517 //max from bluz
- 527 //max from some android device
if mtu is 23, gatt may split big packet into many small packets to transmit.
// should still work.