From 83ea1e26a2c409e7007230f901b8610602903871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jani=20Hirsim=C3=A4ki?= Date: Tue, 8 Aug 2023 13:28:05 +0300 Subject: [PATCH] net: l2: ppp: ppp uart usage fixed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes 3 issues that came within PR #59124 for ppp uart usage. Earlier start/stop of ppp was done at enable() but that was removed in PR #59124. Now putting enable/disable() back and putting start/stop there. Additionally, there was a double ppp carrier ON when NET_EVENT_IF_DOWN. For that net_if_carrier_on/off is set in uart ppp.c driver. Also, maybe worth to be mentioned that after PR #59124 there is no ppp carrier off when lcp is disconnected, for workaround that change, application should use ppp dead/running events. Signed-off-by: Jani Hirsimäki --- drivers/net/ppp.c | 3 ++- include/zephyr/net/ppp.h | 3 +++ subsys/net/l2/ppp/ppp_internal.h | 2 -- subsys/net/l2/ppp/ppp_l2.c | 27 +++++++++++++++++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/ppp.c b/drivers/net/ppp.c index 4db963beeb7..1e1ce474095 100644 --- a/drivers/net/ppp.c +++ b/drivers/net/ppp.c @@ -1046,7 +1046,7 @@ static int ppp_start(const struct device *dev) } #endif /* !CONFIG_NET_TEST */ - ARG_UNUSED(context); + net_if_carrier_on(context->iface); return 0; } @@ -1054,6 +1054,7 @@ static int ppp_stop(const struct device *dev) { struct ppp_driver_context *context = dev->data; + net_if_carrier_off(context->iface); context->modem_init_done = false; return 0; } diff --git a/include/zephyr/net/ppp.h b/include/zephyr/net/ppp.h index 686f34aecf2..4067d37f4cc 100644 --- a/include/zephyr/net/ppp.h +++ b/include/zephyr/net/ppp.h @@ -489,6 +489,9 @@ struct ppp_context { /** Is PPP ready to receive packets */ uint16_t is_ready_to_serve : 1; + /** Is PPP L2 enabled or not */ + uint16_t is_enabled : 1; + /** PPP enable pending */ uint16_t is_enable_done : 1; diff --git a/subsys/net/l2/ppp/ppp_internal.h b/subsys/net/l2/ppp/ppp_internal.h index 0603f1e27b8..c5b5a9547f6 100644 --- a/subsys/net/l2/ppp/ppp_internal.h +++ b/subsys/net/l2/ppp/ppp_internal.h @@ -213,5 +213,3 @@ static inline bool ppp_my_option_is_acked(struct ppp_fsm *fsm, { return ppp_my_option_flags(fsm, code) & PPP_MY_OPTION_ACKED; } - -void ppp_if_carrier_down(struct net_if *iface); diff --git a/subsys/net/l2/ppp/ppp_l2.c b/subsys/net/l2/ppp/ppp_l2.c index 63b4b5d57fe..b949c491406 100644 --- a/subsys/net/l2/ppp/ppp_l2.c +++ b/subsys/net/l2/ppp/ppp_l2.c @@ -17,7 +17,6 @@ LOG_MODULE_REGISTER(net_l2_ppp, CONFIG_NET_L2_PPP_LOG_LEVEL); #include #include "net_private.h" -#include "ipv4_autoconf_internal.h" #include "ppp_stats.h" #include "ppp_internal.h" @@ -218,7 +217,31 @@ static enum net_l2_flags ppp_flags(struct net_if *iface) return ctx->ppp_l2_flags; } -NET_L2_INIT(PPP_L2, ppp_recv, ppp_send, NULL, ppp_flags); +static int ppp_enable(struct net_if *iface, bool state) +{ + const struct ppp_api *ppp = + net_if_get_device(iface)->api; + struct ppp_context *ctx = net_if_l2_data(iface); + + if (ctx->is_enabled == state) { + return 0; + } + + ctx->is_enabled = state; + + if (!state) { + if (ppp->stop) { + ppp->stop(net_if_get_device(iface)); + } + } else { + if (ppp->start) { + ppp->start(net_if_get_device(iface)); + } + } + return 0; +} + +NET_L2_INIT(PPP_L2, ppp_recv, ppp_send, ppp_enable, ppp_flags); #if defined(CONFIG_NET_SHELL) static int get_ppp_context(int idx, struct ppp_context **ctx,