updated with support for getting prefix from tunslip6 and for setting RPL prefix

This commit is contained in:
joxe 2010-05-25 20:34:51 +00:00
parent 293f08e9c7
commit df104b77a3
2 changed files with 54 additions and 13 deletions

View file

@ -44,6 +44,7 @@
#include "net/netstack.h" #include "net/netstack.h"
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
#include "dev/slip.h"
#include "webserver-nogui.h" #include "webserver-nogui.h"
#include "httpd-simple.h" #include "httpd-simple.h"
#include <stdio.h> #include <stdio.h>
@ -59,6 +60,9 @@ uint16_t dag_id[] = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011};
extern uip_ds6_nbr_t uip_ds6_nbr_cache[]; extern uip_ds6_nbr_t uip_ds6_nbr_cache[];
extern uip_ds6_route_t uip_ds6_routing_table[]; extern uip_ds6_route_t uip_ds6_routing_table[];
static uip_ipaddr_t prefix;
static uint8_t prefix_set;
PROCESS(border_router_process, "Border router process"); PROCESS(border_router_process, "Border router process");
AUTOSTART_PROCESSES(&border_router_process); AUTOSTART_PROCESSES(&border_router_process);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -166,12 +170,32 @@ print_local_addresses(void)
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void
request_prefix(void) {
/* mess up uip_buf with a dirty request... */
uip_buf[0] = '!';
uip_buf[1] = 'P';
uip_len = 2;
slip_send();
}
/*---------------------------------------------------------------------------*/
void
set_prefix_64(uip_ipaddr_t *prefix_64) {
uip_ipaddr_t ipaddr;
memcpy(&prefix, prefix_64, 16);
memcpy(&ipaddr, prefix_64, 16);
prefix_set = 1;
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data) PROCESS_THREAD(border_router_process, ev, data)
{ {
uip_ipaddr_t ipaddr; static struct etimer et;
struct uip_ds6_addr *root_if; rpl_dag_t *dag;
PROCESS_BEGIN(); PROCESS_BEGIN();
prefix_set = 0;
PROCESS_PAUSE(); PROCESS_PAUSE();
@ -181,17 +205,18 @@ PROCESS_THREAD(border_router_process, ev, data)
PRINTF("RPL-Border router started\n"); PRINTF("RPL-Border router started\n");
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); /* Request prefix until it has been received */
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); while(!prefix_set) {
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); etimer_set(&et, CLOCK_SECOND);
root_if = uip_ds6_addr_lookup(&ipaddr); request_prefix();
if(root_if != NULL) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
rpl_set_root((uip_ip6addr_t *)dag_id);
PRINTF("created a new RPL dag\n");
} else {
PRINTF("failed to create a new RPL DAG\n");
} }
rpl_set_root((uip_ip6addr_t *)dag_id);
dag = rpl_get_dag(RPL_ANY_INSTANCE);
rpl_set_prefix(dag, &prefix, 64);
PRINTF("created a new RPL dag\n");
print_local_addresses(); print_local_addresses();
/* The border router runs with a 100% duty cycle in order to ensure high /* The border router runs with a 100% duty cycle in order to ensure high

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: slip-bridge.c,v 1.1 2010/05/05 19:44:30 joxe Exp $ * $Id: slip-bridge.c,v 1.2 2010/05/25 20:34:51 joxe Exp $
*/ */
/** /**
@ -50,13 +50,28 @@
#define DEBUG DEBUG_PRINT #define DEBUG DEBUG_PRINT
#include "net/uip-debug.h" #include "net/uip-debug.h"
void set_prefix_64(uip_ipaddr_t *);
static uip_ipaddr_t last_sender; static uip_ipaddr_t last_sender;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
slip_input_callback(void) slip_input_callback(void)
{ {
PRINTF("SIN: %u\n", uip_len); PRINTF("SIN: %u\n", uip_len);
if(uip_buf[0] == '!') {
PRINTF("Got configuration message of type %c\n", uip_buf[1]);
uip_len = 0;
if(uip_buf[1] == 'P') {
uip_ipaddr_t prefix;
/* Here we set a prefix !!! */
memset(&prefix, 0, 16);
memcpy(&prefix, &uip_buf[2], 8);
PRINTF("Setting prefix ");
PRINT6ADDR(&prefix);
PRINTF("\n");
set_prefix_64(&prefix);
}
}
/* Save the last sender received over SLIP to avoid bouncing the /* Save the last sender received over SLIP to avoid bouncing the
packet back if no route is found */ packet back if no route is found */
uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr); uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr);
@ -82,6 +97,7 @@ output(void)
slip_send(); slip_send();
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
putchar(int c) putchar(int c)