Пример #1
0
/******************************************************************************
 * @fn          StubAPS_InterPan
 *
 * @brief       This function checks to see if a PAN is an Inter-PAN.
 *
 * @param       panId - PAN ID
 * @param       endPoint - endpoint
 *
 * @return      TRUE if PAN is Inter-PAN, FALSE otherwise
 */
uint8 StubAPS_InterPan( uint16 panId, uint8 endPoint )
{
  uint8 currChannel;
  
  if ( panId != 0 )
  {
    ZMacGetReq( ZMacChannel, &currChannel );
    if ( currChannel != _NIB.nwkLogicalChannel )
    {
      // different Channels
      return ( TRUE );
    }
  
    // same Channels
    if ( panId != _NIB.nwkPanId )
    {
      // different PAN IDs
      return ( TRUE );
    }
  
    // same Channels and same PAN IDs
    if ( endPoint == STUBAPS_INTER_PAN_EP )
    {
      // Inter-PAN endpoint
      return ( TRUE );
    }
  }
  
  return ( FALSE );
  
} /* StubAPS_InterPan */
Пример #2
0
/******************************************************************************
 * @fn          StubAPS_SetIntraPanChannel
 *
 * @brief       This function sets the device's channel back to the NIB channel.
 *
 * @param       none
 *
 * @return      ZStatus_t
 */
ZStatus_t StubAPS_SetIntraPanChannel( void )
{
  uint8 currChannel;
  uint8 rxOnIdle;

  if ( channelChangeInProgress )
    return ( ZFailure );

  ZMacGetReq( ZMacChannel, &currChannel );
  if ( currChannel == _NIB.nwkLogicalChannel )
    return ( ZSuccess );

  channelChangeInProgress = TRUE;

  // turn MAC receiver off
  rxOnIdle = false;
  ZMacSetReq( ZMacRxOnIdle, &rxOnIdle );

  // set the NIB channel
  ZMacSetReq( ZMacChannel, &(_NIB.nwkLogicalChannel) );

  // turn MAC receiver back on
  rxOnIdle = true;
  ZMacSetReq( ZMacRxOnIdle, &rxOnIdle );

  // set NWK task to run
  nwk_setStateIdle( FALSE );

  channelChangeInProgress = FALSE;

  return ( ZSuccess );

} /* StubAPS_SetIntraPanChannel */
/**************************************************************************************************
 * @fn      MT_SysStackTune
 *
 * @brief   ZAccel RPC interface for tuning the stack parameters to adjust performance
 *
 * @param   uint8 pData - Pointer to the data.
 *
 * @return  None
 *************************************************************************************************/
void MT_SysStackTune(uint8 *pBuf)
{
  uint8 cmd, rtrn;

  cmd = pBuf[MT_RPC_POS_CMD1];
  pBuf += MT_RPC_FRAME_HDR_SZ;

  switch (*pBuf++)
  {
  case STK_TX_PWR:
    rtrn = ZMacSetReq(ZMacPhyTransmitPowerSigned, pBuf);
    break;

  case STK_RX_ON_IDLE:
    if ((*pBuf != TRUE) && (*pBuf != FALSE))
    {
      (void)ZMacGetReq(ZMacRxOnIdle, &rtrn);
    }
    else
    {
      rtrn = ZMacSetReq(ZMacRxOnIdle, pBuf);
    }
    break;

  default:
    rtrn = ZInvalidParameter;
    break;
  }

  MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), cmd, 1, &rtrn);
}
Пример #4
0
/*********************************************************************
 * @fn          zgInit
 *
 * @brief
 *
 *   Initialize the Z-Stack Globals. If an item doesn't exist in
 *   NV memory, write the system default into NV memory. But if
 *   it exists, set the item to the value stored in NV memory.
 *
 * NOTE: The Startup Options (ZCD_NV_STARTUP_OPTION) indicate
 *       that the Config state items (zgItemTable) need to be
 *       set to defaults (ZCD_STARTOPT_DEFAULT_CONFIG_STATE). The
 *
 * @param       none
 *
 * @return      ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
 *              exist in NV, NV_OPER_FAILED if failure.
 */
