PPP, added PPP notify phase support

PPP notify phase support, using compile-time PPP_NOTIFY_PHASE macro.

This can be used for example to set a LED pattern depending on the
current phase of the PPP session.

Callback example:

static void ppp_notify_phase_cb(ppp_pcb *pcb, u8_t phase, void *ctx) {
  switch(phase) {
      case PPP_PHASE_DEAD:  /* Kept off */
      case PPP_PHASE_MASTER:
        /* LED Off */
        break;
      case PPP_PHASE_INITIALIZE:  /* Session opened */
        /* LED FastBlink */
        break;
      case PPP_PHASE_RUNNING:  /* Session running */
        /* LED On */
        break;
      default:
        /* LED SlowBlink */
   }
}
This commit is contained in:
Sylvain Rochet 2013-04-30 15:16:09 +02:00
parent 2ceae6014e
commit 4fda366b67
8 changed files with 140 additions and 86 deletions

View File

@ -102,13 +102,36 @@ void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd) {
} }
#if PPP_NOTIFY_PHASE
/**
* Call ppp_set_notify_phase_callback() inside the tcpip_thread context.
*/
static void pppapi_do_ppp_set_notify_phase_callback(struct pppapi_msg_msg *msg) {
ppp_set_notify_phase_callback(msg->ppp, msg->msg.setnotifyphasecb.notify_phase_cb);
TCPIP_PPPAPI_ACK(msg);
}
/**
* Call ppp_set_notify_phase_callback() in a thread-safe way by running that function inside the
* tcpip_thread context.
*/
void pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb) {
struct pppapi_msg msg;
msg.function = pppapi_do_ppp_set_notify_phase_callback;
msg.msg.ppp = pcb;
msg.msg.msg.setnotifyphasecb.notify_phase_cb = notify_phase_cb;
TCPIP_PPPAPI(&msg);
}
#endif /* PPP_NOTIFY_PHASE */
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
/** /**
* Call ppp_over_serial_create() inside the tcpip_thread context. * Call ppp_over_serial_create() inside the tcpip_thread context.
*/ */
static void pppapi_do_ppp_over_serial_create(struct pppapi_msg_msg *msg) { static void pppapi_do_ppp_over_serial_create(struct pppapi_msg_msg *msg) {
msg->err = ppp_over_serial_create(msg->ppp, msg->msg.serialcreate.fd, msg->err = ppp_over_serial_create(msg->ppp, msg->msg.serialcreate.fd,
msg->msg.serialcreate.link_status_cb, msg->msg.serialcreate.link_status_ctx); msg->msg.serialcreate.link_status_cb, msg->msg.serialcreate.ctx_cb);
TCPIP_PPPAPI_ACK(msg); TCPIP_PPPAPI_ACK(msg);
} }
@ -116,13 +139,13 @@ static void pppapi_do_ppp_over_serial_create(struct pppapi_msg_msg *msg) {
* Call ppp_over_serial_create() in a thread-safe way by running that function inside the * Call ppp_over_serial_create() in a thread-safe way by running that function inside the
* tcpip_thread context. * tcpip_thread context.
*/ */
int pppapi_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { int pppapi_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
struct pppapi_msg msg; struct pppapi_msg msg;
msg.function = pppapi_do_ppp_over_serial_create; msg.function = pppapi_do_ppp_over_serial_create;
msg.msg.ppp = pcb; msg.msg.ppp = pcb;
msg.msg.msg.serialcreate.fd = fd; msg.msg.msg.serialcreate.fd = fd;
msg.msg.msg.serialcreate.link_status_cb = link_status_cb; msg.msg.msg.serialcreate.link_status_cb = link_status_cb;
msg.msg.msg.serialcreate.link_status_ctx = link_status_ctx; msg.msg.msg.serialcreate.ctx_cb = ctx_cb;
TCPIP_PPPAPI(&msg); TCPIP_PPPAPI(&msg);
return msg.msg.err; return msg.msg.err;
} }
@ -137,7 +160,7 @@ static void pppapi_do_ppp_over_ethernet_create(struct pppapi_msg_msg *msg) {
msg->err = ppp_over_ethernet_create(msg->ppp, msg->msg.ethernetcreate.ethif, msg->err = ppp_over_ethernet_create(msg->ppp, msg->msg.ethernetcreate.ethif,
msg->msg.ethernetcreate.service_name, msg->msg.ethernetcreate.concentrator_name, msg->msg.ethernetcreate.service_name, msg->msg.ethernetcreate.concentrator_name,
msg->msg.ethernetcreate.link_status_cb, msg->msg.ethernetcreate.link_status_ctx); msg->msg.ethernetcreate.link_status_cb, msg->msg.ethernetcreate.ctx_cb);
TCPIP_PPPAPI_ACK(msg); TCPIP_PPPAPI_ACK(msg);
} }
@ -147,7 +170,7 @@ static void pppapi_do_ppp_over_ethernet_create(struct pppapi_msg_msg *msg) {
*/ */
int pppapi_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, int pppapi_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name,
const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
void *link_status_ctx) { void *ctx_cb) {
struct pppapi_msg msg; struct pppapi_msg msg;
msg.function = pppapi_do_ppp_over_ethernet_create; msg.function = pppapi_do_ppp_over_ethernet_create;
msg.msg.ppp = pcb; msg.msg.ppp = pcb;
@ -155,7 +178,7 @@ int pppapi_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *s
msg.msg.msg.ethernetcreate.service_name = service_name; msg.msg.msg.ethernetcreate.service_name = service_name;
msg.msg.msg.ethernetcreate.concentrator_name = concentrator_name; msg.msg.msg.ethernetcreate.concentrator_name = concentrator_name;
msg.msg.msg.ethernetcreate.link_status_cb = link_status_cb; msg.msg.msg.ethernetcreate.link_status_cb = link_status_cb;
msg.msg.msg.ethernetcreate.link_status_ctx = link_status_ctx; msg.msg.msg.ethernetcreate.ctx_cb = ctx_cb;
TCPIP_PPPAPI(&msg); TCPIP_PPPAPI(&msg);
return msg.msg.err; return msg.msg.err;
} }
@ -176,7 +199,7 @@ static void pppapi_do_ppp_over_l2tp_create(struct pppapi_msg_msg *msg) {
#else /* PPPOL2TP_AUTH_SUPPORT */ #else /* PPPOL2TP_AUTH_SUPPORT */
NULL, NULL,
#endif /* PPPOL2TP_AUTH_SUPPORT */ #endif /* PPPOL2TP_AUTH_SUPPORT */
msg->msg.l2tpcreate.link_status_cb, msg->msg.l2tpcreate.link_status_ctx); msg->msg.l2tpcreate.link_status_cb, msg->msg.l2tpcreate.ctx_cb);
TCPIP_PPPAPI_ACK(msg); TCPIP_PPPAPI_ACK(msg);
} }
@ -186,7 +209,7 @@ static void pppapi_do_ppp_over_l2tp_create(struct pppapi_msg_msg *msg) {
*/ */
int pppapi_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, int pppapi_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
u8_t *secret, u8_t secret_len, u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
struct pppapi_msg msg; struct pppapi_msg msg;
msg.function = pppapi_do_ppp_over_l2tp_create; msg.function = pppapi_do_ppp_over_l2tp_create;
msg.msg.ppp = pcb; msg.msg.ppp = pcb;
@ -198,7 +221,7 @@ int pppapi_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr
msg.msg.msg.l2tpcreate.secret_len = secret_len; msg.msg.msg.l2tpcreate.secret_len = secret_len;
#endif /* PPPOL2TP_AUTH_SUPPORT */ #endif /* PPPOL2TP_AUTH_SUPPORT */
msg.msg.msg.l2tpcreate.link_status_cb = link_status_cb; msg.msg.msg.l2tpcreate.link_status_cb = link_status_cb;
msg.msg.msg.l2tpcreate.link_status_ctx = link_status_ctx; msg.msg.msg.l2tpcreate.ctx_cb = ctx_cb;
TCPIP_PPPAPI(&msg); TCPIP_PPPAPI(&msg);
return msg.msg.err; return msg.msg.err;
} }

