Beispiel #1
0
int zclss_processincmd_zonestatus_enrollrequest(struct zclincomingmsg * pInMsg){
  IAS_ACE_ZoneTable_t zone;
  ZStatus_t stat = -1;
  uint16 zoneType;
  uint16 manuCode;
  uint8 responseCode;
  uint8 zoneID;

  zoneType = BUILD_UINT16( pInMsg->data[0], pInMsg->data[1] );
  manuCode = BUILD_UINT16( pInMsg->data[2], pInMsg->data[3] );

  if ( zclSS_ZoneTypeSupported( zoneType ) )
  {
    // Add zone to the table if space is available
    if ( ( zclSS_CountAllZones() < ZCL_SS_MAX_ZONES-1 ) &&
       ( ( zoneID = zclSS_GetNextFreeZoneID() ) <= ZCL_SS_MAX_ZONE_ID ) )
    {
      zone.zoneID = zoneID;
      zone.zoneType = zoneType;

      // The application will fill in the right IEEE Address later
 //     zcl_cpyExtAddr( zone.zoneAddress, (void *)zclSS_UknownIeeeAddress );
      memcpy(zone.zoneAddress, &zclSS_UknownIeeeAddress, sizeof(zclSS_UknownIeeeAddress));

      if ( zclSS_AddZone( pInMsg->message->DstEndpoint, &zone ) == ZSuccess )
      {
        responseCode = ZSuccess;
      }
      else
      {
        // CIE does not permit new zones to enroll at this time
        responseCode = SS_IAS_ZONE_STATUS_ENROLL_RESPONSE_CODE_NO_ENROLL_PERMIT;
      }
    }
    else
    {
      // CIE reached its limit of number of enrolled zones
      responseCode = SS_IAS_ZONE_STATUS_ENROLL_RESPONSE_CODE_TOO_MANY_ZONES;
    }
  }
  else
  {
    // Zone type is not known to CIE and is not supported
    responseCode = SS_IAS_ZONE_STATUS_ENROLL_RESPONSE_CODE_NOT_SUPPORTED;
  }

  // Callback the application so it can fill in the Device IEEE Address
//  if ( pCBs->pfnEnrollRequest )
//  {
//    zclZoneEnrollReq_t req;
//
//    req.srcAddr = &(pInMsg->msg->srcAddr);
//    req.zoneID = zoneID;
//    req.zoneType = zoneType;
//    req.manufacturerCode = manuCode;
//
//    stat = pCBs->pfnEnrollRequest( &req, pInMsg->msg->endPoint );
//  }

 // if ( stat == ZSuccess )
  {
    // Send a response back
    stat = zclSS_IAS_Send_ZoneStatusEnrollResponseCmd( pInMsg->message->DstEndpoint, pInMsg->message->SrcEndpoint, pInMsg->message->SrcAddr, responseCode, zoneID, TRUE, pInMsg->zclframehdr.transseqnum );

    return ( ZCL_STATUS_CMD_HAS_RSP );
  }
 // else
  {
    return ( stat );
  }
}
/*******************************************************************************
 * @fn      zclSS_ProcessInCmd_ZoneStatus_EnrollRequest
 *
 * @brief   Process in the received StatusEnrollRequest Command.
 *
 * @param   pInMsg - pointer to the incoming message
 *
 * @return  ZStatus_t
 */
static ZStatus_t zclSS_ProcessInCmd_ZoneStatus_EnrollRequest( zclIncoming_t *pInMsg,
        zclSS_AppCallbacks_t *pCBs )
{
    IAS_ACE_ZoneTable_t zone;
    uint16 zoneType;
    uint16 manuCode;
    uint8 zoneID;
    uint8 status;

    if ( pInMsg->hdr.commandID != COMMAND_SS_IAS_ZONE_STATUS_ENROLL_REQUEST )
        return ( ZFailure );   // Error ignore the command

    zoneType = BUILD_UINT16( pInMsg->pData[0], pInMsg->pData[1] );
    manuCode = BUILD_UINT16( pInMsg->pData[2], pInMsg->pData[3] );

    if ( zclSS_ZoneTypeSupported( zoneType ) )
    {
        // What if the entry already exists?????
        if ( zclSS_CountAllZones() < ZCL_SS_MAX_ZONES-1 )
        {
            // Add zone to the table
            zoneID = zclSS_GetNextFreeZoneID();

            zone.zoneID = zoneID;
            zone.zoneType = zoneType;

            // The application will fill in the right IEEE Address later
            osal_cpyExtAddr( zone.zoneAddress, (void *)zclSS_UknownIeeeAddress );

            if ( zclSS_AddZone( pInMsg->msg->endPoint, &zone ) == ZSuccess )
            {
                status = ZCL_STATUS_SUCCESS;
            }
            else
            {
                // CIE does not permit new zones to enroll at this time
                status = SS_IAS_ZONE_STATUS_ENROLL_RESPONSE_CODE_NO_ENROLL_PERMIT;
            }
        }
        else
        {
            // CIE reached its limit of number of enrolled zones
            status = SS_IAS_ZONE_STATUS_ENROLL_RESPONSE_CODE_TOO_MANY_ZONES;
        }
    }
    else
    {
        // Zone type is not known to CIE and is not supported
        status = SS_IAS_ZONE_STATUS_ENROLL_RESPONSE_CODE_NOT_SUPPORTED;
    }

    // Send a response back
    zclSS_IAS_Send_ZoneStatusEnrollResponseCmd( pInMsg->msg->endPoint, &(pInMsg->msg->srcAddr),
            status, zoneID, true, pInMsg->hdr.transSeqNum );
    if ( status == ZCL_STATUS_SUCCESS )
    {
        // Callback the application so it can fill in the Device IEEE Address
        if ( pCBs->pfnEnrollRequest )
        {
            zclZoneEnrollReq_t req;

            req.srcAddr = &(pInMsg->msg->srcAddr);
            req.zoneID = zoneID;
            req.zoneType = zoneType;
            req.manufacturerCode = manuCode;

            pCBs->pfnEnrollRequest( &req );
        }
    }

    return ( ZCL_STATUS_CMD_HAS_RSP );
}