Merge pull request #146 from simonduq/pr/border-router-common
Move more border router code to common directory
This commit is contained in:
commit
77f4e75acf
@ -15,6 +15,7 @@ endif
|
|||||||
include $(SOURCES_DIR)/Makefile
|
include $(SOURCES_DIR)/Makefile
|
||||||
|
|
||||||
PROJECTDIRS += $(SOURCES_DIR)
|
PROJECTDIRS += $(SOURCES_DIR)
|
||||||
|
PROJECT_SOURCEFILES += httpd-simple.c webserver.c border-router-common.c
|
||||||
CFLAGS += -DPROJECT_CONF_PATH=\"$(SOURCES_DIR)/project-conf.h\"
|
CFLAGS += -DPROJECT_CONF_PATH=\"$(SOURCES_DIR)/project-conf.h\"
|
||||||
|
|
||||||
include $(CONTIKI)/Makefile.include
|
include $(CONTIKI)/Makefile.include
|
||||||
|
69
examples/rpl-border-router/common/border-router-common.c
Normal file
69
examples/rpl-border-router/common/border-router-common.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, RISE SICS
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "border-router-common.h"
|
||||||
|
#include "rpl-dag-root.h"
|
||||||
|
|
||||||
|
/* Log configuration */
|
||||||
|
#include "sys/log.h"
|
||||||
|
#define LOG_MODULE "BR"
|
||||||
|
#define LOG_LEVEL LOG_LEVEL_INFO
|
||||||
|
|
||||||
|
uint8_t prefix_set;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
print_local_addresses(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint8_t state;
|
||||||
|
|
||||||
|
LOG_INFO("Server IPv6 addresses:\n");
|
||||||
|
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||||
|
state = uip_ds6_if.addr_list[i].state;
|
||||||
|
if(uip_ds6_if.addr_list[i].isused &&
|
||||||
|
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
||||||
|
LOG_INFO(" ");
|
||||||
|
LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||||
|
LOG_INFO_("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
set_prefix_64(uip_ipaddr_t *prefix_64)
|
||||||
|
{
|
||||||
|
prefix_set = 1;
|
||||||
|
rpl_dag_root_init(prefix_64, NULL);
|
||||||
|
rpl_dag_root_init_dag_immediately();
|
||||||
|
}
|
40
examples/rpl-border-router/common/border-router-common.h
Normal file
40
examples/rpl-border-router/common/border-router-common.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, RISE SICS
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "net/ipv6/uip.h"
|
||||||
|
#include "net/ipv6/uip-ds6.h"
|
||||||
|
|
||||||
|
extern uint8_t prefix_set;
|
||||||
|
|
||||||
|
void print_local_addresses(void);
|
||||||
|
void set_prefix_64(uip_ipaddr_t *prefix_64);
|
@ -42,8 +42,6 @@
|
|||||||
|
|
||||||
#include "contiki-net.h"
|
#include "contiki-net.h"
|
||||||
|
|
||||||
//#include "urlconv.h"
|
|
||||||
|
|
||||||
#if UIP_CONF_TCP == 0
|
#if UIP_CONF_TCP == 0
|
||||||
#error HTTP server needs TCP enabled
|
#error HTTP server needs TCP enabled
|
||||||
#endif
|
#endif
|
||||||
@ -153,7 +151,7 @@ PT_THREAD(handle_output(struct httpd_state *s))
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
const char http_get[] = "GET ";
|
const char http_get[] = "GET ";
|
||||||
const char http_index_html[] = "/index.html";
|
const char http_index_html[] = "/index.html";
|
||||||
//const char http_referer[] = "Referer:"
|
|
||||||
static
|
static
|
||||||
PT_THREAD(handle_input(struct httpd_state *s))
|
PT_THREAD(handle_input(struct httpd_state *s))
|
||||||
{
|
{
|
||||||
@ -207,7 +205,6 @@ handle_connection(struct httpd_state *s)
|
|||||||
handle_output(s);
|
handle_output(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
httpd_appcall(void *state)
|
httpd_appcall(void *state)
|
||||||
@ -250,7 +247,6 @@ httpd_appcall(void *state)
|
|||||||
uip_abort();
|
uip_abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
httpd_init(void)
|
httpd_init(void)
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
#endif /* WEBSERVER_CONF_CFS_CONNS */
|
#endif /* WEBSERVER_CONF_CFS_CONNS */
|
||||||
|
|
||||||
struct httpd_state;
|
struct httpd_state;
|
||||||
typedef char (* httpd_simple_script_t)(struct httpd_state *s);
|
typedef char (*httpd_simple_script_t)(struct httpd_state *s);
|
||||||
|
|
||||||
struct httpd_state {
|
struct httpd_state {
|
||||||
struct timer timer;
|
struct timer timer;
|
||||||
|
335
examples/rpl-border-router/common/webserver.c
Normal file
335
examples/rpl-border-router/common/webserver.c
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, RISE SICS
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "rpl.h"
|
||||||
|
#if UIP_CONF_IPV6_RPL_LITE == 0
|
||||||
|
#include "rpl-private.h"
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL_LITE == 0 */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const char *TOP = "<html><head><title>Contiki-NG</title></head><body>\n";
|
||||||
|
static const char *BOTTOM = "</body></html>\n";
|
||||||
|
#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];
|
||||||
|
static int blen;
|
||||||
|
#define ADD(...) do { \
|
||||||
|
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
||||||
|
} while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
#include "httpd-simple.h"
|
||||||
|
/* The internal webserver can provide additional information if
|
||||||
|
* enough program flash is available.
|
||||||
|
*/
|
||||||
|
#define WEBSERVER_CONF_LOADTIME 0
|
||||||
|
#define WEBSERVER_CONF_FILESTATS 0
|
||||||
|
#define WEBSERVER_CONF_NEIGHBOR_STATUS 0
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
#define WEBSERVER_CONF_ROUTE_LINKS 0
|
||||||
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
||||||
|
#define BUF_USES_STACK 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
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) {
|
||||||
|
if(f++ == 0) {
|
||||||
|
ADD("::");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(f > 0) {
|
||||||
|
f = -1;
|
||||||
|
} else if(i > 0) {
|
||||||
|
ADD(":");
|
||||||
|
}
|
||||||
|
ADD("%x", a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static
|
||||||
|
PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
|
{
|
||||||
|
static uip_ds6_route_t *r;
|
||||||
|
#if RPL_WITH_NON_STORING
|
||||||
|
static rpl_ns_node_t *link;
|
||||||
|
#endif /* RPL_WITH_NON_STORING */
|
||||||
|
static uip_ds6_nbr_t *nbr;
|
||||||
|
#if BUF_USES_STACK
|
||||||
|
char buf[256];
|
||||||
|
#endif
|
||||||
|
#if WEBSERVER_CONF_LOADTIME
|
||||||
|
static clock_time_t numticks;
|
||||||
|
numticks = clock_time();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PSOCK_BEGIN(&s->sout);
|
||||||
|
|
||||||
|
SEND_STRING(&s->sout, TOP);
|
||||||
|
#if BUF_USES_STACK
|
||||||
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
|
#else
|
||||||
|
blen = 0;
|
||||||
|
#endif
|
||||||
|
ADD("Neighbors<pre>");
|
||||||
|
|
||||||
|
for(nbr = nbr_table_head(ds6_neighbors);
|
||||||
|
nbr != NULL;
|
||||||
|
nbr = nbr_table_next(ds6_neighbors, nbr)) {
|
||||||
|
|
||||||
|
#if WEBSERVER_CONF_NEIGHBOR_STATUS
|
||||||
|
#if BUF_USES_STACK
|
||||||
|
{ char *j = bufptr + 25;
|
||||||
|
ipaddr_add(&nbr->ipaddr);
|
||||||
|
while(bufptr < j) ADD(" ");
|
||||||
|
switch(nbr->state) {
|
||||||
|
case NBR_INCOMPLETE: ADD(" INCOMPLETE");
|
||||||
|
break;
|
||||||
|
case NBR_REACHABLE: ADD(" REACHABLE");
|
||||||
|
break;
|
||||||
|
case NBR_STALE: ADD(" STALE");
|
||||||
|
break;
|
||||||
|
case NBR_DELAY: ADD(" DELAY");
|
||||||
|
break;
|
||||||
|
case NBR_PROBE: ADD(" NBR_PROBE");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{ uint8_t j = blen + 25;
|
||||||
|
ipaddr_add(&nbr->ipaddr);
|
||||||
|
while(blen < j) ADD(" ");
|
||||||
|
switch(nbr->state) {
|
||||||
|
case NBR_INCOMPLETE: ADD(" INCOMPLETE");
|
||||||
|
break;
|
||||||
|
case NBR_REACHABLE: ADD(" REACHABLE");
|
||||||
|
break;
|
||||||
|
case NBR_STALE: ADD(" STALE");
|
||||||
|
break;
|
||||||
|
case NBR_DELAY: ADD(" DELAY");
|
||||||
|
break;
|
||||||
|
case NBR_PROBE: ADD(" NBR_PROBE");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
ipaddr_add(&nbr->ipaddr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ADD("\n");
|
||||||
|
#if BUF_USES_STACK
|
||||||
|
if(bufptr > bufend - 45) {
|
||||||
|
SEND_STRING(&s->sout, buf);
|
||||||
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if(blen > sizeof(buf) - 45) {
|
||||||
|
SEND_STRING(&s->sout, buf);
|
||||||
|
blen = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
ADD("</pre>Routes<pre>\n");
|
||||||
|
SEND_STRING(&s->sout, buf);
|
||||||
|
#if BUF_USES_STACK
|
||||||
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
|
#else
|
||||||
|
blen = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
|
||||||
|
|
||||||
|
#if BUF_USES_STACK
|
||||||
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
||||||
|
ADD("<a href=http://[");
|
||||||
|
ipaddr_add(&r->ipaddr);
|
||||||
|
ADD("]/status.shtml>");
|
||||||
|
ipaddr_add(&r->ipaddr);
|
||||||
|
ADD("</a>");
|
||||||
|
#else
|
||||||
|
ipaddr_add(&r->ipaddr);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if WEBSERVER_CONF_ROUTE_LINKS
|
||||||
|
ADD("<a href=http://[");
|
||||||
|
ipaddr_add(&r->ipaddr);
|
||||||
|
ADD("]/status.shtml>");
|
||||||
|
SEND_STRING(&s->sout, buf);
|
||||||
|
blen = 0;
|
||||||
|
ipaddr_add(&r->ipaddr);
|
||||||
|
ADD("</a>");
|
||||||
|
#else
|
||||||
|
ipaddr_add(&r->ipaddr);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
ADD("/%u (via ", r->length);
|
||||||
|
ipaddr_add(uip_ds6_route_nexthop(r));
|
||||||
|
if(1 || (r->state.lifetime < 600)) {
|
||||||
|
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>");
|
||||||
|
|
||||||
|
#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);
|
||||||
|
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);
|
||||||
|
} 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 */
|
||||||
|
|
||||||
|
#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);
|
||||||
|
SEND_STRING(&s->sout, BOTTOM);
|
||||||
|
|
||||||
|
PSOCK_END(&s->sout);
|
||||||
|
}
|
||||||
|
#if BORDER_ROUTER_CONF_WEBSERVER
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
httpd_simple_script_t
|
||||||
|
httpd_simple_get_script(const char *name)
|
||||||
|
{
|
||||||
|
return generate_routes;
|
||||||
|
}
|
||||||
|
#endif /* BORDER_ROUTER_CONF_WEBSERVER */
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
PROJECTDIRS += $(SOURCES_DIR)/$(TARGET)
|
PROJECTDIRS += $(SOURCES_DIR)/$(TARGET)
|
||||||
|
|
||||||
PROJECT_SOURCEFILES += slip-bridge.c httpd-simple.c border-router-embedded.c
|
PROJECT_SOURCEFILES += slip-bridge.c border-router-embedded.c
|
||||||
|
|
||||||
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
||||||
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
||||||
|
@ -36,353 +36,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "contiki-lib.h"
|
|
||||||
#include "contiki-net.h"
|
|
||||||
#include "net/ipv6/uip.h"
|
|
||||||
#include "net/ipv6/uip-ds6.h"
|
|
||||||
#include "rpl.h"
|
#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"
|
|
||||||
#if RPL_WITH_NON_STORING
|
|
||||||
#include "rpl-ns.h"
|
|
||||||
#endif /* RPL_WITH_NON_STORING */
|
|
||||||
#include "net/netstack.h"
|
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
#include "dev/slip.h"
|
#include "dev/slip.h"
|
||||||
#include "net/ipv6/uip-debug.h"
|
#include "border-router-common.h"
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Log configuration */
|
/* Log configuration */
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
#define LOG_MODULE "BR"
|
#define LOG_MODULE "BR"
|
||||||
#define LOG_LEVEL LOG_LEVEL_INFO
|
#define LOG_LEVEL LOG_LEVEL_INFO
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static uip_ipaddr_t prefix;
|
void request_prefix(void);
|
||||||
static uint8_t prefix_set;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
PROCESS(border_router_process, "Border router process");
|
PROCESS(border_router_process, "Border router process");
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#if BORDER_ROUTER_CONF_WEBSERVER
|
|
||||||
/* 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.
|
|
||||||
*/
|
|
||||||
#include "httpd-simple.h"
|
|
||||||
/* The internal webserver can provide additional information if
|
|
||||||
* enough program flash is available.
|
|
||||||
*/
|
|
||||||
#define WEBSERVER_CONF_LOADTIME 0
|
|
||||||
#define WEBSERVER_CONF_FILESTATS 0
|
|
||||||
#define WEBSERVER_CONF_NEIGHBOR_STATUS 0
|
|
||||||
/* 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.
|
|
||||||
*/
|
|
||||||
#define WEBSERVER_CONF_ROUTE_LINKS 0
|
|
||||||
#if WEBSERVER_CONF_ROUTE_LINKS
|
|
||||||
#define BUF_USES_STACK 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
PROCESS_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *TOP = "<html><head><title>ContikiRPL</title></head><body>\n";
|
|
||||||
static const char *BOTTOM = "</body></html>\n";
|
|
||||||
#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];
|
|
||||||
static int blen;
|
|
||||||
#define ADD(...) do { \
|
|
||||||
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
|
||||||
} while(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
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) {
|
|
||||||
if(f++ == 0) ADD("::");
|
|
||||||
} else {
|
|
||||||
if(f > 0) {
|
|
||||||
f = -1;
|
|
||||||
} else if(i > 0) {
|
|
||||||
ADD(":");
|
|
||||||
}
|
|
||||||
ADD("%x", a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static
|
|
||||||
PT_THREAD(generate_routes(struct httpd_state *s))
|
|
||||||
{
|
|
||||||
static uip_ds6_route_t *r;
|
|
||||||
#if RPL_WITH_NON_STORING
|
|
||||||
static rpl_ns_node_t *link;
|
|
||||||
#endif /* RPL_WITH_NON_STORING */
|
|
||||||
static uip_ds6_nbr_t *nbr;
|
|
||||||
#if BUF_USES_STACK
|
|
||||||
char buf[256];
|
|
||||||
#endif
|
|
||||||
#if WEBSERVER_CONF_LOADTIME
|
|
||||||
static clock_time_t numticks;
|
|
||||||
numticks = clock_time();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PSOCK_BEGIN(&s->sout);
|
|
||||||
|
|
||||||
SEND_STRING(&s->sout, TOP);
|
|
||||||
#if BUF_USES_STACK
|
|
||||||
bufptr = buf;bufend=bufptr+sizeof(buf);
|
|
||||||
#else
|
|
||||||
blen = 0;
|
|
||||||
#endif
|
|
||||||
ADD("Neighbors<pre>");
|
|
||||||
|
|
||||||
for(nbr = nbr_table_head(ds6_neighbors);
|
|
||||||
nbr != NULL;
|
|
||||||
nbr = nbr_table_next(ds6_neighbors, nbr)) {
|
|
||||||
|
|
||||||
#if WEBSERVER_CONF_NEIGHBOR_STATUS
|
|
||||||
#if BUF_USES_STACK
|
|
||||||
{char* j=bufptr+25;
|
|
||||||
ipaddr_add(&nbr->ipaddr);
|
|
||||||
while (bufptr < j) ADD(" ");
|
|
||||||
switch (nbr->state) {
|
|
||||||
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
|
|
||||||
case NBR_REACHABLE: ADD(" REACHABLE");break;
|
|
||||||
case NBR_STALE: ADD(" STALE");break;
|
|
||||||
case NBR_DELAY: ADD(" DELAY");break;
|
|
||||||
case NBR_PROBE: ADD(" NBR_PROBE");break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{uint8_t j=blen+25;
|
|
||||||
ipaddr_add(&nbr->ipaddr);
|
|
||||||
while (blen < j) ADD(" ");
|
|
||||||
switch (nbr->state) {
|
|
||||||
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
|
|
||||||
case NBR_REACHABLE: ADD(" REACHABLE");break;
|
|
||||||
case NBR_STALE: ADD(" STALE");break;
|
|
||||||
case NBR_DELAY: ADD(" DELAY");break;
|
|
||||||
case NBR_PROBE: ADD(" NBR_PROBE");break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
ipaddr_add(&nbr->ipaddr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ADD("\n");
|
|
||||||
#if BUF_USES_STACK
|
|
||||||
if(bufptr > bufend - 45) {
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if(blen > sizeof(buf) - 45) {
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
blen = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
ADD("</pre>Routes<pre>\n");
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
#if BUF_USES_STACK
|
|
||||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
|
||||||
#else
|
|
||||||
blen = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
|
|
||||||
|
|
||||||
#if BUF_USES_STACK
|
|
||||||
#if WEBSERVER_CONF_ROUTE_LINKS
|
|
||||||
ADD("<a href=http://[");
|
|
||||||
ipaddr_add(&r->ipaddr);
|
|
||||||
ADD("]/status.shtml>");
|
|
||||||
ipaddr_add(&r->ipaddr);
|
|
||||||
ADD("</a>");
|
|
||||||
#else
|
|
||||||
ipaddr_add(&r->ipaddr);
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if WEBSERVER_CONF_ROUTE_LINKS
|
|
||||||
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>");
|
|
||||||
#else
|
|
||||||
ipaddr_add(&r->ipaddr);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
ADD("/%u (via ", r->length);
|
|
||||||
ipaddr_add(uip_ds6_route_nexthop(r));
|
|
||||||
if(1 || (r->state.lifetime < 600)) {
|
|
||||||
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>");
|
|
||||||
|
|
||||||
#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 */
|
|
||||||
|
|
||||||
#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);
|
|
||||||
SEND_STRING(&s->sout, BOTTOM);
|
|
||||||
|
|
||||||
PSOCK_END(&s->sout);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
httpd_simple_script_t
|
|
||||||
httpd_simple_get_script(const char *name)
|
|
||||||
{
|
|
||||||
return generate_routes;
|
|
||||||
}
|
|
||||||
#endif /* BORDER_ROUTER_CONF_WEBSERVER */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
print_local_addresses(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint8_t state;
|
|
||||||
|
|
||||||
LOG_INFO("Server IPv6 addresses:\n");
|
|
||||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
|
||||||
state = uip_ds6_if.addr_list[i].state;
|
|
||||||
if(uip_ds6_if.addr_list[i].isused &&
|
|
||||||
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
|
||||||
LOG_INFO(" ");
|
|
||||||
LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
|
||||||
LOG_INFO_("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void
|
|
||||||
request_prefix(void)
|
|
||||||
{
|
|
||||||
/* mess up uip_buf with a dirty request... */
|
|
||||||
uip_buf[0] = '?';
|
|
||||||
uip_buf[1] = 'P';
|
|
||||||
uip_len = 2;
|
|
||||||
slip_send();
|
|
||||||
uip_clear_buf();
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void
|
|
||||||
set_prefix_64(uip_ipaddr_t *prefix_64)
|
|
||||||
{
|
|
||||||
memcpy(&prefix, prefix_64, 16);
|
|
||||||
prefix_set = 1;
|
|
||||||
rpl_dag_root_init(prefix_64, NULL);
|
|
||||||
rpl_dag_root_init_dag_immediately();
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
PROCESS_THREAD(border_router_process, ev, data)
|
PROCESS_THREAD(border_router_process, ev, data)
|
||||||
{
|
{
|
||||||
static struct etimer et;
|
static struct etimer et;
|
||||||
@ -413,13 +82,11 @@ PROCESS_THREAD(border_router_process, ev, data)
|
|||||||
|
|
||||||
NETSTACK_MAC.on();
|
NETSTACK_MAC.on();
|
||||||
|
|
||||||
#if DEBUG || 1
|
|
||||||
print_local_addresses();
|
print_local_addresses();
|
||||||
#endif
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_YIELD();
|
PROCESS_YIELD();
|
||||||
if (ev == sensors_event && data == &button_sensor) {
|
if(ev == sensors_event && data == &button_sensor) {
|
||||||
LOG_INFO("Initiating global repair\n");
|
LOG_INFO("Initiating global repair\n");
|
||||||
#if UIP_CONF_IPV6_RPL_LITE
|
#if UIP_CONF_IPV6_RPL_LITE
|
||||||
rpl_global_repair();
|
rpl_global_repair();
|
||||||
|
@ -53,6 +53,18 @@
|
|||||||
void set_prefix_64(uip_ipaddr_t *);
|
void set_prefix_64(uip_ipaddr_t *);
|
||||||
|
|
||||||
static uip_ipaddr_t last_sender;
|
static uip_ipaddr_t last_sender;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
request_prefix(void)
|
||||||
|
{
|
||||||
|
/* mess up uip_buf with a dirty request... */
|
||||||
|
uip_buf[0] = '?';
|
||||||
|
uip_buf[1] = 'P';
|
||||||
|
uip_len = 2;
|
||||||
|
slip_send();
|
||||||
|
uip_clear_buf();
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
slip_input_callback(void)
|
slip_input_callback(void)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
MODULES += os/services/slip-cmd
|
MODULES += os/services/slip-cmd
|
||||||
|
|
||||||
PROJECT_SOURCEFILES += border-router-native.c
|
PROJECT_SOURCEFILES += border-router-native.c
|
||||||
PROJECT_SOURCEFILES += border-router-cmds.c tun-bridge.c httpd-simple.c
|
PROJECT_SOURCEFILES += border-router-cmds.c tun-bridge.c
|
||||||
PROJECT_SOURCEFILES += slip-config.c slip-dev.c border-router-mac.c
|
PROJECT_SOURCEFILES += slip-config.c slip-dev.c border-router-mac.c
|
||||||
|
|
||||||
MAKE_MAC = MAKE_MAC_OTHER
|
MAKE_MAC = MAKE_MAC_OTHER
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
#define DEBUG DEBUG_NONE
|
#define DEBUG DEBUG_NONE
|
||||||
#include "net/ipv6/uip-debug.h"
|
#include "net/ipv6/uip-debug.h"
|
||||||
|
|
||||||
|
|
||||||
uint8_t command_context;
|
uint8_t command_context;
|
||||||
|
|
||||||
void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx);
|
void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx);
|
||||||
@ -86,7 +85,7 @@ border_router_cmd_handler(const uint8_t *data, int len)
|
|||||||
} else if(data[1] == 'R' && command_context == CMD_CONTEXT_RADIO) {
|
} else if(data[1] == 'R' && command_context == CMD_CONTEXT_RADIO) {
|
||||||
/* We need to know that this is from the slip-radio here. */
|
/* We need to know that this is from the slip-radio here. */
|
||||||
PRINTF("Packet data report for sid:%d st:%d tx:%d\n",
|
PRINTF("Packet data report for sid:%d st:%d tx:%d\n",
|
||||||
data[2], data[3], data[4]);
|
data[2], data[3], data[4]);
|
||||||
packet_sent(data[2], data[3], data[4]);
|
packet_sent(data[2], data[3], data[4]);
|
||||||
return 1;
|
return 1;
|
||||||
} else if(data[1] == 'D' && command_context == CMD_CONTEXT_RADIO) {
|
} else if(data[1] == 'D' && command_context == CMD_CONTEXT_RADIO) {
|
||||||
@ -99,7 +98,7 @@ border_router_cmd_handler(const uint8_t *data, int len)
|
|||||||
PRINTF("Got request message of type %c\n", data[1]);
|
PRINTF("Got request message of type %c\n", data[1]);
|
||||||
if(data[1] == 'M' && command_context == CMD_CONTEXT_STDIO) {
|
if(data[1] == 'M' && command_context == CMD_CONTEXT_STDIO) {
|
||||||
uint8_t buf[20];
|
uint8_t buf[20];
|
||||||
char* hexchar = "0123456789abcdef";
|
char *hexchar = "0123456789abcdef";
|
||||||
int j;
|
int j;
|
||||||
/* this is just a test so far... just to see if it works */
|
/* this is just a test so far... just to see if it works */
|
||||||
buf[0] = '!';
|
buf[0] = '!';
|
||||||
@ -141,7 +140,7 @@ PROCESS_THREAD(border_router_cmd_process, ev, data)
|
|||||||
PROCESS_YIELD();
|
PROCESS_YIELD();
|
||||||
if(ev == serial_line_event_message && data != NULL) {
|
if(ev == serial_line_event_message && data != NULL) {
|
||||||
PRINTF("Got serial data!!! %s of len: %d\n",
|
PRINTF("Got serial data!!! %s of len: %d\n",
|
||||||
(char *)data, strlen((char *)data));
|
(char *)data, strlen((char *)data));
|
||||||
command_context = CMD_CONTEXT_STDIO;
|
command_context = CMD_CONTEXT_STDIO;
|
||||||
cmd_input(data, strlen((char *)data));
|
cmd_input(data, strlen((char *)data));
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@ struct tx_callback {
|
|||||||
|
|
||||||
static struct tx_callback callbacks[MAX_CALLBACKS];
|
static struct tx_callback callbacks[MAX_CALLBACKS];
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
|
void
|
||||||
|
packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
|
||||||
{
|
{
|
||||||
if(sessionid < MAX_CALLBACKS) {
|
if(sessionid < MAX_CALLBACKS) {
|
||||||
struct tx_callback *callback;
|
struct tx_callback *callback;
|
||||||
@ -114,7 +115,6 @@ send_packet(mac_callback_t sent, void *ptr)
|
|||||||
/* Failed to allocate space for headers */
|
/* Failed to allocate space for headers */
|
||||||
PRINTF("br-rdc: send failed, too large header\n");
|
PRINTF("br-rdc: send failed, too large header\n");
|
||||||
mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
|
mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* here we send the data over SLIP to the radio-chip */
|
/* here we send the data over SLIP to the radio-chip */
|
||||||
size = 0;
|
size = 0;
|
||||||
|
@ -39,34 +39,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "contiki-lib.h"
|
|
||||||
#include "contiki-net.h"
|
#include "contiki-net.h"
|
||||||
#include "net/ipv6/uip.h"
|
|
||||||
#include "net/ipv6/uip-ds6.h"
|
|
||||||
#include "rpl.h"
|
#include "rpl.h"
|
||||||
#include "rpl-dag-root.h"
|
#include "border-router-common.h"
|
||||||
|
|
||||||
#include "net/netstack.h"
|
|
||||||
#include "dev/slip.h"
|
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
#include "border-router.h"
|
#include "border-router.h"
|
||||||
#include "border-router-cmds.h"
|
#include "border-router-cmds.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#define DEBUG DEBUG_FULL
|
#define DEBUG DEBUG_FULL
|
||||||
#include "net/ipv6/uip-debug.h"
|
#include "net/ipv6/uip-debug.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define MAX_SENSORS 4
|
#define MAX_SENSORS 4
|
||||||
|
|
||||||
extern long slip_sent;
|
extern long slip_sent;
|
||||||
extern long slip_received;
|
extern long slip_received;
|
||||||
|
|
||||||
static uip_ipaddr_t prefix;
|
|
||||||
static uint8_t prefix_set;
|
|
||||||
static uint8_t mac_set;
|
static uint8_t mac_set;
|
||||||
|
|
||||||
static uint8_t sensor_count = 0;
|
static uint8_t sensor_count = 0;
|
||||||
@ -82,145 +71,6 @@ CMD_HANDLERS(border_router_cmd_handler);
|
|||||||
|
|
||||||
PROCESS(border_router_process, "Border router process");
|
PROCESS(border_router_process, "Border router process");
|
||||||
|
|
||||||
#if BORDER_ROUTER_CONF_WEBSERVER
|
|
||||||
/* Use simple webserver with only one page */
|
|
||||||
#include "httpd-simple.h"
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
PROCESS_END();
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *TOP = "<html><head><title>ContikiRPL</title></head><body>\n";
|
|
||||||
static const char *BOTTOM = "</body></html>\n";
|
|
||||||
static char buf[128];
|
|
||||||
static int blen;
|
|
||||||
#define ADD(...) do { \
|
|
||||||
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
|
||||||
} while(0)
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
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) {
|
|
||||||
if(f++ == 0 && sizeof(buf) - blen >= 2) {
|
|
||||||
buf[blen++] = ':';
|
|
||||||
buf[blen++] = ':';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(f > 0) {
|
|
||||||
f = -1;
|
|
||||||
} else if(i > 0 && blen < sizeof(buf)) {
|
|
||||||
buf[blen++] = ':';
|
|
||||||
}
|
|
||||||
ADD("%x", a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static
|
|
||||||
PT_THREAD(generate_routes(struct httpd_state *s))
|
|
||||||
{
|
|
||||||
static int i;
|
|
||||||
static uip_ds6_route_t *r;
|
|
||||||
static uip_ds6_nbr_t *nbr;
|
|
||||||
|
|
||||||
PSOCK_BEGIN(&s->sout);
|
|
||||||
|
|
||||||
SEND_STRING(&s->sout, TOP);
|
|
||||||
|
|
||||||
blen = 0;
|
|
||||||
ADD("Neighbors<pre>");
|
|
||||||
for(nbr = nbr_table_head(ds6_neighbors);
|
|
||||||
nbr != NULL;
|
|
||||||
nbr = nbr_table_next(ds6_neighbors, nbr)) {
|
|
||||||
ipaddr_add(&nbr->ipaddr);
|
|
||||||
ADD("\n");
|
|
||||||
if(blen > sizeof(buf) - 45) {
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
blen = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ADD("</pre>Routes<pre>");
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
blen = 0;
|
|
||||||
for(r = uip_ds6_route_head();
|
|
||||||
r != NULL;
|
|
||||||
r = uip_ds6_route_next(r)) {
|
|
||||||
ipaddr_add(&r->ipaddr);
|
|
||||||
ADD("/%u (via ", r->length);
|
|
||||||
ipaddr_add(uip_ds6_route_nexthop(r));
|
|
||||||
if(r->state.lifetime < 600) {
|
|
||||||
ADD(") %lus\n", (unsigned long)r->state.lifetime);
|
|
||||||
} else {
|
|
||||||
ADD(")\n");
|
|
||||||
}
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
blen = 0;
|
|
||||||
}
|
|
||||||
ADD("</pre>");
|
|
||||||
//if(blen > 0) {
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
// blen = 0;
|
|
||||||
//}
|
|
||||||
|
|
||||||
if(sensor_count > 0) {
|
|
||||||
ADD("</pre>Sensors<pre>");
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
blen = 0;
|
|
||||||
for(i = 0; i < sensor_count; i++) {
|
|
||||||
ADD("%s\n", sensors[i]);
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
blen = 0;
|
|
||||||
}
|
|
||||||
ADD("</pre>");
|
|
||||||
SEND_STRING(&s->sout, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SEND_STRING(&s->sout, BOTTOM);
|
|
||||||
|
|
||||||
PSOCK_END(&s->sout);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
httpd_simple_script_t
|
|
||||||
httpd_simple_get_script(const char *name)
|
|
||||||
{
|
|
||||||
return generate_routes;
|
|
||||||
}
|
|
||||||
#endif /* BORDER_ROUTER_CONF_WEBSERVER */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
print_local_addresses(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint8_t state;
|
|
||||||
|
|
||||||
PRINTA("Server IPv6 addresses:\n");
|
|
||||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
|
||||||
state = uip_ds6_if.addr_list[i].state;
|
|
||||||
if(uip_ds6_if.addr_list[i].isused &&
|
|
||||||
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
|
||||||
PRINTA(" %p: =>", &uip_ds6_if.addr_list[i]);
|
|
||||||
uip_debug_ipaddr_print(&(uip_ds6_if.addr_list[i]).ipaddr);
|
|
||||||
PRINTA("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
request_mac(void)
|
request_mac(void)
|
||||||
@ -250,7 +100,6 @@ border_router_print_stat()
|
|||||||
printf("bytes received over SLIP: %ld\n", slip_received);
|
printf("bytes received over SLIP: %ld\n", slip_received);
|
||||||
printf("bytes sent over SLIP: %ld\n", slip_sent);
|
printf("bytes sent over SLIP: %ld\n", slip_sent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Format: <name=value>;<name=value>;...;<name=value>*/
|
/* Format: <name=value>;<name=value>;...;<name=value>*/
|
||||||
/* this function just cut at ; and store in the sensor array */
|
/* this function just cut at ; and store in the sensor array */
|
||||||
@ -260,7 +109,7 @@ border_router_set_sensors(const char *data, int len)
|
|||||||
int i;
|
int i;
|
||||||
int last_pos = 0;
|
int last_pos = 0;
|
||||||
int sc = 0;
|
int sc = 0;
|
||||||
for(i = 0;i < len; i++) {
|
for(i = 0; i < len; i++) {
|
||||||
if(data[i] == ';') {
|
if(data[i] == ';') {
|
||||||
sensors[sc][i - last_pos] = 0;
|
sensors[sc][i - last_pos] = 0;
|
||||||
memcpy(sensors[sc++], &data[last_pos], i - last_pos);
|
memcpy(sensors[sc++], &data[last_pos], i - last_pos);
|
||||||
@ -276,15 +125,6 @@ border_router_set_sensors(const char *data, int len)
|
|||||||
sensor_count = sc;
|
sensor_count = sc;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
|
||||||
set_prefix_64(uip_ipaddr_t *prefix_64)
|
|
||||||
{
|
|
||||||
memcpy(&prefix, prefix_64, 16);
|
|
||||||
prefix_set = 1;
|
|
||||||
rpl_dag_root_init(prefix_64, NULL);
|
|
||||||
rpl_dag_root_init_dag_immediately();
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
PROCESS_THREAD(border_router_process, ev, data)
|
PROCESS_THREAD(border_router_process, ev, data)
|
||||||
{
|
{
|
||||||
static struct etimer et;
|
static struct etimer et;
|
||||||
@ -323,9 +163,7 @@ PROCESS_THREAD(border_router_process, ev, data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
print_local_addresses();
|
print_local_addresses();
|
||||||
#endif
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
etimer_set(&et, CLOCK_SECOND * 2);
|
etimer_set(&et, CLOCK_SECOND * 2);
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
/* use a non-default MAC driver */
|
/* use a non-default MAC driver */
|
||||||
#define NETSTACK_CONF_MAC border_router_mac_driver
|
#define NETSTACK_CONF_MAC border_router_mac_driver
|
||||||
|
|
||||||
|
|
||||||
#define SLIP_DEV_CONF_SEND_DELAY (CLOCK_SECOND / 32)
|
#define SLIP_DEV_CONF_SEND_DELAY (CLOCK_SECOND / 32)
|
||||||
|
|
||||||
#define WEBSERVER_CONF_CFS_CONNS 2
|
#define WEBSERVER_CONF_CFS_CONNS 2
|
||||||
@ -50,7 +49,6 @@
|
|||||||
|
|
||||||
#define CMD_CONF_OUTPUT border_router_cmd_output
|
#define CMD_CONF_OUTPUT border_router_cmd_output
|
||||||
|
|
||||||
|
|
||||||
/* used by wpcap (see /cpu/native/net/wpcap-drv.c) */
|
/* used by wpcap (see /cpu/native/net/wpcap-drv.c) */
|
||||||
#define SELECT_CALLBACK 1
|
#define SELECT_CALLBACK 1
|
||||||
|
|
||||||
|
@ -89,17 +89,17 @@ slip_config_handle_arguments(int argc, char **argv)
|
|||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if(strncmp("/dev/", optarg, 5) == 0) {
|
if(strncmp("/dev/", optarg, 5) == 0) {
|
||||||
slip_config_siodev = optarg + 5;
|
slip_config_siodev = optarg + 5;
|
||||||
} else {
|
} else {
|
||||||
slip_config_siodev = optarg;
|
slip_config_siodev = optarg;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
if(strncmp("/dev/", optarg, 5) == 0) {
|
if(strncmp("/dev/", optarg, 5) == 0) {
|
||||||
strncpy(slip_config_tundev, optarg + 5, sizeof(slip_config_tundev));
|
strncpy(slip_config_tundev, optarg + 5, sizeof(slip_config_tundev));
|
||||||
} else {
|
} else {
|
||||||
strncpy(slip_config_tundev, optarg, sizeof(slip_config_tundev));
|
strncpy(slip_config_tundev, optarg, sizeof(slip_config_tundev));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -113,43 +113,47 @@ slip_config_handle_arguments(int argc, char **argv)
|
|||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
slip_config_basedelay = 10;
|
slip_config_basedelay = 10;
|
||||||
if(optarg) slip_config_basedelay = atoi(optarg);
|
if(optarg) {
|
||||||
|
slip_config_basedelay = atoi(optarg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
slip_config_verbose = 2;
|
slip_config_verbose = 2;
|
||||||
if(optarg) slip_config_verbose = atoi(optarg);
|
if(optarg) {
|
||||||
|
slip_config_verbose = atoi(optarg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,"usage: %s [options] ipaddress\n", prog);
|
fprintf(stderr, "usage: %s [options] ipaddress\n", prog);
|
||||||
fprintf(stderr,"example: border-router.native -L -v2 -s ttyUSB1 fd00::1/64\n");
|
fprintf(stderr, "example: border-router.native -L -v2 -s ttyUSB1 fd00::1/64\n");
|
||||||
fprintf(stderr,"Options are:\n");
|
fprintf(stderr, "Options are:\n");
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
fprintf(stderr," -B baudrate 9600,19200,38400,57600,115200,921600 (default 115200)\n");
|
fprintf(stderr, " -B baudrate 9600,19200,38400,57600,115200,921600 (default 115200)\n");
|
||||||
#else
|
#else
|
||||||
fprintf(stderr," -B baudrate 9600,19200,38400,57600,115200 (default 115200)\n");
|
fprintf(stderr, " -B baudrate 9600,19200,38400,57600,115200 (default 115200)\n");
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr," -H Hardware CTS/RTS flow control (default disabled)\n");
|
fprintf(stderr, " -H Hardware CTS/RTS flow control (default disabled)\n");
|
||||||
fprintf(stderr," -L Log output format (adds time stamps)\n");
|
fprintf(stderr, " -L Log output format (adds time stamps)\n");
|
||||||
fprintf(stderr," -s siodev Serial device (default /dev/ttyUSB0)\n");
|
fprintf(stderr, " -s siodev Serial device (default /dev/ttyUSB0)\n");
|
||||||
fprintf(stderr," -a host Connect via TCP to server at <host>\n");
|
fprintf(stderr, " -a host Connect via TCP to server at <host>\n");
|
||||||
fprintf(stderr," -p port Connect via TCP to server at <host>:<port>\n");
|
fprintf(stderr, " -p port Connect via TCP to server at <host>:<port>\n");
|
||||||
fprintf(stderr," -t tundev Name of interface (default tun0)\n");
|
fprintf(stderr, " -t tundev Name of interface (default tun0)\n");
|
||||||
fprintf(stderr," -v[level] Verbosity level\n");
|
fprintf(stderr, " -v[level] Verbosity level\n");
|
||||||
fprintf(stderr," -v0 No messages\n");
|
fprintf(stderr, " -v0 No messages\n");
|
||||||
fprintf(stderr," -v1 Encapsulated SLIP debug messages (default)\n");
|
fprintf(stderr, " -v1 Encapsulated SLIP debug messages (default)\n");
|
||||||
fprintf(stderr," -v2 Printable strings after they are received\n");
|
fprintf(stderr, " -v2 Printable strings after they are received\n");
|
||||||
fprintf(stderr," -v3 Printable strings and SLIP packet notifications\n");
|
fprintf(stderr, " -v3 Printable strings and SLIP packet notifications\n");
|
||||||
fprintf(stderr," -v4 All printable characters as they are received\n");
|
fprintf(stderr, " -v4 All printable characters as they are received\n");
|
||||||
fprintf(stderr," -v5 All SLIP packets in hex\n");
|
fprintf(stderr, " -v5 All SLIP packets in hex\n");
|
||||||
fprintf(stderr," -v Equivalent to -v3\n");
|
fprintf(stderr, " -v Equivalent to -v3\n");
|
||||||
fprintf(stderr," -d[basedelay] Minimum delay between outgoing SLIP packets.\n");
|
fprintf(stderr, " -d[basedelay] Minimum delay between outgoing SLIP packets.\n");
|
||||||
fprintf(stderr," Actual delay is basedelay*(#6LowPAN fragments) milliseconds.\n");
|
fprintf(stderr, " Actual delay is basedelay*(#6LowPAN fragments) milliseconds.\n");
|
||||||
fprintf(stderr," -d is equivalent to -d10.\n");
|
fprintf(stderr, " -d is equivalent to -d10.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,6 @@ long slip_received = 0;
|
|||||||
|
|
||||||
int slipfd = 0;
|
int slipfd = 0;
|
||||||
|
|
||||||
//#define PROGRESS(s) fprintf(stderr, s)
|
|
||||||
#define PROGRESS(s) do { } while(0)
|
#define PROGRESS(s) do { } while(0)
|
||||||
|
|
||||||
#define SLIP_END 0300
|
#define SLIP_END 0300
|
||||||
@ -93,9 +92,9 @@ static void *
|
|||||||
get_in_addr(struct sockaddr *sa)
|
get_in_addr(struct sockaddr *sa)
|
||||||
{
|
{
|
||||||
if(sa->sa_family == AF_INET) {
|
if(sa->sa_family == AF_INET) {
|
||||||
return &(((struct sockaddr_in*)sa)->sin_addr);
|
return &(((struct sockaddr_in *)sa)->sin_addr);
|
||||||
}
|
}
|
||||||
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
return &(((struct sockaddr_in6 *)sa)->sin6_addr);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
@ -138,7 +137,7 @@ connect_to_server(const char *host, const char *port)
|
|||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||||
|
|
||||||
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
|
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
|
||||||
s, sizeof(s));
|
s, sizeof(s));
|
||||||
|
|
||||||
/* all done with this structure */
|
/* all done with this structure */
|
||||||
freeaddrinfo(servinfo);
|
freeaddrinfo(servinfo);
|
||||||
@ -178,23 +177,25 @@ serial_input(FILE *inslip)
|
|||||||
{
|
{
|
||||||
static unsigned char inbuf[2048];
|
static unsigned char inbuf[2048];
|
||||||
static int inbufptr = 0;
|
static int inbufptr = 0;
|
||||||
int ret,i;
|
int ret, i;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
ret = fread(&c, 1, 1, inslip);
|
ret = fread(&c, 1, 1, inslip);
|
||||||
if(ret == -1 || ret == 0) err(1, "serial_input: read");
|
if(ret == -1 || ret == 0) {
|
||||||
|
err(1, "serial_input: read");
|
||||||
|
}
|
||||||
goto after_fread;
|
goto after_fread;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
read_more:
|
read_more:
|
||||||
if(inbufptr >= sizeof(inbuf)) {
|
if(inbufptr >= sizeof(inbuf)) {
|
||||||
fprintf(stderr, "*** dropping large %d byte packet\n", inbufptr);
|
fprintf(stderr, "*** dropping large %d byte packet\n", inbufptr);
|
||||||
inbufptr = 0;
|
inbufptr = 0;
|
||||||
}
|
}
|
||||||
ret = fread(&c, 1, 1, inslip);
|
ret = fread(&c, 1, 1, inslip);
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
after_fread:
|
after_fread:
|
||||||
#endif
|
#endif
|
||||||
if(ret == -1) {
|
if(ret == -1) {
|
||||||
err(1, "serial_input: read");
|
err(1, "serial_input: read");
|
||||||
@ -208,12 +209,12 @@ serial_input(FILE *inslip)
|
|||||||
case SLIP_END:
|
case SLIP_END:
|
||||||
if(inbufptr > 0) {
|
if(inbufptr > 0) {
|
||||||
if(inbuf[0] == '!') {
|
if(inbuf[0] == '!') {
|
||||||
command_context = CMD_CONTEXT_RADIO;
|
command_context = CMD_CONTEXT_RADIO;
|
||||||
cmd_input(inbuf, inbufptr);
|
cmd_input(inbuf, inbufptr);
|
||||||
} else if(inbuf[0] == '?') {
|
} else if(inbuf[0] == '?') {
|
||||||
#define DEBUG_LINE_MARKER '\r'
|
#define DEBUG_LINE_MARKER '\r'
|
||||||
} else if(inbuf[0] == DEBUG_LINE_MARKER) {
|
} else if(inbuf[0] == DEBUG_LINE_MARKER) {
|
||||||
fwrite(inbuf + 1, inbufptr - 1, 1, stdout);
|
fwrite(inbuf + 1, inbufptr - 1, 1, stdout);
|
||||||
} else if(is_sensible_string(inbuf, inbufptr)) {
|
} else if(is_sensible_string(inbuf, inbufptr)) {
|
||||||
if(slip_config_verbose == 1) { /* strings already echoed below for verbose>1 */
|
if(slip_config_verbose == 1) { /* strings already echoed below for verbose>1 */
|
||||||
fwrite(inbuf, inbufptr, 1, stdout);
|
fwrite(inbuf, inbufptr, 1, stdout);
|
||||||
@ -224,19 +225,25 @@ serial_input(FILE *inslip)
|
|||||||
if(slip_config_verbose > 4) {
|
if(slip_config_verbose > 4) {
|
||||||
#if WIRESHARK_IMPORT_FORMAT
|
#if WIRESHARK_IMPORT_FORMAT
|
||||||
printf("0000");
|
printf("0000");
|
||||||
for(i = 0; i < inbufptr; i++) printf(" %02x", inbuf[i]);
|
for(i = 0; i < inbufptr; i++) {
|
||||||
|
printf(" %02x", inbuf[i]);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
printf(" ");
|
printf(" ");
|
||||||
for(i = 0; i < inbufptr; i++) {
|
for(i = 0; i < inbufptr; i++) {
|
||||||
printf("%02x", inbuf[i]);
|
printf("%02x", inbuf[i]);
|
||||||
if((i & 3) == 3) printf(" ");
|
if((i & 3) == 3) {
|
||||||
if((i & 15) == 15) printf("\n ");
|
printf(" ");
|
||||||
|
}
|
||||||
|
if((i & 15) == 15) {
|
||||||
|
printf("\n ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slip_packet_input(inbuf, inbufptr);
|
slip_packet_input(inbuf, inbufptr);
|
||||||
}
|
}
|
||||||
inbufptr = 0;
|
inbufptr = 0;
|
||||||
}
|
}
|
||||||
@ -266,7 +273,7 @@ serial_input(FILE *inslip)
|
|||||||
/* Echo all printable characters for verbose==4 */
|
/* Echo all printable characters for verbose==4 */
|
||||||
if(slip_config_verbose == 4) {
|
if(slip_config_verbose == 4) {
|
||||||
if(c == 0 || c == '\r' || c == '\n' || c == '\t' || (c >= ' ' && c <= '~')) {
|
if(c == 0 || c == '\r' || c == '\n' || c == '\t' || (c >= ' ' && c <= '~')) {
|
||||||
fwrite(&c, 1, 1, stdout);
|
fwrite(&c, 1, 1, stdout);
|
||||||
}
|
}
|
||||||
} else if(slip_config_verbose >= 2) {
|
} else if(slip_config_verbose >= 2) {
|
||||||
if(c == '\n' && is_sensible_string(inbuf, inbufptr)) {
|
if(c == '\n' && is_sensible_string(inbuf, inbufptr)) {
|
||||||
@ -279,7 +286,6 @@ serial_input(FILE *inslip)
|
|||||||
|
|
||||||
goto read_more;
|
goto read_more;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char slip_buf[2048];
|
unsigned char slip_buf[2048];
|
||||||
int slip_end, slip_begin, slip_packet_end, slip_packet_count;
|
int slip_end, slip_begin, slip_packet_end, slip_packet_count;
|
||||||
static struct timer send_delay_timer;
|
static struct timer send_delay_timer;
|
||||||
@ -367,13 +373,19 @@ write_to_serial(int outfd, const uint8_t *inbuf, int len)
|
|||||||
if(slip_config_verbose > 4) {
|
if(slip_config_verbose > 4) {
|
||||||
#if WIRESHARK_IMPORT_FORMAT
|
#if WIRESHARK_IMPORT_FORMAT
|
||||||
printf("0000");
|
printf("0000");
|
||||||
for(i = 0; i < len; i++) printf(" %02x", p[i]);
|
for(i = 0; i < len; i++) {
|
||||||
|
printf(" %02x", p[i]);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
printf(" ");
|
printf(" ");
|
||||||
for(i = 0; i < len; i++) {
|
for(i = 0; i < len; i++) {
|
||||||
printf("%02x", p[i]);
|
printf("%02x", p[i]);
|
||||||
if((i & 3) == 3) printf(" ");
|
if((i & 3) == 3) {
|
||||||
if((i & 15) == 15) printf("\n ");
|
printf(" ");
|
||||||
|
}
|
||||||
|
if((i & 15) == 15) {
|
||||||
|
printf("\n ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -420,9 +432,13 @@ stty_telos(int fd)
|
|||||||
speed_t speed = slip_config_b_rate;
|
speed_t speed = slip_config_b_rate;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
|
if(tcflush(fd, TCIOFLUSH) == -1) {
|
||||||
|
err(1, "tcflush");
|
||||||
|
}
|
||||||
|
|
||||||
if(tcgetattr(fd, &tty) == -1) err(1, "tcgetattr");
|
if(tcgetattr(fd, &tty) == -1) {
|
||||||
|
err(1, "tcgetattr");
|
||||||
|
}
|
||||||
|
|
||||||
cfmakeraw(&tty);
|
cfmakeraw(&tty);
|
||||||
|
|
||||||
@ -440,23 +456,31 @@ stty_telos(int fd)
|
|||||||
cfsetispeed(&tty, speed);
|
cfsetispeed(&tty, speed);
|
||||||
cfsetospeed(&tty, speed);
|
cfsetospeed(&tty, speed);
|
||||||
|
|
||||||
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr");
|
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) {
|
||||||
|
err(1, "tcsetattr");
|
||||||
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
/* Nonblocking read and write. */
|
/* Nonblocking read and write. */
|
||||||
/* if(fcntl(fd, F_SETFL, O_NONBLOCK) == -1) err(1, "fcntl"); */
|
/* if(fcntl(fd, F_SETFL, O_NONBLOCK) == -1) err(1, "fcntl"); */
|
||||||
|
|
||||||
tty.c_cflag |= CLOCAL;
|
tty.c_cflag |= CLOCAL;
|
||||||
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr");
|
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) {
|
||||||
|
err(1, "tcsetattr");
|
||||||
|
}
|
||||||
|
|
||||||
i = TIOCM_DTR;
|
i = TIOCM_DTR;
|
||||||
if(ioctl(fd, TIOCMBIS, &i) == -1) err(1, "ioctl");
|
if(ioctl(fd, TIOCMBIS, &i) == -1) {
|
||||||
|
err(1, "ioctl");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
usleep(10*1000); /* Wait for hardware 10ms. */
|
usleep(10 * 1000); /* Wait for hardware 10ms. */
|
||||||
|
|
||||||
/* Flush input and output buffers. */
|
/* Flush input and output buffers. */
|
||||||
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
|
if(tcflush(fd, TCIOFLUSH) == -1) {
|
||||||
|
err(1, "tcflush");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
@ -498,7 +522,6 @@ slip_init(void)
|
|||||||
if(slipfd == -1) {
|
if(slipfd == -1) {
|
||||||
err(1, "can't connect to ``%s:%s''", slip_config_host, slip_config_port);
|
err(1, "can't connect to ``%s:%s''", slip_config_host, slip_config_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if(slip_config_siodev != NULL) {
|
} else if(slip_config_siodev != NULL) {
|
||||||
if(strcmp(slip_config_siodev, "null") == 0) {
|
if(strcmp(slip_config_siodev, "null") == 0) {
|
||||||
/* Disable slip */
|
/* Disable slip */
|
||||||
@ -508,7 +531,6 @@ slip_init(void)
|
|||||||
if(slipfd == -1) {
|
if(slipfd == -1) {
|
||||||
err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
|
err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
static const char *siodevs[] = {
|
static const char *siodevs[] = {
|
||||||
"ttyUSB0", "cuaU0", "ucom0" /* linux, fbsd6, fbsd5 */
|
"ttyUSB0", "cuaU0", "ucom0" /* linux, fbsd6, fbsd5 */
|
||||||
@ -518,7 +540,7 @@ slip_init(void)
|
|||||||
slip_config_siodev = siodevs[i];
|
slip_config_siodev = siodevs[i];
|
||||||
slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
|
slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
|
||||||
if(slipfd != -1) {
|
if(slipfd != -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(slipfd == -1) {
|
if(slipfd == -1) {
|
||||||
@ -530,7 +552,7 @@ slip_init(void)
|
|||||||
|
|
||||||
if(slip_config_host != NULL) {
|
if(slip_config_host != NULL) {
|
||||||
fprintf(stderr, "********SLIP opened to ``%s:%s''\n", slip_config_host,
|
fprintf(stderr, "********SLIP opened to ``%s:%s''\n", slip_config_host,
|
||||||
slip_config_port);
|
slip_config_port);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "********SLIP started on ``/dev/%s''\n", slip_config_siodev);
|
fprintf(stderr, "********SLIP started on ``/dev/%s''\n", slip_config_siodev);
|
||||||
stty_telos(slipfd);
|
stty_telos(slipfd);
|
||||||
|
@ -96,7 +96,6 @@ ssystem(const char *fmt, ...)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return system(cmd);
|
return system(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cleanup(void)
|
cleanup(void)
|
||||||
@ -110,7 +109,6 @@ cleanup(void)
|
|||||||
" | sh",
|
" | sh",
|
||||||
slip_config_tundev);
|
slip_config_tundev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
sigcleanup(int signo)
|
sigcleanup(int signo)
|
||||||
@ -118,7 +116,6 @@ sigcleanup(int signo)
|
|||||||
fprintf(stderr, "signal %d\n", signo);
|
fprintf(stderr, "signal %d\n", signo);
|
||||||
exit(0); /* exit(0) will call cleanup() */
|
exit(0); /* exit(0) will call cleanup() */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
ifconf(const char *tundev, const char *ipaddr)
|
ifconf(const char *tundev, const char *ipaddr)
|
||||||
@ -154,7 +151,7 @@ tun_alloc(char *dev)
|
|||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int fd, err;
|
int fd, err;
|
||||||
|
|
||||||
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
|
if((fd = open("/dev/net/tun", O_RDWR)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,10 +161,11 @@ tun_alloc(char *dev)
|
|||||||
* IFF_NO_PI - Do not provide packet information
|
* IFF_NO_PI - Do not provide packet information
|
||||||
*/
|
*/
|
||||||
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
|
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
|
||||||
if(*dev != 0)
|
if(*dev != 0) {
|
||||||
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
||||||
|
}
|
||||||
|
|
||||||
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) {
|
if((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -191,11 +189,10 @@ tun_init()
|
|||||||
|
|
||||||
slip_init();
|
slip_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static uint16_t delaymsec=0;
|
static uint16_t delaymsec = 0;
|
||||||
static uint32_t delaystartsec,delaystartmsec;
|
static uint32_t delaystartsec, delaystartmsec;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
@ -209,7 +206,9 @@ tun_init()
|
|||||||
|
|
||||||
tunfd = tun_alloc(slip_config_tundev);
|
tunfd = tun_alloc(slip_config_tundev);
|
||||||
|
|
||||||
if(tunfd == -1) err(1, "main: open");
|
if(tunfd == -1) {
|
||||||
|
err(1, "main: open");
|
||||||
|
}
|
||||||
|
|
||||||
select_set_callback(tunfd, &tun_select_callback);
|
select_set_callback(tunfd, &tun_select_callback);
|
||||||
|
|
||||||
@ -222,7 +221,6 @@ tun_init()
|
|||||||
signal(SIGINT, sigcleanup);
|
signal(SIGINT, sigcleanup);
|
||||||
ifconf(slip_config_tundev, slip_config_ipaddr);
|
ifconf(slip_config_tundev, slip_config_ipaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
tun_output(uint8_t *data, int len)
|
tun_output(uint8_t *data, int len)
|
||||||
@ -239,11 +237,11 @@ int
|
|||||||
tun_input(unsigned char *data, int maxlen)
|
tun_input(unsigned char *data, int maxlen)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
if((size = read(tunfd, data, maxlen)) == -1)
|
if((size = read(tunfd, data, maxlen)) == -1) {
|
||||||
err(1, "tun_input: read");
|
err(1, "tun_input: read");
|
||||||
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
init(void)
|
init(void)
|
||||||
@ -259,8 +257,6 @@ output(void)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const struct uip_fallback_interface rpl_interface = {
|
const struct uip_fallback_interface rpl_interface = {
|
||||||
init, output
|
init, output
|
||||||
};
|
};
|
||||||
@ -274,7 +270,6 @@ set_fd(fd_set *rset, fd_set *wset)
|
|||||||
FD_SET(tunfd, rset);
|
FD_SET(tunfd, rset);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -287,12 +282,16 @@ handle_fd(fd_set *rset, fd_set *wset)
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int dmsec;
|
int dmsec;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
dmsec=(tv.tv_sec-delaystartsec)*1000+tv.tv_usec/1000-delaystartmsec;
|
dmsec = (tv.tv_sec - delaystartsec) * 1000 + tv.tv_usec / 1000 - delaystartmsec;
|
||||||
if(dmsec<0) delaymsec=0;
|
if(dmsec < 0) {
|
||||||
if(dmsec>delaymsec) delaymsec=0;
|
delaymsec = 0;
|
||||||
|
}
|
||||||
|
if(dmsec > delaymsec) {
|
||||||
|
delaymsec = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(delaymsec==0) {
|
if(delaymsec == 0) {
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
if(FD_ISSET(tunfd, rset)) {
|
if(FD_ISSET(tunfd, rset)) {
|
||||||
@ -303,10 +302,10 @@ handle_fd(fd_set *rset, fd_set *wset)
|
|||||||
|
|
||||||
if(slip_config_basedelay) {
|
if(slip_config_basedelay) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL) ;
|
gettimeofday(&tv, NULL);
|
||||||
delaymsec=slip_config_basedelay;
|
delaymsec = slip_config_basedelay;
|
||||||
delaystartsec =tv.tv_sec;
|
delaystartsec = tv.tv_sec;
|
||||||
delaystartmsec=tv.tv_usec/1000;
|
delaystartmsec = tv.tv_usec / 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user