diff --git a/app/include/sys/Espconn_mem.h b/app/include/sys/Espconn_mem.h deleted file mode 100644 index aa6713f703..0000000000 --- a/app/include/sys/Espconn_mem.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ESPRSSIF MIT License - * - * Copyright (c) 2016 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef ESPCONN_MEM_H_ -#define ESPCONN_MEM_H_ - -void *espconn_memzalloc(size_t size); -void espconn_memfree(void *fp); -void *espconn_memcpy(void *dst, const void *src, size_t size); - -#endif - diff --git a/app/mbedtls/app/Espconn_mem.c b/app/mbedtls/app/Espconn_mem.c deleted file mode 100644 index 5620b1b9eb..0000000000 --- a/app/mbedtls/app/Espconn_mem.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include "mem.h" -#include "user_interface.h" - -void *espconn_memzalloc(size_t size, char* file, int line) -{ - void *mp = NULL; - if ((mp = (void*)os_malloc(size)) == NULL){ - - } else{ - //os_printf("%s %d %p %d\n",file, line, mp, size); - os_memset(mp, 0, size); - } - return mp; -} - -void espconn_memfree(void *fp, char* file, int line) -{ - //os_printf("%s %d %p\n",file, line, fp); - os_free(fp); - fp = NULL; -} - -void *espconn_memcpy(void *dst, const void *src, size_t size, char *file, int line) -{ - char *psrc = NULL; - char *pdst = NULL; - - if(NULL == dst || NULL == src) - { - return NULL; - } - //os_printf("%s %d %p %p %d\n",file, line, dst, src, size); - if((src < dst) && (char *)src + size > (char *)dst) - { - psrc = (char *)src + size - 1; - pdst = (char *)dst + size - 1; - while(size--) - { - *pdst-- = *psrc--; - } - } - else - { - psrc = (char *)src; - pdst = (char *)dst; - while(size--) - { - *pdst++ = *psrc++; - } - } - - return dst; - -} - -void *espconn_memcalloc(size_t count, size_t size) -{ - void *cp = NULL; - cp = espconn_memzalloc(count * size, __FILE__, __LINE__); - return cp; -} - -void espconn_memFree(void *fp) -{ - espconn_memfree(fp, __FILE__, __LINE__); -} - -void *espconn_memCpy(void *dst, const void *src, size_t size) -{ - return espconn_memcpy(dst, src, size, __FILE__, __LINE__); -} - diff --git a/app/mbedtls/app/lwIPSocket.c b/app/mbedtls/app/lwIPSocket.c index f406141467..f1014cf2d9 100644 --- a/app/mbedtls/app/lwIPSocket.c +++ b/app/mbedtls/app/lwIPSocket.c @@ -45,48 +45,6 @@ static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__; /** The global array of available sockets */ static lwIP_sock sockets[NUM_SOCKETS]; -/** Table to quickly map an lwIP error (err_t) to a socket error - * by using -err as an index */ -static const int err_to_errno_table[] = -{ - 0, /* ERR_OK 0 No error, everything OK. */ -// ENOMEM, /* ERR_MEM -1 Out of memory error. */ -// ENOBUFS, /* ERR_BUF -2 Buffer error. */ -// EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */ -// EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */ -// EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */ -// EINVAL, /* ERR_VAL -6 Illegal value. */ -// EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */ -// ECONNABORTED, /* ERR_ABRT -8 Connection aborted. */ -// ECONNRESET, /* ERR_RST -9 Connection reset. */ -// ESHUTDOWN, /* ERR_CLSD -10 Connection closed. */ -// ENOTCONN, /* ERR_CONN -11 Not connected. */ -// EIO, /* ERR_ARG -12 Illegal argument. */ -// EADDRINUSE, /* ERR_USE -13 Address in use. */ - -1, /* ERR_IF -14 Low-level netif error */ - -1, /* ERR_ISCONN -15 Already connected. */ -}; - -#define ERR_TO_ERRNO_TABLE_SIZE \ - (sizeof(err_to_errno_table)/sizeof(err_to_errno_table[0])) - -#define err_to_errno(err) \ - ((unsigned)(-(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \ - err_to_errno_table[-(err)] : EIO) - -#ifdef ERRNO -#ifndef set_errno -#define set_errno(err) errno = (err) -#endif -#else /* ERRNO */ -#define set_errno(err) -#endif /* ERRNO */ - -#define sock_set_errno(sk, e) do { \ - sk->err = (e); \ - set_errno(sk->err); \ -} while (0) - static lwIP_sock *get_socket(int s); static int find_socket(lwIP_netconn *newconn) @@ -844,189 +802,3 @@ int lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen) { return lwip_getaddrname(s, name, namelen, 0); } - -int lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen) -{ - return lwip_getaddrname(s, name, namelen, 1); -} - -int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) -{ - lwIP_sock *sock = NULL; - err_t err = ERR_OK; - - lwIP_REQUIRE_ACTION(optval, exit, err = ESP_ARG); - lwIP_REQUIRE_ACTION(optlen, exit, err = ESP_ARG); - - sock = get_socket(s); - lwIP_REQUIRE_ACTION(sock, exit, err = ESP_MEM); - switch (level) - { - /* Level: SOL_SOCKET */ - case SOL_SOCKET: - switch (optname) - { - /* The option flags */ - case SO_ACCEPTCONN: - case SO_BROADCAST: - case SO_KEEPALIVE: -#if SO_REUSE - case SO_REUSEADDR: - case SO_REUSEPORT: -#endif /* SO_REUSE */ - *(int*)optval = sock->conn->tcp->so_options & optname; - break; - case SO_TYPE: - switch (NETCONNTYPE_GROUP(sock->conn->type)) - { - case NETCONN_TCP: - *(int*)optval = SOCK_STREAM; - break; - case NETCONN_UDP: - *(int*)optval = SOCK_DGRAM; - break; - default: - *(int*)optval = sock->conn->type; - break; - } - break; - break; - } - break; - /* Level: IPPROTO_IP */ - case IPPROTO_IP: - break; -#if LWIP_TCP - /* Level: IPPROTO_TCP */ - case IPPROTO_TCP: - if (*optlen < sizeof(int)) - { - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - } - - /* If this is no TCP socket, ignore any options. */ - if (sock->conn->type != NETCONN_TCP) - { - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - } - - switch (optname) - { - case TCP_NODELAY: - case TCP_KEEPALIVE: - *(int*)optval = (int)sock->conn->tcp->keep_idle; - break; -#if LWIP_TCP_KEEPALIVE - case TCP_KEEPIDLE: - *(int*)optval = (int)(sock->conn->tcp->keep_idle/1000); - break; - case TCP_KEEPINTVL: - *(int*)optval = (int)(sock->conn->tcp->keep_intvl/1000); - break; - case TCP_KEEPCNT: - *(int*)optval = (int)sock->conn->tcp->keep_cnt; -#endif /* LWIP_TCP_KEEPALIVE */ - break; - - default: - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - break; - } /* switch (optname) */ - break; -#endif /* LWIP_TCP */ - default: - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - break; - } - -exit: - return err; -} - -int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) -{ - lwIP_sock *sock = NULL; - err_t err = ERR_OK; - lwIP_REQUIRE_ACTION(optval, exit, err = ESP_ARG); - - sock = get_socket(s); - lwIP_REQUIRE_ACTION(sock, exit, err = ESP_MEM); - lwIP_REQUIRE_ACTION(sock->conn, exit, err = ESP_MEM); - lwIP_REQUIRE_ACTION(sock->conn->tcp, exit, err = ESP_MEM); - switch (level) - { - /* Level: SOL_SOCKET */ - case SOL_SOCKET: - switch (optname) - { - case SO_KEEPALIVE: - if (optlen < sizeof(int)) - { - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - } - if (*(int*)optval) - { - sock->conn->tcp->so_options |= optname; - } - else - { - sock->conn->tcp->so_options &= ~optname; - } - break; - } - break; - /* Level: IPPROTO_IP */ - case IPPROTO_IP: - break; - /* Level: IPPROTO_TCP */ - case IPPROTO_TCP: - if (optlen < sizeof(int)) - { - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - } - - /* If this is no TCP socket, ignore any options. */ - if (NETCONNTYPE_GROUP(sock->conn->type) != NETCONN_TCP) - { - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - } - switch (optname) - { - case TCP_KEEPALIVE: - sock->conn->tcp->keep_idle = (u32_t) (*(int*) optval); - break; - -#if LWIP_TCP_KEEPALIVE - case TCP_KEEPIDLE: - sock->conn->tcp->keep_idle = 1000 * (u32_t) (*(int*) optval); - break; - case TCP_KEEPINTVL: - sock->conn->tcp->keep_intvl = 1000 * (u32_t) (*(int*) optval); - break; - case TCP_KEEPCNT: - sock->conn->tcp->keep_cnt = (u32_t) (*(int*) optval); - break; -#endif /* LWIP_TCP_KEEPALIVE */ - default: - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - break; - } - break; - /* UNDEFINED LEVEL */ - default: - err = ESP_ARG; - lwIP_REQUIRE_NOERROR(err, exit); - break; - } - -exit: - return err; -}