• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file
3  * Network Point to Point Protocol over Serial header file.
4  *
5  */
6 
7 /*
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the lwIP TCP/IP stack.
31  *
32  */
33 
34 #include "netif/ppp/ppp_opts.h"
35 #if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in lwipopts.h */
36 
37 #ifndef PPPOS_H
38 #define PPPOS_H
39 
40 #include "lwip/sys.h"
41 
42 #include "ppp.h"
43 #include "vj.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /* PPP packet parser states.  Current state indicates operation yet to be
50  * completed. */
51 enum {
52   PDIDLE = 0,  /* Idle state - waiting. */
53   PDSTART,     /* Process start flag. */
54   PDADDRESS,   /* Process address field. */
55   PDCONTROL,   /* Process control field. */
56   PDPROTOCOL1, /* Process protocol field 1. */
57   PDPROTOCOL2, /* Process protocol field 2. */
58   PDDATA       /* Process data byte. */
59 };
60 
61 /* PPPoS serial output callback function prototype */
62 typedef u32_t (*pppos_output_cb_fn)(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx);
63 
64 /*
65  * Extended asyncmap - allows any character to be escaped.
66  */
67 typedef u8_t ext_accm[32];
68 
69 /*
70  * PPPoS interface control block.
71  */
72 typedef struct pppos_pcb_s pppos_pcb;
73 struct pppos_pcb_s {
74   /* -- below are data that will NOT be cleared between two sessions */
75   ppp_pcb *ppp;                    /* PPP PCB */
76   pppos_output_cb_fn output_cb;    /* PPP serial output callback */
77 
78   /* -- below are data that will be cleared between two sessions
79    *
80    * last_xmit must be the first member of cleared members, because it is
81    * used to know which part must not be cleared.
82    */
83   u32_t last_xmit;                 /* Time of last transmission. */
84   ext_accm out_accm;               /* Async-Ctl-Char-Map for output. */
85 
86   /* flags */
87   unsigned int open            :1; /* Set if PPPoS is open */
88   unsigned int pcomp           :1; /* Does peer accept protocol compression? */
89   unsigned int accomp          :1; /* Does peer accept addr/ctl compression? */
90 
91   /* PPPoS rx */
92   ext_accm in_accm;                /* Async-Ctl-Char-Map for input. */
93   struct pbuf *in_head, *in_tail;  /* The input packet. */
94   u16_t in_protocol;               /* The input protocol code. */
95   u16_t in_fcs;                    /* Input Frame Check Sequence value. */
96   u8_t in_state;                   /* The input process state. */
97   u8_t in_escaped;                 /* Escape next character. */
98 };
99 
100 /* Create a new PPPoS session. */
101 ppp_pcb *pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb,
102        ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
103 
104 #if !NO_SYS && !PPP_INPROC_IRQ_SAFE
105 /* Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. */
106 err_t pppos_input_tcpip(ppp_pcb *ppp, u8_t *s, int l);
107 #endif /* !NO_SYS && !PPP_INPROC_IRQ_SAFE */
108 
109 /* PPP over Serial: this is the input function to be called for received data. */
110 void pppos_input(ppp_pcb *ppp, u8_t* data, int len);
111 
112 
113 /*
114  * Functions called from lwIP
115  * DO NOT CALL FROM lwIP USER APPLICATION.
116  */
117 #if !NO_SYS && !PPP_INPROC_IRQ_SAFE
118 err_t pppos_input_sys(struct pbuf *p, struct netif *inp);
119 #endif /* !NO_SYS && !PPP_INPROC_IRQ_SAFE */
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif /* PPPOS_H */
126 #endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */
127