Skip to content
Permalink
Browse files

net: ppp: Allow delay of PPP protocol handshakes

By default PPP is started immediately when the network interface
goes up. This can be problematic especially when debugging the beast
so allow user to delay the startup.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed May 8, 2019
1 parent d092482 commit 3e481f9d07499ab4f1fa1c0e3811fb4f0d41928c
Showing with 78 additions and 23 deletions.
  1. +9 −0 include/net/ppp.h
  2. +10 −0 subsys/net/l2/ppp/Kconfig
  3. +59 −23 subsys/net/l2/ppp/ppp_l2.c
@@ -351,6 +351,9 @@ struct ipv6cp_options {

/** PPP L2 context specific to certain network interface */
struct ppp_context {
/** PPP startup worker. */
struct k_delayed_work startup;

struct {
/** Carrier ON/OFF handler worker. This is used to create
* network interface UP/DOWN event when PPP L2 driver
@@ -459,6 +462,12 @@ struct ppp_context {
/** Is PPP L2 enabled or not */
u16_t is_enabled : 1;

/** PPP startup pending */
u16_t is_startup_pending : 1;

/** PPP enable pending */
u16_t is_enable_done : 1;

/** Network status (up / down) */
u16_t is_network_up : 1;

@@ -11,6 +11,16 @@ menuconfig NET_L2_PPP

if NET_L2_PPP

config NET_L2_PPP_DELAY_STARTUP_MS
int "PPP delay startup ms"
default 0
help
If the PPP starts too fast, it is possible to delay it
a bit. This is mostly useful in debugging if you want the
device be fully up before PPP handshake is started.
Wait amount of milliseconds before starting PPP. Value 0 disables
the wait.

config NET_L2_PPP_TIMEOUT
int "Maximum timeout in ms for Configure-Req"
default 3000
@@ -222,7 +222,11 @@ static int ppp_enable(struct net_if *iface, bool state)
ppp->start(net_if_get_device(iface));
}

start_ppp(ctx);
if (ctx->is_startup_pending) {
ctx->is_enable_done = true;
} else {
start_ppp(ctx);
}
}

return 0;
@@ -370,10 +374,53 @@ const struct ppp_protocol_handler *ppp_lcp_get(void)
return ppp_lcp;
}

static void ppp_startup(struct k_work *work)
{
struct ppp_context *ctx = CONTAINER_OF(work, struct ppp_context,
startup);
const struct ppp_protocol_handler *proto;
int count;

if (!ctx->is_init) {
return;
}

NET_DBG("PPP %p startup for interface %p", ctx, ctx->iface);

for (proto = __net_ppp_proto_start, count = 0;
proto != __net_ppp_proto_end;
proto++, count++) {
if (proto->protocol == PPP_LCP) {
ppp_lcp = proto;
}

proto->init(ctx);
}

if (count == 0) {
NET_ERR("There are no PPP protocols configured!");
goto bail_out;
}

if (ppp_lcp == NULL) {
NET_ERR("No LCP found!");
goto bail_out;
}

ctx->is_ready_to_serve = true;

bail_out:
ctx->is_startup_pending = false;

if (ctx->is_enable_done) {
start_ppp(ctx);
ctx->is_enable_done = false;
}
}

void net_ppp_init(struct net_if *iface)
{
struct ppp_context *ctx = net_if_l2_data(iface);
const struct ppp_protocol_handler *proto;

NET_DBG("Initializing PPP L2 %p for iface %p", ctx, iface);

@@ -385,33 +432,22 @@ void net_ppp_init(struct net_if *iface)
ctx->iface = iface;

if (!ctx->is_init) {
int count;
ctx->is_init = true;

#if defined(CONFIG_NET_SHELL)
k_sem_init(&ctx->shell.wait_echo_reply, 0, UINT_MAX);
#endif

for (proto = __net_ppp_proto_start, count = 0;
proto != __net_ppp_proto_end;
proto++, count++) {
if (proto->protocol == PPP_LCP) {
ppp_lcp = proto;
}

proto->init(ctx);
}
/* TODO: Unify the startup worker code so that we can save
* some memory if there are more than one PPP context in the
* system. The issue is not very likely as typically there
* would be only one PPP network interface in the system.
*/
k_delayed_work_init(&ctx->startup, ppp_startup);

if (count == 0) {
NET_ERR("There are no PPP protocols configured!");
return;
}
ctx->is_startup_pending = true;

if (ppp_lcp == NULL) {
NET_ERR("No LCP found!");
return;
}
k_delayed_work_submit(&ctx->startup,
K_MSEC(CONFIG_NET_L2_PPP_DELAY_STARTUP_MS));
}

ctx->is_init = true;
ctx->is_ready_to_serve = true;
}

0 comments on commit 3e481f9

Please sign in to comment.
You can’t perform that action at this time.