mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-03 03:01:05 +03:00
LwIP: Support disabling LwIP's IPv6 support
This commit is contained in:
1 parent
c4cfe9380c
commit
f4666c2ea9
11 files changed
+77
-16
No files matched your search
@@ -455,13 +455,17 @@ coap_resolve_address_info(const coap_str_const_t *server,
|
||||
sock4 = (struct sockaddr_in *)ainfo->ai_addr;
|
||||
info->addr.port = ntohs(sock4->sin_port);
|
||||
memcpy(&info->addr.addr, &sock4->sin_addr, 4);
|
||||
#if LWIP_IPV6
|
||||
info->addr.addr.type = IPADDR_TYPE_V4;
|
||||
#endif /* LWIP_IPV6 */
|
||||
break;
|
||||
case AF_INET6:
|
||||
sock6 = (struct sockaddr_in6 *)ainfo->ai_addr;
|
||||
info->addr.port = ntohs(sock6->sin6_port);
|
||||
memcpy(&info->addr.addr, &sock6->sin6_addr, 16);
|
||||
#if LWIP_IPV6
|
||||
info->addr.addr.type = IPADDR_TYPE_V6;
|
||||
#endif /* LWIP_IPV6 */
|
||||
break;
|
||||
default:
|
||||
;
|
||||
|
||||
+2
-2
@@ -37,14 +37,14 @@ asn1_len(const uint8_t **ptr)
|
||||
}
|
||||
|
||||
coap_asn1_tag_t
|
||||
asn1_tag_c(const uint8_t **ptr, int *constructed, int *class)
|
||||
asn1_tag_c(const uint8_t **ptr, int *constructed, int *cls)
|
||||
{
|
||||
coap_asn1_tag_t tag = 0;
|
||||
uint8_t byte;
|
||||
|
||||
byte = (**ptr);
|
||||
*constructed = (byte & 0x20) ? 1 : 0;
|
||||
*class = byte >> 6;
|
||||
*cls = byte >> 6;
|
||||
tag = byte & 0x1F;
|
||||
(*ptr)++;
|
||||
if (tag < 0x1F)
|
||||
|
||||
+7
-3
@@ -303,13 +303,14 @@ coap_print_addr(const coap_address_t *addr, unsigned char *buf, size_t len) {
|
||||
assert(len);
|
||||
buf[0] = '\000';
|
||||
|
||||
switch (addr->addr.type) {
|
||||
switch (IP_GET_TYPE(addr->addr)) {
|
||||
case IPADDR_TYPE_V4:
|
||||
if (len < IP4ADDR_STRLEN_MAX + 6)
|
||||
return 0;
|
||||
memcpy(buf, coap_print_ip_addr(addr, scratch, sizeof(scratch)), IP4ADDR_STRLEN_MAX);
|
||||
p += strlen((char *)buf);
|
||||
break;
|
||||
#if LWIP_IPV6
|
||||
case IPADDR_TYPE_V6:
|
||||
case IPADDR_TYPE_ANY:
|
||||
if (len < 40 + 2 + 6)
|
||||
@@ -319,6 +320,7 @@ coap_print_addr(const coap_address_t *addr, unsigned char *buf, size_t len) {
|
||||
p += strlen((char *)buf);
|
||||
*p++ = ']';
|
||||
break;
|
||||
#endif /* LWIP_IPV6 */
|
||||
}
|
||||
|
||||
*p++ = ':';
|
||||
@@ -426,18 +428,20 @@ coap_print_ip_addr(const coap_address_t *addr, char *buf, size_t len) {
|
||||
assert(len);
|
||||
buf[0] = '\000';
|
||||
|
||||
switch (addr->addr.type) {
|
||||
switch (IP_GET_TYPE(&addr->addr)) {
|
||||
case IPADDR_TYPE_V4:
|
||||
if (len < IP4ADDR_STRLEN_MAX)
|
||||
return buf;
|
||||
memcpy(buf, ip4addr_ntoa(&addr->addr.u_addr.ip4), IP4ADDR_STRLEN_MAX);
|
||||
memcpy(buf, ip4addr_ntoa(ip_2_ip4(&addr->addr)), IP4ADDR_STRLEN_MAX);
|
||||
break;
|
||||
#if LWIP_IPV6
|
||||
case IPADDR_TYPE_V6:
|
||||
case IPADDR_TYPE_ANY:
|
||||
if (len < 40)
|
||||
return buf;
|
||||
memcpy(buf, ip6addr_ntoa(&addr->addr.u_addr.ip6), 40);
|
||||
break;
|
||||
#endif /* LWIP_IPV6 */
|
||||
}
|
||||
return buf;
|
||||
|
||||
|
||||
+42
-4
@@ -17,6 +17,7 @@
|
||||
#include "coap3/coap_internal.h"
|
||||
#include <lwip/udp.h>
|
||||
#include <lwip/timeouts.h>
|
||||
#include <lwip/tcpip.h>
|
||||
|
||||
void
|
||||
coap_lwip_dump_memory_pools(coap_log_t log_level) {
|
||||
@@ -88,6 +89,9 @@ coap_io_process(coap_context_t *context, uint32_t timeout_ms) {
|
||||
timeout > timeout_ms) {
|
||||
timeout = timeout_ms;
|
||||
}
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
|
||||
if (context->timer_configured) {
|
||||
sys_untimeout(coap_io_process_timeout, (void*)context);
|
||||
context->timer_configured = 0;
|
||||
@@ -102,10 +106,19 @@ coap_io_process(coap_context_t *context, uint32_t timeout_ms) {
|
||||
#endif /* COAP_DEBUG_WAKEUP_TIMES */
|
||||
sys_timeout(timeout, coap_io_process_timeout, context);
|
||||
context->timer_configured = 1;
|
||||
|
||||
UNLOCK_TCPIP_CORE();
|
||||
|
||||
if (context->input_wait) {
|
||||
context->input_wait(context->input_arg, timeout);
|
||||
}
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
|
||||
sys_check_timeouts();
|
||||
|
||||
UNLOCK_TCPIP_CORE();
|
||||
|
||||
coap_ticks(&now);
|
||||
return (int)(((now - before) * 1000) / COAP_TICKS_PER_SECOND);
|
||||
}
|
||||
@@ -316,9 +329,14 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session,
|
||||
if (pbuf == NULL)
|
||||
return -1;
|
||||
memcpy(pbuf->payload, data, data_len);
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
|
||||
err = udp_sendto(sock->pcb, pbuf, &session->addr_info.remote.addr,
|
||||
session->addr_info.remote.port);
|
||||
|
||||
UNLOCK_TCPIP_CORE();
|
||||
|
||||
pbuf_free(pbuf);
|
||||
if (err < 0)
|
||||
return -1;
|
||||
@@ -338,8 +356,10 @@ coap_socket_bind_udp(coap_socket_t *sock,
|
||||
if (sock->pcb == NULL)
|
||||
return 0;
|
||||
|
||||
#if LWIP_IPV6
|
||||
if (l_listen.addr.type == IPADDR_TYPE_V6)
|
||||
l_listen.addr.type = IPADDR_TYPE_ANY;
|
||||
#endif /* LWIP_IPV6 */
|
||||
udp_recv(sock->pcb, coap_recvs, (void*)sock->endpoint);
|
||||
err = udp_bind(sock->pcb, &l_listen.addr, l_listen.port);
|
||||
if (err) {
|
||||
@@ -366,31 +386,47 @@ coap_socket_connect_udp(coap_socket_t *sock,
|
||||
(void)default_port;
|
||||
(void)local_addr;
|
||||
(void)remote_addr;
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
|
||||
pcb = udp_new();
|
||||
|
||||
if (!pcb) {
|
||||
return 0;
|
||||
goto err_unlock;
|
||||
}
|
||||
|
||||
err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
|
||||
if (err) {
|
||||
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
|
||||
("coap_socket_connect_udp: port bind failed\n"));
|
||||
return 0;
|
||||
goto err_udp_remove;
|
||||
}
|
||||
|
||||
sock->session->addr_info.local.port = pcb->local_port;
|
||||
|
||||
err = udp_connect(pcb, &server->addr, server->port);
|
||||
if (err) {
|
||||
return 0;
|
||||
goto err_udp_unbind;
|
||||
}
|
||||
|
||||
#if LWIP_IPV6
|
||||
pcb->local_ip.type = pcb->remote_ip.type;
|
||||
#endif /* LWIP_IPV6 */
|
||||
|
||||
sock->pcb = pcb;
|
||||
|
||||
udp_recv(sock->pcb, coap_recvc, (void*)sock->session);
|
||||
|
||||
UNLOCK_TCPIP_CORE();
|
||||
|
||||
return 1;
|
||||
|
||||
err_udp_unbind:
|
||||
err_udp_remove:
|
||||
udp_remove(pcb);
|
||||
err_unlock:
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return 0;
|
||||
}
|
||||
#endif /* ! COAP_CLIENT_SUPPORT */
|
||||
|
||||
@@ -461,8 +497,10 @@ coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len) {
|
||||
}
|
||||
|
||||
void coap_socket_close(coap_socket_t *sock) {
|
||||
if (sock->pcb){
|
||||
if (sock->pcb) {
|
||||
LOCK_TCPIP_CORE();
|
||||
udp_remove(sock->pcb);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
}
|
||||
sock->pcb = NULL;
|
||||
return;
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include <lwip/pbuf.h>
|
||||
#include <lwip/udp.h>
|
||||
#include <lwip/timeouts.h>
|
||||
#include <lwip/tcpip.h>
|
||||
#endif
|
||||
|
||||
#ifndef INET6_ADDRSTRLEN
|
||||
@@ -569,7 +570,9 @@ coap_free_context(coap_context_t *context) {
|
||||
#ifdef WITH_LWIP
|
||||
context->sendqueue = NULL;
|
||||
if (context->timer_configured) {
|
||||
LOCK_TCPIP_CORE();
|
||||
sys_untimeout(coap_io_process_timeout, (void*)context);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
context->timer_configured = 0;
|
||||
}
|
||||
#endif /* WITH_LWIP */
|
||||
|
||||
Reference in new issue
Block a user