mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
Merge branch 'bugfix/esp_netif_list_match_improvement' into 'master'
esp-netif: Improve netif list operations (GitHub PR) Closes IDFGH-5289 See merge request espressif/esp-idf!13636
This commit is contained in:
commit
4b7a7e559a
@ -151,39 +151,39 @@ esp_netif_t* esp_netif_next_unsafe(esp_netif_t* netif)
|
||||
|
||||
bool esp_netif_is_netif_listed(esp_netif_t *esp_netif)
|
||||
{
|
||||
struct slist_netifs_s *item;
|
||||
esp_err_t ret;
|
||||
if ((ret = esp_netif_list_lock()) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to lock esp-netif list with %d", ret);
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
// looking for the netif in the list of registered interfaces
|
||||
esp_netif_t *it = esp_netif_next_unsafe(NULL);
|
||||
do {
|
||||
if (it && it == esp_netif) {
|
||||
SLIST_FOREACH(item, &s_head, next) {
|
||||
if (item->netif == esp_netif) {
|
||||
esp_netif_list_unlock();
|
||||
return true;
|
||||
}
|
||||
} while (NULL != (it = esp_netif_next_unsafe(it)));
|
||||
}
|
||||
esp_netif_list_unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)
|
||||
{
|
||||
struct slist_netifs_s *item;
|
||||
esp_err_t ret;
|
||||
if ((ret = esp_netif_list_lock()) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to lock esp-netif list with %d", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
esp_netif_t *esp_netif = esp_netif_next_unsafe(NULL);
|
||||
do {
|
||||
if (esp_netif && strcmp(if_key, esp_netif_get_ifkey(esp_netif))==0) {
|
||||
SLIST_FOREACH(item, &s_head, next) {
|
||||
esp_netif_t *esp_netif = item->netif;
|
||||
if (strcmp(if_key, esp_netif_get_ifkey(esp_netif)) == 0) {
|
||||
esp_netif_list_unlock();
|
||||
return esp_netif;
|
||||
}
|
||||
} while (NULL != (esp_netif = esp_netif_next_unsafe(esp_netif)));
|
||||
}
|
||||
esp_netif_list_unlock();
|
||||
return NULL;
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ TEST_CASE("esp_netif: get from if_key", "[esp_netif][leaks=0]")
|
||||
|
||||
}
|
||||
|
||||
// This is a private esp-netif API, but include here to test it
|
||||
bool esp_netif_is_netif_listed(esp_netif_t *esp_netif);
|
||||
|
||||
TEST_CASE("esp_netif: create and delete multiple netifs", "[esp_netif][leaks=0]")
|
||||
{
|
||||
@ -54,12 +56,19 @@ TEST_CASE("esp_netif: create and delete multiple netifs", "[esp_netif][leaks=0]"
|
||||
TEST_ASSERT_NOT_NULL(netifs[i]);
|
||||
}
|
||||
|
||||
// there's no AP within created stations
|
||||
TEST_ASSERT_EQUAL(NULL, esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"));
|
||||
// there's no AP within created netifs
|
||||
TEST_ASSERT_NULL(esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"));
|
||||
|
||||
// destroy
|
||||
// check that the created netifs are correctly found by their interface keys and globally listed
|
||||
for (int i=0; i<nr_of_netifs; ++i) {
|
||||
TEST_ASSERT_EQUAL(netifs[i], esp_netif_get_handle_from_ifkey(if_keys[i]));
|
||||
TEST_ASSERT_TRUE(esp_netif_is_netif_listed(netifs[i]));
|
||||
}
|
||||
|
||||
// destroy one by one and check it's been removed
|
||||
for (int i=0; i<nr_of_netifs; ++i) {
|
||||
esp_netif_destroy(netifs[i]);
|
||||
TEST_ASSERT_FALSE(esp_netif_is_netif_listed(netifs[i]));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user