Annotation of Net2/netiso/tp_cons.c, revision 1.1.1.3

1.1       root        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:  *
1.1.1.3 ! root       33:  *     from: @(#)tp_cons.c     7.8 (Berkeley) 5/9/91
        !            34:  *     tp_cons.c,v 1.2 1993/05/20 05:27:31 cgd Exp
1.1       root       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:  * ARGO TP
                     65:  *
                     66:  * Here is where you find the iso- and cons-dependent code.  We've tried
                     67:  * keep all net-level and (primarily) address-family-dependent stuff
                     68:  * out of the tp source, and everthing here is reached indirectly
                     69:  * through a switch table (struct nl_protosw *) tpcb->tp_nlproto 
                     70:  * (see tp_pcb.c). 
                     71:  * The routines here are:
                     72:  *     tpcons_input: pullup and call tp_input w/ correct arguments
                     73:  *     tpcons_output: package a pkt for cons given an isopcb & some data
                     74:  *     cons_chan_to_tpcb: find a tpcb based on the channel #
                     75:  */
                     76: 
                     77: #ifdef ISO
                     78: #ifdef TPCONS
                     79: 
                     80: #include "param.h"
                     81: #include "socket.h"
                     82: #include "domain.h"
                     83: #include "mbuf.h"
                     84: #include "errno.h"
                     85: #include "time.h"
                     86: 
                     87: #include "../net/if.h"
                     88: #include "../net/route.h"
                     89: 
                     90: #include "tp_param.h"
                     91: #include "argo_debug.h"
                     92: #include "tp_stat.h"
                     93: #include "tp_pcb.h"
                     94: #include "tp_trace.h"
                     95: #include "tp_stat.h"
                     96: #include "tp_tpdu.h"
                     97: #include "iso.h"
                     98: #include "iso_errno.h"
                     99: #include "iso_pcb.h"
                    100: #include "cons.h"
                    101: #include "tp_seq.h"
                    102: 
                    103: #undef FALSE
                    104: #undef TRUE
                    105: #include "../netccitt/x25.h"
                    106: #include "../netccitt/pk.h"
                    107: #include "../netccitt/pk_var.h"
                    108: 
                    109: #include "if_cons.c"
                    110: int tpcons_output();
                    111: 
                    112: /*
                    113:  * CALLED FROM:
                    114:  *  tp_route_to() for PRU_CONNECT
                    115:  * FUNCTION, ARGUMENTS, SIDE EFFECTS and RETURN VALUE:
                    116:  *  version of the previous procedure for X.25
                    117:  */
                    118: 
                    119: tpcons_pcbconnect(isop, nam)
                    120: struct isopcb *isop;
                    121: register struct mbuf *nam;
                    122: {
                    123:        int error;
                    124:        if (error = iso_pcbconnect(isop, nam))
                    125:                return error;
                    126:        if ((isop->isop_chan = (caddr_t) pk_attach((struct socket *)0)) == 0) {
                    127:                IFDEBUG(D_CCONS)
                    128:                        printf("tpcons_pcbconnect: no pklcd; returns 0x%x\n", error);
                    129:                ENDDEBUG
                    130:                return ENOBUFS;
                    131:        }
                    132:        if (error = cons_connect(isop)) { /* if it doesn't work */
                    133:                /* oh, dear, throw packet away */
                    134:                pk_disconnect((struct pklcd *)isop->isop_chan);
                    135:                isop->isop_chan = 0;
                    136:        } else 
                    137:                isop->isop_refcnt = 1;
                    138:        return error;
                    139: }
                    140: 
                    141: 
                    142: /*
                    143:  * CALLED FROM:
                    144:  *     cons
                    145:  * FUNCTION and ARGUMENTS:
                    146:  * THIS MAYBE BELONGS IN SOME OTHER PLACE??? but i think not -
                    147:  */
                    148: ProtoHook
                    149: tpcons_ctlinput(cmd, siso, isop)
                    150:        int cmd; 
                    151:        struct sockaddr_iso *siso;
                    152:        struct isopcb *isop;
                    153: {
                    154:        switch (cmd) {
                    155: 
                    156:        case PRC_CONS_SEND_DONE:
                    157:                if( isop->isop_socket ) { /* tp 0 only */
                    158:                        register struct tp_pcb *tpcb = 
                    159:                                (struct tp_pcb *)isop->isop_socket->so_tpcb;
                    160:                        struct  tp_event                E;
                    161:                        int                                     error = 0;
                    162: 
                    163:                        if( tpcb->tp_class == TP_CLASS_0 ) {
                    164:                                /* only if class is exactly class zero, not
                    165:                                 * still in class negotiation
                    166:                                 */
                    167:                                /* fake an ack */
                    168:                                register SeqNum seq =  SEQ_ADD(tpcb, tpcb->tp_snduna, 1);
                    169: 
                    170:                                IFTRACE(D_DATA)
                    171:                                        tptrace(TPPTmisc, "FAKE ACK seq cdt 1", 
                    172:                                                seq, 0,0,0);
                    173:                                ENDTRACE
                    174:                                IFDEBUG(D_DATA)
                    175:                                        printf("FAKE ACK seq 0x%x cdt 1\n", seq );
                    176:                                ENDDEBUG
                    177:                                E.ATTR(AK_TPDU).e_cdt = 1;
                    178:                                E.ATTR(AK_TPDU).e_seq = seq;
                    179:                                E.ATTR(AK_TPDU).e_subseq = 0;
                    180:                                E.ATTR(AK_TPDU).e_fcc_present = 0;
                    181:                                error =  DoEvent(AK_TPDU);
                    182:                                if( error ) {
                    183:                                        tpcb->tp_sock->so_error = error;
                    184:                                }
                    185:                        } /* else ignore it */
                    186:                } 
                    187:                break;
                    188:        case PRC_ROUTEDEAD:
                    189:                if( isop->isop_socket ) { /* tp 0 only */
                    190:                        tpiso_reset(isop);
                    191:                        break;
                    192:                } /* else drop through */
                    193:        default:
                    194:                (void) tpclnp_ctlinput(cmd, siso);
                    195:                break;
                    196:        }
                    197:        return 0;
                    198: }
                    199: 
                    200: /*
                    201:  * CALLED FROM:
                    202:  *     cons's intr routine
                    203:  * FUNCTION and ARGUMENTS:
                    204:  * Take a packet (m) from cons, pullup m as required by tp,
                    205:  *  ignore the socket argument, and call tp_input. 
                    206:  * No return value.  
                    207:  */
                    208: ProtoHook
                    209: tpcons_input(m, faddr, laddr, channel)
                    210:        struct mbuf             *m;
                    211:        struct sockaddr_iso     *faddr, *laddr;
                    212:        caddr_t                         channel;
                    213: {
                    214:        if( m == MNULL)
                    215:                return 0;
                    216: 
                    217:        m = (struct mbuf *)tp_inputprep(m);
                    218: 
                    219:        IFDEBUG(D_TPINPUT)
                    220:                printf("tpcons_input before tp_input(m 0x%x)\n", m);
                    221:                dump_buf( m, 12+ m->m_len);
                    222:        ENDDEBUG
                    223:        tp_input(m, faddr, laddr, channel, tpcons_output, 0);
                    224:        return 0;
                    225: }
                    226: 
                    227: 
                    228: /*
                    229:  * CALLED FROM:
                    230:  *  tp_emit()
                    231:  * FUNCTION and ARGUMENTS:
                    232:  *  Take a packet(m0) from tp and package it so that cons will accept it.
                    233:  *  This means filling in a few of the fields.
                    234:  *  inp is the isopcb structure; datalen is the length of the data in the
                    235:  *  mbuf string m0.
                    236:  * RETURN VALUE:
                    237:  *  whatever (E*) is returned form the net layer output routine.
                    238:  */
                    239: 
                    240: int
                    241: tpcons_output(isop, m0, datalen, nochksum)
                    242:        struct isopcb           *isop;
                    243:        struct mbuf             *m0;
                    244:        int                             datalen;
                    245:        int                                     nochksum;
                    246: {
                    247:        register        struct mbuf *m = m0;
                    248:        int                                     error;
                    249: 
                    250:        IFDEBUG(D_EMIT)
                    251:                printf(
                    252:                "tpcons_output(isop 0x%x, m 0x%x, len 0x%x socket 0x%x\n",
                    253:                        isop, m0, datalen, isop->isop_socket);
                    254:        ENDDEBUG
                    255:        if (m == MNULL)
                    256:                return 0;
                    257:        if ((m->m_flags & M_PKTHDR) == 0) {
                    258:                MGETHDR(m, M_DONTWAIT, MT_DATA);
                    259:                if (m == 0)
                    260:                        return ENOBUFS;
                    261:                m->m_next = m0;
                    262:        }
                    263:        m->m_pkthdr.len = datalen;
                    264:        error = pk_send(isop->isop_chan, m);
                    265:        IncStat(ts_tpdu_sent);
                    266: 
                    267:        return error;
                    268: }
                    269: /*
                    270:  * CALLED FROM:
                    271:  *  tp_error_emit()
                    272:  * FUNCTION and ARGUMENTS:
                    273:  *  Take a packet(m0) from tp and package it so that cons will accept it.
                    274:  *  chan is the cons channel to use; datalen is the length of the data in the
                    275:  *  mbuf string m0.
                    276:  * RETURN VALUE:
                    277:  *  whatever (E*) is returned form the net layer output routine.
                    278:  */
                    279: 
                    280: int
                    281: tpcons_dg_output(chan, m0, datalen)
                    282:        caddr_t                         chan;
                    283:        struct mbuf             *m0;
                    284:        int                             datalen;
                    285: {
                    286:        return tpcons_output(((struct pklcd *)chan)->lcd_upnext, m0, datalen, 0);
                    287: }
                    288: #endif TPCONS
                    289: #endif ISO

unix.superglobalmegacorp.com

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