@@ -46,9 +46,6 @@ static struct modem_pipe *ppp_urc_pipe;
4646static struct k_thread ppp_data_passing_thread_id ;
4747static k_timepoint_t ppp_pdn_timeout ;
4848static 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
5350enum ppp_action {
5451 PPP_START ,
@@ -104,6 +101,13 @@ const char *const ppp_socket_names[PPP_FDS_COUNT] = {
104101};
105102static 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+
107111static 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
376380error :
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
@@ -692,7 +695,7 @@ static int sm_ppp_init(void)
692695 k_thread_create (& ppp_data_passing_thread_id , ppp_data_passing_thread_stack ,
693696 K_THREAD_STACK_SIZEOF (ppp_data_passing_thread_stack ),
694697 ppp_data_passing_thread , NULL , NULL , NULL ,
695- K_PRIO_COOP ( 10 ) , 0 , K_NO_WAIT );
698+ K_LOWEST_APPLICATION_THREAD_PRIO , 0 , K_NO_WAIT );
696699 k_thread_name_set (& ppp_data_passing_thread_id , "ppp_data_passing" );
697700
698701 ppp_iface = modem_ppp_get_iface (& ppp_module );
@@ -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