diff --git a/net/yaip/tcp.c b/net/yaip/tcp.c index 0c0a7daa590590..9e1ad2666f4ab2 100644 --- a/net/yaip/tcp.c +++ b/net/yaip/tcp.c @@ -792,3 +792,24 @@ void net_tcp_change_state(struct net_tcp *tcp, tcp->context->user_data); } } + +void net_tcp_foreach(net_tcp_cb_t cb, void *user_data) +{ + int i, key; + + key = irq_lock(); + + for (i = 0; i < NET_MAX_TCP_CONTEXT; i++) { + if (!net_tcp_is_used(&tcp_context[i])) { + continue; + } + + irq_unlock(key); + + cb(&tcp_context[i], user_data); + + key = irq_lock(); + } + + irq_unlock(key); +} diff --git a/net/yaip/tcp.h b/net/yaip/tcp.h index 5793f6b5a3117f..a1fae16e8a8e84 100644 --- a/net/yaip/tcp.h +++ b/net/yaip/tcp.h @@ -280,6 +280,17 @@ int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote, int net_tcp_prepare_reset(struct net_tcp *tcp, const struct sockaddr *remote, struct net_buf **buf); +typedef void (*net_tcp_cb_t)(struct net_tcp *tcp, void *user_data); + +/** + * @brief Go through all the TCP connections and call callback + * for each of them. + * + * @param cb User supplied callback function to call. + * @param user_data User specified data. + */ +void net_tcp_foreach(net_tcp_cb_t cb, void *user_data); + #if defined(CONFIG_NET_TCP) void net_tcp_init(void); #else