diff --git a/subsys/net/l2/openthread/openthread_utils.c b/subsys/net/l2/openthread/openthread_utils.c index 7a4df04af37c08..6d871a2576f120 100644 --- a/subsys/net/l2/openthread/openthread_utils.c +++ b/subsys/net/l2/openthread/openthread_utils.c @@ -12,6 +12,7 @@ LOG_MODULE_DECLARE(net_l2_openthread, CONFIG_OPENTHREAD_L2_LOG_LEVEL); #include #include +#include #include "openthread_utils.h" @@ -25,6 +26,15 @@ static bool is_anycast_locator(const otNetifAddress *address) address->mAddress.mFields.m8[14] == ALOC16_MASK; } +static bool is_mesh_local(struct openthread_context *context, + const u8_t *address) +{ + const otMeshLocalPrefix *ml_prefix = + otThreadGetMeshLocalPrefix(context->instance); + + return (memcmp(address, ml_prefix->m8, sizeof(ml_prefix)) == 0); +} + int pkt_list_add(struct openthread_context *context, struct net_pkt *pkt) { u16_t i_idx = context->pkt_list_in_idx; @@ -77,6 +87,7 @@ void pkt_list_remove_last(struct openthread_context *context) void add_ipv6_addr_to_zephyr(struct openthread_context *context) { const otNetifAddress *address; + struct net_if_addr *if_addr; for (address = otIp6GetUnicastAddresses(context->instance); address; address = address->mNext) { @@ -94,9 +105,18 @@ void add_ipv6_addr_to_zephyr(struct openthread_context *context) buf, sizeof(buf)))); } - net_if_ipv6_addr_add(context->iface, - (struct in6_addr *)(&address->mAddress), - NET_ADDR_ANY, 0); + if_addr = net_if_ipv6_addr_add( + context->iface, + (struct in6_addr *)(&address->mAddress), + NET_ADDR_AUTOCONF, 0); + + if (if_addr == NULL) { + NET_ERR("Cannot add OpenThread unicast address"); + continue; + } + + if_addr->is_mesh_local = is_mesh_local( + context, address->mAddress.mFields.m8); } } @@ -124,6 +144,9 @@ void add_ipv6_addr_to_ot(struct openthread_context *context) } } + ipv6->unicast[i].is_mesh_local = is_mesh_local( + context, ipv6->unicast[i].address.in6_addr.s6_addr); + addr.mValid = true; addr.mPreferred = true; addr.mPrefixLength = 64;