Merge remote-tracking branch 'sf/master' into rpl-patch
This commit is contained in:
commit
0e32956a63
406 changed files with 26884 additions and 3635 deletions
|
@ -1,20 +1,37 @@
|
|||
all: border-router
|
||||
CONTIKI_PROJECT=border-router
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI=../../..
|
||||
|
||||
WITH_UIP6=1
|
||||
UIP_CONF_IPV6=1
|
||||
CFLAGS+= -DUIP_CONF_IPV6_RPL
|
||||
|
||||
#Override inclusion of internal webserver with make WITH_WEBSERVER=0
|
||||
WITH_WEBSERVER=1
|
||||
#linker optimizations
|
||||
SMALL=1
|
||||
|
||||
ifeq ($(WITH_WEBSERVER), 0)
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
PROJECT_SOURCEFILES += slip-bridge.c
|
||||
else
|
||||
APPS += webserver
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" -DWEBSERVER
|
||||
PROJECT_SOURCEFILES += slip-bridge.c httpd-simple.c
|
||||
|
||||
#Simple built-in webserver is the default.
|
||||
#Override with make WITH_WEBSERVER=0 for no webserver.
|
||||
#WITH_WEBSERVER=webserver-name will use /apps/webserver-name if it can be
|
||||
#found in the /apps, /platform/$(TARGET)/apps/, or current directory (in that order).
|
||||
# WITH_WEBSERVER=webserver for /apps/webserver
|
||||
# WITH_WEBSERVER=raven-webserver for /platform/avr-raven/apps/raven-webserver/
|
||||
#make clean before changing webservers!
|
||||
|
||||
#Note /apps/webserver contains a 2500 byte style sheet which is a severe test
|
||||
#of the slip connection. Large MSS together with low baud rates without flow
|
||||
#control will overrun the transmit buffer when the style sheet is requested.
|
||||
|
||||
WITH_WEBSERVER=1
|
||||
ifeq ($(WITH_WEBSERVER),1)
|
||||
CFLAGS += -DWEBSERVER=1
|
||||
PROJECT_SOURCEFILES += httpd-simple.c
|
||||
else ifneq ($(WITH_WEBSERVER), 0)
|
||||
APPS += $(WITH_WEBSERVER)
|
||||
CFLAGS += -DWEBSERVER=2
|
||||
endif
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
|
|
@ -46,18 +46,12 @@
|
|||
#include "dev/button-sensor.h"
|
||||
#include "dev/slip.h"
|
||||
|
||||
/* For internal webserver Makefile must set APPS += webserver and PROJECT_SOURCEFILES += httpd-simple.c */
|
||||
#if WEBSERVER
|
||||
#include "webserver-nogui.h"
|
||||
#include "httpd-simple.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
uint16_t dag_id[] = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011};
|
||||
|
@ -69,11 +63,33 @@ static uip_ipaddr_t prefix;
|
|||
static uint8_t prefix_set;
|
||||
|
||||
PROCESS(border_router_process, "Border router process");
|
||||
AUTOSTART_PROCESSES(&border_router_process);
|
||||
|
||||
#if WEBSERVER
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Only one single web request at time */
|
||||
#if WEBSERVER==0
|
||||
/* No webserver */
|
||||
AUTOSTART_PROCESSES(&border_router_process);
|
||||
#elif WEBSERVER>1
|
||||
/* Use an external webserver application */
|
||||
#include "webserver-nogui.h"
|
||||
AUTOSTART_PROCESSES(&border_router_process,&webserver_nogui_process);
|
||||
#else
|
||||
/* 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();
|
||||
}
|
||||
AUTOSTART_PROCESSES(&border_router_process,&webserver_nogui_process);
|
||||
|
||||
static const char *TOP = "<html><head><title>ContikiRPL</title></head><body>\n";
|
||||
static const char *BOTTOM = "</body></html>\n";
|
||||
static char buf[128];
|
||||
|
@ -114,11 +130,11 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
|||
SEND_STRING(&s->sout, TOP);
|
||||
|
||||
blen = 0;
|
||||
ADD("<h2>Neighbors</h2>");
|
||||
ADD("Neighbors<pre>");
|
||||
for(i = 0; i < UIP_DS6_NBR_NB; i++) {
|
||||
if(uip_ds6_nbr_cache[i].isused) {
|
||||
ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr);
|
||||
ADD("<br>\n");
|
||||
ADD("\n");
|
||||
if(blen > sizeof(buf) - 45) {
|
||||
SEND_STRING(&s->sout, buf);
|
||||
blen = 0;
|
||||
|
@ -126,7 +142,7 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
|||
}
|
||||
}
|
||||
|
||||
ADD("<h2>Routes</h2>");
|
||||
ADD("</pre>Routes<pre>");
|
||||
SEND_STRING(&s->sout, buf);
|
||||
blen = 0;
|
||||
for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
|
||||
|
@ -135,18 +151,19 @@ PT_THREAD(generate_routes(struct httpd_state *s))
|
|||
ADD("/%u (via ", uip_ds6_routing_table[i].length);
|
||||
ipaddr_add(&uip_ds6_routing_table[i].nexthop);
|
||||
if(uip_ds6_routing_table[i].state.lifetime < 600) {
|
||||
ADD(") %lus<br>\n", uip_ds6_routing_table[i].state.lifetime);
|
||||
ADD(") %lus\n", uip_ds6_routing_table[i].state.lifetime);
|
||||
} else {
|
||||
ADD(")<br>\n");
|
||||
ADD(")\n");
|
||||
}
|
||||
SEND_STRING(&s->sout, buf);
|
||||
blen = 0;
|
||||
}
|
||||
}
|
||||
if(blen > 0) {
|
||||
ADD("</pre>");
|
||||
//if(blen > 0) {
|
||||
SEND_STRING(&s->sout, buf);
|
||||
blen = 0;
|
||||
}
|
||||
// blen = 0;
|
||||
//}
|
||||
|
||||
SEND_STRING(&s->sout, BOTTOM);
|
||||
|
||||
|
@ -212,10 +229,6 @@ PROCESS_THREAD(border_router_process, ev, data)
|
|||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
#if WEBSERVER
|
||||
process_start(&webserver_nogui_process, NULL);
|
||||
#endif
|
||||
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
PRINTF("RPL-Border router started\n");
|
||||
|
|
|
@ -43,12 +43,11 @@
|
|||
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include "webserver.h"
|
||||
#include "lib/petsciiconv.h"
|
||||
#include "http-strings.h"
|
||||
#include "urlconv.h"
|
||||
//#include "urlconv.h"
|
||||
|
||||
#include "httpd-simple.h"
|
||||
#define webserver_log_file(...)
|
||||
#define webserver_log(...)
|
||||
|
||||
#ifndef WEBSERVER_CONF_CFS_CONNS
|
||||
#define CONNS UIP_CONNS
|
||||
|
@ -90,6 +89,7 @@ PT_THREAD(send_string(struct httpd_state *s, const char *str))
|
|||
PSOCK_END(&s->sout);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const char http_content_type_html[] = "Content-type: text/html\r\n\r\n";
|
||||
static
|
||||
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
|
||||
{
|
||||
|
@ -120,18 +120,17 @@ PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
|
|||
PSOCK_END(&s->sout);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const char http_header_200[] = "HTTP/1.0 200 OK\r\nServer: Contiki/2.4 http://www.sics.se/contiki/\r\nConnection: close\r\n";
|
||||
const char http_header_404[] = "HTTP/1.0 404 Not found\r\nServer: Contiki/2.4 http://www.sics.se/contiki/\r\nConnection: close\r\n";
|
||||
static
|
||||
PT_THREAD(handle_output(struct httpd_state *s))
|
||||
{
|
||||
PT_BEGIN(&s->outputpt);
|
||||
|
||||
s->script = NULL;
|
||||
petsciiconv_topetscii(s->filename, sizeof(s->filename));
|
||||
s->script = httpd_simple_get_script(&s->filename[1]);
|
||||
petsciiconv_toascii(s->filename, sizeof(s->filename));
|
||||
if(s->script == NULL) {
|
||||
strcpy(s->filename, "/notfound.html");
|
||||
petsciiconv_toascii(s->filename, sizeof(s->filename));
|
||||
strncpy(s->filename, "/notfound.html", sizeof(s->filename));
|
||||
PT_WAIT_THREAD(&s->outputpt,
|
||||
send_headers(s, http_header_404));
|
||||
PT_WAIT_THREAD(&s->outputpt,
|
||||
|
@ -149,6 +148,9 @@ PT_THREAD(handle_output(struct httpd_state *s))
|
|||
PT_END(&s->outputpt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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))
|
||||
{
|
||||
|
@ -177,19 +179,18 @@ PT_THREAD(handle_input(struct httpd_state *s))
|
|||
}
|
||||
#endif /* URLCONV */
|
||||
|
||||
petsciiconv_topetscii(s->filename, sizeof(s->filename));
|
||||
webserver_log_file(&uip_conn->ripaddr, s->filename);
|
||||
petsciiconv_toascii(s->filename, sizeof(s->filename));
|
||||
|
||||
s->state = STATE_OUTPUT;
|
||||
|
||||
while(1) {
|
||||
PSOCK_READTO(&s->sin, ISO_nl);
|
||||
|
||||
#if 0
|
||||
if(strncmp(s->inputbuf, http_referer, 8) == 0) {
|
||||
s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
|
||||
petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
|
||||
webserver_log(s->inputbuf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PSOCK_END(&s->sin);
|
||||
|
@ -203,6 +204,7 @@ handle_connection(struct httpd_state *s)
|
|||
handle_output(s);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
httpd_appcall(void *state)
|
||||
|
@ -245,10 +247,12 @@ httpd_appcall(void *state)
|
|||
uip_abort();
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
httpd_init(void)
|
||||
{
|
||||
|
||||
tcp_listen(UIP_HTONS(80));
|
||||
memb_init(&conns);
|
||||
#if URLCONV
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: httpd-simple.h,v 1.1 2010/05/09 12:52:05 nifi Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -43,8 +42,10 @@
|
|||
|
||||
#include "contiki-net.h"
|
||||
|
||||
/* The current internal border router webserver ignores the requested file name */
|
||||
/* and needs no per-connection output buffer, so save some RAM */
|
||||
#ifndef WEBSERVER_CONF_CFS_PATHLEN
|
||||
#define HTTPD_PATHLEN 80
|
||||
#define HTTPD_PATHLEN 2
|
||||
#else /* WEBSERVER_CONF_CFS_CONNS */
|
||||
#define HTTPD_PATHLEN WEBSERVER_CONF_CFS_PATHLEN
|
||||
#endif /* WEBSERVER_CONF_CFS_CONNS */
|
||||
|
@ -56,8 +57,8 @@ struct httpd_state {
|
|||
struct timer timer;
|
||||
struct psock sin, sout;
|
||||
struct pt outputpt;
|
||||
char inputbuf[HTTPD_PATHLEN + 30];
|
||||
char outputbuf[UIP_TCP_MSS];
|
||||
char inputbuf[HTTPD_PATHLEN + 24];
|
||||
/*char outputbuf[UIP_TCP_MSS]; */
|
||||
char filename[HTTPD_PATHLEN];
|
||||
httpd_simple_script_t script;
|
||||
char state;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue