diff --git a/src/api/pppapi.c b/src/api/pppapi.c index e4e198a9..f1450a8d 100644 --- a/src/api/pppapi.c +++ b/src/api/pppapi.c @@ -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 /** * Call ppp_over_serial_create() inside the tcpip_thread context. */ 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->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); } @@ -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 * 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; msg.function = pppapi_do_ppp_over_serial_create; msg.msg.ppp = pcb; msg.msg.msg.serialcreate.fd = fd; 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); 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->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); } @@ -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, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, - void *link_status_ctx) { + void *ctx_cb) { struct pppapi_msg msg; msg.function = pppapi_do_ppp_over_ethernet_create; 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.concentrator_name = concentrator_name; 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); 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 */ NULL, #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); } @@ -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, 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; msg.function = pppapi_do_ppp_over_l2tp_create; 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; #endif /* PPPOL2TP_AUTH_SUPPORT */ 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); return msg.msg.err; } diff --git a/src/include/lwip/pppapi.h b/src/include/lwip/pppapi.h index 27660cad..520b4d7f 100644 --- a/src/include/lwip/pppapi.h +++ b/src/include/lwip/pppapi.h @@ -51,11 +51,16 @@ struct pppapi_msg_msg { char *user; char *passwd; } setauth; +#if PPP_NOTIFY_PHASE + struct { + ppp_notify_phase_cb_fn notify_phase_cb; + } setnotifyphasecb; +#endif /* PPP_NOTIFY_PHASE */ #if PPPOS_SUPPORT struct { sio_fd_t fd; ppp_link_status_cb_fn link_status_cb; - void *link_status_ctx; + void *ctx_cb; } serialcreate; #endif /* PPPOS_SUPPORT */ #if PPPOE_SUPPORT @@ -64,7 +69,7 @@ struct pppapi_msg_msg { const char *service_name; const char *concentrator_name; ppp_link_status_cb_fn link_status_cb; - void *link_status_ctx; + void *ctx_cb; } ethernetcreate; #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT @@ -77,7 +82,7 @@ struct pppapi_msg_msg { u8_t secret_len; #endif /* PPPOL2TP_AUTH_SUPPORT */ ppp_link_status_cb_fn link_status_cb; - void *link_status_ctx; + void *ctx_cb; } l2tpcreate; #endif /* PPPOL2TP_SUPPORT */ struct { @@ -109,18 +114,21 @@ struct pppapi_msg { ppp_pcb *pppapi_new(void); void pppapi_set_default(ppp_pcb *pcb); 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 -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 */ #if PPPOE_SUPPORT 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, - void *link_status_ctx); + void *ctx_cb); #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT 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, - 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 */ int pppapi_open(ppp_pcb *pcb, u16_t holdoff); int pppapi_close(ppp_pcb *pcb); diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 168d473e..64fb0592 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -61,6 +61,23 @@ #define PPP_HDRLEN 4 /* octets for standard ppp header */ #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. */ #define PPPERR_NONE 0 /* No error. */ #define PPPERR_PARAM 1 /* Invalid parameter. */ @@ -299,7 +316,10 @@ struct ppp_pcb_s { pppol2tp_pcb *l2tp_pcb; #endif /* PPPOL2TP_SUPPORT */ 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 */ /* -- 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); +#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 */ 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. */ -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 */ #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. */ 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 */ #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, 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 */ /* diff --git a/src/include/netif/ppp/ppp_impl.h b/src/include/netif/ppp/ppp_impl.h index b1d5f9c4..6e02290b 100644 --- a/src/include/netif/ppp/ppp_impl.h +++ b/src/include/netif/ppp/ppp_impl.h @@ -346,23 +346,6 @@ extern const struct protent* const protocols[]; #endif /* MSCHAP_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 */ #if CHAP_SUPPORT #include "chap-new.h" diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index d1dc41f8..4cbf0afb 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -559,7 +559,7 @@ void start_link(unit) char *msg; status = EXIT_NEGOTIATION_FAILED; - new_phase(pcb, PHASE_SERIALCONN); + new_phase(pcb, PPP_PHASE_SERIALCONN); hungup = 0; devfd = the_channel->connect(); @@ -595,18 +595,18 @@ void start_link(unit) ppp_notice("Starting negotiation on %s", ppp_devnam); add_fd(fd_ppp); - new_phase(pcb, PHASE_ESTABLISH); + new_phase(pcb, PPP_PHASE_ESTABLISH); lcp_lowerup(pcb); return; disconnect: - new_phase(pcb, PHASE_DISCONNECT); + new_phase(pcb, PPP_PHASE_DISCONNECT); if (the_channel->disconnect) the_channel->disconnect(); fail: - new_phase(pcb, PHASE_DEAD); + new_phase(pcb, PPP_PHASE_DEAD); if (the_channel->cleanup) (*the_channel->cleanup)(); } @@ -617,9 +617,9 @@ void start_link(unit) * physical layer down. */ 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; - new_phase(pcb, PHASE_DISCONNECT); + new_phase(pcb, PPP_PHASE_DISCONNECT); #if 0 /* UNUSED */ if (pap_logout_hook) { @@ -638,7 +638,7 @@ void link_terminated(ppp_pcb *pcb) { lcp_lowerdown(pcb); - new_phase(pcb, PHASE_DEAD); + new_phase(pcb, PPP_PHASE_DEAD); ppp_link_terminated(pcb); #if 0 /* @@ -680,11 +680,11 @@ void link_terminated(ppp_pcb *pcb) { if (doing_multilink && multilink_master) { if (!bundle_terminating) - new_phase(pcb, PHASE_MASTER); + new_phase(pcb, PPP_PHASE_MASTER); else mp_bundle_terminated(); } else - new_phase(pcb, PHASE_DEAD); + new_phase(pcb, PPP_PHASE_DEAD); #endif } @@ -698,8 +698,8 @@ void link_down(ppp_pcb *pcb) { if (!doing_multilink) { upper_layers_down(pcb); - if (pcb->phase != PHASE_DEAD && pcb->phase != PHASE_MASTER) - new_phase(pcb, PHASE_ESTABLISH); + if (pcb->phase != PPP_PHASE_DEAD && pcb->phase != PPP_PHASE_MASTER) + new_phase(pcb, PPP_PHASE_ESTABLISH); } /* XXX if doing_multilink, should do something to stop network-layer traffic on the link */ @@ -793,7 +793,7 @@ void link_established(ppp_pcb *pcb) { } #endif /* PPP_SERVER */ - new_phase(pcb, PHASE_AUTHENTICATE); + new_phase(pcb, PPP_PHASE_AUTHENTICATE); auth = 0; #if PPP_SERVER #if EAP_SUPPORT @@ -886,7 +886,7 @@ static void network_phase(ppp_pcb *pcb) { * If we negotiated callback, do it now. */ if (go->neg_cbcp) { - new_phase(pcb, PHASE_CALLBACK); + new_phase(pcb, PPP_PHASE_CALLBACK); (*cbcp_protent.open)(pcb); return; } @@ -917,7 +917,7 @@ void start_networks(ppp_pcb *pcb) { int mppe_required; #endif /* MPPE */ - new_phase(pcb, PHASE_NETWORK); + new_phase(pcb, PPP_PHASE_NETWORK); #ifdef HAVE_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. */ - new_phase(pcb, PHASE_RUNNING); + new_phase(pcb, PPP_PHASE_RUNNING); #if PPP_IDLETIMELIMIT #if 0 /* UNUSED */ @@ -1219,7 +1219,7 @@ void np_down(ppp_pcb *pcb, int proto) { #ifdef MAXOCTETS UNTIMEOUT(check_maxoctets, NULL); #endif - new_phase(pcb, PHASE_NETWORK); + new_phase(pcb, PPP_PHASE_NETWORK); } } diff --git a/src/netif/ppp/lcp.c b/src/netif/ppp/lcp.c index 9c69dd8f..52f7a50f 100644 --- a/src/netif/ppp/lcp.c +++ b/src/netif/ppp/lcp.c @@ -440,8 +440,8 @@ void lcp_close(ppp_pcb *pcb, char *reason) { fsm *f = &pcb->lcp_fsm; int oldstate; - if (pcb->phase != PHASE_DEAD && pcb->phase != PHASE_MASTER) - new_phase(pcb, PHASE_TERMINATE); + if (pcb->phase != PPP_PHASE_DEAD && pcb->phase != PPP_PHASE_MASTER) + new_phase(pcb, PPP_PHASE_TERMINATE); if (f->flags & DELAYED_UP) { UNTIMEOUT(lcp_delayed_up, f); diff --git a/src/netif/ppp/multilink.c b/src/netif/ppp/multilink.c index 883ecd00..9acbb567 100644 --- a/src/netif/ppp/multilink.c +++ b/src/netif/ppp/multilink.c @@ -295,7 +295,7 @@ void mp_bundle_terminated() tdb_delete(pppdb, key); unlock_db(); - new_phase(PHASE_DEAD); + new_phase(PPP_PHASE_DEAD); doing_multilink = 0; multilink_master = 0; diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index afc225f8..50d5d34b 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -294,7 +294,7 @@ ppp_pcb *ppp_new(void) { return NULL; } - new_phase(pcb, PHASE_DEAD); + new_phase(pcb, PPP_PHASE_DEAD); 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 -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, * 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->link_status_cb = link_status_cb; - pcb->link_status_ctx = link_status_ctx; + pcb->ctx_cb = ctx_cb; 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); 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(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_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) { 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, 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, * 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_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) { 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. */ int ppp_open(ppp_pcb *pcb, u16_t holdoff) { - if (pcb->phase != PHASE_DEAD) { + if (pcb->phase != PPP_PHASE_DEAD) { return PPPERR_PARAM; } @@ -445,7 +452,7 @@ int ppp_open(ppp_pcb *pcb, u16_t holdoff) { return PPPERR_NONE; } - new_phase(pcb, PHASE_HOLDOFF); + new_phase(pcb, PPP_PHASE_HOLDOFF); sys_timeout((u32_t)(holdoff*1000), ppp_do_open, pcb); return PPPERR_NONE; } @@ -463,15 +470,15 @@ ppp_close(ppp_pcb *pcb) pcb->err_code = PPPERR_USER; /* dead phase, nothing to do, call the status callback to be consistent */ - if (pcb->phase == PHASE_DEAD) { - pcb->link_status_cb(pcb, pcb->err_code, pcb->link_status_ctx); + if (pcb->phase == PPP_PHASE_DEAD) { + pcb->link_status_cb(pcb, pcb->err_code, pcb->ctx_cb); return PPPERR_NONE; } /* 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); - 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; } @@ -481,21 +488,21 @@ ppp_close(ppp_pcb *pcb) #if PPPOE_SUPPORT if (pcb->pppoe_sc) { 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); } else #endif /* PPPOE_SUPPORT */ #if PPPOL2TP_SUPPORT if (pcb->l2tp_pcb) { 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); } else #endif /* PPPOL2TP_SUPPORT */ { #if PPPOS_SUPPORT 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); #endif /* PPPOS_SUPPORT */ } @@ -525,7 +532,7 @@ ppp_sighup(ppp_pcb *pcb) * Return 0 on success, an error code on failure. */ int ppp_free(ppp_pcb *pcb) { - if (pcb->phase != PHASE_DEAD) { + if (pcb->phase != PPP_PHASE_DEAD) { return PPPERR_PARAM; } @@ -566,7 +573,7 @@ int ppp_free(ppp_pcb *pcb) { int ppp_delete(ppp_pcb *pcb) { int err; - if (pcb->phase != PHASE_DEAD) { + if (pcb->phase != PPP_PHASE_DEAD) { return PPPERR_PARAM; } @@ -593,7 +600,7 @@ static void ppp_clear(ppp_pcb *pcb) { const struct protent *protp; 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 link_stats_valid = 0; @@ -609,13 +616,13 @@ static void ppp_clear(ppp_pcb *pcb) { (*protp->init)(pcb); } - new_phase(pcb, PHASE_INITIALIZE); + new_phase(pcb, PPP_PHASE_INITIALIZE); } static void ppp_do_open(void *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 (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 * except LCP, LQR and authentication packets. */ - if (pcb->phase <= PHASE_AUTHENTICATE + if (pcb->phase <= PPP_PHASE_AUTHENTICATE && !(protocol == PPP_LCP #if LQR_SUPPORT || 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: PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: FAILED, aborting\n", pcb->num)); pppoe_err_code = PPPERR_OPEN; - new_phase(pcb, PHASE_DEAD); + new_phase(pcb, PPP_PHASE_DEAD); 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) { @@ -1858,11 +1865,11 @@ static void ppp_over_l2tp_link_status_cb(ppp_pcb *pcb, int state) { case PPPOL2TP_CB_STATE_FAILED: PPPDEBUG(LOG_INFO, ("ppp_over_l2tp_link_status_cb: unit %d: FAILED, aborting\n", pcb->num)); pppol2tp_err_code = PPPERR_OPEN; - new_phase(pcb, PHASE_DEAD); + new_phase(pcb, PPP_PHASE_DEAD); 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) { @@ -1909,7 +1916,7 @@ void ppp_link_terminated(ppp_pcb *pcb) { * 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)); - 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 */ } 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) { pcb->phase = p; PPPDEBUG(LOG_DEBUG, ("ppp phase changed: unit %d: phase=%d\n", pcb->num, pcb->phase)); -#if PPP_NOTIFY - /* The one willing notify support should add here the code to be notified of phase changes */ -#endif /* PPP_NOTIFY */ +#if PPP_NOTIFY_PHASE + if(NULL != pcb->notify_phase_cb) { + 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; 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; }