/********************************************************************* * @fn nwk_MTCallbackSubInitCoordConfirm * * @brief Process the callback subscription for NLME-INIT-COORD.confirm * * @param Status - Result of NLME_InitCoordinatorRequest() * * @return none */ void nwk_MTCallbackSubInitCoordConfirm( ZStatus_t Status ) { #if defined( ZDO_COORDINATOR ) MT_BuildAndSendZToolCB( SPI_CB_NLME_INITCOORD_CNF, sizeof( byte ), (byte*)&Status ); #endif // ZDO_COORDINATOR }
/********************************************************************* * @fn nwk_MTCallbackSubDataIndication * * @brief Process the callback subscription for NLDE-DATA.indication * * @param SrcAddress - 16 bit address * @param nsduLength - Length of incoming data * @param nsdu - Pointer to incoming data * @param LinkQuality - Link quality measured during * reception. * @param SecuritySuite - Security Suite Applied * @param SecurityStatus - MLDE_SUCCESS if security process * successfull, MLDE_FAILURE if not. * * @return none */ void nwk_MTCallbackSubDataIndication( uint16 SrcAddress, int16 nsduLength, byte *nsdu, byte LinkQuality ) { byte *msgPtr; byte *msg; byte msgLen; msgLen = sizeof( uint16 ) + sizeof( uint8 ) + ZTEST_DEFAULT_DATA_LEN + sizeof( byte); msgPtr = osal_mem_alloc( msgLen ); if ( msgPtr ) { //Fill up the data bytes msg = msgPtr; //First fill in details *msg++ = HI_UINT16( SrcAddress ); *msg++ = LO_UINT16( SrcAddress ); //Since the max packet size is less than 255 bytes, a byte is enough //to represent nsdu length *msg++ = ( uint8 ) nsduLength; osal_memset( msg, NULL, ZTEST_DEFAULT_DATA_LEN ); // Clear the mem osal_memcpy( msg, nsdu, nsduLength ); msg += ZTEST_DEFAULT_DATA_LEN; *msg++ = LinkQuality; MT_BuildAndSendZToolCB( SPI_CB_NLDE_DATA_IND, msgLen, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn nwk_MTCallbackSubJoinIndication * * @brief Process the callback subscription for NLME-INIT-COORD.indication * * @param ShortAddress - 16-bit address * @param ExtendedAddress - IEEE (64-bit) address * @param CapabilityInformation - Association Capability Information * * @return ZStatus_t */ void nwk_MTCallbackSubJoinIndication( uint16 ShortAddress, byte *ExtendedAddress, byte CapabilityInformation ) { byte *msgPtr; byte *msg; byte len; len = sizeof( uint16 ) + Z_EXTADDR_LEN + sizeof( byte ); msgPtr = osal_mem_alloc( len ); if ( msgPtr ) { //Fill up the data bytes msg = msgPtr; //First fill in details *msg++ = HI_UINT16( ShortAddress ); *msg++ = LO_UINT16( ShortAddress ); osal_cpyExtAddr( msg, ExtendedAddress ); MT_ReverseBytes( msg, Z_EXTADDR_LEN ); msg += Z_EXTADDR_LEN; *msg = CapabilityInformation; MT_BuildAndSendZToolCB( SPI_CB_NLME_JOIN_IND, len, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn zdo_MTCB_ActiveEPRspCB() * * @brief * * Called by ZDO when a Active_EP_rsp or Match_Desc_rsp message is received. * * @param SrcAddr - Source address * @param Status - response status * @param nwkAddr - Device's short address that this response describes * @param epIntfCnt - number of epIntfList items * @param epIntfList - array of active endpoint/interfaces. * * @return none */ void zdo_MTCB_MatchActiveEPRspCB( uint16 type, zAddrType_t *SrcAddr, byte Status, uint16 nwkAddr, byte epIntfCnt, byte *epIntfList ) { byte buf[22]; byte *msg; byte x; msg = buf; //Fill up the data bytes *msg++ = Status; *msg++ = HI_UINT16( SrcAddr->addr.shortAddr ); *msg++ = LO_UINT16( SrcAddr->addr.shortAddr ); *msg++ = HI_UINT16( nwkAddr ); *msg++ = LO_UINT16( nwkAddr ); *msg++ = epIntfCnt; for ( x = 0; x < 16; x++ ) { if ( x < epIntfCnt ) *msg++ = *epIntfList++; else *msg++ = 0; } MT_BuildAndSendZToolCB( type, 22, buf ); }
/********************************************************************* * @fn zdo_MTCB_BindRspCB() * * @brief * * Called to send MT callback response for binding responses * * @param type - binding type (end device, bind, unbind) * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_BindRspCB( uint16 type, zAddrType_t *SrcAddr, byte Status ) { byte buf[3]; buf[0] = Status; buf[1] = HI_UINT16( SrcAddr->addr.shortAddr ); buf[2] = LO_UINT16( SrcAddr->addr.shortAddr ); MT_BuildAndSendZToolCB( type, 3, buf ); }
/********************************************************************* * @fn nwk_MTCallbackSubDataConfirm * * @brief Process the callback subscription for NLDE-DATA.confirm * * @param nsduHandle - APS handle * @param Status - result of data request * * @return none */ void nwk_MTCallbackSubDataConfirm(byte nsduHandle, ZStatus_t status ) { byte buf[2]; buf[0] = nsduHandle; buf[1] = (byte)status; MT_BuildAndSendZToolCB( SPI_CB_NLDE_DATA_CNF, 2, buf ); }
/********************************************************************* * @fn zdo_MTCB_MgmtPermitJoinRspCB() * * @brief * * Called to send MT callback response for Management Permit Join * responses * * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_MgmtPermitJoinRspCB( uint16 SrcAddr, byte Status, byte SecurityUse ) { byte buf[3]; buf[0] = Status; buf[1] = HI_UINT16( SrcAddr ); buf[2] = LO_UINT16( SrcAddr ); MT_BuildAndSendZToolCB( SPI_CB_ZDO_MGMT_PERMIT_JOIN_RSP, 3, buf ); }
/********************************************************************* * @fn zdo_MTCB_MgmtLeaveRspCB() * * @brief * * Called to send MT callback response for Management Leave * responses * * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_MgmtLeaveRspCB( uint16 SrcAddr, byte Status, byte SecurityUse ) { byte buf[3]; buf[0] = Status; buf[1] = HI_UINT16( SrcAddr ); buf[2] = LO_UINT16( SrcAddr ); MT_BuildAndSendZToolCB( SPI_CB_ZDO_MGMT_LEAVE_RSP, 3, buf ); }
/********************************************************************* * @fn zdo_MTCB_UserDescConfCB() * * @brief * * Called to send MT callback response for User Descriptor * confirm * * @param SrcAddr - Source address * @param Status - response status * @param SecurityUse - * * @return none */ void zdo_MTCB_UserDescConfCB( uint16 SrcAddr, byte status, byte SecurityUse ) { byte buf[3]; buf[0] = status; buf[1] = HI_UINT16( SrcAddr ); buf[2] = LO_UINT16( SrcAddr ); MT_BuildAndSendZToolCB( SPI_CB_ZDO_USER_DESC_CNF, 3, buf ); }
/********************************************************************* * @fn zdo_MTCB_MgmtRtgRspCB() * * @brief * * Called to send MT callback response for Management Network * Discover response * * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_MgmtRtgRspCB( uint16 SrcAddr, byte Status, byte RtgCount, byte StartIndex, byte RtgListCount, rtgItem_t *pList ) { byte *msgPtr; byte *msg; byte len; byte x; /*Allocate a message of size equivalent to the corresponding SPI message (plus a couple of bytes for MT use)so that the same buffer can be sent by MT to the test tool by simply setting the header bytes.*/ /*In order to allocate the message , we need to know the length and this has to be calculated before we allocate the message*/ len = 2 + 1 + 1 + 1 + 1 + (ZDP_RTG_DISCRIPTOR_SIZE * ZDO_MAX_RTG_ITEMS); // SrcAddr + Status + RtgCount + StartIndex + RtgListCount // + (maximum entries * size of struct) msgPtr = osal_mem_alloc( len ); if ( msgPtr ) { msg = msgPtr; //Fill up the data bytes *msg++ = HI_UINT16( SrcAddr ); *msg++ = LO_UINT16( SrcAddr ); *msg++ = Status; *msg++ = RtgCount; *msg++ = StartIndex; *msg++ = RtgListCount; osal_memset( msg, 0, (ZDP_RTG_DISCRIPTOR_SIZE * ZDO_MAX_RTG_ITEMS) ); for ( x = 0; x < ZDO_MAX_RTG_ITEMS; x++ ) { if ( x < RtgListCount ) { *msg++ = HI_UINT16( pList->dstAddress ); *msg++ = LO_UINT16( pList->dstAddress ); *msg++ = HI_UINT16( pList->nextHopAddress ); *msg++ = LO_UINT16( pList->nextHopAddress ); *msg++ = pList->status; pList++; } } MT_BuildAndSendZToolCB( SPI_CB_ZDO_MGMT_RTG_RSP, len, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn nwk_MTCallbackSubJoinConfirm * * @brief Process the callback subscription for NLME-JOIN.confirm * * @param Status - Result of NLME_JoinRequest() * * @return none */ void nwk_MTCallbackSubJoinConfirm( uint16 PanId, ZStatus_t Status ) { byte msg[Z_EXTADDR_LEN + 3]; // This device's 64-bit address ZMacGetReq( ZMacExtAddr, msg ); MT_ReverseBytes( msg, Z_EXTADDR_LEN ); msg[Z_EXTADDR_LEN + 0] = HI_UINT16( PanId ); msg[Z_EXTADDR_LEN + 1] = LO_UINT16( PanId ); msg[Z_EXTADDR_LEN + 2] = (byte)Status; MT_BuildAndSendZToolCB( SPI_CB_NLME_JOIN_CNF, Z_EXTADDR_LEN + 3, msg ); }
/********************************************************************* * @fn zdo_MTCB_ServerDiscRspCB() * * @brief Called to send MT callback response for Server_Discovery_rsp responses. * * @param srcAddr - Source address. * @param status - Response status. * @param aoi - Network Address of Interest. * @param serverMask - Bit mask of services that match request. * @param SecurityUse - * * @return none */ void zdo_MTCB_ServerDiscRspCB( uint16 srcAddr, byte status, uint16 serverMask, byte SecurityUse ) { byte buf[5]; byte *pBuf = buf; *pBuf++ = status; *pBuf++ = HI_UINT16( srcAddr ); *pBuf++ = LO_UINT16( srcAddr ); *pBuf++ = HI_UINT16( serverMask ); *pBuf++ = LO_UINT16( serverMask ); MT_BuildAndSendZToolCB( SPI_CB_ZDO_SERVERDISC_RSP, 5, buf ); #define CB_ID_ZDO_SERVERDISC_RSP 0x00080000 }
/********************************************************************* * @fn nwk_MTCallbackSubLeaveIndication * * @brief Process the callback subscription for NLME-LEAVE.indication * * @param DeviceAddress - IEEE (64-bit) address * * @return NULL */ void nwk_MTCallbackSubLeaveIndication( byte *DeviceAddress ) { byte msg[Z_EXTADDR_LEN+1]; //First fill in details if ( DeviceAddress ) { osal_cpyExtAddr( msg, DeviceAddress ); MT_ReverseBytes( msg, Z_EXTADDR_LEN ); } else osal_memset( msg, 0, Z_EXTADDR_LEN ); msg[Z_EXTADDR_LEN] = 0; // Status, assume good if we get this far MT_BuildAndSendZToolCB( SPI_CB_NLME_LEAVE_IND, Z_EXTADDR_LEN+1, msg ); }
/********************************************************************* * @fn nwk_MTCallbackSubNetworkDiscoveryConfirm * * @brief Process the callback subscription for NLME-NWK_DISC.confirm * * @param ResultCount - number of networks discovered * @param NetworkList - pointer to list of network descriptors * * @return void */ void nwk_MTCallbackSubNetworkDiscoveryConfirm( byte ResultCount, networkDesc_t *NetworkList ) { byte len; byte *msgPtr; byte *msg; byte i; // The message cannot be bigger then SPI_TX_BUFF_MAX. Reduce resultCount if necessary if (ResultCount * sizeof(networkDesc_t) > SPI_TX_BUFF_MAX - (1 + SPI_0DATA_MSG_LEN)) { ResultCount = (SPI_TX_BUFF_MAX - (1 + SPI_0DATA_MSG_LEN)) / sizeof(networkDesc_t); } len = 1 + ResultCount * sizeof(networkDesc_t); msgPtr = osal_mem_alloc( len ); if ( msgPtr ) { //Fill up the data bytes msg = msgPtr; *msg++ = ResultCount; for ( i = 0; i < ResultCount; i++ ) { *msg++ = HI_UINT16( NetworkList->panId ); *msg++ = LO_UINT16( NetworkList->panId ); *msg++ = NetworkList->logicalChannel; *msg++ = NetworkList->beaconOrder; *msg++ = NetworkList->superFrameOrder; *msg++ = NetworkList->routerCapacity; *msg++ = NetworkList->deviceCapacity; *msg++ = NetworkList->version; *msg++ = NetworkList->stackProfile; //*msg++ = NetworkList->securityLevel; NetworkList = (networkDesc_t*)NetworkList->nextDesc; } MT_BuildAndSendZToolCB( SPI_CB_NLME_NWK_DISC_CNF, len, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn zdo_MTCB_UserDescRspCB() * * @brief * * Called to send MT callback response for User Descriptor * responses * * @param SrcAddr - Source address * @param Status - response status * @param nwkAddrOfInterest - * @param userDescLen - * @param userDesc - * @param SecurityUse - * * @return none */ void zdo_MTCB_UserDescRspCB( uint16 SrcAddr, byte status, uint16 nwkAddrOfInterest, byte userDescLen, byte *userDesc, byte SecurityUse ) { byte *msgPtr; byte *msg; msgPtr = osal_mem_alloc( USER_DESC_CB_LEN ); osal_memset( msgPtr, 0, USER_DESC_CB_LEN ); msg = msgPtr; *msg++ = status; *msg++ = HI_UINT16( SrcAddr ); *msg++ = LO_UINT16( SrcAddr ); *msg++ = HI_UINT16( nwkAddrOfInterest ); *msg++ = LO_UINT16( nwkAddrOfInterest ); *msg++ = userDescLen; osal_memcpy( msg, userDesc, userDescLen ); MT_BuildAndSendZToolCB( SPI_CB_ZDO_USER_DESC_RSP, USER_DESC_CB_LEN, msgPtr ); osal_mem_free( msgPtr ); }
/********************************************************************* * @fn zdo_MTCB_PowerDescRspCB() * * @brief * * Called by ZDO when a Power_Desc_rsp message is received. * * @param SrcAddr - Source address * @param Status - response status * @param nwkAddr - 16 bit network address of device * @param pPwrDesc - pointer to the devices Power Descriptor * NULL if Status != ZDP_SUCCESS * * @return none */ void zdo_MTCB_PowerDescRspCB( zAddrType_t *SrcAddr, byte Status, uint16 nwkAddr, NodePowerDescriptorFormat_t *pPwrDesc ) { byte buf[9]; byte *msg; msg = buf; //Fill up the data bytes *msg++ = Status; *msg++ = HI_UINT16( SrcAddr->addr.shortAddr ); *msg++ = LO_UINT16( SrcAddr->addr.shortAddr ); *msg++ = HI_UINT16( nwkAddr ); *msg++ = LO_UINT16( nwkAddr ); *msg++ = pPwrDesc->PowerMode; *msg++ = pPwrDesc->AvailablePowerSources; *msg++ = pPwrDesc->CurrentPowerSource; *msg = pPwrDesc->CurrentPowerSourceLevel; MT_BuildAndSendZToolCB( SPI_CB_ZDO_POWER_DESC_RSP, 9, buf ); }
/********************************************************************* * @fn zdo_MTCB_NodeDescRspCB() * * @brief * * Called by ZDO when a Node_Desc_rsp message is received. * * @param SrcAddr - Source address * @param Status - response status * @param nwkAddr - 16 bit network address of device * @param pNodeDesc - pointer to the devices Node Descriptor * NULL if Status != ZDP_SUCCESS * * @return none */ void zdo_MTCB_NodeDescRspCB( zAddrType_t *SrcAddr, byte Status, uint16 nwkAddr, NodeDescriptorFormat_t *pNodeDesc ) { byte buf[18]; byte *msg; msg = buf; //Fill up the data bytes *msg++ = Status; *msg++ = HI_UINT16( SrcAddr->addr.shortAddr ); *msg++ = LO_UINT16( SrcAddr->addr.shortAddr ); *msg++ = HI_UINT16( nwkAddr ); *msg++ = LO_UINT16( nwkAddr ); *msg++ = (byte)(pNodeDesc->LogicalType); // Since Z-Tool can't treat V1.0 and V1.1 differently, // we just output these two byte in both cases, although // in V1.0, they are always zeros. *msg++ = (byte) pNodeDesc->ComplexDescAvail; *msg++ = (byte) pNodeDesc->UserDescAvail; *msg++ = pNodeDesc->APSFlags; *msg++ = pNodeDesc->FrequencyBand; *msg++ = pNodeDesc->CapabilityFlags; *msg++ = pNodeDesc->ManufacturerCode[1]; *msg++ = pNodeDesc->ManufacturerCode[0]; *msg++ = pNodeDesc->MaxBufferSize; *msg++ = pNodeDesc->MaxTransferSize[1]; *msg++ = pNodeDesc->MaxTransferSize[0]; *msg++ = HI_UINT16( pNodeDesc->ServerMask); *msg++ = LO_UINT16( pNodeDesc->ServerMask); MT_BuildAndSendZToolCB( SPI_CB_ZDO_NODE_DESC_RSP, 18, buf ); }
/********************************************************************* * @fn nwk_MTCallbackSubLeaveConfirm * * @brief Process the callback subscription for NLME-LEAVE.confirm * * @param DeviceAddress - IEEE (64-bit) address * @param Status - Result of NLME_LeaveRequest() * * @return none */ void nwk_MTCallbackSubLeaveConfirm( byte *DeviceAddress, ZStatus_t Status ) { byte *msgPtr; byte *msg; msgPtr = osal_mem_alloc( Z_EXTADDR_LEN + sizeof( byte ) ); if ( msgPtr ) { //Fill up the data bytes msg = msgPtr; //First fill in details osal_cpyExtAddr( msg, DeviceAddress ); MT_ReverseBytes( msg, Z_EXTADDR_LEN ); msg += Z_EXTADDR_LEN; *msg = (byte)Status; MT_BuildAndSendZToolCB( SPI_CB_NLME_LEAVE_CNF, Z_EXTADDR_LEN + sizeof( byte ), msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn nwk_MTCallbackSubSyncIndication * * @brief Process the callback subscription for NLME-SYNC.indication * * @param none * * @return none */ void nwk_MTCallbackSubSyncIndication( void ) { MT_BuildAndSendZToolCB( SPI_CB_NLME_SYNC_IND, 0, NULL ); }
/********************************************************************* * @fn zdo_MTCB_NwkIEEEAddrRspCB * * @brief * * Called by ZDO when a NWK_addr_rsp message is received. * * @param SrcAddr - Source address * @param Status - response status * @param IEEEAddr - 64 bit IEEE address of device * @param nwkAddr - 16 bit network address of device * @param NumAssocDev - number of associated devices to reporting device * @param AssocDevList - array short addresses of associated devices * * @return none */ void zdo_MTCB_NwkIEEEAddrRspCB( uint16 type, zAddrType_t *SrcAddr, byte Status, byte *IEEEAddr, uint16 nwkAddr, byte NumAssocDev, byte StartIndex, uint16 *AssocDevList ) { byte *pBuf; byte *msg; byte len; byte x; /*Allocate a message of size equivalent to the corresponding SPI message (plus a couple of bytes for MT use)so that the same buffer can be sent by MT to the test tool by simply setting the header bytes.*/ /*In order to allocate the message , we need to know the length and this has to be calculated before we allocate the message*/ if ( type == SPI_CB_ZDO_NWK_ADDR_RSP ) { len = 1 + Z_EXTADDR_LEN + 1 + Z_EXTADDR_LEN + 2 + 1 + 1 + (2*8); // Addrmode + SrcAddr + Status + IEEEAddr + nwkAddr + NumAssocDev + StartIndex } else { len = 1 + Z_EXTADDR_LEN + 1 + Z_EXTADDR_LEN + 1 + 1 + (2*8); // Addrmode + SrcAddr + Status + IEEEAddr + NumAssocDev + StartIndex } pBuf = osal_mem_alloc( len ); if ( pBuf ) { msg = pBuf; //First fill in details if ( SrcAddr->addrMode == Addr16Bit ) { *msg++ = Addr16Bit; for ( x = 0; x < (Z_EXTADDR_LEN - 2); x++ ) *msg++ = 0; *msg++ = HI_UINT16( SrcAddr->addr.shortAddr ); *msg++ = LO_UINT16( SrcAddr->addr.shortAddr ); } else { *msg++ = Addr64Bit; msg = zdo_MT_CopyRevExtAddr( msg, SrcAddr->addr.extAddr ); } *msg++ = Status; msg = zdo_MT_CopyRevExtAddr( msg, IEEEAddr ); if ( type == SPI_CB_ZDO_NWK_ADDR_RSP ) { *msg++ = HI_UINT16( nwkAddr ); *msg++ = LO_UINT16( nwkAddr ); } *msg++ = NumAssocDev; *msg++ = StartIndex; byte cnt = NumAssocDev - StartIndex; for ( x = 0; x < 8; x++ ) { if ( x < cnt ) { *msg++ = HI_UINT16( *AssocDevList ); *msg++ = LO_UINT16( *AssocDevList ); AssocDevList++; } else { *msg++ = 0; *msg++ = 0; } } MT_BuildAndSendZToolCB( type, len, pBuf ); osal_mem_free( pBuf ); } }
/********************************************************************* * @fn zdo_MTCB_MgmtBindRspCB() * * @brief * * Called to send MT callback response for Management Network * Discover response * * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_MgmtBindRspCB( uint16 SrcAddr, byte Status, byte BindCount, byte StartIndex, byte BindListCount, apsBindingItem_t *pList ) { byte *msgPtr; byte *msg; byte len; byte x; uint8 protoVer = NLME_GetProtocolVersion(); /*Allocate a message of size equivalent to the corresponding SPI message (plus a couple of bytes for MT use)so that the same buffer can be sent by MT to the test tool by simply setting the header bytes.*/ /*In order to allocate the message , we need to know the length and this has to be calculated before we allocate the message*/ // One more byte for clusterID and DstAddrMode len = 2 + 1 + 1 + 1 + 1 + ( ( ZDP_BIND_DISCRIPTOR_SIZE + 1 + 1 ) * ZDO_MAX_BIND_ITEMS); // SrcAddr + Status + BindCount + StartIndex + BindListCount // + (maximum entries * size of struct) msgPtr = osal_mem_alloc( len ); if ( msgPtr ) { msg = msgPtr; //Fill up the data bytes *msg++ = HI_UINT16( SrcAddr ); *msg++ = LO_UINT16( SrcAddr ); *msg++ = Status; *msg++ = BindCount; *msg++ = StartIndex; *msg++ = BindListCount; osal_memset( msg, 0, ( ( ZDP_BIND_DISCRIPTOR_SIZE + 1 + 1) * ZDO_MAX_BIND_ITEMS) ); for ( x = 0; x < ZDO_MAX_BIND_ITEMS; x++ ) { if ( x < BindListCount ) { msg = zdo_MT_CopyRevExtAddr( msg, pList->srcAddr ); *msg++ = pList->srcEP; if ( protoVer == ZB_PROT_V1_0 ) { *msg++ = LO_UINT16( pList->clusterID); msg = zdo_MT_CopyRevExtAddr( msg, pList->dstAddr.addr.extAddr ); *msg++ = pList->dstEP; } else { *msg++ = HI_UINT16( pList->clusterID); *msg++ = LO_UINT16( pList->clusterID); *msg++ = pList->dstAddr.addrMode; if ( pList->dstAddr.addrMode == Addr64Bit ) { msg = zdo_MT_CopyRevExtAddr( msg, pList->dstAddr.addr.extAddr ); *msg++ = pList->dstEP; } else { *msg++ = HI_UINT16( pList->dstAddr.addr.shortAddr ); *msg++ = LO_UINT16( pList->dstAddr.addr.shortAddr ); // DstEndpoint will not present if DstAddrMode is not 64-bit extAddr } } pList++; } } MT_BuildAndSendZToolCB( SPI_CB_ZDO_MGMT_BIND_RSP, len, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn nwk_MTCallbackSubStartRouterConfirm * * @brief Process the callback subscription for NLME-START-ROUTER.confirm * * @param Status - Result of NLME_StartRouterRequest() * * @return none */ void nwk_MTCallbackSubStartRouterConfirm( ZStatus_t Status ) { MT_BuildAndSendZToolCB( SPI_CB_NLME_START_ROUTER_CNF, sizeof( byte ), (byte*)&Status ); }
/********************************************************************* * @fn zdo_MTCB_SimpleDescRspCB() * * @brief * * Called by ZDO when a Simple_Desc_rsp message is received. * * @param SrcAddr - Source address * @param Status - response status * @param nwkAddr - 16 bit network address of device * @param EPIntf - Endpoint/Interface for description * @param pSimpleDesc - pointer to the devices Simple Descriptor * NULL if Status != ZDP_SUCCESS * * @return none */ void zdo_MTCB_SimpleDescRspCB( zAddrType_t *SrcAddr, byte Status, uint16 nwkAddr, byte EPIntf, SimpleDescriptionFormat_t *pSimpleDesc ) { byte *msgPtr; byte *msg; byte x; msgPtr = osal_mem_alloc( ZDO_SIMPLE_DESC_CB_LEN ); if ( msgPtr ) { msg = msgPtr; //Fill up the data bytes *msg++ = Status; *msg++ = HI_UINT16( SrcAddr->addr.shortAddr ); *msg++ = LO_UINT16( SrcAddr->addr.shortAddr ); *msg++ = HI_UINT16( nwkAddr ); *msg++ = LO_UINT16( nwkAddr ); *msg++ = EPIntf; *msg++ = HI_UINT16( pSimpleDesc->AppProfId ); *msg++ = LO_UINT16( pSimpleDesc->AppProfId ); *msg++ = HI_UINT16( pSimpleDesc->AppDeviceId ); *msg++ = LO_UINT16( pSimpleDesc->AppDeviceId ); *msg++ = pSimpleDesc->AppDevVer; *msg++ = pSimpleDesc->Reserved; *msg++ = pSimpleDesc->AppNumInClusters; // ZTool supports 16 bits the code has taken it into account for ( x = 0; x < 16; x++ ) { if ( x < pSimpleDesc->AppNumInClusters ) { *msg++ = HI_UINT16( pSimpleDesc->pAppInClusterList[x]); *msg++ = LO_UINT16( pSimpleDesc->pAppInClusterList[x]); } else { *msg++ = 0; *msg++ = 0; } } *msg++ = pSimpleDesc->AppNumOutClusters; for ( x = 0; x < 16; x++ ) { if ( x < pSimpleDesc->AppNumOutClusters ) { *msg++ = HI_UINT16( pSimpleDesc->pAppOutClusterList[x]); *msg++ = LO_UINT16( pSimpleDesc->pAppOutClusterList[x]); } else { *msg++ = 0; *msg++ = 0; } } MT_BuildAndSendZToolCB( SPI_CB_ZDO_SIMPLE_DESC_RSP, ZDO_SIMPLE_DESC_CB_LEN, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn nwk_MTCallbackSubPollConfirm * * @brief Process the callback subscription for NLME-POLL.confirm * * @param status - status of the poll operation * * @return none */ void nwk_MTCallbackSubPollConfirm( byte status ) { byte msg = status; MT_BuildAndSendZToolCB( SPI_CB_NLME_POLL_CNF, 1, &msg ); }
/********************************************************************* * @fn zdo_MTCB_MgmtLqiRspCB() * * @brief * * Called to send MT callback response for Management LQI response * * @param type - binding type (end device, bind, unbind) * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_MgmtLqiRspCB( uint16 SrcAddr, byte Status, byte NeighborLqiEntries, byte StartIndex, byte NeighborLqiCount, neighborLqiItem_t *pList ) { byte *msgPtr; byte *msg; byte len; byte x; byte proVer = NLME_GetProtocolVersion(); /*Allocate a message of size equivalent to the corresponding SPI message (plus a couple of bytes for MT use)so that the same buffer can be sent by MT to the test tool by simply setting the header bytes.*/ /*In order to allocate the message , we need to know the length and this has to be calculated before we allocate the message*/ len = 2 + 1 + 1 + 1 + 1 + (ZDP_NEIGHBORLQI_SIZE * ZDO_MAX_LQI_ITEMS ); // SrcAddr + Status + NeighborLqiEntries + StartIndex + NeighborLqiCount // + (maximum entries * size of struct) msgPtr = osal_mem_alloc( len ); if ( msgPtr ) { msg = msgPtr; //Fill up the data bytes *msg++ = HI_UINT16( SrcAddr ); *msg++ = LO_UINT16( SrcAddr ); *msg++ = Status; *msg++ = NeighborLqiEntries; *msg++ = StartIndex; *msg++ = NeighborLqiCount; osal_memset( msg, 0, (ZDP_NEIGHBORLQI_SIZE * ZDO_MAX_LQI_ITEMS) ); for ( x = 0; x < ZDO_MAX_LQI_ITEMS; x++ ) { if ( x < NeighborLqiCount ) { if ( proVer == ZB_PROT_V1_0 ) { *msg++ = HI_UINT16( pList->PANId ); *msg++ = LO_UINT16( pList->PANId ); } else { osal_cpyExtAddr(msg, pList->extPANId); msg += Z_EXTADDR_LEN; } *msg++ = HI_UINT16( pList->nwkAddr ); *msg++ = LO_UINT16( pList->nwkAddr ); *msg++ = pList->rxLqi; *msg++ = pList->txQuality; pList++; } } MT_BuildAndSendZToolCB( SPI_CB_ZDO_MGMT_LQI_RSP, len, msgPtr ); osal_mem_free( msgPtr ); } }
/********************************************************************* * @fn af_MTCB_IncomingData * * @brief Process the callback subscription for AF Incoming data. * * @param pkt - Incoming AF data. * * @return none */ void af_MTCB_IncomingData( void *pkt ) { afIncomingMSGPacket_t *MSGpkt = (afIncomingMSGPacket_t *)pkt; #if ( AF_KVP_SUPPORT ) afIncomingKVPPacket_t *KVPpkt = (afIncomingKVPPacket_t *)pkt; #endif byte *memPtr, *ptr; /* Frametype, WasBroadcast, LinkQuality, SecurityUse, SrcAddr, * SrcEndpoint, DestEndpoint, ClusterId, TransCnt, TransId, CmdType, * AttribDataType, AttribId, ErrorCode, TransDataLen = * 1+1+1+1+2+1+1+2+1+1+1+2+1+1+1. */ const byte len = 18 + ZTEST_DEFAULT_AF_DATA_LEN; byte dataLen; if ( MSGpkt->hdr.event != AF_INCOMING_MSG_CMD ) { #if ( AF_KVP_SUPPORT ) dataLen = KVPpkt->cmd.DataLength; #else return; #endif } else { dataLen = MSGpkt->cmd.DataLength; } if ( dataLen > ZTEST_DEFAULT_AF_DATA_LEN ) { dataLen = ZTEST_DEFAULT_AF_DATA_LEN; } memPtr = osal_mem_alloc( len ); if ( !memPtr ) { return; } ptr = memPtr; #if ( AF_KVP_SUPPORT ) if ( MSGpkt->hdr.event != AF_INCOMING_MSG_CMD ) { *ptr++ = KVPpkt->hdr.event; *ptr++ = KVPpkt->wasBroadcast; *ptr++ = KVPpkt->LinkQuality; *ptr++ = KVPpkt->SecurityUse; *ptr++ = HI_UINT16( KVPpkt->srcAddr.addr.shortAddr ); *ptr++ = LO_UINT16( KVPpkt->srcAddr.addr.shortAddr ); *ptr++ = KVPpkt->srcAddr.endPoint; *ptr++ = KVPpkt->endPoint; *ptr++ = HI_UINT16( KVPpkt->clusterId ); *ptr++ = LO_UINT16( KVPpkt->clusterId ); *ptr++ = KVPpkt->totalTrans; *ptr++ = KVPpkt->cmd.TransSeqNumber; *ptr++ = KVPpkt->cmd.CommandType; *ptr++ = KVPpkt->cmd.AttribDataType; *ptr++ = HI_UINT16( KVPpkt->cmd.AttribId ); *ptr++ = LO_UINT16( KVPpkt->cmd.AttribId ); *ptr++ = KVPpkt->cmd.ErrorCode; *ptr++ = KVPpkt->cmd.DataLength; osal_memcpy( ptr, KVPpkt->cmd.Data, dataLen ); } else #endif { *ptr++ = MSGpkt->hdr.event; *ptr++ = MSGpkt->wasBroadcast; *ptr++ = MSGpkt->LinkQuality; *ptr++ = MSGpkt->SecurityUse; *ptr++ = HI_UINT16( MSGpkt->srcAddr.addr.shortAddr ); *ptr++ = LO_UINT16( MSGpkt->srcAddr.addr.shortAddr ); *ptr++ = MSGpkt->srcAddr.endPoint; *ptr++ = MSGpkt->endPoint; *ptr++ = HI_UINT16( MSGpkt->clusterId ); *ptr++ = LO_UINT16( MSGpkt->clusterId ); osal_memset( ptr, 0, 7 ); ptr += 7; osal_memcpy( ptr, MSGpkt->cmd.Data, dataLen ); } if ( dataLen < ZTEST_DEFAULT_AF_DATA_LEN ) { osal_memset( (ptr + dataLen), 0, (ZTEST_DEFAULT_AF_DATA_LEN - dataLen) ); } #if defined (ZTOOL_P1) || defined (ZTOOL_P2) MT_BuildAndSendZToolCB( SPI_CB_AF_DATA_IND, len, memPtr ); #endif osal_mem_free( memPtr ); }
/********************************************************************* * @fn zdo_MTCB_MgmtNwkDiscRspCB() * * @brief * * Called to send MT callback response for Management Network * Discover response * * @param SrcAddr - Source address * @param Status - response status * * @return none */ void zdo_MTCB_MgmtNwkDiscRspCB( uint16 SrcAddr, byte Status, byte NetworkCount, byte StartIndex, byte networkListCount, mgmtNwkDiscItem_t *pList ) { byte *msgPtr; byte *msg; byte len; byte x; byte proVer = NLME_GetProtocolVersion(); /*Allocate a message of size equivalent to the corresponding SPI message (plus a couple of bytes for MT use)so that the same buffer can be sent by MT to the test tool by simply setting the header bytes.*/ /*In order to allocate the message , we need to know the length and this has to be calculated before we allocate the message*/ if ( proVer == ZB_PROT_V1_0 ) { len = 2 + 1 + 1 + 1 + 1 + (ZDP_NETWORK_DISCRIPTOR_SIZE * ZDO_MAX_NWKDISC_ITEMS); // SrcAddr + Status + NetworkCount + StartIndex + networkListCount // + (maximum entries * size of struct) } else { len = 2 + 1 + 1 + 1 + 1 + (ZDP_NETWORK_EXTENDED_DISCRIPTOR_SIZE * ZDO_MAX_NWKDISC_ITEMS); } msgPtr = osal_mem_alloc( len ); if ( msgPtr ) { msg = msgPtr; //Fill up the data bytes *msg++ = HI_UINT16( SrcAddr ); *msg++ = LO_UINT16( SrcAddr ); *msg++ = Status; *msg++ = NetworkCount; *msg++ = StartIndex; *msg++ = networkListCount; osal_memset( msg, 0, (ZDP_NETWORK_DISCRIPTOR_SIZE * ZDO_MAX_NWKDISC_ITEMS) ); for ( x = 0; x < ZDO_MAX_NWKDISC_ITEMS; x++ ) { if ( x < networkListCount ) { if ( proVer == ZB_PROT_V1_0 ) { *msg++ = HI_UINT16( pList->PANId ); *msg++ = LO_UINT16( pList->PANId ); } else { osal_cpyExtAddr( msg, pList->extendedPANID ); msg += Z_EXTADDR_LEN; } *msg++ = pList->logicalChannel; *msg++ = pList->stackProfile; *msg++ = pList->version; *msg++ = pList->beaconOrder; *msg++ = pList->superFrameOrder; *msg++ = pList->permitJoining; pList++; } } MT_BuildAndSendZToolCB( SPI_CB_ZDO_MGMT_NWKDISC_RSP, len, msgPtr ); osal_mem_free( msgPtr ); } }