|
|
@@ -144,6 +144,8 @@ static void netif_set_mldv6_flag(struct netif *netif);
|
|
|
static void netif_unset_mldv6_flag(struct netif *netif);
|
|
|
#endif /* LWIP_IPV6 */
|
|
|
|
|
|
+static esp_err_t esp_netif_destroy_api(esp_netif_api_msg_t *msg);
|
|
|
+
|
|
|
static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args)
|
|
|
{
|
|
|
#if LWIP_IPV4
|
|
|
@@ -162,30 +164,6 @@ static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, co
|
|
|
#endif /* #if LWIP_IPV6 */
|
|
|
}
|
|
|
|
|
|
-#if LWIP_ESP_NETIF_DATA
|
|
|
-static esp_err_t alloc_client_data_id(esp_netif_api_msg_t *msg)
|
|
|
-{
|
|
|
- uint8_t *client_data_id = msg->data;
|
|
|
- *client_data_id = netif_alloc_client_data_id();
|
|
|
- return ESP_OK;
|
|
|
-}
|
|
|
-#endif // LWIP_ESP_NETIF_DATA
|
|
|
-
|
|
|
-static esp_err_t set_lwip_netif_callback(struct esp_netif_api_msg_s *msg)
|
|
|
-{
|
|
|
- (void)msg;
|
|
|
- netif_add_ext_callback(&netif_callback, netif_callback_fn);
|
|
|
- return ESP_OK;
|
|
|
-}
|
|
|
-
|
|
|
-static esp_err_t remove_lwip_netif_callback(struct esp_netif_api_msg_s *msg)
|
|
|
-{
|
|
|
- (void)msg;
|
|
|
- netif_remove_ext_callback(&netif_callback);
|
|
|
- memset(&netif_callback, 0, sizeof(netif_callback));
|
|
|
- return ESP_OK;
|
|
|
-}
|
|
|
-
|
|
|
#ifdef CONFIG_LWIP_GARP_TMR_INTERVAL
|
|
|
|
|
|
static void netif_send_garp(void *arg)
|
|
|
@@ -276,6 +254,16 @@ static inline esp_err_t esp_netif_lwip_ipc_call_fn(esp_netif_api_fn fn, esp_neti
|
|
|
return esp_netif_lwip_ipc_call_msg(&msg);
|
|
|
}
|
|
|
|
|
|
+static inline esp_err_t esp_netif_lwip_ipc_call_get_netif(esp_netif_api_fn fn, esp_netif_t **netif, void *ctx)
|
|
|
+{
|
|
|
+ esp_netif_api_msg_t msg = {
|
|
|
+ .p_esp_netif = netif,
|
|
|
+ .data = ctx,
|
|
|
+ .api_fn = fn
|
|
|
+ };
|
|
|
+ return esp_netif_lwip_ipc_call_msg(&msg);
|
|
|
+}
|
|
|
+
|
|
|
static inline esp_err_t esp_netif_lwip_ipc_no_args(esp_netif_api_fn fn)
|
|
|
{
|
|
|
esp_netif_api_msg_t msg = {
|
|
|
@@ -364,7 +352,6 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
|
|
|
case ESP_NETIF_STOPPED:
|
|
|
{
|
|
|
s_last_default_esp_netif = NULL;
|
|
|
- esp_netif_list_lock();
|
|
|
esp_netif_t *netif = esp_netif_next_unsafe(NULL);
|
|
|
while (netif) {
|
|
|
if (esp_netif_is_netif_up(netif)) {
|
|
|
@@ -379,7 +366,6 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
|
|
|
}
|
|
|
netif = esp_netif_next_unsafe(netif);
|
|
|
}
|
|
|
- esp_netif_list_unlock();
|
|
|
if (s_last_default_esp_netif && esp_netif_is_netif_up(s_last_default_esp_netif)) {
|
|
|
esp_netif_set_default_netif_internal(s_last_default_esp_netif);
|
|
|
}
|
|
|
@@ -519,6 +505,13 @@ void* esp_netif_get_netif_impl(esp_netif_t *esp_netif)
|
|
|
static void tcpip_init_done(void *arg)
|
|
|
{
|
|
|
sys_sem_t *init_sem = arg;
|
|
|
+
|
|
|
+#if LWIP_ESP_NETIF_DATA
|
|
|
+ if (lwip_netif_client_id == 0xFF) {
|
|
|
+ lwip_netif_client_id = netif_alloc_client_data_id();
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
sys_sem_signal(init_sem);
|
|
|
}
|
|
|
|
|
|
@@ -570,11 +563,6 @@ esp_err_t esp_netif_init(void)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-#if LWIP_ESP_NETIF_DATA
|
|
|
- if (lwip_netif_client_id == 0xFF) {
|
|
|
- esp_netif_lwip_ipc_call(alloc_client_data_id, NULL, &lwip_netif_client_id);
|
|
|
- }
|
|
|
-#endif
|
|
|
ESP_LOGD(TAG, "esp-netif has been successfully initialized");
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -698,15 +686,16 @@ esp_err_t esp_netif_tcpip_exec(esp_netif_callback_fn fn, void*ctx)
|
|
|
return esp_netif_lwip_ipc_call_fn(tcpip_exec_api, fn, ctx);
|
|
|
}
|
|
|
|
|
|
-esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
+static esp_err_t esp_netif_new_api(esp_netif_api_msg_t *msg)
|
|
|
{
|
|
|
+ const esp_netif_config_t *esp_netif_config = msg->data;
|
|
|
// mandatory configuration must be provided when creating esp_netif object
|
|
|
if (esp_netif_config == NULL ||
|
|
|
esp_netif_config->base->if_key == NULL ||
|
|
|
- NULL != esp_netif_get_handle_from_ifkey(esp_netif_config->base->if_key)) {
|
|
|
+ NULL != esp_netif_get_handle_from_ifkey_unsafe(esp_netif_config->base->if_key)) {
|
|
|
ESP_LOGE(TAG, "%s: Failed to configure netif with config=%p (config or if_key is NULL or duplicate key)",
|
|
|
__func__, esp_netif_config);
|
|
|
- return NULL;
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
|
|
|
#if ESP_DHCPS
|
|
|
@@ -715,7 +704,7 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
(esp_netif_config->base->flags & ESP_NETIF_DHCP_CLIENT)) {
|
|
|
ESP_LOGE(TAG, "%s: Failed to configure netif with config=%p (DHCP server and client cannot be configured together)",
|
|
|
__func__, esp_netif_config);
|
|
|
- return NULL;
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
@@ -724,7 +713,7 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
if (!esp_netif) {
|
|
|
ESP_LOGE(TAG, "Failed to allocate %" PRIu32 " bytes (free heap size %" PRIu32 ")", (uint32_t)sizeof(struct esp_netif_obj),
|
|
|
esp_get_free_heap_size());
|
|
|
- return NULL;
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
|
|
|
// Create ip info
|
|
|
@@ -733,7 +722,7 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
ESP_LOGE(TAG, "Failed to allocate %" PRIu32 " bytes (free heap size %" PRIu32 ")", (uint32_t)sizeof(esp_netif_ip_info_t),
|
|
|
esp_get_free_heap_size());
|
|
|
free(esp_netif);
|
|
|
- return NULL;
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
esp_netif->ip_info = ip_info;
|
|
|
|
|
|
@@ -744,19 +733,11 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
esp_get_free_heap_size());
|
|
|
free(esp_netif->ip_info);
|
|
|
free(esp_netif);
|
|
|
- return NULL;
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
esp_netif->ip_info_old = ip_info;
|
|
|
|
|
|
// Create underlying lwip netif
|
|
|
-#if LWIP_ESP_NETIF_DATA
|
|
|
- // Optionally allocate netif client data for esp-netif ptr
|
|
|
- // to allow for running esp_netif_new() before esp_netif_init()
|
|
|
- if (lwip_netif_client_id == 0xFF) {
|
|
|
- esp_netif_lwip_ipc_call(alloc_client_data_id, NULL, &lwip_netif_client_id);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
struct netif * lwip_netif = calloc(1, sizeof(struct netif));
|
|
|
if (!lwip_netif) {
|
|
|
ESP_LOGE(TAG, "Failed to allocate %" PRIu32 " bytes (free heap size %" PRIu32 ")", (uint32_t)sizeof(struct netif),
|
|
|
@@ -764,12 +745,12 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
free(esp_netif->ip_info_old);
|
|
|
free(esp_netif->ip_info);
|
|
|
free(esp_netif);
|
|
|
- return NULL;
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
|
|
|
esp_netif->lwip_netif = lwip_netif;
|
|
|
|
|
|
- esp_netif_add_to_list(esp_netif);
|
|
|
+ esp_netif_add_to_list_unsafe(esp_netif);
|
|
|
|
|
|
#if ESP_DHCPS
|
|
|
// Create DHCP server structure
|
|
|
@@ -777,8 +758,9 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
esp_netif->dhcps = dhcps_new();
|
|
|
if (esp_netif->dhcps == NULL) {
|
|
|
ESP_LOGE(TAG, "Failed to create dhcp server handle");
|
|
|
- esp_netif_destroy(esp_netif);
|
|
|
- return NULL;
|
|
|
+ esp_netif_api_msg_t to_destroy = { .esp_netif = esp_netif};
|
|
|
+ esp_netif_destroy_api(&to_destroy);
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
@@ -787,16 +769,38 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
|
|
esp_err_t ret = esp_netif_init_configuration(esp_netif, esp_netif_config);
|
|
|
if (ret != ESP_OK) {
|
|
|
ESP_LOGE(TAG, "Initial configuration of esp_netif failed with %d", ret);
|
|
|
- esp_netif_destroy(esp_netif);
|
|
|
- return NULL;
|
|
|
+ esp_netif_api_msg_t to_destroy = { .esp_netif = esp_netif};
|
|
|
+ esp_netif_destroy_api(&to_destroy);
|
|
|
+ return ESP_FAIL;
|
|
|
}
|
|
|
lwip_set_esp_netif(lwip_netif, esp_netif);
|
|
|
|
|
|
if (netif_callback.callback_fn == NULL ) {
|
|
|
- esp_netif_lwip_ipc_no_args(set_lwip_netif_callback);
|
|
|
+ netif_add_ext_callback(&netif_callback, netif_callback_fn);
|
|
|
}
|
|
|
|
|
|
- return esp_netif;
|
|
|
+ *msg->p_esp_netif = esp_netif;
|
|
|
+ return ESP_OK;
|
|
|
+}
|
|
|
+
|
|
|
+esp_netif_t *esp_netif_new(const esp_netif_config_t *config)
|
|
|
+{
|
|
|
+ esp_netif_t *netif = NULL;
|
|
|
+ esp_netif_lwip_ipc_call_get_netif(esp_netif_new_api, &netif, (void *)config);
|
|
|
+ return netif;
|
|
|
+}
|
|
|
+
|
|
|
+static esp_err_t get_handle_from_ifkey_api(esp_netif_api_msg_t *msg)
|
|
|
+{
|
|
|
+ *msg->p_esp_netif = esp_netif_get_handle_from_ifkey_unsafe(msg->data);
|
|
|
+ return ESP_OK;
|
|
|
+}
|
|
|
+
|
|
|
+esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)
|
|
|
+{
|
|
|
+ esp_netif_t *netif = NULL;
|
|
|
+ esp_netif_lwip_ipc_call_get_netif(get_handle_from_ifkey_api, &netif, (void*)if_key);
|
|
|
+ return netif;
|
|
|
}
|
|
|
|
|
|
static void esp_netif_lwip_remove(esp_netif_t *esp_netif)
|
|
|
@@ -887,33 +891,36 @@ static void esp_netif_destroy_related(esp_netif_t *esp_netif)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static esp_err_t esp_netif_lwip_remove_api(esp_netif_api_msg_t *msg)
|
|
|
+static esp_err_t esp_netif_destroy_api(esp_netif_api_msg_t *msg)
|
|
|
{
|
|
|
- esp_netif_lwip_remove(msg->esp_netif);
|
|
|
+ esp_netif_t *esp_netif = msg->esp_netif;
|
|
|
+ esp_netif_remove_from_list_unsafe(esp_netif);
|
|
|
+ if (esp_netif_get_nr_of_ifs() == 0) {
|
|
|
+ netif_remove_ext_callback(&netif_callback);
|
|
|
+ netif_callback.callback_fn = NULL;
|
|
|
+ }
|
|
|
+ free(esp_netif->ip_info);
|
|
|
+ free(esp_netif->ip_info_old);
|
|
|
+ free(esp_netif->if_key);
|
|
|
+ free(esp_netif->if_desc);
|
|
|
+ esp_netif_lwip_remove(esp_netif);
|
|
|
+ esp_netif_destroy_related(esp_netif);
|
|
|
+ free(esp_netif->lwip_netif);
|
|
|
+ free(esp_netif->hostname);
|
|
|
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_STOPPED);
|
|
|
+#if ESP_DHCPS
|
|
|
+ dhcps_delete(esp_netif->dhcps);
|
|
|
+#endif
|
|
|
+ free(esp_netif);
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
void esp_netif_destroy(esp_netif_t *esp_netif)
|
|
|
{
|
|
|
- if (esp_netif) {
|
|
|
- esp_netif_remove_from_list(esp_netif);
|
|
|
- if (esp_netif_get_nr_of_ifs() == 0) {
|
|
|
- esp_netif_lwip_ipc_no_args(remove_lwip_netif_callback);
|
|
|
- }
|
|
|
- free(esp_netif->ip_info);
|
|
|
- free(esp_netif->ip_info_old);
|
|
|
- free(esp_netif->if_key);
|
|
|
- free(esp_netif->if_desc);
|
|
|
- esp_netif_lwip_ipc_call(esp_netif_lwip_remove_api, esp_netif, NULL);
|
|
|
- esp_netif_destroy_related(esp_netif);
|
|
|
- free(esp_netif->lwip_netif);
|
|
|
- free(esp_netif->hostname);
|
|
|
- esp_netif_update_default_netif(esp_netif, ESP_NETIF_STOPPED);
|
|
|
-#if ESP_DHCPS
|
|
|
- dhcps_delete(esp_netif->dhcps);
|
|
|
-#endif
|
|
|
- free(esp_netif);
|
|
|
+ if (esp_netif == NULL) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ esp_netif_lwip_ipc_call(esp_netif_destroy_api, esp_netif, NULL);
|
|
|
}
|
|
|
|
|
|
esp_err_t esp_netif_attach(esp_netif_t *esp_netif, esp_netif_iodriver_handle driver_handle)
|
|
|
@@ -1034,6 +1041,15 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
|
|
|
esp_netif_t * esp_netif = msg->esp_netif;
|
|
|
|
|
|
ESP_LOGD(TAG, "%s %p", __func__, esp_netif);
|
|
|
+ if (ESP_NETIF_IS_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) {
|
|
|
+#if CONFIG_PPP_SUPPORT
|
|
|
+ esp_err_t ret = esp_netif_start_ppp(esp_netif);
|
|
|
+ if (ret == ESP_OK) {
|
|
|
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+#endif
|
|
|
+ }
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_netif_config_sanity_check(esp_netif));
|
|
|
|
|
|
@@ -1116,22 +1132,22 @@ 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)
|
|
|
{
|
|
|
+ return esp_netif_lwip_ipc_call(esp_netif_start_api, esp_netif, NULL);
|
|
|
+}
|
|
|
+
|
|
|
+static esp_err_t esp_netif_stop_api(esp_netif_api_msg_t *msg)
|
|
|
+{
|
|
|
+ esp_netif_t *esp_netif = msg->esp_netif;
|
|
|
+
|
|
|
if (ESP_NETIF_IS_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);
|
|
|
+ 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_STARTED);
|
|
|
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_STOPPED);
|
|
|
}
|
|
|
return ret;
|
|
|
#endif
|
|
|
}
|
|
|
- return esp_netif_lwip_ipc_call(esp_netif_start_api, esp_netif, NULL);
|
|
|
-}
|
|
|
-
|
|
|
-static esp_err_t esp_netif_stop_api(esp_netif_api_msg_t *msg)
|
|
|
-{
|
|
|
- esp_netif_t *esp_netif = msg->esp_netif;
|
|
|
|
|
|
struct netif *lwip_netif = esp_netif->lwip_netif;
|
|
|
if (lwip_netif == NULL) {
|
|
|
@@ -1175,16 +1191,6 @@ 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 (ESP_NETIF_IS_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
|
|
|
- }
|
|
|
return esp_netif_lwip_ipc_call(esp_netif_stop_api, esp_netif, NULL);
|
|
|
}
|
|
|
|
|
|
@@ -2398,11 +2404,11 @@ esp_err_t esp_netif_get_netif_impl_name(esp_netif_t *esp_netif, char* name)
|
|
|
return esp_netif_lwip_ipc_call(esp_netif_get_netif_impl_name_api, esp_netif, name);
|
|
|
}
|
|
|
|
|
|
-esp_err_t esp_netif_napt_enable(esp_netif_t *esp_netif)
|
|
|
+#if IP_NAPT
|
|
|
+static esp_err_t esp_netif_napt_control_api(esp_netif_api_msg_t *msg)
|
|
|
{
|
|
|
-#if !IP_NAPT
|
|
|
- return ESP_ERR_NOT_SUPPORTED;
|
|
|
-#else
|
|
|
+ bool enable = (bool)msg->data;
|
|
|
+ esp_netif_t *esp_netif = msg->esp_netif;
|
|
|
ESP_LOGD(TAG, "%s esp_netif:%p", __func__, esp_netif);
|
|
|
|
|
|
/* Check if the interface is up */
|
|
|
@@ -2410,44 +2416,74 @@ esp_err_t esp_netif_napt_enable(esp_netif_t *esp_netif)
|
|
|
return ESP_FAIL;
|
|
|
}
|
|
|
|
|
|
- esp_netif_list_lock();
|
|
|
- /* Disable napt on all other interface */
|
|
|
- esp_netif_t *netif = esp_netif_next_unsafe(NULL);
|
|
|
- while (netif) {
|
|
|
- if (netif != esp_netif) {
|
|
|
- ip_napt_enable_netif(netif->lwip_netif, 0); // Fails only if netif is down
|
|
|
- ESP_LOGW(TAG, "napt disabled on esp_netif:%p", esp_netif);
|
|
|
+ if (enable) {
|
|
|
+ /* Disable napt on all other interface */
|
|
|
+ esp_netif_t *netif = esp_netif_next_unsafe(NULL);
|
|
|
+ while (netif) {
|
|
|
+ if (netif != esp_netif) {
|
|
|
+ ip_napt_enable_netif(netif->lwip_netif, 0); // Fails only if netif is down
|
|
|
+ ESP_LOGW(TAG, "napt disabled on esp_netif:%p", esp_netif);
|
|
|
+ }
|
|
|
+ netif = esp_netif_next_unsafe(netif);
|
|
|
}
|
|
|
- netif = esp_netif_next_unsafe(netif);
|
|
|
- }
|
|
|
|
|
|
- int ret = ip_napt_enable_netif(esp_netif->lwip_netif, 1);
|
|
|
- esp_netif_list_unlock();
|
|
|
+ int ret = ip_napt_enable_netif(esp_netif->lwip_netif, 1);
|
|
|
|
|
|
- if (ret == 0) {
|
|
|
- return ESP_FAIL;
|
|
|
- }
|
|
|
+ if (ret == 0) {
|
|
|
+ return ESP_FAIL;
|
|
|
+ }
|
|
|
+ return ESP_OK;
|
|
|
+ } else {
|
|
|
+ ip_napt_enable_netif(esp_netif->lwip_netif, 0); // Fails only if netif is down
|
|
|
+ ESP_LOGD(TAG, "napt disabled on esp_netif:%p", esp_netif);
|
|
|
|
|
|
- return ESP_OK;
|
|
|
-#endif /* IP_NAPT */
|
|
|
+ return ESP_OK;
|
|
|
+ }
|
|
|
}
|
|
|
+#endif // !IP_NAPT
|
|
|
|
|
|
-esp_err_t esp_netif_napt_disable(esp_netif_t *esp_netif)
|
|
|
+esp_err_t esp_netif_napt_enable(esp_netif_t *esp_netif)
|
|
|
{
|
|
|
#if !IP_NAPT
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
#else
|
|
|
- /* Check if the interface is up */
|
|
|
- if (!netif_is_up(esp_netif->lwip_netif)) {
|
|
|
- return ESP_FAIL;
|
|
|
- }
|
|
|
+ return esp_netif_lwip_ipc_call(esp_netif_napt_control_api, esp_netif, (void*)true /* Enable */);
|
|
|
+#endif /* IP_NAPT */
|
|
|
+}
|
|
|
|
|
|
- esp_netif_list_lock();
|
|
|
- ip_napt_enable_netif(esp_netif->lwip_netif, 0); // Fails only if netif is down
|
|
|
- ESP_LOGD(TAG, "napt disabled on esp_netif:%p", esp_netif);
|
|
|
- esp_netif_list_unlock();
|
|
|
+typedef struct {
|
|
|
+ u8_t authtype;
|
|
|
+ const char *user;
|
|
|
+ const char *passwd;
|
|
|
+} set_auth_msg_t;
|
|
|
|
|
|
+static esp_err_t esp_netif_ppp_set_auth_api(esp_netif_api_msg_t *msg)
|
|
|
+{
|
|
|
+ set_auth_msg_t *params = msg->data;
|
|
|
+ return esp_netif_ppp_set_auth_internal(msg->esp_netif, params->authtype, params->user, params->passwd);
|
|
|
+}
|
|
|
+
|
|
|
+esp_err_t esp_netif_ppp_set_auth(esp_netif_t *esp_netif, esp_netif_auth_type_t authtype, const char *user, const char *passwd)
|
|
|
+{
|
|
|
+ set_auth_msg_t msg = { .authtype = authtype, .user = user, .passwd = passwd };
|
|
|
+ return esp_netif_lwip_ipc_call(esp_netif_ppp_set_auth_api, esp_netif, &msg);
|
|
|
+#if PPP_AUTH_SUPPORT
|
|
|
+ lwip_peer2peer_ctx_t *ppp_ctx = (lwip_peer2peer_ctx_t *)netif->related_data;
|
|
|
+ assert(ppp_ctx->base.netif_type == PPP_LWIP_NETIF);
|
|
|
+ pppapi_set_auth(ppp_ctx->ppp, authtype, user, passwd);
|
|
|
return ESP_OK;
|
|
|
+#else
|
|
|
+ ESP_LOGE(TAG, "%s failed: No authorisation enabled in menuconfig", __func__);
|
|
|
+ return ESP_ERR_ESP_NETIF_IF_NOT_READY;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+esp_err_t esp_netif_napt_disable(esp_netif_t *esp_netif)
|
|
|
+{
|
|
|
+#if !IP_NAPT
|
|
|
+ return ESP_ERR_NOT_SUPPORTED;
|
|
|
+#else
|
|
|
+ return esp_netif_lwip_ipc_call(esp_netif_napt_control_api, esp_netif, (void*)false /* Disable */);
|
|
|
#endif /* IP_NAPT */
|
|
|
}
|
|
|
|