BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netiso / tp_cons.c
index 5fe070e..bfd5e12 100644 (file)
@@ -1,3 +1,38 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)tp_cons.c   7.8 (Berkeley) 5/9/91
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -28,29 +63,20 @@ SOFTWARE.
  * ARGO TP
  * $Header: tp_cons.c,v 5.6 88/11/18 17:27:13 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_cons.c,v $
  * ARGO TP
  * $Header: tp_cons.c,v 5.6 88/11/18 17:27:13 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_cons.c,v $
- *     @(#)tp_cons.c   7.3 (Berkeley) 8/29/89 *
  *
  *
- * Here is where you find the iso-dependent code.  We've tried
+ * Here is where you find the iso- and cons-dependent code.  We've tried
  * keep all net-level and (primarily) address-family-dependent stuff
  * out of the tp source, and everthing here is reached indirectly
  * through a switch table (struct nl_protosw *) tpcb->tp_nlproto 
  * (see tp_pcb.c). 
  * The routines here are:
  * keep all net-level and (primarily) address-family-dependent stuff
  * out of the tp source, and everthing here is reached indirectly
  * through a switch table (struct nl_protosw *) tpcb->tp_nlproto 
  * (see tp_pcb.c). 
  * The routines here are:
- *             tpcons_mtu: figure out what size tpdu to use
- *             tpcons_input: pullup and call tp_input w/ correct arguments
- *             tpcons_output_dg: package a pkt for cons given 2 addresses & some data
- *             tpcons_output: package a pkt for cons given an isopcb & some data
- *             cons_chan_to_tpcb: find a tpcb based on the channel #
+ *     tpcons_input: pullup and call tp_input w/ correct arguments
+ *     tpcons_output: package a pkt for cons given an isopcb & some data
+ *     cons_chan_to_tpcb: find a tpcb based on the channel #
  */
 
  */
 
-#ifndef lint
-static char *rcsid = "$Header: tp_cons.c,v 5.6 88/11/18 17:27:13 nhall Exp $";
-#endif lint
-
-#include "argoxtwentyfive.h"
-
 #ifdef ISO
 #ifdef ISO
-#if NARGOXTWENTYFIVE > 0
+#ifdef TPCONS
 
 #include "param.h"
 #include "socket.h"
 
 #include "param.h"
 #include "socket.h"
@@ -58,7 +84,9 @@ static char *rcsid = "$Header: tp_cons.c,v 5.6 88/11/18 17:27:13 nhall Exp $";
 #include "mbuf.h"
 #include "errno.h"
 #include "time.h"
 #include "mbuf.h"
 #include "errno.h"
 #include "time.h"
+
 #include "../net/if.h"
 #include "../net/if.h"
+#include "../net/route.h"
 
 #include "tp_param.h"
 #include "argo_debug.h"
 
 #include "tp_param.h"
 #include "argo_debug.h"
@@ -67,79 +95,51 @@ static char *rcsid = "$Header: tp_cons.c,v 5.6 88/11/18 17:27:13 nhall Exp $";
 #include "tp_trace.h"
 #include "tp_stat.h"
 #include "tp_tpdu.h"
 #include "tp_trace.h"
 #include "tp_stat.h"
 #include "tp_tpdu.h"
-#include "../net/route.h"
 #include "iso.h"
 #include "iso.h"
+#include "iso_errno.h"
 #include "iso_pcb.h"
 #include "cons.h"
 #include "tp_seq.h"
 
 #include "iso_pcb.h"
 #include "cons.h"
 #include "tp_seq.h"
 
+#undef FALSE
+#undef TRUE
+#include "../netccitt/x25.h"
+#include "../netccitt/pk.h"
+#include "../netccitt/pk_var.h"
+
+#include "if_cons.c"
 int tpcons_output();
 
 /*
  * CALLED FROM:
 int tpcons_output();
 
 /*
  * CALLED FROM:
- *  tp_input() on incoming CR, CC, and pr_usrreq() for PRU_CONNECT
+ *  tp_route_to() for PRU_CONNECT
  * FUNCTION, ARGUMENTS, SIDE EFFECTS and RETURN VALUE:
  *  version of the previous procedure for X.25
  */
 
  * FUNCTION, ARGUMENTS, SIDE EFFECTS and RETURN VALUE:
  *  version of the previous procedure for X.25
  */
 
-void
-tpcons_mtu(so, isop, size, negot)
-       struct socket *so;
-       struct isopcb *isop;
-       int *size;
-       u_char *negot;
+tpcons_pcbconnect(isop, nam)
+struct isopcb *isop;
+register struct mbuf *nam;
 {
 {
-       register struct ifnet *ifp;
-       register int i=0;
-       int windowsize = so->so_rcv.sb_hiwat;
-       struct ifnet    *iso_routeifp();
-
-       IFTRACE(D_CONN)
-               tptrace(TPPTmisc, "ENTER GET MTU: size negot ",*size, *negot, 0, 0);
-       ENDTRACE
-
-
-       *size = 1 << *negot;
-       if ((ifp = iso_routeifp(&isop->isop_faddr)) == (struct ifnet *)0)
-               return;
-
-       if( *size > windowsize ) {
-               *size = windowsize;
-               i++;
-       }
-
-       if(*size > ifp->if_mtu) {
-               *size = ifp->if_mtu ;
-               i++;
-       }
-       if(i) {
-               /* size was changed by this routine - have to transform it to
-                * the log2 of size
-                */
-               for(i=TP_MIN_TPDUSIZE; (i<TP_MAX_TPDUSIZE && ((1<<i)<*size)) ; i++)
-                       ;
-               /* are we on the same LAN? if so, negotiate one tpdu size larger,
-                * and actually send the real mtu size
-                */
-               /* PHASE2: replace with iso_on_localnet(&isop->isop_faddr);
-                */
-               if ( !iso_netmatch(&isop->isop_laddr, &isop->isop_faddr) ) {
-                       i--;
-                       *size = 1<<i;
-               }
-               *negot = i;
+       int error;
+       if (error = iso_pcbconnect(isop, nam))
+               return error;
+       if ((isop->isop_chan = (caddr_t) pk_attach((struct socket *)0)) == 0) {
+               IFDEBUG(D_CCONS)
+                       printf("tpcons_pcbconnect: no pklcd; returns 0x%x\n", error);
+               ENDDEBUG
+               return ENOBUFS;
        }
        }
-
-       IFDEBUG(D_CONN)
-               printf("GET MTU RETURNS: ifp %s size 0x%x negot 0x%x\n",
-               ifp->if_name,   *size, *negot);
-       ENDDEBUG
-       IFTRACE(D_CONN)
-               tptrace(TPPTmisc, "EXIT GET MTU: tpcb size negot ",
-               *size, *negot, 0, 0);
-       ENDTRACE
+       if (error = cons_connect(isop)) { /* if it doesn't work */
+               /* oh, dear, throw packet away */
+               pk_disconnect((struct pklcd *)isop->isop_chan);
+               isop->isop_chan = 0;
+       } else 
+               isop->isop_refcnt = 1;
+       return error;
 }
 
 }
 
+
 /*
  * CALLED FROM:
  *     cons
 /*
  * CALLED FROM:
  *     cons
@@ -207,11 +207,10 @@ tpcons_ctlinput(cmd, siso, isop)
  * No return value.  
  */
 ProtoHook
  * No return value.  
  */
 ProtoHook
-tpcons_input(m, faddr, laddr, so, channel)
+tpcons_input(m, faddr, laddr, channel)
        struct mbuf             *m;
        struct sockaddr_iso     *faddr, *laddr;
        struct mbuf             *m;
        struct sockaddr_iso     *faddr, *laddr;
-       struct socket           *so; /* not used */
-       int                                     channel;
+       caddr_t                         channel;
 {
        if( m == MNULL)
                return 0;
 {
        if( m == MNULL)
                return 0;
@@ -222,7 +221,7 @@ tpcons_input(m, faddr, laddr, so, channel)
                printf("tpcons_input before tp_input(m 0x%x)\n", m);
                dump_buf( m, 12+ m->m_len);
        ENDDEBUG
                printf("tpcons_input before tp_input(m 0x%x)\n", m);
                dump_buf( m, 12+ m->m_len);
        ENDDEBUG
-       tp_input(m, faddr, laddr, channel, tpcons_output);
+       tp_input(m, faddr, laddr, channel, tpcons_output, 0);
        return 0;
 }
 
        return 0;
 }
 
@@ -246,7 +245,7 @@ tpcons_output(isop, m0, datalen, nochksum)
        int                             datalen;
        int                                     nochksum;
 {
        int                             datalen;
        int                                     nochksum;
 {
-       struct tp_pcb           *tpcb;
+       register        struct mbuf *m = m0;
        int                                     error;
 
        IFDEBUG(D_EMIT)
        int                                     error;
 
        IFDEBUG(D_EMIT)
@@ -254,77 +253,38 @@ tpcons_output(isop, m0, datalen, nochksum)
                "tpcons_output(isop 0x%x, m 0x%x, len 0x%x socket 0x%x\n",
                        isop, m0, datalen, isop->isop_socket);
        ENDDEBUG
                "tpcons_output(isop 0x%x, m 0x%x, len 0x%x socket 0x%x\n",
                        isop, m0, datalen, isop->isop_socket);
        ENDDEBUG
-       if(m0 == MNULL)
+       if (m == MNULL)
                return 0;
                return 0;
-       ASSERT(m0->m_len > 0);
-       tpcb = (struct tp_pcb *)isop->isop_socket->so_tpcb;
-
-       /* check is for class EQUAL to 4: if still in negotiation stage, 
-        * cannot send as dgm
-        */
-       error = cons_output(isop, m0,  datalen, (tpcb->tp_class == TP_CLASS_4));
+       if ((m->m_flags & M_PKTHDR) == 0) {
+               MGETHDR(m, M_DONTWAIT, MT_DATA);
+               if (m == 0)
+                       return ENOBUFS;
+               m->m_next = m0;
+       }
+       m->m_pkthdr.len = datalen;
+       error = pk_send(isop->isop_chan, m);
        IncStat(ts_tpdu_sent);
 
        IncStat(ts_tpdu_sent);
 
-       IFTRACE(D_EMIT)
-               tptrace( TPPTmisc, 
-               "tpcons_output( isop  m isdgm cons_output returns", 
-                       isop, m0, (tpcb->tp_class == TP_CLASS_4), error );
-       ENDTRACE
        return error;
 }
        return error;
 }
