Skip to content

Commit 3714b41

Browse files
committed
docs: Add network module documentation
Add network module documentation. The state diagram is an initial version using Mermaid and needs to be improved on as it renders badly. Signed-off-by: Jan Tore Guggedal <jantore.guggedal@nordicsemi.no>
1 parent 7a8f8e2 commit 3714b41

File tree

1 file changed

+88
-3
lines changed

1 file changed

+88
-3
lines changed

docs/modules/network.md

+88-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,96 @@
11
# Network module
22

3-
What does this module do
3+
The Network module manages the cellular connectivity for applications running on nRF91 Series devices. It handles network connection states, system mode configuration, power saving configurations, and network quality monitoring. It utilizes the Zephyr network management APIs and the [LTE Link Control](https://docs.nordicsemi.com/bundle/ncs-2.9.0/page/nrf/libraries/modem/lte_lc.html) library from nRF Connect SDK to control the modem and monitor network events. Internally, the module implements a state machine that uses Zephyr's [State Machine Framework](https://docs.zephyrproject.org/latest/services/smf/index.html).
4+
5+
The module is designed to by default search for a suitable network automatically on startup and then maintain the connection for the lifetime of the application.
6+
The library can also be configured to be fully controlled by the application instead, giving closer control over the LTE link and current consumption.
7+
See the [Configurations](#configurations) section for more information.
48

59
## Messages
610

11+
The network module communicates via the zbus channel ``NETWORK_CHAN``.
12+
The messages are defined in `network.h`. A message consists of a type and optional data. Each message is either an input message or an output message.
13+
All input messages are requests from the application to the network module. The output messages may be responses to input messages or notifications from the network module to the application.
14+
15+
The following messages are supported:
16+
17+
### Input Messages
18+
19+
- **NETWORK_CONNECT**: Request to connect to the network.
20+
- **NETWORK_DISCONNECT**: Request to disconnect from the network.
21+
- **NETWORK_SEARCH_STOP**: Stop searching for a network. The module will not attempt to connect to a network until a new `NETWORK_CONNECT` message is received.
22+
- **NETWORK_SYSTEM_MODE_REQUEST**: Request to retrieve the current system mode. The response will be sent as a `NETWORK_SYSTEM_MODE_RESPONSE` message.
23+
- **NETWORK_SYSTEM_MODE_SET_LTEM**: Request to set the system mode to only use LTE-M only.
24+
- **NETWORK_SYSTEM_MODE_SET_NBIOT**: Request to set the system mode to only use NB-IoT only.
25+
- **NETWORK_SYSTEM_MODE_SET_LTEM_NBIOT**: Request to set the system mode to use both LTE-M and NB-IoT.
26+
- **NETWORK_QUALITY_SAMPLE_REQUEST**: Request to sample the current network connection quality. The response will be sent as a `NETWORK_QUALITY_SAMPLE_RESPONSE` message.
27+
28+
### Output Messages
29+
30+
- **NETWORK_DISCONNECTED**: The device is disconnected from the network.
31+
- **NETWORK_CONNECTED**: The device is connected to the network and has an IP address.
32+
- **NETWORK_MODEM_RESET_LOOP**: The modem has detected a reset loop with too many attach requests within a short time.
33+
- **NETWORK_UICC_FAILURE**: The modem has detected an error with the SIM card. Confirm that it is installed correctly.
34+
- **NETWORK_LIGHT_SERACH_DONE**: The modem has completed a light search based on previous cell history without finding a suitable cell. This message can be used to stop the search to save power.
35+
- **NETWORK_ATTACH_REJECTED**: A network attach request has been rejected by the network.
36+
- **NETWORK_PSM_PARAMS**: PSM parameters have been received (in the `.psm_cfg` field of the message).
37+
- **NETWORK_EDRX_PARAMS**: eDRX parameters have been received (in `.edrx_cfg` field).
38+
- **NETWORK_SYSTEM_MODE_RESPONSE**: Response to a system mode request (`NETWORK_SYSTEM_MODE_REQUEST`) with current mode in `.system_mode` field.
39+
- **NETWORK_QUALITY_SAMPLE_RESPONSE**: Response to a quality sample request (`NETWORK_QUALITY_SAMPLE_REQUEST`) with data in `.conn_eval_params` field.
40+
41+
### Message Structure
42+
43+
The network module uses the `struct network_msg` structure for communication:
44+
45+
```c
46+
struct network_msg {
47+
enum network_msg_type type;
48+
union {
49+
enum lte_lc_system_mode system_mode;
50+
struct lte_lc_psm_cfg psm_cfg;
51+
struct lte_lc_edrx_cfg edrx_cfg;
52+
struct lte_lc_conn_eval_params conn_eval_params;
53+
};
54+
};
55+
```
56+
57+
## Configurations
58+
759
## Configurations
860

9-
Kconfig and device tree
61+
The Network module can be configured using the following Kconfig options:
62+
63+
- **CONFIG_APP_NETWORK_THREAD_STACK_SIZE**: Sets the stack size for the network module thread.
64+
65+
- **CONFIG_APP_NETWORK_WATCHDOG_TIMEOUT_SECONDS**: Defines the timeout in seconds for the network module watchdog. This timeout covers both waiting for incoming messages and message processing time.
66+
67+
- **CONFIG_APP_NETWORK_MSG_PROCESSING_TIMEOUT_SECONDS**: Sets the maximum time allowed for processing a single message in the module's state machine. This value must be smaller than the watchdog timeout.
68+
69+
- **CONFIG_APP_NETWORK_SEARCH_NETWORK_ON_STARTUP**: When enabled, the module will automatically search for a network on startup. If disabled, network search must be triggered by a NETWORK_CONNECT message.
70+
71+
- **CONFIG_APP_NETWORK_LOG_LEVEL_***: Controls the logging level for the network module. This follows Zephyr's standard logging configuration pattern.
72+
73+
## State Diagram
74+
75+
The Network module implements a state machine with the following states and transitions:
76+
77+
```mermaid
78+
stateDiagram-v2
79+
[*] --> STATE_RUNNING
80+
81+
state STATE_RUNNING {
82+
[*] --> STATE_DISCONNECTED
83+
84+
STATE_DISCONNECTED --> STATE_CONNECTED : NETWORK_CONNECTED
85+
STATE_CONNECTED --> STATE_DISCONNECTING : NETWORK_DISCONNECT
86+
STATE_DISCONNECTING --> STATE_DISCONNECTED_IDLE : NETWORK_DISCONNECTED
87+
88+
state STATE_DISCONNECTED {
89+
[*] --> STATE_DISCONNECTED_SEARCHING
90+
91+
STATE_DISCONNECTED_SEARCHING --> STATE_DISCONNECTED_IDLE : NETWORK_SEARCH_STOP/NETWORK_DISCONNECT
92+
STATE_DISCONNECTED_IDLE --> STATE_DISCONNECTED_SEARCHING : NETWORK_CONNECT
93+
}
94+
}
1095
11-
## State diagram
96+
```

0 commit comments

Comments
 (0)