Skip to content

Commit 9b550d7

Browse files
committed
docs(esp_netif): Update ESP-NETIF developers and programmers manual
Made final fixed to both programming manuals and user guidelines
1 parent ea76db7 commit 9b550d7

File tree

5 files changed

+102
-67
lines changed

5 files changed

+102
-67
lines changed

components/esp_netif/include/esp_netif.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,16 @@ esp_err_t esp_netif_napt_disable(esp_netif_t *esp_netif);
595595
* @brief Set or Get DHCP server option
596596
*
597597
* @note Please note that not all combinations of identifiers and options are supported.
598+
*
598599
* Get operations:
600+
*
599601
* * IP_ADDRESS_LEASE_TIME
600602
* * ESP_NETIF_SUBNET_MASK/REQUESTED_IP_ADDRESS (both options do the same, they reflect dhcps_lease_t)
601603
* * ROUTER_SOLICITATION_ADDRESS
602604
* * DOMAIN_NAME_SERVER
605+
*
603606
* Set operations:
607+
*
604608
* * IP_ADDRESS_LEASE_TIME
605609
* * ESP_NETIF_SUBNET_MASK -- set operation is allowed only if the configured mask corresponds to the settings,
606610
* if not, please use esp_netif_set_ip_info() to prevent misconfiguration of DHCPS.
@@ -631,10 +635,14 @@ esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_mode_t opt_
631635
* @brief Set or Get DHCP client option
632636
*
633637
* @note Please note that not all combinations of identifiers and options are supported.
638+
*
634639
* Get operations:
640+
*
635641
* * ESP_NETIF_IP_REQUEST_RETRY_TIME
636642
* * ESP_NETIF_VENDOR_SPECIFIC_INFO -- only available if ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER=n
643+
*
637644
* Set operations:
645+
*
638646
* * ESP_NETIF_IP_REQUEST_RETRY_TIME
639647
* * ESP_NETIF_VENDOR_SPECIFIC_INFO -- only available if ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER=n
640648
* lwip layer creates its own copy of the supplied identifier.

docs/en/api-reference/network/esp_netif.rst

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ The purpose of the ESP-NETIF library is twofold:
1010

1111
ESP-IDF currently implements ESP-NETIF for the lwIP TCP/IP stack only. However, the adapter itself is TCP/IP implementation-agnostic and allows different implementations.
1212

13-
It is also possible to use a custom TCP/IP stack with ESP-IDF, provided it implements BSD API. For more information on building ESP-IDF without lwIP, please refer to :idf_file:`components/esp_netif_stack/README.md`.
14-
15-
Some ESP-NETIF API functions are intended to be called by application code, for example, to get or set interface IP addresses, and configure DHCP. Other functions are intended for internal ESP-IDF use by the network driver layer.
16-
17-
In many cases, applications do not need to call ESP-NETIF APIs directly as they are called by the default network event handlers.
13+
Some ESP-NETIF API functions are intended to be called by application code, for example, to get or set interface IP addresses, and configure DHCP. Other functions are intended for internal ESP-IDF use by the network driver layer. In many cases, applications do not need to call ESP-NETIF APIs directly as they are called by the default network event handlers.
1814

1915
If you are only interested in using the most common network interfaces with default setting, please read :ref:`esp_netif_user` to see how you can initialize default interfaces and register event handlers.
2016

@@ -29,15 +25,15 @@ If you would like to develop your own network driver, implement support for a ne
2925
ESP-NETIF User's Manual
3026
=======================
3127

32-
It is usually just enough to create a default network interface after startup and destroy it upon closing (see :ref:`esp_netif_init`). It is also necessary to receive a notification upon assigning a new IP address or losing it (see :ref:`esp-netif-ip-events`).
28+
It is usually just enough to create a default network interface after startup and destroy it upon closing (see :ref:`esp_netif_init`). It is also useful to receive a notification upon assigning a new IP address or losing it (see :ref:`esp-netif-ip-events`).
3329

3430

3531
.. _esp_netif_init:
3632

3733
Initialization
3834
--------------
3935

40-
Since the ESP-NETIF component uses system events, the typical network startup code looks like this (note, that error handling is omitted for clarity):
36+
Since the ESP-NETIF component uses system events, the typical network startup code looks like this (note, that error handling is omitted for clarity, see :example_file:`ethernet/basic/main/ethernet_example_main.c` for complete startup code):
4137

