diff --git a/subsys/net/ip/connection.c b/subsys/net/ip/connection.c index 267521e168..c1521a938f 100644 --- a/subsys/net/ip/connection.c +++ b/subsys/net/ip/connection.c @@ -268,6 +268,16 @@ static struct net_conn *conn_find_handler(struct net_if *iface, return NULL; } +static void net_conn_change_callback(struct net_conn *conn, + net_conn_cb_t cb, void *user_data) +{ + NET_DBG("[%zu] connection handler %p changed callback", + conn - conns, conn); + + conn->cb = cb; + conn->user_data = user_data; +} + int net_conn_register(uint16_t proto, uint8_t family, const struct sockaddr *remote_addr, const struct sockaddr *local_addr, @@ -376,8 +386,8 @@ int net_conn_register(uint16_t proto, uint8_t family, net_sin(&conn->local_addr)->sin_port = htons(local_port); } - conn->cb = cb; - conn->user_data = user_data; + net_conn_change_callback(conn, cb, user_data); + conn->flags = flags; conn->proto = proto; conn->family = family; @@ -422,28 +432,6 @@ int net_conn_unregister(struct net_conn_handle *handle) return 0; } -int net_conn_change_callback(struct net_conn_handle *handle, - net_conn_cb_t cb, void *user_data) -{ - struct net_conn *conn = (struct net_conn *)handle; - - if (conn < &conns[0] || conn > &conns[CONFIG_NET_MAX_CONN]) { - return -EINVAL; - } - - if (!(conn->flags & NET_CONN_IN_USE)) { - return -ENOENT; - } - - NET_DBG("[%zu] connection handler %p changed callback", - conn - conns, conn); - - conn->cb = cb; - conn->user_data = user_data; - - return 0; -} - static bool conn_addr_cmp(struct net_pkt *pkt, union net_ip_header *ip_hdr, struct sockaddr *addr, diff --git a/subsys/net/ip/connection.h b/subsys/net/ip/connection.h index ee7ee0efc7..9fb40acd18 100644 --- a/subsys/net/ip/connection.h +++ b/subsys/net/ip/connection.h @@ -156,19 +156,6 @@ static inline int net_conn_unregister(struct net_conn_handle *handle) } #endif -/** - * @brief Change the callback and user_data for a registered connection - * handle. - * - * @param handle A handle registered with net_conn_register() - * @param cb Callback to be called - * @param user_data User data supplied by caller. - * - * @return Return 0 if the the change succeed, <0 otherwise. - */ -int net_conn_change_callback(struct net_conn_handle *handle, - net_conn_cb_t cb, void *user_data); - /** * @brief Called by net_core.c when a network packet is received. *