├── include ├── arch │ ├── sys_arch.h │ ├── perf.h │ └── cc.h ├── user_config.h ├── lwip │ ├── icmp.h │ ├── netif.h │ ├── tcp_impl.h │ ├── app │ │ ├── ping.h │ │ ├── espconn_tcp.h │ │ ├── espconn_udp.h │ │ └── dhcpserver.h │ ├── init.h │ ├── ip_frag.h │ ├── err.h │ ├── timers.h │ ├── inet_chksum.h │ ├── raw.h │ ├── netifapi.h │ ├── debug.h │ ├── snmp_asn1.h │ ├── memp.h │ ├── igmp.h │ ├── netbuf.h │ ├── inet.h │ ├── def.h │ ├── sio.h │ ├── autoip.h │ ├── netdb.h │ ├── mem.h │ ├── tcpip.h │ ├── dns.h │ ├── memp_std.h │ ├── api_msg.h │ └── pbuf.h ├── mem_manager.h ├── ip_addr.h ├── httpdconfig.h ├── stdint.h ├── netif │ ├── wlan_lwip_if.h │ └── if_llc.h ├── espmissingincludes-ip.h └── espmissingincludes.h ├── user ├── stdout.h ├── io.h ├── httpdespfs.h ├── espfs.h ├── cgi.h ├── cgiwifi.h ├── heatshrink_decoder.c ├── heatshrink_config_httpd.h ├── user_main.c ├── httpd.h ├── io.c ├── stdout.c ├── cgi.c └── httpdespfs.c ├── espfstest ├── espfs.c ├── Makefile ├── heatshrink_decoder.c └── main.c ├── firmware.zip ├── html ├── 32.png ├── off.png ├── on.png ├── wait.gif ├── favicon.ico ├── wifi │ ├── icons.png │ ├── 140medley.min.js │ └── connecting.html ├── js │ ├── jquery.min.js │ └── bootstrap.min.js ├── css │ └── bootstrap.min.css ├── style.css ├── index.tpl └── led.tpl ├── firmware ├── 0x00000.bin ├── 0x40000.bin ├── firmware.zip ├── webpages.espfs └── _temp_by_dltool │ └── 0x00000.bin_rep ├── htmCopy ├── wifi │ ├── icons.png │ ├── connecting.html │ ├── style.css │ ├── 140medley.min.js │ └── wifi.tpl ├── cats │ ├── cross-eyed-cat.jpg │ ├── junge-katze-iv.jpg │ └── kitten-loves-toy.jpg ├── style.css ├── led.tpl └── index.tpl ├── mkespfsimage ├── mkespfsimage.exe ├── heatshrink_encoder.c ├── Makefile ├── espfsformat.h └── main.c ├── .gitignore ├── .gitmodules ├── lib └── heatshrink │ ├── .travis.yml │ ├── heatshrink_common.h │ ├── LICENSE │ ├── heatshrink_config.h │ ├── Makefile │ ├── enc_sm.dot │ ├── README.md │ ├── dec_sm.dot │ ├── heatshrink_encoder.h │ ├── heatshrink_decoder.h │ └── test_heatshrink_static.c ├── README.md ├── READMEO.md └── Makefile /include/arch/sys_arch.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/user_config.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /user/stdout.h: -------------------------------------------------------------------------------- 1 | void stdoutInit(); 2 | -------------------------------------------------------------------------------- /espfstest/espfs.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "../user/espfs.c" 4 | -------------------------------------------------------------------------------- /firmware.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/firmware.zip -------------------------------------------------------------------------------- /html/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/32.png -------------------------------------------------------------------------------- /html/off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/off.png -------------------------------------------------------------------------------- /html/on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/on.png -------------------------------------------------------------------------------- /user/io.h: -------------------------------------------------------------------------------- 1 | void ICACHE_FLASH_ATTR ioLed(int ena); 2 | void ioInit(void); 3 | -------------------------------------------------------------------------------- /html/wait.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/wait.gif -------------------------------------------------------------------------------- /html/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/favicon.ico -------------------------------------------------------------------------------- /firmware/0x00000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/firmware/0x00000.bin -------------------------------------------------------------------------------- /firmware/0x40000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/firmware/0x40000.bin -------------------------------------------------------------------------------- /html/wifi/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/wifi/icons.png -------------------------------------------------------------------------------- /include/lwip/icmp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/include/lwip/icmp.h -------------------------------------------------------------------------------- /include/lwip/netif.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/include/lwip/netif.h -------------------------------------------------------------------------------- /firmware/firmware.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/firmware/firmware.zip -------------------------------------------------------------------------------- /htmCopy/wifi/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/htmCopy/wifi/icons.png -------------------------------------------------------------------------------- /html/js/jquery.min.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/js/jquery.min.js -------------------------------------------------------------------------------- /include/mem_manager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/include/mem_manager.h -------------------------------------------------------------------------------- /firmware/webpages.espfs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/firmware/webpages.espfs -------------------------------------------------------------------------------- /html/js/bootstrap.min.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/js/bootstrap.min.js -------------------------------------------------------------------------------- /include/lwip/tcp_impl.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/include/lwip/tcp_impl.h -------------------------------------------------------------------------------- /html/css/bootstrap.min.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/css/bootstrap.min.css -------------------------------------------------------------------------------- /html/wifi/140medley.min.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/html/wifi/140medley.min.js -------------------------------------------------------------------------------- /include/ip_addr.h: -------------------------------------------------------------------------------- 1 | //Dummy file to keep the file in the SDK from b0rking things up 2 | #include "lwip/ip_addr.h" -------------------------------------------------------------------------------- /mkespfsimage/mkespfsimage.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/mkespfsimage/mkespfsimage.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | mkespfsimage/*.o 3 | mkespfsimage/mkespfsimage 4 | espfstest/*.o 5 | espfstest/espfstest 6 | -------------------------------------------------------------------------------- /htmCopy/cats/cross-eyed-cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/htmCopy/cats/cross-eyed-cat.jpg -------------------------------------------------------------------------------- /htmCopy/cats/junge-katze-iv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/htmCopy/cats/junge-katze-iv.jpg -------------------------------------------------------------------------------- /htmCopy/cats/kitten-loves-toy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/htmCopy/cats/kitten-loves-toy.jpg -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/heatshrink"] 2 | path = lib/heatshrink 3 | url = https://github.com/atomicobject/heatshrink.git 4 | -------------------------------------------------------------------------------- /firmware/_temp_by_dltool/0x00000.bin_rep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOCare/esp8266GUI/HEAD/firmware/_temp_by_dltool/0x00000.bin_rep -------------------------------------------------------------------------------- /mkespfsimage/heatshrink_encoder.c: -------------------------------------------------------------------------------- 1 | //Stupid wraparound include to make sure object file doesn't end up in heatshrink dir 2 | 3 | #include "../lib/heatshrink/heatshrink_encoder.c" 4 | -------------------------------------------------------------------------------- /lib/heatshrink/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - clang 5 | - gcc 6 | 7 | install: make test_heatshrink_dynamic 8 | 9 | script: ./test_heatshrink_dynamic 10 | -------------------------------------------------------------------------------- /htmCopy/wifi/connecting.html: -------------------------------------------------------------------------------- 1 | 2 | Connecting 3 | 4 | 5 | Connecting to AP now... 6 | 7 | 8 | -------------------------------------------------------------------------------- /html/wifi/connecting.html: -------------------------------------------------------------------------------- 1 | 2 | Connecting 3 | 4 | 5 | Connecting to AP now... 6 | 7 | 8 | -------------------------------------------------------------------------------- /include/httpdconfig.h: -------------------------------------------------------------------------------- 1 | 2 | //Define this if you want to be able to use Heatshrink-compressed espfs images. 3 | #define EFS_HEATSHRINK 4 | 5 | //Pos of esp fs in flash 6 | #define ESPFS_POS 0x12000 7 | -------------------------------------------------------------------------------- /mkespfsimage/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CFLAGS=-I../lib/heatshrink -std=gnu99 3 | OBJS=main.o heatshrink_encoder.o 4 | TARGET=mkespfsimage 5 | 6 | $(TARGET): $(OBJS) 7 | $(CC) -o $@ $^ 8 | 9 | clean: 10 | rm -f $(TARGET) $(OBJS) -------------------------------------------------------------------------------- /espfstest/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-I../lib/heatshrink -I../user -I../include -std=gnu99 2 | 3 | espfstest: main.o espfs.o heatshrink_decoder.o 4 | $(CC) -o $@ $^ 5 | 6 | espfs.o: espfs.c ../user/espfs.c 7 | 8 | 9 | clean: 10 | rm -f *.o espfstest 11 | -------------------------------------------------------------------------------- /espfstest/heatshrink_decoder.c: -------------------------------------------------------------------------------- 1 | #include "httpdconfig.h" 2 | #ifdef EFS_HEATSHRINK 3 | //Stupid wrapper so we don't have to move c-files around 4 | //Also loads httpd-specific config. 5 | 6 | #include "../lib/heatshrink/heatshrink_decoder.c" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /user/httpdespfs.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPDESPFS_H 2 | #define HTTPDESPFS_H 3 | 4 | #include "httpd.h" 5 | #include "espfs.h" 6 | 7 | int cgiEspFsHook(HttpdConnData *connData); 8 | int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData); 9 | 10 | #endif -------------------------------------------------------------------------------- /user/espfs.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPFS_H 2 | #define ESPFS_H 3 | 4 | 5 | 6 | typedef struct EspFsFile EspFsFile; 7 | 8 | EspFsFile *espFsOpen(char *fileName); 9 | int espFsRead(EspFsFile *fh, char *buff, int len); 10 | void espFsClose(EspFsFile *fh); 11 | 12 | 13 | #endif -------------------------------------------------------------------------------- /include/stdint.h: -------------------------------------------------------------------------------- 1 | 2 | //Including the system-wide stdint.h messes stuff up... but I don't want to change heatshrink 3 | //not to do it. Including this dummy file fixes it too, tho'. 4 | 5 | #ifndef __ets__ 6 | //Do include stdint for testing builds. 7 | #include_next 8 | #endif -------------------------------------------------------------------------------- /user/cgi.h: -------------------------------------------------------------------------------- 1 | #ifndef CGI_H 2 | #define CGI_H 3 | 4 | #include "httpd.h" 5 | 6 | int cgiLed(HttpdConnData *connData); 7 | void tplLed(HttpdConnData *connData, char *token, void **arg); 8 | int cgiReadFlash(HttpdConnData *connData); 9 | void tplCounter(HttpdConnData *connData, char *token, void **arg); 10 | 11 | #endif -------------------------------------------------------------------------------- /htmCopy/style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | background-color: #404040; 4 | font-family: sans-serif; 5 | } 6 | 7 | #main { 8 | background-color: #d0d0FF; 9 | -moz-border-radius: 5px; 10 | -webkit-border-radius: 5px; 11 | border-radius: 5px; 12 | border: 2px solid #000000; 13 | width: 800px; 14 | margin: 0 auto; 15 | padding: 20px 16 | } 17 | 18 | -------------------------------------------------------------------------------- /html/style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | background-color: #404040; 4 | font-family: sans-serif; 5 | } 6 | 7 | #main { 8 | background-color: #d0d0FF; 9 | -moz-border-radius: 5px; 10 | -webkit-border-radius: 5px; 11 | border-radius: 5px; 12 | border: 2px solid #000000; 13 | width: 800px; 14 | margin: 0 auto; 15 | padding: 20px 16 | } 17 | 18 | -------------------------------------------------------------------------------- /user/cgiwifi.h: -------------------------------------------------------------------------------- 1 | #ifndef CGIWIFI_H 2 | #define CGIWIFI_H 3 | 4 | #include "httpd.h" 5 | 6 | int cgiWiFiScan(HttpdConnData *connData); 7 | void tplWlan(HttpdConnData *connData, char *token, void **arg); 8 | int cgiWiFi(HttpdConnData *connData); 9 | int cgiWiFiConnect(HttpdConnData *connData); 10 | int cgiWifiSetMode(HttpdConnData *connData); 11 | 12 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##esp8266GUI 2 | ========== 3 | 4 | esp8266GUI is a responsive UI created for ESP8266 with the help of bootstrap. [http://getbootstrap.com/] 5 | The actual source code is the work by (esphttpd) sprite_tm at http://git.spritesserver.nl/esphttpd.git/ 6 | 7 | GUI design by @bkrajendra 8 | Website http://www.iocare.in 9 | Email: research@iocare.in 10 | -------------------------------------------------------------------------------- /htmCopy/led.tpl: -------------------------------------------------------------------------------- 1 | Test 2 | 3 | 4 | 5 |
6 |

The LED

7 |

8 | If there's a LED connected to GPIO2, it's now %ledstate%. You can change that using the buttons below. 9 |

10 |
11 | 12 | 13 |
14 |
15 | 16 | -------------------------------------------------------------------------------- /htmCopy/wifi/style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | background-color: #404040; 4 | font-family: sans-serif; 5 | } 6 | 7 | #main { 8 | background-color: #d0d0FF; 9 | -moz-border-radius: 5px; 10 | -webkit-border-radius: 5px; 11 | border-radius: 5px; 12 | border: 2px solid #000000; 13 | width: 800px; 14 | margin: 0 auto; 15 | padding: 20px 16 | } 17 | 18 | .icon { 19 | background-image: url("icons.png"); 20 | background-color: transparent; 21 | width: 32px; 22 | height: 32px; 23 | display: inline-block; 24 | } -------------------------------------------------------------------------------- /user/heatshrink_decoder.c: -------------------------------------------------------------------------------- 1 | #include "httpdconfig.h" 2 | #ifdef EFS_HEATSHRINK 3 | //Stupid wrapper so we don't have to move c-files around 4 | //Also loads httpd-specific config. 5 | 6 | #define _STDLIB_H_ 7 | #define _STRING_H_ 8 | #define _STDDEF_H 9 | #define _STDINT_H 10 | 11 | #include "espmissingincludes.h" 12 | #include "c_types.h" 13 | #include "mem.h" 14 | #include "osapi.h" 15 | #include "heatshrink_config_httpd.h" 16 | #define memset(x,y,z) os_memset(x,y,z) 17 | #define memcpy(x,y,z) os_memcpy(x,y,z) 18 | #include "../lib/heatshrink/heatshrink_decoder.c" 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/heatshrink/heatshrink_common.h: -------------------------------------------------------------------------------- 1 | #ifndef HEATSHRINK_H 2 | #define HEATSHRINK_H 3 | 4 | #define HEATSHRINK_AUTHOR "Scott Vokes " 5 | #define HEATSHRINK_URL "https://github.com/atomicobject/heatshrink" 6 | 7 | /* Version 0.3.1 */ 8 | #define HEATSHRINK_VERSION_MAJOR 0 9 | #define HEATSHRINK_VERSION_MINOR 3 10 | #define HEATSHRINK_VERSION_PATCH 1 11 | 12 | #define HEATSHRINK_MIN_WINDOW_BITS 4 13 | #define HEATSHRINK_MAX_WINDOW_BITS 15 14 | 15 | #define HEATSHRINK_MIN_LOOKAHEAD_BITS 2 16 | 17 | #define HEATSHRINK_LITERAL_MARKER 0x01 18 | #define HEATSHRINK_BACKREF_MARKER 0x00 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/netif/wlan_lwip_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef _WLAN_LWIP_IF_H_ 7 | #define _WLAN_LWIP_IF_H_ 8 | 9 | #define LWIP_IF0_PRIO 28 10 | #define LWIP_IF1_PRIO 29 11 | 12 | enum { 13 | SIG_LWIP_RX = 0, 14 | }; 15 | 16 | struct netif * eagle_lwip_if_alloc(struct ieee80211_conn *conn, const uint8 *macaddr, struct ip_info *info); 17 | struct netif * eagle_lwip_getif(uint8 index); 18 | 19 | #ifndef IOT_SIP_MODE 20 | sint8 ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb); 21 | #else 22 | sint8 ieee80211_output_pbuf(struct ieee80211_conn *conn, esf_buf *eb); 23 | #endif 24 | 25 | #endif /* _WLAN_LWIP_IF_H_ */ 26 | -------------------------------------------------------------------------------- /include/espmissingincludes-ip.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPMISSINGINCLUDES_IP_H 2 | #define ESPMISSINGINCLUDES_IP_H 3 | 4 | //Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere. 5 | //MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler. 6 | 7 | struct station_info *wifi_softap_get_station_info(); 8 | bool wifi_softap_set_station_info(uint8_t *addr, struct ip_addr *adr); 9 | int igmp_leavegroup(ip_addr_t *host_ip, ip_addr_t *multicast_ip); 10 | int igmp_joingroup(ip_addr_t *host_ip, ip_addr_t *multicast_ip); 11 | void system_station_got_ip_set(ip_addr_t * ip_addr, ip_addr_t *sn_mask, ip_addr_t *gw_addr); 12 | bool wifi_get_ip_info(uint8 if_index, struct ip_info *info); 13 | #endif 14 | -------------------------------------------------------------------------------- /htmCopy/wifi/140medley.min.js: -------------------------------------------------------------------------------- 1 | var t=function(a,b){return function(c,d){return a.replace(/#{([^}]*)}/g,function(a,f){return Function("x","with(x)return "+f).call(c,d||b||{})})}},s=function(a,b){return b?{get:function(c){return a[c]&&b.parse(a[c])},set:function(c,d){a[c]=b.stringify(d)}}:{}}(this.localStorage||{},JSON),p=function(a,b,c,d){c=c||document;d=c[b="on"+b];a=c[b]=function(e){d=d&&d(e=e||c.event);return(a=a&&b(e))?b:d};c=this},m=function(a,b,c){b=document;c=b.createElement("p");c.innerHTML=a;for(a=b.createDocumentFragment();b= 2 | c.firstChild;)a.appendChild(b);return a},$=function(a,b){a=a.match(/^(\W)?(.*)/);return(b||document)["getElement"+(a[1]?a[1]=="#"?"ById":"sByClassName":"sByTagName")](a[2])},j=function(a){for(a=0;a<4;a++)try{return a?new ActiveXObject([,"Msxml2","Msxml3","Microsoft"][a]+".XMLHTTP"):new XMLHttpRequest}catch(b){}}; 3 | -------------------------------------------------------------------------------- /include/lwip/app/ping.h: -------------------------------------------------------------------------------- 1 | #ifndef __PING_H__ 2 | #define __PING_H__ 3 | #include "lwip/ip_addr.h" 4 | #include "lwip/icmp.h" 5 | /** 6 | * PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used 7 | */ 8 | #ifndef PING_USE_SOCKETS 9 | #define PING_USE_SOCKETS LWIP_SOCKET 10 | #endif 11 | 12 | 13 | void ping_init(void)ICACHE_FLASH_ATTR; 14 | void inline set_ping_length(u16_t ping_length)ICACHE_FLASH_ATTR; 15 | u16_t inline get_ping_length()ICACHE_FLASH_ATTR; 16 | 17 | #if !PING_USE_SOCKETS 18 | void ping_send_now(void)ICACHE_FLASH_ATTR; 19 | #endif /* !PING_USE_SOCKETS */ 20 | 21 | #ifdef SSC 22 | void ping_set_target(ip_addr_t *ip)ICACHE_FLASH_ATTR; 23 | void ping_set_recv_cb(void (*ping_recv_cb)(struct pbuf *p, struct icmp_echo_hdr *iecho))ICACHE_FLASH_ATTR; 24 | #endif /* SSC */ 25 | 26 | #endif /* __PING_H__ */ 27 | -------------------------------------------------------------------------------- /lib/heatshrink/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Scott Vokes 2 | All rights reserved. 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /lib/heatshrink/heatshrink_config.h: -------------------------------------------------------------------------------- 1 | #ifndef HEATSHRINK_CONFIG_H 2 | #define HEATSHRINK_CONFIG_H 3 | 4 | /* Should functionality assuming dynamic allocation be used? */ 5 | #define HEATSHRINK_DYNAMIC_ALLOC 1 6 | 7 | #if HEATSHRINK_DYNAMIC_ALLOC 8 | /* Optional replacement of malloc/free */ 9 | #define HEATSHRINK_MALLOC(SZ) malloc(SZ) 10 | #define HEATSHRINK_FREE(P, SZ) free(P) 11 | #else 12 | /* Required parameters for static configuration */ 13 | #define HEATSHRINK_STATIC_INPUT_BUFFER_SIZE 32 14 | #define HEATSHRINK_STATIC_WINDOW_BITS 8 15 | #define HEATSHRINK_STATIC_LOOKAHEAD_BITS 4 16 | #endif 17 | 18 | /* Turn on logging for debugging. */ 19 | #define HEATSHRINK_DEBUGGING_LOGS 0 20 | 21 | /* Use indexing for faster compression. (This requires additional space.) */ 22 | #define HEATSHRINK_USE_INDEX 1 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /user/heatshrink_config_httpd.h: -------------------------------------------------------------------------------- 1 | //Heatshrink config for the decompressor. 2 | #ifndef HEATSHRINK_CONFIG_H 3 | #define HEATSHRINK_CONFIG_H 4 | 5 | /* Should functionality assuming dynamic allocation be used? */ 6 | #define HEATSHRINK_DYNAMIC_ALLOC 1 7 | 8 | #if HEATSHRINK_DYNAMIC_ALLOC 9 | /* Optional replacement of malloc/free */ 10 | #define HEATSHRINK_MALLOC(SZ) os_malloc(SZ) 11 | #define HEATSHRINK_FREE(P, SZ) os_free(P) 12 | #else 13 | /* Required parameters for static configuration */ 14 | #define HEATSHRINK_STATIC_INPUT_BUFFER_SIZE 32 15 | #define HEATSHRINK_STATIC_WINDOW_BITS 8 16 | #define HEATSHRINK_STATIC_LOOKAHEAD_BITS 4 17 | #endif 18 | 19 | /* Turn on logging for debugging. */ 20 | #define HEATSHRINK_DEBUGGING_LOGS 0 21 | 22 | /* Use indexing for faster compression. (This requires additional space.) */ 23 | #define HEATSHRINK_USE_INDEX 1 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /htmCopy/index.tpl: -------------------------------------------------------------------------------- 1 | 2 | Esp8266 web server 3 | 4 | 5 | 6 |
7 |

It Works

8 |

9 | If you see this, it means the tiny li'l website in your ESP8266 does actually work. Fyi, this page has 10 | been loaded %counter% times. 11 |

    12 |
  • If you haven't connected this device to your WLAN network now, you can do so.
  • 13 |
  • You can also control the LED.
  • 14 |
  • You can download the raw contents of the SPI flash rom
  • 15 |
  • And because I can, here's a link to my website
16 | 17 |

18 | 19 |

And because we're on the Internets now, here are the required pictures of cats:
20 |
21 |
22 |
23 |

