2011-12-19 12:50:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011, Swedish Institute of Computer Science.
|
|
|
|
* 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. 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-net.h"
|
2017-06-10 12:35:39 +00:00
|
|
|
#include "rpl.h"
|
2017-12-19 17:02:21 +00:00
|
|
|
#include "rpl-border-router.h"
|
2011-12-19 12:50:50 +00:00
|
|
|
#include "cmd.h"
|
|
|
|
#include "border-router.h"
|
|
|
|
#include "border-router-cmds.h"
|
|
|
|
|
|
|
|
#define DEBUG DEBUG_FULL
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip-debug.h"
|
2011-12-19 12:50:50 +00:00
|
|
|
|
2017-11-01 15:02:41 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-12-19 12:50:50 +00:00
|
|
|
extern long slip_sent;
|
|
|
|
extern long slip_received;
|
|
|
|
|
|
|
|
static uint8_t mac_set;
|
|
|
|
|
|
|
|
extern int contiki_argc;
|
|
|
|
extern char **contiki_argv;
|
|
|
|
extern const char *slip_config_ipaddr;
|
|
|
|
|
|
|
|
CMD_HANDLERS(border_router_cmd_handler);
|
|
|
|
|
|
|
|
PROCESS(border_router_process, "Border router process");
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
request_mac(void)
|
|
|
|
{
|
|
|
|
write_to_slip((uint8_t *)"?M", 2);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
border_router_set_mac(const uint8_t *data)
|
|
|
|
{
|
|
|
|
memcpy(uip_lladdr.addr, data, sizeof(uip_lladdr.addr));
|
2013-12-12 22:58:52 +00:00
|
|
|
linkaddr_set_node_addr((linkaddr_t *)uip_lladdr.addr);
|
2011-12-19 12:50:50 +00:00
|
|
|
|
|
|
|
/* is this ok - should instead remove all addresses and
|
|
|
|
add them back again - a bit messy... ?*/
|
2017-03-21 12:12:39 +00:00
|
|
|
PROCESS_CONTEXT_BEGIN(&tcpip_process);
|
2011-12-19 12:50:50 +00:00
|
|
|
uip_ds6_init();
|
|
|
|
rpl_init();
|
2017-03-21 12:12:39 +00:00
|
|
|
PROCESS_CONTEXT_END(&tcpip_process);
|
2011-12-19 12:50:50 +00:00
|
|
|
|
|
|
|
mac_set = 1;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
border_router_print_stat()
|
|
|
|
{
|
|
|
|
printf("bytes received over SLIP: %ld\n", slip_received);
|
|
|
|
printf("bytes sent over SLIP: %ld\n", slip_sent);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
PROCESS_THREAD(border_router_process, ev, data)
|
|
|
|
{
|
|
|
|
static struct etimer et;
|
|
|
|
|
|
|
|
PROCESS_BEGIN();
|
|
|
|
prefix_set = 0;
|
|
|
|
|
|
|
|
PROCESS_PAUSE();
|
|
|
|
|
2017-11-01 13:39:28 +00:00
|
|
|
process_start(&border_router_cmd_process, NULL);
|
|
|
|
|
2011-12-19 12:50:50 +00:00
|
|
|
PRINTF("RPL-Border router started\n");
|
|
|
|
|
|
|
|
slip_config_handle_arguments(contiki_argc, contiki_argv);
|
|
|
|
|
|
|
|
/* tun init is also responsible for setting up the SLIP connection */
|
|
|
|
tun_init();
|
|
|
|
|
|
|
|
while(!mac_set) {
|
|
|
|
etimer_set(&et, CLOCK_SECOND);
|
|
|
|
request_mac();
|
|
|
|
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(slip_config_ipaddr != NULL) {
|
|
|
|
uip_ipaddr_t prefix;
|
|
|
|
|
|
|
|
if(uiplib_ipaddrconv((const char *)slip_config_ipaddr, &prefix)) {
|
|
|
|
PRINTF("Setting prefix ");
|
|
|
|
PRINT6ADDR(&prefix);
|
|
|
|
PRINTF("\n");
|
|
|
|
set_prefix_64(&prefix);
|
|
|
|
} else {
|
|
|
|
PRINTF("Parse error: %s\n", slip_config_ipaddr);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print_local_addresses();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
etimer_set(&et, CLOCK_SECOND * 2);
|
|
|
|
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
|
|
|
/* do anything here??? */
|
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|