annotate packages/net/ppp/current/src/ppp_io.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents 9ea31f9f2254
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
2 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
3 // src/ppp_io.c
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
4 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
5 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
6 // ####BSDCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
7 // -------------------------------------------
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
8 // This file is part of eCos, the Embedded Configurable Operating System.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
9 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
10 // Portions of this software may have been derived from FreeBSD, OpenBSD,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
11 // or other sources, and if so are covered by the appropriate copyright
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
12 // and license included herein.
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
13 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
14 // Portions created by the Free Software Foundation are
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
15 // Copyright (C) 2003, 2004 Free Software Foundation, Inc.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
16 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2041
diff changeset
17 // ####BSDCOPYRIGHTEND####
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
18 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
19
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
20 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
21 * ppp_tty.c - Point-to-Point Protocol (PPP) driver for asynchronous
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
22 * tty devices.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
23 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
24 * Copyright (c) 1989 Carnegie Mellon University.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
25 * All rights reserved.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
26 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
27 * Redistribution and use in source and binary forms are permitted
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
28 * provided that the above copyright notice and this paragraph are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
29 * duplicated in all such forms and that any documentation,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
30 * advertising materials, and other materials related to such
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
31 * distribution and use acknowledge that the software was developed
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
32 * by Carnegie Mellon University. The name of the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
33 * University may not be used to endorse or promote products derived
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
34 * from this software without specific prior written permission.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
36 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
37 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
38 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
39 * Drew D. Perkins
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
40 * Carnegie Mellon University
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
41 * 4910 Forbes Ave.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
42 * Pittsburgh, PA 15213
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
43 * (412) 268-8576
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
44 * ddp@andrew.cmu.edu
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
45 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
46 * Based on:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
47 * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
48 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
49 * Copyright (c) 1987 Regents of the University of California.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
50 * All rights reserved.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
51 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
52 * Redistribution and use in source and binary forms are permitted
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
53 * provided that the above copyright notice and this paragraph are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
54 * duplicated in all such forms and that any documentation,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
55 * and other materials related to such
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
56 * distribution and use acknowledge that the software was developed
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
57 * by the University of California, Berkeley. The name of the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
58 * University may not be used to endorse or promote products derived
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
59 * from this software without specific prior written permission.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
60 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
61 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
62 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
63 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
64 * Serial Line interface
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
65 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
66 * Rick Adams
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
67 * Center for Seismic Studies
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
68 * 1300 N 17th Street, Suite 1450
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
69 * Arlington, Virginia 22209
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
70 * (703)276-7900
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
71 * rick@seismo.ARPA
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
72 * seismo!rick
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
73 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
74 * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
75 * Converted to 4.3BSD Beta by Chris Torek.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
76 * Other changes made at Berkeley, based in part on code by Kirk Smith.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
77 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
78 * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
79 * Added VJ tcp header compression; more unified ioctls
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
80 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
81 * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
82 * Cleaned up a lot of the mbuf-related code to fix bugs that
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
83 * caused system crashes and packet corruption. Changed pppstart
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
84 * so that it doesn't just give up with a "collision" if the whole
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
85 * packet doesn't fit in the output ring buffer.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
86 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
87 * Added priority queueing for interactive IP packets, following
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
88 * the model of if_sl.c, plus hooks for bpf.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
89 * Paul Mackerras (paulus@cs.anu.edu.au).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
90 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
91
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
92 /* $FreeBSD: src/sys/net/ppp_tty.c,v 1.43 2000/01/29 16:56:24 peter Exp $ */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
93
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
94 #include <pkgconf/system.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
95 #include <pkgconf/net.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
96 #include <pkgconf/ppp.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
97
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
98 #define _KERNEL
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
99
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
100 #define VJC /* XXX for ppp_defs.h */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
101
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
102 #include <sys/param.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
103 #define suser(x) 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
104 #include <sys/mbuf.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
105 #include <sys/socket.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
106 #include <sys/uio.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
107
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
108 #ifdef PPP_FILTER
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
109 #include <net/bpf.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
110 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
111 #include <cyg/ppp/net/if_ppp.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
112 #include <cyg/ppp/net/if_pppvar.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
113
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
114 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
115
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
116 #ifdef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
117
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
118 #include "cyg/ppp/ppp_io.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
119
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
120 //#define db_printf diag_printf
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
121 #define db_printf(fmt, ... )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
122
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
123 #define spltty(x) splsoftnet(x)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
124
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
125 #define ENOIOCTL ENOSYS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
126
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
127 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
128
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
129 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
130
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
131 static u_short pppfcs __P((u_short fcs, u_char *cp, int len));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
132 static void pppasyncstart __P((struct ppp_softc *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
133 static void pppasyncctlp __P((struct ppp_softc *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
134 static void pppasyncrelinq __P((struct ppp_softc *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
135 static void pppasyncsetmtu __P((struct ppp_softc *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
136 static void pppgetm __P((struct ppp_softc *sc));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
137 static void ppplogchar __P((struct ppp_softc *, int));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
138
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
139 /* XXX called from if_ppp.c - layering violation */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
140 void pppasyncattach __P((void *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
141
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
142 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
143 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
144 * Some useful mbuf macros not in mbuf.h.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
145 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
146 #define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
147
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
148 #define M_DATASTART(m) \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
149 (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
150 (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
151
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
152 #define M_DATASIZE(m) \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
153 (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
154 (m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
155
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
156 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
157 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
158 * Does c need to be escaped?
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
159 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
160 #define ESCAPE_P(c) (sc->sc_asyncmap[(c) >> 5] & (1 << ((c) & 0x1F)))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
161
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
162 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
163 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
164 * Procedures for using an async tty interface for PPP.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
165 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
166
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
167 /* This is a FreeBSD-2.X kernel. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
168 //#define CCOUNT(q) ((q)->c_cc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
169 //#define PPP_LOWAT 100 /* Process more output when < LOWAT on queue */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
170 //#define PPP_HIWAT 400 /* Don't start a new packet if HIWAT on que */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
171
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
172
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
173 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
174 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
175 * Line specific open routine for async tty devices.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
176 * Attach the given tty to the first available ppp unit.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
177 * Called from device open routine or ttioctl() at >= splsofttty()
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
178 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
179 /* ARGSUSED */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
180
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
181 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
182 cyg_ppp_pppopen(tp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
183 struct tty *tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
184 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
185 register struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
186 int error, s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
187
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
188 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
189 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
190
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
191 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
192
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
193 if ((sc = pppalloc(0)) == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
194 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
195 return ENXIO;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
196 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
197
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
198 if (sc->sc_relinq)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
199 (*sc->sc_relinq)(sc); /* get previous owner to relinquish the unit */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
200
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
201 sc->sc_ilen = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
202 sc->sc_m = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
203 bzero(sc->sc_asyncmap, sizeof(sc->sc_asyncmap));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
204 sc->sc_asyncmap[0] = 0xffffffff;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
205 sc->sc_asyncmap[3] = 0x60000000;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
206 sc->sc_rasyncmap = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
207 sc->sc_devp = (void *) tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
208 sc->sc_start = pppasyncstart;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
209 sc->sc_ctlp = pppasyncctlp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
210 sc->sc_relinq = pppasyncrelinq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
211 sc->sc_setmtu = pppasyncsetmtu;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
212 sc->sc_outm = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
213 pppgetm(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
214 sc->sc_if.if_flags |= IFF_RUNNING;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
215 getmicrotime(&sc->sc_if.if_lastchange);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
216 tp->t_sc = (caddr_t) sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
217
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
218 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
219
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
220 return (0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
221 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
222
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
223 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
224 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
225 * Line specific close routine, called from device close routine
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
226 * and from ttioctl at >= splsofttty().
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
227 * Detach the tty from the ppp unit.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
228 * Mimics part of ttyclose().
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
229 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
230
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
231 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
232 cyg_ppp_pppclose(tp, flag)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
233 struct tty *tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
234 int flag;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
235 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
236 register struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
237 int s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
238
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
239 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
240 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
241
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
242 sc = (struct ppp_softc *) tp->t_sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
243 if (sc != NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
244 tp->t_sc = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
245 if (tp == (struct tty *) sc->sc_devp) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
246 pppasyncrelinq(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
247 pppdealloc(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
248 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
249 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
250 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
251 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
252 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
253
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
254 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
255 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
256 * Relinquish the interface unit to another device.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
257 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
258
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
259 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
260 pppasyncrelinq(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
261 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
262 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
263 int s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
264
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
265 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
266 if (sc->sc_outm) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
267 m_freem(sc->sc_outm);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
268 sc->sc_outm = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
269 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
270 if (sc->sc_m) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
271 m_freem(sc->sc_m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
272 sc->sc_m = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
273 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
274 if (sc->sc_flags & SC_TIMEOUT) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
275 sc->sc_flags &= ~SC_TIMEOUT;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
276 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
277 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
278 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
279
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
280 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
281 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
282 * This gets called from the upper layer to notify a mtu change
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
283 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
284
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
285 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
286 pppasyncsetmtu(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
287 register struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
288 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
289 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
290 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
291
1629
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
292
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
293
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
294 //==========================================================================
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
295 /*
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
296 * function to check if data is available
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
297 */
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
298
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
299 int
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
300 cyg_ppp_pppcheck(tp)
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
301 register struct tty *tp;
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
302 {
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
303 register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc;
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
304 int status = 0;
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
305 register int s;
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
306
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
307 s = spltty();
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
308
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
309 if (tp != (struct tty *) sc->sc_devp ) {
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
310 splx(s);
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
311 return 0;
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
312 }
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
313 if (sc->sc_inq.ifq_head == NULL)
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
314 {
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
315 splx(s);
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
316 return 0;
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
317 }
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
318
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
319 // if the queue is not empty
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
320 if ( IF_IS_EMPTY(&sc->sc_inq) == false)
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
321 status = 1;
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
322
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
323 splx(s);
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
324
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
325 return(status);
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
326 }
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
327
2609240c9126 * src/ppp_io.c:
nickg
parents: 1586
diff changeset
328
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
329 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
330 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
331 * Line specific (tty) read routine.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
332 * called at zero spl from the device driver in the response to user-level
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
333 * reads on the tty file descriptor (ie: pppd).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
334 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
335
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
336 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
337 cyg_ppp_pppread(tp, uio, flag)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
338 register struct tty *tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
339 struct uio *uio;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
340 int flag;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
341 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
342 register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
343 struct mbuf *m, *m0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
344 register int s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
345 int error = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
346
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
347 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
348
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
349 if (sc == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
350 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
351
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
352 // Look for input. If there is none return EWOULDBLOCK, otherwise
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
353 // dequeue the next packet and return it.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
354
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
355 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
356
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
357 if (tp != (struct tty *) sc->sc_devp ) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
358 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
359 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
360 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
361 if (sc->sc_inq.ifq_head == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
362 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
363 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
364 return EWOULDBLOCK;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
365 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
366
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
367 /* Get the packet from the input queue */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
368 IF_DEQUEUE(&sc->sc_inq, m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
369 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
370
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
371
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
372 for (m = m0; m && uio->uio_resid; m = m->m_next)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
373 {
2041
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
374 if ((error = uiomove(mtod(m, caddr_t), m->m_len, uio)) != 0)
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
375 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
376 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
377 m_freem(m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
378
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
379 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
380 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
381
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
382 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
383 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
384 * Line specific (tty) write routine.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
385 * called at zero spl from the device driver in the response to user-level
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
386 * writes on the tty file descriptor (ie: pppd).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
387 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
388
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
389 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
390 cyg_ppp_pppwrite(tp, uio, flag)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
391 register struct tty *tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
392 struct uio *uio;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
393 int flag;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
394 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
395 register struct ppp_softc *sc = (struct ppp_softc *)tp->t_sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
396 struct mbuf *m, *m0, **mp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
397 struct sockaddr dst;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
398 int len, error, s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
399
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
400 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
401 for (mp = &m0; uio->uio_resid; mp = &m->m_next) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
402 MGET(m, M_WAIT, MT_DATA);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
403 if ((*mp = m) == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
404 m_freem(m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
405 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
406 return (ENOBUFS);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
407 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
408 m->m_len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
409 if (uio->uio_resid >= MCLBYTES / 2)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
410 MCLGET(m, M_DONTWAIT);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
411 len = M_TRAILINGSPACE(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
412 if (len > uio->uio_resid)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
413 len = uio->uio_resid;
2041
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
414 if ((error = uiomove(mtod(m, caddr_t), len, uio)) != 0) {
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
415 m_freem(m0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
416 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
417 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
418 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
419 m->m_len = len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
420 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
421 dst.sa_family = AF_UNSPEC;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
422 bcopy(mtod(m0, u_char *), dst.sa_data, PPP_HDRLEN);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
423 m0->m_data += PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
424 m0->m_len -= PPP_HDRLEN;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
425
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
426 /* call the upper layer to "transmit" it... */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
427 error = pppoutput(&sc->sc_if, m0, &dst, (struct rtentry *)0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
428 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
429 return (error);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
430 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
431
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
432 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
433 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
434 * Line specific (tty) ioctl routine.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
435 * This discipline requires that tty device drivers call
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
436 * the line specific l_ioctl routine from their ioctl routines.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
437 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
438 /* ARGSUSED */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
439 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
440 cyg_ppp_ppptioctl(tp, cmd, data, flag)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
441 struct tty *tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
442 u_long cmd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
443 caddr_t data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
444 int flag;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
445 // struct proc *p;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
446 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
447 struct ppp_softc *sc = (struct ppp_softc *) tp->t_sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
448 int error, s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
449
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
450 if (sc == NULL || tp != (struct tty *) sc->sc_devp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
451 return (ENOIOCTL);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
452
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
453 error = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
454 switch (cmd) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
455 case PPPIOCSASYNCMAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
456 sc->sc_asyncmap[0] = *(u_int *)data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
457 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
458
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
459 case PPPIOCGASYNCMAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
460 *(u_int *)data = sc->sc_asyncmap[0];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
461 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
462
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
463 case PPPIOCSRASYNCMAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
464 if ((error = suser(p)) != 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
465 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
466 sc->sc_rasyncmap = *(u_int *)data;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
467 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
468
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
469 case PPPIOCGRASYNCMAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
470 *(u_int *)data = sc->sc_rasyncmap;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
471 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
472
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
473 case PPPIOCSXASYNCMAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
474 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
475 bcopy(data, sc->sc_asyncmap, sizeof(sc->sc_asyncmap));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
476 sc->sc_asyncmap[1] = 0; /* mustn't escape 0x20 - 0x3f */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
477 sc->sc_asyncmap[2] &= ~0x40000000; /* mustn't escape 0x5e */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
478 sc->sc_asyncmap[3] |= 0x60000000; /* must escape 0x7d, 0x7e */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
479 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
480 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
481
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
482 case PPPIOCGXASYNCMAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
483 bcopy(sc->sc_asyncmap, data, sizeof(sc->sc_asyncmap));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
484 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
485
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
486 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
487 error = pppioctl(sc, cmd, data, flag, 0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
488 if (error == 0 && cmd == PPPIOCSMRU)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
489 pppgetm(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
490 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
491
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
492 return error;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
493 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
494
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
495 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
496 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
497 * FCS lookup table as calculated by genfcstab.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
498 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
499 static u_short fcstab[256] = {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
500 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
501 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
502 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
503 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
504 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
505 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
506 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
507 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
508 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
509 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
510 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
511 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
512 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
513 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
514 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
515 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
516 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
517 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
518 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
519 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
520 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
521 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
522 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
523 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
524 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
525 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
526 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
527 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
528 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
529 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
530 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
531 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
532 };
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
533
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
534 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
535 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
536 * Calculate a new FCS given the current FCS and the new data.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
537 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
538 static u_short
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
539 pppfcs(u_short fcs, u_char *cp, int len)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
540 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
541 while (len--)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
542 fcs = PPP_FCS(fcs, *cp++);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
543 return (fcs);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
544 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
545
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
546 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
547
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
548 #ifdef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
549
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
550 // Call pppasyncstart() to kick transmission into life.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
551 int cyg_ppp_pppstart( struct tty *tp )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
552 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
553 struct ppp_softc *sc = (struct ppp_softc *) tp->t_sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
554
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
555 while( sc->sc_outm != NULL )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
556 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
557 // We wait for the output buffer to drain of all characters
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
558 // before we call pppasyncstart(). That way we know there will
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
559 // be room for some data. We would really like to just drain
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
560 // down to some low water mark, but the drivers don't provide
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
561 // that functionality. However, since most devices have
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
562 // hardware FIFO's, we have a grace period to get more
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
563 // characters into the device, so hopefully there won't be a
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
564 // gap on the line.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
565
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
566 cyg_uint32 nb = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
567 cyg_uint32 len = sizeof(nb);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
568 int s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
569
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
570 cyg_io_get_config( tp->t_handle,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
571 CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
572 &nb, &len);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
573
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
574 s = splsoftnet();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
575
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
576 pppasyncstart( sc );
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
577
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
578 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
579 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
580
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
581 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
582 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
583
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
584 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
585
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
587 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
588 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
589 * This gets called at splsoftnet from if_ppp.c at various times
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
590 * when there is data ready to be sent.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
591 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
592 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
593 pppasyncstart(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
594 register struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
595 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
596 register struct tty *tp = (struct tty *) sc->sc_devp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
597 register struct mbuf *m;
2041
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
598 register unsigned int len;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
599 register u_char *start, *stop, *cp;
2041
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
600 int n, done, idle;
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
601 cyg_uint32 ndone;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
602 struct mbuf *m2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
603 int s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
604 idle = 0;
1868
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
605 #ifdef CYGPKT_PPP_WORKAROUNDS_START_FLAG
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
606 char start_flag = PPP_FLAG;
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
607 int start_flag_len = sizeof(start_flag);
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
608 #endif
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
609
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
610 while (1) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
611 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
612 * See if we have an existing packet partly sent.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
613 * If not, get a new packet and start sending it.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
614 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
615 m = sc->sc_outm;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
616 if (m == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
617 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
618 * Get another packet to be sent.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
619 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
620 m = ppp_dequeue(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
621 if (m == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
622 idle = 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
623 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
624 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
625
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
626 /* Calculate the FCS for the first mbuf's worth. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
627 sc->sc_outfcs = pppfcs(PPP_INITFCS, mtod(m, u_char *), m->m_len);
1868
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
628 getmicrotime(&sc->sc_if.if_lastchange);
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
629 #ifdef CYGPKT_PPP_WORKAROUNDS_START_FLAG
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
630 cyg_io_write(tp->t_handle, &start_flag, &start_flag_len);
3df9bc847a78 * cdl/ppp.cdl
asl
parents: 1629
diff changeset
631 #endif
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
632 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
633
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
634 for (;;) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
635 start = mtod(m, u_char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
636 len = m->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
637 stop = start + len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
638 while (len > 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
639 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
640 * Find out how many bytes in the string we can
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
641 * handle without doing something special.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
642 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
643 for (cp = start; cp < stop; cp++)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
644 if (ESCAPE_P(*cp))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
645 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
646 n = cp - start;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
647 if (n) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
648 #ifndef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
649 /* NetBSD (0.9 or later), 4.3-Reno or similar. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
650 ndone = n - b_to_q(start, n, &tp->t_outq);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
651 #else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
652 ndone = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
653 // db_printf("send: data %d\n",ndone);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
654 // db_dump_buf(start,ndone);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
655 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
656 cyg_serial_buf_info_t info;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
657 cyg_uint32 ilen = sizeof(info);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
658 if( cyg_io_get_config( tp->t_handle, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO, &info, &ilen ) == 0 )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
659 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
660 ndone = info.tx_bufsize-info.tx_count;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
661 if( ndone > n )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
662 ndone = n;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
663 cyg_io_write( tp->t_handle, start, &ndone);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
664 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
665 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
666 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
667 len -= ndone;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
668 start += ndone;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
669 sc->sc_stats.ppp_obytes += ndone;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
670
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
671 if (ndone < n)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
672 break; /* packet doesn't fit */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
673 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
674 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
675 * If there are characters left in the mbuf,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
676 * the first one must be special.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
677 * Put it out in a different form.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
678 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
679 if (len) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
680 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
681 #ifndef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
682 if (putc(PPP_ESCAPE, &tp->t_outq)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
683 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
684 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
685 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
686 if (putc(*start ^ PPP_TRANS, &tp->t_outq)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
687 (void) unputc(&tp->t_outq);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
688 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
689 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
690 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
691 #else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
692 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
693 cyg_serial_buf_info_t info;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
694 cyg_uint32 ilen = sizeof(info);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
695 if( cyg_io_get_config( tp->t_handle, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO, &info, &ilen ) == 0 &&
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
696 info.tx_bufsize-info.tx_count >= 2 )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
697 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
698 char buf[2];
2041
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
699 cyg_uint32 blen = 2;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
700 buf[0] = PPP_ESCAPE;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
701 buf[1] = *start ^ PPP_TRANS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
702 if( cyg_io_write( tp->t_handle, buf, &blen) != 0 ) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
703 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
704 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
705 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
706 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
707 else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
708 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
709 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
710 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
711 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
712 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
713 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
714 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
715 sc->sc_stats.ppp_obytes += 2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
716 start++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
717 len--;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
718 } // if( len )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
719 } // while (len > 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
720
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
721 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
722 * If we didn't empty this mbuf, remember where we're up to.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
723 * If we emptied the last mbuf, try to add the FCS and closing
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
724 * flag, and if we can't, leave sc_outm pointing to m, but with
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
725 * m->m_len == 0, to remind us to output the FCS and flag later.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
726 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
727 done = len == 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
728 if (done && m->m_next == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
729 u_char *p, *q;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
730 int c;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
731 u_char endseq[8];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
732
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
733 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
734 * We may have to escape the bytes in the FCS.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
735 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
736 p = endseq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
737 c = ~sc->sc_outfcs & 0xFF;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
738 if (ESCAPE_P(c)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
739 *p++ = PPP_ESCAPE;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
740 *p++ = c ^ PPP_TRANS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
741 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
742 *p++ = c;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
743 c = (~sc->sc_outfcs >> 8) & 0xFF;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
744 if (ESCAPE_P(c)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
745 *p++ = PPP_ESCAPE;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
746 *p++ = c ^ PPP_TRANS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
747 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
748 *p++ = c;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
749 *p++ = PPP_FLAG;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
750
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
751 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
752 * Try to output the FCS and flag. If the bytes
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
753 * don't all fit, back out.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
754 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
755 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
756 #ifndef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
757 for (q = endseq; q < p; ++q)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
758 if (putc(*q, &tp->t_outq)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
759 done = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
760 for (; q > endseq; --q)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
761 unputc(&tp->t_outq);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
762 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
763 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
764 #else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
765 {
2041
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
766 cyg_uint32 elen = p-endseq;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
767 cyg_serial_buf_info_t info;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
768 cyg_uint32 ilen = sizeof(info);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
769 q = p;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
770 if( (cyg_io_get_config( tp->t_handle, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO, &info, &ilen ) == 0) &&
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
771 ((info.tx_bufsize-info.tx_count) >= elen) )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
772 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
773 if( cyg_io_write( tp->t_handle, endseq, &elen) != 0 ) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
774 done = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
775 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
776 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
777 else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
778 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
779 done = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
780 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
781 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
782 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
783 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
784 if (done)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
785 sc->sc_stats.ppp_obytes += q - endseq;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
786 } // if (done && m->m_next == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
787
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
788 if (!done) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
789 /* remember where we got to */
2041
9ea31f9f2254 * src/ppp_io.c (cyg_ppp_pppread): caddrt_t to stop compiler warnings.
asl
parents: 1923
diff changeset
790 m->m_data = (char *)start;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
791 m->m_len = len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
792 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
793 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
794
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
795 /* Finished with this mbuf; free it and move on. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
796 MFREE(m, m2);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
797 m = m2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
798 if (m == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
799 /* Finished a packet */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
800 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
801 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
802 sc->sc_outfcs = pppfcs(sc->sc_outfcs, mtod(m, u_char *), m->m_len);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
803 } // for(;;)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
804
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
805 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
806 * If m == NULL, we have finished a packet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
807 * If m != NULL, we've either done as much work this time
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
808 * as we need to, or else we've filled up the output queue.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
809 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
810 sc->sc_outm = m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
811 if (m)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
812 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
813 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
814
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
815 #ifndef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
816 /* Call pppstart to start output again if necessary. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
817 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
818 pppstart(tp);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
819
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
820 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
821 * This timeout is needed for operation on a pseudo-tty,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
822 * because the pty code doesn't call pppstart after it has
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
823 * drained the t_outq.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
824 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
825 if (!idle && (sc->sc_flags & SC_TIMEOUT) == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
826 sc->sc_ch = timeout(ppp_timeout, (void *) sc, 1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
827 sc->sc_flags |= SC_TIMEOUT;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
828 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
829
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
830 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
831
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
832 #else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
833
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
834 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
835
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
836 if( sc->sc_outm != NULL &&
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
837 cyg_thread_self() != tp->tx_thread )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
838 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
839 cyg_semaphore_post( &tp->tx_sem );
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
840 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
841
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
842 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
843
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
844 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
845
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
846 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
847
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
848 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
849 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
850 * This gets called when a received packet is placed on
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
851 * the inq, at splsoftnet. The pppd daemon is to be woken up to do a read().
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
852 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
853 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
854 pppasyncctlp(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
855 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
856 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
857 struct tty *tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
858 int s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
859
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
860 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
861 tp = (struct tty *) sc->sc_devp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
862
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
863 tp->pppd_wakeup = 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
864 if( tp->pppd_thread != cyg_thread_self() )
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
865 cyg_thread_release( tp->pppd_thread );
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
866
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
867 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
868 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
869
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
870 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
871 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
872 * Allocate enough mbuf to handle current MRU.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
873 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
874 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
875 pppgetm(sc)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
876 register struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
877 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
878 struct mbuf *m, **mp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
879 int len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
880
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
881 mp = &sc->sc_m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
882 for (len = sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN; len > 0; ){
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
883 if ((m = *mp) == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
884 MGETHDR(m, M_DONTWAIT, MT_DATA);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
885 if (m == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
886 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
887 *mp = m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
888 MCLGET(m, M_DONTWAIT);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
889 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
890 len -= M_DATASIZE(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
891 mp = &m->m_next;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
892 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
893 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
894
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
895 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
896 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
897 * tty interface receiver interrupt.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
898 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
899
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
900 static unsigned paritytab[8] = {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
901 0x96696996, 0x69969669, 0x69969669, 0x96696996,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
902 0x69969669, 0x96696996, 0x96696996, 0x69969669
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
903 };
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
904
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
905 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
906 * Called when character is available from device driver.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
907 * Only guaranteed to be at splsofttty() or spltty()
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
908 * This is safe to be called while the upper half's netisr is preempted.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
909 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
910 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
911 cyg_ppp_pppinput(c, tp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
912 int c;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
913 register struct tty *tp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
914 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
915 register struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
916 struct mbuf *m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
917 int ilen, s;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
918
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
919 sc = (struct ppp_softc *) tp->t_sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
920 if (sc == NULL || tp != (struct tty *) sc->sc_devp)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
921 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
922
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
923 // ++tk_nin;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
924 ++sc->sc_stats.ppp_ibytes;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
925
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
926 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
927 if (c & 0x80)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
928 sc->sc_flags |= SC_RCV_B7_1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
929 else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
930 sc->sc_flags |= SC_RCV_B7_0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
931 if (paritytab[c >> 5] & (1 << (c & 0x1F)))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
932 sc->sc_flags |= SC_RCV_ODDP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
933 else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
934 sc->sc_flags |= SC_RCV_EVNP;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
935 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
936
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
937 if (sc->sc_flags & SC_LOG_RAWIN)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
938 ppplogchar(sc, c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
939
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
940 if (c == PPP_FLAG) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
941 ilen = sc->sc_ilen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
942 sc->sc_ilen = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
943 if (sc->sc_rawin_count > 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
944 ppplogchar(sc, -1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
945
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
946 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
947 * If SC_ESCAPED is set, then we've seen the packet
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
948 * abort sequence "}~".
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
949 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
950 if (sc->sc_flags & (SC_FLUSH | SC_ESCAPED)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
951 || (ilen > 0 && sc->sc_fcs != PPP_GOODFCS)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
952 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
953 sc->sc_flags |= SC_PKTLOST; /* note the dropped packet */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
954 if ((sc->sc_flags & (SC_FLUSH | SC_ESCAPED)) == 0){
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
955 #if 1
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
956 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
957 diag_printf("ppp%d: bad fcs %x, pkt len %d\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
958 sc->sc_if.if_unit, sc->sc_fcs, ilen);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
959 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
960 sc->sc_if.if_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
961 sc->sc_stats.ppp_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
962 } else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
963 sc->sc_flags &= ~(SC_FLUSH | SC_ESCAPED);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
964 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
965 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
966 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
967
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
968 if (ilen < PPP_HDRLEN + PPP_FCSLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
969 if (ilen) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
970 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
971 diag_printf("ppp%d: too short (%d)\n", sc->sc_if.if_unit, ilen);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
972 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
973 sc->sc_if.if_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
974 sc->sc_stats.ppp_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
975 sc->sc_flags |= SC_PKTLOST;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
976 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
977 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
978 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
979 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
980
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
981 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
982 * Remove FCS trailer. Somewhat painful...
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
983 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
984 ilen -= 2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
985 if (--sc->sc_mc->m_len == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
986 for (m = sc->sc_m; m->m_next != sc->sc_mc; m = m->m_next)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
987 ;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
988 sc->sc_mc = m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
989 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
990 sc->sc_mc->m_len--;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
991
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
992 /* excise this mbuf chain */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
993 m = sc->sc_m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
994 sc->sc_m = sc->sc_mc->m_next;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
995 sc->sc_mc->m_next = NULL;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
996
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
997 ppppktin(sc, m, sc->sc_flags & SC_PKTLOST);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
998 if (sc->sc_flags & SC_PKTLOST) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
999 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1000 sc->sc_flags &= ~SC_PKTLOST;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1001 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1002 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1003
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1004 pppgetm(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1005 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1006 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1007
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1008 if (sc->sc_flags & SC_FLUSH) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1009 if (sc->sc_flags & SC_LOG_FLUSH)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1010 ppplogchar(sc, c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1011 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1012 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1013
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1014 if (c < 0x20 && (sc->sc_rasyncmap & (1 << c)))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1015 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1016
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1017 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1018 if (sc->sc_flags & SC_ESCAPED) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1019 sc->sc_flags &= ~SC_ESCAPED;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1020 c ^= PPP_TRANS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1021 } else if (c == PPP_ESCAPE) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1022 sc->sc_flags |= SC_ESCAPED;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1023 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1024 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1025 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1026 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1027
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1028 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1029 * Initialize buffer on first octet received.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1030 * First octet could be address or protocol (when compressing
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1031 * address/control).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1032 * Second octet is control.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1033 * Third octet is first or second (when compressing protocol)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1034 * octet of protocol.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1035 * Fourth octet is second octet of protocol.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1036 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1037 if (sc->sc_ilen == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1038 /* reset the first input mbuf */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1039 if (sc->sc_m == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1040 pppgetm(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1041 if (sc->sc_m == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1042 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1043 diag_printf("ppp%d: no input mbufs!\n", sc->sc_if.if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1044 goto flush;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1045 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1046 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1047 m = sc->sc_m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1048 m->m_len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1049 m->m_data = M_DATASTART(sc->sc_m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1050 sc->sc_mc = m;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1051 sc->sc_mp = mtod(m, char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1052 sc->sc_fcs = PPP_INITFCS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1053 if (c != PPP_ALLSTATIONS) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1054 if (sc->sc_flags & SC_REJ_COMP_AC) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1055 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1056 diag_printf("ppp%d: garbage received: 0x%x (need 0xFF)\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1057 sc->sc_if.if_unit, c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1058 goto flush;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1059 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1060 *sc->sc_mp++ = PPP_ALLSTATIONS;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1061 *sc->sc_mp++ = PPP_UI;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1062 sc->sc_ilen += 2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1063 m->m_len += 2;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1064 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1065 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1066 if (sc->sc_ilen == 1 && c != PPP_UI) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1067 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1068 diag_printf("ppp%d: missing UI (0x3), got 0x%x\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1069 sc->sc_if.if_unit, c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1070 goto flush;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1071 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1072 if (sc->sc_ilen == 2 && (c & 1) == 1) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1073 /* a compressed protocol */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1074 *sc->sc_mp++ = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1075 sc->sc_ilen++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1076 sc->sc_mc->m_len++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1077 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1078 if (sc->sc_ilen == 3 && (c & 1) == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1079 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1080 diag_printf("ppp%d: bad protocol %x\n", sc->sc_if.if_unit,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1081 (sc->sc_mp[-1] << 8) + c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1082 goto flush;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1083 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1084
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1085 /* packet beyond configured mru? */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1086 if (++sc->sc_ilen > sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1087 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1088 diag_printf("ppp%d: packet too big\n", sc->sc_if.if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1089 goto flush;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1090 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1091
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1092 /* is this mbuf full? */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1093 m = sc->sc_mc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1094 if (M_TRAILINGSPACE(m) <= 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1095 if (m->m_next == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1096 pppgetm(sc);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1097 if (m->m_next == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1098 if (sc->sc_flags & SC_DEBUG)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1099 diag_printf("ppp%d: too few input mbufs!\n", sc->sc_if.if_unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1100 goto flush;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1101 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1102 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1103 sc->sc_mc = m = m->m_next;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1104 m->m_len = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1105 m->m_data = M_DATASTART(m);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1106 sc->sc_mp = mtod(m, char *);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1107 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1108
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1109 ++m->m_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1110 *sc->sc_mp++ = c;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1111 sc->sc_fcs = PPP_FCS(sc->sc_fcs, c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1112
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1113 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1114
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1115 flush:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1116 if (!(sc->sc_flags & SC_FLUSH)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1117 s = spltty();
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1118 sc->sc_if.if_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1119 sc->sc_stats.ppp_ierrors++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1120 sc->sc_flags |= SC_FLUSH;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1121 splx(s);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1122 if (sc->sc_flags & SC_LOG_FLUSH)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1123 ppplogchar(sc, c);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1124 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1125 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1126 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1127
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1128 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1129
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1130 #define MAX_DUMP_BYTES 128
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1131
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1132 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1133 ppplogchar(sc, c)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1134 struct ppp_softc *sc;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1135 int c;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1136 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1137 if (c >= 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1138 sc->sc_rawin[sc->sc_rawin_count++] = c;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1139 if (sc->sc_rawin_count >= sizeof(sc->sc_rawin)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1140 || (c < 0 && sc->sc_rawin_count > 0)) {
1923
84f7fdb14fae * tests/ppp_up.c: Change the prototype of pr_func to match
asl
parents: 1868
diff changeset
1141 diag_printf("ppp%d input:\n",sc->sc_if.if_unit);
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1142 diag_vdump_buf_with_offset( diag_printf, sc->sc_rawin, sc->sc_rawin_count, sc->sc_rawin );
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1143 sc->sc_rawin_count = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1144 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1145 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1146
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1147 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1148 // End of ppp_io.c
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1149