33 #ifndef LWIP_HDR_PPP_IMPL_H
34 #define LWIP_HDR_PPP_IMPL_H
40 #ifdef PPP_INCLUDE_SETTINGS_HEADER
41 #include "ppp_settings.h"
63 #define PPP_CTRL_PBUF_TYPE PBUF_RAM
64 #define PPP_CTRL_PBUF_MAX_SIZE 512
66 #define PPP_CTRL_PBUF_TYPE PBUF_POOL
67 #define PPP_CTRL_PBUF_MAX_SIZE PBUF_POOL_BUFSIZE
73 #define PPP_ADDRESS(p) (((u_char *)(p))[0])
74 #define PPP_CONTROL(p) (((u_char *)(p))[1])
75 #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
80 #define PPP_ALLSTATIONS 0xff
83 #define PPP_ESCAPE 0x7d
84 #define PPP_TRANS 0x20
95 #define PPP_VJC_COMP 0x2d
96 #define PPP_VJC_UNCOMP 0x2f
102 #define PPP_COMP 0xfd
104 #define PPP_IPCP 0x8021
106 #define PPP_ATCP 0x8029
107 #define PPP_IPXCP 0x802b
110 #define PPP_IPV6CP 0x8057
113 #define PPP_CCP 0x80fd
116 #define PPP_ECP 0x8053
118 #define PPP_LCP 0xc021
120 #define PPP_PAP 0xc023
123 #define PPP_LQR 0xc025
126 #define PPP_CHAP 0xc223
129 #define PPP_CBCP 0xc029
132 #define PPP_EAP 0xc227
139 struct link_callbacks {
141 void (*connect) (ppp_pcb *pcb,
void *ctx);
144 void (*listen) (ppp_pcb *pcb,
void *ctx);
147 void (*disconnect) (ppp_pcb *pcb,
void *ctx);
149 err_t (*free) (ppp_pcb *pcb,
void *ctx);
153 err_t (*netif_output)(ppp_pcb *pcb,
void *ctx,
struct pbuf *p, u_short protocol);
155 void (*send_config)(ppp_pcb *pcb,
void *ctx,
u32_t accm,
int pcomp,
int accomp);
157 void (*recv_config)(ppp_pcb *pcb,
void *ctx,
u32_t accm,
int pcomp,
int accomp);
173 #if PPP_STATS_SUPPORT
175 unsigned int ppp_ibytes;
176 unsigned int ppp_ipackets;
177 unsigned int ppp_ierrors;
178 unsigned int ppp_obytes;
179 unsigned int ppp_opackets;
180 unsigned int ppp_oerrors;
185 unsigned int vjs_packets;
186 unsigned int vjs_compressed;
187 unsigned int vjs_searches;
188 unsigned int vjs_misses;
189 unsigned int vjs_uncompressedin;
190 unsigned int vjs_compressedin;
191 unsigned int vjs_errorin;
192 unsigned int vjs_tossed;
205 unsigned int unc_bytes;
206 unsigned int unc_packets;
207 unsigned int comp_bytes;
208 unsigned int comp_packets;
209 unsigned int inc_bytes;
210 unsigned int inc_packets;
214 struct ppp_comp_stats {
222 #if PPP_IDLETIMELIMIT
239 #define EPD_PHONENUM 5
244 #ifdef HAVE_MULTILINK
245 extern u8_t multilink;
246 extern u8_t doing_multilink;
247 extern u8_t multilink_master;
248 extern u8_t bundle_eof;
249 extern u8_t bundle_terminating;
253 extern unsigned int maxoctets;
254 extern int maxoctets_dir;
259 extern int maxoctets_timeout;
260 #define PPP_OCTETS_DIRECTION_SUM 0
261 #define PPP_OCTETS_DIRECTION_IN 1
262 #define PPP_OCTETS_DIRECTION_OUT 2
263 #define PPP_OCTETS_DIRECTION_MAXOVERAL 3
265 #define PPP_OCTETS_DIRECTION_MAXSESSION 4
271 #define PPP_DATAINPUT 0
280 void (*init) (ppp_pcb *pcb);
282 void (*input) (ppp_pcb *pcb, u_char *pkt,
int len);
284 void (*protrej) (ppp_pcb *pcb);
286 void (*lowerup) (ppp_pcb *pcb);
288 void (*lowerdown) (ppp_pcb *pcb);
290 void (*open) (ppp_pcb *pcb);
292 void (*
close) (ppp_pcb *pcb,
const char *reason);
295 int (*printpkt) (
const u_char *pkt,
int len,
296 void (*printer) (
void *,
const char *, ...),
301 void (*datainput) (ppp_pcb *pcb, u_char *pkt,
int len);
305 const char *data_name;
316 int (*active_pkt) (u_char *pkt,
int len);
321 extern const struct protent*
const protocols[];
326 #define PAP_WITHPEER 0x1
330 #define CHAP_WITHPEER 0x4
331 #define CHAP_PEER 0x8
334 #define EAP_WITHPEER 0x10
335 #define EAP_PEER 0x20
340 #define CHAP_MD5_WITHPEER 0x40
341 #define CHAP_MD5_PEER 0x80
343 #define CHAP_MS_SHIFT 8
344 #define CHAP_MS_WITHPEER 0x100
345 #define CHAP_MS_PEER 0x200
346 #define CHAP_MS2_WITHPEER 0x400
347 #define CHAP_MS2_PEER 0x800
355 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
357 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5)
361 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE)
364 #if PPP_STATS_SUPPORT
369 unsigned int bytes_in;
370 unsigned int bytes_out;
371 unsigned int pkts_in;
372 unsigned int pkts_out;
394 ppp_pcb *ppp_new(
struct netif *pppif,
const struct link_callbacks *callbacks,
void *link_ctx_cb,
395 ppp_link_status_cb_fn link_status_cb,
void *ctx_cb);
398 void ppp_start(ppp_pcb *pcb);
401 void ppp_link_failed(ppp_pcb *pcb);
404 void ppp_link_end(ppp_pcb *pcb);
407 void ppp_input(ppp_pcb *pcb,
struct pbuf *pb);
410 struct pbuf *ppp_singlebuf(
struct pbuf *p);
418 err_t ppp_write(ppp_pcb *pcb,
struct pbuf *p);
421 void ppp_link_terminated(ppp_pcb *pcb);
423 void new_phase(ppp_pcb *pcb,
int p);
425 int ppp_send_config(ppp_pcb *pcb,
int mtu,
u32_t accm,
int pcomp,
int accomp);
426 int ppp_recv_config(ppp_pcb *pcb,
int mru,
u32_t accm,
int pcomp,
int accomp);
430 int cifaddr(ppp_pcb *pcb,
u32_t our_adr,
u32_t his_adr);
432 int sifproxyarp(ppp_pcb *pcb,
u32_t his_adr);
433 int cifproxyarp(ppp_pcb *pcb,
u32_t his_adr);
440 int sifvjcomp(ppp_pcb *pcb,
int vjcomp,
int cidcomp,
int maxcid);
442 int sifup(ppp_pcb *pcb);
443 int sifdown (ppp_pcb *pcb);
448 int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
449 int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
450 int sif6up(ppp_pcb *pcb);
451 int sif6down (ppp_pcb *pcb);
455 int sifnpmode(ppp_pcb *pcb,
int proto,
enum NPmode
mode);
458 void netif_set_mtu(ppp_pcb *pcb,
int mtu);
459 int netif_get_mtu(ppp_pcb *pcb);
463 int ccp_test(ppp_pcb *pcb, u_char *opt_ptr,
int opt_len,
int for_transmit);
465 void ccp_set(ppp_pcb *pcb,
u8_t isopen,
u8_t isup,
u8_t receive_method,
u8_t transmit_method);
466 void ccp_reset_comp(ppp_pcb *pcb);
467 void ccp_reset_decomp(ppp_pcb *pcb);
469 int ccp_fatal_error(ppp_pcb *pcb);
473 #if PPP_IDLETIMELIMIT
474 int get_idle_time(ppp_pcb *pcb,
struct ppp_idle *ip);
478 int get_loop_output(
void);
483 const char * protocol_name(
int proto);
487 #if PPP_STATS_SUPPORT
488 void print_link_stats(
void);
489 void reset_link_stats(
int u);
490 void update_link_stats(
int u);
501 #define GETCHAR(c, cp) { \
504 #define PUTCHAR(c, cp) { \
505 *(cp)++ = (u_char) (c); \
507 #define GETSHORT(s, cp) { \
508 (s) = *(cp)++ << 8; \
511 #define PUTSHORT(s, cp) { \
512 *(cp)++ = (u_char) ((s) >> 8); \
513 *(cp)++ = (u_char) (s); \
515 #define GETLONG(l, cp) { \
516 (l) = *(cp)++ << 8; \
517 (l) |= *(cp)++; (l) <<= 8; \
518 (l) |= *(cp)++; (l) <<= 8; \
521 #define PUTLONG(l, cp) { \
522 *(cp)++ = (u_char) ((l) >> 24); \
523 *(cp)++ = (u_char) ((l) >> 16); \
524 *(cp)++ = (u_char) ((l) >> 8); \
525 *(cp)++ = (u_char) (l); \
528 #define INCPTR(n, cp) ((cp) += (n))
529 #define DECPTR(n, cp) ((cp) -= (n))
534 #define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0)
535 #define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0)
536 #define UNTIMEOUT(f, a) sys_untimeout((f), (a))
538 #define BZERO(s, n) memset(s, 0, n)
539 #define BCMP(s1, s2, l) memcmp(s1, s2, l)
541 #define PRINTMSG(m, l) { ppp_info("Remote message: %0.*v", l, m); }
546 #define MAKEHEADER(p, t) { \
547 PUTCHAR(PPP_ALLSTATIONS, p); \
548 PUTCHAR(PPP_UI, p); \
552 void link_required(ppp_pcb *pcb);
553 void link_terminated(ppp_pcb *pcb);
554 void link_down(ppp_pcb *pcb);
555 void upper_layers_down(ppp_pcb *pcb);
556 void link_established(ppp_pcb *pcb);
557 void start_networks(ppp_pcb *pcb);
558 void continue_networks(ppp_pcb *pcb);
561 int auth_check_passwd(ppp_pcb *pcb,
char *auser,
int userlen,
char *apasswd,
int passwdlen,
const char **msg,
int *msglen);
563 void auth_peer_fail(ppp_pcb *pcb,
int protocol);
565 void auth_peer_success(ppp_pcb *pcb,
int protocol,
int prot_flavor,
const char *name,
int namelen);
568 void auth_withpeer_fail(ppp_pcb *pcb,
int protocol);
570 void auth_withpeer_success(ppp_pcb *pcb,
int protocol,
int prot_flavor);
573 void np_up(ppp_pcb *pcb,
int proto);
574 void np_down(ppp_pcb *pcb,
int proto);
575 void np_finished(ppp_pcb *pcb,
int proto);
577 int get_secret(ppp_pcb *pcb,
const char *client,
const char *
server,
char *secret,
int *secret_len,
int am_server);
586 void demand_conf (
void);
587 void demand_block (
void);
588 void demand_unblock (
void);
589 void demand_discard (
void);
590 void demand_rexmit (
int,
u32_t);
591 int loop_chars (
unsigned char *,
int);
592 int loop_frame (
unsigned char *,
int);
596 #ifdef HAVE_MULTILINK
597 void mp_check_options (
void);
598 int mp_join_bundle (
void);
599 void mp_exit_bundle (
void);
600 void mp_bundle_terminated (
void);
601 char *epdisc_to_str (
struct epdisc *);
602 int str_to_epdisc (
struct epdisc *,
char *);
604 #define mp_bundle_terminated()
605 #define mp_exit_bundle()
606 #define doing_multilink 0
607 #define multilink_master 0
611 void ppp_print_string(
const u_char *p,
int len,
void (*printer) (
void *,
const char *, ...),
void *arg);
612 int ppp_slprintf(
char *buf,
int buflen,
const char *fmt, ...);
613 int ppp_vslprintf(
char *buf,
int buflen,
const char *fmt, va_list
args);
614 size_t ppp_strlcpy(
char *dest,
const char *src,
size_t len);
615 size_t ppp_strlcat(
char *dest,
const char *src,
size_t len);
616 void ppp_dbglog(
const char *fmt, ...);
617 void ppp_info(
const char *fmt, ...);
618 void ppp_notice(
const char *fmt, ...);
619 void ppp_warn(
const char *fmt, ...);
620 void ppp_error(
const char *fmt, ...);
621 void ppp_fatal(
const char *fmt, ...);
623 void ppp_dump_packet(ppp_pcb *pcb,
const char *tag,
unsigned char *p,
int len);