2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) University of British Columbia, 1984
24 * Copyright (C) Computer Science Department IV,
25 * University of Erlangen-Nuremberg, Germany, 1992
26 * Copyright (c) 1991, 1992, 1993
27 * The Regents of the University of California. All rights reserved.
29 * This code is derived from software contributed to Berkeley by the
30 * Laboratory for Computation Vision and the Computer Science Department
31 * of the the University of British Columbia and the Computer Science
32 * Department (IV) of the University of Erlangen-Nuremberg, Germany.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * @(#)pk_output.c 8.1 (Berkeley) 6/10/93
65 #include <sys/param.h>
66 #include <sys/systm.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
70 #include <sys/protosw.h>
71 #include <sys/errno.h>
75 #include <netccitt/x25.h>
76 #include <netccitt/pk.h>
77 #include <netccitt/pk_var.h>
79 struct mbuf_cache pk_output_cache
= {0 }, pk_input_cache
;
80 struct mbuf
*nextpk ();
83 register struct pklcd
*lcp
;
85 register struct x25_packet
*xp
;
86 register struct mbuf
*m
;
87 register struct pkcb
*pkp
= lcp
-> lcd_pkp
;
89 if (lcp
== 0 || pkp
== 0) {
90 printf ("pk_output: zero arg\n");
94 while ((m
= nextpk (lcp
)) != NULL
) {
95 xp
= mtod (m
, struct x25_packet
*);
97 switch (pk_decode (xp
) + lcp
-> lcd_state
) {
99 * All the work is already done - just set the state and
103 lcp
-> lcd_state
= SENT_CALL
;
104 lcp
-> lcd_timer
= pk_t21
;
108 * Just set the state to allow packet to flow and send the
111 case CALL_ACCEPTED
+ RECEIVED_CALL
:
112 lcp
-> lcd_state
= DATA_TRANSFER
;
116 * Just set the state. Keep the LCD around till the clear
117 * confirmation is returned.
119 case CLEAR
+ RECEIVED_CALL
:
120 case CLEAR
+ SENT_CALL
:
121 case CLEAR
+ DATA_TRANSFER
:
122 lcp
-> lcd_state
= SENT_CLEAR
;
123 lcp
-> lcd_retry
= 0;
126 case CLEAR
+ SENT_CLEAR
:
127 lcp
-> lcd_timer
= pk_t23
;
131 case CLEAR_CONF
+ RECEIVED_CLEAR
:
132 case CLEAR_CONF
+ SENT_CLEAR
:
133 case CLEAR_CONF
+ READY
:
134 lcp
-> lcd_state
= READY
;
137 case DATA
+ DATA_TRANSFER
:
138 SPS(xp
, lcp
-> lcd_ssn
);
139 lcp
-> lcd_input_window
=
140 (lcp
-> lcd_rsn
+ 1) % MODULUS
;
141 SPR(xp
, lcp
-> lcd_input_window
);
142 lcp
-> lcd_last_transmitted_pr
= lcp
-> lcd_input_window
;
143 lcp
-> lcd_ssn
= (lcp
-> lcd_ssn
+ 1) % MODULUS
;
144 if (lcp
-> lcd_ssn
== ((lcp
-> lcd_output_window
+ lcp
-> lcd_windowsize
) % MODULUS
))
145 lcp
-> lcd_window_condition
= TRUE
;
148 case INTERRUPT
+ DATA_TRANSFER
:
149 #ifdef ancient_history
150 xp
-> packet_data
= 0;
152 lcp
-> lcd_intrconf_pending
= TRUE
;
155 case INTERRUPT_CONF
+ DATA_TRANSFER
:
158 case RR
+ DATA_TRANSFER
:
159 case RNR
+ DATA_TRANSFER
:
160 lcp
-> lcd_input_window
=
161 (lcp
-> lcd_rsn
+ 1) % MODULUS
;
162 SPR(xp
, lcp
-> lcd_input_window
);
163 lcp
-> lcd_last_transmitted_pr
= lcp
-> lcd_input_window
;
166 case RESET
+ DATA_TRANSFER
:
167 lcp
-> lcd_reset_condition
= TRUE
;
170 case RESET_CONF
+ DATA_TRANSFER
:
171 lcp
-> lcd_reset_condition
= FALSE
;
175 * A restart should be only generated internally. Therefore
176 * all logic for restart is in the pk_restart routine.
178 case RESTART
+ READY
:
179 lcp
-> lcd_timer
= pk_t20
;
183 * Restarts are all handled internally. Therefore all the
184 * logic for the incoming restart packet is handled in the
187 case RESTART_CONF
+ READY
:
195 /* Trace the packet. */
196 pk_trace (pkp
-> pk_xcp
, m
, "P-Out");
198 /* Pass the packet on down to the link layer */
199 if (pk_input_cache
.mbc_size
|| pk_input_cache
.mbc_oldsize
) {
201 mbuf_cache(&pk_input_cache
, m
);
203 (*pkp
-> pk_lloutput
) (pkp
-> pk_llnext
, m
, pkp
-> pk_rt
);
208 * This procedure returns the next packet to send or null. A
209 * packet is composed of one or more mbufs.
216 register struct mbuf
*m
, *n
;
217 struct socket
*so
= lcp
-> lcd_so
;
218 register struct sockbuf
*sb
= & (so
? so
-> so_snd
: lcp
-> lcd_sb
);
220 if (lcp
-> lcd_template
) {
221 m
= lcp
-> lcd_template
;
222 lcp
-> lcd_template
= NULL
;
224 if (lcp
-> lcd_rnr_condition
|| lcp
-> lcd_window_condition
||
225 lcp
-> lcd_reset_condition
)
228 if ((m
= sb
-> sb_mb
) == 0)
231 sb
-> sb_mb
= m
-> m_nextpkt
;
233 for (n
= m
; n
; n
= n
-> m_next
)