tcpip_adapter: Decompose tcpip_adapter_start() into interface specification options

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.
This commit is contained in:
Kedar Sovani 2017-08-08 10:18:14 +05:30
parent 159e7e81b4
commit a24130b390
3 changed files with 59 additions and 25 deletions

View 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;
}

View file

@ -177,13 +177,8 @@ 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.
*
* For softAP interface, 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 +186,37 @@ 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_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.
*
* DHCP server will be started automatically.
*
* @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_ap_start(uint8_t *mac, tcpip_adapter_ip_info_t *ip_info);
/**
* @brief Stop an interface

View 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);