]> granicus.if.org Git - esp-idf/commitdiff
optimize tcpip adapter layer
authorLiu Zhi Fu <liuzhifu@espressif.com>
Wed, 29 Mar 2017 03:07:41 +0000 (11:07 +0800)
committerLiu Zhi Fu <liuzhifu@espressif.com>
Sat, 1 Apr 2017 08:41:51 +0000 (16:41 +0800)
components/lwip/api/tcpip.c
components/tcpip_adapter/include/tcpip_adapter.h
components/tcpip_adapter/tcpip_adapter_lwip.c

index 8374c429cd161ce86469650ee7a49f9664e2aee6..ac6a711ee12a6c9128b2d16542395181ad67a65c 100755 (executable)
@@ -59,6 +59,7 @@
 static tcpip_init_done_fn tcpip_init_done;
 static void *tcpip_init_done_arg;
 static sys_mbox_t mbox;
+sys_thread_t g_lwip_task = NULL;
 
 #if LWIP_TCPIP_CORE_LOCKING
 /** The global semaphore to lock the stack. */
@@ -498,11 +499,11 @@ tcpip_init(tcpip_init_done_fn initfunc, void *arg)
 #endif /* LWIP_TCPIP_CORE_LOCKING */
 
 
-  sys_thread_t xLwipTaskHandle = sys_thread_new(TCPIP_THREAD_NAME
+  g_lwip_task = sys_thread_new(TCPIP_THREAD_NAME
                 , tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
 
   LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_task_hdlxxx : %x, prio:%d,stack:%d\n",
-                (u32_t)xLwipTaskHandle,TCPIP_THREAD_PRIO,TCPIP_THREAD_STACKSIZE));
+                (u32_t)g_lwip_task,TCPIP_THREAD_PRIO,TCPIP_THREAD_STACKSIZE));
 
 }
 
index 4f3b49ed270e8622ccb32370477a3f880b13db90..f1a0a9e2f89ef0179ea6d89b8e96ca3ef3cc3689 100644 (file)
@@ -136,6 +136,39 @@ typedef enum{
     TCPIP_ADAPTER_IP_REQUEST_RETRY_TIME         = 52,   /**< request IP address retry counter */
 } tcpip_adapter_option_id_t;
 
