📄 mt_nwk.c
字号:
(void)ret;
}
#if defined ( MT_NWK_CB_FUNC ) //NWK callback commands
/*********************************************************************
* @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 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_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_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 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 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 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 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_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_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 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 );
}
#endif /*NWK Callback commands*/
/*********************************************************************
*********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -