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