47 #include "contiki-net.h"
49 #include "httpd-cgi.h"
54 static struct httpd_cgi_call *calls =
NULL;
56 static const char closed[] =
57 {0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};
58 static const char syn_rcvd[] =
59 {0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56,
61 static const char syn_sent[] =
62 {0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e,
64 static const char established[] =
65 {0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49,
66 0x53, 0x48, 0x45, 0x44, 0};
67 static const char fin_wait_1[] =
68 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
70 static const char fin_wait_2[] =
71 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
73 static const char closing[] =
74 {0x43, 0x4c, 0x4f, 0x53, 0x49,
76 static const char time_wait[] =
77 {0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41,
79 static const char last_ack[] =
80 {0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43,
82 static const char none[] =
83 {0x4e, 0x4f, 0x4e, 0x45, 0};
84 static const char running[] =
85 {0x52, 0x55, 0x4e, 0x4e, 0x49, 0x4e, 0x47,
87 static const char called[] =
88 {0x43, 0x41, 0x4c, 0x4c, 0x45, 0x44, 0};
89 static const char file_name[] =
90 {0x66, 0x69, 0x6c, 0x65, 0x2d, 0x73, 0x74,
92 static const char tcp_name[] =
93 {0x74, 0x63, 0x70, 0x2d, 0x63, 0x6f, 0x6e,
94 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
96 static const char proc_name[] =
97 {0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73,
100 static const char *states[] = {
116 PT_THREAD(nullfunction(
struct httpd_state *s,
char *ptr))
123 httpd_cgi(
char *name)
125 struct httpd_cgi_call *f;
128 for(f = calls; f !=
NULL; f = f->next) {
129 if(strncmp(f->name, name, strlen(f->name)) == 0) {
136 static unsigned short
137 generate_file_stats(
void *arg)
139 char *f = (
char *)arg;
144 PT_THREAD(file_stats(
struct httpd_state *s,
char *ptr))
153 static unsigned short
154 make_tcp_stats(
void *arg)
157 struct httpd_state *s = (
struct httpd_state *)arg;
158 conn = &uip_conns[s->u.count];
162 httpd_sprint_ip6(conn->
ripaddr, buf);
164 "<tr align=\"center\"><td>%d</td><td>%s:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",
171 (uip_outstanding(conn))?
'*':
' ',
175 "<tr align=\"center\"><td>%d</td><td>%u.%u.%u.%u:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",
185 (uip_outstanding(conn))?
'*':
' ',
191 PT_THREAD(tcp_stats(
struct httpd_state *s,
char *ptr))
196 for(s->u.count = 0; s->u.count <
UIP_CONNS; ++s->u.count) {
197 if((uip_conns[s->u.count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {
205 static unsigned short
206 make_processes(
void *p)
210 strncpy(name, PROCESS_NAME_STRING((
struct process *)p), 40);
211 petsciiconv_toascii(name, 40);
214 "<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n",
216 *((
char **)&(((
struct process *)p)->thread)),
217 states[9 + ((
struct process *)p)->state]);
221 PT_THREAD(processes(
struct httpd_state *s,
char *ptr))
224 for(s->u.ptr = PROCESS_LIST(); s->u.ptr !=
NULL; s->u.ptr = ((
struct process *)s->u.ptr)->next) {
229 #if WEBSERVER_CONF_STATUSPAGE && UIP_CONF_IPV6
239 #define HTTPD_STRING_ATTR
240 #define httpd_snprintf snprintf
241 #define httpd_cgi_sprint_ip6 httpd_sprint_ip6
243 static const char httpd_cgi_addrh[] HTTPD_STRING_ATTR =
"<code>";
244 static const char httpd_cgi_addrf[] HTTPD_STRING_ATTR =
"</code>[Room for %u more]";
245 static const char httpd_cgi_addrb[] HTTPD_STRING_ATTR =
"<br>";
246 static const char httpd_cgi_addrn[] HTTPD_STRING_ATTR =
"(none)<br>";
249 static unsigned short
250 make_addresses(
void *p)
255 for (i=0; i<UIP_DS6_ADDR_NB;i++) {
256 if (uip_ds6_if.addr_list[i].isused) {
258 numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,
uip_appdata + numprinted);
259 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_addrb);
263 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_addrf, UIP_DS6_ADDR_NB-j);
268 PT_THREAD(addresses(
struct httpd_state *s,
char *ptr))
277 static unsigned short
278 make_neighbors(
void *p)
284 for(nbr = nbr_table_head(ds6_neighbors);
286 nbr = nbr_table_next(ds6_neighbors, nbr)) {
288 numprinted += httpd_cgi_sprint_ip6(nbr->ipaddr,
uip_appdata + numprinted);
289 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_addrb);
292 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_addrf,NBR_TABLE_MAX_NEIGHBORS-j);
297 PT_THREAD(neighbors(
struct httpd_state *s,
char *ptr))
306 static unsigned short
309 static const char httpd_cgi_rtes1[] HTTPD_STRING_ATTR =
"(%u (via ";
310 static const char httpd_cgi_rtes2[] HTTPD_STRING_ATTR =
") %lus<br>";
311 static const char httpd_cgi_rtes3[] HTTPD_STRING_ATTR =
")<br>";
317 for(r = uip_ds6_route_head();
319 r = uip_ds6_route_next(r)) {
321 numprinted += httpd_cgi_sprint_ip6(r->ipaddr,
uip_appdata + numprinted);
322 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_rtes1, r->length);
323 numprinted += httpd_cgi_sprint_ip6(uip_ds6_route_nexthop(r),
uip_appdata + numprinted);
324 if(r->state.lifetime < 3600) {
325 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_rtes2, r->state.lifetime);
327 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_rtes3);
330 if (j==0) numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_addrn);
331 numprinted += httpd_snprintf((
char *)
uip_appdata+numprinted,
uip_mss()-numprinted, httpd_cgi_addrf,UIP_DS6_ROUTE_NB-j);
336 PT_THREAD(routes(
struct httpd_state *s,
char *ptr))
347 httpd_cgi_add(
struct httpd_cgi_call *c)
349 struct httpd_cgi_call *l;
355 for(l = calls; l->next !=
NULL; l = l->next);
360 #if WEBSERVER_CONF_STATUSPAGE && UIP_CONF_IPV6
361 static const char adrs_name[] HTTPD_STRING_ATTR =
"addresses";
362 static const char nbrs_name[] HTTPD_STRING_ATTR =
"neighbors";
363 static const char rtes_name[] HTTPD_STRING_ATTR =
"routes";
365 HTTPD_CGI_CALL(file, file_name, file_stats);
366 HTTPD_CGI_CALL(tcp, tcp_name, tcp_stats);
367 HTTPD_CGI_CALL(proc, proc_name, processes);
368 #if WEBSERVER_CONF_STATUSPAGE && UIP_CONF_IPV6
369 HTTPD_CGI_CALL(adrs, adrs_name, addresses);
370 HTTPD_CGI_CALL(nbrs, nbrs_name, neighbors);
371 HTTPD_CGI_CALL(rtes, rtes_name, routes);
377 httpd_cgi_add(&file);
379 httpd_cgi_add(&proc);
380 #if WEBSERVER_CONF_STATUSPAGE && UIP_CONF_IPV6
381 httpd_cgi_add(&adrs);
382 httpd_cgi_add(&nbrs);
383 httpd_cgi_add(&rtes);
#define UIP_CONNS
The maximum number of simultaneously open TCP connections.
An entry in the routing table.
#define PSOCK_BEGIN(psock)
Start the protosocket protothread in a function.
Representation of a uIP TCP connection.
uint8_t nrtx
The number of retransmissions for the last segment sent.
#define uip_mss()
Get the current maximum segment size that can be sent on the current connection.
uint16_t lport
The local TCP port, in network byte order.
#define NULL
The null pointer.
uint8_t timer
The retransmission timer.
#define PT_THREAD(name_args)
Declaration of a protothread.
uint16_t rport
The local remote TCP port, in network byte order.
PETSCII/ASCII conversion functions.
#define PSOCK_GENERATOR_SEND(psock, generator, arg)
Generate data with a function and send it.
CCIF uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
#define PSOCK_END(psock)
Declare the end of a protosocket's protothread.
uint8_t tcpstateflags
TCP state and flags.
Interface structure (contains all the interface variables)
#define uip_stopped(conn)
Find out if the current connection has been previously stopped with uip_stop().
uip_ipaddr_t ripaddr
The IP address of the remote host.
uip_appdata
Pointer to the application data in the packet buffer.
An entry in the nbr cache.