Skip to content

Commit 011f2bc

Browse files
rluboskartben
authored andcommitted
net: conn_mgr: Fix disconnect with CONN_MGR_IF_NO_AUTO_DOWN unset
Connection manager enforces non-blocking disconnect() behavior, yet in case CONN_MGR_IF_NO_AUTO_DOWN flag is not set, it'd put the interface down right after, disrupting the disconnect process. As putting the interface down can be handled in the corresponding event handler as well, when the interface is actually disconnected, remove the conn_mgr_conn_if_auto_admin_down() call from conn_mgr_if_disconnect(). To make this work with persistence flag, introduce a new internal flag indicating that the interface is in active disconnect. Finally, since it isn't really necessary that disconnect() API call is non-blocking, remove that requirement. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent 0abf4f5 commit 011f2bc

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

include/zephyr/net/conn_mgr_connectivity.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ enum conn_mgr_if_flag {
9090
CONN_MGR_IF_NO_AUTO_DOWN,
9191

9292
/** @cond INTERNAL_HIDDEN */
93+
/**
94+
* Internal flag indicating that the interface is in active (application initiated)
95+
* disconnect.
96+
*/
97+
CONN_MGR_IF_DISCONNECTING,
98+
9399
/* Total number of flags - must be at the end of the enum */
94100
CONN_MGR_NUM_IF_FLAGS,
95101
/** @endcond */

include/zephyr/net/conn_mgr_connectivity_impl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ struct conn_mgr_conn_api {
5757
* stop any in-progress attempts to associate to a network, the bound iface pointed to by
5858
* if_conn->iface.
5959
*
60-
* Must be non-blocking.
61-
*
6260
* Called by @ref conn_mgr_if_disconnect.
6361
*/
6462
int (*disconnect)(struct conn_mgr_conn_binding *const binding);

subsys/net/conn_mgr/conn_mgr_connectivity.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ int conn_mgr_if_connect(struct net_if *iface)
4141
}
4242
}
4343

44+
conn_mgr_if_set_flag(iface, CONN_MGR_IF_DISCONNECTING, false);
45+
4446
status = api->connect(binding);
4547

4648
out:
@@ -49,8 +51,6 @@ int conn_mgr_if_connect(struct net_if *iface)
4951
return status;
5052
}
5153

52-
static void conn_mgr_conn_if_auto_admin_down(struct net_if *iface);
53-
5454
int conn_mgr_if_disconnect(struct net_if *iface)
5555
{
5656
struct conn_mgr_conn_binding *binding;
@@ -75,21 +75,13 @@ int conn_mgr_if_disconnect(struct net_if *iface)
7575
goto out;
7676
}
7777

78+
conn_mgr_if_set_flag(iface, CONN_MGR_IF_DISCONNECTING, true);
79+
7880
status = api->disconnect(binding);
7981

8082
out:
8183
conn_mgr_binding_unlock(binding);
8284

83-
/* Since the connectivity implementation will not automatically attempt to reconnect after
84-
* a call to conn_mgr_if_disconnect, conn_mgr_conn_if_auto_admin_down should be called.
85-
*
86-
* conn_mgr_conn_handle_iface_down will only call conn_mgr_conn_if_auto_admin_down if
87-
* persistence is disabled. To ensure conn_mgr_conn_if_auto_admin_down is called in all
88-
* cases, we must call it directly from here. If persistence is disabled, this will result
89-
* in conn_mgr_conn_if_auto_admin_down being called twice, but that is not an issue.
90-
*/
91-
conn_mgr_conn_if_auto_admin_down(iface);
92-
9385
return status;
9486
}
9587

@@ -306,11 +298,16 @@ static void conn_mgr_conn_handle_iface_down(struct net_if *iface)
306298
return;
307299
}
308300

309-
/* If the iface is persistent, we expect it to try to reconnect, so nothing else to do */
310-
if (conn_mgr_if_get_flag(iface, CONN_MGR_IF_PERSISTENT)) {
301+
/* If the iface is persistent, we expect it to try to reconnect, unless
302+
* disconnect was explicitly initiated by the application.
303+
*/
304+
if (conn_mgr_if_get_flag(iface, CONN_MGR_IF_PERSISTENT) &&
305+
!conn_mgr_if_get_flag(iface, CONN_MGR_IF_DISCONNECTING)) {
311306
return;
312307
}
313308

309+
conn_mgr_if_set_flag(iface, CONN_MGR_IF_DISCONNECTING, false);
310+
314311
/* Otherwise, we do not expect the iface to reconnect, and we should call
315312
* conn_mgr_conn_if_auto_admin_down
316313
*/

0 commit comments

Comments
 (0)