Exemple #1
0
static void write_pair(pSlip gd, pSlipObject pair)
{
	pSlipObject car_obj;
	pSlipObject cdr_obj;

	car_obj = car(pair);
	cdr_obj = cdr(pair);

	slip_write(gd, car_obj);

	if (cdr_obj->type == eType_PAIR)
	{
		printf(" ");
		write_pair(gd, cdr_obj);
	}
	else if (cdr_obj->type == eType_EMPTY_LIST)
	{
		return;
	}
	else
	{
		printf(" . ");
		slip_write(gd, cdr_obj);
	}
}
Exemple #2
0
/*-----------------------------------------------------------------------------------*/
static void
create_hello(void)
{
	hello_packet_t packet;
	uint8_t state, i;
	uint8_t buf[HELLO_PACKETSIZE];

	/* Construct packet */
	packet.type = HELLO_PACKET;
	packet.operation = SEC_ARP_REQUEST;

	buf[0] = packet.type;
	buf[1] = packet.operation;

	/* Get device-id */
	for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
		state = uip_ds6_if.addr_list[i].state;
		if(uip_ds6_if.addr_list[i].isused && state == ADDR_PREFERRED) {
			memcpy(&buf[2], &uip_ds6_if.addr_list[i].ipaddr.u8[0], 16);
		}
	}

	/* Get device MAC */
	memcpy(&buf[18], &rimeaddr_node_addr.u8[0], 8);

	/* Send buf over slip */
	slip_write(buf, HELLO_PACKETSIZE);

	PRINTF("sec-arp: create\n");
}
Exemple #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(slip_process, ev, data)
{
  PROCESS_BEGIN();

  rxbuf_init();

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);

    slip_active = 1;

    /* Move packet from rxbuf to buffer provided by uIP. */
    uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN],
				UIP_BUFSIZE - UIP_LLH_LEN);
#if !UIP_CONF_IPV6
    if(uip_len == 4 && strncmp((char*)&uip_buf[UIP_LLH_LEN], "?IPA", 4) == 0) {
      char buf[8];
      memcpy(&buf[0], "=IPA", 4);
      memcpy(&buf[4], &uip_hostaddr, 4);
      if(input_callback) {
	input_callback();
      }
      slip_write(buf, 8);
    } else if(uip_len > 0
       && uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1])
       && uip_ipchksum() == 0xffff) {
#define IP_DF   0x40
      if(BUF->ipid[0] == 0 && BUF->ipid[1] == 0 && BUF->ipoffset[0] & IP_DF) {
	static u16_t ip_id;
	u16_t nid = ip_id++;
	BUF->ipid[0] = nid >> 8;
	BUF->ipid[1] = nid;
	nid = uip_htons(nid);
	nid = ~nid;		/* negate */
	BUF->ipchksum += nid;	/* add */
	if(BUF->ipchksum < nid) { /* 1-complement overflow? */
	  BUF->ipchksum++;
	}
      }
      tcpip_input();
    } else {
      uip_len = 0;
      SLIP_STATISTICS(slip_ip_drop++);
    }
#else /* UIP_CONF_IPV6 */
    if(uip_len > 0) {
      if(input_callback) {
        input_callback();
      }
      tcpip_input();
    }
#endif /* UIP_CONF_IPV6 */
  }
char *get_arch_rime_addr(void)
{
  struct timer tm;
  
  uart2_set_input(uart_rbyte);
  while (rimeaddr_cmp(&arch_rime_addr, &rimeaddr_null)) {
    printf("send rime addr request!\r\n");
    slip_write("?M", 2); 
    timer_set(&tm, CLOCK_SECOND*2);
    while (!timer_expired(&tm));
  }
  return (char *)&arch_rime_addr;
}
/** \brief Take an IP packet and format it to be sent on an 802.15.4
 *  network using 6lowpan.
 *  \param localdest The MAC address of the destination
 *
 *  The IP packet is initially in uip_buf. Its header is compressed
 *  and if necessary it is fragmented. The resulting
 *  packet/fragments are put in packetbuf and delivered to the 802.15.4
 *  MAC.
 */
