X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fcbcp.c;h=6b68228d0b86b0b8528386d2722541d7dca4c380;hb=44cd25b6c5a886f3cb615f2f0d8d78c6a52a2030;hp=9405f7bfa266a179ceb0860f8a6639c6ce373561;hpb=cbe589d089e6db8828f71e88688793ead5b30954;p=ppp.git diff --git a/pppd/cbcp.c b/pppd/cbcp.c index 9405f7b..6b68228 100644 --- a/pppd/cbcp.c +++ b/pppd/cbcp.c @@ -18,21 +18,30 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef lint -static char rcsid[] = "$Id: cbcp.c,v 1.1 1996/10/08 04:35:41 paulus Exp $"; -#endif +#define RCSID "$Id: cbcp.c,v 1.10 1999/08/13 06:46:10 paulus Exp $" #include #include #include #include -#include #include "pppd.h" #include "cbcp.h" #include "fsm.h" #include "lcp.h" -#include "ipcp.h" + +static const char rcsid[] = RCSID; + +/* + * Options. + */ +static int setcbcp __P((char **)); + +static option_t cbcp_option_list[] = { + { "callback", o_special, setcbcp, + "Ask for callback" }, + { NULL } +}; /* * Protocol entry points. @@ -60,6 +69,8 @@ struct protent cbcp_protent = { 0, "CBCP", NULL, + cbcp_option_list, + NULL, NULL, NULL }; @@ -68,11 +79,26 @@ cbcp_state cbcp[NUM_PPP]; /* internal prototypes */ -void cbcp_recvreq(cbcp_state *us, char *pckt, int len); -void cbcp_resp(cbcp_state *us); -void cbcp_up(cbcp_state *us); -void cbcp_recvack(cbcp_state *us, char *pckt, int len); -void cbcp_send(cbcp_state *us, u_char code, u_char *buf, int len); +static void cbcp_recvreq __P((cbcp_state *us, char *pckt, int len)); +static void cbcp_resp __P((cbcp_state *us)); +static void cbcp_up __P((cbcp_state *us)); +static void cbcp_recvack __P((cbcp_state *us, char *pckt, int len)); +static void cbcp_send __P((cbcp_state *us, u_char code, u_char *buf, int len)); + +/* option processing */ +static int +setcbcp(argv) + char **argv; +{ + lcp_wantoptions[0].neg_cbcp = 1; + cbcp_protent.enabled_flag = 1; + cbcp[0].us_number = strdup(*argv); + if (cbcp[0].us_number == 0) + novm("callback number"); + cbcp[0].us_type |= (1 << CB_CONF_USER); + cbcp[0].us_type |= (1 << CB_CONF_ADMIN); + return (1); +} /* init state */ static void @@ -94,18 +120,18 @@ cbcp_lowerup(iface) { cbcp_state *us = &cbcp[iface]; - syslog(LOG_DEBUG, "cbcp_lowerup"); - syslog(LOG_DEBUG, "want: %d", us->us_type); + dbglog("cbcp_lowerup"); + dbglog("want: %d", us->us_type); if (us->us_type == CB_CONF_USER) - syslog(LOG_DEBUG, "phone no: %s", us->us_number); + dbglog("phone no: %s", us->us_number); } static void cbcp_open(unit) int unit; { - syslog(LOG_DEBUG, "cbcp_open"); + dbglog("cbcp_open"); } /* process an incomming packet */ @@ -124,7 +150,7 @@ cbcp_input(unit, inpacket, pktlen) inp = inpacket; if (pktlen < CBCP_MINLEN) { - syslog(LOG_ERR, "CBCP packet is too small"); + error("CBCP packet is too small"); return; } @@ -134,7 +160,7 @@ cbcp_input(unit, inpacket, pktlen) #if 0 if (len > pktlen) { - syslog(LOG_ERR, "CBCP packet: invalid length"); + error("CBCP packet: invalid length"); return; } #endif @@ -148,12 +174,12 @@ cbcp_input(unit, inpacket, pktlen) break; case CBCP_RESP: - syslog(LOG_DEBUG, "CBCP_RESP received"); + dbglog("CBCP_RESP received"); break; case CBCP_ACK: if (id != us->us_id) - syslog(LOG_DEBUG, "id doesn't match: expected %d recv %d", + dbglog("id doesn't match: expected %d recv %d", us->us_id, id); cbcp_recvack(us, inp, len); @@ -189,9 +215,7 @@ cbcp_printpkt(p, plen, printer, arg) void *arg; { int code, opt, id, len, olen, delay; - u_char *pstart, *optend; - u_short cishort; - u_long cilong; + u_char *pstart; if (plen < HEADERLEN) return 0; @@ -274,7 +298,7 @@ cbcp_recvreq(us, pckt, pcktlen) address[0] = 0; while (len) { - syslog(LOG_DEBUG, "length: %d", len); + dbglog("length: %d", len); GETCHAR(type, pckt); GETCHAR(opt_len, pckt); @@ -286,22 +310,22 @@ cbcp_recvreq(us, pckt, pcktlen) switch(type) { case CB_CONF_NO: - syslog(LOG_DEBUG, "no callback allowed"); + dbglog("no callback allowed"); break; case CB_CONF_USER: - syslog(LOG_DEBUG, "user callback allowed"); + dbglog("user callback allowed"); if (opt_len > 4) { GETCHAR(addr_type, pckt); memcpy(address, pckt, opt_len - 4); address[opt_len - 4] = 0; if (address[0]) - syslog(LOG_DEBUG, "address: %s", address); + dbglog("address: %s", address); } break; case CB_CONF_ADMIN: - syslog(LOG_DEBUG, "user admin defined allowed"); + dbglog("user admin defined allowed"); break; case CB_CONF_LIST: @@ -323,7 +347,7 @@ cbcp_resp(us) int len = 0; cb_type = us->us_allowed & us->us_type; - syslog(LOG_DEBUG, "cbcp_resp cb_type=%d", cb_type); + dbglog("cbcp_resp cb_type=%d", cb_type); #if 0 if (!cb_type) @@ -331,7 +355,7 @@ cbcp_resp(us) #endif if (cb_type & ( 1 << CB_CONF_USER ) ) { - syslog(LOG_DEBUG, "cbcp_resp CONF_USER"); + dbglog("cbcp_resp CONF_USER"); PUTCHAR(CB_CONF_USER, bufp); len = 3 + 1 + strlen(us->us_number) + 1; PUTCHAR(len , bufp); @@ -343,24 +367,23 @@ cbcp_resp(us) } if (cb_type & ( 1 << CB_CONF_ADMIN ) ) { - syslog(LOG_DEBUG, "cbcp_resp CONF_ADMIN"); + dbglog("cbcp_resp CONF_ADMIN"); PUTCHAR(CB_CONF_ADMIN, bufp); - len = 3 + 1; - PUTCHAR(len , bufp); + len = 3; + PUTCHAR(len, bufp); PUTCHAR(5, bufp); /* delay */ - PUTCHAR(0, bufp); cbcp_send(us, CBCP_RESP, buf, len); return; } if (cb_type & ( 1 << CB_CONF_NO ) ) { - syslog(LOG_DEBUG, "cbcp_resp CONF_NO"); + dbglog("cbcp_resp CONF_NO"); PUTCHAR(CB_CONF_NO, bufp); len = 3; PUTCHAR(len , bufp); PUTCHAR(0, bufp); cbcp_send(us, CBCP_RESP, buf, len); - ipcp_open(us->us_unit); + start_networks(); return; } } @@ -413,20 +436,21 @@ cbcp_recvack(us, pckt, len) memcpy(address, pckt, opt_len - 4); address[opt_len - 4] = 0; if (address[0]) - syslog(LOG_DEBUG, "peer will call: %s", address); + dbglog("peer will call: %s", address); } + if (type == CB_CONF_NO) + return; } cbcp_up(us); } -extern int persist; - /* ok peer will do callback */ static void cbcp_up(us) cbcp_state *us; { persist = 0; - lcp_close(0); + lcp_close(0, "Call me back, please"); + status = EXIT_CALLBACK; }