View File

@ -51,11 +51,16 @@ struct pppapi_msg_msg {
char *user; char *user;
char *passwd; char *passwd;
} setauth; } setauth;
#if PPP_NOTIFY_PHASE
struct {
ppp_notify_phase_cb_fn notify_phase_cb;
} setnotifyphasecb;
#endif /* PPP_NOTIFY_PHASE */
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
struct { struct {
sio_fd_t fd; sio_fd_t fd;
ppp_link_status_cb_fn link_status_cb; ppp_link_status_cb_fn link_status_cb;
void *link_status_ctx; void *ctx_cb;
} serialcreate; } serialcreate;
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
@ -64,7 +69,7 @@ struct pppapi_msg_msg {
const char *service_name; const char *service_name;
const char *concentrator_name; const char *concentrator_name;
ppp_link_status_cb_fn link_status_cb; ppp_link_status_cb_fn link_status_cb;
void *link_status_ctx; void *ctx_cb;
} ethernetcreate; } ethernetcreate;
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT #if PPPOL2TP_SUPPORT
@ -77,7 +82,7 @@ struct pppapi_msg_msg {
u8_t secret_len; u8_t secret_len;
#endif /* PPPOL2TP_AUTH_SUPPORT */ #endif /* PPPOL2TP_AUTH_SUPPORT */
ppp_link_status_cb_fn link_status_cb; ppp_link_status_cb_fn link_status_cb;
void *link_status_ctx; void *ctx_cb;
} l2tpcreate; } l2tpcreate;
#endif /* PPPOL2TP_SUPPORT */ #endif /* PPPOL2TP_SUPPORT */
struct { struct {
@ -109,18 +114,21 @@ struct pppapi_msg {
ppp_pcb *pppapi_new(void); ppp_pcb *pppapi_new(void);
void pppapi_set_default(ppp_pcb *pcb); void pppapi_set_default(ppp_pcb *pcb);
void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd); void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd);
#if PPP_NOTIFY_PHASE
void pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb);
#endif /* PPP_NOTIFY_PHASE */
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
int pppapi_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); int pppapi_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
int pppapi_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, int pppapi_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name,
const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb,
void *link_status_ctx); void *ctx_cb);
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT #if PPPOL2TP_SUPPORT
int pppapi_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, int pppapi_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
u8_t *secret, u8_t secret_len, u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
#endif /* PPPOL2TP_SUPPORT */ #endif /* PPPOL2TP_SUPPORT */
int pppapi_open(ppp_pcb *pcb, u16_t holdoff); int pppapi_open(ppp_pcb *pcb, u16_t holdoff);
int pppapi_close(ppp_pcb *pcb); int pppapi_close(ppp_pcb *pcb);

