Bladeren bron

esp_netif: Add CONFIG_PPP_SUPPORT and CONFIG_LWIP_SLIP_SUPPORT to sperate the code

yuanjm 4 jaren geleden
bovenliggende
commit
00d84a3bb2

+ 29 - 11
components/esp_netif/CMakeLists.txt

@@ -1,12 +1,30 @@
-idf_component_register(SRCS "esp_netif_handlers.c"
-                            "esp_netif_objects.c"
-                            "esp_netif_defaults.c"
-                            "lwip/esp_netif_lwip.c"
-                            "lwip/esp_netif_lwip_ppp.c"
-                            "lwip/esp_netif_lwip_slip.c"
-                            "loopback/esp_netif_loopback.c"
-                            "lwip/esp_netif_lwip_defaults.c"
-                            "lwip/esp_netif_sta_list.c"
-                    INCLUDE_DIRS include
-                    PRIV_INCLUDE_DIRS lwip private_include
+set(srcs
+    "esp_netif_handlers.c"
+    "esp_netif_objects.c"
+    "esp_netif_defaults.c"
+    "lwip/esp_netif_lwip.c"
+    "lwip/esp_netif_lwip_defaults.c"
+    "lwip/esp_netif_sta_list.c")
+
+set(include_dirs "include")
+set(priv_include_dirs "lwip" "private_include")
+
+if(CONFIG_LWIP_SLIP_SUPPORT)
+list(APPEND srcs
+    "lwip/esp_netif_lwip_slip.c")
+endif()
+
+if(CONFIG_PPP_SUPPORT)
+list(APPEND srcs
+    "lwip/esp_netif_lwip_ppp.c")
+endif()
+
+if(CONFIG_LWIP_NETIF_LOOPBACK)
+list(APPEND srcs
+    "loopback/esp_netif_loopback.c")
+endif()
+
+idf_component_register(SRCS "${srcs}"
+                    INCLUDE_DIRS "${include_dirs}"
+                    PRIV_INCLUDE_DIRS "${priv_include_dirs}"
                     REQUIRES lwip esp_eth tcpip_adapter)

+ 12 - 0
components/esp_netif/component.mk

@@ -4,3 +4,15 @@
 COMPONENT_ADD_INCLUDEDIRS := include
 COMPONENT_PRIV_INCLUDEDIRS := private_include lwip
 COMPONENT_SRCDIRS := . lwip loopback
+
+ifndef CONFIG_LWIP_SLIP_SUPPORT
+    COMPONENT_OBJEXCLUDE := lwip/esp_netif_lwip_slip.o
+endif
+
+ifndef CONFIG_PPP_SUPPORT
+    COMPONENT_OBJEXCLUDE += lwip/esp_netif_lwip_ppp.o
+endif
+
+ifndef CONFIG_LWIP_NETIF_LOOPBACK
+    COMPONENT_OBJEXCLUDE += loopback/esp_netif_loopback.o
+endif

+ 30 - 3
components/esp_netif/lwip/esp_netif_lwip.c

@@ -60,8 +60,11 @@
 /**
  * @brief macros to check netif related data to evaluate interface type
  */
+#if CONFIG_PPP_SUPPORT || CONFIG_LWIP_SLIP_SUPPORT
 #define _IS_NETIF_ANY_POINT2POINT_TYPE(netif) (netif->related_data && netif->related_data->is_point2point)
-
+#else
+#define _IS_NETIF_ANY_POINT2POINT_TYPE(netif) false
+#endif
 #define _RUN_IN_LWIP_TASK_IF_SUPPORTED(function, netif, param) \
 {                                                              \
     if (_IS_NETIF_ANY_POINT2POINT_TYPE(netif)) {               \
@@ -169,7 +172,9 @@ static esp_netif_t* esp_netif_is_active(esp_netif_t *arg)
 static void esp_netif_set_default_netif(esp_netif_t *esp_netif)
 {
     if (_IS_NETIF_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) {
+#if CONFIG_PPP_SUPPORT
         esp_netif_ppp_set_default_netif(esp_netif->netif_handle);
+#endif
     } else {
         netif_set_default(esp_netif->netif_handle);
     }
@@ -388,6 +393,7 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_
     // Install network stack functions -- connects netif and L3 stack
     const esp_netif_netstack_config_t *esp_netif_stack_config = cfg->stack;
     if (cfg->base->flags & ESP_NETIF_FLAG_IS_PPP) {
+#if CONFIG_PPP_SUPPORT
         esp_netif->related_data = esp_netif_new_ppp(esp_netif, esp_netif_stack_config);
         if (esp_netif->related_data == NULL) {
             return ESP_ERR_ESP_NETIF_INIT_FAILED;
@@ -395,8 +401,11 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_
         esp_netif->lwip_input_fn = esp_netif_stack_config->lwip_ppp.input_fn;
         // Make the netif handle (used for tcpip input function) the ppp_netif
         esp_netif->netif_handle = esp_netif->related_data;
-
+#else
+        LOG_NETIF_DISABLED_AND_DO("PPP", return ESP_ERR_NOT_SUPPORTED);
+#endif
     } else if (cfg->base->flags & ESP_NETIF_FLAG_IS_SLIP) {
+#if CONFIG_LWIP_SLIP_SUPPORT
         esp_netif->related_data = esp_netif_new_slip(esp_netif, esp_netif_stack_config);
         if (esp_netif->related_data == NULL) {
             return ESP_ERR_ESP_NETIF_INIT_FAILED;
@@ -409,7 +418,9 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_
         }
         // Make the netif handle (used for tcpip input function) the esp_netif itself
         esp_netif->netif_handle = esp_netif;
-
+#else
+        LOG_NETIF_DISABLED_AND_DO("SLIP", return ESP_ERR_NOT_SUPPORTED);
+#endif
     } else {
         if (esp_netif_stack_config-> lwip.init_fn) {
             esp_netif->lwip_init_fn = esp_netif_stack_config->lwip.init_fn;
@@ -528,11 +539,15 @@ static esp_err_t esp_netif_lwip_add(esp_netif_t *esp_netif)
         }
     }
     if (esp_netif->flags & ESP_NETIF_FLAG_IS_PPP) {
+#if CONFIG_PPP_SUPPORT
         err_t err = esp_netif->lwip_init_fn(NULL);
         if (err != ERR_OK) {
             ESP_LOGE(TAG, "Init netif failed with  %d", err);
             return ESP_ERR_ESP_NETIF_INIT_FAILED;
         }
+#else
+        LOG_NETIF_DISABLED_AND_DO("PPP", return ESP_ERR_NOT_SUPPORTED);
+#endif
     }
 
     if (NULL == netif_add(esp_netif->lwip_netif, (struct ip4_addr*)&esp_netif->ip_info->ip,
@@ -547,9 +562,13 @@ static esp_err_t esp_netif_lwip_add(esp_netif_t *esp_netif)
 static void esp_netif_destroy_related(esp_netif_t *esp_netif)
 {
     if (_IS_NETIF_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) {
+#if CONFIG_PPP_SUPPORT
         esp_netif_destroy_ppp(esp_netif->related_data);
+#endif
     } else if (_IS_NETIF_POINT2POINT_TYPE(esp_netif, SLIP_LWIP_NETIF)) {
+#if CONFIG_LWIP_SLIP_SUPPORT
         esp_netif_destroy_slip(esp_netif->related_data);
+#endif
     }
 }
 
@@ -695,7 +714,9 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
     }
     struct netif *p_netif = esp_netif->lwip_netif;
     if (_IS_NETIF_POINT2POINT_TYPE(esp_netif, SLIP_LWIP_NETIF)) {
+#if CONFIG_LWIP_SLIP_SUPPORT
         esp_netif_start_slip(esp_netif);
+#endif
     }
     if (esp_netif->flags&ESP_NETIF_FLAG_AUTOUP) {
         ESP_LOGD(TAG, "%s Setting the lwip netif%p UP", __func__, p_netif);
@@ -752,12 +773,14 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
 esp_err_t esp_netif_start(esp_netif_t *esp_netif)
 {
     if (_IS_NETIF_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) {
+#if CONFIG_PPP_SUPPORT
         // No need to start PPP interface in lwip thread
         esp_err_t ret = esp_netif_start_ppp(esp_netif->related_data);
         if (ret == ESP_OK) {
             esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);
         }
         return ret;
+#endif
     }
     return esp_netif_lwip_ipc_call(esp_netif_start_api, esp_netif, NULL);
 }
@@ -805,19 +828,23 @@ static esp_err_t esp_netif_stop_api(esp_netif_api_msg_t *msg)
 esp_err_t esp_netif_stop(esp_netif_t *esp_netif)
 {
     if (_IS_NETIF_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) {
+#if CONFIG_PPP_SUPPORT
         // No need to stop PPP interface in lwip thread
         esp_err_t ret = esp_netif_stop_ppp(esp_netif->related_data);
         if (ret == ESP_OK) {
             esp_netif_update_default_netif(esp_netif, ESP_NETIF_STOPPED);;
         }
         return ret;
+#endif
     } else if (_IS_NETIF_POINT2POINT_TYPE(esp_netif, SLIP_LWIP_NETIF)) {
+#if CONFIG_LWIP_SLIP_SUPPORT
         // No need to stop PPP interface in lwip thread
         esp_err_t ret = esp_netif_stop_slip(esp_netif);
         if (ret == ESP_OK) {
             esp_netif_update_default_netif(esp_netif, ESP_NETIF_STOPPED);;
         }
         return ret;
+#endif
     }
     return esp_netif_lwip_ipc_call(esp_netif_stop_api, esp_netif, NULL);
 }

+ 4 - 0
components/esp_netif/lwip/esp_netif_lwip_internal.h

@@ -70,7 +70,11 @@ typedef struct esp_netif_ip_lost_timer_s {
 /**
  * @brief Check the netif if of a specific P2P type
  */
+#if CONFIG_PPP_SUPPORT || CONFIG_LWIP_SLIP_SUPPORT
 #define _IS_NETIF_POINT2POINT_TYPE(netif, type) (netif->related_data && netif->related_data->is_point2point && netif->related_data->netif_type == type)
+#else
+#define _IS_NETIF_POINT2POINT_TYPE(netif, type) false
+#endif
 
 /**
  * @brief Additional netif types when related data are needed

+ 0 - 40
components/esp_netif/lwip/esp_netif_lwip_ppp.c

@@ -32,8 +32,6 @@ ESP_EVENT_DEFINE_BASE(NETIF_PPP_STATUS);
 
 static const char *TAG = "esp-netif_lwip-ppp";
 
-#if PPPOS_SUPPORT
-
 /**
  * @brief internal lwip_ppp context struct extends the netif related data
  *        used to hold PPP netif related parameters
@@ -350,43 +348,5 @@ esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_confi
     obj->ppp_error_event_enabled = config->ppp_error_event_enabled;
     return ESP_OK;
 }
-#else  /* PPPOS_SUPPORT */
-
-typedef struct lwip_peer2peer_ctx lwip_peer2peer_ctx_t;
-
-/**
- * @brief If PPP not enabled in menuconfig, log the error and return appropriate code indicating failure
-*/
-#define LOG_PPP_DISABLED_AND_DO(action) \
-    {   \
-    ESP_LOGE(TAG, "%s not supported, please enable PPP in lwIP component configuration", __func__); \
-    action; \
-    }
-
-esp_err_t esp_netif_ppp_set_auth(esp_netif_t *netif, esp_netif_auth_type_t authtype, const char *user, const char *passwd)
-    LOG_PPP_DISABLED_AND_DO(return ESP_ERR_NOT_SUPPORTED)
-
-void esp_netif_ppp_set_default_netif(lwip_peer2peer_ctx_t* ppp_ctx)
-    LOG_PPP_DISABLED_AND_DO()
-
-lwip_peer2peer_ctx_t* esp_netif_new_ppp(esp_netif_t *esp_netif, const esp_netif_netstack_config_t *esp_netif_stack_config)
-    LOG_PPP_DISABLED_AND_DO(return NULL)
-
-esp_err_t esp_netif_start_ppp(lwip_peer2peer_ctx_t *ppp_ctx)
-    LOG_PPP_DISABLED_AND_DO(return ESP_ERR_NOT_SUPPORTED)
-
-void esp_netif_lwip_ppp_input(void *ppp_ctx, void *buffer, size_t len, void *eb)
-    LOG_PPP_DISABLED_AND_DO()
-
-esp_err_t esp_netif_stop_ppp(lwip_peer2peer_ctx_t *ppp_ctx)
-    LOG_PPP_DISABLED_AND_DO(return ESP_ERR_NOT_SUPPORTED)
-
-void esp_netif_destroy_ppp(lwip_peer2peer_ctx_t *ppp_ctx)
-    LOG_PPP_DISABLED_AND_DO()
-
-esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_config_t *config)
-    LOG_PPP_DISABLED_AND_DO(return ESP_ERR_NOT_SUPPORTED)
-
-#endif /* PPPOS_SUPPORT */
 
 #endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */

+ 0 - 25
components/esp_netif/lwip/esp_netif_lwip_slip.c

@@ -31,10 +31,8 @@
 
 #include <string.h>
 
-
 static const char *TAG = "esp-netif_lwip-slip";
 
-#if CONFIG_LWIP_SLIP_SUPPORT
 /**
  * @brief LWIP SLIP context object extends esp-netif related data
  */
@@ -312,28 +310,5 @@ void sio_send(uint8_t c, sio_fd_t fd)
         ESP_LOGD(TAG, "%s: uart_write_bytes error %i", __func__, ret);
     }
 }
-#else /* CONFIG_LWIP_SLIP_SUPPORT */
-typedef struct lwip_slip_ctx lwip_slip_ctx_t;
-
-/**
- * @brief If SLIP not enabled in menuconfig, log the error and return appropriate code indicating failure
-*/
-#define LOG_SLIP_DISABLED_AND_DO(action) \
-    {   \
-    ESP_LOGE(TAG, "%s not supported, please enable SLIP in lwIP component configuration", __func__); \
-    action; \
-    }
-
-netif_related_data_t * esp_netif_new_slip(esp_netif_t *esp_netif, const esp_netif_netstack_config_t *esp_netif_stack_config)
-    LOG_SLIP_DISABLED_AND_DO(return NULL)
 
-void esp_netif_destroy_slip(netif_related_data_t *slip)
-    LOG_SLIP_DISABLED_AND_DO()
-
-esp_err_t esp_netif_stop_slip(esp_netif_t *esp_netif)
-    LOG_SLIP_DISABLED_AND_DO(return ESP_ERR_NOT_SUPPORTED)
-
-esp_err_t esp_netif_start_slip(esp_netif_t *esp_netif)
-    LOG_SLIP_DISABLED_AND_DO(return ESP_ERR_NOT_SUPPORTED)
-#endif
 #endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */