sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
ppp_impl.h
Go to the documentation of this file.
1/*****************************************************************************
2* ppp.h - Network Point to Point Protocol header file.
3*
4* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
5* portions Copyright (c) 1997 Global Election Systems Inc.
6*
7* The authors hereby grant permission to use, copy, modify, distribute,
8* and license this software and its documentation for any purpose, provided
9* that existing copyright notices are retained in all copies and that this
10* notice and the following disclaimer are included verbatim in any
11* distributions. No written agreement, license, or royalty fee is required
12* for any of the authorized uses.
13*
14* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25******************************************************************************
26* REVISION HISTORY
27*
28* 03-01-01 Marc Boucher <marc@mbsi.ca>
29* Ported to lwIP.
30* 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
31* Original derived from BSD codes.
32*****************************************************************************/
37#ifndef LWIP_HDR_PPP_IMPL_H
38#define LWIP_HDR_PPP_IMPL_H
39
40#include "netif/ppp/ppp_opts.h"
41
42#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
43
44#ifdef PPP_INCLUDE_SETTINGS_HEADER
45#include "ppp_settings.h"
46#endif
47
48#include <stdio.h> /* formats */
49#include <stdarg.h>
50#include <string.h>
51#include <stdlib.h> /* strtol() */
52
53#include "lwip/netif.h"
54#include "lwip/def.h"
55#include "lwip/timeouts.h"
56
57#include "ppp.h"
58#include "pppdebug.h"
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64/*
65 * Memory used for control packets.
66 *
67 * PPP_CTRL_PBUF_UNKNOWN_SIZE is the amount of memory we allocate when we
68 * cannot figure out how much we are going to use before filling the buffer.
69 */
70#define PPP_CTRL_PBUF_UNKNOWN_SIZE 512
71
72/*
73 * The basic PPP frame.
74 */
75#define PPP_ADDRESS(p) (((u_char *)(p))[0])
76#define PPP_CONTROL(p) (((u_char *)(p))[1])
77#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
78
79/*
80 * Significant octet values.
81 */
82#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
83#define PPP_UI 0x03 /* Unnumbered Information */
84#define PPP_FLAG 0x7e /* Flag Sequence */
85#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
86#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
87
88/*
89 * PPP_DEFMRU: MRU value used prior negotiation and unless negotiated later.
90 * Must be 1500.
91 */
92#define PPP_DEFMRU 1500
93
94/*
95 * Protocol field values.
96 */
97#if PPP_IPV4_SUPPORT
98#define PPP_IP 0x21 /* Internet Protocol */
99#endif /* PPP_IPV4_SUPPORT */
100#if 0 /* UNUSED */
101#define PPP_AT 0x29 /* AppleTalk Protocol */
102#define PPP_IPX 0x2b /* IPX protocol */
103#endif /* UNUSED */
104#if VJ_SUPPORT
105#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
106#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
107#endif /* VJ_SUPPORT */
108#if PPP_IPV6_SUPPORT
109#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */
110#endif /* PPP_IPV6_SUPPORT */
111#if CCP_SUPPORT
112#define PPP_COMP 0xfd /* compressed packet */
113#endif /* CCP_SUPPORT */
114#define PPP_IPCP 0x8021 /* IP Control Protocol */
115#if 0 /* UNUSED */
116#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
117#define PPP_IPXCP 0x802b /* IPX Control Protocol */
118#endif /* UNUSED */
119#if PPP_IPV6_SUPPORT
120#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */
121#endif /* PPP_IPV6_SUPPORT */
122#if CCP_SUPPORT
123#define PPP_CCP 0x80fd /* Compression Control Protocol */
124#endif /* CCP_SUPPORT */
125#if ECP_SUPPORT
126#define PPP_ECP 0x8053 /* Encryption Control Protocol */
127#endif /* ECP_SUPPORT */
128#define PPP_LCP 0xc021 /* Link Control Protocol */
129#if PAP_SUPPORT
130#define PPP_PAP 0xc023 /* Password Authentication Protocol */
131#endif /* PAP_SUPPORT */
132#if LQR_SUPPORT
133#define PPP_LQR 0xc025 /* Link Quality Report protocol */
134#endif /* LQR_SUPPORT */
135#if CHAP_SUPPORT
136#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
137#endif /* CHAP_SUPPORT */
138#if CBCP_SUPPORT
139#define PPP_CBCP 0xc029 /* Callback Control Protocol */
140#endif /* CBCP_SUPPORT */
141#if EAP_SUPPORT
142#define PPP_EAP 0xc227 /* Extensible Authentication Protocol */
143#endif /* EAP_SUPPORT */
144
145/*
146 * The following struct gives the addresses of procedures to call
147 * for a particular lower link level protocol.
148 */
149struct link_callbacks {
150 /* Start a connection (e.g. Initiate discovery phase) */
151 void (*connect) (ppp_pcb *pcb, void *ctx);
152#if PPP_SERVER
153 /* Listen for an incoming connection (Passive mode) */
154 void (*listen) (ppp_pcb *pcb, void *ctx);
155#endif /* PPP_SERVER */
156 /* End a connection (i.e. initiate disconnect phase) */
157 void (*disconnect) (ppp_pcb *pcb, void *ctx);
158 /* Free lower protocol control block */
159 err_t (*free) (ppp_pcb *pcb, void *ctx);
160 /* Write a pbuf to a ppp link, only used from PPP functions to send PPP packets. */
161 err_t (*write)(ppp_pcb *pcb, void *ctx, struct pbuf *p);
162 /* Send a packet from lwIP core (IPv4 or IPv6) */
163 err_t (*netif_output)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u_short protocol);
164 /* configure the transmit-side characteristics of the PPP interface */
165 void (*send_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
166 /* confire the receive-side characteristics of the PPP interface */
167 void (*recv_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
168};
169
170/*
171 * What to do with network protocol (NP) packets.
172 */
173enum NPmode {
174 NPMODE_PASS, /* pass the packet through */
175 NPMODE_DROP, /* silently drop the packet */
176 NPMODE_ERROR, /* return an error */
177 NPMODE_QUEUE /* save it up for later. */
178};
179
180/*
181 * Statistics.
182 */
183#if PPP_STATS_SUPPORT
184struct pppstat {
185 unsigned int ppp_ibytes; /* bytes received */
186 unsigned int ppp_ipackets; /* packets received */
187 unsigned int ppp_ierrors; /* receive errors */
188 unsigned int ppp_obytes; /* bytes sent */
189 unsigned int ppp_opackets; /* packets sent */
190 unsigned int ppp_oerrors; /* transmit errors */
191};
192
193#if VJ_SUPPORT
194struct vjstat {
195 unsigned int vjs_packets; /* outbound packets */
196 unsigned int vjs_compressed; /* outbound compressed packets */
197 unsigned int vjs_searches; /* searches for connection state */
198 unsigned int vjs_misses; /* times couldn't find conn. state */
199 unsigned int vjs_uncompressedin; /* inbound uncompressed packets */
200 unsigned int vjs_compressedin; /* inbound compressed packets */
201 unsigned int vjs_errorin; /* inbound unknown type packets */
202 unsigned int vjs_tossed; /* inbound packets tossed because of error */
203};
204#endif /* VJ_SUPPORT */
205
206struct ppp_stats {
207 struct pppstat p; /* basic PPP statistics */
208#if VJ_SUPPORT
209 struct vjstat vj; /* VJ header compression statistics */
210#endif /* VJ_SUPPORT */
211};
212
213#if CCP_SUPPORT
214struct compstat {
215 unsigned int unc_bytes; /* total uncompressed bytes */
216 unsigned int unc_packets; /* total uncompressed packets */
217 unsigned int comp_bytes; /* compressed bytes */
218 unsigned int comp_packets; /* compressed packets */
219 unsigned int inc_bytes; /* incompressible bytes */
220 unsigned int inc_packets; /* incompressible packets */
221 unsigned int ratio; /* recent compression ratio << 8 */
222};
223
224struct ppp_comp_stats {
225 struct compstat c; /* packet compression statistics */
226 struct compstat d; /* packet decompression statistics */
227};
228#endif /* CCP_SUPPORT */
229
230#endif /* PPP_STATS_SUPPORT */
231
232#if PPP_IDLETIMELIMIT
233/*
234 * The following structure records the time in seconds since
235 * the last NP packet was sent or received.
236 */
237struct ppp_idle {
238 time_t xmit_idle; /* time since last NP packet sent */
239 time_t recv_idle; /* time since last NP packet received */
240};
241#endif /* PPP_IDLETIMELIMIT */
242
243/* values for epdisc.class */
244#define EPD_NULL 0 /* null discriminator, no data */
245#define EPD_LOCAL 1
246#define EPD_IP 2
247#define EPD_MAC 3
248#define EPD_MAGIC 4
249#define EPD_PHONENUM 5
250
251/*
252 * Global variables.
253 */
254#ifdef HAVE_MULTILINK
255extern u8_t multilink; /* enable multilink operation */
256extern u8_t doing_multilink;
257extern u8_t multilink_master;
258extern u8_t bundle_eof;
259extern u8_t bundle_terminating;
260#endif
261
262#ifdef MAXOCTETS
263extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */
264extern int maxoctets_dir; /* Direction :
265 0 - in+out (default)
266 1 - in
267 2 - out
268 3 - max(in,out) */
269extern int maxoctets_timeout; /* Timeout for check of octets limit */
270#define PPP_OCTETS_DIRECTION_SUM 0
271#define PPP_OCTETS_DIRECTION_IN 1
272#define PPP_OCTETS_DIRECTION_OUT 2
273#define PPP_OCTETS_DIRECTION_MAXOVERAL 3
274/* same as previous, but little different on RADIUS side */
275#define PPP_OCTETS_DIRECTION_MAXSESSION 4
276#endif
277
278/* Data input may be used by CCP and ECP, remove this entry
279 * from struct protent to save some flash
280 */
281#define PPP_DATAINPUT 0
282
283/*
284 * The following struct gives the addresses of procedures to call
285 * for a particular protocol.
286 */
287struct protent {
288 u_short protocol; /* PPP protocol number */
289 /* Initialization procedure */
290 void (*init) (ppp_pcb *pcb);
291 /* Process a received packet */
292 void (*input) (ppp_pcb *pcb, u_char *pkt, int len);
293 /* Process a received protocol-reject */
294 void (*protrej) (ppp_pcb *pcb);
295 /* Lower layer has come up */
296 void (*lowerup) (ppp_pcb *pcb);
297 /* Lower layer has gone down */
298 void (*lowerdown) (ppp_pcb *pcb);
299 /* Open the protocol */
300 void (*open) (ppp_pcb *pcb);
301 /* Close the protocol */
302 void (*close) (ppp_pcb *pcb, const char *reason);
303#if PRINTPKT_SUPPORT
304 /* Print a packet in readable form */
305 int (*printpkt) (const u_char *pkt, int len,
306 void (*printer) (void *, const char *, ...),
307 void *arg);
308#endif /* PRINTPKT_SUPPORT */
309#if PPP_DATAINPUT
310 /* Process a received data packet */
311 void (*datainput) (ppp_pcb *pcb, u_char *pkt, int len);
312#endif /* PPP_DATAINPUT */
313#if PRINTPKT_SUPPORT
314 const char *name; /* Text name of protocol */
315 const char *data_name; /* Text name of corresponding data protocol */
316#endif /* PRINTPKT_SUPPORT */
317#if PPP_OPTIONS
318 option_t *options; /* List of command-line options */
319 /* Check requested options, assign defaults */
320 void (*check_options) (void);
321#endif /* PPP_OPTIONS */
322#if DEMAND_SUPPORT
323 /* Configure interface for demand-dial */
324 int (*demand_conf) (int unit);
325 /* Say whether to bring up link for this pkt */
326 int (*active_pkt) (u_char *pkt, int len);
327#endif /* DEMAND_SUPPORT */
328};
329
330/* Table of pointers to supported protocols */
331extern const struct protent* const protocols[];
332
333
334/* Values for auth_pending, auth_done */
335#if PAP_SUPPORT
336#define PAP_WITHPEER 0x1
337#define PAP_PEER 0x2
338#endif /* PAP_SUPPORT */
339#if CHAP_SUPPORT
340#define CHAP_WITHPEER 0x4
341#define CHAP_PEER 0x8
342#endif /* CHAP_SUPPORT */
343#if EAP_SUPPORT
344#define EAP_WITHPEER 0x10
345#define EAP_PEER 0x20
346#endif /* EAP_SUPPORT */
347
348/* Values for auth_done only */
349#if CHAP_SUPPORT
350#define CHAP_MD5_WITHPEER 0x40
351#define CHAP_MD5_PEER 0x80
352#if MSCHAP_SUPPORT
353#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */
354#define CHAP_MS_WITHPEER 0x100
355#define CHAP_MS_PEER 0x200
356#define CHAP_MS2_WITHPEER 0x400
357#define CHAP_MS2_PEER 0x800
358#endif /* MSCHAP_SUPPORT */
359#endif /* CHAP_SUPPORT */
360
361/* Supported CHAP protocols */
362#if CHAP_SUPPORT
363
364#if MSCHAP_SUPPORT
365#define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
366#else /* MSCHAP_SUPPORT */
367#define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5)
368#endif /* MSCHAP_SUPPORT */
369
370#else /* CHAP_SUPPORT */
371#define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE)
372#endif /* CHAP_SUPPORT */
373
374#if PPP_STATS_SUPPORT
375/*
376 * PPP statistics structure
377 */
378struct pppd_stats {
379 unsigned int bytes_in;
380 unsigned int bytes_out;
381 unsigned int pkts_in;
382 unsigned int pkts_out;
383};
384#endif /* PPP_STATS_SUPPORT */
385
386
387/*
388 * PPP private functions
389 */
390
391
392/*
393 * Functions called from lwIP core.
394 */
395
396/* initialize the PPP subsystem */
397int ppp_init(void);
398
399/*
400 * Functions called from PPP link protocols.
401 */
402
403/* Create a new PPP control block */
404ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb,
405 ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
406
407/* Initiate LCP open request */
408void ppp_start(ppp_pcb *pcb);
409
410/* Called when link failed to setup */
411void ppp_link_failed(ppp_pcb *pcb);
412
413/* Called when link is normally down (i.e. it was asked to end) */
414void ppp_link_end(ppp_pcb *pcb);
415
416/* function called to process input packet */
417void ppp_input(ppp_pcb *pcb, struct pbuf *pb);
418
419
420/*
421 * Functions called by PPP protocols.
422 */
423
424/* function called by all PPP subsystems to send packets */
425err_t ppp_write(ppp_pcb *pcb, struct pbuf *p);
426
427/* functions called by auth.c link_terminated() */
428void ppp_link_terminated(ppp_pcb *pcb);
429
430void new_phase(ppp_pcb *pcb, int p);
431
432int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp);
433int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp);
434
435#if PPP_IPV4_SUPPORT
436int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask);
437int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr);
438#if 0 /* UNUSED - PROXY ARP */
439int sifproxyarp(ppp_pcb *pcb, u32_t his_adr);
440int cifproxyarp(ppp_pcb *pcb, u32_t his_adr);
441#endif /* UNUSED - PROXY ARP */
442#if LWIP_DNS
443int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
444int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
445#endif /* LWIP_DNS */
446#if VJ_SUPPORT
447int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid);
448#endif /* VJ_SUPPORT */
449int sifup(ppp_pcb *pcb);
450int sifdown (ppp_pcb *pcb);
451u32_t get_mask(u32_t addr);
452#endif /* PPP_IPV4_SUPPORT */
453
454#if PPP_IPV6_SUPPORT
455int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
456int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
457int sif6up(ppp_pcb *pcb);
458int sif6down (ppp_pcb *pcb);
459#endif /* PPP_IPV6_SUPPORT */
460
461#if DEMAND_SUPPORT
462int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode);
463#endif /* DEMAND_SUPPORt */
464
465void ppp_netif_set_mtu(ppp_pcb *pcb, int mtu);
466int ppp_netif_get_mtu(ppp_pcb *pcb);
467
468#if CCP_SUPPORT
469#if 0 /* unused */
470int ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit);
471#endif /* unused */
472void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method);
473void ccp_reset_comp(ppp_pcb *pcb);
474void ccp_reset_decomp(ppp_pcb *pcb);
475#if 0 /* unused */
476int ccp_fatal_error(ppp_pcb *pcb);
477#endif /* unused */
478#endif /* CCP_SUPPORT */
479
480#if PPP_IDLETIMELIMIT
481int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip);
482#endif /* PPP_IDLETIMELIMIT */
483
484#if DEMAND_SUPPORT
485int get_loop_output(void);
486#endif /* DEMAND_SUPPORT */
487
488/* Optional protocol names list, to make our messages a little more informative. */
489#if PPP_PROTOCOLNAME
490const char * protocol_name(int proto);
491#endif /* PPP_PROTOCOLNAME */
492
493/* Optional stats support, to get some statistics on the PPP interface */
494#if PPP_STATS_SUPPORT
495void print_link_stats(void); /* Print stats, if available */
496void reset_link_stats(int u); /* Reset (init) stats when link goes up */
497void update_link_stats(int u); /* Get stats at link termination */
498#endif /* PPP_STATS_SUPPORT */
499
500
501
502/*
503 * Inline versions of get/put char/short/long.
504 * Pointer is advanced; we assume that both arguments
505 * are lvalues and will already be in registers.
506 * cp MUST be u_char *.
507 */
508#define GETCHAR(c, cp) { \
509 (c) = *(cp)++; \
510}
511#define PUTCHAR(c, cp) { \
512 *(cp)++ = (u_char) (c); \
513}
514#define GETSHORT(s, cp) { \
515 (s) = *(cp)++ << 8; \
516 (s) |= *(cp)++; \
517}
518#define PUTSHORT(s, cp) { \
519 *(cp)++ = (u_char) ((s) >> 8); \
520 *(cp)++ = (u_char) (s); \
521}
522#define GETLONG(l, cp) { \
523 (l) = *(cp)++ << 8; \
524 (l) |= *(cp)++; (l) <<= 8; \
525 (l) |= *(cp)++; (l) <<= 8; \
526 (l) |= *(cp)++; \
527}
528#define PUTLONG(l, cp) { \
529 *(cp)++ = (u_char) ((l) >> 24); \
530 *(cp)++ = (u_char) ((l) >> 16); \
531 *(cp)++ = (u_char) ((l) >> 8); \
532 *(cp)++ = (u_char) (l); \
533}
534
535#define INCPTR(n, cp) ((cp) += (n))
536#define DECPTR(n, cp) ((cp) -= (n))
537
538/*
539 * System dependent definitions for user-level 4.3BSD UNIX implementation.
540 */
541#define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0)
542#define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0)
543#define UNTIMEOUT(f, a) sys_untimeout((f), (a))
544
545#define BZERO(s, n) memset(s, 0, n)
546#define BCMP(s1, s2, l) memcmp(s1, s2, l)
547
548#define PRINTMSG(m, l) { ppp_info(("Remote message: %0.*v", l, m)); }
549
550/*
551 * MAKEHEADER - Add Header fields to a packet.
552 */
553#define MAKEHEADER(p, t) { \
554 PUTCHAR(PPP_ALLSTATIONS, p); \
555 PUTCHAR(PPP_UI, p); \
556 PUTSHORT(t, p); }
557
558/* Procedures exported from auth.c */
559void link_required(ppp_pcb *pcb); /* we are starting to use the link */
560void link_terminated(ppp_pcb *pcb); /* we are finished with the link */
561void link_down(ppp_pcb *pcb); /* the LCP layer has left the Opened state */
562void upper_layers_down(ppp_pcb *pcb); /* take all NCPs down */
563void link_established(ppp_pcb *pcb); /* the link is up; authenticate now */
564void start_networks(ppp_pcb *pcb); /* start all the network control protos */
565void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */
566#if PPP_AUTH_SUPPORT
567#if PPP_SERVER
568int auth_check_passwd(ppp_pcb *pcb, char *auser, unsigned int userlen, char *apasswd, unsigned int passwdlen, const char **msg, int *msglen);
569 /* check the user name and passwd against configuration */
570void auth_peer_fail(ppp_pcb *pcb, int protocol);
571 /* peer failed to authenticate itself */
572void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char *name, int namelen);
573 /* peer successfully authenticated itself */
574#endif /* PPP_SERVER */
575void auth_withpeer_fail(ppp_pcb *pcb, int protocol);
576 /* we failed to authenticate ourselves */
577void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor);
578 /* we successfully authenticated ourselves */
579#endif /* PPP_AUTH_SUPPORT */
580void np_up(ppp_pcb *pcb, int proto); /* a network protocol has come up */
581void np_down(ppp_pcb *pcb, int proto); /* a network protocol has gone down */
582void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */
583#if PPP_AUTH_SUPPORT
584int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server);
585 /* get "secret" for chap */
586#endif /* PPP_AUTH_SUPPORT */
587
588/* Procedures exported from ipcp.c */
589/* int parse_dotted_ip (char *, u32_t *); */
590
591/* Procedures exported from demand.c */
592#if DEMAND_SUPPORT
593void demand_conf (void); /* config interface(s) for demand-dial */
594void demand_block (void); /* set all NPs to queue up packets */
595void demand_unblock (void); /* set all NPs to pass packets */
596void demand_discard (void); /* set all NPs to discard packets */
597void demand_rexmit (int, u32_t); /* retransmit saved frames for an NP*/
598int loop_chars (unsigned char *, int); /* process chars from loopback */
599int loop_frame (unsigned char *, int); /* should we bring link up? */
600#endif /* DEMAND_SUPPORT */
601
602/* Procedures exported from multilink.c */
603#ifdef HAVE_MULTILINK
604void mp_check_options (void); /* Check multilink-related options */
605int mp_join_bundle (void); /* join our link to an appropriate bundle */
606void mp_exit_bundle (void); /* have disconnected our link from bundle */
607void mp_bundle_terminated (void);
608char *epdisc_to_str (struct epdisc *); /* string from endpoint discrim. */
609int str_to_epdisc (struct epdisc *, char *); /* endpt disc. from str */
610#else
611#define mp_bundle_terminated() /* nothing */
612#define mp_exit_bundle() /* nothing */
613#define doing_multilink 0
614#define multilink_master 0
615#endif
616
617/* Procedures exported from utils.c. */
618void ppp_print_string(const u_char *p, int len, void (*printer) (void *, const char *, ...), void *arg); /* Format a string for output */
619int ppp_slprintf(char *buf, int buflen, const char *fmt, ...); /* sprintf++ */
620int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args); /* vsprintf++ */
621size_t ppp_strlcpy(char *dest, const char *src, size_t len); /* safe strcpy */
622size_t ppp_strlcat(char *dest, const char *src, size_t len); /* safe strncpy */
623void ppp_dbglog_impl(const char *fmt, ...); /* log a debug message */
624void ppp_info_impl(const char *fmt, ...); /* log an informational message */
625void ppp_notice_impl(const char *fmt, ...); /* log a notice-level message */
626void ppp_warn_impl(const char *fmt, ...); /* log a warning message */
627void ppp_error_impl(const char *fmt, ...); /* log an error message */
628void ppp_fatal_impl(const char *fmt, ...); /* log an error message and die(1) */
629/* wrap all the above functions so they will only be linked when enabled */
630#define ppp_dbglog(x) do { if (LWIP_DEBUG_ENABLED(LOG_DEBUG)) { ppp_dbglog_impl x; }} while(0)
631#define ppp_info(x) do { if (LWIP_DEBUG_ENABLED(LOG_INFO)) { ppp_info_impl x; }} while(0)
632#define ppp_notice(x) do { if (LWIP_DEBUG_ENABLED(LOG_NOTICE)) { ppp_notice_impl x; }} while(0)
633#define ppp_warn(x) do { if (LWIP_DEBUG_ENABLED(LOG_WARNING)) { ppp_warn_impl x; }} while(0)
634#define ppp_error(x) do { if (LWIP_DEBUG_ENABLED(LOG_ERR)) { ppp_error_impl x; }} while(0)
635#define ppp_fatal(x) do { if (LWIP_DEBUG_ENABLED(LOG_CRITICAL)) { ppp_fatal_impl x; }} while(0)
636#if PRINTPKT_SUPPORT
637void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len);
638 /* dump packet to debug log if interesting */
639#endif /* PRINTPKT_SUPPORT */
640
641/*
642 * Number of necessary timers analysis.
643 *
644 * PPP use at least one timer per each of its protocol, but not all protocols are
645 * active at the same time, thus the number of necessary timeouts is actually
646 * lower than enabled protocols. Here is the actual necessary timeouts based
647 * on code analysis.
648 *
649 * Note that many features analysed here are not working at all and are only
650 * there for a comprehensive analysis of necessary timers in order to prevent
651 * having to redo that each time we add a feature.
652 *
653 * Timer list
654 *
655 * | holdoff timeout
656 * | low level protocol timeout (PPPoE or PPPoL2P)
657 * | LCP delayed UP
658 * | LCP retransmit (FSM)
659 * | LCP Echo timer
660 * .| PAP or CHAP or EAP authentication
661 * . | ECP retransmit (FSM)
662 * . | CCP retransmit (FSM) when MPPE is enabled
663 * . | CCP retransmit (FSM) when MPPE is NOT enabled
664 * . | IPCP retransmit (FSM)
665 * . .| IP6CP retransmit (FSM)
666 * . . | Idle time limit
667 * . . | Max connect time
668 * . . | Max octets
669 * . . | CCP RACK timeout
670 * . . .
671 * PPP_PHASE_DEAD
672 * PPP_PHASE_HOLDOFF
673 * | . . .
674 * PPP_PHASE_INITIALIZE
675 * | . . .
676 * PPP_PHASE_ESTABLISH
677 * | . . .
678 * |. . .
679 * | . .
680 * PPP_PHASE_AUTHENTICATE
681 * || . .
682 * PPP_PHASE_NETWORK
683 * |||| . .
684 * || ||| .
685 * PPP_PHASE_RUNNING
686 * | .|||||
687 * | . ||||
688 * PPP_PHASE_TERMINATE
689 * | . ||||
690 * PPP_PHASE_NETWORK
691 * |. .
692 * PPP_PHASE_ESTABLISH
693 * PPP_PHASE_DISCONNECT
694 * PPP_PHASE_DEAD
695 *
696 * Alright, PPP basic retransmission and LCP Echo consume one timer.
697 * 1
698 *
699 * If authentication is enabled one timer is necessary during authentication.
700 * This timer might still be running up to network phase for any necessary
701 * rechallenge, mostly for PPP server support.
702 * 1 + PPP_AUTH_SUPPORT
703 *
704 * If ECP is enabled one timer is necessary before IPCP and/or IP6CP, one more
705 * is necessary if CCP is enabled (only with MPPE support but we don't care much
706 * up to this detail level).
707 * 1 + PPP_AUTH_SUPPORT + ECP_SUPPORT + CCP_SUPPORT
708 *
709 * If CCP is enabled it might consume a timer during IPCP or IP6CP, thus
710 * we might use AUTH, IPCP, IP6CP and CCP timers simultaneously.
711 * 1 + PPP_AUTH_SUPPORT + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT
712 *
713 * When entering running phase, IPCP or IP6CP is still running. If idle time limit
714 * is enabled one more timer is necessary. Same for max connect time and max
715 * octets features. Furthermore CCP RACK might be used past this point.
716 * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT
717 *
718 * Then the maximum number of simultaneously running timers is given by:
719 * 1 + MAX(PPP_AUTH_SUPPORT + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT,
720 * PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT)
721 *
722 * We don't support ECP_SUPPORT + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS features
723 * and adding those defines to ppp_opts.h just for having the value always defined to 0
724 * is not worth it, thus reducing the overall complexity.
725 * 1 + MAX(PPP_AUTH_SUPPORT + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT,
726 * PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + CCP_SUPPORT)
727 *
728 * PPP_AUTH_SUPPORT is not available in ppp_opts.h because it is defined later in ppp.h,
729 * but we do not need to be that picky about the real number of simultaneously running
730 * timers so we just set the base number of timeouts to 2, thus the following is enough
731 * for now.
732 * 2 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT
733 */
734
735#ifdef __cplusplus
736}
737#endif
738
739#endif /* PPP_SUPPORT */
740#endif /* LWIP_HDR_PPP_IMPL_H */
s8_t err_t
Definition err.h:96
Definition tcpip.h:234