static uint8_t
tip_output(uip_lladdr_t *localdest)
{
  uint8_t buf[RIMEADDR_SIZE+4];
  
  rimeaddr_t dest;
 
  /*
   * The destination address will be tagged to each outbound
   * packet. If the argument localdest is NULL, we are sending a
   * broadcast packet.
   */
  if(localdest == NULL) {
     rimeaddr_copy(&dest, &rimeaddr_null);
  } else {
    rimeaddr_copy(&dest, (const rimeaddr_t *)localdest);
  }
  
  if (0 == rimeaddr_cmp(&dest, &laddr)) {
    // send rime addr
    buf[0]='!'; buf[1]='R';
    rimeaddr_copy((rimeaddr_t *)&buf[2],(const rimeaddr_t *)localdest);
    slip_write(buf, 2+RIMEADDR_SIZE);
    rimeaddr_copy(&laddr, (const rimeaddr_t *)localdest);
  }
#if DEBUG
  {
      uint16_t i;
  PRINTF(">>>len(%u) ", uip_len);
  for (i=0; i<uip_len; i++)PRINTF(":%02X", BUF[i]);
  PRINTF("\r\n");
  }
#endif
  packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &laddr);
  slip_write(&uip_buf[UIP_LLH_LEN], uip_len);
  return 1;
}
Exemple #6
0
/* Packet from SICSLoWPAN */
void
tcpip_input(void)
{
  if(uip_len > 0) {
    mac_LowpanToEthernet();
    if(uip_len > 0) {
      /*      printf("pppp i %u tx %u rx %u\n", UIP_IP_BUF->proto,
	     packetbuf_attr(PACKETBUF_ATTR_TRANSMIT_TIME),
	     packetbuf_attr(PACKETBUF_ATTR_LISTEN_TIME));*/
      slip_write(uip_buf, uip_len);
      leds_invert(LEDS_RED);
      uip_len = 0;
    }
  }
}
Exemple #7
0
/*---------------------------------------------------------------------------*/
static void
slip_input_callback(void)
{
  unsigned char i;
  unsigned short chek_summ,chek_summ_recv;
  if (strncmp(uip_buf, "AdressTarget", 12) == 0){
    chek_summ =chksum(chek_summ,(uint8_t*)uip_buf,16);
    chek_summ_recv = uip_buf[16];
    chek_summ_recv |= ((uint16_t)uip_buf[17])<<8;
    if (chek_summ_recv==chek_summ){
      //set new IPv6 addres
      uip_ipaddr_t ipaddr;
      uip_lladdr_t lladdr;
      lladdr.addr[0] = 0x00;
  		lladdr.addr[1] = 0x12;
  		lladdr.addr[2] = 0x4b;
  		lladdr.addr[3] = 0x00;
      lladdr.addr[4] = uip_buf[12];
      lladdr.addr[5] = uip_buf[13];
      lladdr.addr[6] = uip_buf[14];
      lladdr.addr[7] = uip_buf[15];
      for (i=0;i<4;i++){
        if (uip_buf[12+i]!= uip_ds6_if.addr_list[0].ipaddr.u8[12+i])
          break;
      }
      if (i<4){
        uip_ds6_addr_rm(&uip_ds6_if.addr_list[0]);
        uip_ip6addr(&ipaddr, 0x2001, 0x0db8, 0, 0x0212, 0, 0, 0, 0);
        uip_ds6_set_addr_iid(&ipaddr, &lladdr);
        uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
        uip_buf[12] = uip_ds6_if.addr_list[0].ipaddr.u8[12];
        uip_buf[13] = uip_ds6_if.addr_list[0].ipaddr.u8[13];
        uip_buf[14] = uip_ds6_if.addr_list[0].ipaddr.u8[14];
        uip_buf[15] = uip_ds6_if.addr_list[0].ipaddr.u8[15];
        slip_write(uip_buf, 16);
        print_local_addresses();
      }
    }
  }
 // PRINTF("SIN: %u\n", uip_len);

}
Exemple #8
0
static int slip_transmit(FAR struct slip_driver_s *priv)
{
  uint8_t *src;
  uint8_t *start;
  uint8_t  esc;
  int      remaining;
  int      len;

  /* Increment statistics */

  ninfo("Sending packet size %d\n", priv->dev.d_len);
  NETDEV_TXPACKETS(&priv->dev);

  /* Send an initial END character to flush out any data that may have
   * accumulated in the receiver due to line noise
   */

  slip_putc(priv, SLIP_END);

  /* For each byte in the packet, send the appropriate character sequence */

  src       = priv->dev.d_buf;
  remaining = priv->dev.d_len;
  start     = src;
  len       = 0;

  while (remaining-- > 0)
    {
      switch (*src)
        {
          /* If it's the same code as an END character, we send a special two
           * character code so as not to make the receiver think we sent an
           * END
           */

          case SLIP_END:
            esc = SLIP_ESC_END;
            goto escape;

          /* If it's the same code as an ESC character, we send a special two
           * character code so as not to make the receiver think we sent an
           * ESC
           */

          case SLIP_ESC:
            esc = SLIP_ESC_ESC;

          escape:
            {
              /* Flush any unsent data */

              if (len > 0)
                {
                  slip_write(priv, start, len);
                }

              /* Reset */

              start = src + 1;
              len   = 0;

              /* Then send the escape sequence */

              slip_putc(priv, SLIP_ESC);
              slip_putc(priv, esc);
            }
          break;

          /* otherwise, just bump up the count */

          default:
            len++;
            break;
        }

      /* Point to the next character in the packet */

      src++;
    }

  /* We have looked at every character in the packet.  Now flush any unsent
   * data
   */

  if (len > 0)
    {
      slip_write(priv, start, len);
    }

  /* And send the END token */

  slip_putc(priv, SLIP_END);
  NETDEV_TXDONE(&priv->dev);
  priv->txnodelay = true;
  return OK;
}
Exemple #9
0
static inline void slip_putc(FAR struct slip_driver_s *priv, int ch)
{
  uint8_t buffer = (uint8_t)ch;
  slip_write(priv, &buffer, 1);
}
Exemple #10
0
int main(int argc, char *argv[])
{
	pSlip slip;
	char *buff;
	int32_t bufflen = 1024;

	FILE *fp = stdin;

	if (argc == 2)
	{
		fp = fopen(argv[1], "rt");
		assert(fp != NULL);

		fseek(fp, 0x0L, SEEK_END);
		bufflen = ftell(fp);
		fseek(fp, 0x0L, SEEK_SET);
	}

	buff = malloc(bufflen+16);

	slip = slip_init();
	assert(slip != NULL);

	printf("\nWelcome to bootstrap slip. Use ctrl-c to exit.\n");

	while (slip->running == SLIP_RUNNING)
	{
		char *p;

		pSlipObject obj;

		printf("> ");
		fflush(stdout);

		memset(buff, 0x0, bufflen+1);
		fflush(stdout);
		fread(buff, 1, bufflen, fp);

		// echo if script
		if (fp != stdin)
			printf("%s", buff);

		fflush(stdout);

		if (buff[0] != 0)
		{
			if ( TokeniseBuffer(slip, buff, strlen(buff)) == 0)
			{
				while (obj != NULL && slip->running == SLIP_RUNNING)
				{
					obj = slip_read(slip);
					if (slip->running == SLIP_RUNNING && obj != NULL)
					{
						obj = slip_evaluate(slip, obj);
						if (slip->running == SLIP_RUNNING && obj != NULL)
							slip_write(slip, obj);
						printf("\n");
					}
				}
			}
			else
				printf("tokenise buffer failed\n");
		}
		else
			slip->running = SLIP_SHUTDOWN;
	};

	if (slip->running == SLIP_SHUTDOWN)
		printf("\nThank you.\n");

	slip_release(slip);

	if (fp != stdin)
		fclose(fp);

	return 0;
}