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

How to set GATT's write response after a write request?

Hello,

Consider this scenario: The client successfully writes to a characteristic by the application code can't use the data sent so it would be usefull to signal the client that the data is invalid, through a GATT access response

How can that be accomplished?

Write authorization is not used.

  • FormerMember
    0 FormerMember

    From what I can see, you want to do a "write with response" (Bluetooth core specification v. 4.2, vol. 3, part G, chapter 4.9.3, see figure below from the spec). In our SDK, that is a write request: sd_ble_gattc_write(BLE_GATT_OP_WRITE_REQ, ...).

    image description

    Update 14.10.2016: Perhaps I misunderstood a little. Do I understand you correctly that what you need is a callback if a client tries to write to/read a value at the server that is not writable/readable? If you set the property of an attribute (read/write) to "no access", it will not be possible to read/write that property, and the device will reply with an error to the peer device that tries to read/write to that attribute. The replying with that error is handled by the softdevice.

    An attribute security property is set using BLE_GAP_CONN_SEC_MODE_xxx. That property is added to the attribute when adding it to the softdevice using for example sd_ble_gap_device_name_set(..) or sd_ble_gatts_characteristic_add(..).

    Setting the write property of the device name to no access with the following code, will result in the error code as shown in the below sniffer trace snippet.

    static void gap_params_init(void)
    {
        uint32_t                err_code;
        ble_gap_conn_params_t   gap_conn_params;
        ble_gap_conn_sec_mode_t sec_mode;
    
        BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&sec_mode); 
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                          (const uint8_t *)DEVICE_NAME,
                                          strlen(DEVICE_NAME));
        APP_ERROR_CHECK(err_code);
        ...
    }
    

    image description

  • Kristin, thanks a lot for your input! However I still would like to understand if this is a SDK or BLE limitaton.

    Previously I was using a CSR1011 chip and I used to call a function named "GattAccessRsp" exactly to return/send an "error code" to the client when an invalid value was written to a characteristic.

Related