Hi Gilles On 5 December 2016 at 23:57, Gilles Boccon-Gibod <[email protected]> wrote: > I am running a simple BLE app on an nRF52 DK board. > In it simplest mode, the app advertises a GATT server with a > WriteNoResponse characteristic. > When I write to this characteristic from a GATT client (a mac in my case), > my access callback is properly invoked, and I can get the characteristic > value when this value is "normal" (i.e no more than MTU-3 bytes). > For testing, I set the MTU to 23 with: > ble_att_set_preferred_mtu(23); > > I can verify that writing a 20 byte value works fine, as I get a callback > with ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR > > However, if I write a value that's 21 bytes or more, the callback is never > invoked. > At the GATT level, writing a long attribute involves different GATT > commands, namely BLE_ATT_OP_PREP_WRITE_REQ and BLE_ATT_OP_EXEC_WRITE_REQ, > instead of the one-shot BLE_ATT_OP_WRITE_REQ. > If I enable DEBUG logging, I can see that the BLE_ATT_OP_EXEC_WRITE_REQ is > received and processed, but there's no callback to my code. > > Here's what the log looks like (this is for a 21 bytes value, with the MTU > set at 23): >
According to Bluetooth Specification core v4.2 Vol 3, Part F Chapter 3.4.5.1 maximum attribute value you can send is ATT_MTU - 3. In your case it is 20. Basically 3 octets are consumed for opcode and attribute handle. Using long write in your case is what should be done. > 1687:[ts=13179676ssb, mod=64 level=1] mtu update event; conn_handle=1 cid=4 > mtu=23 > > ... > > > 58955:[ts=460585900ssb, mod=4 level=0] ble_hs_hci_evt_acl_process(): > handle=1 pb=2 len=27 data= > 0x17 0x00 0x04 0x00 0x16 0x16 0x00 0x00 0x00 0x01 0x02 0x03 0x04 0x05 0x06 > 0x07 0x08 0x09 0x0a > 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x12 > 58961:[ts=460632772ssb, mod=4 level=0] rxed att command: prep write req; > conn=1 handle=0x0016 o > ffset=0 > 58963:[ts=460648396ssb, mod=4 level=0] txed att command: prep write rsp; > conn=1 handle=0x0016 o > ffset=0 > 58966:[ts=460671832ssb, mod=4 level=0] host tx hci data; handle=1 length=27 > 58968:[ts=460687456ssb, mod=4 level=0] ble_hs_hci_acl_tx(): 0x01 0x00 0x1b > 0x00 0x17 0x00 0x04 > 0x00 0x17 0x16 0x00 0x00 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 > 0x0a 0x0b 0x0c 0x0d > 0x0e 0x0f 0x10 0x11 0x12 > 58976:[ts=460749952ssb, mod=4 level=0] ble_hs_hci_evt_acl_process(): > handle=1 pb=2 len=6 data=0 > x02 0x00 0x04 0x00 0x18 0x00 > 58979:[ts=460773388ssb, mod=4 level=0] rxed att command: exec write req; > conn=1 flags=0x00 > 58981:[ts=460789012ssb, mod=4 level=0] host tx hci data; handle=1 length=5 > 58983:[ts=460804636ssb, mod=4 level=0] ble_hs_hci_acl_tx(): 0x01 0x00 0x05 > 0x00 0x01 0x00 0x04 > 0x00 0x19 > 58986:[ts=460828072ssb, mod=4 level=0] Number of Completed Packets: > num_handles=1 > 58988:[ts=460843696ssb, mod=4 level=0] handle:1 pkts:1 > 58991:[ts=460867132ssb, mod=4 level=0] Number of Completed Packets: > num_handles=1 > 58993:[ts=460882756ssb, mod=4 level=0] handle:1 pkts:1 Best regards Łukasz
