├── CaptiveHotspot.ino ├── README.md ├── WiFiNatRouter.ino ├── liblwip_src.a └── lwip ├── include ├── arch │ ├── cc.h │ ├── perf.h │ └── sys_arch.h ├── lwip │ ├── api.h │ ├── api_msg.h │ ├── app │ │ ├── dhcpserver.h │ │ ├── espconn.h │ │ ├── espconn_buf.h │ │ ├── espconn_tcp.h │ │ ├── espconn_udp.h │ │ ├── ping.h │ │ └── time.h │ ├── arch.h │ ├── autoip.h │ ├── debug.h │ ├── def.h │ ├── dhcp.h │ ├── dns.h │ ├── err.h │ ├── icmp.h │ ├── igmp.h │ ├── inet.h │ ├── inet_chksum.h │ ├── init.h │ ├── ip.h │ ├── ip_addr.h │ ├── ip_frag.h │ ├── ip_route.h │ ├── lwip_napt.h │ ├── mdns.h │ ├── mem.h │ ├── memp.h │ ├── memp_std.h │ ├── netbuf.h │ ├── netdb.h │ ├── netif.h │ ├── netifapi.h │ ├── opt.h │ ├── pbuf.h │ ├── puck_def.h │ ├── raw.h │ ├── sio.h │ ├── snmp.h │ ├── snmp_asn1.h │ ├── snmp_msg.h │ ├── snmp_structs.h │ ├── sntp.h │ ├── sockets.h │ ├── stats.h │ ├── sys.h │ ├── tcp.h │ ├── tcp_impl.h │ ├── tcpip.h │ ├── timers.h │ └── udp.h ├── lwipopts.h └── netif │ ├── driver │ ├── spi.h │ └── spi_register.h │ ├── etharp.h │ ├── if_llc.h │ ├── ppp_oe.h │ └── wlan_lwip_if.h └── src ├── Makefile ├── api ├── api_lib.c ├── api_msg.c ├── err.c ├── netbuf.c ├── netdb.c ├── netifapi.c ├── sockets.c └── tcpip.c ├── app ├── Makefile ├── dhcpserver.c ├── dhcpserver.c.napt ├── espconn.c ├── espconn_buf.c ├── espconn_mdns.c ├── espconn_tcp.c ├── espconn_udp.c ├── netio.c └── ping.c ├── core ├── def.c ├── dhcp.c ├── dns.c ├── init.c ├── ipv4 │ ├── autoip.c │ ├── icmp.c │ ├── igmp.c │ ├── inet.c │ ├── inet_chksum.c │ ├── ip.c │ ├── ip_addr.c │ ├── ip_frag.c │ └── ip_route.c ├── mdns.c ├── mem.c ├── memp.c ├── netif.c ├── pbuf.c ├── raw.c ├── sntp.c ├── stats.c ├── sys.c ├── sys_arch.c ├── tcp.c ├── tcp_in.c ├── tcp_out.c ├── timers.c └── udp.c └── netif └── etharp.c /CaptiveHotspot.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "lwip/lwip_napt.h" 5 | #include "lwip/app/dhcpserver.h" 6 | #include "lwip/netif.h" 7 | #include "netif/etharp.h" 8 | #include "lwip/udp.h" 9 | 10 | // credentials for ESP8266 STA 11 | const char* sta_ssid = my_ssid; 12 | const char* sta_password = my_password; 13 | 14 | // name of the ESP8266 AP 15 | #define AP_SSID "ESP Hotspot" 16 | 17 | const int MAX_CLIENTS = 16; 18 | 19 | #define VIEWPORT "" 20 | 21 | String indexHTML = "" 22 | "" 23 | "" 24 | "" AP_SSID "" 25 | "" 26 | VIEWPORT 27 | "" 28 | "

" AP_SSID "

" 29 | "I accept the terms of usage.

" 30 | "" 31 | "" 32 | ""; 33 | 34 | String acceptedHTML = "" 35 | "" 36 | "" 37 | "" AP_SSID "" 38 | "" 39 | VIEWPORT 40 | "" 41 | "" 42 | "

Terms accepted!

