8000 [v1.20.0.rc12.1] Fix wlan sta interface terminating after lte disconnect by iwahdan88 · Pull Request #325 · pycom/pycom-micropython-sigfox · 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.

[v1.20.0.rc12.1] Fix wlan sta interface terminating after lte disconnect #325

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion esp32/get_idf_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def main():
shutil.copy(src + '/vfs/libvfs.a', dsttmpapp)
shutil.copy(src + '/wpa_supplicant/libwpa_supplicant.a', dsttmpapp)
shutil.copy(src + '/xtensa-debug-module/libxtensa-debug-module.a', dsttmpapp)
shutil.copy(src + '/openthread/libopenthread.a', dsttmpapp)
except:
print("Couldn't Copy IDF libs defaulting to Local Lib Folders!")
traceback.print_exc()
Expand Down
16 changes: 16 additions & 0 deletions esp32/lte/lteppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "pins.h"
#include "mpsleep.h"
#include "esp32_mphal.h"
#include "lwip/dns.h"

/******************************************************************************
DEFINE CONSTANTS
Expand Down Expand Up @@ -78,6 +79,8 @@ static bool ltepp_ppp_conn_up = false;

static ltepppconnstatus_t lteppp_connstatus = LTE_PPP_IDLE;

static ip_addr_t ltepp_dns_info[2]={0};

/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
Expand Down Expand Up @@ -188,6 +191,14 @@ void lteppp_set_state(lte_state_t state) {
xSemaphoreGive(xLTESem);
}

void lteppp_set_default_inf(void)
{
pppapi_set_default(lteppp_pcb);
//Restore DNS
dns_setserver(0, &(ltepp_dns_info[0]));
dns_setserver(1, &(ltepp_dns_info[1]));
}

void lteppp_set_legacy(lte_legacy_t legacy) {
xSemaphoreTake(xLTESem, portMAX_DELAY);
lteppp_lte_legacy = legacy;
Expand Down Expand Up @@ -656,6 +667,11 @@ static void lteppp_status_cb (ppp_pcb *pcb, int err_code, void *ctx) {
lte_gw = pppif->gw.u_addr.ip4.addr;
lte_netmask = pppif->netmask.u_addr.ip4.addr;
lte_ipv4addr = pppif->ip_addr.u_addr.ip4.addr;
if(lte_ipv4addr > 0)
{
ltepp_dns_info[0] = dns_getserver(0);
ltepp_dns_info[1] = dns_getserver(1);
}
// printf("ipaddr = %s\n", ipaddr_ntoa(&pppif->ip_addr));
// printf("gateway = %s\n", ipaddr_ntoa(&pppif->gw));
// printf("netmask = %s\n", ipaddr_ntoa(&pppif->netmask));
Expand Down
2 changes: 2 additions & 0 deletions esp32/lte/lteppp.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ extern bool ltepp_is_ppp_conn_up(void);
extern void lteppp_suspend(void);

extern void lteppp_resume(void);

extern void lteppp_set_default_inf(void);
#ifdef LTE_DEBUG_BUFF
extern char* lteppp_get_log_buff(void);
#endif
Expand Down
8 changes: 7 additions & 1 deletion esp32/mods/modlte.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ STATIC mp_obj_t lte_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t

STATIC mp_obj_t lte_deinit(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
STATIC mp_obj_t lte_disconnect(mp_obj_t self_in);

static void lte_set_default_inf(void);
/******************************************************************************
DEFINE PUBLIC FUNCTIONS
******************************************************************************/
Expand Down Expand Up @@ -322,6 +322,11 @@ static void lte_check_init(void) {
}
}

static void lte_set_default_inf(void)
{
lteppp_set_default_inf();
}

