Skip to content

Commit fcc4e68

Browse files
committed
app: PPP fixes for recovery
Decrease LCP timeouts to one second. We don't need to realistically wait for longer on the Serial Modem side. Max retransmits set to 5 times, so total timeout is 5 seconds. Increase PPPD holdoff to twice of that, so it is 10 seconds. This allows enough time for Zephyr side to tear down the connection. Retry the net_if_down() as the first attempt might fail when there is heavy traffic. The LCP packet is still queued, so the second retry just tears down the interface in dormant state, so it does not send the LCP anymore. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent f89eb35 commit fcc4e68

3 files changed

Lines changed: 29 additions & 22 deletions

File tree

app/overlay-ppp.conf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ CONFIG_NET_L2_PPP_MGMT=y
2222
CONFIG_NET_L2_PPP_OPTION_MRU=y
2323
CONFIG_NET_L2_PPP_OPTION_SERVE_IP=y
2424
CONFIG_NET_L2_PPP_OPTION_SERVE_DNS=y
25-
CONFIG_NET_L2_PPP_TIMEOUT=5000
26-
CONFIG_NET_L2_PPP_MAX_CONFIGURE_REQ_RETRANSMITS=20
25+
CONFIG_NET_L2_PPP_TIMEOUT=1000
26+
CONFIG_NET_L2_PPP_MAX_CONFIGURE_REQ_RETRANSMITS=5
27+
CONFIG_NET_L2_PPP_MAX_TERMINATE_REQ_RETRANSMITS=5
28+
CONFIG_NET_IF_MAX_IPV4_COUNT=4
29+
CONFIG_NET_IF_MAX_IPV6_COUNT=4
2730

2831
# IP stack
2932
CONFIG_NET_IP_ADDR_CHECK=n

app/scripts/sm2_start_ppp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ linkname nrf91
114114
local
115115
passive
116116
persist
117-
holdoff 5
117+
holdoff 10
118118
nodetach
119119
noauth
120120
noipdefault

app/src/sm_ppp.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ static struct modem_pipe *ppp_urc_pipe;
4646
static struct k_thread ppp_data_passing_thread_id;
4747
static k_timepoint_t ppp_pdn_timeout;
4848
static K_THREAD_STACK_DEFINE(ppp_data_passing_thread_stack, KB(2));
49-
static void ppp_data_passing_thread(void*, void*, void*);
50-
static void sm_ppp_activate_pdp_dwork_fn(struct k_work *work);
51-
static K_WORK_DELAYABLE_DEFINE(activate_pdp_dwork, sm_ppp_activate_pdp_dwork_fn);
5249

5350
enum ppp_action {
5451
PPP_START,
@@ -104,6 +101,13 @@ const char *const ppp_socket_names[PPP_FDS_COUNT] = {
104101
};
105102
static int ppp_fds[PPP_FDS_COUNT] = { -1, -1, -1 };
106103

104+
/* Forward declarations */
105+
static void ppp_data_passing_thread(void*, void*, void*);
106+
static void sm_ppp_activate_pdp_dwork_fn(struct k_work *work);
107+
static int ppp_stop(enum ppp_reason reason);
108+
static void ppp_cmd_fail_return_to_at_mode(void);
109+
static K_WORK_DELAYABLE_DEFINE(activate_pdp_dwork, sm_ppp_activate_pdp_dwork_fn);
110+
107111
static const char *ppp_action_str(enum ppp_action action)
108112
{
109113
switch (action) {
@@ -374,13 +378,7 @@ static int ppp_start(void)
374378
return 0;
375379

376380
error:
377-
ppp_state = PPP_STATE_STOPPED;
378-
379-
if (ppp_pipe) {
380-
modem_ppp_release(&ppp_module);
381-
sm_at_host_attach(ppp_pipe);
382-
}
383-
ppp_pipe = NULL;
381+
ppp_stop(PPP_REASON_ERROR);
384382
return ret;
385383
}
386384

@@ -399,6 +397,7 @@ static int ppp_stop(enum ppp_reason reason)
399397
}
400398

401399
ppp_state = PPP_STATE_STOPPING;
400+
close_ppp_sockets();
402401

403402
if (sm_ppp_keep_pipe_attached) {
404403
switch (reason) {
@@ -415,13 +414,19 @@ static int ppp_stop(enum ppp_reason reason)
415414
at_monitor_pause(&sm_ppp_on_cgev);
416415
}
417416

418-
/* Bring the interface down before releasing pipes and carrier.
419-
* This is needed for LCP to notify the remote endpoint that the link is going down.
420-
*/
421-
int ret = net_if_down(ppp_iface);
417+
if (net_if_is_admin_up(ppp_iface)) {
418+
/* Bring the interface down before releasing pipes and carrier.
419+
* This is needed for LCP to notify the remote endpoint that the link is going down.
420+
*/
421+
int ret = net_if_down(ppp_iface);
422422

423-
if (ret) {
424-
LOG_WRN("Failed to bring PPP interface down (%d).", ret);
423+
if (ret) {
424+
LOG_WRN("Failed to bring PPP interface down (%d).", ret);
425+
/* Retry later */
426+
net_if_dormant_on(ppp_iface);
427+
delegate_ppp_event(PPP_STOP, reason);
428+
return ret;
429+
}
425430
}
426431

427432
modem_ppp_release(&ppp_module);
@@ -436,8 +441,6 @@ static int ppp_stop(enum ppp_reason reason)
436441
net_if_carrier_off(ppp_iface);
437442
net_if_dormant_on(ppp_iface);
438443

439-
close_ppp_sockets();
440-
441444
ppp_state = PPP_STATE_STOPPED;
442445
send_status_notification();
443446

@@ -933,6 +936,7 @@ static void ppp_data_passing_thread(void*, void*, void*)
933936
} else {
934937
LOG_DBG("Connection down. Stop.");
935938
}
939+
ppp_state = PPP_STATE_STOPPING;
936940
delegate_ppp_event(PPP_STOP, PPP_REASON_NETWORK);
937941
continue;
938942
}
@@ -975,7 +979,7 @@ static void ppp_data_passing_thread(void*, void*, void*)
975979
LOG_ERR("Only sent %zd out of %zd bytes to %s socket.",
976980
send_ret, len, ppp_socket_names[dst]);
977981
} else {
978-
LOG_DBG("Forwarded %zd bytes to %s socket.",
982+
LOG_DBG_RATELIMIT_RATE(5000, "Forwarded %zd bytes to %s socket.",
979983
send_ret, ppp_socket_names[dst]);
980984
}
981985
}

0 commit comments

Comments
 (0)