got the error CY_BLE_GATT_ERR_INVALID_OFFSET

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

cross mob
vish_4677576
Level 1
Level 1

Hi Team,

I am using psoc 6. my query is related to the generated code (after compilation). As I am working with ble section.

I got the error "CY_BLE_GATT_ERR_INVALID_OFFSET".

I am using function Cy_BLE_GATTS_SendNotification(&ConnectionHandle, &handleValuePair) for updating any changes to gatt client.

Inside this funcion, there is a function (generated code) named Cy_BLE_GATTS_WriteAttributeValueLocal(const cy_stc_ble_gatt_handle_value_pair_t *handleValuePair). this has structure

cy_stc_ble_gatts_db_attr_val_info_t  param =

        {

            .handleValuePair = *handleValuePair,

            .flags           = CY_BLE_GATT_DB_LOCALLY_INITIATED

        };

this structure instance "param" has other members also apart from the handleValuePair & flags which have not been given any value. e.g. structure members "offset" is also there.

why not all the structure members initializes here?

and finally this structure being passed to function Cy_BLE_GATTS_WriteAttributeValueCCCD(&param) which gives the error "CY_BLE_GATT_ERR_INVALID_OFFSET"

my doubt is here only, if "offset" had been initialized here, then "CY_BLE_GATT_ERR_INVALID_OFFSET" error would not have come.

Is my understanding correct or Could you please get me a resolution of this error?

/Vinay

0 Likes
1 Solution

Hi Vinay,
Do you use some RTOS here?

The following code, should not cause the problem. it is using a designated initializer to initialize a structure, so other members (e.g. offset) are initialized as zero:

( ps: you can debug this:

  - set breakpoint in Cy_BLE_GATTS_WriteAttributeValueLocal and check param.offset after initialize (it should be 0)

  - set breakpoint in Cy_BLE_GATTS_WriteAttributeValueCCCD and check input param (param.offset should be the same zero, but in some reason it is not zero in your case...) )

cy_stc_ble_gatts_db_attr_val_info_t  param =

{

        .handleValuePair = *handleValuePair,

        .flags          = CY_BLE_GATT_DB_LOCALLY_INITIATED

  };


The possible reason can be if you have stack overflow, please increase stack size (in project) or in BLE task (if you use RTOS)

Regards,
Nazar

View solution in original post

0 Likes
8 Replies
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello vish_4677576 ,

Could you please let me know on how you are passing the parameter values to the Cy_BLE_GATTS_SendNotification() API for sending the notification data ? Please share your project so that we can check.

Thanks,
P Yugandhar.

0 Likes

Hi PY_21,

Thanks for your reply.

I am using below function BLE_SendHbspData() as I have data and its respective length to pass in it as arguments. first I am checking whether ble is connected, GATT notification is enabled & length should be within range. then the check for BLE stack status whether it is free or not then give the value to "handleValuePair" structure and then pass it to Cy_BLE_GATTS_SendNotification() function, and ConnectionHandle is taken as below-

    /* Update attribute handle on GATT Connection */

    ConnectionHandle = *(cy_stc_ble_conn_handle_t *) eventParam;

above line for Connectionhandle is written under CY_BLE_EVT_GATT_CONNECT_IND case of the switch case statements in the

StackEventHandler() function.

bool BLE_SendHbspData(uint8_t* data, size_t length)

{

     bool retValue = false;

     if (data)

     {

          if (BLE_IsConnected()

                 && Cy_BLE_GATTS_IsNotificationEnabled(&ConnectionHandle,                     CY_BLE_HQV_BLE_SERIAL_PORT_OUTBUF_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE)

                && (length <= BLE_HBSP_MAX_DATA_LEN))

          {

               if (Cy_BLE_GATT_GetBusyStatus(ConnectionHandle.attId) == CY_BLE_STACK_STATE_FREE)

               {

                    cy_stc_ble_gatt_handle_value_pair_t  handleValuePair =

                    {

                         .attrHandle = CY_BLE_HQV_BLE_SERIAL_PORT_OUTBUF_CHAR_HANDLE,

                         .value.val = data,

                         .value.len = length

                    };

                    cy_en_ble_api_result_t bleApiResult = Cy_BLE_GATTS_SendNotification(&ConnectionHandle, &handleValuePair);

                    if (bleApiResult == CY_BLE_SUCCESS)

                    {

                         char string[150] = {0};

                         for (int i = 0; i < (int)length; i++)

                         {

                              char text[10];

                              sprintf(text, "%02X ", data);

                              strncat(string, text, sizeof(string));

                         }

                        Trace_ThreadInfo("BLE TX Data: %s", string);

                         retValue = true;

                    }

               }

          }

     }

     return retValue;

}

If any other information is required please let me know.

Regards

Vinay K Shukla

0 Likes

Hi PY_21,

hope my given information must have been useful to you to get the actual issue.

Hoping to get some resolution from you soon.

Regards

Vinay K Shukla

0 Likes

Hello,

Please check with using cy_ble_connHandle[0] handle in Cy_BLE_GATTS_SendNotification(&cy_ble_connHandle[0], &handleValuePair) function.

Thanks,

P Yugandhar.

0 Likes

Hi,

Thanks for the suggestion.

I have tried this, but the same result -- CY_BLE_GATT_ERR_INVALID_OFFSET

due to company protocols proprietary reason, I couldn't able to share the whole project. but if you need more details or questions, I can able to get you more.

looking to any other suggestions from you soon

Regards

Vinay K Shukla

0 Likes

Hello,

At my end, Cy_BLE_GATTS_SendNotification(&cy_ble_connHandle[0], &handleValuePair) function is working fine. Could you please refer to the CE222046_GATT_Out0 example project from the PSoC Creator where it uses Cy_BLE_GATTS_Notification(&notificationPacket) function for sending the notification data.

Please let me know if that API works for you.

Thanks,

P Yugandhar.

0 Likes

Hi,

Cy_BLE_GATTS_Notification(&param) is the function that I used before and that was working fine.

but my question was with the Cy_BLE_GATTS_SendNotification() function.Once I used this, then the offset error is coming. since this function has many conditions and sanity checks and then eventually it goes to execute Cy_BLE_GATTS_Notification(&param).

but on the other hand, if you think that we can rely on calling Cy_BLE_GATTS_Notification(&param) function only then it is okay with me.

Regards

Vinay K Shukla 

0 Likes

Hi Vinay,
Do you use some RTOS here?

The following code, should not cause the problem. it is using a designated initializer to initialize a structure, so other members (e.g. offset) are initialized as zero:

( ps: you can debug this:

  - set breakpoint in Cy_BLE_GATTS_WriteAttributeValueLocal and check param.offset after initialize (it should be 0)

  - set breakpoint in Cy_BLE_GATTS_WriteAttributeValueCCCD and check input param (param.offset should be the same zero, but in some reason it is not zero in your case...) )

cy_stc_ble_gatts_db_attr_val_info_t  param =

{

        .handleValuePair = *handleValuePair,

        .flags          = CY_BLE_GATT_DB_LOCALLY_INITIATED

  };


The possible reason can be if you have stack overflow, please increase stack size (in project) or in BLE task (if you use RTOS)

Regards,
Nazar

0 Likes