+struct tcpip_adapter_api_msg_s;
+typedef int (*tcpip_adapter_api_fn)(struct tcpip_adapter_api_msg_s *msg);
+typedef struct tcpip_adapter_api_msg_s {
+    int type;  /**< The first field MUST be int */
+    int ret;
+    tcpip_adapter_api_fn api_fn;
+    tcpip_adapter_if_t tcpip_if;
+    tcpip_adapter_ip_info_t *ip_info;
+    uint8_t *mac;
+    const char *hostname;
+} tcpip_adapter_api_msg_t;
+
+#define TCPIP_ADAPTER_TRHEAD_SAFE 1
+#define TCPIP_ADAPTER_IPC_LOCAL   0 
+#define TCPIP_ADAPTER_IPC_REMOTE  1
+
+#define TCPIP_ADAPTER_IPC_CALL(_if, _mac, _ip, _hostname, _fn) do {\
+    tcpip_adapter_api_msg_t msg;\
+    memset(&msg, 0, sizeof(msg));\
+    msg.tcpip_if = (_if);\
+    msg.mac      = (_mac);\
+    msg.ip_info  = (_ip);\
+    msg.hostname = (_hostname);\
+    msg.api_fn   = (_fn);\
+    if (TCPIP_ADAPTER_IPC_REMOTE == tcpip_adapter_ipc_check(&msg)) {\
+        ESP_LOGD(TAG, "check: remote, if=%d fn=%p\n", (_if), (_fn));\
+        return msg.ret;\
+    } else {\
+        ESP_LOGD(TAG, "check: local, if=%d fn=%p\n", (_if), (_fn));\
+    }\
+}while(0)
+
+
 /**
  * @brief  Initialize tcpip adapter
  *
index 7ee710f39a159dccd0fed2c20c1fb91a70283ac3..bc50c79b9765f968dde931565c6776a0105d683f 100644 (file)
@@ -25,6 +25,7 @@
 #include "lwip/ip_addr.h"
 #include "lwip/ip6_addr.h"
 #include "lwip/nd6.h"
+#include "lwip/priv/tcpip_priv.h"
 #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
 #include "lwip/dns.h"
 #endif
@@ -34,6 +35,7 @@
 #include "apps/dhcpserver.h"
 
 #include "esp_event.h"
+#include "esp_log.h"
 
 static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX];
 static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX];
@@ -41,13 +43,42 @@ static tcpip_adapter_ip6_info_t esp_ip6[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};
+static esp_err_t tcpip_adapter_start_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_stop_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_up_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_down_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_set_ip_info_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_create_ip6_linklocal_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_dhcps_start_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_dhcps_stop_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_dhcpc_start_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_dhcpc_stop_api(tcpip_adapter_api_msg_t * msg);
+static esp_err_t tcpip_adapter_set_hostname_api(tcpip_adapter_api_msg_t * msg);
+static sys_sem_t api_sync_sem = NULL;
+extern sys_thread_t g_lwip_task;
+
+#define TAG "tcpip_adapter"
+
+static void tcpip_adapter_api_cb(void* api_msg)
+{
+    tcpip_adapter_api_msg_t *msg = (tcpip_adapter_api_msg_t*)api_msg;
+
+    if (!msg || !msg->api_fn) {
+        ESP_LOGD(TAG, "null msg/api_fn");
+        return;
+    }
 
-#define TCPIP_ADAPTER_DEBUG(...)
-//#define TCPIP_ADAPTER_DEBUG printf
+    msg->ret = msg->api_fn(msg);
+    ESP_LOGD(TAG, "call api in lwip: ret=0x%x, give sem", msg->ret);
+    sys_sem_signal(&api_sync_sem);
+
+    return;
+}
 
 void tcpip_adapter_init(void)
 {
     static bool tcpip_inited = false;
+    int ret;
 
     if (tcpip_inited == false) {
         tcpip_inited = true;
@@ -57,6 +88,10 @@ void tcpip_adapter_init(void)
         IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].ip, 192, 168 , 4, 1);
         IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].gw, 192, 168 , 4, 1);
         IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].netmask, 255, 255 , 255, 0);
+        ret = sys_sem_new(&api_sync_sem, 0);
+        if (ERR_OK != ret) {
+            ESP_LOGD(TAG, "tcpip adatper api sync sem init fail");
+        }
     }
 }
 
@@ -77,10 +112,29 @@ static netif_init_fn tcpip_if_to_netif_init_fn(tcpip_adapter_if_t tcpip_if)
     }
 }
 
+static int tcpip_adapter_ipc_check(tcpip_adapter_api_msg_t *msg)
+{
+#if TCPIP_ADAPTER_TRHEAD_SAFE
+    xTaskHandle local_task = xTaskGetCurrentTaskHandle();
+
+    if (local_task == g_lwip_task) {
+        return TCPIP_ADAPTER_IPC_LOCAL;
+    }
+
+    tcpip_send_api_msg((tcpip_callback_fn)tcpip_adapter_api_cb, msg, &api_sync_sem);
+
+    return TCPIP_ADAPTER_IPC_REMOTE;
+#else
+    return TCPIP_ADAPTER_IPC_LOCAL;
+#endif
+}
+
 esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_adapter_ip_info_t *ip_info)
 {
     netif_init_fn netif_init;
 
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, mac, ip_info, 0, tcpip_adapter_start_api);
+
     if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || mac == NULL || ip_info == NULL) {
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
     }
@@ -103,7 +157,7 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_a
         if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
             dhcps_start(esp_netif[tcpip_if], ip_info->ip);
 
-            TCPIP_ADAPTER_DEBUG("dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n",
+            ESP_LOGD(TAG, "dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")",
                    IP2STR(&ip_info->ip), IP2STR(&ip_info->netmask), IP2STR(&ip_info->gw));
 
             dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
@@ -122,8 +176,15 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_a
     return ESP_OK;
 }
 
+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);
+}
+
 esp_err_t tcpip_adapter_stop(tcpip_adapter_if_t tcpip_if)
 {
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_stop_api);
+
     if (tcpip_if >= TCPIP_ADAPTER_IF_MAX) {
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
     }
@@ -162,8 +223,16 @@ esp_err_t tcpip_adapter_stop(tcpip_adapter_if_t tcpip_if)
     return ESP_OK;
 }
 
+static esp_err_t tcpip_adapter_stop_api(tcpip_adapter_api_msg_t * msg)
+{
+    msg->ret = tcpip_adapter_stop(msg->tcpip_if);
+    return msg->ret;
+}
+
 esp_err_t tcpip_adapter_up(tcpip_adapter_if_t tcpip_if)
 {
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_up_api);
+
     if (tcpip_if == TCPIP_ADAPTER_IF_STA ||  tcpip_if == TCPIP_ADAPTER_IF_ETH ) {
         if (esp_netif[tcpip_if] == NULL) {
             return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
@@ -177,8 +246,16 @@ esp_err_t tcpip_adapter_up(tcpip_adapter_if_t tcpip_if)
     return ESP_OK;
 }
 
+static esp_err_t tcpip_adapter_up_api(tcpip_adapter_api_msg_t * msg)
+{
+    msg->ret = tcpip_adapter_up(msg->tcpip_if);
+    return msg->ret;
+}
+
 esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if)
 {
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_down_api);
+
     if (tcpip_if == TCPIP_ADAPTER_IF_STA ||  tcpip_if == TCPIP_ADAPTER_IF_ETH ) {
         if (esp_netif[tcpip_if] == NULL) {
             return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
@@ -203,6 +280,11 @@ esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if)
     return ESP_OK;
 }
 
+static esp_err_t tcpip_adapter_down_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_down(msg->tcpip_if);
+}
+
 esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info)
 {
     struct netif *p_netif;
@@ -233,6 +315,8 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i
     struct netif *p_netif;
     tcpip_adapter_dhcp_status_t status;
 
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, ip_info, 0, tcpip_adapter_set_ip_info_api);
+
     if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || ip_info == NULL ||
             ip4_addr_isany_val(ip_info->ip) || ip4_addr_isany_val(ip_info->netmask)) {
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
@@ -271,12 +355,17 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i
     return ESP_OK;
 }
 
+static esp_err_t tcpip_adapter_set_ip_info_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_set_ip_info(msg->tcpip_if, msg->ip_info);
+}
+
 static void tcpip_adapter_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
 {
     tcpip_adapter_ip6_info_t *ip6_info;
 
     if (!p_netif) {
-        TCPIP_ADAPTER_DEBUG("null p_netif=%p\n", p_netif);
+        ESP_LOGD(TAG, "null p_netif=%p", p_netif);
         return;
     }
 
@@ -302,6 +391,8 @@ esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if)
 {
     struct netif *p_netif;
 
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_create_ip6_linklocal_api);
+
     if (tcpip_if >= TCPIP_ADAPTER_IF_MAX) {
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
     }
@@ -317,6 +408,11 @@ esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if)
     }
 }
 
+static esp_err_t tcpip_adapter_create_ip6_linklocal_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_create_ip6_linklocal(msg->tcpip_if);
+}
+
 esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6)
 {
     struct netif *p_netif;
@@ -474,9 +570,11 @@ esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adap
 
 esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if)
 {
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_dhcps_start_api);
+
     /* only support ap now */
     if (tcpip_if != TCPIP_ADAPTER_IF_AP || tcpip_if >= TCPIP_ADAPTER_IF_MAX) {
-        TCPIP_ADAPTER_DEBUG("dhcp server invalid if=%d\n", tcpip_if);
+        ESP_LOGD(TAG, "dhcp server invalid if=%d", tcpip_if);
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
     }
 
