Skip to content
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
7 changes: 5 additions & 2 deletions app/overlay-ppp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ CONFIG_NET_L2_PPP_MGMT=y
CONFIG_NET_L2_PPP_OPTION_MRU=y
CONFIG_NET_L2_PPP_OPTION_SERVE_IP=y
CONFIG_NET_L2_PPP_OPTION_SERVE_DNS=y
CONFIG_NET_L2_PPP_TIMEOUT=5000
CONFIG_NET_L2_PPP_MAX_CONFIGURE_REQ_RETRANSMITS=20
CONFIG_NET_L2_PPP_TIMEOUT=1000
CONFIG_NET_L2_PPP_MAX_CONFIGURE_REQ_RETRANSMITS=5
CONFIG_NET_L2_PPP_MAX_TERMINATE_REQ_RETRANSMITS=5
CONFIG_NET_IF_MAX_IPV4_COUNT=4
CONFIG_NET_IF_MAX_IPV6_COUNT=4

# IP stack
CONFIG_NET_IP_ADDR_CHECK=n
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/sm2_start_ppp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ linkname nrf91
local
passive
persist
holdoff 5
holdoff 10
nodetach
noauth
noipdefault
Expand Down
44 changes: 24 additions & 20 deletions app/src/sm_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ static struct modem_pipe *ppp_urc_pipe;
static struct k_thread ppp_data_passing_thread_id;
static k_timepoint_t ppp_pdn_timeout;
static K_THREAD_STACK_DEFINE(ppp_data_passing_thread_stack, KB(2));
static void ppp_data_passing_thread(void*, void*, void*);
static void sm_ppp_activate_pdp_dwork_fn(struct k_work *work);
static K_WORK_DELAYABLE_DEFINE(activate_pdp_dwork, sm_ppp_activate_pdp_dwork_fn);

enum ppp_action {
PPP_START,
Expand Down Expand Up @@ -104,6 +101,13 @@ const char *const ppp_socket_names[PPP_FDS_COUNT] = {
};
static int ppp_fds[PPP_FDS_COUNT] = { -1, -1, -1 };

/* Forward declarations */
static void ppp_data_passing_thread(void*, void*, void*);
static void sm_ppp_activate_pdp_dwork_fn(struct k_work *work);
static int ppp_stop(enum ppp_reason reason);
static void ppp_cmd_fail_return_to_at_mode(void);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void ppp_cmd_fail_return_to_at_mode(void);

static K_WORK_DELAYABLE_DEFINE(activate_pdp_dwork, sm_ppp_activate_pdp_dwork_fn);

static const char *ppp_action_str(enum ppp_action action)
{
switch (action) {
Expand Down Expand Up @@ -374,13 +378,7 @@ static int ppp_start(void)
return 0;

error:
ppp_state = PPP_STATE_STOPPED;

if (ppp_pipe) {
modem_ppp_release(&ppp_module);
sm_at_host_attach(ppp_pipe);
}
ppp_pipe = NULL;
ppp_stop(PPP_REASON_ERROR);
return ret;
}

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

ppp_state = PPP_STATE_STOPPING;
close_ppp_sockets();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to make this earlier? To close them even if the interface closure fails?

Could there still be data coming when ppp_stop has been called?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was suspecting that these sockets would have been one reason why closing the interface fails.

They keep forwarding traffic, so it can cumulate data and block the LCP messages going through.

I'm unsure if there was any real effect of this after all, but it does not seem to break anything doing it in this order.


if (sm_ppp_keep_pipe_attached) {
switch (reason) {
Expand All @@ -415,13 +414,19 @@ static int ppp_stop(enum ppp_reason reason)
at_monitor_pause(&sm_ppp_on_cgev);
}

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

if (ret) {
LOG_WRN("Failed to bring PPP interface down (%d).", ret);
if (ret) {
LOG_WRN("Failed to bring PPP interface down (%d).", ret);
/* Retry later */
net_if_dormant_on(ppp_iface);
delegate_ppp_event(PPP_STOP, reason);
return ret;
}
}

modem_ppp_release(&ppp_module);
Expand All @@ -436,8 +441,6 @@ static int ppp_stop(enum ppp_reason reason)
net_if_carrier_off(ppp_iface);
net_if_dormant_on(ppp_iface);

close_ppp_sockets();

ppp_state = PPP_STATE_STOPPED;
send_status_notification();

Expand Down Expand Up @@ -692,7 +695,7 @@ static int sm_ppp_init(void)
k_thread_create(&ppp_data_passing_thread_id, ppp_data_passing_thread_stack,
K_THREAD_STACK_SIZEOF(ppp_data_passing_thread_stack),
ppp_data_passing_thread, NULL, NULL, NULL,
K_PRIO_COOP(10), 0, K_NO_WAIT);
K_LOWEST_APPLICATION_THREAD_PRIO, 0, K_NO_WAIT);
k_thread_name_set(&ppp_data_passing_thread_id, "ppp_data_passing");

ppp_iface = modem_ppp_get_iface(&ppp_module);
Expand Down Expand Up @@ -933,6 +936,7 @@ static void ppp_data_passing_thread(void*, void*, void*)
} else {
LOG_DBG("Connection down. Stop.");
}
ppp_state = PPP_STATE_STOPPING;
delegate_ppp_event(PPP_STOP, PPP_REASON_NETWORK);
continue;
}
Expand Down Expand Up @@ -975,7 +979,7 @@ static void ppp_data_passing_thread(void*, void*, void*)
LOG_ERR("Only sent %zd out of %zd bytes to %s socket.",
send_ret, len, ppp_socket_names[dst]);
} else {
LOG_DBG("Forwarded %zd bytes to %s socket.",
LOG_DBG_RATELIMIT_RATE(5000, "Forwarded %zd bytes to %s socket.",
send_ret, ppp_socket_names[dst]);
}
}
Expand Down
Loading