this version compiles; completely untested
[unix-history] / usr / src / sys / netccitt / pk_input.c
index 23f8715..6899f78 100644 (file)
-/* Copyright (c) University of British Columbia, 1984 */
+/*
+ * Copyright (c) University of British Columbia, 1984
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Laboratory for Computation Vision and the Computer Science Department
+ * of the University of British Columbia.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)pk_input.c  7.5 (Berkeley) %G%
+ */
 
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/mbuf.h"
-#include "../h/socket.h"
-#include "../h/protosw.h"
-#include "../h/socketvar.h"
-#include "../h/errno.h"
+#include "param.h"
+#include "systm.h"
+#include "mbuf.h"
+#include "socket.h"
+#include "protosw.h"
+#include "socketvar.h"
+#include "errno.h"
 
 #include "../net/if.h"
 
 
 #include "../net/if.h"
 
-#include "../netccitt/x25.h"
-#include "../netccitt/pk.h"
-#include "../netccitt/pk_var.h"
-
-struct pkcb *
-pk_newlink (xcp)
-struct x25config *xcp;
-{
-       register struct pkcb *pkp;
-       register struct mbuf *m;
-       register struct pklcd *lcp;
-       register struct protosw *pp;
-       register unsigned size;
-
-       if (xcp -> xc_ntnlen <= 0 || xcp -> xc_ntnlen > sizeof (xcp -> xc_ntn) * 2)
-               return ((struct pkcb *)0);
-#ifdef BSD4_3
-       pp = pffindproto (AF_CCITT, (int)xcp -> xc_lproto, 0);
-#else
-       pp = pffindproto (AF_CCITT, (int)xcp -> xc_lproto);
-#endif
-       if (pp == 0 || pp -> pr_output == 0) {
-               pk_message (0, xcp, "link level protosw error");
-               return ((struct pkcb *)0);
-       }
-
-       /*
-        * Allocate a network control block structure
-        */
-
-       size = sizeof (struct pkcb) + xcp->xc_maxlcn * sizeof (struct pklcd *);
-#ifdef sun
-       if (xcp -> xc_maxlcn < 1 || size > mclbytes) {
-#else
-       if (xcp -> xc_maxlcn < 1 || size > CLBYTES) {
-#endif
-               pk_message (0, xcp, "invalid maxlcn");
-               return ((struct pkcb *)0);
-       }
-       m = m_get (M_DONTWAIT, MT_PCB);
-       if (m == 0)
-               return ((struct pkcb *)0);
-       if (size > MLEN) {
-#ifdef sun
-               if (mclget (m) == 0) {
-                       m_freem (m);
-                       return ((struct pkcb *)0);
-               }
-#else
-#ifdef BSD4_3
-               MCLGET (m);
-               if (m -> m_len != CLBYTES) {
-                       (void) m_free (m);
-                       return ((struct pkcb *)0);
-               }
-#else
-               register struct mbuf *p;
-
-               MCLGET (p, 1);
-               if (p == 0) {
-                       m_freem (m);
-                       return ((struct pkcb *)0);
-               }
-               m -> m_off = (int)p - (int)m;
-#endif
-#endif
-       }
-       pkp = mtod (m, struct pkcb *);
-       bzero ((caddr_t)pkp, size);
-
-       /*
-        * Allocate a logical channel descriptor for lcn 0
-        */
-
-       m = m_getclr (M_DONTWAIT, MT_PCB);
-       if (m == 0) {
-               m_freem (dtom (pkp));
-               return ((struct pkcb *)0);
-       }
-       lcp = mtod (m, struct pklcd *);
-       lcp -> lcd_state = READY;
-       lcp -> lcd_pkp = pkp;
-       pkp -> pk_chan[0] = lcp;
-
-       pkp -> pk_output = pp -> pr_output;
-       pkp -> pk_xcp = xcp;
-       pkp -> pk_state = DTE_WAITING;
-       pkp -> pk_maxlcn = xcp -> xc_maxlcn;
-       pkp -> pk_next = pkcbhead;
-       pkcbhead = pkp;
-
-       /*
-        * set defaults
-        */
-
-       if (xcp -> xc_pwsize == 0)
-               xcp -> xc_pwsize = DEFAULT_WINDOW_SIZE;
-       if (xcp -> xc_psize == 0)
-               xcp -> xc_psize = X25_PS128;
-       return (pkp);
-}
+#include "x25.h"
+#include "pk.h"
+#include "pk_var.h"
 
 /* 
  *  This procedure is called by the link level whenever the link
  *  becomes operational, is reset, or when the link goes down. 
  */
 
 
 /* 
  *  This procedure is called by the link level whenever the link
  *  becomes operational, is reset, or when the link goes down. 
  */
 
-pk_ctlinput (code, xcp)
-struct x25config *xcp;
+pk_ctlinput (code, pkp)
+register struct pkcb *pkp;
 {
 {
-       register struct pkcb *pkp;
 
 
-       for (pkp = pkcbhead; pkp; pkp = pkp -> pk_next)
-               if (pkp -> pk_xcp == xcp)
-                       break;
-
-       if (pkp == 0 && (pkp = pk_newlink (xcp)) == 0)
+       if (pkp == 0)
                return (EINVAL);
                return (EINVAL);
-
        switch (code) {
        case PRC_LINKUP: 
                if (pkp -> pk_state == DTE_WAITING)
        switch (code) {
        case PRC_LINKUP: 
                if (pkp -> pk_state == DTE_WAITING)
@@ -331,12 +239,12 @@ struct x25config *xcp;
                        break;
                }
 
                        break;
                }
 
-               m -> m_off += PKHEADERLN;
+               m -> m_data += PKHEADERLN;
                m -> m_len -= PKHEADERLN;
                if (lcp -> lcd_flags & X25_MQBIT) {
                        octet *t;
 
                m -> m_len -= PKHEADERLN;
                if (lcp -> lcd_flags & X25_MQBIT) {
                        octet *t;
 
-                       m -> m_off -= 1;
+                       m -> m_data -= 1;
                        m -> m_len += 1;
                        t = mtod (m, octet *);
                        *t = 0x00;
                        m -> m_len += 1;
                        t = mtod (m, octet *);
                        *t = 0x00;
@@ -545,10 +453,10 @@ incoming_call (pkp, xp, len)
 struct pkcb *pkp;
 struct x25_packet *xp;
 {
 struct pkcb *pkp;
 struct x25_packet *xp;
 {
-       register struct pklcd *lcp, *l;
+       register struct pklcd *lcp = 0, *l;
        register struct sockaddr_x25 *sa;
        register struct x25_calladdr *a;
        register struct sockaddr_x25 *sa;
        register struct x25_calladdr *a;
-       register struct socket *so;
+       register struct socket *so = 0;
        struct mbuf *m;
        register int l1, l2;
        char *e, *errstr = "server unavailable";
        struct mbuf *m;
        register int l1, l2;
        char *e, *errstr = "server unavailable";
@@ -593,7 +501,8 @@ struct x25_packet *xp;
 
                if (bcmp (sxp -> x25_udata, sa -> x25_udata, sxp->x25_udlen))
                        continue;
 
                if (bcmp (sxp -> x25_udata, sa -> x25_udata, sxp->x25_udlen))
                        continue;
-               if (sxp -> x25_net && sxp -> x25_net != pkp->pk_xcp->xc_net)
+               if (sxp -> x25_net &&
+                   sxp -> x25_net != pkp->pk_xc.xc_addr.x25_net)
                        continue;
                /*
                 * don't accept incoming collect calls unless
                        continue;
                /*
                 * don't accept incoming collect calls unless
@@ -604,8 +513,12 @@ struct x25_packet *xp;
                        errstr = "incoming collect call refused";
                        break;
                }
                        errstr = "incoming collect call refused";
                        break;
                }
-               so = sonewconn (l -> lcd_so);
-               if (so == NULL) {
+               if (l -> lcd_so) {
+                       if (so = sonewconn (l -> lcd_so, SS_ISCONNECTED))
+                                   lcp = (struct pklcd *) so -> so_pcb;
+               } else 
+                       lcp = pk_attach((struct socket *) 0);
+               if (lcp == 0) {
                        /*
                         * Insufficient space or too many unaccepted
                         * connections.  Just throw the call away.
                        /*
                         * Insufficient space or too many unaccepted
                         * connections.  Just throw the call away.
@@ -613,7 +526,8 @@ struct x25_packet *xp;
                        errstr = "server malfunction";
                        break;
                }
                        errstr = "server malfunction";
                        break;
                }
-               lcp = (struct pklcd *) so -> so_pcb;
+               lcp -> lcd_upper = l -> lcd_upper;
+               lcp -> lcd_upnext = l -> lcd_upnext;
                lcp -> lcd_lcn = lcn;
                lcp -> lcd_state = RECEIVED_CALL;
                lcp -> lcd_craddr = sa;
                lcp -> lcd_lcn = lcn;
                lcp -> lcd_state = RECEIVED_CALL;
                lcp -> lcd_craddr = sa;
@@ -621,8 +535,11 @@ struct x25_packet *xp;
                        ~X25_REVERSE_CHARGE;
                pk_assoc (pkp, lcp, sa);
                lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_CALL_ACCEPTED);
                        ~X25_REVERSE_CHARGE;
                pk_assoc (pkp, lcp, sa);
                lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_CALL_ACCEPTED);
-               pk_output (lcp);
-               soisconnected (so);
+               if (so) {
+                       pk_output (lcp);
+                       soisconnected (so);
+               } else if (lcp->lcd_upper)
+                       (*lcp->lcd_upper)(lcp);
                return;
        }
 
                return;
        }