@@ -488,24 +586,32 @@ esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if)
             tcpip_adapter_get_ip_info(ESP_IF_WIFI_AP, &default_ip);
             dhcps_start(p_netif, default_ip.ip);
             dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
-            TCPIP_ADAPTER_DEBUG("dhcp server start successfully\n");
+            ESP_LOGD(TAG, "dhcp server start successfully");
             return ESP_OK;
         } else {
-            TCPIP_ADAPTER_DEBUG("dhcp server re init\n");
+            ESP_LOGD(TAG, "dhcp server re init");
             dhcps_status = TCPIP_ADAPTER_DHCP_INIT;
             return ESP_OK;
         }
     }
 
-    TCPIP_ADAPTER_DEBUG("dhcp server already start\n");
+    ESP_LOGD(TAG, "dhcp server already start");
     return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED;
 }
 
+static esp_err_t tcpip_adapter_dhcps_start_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_dhcps_start(msg->tcpip_if);
+}
+
+
 esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if)
 {
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_dhcps_stop_api);
+
     /* only support ap now */
     if (tcpip_if != TCPIP_ADAPTER_IF_AP || tcpip_if >= TCPIP_ADAPTER_IF_MAX) {
-        TCPIP_ADAPTER_DEBUG("dhcp server invalid if=%d\n", tcpip_if);
+        ESP_LOGD(TAG, "dhcp server invalid if=%d", tcpip_if);
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
     }
 
