Skip to content

Commit 40192b6

Browse files
DematteisGiacomojtguggedal
authored andcommitted
network: deprecate connection manager
Deprecate conn mgr in favor of lte_lc Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no> Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent 5939b35 commit 40192b6

File tree

5 files changed

+146
-160
lines changed

5 files changed

+146
-160
lines changed

app/prj.conf

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,10 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1408
3232
# Enable Networking and Connection Manager.
3333
CONFIG_NETWORKING=y
3434
CONFIG_NET_SOCKETS=y
35-
CONFIG_NET_SOCKETS_OFFLOAD=y
36-
CONFIG_POSIX_API=y
37-
38-
# Enable LTE Connectivity using Connection Manager
39-
CONFIG_NET_IPV4=y
40-
CONFIG_NET_IPV6=y
41-
CONFIG_NET_IPV6_NBR_CACHE=n
42-
CONFIG_NET_IPV6_MLD=n
43-
CONFIG_NET_CONNECTION_MANAGER=y
44-
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=512
45-
CONFIG_NRF_MODEM_LIB_NET_IF=y
46-
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_DOWN=y
47-
CONFIG_NRF_MODEM_LIB_NET_IF_DOWN_DEFAULT_LTE_DISCONNECT=y
4835

4936
# Enable Link Controller modules
37+
CONFIG_LTE_LINK_CONTROL=y
38+
CONFIG_LTE_LC_PDN_MODULE=y
5039
CONFIG_LTE_LC_PSM_MODULE=y
5140
CONFIG_LTE_LC_EDRX_MODULE=y
5241
CONFIG_LTE_LC_CONN_EVAL_MODULE=y
@@ -183,10 +172,6 @@ CONFIG_LOCATION_REQUEST_DEFAULT_GNSS_VISIBILITY_DETECTION=y
183172
CONFIG_LTE_NETWORK_MODE_LTE_M_NBIOT_GPS=y
184173
CONFIG_NRF_CLOUD_AGNSS=y
185174

186-
# Not for LTE throughput testing
187-
CONFIG_NRF_MODEM_LIB_SHMEM_TX_SIZE=4096
188-
CONFIG_NRF_MODEM_LIB_SHMEM_RX_SIZE=4096
189-
190175
# For nRF9160 the default is socket interface
191176
CONFIG_NET_DEFAULT_IF_ETHERNET=y
192177
CONFIG_MBEDTLS=n

app/src/modules/network/Kconfig.network

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
menu "Network"
8-
depends on NRF_MODEM_LIB_NET_IF || (WIFI_NRF700X && WIFI_MGMT_EXT) || BOARD_NATIVE_POSIX
8+
depends on LTE_LINK_CONTROL
99

1010
config APP_NETWORK_SHELL
1111
bool "Network module shell commands"

app/src/modules/network/network.c

Lines changed: 50 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/logging/log.h>
99
#include <zephyr/zbus/zbus.h>
10-
#include <zephyr/net/conn_mgr_connectivity.h>
11-
#include <zephyr/net/conn_mgr_monitor.h>
10+
#include <modem/nrf_modem_lib.h>
1211
#include <zephyr/task_wdt/task_wdt.h>
1312
#include <date_time.h>
1413
#include <zephyr/smf.h>
@@ -42,14 +41,6 @@ ZBUS_CHAN_ADD_OBS(NETWORK_CHAN, network, 0);
4241

4342
#define MAX_MSG_SIZE sizeof(struct network_msg)
4443

45-
/* Macros used to subscribe to specific Zephyr NET management events. */
46-
#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
47-
#define CONN_LAYER_EVENT_MASK (NET_EVENT_CONN_IF_FATAL_ERROR)
48-
49-
/* Zephyr NET management event callback structures. */
50-
static struct net_mgmt_event_callback l4_cb;
51-
static struct net_mgmt_event_callback conn_cb;
52-
5344
/* State machine */
5445

