├── include ├── user_config.h └── uart_hw.h ├── libesphttpd ├── include │ ├── user_config.h │ ├── captdns.h │ ├── webpages-espfs.h │ ├── httpdespfs.h │ ├── cgiwifi.h │ ├── esp8266.h │ ├── cgiflash.h │ ├── auth.h │ ├── espfs.h │ ├── sha1.h │ ├── cgiwebsocket.h │ ├── httpd.h │ └── espmissingincludes.h ├── espfs │ ├── mkespfsimage │ │ ├── build-linux.sh │ │ ├── build-win32.sh │ │ ├── heatshrink_encoder.c │ │ ├── mman-win32 │ │ │ ├── config.mak │ │ │ ├── mman.sln │ │ │ ├── Makefile │ │ │ ├── mman.vcxproj.filters │ │ │ ├── mman.h │ │ │ ├── mman.vcxproj │ │ │ ├── configure │ │ │ ├── mman.c │ │ │ └── test.c │ │ ├── Makefile.linux │ │ ├── Makefile.windows │ │ └── Makefile │ ├── espfstest │ │ ├── Makefile │ │ └── main.c │ ├── heatshrink_decoder.c │ ├── espfs.h │ ├── heatshrink_config_custom.h │ ├── espfsformat.h │ └── espfs.c ├── core │ ├── base64.h │ ├── auth.c │ ├── base64.c │ ├── sha1.c │ └── httpdespfs.c ├── webpages.espfs.ld ├── lib │ └── heatshrink │ │ ├── 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 ├── Makefile └── util │ ├── cgiflash.c │ └── captdns.c ├── user ├── stack.c ├── stack.h ├── stdout.h ├── cgi.h ├── io.h ├── types.h ├── globals.h ├── esp_enc_api.h ├── stdout.c ├── timer.h ├── cgi.c ├── dhcpc.h ├── spi.h ├── timer.c ├── io.c ├── esp_enc_api.c ├── config.h ├── config.c └── user_main.c ├── html ├── wifi │ ├── icons.png │ ├── style.css │ ├── 140medley.min.js │ ├── connecting.html │ └── wifi.tpl ├── cats │ ├── cross-eyed-cat.jpg │ ├── junge-katze-iv.jpg │ └── kitten-loves-toy.jpg ├── style.css ├── led.tpl ├── flash │ ├── style.css │ ├── 140medley.min.js │ └── index.html ├── index.tpl └── websocket │ └── index.html ├── ethernet to esp wiring.png ├── .project ├── README.md ├── esphttpdconfig.mk ├── .cproject └── Makefile /include/user_config.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /libesphttpd/include/user_config.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /user/stack.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ESP32DE/esp_enc28j60/HEAD/user/stack.c -------------------------------------------------------------------------------- /user/stack.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ESP32DE/esp_enc28j60/HEAD/user/stack.h -------------------------------------------------------------------------------- /html/wifi/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ESP32DE/esp_enc28j60/HEAD/html/wifi/icons.png -------------------------------------------------------------------------------- /user/stdout.h: -------------------------------------------------------------------------------- 1 | #ifndef STDOUT_H 2 | #define STDOUT_H 3 | 4 | void stdoutInit(); 5 | 6 | #endif -------------------------------------------------------------------------------- /ethernet to esp wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ESP32DE/esp_enc28j60/HEAD/ethernet to esp wiring.png -------------------------------------------------------------------------------- /html/cats/cross-eyed-cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ESP32DE/esp_enc28j60/HEAD/html/cats/cross-eyed-cat.jpg -------------------------------------------------------------------------------- /html/cats/junge-katze-iv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ESP32DE/esp_enc28j60/HEAD/html/cats/junge-katze-iv.jpg -------------------------------------------------------------------------------- /html/cats/kitten-loves-toy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ESP32DE/esp_enc28j60/HEAD/html/cats/kitten-loves-toy.jpg -------------------------------------------------------------------------------- /libesphttpd/include/captdns.h: -------------------------------------------------------------------------------- 1 | #ifndef CAPTDNS_H 2 | #define CAPTDNS_H 3 | void ICACHE_FLASH_ATTR captdnsInit(void); 4 | 5 | #endif -------------------------------------------------------------------------------- /libesphttpd/include/webpages-espfs.h: -------------------------------------------------------------------------------- 1 | extern char webpages_espfs_start[]; 2 | extern char webpages_espfs_end[]; 3 | extern int webpages_espfs_size; 4 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/build-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | make -f Makefile.linux clean 4 | make -f Makefile.linux USE_HEATSHRINK="yes" GZIP_COMPRESSION="no" 5 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/build-win32.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd mman-win32 4 | ./configure && make 5 | cd .. 6 | make -f Makefile.windows clean 7 | make -f Makefile.windows USE_HEATSHRINK="yes" GZIP_COMPRESSION="no" 8 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/heatshrink_encoder.c: -------------------------------------------------------------------------------- 1 | //Stupid wraparound include to make sure object file doesn't end up in heatshrink dir 2 | #ifdef ESPFS_HEATSHRINK 3 | #include "../lib/heatshrink/heatshrink_encoder.c" 4 | #endif -------------------------------------------------------------------------------- /libesphttpd/include/httpdespfs.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPDESPFS_H 2 | #define HTTPDESPFS_H 3 | 4 | #include "httpd.h" 5 | 6 | int cgiEspFsHook(HttpdConnData *connData); 7 | int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData); 8 | 9 | #endif -------------------------------------------------------------------------------- /libesphttpd/core/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE64_H 2 | #define BASE64_H 3 | 4 | int base64_decode(size_t in_len, const char *in, size_t out_len, unsigned char *out); 5 | int base64_encode(size_t in_len, const unsigned char *in, size_t out_len, char *out); 6 | #endif -------------------------------------------------------------------------------- /user/cgi.h: -------------------------------------------------------------------------------- 1 | #ifndef CGI_H 2 | #define CGI_H 3 | 4 | #include "httpd.h" 5 | 6 | int cgiLed(HttpdConnData *connData); 7 | int tplLed(HttpdConnData *connData, char *token, void **arg); 8 | int tplCounter(HttpdConnData *connData, char *token, void **arg); 9 | 10 | #endif -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/config.mak: -------------------------------------------------------------------------------- 1 | # Automatically generated by configure 2 | PREFIX=/mingw 3 | libdir=/mingw/lib 4 | incdir=/mingw/include/sys 5 | AR=ar 6 | CC=gcc 7 | RANLIB=ranlib 8 | STRIP=strip 9 | BUILD_STATIC=yes 10 | BUILD_MSVC= 11 | LIBCMD=echo ignoring lib 12 | -------------------------------------------------------------------------------- /user/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | 4 | #define ENCRESETGPIO 4 5 | #define ENCINTGPIO 5 6 | #define BTNGPIO 0 7 | 8 | void ICACHE_FLASH_ATTR gpio16_output_set(uint8 value); 9 | 10 | void ICACHE_FLASH_ATTR ioLed(int ena); 11 | void ioInit(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /libesphttpd/webpages.espfs.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-xtensa-le") 2 | 3 | 4 | SECTIONS 5 | { 6 | .irom0.literal : ALIGN(4) SUBALIGN(4) { 7 | webpages_espfs_start = .; 8 | *(*) 9 | webpages_espfs_end = .; 10 | webpages_espfs_size = webpages_espfs_end - webpages_espfs_start; 11 | } 12 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /libesphttpd/espfs/espfstest/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-I../../lib/heatshrink -I.. -std=gnu99 -DESPFS_HEATSHRINK 2 | 3 | espfstest: main.o espfs.o heatshrink_decoder.o 4 | $(CC) -o $@ $^ 5 | 6 | espfs.o: ../espfs.c 7 | $(CC) $(CFLAGS) -c $^ -o $@ 8 | 9 | heatshrink_decoder.o: ../heatshrink_decoder.c 10 | $(CC) $(CFLAGS) -c $^ -o $@ 11 | 12 | clean: 13 | rm -f *.o espfstest 14 | -------------------------------------------------------------------------------- /libesphttpd/include/cgiwifi.h: -------------------------------------------------------------------------------- 1 | #ifndef CGIWIFI_H 2 | #define CGIWIFI_H 3 | 4 | #include "httpd.h" 5 | 6 | int cgiWiFiScan(HttpdConnData *connData); 7 | int tplWlan(HttpdConnData *connData, char *token, void **arg); 8 | int cgiWiFi(HttpdConnData *connData); 9 | int cgiWiFiConnect(HttpdConnData *connData); 10 | int cgiWiFiSetMode(HttpdConnData *connData); 11 | int cgiWiFiConnStatus(HttpdConnData *connData); 12 | 13 | #endif -------------------------------------------------------------------------------- /libesphttpd/include/esp8266.h: -------------------------------------------------------------------------------- 1 | // Combined include file for esp8266 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "espmissingincludes.h" 19 | 20 | -------------------------------------------------------------------------------- /html/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 | -------------------------------------------------------------------------------- /libesphttpd/espfs/heatshrink_decoder.c: -------------------------------------------------------------------------------- 1 | #include "espfs.h" 2 | #ifdef ESPFS_HEATSHRINK 3 | //Stupid wrapper so we don't have to move c-files around 4 | //Also loads httpd-specific config. 5 | 6 | #ifdef __ets__ 7 | //esp build 8 | 9 | #include 10 | 11 | #define memset(x,y,z) os_memset(x,y,z) 12 | #define memcpy(x,y,z) os_memcpy(x,y,z) 13 | #endif 14 | 15 | #include "heatshrink_config_custom.h" 16 | #include "../lib/heatshrink/heatshrink_decoder.c" 17 | 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /html/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 | } -------------------------------------------------------------------------------- /libesphttpd/include/cgiflash.h: -------------------------------------------------------------------------------- 1 | #ifndef CGIFLASH_H 2 | #define CGIFLASH_H 3 | 4 | #include "httpd.h" 5 | 6 | #define CGIFLASH_TYPE_FW 0 7 | #define CGIFLASH_TYPE_ESPFS 1 8 | 9 | typedef struct { 10 | int type; 11 | int fw1Pos; 12 | int fw2Pos; 13 | int fwSize; 14 | } CgiUploadFlashDef; 15 | 16 | int cgiReadFlash(HttpdConnData *connData); 17 | int cgiGetFirmwareNext(HttpdConnData *connData); 18 | int cgiUploadFirmware(HttpdConnData *connData); 19 | int cgiRebootFirmware(HttpdConnData *connData); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/Makefile.linux: -------------------------------------------------------------------------------- 1 | GZIP_COMPRESSION ?= no 2 | USE_HEATSHRINK ?= yes 3 | 4 | CFLAGS=-I../../lib/heatshrink -I../../include -I.. -std=gnu99 5 | ifeq ("$(GZIP_COMPRESSION)","yes") 6 | CFLAGS += -DESPFS_GZIP 7 | endif 8 | 9 | ifeq ("$(USE_HEATSHRINK)","yes") 10 | CFLAGS += -DESPFS_HEATSHRINK 11 | endif 12 | 13 | OBJS=main.o heatshrink_encoder.o 14 | TARGET=mkespfsimage 15 | 16 | $(TARGET): $(OBJS) 17 | ifeq ("$(GZIP_COMPRESSION)","yes") 18 | $(CC) -o $@ $^ -lz 19 | else 20 | $(CC) -o $@ $^ 21 | endif 22 | 23 | clean: 24 | rm -f $(TARGET) $(OBJS) -------------------------------------------------------------------------------- /libesphttpd/include/auth.h: -------------------------------------------------------------------------------- 1 | #ifndef AUTH_H 2 | #define AUTH_H 3 | 4 | #include "httpd.h" 5 | 6 | #ifndef HTTP_AUTH_REALM 7 | #define HTTP_AUTH_REALM "Protected" 8 | #endif 9 | 10 | #define HTTPD_AUTH_SINGLE 0 11 | #define HTTPD_AUTH_CALLBACK 1 12 | 13 | #define AUTH_MAX_USER_LEN 32 14 | #define AUTH_MAX_PASS_LEN 32 15 | 16 | //Parameter given to authWhatever functions. This callback returns the usernames/passwords the device 17 | //has. 18 | typedef int (* AuthGetUserPw)(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen); 19 | 20 | int ICACHE_FLASH_ATTR authBasic(HttpdConnData *connData); 21 | 22 | #endif -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /html/flash/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 | #progressbar { 19 | margin: 10px; 20 | padding: 0; 21 | border: 1px solid #000000; 22 | height: 20px; 23 | width: 200px; 24 | background-color: #808080; 25 | } 26 | 27 | #progressbarinner { 28 | width: 10px; 29 | height: 20px; 30 | border: none; 31 | background-color: #00ff00; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /libesphttpd/espfs/espfs.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPFS_H 2 | #define ESPFS_H 3 | 4 | // This define is done in Makefile. If you do not use default Makefile, uncomment 5 | // to be able to use Heatshrink-compressed espfs images. 6 | //#define ESPFS_HEATSHRINK 7 | 8 | typedef enum { 9 | ESPFS_INIT_RESULT_OK, 10 | ESPFS_INIT_RESULT_NO_IMAGE, 11 | ESPFS_INIT_RESULT_BAD_ALIGN, 12 | } EspFsInitResult; 13 | 14 | typedef struct EspFsFile EspFsFile; 15 | 16 | EspFsInitResult espFsInit(void *flashAddress); 17 | EspFsFile *espFsOpen(char *fileName); 18 | int espFsFlags(EspFsFile *fh); 19 | int espFsRead(EspFsFile *fh, char *buff, int len); 20 | void espFsClose(EspFsFile *fh); 21 | 22 | 23 | #endif -------------------------------------------------------------------------------- /libesphttpd/include/espfs.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPFS_H 2 | #define ESPFS_H 3 | 4 | // This define is done in Makefile. If you do not use default Makefile, uncomment 5 | // to be able to use Heatshrink-compressed espfs images. 6 | //#define ESPFS_HEATSHRINK 7 | 8 | typedef enum { 9 | ESPFS_INIT_RESULT_OK, 10 | ESPFS_INIT_RESULT_NO_IMAGE, 11 | ESPFS_INIT_RESULT_BAD_ALIGN, 12 | } EspFsInitResult; 13 | 14 | typedef struct EspFsFile EspFsFile; 15 | 16 | EspFsInitResult espFsInit(void *flashAddress); 17 | EspFsFile *espFsOpen(char *fileName); 18 | int espFsFlags(EspFsFile *fh); 19 | int espFsRead(EspFsFile *fh, char *buff, int len); 20 | void espFsClose(EspFsFile *fh); 21 | 22 | 23 | #endif -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/Makefile.windows: -------------------------------------------------------------------------------- 1 | GZIP_COMPRESSION ?= no 2 | USE_HEATSHRINK ?= yes 3 | 4 | TARGET = mkespfsimage.exe 5 | 6 | CC = gcc 7 | LD = $(CC) 8 | CFLAGS=-c -I../../lib/heatshrink -I.. -Imman-win32 -std=gnu99 9 | LDFLAGS=-Lmman-win32 -lmman 10 | 11 | ifeq ("$(GZIP_COMPRESSION)","yes") 12 | CFLAGS += -DESPFS_GZIP 13 | LDFLAGS += -lz 14 | endif 15 | 16 | ifeq ("$(USE_HEATSHRINK)","yes") 17 | CFLAGS += -DESPFS_HEATSHRINK 18 | endif 19 | 20 | OBJECTS = main.o heatshrink_encoder.o 21 | 22 | all: $(TARGET) 23 | 24 | $(TARGET): $(OBJECTS) 25 | $(LD) -o $@ $^ $(LDFLAGS) 26 | 27 | %.o: %.c 28 | $(CC) $(CFLAGS) -o $@ $^ 29 | 30 | clean: 31 | rm -f $(OBJECTS) $(TARGET) 32 | 33 | .PHONY: all clean 34 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/Makefile: -------------------------------------------------------------------------------- 1 | GZIP_COMPRESSION ?= no 2 | USE_HEATSHRINK ?= yes 3 | 4 | TARGET = mkespfsimage.exe 5 | 6 | CC = gcc 7 | LD = $(CC) 8 | CFLAGS=-c -I../../lib/heatshrink -I.. -Imman-win32 -std=gnu99 9 | LDFLAGS=-Lmman-win32 -lmman 10 | 11 | ifeq ("$(GZIP_COMPRESSION)","yes") 12 | CFLAGS += -DESPFS_GZIP 13 | LDFLAGS += -lz 14 | endif 15 | 16 | ifeq ("$(USE_HEATSHRINK)","yes") 17 | CFLAGS += -DESPFS_HEATSHRINK 18 | endif 19 | 20 | OBJECTS = main.o heatshrink_encoder.o 21 | 22 | all: libmman $(TARGET) 23 | 24 | libmman: 25 | $(Q) make -C mman-win32 26 | 27 | $(TARGET): $(OBJECTS) 28 | $(LD) -o $@ $^ $(LDFLAGS) 29 | 30 | %.o: %.c 31 | $(CC) $(CFLAGS) -o $@ $^ 32 | 33 | clean: 34 | rm -f $(OBJECTS) $(TARGET) 35 | 36 | .PHONY: all clean 37 | -------------------------------------------------------------------------------- /html/flash/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 | -------------------------------------------------------------------------------- /html/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 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /libesphttpd/include/sha1.h: -------------------------------------------------------------------------------- 1 | /* header */ 2 | 3 | #ifndef __SHA1_H__ 4 | #define __SHA1_H__ 5 | 6 | #define HASH_LENGTH 20 7 | #define BLOCK_LENGTH 64 8 | 9 | typedef struct sha1nfo { 10 | uint32_t buffer[BLOCK_LENGTH/4]; 11 | uint32_t state[HASH_LENGTH/4]; 12 | uint32_t byteCount; 13 | uint8_t bufferOffset; 14 | uint8_t keyBuffer[BLOCK_LENGTH]; 15 | uint8_t innerHash[HASH_LENGTH]; 16 | } sha1nfo; 17 | 18 | /* public API - prototypes - TODO: doxygen*/ 19 | 20 | /** 21 | */ 22 | void sha1_init(sha1nfo *s); 23 | /** 24 | */ 25 | void sha1_writebyte(sha1nfo *s, uint8_t data); 26 | /** 27 | */ 28 | void sha1_write(sha1nfo *s, const char *data, size_t len); 29 | /** 30 | */ 31 | uint8_t* sha1_result(sha1nfo *s); 32 | /** 33 | */ 34 | void sha1_initHmac(sha1nfo *s, const uint8_t* key, int keyLength); 35 | /** 36 | */ 37 | uint8_t* sha1_resultHmac(sha1nfo *s); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | esp_enc28j60 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/mman.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mman", "mman.vcxproj", "{F118CC2E-9AED-4DB0-9BF4-028781D97AD1}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {F118CC2E-9AED-4DB0-9BF4-028781D97AD1}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {F118CC2E-9AED-4DB0-9BF4-028781D97AD1}.Debug|Win32.Build.0 = Debug|Win32 14 | {F118CC2E-9AED-4DB0-9BF4-028781D97AD1}.Release|Win32.ActiveCfg = Release|Win32 15 | {F118CC2E-9AED-4DB0-9BF4-028781D97AD1}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /user/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _TYPES_H 2 | #define _TYPES_H 3 | 4 | #ifndef NULL 5 | #define NULL 0 6 | #endif 7 | 8 | //#define FAIL 1 9 | //#define PASS 0 10 | 11 | typedef unsigned char u_char; 12 | typedef unsigned char Uchar; 13 | typedef unsigned char u8; 14 | typedef unsigned char U8; 15 | 16 | typedef unsigned short u_short; 17 | typedef unsigned short u16; 18 | typedef unsigned short U16; 19 | 20 | typedef unsigned int u_int; 21 | typedef unsigned int u32; 22 | typedef unsigned int U32; 23 | 24 | typedef unsigned long u_long; 25 | //typedef unsigned long u64; 26 | typedef unsigned long U64; 27 | 28 | //typedef char s8; 29 | typedef char S8; 30 | 31 | typedef short s16; 32 | typedef short S16; 33 | 34 | typedef int s32; 35 | typedef int S32; 36 | 37 | typedef long s64; 38 | typedef long S64; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /libesphttpd/espfs/heatshrink_config_custom.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 | #ifdef __ets__ 11 | #define HEATSHRINK_MALLOC(SZ) os_malloc(SZ) 12 | #define HEATSHRINK_FREE(P, SZ) os_free(P) 13 | #else 14 | #define HEATSHRINK_MALLOC(SZ) malloc(SZ) 15 | #define HEATSHRINK_FREE(P, SZ) free(P) 16 | #endif 17 | #else 18 | /* Required parameters for static configuration */ 19 | #define HEATSHRINK_STATIC_INPUT_BUFFER_SIZE 32 20 | #define HEATSHRINK_STATIC_WINDOW_BITS 8 21 | #define HEATSHRINK_STATIC_LOOKAHEAD_BITS 4 22 | #endif 23 | 24 | /* Turn on logging for debugging. */ 25 | #define HEATSHRINK_DEBUGGING_LOGS 0 26 | 27 | /* Use indexing for faster compression. (This requires additional space.) */ 28 | #define HEATSHRINK_USE_INDEX 1 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /html/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 |
  • Esphttpd now also supports websockets.
  • 16 |
  • And because I can, here's a link to my website
17 | 18 |

19 | 20 |

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

