Skip to content

Commit

Permalink
Rampage esp mbedtls glue and delete unused code
Browse files Browse the repository at this point in the history
This at least makes the shitshow smaller
  • Loading branch information
nwf committed Oct 4, 2019
1 parent b05c4d4 commit 3ba02a5
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 334 deletions.
33 changes: 0 additions & 33 deletions app/include/sys/Espconn_mem.h

This file was deleted.

73 changes: 0 additions & 73 deletions app/mbedtls/app/Espconn_mem.c

This file was deleted.

228 changes: 0 additions & 228 deletions app/mbedtls/app/lwIPSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

0 comments on commit 3ba02a5

Please sign in to comment.