@@ -515,19 +621,24 @@ esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if)
         if (p_netif != NULL) {
             dhcps_stop(p_netif);
         } else {
-            TCPIP_ADAPTER_DEBUG("dhcp server if not ready\n");
+            ESP_LOGD(TAG, "dhcp server if not ready");
             return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
         }
     } else if (dhcps_status == TCPIP_ADAPTER_DHCP_STOPPED) {
-        TCPIP_ADAPTER_DEBUG("dhcp server already stoped\n");
+        ESP_LOGD(TAG, "dhcp server already stoped");
         return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED;
     }
 
-    TCPIP_ADAPTER_DEBUG("dhcp server stop successfully\n");
+    ESP_LOGD(TAG, "dhcp server stop successfully");
     dhcps_status = TCPIP_ADAPTER_DHCP_STOPPED;
     return ESP_OK;
 }
 
+static esp_err_t tcpip_adapter_dhcps_stop_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_dhcps_stop(msg->tcpip_if);
+}
+
 esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode_t opt_op, tcpip_adapter_option_id_t opt_id, void *opt_val, uint32_t opt_len)
 {
     // TODO: when dhcp request timeout,change the retry count
@@ -537,12 +648,12 @@ esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode_t opt_op, tcpip_a
 static void tcpip_adapter_dhcpc_cb(struct netif *netif)
 {
     if (!netif) {
-        TCPIP_ADAPTER_DEBUG("null netif=%p\n", netif);
+        ESP_LOGD(TAG, "null netif=%p", netif);
         return;
     }
 
     if (netif != esp_netif[TCPIP_ADAPTER_IF_STA] && netif != esp_netif[TCPIP_ADAPTER_IF_ETH]) {
-        TCPIP_ADAPTER_DEBUG("err netif=%p\n", netif);
+        ESP_LOGD(TAG, "err netif=%p", netif);
         return;
     }
 
@@ -575,7 +686,7 @@ static void tcpip_adapter_dhcpc_cb(struct netif *netif)
 
             esp_event_send(&evt);
         } else {
-            TCPIP_ADAPTER_DEBUG("ip unchanged\n");
+            ESP_LOGD(TAG, "ip unchanged");
         }
     }
 
@@ -591,9 +702,11 @@ esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adap
 
 esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if)
 {
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_dhcpc_start_api);
+
     /* only support sta now, need to support ethernet */
     if ((tcpip_if != TCPIP_ADAPTER_IF_STA && tcpip_if != TCPIP_ADAPTER_IF_ETH)  || tcpip_if >= TCPIP_ADAPTER_IF_MAX) {
-        TCPIP_ADAPTER_DEBUG("dhcp client invalid if=%d\n", tcpip_if);
+        ESP_LOGD(TAG, "dhcp client invalid if=%d", tcpip_if);
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
     }
 
