예제 #1
0
파일: common.c 프로젝트: jbodah/grad_work
// Create and initialize a packet
// jbodah
packet *createPacket(char seqNum, char frameKind) {
  packet *newPacket = (packet *)malloc(sizeof(packet)) ;
  bufFlush( newPacket->contents ) ;
  memcpy( &newPacket->contents[0], "AA", 2*sizeof(char)) ;
  memcpy( &newPacket->contents[2], &seqNum, sizeof(char)) ;
  memcpy( &newPacket->contents[3], &frameKind, sizeof(char)) ;
  return newPacket ;
}
예제 #2
0
파일: common.c 프로젝트: jbodah/grad_work
// jbodah
void printPacketContents( packet *newPacket ) {
  char dstString[30] ;
  bufFlush( dstString ) ;
  
  getVerboseFrameKind(newPacket, dstString) ;
  
  printf( "\tseqNum\t\t'%c' %d \n\tframeKind\t%s \n\tpayload\t\t%s \n\tCRC\t\t'%c' %d\n",
            getSeqNum(newPacket), (int)getSeqNum(newPacket),
            dstString,
            getPayload(newPacket),
            getCRC(newPacket), (int)getCRC(newPacket)
  ) ;
}
예제 #3
0
void zb_clear_sniffer()
{
  /* Stop serial transmit, if enabled */
#ifndef ZB_SNIFFER_USB_TRACE
  ZB_CLEAR_SERIAL_TRANSMIT_FLAG();
  ZB_DISABLE_SERIAL_INTER();
#endif
  
  /* Turn off radio */
  ISRFOFF();
  ISFLUSHRX();

  /* Clear output buffer */
  bufFlush(&rbTxBuf);
}
예제 #4
0
int FileMcIDAS::Close(int channel){
  if (Bin[channel]) { 
    bufFlush(channel);
    
    if(GlobalComment)
      write(Doc[channel],GlobalComment,strlen(GlobalComment));

    if(ChannelComment[channel])
      write(Doc[channel],ChannelComment[channel],strlen(ChannelComment[channel]));

    close(Bin[channel]);
    close(Doc[channel]);
    
    rename(tmpName(FileName(channel)), FileName(channel));
    if(linkLatest()) MakeLink(channel);
  }
  return(0);
}
예제 #5
0
void zb_start_sniffer(zb_uint8_t channel)
{
  /* Received channel is in range of supported ZB channels*/
  if (channel >= ZB_TRANSCEIVER_START_CHANNEL_NUMBER &&
      channel <= ZB_TRANSCEIVER_MAX_CHANNEL_NUMBER)
  {
    /* Flush output buffer to prevent old chanel's packets appearance
       in the output of a new capture */
    bufFlush(&rbTxBuf);

    ZB_TRANSCEIVER_SET_CHANNEL(channel);
    ISFLUSHRX();
    ISRXON();
    
#ifndef ZB_SNIFFER_USB_TRACE
    ZB_SET_SERIAL_TRANSMIT_FLAG();
    ZB_ENABLE_SERIAL_INTER();
#endif
    
  }
}
예제 #6
0
void zb_put_out_queue()
{
  zb_uint8_t len;
  zb_sniffer_err_e not_enough_space;
  zb_sniffer_hdr_t hdr;

  ZB_MEMSET(&hdr, 0, ZB_SNIFFER_HDR_SIZE);

  not_enough_space = bufIsFull(&rbTxBuf) ? ZB_SNIFFER_OUT_BUF_OVERFLOW : ZB_SNIFFER_OK;
  if (!not_enough_space)
  {
    zb_uint8_t i;
    zb_bool_t accept_frame = ZB_TRUE;
    zb_uint8_t buf[ZB_SNIFFER_BUF_SIZE];
    /* zb_uint16_t fcf; */
    zb_uint8_t crc;
    
    len = RFD;
    /* Check the reserved 7th bit of length field */
    if (ZB_SNIFFER_CHECK_MSB(len))
    {
      accept_frame = ZB_FALSE;
    }
    /* Max packet length - 127 b, ignore 7th byte to prevent buffer overflow */
    len &= 0x7F;
    buf[0] = len;
    if (len >= ZB_SNIFFER_BUF_SIZE)
    {
      /* Packet length is larger than buffer size;
	 don't change buffer size to value less than 128 b */
      not_enough_space = ZB_SNIFFER_TOO_BIG_LEN;
    }
    if (!not_enough_space)
    {
      /* Read packet payload */
      for (i = 1; i<=len; i++)
      {
	buf[i] = RFD;
      }
      /* Include length byte */
      len++;
      /* Check FCF reserved bits with source &
	 destination addressing modes */
      /* fcf = *((zb_uint16_t *)&buf[1]); */
      /* Auto CRC is enabled: check CRC OK bit */
      crc = buf[len - 1];
      accept_frame &= (ZB_SNIFFER_CHECK_MSB(crc)) ? ZB_TRUE : ZB_FALSE;
      /* accept_frame &= check_fcf(fcf); */
      if (accept_frame)
      {
	if (bufHasEnoughSpace(&rbTxBuf, len + sizeof(hdr)))
	{
	  hdr.len = len + ZB_SNIFFER_HDR_SIZE;
	  hdr.type = ZB_SNIFFER_OK;
          hdr.tail = 0;
	  bufPut(&rbTxBuf, (zb_uint8_t *)(&hdr), sizeof(hdr));
	  bufPut(&rbTxBuf, buf, len);
	}
	else
	{
	  /* There is no space in output buffer for the whole packet */
	  not_enough_space = ZB_SNIFFER_OUT_BUF_OVERFLOW;
	}
      }
    }
  }
  if (not_enough_space)
  {
    if (not_enough_space == ZB_SNIFFER_TOO_BIG_LEN)
    {
      RFST = 0xED; /* flush rxfifo */
      RFST = 0xE3; /* rx on */
    }
    else if (not_enough_space == ZB_SNIFFER_OUT_BUF_OVERFLOW)
    {
      bufFlush(&rbTxBuf);
    }
    /* Tell about problem happened to the host */
    hdr.len = sizeof(zb_sniffer_hdr_t);
    hdr.type = not_enough_space;
    hdr.tail = 0;
    /* Header with ZB_MAC_TRANSPORT_TYPE_TRACE signals about error */
    bufPut(&rbTxBuf, (zb_uint8_t *)(&hdr), sizeof(hdr));
  }
}