123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999 |
- /**************************************************************************************************
- Filename: MT_NWK.c
- Revised: $Date: 2010-05-06 16:49:18 -0700 (Thu, 06 May 2010) $
- Revision: $Revision: 22409 $
- Description: MonitorTest functions for the NWK layer.
- Copyright 2007-2010 Texas Instruments Incorporated. All rights reserved.
- IMPORTANT: Your use of this Software is limited to those specific rights
- granted under the terms of a software license agreement between the user
- who downloaded the software, his/her employer (which must be your employer)
- and Texas Instruments Incorporated (the "License"). You may not use this
- Software unless you agree to abide by the terms of the License. The License
- limits your use, and you acknowledge, that the Software may not be modified,
- copied or distributed unless embedded on a Texas Instruments microcontroller
- or used solely and exclusively in conjunction with a Texas Instruments radio
- frequency transceiver, which is integrated into your product. Other than for
- the foregoing purpose, you may not use, reproduce, copy, prepare derivative
- works of, modify, distribute, perform, display or sell this Software and/or
- its documentation for any purpose.
- YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
- PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
- INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
- NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
- TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
- NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
- LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
- INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
- OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
- OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
- (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
- Should you have any questions regarding your right to use this Software,
- contact Texas Instruments Incorporated at www.TI.com.
- **************************************************************************************************/
- /***************************************************************************************************
- * INCLUDES
- ***************************************************************************************************/
- #include "ZComDef.h"
- #include "MT.h"
- #include "MT_NWK.h"
- #include "NLMEDE.h"
- #include "nwk.h"
- #include "nwk_globals.h"
- #include "nwk_util.h"
- #include "OSAL.h"
- #include "ZDApp.h"
- #if !defined( WIN32 )
- #include "OnBoard.h"
- #endif
- /***************************************************************************************************
- * GLOBAL VARIABLES
- ***************************************************************************************************/
- uint16 _nwkCallbackSub;
- /*********************************************************************
- * TYPEDEFS
- */
- /***************************************************************************************************
- * LOCAL FUNCTIONS
- ***************************************************************************************************/
- #if defined (MT_NWK_FUNC)
- void MT_NldeDataRequest(uint8 *pBuf);
- void MT_NlmeNetworkFormationRequest(uint8 *pBuf);
- void MT_NlmePermitJoiningRequest(uint8 *pBuf);
- void MT_NlmeStartRouterRequest(uint8 *pBuf);
- void MT_NlmeJoinRequest(uint8 *pBuf);
- void MT_NlmeLeaveRequest(uint8 *pBuf);
- void MT_NlmeResetRequest(uint8 *pBuf);
- void MT_NlmeGetRequest(uint8 *pBuf);
- void MT_NlmeSetRequest(uint8 *pBuf);
- void MT_NlmeNetworkDiscoveryRequest(uint8 *pBuf);
- void MT_NlmeRouteDiscoveryRequest(uint8 *pBuf);
- void MT_NlmeDirectJoinRequest(uint8 *pBuf);
- void MT_NlmeOrphanJoinRequest(uint8 *pBuf);
- uint8 MT_Nwk_DataRequest( uint16 dstAddr, uint8 nsduLen, uint8* nsdu,
- uint8 nsduHandle, uint16 nsduHandleOptions,
- uint8 secure, uint8 discoverRoute,
- uint8 radius);
- #endif /* MT_NWK_FUNC */
- #if defined (MT_NWK_FUNC)
- /***************************************************************************************************
- * @fn MT_NwkCommandProcessing
- *
- * @brief
- *
- * Process all the NWK commands that are issued by test tool
- *
- * @param cmd_id - Command ID
- * @param len - Length of received SPI data message
- * @param pData - pointer to received SPI data message
- *
- * @return status
- ***************************************************************************************************/
- uint8 MT_NwkCommandProcessing(uint8 *pBuf)
- {
- uint8 status = MT_RPC_SUCCESS;
- switch (pBuf[MT_RPC_POS_CMD1])
- {
- case MT_NWK_INIT:
- nwk_init(NWK_TaskID);
- break;
- case MT_NLDE_DATA_REQ:
- MT_NldeDataRequest(pBuf);
- break;
- case MT_NLME_NETWORK_FORMATION_REQ:
- MT_NlmeNetworkFormationRequest(pBuf);
- break;
- case MT_NLME_PERMIT_JOINING_REQ:
- MT_NlmePermitJoiningRequest(pBuf);
- break;
- case MT_NLME_JOIN_REQ:
- MT_NlmeJoinRequest(pBuf);
- break;
- case MT_NLME_LEAVE_REQ:
- MT_NlmeLeaveRequest(pBuf);
- break;
- case MT_NLME_RESET_REQ:
- MT_NlmeResetRequest(pBuf);
- break;
- case MT_NLME_GET_REQ:
- MT_NlmeGetRequest(pBuf);
- break;
- case MT_NLME_SET_REQ:
- MT_NlmeSetRequest(pBuf);
- break;
- case MT_NLME_NETWORK_DISCOVERY_REQ:
- MT_NlmeNetworkDiscoveryRequest(pBuf);
- break;
- case MT_NLME_ROUTE_DISCOVERY_REQ:
- MT_NlmeRouteDiscoveryRequest(pBuf);
- break;
- case MT_NLME_DIRECT_JOIN_REQ:
- MT_NlmeDirectJoinRequest(pBuf);
- break;
- case MT_NLME_ORPHAN_JOIN_REQ:
- MT_NlmeOrphanJoinRequest(pBuf);
- break;
- case MT_NLME_START_ROUTER_REQ:
- MT_NlmeStartRouterRequest(pBuf);
- break;
- default:
- status = MT_RPC_ERR_COMMAND_ID;
- break;
- }
- return status;
- }
- /***************************************************************************************************
- * @fn MT_NldeDataReq
- *
- * @brief Process NLDE Data Request commands
- *
- * @param pBuf - pointer to received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NldeDataRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint16 dstAddr;
- uint8 dataLen = 0;
- uint8 *dataPtr;
- uint8 cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- /* First read the DstAddr */
- dstAddr = BUILD_UINT16( pBuf[0], pBuf[1] );
- pBuf += sizeof( dstAddr );
- /* Get the NSDU details */
- dataLen = *pBuf++;
- dataPtr = pBuf;
- /* Skip a length of ZTEST_DEFAULT_DATA_LEN */
- pBuf += ZTEST_DEFAULT_DATA_LEN;
- /* Send out Data Request */
- retValue = MT_Nwk_DataRequest(dstAddr, dataLen, dataPtr, pBuf[0], BUILD_UINT16(pBuf[1], pBuf[2]),
- pBuf[3], pBuf[4], pBuf[5]);
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeNetworkFormationRequest
- *
- * @brief Network Formation Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeNetworkFormationRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint16 panId;
- uint32 channelList;
- uint8 cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- /* Build panId */
- panId = BUILD_UINT16( pBuf[0], pBuf[1]);
- pBuf += sizeof(uint16);
-
- /* Build the channel list */
- channelList = osal_build_uint32(pBuf, 4);
- pBuf += sizeof(uint32);
- if ( ZG_BUILD_COORDINATOR_TYPE && ZG_DEVICE_COORDINATOR_TYPE )
- {
- retValue = NLME_NetworkFormationRequest( panId, NULL, channelList, pBuf[0], pBuf[1], pBuf[2], pBuf[3] );
- }
- else
- {
- retValue = ZUnsupportedMode;
- }
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmePermitJoiningRequest
- *
- * @brief Permit Joining Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmePermitJoiningRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint8 cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- if (ZSTACK_ROUTER_BUILD)
- {
- retValue = NLME_PermitJoiningRequest(*pBuf);
- }
- else
- {
- retValue = ZUnsupportedMode;
- }
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeStartRouterRequest
- *
- * @brief Start Router Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeStartRouterRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint8 cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- if ( ZSTACK_ROUTER_BUILD )
- {
- retValue = (uint8)NLME_StartRouterRequest(pBuf[0], pBuf[1], pBuf[2]);
- }
- else
- {
- retValue = ZUnsupportedMode;
- }
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeJoinRequest
- *
- * @brief Join Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeJoinRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint8 dummyExPANID[Z_EXTADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- uint16 panID;
- uint8 cmdId;
- networkDesc_t *pNwkDesc;
-
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- panID = BUILD_UINT16(pBuf[0], pBuf[1]);
-
- if((pNwkDesc = nwk_getNetworkDesc(dummyExPANID,panID, pBuf[2])) != NULL )
- {
- if (pNwkDesc->chosenRouter == INVALID_NODE_ADDR )
- {
- retValue = ZNwkNotPermitted;
- }
- else
- {
- retValue = NLME_JoinRequest( dummyExPANID, panID, pBuf[2], pBuf[3],
- pNwkDesc->chosenRouter, pNwkDesc->chosenRouterDepth );
- }
- }
- else
- {
- retValue = ZNwkNotPermitted;
- }
- if ( pBuf[3] & CAPINFO_RCVR_ON_IDLE )
- {
- /* The receiver is on, turn network layer polling off. */
- NLME_SetPollRate( 0 );
- NLME_SetQueuedPollRate( 0 );
- NLME_SetResponseRate( 0 );
- }
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeLeaveRequest
- *
- * @brief Leave Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeLeaveRequest(uint8 *pBuf)
- {
- NLME_LeaveReq_t req;
- uint8 retValue = ZFailure;
- uint8 index, cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- /* If extAddr is all zeros, it means null pointer */
- for(index=0;((index < Z_EXTADDR_LEN) && (pBuf[index] == 0));index++);
- if (index == Z_EXTADDR_LEN)
- {
- req.extAddr = NULL;
- }
- else
- {
- req.extAddr = pBuf;
- }
- /* Increment the pointer */
- pBuf += Z_EXTADDR_LEN;
- req.removeChildren = FALSE;
- req.rejoin = FALSE;
- req.silent = FALSE;
- retValue = NLME_LeaveReq(&req);
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeResetRequest
- *
- * @brief Leave Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeResetRequest(uint8 *pBuf)
- {
- uint8 retValue = NLME_ResetRequest();
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), MT_NLME_RESET_REQ, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeGetRequest
- *
- * @brief Get Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeGetRequest(uint8 *pBuf)
- {
- uint8 dataBuf[11];
- uint8 attr, index, cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- attr = *pBuf++;
- index = *pBuf;
- dataBuf[0] = NLME_GetRequest((ZNwkAttributes_t )attr, index, &dataBuf[1]);
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId,
- 11, dataBuf );
- }
- /***************************************************************************************************
- * @fn MT_NlmeSetRequest
- *
- * @brief Set Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeSetRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint8 cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- retValue = NLME_SetRequest((ZNwkAttributes_t)pBuf[0], pBuf[1], &pBuf[2]);
- /* Update NV */
- ZDApp_NVUpdate();
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue );
- }
- /***************************************************************************************************
- * @fn MT_NlmeNetworkDiscoveryRequest
- *
- * @brief Network Discovery Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeNetworkDiscoveryRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint8 cmdId;
- uint32 scanChannels;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- /* Scan channels */
- scanChannels = osal_build_uint32(pBuf, 4);
- pBuf += sizeof(uint32);
- retValue = NLME_NetworkDiscoveryRequest(scanChannels, *pBuf);
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue );
- }
- /***************************************************************************************************
- * @fn MT_NlmeRouteDiscoveryRequest
- *
- * @brief Route Discovery Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeRouteDiscoveryRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint8 cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- if ( ZSTACK_ROUTER_BUILD )
- {
- retValue = NLME_RouteDiscoveryRequest(BUILD_UINT16(pBuf[0], pBuf[1]), pBuf[2], pBuf[3]);
- }
- else
- {
- retValue = ZUnsupportedMode;
- }
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeDirectJoinRequest
- *
- * @brief Direct Join Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeDirectJoinRequest(uint8 *pBuf)
- {
- uint8 retValue = ZFailure;
- uint8 cmdId;
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- if ( ZSTACK_ROUTER_BUILD )
- {
- retValue = NLME_DirectJoinRequest( pBuf, pBuf[8] );
- }
- else
- {
- retValue = ZUnsupportedMode;
- }
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_NlmeOrphanJoinRequest
- *
- * @brief Orphan Join Request
- *
- * @param pBuf - pointer to the received buffer
- *
- * @return void
- ***************************************************************************************************/
- void MT_NlmeOrphanJoinRequest(uint8 *pBuf)
- {
- uint8 i, j, attr;
- uint8 retValue = ZFailure;
- uint32 channelList;
- uint8 cmdId;
- if ( ZSTACK_END_DEVICE_BUILD )
- {
- /* parse header */
- cmdId = pBuf[MT_RPC_POS_CMD1];
- pBuf += MT_RPC_FRAME_HDR_SZ;
- /* Channel list bit mask */
- channelList = osal_build_uint32(pBuf, 4);
- pBuf += sizeof(uint32);
- /* Count number of channels */
- j = attr = 0;
- for (i = 0; i < ED_SCAN_MAXCHANNELS; i++)
- {
- if (channelList & (1 << i))
- {
- j++;
- attr = i;
- }
- }
- /* If only one channel specified */
- if (j == 1)
- {
- _NIB.scanDuration = *pBuf;
- _NIB.nwkLogicalChannel = attr;
- _NIB.channelList = channelList;
- if ( !_NIB.CapabilityFlags )
- {
- _NIB.CapabilityFlags = ZDO_Config_Node_Descriptor.CapabilityFlags;
- }
- devState = DEV_NWK_ORPHAN;
- retValue = (uint8)NLME_OrphanJoinRequest(channelList, *pBuf);
- }
- else
- {
- retValue = ZNwkInvalidParam;
- }
- }
- else
- {
- retValue = ZUnsupportedMode;
- }
- /* Build and send back the response */
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_NWK), cmdId, 1, &retValue);
- }
- /***************************************************************************************************
- * @fn MT_Nwk_DataRequest
- *
- * @brief Nwk Data Request
- *
- * @param dstAddr, nsduLen, nsdu, nsduHandle, nsduHandleOptions, secure, discoverRoute, radius
- *
- * @return void
- ***************************************************************************************************/
- uint8 MT_Nwk_DataRequest(uint16 dstAddr, uint8 nsduLen, uint8* nsdu,
- uint8 nsduHandle, uint16 nsduHandleOptions,
- uint8 secure, uint8 discoverRoute,
- uint8 radius)
- {
- uint8 status;
- NLDE_DataReqAlloc_t dra;
- NLDE_DataReq_t* req;
- dra.overhead = sizeof(NLDE_DataReq_t);
- dra.nsduLen = nsduLen;
- dra.secure = secure;
- req = NLDE_DataReqAlloc(&dra);
- if ( req != NULL )
- {
- osal_memcpy(req->nfd.nsdu, nsdu, nsduLen);
- req->nfd.dstAddr = dstAddr;
- req->nfd.nsduHandleOptions = nsduHandleOptions;
- req->nfd.discoverRoute = discoverRoute;
- req->nfd.radius = radius;
- status = NLDE_DataReq( req );
- }
- else
- {
- status = ZMemError;
- }
- return status;
- }
- #endif /* MT_NWK_FUNC */
- #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(uint8 nsduHandle, ZStatus_t status)
- {
- uint8 buf[2];
- buf[0] = nsduHandle;
- buf[1] = (uint8)status;
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLDE_DATA_CONF, 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.
- *
- * @return none
- ***************************************************************************************************/
- void nwk_MTCallbackSubDataIndication(uint16 SrcAddress, int16 nsduLength, uint8 *nsdu, uint8 LinkQuality)
- {
- uint8 *msgPtr;
- uint8 *msg;
- uint8 msgLen;
- msgLen = sizeof( uint16 ) + sizeof( uint8 ) + ZTEST_DEFAULT_DATA_LEN
- + sizeof( uint8);
- msgPtr = osal_mem_alloc( msgLen );
- if ( msgPtr )
- {
- //Fill up the data bytes
- msg = msgPtr;
- //First fill in details
- *msg++ = LO_UINT16( SrcAddress );
- *msg++ = HI_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_BuildAndSendZToolResponse( ((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_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 )
- {
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLME_NETWORK_FORMATION_CONF,
- sizeof(uint8), (uint8*)&Status);
- }
- /***************************************************************************************************
- * @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_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLME_START_ROUTER_CONF,
- sizeof(uint8), (uint8*)&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)
- {
- uint8 msg[Z_EXTADDR_LEN + 3];
- /* This device's 64-bit address */
- ZMacGetReq( ZMacExtAddr, msg );
- msg[Z_EXTADDR_LEN + 0] = LO_UINT16(PanId);
- msg[Z_EXTADDR_LEN + 1] = HI_UINT16(PanId);
- msg[Z_EXTADDR_LEN + 2] = (uint8)Status;
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLME_JOIN_CONF, 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( uint8 ResultCount, networkDesc_t *NetworkList )
- {
- uint8 len;
- uint8 *msgPtr;
- uint8 *msg;
- uint8 i;
- // The message cannot be bigger then SPI_TX_BUFF_MAX. Reduce resultCount if necessary
- if (ResultCount * sizeof(networkDesc_t) > MT_UART_TX_BUFF_MAX - (1 + SPI_0DATA_MSG_LEN))
- {
- ResultCount = (MT_UART_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++ = LO_UINT16( NetworkList->panId );
- *msg++ = HI_UINT16( NetworkList->panId );
- *msg++ = NetworkList->logicalChannel;
- *msg++ = BEACON_ORDER_NO_BEACONS;
- *msg++ = BEACON_ORDER_NO_BEACONS;
- *msg++ = NetworkList->routerCapacity;
- *msg++ = NetworkList->deviceCapacity;
- *msg++ = NetworkList->version;
- *msg++ = NetworkList->stackProfile;
- //*msg++ = NetworkList->securityLevel;
-
- NetworkList = (networkDesc_t*)NetworkList->nextDesc;
- }
- MT_BuildAndSendZToolResponse (((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLME_NETWORK_DISCOVERY_CONF, 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 CapabilityFlags - Association Capability Information
- *
- * @return ZStatus_t
- ***************************************************************************************************/
- void nwk_MTCallbackSubJoinIndication( uint16 ShortAddress, uint8 *ExtendedAddress,
- uint8 CapabilityFlags )
- {
- uint8 *msgPtr;
- uint8 *msg;
- uint8 len;
- len = sizeof( uint16 ) + Z_EXTADDR_LEN + sizeof( uint8 );
- msgPtr = osal_mem_alloc( len );
- if ( msgPtr )
- {
- /* Fill up the data bytes */
- msg = msgPtr;
- /* First fill in details */
- *msg++ = LO_UINT16( ShortAddress );
- *msg++ = HI_UINT16( ShortAddress );
- osal_cpyExtAddr( msg, ExtendedAddress );
- msg += Z_EXTADDR_LEN;
- *msg = CapabilityFlags;
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_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( uint8 *DeviceAddress, ZStatus_t Status )
- {
- uint8 *msgPtr;
- uint8 *msg;
- msgPtr = osal_mem_alloc( Z_EXTADDR_LEN + sizeof( uint8 ) );
- if ( msgPtr )
- {
- /* Fill up the data bytes */
- msg = msgPtr;
- /* First fill in details */
- osal_cpyExtAddr( msg, DeviceAddress );
- msg += Z_EXTADDR_LEN;
- *msg = (uint8)Status;
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLME_LEAVE_CONF,
- Z_EXTADDR_LEN + sizeof( uint8 ), 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( uint8 *DeviceAddress )
- {
- uint8 msg[Z_EXTADDR_LEN+1];
- /* First fill in details */
- if ( DeviceAddress )
- {
- osal_cpyExtAddr( msg, DeviceAddress );
- }
- else
- {
- osal_memset( msg, 0, Z_EXTADDR_LEN );
- }
- /* Status, assume good if we get this far */
- msg[Z_EXTADDR_LEN] = 0;
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_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_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_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( uint8 status )
- {
- uint8 msg = status;
- MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLME_POLL_CONF, 1, &msg );
- }
- #endif /* NWK Callback commands */
- /***************************************************************************************************
- ***************************************************************************************************/
|