24 |
25 | 26 | -------------------------------------------------------------------------------- /mkespfsimage/espfsformat.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPROFSFORMAT_H 2 | #define ESPROFSFORMAT_H 3 | 4 | /* 5 | Stupid cpio-like tool to make read-only 'filesystems' that live on the flash SPI chip of the module. 6 | Can (will) use lzf compression (when I come around to it) to make shit quicker. Aligns names, files, 7 | headers on 4-byte boundaries so the SPI abstraction hardware in the ESP8266 doesn't crap on itself 8 | when trying to do a <4byte or unaligned read. 9 | */ 10 | 11 | /* 12 | The idea 'borrows' from cpio: it's basically a concatenation of {header, filename, file} data. 13 | Header, filename and file data is 32-bit aligned. The last file is indicated by data-less header 14 | with the FLAG_LASTFILE flag set. 15 | */ 16 | 17 | 18 | #define FLAG_LASTFILE (1<<0) 19 | #define COMPRESS_NONE 0 20 | #define COMPRESS_HEATSHRINK 1 21 | 22 | typedef struct { 23 | int32_t magic; 24 | int8_t flags; 25 | int8_t compression; 26 | int16_t nameLen; 27 | int32_t fileLenComp; 28 | int32_t fileLenDecomp; 29 | } __attribute__((packed)) EspFsHeader; 30 | 31 | #endif -------------------------------------------------------------------------------- /espfstest/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Simple and stupid file decompressor for an espfs image. Mostly used as a testbed for espfs.c and 3 | the decompressors: code compiled natively is way easier to debug using gdb et all :) 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include "espfs.h" 16 | 17 | char *espFsData; 18 | 19 | int main(int argc, char **argv) { 20 | int f, out; 21 | int len; 22 | char buff[128]; 23 | EspFsFile *ef; 24 | off_t size; 25 | 26 | if (argc!=3) { 27 | printf("Usage: %s espfs-image file\nExpands file from the espfs-image archive.\n", argv[0]); 28 | exit(0); 29 | } 30 | 31 | f=open(argv[1], O_RDONLY); 32 | if (f<=0) { 33 | perror(argv[1]); 34 | exit(1); 35 | } 36 | size=lseek(f, 0, SEEK_END); 37 | espFsData=mmap(NULL, size, PROT_READ, MAP_SHARED, f, 0); 38 | if (espFsData==MAP_FAILED) { 39 | perror("mmap"); 40 | exit(1); 41 | } 42 | 43 | ef=espFsOpen(argv[2]); 44 | if (ef==NULL) { 45 | printf("Couldn't find %s in image.\n", argv[2]); 46 | exit(1); 47 | } 48 | 49 | out=open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0644); 50 | if (out<=0) { 51 | perror(argv[2]); 52 | exit(1); 53 | } 54 | 55 | while ((len=espFsRead(ef, buff, 128))!=0) { 56 | write(out, buff, len); 57 | } 58 | espFsClose(ef); 59 | //munmap, close, ... I can't be bothered. 60 | } 61 | -------------------------------------------------------------------------------- /lib/heatshrink/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT = heatshrink 2 | #OPTIMIZE = -O0 3 | #OPTIMIZE = -Os 4 | OPTIMIZE = -O3 5 | WARN = -Wall -Wextra -pedantic #-Werror 6 | CFLAGS += -std=c99 -g ${WARN} ${OPTIMIZE} 7 | CFLAGS += -Wmissing-prototypes 8 | CFLAGS += -Wstrict-prototypes 9 | CFLAGS += -Wmissing-declarations 10 | 11 | # If libtheft is available, build additional property-based tests. 12 | # Uncomment these to use it in test_heatshrink_dynamic. 13 | #CFLAGS += -DHEATSHRINK_HAS_THEFT 14 | #LDFLAGS += -ltheft 15 | 16 | all: 17 | @echo "For tests, make test_heatshrink_dynamic (default) or change the" 18 | @echo "config.h to disable static memory and build test_heatshrink_static." 19 | @echo "For the standalone command-line tool, make heatshrink." 20 | 21 | ${PROJECT}: heatshrink.c 22 | 23 | OBJS= heatshrink_encoder.o \ 24 | heatshrink_decoder.o \ 25 | 26 | heatshrink: ${OBJS} 27 | test_heatshrink_dynamic: ${OBJS} test_heatshrink_dynamic_theft.o 28 | test_heatshrink_static: ${OBJS} 29 | 30 | *.o: Makefile heatshrink_config.h 31 | 32 | heatshrink_decoder.o: heatshrink_decoder.h heatshrink_common.h 33 | heatshrink_encoder.o: heatshrink_encoder.h heatshrink_common.h 34 | 35 | tags: TAGS 36 | 37 | TAGS: 38 | etags *.[ch] 39 | 40 | diagrams: dec_sm.png enc_sm.png 41 | 42 | dec_sm.png: dec_sm.dot 43 | dot -o $@ -Tpng $< 44 | 45 | enc_sm.png: enc_sm.dot 46 | dot -o $@ -Tpng $< 47 | 48 | clean: 49 | rm -f ${PROJECT} test_heatshrink_{dynamic,static} *.o *.core {dec,enc}_sm.png TAGS 50 | -------------------------------------------------------------------------------- /user/user_main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * ---------------------------------------------------------------------------- 5 | * "THE BEER-WARE LICENSE" (Revision 42): 6 | * Jeroen Domburg wrote this file. As long as you retain 7 | * this notice you can do whatever you want with this stuff. If we meet some day, 8 | * and you think this stuff is worth it, you can buy me a beer in return. 9 | * ---------------------------------------------------------------------------- 10 | */ 11 | 12 | 13 | #include "espmissingincludes.h" 14 | #include "ets_sys.h" 15 | #include "osapi.h" 16 | #include "httpd.h" 17 | #include "io.h" 18 | #include "httpdespfs.h" 19 | #include "cgi.h" 20 | #include "cgiwifi.h" 21 | #include "stdout.h" 22 | 23 | HttpdBuiltInUrl builtInUrls[]={ 24 | {"/", cgiRedirect, "/index.tpl"}, 25 | {"/flash.bin", cgiReadFlash, NULL}, 26 | {"/led.tpl", cgiEspFsTemplate, tplLed}, 27 | {"/index.tpl", cgiEspFsTemplate, tplCounter}, 28 | {"/led.cgi", cgiLed, NULL}, 29 | 30 | //Routines to make the /wifi URL and everything beneath it work. 31 | {"/wifi", cgiRedirect, "/wifi/wifi.tpl"}, 32 | {"/wifi/", cgiRedirect, "/wifi/wifi.tpl"}, 33 | {"/wifi/wifiscan.cgi", cgiWiFiScan, NULL}, 34 | {"/wifi/wifi.tpl", cgiEspFsTemplate, tplWlan}, 35 | {"/wifi/connect.cgi", cgiWiFiConnect, NULL}, 36 | {"/wifi/setmode.cgi", cgiWifiSetMode, NULL}, 37 | 38 | 39 | {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem 40 | {NULL, NULL, NULL} 41 | }; 42 | 43 | 44 | void user_init(void) { 45 | stdoutInit(); 46 | ioInit(); 47 | httpdInit(builtInUrls, 80); 48 | os_printf("\nReady\n"); 49 | } 50 | -------------------------------------------------------------------------------- /user/httpd.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPD_H 2 | #define HTTPD_H 3 | #include 4 | #include "lwip/ip_addr.h" 5 | #include 6 | 7 | #define HTTPDVER "0.2" 8 | 9 | #define HTTPD_CGI_MORE 0 10 | #define HTTPD_CGI_DONE 1 11 | #define HTTPD_CGI_NOTFOUND 2 12 | 13 | typedef struct HttpdPriv HttpdPriv; 14 | typedef struct HttpdConnData HttpdConnData; 15 | 16 | typedef int (* cgiSendCallback)(HttpdConnData *connData); 17 | 18 | //A struct describing a http connection. This gets passed to cgi functions. 19 | struct HttpdConnData { 20 | struct espconn *conn; 21 | char *url; 22 | char *getArgs; 23 | const void *cgiArg; 24 | void *cgiData; 25 | HttpdPriv *priv; 26 | cgiSendCallback cgi; 27 | int postLen; 28 | char *postBuff; 29 | }; 30 | 31 | //A struct describing an url. This is the main struct that's used to send different URL requests to 32 | //different routines. 33 | typedef struct { 34 | const char *url; 35 | cgiSendCallback cgiCb; 36 | const void *cgiArg; 37 | } HttpdBuiltInUrl; 38 | 39 | int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData); 40 | void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl); 41 | int httpdUrlDecode(char *val, int valLen, char *ret, int retLen); 42 | int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen); 43 | void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port); 44 | const char *httpdGetMimetype(char *url); 45 | void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code); 46 | void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val); 47 | void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn); 48 | 49 | #endif -------------------------------------------------------------------------------- /user/io.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * ---------------------------------------------------------------------------- 4 | * "THE BEER-WARE LICENSE" (Revision 42): 5 | * Jeroen Domburg wrote this file. As long as you retain 6 | * this notice you can do whatever you want with this stuff. If we meet some day, 7 | * and you think this stuff is worth it, you can buy me a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | 12 | #include "espmissingincludes.h" 13 | #include "c_types.h" 14 | #include "user_interface.h" 15 | #include "espconn.h" 16 | #include "mem.h" 17 | #include "osapi.h" 18 | #include "gpio.h" 19 | 20 | 21 | #define LEDGPIO 2 22 | #define BTNGPIO 0 23 | 24 | static ETSTimer resetBtntimer; 25 | 26 | void ICACHE_FLASH_ATTR ioLed(int ena) { 27 | //gpio_output_set is overkill. ToDo: use better mactos 28 | if (ena) { 29 | gpio_output_set((1<=6) { //3 sec pressed 41 | wifi_station_disconnect(); 42 | wifi_set_opmode(0x3); //reset to AP+STA mode 43 | os_printf("Reset to AP mode. Restarting system...\n"); 44 | system_restart(); 45 | } 46 | resetCnt=0; 47 | } 48 | } 49 | 50 | void ioInit() { 51 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); 52 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); 53 | gpio_output_set(0, 0, (1< wrote this file. As long as you retain 7 | * this notice you can do whatever you want with this stuff. If we meet some day, 8 | * and you think this stuff is worth it, you can buy me a beer in return. 9 | * ---------------------------------------------------------------------------- 10 | */ 11 | 12 | 13 | #include "espmissingincludes.h" 14 | #include "ets_sys.h" 15 | #include "osapi.h" 16 | #include "uart_hw.h" 17 | 18 | static void ICACHE_FLASH_ATTR stdoutUartTxd(char c) { 19 | //Wait until there is room in the FIFO 20 | while (((READ_PERI_REG(UART_STATUS(0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=126) ; 21 | //Send the character 22 | WRITE_PERI_REG(UART_FIFO(0), c); 23 | } 24 | 25 | static void ICACHE_FLASH_ATTR stdoutPutchar(char c) { 26 | //convert \n -> \r\n 27 | if (c=='\n') stdoutUartTxd('\r'); 28 | stdoutUartTxd(c); 29 | } 30 | 31 | 32 | void stdoutInit() { 33 | //Enable TxD pin 34 | PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); 35 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); 36 | 37 | //Set baud rate and other serial parameters to 115200,n,8,1 38 | uart_div_modify(0, UART_CLK_FREQ/BIT_RATE_115200); 39 | WRITE_PERI_REG(UART_CONF0(0), (STICK_PARITY_DIS)|(ONE_STOP_BIT << UART_STOP_BIT_NUM_S)| \ 40 | (EIGHT_BITS << UART_BIT_NUM_S)); 41 | 42 | //Reset tx & rx fifo 43 | SET_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST|UART_TXFIFO_RST); 44 | CLEAR_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST|UART_TXFIFO_RST); 45 | //Clear pending interrupts 46 | WRITE_PERI_REG(UART_INT_CLR(0), 0xffff); 47 | 48 | //Install our own putchar handler 49 | os_install_putc1((void *)stdoutPutchar); 50 | } -------------------------------------------------------------------------------- /include/espmissingincludes.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPMISSINGINCLUDES_H 2 | #define ESPMISSINGINCLUDES_H 3 | 4 | #include 5 | #include 6 | 7 | //Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere. 8 | //MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler. 9 | typedef struct espconn espconn; 10 | 11 | int atoi(const char *nptr); 12 | void ets_install_putc1(void *routine); 13 | void ets_isr_attach(int intr, void *handler, void *arg); 14 | void ets_isr_mask(unsigned intr); 15 | void ets_isr_unmask(unsigned intr); 16 | int ets_memcmp(const void *s1, const void *s2, size_t n); 17 | void *ets_memcpy(void *dest, const void *src, size_t n); 18 | void *ets_memset(void *s, int c, size_t n); 19 | int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); 20 | int ets_str2macaddr(void *, void *); 21 | int ets_strcmp(const char *s1, const char *s2); 22 | char *ets_strcpy(char *dest, const char *src); 23 | size_t ets_strlen(const char *s); 24 | int ets_strncmp(const char *s1, const char *s2, int len); 25 | char *ets_strncpy(char *dest, const char *src, size_t n); 26 | char *ets_strstr(const char *haystack, const char *needle); 27 | void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer); 28 | void ets_timer_disarm(ETSTimer *a); 29 | void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg); 30 | int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 31 | int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4))); 32 | void pvPortFree(void *ptr); 33 | void *pvPortMalloc(size_t xWantedSize); 34 | void *pvPortZalloc(size_t); 35 | void uart_div_modify(int no, unsigned int freq); 36 | void vPortFree(void *ptr); 37 | void *vPortMalloc(size_t xWantedSize); 38 | uint8 wifi_get_opmode(void); 39 | uint32 system_get_time(); 40 | int os_random(); 41 | int rand(void); 42 | void ets_bzero(void *s, size_t n); 43 | #endif 44 | -------------------------------------------------------------------------------- /include/lwip/app/espconn_tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ESPCONN_TCP_H__ 2 | #define __ESPCONN_TCP_H__ 3 | 4 | #ifndef ESPCONN_TCP_DEBUG 5 | #define ESPCONN_TCP_DEBUG LWIP_DBG_OFF 6 | #endif 7 | #include "lwip/app/espconn.h" 8 | 9 | #ifndef ESPCONN_TCP_TIMER 10 | #define ESPCONN_TCP_TIMER 40 11 | #endif 12 | 13 | /****************************************************************************** 14 | * FunctionName : espconn_tcp_disconnect 15 | * Description : A new incoming connection has been disconnected. 16 | * Parameters : espconn -- the espconn used to disconnect with host 17 | * Returns : none 18 | *******************************************************************************/ 19 | 20 | extern void espconn_tcp_disconnect(espconn_msg *pdiscon); 21 | 22 | /****************************************************************************** 23 | * FunctionName : espconn_tcp_client 24 | * Description : Initialize the client: set up a connect PCB and bind it to 25 | * the defined port 26 | * Parameters : espconn -- the espconn used to build client 27 | * Returns : none 28 | *******************************************************************************/ 29 | 30 | extern sint8 espconn_tcp_client(struct espconn* espconn); 31 | 32 | /****************************************************************************** 33 | * FunctionName : espconn_tcp_server 34 | * Description : Initialize the server: set up a listening PCB and bind it to 35 | * the defined port 36 | * Parameters : espconn -- the espconn used to build server 37 | * Returns : none 38 | *******************************************************************************/ 39 | 40 | extern sint8 espconn_tcp_server(struct espconn *espconn); 41 | 42 | void ICACHE_FLASH_ATTR 43 | espconn_tcp_sent(void *arg, uint8 *psent, uint16 length); 44 | 45 | sint8 ICACHE_FLASH_ATTR espconn_tcp_delete(struct espconn *pdeletecon); 46 | 47 | 48 | #endif /* __CLIENT_TCP_H__ */ 49 | 50 | -------------------------------------------------------------------------------- /include/arch/perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001, Swedish Institute of Computer Science. 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. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | */ 34 | #ifndef __PERF_H__ 35 | #define __PERF_H__ 36 | 37 | #define PERF_START /* null definition */ 38 | #define PERF_STOP(x) /* null definition */ 39 | 40 | #endif /* __PERF_H__ */ 41 | -------------------------------------------------------------------------------- /include/lwip/app/espconn_udp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ESPCONN_UDP_H__ 2 | #define __ESPCONN_UDP_H__ 3 | 4 | #ifndef ESPCONN_UDP_DEBUG 5 | #define ESPCONN_UDP_DEBUG LWIP_DBG_OFF 6 | #endif 7 | 8 | #include "lwip/app/espconn.h" 9 | 10 | /****************************************************************************** 11 | * FunctionName : espconn_udp_client 12 | * Description : Initialize the client: set up a PCB and bind it to the port 13 | * Parameters : pespconn -- the espconn used to build client 14 | * Returns : none 15 | *******************************************************************************/ 16 | 17 | extern sint8 espconn_udp_client(struct espconn *pespconn); 18 | 19 | /****************************************************************************** 20 | * FunctionName : espconn_udp_disconnect 21 | * Description : A new incoming connection has been disconnected. 22 | * Parameters : espconn -- the espconn used to disconnect with host 23 | * Returns : none 24 | *******************************************************************************/ 25 | 26 | extern void espconn_udp_disconnect(espconn_msg *pdiscon); 27 | 28 | /****************************************************************************** 29 | * FunctionName : espconn_udp_server 30 | * Description : Initialize the server: set up a PCB and bind it to the port 31 | * Parameters : pespconn -- the espconn used to build server 32 | * Returns : none 33 | *******************************************************************************/ 34 | 35 | extern sint8 espconn_udp_server(struct espconn *espconn); 36 | 37 | /****************************************************************************** 38 | * FunctionName : espconn_udp_sent 39 | * Description : sent data for client or server 40 | * Parameters : void *arg -- client or server to send 41 | * uint8* psent -- Data to send 42 | * uint16 length -- Length of data to send 43 | * Returns : none 44 | *******************************************************************************/ 45 | 46 | extern void espconn_udp_sent(void *arg, uint8 *psent, uint16 length); 47 | 48 | 49 | #endif /* __ESPCONN_UDP_H__ */ 50 | 51 | 52 | -------------------------------------------------------------------------------- /lib/heatshrink/enc_sm.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | graph [label="Encoder state machine", labelloc="t"] 3 | start [style="invis", shape="point"] 4 | not_full 5 | filled 6 | search 7 | yield_tag_bit 8 | yield_literal 9 | yield_br_length 10 | yield_br_index 11 | save_backlog 12 | flush_bits 13 | done [peripheries=2] 14 | 15 | start->not_full [label="start"] 16 | 17 | not_full->not_full [label="sink(), not full", color="blue"] 18 | not_full->filled [label="sink(), buffer is full", color="blue"] 19 | not_full->filled [label="finish(), set is_finished", color="blue"] 20 | 21 | filled->search [label="indexing (if any)"] 22 | 23 | search->search [label="step"] 24 | search->yield_tag_bit [label="literal"] 25 | search->yield_tag_bit [label="match found"] 26 | search->save_backlog [label="input exhausted"] 27 | 28 | yield_tag_bit->yield_tag_bit [label="poll(), full buf", color="red"] 29 | yield_tag_bit->yield_literal [label="poll(), literal", color="red"] 30 | yield_tag_bit->yield_br_index [label="poll(), no literal", color="red"] 31 | yield_tag_bit->flush_bits [label="finishing, no literal"] 32 | 33 | yield_literal->yield_literal [label="poll(), full buf", color="red"] 34 | yield_literal->search [label="poll(), no match", color="red"] 35 | yield_literal->yield_tag_bit [label="poll(), match", color="red"] 36 | yield_literal->flush_bits [label="poll(), final literal", color="red"] 37 | 38 | yield_br_index->yield_br_index [label="poll(), full buf", color="red"] 39 | yield_br_index->yield_br_length [label="poll()", color="red"] 40 | 41 | yield_br_length->yield_br_length [label="poll(), full buf", color="red"] 42 | yield_br_length->search [label="done"] 43 | 44 | save_backlog->flush_bits [label="finishing, no literal"] 45 | save_backlog->yield_tag_bit [label="finishing, literal"] 46 | save_backlog->not_full [label="expect more input"] 47 | 48 | flush_bits->flush_bits [label="poll(), full buf", color="red"] 49 | flush_bits->done [label="poll(), flushed", color="red"] 50 | flush_bits->done [label="no more output"] 51 | } 52 | -------------------------------------------------------------------------------- /lib/heatshrink/README.md: -------------------------------------------------------------------------------- 1 | # heatshrink 2 | 3 | A data compression/decompression library for embedded/real-time systems. 4 | 5 | ## Key Features: 6 | 7 | - **Low memory usage (as low as 50 bytes)** 8 | It is useful for some cases with less than 50 bytes, and useful 9 | for many general cases with < 300 bytes. 10 | - **Incremental, bounded CPU use** 11 | You can chew on input data in arbitrarily tiny bites. 12 | This is a useful property in hard real-time environments. 13 | - **Can use either static or dynamic memory allocation** 14 | The library doesn't impose any constraints on memory management. 15 | - **ISC license** 16 | You can use it freely, even for commercial purposes. 17 | 18 | ## Getting Started: 19 | 20 | There is a standalone command-line program, `heatshrink`, but the 21 | encoder and decoder can also be used as libraries, independent of each 22 | other. To do so, copy `heatshrink_common.h`, `heatshrink_config.h`, and 23 | either `heatshrink_encoder.c` or `heatshrink_decoder.c` (and their 24 | respective header) into your project. 25 | 26 | Dynamic allocation is used by default, but in an embedded context, you 27 | probably want to statically allocate the encoder/decoder. Set 28 | `HEATSHRINK_DYNAMIC_ALLOC` to 0 in `heatshrink_config.h`. 29 | 30 | ## More Information and Benchmarks: 31 | 32 | heatshrink is based on [LZSS], since it's particularly suitable for 33 | compression in small amounts of memory. It can use an optional, small 34 | [index] to make compression significantly faster, but otherwise can run 35 | in under 100 bytes of memory. The index currently adds 2^(window size+1) 36 | bytes to memory usage for compression, and temporarily allocates 512 37 | bytes on the stack during index construction. 38 | 39 | For more information, see the [blog post] for an overview, and the 40 | `heatshrink_encoder.h` / `heatshrink_decoder.h` header files for API 41 | documentation. 42 | 43 | [blog post]: http://spin.atomicobject.com/2013/03/14/heatshrink-embedded-data-compression/ 44 | [index]: http://spin.atomicobject.com/2014/01/13/lightweight-indexing-for-embedded-systems/ 45 | [LZSS]: http://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski 46 | 47 | ## Build Status 48 | 49 | [![Build Status](https://travis-ci.org/atomicobject/heatshrink.png)](http://travis-ci.org/atomicobject/heatshrink) 50 | -------------------------------------------------------------------------------- /include/lwip/app/dhcpserver.h: -------------------------------------------------------------------------------- 1 | #ifndef __DHCPS_H__ 2 | #define __DHCPS_H__ 3 | 4 | typedef struct dhcps_state{ 5 | sint16_t state; 6 | } dhcps_state; 7 | 8 | // ����dhcpclient�Զ����һ��DHCP msg�ṹ�� 9 | typedef struct dhcps_msg { 10 | uint8_t op, htype, hlen, hops; 11 | uint8_t xid[4]; 12 | uint16_t secs, flags; 13 | uint8_t ciaddr[4]; 14 | uint8_t yiaddr[4]; 15 | uint8_t siaddr[4]; 16 | uint8_t giaddr[4]; 17 | uint8_t chaddr[16]; 18 | uint8_t sname[64]; 19 | uint8_t file[128]; 20 | uint8_t options[312]; 21 | }dhcps_msg; 22 | 23 | #ifndef LWIP_OPEN_SRC 24 | struct dhcps_lease { 25 | uint32 start_ip; 26 | uint32 end_ip; 27 | }; 28 | #endif 29 | 30 | struct dhcps_pool{ 31 | struct ip_addr ip; 32 | uint8 mac[6]; 33 | uint32 lease_timer; 34 | }; 35 | 36 | typedef struct _list_node{ 37 | void *pnode; 38 | struct _list_node *pnext; 39 | }list_node; 40 | 41 | #define DHCPS_LEASE_TIMER 0x05A0 42 | #define DHCPS_MAX_LEASE 0x64 43 | #define BOOTP_BROADCAST 0x8000 44 | 45 | #define DHCP_REQUEST 1 46 | #define DHCP_REPLY 2 47 | #define DHCP_HTYPE_ETHERNET 1 48 | #define DHCP_HLEN_ETHERNET 6 49 | #define DHCP_MSG_LEN 236 50 | 51 | #define DHCPS_SERVER_PORT 67 52 | #define DHCPS_CLIENT_PORT 68 53 | 54 | #define DHCPDISCOVER 1 55 | #define DHCPOFFER 2 56 | #define DHCPREQUEST 3 57 | #define DHCPDECLINE 4 58 | #define DHCPACK 5 59 | #define DHCPNAK 6 60 | #define DHCPRELEASE 7 61 | 62 | #define DHCP_OPTION_SUBNET_MASK 1 63 | #define DHCP_OPTION_ROUTER 3 64 | #define DHCP_OPTION_DNS_SERVER 6 65 | #define DHCP_OPTION_REQ_IPADDR 50 66 | #define DHCP_OPTION_LEASE_TIME 51 67 | #define DHCP_OPTION_MSG_TYPE 53 68 | #define DHCP_OPTION_SERVER_ID 54 69 | #define DHCP_OPTION_INTERFACE_MTU 26 70 | #define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31 71 | #define DHCP_OPTION_BROADCAST_ADDRESS 28 72 | #define DHCP_OPTION_REQ_LIST 55 73 | #define DHCP_OPTION_END 255 74 | 75 | //#define USE_CLASS_B_NET 1 76 | #define DHCPS_DEBUG 0 77 | 78 | 79 | #define DHCPS_STATE_OFFER 1 80 | #define DHCPS_STATE_DECLINE 2 81 | #define DHCPS_STATE_ACK 3 82 | #define DHCPS_STATE_NAK 4 83 | #define DHCPS_STATE_IDLE 5 84 | 85 | void dhcps_start(struct ip_info *info); 86 | void dhcps_stop(void); 87 | 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /lib/heatshrink/dec_sm.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | graph [label="Decoder state machine", labelloc="t"] 3 | Start [style="invis", shape="point"] 4 | empty 5 | input_available 6 | yield_literal 7 | backref_index_msb 8 | backref_index_lsb 9 | backref_count_msb 10 | backref_count_lsb 11 | yield_backref 12 | check_for_more_input 13 | done [peripheries=2] 14 | 15 | empty->input_available [label="sink()", color="blue", weight=10] 16 | Start->empty 17 | 18 | input_available->yield_literal [label="pop 1-bit"] 19 | input_available->backref_index_msb [label="pop 0-bit", weight=10] 20 | input_available->backref_index_lsb [label="pop 0-bit, index <8 bits", weight=10] 21 | 22 | yield_literal->yield_literal [label="sink()", color="blue"] 23 | yield_literal->yield_literal [label="poll()", color="red"] 24 | yield_literal->check_for_more_input [label="poll(), done", color="red"] 25 | 26 | backref_index_msb->backref_index_msb [label="sink()", color="blue"] 27 | backref_index_msb->backref_index_lsb [label="pop index, upper bits", weight=10] 28 | backref_index_msb->done [label="finish()", color="blue"] 29 | 30 | backref_index_lsb->backref_index_lsb [label="sink()", color="blue"] 31 | backref_index_lsb->backref_count_msb [label="pop index, lower bits", weight=10] 32 | backref_index_lsb->backref_count_lsb [label="pop index, count <=8 bits", weight=10] 33 | backref_index_lsb->done [label="finish()", color="blue"] 34 | 35 | backref_count_msb->backref_count_msb [label="sink()", color="blue"] 36 | backref_count_msb->backref_count_lsb [label="pop count, upper bits", weight=10] 37 | backref_count_msb->done [label="finish()", color="blue"] 38 | 39 | backref_count_lsb->backref_count_lsb [label="sink()", color="blue"] 40 | backref_count_lsb->yield_backref [label="pop count, lower bits", weight=10] 41 | backref_count_lsb->done [label="finish()", color="blue"] 42 | 43 | yield_backref->yield_backref [label="sink()", color="blue"] 44 | yield_backref->yield_backref [label="poll()", color="red"] 45 | yield_backref->check_for_more_input [label="poll(), done", 46 | color="red", weight=10] 47 | 48 | check_for_more_input->empty [label="no"] 49 | check_for_more_input->input_available [label="yes"] 50 | 51 | empty->done [label="finish()", color="blue"] 52 | } 53 | -------------------------------------------------------------------------------- /htmCopy/wifi/wifi.tpl: -------------------------------------------------------------------------------- 1 | WiFi connection 2 | 3 | 4 | 74 | 75 | 76 |
77 |