uint8 zgInit( void )
{
  uint8  setDefault = FALSE;

  // Do we want to default the Config state values
  if ( zgReadStartupOptions() & ZCD_STARTOPT_DEFAULT_CONFIG_STATE )
  {
    setDefault = TRUE;
  }

#if defined ( FEATURE_SYSTEM_STATS )
  // This sections tracks the number of resets
  uint16 bootCnt = 0;

  // Update the Boot Counter
  if ( osal_nv_item_init( ZCD_NV_BOOTCOUNTER, sizeof(bootCnt), &bootCnt ) == ZSUCCESS )
  {
    // Get the old value from NV memory
    osal_nv_read( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
  }

  // Increment the Boot Counter and store it into NV memory
  if ( setDefault )
  {
    bootCnt = 0;
  }
  else
  {
    bootCnt++;
  }

  osal_nv_write( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
#endif  // FEATURE_SYSTEM_STATS

  // Initialize the Extended PAN ID as my own extended address
  ZMacGetReq( ZMacExtAddr, zgExtendedPANID );

  // Initialize the items table
  zgInitItems( setDefault );

#ifndef NONWK
  if ( ZG_SECURE_ENABLED )
  {
    // Initialize the Pre-Configured Key to the default key
    zgPreconfigKeyInit( setDefault );

    // Initialize NV items for all Keys: NWK, APS, TCLK and Master
    ZDSecMgrInitNVKeyTables( setDefault );
  }
#endif // NONWK

  // Clear the Config State default
  if ( setDefault )
  {
    zgWriteStartupOptions( ZG_STARTUP_CLEAR, ZCD_STARTOPT_DEFAULT_CONFIG_STATE );
  }

  return ( ZSUCCESS );
}
Пример #5
0
/*********************************************************************
 * @fn          zgInit
 *
 * @brief
 *
 *   Initialize the Z-Stack Globals. If an item doesn't exist in
 *   NV memory, write the system default into NV memory. But if
 *   it exists, set the item to the value stored in NV memory.
 *
 * NOTE: The Startup Options (ZCD_NV_STARTUP_OPTION) indicate
 *       that the Config state items (zgItemTable) need to be
 *       set to defaults (ZCD_STARTOPT_DEFAULT_CONFIG_STATE). The
 *
 *
 * @param       none
 *
 * @return      ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
 *              exist in NV, NV_OPER_FAILED if failure.
 */
uint8 zgInit( void )
{
  uint8  i = 0;
  uint8  setDefault = FALSE;

  // Do we want to default the Config state values
  if ( zgReadStartupOptions() & ZCD_STARTOPT_DEFAULT_CONFIG_STATE )
  {
    setDefault = TRUE;
  }

#if 0
  // Enable this section if you need to track the number of resets
  // This section is normally disabled to minimize "wear" on NV memory
  uint16 bootCnt = 0;

  // Update the Boot Counter
  if ( osal_nv_item_init( ZCD_NV_BOOTCOUNTER, sizeof(bootCnt), &bootCnt ) == ZSUCCESS )
  {
    // Get the old value from NV memory
    osal_nv_read( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
  }

  // Increment the Boot Counter and store it into NV memory
  if ( setDefault )
    bootCnt = 0;
  else
    bootCnt++;
  osal_nv_write( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
#endif

  // Initialize the Extended PAN ID as my own extended address
  ZMacGetReq( ZMacExtAddr, zgExtendedPANID );

#ifndef NONWK
  // Initialize the Pre-Configured Key to the default key
  osal_memcpy( zgPreConfigKey, defaultKey, SEC_KEY_LEN );  // Do NOT Change!!!
#endif // NONWK

  while ( zgItemTable[i].id != 0x00 )
  {
    // Initialize the item
    zgItemInit( zgItemTable[i].id, zgItemTable[i].len, zgItemTable[i].buf, setDefault  );

    // Move on to the next item
    i++;
  }

  // Clear the Config State default
  if ( setDefault )
  {
    zgWriteStartupOptions( ZG_STARTUP_CLEAR, ZCD_STARTOPT_DEFAULT_CONFIG_STATE );
  }

  return ( ZSUCCESS );
}
/***************************************************************************************************
 * @fn      MT_SysGetExtAddr
 *
 * @brief   Get the Extended Address
 *
 * @param   None
 *
 * @return  None
 ***************************************************************************************************/
void MT_SysGetExtAddr(void)
{
  uint8 extAddr[Z_EXTADDR_LEN];

  ZMacGetReq( ZMacExtAddr, extAddr );

  /* Build and send back the response */
  MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), MT_SYS_GET_EXTADDR,
                               Z_EXTADDR_LEN, extAddr);
}
Пример #7
0
/***************************************************************************************************
 * @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 );
}
Пример #8
0
/*********************************************************************
 * @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 );
}
Пример #9
0
/******************************************************************************
 * @fn          StubAPS_SetInterPanChannel
 *
 * @brief       This function changes the device's channel for inter-PAN communication.
 *
 * @param       channel - new channel
 *
 * @return      ZStatus_t
 */
ZStatus_t StubAPS_SetInterPanChannel( uint8 channel )
{
  uint8 currChannel;
  uint8 rxOnIdle;

  if ( channelChangeInProgress )
    return ( ZFailure );

  ZMacGetReq( ZMacChannel, &currChannel );
  if ( currChannel == channel )
  {
    // inter PANs communication within the same channel
    return ( ZSuccess );
  }

  // go into channel transition state
  channelChangeInProgress = TRUE;

  // set NWK task to idle
  nwk_setStateIdle( TRUE );

  // turn MAC receiver off
  rxOnIdle = false;
  ZMacSetReq( ZMacRxOnIdle, &rxOnIdle );

  // try to change to the new channel
  if ( StubAPS_SetNewChannel( channel ) == ZSuccess )
    return ( ZSuccess );

  // save the new channel for retry
  newChannel = channel;

  // ask StubAPS task to retry it later
  osal_start_timerEx( StubAPS_TaskID, CHANNEL_CHANGE_EVT, CHANNEL_CHANGE_RETRY_TIMEOUT );

  return ( ZApsNotAllowed );

} /* StubAPS_SetInterPanChannel */
Пример #10
0
/****************************************************************************
 * @fn          ZDiagsGetStatsAttr
 *
 * @brief       Reads specific systemID statistics and/or metrics
 *
 * @param       attributeId  input  - unique identifier for the required attribute
 *
 *   NOTE: the user of this function will have to cast the value
 *         based on the type of the attributeID, the returned value
 *         will allways be uint32.
 *
 * @return      Value of the attribute requested.
 */
uint32 ZDiagsGetStatsAttr( uint16 attributeId )
{
  uint32 diagsValue = 0;

#if defined ( FEATURE_SYSTEM_STATS )
  switch ( attributeId )
  {
    // System and Hardware Diagnostics
    case ZDIAGS_SYSTEM_CLOCK:
      // this is the system clock when statistics were cleared;
      diagsValue = DiagsStatsTable.SysClock;
      break;

    case ZDIAGS_NUMBER_OF_RESETS:
      // Get the value from NV memory
      osal_nv_read( ZCD_NV_BOOTCOUNTER, 0, sizeof(uint16), &diagsValue );
      break;

    case ZDIAGS_PERSISTENT_MEMORY_WRITES:
      diagsValue = DiagsStatsTable.PersistentMemoryWrites;
      break;

    // MAC Diagnostics
    case ZDIAGS_MAC_RX_CRC_PASS:
      ZMacGetReq( ZMacDiagsRxCrcPass, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacRxCrcPass = diagsValue;
      break;

    case ZDIAGS_MAC_RX_CRC_FAIL:
      ZMacGetReq( ZMacDiagsRxCrcFail, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacRxCrcFail = diagsValue;
      break;

    case ZDIAGS_MAC_RX_BCAST:
      ZMacGetReq( ZMacDiagsRxBcast, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacRxBcast = diagsValue;
      break;

    case ZDIAGS_MAC_TX_BCAST:
      ZMacGetReq( ZMacDiagsTxBcast, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacTxBcast = diagsValue;
      break;

    case ZDIAGS_MAC_RX_UCAST:
      ZMacGetReq( ZMacDiagsRxUcast, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacRxUcast = diagsValue;
      break;

    case ZDIAGS_MAC_TX_UCAST:
      ZMacGetReq( ZMacDiagsTxUcast, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacTxUcast = diagsValue;
      break;

    case ZDIAGS_MAC_TX_UCAST_RETRY:
      ZMacGetReq( ZMacDiagsTxUcastRetry, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacTxUcastRetry = diagsValue;
      break;

    case ZDIAGS_MAC_TX_UCAST_FAIL:
      ZMacGetReq( ZMacDiagsTxUcastFail, (uint8 *)&diagsValue );
      // Update the statistics table with this value from MAC
      DiagsStatsTable.MacTxUcastFail = diagsValue;
      break;

    // NWK Diagnostics
    case ZDIAGS_ROUTE_DISC_INITIATED:
      diagsValue = DiagsStatsTable.RouteDiscInitiated;
      break;

    case ZDIAGS_NEIGHBOR_ADDED:
      diagsValue = DiagsStatsTable.NeighborAdded;
      break;

    case ZDIAGS_NEIGHBOR_REMOVED:
      diagsValue = DiagsStatsTable.NeighborRemoved;
      break;

    case ZDIAGS_NEIGHBOR_STALE:
      diagsValue = DiagsStatsTable.NeighborStale;
      break;

    case ZDIAGS_JOIN_INDICATION:
      diagsValue = DiagsStatsTable.JoinIndication;
      break;

    case ZDIAGS_CHILD_MOVED:
      diagsValue = DiagsStatsTable.ChildMoved;
      break;

    case ZDIAGS_NWK_FC_FAILURE:
      diagsValue = DiagsStatsTable.NwkFcFailure;
      break;

    case ZDIAGS_NWK_DECRYPT_FAILURES:
      diagsValue = DiagsStatsTable.NwkDecryptFailures;
      break;

    case ZDIAGS_PACKET_BUFFER_ALLOCATE_FAILURES:
      diagsValue = DiagsStatsTable.PacketBufferAllocateFailures;
      break;

    case ZDIAGS_RELAYED_UCAST:
      diagsValue = DiagsStatsTable.RelayedUcast;
      break;

    case ZDIAGS_PHY_TO_MAC_QUEUE_LIMIT_REACHED:
      diagsValue = DiagsStatsTable.PhyToMacQueueLimitReached;
      break;

    case ZDIAGS_PACKET_VALIDATE_DROP_COUNT:
      diagsValue = DiagsStatsTable.PacketValidateDropCount;
      break;

    // APS Diagnostics
    case ZDIAGS_APS_RX_BCAST:
      diagsValue = DiagsStatsTable.ApsRxBcast;
      break;

    case ZDIAGS_APS_TX_BCAST:
      diagsValue = DiagsStatsTable.ApsTxBcast;
      break;

    case ZDIAGS_APS_RX_UCAST:
      diagsValue = DiagsStatsTable.ApsRxUcast;
      break;

    case ZDIAGS_APS_TX_UCAST_SUCCESS:
      diagsValue = DiagsStatsTable.ApsTxUcastSuccess;
      break;

    case ZDIAGS_APS_TX_UCAST_RETRY:
      diagsValue = DiagsStatsTable.ApsTxUcastRetry;
      break;

    case ZDIAGS_APS_TX_UCAST_FAIL:
      diagsValue = DiagsStatsTable.ApsTxUcastFail;
      break;

    case ZDIAGS_APS_FC_FAILURE:
      diagsValue = DiagsStatsTable.ApsFcFailure;
      break;

    case ZDIAGS_APS_UNAUTHORIZED_KEY:
      diagsValue = DiagsStatsTable.ApsUnauthorizedKey;
      break;

    case ZDIAGS_APS_DECRYPT_FAILURES:
      diagsValue = DiagsStatsTable.ApsDecryptFailures;
      break;

    case ZDIAGS_APS_INVALID_PACKETS:
      diagsValue = DiagsStatsTable.ApsInvalidPackets;
      break;

    case ZDIAGS_MAC_RETRIES_PER_APS_TX_SUCCESS:
      diagsValue = DiagsStatsTable.MacRetriesPerApsTxSuccess;
      break;


    default:
      break;
  }
#endif // FEATURE_SYSTEM_STATS

  return ( diagsValue );
}
Пример #11
0
/*********************************************************************
 * @fn      ipd_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   shift - true if in shift/alt.
 * @param   keys - bit field for key events. Valid entries:
 *                 HAL_KEY_SW_4
 *                 HAL_KEY_SW_3
 *                 HAL_KEY_SW_2
 *                 HAL_KEY_SW_1
 *
 * @return  none
 */
static void ipd_HandleKeys( uint8 shift, uint8 keys )
{
    // Shift is used to make each button/switch dual purpose.
    if ( shift )
    {
        if ( keys & HAL_KEY_SW_1 )
        {
        }
        if ( keys & HAL_KEY_SW_2 )
        {
        }
        if ( keys & HAL_KEY_SW_3 )
        {
        }
        if ( keys & HAL_KEY_SW_4 )
        {
        }
    }
    else
    {
        if ( keys & HAL_KEY_SW_1 )
        {
            ZDOInitDevice(0); // join the network
        }

        if ( keys & HAL_KEY_SW_2 )
        {
#if defined( INTER_PAN )

            uint8 x = true;
            ZMacGetReq( ZMacRxOnIdle, &rxOnIdle );
            ZMacSetReq( ZMacRxOnIdle, &x );
            afAddrType_t dstAddr;
            uint8 option = 1;

            // Send a request for public pricing information using the INTERP-DATA SAP.
            // The request is sent as a broadcast to all PANs within the discovered
            // channel. Receiving devices that implement the INTRP-DATA SAP will process
            // it and, if any such device is able to respond, it will respond directly
            // to the requestor. After receiving at least one response the requestor may
            // store the PAN ID and device address of one or more responders so that it
            // may query them directly in future.
            dstAddr.addrMode = afAddrBroadcast;
            dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL;
            dstAddr.endPoint = STUBAPS_INTER_PAN_EP;
            dstAddr.panId = 0xFFFF;

            zclSE_Pricing_Send_GetCurrentPrice( IPD_ENDPOINT, &dstAddr, option, TRUE, 0 );
#endif
        }

        if ( keys & HAL_KEY_SW_3 )
        {

        }

        if ( keys & HAL_KEY_SW_4 )
        {

        }
    }
}