コード例 #1
0
ファイル: raw-tap-dev.c プロジェクト: Mastnest/6lbr
/*wpcap process is used to connect to host interface */
void
tun_init()
{
  setvbuf(stdout, NULL, _IOLBF, 0);     /* Line buffered output. */

  slip_init();
}
コード例 #2
0
ファイル: native-rdc.c プロジェクト: Scypho/6lbr
/*---------------------------------------------------------------------------*/
void
native_rdc_init(void)
{
    slip_init();
    process_start(&border_router_cmd_process, NULL);
    process_start(&native_rdc_process, NULL);
}
コード例 #3
0
ファイル: microps.c プロジェクト: pandax381/microps
int
microps_init (void) {
    if (ethernet_init() == -1) {
        goto ERROR;
    }
    if (slip_init() == -1) {
        goto ERROR;
    }
    if (arp_init() == -1) {
        goto ERROR;
    }
    if (ip_init() == -1) {
        goto ERROR;
    }
    if (icmp_init() == -1) {
        goto ERROR;
    }
    if (udp_init() == -1) {
        goto ERROR;
    }
    if (tcp_init() == -1) {
        goto ERROR;
    }
    return  0;

ERROR:
    microps_cleanup();
    return -1;
}
コード例 #4
0
ファイル: raw-tap-dev.c プロジェクト: denghongcai/6lbr
void
tun_init()
{
  setvbuf(stdout, NULL, _IOLBF, 0);     /* Line buffered output. */

  slip_init();

  if(use_raw_ethernet) {
    tunfd = eth_alloc(slip_config_tundev);
  } else {
    tunfd = tun_alloc(slip_config_tundev);
  }
  if(tunfd == -1)
    err(1, "main: open");

  select_set_callback(tunfd, &tun_select_callback);

  printf("opened device ``/dev/%s''\n", slip_config_tundev);

  atexit(cleanup);
  signal(SIGHUP, sigcleanup);
  signal(SIGTERM, sigcleanup);
  signal(SIGINT, sigcleanup);
  ifconf(slip_config_tundev);
  if(use_raw_ethernet) {
    fetch_mac(tunfd, slip_config_tundev, &eth_mac_addr);
    PRINTF("Eth MAC address : ");
    PRINTETHADDR(&eth_mac_addr);
    PRINTF("\n");
    eth_mac_addr_ready = 1;
  }
}
コード例 #5
0
ファイル: main.c プロジェクト: adamselevan/dicio
void Task3 ()
{
  int8_t v;
  int8_t i;
  printf ("Task3 PID=%d\r\n", nrk_get_pid ());
  slip_init (stdin, stdout, 0, 0);
  while (slip_started () != 1)
    nrk_wait_until_next_period ();

  while (1) {
    nrk_led_toggle (RED_LED);

    v = slip_rx (slip_rx_buf, MAX_SLIP_BUF);

    printf ("%d\r\n", slip_rx_buf[0]);
  /*  if (v > 0) {
      nrk_kprintf (PSTR ("Task3 got data "));
      printf( "%d bytes: ",v );
      for (i = 0; i < v; i++)
        printf ("%d ", slip_rx_buf[i]);
      printf ("\r\n");
    }
    else
      nrk_kprintf (PSTR ("Task3 data failed\r\n"));
*/
    //nrk_wait_until_next_period ();
  }
}
コード例 #6
0
ファイル: dprot_master.c プロジェクト: meexmachina/dprot
uint8_t dprot_master_init_protocol (fn_put_char put_function, fn_get_char_to get_function)
{
	// initialize the crc table
	init_crc8( );
    
    master_last_parity = 0;
	
	// initialize the slip protocol
	return slip_init (put_function, NULL, get_function, &master_channel);
}
コード例 #7
0
ファイル: Serial.c プロジェクト: ESE519/ISA100.11a
void serial_task()
{
	int8_t ret;
	
	if(DEBUG_SR == 0)
	{
			nrk_kprintf(PSTR("Inside serial_task. Task PID = "));
			printf("%d\r\n", nrk_get_pid());
	}
	
	// initialise the SLIP module 
	slip_init (stdin, stdout, 0, 0);
	
	while(1)
	{
		// wait for the gateway to send you a message
		if(DEBUG_SR == 0)
		{
			nrk_kprintf(PSTR("SL: Waiting for a packet from the gateway\r\n"));
		}
		ret = slip_rx (rx_buf, SIZE_GATEWAYTONODESERIAL_PACKET);
		if (ret > 0)	// message received successfully
		{
			if(DEBUG_SR == 0)
			{
				nrk_kprintf(PSTR("Received a message from the gateway\r\n"));
			}
			unpack_GatewayToNodeSerial_Packet_header(&gtn_pkt, rx_buf);
			
			switch(serial_pkt_type(&gtn_pkt))
			{
				case SERIAL_APPLICATION:
					process_serial_app_pkt(&gtn_pkt);
					break;
				
				case SERIAL_NW_CONTROL:
					process_serial_nw_ctrl_pkt(&gtn_pkt);
					break;
					
				case INVALID: 
					// drop the packet and go receive another one 
					//printf("serial_task(): Invalid packet type received = %d\n", gtn_pkt.type);	 
					break;
			} // end switch
		} // end if
      	else	// message was corrupted
      	{
      		nrk_kprintf(PSTR("Failed to receive a SLIP message from gateway\r\n"));
      		//nrk_wait_until_next_period ();
      	}
	} // end while 
		
	return;
}
コード例 #8
0
ファイル: test_slip.c プロジェクト: Kvasshtain/uos-embedded
void uos_init (void)
{
	/* Baud 19200. */
	UBRR = ((int) (KHZ * 1000L / 19200) + 8) / 16 - 1;

	/* Enable external RAM: port A - address/data, port C - address. */
	setb (SRE, MCUCR);
	mem_init (&pool, RAM_START, RAM_END);

	slip_init (&slip, 0, "slip0", 80, &pool, KHZ, 38400);
	task_create (hello, 0, "hello", 1, task, sizeof (task));
}
コード例 #9
0
ファイル: slip.c プロジェクト: GlitchMasta47/pce
slip_t *slip_new (void)
{
	slip_t *slip;

	slip = malloc (sizeof (slip_t));
	if (slip == NULL) {
		return (NULL);
	}

	slip_init (slip);

	return (slip);
}
コード例 #10
0
ファイル: tun-bridge.c プロジェクト: 13416795/contiki
/*---------------------------------------------------------------------------*/
void
tun_init()
{
  setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */

  slip_init();

  tunfd = tun_alloc(slip_config_tundev);
  if(tunfd == -1) err(1, "main: open");

  select_set_callback(tunfd, &tun_select_callback);

  fprintf(stderr, "opened %s device ``/dev/%s''\n",
          "tun", slip_config_tundev);

  atexit(cleanup);
  signal(SIGHUP, sigcleanup);
  signal(SIGTERM, sigcleanup);
  signal(SIGINT, sigcleanup);
  ifconf(slip_config_tundev, slip_config_ipaddr);
}
コード例 #11
0
ファイル: main.c プロジェクト: ESE519/ISA100.11a
void Task1 ()
{
  uint16_t cnt;
  uint8_t len;
  printf ("My node's address is %d\r\n", NODE_ADDR);

  printf ("Task1 PID=%d\r\n", nrk_get_pid ());
  cnt = 0;
  slip_init (stdin, stdout, 0, 0);

  while (1) {
    nrk_led_set (ORANGE_LED);
    sprintf (slip_tx_buf, "Hello %d", cnt);
    len = strlen (slip_tx_buf);
    slip_tx (slip_tx_buf, len);
    nrk_wait_until_next_period ();
    nrk_led_clr (ORANGE_LED);
    nrk_wait_until_next_period ();
    cnt++;
  }
}
コード例 #12
0
ファイル: main.c プロジェクト: adamselevan/dicio
void Task1 ()
{
  uint16_t cnt;
  uint8_t len,i;
  //printf ("My node's address is %d\r\n", NODE_ADDR);

  //printf ("Task1 PID=%d\r\n", nrk_get_pid ());


  rfRxInfo.pPayload = rx_buf;
  rfRxInfo.max_length = RF_MAX_PAYLOAD_SIZE;
  nrk_int_enable();
  rf_init (&rfRxInfo, 13, 0x2420, 0x1214);

  cnt = 0;
  slip_init (stdin, stdout, 0, 0);
	rf_rx_on();
  while (1) {
    


    while (rf_rx_packet_nonblock () != NRK_OK) {
      nrk_wait_until_next_period();

    }
		
		
    rx_packet_len = rfRxInfo.length;
    for(i=0; i<rfRxInfo.length; i++ ) slip_tx_buf[i]=rfRxInfo.pPayload[i];
		slip_tx_buf[10] = rfRxInfo.rssi;
		
    while(uart_tx_busy==1) nrk_wait_until_next_period();
    uart_tx_busy=1;
    slip_tx (slip_tx_buf, rx_packet_len);
    uart_tx_busy=0;
		

  }
}
コード例 #13
0
ファイル: raw-tap-dev.c プロジェクト: Mastnest/6lbr
void
tun_init()
{
  setvbuf(stdout, NULL, _IOLBF, 0);     /* Line buffered output. */

#if !CETIC_6LBR_ONE_ITF
  slip_init();
#endif

  if(use_raw_ethernet) {
    tunfd = eth_alloc(slip_config_tundev);
  } else {
    tunfd = tun_alloc(slip_config_tundev);
  }
  if(tunfd == -1) {
    LOG6LBR_FATAL("tun_alloc() : %s\n", strerror(errno));
    exit(1);
  }

  select_set_callback(tunfd, &tun_select_callback);

  LOG6LBR_INFO("opened device /dev/%s\n", slip_config_tundev);

  atexit(cleanup);
  signal(SIGHUP, sigcleanup);
  signal(SIGTERM, sigcleanup);
  signal(SIGINT, sigcleanup);
  ifconf(slip_config_tundev);
#if !CETIC_6LBR_ONE_ITF
  if(use_raw_ethernet) {
#endif
	fetch_mac(tunfd, slip_config_tundev, &eth_mac_addr);
	LOG6LBR_ETHADDR(INFO, &eth_mac_addr, "Eth MAC address : ");
    eth_mac_addr_ready = 1;
#if !CETIC_6LBR_ONE_ITF
  }
#endif
}
コード例 #14
0
ファイル: ktcp.c プロジェクト: Edwin-Edward/elks
int main(int argc,char **argv)
{
    if (argc < 3) {
	printf("Syntax :\n    %s local_ip slip_tty\n",argv[0]);
	exit(3);
    }

    debug("KTCP: Mark 1.\n");
    local_ip = in_aton(argv[1]);

    debug("KTCP: Mark 2.\n");
    if((tcpdevfd = tcpdev_init("/dev/tcpdev")) < 0)
	exit(1);

    debug("KTCP: Mark 3.\n");
    if ((sfd = slip_init(argv[2])) < 0)
	exit(2);

    debug("KTCP: Mark 4.\n");
    ip_init();

    debug("KTCP: Mark 5.\n");
    icmp_init();

    debug("KTCP: Mark 6.\n");
    tcp_init();

    debug("KTCP: Mark 7.\n");
    netconf_init();

    debug("KTCP: Mark 8.\n");
    ktcp_run();

    debug("KTCP: Mark 9.\n");
    exit(0);
}
コード例 #15
0
ファイル: Serial.c プロジェクト: ESE519/ISA100.11a
void serial_task()												// CHECKED
{
	int8_t ret;			// to hold the return value of various function calls
	
	// initialise the SLIPstream module 
	slip_init (stdin, stdout, 0, 0);
	
	while(1)			// start processing forever
	{
		// wait for the gateway to send you a message
		if(DEBUG_SR >= 1)
		{
			nrk_kprintf(PSTR("SR: serial_task(): Waiting for a packet from the gateway\r\n"));
		}
		ret = slip_rx (rx_buf, SIZE_GATEWAYTONODESERIAL_PACKET);
		if (ret > 0)	// message received successfully
		{
			/*
			if(ret != SIZE_GATEWAYTONODESERIAL_PACKET)	// wrong-length packet received
			{
				nrk_kprintf(PSTR("SR: serial_task(): Incorrect packet length received from gateway: "));
				printf("%d\r\n",ret);
				continue;
			}
			*/
			if(ret < SIZE_GATEWAYTONODESERIAL_PACKET_HEADER)	// wrong length packet received
			{
				nrk_kprintf(PSTR("SR: serial_task(): Incorrect packet length received from gateway: "));
				printf("%d\r\n", ret);
				continue;
			}				 
			
			// got a valid packet. Send ACK
			send_ACK();
			//unpack the received data into a packet
			unpack_GatewayToNodeSerial_Packet_header(&gtn_pkt, rx_buf);
			//memcpy(gtn_pkt.data, rx_buf + SIZE_GATEWAYTONODESERIAL_PACKET_HEADER, MAX_GATEWAY_PAYLOAD);
			memcpy(gtn_pkt.data, rx_buf + SIZE_GATEWAYTONODESERIAL_PACKET_HEADER, gtn_pkt.length);
			
			switch(serial_pkt_type(&gtn_pkt))
			{
				case SERIAL_APPLICATION:
					process_serial_app_pkt(&gtn_pkt);
					break;
				
				case SERIAL_NW_CONTROL:
					process_serial_nw_ctrl_pkt(&gtn_pkt);
					break;
					
				default: 
					// drop the packet and go receive another one 
					if(DEBUG_SR == 0)
					{
						nrk_kprintf(PSTR("SR: serial_task(): Invalid packet type received = "));
						printf("%x\n", gtn_pkt.type);
					}	 
					break;
			} // end switch
			
		
		} // end if
		else	// message was corrupted
      	{
      		nrk_kprintf(PSTR("SR: serial_task(): Failed to receive a SLIP message from gateway: Length = "));
      		printf("%d\r\n", ret);
       	}
      	//nrk_wait_until_next_period();
   	} // end while 
		
	return;
}
コード例 #16
0
ファイル: main.c プロジェクト: mlab-upenn/mrk
void rx_task()
{
nrk_time_t t;
uint16_t cnt;
int8_t v;
uint8_t len,i,chan;


cnt=0;
nrk_kprintf( PSTR("Nano-RK Version ") );
printf( "%d\r\n",NRK_VERSION );

  
printf( "Gateway Task PID=%u\r\n",nrk_get_pid());
t.secs=10;
t.nano_secs=0;

// setup a software watch dog timer
nrk_sw_wdt_init(0, &t, NULL);
nrk_sw_wdt_start(0);

  chan = 16;
  if (SET_MAC == 0xffff) {

    v = read_eeprom_mac_address (&mac_address);
    if (v == NRK_OK) {
      v = read_eeprom_channel (&chan);
    }
    else {
      while (1) {
        nrk_kprintf (PSTR
                     ("* ERROR reading MAC address, run eeprom-set utility\r\n"));
  	nrk_led_toggle(RED_LED);
        nrk_wait_until_next_period ();
      }
    }
  }
  else
    mac_address = SET_MAC;

  printf ("MAC ADDR: %x\r\n", mac_address & 0xffff);
  printf ("chan = %d\r\n", chan);


tdma_init(TDMA_HOST, chan, mac_address);

// Change these parameters anytime you want...
tdma_set_slot_len_ms(10);
tdma_set_slots_per_cycle(12);

slip_init (stdin, stdout, 0, 0);

while(!tdma_started()) nrk_wait_until_next_period();
nrk_led_set(GREEN_LED);
  while(1) {
	v=tdma_recv(&rx_tdma_fd, &slip_tx_buf, &len, TDMA_BLOCKING );	
	nrk_led_set(ORANGE_LED);
	if(v==NRK_OK)
	{
		//for(i=0; i<len; i++ ) printf( "%c", rx_buf[i]);
		// Got a packet from the network so send it over SLIP
		slip_tx ( slip_tx_buf, len );
	}
	else tdma_rx_pkt_release();
	nrk_led_clr(ORANGE_LED);
	nrk_sw_wdt_update(0); 
  	}
}
コード例 #17
0
ファイル: main.c プロジェクト: stu/bootstrap-slip
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;
}
コード例 #18
0
ファイル: udp-client.c プロジェクト: shomagan/contiki_6to4
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;
#if WITH_COMPOWER
  static int print = 0;
#endif

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();
  
  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 
  PRINTF("UIP_CONF_TCP_MSS %u \n",UIP_CONF_TCP_MSS);
  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

#if WITH_COMPOWER
  powertrace_sniff(POWERTRACE_ON);
#endif

  etimer_set(&periodic, SEND_INTERVAL);
  request_prefix();
  slip_init();
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
    
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

#if WITH_COMPOWER
      if (print == 0) {
	powertrace_print("#P");
      }
      if (++print == 3) {
	print = 0;
      }
#endif

    }
  }

  PROCESS_END();
}