PPP, slight API change, great code factorisation

Created new ppp_over_X_create() functions which only prepare the PPP session without starting it
Removed ppp_reopen() and all of its sub ppp_over_X_reopen()
Removed PPPoL2TP reconnect() function, merged to connect()
Added ppp_open() able to start or restart any session
This commit is contained in:
Sylvain Rochet
2013-04-22 23:58:51 +02:00
parent ed294c5945
commit 44b527415f
6 changed files with 98 additions and 187 deletions

View File

@@ -56,7 +56,7 @@ struct pppapi_msg_msg {
sio_fd_t fd;
ppp_link_status_cb_fn link_status_cb;
void *link_status_ctx;
} serialopen;
} serialcreate;
#endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT
struct {
@@ -65,7 +65,7 @@ struct pppapi_msg_msg {
const char *concentrator_name;
ppp_link_status_cb_fn link_status_cb;
void *link_status_ctx;
} ethernetopen;
} ethernetcreate;
#endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT
struct {
@@ -78,11 +78,11 @@ struct pppapi_msg_msg {
#endif /* PPPOL2TP_AUTH_SUPPORT */
ppp_link_status_cb_fn link_status_cb;
void *link_status_ctx;
} l2tpopen;
} l2tpcreate;
#endif /* PPPOL2TP_SUPPORT */
struct {
u16_t holdoff;
} reopen;
} open;
struct {
int cmd;
void *arg;
@@ -110,19 +110,19 @@ 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 PPPOS_SUPPORT
int pppapi_over_serial_open(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 *link_status_ctx);
#endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT
int pppapi_over_ethernet_open(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,
void *link_status_ctx);
#endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT
int pppapi_over_l2tp_open(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,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx);
#endif /* PPPOL2TP_SUPPORT */
int pppapi_reopen(ppp_pcb *pcb, u16_t holdoff);
int pppapi_open(ppp_pcb *pcb, u16_t holdoff);
int pppapi_close(ppp_pcb *pcb);
void pppapi_sighup(ppp_pcb *pcb);
int pppapi_delete(ppp_pcb *pcb);

View File

@@ -488,44 +488,44 @@ typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx);
#if PPPOS_SUPPORT
/*
* Start a new PPP connection using the given serial I/O device.
* Create a new PPP connection using the given serial I/O device.
*
* If this port connects to a modem, the modem connection must be
* established before calling this.
*
* Return 0 on success, an error code on failure.
*/
int ppp_over_serial_open(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 *link_status_ctx);
#endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT
/*
* Start a new PPP Over Ethernet (PPPoE) connection.
* Create a new PPP Over Ethernet (PPPoE) connection.
*
* Return 0 on success, an error code on failure.
*/
int ppp_over_ethernet_open(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);
#endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT
/*
* Open a new PPP Over L2TP (PPPoL2TP) connection.
* Create a new PPP Over L2TP (PPPoL2TP) connection.
*/
int ppp_over_l2tp_open(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,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx);
#endif /* PPPOL2TP_SUPPORT */
/*
* Open a previously opened PPP connection.
* Open a PPP connection.
*
* This can only be called if PPP is in the dead phase.
*
* Holdoff is the time to wait (in seconds) before initiating
* the connection.
*/
int ppp_reopen(ppp_pcb *pcb, u16_t holdoff);
int ppp_open(ppp_pcb *pcb, u16_t holdoff);
/*
* Initiate the end of a PPP connection.

View File

@@ -197,21 +197,19 @@ struct pppol2tp_pcb_s {
/* Create a new L2TP session. */
err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status),
pppol2tp_pcb **l2tpptr, u8_t *secret, u8_t secret_len);
err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status), pppol2tp_pcb **l2tpptr,
struct netif *netif, ip_addr_t *ipaddr, u16_t port,
u8_t *secret, u8_t secret_len);
/* 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, struct netif *netif, ip_addr_t *ipaddr, u16_t port);
err_t pppol2tp_connect(pppol2tp_pcb *l2tp);
/* Disconnect */
void pppol2tp_disconnect(pppol2tp_pcb *l2tp);
/* Reconnect to a LNS, using previously set L2TP server IP address and port. */
void pppol2tp_reconnect(pppol2tp_pcb *l2tp);
/* Data packet from PPP to L2TP */
err_t pppol2tp_xmit(pppol2tp_pcb *l2tp, struct pbuf *pb);