Contiki 3.x
httpd-cgi.c
1 /*
2  * Copyright (c) 2001, Adam Dunkels.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote
14  * products derived from this software without specific prior
15  * written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the uIP TCP/IP stack.
30  *
31  *
32  */
33 /* Line endings in git repository are LF instead of CR-LF ? */
34 /*
35  * This file includes functions that are called by the web server
36  * scripts. The functions takes no argument, and the return value is
37  * interpreted as follows. A zero means that the function did not
38  * complete and should be invoked for the next packet as well. A
39  * non-zero value indicates that the function has completed and that
40  * the web server should move along to the next script line.
41  *
42  */
43 
44 #include <stdio.h>
45 #include <string.h>
46 
47 #include "contiki-net.h"
48 #include "httpd.h"
49 #include "httpd-cgi.h"
50 #include "httpd-fs.h"
51 #include "httpd-fsdata.h"
52 #include "lib/petsciiconv.h"
53 
54 #include "sensors.h"
55 
56 #define DEBUGLOGIC 0 //See httpd.c, if 1 must also set it there!
57 #if DEBUGLOGIC
58 #define uip_mss(...) 512
59 #define uip_appdata TCPBUF
60 extern char TCPBUF[512];
61 #endif
62 
63 /* RADIOSTATS must also be set in clock.c and the radio driver */
64 #if RF230BB
65 #define RADIOSTATS 1
66 #endif
67 
68 static struct httpd_cgi_call *calls = NULL;
69 
70 /*cgi function names*/
71 #if HTTPD_FS_STATISTICS
72 static const char file_name[] HTTPD_STRING_ATTR = "file-stats";
73 #endif
74 static const char tcp_name[] HTTPD_STRING_ATTR = "tcp-connections";
75 static const char proc_name[] HTTPD_STRING_ATTR = "processes";
76 static const char sensor_name[] HTTPD_STRING_ATTR = "sensors";
77 static const char adrs_name[] HTTPD_STRING_ATTR = "addresses";
78 static const char nbrs_name[] HTTPD_STRING_ATTR = "neighbors";
79 static const char rtes_name[] HTTPD_STRING_ATTR = "routes";
80 
81 /*Process states for processes cgi*/
82 static const char closed[] HTTPD_STRING_ATTR = "CLOSED";
83 static const char syn_rcvd[] HTTPD_STRING_ATTR = "SYN-RCVD";
84 static const char syn_sent[] HTTPD_STRING_ATTR = "SYN-SENT";
85 static const char established[] HTTPD_STRING_ATTR = "ESTABLISHED";
86 static const char fin_wait_1[] HTTPD_STRING_ATTR = "FIN-WAIT-1";
87 static const char fin_wait_2[] HTTPD_STRING_ATTR = "FIN-WAIT-2";
88 static const char closing[] HTTPD_STRING_ATTR = "CLOSING";
89 static const char time_wait[] HTTPD_STRING_ATTR = "TIME-WAIT";
90 static const char last_ack[] HTTPD_STRING_ATTR = "LAST-ACK";
91 static const char none[] HTTPD_STRING_ATTR = "NONE";
92 static const char running[] HTTPD_STRING_ATTR = "RUNNING";
93 static const char called[] HTTPD_STRING_ATTR = "CALLED";
94 static const char *states[] = {
95  closed,
96  syn_rcvd,
97  syn_sent,
98  established,
99  fin_wait_1,
100  fin_wait_2,
101  closing,
102  time_wait,
103  last_ack,
104  none,
105  running,
106  called};
107 
108  static char sensor_temperature[12]="Not Enabled";
109  static char sensor_extvoltage[12]="Not Enabled";
110  static unsigned long last_tempupdate,last_extvoltageupdate;
111  extern unsigned long seconds, sleepseconds;
112 #if RADIOSTATS
113  extern unsigned long radioontime;
114  static unsigned long savedradioontime;
115  extern uint8_t RF230_radio_on, rf230_last_rssi;
116  extern uint16_t RF230_sendpackets,RF230_receivepackets,RF230_sendfail,RF230_receivefail;
117 #endif
118 
119 
120 void
121 web_set_temp(char *s)
122 {
123  strcpy(sensor_temperature, s);
124 // printf_P(PSTR("got temp"));
125  last_tempupdate=seconds;
126 }
127 void
128 web_set_voltage(char *s)
129 {
130  strcpy(sensor_extvoltage, s);
131 // printf_P(PSTR("got volts"));
132  last_extvoltageupdate=seconds;
133 }
134 
135 /*---------------------------------------------------------------------------*/
136 static
137 PT_THREAD(nullfunction(struct httpd_state *s, char *ptr))
138 {
139  PSOCK_BEGIN(&s->sout);
140  PSOCK_END(&s->sout);
141 }
142 /*---------------------------------------------------------------------------*/
143 httpd_cgifunction
144 httpd_cgi(char *name)
145 {
146  struct httpd_cgi_call *f;
147 
148  /* Find the matching name in the table, return the function. */
149  for(f = calls; f != NULL; f = f->next) {
150  if(httpd_strncmp(name, f->name, httpd_strlen(f->name)) == 0) {
151  return f->function;
152  }
153  }
154  return nullfunction;
155 }
156 
157 #if HTTPD_FS_STATISTICS
158 static char *thisfilename;
159 /*---------------------------------------------------------------------------*/
160 static unsigned short
161 generate_file_stats(void *arg)
162 {
163  static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "<p class=right><br><br><i>This page has been sent %u times</i></div></body></html>";
164  static const char httpd_cgi_filestat2[] HTTPD_STRING_ATTR = "<tr><td><a href=\"%s\">%s</a></td><td>%d</td>";
165  static const char httpd_cgi_filestat3[] HTTPD_STRING_ATTR = "%5u";
166  char tmp[20];
167  struct httpd_fsdata_file_noconst *f,fram;
168  uint16_t i;
169  unsigned short numprinted;
170 
171  /* Transfer arg from whichever flash that contains the html file to RAM */
172  httpd_fs_cpy(&tmp, (char *)arg, 20);
173 
174  /* Count for this page, with common page footer */
175  if (tmp[0]=='.') {
176  numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat1, httpd_fs_open(thisfilename, 0));
177 
178  /* Count for all files */
179  /* Note buffer will overflow if there are too many files! */
180  } else if (tmp[0]=='*') {
181  i=0;numprinted=0;
182  for(f = (struct httpd_fsdata_file_noconst *)httpd_fs_get_root();
183  f != NULL;
184  f = (struct httpd_fsdata_file_noconst *)fram.next) {
185 
186  /* Get the linked list file entry into RAM from from wherever it is*/
187  httpd_memcpy(&fram,f,sizeof(fram));
188 
189  /* Get the file name from whatever memory it is in */
190  httpd_fs_cpy(&tmp, fram.name, sizeof(tmp));
191 #if HTTPD_FS_STATISTICS==1
192  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, f->count);
193 #elif HTTPD_FS_STATISTICS==2
194  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, httpd_filecount[i]);
195 #endif
196  i++;
197  }
198 
199  /* Count for specified file */
200  } else {
201  numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat3, httpd_fs_open(tmp, 0));
202  }
203 #if DEBUGLOGIC
204  return 0;
205 #endif
206  return numprinted;
207 }
208 /*---------------------------------------------------------------------------*/
209 static
210 PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
211 {
212 
213  PSOCK_BEGIN(&s->sout);
214 
215  thisfilename=&s->filename[0]; //temporary way to pass filename to generate_file_stats
216 
217  PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, (void *) ptr);
218 
219  PSOCK_END(&s->sout);
220 }
221 #endif /*HTTPD_FS_STATISTICS*/
222 /*---------------------------------------------------------------------------*/
223 static unsigned short
224 make_tcp_stats(void *arg)
225 {
226  static const char httpd_cgi_tcpstat1[] HTTPD_STRING_ATTR = "<tr align=\"center\"><td>%d</td><td>";
227  static const char httpd_cgi_tcpstat2[] HTTPD_STRING_ATTR = "-%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n";
228  struct uip_conn *conn;
229  struct httpd_state *s = (struct httpd_state *)arg;
230  char tstate[20];
231  uint16_t numprinted;
232 
233  conn = &uip_conns[s->u.count];
234 
235  numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_tcpstat1, uip_htons(conn->lport));
236  numprinted += httpd_cgi_sprint_ip6(conn->ripaddr, uip_appdata + numprinted);
237  httpd_strcpy(tstate,states[conn->tcpstateflags & UIP_TS_MASK]);
238  numprinted += httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted,
239  httpd_cgi_tcpstat2,
240  uip_htons(conn->rport),
241  tstate,
242  conn->nrtx,
243  conn->timer,
244  (uip_outstanding(conn))? '*':' ',
245  (uip_stopped(conn))? '!':' ');
246 
247  return numprinted;
248 }
249 /*---------------------------------------------------------------------------*/
250 static
251 PT_THREAD(tcp_stats(struct httpd_state *s, char *ptr))
252 {
253 
254  PSOCK_BEGIN(&s->sout);
255 
256  for(s->u.count = 0; s->u.count < UIP_CONNS; ++s->u.count) {
257  if((uip_conns[s->u.count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {
258  PSOCK_GENERATOR_SEND(&s->sout, make_tcp_stats, s);
259  }
260  }
261 
262  PSOCK_END(&s->sout);
263 }
264 /*---------------------------------------------------------------------------*/
265 static unsigned short
266 make_processes(void *p)
267 {
268  static const char httpd_cgi_proc[] HTTPD_STRING_ATTR = "<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n";
269  char name[40],tstate[20];
270 
271  strncpy(name, PROCESS_NAME_STRING((struct process *)p), 40);
272  petsciiconv_toascii(name, 40);
273  httpd_strcpy(tstate,states[9 + ((struct process *)p)->state]);
274  return httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_proc, p, name,
275  *(char *)(&(((struct process *)p)->thread)),
276 
277  tstate);
278 }
279 /*---------------------------------------------------------------------------*/
280 static
281 PT_THREAD(processes(struct httpd_state *s, char *ptr))
282 {
283  PSOCK_BEGIN(&s->sout);
284  for(s->u.ptr = PROCESS_LIST(); s->u.ptr != NULL; s->u.ptr = ((struct process *)s->u.ptr)->next) {
285  PSOCK_GENERATOR_SEND(&s->sout, make_processes, s->u.ptr);
286  }
287  PSOCK_END(&s->sout);
288 }
289 /*---------------------------------------------------------------------------*/
290 static const char httpd_cgi_addrh[] HTTPD_STRING_ATTR = "<code>";
291 static const char httpd_cgi_addrf[] HTTPD_STRING_ATTR = "</code>[Room for %u more]";
292 static const char httpd_cgi_addrb[] HTTPD_STRING_ATTR = "<br>";
293 static const char httpd_cgi_addrn[] HTTPD_STRING_ATTR = "(none)<br>";
294 extern uip_ds6_netif_t uip_ds6_if;
295 
296 static unsigned short
297 make_addresses(void *p)
298 {
299 uint8_t i,j=0;
300 uint16_t numprinted;
301  numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(),httpd_cgi_addrh);
302  for (i=0; i<UIP_DS6_ADDR_NB;i++) {
303  if (uip_ds6_if.addr_list[i].isused) {
304  j++;
305  numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, uip_appdata + numprinted);
306  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrb);
307  }
308  }
309 //if (j==0) numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrn);
310  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf, UIP_DS6_ADDR_NB-j);
311  return numprinted;
312 }
313 /*---------------------------------------------------------------------------*/
314 static
315 PT_THREAD(addresses(struct httpd_state *s, char *ptr))
316 {
317  PSOCK_BEGIN(&s->sout);
318 
319  PSOCK_GENERATOR_SEND(&s->sout, make_addresses, s->u.ptr);
320 
321  PSOCK_END(&s->sout);
322 }
323 /*---------------------------------------------------------------------------*/
324 static unsigned short
325 make_neighbors(void *p)
326 {
327 uint8_t i,j=0;
328 uint16_t numprinted;
329 uip_ds6_nbr_t *nbr;
330 
331  numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(),httpd_cgi_addrh);
332  for(nbr = nbr_table_head(ds6_neighbors);
333  nbr != NULL;
334  nbr = nbr_table_next(ds6_neighbors, nbr)) {
335  j++;
336  numprinted += httpd_cgi_sprint_ip6(nbr->ipaddr, uip_appdata + numprinted);
337  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrb);
338  }
339 //if (j==0) numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrn);
340  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf,NBR_TABLE_MAX_NEIGHBORS-j);
341  return numprinted;
342 }
343 /*---------------------------------------------------------------------------*/
344 static
345 PT_THREAD(neighbors(struct httpd_state *s, char *ptr))
346 {
347  PSOCK_BEGIN(&s->sout);
348 
349  PSOCK_GENERATOR_SEND(&s->sout, make_neighbors, s->u.ptr);
350 
351  PSOCK_END(&s->sout);
352 }
353 /*---------------------------------------------------------------------------*/
354 static unsigned short
355 make_routes(void *p)
356 {
357  static const char httpd_cgi_rtes1[] HTTPD_STRING_ATTR = "(%u (via ";
358  static const char httpd_cgi_rtes2[] HTTPD_STRING_ATTR = ") %lus<br>";
359  static const char httpd_cgi_rtes3[] HTTPD_STRING_ATTR = ")<br>";
360  uint8_t i,j=0;
361  uint16_t numprinted;
362  uip_ds6_route_t *r;
363 
364  numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(),httpd_cgi_addrh);
365  for(r = uip_ds6_route_head();
366  r != NULL;
367  r = uip_ds6_route_next(r)) {
368  j++;
369  numprinted += httpd_cgi_sprint_ip6(r->ipaddr, uip_appdata + numprinted);
370  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtes1, r->length);
371  numprinted += httpd_cgi_sprint_ip6(uip_ds6_route_nexthop(r), uip_appdata + numprinted);
372  if(r->state.lifetime < 3600) {
373  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtes2, r->state.lifetime);
374  } else {
375  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtes3);
376  }
377  }
378  if (j==0) numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrn);
379  numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf,UIP_DS6_ROUTE_NB-j);
380  return numprinted;
381 }
382 /*---------------------------------------------------------------------------*/
383 static
384 PT_THREAD(routes(struct httpd_state *s, char *ptr))
385 {
386  PSOCK_BEGIN(&s->sout);
387 
388  PSOCK_GENERATOR_SEND(&s->sout, make_routes, s->u.ptr);
389 
390  PSOCK_END(&s->sout);
391 }
392 /*---------------------------------------------------------------------------*/
393 static unsigned short
394 generate_sensor_readings(void *arg)
395 {
396  uint16_t numprinted;
397  uint16_t h,m,s;
398  uint8_t p1;
399  static const char httpd_cgi_sensor0[] HTTPD_STRING_ATTR = "[Updated %d seconds ago]<br><br>";
400 // static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "<em>Temperature:</em> %s<br>";
401 // static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "<em>Battery:</em> %s<br>";
402  static const char httpd_cgi_sensr12[] HTTPD_STRING_ATTR = "<em>Temperature:</em> %s <em>Battery:<em> %s<br>";
403  static const char httpd_cgi_sensor3[] HTTPD_STRING_ATTR = "<em>Elapsed timer :</em> %02d:%02d:%02d<br>";
404  static const char httpd_cgi_sensor4[] HTTPD_STRING_ATTR = "<em>Sleeping time :</em> %02d:%02d:%02d (%d%%)<br>";
405 
406  numprinted=0;
407  if (last_tempupdate) {
408  numprinted =httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_sensor0,seconds-last_tempupdate);
409  }
410 
411 // numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor1, sensor_temperature);
412  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensr12, sensor_temperature,sensor_extvoltage);
413 
414 #if 0
415 //Measuring AVcc might be useful to check on battery condition but on ext power it's always 3v3
416  ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference.
417 //ADMUX =0x5E; //Select AVCC as reference, measure 1.1 volt bandgap reference.
418  ADCSRA=0x07; //Enable ADC, not free running, interrupt disabled, clock divider 128 (62 KHz@ 8 MHz)
419  ADCSRA|=1<<ADSC; //Start throwaway conversion
420  while (ADCSRA&(1<<ADSC)); //Wait till done
421  ADCSRA|=1<<ADSC; //Start another conversion
422  while (ADCSRA&(1<<ADSC)); //Wait till done
423  h=1131632UL/ADC; //Get supply voltage
424 #endif
425 
426  // numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor2, sensor_extvoltage);
427 #if RADIOSTATS
428  /* Remember radioontime for display below - slow connection might make it report longer than cpu ontime! */
429  savedradioontime = radioontime;
430 #endif
431  h=seconds/3600;
432  s=seconds-h*3600;
433  m=s/60;
434  s=s-m*60;
435  numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor3, h,m,s);
436  if (sleepseconds) {
437  p1=100UL*sleepseconds/seconds;
438  h=sleepseconds/3600;
439  s=sleepseconds-h*3600;
440  m=s/60;
441  s=s-m*60;
442  numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor4, h,m,s,p1);
443  }
444  return numprinted;
445 }
446 #if RADIOSTATS
447 /*---------------------------------------------------------------------------*/
448 static unsigned short
449 generate_radio_stats(void *arg)
450 {
451  uint16_t numprinted;
452  uint16_t h,m,s;
453  uint8_t p1,p2;
454  static const char httpd_cgi_sensor10[] HTTPD_STRING_ATTR = "<em>Radio on time :</em> %02d:%02d:%02d (%d.%02d%%)<br>";
455  static const char httpd_cgi_sensor11[] HTTPD_STRING_ATTR = "<em>Packets:</em> Tx=%5d Rx=%5d TxL=%5d RxL=%5d RSSI=%2ddBm\n";
456 
457  s=(10000UL*savedradioontime)/seconds;
458  p1=s/100;
459  p2=s-p1*100;
460  h=savedradioontime/3600;
461  s=savedradioontime-h*3600;
462  m=s/60;
463  s=s-m*60;
464 
465  numprinted =httpd_snprintf((char *)uip_appdata , uip_mss() , httpd_cgi_sensor10,\
466  h,m,s,p1,p2);
467 
468 #if RF230BB
469  numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor11,\
470  RF230_sendpackets,RF230_receivepackets,RF230_sendfail,RF230_receivefail,-92+rf230_last_rssi);
471 #else
472  p1=0;
474  p1 = -91*3(p1-1);
475  numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor11,\
476  RF230_sendpackets,RF230_receivepackets,RF230_sendfail,RF230_receivefail,p1);
477 #endif
478 
479  return numprinted;
480 }
481 #endif
482 /*---------------------------------------------------------------------------*/
483 static
484 PT_THREAD(sensor_readings(struct httpd_state *s, char *ptr))
485 {
486  PSOCK_BEGIN(&s->sout);
487 
488  PSOCK_GENERATOR_SEND(&s->sout, generate_sensor_readings, s);
489 #if RADIOSTATS
490  PSOCK_GENERATOR_SEND(&s->sout, generate_radio_stats, s);
491 #endif
492 
493 
494  PSOCK_END(&s->sout);
495 }
496 /*---------------------------------------------------------------------------*/
497 void
498 httpd_cgi_add(struct httpd_cgi_call *c)
499 {
500  struct httpd_cgi_call *l;
501 
502  c->next = NULL;
503  if(calls == NULL) {
504  calls = c;
505  } else {
506  for(l = calls; l->next != NULL; l = l->next);
507  l->next = c;
508  }
509 }
510 /*---------------------------------------------------------------------------*/
511 
512 #if HTTPD_FS_STATISTICS
513 HTTPD_CGI_CALL( file, file_name, file_stats);
514 #endif
515 HTTPD_CGI_CALL( tcp, tcp_name, tcp_stats );
516 HTTPD_CGI_CALL( proc, proc_name, processes );
517 HTTPD_CGI_CALL( adrs, adrs_name, addresses );
518 HTTPD_CGI_CALL( nbrs, nbrs_name, neighbors );
519 HTTPD_CGI_CALL( rtes, rtes_name, routes );
520 HTTPD_CGI_CALL(sensors, sensor_name, sensor_readings);
521 
522 void
523 httpd_cgi_init(void)
524 {
525 #if HTTPD_FS_STATISTICS
526  httpd_cgi_add( &file);
527 #endif
528  httpd_cgi_add( &tcp);
529  httpd_cgi_add( &proc);
530  httpd_cgi_add( &adrs);
531  httpd_cgi_add( &nbrs);
532  httpd_cgi_add( &rtes);
533  httpd_cgi_add(&sensors);
534 }
535 /*---------------------------------------------------------------------------*/
536 
537 uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result)
538  {
539  unsigned char zerocnt = 0;
540  unsigned char numprinted = 0;
541  char * starting = result;
542 
543  unsigned char i = 0;
544 
545  while (numprinted < 8)
546  {
547  //Address is zero, have we used our ability to
548  //replace a bunch with : yet?
549  if ((addr.u16[i] == 0) && (zerocnt == 0))
550  {
551  //How mant zeros?
552  zerocnt = 0;
553  while(addr.u16[zerocnt + i] == 0)
554  zerocnt++;
555 
556  //just one, don't waste our zeros...
557  if (zerocnt == 1)
558  {
559  *result++ = '0';
560  numprinted++;
561  break;
562  }
563 
564  //Cool - can replace a bunch of zeros
565  i += zerocnt;
566  numprinted += zerocnt;
567  }
568  //Normal address, just print it
569  else
570  {
571  result += sprintf(result, "%x", (unsigned int)(uip_ntohs(addr.u16[i])));
572  i++;
573  numprinted++;
574  }
575 
576  //Don't print : on last one
577  if (numprinted != 8)
578  *result++ = ':';
579  }
580 
581  return (result - starting);
582  }
583 
#define UIP_CONNS
The maximum number of simultaneously open TCP connections.
Definition: uipopt.h:419
An entry in the routing table.
radio_status_t radio_get_rssi_value(uint8_t *rssi)
This function returns the Received Signal Strength Indication.
Definition: radio.c:485
#define PSOCK_BEGIN(psock)
Start the protosocket protothread in a function.
Definition: psock.h:164
Representation of a uIP TCP connection.
Definition: uip.h:1336
uint8_t nrtx
The number of retransmissions for the last segment sent.
Definition: uip.h:1359
#define uip_mss()
Get the current maximum segment size that can be sent on the current connection.
Definition: uip.h:838
uint16_t lport
The local TCP port, in network byte order.
Definition: uip.h:1339
#define NULL
The null pointer.
uint8_t timer
The retransmission timer.
Definition: uip.h:1358
#define PT_THREAD(name_args)
Declaration of a protothread.
Definition: pt.h:99
uint16_t rport
The local remote TCP port, in network byte order.
Definition: uip.h:1340
PETSCII/ASCII conversion functions.
#define PSOCK_GENERATOR_SEND(psock, generator, arg)
Generate data with a function and send it.
Definition: psock.h:225
CCIF uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
Definition: uip6.c:2298
#define PSOCK_END(psock)
Declare the end of a protosocket&#39;s protothread.
Definition: psock.h:348
uint8_t tcpstateflags
TCP state and flags.
Definition: uip.h:1357
Interface structure (contains all the interface variables)
Definition: uip-ds6.h:212
#define uip_stopped(conn)
Find out if the current connection has been previously stopped with uip_stop().
Definition: uip.h:700
uip_ipaddr_t ripaddr
The IP address of the remote host.
Definition: uip.h:1337
uip_appdata
Pointer to the application data in the packet buffer.
Definition: tcp_loader.c:74
An entry in the nbr cache.
Definition: uip-ds6-nbr.h:70