" 43 | "" 44 | ""; 45 | 46 | const byte DHCP_PORT = 67; 47 | const byte DNS_PORT = 53; 48 | const byte HTTP_PORT = 80; 49 | 50 | IPAddress myIP; 51 | ESP8266WebServer webServer(80); 52 | 53 | PACK_STRUCT_BEGIN 54 | struct tcp_hdr { 55 | PACK_STRUCT_FIELD(u16_t src); 56 | PACK_STRUCT_FIELD(u16_t dest); 57 | PACK_STRUCT_FIELD(u32_t seqno); 58 | PACK_STRUCT_FIELD(u32_t ackno); 59 | PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags); 60 | PACK_STRUCT_FIELD(u16_t wnd); 61 | PACK_STRUCT_FIELD(u16_t chksum); 62 | PACK_STRUCT_FIELD(u16_t urgp); 63 | } PACK_STRUCT_STRUCT; 64 | PACK_STRUCT_END 65 | 66 | // some magic from inside the NAT lwip for address rewriting 67 | extern "C" { 68 | void ip_napt_modify_addr_tcp(struct tcp_hdr *tcphdr, ip_addr_p_t *oldval, u32_t newval); 69 | void ip_napt_modify_addr(struct ip_hdr *iphdr, ip_addr_p_t *field, u32_t newval); 70 | } 71 | 72 | static netif_input_fn orig_input_ap; 73 | static netif_linkoutput_fn orig_output_ap; 74 | struct eth_addr curr_mac; 75 | uint32_t curr_origIP, curr_srcIP; 76 | 77 | struct eth_addr allowed_macs[MAX_CLIENTS]; 78 | int max_client = 0; 79 | 80 | bool check_packet_in(struct pbuf *p) { 81 | struct eth_hdr *mac_h; 82 | struct ip_hdr *ip_h; 83 | struct udp_hdr *udp_he; 84 | struct tcp_hdr *tcp_h; 85 | 86 | if (p->len < sizeof(struct eth_hdr)) 87 | return false; 88 | 89 | mac_h = (struct eth_hdr *)p->payload; 90 | 91 | // Check only IPv4 traffic 92 | if (ntohs(mac_h->type) != ETHTYPE_IP) 93 | return true; 94 | 95 | if (p->len < sizeof(struct eth_hdr)+sizeof(struct ip_hdr)) 96 | return false; 97 | 98 | ip_h = (struct ip_hdr *)(p->payload + sizeof(struct eth_hdr)); 99 | 100 | // Known MACs can pass 101 | for(int i = 0; isrc.addr, allowed_macs[i].addr, sizeof(mac_h->src.addr)) == 0) { 103 | return true; 104 | } 105 | } 106 | 107 | // DHCP and DNS is okay 108 | if (IPH_PROTO(ip_h) == IP_PROTO_UDP) { 109 | if (p->len < sizeof(struct eth_hdr)+sizeof(struct ip_hdr)+sizeof(struct udp_hdr)) 110 | return false; 111 | 112 | udp_he = (struct udp_hdr *)(p->payload + sizeof(struct eth_hdr) + sizeof(struct ip_hdr)); 113 | 114 | if (ntohs(udp_he->dest) == DHCP_PORT) 115 | return true; 116 | 117 | if (ntohs(udp_he->dest) == DNS_PORT) 118 | return true; 119 | 120 | return false; 121 | } 122 | 123 | // HTTP is redirected 124 | if (IPH_PROTO(ip_h) == IP_PROTO_TCP) { 125 | if (p->len < sizeof(struct eth_hdr)+sizeof(struct ip_hdr)+sizeof(struct tcp_hdr)) 126 | return false; 127 | 128 | tcp_h = (struct tcp_hdr *)(p->payload + sizeof(struct eth_hdr) + sizeof(struct ip_hdr)); 129 | 130 | if (ntohs(tcp_h->dest) == HTTP_PORT) { 131 | curr_mac = mac_h->src; 132 | curr_origIP = ip_h->dest.addr; 133 | curr_srcIP = ip_h->src.addr; 134 | ip_napt_modify_addr_tcp(tcp_h, &ip_h->dest, (uint32_t)myIP); 135 | ip_napt_modify_addr(ip_h, &ip_h->dest, (uint32_t)myIP); 136 | return true; 137 | } 138 | } 139 | 140 | // drop anything else 141 | return false; 142 | } 143 | 144 | err_t my_input_ap (struct pbuf *p, struct netif *inp) { 145 | 146 | if (check_packet_in(p)) { 147 | return orig_input_ap(p, inp); 148 | } else { 149 | pbuf_free(p); 150 | return ERR_OK; 151 | } 152 | } 153 | 154 | bool check_packet_out(struct pbuf *p) { 155 | struct eth_hdr *mac_h; 156 | struct ip_hdr *ip_h; 157 | struct tcp_hdr *tcp_h; 158 | 159 | if (p->len < sizeof(struct eth_hdr)+sizeof(struct ip_hdr)+sizeof(struct tcp_hdr)) 160 | return true; 161 | 162 | ip_h = (struct ip_hdr *)(p->payload + sizeof(struct eth_hdr)); 163 | 164 | if (IPH_PROTO(ip_h) != IP_PROTO_TCP) 165 | return true; 166 | 167 | tcp_h = (struct tcp_hdr *)(p->payload + sizeof(struct eth_hdr) + sizeof(struct ip_hdr)); 168 | 169 | // rewrite packet from our HTTP server 170 | if (ntohs(tcp_h->src) == HTTP_PORT && ip_h->src.addr == (uint32_t)myIP && ip_h->dest.addr == (uint32_t)curr_srcIP) { 171 | ip_napt_modify_addr_tcp(tcp_h, &ip_h->src, curr_origIP); 172 | ip_napt_modify_addr(ip_h, &ip_h->src, curr_origIP); 173 | } 174 | 175 | return true; 176 | } 177 | 178 | err_t my_output_ap (struct netif *outp, struct pbuf *p) { 179 | 180 | if (check_packet_out(p)) { 181 | return orig_output_ap(outp, p); 182 | } else { 183 | pbuf_free(p); 184 | return ERR_OK; 185 | } 186 | } 187 | 188 | // patches the netif to insert the filter functions 189 | void patch_netif(ip_addr_t netif_ip, netif_input_fn ifn, netif_input_fn *orig_ifn, netif_linkoutput_fn ofn, netif_linkoutput_fn *orig_ofn) 190 | { 191 | struct netif *nif; 192 | 193 | for (nif = netif_list; nif != NULL && nif->ip_addr.addr != netif_ip.addr; nif = nif->next); 194 | if (nif == NULL) return; 195 | 196 | if (ifn != NULL && nif->input != ifn) { 197 | *orig_ifn = nif->input; 198 | nif->input = ifn; 199 | } 200 | if (ofn != NULL && nif->linkoutput != ofn) { 201 | *orig_ofn = nif->linkoutput; 202 | nif->linkoutput = ofn; 203 | } 204 | } 205 | 206 | void setup() 207 | { 208 | Serial.begin(115200); 209 | Serial.println(); 210 | 211 | WiFi.mode(WIFI_AP_STA); 212 | 213 | Serial.println("Starting Hotspot demo"); 214 | 215 | WiFi.begin(sta_ssid, sta_password); 216 | 217 | //Wifi connection 218 | while (WiFi.status() != WL_CONNECTED) { 219 | delay(500); 220 | Serial.print("."); 221 | } 222 | 223 | Serial.println(""); 224 | Serial.print("Connected to "); 225 | Serial.println(sta_ssid); 226 | Serial.print("IP address: "); 227 | Serial.println(WiFi.localIP()); 228 | Serial.print("dnsIP address: "); 229 | Serial.println(WiFi.dnsIP()); 230 | Serial.print("gatewayIP address: "); 231 | Serial.println(WiFi.gatewayIP()); 232 | Serial.print("subnetMask address: "); 233 | Serial.println(WiFi.subnetMask()); 234 | 235 | 236 | Serial.println(""); 237 | Serial.println("Configuring access point..."); 238 | WiFi.softAP(AP_SSID, NULL, 1, 0, 8); 239 | 240 | myIP = WiFi.softAPIP(); 241 | Serial.print("AP IP address: "); 242 | Serial.println(myIP); 243 | 244 | // Insert the filter functions 245 | patch_netif(myIP, my_input_ap, &orig_input_ap, my_output_ap, &orig_output_ap); 246 | 247 | // Initialize the NAT feature 248 | ip_napt_init(IP_NAPT_MAX, IP_PORTMAP_MAX); 249 | 250 | // Enable NAT on the AP interface 251 | ip_napt_enable_no(1, 1); 252 | 253 | // Set the DNS server for clients of the AP to the one we also use for the STA interface 254 | dhcps_set_DNS(WiFi.dnsIP()); 255 | 256 | webServer.on("/", []() { 257 | webServer.send(200, "text/html", indexHTML); 258 | }); 259 | 260 | webServer.on("/accepted", []() { 261 | for (int i = 0; i < 6; i++) { 262 | Serial.print(curr_mac.addr[i]);Serial.print(":"); 263 | } 264 | Serial.println(" allowed"); 265 | 266 | if (max_client < MAX_CLIENTS) { 267 | allowed_macs[max_client++] = curr_mac; 268 | } 269 | webServer.send(200, "text/html", acceptedHTML); 270 | }); 271 | 272 | // redirect all other URIs to our "/" 273 | webServer.onNotFound([]() { 274 | webServer.sendHeader("Location", String("http://")+myIP.toString()+String("/"), true); 275 | webServer.send (302, "text/plain", ""); 276 | }); 277 | webServer.begin(); 278 | 279 | } 280 | 281 | void loop() 282 | { 283 | webServer.handleClient(); 284 | } 285 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lwip_nat_arduino 2 | lwip library with NAT routing feature for Arduino environment 3 | 4 | *** This lib is somewhat obsolete because of the recent update of ESP8266 Arduino https://github.com/esp8266/Arduino. Since release 2.6.0 NAPT/NAT is part of the standard distribution. See also this example: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/RangeExtender-NAPT/RangeExtender-NAPT.ino *** 5 | 6 | ## Sample 7 | For an example look into: "WiFiNATRouter.ino" that sets up a basic NAT router between the AP and the STA interface (works like a basic version of https://github.com/martin-ger/esp_wifi_repeater ). 8 | 9 | The other example "CaptiveHotspot.ino" implements a skeleton of a hotspot with MAC filtering and a captive portal. In this sample it only asks for a confirmation of the "Terms of use" before enabling a certain MAC address. In a more sophisticated version it could ask for some credentials. 10 | 11 | ## Install 12 | Install the Arduino environment for the esp8266 as described here: https://github.com/esp8266/Arduino . As you are here, you probably did this already. Make sure that the "make" command is installed in your environment - this is especially an issue in Windows environment. 13 | 14 | This extension has been developed for the version 2.5 of the ESP8266 core (now also tested with 2.5.2). Switch to that in the Board Manager, if you havn't done already. 15 | 16 | Download this repo to some place. Go to the ".../packages/esp8266/hardware/esp8266/2.5.2/tools/sdk/" directory of your Arduino installation. Here you rename the directory "lwip" to "lwip.orig". Then you copy the complete directory "lwip" of this repo to this place (in fact you replace "lwip" with my implementation). 17 | 18 | Whenever you want to use this library, select *LwIP Variant: "v1.4 Compile from source* in the "Tools" menu of the Arduino shell. 19 | 20 | ## Usage 21 | The new NAT functions are exported in the "lwip/lwip_napt.h" header: 22 | 23 | ``` 24 | /** 25 | * Allocates and initializes the NAPT tables. 26 | * 27 | * @param max_nat max number of enties in the NAPT table (use IP_NAPT_MAX if in doubt) 28 | * @param max_portmap max number of enties in the NAPT table (use IP_PORTMAP_MAX if in doubt) 29 | */ 30 | void 31 | ip_napt_init(uint16_t max_nat, uint8_t max_portmap); 32 | 33 | 34 | /** 35 | * Enable/Disable NAPT for a specified interface. 36 | * 37 | * @param addr ip address of the interface 38 | * @param enable non-zero to enable NAPT, or 0 to disable. 39 | */ 40 | void 41 | ip_napt_enable(u32_t addr, int enable); 42 | 43 | 44 | /** 45 | * Enable/Disable NAPT for a specified interface. 46 | * 47 | * @param netif number of the interface: 0 = STA, 1 = AP 48 | * @param enable non-zero to enable NAPT, or 0 to disable. 49 | */ 50 | void 51 | ip_napt_enable_no(u8_t number, int enable); 52 | 53 | 54 | /** 55 | * Register port mapping on the external interface to internal interface. 56 | * When the same port mapping is registered again, the old mapping is overwritten. 57 | * In this implementation, only 1 unique port mapping can be defined for each target address/port. 58 | * 59 | * @param proto target protocol 60 | * @param maddr ip address of the external interface 61 | * @param mport mapped port on the external interface, in host byte order. 62 | * @param daddr destination ip address 63 | * @param dport destination port, in host byte order. 64 | */ 65 | u8_t 66 | ip_portmap_add(u8_t proto, u32_t maddr, u16_t mport, u32_t daddr, u16_t dport); 67 | 68 | 69 | /** 70 | * Unregister port mapping on the external interface to internal interface. 71 | * 72 | * @param proto target protocol 73 | * @param maddr ip address of the external interface 74 | */ 75 | u8_t 76 | ip_portmap_remove(u8_t proto, u16_t mport); 77 | 78 | 79 | /** 80 | * Sets the NAPT timeout for TCP connections. 81 | * 82 | * @param secs timeout in secs 83 | */ 84 | void 85 | ip_napt_set_tcp_timeout(u32_t secs); 86 | 87 | 88 | /** 89 | * Sets the NAPT timeout for UDP 'connections'. 90 | * 91 | * @param secs timeout in secs 92 | */ 93 | void 94 | ip_napt_set_udp_timeout(u32_t secs); 95 | ``` 96 | 97 | In addition, the following extension to the DHCP server of the AP interface might help: 98 | ``` 99 | void dhcps_set_DNS(struct ip_addr *dns_ip) ICACHE_FLASH_ATTR; 100 | ``` 101 | 102 | This sets the DNS server that is distributed to the stations connected to the AP interface. 103 | 104 | ## Routing 105 | 106 | IPv4 also now supports a static routing table. In "ip_route.h" there are these new functions: 107 | ``` 108 | struct route_entry { 109 | ip_addr_t ip; 110 | ip_addr_t mask; 111 | ip_addr_t gw; 112 | }; 113 | 114 | /* Add a static route, true on success */ 115 | bool ip_add_route(ip_addr_t ip, ip_addr_t mask, ip_addr_t gw); 116 | 117 | /* Remove a static route, true on success */ 118 | bool ip_rm_route(ip_addr_t ip, ip_addr_t mask); 119 | 120 | /* Finds a route entry for an address, NULL if none */ 121 | struct route_entry *ip_find_route(ip_addr_t ip); 122 | 123 | /* Delete all static routes */ 124 | void ip_delete_routes(void); 125 | 126 | /* Returns the n_th entry of the routing table, true on success */ 127 | bool ip_get_route(uint32_t no, ip_addr_t *ip, ip_addr_t *mask, ip_addr_t *gw); 128 | ``` 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /WiFiNatRouter.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "lwip/lwip_napt.h" 4 | 5 | #include "lwip/app/dhcpserver.h" 6 | 7 | // credentials for ESP8266 STA 8 | const char* sta_ssid = "your_ssid"; 9 | const char* sta_password = "your_pw"; 10 | 11 | // credentials for ESP8266 AP 12 | const char *ap_ssid = "ESPap"; 13 | const char *ap_password = "password"; 14 | 15 | void setup() 16 | { 17 | Serial.begin(115200); 18 | Serial.println(); 19 | 20 | WiFi.mode(WIFI_AP_STA); 21 | 22 | Serial.println("Starting NAT demo"); 23 | 24 | WiFi.begin(sta_ssid, sta_password); 25 | //WiFi.config(ip, gateway, subnet); 26 | 27 | //Wifi connection 28 | while (WiFi.status() != WL_CONNECTED) { 29 | delay(500); 30 | Serial.print("."); 31 | } 32 | 33 | Serial.println(""); 34 | Serial.print("Connected to "); 35 | Serial.println(sta_ssid); 36 | Serial.print("IP address: "); 37 | Serial.println(WiFi.localIP()); 38 | Serial.print("dnsIP address: "); 39 | Serial.println(WiFi.dnsIP()); 40 | Serial.print("gatewayIP address: "); 41 | Serial.println(WiFi.gatewayIP()); 42 | Serial.print("subnetMask address: "); 43 | Serial.println(WiFi.subnetMask()); 44 | 45 | 46 | Serial.println(""); 47 | Serial.println("Configuring access point..."); 48 | WiFi.softAP(ap_ssid, ap_password); 49 | 50 | IPAddress myIP = WiFi.softAPIP(); 51 | Serial.print("AP IP address: "); 52 | Serial.println(myIP); 53 | 54 | // Initialize the NAT feature 55 | ip_napt_init(IP_NAPT_MAX, IP_PORTMAP_MAX); 56 | 57 | // Enable NAT on the AP interface 58 | ip_napt_enable_no(1, 1); 59 | 60 | // Set the DNS server for clients of the AP to the one we also use for the STA interface 61 | dhcps_set_DNS(WiFi.dnsIP()); 62 | } 63 | 64 | void loop() 65 | { 66 | delay(500); 67 | } 68 | -------------------------------------------------------------------------------- /liblwip_src.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martin-ger/lwip_nat_arduino/ca2bdc9f37203b9061064e0fdfa78f293a84e2b2/liblwip_src.a -------------------------------------------------------------------------------- /lwip/include/arch/cc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | */ 34 | #ifndef __ARCH_CC_H__ 35 | #define __ARCH_CC_H__ 36 | 37 | //#include 38 | #include "c_types.h" 39 | #include "ets_sys.h" 40 | #include "osapi.h" 41 | #define EFAULT 14 42 | 43 | //#define LWIP_PROVIDE_ERRNO 44 | 45 | #if (1) 46 | #define BYTE_ORDER LITTLE_ENDIAN 47 | #else 48 | #define BYTE_ORDER BIG_ENDIAN 49 | #endif 50 | 51 | 52 | typedef unsigned char u8_t; 53 | typedef signed char s8_t; 54 | typedef unsigned short u16_t; 55 | typedef signed short s16_t; 56 | typedef unsigned long u32_t; 57 | typedef signed long s32_t; 58 | typedef unsigned long mem_ptr_t; 59 | 60 | #define S16_F "d" 61 | #define U16_F "d" 62 | #define X16_F "x" 63 | 64 | #define S32_F "d" 65 | #define U32_F "d" 66 | #define X32_F "x" 67 | 68 | #define LWIP_ERR_T s32_t 69 | 70 | //#define PACK_STRUCT_FIELD(x) x __attribute__((packed)) 71 | #define PACK_STRUCT_FIELD(x) x 72 | #define PACK_STRUCT_STRUCT __attribute__((packed)) 73 | #define PACK_STRUCT_BEGIN 74 | #define PACK_STRUCT_END 75 | 76 | //#define LWIP_DEBUG 77 | 78 | #ifdef LWIP_DEBUG 79 | #define LWIP_PLATFORM_DIAG(x) os_printf x 80 | #define LWIP_PLATFORM_ASSERT(x) ETS_ASSERT(x) 81 | #else 82 | #define LWIP_PLATFORM_DIAG(x) 83 | #define LWIP_PLATFORM_ASSERT(x) 84 | #endif 85 | 86 | #define SYS_ARCH_DECL_PROTECT(x) 87 | #define SYS_ARCH_PROTECT(x) 88 | #define SYS_ARCH_UNPROTECT(x) 89 | 90 | #define LWIP_PLATFORM_BYTESWAP 1 91 | #define LWIP_PLATFORM_HTONS(_n) ((u16_t)((((_n) & 0xff) << 8) | (((_n) >> 8) & 0xff))) 92 | #define LWIP_PLATFORM_HTONL(_n) ((u32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) )) 93 | 94 | #if LWIP_RAW 95 | extern u8_t memp_memory_RAW_PCB_base[]; 96 | #endif /* LWIP_RAW */ 97 | 98 | #if LWIP_UDP 99 | extern u8_t memp_memory_UDP_PCB_base[]; 100 | #endif /* LWIP_UDP */ 101 | 102 | #if LWIP_TCP 103 | extern u8_t memp_memory_TCP_PCB_base[]; 104 | extern u8_t memp_memory_TCP_PCB_LISTEN_base[]; 105 | extern u8_t memp_memory_TCP_SEG_base[] SHMEM_ATTR; 106 | #endif /* LWIP_TCP */ 107 | 108 | #if (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) /* LWIP_TIMERS */ 109 | extern u8_t memp_memory_SYS_TIMEOUT_base[]; 110 | #endif /* LWIP_TIMERS */ 111 | 112 | extern u8_t memp_memory_PBUF_base[]; 113 | extern u8_t memp_memory_PBUF_POOL_base[]; 114 | 115 | 116 | 117 | #endif /* __ARCH_CC_H__ */ 118 | -------------------------------------------------------------------------------- /lwip/include/arch/perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | */ 34 | #ifndef __PERF_H__ 35 | #define __PERF_H__ 36 | 37 | #define PERF_START /* null definition */ 38 | #define PERF_STOP(x) /* null definition */ 39 | 40 | #endif /* __PERF_H__ */ 41 | -------------------------------------------------------------------------------- /lwip/include/arch/sys_arch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martin-ger/lwip_nat_arduino/ca2bdc9f37203b9061064e0fdfa78f293a84e2b2/lwip/include/arch/sys_arch.h -------------------------------------------------------------------------------- /lwip/include/lwip/api_msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_API_MSG_H__ 33 | #define __LWIP_API_MSG_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ 38 | 39 | #include /* for size_t */ 40 | 41 | #include "lwip/ip_addr.h" 42 | #include "lwip/err.h" 43 | #include "lwip/sys.h" 44 | #include "lwip/igmp.h" 45 | #include "lwip/api.h" 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /* For the netconn API, these values are use as a bitmask! */ 52 | #define NETCONN_SHUT_RD 1 53 | #define NETCONN_SHUT_WR 2 54 | #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR) 55 | 56 | /* IP addresses and port numbers are expected to be in 57 | * the same byte order as in the corresponding pcb. 58 | */ 59 | /** This struct includes everything that is necessary to execute a function 60 | for a netconn in another thread context (mainly used to process netconns 61 | in the tcpip_thread context to be thread safe). */ 62 | struct api_msg_msg { 63 | /** The netconn which to process - always needed: it includes the semaphore 64 | which is used to block the application thread until the function finished. */ 65 | struct netconn *conn; 66 | /** The return value of the function executed in tcpip_thread. */ 67 | err_t err; 68 | /** Depending on the executed function, one of these union members is used */ 69 | union { 70 | /** used for do_send */ 71 | struct netbuf *b; 72 | /** used for do_newconn */ 73 | struct { 74 | u8_t proto; 75 | } n; 76 | /** used for do_bind and do_connect */ 77 | struct { 78 | ip_addr_t *ipaddr; 79 | u16_t port; 80 | } bc; 81 | /** used for do_getaddr */ 82 | struct { 83 | ip_addr_t *ipaddr; 84 | u16_t *port; 85 | u8_t local; 86 | } ad; 87 | /** used for do_write */ 88 | struct { 89 | const void *dataptr; 90 | size_t len; 91 | u8_t apiflags; 92 | } w; 93 | /** used for do_recv */ 94 | struct { 95 | u32_t len; 96 | } r; 97 | /** used for do_close (/shutdown) */ 98 | struct { 99 | u8_t shut; 100 | } sd; 101 | #if LWIP_IGMP 102 | /** used for do_join_leave_group */ 103 | struct { 104 | ip_addr_t *multiaddr; 105 | ip_addr_t *netif_addr; 106 | enum netconn_igmp join_or_leave; 107 | } jl; 108 | #endif /* LWIP_IGMP */ 109 | #if TCP_LISTEN_BACKLOG 110 | struct { 111 | u8_t backlog; 112 | } lb; 113 | #endif /* TCP_LISTEN_BACKLOG */ 114 | } msg; 115 | }; 116 | 117 | /** This struct contains a function to execute in another thread context and 118 | a struct api_msg_msg that serves as an argument for this function. 119 | This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */ 120 | struct api_msg { 121 | /** function to execute in tcpip_thread context */ 122 | void (* function)(struct api_msg_msg *msg); 123 | /** arguments for this function */ 124 | struct api_msg_msg msg; 125 | }; 126 | 127 | #if LWIP_DNS 128 | /** As do_gethostbyname requires more arguments but doesn't require a netconn, 129 | it has its own struct (to avoid struct api_msg getting bigger than necessary). 130 | do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg 131 | (see netconn_gethostbyname). */ 132 | struct dns_api_msg { 133 | /** Hostname to query or dotted IP address string */ 134 | const char *name; 135 | /** Rhe resolved address is stored here */ 136 | ip_addr_t *addr; 137 | /** This semaphore is posted when the name is resolved, the application thread 138 | should wait on it. */ 139 | sys_sem_t *sem; 140 | /** Errors are given back here */ 141 | err_t *err; 142 | }; 143 | #endif /* LWIP_DNS */ 144 | 145 | void do_newconn ( struct api_msg_msg *msg); 146 | void do_delconn ( struct api_msg_msg *msg); 147 | void do_bind ( struct api_msg_msg *msg); 148 | void do_connect ( struct api_msg_msg *msg); 149 | void do_disconnect ( struct api_msg_msg *msg); 150 | void do_listen ( struct api_msg_msg *msg); 151 | void do_send ( struct api_msg_msg *msg); 152 | void do_recv ( struct api_msg_msg *msg); 153 | void do_write ( struct api_msg_msg *msg); 154 | void do_getaddr ( struct api_msg_msg *msg); 155 | void do_close ( struct api_msg_msg *msg); 156 | void do_shutdown ( struct api_msg_msg *msg); 157 | #if LWIP_IGMP 158 | void do_join_leave_group( struct api_msg_msg *msg); 159 | #endif /* LWIP_IGMP */ 160 | 161 | #if LWIP_DNS 162 | void do_gethostbyname(void *arg); 163 | #endif /* LWIP_DNS */ 164 | 165 | struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback); 166 | void netconn_free(struct netconn *conn); 167 | 168 | #ifdef __cplusplus 169 | } 170 | #endif 171 | 172 | #endif /* LWIP_NETCONN */ 173 | 174 | #endif /* __LWIP_API_MSG_H__ */ 175 | -------------------------------------------------------------------------------- /lwip/include/lwip/app/dhcpserver.h: -------------------------------------------------------------------------------- 1 | #ifndef __DHCPS_H__ 2 | #define __DHCPS_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define USE_DNS 9 | 10 | typedef struct dhcps_state{ 11 | sint16_t state; 12 | } dhcps_state; 13 | 14 | typedef struct dhcps_msg { 15 | uint8_t op, htype, hlen, hops; 16 | uint8_t xid[4]; 17 | uint16_t secs, flags; 18 | uint8_t ciaddr[4]; 19 | uint8_t yiaddr[4]; 20 | uint8_t siaddr[4]; 21 | uint8_t giaddr[4]; 22 | uint8_t chaddr[16]; 23 | uint8_t sname[64]; 24 | uint8_t file[128]; 25 | uint8_t options[312]; 26 | }dhcps_msg; 27 | 28 | #ifndef LWIP_OPEN_SRC 29 | struct dhcps_lease { 30 | bool enable; 31 | struct ip_addr start_ip; 32 | struct ip_addr end_ip; 33 | }; 34 | 35 | enum dhcps_offer_option{ 36 | OFFER_START = 0x00, 37 | OFFER_ROUTER = 0x01, 38 | OFFER_END 39 | }; 40 | #endif 41 | 42 | typedef enum { 43 | DHCPS_TYPE_DYNAMIC, 44 | DHCPS_TYPE_STATIC 45 | } dhcps_type_t; 46 | 47 | typedef enum { 48 | DHCPS_STATE_ONLINE, 49 | DHCPS_STATE_OFFLINE 50 | } dhcps_state_t; 51 | 52 | struct dhcps_pool{ 53 | struct ip_addr ip; 54 | uint8 mac[6]; 55 | uint32 lease_timer; 56 | dhcps_type_t type; 57 | dhcps_state_t state; 58 | 59 | }; 60 | 61 | typedef struct _list_node{ 62 | void *pnode; 63 | struct _list_node *pnext; 64 | }list_node; 65 | 66 | extern uint32 dhcps_lease_time; 67 | #define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0 68 | #define DHCPS_MAX_LEASE 0x64 69 | #define BOOTP_BROADCAST 0x8000 70 | 71 | #define DHCP_REQUEST 1 72 | #define DHCP_REPLY 2 73 | #define DHCP_HTYPE_ETHERNET 1 74 | #define DHCP_HLEN_ETHERNET 6 75 | #define DHCP_MSG_LEN 236 76 | 77 | #define DHCPS_SERVER_PORT 67 78 | #define DHCPS_CLIENT_PORT 68 79 | 80 | #define DHCPDISCOVER 1 81 | #define DHCPOFFER 2 82 | #define DHCPREQUEST 3 83 | #define DHCPDECLINE 4 84 | #define DHCPACK 5 85 | #define DHCPNAK 6 86 | #define DHCPRELEASE 7 87 | 88 | #define DHCP_OPTION_SUBNET_MASK 1 89 | #define DHCP_OPTION_ROUTER 3 90 | #define DHCP_OPTION_DNS_SERVER 6 91 | #define DHCP_OPTION_REQ_IPADDR 50 92 | #define DHCP_OPTION_LEASE_TIME 51 93 | #define DHCP_OPTION_MSG_TYPE 53 94 | #define DHCP_OPTION_SERVER_ID 54 95 | #define DHCP_OPTION_INTERFACE_MTU 26 96 | #define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31 97 | #define DHCP_OPTION_BROADCAST_ADDRESS 28 98 | #define DHCP_OPTION_REQ_LIST 55 99 | #define DHCP_OPTION_END 255 100 | 101 | //#define USE_CLASS_B_NET 1 102 | #define DHCPS_DEBUG 0 103 | #define MAX_STATION_NUM 8 104 | 105 | #define DHCPS_STATE_OFFER 1 106 | #define DHCPS_STATE_DECLINE 2 107 | #define DHCPS_STATE_ACK 3 108 | #define DHCPS_STATE_NAK 4 109 | #define DHCPS_STATE_IDLE 5 110 | #define DHCPS_STATE_RELEASE 6 111 | 112 | #define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0) 113 | 114 | void dhcps_start(struct ip_info *info); 115 | void dhcps_stop(void); 116 | 117 | void dhcps_set_DNS(struct ip_addr *dns_ip) ICACHE_FLASH_ATTR; 118 | struct dhcps_pool *dhcps_get_mapping(uint16_t no) ICACHE_FLASH_ATTR; 119 | void dhcps_set_mapping(struct ip_addr *addr, uint8 *mac, uint32 lease_time) ICACHE_FLASH_ATTR; 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif 126 | 127 | -------------------------------------------------------------------------------- /lwip/include/lwip/app/espconn_buf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ringbuf.h 3 | * 4 | * Created on: Apr 22, 2016 5 | * Author: liuhan 6 | */ 7 | 8 | #ifndef _ESPCONN_BUF_H_ 9 | #define _ESPCONN_BUF_H_ 10 | 11 | /* 12 | * ringbuffer.c 13 | * 14 | * Created on: Apr 22, 2016 15 | * Author: liuhan 16 | */ 17 | #include "c_types.h" 18 | 19 | #include "ets_sys.h" 20 | #include "os_type.h" 21 | 22 | typedef struct ringbuf_t { 23 | uint8_t *buf; 24 | uint8_t *head, *tail; 25 | size_t size; 26 | } ringbuf, *ringbuf_t; 27 | 28 | ringbuf_t ringbuf_new(size_t capacity); 29 | 30 | size_t ringbuf_buffer_size(const struct ringbuf_t *rb); 31 | 32 | void ringbuf_reset(ringbuf_t rb); 33 | 34 | void ringbuf_free(ringbuf_t *rb); 35 | 36 | size_t ringbuf_capacity(const struct ringbuf_t *rb); 37 | 38 | size_t ringbuf_bytes_free(const struct ringbuf_t *rb); 39 | 40 | size_t ringbuf_bytes_used(const struct ringbuf_t *rb); 41 | 42 | int ringbuf_is_full(const struct ringbuf_t *rb); 43 | 44 | int ringbuf_is_empty(const struct ringbuf_t *rb); 45 | 46 | const void* ringbuf_tail(const struct ringbuf_t *rb); 47 | 48 | const void* ringbuf_head(const struct ringbuf_t *rb); 49 | 50 | static uint8_t *ringbuf_nextp(ringbuf_t rb, const uint8_t *p); 51 | 52 | size_t ringbuf_findchr(const struct ringbuf_t *rb, int c, size_t offset); 53 | 54 | size_t ringbuf_memset(ringbuf_t dst, int c, size_t len); 55 | 56 | void *ringbuf_memcpy_into(ringbuf_t dst, const void *src, size_t count); 57 | 58 | void *ringbuf_memcpy_from(void *dst, ringbuf_t src, size_t count); 59 | 60 | #endif /* RINGBUF_H_ */ 61 | -------------------------------------------------------------------------------- /lwip/include/lwip/app/espconn_tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ESPCONN_TCP_H__ 2 | #define __ESPCONN_TCP_H__ 3 | 4 | #ifndef ESPCONN_TCP_DEBUG 5 | #define ESPCONN_TCP_DEBUG LWIP_DBG_OFF 6 | #endif 7 | #include "lwip/app/espconn.h" 8 | 9 | #ifndef ESPCONN_TCP_TIMER 10 | #define ESPCONN_TCP_TIMER 40 11 | #endif 12 | 13 | #define espconn_keepalive_enable(pcb) ((pcb)->so_options |= SOF_KEEPALIVE) 14 | #define espconn_keepalive_disable(pcb) ((pcb)->so_options &= ~SOF_KEEPALIVE) 15 | 16 | /****************************************************************************** 17 | * FunctionName : espconn_kill_oldest_pcb 18 | * Description : A oldest incoming connection has been killed. 19 | * Parameters : none 20 | * Returns : none 21 | *******************************************************************************/ 22 | 23 | extern void espconn_kill_oldest_pcb(void); 24 | 25 | /****************************************************************************** 26 | * FunctionName : espconn_tcp_disconnect 27 | * Description : A new incoming connection has been disconnected. 28 | * Parameters : espconn -- the espconn used to disconnect with host 29 | * Returns : none 30 | *******************************************************************************/ 31 | 32 | extern void espconn_tcp_disconnect(espconn_msg *pdiscon,u8 type); 33 | 34 | /****************************************************************************** 35 | * FunctionName : espconn_tcp_client 36 | * Description : Initialize the client: set up a connect PCB and bind it to 37 | * the defined port 38 | * Parameters : espconn -- the espconn used to build client 39 | * Returns : none 40 | *******************************************************************************/ 41 | 42 | extern sint8 espconn_tcp_client(struct espconn* espconn); 43 | 44 | /****************************************************************************** 45 | * FunctionName : espconn_tcp_server 46 | * Description : Initialize the server: set up a listening PCB and bind it to 47 | * the defined port 48 | * Parameters : espconn -- the espconn used to build server 49 | * Returns : none 50 | *******************************************************************************/ 51 | 52 | extern sint8 espconn_tcp_server(struct espconn *espconn); 53 | 54 | #endif /* __CLIENT_TCP_H__ */ 55 | 56 | -------------------------------------------------------------------------------- /lwip/include/lwip/app/espconn_udp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ESPCONN_UDP_H__ 2 | #define __ESPCONN_UDP_H__ 3 | 4 | #ifndef ESPCONN_UDP_DEBUG 5 | #define ESPCONN_UDP_DEBUG LWIP_DBG_OFF 6 | #endif 7 | 8 | #include "lwip/app/espconn.h" 9 | 10 | /****************************************************************************** 11 | * FunctionName : espconn_udp_client 12 | * Description : Initialize the client: set up a PCB and bind it to the port 13 | * Parameters : pespconn -- the espconn used to build client 14 | * Returns : none 15 | *******************************************************************************/ 16 | 17 | extern sint8 espconn_udp_client(struct espconn *pespconn); 18 | 19 | /****************************************************************************** 20 | * FunctionName : espconn_udp_disconnect 21 | * Description : A new incoming connection has been disconnected. 22 | * Parameters : espconn -- the espconn used to disconnect with host 23 | * Returns : none 24 | *******************************************************************************/ 25 | 26 | extern void espconn_udp_disconnect(espconn_msg *pdiscon); 27 | 28 | /****************************************************************************** 29 | * FunctionName : espconn_udp_server 30 | * Description : Initialize the server: set up a PCB and bind it to the port 31 | * Parameters : pespconn -- the espconn used to build server 32 | * Returns : none 33 | *******************************************************************************/ 34 | 35 | extern sint8 espconn_udp_server(struct espconn *espconn); 36 | 37 | /****************************************************************************** 38 | * FunctionName : espconn_udp_sent 39 | * Description : sent data for client or server 40 | * Parameters : void *arg -- client or server to send 41 | * uint8* psent -- Data to send 42 | * uint16 length -- Length of data to send 43 | * Returns : none 44 | *******************************************************************************/ 45 | 46 | extern err_t espconn_udp_sent(void *arg, uint8 *psent, uint16 length); 47 | 48 | /****************************************************************************** 49 | * FunctionName : espconn_udp_sendto 50 | * Description : sent data for UDP 51 | * Parameters : void *arg -- UDP to send 52 | * uint8* psent -- Data to send 53 | * uint16 length -- Length of data to send 54 | * Returns : return espconn error code. 55 | * - ESPCONN_OK. Successful. No error occured. 56 | * - ESPCONN_MEM. Out of memory. 57 | * - ESPCONN_RTE. Could not find route to destination address. 58 | * - More errors could be returned by lower protocol layers. 59 | *******************************************************************************/ 60 | extern err_t espconn_udp_sendto(void *arg, uint8 *psent, uint16 length); 61 | 62 | #endif /* __ESPCONN_UDP_H__ */ 63 | 64 | 65 | -------------------------------------------------------------------------------- /lwip/include/lwip/app/ping.h: -------------------------------------------------------------------------------- 1 | #ifndef __PING_H__ 2 | #define __PING_H__ 3 | #include "lwip/ip_addr.h" 4 | #include "lwip/icmp.h" 5 | /** 6 | * PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used 7 | */ 8 | #ifndef PING_USE_SOCKETS 9 | #define PING_USE_SOCKETS LWIP_SOCKET 10 | #endif 11 | 12 | /** 13 | * PING_DEBUG: Enable debugging for PING. 14 | */ 15 | #ifndef PING_DEBUG 16 | #define PING_DEBUG LWIP_DBG_OFF 17 | #endif 18 | 19 | /** ping receive timeout - in milliseconds */ 20 | #ifndef PING_RCV_TIMEO 21 | #define PING_RCV_TIMEO 1000 22 | #endif 23 | 24 | /** ping delay - in milliseconds */ 25 | #ifndef PING_COARSE 26 | #define PING_COARSE 1000 27 | #endif 28 | 29 | /** ping identifier - must fit on a u16_t */ 30 | #ifndef PING_ID 31 | #define PING_ID 0xAFAF 32 | #endif 33 | 34 | /** ping additional data size to include in the packet */ 35 | #ifndef PING_DATA_SIZE 36 | #define PING_DATA_SIZE 32 37 | #endif 38 | 39 | /** ping result action - no default action */ 40 | #ifndef PING_RESULT 41 | #define PING_RESULT(ping_ok) 42 | #endif 43 | 44 | #define DEFAULT_PING_MAX_COUNT 4 45 | #define PING_TIMEOUT_MS 1000 46 | 47 | typedef void (* ping_recv_function)(void* arg, void *pdata); 48 | typedef void (* ping_sent_function)(void* arg, void *pdata); 49 | 50 | struct ping_option{ 51 | uint32 count; 52 | uint32 ip; 53 | uint32 coarse_time; 54 | ping_recv_function recv_function; 55 | ping_sent_function sent_function; 56 | void* reverse; 57 | }; 58 | 59 | struct ping_msg{ 60 | struct ping_option *ping_opt; 61 | struct raw_pcb *ping_pcb; 62 | uint32 ping_start; 63 | uint32 ping_sent; 64 | uint32 timeout_count; 65 | uint32 max_count; 66 | uint32 sent_count; 67 | uint32 coarse_time; 68 | }; 69 | 70 | struct ping_resp{ 71 | uint32 total_count; 72 | uint32 resp_time; 73 | uint32 seqno; 74 | uint32 timeout_count; 75 | uint32 bytes; 76 | uint32 total_bytes; 77 | uint32 total_time; 78 | sint8 ping_err; 79 | }; 80 | 81 | bool ping_start(struct ping_option *ping_opt); 82 | bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv); 83 | bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent); 84 | 85 | #endif /* __PING_H__ */ 86 | -------------------------------------------------------------------------------- /lwip/include/lwip/app/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * time.h 3 | * 4 | * Created on: May 31, 2016 5 | * Author: liuhan 6 | */ 7 | 8 | #ifndef TIME_H_ 9 | #define TIME_H_ 10 | #include "osapi.h" 11 | #include "os_type.h" 12 | #include "lwip/sntp.h" 13 | 14 | struct timeval { 15 | unsigned long tv_sec; /* seconds */ 16 | unsigned long tv_usec; /* and microseconds */ 17 | }; 18 | 19 | /***************************RTC TIME OPTION***************************************/ 20 | // daylight settings 21 | // Base calculated with value obtained from NTP server (64 bits) 22 | #define sntp_base (*((uint64_t*)RTC_STORE0)) 23 | // Timer value when base was obtained 24 | #define TIM_REF_SET(value) WRITE_PERI_REG(RTC_STORE2, value) 25 | #define TIM_REF_GET() READ_PERI_REG(RTC_STORE2) 26 | 27 | // Setters and getters for CAL, TZ and DST. 28 | #define RTC_CAL_SET(val) do {uint32 value = READ_PERI_REG(RTC_STORE3);\ 29 | value |= ((val) & 0x0000FFFF);\ 30 | WRITE_PERI_REG(RTC_STORE3, value);\ 31 | }while(0) 32 | #define RTC_DST_SET(val) do {uint32 value = READ_PERI_REG(RTC_STORE3);\ 33 | value |= (((val)<<16) & 0x00010000);\ 34 | WRITE_PERI_REG(RTC_STORE3, value);\ 35 | }while(0) 36 | #define RTC_TZ_SET(val) do {uint32 value = READ_PERI_REG(RTC_STORE3);\ 37 | value |= (((val)<<24) & 0xFF000000);\ 38 | WRITE_PERI_REG(RTC_STORE3, value);\ 39 | }while(0) 40 | 41 | #define RTC_CAL_GET() (READ_PERI_REG(RTC_STORE3) & 0x0000FFFF) 42 | #define RTC_DST_GET() ((READ_PERI_REG(RTC_STORE3) & 0x00010000)>>16) 43 | #define RTC_TZ_GET() ((((int)READ_PERI_REG(RTC_STORE3)) & ((int)0xFF000000))>>24) 44 | void system_update_rtc(time_t t, uint32_t us); 45 | time_t sntp_get_rtc_time(sint32_t *us); 46 | 47 | int gettimeofday(struct timeval* t, void* timezone); 48 | void updateTime(uint32 ms); 49 | bool configTime(int timezone, int daylightOffset, char *server1, char *server2, char *server3, bool enable); 50 | time_t time(time_t *t); 51 | unsigned long millis(void); 52 | unsigned long micros(void); 53 | #endif /* TIME_H_ */ 54 | -------------------------------------------------------------------------------- /lwip/include/lwip/autoip.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * AutoIP Automatic LinkLocal IP Configuration 5 | */ 6 | 7 | /* 8 | * 9 | * Copyright (c) 2007 Dominik Spies 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without modification, 13 | * are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 | * OF SUCH DAMAGE. 33 | * 34 | * Author: Dominik Spies 35 | * 36 | * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform 37 | * with RFC 3927. 38 | * 39 | * 40 | * Please coordinate changes and requests with Dominik Spies 41 | * 42 | */ 43 | 44 | #ifndef __LWIP_AUTOIP_H__ 45 | #define __LWIP_AUTOIP_H__ 46 | 47 | #include "lwip/opt.h" 48 | 49 | #if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */ 50 | 51 | #include "lwip/netif.h" 52 | #include "lwip/udp.h" 53 | #include "netif/etharp.h" 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | /* AutoIP Timing */ 60 | #define AUTOIP_TMR_INTERVAL 100 61 | #define AUTOIP_TICKS_PER_SECOND (1000 / AUTOIP_TMR_INTERVAL) 62 | 63 | /* RFC 3927 Constants */ 64 | #define PROBE_WAIT 1 /* second (initial random delay) */ 65 | #define PROBE_MIN 1 /* second (minimum delay till repeated probe) */ 66 | #define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */ 67 | #define PROBE_NUM 3 /* (number of probe packets) */ 68 | #define ANNOUNCE_NUM 2 /* (number of announcement packets) */ 69 | #define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */ 70 | #define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */ 71 | #define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */ 72 | #define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */ 73 | #define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */ 74 | 75 | /* AutoIP client states */ 76 | #define AUTOIP_STATE_OFF 0 77 | #define AUTOIP_STATE_PROBING 1 78 | #define AUTOIP_STATE_ANNOUNCING 2 79 | #define AUTOIP_STATE_BOUND 3 80 | 81 | struct autoip 82 | { 83 | ip_addr_t llipaddr; /* the currently selected, probed, announced or used LL IP-Address */ 84 | u8_t state; /* current AutoIP state machine state */ 85 | u8_t sent_num; /* sent number of probes or announces, dependent on state */ 86 | u16_t ttw; /* ticks to wait, tick is AUTOIP_TMR_INTERVAL long */ 87 | u8_t lastconflict; /* ticks until a conflict can be solved by defending */ 88 | u8_t tried_llipaddr; /* total number of probed/used Link Local IP-Addresses */ 89 | }; 90 | 91 | 92 | /** Init srand, has to be called before entering mainloop */ 93 | void autoip_init(void); 94 | 95 | /** Set a struct autoip allocated by the application to work with */ 96 | void autoip_set_struct(struct netif *netif, struct autoip *autoip); 97 | 98 | /** Start AutoIP client */ 99 | err_t autoip_start(struct netif *netif); 100 | 101 | /** Stop AutoIP client */ 102 | err_t autoip_stop(struct netif *netif); 103 | 104 | /** Handles every incoming ARP Packet, called by etharp_arp_input */ 105 | void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr); 106 | 107 | /** Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds */ 108 | void autoip_tmr(void); 109 | 110 | /** Handle a possible change in the network configuration */ 111 | void autoip_network_changed(struct netif *netif); 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | 117 | #endif /* LWIP_AUTOIP */ 118 | 119 | #endif /* __LWIP_AUTOIP_H__ */ 120 | -------------------------------------------------------------------------------- /lwip/include/lwip/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_DEBUG_H__ 33 | #define __LWIP_DEBUG_H__ 34 | 35 | #include "lwipopts.h" 36 | #include "lwip/arch.h" 37 | 38 | /** lower two bits indicate debug level 39 | * - 0 all 40 | * - 1 warning 41 | * - 2 serious 42 | * - 3 severe 43 | */ 44 | #define LWIP_DBG_LEVEL_ALL 0x00 45 | #define LWIP_DBG_LEVEL_OFF LWIP_DBG_LEVEL_ALL /* compatibility define only */ 46 | #define LWIP_DBG_LEVEL_WARNING 0x01 /* bad checksums, dropped packets, ... */ 47 | #define LWIP_DBG_LEVEL_SERIOUS 0x02 /* memory allocation failures, ... */ 48 | #define LWIP_DBG_LEVEL_SEVERE 0x03 49 | #define LWIP_DBG_MASK_LEVEL 0x03 50 | 51 | /** flag for LWIP_DEBUGF to enable that debug message */ 52 | #define LWIP_DBG_ON 0x80U 53 | /** flag for LWIP_DEBUGF to disable that debug message */ 54 | #define LWIP_DBG_OFF 0x00U 55 | 56 | /** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */ 57 | #define LWIP_DBG_TRACE 0x40U 58 | /** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */ 59 | #define LWIP_DBG_STATE 0x20U 60 | /** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */ 61 | #define LWIP_DBG_FRESH 0x10U 62 | /** flag for LWIP_DEBUGF to halt after printing this debug message */ 63 | #define LWIP_DBG_HALT 0x08U 64 | 65 | #ifndef LWIP_NOASSERT 66 | #define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \ 67 | LWIP_PLATFORM_ASSERT(message); } while(0) 68 | #else /* LWIP_NOASSERT */ 69 | #define LWIP_ASSERT(message, assertion) 70 | #endif /* LWIP_NOASSERT */ 71 | 72 | /** if "expression" isn't true, then print "message" and execute "handler" expression */ 73 | #ifndef LWIP_ERROR 74 | #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ 75 | LWIP_PLATFORM_ASSERT(message); handler;}} while(0) 76 | #endif /* LWIP_ERROR */ 77 | 78 | #ifdef LWIP_DEBUG 79 | /** print debug message only if debug message type is enabled... 80 | * AND is of correct type AND is at least LWIP_DBG_LEVEL 81 | */ 82 | #define LWIP_DEBUGF(debug, message) do { \ 83 | if ( \ 84 | ((debug) & LWIP_DBG_ON) && \ 85 | ((debug) & LWIP_DBG_TYPES_ON) && \ 86 | ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \ 87 | LWIP_PLATFORM_DIAG(message); \ 88 | if ((debug) & LWIP_DBG_HALT) { \ 89 | while(1); \ 90 | } \ 91 | } \ 92 | } while(0) 93 | 94 | #else /* LWIP_DEBUG */ 95 | #define LWIP_DEBUGF(debug, message) 96 | #endif /* LWIP_DEBUG */ 97 | 98 | #endif /* __LWIP_DEBUG_H__ */ 99 | 100 | -------------------------------------------------------------------------------- /lwip/include/lwip/def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_DEF_H__ 33 | #define __LWIP_DEF_H__ 34 | 35 | /* arch.h might define NULL already */ 36 | #include "lwip/arch.h" 37 | #include "lwip/opt.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y)) 44 | #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y)) 45 | 46 | #ifndef NULL 47 | #define NULL ((void *)0) 48 | #endif 49 | 50 | /** Get the absolute difference between 2 u32_t values (correcting overflows) 51 | * 'a' is expected to be 'higher' (without overflow) than 'b'. */ 52 | #define LWIP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1))) 53 | 54 | /* Endianess-optimized shifting of two u8_t to create one u16_t */ 55 | #if BYTE_ORDER == LITTLE_ENDIAN 56 | #define LWIP_MAKE_U16(a, b) ((a << 8) | b) 57 | #else 58 | #define LWIP_MAKE_U16(a, b) ((b << 8) | a) 59 | #endif 60 | 61 | #ifndef LWIP_PLATFORM_BYTESWAP 62 | #define LWIP_PLATFORM_BYTESWAP 0 63 | #endif 64 | 65 | #ifndef LWIP_PREFIX_BYTEORDER_FUNCS 66 | /* workaround for naming collisions on some platforms */ 67 | 68 | #ifdef htons 69 | #undef htons 70 | #endif /* htons */ 71 | #ifdef htonl 72 | #undef htonl 73 | #endif /* htonl */ 74 | #ifdef ntohs 75 | #undef ntohs 76 | #endif /* ntohs */ 77 | #ifdef ntohl 78 | #undef ntohl 79 | #endif /* ntohl */ 80 | 81 | #define htons(x) lwip_htons(x) 82 | #define ntohs(x) lwip_ntohs(x) 83 | #define htonl(x) lwip_htonl(x) 84 | #define ntohl(x) lwip_ntohl(x) 85 | #endif /* LWIP_PREFIX_BYTEORDER_FUNCS */ 86 | 87 | #if BYTE_ORDER == BIG_ENDIAN 88 | #define lwip_htons(x) (x) 89 | #define lwip_ntohs(x) (x) 90 | #define lwip_htonl(x) (x) 91 | #define lwip_ntohl(x) (x) 92 | #define PP_HTONS(x) (x) 93 | #define PP_NTOHS(x) (x) 94 | #define PP_HTONL(x) (x) 95 | #define PP_NTOHL(x) (x) 96 | #else /* BYTE_ORDER != BIG_ENDIAN */ 97 | #if LWIP_PLATFORM_BYTESWAP 98 | #define lwip_htons(x) LWIP_PLATFORM_HTONS(x) 99 | #define lwip_ntohs(x) LWIP_PLATFORM_HTONS(x) 100 | #define lwip_htonl(x) LWIP_PLATFORM_HTONL(x) 101 | #define lwip_ntohl(x) LWIP_PLATFORM_HTONL(x) 102 | #else /* LWIP_PLATFORM_BYTESWAP */ 103 | u16_t lwip_htons(u16_t x); 104 | u16_t lwip_ntohs(u16_t x); 105 | u32_t lwip_htonl(u32_t x); 106 | u32_t lwip_ntohl(u32_t x); 107 | #endif /* LWIP_PLATFORM_BYTESWAP */ 108 | 109 | /* These macros should be calculated by the preprocessor and are used 110 | with compile-time constants only (so that there is no little-endian 111 | overhead at runtime). */ 112 | #define PP_HTONS(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8)) 113 | #define PP_NTOHS(x) PP_HTONS(x) 114 | #define PP_HTONL(x) ((((x) & 0xff) << 24) | \ 115 | (((x) & 0xff00) << 8) | \ 116 | (((x) & 0xff0000UL) >> 8) | \ 117 | (((x) & 0xff000000UL) >> 24)) 118 | #define PP_NTOHL(x) PP_HTONL(x) 119 | 120 | #endif /* BYTE_ORDER == BIG_ENDIAN */ 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif /* __LWIP_DEF_H__ */ 127 | 128 | -------------------------------------------------------------------------------- /lwip/include/lwip/dns.h: -------------------------------------------------------------------------------- 1 | /** 2 | * lwip DNS resolver header file. 3 | 4 | * Author: Jim Pettinato 5 | * April 2007 6 | 7 | * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. The name of the author may not be used to endorse or promote 18 | * products derived from this software without specific prior 19 | * written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef __LWIP_DNS_H__ 35 | #define __LWIP_DNS_H__ 36 | 37 | #include "lwip/opt.h" 38 | 39 | #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */ 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /** DNS timer period */ 46 | #define DNS_TMR_INTERVAL 1000 47 | 48 | /** DNS field TYPE used for "Resource Records" */ 49 | #define DNS_RRTYPE_A 1 /* a host address */ 50 | #define DNS_RRTYPE_NS 2 /* an authoritative name server */ 51 | #define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */ 52 | #define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */ 53 | #define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */ 54 | #define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */ 55 | #define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */ 56 | #define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */ 57 | #define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */ 58 | #define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */ 59 | #define DNS_RRTYPE_WKS 11 /* a well known service description */ 60 | #define DNS_RRTYPE_PTR 12 /* a domain name pointer */ 61 | #define DNS_RRTYPE_HINFO 13 /* host information */ 62 | #define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */ 63 | #define DNS_RRTYPE_MX 15 /* mail exchange */ 64 | #define DNS_RRTYPE_TXT 16 /* text strings */ 65 | 66 | /** DNS field CLASS used for "Resource Records" */ 67 | #define DNS_RRCLASS_IN 1 /* the Internet */ 68 | #define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */ 69 | #define DNS_RRCLASS_CH 3 /* the CHAOS class */ 70 | #define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ 71 | #define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ 72 | 73 | /* The size used for the next line is rather a hack, but it prevents including socket.h in all files 74 | that include memp.h, and that would possibly break portability (since socket.h defines some types 75 | and constants possibly already define by the OS). 76 | Calculation rule: 77 | sizeof(struct addrinfo) + sizeof(struct sockaddr_in) + DNS_MAX_NAME_LENGTH + 1 byte zero-termination */ 78 | #define NETDB_ELEM_SIZE (32 + 16 + DNS_MAX_NAME_LENGTH + 1) 79 | 80 | #if DNS_LOCAL_HOSTLIST 81 | /** struct used for local host-list */ 82 | struct local_hostlist_entry { 83 | /** static hostname */ 84 | const char *name; 85 | /** static host address in network byteorder */ 86 | ip_addr_t addr; 87 | struct local_hostlist_entry *next; 88 | }; 89 | #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC 90 | #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN 91 | #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH 92 | #endif 93 | #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1)) 94 | #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 95 | #endif /* DNS_LOCAL_HOSTLIST */ 96 | 97 | /** Callback which is invoked when a hostname is found. 98 | * A function of this type must be implemented by the application using the DNS resolver. 99 | * @param name pointer to the name that was looked up. 100 | * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname, 101 | * or NULL if the name could not be found (or on any other error). 102 | * @param callback_arg a user-specified callback argument passed to dns_gethostbyname 103 | */ 104 | typedef void (*dns_found_callback)(const char *name, ip_addr_t *ipaddr, void *callback_arg); 105 | 106 | void dns_init(void); 107 | void dns_tmr(void); 108 | void dns_setserver(u8_t numdns, ip_addr_t *dnsserver); 109 | ip_addr_t dns_getserver(u8_t numdns); 110 | err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr, 111 | dns_found_callback found, void *callback_arg); 112 | 113 | #if DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC 114 | int dns_local_removehost(const char *hostname, const ip_addr_t *addr); 115 | err_t dns_local_addhost(const char *hostname, const ip_addr_t *addr); 116 | #endif /* DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* LWIP_DNS */ 123 | 124 | #endif /* __LWIP_DNS_H__ */ 125 | -------------------------------------------------------------------------------- /lwip/include/lwip/err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_ERR_H__ 33 | #define __LWIP_ERR_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "lwip/arch.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** Define LWIP_ERR_T in cc.h if you want to use 43 | * a different type for your platform (must be signed). */ 44 | #ifdef LWIP_ERR_T 45 | typedef LWIP_ERR_T err_t; 46 | #else /* LWIP_ERR_T */ 47 | typedef s8_t err_t; 48 | #endif /* LWIP_ERR_T*/ 49 | 50 | /* Definitions for error constants. */ 51 | 52 | #define ERR_OK 0 /* No error, everything OK. */ 53 | #define ERR_MEM -1 /* Out of memory error. */ 54 | #define ERR_BUF -2 /* Buffer error. */ 55 | #define ERR_TIMEOUT -3 /* Timeout. */ 56 | #define ERR_RTE -4 /* Routing problem. */ 57 | #define ERR_INPROGRESS -5 /* Operation in progress */ 58 | #define ERR_VAL -6 /* Illegal value. */ 59 | #define ERR_WOULDBLOCK -7 /* Operation would block. */ 60 | 61 | #define ERR_IS_FATAL(e) ((e) < ERR_WOULDBLOCK) 62 | 63 | #define ERR_ABRT -8 /* Connection aborted. */ 64 | #define ERR_RST -9 /* Connection reset. */ 65 | #define ERR_CLSD -10 /* Connection closed. */ 66 | #define ERR_CONN -11 /* Not connected. */ 67 | 68 | #define ERR_ARG -12 /* Illegal argument. */ 69 | 70 | #define ERR_USE -13 /* Address in use. */ 71 | 72 | #define ERR_IF -14 /* Low-level netif error */ 73 | #define ERR_ISCONN -15 /* Already connected. */ 74 | 75 | 76 | #ifdef LWIP_DEBUG 77 | extern const char *lwip_strerr(err_t err)ICACHE_FLASH_ATTR; 78 | #else 79 | #define lwip_strerr(x) "" 80 | #endif /* LWIP_DEBUG */ 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif /* __LWIP_ERR_H__ */ 87 | -------------------------------------------------------------------------------- /lwip/include/lwip/icmp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martin-ger/lwip_nat_arduino/ca2bdc9f37203b9061064e0fdfa78f293a84e2b2/lwip/include/lwip/icmp.h -------------------------------------------------------------------------------- /lwip/include/lwip/igmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 CITEL Technologies Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is a contribution to the lwIP TCP/IP stack. 30 | * The Swedish Institute of Computer Science and Adam Dunkels 31 | * are specifically granted permission to redistribute this 32 | * source code. 33 | */ 34 | 35 | #ifndef __LWIP_IGMP_H__ 36 | #define __LWIP_IGMP_H__ 37 | 38 | #include "lwip/opt.h" 39 | #include "lwip/ip_addr.h" 40 | #include "lwip/netif.h" 41 | #include "lwip/pbuf.h" 42 | 43 | #if LWIP_IGMP /* don't build if not configured for use in lwipopts.h */ 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | 50 | /* IGMP timer */ 51 | #define IGMP_TMR_INTERVAL 100 /* Milliseconds */ 52 | #define IGMP_V1_DELAYING_MEMBER_TMR (1000/IGMP_TMR_INTERVAL) 53 | #define IGMP_JOIN_DELAYING_MEMBER_TMR (500 /IGMP_TMR_INTERVAL) 54 | 55 | /* MAC Filter Actions, these are passed to a netif's 56 | * igmp_mac_filter callback function. */ 57 | #define IGMP_DEL_MAC_FILTER 0 58 | #define IGMP_ADD_MAC_FILTER 1 59 | 60 | 61 | /** 62 | * igmp group structure - there is 63 | * a list of groups for each interface 64 | * these should really be linked from the interface, but 65 | * if we keep them separate we will not affect the lwip original code 66 | * too much 67 | * 68 | * There will be a group for the all systems group address but this 69 | * will not run the state machine as it is used to kick off reports 70 | * from all the other groups 71 | */ 72 | struct igmp_group { 73 | /** next link */ 74 | struct igmp_group *next; 75 | /** interface on which the group is active */ 76 | struct netif *netif; 77 | /** multicast address */ 78 | ip_addr_t group_address; 79 | /** signifies we were the last person to report */ 80 | u8_t last_reporter_flag; 81 | /** current state of the group */ 82 | u8_t group_state; 83 | /** timer for reporting, negative is OFF */ 84 | u16_t timer; 85 | /** counter of simultaneous uses */ 86 | u8_t use; 87 | }; 88 | 89 | /* Prototypes */ 90 | void igmp_init(void)ICACHE_FLASH_ATTR; 91 | err_t igmp_start(struct netif *netif)ICACHE_FLASH_ATTR; 92 | err_t igmp_stop(struct netif *netif)ICACHE_FLASH_ATTR; 93 | void igmp_report_groups(struct netif *netif)ICACHE_FLASH_ATTR; 94 | struct igmp_group *igmp_lookfor_group(struct netif *ifp, ip_addr_t *addr)ICACHE_FLASH_ATTR; 95 | void igmp_input(struct pbuf *p, struct netif *inp, ip_addr_t *dest)ICACHE_FLASH_ATTR; 96 | err_t igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR; 97 | err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR; 98 | void igmp_tmr(void)ICACHE_FLASH_ATTR; 99 | #define LWIP_RAND() os_random() 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif /* LWIP_IGMP */ 105 | 106 | #endif /* __LWIP_IGMP_H__ */ 107 | -------------------------------------------------------------------------------- /lwip/include/lwip/inet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INET_H__ 33 | #define __LWIP_INET_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "lwip/def.h" 37 | #include "lwip/ip_addr.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** For compatibility with BSD code */ 44 | struct in_addr { 45 | u32_t s_addr; 46 | }; 47 | 48 | /** 255.255.255.255 */ 49 | #define INADDR_NONE IPADDR_NONE 50 | /** 127.0.0.1 */ 51 | #define INADDR_LOOPBACK IPADDR_LOOPBACK 52 | /** 0.0.0.0 */ 53 | #define INADDR_ANY IPADDR_ANY 54 | /** 255.255.255.255 */ 55 | #define INADDR_BROADCAST IPADDR_BROADCAST 56 | 57 | /* Definitions of the bits in an Internet address integer. 58 | 59 | On subnets, host and network parts are found according to 60 | the subnet mask, not these masks. */ 61 | #define IN_CLASSA(a) IP_CLASSA(a) 62 | #define IN_CLASSA_NET IP_CLASSA_NET 63 | #define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT 64 | #define IN_CLASSA_HOST IP_CLASSA_HOST 65 | #define IN_CLASSA_MAX IP_CLASSA_MAX 66 | 67 | #define IN_CLASSB(b) IP_CLASSB(b) 68 | #define IN_CLASSB_NET IP_CLASSB_NET 69 | #define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT 70 | #define IN_CLASSB_HOST IP_CLASSB_HOST 71 | #define IN_CLASSB_MAX IP_CLASSB_MAX 72 | 73 | #define IN_CLASSC(c) IP_CLASSC(c) 74 | #define IN_CLASSC_NET IP_CLASSC_NET 75 | #define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT 76 | #define IN_CLASSC_HOST IP_CLASSC_HOST 77 | #define IN_CLASSC_MAX IP_CLASSC_MAX 78 | 79 | #define IN_CLASSD(d) IP_CLASSD(d) 80 | #define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */ 81 | #define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */ 82 | #define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */ 83 | #define IN_CLASSD_MAX IP_CLASSD_MAX 84 | 85 | #define IN_MULTICAST(a) IP_MULTICAST(a) 86 | 87 | #define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a) 88 | #define IN_BADCLASS(a) IP_BADCLASS(a) 89 | 90 | #define IN_LOOPBACKNET IP_LOOPBACKNET 91 | 92 | #define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) 93 | #define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) 94 | /* ATTENTION: the next define only works because both s_addr and ip_addr_t are an u32_t effectively! */ 95 | #define inet_addr_to_ipaddr_p(target_ipaddr_p, source_inaddr) ((target_ipaddr_p) = (ip_addr_t*)&((source_inaddr)->s_addr)) 96 | 97 | /* directly map this to the lwip internal functions */ 98 | #define inet_addr(cp) ipaddr_addr(cp) 99 | #define inet_aton(cp, addr) ipaddr_aton(cp, (ip_addr_t*)addr) 100 | #define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr)) 101 | #define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((ip_addr_t*)&(addr), buf, buflen) 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* __LWIP_INET_H__ */ 108 | -------------------------------------------------------------------------------- /lwip/include/lwip/inet_chksum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INET_CHKSUM_H__ 33 | #define __LWIP_INET_CHKSUM_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #include "lwip/pbuf.h" 38 | #include "lwip/ip_addr.h" 39 | 40 | /** Swap the bytes in an u16_t: much like htons() for little-endian */ 41 | #ifndef SWAP_BYTES_IN_WORD 42 | #if LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) 43 | /* little endian and PLATFORM_BYTESWAP defined */ 44 | #define SWAP_BYTES_IN_WORD(w) LWIP_PLATFORM_HTONS(w) 45 | #else /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) */ 46 | /* can't use htons on big endian (or PLATFORM_BYTESWAP not defined)... */ 47 | #define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8) 48 | #endif /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN)*/ 49 | #endif /* SWAP_BYTES_IN_WORD */ 50 | 51 | /** Split an u32_t in two u16_ts and add them up */ 52 | #ifndef FOLD_U32T 53 | #define FOLD_U32T(u) (((u) >> 16) + ((u) & 0x0000ffffUL)) 54 | #endif 55 | 56 | #if LWIP_CHECKSUM_ON_COPY 57 | /** Function-like macro: same as MEMCPY but returns the checksum of copied data 58 | as u16_t */ 59 | #ifndef LWIP_CHKSUM_COPY 60 | #define LWIP_CHKSUM_COPY(dst, src, len) lwip_chksum_copy(dst, src, len) 61 | #ifndef LWIP_CHKSUM_COPY_ALGORITHM 62 | #define LWIP_CHKSUM_COPY_ALGORITHM 1 63 | #endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 64 | #endif /* LWIP_CHKSUM_COPY */ 65 | #else /* LWIP_CHECKSUM_ON_COPY */ 66 | #define LWIP_CHKSUM_COPY_ALGORITHM 0 67 | #endif /* LWIP_CHECKSUM_ON_COPY */ 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | u16_t inet_chksum(void *dataptr, u16_t len)ICACHE_FLASH_ATTR; 74 | u16_t inet_chksum_pbuf(struct pbuf *p)ICACHE_FLASH_ATTR; 75 | u16_t inet_chksum_pseudo(struct pbuf *p, 76 | ip_addr_t *src, ip_addr_t *dest, 77 | u8_t proto, u16_t proto_len)ICACHE_FLASH_ATTR; 78 | u16_t inet_chksum_pseudo_partial(struct pbuf *p, 79 | ip_addr_t *src, ip_addr_t *dest, 80 | u8_t proto, u16_t proto_len, u16_t chksum_len)ICACHE_FLASH_ATTR; 81 | #if LWIP_CHKSUM_COPY_ALGORITHM 82 | u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len)ICACHE_FLASH_ATTR; 83 | #endif /* LWIP_CHKSUM_COPY_ALGORITHM */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* __LWIP_INET_H__ */ 90 | 91 | -------------------------------------------------------------------------------- /lwip/include/lwip/init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INIT_H__ 33 | #define __LWIP_INIT_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** X.x.x: Major version of the stack */ 42 | #define LWIP_VERSION_MAJOR 1U 43 | /** x.X.x: Minor version of the stack */ 44 | #define LWIP_VERSION_MINOR 4U 45 | /** x.x.X: Revision of the stack */ 46 | #define LWIP_VERSION_REVISION 0U 47 | /** For release candidates, this is set to 1..254 48 | * For official releases, this is set to 255 (LWIP_RC_RELEASE) 49 | * For development versions (CVS), this is set to 0 (LWIP_RC_DEVELOPMENT) */ 50 | #define LWIP_VERSION_RC 2U 51 | 52 | /** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ 53 | #define LWIP_RC_RELEASE 255U 54 | /** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for CVS versions */ 55 | #define LWIP_RC_DEVELOPMENT 0U 56 | 57 | #define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) 58 | #define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) 59 | #define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) 60 | 61 | /** Provides the version of the stack */ 62 | #define LWIP_VERSION (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 | \ 63 | LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC) 64 | 65 | /* Modules initialization */ 66 | void lwip_init(void) ICACHE_FLASH_ATTR; 67 | //void lwip_init(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __LWIP_INIT_H__ */ 74 | -------------------------------------------------------------------------------- /lwip/include/lwip/ip_frag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Jani Monoses 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_IP_FRAG_H__ 34 | #define __LWIP_IP_FRAG_H__ 35 | 36 | #include "lwip/opt.h" 37 | #include "lwip/err.h" 38 | #include "lwip/pbuf.h" 39 | #include "lwip/netif.h" 40 | #include "lwip/ip_addr.h" 41 | #include "lwip/ip.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #if IP_REASSEMBLY 48 | /* The IP reassembly timer interval in milliseconds. */ 49 | #define IP_TMR_INTERVAL 1000 50 | 51 | /* IP reassembly helper struct. 52 | * This is exported because memp needs to know the size. 53 | */ 54 | struct ip_reassdata { 55 | struct ip_reassdata *next; 56 | struct pbuf *p; 57 | struct ip_hdr iphdr; 58 | u16_t datagram_len; 59 | u8_t flags; 60 | u8_t timer; 61 | }; 62 | 63 | void ip_reass_init(void)ICACHE_FLASH_ATTR; 64 | void ip_reass_tmr(void)ICACHE_FLASH_ATTR; 65 | struct pbuf * ip_reass(struct pbuf *p)ICACHE_FLASH_ATTR; 66 | #endif /* IP_REASSEMBLY */ 67 | 68 | #if IP_FRAG 69 | #if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF 70 | /** A custom pbuf that holds a reference to another pbuf, which is freed 71 | * when this custom pbuf is freed. This is used to create a custom PBUF_REF 72 | * that points into the original pbuf. */ 73 | struct pbuf_custom_ref { 74 | /** 'base class' */ 75 | struct pbuf_custom pc; 76 | /** pointer to the original pbuf that is referenced */ 77 | struct pbuf *original; 78 | }; 79 | #endif /* !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ 80 | 81 | err_t ip_frag(struct pbuf *p, struct netif *netif, ip_addr_t *dest)ICACHE_FLASH_ATTR; 82 | #endif /* IP_FRAG */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* __LWIP_IP_FRAG_H__ */ 89 | -------------------------------------------------------------------------------- /lwip/include/lwip/ip_route.h: -------------------------------------------------------------------------------- 1 | #ifndef __LWIP_IP_ROUTE_H__ 2 | #define __LWIP_IP_ROUTE_H__ 3 | 4 | #include "lwip/opt.h" 5 | #include "lwip/ip_addr.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define MAX_ROUTES 10 12 | 13 | struct route_entry { 14 | ip_addr_t ip; 15 | ip_addr_t mask; 16 | ip_addr_t gw; 17 | }; 18 | 19 | extern struct route_entry ip_rt_table[MAX_ROUTES]; 20 | extern int ip_route_max; 21 | 22 | /* Add a static route, true on success */ 23 | bool ip_add_route(ip_addr_t ip, ip_addr_t mask, ip_addr_t gw); 24 | 25 | /* Remove a static route, true on success */ 26 | bool ip_rm_route(ip_addr_t ip, ip_addr_t mask); 27 | 28 | /* Finds a route entry for an address, NULL if none */ 29 | struct route_entry *ip_find_route(ip_addr_t ip); 30 | 31 | /* Delete all static routes */ 32 | void ip_delete_routes(void); 33 | 34 | /* Returns the n_th entry of the routing table, true on success */ 35 | bool ip_get_route(uint32_t no, ip_addr_t *ip, ip_addr_t *mask, ip_addr_t *gw); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* __LWIP_IP_ROUTE_H__ */ 42 | -------------------------------------------------------------------------------- /lwip/include/lwip/lwip_napt.h: -------------------------------------------------------------------------------- 1 | #ifndef __LWIP_NAPT_H__ 2 | #define __LWIP_NAPT_H__ 3 | 4 | #include "lwip/opt.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #if IP_FORWARD 11 | #if IP_NAPT 12 | 13 | /* Default size of the tables used for NAPT */ 14 | #define IP_NAPT_MAX 512 15 | #define IP_PORTMAP_MAX 32 16 | 17 | /* Timeouts in sec for the various protocol types */ 18 | #define IP_NAPT_TIMEOUT_MS_TCP (30*60*1000) 19 | #define IP_NAPT_TIMEOUT_MS_TCP_DISCON (20*1000) 20 | #define IP_NAPT_TIMEOUT_MS_UDP (2*1000) 21 | #define IP_NAPT_TIMEOUT_MS_ICMP (2*1000) 22 | 23 | #define IP_NAPT_PORT_RANGE_START 49152 24 | #define IP_NAPT_PORT_RANGE_END 61439 25 | 26 | struct napt_table { 27 | u32_t last; 28 | u32_t src; 29 | u32_t dest; 30 | u16_t sport; 31 | u16_t dport; 32 | u16_t mport; 33 | u8_t proto; 34 | u8_t fin1 : 1; 35 | u8_t fin2 : 1; 36 | u8_t finack1 : 1; 37 | u8_t finack2 : 1; 38 | u8_t synack : 1; 39 | u8_t rst : 1; 40 | u16_t next, prev; 41 | }; 42 | 43 | struct portmap_table { 44 | u32_t maddr; 45 | u32_t daddr; 46 | u16_t mport; 47 | u16_t dport; 48 | u8_t proto; 49 | u8 valid; 50 | }; 51 | 52 | extern struct portmap_table *ip_portmap_table; 53 | 54 | /** 55 | * Allocates and initializes the NAPT tables. 56 | * 57 | * @param max_nat max number of enties in the NAPT table (use IP_NAPT_MAX if in doubt) 58 | * @param max_portmap max number of enties in the NAPT table (use IP_PORTMAP_MAX if in doubt) 59 | */ 60 | void 61 | ip_napt_init(uint16_t max_nat, uint8_t max_portmap); 62 | 63 | 64 | /** 65 | * Enable/Disable NAPT for a specified interface. 66 | * 67 | * @param addr ip address of the interface 68 | * @param enable non-zero to enable NAPT, or 0 to disable. 69 | */ 70 | void 71 | ip_napt_enable(u32_t addr, int enable); 72 | 73 | 74 | /** 75 | * Enable/Disable NAPT for a specified interface. 76 | * 77 | * @param netif number of the interface 78 | * @param enable non-zero to enable NAPT, or 0 to disable. 79 | */ 80 | void 81 | ip_napt_enable_no(u8_t number, int enable); 82 | 83 | 84 | /** 85 | * Register port mapping on the external interface to internal interface. 86 | * When the same port mapping is registered again, the old mapping is overwritten. 87 | * In this implementation, only 1 unique port mapping can be defined for each target address/port. 88 | * 89 | * @param proto target protocol 90 | * @param maddr ip address of the external interface 91 | * @param mport mapped port on the external interface, in host byte order. 92 | * @param daddr destination ip address 93 | * @param dport destination port, in host byte order. 94 | */ 95 | u8_t 96 | ip_portmap_add(u8_t proto, u32_t maddr, u16_t mport, u32_t daddr, u16_t dport); 97 | 98 | 99 | /** 100 | * Unregister port mapping on the external interface to internal interface. 101 | * 102 | * @param proto target protocol 103 | * @param maddr ip address of the external interface 104 | */ 105 | u8_t 106 | ip_portmap_remove(u8_t proto, u16_t mport); 107 | 108 | 109 | /** 110 | * Sets the NAPT timeout for TCP connections. 111 | * 112 | * @param secs timeout in secs 113 | */ 114 | void 115 | ip_napt_set_tcp_timeout(u32_t secs); 116 | 117 | 118 | /** 119 | * Sets the NAPT timeout for UDP 'connections'. 120 | * 121 | * @param secs timeout in secs 122 | */ 123 | void 124 | ip_napt_set_udp_timeout(u32_t secs); 125 | 126 | #endif /* IP_NAPT */ 127 | #endif /* IP_FORWARD */ 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* __LWIP_NAPT_H__ */ 134 | -------------------------------------------------------------------------------- /lwip/include/lwip/mdns.h: -------------------------------------------------------------------------------- 1 | /** 2 | * lwip MDNS resolver header file. 3 | * 4 | * Created on: Jul 29, 2010 5 | * Author: Daniel Toma 6 | 7 | 8 | * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. The name of the author may not be used to endorse or promote 19 | * products derived from this software without specific prior 20 | * written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 23 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 26 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 28 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __LWIP_MDNS_H__ 36 | #define __LWIP_MDNS_H__ 37 | 38 | #include "lwip/opt.h" 39 | 40 | #if LWIP_MDNS /* don't build if not configured for use in lwipopts.h */ 41 | 42 | /** DNS timer period */ 43 | #define DNS_TMR_INTERVAL 1000 44 | 45 | /** mDNS Address offset flag*/ 46 | #define DNS_OFFSET_FLAG 0xC0 /* the offset flag in the DNS message */ 47 | #define DNS_DEFAULT_OFFSET 0x0C /* the offset is set at the beginning of the DNS message */ 48 | 49 | #define DNS_IP_ADDR_LEN 4 50 | 51 | 52 | /** DNS field TYPE used for "Resource Records" */ 53 | #define DNS_RRTYPE_A 1 /* a host address */ 54 | #define DNS_RRTYPE_NS 2 /* an authoritative name server */ 55 | #define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */ 56 | #define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */ 57 | #define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */ 58 | #define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */ 59 | #define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */ 60 | #define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */ 61 | #define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */ 62 | #define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */ 63 | #define DNS_RRTYPE_WKS 11 /* a well known service description */ 64 | #define DNS_RRTYPE_PTR 12 /* a domain name pointer */ 65 | #define DNS_RRTYPE_HINFO 13 /* host information */ 66 | #define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */ 67 | #define DNS_RRTYPE_MX 15 /* mail exchange */ 68 | #define DNS_RRTYPE_TXT 16 /* text strings */ 69 | #define DNS_RRTYPE_SRV 33 /* Service record */ 70 | #define DNS_RRTYPE_OPT 41 /* EDNS0 OPT record */ 71 | #define DNS_RRTYPE_TSIG 250 /* Transaction Signature */ 72 | #define DNS_RRTYPE_ANY 255 /*Not a DNS type, but a DNS query type, meaning "all types"*/ 73 | 74 | /* DNS field CLASS used for "Resource Records" */ 75 | #define DNS_RRCLASS_IN 1 /* the Internet */ 76 | #define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */ 77 | #define DNS_RRCLASS_CH 3 /* the CHAOS class */ 78 | #define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ 79 | #define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ 80 | #define DNS_RRCLASS_FLUSH_IN 0x8001/* Flush bit and Internet*/ 81 | 82 | /** Callback which is invoked when a hostname is found. 83 | * A function of this type must be implemented by the application using the DNS resolver. 84 | * @param name pointer to the name that was looked up. 85 | * @param ipaddr pointer to a struct ip_addr containing the IP address of the hostname, 86 | * or NULL if the name could not be found (or on any other error). 87 | * @param callback_arg a user-specified callback argument passed to dns_gethostbyname 88 | */ 89 | #ifndef _MDNS_INFO 90 | #define _MDNS_INFO 91 | struct mdns_info { 92 | char *host_name; 93 | char *server_name; 94 | uint16 server_port; 95 | unsigned long ipAddr; 96 | char *txt_data[10]; 97 | }; 98 | #endif 99 | //void mdns_enable(void); 100 | //void mdns_disable(void); 101 | //void mdns_init(struct mdns_info *info); 102 | //void mdns_close(void); 103 | //char* mdns_get_hostname(void); 104 | //void mdns_set_hostname(char *name); 105 | //void mdns_set_servername(const char *name); 106 | //char* mdns_get_servername(void); 107 | //void mdns_server_unregister(void); 108 | //void mdns_server_register(void) ; 109 | //void mdns_tmr(void); 110 | //void Delay(unsigned long ulSeconds); 111 | 112 | #endif /* LWIP_MDNS */ 113 | 114 | #endif /* __LWIP_MDNS_H__ */ 115 | -------------------------------------------------------------------------------- /lwip/include/lwip/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_MEM_H__ 33 | #define __LWIP_MEM_H__ 34 | 35 | #include "lwip/opt.h" 36 | //#include "mem_manager.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #if MEM_LIBC_MALLOC 43 | 44 | #include /* for size_t */ 45 | 46 | typedef size_t mem_size_t; 47 | 48 | /* aliases for C library malloc() */ 49 | #define mem_init() 50 | /* in case C library malloc() needs extra protection, 51 | * allow these defines to be overridden. 52 | */ 53 | #ifndef mem_free 54 | #define mem_free(p) vPortFree(p, "", 0) 55 | #endif 56 | #ifndef mem_malloc 57 | #define mem_malloc(s) pvPortMalloc(s, "", 0) 58 | #endif 59 | #ifndef mem_calloc 60 | #define mem_calloc(s) pvPortCalloc(s, "", 0) 61 | #endif 62 | #ifndef mem_realloc 63 | #define mem_realloc(p, s) pvPortRealloc(p, s, "", 0) 64 | #endif 65 | #ifndef mem_zalloc 66 | #define mem_zalloc(s) pvPortZalloc(s, "", 0) 67 | #endif 68 | 69 | #ifndef os_malloc 70 | #define os_malloc(s) mem_malloc((s)) 71 | #endif 72 | #ifndef os_realloc 73 | #define os_realloc(p, s) mem_realloc((p), (s)) 74 | #endif 75 | #ifndef os_zalloc 76 | #define os_zalloc(s) mem_zalloc((s)) 77 | #endif 78 | #ifndef os_free 79 | #define os_free(p) mem_free((p)) 80 | #endif 81 | 82 | /* Since there is no C library allocation function to shrink memory without 83 | moving it, define this to nothing. */ 84 | #ifndef mem_trim 85 | #define mem_trim(mem, size) (mem) 86 | #endif 87 | #else /* MEM_LIBC_MALLOC */ 88 | 89 | /* MEM_SIZE would have to be aligned, but using 64000 here instead of 90 | * 65535 leaves some room for alignment... 91 | */ 92 | #if MEM_SIZE > 64000l 93 | typedef u32_t mem_size_t; 94 | #define MEM_SIZE_F U32_F 95 | #else 96 | typedef u16_t mem_size_t; 97 | #define MEM_SIZE_F U16_F 98 | #endif /* MEM_SIZE > 64000 */ 99 | 100 | #if MEM_USE_POOLS 101 | /** mem_init is not used when using pools instead of a heap */ 102 | #define mem_init() 103 | /** mem_trim is not used when using pools instead of a heap: 104 | we can't free part of a pool element and don't want to copy the rest */ 105 | #define mem_trim(mem, size) (mem) 106 | #else /* MEM_USE_POOLS */ 107 | /* lwIP alternative malloc */ 108 | void mem_init(void)ICACHE_FLASH_ATTR; 109 | void *mem_trim(void *mem, mem_size_t size)ICACHE_FLASH_ATTR; 110 | #endif /* MEM_USE_POOLS */ 111 | void *mem_malloc(mem_size_t size)ICACHE_FLASH_ATTR; 112 | void *mem_calloc(mem_size_t count, mem_size_t size)ICACHE_FLASH_ATTR; 113 | void mem_free(void *mem)ICACHE_FLASH_ATTR; 114 | #endif /* MEM_LIBC_MALLOC */ 115 | 116 | /** Calculate memory size for an aligned buffer - returns the next highest 117 | * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and 118 | * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4). 119 | */ 120 | #ifndef LWIP_MEM_ALIGN_SIZE 121 | #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1)) 122 | #endif 123 | 124 | /** Calculate safe memory size for an aligned buffer when using an unaligned 125 | * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the 126 | * start (e.g. if buffer is u8_t[] and actual data will be u32_t*) 127 | */ 128 | #ifndef LWIP_MEM_ALIGN_BUFFER 129 | #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1)) 130 | #endif 131 | 132 | /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT 133 | * so that ADDR % MEM_ALIGNMENT == 0 134 | */ 135 | #ifndef LWIP_MEM_ALIGN 136 | #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1))) 137 | #endif 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __LWIP_MEM_H__ */ 144 | -------------------------------------------------------------------------------- /lwip/include/lwip/memp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_MEMP_H__ 34 | #define __LWIP_MEMP_H__ 35 | 36 | #include "lwip/opt.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */ 43 | typedef enum { 44 | #define LWIP_MEMPOOL(name,num,size,desc, attr) MEMP_##name, 45 | #include "lwip/memp_std.h" 46 | MEMP_MAX 47 | } memp_t; 48 | 49 | #if MEM_USE_POOLS 50 | /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */ 51 | typedef enum { 52 | /* Get the first (via: 53 | MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/ 54 | MEMP_POOL_HELPER_FIRST = ((u8_t) 55 | #define LWIP_MEMPOOL(name,num,size,desc) 56 | #define LWIP_MALLOC_MEMPOOL_START 1 57 | #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0 58 | #define LWIP_MALLOC_MEMPOOL_END 59 | #include "lwip/memp_std.h" 60 | ) , 61 | /* Get the last (via: 62 | MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */ 63 | MEMP_POOL_HELPER_LAST = ((u8_t) 64 | #define LWIP_MEMPOOL(name,num,size,desc) 65 | #define LWIP_MALLOC_MEMPOOL_START 66 | #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size * 67 | #define LWIP_MALLOC_MEMPOOL_END 1 68 | #include "lwip/memp_std.h" 69 | ) 70 | } memp_pool_helper_t; 71 | 72 | /* The actual start and stop values are here (cast them over) 73 | We use this helper type and these defines so we can avoid using const memp_t values */ 74 | #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST) 75 | #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST) 76 | #endif /* MEM_USE_POOLS */ 77 | 78 | #if MEMP_MEM_MALLOC || MEM_USE_POOLS 79 | extern const u32_t memp_sizes[MEMP_MAX]; 80 | #endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */ 81 | 82 | #if MEMP_MEM_MALLOC 83 | 84 | #include "mem.h" 85 | 86 | #define memp_init() 87 | #define memp_malloc(type) mem_malloc(memp_sizes[type]) 88 | #define memp_free(type, mem) mem_free(mem) 89 | 90 | #else /* MEMP_MEM_MALLOC */ 91 | 92 | #if MEM_USE_POOLS 93 | /** This structure is used to save the pool one element came from. */ 94 | struct memp_malloc_helper 95 | { 96 | memp_t poolnr; 97 | }; 98 | #endif /* MEM_USE_POOLS */ 99 | 100 | void memp_init(void)ICACHE_FLASH_ATTR; 101 | 102 | #if MEMP_OVERFLOW_CHECK 103 | void *memp_malloc_fn(memp_t type, const char* file, const int line)ICACHE_FLASH_ATTR; 104 | #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__) 105 | #else 106 | void *memp_malloc(memp_t type)ICACHE_FLASH_ATTR; 107 | #endif 108 | void memp_free(memp_t type, void *mem)ICACHE_FLASH_ATTR; 109 | 110 | #endif /* MEMP_MEM_MALLOC */ 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif /* __LWIP_MEMP_H__ */ 117 | -------------------------------------------------------------------------------- /lwip/include/lwip/memp_std.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SETUP: Make sure we define everything we will need. 3 | * 4 | * We have create three types of pools: 5 | * 1) MEMPOOL - standard pools 6 | * 2) MALLOC_MEMPOOL - to be used by mem_malloc in mem.c 7 | * 3) PBUF_MEMPOOL - a mempool of pbuf's, so include space for the pbuf struct 8 | * 9 | * If the include'r doesn't require any special treatment of each of the types 10 | * above, then will declare #2 & #3 to be just standard mempools. 11 | */ 12 | #ifndef LWIP_MALLOC_MEMPOOL 13 | /* This treats "malloc pools" just like any other pool. 14 | The pools are a little bigger to provide 'size' as the amount of user data. */ 15 | #define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + sizeof(struct memp_malloc_helper)), "MALLOC_"#size, attr) 16 | #define LWIP_MALLOC_MEMPOOL_START 17 | #define LWIP_MALLOC_MEMPOOL_END 18 | #endif /* LWIP_MALLOC_MEMPOOL */ 19 | 20 | #ifndef LWIP_PBUF_MEMPOOL 21 | /* This treats "pbuf pools" just like any other pool. 22 | * Allocates buffers for a pbuf struct AND a payload size */ 23 | #define LWIP_PBUF_MEMPOOL(name, num, payload, desc, attr) LWIP_MEMPOOL(name, num, (MEMP_ALIGN_SIZE(sizeof(struct pbuf)) + MEMP_ALIGN_SIZE(payload)), desc, attr) 24 | #endif /* LWIP_PBUF_MEMPOOL */ 25 | 26 | 27 | /* 28 | * A list of internal pools used by LWIP. 29 | * 30 | * LWIP_MEMPOOL(pool_name, number_elements, element_size, pool_description) 31 | * creates a pool name MEMP_pool_name. description is used in stats.c 32 | */ 33 | #if LWIP_RAW 34 | LWIP_MEMPOOL(RAW_PCB, MEMP_NUM_RAW_PCB, sizeof(struct raw_pcb), "RAW_PCB", DMEM_ATTR) 35 | #endif /* LWIP_RAW */ 36 | 37 | #if LWIP_UDP 38 | LWIP_MEMPOOL(UDP_PCB, MEMP_NUM_UDP_PCB, sizeof(struct udp_pcb), "UDP_PCB", DMEM_ATTR) 39 | #endif /* LWIP_UDP */ 40 | 41 | #if LWIP_TCP 42 | LWIP_MEMPOOL(TCP_PCB, MEMP_NUM_TCP_PCB, sizeof(struct tcp_pcb), "TCP_PCB", DMEM_ATTR) 43 | LWIP_MEMPOOL(TCP_PCB_LISTEN, MEMP_NUM_TCP_PCB_LISTEN, sizeof(struct tcp_pcb_listen), "TCP_PCB_LISTEN", DMEM_ATTR) 44 | LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg), "TCP_SEG", DMEM_ATTR) 45 | #endif /* LWIP_TCP */ 46 | 47 | #if IP_REASSEMBLY 48 | LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA", DMEM_ATTR) 49 | #endif /* IP_REASSEMBLY */ 50 | #if IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF 51 | LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF", DMEM_ATTR) 52 | #endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ 53 | 54 | #if LWIP_NETCONN 55 | LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF") 56 | LWIP_MEMPOOL(NETCONN, MEMP_NUM_NETCONN, sizeof(struct netconn), "NETCONN") 57 | #endif /* LWIP_NETCONN */ 58 | 59 | #if NO_SYS==0 60 | LWIP_MEMPOOL(TCPIP_MSG_API, MEMP_NUM_TCPIP_MSG_API, sizeof(struct tcpip_msg), "TCPIP_MSG_API") 61 | #if !LWIP_TCPIP_CORE_LOCKING_INPUT 62 | LWIP_MEMPOOL(TCPIP_MSG_INPKT,MEMP_NUM_TCPIP_MSG_INPKT, sizeof(struct tcpip_msg), "TCPIP_MSG_INPKT") 63 | #endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ 64 | #endif /* NO_SYS==0 */ 65 | 66 | #if ARP_QUEUEING 67 | LWIP_MEMPOOL(ARP_QUEUE, MEMP_NUM_ARP_QUEUE, sizeof(struct etharp_q_entry), "ARP_QUEUE", DMEM_ATTR) 68 | #endif /* ARP_QUEUEING */ 69 | 70 | #if LWIP_IGMP 71 | LWIP_MEMPOOL(IGMP_GROUP, MEMP_NUM_IGMP_GROUP, sizeof(struct igmp_group), "IGMP_GROUP", DMEM_ATTR) 72 | #endif /* LWIP_IGMP */ 73 | 74 | #if (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) /* LWIP_TIMERS */ 75 | LWIP_MEMPOOL(SYS_TIMEOUT, MEMP_NUM_SYS_TIMEOUT, sizeof(struct sys_timeo), "SYS_TIMEOUT", DMEM_ATTR) 76 | #endif /* LWIP_TIMERS */ 77 | 78 | #if LWIP_SNMP 79 | LWIP_MEMPOOL(SNMP_ROOTNODE, MEMP_NUM_SNMP_ROOTNODE, sizeof(struct mib_list_rootnode), "SNMP_ROOTNODE") 80 | LWIP_MEMPOOL(SNMP_NODE, MEMP_NUM_SNMP_NODE, sizeof(struct mib_list_node), "SNMP_NODE") 81 | LWIP_MEMPOOL(SNMP_VARBIND, MEMP_NUM_SNMP_VARBIND, sizeof(struct snmp_varbind), "SNMP_VARBIND") 82 | LWIP_MEMPOOL(SNMP_VALUE, MEMP_NUM_SNMP_VALUE, SNMP_MAX_VALUE_SIZE, "SNMP_VALUE") 83 | #endif /* LWIP_SNMP */ 84 | #if LWIP_DNS && LWIP_SOCKET 85 | LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE, "NETDB") 86 | #endif /* LWIP_DNS && LWIP_SOCKET */ 87 | #if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC 88 | LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST") 89 | #endif /* LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ 90 | #if PPP_SUPPORT && PPPOE_SUPPORT 91 | LWIP_MEMPOOL(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF") 92 | #endif /* PPP_SUPPORT && PPPOE_SUPPORT */ 93 | 94 | /* 95 | * A list of pools of pbuf's used by LWIP. 96 | * 97 | * LWIP_PBUF_MEMPOOL(pool_name, number_elements, pbuf_payload_size, pool_description) 98 | * creates a pool name MEMP_pool_name. description is used in stats.c 99 | * This allocates enough space for the pbuf struct and a payload. 100 | * (Example: pbuf_payload_size=0 allocates only size for the struct) 101 | */ 102 | LWIP_PBUF_MEMPOOL(PBUF, MEMP_NUM_PBUF, 0, "PBUF_REF/ROM", DMEM_ATTR) 103 | 104 | /* XXX: need to align to 4 byte as memp strcut is 4-byte long. otherwise will crash */ 105 | #define LWIP_MEM_ALIGN4_SIZE(size) (((size) + 4 - 1) & ~(4-1)) 106 | 107 | LWIP_PBUF_MEMPOOL(PBUF_POOL, PBUF_POOL_SIZE, LWIP_MEM_ALIGN4_SIZE(PBUF_POOL_BUFSIZE), "PBUF_POOL", DMEM_ATTR) 108 | 109 | 110 | /* 111 | * Allow for user-defined pools; this must be explicitly set in lwipopts.h 112 | * since the default is to NOT look for lwippools.h 113 | */ 114 | #if MEMP_USE_CUSTOM_POOLS 115 | #include "lwippools.h" 116 | #endif /* MEMP_USE_CUSTOM_POOLS */ 117 | 118 | /* 119 | * REQUIRED CLEANUP: Clear up so we don't get "multiply defined" error later 120 | * (#undef is ignored for something that is not defined) 121 | */ 122 | #undef LWIP_MEMPOOL 123 | #undef LWIP_MALLOC_MEMPOOL 124 | #undef LWIP_MALLOC_MEMPOOL_START 125 | #undef LWIP_MALLOC_MEMPOOL_END 126 | #undef LWIP_PBUF_MEMPOOL 127 | -------------------------------------------------------------------------------- /lwip/include/lwip/netbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_NETBUF_H__ 33 | #define __LWIP_NETBUF_H__ 34 | 35 | #include "lwip/opt.h" 36 | #include "lwip/pbuf.h" 37 | #include "lwip/ip_addr.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** This netbuf has dest-addr/port set */ 44 | #define NETBUF_FLAG_DESTADDR 0x01 45 | /** This netbuf includes a checksum */ 46 | #define NETBUF_FLAG_CHKSUM 0x02 47 | 48 | struct netbuf { 49 | struct pbuf *p, *ptr; 50 | ip_addr_t addr; 51 | u16_t port; 52 | #if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY 53 | #if LWIP_CHECKSUM_ON_COPY 54 | u8_t flags; 55 | #endif /* LWIP_CHECKSUM_ON_COPY */ 56 | u16_t toport_chksum; 57 | #if LWIP_NETBUF_RECVINFO 58 | ip_addr_t toaddr; 59 | #endif /* LWIP_NETBUF_RECVINFO */ 60 | #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */ 61 | }; 62 | 63 | /* Network buffer functions: */ 64 | struct netbuf * netbuf_new (void)ICACHE_FLASH_ATTR; 65 | void netbuf_delete (struct netbuf *buf)ICACHE_FLASH_ATTR; 66 | void * netbuf_alloc (struct netbuf *buf, u16_t size)ICACHE_FLASH_ATTR; 67 | void netbuf_free (struct netbuf *buf)ICACHE_FLASH_ATTR; 68 | err_t netbuf_ref (struct netbuf *buf, 69 | const void *dataptr, u16_t size)ICACHE_FLASH_ATTR; 70 | void netbuf_chain (struct netbuf *head, 71 | struct netbuf *tail)ICACHE_FLASH_ATTR; 72 | 73 | err_t netbuf_data (struct netbuf *buf, 74 | void **dataptr, u16_t *len)ICACHE_FLASH_ATTR; 75 | s8_t netbuf_next (struct netbuf *buf)ICACHE_FLASH_ATTR; 76 | void netbuf_first (struct netbuf *buf)ICACHE_FLASH_ATTR; 77 | 78 | 79 | #define netbuf_copy_partial(buf, dataptr, len, offset) \ 80 | pbuf_copy_partial((buf)->p, (dataptr), (len), (offset)) 81 | #define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0) 82 | #define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len) 83 | #define netbuf_len(buf) ((buf)->p->tot_len) 84 | #define netbuf_fromaddr(buf) (&((buf)->addr)) 85 | #define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set((&(buf)->addr), fromaddr) 86 | #define netbuf_fromport(buf) ((buf)->port) 87 | #if LWIP_NETBUF_RECVINFO 88 | #define netbuf_destaddr(buf) (&((buf)->toaddr)) 89 | #define netbuf_set_destaddr(buf, destaddr) ip_addr_set((&(buf)->addr), destaddr) 90 | #define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0) 91 | #endif /* LWIP_NETBUF_RECVINFO */ 92 | #if LWIP_CHECKSUM_ON_COPY 93 | #define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \ 94 | (buf)->toport_chksum = chksum; } while(0) 95 | #endif /* LWIP_CHECKSUM_ON_COPY */ 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __LWIP_NETBUF_H__ */ 102 | -------------------------------------------------------------------------------- /lwip/include/lwip/netdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Redistribution and use in source and binary forms, with or without modification, 3 | * are permitted provided that the following conditions are met: 4 | * 5 | * 1. Redistributions of source code must retain the above copyright notice, 6 | * this list of conditions and the following disclaimer. 7 | * 2. Redistributions in binary form must reproduce the above copyright notice, 8 | * this list of conditions and the following disclaimer in the documentation 9 | * and/or other materials provided with the distribution. 10 | * 3. The name of the author may not be used to endorse or promote products 11 | * derived from this software without specific prior written permission. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 14 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 16 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 18 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 22 | * OF SUCH DAMAGE. 23 | * 24 | * This file is part of the lwIP TCP/IP stack. 25 | * 26 | * Author: Simon Goldschmidt 27 | * 28 | */ 29 | #ifndef __LWIP_NETDB_H__ 30 | #define __LWIP_NETDB_H__ 31 | 32 | #include "lwip/opt.h" 33 | 34 | #if LWIP_DNS && LWIP_SOCKET 35 | 36 | #include /* for size_t */ 37 | 38 | #include "lwip/inet.h" 39 | #include "lwip/sockets.h" 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* some rarely used options */ 46 | #ifndef LWIP_DNS_API_DECLARE_H_ERRNO 47 | #define LWIP_DNS_API_DECLARE_H_ERRNO 1 48 | #endif 49 | 50 | #ifndef LWIP_DNS_API_DEFINE_ERRORS 51 | #define LWIP_DNS_API_DEFINE_ERRORS 1 52 | #endif 53 | 54 | #ifndef LWIP_DNS_API_DECLARE_STRUCTS 55 | #define LWIP_DNS_API_DECLARE_STRUCTS 1 56 | #endif 57 | 58 | #if LWIP_DNS_API_DEFINE_ERRORS 59 | /** Errors used by the DNS API functions, h_errno can be one of them */ 60 | #define EAI_NONAME 200 61 | #define EAI_SERVICE 201 62 | #define EAI_FAIL 202 63 | #define EAI_MEMORY 203 64 | 65 | #define HOST_NOT_FOUND 210 66 | #define NO_DATA 211 67 | #define NO_RECOVERY 212 68 | #define TRY_AGAIN 213 69 | #endif /* LWIP_DNS_API_DEFINE_ERRORS */ 70 | 71 | #if LWIP_DNS_API_DECLARE_STRUCTS 72 | struct hostent { 73 | char *h_name; /* Official name of the host. */ 74 | char **h_aliases; /* A pointer to an array of pointers to alternative host names, 75 | terminated by a null pointer. */ 76 | int h_addrtype; /* Address type. */ 77 | int h_length; /* The length, in bytes, of the address. */ 78 | char **h_addr_list; /* A pointer to an array of pointers to network addresses (in 79 | network byte order) for the host, terminated by a null pointer. */ 80 | #define h_addr h_addr_list[0] /* for backward compatibility */ 81 | }; 82 | 83 | struct addrinfo { 84 | int ai_flags; /* Input flags. */ 85 | int ai_family; /* Address family of socket. */ 86 | int ai_socktype; /* Socket type. */ 87 | int ai_protocol; /* Protocol of socket. */ 88 | socklen_t ai_addrlen; /* Length of socket address. */ 89 | struct sockaddr *ai_addr; /* Socket address of socket. */ 90 | char *ai_canonname; /* Canonical name of service location. */ 91 | struct addrinfo *ai_next; /* Pointer to next in list. */ 92 | }; 93 | #endif /* LWIP_DNS_API_DECLARE_STRUCTS */ 94 | 95 | #if LWIP_DNS_API_DECLARE_H_ERRNO 96 | /* application accessable error code set by the DNS API functions */ 97 | extern int h_errno; 98 | #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/ 99 | 100 | struct hostent *lwip_gethostbyname(const char *name); 101 | int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf, 102 | size_t buflen, struct hostent **result, int *h_errnop); 103 | void lwip_freeaddrinfo(struct addrinfo *ai); 104 | int lwip_getaddrinfo(const char *nodename, 105 | const char *servname, 106 | const struct addrinfo *hints, 107 | struct addrinfo **res); 108 | 109 | #if LWIP_COMPAT_SOCKETS 110 | #define gethostbyname(name) lwip_gethostbyname(name) 111 | #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \ 112 | lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop) 113 | #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo) 114 | #define getaddrinfo(nodname, servname, hints, res) \ 115 | lwip_getaddrinfo(nodname, servname, hints, res) 116 | #endif /* LWIP_COMPAT_SOCKETS */ 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* LWIP_DNS && LWIP_SOCKET */ 123 | 124 | #endif /* __LWIP_NETDB_H__ */ 125 | -------------------------------------------------------------------------------- /lwip/include/lwip/netif.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martin-ger/lwip_nat_arduino/ca2bdc9f37203b9061064e0fdfa78f293a84e2b2/lwip/include/lwip/netif.h -------------------------------------------------------------------------------- /lwip/include/lwip/netifapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Redistribution and use in source and binary forms, with or without modification, 3 | * are permitted provided that the following conditions are met: 4 | * 5 | * 1. Redistributions of source code must retain the above copyright notice, 6 | * this list of conditions and the following disclaimer. 7 | * 2. Redistributions in binary form must reproduce the above copyright notice, 8 | * this list of conditions and the following disclaimer in the documentation 9 | * and/or other materials provided with the distribution. 10 | * 3. The name of the author may not be used to endorse or promote products 11 | * derived from this software without specific prior written permission. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 14 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 15 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 16 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 18 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 22 | * OF SUCH DAMAGE. 23 | * 24 | * This file is part of the lwIP TCP/IP stack. 25 | * 26 | */ 27 | 28 | #ifndef __LWIP_NETIFAPI_H__ 29 | #define __LWIP_NETIFAPI_H__ 30 | 31 | #include "lwip/opt.h" 32 | 33 | #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ 34 | 35 | #include "lwip/sys.h" 36 | #include "lwip/netif.h" 37 | #include "lwip/dhcp.h" 38 | #include "lwip/autoip.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef void (*netifapi_void_fn)(struct netif *netif); 45 | typedef err_t (*netifapi_errt_fn)(struct netif *netif); 46 | 47 | struct netifapi_msg_msg { 48 | #if !LWIP_TCPIP_CORE_LOCKING 49 | sys_sem_t sem; 50 | #endif /* !LWIP_TCPIP_CORE_LOCKING */ 51 | err_t err; 52 | struct netif *netif; 53 | union { 54 | struct { 55 | ip_addr_t *ipaddr; 56 | ip_addr_t *netmask; 57 | ip_addr_t *gw; 58 | void *state; 59 | netif_init_fn init; 60 | netif_input_fn input; 61 | } add; 62 | struct { 63 | netifapi_void_fn voidfunc; 64 | netifapi_errt_fn errtfunc; 65 | } common; 66 | } msg; 67 | }; 68 | 69 | struct netifapi_msg { 70 | void (* function)(struct netifapi_msg_msg *msg); 71 | struct netifapi_msg_msg msg; 72 | }; 73 | 74 | 75 | /* API for application */ 76 | err_t netifapi_netif_add ( struct netif *netif, 77 | ip_addr_t *ipaddr, 78 | ip_addr_t *netmask, 79 | ip_addr_t *gw, 80 | void *state, 81 | netif_init_fn init, 82 | netif_input_fn input); 83 | 84 | err_t netifapi_netif_set_addr ( struct netif *netif, 85 | ip_addr_t *ipaddr, 86 | ip_addr_t *netmask, 87 | ip_addr_t *gw ); 88 | 89 | err_t netifapi_netif_common ( struct netif *netif, 90 | netifapi_void_fn voidfunc, 91 | netifapi_errt_fn errtfunc); 92 | 93 | #define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL) 94 | #define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL) 95 | #define netifapi_netif_set_down(n) netifapi_netif_common(n, netif_set_down, NULL) 96 | #define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL) 97 | #define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start) 98 | #define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL) 99 | #define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start) 100 | #define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop) 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* LWIP_NETIF_API */ 107 | 108 | #endif /* __LWIP_NETIFAPI_H__ */ 109 | -------------------------------------------------------------------------------- /lwip/include/lwip/pbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_PBUF_H__ 34 | #define __LWIP_PBUF_H__ 35 | 36 | #include "lwip/opt.h" 37 | #include "lwip/err.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** Currently, the pbuf_custom code is only needed for one specific configuration 44 | * of IP_FRAG */ 45 | #define LWIP_SUPPORT_CUSTOM_PBUF (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) 46 | 47 | #define PBUF_TRANSPORT_HLEN 20 48 | #define PBUF_IP_HLEN 20 49 | 50 | typedef enum { 51 | PBUF_TRANSPORT, 52 | PBUF_IP, 53 | PBUF_LINK, 54 | PBUF_RAW 55 | } pbuf_layer; 56 | 57 | typedef enum { 58 | PBUF_RAM, /* pbuf data is stored in RAM */ 59 | PBUF_ROM, /* pbuf data is stored in ROM */ 60 | PBUF_REF, /* pbuf comes from the pbuf pool */ 61 | PBUF_POOL, /* pbuf payload refers to RAM */ 62 | #ifdef EBUF_LWIP 63 | PBUF_ESF_RX /* pbuf payload is from WLAN */ 64 | #endif /* ESF_LWIP */ 65 | } pbuf_type; 66 | 67 | 68 | /** indicates this packet's data should be immediately passed to the application */ 69 | #define PBUF_FLAG_PUSH 0x01U 70 | /** indicates this is a custom pbuf: pbuf_free and pbuf_header handle such a 71 | a pbuf differently */ 72 | #define PBUF_FLAG_IS_CUSTOM 0x02U 73 | /** indicates this pbuf is UDP multicast to be looped back */ 74 | #define PBUF_FLAG_MCASTLOOP 0x04U 75 | 76 | struct pbuf { 77 | /** next pbuf in singly linked pbuf chain */ 78 | struct pbuf *next; 79 | 80 | /** pointer to the actual data in the buffer */ 81 | void *payload; 82 | 83 | /** 84 | * total length of this buffer and all next buffers in chain 85 | * belonging to the same packet. 86 | * 87 | * For non-queue packet chains this is the invariant: 88 | * p->tot_len == p->len + (p->next? p->next->tot_len: 0) 89 | */ 90 | u16_t tot_len; 91 | 92 | /** length of this buffer */ 93 | u16_t len; 94 | 95 | /** pbuf_type as u8_t instead of enum to save space */ 96 | u8_t /*pbuf_type*/ type; 97 | 98 | /** misc flags */ 99 | u8_t flags; 100 | 101 | /** 102 | * the reference count always equals the number of pointers 103 | * that refer to this pbuf. This can be pointers from an application, 104 | * the stack itself, or pbuf->next pointers from a chain. 105 | */ 106 | u16_t ref; 107 | 108 | /* add a pointer for esf_buf */ 109 | void * eb; 110 | }; 111 | 112 | #if LWIP_SUPPORT_CUSTOM_PBUF 113 | /** Prototype for a function to free a custom pbuf */ 114 | typedef void (*pbuf_free_custom_fn)(struct pbuf *p); 115 | 116 | /** A custom pbuf: like a pbuf, but following a function pointer to free it. */ 117 | struct pbuf_custom { 118 | /** The actual pbuf */ 119 | struct pbuf pbuf; 120 | /** This function is called when pbuf_free deallocates this pbuf(_custom) */ 121 | pbuf_free_custom_fn custom_free_function; 122 | }; 123 | #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ 124 | 125 | /* Initializes the pbuf module. This call is empty for now, but may not be in future. */ 126 | #define pbuf_init() 127 | 128 | struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)ICACHE_FLASH_ATTR; 129 | #if LWIP_SUPPORT_CUSTOM_PBUF 130 | struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, 131 | struct pbuf_custom *p, void *payload_mem, 132 | u16_t payload_mem_len)ICACHE_FLASH_ATTR; 133 | #endif /* LWIP_SUPPORT_CUSTOM_PBUF */ 134 | void pbuf_realloc(struct pbuf *p, u16_t size)ICACHE_FLASH_ATTR; 135 | u8_t pbuf_header(struct pbuf *p, s16_t header_size)ICACHE_FLASH_ATTR; 136 | void pbuf_ref(struct pbuf *p)ICACHE_FLASH_ATTR; 137 | u8_t pbuf_free(struct pbuf *p)ICACHE_FLASH_ATTR; 138 | u8_t pbuf_clen(struct pbuf *p)ICACHE_FLASH_ATTR; 139 | void pbuf_cat(struct pbuf *head, struct pbuf *tail)ICACHE_FLASH_ATTR; 140 | void pbuf_chain(struct pbuf *head, struct pbuf *tail)ICACHE_FLASH_ATTR; 141 | struct pbuf *pbuf_dechain(struct pbuf *p)ICACHE_FLASH_ATTR; 142 | err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)ICACHE_FLASH_ATTR; 143 | u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset)ICACHE_FLASH_ATTR; 144 | err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)ICACHE_FLASH_ATTR; 145 | struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer)ICACHE_FLASH_ATTR; 146 | #if LWIP_CHECKSUM_ON_COPY 147 | err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, 148 | u16_t len, u16_t *chksum)ICACHE_FLASH_ATTR; 149 | #endif /* LWIP_CHECKSUM_ON_COPY */ 150 | 151 | u8_t pbuf_get_at(struct pbuf* p, u16_t offset)ICACHE_FLASH_ATTR; 152 | u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n)ICACHE_FLASH_ATTR; 153 | u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset)ICACHE_FLASH_ATTR; 154 | u16_t pbuf_strstr(struct pbuf* p, const char* substr)ICACHE_FLASH_ATTR; 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | 160 | #endif /* __LWIP_PBUF_H__ */ 161 | -------------------------------------------------------------------------------- /lwip/include/lwip/puck_def.h: -------------------------------------------------------------------------------- 1 | /* 2 | * puck_def.h 3 | * 4 | * Created on: Jul 22, 2010 5 | * Author: dtoma 6 | */ 7 | 8 | #ifndef PUCK_DEF_H_ 9 | #define PUCK_DEF_H_ 10 | 11 | 12 | 13 | #define INSTRUMENT_PORT 8760 14 | 15 | #define INSTRUMENT_LENGTH 80 16 | 17 | #define MDNS_NAME_LENGTH 68 //68 18 | 19 | char* PUCK_SERVICE = NULL; 20 | //#define PUCK_SERVICE "_Escpressif._tcp.local" 21 | #define DNS_SD_SERVICE "_services._dns-sd._udp.local" 22 | #define SERVICE_DESCRIPTION "PUCK PROTOCOL" 23 | #define PUCK_SERVICE_LENGTH 30 24 | 25 | #define UUID_LEN 16 26 | #define DS_VERS_LEN 2 27 | #define DS_SIZE_LEN 2 28 | #define MAN_ID_LEN 4 29 | #define MAN_MODEL_LEN 2 30 | #define MAN_VERS_LEN 2 31 | #define SER_NUM_LEN 4 32 | #define NAME_LEN 64 33 | #define PUCK_DATASHEET_SIZE 96 34 | 35 | #define UUID_OFFSET 0 36 | #define DS_VERS_OFFSET UUID_LEN + UUID_OFFSET 37 | #define DS_SIZE_OFFSET DS_VERS_LEN + DS_VERS_OFFSET 38 | #define MAN_ID_OFFSET DS_SIZE_LEN + DS_SIZE_OFFSET 39 | #define MAN_MODEL_OFFSET MAN_ID_LEN + MAN_ID_OFFSET 40 | #define MAN_VERS_OFFSET MAN_MODEL_LEN + MAN_MODEL_OFFSET 41 | #define SER_NUM_OFFSET MAN_VERS_LEN + MAN_VERS_OFFSET 42 | #define NAME_OFFSET SER_NUM_LEN + SER_NUM_OFFSET 43 | 44 | #endif /* __PUCK_DEF_H__ */ 45 | -------------------------------------------------------------------------------- /lwip/include/lwip/raw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_RAW_H__ 33 | #define __LWIP_RAW_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */ 38 | 39 | #include "lwip/pbuf.h" 40 | #include "lwip/def.h" 41 | #include "lwip/ip.h" 42 | #include "lwip/ip_addr.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | struct raw_pcb; 49 | 50 | /** Function prototype for raw pcb receive callback functions. 51 | * @param arg user supplied argument (raw_pcb.recv_arg) 52 | * @param pcb the raw_pcb which received data 53 | * @param p the packet buffer that was received 54 | * @param addr the remote IP address from which the packet was received 55 | * @return 1 if the packet was 'eaten' (aka. deleted), 56 | * 0 if the packet lives on 57 | * If returning 1, the callback is responsible for freeing the pbuf 58 | * if it's not used any more. 59 | */ 60 | typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p, 61 | ip_addr_t *addr); 62 | 63 | struct raw_pcb { 64 | /* Common members of all PCB types */ 65 | IP_PCB; 66 | 67 | struct raw_pcb *next; 68 | 69 | u8_t protocol; 70 | 71 | /** receive callback function */ 72 | raw_recv_fn recv; 73 | /* user-supplied argument for the recv callback */ 74 | void *recv_arg; 75 | }; 76 | 77 | /* The following functions is the application layer interface to the 78 | RAW code. */ 79 | struct raw_pcb * raw_new (u8_t proto)ICACHE_FLASH_ATTR; 80 | void raw_remove (struct raw_pcb *pcb)ICACHE_FLASH_ATTR; 81 | err_t raw_bind (struct raw_pcb *pcb, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; 82 | err_t raw_connect (struct raw_pcb *pcb, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; 83 | 84 | void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)ICACHE_FLASH_ATTR; 85 | err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR; 86 | err_t raw_send (struct raw_pcb *pcb, struct pbuf *p); 87 | 88 | /* The following functions are the lower layer interface to RAW. */ 89 | u8_t raw_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_ATTR; 90 | #define raw_init() /* Compatibility define, not init needed. */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* LWIP_RAW */ 97 | 98 | #endif /* __LWIP_RAW_H__ */ 99 | -------------------------------------------------------------------------------- /lwip/include/lwip/sio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | */ 29 | 30 | /* 31 | * This is the interface to the platform specific serial IO module 32 | * It needs to be implemented by those platforms which need SLIP or PPP 33 | */ 34 | 35 | #ifndef __SIO_H__ 36 | #define __SIO_H__ 37 | 38 | #include "lwip/arch.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* If you want to define sio_fd_t elsewhere or differently, 45 | define this in your cc.h file. */ 46 | #ifndef __sio_fd_t_defined 47 | typedef void * sio_fd_t; 48 | #endif 49 | 50 | /* The following functions can be defined to something else in your cc.h file 51 | or be implemented in your custom sio.c file. */ 52 | 53 | #ifndef sio_open 54 | /** 55 | * Opens a serial device for communication. 56 | * 57 | * @param devnum device number 58 | * @return handle to serial device if successful, NULL otherwise 59 | */ 60 | sio_fd_t sio_open(u8_t devnum)ICACHE_FLASH_ATTR; 61 | #endif 62 | 63 | #ifndef sio_send 64 | /** 65 | * Sends a single character to the serial device. 66 | * 67 | * @param c character to send 68 | * @param fd serial device handle 69 | * 70 | * @note This function will block until the character can be sent. 71 | */ 72 | void sio_send(u8_t c, sio_fd_t fd)ICACHE_FLASH_ATTR; 73 | #endif 74 | 75 | #ifndef sio_recv 76 | /** 77 | * Receives a single character from the serial device. 78 | * 79 | * @param fd serial device handle 80 | * 81 | * @note This function will block until a character is received. 82 | */ 83 | u8_t sio_recv(sio_fd_t fd)ICACHE_FLASH_ATTR; 84 | #endif 85 | 86 | #ifndef sio_read 87 | /** 88 | * Reads from the serial device. 89 | * 90 | * @param fd serial device handle 91 | * @param data pointer to data buffer for receiving 92 | * @param len maximum length (in bytes) of data to receive 93 | * @return number of bytes actually received - may be 0 if aborted by sio_read_abort 94 | * 95 | * @note This function will block until data can be received. The blocking 96 | * can be cancelled by calling sio_read_abort(). 97 | */ 98 | u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)ICACHE_FLASH_ATTR; 99 | #endif 100 | 101 | #ifndef sio_tryread 102 | /** 103 | * Tries to read from the serial device. Same as sio_read but returns 104 | * immediately if no data is available and never blocks. 105 | * 106 | * @param fd serial device handle 107 | * @param data pointer to data buffer for receiving 108 | * @param len maximum length (in bytes) of data to receive 109 | * @return number of bytes actually received 110 | */ 111 | u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)ICACHE_FLASH_ATTR; 112 | #endif 113 | 114 | #ifndef sio_write 115 | /** 116 | * Writes to the serial device. 117 | * 118 | * @param fd serial device handle 119 | * @param data pointer to data to send 120 | * @param len length (in bytes) of data to send 121 | * @return number of bytes actually sent 122 | * 123 | * @note This function will block until all data can be sent. 124 | */ 125 | u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len)ICACHE_FLASH_ATTR; 126 | #endif 127 | 128 | #ifndef sio_read_abort 129 | /** 130 | * Aborts a blocking sio_read() call. 131 | * 132 | * @param fd serial device handle 133 | */ 134 | void sio_read_abort(sio_fd_t fd)ICACHE_FLASH_ATTR; 135 | #endif 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* __SIO_H__ */ 142 | -------------------------------------------------------------------------------- /lwip/include/lwip/snmp_asn1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Abstract Syntax Notation One (ISO 8824, 8825) codec. 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. The name of the author may not be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 | * OF SUCH DAMAGE. 31 | * 32 | * Author: Christiaan Simons 33 | */ 34 | 35 | #ifndef __LWIP_SNMP_ASN1_H__ 36 | #define __LWIP_SNMP_ASN1_H__ 37 | 38 | #include "lwip/opt.h" 39 | #include "lwip/err.h" 40 | #include "lwip/pbuf.h" 41 | #include "lwip/snmp.h" 42 | 43 | #if LWIP_SNMP 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #define SNMP_ASN1_UNIV (0) /* (!0x80 | !0x40) */ 50 | #define SNMP_ASN1_APPLIC (0x40) /* (!0x80 | 0x40) */ 51 | #define SNMP_ASN1_CONTXT (0x80) /* ( 0x80 | !0x40) */ 52 | 53 | #define SNMP_ASN1_CONSTR (0x20) /* ( 0x20) */ 54 | #define SNMP_ASN1_PRIMIT (0) /* (!0x20) */ 55 | 56 | /* universal tags */ 57 | #define SNMP_ASN1_INTEG 2 58 | #define SNMP_ASN1_OC_STR 4 59 | #define SNMP_ASN1_NUL 5 60 | #define SNMP_ASN1_OBJ_ID 6 61 | #define SNMP_ASN1_SEQ 16 62 | 63 | /* application specific (SNMP) tags */ 64 | #define SNMP_ASN1_IPADDR 0 /* octet string size(4) */ 65 | #define SNMP_ASN1_COUNTER 1 /* u32_t */ 66 | #define SNMP_ASN1_GAUGE 2 /* u32_t */ 67 | #define SNMP_ASN1_TIMETICKS 3 /* u32_t */ 68 | #define SNMP_ASN1_OPAQUE 4 /* octet string */ 69 | 70 | /* context specific (SNMP) tags */ 71 | #define SNMP_ASN1_PDU_GET_REQ 0 72 | #define SNMP_ASN1_PDU_GET_NEXT_REQ 1 73 | #define SNMP_ASN1_PDU_GET_RESP 2 74 | #define SNMP_ASN1_PDU_SET_REQ 3 75 | #define SNMP_ASN1_PDU_TRAP 4 76 | 77 | err_t snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type); 78 | err_t snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length); 79 | err_t snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value); 80 | err_t snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value); 81 | err_t snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid); 82 | err_t snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw); 83 | 84 | void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed); 85 | void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed); 86 | void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed); 87 | void snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed); 88 | err_t snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type); 89 | err_t snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length); 90 | err_t snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, u32_t value); 91 | err_t snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, s32_t value); 92 | err_t snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident); 93 | err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u16_t raw_len, u8_t *raw); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* LWIP_SNMP */ 100 | 101 | #endif /* __LWIP_SNMP_ASN1_H__ */ 102 | -------------------------------------------------------------------------------- /lwip/include/lwip/sntp.h: -------------------------------------------------------------------------------- 1 | #ifndef LWIP_SNTP_H 2 | #define LWIP_SNTP_H 3 | 4 | #include "lwip/opt.h" 5 | #include "lwip/ip_addr.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef long time_t; 12 | 13 | /** The maximum number of SNTP servers that can be set */ 14 | #ifndef SNTP_MAX_SERVERS 15 | #define SNTP_MAX_SERVERS 3 16 | #endif 17 | 18 | /** Set this to 1 to implement the callback function called by dhcp when 19 | * NTP servers are received. */ 20 | #ifndef SNTP_GET_SERVERS_FROM_DHCP 21 | #define SNTP_GET_SERVERS_FROM_DHCP 0//LWIP_DHCP_GET_NTP_SRV 22 | #endif 23 | 24 | /* Set this to 1 to support DNS names (or IP address strings) to set sntp servers */ 25 | #ifndef SNTP_SERVER_DNS 26 | #define SNTP_SERVER_DNS 1 27 | #endif 28 | 29 | bool sntp_get_timetype(void); 30 | void sntp_set_receive_time_size(void); 31 | /** One server address/name can be defined as default if SNTP_SERVER_DNS == 1: 32 | * #define SNTP_SERVER_ADDRESS "pool.ntp.org" 33 | */ 34 | uint32 sntp_get_current_timestamp(); 35 | char* sntp_get_real_time(long t); 36 | 37 | void sntp_init(void); 38 | void sntp_stop(void); 39 | 40 | sint8 sntp_get_timezone(void); 41 | bool sntp_set_timezone(sint8 timezone); 42 | void sntp_setserver(u8_t idx, ip_addr_t *addr); 43 | ip_addr_t sntp_getserver(u8_t idx); 44 | 45 | #if SNTP_SERVER_DNS 46 | void sntp_setservername(u8_t idx, char *server); 47 | char *sntp_getservername(u8_t idx); 48 | #endif /* SNTP_SERVER_DNS */ 49 | 50 | #if SNTP_GET_SERVERS_FROM_DHCP 51 | void sntp_servermode_dhcp(int set_servers_from_dhcp); 52 | #else /* SNTP_GET_SERVERS_FROM_DHCP */ 53 | #define sntp_servermode_dhcp(x) 54 | #endif /* SNTP_GET_SERVERS_FROM_DHCP */ 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* LWIP_SNTP_H */ 61 | -------------------------------------------------------------------------------- /lwip/include/lwip/tcpip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_TCPIP_H__ 33 | #define __LWIP_TCPIP_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #if !NO_SYS /* don't build if not configured for use in lwipopts.h */ 38 | 39 | #include "lwip/api_msg.h" 40 | #include "lwip/netifapi.h" 41 | #include "lwip/pbuf.h" 42 | #include "lwip/api.h" 43 | #include "lwip/sys.h" 44 | #include "lwip/timers.h" 45 | #include "lwip/netif.h" 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /** Define this to something that triggers a watchdog. This is called from 52 | * tcpip_thread after processing a message. */ 53 | #ifndef LWIP_TCPIP_THREAD_ALIVE 54 | #define LWIP_TCPIP_THREAD_ALIVE() 55 | #endif 56 | 57 | #if LWIP_TCPIP_CORE_LOCKING 58 | /** The global semaphore to lock the stack. */ 59 | extern sys_mutex_t lock_tcpip_core; 60 | #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core) 61 | #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core) 62 | #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m) 63 | #define TCPIP_APIMSG_ACK(m) 64 | #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m) 65 | #define TCPIP_NETIFAPI_ACK(m) 66 | #else /* LWIP_TCPIP_CORE_LOCKING */ 67 | #define LOCK_TCPIP_CORE() 68 | #define UNLOCK_TCPIP_CORE() 69 | #define TCPIP_APIMSG(m) tcpip_apimsg(m) 70 | #define TCPIP_APIMSG_ACK(m) sys_sem_signal(&m->conn->op_completed) 71 | #define TCPIP_NETIFAPI(m) tcpip_netifapi(m) 72 | #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem) 73 | #endif /* LWIP_TCPIP_CORE_LOCKING */ 74 | 75 | /** Function prototype for the init_done function passed to tcpip_init */ 76 | typedef void (*tcpip_init_done_fn)(void *arg); 77 | /** Function prototype for functions passed to tcpip_callback() */ 78 | typedef void (*tcpip_callback_fn)(void *ctx); 79 | 80 | void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg); 81 | 82 | #if LWIP_NETCONN 83 | err_t tcpip_apimsg(struct api_msg *apimsg); 84 | #if LWIP_TCPIP_CORE_LOCKING 85 | err_t tcpip_apimsg_lock(struct api_msg *apimsg); 86 | #endif /* LWIP_TCPIP_CORE_LOCKING */ 87 | #endif /* LWIP_NETCONN */ 88 | 89 | err_t tcpip_input(struct pbuf *p, struct netif *inp); 90 | 91 | #if LWIP_NETIF_API 92 | err_t tcpip_netifapi(struct netifapi_msg *netifapimsg); 93 | #if LWIP_TCPIP_CORE_LOCKING 94 | err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg); 95 | #endif /* LWIP_TCPIP_CORE_LOCKING */ 96 | #endif /* LWIP_NETIF_API */ 97 | 98 | err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block); 99 | #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) 100 | 101 | /* free pbufs or heap memory from another context without blocking */ 102 | err_t pbuf_free_callback(struct pbuf *p); 103 | err_t mem_free_callback(void *m); 104 | 105 | #if LWIP_TCPIP_TIMEOUT 106 | err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); 107 | err_t tcpip_untimeout(sys_timeout_handler h, void *arg); 108 | #endif /* LWIP_TCPIP_TIMEOUT */ 109 | 110 | enum tcpip_msg_type { 111 | #if LWIP_NETCONN 112 | TCPIP_MSG_API, 113 | #endif /* LWIP_NETCONN */ 114 | TCPIP_MSG_INPKT, 115 | #if LWIP_NETIF_API 116 | TCPIP_MSG_NETIFAPI, 117 | #endif /* LWIP_NETIF_API */ 118 | #if LWIP_TCPIP_TIMEOUT 119 | TCPIP_MSG_TIMEOUT, 120 | TCPIP_MSG_UNTIMEOUT, 121 | #endif /* LWIP_TCPIP_TIMEOUT */ 122 | TCPIP_MSG_CALLBACK 123 | }; 124 | 125 | struct tcpip_msg { 126 | enum tcpip_msg_type type; 127 | sys_sem_t *sem; 128 | union { 129 | #if LWIP_NETCONN 130 | struct api_msg *apimsg; 131 | #endif /* LWIP_NETCONN */ 132 | #if LWIP_NETIF_API 133 | struct netifapi_msg *netifapimsg; 134 | #endif /* LWIP_NETIF_API */ 135 | struct { 136 | struct pbuf *p; 137 | struct netif *netif; 138 | } inp; 139 | struct { 140 | tcpip_callback_fn function; 141 | void *ctx; 142 | } cb; 143 | #if LWIP_TCPIP_TIMEOUT 144 | struct { 145 | u32_t msecs; 146 | sys_timeout_handler h; 147 | void *arg; 148 | } tmo; 149 | #endif /* LWIP_TCPIP_TIMEOUT */ 150 | } msg; 151 | }; 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif 156 | 157 | #endif /* !NO_SYS */ 158 | 159 | #endif /* __LWIP_TCPIP_H__ */ 160 | -------------------------------------------------------------------------------- /lwip/include/lwip/timers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * Simon Goldschmidt 31 | * 32 | */ 33 | #ifndef __LWIP_TIMERS_H__ 34 | #define __LWIP_TIMERS_H__ 35 | 36 | #include "lwip/opt.h" 37 | 38 | /* Timers are not supported when NO_SYS==1 and NO_SYS_NO_TIMERS==1 */ 39 | #define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) 40 | 41 | #if LWIP_TIMERS 42 | 43 | #include "lwip/err.h" 44 | #include "lwip/sys.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #ifndef LWIP_DEBUG_TIMERNAMES 51 | #ifdef LWIP_DEBUG 52 | #define LWIP_DEBUG_TIMERNAMES SYS_DEBUG 53 | #else /* LWIP_DEBUG */ 54 | #define LWIP_DEBUG_TIMERNAMES 0 55 | #endif /* LWIP_DEBUG*/ 56 | #endif 57 | 58 | /** Function prototype for a timeout callback function. Register such a function 59 | * using sys_timeout(). 60 | * 61 | * @param arg Additional argument to pass to the function - set up by sys_timeout() 62 | */ 63 | typedef void (* sys_timeout_handler)(void *arg); 64 | 65 | struct sys_timeo { 66 | struct sys_timeo *next; 67 | u32_t time; 68 | sys_timeout_handler h; 69 | void *arg; 70 | #if LWIP_DEBUG_TIMERNAMES 71 | const char* handler_name; 72 | #endif /* LWIP_DEBUG_TIMERNAMES */ 73 | }; 74 | 75 | void sys_timeouts_init(void)ICACHE_FLASH_ATTR; 76 | 77 | #if LWIP_DEBUG_TIMERNAMES 78 | void sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name)ICACHE_FLASH_ATTR; 79 | #define sys_timeout(msecs, handler, arg) sys_timeout_debug(msecs, handler, arg, #handler) 80 | #else /* LWIP_DEBUG_TIMERNAMES */ 81 | void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)ICACHE_FLASH_ATTR; 82 | #endif /* LWIP_DEBUG_TIMERNAMES */ 83 | 84 | void sys_untimeout(sys_timeout_handler handler, void *arg)ICACHE_FLASH_ATTR; 85 | #if NO_SYS 86 | void sys_check_timeouts(void)ICACHE_FLASH_ATTR; 87 | void sys_restart_timeouts(void)ICACHE_FLASH_ATTR; 88 | #else /* NO_SYS */ 89 | void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg); 90 | #endif /* NO_SYS */ 91 | 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /* LWIP_TIMERS */ 98 | #endif /* __LWIP_TIMERS_H__ */ 99 | -------------------------------------------------------------------------------- /lwip/include/lwip/udp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_UDP_H__ 33 | #define __LWIP_UDP_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */ 38 | 39 | #include "lwip/pbuf.h" 40 | #include "lwip/netif.h" 41 | #include "lwip/ip_addr.h" 42 | #include "lwip/ip.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | #define UDP_HLEN 8 49 | 50 | /* Fields are (of course) in network byte order. */ 51 | #ifdef PACK_STRUCT_USE_INCLUDES 52 | # include "arch/bpstruct.h" 53 | #endif 54 | PACK_STRUCT_BEGIN 55 | struct udp_hdr { 56 | PACK_STRUCT_FIELD(u16_t src); 57 | PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ 58 | PACK_STRUCT_FIELD(u16_t len); 59 | PACK_STRUCT_FIELD(u16_t chksum); 60 | } PACK_STRUCT_STRUCT; 61 | PACK_STRUCT_END 62 | #ifdef PACK_STRUCT_USE_INCLUDES 63 | # include "arch/epstruct.h" 64 | #endif 65 | 66 | #define UDP_FLAGS_NOCHKSUM 0x01U 67 | #define UDP_FLAGS_UDPLITE 0x02U 68 | #define UDP_FLAGS_CONNECTED 0x04U 69 | #define UDP_FLAGS_MULTICAST_LOOP 0x08U 70 | 71 | struct udp_pcb; 72 | 73 | /** Function prototype for udp pcb receive callback functions 74 | * addr and port are in same byte order as in the pcb 75 | * The callback is responsible for freeing the pbuf 76 | * if it's not used any more. 77 | * 78 | * ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf 79 | * makes 'addr' invalid, too. 80 | * 81 | * @param arg user supplied argument (udp_pcb.recv_arg) 82 | * @param pcb the udp_pcb which received data 83 | * @param p the packet buffer that was received 84 | * @param addr the remote IP address from which the packet was received 85 | * @param port the remote port from which the packet was received 86 | */ 87 | typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p, 88 | ip_addr_t *addr, u16_t port); 89 | 90 | 91 | struct udp_pcb { 92 | /* Common members of all PCB types */ 93 | IP_PCB; 94 | 95 | /* Protocol specific PCB members */ 96 | 97 | struct udp_pcb *next; 98 | 99 | u8_t flags; 100 | /** ports are in host byte order */ 101 | u16_t local_port, remote_port; 102 | 103 | #if LWIP_IGMP 104 | /** outgoing network interface for multicast packets */ 105 | ip_addr_t multicast_ip; 106 | #ifndef LWIP_MAYBE_XCC 107 | /** TTL for outgoing multicast packets */ 108 | u8_t mcast_ttl; 109 | #endif /* LWIP_MAYBE_XCC */ 110 | #endif /* LWIP_IGMP */ 111 | 112 | #if LWIP_UDPLITE 113 | /** used for UDP_LITE only */ 114 | u16_t chksum_len_rx, chksum_len_tx; 115 | #endif /* LWIP_UDPLITE */ 116 | 117 | /** receive callback function */ 118 | udp_recv_fn recv; 119 | /** user-supplied argument for the recv callback */ 120 | void *recv_arg; 121 | }; 122 | /* udp_pcbs export for exernal reference (e.g. SNMP agent) */ 123 | extern struct udp_pcb *udp_pcbs; 124 | 125 | /* The following functions is the application layer interface to the 126 | UDP code. */ 127 | struct udp_pcb * udp_new (void)ICACHE_FLASH_ATTR; 128 | void udp_remove (struct udp_pcb *pcb)ICACHE_FLASH_ATTR; 129 | err_t udp_bind (struct udp_pcb *pcb, ip_addr_t *ipaddr, 130 | u16_t port)ICACHE_FLASH_ATTR; 131 | err_t udp_connect (struct udp_pcb *pcb, ip_addr_t *ipaddr, 132 | u16_t port)ICACHE_FLASH_ATTR; 133 | void udp_disconnect (struct udp_pcb *pcb)ICACHE_FLASH_ATTR; 134 | void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, 135 | void *recv_arg)ICACHE_FLASH_ATTR; 136 | err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, 137 | ip_addr_t *dst_ip, u16_t dst_port, 138 | struct netif *netif)ICACHE_FLASH_ATTR; 139 | err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, 140 | ip_addr_t *dst_ip, u16_t dst_port)ICACHE_FLASH_ATTR; 141 | err_t udp_send (struct udp_pcb *pcb, struct pbuf *p)ICACHE_FLASH_ATTR; 142 | 143 | #if LWIP_CHECKSUM_ON_COPY 144 | err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, 145 | ip_addr_t *dst_ip, u16_t dst_port, 146 | struct netif *netif, u8_t have_chksum, 147 | u16_t chksum)ICACHE_FLASH_ATTR; 148 | err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, 149 | ip_addr_t *dst_ip, u16_t dst_port, 150 | u8_t have_chksum, u16_t chksum)ICACHE_FLASH_ATTR; 151 | err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, 152 | u8_t have_chksum, u16_t chksum)ICACHE_FLASH_ATTR; 153 | #endif /* LWIP_CHECKSUM_ON_COPY */ 154 | 155 | #define udp_flags(pcb) ((pcb)->flags) 156 | #define udp_setflags(pcb, f) ((pcb)->flags = (f)) 157 | 158 | /* The following functions are the lower layer interface to UDP. */ 159 | void udp_input (struct pbuf *p, struct netif *inp)ICACHE_FLASH_ATTR; 160 | 161 | #define udp_init() /* Compatibility define, not init needed. */ 162 | 163 | #if LWIP_IGMP 164 | #define udp_set_multicast_netif_addr(pcb, ipaddr) ip_addr_copy((pcb)->multicast_ip, (ipaddr)) 165 | #define udp_get_multicast_netif_addr(pcb) ((pcb)->multicast_ip) 166 | #ifndef LWIP_MAYBE_XCC 167 | #define udp_set_multicast_ttl(pcb, value) do { (pcb)->mcast_ttl = value; } while(0) 168 | #define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl) 169 | #endif /* LWIP_MAYBE_XCC */ 170 | #endif /* LWIP_IGMP */ 171 | 172 | #if UDP_DEBUG 173 | void udp_debug_print(struct udp_hdr *udphdr)ICACHE_FLASH_ATTR; 174 | #else 175 | #define udp_debug_print(udphdr) 176 | #endif 177 | 178 | #ifdef __cplusplus 179 | } 180 | #endif 181 | 182 | #endif /* LWIP_UDP */ 183 | 184 | #endif /* __LWIP_UDP_H__ */ 185 | -------------------------------------------------------------------------------- /lwip/include/netif/driver/spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 David Ogilvy (MetalPhreak) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef SPI_APP_H 26 | #define SPI_APP_H 27 | 28 | #include "spi_register.h" 29 | #include "ets_sys.h" 30 | #include "osapi.h" 31 | //#include "uart.h" 32 | #include "os_type.h" 33 | 34 | //Define SPI hardware modules 35 | #define SPI 0 36 | #define HSPI 1 37 | 38 | #define SPI_CLK_USE_DIV 0 39 | #define SPI_CLK_80MHZ_NODIV 1 40 | 41 | #define SPI_BYTE_ORDER_HIGH_TO_LOW 1 42 | #define SPI_BYTE_ORDER_LOW_TO_HIGH 0 43 | 44 | #ifndef CPU_CLK_FREQ //Should already be defined in eagle_soc.h 45 | #define CPU_CLK_FREQ 80*1000000 46 | #endif 47 | 48 | /* 49 | * Spec says maximum is 20Mhz, 50 | * so why are we running at 4??!! 51 | * 52 | * 1000000 PREDIV: 40 CNTDIV: 2 53 | * 2000000 PREDIV: 20 CNTDIV: 2 54 | * 2962962 PREDIV: 9 CNTDIV: 3 55 | * 4000000 PREDIV: 10 CNTDIV: 2 56 | * 5000000 PREDIV: 8 CNTDIV: 2 57 | * 5714285 PREDIV: 7 CNTDIV: 2 58 | * 6666666 PREDIV: 6 CNTDIV: 2 59 | * 8000000 PREDIV: 5 CNTDIV: 2 60 | * 8888888 PREDIV: 3 CNTDIV: 3 61 | * 10000000 PREDIV: 4 CNTDIV: 2 62 | * 11428571 PREDIV: 1 CNTDIV: 7 63 | * 13333333 PREDIV: 3 CNTDIV: 2 64 | * 16000000 PREDIV: 1 CNTDIV: 5 65 | * 20000000 PREDIV: 2 CNTDIV: 2 66 | * 26666666 PREDIV: 1 CNTDIV: 3 67 | * 40000000 PREDIV: 1 CNTDIV: 2 68 | */ 69 | //Define some default SPI clock settings 70 | #define SPI_CLK_PREDIV 10 71 | #define SPI_CLK_CNTDIV 2 72 | #define SPI_CLK_FREQ CPU_CLK_FREQ/(SPI_CLK_PREDIV*SPI_CLK_CNTDIV) // 80 / 20 = 4 MHz 73 | 74 | 75 | 76 | 77 | 78 | void spi_init(uint8 spi_no); 79 | void spi_mode(uint8 spi_no, uint8 spi_cpha,uint8 spi_cpol); 80 | void spi_init_gpio(uint8 spi_no, uint8 sysclk_as_spiclk); 81 | void spi_clock(uint8 spi_no, uint16 prediv, uint8 cntdiv); 82 | void spi_tx_byte_order(uint8 spi_no, uint8 byte_order); 83 | void spi_rx_byte_order(uint8 spi_no, uint8 byte_order); 84 | uint32 spi_transaction(uint8 spi_no, uint8 cmd_bits, uint16 cmd_data, uint32 addr_bits, uint32 addr_data, uint32 dout_bits, uint32 dout_data, uint32 din_bits, uint32 dummy_bits); 85 | 86 | //Expansion Macros 87 | #define spi_busy(spi_no) READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR 88 | 89 | #define spi_txd(spi_no, bits, data) spi_transaction(spi_no, 0, 0, 0, 0, bits, (uint32) data, 0, 0) 90 | #define spi_tx8(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 8, (uint32) data, 0, 0) 91 | #define spi_tx16(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 16, (uint32) data, 0, 0) 92 | #define spi_tx32(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 32, (uint32) data, 0, 0) 93 | 94 | #define spi_rxd(spi_no, bits) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, bits, 0) 95 | #define spi_rx8(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 8, 0) 96 | #define spi_rx16(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 16, 0) 97 | #define spi_rx32(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 32, 0) 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /lwip/include/netif/if_llc.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: if_llc.h,v 1.12 1999/11/19 20:41:19 thorpej Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1988, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 4. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * @(#)if_llc.h 8.1 (Berkeley) 6/10/93 32 | * $FreeBSD$ 33 | */ 34 | 35 | #ifndef _NET_IF_LLC_H_ 36 | #define _NET_IF_LLC_H_ 37 | 38 | /* 39 | * IEEE 802.2 Link Level Control headers, for use in conjunction with 40 | * 802.{3,4,5} media access control methods. 41 | * 42 | * Headers here do not use bit fields due to shortcommings in many 43 | * compilers. 44 | */ 45 | 46 | struct llc { 47 | uint8_t llc_dsap; 48 | uint8_t llc_ssap; 49 | union { 50 | struct { 51 | uint8_t control; 52 | uint8_t format_id; 53 | uint8_t class; 54 | uint8_t window_x2; 55 | } __packed type_u; 56 | struct { 57 | uint8_t num_snd_x2; 58 | uint8_t num_rcv_x2; 59 | } __packed type_i; 60 | struct { 61 | uint8_t control; 62 | uint8_t num_rcv_x2; 63 | } __packed type_s; 64 | struct { 65 | uint8_t control; 66 | /* 67 | * We cannot put the following fields in a structure because 68 | * the structure rounding might cause padding. 69 | */ 70 | uint8_t frmr_rej_pdu0; 71 | uint8_t frmr_rej_pdu1; 72 | uint8_t frmr_control; 73 | uint8_t frmr_control_ext; 74 | uint8_t frmr_cause; 75 | } __packed type_frmr; 76 | struct { 77 | uint8_t control; 78 | uint8_t org_code[3]; 79 | uint16_t ether_type; 80 | } __packed type_snap; 81 | struct { 82 | uint8_t control; 83 | uint8_t control_ext; 84 | } __packed type_raw; 85 | } __packed llc_un; 86 | } __packed; 87 | 88 | struct frmrinfo { 89 | uint8_t frmr_rej_pdu0; 90 | uint8_t frmr_rej_pdu1; 91 | uint8_t frmr_control; 92 | uint8_t frmr_control_ext; 93 | uint8_t frmr_cause; 94 | } __packed; 95 | 96 | #define llc_control llc_un.type_u.control 97 | #define llc_control_ext llc_un.type_raw.control_ext 98 | #define llc_fid llc_un.type_u.format_id 99 | #define llc_class llc_un.type_u.class 100 | #define llc_window llc_un.type_u.window_x2 101 | #define llc_frmrinfo llc_un.type_frmr.frmr_rej_pdu0 102 | #define llc_frmr_pdu0 llc_un.type_frmr.frmr_rej_pdu0 103 | #define llc_frmr_pdu1 llc_un.type_frmr.frmr_rej_pdu1 104 | #define llc_frmr_control llc_un.type_frmr.frmr_control 105 | #define llc_frmr_control_ext llc_un.type_frmr.frmr_control_ext 106 | #define llc_frmr_cause llc_un.type_frmr.frmr_cause 107 | #define llc_snap llc_un.type_snap 108 | 109 | /* 110 | * Don't use sizeof(struct llc_un) for LLC header sizes 111 | */ 112 | #define LLC_ISFRAMELEN 4 113 | #define LLC_UFRAMELEN 3 114 | #define LLC_FRMRLEN 7 115 | #define LLC_SNAPFRAMELEN 8 116 | 117 | #ifdef CTASSERT 118 | CTASSERT(sizeof (struct llc) == LLC_SNAPFRAMELEN); 119 | #endif 120 | 121 | /* 122 | * Unnumbered LLC format commands 123 | */ 124 | #define LLC_UI 0x3 125 | #define LLC_UI_P 0x13 126 | #define LLC_DISC 0x43 127 | #define LLC_DISC_P 0x53 128 | #define LLC_UA 0x63 129 | #define LLC_UA_P 0x73 130 | #define LLC_TEST 0xe3 131 | #define LLC_TEST_P 0xf3 132 | #define LLC_FRMR 0x87 133 | #define LLC_FRMR_P 0x97 134 | #define LLC_DM 0x0f 135 | #define LLC_DM_P 0x1f 136 | #define LLC_XID 0xaf 137 | #define LLC_XID_P 0xbf 138 | #define LLC_SABME 0x6f 139 | #define LLC_SABME_P 0x7f 140 | 141 | /* 142 | * Supervisory LLC commands 143 | */ 144 | #define LLC_RR 0x01 145 | #define LLC_RNR 0x05 146 | #define LLC_REJ 0x09 147 | 148 | /* 149 | * Info format - dummy only 150 | */ 151 | #define LLC_INFO 0x00 152 | 153 | /* 154 | * ISO PDTR 10178 contains among others 155 | */ 156 | #define LLC_8021D_LSAP 0x42 157 | #define LLC_X25_LSAP 0x7e 158 | #define LLC_SNAP_LSAP 0xaa 159 | #define LLC_ISO_LSAP 0xfe 160 | 161 | #define RFC1042_LEN 6 162 | #define RFC1042 {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00} 163 | #define ETHERNET_TUNNEL {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8} 164 | 165 | /* 166 | * copied from sys/net/ethernet.h 167 | */ 168 | #define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */ 169 | #define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */ 170 | 171 | 172 | 173 | #endif /* _NET_IF_LLC_H_ */ 174 | -------------------------------------------------------------------------------- /lwip/include/netif/ppp_oe.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * ppp_oe.h - PPP Over Ethernet implementation for lwIP. 3 | * 4 | * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc. 5 | * 6 | * The authors hereby grant permission to use, copy, modify, distribute, 7 | * and license this software and its documentation for any purpose, provided 8 | * that existing copyright notices are retained in all copies and that this 9 | * notice and the following disclaimer are included verbatim in any 10 | * distributions. No written agreement, license, or royalty fee is required 11 | * for any of the authorized uses. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | * 24 | ****************************************************************************** 25 | * REVISION HISTORY 26 | * 27 | * 06-01-01 Marc Boucher 28 | * Ported to lwIP. 29 | *****************************************************************************/ 30 | 31 | 32 | 33 | /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */ 34 | 35 | /*- 36 | * Copyright (c) 2002 The NetBSD Foundation, Inc. 37 | * All rights reserved. 38 | * 39 | * This code is derived from software contributed to The NetBSD Foundation 40 | * by Martin Husemann . 41 | * 42 | * Redistribution and use in source and binary forms, with or without 43 | * modification, are permitted provided that the following conditions 44 | * are met: 45 | * 1. Redistributions of source code must retain the above copyright 46 | * notice, this list of conditions and the following disclaimer. 47 | * 2. Redistributions in binary form must reproduce the above copyright 48 | * notice, this list of conditions and the following disclaimer in the 49 | * documentation and/or other materials provided with the distribution. 50 | * 3. All advertising materials mentioning features or use of this software 51 | * must display the following acknowledgement: 52 | * This product includes software developed by the NetBSD 53 | * Foundation, Inc. and its contributors. 54 | * 4. Neither the name of The NetBSD Foundation nor the names of its 55 | * contributors may be used to endorse or promote products derived 56 | * from this software without specific prior written permission. 57 | * 58 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 59 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 60 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 61 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 62 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 63 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 64 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 65 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 66 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 67 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 68 | * POSSIBILITY OF SUCH DAMAGE. 69 | */ 70 | #ifndef PPP_OE_H 71 | #define PPP_OE_H 72 | 73 | #include "lwip/opt.h" 74 | 75 | #if PPPOE_SUPPORT > 0 76 | 77 | #include "netif/etharp.h" 78 | 79 | #ifdef PACK_STRUCT_USE_INCLUDES 80 | # include "arch/bpstruct.h" 81 | #endif 82 | PACK_STRUCT_BEGIN 83 | struct pppoehdr { 84 | PACK_STRUCT_FIELD(u8_t vertype); 85 | PACK_STRUCT_FIELD(u8_t code); 86 | PACK_STRUCT_FIELD(u16_t session); 87 | PACK_STRUCT_FIELD(u16_t plen); 88 | } PACK_STRUCT_STRUCT; 89 | PACK_STRUCT_END 90 | #ifdef PACK_STRUCT_USE_INCLUDES 91 | # include "arch/epstruct.h" 92 | #endif 93 | 94 | #ifdef PACK_STRUCT_USE_INCLUDES 95 | # include "arch/bpstruct.h" 96 | #endif 97 | PACK_STRUCT_BEGIN 98 | struct pppoetag { 99 | PACK_STRUCT_FIELD(u16_t tag); 100 | PACK_STRUCT_FIELD(u16_t len); 101 | } PACK_STRUCT_STRUCT; 102 | PACK_STRUCT_END 103 | #ifdef PACK_STRUCT_USE_INCLUDES 104 | # include "arch/epstruct.h" 105 | #endif 106 | 107 | 108 | #define PPPOE_STATE_INITIAL 0 109 | #define PPPOE_STATE_PADI_SENT 1 110 | #define PPPOE_STATE_PADR_SENT 2 111 | #define PPPOE_STATE_SESSION 3 112 | #define PPPOE_STATE_CLOSING 4 113 | /* passive */ 114 | #define PPPOE_STATE_PADO_SENT 1 115 | 116 | #define PPPOE_HEADERLEN sizeof(struct pppoehdr) 117 | #define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */ 118 | 119 | #define PPPOE_TAG_EOL 0x0000 /* end of list */ 120 | #define PPPOE_TAG_SNAME 0x0101 /* service name */ 121 | #define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */ 122 | #define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */ 123 | #define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */ 124 | #define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */ 125 | #define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */ 126 | #define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */ 127 | #define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */ 128 | #define PPPOE_TAG_GENERIC_ERR 0x0203 /* gerneric error */ 129 | 130 | #define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */ 131 | #define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */ 132 | #define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */ 133 | #define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */ 134 | #define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */ 135 | 136 | #ifndef ETHERMTU 137 | #define ETHERMTU 1500 138 | #endif 139 | 140 | /* two byte PPP protocol discriminator, then IP data */ 141 | #define PPPOE_MAXMTU (ETHERMTU-PPPOE_HEADERLEN-2) 142 | 143 | #ifndef PPPOE_MAX_AC_COOKIE_LEN 144 | #define PPPOE_MAX_AC_COOKIE_LEN 64 145 | #endif 146 | 147 | struct pppoe_softc { 148 | struct pppoe_softc *next; 149 | struct netif *sc_ethif; /* ethernet interface we are using */ 150 | int sc_pd; /* ppp unit number */ 151 | void (*sc_linkStatusCB)(int pd, int up); 152 | 153 | int sc_state; /* discovery phase or session connected */ 154 | struct eth_addr sc_dest; /* hardware address of concentrator */ 155 | u16_t sc_session; /* PPPoE session id */ 156 | 157 | #ifdef PPPOE_TODO 158 | char *sc_service_name; /* if != NULL: requested name of service */ 159 | char *sc_concentrator_name; /* if != NULL: requested concentrator id */ 160 | #endif /* PPPOE_TODO */ 161 | u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */ 162 | size_t sc_ac_cookie_len; /* length of cookie data */ 163 | #ifdef PPPOE_SERVER 164 | u8_t *sc_hunique; /* content of host unique we must echo back */ 165 | size_t sc_hunique_len; /* length of host unique */ 166 | #endif 167 | int sc_padi_retried; /* number of PADI retries already done */ 168 | int sc_padr_retried; /* number of PADR retries already done */ 169 | }; 170 | 171 | 172 | #define pppoe_init() /* compatibility define, no initialization needed */ 173 | 174 | err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr); 175 | err_t pppoe_destroy(struct netif *ifp); 176 | 177 | int pppoe_connect(struct pppoe_softc *sc); 178 | void pppoe_disconnect(struct pppoe_softc *sc); 179 | 180 | void pppoe_disc_input(struct netif *netif, struct pbuf *p); 181 | void pppoe_data_input(struct netif *netif, struct pbuf *p); 182 | 183 | err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb); 184 | 185 | /** used in ppp.c */ 186 | #define PPPOE_HDRLEN (sizeof(struct eth_hdr) + PPPOE_HEADERLEN) 187 | 188 | #endif /* PPPOE_SUPPORT */ 189 | 190 | #endif /* PPP_OE_H */ 191 | -------------------------------------------------------------------------------- /lwip/include/netif/wlan_lwip_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef _WLAN_LWIP_IF_H_ 7 | #define _WLAN_LWIP_IF_H_ 8 | 9 | #define LWIP_IF0_PRIO 28 10 | #define LWIP_IF1_PRIO 29 11 | 12 | enum { 13 | SIG_LWIP_RX = 0, 14 | }; 15 | 16 | struct netif * eagle_lwip_if_alloc(struct ieee80211_conn *conn, const uint8 *macaddr, struct ip_info *info); 17 | struct netif * eagle_lwip_getif(uint8 index); 18 | 19 | #ifndef IOT_SIP_MODE 20 | sint8 ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb); 21 | #else 22 | sint8 ieee80211_output_pbuf(struct ieee80211_conn *conn, esf_buf *eb); 23 | #endif 24 | 25 | #endif /* _WLAN_LWIP_IF_H_ */ 26 | -------------------------------------------------------------------------------- /lwip/src/Makefile: -------------------------------------------------------------------------------- 1 | TOOLCHAIN_DIR ?= ../../../xtensa-lx106-elf 2 | TOOLS_PATH ?= $(TOOLCHAIN_DIR)/bin/xtensa-lx106-elf- 3 | LWIP_LIB ?= liblwip_src.a 4 | SDK_PATH ?= $(abspath ../../) 5 | 6 | BUILD_PATH = build 7 | LWIP_SRCS = $(patsubst %.c,$(BUILD_PATH)/%.o,$(wildcard */*.c)) $(patsubst %.c,$(BUILD_PATH)/%.o,$(wildcard */*/*.c)) 8 | 9 | LWIP_INCLUDE = -Ibuild -I$(SDK_PATH)/include -I$(SDK_PATH)/lwip/include 10 | BUILD_FLAGS = -c -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections 11 | BUILD_DEFINES = -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -DLWIP_OPEN_SRC 12 | 13 | ifdef WITH_DEBUG_PREFIX_MAP 14 | EXTRA_FLAGS = -fdebug-prefix-map=$(PWD)= -fdebug-prefix-map=$(TOOLCHAIN_DIR)=xtensa-lx106-elf -gno-record-gcc-switches 15 | endif 16 | 17 | CC=$(TOOLS_PATH)gcc 18 | AR=$(TOOLS_PATH)ar 19 | 20 | $(BUILD_PATH)/%.h: 21 | @mkdir -p $(dir $@) 22 | @touch $@ 23 | 24 | $(BUILD_PATH)/%.o: %.c 25 | @mkdir -p $(dir $@) 26 | $(CC) $(BUILD_FLAGS) $(BUILD_DEFINES) $(LWIP_INCLUDE) $(EXTRA_FLAGS) $< -o $@ 27 | 28 | $(LWIP_LIB): $(BUILD_PATH)/user_config.h $(LWIP_SRCS) 29 | $(AR) cru $(LWIP_LIB) $(LWIP_SRCS) 30 | 31 | all: $(LWIP_LIB) 32 | 33 | install: all 34 | cp -f $(LWIP_LIB) $(SDK_PATH)/lib/$(LWIP_LIB) 35 | 36 | release: all 37 | cp -f $(LWIP_LIB) $(SDK_PATH)/lib/liblwip_gcc.a 38 | 39 | clean: 40 | @rm -rf $(BUILD_PATH) $(LWIP_LIB) 41 | -------------------------------------------------------------------------------- /lwip/src/api/err.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Error Management module 4 | * 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 | 39 | #include "lwip/err.h" 40 | 41 | #ifdef LWIP_DEBUG 42 | 43 | static const char *err_strerr[] = { 44 | "Ok.", /* ERR_OK 0 */ 45 | "Out of memory error.", /* ERR_MEM -1 */ 46 | "Buffer error.", /* ERR_BUF -2 */ 47 | "Timeout.", /* ERR_TIMEOUT -3 */ 48 | "Routing problem.", /* ERR_RTE -4 */ 49 | "Operation in progress.", /* ERR_INPROGRESS -5 */ 50 | "Illegal value.", /* ERR_VAL -6 */ 51 | "Operation would block.", /* ERR_WOULDBLOCK -7 */ 52 | "Connection aborted.", /* ERR_ABRT -8 */ 53 | "Connection reset.", /* ERR_RST -9 */ 54 | "Connection closed.", /* ERR_CLSD -10 */ 55 | "Not connected.", /* ERR_CONN -11 */ 56 | "Illegal argument.", /* ERR_ARG -12 */ 57 | "Address in use.", /* ERR_USE -13 */ 58 | "Low-level netif error.", /* ERR_IF -14 */ 59 | "Already connected.", /* ERR_ISCONN -15 */ 60 | }; 61 | 62 | /** 63 | * Convert an lwip internal error to a string representation. 64 | * 65 | * @param err an lwip internal err_t 66 | * @return a string representation for err 67 | */ 68 | const char * 69 | lwip_strerr(err_t err) 70 | { 71 | return err_strerr[-err]; 72 | 73 | } 74 | 75 | #endif /* LWIP_DEBUG */ 76 | -------------------------------------------------------------------------------- /lwip/src/api/netbuf.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martin-ger/lwip_nat_arduino/ca2bdc9f37203b9061064e0fdfa78f293a84e2b2/lwip/src/api/netbuf.c -------------------------------------------------------------------------------- /lwip/src/api/netifapi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Network Interface Sequential API module 4 | * 5 | */ 6 | 7 | /* 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 22 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 24 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 28 | * OF SUCH DAMAGE. 29 | * 30 | * This file is part of the lwIP TCP/IP stack. 31 | * 32 | */ 33 | 34 | #include "lwip/opt.h" 35 | 36 | #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ 37 | 38 | #include "lwip/netifapi.h" 39 | #include "lwip/tcpip.h" 40 | 41 | /** 42 | * Call netif_add() inside the tcpip_thread context. 43 | */ 44 | void 45 | do_netifapi_netif_add(struct netifapi_msg_msg *msg) 46 | { 47 | if (!netif_add( msg->netif, 48 | msg->msg.add.ipaddr, 49 | msg->msg.add.netmask, 50 | msg->msg.add.gw, 51 | msg->msg.add.state, 52 | msg->msg.add.init, 53 | msg->msg.add.input)) { 54 | msg->err = ERR_IF; 55 | } else { 56 | msg->err = ERR_OK; 57 | } 58 | TCPIP_NETIFAPI_ACK(msg); 59 | } 60 | 61 | /** 62 | * Call netif_set_addr() inside the tcpip_thread context. 63 | */ 64 | void 65 | do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg) 66 | { 67 | netif_set_addr( msg->netif, 68 | msg->msg.add.ipaddr, 69 | msg->msg.add.netmask, 70 | msg->msg.add.gw); 71 | msg->err = ERR_OK; 72 | TCPIP_NETIFAPI_ACK(msg); 73 | } 74 | 75 | /** 76 | * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the 77 | * tcpip_thread context. 78 | */ 79 | void 80 | do_netifapi_netif_common(struct netifapi_msg_msg *msg) 81 | { 82 | if (msg->msg.common.errtfunc != NULL) { 83 | msg->err = msg->msg.common.errtfunc(msg->netif); 84 | } else { 85 | msg->err = ERR_OK; 86 | msg->msg.common.voidfunc(msg->netif); 87 | } 88 | TCPIP_NETIFAPI_ACK(msg); 89 | } 90 | 91 | /** 92 | * Call netif_add() in a thread-safe way by running that function inside the 93 | * tcpip_thread context. 94 | * 95 | * @note for params @see netif_add() 96 | */ 97 | err_t 98 | netifapi_netif_add(struct netif *netif, 99 | ip_addr_t *ipaddr, 100 | ip_addr_t *netmask, 101 | ip_addr_t *gw, 102 | void *state, 103 | netif_init_fn init, 104 | netif_input_fn input) 105 | { 106 | struct netifapi_msg msg; 107 | msg.function = do_netifapi_netif_add; 108 | msg.msg.netif = netif; 109 | msg.msg.msg.add.ipaddr = ipaddr; 110 | msg.msg.msg.add.netmask = netmask; 111 | msg.msg.msg.add.gw = gw; 112 | msg.msg.msg.add.state = state; 113 | msg.msg.msg.add.init = init; 114 | msg.msg.msg.add.input = input; 115 | TCPIP_NETIFAPI(&msg); 116 | return msg.msg.err; 117 | } 118 | 119 | /** 120 | * Call netif_set_addr() in a thread-safe way by running that function inside the 121 | * tcpip_thread context. 122 | * 123 | * @note for params @see netif_set_addr() 124 | */ 125 | err_t 126 | netifapi_netif_set_addr(struct netif *netif, 127 | ip_addr_t *ipaddr, 128 | ip_addr_t *netmask, 129 | ip_addr_t *gw) 130 | { 131 | struct netifapi_msg msg; 132 | msg.function = do_netifapi_netif_set_addr; 133 | msg.msg.netif = netif; 134 | msg.msg.msg.add.ipaddr = ipaddr; 135 | msg.msg.msg.add.netmask = netmask; 136 | msg.msg.msg.add.gw = gw; 137 | TCPIP_NETIFAPI(&msg); 138 | return msg.msg.err; 139 | } 140 | 141 | /** 142 | * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe 143 | * way by running that function inside the tcpip_thread context. 144 | * 145 | * @note use only for functions where there is only "netif" parameter. 146 | */ 147 | err_t 148 | netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc, 149 | netifapi_errt_fn errtfunc) 150 | { 151 | struct netifapi_msg msg; 152 | msg.function = do_netifapi_netif_common; 153 | msg.msg.netif = netif; 154 | msg.msg.msg.common.voidfunc = voidfunc; 155 | msg.msg.msg.common.errtfunc = errtfunc; 156 | TCPIP_NETIFAPI(&msg); 157 | return msg.msg.err; 158 | } 159 | 160 | #endif /* LWIP_NETIF_API */ 161 | -------------------------------------------------------------------------------- /lwip/src/api/tcpip.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martin-ger/lwip_nat_arduino/ca2bdc9f37203b9061064e0fdfa78f293a84e2b2/lwip/src/api/tcpip.c -------------------------------------------------------------------------------- /lwip/src/app/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ############################################################# 3 | # Required variables for each makefile 4 | # Discard this section from all parent makefiles 5 | # Expected variables (with automatic defaults): 6 | # CSRCS (all "C" files in the dir) 7 | # SUBDIRS (all subdirs with a Makefile) 8 | # GEN_LIBS - list of libs to be generated () 9 | # GEN_IMAGES - list of images to be generated () 10 | # COMPONENTS_xxx - a list of libs/objs in the form 11 | # subdir/lib to be extracted and rolled up into 12 | # a generated lib/image xxx.a () 13 | # 14 | ifndef PDIR 15 | 16 | GEN_LIBS = liblwipapp.a 17 | 18 | endif 19 | 20 | 21 | ############################################################# 22 | # Configuration i.e. compile options etc. 23 | # Target specific stuff (defines etc.) goes in here! 24 | # Generally values applying to a tree are captured in the 25 | # makefile at its root level - these are then overridden 26 | # for a subtree within the makefile rooted therein 27 | # 28 | #DEFINES += 29 | 30 | ############################################################# 31 | # Recursion Magic - Don't touch this!! 32 | # 33 | # Each subtree potentially has an include directory 34 | # corresponding to the common APIs applicable to modules 35 | # rooted at that subtree. Accordingly, the INCLUDE PATH 36 | # of a module can only contain the include directories up 37 | # its parent path, and not its siblings 38 | # 39 | # Required for each makefile to inherit from the parent 40 | # 41 | 42 | INCLUDES := $(INCLUDES) -I $(PDIR)include 43 | INCLUDES += -I ./ 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | -------------------------------------------------------------------------------- /lwip/src/app/espconn_buf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * espconn_buf.c 3 | * 4 | * Created on: May 25, 2016 5 | * Author: liuhan 6 | */ 7 | 8 | #include "lwip/memp.h" 9 | #include "lwip/def.h" 10 | #include "ets_sys.h" 11 | #include "os_type.h" 12 | #include "lwip/app/espconn_buf.h" 13 | 14 | 15 | #ifdef MEMLEAK_DEBUG 16 | static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__; 17 | #endif 18 | 19 | #if (!defined(lwIP_unlikely)) 20 | #define lwIP_unlikely(Expression) !!(Expression) 21 | #endif 22 | 23 | #define lwIP_ASSERT(Expression) do{if(!(Expression)) {os_printf("%s %d\n", __func__, __LINE__);return;}}while(0) 24 | 25 | ringbuf_t ringbuf_new(size_t capacity) 26 | { 27 | ringbuf_t rb = (ringbuf_t)os_zalloc(sizeof(struct ringbuf_t)); 28 | if (rb){ 29 | rb->size = capacity + 1; 30 | rb->buf = (uint8*)os_zalloc(rb->size); 31 | if (rb->buf){ 32 | ringbuf_reset(rb); 33 | }else{ 34 | os_free(rb); 35 | return NULL; 36 | } 37 | } 38 | return rb; 39 | } 40 | 41 | size_t ringbuf_buffer_size(const struct ringbuf_t *rb) 42 | { 43 | return rb->size; 44 | } 45 | 46 | void ringbuf_reset(ringbuf_t rb) 47 | { 48 | rb ->head = rb->tail = rb->buf; 49 | } 50 | 51 | void ringbuf_free(ringbuf_t *rb) 52 | { 53 | lwIP_ASSERT(rb && *rb); 54 | os_free((*rb)->buf); 55 | os_free(*rb); 56 | *rb = NULL; 57 | } 58 | 59 | size_t ringbuf_capacity(const struct ringbuf_t *rb) 60 | { 61 | return ringbuf_buffer_size(rb) - 1; 62 | } 63 | 64 | static const uint8_t* ringbuf_end(const struct ringbuf_t *rb) 65 | { 66 | return rb->buf + ringbuf_buffer_size(rb); 67 | } 68 | 69 | size_t ringbuf_bytes_free(const struct ringbuf_t *rb) 70 | { 71 | if (rb->head >= rb->tail){ 72 | return ringbuf_capacity(rb) - (rb->head - rb->tail); 73 | }else{ 74 | return rb->tail - rb->head -1; 75 | } 76 | } 77 | 78 | size_t ringbuf_bytes_used(const struct ringbuf_t *rb) 79 | { 80 | return ringbuf_capacity(rb) - ringbuf_bytes_free(rb); 81 | } 82 | 83 | int ringbuf_is_full(const struct ringbuf_t *rb) 84 | { 85 | return ringbuf_bytes_free(rb) == 0; 86 | } 87 | 88 | int ringbuf_is_empty(const struct ringbuf_t *rb) 89 | { 90 | return ringbuf_bytes_free(rb) == ringbuf_capacity(rb); 91 | } 92 | 93 | const void* ringbuf_tail(const struct ringbuf_t *rb) 94 | { 95 | return rb->tail; 96 | } 97 | const void* ringbuf_head(const struct ringbuf_t *rb) 98 | { 99 | return rb->head; 100 | } 101 | 102 | static uint8_t *ringbuf_nextp(ringbuf_t rb, const uint8_t *p) 103 | { 104 | lwIP_ASSERT((p >= rb->buf) && (p < ringbuf_end(rb))); 105 | return rb->buf + ((++p -rb->buf) % ringbuf_buffer_size(rb)); 106 | } 107 | 108 | size_t ringbuf_findchr(const struct ringbuf_t *rb, int c, size_t offset) 109 | { 110 | const uint8_t *bufend = ringbuf_end(rb); 111 | size_t bytes_used = ringbuf_bytes_used(rb); 112 | if (offset >= bytes_used) 113 | return bytes_used; 114 | 115 | const uint8_t *start = rb ->buf + (((rb->tail - rb->buf) + offset) % ringbuf_buffer_size(rb)); 116 | lwIP_ASSERT(bufend > start); 117 | size_t n = LWIP_MIN(bufend - start, bytes_used - offset); 118 | const uint8_t *found = (const uint8_t *)memchr(start, c, n); 119 | if (found) 120 | return offset + (found - start); 121 | else 122 | return ringbuf_findchr(rb, c, offset + n); 123 | } 124 | 125 | size_t ringbuf_memset(ringbuf_t dst, int c, size_t len) 126 | { 127 | const uint8_t *bufend = ringbuf_end(dst); 128 | size_t nwritten = 0; 129 | size_t count = LWIP_MIN(len, ringbuf_buffer_size(dst)); 130 | int overflow = count > ringbuf_bytes_free(dst); 131 | 132 | while (nwritten != count){ 133 | 134 | lwIP_ASSERT(bufend > dst->head); 135 | size_t n = LWIP_MIN(bufend - dst->head, count - nwritten); 136 | os_memset(dst->head, c, n); 137 | dst->head += n; 138 | nwritten += n; 139 | 140 | if (dst->head == bufend) 141 | dst->head = dst->buf; 142 | } 143 | 144 | if (overflow){ 145 | dst->tail = ringbuf_nextp(dst, dst->head); 146 | lwIP_ASSERT(ringbuf_is_full(dst)); 147 | } 148 | 149 | return nwritten; 150 | } 151 | 152 | void *ringbuf_memcpy_into(ringbuf_t dst,const void *src, size_t count) 153 | { 154 | const uint8_t *u8src = src; 155 | const uint8_t *bufend = ringbuf_end(dst); 156 | int overflow = count > ringbuf_bytes_free(dst); 157 | size_t nread = 0; 158 | 159 | while (nread != count){ 160 | lwIP_ASSERT(bufend > dst->head); 161 | size_t n = LWIP_MIN(bufend - dst->head, count - nread); 162 | os_memcpy(dst->head, u8src + nread, n); 163 | dst->head += n; 164 | nread += n; 165 | 166 | if (dst->head == bufend) 167 | dst->head = dst->buf; 168 | } 169 | 170 | if (overflow) { 171 | dst->tail = ringbuf_nextp(dst, dst->head); 172 | lwIP_ASSERT(ringbuf_is_full(dst)); 173 | } 174 | 175 | return dst->head; 176 | } 177 | 178 | void *ringbuf_memcpy_from(void *dst,ringbuf_t src, size_t count) 179 | { 180 | size_t bytes_used = ringbuf_bytes_used(src); 181 | 182 | if (count > bytes_used) 183 | return NULL; 184 | 185 | const uint8_t *u8dst = dst; 186 | const uint8_t *bufend = ringbuf_end(src); 187 | size_t nwritten = 0; 188 | 189 | while (nwritten != count){ 190 | lwIP_ASSERT(bufend > src->tail); 191 | size_t n = LWIP_MIN(bufend - src->tail, count - nwritten); 192 | os_memcpy((uint8_t*)u8dst + nwritten, src->tail, n); 193 | src->tail += n; 194 | nwritten += n; 195 | 196 | if (src->tail == bufend) 197 | src->tail = src->buf; 198 | } 199 | 200 | lwIP_ASSERT(count + ringbuf_bytes_used(src) == bytes_used); 201 | return src->tail; 202 | } 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /lwip/src/app/espconn_mdns.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: espconn_mdns.c 5 | * 6 | * Description: udp proto interface 7 | * 8 | * Modification history: 9 | * 2014/3/31, v1.0 create this file. 10 | *******************************************************************************/ 11 | 12 | #include "ets_sys.h" 13 | #include "os_type.h" 14 | 15 | #include "lwip/mdns.h" 16 | 17 | /****************************************************************************** 18 | * FunctionName : espconn_mdns_enable 19 | * Description : join a multicast group 20 | * Parameters : host_ip -- the ip address of udp server 21 | * multicast_ip -- multicast ip given by user 22 | * Returns : none 23 | *******************************************************************************/ 24 | void ICACHE_FLASH_ATTR 25 | espconn_mdns_enable(void) 26 | { 27 | mdns_enable(); 28 | } 29 | /****************************************************************************** 30 | * FunctionName : espconn_mdns_disable 31 | * Description : join a multicast group 32 | * Parameters : host_ip -- the ip address of udp server 33 | * multicast_ip -- multicast ip given by user 34 | * Returns : none 35 | *******************************************************************************/ 36 | void ICACHE_FLASH_ATTR 37 | espconn_mdns_disable(void) 38 | { 39 | mdns_disable(); 40 | } 41 | 42 | /****************************************************************************** 43 | * FunctionName : espconn_mdns_set_hostname 44 | * Description : join a multicast group 45 | * Parameters : host_ip -- the ip address of udp server 46 | * multicast_ip -- multicast ip given by user 47 | * Returns : none 48 | *******************************************************************************/ 49 | void ICACHE_FLASH_ATTR 50 | espconn_mdns_set_hostname(char *name) 51 | { 52 | mdns_set_hostname(name); 53 | } 54 | 55 | /****************************************************************************** 56 | * FunctionName : espconn_mdns_init 57 | * Description : join a multicast group 58 | * Parameters : host_ip -- the ip address of udp server 59 | * multicast_ip -- multicast ip given by user 60 | * Returns : none 61 | *******************************************************************************/ 62 | char* ICACHE_FLASH_ATTR 63 | espconn_mdns_get_hostname(void) 64 | { 65 | return (char *)mdns_get_hostname(); 66 | } 67 | /****************************************************************************** 68 | * FunctionName : espconn_mdns_get_servername 69 | * Description : join a multicast group 70 | * Parameters : info -- the info of mdns 71 | * Returns : none 72 | *******************************************************************************/ 73 | void ICACHE_FLASH_ATTR 74 | espconn_mdns_set_servername(const char *name) 75 | { 76 | mdns_set_servername(name); 77 | } 78 | /****************************************************************************** 79 | * FunctionName : espconn_mdns_get_servername 80 | * Description : join a multicast group 81 | * Parameters : info -- the info of mdns 82 | * Returns : none 83 | *******************************************************************************/ 84 | char* ICACHE_FLASH_ATTR 85 | espconn_mdns_get_servername(void) 86 | { 87 | return (char *)mdns_get_servername(); 88 | } 89 | /****************************************************************************** 90 | * FunctionName : mdns_server_register 91 | * Description : join a multicast group 92 | * Parameters : info -- the info of mdns 93 | * Returns : none 94 | *******************************************************************************/ 95 | void ICACHE_FLASH_ATTR 96 | espconn_mdns_server_register(void) 97 | { 98 | mdns_server_register(); 99 | } 100 | /****************************************************************************** 101 | * FunctionName : mdns_server_register 102 | * Description : join a multicast group 103 | * Parameters : info -- the info of mdns 104 | * Returns : none 105 | *******************************************************************************/ 106 | void ICACHE_FLASH_ATTR 107 | espconn_mdns_server_unregister(void) 108 | { 109 | mdns_server_unregister(); 110 | } 111 | /****************************************************************************** 112 | * FunctionName : espconn_mdns_init 113 | * Description : join a multicast group 114 | * Parameters : host_ip -- the ip address of udp server 115 | * multicast_ip -- multicast ip given by user 116 | * Returns : none 117 | *******************************************************************************/ 118 | void ICACHE_FLASH_ATTR 119 | espconn_mdns_close(void) 120 | { 121 | mdns_close(); 122 | } 123 | /****************************************************************************** 124 | * FunctionName : espconn_mdns_init 125 | * Description : join a multicast group 126 | * Parameters : host_ip -- the ip address of udp server 127 | * multicast_ip -- multicast ip given by user 128 | * Returns : none 129 | *******************************************************************************/ 130 | void ICACHE_FLASH_ATTR 131 | espconn_mdns_init(struct mdns_info *info) 132 | { 133 | mdns_init(info); 134 | } 135 | -------------------------------------------------------------------------------- /lwip/src/core/def.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Common functions used throughout the stack. 4 | * 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: Simon Goldschmidt 36 | * 37 | */ 38 | 39 | #include "lwip/opt.h" 40 | #include "lwip/def.h" 41 | 42 | /** 43 | * These are reference implementations of the byte swapping functions. 44 | * Again with the aim of being simple, correct and fully portable. 45 | * Byte swapping is the second thing you would want to optimize. You will 46 | * need to port it to your architecture and in your cc.h: 47 | * 48 | * #define LWIP_PLATFORM_BYTESWAP 1 49 | * #define LWIP_PLATFORM_HTONS(x) 50 | * #define LWIP_PLATFORM_HTONL(x) 51 | * 52 | * Note ntohs() and ntohl() are merely references to the htonx counterparts. 53 | */ 54 | 55 | #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) 56 | 57 | /** 58 | * Convert an u16_t from host- to network byte order. 59 | * 60 | * @param n u16_t in host byte order 61 | * @return n in network byte order 62 | */ 63 | u16_t 64 | lwip_htons(u16_t n) 65 | { 66 | return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); 67 | } 68 | 69 | /** 70 | * Convert an u16_t from network- to host byte order. 71 | * 72 | * @param n u16_t in network byte order 73 | * @return n in host byte order 74 | */ 75 | u16_t 76 | lwip_ntohs(u16_t n) 77 | { 78 | return lwip_htons(n); 79 | } 80 | 81 | /** 82 | * Convert an u32_t from host- to network byte order. 83 | * 84 | * @param n u32_t in host byte order 85 | * @return n in network byte order 86 | */ 87 | u32_t 88 | lwip_htonl(u32_t n) 89 | { 90 | return ((n & 0xff) << 24) | 91 | ((n & 0xff00) << 8) | 92 | ((n & 0xff0000UL) >> 8) | 93 | ((n & 0xff000000UL) >> 24); 94 | } 95 | 96 | /** 97 | * Convert an u32_t from network- to host byte order. 98 | * 99 | * @param n u32_t in network byte order 100 | * @return n in host byte order 101 | */ 102 | u32_t 103 | lwip_ntohl(u32_t n) 104 | { 105 | return lwip_htonl(n); 106 | } 107 | 108 | #endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ 109 | -------------------------------------------------------------------------------- /lwip/src/core/ipv4/inet.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Functions common to all TCP/IPv4 modules, such as the byte order functions. 4 | * 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 | 39 | #include "lwip/opt.h" 40 | 41 | #include "lwip/inet.h" 42 | 43 | -------------------------------------------------------------------------------- /lwip/src/core/ipv4/ip_route.c: -------------------------------------------------------------------------------- 1 | #include "lwip/opt.h" 2 | #include "lwip/ip.h" 3 | 4 | #ifdef IP_ROUTING_TAB 5 | #include "lwip/ip_route.h" 6 | 7 | struct route_entry ip_rt_table[MAX_ROUTES]; 8 | int ip_route_max = 0; 9 | 10 | uint32_t ICACHE_FLASH_ATTR 11 | mask2clidr (ip_addr_t *mask) 12 | { 13 | uint32_t clidr; 14 | 15 | uint32_t m = mask->addr; 16 | for (clidr = 0; m; m <<= 1,clidr++); 17 | return clidr; 18 | } 19 | 20 | bool ICACHE_FLASH_ATTR 21 | ip_add_route(ip_addr_t ip, ip_addr_t mask, ip_addr_t gw) 22 | { 23 | int add_pos, i, j; 24 | 25 | // Remove it if already existing 26 | ip_rm_route(ip, mask); 27 | 28 | if (ip_route_max >= MAX_ROUTES) 29 | return false; 30 | 31 | ip.addr &= mask.addr; 32 | 33 | add_pos = ip_route_max; 34 | for (i = 0; i mask2clidr(&ip_rt_table[i].mask)) { 37 | add_pos = i; 38 | for (j = ip_route_max-1; j >= i; j--) { 39 | ip_rt_table[j+1] = ip_rt_table[j]; 40 | } 41 | break; 42 | } 43 | } 44 | 45 | ip_addr_copy(ip_rt_table[add_pos].ip, ip); 46 | ip_addr_copy(ip_rt_table[add_pos].mask, mask); 47 | ip_addr_copy(ip_rt_table[add_pos].gw, gw); 48 | ip_route_max++; 49 | return true; 50 | } 51 | 52 | bool ICACHE_FLASH_ATTR 53 | ip_rm_route(ip_addr_t ip, ip_addr_t mask) 54 | { 55 | int i; 56 | 57 | for (i = 0; i= ip_route_max) 92 | return false; 93 | 94 | ip_addr_copy(*ip, ip_rt_table[no].ip); 95 | ip_addr_copy(*mask, ip_rt_table[no].mask); 96 | ip_addr_copy(*gw, ip_rt_table[no].gw); 97 | return true; 98 | } 99 | 100 | #endif /* IP_ROUTING_TAB */ 101 | -------------------------------------------------------------------------------- /lwip/src/core/stats.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Statistics module 4 | * 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 | 39 | #include "lwip/opt.h" 40 | 41 | #if LWIP_STATS /* don't build if not configured for use in lwipopts.h */ 42 | 43 | #include "lwip/def.h" 44 | #include "lwip/stats.h" 45 | #include "lwip/mem.h" 46 | 47 | #include 48 | 49 | struct stats_ lwip_stats; 50 | 51 | void stats_init(void) 52 | { 53 | #ifdef LWIP_DEBUG 54 | #if MEMP_STATS 55 | const char * memp_names[] = { 56 | #define LWIP_MEMPOOL(name,num,size,desc) desc, 57 | #include "lwip/memp_std.h" 58 | }; 59 | int i; 60 | for (i = 0; i < MEMP_MAX; i++) { 61 | lwip_stats.memp[i].name = memp_names[i]; 62 | } 63 | #endif /* MEMP_STATS */ 64 | #if MEM_STATS 65 | lwip_stats.mem.name = "MEM"; 66 | #endif /* MEM_STATS */ 67 | #endif /* LWIP_DEBUG */ 68 | } 69 | 70 | #if LWIP_STATS_DISPLAY 71 | void 72 | stats_display_proto(struct stats_proto *proto, char *name) 73 | { 74 | LWIP_PLATFORM_DIAG(("\n%s\n\t", name)); 75 | LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit)); 76 | LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv)); 77 | LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw)); 78 | LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop)); 79 | LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", proto->chkerr)); 80 | LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", proto->lenerr)); 81 | LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", proto->memerr)); 82 | LWIP_PLATFORM_DIAG(("rterr: %"STAT_COUNTER_F"\n\t", proto->rterr)); 83 | LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", proto->proterr)); 84 | LWIP_PLATFORM_DIAG(("opterr: %"STAT_COUNTER_F"\n\t", proto->opterr)); 85 | LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n\t", proto->err)); 86 | LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit)); 87 | } 88 | 89 | #if IGMP_STATS 90 | void 91 | stats_display_igmp(struct stats_igmp *igmp) 92 | { 93 | LWIP_PLATFORM_DIAG(("\nIGMP\n\t")); 94 | LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", igmp->xmit)); 95 | LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", igmp->recv)); 96 | LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", igmp->drop)); 97 | LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", igmp->chkerr)); 98 | LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", igmp->lenerr)); 99 | LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", igmp->memerr)); 100 | LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", igmp->proterr)); 101 | LWIP_PLATFORM_DIAG(("rx_v1: %"STAT_COUNTER_F"\n\t", igmp->rx_v1)); 102 | LWIP_PLATFORM_DIAG(("rx_group: %"STAT_COUNTER_F"\n", igmp->rx_group)); 103 | LWIP_PLATFORM_DIAG(("rx_general: %"STAT_COUNTER_F"\n", igmp->rx_general)); 104 | LWIP_PLATFORM_DIAG(("rx_report: %"STAT_COUNTER_F"\n\t", igmp->rx_report)); 105 | LWIP_PLATFORM_DIAG(("tx_join: %"STAT_COUNTER_F"\n\t", igmp->tx_join)); 106 | LWIP_PLATFORM_DIAG(("tx_leave: %"STAT_COUNTER_F"\n\t", igmp->tx_leave)); 107 | LWIP_PLATFORM_DIAG(("tx_report: %"STAT_COUNTER_F"\n\t", igmp->tx_report)); 108 | } 109 | #endif /* IGMP_STATS */ 110 | 111 | #if MEM_STATS || MEMP_STATS 112 | void 113 | stats_display_mem(struct stats_mem *mem, char *name) 114 | { 115 | LWIP_PLATFORM_DIAG(("\nMEM %s\n\t", name)); 116 | LWIP_PLATFORM_DIAG(("avail: %"U32_F"\n\t", (u32_t)mem->avail)); 117 | LWIP_PLATFORM_DIAG(("used: %"U32_F"\n\t", (u32_t)mem->used)); 118 | LWIP_PLATFORM_DIAG(("max: %"U32_F"\n\t", (u32_t)mem->max)); 119 | LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err)); 120 | } 121 | 122 | #if MEMP_STATS 123 | void 124 | stats_display_memp(struct stats_mem *mem, int index) 125 | { 126 | char * memp_names[] = { 127 | #define LWIP_MEMPOOL(name,num,size,desc) desc, 128 | #include "lwip/memp_std.h" 129 | }; 130 | if(index < MEMP_MAX) { 131 | stats_display_mem(mem, memp_names[index]); 132 | } 133 | } 134 | #endif /* MEMP_STATS */ 135 | #endif /* MEM_STATS || MEMP_STATS */ 136 | 137 | #if SYS_STATS 138 | void 139 | stats_display_sys(struct stats_sys *sys) 140 | { 141 | LWIP_PLATFORM_DIAG(("\nSYS\n\t")); 142 | LWIP_PLATFORM_DIAG(("sem.used: %"U32_F"\n\t", (u32_t)sys->sem.used)); 143 | LWIP_PLATFORM_DIAG(("sem.max: %"U32_F"\n\t", (u32_t)sys->sem.max)); 144 | LWIP_PLATFORM_DIAG(("sem.err: %"U32_F"\n\t", (u32_t)sys->sem.err)); 145 | LWIP_PLATFORM_DIAG(("mutex.used: %"U32_F"\n\t", (u32_t)sys->mutex.used)); 146 | LWIP_PLATFORM_DIAG(("mutex.max: %"U32_F"\n\t", (u32_t)sys->mutex.max)); 147 | LWIP_PLATFORM_DIAG(("mutex.err: %"U32_F"\n\t", (u32_t)sys->mutex.err)); 148 | LWIP_PLATFORM_DIAG(("mbox.used: %"U32_F"\n\t", (u32_t)sys->mbox.used)); 149 | LWIP_PLATFORM_DIAG(("mbox.max: %"U32_F"\n\t", (u32_t)sys->mbox.max)); 150 | LWIP_PLATFORM_DIAG(("mbox.err: %"U32_F"\n\t", (u32_t)sys->mbox.err)); 151 | } 152 | #endif /* SYS_STATS */ 153 | 154 | void 155 | stats_display(void) 156 | { 157 | s16_t i; 158 | 159 | LINK_STATS_DISPLAY(); 160 | ETHARP_STATS_DISPLAY(); 161 | IPFRAG_STATS_DISPLAY(); 162 | IP_STATS_DISPLAY(); 163 | IGMP_STATS_DISPLAY(); 164 | ICMP_STATS_DISPLAY(); 165 | UDP_STATS_DISPLAY(); 166 | TCP_STATS_DISPLAY(); 167 | MEM_STATS_DISPLAY(); 168 | for (i = 0; i < MEMP_MAX; i++) { 169 | MEMP_STATS_DISPLAY(i); 170 | } 171 | SYS_STATS_DISPLAY(); 172 | } 173 | #endif /* LWIP_STATS_DISPLAY */ 174 | 175 | #endif /* LWIP_STATS */ 176 | 177 | -------------------------------------------------------------------------------- /lwip/src/core/sys.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * lwIP Operating System abstraction 4 | * 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 | 39 | #include "lwip/opt.h" 40 | 41 | #include "lwip/sys.h" 42 | 43 | /* Most of the functions defined in sys.h must be implemented in the 44 | * architecture-dependent file sys_arch.c */ 45 | 46 | #if !NO_SYS 47 | 48 | /** 49 | * Sleep for some ms. Timeouts are NOT processed while sleeping. 50 | * 51 | * @param ms number of milliseconds to sleep 52 | */ 53 | void 54 | sys_msleep(u32_t ms) 55 | { 56 | if (ms > 0) { 57 | sys_sem_t delaysem; 58 | err_t err = sys_sem_new(&delaysem, 0); 59 | if (err == ERR_OK) { 60 | sys_arch_sem_wait(&delaysem, ms); 61 | sys_sem_free(&delaysem); 62 | } 63 | } 64 | } 65 | 66 | #endif /* !NO_SYS */ 67 | -------------------------------------------------------------------------------- /lwip/src/core/sys_arch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2010 - 2011 espressif system 3 | */ 4 | 5 | #include "c_types.h" 6 | #include "ets_sys.h" 7 | #include "osapi.h" 8 | #include "os_type.h" 9 | 10 | #include "lwip/opt.h" 11 | #include "lwip/sys.h" 12 | 13 | #include "eagle_soc.h" 14 | --------------------------------------------------------------------------------