78 | Current WiFi mode: %WiFiMode% 79 |

80 |

81 | Note: %WiFiapwarn% 82 |

83 |
84 |

85 | To connect to a WiFi network, please select one of the detected networks...
86 |

Scanning...
87 |
88 | WiFi password, if applicable:
89 |
90 | 91 |

92 |
93 | 94 | 95 | -------------------------------------------------------------------------------- /include/lwip/init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INIT_H__ 33 | #define __LWIP_INIT_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** X.x.x: Major version of the stack */ 42 | #define LWIP_VERSION_MAJOR 1U 43 | /** x.X.x: Minor version of the stack */ 44 | #define LWIP_VERSION_MINOR 4U 45 | /** x.x.X: Revision of the stack */ 46 | #define LWIP_VERSION_REVISION 0U 47 | /** For release candidates, this is set to 1..254 48 | * For official releases, this is set to 255 (LWIP_RC_RELEASE) 49 | * For development versions (CVS), this is set to 0 (LWIP_RC_DEVELOPMENT) */ 50 | #define LWIP_VERSION_RC 2U 51 | 52 | /** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ 53 | #define LWIP_RC_RELEASE 255U 54 | /** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for CVS versions */ 55 | #define LWIP_RC_DEVELOPMENT 0U 56 | 57 | #define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) 58 | #define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) 59 | #define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) 60 | 61 | /** Provides the version of the stack */ 62 | #define LWIP_VERSION (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 | \ 63 | LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC) 64 | 65 | /* Modules initialization */ 66 | void lwip_init(void) ICACHE_FLASH_ATTR; 67 | //void lwip_init(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __LWIP_INIT_H__ */ 74 | -------------------------------------------------------------------------------- /user/cgi.c: -------------------------------------------------------------------------------- 1 | /* 2 | Some random cgi routines. Used in the LED example and the page that returns the entire 3 | flash as a binary. Also handles the hit counter on the main page. 4 | */ 5 | 6 | /* 7 | * ---------------------------------------------------------------------------- 8 | * "THE BEER-WARE LICENSE" (Revision 42): 9 | * Jeroen Domburg wrote this file. As long as you retain 10 | * this notice you can do whatever you want with this stuff. If we meet some day, 11 | * and you think this stuff is worth it, you can buy me a beer in return. 12 | * ---------------------------------------------------------------------------- 13 | */ 14 | 15 | 16 | #include 17 | #include 18 | #include "user_interface.h" 19 | #include "mem.h" 20 | #include "httpd.h" 21 | #include "cgi.h" 22 | #include "io.h" 23 | #include "espmissingincludes.h" 24 | #include 25 | 26 | //cause I can't be bothered to write an ioGetLed() 27 | static char currLedState=0; 28 | 29 | //Cgi that turns the LED on or off according to the 'led' param in the POST data 30 | int ICACHE_FLASH_ATTR cgiLed(HttpdConnData *connData) { 31 | int len; 32 | char buff[1024]; 33 | 34 | if (connData->conn==NULL) { 35 | //Connection aborted. Clean up. 36 | return HTTPD_CGI_DONE; 37 | } 38 | 39 | len=httpdFindArg(connData->postBuff, "led", buff, sizeof(buff)); 40 | if (len!=0) { 41 | currLedState=atoi(buff); 42 | ioLed(currLedState); 43 | } 44 | 45 | httpdRedirect(connData, "led.tpl"); 46 | return HTTPD_CGI_DONE; 47 | } 48 | 49 | 50 | 51 | //Template code for the led page. 52 | void ICACHE_FLASH_ATTR tplLed(HttpdConnData *connData, char *token, void **arg) { 53 | char buff[128]; 54 | if (token==NULL) return; 55 | 56 | os_strcpy(buff, "Unknown"); 57 | if (os_strcmp(token, "ledstate")==0) { 58 | if (currLedState) { 59 | os_strcpy(buff, "on"); 60 | } else { 61 | os_strcpy(buff, "off"); 62 | } 63 | } 64 | espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff)); 65 | } 66 | 67 | static long hitCounter=0; 68 | 69 | //Template code for the counter on the index page. 70 | void ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) { 71 | char buff[128]; 72 | if (token==NULL) return; 73 | 74 | if (os_strcmp(token, "counter")==0) { 75 | hitCounter++; 76 | os_sprintf(buff, "%ld", hitCounter); 77 | } 78 | espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff)); 79 | } 80 | 81 | 82 | //Cgi that reads the SPI flash. Assumes 512KByte flash. 83 | int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) { 84 | int *pos=(int *)&connData->cgiData; 85 | if (connData->conn==NULL) { 86 | //Connection aborted. Clean up. 87 | return HTTPD_CGI_DONE; 88 | } 89 | 90 | if (*pos==0) { 91 | os_printf("Start flash download.\n"); 92 | httpdStartResponse(connData, 200); 93 | httpdHeader(connData, "Content-Type", "application/bin"); 94 | httpdEndHeaders(connData); 95 | *pos=0x40200000; 96 | return HTTPD_CGI_MORE; 97 | } 98 | //Send 1K of flash per call. We will get called again if we haven't sent 512K yet. 99 | espconn_sent(connData->conn, (uint8 *)(*pos), 1024); 100 | *pos+=1024; 101 | if (*pos>=0x40200000+(512*1024)) return HTTPD_CGI_DONE; else return HTTPD_CGI_MORE; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /include/lwip/ip_frag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Jani Monoses 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_IP_FRAG_H__ 34 | #define __LWIP_IP_FRAG_H__ 35 | 36 | #include "lwip/opt.h" 37 | #include "lwip/err.h" 38 | #include "lwip/pbuf.h" 39 | #include "lwip/netif.h" 40 | #include "lwip/ip_addr.h" 41 | #include "lwip/ip.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #if IP_REASSEMBLY 48 | /* The IP reassembly timer interval in milliseconds. */ 49 | #define IP_TMR_INTERVAL 1000 50 | 51 | /* IP reassembly helper struct. 52 | * This is exported because memp needs to know the size. 53 | */ 54 | struct ip_reassdata { 55 | struct ip_reassdata *next; 56 | struct pbuf *p; 57 | struct ip_hdr iphdr; 58 | u16_t datagram_len; 59 | u8_t flags; 60 | u8_t timer; 61 | }; 62 | 63 | void ip_reass_init(void)ICACHE_FLASH_ATTR; 64 | void ip_reass_tmr(void)ICACHE_FLASH_ATTR; 65 | struct pbuf * ip_reass(struct pbuf *p)ICACHE_FLASH_ATTR; 66 | #endif /* IP_REASSEMBLY */ 67 | 68 | #if IP_FRAG 69 | #if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF 70 | /** A custom pbuf that holds a reference to another pbuf, which is freed 71 | * when this custom pbuf is freed. This is used to create a custom PBUF_REF 72 | * that points into the original pbuf. */ 73 | struct pbuf_custom_ref { 74 | /** 'base class' */ 75 | struct pbuf_custom pc; 76 | /** pointer to the original pbuf that is referenced */ 77 | struct pbuf *original; 78 | }; 79 | #endif /* !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ 80 | 81 | err_t ip_frag(struct pbuf *p, struct netif *netif, ip_addr_t *dest)ICACHE_FLASH_ATTR; 82 | #endif /* IP_FRAG */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* __LWIP_IP_FRAG_H__ */ 89 | -------------------------------------------------------------------------------- /include/lwip/err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_ERR_H__ 33 | #define __LWIP_ERR_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "lwip/arch.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** Define LWIP_ERR_T in cc.h if you want to use 43 | * a different type for your platform (must be signed). */ 44 | #ifdef LWIP_ERR_T 45 | typedef LWIP_ERR_T err_t; 46 | #else /* LWIP_ERR_T */ 47 | typedef s8_t err_t; 48 | #endif /* LWIP_ERR_T*/ 49 | 50 | /* Definitions for error constants. */ 51 | 52 | #define ERR_OK 0 /* No error, everything OK. */ 53 | #define ERR_MEM -1 /* Out of memory error. */ 54 | #define ERR_BUF -2 /* Buffer error. */ 55 | #define ERR_TIMEOUT -3 /* Timeout. */ 56 | #define ERR_RTE -4 /* Routing problem. */ 57 | #define ERR_INPROGRESS -5 /* Operation in progress */ 58 | #define ERR_VAL -6 /* Illegal value. */ 59 | #define ERR_WOULDBLOCK -7 /* Operation would block. */ 60 | 61 | #define ERR_IS_FATAL(e) ((e) < ERR_WOULDBLOCK) 62 | 63 | #define ERR_ABRT -8 /* Connection aborted. */ 64 | #define ERR_RST -9 /* Connection reset. */ 65 | #define ERR_CLSD -10 /* Connection closed. */ 66 | #define ERR_CONN -11 /* Not connected. */ 67 | 68 | #define ERR_ARG -12 /* Illegal argument. */ 69 | 70 | #define ERR_USE -13 /* Address in use. */ 71 | 72 | #define ERR_IF -14 /* Low-level netif error */ 73 | #define ERR_ISCONN -15 /* Already connected. */ 74 | 75 | 76 | #ifdef LWIP_DEBUG 77 | extern const char *lwip_strerr(err_t err)ICACHE_FLASH_ATTR; 78 | #else 79 | #define lwip_strerr(x) "" 80 | #endif /* LWIP_DEBUG */ 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif /* __LWIP_ERR_H__ */ 87 | -------------------------------------------------------------------------------- /include/lwip/timers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * Simon Goldschmidt 31 | * 32 | */ 33 | #ifndef __LWIP_TIMERS_H__ 34 | #define __LWIP_TIMERS_H__ 35 | 36 | #include "lwip/opt.h" 37 | 38 | /* Timers are not supported when NO_SYS==1 and NO_SYS_NO_TIMERS==1 */ 39 | #define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) 40 | 41 | #if LWIP_TIMERS 42 | 43 | #include "lwip/err.h" 44 | #include "lwip/sys.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #ifndef LWIP_DEBUG_TIMERNAMES 51 | #ifdef LWIP_DEBUG 52 | #define LWIP_DEBUG_TIMERNAMES SYS_DEBUG 53 | #else /* LWIP_DEBUG */ 54 | #define LWIP_DEBUG_TIMERNAMES 0 55 | #endif /* LWIP_DEBUG*/ 56 | #endif 57 | 58 | /** Function prototype for a timeout callback function. Register such a function 59 | * using sys_timeout(). 60 | * 61 | * @param arg Additional argument to pass to the function - set up by sys_timeout() 62 | */ 63 | typedef void (* sys_timeout_handler)(void *arg); 64 | 65 | struct sys_timeo { 66 | struct sys_timeo *next; 67 | u32_t time; 68 | sys_timeout_handler h; 69 | void *arg; 70 | #if LWIP_DEBUG_TIMERNAMES 71 | const char* handler_name; 72 | #endif /* LWIP_DEBUG_TIMERNAMES */ 73 | }; 74 | 75 | void sys_timeouts_init(void)ICACHE_FLASH_ATTR; 76 | 77 | #if LWIP_DEBUG_TIMERNAMES 78 | void sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name)ICACHE_FLASH_ATTR; 79 | #define sys_timeout(msecs, handler, arg) sys_timeout_debug(msecs, handler, arg, #handler) 80 | #else /* LWIP_DEBUG_TIMERNAMES */ 81 | void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)ICACHE_FLASH_ATTR; 82 | #endif /* LWIP_DEBUG_TIMERNAMES */ 83 | 84 | void sys_untimeout(sys_timeout_handler handler, void *arg)ICACHE_FLASH_ATTR; 85 | #if NO_SYS 86 | void sys_check_timeouts(void)ICACHE_FLASH_ATTR; 87 | void sys_restart_timeouts(void)ICACHE_FLASH_ATTR; 88 | #else /* NO_SYS */ 89 | void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg); 90 | #endif /* NO_SYS */ 91 | 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /* LWIP_TIMERS */ 98 | #endif /* __LWIP_TIMERS_H__ */ 99 | -------------------------------------------------------------------------------- /READMEO.md: -------------------------------------------------------------------------------- 1 | esp-httpd README 2 | 3 | This is a small but powerful webserver for ESP8266(EX) chips. Included is an example of how 4 | to make a module that can have the AP it connects to configured over a webbrowser. 5 | 6 | ABOUT THE WEBSERVER 7 | 8 | The Good (aka: what's awesome) 9 | - Supports multiple connections, for eg simultaneous html/css/js/images downloading 10 | - Static files stored in flash, in an (optionally compressed) RO filesystem 11 | - Pluggable using external cgi routines 12 | - Simple template engine for mixed c and html things 13 | 14 | The Bad (aka: what can be improved) 15 | - Not built for speediness, although it's reasonable fast. 16 | - Built according to what I remember of the HTTP protocol, not according to the 17 | RFCs. Should work with most modern browsers, though. 18 | - No support for authentication or https. 19 | 20 | The Ugly (aka: bugs, misbehaviour) 21 | - Possible buffer overflows (usually not remotely exploitable) due to no os_snprintf 22 | This can be theoretically remedied by either Espressif including an os_snprintf in 23 | their libs or by using some alternate printf lib, like elm-chans xprintf 24 | 25 | ABOUT THE EXAMPLE 26 | 27 | When you flash the example into an ESP8266(EX) module, you get a small webserver with a few example 28 | pages. If you've already connected your module to your WLAN before, it'll keep those settings. When 29 | you haven't or the settings are wrong, keep GPIO0 for >5 seconds. The module will reboot into 30 | its STA+AP mode. Connect a computer to the newly formed access point and browse to 31 | http://192.168.4.1/wifi in order to connect the module to your WiFi network. The example also 32 | allows you to control a LED that's connected to GPIO2. 33 | 34 | BUILDING EVERYTHING 35 | 36 | For this, you need an environment that can compile ESP8266 firmware. Environments for this still 37 | are in flux at the moment, but I'm using a crosstool-ng gcc setup combined with the libs & includes 38 | from the ESP SDK and ESP VM. You probably also need an UNIX-slike system; I'm working on 39 | Debian Linux myself. 40 | 41 | To manage the paths to all this, you can source a small shell fragment into your current session. For 42 | example, I source a file with these contents: 43 | export PATH=${PWD}/crosstool-NG/builds/xtensa-lx106-elf/bin:$PATH 44 | export XTENSA_TOOLS_ROOT=${PWD}/crosstool-NG/builds/xtensa-lx106-elf/bin 45 | export SDK_BASE=${PWD}/esp_iot_sdk_v0.9.2/ 46 | export SDK_EXTRA_INCLUDES=${PWD}/esp_iot_sdk_novm_unpacked/usr/xtensa/XtDevTools/install/builds/RC-2010.1-win32/lx106/xtensa-elf/include/ 47 | export ESPTOOL=${PWD}/esptool/esptool.py 48 | export ESPPORT=/dev/ttyUSB0 49 | Actual setup of the SDK and toolchain is out of the scope of this document, so I hope this helps you 50 | enough to set up your own if you haven't already. 51 | 52 | If you have that, you can clone out the source code: 53 | git clone http://git.spritesserver.nl/esphttpd.git/ 54 | 55 | This project makes use of heatshrink, which is a git submodule. To fetch the code: 56 | cd esphttpd 57 | git submodule init 58 | git submodule update 59 | 60 | 61 | Now, build the code: 62 | make 63 | 64 | Flash the code happens in 2 steps. First the code itself gets flashed. Reset the module into bootloader 65 | mode and enter 'make flash'. You may want to reset and re-enter the bootloader halfway (at 'sleep 3') for 66 | the 2nd part of this flash to work. 67 | 68 | The 2nd step is to pack the static files the webserver will serve and flash that. Reset the module into 69 | bootloader mode again and enter 'make htmlflash'. 70 | 71 | You should have a working webserver now. 72 | 73 | WRITING CODE FOR THE WEBSERVER 74 | 75 | ...errm... to be done. For now, look at the examples. Hey, you probably managed to find out how 76 | the SDK works, this shouldn't be too hard :P 77 | 78 | 79 | -------------------------------------------------------------------------------- /include/lwip/inet_chksum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INET_CHKSUM_H__ 33 | #define __LWIP_INET_CHKSUM_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #include "lwip/pbuf.h" 38 | #include "lwip/ip_addr.h" 39 | 40 | /** Swap the bytes in an u16_t: much like htons() for little-endian */ 41 | #ifndef SWAP_BYTES_IN_WORD 42 | #if LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) 43 | /* little endian and PLATFORM_BYTESWAP defined */ 44 | #define SWAP_BYTES_IN_WORD(w) LWIP_PLATFORM_HTONS(w) 45 | #else /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) */ 46 | /* can't use htons on big endian (or PLATFORM_BYTESWAP not defined)... */ 47 | #define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8) 48 | #endif /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN)*/ 49 | #endif /* SWAP_BYTES_IN_WORD */ 50 | 51 | /** Split an u32_t in two u16_ts and add them up */ 52 | #ifndef FOLD_U32T 53 | #define FOLD_U32T(u) (((u) >> 16) + ((u) & 0x0000ffffUL)) 54 | #endif 55 | 56 | #if LWIP_CHECKSUM_ON_COPY 57 | /** Function-like macro: same as MEMCPY but returns the checksum of copied data 58 | as u16_t */ 59 | #ifndef LWIP_CHKSUM_COPY 60 | #define LWIP_CHKSUM_COPY(dst, src, len) lwip_chksum_copy(dst, src, len) 61 | #ifndef LWIP_CHKSUM_COPY_ALGORITHM 62 | #define LWIP_CHKSUM_COPY_ALGORITHM 1 63 | #endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 64 | #endif /* LWIP_CHKSUM_COPY */ 65 | #else /* LWIP_CHECKSUM_ON_COPY */ 66 | #define LWIP_CHKSUM_COPY_ALGORITHM 0 67 | #endif /* LWIP_CHECKSUM_ON_COPY */ 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | u16_t inet_chksum(void *dataptr, u16_t len)ICACHE_FLASH_ATTR; 74 | u16_t inet_chksum_pbuf(struct pbuf *p)ICACHE_FLASH_ATTR; 75 | u16_t inet_chksum_pseudo(struct pbuf *p, 76 | ip_addr_t *src, ip_addr_t *dest, 77 | u8_t proto, u16_t proto_len)ICACHE_FLASH_ATTR; 78 | u16_t inet_chksum_pseudo_partial(struct pbuf *p, 79 | ip_addr_t *src, ip_addr_t *dest, 80 | u8_t proto, u16_t proto_len, u16_t chksum_len)ICACHE_FLASH_ATTR; 81 | #if LWIP_CHKSUM_COPY_ALGORITHM 82 | u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len)ICACHE_FLASH_ATTR; 83 | #endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* __LWIP_INET_H__ */ 90 | 91 | -------------------------------------------------------------------------------- /include/lwip/raw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_RAW_H__ 33 | #define __LWIP_RAW_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */ 38 | 39 | #include "lwip/pbuf.h" 40 | #include "lwip/def.h" 41 | #include "lwip/ip.h" 42 | #include "lwip/ip_addr.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | struct raw_pcb; 49 | 50 | /** Function prototype for raw pcb receive callback functions. 51 | * @param arg user supplied argument (raw_pcb.recv_arg) 52 | * @param pcb the raw_pcb which received data 53 | * @param p the packet buffer that was received 54 | * @param addr the remote IP address from which the packet was received 55 | * @return 1 if the packet was 'eaten' (aka. deleted), 56 | * 0 if the packet lives on 57 | * If returning 1, the callback is responsible for freeing the pbuf 58 | * if it's not used any more. 59 | */ 60 | typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p, 61 | ip_addr_t *addr); 62 | 63 | struct raw_pcb { 64 | /* Common members of all PCB types */ 65 | IP_PCB; 66 | 67 | struct raw_pcb *next; 68 | 69 | u8_t protocol; 70 | 71 | /** receive callback function */ 72 | raw_recv_fn recv; 73 | /* user-supplied argument for the recv callback */ 74 | void *recv_arg; 75 | }; 76 | 77 | /* The following functions is the application layer interface to the 78 | RAW code. */ 79 | struct raw_pcb * raw_new (u8_t proto)ICACHE_FLASH_ATTR; 80 | void raw_remove (struct raw_pcb *pcb)ICACHE_FLASH_ATTR; 81 | err_t raw_bind (struct raw_pcb *pcb, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; 82 | err_t raw_connect (struct raw_pcb *pcb, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; 83 | 84 | void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)ICACHE_FLASH_ATTR; 85 | err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; 86 | err_t raw_send (struct raw_pcb *pcb, struct pbuf *p); 87 | 88 | /* The following functions are the lower layer interface to RAW. */ 89 | u8_t raw_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_ATTR; 90 | #define raw_init() /* Compatibility define, not init needed. */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* LWIP_RAW */ 97 | 98 | #endif /* __LWIP_RAW_H__ */ 99 | -------------------------------------------------------------------------------- /lib/heatshrink/heatshrink_encoder.h: -------------------------------------------------------------------------------- 1 | #ifndef HEATSHRINK_ENCODER_H 2 | #define HEATSHRINK_ENCODER_H 3 | 4 | #include 5 | #include 6 | #include "heatshrink_common.h" 7 | #include "heatshrink_config.h" 8 | 9 | typedef enum { 10 | HSER_SINK_OK, /* data sunk into input buffer */ 11 | HSER_SINK_ERROR_NULL=-1, /* NULL argument */ 12 | HSER_SINK_ERROR_MISUSE=-2, /* API misuse */ 13 | } HSE_sink_res; 14 | 15 | typedef enum { 16 | HSER_POLL_EMPTY, /* input exhausted */ 17 | HSER_POLL_MORE, /* poll again for more output */ 18 | HSER_POLL_ERROR_NULL=-1, /* NULL argument */ 19 | HSER_POLL_ERROR_MISUSE=-2, /* API misuse */ 20 | } HSE_poll_res; 21 | 22 | typedef enum { 23 | HSER_FINISH_DONE, /* encoding is complete */ 24 | HSER_FINISH_MORE, /* more output remaining; use poll */ 25 | HSER_FINISH_ERROR_NULL=-1, /* NULL argument */ 26 | } HSE_finish_res; 27 | 28 | #if HEATSHRINK_DYNAMIC_ALLOC 29 | #define HEATSHRINK_ENCODER_WINDOW_BITS(HSE) \ 30 | ((HSE)->window_sz2) 31 | #define HEATSHRINK_ENCODER_LOOKAHEAD_BITS(HSE) \ 32 | ((HSE)->lookahead_sz2) 33 | #define HEATSHRINK_ENCODER_INDEX(HSE) \ 34 | ((HSE)->search_index) 35 | struct hs_index { 36 | uint16_t size; 37 | int16_t index[]; 38 | }; 39 | #else 40 | #define HEATSHRINK_ENCODER_WINDOW_BITS(_) \ 41 | (HEATSHRINK_STATIC_WINDOW_BITS) 42 | #define HEATSHRINK_ENCODER_LOOKAHEAD_BITS(_) \ 43 | (HEATSHRINK_STATIC_LOOKAHEAD_BITS) 44 | #define HEATSHRINK_ENCODER_INDEX(HSE) \ 45 | (&(HSE)->search_index) 46 | struct hs_index { 47 | uint16_t size; 48 | int16_t index[2 << HEATSHRINK_STATIC_WINDOW_BITS]; 49 | }; 50 | #endif 51 | 52 | typedef struct { 53 | uint16_t input_size; /* bytes in input buffer */ 54 | uint16_t match_scan_index; 55 | uint16_t match_length; 56 | uint16_t match_pos; 57 | uint16_t outgoing_bits; /* enqueued outgoing bits */ 58 | uint8_t outgoing_bits_count; 59 | uint8_t flags; 60 | uint8_t state; /* current state machine node */ 61 | uint8_t current_byte; /* current byte of output */ 62 | uint8_t bit_index; /* current bit index */ 63 | #if HEATSHRINK_DYNAMIC_ALLOC 64 | uint8_t window_sz2; /* 2^n size of window */ 65 | uint8_t lookahead_sz2; /* 2^n size of lookahead */ 66 | #if HEATSHRINK_USE_INDEX 67 | struct hs_index *search_index; 68 | #endif 69 | /* input buffer and / sliding window for expansion */ 70 | uint8_t buffer[]; 71 | #else 72 | #if HEATSHRINK_USE_INDEX 73 | struct hs_index search_index; 74 | #endif 75 | /* input buffer and / sliding window for expansion */ 76 | uint8_t buffer[2 << HEATSHRINK_ENCODER_WINDOW_BITS(_)]; 77 | #endif 78 | } heatshrink_encoder; 79 | 80 | #if HEATSHRINK_DYNAMIC_ALLOC 81 | /* Allocate a new encoder struct and its buffers. 82 | * Returns NULL on error. */ 83 | heatshrink_encoder *heatshrink_encoder_alloc(uint8_t window_sz2, 84 | uint8_t lookahead_sz2); 85 | 86 | /* Free an encoder. */ 87 | void heatshrink_encoder_free(heatshrink_encoder *hse); 88 | #endif 89 | 90 | /* Reset an encoder. */ 91 | void heatshrink_encoder_reset(heatshrink_encoder *hse); 92 | 93 | /* Sink up to SIZE bytes from IN_BUF into the encoder. 94 | * INPUT_SIZE is set to the number of bytes actually sunk (in case a 95 | * buffer was filled.). */ 96 | HSE_sink_res heatshrink_encoder_sink(heatshrink_encoder *hse, 97 | uint8_t *in_buf, size_t size, size_t *input_size); 98 | 99 | /* Poll for output from the encoder, copying at most OUT_BUF_SIZE bytes into 100 | * OUT_BUF (setting *OUTPUT_SIZE to the actual amount copied). */ 101 | HSE_poll_res heatshrink_encoder_poll(heatshrink_encoder *hse, 102 | uint8_t *out_buf, size_t out_buf_size, size_t *output_size); 103 | 104 | /* Notify the encoder that the input stream is finished. 105 | * If the return value is HSER_FINISH_MORE, there is still more output, so 106 | * call heatshrink_encoder_poll and repeat. */ 107 | HSE_finish_res heatshrink_encoder_finish(heatshrink_encoder *hse); 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /include/arch/cc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001, Swedish Institute of Computer Science. 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. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | */ 34 | #ifndef __ARCH_CC_H__ 35 | #define __ARCH_CC_H__ 36 | 37 | //#include 38 | #include "c_types.h" 39 | #include "ets_sys.h" 40 | #include "osapi.h" 41 | #define EFAULT 14 42 | 43 | //#define LWIP_PROVIDE_ERRNO 44 | 45 | #if (1) 46 | #define BYTE_ORDER LITTLE_ENDIAN 47 | #else 48 | #define BYTE_ORDER BIG_ENDIAN 49 | #endif 50 | 51 | 52 | typedef unsigned char u8_t; 53 | typedef signed char s8_t; 54 | typedef unsigned short u16_t; 55 | typedef signed short s16_t; 56 | typedef unsigned long u32_t; 57 | typedef signed long s32_t; 58 | typedef unsigned long mem_ptr_t; 59 | 60 | #define S16_F "d" 61 | #define U16_F "d" 62 | #define X16_F "x" 63 | 64 | #define S32_F "d" 65 | #define U32_F "d" 66 | #define X32_F "x" 67 | 68 | 69 | 70 | //#define PACK_STRUCT_FIELD(x) x __attribute__((packed)) 71 | #define PACK_STRUCT_FIELD(x) x 72 | #define PACK_STRUCT_STRUCT __attribute__((packed)) 73 | #define PACK_STRUCT_BEGIN 74 | #define PACK_STRUCT_END 75 | 76 | //#define LWIP_DEBUG 77 | 78 | #ifdef LWIP_DEBUG 79 | #define LWIP_PLATFORM_DIAG(x) os_printf x 80 | #define LWIP_PLATFORM_ASSERT(x) ETS_ASSERT(x) 81 | #else 82 | #define LWIP_PLATFORM_DIAG(x) 83 | #define LWIP_PLATFORM_ASSERT(x) 84 | #endif 85 | 86 | #define SYS_ARCH_DECL_PROTECT(x) 87 | #define SYS_ARCH_PROTECT(x) 88 | #define SYS_ARCH_UNPROTECT(x) 89 | 90 | #define LWIP_PLATFORM_BYTESWAP 1 91 | #define LWIP_PLATFORM_HTONS(_n) ((u16_t)((((_n) & 0xff) << 8) | (((_n) >> 8) & 0xff))) 92 | #define LWIP_PLATFORM_HTONL(_n) ((u32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) )) 93 | 94 | #if LWIP_RAW 95 | extern u8_t memp_memory_RAW_PCB_base[]; 96 | #endif /* LWIP_RAW */ 97 | 98 | #if LWIP_UDP 99 | extern u8_t memp_memory_UDP_PCB_base[]; 100 | #endif /* LWIP_UDP */ 101 | 102 | #if LWIP_TCP 103 | extern u8_t memp_memory_TCP_PCB_base[]; 104 | extern u8_t memp_memory_TCP_PCB_LISTEN_base[]; 105 | extern u8_t memp_memory_TCP_SEG_base[] SHMEM_ATTR; 106 | #endif /* LWIP_TCP */ 107 | 108 | #if (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) /* LWIP_TIMERS */ 109 | extern u8_t memp_memory_SYS_TIMEOUT_base[]; 110 | #endif /* LWIP_TIMERS */ 111 | 112 | extern u8_t memp_memory_PBUF_base[]; 113 | extern u8_t memp_memory_PBUF_POOL_base[]; 114 | 115 | 116 | 117 | #endif /* __ARCH_CC_H__ */ 118 | -------------------------------------------------------------------------------- /lib/heatshrink/heatshrink_decoder.h: -------------------------------------------------------------------------------- 1 | #ifndef HEATSHRINK_DECODER_H 2 | #define HEATSHRINK_DECODER_H 3 | 4 | #include 5 | #include 6 | #include "heatshrink_common.h" 7 | #include "heatshrink_config.h" 8 | 9 | typedef enum { 10 | HSDR_SINK_OK, /* data sunk, ready to poll */ 11 | HSDR_SINK_FULL, /* out of space in internal buffer */ 12 | HSDR_SINK_ERROR_NULL=-1, /* NULL argument */ 13 | } HSD_sink_res; 14 | 15 | typedef enum { 16 | HSDR_POLL_EMPTY, /* input exhausted */ 17 | HSDR_POLL_MORE, /* more data remaining, call again w/ fresh output buffer */ 18 | HSDR_POLL_ERROR_NULL=-1, /* NULL arguments */ 19 | HSDR_POLL_ERROR_UNKNOWN=-2, 20 | } HSD_poll_res; 21 | 22 | typedef enum { 23 | HSDR_FINISH_DONE, /* output is done */ 24 | HSDR_FINISH_MORE, /* more output remains */ 25 | HSDR_FINISH_ERROR_NULL=-1, /* NULL arguments */ 26 | } HSD_finish_res; 27 | 28 | #if HEATSHRINK_DYNAMIC_ALLOC 29 | #define HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(BUF) \ 30 | ((BUF)->input_buffer_size) 31 | #define HEATSHRINK_DECODER_WINDOW_BITS(BUF) \ 32 | ((BUF)->window_sz2) 33 | #define HEATSHRINK_DECODER_LOOKAHEAD_BITS(BUF) \ 34 | ((BUF)->lookahead_sz2) 35 | #else 36 | #define HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(_) \ 37 | HEATSHRINK_STATIC_INPUT_BUFFER_SIZE 38 | #define HEATSHRINK_DECODER_WINDOW_BITS(_) \ 39 | (HEATSHRINK_STATIC_WINDOW_BITS) 40 | #define HEATSHRINK_DECODER_LOOKAHEAD_BITS(BUF) \ 41 | (HEATSHRINK_STATIC_LOOKAHEAD_BITS) 42 | #endif 43 | 44 | typedef struct { 45 | uint16_t input_size; /* bytes in input buffer */ 46 | uint16_t input_index; /* offset to next unprocessed input byte */ 47 | uint16_t output_count; /* how many bytes to output */ 48 | uint16_t output_index; /* index for bytes to output */ 49 | uint16_t head_index; /* head of window buffer */ 50 | uint16_t bit_accumulator; 51 | uint8_t state; /* current state machine node */ 52 | uint8_t current_byte; /* current byte of input */ 53 | uint8_t bit_index; /* current bit index */ 54 | 55 | #if HEATSHRINK_DYNAMIC_ALLOC 56 | /* Fields that are only used if dynamically allocated. */ 57 | uint8_t window_sz2; /* window buffer bits */ 58 | uint8_t lookahead_sz2; /* lookahead bits */ 59 | uint16_t input_buffer_size; /* input buffer size */ 60 | 61 | /* Input buffer, then expansion window buffer */ 62 | uint8_t buffers[]; 63 | #else 64 | /* Input buffer, then expansion window buffer */ 65 | uint8_t buffers[(1 << HEATSHRINK_DECODER_WINDOW_BITS(_)) 66 | + HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(_)]; 67 | #endif 68 | } heatshrink_decoder; 69 | 70 | #if HEATSHRINK_DYNAMIC_ALLOC 71 | /* Allocate a decoder with an input buffer of INPUT_BUFFER_SIZE bytes, 72 | * an expansion buffer size of 2^WINDOW_SZ2, and a lookahead 73 | * size of 2^lookahead_sz2. (The window buffer and lookahead sizes 74 | * must match the settings used when the data was compressed.) 75 | * Returns NULL on error. */ 76 | heatshrink_decoder *heatshrink_decoder_alloc(uint16_t input_buffer_size, 77 | uint8_t expansion_buffer_sz2, uint8_t lookahead_sz2); 78 | 79 | /* Free a decoder. */ 80 | void heatshrink_decoder_free(heatshrink_decoder *hsd); 81 | #endif 82 | 83 | /* Reset a decoder. */ 84 | void heatshrink_decoder_reset(heatshrink_decoder *hsd); 85 | 86 | /* Sink at most SIZE bytes from IN_BUF into the decoder. *INPUT_SIZE is set to 87 | * indicate how many bytes were actually sunk (in case a buffer was filled). */ 88 | HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd, 89 | uint8_t *in_buf, size_t size, size_t *input_size); 90 | 91 | /* Poll for output from the decoder, copying at most OUT_BUF_SIZE bytes into 92 | * OUT_BUF (setting *OUTPUT_SIZE to the actual amount copied). */ 93 | HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, 94 | uint8_t *out_buf, size_t out_buf_size, size_t *output_size); 95 | 96 | /* Notify the dencoder that the input stream is finished. 97 | * If the return value is HSDR_FINISH_MORE, there is still more output, so 98 | * call heatshrink_decoder_poll and repeat. */ 99 | HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd); 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /include/lwip/netifapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Redistribution and use in source and binary forms, with or without modification, 3 | * are permitted provided that the following conditions are met: 4 | * 5 | * 1. Redistributions of source code must retain the above copyright notice, 6 | * this list of conditions and the following disclaimer. 7 | * 2. Redistributions in binary form must reproduce the above copyright notice, 8 | * this list of conditions and the following disclaimer in the documentation 9 | * and/or other materials provided with the distribution. 10 | * 3. The name of the author may not be used to endorse or promote products 11 | * derived from this software without specific prior written permission. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 14 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 16 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 18 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 22 | * OF SUCH DAMAGE. 23 | * 24 | * This file is part of the lwIP TCP/IP stack. 25 | * 26 | */ 27 | 28 | #ifndef __LWIP_NETIFAPI_H__ 29 | #define __LWIP_NETIFAPI_H__ 30 | 31 | #include "lwip/opt.h" 32 | 33 | #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ 34 | 35 | #include "lwip/sys.h" 36 | #include "lwip/netif.h" 37 | #include "lwip/dhcp.h" 38 | #include "lwip/autoip.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef void (*netifapi_void_fn)(struct netif *netif); 45 | typedef err_t (*netifapi_errt_fn)(struct netif *netif); 46 | 47 | struct netifapi_msg_msg { 48 | #if !LWIP_TCPIP_CORE_LOCKING 49 | sys_sem_t sem; 50 | #endif /* !LWIP_TCPIP_CORE_LOCKING */ 51 | err_t err; 52 | struct netif *netif; 53 | union { 54 | struct { 55 | ip_addr_t *ipaddr; 56 | ip_addr_t *netmask; 57 | ip_addr_t *gw; 58 | void *state; 59 | netif_init_fn init; 60 | netif_input_fn input; 61 | } add; 62 | struct { 63 | netifapi_void_fn voidfunc; 64 | netifapi_errt_fn errtfunc; 65 | } common; 66 | } msg; 67 | }; 68 | 69 | struct netifapi_msg { 70 | void (* function)(struct netifapi_msg_msg *msg); 71 | struct netifapi_msg_msg msg; 72 | }; 73 | 74 | 75 | /* API for application */ 76 | err_t netifapi_netif_add ( struct netif *netif, 77 | ip_addr_t *ipaddr, 78 | ip_addr_t *netmask, 79 | ip_addr_t *gw, 80 | void *state, 81 | netif_init_fn init, 82 | netif_input_fn input); 83 | 84 | err_t netifapi_netif_set_addr ( struct netif *netif, 85 | ip_addr_t *ipaddr, 86 | ip_addr_t *netmask, 87 | ip_addr_t *gw ); 88 | 89 | err_t netifapi_netif_common ( struct netif *netif, 90 | netifapi_void_fn voidfunc, 91 | netifapi_errt_fn errtfunc); 92 | 93 | #define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL) 94 | #define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL) 95 | #define netifapi_netif_set_down(n) netifapi_netif_common(n, netif_set_down, NULL) 96 | #define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL) 97 | #define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start) 98 | #define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL) 99 | #define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start) 100 | #define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop) 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* LWIP_NETIF_API */ 107 | 108 | #endif /* __LWIP_NETIFAPI_H__ */ 109 | -------------------------------------------------------------------------------- /include/lwip/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_DEBUG_H__ 33 | #define __LWIP_DEBUG_H__ 34 | 35 | #include "lwip/arch.h" 36 | 37 | /** lower two bits indicate debug level 38 | * - 0 all 39 | * - 1 warning 40 | * - 2 serious 41 | * - 3 severe 42 | */ 43 | #define LWIP_DBG_LEVEL_ALL 0x00 44 | #define LWIP_DBG_LEVEL_OFF LWIP_DBG_LEVEL_ALL /* compatibility define only */ 45 | #define LWIP_DBG_LEVEL_WARNING 0x01 /* bad checksums, dropped packets, ... */ 46 | #define LWIP_DBG_LEVEL_SERIOUS 0x02 /* memory allocation failures, ... */ 47 | #define LWIP_DBG_LEVEL_SEVERE 0x03 48 | #define LWIP_DBG_MASK_LEVEL 0x03 49 | 50 | /** flag for LWIP_DEBUGF to enable that debug message */ 51 | #define LWIP_DBG_ON 0x80U 52 | /** flag for LWIP_DEBUGF to disable that debug message */ 53 | #define LWIP_DBG_OFF 0x00U 54 | 55 | /** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */ 56 | #define LWIP_DBG_TRACE 0x40U 57 | /** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */ 58 | #define LWIP_DBG_STATE 0x20U 59 | /** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */ 60 | #define LWIP_DBG_FRESH 0x10U 61 | /** flag for LWIP_DEBUGF to halt after printing this debug message */ 62 | #define LWIP_DBG_HALT 0x08U 63 | 64 | #ifndef LWIP_NOASSERT 65 | #define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \ 66 | LWIP_PLATFORM_ASSERT(message); } while(0) 67 | #else /* LWIP_NOASSERT */ 68 | #define LWIP_ASSERT(message, assertion) 69 | #endif /* LWIP_NOASSERT */ 70 | 71 | /** if "expression" isn't true, then print "message" and execute "handler" expression */ 72 | #ifndef LWIP_ERROR 73 | #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ 74 | LWIP_PLATFORM_ASSERT(message); handler;}} while(0) 75 | #endif /* LWIP_ERROR */ 76 | 77 | #ifdef LWIP_DEBUG 78 | /** print debug message only if debug message type is enabled... 79 | * AND is of correct type AND is at least LWIP_DBG_LEVEL 80 | */ 81 | #define LWIP_DEBUGF(debug, message) do { \ 82 | if ( \ 83 | ((debug) & LWIP_DBG_ON) && \ 84 | ((debug) & LWIP_DBG_TYPES_ON) && \ 85 | ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \ 86 | LWIP_PLATFORM_DIAG(message); \ 87 | if ((debug) & LWIP_DBG_HALT) { \ 88 | while(1); \ 89 | } \ 90 | } \ 91 | } while(0) 92 | 93 | #else /* LWIP_DEBUG */ 94 | #define LWIP_DEBUGF(debug, message) 95 | #endif /* LWIP_DEBUG */ 96 | 97 | #endif /* __LWIP_DEBUG_H__ */ 98 | 99 | -------------------------------------------------------------------------------- /include/lwip/snmp_asn1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Abstract Syntax Notation One (ISO 8824, 8825) codec. 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. The name of the author may not be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 | * OF SUCH DAMAGE. 31 | * 32 | * Author: Christiaan Simons 33 | */ 34 | 35 | #ifndef __LWIP_SNMP_ASN1_H__ 36 | #define __LWIP_SNMP_ASN1_H__ 37 | 38 | #include "lwip/opt.h" 39 | #include "lwip/err.h" 40 | #include "lwip/pbuf.h" 41 | #include "lwip/snmp.h" 42 | 43 | #if LWIP_SNMP 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #define SNMP_ASN1_UNIV (0) /* (!0x80 | !0x40) */ 50 | #define SNMP_ASN1_APPLIC (0x40) /* (!0x80 | 0x40) */ 51 | #define SNMP_ASN1_CONTXT (0x80) /* ( 0x80 | !0x40) */ 52 | 53 | #define SNMP_ASN1_CONSTR (0x20) /* ( 0x20) */ 54 | #define SNMP_ASN1_PRIMIT (0) /* (!0x20) */ 55 | 56 | /* universal tags */ 57 | #define SNMP_ASN1_INTEG 2 58 | #define SNMP_ASN1_OC_STR 4 59 | #define SNMP_ASN1_NUL 5 60 | #define SNMP_ASN1_OBJ_ID 6 61 | #define SNMP_ASN1_SEQ 16 62 | 63 | /* application specific (SNMP) tags */ 64 | #define SNMP_ASN1_IPADDR 0 /* octet string size(4) */ 65 | #define SNMP_ASN1_COUNTER 1 /* u32_t */ 66 | #define SNMP_ASN1_GAUGE 2 /* u32_t */ 67 | #define SNMP_ASN1_TIMETICKS 3 /* u32_t */ 68 | #define SNMP_ASN1_OPAQUE 4 /* octet string */ 69 | 70 | /* context specific (SNMP) tags */ 71 | #define SNMP_ASN1_PDU_GET_REQ 0 72 | #define SNMP_ASN1_PDU_GET_NEXT_REQ 1 73 | #define SNMP_ASN1_PDU_GET_RESP 2 74 | #define SNMP_ASN1_PDU_SET_REQ 3 75 | #define SNMP_ASN1_PDU_TRAP 4 76 | 77 | err_t snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type); 78 | err_t snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length); 79 | err_t snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value); 80 | err_t snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value); 81 | err_t snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid); 82 | err_t snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw); 83 | 84 | void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed); 85 | void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed); 86 | void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed); 87 | void snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed); 88 | err_t snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type); 89 | err_t snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length); 90 | err_t snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, u32_t value); 91 | err_t snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, s32_t value); 92 | err_t snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident); 93 | err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u16_t raw_len, u8_t *raw); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* LWIP_SNMP */ 100 | 101 | #endif /* __LWIP_SNMP_ASN1_H__ */ 102 | -------------------------------------------------------------------------------- /include/lwip/memp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_MEMP_H__ 34 | #define __LWIP_MEMP_H__ 35 | 36 | #include "lwip/opt.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */ 43 | typedef enum { 44 | #define LWIP_MEMPOOL(name,num,size,desc, attr) MEMP_##name, 45 | #include "lwip/memp_std.h" 46 | MEMP_MAX 47 | } memp_t; 48 | 49 | #if MEM_USE_POOLS 50 | /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */ 51 | typedef enum { 52 | /* Get the first (via: 53 | MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/ 54 | MEMP_POOL_HELPER_FIRST = ((u8_t) 55 | #define LWIP_MEMPOOL(name,num,size,desc) 56 | #define LWIP_MALLOC_MEMPOOL_START 1 57 | #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0 58 | #define LWIP_MALLOC_MEMPOOL_END 59 | #include "lwip/memp_std.h" 60 | ) , 61 | /* Get the last (via: 62 | MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */ 63 | MEMP_POOL_HELPER_LAST = ((u8_t) 64 | #define LWIP_MEMPOOL(name,num,size,desc) 65 | #define LWIP_MALLOC_MEMPOOL_START 66 | #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size * 67 | #define LWIP_MALLOC_MEMPOOL_END 1 68 | #include "lwip/memp_std.h" 69 | ) 70 | } memp_pool_helper_t; 71 | 72 | /* The actual start and stop values are here (cast them over) 73 | We use this helper type and these defines so we can avoid using const memp_t values */ 74 | #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST) 75 | #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST) 76 | #endif /* MEM_USE_POOLS */ 77 | 78 | #if MEMP_MEM_MALLOC || MEM_USE_POOLS 79 | extern const u16_t memp_sizes[MEMP_MAX]; 80 | #endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */ 81 | 82 | #if MEMP_MEM_MALLOC 83 | 84 | #include "mem.h" 85 | 86 | #define memp_init() 87 | #define memp_malloc(type) mem_malloc(memp_sizes[type]) 88 | #define memp_free(type, mem) mem_free(mem) 89 | 90 | #else /* MEMP_MEM_MALLOC */ 91 | 92 | #if MEM_USE_POOLS 93 | /** This structure is used to save the pool one element came from. */ 94 | struct memp_malloc_helper 95 | { 96 | memp_t poolnr; 97 | }; 98 | #endif /* MEM_USE_POOLS */ 99 | 100 | void memp_init(void)ICACHE_FLASH_ATTR; 101 | 102 | #if MEMP_OVERFLOW_CHECK 103 | void *memp_malloc_fn(memp_t type, const char* file, const int line)ICACHE_FLASH_ATTR; 104 | #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__) 105 | #else 106 | void *memp_malloc(memp_t type)ICACHE_FLASH_ATTR; 107 | #endif 108 | void memp_free(memp_t type, void *mem)ICACHE_FLASH_ATTR; 109 | 110 | #endif /* MEMP_MEM_MALLOC */ 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif /* __LWIP_MEMP_H__ */ 117 | -------------------------------------------------------------------------------- /include/lwip/igmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 CITEL Technologies Ltd. 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. Neither the name of CITEL Technologies Ltd nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is a contribution to the lwIP TCP/IP stack. 30 | * The Swedish Institute of Computer Science and Adam Dunkels 31 | * are specifically granted permission to redistribute this 32 | * source code. 33 | */ 34 | 35 | #ifndef __LWIP_IGMP_H__ 36 | #define __LWIP_IGMP_H__ 37 | 38 | #include "lwip/opt.h" 39 | #include "lwip/ip_addr.h" 40 | #include "lwip/netif.h" 41 | #include "lwip/pbuf.h" 42 | 43 | #if LWIP_IGMP /* don't build if not configured for use in lwipopts.h */ 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | 50 | /* IGMP timer */ 51 | #define IGMP_TMR_INTERVAL 100 /* Milliseconds */ 52 | #define IGMP_V1_DELAYING_MEMBER_TMR (1000/IGMP_TMR_INTERVAL) 53 | #define IGMP_JOIN_DELAYING_MEMBER_TMR (500 /IGMP_TMR_INTERVAL) 54 | 55 | /* MAC Filter Actions, these are passed to a netif's 56 | * igmp_mac_filter callback function. */ 57 | #define IGMP_DEL_MAC_FILTER 0 58 | #define IGMP_ADD_MAC_FILTER 1 59 | 60 | 61 | /** 62 | * igmp group structure - there is 63 | * a list of groups for each interface 64 | * these should really be linked from the interface, but 65 | * if we keep them separate we will not affect the lwip original code 66 | * too much 67 | * 68 | * There will be a group for the all systems group address but this 69 | * will not run the state machine as it is used to kick off reports 70 | * from all the other groups 71 | */ 72 | struct igmp_group { 73 | /** next link */ 74 | struct igmp_group *next; 75 | /** interface on which the group is active */ 76 | struct netif *netif; 77 | /** multicast address */ 78 | ip_addr_t group_address; 79 | /** signifies we were the last person to report */ 80 | u8_t last_reporter_flag; 81 | /** current state of the group */ 82 | u8_t group_state; 83 | /** timer for reporting, negative is OFF */ 84 | u16_t timer; 85 | /** counter of simultaneous uses */ 86 | u8_t use; 87 | }; 88 | 89 | /* Prototypes */ 90 | void igmp_init(void)ICACHE_FLASH_ATTR; 91 | err_t igmp_start(struct netif *netif)ICACHE_FLASH_ATTR; 92 | err_t igmp_stop(struct netif *netif)ICACHE_FLASH_ATTR; 93 | void igmp_report_groups(struct netif *netif)ICACHE_FLASH_ATTR; 94 | struct igmp_group *igmp_lookfor_group(struct netif *ifp, ip_addr_t *addr)ICACHE_FLASH_ATTR; 95 | void igmp_input(struct pbuf *p, struct netif *inp, ip_addr_t *dest)ICACHE_FLASH_ATTR; 96 | err_t igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR; 97 | err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR; 98 | void igmp_tmr(void)ICACHE_FLASH_ATTR; 99 | #define LWIP_RAND() rand() 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif /* LWIP_IGMP */ 105 | 106 | #endif /* __LWIP_IGMP_H__ */ 107 | -------------------------------------------------------------------------------- /include/lwip/netbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_NETBUF_H__ 33 | #define __LWIP_NETBUF_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "lwip/pbuf.h" 37 | #include "lwip/ip_addr.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** This netbuf has dest-addr/port set */ 44 | #define NETBUF_FLAG_DESTADDR 0x01 45 | /** This netbuf includes a checksum */ 46 | #define NETBUF_FLAG_CHKSUM 0x02 47 | 48 | struct netbuf { 49 | struct pbuf *p, *ptr; 50 | ip_addr_t addr; 51 | u16_t port; 52 | #if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY 53 | #if LWIP_CHECKSUM_ON_COPY 54 | u8_t flags; 55 | #endif /* LWIP_CHECKSUM_ON_COPY */ 56 | u16_t toport_chksum; 57 | #if LWIP_NETBUF_RECVINFO 58 | ip_addr_t toaddr; 59 | #endif /* LWIP_NETBUF_RECVINFO */ 60 | #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */ 61 | }; 62 | 63 | /* Network buffer functions: */ 64 | struct netbuf * netbuf_new (void)ICACHE_FLASH_ATTR; 65 | void netbuf_delete (struct netbuf *buf)ICACHE_FLASH_ATTR; 66 | void * netbuf_alloc (struct netbuf *buf, u16_t size)ICACHE_FLASH_ATTR; 67 | void netbuf_free (struct netbuf *buf)ICACHE_FLASH_ATTR; 68 | err_t netbuf_ref (struct netbuf *buf, 69 | const void *dataptr, u16_t size)ICACHE_FLASH_ATTR; 70 | void netbuf_chain (struct netbuf *head, 71 | struct netbuf *tail)ICACHE_FLASH_ATTR; 72 | 73 | err_t netbuf_data (struct netbuf *buf, 74 | void **dataptr, u16_t *len)ICACHE_FLASH_ATTR; 75 | s8_t netbuf_next (struct netbuf *buf)ICACHE_FLASH_ATTR; 76 | void netbuf_first (struct netbuf *buf)ICACHE_FLASH_ATTR; 77 | 78 | 79 | #define netbuf_copy_partial(buf, dataptr, len, offset) \ 80 | pbuf_copy_partial((buf)->p, (dataptr), (len), (offset)) 81 | #define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0) 82 | #define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len) 83 | #define netbuf_len(buf) ((buf)->p->tot_len) 84 | #define netbuf_fromaddr(buf) (&((buf)->addr)) 85 | #define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set((&(buf)->addr), fromaddr) 86 | #define netbuf_fromport(buf) ((buf)->port) 87 | #if LWIP_NETBUF_RECVINFO 88 | #define netbuf_destaddr(buf) (&((buf)->toaddr)) 89 | #define netbuf_set_destaddr(buf, destaddr) ip_addr_set((&(buf)->addr), destaddr) 90 | #define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0) 91 | #endif /* LWIP_NETBUF_RECVINFO */ 92 | #if LWIP_CHECKSUM_ON_COPY 93 | #define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \ 94 | (buf)->toport_chksum = chksum; } while(0) 95 | #endif /* LWIP_CHECKSUM_ON_COPY */ 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __LWIP_NETBUF_H__ */ 102 | -------------------------------------------------------------------------------- /include/lwip/inet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INET_H__ 33 | #define __LWIP_INET_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "lwip/def.h" 37 | #include "lwip/ip_addr.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** For compatibility with BSD code */ 44 | struct in_addr { 45 | u32_t s_addr; 46 | }; 47 | 48 | /** 255.255.255.255 */ 49 | #define INADDR_NONE IPADDR_NONE 50 | /** 127.0.0.1 */ 51 | #define INADDR_LOOPBACK IPADDR_LOOPBACK 52 | /** 0.0.0.0 */ 53 | #define INADDR_ANY IPADDR_ANY 54 | /** 255.255.255.255 */ 55 | #define INADDR_BROADCAST IPADDR_BROADCAST 56 | 57 | /* Definitions of the bits in an Internet address integer. 58 | 59 | On subnets, host and network parts are found according to 60 | the subnet mask, not these masks. */ 61 | #define IN_CLASSA(a) IP_CLASSA(a) 62 | #define IN_CLASSA_NET IP_CLASSA_NET 63 | #define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT 64 | #define IN_CLASSA_HOST IP_CLASSA_HOST 65 | #define IN_CLASSA_MAX IP_CLASSA_MAX 66 | 67 | #define IN_CLASSB(b) IP_CLASSB(b) 68 | #define IN_CLASSB_NET IP_CLASSB_NET 69 | #define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT 70 | #define IN_CLASSB_HOST IP_CLASSB_HOST 71 | #define IN_CLASSB_MAX IP_CLASSB_MAX 72 | 73 | #define IN_CLASSC(c) IP_CLASSC(c) 74 | #define IN_CLASSC_NET IP_CLASSC_NET 75 | #define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT 76 | #define IN_CLASSC_HOST IP_CLASSC_HOST 77 | #define IN_CLASSC_MAX IP_CLASSC_MAX 78 | 79 | #define IN_CLASSD(d) IP_CLASSD(d) 80 | #define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */ 81 | #define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */ 82 | #define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */ 83 | #define IN_CLASSD_MAX IP_CLASSD_MAX 84 | 85 | #define IN_MULTICAST(a) IP_MULTICAST(a) 86 | 87 | #define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a) 88 | #define IN_BADCLASS(a) IP_BADCLASS(a) 89 | 90 | #define IN_LOOPBACKNET IP_LOOPBACKNET 91 | 92 | #define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) 93 | #define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) 94 | /* ATTENTION: the next define only works because both s_addr and ip_addr_t are an u32_t effectively! */ 95 | #define inet_addr_to_ipaddr_p(target_ipaddr_p, source_inaddr) ((target_ipaddr_p) = (ip_addr_t*)&((source_inaddr)->s_addr)) 96 | 97 | /* directly map this to the lwip internal functions */ 98 | #define inet_addr(cp) ipaddr_addr(cp) 99 | #define inet_aton(cp, addr) ipaddr_aton(cp, (ip_addr_t*)addr) 100 | #define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr)) 101 | #define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((ip_addr_t*)&(addr), buf, buflen) 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* __LWIP_INET_H__ */ 108 | -------------------------------------------------------------------------------- /include/lwip/def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_DEF_H__ 33 | #define __LWIP_DEF_H__ 34 | 35 | /* arch.h might define NULL already */ 36 | #include "lwip/arch.h" 37 | #include "lwip/opt.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y)) 44 | #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y)) 45 | 46 | #ifndef NULL 47 | #define NULL ((void *)0) 48 | #endif 49 | 50 | /** Get the absolute difference between 2 u32_t values (correcting overflows) 51 | * 'a' is expected to be 'higher' (without overflow) than 'b'. */ 52 | #define LWIP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1))) 53 | 54 | /* Endianess-optimized shifting of two u8_t to create one u16_t */ 55 | #if BYTE_ORDER == LITTLE_ENDIAN 56 | #define LWIP_MAKE_U16(a, b) ((a << 8) | b) 57 | #else 58 | #define LWIP_MAKE_U16(a, b) ((b << 8) | a) 59 | #endif 60 | 61 | #ifndef LWIP_PLATFORM_BYTESWAP 62 | #define LWIP_PLATFORM_BYTESWAP 0 63 | #endif 64 | 65 | #ifndef LWIP_PREFIX_BYTEORDER_FUNCS 66 | /* workaround for naming collisions on some platforms */ 67 | 68 | #ifdef htons 69 | #undef htons 70 | #endif /* htons */ 71 | #ifdef htonl 72 | #undef htonl 73 | #endif /* htonl */ 74 | #ifdef ntohs 75 | #undef ntohs 76 | #endif /* ntohs */ 77 | #ifdef ntohl 78 | #undef ntohl 79 | #endif /* ntohl */ 80 | 81 | #define htons(x) lwip_htons(x) 82 | #define ntohs(x) lwip_ntohs(x) 83 | #define htonl(x) lwip_htonl(x) 84 | #define ntohl(x) lwip_ntohl(x) 85 | #endif /* LWIP_PREFIX_BYTEORDER_FUNCS */ 86 | 87 | #if BYTE_ORDER == BIG_ENDIAN 88 | #define lwip_htons(x) (x) 89 | #define lwip_ntohs(x) (x) 90 | #define lwip_htonl(x) (x) 91 | #define lwip_ntohl(x) (x) 92 | #define PP_HTONS(x) (x) 93 | #define PP_NTOHS(x) (x) 94 | #define PP_HTONL(x) (x) 95 | #define PP_NTOHL(x) (x) 96 | #else /* BYTE_ORDER != BIG_ENDIAN */ 97 | #if LWIP_PLATFORM_BYTESWAP 98 | #define lwip_htons(x) LWIP_PLATFORM_HTONS(x) 99 | #define lwip_ntohs(x) LWIP_PLATFORM_HTONS(x) 100 | #define lwip_htonl(x) LWIP_PLATFORM_HTONL(x) 101 | #define lwip_ntohl(x) LWIP_PLATFORM_HTONL(x) 102 | #else /* LWIP_PLATFORM_BYTESWAP */ 103 | u16_t lwip_htons(u16_t x); 104 | u16_t lwip_ntohs(u16_t x); 105 | u32_t lwip_htonl(u32_t x); 106 | u32_t lwip_ntohl(u32_t x); 107 | #endif /* LWIP_PLATFORM_BYTESWAP */ 108 | 109 | /* These macros should be calculated by the preprocessor and are used 110 | with compile-time constants only (so that there is no little-endian 111 | overhead at runtime). */ 112 | #define PP_HTONS(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8)) 113 | #define PP_NTOHS(x) PP_HTONS(x) 114 | #define PP_HTONL(x) ((((x) & 0xff) << 24) | \ 115 | (((x) & 0xff00) << 8) | \ 116 | (((x) & 0xff0000UL) >> 8) | \ 117 | (((x) & 0xff000000UL) >> 24)) 118 | #define PP_NTOHL(x) PP_HTONL(x) 119 | 120 | #endif /* BYTE_ORDER == BIG_ENDIAN */ 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif /* __LWIP_DEF_H__ */ 127 | 128 | -------------------------------------------------------------------------------- /include/lwip/sio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | */ 29 | 30 | /* 31 | * This is the interface to the platform specific serial IO module 32 | * It needs to be implemented by those platforms which need SLIP or PPP 33 | */ 34 | 35 | #ifndef __SIO_H__ 36 | #define __SIO_H__ 37 | 38 | #include "lwip/arch.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* If you want to define sio_fd_t elsewhere or differently, 45 | define this in your cc.h file. */ 46 | #ifndef __sio_fd_t_defined 47 | typedef void * sio_fd_t; 48 | #endif 49 | 50 | /* The following functions can be defined to something else in your cc.h file 51 | or be implemented in your custom sio.c file. */ 52 | 53 | #ifndef sio_open 54 | /** 55 | * Opens a serial device for communication. 56 | * 57 | * @param devnum device number 58 | * @return handle to serial device if successful, NULL otherwise 59 | */ 60 | sio_fd_t sio_open(u8_t devnum)ICACHE_FLASH_ATTR; 61 | #endif 62 | 63 | #ifndef sio_send 64 | /** 65 | * Sends a single character to the serial device. 66 | * 67 | * @param c character to send 68 | * @param fd serial device handle 69 | * 70 | * @note This function will block until the character can be sent. 71 | */ 72 | void sio_send(u8_t c, sio_fd_t fd)ICACHE_FLASH_ATTR; 73 | #endif 74 | 75 | #ifndef sio_recv 76 | /** 77 | * Receives a single character from the serial device. 78 | * 79 | * @param fd serial device handle 80 | * 81 | * @note This function will block until a character is received. 82 | */ 83 | u8_t sio_recv(sio_fd_t fd)ICACHE_FLASH_ATTR; 84 | #endif 85 | 86 | #ifndef sio_read 87 | /** 88 | * Reads from the serial device. 89 | * 90 | * @param fd serial device handle 91 | * @param data pointer to data buffer for receiving 92 | * @param len maximum length (in bytes) of data to receive 93 | * @return number of bytes actually received - may be 0 if aborted by sio_read_abort 94 | * 95 | * @note This function will block until data can be received. The blocking 96 | * can be cancelled by calling sio_read_abort(). 97 | */ 98 | u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)ICACHE_FLASH_ATTR; 99 | #endif 100 | 101 | #ifndef sio_tryread 102 | /** 103 | * Tries to read from the serial device. Same as sio_read but returns 104 | * immediately if no data is available and never blocks. 105 | * 106 | * @param fd serial device handle 107 | * @param data pointer to data buffer for receiving 108 | * @param len maximum length (in bytes) of data to receive 109 | * @return number of bytes actually received 110 | */ 111 | u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)ICACHE_FLASH_ATTR; 112 | #endif 113 | 114 | #ifndef sio_write 115 | /** 116 | * Writes to the serial device. 117 | * 118 | * @param fd serial device handle 119 | * @param data pointer to data to send 120 | * @param len length (in bytes) of data to send 121 | * @return number of bytes actually sent 122 | * 123 | * @note This function will block until all data can be sent. 124 | */ 125 | u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len)ICACHE_FLASH_ATTR; 126 | #endif 127 | 128 | #ifndef sio_read_abort 129 | /** 130 | * Aborts a blocking sio_read() call. 131 | * 132 | * @param fd serial device handle 133 | */ 134 | void sio_read_abort(sio_fd_t fd)ICACHE_FLASH_ATTR; 135 | #endif 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* __SIO_H__ */ 142 | -------------------------------------------------------------------------------- /include/lwip/autoip.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * AutoIP Automatic LinkLocal IP Configuration 5 | */ 6 | 7 | /* 8 | * 9 | * Copyright (c) 2007 Dominik Spies 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without modification, 13 | * are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | * OF SUCH DAMAGE. 33 | * 34 | * Author: Dominik Spies 35 | * 36 | * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform 37 | * with RFC 3927. 38 | * 39 | * 40 | * Please coordinate changes and requests with Dominik Spies 41 | * 42 | */ 43 | 44 | #ifndef __LWIP_AUTOIP_H__ 45 | #define __LWIP_AUTOIP_H__ 46 | 47 | #include "lwip/opt.h" 48 | 49 | #if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */ 50 | 51 | #include "lwip/netif.h" 52 | #include "lwip/udp.h" 53 | #include "netif/etharp.h" 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | /* AutoIP Timing */ 60 | #define AUTOIP_TMR_INTERVAL 100 61 | #define AUTOIP_TICKS_PER_SECOND (1000 / AUTOIP_TMR_INTERVAL) 62 | 63 | /* RFC 3927 Constants */ 64 | #define PROBE_WAIT 1 /* second (initial random delay) */ 65 | #define PROBE_MIN 1 /* second (minimum delay till repeated probe) */ 66 | #define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */ 67 | #define PROBE_NUM 3 /* (number of probe packets) */ 68 | #define ANNOUNCE_NUM 2 /* (number of announcement packets) */ 69 | #define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */ 70 | #define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */ 71 | #define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */ 72 | #define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */ 73 | #define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */ 74 | 75 | /* AutoIP client states */ 76 | #define AUTOIP_STATE_OFF 0 77 | #define AUTOIP_STATE_PROBING 1 78 | #define AUTOIP_STATE_ANNOUNCING 2 79 | #define AUTOIP_STATE_BOUND 3 80 | 81 | struct autoip 82 | { 83 | ip_addr_t llipaddr; /* the currently selected, probed, announced or used LL IP-Address */ 84 | u8_t state; /* current AutoIP state machine state */ 85 | u8_t sent_num; /* sent number of probes or announces, dependent on state */ 86 | u16_t ttw; /* ticks to wait, tick is AUTOIP_TMR_INTERVAL long */ 87 | u8_t lastconflict; /* ticks until a conflict can be solved by defending */ 88 | u8_t tried_llipaddr; /* total number of probed/used Link Local IP-Addresses */ 89 | }; 90 | 91 | 92 | /** Init srand, has to be called before entering mainloop */ 93 | void autoip_init(void); 94 | 95 | /** Set a struct autoip allocated by the application to work with */ 96 | void autoip_set_struct(struct netif *netif, struct autoip *autoip); 97 | 98 | /** Start AutoIP client */ 99 | err_t autoip_start(struct netif *netif); 100 | 101 | /** Stop AutoIP client */ 102 | err_t autoip_stop(struct netif *netif); 103 | 104 | /** Handles every incoming ARP Packet, called by etharp_arp_input */ 105 | void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr); 106 | 107 | /** Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds */ 108 | void autoip_tmr(void); 109 | 110 | /** Handle a possible change in the network configuration */ 111 | void autoip_network_changed(struct netif *netif); 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | 117 | #endif /* LWIP_AUTOIP */ 118 | 119 | #endif /* __LWIP_AUTOIP_H__ */ 120 | -------------------------------------------------------------------------------- /include/lwip/netdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Redistribution and use in source and binary forms, with or without modification, 3 | * are permitted provided that the following conditions are met: 4 | * 5 | * 1. Redistributions of source code must retain the above copyright notice, 6 | * this list of conditions and the following disclaimer. 7 | * 2. Redistributions in binary form must reproduce the above copyright notice, 8 | * this list of conditions and the following disclaimer in the documentation 9 | * and/or other materials provided with the distribution. 10 | * 3. The name of the author may not be used to endorse or promote products 11 | * derived from this software without specific prior written permission. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 14 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 16 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 18 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 22 | * OF SUCH DAMAGE. 23 | * 24 | * This file is part of the lwIP TCP/IP stack. 25 | * 26 | * Author: Simon Goldschmidt 27 | * 28 | */ 29 | #ifndef __LWIP_NETDB_H__ 30 | #define __LWIP_NETDB_H__ 31 | 32 | #include "lwip/opt.h" 33 | 34 | #if LWIP_DNS && LWIP_SOCKET 35 | 36 | #include /* for size_t */ 37 | 38 | #include "lwip/inet.h" 39 | #include "lwip/sockets.h" 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* some rarely used options */ 46 | #ifndef LWIP_DNS_API_DECLARE_H_ERRNO 47 | #define LWIP_DNS_API_DECLARE_H_ERRNO 1 48 | #endif 49 | 50 | #ifndef LWIP_DNS_API_DEFINE_ERRORS 51 | #define LWIP_DNS_API_DEFINE_ERRORS 1 52 | #endif 53 | 54 | #ifndef LWIP_DNS_API_DECLARE_STRUCTS 55 | #define LWIP_DNS_API_DECLARE_STRUCTS 1 56 | #endif 57 | 58 | #if LWIP_DNS_API_DEFINE_ERRORS 59 | /** Errors used by the DNS API functions, h_errno can be one of them */ 60 | #define EAI_NONAME 200 61 | #define EAI_SERVICE 201 62 | #define EAI_FAIL 202 63 | #define EAI_MEMORY 203 64 | 65 | #define HOST_NOT_FOUND 210 66 | #define NO_DATA 211 67 | #define NO_RECOVERY 212 68 | #define TRY_AGAIN 213 69 | #endif /* LWIP_DNS_API_DEFINE_ERRORS */ 70 | 71 | #if LWIP_DNS_API_DECLARE_STRUCTS 72 | struct hostent { 73 | char *h_name; /* Official name of the host. */ 74 | char **h_aliases; /* A pointer to an array of pointers to alternative host names, 75 | terminated by a null pointer. */ 76 | int h_addrtype; /* Address type. */ 77 | int h_length; /* The length, in bytes, of the address. */ 78 | char **h_addr_list; /* A pointer to an array of pointers to network addresses (in 79 | network byte order) for the host, terminated by a null pointer. */ 80 | #define h_addr h_addr_list[0] /* for backward compatibility */ 81 | }; 82 | 83 | struct addrinfo { 84 | int ai_flags; /* Input flags. */ 85 | int ai_family; /* Address family of socket. */ 86 | int ai_socktype; /* Socket type. */ 87 | int ai_protocol; /* Protocol of socket. */ 88 | socklen_t ai_addrlen; /* Length of socket address. */ 89 | struct sockaddr *ai_addr; /* Socket address of socket. */ 90 | char *ai_canonname; /* Canonical name of service location. */ 91 | struct addrinfo *ai_next; /* Pointer to next in list. */ 92 | }; 93 | #endif /* LWIP_DNS_API_DECLARE_STRUCTS */ 94 | 95 | #if LWIP_DNS_API_DECLARE_H_ERRNO 96 | /* application accessable error code set by the DNS API functions */ 97 | extern int h_errno; 98 | #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/ 99 | 100 | struct hostent *lwip_gethostbyname(const char *name); 101 | int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf, 102 | size_t buflen, struct hostent **result, int *h_errnop); 103 | void lwip_freeaddrinfo(struct addrinfo *ai); 104 | int lwip_getaddrinfo(const char *nodename, 105 | const char *servname, 106 | const struct addrinfo *hints, 107 | struct addrinfo **res); 108 | 109 | #if LWIP_COMPAT_SOCKETS 110 | #define gethostbyname(name) lwip_gethostbyname(name) 111 | #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \ 112 | lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop) 113 | #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo) 114 | #define getaddrinfo(nodname, servname, hints, res) \ 115 | lwip_getaddrinfo(nodname, servname, hints, res) 116 | #endif /* LWIP_COMPAT_SOCKETS */ 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* LWIP_DNS && LWIP_SOCKET */ 123 | 124 | #endif /* __LWIP_NETDB_H__ */ 125 | -------------------------------------------------------------------------------- /include/lwip/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_MEM_H__ 33 | #define __LWIP_MEM_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "mem_manager.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #if MEM_LIBC_MALLOC 43 | 44 | #include /* for size_t */ 45 | 46 | typedef size_t mem_size_t; 47 | 48 | /* aliases for C library malloc() */ 49 | #define mem_init() 50 | /* in case C library malloc() needs extra protection, 51 | * allow these defines to be overridden. 52 | */ 53 | #ifndef mem_free 54 | #define mem_free vPortFree 55 | #endif 56 | #ifndef mem_malloc 57 | #define mem_malloc pvPortMalloc 58 | #endif 59 | #ifndef mem_calloc 60 | #define mem_calloc pvPortCalloc 61 | #endif 62 | #ifndef mem_realloc 63 | #define mem_realloc pvPortRealloc 64 | #endif 65 | #ifndef mem_zalloc 66 | #define mem_zalloc pvPortZalloc 67 | #endif 68 | 69 | #ifndef os_malloc 70 | #define os_malloc(s) mem_malloc((s)) 71 | #endif 72 | #ifndef os_realloc 73 | #define os_realloc(p, s) mem_realloc((p), (s)) 74 | #endif 75 | #ifndef os_zalloc 76 | #define os_zalloc(s) mem_zalloc((s)) 77 | #endif 78 | #ifndef os_free 79 | #define os_free(p) mem_free((p)) 80 | #endif 81 | 82 | /* Since there is no C library allocation function to shrink memory without 83 | moving it, define this to nothing. */ 84 | #ifndef mem_trim 85 | #define mem_trim(mem, size) (mem) 86 | #endif 87 | #else /* MEM_LIBC_MALLOC */ 88 | 89 | /* MEM_SIZE would have to be aligned, but using 64000 here instead of 90 | * 65535 leaves some room for alignment... 91 | */ 92 | #if MEM_SIZE > 64000l 93 | typedef u32_t mem_size_t; 94 | #define MEM_SIZE_F U32_F 95 | #else 96 | typedef u16_t mem_size_t; 97 | #define MEM_SIZE_F U16_F 98 | #endif /* MEM_SIZE > 64000 */ 99 | 100 | #if MEM_USE_POOLS 101 | /** mem_init is not used when using pools instead of a heap */ 102 | #define mem_init() 103 | /** mem_trim is not used when using pools instead of a heap: 104 | we can't free part of a pool element and don't want to copy the rest */ 105 | #define mem_trim(mem, size) (mem) 106 | #else /* MEM_USE_POOLS */ 107 | /* lwIP alternative malloc */ 108 | void mem_init(void)ICACHE_FLASH_ATTR; 109 | void *mem_trim(void *mem, mem_size_t size)ICACHE_FLASH_ATTR; 110 | #endif /* MEM_USE_POOLS */ 111 | void *mem_malloc(mem_size_t size)ICACHE_FLASH_ATTR; 112 | void *mem_calloc(mem_size_t count, mem_size_t size)ICACHE_FLASH_ATTR; 113 | void mem_free(void *mem)ICACHE_FLASH_ATTR; 114 | #endif /* MEM_LIBC_MALLOC */ 115 | 116 | /** Calculate memory size for an aligned buffer - returns the next highest 117 | * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and 118 | * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4). 119 | */ 120 | #ifndef LWIP_MEM_ALIGN_SIZE 121 | #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1)) 122 | #endif 123 | 124 | /** Calculate safe memory size for an aligned buffer when using an unaligned 125 | * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the 126 | * start (e.g. if buffer is u8_t[] and actual data will be u32_t*) 127 | */ 128 | #ifndef LWIP_MEM_ALIGN_BUFFER 129 | #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1)) 130 | #endif 131 | 132 | /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT 133 | * so that ADDR % MEM_ALIGNMENT == 0 134 | */ 135 | #ifndef LWIP_MEM_ALIGN 136 | #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1))) 137 | #endif 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __LWIP_MEM_H__ */ 144 | -------------------------------------------------------------------------------- /user/httpdespfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Connector to let httpd use the espfs filesystem to serve the files in it. 3 | */ 4 | 5 | /* 6 | * ---------------------------------------------------------------------------- 7 | * "THE BEER-WARE LICENSE" (Revision 42): 8 | * Jeroen Domburg wrote this file. As long as you retain 9 | * this notice you can do whatever you want with this stuff. If we meet some day, 10 | * and you think this stuff is worth it, you can buy me a beer in return. 11 | * ---------------------------------------------------------------------------- 12 | */ 13 | 14 | #include "espmissingincludes.h" 15 | #include 16 | #include 17 | #include "c_types.h" 18 | #include "user_interface.h" 19 | #include "espconn.h" 20 | #include "mem.h" 21 | 22 | #include "httpd.h" 23 | #include "espfs.h" 24 | #include "httpdespfs.h" 25 | 26 | 27 | //This is a catch-all cgi function. It takes the url passed to it, looks up the corresponding 28 | //path in the filesystem and if it exists, passes the file through. This simulates what a normal 29 | //webserver would do with static files. 30 | int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData) { 31 | EspFsFile *file=connData->cgiData; 32 | int len; 33 | char buff[1024]; 34 | 35 | if (connData->conn==NULL) { 36 | //Connection aborted. Clean up. 37 | espFsClose(file); 38 | return HTTPD_CGI_DONE; 39 | } 40 | 41 | if (file==NULL) { 42 | //First call to this cgi. Open the file so we can read it. 43 | file=espFsOpen(connData->url); 44 | if (file==NULL) { 45 | return HTTPD_CGI_NOTFOUND; 46 | } 47 | connData->cgiData=file; 48 | httpdStartResponse(connData, 200); 49 | httpdHeader(connData, "Content-Type", httpdGetMimetype(connData->url)); 50 | 51 | //Modification : bkrajendra 52 | char *url; 53 | url = connData->url; 54 | //Go find the extension 55 | char *ext=url+(strlen(url)-1); 56 | while (ext!=url && *ext!='.') ext--; 57 | if (*ext=='.') ext++; 58 | 59 | if (os_strcmp(ext, "css")==0 || os_strcmp(ext, "js")==0) 60 | { 61 | httpdHeader(connData, "Content-Encoding", "gzip"); 62 | } 63 | //Modification : bkrajendra 64 | 65 | httpdEndHeaders(connData); 66 | return HTTPD_CGI_MORE; 67 | } 68 | 69 | len=espFsRead(file, buff, 1024); 70 | if (len>0) espconn_sent(connData->conn, (uint8 *)buff, len); 71 | if (len!=1024) { 72 | //We're done. 73 | espFsClose(file); 74 | return HTTPD_CGI_DONE; 75 | } else { 76 | //Ok, till next time. 77 | return HTTPD_CGI_MORE; 78 | } 79 | } 80 | 81 | 82 | //cgiEspFsTemplate can be used as a template. 83 | 84 | typedef struct { 85 | EspFsFile *file; 86 | void *tplArg; 87 | char token[64]; 88 | int tokenPos; 89 | } TplData; 90 | 91 | typedef void (* TplCallback)(HttpdConnData *connData, char *token, void **arg); 92 | 93 | int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData) { 94 | TplData *tpd=connData->cgiData; 95 | int len; 96 | int x, sp=0; 97 | char *e=NULL; 98 | char buff[1025]; 99 | 100 | if (connData->conn==NULL) { 101 | //Connection aborted. Clean up. 102 | ((TplCallback)(connData->cgiArg))(connData, NULL, &tpd->tplArg); 103 | espFsClose(tpd->file); 104 | os_free(tpd); 105 | return HTTPD_CGI_DONE; 106 | } 107 | 108 | if (tpd==NULL) { 109 | //First call to this cgi. Open the file so we can read it. 110 | tpd=(TplData *)os_malloc(sizeof(TplData)); 111 | tpd->file=espFsOpen(connData->url); 112 | tpd->tplArg=NULL; 113 | tpd->tokenPos=-1; 114 | if (tpd->file==NULL) { 115 | return HTTPD_CGI_NOTFOUND; 116 | } 117 | connData->cgiData=tpd; 118 | httpdStartResponse(connData, 200); 119 | httpdHeader(connData, "Content-Type", httpdGetMimetype(connData->url)); 120 | httpdEndHeaders(connData); 121 | return HTTPD_CGI_MORE; 122 | } 123 | 124 | len=espFsRead(tpd->file, buff, 1024); 125 | if (len>0) { 126 | sp=0; 127 | e=buff; 128 | for (x=0; xtokenPos==-1) { 130 | //Inside ordinary text. 131 | if (buff[x]=='%') { 132 | //Send raw data up to now 133 | if (sp!=0) espconn_sent(connData->conn, (uint8 *)e, sp); 134 | sp=0; 135 | //Go collect token chars. 136 | tpd->tokenPos=0; 137 | } else { 138 | sp++; 139 | } 140 | } else { 141 | if (buff[x]=='%') { 142 | if (tpd->tokenPos==0) { 143 | //This is the second % of a %% escape string. 144 | //Send a single % and resume with the normal program flow. 145 | espconn_sent(connData->conn, (uint8 *)"%", 1); 146 | } else { 147 | //This is an actual token. 148 | tpd->token[tpd->tokenPos++]=0; //zero-terminate token 149 | ((TplCallback)(connData->cgiArg))(connData, tpd->token, &tpd->tplArg); 150 | } 151 | //Go collect normal chars again. 152 | e=&buff[x+1]; 153 | tpd->tokenPos=-1; 154 | } else { 155 | if (tpd->tokenPos<(sizeof(tpd->token)-1)) tpd->token[tpd->tokenPos++]=buff[x]; 156 | } 157 | } 158 | } 159 | } 160 | //Send remaining bit. 161 | if (sp!=0) espconn_sent(connData->conn, (uint8 *)e, sp); 162 | if (len!=1024) { 163 | //We're done. 164 | ((TplCallback)(connData->cgiArg))(connData, NULL, &tpd->tplArg); 165 | espFsClose(tpd->file); 166 | return HTTPD_CGI_DONE; 167 | } else { 168 | //Ok, till next time. 169 | return HTTPD_CGI_MORE; 170 | } 171 | } 172 | 173 | -------------------------------------------------------------------------------- /html/index.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Responsive UI for ESP8266 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 55 | 56 |
57 | 58 | 59 | 75 | 76 | 77 | 95 | 96 | 97 |
98 |