25 |
26 | 27 | -------------------------------------------------------------------------------- /libesphttpd/espfs/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 FLAG_GZIP (1<<1) 20 | #define COMPRESS_NONE 0 21 | #define COMPRESS_HEATSHRINK 1 22 | #define ESPFS_MAGIC 0x73665345 23 | 24 | typedef struct { 25 | int32_t magic; 26 | int8_t flags; 27 | int8_t compression; 28 | int16_t nameLen; 29 | int32_t fileLenComp; 30 | int32_t fileLenDecomp; 31 | } __attribute__((packed)) EspFsHeader; 32 | 33 | #endif -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # mman-win32 (mingw32) Makefile 3 | # 4 | include config.mak 5 | 6 | ifeq ($(BUILD_STATIC),yes) 7 | TARGETS+=libmman.a 8 | INSTALL+=static-install 9 | endif 10 | ifeq ($(BUILD_MSVC),yes) 11 | SHFLAGS+=-Wl,--output-def,libmman.def 12 | INSTALL+=lib-install 13 | endif 14 | 15 | all: $(TARGETS) 16 | 17 | mman.o: mman.c mman.h 18 | $(CC) -o mman.o -c mman.c -Wall -O3 -fomit-frame-pointer 19 | 20 | libmman.a: mman.o 21 | $(AR) cru libmman.a mman.o 22 | $(RANLIB) libmman.a 23 | 24 | static-install: 25 | mkdir -p $(DESTDIR)$(libdir) 26 | cp libmman.a $(DESTDIR)$(libdir) 27 | mkdir -p $(DESTDIR)$(incdir) 28 | cp mman.h $(DESTDIR)$(incdir) 29 | 30 | lib-install: 31 | mkdir -p $(DESTDIR)$(libdir) 32 | cp libmman.lib $(DESTDIR)$(libdir) 33 | 34 | install: $(INSTALL) 35 | 36 | test.exe: test.c mman.c mman.h 37 | $(CC) -o test.exe test.c -L. -lmman 38 | 39 | test: $(TARGETS) test.exe 40 | test.exe 41 | 42 | clean:: 43 | rm -f mman.o libmman.a libmman.def libmman.lib test.exe *.dat 44 | 45 | distclean: clean 46 | rm -f config.mak 47 | 48 | .PHONY: clean distclean install test 49 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/mman.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Header Files 25 | 26 | 27 | -------------------------------------------------------------------------------- /libesphttpd/include/cgiwebsocket.h: -------------------------------------------------------------------------------- 1 | #ifndef CGIWEBSOCKET_H 2 | #define CGIWEBSOCKET_H 3 | 4 | #include "httpd.h" 5 | 6 | #define WEBSOCK_FLAG_NONE 0 7 | #define WEBSOCK_FLAG_CONT (1<<0) //Set if the data is not the final data in the message; more follows 8 | #define WEBSOCK_FLAG_BIN (1<<1) //Set if the data is binary instead of text 9 | 10 | 11 | 12 | typedef struct Websock Websock; 13 | typedef struct WebsockPriv WebsockPriv; 14 | 15 | typedef void(*WsConnectedCb)(Websock *ws); 16 | typedef void(*WsRecvCb)(Websock *ws, char *data, int len, int flags); 17 | typedef void(*WsSentCb)(Websock *ws); 18 | typedef void(*WsCloseCb)(Websock *ws); 19 | 20 | struct Websock { 21 | void *userData; 22 | HttpdConnData *conn; 23 | uint8_t status; 24 | WsRecvCb recvCb; 25 | WsSentCb sentCb; 26 | WsCloseCb closeCb; 27 | WebsockPriv *priv; 28 | }; 29 | 30 | int ICACHE_FLASH_ATTR cgiWebsocket(HttpdConnData *connData); 31 | int ICACHE_FLASH_ATTR cgiWebsocketSend(Websock *ws, char *data, int len, int flags); 32 | void ICACHE_FLASH_ATTR cgiWebsocketClose(Websock *ws); 33 | int ICACHE_FLASH_ATTR cgiWebSocketRecv(HttpdConnData *connData, char *data, int len); 34 | int ICACHE_FLASH_ATTR cgiWebsockBroadcast(char *resource, char *data, int len, int flags); 35 | 36 | 37 | #endif -------------------------------------------------------------------------------- /html/wifi/connecting.html: -------------------------------------------------------------------------------- 1 | Connecting... 2 | 3 | 4 | 34 | 35 | 36 |
37 |

Connecting to AP...

38 |

Status:
39 |

...
40 |

41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp_enc28j60 2 | ##Ethernet connectivity to an ESP8266 via an ENC28J60 3 | 4 | This project adds the ENC28J60 to the ESP8266, and allows Sprites HTTPD functionality via a wired connection. 5 | - Allows for concurrent connections to the ESP, both via wired connection and wireless to serve the HTTPD project. 6 | 7 | Forum discussion - http://www.esp8266.com/viewtopic.php?f=11&t=9413 8 | 9 | ![alt tag](https://github.com/Cicero-MF/esp_enc28j60/blob/master/ethernet%20to%20esp%20wiring.png) 10 | 11 | **SDK Version:** v1.5.0 27-11-2015 12 | 13 | ## Running and testing esp_enc28j60 14 | - Connect up your ENC28J60 to your ESP8266 as shown 15 | - I work in Cherts Windows Environment http://www.esp8266.com/viewtopic.php?t=820, and so the project has been copied in full to compile with his standard install directories. If you are on Linux/BSD, please follow PuceBaboon's setup/makefile changes here: https://esp8266hints.wordpress.com/2016/06/09/compiling-ciceros-esp-enc28j60-package-on-linux/ 16 | - Lastly, dont hesitate to contact me with any questions you may have. Good luck! 17 | 18 | ##Thanks 19 | Special thanks should go to the following people who have provided the building blocks of each aspect, I've just managed to piece them together in some sort of fashion and suprisingly it works. 20 | 21 | 1. For the stack, Ulrich Radig http://www.ulrichradig.de/ 22 | 2. For the HTTPD project - Sprite_tm http://www.esp8266.com/viewforum.php?f=34&sid=cd5a2e06f4567c5293795af3709402e7 23 | 3. MetalPhreak for the ESP8266 SPI functionality - https://github.com/MetalPhreak/ESP8266_SPI_Driver 24 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/mman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sys/mman.h 3 | * mman-win32 4 | */ 5 | 6 | #ifndef _SYS_MMAN_H_ 7 | #define _SYS_MMAN_H_ 8 | 9 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 10 | #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 11 | #endif 12 | 13 | /* All the headers include this file. */ 14 | #ifndef _MSC_VER 15 | #include <_mingw.h> 16 | #endif 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define PROT_NONE 0 25 | #define PROT_READ 1 26 | #define PROT_WRITE 2 27 | #define PROT_EXEC 4 28 | 29 | #define MAP_FILE 0 30 | #define MAP_SHARED 1 31 | #define MAP_PRIVATE 2 32 | #define MAP_TYPE 0xf 33 | #define MAP_FIXED 0x10 34 | #define MAP_ANONYMOUS 0x20 35 | #define MAP_ANON MAP_ANONYMOUS 36 | 37 | #define MAP_FAILED ((void *)-1) 38 | 39 | /* Flags for msync. */ 40 | #define MS_ASYNC 1 41 | #define MS_SYNC 2 42 | #define MS_INVALIDATE 4 43 | 44 | void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); 45 | int munmap(void *addr, size_t len); 46 | int mprotect(void *addr, size_t len, int prot); 47 | int msync(void *addr, size_t len, int flags); 48 | int mlock(const void *addr, size_t len); 49 | int munlock(const void *addr, size_t len); 50 | 51 | #ifdef __cplusplus 52 | }; 53 | #endif 54 | 55 | #endif /* _SYS_MMAN_H_ */ 56 | -------------------------------------------------------------------------------- /libesphttpd/espfs/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 | EspFsInitResult ir; 26 | 27 | if (argc!=3) { 28 | printf("Usage: %s espfs-image file\nExpands file from the espfs-image archive.\n", argv[0]); 29 | exit(0); 30 | } 31 | 32 | f=open(argv[1], O_RDONLY); 33 | if (f<=0) { 34 | perror(argv[1]); 35 | exit(1); 36 | } 37 | size=lseek(f, 0, SEEK_END); 38 | espFsData=mmap(NULL, size, PROT_READ, MAP_SHARED, f, 0); 39 | if (espFsData==MAP_FAILED) { 40 | perror("mmap"); 41 | exit(1); 42 | } 43 | 44 | ir=espFsInit(espFsData); 45 | if (ir != ESPFS_INIT_RESULT_OK) { 46 | printf("Couldn't init espfs filesystem (code %d)\n", ir); 47 | exit(1); 48 | } 49 | 50 | ef=espFsOpen(argv[2]); 51 | if (ef==NULL) { 52 | printf("Couldn't find %s in image.\n", argv[2]); 53 | exit(1); 54 | } 55 | 56 | out=open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0644); 57 | if (out<=0) { 58 | perror(argv[2]); 59 | exit(1); 60 | } 61 | 62 | while ((len=espFsRead(ef, buff, 128))!=0) { 63 | write(out, buff, len); 64 | } 65 | espFsClose(ef); 66 | //munmap, close, ... I can't be bothered. 67 | } 68 | -------------------------------------------------------------------------------- /user/globals.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------------------- 2 | Author: Mark F (Cicero-MF) mark@cdelec.co.za 3 | Known Issues: none 4 | Version: 18.05.2016 5 | Description: Mainly just global defines for debugging 6 | 7 | -----------------------------------------------------------------------------------------*/ 8 | #ifndef _GLOBALS_H 9 | #define _GLOBALS_H 10 | 11 | #include "user_config.h" 12 | #include "types.h" 13 | 14 | /* DEBUG UART DEFINES --------------------------------------------------------- 15 | Please keep in mind these slow down proceedings and can, in some cases 16 | if too many debug outputs, cause watchdog resets from the SDK 17 | */ 18 | 19 | #define ENC_DEBUG(...) 20 | //#define ENC_DEBUG os_printf 21 | 22 | //#define SPI_DEBUG(...) 23 | #define SPI_DEBUG os_printf 24 | 25 | //#define CONFIG_DEBUG(...) 26 | #define CONFIG_DEBUG os_printf 27 | 28 | //#define TIMER_DEBUG os_printf 29 | #define TIMER_DEBUG(...) 30 | 31 | //#define STACK_DEBUG os_printf 32 | #define STACK_DEBUG(...) 33 | 34 | #define DHCP_DEBUG os_printf 35 | //#define DHCP_DEBUG(...) 36 | 37 | #define MAIN_DEBUG os_printf 38 | //#define MAIN_DEBUG(...) 39 | 40 | // #define CAPTDNS_DEBUG os_printf 41 | #define CAPTDNS_DEBUG(...) 42 | 43 | #define IPS_IN_UNION 44 | #define MQTT_QUEUE_SETBUF 45 | #define HAVE_COMMS 46 | #define ENC28J60 47 | #define USE_DHCP 48 | 49 | #define USE_DNS 50 | 51 | 52 | #ifdef MQTT_KEEPALIVE 53 | #define ENC_RESET_TIMEOUT (MQTT_KEEPALIVE+5) 54 | #else 55 | #define ENC_RESET_TIMEOUT (30) 56 | #endif 57 | 58 | 59 | #endif /* _GLOBALS_H */ 60 | -------------------------------------------------------------------------------- /html/websocket/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | WebSocket Test 6 | 7 | 66 | 67 |

WebSocket Test

68 | 69 |
70 | -------------------------------------------------------------------------------- /esphttpdconfig.mk: -------------------------------------------------------------------------------- 1 | # --------------- esphttpd config options --------------- 2 | 3 | # If GZIP_COMPRESSION is set to "yes" then the static css, js, and html files will be compressed with gzip before added to the espfs image 4 | # and will be served with gzip Content-Encoding header. 5 | # This could speed up the downloading of these files, but might break compatibility with older web browsers not supporting gzip encoding 6 | # because Accept-Encoding is simply ignored. Enable this option if you have large static files to serve (for e.g. JQuery, Twitter bootstrap) 7 | # By default only js, css and html files are compressed. 8 | # If you have text based static files with different extensions what you want to serve compressed then you will need to add the extension to the following places: 9 | # - Add the extension to this Makefile at the webpages.espfs target to the find command 10 | # - Add the extension to the gzippedFileTypes array in the user/httpd.c file 11 | # 12 | # Adding JPG or PNG files (and any other compressed formats) is not recommended, because GZIP compression does not works effectively on compressed files. 13 | 14 | #Static gzipping is disabled by default. 15 | GZIP_COMPRESSION ?= no 16 | 17 | # If COMPRESS_W_YUI is set to "yes" then the static css and js files will be compressed with yui-compressor 18 | # This option works only when GZIP_COMPRESSION is set to "yes" 19 | # http://yui.github.io/yuicompressor/ 20 | #Disabled by default. 21 | COMPRESS_W_YUI ?= no 22 | YUI-COMPRESSOR ?= /usr/bin/yui-compressor 23 | 24 | #If USE_HEATSHRINK is set to "yes" then the espfs files will be compressed with Heatshrink and decompressed 25 | #on the fly while reading the file. Because the decompression is done in the esp8266, it does not require 26 | #any support in the browser. 27 | USE_HEATSHRINK ?= yes 28 | 29 | -------------------------------------------------------------------------------- /user/esp_enc_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | ----------------------------------------------------------------------------------------- 3 | Author: Mark F (Cicero-MF) mark@cdelec.co.za 4 | Known Issues: none 5 | Version: 18.05.2016 6 | Description: Header for API or 'tunnel' for espconn and enc28j60 stack callbacks and setup 7 | 8 | ----------------------------------------------------------------------------------------- 9 | */ 10 | #ifndef _ESP_ENC_API_H 11 | #define _ESP_ENC_API_H 12 | 13 | #include "esp8266.h" 14 | #include "httpd.h" 15 | 16 | /* Sneaky addition to the type enum in struct espconn to distinguish ENC conns */ 17 | #define ESPCONN_TCP_WIRED 0x40 18 | 19 | /* Module types supported 20 | Add in what ever other module you need here, 21 | and make sure they're used in stack_register_tcp_accept() 22 | */ 23 | #define STACK_NA 0x00 24 | #define STACK_HTTPD 0x01 25 | #define STACK_MQTT 0x02 26 | 27 | sint8 esp_enc_api_sendData (struct espconn *conn, u8* dataIn, int len); 28 | sint8 esp_enc_api_disconnect (struct espconn *espconn); 29 | sint8 esp_enc_api_regist_recvcb (struct espconn *espconn, espconn_recv_callback recv_cb); 30 | sint8 esp_enc_api_regist_reconcb (struct espconn *espconn, espconn_reconnect_callback recon_cb); 31 | sint8 esp_enc_api_regist_disconcb (struct espconn *espconn, espconn_connect_callback discon_cb); 32 | sint8 esp_enc_api_regist_sentcb (struct espconn *espconn, espconn_sent_callback sent_cb); 33 | sint8 esp_enc_api_regist_connectcb (struct espconn *espconn, espconn_connect_callback connect_cb); 34 | sint8 esp_enc_api_connaccept (struct espconn *espconn, u8 stack_func); 35 | sint8 esp_enc_api_tcp_set_max_con_allowed (struct espconn *espconn, uint8 num); 36 | 37 | 38 | #endif /* _ESP_ENC_API_H */ 39 | -------------------------------------------------------------------------------- /user/stdout.c: -------------------------------------------------------------------------------- 1 | //Stupid bit of code that does the bare minimum to make os_printf work. 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 | #include 13 | #include 14 | 15 | static void ICACHE_FLASH_ATTR stdoutUartTxd(char c) { 16 | //Wait until there is room in the FIFO 17 | while (((READ_PERI_REG(UART_STATUS(0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=126) ; 18 | //Send the character 19 | WRITE_PERI_REG(UART_FIFO(0), c); 20 | } 21 | 22 | static void ICACHE_FLASH_ATTR stdoutPutchar(char c) { 23 | //convert \n -> \r\n 24 | if (c=='\n') stdoutUartTxd('\r'); 25 | stdoutUartTxd(c); 26 | } 27 | 28 | 29 | void stdoutInit() { 30 | //Enable TxD pin 31 | PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); 32 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); 33 | 34 | //Set baud rate and other serial parameters to 115200,n,8,1 35 | uart_div_modify(0, UART_CLK_FREQ/BIT_RATE_115200); 36 | WRITE_PERI_REG(UART_CONF0(0), (STICK_PARITY_DIS)|(ONE_STOP_BIT << UART_STOP_BIT_NUM_S)| \ 37 | (EIGHT_BITS << UART_BIT_NUM_S)); 38 | 39 | //Reset tx & rx fifo 40 | SET_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST|UART_TXFIFO_RST); 41 | CLEAR_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST|UART_TXFIFO_RST); 42 | //Clear pending interrupts 43 | WRITE_PERI_REG(UART_INT_CLR(0), 0xffff); 44 | 45 | //Install our own putchar handler 46 | os_install_putc1((void *)stdoutPutchar); 47 | } 48 | -------------------------------------------------------------------------------- /user/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ----------------------------------------------------------------------------------------- 3 | Author: Mark F (Cicero-MF) mark@cdelec.co.za 4 | Remarks: 5 | Version: 04.04.2016 6 | Description: Ethernet device driver for the enc28j60 and an esp8266 7 | 8 | This code was modified for use with the ESP8266, based off a version by Radig Ulrich 9 | Author: Radig Ulrich mailto: mail@ulrichradig.de 10 | Remarks: 11 | known Problems: none 12 | Version: 24.10.2007 13 | Description: Timer Routinen 14 | 15 | ----------------------------------------------------------------------------------------- 16 | License: 17 | This program is free software; you can redistribute it and/or modify it under 18 | the terms of the GNU General Public License as published by the Free Software 19 | Foundation; either version 2 of the License, or (at your option) any later 20 | version. 21 | This program is distributed in the hope that it will be useful, but 22 | 23 | WITHOUT ANY WARRANTY; 24 | 25 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 26 | PURPOSE. See the GNU General Public License for more details. 27 | 28 | You should have received a copy of the GNU General Public License along with 29 | this program; if not, write to the Free Software Foundation, Inc., 51 30 | Franklin St, Fifth Floor, Boston, MA 02110, USA 31 | 32 | http://www.gnu.de/gpl-ger.html 33 | -----------------------------------------------------------------------------------------*/ 34 | #ifndef _TIMER_H 35 | #define _TIMER_H 36 | 37 | #include "stack.h" 38 | 39 | #define RESET_TIME 86400 40 | 41 | #ifdef USE_DHCP 42 | extern volatile u8 gp_timer; 43 | #endif 44 | void timer_init (void); 45 | 46 | #endif //_TIMER_H 47 | 48 | -------------------------------------------------------------------------------- /html/flash/index.html: -------------------------------------------------------------------------------- 1 | 2 | Upgrade firmware 3 | 4 | 5 | 67 | 68 | 69 |
70 |

Update firmware

