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