2006-06-18 00:41:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002, Adam Dunkels.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki OS
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-05-22 23:19:34 +02:00
|
|
|
#include <stdio.h>
|
2012-05-17 19:34:58 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
2007-11-27 00:28:33 +01:00
|
|
|
#include <time.h>
|
2007-11-28 15:16:12 +01:00
|
|
|
#include <sys/select.h>
|
2007-05-22 23:19:34 +02:00
|
|
|
#include <unistd.h>
|
2010-02-02 18:51:55 +01:00
|
|
|
#include <memory.h>
|
2007-05-22 23:19:34 +02:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
#include "contiki.h"
|
2009-03-06 01:13:56 +01:00
|
|
|
#include "contiki-net.h"
|
2012-05-17 19:34:58 +02:00
|
|
|
#include "lib/assert.h"
|
2009-03-06 01:13:56 +01:00
|
|
|
|
2009-03-17 16:56:32 +01:00
|
|
|
#include "dev/serial-line.h"
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/uip.h"
|
2007-03-26 04:53:54 +02:00
|
|
|
#ifdef __CYGWIN__
|
2007-05-20 23:29:39 +02:00
|
|
|
#include "net/wpcap-drv.h"
|
2008-01-04 22:53:32 +01:00
|
|
|
#else /* __CYGWIN__ */
|
2007-05-20 23:29:39 +02:00
|
|
|
#include "net/tapdev-drv.h"
|
2008-01-04 22:53:32 +01:00
|
|
|
#endif /* __CYGWIN__ */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2007-03-26 04:53:54 +02:00
|
|
|
#ifdef __CYGWIN__
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
|
2009-03-17 16:56:32 +01:00
|
|
|
PROCINIT(&etimer_process, &tcpip_process, &wpcap_process, &serial_line_process);
|
2014-11-12 10:18:29 +01:00
|
|
|
#else
|
|
|
|
PROCINIT(&etimer_process, &wpcap_process, &serial_line_process);
|
|
|
|
#endif
|
2008-01-04 22:53:32 +01:00
|
|
|
#else /* __CYGWIN__ */
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
|
2009-03-17 16:56:32 +01:00
|
|
|
PROCINIT(&etimer_process, &tapdev_process, &tcpip_process, &serial_line_process);
|
2014-11-12 10:18:29 +01:00
|
|
|
#else
|
|
|
|
PROCINIT(&etimer_process, &tapdev_process, &serial_line_process);
|
|
|
|
#endif
|
2008-01-04 22:53:32 +01:00
|
|
|
#endif /* __CYGWIN__ */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2011-06-28 14:19:48 +02:00
|
|
|
#if RPL_BORDER_ROUTER
|
|
|
|
#include "net/rpl/rpl.h"
|
|
|
|
|
2012-01-25 15:41:39 +01:00
|
|
|
static uint16_t dag_id[] = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011};
|
2011-06-28 14:19:48 +02:00
|
|
|
|
|
|
|
PROCESS(border_router_process, "RPL Border Router");
|
|
|
|
PROCESS_THREAD(border_router_process, ev, data)
|
|
|
|
{
|
|
|
|
|
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
|
|
|
PROCESS_PAUSE();
|
|
|
|
|
2012-01-25 15:34:10 +01:00
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
|
|
|
char buf[sizeof(dag_id)];
|
|
|
|
memcpy(buf,dag_id,sizeof(dag_id));
|
|
|
|
dag = rpl_set_root((uip_ip6addr_t *)buf);
|
|
|
|
|
|
|
|
/* Assign separate addresses to the uip stack and the host network
|
|
|
|
interface, but with the same prefix E.g. bbbb::ff:fe00:200 to
|
|
|
|
the stack and bbbb::1 to the host *fallback* network interface
|
|
|
|
Otherwise the host will trap packets intended for the stack,
|
|
|
|
just as the stack will trap packets intended for the host
|
|
|
|
$ifconfig usb0 -arp on Ubuntu to skip the neighbor
|
|
|
|
solicitations. Add explicit neighbors on other OSs */
|
|
|
|
|
|
|
|
if(dag != NULL) {
|
|
|
|
printf("Created a new RPL dag\n");
|
|
|
|
|
2011-06-28 14:19:48 +02:00
|
|
|
#if UIP_CONF_ROUTER_RECEIVE_RA
|
2012-01-25 15:34:10 +01:00
|
|
|
/* Contiki stack will shut down until assigned an address from the
|
|
|
|
interface RA Currently this requires changes in the core
|
|
|
|
rpl-icmp6.c to pass the link-local RA broadcast.
|
|
|
|
*/
|
|
|
|
|
2011-06-28 14:19:48 +02:00
|
|
|
#else
|
2012-01-25 15:34:10 +01:00
|
|
|
{
|
|
|
|
static void sprint_ip6(uip_ip6addr_t addr);
|
|
|
|
int i;
|
|
|
|
uip_ip6addr_t ipaddr;
|
2011-06-28 14:19:48 +02:00
|
|
|
#ifdef HARD_CODED_ADDRESS
|
2012-01-25 15:34:10 +01:00
|
|
|
uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
|
2011-06-28 14:19:48 +02:00
|
|
|
#else
|
2012-01-25 15:34:10 +01:00
|
|
|
uip_ip6addr(&ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1);
|
2011-06-28 14:19:48 +02:00
|
|
|
#endif
|
2012-01-25 15:34:10 +01:00
|
|
|
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
|
|
|
rpl_set_prefix(dag, &ipaddr, 64);
|
|
|
|
|
|
|
|
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
|
|
|
if(uip_ds6_if.addr_list[i].isused) {
|
|
|
|
printf("IPV6 Address: ");
|
|
|
|
sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);
|
|
|
|
printf("\n");
|
2011-06-28 14:19:48 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-25 15:34:10 +01:00
|
|
|
}
|
2011-06-28 14:19:48 +02:00
|
|
|
#endif
|
2012-01-25 15:34:10 +01:00
|
|
|
}
|
2011-06-28 14:19:48 +02:00
|
|
|
}
|
|
|
|
/* The border router runs with a 100% duty cycle in order to ensure high
|
|
|
|
packet reception rates. */
|
2012-01-25 15:34:10 +01:00
|
|
|
/* NETSTACK_MAC.off(1); */
|
2011-06-28 14:19:48 +02:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
PROCESS_YIELD();
|
|
|
|
/* Local and global dag repair can be done from ? */
|
2012-01-25 15:34:10 +01:00
|
|
|
/* rpl_set_prefix(rpl_get_dag(RPL_ANY_INSTANCE), &ipaddr, 64);
|
|
|
|
rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE)); */
|
2011-06-28 14:19:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
#endif /* RPL_BORDER_ROUTER */
|
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2010-02-02 18:51:55 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-01-25 15:34:10 +01:00
|
|
|
static void
|
2010-02-02 18:51:55 +01:00
|
|
|
sprint_ip6(uip_ip6addr_t addr)
|
|
|
|
{
|
|
|
|
unsigned char i = 0;
|
|
|
|
unsigned char zerocnt = 0;
|
|
|
|
unsigned char numprinted = 0;
|
2012-03-21 21:27:52 +01:00
|
|
|
unsigned char notskipped = 0;
|
2010-02-02 18:51:55 +01:00
|
|
|
char thestring[40];
|
2012-01-25 15:34:10 +01:00
|
|
|
char *result = thestring;
|
2010-02-02 18:51:55 +01:00
|
|
|
|
2012-01-25 15:34:10 +01:00
|
|
|
*result++ = '[';
|
|
|
|
while(numprinted < 8) {
|
|
|
|
if((addr.u16[i] == 0) && (zerocnt == 0)) {
|
|
|
|
while(addr.u16[zerocnt + i] == 0) {
|
|
|
|
zerocnt++;
|
|
|
|
}
|
2012-03-21 21:27:52 +01:00
|
|
|
if(zerocnt == 1 && notskipped) {
|
2010-02-02 18:51:55 +01:00
|
|
|
*result++ = '0';
|
|
|
|
numprinted++;
|
2012-03-21 21:27:52 +01:00
|
|
|
notskipped = 1;
|
|
|
|
continue;
|
2010-02-02 18:51:55 +01:00
|
|
|
}
|
|
|
|
i += zerocnt;
|
|
|
|
numprinted += zerocnt;
|
|
|
|
} else {
|
2010-10-19 20:29:03 +02:00
|
|
|
result += sprintf(result, "%x", (unsigned int)(uip_ntohs(addr.u16[i])));
|
2010-02-02 18:51:55 +01:00
|
|
|
i++;
|
|
|
|
numprinted++;
|
|
|
|
}
|
2012-01-25 15:34:10 +01:00
|
|
|
if(numprinted != 8) {
|
|
|
|
*result++ = ':';
|
|
|
|
}
|
2010-02-02 18:51:55 +01:00
|
|
|
}
|
|
|
|
*result++=']';
|
|
|
|
*result=0;
|
2012-01-25 15:34:10 +01:00
|
|
|
printf("%s", thestring);
|
2010-02-02 18:51:55 +01:00
|
|
|
}
|
2014-12-01 21:02:57 +01:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
2006-06-18 00:41:10 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-01-24 11:56:40 +01:00
|
|
|
int contiki_argc = 0;
|
|
|
|
char **contiki_argv;
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
int
|
2014-01-24 11:56:40 +01:00
|
|
|
main(int argc, char **argv)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
2014-01-24 11:56:40 +01:00
|
|
|
/* crappy way of remembering and accessing argc/v */
|
|
|
|
contiki_argc = argc;
|
|
|
|
contiki_argv = argv;
|
|
|
|
|
|
|
|
/* minimal-net under windows is hardcoded to use the first one or two args */
|
|
|
|
/* for wpcap configuration so this needs to be "removed" from contiki_args */
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
contiki_argc--;
|
|
|
|
contiki_argv++;
|
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
contiki_argc--;
|
|
|
|
contiki_argv++;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-07-24 17:53:36 +02:00
|
|
|
clock_init();
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
2012-01-25 15:34:10 +01:00
|
|
|
/* A hard coded address overrides the stack default MAC address to
|
|
|
|
allow multiple instances. uip6.c defines it as
|
|
|
|
{0x00,0x06,0x98,0x00,0x02,0x32} giving an ipv6 address of
|
|
|
|
[fe80::206:98ff:fe00:232] We make it simpler, {0x02,0x00,0x00 + the
|
|
|
|
last three bytes of the hard coded address (if any are nonzero).
|
|
|
|
HARD_CODED_ADDRESS can be defined in the contiki-conf.h file, or
|
|
|
|
here to allow quick builds using different addresses. If
|
|
|
|
HARD_CODED_ADDRESS has a prefix it also applied, unless built as a
|
|
|
|
RPL end node. E.g. bbbb::12:3456 becomes fe80::ff:fe12:3456 and
|
|
|
|
prefix bbbb::/64 if non-RPL ::10 becomes fe80::ff:fe00:10 and
|
|
|
|
prefix awaits RA or RPL formation bbbb:: gives an address of
|
|
|
|
bbbb::206:98ff:fe00:232 if non-RPL */
|
2011-06-28 14:19:48 +02:00
|
|
|
#ifdef HARD_CODED_ADDRESS
|
2012-01-25 15:34:10 +01:00
|
|
|
{
|
2011-06-28 14:19:48 +02:00
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
|
2012-01-25 15:34:10 +01:00
|
|
|
if((ipaddr.u8[13] != 0) ||
|
|
|
|
(ipaddr.u8[14] != 0) ||
|
|
|
|
(ipaddr.u8[15] != 0)) {
|
|
|
|
if(sizeof(uip_lladdr) == 6) { /* Minimal-net uses ethernet MAC */
|
|
|
|
uip_lladdr.addr[0] = 0x02;
|
|
|
|
uip_lladdr.addr[1] = 0;
|
|
|
|
uip_lladdr.addr[2] = 0;
|
|
|
|
uip_lladdr.addr[3] = ipaddr.u8[13];
|
|
|
|
uip_lladdr.addr[4] = ipaddr.u8[14];
|
|
|
|
uip_lladdr.addr[5] = ipaddr.u8[15];
|
|
|
|
}
|
|
|
|
}
|
2011-06-28 14:19:48 +02:00
|
|
|
}
|
2012-01-25 15:34:10 +01:00
|
|
|
#endif /* HARD_CODED_ADDRESS */
|
2014-12-01 21:02:57 +01:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
process_init();
|
2011-06-30 18:12:07 +02:00
|
|
|
/* procinit_init initializes RPL which sets a ctimer for the first DIS */
|
|
|
|
/* We must start etimers and ctimers,before calling it */
|
|
|
|
process_start(&etimer_process, NULL);
|
2009-04-29 13:49:27 +02:00
|
|
|
ctimer_init();
|
|
|
|
|
2011-06-28 14:19:48 +02:00
|
|
|
#if RPL_BORDER_ROUTER
|
|
|
|
process_start(&border_router_process, NULL);
|
|
|
|
printf("Border Router Process started\n");
|
|
|
|
#elif UIP_CONF_IPV6_RPL
|
|
|
|
printf("RPL enabled\n");
|
|
|
|
#endif
|
|
|
|
|
2012-02-11 21:19:28 +01:00
|
|
|
procinit_init();
|
|
|
|
autostart_start(autostart_processes);
|
|
|
|
|
2010-02-02 18:51:55 +01:00
|
|
|
/* Set default IP addresses if not specified */
|
2014-12-01 21:02:57 +01:00
|
|
|
#if !NETSTACK_CONF_WITH_IPV6
|
2012-01-25 15:34:10 +01:00
|
|
|
{
|
|
|
|
uip_ipaddr_t addr;
|
2006-06-18 00:41:10 +02:00
|
|
|
|
2012-01-25 15:34:10 +01:00
|
|
|
uip_gethostaddr(&addr);
|
|
|
|
if(addr.u8[0] == 0) {
|
2012-05-17 19:34:58 +02:00
|
|
|
uip_ipaddr(&addr, 172,18,0,2);
|
2012-01-25 15:34:10 +01:00
|
|
|
}
|
|
|
|
printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
|
|
|
|
uip_sethostaddr(&addr);
|
|
|
|
|
|
|
|
uip_getnetmask(&addr);
|
|
|
|
if(addr.u8[0] == 0) {
|
2012-05-17 19:34:58 +02:00
|
|
|
uip_ipaddr(&addr, 255,255,0,0);
|
2012-01-25 15:41:39 +01:00
|
|
|
uip_setnetmask(&addr);
|
2012-01-25 15:34:10 +01:00
|
|
|
}
|
|
|
|
printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
|
|
|
|
|
|
|
|
uip_getdraddr(&addr);
|
|
|
|
if(addr.u8[0] == 0) {
|
2012-05-17 19:34:58 +02:00
|
|
|
uip_ipaddr(&addr, 172,18,0,1);
|
2012-01-25 15:34:10 +01:00
|
|
|
uip_setdraddr(&addr);
|
|
|
|
}
|
|
|
|
printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr));
|
2010-02-02 18:51:55 +01:00
|
|
|
}
|
2014-12-01 21:02:57 +01:00
|
|
|
#else /* NETSTACK_CONF_WITH_IPV6 */
|
2011-06-28 14:19:48 +02:00
|
|
|
|
|
|
|
#if !UIP_CONF_IPV6_RPL
|
2012-01-25 15:34:10 +01:00
|
|
|
{
|
|
|
|
uip_ipaddr_t ipaddr;
|
2011-08-03 18:30:20 +02:00
|
|
|
#ifdef HARD_CODED_ADDRESS
|
2012-01-25 15:34:10 +01:00
|
|
|
uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
|
2011-08-03 18:30:20 +02:00
|
|
|
#else
|
2012-01-25 15:34:10 +01:00
|
|
|
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
2011-08-03 18:30:20 +02:00
|
|
|
#endif
|
2012-01-25 15:34:10 +01:00
|
|
|
if((ipaddr.u16[0] != 0) ||
|
|
|
|
(ipaddr.u16[1] != 0) ||
|
|
|
|
(ipaddr.u16[2] != 0) ||
|
|
|
|
(ipaddr.u16[3] != 0)) {
|
2010-03-18 21:11:54 +01:00
|
|
|
#if UIP_CONF_ROUTER
|
2012-05-17 19:34:58 +02:00
|
|
|
if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0)) {
|
|
|
|
fprintf(stderr,"uip_ds6_prefix_add() failed.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2010-03-18 21:11:54 +01:00
|
|
|
#else /* UIP_CONF_ROUTER */
|
2012-05-17 19:34:58 +02:00
|
|
|
if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0)) {
|
|
|
|
fprintf(stderr,"uip_ds6_prefix_add() failed.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2010-03-18 21:11:54 +01:00
|
|
|
#endif /* UIP_CONF_ROUTER */
|
2011-06-28 14:19:48 +02:00
|
|
|
|
2012-01-25 15:34:10 +01:00
|
|
|
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
|
|
|
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
|
|
|
}
|
2010-03-18 21:11:54 +01:00
|
|
|
}
|
2012-01-25 15:34:10 +01:00
|
|
|
#endif /* !UIP_CONF_IPV6_RPL */
|
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#endif /* !NETSTACK_CONF_WITH_IPV6 */
|
2012-02-11 21:19:28 +01:00
|
|
|
|
|
|
|
// procinit_init();
|
|
|
|
// autostart_start(autostart_processes);
|
|
|
|
|
|
|
|
/* Make standard output unbuffered. */
|
|
|
|
setvbuf(stdout, (char *)NULL, _IONBF, 0);
|
|
|
|
|
|
|
|
printf("\n*******%s online*******\n",CONTIKI_VERSION_STRING);
|
|
|
|
|
2014-12-01 21:02:57 +01:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6 && !RPL_BORDER_ROUTER /* Border router process prints addresses later */
|
2012-01-25 15:34:10 +01:00
|
|
|
{
|
2012-05-17 19:34:58 +02:00
|
|
|
int i = 0;
|
|
|
|
int interface_count = 0;
|
2012-01-25 15:34:10 +01:00
|
|
|
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
2012-03-21 21:27:52 +01:00
|
|
|
if(uip_ds6_if.addr_list[i].isused) {
|
2012-05-17 19:34:58 +02:00
|
|
|
printf("IPV6 Addresss: ");
|
|
|
|
sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);
|
|
|
|
printf("\n");
|
|
|
|
interface_count++;
|
2012-01-25 15:34:10 +01:00
|
|
|
}
|
|
|
|
}
|
2012-05-17 19:34:58 +02:00
|
|
|
assert(0 < interface_count);
|
2012-01-25 15:34:10 +01:00
|
|
|
}
|
2012-02-11 21:19:28 +01:00
|
|
|
#endif
|
2011-07-24 17:53:36 +02:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
while(1) {
|
2009-03-06 01:13:56 +01:00
|
|
|
fd_set fds;
|
2006-06-18 00:41:10 +02:00
|
|
|
int n;
|
2007-11-28 13:54:41 +01:00
|
|
|
struct timeval tv;
|
2012-05-17 19:34:58 +02:00
|
|
|
clock_time_t next_event;
|
2007-11-27 00:28:33 +01:00
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
n = process_run();
|
2012-05-17 19:34:58 +02:00
|
|
|
next_event = etimer_next_expiration_time() - clock_time();
|
|
|
|
|
|
|
|
#if DEBUG_SLEEP
|
|
|
|
if(n > 0)
|
|
|
|
printf("sleep: %d events pending\n",n);
|
|
|
|
else
|
|
|
|
printf("sleep: next event @ T-%.03f\n",(double)next_event / (double)CLOCK_SECOND);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
/* wpcap doesn't appear to support select, so
|
|
|
|
* we can't idle the process on windows. */
|
|
|
|
next_event = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(next_event > (CLOCK_SECOND * 2))
|
|
|
|
next_event = CLOCK_SECOND * 2;
|
|
|
|
tv.tv_sec = n ? 0 : (next_event / CLOCK_SECOND);
|
|
|
|
tv.tv_usec = n ? 0 : ((next_event % 1000) * 1000);
|
2007-11-27 00:28:33 +01:00
|
|
|
|
2009-03-06 01:13:56 +01:00
|
|
|
FD_ZERO(&fds);
|
|
|
|
FD_SET(STDIN_FILENO, &fds);
|
2012-05-17 19:34:58 +02:00
|
|
|
#ifdef __CYGWIN__
|
2009-03-06 01:13:56 +01:00
|
|
|
select(1, &fds, NULL, NULL, &tv);
|
2012-05-17 19:34:58 +02:00
|
|
|
#else
|
|
|
|
FD_SET(tapdev_fd(), &fds);
|
|
|
|
if(0 > select(tapdev_fd() + 1, &fds, NULL, NULL, &tv)) {
|
|
|
|
perror("Call to select() failed.");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
#endif
|
2009-03-06 01:13:56 +01:00
|
|
|
|
|
|
|
if(FD_ISSET(STDIN_FILENO, &fds)) {
|
|
|
|
char c;
|
|
|
|
if(read(STDIN_FILENO, &c, 1) > 0) {
|
2009-03-17 16:56:32 +01:00
|
|
|
serial_line_input_byte(c);
|
2009-03-06 01:13:56 +01:00
|
|
|
}
|
|
|
|
}
|
2013-06-06 19:04:11 +02:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
process_poll(&wpcap_process);
|
|
|
|
#else
|
2012-05-17 19:34:58 +02:00
|
|
|
process_poll(&tapdev_process);
|
2013-06-06 19:04:11 +02:00
|
|
|
#endif
|
2006-06-18 00:41:10 +02:00
|
|
|
etimer_request_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-01-25 15:41:39 +01:00
|
|
|
void
|
|
|
|
log_message(char *m1, char *m2)
|
2006-06-18 00:41:10 +02:00
|
|
|
{
|
|
|
|
printf("%s%s\n", m1, m2);
|
|
|
|
}
|
2007-11-25 16:00:32 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2006-06-18 00:41:10 +02:00
|
|
|
void
|
|
|
|
uip_log(char *m)
|
|
|
|
{
|
|
|
|
printf("uIP: '%s'\n", m);
|
|
|
|
}
|
2007-11-25 16:00:32 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-05-17 19:34:58 +02:00
|
|
|
void
|
|
|
|
_xassert(const char *file, int line)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%u: failed assertion\n", file, line);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-18 00:41:10 +02:00
|
|
|
unsigned short
|
|
|
|
sensors_light1(void)
|
|
|
|
{
|
|
|
|
static unsigned short count;
|
|
|
|
return count++;
|
|
|
|
}
|
2007-11-25 16:00:32 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|