View File

@ -61,6 +61,23 @@
#define PPP_HDRLEN 4 /* octets for standard ppp header */ #define PPP_HDRLEN 4 /* octets for standard ppp header */
#define PPP_FCSLEN 2 /* octets for FCS */ #define PPP_FCSLEN 2 /* octets for FCS */
/*
* Values for phase.
*/
#define PPP_PHASE_DEAD 0
#define PPP_PHASE_INITIALIZE 1
#define PPP_PHASE_SERIALCONN 2
#define PPP_PHASE_DORMANT 3
#define PPP_PHASE_ESTABLISH 4
#define PPP_PHASE_AUTHENTICATE 5
#define PPP_PHASE_CALLBACK 6
#define PPP_PHASE_NETWORK 7
#define PPP_PHASE_RUNNING 8
#define PPP_PHASE_TERMINATE 9
#define PPP_PHASE_DISCONNECT 10
#define PPP_PHASE_HOLDOFF 11
#define PPP_PHASE_MASTER 12
/* Error codes. */ /* Error codes. */
#define PPPERR_NONE 0 /* No error. */ #define PPPERR_NONE 0 /* No error. */
#define PPPERR_PARAM 1 /* Invalid parameter. */ #define PPPERR_PARAM 1 /* Invalid parameter. */
@ -299,7 +316,10 @@ struct ppp_pcb_s {
pppol2tp_pcb *l2tp_pcb; pppol2tp_pcb *l2tp_pcb;
#endif /* PPPOL2TP_SUPPORT */ #endif /* PPPOL2TP_SUPPORT */
void (*link_status_cb)(ppp_pcb *pcb, int err_code, void *ctx); /* Status change callback */ void (*link_status_cb)(ppp_pcb *pcb, int err_code, void *ctx); /* Status change callback */
void *link_status_ctx; /* Status change callback optional pointer */ #if PPP_NOTIFY_PHASE
void (*notify_phase_cb)(ppp_pcb *pcb, u8_t phase, void *ctx); /* Notify phase callback */
#endif /* PPP_NOTIFY_PHASE */
void *ctx_cb; /* Callbacks optional pointer */
struct netif netif; /* PPP interface */ struct netif netif; /* PPP interface */
/* -- below are data that will be cleared between two sessions */ /* -- below are data that will be cleared between two sessions */
@ -451,6 +471,17 @@ void ppp_set_default(ppp_pcb *pcb);
void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd); void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd);
#if PPP_NOTIFY_PHASE
/*
* Set a PPP notify phase callback.
*
* This can be used for example to set a LED pattern depending on the
* current phase of the PPP session.
*/
typedef void (*ppp_notify_phase_cb_fn)(ppp_pcb *pcb, u8_t phase, void *ctx);
void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb);
#endif /* PPP_NOTIFY_PHASE */
/* Link status callback function prototype */ /* Link status callback function prototype */
typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx); typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx);
@ -463,7 +494,7 @@ typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx);
* *
* Return 0 on success, an error code on failure. * Return 0 on success, an error code on failure.
*/ */
int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
@ -473,7 +504,7 @@ int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link
* Return 0 on success, an error code on failure. * Return 0 on success, an error code on failure.
*/ */
int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT #if PPPOL2TP_SUPPORT
@ -482,7 +513,7 @@ int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *serv
*/ */
int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
u8_t *secret, u8_t secret_len, u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx); ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
#endif /* PPPOL2TP_SUPPORT */ #endif /* PPPOL2TP_SUPPORT */
/* /*

View File

@ -346,23 +346,6 @@ extern const struct protent* const protocols[];
#endif /* MSCHAP_SUPPORT */ #endif /* MSCHAP_SUPPORT */
#endif /* CHAP_SUPPORT */ #endif /* CHAP_SUPPORT */
/*
* Values for phase.
*/
#define PHASE_DEAD 0
#define PHASE_INITIALIZE 1
#define PHASE_SERIALCONN 2
#define PHASE_DORMANT 3
#define PHASE_ESTABLISH 4
#define PHASE_AUTHENTICATE 5
#define PHASE_CALLBACK 6
#define PHASE_NETWORK 7
#define PHASE_RUNNING 8
#define PHASE_TERMINATE 9
#define PHASE_DISCONNECT 10
#define PHASE_HOLDOFF 11
#define PHASE_MASTER 12
/* Supported CHAP protocols */ /* Supported CHAP protocols */
#if CHAP_SUPPORT #if CHAP_SUPPORT
#include "chap-new.h" #include "chap-new.h"

