Commit | Line | Data |
---|---|---|
7bcd1bb8 | 1 | /*- |
ad787160 C |
2 | * Copyright (c) 1991, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
7bcd1bb8 | 4 | * |
ad787160 C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
7bcd1bb8 | 20 | * |
ad787160 C |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)tp_cons.c 8.1 (Berkeley) 6/10/93 | |
7bcd1bb8 KB |
34 | */ |
35 | ||
47f37345 KS |
36 | /*********************************************************** |
37 | Copyright IBM Corporation 1987 | |
38 | ||
39 | All Rights Reserved | |
40 | ||
41 | Permission to use, copy, modify, and distribute this software and its | |
42 | documentation for any purpose and without fee is hereby granted, | |
43 | provided that the above copyright notice appear in all copies and that | |
44 | both that copyright notice and this permission notice appear in | |
45 | supporting documentation, and that the name of IBM not be | |
46 | used in advertising or publicity pertaining to distribution of the | |
47 | software without specific, written prior permission. | |
48 | ||
49 | IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
50 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
51 | IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | |
52 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
53 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
54 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
55 | SOFTWARE. | |
56 | ||
57 | ******************************************************************/ | |
58 | ||
59 | /* | |
60 | * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison | |
61 | */ | |
62 | /* | |
63 | * ARGO TP | |
64 | * $Header: tp_cons.c,v 5.6 88/11/18 17:27:13 nhall Exp $ | |
65 | * $Source: /usr/argo/sys/netiso/RCS/tp_cons.c,v $ | |
66 | * | |
194a383a | 67 | * Here is where you find the iso- and cons-dependent code. We've tried |
47f37345 KS |
68 | * keep all net-level and (primarily) address-family-dependent stuff |
69 | * out of the tp source, and everthing here is reached indirectly | |
70 | * through a switch table (struct nl_protosw *) tpcb->tp_nlproto | |
71 | * (see tp_pcb.c). | |
72 | * The routines here are: | |
7bcd1bb8 KB |
73 | * tpcons_input: pullup and call tp_input w/ correct arguments |
74 | * tpcons_output: package a pkt for cons given an isopcb & some data | |
75 | * cons_chan_to_tpcb: find a tpcb based on the channel # | |
47f37345 KS |
76 | */ |
77 | ||
47f37345 | 78 | #ifdef ISO |
194a383a | 79 | #ifdef TPCONS |
47f37345 | 80 | |
5548a02f KB |
81 | #include <sys/param.h> |
82 | #include <sys/socket.h> | |
83 | #include <sys/domain.h> | |
84 | #include <sys/mbuf.h> | |
85 | #include <sys/errno.h> | |
86 | #include <sys/time.h> | |
194a383a | 87 | |
5548a02f KB |
88 | #include <net/if.h> |
89 | #include <net/route.h> | |
47f37345 | 90 | |
5548a02f KB |
91 | #include <netiso/tp_param.h> |
92 | #include <netiso/argo_debug.h> | |
93 | #include <netiso/tp_stat.h> | |
94 | #include <netiso/tp_pcb.h> | |
95 | #include <netiso/tp_trace.h> | |
96 | #include <netiso/tp_stat.h> | |
97 | #include <netiso/tp_tpdu.h> | |
98 | #include <netiso/iso.h> | |
99 | #include <netiso/iso_errno.h> | |
100 | #include <netiso/iso_pcb.h> | |
101 | #include <netiso/cons.h> | |
102 | #include <netiso/tp_seq.h> | |
47f37345 | 103 | |
194a383a KS |
104 | #undef FALSE |
105 | #undef TRUE | |
5548a02f KB |
106 | #include <netccitt/x25.h> |
107 | #include <netccitt/pk.h> | |
108 | #include <netccitt/pk_var.h> | |
194a383a | 109 | |
5548a02f | 110 | #include <netiso/if_cons.c> |
47f37345 KS |
111 | int tpcons_output(); |
112 | ||
194a383a KS |
113 | /* |
114 | * CALLED FROM: | |
115 | * tp_route_to() for PRU_CONNECT | |
116 | * FUNCTION, ARGUMENTS, SIDE EFFECTS and RETURN VALUE: | |
117 | * version of the previous procedure for X.25 | |
118 | */ | |
119 | ||
120 | tpcons_pcbconnect(isop, nam) | |
121 | struct isopcb *isop; | |
122 | register struct mbuf *nam; | |
123 | { | |
124 | int error; | |
125 | if (error = iso_pcbconnect(isop, nam)) | |
126 | return error; | |
127 | if ((isop->isop_chan = (caddr_t) pk_attach((struct socket *)0)) == 0) { | |
128 | IFDEBUG(D_CCONS) | |
129 | printf("tpcons_pcbconnect: no pklcd; returns 0x%x\n", error); | |
130 | ENDDEBUG | |
131 | return ENOBUFS; | |
132 | } | |
133 | if (error = cons_connect(isop)) { /* if it doesn't work */ | |
134 | /* oh, dear, throw packet away */ | |
135 | pk_disconnect((struct pklcd *)isop->isop_chan); | |
136 | isop->isop_chan = 0; | |
a4063d79 KS |
137 | } else |
138 | isop->isop_refcnt = 1; | |
139 | return error; | |
194a383a KS |
140 | } |
141 | ||
142 | ||
47f37345 KS |
143 | /* |
144 | * CALLED FROM: | |
145 | * cons | |
146 | * FUNCTION and ARGUMENTS: | |
147 | * THIS MAYBE BELONGS IN SOME OTHER PLACE??? but i think not - | |
148 | */ | |
149 | ProtoHook | |
150 | tpcons_ctlinput(cmd, siso, isop) | |
151 | int cmd; | |
152 | struct sockaddr_iso *siso; | |
153 | struct isopcb *isop; | |
154 | { | |
01acbfa1 KS |
155 | register struct tp_pcb *tpcb = 0; |
156 | ||
157 | if (isop->isop_socket) | |
158 | tpcb = (struct tp_pcb *)isop->isop_socket->so_pcb; | |
47f37345 KS |
159 | switch (cmd) { |
160 | ||
161 | case PRC_CONS_SEND_DONE: | |
01acbfa1 | 162 | if (tpcb) { |
47f37345 KS |
163 | struct tp_event E; |
164 | int error = 0; | |
165 | ||
01acbfa1 | 166 | if (tpcb->tp_class == TP_CLASS_0) { |
47f37345 KS |
167 | /* only if class is exactly class zero, not |
168 | * still in class negotiation | |
169 | */ | |
170 | /* fake an ack */ | |
171 | register SeqNum seq = SEQ_ADD(tpcb, tpcb->tp_snduna, 1); | |
172 | ||
173 | IFTRACE(D_DATA) | |
174 | tptrace(TPPTmisc, "FAKE ACK seq cdt 1", | |
175 | seq, 0,0,0); | |
176 | ENDTRACE | |
177 | IFDEBUG(D_DATA) | |
178 | printf("FAKE ACK seq 0x%x cdt 1\n", seq ); | |
179 | ENDDEBUG | |
180 | E.ATTR(AK_TPDU).e_cdt = 1; | |
181 | E.ATTR(AK_TPDU).e_seq = seq; | |
182 | E.ATTR(AK_TPDU).e_subseq = 0; | |
183 | E.ATTR(AK_TPDU).e_fcc_present = 0; | |
184 | error = DoEvent(AK_TPDU); | |
185 | if( error ) { | |
186 | tpcb->tp_sock->so_error = error; | |
187 | } | |
188 | } /* else ignore it */ | |
01acbfa1 | 189 | } |
47f37345 KS |
190 | break; |
191 | case PRC_ROUTEDEAD: | |
01acbfa1 | 192 | if (tpcb && tpcb->tp_class == TP_CLASS_0) { |
47f37345 KS |
193 | tpiso_reset(isop); |
194 | break; | |
195 | } /* else drop through */ | |
196 | default: | |
197 | (void) tpclnp_ctlinput(cmd, siso); | |
198 | break; | |
199 | } | |
200 | return 0; | |
201 | } | |
202 | ||
203 | /* | |
204 | * CALLED FROM: | |
205 | * cons's intr routine | |
206 | * FUNCTION and ARGUMENTS: | |
207 | * Take a packet (m) from cons, pullup m as required by tp, | |
208 | * ignore the socket argument, and call tp_input. | |
209 | * No return value. | |
210 | */ | |
211 | ProtoHook | |
194a383a | 212 | tpcons_input(m, faddr, laddr, channel) |
47f37345 KS |
213 | struct mbuf *m; |
214 | struct sockaddr_iso *faddr, *laddr; | |
194a383a | 215 | caddr_t channel; |
47f37345 KS |
216 | { |
217 | if( m == MNULL) | |
218 | return 0; | |
219 | ||
220 | m = (struct mbuf *)tp_inputprep(m); | |
221 | ||
222 | IFDEBUG(D_TPINPUT) | |
223 | printf("tpcons_input before tp_input(m 0x%x)\n", m); | |
224 | dump_buf( m, 12+ m->m_len); | |
225 | ENDDEBUG | |
0a55afa9 | 226 | tp_input(m, faddr, laddr, channel, tpcons_output, 0); |
47f37345 KS |
227 | return 0; |
228 | } | |
229 | ||
230 | ||
231 | /* | |
232 | * CALLED FROM: | |
233 | * tp_emit() | |
234 | * FUNCTION and ARGUMENTS: | |
235 | * Take a packet(m0) from tp and package it so that cons will accept it. | |
236 | * This means filling in a few of the fields. | |
237 | * inp is the isopcb structure; datalen is the length of the data in the | |
238 | * mbuf string m0. | |
239 | * RETURN VALUE: | |
240 | * whatever (E*) is returned form the net layer output routine. | |
241 | */ | |
242 | ||
243 | int | |
244 | tpcons_output(isop, m0, datalen, nochksum) | |
245 | struct isopcb *isop; | |
246 | struct mbuf *m0; | |
247 | int datalen; | |
248 | int nochksum; | |
249 | { | |
194a383a | 250 | register struct mbuf *m = m0; |
47f37345 KS |
251 | int error; |
252 | ||
253 | IFDEBUG(D_EMIT) | |
254 | printf( | |
255 | "tpcons_output(isop 0x%x, m 0x%x, len 0x%x socket 0x%x\n", | |
256 | isop, m0, datalen, isop->isop_socket); | |
257 | ENDDEBUG | |
194a383a | 258 | if (m == MNULL) |
47f37345 | 259 | return 0; |
793d846b | 260 | if ((m->m_flags & M_PKTHDR) == 0) { |
194a383a KS |
261 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
262 | if (m == 0) | |
263 | return ENOBUFS; | |
264 | m->m_next = m0; | |
265 | } | |
266 | m->m_pkthdr.len = datalen; | |
01acbfa1 KS |
267 | if (isop->isop_chan == 0) { |
268 | /* got a restart maybe? */ | |
269 | if ((isop->isop_chan = (caddr_t) pk_attach((struct socket *)0)) == 0) { | |
270 | IFDEBUG(D_CCONS) | |
271 | printf("tpcons_output: no pklcd\n"); | |
272 | ENDDEBUG | |
273 | error = ENOBUFS; | |
274 | } | |
275 | if (error = cons_connect(isop)) { | |
276 | pk_disconnect((struct pklcd *)isop->isop_chan); | |
277 | isop->isop_chan = 0; | |
278 | IFDEBUG(D_CCONS) | |
279 | printf("tpcons_output: can't reconnect\n"); | |
280 | ENDDEBUG | |
281 | } | |
282 | } else { | |
283 | error = pk_send(isop->isop_chan, m); | |
284 | IncStat(ts_tpdu_sent); | |
285 | } | |
47f37345 KS |
286 | return error; |
287 | } | |
47f37345 KS |
288 | /* |
289 | * CALLED FROM: | |
290 | * tp_error_emit() | |
291 | * FUNCTION and ARGUMENTS: | |
194a383a KS |
292 | * Take a packet(m0) from tp and package it so that cons will accept it. |
293 | * chan is the cons channel to use; datalen is the length of the data in the | |
294 | * mbuf string m0. | |
47f37345 | 295 | * RETURN VALUE: |
47f37345 KS |
296 | * whatever (E*) is returned form the net layer output routine. |
297 | */ | |
298 | ||
299 | int | |
194a383a KS |
300 | tpcons_dg_output(chan, m0, datalen) |
301 | caddr_t chan; | |
47f37345 KS |
302 | struct mbuf *m0; |
303 | int datalen; | |
47f37345 | 304 | { |
194a383a | 305 | return tpcons_output(((struct pklcd *)chan)->lcd_upnext, m0, datalen, 0); |
47f37345 | 306 | } |
4d8170e5 KB |
307 | #endif /* TPCONS */ |
308 | #endif /* ISO */ |