How to send an ATT Error response

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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?

0 Likes
1 Solution
Anonymous
Not applicable

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 3.4.1.1 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

*

******************************************************************************/

Tl;Dr;

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.

View solution in original post

0 Likes
2 Replies
Anonymous
Not applicable

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 3.4.1.1 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

*

******************************************************************************/

Tl;Dr;

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.

0 Likes

I also try sending a customized response for Control Point write procedure. But i always get CYBLE_ERROR_INVALID_OPERATION (0x02). I've set all required variables in the CYBLE_GATTS_ERR_PARAM_T struct.

What i am do wrong?

0 Likes