4238
.. code-block:: c
4339
@@ -48,7 +44,7 @@ Since the ESP-NETIF component uses system events, the typical network startup co
4844
// 2) Create the network interface handle
4945
esp_netif = esp_netif_new(&config);
5046
51-
// 3) Create the communication driver (e.g. Ethernet) and it's network layer glue
47+
// 3) Create the network interface driver (e.g. Ethernet) and it's network layer glue
5248
// and register the ESP-NETIF event (e.g. to bring the interface up upon link-up event)
5349
esp_netif_glue_t glue = driver_glue(driver);
5450
@@ -57,15 +53,15 @@ Since the ESP-NETIF component uses system events, the typical network startup co
5753
5854
// 5) Register user-side event handlers
5955
esp_event_handler_register(DRIVER_EVENT, ...); // to observe driver states, e.g. link-up
60-
esp_event_handler_register(IP_EVENT, ...); // to observer ESP-NETIF states, e.g. get an IP
56+
esp_event_handler_register(IP_EVENT, ...); // to observe ESP-NETIF states, e.g. get an IP
6157
6258
6359
.. note::
6460

65-
These 5 steps need to be performed in the exact order as shown above, mainly due to the default event loop, which is used by network interface drivers to register system events.
61+
These steps must be performed in the exact order shown above, primarily due to the default event loop used by network interface drivers to register system events.
6662

67-
- Default event loop needs to be created **before** initializing an interface driver (as it typically needs register system even handlers)
68-
- Registering application event handlers need to happen **after** calling :cpp:func:`esp_netif_attach`, because the event handlers are called in the order they were registered and we need to have the system handlers called first.
63+
- The default event loop needs to be created **before** initializing an interface driver, as the driver typically needs to register system event handlers.
64+
- Registering application event handlers must occur **after** calling :cpp:func:`esp_netif_attach`, because event handlers are called in the order they were registered. To ensure that system handlers are called first, you should register application handlers afterward.
6965

7066
Steps ``2)``, ``3)`` and ``4)`` are quite complex for most common use-cases, so ESP-NETIF provides some pre-configured interfaces and convenience functions that create the most common network interfaces in their most common configurations.
7167

@@ -74,16 +70,16 @@ Since the ESP-NETIF component uses system events, the typical network startup co
7470
Each network interface needs to be initialized separately, so if you would like to use multiple interfaces, you would have to run steps ``2)`` to ``5)`` for every interface. Set ``1)`` should be performed only once.
7571

7672

77-
Creating and configuring the interface and attaching the communication driver to it (steps ``2)``, ``3)`` and ``4)``) is described in :ref:`create_esp_netif`.
73+
Creating and configuring the interface and attaching the network interface driver to it (steps ``2)``, ``3)`` and ``4)``) is described in :ref:`create_esp_netif`.
7874
Using the ESP-NETIF event handlers (step ``5)``) is described in :ref:`esp-netif-ip-events`.
7975

8076

8177
.. _create_esp_netif:
8278

83-
Common network interfaces
79+
Common Network Interfaces
8480
^^^^^^^^^^^^^^^^^^^^^^^^^
8581

86-
As the initialization of network interfaces could be quite complex, ESP-NETIF provides some convenient methods of creating the most common onc, such as Wi-Fi and Ethernet.
82+
As the initialization of network interfaces could be quite complex, ESP-NETIF provides some convenient methods of creating the most common ones, such as Wi-Fi and Ethernet.
8783

8884
Please refer to the following example to understand the initialization process of the default interface:
8985

@@ -115,34 +111,34 @@ The initialization code as well as registering event handlers for default interf
115111

116112
.. only:: SOC_WIFI_SUPPORTED
117113

118-
Please note that these functions return the ``esp_netif`` handle, i.e., a pointer to a network interface object allocated and configured with default settings, as a consequence, which means that:
114+
Please note that these functions return the ``esp_netif`` handle, i.e., a pointer to a network interface object allocated and configured with default settings, which means that:
119115

120116
* The created object has to be destroyed if a network de-initialization is provided by an application using :cpp:func:`esp_netif_destroy_default_wifi()`.
121117

122-
* These *default* interfaces must not be created multiple times unless the created handle is deleted using :cpp:func:`esp_netif_destroy()`.
118+
* These *default* interfaces must not be created multiple times unless the created handle is deleted using :cpp:func:`esp_netif_destroy_default_wifi()`.
123119

124120

