mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-30 12:32:37 +00:00
PPP: prepared callbacks from PPP core to low level protocols
New PPP callback from PPP core to low level protocols, first step about removing named calls to low level protocols from PPP core.
This commit is contained in:
parent
a5582e0960
commit
f8501478f6
@ -358,6 +358,7 @@ struct ppp_pcb_s {
|
|||||||
#if PPPOS_SUPPORT
|
#if PPPOS_SUPPORT
|
||||||
sio_fd_t fd; /* File device ID of port. */
|
sio_fd_t fd; /* File device ID of port. */
|
||||||
#endif /* PPPOS_SUPPORT */
|
#endif /* PPPOS_SUPPORT */
|
||||||
|
void (*link_command_cb)(void *pcb, u8_t command);
|
||||||
#if PPPOE_SUPPORT
|
#if PPPOE_SUPPORT
|
||||||
struct pppoe_softc *pppoe_sc;
|
struct pppoe_softc *pppoe_sc;
|
||||||
#endif /* PPPOE_SUPPORT */
|
#endif /* PPPOE_SUPPORT */
|
||||||
|
@ -87,6 +87,16 @@
|
|||||||
#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
|
#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
|
||||||
#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
|
#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Low-level links commands
|
||||||
|
*/
|
||||||
|
/* Start a connection (i.e. initiate discovery phase) */
|
||||||
|
#define PPP_LINK_COMMAND_CONNECT 0
|
||||||
|
/* End a connection (i.e. initiate disconnect phase) */
|
||||||
|
#define PPP_LINK_COMMAND_DISCONNECT 1
|
||||||
|
/* Free link connection */
|
||||||
|
#define PPP_LINK_COMMAND_FREE 2
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Protocol field values.
|
* Protocol field values.
|
||||||
*/
|
*/
|
||||||
@ -370,6 +380,9 @@ int ppp_init(void);
|
|||||||
/* Create a new PPP control block */
|
/* Create a new PPP control block */
|
||||||
ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
||||||
|
|
||||||
|
/* Set link callback function */
|
||||||
|
#define ppp_link_set_callback(ppp, cb) (ppp->link_command_cb = cb)
|
||||||
|
|
||||||
/* Initiate LCP open request */
|
/* Initiate LCP open request */
|
||||||
void ppp_start(ppp_pcb *pcb);
|
void ppp_start(ppp_pcb *pcb);
|
||||||
|
|
||||||
|
@ -165,10 +165,6 @@ struct pppoe_softc {
|
|||||||
ppp_pcb *pppoe_create(struct netif *pppif,
|
ppp_pcb *pppoe_create(struct netif *pppif,
|
||||||
struct netif *ethif,
|
struct netif *ethif,
|
||||||
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
||||||
err_t pppoe_destroy(struct pppoe_softc *sc);
|
|
||||||
|
|
||||||
int pppoe_connect(struct pppoe_softc *sc);
|
|
||||||
void pppoe_disconnect(struct pppoe_softc *sc);
|
|
||||||
|
|
||||||
void pppoe_disc_input(struct netif *netif, struct pbuf *p);
|
void pppoe_disc_input(struct netif *netif, struct pbuf *p);
|
||||||
void pppoe_data_input(struct netif *netif, struct pbuf *p);
|
void pppoe_data_input(struct netif *netif, struct pbuf *p);
|
||||||
|
@ -196,15 +196,6 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
|
|||||||
struct netif *netif, ip_addr_t *ipaddr, u16_t port, u8_t *secret, u8_t secret_len,
|
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 *ctx_cb);
|
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
||||||
|
|
||||||
/* Destroy a L2TP control block */
|
|
||||||
err_t pppol2tp_destroy(pppol2tp_pcb *l2tp);
|
|
||||||
|
|
||||||
/* Be a LAC, connect to a LNS. */
|
|
||||||
err_t pppol2tp_connect(pppol2tp_pcb *l2tp);
|
|
||||||
|
|
||||||
/* Disconnect */
|
|
||||||
void pppol2tp_disconnect(pppol2tp_pcb *l2tp);
|
|
||||||
|
|
||||||
/* Data packet from PPP to L2TP */
|
/* Data packet from PPP to L2TP */
|
||||||
err_t pppol2tp_xmit(pppol2tp_pcb *l2tp, struct pbuf *pb);
|
err_t pppol2tp_xmit(pppol2tp_pcb *l2tp, struct pbuf *pb);
|
||||||
|
|
||||||
|
@ -407,14 +407,14 @@ int ppp_free(ppp_pcb *pcb) {
|
|||||||
|
|
||||||
#if PPPOE_SUPPORT
|
#if PPPOE_SUPPORT
|
||||||
if (pcb->pppoe_sc) {
|
if (pcb->pppoe_sc) {
|
||||||
pppoe_destroy(pcb->pppoe_sc);
|
pcb->link_command_cb(pcb->pppoe_sc, PPP_LINK_COMMAND_FREE);
|
||||||
pcb->pppoe_sc = NULL;
|
pcb->pppoe_sc = NULL;
|
||||||
}
|
}
|
||||||
#endif /* PPPOE_SUPPORT */
|
#endif /* PPPOE_SUPPORT */
|
||||||
|
|
||||||
#if PPPOL2TP_SUPPORT
|
#if PPPOL2TP_SUPPORT
|
||||||
if (pcb->l2tp_pcb) {
|
if (pcb->l2tp_pcb) {
|
||||||
pppol2tp_destroy(pcb->l2tp_pcb);
|
pcb->link_command_cb(pcb->l2tp_pcb, PPP_LINK_COMMAND_FREE);
|
||||||
pcb->l2tp_pcb = NULL;
|
pcb->l2tp_pcb = NULL;
|
||||||
}
|
}
|
||||||
#endif /* PPPOL2TP_SUPPORT */
|
#endif /* PPPOL2TP_SUPPORT */
|
||||||
@ -1807,7 +1807,7 @@ static void ppp_over_ethernet_open(ppp_pcb *pcb) {
|
|||||||
ao->neg_pcompression = 0;
|
ao->neg_pcompression = 0;
|
||||||
ao->neg_accompression = 0;
|
ao->neg_accompression = 0;
|
||||||
|
|
||||||
pppoe_connect(pcb->pppoe_sc);
|
pcb->link_command_cb(pcb->pppoe_sc, PPP_LINK_COMMAND_CONNECT);
|
||||||
}
|
}
|
||||||
#endif /* PPPOE_SUPPORT */
|
#endif /* PPPOE_SUPPORT */
|
||||||
|
|
||||||
@ -1829,7 +1829,7 @@ static void ppp_over_l2tp_open(ppp_pcb *pcb) {
|
|||||||
ao->neg_pcompression = 0;
|
ao->neg_pcompression = 0;
|
||||||
ao->neg_accompression = 0;
|
ao->neg_accompression = 0;
|
||||||
|
|
||||||
pppol2tp_connect(pcb->l2tp_pcb);
|
pcb->link_command_cb(pcb->l2tp_pcb, PPP_LINK_COMMAND_CONNECT);
|
||||||
}
|
}
|
||||||
#endif /* PPPOL2TP_SUPPORT */
|
#endif /* PPPOL2TP_SUPPORT */
|
||||||
|
|
||||||
@ -1843,12 +1843,12 @@ void ppp_link_terminated(ppp_pcb *pcb) {
|
|||||||
|
|
||||||
#if PPPOE_SUPPORT
|
#if PPPOE_SUPPORT
|
||||||
if (pcb->pppoe_sc) {
|
if (pcb->pppoe_sc) {
|
||||||
pppoe_disconnect(pcb->pppoe_sc);
|
pcb->link_command_cb(pcb->pppoe_sc, PPP_LINK_COMMAND_DISCONNECT);
|
||||||
} else
|
} else
|
||||||
#endif /* PPPOE_SUPPORT */
|
#endif /* PPPOE_SUPPORT */
|
||||||
#if PPPOL2TP_SUPPORT
|
#if PPPOL2TP_SUPPORT
|
||||||
if (pcb->l2tp_pcb) {
|
if (pcb->l2tp_pcb) {
|
||||||
pppol2tp_disconnect(pcb->l2tp_pcb);
|
pcb->link_command_cb(pcb->l2tp_pcb, PPP_LINK_COMMAND_DISCONNECT);
|
||||||
} else
|
} else
|
||||||
#endif /* PPPOL2TP_SUPPORT */
|
#endif /* PPPOL2TP_SUPPORT */
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,13 @@
|
|||||||
static char pppoe_error_tmp[PPPOE_ERRORSTRING_LEN];
|
static char pppoe_error_tmp[PPPOE_ERRORSTRING_LEN];
|
||||||
|
|
||||||
|
|
||||||
|
/* callback called from PPP core */
|
||||||
|
static void pppoe_link_callback(void *pcb, u8_t command);
|
||||||
|
|
||||||
/* management routines */
|
/* management routines */
|
||||||
|
static err_t pppoe_destroy(struct pppoe_softc *sc);
|
||||||
|
static int pppoe_connect(struct pppoe_softc *sc);
|
||||||
|
static void pppoe_disconnect(struct pppoe_softc *sc);
|
||||||
static void pppoe_abort_connect(struct pppoe_softc *);
|
static void pppoe_abort_connect(struct pppoe_softc *);
|
||||||
static void pppoe_clear_softc(struct pppoe_softc *, const char *);
|
static void pppoe_clear_softc(struct pppoe_softc *, const char *);
|
||||||
|
|
||||||
@ -167,10 +173,32 @@ pppoe_create(struct netif *pppif,
|
|||||||
pppoe_softc_list = sc;
|
pppoe_softc_list = sc;
|
||||||
|
|
||||||
ppp->pppoe_sc = sc;
|
ppp->pppoe_sc = sc;
|
||||||
|
ppp_link_set_callback(ppp, pppoe_link_callback);
|
||||||
return ppp;
|
return ppp;
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t
|
/* Called by PPP core */
|
||||||
|
static void pppoe_link_callback(void *pcb, u8_t command) {
|
||||||
|
struct pppoe_softc *sc = (struct pppoe_softc *)pcb;
|
||||||
|
|
||||||
|
switch(command) {
|
||||||
|
case PPP_LINK_COMMAND_CONNECT:
|
||||||
|
pppoe_connect(sc);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PPP_LINK_COMMAND_DISCONNECT:
|
||||||
|
pppoe_disconnect(sc);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PPP_LINK_COMMAND_FREE:
|
||||||
|
pppoe_destroy(sc);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static err_t
|
||||||
pppoe_destroy(struct pppoe_softc *sc)
|
pppoe_destroy(struct pppoe_softc *sc)
|
||||||
{
|
{
|
||||||
struct pppoe_softc *cur, *prev = NULL;
|
struct pppoe_softc *cur, *prev = NULL;
|
||||||
@ -789,7 +817,7 @@ pppoe_timeout(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Start a connection (i.e. initiate discovery phase) */
|
/* Start a connection (i.e. initiate discovery phase) */
|
||||||
int
|
static int
|
||||||
pppoe_connect(struct pppoe_softc *sc)
|
pppoe_connect(struct pppoe_softc *sc)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -819,7 +847,7 @@ pppoe_connect(struct pppoe_softc *sc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* disconnect */
|
/* disconnect */
|
||||||
void
|
static void
|
||||||
pppoe_disconnect(struct pppoe_softc *sc)
|
pppoe_disconnect(struct pppoe_softc *sc)
|
||||||
{
|
{
|
||||||
if (sc->sc_state < PPPOE_STATE_SESSION) {
|
if (sc->sc_state < PPPOE_STATE_SESSION) {
|
||||||
|
@ -72,6 +72,10 @@
|
|||||||
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
||||||
|
|
||||||
/* Prototypes for procedures local to this file. */
|
/* Prototypes for procedures local to this file. */
|
||||||
|
static void pppol2tp_link_callback(void *pcb, u8_t command);
|
||||||
|
static err_t pppol2tp_destroy(pppol2tp_pcb *l2tp); /* Destroy a L2TP control block */
|
||||||
|
static err_t pppol2tp_connect(pppol2tp_pcb *l2tp); /* Be a LAC, connect to a LNS. */
|
||||||
|
static void pppol2tp_disconnect(pppol2tp_pcb *l2tp); /* Disconnect */
|
||||||
static void pppol2tp_input(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
|
static void pppol2tp_input(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
|
||||||
static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, struct ip_addr *addr, u16_t port,
|
static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, struct ip_addr *addr, u16_t port,
|
||||||
struct pbuf *p, u16_t len, u16_t tunnel_id, u16_t session_id, u16_t ns, u16_t nr);
|
struct pbuf *p, u16_t len, u16_t tunnel_id, u16_t session_id, u16_t ns, u16_t nr);
|
||||||
@ -126,11 +130,33 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
|
|||||||
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
||||||
|
|
||||||
ppp->l2tp_pcb = l2tp;
|
ppp->l2tp_pcb = l2tp;
|
||||||
|
ppp_link_set_callback(ppp, pppol2tp_link_callback);
|
||||||
return ppp;
|
return ppp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called by PPP core */
|
||||||
|
static void pppol2tp_link_callback(void *pcb, u8_t command) {
|
||||||
|
pppol2tp_pcb *l2tp = (pppol2tp_pcb *)pcb;
|
||||||
|
|
||||||
|
switch(command) {
|
||||||
|
case PPP_LINK_COMMAND_CONNECT:
|
||||||
|
pppol2tp_connect(l2tp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PPP_LINK_COMMAND_DISCONNECT:
|
||||||
|
pppol2tp_disconnect(l2tp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PPP_LINK_COMMAND_FREE:
|
||||||
|
pppol2tp_destroy(l2tp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Destroy a L2TP control block */
|
/* Destroy a L2TP control block */
|
||||||
err_t pppol2tp_destroy(pppol2tp_pcb *l2tp) {
|
static err_t pppol2tp_destroy(pppol2tp_pcb *l2tp) {
|
||||||
|
|
||||||
sys_untimeout(pppol2tp_timeout, l2tp);
|
sys_untimeout(pppol2tp_timeout, l2tp);
|
||||||
if (l2tp->udp != NULL) {
|
if (l2tp->udp != NULL) {
|
||||||
@ -141,7 +167,7 @@ err_t pppol2tp_destroy(pppol2tp_pcb *l2tp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Be a LAC, connect to a LNS. */
|
/* Be a LAC, connect to a LNS. */
|
||||||
err_t pppol2tp_connect(pppol2tp_pcb *l2tp) {
|
static err_t pppol2tp_connect(pppol2tp_pcb *l2tp) {
|
||||||
err_t err;
|
err_t err;
|
||||||
|
|
||||||
if (l2tp->phase != PPPOL2TP_STATE_INITIAL) {
|
if (l2tp->phase != PPPOL2TP_STATE_INITIAL) {
|
||||||
@ -176,7 +202,7 @@ err_t pppol2tp_connect(pppol2tp_pcb *l2tp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Disconnect */
|
/* Disconnect */
|
||||||
void pppol2tp_disconnect(pppol2tp_pcb *l2tp) {
|
static void pppol2tp_disconnect(pppol2tp_pcb *l2tp) {
|
||||||
|
|
||||||
if (l2tp->phase < PPPOL2TP_STATE_DATA) {
|
if (l2tp->phase < PPPOL2TP_STATE_DATA) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user