Skip to content

Commit d4b6469

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 e2d6af1 commit d4b6469

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
#include <zephyr/net/socket_service.h>
1414
#include <zephyr/net/net_if.h>
1515
#include <zephyr/net/net_ip.h>
16+
#include <zephyr/net/wifi_mgmt.h>
1617
#include "sockets_internal.h"
18+
#include <platform-zephyr.h>
1719

1820
#define MAX_SERVICES 1
1921

2022
static struct zsock_pollfd sockfd_udp[MAX_SERVICES];
2123
static int trel_sock = -1;
2224
static struct otInstance *ot_instance_ptr;
25+
static struct net_if *ail_iface_ptr;
2326
static otPlatTrelCounters trel_counters;
2427
static bool trel_is_enabled;
2528
static void trel_receive_handler(struct net_socket_service_event *evt);
@@ -34,6 +37,7 @@ void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort)
3437
.sin6_addr = IN6ADDR_ANY_INIT,
3538
.sin6_scope_id = 0};
3639
socklen_t len = sizeof(addr);
40+
struct wifi_iface_status status = {0};
3741

3842
trel_sock = zsock_socket(AF_INET6, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
3943
VerifyOrExit(trel_sock >= 0);
@@ -47,6 +51,16 @@ void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort)
4751

4852
trel_is_enabled = true;
4953

54+
if (ail_iface_ptr != NULL) {
55+
if (!net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, ail_iface_ptr,
56+
&status, sizeof(status))) {
57+
if (status.state == WIFI_STATE_COMPLETED) {
58+
(void)trel_plat_init(ot_instance_ptr, ail_iface_ptr);
59+
}
60+
}
61+
}
62+
63+
5064
exit:
5165
return;
5266

@@ -141,13 +155,14 @@ static void process_trel_message(struct otbr_msg_ctx *msg_ctx_ptr)
141155
&msg_ctx_ptr->sock_addr);
142156
}
143157

144-
otError trel_plat_init(otInstance *instance, struct net_if *ail_iface_ptr)
158+
otError trel_plat_init(otInstance *instance, struct net_if *ail_iface)
145159
{
146160
otError error = OT_ERROR_NONE;
147161
struct ifreq if_req = {0};
148162
char name[CONFIG_NET_INTERFACE_NAME_LEN + 1] = {0};
149163

150164
ot_instance_ptr = instance;
165+
ail_iface_ptr = ail_iface;
151166

152167
VerifyOrExit(net_if_get_name(ail_iface_ptr, name,
153168
CONFIG_NET_INTERFACE_NAME_LEN) > 0,

0 commit comments

Comments
 (0)