示例#1
0
/*************************************************************************//**
*****************************************************************************/
static void nwkTxDelayTimerHandler(SYS_Timer_t *timer)
{
	NwkFrame_t *frame = NULL;
	bool restart = false;

	while (NULL != (frame = nwkFrameNext(frame))) {
		if (NWK_TX_STATE_WAIT_DELAY == frame->state) {
			restart = true;

			if (0 == --frame->tx.timeout) {
				frame->state = NWK_TX_STATE_SEND;
			}
		}
	}

	if (restart) {
		SYS_TimerStart(timer);
	}
}
示例#2
0
/*************************************************************************//**
*****************************************************************************/
static void nwkTxAckWaitTimerHandler(SYS_Timer_t *timer)
{
	NwkFrame_t *frame = NULL;
	bool restart = false;

	while (NULL != (frame = nwkFrameNext(frame))) {
		if (NWK_TX_STATE_WAIT_ACK == frame->state) {
			restart = true;

			if (0 == --frame->tx.timeout) {
				nwkTxConfirm(frame, NWK_NO_ACK_STATUS);
			}
		}
	}

	if (restart) {
		SYS_TimerStart(timer);
	}
}
/*************************************************************************//**
*****************************************************************************/
static void nwkRouteDiscoveryDone(NwkRouteDiscoveryTableEntry_t *entry, bool status)
{
  NwkFrame_t *frame = NULL;

  while (NULL != (frame = nwkFrameNext(frame)))
  {
    if (NWK_RD_STATE_WAIT_FOR_ROUTE != frame->state)
      continue;

    if (entry->dstAddr != frame->header.nwkDstAddr ||
        entry->multicast != frame->header.nwkFcf.multicast)
      continue;

    if (status)
      nwkTxFrame(frame);
    else
      nwkTxConfirm(frame, NWK_NO_ROUTE_STATUS);
  }
}
示例#4
0
/*************************************************************************//**
*****************************************************************************/
bool nwkTxAckReceived(NWK_DataInd_t *ind)
{
	NwkCommandAck_t *command = (NwkCommandAck_t *)ind->data;
	NwkFrame_t *frame = NULL;

	if (sizeof(NwkCommandAck_t) != ind->size) {
		return false;
	}

	while (NULL != (frame = nwkFrameNext(frame))) {
		if (NWK_TX_STATE_WAIT_ACK == frame->state &&
				frame->header.nwkSeq == command->seq) {
			frame->state = NWK_TX_STATE_CONFIRM;
			frame->tx.control = command->control;
			return true;
		}
	}

	return false;
}
/*************************************************************************//**
  @brief Security Module task handler
*****************************************************************************/
void nwkSecurityTaskHandler(void)
{
  NwkFrame_t *frame = NULL;

  if (0 == nwkSecurityActiveFrames)
    return;

  if (nwkSecurityActiveFrame)
  {
    if (NWK_SECURITY_STATE_CONFIRM == nwkSecurityActiveFrame->state)
    {
      bool micStatus = nwkSecurityProcessMic();

      if (nwkSecurityEncrypt)
        nwkTxEncryptConf(nwkSecurityActiveFrame);
      else
        nwkRxDecryptConf(nwkSecurityActiveFrame, micStatus);

      nwkSecurityActiveFrame = NULL;
      --nwkSecurityActiveFrames;
    }
    else if (NWK_SECURITY_STATE_PROCESS == nwkSecurityActiveFrame->state)
    {
      nwkSecurityActiveFrame->state = NWK_SECURITY_STATE_WAIT;
      SYS_EncryptReq((uint8_t *)nwkSecurityVector, (uint8_t *)nwkIb.key);
    }

    return;
  }

  while (NULL != (frame = nwkFrameNext(frame)))
  {
    if (NWK_SECURITY_STATE_ENCRYPT_PENDING == frame->state ||
        NWK_SECURITY_STATE_DECRYPT_PENDING == frame->state)
    {
      nwkSecurityActiveFrame = frame;
      nwkSecurityStart();
      return;
    }
  }
}
示例#6
0
/*************************************************************************//**
  @brief Rx Module task handler
*****************************************************************************/
void nwkRxTaskHandler(void)
{
  NwkFrame_t *frame = NULL;

  while (NULL != (frame = nwkFrameNext(frame)))
  {
    switch (frame->state)
    {
      case NWK_RX_STATE_RECEIVED:
      {
        nwkRxHandleReceivedFrame(frame);
      } break;

#ifdef NWK_ENABLE_SECURITY
      case NWK_RX_STATE_DECRYPT:
      {
        nwkSecurityProcess(frame, false);
      } break;
#endif

      case NWK_RX_STATE_INDICATE:
      {
        nwkRxHandleIndication(frame);
      } break;

#ifdef NWK_ENABLE_ROUTING
      case NWK_RX_STATE_ROUTE:
      {
        nwkRouteFrame(frame);
      } break;
#endif

      case NWK_RX_STATE_FINISH:
      {
        nwkFrameFree(frame);
      } break;
    }
  }
}
示例#7
0
/*************************************************************************//**
*  @brief Tx Module task handler
*****************************************************************************/
void nwkTxTaskHandler(void)
{
	NwkFrame_t *frame = NULL;

	while (NULL != (frame = nwkFrameNext(frame))) {
		switch (frame->state) {
#ifdef NWK_ENABLE_SECURITY
		case NWK_TX_STATE_ENCRYPT:
		{
			nwkSecurityProcess(frame, true);
		}
		break;
#endif

		case NWK_TX_STATE_DELAY:
		{
			if (frame->tx.timeout > 0) {
				frame->state = NWK_TX_STATE_WAIT_DELAY;
				SYS_TimerStart(&nwkTxDelayTimer);
			} else {
				frame->state = NWK_TX_STATE_SEND;
			}
		}
		break;

		case NWK_TX_STATE_SEND:
		{
			if (NULL == nwkTxPhyActiveFrame) {
				nwkTxPhyActiveFrame = frame;
				frame->state = NWK_TX_STATE_WAIT_CONF;
				PHY_DataReq(&(frame->size));
				nwkIb.lock++;
			}
		}
		break;

		case NWK_TX_STATE_WAIT_CONF:
			break;

		case NWK_TX_STATE_SENT:
		{
			if (NWK_SUCCESS_STATUS == frame->tx.status) {
				if (frame->header.nwkSrcAddr == nwkIb.addr &&
						frame->header.nwkFcf.
						ackRequest) {
					frame->state = NWK_TX_STATE_WAIT_ACK;
					frame->tx.timeout = NWK_ACK_WAIT_TIME /
							NWK_TX_ACK_WAIT_TIMER_INTERVAL
							+ 1;
					SYS_TimerStart(&nwkTxAckWaitTimer);
				} else {
					frame->state = NWK_TX_STATE_CONFIRM;
				}
			} else {
				frame->state = NWK_TX_STATE_CONFIRM;
			}
		}
		break;

		case NWK_TX_STATE_WAIT_ACK:
			break;

		case NWK_TX_STATE_CONFIRM:
		{
#ifdef NWK_ENABLE_ROUTING
			nwkRouteFrameSent(frame);
#endif
			if (NULL == frame->tx.confirm) {
				nwkFrameFree(frame);
			} else {
				frame->tx.confirm(frame);
			}
		}
		break;

		default:
			break;
		}
	}
}