8000 [v1.20.0.rc12.1] Fix wlan sta interface terminating after lte discon… · pycom/pycom-micropython-sigfox@6c0000f · GitHub
[go: up one dir, main page]

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

Commit 6c0000f

Browse files
author
Islam Wahdan
authored
[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
1 parent 81167ed commit 6c0000f

File tree

8 files changed

+44
-14
lines changed

8 files changed

+44
-14
lines changed

esp32/get_idf_libs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def main():
5959
shutil.copy(src + '/vfs/libvfs.a', dsttmpapp)
6060
shutil.copy(src + '/wpa_supplicant/libwpa_supplicant.a', dsttmpapp)
6161
shutil.copy(src + '/xtensa-debug-module/libxtensa-debug-module.a', dsttmpapp)
62-
shutil.copy(src + '/openthread/libopenthread.a', dsttmpapp)
6362
except:
6463
print("Couldn't Copy IDF libs defaulting to Local Lib Folders!")
6564
traceback.print_exc()

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
@@ -128,7 +128,7 @@ STATIC mp_obj_t lte_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
128128

129129
STATIC mp_obj_t lte_deinit(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
130130
STATIC mp_obj_t lte_disconnect(mp_obj_t self_in);
131-
131+
static void lte_set_default_inf(void);
132132
/******************************************************************************
133133
DEFINE PUBLIC FUNCTIONS
134134
******************************************************************************/
@@ -322,6 +322,11 @@ static void lte_check_init(void) {
322322
}
323323
}
324324

325+
static void lte_set_default_inf(void)
326+
{
327+
lteppp_set_default_inf();
328+
}
329+
325330
static void lte_check_inppp(void) {
326331
if (lteppp_get_state() == E_LTE_PPP) {
327332
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "LTE modem is in data state, cannot send AT commands"));
@@ -1385,4 +1390,5 @@ const mod_network_nic_type_t mod_network_nic_type_lte = {
13851390
.n_ioctl = lwipsocket_socket_ioctl,
13861391
.n_setupssl = lwipsocket_socket_setup_ssl,
13871392
.inf_up = ltepp_is_ppp_conn_up,
1393+
.set_default_inf = lte_set_default_inf
13881394
};

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
@@ -124,6 +124,10 @@ static bool is_inf_up = false;
124124

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

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

946-
STATIC void wlan_inf_up(void)
954+
STATIC void wlan_set_default_inf(void)
947955
{
956+
#if defined(FIPY) || defined(GPY)
948957
if (wlan_obj.mode == WIFI_MODE_STA || wlan_obj.mode == WIFI_MODE_APSTA) {
958+
tcpip_adapter_set_dns_info(TCPIP_ADAPTER_IF_STA, TCPIP_ADAPTER_DNS_MAIN, &wlan_sta_inf_dns_info);
949959
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
950-
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
951-
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
952960
}
961+
#endif
953962
}
954963

955964
//STATIC void wlan_get_sl_mac (void) {
@@ -2619,7 +2628,7 @@ const mod_network_nic_type_t mod_network_nic_type_wlan = {
26192628
.n_ioctl = lwipsocket_socket_ioctl,
26202629
.n_setupssl = lwipsocket_socket_setup_ssl,
26212630
.inf_up = wlan_is_inf_up,
2622-
.set_inf_up = wlan_inf_up
2631+
.set_default_inf = wlan_set_default_inf
26232632
};
26242633

26252634
//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)
0