3 Replies Latest reply on Sep 25, 2018 9:02 PM by ranjithk_81

    CyBle_GattsErrorRsp example

    maze_1672671

      Hello all,

       

      I would like to send a negative response to a write request, so I wrote:

       

      case CYBLE_EVT_GATTS_WRITE_REQ: {

           CYBLE_GATTS_WRITE_REQ_PARAM_T * wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam ;

       

           if (MY_PORT_CHAR_HANDLE == wrReqParam->handleValPair.attrHandle) {

      CYBLE_GATTS_ERR_PARAM_T err = {

      .attrHandle = wrReqParam->handleValPair.attrHandle,

      .opcode = 1,

      .errorCode = CYBLE_GATT_ERR_UNLIKELY_ERROR

      } ;

       

                CYBLE_API_RESULT_T x = CyBle_GattsErrorRsp(cyBle_connHandle, &err) ;

                DBG_PRINTF("%d = CyBle_GattsErrorRsp\n", x) ;

           }

      }

      break ;    

       

      the print result is 2 == CYBLE_ERROR_INVALID_OPERATION

       

      I read this post Re: How to send an ATT Error response , but it has not an example

       

      In the specification I found:

       

      Immagine.png

       

      Can I send an error? How?

        • 1. Re: CyBle_GattsErrorRsp example

          Hello,

           

          If the Server already responded with an opcode which is done by the stack in most scenarios, this this operation could be invalid.

          I believe this is what you are seeing in your case.  Do you have airlogs for this scenario?

           

          Thanks,

          Ranjith

          • 2. Re: CyBle_GattsErrorRsp example
            maze_1672671

            Hello Ranjith,

             

            I don't have airlogs.

             

            I think that the stack does not respond because I must invoke:

             

            Immagine.png

            If, inside CYBLE_EVT_GATTS_WRITE_REQ event, I don't call this function, the phone connected to me complains.

             

            The doc says: This function has to be invoked in response to a valid Write Request, but, in some cases, I would like to send an error (the phone should retry later). How can I send an error?

             

            Best regards

             

            • 3. Re: CyBle_GattsErrorRsp example

              Looks like the issue is with the opcode used, the below code works for me to generate the error response

               

                              errrsp.attrHandle=CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CHAR_HANDLE;//handle to which write was done

                              errrsp.opcode= (uint8)CYBLE_GATT_WRITE_REQ;//opcode for error response

                              errrsp.errorCode=CYBLE_GATT_ERR_INVALID_ATTRIBUTE_LEN ;//ATTr length error

                             

                              apiresult = CyBle_GattsErrorRsp(cyBle_connHandle,&errrsp);

                             

                              printf(" ERROR API RESULT %d \n",apiresult);

               

              Thanks,

              Ranjith