Skip to content

Commit c665bcf

Browse files
committed
Merge branch 'bugfix/doc_wifi_default_init' into 'master'
esp_netif: Update documentation on deinitialization of wifi default netif Closes IDFGH-4692 See merge request espressif/esp-idf!12300
2 parents 61f3af0 + cab1b35 commit c665bcf

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

components/esp_netif/test/test_esp_netif.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,42 @@ TEST_CASE("esp_netif: convert ip address from string", "[esp_netif]")
310310
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_netif_str_to_ip6(NULL, &ipv6));
311311
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_netif_str_to_ip6(ipv6_src[0], NULL));
312312
}
313+
314+
TEST_CASE("esp_netif: create and destroy default wifi interfaces", "[esp_netif][leaks=0]")
315+
{
316+
// Helper constants to refer default STA and AP's params
317+
static const esp_netif_inherent_config_t default_sta_cfg = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA();
318+
static const esp_netif_inherent_config_t default_ap_cfg = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP();
319+
320+
// create default station
321+
esp_netif_t *sta = esp_netif_create_default_wifi_sta();
322+
323+
// check it gets created and has default params
324+
TEST_ASSERT_NOT_NULL(sta);
325+
TEST_ASSERT_EQUAL_STRING(default_sta_cfg.if_desc, esp_netif_get_desc(sta));
326+
TEST_ASSERT_EQUAL(default_sta_cfg.route_prio, esp_netif_get_route_prio(sta));
327+
328+
// create default access point
329+
esp_netif_t *ap = esp_netif_create_default_wifi_ap();
330+
331+
// check it gets created and has default params
332+
TEST_ASSERT_NOT_NULL(ap);
333+
TEST_ASSERT_EQUAL_STRING(default_ap_cfg.if_desc, esp_netif_get_desc(ap));
334+
TEST_ASSERT_EQUAL(default_ap_cfg.route_prio, esp_netif_get_route_prio(ap));
335+
336+
// destroy the station
337+
esp_wifi_clear_default_wifi_driver_and_handlers(sta);
338+
esp_netif_destroy(sta);
339+
340+
// destroy the AP
341+
esp_wifi_clear_default_wifi_driver_and_handlers(ap);
342+
esp_netif_destroy(ap);
343+
344+
345+
// quick check on create-destroy cycle of the default station again
346+
sta = NULL;
347+
sta = esp_netif_create_default_wifi_sta();
348+
TEST_ASSERT_NOT_NULL(sta);
349+
esp_wifi_clear_default_wifi_driver_and_handlers(sta);
350+
esp_netif_destroy(sta);
351+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ such as softAP and station, are provided in two separate APIs to facilitate simp
160160
Please note that these functions return the ``esp_netif`` handle, i.e. a pointer to a network interface object allocated and
161161
configured with default settings, which as a consequence, means that:
162162

163-
* The created object has to be destroyed if a network de-initialization is provided by an application.
163+
* The created object has to be destroyed if a network de-initialization is provided by an application. The de-initialization should be performed in the two steps:
164+
- :cpp:func:`esp_wifi_clear_default_wifi_driver_and_handlers()` -- To unregister default wifi handlers and detach the created object from the wifi
165+
- :cpp:func:`esp_netif_destroy()` -- To destroy the ``esp_netif`` object.
164166
* These *default* interfaces must not be created multiple times, unless the created handle is deleted using :cpp:func:`esp_netif_destroy()`.
165167
* When using Wifi in ``AP+STA`` mode, both these interfaces has to be created.
166168

0 commit comments

Comments
 (0)