mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/tinydtls: add IPv4 support
This commit is contained in:
parent
e623133dab
commit
d424aaedac
@ -128,11 +128,11 @@ static int dtls_handle_read(dtls_context_t *ctx)
|
||||
session.ifindex = remote.netif;
|
||||
}
|
||||
|
||||
memcpy(&session.addr.addr, &remote.addr.ipv6, sizeof(session.addr.addr));
|
||||
memcpy(&session.addr.ipv6, &remote.addr.ipv6, sizeof(session.addr.ipv6));
|
||||
|
||||
if (IS_ACTIVE(ENABLE_DEBUG)) {
|
||||
DEBUG("DBG-Client: Msg received from \n\t Addr Src: [");
|
||||
ipv6_addr_print(&session.addr.addr);
|
||||
ipv6_addr_print(&session.addr.ipv6);
|
||||
DEBUG("]:%u\n", remote.port);
|
||||
}
|
||||
|
||||
@ -361,8 +361,8 @@ dtls_context_t *_init_dtls(sock_udp_t *sock, sock_udp_ep_t *local,
|
||||
/* Second: We prepare the DTLS Session by means of ctx->app */
|
||||
dst->addr.port = remote->port;
|
||||
|
||||
/* NOTE: remote.addr.ipv6 and dst->addr.addr are different structures. */
|
||||
if (ipv6_addr_from_str(&dst->addr.addr, addr_str) == NULL) {
|
||||
/* NOTE: remote.addr.ipv6 and dst->addr.ipv6 are different structures. */
|
||||
if (ipv6_addr_from_str(&dst->addr.ipv6, addr_str) == NULL) {
|
||||
puts("ERROR: init_dtls was unable to load the IPv6 addresses!");
|
||||
return new_context;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ static int dtls_handle_read(dtls_context_t *ctx)
|
||||
session.ifindex = remote_peer->remote->netif;
|
||||
}
|
||||
|
||||
memcpy(&session.addr.addr, &remote_peer->remote->addr.ipv6, sizeof(session.addr.addr));
|
||||
memcpy(&session.addr.ipv6, &remote_peer->remote->addr.ipv6, sizeof(session.addr.ipv6));
|
||||
return dtls_handle_message(ctx, &session, packet_rcvd, res);
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,6 @@ static int _write(struct dtls_context_t *ctx, session_t *session, uint8_t *buf,
|
||||
sock_udp_ep_t remote;
|
||||
|
||||
_session_to_ep(session, &remote);
|
||||
remote.family = AF_INET6;
|
||||
|
||||
ssize_t res = sock_udp_send(sock->udp_sock, buf, len, &remote);
|
||||
|
||||
@ -529,15 +528,20 @@ int sock_dtls_session_init(sock_dtls_t *sock, const sock_udp_ep_t *ep,
|
||||
if (!sock->udp_sock || (sock_udp_get_local(sock->udp_sock, &local) < 0)) {
|
||||
return -EADDRNOTAVAIL;
|
||||
}
|
||||
|
||||
if (ep->port == 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
switch (ep->family) {
|
||||
#ifdef SOCK_HAS_IPV4
|
||||
case AF_INET:
|
||||
#if IS_ACTIVE(SOCK_HAS_IPV6)
|
||||
case AF_INET6:
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#ifdef SOCK_HAS_IPV6
|
||||
case AF_INET6:
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -812,24 +816,55 @@ void sock_dtls_init(void)
|
||||
static void _ep_to_session(const sock_udp_ep_t *ep, session_t *session)
|
||||
{
|
||||
dtls_session_init(session);
|
||||
session->addr.family = ep->family;
|
||||
session->addr.port = ep->port;
|
||||
|
||||
if (ipv6_addr_is_link_local((ipv6_addr_t *)ep->addr.ipv6)) {
|
||||
/* set ifindex for link-local addresses */
|
||||
session->ifindex = ep->netif;
|
||||
}
|
||||
else {
|
||||
switch (ep->family) {
|
||||
#ifdef SOCK_HAS_IPV4
|
||||
case AF_INET:
|
||||
session->ifindex = SOCK_ADDR_ANY_NETIF;
|
||||
memcpy(&session->addr.ipv4, &ep->addr.ipv4, sizeof(session->addr.ipv4));
|
||||
break;
|
||||
#endif
|
||||
#ifdef SOCK_HAS_IPV6
|
||||
case AF_INET6:
|
||||
if (ipv6_addr_is_link_local((ipv6_addr_t *)ep->addr.ipv6)) {
|
||||
/* set ifindex for link-local addresses */
|
||||
session->ifindex = ep->netif;
|
||||
}
|
||||
else {
|
||||
session->ifindex = SOCK_ADDR_ANY_NETIF;
|
||||
}
|
||||
memcpy(&session->addr.ipv6, &ep->addr.ipv6, sizeof(session->addr.ipv6));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
memcpy(&session->addr.addr, &ep->addr.ipv6, sizeof(session->addr.addr));
|
||||
}
|
||||
|
||||
static void _session_to_ep(const session_t *session, sock_udp_ep_t *ep)
|
||||
{
|
||||
ep->port = session->addr.port;
|
||||
ep->netif = session->ifindex;
|
||||
ep->family = AF_INET6;
|
||||
memcpy(&ep->addr.ipv6, &session->addr.addr, sizeof(ep->addr.ipv6));
|
||||
ep->family = session->addr.family;
|
||||
|
||||
switch (session->addr.family) {
|
||||
#ifdef SOCK_HAS_IPV4
|
||||
case AF_INET:
|
||||
memcpy(&ep->addr.ipv4, &session->addr.ipv4, sizeof(ep->addr.ipv4));
|
||||
break;
|
||||
#endif
|
||||
#ifdef SOCK_HAS_IPV6
|
||||
case AF_INET6:
|
||||
memcpy(&ep->addr.ipv6, &session->addr.ipv6, sizeof(ep->addr.ipv6));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
/* addr_family is actually ok to be 0 when coming from _copy_buffer */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t _update_timeout(uint32_t start, uint32_t timeout)
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user