125121
.. only:: CONFIG_ESP_WIFI_SOFTAP_SUPPORT
126122

127-
* When using Wi-Fi in ``AP+STA`` mode, both these interfaces have to be created.
123+
* When using Wi-Fi in ``AP+STA`` mode, both these interfaces have to be created. Please refer to the example :example_file:`wifi/softap_sta/main/softap_sta.c`
128124

129125
.. _esp-netif-ip-events:
130126

131127
IP Events
132128
---------
133129

134-
In the last section of :ref:`esp_netif_init` code (step ``5)``), we register two sets of event handlers:
130+
In the final section of :ref:`esp_netif_init` code (step ``5)``), you register two sets of event handlers:
135131

136-
* Communication driver events: To be notified about driver's lifecycle states, for example when Wi-Fi station joined an AP, or when it gets disconnected. Handling these events is out of the scope of ESP-NETIF component, it is only worth mentioning that the same events are also used by ESP-NETIF to set the network interface to a desired state of, so if an application uses the driver's events to assume specific states of the network interface, it need to register their handlers **after** registering system handlers (which typically happen when attaching the driver to the interface). That is why the handler registration is performed in the last step of the :ref:`esp_netif_init` code.
132+
* **Network Interface Driver Events**: These events notify you about the driver's lifecycle states, such as when a Wi-Fi station joins an AP or gets disconnected. Handling these events is outside the scope of the ESP-NETIF component. It is worth noting that the same events are also used by ESP-NETIF to set the network interface to a desired state. Therefore, if your application uses the driver's events to determine specific states of the network interface, you should register these handlers **after** registering the system handlers (which typically happens when attaching the driver to the interface). This is why handler registration occurs in the final step of the :ref:`esp_netif_init` code.
137133

138-
* IP events: To be notified about IP address changes, that is when we get assigned a new address or when the valid address is lost. Specific types of these events are listed in :cpp:type:`ip_event_t`, each common interface has the related pair of ``GOT_IP`` and ``LOST_IP`` events.
134+
* **IP Events**: These events notify you about IP address changes, such as when a new address is assigned or when a valid address is lost. Specific types of these events are listed in :cpp:type:`ip_event_t`. Each common interface has a related pair of ``GOT_IP`` and ``LOST_IP`` events.
135+
136+
Registering event handlers is crucial due to the asynchronous nature of networking, where changes in network state can occur unpredictably. By registering event handlers, applications can respond to these changes promptly, ensuring appropriate actions are taken in response to network events.
139137

140138
.. note::
141139

