123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941 |
- #include "ZComdef.h"
- #include "OSAL.h"
- #include "AF.h"
- #include "NLMEDE.h"
- #include "nwk_util.h"
- #include "APS.h"
- #include "AddrMgr.h"
- #include "ZDConfig.h"
- #include "ZDProfile.h"
- #include "ZDObject.h"
- #include "ZDNwkMgr.h"
- #if defined( LCD_SUPPORTED )
- #include "OnBoard.h"
- #endif
- #include "nwk_util.h"
- #if defined( MT_ZDO_FUNC )
- #include "MT_ZDO.h"
- #endif
- #define ZADDR_TO_AFADDR( pZADDR, AFADDR ) { \
- (AFADDR).endPoint = ZDP_AF_ENDPOINT; \
- (AFADDR).addrMode = (afAddrMode_t)(pZADDR)->addrMode; \
- (AFADDR).addr.shortAddr = (pZADDR)->addr.shortAddr; \
- }
- #define FillAndSendBuffer( TRANSSEQ, ADDR, ID, LEN, BUF ) { \
- afStatus_t stat; \
- ZDP_TmpBuf = (BUF)+1; \
- stat = fillAndSend( (TRANSSEQ), (ADDR), (ID), (LEN) ); \
- osal_mem_free( (BUF) ); \
- ZDP_TmpBuf = ZDP_Buf+1; \
- return stat; \
- }
- #define FillAndSendTxOptions( TRANSSEQ, ADDR, ID, LEN, TxO ) { \
- afStatus_t stat; \
- ZDP_TxOptions = (TxO); \
- stat = fillAndSend( (TRANSSEQ), (ADDR), (ID), (LEN) ); \
- ZDP_TxOptions = AF_TX_OPTIONS_NONE; \
- return stat; \
- }
- #define FillAndSendBufferTxOptions( TRANSSEQ, ADDR, ID, LEN, BUF, TxO ) { \
- afStatus_t stat; \
- ZDP_TmpBuf = (BUF)+1; \
- ZDP_TxOptions = (TxO); \
- stat = fillAndSend( (TRANSSEQ), (ADDR), (ID), (LEN) ); \
- osal_mem_free( (BUF) ); \
- ZDP_TmpBuf = ZDP_Buf+1; \
- ZDP_TxOptions = AF_TX_OPTIONS_NONE; \
- return stat; \
- }
- #define ZDP_BUF_SZ 80
- CONST byte ZDP_AF_ENDPOINT = 0;
- typedef struct
- {
- void *next;
- uint8 taskID;
- uint16 clusterID;
- } ZDO_MsgCB_t;
- byte ZDP_TransID = 0;
- extern endPointDesc_t ZDApp_epDesc;
- static afStatus_t fillAndSend( uint8 *transSeq, zAddrType_t *addr, cId_t clusterID, byte len );
- uint8 ZDO_SendMsgCBs( zdoIncomingMsg_t *inMsg );
- void zdpProcessAddrReq( zdoIncomingMsg_t *inMsg );
- static uint8 ZDP_Buf[ ZDP_BUF_SZ ];
- static uint8 *ZDP_TmpBuf = ZDP_Buf+1;
- byte ZDP_TxOptions = AF_TX_OPTIONS_NONE;
- ZDO_MsgCB_t *zdoMsgCBs = (ZDO_MsgCB_t *)NULL;
- typedef void (*pfnZDPMsgProcessor)( zdoIncomingMsg_t *inMsg );
- typedef struct
- {
- uint16 clusterID;
- pfnZDPMsgProcessor pFn;
- } zdpMsgProcItem_t;
- CONST zdpMsgProcItem_t zdpMsgProcs[] =
- {
- #if ( RFD_RCVC_ALWAYS_ON==TRUE ) || ( ZG_BUILD_RTR_TYPE )
-
- { NWK_addr_req, zdpProcessAddrReq },
- { Device_annce, ZDO_ProcessDeviceAnnce },
- #endif
- { IEEE_addr_req, zdpProcessAddrReq },
- { Node_Desc_req, ZDO_ProcessNodeDescReq },
- { Power_Desc_req, ZDO_ProcessPowerDescReq },
- { Simple_Desc_req, ZDO_ProcessSimpleDescReq },
- { Active_EP_req, ZDO_ProcessActiveEPReq },
- { Match_Desc_req, ZDO_ProcessMatchDescReq },
- #if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
- { Mgmt_NWK_Disc_req, ZDO_ProcessMgmtNwkDiscReq },
- #endif
- #if defined ( ZDO_MGMT_LQI_RESPONSE ) && ( ZG_BUILD_RTR_TYPE )
- { Mgmt_Lqi_req, ZDO_ProcessMgmtLqiReq },
- #endif
- #if defined ( ZDO_MGMT_RTG_RESPONSE ) && ( ZG_BUILD_RTR_TYPE )
- { Mgmt_Rtg_req, ZDO_ProcessMgmtRtgReq },
- #endif
- #if defined ( ZDO_MGMT_BIND_RESPONSE ) && defined ( REFLECTOR )
- { Mgmt_Bind_req, ZDO_ProcessMgmtBindReq },
- #endif
- #if defined ( ZDO_MGMT_JOINDIRECT_RESPONSE ) && ( ZG_BUILD_RTR_TYPE )
- { Mgmt_Direct_Join_req, ZDO_ProcessMgmtDirectJoinReq },
- #endif
- #if defined ( ZDO_MGMT_LEAVE_RESPONSE )
- { Mgmt_Leave_req, ZDO_ProcessMgmtLeaveReq },
- #endif
- #if defined ( ZDO_MGMT_PERMIT_JOIN_RESPONSE ) && ( ZG_BUILD_RTR_TYPE )
- { Mgmt_Permit_Join_req, ZDO_ProcessMgmtPermitJoinReq },
- #endif
- #if defined ( ZDO_USERDESC_RESPONSE )
- { User_Desc_req, ZDO_ProcessUserDescReq },
- #endif
- #if defined ( ZDO_USERDESCSET_RESPONSE )
- { User_Desc_set, ZDO_ProcessUserDescSet },
- #endif
- #if defined ( ZDO_SERVERDISC_RESPONSE )
- { Server_Discovery_req, ZDO_ProcessServerDiscReq },
- #endif
- {0xFFFF, NULL}
- };
- static afStatus_t fillAndSend( uint8 *transSeq, zAddrType_t *addr, cId_t clusterID, byte len )
- {
- afAddrType_t afAddr;
- osal_memset( &afAddr, 0, sizeof(afAddrType_t) );
- ZADDR_TO_AFADDR( addr, afAddr );
- *(ZDP_TmpBuf-1) = *transSeq;
- return AF_DataRequest( &afAddr, &ZDApp_epDesc, clusterID,
- (uint16)(len+1), (uint8*)(ZDP_TmpBuf-1),
- transSeq, ZDP_TxOptions, AF_DEFAULT_RADIUS );
- }
- afStatus_t ZDP_SendData( uint8 *TransSeq, zAddrType_t *dstAddr, uint16 cmd,
- byte len, uint8 *buf, byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte cnt = len;
- while ( cnt-- )
- {
- *pBuf++ = *buf++;
- }
- FillAndSendTxOptions( TransSeq, dstAddr, cmd, len, ((SecurityEnable) ? AF_EN_SECURITY : 0) );
- }
- afStatus_t ZDP_NWKAddrOfInterestReq( zAddrType_t *dstAddr, uint16 nwkAddr,
- byte cmd, byte SecurityEnable )
- {
- (void)SecurityEnable;
- ZDP_TmpBuf[0] = LO_UINT16( nwkAddr );
- ZDP_TmpBuf[1] = HI_UINT16( nwkAddr );
- return fillAndSend( &ZDP_TransID, dstAddr, cmd, 2 );
- }
- afStatus_t ZDP_NwkAddrReq( uint8 *IEEEAddress, byte ReqType,
- byte StartIndex, byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = Z_EXTADDR_LEN + 1 + 1;
- zAddrType_t dstAddr;
- (void)SecurityEnable;
- if ( osal_ExtAddrEqual( saveExtAddr, IEEEAddress ) == FALSE )
- {
- dstAddr.addrMode = AddrBroadcast;
- dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVRXON;
- }
- else
- {
- dstAddr.addrMode = Addr16Bit;
- dstAddr.addr.shortAddr = ZDAppNwkAddr.addr.shortAddr;
- }
- pBuf = osal_cpyExtAddr( pBuf, IEEEAddress );
- *pBuf++ = ReqType;
- *pBuf++ = StartIndex;
- return fillAndSend( &ZDP_TransID, &dstAddr, NWK_addr_req, len );
- }
- afStatus_t ZDP_IEEEAddrReq( uint16 shortAddr, byte ReqType,
- byte StartIndex, byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = 2 + 1 + 1;
- zAddrType_t dstAddr;
- (void)SecurityEnable;
- dstAddr.addrMode = (afAddrMode_t)Addr16Bit;
- dstAddr.addr.shortAddr = shortAddr;
- *pBuf++ = LO_UINT16( shortAddr );
- *pBuf++ = HI_UINT16( shortAddr );
- *pBuf++ = ReqType;
- *pBuf++ = StartIndex;
- return fillAndSend( &ZDP_TransID, &dstAddr, IEEE_addr_req, len );
- }
- afStatus_t ZDP_MatchDescReq( zAddrType_t *dstAddr, uint16 nwkAddr,
- uint16 ProfileID,
- byte NumInClusters, cId_t *InClusterList,
- byte NumOutClusters, cId_t *OutClusterList,
- byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
-
- byte i, len = 2 + 2 + 1 + 1;
- (void)SecurityEnable;
- len += (NumInClusters + NumOutClusters) * sizeof(uint16);
- if ( len >= ZDP_BUF_SZ-1 )
- {
- return afStatus_MEM_FAIL;
- }
-
-
-
-
- if ( ((dstAddr->addrMode == AddrBroadcast) || (dstAddr->addrMode == Addr16Bit))
- && (dstAddr->addr.shortAddr == NWK_BROADCAST_SHORTADDR_DEVALL) )
- {
- dstAddr->addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVRXON;
- }
- if ( nwkAddr == NWK_BROADCAST_SHORTADDR_DEVALL )
- {
- nwkAddr = NWK_BROADCAST_SHORTADDR_DEVRXON;
- }
-
- *pBuf++ = LO_UINT16( nwkAddr );
- *pBuf++ = HI_UINT16( nwkAddr );
- *pBuf++ = LO_UINT16( ProfileID );
- *pBuf++ = HI_UINT16( ProfileID );
- *pBuf++ = NumInClusters;
- if ( NumInClusters )
- {
- for (i=0; i<NumInClusters; ++i) {
- *pBuf++ = LO_UINT16( InClusterList[i] );
- *pBuf++ = HI_UINT16( InClusterList[i] );
- }
- }
- *pBuf++ = NumOutClusters;
- if ( NumOutClusters )
- {
- for (i=0; i<NumOutClusters; ++i) {
- *pBuf++ = LO_UINT16( OutClusterList[i] );
- *pBuf++ = HI_UINT16( OutClusterList[i] );
- }
- }
- return fillAndSend( &ZDP_TransID, dstAddr, Match_Desc_req, len );
- }
- afStatus_t ZDP_SimpleDescReq( zAddrType_t *dstAddr, uint16 nwkAddr,
- byte endPoint, byte SecurityEnable )
- {
- (void)SecurityEnable;
- ZDP_TmpBuf[0] = LO_UINT16( nwkAddr );
- ZDP_TmpBuf[1] = HI_UINT16( nwkAddr );
- ZDP_TmpBuf[2] = endPoint;
- return fillAndSend( &ZDP_TransID, dstAddr, Simple_Desc_req, 3 );
- }
- afStatus_t ZDP_UserDescSet( zAddrType_t *dstAddr, uint16 nwkAddr,
- UserDescriptorFormat_t *UserDescriptor,
- byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = (UserDescriptor->len < AF_MAX_USER_DESCRIPTOR_LEN) ?
- UserDescriptor->len : AF_MAX_USER_DESCRIPTOR_LEN;
- byte addrLen = 2;
- (void)SecurityEnable;
- *pBuf++ = LO_UINT16( nwkAddr );
- *pBuf++ = HI_UINT16( nwkAddr );
- *pBuf++ = len;
- addrLen = 3;
- pBuf = osal_memcpy( pBuf, UserDescriptor->desc, len );
- osal_memset( pBuf, AF_USER_DESCRIPTOR_FILL, AF_MAX_USER_DESCRIPTOR_LEN-len );
- return fillAndSend( &ZDP_TransID, dstAddr, User_Desc_set, (AF_MAX_USER_DESCRIPTOR_LEN + addrLen) );
- }
- afStatus_t ZDP_ServerDiscReq( uint16 serverMask, byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- zAddrType_t dstAddr;
- dstAddr.addrMode = AddrBroadcast;
- dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVRXON;
- *pBuf++ = LO_UINT16( serverMask );
- *pBuf = HI_UINT16( serverMask );
- FillAndSendTxOptions( &ZDP_TransID, &dstAddr, Server_Discovery_req, 2,
- ((SecurityEnable) ? AF_EN_SECURITY : AF_TX_OPTIONS_NONE) );
- }
- afStatus_t ZDP_DeviceAnnce( uint16 nwkAddr, uint8 *IEEEAddr,
- byte capabilities, byte SecurityEnable )
- {
- zAddrType_t dstAddr;
- uint8 len;
- (void)SecurityEnable;
- dstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
- dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVRXON;
- ZDP_TmpBuf[0] = LO_UINT16( nwkAddr );
- ZDP_TmpBuf[1] = HI_UINT16( nwkAddr );
- osal_cpyExtAddr( &ZDP_TmpBuf[2], IEEEAddr );
- len = 2 + Z_EXTADDR_LEN;
- ZDP_TmpBuf[10] = capabilities;
- len++;
- return fillAndSend( &ZDP_TransID, &dstAddr, Device_annce, len );
- }
- void zdpProcessAddrReq( zdoIncomingMsg_t *inMsg )
- {
- associated_devices_t *pAssoc;
- uint8 reqType;
- uint16 aoi = INVALID_NODE_ADDR;
- uint8 *ieee = NULL;
- reqType = inMsg->asdu[(inMsg->clusterID == NWK_addr_req) ? Z_EXTADDR_LEN : sizeof( uint16 ) ];
- if ( inMsg->clusterID == NWK_addr_req )
- {
- ieee = inMsg->asdu;
- if ( osal_ExtAddrEqual( saveExtAddr, ieee ) )
- {
- aoi = ZDAppNwkAddr.addr.shortAddr;
- }
-
- else if ( (ZSTACK_ROUTER_BUILD)
- && (((pAssoc = AssocGetWithExt( ieee )) != NULL)
- && (pAssoc->nodeRelation == CHILD_RFD)) )
- {
- aoi = pAssoc->shortAddr;
- if ( reqType != ZDP_ADDR_REQTYPE_SINGLE )
- reqType = 0xFF;
- }
- }
- else
- {
- aoi = BUILD_UINT16( inMsg->asdu[0], inMsg->asdu[1] );
- if ( aoi == ZDAppNwkAddr.addr.shortAddr )
- {
- ieee = saveExtAddr;
- }
- else if ( (ZSTACK_ROUTER_BUILD)
- && (((pAssoc = AssocGetWithShort( aoi )) != NULL)
- && (pAssoc->nodeRelation == CHILD_RFD)) )
- {
- AddrMgrEntry_t addrEntry;
- addrEntry.user = ADDRMGR_USER_DEFAULT;
- addrEntry.index = pAssoc->addrIdx;
- if ( AddrMgrEntryGet( &addrEntry ) )
- {
- ieee = addrEntry.extAddr;
- }
- if ( reqType != ZDP_ADDR_REQTYPE_SINGLE )
- reqType = 0xFF;
- }
- }
- if ( ((aoi != INVALID_NODE_ADDR) && (ieee != NULL)) || (inMsg->wasBroadcast == FALSE) )
- {
- uint8 stat;
- uint8 *pBuf = ZDP_TmpBuf;
-
- uint8 len = 1 + Z_EXTADDR_LEN + 2;
-
-
- if ( (aoi != INVALID_NODE_ADDR) && (ieee != NULL) )
- {
- stat = ((reqType == ZDP_ADDR_REQTYPE_SINGLE) || (reqType == ZDP_ADDR_REQTYPE_EXTENDED))
- ? ZDP_SUCCESS : ZDP_INVALID_REQTYPE;
- }
- else
- {
-
- stat = ZDP_DEVICE_NOT_FOUND;
-
-
- if ( inMsg->clusterID == NWK_addr_req )
- {
- aoi = ZDAppNwkAddr.addr.shortAddr;
- }
- else
- {
- ieee = saveExtAddr;
- }
- }
- *pBuf++ = stat;
- pBuf = osal_cpyExtAddr( pBuf, ieee );
- *pBuf++ = LO_UINT16( aoi );
- *pBuf++ = HI_UINT16( aoi );
- if ( ZSTACK_ROUTER_BUILD )
- {
- if ( (reqType == ZDP_ADDR_REQTYPE_EXTENDED) && (aoi == ZDAppNwkAddr.addr.shortAddr)
- && (stat == ZDP_SUCCESS) )
- {
- uint8 cnt = 0;
- uint16 *list = AssocMakeList( &cnt );
- if ( list != NULL )
- {
- byte idx = inMsg->asdu[(((inMsg->clusterID == NWK_addr_req) ? Z_EXTADDR_LEN : sizeof( uint16 )) + 1)];
- uint16 *pList = list + idx;
-
- if ( cnt > idx )
- {
- cnt -= idx;
- len += (cnt * sizeof( uint16 ));
- }
- else
- {
- cnt = 0;
- }
- *pBuf++ = cnt;
- len++;
-
- *pBuf++ = idx;
- len++;
- while ( cnt != 0 )
- {
- *pBuf++ = LO_UINT16( *pList );
- *pBuf++ = HI_UINT16( *pList );
- pList++;
- cnt--;
- }
- osal_mem_free( (uint8 *)list );
- }
- else
- {
-
- *pBuf++ = 0;
- len++;
- }
- }
- }
- ZDP_TxOptions = AF_MSG_ACK_REQUEST;
- fillAndSend( &(inMsg->TransSeq), &(inMsg->srcAddr), (cId_t)(inMsg->clusterID | ZDO_RESPONSE_BIT), len );
- ZDP_TxOptions = AF_TX_OPTIONS_NONE;
- }
- }
- afStatus_t ZDP_NodeDescMsg( zdoIncomingMsg_t *inMsg,
- uint16 nwkAddr, NodeDescriptorFormat_t *pNodeDesc )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len;
- len = 1 + 2 + 13;
- *pBuf++ = ZDP_SUCCESS;
- *pBuf++ = LO_UINT16( nwkAddr );
- *pBuf++ = HI_UINT16( nwkAddr );
- *pBuf++ = (byte)((pNodeDesc->ComplexDescAvail << 3) |
- (pNodeDesc->UserDescAvail << 4) |
- (pNodeDesc->LogicalType & 0x07));
- *pBuf++ = (byte)((pNodeDesc->FrequencyBand << 3) | (pNodeDesc->APSFlags & 0x07));
- *pBuf++ = pNodeDesc->CapabilityFlags;
- *pBuf++ = pNodeDesc->ManufacturerCode[0];
- *pBuf++ = pNodeDesc->ManufacturerCode[1];
- *pBuf++ = pNodeDesc->MaxBufferSize;
- *pBuf++ = pNodeDesc->MaxInTransferSize[0];
- *pBuf++ = pNodeDesc->MaxInTransferSize[1];
- *pBuf++ = LO_UINT16( pNodeDesc->ServerMask );
- *pBuf++ = HI_UINT16( pNodeDesc->ServerMask );
- *pBuf++ = pNodeDesc->MaxOutTransferSize[0];
- *pBuf++ = pNodeDesc->MaxOutTransferSize[1];
- *pBuf = pNodeDesc->DescriptorCapability;
- return fillAndSend( &(inMsg->TransSeq), &(inMsg->srcAddr), Node_Desc_rsp, len );
- }
- afStatus_t ZDP_PowerDescMsg( zdoIncomingMsg_t *inMsg,
- uint16 nwkAddr, NodePowerDescriptorFormat_t *pPowerDesc )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = 1 + 2 + 2;
- *pBuf++ = ZDP_SUCCESS;
- *pBuf++ = LO_UINT16( nwkAddr );
- *pBuf++ = HI_UINT16( nwkAddr );
- *pBuf++ = (byte)((pPowerDesc->AvailablePowerSources << 4)
- | (pPowerDesc->PowerMode & 0x0F));
- *pBuf++ = (byte)((pPowerDesc->CurrentPowerSourceLevel << 4)
- | (pPowerDesc->CurrentPowerSource & 0x0F));
- return fillAndSend( &(inMsg->TransSeq), &(inMsg->srcAddr), Power_Desc_rsp, len );
- }
- afStatus_t ZDP_SimpleDescMsg( zdoIncomingMsg_t *inMsg, byte Status,
- SimpleDescriptionFormat_t *pSimpleDesc )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- uint8 i, len;
- if ( Status == ZDP_SUCCESS && pSimpleDesc )
- {
-
- len = 1 + 2 + 1 + 8;
- len += (pSimpleDesc->AppNumInClusters + pSimpleDesc->AppNumOutClusters) * sizeof ( uint16 );
- }
- else
- {
- len = 1 + 2 + 1;
- }
- if ( len >= ZDP_BUF_SZ-1 )
- {
- return afStatus_MEM_FAIL;
- }
- *pBuf++ = Status;
- *pBuf++ = LO_UINT16( ZDAppNwkAddr.addr.shortAddr );
- *pBuf++ = HI_UINT16( ZDAppNwkAddr.addr.shortAddr );
- if ( len > 4 )
- {
- *pBuf++ = len - 4;
- *pBuf++ = pSimpleDesc->EndPoint;
- *pBuf++ = LO_UINT16( pSimpleDesc->AppProfId );
- *pBuf++ = HI_UINT16( pSimpleDesc->AppProfId );
- *pBuf++ = LO_UINT16( pSimpleDesc->AppDeviceId );
- *pBuf++ = HI_UINT16( pSimpleDesc->AppDeviceId );
- *pBuf++ = (byte)(pSimpleDesc->AppDevVer << 4);
- *pBuf++ = pSimpleDesc->AppNumInClusters;
- if ( pSimpleDesc->AppNumInClusters )
- {
- for (i=0; i<pSimpleDesc->AppNumInClusters; ++i)
- {
- *pBuf++ = LO_UINT16( pSimpleDesc->pAppInClusterList[i] );
- *pBuf++ = HI_UINT16( pSimpleDesc->pAppInClusterList[i] );
- }
- }
- *pBuf++ = pSimpleDesc->AppNumOutClusters;
- if ( pSimpleDesc->AppNumOutClusters )
- {
- for (i=0; i<pSimpleDesc->AppNumOutClusters; ++i)
- {
- *pBuf++ = LO_UINT16( pSimpleDesc->pAppOutClusterList[i] );
- *pBuf++ = HI_UINT16( pSimpleDesc->pAppOutClusterList[i] );
- }
- }
- }
- else
- {
- *pBuf = 0;
- }
- return fillAndSend( &(inMsg->TransSeq), &(inMsg->srcAddr), Simple_Desc_rsp, len );
- }
- afStatus_t ZDP_EPRsp( uint16 MsgType, byte TransSeq, zAddrType_t *dstAddr,
- byte Status, uint16 nwkAddr, byte Count,
- uint8 *pEPList,
- byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = 1 + 2 + 1;
- byte txOptions;
- (void)SecurityEnable;
- if ( MsgType == Match_Desc_rsp )
- txOptions = AF_MSG_ACK_REQUEST;
- else
- txOptions = 0;
- *pBuf++ = Status;
- *pBuf++ = LO_UINT16( nwkAddr );
- *pBuf++ = HI_UINT16( nwkAddr );
- *pBuf++ = Count;
- if ( Count )
- {
- len += Count;
- osal_memcpy( pBuf, pEPList, Count );
- }
- FillAndSendTxOptions( &TransSeq, dstAddr, MsgType, len, txOptions );
- }
- ZStatus_t ZDP_UserDescRsp( byte TransSeq, zAddrType_t *dstAddr,
- uint16 nwkAddrOfInterest, UserDescriptorFormat_t *userDesc,
- byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = 1 + 2 + 1;
- (void)SecurityEnable;
- len += userDesc->len;
- *pBuf++ = ZSUCCESS;
- *pBuf++ = LO_UINT16( nwkAddrOfInterest );
- *pBuf++ = HI_UINT16( nwkAddrOfInterest );
- *pBuf++ = userDesc->len;
- osal_memcpy( pBuf, userDesc->desc, userDesc->len );
- return (ZStatus_t)fillAndSend( &TransSeq, dstAddr, User_Desc_rsp, len );
- }
- ZStatus_t ZDP_ServerDiscRsp( byte transID, zAddrType_t *dstAddr, byte status,
- uint16 aoi, uint16 serverMask, byte SecurityEnable )
- {
- const byte len = 1 + 2;
- uint8 *pBuf = ZDP_TmpBuf;
- ZStatus_t stat;
-
- (void)aoi;
- (void)SecurityEnable;
- *pBuf++ = status;
- *pBuf++ = LO_UINT16( serverMask );
- *pBuf++ = HI_UINT16( serverMask );
- ZDP_TxOptions = AF_MSG_ACK_REQUEST;
- stat = fillAndSend( &transID, dstAddr, Server_Discovery_rsp, len );
- ZDP_TxOptions = AF_TX_OPTIONS_NONE;
- return ( stat );
- }
- afStatus_t ZDP_GenericRsp( byte TransSeq, zAddrType_t *dstAddr,
- byte status, uint16 aoi, uint16 rspID, byte SecurityEnable )
- {
- uint8 len;
- (void)SecurityEnable;
- ZDP_TmpBuf[0] = status;
- ZDP_TmpBuf[1] = LO_UINT16( aoi );
- ZDP_TmpBuf[2] = HI_UINT16( aoi );
-
- ZDP_TmpBuf[3] = 0;
- len = 4;
- return fillAndSend( &TransSeq, dstAddr, rspID, len );
- }
- afStatus_t ZDP_EndDeviceBindReq( zAddrType_t *dstAddr,
- uint16 LocalCoordinator,
- byte endPoint,
- uint16 ProfileID,
- byte NumInClusters, cId_t *InClusterList,
- byte NumOutClusters, cId_t *OutClusterList,
- byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- uint8 i, len;
- uint8 *ieeeAddr;
- (void)SecurityEnable;
-
- len = 2 + Z_EXTADDR_LEN + 1 + 2 + 1 + 1;
- len += (NumInClusters + NumOutClusters) * sizeof ( uint16 );
- if ( len >= ZDP_BUF_SZ-1 )
- {
- return afStatus_MEM_FAIL;
- }
- if ( LocalCoordinator != NLME_GetShortAddr() )
- {
- return afStatus_INVALID_PARAMETER;
- }
- *pBuf++ = LO_UINT16( LocalCoordinator );
- *pBuf++ = HI_UINT16( LocalCoordinator );
- ieeeAddr = NLME_GetExtAddr();
- pBuf = osal_cpyExtAddr( pBuf, ieeeAddr );
- *pBuf++ = endPoint;
- *pBuf++ = LO_UINT16( ProfileID );
- *pBuf++ = HI_UINT16( ProfileID );
- *pBuf++ = NumInClusters;
- for ( i = 0; i < NumInClusters; ++i )
- {
- *pBuf++ = LO_UINT16(InClusterList[i]);
- *pBuf++ = HI_UINT16(InClusterList[i]);
- }
- *pBuf++ = NumOutClusters;
- for ( i = 0; i < NumOutClusters; ++i )
- {
- *pBuf++ = LO_UINT16(OutClusterList[i]);
- *pBuf++ = HI_UINT16(OutClusterList[i]);
- }
- return fillAndSend( &ZDP_TransID, dstAddr, End_Device_Bind_req, len );
- }
- afStatus_t ZDP_BindUnbindReq( uint16 BindOrUnbind, zAddrType_t *dstAddr,
- uint8 *SourceAddr, byte SrcEndPoint,
- cId_t ClusterID,
- zAddrType_t *destinationAddr, byte DstEndPoint,
- byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len;
- (void)SecurityEnable;
-
- len = Z_EXTADDR_LEN + 1 + sizeof( cId_t ) + sizeof( uint8 );
- if ( destinationAddr->addrMode == Addr64Bit )
- len += Z_EXTADDR_LEN + 1;
- else if ( destinationAddr->addrMode == AddrGroup )
- len += sizeof ( uint16 );
- pBuf = osal_cpyExtAddr( pBuf, SourceAddr );
- *pBuf++ = SrcEndPoint;
- *pBuf++ = LO_UINT16( ClusterID );
- *pBuf++ = HI_UINT16( ClusterID );
- *pBuf++ = destinationAddr->addrMode;
- if ( destinationAddr->addrMode == Addr64Bit )
- {
- pBuf = osal_cpyExtAddr( pBuf, destinationAddr->addr.extAddr );
- *pBuf = DstEndPoint;
- }
- else if ( destinationAddr->addrMode == AddrGroup )
- {
- *pBuf++ = LO_UINT16( destinationAddr->addr.shortAddr );
- *pBuf++ = HI_UINT16( destinationAddr->addr.shortAddr );
- }
- FillAndSendTxOptions( &ZDP_TransID, dstAddr, BindOrUnbind, len, AF_MSG_ACK_REQUEST );
- }
- afStatus_t ZDP_MgmtNwkDiscReq( zAddrType_t *dstAddr,
- uint32 ScanChannels,
- byte ScanDuration,
- byte StartIndex,
- byte SecurityEnable )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = sizeof( uint32 )+1+1;
- (void)SecurityEnable;
- pBuf = osal_buffer_uint32( pBuf, ScanChannels );
- *pBuf++ = ScanDuration;
- *pBuf = StartIndex;
- return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_NWK_Disc_req, len );
- }
- afStatus_t ZDP_MgmtDirectJoinReq( zAddrType_t *dstAddr,
- uint8 *deviceAddr,
- byte capInfo,
- byte SecurityEnable )
- {
- (void)SecurityEnable;
- osal_cpyExtAddr( ZDP_TmpBuf, deviceAddr );
- ZDP_TmpBuf[Z_EXTADDR_LEN] = capInfo;
- return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_Direct_Join_req, (Z_EXTADDR_LEN + 1) );
- }
- afStatus_t ZDP_MgmtPermitJoinReq( zAddrType_t *dstAddr, byte duration,
- byte TcSignificance, byte SecurityEnable )
- {
- (void)SecurityEnable;
-
- ZDP_TmpBuf[ZDP_MGMT_PERMIT_JOIN_REQ_DURATION] = duration;
- ZDP_TmpBuf[ZDP_MGMT_PERMIT_JOIN_REQ_TC_SIG] = TcSignificance;
-
- return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_Permit_Join_req,
- ZDP_MGMT_PERMIT_JOIN_REQ_SIZE );
- }
- afStatus_t ZDP_MgmtLeaveReq( zAddrType_t *dstAddr, uint8 *IEEEAddr, uint8 RemoveChildren,
- uint8 Rejoin, uint8 SecurityEnable )
- {
- (void)SecurityEnable;
- osal_cpyExtAddr( ZDP_TmpBuf, IEEEAddr );
- ZDP_TmpBuf[Z_EXTADDR_LEN] = 0;
- if ( RemoveChildren == TRUE )
- {
- ZDP_TmpBuf[Z_EXTADDR_LEN] |= ZDP_MGMT_LEAVE_REQ_RC;
- }
- if ( Rejoin == TRUE )
- {
- ZDP_TmpBuf[Z_EXTADDR_LEN] |= ZDP_MGMT_LEAVE_REQ_REJOIN;
- }
- return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_Leave_req, (Z_EXTADDR_LEN + 1) );
- }
- afStatus_t ZDP_MgmtNwkUpdateReq( zAddrType_t *dstAddr,
- uint32 ChannelMask,
- uint8 ScanDuration,
- uint8 ScanCount,
- uint8 NwkUpdateId,
- uint16 NwkManagerAddr )
- {
- uint8 *pBuf = ZDP_TmpBuf;
- byte len = sizeof( uint32 ) + 1;
- pBuf = osal_buffer_uint32( pBuf, ChannelMask );
- *pBuf++ = ScanDuration;
- if ( ScanDuration <= 0x05 )
- {
-
- len += sizeof( uint8 );
- *pBuf++ = ScanCount;
- }
- else if ( ( ScanDuration == 0xFE ) || ( ScanDuration == 0xFF ) )
- {
-
- len += sizeof( uint8 );
- *pBuf++ = NwkUpdateId;
- if ( ScanDuration == 0xFF )
- {
- len += sizeof( uint16 );
- *pBuf++ = LO_UINT16( NwkManagerAddr );
- *pBuf++ = HI_UINT16( NwkManagerAddr );
- }
- }
- return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_NWK_Update_req, len );
- }
- afStatus_t ZDP_MgmtNwkDiscRsp( byte TransSeq, zAddrType_t *dstAddr,
- byte Status,
- byte NetworkCount,
- byte StartIndex,
- byte NetworkListCount,
- networkDesc_t *NetworkList,
- byte SecurityEnable )
- {
- uint8 *buf;
- uint8 *pBuf;
- byte len = 1+1+1+1;
- byte idx;
- (void)SecurityEnable;
- len += (NetworkListCount * ( ZDP_NETWORK_EXTENDED_DISCRIPTOR_SIZE - 2 ));
- buf = osal_mem_alloc( len+1 );
- if ( buf == NULL )
- {
- return afStatus_MEM_FAIL;
- }
- pBuf = buf+1;
- *pBuf++ = Status;
- *pBuf++ = NetworkCount;
- *pBuf++ = StartIndex;
- *pBuf++ = NetworkListCount;
- for ( idx = 0; idx < NetworkListCount; idx++ )
- {
- osal_cpyExtAddr( pBuf, NetworkList->extendedPANID);
- pBuf += Z_EXTADDR_LEN;
- *pBuf++ = NetworkList->logicalChannel;
- *pBuf = NetworkList->stackProfile;
- *pBuf++ |= (byte)(NetworkList->version << 4);
- *pBuf = BEACON_ORDER_NO_BEACONS;
- *pBuf++ |= (uint8)(BEACON_ORDER_NO_BEACONS << 4);
- if ( NetworkList->chosenRouter != INVALID_NODE_ADDR )
- {
- *pBuf++ = TRUE;
- }
- else
- {
- *pBuf++ = FALSE;
- }
- NetworkList = NetworkList->nextDesc;
- }
- FillAndSendBuffer( &TransSeq, dstAddr, Mgmt_NWK_Disc_rsp, len, buf );
- }
- ZStatus_t ZDP_MgmtLqiRsp( byte TransSeq, zAddrType_t *dstAddr,
- byte Status,
- byte NeighborLqiEntries,
- byte StartIndex,
- byte NeighborLqiCount,
- ZDP_MgmtLqiItem_t* NeighborList,
- byte SecurityEnable )
- {
- ZDP_MgmtLqiItem_t* list = NeighborList;
- uint8 *buf, *pBuf;
- byte len, x;
- (void)SecurityEnable;
- if ( ZSuccess != Status )
- {
- ZDP_TmpBuf[0] = Status;
- return fillAndSend( &TransSeq, dstAddr, Mgmt_Lqi_rsp, 1 );
- }
-
-
- len = (1 + 1 + 1 + 1) + (NeighborLqiCount * ZDP_MGMTLQI_EXTENDED_SIZE);
- buf = osal_mem_alloc( len+1 );
- if ( buf == NULL )
- {
- return afStatus_MEM_FAIL;
- }
- pBuf = buf+1;
- *pBuf++ = Status;
- *pBuf++ = NeighborLqiEntries;
- *pBuf++ = StartIndex;
- *pBuf++ = NeighborLqiCount;
- for ( x = 0; x < NeighborLqiCount; x++ )
- {
- osal_cpyExtAddr( pBuf, list->extPanID);
- pBuf += Z_EXTADDR_LEN;
-
- pBuf = osal_cpyExtAddr( pBuf, list->extAddr );
-
- *pBuf++ = LO_UINT16( list->nwkAddr );
- *pBuf++ = HI_UINT16( list->nwkAddr );
-
- *pBuf = list->devType;
-
- *pBuf |= (uint8)(list->rxOnIdle << 2);
-
- *pBuf++ |= (uint8)(list->relation << 4);
-
- *pBuf++ = (uint8)(list->permit);
-
- *pBuf++ = list->depth;
-
- *pBuf++ = list->lqi;
- list++;
- }
- FillAndSendBuffer( &TransSeq, dstAddr, Mgmt_Lqi_rsp, len, buf );
- }
- ZStatus_t ZDP_MgmtRtgRsp( byte TransSeq, zAddrType_t *dstAddr,
- byte Status,
- byte RoutingTableEntries,
- byte StartIndex,
- byte RoutingListCount,
- rtgItem_t *RoutingTableList,
- byte SecurityEnable )
- {
- uint8 *buf;
- uint8 *pBuf;
-
- byte len = 1 + 1 + 1 + 1;
- byte x;
- (void)SecurityEnable;
-
- len += (RoutingListCount * ZDP_ROUTINGENTRY_SIZE);
- buf = osal_mem_alloc( (short)(len+1) );
- if ( buf == NULL )
- {
- return afStatus_MEM_FAIL;
- }
- pBuf = buf+1;
- *pBuf++ = Status;
- *pBuf++ = RoutingTableEntries;
- *pBuf++ = StartIndex;
- *pBuf++ = RoutingListCount;
- for ( x = 0; x < RoutingListCount; x++ )
- {
- *pBuf++ = LO_UINT16( RoutingTableList->dstAddress );
- *pBuf++ = HI_UINT16( RoutingTableList->dstAddress );
- *pBuf++ = RoutingTableList->status;
- *pBuf++ = LO_UINT16( RoutingTableList->nextHopAddress );
- *pBuf++ = HI_UINT16( RoutingTableList->nextHopAddress );
- RoutingTableList++;
- }
- FillAndSendBuffer( &TransSeq, dstAddr, Mgmt_Rtg_rsp, len, buf );
- }
- ZStatus_t ZDP_MgmtBindRsp( byte TransSeq, zAddrType_t *dstAddr,
- byte Status,
- byte BindingTableEntries,
- byte StartIndex,
- byte BindingTableListCount,
- apsBindingItem_t *BindingTableList,
- byte SecurityEnable )
- {
- uint8 *buf;
- uint8 *pBuf;
- uint8 maxLen;
- uint8 len;
- uint8 x;
- byte extZdpBindEntrySize = ZDP_BINDINGENTRY_SIZE + 1 + 1;
- byte shortZdpBindEntrySize = ZDP_BINDINGENTRY_SIZE + 1 + 1 + 2 - 8 - 1;
- (void)SecurityEnable;
-
- maxLen = 1 + 1 + 1 + 1;
- maxLen += (BindingTableListCount * extZdpBindEntrySize );
- buf = osal_mem_alloc( maxLen + 1 );
- if ( buf == NULL )
- {
- return afStatus_MEM_FAIL;
- }
- pBuf = buf+1;
- *pBuf++ = Status;
- *pBuf++ = BindingTableEntries;
- *pBuf++ = StartIndex;
- *pBuf++ = BindingTableListCount;
-
-
-
-
- len = 1 + 1 + 1 + 1;
- for ( x = 0; x < BindingTableListCount; x++ )
- {
- pBuf = osal_cpyExtAddr( pBuf, BindingTableList->srcAddr );
- *pBuf++ = BindingTableList->srcEP;
-
- *pBuf++ = LO_UINT16( BindingTableList->clusterID );
- *pBuf++ = HI_UINT16( BindingTableList->clusterID );
- *pBuf++ = BindingTableList->dstAddr.addrMode;
- if ( BindingTableList->dstAddr.addrMode == Addr64Bit )
- {
- len += extZdpBindEntrySize;
- pBuf = osal_cpyExtAddr( pBuf, BindingTableList->dstAddr.addr.extAddr );
- *pBuf++ = BindingTableList->dstEP;
- }
- else
- {
- len += shortZdpBindEntrySize;
- *pBuf++ = LO_UINT16( BindingTableList->dstAddr.addr.shortAddr );
- *pBuf++ = HI_UINT16( BindingTableList->dstAddr.addr.shortAddr );
- }
- BindingTableList++;
- }
- FillAndSendBuffer( &TransSeq, dstAddr, Mgmt_Bind_rsp, len, buf );
- }
- afStatus_t ZDP_MgmtNwkUpdateNotify( uint8 TransSeq, zAddrType_t *dstAddr,
- uint8 status, uint32 scannedChannels,
- uint16 totalTransmissions, uint16 transmissionFailures,
- uint8 listCount, uint8 *energyValues, uint8 txOptions,
- uint8 securityEnable )
- {
- uint8 *buf;
- uint8 *pBuf;
- uint8 len;
- (void)securityEnable;
-
- len = 1 + 4 + 2 + 2 + 1 + listCount;
- buf = osal_mem_alloc( len+1 );
- if ( buf == NULL )
- {
- return afStatus_MEM_FAIL;
- }
- pBuf = buf+1;
- *pBuf++ = status;
- pBuf = osal_buffer_uint32( pBuf, scannedChannels );
- *pBuf++ = LO_UINT16( totalTransmissions );
- *pBuf++ = HI_UINT16( totalTransmissions );
- *pBuf++ = LO_UINT16( transmissionFailures );
- *pBuf++ = HI_UINT16( transmissionFailures );
- *pBuf++ = listCount;
- if ( listCount > 0 )
- osal_memcpy( pBuf, energyValues, listCount );
- FillAndSendBufferTxOptions( &TransSeq, dstAddr, Mgmt_NWK_Update_notify, len, buf, txOptions );
- }
- ZStatus_t ZDO_RegisterForZDOMsg( uint8 taskID, uint16 clusterID )
- {
- ZDO_MsgCB_t *pList;
- ZDO_MsgCB_t *pLast;
- ZDO_MsgCB_t *pNew;
-
- pList = pLast = zdoMsgCBs;
- while ( pList )
- {
- if ( pList->taskID == taskID && pList->clusterID == clusterID )
- return ( ZSuccess );
- pLast = pList;
- pList = (ZDO_MsgCB_t *)pList->next;
- }
-
- pNew = (ZDO_MsgCB_t *)osal_mem_alloc( sizeof ( ZDO_MsgCB_t ) );
- if ( pNew )
- {
- pNew->taskID = taskID;
- pNew->clusterID = clusterID;
- pNew->next = NULL;
- if ( zdoMsgCBs )
- {
- pLast->next = pNew;
- }
- else
- zdoMsgCBs = pNew;
- return ( ZSuccess );
- }
- else
- return ( ZMemError );
- }
- ZStatus_t ZDO_RemoveRegisteredCB( uint8 taskID, uint16 clusterID )
- {
- ZDO_MsgCB_t *pList;
- ZDO_MsgCB_t *pLast = NULL;
- pList = zdoMsgCBs;
- while ( pList )
- {
- if ( pList->taskID == taskID && pList->clusterID == clusterID )
- {
- if ( pLast )
- {
-
- pLast->next = pList->next;
- }
- else if ( pList->next )
- {
-
- zdoMsgCBs = pList->next;
- }
- else
- {
-
- zdoMsgCBs = (ZDO_MsgCB_t *)NULL;
- }
- osal_mem_free( pList );
- return ( ZSuccess );
- }
- pLast = pList;
- pList = pList->next;
- }
- return ( ZFailure );
- }
- uint8 ZDO_SendMsgCBs( zdoIncomingMsg_t *inMsg )
- {
- uint8 ret = FALSE;
- ZDO_MsgCB_t *pList = zdoMsgCBs;
- while ( pList )
- {
- if ( pList->clusterID == inMsg->clusterID )
- {
- zdoIncomingMsg_t *msgPtr;
-
- msgPtr = (zdoIncomingMsg_t *)osal_msg_allocate( sizeof( zdoIncomingMsg_t ) + inMsg->asduLen );
- if ( msgPtr )
- {
-
- osal_memcpy( msgPtr, inMsg, sizeof( zdoIncomingMsg_t ));
- if ( inMsg->asduLen )
- {
- msgPtr->asdu = (byte*)(((byte*)msgPtr) + sizeof( zdoIncomingMsg_t ));
- osal_memcpy( msgPtr->asdu, inMsg->asdu, inMsg->asduLen );
- }
- msgPtr->hdr.event = ZDO_CB_MSG;
- osal_msg_send( pList->taskID, (uint8 *)msgPtr );
- ret = TRUE;
- }
- }
- pList = (ZDO_MsgCB_t *)pList->next;
- }
- return ( ret );
- }
- void ZDP_IncomingData( afIncomingMSGPacket_t *pData )
- {
- uint8 x = 0;
- uint8 handled;
- zdoIncomingMsg_t inMsg;
- inMsg.srcAddr.addrMode = Addr16Bit;
- inMsg.srcAddr.addr.shortAddr = pData->srcAddr.addr.shortAddr;
- inMsg.wasBroadcast = pData->wasBroadcast;
- inMsg.clusterID = pData->clusterId;
- inMsg.SecurityUse = pData->SecurityUse;
- inMsg.asduLen = pData->cmd.DataLength-1;
- inMsg.asdu = pData->cmd.Data+1;
- inMsg.TransSeq = pData->cmd.Data[0];
- inMsg.macDestAddr = pData->macDestAddr;
- handled = ZDO_SendMsgCBs( &inMsg );
- #if (defined MT_ZDO_CB_FUNC)
- #if !defined MT_TASK
- if (zgZdoDirectCB)
- #endif
- {
- MT_ZdoDirectCB( pData, &inMsg );
- }
- #endif
- while ( zdpMsgProcs[x].clusterID != 0xFFFF )
- {
- if ( zdpMsgProcs[x].clusterID == inMsg.clusterID )
- {
- zdpMsgProcs[x].pFn( &inMsg );
- return;
- }
- x++;
- }
-
- if ( !handled )
- ZDApp_InMsgCB( &inMsg );
- }
|