39 #include <sys/select.h>
44 #include "contiki-net.h"
45 #include "lib/assert.h"
51 #include "net/wpcap-drv.h"
53 #include "net/tapdev-drv.h"
57 #if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
58 PROCINIT(&etimer_process, &tcpip_process, &wpcap_process, &serial_line_process);
60 PROCINIT(&etimer_process, &wpcap_process, &serial_line_process);
63 #if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
64 PROCINIT(&etimer_process, &tapdev_process, &tcpip_process, &serial_line_process);
66 PROCINIT(&etimer_process, &tapdev_process, &serial_line_process);
71 #include "net/rpl/rpl.h"
73 static uint16_t dag_id[] = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011};
75 PROCESS(border_router_process,
"RPL Border Router");
85 char buf[
sizeof(dag_id)];
86 memcpy(buf,dag_id,
sizeof(dag_id));
87 dag = rpl_set_root((uip_ip6addr_t *)buf);
98 printf(
"Created a new RPL dag\n");
100 #if UIP_CONF_ROUTER_RECEIVE_RA
108 static void sprint_ip6(uip_ip6addr_t
addr);
111 #ifdef HARD_CODED_ADDRESS
114 uip_ip6addr(&ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1);
118 rpl_set_prefix(dag, &ipaddr, 64);
120 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
122 printf(
"IPV6 Address: ");
146 #if NETSTACK_CONF_WITH_IPV6
149 sprint_ip6(uip_ip6addr_t
addr)
152 unsigned char zerocnt = 0;
153 unsigned char numprinted = 0;
154 unsigned char notskipped = 0;
156 char *result = thestring;
159 while(numprinted < 8) {
160 if((addr.u16[i] == 0) && (zerocnt == 0)) {
161 while(addr.u16[zerocnt + i] == 0) {
164 if(zerocnt == 1 && notskipped) {
171 numprinted += zerocnt;
173 result += sprintf(result,
"%x", (
unsigned int)(uip_ntohs(addr.u16[i])));
177 if(numprinted != 8) {
183 printf(
"%s", thestring);
187 int contiki_argc = 0;
191 main(
int argc,
char **argv)
202 #ifdef UIP_FALLBACK_INTERFACE
209 #if NETSTACK_CONF_WITH_IPV6
222 #ifdef HARD_CODED_ADDRESS
226 if((ipaddr.u8[13] != 0) ||
227 (ipaddr.u8[14] != 0) ||
228 (ipaddr.u8[15] != 0)) {
248 #if RPL_BORDER_ROUTER
250 printf(
"Border Router Process started\n");
251 #elif UIP_CONF_IPV6_RPL
252 printf(
"RPL enabled\n");
256 autostart_start(autostart_processes);
259 #if !NETSTACK_CONF_WITH_IPV6
264 if(addr.u8[0] == 0) {
271 if(addr.u8[0] == 0) {
278 if(addr.u8[0] == 0) {
286 #if !UIP_CONF_IPV6_RPL
289 #ifdef HARD_CODED_ADDRESS
292 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
294 if((ipaddr.u16[0] != 0) ||
295 (ipaddr.u16[1] != 0) ||
296 (ipaddr.u16[2] != 0) ||
297 (ipaddr.u16[3] != 0)) {
299 if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0)) {
300 fprintf(stderr,
"uip_ds6_prefix_add() failed.\n");
304 if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0)) {
305 fprintf(stderr,
"uip_ds6_prefix_add() failed.\n");
322 setvbuf(stdout, (
char *)
NULL, _IONBF, 0);
324 printf(
"\n*******%s online*******\n",CONTIKI_VERSION_STRING);
326 #if NETSTACK_CONF_WITH_IPV6 && !RPL_BORDER_ROUTER
329 int interface_count = 0;
330 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
332 printf(
"IPV6 Addresss: ");
338 assert(0 < interface_count);
346 clock_time_t next_event;
353 printf(
"sleep: %d events pending\n",n);
355 printf(
"sleep: next event @ T-%.03f\n",(
double)next_event / (
double)
CLOCK_SECOND);
367 tv.tv_usec = n ? 0 : ((next_event % 1000) * 1000);
370 FD_SET(STDIN_FILENO, &fds);
374 FD_SET(tapdev_fd(), &fds);
375 if(0 > select(tapdev_fd() + 1, &fds,
NULL,
NULL, &tv)) {
376 perror(
"Call to select() failed.");
381 if(FD_ISSET(STDIN_FILENO, &fds)) {
383 if(read(STDIN_FILENO, &c, 1) > 0) {
399 log_message(
char *m1,
char *m2)
401 printf(
"%s%s\n", m1, m2);
407 printf(
"uIP: '%s'\n", m);
411 _xassert(
const char *file,
int line)
413 fprintf(stderr,
"%s:%u: failed assertion\n", file, line);
421 static unsigned short count;
void uip_log(char *m)
Print out a uIP log message.
void process_poll(struct process *p)
Request a process to be polled.
#define uip_sethostaddr(addr)
Set the IP address of this host.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
#define uip_setdraddr(addr)
Set the default router's IP address.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
clock_time_t etimer_next_expiration_time(void)
Get next event timer expiration time.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
CCIF clock_time_t clock_time(void)
Get the current clock time.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
#define uip_getnetmask(addr)
Get the netmask.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
void clock_init(void)
Initialize the clock library.
int process_run(void)
Run the system once - call poll handlers and process one event.
#define uip_setnetmask(addr)
Set the netmask.
#define NULL
The null pointer.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
#define PROCESS_YIELD()
Yield the currently running process.
#define CLOCK_SECOND
A second, measured in system clock time.
#define uip_gethostaddr(addr)
Get the IP address of this host.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
static volatile clock_time_t count
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number...
Header file for the uIP TCP/IP stack.
void process_start(struct process *p, process_data_t data)
Start a process.
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
int main(void)
This is main...
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
#define uip_getdraddr(addr)
Get the default router's IP address.
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
void process_init(void)
Initialize the process module.
void ctimer_init(void)
Initialize the callback timer library.
uip_ds6_netif_t uip_ds6_if
The single interface.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
#define PROCESS_PAUSE()
Yield the process for a short while.
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
#define PROCESS_BEGIN()
Define the beginning of a process.