net: l2: ppp: ppp uart usage fixed

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 <jani.hirsimaki@nordicsemi.no>
This commit is contained in:
Jani Hirsimäki 2023-08-08 13:28:05 +03:00 committed by Fabio Baltieri
commit 83ea1e26a2
4 changed files with 30 additions and 5 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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);

View file

@ -17,7 +17,6 @@ LOG_MODULE_REGISTER(net_l2_ppp, CONFIG_NET_L2_PPP_LOG_LEVEL);
#include <zephyr/sys/iterable_sections.h>
#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,