Example #1
0
/***************************************************************************************************
 * @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.CapabilityInfo )
      {
        _NIB.CapabilityInfo = 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);
}
Example #2
0
/*********************************************************************
 * @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  void
 */
void MT_NwkCommandProcessing( uint16 cmd_id , byte len , byte *pData )
{
  byte ret;
#if defined ( MT_NWK_FUNC )
  uint8 dummyExPANID[Z_EXTADDR_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  uint16 dstAddr;
#endif
#if defined ( MT_NWK_FUNC )  //NWK commands
  byte attr;
  byte index;
  byte dataLen;
  byte *dataPtr;
  uint32 channelList;
  byte databuf[SPI_RESP_LEN_NWK_DEFAULT + NWK_DEFAULT_GET_RESPONSE_LEN];
#if defined( ZDO_COORDINATOR )
	uint16 panId;
#else
  byte i,j;
#endif
#endif // MT_NWK_FUNC

  len = SPI_0DATA_MSG_LEN + SPI_RESP_LEN_NWK_DEFAULT;
	ret = (byte)ZSuccess;

  switch (cmd_id)
  {
#if defined( RTR_NWK )
    case SPI_CMD_NLME_PERMIT_JOINING_REQ:
      //The only information is PermitDuration
      ret = (byte)NLME_PermitJoiningRequest( *pData );
      break;
#endif

#if defined ( MT_NWK_FUNC )  //NWK commands
    case SPI_CMD_NWK_INIT:
      nwk_init( NWK_TaskID );
      break;

    case SPI_CMD_NLDE_DATA_REQ:
      //First read the DstAddr
      dstAddr = BUILD_UINT16( pData[1], pData[0] );
      pData += sizeof( dstAddr );

      //Get the NSDU details
      dataLen = *pData++;
      dataPtr = pData;

      /* For now, skip a length of ZTEST_DEFAULT_DATA_LEN, instead of dataLen.
         In future ZTOOL releases the data buffer will be only as long as dataLen */

      //pData += dataLen;
      pData += ZTEST_DEFAULT_DATA_LEN;

      /* pData[0] = NSDUHandlde
         pData[1] = NSDUHandleOptions
         pData[3] = SecurityEnable
         pData[4] = DiscoverRoute
         pData[5] = RadiusCounter */

      ret = (byte)MT_Nwk_DataRequest( dstAddr, dataLen, dataPtr, pData[0],
                                      BUILD_UINT16( pData[2], pData[1] ),
                                      pData[3], pData[4], pData[5]);
      break;

#if defined( ZDO_COORDINATOR )
    case SPI_CMD_NLME_INIT_COORD_REQ:
			panId = BUILD_UINT16( pData[1], pData[0] );
			
			MT_ReverseBytes( &pData[2], 4 );
			channelList = osal_build_uint32( &pData[2], 4 );

			ret = (byte)NLME_NetworkFormationRequest( panId, channelList, pData[6], pData[7],
                                                      pData[8], pData[9] );
      break;
#endif  // ZDO

#if defined( RTR_NWK )
    case SPI_CMD_NLME_START_ROUTER_REQ:
      // NOTE: first two parameters are not used, see NLMEDE.h for details
      ret = (byte)NLME_StartRouterRequest( pData[0], pData[1], pData[2] );
    break;
#endif  // RTR

    case SPI_CMD_NLME_JOIN_REQ:
		  ret = (byte)NLME_JoinRequest( dummyExPANID, BUILD_UINT16( pData[1], pData[0] ), pData[2], pData[3] );
      if ( pData[3] & CAPINFO_RCVR_ON_IDLE )
      {
        // The receiver is on, turn network layer polling off.
        NLME_SetPollRate( 0 );
        NLME_SetQueuedPollRate( 0 );
        NLME_SetResponseRate( 0 );
      }
      break;

    case SPI_CMD_NLME_LEAVE_REQ:
      {
        NLME_LeaveReq_t req;
        // if extAddr is all zeros, it means null pointer..
        for( index = 0; ( ( index < Z_EXTADDR_LEN ) &&
                        ( pData[index] == 0 ) ) ; index++ );
        if ( index == Z_EXTADDR_LEN )
        {
          req.extAddr = NULL;
        }
        else
        {
          MT_ReverseBytes( pData, Z_EXTADDR_LEN );
          req.extAddr = pData;
        }
        pData += Z_EXTADDR_LEN;

        req.removeChildren = FALSE;
        req.rejoin         = FALSE;
        req.silent         = FALSE;
        ret = (byte)NLME_LeaveReq( &req );
      }
      break;

    case SPI_CMD_NLME_RESET_REQ:
      //Its a direct call to reset NWK
      ret = (byte)NLME_ResetRequest();
      break;

    case SPI_CMD_NLME_GET_REQ:
      attr = *pData++;
      index = *pData;
			databuf[0] = (byte)NLME_GetRequest( (ZNwkAttributes_t )attr, index, &databuf[1] );
      len = SPI_0DATA_MSG_LEN + SPI_RESP_LEN_NWK_DEFAULT + NWK_DEFAULT_GET_RESPONSE_LEN;
      MT_BuildAndSendZToolResponse( len, (SPI_RESPONSE_BIT | SPI_CMD_NLME_GET_REQ),
            (SPI_RESP_LEN_NWK_DEFAULT + NWK_DEFAULT_GET_RESPONSE_LEN), databuf );
      return;   // Don't return to this function

    case SPI_CMD_NLME_SET_REQ:
      ret = (byte)NLME_SetRequest( (ZNwkAttributes_t)pData[0], pData[1], &pData[2] );
      osal_start_timerEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV, 1000 );
      break;

    case SPI_CMD_NLME_NWK_DISC_REQ:
      MT_ReverseBytes( pData, 4 );
      ret = (byte)NLME_NetworkDiscoveryRequest( osal_build_uint32( pData, 4 ), pData[4] );
      break;

#if !defined( ZDO_COORDINATOR )
    case SPI_CMD_NLME_ORPHAN_JOIN_REQ:
      // Channel list bit mask
      MT_ReverseBytes( pData, 4 );
      channelList = osal_build_uint32( pData, 4 );

      // 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 = pData[4];
        _NIB.nwkLogicalChannel = attr;
        _NIB.channelList = channelList;
        if ( !_NIB.CapabilityInfo )
          _NIB.CapabilityInfo = ZDO_Config_Node_Descriptor.CapabilityFlags;

        devState = DEV_NWK_ORPHAN;
        ret = (byte)NLME_OrphanJoinRequest( channelList, pData[4] );
      }
      else
        ret = ZNwkInvalidParam;
      break;
#endif  // !ZDO
	
#if defined (RTR_NWK)
    case SPI_CMD_NLME_ROUTE_DISC_REQ:
      ret = (byte)NLME_RouteDiscoveryRequest( BUILD_UINT16( pData[1], pData[0] ), pData[2] );
      break;
			
    case SPI_CMD_NLME_DIRECT_JOIN_REQ:
      MT_ReverseBytes( pData, 8 );
      ret = (byte)NLME_DirectJoinRequest( pData, pData[8] );
    break;
#endif	// RTR

#endif // MT_NWK_FUNC

    default:
      ret = (byte)ZUnsupportedMode;
      break;
  }

#if defined ( MT_NWK_FUNC )
	MT_SendSPIRespMsg( ret, cmd_id, len, SPI_RESP_LEN_NWK_DEFAULT );
#endif	
  (void)len;
  (void)ret;
}