71 |
Loading...
72 | 73 | 74 |
75 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /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 "cgi.h" 18 | #include "io.h" 19 | 20 | 21 | //cause I can't be bothered to write an ioGetLed() 22 | static char currLedState=0; 23 | 24 | //Cgi that turns the LED on or off according to the 'led' param in the POST data 25 | int ICACHE_FLASH_ATTR cgiLed(HttpdConnData *connData) { 26 | int len; 27 | char buff[1024]; 28 | 29 | if (connData->conn==NULL) { 30 | //Connection aborted. Clean up. 31 | return HTTPD_CGI_DONE; 32 | } 33 | 34 | len=httpdFindArg(connData->post->buff, "led", buff, sizeof(buff)); 35 | if (len!=0) { 36 | currLedState=atoi(buff); 37 | ioLed(currLedState); 38 | } 39 | 40 | httpdRedirect(connData, "led.tpl"); 41 | return HTTPD_CGI_DONE; 42 | } 43 | 44 | 45 | 46 | //Template code for the led page. 47 | int ICACHE_FLASH_ATTR tplLed(HttpdConnData *connData, char *token, void **arg) { 48 | char buff[128]; 49 | if (token==NULL) return HTTPD_CGI_DONE; 50 | 51 | os_strcpy(buff, "Unknown"); 52 | if (os_strcmp(token, "ledstate")==0) { 53 | if (currLedState) { 54 | os_strcpy(buff, "on"); 55 | } else { 56 | os_strcpy(buff, "off"); 57 | } 58 | } 59 | httpdSend(connData, buff, -1); 60 | return HTTPD_CGI_DONE; 61 | } 62 | 63 | static long hitCounter=0; 64 | 65 | //Template code for the counter on the index page. 66 | int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) { 67 | char buff[128]; 68 | if (token==NULL) return HTTPD_CGI_DONE; 69 | 70 | if (os_strcmp(token, "counter")==0) { 71 | hitCounter++; 72 | os_sprintf(buff, "%ld", hitCounter); 73 | } 74 | httpdSend(connData, buff, -1); 75 | return HTTPD_CGI_DONE; 76 | } 77 | -------------------------------------------------------------------------------- /user/dhcpc.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------- 2 | Author: Mark F (Cicero-MF) mark@cdelec.co.za 3 | Remarks: 4 | Version: 04.04.2016 5 | Description: DHCP client for the enc28j60 and an esp8266 6 | 7 | This code was adapted for use with the ESP8266, and based off Michael Kliebers version. 8 | Author: Michael Kleiber 9 | Remarks: 10 | known Problems: none 11 | Version: 29.11.2008 12 | Description: DHCP Client 13 | 14 | ----------------------------------------------------------------------------------------- 15 | License: 16 | This program is free software; you can redistribute it and/or modify it under 17 | the terms of the GNU General Public License as published by the Free Software 18 | Foundation; either version 2 of the License, or (at your option) any later 19 | version. 20 | This program is distributed in the hope that it will be useful, but 21 | 22 | WITHOUT ANY WARRANTY; 23 | 24 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 25 | PURPOSE. See the GNU General Public License for more details. 26 | 27 | You should have received a copy of the GNU General Public License along with 28 | this program; if not, write to the Free Software Foundation, Inc., 51 29 | Franklin St, Fifth Floor, Boston, MA 02110, USA 30 | 31 | http://www.gnu.de/gpl-ger.html 32 | -----------------------------------------------------------------------------------------*/ 33 | 34 | #ifdef USE_DHCP 35 | #ifndef _DHCPCLIENT_H 36 | #define _DHCPCLIENT_H 37 | #include 38 | #include "globals.h" 39 | 40 | #define DHCP_CLIENT_PORT 68 41 | #define DHCP_SERVER_PORT 67 42 | 43 | /* Flags for where we are in the DHCP negotiation process */ 44 | #define DHCP_SUCCESS 0 45 | #define DHCP_CONTINUE 1 46 | #define DHCP_TIMEOUT 2 47 | 48 | extern volatile u32 dhcp_lease; 49 | extern volatile u8 dhcp_timer; 50 | 51 | void dhcp_init (void); 52 | void dhcp_message (u8 type); 53 | void dhcp_get (u8 index, u8 port_index); 54 | 55 | u8 ICACHE_FLASH_ATTR dhcp (void); 56 | void ICACHE_FLASH_ATTR check_dhcp (void *arg); 57 | void ICACHE_FLASH_ATTR user_main_setupContinued (void); 58 | 59 | #endif //_DHCPCLIENT_H 60 | #endif //USE_DHCP 61 | 62 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /libesphttpd/core/auth.c: -------------------------------------------------------------------------------- 1 | /* 2 | HTTP auth implementation. Only does basic authentication for now. 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 | 15 | #include 16 | #include "auth.h" 17 | #include "base64.h" 18 | 19 | int ICACHE_FLASH_ATTR authBasic(HttpdConnData *connData) { 20 | const char *forbidden="401 Forbidden."; 21 | int no=0; 22 | int r; 23 | char hdr[(AUTH_MAX_USER_LEN+AUTH_MAX_PASS_LEN+2)*10]; 24 | char userpass[AUTH_MAX_USER_LEN+AUTH_MAX_PASS_LEN+2]; 25 | char user[AUTH_MAX_USER_LEN]; 26 | char pass[AUTH_MAX_PASS_LEN]; 27 | if (connData->conn==NULL) { 28 | //Connection aborted. Clean up. 29 | return HTTPD_CGI_DONE; 30 | } 31 | 32 | r=httpdGetHeader(connData, "Authorization", hdr, sizeof(hdr)); 33 | if (r && strncmp(hdr, "Basic", 5)==0) { 34 | r=base64_decode(strlen(hdr)-6, hdr+6, sizeof(userpass), (unsigned char *)userpass); 35 | if (r<0) r=0; //just clean out string on decode error 36 | userpass[r]=0; //zero-terminate user:pass string 37 | // os_printf("Auth: %s\n", userpass); 38 | while (((AuthGetUserPw)(connData->cgiArg))(connData, no, 39 | user, AUTH_MAX_USER_LEN, pass, AUTH_MAX_PASS_LEN)) { 40 | //Check user/pass against auth header 41 | if (strlen(userpass)==strlen(user)+strlen(pass)+1 && 42 | os_strncmp(userpass, user, strlen(user))==0 && 43 | userpass[strlen(user)]==':' && 44 | os_strcmp(userpass+strlen(user)+1, pass)==0) { 45 | //Authenticated. Yay! 46 | return HTTPD_CGI_AUTHENTICATED; 47 | } 48 | no++; //Not authenticated with this user/pass. Check next user/pass combo. 49 | } 50 | } 51 | 52 | //Not authenticated. Go bug user with login screen. 53 | httpdStartResponse(connData, 401); 54 | httpdHeader(connData, "Content-Type", "text/plain"); 55 | httpdHeader(connData, "WWW-Authenticate", "Basic realm=\""HTTP_AUTH_REALM"\""); 56 | httpdEndHeaders(connData); 57 | httpdSend(connData, forbidden, -1); 58 | //Okay, all done. 59 | return HTTPD_CGI_DONE; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /libesphttpd/include/httpd.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPD_H 2 | #define HTTPD_H 3 | 4 | #define HTTPDVER "0.3" 5 | 6 | #define HTTPD_CGI_MORE 0 7 | #define HTTPD_CGI_DONE 1 8 | #define HTTPD_CGI_NOTFOUND 2 9 | #define HTTPD_CGI_AUTHENTICATED 3 10 | 11 | #define HTTPD_METHOD_GET 1 12 | #define HTTPD_METHOD_POST 2 13 | 14 | typedef struct HttpdPriv HttpdPriv; 15 | typedef struct HttpdConnData HttpdConnData; 16 | typedef struct HttpdPostData HttpdPostData; 17 | 18 | typedef int (* cgiSendCallback)(HttpdConnData *connData); 19 | typedef int (* cgiRecvHandler)(HttpdConnData *connData, char *data, int len); 20 | 21 | //A struct describing a http connection. This gets passed to cgi functions. 22 | struct HttpdConnData { 23 | struct espconn *conn; 24 | char requestType; 25 | char *url; 26 | char *getArgs; 27 | const void *cgiArg; 28 | void *cgiData; 29 | void *cgiPrivData; // Used for streaming handlers storing state between requests 30 | char *hostName; 31 | HttpdPriv *priv; 32 | cgiSendCallback cgi; 33 | cgiRecvHandler recvHdl; 34 | HttpdPostData *post; 35 | int remote_port; 36 | uint8 remote_ip[4]; 37 | }; 38 | 39 | //A struct describing the POST data sent inside the http connection. This is used by the CGI functions 40 | struct HttpdPostData { 41 | int len; // POST Content-Length 42 | int buffSize; // The maximum length of the post buffer 43 | int buffLen; // The amount of bytes in the current post buffer 44 | int received; // The total amount of bytes received so far 45 | char *buff; // Actual POST data buffer 46 | char *multipartBoundary; 47 | }; 48 | 49 | //A struct describing an url. This is the main struct that's used to send different URL requests to 50 | //different routines. 51 | typedef struct { 52 | const char *url; 53 | cgiSendCallback cgiCb; 54 | const void *cgiArg; 55 | } HttpdBuiltInUrl; 56 | 57 | int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData); 58 | int ICACHE_FLASH_ATTR cgiRedirectToHostname(HttpdConnData *connData); 59 | int ICACHE_FLASH_ATTR cgiRedirectApClientToHostname(HttpdConnData *connData); 60 | void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl); 61 | int httpdUrlDecode(char *val, int valLen, char *ret, int retLen); 62 | int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen); 63 | void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port); 64 | const char *httpdGetMimetype(char *url); 65 | void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code); 66 | void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val); 67 | void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn); 68 | int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *ret, int retLen); 69 | int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len); 70 | void ICACHE_FLASH_ATTR httpdFlushSendBuffer(HttpdConnData *conn); 71 | 72 | #endif -------------------------------------------------------------------------------- /html/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 | -------------------------------------------------------------------------------- /libesphttpd/include/espmissingincludes.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPMISSINGINCLUDES_H 2 | #define ESPMISSINGINCLUDES_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | //Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere. 10 | //MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler. 11 | typedef struct espconn espconn; 12 | 13 | int atoi(const char *nptr); 14 | void ets_install_putc1(void *routine); 15 | void ets_isr_attach(int intr, void *handler, void *arg); 16 | void ets_isr_mask(unsigned intr); 17 | void ets_isr_unmask(unsigned intr); 18 | int ets_memcmp(const void *s1, const void *s2, size_t n); 19 | void *ets_memcpy(void *dest, const void *src, size_t n); 20 | void *ets_memset(void *s, int c, size_t n); 21 | int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); 22 | int ets_str2macaddr(void *, void *); 23 | int ets_strcmp(const char *s1, const char *s2); 24 | char *ets_strcpy(char *dest, const char *src); 25 | size_t ets_strlen(const char *s); 26 | int ets_strncmp(const char *s1, const char *s2, int len); 27 | char *ets_strncpy(char *dest, const char *src, size_t n); 28 | char *ets_strstr(const char *haystack, const char *needle); 29 | void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer); 30 | void ets_timer_disarm(ETSTimer *a); 31 | void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg); 32 | void ets_update_cpu_frequency(int freqmhz); 33 | int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 34 | int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4))); 35 | int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 36 | void uart_div_modify(int no, unsigned int freq); 37 | uint8 wifi_get_opmode(void); 38 | uint32 system_get_time(); 39 | int rand(void); 40 | void ets_bzero(void *s, size_t n); 41 | void ets_delay_us(int ms); 42 | 43 | 44 | //Hack: this is defined in SDK 1.4.0 and undefined in 1.3.0. It's only used for this, the symbol itself 45 | //has no meaning here. 46 | #ifndef RC_LIMIT_P2P_11N 47 | //Defs for SDK <1.4.0 48 | void *pvPortMalloc(size_t xWantedSize); 49 | void *pvPortZalloc(size_t); 50 | void vPortFree(void *ptr); 51 | void *vPortMalloc(size_t xWantedSize); 52 | void pvPortFree(void *ptr); 53 | #else 54 | void *pvPortMalloc(size_t xWantedSize, const char *file, int line); 55 | void *pvPortZalloc(size_t, const char *file, int line); 56 | void vPortFree(void *ptr, const char *file, int line); 57 | void *vPortMalloc(size_t xWantedSize, const char *file, int line); 58 | void pvPortFree(void *ptr, const char *file, int line); 59 | #endif 60 | 61 | //Standard PIN_FUNC_SELECT gives a warning. Replace by a non-warning one. 62 | #ifdef PIN_FUNC_SELECT 63 | #undef PIN_FUNC_SELECT 64 | #define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \ 65 | WRITE_PERI_REG(PIN_NAME, \ 66 | (READ_PERI_REG(PIN_NAME) \ 67 | & (~(PERIPHS_IO_MUX_FUNC< 0 ) dhcp_lease--; 84 | if ( gp_timer > 0 ) gp_timer--; 85 | #endif //USE_DHCP 86 | 87 | eth.timer = 1; 88 | } 89 | 90 | 91 | 92 | //---------------------------------------------------------------------------- 93 | // Timer init 94 | void timer_init (void) 95 | { 96 | os_timer_disarm(&secondTickerTimer); 97 | os_timer_setfn(&secondTickerTimer, secondTickerCb, NULL); 98 | os_timer_arm(&secondTickerTimer, 1000, 1); 99 | 100 | TIMER_DEBUG("timer init\r\n"); 101 | return; 102 | }; 103 | 104 | //---------------------------------------------------------------------------- 105 | 106 | -------------------------------------------------------------------------------- /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 13 | #include "globals.h" 14 | #include "io.h" 15 | #include "stack.h" 16 | 17 | #define LEDGPIO 2 18 | #define BTNGPIO 0 19 | 20 | static ETSTimer resetBtntimer; 21 | 22 | void ICACHE_FLASH_ATTR ioLed(int ena) { 23 | //gpio_output_set is overkill. ToDo: use better mactos 24 | if (ena) { 25 | gpio_output_set((1<=6) { //3 sec pressed 37 | wifi_station_disconnect(); 38 | wifi_set_opmode(0x3); //reset to AP+STA mode 39 | os_printf("Reset to AP mode. Restarting system...\n"); 40 | system_restart(); 41 | } 42 | resetCnt=0; 43 | } 44 | } 45 | 46 | void ICACHE_FLASH_ATTR gpio16_output_conf(void) { 47 | WRITE_PERI_REG(PAD_XPD_DCDC_CONF, 48 | (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0 49 | 50 | WRITE_PERI_REG(RTC_GPIO_CONF, 51 | (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable 52 | 53 | WRITE_PERI_REG(RTC_GPIO_ENABLE, 54 | (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable 55 | } 56 | 57 | void ICACHE_FLASH_ATTR gpio16_output_set(uint8 value) { 58 | WRITE_PERI_REG(RTC_GPIO_OUT, 59 | (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1)); 60 | } 61 | 62 | void ioInit() { 63 | uint32 gpio_status; 64 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); 65 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); 66 | gpio_output_set(0, 0, (1<type != ESPCONN_TCP_WIRED) { 18 | return espconn_sent(conn, dataIn, len); 19 | } else { 20 | return stack_sendData(conn, dataIn, len); 21 | } 22 | } 23 | 24 | /* Use this to disconnect */ 25 | sint8 esp_enc_api_disconnect (struct espconn *espconn) { 26 | if (espconn->type != ESPCONN_TCP_WIRED) { 27 | return espconn_disconnect(espconn); 28 | } else { 29 | stack_connDisconnect (espconn); 30 | return 1; 31 | } 32 | } 33 | 34 | /* Use this to register the correct callback for receiving */ 35 | sint8 esp_enc_api_regist_recvcb (struct espconn *espconn, espconn_recv_callback recv_cb) { 36 | if (espconn->type != ESPCONN_TCP_WIRED) { 37 | return espconn_regist_recvcb(espconn, recv_cb); 38 | } else { 39 | espconn->recv_callback = recv_cb; 40 | return 1; 41 | } 42 | } 43 | 44 | 45 | /* Use this to register the correct callback for receiving */ 46 | sint8 esp_enc_api_regist_reconcb (struct espconn *espconn, espconn_reconnect_callback recon_cb) { 47 | if (espconn->type != ESPCONN_TCP_WIRED) { 48 | return espconn_regist_reconcb(espconn, recon_cb); 49 | } else { 50 | espconn->proto.tcp->reconnect_callback = recon_cb; 51 | return 1; 52 | } 53 | } 54 | 55 | /* Use this to register the disconnect callback */ 56 | sint8 esp_enc_api_regist_disconcb (struct espconn *espconn, espconn_connect_callback discon_cb) { 57 | if (espconn->type != ESPCONN_TCP_WIRED) { 58 | return espconn_regist_disconcb(espconn, discon_cb); 59 | } else { 60 | espconn->proto.tcp->disconnect_callback = discon_cb; 61 | return 1; 62 | } 63 | } 64 | 65 | /* Use this to register the sent callback */ 66 | sint8 esp_enc_api_regist_sentcb (struct espconn *espconn, espconn_sent_callback sent_cb) { 67 | if (espconn->type != ESPCONN_TCP_WIRED) { 68 | return espconn_regist_sentcb(espconn, sent_cb); 69 | } else { 70 | espconn->sent_callback = sent_cb; 71 | return 1; 72 | } 73 | } 74 | 75 | 76 | /* Use this to register the connect callback */ 77 | sint8 esp_enc_api_regist_connectcb (struct espconn *espconn, espconn_connect_callback connect_cb) { 78 | if (espconn->type != ESPCONN_TCP_WIRED) { 79 | return espconn_regist_connectcb(espconn, connect_cb); 80 | } else { 81 | espconn->proto.tcp->connect_callback = connect_cb; 82 | return 1; 83 | } 84 | } 85 | 86 | 87 | /* Use this to accept */ 88 | sint8 esp_enc_api_connaccept (struct espconn *espconn, u8 stack_func) { 89 | if (espconn->type != ESPCONN_TCP_WIRED) { 90 | return espconn_accept(espconn); 91 | } else { 92 | return stack_register_tcp_accept(espconn, stack_func); 93 | } 94 | } 95 | 96 | /* Use this to set max connections allowed */ 97 | sint8 esp_enc_api_tcp_set_max_con_allowed (struct espconn *espconn, uint8 num) { 98 | if (espconn->type != ESPCONN_TCP_WIRED) { 99 | return espconn_tcp_set_max_con_allow(espconn, num); 100 | } else { 101 | /* FIXME: Set max conns allowed by stack.c for httpd */ 102 | return 1; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /libesphttpd/core/base64.c: -------------------------------------------------------------------------------- 1 | /* base64.c : base-64 / MIME encode/decode */ 2 | /* PUBLIC DOMAIN - Jon Mayo - November 13, 2003 */ 3 | #include 4 | #include "base64.h" 5 | 6 | static const uint8_t base64dec_tab[256]= { 7 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 8 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 9 | 255,255,255,255,255,255,255,255,255,255,255, 62,255,255,255, 63, 10 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255, 0,255,255, 11 | 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255, 13 | 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 14 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255, 15 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 16 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 17 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 18 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 19 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 20 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 21 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 22 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 23 | }; 24 | 25 | #if 0 26 | static int ICACHE_FLASH_ATTR base64decode(const char in[4], char out[3]) { 27 | uint8_t v[4]; 28 | 29 | v[0]=base64dec_tab[(unsigned)in[0]]; 30 | v[1]=base64dec_tab[(unsigned)in[1]]; 31 | v[2]=base64dec_tab[(unsigned)in[2]]; 32 | v[3]=base64dec_tab[(unsigned)in[3]]; 33 | 34 | out[0]=(v[0]<<2)|(v[1]>>4); 35 | out[1]=(v[1]<<4)|(v[2]>>2); 36 | out[2]=(v[2]<<6)|(v[3]); 37 | return (v[0]|v[1]|v[2]|v[3])!=255 ? in[3]=='=' ? in[2]=='=' ? 1 : 2 : 3 : 0; 38 | } 39 | #endif 40 | 41 | /* decode a base64 string in one shot */ 42 | int ICACHE_FLASH_ATTR base64_decode(size_t in_len, const char *in, size_t out_len, unsigned char *out) { 43 | unsigned int ii, io; 44 | uint32_t v; 45 | unsigned int rem; 46 | 47 | for(io=0,ii=0,v=0,rem=0;ii=8) { 56 | rem-=8; 57 | if(io>=out_len) return -1; /* truncation is failure */ 58 | out[io++]=(v>>rem)&255; 59 | } 60 | } 61 | if(rem>=8) { 62 | rem-=8; 63 | if(io>=out_len) return -1; /* truncation is failure */ 64 | out[io++]=(v>>rem)&255; 65 | } 66 | return io; 67 | } 68 | 69 | static const uint8_t base64enc_tab[64]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 70 | 71 | #if 0 72 | void base64encode(const unsigned char in[3], unsigned char out[4], int count) { 73 | out[0]=base64enc_tab[(in[0]>>2)]; 74 | out[1]=base64enc_tab[((in[0]&3)<<4)|(in[1]>>4)]; 75 | out[2]=count<2 ? '=' : base64enc_tab[((in[1]&15)<<2)|(in[2]>>6)]; 76 | out[3]=count<3 ? '=' : base64enc_tab[(in[2]&63)]; 77 | } 78 | #endif 79 | 80 | int ICACHE_FLASH_ATTR base64_encode(size_t in_len, const unsigned char *in, size_t out_len, char *out) { 81 | unsigned ii, io; 82 | uint32_t v; 83 | unsigned rem; 84 | 85 | for(io=0,ii=0,v=0,rem=0;ii=6) { 91 | rem-=6; 92 | if(io>=out_len) return -1; /* truncation is failure */ 93 | out[io++]=base64enc_tab[(v>>rem)&63]; 94 | } 95 | } 96 | if(rem) { 97 | v<<=(6-rem); 98 | if(io>=out_len) return -1; /* truncation is failure */ 99 | out[io++]=base64enc_tab[v&63]; 100 | } 101 | while(io&3) { 102 | if(io>=out_len) return -1; /* truncation is failure */ 103 | out[io++]='='; 104 | } 105 | if(io>=out_len) return -1; /* no room for null terminator */ 106 | out[io]=0; 107 | return io; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/mman.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {F118CC2E-9AED-4DB0-9BF4-028781D97AD1} 15 | mman 16 | Win32Proj 17 | 18 | 19 | 20 | StaticLibrary 21 | v110 22 | Unicode 23 | true 24 | 25 | 26 | StaticLibrary 27 | v110 28 | MultiByte 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>11.0.61030.0 42 | 43 | 44 | $(Platform)\$(Configuration) 45 | $(Platform)\$(Configuration)\Tmp 46 | 47 | 48 | $(Platform)\$(Configuration)\ 49 | $(Platform)\$(Configuration)\Tmp 50 | 51 | 52 | 53 | Disabled 54 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 55 | EnableFastChecks 56 | MultiThreadedDebug 57 | 58 | Level3 59 | EditAndContinue 60 | 61 | 62 | 63 | 64 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 65 | MultiThreadedDLL 66 | 67 | Level3 68 | ProgramDatabase 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # mmap-win32 configure script 3 | # 4 | # Parts copied from FFmpeg's configure 5 | # 6 | 7 | set_all(){ 8 | value=$1 9 | shift 10 | for var in $*; do 11 | eval $var=$value 12 | done 13 | } 14 | 15 | enable(){ 16 | set_all yes $* 17 | } 18 | 19 | disable(){ 20 | set_all no $* 21 | } 22 | 23 | enabled(){ 24 | eval test "x\$$1" = "xyes" 25 | } 26 | 27 | disabled(){ 28 | eval test "x\$$1" = "xno" 29 | } 30 | 31 | show_help(){ 32 | echo "Usage: configure [options]" 33 | echo "Options: [defaults in brackets after descriptions]" 34 | echo "All \"enable\" options have \"disable\" counterparts" 35 | echo 36 | echo " --help print this message" 37 | echo " --prefix=PREFIX install in PREFIX [$PREFIX]" 38 | echo " --libdir=DIR install libs in DIR [$PREFIX/lib]" 39 | echo " --incdir=DIR install includes in DIR [$PREFIX/include]" 40 | echo " --enable-static build static libraries [yes]" 41 | echo " --enable-msvc create msvc-compatible import lib [auto]" 42 | echo 43 | echo " --cc=CC use C compiler CC [$cc_default]" 44 | echo " --cross-prefix=PREFIX use PREFIX for compilation tools [$cross_prefix]" 45 | exit 1 46 | } 47 | 48 | die_unknown(){ 49 | echo "Unknown option \"$1\"." 50 | echo "See $0 --help for available options." 51 | exit 1 52 | } 53 | 54 | PREFIX="/mingw" 55 | libdir="${PREFIX}/lib" 56 | incdir="${PREFIX}/include/sys" 57 | ar="ar" 58 | cc_default="gcc" 59 | ranlib="ranlib" 60 | strip="strip" 61 | 62 | DEFAULT="msvc 63 | " 64 | 65 | DEFAULT_YES="static 66 | stripping 67 | " 68 | 69 | CMDLINE_SELECT="$DEFAULT 70 | $DEFAULT_NO 71 | $DEFAULT_YES 72 | " 73 | 74 | enable $DEFAULT_YES 75 | disable $DEFAULT_NO 76 | 77 | for opt do 78 | optval="${opt#*=}" 79 | case "$opt" in 80 | --help) 81 | show_help 82 | ;; 83 | --prefix=*) 84 | PREFIX="$optval" 85 | ;; 86 | --libdir=*) 87 | libdir="$optval" 88 | ;; 89 | --incdir=*) 90 | incdir="$optval" 91 | ;; 92 | --cc=*) 93 | cc="$optval" 94 | ;; 95 | --cross-prefix=*) 96 | cross_prefix="$optval" 97 | ;; 98 | --enable-?*|--disable-?*) 99 | eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` 100 | echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt 101 | $action $option 102 | ;; 103 | *) 104 | die_unknown $opt 105 | ;; 106 | esac 107 | done 108 | 109 | ar="${cross_prefix}${ar}" 110 | cc_default="${cross_prefix}${cc_default}" 111 | ranlib="${cross_prefix}${ranlib}" 112 | strip="${cross_prefix}${strip}" 113 | 114 | if ! test -z $cc; then 115 | cc_default="${cc}" 116 | fi 117 | cc="${cc_default}" 118 | 119 | disabled static && { 120 | echo "At least one library type must be set."; 121 | exit 1; 122 | } 123 | 124 | if enabled msvc; then 125 | lib /? > /dev/null 2>&1 /dev/null || { 126 | echo "MSVC's lib command not found." 127 | echo "Make sure MSVC is installed and its bin folder is in your \$PATH." 128 | exit 1 129 | } 130 | fi 131 | 132 | if ! enabled stripping; then 133 | strip="echo ignoring strip" 134 | fi 135 | 136 | enabled msvc && libcmd="lib" || libcmd="echo ignoring lib" 137 | 138 | echo "# Automatically generated by configure" > config.mak 139 | echo "PREFIX=$PREFIX" >> config.mak 140 | echo "libdir=$libdir" >> config.mak 141 | echo "incdir=$incdir" >> config.mak 142 | echo "AR=$ar" >> config.mak 143 | echo "CC=$cc" >> config.mak 144 | echo "RANLIB=$ranlib" >> config.mak 145 | echo "STRIP=$strip" >> config.mak 146 | echo "BUILD_STATIC=$static" >> config.mak 147 | echo "BUILD_MSVC=$msvc" >> config.mak 148 | echo "LIBCMD=$libcmd" >> config.mak 149 | 150 | echo "prefix: $PREFIX" 151 | echo "libdir: $libdir" 152 | echo "incdir: $incdir" 153 | echo "ar: $ar" 154 | echo "cc: $cc" 155 | echo "ranlib: $ranlib" 156 | echo "strip: $strip" 157 | echo "static: $static" 158 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /user/config.h: -------------------------------------------------------------------------------- 1 | /* config.h 2 | 3 | ----------------------------------------------------------------------------------------- 4 | Author: Mark F (Cicero-MF) mark@cdelec.co.za 5 | Known Issues: none 6 | Version: 18.05.2016 7 | Description: Config holding structure adapted for the enc28j60 and an esp8266 8 | 9 | This code was modified from TuanPM's mqtt project 10 | Author: Tuan PM 11 | Version: 2014-2015 12 | 13 | ----------------------------------------------------------------------------------------- 14 | * Copyright (c) 2014-2015, Tuan PM 15 | * All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted provided that the following conditions are met: 19 | * 20 | * * Redistributions of source code must retain the above copyright notice, 21 | * this list of conditions and the following disclaimer. 22 | * * Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * * Neither the name of Redis nor the names of its contributors may be used 26 | * to endorse or promote products derived from this software without 27 | * specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 30 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 33 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 36 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 37 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 | * POSSIBILITY OF SUCH DAMAGE. 40 | */ 41 | 42 | #ifndef USER_CONFIG_H_ 43 | #define USER_CONFIG_H_ 44 | #include "os_type.h" 45 | #include "globals.h" 46 | 47 | #define CFG_HOLDER 0x00FF55A4 /* Change this value to load default configurations */ 48 | #define CFG_LOCATION 0x3C /* Please don't change or if you know what you doing */ 49 | 50 | #ifdef MQTT_USER_CONFIG 51 | #include "user_config.h" 52 | #endif 53 | 54 | /* Conversion from IP to u32 */ 55 | #define IP(a,b,c,d) ((u32)(d)<<24)+((u32)(c)<<16)+((u32)(b)<<8)+a 56 | 57 | /* IP's */ 58 | #define DHCPIP 0 59 | #define MYIP IP(192,168,0,222) 60 | #define ROUTER_IP IP(192,168,0,1) 61 | #define NETMASK IP(255,255,255,0) 62 | #define DNSIP ROUTER_IP 63 | 64 | /* Dummy MAC Address for ENC - ENC specific 65 | Only actually used if USE_SEPARATE_ENC_MAC is defined */ 66 | #define MYMAC1 0x00 67 | #define MYMAC2 0x11 68 | #define MYMAC3 0x22 69 | #define MYMAC4 0x33 70 | #define MYMAC5 0x44 71 | #define MYMAC6 0x55 72 | 73 | 74 | typedef struct{ 75 | uint32_t cfg_holder; 76 | 77 | /* ENC28J60 ethernet IP address's - placed here to keep alignment */ 78 | #ifdef IPS_IN_UNION 79 | union { 80 | uint8_t thech[4]; 81 | uint32_t theint; 82 | } setipaddr; 83 | union { 84 | uint8_t thech[4]; 85 | uint32_t theint; 86 | } ethip; 87 | union { 88 | uint8_t thech[4]; 89 | uint32_t theint; 90 | } netmask; 91 | union { 92 | uint8_t thech[4]; 93 | uint32_t theint; 94 | } router_ip; 95 | union { 96 | uint8_t thech[4]; 97 | uint32_t theint; 98 | } dns_server_ip; 99 | #else 100 | uint8_t setipaddr[4]; 101 | uint8_t ethip[4]; 102 | uint8_t netmask[4]; 103 | uint8_t router_ip[4]; 104 | uint8_t dns_server_ip[4]; 105 | #endif 106 | 107 | uint8_t device_id[16]; 108 | 109 | uint8_t sta_ssid[64]; 110 | uint8_t sta_pwd[64]; 111 | uint32_t sta_type; 112 | 113 | uint8_t mqtt_host[64]; 114 | uint32_t mqtt_port; 115 | uint8_t mqtt_user[32]; 116 | uint8_t mqtt_pass[32]; 117 | uint32_t mqtt_keepalive; 118 | uint8_t security; 119 | } SYSCFG; 120 | 121 | typedef struct { 122 | uint8 flag; 123 | uint8 pad[3]; 124 | } SAVE_FLAG; 125 | 126 | void ICACHE_FLASH_ATTR CFG_Save(); 127 | void ICACHE_FLASH_ATTR CFG_Load(); 128 | 129 | extern SYSCFG sysCfg; 130 | 131 | #endif /* USER_CONFIG_H_ */ 132 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/mman.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include "mman.h" 7 | 8 | #ifndef FILE_MAP_EXECUTE 9 | #define FILE_MAP_EXECUTE 0x0020 10 | #endif /* FILE_MAP_EXECUTE */ 11 | 12 | static int __map_mman_error(const DWORD err, const int deferr) 13 | { 14 | if (err == 0) 15 | return 0; 16 | //TODO: implement 17 | return err; 18 | } 19 | 20 | static DWORD __map_mmap_prot_page(const int prot) 21 | { 22 | DWORD protect = 0; 23 | 24 | if (prot == PROT_NONE) 25 | return protect; 26 | 27 | if ((prot & PROT_EXEC) != 0) 28 | { 29 | protect = ((prot & PROT_WRITE) != 0) ? 30 | PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ; 31 | } 32 | else 33 | { 34 | protect = ((prot & PROT_WRITE) != 0) ? 35 | PAGE_READWRITE : PAGE_READONLY; 36 | } 37 | 38 | return protect; 39 | } 40 | 41 | static DWORD __map_mmap_prot_file(const int prot) 42 | { 43 | DWORD desiredAccess = 0; 44 | 45 | if (prot == PROT_NONE) 46 | return desiredAccess; 47 | 48 | if ((prot & PROT_READ) != 0) 49 | desiredAccess |= FILE_MAP_READ; 50 | if ((prot & PROT_WRITE) != 0) 51 | desiredAccess |= FILE_MAP_WRITE; 52 | if ((prot & PROT_EXEC) != 0) 53 | desiredAccess |= FILE_MAP_EXECUTE; 54 | 55 | return desiredAccess; 56 | } 57 | 58 | void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) 59 | { 60 | HANDLE fm, h; 61 | 62 | void * map = MAP_FAILED; 63 | 64 | #ifdef _MSC_VER 65 | #pragma warning(push) 66 | #pragma warning(disable: 4293) 67 | #endif 68 | 69 | const DWORD dwFileOffsetLow = (sizeof(off_t) <= sizeof(DWORD)) ? 70 | (DWORD)off : (DWORD)(off & 0xFFFFFFFFL); 71 | const DWORD dwFileOffsetHigh = (sizeof(off_t) <= sizeof(DWORD)) ? 72 | (DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL); 73 | const DWORD protect = __map_mmap_prot_page(prot); 74 | const DWORD desiredAccess = __map_mmap_prot_file(prot); 75 | 76 | const off_t maxSize = off + (off_t)len; 77 | 78 | const DWORD dwMaxSizeLow = (sizeof(off_t) <= sizeof(DWORD)) ? 79 | (DWORD)maxSize : (DWORD)(maxSize & 0xFFFFFFFFL); 80 | const DWORD dwMaxSizeHigh = (sizeof(off_t) <= sizeof(DWORD)) ? 81 | (DWORD)0 : (DWORD)((maxSize >> 32) & 0xFFFFFFFFL); 82 | 83 | #ifdef _MSC_VER 84 | #pragma warning(pop) 85 | #endif 86 | 87 | errno = 0; 88 | 89 | if (len == 0 90 | /* Unsupported flag combinations */ 91 | || (flags & MAP_FIXED) != 0 92 | /* Usupported protection combinations */ 93 | || prot == PROT_EXEC) 94 | { 95 | errno = EINVAL; 96 | return MAP_FAILED; 97 | } 98 | 99 | h = ((flags & MAP_ANONYMOUS) == 0) ? 100 | (HANDLE)_get_osfhandle(fildes) : INVALID_HANDLE_VALUE; 101 | 102 | if ((flags & MAP_ANONYMOUS) == 0 && h == INVALID_HANDLE_VALUE) 103 | { 104 | errno = EBADF; 105 | return MAP_FAILED; 106 | } 107 | 108 | fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL); 109 | 110 | if (fm == NULL) 111 | { 112 | errno = __map_mman_error(GetLastError(), EPERM); 113 | return MAP_FAILED; 114 | } 115 | 116 | map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len); 117 | 118 | CloseHandle(fm); 119 | 120 | if (map == NULL) 121 | { 122 | errno = __map_mman_error(GetLastError(), EPERM); 123 | return MAP_FAILED; 124 | } 125 | 126 | return map; 127 | } 128 | 129 | int munmap(void *addr, size_t len) 130 | { 131 | if (UnmapViewOfFile(addr)) 132 | return 0; 133 | 134 | errno = __map_mman_error(GetLastError(), EPERM); 135 | 136 | return -1; 137 | } 138 | 139 | int mprotect(void *addr, size_t len, int prot) 140 | { 141 | DWORD newProtect = __map_mmap_prot_page(prot); 142 | DWORD oldProtect = 0; 143 | 144 | if (VirtualProtect(addr, len, newProtect, &oldProtect)) 145 | return 0; 146 | 147 | errno = __map_mman_error(GetLastError(), EPERM); 148 | 149 | return -1; 150 | } 151 | 152 | int msync(void *addr, size_t len, int flags) 153 | { 154 | if (FlushViewOfFile(addr, len)) 155 | return 0; 156 | 157 | errno = __map_mman_error(GetLastError(), EPERM); 158 | 159 | return -1; 160 | } 161 | 162 | int mlock(const void *addr, size_t len) 163 | { 164 | if (VirtualLock((LPVOID)addr, len)) 165 | return 0; 166 | 167 | errno = __map_mman_error(GetLastError(), EPERM); 168 | 169 | return -1; 170 | } 171 | 172 | int munlock(const void *addr, size_t len) 173 | { 174 | if (VirtualUnlock((LPVOID)addr, len)) 175 | return 0; 176 | 177 | errno = __map_mman_error(GetLastError(), EPERM); 178 | 179 | return -1; 180 | } 181 | -------------------------------------------------------------------------------- /libesphttpd/core/sha1.c: -------------------------------------------------------------------------------- 1 | /* This code is public-domain - it is based on libcrypt 2 | * placed in the public domain by Wei Dai and other contributors. 3 | */ 4 | // gcc -Wall -DSHA1TEST -o sha1test sha1.c && ./sha1test 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "sha1.h" 11 | 12 | //according to http://ip.cadence.com/uploads/pdf/xtensalx_overview_handbook.pdf 13 | // the cpu is normally defined as little ending, but can be big endian too. 14 | // for the esp this seems to work 15 | //#define SHA_BIG_ENDIAN 16 | 17 | 18 | 19 | /* code */ 20 | #define SHA1_K0 0x5a827999 21 | #define SHA1_K20 0x6ed9eba1 22 | #define SHA1_K40 0x8f1bbcdc 23 | #define SHA1_K60 0xca62c1d6 24 | 25 | void ICACHE_FLASH_ATTR sha1_init(sha1nfo *s) { 26 | s->state[0] = 0x67452301; 27 | s->state[1] = 0xefcdab89; 28 | s->state[2] = 0x98badcfe; 29 | s->state[3] = 0x10325476; 30 | s->state[4] = 0xc3d2e1f0; 31 | s->byteCount = 0; 32 | s->bufferOffset = 0; 33 | } 34 | 35 | uint32_t ICACHE_FLASH_ATTR sha1_rol32(uint32_t number, uint8_t bits) { 36 | return ((number << bits) | (number >> (32-bits))); 37 | } 38 | 39 | void ICACHE_FLASH_ATTR sha1_hashBlock(sha1nfo *s) { 40 | uint8_t i; 41 | uint32_t a,b,c,d,e,t; 42 | 43 | a=s->state[0]; 44 | b=s->state[1]; 45 | c=s->state[2]; 46 | d=s->state[3]; 47 | e=s->state[4]; 48 | for (i=0; i<80; i++) { 49 | if (i>=16) { 50 | t = s->buffer[(i+13)&15] ^ s->buffer[(i+8)&15] ^ s->buffer[(i+2)&15] ^ s->buffer[i&15]; 51 | s->buffer[i&15] = sha1_rol32(t,1); 52 | } 53 | if (i<20) { 54 | t = (d ^ (b & (c ^ d))) + SHA1_K0; 55 | } else if (i<40) { 56 | t = (b ^ c ^ d) + SHA1_K20; 57 | } else if (i<60) { 58 | t = ((b & c) | (d & (b | c))) + SHA1_K40; 59 | } else { 60 | t = (b ^ c ^ d) + SHA1_K60; 61 | } 62 | t+=sha1_rol32(a,5) + e + s->buffer[i&15]; 63 | e=d; 64 | d=c; 65 | c=sha1_rol32(b,30); 66 | b=a; 67 | a=t; 68 | } 69 | s->state[0] += a; 70 | s->state[1] += b; 71 | s->state[2] += c; 72 | s->state[3] += d; 73 | s->state[4] += e; 74 | } 75 | 76 | void ICACHE_FLASH_ATTR sha1_addUncounted(sha1nfo *s, uint8_t data) { 77 | uint8_t * const b = (uint8_t*) s->buffer; 78 | #ifdef SHA_BIG_ENDIAN 79 | b[s->bufferOffset] = data; 80 | #else 81 | b[s->bufferOffset ^ 3] = data; 82 | #endif 83 | s->bufferOffset++; 84 | if (s->bufferOffset == BLOCK_LENGTH) { 85 | sha1_hashBlock(s); 86 | s->bufferOffset = 0; 87 | } 88 | } 89 | 90 | void ICACHE_FLASH_ATTR sha1_writebyte(sha1nfo *s, uint8_t data) { 91 | ++s->byteCount; 92 | sha1_addUncounted(s, data); 93 | } 94 | 95 | void ICACHE_FLASH_ATTR sha1_write(sha1nfo *s, const char *data, size_t len) { 96 | for (;len--;) sha1_writebyte(s, (uint8_t) *data++); 97 | } 98 | 99 | void ICACHE_FLASH_ATTR sha1_pad(sha1nfo *s) { 100 | // Implement SHA-1 padding (fips180-2 §5.1.1) 101 | 102 | // Pad with 0x80 followed by 0x00 until the end of the block 103 | sha1_addUncounted(s, 0x80); 104 | while (s->bufferOffset != 56) sha1_addUncounted(s, 0x00); 105 | 106 | // Append length in the last 8 bytes 107 | sha1_addUncounted(s, 0); // We're only using 32 bit lengths 108 | sha1_addUncounted(s, 0); // But SHA-1 supports 64 bit lengths 109 | sha1_addUncounted(s, 0); // So zero pad the top bits 110 | sha1_addUncounted(s, s->byteCount >> 29); // Shifting to multiply by 8 111 | sha1_addUncounted(s, s->byteCount >> 21); // as SHA-1 supports bitstreams as well as 112 | sha1_addUncounted(s, s->byteCount >> 13); // byte. 113 | sha1_addUncounted(s, s->byteCount >> 5); 114 | sha1_addUncounted(s, s->byteCount << 3); 115 | } 116 | 117 | uint8_t* ICACHE_FLASH_ATTR sha1_result(sha1nfo *s) { 118 | // Pad to complete the last block 119 | sha1_pad(s); 120 | 121 | #ifndef SHA_BIG_ENDIAN 122 | // Swap byte order back 123 | int i; 124 | for (i=0; i<5; i++) { 125 | s->state[i]= 126 | (((s->state[i])<<24)& 0xff000000) 127 | | (((s->state[i])<<8) & 0x00ff0000) 128 | | (((s->state[i])>>8) & 0x0000ff00) 129 | | (((s->state[i])>>24)& 0x000000ff); 130 | } 131 | #endif 132 | 133 | // Return pointer to hash (20 characters) 134 | return (uint8_t*) s->state; 135 | } 136 | 137 | #define HMAC_IPAD 0x36 138 | #define HMAC_OPAD 0x5c 139 | 140 | void ICACHE_FLASH_ATTR sha1_initHmac(sha1nfo *s, const uint8_t* key, int keyLength) { 141 | uint8_t i; 142 | memset(s->keyBuffer, 0, BLOCK_LENGTH); 143 | if (keyLength > BLOCK_LENGTH) { 144 | // Hash long keys 145 | sha1_init(s); 146 | for (;keyLength--;) sha1_writebyte(s, *key++); 147 | memcpy(s->keyBuffer, sha1_result(s), HASH_LENGTH); 148 | } else { 149 | // Block length keys are used as is 150 | memcpy(s->keyBuffer, key, keyLength); 151 | } 152 | // Start inner hash 153 | sha1_init(s); 154 | for (i=0; ikeyBuffer[i] ^ HMAC_IPAD); 156 | } 157 | } 158 | 159 | uint8_t* ICACHE_FLASH_ATTR sha1_resultHmac(sha1nfo *s) { 160 | uint8_t i; 161 | // Complete inner hash 162 | memcpy(s->innerHash,sha1_result(s),HASH_LENGTH); 163 | // Calculate outer hash 164 | sha1_init(s); 165 | for (i=0; ikeyBuffer[i] ^ HMAC_OPAD); 166 | for (i=0; iinnerHash[i]); 167 | return sha1_result(s); 168 | } 169 | -------------------------------------------------------------------------------- /user/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | /* config.c 3 | * 4 | ----------------------------------------------------------------------------------------- 5 | Author: Mark F (Cicero-MF) mark@cdelec.co.za 6 | Known Issues: none 7 | Version: 18.05.2016 8 | Description: Simple Ethernet stack for the enc28j60 and an esp8266 9 | 10 | This code was modified from TuanPM's mqtt project 11 | Author: Tuan PM 12 | Version: 2014-2015 13 | 14 | ----------------------------------------------------------------------------------------- 15 | 16 | * Copyright (c) 2014-2015, Tuan PM 17 | * All rights reserved. 18 | * 19 | * Redistribution and use in source and binary forms, with or without 20 | * modification, are permitted provided that the following conditions are met: 21 | * 22 | * * Redistributions of source code must retain the above copyright notice, 23 | * this list of conditions and the following disclaimer. 24 | * * Redistributions in binary form must reproduce the above copyright 25 | * notice, this list of conditions and the following disclaimer in the 26 | * documentation and/or other materials provided with the distribution. 27 | * * Neither the name of Redis nor the names of its contributors may be used 28 | * to endorse or promote products derived from this software without 29 | * specific prior written permission. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 32 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 35 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 36 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 39 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 | * POSSIBILITY OF SUCH DAMAGE. 42 | */ 43 | #include "globals.h" 44 | #include "esp8266.h" 45 | #include "user_interface.h" 46 | #include "config.h" 47 | 48 | SYSCFG sysCfg; 49 | SAVE_FLAG saveFlag; 50 | 51 | void ICACHE_FLASH_ATTR CFG_Save (void) { 52 | spi_flash_read((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE, 53 | (uint32 *)&saveFlag, sizeof(SAVE_FLAG)); 54 | 55 | if (saveFlag.flag == 0) { 56 | spi_flash_erase_sector(CFG_LOCATION + 1); 57 | spi_flash_write((CFG_LOCATION + 1) * SPI_FLASH_SEC_SIZE, 58 | (uint32 *)&sysCfg, sizeof(SYSCFG)); 59 | saveFlag.flag = 1; 60 | spi_flash_erase_sector(CFG_LOCATION + 3); 61 | spi_flash_write((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE, 62 | (uint32 *)&saveFlag, sizeof(SAVE_FLAG)); 63 | } else { 64 | spi_flash_erase_sector(CFG_LOCATION + 0); 65 | spi_flash_write((CFG_LOCATION + 0) * SPI_FLASH_SEC_SIZE, 66 | (uint32 *)&sysCfg, sizeof(SYSCFG)); 67 | saveFlag.flag = 0; 68 | spi_flash_erase_sector(CFG_LOCATION + 3); 69 | spi_flash_write((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE, 70 | (uint32 *)&saveFlag, sizeof(SAVE_FLAG)); 71 | } 72 | } 73 | 74 | void ICACHE_FLASH_ATTR CFG_Load (void) { 75 | CONFIG_DEBUG("\r\nload ...\r\n"); 76 | spi_flash_read((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE, 77 | (uint32 *)&saveFlag, sizeof(SAVE_FLAG)); 78 | if (saveFlag.flag == 0) { 79 | spi_flash_read((CFG_LOCATION + 0) * SPI_FLASH_SEC_SIZE, 80 | (uint32 *)&sysCfg, sizeof(SYSCFG)); 81 | } else { 82 | spi_flash_read((CFG_LOCATION + 1) * SPI_FLASH_SEC_SIZE, 83 | (uint32 *)&sysCfg, sizeof(SYSCFG)); 84 | } 85 | 86 | if(sysCfg.cfg_holder != CFG_HOLDER) { 87 | os_memset(&sysCfg, 0x00, sizeof sysCfg); 88 | 89 | 90 | sysCfg.cfg_holder = CFG_HOLDER; 91 | 92 | /* Save the default ethernet IP's */ 93 | #ifdef IPS_IN_UNION 94 | sysCfg.setipaddr.theint = DHCPIP; 95 | sysCfg.ethip.theint = MYIP; 96 | sysCfg.netmask.theint = NETMASK; 97 | sysCfg.router_ip.theint = ROUTER_IP; 98 | sysCfg.dns_server_ip.theint = DNSIP; 99 | #else 100 | (*((u32*)&sysCfg.setipaddr)) = DHCPIP; 101 | (*((u32*)&sysCfg.ethip)) = MYIP; 102 | (*((u32*)&sysCfg.netmask)) = NETMASK; 103 | (*((u32*)&sysCfg.router_ip)) = ROUTER_IP; 104 | (*((u32*)&sysCfg.dns_server_ip)) = DNSIP; 105 | #endif 106 | 107 | #ifdef MQTT_USER_CONFIG 108 | os_sprintf(sysCfg.sta_ssid, "%s", STA_SSID); 109 | os_sprintf(sysCfg.sta_pwd, "%s", STA_PASS); 110 | sysCfg.sta_type = STA_TYPE; 111 | 112 | os_sprintf(sysCfg.device_id, MQTT_CLIENT_ID, system_get_chip_id()); 113 | os_sprintf(sysCfg.mqtt_host, "%s", MQTT_HOST); 114 | sysCfg.mqtt_port = MQTT_PORT; 115 | os_sprintf(sysCfg.mqtt_user, "%s", MQTT_USER); 116 | os_sprintf(sysCfg.mqtt_pass, "%s", MQTT_PASS); 117 | 118 | sysCfg.security = DEFAULT_SECURITY; /* default non ssl */ 119 | 120 | sysCfg.mqtt_keepalive = MQTT_KEEPALIVE; 121 | #endif 122 | 123 | CONFIG_DEBUG("CFG_Load - default configuration\r\n"); 124 | 125 | CFG_Save(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /libesphttpd/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Directory the Makefile is in. Please don't include other Makefiles before this. 3 | THISDIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 4 | 5 | #Include httpd config from lower level, if it exists 6 | -include ../esphttpdconfig.mk 7 | 8 | 9 | #Default options. If you want to change them, please create ../esphttpdconfig.mk with the options you want in it. 10 | GZIP_COMPRESSION ?= no 11 | COMPRESS_W_YUI ?= no 12 | YUI-COMPRESSOR ?= /usr/bin/yui-compressor 13 | USE_HEATSHRINK ?= yes 14 | 15 | 16 | 17 | # Output directors to store intermediate compiled files 18 | # relative to the project directory 19 | BUILD_BASE = build 20 | 21 | # Base directory for the compiler. Needs a / at the end; if not set it'll use the tools that are in 22 | # the PATH. 23 | XTENSA_TOOLS_ROOT ?= c:/Espressif/xtensa-lx106-elf/bin 24 | 25 | # base directory of the ESP8266 SDK package, absolute 26 | SDK_BASE ?= c:/Espressif/ESP8266_SDK 27 | 28 | # name for the target project 29 | LIB = libesphttpd.a 30 | 31 | # which modules (subdirectories) of the project to include in compiling 32 | MODULES = espfs core util 33 | EXTRA_INCDIR = ./include \ 34 | . \ 35 | lib/heatshrink/ \ 36 | ../user 37 | 38 | 39 | # compiler flags using during compilation of source files 40 | CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ 41 | -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -D_STDINT_H \ 42 | -Wno-address 43 | 44 | # various paths from the SDK used in this project 45 | SDK_LIBDIR = lib 46 | SDK_LDDIR = ld 47 | SDK_INCDIR = include 48 | 49 | # select which tools to use as compiler, librarian and linker 50 | CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 51 | AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar 52 | LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 53 | OBJCOPY := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objcopy 54 | OBJDUMP := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump 55 | 56 | #### 57 | #### no user configurable options below here 58 | #### 59 | SRC_DIR := $(MODULES) 60 | BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) 61 | 62 | SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) 63 | 64 | SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) 65 | OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) 66 | 67 | INCDIR := $(addprefix -I,$(SRC_DIR)) 68 | EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) 69 | MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) 70 | 71 | V ?= $(VERBOSE) 72 | ifeq ("$(V)","1") 73 | Q := 74 | vecho := @true 75 | else 76 | Q := @ 77 | vecho := @echo 78 | endif 79 | 80 | ifeq ("$(GZIP_COMPRESSION)","yes") 81 | CFLAGS += -DGZIP_COMPRESSION 82 | endif 83 | 84 | ifeq ("$(USE_HEATSHRINK)","yes") 85 | CFLAGS += -DESPFS_HEATSHRINK 86 | endif 87 | 88 | vpath %.c $(SRC_DIR) 89 | 90 | define compile-objects 91 | $1/%.o: %.c 92 | $(vecho) "CC $$<" 93 | $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ 94 | endef 95 | 96 | .PHONY: all checkdirs clean webpages.espfs submodules 97 | 98 | all: checkdirs $(LIB) webpages.espfs libwebpages-espfs.a 99 | 100 | submodules: lib/heatshrink/Makefile 101 | lib/heatshrink/Makefile: 102 | $(Q) echo "Heatshrink isn't found. Checking out submodules to fetch it." 103 | $(Q) git submodule init 104 | $(Q) git submodule update 105 | 106 | 107 | $(LIB): submodules $(OBJ) 108 | $(vecho) "AR $@" 109 | $(Q) $(AR) cru $@ $(OBJ) 110 | 111 | checkdirs: $(BUILD_DIR) 112 | 113 | $(BUILD_DIR): 114 | $(Q) mkdir -p $@ 115 | 116 | 117 | webpages.espfs: $(HTMLDIR) espfs/mkespfsimage/mkespfsimage 118 | ifeq ("$(COMPRESS_W_YUI)","yes") 119 | $(Q) rm -rf html_compressed; 120 | $(Q) cp -r ../html html_compressed; 121 | $(Q) echo "Compression assets with yui-compressor. This may take a while..." 122 | $(Q) for file in `find html_compressed -type f -name "*.js"`; do $(YUI-COMPRESSOR) --type js $$file -o $$file; done 123 | $(Q) for file in `find html_compressed -type f -name "*.css"`; do $(YUI-COMPRESSOR) --type css $$file -o $$file; done 124 | $(Q) awk "BEGIN {printf \"YUI compression ratio was: %.2f%%\\n\", (`du -b -s html_compressed/ | sed 's/\([0-9]*\).*/\1/'`/`du -b -s ../html/ | sed 's/\([0-9]*\).*/\1/'`)*100}" 125 | # mkespfsimage will compress html, css and js files with gzip by default if enabled 126 | # override with -g cmdline parameter 127 | $(Q) cd html_compressed; find | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd ..; 128 | else 129 | $(Q) cd ../html; find | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd .. 130 | endif 131 | 132 | libwebpages-espfs.a: webpages.espfs 133 | $(Q) $(OBJCOPY) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.irom0.literal \ 134 | --redefine-sym _binary_webpages_espfs_start=webpages_espfs_start \ 135 | --redefine-sym _binary_webpages_espfs_end=webpages_espfs_end \ 136 | --redefine-sym _binary_webpages_espfs_size=webpages_espfs_size \ 137 | webpages.espfs build/webpages.espfs.o 138 | $(Q) $(AR) cru $@ build/webpages.espfs.o 139 | 140 | espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/ 141 | $(Q) $(MAKE) -C espfs/mkespfsimage USE_HEATSHRINK="$(USE_HEATSHRINK)" GZIP_COMPRESSION="$(GZIP_COMPRESSION)" 142 | 143 | clean: 144 | $(Q) rm -f $(LIB) 145 | $(Q) rm -rf $(BUILD_BASE) 146 | $(Q) find $(BUILD_BASE) -type f | xargs rm -f 147 | $(Q) make -C espfs/mkespfsimage/ clean 148 | $(Q) make -C espfs/mkespfsimage/mman-win32 clean 149 | $(Q) rm -rf $(FW_BASE) 150 | $(Q) rm -f webpages.espfs 151 | $(Q) rm -f libwebpages-espfs.a 152 | ifeq ("$(COMPRESS_W_YUI)","yes") 153 | $(Q) rm -rf html_compressed 154 | endif 155 | 156 | $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) 157 | -------------------------------------------------------------------------------- /libesphttpd/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 | -------------------------------------------------------------------------------- /include/uart_hw.h: -------------------------------------------------------------------------------- 1 | //Generated at 2012-07-03 18:44:06 2 | /* 3 | * Copyright (c) 2010 - 2011 Espressif System 4 | * 5 | */ 6 | 7 | #ifndef UART_REGISTER_H_INCLUDED 8 | #define UART_REGISTER_H_INCLUDED 9 | #define REG_UART_BASE( i ) (0x60000000+(i)*0xf00) 10 | //version value:32'h062000 11 | 12 | #define UART_FIFO( i ) (REG_UART_BASE( i ) + 0x0) 13 | #define UART_RXFIFO_RD_BYTE 0x000000FF 14 | #define UART_RXFIFO_RD_BYTE_S 0 15 | 16 | #define UART_INT_RAW( i ) (REG_UART_BASE( i ) + 0x4) 17 | #define UART_RXFIFO_TOUT_INT_RAW (BIT(8)) 18 | #define UART_BRK_DET_INT_RAW (BIT(7)) 19 | #define UART_CTS_CHG_INT_RAW (BIT(6)) 20 | #define UART_DSR_CHG_INT_RAW (BIT(5)) 21 | #define UART_RXFIFO_OVF_INT_RAW (BIT(4)) 22 | #define UART_FRM_ERR_INT_RAW (BIT(3)) 23 | #define UART_PARITY_ERR_INT_RAW (BIT(2)) 24 | #define UART_TXFIFO_EMPTY_INT_RAW (BIT(1)) 25 | #define UART_RXFIFO_FULL_INT_RAW (BIT(0)) 26 | 27 | #define UART_INT_ST( i ) (REG_UART_BASE( i ) + 0x8) 28 | #define UART_RXFIFO_TOUT_INT_ST (BIT(8)) 29 | #define UART_BRK_DET_INT_ST (BIT(7)) 30 | #define UART_CTS_CHG_INT_ST (BIT(6)) 31 | #define UART_DSR_CHG_INT_ST (BIT(5)) 32 | #define UART_RXFIFO_OVF_INT_ST (BIT(4)) 33 | #define UART_FRM_ERR_INT_ST (BIT(3)) 34 | #define UART_PARITY_ERR_INT_ST (BIT(2)) 35 | #define UART_TXFIFO_EMPTY_INT_ST (BIT(1)) 36 | #define UART_RXFIFO_FULL_INT_ST (BIT(0)) 37 | 38 | #define UART_INT_ENA( i ) (REG_UART_BASE( i ) + 0xC) 39 | #define UART_RXFIFO_TOUT_INT_ENA (BIT(8)) 40 | #define UART_BRK_DET_INT_ENA (BIT(7)) 41 | #define UART_CTS_CHG_INT_ENA (BIT(6)) 42 | #define UART_DSR_CHG_INT_ENA (BIT(5)) 43 | #define UART_RXFIFO_OVF_INT_ENA (BIT(4)) 44 | #define UART_FRM_ERR_INT_ENA (BIT(3)) 45 | #define UART_PARITY_ERR_INT_ENA (BIT(2)) 46 | #define UART_TXFIFO_EMPTY_INT_ENA (BIT(1)) 47 | #define UART_RXFIFO_FULL_INT_ENA (BIT(0)) 48 | 49 | #define UART_INT_CLR( i ) (REG_UART_BASE( i ) + 0x10) 50 | #define UART_RXFIFO_TOUT_INT_CLR (BIT(8)) 51 | #define UART_BRK_DET_INT_CLR (BIT(7)) 52 | #define UART_CTS_CHG_INT_CLR (BIT(6)) 53 | #define UART_DSR_CHG_INT_CLR (BIT(5)) 54 | #define UART_RXFIFO_OVF_INT_CLR (BIT(4)) 55 | #define UART_FRM_ERR_INT_CLR (BIT(3)) 56 | #define UART_PARITY_ERR_INT_CLR (BIT(2)) 57 | #define UART_TXFIFO_EMPTY_INT_CLR (BIT(1)) 58 | #define UART_RXFIFO_FULL_INT_CLR (BIT(0)) 59 | 60 | #define UART_CLKDIV( i ) (REG_UART_BASE( i ) + 0x14) 61 | #define UART_CLKDIV_CNT 0x000FFFFF 62 | #define UART_CLKDIV_S 0 63 | 64 | #define UART_AUTOBAUD( i ) (REG_UART_BASE( i ) + 0x18) 65 | #define UART_GLITCH_FILT 0x000000FF 66 | #define UART_GLITCH_FILT_S 8 67 | #define UART_AUTOBAUD_EN (BIT(0)) 68 | 69 | #define UART_STATUS( i ) (REG_UART_BASE( i ) + 0x1C) 70 | #define UART_TXD (BIT(31)) 71 | #define UART_RTSN (BIT(30)) 72 | #define UART_DTRN (BIT(29)) 73 | #define UART_TXFIFO_CNT 0x000000FF 74 | #define UART_TXFIFO_CNT_S 16 75 | #define UART_RXD (BIT(15)) 76 | #define UART_CTSN (BIT(14)) 77 | #define UART_DSRN (BIT(13)) 78 | #define UART_RXFIFO_CNT 0x000000FF 79 | #define UART_RXFIFO_CNT_S 0 80 | 81 | #define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20) 82 | #define UART_TXFIFO_RST (BIT(18)) 83 | #define UART_RXFIFO_RST (BIT(17)) 84 | #define UART_IRDA_EN (BIT(16)) 85 | #define UART_TX_FLOW_EN (BIT(15)) 86 | #define UART_LOOPBACK (BIT(14)) 87 | #define UART_IRDA_RX_INV (BIT(13)) 88 | #define UART_IRDA_TX_INV (BIT(12)) 89 | #define UART_IRDA_WCTL (BIT(11)) 90 | #define UART_IRDA_TX_EN (BIT(10)) 91 | #define UART_IRDA_DPLX (BIT(9)) 92 | #define UART_TXD_BRK (BIT(8)) 93 | #define UART_SW_DTR (BIT(7)) 94 | #define UART_SW_RTS (BIT(6)) 95 | #define UART_STOP_BIT_NUM 0x00000003 96 | #define UART_STOP_BIT_NUM_S 4 97 | #define UART_BIT_NUM 0x00000003 98 | #define UART_BIT_NUM_S 2 99 | #define UART_PARITY_EN (BIT(1)) 100 | #define UART_PARITY (BIT(0)) 101 | 102 | #define UART_CONF1( i ) (REG_UART_BASE( i ) + 0x24) 103 | #define UART_RX_TOUT_EN (BIT(31)) 104 | #define UART_RX_TOUT_THRHD 0x0000007F 105 | #define UART_RX_TOUT_THRHD_S 24 106 | #define UART_RX_FLOW_EN (BIT(23)) 107 | #define UART_RX_FLOW_THRHD 0x0000007F 108 | #define UART_RX_FLOW_THRHD_S 16 109 | #define UART_TXFIFO_EMPTY_THRHD 0x0000007F 110 | #define UART_TXFIFO_EMPTY_THRHD_S 8 111 | #define UART_RXFIFO_FULL_THRHD 0x0000007F 112 | #define UART_RXFIFO_FULL_THRHD_S 0 113 | 114 | #define UART_LOWPULSE( i ) (REG_UART_BASE( i ) + 0x28) 115 | #define UART_LOWPULSE_MIN_CNT 0x000FFFFF 116 | #define UART_LOWPULSE_MIN_CNT_S 0 117 | 118 | #define UART_HIGHPULSE( i ) (REG_UART_BASE( i ) + 0x2C) 119 | #define UART_HIGHPULSE_MIN_CNT 0x000FFFFF 120 | #define UART_HIGHPULSE_MIN_CNT_S 0 121 | 122 | #define UART_PULSE_NUM( i ) (REG_UART_BASE( i ) + 0x30) 123 | #define UART_PULSE_NUM_CNT 0x0003FF 124 | #define UART_PULSE_NUM_CNT_S 0 125 | 126 | #define UART_DATE( i ) (REG_UART_BASE( i ) + 0x78) 127 | #define UART_ID( i ) (REG_UART_BASE( i ) + 0x7C) 128 | #endif // UART_REGISTER_H_INCLUDED 129 | 130 | #define RX_BUFF_SIZE 256 131 | #define TX_BUFF_SIZE 100 132 | #define UART0 0 133 | #define UART1 1 134 | 135 | typedef enum { 136 | FIVE_BITS = 0x0, 137 | SIX_BITS = 0x1, 138 | SEVEN_BITS = 0x2, 139 | EIGHT_BITS = 0x3 140 | } UartBitsNum4Char; 141 | 142 | typedef enum { 143 | ONE_STOP_BIT = 0, 144 | ONE_HALF_STOP_BIT = BIT2, 145 | TWO_STOP_BIT = BIT2 146 | } UartStopBitsNum; 147 | 148 | typedef enum { 149 | NONE_BITS = 0, 150 | ODD_BITS = 0, 151 | EVEN_BITS = BIT4 152 | } UartParityMode; 153 | 154 | typedef enum { 155 | STICK_PARITY_DIS = 0, 156 | STICK_PARITY_EN = BIT3 | BIT5 157 | } UartExistParity; 158 | 159 | typedef enum { 160 | BIT_RATE_9600 = 9600, 161 | BIT_RATE_19200 = 19200, 162 | BIT_RATE_38400 = 38400, 163 | BIT_RATE_57600 = 57600, 164 | BIT_RATE_74880 = 74880, 165 | BIT_RATE_115200 = 115200, 166 | BIT_RATE_230400 = 230400, 167 | BIT_RATE_460800 = 460800, 168 | BIT_RATE_921600 = 921600 169 | } UartBautRate; 170 | 171 | typedef enum { 172 | NONE_CTRL, 173 | HARDWARE_CTRL, 174 | XON_XOFF_CTRL 175 | } UartFlowCtrl; 176 | 177 | typedef enum { 178 | EMPTY, 179 | UNDER_WRITE, 180 | WRITE_OVER 181 | } RcvMsgBuffState; 182 | 183 | typedef struct { 184 | uint32 TrxBuffSize; 185 | uint8 *pTrxBuff; 186 | } TrxMsgBuff; 187 | 188 | typedef enum { 189 | BAUD_RATE_DET, 190 | WAIT_SYNC_FRM, 191 | SRCH_MSG_HEAD, 192 | RCV_MSG_BODY, 193 | RCV_ESC_CHAR, 194 | } RcvMsgState; 195 | 196 | -------------------------------------------------------------------------------- /libesphttpd/core/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 15 | #include "httpdespfs.h" 16 | #include "espfs.h" 17 | #include "espfsformat.h" 18 | #include "esp_enc_api.h" 19 | 20 | // The static files marked with FLAG_GZIP are compressed and will be served with GZIP compression. 21 | // If the client does not advertise that he accepts GZIP send following warning message (telnet users for e.g.) 22 | static const char *gzipNonSupportedMessage = "HTTP/1.0 501 Not implemented\r\nServer: esp8266-httpd/"HTTPDVER"\r\nConnection: close\r\nContent-Type: text/plain\r\nContent-Length: 52\r\n\r\nYour browser does not accept gzip-compressed data.\r\n"; 23 | 24 | 25 | //This is a catch-all cgi function. It takes the url passed to it, looks up the corresponding 26 | //path in the filesystem and if it exists, passes the file through. This simulates what a normal 27 | //webserver would do with static files. 28 | int ICACHE_FLASH_ATTR cgiEspFsHook(HttpdConnData *connData) { 29 | EspFsFile *file=connData->cgiData; 30 | int len; 31 | char buff[1024]; 32 | char acceptEncodingBuffer[64]; 33 | int isGzip; 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 | 48 | // The gzip checking code is intentionally without #ifdefs because checking 49 | // for FLAG_GZIP (which indicates gzip compressed file) is very easy, doesn't 50 | // mean additional overhead and is actually safer to be on at all times. 51 | // If there are no gzipped files in the image, the code bellow will not cause any harm. 52 | 53 | // Check if requested file was GZIP compressed 54 | isGzip = espFsFlags(file) & FLAG_GZIP; 55 | if (isGzip) { 56 | // Check the browser's "Accept-Encoding" header. If the client does not 57 | // advertise that he accepts GZIP send a warning message (telnet users for e.g.) 58 | httpdGetHeader(connData, "Accept-Encoding", acceptEncodingBuffer, 64); 59 | if (os_strstr(acceptEncodingBuffer, "gzip") == NULL) { 60 | //No Accept-Encoding: gzip header present 61 | httpdSend(connData, gzipNonSupportedMessage, -1); 62 | espFsClose(file); 63 | return HTTPD_CGI_DONE; 64 | } 65 | } 66 | 67 | connData->cgiData=file; 68 | httpdStartResponse(connData, 200); 69 | httpdHeader(connData, "Content-Type", httpdGetMimetype(connData->url)); 70 | if (isGzip) { 71 | httpdHeader(connData, "Content-Encoding", "gzip"); 72 | } 73 | httpdHeader(connData, "Cache-Control", "max-age=3600, must-revalidate"); 74 | httpdEndHeaders(connData); 75 | return HTTPD_CGI_MORE; 76 | } 77 | 78 | len=espFsRead(file, buff, 1024); 79 | //if (len>0) espconn_sent(connData->conn, (uint8 *)buff, len); 80 | if (len>0) esp_enc_api_sendData(connData->conn, (uint8 *)buff, len); 81 | if (len!=1024) { 82 | //We're done. 83 | espFsClose(file); 84 | return HTTPD_CGI_DONE; 85 | } else { 86 | //Ok, till next time. 87 | return HTTPD_CGI_MORE; 88 | } 89 | } 90 | 91 | 92 | //cgiEspFsTemplate can be used as a template. 93 | 94 | typedef struct { 95 | EspFsFile *file; 96 | void *tplArg; 97 | char token[64]; 98 | int tokenPos; 99 | } TplData; 100 | 101 | typedef void (* TplCallback)(HttpdConnData *connData, char *token, void **arg); 102 | 103 | int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData) { 104 | TplData *tpd=connData->cgiData; 105 | int len; 106 | int x, sp=0; 107 | char *e=NULL; 108 | char buff[1025]; 109 | 110 | if (connData->conn==NULL) { 111 | //Connection aborted. Clean up. 112 | ((TplCallback)(connData->cgiArg))(connData, NULL, &tpd->tplArg); 113 | espFsClose(tpd->file); 114 | os_free(tpd); 115 | return HTTPD_CGI_DONE; 116 | } 117 | 118 | if (tpd==NULL) { 119 | //First call to this cgi. Open the file so we can read it. 120 | tpd=(TplData *)os_malloc(sizeof(TplData)); 121 | tpd->file=espFsOpen(connData->url); 122 | tpd->tplArg=NULL; 123 | tpd->tokenPos=-1; 124 | if (tpd->file==NULL) { 125 | espFsClose(tpd->file); 126 | os_free(tpd); 127 | return HTTPD_CGI_NOTFOUND; 128 | } 129 | if (espFsFlags(tpd->file) & FLAG_GZIP) { 130 | os_printf("cgiEspFsTemplate: Trying to use gzip-compressed file %s as template!\n", connData->url); 131 | espFsClose(tpd->file); 132 | os_free(tpd); 133 | return HTTPD_CGI_NOTFOUND; 134 | } 135 | connData->cgiData=tpd; 136 | httpdStartResponse(connData, 200); 137 | httpdHeader(connData, "Content-Type", httpdGetMimetype(connData->url)); 138 | httpdEndHeaders(connData); 139 | return HTTPD_CGI_MORE; 140 | } 141 | 142 | len=espFsRead(tpd->file, buff, 1024); 143 | if (len>0) { 144 | sp=0; 145 | e=buff; 146 | for (x=0; xtokenPos==-1) { 148 | //Inside ordinary text. 149 | if (buff[x]=='%') { 150 | //Send raw data up to now 151 | if (sp!=0) httpdSend(connData, e, sp); 152 | sp=0; 153 | //Go collect token chars. 154 | tpd->tokenPos=0; 155 | } else { 156 | sp++; 157 | } 158 | } else { 159 | if (buff[x]=='%') { 160 | if (tpd->tokenPos==0) { 161 | //This is the second % of a %% escape string. 162 | //Send a single % and resume with the normal program flow. 163 | httpdSend(connData, "%", 1); 164 | } else { 165 | //This is an actual token. 166 | tpd->token[tpd->tokenPos++]=0; //zero-terminate token 167 | ((TplCallback)(connData->cgiArg))(connData, tpd->token, &tpd->tplArg); 168 | } 169 | //Go collect normal chars again. 170 | e=&buff[x+1]; 171 | tpd->tokenPos=-1; 172 | } else { 173 | if (tpd->tokenPos<(sizeof(tpd->token)-1)) tpd->token[tpd->tokenPos++]=buff[x]; 174 | } 175 | } 176 | } 177 | } 178 | //Send remaining bit. 179 | if (sp!=0) httpdSend(connData, e, sp); 180 | if (len!=1024) { 181 | //We're done. 182 | ((TplCallback)(connData->cgiArg))(connData, NULL, &tpd->tplArg); 183 | espFsClose(tpd->file); 184 | os_free(tpd); 185 | return HTTPD_CGI_DONE; 186 | } else { 187 | //Ok, till next time. 188 | return HTTPD_CGI_MORE; 189 | } 190 | } 191 | 192 | -------------------------------------------------------------------------------- /user/user_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * Jeroen Domburg wrote this file. As long as you retain 5 | * this notice you can do whatever you want with this stuff. If we meet some day, 6 | * and you think this stuff is worth it, you can buy me a beer in return. 7 | * ---------------------------------------------------------------------------- 8 | */ 9 | 10 | /* 11 | This is example code for the esphttpd library. It's a small-ish demo showing off 12 | the server, including WiFi connection management capabilities, some IO and 13 | some pictures of cats. 14 | */ 15 | #include 16 | #include "httpd.h" 17 | #include "io.h" 18 | #include "httpdespfs.h" 19 | #include "cgi.h" 20 | #include "cgiwifi.h" 21 | #include "cgiflash.h" 22 | #include "stdout.h" 23 | #include "auth.h" 24 | #include "espfs.h" 25 | #include "captdns.h" 26 | #include "webpages-espfs.h" 27 | #include "cgiwebsocket.h" 28 | #include "stack.h" 29 | 30 | //The example can print out the heap use every 3 seconds. You can use this to catch memory leaks. 31 | #define SHOW_HEAP_USE 32 | 33 | //Function that tells the authentication system what users/passwords live on the system. 34 | //This is disabled in the default build; if you want to try it, enable the authBasic line in 35 | //the builtInUrls below. 36 | int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen) { 37 | if (no==0) { 38 | os_strcpy(user, "admin"); 39 | os_strcpy(pass, "s3cr3t"); 40 | return 1; 41 | //Add more users this way. Check against incrementing no for each user added. 42 | // } else if (no==1) { 43 | // os_strcpy(user, "user1"); 44 | // os_strcpy(pass, "something"); 45 | // return 1; 46 | } 47 | return 0; 48 | } 49 | 50 | static ETSTimer websockTimer; 51 | 52 | //Broadcast the uptime in seconds every second over connected websockets 53 | static void ICACHE_FLASH_ATTR websockTimerCb(void *arg) { 54 | static int ctr=0; 55 | char buff[128]; 56 | ctr++; 57 | os_sprintf(buff, "Up for %d minutes %d seconds!\n", ctr/60, ctr%60); 58 | cgiWebsockBroadcast("/websocket/ws.cgi", buff, os_strlen(buff), WEBSOCK_FLAG_NONE); 59 | } 60 | 61 | //On reception of a message, send "You sent: " plus whatever the other side sent 62 | void myWebsocketRecv(Websock *ws, char *data, int len, int flags) { 63 | int i; 64 | char buff[128]; 65 | os_sprintf(buff, "You sent: "); 66 | for (i=0; irecvCb=myWebsocketRecv; 74 | cgiWebsocketSend(ws, "Hi, Websocket!", 14, WEBSOCK_FLAG_NONE); 75 | } 76 | 77 | 78 | #ifdef ESPFS_POS 79 | CgiUploadFlashDef uploadParams={ 80 | .type=CGIFLASH_TYPE_ESPFS, 81 | .fw1Pos=ESPFS_POS, 82 | .fw2Pos=0, 83 | .fwSize=ESPFS_SIZE, 84 | }; 85 | #define INCLUDE_FLASH_FNS 86 | #endif 87 | #ifdef OTA_FLASH_SIZE_K 88 | CgiUploadFlashDef uploadParams={ 89 | .type=CGIFLASH_TYPE_FW, 90 | .fw1Pos=0x1000, 91 | .fw2Pos=((OTA_FLASH_SIZE_K*1024)/2)+0x1000, 92 | .fwSize=((OTA_FLASH_SIZE_K*1024)/2)-0x1000, 93 | }; 94 | #define INCLUDE_FLASH_FNS 95 | #endif 96 | 97 | /* 98 | This is the main url->function dispatching data struct. 99 | In short, it's a struct with various URLs plus their handlers. The handlers can 100 | be 'standard' CGI functions you wrote, or 'special' CGIs requiring an argument. 101 | They can also be auth-functions. An asterisk will match any url starting with 102 | everything before the asterisks; "*" matches everything. The list will be 103 | handled top-down, so make sure to put more specific rules above the more 104 | general ones. Authorization things (like authBasic) act as a 'barrier' and 105 | should be placed above the URLs they protect. 106 | */ 107 | HttpdBuiltInUrl builtInUrls[]={ 108 | {"*", cgiRedirectApClientToHostname, "esp8266.nonet"}, 109 | {"/", cgiRedirect, "/index.tpl"}, 110 | {"/flash.bin", cgiReadFlash, NULL}, 111 | {"/led.tpl", cgiEspFsTemplate, tplLed}, 112 | {"/index.tpl", cgiEspFsTemplate, tplCounter}, 113 | {"/led.cgi", cgiLed, NULL}, 114 | {"/flash/download", cgiReadFlash, NULL}, 115 | #ifdef INCLUDE_FLASH_FNS 116 | {"/flash/next", cgiGetFirmwareNext, &uploadParams}, 117 | {"/flash/upload", cgiUploadFirmware, &uploadParams}, 118 | #endif 119 | {"/flash/reboot", cgiRebootFirmware, NULL}, 120 | 121 | //Routines to make the /wifi URL and everything beneath it work. 122 | 123 | //Enable the line below to protect the WiFi configuration with an username/password combo. 124 | // {"/wifi/*", authBasic, myPassFn}, 125 | 126 | {"/wifi", cgiRedirect, "/wifi/wifi.tpl"}, 127 | {"/wifi/", cgiRedirect, "/wifi/wifi.tpl"}, 128 | {"/wifi/wifiscan.cgi", cgiWiFiScan, NULL}, 129 | {"/wifi/wifi.tpl", cgiEspFsTemplate, tplWlan}, 130 | {"/wifi/connect.cgi", cgiWiFiConnect, NULL}, 131 | {"/wifi/connstatus.cgi", cgiWiFiConnStatus, NULL}, 132 | {"/wifi/setmode.cgi", cgiWiFiSetMode, NULL}, 133 | 134 | {"/websocket/ws.cgi", cgiWebsocket, myWebsocketConnect}, 135 | 136 | {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem 137 | {NULL, NULL, NULL} 138 | }; 139 | 140 | 141 | #ifdef SHOW_HEAP_USE 142 | static ETSTimer prHeapTimer; 143 | 144 | static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) { 145 | os_printf("Heap: %ld\n", (unsigned long)system_get_free_heap_size()); 146 | } 147 | #endif 148 | 149 | 150 | 151 | //Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. 152 | void user_init(void) { 153 | wifi_station_set_auto_connect(FALSE); 154 | stdoutInit(); 155 | CFG_Load(); 156 | ioInit(); 157 | 158 | MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n"); 159 | stack_init(); 160 | 161 | /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */ 162 | captdnsInit(); 163 | 164 | // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position 165 | // where image is written in flash that is defined in Makefile. 166 | #ifdef ESPFS_POS 167 | espFsInit((void*)(0x40200000 + ESPFS_POS)); 168 | #else 169 | espFsInit((void*)(webpages_espfs_start)); 170 | #endif 171 | httpdInit(builtInUrls, 80); 172 | #ifdef SHOW_HEAP_USE 173 | os_timer_disarm(&prHeapTimer); 174 | os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); 175 | os_timer_arm(&prHeapTimer, 3000, 1); 176 | #endif 177 | os_timer_disarm(&websockTimer); 178 | os_timer_setfn(&websockTimer, websockTimerCb, NULL); 179 | os_timer_arm(&websockTimer, 1000, 1); 180 | 181 | os_printf("\nReady\n"); 182 | } 183 | 184 | void user_rf_pre_init() { 185 | //Not needed, but some SDK versions want this defined. 186 | } 187 | -------------------------------------------------------------------------------- /libesphttpd/util/cgiflash.c: -------------------------------------------------------------------------------- 1 | /* 2 | Some flash handling cgi routines. Used for reading the existing flash and updating the ESPFS image. 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 | 15 | #include 16 | #include "cgiflash.h" 17 | #include "espfs.h" 18 | #include 19 | #include "cgiflash.h" 20 | #include "espfs.h" 21 | 22 | #include 23 | #include "cgiflash.h" 24 | #include "espfs.h" 25 | #include "esp_enc_api.h" 26 | 27 | #define ESPFS_SIZE 0 28 | #define FIRMWARE_SIZE 0 29 | 30 | 31 | // Check that the header of the firmware blob looks like actual firmware... 32 | static char* ICACHE_FLASH_ATTR checkBinHeader(void *buf) { 33 | uint8_t *cd = (uint8_t *)buf; 34 | if (cd[0] != 0xEA) return "IROM magic missing"; 35 | if (cd[1] != 4 || cd[2] > 3 || cd[3] > 0x40) return "bad flash header"; 36 | if (((uint16_t *)buf)[3] != 0x4010) return "Invalid entry addr"; 37 | if (((uint32_t *)buf)[2] != 0) return "Invalid start offset"; 38 | return NULL; 39 | } 40 | 41 | static char* ICACHE_FLASH_ATTR checkEspfsHeader(void *buf) { 42 | if (os_memcmp(buf, "ESfs", 4)!=0) return "Bad ESPfs header"; 43 | return NULL; 44 | } 45 | 46 | 47 | // Cgi to query which firmware needs to be uploaded next 48 | int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) { 49 | if (connData->conn==NULL) { 50 | //Connection aborted. Clean up. 51 | return HTTPD_CGI_DONE; 52 | } 53 | uint8 id = system_upgrade_userbin_check(); 54 | httpdStartResponse(connData, 200); 55 | httpdHeader(connData, "Content-Type", "text/plain"); 56 | httpdHeader(connData, "Content-Length", "9"); 57 | httpdEndHeaders(connData); 58 | char *next = id == 1 ? "user1.bin" : "user2.bin"; 59 | httpdSend(connData, next, -1); 60 | os_printf("Next firmware: %s (got %d)\n", next, id); 61 | return HTTPD_CGI_DONE; 62 | } 63 | 64 | 65 | //Cgi that reads the SPI flash. Assumes 512KByte flash. 66 | //ToDo: Figure out real flash size somehow? 67 | int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) { 68 | int *pos=(int *)&connData->cgiData; 69 | if (connData->conn==NULL) { 70 | //Connection aborted. Clean up. 71 | return HTTPD_CGI_DONE; 72 | } 73 | 74 | if (*pos==0) { 75 | os_printf("Start flash download.\n"); 76 | httpdStartResponse(connData, 200); 77 | httpdHeader(connData, "Content-Type", "application/bin"); 78 | httpdEndHeaders(connData); 79 | *pos=0x40200000; 80 | return HTTPD_CGI_MORE; 81 | } 82 | //Send 1K of flash per call. We will get called again if we haven't sent 512K yet. 83 | //espconn_sent(connData->conn, (uint8 *)(*pos), 1024); 84 | esp_enc_api_sendData(connData->conn, (uint8 *)(*pos), 1024); 85 | *pos+=1024; 86 | if (*pos>=0x40200000+(512*1024)) return HTTPD_CGI_DONE; else return HTTPD_CGI_MORE; 87 | } 88 | 89 | 90 | //Cgi that allows the firmware to be replaced via http POST 91 | int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) { 92 | CgiUploadFlashDef *def=(CgiUploadFlashDef*)connData->cgiArg; 93 | uint32_t address; 94 | if (connData->conn==NULL) { 95 | //Connection aborted. Clean up. 96 | return HTTPD_CGI_DONE; 97 | } 98 | 99 | int offset = connData->post->received - connData->post->buffLen; 100 | if (offset == 0) { 101 | connData->cgiPrivData = NULL; 102 | } else if (connData->cgiPrivData != NULL) { 103 | // we have an error condition, do nothing 104 | return HTTPD_CGI_DONE; 105 | } 106 | 107 | // assume no error yet... 108 | char *err = NULL; 109 | int code = 400; 110 | 111 | if (connData->post==NULL) err="No POST request."; 112 | if (def==NULL) err="Flash def = NULL ?"; 113 | 114 | // check overall size 115 | os_printf("Max img sz 0x%X, post len 0x%X\n", def->fwSize, connData->post->len); 116 | if (err==NULL && connData->post->len > def->fwSize) err = "Firmware image too large"; 117 | 118 | // check that data starts with an appropriate header 119 | if (err == NULL && offset == 0 && def->type==CGIFLASH_TYPE_FW) err = checkBinHeader(connData->post->buff); 120 | if (err == NULL && offset == 0 && def->type==CGIFLASH_TYPE_ESPFS) err = checkEspfsHeader(connData->post->buff); 121 | 122 | // make sure we're buffering in 1024 byte chunks 123 | if (err == NULL && offset % 1024 != 0) { 124 | err = "Buffering problem"; 125 | code = 500; 126 | } 127 | 128 | // return an error if there is one 129 | if (err != NULL) { 130 | os_printf("Error %d: %s\n", code, err); 131 | httpdStartResponse(connData, code); 132 | httpdHeader(connData, "Content-Type", "text/plain"); 133 | httpdEndHeaders(connData); 134 | httpdSend(connData, "Firmware image error:\r\n", -1); 135 | httpdSend(connData, err, -1); 136 | httpdSend(connData, "\r\n", -1); 137 | connData->cgiPrivData = (void *)1; 138 | return HTTPD_CGI_DONE; 139 | } 140 | 141 | // let's see which partition we need to flash and what flash address that puts us at 142 | int id=system_upgrade_userbin_check(); 143 | if (id==1) address=def->fw1Pos; else address=def->fw2Pos; 144 | address += offset; 145 | // erase next flash block if necessary 146 | if (address % SPI_FLASH_SEC_SIZE == 0){ 147 | // We need to erase this block 148 | os_printf("Erasing flash at 0x%05x (id=%d)\n", (unsigned int)address, 2-id); 149 | spi_flash_erase_sector(address/SPI_FLASH_SEC_SIZE); 150 | } 151 | 152 | // Write the data 153 | os_printf("Writing %d bytes at 0x%05x (%d of %d)\n", connData->post->buffSize, (unsigned int)address, 154 | connData->post->received, connData->post->len); 155 | spi_flash_write(address, (uint32 *)connData->post->buff, connData->post->buffLen); 156 | 157 | if (connData->post->received == connData->post->len){ 158 | httpdStartResponse(connData, 200); 159 | httpdEndHeaders(connData); 160 | return HTTPD_CGI_DONE; 161 | } else { 162 | return HTTPD_CGI_MORE; 163 | } 164 | } 165 | 166 | //static ETSTimer flash_reboot_timer; 167 | 168 | // Handle request to reboot into the new firmware 169 | int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { 170 | if (connData->conn==NULL) { 171 | //Connection aborted. Clean up. 172 | return HTTPD_CGI_DONE; 173 | } 174 | 175 | // TODO: sanity-check that the 'next' partition actually contains something that looks like 176 | // valid firmware 177 | 178 | // This should probably be forked into a separate task that waits a second to let the 179 | // current HTTP request finish... 180 | system_upgrade_flag_set(UPGRADE_FLAG_FINISH); 181 | system_upgrade_reboot(); 182 | httpdStartResponse(connData, 200); 183 | httpdEndHeaders(connData); 184 | return HTTPD_CGI_DONE; 185 | } 186 | 187 | -------------------------------------------------------------------------------- /libesphttpd/espfs/mkespfsimage/mman-win32/test.c: -------------------------------------------------------------------------------- 1 | 2 | #include "mman.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifndef NULL 9 | #define NULL (void*)0 10 | #endif 11 | 12 | const char* map_file_name = "map_file.dat"; 13 | 14 | int test_anon_map_readwrite() 15 | { 16 | void* map = mmap(NULL, 1024, PROT_READ | PROT_WRITE, 17 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 18 | if (map == MAP_FAILED) 19 | { 20 | printf("mmap (MAP_ANONYMOUS, PROT_READ | PROT_WRITE) returned unexpected error: %d\n", errno); 21 | return -1; 22 | } 23 | 24 | *((unsigned char*)map) = 1; 25 | 26 | int result = munmap(map, 1024); 27 | 28 | if (result != 0) 29 | printf("munmap (MAP_ANONYMOUS, PROT_READ | PROT_WRITE) returned unexpected error: %d\n", errno); 30 | 31 | return result; 32 | } 33 | 34 | int test_anon_map_readonly() 35 | { 36 | void* map = mmap(NULL, 1024, PROT_READ, 37 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 38 | if (map == MAP_FAILED) 39 | { 40 | printf("mmap (MAP_ANONYMOUS, PROT_READ) returned unexpected error: %d\n", errno); 41 | return -1; 42 | } 43 | 44 | *((unsigned char*)map) = 1; 45 | 46 | int result = munmap(map, 1024); 47 | 48 | if (result != 0) 49 | printf("munmap (MAP_ANONYMOUS, PROT_READ) returned unexpected error: %d\n", errno); 50 | 51 | return result; 52 | } 53 | 54 | int test_anon_map_writeonly() 55 | { 56 | void* map = mmap(NULL, 1024, PROT_WRITE, 57 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 58 | if (map == MAP_FAILED) 59 | { 60 | printf("mmap (MAP_ANONYMOUS, PROT_WRITE) returned unexpected error: %d\n", errno); 61 | return -1; 62 | } 63 | 64 | *((unsigned char*)map) = 1; 65 | 66 | int result = munmap(map, 1024); 67 | 68 | if (result != 0) 69 | printf("munmap (MAP_ANONYMOUS, PROT_WRITE) returned unexpected error: %d\n", errno); 70 | 71 | return result; 72 | } 73 | 74 | int test_anon_map_readonly_nowrite() 75 | { 76 | void* map = mmap(NULL, 1024, PROT_READ, 77 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 78 | if (map == MAP_FAILED) 79 | { 80 | printf("mmap (MAP_ANONYMOUS, PROT_READ) returned unexpected error: %d\n", errno); 81 | return -1; 82 | } 83 | 84 | if (*((unsigned char*)map) != 0) 85 | printf("test_anon_map_readonly_nowrite (MAP_ANONYMOUS, PROT_READ) returned unexpected value: %d\n", 86 | (int)*((unsigned char*)map)); 87 | 88 | int result = munmap(map, 1024); 89 | 90 | if (result != 0) 91 | printf("munmap (MAP_ANONYMOUS, PROT_READ) returned unexpected error: %d\n", errno); 92 | 93 | return result; 94 | } 95 | 96 | int test_file_map_readwrite() 97 | { 98 | mode_t mode = S_IRUSR | S_IWUSR; 99 | int o = open(map_file_name, O_TRUNC | O_BINARY | O_RDWR | O_CREAT, mode); 100 | 101 | void* map = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE, o, 0); 102 | if (map == MAP_FAILED) 103 | { 104 | printf("mmap returned unexpected error: %d\n", errno); 105 | return -1; 106 | } 107 | 108 | *((unsigned char*)map) = 1; 109 | 110 | int result = munmap(map, 1024); 111 | 112 | if (result != 0) 113 | printf("munmap returned unexpected error: %d\n", errno); 114 | 115 | close(o); 116 | 117 | /*TODO: get file info and content and compare it with the sources conditions */ 118 | unlink(map_file_name); 119 | 120 | return result; 121 | } 122 | 123 | int test_file_map_mlock_munlock() 124 | { 125 | const size_t map_size = 1024; 126 | 127 | int result = 0; 128 | mode_t mode = S_IRUSR | S_IWUSR; 129 | int o = open(map_file_name, O_TRUNC | O_BINARY | O_RDWR | O_CREAT, mode); 130 | if (o == -1) 131 | { 132 | printf("unable to create file %s: %d\n", map_file_name, errno); 133 | return -1; 134 | } 135 | 136 | void* map = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, o, 0); 137 | if (map == MAP_FAILED) 138 | { 139 | printf("mmap returned unexpected error: %d\n", errno); 140 | result = -1; 141 | goto done_close; 142 | } 143 | 144 | if (mlock(map, map_size) != 0) 145 | { 146 | printf("mlock returned unexpected error: %d\n", errno); 147 | result = -1; 148 | goto done_munmap; 149 | } 150 | 151 | *((unsigned char*)map) = 1; 152 | 153 | if (munlock(map, map_size) != 0) 154 | { 155 | printf("munlock returned unexpected error: %d\n", errno); 156 | result = -1; 157 | } 158 | 159 | done_munmap: 160 | result = munmap(map, map_size); 161 | 162 | if (result != 0) 163 | printf("munmap returned unexpected error: %d\n", errno); 164 | 165 | done_close: 166 | close(o); 167 | 168 | unlink(map_file_name); 169 | done: 170 | return result; 171 | } 172 | 173 | int test_file_map_msync() 174 | { 175 | const size_t map_size = 1024; 176 | 177 | int result = 0; 178 | mode_t mode = S_IRUSR | S_IWUSR; 179 | int o = open(map_file_name, O_TRUNC | O_BINARY | O_RDWR | O_CREAT, mode); 180 | if (o == -1) 181 | { 182 | printf("unable to create file %s: %d\n", map_file_name, errno); 183 | return -1; 184 | } 185 | 186 | void* map = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, o, 0); 187 | if (map == MAP_FAILED) 188 | { 189 | printf("mmap returned unexpected error: %d\n", errno); 190 | result = -1; 191 | goto done_close; 192 | } 193 | 194 | *((unsigned char*)map) = 1; 195 | 196 | if (msync(map, map_size, MS_SYNC) != 0) 197 | { 198 | printf("msync returned unexpected error: %d\n", errno); 199 | result = -1; 200 | } 201 | 202 | result = munmap(map, map_size); 203 | 204 | if (result != 0) 205 | printf("munmap returned unexpected error: %d\n", errno); 206 | 207 | done_close: 208 | close(o); 209 | 210 | unlink(map_file_name); 211 | done: 212 | return result; 213 | } 214 | 215 | #define EXEC_TEST(name) \ 216 | if (name() != 0) { result = -1; printf( #name ": fail\n"); } \ 217 | else { printf(#name ": pass\n"); } 218 | 219 | int main() 220 | { 221 | int result = 0; 222 | 223 | EXEC_TEST(test_anon_map_readwrite); 224 | //NOTE: this test must cause an access violation exception 225 | //EXEC_TEST(test_anon_map_readonly); 226 | EXEC_TEST(test_anon_map_readonly_nowrite); 227 | EXEC_TEST(test_anon_map_writeonly); 228 | 229 | EXEC_TEST(test_file_map_readwrite); 230 | EXEC_TEST(test_file_map_mlock_munlock); 231 | EXEC_TEST(test_file_map_msync); 232 | //TODO: EXEC_TEST(test_file_map_mprotect); 233 | 234 | return result; 235 | } 236 | -------------------------------------------------------------------------------- /.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | mingw32-make.exe 74 | -f ${ProjDirPath}/Makefile 75 | all 76 | true 77 | true 78 | true 79 | 80 | 81 | mingw32-make.exe 82 | -f ${ProjDirPath}/Makefile 83 | clean 84 | true 85 | true 86 | true 87 | 88 | 89 | mingw32-make.exe 90 | -f ${ProjDirPath}/Makefile 91 | flash 92 | true 93 | true 94 | true 95 | 96 | 97 | mingw32-make.exe 98 | -f ${ProjDirPath}/Makefile 99 | htmlflash 100 | true 101 | true 102 | true 103 | 104 | 105 | mingw32-make.exe 106 | -f ${ProjDirPath}/Makefile 107 | flashinit 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /libesphttpd/util/captdns.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "globals.h" 3 | 4 | /* 5 | * ---------------------------------------------------------------------------- 6 | * "THE BEER-WARE LICENSE" (Revision 42): 7 | * Jeroen Domburg wrote this file. As long as you retain 8 | * this notice you can do whatever you want with this stuff. If we meet some day, 9 | * and you think this stuff is worth it, you can buy me a beer in return. 10 | * ---------------------------------------------------------------------------- 11 | */ 12 | 13 | 14 | /* 15 | This is a 'captive portal' DNS server: it basically replies with a fixed IP (in this case: 16 | the one of the SoftAP interface of this ESP module) for any and all DNS queries. This can 17 | be used to send mobile phones, tablets etc which connect to the ESP in AP mode directly to 18 | the internal webserver. 19 | */ 20 | 21 | 22 | typedef struct __attribute__ ((packed)) { 23 | uint16_t id; 24 | uint8_t flags; 25 | uint8_t rcode; 26 | uint16_t qdcount; 27 | uint16_t ancount; 28 | uint16_t nscount; 29 | uint16_t arcount; 30 | } DnsHeader; 31 | 32 | 33 | typedef struct __attribute__ ((packed)) { 34 | uint8_t len; 35 | uint8_t data; 36 | } DnsLabel; 37 | 38 | 39 | typedef struct __attribute__ ((packed)) { 40 | //before: label 41 | uint16_t type; 42 | uint16_t class; 43 | } DnsQuestionFooter; 44 | 45 | 46 | typedef struct __attribute__ ((packed)) { 47 | //before: label 48 | uint16_t type; 49 | uint16_t class; 50 | uint32_t ttl; 51 | uint16_t rdlength; 52 | //after: rdata 53 | } DnsResourceFooter; 54 | 55 | typedef struct __attribute__ ((packed)) { 56 | uint16_t prio; 57 | uint16_t weight; 58 | } DnsUriHdr; 59 | 60 | 61 | #define FLAG_QR (1<<7) 62 | #define FLAG_AA (1<<2) 63 | #define FLAG_TC (1<<1) 64 | #define FLAG_RD (1<<0) 65 | 66 | #define QTYPE_A 1 67 | #define QTYPE_NS 2 68 | #define QTYPE_CNAME 5 69 | #define QTYPE_SOA 6 70 | #define QTYPE_WKS 11 71 | #define QTYPE_PTR 12 72 | #define QTYPE_HINFO 13 73 | #define QTYPE_MINFO 14 74 | #define QTYPE_MX 15 75 | #define QTYPE_TXT 16 76 | #define QTYPE_URI 256 77 | 78 | #define QCLASS_IN 1 79 | #define QCLASS_ANY 255 80 | #define QCLASS_URI 256 81 | 82 | 83 | //Function to put unaligned 16-bit network values 84 | static void ICACHE_FLASH_ATTR setn16(void *pp, int16_t n) { 85 | char *p=pp; 86 | *p++=(n>>8); 87 | *p++=(n&0xff); 88 | } 89 | 90 | //Function to put unaligned 32-bit network values 91 | static void ICACHE_FLASH_ATTR setn32(void *pp, int32_t n) { 92 | char *p=pp; 93 | *p++=(n>>24)&0xff; 94 | *p++=(n>>16)&0xff; 95 | *p++=(n>>8)&0xff; 96 | *p++=(n&0xff); 97 | } 98 | 99 | static uint16_t ICACHE_FLASH_ATTR ntohs(uint16_t *in) { 100 | char *p=(char*)in; 101 | return ((p[0]<<8)&0xff00)|(p[1]&0xff); 102 | } 103 | 104 | 105 | //Parses a label into a C-string containing a dotted 106 | //Returns pointer to start of next fields in packet 107 | static char* ICACHE_FLASH_ATTR labelToStr(char *packet, char *labelPtr, int packetSz, char *res, int resMaxLen) { 108 | int i, j, k; 109 | char *endPtr=NULL; 110 | i=0; 111 | do { 112 | if ((*labelPtr&0xC0)==0) { 113 | j=*labelPtr++; //skip past length 114 | //Add separator period if there already is data in res 115 | if (ipacketSz) return NULL; 119 | if (ipacketSz) return NULL; 127 | labelPtr=&packet[offset]; 128 | } 129 | //check for out-of-bound-ness 130 | if ((labelPtr-packet)>packetSz) return NULL; 131 | } while (*labelPtr!=0); 132 | res[i]=0; //zero-terminate 133 | if (endPtr==NULL) endPtr=labelPtr+1; 134 | return endPtr; 135 | } 136 | 137 | 138 | //Converts a dotted hostname to the weird label form dns uses. 139 | static char ICACHE_FLASH_ATTR *strToLabel(char *str, char *label, int maxLen) { 140 | char *len=label; //ptr to len byte 141 | char *p=label+1; //ptr to next label byte to be written 142 | while (1) { 143 | if (*str=='.' || *str==0) { 144 | *len=((p-len)-1); //write len of label bit 145 | len=p; //pos of len for next part 146 | p++; //data ptr is one past len 147 | if (*str==0) break; //done 148 | str++; 149 | } else { 150 | *p++=*str++; //copy byte 151 | // if ((p-label)>maxLen) return NULL; //check out of bounds 152 | } 153 | } 154 | *len=0; 155 | return p; //ptr to first free byte in resp 156 | } 157 | 158 | 159 | //Receive a DNS packet and maybe send a response back 160 | static void ICACHE_FLASH_ATTR captdnsRecv(void* arg, char *pusrdata, unsigned short length) { 161 | struct espconn *conn=(struct espconn *)arg; 162 | char buff[512]; 163 | char reply[512]; 164 | int i; 165 | char *rend=&reply[length]; 166 | char *p=pusrdata; 167 | DnsHeader *hdr=(DnsHeader*)p; 168 | DnsHeader *rhdr=(DnsHeader*)&reply[0]; 169 | p+=sizeof(DnsHeader); 170 | // os_printf("DNS packet: id 0x%X flags 0x%X rcode 0x%X qcnt %d ancnt %d nscount %d arcount %d len %d\n", 171 | // ntohs(&hdr->id), hdr->flags, hdr->rcode, ntohs(&hdr->qdcount), ntohs(&hdr->ancount), ntohs(&hdr->nscount), ntohs(&hdr->arcount), length); 172 | //Some sanity checks: 173 | if (length>512) return; //Packet is longer than DNS implementation allows 174 | if (lengthancount || hdr->nscount || hdr->arcount) return; //this is a reply, don't know what to do with it 176 | if (hdr->flags&FLAG_TC) return; //truncated, can't use this 177 | //Reply is basically the request plus the needed data 178 | os_memcpy(reply, pusrdata, length); 179 | rhdr->flags|=FLAG_QR; 180 | for (i=0; iqdcount); i++) { 181 | //Grab the labels in the q string 182 | p=labelToStr(pusrdata, p, length, buff, sizeof(buff)); 183 | if (p==NULL) return; 184 | DnsQuestionFooter *qf=(DnsQuestionFooter*)p; 185 | p+=sizeof(DnsQuestionFooter); 186 | CAPTDNS_DEBUG("DNS: Q (type 0x%X class 0x%X) for %s\n", ntohs(&qf->type), ntohs(&qf->class), buff); 187 | if (ntohs(&qf->type)==QTYPE_A) { 188 | //They want to know the IPv4 address of something. 189 | //Build the response. 190 | rend=strToLabel(buff, rend, sizeof(reply)-(rend-reply)); //Add the label 191 | if (rend==NULL) return; 192 | DnsResourceFooter *rf=(DnsResourceFooter *)rend; 193 | rend+=sizeof(DnsResourceFooter); 194 | setn16(&rf->type, QTYPE_A); 195 | setn16(&rf->class, QCLASS_IN); 196 | setn32(&rf->ttl, 0); 197 | setn16(&rf->rdlength, 4); //IPv4 addr is 4 bytes; 198 | //Grab the current IP of the softap interface 199 | struct ip_info info; 200 | wifi_get_ip_info(SOFTAP_IF, &info); 201 | *rend++=ip4_addr1(&info.ip); 202 | *rend++=ip4_addr2(&info.ip); 203 | *rend++=ip4_addr3(&info.ip); 204 | *rend++=ip4_addr4(&info.ip); 205 | setn16(&rhdr->ancount, ntohs(&rhdr->ancount)+1); 206 | // os_printf("Added A rec to resp. Resp len is %d\n", (rend-reply)); 207 | } else if (ntohs(&qf->type)==QTYPE_NS) { 208 | //Give ns server. Basically can be whatever we want because it'll get resolved to our IP later anyway. 209 | rend=strToLabel(buff, rend, sizeof(reply)-(rend-reply)); //Add the label 210 | DnsResourceFooter *rf=(DnsResourceFooter *)rend; 211 | rend+=sizeof(DnsResourceFooter); 212 | setn16(&rf->type, QTYPE_NS); 213 | setn16(&rf->class, QCLASS_IN); 214 | setn16(&rf->ttl, 0); 215 | setn16(&rf->rdlength, 4); 216 | *rend++=2; 217 | *rend++='n'; 218 | *rend++='s'; 219 | *rend++=0; 220 | setn16(&rhdr->ancount, ntohs(&rhdr->ancount)+1); 221 | // os_printf("Added NS rec to resp. Resp len is %d\n", (rend-reply)); 222 | } else if (ntohs(&qf->type)==QTYPE_URI) { 223 | //Give uri to us 224 | rend=strToLabel(buff, rend, sizeof(reply)-(rend-reply)); //Add the label 225 | DnsResourceFooter *rf=(DnsResourceFooter *)rend; 226 | rend+=sizeof(DnsResourceFooter); 227 | DnsUriHdr *uh=(DnsUriHdr *)rend; 228 | rend+=sizeof(DnsUriHdr); 229 | setn16(&rf->type, QTYPE_URI); 230 | setn16(&rf->class, QCLASS_URI); 231 | setn16(&rf->ttl, 0); 232 | setn16(&rf->rdlength, 4+16); 233 | setn16(&uh->prio, 10); 234 | setn16(&uh->weight, 1); 235 | memcpy(rend, "http://esp.nonet", 16); 236 | rend+=16; 237 | setn16(&rhdr->ancount, ntohs(&rhdr->ancount)+1); 238 | // os_printf("Added NS rec to resp. Resp len is %d\n", (rend-reply)); 239 | } 240 | } 241 | //Send the response 242 | espconn_sent(conn, (uint8*)reply, rend-reply); 243 | } 244 | 245 | void ICACHE_FLASH_ATTR captdnsInit(void) { 246 | static struct espconn conn; 247 | static esp_udp udpconn; 248 | conn.type=ESPCONN_UDP; 249 | conn.proto.udp=&udpconn; 250 | conn.proto.udp->local_port = 53; 251 | espconn_regist_recvcb(&conn, captdnsRecv); 252 | espconn_create(&conn); 253 | } 254 | -------------------------------------------------------------------------------- /libesphttpd/espfs/espfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | This is a simple read-only implementation of a file system. It uses a block of data coming from the 3 | mkespfsimg tool, and can use that block to do abstracted operations on the files that are in there. 4 | It's written for use with httpd, but doesn't need to be used as such. 5 | */ 6 | 7 | /* 8 | * ---------------------------------------------------------------------------- 9 | * "THE BEER-WARE LICENSE" (Revision 42): 10 | * Jeroen Domburg wrote this file. As long as you retain 11 | * this notice you can do whatever you want with this stuff. If we meet some day, 12 | * and you think this stuff is worth it, you can buy me a beer in return. 13 | * ---------------------------------------------------------------------------- 14 | */ 15 | 16 | 17 | //These routines can also be tested by comping them in with the espfstest tool. This 18 | //simplifies debugging, but needs some slightly different headers. The #ifdef takes 19 | //care of that. 20 | 21 | #ifdef __ets__ 22 | //esp build 23 | #include 24 | #else 25 | //Test build 26 | #include 27 | #include 28 | #include 29 | #include 30 | #define os_malloc malloc 31 | #define os_free free 32 | #define os_memcpy memcpy 33 | #define os_strncmp strncmp 34 | #define os_strcmp strcmp 35 | #define os_strcpy strcpy 36 | #define os_printf printf 37 | #define ICACHE_FLASH_ATTR 38 | #endif 39 | 40 | #include "espfsformat.h" 41 | #include "espfs.h" 42 | 43 | #ifdef ESPFS_HEATSHRINK 44 | #include "heatshrink_config_custom.h" 45 | #include "heatshrink_decoder.h" 46 | #endif 47 | 48 | static char* espFsData = NULL; 49 | 50 | 51 | struct EspFsFile { 52 | EspFsHeader *header; 53 | char decompressor; 54 | int32_t posDecomp; 55 | char *posStart; 56 | char *posComp; 57 | void *decompData; 58 | }; 59 | 60 | /* 61 | Available locations, at least in my flash, with boundaries partially guessed. This 62 | is using 0.9.1/0.9.2 SDK on a not-too-new module. 63 | 0x00000 (0x10000): Code/data (RAM data?) 64 | 0x10000 (0x02000): Gets erased by something? 65 | 0x12000 (0x2E000): Free (filled with zeroes) (parts used by ESPCloud and maybe SSL) 66 | 0x40000 (0x20000): Code/data (ROM data?) 67 | 0x60000 (0x1C000): Free 68 | 0x7c000 (0x04000): Param store 69 | 0x80000 - end of flash 70 | 71 | Accessing the flash through the mem emulation at 0x40200000 is a bit hairy: All accesses 72 | *must* be aligned 32-bit accesses. Reading a short, byte or unaligned word will result in 73 | a memory exception, crashing the program. 74 | */ 75 | 76 | EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) { 77 | if((uint32_t)flashAddress > 0x40200000) { 78 | flashAddress = (void*)((uint32_t)flashAddress-0x40200000); 79 | } 80 | 81 | // base address must be aligned to 4 bytes 82 | if (((int)flashAddress & 3) != 0) { 83 | return ESPFS_INIT_RESULT_BAD_ALIGN; 84 | } 85 | 86 | // check if there is valid header at address 87 | EspFsHeader testHeader; 88 | spi_flash_read((uint32)flashAddress, (uint32*)&testHeader, sizeof(EspFsHeader)); 89 | if (testHeader.magic != ESPFS_MAGIC) { 90 | return ESPFS_INIT_RESULT_NO_IMAGE; 91 | } 92 | 93 | espFsData = (char *)flashAddress; 94 | return ESPFS_INIT_RESULT_OK; 95 | } 96 | 97 | //Copies len bytes over from dst to src, but does it using *only* 98 | //aligned 32-bit reads. Yes, it's no too optimized but it's short and sweet and it works. 99 | 100 | //ToDo: perhaps os_memcpy also does unaligned accesses? 101 | #ifdef __ets__ 102 | void ICACHE_FLASH_ATTR readFlashUnaligned(char *dst, char *src, int len) { 103 | uint8_t src_offset = ((uint32_t)src) & 3; 104 | uint32_t src_address = ((uint32_t)src) - src_offset; 105 | 106 | uint32_t tmp_buf[len/4 + 2]; 107 | spi_flash_read((uint32)src_address, (uint32*)tmp_buf, len+src_offset); 108 | os_memcpy(dst, ((uint8_t*)tmp_buf)+src_offset, len); 109 | } 110 | #else 111 | #define readFlashUnaligned memcpy 112 | #endif 113 | 114 | // Returns flags of opened file. 115 | int ICACHE_FLASH_ATTR espFsFlags(EspFsFile *fh) { 116 | if (fh == NULL) { 117 | os_printf("File handle not ready\n"); 118 | return -1; 119 | } 120 | 121 | int8_t flags; 122 | readFlashUnaligned((char*)&flags, (char*)&fh->header->flags, 1); 123 | return (int)flags; 124 | } 125 | 126 | //Open a file and return a pointer to the file desc struct. 127 | EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { 128 | if (espFsData == NULL) { 129 | os_printf("Call espFsInit first!\n"); 130 | return NULL; 131 | } 132 | char *p=espFsData; 133 | char *hpos; 134 | char namebuf[256]; 135 | EspFsHeader h; 136 | EspFsFile *r; 137 | //Strip initial slashes 138 | while(fileName[0]=='/') fileName++; 139 | //Go find that file! 140 | while(1) { 141 | hpos=p; 142 | //Grab the next file header. 143 | spi_flash_read((uint32)p, (uint32*)&h, sizeof(EspFsHeader)); 144 | 145 | if (h.magic!=ESPFS_MAGIC) { 146 | os_printf("Magic mismatch. EspFS image broken.\n"); 147 | return NULL; 148 | } 149 | if (h.flags&FLAG_LASTFILE) { 150 | os_printf("End of image.\n"); 151 | return NULL; 152 | } 153 | //Grab the name of the file. 154 | p+=sizeof(EspFsHeader); 155 | spi_flash_read((uint32)p, (uint32*)&namebuf, sizeof(namebuf)); 156 | // os_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n", 157 | // namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags); 158 | if (os_strcmp(namebuf, fileName)==0) { 159 | //Yay, this is the file we need! 160 | p+=h.nameLen; //Skip to content. 161 | r=(EspFsFile *)os_malloc(sizeof(EspFsFile)); //Alloc file desc mem 162 | // os_printf("Alloc %p\n", r); 163 | if (r==NULL) return NULL; 164 | r->header=(EspFsHeader *)hpos; 165 | r->decompressor=h.compression; 166 | r->posComp=p; 167 | r->posStart=p; 168 | r->posDecomp=0; 169 | if (h.compression==COMPRESS_NONE) { 170 | r->decompData=NULL; 171 | #ifdef ESPFS_HEATSHRINK 172 | } else if (h.compression==COMPRESS_HEATSHRINK) { 173 | //File is compressed with Heatshrink. 174 | char parm; 175 | heatshrink_decoder *dec; 176 | //Decoder params are stored in 1st byte. 177 | readFlashUnaligned(&parm, r->posComp, 1); 178 | r->posComp++; 179 | os_printf("Heatshrink compressed file; decode parms = %x\n", parm); 180 | dec=heatshrink_decoder_alloc(16, (parm>>4)&0xf, parm&0xf); 181 | r->decompData=dec; 182 | #endif 183 | } else { 184 | os_printf("Invalid compression: %d\n", h.compression); 185 | return NULL; 186 | } 187 | return r; 188 | } 189 | //We don't need this file. Skip name and file 190 | p+=h.nameLen+h.fileLenComp; 191 | if ((int)p&3) p+=4-((int)p&3); //align to next 32bit val 192 | } 193 | } 194 | 195 | //Read len bytes from the given file into buff. Returns the actual amount of bytes read. 196 | int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) { 197 | int flen, fdlen; 198 | if (fh==NULL) return 0; 199 | 200 | readFlashUnaligned((char*)&flen, (char*)&fh->header->fileLenComp, 4); 201 | //Cache file length. 202 | //Do stuff depending on the way the file is compressed. 203 | if (fh->decompressor==COMPRESS_NONE) { 204 | int toRead; 205 | toRead=flen-(fh->posComp-fh->posStart); 206 | if (len>toRead) len=toRead; 207 | // os_printf("Reading %d bytes from %x\n", len, (unsigned int)fh->posComp); 208 | readFlashUnaligned(buff, fh->posComp, len); 209 | fh->posDecomp+=len; 210 | fh->posComp+=len; 211 | // os_printf("Done reading %d bytes, pos=%x\n", len, fh->posComp); 212 | return len; 213 | #ifdef ESPFS_HEATSHRINK 214 | } else if (fh->decompressor==COMPRESS_HEATSHRINK) { 215 | readFlashUnaligned((char*)&fdlen, (char*)&fh->header->fileLenDecomp, 4); 216 | int decoded=0; 217 | size_t elen, rlen; 218 | char ebuff[16]; 219 | heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData; 220 | // os_printf("Alloc %p\n", dec); 221 | if (fh->posDecomp == fdlen) { 222 | return 0; 223 | } 224 | 225 | // We must ensure that whole file is decompressed and written to output buffer. 226 | // This means even when there is no input data (elen==0) try to poll decoder until 227 | // posDecomp equals decompressed file length 228 | 229 | while(decodedposComp - fh->posStart); 233 | if (elen>0) { 234 | readFlashUnaligned(ebuff, fh->posComp, 16); 235 | heatshrink_decoder_sink(dec, (uint8_t *)ebuff, (elen>16)?16:elen, &rlen); 236 | fh->posComp+=rlen; 237 | } 238 | //Grab decompressed data and put into buff 239 | heatshrink_decoder_poll(dec, (uint8_t *)buff, len-decoded, &rlen); 240 | fh->posDecomp+=rlen; 241 | buff+=rlen; 242 | decoded+=rlen; 243 | 244 | // os_printf("Elen %d rlen %d d %d pd %ld fdl %d\n",elen,rlen,decoded, fh->posDecomp, fdlen); 245 | 246 | if (elen == 0) { 247 | if (fh->posDecomp == fdlen) { 248 | // os_printf("Decoder finish\n"); 249 | heatshrink_decoder_finish(dec); 250 | } 251 | return decoded; 252 | } 253 | } 254 | return len; 255 | #endif 256 | } 257 | return 0; 258 | } 259 | 260 | //Close the file. 261 | void ICACHE_FLASH_ATTR espFsClose(EspFsFile *fh) { 262 | if (fh==NULL) return; 263 | #ifdef ESPFS_HEATSHRINK 264 | if (fh->decompressor==COMPRESS_HEATSHRINK) { 265 | heatshrink_decoder *dec=(heatshrink_decoder *)fh->decompData; 266 | heatshrink_decoder_free(dec); 267 | // os_printf("Freed %p\n", dec); 268 | } 269 | #endif 270 | // os_printf("Freed %p\n", fh); 271 | os_free(fh); 272 | } 273 | 274 | 275 | 276 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #Position and maximum length of espfs in flash memory. This can be undefined. In this case 2 | #the webpages will be linked in into the executable file. If this is defined, please do a 3 | #'make htmlflash' to flash the espfs into the ESPs memory. 4 | ESPFS_POS = 0x12000 5 | ESPFS_SIZE = 0x2E000 6 | 7 | # Output directors to store intermediate compiled files 8 | # relative to the project directory 9 | BUILD_BASE = build 10 | FW_BASE = firmware 11 | 12 | # Base directory for the compiler. Needs a / at the end; if not set it'll use the tools that are in 13 | # the PATH. 14 | XTENSA_TOOLS_ROOT ?= c:/Espressif/xtensa-lx106-elf/bin 15 | 16 | # base directory of the ESP8266 SDK package, absolute 17 | SDK_BASE ?= c:/Espressif/ESP8266_SDK 18 | SDK_TOOLS ?= c:/Espressif/utils 19 | 20 | # esptool path and port 21 | ESPTOOL ?= $(SDK_TOOLS)/esptool.exe 22 | ESPPORT ?= COM3 23 | # Baud rate for programmer 24 | BAUD ?= 115200 25 | 26 | # SPI_SPEED = 40, 26, 20, 80 27 | SPI_SPEED ?= 40 28 | # SPI_MODE: qio, qout, dio, dout 29 | SPI_MODE ?= qio 30 | # SPI_SIZE_MAP 31 | # 0 : 512 KB (256 KB + 256 KB) 32 | # 1 : 256 KB 33 | # 2 : 1024 KB (512 KB + 512 KB) 34 | # 3 : 2048 KB (512 KB + 512 KB) 35 | # 4 : 4096 KB (512 KB + 512 KB) 36 | # 5 : 2048 KB (1024 KB + 1024 KB) 37 | # 6 : 4096 KB (1024 KB + 1024 KB) 38 | SPI_SIZE_MAP ?= 0 39 | 40 | ifeq ($(SPI_SPEED), 26.7) 41 | freqdiv = 1 42 | flashimageoptions = -ff 26m 43 | else 44 | ifeq ($(SPI_SPEED), 20) 45 | freqdiv = 2 46 | flashimageoptions = -ff 20m 47 | else 48 | ifeq ($(SPI_SPEED), 80) 49 | freqdiv = 15 50 | flashimageoptions = -ff 80m 51 | else 52 | freqdiv = 0 53 | flashimageoptions = -ff 40m 54 | endif 55 | endif 56 | endif 57 | 58 | ifeq ($(SPI_MODE), QOUT) 59 | mode = 1 60 | flashimageoptions += -fm qout 61 | else 62 | ifeq ($(SPI_MODE), DIO) 63 | mode = 2 64 | flashimageoptions += -fm dio 65 | else 66 | ifeq ($(SPI_MODE), DOUT) 67 | mode = 3 68 | flashimageoptions += -fm dout 69 | else 70 | mode = 0 71 | flashimageoptions += -fm qio 72 | endif 73 | endif 74 | endif 75 | 76 | ifeq ($(SPI_SIZE_MAP), 1) 77 | size_map = 1 78 | flash = 256 79 | flashimageoptions += -fs 2m 80 | else 81 | ifeq ($(SPI_SIZE_MAP), 2) 82 | size_map = 2 83 | flash = 1024 84 | flashimageoptions += -fs 8m 85 | else 86 | ifeq ($(SPI_SIZE_MAP), 3) 87 | size_map = 3 88 | flash = 2048 89 | flashimageoptions += -fs 16m 90 | else 91 | ifeq ($(SPI_SIZE_MAP), 4) 92 | size_map = 4 93 | flash = 4096 94 | flashimageoptions += -fs 32m 95 | else 96 | ifeq ($(SPI_SIZE_MAP), 5) 97 | size_map = 5 98 | flash = 2048 99 | flashimageoptions += -fs 16m 100 | else 101 | ifeq ($(SPI_SIZE_MAP), 6) 102 | size_map = 6 103 | flash = 4096 104 | flashimageoptions += -fs 32m 105 | else 106 | size_map = 0 107 | flash = 512 108 | flashimageoptions += -fs 4m 109 | endif 110 | endif 111 | endif 112 | endif 113 | endif 114 | endif 115 | 116 | # name for the target project 117 | TARGET = httpd 118 | 119 | # which modules (subdirectories) of the project to include in compiling 120 | MODULES = user 121 | EXTRA_INCDIR = include libesphttpd/include 122 | 123 | # libraries used in this project, mainly provided by the SDK 124 | LIBS = c gcc hal phy pp net80211 wpa main lwip crypto 125 | #Add in esphttpd lib 126 | LIBS += esphttpd 127 | 128 | # compiler flags using during compilation of source files 129 | CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions \ 130 | -nostdlib -mlongcalls -mtext-section-literals -mno-serialize-volatile -D__ets__ -DICACHE_FLASH -D_STDINT_H \ 131 | -Wno-address 132 | 133 | # linker flags used to generate the main object file 134 | LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static 135 | 136 | # linker script used for the above linkier step 137 | LD_SCRIPT = eagle.app.v6.ld 138 | 139 | # various paths from the SDK used in this project 140 | SDK_LIBDIR = lib 141 | SDK_LDDIR = ld 142 | SDK_INCDIR = include include/json 143 | 144 | # select which tools to use as compiler, librarian and linker 145 | CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 146 | AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar 147 | LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 148 | OBJCOPY := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objcopy 149 | OBJDUMP := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump 150 | 151 | #### 152 | #### no user configurable options below here 153 | #### 154 | SRC_DIR := $(MODULES) 155 | BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) 156 | 157 | SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) 158 | SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) 159 | 160 | SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) 161 | OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) 162 | LIBS := $(addprefix -l,$(LIBS)) 163 | APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) 164 | TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) 165 | 166 | LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) 167 | 168 | INCDIR := $(addprefix -I,$(SRC_DIR)) 169 | EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) 170 | MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) 171 | 172 | V ?= $(VERBOSE) 173 | ifeq ("$(V)","1") 174 | Q := 175 | vecho := @true 176 | else 177 | Q := @ 178 | vecho := @echo 179 | endif 180 | 181 | ifeq ("$(GZIP_COMPRESSION)","yes") 182 | CFLAGS += -DGZIP_COMPRESSION 183 | endif 184 | 185 | ifeq ("$(USE_HEATSHRINK)","yes") 186 | CFLAGS += -DESPFS_HEATSHRINK 187 | endif 188 | 189 | ifeq ("$(ESPFS_POS)","") 190 | #No hardcoded espfs position: link it in with the binaries. 191 | LIBS += -lwebpages-espfs 192 | else 193 | #Hardcoded espfs location: Pass espfs position to rest of code 194 | CFLAGS += -DESPFS_POS=$(ESPFS_POS) -DESPFS_SIZE=$(ESPFS_SIZE) 195 | endif 196 | 197 | vpath %.c $(SRC_DIR) 198 | 199 | define compile-objects 200 | $1/%.o: %.c 201 | $(vecho) "CC $$<" 202 | $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ 203 | endef 204 | 205 | .PHONY: all checkdirs clean libesphttpd 206 | 207 | all: checkdirs $(TARGET_OUT) 208 | 209 | libesphttpd/Makefile: 210 | $(Q) echo "No libesphttpd submodule found. Using git to fetch it..." 211 | $(Q) git submodule init 212 | $(Q) git submodule update 213 | 214 | libesphttpd: libesphttpd/Makefile 215 | $(Q) make -C libesphttpd 216 | 217 | $(TARGET_OUT): $(APP_AR) 218 | $(vecho) "LD $@" 219 | $(Q) $(LD) -Llibesphttpd -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ 220 | $(vecho) "------------------------------------------------------------------------------" 221 | $(vecho) "Section info:" 222 | $(Q) $(OBJDUMP) -h -j .data -j .rodata -j .bss -j .text -j .irom0.text $@ 223 | $(vecho) "------------------------------------------------------------------------------" 224 | $(Q) $(ESPTOOL) elf2image $(TARGET_OUT) -o$(FW_BASE)/ $(flashimageoptions) 225 | $(vecho) "------------------------------------------------------------------------------" 226 | $(vecho) "Generate 0x00000.bin and 0x40000.bin successully in folder $(FW_BASE)." 227 | $(vecho) "0x00000.bin-------->0x00000" 228 | $(vecho) "0x40000.bin-------->0x40000" 229 | $(vecho) "Done" 230 | 231 | $(FW_BASE): 232 | $(Q) mkdir -p $@ 233 | 234 | $(APP_AR): libesphttpd $(OBJ) 235 | $(vecho) "AR $@" 236 | $(Q) $(AR) cru $@ $(OBJ) 237 | 238 | checkdirs: $(BUILD_DIR) $(FW_BASE) 239 | 240 | $(BUILD_DIR): 241 | $(Q) mkdir -p $@ 242 | 243 | flash: $(TARGET_OUT) $(FW_BASE) 244 | $(ESPTOOL) -p $(ESPPORT) -b $(BAUD) write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/0x00000.bin 0x40000 $(FW_BASE)/0x40000.bin 245 | 246 | htmlflash: libesphttpd 247 | $(Q) if [ $$(stat -c '%s' libesphttpd/webpages.espfs) -gt $$(( $(ESPFS_SIZE) )) ]; then echo "webpages.espfs too big!"; false; fi 248 | $(ESPTOOL) -p $(ESPPORT) -b $(BAUD) write_flash $(flashimageoptions) $(ESPFS_POS) libesphttpd/webpages.espfs 249 | 250 | # =============================================================== 251 | # From http://bbs.espressif.com/viewtopic.php?f=10&t=305 252 | # master-device-key.bin is only need if using espressive services 253 | # master_device_key.bin 0x3e000 is not used , write blank 254 | # See 2A-ESP8266__IOT_SDK_User_Manual__EN_v1.1.0.pdf 255 | # http://bbs.espressif.com/download/file.php?id=532 256 | # 257 | # System parameter area is the last 16KB of flash 258 | # 512KB flash - system parameter area starts from 0x7C000 259 | # download blank.bin to 0x7E000 as initialization. 260 | # 1024KB flash - system parameter area starts from 0xFC000 261 | # download blank.bin to 0xFE000 as initialization. 262 | # 2048KB flash - system parameter area starts from 0x1FC000 263 | # download blank.bin to 0x1FE000 as initialization. 264 | # 4096KB flash - system parameter area starts from 0x3FC000 265 | # download blank.bin to 0x3FE000 as initialization. 266 | # =============================================================== 267 | 268 | # FLASH SIZE 269 | flashinit: 270 | $(vecho) "Flash init data:" 271 | $(vecho) "Default config (Clear SDK settings):" 272 | $(vecho) "blank.bin-------->0x3e000" 273 | $(vecho) "blank.bin-------->0x3fc000" 274 | $(vecho) "esp_init_data_default.bin-------->0x3fc000" 275 | $(ESPTOOL) -p $(ESPPORT) write_flash $(flashimageoptions) \ 276 | 0x3e000 $(SDK_BASE)/bin/blank.bin \ 277 | 0x3fc000 $(SDK_BASE)/bin/esp_init_data_default.bin \ 278 | 0x3fe000 $(SDK_BASE)/bin/blank.bin 279 | 280 | clean: 281 | $(Q) make -C libesphttpd clean 282 | $(Q) rm -f $(APP_AR) 283 | $(Q) rm -f $(TARGET_OUT) 284 | $(Q) rm -rf $(BUILD_BASE) 285 | $(Q) find $(BUILD_BASE) -type f | xargs rm -f 286 | $(Q) rm -rf $(FW_BASE) 287 | 288 | $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) 289 | --------------------------------------------------------------------------------