Annotation of kernel/bsd/netiso/tp_cons.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.