nes-proj/os/services/rpl-border-router/native/border-router-native.c

147 lines
4.3 KiB
C
Raw Normal View History

/*
* 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"
#include "net/routing/routing.h"
#include "rpl-border-router.h"
#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"
#include <stdlib.h>
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));
linkaddr_set_node_addr((linkaddr_t *)uip_lladdr.addr);
/* is this ok - should instead remove all addresses and
add them back again - a bit messy... ?*/
PROCESS_CONTEXT_BEGIN(&tcpip_process);
uip_ds6_init();
NETSTACK_ROUTING.init();
PROCESS_CONTEXT_END(&tcpip_process);
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();
process_start(&border_router_cmd_process, NULL);
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();
}
/*---------------------------------------------------------------------------*/