├── .gitignore ├── LICENCE ├── Makefile ├── README.esphttpd ├── README.md ├── include ├── espmissingincludes.h ├── httpdconfig.h ├── lwipopts.h ├── mem_manager.h ├── uart_hw.h └── user_config.h └── user ├── base64.c ├── base64.h ├── sha1.c ├── sha1.h ├── uart.c ├── uart.h ├── uart_register.h ├── user_main.c ├── websocketd.c └── websocketd.h /.gitignore: -------------------------------------------------------------------------------- 1 | #MacOSX 2 | .DS_Store 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Libraries 15 | *.lib 16 | *.a 17 | *.la 18 | *.lo 19 | 20 | # Shared objects (inc. Windows DLLs) 21 | *.dll 22 | *.so 23 | *.so.* 24 | *.dylib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | *.i*86 31 | *.x86_64 32 | *.hex 33 | 34 | # Debug files 35 | *.dSYM/ 36 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Daniel Grießhaber 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # tnx to mamalala 2 | # Changelog 3 | # Changed the variables to include the header file directory 4 | # Added global var for the XTENSA tool root 5 | # 6 | # This make file still needs some work. 7 | # 8 | # 9 | # Output directors to store intermediate compiled files 10 | # relative to the project directory 11 | BUILD_BASE = build 12 | FW_BASE = firmware 13 | 14 | # Base directory for the compiler. Needs a / at the end; if not set it'll use the tools that are in 15 | # the PATH. 16 | XTENSA_TOOLS_ROOT ?= 17 | 18 | # base directory of the ESP8266 SDK package, absolute 19 | SDK_BASE ?= /opt/Espressif/ESP8266_SDK 20 | 21 | #Esptool.py path and port 22 | ESPTOOL ?= esptool 23 | ESPPORT ?= /dev/ttyUSB0 24 | #ESPDELAY indicates seconds to wait between flashing the two binary images 25 | ESPDELAY ?= 3 26 | ESPBAUD ?= 115200 27 | 28 | # name for the target project 29 | TARGET = websocketd 30 | 31 | # which modules (subdirectories) of the project to include in compiling 32 | #MODULES = driver user lwip/api lwip/app lwip/core lwip/core/ipv4 lwip/netif 33 | MODULES = driver user 34 | EXTRA_INCDIR = include \ 35 | . 36 | 37 | # libraries used in this project, mainly provided by the SDK 38 | LIBS = c gcc hal phy pp net80211 wpa main lwip 39 | 40 | # compiler flags using during compilation of source files 41 | CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ 42 | -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \ 43 | -Wno-address 44 | 45 | # linker flags used to generate the main object file 46 | LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static 47 | 48 | # linker script used for the above linkier step 49 | LD_SCRIPT = eagle.app.v6.ld 50 | 51 | # various paths from the SDK used in this project 52 | SDK_LIBDIR = lib 53 | SDK_LDDIR = ld 54 | SDK_INCDIR = include include/json 55 | 56 | # we create two different files for uploading into the flash 57 | # these are the names and options to generate them 58 | FW_FILE_1 = 0x00000 59 | FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec 60 | FW_FILE_2 = 0x40000 61 | FW_FILE_2_ARGS = -es .irom0.text $@ -ec 62 | 63 | # select which tools to use as compiler, librarian and linker 64 | CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc 65 | AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar 66 | LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc 67 | 68 | 69 | 70 | #### 71 | #### no user configurable options below here 72 | #### 73 | SRC_DIR := $(MODULES) 74 | BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) 75 | 76 | SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) 77 | SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) 78 | 79 | SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) 80 | OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) 81 | LIBS := $(addprefix -l,$(LIBS)) 82 | APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) 83 | TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) 84 | 85 | LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) 86 | 87 | INCDIR := $(addprefix -I,$(SRC_DIR)) 88 | EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) 89 | MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) 90 | 91 | FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) 92 | FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) 93 | 94 | V ?= $(VERBOSE) 95 | ifeq ("$(V)","1") 96 | Q := 97 | vecho := @true 98 | else 99 | Q := @ 100 | vecho := @echo 101 | endif 102 | 103 | vpath %.c $(SRC_DIR) 104 | 105 | define compile-objects 106 | $1/%.o: %.c 107 | $(vecho) "CC $$<" 108 | $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ 109 | endef 110 | 111 | .PHONY: all checkdirs clean 112 | 113 | all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) 114 | 115 | $(FW_FILE_1): $(TARGET_OUT) firmware 116 | $(vecho) "FW $@" 117 | $(Q) $(ESPTOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS) 118 | 119 | $(FW_FILE_2): $(TARGET_OUT) firmware 120 | $(vecho) "FW $@" 121 | $(Q) $(ESPTOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS) 122 | 123 | $(TARGET_OUT): $(APP_AR) 124 | $(vecho) "LD $@" 125 | $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ 126 | 127 | $(APP_AR): $(OBJ) 128 | $(vecho) "AR $@" 129 | $(Q) $(AR) cru $@ $^ 130 | 131 | checkdirs: $(BUILD_DIR) $(FW_BASE) 132 | 133 | $(BUILD_DIR): 134 | $(Q) mkdir -p $@ 135 | 136 | firmware: 137 | $(Q) mkdir -p $@ 138 | 139 | flash: $(FW_FILE_1) $(FW_FILE_2) 140 | $(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x00000 -cf firmware/0x00000.bin -v 141 | $(Q) [ $(ESPDELAY) -ne 0 ] && echo "Please put the ESP in bootloader mode..." || true 142 | $(Q) sleep $(ESPDELAY) || true 143 | $(Q) $(ESPTOOL) -cp $(ESPPORT) -cb $(ESPBAUD) -ca 0x40000 -cf firmware/0x40000.bin -v 144 | 145 | clean: 146 | $(Q) rm -f $(APP_AR) 147 | $(Q) rm -f $(TARGET_OUT) 148 | $(Q) find $(BUILD_BASE) -type f | xargs rm -f 149 | 150 | 151 | $(Q) rm -f $(FW_FILE_1) 152 | $(Q) rm -f $(FW_FILE_2) 153 | $(Q) rm -rf $(FW_BASE) 154 | 155 | $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) 156 | -------------------------------------------------------------------------------- /README.esphttpd: -------------------------------------------------------------------------------- 1 | esp-httpd README 2 | 3 | This is a small but powerful webserver for ESP8266(EX) chips. Included is an example of how 4 | to make a module that can have the AP it connects to configured over a webbrowser. 5 | 6 | ABOUT THE WEBSERVER 7 | 8 | The Good (aka: what's awesome) 9 | - Supports multiple connections, for eg simultaneous html/css/js/images downloading 10 | - Static files stored in flash, in an (optionally compressed) RO filesystem 11 | - Pluggable using external cgi routines 12 | - Simple template engine for mixed c and html things 13 | 14 | The Bad (aka: what can be improved) 15 | - Not built for speediness, although it's reasonable fast. 16 | - Built according to what I remember of the HTTP protocol, not according to the 17 | RFCs. Should work with most modern browsers, though. 18 | - No support for https. 19 | 20 | The Ugly (aka: bugs, misbehaviour) 21 | - Possible buffer overflows (usually not remotely exploitable) due to no os_snprintf 22 | This can be theoretically remedied by either Espressif including an os_snprintf in 23 | their libs or by using some alternate printf lib, like elm-chans xprintf 24 | 25 | ABOUT THE EXAMPLE 26 | 27 | When you flash the example into an ESP8266(EX) module, you get a small webserver with a few example 28 | pages. If you've already connected your module to your WLAN before, it'll keep those settings. When 29 | you haven't or the settings are wrong, keep GPIO0 for >5 seconds. The module will reboot into 30 | its STA+AP mode. Connect a computer to the newly formed access point and browse to 31 | http://192.168.4.1/wifi in order to connect the module to your WiFi network. The example also 32 | allows you to control a LED that's connected to GPIO2. 33 | 34 | BUILDING EVERYTHING 35 | 36 | For this, you need an environment that can compile ESP8266 firmware. Environments for this still 37 | are in flux at the moment, but I'm using esp-open-sdk: https://github.com/pfalcon/esp-open-sdk . 38 | You probably also need an UNIX-like system; I'm working on Debian Linux myself. 39 | 40 | To manage the paths to all this, you can source a small shell fragment into your current session. For 41 | example, I source a file with these contents: 42 | export PATH=${PWD}/esp-open-sdk/xtensa-lx106-elf/bin:$PATH 43 | export SDK_BASE=${PWD}/esp-open-sdk/sdk 44 | export ESPTOOL=${PWD}/esptool/esptool 45 | export ESPPORT=/dev/ttyUSB0 46 | export ESPBAUD=460800 47 | 48 | Actual setup of the SDK and toolchain is out of the scope of this document, so I hope this helps you 49 | enough to set up your own if you haven't already. 50 | 51 | If you have that, you can clone out the source code: 52 | git clone http://git.spritesserver.nl/esphttpd.git/ 53 | 54 | This project makes use of heatshrink, which is a git submodule. To fetch the code: 55 | cd esphttpd 56 | git submodule init 57 | git submodule update 58 | 59 | Now, build the code: 60 | make 61 | 62 | Flash the code happens in 2 steps. First the code itself gets flashed. Reset the module into bootloader 63 | mode and enter 'make flash'. You may want to reset and re-enter the bootloader halfway (at 'sleep 3') for 64 | the 2nd part of this flash to work. 65 | 66 | The 2nd step is to pack the static files the webserver will serve and flash that. Reset the module into 67 | bootloader mode again and enter 'make htmlflash'. 68 | 69 | You should have a working webserver now. 70 | 71 | WRITING CODE FOR THE WEBSERVER 72 | 73 | ...errm... to be done. For now, look at the examples. Hey, you probably managed to find out how 74 | the SDK works, this shouldn't be too hard :P 75 | 76 | 77 | CHANGE FROM SDK 0.9.3 (and earlier) TO SDK 0.9.4 (and later): 78 | Change all occurences of 79 | espconn_sent(connData->conn, (uint8 *)buff, len); 80 | to 81 | httpdSend(connData, buff, len) 82 | please. The reason for this is that you can't do multiple espconn_sent calls serially anymore, so 83 | httpd needs to buffer the writes now. This is only needed in your own code; the code that comes 84 | with httpd already has this changed. 85 | 86 | 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Websocket Daemon for the ESP 8266 2 | ================================= 3 | 4 | This is a Websocket implementation based upon the [RFC 6455](https://tools.ietf.org/html/rfc6455). 5 | 6 | The Library uses a stripped Version of the [esphttpd](http://git.spritesserver.nl/esphttpd.git/) as a base. Even though the Websocket Implementation is fully independent from this code, I used this Project as a starting point. So thanks to the author os this project. 7 | 8 | 9 | The code implements a WebSocket Deamon for the ESP8266 WiFi Module. It supports: 10 | 11 | * listening for new Clients 12 | * doing the handshake 13 | * Sending and receiving messages 14 | * as plain text 15 | * as binary 16 | * message unmasking 17 | * creating arbitary message frames 18 | * callbacks for received messages 19 | 20 | ToDo: 21 | 22 | * connect to servers 23 | * send as client 24 | 25 | There are no direct dependencies, as a SHA1 and a Base64 implementation are part of the code. 26 | 27 | Sample server that just echoes ws frames on the UART (serial) 28 | ------------------------------------------------------------- 29 | 30 | ```c 31 | void onWsMessage(WSConnection *connection, const WSFrame *message) { 32 | for (int i = 0; i < message->payloadLength; i++) { 33 | stdoutPutchar(message->payloadData[i]); 34 | } 35 | stdoutPutchar('\n'); 36 | } 37 | 38 | void onWsConnection(WSConnection *connection) { 39 | connection->onMessage = &onWsMessage; 40 | } 41 | 42 | 43 | 44 | //Main routine. Initialize stdout, the I/O and the webserver and we're done. 45 | void user_init(void) { 46 | uart_init(); 47 | ioInit(); 48 | websocketdInit(8080, &onWsConnection); 49 | 50 | //Start os task 51 | system_os_task(rxLoop, RX_PRIO, user_procTaskQueue, RX_QUEUE_LEN); 52 | system_os_post(RX_PRIO, 0, 0 ); 53 | 54 | os_printf("\nReady\n"); 55 | } 56 | ``` 57 | 58 | sample server that echoes the serial data (bidirectional) 59 | --------------------------------------------------------- 60 | 61 | ```c 62 | #include "espmissingincludes.h" 63 | #include "ets_sys.h" 64 | #include "osapi.h" 65 | #include "os_type.h" 66 | #include "uart.h" 67 | #include "websocketd.h" 68 | 69 | #define RX_PRIO 0 70 | #define RX_QUEUE_LEN 1 71 | #define COMMAND_MAXLEN 1024 72 | 73 | os_event_t user_procTaskQueue[RX_QUEUE_LEN]; 74 | static char *statusCommand = "STATUS:"; 75 | static uint8_t commandMatcher = 0; 76 | static uint8_t commandMatched = FALSE; 77 | static char command[COMMAND_MAXLEN]; 78 | static uint32_t commandPosition = 0; 79 | 80 | 81 | //Main code function 82 | static void ICACHE_FLASH_ATTR rxLoop(os_event_t *events) { 83 | 84 | int c = uart0_rx_one_char(); 85 | 86 | if (c != -1) { 87 | 88 | if (commandMatched == TRUE) { 89 | if (c == '\n' || c == '\r') { 90 | broadcastWsMessage(command, commandPosition, FLAG_FIN | OPCODE_TEXT); 91 | commandMatched = FALSE; 92 | commandPosition = 0; 93 | commandMatcher = 0; 94 | }else{ 95 | command[commandPosition++] = c; 96 | } 97 | 98 | if (commandPosition == COMMAND_MAXLEN) { 99 | commandMatched = FALSE; 100 | commandPosition = 0; 101 | commandMatcher = 0; 102 | } 103 | } else { 104 | if (statusCommand[commandMatcher] == c) { 105 | commandMatcher++; 106 | 107 | if (commandMatcher == strlen(statusCommand)) { 108 | commandMatched = TRUE; 109 | } 110 | } else { 111 | commandMatcher = 0; 112 | } 113 | } 114 | } 115 | 116 | system_os_post(RX_PRIO, 0, 0 ); 117 | } 118 | 119 | void onWsMessage(WSConnection *connection, const WSFrame *message) { 120 | for (int i = 0; i < message->payloadLength; i++) { 121 | stdoutPutchar(message->payloadData[i]); 122 | } 123 | stdoutPutchar('\n'); 124 | } 125 | 126 | void onWsConnection(WSConnection *connection) { 127 | connection->onMessage = &onWsMessage; 128 | } 129 | 130 | 131 | 132 | //Main routine. Initialize stdout, the I/O and the webserver and we're done. 133 | void user_init(void) { 134 | uart_init(); 135 | ioInit(); 136 | websocketdInit(8080, &onWsConnection); 137 | 138 | //Start os task 139 | system_os_task(rxLoop, RX_PRIO, user_procTaskQueue, RX_QUEUE_LEN); 140 | system_os_post(RX_PRIO, 0, 0 ); 141 | 142 | os_printf("\nReady\n"); 143 | } 144 | 145 | 146 | ``` 147 | 148 | For Build and upload instructions please refer to the `README.esphttpd` of the esphttpd author. -------------------------------------------------------------------------------- /include/espmissingincludes.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPMISSINGINCLUDES_H 2 | #define ESPMISSINGINCLUDES_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "user_interface.h" 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 pvPortFree(void *ptr); 37 | void *pvPortMalloc(size_t xWantedSize); 38 | void *pvPortZalloc(size_t); 39 | void uart_div_modify(int no, unsigned int freq); 40 | void vPortFree(void *ptr); 41 | void *vPortMalloc(size_t xWantedSize); 42 | uint8 wifi_get_opmode(void); 43 | uint32 system_get_time(); 44 | int os_random(); 45 | int rand(void); 46 | void ets_bzero(void *s, size_t n); 47 | void ets_delay_us(int ms); 48 | bool system_os_task(os_task_t task, uint8 prio, os_event_t *queue, uint8 qlen); 49 | 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/httpdconfig.h: -------------------------------------------------------------------------------- 1 | 2 | //Define this if you want to be able to use Heatshrink-compressed espfs images. 3 | #define EFS_HEATSHRINK 4 | 5 | //Pos of esp fs in flash 6 | #define ESPFS_POS 0x12000 7 | 8 | //If you want, you can define a realm for the authentication system. 9 | //#define HTTP_AUTH_REALM "MyRealm" -------------------------------------------------------------------------------- /include/lwipopts.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * lwIP Options Configuration 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | #ifndef __LWIPOPTS_H__ 39 | #define __LWIPOPTS_H__ 40 | 41 | 42 | /* 43 | ----------------------------------------------- 44 | ---------- Platform specific locking ---------- 45 | ----------------------------------------------- 46 | */ 47 | 48 | /** 49 | * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain 50 | * critical regions during buffer allocation, deallocation and memory 51 | * allocation and deallocation. 52 | */ 53 | #ifndef SYS_LIGHTWEIGHT_PROT 54 | #define SYS_LIGHTWEIGHT_PROT 0 55 | #endif 56 | 57 | /** 58 | * NO_SYS==1: Provides VERY minimal functionality. Otherwise, 59 | * use lwIP facilities. 60 | */ 61 | #ifndef NO_SYS 62 | #define NO_SYS 1 63 | #endif 64 | 65 | /** 66 | * NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1 67 | * Mainly for compatibility to old versions. 68 | */ 69 | #ifndef NO_SYS_NO_TIMERS 70 | #define NO_SYS_NO_TIMERS 0 71 | #endif 72 | 73 | /** 74 | * MEMCPY: override this if you have a faster implementation at hand than the 75 | * one included in your C library 76 | */ 77 | #ifndef MEMCPY 78 | #define MEMCPY(dst,src,len) os_memcpy(dst,src,len) 79 | #endif 80 | 81 | /** 82 | * SMEMCPY: override this with care! Some compilers (e.g. gcc) can inline a 83 | * call to memcpy() if the length is known at compile time and is small. 84 | */ 85 | #ifndef SMEMCPY 86 | #define SMEMCPY(dst,src,len) os_memcpy(dst,src,len) 87 | #endif 88 | 89 | /* 90 | ------------------------------------ 91 | ---------- Memory options ---------- 92 | ------------------------------------ 93 | */ 94 | /** 95 | * MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library 96 | * instead of the lwip internal allocator. Can save code size if you 97 | * already use it. 98 | */ 99 | #ifndef MEM_LIBC_MALLOC 100 | #define MEM_LIBC_MALLOC 1 101 | #endif 102 | 103 | /** 104 | * MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. 105 | * Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution 106 | * speed and usage from interrupts! 107 | */ 108 | #ifndef MEMP_MEM_MALLOC 109 | #define MEMP_MEM_MALLOC 1 110 | #endif 111 | 112 | /** 113 | * MEM_ALIGNMENT: should be set to the alignment of the CPU 114 | * 4 byte alignment -> #define MEM_ALIGNMENT 4 115 | * 2 byte alignment -> #define MEM_ALIGNMENT 2 116 | */ 117 | #ifndef MEM_ALIGNMENT 118 | #define MEM_ALIGNMENT 4 119 | #endif 120 | 121 | /** 122 | * MEM_SIZE: the size of the heap memory. If the application will send 123 | * a lot of data that needs to be copied, this should be set high. 124 | */ 125 | #ifndef MEM_SIZE 126 | #define MEM_SIZE 16000 127 | #endif 128 | 129 | /** 130 | * MEMP_SEPARATE_POOLS: if defined to 1, each pool is placed in its own array. 131 | * This can be used to individually change the location of each pool. 132 | * Default is one big array for all pools 133 | */ 134 | #ifndef MEMP_SEPARATE_POOLS 135 | #define MEMP_SEPARATE_POOLS 1 136 | #endif 137 | 138 | /** 139 | * MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable 140 | * amount of bytes before and after each memp element in every pool and fills 141 | * it with a prominent default value. 142 | * MEMP_OVERFLOW_CHECK == 0 no checking 143 | * MEMP_OVERFLOW_CHECK == 1 checks each element when it is freed 144 | * MEMP_OVERFLOW_CHECK >= 2 checks each element in every pool every time 145 | * memp_malloc() or memp_free() is called (useful but slow!) 146 | */ 147 | #ifndef MEMP_OVERFLOW_CHECK 148 | #define MEMP_OVERFLOW_CHECK 0 149 | #endif 150 | 151 | /** 152 | * MEMP_SANITY_CHECK==1: run a sanity check after each memp_free() to make 153 | * sure that there are no cycles in the linked lists. 154 | */ 155 | #ifndef MEMP_SANITY_CHECK 156 | #define MEMP_SANITY_CHECK 1 157 | #endif 158 | 159 | /** 160 | * MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set 161 | * of memory pools of various sizes. When mem_malloc is called, an element of 162 | * the smallest pool that can provide the length needed is returned. 163 | * To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled. 164 | */ 165 | #ifndef MEM_USE_POOLS 166 | #define MEM_USE_POOLS 0 167 | #endif 168 | 169 | /** 170 | * MEM_USE_POOLS_TRY_BIGGER_POOL==1: if one malloc-pool is empty, try the next 171 | * bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more 172 | * reliable. */ 173 | #ifndef MEM_USE_POOLS_TRY_BIGGER_POOL 174 | #define MEM_USE_POOLS_TRY_BIGGER_POOL 0 175 | #endif 176 | 177 | /** 178 | * MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h 179 | * that defines additional pools beyond the "standard" ones required 180 | * by lwIP. If you set this to 1, you must have lwippools.h in your 181 | * inlude path somewhere. 182 | */ 183 | #ifndef MEMP_USE_CUSTOM_POOLS 184 | #define MEMP_USE_CUSTOM_POOLS 0 185 | #endif 186 | 187 | /** 188 | * Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from 189 | * interrupt context (or another context that doesn't allow waiting for a 190 | * semaphore). 191 | * If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT, 192 | * while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs 193 | * with each loop so that mem_free can run. 194 | * 195 | * ATTENTION: As you can see from the above description, this leads to dis-/ 196 | * enabling interrupts often, which can be slow! Also, on low memory, mem_malloc 197 | * can need longer. 198 | * 199 | * If you don't want that, at least for NO_SYS=0, you can still use the following 200 | * functions to enqueue a deallocation call which then runs in the tcpip_thread 201 | * context: 202 | * - pbuf_free_callback(p); 203 | * - mem_free_callback(m); 204 | */ 205 | #ifndef LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 206 | #define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0 207 | #endif 208 | 209 | /* 210 | ------------------------------------------------ 211 | ---------- Internal Memory Pool Sizes ---------- 212 | ------------------------------------------------ 213 | */ 214 | /** 215 | * MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF). 216 | * If the application sends a lot of data out of ROM (or other static memory), 217 | * this should be set high. 218 | */ 219 | #ifndef MEMP_NUM_PBUF 220 | #define MEMP_NUM_PBUF 10 221 | #endif 222 | 223 | /** 224 | * MEMP_NUM_RAW_PCB: Number of raw connection PCBs 225 | * (requires the LWIP_RAW option) 226 | */ 227 | #ifndef MEMP_NUM_RAW_PCB 228 | #define MEMP_NUM_RAW_PCB 4 229 | #endif 230 | 231 | /** 232 | * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One 233 | * per active UDP "connection". 234 | * (requires the LWIP_UDP option) 235 | */ 236 | #ifndef MEMP_NUM_UDP_PCB 237 | #define MEMP_NUM_UDP_PCB 4 238 | #endif 239 | 240 | /** 241 | * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections. 242 | * (requires the LWIP_TCP option) 243 | */ 244 | #ifndef MEMP_NUM_TCP_PCB 245 | #define MEMP_NUM_TCP_PCB 5 246 | #endif 247 | 248 | /** 249 | * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections. 250 | * (requires the LWIP_TCP option) 251 | */ 252 | #ifndef MEMP_NUM_TCP_PCB_LISTEN 253 | #define MEMP_NUM_TCP_PCB_LISTEN 2 254 | #endif 255 | 256 | /** 257 | * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. 258 | * (requires the LWIP_TCP option) 259 | */ 260 | #ifndef MEMP_NUM_TCP_SEG 261 | #define MEMP_NUM_TCP_SEG 16 262 | #endif 263 | 264 | /** 265 | * MEMP_NUM_REASSDATA: the number of simultaneously IP packets queued for 266 | * reassembly (whole packets, not fragments!) 267 | */ 268 | #ifndef MEMP_NUM_REASSDATA 269 | #define MEMP_NUM_REASSDATA 0 270 | #endif 271 | 272 | /** 273 | * MEMP_NUM_FRAG_PBUF: the number of IP fragments simultaneously sent 274 | * (fragments, not whole packets!). 275 | * This is only used with IP_FRAG_USES_STATIC_BUF==0 and 276 | * LWIP_NETIF_TX_SINGLE_PBUF==0 and only has to be > 1 with DMA-enabled MACs 277 | * where the packet is not yet sent when netif->output returns. 278 | */ 279 | #ifndef MEMP_NUM_FRAG_PBUF 280 | #define MEMP_NUM_FRAG_PBUF 0 281 | #endif 282 | 283 | /** 284 | * MEMP_NUM_ARP_QUEUE: the number of simulateously queued outgoing 285 | * packets (pbufs) that are waiting for an ARP request (to resolve 286 | * their destination address) to finish. 287 | * (requires the ARP_QUEUEING option) 288 | */ 289 | #ifndef MEMP_NUM_ARP_QUEUE 290 | #define MEMP_NUM_ARP_QUEUE 10 291 | #endif 292 | 293 | /** 294 | * MEMP_NUM_IGMP_GROUP: The number of multicast groups whose network interfaces 295 | * can be members et the same time (one per netif - allsystems group -, plus one 296 | * per netif membership). 297 | * (requires the LWIP_IGMP option) 298 | */ 299 | #ifndef MEMP_NUM_IGMP_GROUP 300 | #define MEMP_NUM_IGMP_GROUP 8 301 | #endif 302 | 303 | /** 304 | * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. 305 | * (requires NO_SYS==0) 306 | */ 307 | #ifndef MEMP_NUM_SYS_TIMEOUT 308 | #define MEMP_NUM_SYS_TIMEOUT 6 309 | #endif 310 | 311 | /** 312 | * MEMP_NUM_NETBUF: the number of struct netbufs. 313 | * (only needed if you use the sequential API, like api_lib.c) 314 | */ 315 | #ifndef MEMP_NUM_NETBUF 316 | #define MEMP_NUM_NETBUF 0 317 | #endif 318 | 319 | /** 320 | * MEMP_NUM_NETCONN: the number of struct netconns. 321 | * (only needed if you use the sequential API, like api_lib.c) 322 | */ 323 | #ifndef MEMP_NUM_NETCONN 324 | #define MEMP_NUM_NETCONN 0 325 | #endif 326 | 327 | /** 328 | * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used 329 | * for callback/timeout API communication. 330 | * (only needed if you use tcpip.c) 331 | */ 332 | #ifndef MEMP_NUM_TCPIP_MSG_API 333 | #define MEMP_NUM_TCPIP_MSG_API 4 334 | #endif 335 | 336 | /** 337 | * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used 338 | * for incoming packets. 339 | * (only needed if you use tcpip.c) 340 | */ 341 | #ifndef MEMP_NUM_TCPIP_MSG_INPKT 342 | #define MEMP_NUM_TCPIP_MSG_INPKT 4 343 | #endif 344 | 345 | /** 346 | * MEMP_NUM_SNMP_NODE: the number of leafs in the SNMP tree. 347 | */ 348 | #ifndef MEMP_NUM_SNMP_NODE 349 | #define MEMP_NUM_SNMP_NODE 0 350 | #endif 351 | 352 | /** 353 | * MEMP_NUM_SNMP_ROOTNODE: the number of branches in the SNMP tree. 354 | * Every branch has one leaf (MEMP_NUM_SNMP_NODE) at least! 355 | */ 356 | #ifndef MEMP_NUM_SNMP_ROOTNODE 357 | #define MEMP_NUM_SNMP_ROOTNODE 0 358 | #endif 359 | 360 | /** 361 | * MEMP_NUM_SNMP_VARBIND: the number of concurrent requests (does not have to 362 | * be changed normally) - 2 of these are used per request (1 for input, 363 | * 1 for output) 364 | */ 365 | #ifndef MEMP_NUM_SNMP_VARBIND 366 | #define MEMP_NUM_SNMP_VARBIND 0 367 | #endif 368 | 369 | /** 370 | * MEMP_NUM_SNMP_VALUE: the number of OID or values concurrently used 371 | * (does not have to be changed normally) - 3 of these are used per request 372 | * (1 for the value read and 2 for OIDs - input and output) 373 | */ 374 | #ifndef MEMP_NUM_SNMP_VALUE 375 | #define MEMP_NUM_SNMP_VALUE 0 376 | #endif 377 | 378 | /** 379 | * MEMP_NUM_NETDB: the number of concurrently running lwip_addrinfo() calls 380 | * (before freeing the corresponding memory using lwip_freeaddrinfo()). 381 | */ 382 | #ifndef MEMP_NUM_NETDB 383 | #define MEMP_NUM_NETDB 0 384 | #endif 385 | 386 | /** 387 | * MEMP_NUM_LOCALHOSTLIST: the number of host entries in the local host list 388 | * if DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1. 389 | */ 390 | #ifndef MEMP_NUM_LOCALHOSTLIST 391 | #define MEMP_NUM_LOCALHOSTLIST 0 392 | #endif 393 | 394 | /** 395 | * MEMP_NUM_PPPOE_INTERFACES: the number of concurrently active PPPoE 396 | * interfaces (only used with PPPOE_SUPPORT==1) 397 | */ 398 | #ifndef MEMP_NUM_PPPOE_INTERFACES 399 | #define MEMP_NUM_PPPOE_INTERFACES 0 400 | #endif 401 | 402 | /** 403 | * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. 404 | */ 405 | #ifndef PBUF_POOL_SIZE 406 | #define PBUF_POOL_SIZE 10 407 | #endif 408 | 409 | /* 410 | --------------------------------- 411 | ---------- ARP options ---------- 412 | --------------------------------- 413 | */ 414 | /** 415 | * LWIP_ARP==1: Enable ARP functionality. 416 | */ 417 | #ifndef LWIP_ARP 418 | #define LWIP_ARP 1 419 | #endif 420 | 421 | /** 422 | * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached. 423 | */ 424 | #ifndef ARP_TABLE_SIZE 425 | #define ARP_TABLE_SIZE 10 426 | #endif 427 | 428 | /** 429 | * ARP_QUEUEING==1: Multiple outgoing packets are queued during hardware address 430 | * resolution. By default, only the most recent packet is queued per IP address. 431 | * This is sufficient for most protocols and mainly reduces TCP connection 432 | * startup time. Set this to 1 if you know your application sends more than one 433 | * packet in a row to an IP address that is not in the ARP cache. 434 | */ 435 | #ifndef ARP_QUEUEING 436 | #define ARP_QUEUEING 1 437 | #endif 438 | 439 | /** 440 | * ETHARP_TRUST_IP_MAC==1: Incoming IP packets cause the ARP table to be 441 | * updated with the source MAC and IP addresses supplied in the packet. 442 | * You may want to disable this if you do not trust LAN peers to have the 443 | * correct addresses, or as a limited approach to attempt to handle 444 | * spoofing. If disabled, lwIP will need to make a new ARP request if 445 | * the peer is not already in the ARP table, adding a little latency. 446 | * The peer *is* in the ARP table if it requested our address before. 447 | * Also notice that this slows down input processing of every IP packet! 448 | */ 449 | #ifndef ETHARP_TRUST_IP_MAC 450 | #define ETHARP_TRUST_IP_MAC 1 451 | #endif 452 | 453 | /** 454 | * ETHARP_SUPPORT_VLAN==1: support receiving ethernet packets with VLAN header. 455 | * Additionally, you can define ETHARP_VLAN_CHECK to an u16_t VLAN ID to check. 456 | * If ETHARP_VLAN_CHECK is defined, only VLAN-traffic for this VLAN is accepted. 457 | * If ETHARP_VLAN_CHECK is not defined, all traffic is accepted. 458 | */ 459 | #ifndef ETHARP_SUPPORT_VLAN 460 | #define ETHARP_SUPPORT_VLAN 0 461 | #endif 462 | 463 | /** LWIP_ETHERNET==1: enable ethernet support for PPPoE even though ARP 464 | * might be disabled 465 | */ 466 | #ifndef LWIP_ETHERNET 467 | #define LWIP_ETHERNET (LWIP_ARP || PPPOE_SUPPORT) 468 | #endif 469 | 470 | /** ETH_PAD_SIZE: number of bytes added before the ethernet header to ensure 471 | * alignment of payload after that header. Since the header is 14 bytes long, 472 | * without this padding e.g. addresses in the IP header will not be aligned 473 | * on a 32-bit boundary, so setting this to 2 can speed up 32-bit-platforms. 474 | */ 475 | #ifndef ETH_PAD_SIZE 476 | #define ETH_PAD_SIZE 0 477 | #endif 478 | 479 | /** ETHARP_SUPPORT_STATIC_ENTRIES==1: enable code to support static ARP table 480 | * entries (using etharp_add_static_entry/etharp_remove_static_entry). 481 | */ 482 | #ifndef ETHARP_SUPPORT_STATIC_ENTRIES 483 | #define ETHARP_SUPPORT_STATIC_ENTRIES 0 484 | #endif 485 | 486 | 487 | /* 488 | -------------------------------- 489 | ---------- IP options ---------- 490 | -------------------------------- 491 | */ 492 | /** 493 | * IP_FORWARD==1: Enables the ability to forward IP packets across network 494 | * interfaces. If you are going to run lwIP on a device with only one network 495 | * interface, define this to 0. 496 | */ 497 | #ifndef IP_FORWARD 498 | #define IP_FORWARD 0 499 | #endif 500 | 501 | /** 502 | * IP_OPTIONS_ALLOWED: Defines the behavior for IP options. 503 | * IP_OPTIONS_ALLOWED==0: All packets with IP options are dropped. 504 | * IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed). 505 | */ 506 | #ifndef IP_OPTIONS_ALLOWED 507 | #define IP_OPTIONS_ALLOWED 1 508 | #endif 509 | 510 | /** 511 | * IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that 512 | * this option does not affect outgoing packet sizes, which can be controlled 513 | * via IP_FRAG. 514 | */ 515 | #ifndef IP_REASSEMBLY 516 | #define IP_REASSEMBLY 0 517 | #endif 518 | 519 | /** 520 | * IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note 521 | * that this option does not affect incoming packet sizes, which can be 522 | * controlled via IP_REASSEMBLY. 523 | */ 524 | #ifndef IP_FRAG 525 | #define IP_FRAG 0 526 | #endif 527 | 528 | /** 529 | * IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally) 530 | * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived 531 | * in this time, the whole packet is discarded. 532 | */ 533 | #ifndef IP_REASS_MAXAGE 534 | #define IP_REASS_MAXAGE 0 535 | #endif 536 | 537 | /** 538 | * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled. 539 | * Since the received pbufs are enqueued, be sure to configure 540 | * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive 541 | * packets even if the maximum amount of fragments is enqueued for reassembly! 542 | */ 543 | #ifndef IP_REASS_MAX_PBUFS 544 | #define IP_REASS_MAX_PBUFS 0 545 | #endif 546 | 547 | /** 548 | * IP_FRAG_USES_STATIC_BUF==1: Use a static MTU-sized buffer for IP 549 | * fragmentation. Otherwise pbufs are allocated and reference the original 550 | * packet data to be fragmented (or with LWIP_NETIF_TX_SINGLE_PBUF==1, 551 | * new PBUF_RAM pbufs are used for fragments). 552 | * ATTENTION: IP_FRAG_USES_STATIC_BUF==1 may not be used for DMA-enabled MACs! 553 | */ 554 | #ifndef IP_FRAG_USES_STATIC_BUF 555 | #define IP_FRAG_USES_STATIC_BUF 1 556 | #endif 557 | 558 | /** 559 | * IP_FRAG_MAX_MTU: Assumed max MTU on any interface for IP frag buffer 560 | * (requires IP_FRAG_USES_STATIC_BUF==1) 561 | */ 562 | #if IP_FRAG_USES_STATIC_BUF && !defined(IP_FRAG_MAX_MTU) 563 | #define IP_FRAG_MAX_MTU 1500 564 | #endif 565 | 566 | /** 567 | * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. 568 | */ 569 | #ifndef IP_DEFAULT_TTL 570 | #define IP_DEFAULT_TTL 255 571 | #endif 572 | 573 | /** 574 | * IP_SOF_BROADCAST=1: Use the SOF_BROADCAST field to enable broadcast 575 | * filter per pcb on udp and raw send operations. To enable broadcast filter 576 | * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1. 577 | */ 578 | #ifndef IP_SOF_BROADCAST 579 | #define IP_SOF_BROADCAST 0 580 | #endif 581 | 582 | /** 583 | * IP_SOF_BROADCAST_RECV (requires IP_SOF_BROADCAST=1) enable the broadcast 584 | * filter on recv operations. 585 | */ 586 | #ifndef IP_SOF_BROADCAST_RECV 587 | #define IP_SOF_BROADCAST_RECV 0 588 | #endif 589 | 590 | /* 591 | ---------------------------------- 592 | ---------- ICMP options ---------- 593 | ---------------------------------- 594 | */ 595 | /** 596 | * LWIP_ICMP==1: Enable ICMP module inside the IP stack. 597 | * Be careful, disable that make your product non-compliant to RFC1122 598 | */ 599 | #ifndef LWIP_ICMP 600 | #define LWIP_ICMP 1 601 | #endif 602 | 603 | /** 604 | * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. 605 | */ 606 | #ifndef ICMP_TTL 607 | #define ICMP_TTL (IP_DEFAULT_TTL) 608 | #endif 609 | 610 | /** 611 | * LWIP_BROADCAST_PING==1: respond to broadcast pings (default is unicast only) 612 | */ 613 | #ifndef LWIP_BROADCAST_PING 614 | #define LWIP_BROADCAST_PING 0 615 | #endif 616 | 617 | /** 618 | * LWIP_MULTICAST_PING==1: respond to multicast pings (default is unicast only) 619 | */ 620 | #ifndef LWIP_MULTICAST_PING 621 | #define LWIP_MULTICAST_PING 0 622 | #endif 623 | 624 | /* 625 | --------------------------------- 626 | ---------- RAW options ---------- 627 | --------------------------------- 628 | */ 629 | /** 630 | * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. 631 | */ 632 | #ifndef LWIP_RAW 633 | #define LWIP_RAW 0 634 | #endif 635 | 636 | /** 637 | * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. 638 | */ 639 | #ifndef RAW_TTL 640 | #define RAW_TTL (IP_DEFAULT_TTL) 641 | #endif 642 | 643 | /* 644 | ---------------------------------- 645 | ---------- DHCP options ---------- 646 | ---------------------------------- 647 | */ 648 | /** 649 | * LWIP_DHCP==1: Enable DHCP module. 650 | */ 651 | #ifndef LWIP_DHCP 652 | #define LWIP_DHCP 1 653 | #endif 654 | 655 | /** 656 | * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. 657 | */ 658 | #ifndef DHCP_DOES_ARP_CHECK 659 | #define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP)) 660 | #endif 661 | 662 | /* 663 | ------------------------------------ 664 | ---------- AUTOIP options ---------- 665 | ------------------------------------ 666 | */ 667 | /** 668 | * LWIP_AUTOIP==1: Enable AUTOIP module. 669 | */ 670 | #ifndef LWIP_AUTOIP 671 | #define LWIP_AUTOIP 0 672 | #endif 673 | 674 | /** 675 | * LWIP_DHCP_AUTOIP_COOP==1: Allow DHCP and AUTOIP to be both enabled on 676 | * the same interface at the same time. 677 | */ 678 | #ifndef LWIP_DHCP_AUTOIP_COOP 679 | #define LWIP_DHCP_AUTOIP_COOP 0 680 | #endif 681 | 682 | /** 683 | * LWIP_DHCP_AUTOIP_COOP_TRIES: Set to the number of DHCP DISCOVER probes 684 | * that should be sent before falling back on AUTOIP. This can be set 685 | * as low as 1 to get an AutoIP address very quickly, but you should 686 | * be prepared to handle a changing IP address when DHCP overrides 687 | * AutoIP. 688 | */ 689 | #ifndef LWIP_DHCP_AUTOIP_COOP_TRIES 690 | #define LWIP_DHCP_AUTOIP_COOP_TRIES 9 691 | #endif 692 | 693 | /* 694 | ---------------------------------- 695 | ---------- SNMP options ---------- 696 | ---------------------------------- 697 | */ 698 | /** 699 | * LWIP_SNMP==1: Turn on SNMP module. UDP must be available for SNMP 700 | * transport. 701 | */ 702 | #ifndef LWIP_SNMP 703 | #define LWIP_SNMP 0 704 | #endif 705 | 706 | /** 707 | * SNMP_CONCURRENT_REQUESTS: Number of concurrent requests the module will 708 | * allow. At least one request buffer is required. 709 | */ 710 | #ifndef SNMP_CONCURRENT_REQUESTS 711 | #define SNMP_CONCURRENT_REQUESTS 0 712 | #endif 713 | 714 | /** 715 | * SNMP_TRAP_DESTINATIONS: Number of trap destinations. At least one trap 716 | * destination is required 717 | */ 718 | #ifndef SNMP_TRAP_DESTINATIONS 719 | #define SNMP_TRAP_DESTINATIONS 0 720 | #endif 721 | 722 | /** 723 | * SNMP_PRIVATE_MIB: 724 | */ 725 | #ifndef SNMP_PRIVATE_MIB 726 | #define SNMP_PRIVATE_MIB 0 727 | #endif 728 | 729 | /** 730 | * Only allow SNMP write actions that are 'safe' (e.g. disabeling netifs is not 731 | * a safe action and disabled when SNMP_SAFE_REQUESTS = 1). 732 | * Unsafe requests are disabled by default! 733 | */ 734 | #ifndef SNMP_SAFE_REQUESTS 735 | #define SNMP_SAFE_REQUESTS 0 736 | #endif 737 | 738 | /** 739 | * The maximum length of strings used. This affects the size of 740 | * MEMP_SNMP_VALUE elements. 741 | */ 742 | #ifndef SNMP_MAX_OCTET_STRING_LEN 743 | #define SNMP_MAX_OCTET_STRING_LEN 127 744 | #endif 745 | 746 | /** 747 | * The maximum depth of the SNMP tree. 748 | * With private MIBs enabled, this depends on your MIB! 749 | * This affects the size of MEMP_SNMP_VALUE elements. 750 | */ 751 | #ifndef SNMP_MAX_TREE_DEPTH 752 | #define SNMP_MAX_TREE_DEPTH 15 753 | #endif 754 | 755 | /** 756 | * The size of the MEMP_SNMP_VALUE elements, normally calculated from 757 | * SNMP_MAX_OCTET_STRING_LEN and SNMP_MAX_TREE_DEPTH. 758 | */ 759 | #ifndef SNMP_MAX_VALUE_SIZE 760 | #define SNMP_MAX_VALUE_SIZE LWIP_MAX((SNMP_MAX_OCTET_STRING_LEN)+1, sizeof(s32_t)*(SNMP_MAX_TREE_DEPTH)) 761 | #endif 762 | 763 | /* 764 | ---------------------------------- 765 | ---------- IGMP options ---------- 766 | ---------------------------------- 767 | */ 768 | /** 769 | * LWIP_IGMP==1: Turn on IGMP module. 770 | */ 771 | #ifndef LWIP_IGMP 772 | #define LWIP_IGMP 1 773 | #endif 774 | 775 | /* 776 | ---------------------------------- 777 | ---------- DNS options ----------- 778 | ---------------------------------- 779 | */ 780 | /** 781 | * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS 782 | * transport. 783 | */ 784 | #ifndef LWIP_DNS 785 | #define LWIP_DNS 1 786 | #endif 787 | 788 | /** DNS maximum number of entries to maintain locally. */ 789 | #ifndef DNS_TABLE_SIZE 790 | #define DNS_TABLE_SIZE 4 791 | #endif 792 | 793 | /** DNS maximum host name length supported in the name table. */ 794 | #ifndef DNS_MAX_NAME_LENGTH 795 | #define DNS_MAX_NAME_LENGTH 256 796 | #endif 797 | 798 | /** The maximum of DNS servers */ 799 | #ifndef DNS_MAX_SERVERS 800 | #define DNS_MAX_SERVERS 2 801 | #endif 802 | 803 | /** DNS do a name checking between the query and the response. */ 804 | #ifndef DNS_DOES_NAME_CHECK 805 | #define DNS_DOES_NAME_CHECK 1 806 | #endif 807 | 808 | /** DNS message max. size. Default value is RFC compliant. */ 809 | #ifndef DNS_MSG_SIZE 810 | #define DNS_MSG_SIZE 512 811 | #endif 812 | 813 | /** DNS_LOCAL_HOSTLIST: Implements a local host-to-address list. If enabled, 814 | * you have to define 815 | * #define DNS_LOCAL_HOSTLIST_INIT {{"host1", 0x123}, {"host2", 0x234}} 816 | * (an array of structs name/address, where address is an u32_t in network 817 | * byte order). 818 | * 819 | * Instead, you can also use an external function: 820 | * #define DNS_LOOKUP_LOCAL_EXTERN(x) extern u32_t my_lookup_function(const char *name) 821 | * that returns the IP address or INADDR_NONE if not found. 822 | */ 823 | #ifndef DNS_LOCAL_HOSTLIST 824 | #define DNS_LOCAL_HOSTLIST 0 825 | #endif /* DNS_LOCAL_HOSTLIST */ 826 | 827 | /** If this is turned on, the local host-list can be dynamically changed 828 | * at runtime. */ 829 | #ifndef DNS_LOCAL_HOSTLIST_IS_DYNAMIC 830 | #define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0 831 | #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 832 | 833 | /* 834 | --------------------------------- 835 | ---------- UDP options ---------- 836 | --------------------------------- 837 | */ 838 | /** 839 | * LWIP_UDP==1: Turn on UDP. 840 | */ 841 | #ifndef LWIP_UDP 842 | #define LWIP_UDP 1 843 | #endif 844 | 845 | /** 846 | * LWIP_UDPLITE==1: Turn on UDP-Lite. (Requires LWIP_UDP) 847 | */ 848 | #ifndef LWIP_UDPLITE 849 | #define LWIP_UDPLITE 0 850 | #endif 851 | 852 | /** 853 | * UDP_TTL: Default Time-To-Live value. 854 | */ 855 | #ifndef UDP_TTL 856 | #define UDP_TTL (IP_DEFAULT_TTL) 857 | #endif 858 | 859 | /** 860 | * LWIP_NETBUF_RECVINFO==1: append destination addr and port to every netbuf. 861 | */ 862 | #ifndef LWIP_NETBUF_RECVINFO 863 | #define LWIP_NETBUF_RECVINFO 0 864 | #endif 865 | 866 | /* 867 | --------------------------------- 868 | ---------- TCP options ---------- 869 | --------------------------------- 870 | */ 871 | /** 872 | * LWIP_TCP==1: Turn on TCP. 873 | */ 874 | #ifndef LWIP_TCP 875 | #define LWIP_TCP 1 876 | #endif 877 | 878 | /** 879 | * TCP_TTL: Default Time-To-Live value. 880 | */ 881 | #ifndef TCP_TTL 882 | #define TCP_TTL (IP_DEFAULT_TTL) 883 | #endif 884 | 885 | /** 886 | * TCP_WND: The size of a TCP window. This must be at least 887 | * (2 * TCP_MSS) for things to work well 888 | */ 889 | #ifndef TCP_WND 890 | #define TCP_WND (4 * TCP_MSS) 891 | #endif 892 | 893 | /** 894 | * TCP_MAXRTX: Maximum number of retransmissions of data segments. 895 | */ 896 | #ifndef TCP_MAXRTX 897 | #define TCP_MAXRTX 5 898 | #endif 899 | 900 | /** 901 | * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments. 902 | */ 903 | #ifndef TCP_SYNMAXRTX 904 | #define TCP_SYNMAXRTX 5 905 | #endif 906 | 907 | /** 908 | * TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order. 909 | * Define to 0 if your device is low on memory. 910 | */ 911 | #ifndef TCP_QUEUE_OOSEQ 912 | #define TCP_QUEUE_OOSEQ 0 913 | #endif 914 | 915 | /** 916 | * TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default, 917 | * you might want to increase this.) 918 | * For the receive side, this MSS is advertised to the remote side 919 | * when opening a connection. For the transmit size, this MSS sets 920 | * an upper limit on the MSS advertised by the remote host. 921 | */ 922 | #ifndef TCP_MSS 923 | #define TCP_MSS 1460 924 | #endif 925 | 926 | /** 927 | * TCP_CALCULATE_EFF_SEND_MSS: "The maximum size of a segment that TCP really 928 | * sends, the 'effective send MSS,' MUST be the smaller of the send MSS (which 929 | * reflects the available reassembly buffer size at the remote host) and the 930 | * largest size permitted by the IP layer" (RFC 1122) 931 | * Setting this to 1 enables code that checks TCP_MSS against the MTU of the 932 | * netif used for a connection and limits the MSS if it would be too big otherwise. 933 | */ 934 | #ifndef TCP_CALCULATE_EFF_SEND_MSS 935 | #define TCP_CALCULATE_EFF_SEND_MSS 1 936 | #endif 937 | 938 | 939 | /** 940 | * TCP_SND_BUF: TCP sender buffer space (bytes). 941 | */ 942 | #ifndef TCP_SND_BUF 943 | #define TCP_SND_BUF 2 * TCP_MSS 944 | #endif 945 | 946 | /** 947 | * TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least 948 | * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. 949 | */ 950 | #ifndef TCP_SND_QUEUELEN 951 | #define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) 952 | #endif 953 | 954 | /** 955 | * TCP_SNDLOWAT: TCP writable space (bytes). This must be less than 956 | * TCP_SND_BUF. It is the amount of space which must be available in the 957 | * TCP snd_buf for select to return writable (combined with TCP_SNDQUEUELOWAT). 958 | */ 959 | #ifndef TCP_SNDLOWAT 960 | #define TCP_SNDLOWAT ((TCP_SND_BUF)/2) 961 | #endif 962 | 963 | /** 964 | * TCP_SNDQUEUELOWAT: TCP writable bufs (pbuf count). This must be grater 965 | * than TCP_SND_QUEUELEN. If the number of pbufs queued on a pcb drops below 966 | * this number, select returns writable (combined with TCP_SNDLOWAT). 967 | */ 968 | #ifndef TCP_SNDQUEUELOWAT 969 | #define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5) 970 | #endif 971 | 972 | /** 973 | * TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb. 974 | */ 975 | #ifndef TCP_LISTEN_BACKLOG 976 | #define TCP_LISTEN_BACKLOG 0 977 | #endif 978 | 979 | /** 980 | * The maximum allowed backlog for TCP listen netconns. 981 | * This backlog is used unless another is explicitly specified. 982 | * 0xff is the maximum (u8_t). 983 | */ 984 | #ifndef TCP_DEFAULT_LISTEN_BACKLOG 985 | #define TCP_DEFAULT_LISTEN_BACKLOG 0xff 986 | #endif 987 | 988 | /** 989 | * TCP_OVERSIZE: The maximum number of bytes that tcp_write may 990 | * allocate ahead of time in an attempt to create shorter pbuf chains 991 | * for transmission. The meaningful range is 0 to TCP_MSS. Some 992 | * suggested values are: 993 | * 994 | * 0: Disable oversized allocation. Each tcp_write() allocates a new 995 | pbuf (old behaviour). 996 | * 1: Allocate size-aligned pbufs with minimal excess. Use this if your 997 | * scatter-gather DMA requires aligned fragments. 998 | * 128: Limit the pbuf/memory overhead to 20%. 999 | * TCP_MSS: Try to create unfragmented TCP packets. 1000 | * TCP_MSS/4: Try to create 4 fragments or less per TCP packet. 1001 | */ 1002 | #ifndef TCP_OVERSIZE 1003 | #define TCP_OVERSIZE TCP_MSS 1004 | #endif 1005 | 1006 | /** 1007 | * LWIP_TCP_TIMESTAMPS==1: support the TCP timestamp option. 1008 | */ 1009 | #ifndef LWIP_TCP_TIMESTAMPS 1010 | #define LWIP_TCP_TIMESTAMPS 0 1011 | #endif 1012 | 1013 | /** 1014 | * TCP_WND_UPDATE_THRESHOLD: difference in window to trigger an 1015 | * explicit window update 1016 | */ 1017 | #ifndef TCP_WND_UPDATE_THRESHOLD 1018 | #define TCP_WND_UPDATE_THRESHOLD (TCP_WND / 4) 1019 | #endif 1020 | 1021 | /** 1022 | * LWIP_EVENT_API and LWIP_CALLBACK_API: Only one of these should be set to 1. 1023 | * LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all 1024 | * events (accept, sent, etc) that happen in the system. 1025 | * LWIP_CALLBACK_API==1: The PCB callback function is called directly 1026 | * for the event. 1027 | */ 1028 | #ifndef LWIP_EVENT_API 1029 | #define LWIP_EVENT_API 0 1030 | #define LWIP_CALLBACK_API 1 1031 | #else 1032 | #define LWIP_EVENT_API 1 1033 | #define LWIP_CALLBACK_API 0 1034 | #endif 1035 | 1036 | 1037 | /* 1038 | ---------------------------------- 1039 | ---------- Pbuf options ---------- 1040 | ---------------------------------- 1041 | */ 1042 | /** 1043 | * PBUF_LINK_HLEN: the number of bytes that should be allocated for a 1044 | * link level header. The default is 14, the standard value for 1045 | * Ethernet. 1046 | */ 1047 | #ifndef PBUF_LINK_HLEN 1048 | #define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) 1049 | #endif 1050 | 1051 | /** 1052 | * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is 1053 | * designed to accomodate single full size TCP frame in one pbuf, including 1054 | * TCP_MSS, IP header, and link header. 1055 | */ 1056 | #ifndef PBUF_POOL_BUFSIZE 1057 | #define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN) 1058 | #endif 1059 | 1060 | /* 1061 | ------------------------------------------------ 1062 | ---------- Network Interfaces options ---------- 1063 | ------------------------------------------------ 1064 | */ 1065 | /** 1066 | * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname 1067 | * field. 1068 | */ 1069 | #ifndef LWIP_NETIF_HOSTNAME 1070 | #define LWIP_NETIF_HOSTNAME 0 1071 | #endif 1072 | 1073 | /** 1074 | * LWIP_NETIF_API==1: Support netif api (in netifapi.c) 1075 | */ 1076 | #ifndef LWIP_NETIF_API 1077 | #define LWIP_NETIF_API 0 1078 | #endif 1079 | 1080 | /** 1081 | * LWIP_NETIF_STATUS_CALLBACK==1: Support a callback function whenever an interface 1082 | * changes its up/down status (i.e., due to DHCP IP acquistion) 1083 | */ 1084 | #ifndef LWIP_NETIF_STATUS_CALLBACK 1085 | #define LWIP_NETIF_STATUS_CALLBACK 0 1086 | #endif 1087 | 1088 | /** 1089 | * LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface 1090 | * whenever the link changes (i.e., link down) 1091 | */ 1092 | #ifndef LWIP_NETIF_LINK_CALLBACK 1093 | #define LWIP_NETIF_LINK_CALLBACK 0 1094 | #endif 1095 | 1096 | /** 1097 | * LWIP_NETIF_HWADDRHINT==1: Cache link-layer-address hints (e.g. table 1098 | * indices) in struct netif. TCP and UDP can make use of this to prevent 1099 | * scanning the ARP table for every sent packet. While this is faster for big 1100 | * ARP tables or many concurrent connections, it might be counterproductive 1101 | * if you have a tiny ARP table or if there never are concurrent connections. 1102 | */ 1103 | #ifndef LWIP_NETIF_HWADDRHINT 1104 | #define LWIP_NETIF_HWADDRHINT 0 1105 | #endif 1106 | 1107 | /** 1108 | * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP 1109 | * address equal to the netif IP address, looping them back up the stack. 1110 | */ 1111 | #ifndef LWIP_NETIF_LOOPBACK 1112 | #define LWIP_NETIF_LOOPBACK 0 1113 | #endif 1114 | 1115 | /** 1116 | * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback 1117 | * sending for each netif (0 = disabled) 1118 | */ 1119 | #ifndef LWIP_LOOPBACK_MAX_PBUFS 1120 | #define LWIP_LOOPBACK_MAX_PBUFS 0 1121 | #endif 1122 | 1123 | /** 1124 | * LWIP_NETIF_LOOPBACK_MULTITHREADING: Indicates whether threading is enabled in 1125 | * the system, as netifs must change how they behave depending on this setting 1126 | * for the LWIP_NETIF_LOOPBACK option to work. 1127 | * Setting this is needed to avoid reentering non-reentrant functions like 1128 | * tcp_input(). 1129 | * LWIP_NETIF_LOOPBACK_MULTITHREADING==1: Indicates that the user is using a 1130 | * multithreaded environment like tcpip.c. In this case, netif->input() 1131 | * is called directly. 1132 | * LWIP_NETIF_LOOPBACK_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup. 1133 | * The packets are put on a list and netif_poll() must be called in 1134 | * the main application loop. 1135 | */ 1136 | #ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING 1137 | #define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS) 1138 | #endif 1139 | 1140 | /** 1141 | * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data 1142 | * to be sent into one single pbuf. This is for compatibility with DMA-enabled 1143 | * MACs that do not support scatter-gather. 1144 | * Beware that this might involve CPU-memcpy before transmitting that would not 1145 | * be needed without this flag! Use this only if you need to! 1146 | * 1147 | * @todo: TCP and IP-frag do not work with this, yet: 1148 | */ 1149 | #ifndef LWIP_NETIF_TX_SINGLE_PBUF 1150 | #define LWIP_NETIF_TX_SINGLE_PBUF 1 1151 | #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ 1152 | 1153 | /* 1154 | ------------------------------------ 1155 | ---------- LOOPIF options ---------- 1156 | ------------------------------------ 1157 | */ 1158 | /** 1159 | * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c 1160 | */ 1161 | #ifndef LWIP_HAVE_LOOPIF 1162 | #define LWIP_HAVE_LOOPIF 0 1163 | #endif 1164 | 1165 | /* 1166 | ------------------------------------ 1167 | ---------- SLIPIF options ---------- 1168 | ------------------------------------ 1169 | */ 1170 | /** 1171 | * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c 1172 | */ 1173 | #ifndef LWIP_HAVE_SLIPIF 1174 | #define LWIP_HAVE_SLIPIF 0 1175 | #endif 1176 | 1177 | /* 1178 | ------------------------------------ 1179 | ---------- Thread options ---------- 1180 | ------------------------------------ 1181 | */ 1182 | /** 1183 | * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread. 1184 | */ 1185 | #ifndef TCPIP_THREAD_NAME 1186 | #define TCPIP_THREAD_NAME "tcpip_thread" 1187 | #endif 1188 | 1189 | /** 1190 | * TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread. 1191 | * The stack size value itself is platform-dependent, but is passed to 1192 | * sys_thread_new() when the thread is created. 1193 | */ 1194 | #ifndef TCPIP_THREAD_STACKSIZE 1195 | #define TCPIP_THREAD_STACKSIZE 0 1196 | #endif 1197 | 1198 | /** 1199 | * TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread. 1200 | * The priority value itself is platform-dependent, but is passed to 1201 | * sys_thread_new() when the thread is created. 1202 | */ 1203 | #ifndef TCPIP_THREAD_PRIO 1204 | #define TCPIP_THREAD_PRIO 1 1205 | #endif 1206 | 1207 | /** 1208 | * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages 1209 | * The queue size value itself is platform-dependent, but is passed to 1210 | * sys_mbox_new() when tcpip_init is called. 1211 | */ 1212 | #ifndef TCPIP_MBOX_SIZE 1213 | #define TCPIP_MBOX_SIZE 0 1214 | #endif 1215 | 1216 | /** 1217 | * SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread. 1218 | */ 1219 | #ifndef SLIPIF_THREAD_NAME 1220 | #define SLIPIF_THREAD_NAME "slipif_loop" 1221 | #endif 1222 | 1223 | /** 1224 | * SLIP_THREAD_STACKSIZE: The stack size used by the slipif_loop thread. 1225 | * The stack size value itself is platform-dependent, but is passed to 1226 | * sys_thread_new() when the thread is created. 1227 | */ 1228 | #ifndef SLIPIF_THREAD_STACKSIZE 1229 | #define SLIPIF_THREAD_STACKSIZE 0 1230 | #endif 1231 | 1232 | /** 1233 | * SLIPIF_THREAD_PRIO: The priority assigned to the slipif_loop thread. 1234 | * The priority value itself is platform-dependent, but is passed to 1235 | * sys_thread_new() when the thread is created. 1236 | */ 1237 | #ifndef SLIPIF_THREAD_PRIO 1238 | #define SLIPIF_THREAD_PRIO 1 1239 | #endif 1240 | 1241 | /** 1242 | * PPP_THREAD_NAME: The name assigned to the pppInputThread. 1243 | */ 1244 | #ifndef PPP_THREAD_NAME 1245 | #define PPP_THREAD_NAME "pppInputThread" 1246 | #endif 1247 | 1248 | /** 1249 | * PPP_THREAD_STACKSIZE: The stack size used by the pppInputThread. 1250 | * The stack size value itself is platform-dependent, but is passed to 1251 | * sys_thread_new() when the thread is created. 1252 | */ 1253 | #ifndef PPP_THREAD_STACKSIZE 1254 | #define PPP_THREAD_STACKSIZE 0 1255 | #endif 1256 | 1257 | /** 1258 | * PPP_THREAD_PRIO: The priority assigned to the pppInputThread. 1259 | * The priority value itself is platform-dependent, but is passed to 1260 | * sys_thread_new() when the thread is created. 1261 | */ 1262 | #ifndef PPP_THREAD_PRIO 1263 | #define PPP_THREAD_PRIO 1 1264 | #endif 1265 | 1266 | /** 1267 | * DEFAULT_THREAD_NAME: The name assigned to any other lwIP thread. 1268 | */ 1269 | #ifndef DEFAULT_THREAD_NAME 1270 | #define DEFAULT_THREAD_NAME "lwIP" 1271 | #endif 1272 | 1273 | /** 1274 | * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread. 1275 | * The stack size value itself is platform-dependent, but is passed to 1276 | * sys_thread_new() when the thread is created. 1277 | */ 1278 | #ifndef DEFAULT_THREAD_STACKSIZE 1279 | #define DEFAULT_THREAD_STACKSIZE 0 1280 | #endif 1281 | 1282 | /** 1283 | * DEFAULT_THREAD_PRIO: The priority assigned to any other lwIP thread. 1284 | * The priority value itself is platform-dependent, but is passed to 1285 | * sys_thread_new() when the thread is created. 1286 | */ 1287 | #ifndef DEFAULT_THREAD_PRIO 1288 | #define DEFAULT_THREAD_PRIO 1 1289 | #endif 1290 | 1291 | /** 1292 | * DEFAULT_RAW_RECVMBOX_SIZE: The mailbox size for the incoming packets on a 1293 | * NETCONN_RAW. The queue size value itself is platform-dependent, but is passed 1294 | * to sys_mbox_new() when the recvmbox is created. 1295 | */ 1296 | #ifndef DEFAULT_RAW_RECVMBOX_SIZE 1297 | #define DEFAULT_RAW_RECVMBOX_SIZE 0 1298 | #endif 1299 | 1300 | /** 1301 | * DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a 1302 | * NETCONN_UDP. The queue size value itself is platform-dependent, but is passed 1303 | * to sys_mbox_new() when the recvmbox is created. 1304 | */ 1305 | #ifndef DEFAULT_UDP_RECVMBOX_SIZE 1306 | #define DEFAULT_UDP_RECVMBOX_SIZE 0 1307 | #endif 1308 | 1309 | /** 1310 | * DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a 1311 | * NETCONN_TCP. The queue size value itself is platform-dependent, but is passed 1312 | * to sys_mbox_new() when the recvmbox is created. 1313 | */ 1314 | #ifndef DEFAULT_TCP_RECVMBOX_SIZE 1315 | #define DEFAULT_TCP_RECVMBOX_SIZE 0 1316 | #endif 1317 | 1318 | /** 1319 | * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections. 1320 | * The queue size value itself is platform-dependent, but is passed to 1321 | * sys_mbox_new() when the acceptmbox is created. 1322 | */ 1323 | #ifndef DEFAULT_ACCEPTMBOX_SIZE 1324 | #define DEFAULT_ACCEPTMBOX_SIZE 0 1325 | #endif 1326 | 1327 | /* 1328 | ---------------------------------------------- 1329 | ---------- Sequential layer options ---------- 1330 | ---------------------------------------------- 1331 | */ 1332 | /** 1333 | * LWIP_TCPIP_CORE_LOCKING: (EXPERIMENTAL!) 1334 | * Don't use it if you're not an active lwIP project member 1335 | */ 1336 | #ifndef LWIP_TCPIP_CORE_LOCKING 1337 | #define LWIP_TCPIP_CORE_LOCKING 0 1338 | #endif 1339 | 1340 | /** 1341 | * LWIP_TCPIP_CORE_LOCKING_INPUT: (EXPERIMENTAL!) 1342 | * Don't use it if you're not an active lwIP project member 1343 | */ 1344 | #ifndef LWIP_TCPIP_CORE_LOCKING_INPUT 1345 | #define LWIP_TCPIP_CORE_LOCKING_INPUT 0 1346 | #endif 1347 | 1348 | /** 1349 | * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) 1350 | */ 1351 | #ifndef LWIP_NETCONN 1352 | #define LWIP_NETCONN 0 1353 | #endif 1354 | 1355 | /** LWIP_TCPIP_TIMEOUT==1: Enable tcpip_timeout/tcpip_untimeout tod create 1356 | * timers running in tcpip_thread from another thread. 1357 | */ 1358 | #ifndef LWIP_TCPIP_TIMEOUT 1359 | #define LWIP_TCPIP_TIMEOUT 1 1360 | #endif 1361 | 1362 | /* 1363 | ------------------------------------ 1364 | ---------- Socket options ---------- 1365 | ------------------------------------ 1366 | */ 1367 | /** 1368 | * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) 1369 | */ 1370 | #ifndef LWIP_SOCKET 1371 | #define LWIP_SOCKET 0 1372 | #endif 1373 | 1374 | /** 1375 | * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names. 1376 | * (only used if you use sockets.c) 1377 | */ 1378 | #ifndef LWIP_COMPAT_SOCKETS 1379 | #define LWIP_COMPAT_SOCKETS 0 1380 | #endif 1381 | 1382 | /** 1383 | * LWIP_POSIX_SOCKETS_IO_NAMES==1: Enable POSIX-style sockets functions names. 1384 | * Disable this option if you use a POSIX operating system that uses the same 1385 | * names (read, write & close). (only used if you use sockets.c) 1386 | */ 1387 | #ifndef LWIP_POSIX_SOCKETS_IO_NAMES 1388 | #define LWIP_POSIX_SOCKETS_IO_NAMES 0 1389 | #endif 1390 | 1391 | /** 1392 | * LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT 1393 | * options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set 1394 | * in seconds. (does not require sockets.c, and will affect tcp.c) 1395 | */ 1396 | #ifndef LWIP_TCP_KEEPALIVE 1397 | #define LWIP_TCP_KEEPALIVE 1 1398 | #endif 1399 | 1400 | /** 1401 | * LWIP_SO_RCVTIMEO==1: Enable SO_RCVTIMEO processing. 1402 | */ 1403 | #ifndef LWIP_SO_RCVTIMEO 1404 | #define LWIP_SO_RCVTIMEO 0 1405 | #endif 1406 | 1407 | /** 1408 | * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing. 1409 | */ 1410 | #ifndef LWIP_SO_RCVBUF 1411 | #define LWIP_SO_RCVBUF 0 1412 | #endif 1413 | 1414 | /** 1415 | * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize. 1416 | */ 1417 | #ifndef RECV_BUFSIZE_DEFAULT 1418 | #define RECV_BUFSIZE_DEFAULT INT_MAX 1419 | #endif 1420 | 1421 | /** 1422 | * SO_REUSE==1: Enable SO_REUSEADDR option. 1423 | */ 1424 | #ifndef SO_REUSE 1425 | #define SO_REUSE 0 1426 | #endif 1427 | 1428 | /** 1429 | * SO_REUSE_RXTOALL==1: Pass a copy of incoming broadcast/multicast packets 1430 | * to all local matches if SO_REUSEADDR is turned on. 1431 | * WARNING: Adds a memcpy for every packet if passing to more than one pcb! 1432 | */ 1433 | #ifndef SO_REUSE_RXTOALL 1434 | #define SO_REUSE_RXTOALL 0 1435 | #endif 1436 | 1437 | /* 1438 | ---------------------------------------- 1439 | ---------- Statistics options ---------- 1440 | ---------------------------------------- 1441 | */ 1442 | /** 1443 | * LWIP_STATS==1: Enable statistics collection in lwip_stats. 1444 | */ 1445 | #ifndef LWIP_STATS 1446 | #define LWIP_STATS 0 1447 | #endif 1448 | 1449 | #if LWIP_STATS 1450 | 1451 | /** 1452 | * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions. 1453 | */ 1454 | #ifndef LWIP_STATS_DISPLAY 1455 | #define LWIP_STATS_DISPLAY 0 1456 | #endif 1457 | 1458 | /** 1459 | * LINK_STATS==1: Enable link stats. 1460 | */ 1461 | #ifndef LINK_STATS 1462 | #define LINK_STATS 1 1463 | #endif 1464 | 1465 | /** 1466 | * ETHARP_STATS==1: Enable etharp stats. 1467 | */ 1468 | #ifndef ETHARP_STATS 1469 | #define ETHARP_STATS (LWIP_ARP) 1470 | #endif 1471 | 1472 | /** 1473 | * IP_STATS==1: Enable IP stats. 1474 | */ 1475 | #ifndef IP_STATS 1476 | #define IP_STATS 1 1477 | #endif 1478 | 1479 | /** 1480 | * IPFRAG_STATS==1: Enable IP fragmentation stats. Default is 1481 | * on if using either frag or reass. 1482 | */ 1483 | #ifndef IPFRAG_STATS 1484 | #define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG) 1485 | #endif 1486 | 1487 | /** 1488 | * ICMP_STATS==1: Enable ICMP stats. 1489 | */ 1490 | #ifndef ICMP_STATS 1491 | #define ICMP_STATS 1 1492 | #endif 1493 | 1494 | /** 1495 | * IGMP_STATS==1: Enable IGMP stats. 1496 | */ 1497 | #ifndef IGMP_STATS 1498 | #define IGMP_STATS (LWIP_IGMP) 1499 | #endif 1500 | 1501 | /** 1502 | * UDP_STATS==1: Enable UDP stats. Default is on if 1503 | * UDP enabled, otherwise off. 1504 | */ 1505 | #ifndef UDP_STATS 1506 | #define UDP_STATS (LWIP_UDP) 1507 | #endif 1508 | 1509 | /** 1510 | * TCP_STATS==1: Enable TCP stats. Default is on if TCP 1511 | * enabled, otherwise off. 1512 | */ 1513 | #ifndef TCP_STATS 1514 | #define TCP_STATS (LWIP_TCP) 1515 | #endif 1516 | 1517 | /** 1518 | * MEM_STATS==1: Enable mem.c stats. 1519 | */ 1520 | #ifndef MEM_STATS 1521 | #define MEM_STATS ((MEM_LIBC_MALLOC == 0) && (MEM_USE_POOLS == 0)) 1522 | #endif 1523 | 1524 | /** 1525 | * MEMP_STATS==1: Enable memp.c pool stats. 1526 | */ 1527 | #ifndef MEMP_STATS 1528 | #define MEMP_STATS (MEMP_MEM_MALLOC == 0) 1529 | #endif 1530 | 1531 | /** 1532 | * SYS_STATS==1: Enable system stats (sem and mbox counts, etc). 1533 | */ 1534 | #ifndef SYS_STATS 1535 | #define SYS_STATS (NO_SYS == 0) 1536 | #endif 1537 | 1538 | #else 1539 | #define ETHARP_STATS 0 1540 | #define LINK_STATS 0 1541 | #define IP_STATS 0 1542 | #define IPFRAG_STATS 0 1543 | #define ICMP_STATS 0 1544 | #define IGMP_STATS 0 1545 | #define UDP_STATS 0 1546 | #define TCP_STATS 0 1547 | #define MEM_STATS 0 1548 | #define MEMP_STATS 0 1549 | #define SYS_STATS 0 1550 | #define LWIP_STATS_DISPLAY 0 1551 | 1552 | #endif /* LWIP_STATS */ 1553 | 1554 | /* 1555 | --------------------------------- 1556 | ---------- PPP options ---------- 1557 | --------------------------------- 1558 | */ 1559 | /** 1560 | * PPP_SUPPORT==1: Enable PPP. 1561 | */ 1562 | #ifndef PPP_SUPPORT 1563 | #define PPP_SUPPORT 0 1564 | #endif 1565 | 1566 | /** 1567 | * PPPOE_SUPPORT==1: Enable PPP Over Ethernet 1568 | */ 1569 | #ifndef PPPOE_SUPPORT 1570 | #define PPPOE_SUPPORT 0 1571 | #endif 1572 | 1573 | /** 1574 | * PPPOS_SUPPORT==1: Enable PPP Over Serial 1575 | */ 1576 | #ifndef PPPOS_SUPPORT 1577 | #define PPPOS_SUPPORT PPP_SUPPORT 1578 | #endif 1579 | 1580 | #if PPP_SUPPORT 1581 | 1582 | /** 1583 | * NUM_PPP: Max PPP sessions. 1584 | */ 1585 | #ifndef NUM_PPP 1586 | #define NUM_PPP 1 1587 | #endif 1588 | 1589 | /** 1590 | * PAP_SUPPORT==1: Support PAP. 1591 | */ 1592 | #ifndef PAP_SUPPORT 1593 | #define PAP_SUPPORT 0 1594 | #endif 1595 | 1596 | /** 1597 | * CHAP_SUPPORT==1: Support CHAP. 1598 | */ 1599 | #ifndef CHAP_SUPPORT 1600 | #define CHAP_SUPPORT 0 1601 | #endif 1602 | 1603 | /** 1604 | * MSCHAP_SUPPORT==1: Support MSCHAP. CURRENTLY NOT SUPPORTED! DO NOT SET! 1605 | */ 1606 | #ifndef MSCHAP_SUPPORT 1607 | #define MSCHAP_SUPPORT 0 1608 | #endif 1609 | 1610 | /** 1611 | * CBCP_SUPPORT==1: Support CBCP. CURRENTLY NOT SUPPORTED! DO NOT SET! 1612 | */ 1613 | #ifndef CBCP_SUPPORT 1614 | #define CBCP_SUPPORT 0 1615 | #endif 1616 | 1617 | /** 1618 | * CCP_SUPPORT==1: Support CCP. CURRENTLY NOT SUPPORTED! DO NOT SET! 1619 | */ 1620 | #ifndef CCP_SUPPORT 1621 | #define CCP_SUPPORT 0 1622 | #endif 1623 | 1624 | /** 1625 | * VJ_SUPPORT==1: Support VJ header compression. 1626 | */ 1627 | #ifndef VJ_SUPPORT 1628 | #define VJ_SUPPORT 0 1629 | #endif 1630 | 1631 | /** 1632 | * MD5_SUPPORT==1: Support MD5 (see also CHAP). 1633 | */ 1634 | #ifndef MD5_SUPPORT 1635 | #define MD5_SUPPORT 0 1636 | #endif 1637 | 1638 | /* 1639 | * Timeouts 1640 | */ 1641 | #ifndef FSM_DEFTIMEOUT 1642 | #define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */ 1643 | #endif 1644 | 1645 | #ifndef FSM_DEFMAXTERMREQS 1646 | #define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ 1647 | #endif 1648 | 1649 | #ifndef FSM_DEFMAXCONFREQS 1650 | #define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ 1651 | #endif 1652 | 1653 | #ifndef FSM_DEFMAXNAKLOOPS 1654 | #define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ 1655 | #endif 1656 | 1657 | #ifndef UPAP_DEFTIMEOUT 1658 | #define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */ 1659 | #endif 1660 | 1661 | #ifndef UPAP_DEFREQTIME 1662 | #define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ 1663 | #endif 1664 | 1665 | #ifndef CHAP_DEFTIMEOUT 1666 | #define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */ 1667 | #endif 1668 | 1669 | #ifndef CHAP_DEFTRANSMITS 1670 | #define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */ 1671 | #endif 1672 | 1673 | /* Interval in seconds between keepalive echo requests, 0 to disable. */ 1674 | #ifndef LCP_ECHOINTERVAL 1675 | #define LCP_ECHOINTERVAL 0 1676 | #endif 1677 | 1678 | /* Number of unanswered echo requests before failure. */ 1679 | #ifndef LCP_MAXECHOFAILS 1680 | #define LCP_MAXECHOFAILS 3 1681 | #endif 1682 | 1683 | /* Max Xmit idle time (in jiffies) before resend flag char. */ 1684 | #ifndef PPP_MAXIDLEFLAG 1685 | #define PPP_MAXIDLEFLAG 100 1686 | #endif 1687 | 1688 | /* 1689 | * Packet sizes 1690 | * 1691 | * Note - lcp shouldn't be allowed to negotiate stuff outside these 1692 | * limits. See lcp.h in the pppd directory. 1693 | * (XXX - these constants should simply be shared by lcp.c instead 1694 | * of living in lcp.h) 1695 | */ 1696 | #define PPP_MTU 1500 /* Default MTU (size of Info field) */ 1697 | #ifndef PPP_MAXMTU 1698 | /* #define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN) */ 1699 | #define PPP_MAXMTU 1500 /* Largest MTU we allow */ 1700 | #endif 1701 | #define PPP_MINMTU 64 1702 | #define PPP_MRU 1500 /* default MRU = max length of info field */ 1703 | #define PPP_MAXMRU 1500 /* Largest MRU we allow */ 1704 | #ifndef PPP_DEFMRU 1705 | #define PPP_DEFMRU 296 /* Try for this */ 1706 | #endif 1707 | #define PPP_MINMRU 128 /* No MRUs below this */ 1708 | 1709 | #ifndef MAXNAMELEN 1710 | #define MAXNAMELEN 256 /* max length of hostname or name for auth */ 1711 | #endif 1712 | #ifndef MAXSECRETLEN 1713 | #define MAXSECRETLEN 256 /* max length of password or secret */ 1714 | #endif 1715 | 1716 | #endif /* PPP_SUPPORT */ 1717 | 1718 | /* 1719 | -------------------------------------- 1720 | ---------- Checksum options ---------- 1721 | -------------------------------------- 1722 | */ 1723 | /** 1724 | * CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets. 1725 | */ 1726 | #ifndef CHECKSUM_GEN_IP 1727 | #define CHECKSUM_GEN_IP 1 1728 | #endif 1729 | 1730 | /** 1731 | * CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets. 1732 | */ 1733 | #ifndef CHECKSUM_GEN_UDP 1734 | #define CHECKSUM_GEN_UDP 1 1735 | #endif 1736 | 1737 | /** 1738 | * CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets. 1739 | */ 1740 | #ifndef CHECKSUM_GEN_TCP 1741 | #define CHECKSUM_GEN_TCP 1 1742 | #endif 1743 | 1744 | /** 1745 | * CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets. 1746 | */ 1747 | #ifndef CHECKSUM_CHECK_IP 1748 | #define CHECKSUM_CHECK_IP 1 1749 | #endif 1750 | 1751 | /** 1752 | * CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets. 1753 | */ 1754 | #ifndef CHECKSUM_CHECK_UDP 1755 | #define CHECKSUM_CHECK_UDP 1 1756 | #endif 1757 | 1758 | /** 1759 | * CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets. 1760 | */ 1761 | #ifndef CHECKSUM_CHECK_TCP 1762 | #define CHECKSUM_CHECK_TCP 1 1763 | #endif 1764 | 1765 | /** 1766 | * LWIP_CHECKSUM_ON_COPY==1: Calculate checksum when copying data from 1767 | * application buffers to pbufs. 1768 | */ 1769 | #ifndef LWIP_CHECKSUM_ON_COPY 1770 | #define LWIP_CHECKSUM_ON_COPY 0 1771 | #endif 1772 | 1773 | /* 1774 | --------------------------------------- 1775 | ---------- Debugging options ---------- 1776 | --------------------------------------- 1777 | */ 1778 | /** 1779 | * LWIP_DBG_MIN_LEVEL: After masking, the value of the debug is 1780 | * compared against this value. If it is smaller, then debugging 1781 | * messages are written. 1782 | */ 1783 | #ifndef LWIP_DBG_MIN_LEVEL 1784 | #define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL 1785 | #endif 1786 | 1787 | /** 1788 | * LWIP_DBG_TYPES_ON: A mask that can be used to globally enable/disable 1789 | * debug messages of certain types. 1790 | */ 1791 | #ifndef LWIP_DBG_TYPES_ON 1792 | #define LWIP_DBG_TYPES_ON LWIP_DBG_OFF 1793 | #endif 1794 | 1795 | /** 1796 | * ETHARP_DEBUG: Enable debugging in etharp.c. 1797 | */ 1798 | #ifndef ETHARP_DEBUG 1799 | #define ETHARP_DEBUG LWIP_DBG_OFF 1800 | #endif 1801 | 1802 | /** 1803 | * NETIF_DEBUG: Enable debugging in netif.c. 1804 | */ 1805 | #ifndef NETIF_DEBUG 1806 | #define NETIF_DEBUG LWIP_DBG_OFF 1807 | #endif 1808 | 1809 | /** 1810 | * PBUF_DEBUG: Enable debugging in pbuf.c. 1811 | */ 1812 | #ifndef PBUF_DEBUG 1813 | #define PBUF_DEBUG LWIP_DBG_OFF 1814 | #endif 1815 | 1816 | /** 1817 | * API_LIB_DEBUG: Enable debugging in api_lib.c. 1818 | */ 1819 | #ifndef API_LIB_DEBUG 1820 | #define API_LIB_DEBUG LWIP_DBG_OFF 1821 | #endif 1822 | 1823 | /** 1824 | * API_MSG_DEBUG: Enable debugging in api_msg.c. 1825 | */ 1826 | #ifndef API_MSG_DEBUG 1827 | #define API_MSG_DEBUG LWIP_DBG_OFF 1828 | #endif 1829 | 1830 | /** 1831 | * SOCKETS_DEBUG: Enable debugging in sockets.c. 1832 | */ 1833 | #ifndef SOCKETS_DEBUG 1834 | #define SOCKETS_DEBUG LWIP_DBG_OFF 1835 | #endif 1836 | 1837 | /** 1838 | * ICMP_DEBUG: Enable debugging in icmp.c. 1839 | */ 1840 | #ifndef ICMP_DEBUG 1841 | #define ICMP_DEBUG LWIP_DBG_OFF 1842 | #endif 1843 | 1844 | /** 1845 | * IGMP_DEBUG: Enable debugging in igmp.c. 1846 | */ 1847 | #ifndef IGMP_DEBUG 1848 | #define IGMP_DEBUG LWIP_DBG_OFF 1849 | #endif 1850 | 1851 | /** 1852 | * INET_DEBUG: Enable debugging in inet.c. 1853 | */ 1854 | #ifndef INET_DEBUG 1855 | #define INET_DEBUG LWIP_DBG_OFF 1856 | #endif 1857 | 1858 | /** 1859 | * IP_DEBUG: Enable debugging for IP. 1860 | */ 1861 | #ifndef IP_DEBUG 1862 | #define IP_DEBUG LWIP_DBG_OFF 1863 | #endif 1864 | 1865 | /** 1866 | * IP_REASS_DEBUG: Enable debugging in ip_frag.c for both frag & reass. 1867 | */ 1868 | #ifndef IP_REASS_DEBUG 1869 | #define IP_REASS_DEBUG LWIP_DBG_OFF 1870 | #endif 1871 | 1872 | /** 1873 | * RAW_DEBUG: Enable debugging in raw.c. 1874 | */ 1875 | #ifndef RAW_DEBUG 1876 | #define RAW_DEBUG LWIP_DBG_OFF 1877 | #endif 1878 | 1879 | /** 1880 | * MEM_DEBUG: Enable debugging in mem.c. 1881 | */ 1882 | #ifndef MEM_DEBUG 1883 | #define MEM_DEBUG LWIP_DBG_OFF 1884 | #endif 1885 | 1886 | /** 1887 | * MEMP_DEBUG: Enable debugging in memp.c. 1888 | */ 1889 | #ifndef MEMP_DEBUG 1890 | #define MEMP_DEBUG LWIP_DBG_OFF 1891 | #endif 1892 | 1893 | /** 1894 | * SYS_DEBUG: Enable debugging in sys.c. 1895 | */ 1896 | #ifndef SYS_DEBUG 1897 | #define SYS_DEBUG LWIP_DBG_OFF 1898 | #endif 1899 | 1900 | /** 1901 | * TIMERS_DEBUG: Enable debugging in timers.c. 1902 | */ 1903 | #ifndef TIMERS_DEBUG 1904 | #define TIMERS_DEBUG LWIP_DBG_OFF 1905 | #endif 1906 | 1907 | /** 1908 | * TCP_DEBUG: Enable debugging for TCP. 1909 | */ 1910 | #ifndef TCP_DEBUG 1911 | #define TCP_DEBUG LWIP_DBG_OFF 1912 | #endif 1913 | 1914 | /** 1915 | * TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug. 1916 | */ 1917 | #ifndef TCP_INPUT_DEBUG 1918 | #define TCP_INPUT_DEBUG LWIP_DBG_OFF 1919 | #endif 1920 | 1921 | /** 1922 | * TCP_FR_DEBUG: Enable debugging in tcp_in.c for fast retransmit. 1923 | */ 1924 | #ifndef TCP_FR_DEBUG 1925 | #define TCP_FR_DEBUG LWIP_DBG_OFF 1926 | #endif 1927 | 1928 | /** 1929 | * TCP_RTO_DEBUG: Enable debugging in TCP for retransmit 1930 | * timeout. 1931 | */ 1932 | #ifndef TCP_RTO_DEBUG 1933 | #define TCP_RTO_DEBUG LWIP_DBG_OFF 1934 | #endif 1935 | 1936 | /** 1937 | * TCP_CWND_DEBUG: Enable debugging for TCP congestion window. 1938 | */ 1939 | #ifndef TCP_CWND_DEBUG 1940 | #define TCP_CWND_DEBUG LWIP_DBG_OFF 1941 | #endif 1942 | 1943 | /** 1944 | * TCP_WND_DEBUG: Enable debugging in tcp_in.c for window updating. 1945 | */ 1946 | #ifndef TCP_WND_DEBUG 1947 | #define TCP_WND_DEBUG LWIP_DBG_OFF 1948 | #endif 1949 | 1950 | /** 1951 | * TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions. 1952 | */ 1953 | #ifndef TCP_OUTPUT_DEBUG 1954 | #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF 1955 | #endif 1956 | 1957 | /** 1958 | * TCP_RST_DEBUG: Enable debugging for TCP with the RST message. 1959 | */ 1960 | #ifndef TCP_RST_DEBUG 1961 | #define TCP_RST_DEBUG LWIP_DBG_OFF 1962 | #endif 1963 | 1964 | /** 1965 | * TCP_QLEN_DEBUG: Enable debugging for TCP queue lengths. 1966 | */ 1967 | #ifndef TCP_QLEN_DEBUG 1968 | #define TCP_QLEN_DEBUG LWIP_DBG_OFF 1969 | #endif 1970 | 1971 | /** 1972 | * UDP_DEBUG: Enable debugging in UDP. 1973 | */ 1974 | #ifndef UDP_DEBUG 1975 | #define UDP_DEBUG LWIP_DBG_OFF 1976 | #endif 1977 | 1978 | /** 1979 | * TCPIP_DEBUG: Enable debugging in tcpip.c. 1980 | */ 1981 | #ifndef TCPIP_DEBUG 1982 | #define TCPIP_DEBUG LWIP_DBG_OFF 1983 | #endif 1984 | 1985 | /** 1986 | * PPP_DEBUG: Enable debugging for PPP. 1987 | */ 1988 | #ifndef PPP_DEBUG 1989 | #define PPP_DEBUG LWIP_DBG_OFF 1990 | #endif 1991 | 1992 | /** 1993 | * SLIP_DEBUG: Enable debugging in slipif.c. 1994 | */ 1995 | #ifndef SLIP_DEBUG 1996 | #define SLIP_DEBUG LWIP_DBG_OFF 1997 | #endif 1998 | 1999 | /** 2000 | * DHCP_DEBUG: Enable debugging in dhcp.c. 2001 | */ 2002 | #ifndef DHCP_DEBUG 2003 | #define DHCP_DEBUG LWIP_DBG_OFF 2004 | #endif 2005 | 2006 | /** 2007 | * AUTOIP_DEBUG: Enable debugging in autoip.c. 2008 | */ 2009 | #ifndef AUTOIP_DEBUG 2010 | #define AUTOIP_DEBUG LWIP_DBG_OFF 2011 | #endif 2012 | 2013 | /** 2014 | * SNMP_MSG_DEBUG: Enable debugging for SNMP messages. 2015 | */ 2016 | #ifndef SNMP_MSG_DEBUG 2017 | #define SNMP_MSG_DEBUG LWIP_DBG_OFF 2018 | #endif 2019 | 2020 | /** 2021 | * SNMP_MIB_DEBUG: Enable debugging for SNMP MIBs. 2022 | */ 2023 | #ifndef SNMP_MIB_DEBUG 2024 | #define SNMP_MIB_DEBUG LWIP_DBG_OFF 2025 | #endif 2026 | 2027 | /** 2028 | * DNS_DEBUG: Enable debugging for DNS. 2029 | */ 2030 | #ifndef DNS_DEBUG 2031 | #define DNS_DEBUG LWIP_DBG_OFF 2032 | #endif 2033 | 2034 | #include "espmissingincludes.h" 2035 | 2036 | 2037 | #endif /* __LWIP_OPT_H__ */ 2038 | -------------------------------------------------------------------------------- /include/mem_manager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dangrie158/ESP-8266-WebSocket/68246177100c445ad11c4ce9ff7898ee6f5f0676/include/mem_manager.h -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /include/user_config.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /user/base64.c: -------------------------------------------------------------------------------- 1 | /* base64.c : base-64 / MIME encode/decode */ 2 | /* PUBLIC DOMAIN - Jon Mayo - November 13, 2003 */ 3 | #include "c_types.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "base64.h" 9 | 10 | static const uint8_t base64dec_tab[256]= { 11 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 12 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 13 | 255,255,255,255,255,255,255,255,255,255,255, 62,255,255,255, 63, 14 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255, 0,255,255, 15 | 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255, 17 | 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 18 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,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 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 24 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 25 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 26 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 27 | }; 28 | 29 | #if 0 30 | static int ICACHE_FLASH_ATTR base64decode(const char in[4], char out[3]) { 31 | uint8_t v[4]; 32 | 33 | v[0]=base64dec_tab[(unsigned)in[0]]; 34 | v[1]=base64dec_tab[(unsigned)in[1]]; 35 | v[2]=base64dec_tab[(unsigned)in[2]]; 36 | v[3]=base64dec_tab[(unsigned)in[3]]; 37 | 38 | out[0]=(v[0]<<2)|(v[1]>>4); 39 | out[1]=(v[1]<<4)|(v[2]>>2); 40 | out[2]=(v[2]<<6)|(v[3]); 41 | return (v[0]|v[1]|v[2]|v[3])!=255 ? in[3]=='=' ? in[2]=='=' ? 1 : 2 : 3 : 0; 42 | } 43 | #endif 44 | 45 | /* decode a base64 string in one shot */ 46 | int ICACHE_FLASH_ATTR base64_decode(size_t in_len, const char *in, size_t out_len, unsigned char *out) { 47 | unsigned int ii, io; 48 | uint32_t v; 49 | unsigned int rem; 50 | 51 | for(io=0,ii=0,v=0,rem=0;ii=8) { 60 | rem-=8; 61 | if(io>=out_len) return -1; /* truncation is failure */ 62 | out[io++]=(v>>rem)&255; 63 | } 64 | } 65 | if(rem>=8) { 66 | rem-=8; 67 | if(io>=out_len) return -1; /* truncation is failure */ 68 | out[io++]=(v>>rem)&255; 69 | } 70 | return io; 71 | } 72 | 73 | static const uint8_t base64enc_tab[64]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 74 | 75 | void base64encode(const unsigned char in[3], unsigned char out[4], int count) { 76 | out[0]=base64enc_tab[(in[0]>>2)]; 77 | out[1]=base64enc_tab[((in[0]&3)<<4)|(in[1]>>4)]; 78 | out[2]=count<2 ? '=' : base64enc_tab[((in[1]&15)<<2)|(in[2]>>6)]; 79 | out[3]=count<3 ? '=' : base64enc_tab[(in[2]&63)]; 80 | } 81 | 82 | 83 | int base64_encode(size_t in_len, const unsigned char *in, size_t out_len, char *out) { 84 | unsigned ii, io; 85 | uint_least32_t v; 86 | unsigned rem; 87 | 88 | for(io=0,ii=0,v=0,rem=0;ii=6) { 94 | rem-=6; 95 | if(io>=out_len) return -1; /* truncation is failure */ 96 | out[io++]=base64enc_tab[(v>>rem)&63]; 97 | } 98 | } 99 | if(rem) { 100 | v<<=(6-rem); 101 | if(io>=out_len) return -1; /* truncation is failure */ 102 | out[io++]=base64enc_tab[v&63]; 103 | } 104 | while(io&3) { 105 | if(io>=out_len) return -1; /* truncation is failure */ 106 | out[io++]='='; 107 | } 108 | if(io>=out_len) return -1; /* no room for null terminator */ 109 | out[io]=0; 110 | return io; 111 | } -------------------------------------------------------------------------------- /user/base64.h: -------------------------------------------------------------------------------- 1 | int base64_decode(size_t in_len, const char *in, size_t out_len, unsigned char *out); 2 | int base64_encode(size_t in_len, const unsigned char *in, size_t out_len, char *out); -------------------------------------------------------------------------------- /user/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 | 9 | #include "sha1.h" 10 | 11 | //according to http://ip.cadence.com/uploads/pdf/xtensalx_overview_handbook.pdf 12 | // the cpu is normally defined as little ending, but can be big endian too. 13 | // for the esp this seems to work 14 | //#define SHA_BIG_ENDIAN 15 | 16 | 17 | 18 | /* code */ 19 | #define SHA1_K0 0x5a827999 20 | #define SHA1_K20 0x6ed9eba1 21 | #define SHA1_K40 0x8f1bbcdc 22 | #define SHA1_K60 0xca62c1d6 23 | 24 | void sha1_init(sha1nfo *s) { 25 | s->state[0] = 0x67452301; 26 | s->state[1] = 0xefcdab89; 27 | s->state[2] = 0x98badcfe; 28 | s->state[3] = 0x10325476; 29 | s->state[4] = 0xc3d2e1f0; 30 | s->byteCount = 0; 31 | s->bufferOffset = 0; 32 | } 33 | 34 | uint32_t sha1_rol32(uint32_t number, uint8_t bits) { 35 | return ((number << bits) | (number >> (32-bits))); 36 | } 37 | 38 | void sha1_hashBlock(sha1nfo *s) { 39 | uint8_t i; 40 | uint32_t a,b,c,d,e,t; 41 | 42 | a=s->state[0]; 43 | b=s->state[1]; 44 | c=s->state[2]; 45 | d=s->state[3]; 46 | e=s->state[4]; 47 | for (i=0; i<80; i++) { 48 | if (i>=16) { 49 | t = s->buffer[(i+13)&15] ^ s->buffer[(i+8)&15] ^ s->buffer[(i+2)&15] ^ s->buffer[i&15]; 50 | s->buffer[i&15] = sha1_rol32(t,1); 51 | } 52 | if (i<20) { 53 | t = (d ^ (b & (c ^ d))) + SHA1_K0; 54 | } else if (i<40) { 55 | t = (b ^ c ^ d) + SHA1_K20; 56 | } else if (i<60) { 57 | t = ((b & c) | (d & (b | c))) + SHA1_K40; 58 | } else { 59 | t = (b ^ c ^ d) + SHA1_K60; 60 | } 61 | t+=sha1_rol32(a,5) + e + s->buffer[i&15]; 62 | e=d; 63 | d=c; 64 | c=sha1_rol32(b,30); 65 | b=a; 66 | a=t; 67 | } 68 | s->state[0] += a; 69 | s->state[1] += b; 70 | s->state[2] += c; 71 | s->state[3] += d; 72 | s->state[4] += e; 73 | } 74 | 75 | void sha1_addUncounted(sha1nfo *s, uint8_t data) { 76 | uint8_t * const b = (uint8_t*) s->buffer; 77 | #ifdef SHA_BIG_ENDIAN 78 | b[s->bufferOffset] = data; 79 | #else 80 | b[s->bufferOffset ^ 3] = data; 81 | #endif 82 | s->bufferOffset++; 83 | if (s->bufferOffset == BLOCK_LENGTH) { 84 | sha1_hashBlock(s); 85 | s->bufferOffset = 0; 86 | } 87 | } 88 | 89 | void sha1_writebyte(sha1nfo *s, uint8_t data) { 90 | ++s->byteCount; 91 | sha1_addUncounted(s, data); 92 | } 93 | 94 | void sha1_write(sha1nfo *s, const char *data, size_t len) { 95 | for (;len--;) sha1_writebyte(s, (uint8_t) *data++); 96 | } 97 | 98 | void sha1_pad(sha1nfo *s) { 99 | // Implement SHA-1 padding (fips180-2 §5.1.1) 100 | 101 | // Pad with 0x80 followed by 0x00 until the end of the block 102 | sha1_addUncounted(s, 0x80); 103 | while (s->bufferOffset != 56) sha1_addUncounted(s, 0x00); 104 | 105 | // Append length in the last 8 bytes 106 | sha1_addUncounted(s, 0); // We're only using 32 bit lengths 107 | sha1_addUncounted(s, 0); // But SHA-1 supports 64 bit lengths 108 | sha1_addUncounted(s, 0); // So zero pad the top bits 109 | sha1_addUncounted(s, s->byteCount >> 29); // Shifting to multiply by 8 110 | sha1_addUncounted(s, s->byteCount >> 21); // as SHA-1 supports bitstreams as well as 111 | sha1_addUncounted(s, s->byteCount >> 13); // byte. 112 | sha1_addUncounted(s, s->byteCount >> 5); 113 | sha1_addUncounted(s, s->byteCount << 3); 114 | } 115 | 116 | uint8_t* sha1_result(sha1nfo *s) { 117 | // Pad to complete the last block 118 | sha1_pad(s); 119 | 120 | #ifndef SHA_BIG_ENDIAN 121 | // Swap byte order back 122 | int i; 123 | for (i=0; i<5; i++) { 124 | s->state[i]= 125 | (((s->state[i])<<24)& 0xff000000) 126 | | (((s->state[i])<<8) & 0x00ff0000) 127 | | (((s->state[i])>>8) & 0x0000ff00) 128 | | (((s->state[i])>>24)& 0x000000ff); 129 | } 130 | #endif 131 | 132 | // Return pointer to hash (20 characters) 133 | return (uint8_t*) s->state; 134 | } 135 | 136 | #define HMAC_IPAD 0x36 137 | #define HMAC_OPAD 0x5c 138 | 139 | void sha1_initHmac(sha1nfo *s, const uint8_t* key, int keyLength) { 140 | uint8_t i; 141 | memset(s->keyBuffer, 0, BLOCK_LENGTH); 142 | if (keyLength > BLOCK_LENGTH) { 143 | // Hash long keys 144 | sha1_init(s); 145 | for (;keyLength--;) sha1_writebyte(s, *key++); 146 | memcpy(s->keyBuffer, sha1_result(s), HASH_LENGTH); 147 | } else { 148 | // Block length keys are used as is 149 | memcpy(s->keyBuffer, key, keyLength); 150 | } 151 | // Start inner hash 152 | sha1_init(s); 153 | for (i=0; ikeyBuffer[i] ^ HMAC_IPAD); 155 | } 156 | } 157 | 158 | uint8_t* sha1_resultHmac(sha1nfo *s) { 159 | uint8_t i; 160 | // Complete inner hash 161 | memcpy(s->innerHash,sha1_result(s),HASH_LENGTH); 162 | // Calculate outer hash 163 | sha1_init(s); 164 | for (i=0; ikeyBuffer[i] ^ HMAC_OPAD); 165 | for (i=0; iinnerHash[i]); 166 | return sha1_result(s); 167 | } -------------------------------------------------------------------------------- /user/sha1.h: -------------------------------------------------------------------------------- 1 | /* header */ 2 | 3 | #define HASH_LENGTH 20 4 | #define BLOCK_LENGTH 64 5 | 6 | typedef struct sha1nfo { 7 | uint32_t buffer[BLOCK_LENGTH/4]; 8 | uint32_t state[HASH_LENGTH/4]; 9 | uint32_t byteCount; 10 | uint8_t bufferOffset; 11 | uint8_t keyBuffer[BLOCK_LENGTH]; 12 | uint8_t innerHash[HASH_LENGTH]; 13 | } sha1nfo; 14 | 15 | /* public API - prototypes - TODO: doxygen*/ 16 | 17 | /** 18 | */ 19 | void sha1_init(sha1nfo *s); 20 | /** 21 | */ 22 | void sha1_writebyte(sha1nfo *s, uint8_t data); 23 | /** 24 | */ 25 | void sha1_write(sha1nfo *s, const char *data, size_t len); 26 | /** 27 | */ 28 | uint8_t* sha1_result(sha1nfo *s); 29 | /** 30 | */ 31 | void sha1_initHmac(sha1nfo *s, const uint8_t* key, int keyLength); 32 | /** 33 | */ 34 | uint8_t* sha1_resultHmac(sha1nfo *s); 35 | 36 | -------------------------------------------------------------------------------- /user/uart.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: uart.c 5 | * 6 | * Description: Two UART mode configration and interrupt handler. 7 | * Check your hardware connection while use this mode. 8 | * 9 | * Modification history: 10 | * 2014/3/12, v1.0 create this file. 11 | *******************************************************************************/ 12 | #include "ets_sys.h" 13 | #include "osapi.h" 14 | #include "gpio.h" 15 | #include "os_type.h" 16 | #include "user_interface.h" 17 | #include "uart.h" 18 | #include "espmissingincludes.h" 19 | 20 | #define UART0 0 21 | 22 | // UartDev is defined and initialized in rom code. 23 | extern UartDevice UartDev; 24 | 25 | LOCAL void uart0_rx_intr_handler(void *para); 26 | 27 | /****************************************************************************** 28 | * FunctionName : uart_config 29 | * Description : Internal used function 30 | * UART0 used for data TX/RX, RX buffer size is 0x100, interrupt enabled 31 | * UART1 just used for debug output 32 | * Parameters : uart_no, use UART0 or UART1 defined ahead 33 | * Returns : NONE 34 | *******************************************************************************/ 35 | LOCAL void ICACHE_FLASH_ATTR 36 | uart_config() 37 | { 38 | /* rcv_buff size if 0x100 */ 39 | ETS_UART_INTR_ATTACH(uart0_rx_intr_handler, &(UartDev.rcv_buff)); 40 | PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); 41 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); 42 | 43 | uart_div_modify(UART0, UART_CLK_FREQ / BIT_RATE_9600); 44 | 45 | WRITE_PERI_REG(UART_CONF0(UART0), (STICK_PARITY_DIS)|(ONE_STOP_BIT << UART_STOP_BIT_NUM_S)| \ 46 | (EIGHT_BITS << UART_BIT_NUM_S)); 47 | 48 | 49 | //clear rx and tx fifo,not ready 50 | SET_PERI_REG_MASK(UART_CONF0(UART0), UART_RXFIFO_RST | UART_TXFIFO_RST); 51 | CLEAR_PERI_REG_MASK(UART_CONF0(UART0), UART_RXFIFO_RST | UART_TXFIFO_RST); 52 | 53 | //set rx fifo trigger 54 | WRITE_PERI_REG(UART_CONF1(0), (UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S); 55 | 56 | //clear all interrupt 57 | WRITE_PERI_REG(UART_INT_CLR(0), 0xffff); 58 | //enable rx_interrupt 59 | SET_PERI_REG_MASK(UART_INT_ENA(0), UART_RXFIFO_FULL_INT_ENA); 60 | } 61 | 62 | /****************************************************************************** 63 | * FunctionName : uart1_tx_one_char 64 | * Description : Internal used function 65 | * Use uart1 interface to transfer one char 66 | * Parameters : uint8 TxChar - character to tx 67 | * Returns : OK 68 | *******************************************************************************/ 69 | void ICACHE_FLASH_ATTR stdoutUartTxd(char c) { 70 | //Wait until there is room in the FIFO 71 | while (((READ_PERI_REG(UART_STATUS(0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=126) ; 72 | //Send the character 73 | WRITE_PERI_REG(UART_FIFO(0), c); 74 | } 75 | 76 | void ICACHE_FLASH_ATTR stdoutPutchar(char c) { 77 | //convert \n -> \r\n 78 | if (c=='\n') stdoutUartTxd('\r'); 79 | stdoutUartTxd(c); 80 | } 81 | 82 | /****************************************************************************** 83 | * FunctionName : uart0_rx_intr_handler 84 | * Description : Internal used function 85 | * UART0 interrupt handler, add self handle code inside 86 | * Parameters : void *para - point to ETS_UART_INTR_ATTACH's arg 87 | * Returns : NONE 88 | *******************************************************************************/ 89 | LOCAL void 90 | uart0_rx_intr_handler(void *para) 91 | { 92 | /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents 93 | * uart1 and uart0 respectively 94 | */ 95 | RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para; 96 | uint8 RcvChar; 97 | 98 | if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) { 99 | return; 100 | } 101 | 102 | WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR); 103 | 104 | while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) { 105 | RcvChar = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF; 106 | 107 | /* you can add your handle code below.*/ 108 | 109 | *(pRxBuff->pWritePos) = RcvChar; 110 | 111 | // insert here for get one command line from uart 112 | if (RcvChar == '\r') { 113 | pRxBuff->BuffState = WRITE_OVER; 114 | } 115 | 116 | pRxBuff->pWritePos++; 117 | 118 | // if we hit the end of the buffer, loop back to the beginning 119 | if (pRxBuff->pWritePos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE)) { 120 | // overflow ...we may need more error handle here. 121 | pRxBuff->pWritePos = pRxBuff->pRcvMsgBuff ; 122 | } 123 | } 124 | } 125 | 126 | ICACHE_FLASH_ATTR int uart0_rx_one_char() { 127 | if(UartDev.rcv_buff.pReadPos == UartDev.rcv_buff.pWritePos) return -1; 128 | int ret = *UartDev.rcv_buff.pReadPos; 129 | UartDev.rcv_buff.pReadPos++; 130 | if(UartDev.rcv_buff.pReadPos == (UartDev.rcv_buff.pRcvMsgBuff + RX_BUFF_SIZE)) { 131 | UartDev.rcv_buff.pReadPos = UartDev.rcv_buff.pRcvMsgBuff; 132 | } 133 | 134 | return ret; 135 | } 136 | 137 | /****************************************************************************** 138 | * FunctionName : uart_init 139 | * Description : user interface for init uart 140 | * Parameters : UartBautRate uart0_br - uart0 bautrate 141 | * UartBautRate uart1_br - uart1 bautrate 142 | * Returns : NONE 143 | *******************************************************************************/ 144 | void ICACHE_FLASH_ATTR 145 | uart_init() 146 | { 147 | // rom use 74880 baut_rate, here reinitialize 148 | UartDev.baut_rate = BIT_RATE_9600; 149 | uart_config(0); 150 | ETS_UART_INTR_ENABLE(); 151 | 152 | // install uart1 putc callback 153 | os_install_putc1((void *)stdoutPutchar); 154 | UartDev.rcv_buff.pWritePos = UartDev.rcv_buff.pRcvMsgBuff; 155 | UartDev.rcv_buff.pReadPos = UartDev.rcv_buff.pRcvMsgBuff; 156 | } 157 | 158 | -------------------------------------------------------------------------------- /user/uart.h: -------------------------------------------------------------------------------- 1 | #ifndef UART_APP_H 2 | #define UART_APP_H 3 | 4 | #include "uart_register.h" 5 | 6 | #define RX_BUFF_SIZE 0x100 7 | #define TX_BUFF_SIZE 100 8 | 9 | typedef enum { 10 | FIVE_BITS = 0x0, 11 | SIX_BITS = 0x1, 12 | SEVEN_BITS = 0x2, 13 | EIGHT_BITS = 0x3 14 | } UartBitsNum4Char; 15 | 16 | typedef enum { 17 | ONE_STOP_BIT = 0, 18 | ONE_HALF_STOP_BIT = BIT2, 19 | TWO_STOP_BIT = BIT2 20 | } UartStopBitsNum; 21 | 22 | typedef enum { 23 | NONE_BITS = 0, 24 | ODD_BITS = 0, 25 | EVEN_BITS = BIT4 26 | } UartParityMode; 27 | 28 | typedef enum { 29 | STICK_PARITY_DIS = 0, 30 | STICK_PARITY_EN = BIT3 | BIT5 31 | } UartExistParity; 32 | 33 | typedef enum { 34 | BIT_RATE_9600 = 9600, 35 | BIT_RATE_19200 = 19200, 36 | BIT_RATE_38400 = 38400, 37 | BIT_RATE_57600 = 57600, 38 | BIT_RATE_74880 = 74880, 39 | BIT_RATE_115200 = 115200, 40 | BIT_RATE_230400 = 230400, 41 | BIT_RATE_460800 = 460800, 42 | BIT_RATE_921600 = 921600 43 | } UartBautRate; 44 | 45 | typedef enum { 46 | NONE_CTRL, 47 | HARDWARE_CTRL, 48 | XON_XOFF_CTRL 49 | } UartFlowCtrl; 50 | 51 | typedef enum { 52 | EMPTY, 53 | UNDER_WRITE, 54 | WRITE_OVER 55 | } RcvMsgBuffState; 56 | 57 | typedef struct { 58 | uint32 RcvBuffSize; 59 | uint8 *pRcvMsgBuff; 60 | uint8 *pWritePos; 61 | uint8 *pReadPos; 62 | uint8 TrigLvl; //JLU: may need to pad 63 | RcvMsgBuffState BuffState; 64 | } RcvMsgBuff; 65 | 66 | typedef struct { 67 | uint32 TrxBuffSize; 68 | uint8 *pTrxBuff; 69 | } TrxMsgBuff; 70 | 71 | typedef enum { 72 | BAUD_RATE_DET, 73 | WAIT_SYNC_FRM, 74 | SRCH_MSG_HEAD, 75 | RCV_MSG_BODY, 76 | RCV_ESC_CHAR, 77 | } RcvMsgState; 78 | 79 | typedef struct { 80 | UartBautRate baut_rate; 81 | UartBitsNum4Char data_bits; 82 | UartExistParity exist_parity; 83 | UartParityMode parity; // chip size in byte 84 | UartStopBitsNum stop_bits; 85 | UartFlowCtrl flow_ctrl; 86 | RcvMsgBuff rcv_buff; 87 | TrxMsgBuff trx_buff; 88 | RcvMsgState rcv_state; 89 | int received; 90 | int buff_uart_no; //indicate which uart use tx/rx buffer 91 | } UartDevice; 92 | 93 | void uart_init(); 94 | ICACHE_FLASH_ATTR int uart0_rx_one_char(); 95 | ICACHE_FLASH_ATTR void stdoutPutchar(char c); 96 | 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /user/uart_register.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 | -------------------------------------------------------------------------------- /user/user_main.c: -------------------------------------------------------------------------------- 1 | #include "espmissingincludes.h" 2 | #include "ets_sys.h" 3 | #include "osapi.h" 4 | #include "os_type.h" 5 | #include "uart.h" 6 | #include "websocketd.h" 7 | 8 | #define RX_PRIO 0 9 | #define RX_QUEUE_LEN 1 10 | #define COMMAND_MAXLEN 1024 11 | 12 | os_event_t user_procTaskQueue[RX_QUEUE_LEN]; 13 | static char *statusCommand = "STATUS:"; 14 | static uint8_t commandMatcher = 0; 15 | static uint8_t commandMatched = FALSE; 16 | static char command[COMMAND_MAXLEN]; 17 | static uint32_t commandPosition = 0; 18 | 19 | 20 | //Main code function 21 | static void ICACHE_FLASH_ATTR rxLoop(os_event_t *events) { 22 | 23 | int c = uart0_rx_one_char(); 24 | 25 | if (c != -1) { 26 | 27 | if (commandMatched == TRUE) { 28 | if (c == '\n' || c == '\r') { 29 | broadcastWsMessage(command, commandPosition, FLAG_FIN | OPCODE_TEXT); 30 | commandMatched = FALSE; 31 | commandPosition = 0; 32 | commandMatcher = 0; 33 | }else{ 34 | command[commandPosition++] = c; 35 | } 36 | 37 | if (commandPosition == COMMAND_MAXLEN) { 38 | commandMatched = FALSE; 39 | commandPosition = 0; 40 | commandMatcher = 0; 41 | } 42 | } else { 43 | if (statusCommand[commandMatcher] == c) { 44 | commandMatcher++; 45 | 46 | if (commandMatcher == strlen(statusCommand)) { 47 | commandMatched = TRUE; 48 | } 49 | } else { 50 | commandMatcher = 0; 51 | } 52 | } 53 | } 54 | 55 | system_os_post(RX_PRIO, 0, 0 ); 56 | } 57 | 58 | void onWsMessage(WSConnection *connection, const WSFrame *message) { 59 | for (int i = 0; i < message->payloadLength; i++) { 60 | stdoutPutchar(message->payloadData[i]); 61 | } 62 | stdoutPutchar('\n'); 63 | } 64 | 65 | void onWsConnection(WSConnection *connection) { 66 | connection->onMessage = &onWsMessage; 67 | } 68 | 69 | 70 | 71 | //Main routine. Initialize stdout, the I/O and the webserver and we're done. 72 | void user_init(void) { 73 | uart_init(); 74 | ioInit(); 75 | websocketdInit(8080, &onWsConnection); 76 | 77 | //Start os task 78 | system_os_task(rxLoop, RX_PRIO, user_procTaskQueue, RX_QUEUE_LEN); 79 | system_os_post(RX_PRIO, 0, 0 ); 80 | 81 | os_printf("\nReady\n"); 82 | } 83 | -------------------------------------------------------------------------------- /user/websocketd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "espmissingincludes.h" 5 | #include "sha1.h" 6 | #include "base64.h" 7 | 8 | #include "websocketd.h" 9 | 10 | //server socket 11 | static struct espconn wsConn; 12 | static esp_tcp wsTcp; 13 | static WSOnConnection wsOnConnectionCallback; 14 | static WSConnection wsConnections[WS_MAXCONN]; 15 | 16 | static int ICACHE_FLASH_ATTR createWsAcceptKey(const char *key, char *buffer, int bufferSize) { 17 | sha1nfo s; 18 | 19 | char concatenatedBuffer[512]; 20 | concatenatedBuffer[0] = '\0'; 21 | //concatenate the key and the GUID 22 | os_strcat(concatenatedBuffer, key); 23 | os_strcat(concatenatedBuffer, WS_GUID); 24 | 25 | //build the sha1 hash 26 | sha1_init(&s); 27 | sha1_write(&s, concatenatedBuffer, strlen(concatenatedBuffer)); 28 | uint8_t *hash = sha1_result(&s); 29 | 30 | return base64_encode(20, hash, bufferSize, buffer); 31 | } 32 | 33 | static void ICACHE_FLASH_ATTR parseWsFrame(char *data, WSFrame *frame) { 34 | frame->flags = (*data) & FLAGS_MASK; 35 | frame->opcode = (*data) & OPCODE_MASK; 36 | //next byte 37 | data += 1; 38 | frame->isMasked = (*data) & IS_MASKED; 39 | frame->payloadLength = (*data) & PAYLOAD_MASK; 40 | 41 | //next byte 42 | data += 1; 43 | 44 | if (frame->payloadLength == 126) { 45 | os_memcpy(&frame->payloadLength, data, sizeof(uint16_t)); 46 | data += sizeof(uint16_t); 47 | } else if (frame->payloadLength == 127) { 48 | os_memcpy(&frame->payloadLength, data, sizeof(uint64_t)); 49 | data += sizeof(uint64_t); 50 | } 51 | 52 | if (frame->isMasked) { 53 | os_memcpy(&frame->maskingKey, data, sizeof(uint32_t)); 54 | data += sizeof(uint32_t); 55 | } 56 | 57 | frame->payloadData = data; 58 | } 59 | 60 | static void ICACHE_FLASH_ATTR unmaskWsPayload(char *maskedPayload, uint64_t payloadLength, uint32_t maskingKey) { 61 | //the algorith described in IEEE RFC 6455 Section 5.3 62 | //TODO: this should decode the payload 4-byte wise and do the remainder afterwards 63 | for (int i = 0; i < payloadLength; i++) { 64 | int j = i % 4; 65 | maskedPayload[i] = maskedPayload[i] ^ ((uint8_t *)&maskingKey)[j]; 66 | } 67 | } 68 | 69 | void ICACHE_FLASH_ATTR broadcastWsMessage(const char *payload, uint64_t payloadLength, uint8_t options) { 70 | 71 | for(int slotId=0; slotId < WS_MAXCONN; slotId++){ 72 | WSConnection connection = wsConnections[slotId]; 73 | if(connection.connection != NULL && connection.status == STATUS_OPEN){ 74 | sendWsMessage(&connection, payload, payloadLength, options); 75 | } 76 | } 77 | } 78 | 79 | void ICACHE_FLASH_ATTR sendWsMessage(WSConnection* connection, const char *payload, uint64_t payloadLength, uint8_t options) { 80 | uint8_t payloadLengthField[9]; 81 | uint8_t payloadLengthFieldLength = 0; 82 | 83 | 84 | if (payloadLength > ((1 << 16) - 1)) { 85 | payloadLengthField[0] = 127; 86 | os_memcpy(payloadLengthField + 1, &payloadLength, sizeof(uint64_t)); 87 | payloadLengthFieldLength = sizeof(uint64_t) + 1; 88 | } else if (payloadLength > ((1 << 8) - 1)) { 89 | payloadLengthField[0] = 126; 90 | os_memcpy(payloadLengthField + 1, &payloadLength, sizeof(uint16_t)); 91 | payloadLengthFieldLength = sizeof(uint16_t) + 1; 92 | } else { 93 | payloadLengthField[0] = payloadLength; 94 | payloadLengthFieldLength = 1; 95 | } 96 | 97 | uint64_t maximumPossibleMessageSize = 14 + payloadLength; //14 bytes is the biggest frame header size 98 | char message[maximumPossibleMessageSize]; 99 | message[0] = options; 100 | 101 | os_memcpy(message + 1, &payloadLengthField, payloadLengthFieldLength); 102 | os_memcpy(message + 1 + payloadLengthFieldLength, payload, strlen(payload)); 103 | 104 | espconn_sent(connection->connection, (uint8_t *)&message, payloadLength + 1 + payloadLengthFieldLength); 105 | } 106 | 107 | void ICACHE_FLASH_ATTR closeWsConnection(WSConnection* connection) { 108 | char closeMessage[CLOSE_MESSAGE_LENGTH] = CLOSE_MESSAGE; 109 | espconn_sent(connection->connection, (uint8_t *)closeMessage, sizeof(closeMessage)); 110 | connection->status = STATUS_CLOSED; 111 | return; 112 | } 113 | 114 | static WSConnection *ICACHE_FLASH_ATTR getWsConnection(struct espconn *connection) { 115 | for (int slotId = 0; slotId < WS_MAXCONN; slotId++) { 116 | if (wsConnections[slotId].connection == connection) { 117 | return wsConnections + slotId; 118 | } 119 | } 120 | return NULL; 121 | } 122 | 123 | static void ICACHE_FLASH_ATTR wsSentCb(void *esp_connection) { 124 | WSConnection *wsConnection = getWsConnection(esp_connection); 125 | 126 | if (wsConnection == NULL) { 127 | //huh? 128 | return; 129 | } 130 | 131 | if(wsConnection->status == STATUS_CLOSED){ 132 | //Close message sent, now close the socket 133 | espconn_disconnect(wsConnection->connection); 134 | //free the slot 135 | wsConnection->connection = NULL; 136 | } 137 | } 138 | 139 | static void ICACHE_FLASH_ATTR wsRecvCb(void *esp_connection, char *data, unsigned short len) { 140 | WSConnection *wsConnection = getWsConnection(esp_connection); 141 | /*if (wsConnection == NULL) { 142 | //huh? 143 | return; 144 | }*/ 145 | 146 | //get the first occurrence of the key identifier 147 | char *key = os_strstr(data, WS_KEY_IDENTIFIER); 148 | 149 | if (key != NULL) { 150 | // ------------------------ Handle the Handshake ------------------------ 151 | 152 | //Skip the identifier (that contains the space already) 153 | key += os_strlen(WS_KEY_IDENTIFIER); 154 | 155 | //the key ends at the newline 156 | char *endSequence = os_strstr(key, HTML_HEADER_LINEEND); 157 | if (endSequence != NULL) { 158 | int keyLastChar = endSequence - key; 159 | //we can throw away all the other data, only the key is interesting 160 | key[keyLastChar] = '\0'; 161 | 162 | char acceptKey[100]; 163 | createWsAcceptKey(key, acceptKey, 100); 164 | 165 | //now construct our message and send it back to the client 166 | char responseMessage[strlen(WS_RESPONSE) + 100]; 167 | os_sprintf(responseMessage, WS_RESPONSE, acceptKey); 168 | 169 | //send the response 170 | espconn_sent(esp_connection, (uint8_t *)responseMessage, strlen(responseMessage)); 171 | wsConnection->status = STATUS_OPEN; 172 | //call the connection callback 173 | if (wsOnConnectionCallback != NULL) { 174 | wsOnConnectionCallback(wsConnection); 175 | } 176 | } 177 | } else { 178 | // ------------------------ Handle a Frame ------------------------ 179 | WSFrame frame; 180 | parseWsFrame(data, &frame); 181 | 182 | if (frame.isMasked) { 183 | unmaskWsPayload(frame.payloadData, frame.payloadLength, frame.maskingKey); 184 | } else { 185 | //we are the server, and need to shut down the connection 186 | //if we receive an unmasked packet 187 | closeWsConnection(wsConnection); 188 | return; 189 | } 190 | 191 | if (frame.opcode == OPCODE_PING) { 192 | sendWsMessage(wsConnection, frame.payloadData, frame.payloadLength, FLAG_FIN | OPCODE_PONG); 193 | return; 194 | } 195 | 196 | if(frame.opcode == OPCODE_CLOSE){ 197 | //gracefully shut down the connection 198 | closeWsConnection(wsConnection); 199 | return; 200 | } 201 | 202 | if(wsConnection->onMessage != NULL){ 203 | wsConnection->onMessage(wsConnection, &frame); 204 | } 205 | } 206 | } 207 | 208 | static void ICACHE_FLASH_ATTR wsConnectCb(void *connection) { 209 | 210 | //find an empty slot 211 | uint8_t slotId = 0; 212 | while (wsConnections[slotId].connection != NULL && slotId < WS_MAXCONN) { 213 | slotId++; 214 | } 215 | 216 | if (slotId == WS_MAXCONN) { 217 | //no more free slots, close the connection 218 | espconn_disconnect(connection); 219 | return; 220 | } 221 | 222 | WSConnection wsConnection; 223 | wsConnection.status = STATUS_UNINITIALISED; 224 | wsConnection.connection = connection; 225 | wsConnections[slotId] = wsConnection; 226 | 227 | espconn_regist_recvcb(connection, wsRecvCb); 228 | espconn_regist_sentcb(connection, wsSentCb); 229 | } 230 | 231 | void ICACHE_FLASH_ATTR websocketdInit(int port, WSOnConnection onConnection) { 232 | 233 | wsOnConnectionCallback = onConnection; 234 | 235 | wsConn.type = ESPCONN_TCP; 236 | wsConn.state = ESPCONN_NONE; 237 | 238 | wsTcp.local_port = port; 239 | wsConn.proto.tcp = &wsTcp; 240 | 241 | espconn_regist_connectcb(&wsConn, wsConnectCb); 242 | espconn_accept(&wsConn); 243 | espconn_regist_time(&wsConn, CONN_TIMEOUT, 0); 244 | } -------------------------------------------------------------------------------- /user/websocketd.h: -------------------------------------------------------------------------------- 1 | #ifndef WEBSOCKETD_H 2 | #define WEBSOCKETD_H 3 | #include 4 | #include 5 | #include 6 | 7 | #define WS_KEY_IDENTIFIER "Sec-WebSocket-Key: " 8 | #define WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" 9 | #define WS_RESPONSE "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: %s\r\nSec-WebSocket-Protocol: chat\r\n\r\n" 10 | #define HTML_HEADER_LINEEND "\r\n" 11 | 12 | 13 | //we normally dont need that many connection, however a single 14 | //connection only allocates a WSConnection struct and is therefore really small 15 | #define WS_MAXCONN 4 16 | #define CONN_TIMEOUT 60*60*12 17 | 18 | /* from IEEE RFC6455 sec 5.2 19 | 0 1 2 3 20 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 21 | +-+-+-+-+-------+-+-------------+-------------------------------+ 22 | |F|R|R|R| opcode|M| Payload len | Extended payload length | 23 | |I|S|S|S| (4) |A| (7) | (16/64) | 24 | |N|V|V|V| |S| | (if payload len==126/127) | 25 | | |1|2|3| |K| | | 26 | +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + 27 | | Extended payload length continued, if payload len == 127 | 28 | + - - - - - - - - - - - - - - - +-------------------------------+ 29 | | |Masking-key, if MASK set to 1 | 30 | +-------------------------------+-------------------------------+ 31 | | Masking-key (continued) | Payload Data | 32 | +-------------------------------- - - - - - - - - - - - - - - - + 33 | : Payload Data continued ... : 34 | + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 35 | | Payload Data continued ... | 36 | +---------------------------------------------------------------+ 37 | */ 38 | 39 | #define FLAG_FIN (1 << 7) 40 | #define FLAG_RSV1 (1 << 6) 41 | #define FLAG_RSV2 (1 << 5) 42 | #define FLAG_RSV3 (1 << 4) 43 | 44 | #define OPCODE_CONTINUE 0x0 45 | #define OPCODE_TEXT 0x1 46 | #define OPCODE_BINARY 0x2 47 | #define OPCODE_CLOSE 0x8 48 | #define OPCODE_PING 0x9 49 | #define OPCODE_PONG 0xA 50 | 51 | #define FLAGS_MASK ((uint8_t)0xF0) 52 | #define OPCODE_MASK ((uint8_t)0x0F) 53 | #define IS_MASKED ((uint8_t)(1<<7)) 54 | #define PAYLOAD_MASK ((uint8_t)0x7F) 55 | 56 | #define STATUS_OPEN 0 57 | #define STATUS_CLOSED 1 58 | #define STATUS_UNINITIALISED 2 59 | 60 | #define CLOSE_MESSAGE {FLAG_FIN | OPCODE_CLOSE, IS_MASKED /* + payload = 0*/, 0 /* + masking key*/} 61 | #define CLOSE_MESSAGE_LENGTH 3 62 | 63 | typedef struct WSFrame WSFrame; 64 | typedef struct WSConnection WSConnection; 65 | 66 | typedef void (* WSOnMessage)(WSConnection *,const WSFrame* ); 67 | typedef void (* WSOnConnection)(WSConnection *connection); 68 | 69 | struct WSFrame { 70 | uint8_t flags; 71 | uint8_t opcode; 72 | uint8_t isMasked; 73 | uint64_t payloadLength; 74 | uint32_t maskingKey; 75 | char* payloadData; 76 | }; 77 | 78 | struct WSConnection { 79 | uint8_t status; 80 | struct espconn* connection; 81 | WSOnMessage onMessage; 82 | }; 83 | 84 | void ICACHE_FLASH_ATTR websocketdInit(int port, WSOnConnection onConnection); 85 | void ICACHE_FLASH_ATTR sendWsMessage(WSConnection* connection, const char* payload, uint64_t payloadLength, uint8_t options); 86 | void ICACHE_FLASH_ATTR broadcastWsMessage(const char* payload, uint64_t payloadLength, uint8_t options); 87 | 88 | #endif //WEBSOCKETD_H --------------------------------------------------------------------------------