| 1 | /*- |
| 2 | * Copyright (c) 1991 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 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. |
| 20 | * |
| 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 | * from: @(#)tp_cons.c 7.8 (Berkeley) 5/9/91 |
| 34 | * $Id: tp_cons.c,v 1.3 1993/12/19 00:53:30 wollman Exp $ |
| 35 | */ |
| 36 | |
| 37 | /*********************************************************** |
| 38 | Copyright IBM Corporation 1987 |
| 39 | |
| 40 | All Rights Reserved |
| 41 | |
| 42 | Permission to use, copy, modify, and distribute this software and its |
| 43 | documentation for any purpose and without fee is hereby granted, |
| 44 | provided that the above copyright notice appear in all copies and that |
| 45 | both that copyright notice and this permission notice appear in |
| 46 | supporting documentation, and that the name of IBM not be |
| 47 | used in advertising or publicity pertaining to distribution of the |
| 48 | software without specific, written prior permission. |
| 49 | |
| 50 | IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING |
| 51 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL |
| 52 | IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
| 53 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 54 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
| 55 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
| 56 | SOFTWARE. |
| 57 | |
| 58 | ******************************************************************/ |
| 59 | |
| 60 | /* |
| 61 | * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison |
| 62 | */ |
| 63 | |
| 64 | /* |
| 65 | * ARGO TP |
| 66 | * |
| 67 | * Here is where you find the iso- and cons-dependent code. We've tried |
| 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: |
| 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 # |
| 76 | */ |
| 77 | |
| 78 | #ifdef ISO |
| 79 | #ifdef TPCONS |
| 80 | |
| 81 | #include "param.h" |
| 82 | #include "systm.h" |
| 83 | #include "socket.h" |
| 84 | #include "domain.h" |
| 85 | #include "mbuf.h" |
| 86 | #include "errno.h" |
| 87 | #include "time.h" |
| 88 | |
| 89 | #include "../net/if.h" |
| 90 | #include "../net/route.h" |
| 91 | |
| 92 | #include "tp_param.h" |
| 93 | #include "argo_debug.h" |
| 94 | #include "tp_stat.h" |
| 95 | #include "tp_pcb.h" |
| 96 | #include "tp_trace.h" |
| 97 | #include "tp_stat.h" |
| 98 | #include "tp_tpdu.h" |
| 99 | #include "iso.h" |
| 100 | #include "iso_errno.h" |
| 101 | #include "iso_pcb.h" |
| 102 | #include "cons.h" |
| 103 | #include "tp_seq.h" |
| 104 | |
| 105 | #undef FALSE |
| 106 | #undef TRUE |
| 107 | #include "../netccitt/x25.h" |
| 108 | #include "../netccitt/pk.h" |
| 109 | #include "../netccitt/pk_var.h" |
| 110 | |
| 111 | #include "if_cons.c" |
| 112 | int tpcons_output(); |
| 113 | |
| 114 | /* |
| 115 | * CALLED FROM: |
| 116 | * tp_route_to() for PRU_CONNECT |
| 117 | * FUNCTION, ARGUMENTS, SIDE EFFECTS and RETURN VALUE: |
| 118 | * version of the previous procedure for X.25 |
| 119 | */ |
| 120 | |
| 121 | int |
| 122 | tpcons_pcbconnect(isop, nam) |
| 123 | struct isopcb *isop; |
| 124 | register struct mbuf *nam; |
| 125 | { |
| 126 | int error; |
| 127 | if (error = iso_pcbconnect(isop, nam)) |
| 128 | return error; |
| 129 | if ((isop->isop_chan = (caddr_t) pk_attach((struct socket *)0)) == 0) { |
| 130 | IFDEBUG(D_CCONS) |
| 131 | printf("tpcons_pcbconnect: no pklcd; returns 0x%x\n", error); |
| 132 | ENDDEBUG |
| 133 | return ENOBUFS; |
| 134 | } |
| 135 | if (error = cons_connect(isop)) { /* if it doesn't work */ |
| 136 | /* oh, dear, throw packet away */ |
| 137 | pk_disconnect((struct pklcd *)isop->isop_chan); |
| 138 | isop->isop_chan = 0; |
| 139 | } else |
| 140 | isop->isop_refcnt = 1; |
| 141 | return error; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /* |
| 146 | * CALLED FROM: |
| 147 | * cons |
| 148 | * FUNCTION and ARGUMENTS: |
| 149 | * THIS MAYBE BELONGS IN SOME OTHER PLACE??? but i think not - |
| 150 | */ |
| 151 | ProtoHook |
| 152 | tpcons_ctlinput(cmd, siso, isop) |
| 153 | int cmd; |
| 154 | struct sockaddr_iso *siso; |
| 155 | struct isopcb *isop; |
| 156 | { |
| 157 | switch (cmd) { |
| 158 | |
| 159 | case PRC_CONS_SEND_DONE: |
| 160 | if( isop->isop_socket ) { /* tp 0 only */ |
| 161 | register struct tp_pcb *tpcb = |
| 162 | (struct tp_pcb *)isop->isop_socket->so_tpcb; |
| 163 | struct tp_event E; |
| 164 | int error = 0; |
| 165 | |
| 166 | if( tpcb->tp_class == TP_CLASS_0 ) { |
| 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 */ |
| 189 | } |
| 190 | break; |
| 191 | case PRC_ROUTEDEAD: |
| 192 | if( isop->isop_socket ) { /* tp 0 only */ |
| 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 |
| 212 | tpcons_input(m, faddr, laddr, channel) |
| 213 | struct mbuf *m; |
| 214 | struct sockaddr_iso *faddr, *laddr; |
| 215 | caddr_t channel; |
| 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 |
| 226 | tp_input(m, (struct sockaddr *)faddr, (struct sockaddr *)laddr, |
| 227 | (u_long)channel, tpcons_output, 0); |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /* |
| 233 | * CALLED FROM: |
| 234 | * tp_emit() |
| 235 | * FUNCTION and ARGUMENTS: |
| 236 | * Take a packet(m0) from tp and package it so that cons will accept it. |
| 237 | * This means filling in a few of the fields. |
| 238 | * inp is the isopcb structure; datalen is the length of the data in the |
| 239 | * mbuf string m0. |
| 240 | * RETURN VALUE: |
| 241 | * whatever (E*) is returned form the net layer output routine. |
| 242 | */ |
| 243 | |
| 244 | int |
| 245 | tpcons_output(isop, m0, datalen, nochksum) |
| 246 | struct isopcb *isop; |
| 247 | struct mbuf *m0; |
| 248 | int datalen; |
| 249 | int nochksum; |
| 250 | { |
| 251 | register struct mbuf *m = m0; |
| 252 | int error; |
| 253 | |
| 254 | IFDEBUG(D_EMIT) |
| 255 | printf( |
| 256 | "tpcons_output(isop 0x%x, m 0x%x, len 0x%x socket 0x%x\n", |
| 257 | isop, m0, datalen, isop->isop_socket); |
| 258 | ENDDEBUG |
| 259 | if (m == MNULL) |
| 260 | return 0; |
| 261 | if ((m->m_flags & M_PKTHDR) == 0) { |
| 262 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
| 263 | if (m == 0) |
| 264 | return ENOBUFS; |
| 265 | m->m_next = m0; |
| 266 | } |
| 267 | m->m_pkthdr.len = datalen; |
| 268 | error = pk_send((void *)isop->isop_chan, m); |
| 269 | IncStat(ts_tpdu_sent); |
| 270 | |
| 271 | return error; |
| 272 | } |
| 273 | /* |
| 274 | * CALLED FROM: |
| 275 | * tp_error_emit() |
| 276 | * FUNCTION and ARGUMENTS: |
| 277 | * Take a packet(m0) from tp and package it so that cons will accept it. |
| 278 | * chan is the cons channel to use; datalen is the length of the data in the |
| 279 | * mbuf string m0. |
| 280 | * RETURN VALUE: |
| 281 | * whatever (E*) is returned form the net layer output routine. |
| 282 | */ |
| 283 | |
| 284 | int |
| 285 | tpcons_dg_output(chan, m0, datalen) |
| 286 | caddr_t chan; |
| 287 | struct mbuf *m0; |
| 288 | int datalen; |
| 289 | { |
| 290 | return tpcons_output(((struct pklcd *)chan)->lcd_upnext, m0, datalen, 0); |
| 291 | } |
| 292 | #endif /* TPCONS */ |
| 293 | #endif /* ISO */ |