5546
/* Network module states.
@@ -161,42 +152,6 @@ static void network_msg_send(const struct network_msg *msg)
161152
}
162153
}
163154

164-
static void l4_event_handler(struct net_mgmt_event_callback *cb,
165-
uint64_t event,
166-
struct net_if *iface)
167-
{
168-
ARG_UNUSED(cb);
169-
ARG_UNUSED(iface);
170-
171-
switch (event) {
172-
case NET_EVENT_L4_CONNECTED:
173-
LOG_DBG("Network connectivity established");
174-
network_status_notify(NETWORK_CONNECTED);
175-
break;
176-
case NET_EVENT_L4_DISCONNECTED:
177-
LOG_DBG("Network connectivity lost");
178-
network_status_notify(NETWORK_DISCONNECTED);
179-
break;
180-
default:
181-
/* Don't care */
182-
return;
183-
}
184-
}
185-
186-
static void connectivity_event_handler(struct net_mgmt_event_callback *cb,
187-
uint64_t event,
188-
struct net_if *iface)
189-
{
190-
ARG_UNUSED(cb);
191-
ARG_UNUSED(iface);
192-
193-
if (event == NET_EVENT_CONN_IF_FATAL_ERROR) {
194-
LOG_ERR("NET_EVENT_CONN_IF_FATAL_ERROR");
195-
SEND_FATAL_ERROR();
196-
return;
197-
}
198-
}
199-
200155
static void lte_lc_evt_handler(const struct lte_lc_evt *const evt)
201156
{
202157
switch (evt->type) {
@@ -208,6 +163,38 @@ static void lte_lc_evt_handler(const struct lte_lc_evt *const evt)
208163
LOG_WRN("Not registered, check rejection cause");
209164
network_status_notify(NETWORK_ATTACH_REJECTED);
210165
}
166+
167+
break;
168+
case LTE_LC_EVT_PDN:
169+
switch (evt->pdn.type) {
170+
case LTE_LC_EVT_PDN_ACTIVATED:
171+
LOG_DBG("PDN connection activated");
172+
network_status_notify(NETWORK_CONNECTED);
173+
174+
break;
175+
case LTE_LC_EVT_PDN_DEACTIVATED:
176+
LOG_DBG("PDN connection deactivated");
177+
network_status_notify(NETWORK_DISCONNECTED);
178+
179+
break;
180+
case LTE_LC_EVT_PDN_NETWORK_DETACH:
181+
LOG_DBG("PDN connection network detached");
182+
network_status_notify(NETWORK_DISCONNECTED);
183+
184+
break;
185+
case LTE_LC_EVT_PDN_SUSPENDED:
186+
LOG_DBG("PDN connection suspended");
187+
network_status_notify(NETWORK_DISCONNECTED);
188+
189+
break;
190+
case LTE_LC_EVT_PDN_RESUMED:
191+
LOG_DBG("PDN connection resumed");
192+
network_status_notify(NETWORK_CONNECTED);
193+
194+
default:
195+
break;
196+
}
197+
211198
break;
212199
case LTE_LC_EVT_MODEM_EVENT:
213200
/* If a reset loop happens in the field, it should not be necessary
@@ -224,6 +211,7 @@ static void lte_lc_evt_handler(const struct lte_lc_evt *const evt)
224211
LOG_DBG("LTE_LC_MODEM_EVT_SEARCH_DONE");
225212
network_status_notify(NETWORK_SEARCH_DONE);
226213
}
214+
227215
break;
228216
case LTE_LC_EVT_PSM_UPDATE: {
229217
struct network_msg msg = {
@@ -302,10 +290,10 @@ static int network_disconnect(void)
302290
{
303291
int err;
304292

305-
err = conn_mgr_all_if_disconnect(true);
293+
err = lte_lc_offline();
306294
if (err) {
307-
LOG_ERR("conn_mgr_all_if_down, error: %d", err);
308-
SEND_FATAL_ERROR();
295+
LOG_ERR("lte_lc_offline, error: %d", err);
296+
309297
return err;
310298
}
311299

@@ -322,26 +310,23 @@ static void state_running_entry(void *obj)
322310

323311
LOG_DBG("state_running_entry");
324312

325-
/* Setup handler for Zephyr NET Connection Manager events. */
326-
net_mgmt_init_event_callback(&l4_cb, &l4_event_handler, L4_EVENT_MASK);
327-
net_mgmt_add_event_callback(&l4_cb);
313+
err = nrf_modem_lib_init();
314+
if (err) {
315+
LOG_ERR("Failed to initialize the modem library, error: %d", err);
328316

329-
/* Setup handler for Zephyr NET Connection Manager Connectivity layer. */
330-
net_mgmt_init_event_callback(&conn_cb, &connectivity_event_handler, CONN_LAYER_EVENT_MASK);
331-
net_mgmt_add_event_callback(&conn_cb);
317+
return;
318+
}
332319

333-
/* Connecting to the configured connectivity layer. */
334-
LOG_DBG("Bringing network interface up and connecting to the network");
320+
lte_lc_register_handler(lte_lc_evt_handler);
335321

336-
err = conn_mgr_all_if_up(true);
322+
/* Register handler for default PDP context. */
323+
err = lte_lc_pdn_default_ctx_events_enable();
337324
if (err) {
338-
LOG_ERR("conn_mgr_all_if_up, error: %d", err);
339-
SEND_FATAL_ERROR();
325+
LOG_ERR("lte_lc_pdn_default_ctx_events_enable, error: %d", err);
326+
340327
return;
341328
}
342329

343-
lte_lc_register_handler(lte_lc_evt_handler);
344-
345330
LOG_DBG("Network module started");
346331
}
347332

