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
|
||||
print_local_addresses(void)
|
||||
{
|
||||
int i;
|
||||
uint8_t state;
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
@ -42,8 +42,6 @@
|
||||
|
||||
#include "contiki-net.h"
|
||||
|
||||
//#include "urlconv.h"
|
||||
|
||||
#if UIP_CONF_TCP == 0
|
||||
#error HTTP server needs TCP enabled
|
||||
#endif
|
||||
@ -153,7 +151,7 @@ PT_THREAD(handle_output(struct httpd_state *s))
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const char http_get[] = "GET ";
|
||||
const char http_index_html[] = "/index.html";
|
||||
//const char http_referer[] = "Referer:"
|
||||
|
||||
static
|
||||
PT_THREAD(handle_input(struct httpd_state *s))
|
||||
{
|
||||
@ -207,7 +205,6 @@ handle_connection(struct httpd_state *s)
|
||||
handle_output(s);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
httpd_appcall(void *state)
|
||||
@ -250,7 +247,6 @@ httpd_appcall(void *state)
|
||||
uip_abort();
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
httpd_init(void)
|
||||
|
@ -51,7 +51,7 @@
|
||||
#endif /* WEBSERVER_CONF_CFS_CONNS */
|
||||
|
||||
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 timer timer;
|
||||
|
@ -55,7 +55,6 @@ static int blen;
|
||||
} 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.
|
||||
@ -86,7 +85,9 @@ ipaddr_add(const uip_ipaddr_t *addr)
|
||||
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("::");
|
||||
if(f++ == 0) {
|
||||
ADD("::");
|
||||
}
|
||||
} else {
|
||||
if(f > 0) {
|
||||
f = -1;
|
||||
@ -118,7 +119,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
|
||||
SEND_STRING(&s->sout, TOP);
|
||||
#if BUF_USES_STACK
|
||||
bufptr = buf;bufend=bufptr+sizeof(buf);
|
||||
bufptr = buf;
|
||||
bufend = bufptr + sizeof(buf);
|
||||
#else
|
||||
blen = 0;
|
||||
#endif
|
||||
@ -130,51 +132,63 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
|
||||
#if WEBSERVER_CONF_NEIGHBOR_STATUS
|
||||
#if BUF_USES_STACK
|
||||
{char* j=bufptr+25;
|
||||
{ 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;
|
||||
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;
|
||||
{ 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;
|
||||
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);
|
||||
ipaddr_add(&nbr->ipaddr);
|
||||
#endif
|
||||
|
||||
ADD("\n");
|
||||
ADD("\n");
|
||||
#if BUF_USES_STACK
|
||||
if(bufptr > bufend - 45) {
|
||||
SEND_STRING(&s->sout, buf);
|
||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
||||
}
|
||||
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;
|
||||
}
|
||||
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);
|
||||
bufptr = buf;
|
||||
bufend = bufptr + sizeof(buf);
|
||||
#else
|
||||
blen = 0;
|
||||
#endif
|
||||
@ -196,7 +210,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
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
|
||||
SEND_STRING(&s->sout, buf);
|
||||
blen = 0;
|
||||
ipaddr_add(&r->ipaddr);
|
||||
ADD("</a>");
|
||||
@ -213,7 +227,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
}
|
||||
SEND_STRING(&s->sout, buf);
|
||||
#if BUF_USES_STACK
|
||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
||||
bufptr = buf;
|
||||
bufend = bufptr + sizeof(buf);
|
||||
#else
|
||||
blen = 0;
|
||||
#endif
|
||||
@ -224,7 +239,8 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
ADD("Links<pre>\n");
|
||||
SEND_STRING(&s->sout, buf);
|
||||
#if BUF_USES_STACK
|
||||
bufptr = buf; bufend = bufptr + sizeof(buf);
|
||||
bufptr = buf;
|
||||
bufend = bufptr + sizeof(buf);
|
||||
#else
|
||||
blen = 0;
|
||||
#endif
|
||||
@ -251,7 +267,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
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
|
||||
SEND_STRING(&s->sout, buf);
|
||||
blen = 0;
|
||||
ipaddr_add(&child_ipaddr);
|
||||
ADD("</a>");
|
||||
@ -263,14 +279,14 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
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);
|
||||
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);
|
||||
bufptr = buf;
|
||||
bufend = bufptr + sizeof(buf);
|
||||
#else
|
||||
blen = 0;
|
||||
#endif
|
||||
@ -281,12 +297,12 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
||||
|
||||
#if WEBSERVER_CONF_FILESTATS
|
||||
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
|
||||
|
||||
#if WEBSERVER_CONF_LOADTIME
|
||||
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
|
||||
|
||||
SEND_STRING(&s->sout, buf);
|
||||
|
@ -86,7 +86,7 @@ PROCESS_THREAD(border_router_process, ev, data)
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if (ev == sensors_event && data == &button_sensor) {
|
||||
if(ev == sensors_event && data == &button_sensor) {
|
||||
LOG_INFO("Initiating global repair\n");
|
||||
#if UIP_CONF_IPV6_RPL_LITE
|
||||
rpl_global_repair();
|
||||
|
@ -47,7 +47,6 @@
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/ipv6/uip-debug.h"
|
||||
|
||||
|
||||
uint8_t command_context;
|
||||
|
||||
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) {
|
||||
/* We need to know that this is from the slip-radio here. */
|
||||
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]);
|
||||
return 1;
|
||||
} 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]);
|
||||
if(data[1] == 'M' && command_context == CMD_CONTEXT_STDIO) {
|
||||
uint8_t buf[20];
|
||||
char* hexchar = "0123456789abcdef";
|
||||
char *hexchar = "0123456789abcdef";
|
||||
int j;
|
||||
/* this is just a test so far... just to see if it works */
|
||||
buf[0] = '!';
|
||||
@ -141,7 +140,7 @@ PROCESS_THREAD(border_router_cmd_process, ev, data)
|
||||
PROCESS_YIELD();
|
||||
if(ev == serial_line_event_message && data != NULL) {
|
||||
PRINTF("Got serial data!!! %s of len: %d\n",
|
||||
(char *)data, strlen((char *)data));
|
||||
(char *)data, strlen((char *)data));
|
||||
command_context = CMD_CONTEXT_STDIO;
|
||||
cmd_input(data, strlen((char *)data));
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ struct tx_callback {
|
||||
|
||||
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) {
|
||||
struct tx_callback *callback;
|
||||
@ -114,7 +115,6 @@ send_packet(mac_callback_t sent, void *ptr)
|
||||
/* Failed to allocate space for headers */
|
||||
PRINTF("br-rdc: send failed, too large header\n");
|
||||
mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
|
||||
|
||||
} else {
|
||||
/* here we send the data over SLIP to the radio-chip */
|
||||
size = 0;
|
||||
|
@ -100,7 +100,6 @@ border_router_print_stat()
|
||||
printf("bytes received over SLIP: %ld\n", slip_received);
|
||||
printf("bytes sent over SLIP: %ld\n", slip_sent);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Format: <name=value>;<name=value>;...;<name=value>*/
|
||||
/* 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 last_pos = 0;
|
||||
int sc = 0;
|
||||
for(i = 0;i < len; i++) {
|
||||
for(i = 0; i < len; i++) {
|
||||
if(data[i] == ';') {
|
||||
sensors[sc][i - last_pos] = 0;
|
||||
memcpy(sensors[sc++], &data[last_pos], i - last_pos);
|
||||
|
@ -40,7 +40,6 @@
|
||||
/* use a non-default MAC driver */
|
||||
#define NETSTACK_CONF_MAC border_router_mac_driver
|
||||
|
||||
|
||||
#define SLIP_DEV_CONF_SEND_DELAY (CLOCK_SECOND / 32)
|
||||
|
||||
#define WEBSERVER_CONF_CFS_CONNS 2
|
||||
@ -50,7 +49,6 @@
|
||||
|
||||
#define CMD_CONF_OUTPUT border_router_cmd_output
|
||||
|
||||
|
||||
/* used by wpcap (see /cpu/native/net/wpcap-drv.c) */
|
||||
#define SELECT_CALLBACK 1
|
||||
|
||||
|
@ -89,17 +89,17 @@ slip_config_handle_arguments(int argc, char **argv)
|
||||
|
||||
case 's':
|
||||
if(strncmp("/dev/", optarg, 5) == 0) {
|
||||
slip_config_siodev = optarg + 5;
|
||||
slip_config_siodev = optarg + 5;
|
||||
} else {
|
||||
slip_config_siodev = optarg;
|
||||
slip_config_siodev = optarg;
|
||||
}
|
||||
break;
|
||||
|
||||
case 't':
|
||||
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 {
|
||||
strncpy(slip_config_tundev, optarg, sizeof(slip_config_tundev));
|
||||
strncpy(slip_config_tundev, optarg, sizeof(slip_config_tundev));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -113,43 +113,47 @@ slip_config_handle_arguments(int argc, char **argv)
|
||||
|
||||
case 'd':
|
||||
slip_config_basedelay = 10;
|
||||
if(optarg) slip_config_basedelay = atoi(optarg);
|
||||
if(optarg) {
|
||||
slip_config_basedelay = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
slip_config_verbose = 2;
|
||||
if(optarg) slip_config_verbose = atoi(optarg);
|
||||
if(optarg) {
|
||||
slip_config_verbose = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
case '?':
|
||||
case 'h':
|
||||
default:
|
||||
fprintf(stderr,"usage: %s [options] ipaddress\n", prog);
|
||||
fprintf(stderr,"example: border-router.native -L -v2 -s ttyUSB1 fd00::1/64\n");
|
||||
fprintf(stderr,"Options are:\n");
|
||||
fprintf(stderr, "usage: %s [options] ipaddress\n", prog);
|
||||
fprintf(stderr, "example: border-router.native -L -v2 -s ttyUSB1 fd00::1/64\n");
|
||||
fprintf(stderr, "Options are:\n");
|
||||
#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
|
||||
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
|
||||
fprintf(stderr," -H Hardware CTS/RTS flow control (default disabled)\n");
|
||||
fprintf(stderr," -L Log output format (adds time stamps)\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," -p port Connect via TCP to server at <host>:<port>\n");
|
||||
fprintf(stderr," -t tundev Name of interface (default tun0)\n");
|
||||
fprintf(stderr," -v[level] Verbosity level\n");
|
||||
fprintf(stderr," -v0 No messages\n");
|
||||
fprintf(stderr," -v1 Encapsulated SLIP debug messages (default)\n");
|
||||
fprintf(stderr," -v2 Printable strings after they are received\n");
|
||||
fprintf(stderr," -v3 Printable strings and SLIP packet notifications\n");
|
||||
fprintf(stderr," -v4 All printable characters as they are received\n");
|
||||
fprintf(stderr," -v5 All SLIP packets in hex\n");
|
||||
fprintf(stderr," -v Equivalent to -v3\n");
|
||||
fprintf(stderr," -d[basedelay] Minimum delay between outgoing SLIP packets.\n");
|
||||
fprintf(stderr," Actual delay is basedelay*(#6LowPAN fragments) milliseconds.\n");
|
||||
fprintf(stderr," -d is equivalent to -d10.\n");
|
||||
exit(1);
|
||||
fprintf(stderr, " -H Hardware CTS/RTS flow control (default disabled)\n");
|
||||
fprintf(stderr, " -L Log output format (adds time stamps)\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, " -p port Connect via TCP to server at <host>:<port>\n");
|
||||
fprintf(stderr, " -t tundev Name of interface (default tun0)\n");
|
||||
fprintf(stderr, " -v[level] Verbosity level\n");
|
||||
fprintf(stderr, " -v0 No messages\n");
|
||||
fprintf(stderr, " -v1 Encapsulated SLIP debug messages (default)\n");
|
||||
fprintf(stderr, " -v2 Printable strings after they are received\n");
|
||||
fprintf(stderr, " -v3 Printable strings and SLIP packet notifications\n");
|
||||
fprintf(stderr, " -v4 All printable characters as they are received\n");
|
||||
fprintf(stderr, " -v5 All SLIP packets in hex\n");
|
||||
fprintf(stderr, " -v Equivalent to -v3\n");
|
||||
fprintf(stderr, " -d[basedelay] Minimum delay between outgoing SLIP packets.\n");
|
||||
fprintf(stderr, " Actual delay is basedelay*(#6LowPAN fragments) milliseconds.\n");
|
||||
fprintf(stderr, " -d is equivalent to -d10.\n");
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ long slip_received = 0;
|
||||
|
||||
int slipfd = 0;
|
||||
|
||||
//#define PROGRESS(s) fprintf(stderr, s)
|
||||
#define PROGRESS(s) do { } while(0)
|
||||
|
||||
#define SLIP_END 0300
|
||||
@ -93,9 +92,9 @@ static void *
|
||||
get_in_addr(struct sockaddr *sa)
|
||||
{
|
||||
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
|
||||
@ -138,7 +137,7 @@ connect_to_server(const char *host, const char *port)
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
|
||||
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
|
||||
s, sizeof(s));
|
||||
s, sizeof(s));
|
||||
|
||||
/* all done with this structure */
|
||||
freeaddrinfo(servinfo);
|
||||
@ -178,23 +177,25 @@ serial_input(FILE *inslip)
|
||||
{
|
||||
static unsigned char inbuf[2048];
|
||||
static int inbufptr = 0;
|
||||
int ret,i;
|
||||
int ret, i;
|
||||
unsigned char c;
|
||||
|
||||
#ifdef linux
|
||||
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;
|
||||
#endif
|
||||
|
||||
read_more:
|
||||
read_more:
|
||||
if(inbufptr >= sizeof(inbuf)) {
|
||||
fprintf(stderr, "*** dropping large %d byte packet\n", inbufptr);
|
||||
inbufptr = 0;
|
||||
fprintf(stderr, "*** dropping large %d byte packet\n", inbufptr);
|
||||
inbufptr = 0;
|
||||
}
|
||||
ret = fread(&c, 1, 1, inslip);
|
||||
#ifdef linux
|
||||
after_fread:
|
||||
after_fread:
|
||||
#endif
|
||||
if(ret == -1) {
|
||||
err(1, "serial_input: read");
|
||||
@ -208,12 +209,12 @@ serial_input(FILE *inslip)
|
||||
case SLIP_END:
|
||||
if(inbufptr > 0) {
|
||||
if(inbuf[0] == '!') {
|
||||
command_context = CMD_CONTEXT_RADIO;
|
||||
cmd_input(inbuf, inbufptr);
|
||||
command_context = CMD_CONTEXT_RADIO;
|
||||
cmd_input(inbuf, inbufptr);
|
||||
} else if(inbuf[0] == '?') {
|
||||
#define DEBUG_LINE_MARKER '\r'
|
||||
} 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)) {
|
||||
if(slip_config_verbose == 1) { /* strings already echoed below for verbose>1 */
|
||||
fwrite(inbuf, inbufptr, 1, stdout);
|
||||
@ -224,19 +225,25 @@ serial_input(FILE *inslip)
|
||||
if(slip_config_verbose > 4) {
|
||||
#if WIRESHARK_IMPORT_FORMAT
|
||||
printf("0000");
|
||||
for(i = 0; i < inbufptr; i++) printf(" %02x", inbuf[i]);
|
||||
for(i = 0; i < inbufptr; i++) {
|
||||
printf(" %02x", inbuf[i]);
|
||||
}
|
||||
#else
|
||||
printf(" ");
|
||||
for(i = 0; i < inbufptr; i++) {
|
||||
printf("%02x", inbuf[i]);
|
||||
if((i & 3) == 3) printf(" ");
|
||||
if((i & 15) == 15) printf("\n ");
|
||||
if((i & 3) == 3) {
|
||||
printf(" ");
|
||||
}
|
||||
if((i & 15) == 15) {
|
||||
printf("\n ");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
slip_packet_input(inbuf, inbufptr);
|
||||
slip_packet_input(inbuf, inbufptr);
|
||||
}
|
||||
inbufptr = 0;
|
||||
}
|
||||
@ -266,7 +273,7 @@ serial_input(FILE *inslip)
|
||||
/* Echo all printable characters for verbose==4 */
|
||||
if(slip_config_verbose == 4) {
|
||||
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) {
|
||||
if(c == '\n' && is_sensible_string(inbuf, inbufptr)) {
|
||||
@ -279,7 +286,6 @@ serial_input(FILE *inslip)
|
||||
|
||||
goto read_more;
|
||||
}
|
||||
|
||||
unsigned char slip_buf[2048];
|
||||
int slip_end, slip_begin, slip_packet_end, slip_packet_count;
|
||||
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 WIRESHARK_IMPORT_FORMAT
|
||||
printf("0000");
|
||||
for(i = 0; i < len; i++) printf(" %02x", p[i]);
|
||||
for(i = 0; i < len; i++) {
|
||||
printf(" %02x", p[i]);
|
||||
}
|
||||
#else
|
||||
printf(" ");
|
||||
for(i = 0; i < len; i++) {
|
||||
printf("%02x", p[i]);
|
||||
if((i & 3) == 3) printf(" ");
|
||||
if((i & 15) == 15) printf("\n ");
|
||||
if((i & 3) == 3) {
|
||||
printf(" ");
|
||||
}
|
||||
if((i & 15) == 15) {
|
||||
printf("\n ");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
printf("\n");
|
||||
@ -420,9 +432,13 @@ stty_telos(int fd)
|
||||
speed_t speed = slip_config_b_rate;
|
||||
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);
|
||||
|
||||
@ -440,23 +456,31 @@ stty_telos(int fd)
|
||||
cfsetispeed(&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
|
||||
/* Nonblocking read and write. */
|
||||
/* if(fcntl(fd, F_SETFL, O_NONBLOCK) == -1) err(1, "fcntl"); */
|
||||
|
||||
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;
|
||||
if(ioctl(fd, TIOCMBIS, &i) == -1) err(1, "ioctl");
|
||||
if(ioctl(fd, TIOCMBIS, &i) == -1) {
|
||||
err(1, "ioctl");
|
||||
}
|
||||
#endif
|
||||
|
||||
usleep(10*1000); /* Wait for hardware 10ms. */
|
||||
usleep(10 * 1000); /* Wait for hardware 10ms. */
|
||||
|
||||
/* Flush input and output buffers. */
|
||||
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
|
||||
if(tcflush(fd, TCIOFLUSH) == -1) {
|
||||
err(1, "tcflush");
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
@ -498,7 +522,6 @@ slip_init(void)
|
||||
if(slipfd == -1) {
|
||||
err(1, "can't connect to ``%s:%s''", slip_config_host, slip_config_port);
|
||||
}
|
||||
|
||||
} else if(slip_config_siodev != NULL) {
|
||||
if(strcmp(slip_config_siodev, "null") == 0) {
|
||||
/* Disable slip */
|
||||
@ -508,7 +531,6 @@ slip_init(void)
|
||||
if(slipfd == -1) {
|
||||
err(1, "can't open siodev ``/dev/%s''", slip_config_siodev);
|
||||
}
|
||||
|
||||
} else {
|
||||
static const char *siodevs[] = {
|
||||
"ttyUSB0", "cuaU0", "ucom0" /* linux, fbsd6, fbsd5 */
|
||||
@ -518,7 +540,7 @@ slip_init(void)
|
||||
slip_config_siodev = siodevs[i];
|
||||
slipfd = devopen(slip_config_siodev, O_RDWR | O_NONBLOCK);
|
||||
if(slipfd != -1) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(slipfd == -1) {
|
||||
@ -530,7 +552,7 @@ slip_init(void)
|
||||
|
||||
if(slip_config_host != NULL) {
|
||||
fprintf(stderr, "********SLIP opened to ``%s:%s''\n", slip_config_host,
|
||||
slip_config_port);
|
||||
slip_config_port);
|
||||
} else {
|
||||
fprintf(stderr, "********SLIP started on ``/dev/%s''\n", slip_config_siodev);
|
||||
stty_telos(slipfd);
|
||||
|
@ -96,7 +96,6 @@ ssystem(const char *fmt, ...)
|
||||
fflush(stdout);
|
||||
return system(cmd);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
cleanup(void)
|
||||
@ -110,7 +109,6 @@ cleanup(void)
|
||||
" | sh",
|
||||
slip_config_tundev);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
sigcleanup(int signo)
|
||||
@ -118,7 +116,6 @@ sigcleanup(int signo)
|
||||
fprintf(stderr, "signal %d\n", signo);
|
||||
exit(0); /* exit(0) will call cleanup() */
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ifconf(const char *tundev, const char *ipaddr)
|
||||
@ -154,7 +151,7 @@ tun_alloc(char *dev)
|
||||
struct ifreq ifr;
|
||||
int fd, err;
|
||||
|
||||
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
|
||||
if((fd = open("/dev/net/tun", O_RDWR)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -164,10 +161,11 @@ tun_alloc(char *dev)
|
||||
* IFF_NO_PI - Do not provide packet information
|
||||
*/
|
||||
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
|
||||
if(*dev != 0)
|
||||
if(*dev != 0) {
|
||||
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
||||
}
|
||||
|
||||
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) {
|
||||
if((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) {
|
||||
close(fd);
|
||||
return err;
|
||||
}
|
||||
@ -191,11 +189,10 @@ tun_init()
|
||||
|
||||
slip_init();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static uint16_t delaymsec=0;
|
||||
static uint32_t delaystartsec,delaystartmsec;
|
||||
static uint16_t delaymsec = 0;
|
||||
static uint32_t delaystartsec, delaystartmsec;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
@ -209,7 +206,9 @@ tun_init()
|
||||
|
||||
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);
|
||||
|
||||
@ -222,7 +221,6 @@ tun_init()
|
||||
signal(SIGINT, sigcleanup);
|
||||
ifconf(slip_config_tundev, slip_config_ipaddr);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
tun_output(uint8_t *data, int len)
|
||||
@ -239,11 +237,11 @@ int
|
||||
tun_input(unsigned char *data, int maxlen)
|
||||
{
|
||||
int size;
|
||||
if((size = read(tunfd, data, maxlen)) == -1)
|
||||
if((size = read(tunfd, data, maxlen)) == -1) {
|
||||
err(1, "tun_input: read");
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
@ -259,8 +257,6 @@ output(void)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const struct uip_fallback_interface rpl_interface = {
|
||||
init, output
|
||||
};
|
||||
@ -274,7 +270,6 @@ set_fd(fd_set *rset, fd_set *wset)
|
||||
FD_SET(tunfd, rset);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
@ -287,12 +282,16 @@ handle_fd(fd_set *rset, fd_set *wset)
|
||||
struct timeval tv;
|
||||
int dmsec;
|
||||
gettimeofday(&tv, NULL);
|
||||
dmsec=(tv.tv_sec-delaystartsec)*1000+tv.tv_usec/1000-delaystartmsec;
|
||||
if(dmsec<0) delaymsec=0;
|
||||
if(dmsec>delaymsec) delaymsec=0;
|
||||
dmsec = (tv.tv_sec - delaystartsec) * 1000 + tv.tv_usec / 1000 - delaystartmsec;
|
||||
if(dmsec < 0) {
|
||||
delaymsec = 0;
|
||||
}
|
||||
if(dmsec > delaymsec) {
|
||||
delaymsec = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(delaymsec==0) {
|
||||
if(delaymsec == 0) {
|
||||
int size;
|
||||
|
||||
if(FD_ISSET(tunfd, rset)) {
|
||||
@ -303,10 +302,10 @@ handle_fd(fd_set *rset, fd_set *wset)
|
||||
|
||||
if(slip_config_basedelay) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL) ;
|
||||
delaymsec=slip_config_basedelay;
|
||||
delaystartsec =tv.tv_sec;
|
||||
delaystartmsec=tv.tv_usec/1000;
|
||||
gettimeofday(&tv, NULL);
|
||||
delaymsec = slip_config_basedelay;
|
||||
delaystartsec = tv.tv_sec;
|
||||
delaystartmsec = tv.tv_usec / 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user