mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -04:00
Compare commits
3 Commits
bbab011748
...
112b74abd4
Author | SHA1 | Date | |
---|---|---|---|
|
112b74abd4 | ||
|
7326fe39d8 | ||
|
f6ab11ed8f |
@ -31,6 +31,9 @@ typedef struct esp_netif_ppp_config {
|
|||||||
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
||||||
esp_ip4_addr_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */
|
esp_ip4_addr_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */
|
||||||
esp_ip4_addr_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */
|
esp_ip4_addr_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */
|
||||||
|
esp_ip4_addr_t ppp_dns1_addr; /**< DNS to provide if peer asks for it, typically used when we're the PPP server */
|
||||||
|
esp_ip4_addr_t ppp_dns2_addr; /**< DNS to provide if peer asks for it, typically used when we're the PPP server */
|
||||||
|
bool ppp_passive; /**< Try once to initiate connection, stay silent if it fails, typically used when we're the PPP server */
|
||||||
#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT
|
#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT
|
||||||
} esp_netif_ppp_config_t;
|
} esp_netif_ppp_config_t;
|
||||||
|
|
||||||
|
@ -105,6 +105,8 @@ typedef enum {
|
|||||||
IP_EVENT_PPP_GOT_IP, /*!< PPP interface got IP */
|
IP_EVENT_PPP_GOT_IP, /*!< PPP interface got IP */
|
||||||
IP_EVENT_PPP_LOST_IP, /*!< PPP interface lost IP */
|
IP_EVENT_PPP_LOST_IP, /*!< PPP interface lost IP */
|
||||||
IP_EVENT_TX_RX, /*!< transmitting/receiving data packet */
|
IP_EVENT_TX_RX, /*!< transmitting/receiving data packet */
|
||||||
|
IP_EVENT_PPPD_GOT_IP, /*!< PPP server interface got IP */
|
||||||
|
IP_EVENT_PPPD_LOST_IP, /*!< PPP server interface lost IP */
|
||||||
} ip_event_t;
|
} ip_event_t;
|
||||||
|
|
||||||
/** @brief IP event base declaration */
|
/** @brief IP event base declaration */
|
||||||
|
@ -37,6 +37,9 @@ typedef struct lwip_peer2peer_ctx {
|
|||||||
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
||||||
esp_ip4_addr_t ppp_our_ip4_addr; // our desired IP (IPADDR_ANY if no preference)
|
esp_ip4_addr_t ppp_our_ip4_addr; // our desired IP (IPADDR_ANY if no preference)
|
||||||
esp_ip4_addr_t ppp_their_ip4_addr; // their desired IP (IPADDR_ANY if no preference)
|
esp_ip4_addr_t ppp_their_ip4_addr; // their desired IP (IPADDR_ANY if no preference)
|
||||||
|
esp_ip4_addr_t ppp_dns1_addr; // dns server 1 IP (IPADDR_ANY if no preference)
|
||||||
|
esp_ip4_addr_t ppp_dns2_addr; // dns server 2 IP (IPADDR_ANY if no preference)
|
||||||
|
bool ppp_passive; // Set ppp_passive() and use ppp_listen()
|
||||||
#endif
|
#endif
|
||||||
ppp_pcb *ppp;
|
ppp_pcb *ppp;
|
||||||
} lwip_peer2peer_ctx_t;
|
} lwip_peer2peer_ctx_t;
|
||||||
@ -48,6 +51,7 @@ typedef struct lwip_peer2peer_ctx {
|
|||||||
static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx)
|
static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx)
|
||||||
{
|
{
|
||||||
esp_netif_t *netif = ctx;
|
esp_netif_t *netif = ctx;
|
||||||
|
const char *name = netif->if_desc ? netif->if_desc : "";
|
||||||
ip_event_got_ip_t evt = {
|
ip_event_got_ip_t evt = {
|
||||||
.esp_netif = netif,
|
.esp_netif = netif,
|
||||||
};
|
};
|
||||||
@ -56,59 +60,59 @@ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx)
|
|||||||
assert(obj->base.netif_type == PPP_LWIP_NETIF);
|
assert(obj->base.netif_type == PPP_LWIP_NETIF);
|
||||||
switch (err_code) {
|
switch (err_code) {
|
||||||
case PPPERR_NONE:
|
case PPPERR_NONE:
|
||||||
ESP_LOGI(TAG, "Connected");
|
ESP_LOGI(TAG, "%s: Connected", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_PARAM:
|
case PPPERR_PARAM:
|
||||||
ESP_LOGE(TAG, "Invalid parameter");
|
ESP_LOGE(TAG, "%s: Invalid parameter", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_OPEN:
|
case PPPERR_OPEN:
|
||||||
ESP_LOGE(TAG, "Unable to open PPP session");
|
ESP_LOGE(TAG, "%s: Unable to open PPP session", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_DEVICE:
|
case PPPERR_DEVICE:
|
||||||
ESP_LOGE(TAG, "Invalid I/O device for PPP");
|
ESP_LOGE(TAG, "%s: Invalid I/O device for PPP", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_ALLOC:
|
case PPPERR_ALLOC:
|
||||||
ESP_LOGE(TAG, "Unable to allocate resources");
|
ESP_LOGE(TAG, "%s: Unable to allocate resources", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_USER: /* User interrupt */
|
case PPPERR_USER: /* User interrupt */
|
||||||
ESP_LOGI(TAG, "User interrupt");
|
ESP_LOGI(TAG, "%s: User interrupt", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_CONNECT: /* Connection lost */
|
case PPPERR_CONNECT: /* Connection lost */
|
||||||
ESP_LOGI(TAG, "Connection lost");
|
ESP_LOGI(TAG, "%s: Connection lost", name);
|
||||||
esp_netif_update_default_netif(netif, ESP_NETIF_LOST_IP);
|
esp_netif_update_default_netif(netif, ESP_NETIF_LOST_IP);
|
||||||
err = esp_event_post(IP_EVENT, netif->lost_ip_event, &evt, sizeof(evt), 0);
|
err = esp_event_post(IP_EVENT, netif->lost_ip_event, &evt, sizeof(evt), 0);
|
||||||
|
|
||||||
if (ESP_OK != err) {
|
if (ESP_OK != err) {
|
||||||
ESP_LOGE(TAG, "esp_event_post failed with code %d", err);
|
ESP_LOGE(TAG, "%s: esp_event_post failed with code %d", name, err);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PPPERR_AUTHFAIL:
|
case PPPERR_AUTHFAIL:
|
||||||
ESP_LOGE(TAG, "Failed authentication challenge");
|
ESP_LOGE(TAG, "%s: Failed authentication challenge", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_PROTOCOL:
|
case PPPERR_PROTOCOL:
|
||||||
ESP_LOGE(TAG, "Failed to meet protocol");
|
ESP_LOGE(TAG, "%s: Failed to meet protocol", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_PEERDEAD:
|
case PPPERR_PEERDEAD:
|
||||||
ESP_LOGE(TAG, "Connection timeout");
|
ESP_LOGE(TAG, "%s: Connection timeout", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_IDLETIMEOUT:
|
case PPPERR_IDLETIMEOUT:
|
||||||
ESP_LOGE(TAG, "Idle Timeout");
|
ESP_LOGE(TAG, "%s: Idle Timeout", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_CONNECTTIME:
|
case PPPERR_CONNECTTIME:
|
||||||
ESP_LOGE(TAG, "Max connect time reached");
|
ESP_LOGE(TAG, "%s: Max connect time reached", name);
|
||||||
break;
|
break;
|
||||||
case PPPERR_LOOPBACK:
|
case PPPERR_LOOPBACK:
|
||||||
ESP_LOGE(TAG, "Loopback detected");
|
ESP_LOGE(TAG, "%s: Loopback detected", name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGE(TAG, "Unknown error code %d", err_code);
|
ESP_LOGE(TAG, "%s: Unknown error code %d", name, err_code);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (obj->ppp_error_event_enabled) {
|
if (obj->ppp_error_event_enabled) {
|
||||||
err = esp_event_post(NETIF_PPP_STATUS, err_code, &netif, sizeof(netif), 0);
|
err = esp_event_post(NETIF_PPP_STATUS, err_code, &netif, sizeof(netif), 0);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "esp_event_post failed with code %d", err);
|
ESP_LOGE(TAG, "%s: esp_event_post failed with code %d", name, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -124,42 +128,44 @@ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx)
|
|||||||
*/
|
*/
|
||||||
static void on_ppp_notify_phase(ppp_pcb *pcb, u8_t phase, void *ctx)
|
static void on_ppp_notify_phase(ppp_pcb *pcb, u8_t phase, void *ctx)
|
||||||
{
|
{
|
||||||
|
esp_netif_t *netif = ctx;
|
||||||
|
const char *name = netif->if_desc ? netif->if_desc : "";
|
||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
case PPP_PHASE_DEAD:
|
case PPP_PHASE_DEAD:
|
||||||
ESP_LOGD(TAG, "Phase Dead");
|
ESP_LOGD(TAG, "%s: Phase Dead", name);
|
||||||
break;
|
break;
|
||||||
case PPP_PHASE_INITIALIZE:
|
case PPP_PHASE_INITIALIZE:
|
||||||
ESP_LOGD(TAG, "Phase Start");
|
ESP_LOGD(TAG, "%s: Phase Start", name);
|
||||||
break;
|
break;
|
||||||
case PPP_PHASE_ESTABLISH:
|
case PPP_PHASE_ESTABLISH:
|
||||||
ESP_LOGD(TAG, "Phase Establish");
|
ESP_LOGD(TAG, "%s: Phase Establish", name);
|
||||||
break;
|
break;
|
||||||
case PPP_PHASE_AUTHENTICATE:
|
case PPP_PHASE_AUTHENTICATE:
|
||||||
ESP_LOGD(TAG, "Phase Authenticate");
|
ESP_LOGD(TAG, "%s: Phase Authenticate", name);
|
||||||
break;
|
break;
|
||||||
case PPP_PHASE_NETWORK:
|
case PPP_PHASE_NETWORK:
|
||||||
ESP_LOGD(TAG, "Phase Network");
|
ESP_LOGD(TAG, "%s: Phase Network", name);
|
||||||
break;
|
break;
|
||||||
case PPP_PHASE_RUNNING:
|
case PPP_PHASE_RUNNING:
|
||||||
ESP_LOGD(TAG, "Phase Running");
|
ESP_LOGD(TAG, "%s: Phase Running", name);
|
||||||
break;
|
break;
|
||||||
case PPP_PHASE_TERMINATE:
|
case PPP_PHASE_TERMINATE:
|
||||||
ESP_LOGD(TAG, "Phase Terminate");
|
ESP_LOGD(TAG, "%s: Phase Terminate", name);
|
||||||
break;
|
break;
|
||||||
case PPP_PHASE_DISCONNECT:
|
case PPP_PHASE_DISCONNECT:
|
||||||
ESP_LOGD(TAG, "Phase Disconnect");
|
ESP_LOGD(TAG, "%s: Phase Disconnect", name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGW(TAG, "Phase Unknown: %d", phase);
|
ESP_LOGW(TAG, "%s: Phase Unknown: %d", name, phase);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
esp_netif_t *netif = ctx;
|
|
||||||
lwip_peer2peer_ctx_t *obj = (lwip_peer2peer_ctx_t *)netif->related_data;
|
lwip_peer2peer_ctx_t *obj = (lwip_peer2peer_ctx_t *)netif->related_data;
|
||||||
assert(obj->base.netif_type == PPP_LWIP_NETIF);
|
assert(obj->base.netif_type == PPP_LWIP_NETIF);
|
||||||
if (obj && obj->ppp_phase_event_enabled) {
|
if (obj && obj->ppp_phase_event_enabled) {
|
||||||
esp_err_t err = esp_event_post(NETIF_PPP_STATUS, NETIF_PP_PHASE_OFFSET + phase, &netif, sizeof(netif), 0);
|
esp_err_t err = esp_event_post(NETIF_PPP_STATUS, NETIF_PP_PHASE_OFFSET + phase, &netif, sizeof(netif), 0);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "esp_event_post failed with code %d", err);
|
ESP_LOGE(TAG, "%s: esp_event_post failed with code %d", name, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,6 +274,19 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif)
|
|||||||
ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr.addr;
|
ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr.addr;
|
||||||
ppp_ctx->ppp->ipcp_wantoptions.accept_local = 1;
|
ppp_ctx->ppp->ipcp_wantoptions.accept_local = 1;
|
||||||
}
|
}
|
||||||
|
if (ppp_ctx->ppp_dns1_addr.addr != IPADDR_TYPE_ANY) {
|
||||||
|
ppp_set_ipcp_dnsaddr(ppp_ctx->ppp, 0, &ppp_ctx->ppp_dns1_addr);
|
||||||
|
}
|
||||||
|
if (ppp_ctx->ppp_dns2_addr.addr != IPADDR_TYPE_ANY) {
|
||||||
|
ppp_set_ipcp_dnsaddr(ppp_ctx->ppp, 1, &ppp_ctx->ppp_dns2_addr);
|
||||||
|
}
|
||||||
|
if (ppp_ctx->ppp_dns1_addr.addr != IPADDR_TYPE_ANY ||
|
||||||
|
ppp_ctx->ppp_dns2_addr.addr != IPADDR_TYPE_ANY) {
|
||||||
|
// No need to request DNS servers from peer when providing DNS servers.
|
||||||
|
ppp_set_usepeerdns(ppp_ctx->ppp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ppp_set_passive(ppp_ctx->ppp, ppp_ctx->ppp_passive);
|
||||||
#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT
|
#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT
|
||||||
|
|
||||||
#if ESP_IPV6_AUTOCONFIG
|
#if ESP_IPV6_AUTOCONFIG
|
||||||
@ -276,7 +295,12 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif)
|
|||||||
|
|
||||||
ESP_LOGD(TAG, "%s: Starting PPP connection: %p", __func__, ppp_ctx->ppp);
|
ESP_LOGD(TAG, "%s: Starting PPP connection: %p", __func__, ppp_ctx->ppp);
|
||||||
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
||||||
esp_err_t err = ppp_listen(ppp_ctx->ppp);
|
esp_err_t err;
|
||||||
|
if (ppp_ctx->ppp_passive) {
|
||||||
|
err = ppp_listen(ppp_ctx->ppp);
|
||||||
|
} else {
|
||||||
|
err = ppp_connect(ppp_ctx->ppp, 0);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
err_t err = ppp_connect(ppp_ctx->ppp, 0);
|
err_t err = ppp_connect(ppp_ctx->ppp, 0);
|
||||||
#endif
|
#endif
|
||||||
@ -338,6 +362,9 @@ esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_confi
|
|||||||
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
||||||
obj->ppp_our_ip4_addr = config->ppp_our_ip4_addr;
|
obj->ppp_our_ip4_addr = config->ppp_our_ip4_addr;
|
||||||
obj->ppp_their_ip4_addr = config->ppp_their_ip4_addr;
|
obj->ppp_their_ip4_addr = config->ppp_their_ip4_addr;
|
||||||
|
obj->ppp_dns1_addr = config->ppp_dns1_addr;
|
||||||
|
obj->ppp_dns2_addr = config->ppp_dns2_addr;
|
||||||
|
obj->ppp_passive = config->ppp_passive;
|
||||||
#endif
|
#endif
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -357,6 +384,9 @@ esp_err_t esp_netif_ppp_get_params(esp_netif_t *netif, esp_netif_ppp_config_t *c
|
|||||||
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
|
||||||
config->ppp_our_ip4_addr = obj->ppp_our_ip4_addr;
|
config->ppp_our_ip4_addr = obj->ppp_our_ip4_addr;
|
||||||
config->ppp_their_ip4_addr = obj->ppp_their_ip4_addr;
|
config->ppp_their_ip4_addr = obj->ppp_their_ip4_addr;
|
||||||
|
config->ppp_dns1_addr = obj->ppp_dns1_addr;
|
||||||
|
config->ppp_dns2_addr = obj->ppp_dns2_addr;
|
||||||
|
config->ppp_passive = obj->ppp_passive;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user