Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | /*
* Copyright (c) 2019 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <logging/log.h>
LOG_MODULE_DECLARE(net_l2_ppp, CONFIG_NET_L2_PPP_LOG_LEVEL);
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/ppp.h>
#include "net_private.h"
#include "ppp_internal.h"
static void lcp_up(struct ppp_context *ctx)
{
struct ppp_protocol_handler *proto;
for (proto = __net_ppp_proto_start;
proto != __net_ppp_proto_end;
proto++) {
if (proto->protocol == PPP_LCP) {
continue;
}
if (proto->lower_up) {
proto->lower_up(ctx);
}
}
}
static void do_network(struct ppp_context *ctx)
{
const struct ppp_protocol_handler *proto;
ppp_change_phase(ctx, PPP_NETWORK);
for (proto = __net_ppp_proto_start;
proto != __net_ppp_proto_end;
proto++) {
if (proto->protocol == PPP_CCP || proto->protocol == PPP_ECP) {
if (proto->open) {
proto->open(ctx);
}
}
}
/* Do the other network protocols if encryption is not needed for
* them.
*/
/* TODO possible encryption stuff here*/
for (proto = __net_ppp_proto_start;
proto != __net_ppp_proto_end;
proto++) {
if (proto->protocol == PPP_CCP || proto->protocol == PPP_ECP ||
proto->protocol >= 0xC000) {
continue;
}
if (proto->open) {
ctx->network_protos_open++;
proto->open(ctx);
}
}
if (ctx->network_protos_open == 0) {
proto = ppp_lcp_get();
if (proto) {
proto->close(ctx, "No network protocols open");
}
}
}
void ppp_link_established(struct ppp_context *ctx, struct ppp_fsm *fsm)
{
NET_DBG("[%p] Link established", ctx);
ppp_change_phase(ctx, PPP_ESTABLISH);
ppp_change_phase(ctx, PPP_AUTH);
/* If no authentication is need, then we are done */
/* TODO: check here if auth is needed */
do_network(ctx);
lcp_up(ctx);
}
void ppp_link_terminated(struct ppp_context *ctx)
{
if (ctx->phase == PPP_DEAD) {
return;
}
/* TODO: cleanup things etc here if needed */
ppp_change_phase(ctx, PPP_DEAD);
NET_DBG("[%p] Link terminated", ctx);
}
void ppp_link_down(struct ppp_context *ctx)
{
if (ctx->phase == PPP_DEAD) {
return;
}
ppp_change_phase(ctx, PPP_NETWORK);
ppp_network_all_down(ctx);
ppp_change_phase(ctx, PPP_DEAD);
}
void ppp_link_needed(struct ppp_context *ctx)
{
/* TODO: Try to create link if needed. */
}
|