Bootstrap Responisve UI in ESP8266

99 | 100 |

101 | If you see this, it means the tiny li'l website in your ESP8266 does actually work.
102 | This is an effort to create responsive UI in ESP.
103 | 104 |

105 | This page has been loaded %counter% times..! 106 |


107 | 108 | 109 | 110 | WLAN Config 111 | LED Control 112 | SPI flash ROM
113 | My Website 114 | 115 | 116 |

117 | 118 | 119 | 120 |

121 |
122 | 123 |
124 | 125 | 126 | 133 | 134 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /html/led.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Responsive UI for ESP8266 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 55 | 56 |
57 | 58 | 59 | 75 | 76 | 77 | 95 | 96 | 97 |
98 |

The LED Control

99 | 100 | 101 |

102 | If there's a LED connected to GPIO2, it's now %ledstate%. You can change that using the buttons below. 103 |

104 | 105 |
106 | LED stat

107 | 108 | 109 | 110 |
111 | 112 | 113 | 114 |
115 | 116 |
117 | 118 | 125 | 126 | 128 | 129 | 130 | 131 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /include/netif/if_llc.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: if_llc.h,v 1.12 1999/11/19 20:41:19 thorpej Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1988, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 4. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * @(#)if_llc.h 8.1 (Berkeley) 6/10/93 32 | * $FreeBSD$ 33 | */ 34 | 35 | #ifndef _NET_IF_LLC_H_ 36 | #define _NET_IF_LLC_H_ 37 | 38 | /* 39 | * IEEE 802.2 Link Level Control headers, for use in conjunction with 40 | * 802.{3,4,5} media access control methods. 41 | * 42 | * Headers here do not use bit fields due to shortcommings in many 43 | * compilers. 44 | */ 45 | 46 | struct llc { 47 | uint8_t llc_dsap; 48 | uint8_t llc_ssap; 49 | union { 50 | struct { 51 | uint8_t control; 52 | uint8_t format_id; 53 | uint8_t class; 54 | uint8_t window_x2; 55 | } __packed type_u; 56 | struct { 57 | uint8_t num_snd_x2; 58 | uint8_t num_rcv_x2; 59 | } __packed type_i; 60 | struct { 61 | uint8_t control; 62 | uint8_t num_rcv_x2; 63 | } __packed type_s; 64 | struct { 65 | uint8_t control; 66 | /* 67 | * We cannot put the following fields in a structure because 68 | * the structure rounding might cause padding. 69 | */ 70 | uint8_t frmr_rej_pdu0; 71 | uint8_t frmr_rej_pdu1; 72 | uint8_t frmr_control; 73 | uint8_t frmr_control_ext; 74 | uint8_t frmr_cause; 75 | } __packed type_frmr; 76 | struct { 77 | uint8_t control; 78 | uint8_t org_code[3]; 79 | uint16_t ether_type; 80 | } __packed type_snap; 81 | struct { 82 | uint8_t control; 83 | uint8_t control_ext; 84 | } __packed type_raw; 85 | } __packed llc_un; 86 | } __packed; 87 | 88 | struct frmrinfo { 89 | uint8_t frmr_rej_pdu0; 90 | uint8_t frmr_rej_pdu1; 91 | uint8_t frmr_control; 92 | uint8_t frmr_control_ext; 93 | uint8_t frmr_cause; 94 | } __packed; 95 | 96 | #define llc_control llc_un.type_u.control 97 | #define llc_control_ext llc_un.type_raw.control_ext 98 | #define llc_fid llc_un.type_u.format_id 99 | #define llc_class llc_un.type_u.class 100 | #define llc_window llc_un.type_u.window_x2 101 | #define llc_frmrinfo llc_un.type_frmr.frmr_rej_pdu0 102 | #define llc_frmr_pdu0 llc_un.type_frmr.frmr_rej_pdu0 103 | #define llc_frmr_pdu1 llc_un.type_frmr.frmr_rej_pdu1 104 | #define llc_frmr_control llc_un.type_frmr.frmr_control 105 | #define llc_frmr_control_ext llc_un.type_frmr.frmr_control_ext 106 | #define llc_frmr_cause llc_un.type_frmr.frmr_cause 107 | #define llc_snap llc_un.type_snap 108 | 109 | /* 110 | * Don't use sizeof(struct llc_un) for LLC header sizes 111 | */ 112 | #define LLC_ISFRAMELEN 4 113 | #define LLC_UFRAMELEN 3 114 | #define LLC_FRMRLEN 7 115 | #define LLC_SNAPFRAMELEN 8 116 | 117 | #ifdef CTASSERT 118 | CTASSERT(sizeof (struct llc) == LLC_SNAPFRAMELEN); 119 | #endif 120 | 121 | /* 122 | * Unnumbered LLC format commands 123 | */ 124 | #define LLC_UI 0x3 125 | #define LLC_UI_P 0x13 126 | #define LLC_DISC 0x43 127 | #define LLC_DISC_P 0x53 128 | #define LLC_UA 0x63 129 | #define LLC_UA_P 0x73 130 | #define LLC_TEST 0xe3 131 | #define LLC_TEST_P 0xf3 132 | #define LLC_FRMR 0x87 133 | #define LLC_FRMR_P 0x97 134 | #define LLC_DM 0x0f 135 | #define LLC_DM_P 0x1f 136 | #define LLC_XID 0xaf 137 | #define LLC_XID_P 0xbf 138 | #define LLC_SABME 0x6f 139 | #define LLC_SABME_P 0x7f 140 | 141 | /* 142 | * Supervisory LLC commands 143 | */ 144 | #define LLC_RR 0x01 145 | #define LLC_RNR 0x05 146 | #define LLC_REJ 0x09 147 | 148 | /* 149 | * Info format - dummy only 150 | */ 151 | #define LLC_INFO 0x00 152 | 153 | /* 154 | * ISO PDTR 10178 contains among others 155 | */ 156 | #define LLC_8021D_LSAP 0x42 157 | #define LLC_X25_LSAP 0x7e 158 | #define LLC_SNAP_LSAP 0xaa 159 | #define LLC_ISO_LSAP 0xfe 160 | 161 | #define RFC1042_LEN 6 162 | #define RFC1042 {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00} 163 | #define ETHERNET_TUNNEL {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8} 164 | 165 | /* 166 | * copied from sys/net/ethernet.h 167 | */ 168 | #define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */ 169 | #define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */ 170 | 171 | 172 | 173 | #endif /* _NET_IF_LLC_H_ */ 174 | -------------------------------------------------------------------------------- /include/lwip/tcpip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_TCPIP_H__ 33 | #define __LWIP_TCPIP_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #if !NO_SYS /* don't build if not configured for use in lwipopts.h */ 38 | 39 | #include "lwip/api_msg.h" 40 | #include "lwip/netifapi.h" 41 | #include "lwip/pbuf.h" 42 | #include "lwip/api.h" 43 | #include "lwip/sys.h" 44 | #include "lwip/timers.h" 45 | #include "lwip/netif.h" 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /** Define this to something that triggers a watchdog. This is called from 52 | * tcpip_thread after processing a message. */ 53 | #ifndef LWIP_TCPIP_THREAD_ALIVE 54 | #define LWIP_TCPIP_THREAD_ALIVE() 55 | #endif 56 | 57 | #if LWIP_TCPIP_CORE_LOCKING 58 | /** The global semaphore to lock the stack. */ 59 | extern sys_mutex_t lock_tcpip_core; 60 | #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core) 61 | #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core) 62 | #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m) 63 | #define TCPIP_APIMSG_ACK(m) 64 | #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m) 65 | #define TCPIP_NETIFAPI_ACK(m) 66 | #else /* LWIP_TCPIP_CORE_LOCKING */ 67 | #define LOCK_TCPIP_CORE() 68 | #define UNLOCK_TCPIP_CORE() 69 | #define TCPIP_APIMSG(m) tcpip_apimsg(m) 70 | #define TCPIP_APIMSG_ACK(m) sys_sem_signal(&m->conn->op_completed) 71 | #define TCPIP_NETIFAPI(m) tcpip_netifapi(m) 72 | #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem) 73 | #endif /* LWIP_TCPIP_CORE_LOCKING */ 74 | 75 | /** Function prototype for the init_done function passed to tcpip_init */ 76 | typedef void (*tcpip_init_done_fn)(void *arg); 77 | /** Function prototype for functions passed to tcpip_callback() */ 78 | typedef void (*tcpip_callback_fn)(void *ctx); 79 | 80 | void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg); 81 | 82 | #if LWIP_NETCONN 83 | err_t tcpip_apimsg(struct api_msg *apimsg); 84 | #if LWIP_TCPIP_CORE_LOCKING 85 | err_t tcpip_apimsg_lock(struct api_msg *apimsg); 86 | #endif /* LWIP_TCPIP_CORE_LOCKING */ 87 | #endif /* LWIP_NETCONN */ 88 | 89 | err_t tcpip_input(struct pbuf *p, struct netif *inp); 90 | 91 | #if LWIP_NETIF_API 92 | err_t tcpip_netifapi(struct netifapi_msg *netifapimsg); 93 | #if LWIP_TCPIP_CORE_LOCKING 94 | err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg); 95 | #endif /* LWIP_TCPIP_CORE_LOCKING */ 96 | #endif /* LWIP_NETIF_API */ 97 | 98 | err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block); 99 | #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) 100 | 101 | /* free pbufs or heap memory from another context without blocking */ 102 | err_t pbuf_free_callback(struct pbuf *p); 103 | err_t mem_free_callback(void *m); 104 | 105 | #if LWIP_TCPIP_TIMEOUT 106 | err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); 107 | err_t tcpip_untimeout(sys_timeout_handler h, void *arg); 108 | #endif /* LWIP_TCPIP_TIMEOUT */ 109 | 110 | enum tcpip_msg_type { 111 | #if LWIP_NETCONN 112 | TCPIP_MSG_API, 113 | #endif /* LWIP_NETCONN */ 114 | TCPIP_MSG_INPKT, 115 | #if LWIP_NETIF_API 116 | TCPIP_MSG_NETIFAPI, 117 | #endif /* LWIP_NETIF_API */ 118 | #if LWIP_TCPIP_TIMEOUT 119 | TCPIP_MSG_TIMEOUT, 120 | TCPIP_MSG_UNTIMEOUT, 121 | #endif /* LWIP_TCPIP_TIMEOUT */ 122 | TCPIP_MSG_CALLBACK 123 | }; 124 | 125 | struct tcpip_msg { 126 | enum tcpip_msg_type type; 127 | sys_sem_t *sem; 128 | union { 129 | #if LWIP_NETCONN 130 | struct api_msg *apimsg; 131 | #endif /* LWIP_NETCONN */ 132 | #if LWIP_NETIF_API 133 | struct netifapi_msg *netifapimsg; 134 | #endif /* LWIP_NETIF_API */ 135 | struct { 136 | struct pbuf *p; 137 | struct netif *netif; 138 | } inp; 139 | struct { 140 | tcpip_callback_fn function; 141 | void *ctx; 142 | } cb; 143 | #if LWIP_TCPIP_TIMEOUT 144 | struct { 145 | u32_t msecs; 146 | sys_timeout_handler h; 147 | void *arg; 148 | } tmo; 149 | #endif /* LWIP_TCPIP_TIMEOUT */ 150 | } msg; 151 | }; 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif 156 | 157 | #endif /* !NO_SYS */ 158 | 159 | #endif /* __LWIP_TCPIP_H__ */ 160 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # tnx to mamalala 2 | # Changelog 3 | # Changed the variables to include the header file directory 4 | # Added global var for the XTENSA tool root 5 | # 6 | # This make file still needs some work. 7 | # 8 | # 9 | # Output directors to store intermediate compiled files 10 | # relative to the project directory 11 | BUILD_BASE = build 12 | FW_BASE = firmware 13 | 14 | # Base directory for the compiler 15 | XTENSA_TOOLS_ROOT ?= D:/ESP8266/Projects/esp8266/xtensa-lx106-elf-161014/xtensa-lx106-elf/bin 16 | 17 | #Extra Tensilica includes from the ESS VM 18 | SDK_EXTRA_INCLUDES ?= D:/ESP8266/Projects/esp8266/esp_iot_sdk_v0.9.3/include 19 | SDK_EXTRA_LIBS ?= D:/ESP8266/Projects/esp8266/esp_iot_sdk_v0.9.3/lib 20 | 21 | # base directory of the ESP8266 SDK package, absolute 22 | SDK_BASE ?= D:/ESP8266/Projects/esp8266/esp_iot_sdk_v0.9.3 23 | 24 | #Esptool.py path and port 25 | ESPTOOL ?= esptool 26 | ESPPORT ?= /dev/ttyUSB0 27 | #ESPDELAY indicates seconds to wait between flashing the two binary images 28 | ESPDELAY ?= 3 29 | ESPBAUD ?= 115200 30 | 31 | # name for the target project 32 | TARGET = httpd 33 | 34 | # which modules (subdirectories) of the project to include in compiling 35 | #MODULES = driver user lwip/api lwip/app lwip/core lwip/core/ipv4 lwip/netif 36 | MODULES = driver user 37 | EXTRA_INCDIR = include \ 38 | . \ 39 | lib/heatshrink/ \ 40 | $(SDK_EXTRA_INCLUDES) 41 | 42 | # libraries used in this project, mainly provided by the SDK 43 | LIBS = c gcc hal phy pp net80211 wpa main lwip 44 | 45 | # compiler flags using during compilation of source files 46 | CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ 47 | -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \ 48 | -DLWIP_OPEN_SRC -Wno-address 49 | 50 | # linker flags used to generate the main object file 51 | LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -L$(SDK_EXTRA_LIBS) 52 | 53 | # linker script used for the above linkier step 54 | LD_SCRIPT = eagle.app.v6.ld 55 | 56 | # various paths from the SDK used in this project 57 | SDK_LIBDIR = lib 58 | SDK_LDDIR = ld 59 | SDK_INCDIR = include include/json 60 | 61 | # we create two different files for uploading into the flash 62 | # these are the names and options to generate them 63 | FW_FILE_1 = 0x00000 64 | FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec 65 | FW_FILE_2 = 0x40000 66 | FW_FILE_2_ARGS = -es .irom0.text $@ -ec 67 | 68 | # select which tools to use as compiler, librarian and linker 69 | CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 70 | AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar 71 | LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 72 | 73 | 74 | 75 | #### 76 | #### no user configurable options below here 77 | #### 78 | SRC_DIR := $(MODULES) 79 | BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) 80 | 81 | SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) 82 | SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) 83 | 84 | SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) 85 | OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) 86 | LIBS := $(addprefix -l,$(LIBS)) 87 | APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) 88 | TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) 89 | 90 | LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) 91 | 92 | INCDIR := $(addprefix -I,$(SRC_DIR)) 93 | EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) 94 | MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) 95 | 96 | FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) 97 | FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) 98 | 99 | V ?= $(VERBOSE) 100 | ifeq ("$(V)","1") 101 | Q := 102 | vecho := @true 103 | else 104 | Q := @ 105 | vecho := @echo 106 | endif 107 | 108 | vpath %.c $(SRC_DIR) 109 | 110 | define compile-objects 111 | $1/%.o: %.c 112 | $(vecho) "CC $$<" 113 | $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ 114 | endef 115 | 116 | .PHONY: all checkdirs clean 117 | 118 | all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) 119 | 120 | $(FW_FILE_1): $(TARGET_OUT) firmware 121 | $(vecho) "FW $@" 122 | $(Q) $(ESPTOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS) 123 | 124 | $(FW_FILE_2): $(TARGET_OUT) firmware 125 | $(vecho) "FW $@" 126 | $(Q) $(ESPTOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS) 127 | 128 | $(TARGET_OUT): $(APP_AR) 129 | $(vecho) "LD $@" 130 | $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ 131 | 132 | $(APP_AR): $(OBJ) 133 | $(vecho) "AR $@" 134 | $(Q) $(AR) cru $@ $^ 135 | 136 | checkdirs: $(BUILD_DIR) $(FW_BASE) 137 | 138 | $(BUILD_DIR): 139 | $(Q) mkdir -p $@ 140 | 141 | firmware: 142 | $(Q) mkdir -p $@ 143 | 144 | flash: $(FW_FILE_1) $(FW_FILE_2) 145 | $(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x00000 -cf firmware/0x00000.bin -v 146 | $(Q) [ $(ESPDELAY) -ne 0 ] && echo "Please put the ESP in bootloader mode..." 147 | $(Q) sleep $(ESPDELAY) 148 | $(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x40000 -cf firmware/0x40000.bin -v 149 | 150 | webpages.espfs: html/ html/wifi/ mkespfsimage/mkespfsimage 151 | cd html; find | ../mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. 152 | 153 | mkespfsimage/mkespfsimage: mkespfsimage/ 154 | make -C mkespfsimage 155 | 156 | htmlflash: webpages.espfs 157 | if [ $$(stat -c '%s' webpages.espfs) -gt $$(( 0x2E000 )) ]; then echo "webpages.espfs too big!"; false; fi 158 | $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x12000 -cf webpages.espfs -v 159 | 160 | clean: 161 | $(Q) rm -f $(APP_AR) 162 | $(Q) rm -f $(TARGET_OUT) 163 | $(Q) find $(BUILD_BASE) -type f | xargs rm -f 164 | 165 | 166 | $(Q) rm -f $(FW_FILE_1) 167 | $(Q) rm -f $(FW_FILE_2) 168 | $(Q) rm -rf $(FW_BASE) 169 | 170 | $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) 171 | -------------------------------------------------------------------------------- /mkespfsimage/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "espfsformat.h" 12 | 13 | //Heatshrink 14 | #include "heatshrink_common.h" 15 | #include "heatshrink_config.h" 16 | #include "heatshrink_encoder.h" 17 | 18 | 19 | //Routines to convert host format to the endianness used in the xtensa 20 | short htoxs(short in) { 21 | char r[2]; 22 | r[0]=in; 23 | r[1]=in>>8; 24 | return *((short *)r); 25 | } 26 | 27 | int htoxl(int in) { 28 | unsigned char r[4]; 29 | r[0]=in; 30 | r[1]=in>>8; 31 | r[2]=in>>16; 32 | r[3]=in>>24; 33 | return *((int *)r); 34 | } 35 | 36 | size_t compressHeatshrink(char *in, int insize, char *out, int outsize, int level) { 37 | char *inp=in; 38 | char *outp=out; 39 | size_t len; 40 | int ws[]={5, 6, 8, 11, 13}; 41 | int ls[]={3, 3, 4, 4, 4}; 42 | HSE_poll_res pres; 43 | HSE_sink_res sres; 44 | size_t r; 45 | if (level==-1) level=8; 46 | level=(level-1)/2; //level is now 0, 1, 2, 3, 4 47 | heatshrink_encoder *enc=heatshrink_encoder_alloc(ws[level], ls[level]); 48 | if (enc==NULL) { 49 | perror("allocating mem for heatshrink"); 50 | exit(1); 51 | } 52 | //Save encoder parms as first byte 53 | *outp=(ws[level]<<4)|ls[level]; 54 | outp++; outsize--; 55 | 56 | r=1; 57 | do { 58 | if (insize>0) { 59 | sres=heatshrink_encoder_sink(enc, inp, insize, &len); 60 | if (sres!=HSER_SINK_OK) break; 61 | inp+=len; insize-=len; 62 | if (insize==0) heatshrink_encoder_finish(enc); 63 | } 64 | do { 65 | pres=heatshrink_encoder_poll(enc, outp, outsize, &len); 66 | if (pres!=HSER_POLL_MORE && pres!=HSER_POLL_EMPTY) break; 67 | outp+=len; outsize-=len; 68 | r+=len; 69 | } while (pres==HSER_POLL_MORE); 70 | } while (insize!=0); 71 | 72 | if (insize!=0) { 73 | fprintf(stderr, "Heatshrink: Bug? insize is still %d. sres=%d pres=%d\n", insize, sres, pres); 74 | exit(1); 75 | } 76 | 77 | heatshrink_encoder_free(enc); 78 | return r; 79 | } 80 | 81 | int handleFile(int f, char *name, int compression, int level) { 82 | char *fdat, *cdat; 83 | off_t size, csize; 84 | EspFsHeader h; 85 | int nameLen; 86 | size=lseek(f, 0, SEEK_END); 87 | fdat=mmap(NULL, size, PROT_READ, MAP_SHARED, f, 0); 88 | if (fdat==MAP_FAILED) { 89 | perror("mmap"); 90 | return 0; 91 | } 92 | 93 | if (compression==COMPRESS_NONE) { 94 | csize=size; 95 | cdat=fdat; 96 | } else if (compression==COMPRESS_HEATSHRINK) { 97 | cdat=malloc(size*2); 98 | csize=compressHeatshrink(fdat, size, cdat, size*2, level); 99 | } else { 100 | fprintf(stderr, "Unknown compression - %d\n", compression); 101 | exit(1); 102 | } 103 | 104 | if (csize>size) { 105 | //Compressing enbiggened this file. Revert to uncompressed store. 106 | compression=COMPRESS_NONE; 107 | csize=size; 108 | cdat=fdat; 109 | } 110 | 111 | //Fill header data 112 | h.magic=('E'<<0)+('S'<<8)+('f'<<16)+('s'<<24); 113 | h.flags=0; 114 | h.compression=compression; 115 | nameLen=strlen(name)+1; 116 | if (nameLen&3) nameLen+=4-(nameLen&3); //Round to next 32bit boundary 117 | h.nameLen=htoxs(nameLen); 118 | h.fileLenComp=htoxl(csize); 119 | h.fileLenDecomp=htoxl(size); 120 | 121 | write(1, &h, sizeof(EspFsHeader)); 122 | write(1, name, nameLen); //ToDo: this can eat up a few bytes after the buffer. 123 | write(1, cdat, csize); 124 | //Pad out to 32bit boundary 125 | while (csize&3) { 126 | write(1, "\000", 1); 127 | csize++; 128 | } 129 | munmap(fdat, size); 130 | return (csize*100)/size; 131 | } 132 | 133 | //Write final dummy header with FLAG_LASTFILE set. 134 | void finishArchive() { 135 | EspFsHeader h; 136 | h.magic=('E'<<0)+('S'<<8)+('f'<<16)+('s'<<24); 137 | h.flags=FLAG_LASTFILE; 138 | h.compression=COMPRESS_NONE; 139 | h.nameLen=htoxs(0); 140 | h.fileLenComp=htoxl(0); 141 | h.fileLenDecomp=htoxl(0); 142 | write(1, &h, sizeof(EspFsHeader)); 143 | } 144 | 145 | 146 | int main(int argc, char **argv) { 147 | int f, x; 148 | char fileName[1024]; 149 | char *realName; 150 | struct stat statBuf; 151 | int serr; 152 | int rate; 153 | int err=0; 154 | int compType=1; //default compression type - heatshrink 155 | int compLvl=-1; 156 | 157 | for (x=1; x=x-2) { 159 | compType=atoi(argv[x=1]); 160 | x++; 161 | } else if (strcmp(argv[x], "-l")==0 && argc>=x-2) { 162 | compLvl=atoi(argv[x=1]); 163 | if (compLvl<1 || compLvl>9) err=1; 164 | x++; 165 | } else { 166 | err=1; 167 | } 168 | } 169 | 170 | if (err) { 171 | fprintf(stderr, "%s - Program to create espfs images\n", argv[0]); 172 | fprintf(stderr, "Usage: \nfind | %s [-c compressor] [-l compression_level] > out.espfs\n", argv[0]); 173 | fprintf(stderr, "Compressors:\n0 - None\n1 - Heatshrink(defautl\n"); 174 | fprintf(stderr, "Compression level: 1 is worst but low RAM usage, higher is better compression \nbut uses more ram on decompression. -1 = compressors default.\n"); 175 | exit(0); 176 | } 177 | 178 | while(fgets(fileName, sizeof(fileName), stdin)) { 179 | //Kill off '\n' at the end 180 | fileName[strlen(fileName)-1]=0; 181 | //Only include files 182 | serr=stat(fileName, &statBuf); 183 | if ((serr==0) && S_ISREG(statBuf.st_mode)) { 184 | //Strip off './' or '/' madness. 185 | realName=fileName; 186 | if (fileName[0]=='.') realName++; 187 | if (realName[0]=='/') realName++; 188 | f=open(fileName, O_RDONLY); 189 | if (f>0) { 190 | rate=handleFile(f, realName, compType, compLvl); 191 | fprintf(stderr, "%s (%d%%)\n", realName, rate); 192 | close(f); 193 | } else { 194 | perror(fileName); 195 | } 196 | } else { 197 | if (serr!=0) { 198 | perror(fileName); 199 | } 200 | } 201 | } 202 | finishArchive(); 203 | return 0; 204 | } 205 | 206 | -------------------------------------------------------------------------------- /include/lwip/dns.h: -------------------------------------------------------------------------------- 1 | /** 2 | * lwip DNS resolver header file. 3 | 4 | * Author: Jim Pettinato 5 | * April 2007 6 | 7 | * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. The name of the author may not be used to endorse or promote 18 | * products derived from this software without specific prior 19 | * written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __LWIP_DNS_H__ 35 | #define __LWIP_DNS_H__ 36 | 37 | #include "lwip/opt.h" 38 | 39 | #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */ 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /** DNS timer period */ 46 | #define DNS_TMR_INTERVAL 1000 47 | 48 | /** DNS field TYPE used for "Resource Records" */ 49 | #define DNS_RRTYPE_A 1 /* a host address */ 50 | #define DNS_RRTYPE_NS 2 /* an authoritative name server */ 51 | #define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */ 52 | #define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */ 53 | #define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */ 54 | #define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */ 55 | #define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */ 56 | #define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */ 57 | #define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */ 58 | #define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */ 59 | #define DNS_RRTYPE_WKS 11 /* a well known service description */ 60 | #define DNS_RRTYPE_PTR 12 /* a domain name pointer */ 61 | #define DNS_RRTYPE_HINFO 13 /* host information */ 62 | #define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */ 63 | #define DNS_RRTYPE_MX 15 /* mail exchange */ 64 | #define DNS_RRTYPE_TXT 16 /* text strings */ 65 | 66 | /** DNS field CLASS used for "Resource Records" */ 67 | #define DNS_RRCLASS_IN 1 /* the Internet */ 68 | #define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */ 69 | #define DNS_RRCLASS_CH 3 /* the CHAOS class */ 70 | #define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ 71 | #define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ 72 | 73 | /* The size used for the next line is rather a hack, but it prevents including socket.h in all files 74 | that include memp.h, and that would possibly break portability (since socket.h defines some types 75 | and constants possibly already define by the OS). 76 | Calculation rule: 77 | sizeof(struct addrinfo) + sizeof(struct sockaddr_in) + DNS_MAX_NAME_LENGTH + 1 byte zero-termination */ 78 | #define NETDB_ELEM_SIZE (32 + 16 + DNS_MAX_NAME_LENGTH + 1) 79 | 80 | #if DNS_LOCAL_HOSTLIST 81 | /** struct used for local host-list */ 82 | struct local_hostlist_entry { 83 | /** static hostname */ 84 | const char *name; 85 | /** static host address in network byteorder */ 86 | ip_addr_t addr; 87 | struct local_hostlist_entry *next; 88 | }; 89 | #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 90 | #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN 91 | #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH 92 | #endif 93 | #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1)) 94 | #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 95 | #endif /* DNS_LOCAL_HOSTLIST */ 96 | 97 | /** Callback which is invoked when a hostname is found. 98 | * A function of this type must be implemented by the application using the DNS resolver. 99 | * @param name pointer to the name that was looked up. 100 | * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname, 101 | * or NULL if the name could not be found (or on any other error). 102 | * @param callback_arg a user-specified callback argument passed to dns_gethostbyname 103 | */ 104 | typedef void (*dns_found_callback)(const char *name, ip_addr_t *ipaddr, void *callback_arg); 105 | 106 | void dns_init(void); 107 | void dns_tmr(void); 108 | void dns_setserver(u8_t numdns, ip_addr_t *dnsserver); 109 | ip_addr_t dns_getserver(u8_t numdns); 110 | err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr, 111 | dns_found_callback found, void *callback_arg); 112 | 113 | #if DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC 114 | int dns_local_removehost(const char *hostname, const ip_addr_t *addr); 115 | err_t dns_local_addhost(const char *hostname, const ip_addr_t *addr); 116 | #endif /* DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* LWIP_DNS */ 123 | 124 | #endif /* __LWIP_DNS_H__ */ 125 | -------------------------------------------------------------------------------- /include/lwip/memp_std.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SETUP: Make sure we define everything we will need. 3 | * 4 | * We have create three types of pools: 5 | * 1) MEMPOOL - standard pools 6 | * 2) MALLOC_MEMPOOL - to be used by mem_malloc in mem.c 7 | * 3) PBUF_MEMPOOL - a mempool of pbuf's, so include space for the pbuf struct 8 | * 9 | * If the include'r doesn't require any special treatment of each of the types 10 | * above, then will declare #2 & #3 to be just standard mempools. 11 | */ 12 | #ifndef LWIP_MALLOC_MEMPOOL 13 | /* This treats "malloc pools" just like any other pool. 14 | The pools are a little bigger to provide 'size' as the amount of user data. */ 15 | #define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + sizeof(struct memp_malloc_helper)), "MALLOC_"#size, attr) 16 | #define LWIP_MALLOC_MEMPOOL_START 17 | #define LWIP_MALLOC_MEMPOOL_END 18 | #endif /* LWIP_MALLOC_MEMPOOL */ 19 | 20 | #ifndef LWIP_PBUF_MEMPOOL 21 | /* This treats "pbuf pools" just like any other pool. 22 | * Allocates buffers for a pbuf struct AND a payload size */ 23 | #define LWIP_PBUF_MEMPOOL(name, num, payload, desc, attr) LWIP_MEMPOOL(name, num, (MEMP_ALIGN_SIZE(sizeof(struct pbuf)) + MEMP_ALIGN_SIZE(payload)), desc, attr) 24 | #endif /* LWIP_PBUF_MEMPOOL */ 25 | 26 | 27 | /* 28 | * A list of internal pools used by LWIP. 29 | * 30 | * LWIP_MEMPOOL(pool_name, number_elements, element_size, pool_description) 31 | * creates a pool name MEMP_pool_name. description is used in stats.c 32 | */ 33 | #if LWIP_RAW 34 | LWIP_MEMPOOL(RAW_PCB, MEMP_NUM_RAW_PCB, sizeof(struct raw_pcb), "RAW_PCB", DMEM_ATTR) 35 | #endif /* LWIP_RAW */ 36 | 37 | #if LWIP_UDP 38 | LWIP_MEMPOOL(UDP_PCB, MEMP_NUM_UDP_PCB, sizeof(struct udp_pcb), "UDP_PCB", DMEM_ATTR) 39 | #endif /* LWIP_UDP */ 40 | 41 | #if LWIP_TCP 42 | LWIP_MEMPOOL(TCP_PCB, MEMP_NUM_TCP_PCB, sizeof(struct tcp_pcb), "TCP_PCB", DMEM_ATTR) 43 | LWIP_MEMPOOL(TCP_PCB_LISTEN, MEMP_NUM_TCP_PCB_LISTEN, sizeof(struct tcp_pcb_listen), "TCP_PCB_LISTEN", DMEM_ATTR) 44 | LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg), "TCP_SEG", DMEM_ATTR) 45 | #endif /* LWIP_TCP */ 46 | 47 | #if IP_REASSEMBLY 48 | LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA", DMEM_ATTR) 49 | #endif /* IP_REASSEMBLY */ 50 | #if IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF 51 | LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF", DMEM_ATTR) 52 | #endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ 53 | 54 | #if LWIP_NETCONN 55 | LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF") 56 | LWIP_MEMPOOL(NETCONN, MEMP_NUM_NETCONN, sizeof(struct netconn), "NETCONN") 57 | #endif /* LWIP_NETCONN */ 58 | 59 | #if NO_SYS==0 60 | LWIP_MEMPOOL(TCPIP_MSG_API, MEMP_NUM_TCPIP_MSG_API, sizeof(struct tcpip_msg), "TCPIP_MSG_API") 61 | #if !LWIP_TCPIP_CORE_LOCKING_INPUT 62 | LWIP_MEMPOOL(TCPIP_MSG_INPKT,MEMP_NUM_TCPIP_MSG_INPKT, sizeof(struct tcpip_msg), "TCPIP_MSG_INPKT") 63 | #endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ 64 | #endif /* NO_SYS==0 */ 65 | 66 | #if ARP_QUEUEING 67 | LWIP_MEMPOOL(ARP_QUEUE, MEMP_NUM_ARP_QUEUE, sizeof(struct etharp_q_entry), "ARP_QUEUE", DMEM_ATTR) 68 | #endif /* ARP_QUEUEING */ 69 | 70 | #if LWIP_IGMP 71 | LWIP_MEMPOOL(IGMP_GROUP, MEMP_NUM_IGMP_GROUP, sizeof(struct igmp_group), "IGMP_GROUP", DMEM_ATTR) 72 | #endif /* LWIP_IGMP */ 73 | 74 | #if (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) /* LWIP_TIMERS */ 75 | LWIP_MEMPOOL(SYS_TIMEOUT, MEMP_NUM_SYS_TIMEOUT, sizeof(struct sys_timeo), "SYS_TIMEOUT", DMEM_ATTR) 76 | #endif /* LWIP_TIMERS */ 77 | 78 | #if LWIP_SNMP 79 | LWIP_MEMPOOL(SNMP_ROOTNODE, MEMP_NUM_SNMP_ROOTNODE, sizeof(struct mib_list_rootnode), "SNMP_ROOTNODE") 80 | LWIP_MEMPOOL(SNMP_NODE, MEMP_NUM_SNMP_NODE, sizeof(struct mib_list_node), "SNMP_NODE") 81 | LWIP_MEMPOOL(SNMP_VARBIND, MEMP_NUM_SNMP_VARBIND, sizeof(struct snmp_varbind), "SNMP_VARBIND") 82 | LWIP_MEMPOOL(SNMP_VALUE, MEMP_NUM_SNMP_VALUE, SNMP_MAX_VALUE_SIZE, "SNMP_VALUE") 83 | #endif /* LWIP_SNMP */ 84 | #if LWIP_DNS && LWIP_SOCKET 85 | LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE, "NETDB") 86 | #endif /* LWIP_DNS && LWIP_SOCKET */ 87 | #if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC 88 | LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST") 89 | #endif /* LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 90 | #if PPP_SUPPORT && PPPOE_SUPPORT 91 | LWIP_MEMPOOL(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF") 92 | #endif /* PPP_SUPPORT && PPPOE_SUPPORT */ 93 | 94 | /* 95 | * A list of pools of pbuf's used by LWIP. 96 | * 97 | * LWIP_PBUF_MEMPOOL(pool_name, number_elements, pbuf_payload_size, pool_description) 98 | * creates a pool name MEMP_pool_name. description is used in stats.c 99 | * This allocates enough space for the pbuf struct and a payload. 100 | * (Example: pbuf_payload_size=0 allocates only size for the struct) 101 | */ 102 | LWIP_PBUF_MEMPOOL(PBUF, MEMP_NUM_PBUF, 0, "PBUF_REF/ROM", DMEM_ATTR) 103 | 104 | /* XXX: need to align to 4 byte as memp strcut is 4-byte long. otherwise will crash */ 105 | #define LWIP_MEM_ALIGN4_SIZE(size) (((size) + 4 - 1) & ~(4-1)) 106 | 107 | LWIP_PBUF_MEMPOOL(PBUF_POOL, PBUF_POOL_SIZE, LWIP_MEM_ALIGN4_SIZE(PBUF_POOL_BUFSIZE), "PBUF_POOL", DMEM_ATTR) 108 | 109 | 110 | /* 111 | * Allow for user-defined pools; this must be explicitly set in lwipopts.h 112 | * since the default is to NOT look for lwippools.h 113 | */ 114 | #if MEMP_USE_CUSTOM_POOLS 115 | #include "lwippools.h" 116 | #endif /* MEMP_USE_CUSTOM_POOLS */ 117 | 118 | /* 119 | * REQUIRED CLEANUP: Clear up so we don't get "multiply defined" error later 120 | * (#undef is ignored for something that is not defined) 121 | */ 122 | #undef LWIP_MEMPOOL 123 | #undef LWIP_MALLOC_MEMPOOL 124 | #undef LWIP_MALLOC_MEMPOOL_START 125 | #undef LWIP_MALLOC_MEMPOOL_END 126 | #undef LWIP_PBUF_MEMPOOL 127 | -------------------------------------------------------------------------------- /include/lwip/api_msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_API_MSG_H__ 33 | #define __LWIP_API_MSG_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ 38 | 39 | #include /* for size_t */ 40 | 41 | #include "lwip/ip_addr.h" 42 | #include "lwip/err.h" 43 | #include "lwip/sys.h" 44 | #include "lwip/igmp.h" 45 | #include "lwip/api.h" 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /* For the netconn API, these values are use as a bitmask! */ 52 | #define NETCONN_SHUT_RD 1 53 | #define NETCONN_SHUT_WR 2 54 | #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR) 55 | 56 | /* IP addresses and port numbers are expected to be in 57 | * the same byte order as in the corresponding pcb. 58 | */ 59 | /** This struct includes everything that is necessary to execute a function 60 | for a netconn in another thread context (mainly used to process netconns 61 | in the tcpip_thread context to be thread safe). */ 62 | struct api_msg_msg { 63 | /** The netconn which to process - always needed: it includes the semaphore 64 | which is used to block the application thread until the function finished. */ 65 | struct netconn *conn; 66 | /** The return value of the function executed in tcpip_thread. */ 67 | err_t err; 68 | /** Depending on the executed function, one of these union members is used */ 69 | union { 70 | /** used for do_send */ 71 | struct netbuf *b; 72 | /** used for do_newconn */ 73 | struct { 74 | u8_t proto; 75 | } n; 76 | /** used for do_bind and do_connect */ 77 | struct { 78 | ip_addr_t *ipaddr; 79 | u16_t port; 80 | } bc; 81 | /** used for do_getaddr */ 82 | struct { 83 | ip_addr_t *ipaddr; 84 | u16_t *port; 85 | u8_t local; 86 | } ad; 87 | /** used for do_write */ 88 | struct { 89 | const void *dataptr; 90 | size_t len; 91 | u8_t apiflags; 92 | } w; 93 | /** used for do_recv */ 94 | struct { 95 | u32_t len; 96 | } r; 97 | /** used for do_close (/shutdown) */ 98 | struct { 99 | u8_t shut; 100 | } sd; 101 | #if LWIP_IGMP 102 | /** used for do_join_leave_group */ 103 | struct { 104 | ip_addr_t *multiaddr; 105 | ip_addr_t *netif_addr; 106 | enum netconn_igmp join_or_leave; 107 | } jl; 108 | #endif /* LWIP_IGMP */ 109 | #if TCP_LISTEN_BACKLOG 110 | struct { 111 | u8_t backlog; 112 | } lb; 113 | #endif /* TCP_LISTEN_BACKLOG */ 114 | } msg; 115 | }; 116 | 117 | /** This struct contains a function to execute in another thread context and 118 | a struct api_msg_msg that serves as an argument for this function. 119 | This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */ 120 | struct api_msg { 121 | /** function to execute in tcpip_thread context */ 122 | void (* function)(struct api_msg_msg *msg); 123 | /** arguments for this function */ 124 | struct api_msg_msg msg; 125 | }; 126 | 127 | #if LWIP_DNS 128 | /** As do_gethostbyname requires more arguments but doesn't require a netconn, 129 | it has its own struct (to avoid struct api_msg getting bigger than necessary). 130 | do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg 131 | (see netconn_gethostbyname). */ 132 | struct dns_api_msg { 133 | /** Hostname to query or dotted IP address string */ 134 | const char *name; 135 | /** Rhe resolved address is stored here */ 136 | ip_addr_t *addr; 137 | /** This semaphore is posted when the name is resolved, the application thread 138 | should wait on it. */ 139 | sys_sem_t *sem; 140 | /** Errors are given back here */ 141 | err_t *err; 142 | }; 143 | #endif /* LWIP_DNS */ 144 | 145 | void do_newconn ( struct api_msg_msg *msg); 146 | void do_delconn ( struct api_msg_msg *msg); 147 | void do_bind ( struct api_msg_msg *msg); 148 | void do_connect ( struct api_msg_msg *msg); 149 | void do_disconnect ( struct api_msg_msg *msg); 150 | void do_listen ( struct api_msg_msg *msg); 151 | void do_send ( struct api_msg_msg *msg); 152 | void do_recv ( struct api_msg_msg *msg); 153 | void do_write ( struct api_msg_msg *msg); 154 | void do_getaddr ( struct api_msg_msg *msg); 155 | void do_close ( struct api_msg_msg *msg); 156 | void do_shutdown ( struct api_msg_msg *msg); 157 | #if LWIP_IGMP 158 | void do_join_leave_group( struct api_msg_msg *msg); 159 | #endif /* LWIP_IGMP */ 160 | 161 | #if LWIP_DNS 162 | void do_gethostbyname(void *arg); 163 | #endif /* LWIP_DNS */ 164 | 165 | struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback); 166 | void netconn_free(struct netconn *conn); 167 | 168 | #ifdef __cplusplus 169 | } 170 | #endif 171 | 172 | #endif /* LWIP_NETCONN */ 173 | 174 | #endif /* __LWIP_API_MSG_H__ */ 175 | -------------------------------------------------------------------------------- /include/lwip/pbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_PBUF_H__ 34 | #define __LWIP_PBUF_H__ 35 | 36 | #include "lwip/opt.h" 37 | #include "lwip/err.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** Currently, the pbuf_custom code is only needed for one specific configuration 44 | * of IP_FRAG */ 45 | #define LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) 46 | 47 | #define PBUF_TRANSPORT_HLEN 20 48 | #define PBUF_IP_HLEN 20 49 | 50 | typedef enum { 51 | PBUF_TRANSPORT, 52 | PBUF_IP, 53 | PBUF_LINK, 54 | PBUF_RAW 55 | } pbuf_layer; 56 | 57 | typedef enum { 58 | PBUF_RAM, /* pbuf data is stored in RAM */ 59 | PBUF_ROM, /* pbuf data is stored in ROM */ 60 | PBUF_REF, /* pbuf comes from the pbuf pool */ 61 | PBUF_POOL, /* pbuf payload refers to RAM */ 62 | #ifdef EBUF_LWIP 63 | PBUF_ESF_RX /* pbuf payload is from WLAN */ 64 | #endif /* ESF_LWIP */ 65 | } pbuf_type; 66 | 67 | 68 | /** indicates this packet's data should be immediately passed to the application */ 69 | #define PBUF_FLAG_PUSH 0x01U 70 | /** indicates this is a custom pbuf: pbuf_free and pbuf_header handle such a 71 | a pbuf differently */ 72 | #define PBUF_FLAG_IS_CUSTOM 0x02U 73 | /** indicates this pbuf is UDP multicast to be looped back */ 74 | #define PBUF_FLAG_MCASTLOOP 0x04U 75 | 76 | struct pbuf { 77 | /** next pbuf in singly linked pbuf chain */ 78 | struct pbuf *next; 79 | 80 | /** pointer to the actual data in the buffer */ 81 | void *payload; 82 | 83 | /** 84 | * total length of this buffer and all next buffers in chain 85 | * belonging to the same packet. 86 | * 87 | * For non-queue packet chains this is the invariant: 88 | * p->tot_len == p->len + (p->next? p->next->tot_len: 0) 89 | */ 90 | u16_t tot_len; 91 | 92 | /** length of this buffer */ 93 | u16_t len; 94 | 95 | /** pbuf_type as u8_t instead of enum to save space */ 96 | u8_t /*pbuf_type*/ type; 97 | 98 | /** misc flags */ 99 | u8_t flags; 100 | 101 | /** 102 | * the reference count always equals the number of pointers 103 | * that refer to this pbuf. This can be pointers from an application, 104 | * the stack itself, or pbuf->next pointers from a chain. 105 | */ 106 | u16_t ref; 107 | 108 | /* add a pointer for esf_buf */ 109 | void * eb; 110 | }; 111 | 112 | #if LWIP_SUPPORT_CUSTOM_PBUF 113 | /** Prototype for a function to free a custom pbuf */ 114 | typedef void (*pbuf_free_custom_fn)(struct pbuf *p); 115 | 116 | /** A custom pbuf: like a pbuf, but following a function pointer to free it. */ 117 | struct pbuf_custom { 118 | /** The actual pbuf */ 119 | struct pbuf pbuf; 120 | /** This function is called when pbuf_free deallocates this pbuf(_custom) */ 121 | pbuf_free_custom_fn custom_free_function; 122 | }; 123 | #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ 124 | 125 | /* Initializes the pbuf module. This call is empty for now, but may not be in future. */ 126 | #define pbuf_init() 127 | 128 | struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)ICACHE_FLASH_ATTR; 129 | #if LWIP_SUPPORT_CUSTOM_PBUF 130 | struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, 131 | struct pbuf_custom *p, void *payload_mem, 132 | u16_t payload_mem_len)ICACHE_FLASH_ATTR; 133 | #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ 134 | void pbuf_realloc(struct pbuf *p, u16_t size)ICACHE_FLASH_ATTR; 135 | u8_t pbuf_header(struct pbuf *p, s16_t header_size)ICACHE_FLASH_ATTR; 136 | void pbuf_ref(struct pbuf *p)ICACHE_FLASH_ATTR; 137 | u8_t pbuf_free(struct pbuf *p)ICACHE_FLASH_ATTR; 138 | u8_t pbuf_clen(struct pbuf *p)ICACHE_FLASH_ATTR; 139 | void pbuf_cat(struct pbuf *head, struct pbuf *tail)ICACHE_FLASH_ATTR; 140 | void pbuf_chain(struct pbuf *head, struct pbuf *tail)ICACHE_FLASH_ATTR; 141 | struct pbuf *pbuf_dechain(struct pbuf *p)ICACHE_FLASH_ATTR; 142 | err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)ICACHE_FLASH_ATTR; 143 | u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset)ICACHE_FLASH_ATTR; 144 | err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)ICACHE_FLASH_ATTR; 145 | struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer)ICACHE_FLASH_ATTR; 146 | #if LWIP_CHECKSUM_ON_COPY 147 | err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, 148 | u16_t len, u16_t *chksum)ICACHE_FLASH_ATTR; 149 | #endif /* LWIP_CHECKSUM_ON_COPY */ 150 | 151 | u8_t pbuf_get_at(struct pbuf* p, u16_t offset)ICACHE_FLASH_ATTR; 152 | u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n)ICACHE_FLASH_ATTR; 153 | u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset)ICACHE_FLASH_ATTR; 154 | u16_t pbuf_strstr(struct pbuf* p, const char* substr)ICACHE_FLASH_ATTR; 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | 160 | #endif /* __LWIP_PBUF_H__ */ 161 | -------------------------------------------------------------------------------- /lib/heatshrink/test_heatshrink_static.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "heatshrink_encoder.h" 5 | #include "heatshrink_decoder.h" 6 | #include "greatest.h" 7 | 8 | #if HEATSHRINK_DYNAMIC_ALLOC 9 | #error HEATSHRINK_DYNAMIC_ALLOC must be false for static allocation test suite. 10 | #endif 11 | 12 | SUITE(integration); 13 | 14 | /* The majority of the tests are in test_heatshrink_dynamic, because that allows 15 | * instantiating encoders/decoders with different settings at run-time. */ 16 | 17 | static heatshrink_encoder hse; 18 | static heatshrink_decoder hsd; 19 | 20 | static void fill_with_pseudorandom_letters(uint8_t *buf, uint16_t size, uint32_t seed) { 21 | uint64_t rn = 9223372036854775783; /* prime under 2^64 */ 22 | for (int i=0; i 1) { 50 | printf("\n^^ COMPRESSING\n"); 51 | dump_buf("input", input, input_size); 52 | } 53 | 54 | uint32_t sunk = 0; 55 | uint32_t polled = 0; 56 | while (sunk < input_size) { 57 | ASSERT(heatshrink_encoder_sink(&hse, &input[sunk], input_size - sunk, &count) >= 0); 58 | sunk += count; 59 | if (log_lvl > 1) printf("^^ sunk %zd\n", count); 60 | if (sunk == input_size) { 61 | ASSERT_EQ(HSER_FINISH_MORE, heatshrink_encoder_finish(&hse)); 62 | } 63 | 64 | HSE_poll_res pres; 65 | do { /* "turn the crank" */ 66 | pres = heatshrink_encoder_poll(&hse, &comp[polled], comp_sz - polled, &count); 67 | ASSERT(pres >= 0); 68 | polled += count; 69 | if (log_lvl > 1) printf("^^ polled %zd\n", count); 70 | } while (pres == HSER_POLL_MORE); 71 | ASSERT_EQ(HSER_POLL_EMPTY, pres); 72 | if (polled >= comp_sz) FAILm("compression should never expand that much"); 73 | if (sunk == input_size) { 74 | ASSERT_EQ(HSER_FINISH_DONE, heatshrink_encoder_finish(&hse)); 75 | } 76 | } 77 | if (log_lvl > 0) printf("in: %u compressed: %u ", input_size, polled); 78 | uint32_t compressed_size = polled; 79 | sunk = 0; 80 | polled = 0; 81 | 82 | if (log_lvl > 1) { 83 | printf("\n^^ DECOMPRESSING\n"); 84 | dump_buf("comp", comp, compressed_size); 85 | } 86 | while (sunk < compressed_size) { 87 | ASSERT(heatshrink_decoder_sink(&hsd, &comp[sunk], compressed_size - sunk, &count) >= 0); 88 | sunk += count; 89 | if (log_lvl > 1) printf("^^ sunk %zd\n", count); 90 | if (sunk == compressed_size) { 91 | ASSERT_EQ(HSDR_FINISH_MORE, heatshrink_decoder_finish(&hsd)); 92 | } 93 | 94 | HSD_poll_res pres; 95 | do { 96 | pres = heatshrink_decoder_poll(&hsd, &decomp[polled], 97 | decomp_sz - polled, &count); 98 | ASSERT(pres >= 0); 99 | polled += count; 100 | if (log_lvl > 1) printf("^^ polled %zd\n", count); 101 | } while (pres == HSDR_POLL_MORE); 102 | ASSERT_EQ(HSDR_POLL_EMPTY, pres); 103 | if (sunk == compressed_size) { 104 | HSD_finish_res fres = heatshrink_decoder_finish(&hsd); 105 | ASSERT_EQ(HSDR_FINISH_DONE, fres); 106 | } 107 | 108 | if (polled > input_size) { 109 | FAILm("Decompressed data is larger than original input"); 110 | } 111 | } 112 | if (log_lvl > 0) printf("decompressed: %u\n", polled); 113 | if (polled != input_size) { 114 | FAILm("Decompressed length does not match original input length"); 115 | } 116 | 117 | if (log_lvl > 1) dump_buf("decomp", decomp, polled); 118 | for (size_t i=0; i out[%zd] == 0x%02x ('%c')\n", 124 | j, input[j], isprint(input[j]) ? input[j] : '.', 125 | j, decomp[j], isprint(decomp[j]) ? decomp[j] : '.'); 126 | } 127 | } 128 | } 129 | ASSERT_EQ(input[i], decomp[i]); 130 | } 131 | free(comp); 132 | free(decomp); 133 | PASS(); 134 | } 135 | 136 | TEST pseudorandom_data_should_match(uint32_t size, uint32_t seed) { 137 | uint8_t input[size]; 138 | fill_with_pseudorandom_letters(input, size, seed); 139 | return compress_and_expand_and_check(input, size, 0); 140 | } 141 | 142 | SUITE(integration) { 143 | #if __STDC_VERSION__ >= 19901L 144 | for (uint32_t size=1; size < 64*1024; size <<= 1) { 145 | if (GREATEST_IS_VERBOSE()) printf(" -- size %u\n", size); 146 | for (uint32_t seed=1; seed<=100; seed++) { 147 | if (GREATEST_IS_VERBOSE()) printf(" -- seed %u\n", seed); 148 | RUN_TESTp(pseudorandom_data_should_match, size, seed); 149 | } 150 | } 151 | #endif 152 | } 153 | 154 | /* Add all the definitions that need to be in the test runner's main file. */ 155 | GREATEST_MAIN_DEFS(); 156 | 157 | int main(int argc, char **argv) { 158 | GREATEST_MAIN_BEGIN(); /* command-line arguments, initialization. */ 159 | printf("INPUT_BUFFER_SIZE: %u\n", HEATSHRINK_STATIC_INPUT_BUFFER_SIZE); 160 | printf("WINDOW_BITS: %u\n", HEATSHRINK_STATIC_WINDOW_BITS); 161 | printf("LOOKAHEAD_BITS: %u\n", HEATSHRINK_STATIC_LOOKAHEAD_BITS); 162 | 163 | printf("sizeof(heatshrink_encoder): %zd\n", sizeof(heatshrink_encoder)); 164 | printf("sizeof(heatshrink_decoder): %zd\n", sizeof(heatshrink_decoder)); 165 | RUN_SUITE(integration); 166 | GREATEST_MAIN_END(); /* display results */ 167 | } 168 | --------------------------------------------------------------------------------