2010-05-05 19:44:30 +00:00
|
|
|
/*
|
|
|
|
* 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. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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 operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* border-router
|
|
|
|
* \author
|
|
|
|
* Niclas Finne <nfi@sics.se>
|
|
|
|
* Joakim Eriksson <joakime@sics.se>
|
|
|
|
* Nicolas Tsiftes <nvt@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-lib.h"
|
|
|
|
#include "contiki-net.h"
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip.h"
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2017-06-10 12:35:39 +00:00
|
|
|
#include "rpl.h"
|
|
|
|
#if UIP_CONF_IPV6_RPL_LITE == 0
|
|
|
|
#include "rpl-private.h"
|
|
|
|
#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */
|
|
|
|
#include "rpl-dag-root.h"
|
2016-06-29 14:51:38 +00:00
|
|
|
#if RPL_WITH_NON_STORING
|
2017-06-10 12:35:39 +00:00
|
|
|
#include "rpl-ns.h"
|
2016-06-29 14:51:38 +00:00
|
|
|
#endif /* RPL_WITH_NON_STORING */
|
2010-05-05 19:44:30 +00:00
|
|
|
#include "net/netstack.h"
|
|
|
|
#include "dev/button-sensor.h"
|
2010-05-25 20:34:51 +00:00
|
|
|
#include "dev/slip.h"
|
2017-10-29 03:08:30 +00:00
|
|
|
#include "net/ipv6/uip-debug.h"
|
2017-10-29 03:08:07 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-05 19:44:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2017-10-29 03:08:30 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Log configuration */
|
|
|
|
#include "sys/log.h"
|
|
|
|
#define LOG_MODULE "BR"
|
2017-10-31 22:10:37 +00:00
|
|
|
#define LOG_LEVEL LOG_LEVEL_INFO
|
2017-10-29 03:08:30 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-25 20:34:51 +00:00
|
|
|
static uip_ipaddr_t prefix;
|
|
|
|
static uint8_t prefix_set;
|
2017-10-29 03:08:07 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-05 19:44:30 +00:00
|
|
|
PROCESS(border_router_process, "Border router process");
|
2017-10-29 03:08:07 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-10-28 22:48:46 +00:00
|
|
|
#if BORDER_ROUTER_CONF_WEBSERVER
|
2012-03-06 14:10:12 +00:00
|
|
|
/* Use simple webserver with only one page for minimum footprint.
|
|
|
|
* Multiple connections can result in interleaved tcp segments since
|
|
|
|
* a single static buffer is used for all segments.
|
|
|
|
*/
|
2011-08-15 22:30:31 +00:00
|
|
|
#include "httpd-simple.h"
|
2012-03-06 14:10:12 +00:00
|
|
|
/* The internal webserver can provide additional information if
|
|
|
|
* enough program flash is available.
|
|
|
|
*/
|
2012-03-02 21:01:12 +00:00
|
|
|
#define WEBSERVER_CONF_LOADTIME 0
|
|
|
|
#define WEBSERVER_CONF_FILESTATS 0
|
|
|
|
#define WEBSERVER_CONF_NEIGHBOR_STATUS 0
|
2012-03-06 14:10:12 +00:00
|
|
|
/* Adding links requires a larger RAM buffer. To avoid static allocation
|
|
|
|
* the stack can be used for formatting; however tcp retransmissions
|
|
|
|
* and multiple connections can result in garbled segments.
|
|
|
|
* TODO:use PSOCk_GENERATOR_SEND and tcp state storage to fix this.
|
|
|
|
*/
|
2012-03-02 21:01:12 +00:00
|
|
|
#define WEBSERVER_CONF_ROUTE_LINKS 0
|
2012-03-06 14:10:12 +00:00
|
|
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
2012-03-02 21:01:12 +00:00
|
|
|
#define BUF_USES_STACK 1
|
2012-03-06 14:10:12 +00:00
|
|
|
#endif
|
2012-03-02 21:01:12 +00:00
|
|
|
|
2011-08-15 22:30:31 +00:00
|
|
|
PROCESS(webserver_nogui_process, "Web server");
|
|
|
|
PROCESS_THREAD(webserver_nogui_process, ev, data)
|
|
|
|
{
|
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
|
|
|
httpd_init();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
|
|
|
|
httpd_appcall(data);
|
|
|
|
}
|
2014-10-04 16:05:38 +00:00
|
|
|
|
2011-08-15 22:30:31 +00:00
|
|
|
PROCESS_END();
|
|
|
|
}
|
2011-03-13 15:59:17 +00:00
|
|
|
|
2010-05-09 12:52:05 +00:00
|
|
|
static const char *TOP = "<html><head><title>ContikiRPL</title></head><body>\n";
|
|
|
|
static const char *BOTTOM = "</body></html>\n";
|
2012-03-02 21:01:12 +00:00
|
|
|
#if BUF_USES_STACK
|
|
|
|
static char *bufptr, *bufend;
|
|
|
|
#define ADD(...) do { \
|
|
|
|
bufptr += snprintf(bufptr, bufend - bufptr, __VA_ARGS__); \
|
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
static char buf[256];
|
2010-05-09 12:52:05 +00:00
|
|
|
static int blen;
|
|
|
|
#define ADD(...) do { \
|
|
|
|
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
|
|
|
} while(0)
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-09 12:52:05 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
ipaddr_add(const uip_ipaddr_t *addr)
|
|
|
|
{
|
|
|
|
uint16_t a;
|
|
|
|
int i, f;
|
|
|
|
for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
|
|
|
|
a = (addr->u8[i] << 8) + addr->u8[i + 1];
|
|
|
|
if(a == 0 && f >= 0) {
|
2012-03-02 21:01:12 +00:00
|
|
|
if(f++ == 0) ADD("::");
|
2010-05-09 12:52:05 +00:00
|
|
|
} else {
|
|
|
|
if(f > 0) {
|
|
|
|
f = -1;
|
2012-03-02 21:01:12 +00:00
|
|
|
} else if(i > 0) {
|
|
|
|
ADD(":");
|
2010-05-09 12:52:05 +00:00
|
|
|
}
|
|
|
|
ADD("%x", a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static
|
|
|
|
PT_THREAD(generate_routes(struct httpd_state *s))
|
|
|
|
{
|
2012-11-26 18:58:52 +00:00
|
|
|
static uip_ds6_route_t *r;
|
2016-06-29 14:51:38 +00:00
|
|
|
#if RPL_WITH_NON_STORING
|
|
|
|
static rpl_ns_node_t *link;
|
|
|
|
#endif /* RPL_WITH_NON_STORING */
|
2013-07-03 18:26:54 +00:00
|
|
|
static uip_ds6_nbr_t *nbr;
|
2012-03-02 21:01:12 +00:00
|
|
|
#if BUF_USES_STACK
|
|
|
|
char buf[256];
|
|
|
|
#endif
|
|
|
|
#if WEBSERVER_CONF_LOADTIME
|
|
|
|
static clock_time_t numticks;
|
|
|
|
numticks = clock_time();
|
|
|
|
#endif
|
|
|
|
|
2010-05-09 12:52:05 +00:00
|
|
|
PSOCK_BEGIN(&s->sout);
|
|
|
|
|
|
|
|
SEND_STRING(&s->sout, TOP);
|
2012-03-02 21:01:12 +00:00
|
|
|
#if BUF_USES_STACK
|
|
|
|
bufptr = buf;bufend=bufptr+sizeof(buf);
|
|
|
|
#else
|
2010-05-09 12:52:05 +00:00
|
|
|
blen = 0;
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
2011-10-27 13:20:04 +00:00
|
|
|
ADD("Neighbors<pre>");
|
2013-07-03 18:26:54 +00:00
|
|
|
|
|
|
|
for(nbr = nbr_table_head(ds6_neighbors);
|
|
|
|
nbr != NULL;
|
|
|
|
nbr = nbr_table_next(ds6_neighbors, nbr)) {
|
2012-03-02 21:01:12 +00:00
|
|
|
|
|
|
|
#if WEBSERVER_CONF_NEIGHBOR_STATUS
|
|
|
|
#if BUF_USES_STACK
|
|
|
|
{char* j=bufptr+25;
|
2013-07-03 18:26:54 +00:00
|
|
|
ipaddr_add(&nbr->ipaddr);
|
2012-03-02 21:01:12 +00:00
|
|
|
while (bufptr < j) ADD(" ");
|
2013-07-03 18:26:54 +00:00
|
|
|
switch (nbr->state) {
|
2012-03-02 21:01:12 +00:00
|
|
|
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
|
|
|
|
case NBR_REACHABLE: ADD(" REACHABLE");break;
|
2014-10-04 16:05:38 +00:00
|
|
|
case NBR_STALE: ADD(" STALE");break;
|
2012-03-02 21:01:12 +00:00
|
|
|
case NBR_DELAY: ADD(" DELAY");break;
|
|
|
|
case NBR_PROBE: ADD(" NBR_PROBE");break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{uint8_t j=blen+25;
|
2013-07-03 18:26:54 +00:00
|
|
|
ipaddr_add(&nbr->ipaddr);
|
2012-03-02 21:01:12 +00:00
|
|
|
while (blen < j) ADD(" ");
|
2013-07-03 18:26:54 +00:00
|
|
|
switch (nbr->state) {
|
2012-03-02 21:01:12 +00:00
|
|
|
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
|
|
|
|
case NBR_REACHABLE: ADD(" REACHABLE");break;
|
2014-10-04 16:05:38 +00:00
|
|
|
case NBR_STALE: ADD(" STALE");break;
|
2012-03-02 21:01:12 +00:00
|
|
|
case NBR_DELAY: ADD(" DELAY");break;
|
|
|
|
case NBR_PROBE: ADD(" NBR_PROBE");break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#else
|
2013-07-03 18:26:54 +00:00
|
|
|
ipaddr_add(&nbr->ipaddr);
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-27 13:20:04 +00:00
|
|
|
ADD("\n");
|
2012-03-02 21:01:12 +00:00
|
|
|
#if BUF_USES_STACK
|
|
|
|
if(bufptr > bufend - 45) {
|
|
|
|
SEND_STRING(&s->sout, buf);
|
|
|
|
bufptr = buf; bufend = bufptr + sizeof(buf);
|
|
|
|
}
|
|
|
|
#else
|
2010-05-10 14:25:02 +00:00
|
|
|
if(blen > sizeof(buf) - 45) {
|
|
|
|
SEND_STRING(&s->sout, buf);
|
|
|
|
blen = 0;
|
|
|
|
}
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
2010-05-09 12:52:05 +00:00
|
|
|
}
|
2016-06-29 14:51:38 +00:00
|
|
|
ADD("</pre>Routes<pre>\n");
|
2010-05-10 14:25:02 +00:00
|
|
|
SEND_STRING(&s->sout, buf);
|
2012-03-02 21:01:12 +00:00
|
|
|
#if BUF_USES_STACK
|
|
|
|
bufptr = buf; bufend = bufptr + sizeof(buf);
|
|
|
|
#else
|
2010-05-10 14:25:02 +00:00
|
|
|
blen = 0;
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
2012-11-26 18:58:52 +00:00
|
|
|
|
2013-07-03 18:26:54 +00:00
|
|
|
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
|
2012-11-26 18:58:52 +00:00
|
|
|
|
2012-03-02 21:01:12 +00:00
|
|
|
#if BUF_USES_STACK
|
|
|
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
2012-11-26 18:58:52 +00:00
|
|
|
ADD("<a href=http://[");
|
|
|
|
ipaddr_add(&r->ipaddr);
|
|
|
|
ADD("]/status.shtml>");
|
|
|
|
ipaddr_add(&r->ipaddr);
|
|
|
|
ADD("</a>");
|
2012-03-02 21:01:12 +00:00
|
|
|
#else
|
2012-11-26 18:58:52 +00:00
|
|
|
ipaddr_add(&r->ipaddr);
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
2012-11-26 18:58:52 +00:00
|
|
|
ADD("<a href=http://[");
|
|
|
|
ipaddr_add(&r->ipaddr);
|
|
|
|
ADD("]/status.shtml>");
|
|
|
|
SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
|
|
|
|
blen = 0;
|
|
|
|
ipaddr_add(&r->ipaddr);
|
|
|
|
ADD("</a>");
|
2012-03-02 21:01:12 +00:00
|
|
|
#else
|
2012-11-26 18:58:52 +00:00
|
|
|
ipaddr_add(&r->ipaddr);
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2012-11-26 18:58:52 +00:00
|
|
|
ADD("/%u (via ", r->length);
|
2013-07-03 18:26:54 +00:00
|
|
|
ipaddr_add(uip_ds6_route_nexthop(r));
|
2012-11-26 18:58:52 +00:00
|
|
|
if(1 || (r->state.lifetime < 600)) {
|
2014-10-04 16:05:38 +00:00
|
|
|
ADD(") %lus\n", (unsigned long)r->state.lifetime);
|
2012-11-26 18:58:52 +00:00
|
|
|
} else {
|
|
|
|
ADD(")\n");
|
|
|
|
}
|
|
|
|
SEND_STRING(&s->sout, buf);
|
2012-03-02 21:01:12 +00:00
|
|
|
#if BUF_USES_STACK
|
2012-11-26 18:58:52 +00:00
|
|
|
bufptr = buf; bufend = bufptr + sizeof(buf);
|
2012-03-02 21:01:12 +00:00
|
|
|
#else
|
2012-11-26 18:58:52 +00:00
|
|
|
blen = 0;
|
2012-03-02 21:01:12 +00:00
|
|
|
#endif
|
2010-05-09 12:52:05 +00:00
|
|
|
}
|
2011-10-27 13:20:04 +00:00
|
|
|
ADD("</pre>");
|
2010-05-09 12:52:05 +00:00
|
|
|
|
2016-06-29 14:51:38 +00:00
|
|
|
#if RPL_WITH_NON_STORING
|
|
|
|
ADD("Links<pre>\n");
|
|
|
|
SEND_STRING(&s->sout, buf);
|
|
|
|
#if BUF_USES_STACK
|
|
|
|
bufptr = buf; bufend = bufptr + sizeof(buf);
|
|
|
|
#else
|
|
|
|
blen = 0;
|
|
|
|
#endif
|
|
|
|
for(link = rpl_ns_node_head(); link != NULL; link = rpl_ns_node_next(link)) {
|
|
|
|
if(link->parent != NULL) {
|
|
|
|
uip_ipaddr_t child_ipaddr;
|
|
|
|
uip_ipaddr_t parent_ipaddr;
|
|
|
|
|
|
|
|
rpl_ns_get_node_global_addr(&child_ipaddr, link);
|
|
|
|
rpl_ns_get_node_global_addr(&parent_ipaddr, link->parent);
|
|
|
|
|
|
|
|
#if BUF_USES_STACK
|
|
|
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
|
|
|
ADD("<a href=http://[");
|
|
|
|
ipaddr_add(&child_ipaddr);
|
|
|
|
ADD("]/status.shtml>");
|
|
|
|
ipaddr_add(&child_ipaddr);
|
|
|
|
ADD("</a>");
|
|
|
|
#else
|
|
|
|
ipaddr_add(&child_ipaddr);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
|
|
|
ADD("<a href=http://[");
|
|
|
|
ipaddr_add(&child_ipaddr);
|
|
|
|
ADD("]/status.shtml>");
|
|
|
|
SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
|
|
|
|
blen = 0;
|
|
|
|
ipaddr_add(&child_ipaddr);
|
|
|
|
ADD("</a>");
|
|
|
|
#else
|
|
|
|
ipaddr_add(&child_ipaddr);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ADD(" (parent: ");
|
|
|
|
ipaddr_add(&parent_ipaddr);
|
|
|
|
if(1 || (link->lifetime < 600)) {
|
|
|
|
ADD(") %us\n", (unsigned int)link->lifetime); // iotlab printf does not have %lu
|
|
|
|
//ADD(") %lus\n", (unsigned long)r->state.lifetime);
|
|
|
|
} else {
|
|
|
|
ADD(")\n");
|
|
|
|
}
|
|
|
|
SEND_STRING(&s->sout, buf);
|
|
|
|
#if BUF_USES_STACK
|
|
|
|
bufptr = buf; bufend = bufptr + sizeof(buf);
|
|
|
|
#else
|
|
|
|
blen = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ADD("</pre>");
|
|
|
|
#endif /* RPL_WITH_NON_STORING */
|
|
|
|
|
2012-03-02 21:01:12 +00:00
|
|
|
#if WEBSERVER_CONF_FILESTATS
|
|
|
|
static uint16_t numtimes;
|
|
|
|
ADD("<br><i>This page sent %u times</i>",++numtimes);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WEBSERVER_CONF_LOADTIME
|
|
|
|
numticks = clock_time() - numticks + 1;
|
|
|
|
ADD(" <i>(%u.%02u sec)</i>",numticks/CLOCK_SECOND,(100*(numticks%CLOCK_SECOND))/CLOCK_SECOND));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SEND_STRING(&s->sout, buf);
|
2010-05-09 12:52:05 +00:00
|
|
|
SEND_STRING(&s->sout, BOTTOM);
|
|
|
|
|
|
|
|
PSOCK_END(&s->sout);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
httpd_simple_script_t
|
|
|
|
httpd_simple_get_script(const char *name)
|
|
|
|
{
|
|
|
|
return generate_routes;
|
|
|
|
}
|
2017-10-28 22:48:46 +00:00
|
|
|
#endif /* BORDER_ROUTER_CONF_WEBSERVER */
|
2010-05-09 12:52:05 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-05 19:44:30 +00:00
|
|
|
static void
|
|
|
|
print_local_addresses(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t state;
|
|
|
|
|
2017-10-31 22:10:37 +00:00
|
|
|
LOG_INFO("Server IPv6 addresses:\n");
|
2010-05-05 19:44:30 +00:00
|
|
|
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
|
|
|
state = uip_ds6_if.addr_list[i].state;
|
2010-05-10 15:15:17 +00:00
|
|
|
if(uip_ds6_if.addr_list[i].isused &&
|
|
|
|
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
2017-11-01 07:51:41 +00:00
|
|
|
LOG_INFO(" ");
|
2017-10-31 22:10:37 +00:00
|
|
|
LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
|
|
|
LOG_INFO_("\n");
|
2010-05-05 19:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-25 20:34:51 +00:00
|
|
|
void
|
2010-11-03 07:53:12 +00:00
|
|
|
request_prefix(void)
|
|
|
|
{
|
2010-05-25 20:34:51 +00:00
|
|
|
/* mess up uip_buf with a dirty request... */
|
2011-03-11 15:34:30 +00:00
|
|
|
uip_buf[0] = '?';
|
2010-05-25 20:34:51 +00:00
|
|
|
uip_buf[1] = 'P';
|
|
|
|
uip_len = 2;
|
|
|
|
slip_send();
|
2015-06-15 08:25:58 +00:00
|
|
|
uip_clear_buf();
|
2010-05-25 20:34:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2010-11-03 07:53:12 +00:00
|
|
|
set_prefix_64(uip_ipaddr_t *prefix_64)
|
|
|
|
{
|
2010-05-25 20:34:51 +00:00
|
|
|
memcpy(&prefix, prefix_64, 16);
|
|
|
|
prefix_set = 1;
|
2017-06-10 12:35:39 +00:00
|
|
|
rpl_dag_root_init(prefix_64, NULL);
|
|
|
|
rpl_dag_root_init_dag_immediately();
|
2010-05-25 20:34:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-05-05 19:44:30 +00:00
|
|
|
PROCESS_THREAD(border_router_process, ev, data)
|
|
|
|
{
|
2010-05-25 20:34:51 +00:00
|
|
|
static struct etimer et;
|
2010-05-05 19:44:30 +00:00
|
|
|
|
|
|
|
PROCESS_BEGIN();
|
2012-02-11 20:15:00 +00:00
|
|
|
|
2012-03-02 21:01:12 +00:00
|
|
|
/* While waiting for the prefix to be sent through the SLIP connection, the future
|
2014-10-04 16:05:38 +00:00
|
|
|
* border router can join an existing DAG as a parent or child, or acquire a default
|
2012-03-02 21:01:12 +00:00
|
|
|
* router that will later take precedence over the SLIP fallback interface.
|
|
|
|
* Prevent that by turning the radio off until we are initialized as a DAG root.
|
|
|
|
*/
|
2010-05-25 20:34:51 +00:00
|
|
|
prefix_set = 0;
|
2017-05-17 13:09:19 +00:00
|
|
|
NETSTACK_MAC.off();
|
2010-05-05 19:44:30 +00:00
|
|
|
|
|
|
|
PROCESS_PAUSE();
|
2011-03-13 15:59:17 +00:00
|
|
|
|
2010-05-05 19:44:30 +00:00
|
|
|
SENSORS_ACTIVATE(button_sensor);
|
|
|
|
|
2017-10-31 22:10:37 +00:00
|
|
|
LOG_INFO("RPL-Border router started\n");
|
2014-10-04 16:05:38 +00:00
|
|
|
|
2010-05-25 20:34:51 +00:00
|
|
|
/* Request prefix until it has been received */
|
|
|
|
while(!prefix_set) {
|
|
|
|
etimer_set(&et, CLOCK_SECOND);
|
|
|
|
request_prefix();
|
|
|
|
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
2017-10-29 03:08:30 +00:00
|
|
|
LOG_INFO("Waiting for prefix\n");
|
2010-05-05 19:44:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-29 23:46:28 +00:00
|
|
|
NETSTACK_MAC.on();
|
|
|
|
|
2011-03-13 15:59:17 +00:00
|
|
|
#if DEBUG || 1
|
2010-05-05 19:44:30 +00:00
|
|
|
print_local_addresses();
|
2011-03-11 20:07:15 +00:00
|
|
|
#endif
|
2010-05-05 19:44:30 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
PROCESS_YIELD();
|
|
|
|
if (ev == sensors_event && data == &button_sensor) {
|
2017-10-29 03:08:30 +00:00
|
|
|
LOG_INFO("Initiating global repair\n");
|
2017-06-10 12:35:39 +00:00
|
|
|
#if UIP_CONF_IPV6_RPL_LITE
|
|
|
|
rpl_global_repair();
|
|
|
|
#else
|
2011-07-11 13:50:51 +00:00
|
|
|
rpl_repair_root(RPL_DEFAULT_INSTANCE);
|
2017-06-10 12:35:39 +00:00
|
|
|
#endif
|
2010-05-05 19:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|