Skip to content

Commit bc2be92

Browse files
committed
esp32/network_ppp: Restructure to match extmod/network_ppp_lwip.
The ESP32 PPP implementation predates the generic implementation in extmod. The new extmod implementation has a few advantages such as a better deinitialisation procedure (the ESP32 implemementation would not clean up properly and cause crashes if recreated) and using the UART IRQ functionality instead of running a task to read data from the UART. This change restructures the ESP implementation to be much closer to the new extmod version, while also bringing a few tiny improvements from the ESP32 version to the extmod version. The diff between extmod/network_ppp_lwip.c and ports/esp32/network_ppp.c is now a small set of easy to review ESP32 port-specific changes. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
1 parent f498a16 commit bc2be92

File tree

4 files changed

+304
-214
lines changed

4 files changed

+304
-214
lines changed

extmod/network_ppp_lwip.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ static void network_ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
8080
break;
8181
case PPPERR_USER:
8282
if (self->state >= STATE_ERROR) {
83-
network_ppp_stream_uart_irq_disable(self);
8483
// Indicate that we are no longer connected and thus
8584
// only need to free the PPP PCB, not close it.
8685
self->state = STATE_ACTIVE;
@@ -121,6 +120,7 @@ static mp_obj_t network_ppp___del__(mp_obj_t self_in) {
121120
self->state = STATE_INACTIVE;
122121
ppp_close(self->pcb, 1);
123122
}
123+
network_ppp_stream_uart_irq_disable(self);
124124
// Free PPP PCB and reset state.
125125
self->state = STATE_INACTIVE;
126126
ppp_free(self->pcb);
@@ -295,7 +295,10 @@ static mp_obj_t network_ppp_connect(size_t n_args, const mp_obj_t *args, mp_map_
295295
ppp_set_auth(self->pcb, parsed_args[ARG_security].u_int, user_str, key_str);
296296
}
297297

298-
netif_set_default(self->pcb->netif);
298+
if (ppp_set_default(self->pcb) != ERR_OK) {
299+
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("ppp_set_default failed"));
300+
}
301+
299302
ppp_set_usepeerdns(self->pcb, true);
300303

301304
if (ppp_connect(self->pcb, 0) != ERR_OK) {

ports/esp32/modnetwork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern const mp_obj_type_t esp_network_wlan_type;
5252
MP_DECLARE_CONST_FUN_OBJ_0(esp_network_initialize_obj);
5353
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj);
5454
MP_DECLARE_CONST_FUN_OBJ_KW(esp_network_get_lan_obj);
55-
MP_DECLARE_CONST_FUN_OBJ_1(esp_network_ppp_make_new_obj);
55+
extern const struct _mp_obj_type_t esp_network_ppp_lwip_type;
5656
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_ifconfig_obj);
5757
MP_DECLARE_CONST_FUN_OBJ_KW(esp_network_ipconfig_obj);
5858
MP_DECLARE_CONST_FUN_OBJ_KW(esp_nic_ipconfig_obj);

ports/esp32/modnetwork_globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{ MP_ROM_QSTR(MP_QSTR_LAN), MP_ROM_PTR(&esp_network_get_lan_obj) },
99
#endif
1010
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) && defined(CONFIG_LWIP_PPP_SUPPORT)
11-
{ MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&esp_network_ppp_make_new_obj) },
11+
{ MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&esp_network_ppp_lwip_type) },
1212
#endif
1313
{ MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_network_phy_mode_obj) },
1414
{ MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&esp_network_ipconfig_obj) },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy