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