View File

@ -559,7 +559,7 @@ void start_link(unit)
char *msg; char *msg;
status = EXIT_NEGOTIATION_FAILED; status = EXIT_NEGOTIATION_FAILED;
new_phase(pcb, PHASE_SERIALCONN); new_phase(pcb, PPP_PHASE_SERIALCONN);
hungup = 0; hungup = 0;
devfd = the_channel->connect(); devfd = the_channel->connect();
@ -595,18 +595,18 @@ void start_link(unit)
ppp_notice("Starting negotiation on %s", ppp_devnam); ppp_notice("Starting negotiation on %s", ppp_devnam);
add_fd(fd_ppp); add_fd(fd_ppp);
new_phase(pcb, PHASE_ESTABLISH); new_phase(pcb, PPP_PHASE_ESTABLISH);
lcp_lowerup(pcb); lcp_lowerup(pcb);
return; return;
disconnect: disconnect:
new_phase(pcb, PHASE_DISCONNECT); new_phase(pcb, PPP_PHASE_DISCONNECT);
if (the_channel->disconnect) if (the_channel->disconnect)
the_channel->disconnect(); the_channel->disconnect();
fail: fail:
new_phase(pcb, PHASE_DEAD); new_phase(pcb, PPP_PHASE_DEAD);
if (the_channel->cleanup) if (the_channel->cleanup)
(*the_channel->cleanup)(); (*the_channel->cleanup)();
} }
@ -617,9 +617,9 @@ void start_link(unit)
* physical layer down. * physical layer down.
*/ */
void link_terminated(ppp_pcb *pcb) { void link_terminated(ppp_pcb *pcb) {
if (pcb->phase == PHASE_DEAD || pcb->phase == PHASE_MASTER) if (pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_MASTER)
return; return;
new_phase(pcb, PHASE_DISCONNECT); new_phase(pcb, PPP_PHASE_DISCONNECT);
#if 0 /* UNUSED */ #if 0 /* UNUSED */
if (pap_logout_hook) { if (pap_logout_hook) {
@ -638,7 +638,7 @@ void link_terminated(ppp_pcb *pcb) {
lcp_lowerdown(pcb); lcp_lowerdown(pcb);
new_phase(pcb, PHASE_DEAD); new_phase(pcb, PPP_PHASE_DEAD);
ppp_link_terminated(pcb); ppp_link_terminated(pcb);
#if 0 #if 0
/* /*
@ -680,11 +680,11 @@ void link_terminated(ppp_pcb *pcb) {
if (doing_multilink && multilink_master) { if (doing_multilink && multilink_master) {
if (!bundle_terminating) if (!bundle_terminating)
new_phase(pcb, PHASE_MASTER); new_phase(pcb, PPP_PHASE_MASTER);
else else
mp_bundle_terminated(); mp_bundle_terminated();
} else } else
new_phase(pcb, PHASE_DEAD); new_phase(pcb, PPP_PHASE_DEAD);
#endif #endif
} }
@ -698,8 +698,8 @@ void link_down(ppp_pcb *pcb) {
if (!doing_multilink) { if (!doing_multilink) {
upper_layers_down(pcb); upper_layers_down(pcb);
if (pcb->phase != PHASE_DEAD && pcb->phase != PHASE_MASTER) if (pcb->phase != PPP_PHASE_DEAD && pcb->phase != PPP_PHASE_MASTER)
new_phase(pcb, PHASE_ESTABLISH); new_phase(pcb, PPP_PHASE_ESTABLISH);
} }
/* XXX if doing_multilink, should do something to stop /* XXX if doing_multilink, should do something to stop
network-layer traffic on the link */ network-layer traffic on the link */
@ -793,7 +793,7 @@ void link_established(ppp_pcb *pcb) {
} }
#endif /* PPP_SERVER */ #endif /* PPP_SERVER */
new_phase(pcb, PHASE_AUTHENTICATE); new_phase(pcb, PPP_PHASE_AUTHENTICATE);
auth = 0; auth = 0;
#if PPP_SERVER #if PPP_SERVER
#if EAP_SUPPORT #if EAP_SUPPORT
@ -886,7 +886,7 @@ static void network_phase(ppp_pcb *pcb) {
* If we negotiated callback, do it now. * If we negotiated callback, do it now.
*/ */
if (go->neg_cbcp) { if (go->neg_cbcp) {
new_phase(pcb, PHASE_CALLBACK); new_phase(pcb, PPP_PHASE_CALLBACK);
(*cbcp_protent.open)(pcb); (*cbcp_protent.open)(pcb);
return; return;
} }
@ -917,7 +917,7 @@ void start_networks(ppp_pcb *pcb) {
int mppe_required; int mppe_required;
#endif /* MPPE */ #endif /* MPPE */
new_phase(pcb, PHASE_NETWORK); new_phase(pcb, PPP_PHASE_NETWORK);
#ifdef HAVE_MULTILINK #ifdef HAVE_MULTILINK
if (multilink) { if (multilink) {
@ -1167,7 +1167,7 @@ void np_up(ppp_pcb *pcb, int proto) {
/* /*
* At this point we consider that the link has come up successfully. * At this point we consider that the link has come up successfully.
*/ */
new_phase(pcb, PHASE_RUNNING); new_phase(pcb, PPP_PHASE_RUNNING);
#if PPP_IDLETIMELIMIT #if PPP_IDLETIMELIMIT
#if 0 /* UNUSED */ #if 0 /* UNUSED */
@ -1219,7 +1219,7 @@ void np_down(ppp_pcb *pcb, int proto) {
#ifdef MAXOCTETS #ifdef MAXOCTETS
UNTIMEOUT(check_maxoctets, NULL); UNTIMEOUT(check_maxoctets, NULL);
#endif #endif
new_phase(pcb, PHASE_NETWORK); new_phase(pcb, PPP_PHASE_NETWORK);
} }
} }

View File

@ -440,8 +440,8 @@ void lcp_close(ppp_pcb *pcb, char *reason) {
fsm *f = &pcb->lcp_fsm; fsm *f = &pcb->lcp_fsm;
int oldstate; int oldstate;
if (pcb->phase != PHASE_DEAD && pcb->phase != PHASE_MASTER) if (pcb->phase != PPP_PHASE_DEAD && pcb->phase != PPP_PHASE_MASTER)
new_phase(pcb, PHASE_TERMINATE); new_phase(pcb, PPP_PHASE_TERMINATE);
if (f->flags & DELAYED_UP) { if (f->flags & DELAYED_UP) {
UNTIMEOUT(lcp_delayed_up, f); UNTIMEOUT(lcp_delayed_up, f);

View File

@ -295,7 +295,7 @@ void mp_bundle_terminated()
tdb_delete(pppdb, key); tdb_delete(pppdb, key);
unlock_db(); unlock_db();
new_phase(PHASE_DEAD); new_phase(PPP_PHASE_DEAD);
doing_multilink = 0; doing_multilink = 0;
multilink_master = 0; multilink_master = 0;

View File

@ -294,7 +294,7 @@ ppp_pcb *ppp_new(void) {
return NULL; return NULL;
} }
new_phase(pcb, PHASE_DEAD); new_phase(pcb, PPP_PHASE_DEAD);
return pcb; return pcb;
} }
@ -346,8 +346,15 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, char *user, char *passwd) {
} }
} }
#if PPP_NOTIFY_PHASE
void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb) {
pcb->notify_phase_cb = notify_phase_cb;
notify_phase_cb(pcb, pcb->phase, pcb->ctx_cb);
}
#endif /* PPP_NOTIFY_PHASE */
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
/* PPP is single-threaded: without a callback, /* PPP is single-threaded: without a callback,
* there is no way to know when the link is up. */ * there is no way to know when the link is up. */
@ -357,7 +364,7 @@ int ppp_over_serial_create(ppp_pcb *pcb, sio_fd_t fd, ppp_link_status_cb_fn link
pcb->fd = fd; pcb->fd = fd;
pcb->link_status_cb = link_status_cb; pcb->link_status_cb = link_status_cb;
pcb->link_status_ctx = link_status_ctx; pcb->ctx_cb = ctx_cb;
return PPPERR_NONE; return PPPERR_NONE;
} }
@ -379,7 +386,7 @@ void ppp_set_xaccm(ppp_pcb *pcb, ext_accm *accm) {
static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state); static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state);
int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
LWIP_UNUSED_ARG(service_name); LWIP_UNUSED_ARG(service_name);
LWIP_UNUSED_ARG(concentrator_name); LWIP_UNUSED_ARG(concentrator_name);
@ -391,7 +398,7 @@ int ppp_over_ethernet_create(ppp_pcb *pcb, struct netif *ethif, const char *serv
} }
pcb->link_status_cb = link_status_cb; pcb->link_status_cb = link_status_cb;
pcb->link_status_ctx = link_status_ctx; pcb->ctx_cb = ctx_cb;
if (pppoe_create(ethif, pcb, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) { if (pppoe_create(ethif, pcb, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) {
return PPPERR_OPEN; return PPPERR_OPEN;
@ -406,7 +413,7 @@ static void ppp_over_l2tp_link_status_cb(ppp_pcb *pcb, int state);
int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port, int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
u8_t *secret, u8_t secret_len, u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
/* PPP is single-threaded: without a callback, /* PPP is single-threaded: without a callback,
* there is no way to know when the link is up. */ * there is no way to know when the link is up. */
@ -415,7 +422,7 @@ int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u
} }
pcb->link_status_cb = link_status_cb; pcb->link_status_cb = link_status_cb;
pcb->link_status_ctx = link_status_ctx; pcb->ctx_cb = ctx_cb;
if (pppol2tp_create(pcb, ppp_over_l2tp_link_status_cb, &pcb->l2tp_pcb, netif, ipaddr, port, secret, secret_len) != ERR_OK) { if (pppol2tp_create(pcb, ppp_over_l2tp_link_status_cb, &pcb->l2tp_pcb, netif, ipaddr, port, secret, secret_len) != ERR_OK) {
return PPPERR_OPEN; return PPPERR_OPEN;
@ -434,7 +441,7 @@ int ppp_over_l2tp_create(ppp_pcb *pcb, struct netif *netif, ip_addr_t *ipaddr, u
* the connection. * the connection.
*/ */
int ppp_open(ppp_pcb *pcb, u16_t holdoff) { int ppp_open(ppp_pcb *pcb, u16_t holdoff) {
if (pcb->phase != PHASE_DEAD) { if (pcb->phase != PPP_PHASE_DEAD) {
return PPPERR_PARAM; return PPPERR_PARAM;
} }
@ -445,7 +452,7 @@ int ppp_open(ppp_pcb *pcb, u16_t holdoff) {
return PPPERR_NONE; return PPPERR_NONE;
} }
new_phase(pcb, PHASE_HOLDOFF); new_phase(pcb, PPP_PHASE_HOLDOFF);
sys_timeout((u32_t)(holdoff*1000), ppp_do_open, pcb); sys_timeout((u32_t)(holdoff*1000), ppp_do_open, pcb);
return PPPERR_NONE; return PPPERR_NONE;
} }
@ -463,15 +470,15 @@ ppp_close(ppp_pcb *pcb)
pcb->err_code = PPPERR_USER; pcb->err_code = PPPERR_USER;
/* dead phase, nothing to do, call the status callback to be consistent */ /* dead phase, nothing to do, call the status callback to be consistent */
if (pcb->phase == PHASE_DEAD) { if (pcb->phase == PPP_PHASE_DEAD) {
pcb->link_status_cb(pcb, pcb->err_code, pcb->link_status_ctx); pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
return PPPERR_NONE; return PPPERR_NONE;
} }
/* holdoff phase, cancel the reconnection and call the status callback */ /* holdoff phase, cancel the reconnection and call the status callback */
if (pcb->phase == PHASE_HOLDOFF) { if (pcb->phase == PPP_PHASE_HOLDOFF) {
sys_untimeout(ppp_do_open, pcb); sys_untimeout(ppp_do_open, pcb);
pcb->link_status_cb(pcb, pcb->err_code, pcb->link_status_ctx); pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
return PPPERR_NONE; return PPPERR_NONE;
} }
@ -481,21 +488,21 @@ ppp_close(ppp_pcb *pcb)
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
if (pcb->pppoe_sc) { if (pcb->pppoe_sc) {
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> ppp_stop\n", pcb->num)); PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> ppp_stop\n", pcb->num));
/* This will leave us at PHASE_DEAD. */ /* This will leave us at PPP_PHASE_DEAD. */
ppp_stop(pcb); ppp_stop(pcb);
} else } else
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT #if PPPOL2TP_SUPPORT
if (pcb->l2tp_pcb) { if (pcb->l2tp_pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> ppp_stop\n", pcb->num)); PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> ppp_stop\n", pcb->num));
/* This will leave us at PHASE_DEAD. */ /* This will leave us at PPP_PHASE_DEAD. */
ppp_stop(pcb); ppp_stop(pcb);
} else } else
#endif /* PPPOL2TP_SUPPORT */ #endif /* PPPOL2TP_SUPPORT */
{ {
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> ppp_stop\n", pcb->num)); PPPDEBUG(LOG_DEBUG, ("ppp_close: unit %d kill_link -> ppp_stop\n", pcb->num));
/* This will leave us at PHASE_DEAD. */ /* This will leave us at PPP_PHASE_DEAD. */
ppp_stop(pcb); ppp_stop(pcb);
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
} }
@ -525,7 +532,7 @@ ppp_sighup(ppp_pcb *pcb)
* Return 0 on success, an error code on failure. * Return 0 on success, an error code on failure.
*/ */
int ppp_free(ppp_pcb *pcb) { int ppp_free(ppp_pcb *pcb) {
if (pcb->phase != PHASE_DEAD) { if (pcb->phase != PPP_PHASE_DEAD) {
return PPPERR_PARAM; return PPPERR_PARAM;
} }
@ -566,7 +573,7 @@ int ppp_free(ppp_pcb *pcb) {
int ppp_delete(ppp_pcb *pcb) { int ppp_delete(ppp_pcb *pcb) {
int err; int err;
if (pcb->phase != PHASE_DEAD) { if (pcb->phase != PPP_PHASE_DEAD) {
return PPPERR_PARAM; return PPPERR_PARAM;
} }
@ -593,7 +600,7 @@ static void ppp_clear(ppp_pcb *pcb) {
const struct protent *protp; const struct protent *protp;
int i; int i;
LWIP_ASSERT("pcb->phase == PHASE_DEAD || pcb->phase == PHASE_HOLDOFF", pcb->phase == PHASE_DEAD || pcb->phase == PHASE_HOLDOFF); LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF);
#if PPP_STATS_SUPPORTs #if PPP_STATS_SUPPORTs
link_stats_valid = 0; link_stats_valid = 0;
@ -609,13 +616,13 @@ static void ppp_clear(ppp_pcb *pcb) {
(*protp->init)(pcb); (*protp->init)(pcb);
} }
new_phase(pcb, PHASE_INITIALIZE); new_phase(pcb, PPP_PHASE_INITIALIZE);
} }
static void ppp_do_open(void *arg) { static void ppp_do_open(void *arg) {
ppp_pcb *pcb = (ppp_pcb*)arg; ppp_pcb *pcb = (ppp_pcb*)arg;
LWIP_ASSERT("pcb->phase == PHASE_DEAD || pcb->phase == PHASE_HOLDOFF", pcb->phase == PHASE_DEAD || pcb->phase == PHASE_HOLDOFF); LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF);
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
if (pcb->pppoe_sc) { if (pcb->pppoe_sc) {
@ -691,7 +698,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
* Until we get past the authentication phase, toss all packets * Until we get past the authentication phase, toss all packets
* except LCP, LQR and authentication packets. * except LCP, LQR and authentication packets.
*/ */
if (pcb->phase <= PHASE_AUTHENTICATE if (pcb->phase <= PPP_PHASE_AUTHENTICATE
&& !(protocol == PPP_LCP && !(protocol == PPP_LCP
#if LQR_SUPPORT #if LQR_SUPPORT
|| protocol == PPP_LQR || protocol == PPP_LQR
@ -1808,11 +1815,11 @@ static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state) {
case PPPOE_CB_STATE_FAILED: case PPPOE_CB_STATE_FAILED:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: FAILED, aborting\n", pcb->num)); PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: FAILED, aborting\n", pcb->num));
pppoe_err_code = PPPERR_OPEN; pppoe_err_code = PPPERR_OPEN;
new_phase(pcb, PHASE_DEAD); new_phase(pcb, PPP_PHASE_DEAD);
break; break;
} }
pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppoe_err_code, pcb->link_status_ctx); pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppoe_err_code, pcb->ctx_cb);
} }
static void ppp_over_ethernet_open(ppp_pcb *pcb) { static void ppp_over_ethernet_open(ppp_pcb *pcb) {
@ -1858,11 +1865,11 @@ static void ppp_over_l2tp_link_status_cb(ppp_pcb *pcb, int state) {
case PPPOL2TP_CB_STATE_FAILED: case PPPOL2TP_CB_STATE_FAILED:
PPPDEBUG(LOG_INFO, ("ppp_over_l2tp_link_status_cb: unit %d: FAILED, aborting\n", pcb->num)); PPPDEBUG(LOG_INFO, ("ppp_over_l2tp_link_status_cb: unit %d: FAILED, aborting\n", pcb->num));
pppol2tp_err_code = PPPERR_OPEN; pppol2tp_err_code = PPPERR_OPEN;
new_phase(pcb, PHASE_DEAD); new_phase(pcb, PPP_PHASE_DEAD);
break; break;
} }
pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppol2tp_err_code, pcb->link_status_ctx); pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppol2tp_err_code, pcb->ctx_cb);
} }
static void ppp_over_l2tp_open(ppp_pcb *pcb) { static void ppp_over_l2tp_open(ppp_pcb *pcb) {
@ -1909,7 +1916,7 @@ void ppp_link_terminated(ppp_pcb *pcb) {
* rx thread might still call pppos_input() * rx thread might still call pppos_input()
*/ */
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d: link_status_cb=%p err_code=%d\n", pcb->num, pcb->link_status_cb, pcb->err_code)); PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: unit %d: link_status_cb=%p err_code=%d\n", pcb->num, pcb->link_status_cb, pcb->err_code));
pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : PPPERR_PROTOCOL, pcb->link_status_ctx); pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : PPPERR_PROTOCOL, pcb->ctx_cb);
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
} }
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: finished.\n")); PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: finished.\n"));
@ -1956,9 +1963,11 @@ ppp_set_netif_linkcallback(ppp_pcb *pcb, netif_status_callback_fn link_callback)
void new_phase(ppp_pcb *pcb, int p) { void new_phase(ppp_pcb *pcb, int p) {
pcb->phase = p; pcb->phase = p;
PPPDEBUG(LOG_DEBUG, ("ppp phase changed: unit %d: phase=%d\n", pcb->num, pcb->phase)); PPPDEBUG(LOG_DEBUG, ("ppp phase changed: unit %d: phase=%d\n", pcb->num, pcb->phase));
#if PPP_NOTIFY #if PPP_NOTIFY_PHASE
/* The one willing notify support should add here the code to be notified of phase changes */ if(NULL != pcb->notify_phase_cb) {
#endif /* PPP_NOTIFY */ pcb->notify_phase_cb(pcb, p, pcb->ctx_cb);
}
#endif /* PPP_NOTIFY_PHASE */
} }
/* /*
@ -2137,7 +2146,7 @@ int sifup(ppp_pcb *pcb) {
pcb->err_code = PPPERR_NONE; pcb->err_code = PPPERR_NONE;
PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: err_code=%d\n", pcb->num, pcb->err_code)); PPPDEBUG(LOG_DEBUG, ("sifup: unit %d: err_code=%d\n", pcb->num, pcb->err_code));
pcb->link_status_cb(pcb, pcb->err_code, pcb->link_status_ctx); pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb);
return 1; return 1;
} }