This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

issues with writable characteristic

I have a service a writeable characteristic and I'm finding the following issues.

Characteristic is read/write, not variable length, size of 4, no read or write auth, no extended attributes (ie no reliable/long writes)

  1. If I write the characteristic with more than 4 bytes (but less than 20) there's a correct 'invalid attribute value length' error returned. However if I write with less than 4 bytes the write succeeds and only some bytes of the value are updated, but the length remains at 4. Since it's fixed length, I would expect an invalid attribute value length error in this case too.

Edit: and I'm wrong for expecting that as someone kindly pointed me at the spec and it says

If the attribute value has a fixed length and the Attribute Value parameter length is less than or equal to the length of the attribute value, the octets of the attribute value parameter length shall be written; all other octets in this attribute value shall be unchanged.

That still leaves the other two

  1. If I send a prepared write for that characteristic even though it's fixed-length and doesn't have any extended attributes (nor does any other characteristic) I get a USER MEM request and the rw_auth calls. Since I'm not expecting any long writes, I don't look for those events or handle them. If a characteristic is not set up for reliable/long writes, why doesn't the softdevice instantly reject the prepare write with an error message? I would expect the 'Attribute Not Long' error. I would only expect to ever get the user memory and prepare/commit calls for attributes which have the extended reliable_wr property set true.
  2. If I do try to handle the rw_auth and send back a proper error code, like 'Attribute Not Long'' the sd_ble_gatts_rw_authorize_reply() function returns an INVALID_PARAM error. It seems that I am only allowed to send a very few gatt_status codes, others are rejected as invalid params, why?

You can see this in the sample code too, if you run say the uart example and use lightblue to attempt to send a > 20 byte value to the writable characteristic, for which it will send out a prepare write, nothing will happen and eventually the connection will drop - this is because internally a memory request has been sent and not handled so the connection times out. It's true that a client ought to see the lack of extended characteristics and not attempt a prepared/long write, but if one is sent, the softdevice should reject it.

Related