|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) University of British Columbia, 1984
27: * Copyright (C) Computer Science Department IV,
28: * University of Erlangen-Nuremberg, Germany, 1992
29: * Copyright (c) 1991, 1992, 1993
30: * The Regents of the University of California. All rights reserved.
31: *
32: * This code is derived from software contributed to Berkeley by the
33: * Laboratory for Computation Vision and the Computer Science Department
34: * of the the University of British Columbia and the Computer Science
35: * Department (IV) of the University of Erlangen-Nuremberg, Germany.
36: *
37: * Redistribution and use in source and binary forms, with or without
38: * modification, are permitted provided that the following conditions
39: * are met:
40: * 1. Redistributions of source code must retain the above copyright
41: * notice, this list of conditions and the following disclaimer.
42: * 2. Redistributions in binary form must reproduce the above copyright
43: * notice, this list of conditions and the following disclaimer in the
44: * documentation and/or other materials provided with the distribution.
45: * 3. All advertising materials mentioning features or use of this software
46: * must display the following acknowledgement:
47: * This product includes software developed by the University of
48: * California, Berkeley and its contributors.
49: * 4. Neither the name of the University nor the names of its contributors
50: * may be used to endorse or promote products derived from this software
51: * without specific prior written permission.
52: *
53: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63: * SUCH DAMAGE.
64: *
65: * @(#)pk_output.c 8.1 (Berkeley) 6/10/93
66: */
67:
68: #include <sys/param.h>
69: #include <sys/systm.h>
70: #include <sys/mbuf.h>
71: #include <sys/socket.h>
72: #include <sys/socketvar.h>
73: #include <sys/protosw.h>
74: #include <sys/errno.h>
75:
76: #include <net/if.h>
77:
78: #include <netccitt/x25.h>
79: #include <netccitt/pk.h>
80: #include <netccitt/pk_var.h>
81:
82: struct mbuf_cache pk_output_cache = {0 }, pk_input_cache;
83: struct mbuf *nextpk ();
84:
85: pk_output (lcp)
86: register struct pklcd *lcp;
87: {
88: register struct x25_packet *xp;
89: register struct mbuf *m;
90: register struct pkcb *pkp = lcp -> lcd_pkp;
91:
92: if (lcp == 0 || pkp == 0) {
93: printf ("pk_output: zero arg\n");
94: return;
95: }
96:
97: while ((m = nextpk (lcp)) != NULL) {
98: xp = mtod (m, struct x25_packet *);
99:
100: switch (pk_decode (xp) + lcp -> lcd_state) {
101: /*
102: * All the work is already done - just set the state and
103: * pass to peer.
104: */
105: case CALL + READY:
106: lcp -> lcd_state = SENT_CALL;
107: lcp -> lcd_timer = pk_t21;
108: break;
109:
110: /*
111: * Just set the state to allow packet to flow and send the
112: * confirmation.
113: */
114: case CALL_ACCEPTED + RECEIVED_CALL:
115: lcp -> lcd_state = DATA_TRANSFER;
116: break;
117:
118: /*
119: * Just set the state. Keep the LCD around till the clear
120: * confirmation is returned.
121: */
122: case CLEAR + RECEIVED_CALL:
123: case CLEAR + SENT_CALL:
124: case CLEAR + DATA_TRANSFER:
125: lcp -> lcd_state = SENT_CLEAR;
126: lcp -> lcd_retry = 0;
127: /* fall through */
128:
129: case CLEAR + SENT_CLEAR:
130: lcp -> lcd_timer = pk_t23;
131: lcp -> lcd_retry++;
132: break;
133:
134: case CLEAR_CONF + RECEIVED_CLEAR:
135: case CLEAR_CONF + SENT_CLEAR:
136: case CLEAR_CONF + READY:
137: lcp -> lcd_state = READY;
138: break;
139:
140: case DATA + DATA_TRANSFER:
141: SPS(xp, lcp -> lcd_ssn);
142: lcp -> lcd_input_window =
143: (lcp -> lcd_rsn + 1) % MODULUS;
144: SPR(xp, lcp -> lcd_input_window);
145: lcp -> lcd_last_transmitted_pr = lcp -> lcd_input_window;
146: lcp -> lcd_ssn = (lcp -> lcd_ssn + 1) % MODULUS;
147: if (lcp -> lcd_ssn == ((lcp -> lcd_output_window + lcp -> lcd_windowsize) % MODULUS))
148: lcp -> lcd_window_condition = TRUE;
149: break;
150:
151: case INTERRUPT + DATA_TRANSFER:
152: #ifdef ancient_history
153: xp -> packet_data = 0;
154: #endif
155: lcp -> lcd_intrconf_pending = TRUE;
156: break;
157:
158: case INTERRUPT_CONF + DATA_TRANSFER:
159: break;
160:
161: case RR + DATA_TRANSFER:
162: case RNR + DATA_TRANSFER:
163: lcp -> lcd_input_window =
164: (lcp -> lcd_rsn + 1) % MODULUS;
165: SPR(xp, lcp -> lcd_input_window);
166: lcp -> lcd_last_transmitted_pr = lcp -> lcd_input_window;
167: break;
168:
169: case RESET + DATA_TRANSFER:
170: lcp -> lcd_reset_condition = TRUE;
171: break;
172:
173: case RESET_CONF + DATA_TRANSFER:
174: lcp -> lcd_reset_condition = FALSE;
175: break;
176:
177: /*
178: * A restart should be only generated internally. Therefore
179: * all logic for restart is in the pk_restart routine.
180: */
181: case RESTART + READY:
182: lcp -> lcd_timer = pk_t20;
183: break;
184:
185: /*
186: * Restarts are all handled internally. Therefore all the
187: * logic for the incoming restart packet is handled in the
188: * pk_input routine.
189: */
190: case RESTART_CONF + READY:
191: break;
192:
193: default:
194: m_freem (m);
195: return;
196: }
197:
198: /* Trace the packet. */
199: pk_trace (pkp -> pk_xcp, m, "P-Out");
200:
201: /* Pass the packet on down to the link layer */
202: if (pk_input_cache.mbc_size || pk_input_cache.mbc_oldsize) {
203: m->m_flags |= 0x08;
204: mbuf_cache(&pk_input_cache, m);
205: }
206: (*pkp -> pk_lloutput) (pkp -> pk_llnext, m, pkp -> pk_rt);
207: }
208: }
209:
210: /*
211: * This procedure returns the next packet to send or null. A
212: * packet is composed of one or more mbufs.
213: */
214:
215: struct mbuf *
216: nextpk (lcp)
217: struct pklcd *lcp;
218: {
219: register struct mbuf *m, *n;
220: struct socket *so = lcp -> lcd_so;
221: register struct sockbuf *sb = & (so ? so -> so_snd : lcp -> lcd_sb);
222:
223: if (lcp -> lcd_template) {
224: m = lcp -> lcd_template;
225: lcp -> lcd_template = NULL;
226: } else {
227: if (lcp -> lcd_rnr_condition || lcp -> lcd_window_condition ||
228: lcp -> lcd_reset_condition)
229: return (NULL);
230:
231: if ((m = sb -> sb_mb) == 0)
232: return (NULL);
233:
234: sb -> sb_mb = m -> m_nextpkt;
235: m->m_act = 0;
236: for (n = m; n; n = n -> m_next)
237: sbfree (sb, n);
238: }
239: return (m);
240: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.