1 Reply Latest reply on Mar 5, 2018 7:22 AM by e.pratt_1639216

    How to send an ATT Error response


      Hello all,


      I am making some cypress psoc 4 application and I want to reply whith an error response after the client does a write.


      I've noticed that if I do not use "CyBle_GattsWriteRsp(cyBle_connHandle);" the server will timeout after some time and I have to reconnect again.


      I was wondering if it is posible to use "CyBle_GattsErrorRsp(cyBle_connHandle, &err);". on its own and how I can read this error on the client side.


      Anyone has an exaple of this?

        • 1. Re: How to send an ATT Error response

          Yes, you should use CyBle_GattsErrorRsp(). CyBle_GattsWriteRsp() is only called when you want the write to succeed/response to be sent as okay.


          The documentation/comments for the CyBle_GattsErrorRsp() should explain how to use it pretty well:


          * Function Name: CyBle_GattsErrorRsp



          *  This function sends an error response to the peer device. The Error Response

          *  is used to state that a given request cannot be performed, and to provide the

          *  reason as defined in 'CYBLE_GATT_ERR_CODE_T'. This is a non-blocking function.


          *  Note that the 'Write Command' initiated by GATT Client does not generate an

          *  'Error Response' from the GATT Server's end. The GATT Client gets

          CYBLE_EVT_GATTC_ERROR_RSP event on receiving error response.


          *  Refer Bluetooth 4.1 core specification, Volume 3, Part F, section for

          *  more details on Error Response operation.

          *  \param connHandle: Connection handle to identify the peer GATT entity, of type

          *               CYBLE_CONN_HANDLE_T.

          *  \param errRspParam: Pointer to structure of type CYBLE_GATTS_ERR_PARAM_T.


          * \return

          *  CYBLE_API_RESULT_T : Return value indicates if the function succeeded or

          *  failed. Following are the possible error codes.


          *  Errors codes                          | Description

          *  ------------                          | -----------

          *   CYBLE_ERROR_OK                       | On successful operation

          *   CYBLE_ERROR_INVALID_PARAMETER        | 'connHandle' value does not represent any existing entry in the Stack

          *   CYBLE_ERROR_INVALID_OPERATION        | This operation is not permitted

          *   CYBLE_ERROR_MEMORY_ALLOCATION_FAILED | Memory allocation failed





          To do what you are asking:

          Call CyBle_GattsErrorRsp() on the peripheral

          Handle the CYBLE_EVT_GATTC_ERROR_RSP event on the central

          The error should be packaged within the CYBLE_GATTS_ERR_PARAM_T structure for both the event on the central and the response function on the peripheral.