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

Is it possible to just have reliable write enabled?

Hey everyone,

I have an application where I have to write data to a characteristic. I would like to only allow reliable writes (not unacknowledged ones). Is this permitted by the specification? (and by the s110 softdevice)

  • Yes. This is done by setting the following parameters when creating the characteristic:

    ble_gatts_char_md_t char_md;
    char_md.char_props.write = 1;
    char_md.char_props.write_wo_resp = 0;
    

    This way only the safe 'Write Request' is allowed, not the unsafe 'Write Command'.

  • You have attribute permissions and characterisitc properties.

    Attribute permissions are described in Vol. 3, Part F, Section 3.2.5, and Characteristic properties are described in Vol. 3, Part G, Section 3.3.1.1 in the Bluetooth Core Specification v4.2.

    The characteristic properties determine how the characterisitic value can be used, this information is given to the GATT client as a reference.

    The attribute permissions, or the attribute access permissions specifies that it may be read and/or written, this information is not given to the GATT client.

    If you try to write to an attribute that only is readable, you would get an Write Not Permitted error.

    If you try to write to an attribute that is writeable, you would be able to write to it regardless of what the characteristic properties are, so you will be able to use write request and write commands(write without response).

    This is assuming that none of the other type of permissions are set, and that the device with GATT server doesn't check the characteristic permissions first.

    The only way to only allow write requests is to use authorization. Please see this MSC. Then the application will get a BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event every time a write request or a write command is performed. Then you can check if it is a write request, and reply with sd_ble_gatts_rw_authorize_reply(SUCCESS), or a write command and reply with sd_ble_gatts_rw_authorize_reply(error). What error you use doesn't really matter, since it will not be propagated to the peer (there is no write response).

    Please be aware that currently our SoftDevices have a bug where write commands doesn't trigger a BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event, even though authorization is required. Write commands are executed regardless if authorization is required or not. This will be fixed in the next releases of the SoftDevices.

  • I don't think this is correct. Please see my answer.

Related