@@ -606,42 +719,49 @@ esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if)
 
         if (p_netif != NULL) {
             if (netif_is_up(p_netif)) {
-                TCPIP_ADAPTER_DEBUG("dhcp client init ip/mask/gw to all-0\n");
+                ESP_LOGD(TAG, "dhcp client init ip/mask/gw to all-0");
                 ip_addr_set_zero(&p_netif->ip_addr);
                 ip_addr_set_zero(&p_netif->netmask);
                 ip_addr_set_zero(&p_netif->gw);
             } else {
-                TCPIP_ADAPTER_DEBUG("dhcp client re init\n");
+                ESP_LOGD(TAG, "dhcp client re init");
                 dhcpc_status[tcpip_if] = TCPIP_ADAPTER_DHCP_INIT;
                 return ESP_OK;
             }
 
             if (dhcp_start(p_netif) != ERR_OK) {
-                TCPIP_ADAPTER_DEBUG("dhcp client start failed\n");
+                ESP_LOGD(TAG, "dhcp client start failed");
                 return ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED;
             }
 
             dhcp_set_cb(p_netif, tcpip_adapter_dhcpc_cb);
 
-            TCPIP_ADAPTER_DEBUG("dhcp client start successfully\n");
+            ESP_LOGD(TAG, "dhcp client start successfully");
             dhcpc_status[tcpip_if] = TCPIP_ADAPTER_DHCP_STARTED;
             return ESP_OK;
         } else {
-            TCPIP_ADAPTER_DEBUG("dhcp client re init\n");
+            ESP_LOGD(TAG, "dhcp client re init");
             dhcpc_status[tcpip_if] = TCPIP_ADAPTER_DHCP_INIT;
             return ESP_OK;
         }
     }
 
-    TCPIP_ADAPTER_DEBUG("dhcp client already started\n");
+    ESP_LOGD(TAG, "dhcp client already started");
     return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED;
 }
 
+static esp_err_t tcpip_adapter_dhcpc_start_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_dhcpc_start(msg->tcpip_if);
+}
+
 esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if)
 {
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, 0, tcpip_adapter_dhcpc_stop_api);
+
     /* only support sta now, need to support ethernet */
     if (tcpip_if != TCPIP_ADAPTER_IF_STA || tcpip_if >= TCPIP_ADAPTER_IF_MAX) {
-        TCPIP_ADAPTER_DEBUG("dhcp client invalid if=%d\n", tcpip_if);
+        ESP_LOGD(TAG, "dhcp client invalid if=%d", tcpip_if);
         return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
     }
 
@@ -655,19 +775,24 @@ esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if)
             ip4_addr_set_zero(&esp_ip[tcpip_if].gw);
             ip4_addr_set_zero(&esp_ip[tcpip_if].netmask);
         } else {
-            TCPIP_ADAPTER_DEBUG("dhcp client if not ready\n");
+            ESP_LOGD(TAG, "dhcp client if not ready");
             return ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY;
         }
     } else if (dhcpc_status[tcpip_if] == TCPIP_ADAPTER_DHCP_STOPPED) {
-        TCPIP_ADAPTER_DEBUG("dhcp client already stoped\n");
+        ESP_LOGD(TAG, "dhcp client already stoped");
         return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED;
     }
 
-    TCPIP_ADAPTER_DEBUG("dhcp client stop successfully\n");
+    ESP_LOGD(TAG, "dhcp client stop successfully");
     dhcpc_status[tcpip_if] = TCPIP_ADAPTER_DHCP_STOPPED;
     return ESP_OK;
 }
 
+static esp_err_t tcpip_adapter_dhcpc_stop_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_dhcpc_stop(msg->tcpip_if);
+}
+
 esp_err_t tcpip_adapter_eth_input(void *buffer, uint16_t len, void *eb)
 {
     ethernetif_input(esp_netif[TCPIP_ADAPTER_IF_ETH], buffer, len);
@@ -730,6 +855,7 @@ esp_err_t tcpip_adapter_get_sta_list(wifi_sta_list_t *wifi_sta_list, tcpip_adapt
 esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *hostname)
 {
 #if LWIP_NETIF_HOSTNAME
+    TCPIP_ADAPTER_IPC_CALL(tcpip_if, 0, 0, hostname, tcpip_adapter_set_hostname_api);
     struct netif *p_netif;
     static char hostinfo[TCPIP_ADAPTER_IF_MAX][TCPIP_HOSTNAME_MAX_SIZE + 1];
 
@@ -755,6 +881,11 @@ esp_err_t tcpip_adapter_set_hostname(tcpip_adapter_if_t tcpip_if, const char *ho
 #endif
 }
 
+static esp_err_t tcpip_adapter_set_hostname_api(tcpip_adapter_api_msg_t * msg)
+{
+    return tcpip_adapter_set_hostname(msg->tcpip_if, msg->hostname);
+}
+
 esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **hostname)
 {
 #if LWIP_NETIF_HOSTNAME