Skip to content

Commit 5f62980

Browse files
committed
openthread: platform: trel: Handle enable/disable from CLI
OpenThread interface is initialized beform Wi-Fi interface. `otPlatTrelEnable` is called by OpenThread stack when it's interface is being initialized. Given this scenario, socket operation, like `bind`, will fail. There is also no mean to get a valid pointer to backbone interface. This is why, `trel_plat_init` was declared and called when backbone interface reported connectivity. This commit handles the `ot trel disable/ot trel enable` scenario that can be initialized from CLI. `otPlatTrelEnable` will be called, but `trel_plat_init` will not be called anymore, leaving trel socket without any options set, and `net_socket_service_register` is not called anymore, to handle incoming traffic. Now, when `otPlatTrelEnable` is called, it will verify if Wi-Fi interface is connected and will call `trel_plat_init` if needed. Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
1 parent 5973b55 commit 5f62980

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

modules/openthread/platform/platform-zephyr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ otError mdns_plat_socket_init(otInstance *ot_instance, uint32_t ail_iface_idx);
129129
void mdns_plat_monitor_interface(struct net_if *ail_iface);
130130
otError border_agent_init(otInstance *instance);
131131
void border_agent_deinit(void);
132-
otError trel_plat_init(otInstance *instance, struct net_if *ail_iface_ptr);
132+
otError trel_plat_init(otInstance *instance, struct net_if *ail_iface);
133133
otError dhcpv6_pd_client_init(otInstance *ot_instance, uint32_t ail_iface_index);
134134
otError dns_upstream_resolver_init(otInstance *ot_instance);
135135
#endif /* CONFIG_OPENTHREAD_ZEPHYR_BORDER_ROUTER */

modules/openthread/platform/trel.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#include <zephyr/net/net_if.h>
1515
#include <zephyr/net/net_ip.h>
1616
#include "sockets_internal.h"
17+
#include <platform-zephyr.h>
1718

1819
#define MAX_SERVICES 1
1920

2021
static struct zsock_pollfd sockfd_udp[MAX_SERVICES];
2122
static int trel_sock = -1;
2223
static struct otInstance *ot_instance_ptr;
24+
static struct net_if *ail_iface_ptr;
2325
static otPlatTrelCounters trel_counters;
2426
static bool trel_is_enabled;
2527
static void trel_receive_handler(struct net_socket_service_event *evt);
@@ -47,6 +49,11 @@ void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort)
4749

4850
trel_is_enabled = true;
4951

52+
if (ail_iface_ptr != NULL && net_if_is_up(ail_iface_ptr)) {
53+
(void)trel_plat_init(ot_instance_ptr, ail_iface_ptr);
54+
}
55+
56+
5057
exit:
5158
return;
5259

@@ -141,13 +148,14 @@ static void process_trel_message(struct otbr_msg_ctx *msg_ctx_ptr)
141148
&msg_ctx_ptr->sock_addr);
142149
}
143150

144-
otError trel_plat_init(otInstance *instance, struct net_if *ail_iface_ptr)
151+
otError trel_plat_init(otInstance *instance, struct net_if *ail_iface)
145152
{
146153
otError error = OT_ERROR_NONE;
147154
struct ifreq if_req = {0};
148155
char name[CONFIG_NET_INTERFACE_NAME_LEN + 1] = {0};
149156

150157
ot_instance_ptr = instance;
158+
ail_iface_ptr = ail_iface;
151159

152160
VerifyOrExit(net_if_get_name(ail_iface_ptr, name,
153161
CONFIG_NET_INTERFACE_NAME_LEN) > 0,

0 commit comments

Comments
 (0)