Improve code style and remove obsolete lines
This commit is contained in:
parent
71ed11cdea
commit
517031f673
|
@ -43,27 +43,27 @@ uint8_t prefix_set;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
print_local_addresses(void)
|
print_local_addresses(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
|
||||||
LOG_INFO("Server IPv6 addresses:\n");
|
LOG_INFO("Server IPv6 addresses:\n");
|
||||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||||
state = uip_ds6_if.addr_list[i].state;
|
state = uip_ds6_if.addr_list[i].state;
|
||||||
if(uip_ds6_if.addr_list[i].isused &&
|
if(uip_ds6_if.addr_list[i].isused &&
|
||||||
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
||||||
LOG_INFO(" ");
|
LOG_INFO(" ");
|
||||||
LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||||
LOG_INFO_("\n");
|
LOG_INFO_("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
set_prefix_64(uip_ipaddr_t *prefix_64)
|
set_prefix_64(uip_ipaddr_t *prefix_64)
|
||||||
{
|
{
|
||||||
prefix_set = 1;
|
prefix_set = 1;
|
||||||
rpl_dag_root_init(prefix_64, NULL);
|
rpl_dag_root_init(prefix_64, NULL);
|
||||||
rpl_dag_root_init_dag_immediately();
|
rpl_dag_root_init_dag_immediately();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -55,7 +55,6 @@ static int blen;
|
||||||
} while(0)
|
} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Use simple webserver with only one page for minimum footprint.
|
/* Use simple webserver with only one page for minimum footprint.
|
||||||
* Multiple connections can result in interleaved tcp segments since
|
* Multiple connections can result in interleaved tcp segments since
|
||||||
* a single static buffer is used for all segments.
|
* a single static buffer is used for all segments.
|
||||||
|
@ -86,7 +85,9 @@ ipaddr_add(const uip_ipaddr_t *addr)
|
||||||
for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
|
for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) {
|
||||||
a = (addr->u8[i] << 8) + addr->u8[i + 1];
|
a = (addr->u8[i] << 8) + addr->u8[i + 1];
|
||||||
if(a == 0 && f >= 0) {
|
if(a == 0 && f >= 0) {
|
||||||
if(f++ == 0) ADD("::");
|
if(f++ == 0) {
|
||||||
|
ADD("::");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if(f > 0) {
|
if(f > 0) {
|
||||||
f = -1;
|
f = -1;
|
||||||
|
@ -118,7 +119,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
|
|
||||||
SEND_STRING(&s->sout, TOP);
|
SEND_STRING(&s->sout, TOP);
|
||||||
#if BUF_USES_STACK
|
#if BUF_USES_STACK
|
||||||
bufptr = buf;bufend=bufptr+sizeof(buf);
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
#else
|
#else
|
||||||
blen = 0;
|
blen = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -130,51 +132,63 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
|
|
||||||
#if WEBSERVER_CONF_NEIGHBOR_STATUS
|
#if WEBSERVER_CONF_NEIGHBOR_STATUS
|
||||||
#if BUF_USES_STACK
|
#if BUF_USES_STACK
|
||||||
{char* j=bufptr+25;
|
{ char *j = bufptr + 25;
|
||||||
ipaddr_add(&nbr->ipaddr);
|
ipaddr_add(&nbr->ipaddr);
|
||||||
while (bufptr < j) ADD(" ");
|
while(bufptr < j) ADD(" ");
|
||||||
switch (nbr->state) {
|
switch(nbr->state) {
|
||||||
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
|
case NBR_INCOMPLETE: ADD(" INCOMPLETE");
|
||||||
case NBR_REACHABLE: ADD(" REACHABLE");break;
|
break;
|
||||||
case NBR_STALE: ADD(" STALE");break;
|
case NBR_REACHABLE: ADD(" REACHABLE");
|
||||||
case NBR_DELAY: ADD(" DELAY");break;
|
break;
|
||||||
case NBR_PROBE: ADD(" NBR_PROBE");break;
|
case NBR_STALE: ADD(" STALE");
|
||||||
|
break;
|
||||||
|
case NBR_DELAY: ADD(" DELAY");
|
||||||
|
break;
|
||||||
|
case NBR_PROBE: ADD(" NBR_PROBE");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{uint8_t j=blen+25;
|
{ uint8_t j = blen + 25;
|
||||||
ipaddr_add(&nbr->ipaddr);
|
ipaddr_add(&nbr->ipaddr);
|
||||||
while (blen < j) ADD(" ");
|
while(blen < j) ADD(" ");
|
||||||
switch (nbr->state) {
|
switch(nbr->state) {
|
||||||
case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
|
case NBR_INCOMPLETE: ADD(" INCOMPLETE");
|
||||||
case NBR_REACHABLE: ADD(" REACHABLE");break;
|
break;
|
||||||
case NBR_STALE: ADD(" STALE");break;
|
case NBR_REACHABLE: ADD(" REACHABLE");
|
||||||
case NBR_DELAY: ADD(" DELAY");break;
|
break;
|
||||||
case NBR_PROBE: ADD(" NBR_PROBE");break;
|
case NBR_STALE: ADD(" STALE");
|
||||||
|
break;
|
||||||
|
case NBR_DELAY: ADD(" DELAY");
|
||||||
|
break;
|
||||||
|
case NBR_PROBE: ADD(" NBR_PROBE");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
ipaddr_add(&nbr->ipaddr);
|
ipaddr_add(&nbr->ipaddr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ADD("\n");
|
ADD("\n");
|
||||||
#if BUF_USES_STACK
|
#if BUF_USES_STACK
|
||||||
if(bufptr > bufend - 45) {
|
if(bufptr > bufend - 45) {
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
bufptr = buf;
|
||||||
}
|
bufend = bufptr + sizeof(buf);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if(blen > sizeof(buf) - 45) {
|
if(blen > sizeof(buf) - 45) {
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
blen = 0;
|
blen = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ADD("</pre>Routes<pre>\n");
|
ADD("</pre>Routes<pre>\n");
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
#if BUF_USES_STACK
|
#if BUF_USES_STACK
|
||||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
#else
|
#else
|
||||||
blen = 0;
|
blen = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -196,7 +210,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
ADD("<a href=http://[");
|
ADD("<a href=http://[");
|
||||||
ipaddr_add(&r->ipaddr);
|
ipaddr_add(&r->ipaddr);
|
||||||
ADD("]/status.shtml>");
|
ADD("]/status.shtml>");
|
||||||
SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
|
SEND_STRING(&s->sout, buf);
|
||||||
blen = 0;
|
blen = 0;
|
||||||
ipaddr_add(&r->ipaddr);
|
ipaddr_add(&r->ipaddr);
|
||||||
ADD("</a>");
|
ADD("</a>");
|
||||||
|
@ -213,7 +227,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
}
|
}
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
#if BUF_USES_STACK
|
#if BUF_USES_STACK
|
||||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
#else
|
#else
|
||||||
blen = 0;
|
blen = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -224,7 +239,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
ADD("Links<pre>\n");
|
ADD("Links<pre>\n");
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
#if BUF_USES_STACK
|
#if BUF_USES_STACK
|
||||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
#else
|
#else
|
||||||
blen = 0;
|
blen = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -251,7 +267,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
ADD("<a href=http://[");
|
ADD("<a href=http://[");
|
||||||
ipaddr_add(&child_ipaddr);
|
ipaddr_add(&child_ipaddr);
|
||||||
ADD("]/status.shtml>");
|
ADD("]/status.shtml>");
|
||||||
SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
|
SEND_STRING(&s->sout, buf);
|
||||||
blen = 0;
|
blen = 0;
|
||||||
ipaddr_add(&child_ipaddr);
|
ipaddr_add(&child_ipaddr);
|
||||||
ADD("</a>");
|
ADD("</a>");
|
||||||
|
@ -263,14 +279,14 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
ADD(" (parent: ");
|
ADD(" (parent: ");
|
||||||
ipaddr_add(&parent_ipaddr);
|
ipaddr_add(&parent_ipaddr);
|
||||||
if(1 || (link->lifetime < 600)) {
|
if(1 || (link->lifetime < 600)) {
|
||||||
ADD(") %us\n", (unsigned int)link->lifetime); // iotlab printf does not have %lu
|
ADD(") %us\n", (unsigned int)link->lifetime);
|
||||||
//ADD(") %lus\n", (unsigned long)r->state.lifetime);
|
|
||||||
} else {
|
} else {
|
||||||
ADD(")\n");
|
ADD(")\n");
|
||||||
}
|
}
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
#if BUF_USES_STACK
|
#if BUF_USES_STACK
|
||||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
bufptr = buf;
|
||||||
|
bufend = bufptr + sizeof(buf);
|
||||||
#else
|
#else
|
||||||
blen = 0;
|
blen = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -281,12 +297,12 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||||
|
|
||||||
#if WEBSERVER_CONF_FILESTATS
|
#if WEBSERVER_CONF_FILESTATS
|
||||||
static uint16_t numtimes;
|
static uint16_t numtimes;
|
||||||
ADD("<br><i>This page sent %u times</i>",++numtimes);
|
ADD("<br><i>This page sent %u times</i>", ++numtimes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WEBSERVER_CONF_LOADTIME
|
#if WEBSERVER_CONF_LOADTIME
|
||||||
numticks = clock_time() - numticks + 1;
|
numticks = clock_time() - numticks + 1;
|
||||||
ADD(" <i>(%u.%02u sec)</i>",numticks/CLOCK_SECOND,(100*(numticks%CLOCK_SECOND))/CLOCK_SECOND));
|
ADD(" <i>(%u.%02u sec)</i>", numticks / CLOCK_SECOND, (100 * (numticks % CLOCK_SECOND)) / CLOCK_SECOND));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SEND_STRING(&s->sout, buf);
|
SEND_STRING(&s->sout, buf);
|
||||||
|
|
|
@ -86,7 +86,7 @@ PROCESS_THREAD(border_router_process, ev, data)
|
||||||
|
|
||||||
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();
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -100,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 */
|
||||||
|
@ -110,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);
|
||||||
|
|
|
@ -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