-
 /*
  * CALLED FROM:
  *  tp_error_emit()
  * FUNCTION and ARGUMENTS:
 /*
  * CALLED FROM:
  *  tp_error_emit()
  * FUNCTION and ARGUMENTS:
- *  This is a copy of tpcons_output that takes the addresses
- *  instead of a pcb.  It's used by the tp_error_emit, when we
- *  don't have an iso_pcb with which to call the normal output rtn.
+ *  Take a packet(m0) from tp and package it so that cons will accept it.
+ *  chan is the cons channel to use; datalen is the length of the data in the
+ *  mbuf string m0.
  * RETURN VALUE:
  * RETURN VALUE:
- *  ENOBUFS or
  *  whatever (E*) is returned form the net layer output routine.
  */
 
 int
  *  whatever (E*) is returned form the net layer output routine.
  */
 
 int
-tpcons_output_dg(laddr, faddr, m0, datalen, ro, nochksum)
-       struct iso_addr         *laddr, *faddr;
+tpcons_dg_output(chan, m0, datalen)
+       caddr_t                         chan;
        struct mbuf             *m0;
        int                             datalen;
        struct mbuf             *m0;
        int                             datalen;
-       struct route            *ro;
-       int                                     nochksum;
 {
 {
-       IFDEBUG(D_TPISO)
-               printf("PANIC: tpcons_output_dg  datalen 0x%x m0 0x%x\n", datalen, m0);
-       ENDDEBUG
-
-       return 0;
-}
-
-struct tp_pcb *
-cons_chan_to_tpcb(chan)
-       int chan;
-{
-       extern struct isopcb *cons_chan_to_pcb ();
-#ifdef ARGO_DEBUG
-       struct isopcb *isop = cons_chan_to_pcb (chan, -1);
-#else ARGO_DEBUG
-       struct isopcb *isop = cons_chan_to_pcb (chan);
-#endif ARGO_DEBUG
-
-       IFTRACE(D_CONN)
-               tptrace(TPPTmisc, "vc->tpcb(chan) socket",
-                       chan, isop->isop_socket, 0, 0);
-       ENDTRACE
-       IFDEBUG(D_CONN)
-               printf("vc->tpcb(0x%x) socket 0x%x, *ISOP dump:",
-                       chan, isop->isop_socket);
-               dump_buf( isop, 32);
-       ENDDEBUG
-       if( isop->isop_socket == (struct socket *)0 )
-               return (struct tp_pcb *) 0;
-       else {
-               return (struct tp_pcb *)(isop->isop_socket->so_tpcb);
-}
+       return tpcons_output(((struct pklcd *)chan)->lcd_upnext, m0, datalen, 0);
 }
 }
-#endif NARGOXTWENTYFIVE
+#endif TPCONS
 #endif ISO
 #endif ISO