Skip to content

Commit

Permalink
net: openthread: rpc: network interface changes
Browse files Browse the repository at this point in the history
1. Enable implementation of RPC commands for sending and
   receiving IPv6 packets only if OPENTHREAD_RPC_NET_IF
   Kconfig option is set. This is to enable using OT RPC
   without the Zephyr networking stack.
2. Autostart OpenThread network interface on the RPC server
   even if the network interface is not present or enabled
   on the RPC client side. This is because when the
   interface is disabled on the server side, the received
   frames are not even delivered to the OpenThread stack.
3. Other minor cleanup.

Signed-off-by: Damian Krolik <[email protected]>
  • Loading branch information
Damian-Nordic authored and rlubos committed Oct 17, 2024
1 parent e318da5 commit 32bd0b9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_PACKET=y
CONFIG_OPENTHREAD_RPC=y
CONFIG_OPENTHREAD_RPC_SERVER=y
CONFIG_IEEE802154_NET_IF_NO_AUTO_START=y # Let RPC client start the interface on demand
CONFIG_OPENTHREAD_MANUAL_START=y
CONFIG_NET_BUF_RX_COUNT=80
CONFIG_NET_BUF_TX_COUNT=80
10 changes: 9 additions & 1 deletion subsys/net/openthread/rpc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ choice OPENTHREAD_RPC_ROLE_CHOICE

config OPENTHREAD_RPC_CLIENT
bool "OpenThread over RPC client"
depends on NETWORKING
help
Enables OpenThread over RPC client role that uses nRF RPC library to
invoke OpenThread functions on the remote core.
Expand All @@ -39,6 +38,15 @@ config OPENTHREAD_RPC_SERVER

endchoice

config OPENTHREAD_RPC_NET_IF
bool "OpenThread over RPC network interface"
default y
depends on NETWORKING
help
Enables OpenThread RPC commands for sending and receiving IPv6 packets
to/from the OpenThread stack. For the RPC client role, it additionally
creates a Zephyr network interface that employs these commands.

menu "OpenThread over RPC client configuration"
depends on OPENTHREAD_RPC_CLIENT

Expand Down
3 changes: 2 additions & 1 deletion subsys/net/openthread/rpc/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ zephyr_library_sources(
ot_rpc_coap.c
ot_rpc_diag.c
ot_rpc_dataset.c
ot_rpc_if.c
ot_rpc_instance.c
ot_rpc_ip6.c
ot_rpc_link.c
Expand All @@ -22,6 +21,8 @@ zephyr_library_sources(
ot_rpc_udp.c
)

zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_RPC_NET_IF ot_rpc_if.c)

zephyr_library_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../common
)
Expand Down
10 changes: 3 additions & 7 deletions subsys/net/openthread/rpc/client/ot_rpc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,23 @@ static int ot_rpc_l2_enable(struct net_if *iface, bool state)
{
const size_t cbor_buffer_size = 1;
struct nrf_rpc_cbor_ctx ctx;
int error = 0;

const otExtAddress *mac = otLinkGetExtendedAddress(0);

if (!state) {
otRemoveStateChangeCallback(NULL, ot_state_changed_handler, iface);
}

net_if_set_link_addr(iface, (uint8_t *)mac->m8, 8, NET_LINK_IEEE802154);

NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
zcbor_bool_put(ctx.zs, state);
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_IF_ENABLE, &ctx, ot_rpc_decode_void, NULL);

if (state) {
net_if_set_link_addr(iface, (uint8_t *)otLinkGetExtendedAddress(NULL)->m8,
OT_EXT_ADDRESS_SIZE, NET_LINK_IEEE802154);
update_netif_addrs(iface);
otSetStateChangedCallback(NULL, ot_state_changed_handler, iface);
}

return error;
return 0;
}

static enum net_l2_flags ot_rpc_l2_flags(struct net_if *iface)
Expand All @@ -195,7 +192,6 @@ static int ot_rpc_dev_init(const struct device *dev)

static void ot_rpc_if_init(struct net_if *iface)
{
/* TODO: auto-start the interface when nRF RPC transport is ready? */
net_if_flag_set(iface, NET_IF_NO_AUTO_START);
net_if_flag_set(iface, NET_IF_IPV6_NO_ND);
net_if_flag_set(iface, NET_IF_IPV6_NO_MLD);
Expand Down
3 changes: 2 additions & 1 deletion subsys/net/openthread/rpc/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ zephyr_library_sources(
)

zephyr_library_sources_ifdef(CONFIG_NET_L2_OPENTHREAD
ot_rpc_if.c
ot_rpc_diag.c
ot_rpc_udp.c
)

zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_RPC_NET_IF ot_rpc_if.c)

zephyr_library_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../common
)

0 comments on commit 32bd0b9

Please sign in to comment.