Lines Matching +full:address +full:- +full:0

4  * SPDX-License-Identifier: Apache-2.0
19 #define ALOC16_MASK 0xfc
21 static bool is_anycast_locator(const otNetifAddress *address) in is_anycast_locator() argument
23 return address->mAddress.mFields.m16[4] == htons(0x0000) && in is_anycast_locator()
24 address->mAddress.mFields.m16[5] == htons(0x00ff) && in is_anycast_locator()
25 address->mAddress.mFields.m16[6] == htons(0xfe00) && in is_anycast_locator()
26 address->mAddress.mFields.m8[14] == ALOC16_MASK; in is_anycast_locator()
30 const uint8_t *address) in is_mesh_local() argument
33 otThreadGetMeshLocalPrefix(context->instance); in is_mesh_local()
35 return (memcmp(address, ml_prefix->m8, sizeof(ml_prefix->m8)) == 0); in is_mesh_local()
40 uint16_t i_idx = context->pkt_list_in_idx; in pkt_list_add()
42 if (context->pkt_list_full) { in pkt_list_add()
43 return -ENOMEM; in pkt_list_add()
48 i_idx = 0U; in pkt_list_add()
51 if (i_idx == context->pkt_list_out_idx) { in pkt_list_add()
52 context->pkt_list_full = 1U; in pkt_list_add()
55 context->pkt_list[context->pkt_list_in_idx].pkt = pkt; in pkt_list_add()
56 context->pkt_list_in_idx = i_idx; in pkt_list_add()
58 return 0; in pkt_list_add()
63 uint16_t idx = context->pkt_list_in_idx; in pkt_list_remove_first()
65 if (idx == 0U) { in pkt_list_remove_first()
66 idx = CONFIG_OPENTHREAD_PKT_LIST_SIZE - 1; in pkt_list_remove_first()
68 idx--; in pkt_list_remove_first()
70 context->pkt_list_in_idx = idx; in pkt_list_remove_first()
72 if (context->pkt_list_full) { in pkt_list_remove_first()
73 context->pkt_list_full = 0U; in pkt_list_remove_first()
79 if ((context->pkt_list_in_idx == context->pkt_list_out_idx) && in pkt_list_peek()
80 (!context->pkt_list_full)) { in pkt_list_peek()
84 return context->pkt_list[context->pkt_list_out_idx].pkt; in pkt_list_peek()
89 if ((context->pkt_list_in_idx == context->pkt_list_out_idx) && in pkt_list_remove_last()
90 (!context->pkt_list_full)) { in pkt_list_remove_last()
95 context->pkt_list_out_idx++; in pkt_list_remove_last()
96 if (context->pkt_list_out_idx == CONFIG_OPENTHREAD_PKT_LIST_SIZE) { in pkt_list_remove_last()
97 context->pkt_list_out_idx = 0U; in pkt_list_remove_last()
100 context->pkt_list_full = 0U; in pkt_list_remove_last()
105 const otNetifAddress *address; in add_ipv6_addr_to_zephyr() local
108 for (address = otIp6GetUnicastAddresses(context->instance); in add_ipv6_addr_to_zephyr()
109 address; address = address->mNext) { in add_ipv6_addr_to_zephyr()
111 if (address->mRloc || is_anycast_locator(address)) { in add_ipv6_addr_to_zephyr()
120 (struct in6_addr *)(&address->mAddress), in add_ipv6_addr_to_zephyr()
127 if ((address->mAddressOrigin == OT_ADDRESS_ORIGIN_THREAD) || in add_ipv6_addr_to_zephyr()
128 (address->mAddressOrigin == OT_ADDRESS_ORIGIN_SLAAC)) { in add_ipv6_addr_to_zephyr()
130 context->iface, in add_ipv6_addr_to_zephyr()
131 (struct in6_addr *)(&address->mAddress), in add_ipv6_addr_to_zephyr()
132 NET_ADDR_AUTOCONF, 0); in add_ipv6_addr_to_zephyr()
133 } else if (address->mAddressOrigin == in add_ipv6_addr_to_zephyr()
136 context->iface, in add_ipv6_addr_to_zephyr()
137 (struct in6_addr *)(&address->mAddress), in add_ipv6_addr_to_zephyr()
138 NET_ADDR_DHCP, 0); in add_ipv6_addr_to_zephyr()
139 } else if (address->mAddressOrigin == in add_ipv6_addr_to_zephyr()
142 context->iface, in add_ipv6_addr_to_zephyr()
143 (struct in6_addr *)(&address->mAddress), in add_ipv6_addr_to_zephyr()
144 NET_ADDR_MANUAL, 0); in add_ipv6_addr_to_zephyr()
146 NET_ERR("Unknown OpenThread address origin ignored."); in add_ipv6_addr_to_zephyr()
151 NET_ERR("Cannot add OpenThread unicast address"); in add_ipv6_addr_to_zephyr()
155 if_addr->is_mesh_local = is_mesh_local( in add_ipv6_addr_to_zephyr()
156 context, address->mAddress.mFields.m8); in add_ipv6_addr_to_zephyr()
158 /* Mark address as deprecated if it is not preferred. */ in add_ipv6_addr_to_zephyr()
159 if_addr->addr_state = in add_ipv6_addr_to_zephyr()
160 address->mPreferred ? NET_ADDR_PREFERRED : NET_ADDR_DEPRECATED; in add_ipv6_addr_to_zephyr()
167 struct otNetifAddress addr = { 0 }; in add_ipv6_addr_to_ot()
173 * address added event. in add_ipv6_addr_to_ot()
175 ipv6 = context->iface->config.ip.ipv6; in add_ipv6_addr_to_ot()
181 /* Find the net_if_addr structure containing the newly added address. */ in add_ipv6_addr_to_ot()
182 for (i = NET_IF_MAX_IPV6_ADDR - 1; i >= 0; i--) { in add_ipv6_addr_to_ot()
183 if (ipv6->unicast[i].is_used && in add_ipv6_addr_to_ot()
184 net_ipv6_addr_cmp(&ipv6->unicast[i].address.in6_addr, in add_ipv6_addr_to_ot()
186 if_addr = &ipv6->unicast[i]; in add_ipv6_addr_to_ot()
198 if_addr->is_mesh_local = is_mesh_local( in add_ipv6_addr_to_ot()
199 context, ipv6->unicast[i].address.in6_addr.s6_addr); in add_ipv6_addr_to_ot()
202 addr.mPreferred = (if_addr->addr_state == NET_ADDR_PREFERRED); in add_ipv6_addr_to_ot()
205 if (if_addr->addr_type == NET_ADDR_AUTOCONF) { in add_ipv6_addr_to_ot()
207 } else if (if_addr->addr_type == NET_ADDR_DHCP) { in add_ipv6_addr_to_ot()
209 } else if (if_addr->addr_type == NET_ADDR_MANUAL) { in add_ipv6_addr_to_ot()
212 NET_ERR("Unknown address type"); in add_ipv6_addr_to_ot()
217 otIp6AddUnicastAddress(context->instance, &addr); in add_ipv6_addr_to_ot()
236 otIp6SubscribeMulticastAddress(context->instance, &addr); in add_ipv6_maddr_to_ot()
252 for (maddress = otIp6GetMulticastAddresses(context->instance); in add_ipv6_maddr_to_zephyr()
253 maddress; maddress = maddress->mNext) { in add_ipv6_maddr_to_zephyr()
255 (struct in6_addr *)(&maddress->mAddress), in add_ipv6_maddr_to_zephyr()
256 &context->iface) != NULL) { in add_ipv6_maddr_to_zephyr()
266 (&maddress->mAddress), in add_ipv6_maddr_to_zephyr()
270 zmaddr = net_if_ipv6_maddr_add(context->iface, in add_ipv6_maddr_to_zephyr()
271 (struct in6_addr *)(&maddress->mAddress)); in add_ipv6_maddr_to_zephyr()
276 (struct in6_addr *)(&maddress->mAddress)) || in add_ipv6_maddr_to_zephyr()
278 (struct in6_addr *)(&maddress->mAddress)))) { in add_ipv6_maddr_to_zephyr()
280 net_if_ipv6_maddr_join(context->iface, zmaddr); in add_ipv6_maddr_to_zephyr()
292 if (net_if_config_ipv6_get(context->iface, &ipv6) < 0) { in rm_ipv6_addr_from_zephyr()
293 NET_DBG("Cannot find IPv6 address"); in rm_ipv6_addr_from_zephyr()
297 for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) { in rm_ipv6_addr_from_zephyr()
298 const otNetifAddress *address; in rm_ipv6_addr_from_zephyr() local
301 zephyr_addr = &ipv6->unicast[i]; in rm_ipv6_addr_from_zephyr()
302 if (!zephyr_addr->is_used) { in rm_ipv6_addr_from_zephyr()
306 for (address = otIp6GetUnicastAddresses(context->instance); in rm_ipv6_addr_from_zephyr()
307 address; address = address->mNext) { in rm_ipv6_addr_from_zephyr()
309 ot_addr = (struct in6_addr *)(&address->mAddress); in rm_ipv6_addr_from_zephyr()
311 &zephyr_addr->address.in6_addr)) { in rm_ipv6_addr_from_zephyr()
323 &zephyr_addr->address.in6_addr, in rm_ipv6_addr_from_zephyr()
327 net_if_ipv6_addr_rm(context->iface, in rm_ipv6_addr_from_zephyr()
328 &zephyr_addr->address.in6_addr); in rm_ipv6_addr_from_zephyr()
340 if (net_if_config_ipv6_get(context->iface, &ipv6) < 0) { in rm_ipv6_maddr_from_zephyr()
341 NET_DBG("Cannot find IPv6 address"); in rm_ipv6_maddr_from_zephyr()
345 for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) { in rm_ipv6_maddr_from_zephyr()
349 zephyr_addr = &ipv6->mcast[i]; in rm_ipv6_maddr_from_zephyr()
350 if (!zephyr_addr->is_used) { in rm_ipv6_maddr_from_zephyr()
354 for (maddress = otIp6GetMulticastAddresses(context->instance); in rm_ipv6_maddr_from_zephyr()
355 maddress; maddress = maddress->mNext) { in rm_ipv6_maddr_from_zephyr()
357 ot_addr = (struct in6_addr *)(&maddress->mAddress); in rm_ipv6_maddr_from_zephyr()
359 &zephyr_addr->address.in6_addr)) { in rm_ipv6_maddr_from_zephyr()
371 &zephyr_addr->address.in6_addr, in rm_ipv6_maddr_from_zephyr()
375 net_if_ipv6_maddr_rm(context->iface, in rm_ipv6_maddr_from_zephyr()
376 &zephyr_addr->address.in6_addr); in rm_ipv6_maddr_from_zephyr()