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 PROCINIT(&etimer_process, &tcpip_process, &wpcap_process, &serial_line_process);
59 PROCINIT(&etimer_process, &tapdev_process, &tcpip_process, &serial_line_process);
63 #include "net/rpl/rpl.h"
65 static uint16_t dag_id[] = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011};
67 PROCESS(border_router_process,
"RPL Border Router");
77 char buf[
sizeof(dag_id)];
78 memcpy(buf,dag_id,
sizeof(dag_id));
79 dag = rpl_set_root((uip_ip6addr_t *)buf);
90 printf(
"Created a new RPL dag\n");
92 #if UIP_CONF_ROUTER_RECEIVE_RA
100 static void sprint_ip6(uip_ip6addr_t addr);
102 uip_ip6addr_t ipaddr;
103 #ifdef HARD_CODED_ADDRESS
106 uip_ip6addr(&ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1);
109 uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
110 rpl_set_prefix(dag, &ipaddr, 64);
112 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
113 if(uip_ds6_if.addr_list[i].isused) {
114 printf(
"IPV6 Address: ");
115 sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);
141 sprint_ip6(uip_ip6addr_t addr)
144 unsigned char zerocnt = 0;
145 unsigned char numprinted = 0;
146 unsigned char notskipped = 0;
148 char *result = thestring;
151 while(numprinted < 8) {
152 if((addr.u16[i] == 0) && (zerocnt == 0)) {
153 while(addr.u16[zerocnt + i] == 0) {
156 if(zerocnt == 1 && notskipped) {
163 numprinted += zerocnt;
165 result += sprintf(result,
"%x", (
unsigned int)(uip_ntohs(addr.u16[i])));
169 if(numprinted != 8) {
175 printf(
"%s", thestring);
179 int contiki_argc = 0;
183 main(
int argc,
char **argv)
194 #ifdef UIP_FALLBACK_INTERFACE
214 #ifdef HARD_CODED_ADDRESS
218 if((ipaddr.u8[13] != 0) ||
219 (ipaddr.u8[14] != 0) ||
220 (ipaddr.u8[15] != 0)) {
240 #if RPL_BORDER_ROUTER
242 printf(
"Border Router Process started\n");
243 #elif UIP_CONF_IPV6_RPL
244 printf(
"RPL enabled\n");
248 autostart_start(autostart_processes);
256 if(addr.u8[0] == 0) {
263 if(addr.u8[0] == 0) {
270 if(addr.u8[0] == 0) {
278 #if !UIP_CONF_IPV6_RPL
281 #ifdef HARD_CODED_ADDRESS
286 if((ipaddr.u16[0] != 0) ||
287 (ipaddr.u16[1] != 0) ||
288 (ipaddr.u16[2] != 0) ||
289 (ipaddr.u16[3] != 0)) {
291 if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0)) {
292 fprintf(stderr,
"uip_ds6_prefix_add() failed.\n");
296 if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0)) {
297 fprintf(stderr,
"uip_ds6_prefix_add() failed.\n");
303 uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
314 setvbuf(stdout, (
char *)
NULL, _IONBF, 0);
316 printf(
"\n*******%s online*******\n",CONTIKI_VERSION_STRING);
318 #if UIP_CONF_IPV6 && !RPL_BORDER_ROUTER
321 int interface_count = 0;
322 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
323 if(uip_ds6_if.addr_list[i].isused) {
324 printf(
"IPV6 Addresss: ");
325 sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);
330 assert(0 < interface_count);
338 clock_time_t next_event;
345 printf(
"sleep: %d events pending\n",n);
347 printf(
"sleep: next event @ T-%.03f\n",(
double)next_event / (
double)
CLOCK_SECOND);
359 tv.tv_usec = n ? 0 : ((next_event % 1000) * 1000);
362 FD_SET(STDIN_FILENO, &fds);
366 FD_SET(tapdev_fd(), &fds);
367 if(0 > select(tapdev_fd() + 1, &fds,
NULL,
NULL, &tv)) {
368 perror(
"Call to select() failed.");
373 if(FD_ISSET(STDIN_FILENO, &fds)) {
375 if(read(STDIN_FILENO, &c, 1) > 0) {
391 log_message(
char *m1,
char *m2)
393 printf(
"%s%s\n", m1, m2);
399 printf(
"uIP: '%s'\n", m);
403 _xassert(
const char *file,
int line)
405 fprintf(stderr,
"%s:%u: failed assertion\n", file, line);
413 static unsigned short count;
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
#define uip_sethostaddr(addr)
Set the IP address of this host.
void process_poll(struct process *p)
Request a process to be polled.
#define uip_gethostaddr(addr)
Get the IP address of this host.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
#define PROCESS_BEGIN()
Define the beginning of a process.
Header file for the uIP TCP/IP stack.
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 NULL
The null pointer.
void uip_log(char *msg)
Print out a uIP log message.
void clock_init(void)
Initialize the clock library.
int main(void)
This is main...
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
void process_init(void)
Initialize the process module.
#define uip_getdraddr(addr)
Get the default router's IP address.
#define uip_setdraddr(addr)
Set the default router's IP address.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
CCIF clock_time_t clock_time(void)
Get the current clock time.
Generic serial I/O process header filer.
#define uip_getnetmask(addr)
Get the netmask.
void ctimer_init(void)
Initialize the callback timer library.
clock_time_t etimer_next_expiration_time(void)
Get next event timer expiration time.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
#define PROCESS_PAUSE()
Yield the process for a short while.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
#define PROCESS(name, strname)
Declare a process.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_YIELD()
Yield the currently running process.
int process_run(void)
Run the system once - call poll handlers and process one event.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
#define uip_setnetmask(addr)
Set the netmask.
#define CLOCK_SECOND
A second, measured in system clock time.