diff --git a/components/esp_common/include/esp_compiler.h b/components/esp_common/include/esp_compiler.h index 94ec29c23c..6922c50adc 100644 --- a/components/esp_common/include/esp_compiler.h +++ b/components/esp_common/include/esp_compiler.h @@ -30,4 +30,22 @@ #define unlikely(x) (x) #endif +/* + * Utility macros used for designated initializers, which work differently + * in C99 and C++ standards mainly for aggregate types. + * The member separator, comma, is already part of the macro, please omit the trailing comma. + * Usage example: + * struct config_t { char* pchr; char arr[SIZE]; } config = { + * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(pchr) + * ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(arr, "Value") + * }; + */ +#ifdef __cplusplus +#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) { .member = value }, +#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) .member = { }, +#else +#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(member, value) .member = value, +#define ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(member) +#endif + #endif \ No newline at end of file diff --git a/components/esp_netif/esp_netif_defaults.c b/components/esp_netif/esp_netif_defaults.c index 39278857fb..4dd497648a 100644 --- a/components/esp_netif/esp_netif_defaults.c +++ b/components/esp_netif/esp_netif_defaults.c @@ -35,44 +35,16 @@ // // Default configuration of common interfaces, such as STA, AP, ETH // -const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config = { - .flags = ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED, - .lost_ip_event = IP_EVENT_STA_LOST_IP, - .get_ip_event = IP_EVENT_STA_GOT_IP, - .if_key = "WIFI_STA_DEF", - .if_desc = "sta", - .route_prio = 100 -}; +const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA(); -static const esp_netif_ip_info_t soft_ap_ip = { +const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP(); + +const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); + +const esp_netif_inherent_config_t _g_esp_netif_inherent_ppp_config = ESP_NETIF_INHERENT_DEFAULT_PPP(); + +const esp_netif_ip_info_t _g_esp_netif_soft_ap_ip = { .ip = { .addr = IP4TOADDR( 192, 168, 4, 1) }, .gw = { .addr = IP4TOADDR( 192, 168, 4, 1) }, .netmask = { .addr = IP4TOADDR( 255, 255, 255, 0) }, - -}; - -const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config = { - .flags = ESP_NETIF_DHCP_SERVER | ESP_NETIF_FLAG_AUTOUP, - .ip_info = (esp_netif_ip_info_t*)&soft_ap_ip, - .if_key = "WIFI_AP_DEF", - .if_desc = "ap", - .route_prio = 10 -}; - -const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config = { - .get_ip_event = IP_EVENT_ETH_GOT_IP, - .lost_ip_event = 0, - .flags = ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED, - .if_key = "ETH_DEF", - .if_desc = "eth", - .route_prio = 50 -}; - -const esp_netif_inherent_config_t _g_esp_netif_inherent_ppp_config = { - .flags = ESP_NETIF_FLAG_IS_PPP, - .lost_ip_event = IP_EVENT_PPP_LOST_IP, - .get_ip_event = IP_EVENT_PPP_GOT_IP, - .if_key = "PPP_DEF", - .if_desc = "ppp", - .route_prio = 128 }; diff --git a/components/esp_netif/include/esp_netif.h b/components/esp_netif/include/esp_netif.h index 9c8057f9bb..c4ff453013 100644 --- a/components/esp_netif/include/esp_netif.h +++ b/components/esp_netif/include/esp_netif.h @@ -255,10 +255,25 @@ void esp_netif_action_got_ip(void *esp_netif, esp_event_base_t base, int32_t eve * @param[in] esp_netif Handle to esp-netif instance * @param[in] mac Desired mac address for the related network interface - * @return ESP_OK + * @return + * - ESP_OK - success + * - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error + * - ESP_ERR_NOT_SUPPORTED - mac not supported on this interface */ esp_err_t esp_netif_set_mac(esp_netif_t *esp_netif, uint8_t mac[]); +/** + * @brief Get the mac address for the interface instance + + * @param[in] esp_netif Handle to esp-netif instance + * @param[out] mac Resultant mac address for the related network interface + * @return + * - ESP_OK - success + * - ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error + * - ESP_ERR_NOT_SUPPORTED - mac not supported on this interface + */ +esp_err_t esp_netif_get_mac(esp_netif_t *esp_netif, uint8_t mac[]); + /** * @brief Set the hostname of an interface * @@ -719,6 +734,15 @@ const char *esp_netif_get_ifkey(esp_netif_t *esp_netif); */ const char *esp_netif_get_desc(esp_netif_t *esp_netif); +/** + * @brief Returns configured routing priority number + * + * @param[in] esp_netif Handle to esp-netif instance + * + * @return Integer representing the instance's route-prio, or -1 if invalid paramters + */ +int esp_netif_get_route_prio(esp_netif_t *esp_netif); + /** * @brief Returns configured event for this esp-netif instance and supplied event type * diff --git a/components/esp_netif/include/esp_netif_defaults.h b/components/esp_netif/include/esp_netif_defaults.h index d03c45965a..3c41d9c2b9 100644 --- a/components/esp_netif/include/esp_netif_defaults.h +++ b/components/esp_netif/include/esp_netif_defaults.h @@ -15,6 +15,8 @@ #ifndef _ESP_NETIF_DEFAULTS_H #define _ESP_NETIF_DEFAULTS_H +#include "esp_compiler.h" + #ifdef __cplusplus extern "C" { #endif @@ -23,6 +25,54 @@ extern "C" { // Macros to assemble master configs with partial configs from netif, stack and driver // +#define ESP_NETIF_INHERENT_DEFAULT_WIFI_STA() \ + { \ + .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \ + .get_ip_event = IP_EVENT_STA_GOT_IP, \ + .lost_ip_event = IP_EVENT_STA_LOST_IP, \ + .if_key = "WIFI_STA_DEF", \ + .if_desc = "sta", \ + .route_prio = 100 \ + } \ + +#define ESP_NETIF_INHERENT_DEFAULT_WIFI_AP() \ + { \ + .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_SERVER | ESP_NETIF_FLAG_AUTOUP), \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \ + .ip_info = &_g_esp_netif_soft_ap_ip, \ + .get_ip_event = 0, \ + .lost_ip_event = 0, \ + .if_key = "WIFI_AP_DEF", \ + .if_desc = "ap", \ + .route_prio = 10 \ + }; + +#define ESP_NETIF_INHERENT_DEFAULT_ETH() \ + { \ + .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \ + .get_ip_event = IP_EVENT_ETH_GOT_IP, \ + .lost_ip_event = 0, \ + .if_key = "ETH_DEF", \ + .if_desc = "eth", \ + .route_prio = 50 \ + }; + +#define ESP_NETIF_INHERENT_DEFAULT_PPP() \ + { \ + .flags = ESP_NETIF_FLAG_IS_PPP, \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \ + .get_ip_event = IP_EVENT_PPP_GOT_IP, \ + .lost_ip_event = IP_EVENT_PPP_LOST_IP, \ + .if_key = "PPP_DEF", \ + .if_desc = "ppp", \ + .route_prio = 128 \ +}; + /** * @brief Default configuration reference of ethernet interface */ @@ -37,7 +87,7 @@ extern "C" { * @brief Default configuration reference of WIFI AP */ #define ESP_NETIF_DEFAULT_WIFI_AP() \ -{ \ + { \ .base = ESP_NETIF_BASE_DEFAULT_WIFI_AP, \ .driver = NULL, \ .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP, \ @@ -102,13 +152,15 @@ extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp; // // Include default common configs inherent to esp-netif // - These inherent configs are defined in esp_netif_defaults.c and describe -// common behavioural patters for common interfaces such as STA, AP, ETH +// common behavioural patterns for common interfaces such as STA, AP, ETH, PPP // extern const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config; extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config; extern const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config; extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ppp_config; +extern const esp_netif_ip_info_t _g_esp_netif_soft_ap_ip; + #ifdef __cplusplus } #endif diff --git a/components/esp_netif/include/esp_netif_types.h b/components/esp_netif/include/esp_netif_types.h index 9c785ad883..242ce53c36 100644 --- a/components/esp_netif/include/esp_netif_types.h +++ b/components/esp_netif/include/esp_netif_types.h @@ -155,7 +155,7 @@ typedef enum esp_netif_ip_event_type { typedef struct esp_netif_inherent_config { esp_netif_flags_t flags; /*!< flags that define esp-netif behavior */ uint8_t mac[6]; /*!< initial mac address for this interface */ - esp_netif_ip_info_t* ip_info; /*!< initial ip address for this interface */ + const esp_netif_ip_info_t* ip_info; /*!< initial ip address for this interface */ uint32_t get_ip_event; /*!< event id to be raised when interface gets an IP */ uint32_t lost_ip_event; /*!< event id to be raised when interface losts its IP */ const char * if_key; /*!< string identifier of the interface */ diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 195ddd3ffa..f14a2583bb 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -528,6 +528,22 @@ esp_err_t esp_netif_set_mac(esp_netif_t *esp_netif, uint8_t mac[]) return ESP_OK; } +esp_err_t esp_netif_get_mac(esp_netif_t *esp_netif, uint8_t mac[]) +{ + if (esp_netif == NULL || esp_netif->lwip_netif == NULL) { + return ESP_ERR_ESP_NETIF_IF_NOT_READY; + } + if (esp_netif->is_ppp_netif) { + return ESP_ERR_NOT_SUPPORTED; + } + if (esp_netif_is_netif_up(esp_netif)) { + memcpy(mac, esp_netif->lwip_netif->hwaddr, NETIF_MAX_HWADDR_LEN); + return ESP_OK; + } + memcpy(mac, esp_netif->mac, NETIF_MAX_HWADDR_LEN); + return ESP_OK; +} + static void esp_netif_dhcps_cb(u8_t client_ip[4]) { @@ -1434,6 +1450,14 @@ const char *esp_netif_get_desc(esp_netif_t *esp_netif) return esp_netif->if_desc; } +int esp_netif_get_route_prio(esp_netif_t *esp_netif) +{ + if (esp_netif == NULL) { + return -1; + } + return esp_netif->route_prio; +} + int32_t esp_netif_get_event_id(esp_netif_t *esp_netif, esp_netif_ip_event_type_t event_type) { switch(event_type) { diff --git a/components/esp_netif/test/test_esp_netif.c b/components/esp_netif/test/test_esp_netif.c index 342018a325..be1c99798c 100644 --- a/components/esp_netif/test/test_esp_netif.c +++ b/components/esp_netif/test/test_esp_netif.c @@ -3,6 +3,8 @@ #include "esp_netif.h" #include "esp_wifi.h" #include "nvs_flash.h" +#include "esp_wifi_netif.h" +#include TEST_CASE("esp_netif: init and destroy", "[esp_netif]") { @@ -187,3 +189,39 @@ TEST_CASE("esp_netif: test dhcp state transitions for mesh netifs", "[esp_netif] TEST_ASSERT(esp_wifi_deinit() == ESP_OK); nvs_flash_deinit(); } + +TEST_CASE("esp_netif: create custom wifi interfaces", "[esp_netif][leaks=0]") +{ + esp_netif_t *ap = NULL; + esp_netif_t *sta = NULL; + uint8_t configured_mac[6] = {1, 2, 3, 4, 5, 6}; + uint8_t actual_mac[6] = { 0 }; + + // create customized station + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA(); + esp_netif_config.if_desc = "custom wifi station"; + esp_netif_config.route_prio = 1; + sta = esp_netif_create_wifi(WIFI_IF_STA, &esp_netif_config); + TEST_ASSERT_NOT_NULL(sta); + TEST_ASSERT_EQUAL_STRING("custom wifi station", esp_netif_get_desc(sta)); + TEST_ASSERT_EQUAL(1, esp_netif_get_route_prio(sta)); + + // create customized access point + esp_netif_inherent_config_t esp_netif_config2 = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP(); + esp_netif_config2.if_desc = "custom wifi ap"; + esp_netif_config2.route_prio = 10; + memcpy(esp_netif_config2.mac, configured_mac, 6); + + ap = esp_netif_create_wifi(WIFI_IF_AP, &esp_netif_config2); + TEST_ASSERT_NOT_NULL(ap); + TEST_ASSERT_EQUAL_STRING( "custom wifi ap", esp_netif_get_desc(ap)); + TEST_ASSERT_EQUAL(10, esp_netif_get_route_prio(ap)); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_get_mac(ap, actual_mac)); + TEST_ASSERT_EQUAL_HEX8_ARRAY(configured_mac, actual_mac, 6); + + esp_wifi_destroy_if_driver(esp_netif_get_io_driver(ap)); + esp_wifi_destroy_if_driver(esp_netif_get_io_driver(sta)); + esp_netif_destroy(ap); + esp_netif_destroy(sta); +} + diff --git a/components/esp_wifi/include/esp_wifi_default.h b/components/esp_wifi/include/esp_wifi_default.h index 614a4ff9fd..4ce7f8b28e 100644 --- a/components/esp_wifi/include/esp_wifi_default.h +++ b/components/esp_wifi/include/esp_wifi_default.h @@ -81,6 +81,18 @@ esp_netif_t* esp_netif_create_default_wifi_ap(void); */ esp_netif_t* esp_netif_create_default_wifi_sta(void); +/** + * @brief Creates esp_netif WiFi object based on the custom configuration. + * + * @attention This API DOES NOT register default handlers! + * + * @param[in] wifi_if type of wifi interface + * @param[in] esp_netif_config inherent esp-netif configuration pointer + * + * @return pointer to esp-netif instance + */ +esp_netif_t* esp_netif_create_wifi(wifi_interface_t wifi_if, esp_netif_inherent_config_t *esp_netif_config); + /** * @brief Creates default STA and AP network interfaces for esp-mesh. * diff --git a/components/esp_wifi/src/wifi_default.c b/components/esp_wifi/src/wifi_default.c index d5b1c89299..7fb4b91142 100644 --- a/components/esp_wifi/src/wifi_default.c +++ b/components/esp_wifi/src/wifi_default.c @@ -272,22 +272,23 @@ static esp_err_t create_and_attach(wifi_interface_t wifi_if, esp_netif_t* esp_ne return esp_netif_attach(esp_netif, driver); } -esp_err_t esp_netif_attach_wifi_station(esp_netif_t *esp_netif) +static inline esp_err_t esp_netif_attach_wifi(esp_netif_t *esp_netif, wifi_interface_t wifi_if) { - if (esp_netif == NULL) { + if (esp_netif == NULL || (wifi_if != WIFI_IF_STA && wifi_if != WIFI_IF_AP)) { return ESP_ERR_INVALID_ARG; } - s_wifi_netifs[WIFI_IF_STA] = esp_netif; - return create_and_attach(WIFI_IF_STA, esp_netif); + s_wifi_netifs[wifi_if] = esp_netif; + return create_and_attach(wifi_if, esp_netif); +} + +esp_err_t esp_netif_attach_wifi_station(esp_netif_t *esp_netif) +{ + return esp_netif_attach_wifi(esp_netif, WIFI_IF_STA); } esp_err_t esp_netif_attach_wifi_ap(esp_netif_t *esp_netif) { - if (esp_netif == NULL) { - return ESP_ERR_INVALID_ARG; - } - s_wifi_netifs[WIFI_IF_AP] = esp_netif; - return create_and_attach(WIFI_IF_AP, esp_netif); + return esp_netif_attach_wifi(esp_netif, WIFI_IF_AP); } @@ -321,6 +322,28 @@ esp_netif_t* esp_netif_create_default_wifi_sta(void) return netif; } +/** + * @brief User init custom wifi interface + */ +esp_netif_t* esp_netif_create_wifi(wifi_interface_t wifi_if, esp_netif_inherent_config_t *esp_netif_config) +{ + esp_netif_config_t cfg = { + .base = esp_netif_config + }; + if (wifi_if == WIFI_IF_STA) { + cfg.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA; + } else if (wifi_if == WIFI_IF_AP) { + cfg.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP; + } else { + return NULL; + } + + esp_netif_t *netif = esp_netif_new(&cfg); + assert(netif); + esp_netif_attach_wifi(netif, wifi_if); + return netif; +} + /** * @brief Creates mesh network interfaces based on default STA and AP, * but without DHCP, this is to be enabled separately only on root node diff --git a/components/wpa_supplicant/include/esp_supplicant/esp_wps.h b/components/wpa_supplicant/include/esp_supplicant/esp_wps.h index c06ae2e368..76c96730cd 100644 --- a/components/wpa_supplicant/include/esp_supplicant/esp_wps.h +++ b/components/wpa_supplicant/include/esp_supplicant/esp_wps.h @@ -19,6 +19,7 @@ #include #include "esp_err.h" #include "esp_wifi_crypto_types.h" +#include "esp_compiler.h" #ifdef __cplusplus extern "C" { @@ -71,20 +72,13 @@ typedef struct { wps_factory_information_t factory_info; } esp_wps_config_t; -/* C & C++ compilers have different rules about C99-style named initializers */ -#ifdef __cplusplus -#define WPS_AGG(X) { X } -#else -#define WPS_AGG(X) X -#endif - #define WPS_CONFIG_INIT_DEFAULT(type) { \ .wps_type = type, \ .factory_info = { \ - WPS_AGG( .manufacturer = "ESPRESSIF" ), \ - WPS_AGG( .model_number = "ESP32" ), \ - WPS_AGG( .model_name = "ESPRESSIF IOT" ), \ - WPS_AGG( .device_name = "ESP STATION" ), \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(manufacturer, "ESPRESSIF") \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(model_number, "ESP32") \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(model_name, "ESPRESSIF IOT") \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(device_name, "ESP STATION") \ } \ } diff --git a/tools/test_apps/protocols/esp_netif/build_config/CMakeLists.txt b/tools/test_apps/protocols/esp_netif/build_config/CMakeLists.txt new file mode 100644 index 0000000000..e73e4a9121 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(esp_netif_build_config) diff --git a/tools/test_apps/protocols/esp_netif/build_config/README.md b/tools/test_apps/protocols/esp_netif/build_config/README.md new file mode 100644 index 0000000000..d08acda7f3 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/README.md @@ -0,0 +1,11 @@ +# Build only test for C++/C configuration + +This test application aims to exercise different configuration options using standard espressif initialization pattern: +``` +component_config cfg = COMPONENT_DEFAULT_CFG(); +cfg.member1 = custom_config_for_member1; +... +cfg.memberN = custom_config_for_memberN; +esp_err_t = component_init(cfg); +``` +To be build with both C++ and C compilers. \ No newline at end of file diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/CMakeLists.txt b/tools/test_apps/protocols/esp_netif/build_config/main/CMakeLists.txt new file mode 100644 index 0000000000..f8f294e946 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "netif_init_c99.c" "main.cpp" "netif_init_cpp.cpp" + INCLUDE_DIRS ".") \ No newline at end of file diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h b/tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h new file mode 100644 index 0000000000..06e68f04d4 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h @@ -0,0 +1,30 @@ +#pragma once + +#include "esp_compiler.h" + +typedef struct { + const char * char_star; + const char char_array[10]; + int x; + float y; + struct var_struct_t { + } var_struct; +} g_netif_test_struct_t; + +#define NETIF_TEST_STRUCT_EMPTY() \ + { \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(char_star) \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(char_array) \ + .x = 0, \ + .y = 0.0, \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(var_struct) \ + } + +#define NETIF_TEST_STRUCT_DEFAULT() \ + { \ + .char_star = "Espressif", \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(char_array, "Espressif") \ + .x = 42, \ + .y = 42.192, \ + ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(var_struct) \ + } diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/main.cpp b/tools/test_apps/protocols/esp_netif/build_config/main/main.cpp new file mode 100644 index 0000000000..374ff4295e --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/main.cpp @@ -0,0 +1,33 @@ +/* Test only application + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include "esp_system.h" +#include "esp_log.h" +#include "nvs_flash.h" + +static const char *TAG = "build only test"; + +extern "C" void esp_netif_compile_test_c99(); +void esp_netif_compile_test_cpp(void); + +extern "C" void app_main(void) +{ + esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } + ESP_ERROR_CHECK(ret); + + ESP_LOGE(TAG, "This is app is test only! It is not supposed to be executed!"); + // Calling CPP initialization tests + esp_netif_compile_test_cpp(); + // Calling C initialization tests + esp_netif_compile_test_c99(); +} \ No newline at end of file diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_c99.c b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_c99.c new file mode 100644 index 0000000000..f2fe9f805f --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_c99.c @@ -0,0 +1,80 @@ +/* Test only application + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include "esp_system.h" +#include "esp_wifi.h" +#include "esp_event.h" +#include "esp_log.h" +#include "init_macro.h" +#include "esp_wps.h" + + +static void s_init_wifi_netif(esp_netif_inherent_config_t* esp_netif_config) +{ + esp_netif_config->if_desc = "custom wifi station"; + esp_netif_config->route_prio = 1; + esp_netif_create_wifi(WIFI_IF_STA, esp_netif_config); + esp_wifi_set_default_wifi_sta_handlers(); +} + +static void s_use_test_config_struct(g_netif_test_struct_t* cfg) +{ + printf("%s\n", cfg->char_star); +} + +static void test_wifi_init_custom(void) +{ + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA(); + s_init_wifi_netif(&esp_netif_config); + } + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP(); + s_init_wifi_netif(&esp_netif_config); + } + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); + s_init_wifi_netif(&esp_netif_config); + } + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_PPP(); + s_init_wifi_netif(&esp_netif_config); + } +} + +static void test_common_init_field(void) +{ + { + g_netif_test_struct_t cfg = NETIF_TEST_STRUCT_EMPTY(); + s_use_test_config_struct(&cfg); + } + { + g_netif_test_struct_t cfg = NETIF_TEST_STRUCT_DEFAULT(); + s_use_test_config_struct(&cfg); + } +} + +static void test_wps_init(void) +{ + esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_TYPE_DISABLE); + ESP_ERROR_CHECK(esp_wifi_wps_enable(&config)); + ESP_ERROR_CHECK(esp_wifi_wps_start(0)); +} + + +void esp_netif_compile_test_c99(void) +{ + test_wifi_init_custom(); + test_common_init_field(); + test_wps_init(); +} diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_cpp.cpp b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_cpp.cpp new file mode 100644 index 0000000000..296157c4d6 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_cpp.cpp @@ -0,0 +1,75 @@ +/* Test only application + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ + +#include +#include "esp_system.h" +#include "esp_wifi.h" +#include "esp_event.h" +#include "init_macro.h" +#include "esp_wps.h" + +static void s_init_wifi_netif(esp_netif_inherent_config_t& esp_netif_config) +{ + esp_netif_config.if_desc = "custom wifi station"; + esp_netif_config.route_prio = 1; + esp_netif_create_wifi(WIFI_IF_STA, &esp_netif_config); + esp_wifi_set_default_wifi_sta_handlers(); +} + +static void s_use_test_config_struct(g_netif_test_struct_t& cfg) +{ + printf("%s\n", cfg.char_star); +} + +static void test_wifi_init_custom(void) +{ + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA(); + s_init_wifi_netif(esp_netif_config); + } + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP(); + s_init_wifi_netif(esp_netif_config); + } + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH(); + s_init_wifi_netif(esp_netif_config); + } + + { + esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_PPP(); + s_init_wifi_netif(esp_netif_config); + } +} + +static void test_common_init_field(void) +{ + { + g_netif_test_struct_t cfg = NETIF_TEST_STRUCT_EMPTY(); + s_use_test_config_struct(cfg); + } +} + +static void test_wps_init(void) +{ + esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_TYPE_DISABLE); + ESP_ERROR_CHECK(esp_wifi_wps_enable(&config)); + ESP_ERROR_CHECK(esp_wifi_wps_start(0)); +} + + +void esp_netif_compile_test_cpp(void) +{ + test_wifi_init_custom(); + test_common_init_field(); + test_wps_init(); +} \ No newline at end of file