Skip to content

Commit

Permalink
net: shell: add conn_mgr shell commands
Browse files Browse the repository at this point in the history
Adds commands for triggering conn_mgr functions and
tweaking conn_mgr connectivity flags.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
  • Loading branch information
glarsennordic authored and henrikbrixandersen committed Aug 20, 2024
1 parent 4cebe53 commit ebc7a4a
Show file tree
Hide file tree
Showing 4 changed files with 974 additions and 1 deletion.
16 changes: 15 additions & 1 deletion subsys/net/conn_mgr/conn_mgr_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static void conn_mgr_mon_handle_update(void)
*/
static void conn_mgr_mon_initial_state(struct net_if *iface)
{
int idx = net_if_get_by_iface(iface) - 1;
int idx = conn_mgr_get_index_for_if(iface);

k_mutex_lock(&conn_mgr_mon_lock, K_FOREVER);

Expand Down Expand Up @@ -415,4 +415,18 @@ static int conn_mgr_mon_init(void)
return 0;
}

uint16_t conn_mgr_if_state(struct net_if *iface)
{
int idx = conn_mgr_get_index_for_if(iface);
uint16_t state = CONN_MGR_IF_STATE_INVALID;

if (idx < CONN_MGR_IFACE_MAX) {
k_mutex_lock(&conn_mgr_mon_lock, K_FOREVER);
state = iface_states[idx];
k_mutex_unlock(&conn_mgr_mon_lock);
}

return state;
}

SYS_INIT(conn_mgr_mon_init, APPLICATION, CONFIG_NET_CONNECTION_MANAGER_MONITOR_PRIORITY);
6 changes: 6 additions & 0 deletions subsys/net/conn_mgr/conn_mgr_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#define CONN_MGR_IF_READY_IPV4 BIT(14)
#define CONN_MGR_IF_READY_IPV6 BIT(15)

/* Special value indicating invalid state. */
#define CONN_MGR_IF_STATE_INVALID 0xFFFF

/* NET_MGMT event masks */
#define CONN_MGR_IFACE_EVENTS_MASK (NET_EVENT_IF_DOWN | \
NET_EVENT_IF_UP)
Expand Down Expand Up @@ -60,4 +63,7 @@ void conn_mgr_init_events_handler(void);
/* Cause conn_mgr_connectivity to Initialize all connectivity implementation bindings */
void conn_mgr_conn_init(void);

/* Internal helper function to allow the shell net cm command to safely read conn_mgr state. */
uint16_t conn_mgr_if_state(struct net_if *iface);

#endif /* __CONN_MGR_PRV_H__ */
1 change: 1 addition & 0 deletions subsys/net/lib/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ zephyr_library_sources(events.c)
zephyr_library_sources(gptp.c)
zephyr_library_sources(http.c)
zephyr_library_sources(iface.c)
zephyr_library_sources(cm.c)
zephyr_library_sources(ipv4.c)
zephyr_library_sources(ipv6.c)
zephyr_library_sources(mem.c)
Expand Down
Loading

0 comments on commit ebc7a4a

Please sign in to comment.