mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-26 16:12:55 +00:00
Reformat altcp_tls_mbedtls* using astylerc
This commit is contained in:
parent
438cfd3f14
commit
c35b1099a4
@ -97,8 +97,7 @@
|
|||||||
extern const struct altcp_functions altcp_mbedtls_functions;
|
extern const struct altcp_functions altcp_mbedtls_functions;
|
||||||
|
|
||||||
/** Our global mbedTLS configuration (server-specific, not connection-specific) */
|
/** Our global mbedTLS configuration (server-specific, not connection-specific) */
|
||||||
struct altcp_tls_config
|
struct altcp_tls_config {
|
||||||
{
|
|
||||||
mbedtls_ssl_config conf;
|
mbedtls_ssl_config conf;
|
||||||
mbedtls_entropy_context entropy;
|
mbedtls_entropy_context entropy;
|
||||||
mbedtls_ctr_drbg_context ctr_drbg;
|
mbedtls_ctr_drbg_context ctr_drbg;
|
||||||
@ -113,7 +112,7 @@ static err_t altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altc
|
|||||||
static void altcp_mbedtls_dealloc(struct altcp_pcb *conn);
|
static void altcp_mbedtls_dealloc(struct altcp_pcb *conn);
|
||||||
static err_t altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *state);
|
static err_t altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *state);
|
||||||
static err_t altcp_mbedtls_handle_rx_appldata(struct altcp_pcb *conn, altcp_mbedtls_state_t *state);
|
static err_t altcp_mbedtls_handle_rx_appldata(struct altcp_pcb *conn, altcp_mbedtls_state_t *state);
|
||||||
static int altcp_mbedtls_bio_send(void* ctx, const unsigned char* dataptr, size_t size);
|
static int altcp_mbedtls_bio_send(void *ctx, const unsigned char *dataptr, size_t size);
|
||||||
|
|
||||||
|
|
||||||
/* callback functions from inner/lower connection: */
|
/* callback functions from inner/lower connection: */
|
||||||
@ -163,7 +162,7 @@ altcp_mbedtls_lower_connected(void *arg, struct altcp_pcb *inner_conn, err_t err
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return altcp_mbedtls_lower_recv_process(conn, (altcp_mbedtls_state_t*)conn->state);
|
return altcp_mbedtls_lower_recv_process(conn, (altcp_mbedtls_state_t *)conn->state);
|
||||||
}
|
}
|
||||||
return ERR_VAL;
|
return ERR_VAL;
|
||||||
}
|
}
|
||||||
@ -216,8 +215,8 @@ altcp_mbedtls_lower_recv(void *arg, struct altcp_pcb *inner_conn, struct pbuf *p
|
|||||||
/* remote host sent FIN, remember this (SSL state is destroyed
|
/* remote host sent FIN, remember this (SSL state is destroyed
|
||||||
when both sides are closed only!) */
|
when both sides are closed only!) */
|
||||||
state->flags |= ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED;
|
state->flags |= ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED;
|
||||||
if ((state->flags & (ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE|ALTCP_MBEDTLS_FLAGS_UPPER_CALLED)) ==
|
if ((state->flags & (ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE | ALTCP_MBEDTLS_FLAGS_UPPER_CALLED)) ==
|
||||||
(ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE|ALTCP_MBEDTLS_FLAGS_UPPER_CALLED)) {
|
(ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE | ALTCP_MBEDTLS_FLAGS_UPPER_CALLED)) {
|
||||||
/* need to notify upper layer (e.g. 'accept' called or 'connect' succeeded) */
|
/* need to notify upper layer (e.g. 'accept' called or 'connect' succeeded) */
|
||||||
if ((state->rx != NULL) || (state->rx_app != NULL)) {
|
if ((state->rx != NULL) || (state->rx_app != NULL)) {
|
||||||
/* this is a normal close (FIN) but we have unprocessed data, so delay the FIN */
|
/* this is a normal close (FIN) but we have unprocessed data, so delay the FIN */
|
||||||
@ -269,7 +268,7 @@ altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *
|
|||||||
state->bio_bytes_read = 0;
|
state->bio_bytes_read = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
|
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||||
/* handshake not done, wait for more recv calls */
|
/* handshake not done, wait for more recv calls */
|
||||||
LWIP_ASSERT("in this state, the rx chain should be empty", state->rx == NULL);
|
LWIP_ASSERT("in this state, the rx chain should be empty", state->rx == NULL);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -328,7 +327,7 @@ altcp_mbedtls_pass_rx_data(struct altcp_pcb *conn, altcp_mbedtls_state_t *state)
|
|||||||
pbuf_free(buf);
|
pbuf_free(buf);
|
||||||
}
|
}
|
||||||
state->rx_app = NULL;
|
state->rx_app = NULL;
|
||||||
} else if ((state->flags & (ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED|ALTCP_MBEDTLS_FLAGS_RX_CLOSED)) ==
|
} else if ((state->flags & (ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED | ALTCP_MBEDTLS_FLAGS_RX_CLOSED)) ==
|
||||||
ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED) {
|
ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED) {
|
||||||
state->flags |= ALTCP_MBEDTLS_FLAGS_RX_CLOSED;
|
state->flags |= ALTCP_MBEDTLS_FLAGS_RX_CLOSED;
|
||||||
if (conn->recv) {
|
if (conn->recv) {
|
||||||
@ -434,7 +433,7 @@ altcp_mbedtls_bio_recv(void *ctx, unsigned char *buf, size_t len)
|
|||||||
{
|
{
|
||||||
struct altcp_pcb *conn = (struct altcp_pcb *)ctx;
|
struct altcp_pcb *conn = (struct altcp_pcb *)ctx;
|
||||||
altcp_mbedtls_state_t *state;
|
altcp_mbedtls_state_t *state;
|
||||||
struct pbuf* p;
|
struct pbuf *p;
|
||||||
u16_t ret;
|
u16_t ret;
|
||||||
u16_t copy_len;
|
u16_t copy_len;
|
||||||
err_t err;
|
err_t err;
|
||||||
@ -452,7 +451,7 @@ altcp_mbedtls_bio_recv(void *ctx, unsigned char *buf, size_t len)
|
|||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
}
|
}
|
||||||
state->rx = NULL;
|
state->rx = NULL;
|
||||||
if ((state->flags & (ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED|ALTCP_MBEDTLS_FLAGS_RX_CLOSED)) ==
|
if ((state->flags & (ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED | ALTCP_MBEDTLS_FLAGS_RX_CLOSED)) ==
|
||||||
ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED) {
|
ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED) {
|
||||||
/* close queued but not passed up yet */
|
/* close queued but not passed up yet */
|
||||||
return 0;
|
return 0;
|
||||||
@ -589,7 +588,7 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct altcp_pcb *
|
struct altcp_pcb *
|
||||||
altcp_tls_new(struct altcp_tls_config* config, struct altcp_pcb *inner_pcb)
|
altcp_tls_new(struct altcp_tls_config *config, struct altcp_pcb *inner_pcb)
|
||||||
{
|
{
|
||||||
struct altcp_pcb *ret;
|
struct altcp_pcb *ret;
|
||||||
if (inner_pcb == NULL) {
|
if (inner_pcb == NULL) {
|
||||||
@ -631,7 +630,7 @@ altcp_mbedtls_debug(void *ctx, int level, const char *file, int line, const char
|
|||||||
#ifndef ALTCP_MBEDTLS_RNG_FN
|
#ifndef ALTCP_MBEDTLS_RNG_FN
|
||||||
/** ATTENTION: It is *really* important to *NOT* use this dummy RNG in production code!!!! */
|
/** ATTENTION: It is *really* important to *NOT* use this dummy RNG in production code!!!! */
|
||||||
static int
|
static int
|
||||||
dummy_rng(void *ctx, unsigned char *buffer , size_t len)
|
dummy_rng(void *ctx, unsigned char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
static size_t ctr;
|
static size_t ctr;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -787,7 +786,7 @@ altcp_mbedtls_recved(struct altcp_pcb *conn, u16_t len)
|
|||||||
if (conn == NULL) {
|
if (conn == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state = (altcp_mbedtls_state_t*)conn->state;
|
state = (altcp_mbedtls_state_t *)conn->state;
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -846,7 +845,7 @@ altcp_mbedtls_close(struct altcp_pcb *conn)
|
|||||||
if (conn == NULL) {
|
if (conn == NULL) {
|
||||||
return ERR_VAL;
|
return ERR_VAL;
|
||||||
}
|
}
|
||||||
state = (altcp_mbedtls_state_t*)conn->state;
|
state = (altcp_mbedtls_state_t *)conn->state;
|
||||||
if (state != NULL) {
|
if (state != NULL) {
|
||||||
state->flags |= ALTCP_MBEDTLS_FLAGS_TX_CLOSED;
|
state->flags |= ALTCP_MBEDTLS_FLAGS_TX_CLOSED;
|
||||||
if (state->flags & ALTCP_MBEDTLS_FLAGS_RX_CLOSED) {
|
if (state->flags & ALTCP_MBEDTLS_FLAGS_RX_CLOSED) {
|
||||||
@ -871,7 +870,7 @@ altcp_mbedtls_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t
|
|||||||
return ERR_VAL;
|
return ERR_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = (altcp_mbedtls_state_t*)conn->state;
|
state = (altcp_mbedtls_state_t *)conn->state;
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
/* @todo: which error? */
|
/* @todo: which error? */
|
||||||
return ERR_CLSD;
|
return ERR_CLSD;
|
||||||
@ -894,7 +893,7 @@ altcp_mbedtls_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t
|
|||||||
/* try to send data... */
|
/* try to send data... */
|
||||||
altcp_output(conn->inner_conn);
|
altcp_output(conn->inner_conn);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
if(ret == len) {
|
if (ret == len) {
|
||||||
state->flags |= ALTCP_MBEDTLS_FLAGS_APPLDATA_SENT;
|
state->flags |= ALTCP_MBEDTLS_FLAGS_APPLDATA_SENT;
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
} else {
|
} else {
|
||||||
@ -917,7 +916,7 @@ altcp_mbedtls_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t
|
|||||||
* data via @ref altcp_mbedtls_write (or altcp_write)
|
* data via @ref altcp_mbedtls_write (or altcp_write)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
altcp_mbedtls_bio_send(void* ctx, const unsigned char* dataptr, size_t size)
|
altcp_mbedtls_bio_send(void *ctx, const unsigned char *dataptr, size_t size)
|
||||||
{
|
{
|
||||||
struct altcp_pcb *conn = (struct altcp_pcb *) ctx;
|
struct altcp_pcb *conn = (struct altcp_pcb *) ctx;
|
||||||
int written = 0;
|
int written = 0;
|
||||||
@ -964,7 +963,7 @@ altcp_mbedtls_dealloc(struct altcp_pcb *conn)
|
|||||||
{
|
{
|
||||||
/* clean up and free tls state */
|
/* clean up and free tls state */
|
||||||
if (conn) {
|
if (conn) {
|
||||||
altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t*)conn->state;
|
altcp_mbedtls_state_t *state = (altcp_mbedtls_state_t *)conn->state;
|
||||||
if (state) {
|
if (state) {
|
||||||
mbedtls_ssl_free(&state->ssl_context);
|
mbedtls_ssl_free(&state->ssl_context);
|
||||||
state->flags = 0;
|
state->flags = 0;
|
||||||
@ -1001,7 +1000,7 @@ const struct altcp_functions altcp_mbedtls_functions = {
|
|||||||
altcp_default_get_ip,
|
altcp_default_get_ip,
|
||||||
altcp_default_get_port
|
altcp_default_get_port
|
||||||
#ifdef LWIP_DEBUG
|
#ifdef LWIP_DEBUG
|
||||||
,altcp_default_dbg_get_tcp_state
|
, altcp_default_dbg_get_tcp_state
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,8 +102,8 @@ volatile int altcp_mbedtls_malloc_clear_stats;
|
|||||||
static void *
|
static void *
|
||||||
tls_malloc(size_t c, size_t len)
|
tls_malloc(size_t c, size_t len)
|
||||||
{
|
{
|
||||||
altcp_mbedtls_malloc_helper_t* hlpr;
|
altcp_mbedtls_malloc_helper_t *hlpr;
|
||||||
void* ret;
|
void *ret;
|
||||||
size_t alloc_size;
|
size_t alloc_size;
|
||||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
||||||
if (altcp_mbedtls_malloc_clear_stats) {
|
if (altcp_mbedtls_malloc_clear_stats) {
|
||||||
@ -113,46 +113,46 @@ tls_malloc(size_t c, size_t len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
alloc_size = sizeof(altcp_mbedtls_malloc_helper_t) + (c*len);
|
alloc_size = sizeof(altcp_mbedtls_malloc_helper_t) + (c * len);
|
||||||
/* check for maximum allocation size, mainly to prevent mem_size_t overflow */
|
/* check for maximum allocation size, mainly to prevent mem_size_t overflow */
|
||||||
if (alloc_size > MEM_SIZE) {
|
if (alloc_size > MEM_SIZE) {
|
||||||
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls allocation too big: %c * %d bytes vs MEM_SIZE=%d",
|
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls allocation too big: %c * %d bytes vs MEM_SIZE=%d",
|
||||||
(int)c, (int)len, (int)MEM_SIZE));
|
(int)c, (int)len, (int)MEM_SIZE));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
hlpr = (altcp_mbedtls_malloc_helper_t*)mem_malloc((mem_size_t)alloc_size);
|
hlpr = (altcp_mbedtls_malloc_helper_t *)mem_malloc((mem_size_t)alloc_size);
|
||||||
if (hlpr == NULL) {
|
if (hlpr == NULL) {
|
||||||
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls alloc callback failed for %c * %d bytes", (int)c, (int)len));
|
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls alloc callback failed for %c * %d bytes", (int)c, (int)len));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
||||||
altcp_mbedtls_malloc_stats.allocCnt++;
|
altcp_mbedtls_malloc_stats.allocCnt++;
|
||||||
altcp_mbedtls_malloc_stats.allocedBytes += c*len;
|
altcp_mbedtls_malloc_stats.allocedBytes += c * len;
|
||||||
if (altcp_mbedtls_malloc_stats.allocedBytes > altcp_mbedtls_malloc_stats.maxBytes) {
|
if (altcp_mbedtls_malloc_stats.allocedBytes > altcp_mbedtls_malloc_stats.maxBytes) {
|
||||||
altcp_mbedtls_malloc_stats.maxBytes = altcp_mbedtls_malloc_stats.allocedBytes;
|
altcp_mbedtls_malloc_stats.maxBytes = altcp_mbedtls_malloc_stats.allocedBytes;
|
||||||
}
|
}
|
||||||
altcp_mbedtls_malloc_stats.totalBytes += c*len;
|
altcp_mbedtls_malloc_stats.totalBytes += c * len;
|
||||||
#endif
|
#endif
|
||||||
hlpr->c = c;
|
hlpr->c = c;
|
||||||
hlpr->len = len;
|
hlpr->len = len;
|
||||||
ret = hlpr + 1;
|
ret = hlpr + 1;
|
||||||
/* zeroing the allocated chunk is required by mbedTLS! */
|
/* zeroing the allocated chunk is required by mbedTLS! */
|
||||||
memset(ret, 0, c*len);
|
memset(ret, 0, c * len);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tls_free(void * ptr)
|
tls_free(void *ptr)
|
||||||
{
|
{
|
||||||
altcp_mbedtls_malloc_helper_t *hlpr;
|
altcp_mbedtls_malloc_helper_t *hlpr;
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
/* this obviously happened in mbedtls... */
|
/* this obviously happened in mbedtls... */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hlpr = ((altcp_mbedtls_malloc_helper_t *)ptr)-1;
|
hlpr = ((altcp_mbedtls_malloc_helper_t *)ptr) - 1;
|
||||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
||||||
if (!altcp_mbedtls_malloc_clear_stats) {
|
if (!altcp_mbedtls_malloc_clear_stats) {
|
||||||
altcp_mbedtls_malloc_stats.allocedBytes -= hlpr->c*hlpr->len;
|
altcp_mbedtls_malloc_stats.allocedBytes -= hlpr->c * hlpr->len;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
mem_free(hlpr);
|
mem_free(hlpr);
|
||||||
|
@ -68,8 +68,8 @@ typedef struct altcp_mbedtls_state_s {
|
|||||||
void *conf;
|
void *conf;
|
||||||
mbedtls_ssl_context ssl_context;
|
mbedtls_ssl_context ssl_context;
|
||||||
/* chain of rx pbufs (before decryption) */
|
/* chain of rx pbufs (before decryption) */
|
||||||
struct pbuf* rx;
|
struct pbuf *rx;
|
||||||
struct pbuf* rx_app;
|
struct pbuf *rx_app;
|
||||||
u8_t flags;
|
u8_t flags;
|
||||||
int rx_passed_unrecved;
|
int rx_passed_unrecved;
|
||||||
int bio_bytes_read;
|
int bio_bytes_read;
|
||||||
|
Loading…
Reference in New Issue
Block a user