Esempio n. 1
0
/*************************************************************************//**
*****************************************************************************/
static bool nwkRxIndicateFrame(NwkFrame_t *frame)
{
  NwkFrameHeader_t *header = &frame->header;
  NWK_DataInd_t ind;

  if (NULL == nwkIb.endpoint[header->nwkDstEndpoint])
    return false;

  ind.srcAddr = header->nwkSrcAddr;
  ind.dstAddr = header->nwkDstAddr;
  ind.srcEndpoint = header->nwkSrcEndpoint;
  ind.dstEndpoint = header->nwkDstEndpoint;
  ind.data = frame->payload;
  ind.size = nwkFramePayloadSize(frame);
  ind.lqi = frame->rx.lqi;
  ind.rssi = frame->rx.rssi;

  ind.options  = (header->nwkFcf.ackRequest) ? NWK_IND_OPT_ACK_REQUESTED : 0;
  ind.options |= (header->nwkFcf.security) ? NWK_IND_OPT_SECURED : 0;
  ind.options |= (header->nwkFcf.linkLocal) ? NWK_IND_OPT_LINK_LOCAL : 0;
  ind.options |= (header->nwkFcf.multicast) ? NWK_IND_OPT_MULTICAST : 0;
  ind.options |= (NWK_BROADCAST_ADDR == header->nwkDstAddr) ? NWK_IND_OPT_BROADCAST : 0;
  ind.options |= (header->nwkSrcAddr == header->macSrcAddr) ? NWK_IND_OPT_LOCAL : 0;
  ind.options |= (NWK_BROADCAST_PANID == header->macDstPanId) ? NWK_IND_OPT_BROADCAST_PAN_ID : 0;

  return nwkIb.endpoint[header->nwkDstEndpoint](&ind);
}
/*************************************************************************//**
*****************************************************************************/
static void nwkSecurityStart(void)
{
  NwkFrameHeader_t *header = &nwkSecurityActiveFrame->header;

  nwkSecurityVector[0] = header->nwkSeq;
  nwkSecurityVector[1] = ((uint32_t)header->nwkDstAddr << 16) | header->nwkDstEndpoint;
  nwkSecurityVector[2] = ((uint32_t)header->nwkSrcAddr << 16) | header->nwkSrcEndpoint;
  nwkSecurityVector[3] = ((uint32_t)header->macDstPanId << 16) | *(uint8_t *)&header->nwkFcf;

  if (NWK_SECURITY_STATE_DECRYPT_PENDING == nwkSecurityActiveFrame->state)
    nwkSecurityActiveFrame->size -= NWK_SECURITY_MIC_SIZE;

  nwkSecuritySize = nwkFramePayloadSize(nwkSecurityActiveFrame);
  nwkSecurityOffset = 0;
  nwkSecurityEncrypt = (NWK_SECURITY_STATE_ENCRYPT_PENDING == nwkSecurityActiveFrame->state);

  nwkSecurityActiveFrame->state = NWK_SECURITY_STATE_PROCESS;
}