]> granicus.if.org Git - esp-idf/commitdiff
tcpip_adapter: Decompose tcpip_adapter_start() into interface specification options
authorKedar Sovani <kedars@gmail.com>
Tue, 8 Aug 2017 04:48:14 +0000 (10:18 +0530)
committerKedar Sovani <kedars@gmail.com>
Wed, 16 Aug 2017 10:24:29 +0000 (15:54 +0530)
Since only the used interface's start function gets called, it pulls
in only the functions that are required in the current application,
thereby saving footprint.

components/esp32/event_default_handlers.c
components/tcpip_adapter/include/tcpip_adapter.h
components/tcpip_adapter/tcpip_adapter_lwip.c

index 34a0ddcb4d400ec395cf88cd51b681ba49bf3c18..d08fe43e7cb57c700dfd9fca4af2686ce9f8dd8c 100644 (file)
@@ -103,7 +103,7 @@ esp_err_t system_event_eth_start_handle_default(system_event_t *event)
 
     esp_eth_get_mac(eth_mac);
     tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &eth_ip);
-    tcpip_adapter_start(TCPIP_ADAPTER_IF_ETH, eth_mac, &eth_ip);
+    tcpip_adapter_eth_start(eth_mac, &eth_ip);
 
     return ESP_OK;
 }
@@ -174,7 +174,7 @@ esp_err_t system_event_ap_start_handle_default(system_event_t *event)
     WIFI_API_CALL_CHECK("esp_wifi_mac_get",  esp_wifi_get_mac(ESP_IF_WIFI_AP, ap_mac), ESP_OK);
 
     tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip);
-    tcpip_adapter_start(TCPIP_ADAPTER_IF_AP, ap_mac, &ap_ip);
+    tcpip_adapter_ap_start(ap_mac, &ap_ip);
 
     return ESP_OK;
 }
@@ -195,7 +195,7 @@ esp_err_t system_event_sta_start_handle_default(system_event_t *event)
 
     WIFI_API_CALL_CHECK("esp_wifi_mac_get",  esp_wifi_get_mac(ESP_IF_WIFI_STA, sta_mac), ESP_OK);
     tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
-    tcpip_adapter_start(TCPIP_ADAPTER_IF_STA, sta_mac, &sta_ip);
+    tcpip_adapter_sta_start(sta_mac, &sta_ip);
 
     return ESP_OK;
 }
index f1a0a9e2f89ef0179ea6d89b8e96ca3ef3cc3689..6d99b4a81146a9f9f7b3db431365755cc875f202 100644 (file)
@@ -177,13 +177,38 @@ typedef struct tcpip_adapter_api_msg_s {
 void tcpip_adapter_init(void);
 
 /**
- * @brief  Start an interface with specific MAC and IP
+ * @brief  Start the ethernet interface with specific MAC and IP
  *
- * softAP or station interface will be initialized, connect WiFi stack with TCPIP stack.
+ * @param[in]  mac: set MAC address of this interface
+ * @param[in]  ip_info: set IP address of this interface
+ *
+ * @return ESP_OK
+ *         ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
+ *         ESP_ERR_NO_MEM
+ */
+esp_err_t tcpip_adapter_eth_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);
+
+/**
+ * @brief  Start the Wi-Fi station interface with specific MAC and IP
+ *
+ * Station interface will be initialized, connect WiFi stack with TCPIP stack.
+ *
+ * @param[in]  mac: set MAC address of this interface
+ * @param[in]  ip_info: set IP address of this interface
+ *
+ * @return ESP_OK
+ *         ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
+ *         ESP_ERR_NO_MEM
+ */
+esp_err_t tcpip_adapter_sta_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);
+
+/**
+ * @brief  Start the Wi-Fi AP interface with specific MAC and IP
+ *
+ * softAP interface will be initialized, connect WiFi stack with TCPIP stack.
  *
- * For softAP interface, DHCP server will be started automatically.
+ * DHCP server will be started automatically.
  *
- * @param[in]  tcpip_if: the interface which we will start
  * @param[in]  mac: set MAC address of this interface
  * @param[in]  ip_info: set IP address of this interface
  *
@@ -191,7 +216,7 @@ void tcpip_adapter_init(void);
  *         ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
  *         ESP_ERR_NO_MEM
  */
-esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);
+esp_err_t tcpip_adapter_ap_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);
 
 /**
  * @brief  Stop an interface
index 37be2bd44c278b3853bafaee8683f16b008c4a7f..372c6d3eecf3f11740595f33d476ee455d5b2b67 100644 (file)
@@ -40,6 +40,7 @@
 static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX];
 static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX];
 static tcpip_adapter_ip6_info_t esp_ip6[TCPIP_ADAPTER_IF_MAX];
+static netif_init_fn esp_netif_init_fn[TCPIP_ADAPTER_IF_MAX];
 
 static tcpip_adapter_dhcp_status_t dhcps_status = TCPIP_ADAPTER_DHCP_INIT;
 static tcpip_adapter_dhcp_status_t dhcpc_status[TCPIP_ADAPTER_IF_MAX] = {TCPIP_ADAPTER_DHCP_INIT};
@@ -96,22 +97,12 @@ void tcpip_adapter_init(void)
     }
 }
 
-static netif_init_fn tcpip_if_to_netif_init_fn(tcpip_adapter_if_t tcpip_if)
+static inline netif_init_fn tcpip_if_to_netif_init_fn(tcpip_adapter_if_t tcpip_if)
 {
-    switch(tcpip_if) {
-#ifdef CONFIG_WIFI_ENABLED
-    case TCPIP_ADAPTER_IF_AP:
-        return wlanif_init_ap;
-    case TCPIP_ADAPTER_IF_STA:
-        return wlanif_init_sta;
-#endif
-#ifdef CONFIG_ETHERNET
-        case TCPIP_ADAPTER_IF_ETH:
-            return ethernetif_init;
-#endif
-        default:
-            return NULL;
-    }
+     if (tcpip_if < TCPIP_ADAPTER_IF_MAX)
+         return esp_netif_init_fn[tcpip_if];
+     else
+         return NULL;
 }
 
 static int tcpip_adapter_ipc_check(tcpip_adapter_api_msg_t *msg)
@@ -181,6 +172,24 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_a
     return ESP_OK;
 }
 
+esp_err_t tcpip_adapter_eth_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info)
+{
+     esp_netif_init_fn[TCPIP_ADAPTER_IF_ETH] = ethernetif_init;
+     return tcpip_adapter_start(TCPIP_ADAPTER_IF_ETH, mac, ip_info);
+}
+
+esp_err_t tcpip_adapter_sta_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info)
+{
+     esp_netif_init_fn[TCPIP_ADAPTER_IF_STA] = wlanif_init_sta;
+     return tcpip_adapter_start(TCPIP_ADAPTER_IF_STA, mac, ip_info);
+}
+
+esp_err_t tcpip_adapter_ap_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info)
+{
+     esp_netif_init_fn[TCPIP_ADAPTER_IF_AP] = wlanif_init_ap;
+     return tcpip_adapter_start(TCPIP_ADAPTER_IF_AP, mac, ip_info);
+}
+
 static esp_err_t tcpip_adapter_start_api(tcpip_adapter_api_msg_t * msg)
 {
     return tcpip_adapter_start(msg->tcpip_if, msg->mac, msg->ip_info);