PPP, prepare new callbacks for low level protocols

New callbacks: write and netif_output
This commit is contained in:
Sylvain Rochet 2015-02-15 10:35:59 +01:00
parent f8501478f6
commit 45bfccfddc
5 changed files with 20 additions and 8 deletions

View File

@ -349,6 +349,10 @@ typedef struct ppp_pcb_rx_s {
/* /*
* PPP interface control block. * PPP interface control block.
*/ */
typedef void (*link_command_cb_fn)(void *pcb, u8_t command);
typedef void (*link_write_cb_fn)(void *pcb, struct pbuf *p);
typedef void (*link_netif_output_cb_fn)(void *pcb, struct pbuf *p, u_short protocol);
struct ppp_pcb_s { struct ppp_pcb_s {
/* -- below are data that will NOT be cleared between two sessions */ /* -- below are data that will NOT be cleared between two sessions */
#if PPP_DEBUG #if PPP_DEBUG
@ -358,7 +362,9 @@ 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); link_command_cb_fn link_command_cb;
link_write_cb_fn link_write_cb;
link_netif_output_cb_fn link_netif_output_cb;
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
struct pppoe_softc *pppoe_sc; struct pppoe_softc *pppoe_sc;
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */

View File

@ -381,7 +381,7 @@ int ppp_init(void);
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 */ /* Set link callback function */
#define ppp_link_set_callback(ppp, cb) (ppp->link_command_cb = cb) void ppp_link_set_callbacks(ppp_pcb *pcb, link_command_cb_fn command, link_write_cb_fn write, link_netif_output_cb_fn netif_output);
/* Initiate LCP open request */ /* Initiate LCP open request */
void ppp_start(ppp_pcb *pcb); void ppp_start(ppp_pcb *pcb);

View File

@ -550,6 +550,12 @@ static void ppp_clear(ppp_pcb *pcb) {
new_phase(pcb, PPP_PHASE_INITIALIZE); new_phase(pcb, PPP_PHASE_INITIALIZE);
} }
void ppp_link_set_callbacks(ppp_pcb *pcb, link_command_cb_fn command, link_write_cb_fn write, link_netif_output_cb_fn netif_output) {
pcb->link_command_cb = command;
pcb->link_write_cb = write;
pcb->link_netif_output_cb = netif_output;
}
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;

View File

@ -114,7 +114,7 @@ static char pppoe_error_tmp[PPPOE_ERRORSTRING_LEN];
/* callback called from PPP core */ /* callback called from PPP core */
static void pppoe_link_callback(void *pcb, u8_t command); static void pppoe_link_command_callback(void *pcb, u8_t command);
/* management routines */ /* management routines */
static err_t pppoe_destroy(struct pppoe_softc *sc); static err_t pppoe_destroy(struct pppoe_softc *sc);
@ -173,12 +173,12 @@ 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); ppp_link_set_callbacks(ppp, pppoe_link_command_callback, NULL, NULL);
return ppp; return ppp;
} }
/* Called by PPP core */ /* Called by PPP core */
static void pppoe_link_callback(void *pcb, u8_t command) { static void pppoe_link_command_callback(void *pcb, u8_t command) {
struct pppoe_softc *sc = (struct pppoe_softc *)pcb; struct pppoe_softc *sc = (struct pppoe_softc *)pcb;
switch(command) { switch(command) {

View File

@ -72,7 +72,7 @@
#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 void pppol2tp_link_command_callback(void *pcb, u8_t command);
static err_t pppol2tp_destroy(pppol2tp_pcb *l2tp); /* Destroy a L2TP control block */ 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 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_disconnect(pppol2tp_pcb *l2tp); /* Disconnect */
@ -130,12 +130,12 @@ 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); ppp_link_set_callbacks(ppp, pppol2tp_link_command_callback, NULL, NULL);
return ppp; return ppp;
} }
/* Called by PPP core */ /* Called by PPP core */
static void pppol2tp_link_callback(void *pcb, u8_t command) { static void pppol2tp_link_command_callback(void *pcb, u8_t command) {
pppol2tp_pcb *l2tp = (pppol2tp_pcb *)pcb; pppol2tp_pcb *l2tp = (pppol2tp_pcb *)pcb;
switch(command) { switch(command) {