Commit | Line | Data |
---|---|---|
15637ed4 RG |
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 | * | |
1cdffd64 | 38 | * from: @(#)pk_output.c 7.10 (Berkeley) 5/29/91 |
fde1aeb2 | 39 | * $Id: pk_output.c,v 1.3 1993/11/25 01:34:30 wollman Exp $ |
15637ed4 RG |
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 }; | |
fde1aeb2 | 57 | static struct mbuf *nextpk (struct pklcd *); |
15637ed4 | 58 | |
fde1aeb2 GW |
59 | /* |
60 | * The `n' argument is just there to make if_x25subr.c happy. We | |
61 | * don't actually do anything with it, although meybe we should. | |
62 | * All the other code passes in a null pointer. | |
63 | */ | |
64 | int | |
65 | pk_output (lcp, n) | |
4c45483e | 66 | register struct pklcd *lcp; |
fde1aeb2 | 67 | struct mbuf *n; |
15637ed4 RG |
68 | { |
69 | register struct x25_packet *xp; | |
70 | register struct mbuf *m; | |
71 | register struct pkcb *pkp = lcp -> lcd_pkp; | |
72 | ||
73 | if (lcp == 0 || pkp == 0) { | |
74 | printf ("pk_output: zero arg\n"); | |
fde1aeb2 | 75 | return -1; |
15637ed4 RG |
76 | } |
77 | ||
78 | while ((m = nextpk (lcp)) != NULL) { | |
79 | xp = mtod (m, struct x25_packet *); | |
80 | ||
81 | switch (pk_decode (xp) + lcp -> lcd_state) { | |
82 | /* | |
83 | * All the work is already done - just set the state and | |
84 | * pass to peer. | |
85 | */ | |
86 | case CALL + READY: | |
87 | lcp -> lcd_state = SENT_CALL; | |
88 | lcp -> lcd_timer = pk_t21; | |
89 | break; | |
90 | ||
91 | /* | |
92 | * Just set the state to allow packet to flow and send the | |
93 | * confirmation. | |
94 | */ | |
95 | case CALL_ACCEPTED + RECEIVED_CALL: | |
96 | lcp -> lcd_state = DATA_TRANSFER; | |
97 | break; | |
98 | ||
99 | /* | |
100 | * Just set the state. Keep the LCD around till the clear | |
101 | * confirmation is returned. | |
102 | */ | |
103 | case CLEAR + RECEIVED_CALL: | |
104 | case CLEAR + SENT_CALL: | |
105 | case CLEAR + DATA_TRANSFER: | |
106 | lcp -> lcd_state = SENT_CLEAR; | |
107 | lcp -> lcd_retry = 0; | |
108 | /* fall through */ | |
109 | ||
110 | case CLEAR + SENT_CLEAR: | |
111 | lcp -> lcd_timer = pk_t23; | |
112 | lcp -> lcd_retry++; | |
113 | break; | |
114 | ||
115 | case CLEAR_CONF + RECEIVED_CLEAR: | |
116 | case CLEAR_CONF + SENT_CLEAR: | |
117 | case CLEAR_CONF + READY: | |
118 | lcp -> lcd_state = READY; | |
119 | break; | |
120 | ||
121 | case DATA + DATA_TRANSFER: | |
122 | PS(xp) = lcp -> lcd_ssn; | |
123 | lcp -> lcd_input_window = | |
124 | (lcp -> lcd_rsn + 1) % MODULUS; | |
125 | PR(xp) = lcp -> lcd_input_window; | |
126 | lcp -> lcd_last_transmitted_pr = lcp -> lcd_input_window; | |
127 | lcp -> lcd_ssn = (lcp -> lcd_ssn + 1) % MODULUS; | |
128 | if (lcp -> lcd_ssn == ((lcp -> lcd_output_window + lcp -> lcd_windowsize) % MODULUS)) | |
129 | lcp -> lcd_window_condition = TRUE; | |
130 | break; | |
131 | ||
132 | case INTERRUPT + DATA_TRANSFER: | |
133 | #ifdef ancient_history | |
134 | xp -> packet_data = 0; | |
135 | #endif | |
136 | lcp -> lcd_intrconf_pending = TRUE; | |
137 | break; | |
138 | ||
139 | case INTERRUPT_CONF + DATA_TRANSFER: | |
140 | break; | |
141 | ||
142 | case RR + DATA_TRANSFER: | |
143 | case RNR + DATA_TRANSFER: | |
144 | lcp -> lcd_input_window = | |
145 | (lcp -> lcd_rsn + 1) % MODULUS; | |
146 | PR(xp) = lcp -> lcd_input_window; | |
147 | lcp -> lcd_last_transmitted_pr = lcp -> lcd_input_window; | |
148 | break; | |
149 | ||
150 | case RESET + DATA_TRANSFER: | |
151 | lcp -> lcd_reset_condition = TRUE; | |
152 | break; | |
153 | ||
154 | case RESET_CONF + DATA_TRANSFER: | |
155 | lcp -> lcd_reset_condition = FALSE; | |
156 | break; | |
157 | ||
158 | /* | |
159 | * A restart should be only generated internally. Therefore | |
160 | * all logic for restart is in the pk_restart routine. | |
161 | */ | |
162 | case RESTART + READY: | |
163 | lcp -> lcd_timer = pk_t20; | |
164 | break; | |
165 | ||
166 | /* | |
167 | * Restarts are all handled internally. Therefore all the | |
168 | * logic for the incoming restart packet is handled in the | |
169 | * pk_input routine. | |
170 | */ | |
171 | case RESTART_CONF + READY: | |
172 | break; | |
173 | ||
174 | default: | |
175 | m_freem (m); | |
fde1aeb2 | 176 | return 0; |
15637ed4 RG |
177 | } |
178 | ||
179 | /* Trace the packet. */ | |
180 | pk_trace (pkp -> pk_xcp, m, "P-Out"); | |
181 | ||
182 | /* Pass the packet on down to the link layer */ | |
183 | if (pk_output_cache.mbc_size || pk_output_cache.mbc_oldsize) | |
184 | mbuf_cache(&pk_output_cache, m); | |
185 | (*pkp -> pk_lloutput) (pkp -> pk_llnext, m); | |
186 | } | |
fde1aeb2 | 187 | return 0; |
15637ed4 RG |
188 | } |
189 | ||
190 | /* | |
191 | * This procedure returns the next packet to send or null. A | |
192 | * packet is composed of one or more mbufs. | |
193 | */ | |
194 | ||
fde1aeb2 | 195 | static struct mbuf * |
15637ed4 | 196 | nextpk (lcp) |
fde1aeb2 | 197 | struct pklcd *lcp; |
15637ed4 RG |
198 | { |
199 | register struct mbuf *m, *n; | |
200 | struct socket *so = lcp -> lcd_so; | |
201 | register struct sockbuf *sb = & (so ? so -> so_snd : lcp -> lcd_sb); | |
202 | ||
203 | if (lcp -> lcd_template) { | |
204 | m = lcp -> lcd_template; | |
205 | lcp -> lcd_template = NULL; | |
206 | } else { | |
207 | if (lcp -> lcd_rnr_condition || lcp -> lcd_window_condition || | |
208 | lcp -> lcd_reset_condition) | |
209 | return (NULL); | |
210 | ||
211 | if ((m = sb -> sb_mb) == 0) | |
212 | return (NULL); | |
213 | ||
214 | sb -> sb_mb = m -> m_nextpkt; | |
215 | m->m_act = 0; | |
216 | for (n = m; n; n = n -> m_next) | |
217 | sbfree (sb, n); | |
218 | } | |
219 | return (m); | |
220 | } |