@@ -382,16 +367,6 @@ static void state_disconnected_entry(void *obj)
382367
ARG_UNUSED(obj);
383368

384369
LOG_DBG("state_disconnected_entry");
385-
386-
/* Resend connection status if the sample is built for Native Sim.
387-
* This is necessary because the network interface is automatically brought up
388-
* at SYS_INIT() before main() is called.
389-
* This means that NET_EVENT_L4_CONNECTED fires before the
390-
* appropriate handler l4_event_handler() is registered.
391-
*/
392-
if (IS_ENABLED(CONFIG_BOARD_NATIVE_SIM)) {
393-
conn_mgr_mon_resend_status();
394-
}
395370
}
396371

397372
static enum smf_state_result state_disconnected_run(void *obj)
@@ -424,21 +399,11 @@ static void state_disconnected_searching_entry(void *obj)
424399

425400
LOG_DBG("state_disconnected_searching_entry");
426401

427-
err = conn_mgr_all_if_connect(true);
402+
err = lte_lc_connect_async(lte_lc_evt_handler);
428403
if (err) {
429-
LOG_ERR("conn_mgr_all_if_connect, error: %d", err);
430-
SEND_FATAL_ERROR();
431-
return;
432-
}
404+
LOG_ERR("lte_lc_connect_async, error: %d", err);
433405

434-
/* Resend connection status if the sample is built for Native Sim.
435-
* This is necessary because the network interface is automatically brought up
436-
* at SYS_INIT() before main() is called.
437-
* This means that NET_EVENT_L4_CONNECTED fires before the
438-
* appropriate handler l4_event_handler() is registered.
439-
*/
440-
if (IS_ENABLED(CONFIG_BOARD_NATIVE_SIM)) {
441-
conn_mgr_mon_resend_status();
406+
return;
442407
}
443408
}
444409

tests/module/network/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
2222
zephyr_include_directories(../../../app/src/common)
2323
zephyr_include_directories(../../../app/src/modules/cloud)
2424
zephyr_include_directories(../../../app/src/modules/network)
25+
zephyr_include_directories(${NRF_BASE}/include/)
26+
zephyr_include_directories(${ZEPHYR_BASE}/../nrfxlib/nrf_modem/include/)
2527

2628
target_link_options(app PRIVATE --whole-archive)
2729
# Options that cannot be passed through Kconfig fragments
@@ -32,9 +34,9 @@ target_compile_definitions(app PRIVATE
3234
-DCONFIG_APP_NETWORK_MESSAGE_QUEUE_SIZE=5
3335
-DCONFIG_APP_NETWORK_MSG_PROCESSING_TIMEOUT_SECONDS=1
3436
-DCONFIG_APP_NETWORK_WATCHDOG_TIMEOUT_SECONDS=2
35-
-DCONFIG_NET_MGMT_EVENT
3637
-DCONFIG_LTE_LC_NETWORK_REGISTRATION_MODULE=1
3738
-DCONFIG_LTE_LC_CONN_EVAL_MODULE=1
3839
-DCONFIG_LTE_LC_EDRX_MODULE=1
3940
-DCONFIG_LTE_LC_PSM_MODULE=1
41+
-DCONFIG_LTE_LC_PDN_MODULE=1
4042
)

0 commit comments

Comments
 (0)