142140
Lost IP events are triggered by a timer configurable by :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL`. The timer is started upon losing the IP address and the event will be raised after the configured interval, which is 120s by default. The event could be disabled when setting the interval to 0.
143141

144-
145-
146142
.. _esp-netif structure:
147143

148144
ESP-NETIF Architecture
@@ -175,26 +171,25 @@ ESP-NETIF Architecture
175171
+-----| | | | | | |
176172
| | | | | | (D) |
177173
(B) | | | | (C) | +-----------------------+
178-
--------+ | | +===========================+
179-
COMMUNICATION | | NETWORK STACK
180-
DRIVER | | ESP-NETIF
181-
| | +------------------+
182-
| | +---------------------------+.........| open/close |
174+
--------+ | | +===========================+ NETWORK STACK
175+
NETWORK | | ESP-NETIF
176+
INTERFACE | |
177+
DRIVER | | +---------------------------+ +------------------+
178+
| | | |.........| open/close |
183179
| | | | | |
184180
| -<--| l2tap_write |-----<---| write |
185181
| | | | |
186182
---->--| esp_vfs_l2tap_eth_filter |----->---| read |
187-
| | | |
183+
| | | (A) |
188184
| (E) | +------------------+
189-
+---------------------------+
190-
USER CODE
185+
+---------------------------+ USER CODE
191186
ESP-NETIF L2 TAP
192187
193188
194189
Data and Event Flow in the Diagram
195190
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
196191

197-
* ``........`` Initialization line from user code to ESP-NETIF and communication driver
192+
* ``........`` Initialization line from user code to ESP-NETIF and network interface driver
198193

199194
* ``--<--->--`` Data packets going from communication media to TCP/IP stack and back
200195

@@ -208,7 +203,7 @@ ESP-NETIF Interaction
208203
A) User Code, Boilerplate
209204
'''''''''''''''''''''''''
210205

211-
Overall application interaction with a specific IO driver for communication media and configured TCP/IP network stack is abstracted using ESP-NETIF APIs and is outlined as below:
206+
Overall application interaction with a specific IO driver for the communication media (network interface driver) and configured TCP/IP network stack is abstracted using ESP-NETIF APIs and is outlined as below:
212207

213208
A) Initialization code
214209

@@ -232,10 +227,10 @@ B) Interaction with network interfaces using ESP-NETIF API
232227
3) Controls application lifecycle (set interface up or down)
233228

234229

235-
B) Communication Driver, IO Driver, and Media Driver
236-
''''''''''''''''''''''''''''''''''''''''''''''''''''
230+
B) Network Interface Driver
231+
'''''''''''''''''''''''''''
237232

238-
Communication driver plays these two important roles in relation to ESP-NETIF:
233+
Network interface driver (also called I/O Driver, or Media Driver) plays these two important roles in relation to ESP-NETIF:
239234

240235
1) Event handlers: Defines behavior patterns of interaction with ESP-NETIF (e.g., ethernet link-up -> turn netif on)
241236

@@ -276,18 +271,14 @@ The network stack has no public interaction with application code with regard to
276271

277272
E) ESP-NETIF L2 TAP Interface
278273
'''''''''''''''''''''''''''''
279-
The ESP-NETIF L2 TAP interface is a mechanism in ESP-IDF used to access Data Link Layer (L2 per OSI/ISO) for frame reception and transmission from the user application. Its typical usage in the embedded world might be the implementation of non-IP-related protocols, e.g., PTP, Wake on LAN. Note that only Ethernet (IEEE 802.3) is currently supported.
280-
281-
From a user perspective, the ESP-NETIF L2 TAP interface is accessed using file descriptors of VFS, which provides file-like interfacing (using functions like ``open()``, ``read()``, ``write()``, etc). To learn more, refer to :doc:`/api-reference/storage/vfs`.
282-
283-
There is only one ESP-NETIF L2 TAP interface device (path name) available. However multiple file descriptors with different configurations can be opened at a time since the ESP-NETIF L2 TAP interface can be understood as a generic entry point to the Layer 2 infrastructure. What is important is then the specific configuration of the particular file descriptor. It can be configured to give access to a specific Network Interface identified by ``if_key`` (e.g., `ETH_DEF`) and to filter only specific frames based on their type (e.g., Ethernet type in the case of IEEE 802.3). Filtering only specific frames is crucial since the ESP-NETIF L2 TAP needs to exist along with the IP stack and so the IP-related traffic (IP, ARP, etc.) should not be passed directly to the user application. Even though this option is still configurable, it is not recommended in standard use cases. Filtering is also advantageous from the perspective of the user's application, as it only gets access to the frame types it is interested in, and the remaining traffic is either passed to other L2 TAP file descriptors or to the IP stack.
274+
The ESP-NETIF L2 TAP interface is a mechanism in ESP-IDF used to access Data Link Layer (L2 per OSI/ISO) for frame reception and transmission from the user application. Its typical usage in the embedded world might be the implementation of non-IP-related protocols, e.g., PTP, Wake on LAN. Note that only Ethernet (IEEE 802.3) is currently supported. Please read more about L2 TAP in :ref:`esp_netif_l2tap`.
284275

285276
.. _esp_netif_programmer:
286277

287278
ESP-NETIF Programmer's Manual
288279
=============================
289280

290-
In same cases, it is not enough to simply initialize a network interface by default, start using it and connect to the local network. If so, please consult the programming guide: :doc:`/api-reference/network/esp_netif_programming`.
281+
In some cases, it is not enough to simply initialize a network interface by default, start using it and connect to the local network. If so, please consult the programming guide: :doc:`/api-reference/network/esp_netif_programming`.
291282

292283
You would typically need to use specific sets of ESP-NETIF APIs in the following use-cases:
293284

@@ -303,4 +294,4 @@ You would typically need to use specific sets of ESP-NETIF APIs in the following
303294
ESP-NETIF Developer's Manual
304295
============================
305296

306-
In some cases, user applications might need to customize ESP-NETIF, register custom drivers or even custom TCP/IP stacks. If so, please consult the programming guide: :doc:`/api-reference/network/esp_netif_driver`.
297+
In some cases, user applications might need to customize ESP-NETIF, register custom drivers or even use a custom TCP/IP stack. If so, please consult the :doc:`/api-reference/network/esp_netif_driver`.

0 commit comments

Comments
 (0)