Reformat api_msg.c using astylerc

This commit is contained in:
Dirk Ziegelmeier 2017-09-17 17:42:30 +02:00
parent 30152cea78
commit 2b977a4a6a

View File

@ -90,20 +90,19 @@ const u8_t netconn_reset = 0;
const u8_t netconn_closed = 0;
/** Translate an error to a unique void* passed via an mbox */
static void*
static void *
lwip_netconn_err_to_msg(err_t err)
{
switch(err)
{
case ERR_ABRT:
return LWIP_CONST_CAST(void*, &netconn_aborted);
case ERR_RST:
return LWIP_CONST_CAST(void*, &netconn_reset);
case ERR_CLSD:
return LWIP_CONST_CAST(void*, &netconn_closed);
default:
LWIP_ASSERT("unhandled error", err == ERR_OK);
return NULL;
switch (err) {
case ERR_ABRT:
return LWIP_CONST_CAST(void *, &netconn_aborted);
case ERR_RST:
return LWIP_CONST_CAST(void *, &netconn_reset);
case ERR_CLSD:
return LWIP_CONST_CAST(void *, &netconn_closed);
default:
LWIP_ASSERT("unhandled error", err == ERR_OK);
return NULL;
}
}
@ -137,7 +136,7 @@ lwip_netconn_is_err_msg(void *msg, err_t *err)
*/
static u8_t
recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr)
const ip_addr_t *addr)
{
struct pbuf *q;
struct netbuf *buf;
@ -203,7 +202,7 @@ recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
*/
static void
recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port)
const ip_addr_t *addr, u16_t port)
{
struct netbuf *buf;
struct netconn *conn;
@ -247,7 +246,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
#if LWIP_NETBUF_RECVINFO
if (conn->flags & NETCONN_FLAG_PKTINFO) {
/* get the UDP header - always in the first pbuf, ensured by udp_input */
const struct udp_hdr* udphdr = (const struct udp_hdr*)ip_next_header_ptr();
const struct udp_hdr *udphdr = (const struct udp_hdr *)ip_next_header_ptr();
buf->flags = NETBUF_FLAG_DESTADDR;
ip_addr_set(&buf->toaddr, ip_current_dest_addr());
buf->toport_chksum = udphdr->dest;
@ -310,7 +309,7 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
msg = p;
len = p->tot_len;
} else {
msg = LWIP_CONST_CAST(void*, &netconn_closed);
msg = LWIP_CONST_CAST(void *, &netconn_closed);
len = 0;
}
@ -364,7 +363,7 @@ poll_tcp(void *arg, struct tcp_pcb *pcb)
/* If the queued byte- or pbuf-count drops below the configured low-water limit,
let select mark this pcb as writable again. */
if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT) &&
(tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT)) {
(tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT)) {
netconn_clear_flags(conn, NETCONN_FLAG_CHECK_WRITESPACE);
API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
}
@ -398,7 +397,7 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
/* If the queued byte- or pbuf-count drops below the configured low-water limit,
let select mark this pcb as writable again. */
if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT) &&
(tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT)) {
(tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT)) {
netconn_clear_flags(conn, NETCONN_FLAG_CHECK_WRITESPACE);
API_EVENT(conn, NETCONN_EVT_SENDPLUS, len);
}
@ -467,7 +466,7 @@ err_tcp(void *arg, err_t err)
SET_NONBLOCKING_CONNECT(conn, 0);
if (!was_nonblocking_connect) {
sys_sem_t* op_completed_sem;
sys_sem_t *op_completed_sem;
/* set error return code */
LWIP_ASSERT("conn->current_msg != NULL", conn->current_msg != NULL);
if (old_state == NETCONN_CLOSE) {
@ -563,7 +562,7 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
/* When returning != ERR_OK, the pcb is aborted in tcp_process(),
so do nothing here! */
/* remove all references to this netconn from the pcb */
struct tcp_pcb* pcb = newconn->pcb.tcp;
struct tcp_pcb *pcb = newconn->pcb.tcp;
tcp_arg(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_sent(pcb, NULL);
@ -597,59 +596,59 @@ pcb_new(struct api_msg *msg)
enum lwip_ip_addr_type iptype = IPADDR_TYPE_V4;
LWIP_ASSERT("pcb_new: pcb already allocated", msg->conn->pcb.tcp == NULL);
#if LWIP_IPV6 && LWIP_IPV4
/* IPv6: Dual-stack by default, unless netconn_set_ipv6only() is called */
if(NETCONNTYPE_ISIPV6(netconn_type(msg->conn))) {
if (NETCONNTYPE_ISIPV6(netconn_type(msg->conn))) {
iptype = IPADDR_TYPE_ANY;
}
#endif
/* Allocate a PCB for this connection */
switch(NETCONNTYPE_GROUP(msg->conn->type)) {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
msg->conn->pcb.raw = raw_new_ip_type(iptype, msg->msg.n.proto);
if (msg->conn->pcb.raw != NULL) {
case NETCONN_RAW:
msg->conn->pcb.raw = raw_new_ip_type(iptype, msg->msg.n.proto);
if (msg->conn->pcb.raw != NULL) {
#if LWIP_IPV6
/* ICMPv6 packets should always have checksum calculated by the stack as per RFC 3542 chapter 3.1 */
if (NETCONNTYPE_ISIPV6(msg->conn->type) && msg->conn->pcb.raw->protocol == IP6_NEXTH_ICMP6) {
msg->conn->pcb.raw->chksum_reqd = 1;
msg->conn->pcb.raw->chksum_offset = 2;
}
/* ICMPv6 packets should always have checksum calculated by the stack as per RFC 3542 chapter 3.1 */
if (NETCONNTYPE_ISIPV6(msg->conn->type) && msg->conn->pcb.raw->protocol == IP6_NEXTH_ICMP6) {
msg->conn->pcb.raw->chksum_reqd = 1;
msg->conn->pcb.raw->chksum_offset = 2;
}
#endif /* LWIP_IPV6 */
raw_recv(msg->conn->pcb.raw, recv_raw, msg->conn);
}
break;
raw_recv(msg->conn->pcb.raw, recv_raw, msg->conn);
}
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
msg->conn->pcb.udp = udp_new_ip_type(iptype);
if (msg->conn->pcb.udp != NULL) {
case NETCONN_UDP:
msg->conn->pcb.udp = udp_new_ip_type(iptype);
if (msg->conn->pcb.udp != NULL) {
#if LWIP_UDPLITE
if (NETCONNTYPE_ISUDPLITE(msg->conn->type)) {
udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE);
}
if (NETCONNTYPE_ISUDPLITE(msg->conn->type)) {
udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE);
}
#endif /* LWIP_UDPLITE */
if (NETCONNTYPE_ISUDPNOCHKSUM(msg->conn->type)) {
udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM);
if (NETCONNTYPE_ISUDPNOCHKSUM(msg->conn->type)) {
udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM);
}
udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
}
udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
}
break;
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
msg->conn->pcb.tcp = tcp_new_ip_type(iptype);
if (msg->conn->pcb.tcp != NULL) {
setup_tcp(msg->conn);
}
break;
case NETCONN_TCP:
msg->conn->pcb.tcp = tcp_new_ip_type(iptype);
if (msg->conn->pcb.tcp != NULL) {
setup_tcp(msg->conn);
}
break;
#endif /* LWIP_TCP */
default:
/* Unsupported netconn type, e.g. protocol disabled */
msg->err = ERR_VAL;
return;
default:
/* Unsupported netconn type, e.g. protocol disabled */
msg->err = ERR_VAL;
return;
}
if (msg->conn->pcb.ip == NULL) {
msg->err = ERR_MEM;
@ -665,7 +664,7 @@ pcb_new(struct api_msg *msg)
void
lwip_netconn_do_newconn(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
msg->err = ERR_OK;
if (msg->conn->pcb.tcp == NULL) {
@ -687,7 +686,7 @@ lwip_netconn_do_newconn(void *m)
* @return a newly allocated struct netconn or
* NULL on memory error
*/
struct netconn*
struct netconn *
netconn_alloc(enum netconn_type t, netconn_callback callback)
{
struct netconn *conn;
@ -704,28 +703,28 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
conn->pcb.tcp = NULL;
/* If all sizes are the same, every compiler should optimize this switch to nothing */
switch(NETCONNTYPE_GROUP(t)) {
switch (NETCONNTYPE_GROUP(t)) {
#if LWIP_RAW
case NETCONN_RAW:
size = DEFAULT_RAW_RECVMBOX_SIZE;
break;
case NETCONN_RAW:
size = DEFAULT_RAW_RECVMBOX_SIZE;
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
size = DEFAULT_UDP_RECVMBOX_SIZE;
case NETCONN_UDP:
size = DEFAULT_UDP_RECVMBOX_SIZE;
#if LWIP_NETBUF_RECVINFO
init_flags |= NETCONN_FLAG_PKTINFO;
init_flags |= NETCONN_FLAG_PKTINFO;
#endif /* LWIP_NETBUF_RECVINFO */
break;
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
size = DEFAULT_TCP_RECVMBOX_SIZE;
break;
case NETCONN_TCP:
size = DEFAULT_TCP_RECVMBOX_SIZE;
break;
#endif /* LWIP_TCP */
default:
LWIP_ASSERT("netconn_alloc: undefined netconn_type", 0);
goto free_and_return;
default:
LWIP_ASSERT("netconn_alloc: undefined netconn_type", 0);
goto free_and_return;
}
if (sys_mbox_new(&conn->recvmbox, size) != ERR_OK) {
@ -781,10 +780,10 @@ netconn_free(struct netconn *conn)
{
LWIP_ASSERT("PCB must be deallocated outside this function", conn->pcb.tcp == NULL);
LWIP_ASSERT("recvmbox must be deallocated before calling this function",
!sys_mbox_valid(&conn->recvmbox));
!sys_mbox_valid(&conn->recvmbox));
#if LWIP_TCP
LWIP_ASSERT("acceptmbox must be deallocated before calling this function",
!sys_mbox_valid(&conn->acceptmbox));
!sys_mbox_valid(&conn->acceptmbox));
#endif /* LWIP_TCP */
#if !LWIP_NETCONN_SEM_PER_THREAD
@ -820,7 +819,7 @@ netconn_drain(struct netconn *conn)
if (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP) {
err_t err;
if (!lwip_netconn_is_err_msg(mem, &err)) {
p = (struct pbuf*)mem;
p = (struct pbuf *)mem;
/* pcb might be set to NULL already by err_tcp() */
if (conn->pcb.tcp != NULL) {
tcp_recved(conn->pcb.tcp, p->tot_len);
@ -875,7 +874,7 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
err_t err;
u8_t shut, shut_rx, shut_tx, shut_close;
u8_t close_finished = 0;
struct tcp_pcb* tpcb;
struct tcp_pcb *tpcb;
#if LWIP_SO_LINGER
u8_t linger_wait_required = 0;
#endif /* LWIP_SO_LINGER */
@ -942,7 +941,7 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
/* data left on a nonblocking netconn -> cannot linger */
err = ERR_WOULDBLOCK;
} else if ((s32_t)(sys_now() - conn->current_msg->msg.sd.time_started) >=
(conn->linger * 1000)) {
(conn->linger * 1000)) {
/* data left but linger timeout has expired (this happens on further
calls to this function through poll_tcp */
tcp_abort(tpcb);
@ -1008,7 +1007,7 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
}
if (close_finished) {
/* Closing done (succeeded, non-memory error, nonblocking error or timeout) */
sys_sem_t* op_completed_sem = LWIP_API_MSG_SEM(conn->current_msg);
sys_sem_t *op_completed_sem = LWIP_API_MSG_SEM(conn->current_msg);
conn->current_msg->err = err;
conn->current_msg = NULL;
conn->state = NETCONN_NONE;
@ -1065,18 +1064,18 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
void
lwip_netconn_do_delconn(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
enum netconn_state state = msg->conn->state;
LWIP_ASSERT("netconn state error", /* this only happens for TCP netconns */
(state == NETCONN_NONE) || (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP));
(state == NETCONN_NONE) || (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP));
#if LWIP_NETCONN_FULLDUPLEX
/* In full duplex mode, blocking write/connect is aborted with ERR_CLSD */
if (state != NETCONN_NONE) {
if ((state == NETCONN_WRITE) ||
((state == NETCONN_CONNECT) && !IN_NONBLOCKING_CONNECT(msg->conn))) {
/* close requested, abort running write/connect */
sys_sem_t* op_completed_sem;
sys_sem_t *op_completed_sem;
LWIP_ASSERT("msg->conn->current_msg != NULL", msg->conn->current_msg != NULL);
op_completed_sem = LWIP_API_MSG_SEM(msg->conn->current_msg);
msg->conn->current_msg->err = ERR_CLSD;
@ -1097,7 +1096,7 @@ lwip_netconn_do_delconn(void *m)
#endif /* LWIP_NETCONN_FULLDUPLEX */
{
LWIP_ASSERT("blocking connect in progress",
(state != NETCONN_CONNECT) || IN_NONBLOCKING_CONNECT(msg->conn));
(state != NETCONN_CONNECT) || IN_NONBLOCKING_CONNECT(msg->conn));
msg->err = ERR_OK;
/* Drain and delete mboxes */
netconn_drain(msg->conn);
@ -1106,39 +1105,39 @@ lwip_netconn_do_delconn(void *m)
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
raw_remove(msg->conn->pcb.raw);
break;
case NETCONN_RAW:
raw_remove(msg->conn->pcb.raw);
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
msg->conn->pcb.udp->recv_arg = NULL;
udp_remove(msg->conn->pcb.udp);
break;
case NETCONN_UDP:
msg->conn->pcb.udp->recv_arg = NULL;
udp_remove(msg->conn->pcb.udp);
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
LWIP_ASSERT("already writing or closing", msg->conn->current_msg == NULL);
msg->conn->state = NETCONN_CLOSE;
msg->msg.sd.shut = NETCONN_SHUT_RDWR;
msg->conn->current_msg = msg;
case NETCONN_TCP:
LWIP_ASSERT("already writing or closing", msg->conn->current_msg == NULL);
msg->conn->state = NETCONN_CLOSE;
msg->msg.sd.shut = NETCONN_SHUT_RDWR;
msg->conn->current_msg = msg;
#if LWIP_TCPIP_CORE_LOCKING
if (lwip_netconn_do_close_internal(msg->conn, 0) != ERR_OK) {
LWIP_ASSERT("state!", msg->conn->state == NETCONN_CLOSE);
UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state == NETCONN_NONE);
}
if (lwip_netconn_do_close_internal(msg->conn, 0) != ERR_OK) {
LWIP_ASSERT("state!", msg->conn->state == NETCONN_CLOSE);
UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state == NETCONN_NONE);
}
#else /* LWIP_TCPIP_CORE_LOCKING */
lwip_netconn_do_close_internal(msg->conn);
lwip_netconn_do_close_internal(msg->conn);
#endif /* LWIP_TCPIP_CORE_LOCKING */
/* API_EVENT is called inside lwip_netconn_do_close_internal, before releasing
the application thread, so we can return at this point! */
return;
/* API_EVENT is called inside lwip_netconn_do_close_internal, before releasing
the application thread, so we can return at this point! */
return;
#endif /* LWIP_TCP */
default:
break;
default:
break;
}
msg->conn->pcb.tcp = NULL;
}
@ -1164,29 +1163,29 @@ lwip_netconn_do_delconn(void *m)
void
lwip_netconn_do_bind(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
err_t err;
if (msg->conn->pcb.tcp != NULL) {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
err = raw_bind(msg->conn->pcb.raw, API_EXPR_REF(msg->msg.bc.ipaddr));
break;
case NETCONN_RAW:
err = raw_bind(msg->conn->pcb.raw, API_EXPR_REF(msg->msg.bc.ipaddr));
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
err = udp_bind(msg->conn->pcb.udp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
case NETCONN_UDP:
err = udp_bind(msg->conn->pcb.udp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
err = tcp_bind(msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
case NETCONN_TCP:
err = tcp_bind(msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
#endif /* LWIP_TCP */
default:
err = ERR_VAL;
break;
default:
err = ERR_VAL;
break;
}
} else {
err = ERR_VAL;
@ -1204,33 +1203,33 @@ lwip_netconn_do_bind(void *m)
void
lwip_netconn_do_bind_if(void *m)
{
struct netif* netif;
struct api_msg *msg = (struct api_msg*)m;
struct netif *netif;
struct api_msg *msg = (struct api_msg *)m;
err_t err;
netif = netif_get_by_index(msg->msg.bc.if_idx);
if ((netif != NULL) && (msg->conn->pcb.tcp != NULL)) {
err = ERR_OK;
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
raw_bind_netif(msg->conn->pcb.raw, netif);
break;
case NETCONN_RAW:
raw_bind_netif(msg->conn->pcb.raw, netif);
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
udp_bind_netif(msg->conn->pcb.udp, netif);
break;
case NETCONN_UDP:
udp_bind_netif(msg->conn->pcb.udp, netif);
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
tcp_bind_netif(msg->conn->pcb.tcp, netif);
break;
case NETCONN_TCP:
tcp_bind_netif(msg->conn->pcb.tcp, netif);
break;
#endif /* LWIP_TCP */
default:
err = ERR_VAL;
break;
default:
err = ERR_VAL;
break;
}
} else {
err = ERR_VAL;
@ -1251,7 +1250,7 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
{
struct netconn *conn;
int was_blocking;
sys_sem_t* op_completed_sem = NULL;
sys_sem_t *op_completed_sem = NULL;
LWIP_UNUSED_ARG(pcb);
@ -1263,7 +1262,7 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
LWIP_ASSERT("conn->state == NETCONN_CONNECT", conn->state == NETCONN_CONNECT);
LWIP_ASSERT("(conn->current_msg != NULL) || conn->in_non_blocking_connect",
(conn->current_msg != NULL) || IN_NONBLOCKING_CONNECT(conn));
(conn->current_msg != NULL) || IN_NONBLOCKING_CONNECT(conn));
if (conn->current_msg != NULL) {
conn->current_msg->err = err;
@ -1275,8 +1274,8 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
was_blocking = !IN_NONBLOCKING_CONNECT(conn);
SET_NONBLOCKING_CONNECT(conn, 0);
LWIP_ASSERT("blocking connect state error",
(was_blocking && op_completed_sem != NULL) ||
(!was_blocking && op_completed_sem == NULL));
(was_blocking && op_completed_sem != NULL) ||
(!was_blocking && op_completed_sem == NULL));
conn->current_msg = NULL;
conn->state = NETCONN_NONE;
API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
@ -1298,7 +1297,7 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
void
lwip_netconn_do_connect(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
err_t err;
if (msg->conn->pcb.tcp == NULL) {
@ -1307,52 +1306,54 @@ lwip_netconn_do_connect(void *m)
} else {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
err = raw_connect(msg->conn->pcb.raw, API_EXPR_REF(msg->msg.bc.ipaddr));
break;
case NETCONN_RAW:
err = raw_connect(msg->conn->pcb.raw, API_EXPR_REF(msg->msg.bc.ipaddr));
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
err = udp_connect(msg->conn->pcb.udp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
case NETCONN_UDP:
err = udp_connect(msg->conn->pcb.udp, API_EXPR_REF(msg->msg.bc.ipaddr), msg->msg.bc.port);
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
/* Prevent connect while doing any other action. */
if (msg->conn->state == NETCONN_CONNECT) {
err = ERR_ALREADY;
} else if (msg->conn->state != NETCONN_NONE) {
err = ERR_ISCONN;
} else {
setup_tcp(msg->conn);
err = tcp_connect(msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr),
msg->msg.bc.port, lwip_netconn_do_connected);
if (err == ERR_OK) {
u8_t non_blocking = netconn_is_nonblocking(msg->conn);
msg->conn->state = NETCONN_CONNECT;
SET_NONBLOCKING_CONNECT(msg->conn, non_blocking);
if (non_blocking) {
err = ERR_INPROGRESS;
} else {
msg->conn->current_msg = msg;
/* sys_sem_signal() is called from lwip_netconn_do_connected (or err_tcp()),
when the connection is established! */
case NETCONN_TCP:
/* Prevent connect while doing any other action. */
if (msg->conn->state == NETCONN_CONNECT) {
err = ERR_ALREADY;
} else if (msg->conn->state != NETCONN_NONE) {
err = ERR_ISCONN;
} else {
setup_tcp(msg->conn);
err = tcp_connect(msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr),
msg->msg.bc.port, lwip_netconn_do_connected);
if (err == ERR_OK) {
u8_t non_blocking = netconn_is_nonblocking(msg->conn);
msg->conn->state = NETCONN_CONNECT;
SET_NONBLOCKING_CONNECT(msg->conn, non_blocking);
if (non_blocking) {
err = ERR_INPROGRESS;
} else {
msg->conn->current_msg = msg;
/* sys_sem_signal() is called from lwip_netconn_do_connected (or err_tcp()),
when the connection is established! */
#if LWIP_TCPIP_CORE_LOCKING
LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT);
UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT);
LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT);
UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT);
#endif /* LWIP_TCPIP_CORE_LOCKING */
return;
return;
}
}
}
}
break;
break;
#endif /* LWIP_TCP */
default:
LWIP_ERROR("Invalid netconn type", 0, do{ err = ERR_VAL; }while(0));
break;
default:
LWIP_ERROR("Invalid netconn type", 0, do {
err = ERR_VAL;
} while (0));
break;
}
}
msg->err = err;
@ -1371,7 +1372,7 @@ lwip_netconn_do_connect(void *m)
void
lwip_netconn_do_disconnect(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
#if LWIP_UDP
if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) {
@ -1395,13 +1396,13 @@ lwip_netconn_do_disconnect(void *m)
void
lwip_netconn_do_listen(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
err_t err;
if (msg->conn->pcb.tcp != NULL) {
if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP) {
if (msg->conn->state == NETCONN_NONE) {
struct tcp_pcb* lpcb;
struct tcp_pcb *lpcb;
if (msg->conn->pcb.tcp->state != CLOSED) {
/* connection is not closed, cannot listen */
err = ERR_VAL;
@ -1455,8 +1456,7 @@ lwip_netconn_do_listen(void *m)
/* already listening, allow updating of the backlog */
err = ERR_OK;
tcp_backlog_set(msg->conn->pcb.tcp, msg->msg.lb.backlog);
}
else {
} else {
err = ERR_CONN;
}
} else {
@ -1479,44 +1479,44 @@ lwip_netconn_do_listen(void *m)
void
lwip_netconn_do_send(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
err_t err = netconn_err(msg->conn);
if (err == ERR_OK) {
if (msg->conn->pcb.tcp != NULL) {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
if (ip_addr_isany(&msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
err = raw_send(msg->conn->pcb.raw, msg->msg.b->p);
} else {
err = raw_sendto(msg->conn->pcb.raw, msg->msg.b->p, &msg->msg.b->addr);
}
break;
case NETCONN_RAW:
if (ip_addr_isany(&msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
err = raw_send(msg->conn->pcb.raw, msg->msg.b->p);
} else {
err = raw_sendto(msg->conn->pcb.raw, msg->msg.b->p, &msg->msg.b->addr);
}
break;
#endif
#if LWIP_UDP
case NETCONN_UDP:
case NETCONN_UDP:
#if LWIP_CHECKSUM_ON_COPY
if (ip_addr_isany(&msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
err = udp_send_chksum(msg->conn->pcb.udp, msg->msg.b->p,
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
} else {
err = udp_sendto_chksum(msg->conn->pcb.udp, msg->msg.b->p,
&msg->msg.b->addr, msg->msg.b->port,
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
}
if (ip_addr_isany(&msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
err = udp_send_chksum(msg->conn->pcb.udp, msg->msg.b->p,
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
} else {
err = udp_sendto_chksum(msg->conn->pcb.udp, msg->msg.b->p,
&msg->msg.b->addr, msg->msg.b->port,
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
}
#else /* LWIP_CHECKSUM_ON_COPY */
if (ip_addr_isany_val(msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
} else {
err = udp_sendto(msg->conn->pcb.udp, msg->msg.b->p, &msg->msg.b->addr, msg->msg.b->port);
}
if (ip_addr_isany_val(msg->msg.b->addr) || IP_IS_ANY_TYPE_VAL(msg->msg.b->addr)) {
err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
} else {
err = udp_sendto(msg->conn->pcb.udp, msg->msg.b->p, &msg->msg.b->addr, msg->msg.b->port);
}
#endif /* LWIP_CHECKSUM_ON_COPY */
break;
break;
#endif /* LWIP_UDP */
default:
err = ERR_CONN;
break;
default:
err = ERR_CONN;
break;
}
} else {
err = ERR_CONN;
@ -1536,7 +1536,7 @@ lwip_netconn_do_send(void *m)
void
lwip_netconn_do_recv(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
msg->err = ERR_OK;
if (msg->conn->pcb.tcp != NULL) {
@ -1561,7 +1561,7 @@ lwip_netconn_do_recv(void *m)
void
lwip_netconn_do_accepted(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
msg->err = ERR_OK;
if (msg->conn->pcb.tcp != NULL) {
@ -1601,7 +1601,7 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
LWIP_ASSERT("conn->current_msg != NULL", conn->current_msg != NULL);
LWIP_ASSERT("conn->pcb.tcp != NULL", conn->pcb.tcp != NULL);
LWIP_ASSERT("conn->current_msg->msg.w.offset < conn->current_msg->msg.w.len",
conn->current_msg->msg.w.offset < conn->current_msg->msg.w.len);
conn->current_msg->msg.w.offset < conn->current_msg->msg.w.len);
LWIP_ASSERT("conn->current_msg->msg.w.vector_cnt > 0", conn->current_msg->msg.w.vector_cnt > 0);
apiflags = conn->current_msg->msg.w.apiflags;
@ -1622,7 +1622,7 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
#endif /* LWIP_SO_SNDTIMEO */
{
do {
dataptr = (const u8_t*)conn->current_msg->msg.w.vector->ptr + conn->current_msg->msg.w.vector_off;
dataptr = (const u8_t *)conn->current_msg->msg.w.vector->ptr + conn->current_msg->msg.w.vector_off;
diff = conn->current_msg->msg.w.vector->len - conn->current_msg->msg.w.vector_off;
if (diff > 0xffffUL) { /* max_u16_t */
len = 0xffff;
@ -1645,7 +1645,7 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
}
}
LWIP_ASSERT("lwip_netconn_do_writemore: invalid length!",
((conn->current_msg->msg.w.vector_off + len) <= conn->current_msg->msg.w.vector->len));
((conn->current_msg->msg.w.vector_off + len) <= conn->current_msg->msg.w.vector->len));
/* we should loop around for more sending in the following cases:
1) We couldn't finish the current vector because of 16-bit size limitations.
tcp_write() and tcp_sndbuf() both are limited to 16-bit sizes
@ -1731,7 +1731,7 @@ err_mem:
if (write_finished) {
/* everything was written: set back connection state
and back to application task */
sys_sem_t* op_completed_sem = LWIP_API_MSG_SEM(conn->current_msg);
sys_sem_t *op_completed_sem = LWIP_API_MSG_SEM(conn->current_msg);
conn->current_msg->err = err;
conn->current_msg = NULL;
conn->state = NETCONN_NONE;
@ -1760,7 +1760,7 @@ err_mem:
void
lwip_netconn_do_write(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
err_t err = netconn_err(msg->conn);
if (err == ERR_OK) {
@ -1814,56 +1814,56 @@ lwip_netconn_do_write(void *m)
void
lwip_netconn_do_getaddr(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
if (msg->conn->pcb.ip != NULL) {
if (msg->msg.ad.local) {
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr),
msg->conn->pcb.ip->local_ip);
msg->conn->pcb.ip->local_ip);
} else {
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr),
msg->conn->pcb.ip->remote_ip);
msg->conn->pcb.ip->remote_ip);
}
msg->err = ERR_OK;
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
if (msg->msg.ad.local) {
API_EXPR_DEREF(msg->msg.ad.port) = msg->conn->pcb.raw->protocol;
} else {
/* return an error as connecting is only a helper for upper layers */
msg->err = ERR_CONN;
}
break;
case NETCONN_RAW:
if (msg->msg.ad.local) {
API_EXPR_DEREF(msg->msg.ad.port) = msg->conn->pcb.raw->protocol;
} else {
/* return an error as connecting is only a helper for upper layers */
msg->err = ERR_CONN;
}
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDP:
if (msg->msg.ad.local) {
API_EXPR_DEREF(msg->msg.ad.port) = msg->conn->pcb.udp->local_port;
} else {
if ((msg->conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0) {
msg->err = ERR_CONN;
case NETCONN_UDP:
if (msg->msg.ad.local) {
API_EXPR_DEREF(msg->msg.ad.port) = msg->conn->pcb.udp->local_port;
} else {
API_EXPR_DEREF(msg->msg.ad.port) = msg->conn->pcb.udp->remote_port;
if ((msg->conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0) {
msg->err = ERR_CONN;
} else {
API_EXPR_DEREF(msg->msg.ad.port) = msg->conn->pcb.udp->remote_port;
}
}
}
break;
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
if ((msg->msg.ad.local == 0) &&
((msg->conn->pcb.tcp->state == CLOSED) || (msg->conn->pcb.tcp->state == LISTEN))) {
/* pcb is not connected and remote name is requested */
msg->err = ERR_CONN;
} else {
API_EXPR_DEREF(msg->msg.ad.port) = (msg->msg.ad.local ? msg->conn->pcb.tcp->local_port : msg->conn->pcb.tcp->remote_port);
}
break;
case NETCONN_TCP:
if ((msg->msg.ad.local == 0) &&
((msg->conn->pcb.tcp->state == CLOSED) || (msg->conn->pcb.tcp->state == LISTEN))) {
/* pcb is not connected and remote name is requested */
msg->err = ERR_CONN;
} else {
API_EXPR_DEREF(msg->msg.ad.port) = (msg->msg.ad.local ? msg->conn->pcb.tcp->local_port : msg->conn->pcb.tcp->remote_port);
}
break;
#endif /* LWIP_TCP */
default:
LWIP_ASSERT("invalid netconn_type", 0);
break;
default:
LWIP_ASSERT("invalid netconn_type", 0);
break;
}
} else {
msg->err = ERR_CONN;
@ -1881,7 +1881,7 @@ lwip_netconn_do_getaddr(void *m)
void
lwip_netconn_do_close(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
#if LWIP_TCP
enum netconn_state state = msg->conn->state;
@ -1898,7 +1898,7 @@ lwip_netconn_do_close(void *m)
#if LWIP_NETCONN_FULLDUPLEX
if (msg->msg.sd.shut & NETCONN_SHUT_WR) {
/* close requested, abort running write */
sys_sem_t* write_completed_sem;
sys_sem_t *write_completed_sem;
LWIP_ASSERT("msg->conn->current_msg != NULL", msg->conn->current_msg != NULL);
write_completed_sem = LWIP_API_MSG_SEM(msg->conn->current_msg);
msg->conn->current_msg->err = ERR_CLSD;
@ -1957,7 +1957,7 @@ lwip_netconn_do_close(void *m)
void
lwip_netconn_do_join_leave_group(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
msg->err = ERR_CONN;
if (msg->conn->pcb.tcp != NULL) {
@ -1967,22 +1967,21 @@ lwip_netconn_do_join_leave_group(void *m)
if (NETCONNTYPE_ISIPV6(msg->conn->type)) {
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
msg->err = mld6_joingroup(ip_2_ip6(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
} else {
msg->err = mld6_leavegroup(ip_2_ip6(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
}
}
else
} else
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
{
#if LWIP_IGMP
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
msg->err = igmp_joingroup(ip_2_ip4(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
} else {
msg->err = igmp_leavegroup(ip_2_ip4(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
}
#endif /* LWIP_IGMP */
}
@ -2004,7 +2003,7 @@ lwip_netconn_do_join_leave_group(void *m)
void
lwip_netconn_do_join_leave_group_netif(void *m)
{
struct api_msg *msg = (struct api_msg*)m;
struct api_msg *msg = (struct api_msg *)m;
struct netif *netif;
netif = netif_get_by_index(msg->msg.jl.if_idx);
@ -2021,22 +2020,21 @@ lwip_netconn_do_join_leave_group_netif(void *m)
if (NETCONNTYPE_ISIPV6(msg->conn->type)) {
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
msg->err = mld6_joingroup_netif(netif,
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
} else {
msg->err = mld6_leavegroup_netif(netif,
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
}
}
else
} else
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
{
#if LWIP_IGMP
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
msg->err = igmp_joingroup_netif(netif,
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
} else {
msg->err = igmp_leavegroup_netif(netif,
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
}
#endif /* LWIP_IGMP */
}
@ -2062,7 +2060,7 @@ done:
static void
lwip_netconn_do_dns_found(const char *name, const ip_addr_t *ipaddr, void *arg)
{
struct dns_api_msg *msg = (struct dns_api_msg*)arg;
struct dns_api_msg *msg = (struct dns_api_msg *)arg;
/* we trust the internal implementation to be correct :-) */
LWIP_UNUSED_ARG(name);
@ -2088,7 +2086,7 @@ lwip_netconn_do_dns_found(const char *name, const ip_addr_t *ipaddr, void *arg)
void
lwip_netconn_do_gethostbyname(void *arg)
{
struct dns_api_msg *msg = (struct dns_api_msg*)arg;
struct dns_api_msg *msg = (struct dns_api_msg *)arg;
u8_t addrtype =
#if LWIP_IPV4 && LWIP_IPV6
msg->dns_addrtype;
@ -2097,7 +2095,7 @@ lwip_netconn_do_gethostbyname(void *arg)
#endif
API_EXPR_DEREF(msg->err) = dns_gethostbyname_addrtype(msg->name,
API_EXPR_REF(msg->addr), lwip_netconn_do_dns_found, msg, addrtype);
API_EXPR_REF(msg->addr), lwip_netconn_do_dns_found, msg, addrtype);
#if LWIP_TCPIP_CORE_LOCKING
/* For core locking, only block if we need to wait for answer/timeout */
if (API_EXPR_DEREF(msg->err) == ERR_INPROGRESS) {