This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2652P: My opinion about APS-ack in z-stack

Part Number: CC2652P

There is no strict rule about APS Ack on ZigBee standard. But I think the APS-Ack should be enabled when these condition.

1, The ZPD Response command should enable APS-Ack. Because the ZDP Response command is sent by system, and application could not control it. But application can generate any ZDP Request Command, also can receive ZDP Response command. When ZDP Request Command is lost, the application can't receive ZDP Response command.

2, The ZCL Command which has disabled ZCL-default-response should enable APS-ack. Such as all the ZCL-general-response-command should disabled ZCL-default-response and enable APS-Ack. Because ZCL-Response is sent by ZCL-processing which can't be controlled by application. But ZCL-Request is sent by application, so application can receives ZCL-Response instead of APS-Ack. 

3,The ZCL Reporting is controlled by BDB, so BDB should offer a callback to application to detect the ZCL-default-response or APS-ack.

  • fixing of ZDP

    afStatus_t ZDP_SendDataExt( uint8_t *TransSeq, zAddrType_t *dstAddr, uint16_t cmd, byte len, uint8_t *buf,
                                byte SecurityEnable, pfnAfCnfCB cnfCB, void* param, bool ackReq )
    {
      uint8_t *pBuf = ZDP_TmpBuf;
      byte cnt = len;
    
      while ( cnt-- )
      {
        *pBuf++ = *buf++;
      }
    
      // set send confirm callback
      ZDP_afCnfCB = cnfCB;
      ZDP_afCnfParam = param;
    
      //Enable APS Ack request for some ZDP command,added by Luoyiming
      FillAndSendTxOptions( TransSeq, dstAddr, cmd, len,
                           ((SecurityEnable) ? AF_EN_SECURITY : 0)
                             |((ackReq) ? AF_MSG_ACK_REQUEST : 0) );
    }

    fixing of ZCL

    ZStatus_t zcl_SendCommandEx( uint8_t srcEP, afAddrType_t *destAddr,
                               uint16_t clusterID, uint8_t cmd, uint8_t specific, uint8_t direction,
                               uint8_t disableDefaultRsp, uint16_t manuCode, uint8_t seqNum,
                               uint16_t cmdFormatLen, uint8_t *cmdFormat, uint8_t isReqFromApp )
    {
      endPointDesc_t *epDesc;
      zclFrameHdr_t hdr;
      uint8_t *msgBuf;
      uint16_t msgLen;
      uint8_t *pBuf;
      uint8_t options;
      ZStatus_t status;
    
      //seting send-extParam, add by luoyiming, fix at 2019-3-15
      pfnAfCnfCB cnfCB = NULL;
      void* cnfParam = NULL;
      uint8_t optionsMsk = 0;
      if ( pZclSendExtParam )
      {
        cnfCB = pZclSendExtParam->cnfCB;
        cnfParam = pZclSendExtParam->cnfParam;
        optionsMsk = pZclSendExtParam->options;
        zcl_ClearSendExtParam();
      }
    
      epDesc = afFindEndPointDesc( srcEP );
      if ( epDesc == NULL )
      {
        return ( ZInvalidParameter ); // EMBEDDED RETURN
      }
    
    #if defined ( INTER_PAN ) || defined ( BDB_TL_INITIATOR ) || defined ( BDB_TL_TARGET )
      if ( StubAPS_InterPan( destAddr->panId, destAddr->endPoint ) )
      {
        options = AF_TX_OPTIONS_NONE;
      }
      else
    #endif
      {
        options = zclGetClusterOption( srcEP, clusterID );
    
        // The cluster might not have been defined to use security but if this message
        // is in response to another message that was using APS security this message
        // will be sent with APS security
        if ( !( options & AF_EN_SECURITY ) )
        {
          afIncomingMSGPacket_t *origPkt = zcl_getRawAFMsg();
    
          if ( ( origPkt != NULL ) && ( origPkt->SecurityUse == TRUE ) )
          {
            options |= AF_EN_SECURITY;
          }
        }
      }
      //set zcl send options, add by luoyiming
      options |= optionsMsk;
    
      zcl_memset( &hdr, 0, sizeof( zclFrameHdr_t ) );
    
      // Not Profile wide command (like READ, WRITE)
      if ( specific )
      {
        hdr.fc.type = ZCL_FRAME_TYPE_SPECIFIC_CMD;
      }
      else
      {
        hdr.fc.type = ZCL_FRAME_TYPE_PROFILE_CMD;
      }
    
      if ( ( epDesc->simpleDesc == NULL ) ||
           ( zcl_DeviceOperational( srcEP, clusterID, hdr.fc.type,
                                    cmd, epDesc->simpleDesc->AppProfId ) == FALSE ) )
      {
        return ( ZFailure ); // EMBEDDED RETURN
      }
    
      // Fill in the Maufacturer Code
      if ( manuCode != 0 )
      {
        hdr.fc.manuSpecific = 1;
        hdr.manuCode = manuCode;
      }
    
      // Set the Command Direction
      if ( direction )
      {
        hdr.fc.direction = ZCL_FRAME_SERVER_CLIENT_DIR;
      }
      else
      {
        hdr.fc.direction = ZCL_FRAME_CLIENT_SERVER_DIR;
      }
    
      // Set the Disable Default Response field
      if ( disableDefaultRsp )
      {
        hdr.fc.disableDefaultRsp = 1;
        // Enable APS-ack for Disable Default Response command, luoyiming 2022-01-30
        options |= AF_ACK_REQUEST;
      }
      else
      {
        hdr.fc.disableDefaultRsp = 0;
      }
    
      // Fill in the Transaction Sequence Number
      hdr.transSeqNum = seqNum;
    
      // Fill in the command
      hdr.commandID = cmd;
    
      // calculate the needed buffer size
      msgLen = zclCalcHdrSize( &hdr );
      msgLen += cmdFormatLen;
    
      // Allocate the buffer needed
      msgBuf = zcl_mem_alloc( msgLen );
      if ( msgBuf != NULL )
      {
        //1-junp radius for no-routing,add by luoyiming
        uint8_t radius = zcl_radius;
        if (options & AF_SKIP_ROUTING)
        {
          radius = 1;
        }
    
        // Fill in the ZCL Header
        pBuf = zclBuildHdr( &hdr, msgBuf );
    
        // Fill in the command frame
        zcl_memcpy( pBuf, cmdFormat, cmdFormatLen );
    
        if(isReqFromApp)
        {
          status = zcl_AF_DataRequestExt( destAddr, epDesc, clusterID, msgLen, msgBuf,
                                         &zcl_TransID, options, radius, cnfCB, cnfParam );
        }
        else
        {
          status = AF_DataRequestExt( destAddr, epDesc, clusterID, msgLen, msgBuf,
                                     &zcl_TransID, options, radius, cnfCB, cnfParam );
        }
        zcl_mem_free ( msgBuf );
      }
      else
      {
        status = ZMemError;
      }
    
      return ( status );
    }

  • Hi Aries,

    Thanks for sharing your thoughts and solution with the community!

    Regards,
    Ryan

  • Hi Aries! I am trying to fix the code of SDK to support manufacturer cluster and manufacturer attribute with yours zcl files but I have a compilation error since it does not recognize the identifier pfnAfCnfCB. Could you help me. thanks
  • U needs my complete fixed SDK

    https://gitee.com/zigbee_luo/simplelink_ti_rtos_7.git   

    I have fixed AF_DataRequest and add parameter "cnfCB" and "cnfParam"