zdobject.c
来自「一些基于IRA环境开发的zigbee实例程序」· C语言 代码 · 共 2,264 行 · 第 1/5 页
C
2,264 行
else
{
if ( inMsg->clusterID == Bind_req )
{
uint16 nwkAddr;
// Check for the destination address
if ( pReq->dstAddress.addrMode == Addr64Bit )
{
if ( APSME_LookupNwkAddr( pReq->dstAddress.addr.extAddr, &nwkAddr ) == FALSE )
{
ZDP_NwkAddrReq( pReq->dstAddress.addr.extAddr, ZDP_ADDR_REQTYPE_SINGLE, 0, 0 );
}
}
}
if ( inMsg->clusterID == Bind_req )
{
if ( APSME_BindRequest( pReq->srcEndpoint, pReq->clusterID,
&(pReq->dstAddress), pReq->dstEndpoint ) == ZSuccess )
{
bindStat = ZDP_SUCCESS;
// Notify to save info into NV
ZDApp_NVUpdate();
}
else
bindStat = ZDP_TABLE_FULL;
}
else // Unbind_req
{
if ( APSME_UnBindRequest( pReq->srcEndpoint, pReq->clusterID,
&(pReq->dstAddress), pReq->dstEndpoint ) == ZSuccess )
{
bindStat = ZDP_SUCCESS;
// Notify to save info into NV
ZDApp_NVUpdate();
}
else
bindStat = ZDP_NO_ENTRY;
}
}
}
// Send back a response message
ZDP_SendData( &(inMsg->TransSeq), &(inMsg->srcAddr),
(inMsg->clusterID | ZDO_RESPONSE_BIT), 1, &bindStat,
inMsg->SecurityUse );
}
/*********************************************************************
* @fn ZDO_UpdateAddrManager
*
* @brief Update the Address Manager.
*
* @param nwkAddr - network address
* @param extAddr - extended address
*
* @return none
*/
void ZDO_UpdateAddrManager( uint16 nwkAddr, uint8 *extAddr )
{
AddrMgrEntry_t addrEntry;
// Update the address manager
addrEntry.user = ADDRMGR_USER_DEFAULT;
addrEntry.nwkAddr = nwkAddr;
AddrMgrExtAddrSet( addrEntry.extAddr, extAddr );
AddrMgrEntryUpdate( &addrEntry );
}
#if defined ( ZDO_SERVERDISC_RESPONSE )
/*********************************************************************
* @fn ZDO_ProcessServerDiscReq
*
* @brief Process the Server_Discovery_req message.
*
* @param inMsg - incoming message (request)
*
* @return none
*/
void ZDO_ProcessServerDiscReq( zdoIncomingMsg_t *inMsg )
{
uint16 serverMask = BUILD_UINT16( inMsg->asdu[0], inMsg->asdu[1] );
uint16 matchMask = serverMask & ZDO_Config_Node_Descriptor.ServerMask;
if ( matchMask )
{
ZDP_ServerDiscRsp( inMsg->TransSeq, &(inMsg->srcAddr), ZSUCCESS,
ZDAppNwkAddr.addr.shortAddr, matchMask, inMsg->SecurityUse );
}
}
#endif
/*********************************************************************
* Call Back Functions from APS - API
*/
/*********************************************************************
* @fn ZDO_EndDeviceTimeoutCB
*
* @brief This function handles the binding timer for the End
* Device Bind command.
*
* @param none
*
* @return none
*/
void ZDO_EndDeviceTimeoutCB( void )
{
#if defined ( REFLECTOR )
byte stat;
if ( ZDO_EDBind )
{
stat = ZDO_EDBind->status;
// Send the response message to the first sent
ZDO_SendEDBindRsp( ZDO_EDBind->SrcTransSeq, &(ZDO_EDBind->SrcAddr),
stat, ZDO_EDBind->SecurityUse );
ZDO_RemoveEndDeviceBind();
}
#endif // REFLECTOR
}
/*********************************************************************
* Optional Management Messages
*/
#if defined( ZDO_MGMT_LQI_RESPONSE ) && defined ( RTR_NWK )
/*********************************************************************
* @fn ZDO_ProcessMgmtLqiReq
*
* @brief This function handles parsing the incoming Management
* LQI request and generate the response.
*
* Note: This function will limit the number of items returned
* to ZDO_MAX_LQI_ITEMS items.
*
* @param inMsg - incoming message (request)
*
* @return none
*/
void ZDO_ProcessMgmtLqiReq( zdoIncomingMsg_t *inMsg )
{
byte x;
byte index;
byte numItems;
byte maxItems;
ZDP_MgmtLqiItem_t* table;
ZDP_MgmtLqiItem_t* item;
neighborEntry_t entry;
byte aItems;
associated_devices_t *aDevice;
uint8 StartIndex = inMsg->asdu[0];
// Get the number of neighbor items
NLME_GetRequest( nwkNumNeighborTableEntries, 0, &maxItems );
// Get the number of associated items
aItems = (uint8)AssocCount( PARENT, CHILD_FFD_RX_IDLE );
// Total number of items
maxItems += aItems;
// Start with the supplied index
numItems = maxItems - StartIndex;
// limit the size of the list
if ( numItems > ZDO_MAX_LQI_ITEMS )
numItems = ZDO_MAX_LQI_ITEMS;
// Allocate the memory to build the table
table = (ZDP_MgmtLqiItem_t*)osal_mem_alloc( (short)
( numItems * sizeof( ZDP_MgmtLqiItem_t ) ) );
if ( table != NULL )
{
x = 0;
item = table;
index = StartIndex;
// Loop through associated items and build list
for ( ; x < numItems; x++ )
{
if ( index < aItems )
{
// get next associated device
aDevice = AssocFindDevice( index++ );
// set basic fields
item->panID = _NIB.nwkPanId;
osal_cpyExtAddr( item->extPanID, _NIB.extendedPANID );
item->nwkAddr = aDevice->shortAddr;
item->permit = ZDP_MGMT_BOOL_UNKNOWN;
item->depth = 0xFF;
item->lqi = aDevice->linkInfo.rxCost;
osal_memset( item->extAddr, 0x00, Z_EXTADDR_LEN );
// use association info to set other fields
if ( aDevice->nodeRelation == PARENT )
{
if ( aDevice->shortAddr == 0 )
{
item->devType = ZDP_MGMT_DT_COORD;
}
else
{
item->devType = ZDP_MGMT_DT_ROUTER;
}
item->rxOnIdle = ZDP_MGMT_BOOL_UNKNOWN;
item->relation = ZDP_MGMT_REL_PARENT;
}
else
{
if ( aDevice->nodeRelation < CHILD_FFD )
{
item->devType = ZDP_MGMT_DT_ENDDEV;
if ( aDevice->nodeRelation == CHILD_RFD )
{
item->rxOnIdle = FALSE;
}
else
{
item->rxOnIdle = TRUE;
}
}
else
{
item->devType = ZDP_MGMT_DT_ROUTER;
if ( aDevice->nodeRelation == CHILD_FFD )
{
item->rxOnIdle = FALSE;
}
else
{
item->rxOnIdle = TRUE;
}
}
item->relation = ZDP_MGMT_REL_CHILD;
}
item++;
}
else
{
if ( StartIndex <= aItems )
// Start with 1st neighbor
index = 0;
else
// Start with >1st neighbor
index = StartIndex - aItems;
break;
}
}
// Loop through neighbor items and finish list
for ( ; x < numItems; x++ )
{
// Add next neighbor table item
NLME_GetRequest( nwkNeighborTable, index++, &entry );
// set ZDP_MgmtLqiItem_t fields
item->panID = entry.panId;
osal_memset( item->extPanID, 0x00, Z_EXTADDR_LEN);
osal_memset( item->extAddr, 0x00, Z_EXTADDR_LEN );
item->nwkAddr = entry.neighborAddress;
item->rxOnIdle = ZDP_MGMT_BOOL_UNKNOWN;
item->relation = ZDP_MGMT_REL_UNKNOWN;
item->permit = ZDP_MGMT_BOOL_UNKNOWN;
item->depth = 0xFF;
item->lqi = entry.linkInfo.rxCost;
if ( item->nwkAddr == 0 )
{
item->devType = ZDP_MGMT_DT_COORD;
}
else
{
item->devType = ZDP_MGMT_DT_ROUTER;
}
item++;
}
// Send response
ZDP_MgmtLqiRsp( inMsg->TransSeq, &(inMsg->srcAddr), ZSuccess, maxItems,
StartIndex, numItems, table, false );
osal_mem_free( table );
}
}
#endif // ZDO_MGMT_LQI_RESPONSE && RTR_NWK
#if defined( ZDO_MGMT_NWKDISC_RESPONSE )
/*********************************************************************
* @fn ZDO_ProcessMgmtNwkDiscReq
*
* @brief This function handles parsing the incoming Management
* Network Discover request and starts the request.
*
* @param inMsg - incoming message (request)
*
* @return none
*/
void ZDO_ProcessMgmtNwkDiscReq( zdoIncomingMsg_t *inMsg )
{
NLME_ScanFields_t scan;
uint8 index;
uint8 *msg;
msg = inMsg->asdu;
scan.channels = BUILD_UINT32( msg[0], msg[1], msg[2], msg[3] );
msg += 4;
scan.duration = *msg++;
index = *msg;
// Save off the information to be used for the response
zdappMgmtNwkDiscReqInProgress = true;
zdappMgmtNwkDiscRspAddr.addrMode = Addr16Bit;
zdappMgmtNwkDiscRspAddr.addr.shortAddr = inMsg->srcAddr.addr.shortAddr;
zdappMgmtNwkDiscStartIndex = index;
zdappMgmtNwkDiscRspTransSeq = inMsg->TransSeq;
if ( NLME_NwkDiscReq2( &scan ) != ZSuccess )
{
NLME_NwkDiscTerm();
// zdappMgmtNwkDiscReqInProgress will be reset in the confirm callback
}
}
#endif // ZDO_MGMT_NWKDISC_RESPONSE
#if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
/*********************************************************************
* @fn ZDO_FinishProcessingMgmtNwkDiscReq
*
* @brief This function finishes the processing of the Management
* Network Discover Request and generates the response.
*
* Note: This function will limit the number of items returned
* to ZDO_MAX_NWKDISC_ITEMS items.
*
* @param ResultCountSrcAddr - source of the request
* @param msg - pointer to incoming message
* @param SecurityUse -
*
* @return none
*/
void ZDO_FinishProcessingMgmtNwkDiscReq( byte ResultCount,
networkDesc_t *NetworkList )
{
byte count;
#if defined ( RTR_NWK )
networkDesc_t *newDesc, *pList = NetworkList;
// Look for my PanID.
while ( pList )
{
if ( pList->panId == _NIB.nwkPanId )
{
break;
}
if ( !pList->nextDesc )
{
break;
}
pList = pList->nextDesc;
}
// If my Pan not present (query to a star network ZC or an isolated ZR?),
// prepend it.
if ( !pList || (pList->panId != _NIB.nwkPanId) )
{
newDesc = (networkDesc_t *)osal_mem_alloc( sizeof( networkDesc_t ) );
if ( newDesc )
{
byte pJoin;
newDesc->panId = _NIB.nwkPanId;
newDesc->logicalChannel = _NIB.nwkLogicalChannel;
newDesc->beaconOrder = _NIB.beaconOrder;
newDesc->superFrameOrder = _NIB.superFrameOrder;
newDesc->version = NLME_GetProtocolVersion();
newDesc->stackProfile = zgStackProfile;
//Extended PanID
osal_cpyExtAddr( newDesc->extendedPANID, _NIB.extendedPANID);
ZMacGetReq( ZMacAssociationPermit, &pJoin );
newDesc->chosenRouter = ((pJoin) ? ZDAppNwkAddr.addr.shortAddr :
INVALID_NODE_ADDR);
newDesc->nextDesc = NetworkList;
NetworkList = newDesc;
ResultCount++;
}
}
#endif
// Calc the count and apply a max count.
if ( zdappMgmtNwkDiscStartIndex > ResultCount )
{
count = 0;
}
else
{
count = ResultCount - zdappMgmtNwkDiscStartIndex;
if ( count > ZDO_MAX_NWKDISC_ITEMS )
{
count = ZDO_MAX_NWKDISC_ITEMS;
}
// Move the list pointer up to the start index.
NetworkList += zdappMgmtNwkDiscStartIndex;
}
ZDP_MgmtNwkDiscRsp( zdappMgmtNwkDiscRspTransSeq,
&zdappMgmtNwkDiscRspAddr, ZSuccess, ResultCount,
zdappMgmtNwkDiscStartIndex,
count,
NetworkList,
false );
#if defined ( RTR_NWK )
if ( newDesc )
{
osal_mem_free( newDesc );
}
#endif
NLME_NwkDiscTerm();
}
#endif
#if defined ( ZDO_MGMT_RTG_RESPONSE ) && defined ( RTR_NWK )
/*********************************************************************
* @fn ZDO_ProcessMgmtRtgReq
*
* @brief This function finishes the processing of the Management
* Routing Request and generates the response.
*
* Note: This function will limit the number of items returned
* to ZDO_MAX_RTG_ITEMS items.
*
* @param ResultCountSrcAddr - source of the request
* @param msg - pointer to incoming message
* @param SecurityUse -
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?