static void lte_check_inppp(void) {
if (lteppp_get_state() == E_LTE_PPP) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "LTE modem is in data state, cannot send AT commands"));
Expand Down Expand Up @@ -1385,4 +1390,5 @@ const mod_network_nic_type_t mod_network_nic_type_lte = {
.n_ioctl = lwipsocket_socket_ioctl,
.n_setupssl = lwipsocket_socket_setup_ssl,
.inf_up = ltepp_is_ppp_conn_up,
.set_default_inf = lte_set_default_inf
};
6 changes: 2 additions & 4 deletions esp32/mods/modnetwork.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ void mod_network_deregister_nic(mp_obj_t nic) {
mp_obj_t nic_rem = MP_STATE_PORT(mod_network_nic_list).items[i];
if(mp_obj_get_type(nic_rem) == (mp_obj_type_t *)&mod_network_nic_type_wlan)
{
mod_network_nic_type_wlan.set_inf_up();
mod_network_nic_type_wlan.set_default_inf();
}
else if (mp_obj_get_type(nic_rem) == (mp_obj_type_t *)&mod_network_nic_type_lte)
{
if (mod_network_nic_type_lte.set_inf_up != NULL) {
mod_network_nic_type_lte.set_inf_up();
}
mod_network_nic_type_lte.set_default_inf();
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion esp32/mods/modnetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ typedef struct _mod_network_nic_type_t {
// Interface status
bool (*inf_up)(void);
// Bring Inf_up
void (*set_inf_up)(void);
void (*set_default_inf)(void);
} mod_network_nic_type_t;

typedef struct _mod_network_socket_base_t {
Expand Down
21 changes: 15 additions & 6 deletions esp32/mods/modwlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ static bool is_inf_up = false;

//mutex for Timeout Counter protection
SemaphoreHandle_t timeout_mutex;
#if defined(FIPY) || defined(GPY)
// Variable saving DNS info
static tcpip_adapter_dns_info_t wlan_sta_inf_dns_info;
#endif

/******************************************************************************
DECLARE PUBLIC DATA
Expand Down Expand Up @@ -157,7 +161,7 @@ static void wlan_timer_callback( TimerHandle_t xTimer );
static void wlan_validate_country(const char * country);
static void wlan_validate_country_policy(uint8_t policy);
STATIC void wlan_stop_sta_conn_timer();
STATIC void wlan_inf_up(void);
STATIC void wlan_set_default_inf(void);
//*****************************************************************************
//
//! \brief The Function Handles WLAN Events
Expand Down Expand Up @@ -347,7 +351,11 @@ STATIC esp_err_t wlan_event_handler(void *ctx, system_event_t *event) {
break;
case SYSTEM_EVENT_STA_GOT_IP: /**< ESP32 station got IP from connected AP */
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
is_inf_up = true;
#if defined(FIPY) || defined(GPY)
// Save DNS info for restoring if wifi inf is usable again after LTE disconnect
tcpip_adapter_get_dns_info(TCPIP_ADAPTER_IF_STA, TCPIP_ADAPTER_DNS_MAIN, &wlan_sta_inf_dns_info);
#endif
is_inf_up = true;
break;
case SYSTEM_EVENT_STA_DISCONNECTED: /**< ESP32 station disconnected from AP */
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
Expand Down Expand Up @@ -943,13 +951,14 @@ STATIC void promiscuous_callback(void *buf, wifi_promiscuous_pkt_type_t type)
}
}

STATIC void wlan_inf_up(void)
STATIC void wlan_set_default_inf(void)
{
#if defined(FIPY) || defined(GPY)
if (wlan_obj.mode == WIFI_MODE_STA || wlan_obj.mode == WIFI_MODE_APSTA) {
tcpip_adapter_set_dns_info(TCPIP_ADAPTER_IF_STA, TCPIP_ADAPTER_DNS_MAIN, &wlan_sta_inf_dns_info);
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
}
#endif
}

//STATIC void wlan_get_sl_mac (void) {
Expand Down Expand Up @@ -2619,7 +2628,7 @@ const mod_network_nic_type_t mod_network_nic_type_wlan = {
.n_ioctl = lwipsocket_socket_ioctl,
.n_setupssl = lwipsocket_socket_setup_ssl,
.inf_up = wlan_is_inf_up,
.set_inf_up = wlan_inf_up
.set_default_inf = wlan_set_default_inf
};

//STATIC const mp_irq_methods_t wlan_irq_methods = {
Expand Down
2 changes: 1 addition & 1 deletion esp32/pycom_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef VERSION_H_
#define VERSION_H_

#define SW_VERSION_NUMBER "1.20.0.rc12"
#define SW_VERSION_NUMBER "1.20.0.rc12.1"

#define LORAWAN_VERSION_NUMBER "1.0.2"

Expand Down
0