Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 54e5743

Browse files
author
Islam Wahdan
committed
[v1.20.0.rc12.1] Fix wlan sta interface terminating after lte disconnect (#325)
* [PYFW-86] Fix wlan sta interface terminating after lte disconnect * [v1.20.0.rc12.1] Hot fix Fix wlan sta interface terminating after lte disconnect * Fix compilation error # Conflicts: # esp32/get_idf_libs.py
1 parent 9e272e4 commit 54e5743

File tree

7 files changed

+44
-13
lines changed

7 files changed

+44
-13
lines changed

esp32/lte/lteppp.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "pins.h"
2828
#include "mpsleep.h"
2929
#include "esp32_mphal.h"
30+
#include "lwip/dns.h"
3031

3132
/******************************************************************************
3233
DEFINE CONSTANTS
@@ -78,6 +79,8 @@ static bool ltepp_ppp_conn_up = false;
7879

7980
static ltepppconnstatus_t lteppp_connstatus = LTE_PPP_IDLE;
8081

82+
static ip_addr_t ltepp_dns_info[2]={0};
83+
8184
/******************************************************************************
8285
DECLARE PRIVATE FUNCTIONS
8386
******************************************************************************/
@@ -188,6 +191,14 @@ void lteppp_set_state(lte_state_t state) {
188191
xSemaphoreGive(xLTESem);
189192
}
190193

194+
void lteppp_set_default_inf(void)
195+
{
196+
pppapi_set_default(lteppp_pcb);
197+
//Restore DNS
198+
dns_setserver(0, &(ltepp_dns_info[0]));
199+
dns_setserver(1, &(ltepp_dns_info[1]));
200+
}
201+
191202
void lteppp_set_legacy(lte_legacy_t legacy) {
192203
xSemaphoreTake(xLTESem, portMAX_DELAY);
193204
lteppp_lte_legacy = legacy;
@@ -656,6 +667,11 @@ static void lteppp_status_cb (ppp_pcb *pcb, int err_code, void *ctx) {
656667
lte_gw = pppif->gw.u_addr.ip4.addr;
657668
lte_netmask = pppif->netmask.u_addr.ip4.addr;
658669
lte_ipv4addr = pppif->ip_addr.u_addr.ip4.addr;
670+
if(lte_ipv4addr > 0)
671+
{
672+
ltepp_dns_info[0] = dns_getserver(0);
673+
ltepp_dns_info[1] = dns_getserver(1);
674+
}
659675
// printf("ipaddr = %s\n", ipaddr_ntoa(&pppif->ip_addr));
660676
// printf("gateway = %s\n", ipaddr_ntoa(&pppif->gw));
661677
// printf("netmask = %s\n", ipaddr_ntoa(&pppif->netmask));

esp32/lte/lteppp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ extern bool ltepp_is_ppp_conn_up(void);
124124
extern void lteppp_suspend(void);
125125

126126
extern void lteppp_resume(void);
127+
128+
extern void lteppp_set_default_inf(void);
127129
#ifdef LTE_DEBUG_BUFF
128130
extern char* lteppp_get_log_buff(void);
129131
#endif

esp32/mods/modlte.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ STATIC mp_obj_t lte_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
127127

128128
STATIC mp_obj_t lte_deinit(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
129129
STATIC mp_obj_t lte_disconnect(mp_obj_t self_in);
130-
130+
static void lte_set_default_inf(void);
131131
/******************************************************************************
132132
DEFINE PUBLIC FUNCTIONS
133133
******************************************************************************/
@@ -321,6 +321,11 @@ static void lte_check_init(void) {
321321
}
322322
}
323323

324+
static void lte_set_default_inf(void)
325+
{
326+
lteppp_set_default_inf();
327+
}
328+
324329
static void lte_check_inppp(void) {
325330
if (lteppp_get_state() == E_LTE_PPP) {
326331
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "LTE modem is in data state, cannot send AT commands"));
@@ -1384,4 +1389,5 @@ const mod_network_nic_type_t mod_network_nic_type_lte = {
13841389
.n_ioctl = lwipsocket_socket_ioctl,
13851390
.n_setupssl = lwipsocket_socket_setup_ssl,
13861391
.inf_up = ltepp_is_ppp_conn_up,
1392+
.set_default_inf = lte_set_default_inf
13871393
};

esp32/mods/modnetwork.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ void mod_network_deregister_nic(mp_obj_t nic) {
9494
mp_obj_t nic_rem = MP_STATE_PORT(mod_network_nic_list).items[i];
9595
if(mp_obj_get_type(nic_rem) == (mp_obj_type_t *)&mod_network_nic_type_wlan)
9696
{
97-
mod_network_nic_type_wlan.set_inf_up();
97+
mod_network_nic_type_wlan.set_default_inf();
9898
}
9999
else if (mp_obj_get_type(nic_rem) == (mp_obj_type_t *)&mod_network_nic_type_lte)
100100
{
101-
if (mod_network_nic_type_lte.set_inf_up != NULL) {
102-
mod_network_nic_type_lte.set_inf_up();
103-
}
101+
mod_network_nic_type_lte.set_default_inf();
104102
}
105103
}
106104
#endif

esp32/mods/modnetwork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ typedef struct _mod_network_nic_type_t {
8484
// Interface status
8585
bool (*inf_up)(void);
8686
// Bring Inf_up
87-
void (*set_inf_up)(void);
87+
void (*set_default_inf)(void);
8888
} mod_network_nic_type_t;
8989

9090
typedef struct _mod_network_socket_base_t {

esp32/mods/modwlan.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ static bool is_inf_up = false;
123123

124124
//mutex for Timeout Counter protection
125125
SemaphoreHandle_t timeout_mutex;
126+
#if defined(FIPY) || defined(GPY)
127+
// Variable saving DNS info
128+
static tcpip_adapter_dns_info_t wlan_sta_inf_dns_info;
129+
#endif
126130

127131
/******************************************************************************
128132
DECLARE PUBLIC DATA
@@ -156,7 +160,7 @@ static void wlan_timer_callback( TimerHandle_t xTimer );
156160
static void wlan_validate_country(const char * country);
157161
static void wlan_validate_country_policy(uint8_t policy);
158162
STATIC void wlan_stop_sta_conn_timer();
159-
STATIC void wlan_inf_up(void);
163+
STATIC void wlan_set_default_inf(void);
160164
//*****************************************************************************
161165
//
162166
//! \brief The Function Handles WLAN Events
@@ -346,7 +350,11 @@ STATIC esp_err_t wlan_event_handler(void *ctx, system_event_t *event) {
346350
break;
347351
case SYSTEM_EVENT_STA_GOT_IP: /**< ESP32 station got IP from connected AP */
348352
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
349-
is_inf_up = true;
353+
#if defined(FIPY) || defined(GPY)
354+
// Save DNS info for restoring if wifi inf is usable again after LTE disconnect
355+
tcpip_adapter_get_dns_info(TCPIP_ADAPTER_IF_STA, TCPIP_ADAPTER_DNS_MAIN, &wlan_sta_inf_dns_info);
356+
#endif
357+
is_inf_up = true;
350358
break;
351359
case SYSTEM_EVENT_STA_DISCONNECTED: /**< ESP32 station disconnected from AP */
352360
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
@@ -942,13 +950,14 @@ STATIC void promiscuous_callback(void *buf, wifi_promiscuous_pkt_type_t type)
942950
}
943951
}
944952

945-
STATIC void wlan_inf_up(void)
953+
STATIC void wlan_set_default_inf(void)
946954
{
955+
#if defined(FIPY) || defined(GPY)
947956
if (wlan_obj.mode == WIFI_MODE_STA || wlan_obj.mode == WIFI_MODE_APSTA) {
957+
tcpip_adapter_set_dns_info(TCPIP_ADAPTER_IF_STA, TCPIP_ADAPTER_DNS_MAIN, &wlan_sta_inf_dns_info);
948958
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
949-
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
950-
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
951959
}
960+
#endif
952961
}
953962

954963
//STATIC void wlan_get_sl_mac (void) {
@@ -2618,7 +2627,7 @@ const mod_network_nic_type_t mod_network_nic_type_wlan = {
26182627
.n_ioctl = lwipsocket_socket_ioctl,
26192628
.n_setupssl = lwipsocket_socket_setup_ssl,
26202629
.inf_up = wlan_is_inf_up,
2621-
.set_inf_up = wlan_inf_up
2630+
.set_default_inf = wlan_set_default_inf
26222631
};
26232632

26242633
//STATIC const mp_irq_methods_t wlan_irq_methods = {

esp32/pycom_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef VERSION_H_
1111
#define VERSION_H_
1212

13-
#define SW_VERSION_NUMBER "1.20.0.rc12"
13+
#define SW_VERSION_NUMBER "1.20.0.rc12.1"
1414

1515
#define LORAWAN_VERSION_NUMBER "1.0.2"
1616

0 commit comments

Comments
 (0)