From: niklas Date: Mon, 4 Mar 1996 07:36:20 +0000 (+0000) Subject: From NetBSD: 960217 merge X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e321ea083f58e0d7db3d7a9f0f2e45d2708e93f9;p=openbsd From NetBSD: 960217 merge --- diff --git a/sys/netccitt/ccitt_proto.c b/sys/netccitt/ccitt_proto.c index 4e1e88bb6d0..275a3ea3d0a 100644 --- a/sys/netccitt/ccitt_proto.c +++ b/sys/netccitt/ccitt_proto.c @@ -1,4 +1,5 @@ -/* $NetBSD: ccitt_proto.c,v 1.5 1994/06/29 06:37:00 cgd Exp $ */ +/* $OpenBSD: ccitt_proto.c,v 1.2 1996/03/04 07:36:20 niklas Exp $ */ +/* $NetBSD: ccitt_proto.c,v 1.6 1996/02/13 22:04:21 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -57,36 +58,38 @@ extern struct domain ccittdomain; #define DOMAIN &ccittdomain #ifdef LLC -int llc_output(); -void llc_ctlinput(), llc_init(), llc_timer(); +#include +#include +#include +#include +#include #endif #ifdef HDLC -int hd_output(); -void hd_ctlinput(), hd_init(), hd_timer(); +#include +#include #endif -int pk_usrreq(), pk_ctloutput(); -void pk_timer(), pk_init(), pk_input(), pk_ctlinput(); +#include struct protosw ccittsw[] = { #ifdef LLC - { 0, DOMAIN, IEEEPROTO_802LLC,0, +{ 0, DOMAIN, IEEEPROTO_802LLC,0, 0, llc_output, llc_ctlinput, 0, 0, llc_init, 0, llc_timer, 0, - }, +}, #endif #ifdef HDLC - { 0, DOMAIN, CCITTPROTO_HDLC,0, +{ 0, DOMAIN, CCITTPROTO_HDLC,0, 0, hd_output, hd_ctlinput, 0, 0, hd_init, 0, hd_timer, 0, - }, +}, #endif - { SOCK_STREAM, DOMAIN, CCITTPROTO_X25, PR_CONNREQUIRED|PR_ATOMIC|PR_WANTRCVD, +{ SOCK_STREAM, DOMAIN, CCITTPROTO_X25, PR_CONNREQUIRED|PR_ATOMIC|PR_WANTRCVD, pk_input, 0, pk_ctlinput, pk_ctloutput, pk_usrreq, pk_init, 0, pk_timer, 0, - } +} }; struct domain ccittdomain = diff --git a/sys/netccitt/hd_debug.c b/sys/netccitt/hd_debug.c index e99a77eba2e..ac8fa2cceaa 100644 --- a/sys/netccitt/hd_debug.c +++ b/sys/netccitt/hd_debug.c @@ -1,4 +1,5 @@ -/* $NetBSD: hd_debug.c,v 1.5 1994/06/29 06:37:05 cgd Exp $ */ +/* $OpenBSD: hd_debug.c,v 1.2 1996/03/04 07:36:21 niklas Exp $ */ +/* $NetBSD: hd_debug.c,v 1.6 1996/02/13 22:04:25 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -59,113 +60,116 @@ #ifdef HDLCDEBUG #define NTRACE 32 -struct hdlctrace { - struct hdcb *ht_hdp; - short ht_dir; - struct mbuf *ht_frame; - struct timeval ht_time; -} hdtrace[NTRACE]; +struct hdlctrace { + struct hdcb *ht_hdp; + short ht_dir; + struct mbuf *ht_frame; + struct timeval ht_time; +} hdtrace[NTRACE]; -int lasttracelogged, freezetrace; +int lasttracelogged, freezetrace; #endif -hd_trace (hdp, direction, frame) -struct hdcb *hdp; -register struct Hdlc_frame *frame; +void +hd_trace(hdp, direction, frame) + struct hdcb *hdp; + int direction; + register struct Hdlc_frame *frame; { - register char *s; - register int nr, pf, ns, i; + register char *s; + register int nr, pf, ns, i; struct Hdlc_iframe *iframe = (struct Hdlc_iframe *) frame; #ifdef HDLCDEBUG - hd_savetrace (hdp, direction, frame); + hd_savetrace(hdp, direction, frame); #endif - if (hdp -> hd_xcp -> xc_ltrace) { + if (hdp->hd_xcp->xc_ltrace) { if (direction == RX) - printf ("F-In: "); + printf("F-In: "); else if (direction == 2) - printf ("F-Xmt: "); - else - printf ("F-Out: "); + printf("F-Xmt: "); + else + printf("F-Out: "); - nr = iframe -> nr; - pf = iframe -> pf; - ns = iframe -> ns; + nr = iframe->nr; + pf = iframe->pf; + ns = iframe->ns; - switch (hd_decode (hdp, frame)) { - case SABM: - printf ("SABM : PF=%d\n", pf); + switch (hd_decode(hdp, frame)) { + case SABM: + printf("SABM : PF=%d\n", pf); break; - case DISC: - printf ("DISC : PF=%d\n", pf); + case DISC: + printf("DISC : PF=%d\n", pf); break; - case DM: - printf ("DM : PF=%d\n", pf); + case DM: + printf("DM : PF=%d\n", pf); break; - case FRMR: + case FRMR: { - register struct Frmr_frame *f = (struct Frmr_frame *)frame; - - printf ("FRMR : PF=%d, TEXT=", pf); - for (s = (char *) frame, i = 0; i < 5; ++i, ++s) - printf ("%x ", (int) * s & 0xff); - printf ("\n"); - printf ("control=%x v(s)=%d v(r)=%d w%d x%d y%d z%d\n", - f->frmr_control, f->frmr_ns, f->frmr_nr, + register struct Frmr_frame *f = (struct Frmr_frame *) frame; + + printf("FRMR : PF=%d, TEXT=", pf); + for (s = (char *) frame, i = 0; i < 5; ++i, ++s) + printf("%x ", (int) *s & 0xff); + printf("\n"); + printf("control=%x v(s)=%d v(r)=%d w%d x%d y%d z%d\n", + f->frmr_control, f->frmr_ns, f->frmr_nr, f->frmr_w, f->frmr_x, f->frmr_y, f->frmr_z); - break; + break; } - case UA: - printf ("UA : PF=%d\n", pf); + case UA: + printf("UA : PF=%d\n", pf); break; - case RR: - printf ("RR : N(R)=%d, PF=%d\n", nr, pf); + case RR: + printf("RR : N(R)=%d, PF=%d\n", nr, pf); break; - case RNR: - printf ("RNR : N(R)=%d, PF=%d\n", nr, pf); + case RNR: + printf("RNR : N(R)=%d, PF=%d\n", nr, pf); break; - case REJ: - printf ("REJ : N(R)=%d, PF=%d\n", nr, pf); + case REJ: + printf("REJ : N(R)=%d, PF=%d\n", nr, pf); break; - case IFRAME: + case IFRAME: { - register struct mbuf *m; - register int len = 0; - - for(m = dtom (frame); m; m = m -> m_next) - len += m -> m_len; - len -= HDHEADERLN; - printf ("IFRAME : N(R)=%d, PF=%d, N(S)=%d, DATA(%d)=", - nr, pf, ns, len); - for (s = (char *)iframe->i_field, i = 0; i < 3; ++i, ++s) - printf ("%x ", (int) *s & 0xff); - printf ("\n"); - break; + register struct mbuf *m; + register int len = 0; + + for (m = dtom(frame); m; m = m->m_next) + len += m->m_len; + len -= HDHEADERLN; + printf("IFRAME : N(R)=%d, PF=%d, N(S)=%d, DATA(%d)=", + nr, pf, ns, len); + for (s = (char *) iframe->i_field, i = 0; i < 3; ++i, ++s) + printf("%x ", (int) *s & 0xff); + printf("\n"); + break; } - default: - printf ("ILLEGAL: "); + default: + printf("ILLEGAL: "); for (s = (char *) frame, i = 0; i < 5; ++i, ++s) - printf ("%x ", (int) *s & 0xff); - printf ("\n"); + printf("%x ", (int) *s & 0xff); + printf("\n"); } } } #ifdef HDLCDEBUG -static -hd_savetrace (hdp, dir, frame) -struct hdcb *hdp; -struct Hdlc_frame *frame; +static void +hd_savetrace(hdp, dir, frame) + struct hdcb *hdp; + int dir; + struct Hdlc_frame *frame; { register struct hdlctrace *htp; register struct mbuf *m; @@ -175,40 +179,41 @@ struct Hdlc_frame *frame; htp = &hdtrace[lasttracelogged]; lasttracelogged = (lasttracelogged + 1) % NTRACE; if (m = htp->ht_frame) - m_freem (m); - m = dtom (frame); - htp->ht_frame = m_copy (m, 0, m->m_len); + m_freem(m); + m = dtom(frame); + htp->ht_frame = m_copy(m, 0, m->m_len); htp->ht_hdp = hdp; htp->ht_dir = dir; htp->ht_time = time; } -hd_dumptrace (hdp) -struct hdcb *hdp; +void +hd_dumptrace(hdp) + struct hdcb *hdp; { - register int i, ltrace; + register int i, ltrace; register struct hdlctrace *htp; freezetrace = 1; - hd_status (hdp); - printf ("retransmit queue:"); + hd_status(hdp); + printf("retransmit queue:"); for (i = 0; i < 8; i++) - printf (" %x", hdp -> hd_retxq[i]); - printf ("\n"); - ltrace = hdp -> hd_xcp -> xc_ltrace; - hdp -> hd_xcp -> xc_ltrace = 1; + printf(" %x", hdp->hd_retxq[i]); + printf("\n"); + ltrace = hdp->hd_xcp->xc_ltrace; + hdp->hd_xcp->xc_ltrace = 1; for (i = 0; i < NTRACE; i++) { htp = &hdtrace[(lasttracelogged + i) % NTRACE]; if (htp->ht_hdp != hdp || htp->ht_frame == 0) continue; - printf ("%d/%d ", htp->ht_time.tv_sec & 0xff, - htp->ht_time.tv_usec / 10000); - hd_trace (htp->ht_hdp, htp->ht_dir, - mtod (htp->ht_frame, struct Hdlc_frame *)); - m_freem (htp->ht_frame); + printf("%d/%d ", htp->ht_time.tv_sec & 0xff, + htp->ht_time.tv_usec / 10000); + hd_trace(htp->ht_hdp, htp->ht_dir, + mtod(htp->ht_frame, struct Hdlc_frame *)); + m_freem(htp->ht_frame); htp->ht_frame = 0; } - hdp -> hd_xcp -> xc_ltrace = ltrace; + hdp->hd_xcp->xc_ltrace = ltrace; freezetrace = 0; } #endif diff --git a/sys/netccitt/hd_input.c b/sys/netccitt/hd_input.c index d9511c462a5..51197f98d5a 100644 --- a/sys/netccitt/hd_input.c +++ b/sys/netccitt/hd_input.c @@ -1,4 +1,5 @@ -/* $NetBSD: hd_input.c,v 1.7 1994/06/29 06:37:07 cgd Exp $ */ +/* $OpenBSD: hd_input.c,v 1.2 1996/03/04 07:36:22 niklas Exp $ */ +/* $NetBSD: hd_input.c,v 1.8 1996/02/13 22:04:27 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -55,10 +56,12 @@ #include #include #include +#include + +static void frame_reject __P((struct hdcb *, int, struct Hdlc_iframe *)); +static void rej_routine __P((register struct hdcb *, int)); +static void free_iframes __P((struct hdcb *, int *, int)); -static frame_reject(); -static rej_routine(); -static free_iframes(); /* * HDLC INPUT INTERFACE * @@ -66,25 +69,26 @@ static free_iframes(); * completed reading a frame. */ -hdintr () +void +hdintr() { register struct mbuf *m; register struct hdcb *hdp; register struct ifnet *ifp; - register int s; + register int s; static struct ifnet *lastifp; static struct hdcb *lasthdp; for (;;) { - s = splimp (); - IF_DEQUEUE (&hdintrq, m); - splx (s); + s = splimp(); + IF_DEQUEUE(&hdintrq, m); + splx(s); if (m == 0) break; if (m->m_len < HDHEADERLN) { - printf ("hdintr: packet too short (len=%d)\n", - m->m_len); - m_freem (m); + printf("hdintr: packet too short (len=%d)\n", + m->m_len); + m_freem(m); continue; } if ((m->m_flags & M_PKTHDR) == 0) @@ -102,36 +106,41 @@ hdintr () if (hdp->hd_ifp == ifp) break; if (hdp == 0) { - printf ("hdintr: unknown interface %x\n", ifp); - m_freem (m); + printf("hdintr: unknown interface %x\n", + (unsigned int) ifp); + m_freem(m); continue; } lastifp = ifp; lasthdp = hdp; } - /* Process_rxframe returns FALSE if the frame was NOT queued - for the next higher layers. */ - if (process_rxframe (hdp, m) == FALSE) - m_freem (m); + /* + * Process_rxframe returns FALSE if the frame was NOT queued + * for the next higher layers. + */ + if (process_rxframe(hdp, m) == FALSE) + m_freem(m); } } -process_rxframe (hdp, fbuf) -register struct hdcb *hdp; -register struct mbuf *fbuf; +int +process_rxframe(hdp, fbuf) + register struct hdcb *hdp; + register struct mbuf *fbuf; { - register int queued = FALSE, frametype, pf; + register int queued = FALSE, frametype, pf; register struct Hdlc_frame *frame; + struct sockaddr *sa = (struct sockaddr *) hdp->hd_pkp; - frame = mtod (fbuf, struct Hdlc_frame *); - pf = ((struct Hdlc_iframe *) frame) -> pf; + frame = mtod(fbuf, struct Hdlc_frame *); + pf = ((struct Hdlc_iframe *) frame)->pf; - hd_trace (hdp, RX, frame); - if (frame -> address != ADDRESS_A && frame -> address != ADDRESS_B) + hd_trace(hdp, RX, frame); + if (frame->address != ADDRESS_A && frame->address != ADDRESS_B) return (queued); - switch ((frametype = hd_decode (hdp, frame)) + hdp->hd_state) { + switch ((frametype = hd_decode(hdp, frame)) + hdp->hd_state) { case DM + DISC_SENT: case UA + DISC_SENT: /* @@ -149,196 +158,195 @@ register struct mbuf *fbuf; * that do dynamic link selection. We can't go into the * usual "SEND DM" state because a DM is a SARM in LAP. */ - hd_writeinternal (hdp, SABM, POLLOFF); + hd_writeinternal(hdp, SABM, POLLOFF); hdp->hd_state = SABM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case SABM + DM_SENT: - case SABM + WAIT_SABM: - hd_writeinternal (hdp, UA, pf); - case UA + SABM_SENT: - case UA + WAIT_UA: - KILL_TIMER (hdp); - hd_initvars (hdp); + case SABM + DM_SENT: + case SABM + WAIT_SABM: + hd_writeinternal(hdp, UA, pf); + case UA + SABM_SENT: + case UA + WAIT_UA: + KILL_TIMER(hdp); + hd_initvars(hdp); hdp->hd_state = ABM; - hd_message (hdp, "Link level operational"); + hd_message(hdp, "Link level operational"); /* Notify the packet level - to send RESTART. */ - (void) pk_ctlinput (PRC_LINKUP, hdp->hd_pkp); + (void) pk_ctlinput(PRC_LINKUP, sa, NULL); break; - case SABM + SABM_SENT: - /* Got a SABM collision. Acknowledge the remote's SABM - via UA but still wait for UA. */ - hd_writeinternal (hdp, UA, pf); + case SABM + SABM_SENT: + /* + * Got a SABM collision. Acknowledge the remote's SABM via UA + * but still wait for UA. + */ + hd_writeinternal(hdp, UA, pf); break; - case SABM + ABM: + case SABM + ABM: /* Request to reset the link from the remote. */ - KILL_TIMER (hdp); - hd_message (hdp, "Link reset"); + KILL_TIMER(hdp); + hd_message(hdp, "Link reset"); #ifdef HDLCDEBUG - hd_dumptrace (hdp); + hd_dumptrace(hdp); #endif - hd_flush (hdp->hd_ifp); - hd_writeinternal (hdp, UA, pf); - hd_initvars (hdp); - (void) pk_ctlinput (PRC_LINKRESET, hdp->hd_pkp); + hd_flush(hdp->hd_ifp); + hd_writeinternal(hdp, UA, pf); + hd_initvars(hdp); + (void) pk_ctlinput(PRC_LINKRESET, sa, NULL); hdp->hd_resets++; break; - case SABM + WAIT_UA: - hd_writeinternal (hdp, UA, pf); + case SABM + WAIT_UA: + hd_writeinternal(hdp, UA, pf); break; - case DM + ABM: - hd_message (hdp, "DM received: link down"); + case DM + ABM: + hd_message(hdp, "DM received: link down"); #ifdef HDLCDEBUG - hd_dumptrace (hdp); + hd_dumptrace(hdp); #endif - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); - hd_flush (hdp->hd_ifp); - case DM + DM_SENT: - case DM + WAIT_SABM: - case DM + WAIT_UA: - hd_writeinternal (hdp, SABM, pf); + (void) pk_ctlinput(PRC_LINKDOWN, sa, NULL); + hd_flush(hdp->hd_ifp); + case DM + DM_SENT: + case DM + WAIT_SABM: + case DM + WAIT_UA: + hd_writeinternal(hdp, SABM, pf); hdp->hd_state = SABM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; case DISC + INIT: - case DISC + DM_SENT: - case DISC + SABM_SENT: + case DISC + DM_SENT: + case DISC + SABM_SENT: /* Note: This is a non-standard state change. */ - hd_writeinternal (hdp, UA, pf); - hd_writeinternal (hdp, SABM, POLLOFF); + hd_writeinternal(hdp, UA, pf); + hd_writeinternal(hdp, SABM, POLLOFF); hdp->hd_state = SABM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case DISC + WAIT_UA: - hd_writeinternal (hdp, DM, pf); - SET_TIMER (hdp); + case DISC + WAIT_UA: + hd_writeinternal(hdp, DM, pf); + SET_TIMER(hdp); hdp->hd_state = DM_SENT; break; - case DISC + ABM: - hd_message (hdp, "DISC received: link down"); - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); - case DISC + WAIT_SABM: - hd_writeinternal (hdp, UA, pf); + case DISC + ABM: + hd_message(hdp, "DISC received: link down"); + (void) pk_ctlinput(PRC_LINKDOWN, sa, NULL); + case DISC + WAIT_SABM: + hd_writeinternal(hdp, UA, pf); hdp->hd_state = DM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case UA + ABM: - hd_message (hdp, "UA received: link down"); - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); - case UA + WAIT_SABM: - hd_writeinternal (hdp, DM, pf); + case UA + ABM: + hd_message(hdp, "UA received: link down"); + (void) pk_ctlinput(PRC_LINKDOWN, sa, NULL); + case UA + WAIT_SABM: + hd_writeinternal(hdp, DM, pf); hdp->hd_state = DM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case FRMR + DM_SENT: - hd_writeinternal (hdp, SABM, pf); + case FRMR + DM_SENT: + hd_writeinternal(hdp, SABM, pf); hdp->hd_state = SABM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case FRMR + WAIT_SABM: - hd_writeinternal (hdp, DM, pf); + case FRMR + WAIT_SABM: + hd_writeinternal(hdp, DM, pf); hdp->hd_state = DM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case FRMR + ABM: - hd_message (hdp, "FRMR received: link down"); - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); + case FRMR + ABM: + hd_message(hdp, "FRMR received: link down"); + (void) pk_ctlinput(PRC_LINKDOWN, sa, NULL); #ifdef HDLCDEBUG - hd_dumptrace (hdp); + hd_dumptrace(hdp); #endif - hd_flush (hdp->hd_ifp); - hd_writeinternal (hdp, SABM, pf); + hd_flush(hdp->hd_ifp); + hd_writeinternal(hdp, SABM, pf); hdp->hd_state = WAIT_UA; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case RR + ABM: - case RNR + ABM: - case REJ + ABM: - process_sframe (hdp, (struct Hdlc_sframe *)frame, frametype); + case RR + ABM: + case RNR + ABM: + case REJ + ABM: + process_sframe(hdp, (struct Hdlc_sframe *) frame, frametype); break; - case IFRAME + ABM: - queued = process_iframe (hdp, fbuf, (struct Hdlc_iframe *)frame); + case IFRAME + ABM: + queued = process_iframe(hdp, fbuf, (struct Hdlc_iframe *) frame); break; - case IFRAME + SABM_SENT: - case RR + SABM_SENT: - case RNR + SABM_SENT: - case REJ + SABM_SENT: - hd_writeinternal (hdp, DM, POLLON); + case IFRAME + SABM_SENT: + case RR + SABM_SENT: + case RNR + SABM_SENT: + case REJ + SABM_SENT: + hd_writeinternal(hdp, DM, POLLON); hdp->hd_state = DM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case IFRAME + WAIT_SABM: - case RR + WAIT_SABM: - case RNR + WAIT_SABM: - case REJ + WAIT_SABM: - hd_writeinternal (hdp, FRMR, POLLOFF); - SET_TIMER (hdp); + case IFRAME + WAIT_SABM: + case RR + WAIT_SABM: + case RNR + WAIT_SABM: + case REJ + WAIT_SABM: + hd_writeinternal(hdp, FRMR, POLLOFF); + SET_TIMER(hdp); break; - case ILLEGAL + SABM_SENT: + case ILLEGAL + SABM_SENT: hdp->hd_unknown++; - hd_writeinternal (hdp, DM, POLLOFF); + hd_writeinternal(hdp, DM, POLLOFF); hdp->hd_state = DM_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); break; - case ILLEGAL + ABM: - hd_message (hdp, "Unknown frame received: link down"); - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); + case ILLEGAL + ABM: + hd_message(hdp, "Unknown frame received: link down"); + (void) pk_ctlinput(PRC_LINKDOWN, sa, NULL); case ILLEGAL + WAIT_SABM: hdp->hd_unknown++; #ifdef HDLCDEBUG - hd_dumptrace (hdp); + hd_dumptrace(hdp); #endif - hd_writeinternal (hdp, FRMR, POLLOFF); + hd_writeinternal(hdp, FRMR, POLLOFF); hdp->hd_state = WAIT_SABM; - SET_TIMER (hdp); + SET_TIMER(hdp); break; } return (queued); } -process_iframe (hdp, fbuf, frame) -register struct hdcb *hdp; -struct mbuf *fbuf; -register struct Hdlc_iframe *frame; +int +process_iframe(hdp, fbuf, frame) + register struct hdcb *hdp; + struct mbuf *fbuf; + register struct Hdlc_iframe *frame; { - register int nr = frame -> nr, - ns = frame -> ns, - pf = frame -> pf; + register int nr = frame->nr, ns = frame->ns, pf = frame->pf; register int queued = FALSE; - /* - * Validate the iframe's N(R) value. It's N(R) value must be in - * sync with our V(S) value and our "last received nr". + /* + * Validate the iframe's N(R) value. It's N(R) value must be in sync + * with our V(S) value and our "last received nr". */ - if (valid_nr (hdp, nr, FALSE) == FALSE) { - frame_reject (hdp, Z, frame); + if (valid_nr(hdp, nr, FALSE) == FALSE) { + frame_reject(hdp, Z, frame); return (queued); } - - - /* - * This section tests the IFRAME for proper sequence. That is, it's - * sequence number N(S) MUST be equal to V(S). + /* + * This section tests the IFRAME for proper sequence. That is, it's + * sequence number N(S) MUST be equal to V(S). */ if (ns != hdp->hd_vr) { @@ -355,79 +363,77 @@ register struct Hdlc_iframe *frame; * will cause the DCE to receive two or more * rejects back to back, which must never happen. */ - hd_flush (hdp->hd_ifp); - hd_writeinternal (hdp, REJ, pf); + hd_flush(hdp->hd_ifp); + hd_writeinternal(hdp, REJ, pf); } return (queued); } hdp->hd_condition &= ~REJ_CONDITION; - /* - * This section finally tests the IFRAME's sequence number against - * the window size (K) and the sequence number of the last frame - * we have acknowledged. If the IFRAME is completely correct then - * it is queued for the packet level. + /* + * This section finally tests the IFRAME's sequence number against + * the window size (K) and the sequence number of the last frame we + * have acknowledged. If the IFRAME is completely correct then it is + * queued for the packet level. */ - if (ns != (hdp -> hd_lasttxnr + hdp -> hd_xcp -> xc_lwsize) % MODULUS) { - hdp -> hd_vr = (hdp -> hd_vr + 1) % MODULUS; + if (ns != (hdp->hd_lasttxnr + hdp->hd_xcp->xc_lwsize) % MODULUS) { + hdp->hd_vr = (hdp->hd_vr + 1) % MODULUS; if (pf == 1) { /* Must generate a RR or RNR with final bit on. */ - hd_writeinternal (hdp, RR, POLLON); + hd_writeinternal(hdp, RR, POLLON); } else - /* - * Hopefully we can piggyback the RR, if not we will generate - * a RR when T3 timer expires. + /* + * Hopefully we can piggyback the RR, if not we will + * generate a RR when T3 timer expires. */ - if (hdp -> hd_rrtimer == 0) - hdp->hd_rrtimer = hd_t3; + if (hdp->hd_rrtimer == 0) + hdp->hd_rrtimer = hd_t3; /* Forward iframe to packet level of X.25. */ - fbuf -> m_data += HDHEADERLN; - fbuf -> m_len -= HDHEADERLN; - fbuf -> m_pkthdr.len -= HDHEADERLN; - fbuf -> m_pkthdr.rcvif = (struct ifnet *)hdp -> hd_pkp; + fbuf->m_data += HDHEADERLN; + fbuf->m_len -= HDHEADERLN; + fbuf->m_pkthdr.len -= HDHEADERLN; + fbuf->m_pkthdr.rcvif = (struct ifnet *) hdp->hd_pkp; #ifdef BSD4_3 - fbuf->m_act = 0; /* probably not necessary */ + fbuf->m_act = 0;/* probably not necessary */ #else { register struct mbuf *m; - - for (m = fbuf; m -> m_next; m = m -> m_next) - m -> m_act = (struct mbuf *) 0; - m -> m_act = (struct mbuf *) 1; + + for (m = fbuf; m->m_next; m = m->m_next) + m->m_act = (struct mbuf *) 0; + m->m_act = (struct mbuf *) 1; } #endif - pk_input (fbuf); + pk_input(fbuf); queued = TRUE; - hd_start (hdp); + hd_start(hdp); } else { - /* - * Here if the remote station has transmitted more iframes then - * the number which have been acknowledged plus K. + /* + * Here if the remote station has transmitted more iframes + * then the number which have been acknowledged plus K. */ hdp->hd_invalid_ns++; - frame_reject (hdp, W, frame); + frame_reject(hdp, W, frame); } return (queued); } -/* - * This routine is used to determine if a value (the middle parameter) - * is between two other values. The low value is the first parameter - * the high value is the last parameter. The routine checks the middle - * value to see if it is within the range of the first and last values. - * The reason we need this routine is the values are modulo some base - * hence a simple test for greater or less than is not sufficient. +/* + * This routine is used to determine if a value (the middle parameter) is + * between two other values. The low value is the first parameter the high + * value is the last parameter. The routine checks the middle value to see if + * it is within the range of the first and last values. The reason we need + * this routine is the values are modulo some base hence a simple test for + * greater or less than is not sufficient. */ bool -range_check (rear, value, front) -int rear, - value, - front; +range_check(rear, value, front) + int rear, value, front; { - register bool result = FALSE; + register bool result = FALSE; if (front > rear) result = (rear <= value) && (value <= front); @@ -437,80 +443,81 @@ int rear, return (result); } -/* - * This routine handles all the frame reject conditions which can - * arise as a result of secondary processing. The frame reject - * condition Y (frame length error) are handled elsewhere. +/* + * This routine handles all the frame reject conditions which can arise as a + * result of secondary processing. The frame reject condition Y (frame + * length error) are handled elsewhere. */ -static -frame_reject (hdp, rejectcode, frame) -struct hdcb *hdp; -struct Hdlc_iframe *frame; +static void +frame_reject(hdp, rejectcode, frame) + struct hdcb *hdp; + int rejectcode; + struct Hdlc_iframe *frame; { register struct Frmr_frame *frmr = &hd_frmr; - frmr -> frmr_control = ((struct Hdlc_frame *) frame) -> control; + frmr->frmr_control = ((struct Hdlc_frame *) frame)->control; - frmr -> frmr_ns = frame -> ns; - frmr -> frmr_f1_0 = 0; - frmr -> frmr_nr = frame -> nr; - frmr -> frmr_f2_0 = 0; + frmr->frmr_ns = frame->ns; + frmr->frmr_f1_0 = 0; + frmr->frmr_nr = frame->nr; + frmr->frmr_f2_0 = 0; - frmr -> frmr_0000 = 0; - frmr -> frmr_w = frmr -> frmr_x = frmr -> frmr_y = - frmr -> frmr_z = 0; + frmr->frmr_0000 = 0; + frmr->frmr_w = frmr->frmr_x = frmr->frmr_y = + frmr->frmr_z = 0; switch (rejectcode) { - case Z: - frmr -> frmr_z = 1;/* invalid N(R). */ + case Z: + frmr->frmr_z = 1; /* invalid N(R). */ break; - case Y: - frmr -> frmr_y = 1;/* iframe length error. */ + case Y: + frmr->frmr_y = 1; /* iframe length error. */ break; - case X: - frmr -> frmr_x = 1;/* invalid information field. */ - frmr -> frmr_w = 1; + case X: + frmr->frmr_x = 1; /* invalid information field. */ + frmr->frmr_w = 1; break; - case W: - frmr -> frmr_w = 1;/* invalid N(S). */ + case W: + frmr->frmr_w = 1; /* invalid N(S). */ } - hd_writeinternal (hdp, FRMR, POLLOFF); + hd_writeinternal(hdp, FRMR, POLLOFF); hdp->hd_state = WAIT_SABM; - SET_TIMER (hdp); + SET_TIMER(hdp); } -/* - * This procedure is invoked when ever we receive a supervisor - * frame such as RR, RNR and REJ. All processing for these - * frames is done here. +/* + * This procedure is invoked when ever we receive a supervisor frame such as + * RR, RNR and REJ. All processing for these frames is done here. */ -process_sframe (hdp, frame, frametype) -register struct hdcb *hdp; -register struct Hdlc_sframe *frame; -int frametype; +void +process_sframe(hdp, frame, frametype) + register struct hdcb *hdp; + register struct Hdlc_sframe *frame; + int frametype; { - register int nr = frame -> nr, pf = frame -> pf, pollbit = 0; + register int nr = frame->nr, pf = frame->pf, pollbit = 0; - if (valid_nr (hdp, nr, pf) == TRUE) { + if (valid_nr(hdp, nr, pf) == TRUE) { switch (frametype) { - case RR: + case RR: hdp->hd_condition &= ~REMOTE_RNR_CONDITION; break; - case RNR: + case RNR: hdp->hd_condition |= REMOTE_RNR_CONDITION; hdp->hd_retxcnt = 0; break; - case REJ: + case REJ: hdp->hd_condition &= ~REMOTE_RNR_CONDITION; - rej_routine (hdp, nr); + rej_routine(hdp, nr); } if (pf == 1) { @@ -518,52 +525,59 @@ int frametype; hdp->hd_condition &= ~TIMER_RECOVERY_CONDITION; if (frametype == RR && hdp->hd_lastrxnr == hdp->hd_vs - && hdp->hd_timer == 0 && hdp->hd_txq.head == 0) + && hdp->hd_timer == 0 && hdp->hd_txq.head == 0) hd_writeinternal(hdp, RR, pf); else - /* If any iframes have been queued because of the - timer condition, transmit then now. */ + /* + * If any iframes have been queued because of + * the timer condition, transmit then now. + */ if (hdp->hd_condition & REMOTE_RNR_CONDITION) { - /* Remote is busy or timer condition, so only - send one. */ + /* + * Remote is busy or timer condition, so only + * send one. + */ if (hdp->hd_vs != hdp->hd_retxqi) - hd_send_iframe (hdp, hdp->hd_retxq[hdp->hd_vs], pollbit); - } - else /* Flush the retransmit list first. */ + hd_send_iframe(hdp, + hdp->hd_retxq[(u_char)hdp->hd_vs], + pollbit); + } else /* Flush the retransmit list first. */ while (hdp->hd_vs != hdp->hd_retxqi) - hd_send_iframe (hdp, hdp->hd_retxq[hdp->hd_vs], POLLOFF); + hd_send_iframe(hdp, + hdp->hd_retxq[(u_char)hdp->hd_vs], + POLLOFF); } - - hd_start (hdp); + hd_start(hdp); } else - frame_reject (hdp, Z, (struct Hdlc_iframe *)frame); /* Invalid N(R). */ + frame_reject(hdp, Z, (struct Hdlc_iframe *) frame); /* Invalid N(R). */ } -/* - * This routine tests the validity of the N(R) which we have received. - * If it is ok, then all the iframes which it acknowledges (if any) - * will be freed. +/* + * This routine tests the validity of the N(R) which we have received. If it + * is ok, then all the iframes which it acknowledges (if any) will be + * freed. */ bool -valid_nr (hdp, nr, finalbit) -register struct hdcb *hdp; -register int finalbit; +valid_nr(hdp, nr, finalbit) + register struct hdcb *hdp; + int nr; + register int finalbit; { /* Make sure it really does acknowledge something. */ if (hdp->hd_lastrxnr == nr) return (TRUE); - /* - * This section validates the frame's N(R) value. It's N(R) value - * must be in syncronization with our V(S) value and our "last - * received nr" variable. If it is correct then we are able to send - * more IFRAME's, else frame reject condition is entered. + /* + * This section validates the frame's N(R) value. It's N(R) value + * must be in syncronization with our V(S) value and our "last + * received nr" variable. If it is correct then we are able to send + * more IFRAME's, else frame reject condition is entered. */ - if (range_check (hdp->hd_lastrxnr, nr, hdp->hd_vs) == FALSE) { + if (range_check(hdp->hd_lastrxnr, nr, hdp->hd_vs) == FALSE) { if ((hdp->hd_condition & TIMER_RECOVERY_CONDITION) && - range_check (hdp->hd_vs, nr, hdp->hd_xx) == TRUE) + range_check(hdp->hd_vs, nr, hdp->hd_xx) == TRUE) hdp->hd_vs = nr; else { @@ -571,45 +585,45 @@ register int finalbit; return (FALSE); } } - - /* - * If we get to here, we do have a valid frame but it might be out - * of sequence. However, we should still accept the receive state - * number N(R) since it has already passed our previous test and it - * does acknowledge frames which we are sending. + /* + * If we get to here, we do have a valid frame but it might be out + * of sequence. However, we should still accept the receive state + * number N(R) since it has already passed our previous test and it + * does acknowledge frames which we are sending. */ - KILL_TIMER (hdp); - free_iframes (hdp, &nr, finalbit);/* Free all acknowledged iframes */ + KILL_TIMER(hdp); + free_iframes(hdp, &nr, finalbit); /* Free all acknowledged + * iframes */ if (nr != hdp->hd_vs) - SET_TIMER (hdp); + SET_TIMER(hdp); return (TRUE); } -/* - * This routine determines how many iframes need to be retransmitted. - * It then resets the Send State Variable V(S) to accomplish this. +/* + * This routine determines how many iframes need to be retransmitted. It then + * resets the Send State Variable V(S) to accomplish this. */ -static -rej_routine (hdp, rejnr) -register struct hdcb *hdp; -register int rejnr; +static void +rej_routine(hdp, rejnr) + register struct hdcb *hdp; + register int rejnr; { - register int anchor; + register int anchor; /* * Flush the output queue. Any iframes queued for * transmission will be out of sequence. */ - hd_flush (hdp->hd_ifp); + hd_flush(hdp->hd_ifp); - /* - * Determine how many frames should be re-transmitted. In the case - * of a normal REJ this should be 1 to K. In the case of a timer - * recovery REJ (ie. a REJ with the Final Bit on) this could be 0. + /* + * Determine how many frames should be re-transmitted. In the case of + * a normal REJ this should be 1 to K. In the case of a timer + * recovery REJ (ie. a REJ with the Final Bit on) this could be 0. */ anchor = hdp->hd_vs; @@ -621,50 +635,50 @@ register int rejnr; if (anchor > 0) { /* There is at least one iframe to retransmit. */ - KILL_TIMER (hdp); + KILL_TIMER(hdp); hdp->hd_vs = rejnr; while (hdp->hd_vs != hdp->hd_retxqi) - hd_send_iframe (hdp, hdp->hd_retxq[hdp->hd_vs], POLLOFF); + hd_send_iframe(hdp, hdp->hd_retxq[(u_char)hdp->hd_vs], + POLLOFF); } - hd_start (hdp); + hd_start(hdp); } -/* - * This routine frees iframes from the retransmit queue. It is called - * when a previously written iframe is acknowledged. +/* + * This routine frees iframes from the retransmit queue. It is called when a + * previously written iframe is acknowledged. */ -static -free_iframes (hdp, nr, finalbit) -register struct hdcb *hdp; -int *nr; -register int finalbit; +static void +free_iframes(hdp, nr, finalbit) + register struct hdcb *hdp; + int *nr; + register int finalbit; { register int i, k; - /* - * We need to do the following because of a funny quirk in the - * protocol. This case occures when in Timer recovery condition - * we get a N(R) which acknowledges all the outstanding iframes - * but with the Final Bit off. In this case we need to save the last - * iframe for possible retransmission even though it has already been - * acknowledged! + /* + * We need to do the following because of a funny quirk in the + * protocol. This case occures when in Timer recovery condition + * we get a N(R) which acknowledges all the outstanding iframes + * but with the Final Bit off. In this case we need to save the last + * iframe for possible retransmission even though it has already been + * acknowledged! */ if ((hdp->hd_condition & TIMER_RECOVERY_CONDITION) && *nr == hdp->hd_xx && finalbit == 0) { *nr = (*nr - 1 + 8) % MODULUS; -/* printf ("QUIRK\n"); */ + /* printf ("QUIRK\n"); */ } - k = (*nr - hdp->hd_lastrxnr + 8) % MODULUS; /* Loop here freeing all acknowledged iframes. */ for (i = 0; i < k; ++i) { - m_freem (hdp->hd_retxq[hdp->hd_lastrxnr]); - hdp->hd_retxq[hdp->hd_lastrxnr] = 0; + m_freem(hdp->hd_retxq[(u_char)hdp->hd_lastrxnr]); + hdp->hd_retxq[(u_char)hdp->hd_lastrxnr] = 0; hdp->hd_lastrxnr = (hdp->hd_lastrxnr + 1) % MODULUS; } diff --git a/sys/netccitt/hd_output.c b/sys/netccitt/hd_output.c index d0e5ada43c1..301e36b5e67 100644 --- a/sys/netccitt/hd_output.c +++ b/sys/netccitt/hd_output.c @@ -1,4 +1,5 @@ -/* $NetBSD: hd_output.c,v 1.5 1994/06/29 06:37:11 cgd Exp $ */ +/* $OpenBSD: hd_output.c,v 1.2 1996/03/04 07:36:24 niklas Exp $ */ +/* $NetBSD: hd_output.c,v 1.6 1996/02/13 22:04:29 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -56,33 +57,45 @@ #include #include #include +#include + +#include /* * HDLC OUTPUT INTERFACE * * This routine is called when the X.25 packet layer output routine - * has a information frame (iframe) to write. It is also called + * has a information frame (iframe) to write. It is also called * by the input and control routines of the HDLC layer. */ -hd_output (hdp, m0) -register struct hdcb *hdp; -struct mbuf *m0; +int +#if __STDC__ +hd_output(struct mbuf *m0, ...) +#else +hd_output(m0, va_alist) + struct mbuf *m0; + va_dcl +#endif { - struct x25config *xcp; + register struct hdcb *hdp; register struct mbuf *m = m0; - int len; + int len; + va_list ap; + + va_start(ap, m0); + hdp = va_arg(ap, struct hdcb *); + va_end(ap); if (m == NULL) - panic ("hd_output"); + panic("hd_output"); if ((m->m_flags & M_PKTHDR) == 0) - panic ("hd_output 2"); + panic("hd_output 2"); if (hdp->hd_state != ABM) { - m_freem (m); - return; + m_freem(m); + return 0; } - /* * Make room for the hdlc header either by prepending * another mbuf, or by adjusting the offset and length @@ -91,140 +104,161 @@ struct mbuf *m0; M_PREPEND(m, HDHEADERLN, M_DONTWAIT); if (m == NULL) - return; + return 0; for (len = 0; m; m = m->m_next) len += m->m_len; m = m0; m->m_pkthdr.len = len; - hd_append (&hdp->hd_txq, m); - hd_start (hdp); + hd_append(&hdp->hd_txq, m); + hd_start(hdp); + return 0; } -hd_start (hdp) -register struct hdcb *hdp; +void +hd_start(hdp) + register struct hdcb *hdp; { register struct mbuf *m; - /* + /* * The iframe is only transmitted if all these conditions are FALSE. * The iframe remains queued (hdp->hd_txq) however and will be * transmitted as soon as these conditions are cleared. */ - while (!(hdp->hd_condition & (TIMER_RECOVERY_CONDITION | REMOTE_RNR_CONDITION | REJ_CONDITION))) { - if (hdp->hd_vs == (hdp->hd_lastrxnr + hdp->hd_xcp->xc_lwsize) % MODULUS) { - - /* We have now exceeded the maximum number of - outstanding iframes. Therefore, we must wait - until at least one is acknowledged if this - condition is not turned off before we are - requested to write another iframe. */ + while (!(hdp->hd_condition & (TIMER_RECOVERY_CONDITION | + REMOTE_RNR_CONDITION | REJ_CONDITION))) { + if (hdp->hd_vs == + (hdp->hd_lastrxnr + hdp->hd_xcp->xc_lwsize) % MODULUS) { + + /* + * We have now exceeded the maximum number of + * outstanding iframes. Therefore, we must wait + * until at least one is acknowledged if this + * condition is not turned off before we are + * requested to write another iframe. + */ hdp->hd_window_condition++; break; } - /* hd_remove top iframe from transmit queue. */ - if ((m = hd_remove (&hdp->hd_txq)) == NULL) + if ((m = hd_remove(&hdp->hd_txq)) == NULL) break; - hd_send_iframe (hdp, m, POLLOFF); + hd_send_iframe(hdp, m, POLLOFF); } } -/* - * This procedure is passed a buffer descriptor for an iframe. It builds - * the rest of the control part of the frame and then writes it out. It - * also starts the acknowledgement timer and keeps the iframe in the - * Retransmit queue (Retxq) just in case we have to do this again. - * - * Note: This routine is also called from hd_input.c when retransmission - * of old frames is required. +/* + * This procedure is passed a buffer descriptor for an iframe. It builds the + * rest of the control part of the frame and then writes it out. It also + * starts the acknowledgement timer and keeps the iframe in the Retransmit + * queue (Retxq) just in case we have to do this again. + * + * Note: This routine is also called from hd_input.c when retransmission of old + * frames is required. */ - -hd_send_iframe (hdp, buf, poll_bit) -register struct hdcb *hdp; -register struct mbuf *buf; -int poll_bit; +void +hd_send_iframe(hdp, buf, poll_bit) + register struct hdcb *hdp; + register struct mbuf *buf; + int poll_bit; { register struct Hdlc_iframe *iframe; - struct mbuf *m; + struct mbuf *m; - KILL_TIMER (hdp); + KILL_TIMER(hdp); if (buf == 0) { - printf ("hd_send_iframe: zero arg\n"); + printf("hd_send_iframe: zero arg\n"); #ifdef HDLCDEBUG - hd_status (hdp); - hd_dumptrace (hdp); + hd_status(hdp); + hd_dumptrace(hdp); #endif hdp->hd_vs = (hdp->hd_vs + 7) % MODULUS; return; } - iframe = mtod (buf, struct Hdlc_iframe *); + iframe = mtod(buf, struct Hdlc_iframe *); - iframe -> hdlc_0 = 0; - iframe -> nr = hdp->hd_vr; - iframe -> pf = poll_bit; - iframe -> ns = hdp->hd_vs; - iframe -> address = ADDRESS_B; + iframe->hdlc_0 = 0; + iframe->nr = hdp->hd_vr; + iframe->pf = poll_bit; + iframe->ns = hdp->hd_vs; + iframe->address = ADDRESS_B; hdp->hd_lasttxnr = hdp->hd_vr; hdp->hd_rrtimer = 0; if (hdp->hd_vs == hdp->hd_retxqi) { /* Check for retransmissions. */ /* Put iframe only once in the Retransmission queue. */ - hdp->hd_retxq[hdp->hd_retxqi] = buf; + hdp->hd_retxq[(u_char) hdp->hd_retxqi] = buf; hdp->hd_retxqi = (hdp->hd_retxqi + 1) % MODULUS; hdp->hd_iframes_out++; } - hdp->hd_vs = (hdp->hd_vs + 1) % MODULUS; - hd_trace (hdp, TX, (struct Hdlc_frame *)iframe); + hd_trace(hdp, TX, (struct Hdlc_frame *) iframe); /* Write buffer on device. */ - m = hdp->hd_dontcopy ? buf : m_copy(buf, 0, (int)M_COPYALL); + m = hdp->hd_dontcopy ? buf : m_copy(buf, 0, (int) M_COPYALL); if (m == 0) { printf("hdlc: out of mbufs\n"); return; } - (*hdp->hd_output)(hdp, m); - SET_TIMER (hdp); + (*hdp->hd_output) (m, hdp); + SET_TIMER(hdp); } -hd_ifoutput(hdp, m) -register struct mbuf *m; -register struct hdcb *hdp; +int +#if __STDC__ +hd_ifoutput(struct mbuf *m, ...) +#else +hd_ifoutput(m, va_alist) + struct mbuf *m; + va_dcl +#endif { + register struct hdcb *hdp; + register struct ifnet *ifp; + int s = splimp(); + va_list ap; + + va_start(ap, m); + hdp = va_arg(ap, struct hdcb *); + va_end(ap); + ifp = hdp->hd_ifp; + /* * Queue message on interface, and start output if interface * not yet active. */ - register struct ifnet *ifp = hdp->hd_ifp; - int s = splimp(); if (IF_QFULL(&ifp->if_snd)) { IF_DROP(&ifp->if_snd); - /* printf("%s%d: HDLC says OK to send but queue full, may hang\n", - ifp->if_name, ifp->if_unit);*/ + /* + * printf("%s%d: HDLC says OK to send but queue full, may + * hang\n", ifp->if_name, ifp->if_unit); + */ m_freem(m); } else { IF_ENQUEUE(&ifp->if_snd, m); if ((ifp->if_flags & IFF_OACTIVE) == 0) - (*ifp->if_start)(ifp); + (*ifp->if_start) (ifp); } splx(s); + return 0; } -/* - * This routine gets control when the timer expires because we have not - * received an acknowledgement for a iframe. +/* + * This routine gets control when the timer expires because we have not + * received an acknowledgement for a iframe. */ -hd_resend_iframe (hdp) -register struct hdcb *hdp; +void +hd_resend_iframe(hdp) + register struct hdcb *hdp; { if (hdp->hd_retxcnt++ < hd_n2) { @@ -232,18 +266,20 @@ register struct hdcb *hdp; hdp->hd_xx = hdp->hd_vs; hdp->hd_condition |= TIMER_RECOVERY_CONDITION; } - hdp->hd_vs = hdp->hd_lastrxnr; - hd_send_iframe (hdp, hdp->hd_retxq[hdp->hd_vs], POLLON); + hd_send_iframe(hdp, hdp->hd_retxq[(u_char)hdp->hd_vs], POLLON); } else { - /* At this point we have not received a RR even after N2 - retries - attempt to reset link. */ + /* + * At this point we have not received a RR even after N2 + * retries - attempt to reset link. + */ - hd_initvars (hdp); - hd_writeinternal (hdp, SABM, POLLOFF); + hd_initvars(hdp); + hd_writeinternal(hdp, SABM, POLLOFF); hdp->hd_state = WAIT_UA; - SET_TIMER (hdp); - hd_message (hdp, "Timer recovery failed: link down"); - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); + SET_TIMER(hdp); + hd_message(hdp, "Timer recovery failed: link down"); + (void) pk_ctlinput(PRC_LINKDOWN, + (struct sockaddr *)hdp->hd_pkp, NULL); } } diff --git a/sys/netccitt/hd_subr.c b/sys/netccitt/hd_subr.c index db8ec819296..e53954e594a 100644 --- a/sys/netccitt/hd_subr.c +++ b/sys/netccitt/hd_subr.c @@ -1,4 +1,5 @@ -/* $NetBSD: hd_subr.c,v 1.5 1994/06/29 06:37:13 cgd Exp $ */ +/* $OpenBSD: hd_subr.c,v 1.2 1996/03/04 07:36:25 niklas Exp $ */ +/* $NetBSD: hd_subr.c,v 1.6 1996/02/13 22:04:31 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -57,50 +58,53 @@ #include #include #include +#include -hd_init () +void +hd_init() { hdintrq.ifq_maxlen = IFQ_MAXLEN; } -hd_ctlinput (prc, addr) -struct sockaddr *addr; +void * +hd_ctlinput(prc, addr, ext) + int prc; + struct sockaddr *addr; + void *ext; { - register struct x25config *xcp = (struct x25config *)addr; + register struct x25config *xcp = (struct x25config *) addr; register struct hdcb *hdp; register struct ifaddr *ifa; - struct ifnet *ifp; - caddr_t pk_newlink(); + struct ifnet *ifp; if (addr->sa_family != AF_CCITT) - return (EAFNOSUPPORT); + return (void *) (EAFNOSUPPORT); if (xcp->xc_lptype != HDLCPROTO_LAPB) - return (EPROTONOSUPPORT); + return (void *) (EPROTONOSUPPORT); ifa = ifa_ifwithaddr(addr); if (ifa == 0 || ifa->ifa_addr->sa_family != AF_CCITT || (ifp = ifa->ifa_ifp) == 0) - panic ("hd_ctlinput"); + panic("hd_ctlinput"); for (hdp = hdcbhead; hdp; hdp = hdp->hd_next) if (hdp->hd_ifp == ifp) break; if (hdp == 0) { /* new interface */ - int error, hd_ifoutput(), hd_output(); /* an hdcb is now too big to fit in an mbuf */ - MALLOC(hdp, struct hdcb *, sizeof (*hdp), M_PCB, M_DONTWAIT); + MALLOC(hdp, struct hdcb *, sizeof(*hdp), M_PCB, M_DONTWAIT); if (hdp == 0) - return (ENOBUFS); - bzero((caddr_t)hdp, sizeof(*hdp)); + return (void *) (ENOBUFS); + bzero((caddr_t) hdp, sizeof(*hdp)); hdp->hd_pkp = - (caddr_t) pk_newlink ((struct x25_ifaddr *) ifa, - (caddr_t) hdp); - ((struct x25_ifaddr *)ifa)->ia_pkcb = + (caddr_t) pk_newlink((struct x25_ifaddr *) ifa, + (caddr_t) hdp); + ((struct x25_ifaddr *) ifa)->ia_pkcb = (struct pkcb *) hdp->hd_pkp; - if (hdp -> hd_pkp == 0) { + if (hdp->hd_pkp == 0) { free(hdp, M_PCB); - return (ENOBUFS); + return (void *) (ENOBUFS); } hdp->hd_ifp = ifp; hdp->hd_ifa = ifa; @@ -109,60 +113,61 @@ struct sockaddr *addr; hdp->hd_output = hd_ifoutput; hdp->hd_next = hdcbhead; hdcbhead = hdp; - } else if (hdp->hd_pkp == 0) { /* interface got reconfigured */ + } else if (hdp->hd_pkp == 0) { /* interface got reconfigured */ hdp->hd_pkp = - (caddr_t) pk_newlink ((struct x25_ifaddr *) ifa, - (caddr_t) hdp); - ((struct x25_ifaddr *)ifa)->ia_pkcb = + (caddr_t) pk_newlink((struct x25_ifaddr *) ifa, + (caddr_t) hdp); + ((struct x25_ifaddr *) ifa)->ia_pkcb = (struct pkcb *) hdp->hd_pkp; - if (hdp -> hd_pkp == 0) { + if (hdp->hd_pkp == 0) { free(hdp, M_PCB); - return (ENOBUFS); + return (void *) (ENOBUFS); } } - switch (prc) { case PRC_IFUP: if (xcp->xc_lwsize == 0 || - xcp->xc_lwsize > MAX_WINDOW_SIZE) - xcp->xc_lwsize = MAX_WINDOW_SIZE; + xcp->xc_lwsize > MAX_WINDOW_SIZE) + xcp->xc_lwsize = MAX_WINDOW_SIZE; if (hdp->hd_state == INIT) - SET_TIMER (hdp); + SET_TIMER(hdp); break; case PRC_IFDOWN: if (hdp->hd_state == ABM) - hd_message (hdp, "Operator shutdown: link closed"); - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); + hd_message(hdp, "Operator shutdown: link closed"); + (void) pk_ctlinput(PRC_LINKDOWN, + (struct sockaddr *) hdp->hd_pkp, NULL); /* fall thru to ... */ case PRC_DISCONNECT_REQUEST: /* drop reference to pkcb --- it's dead meat */ hdp->hd_pkp = (caddr_t) 0; - ((struct x25_ifaddr *)ifa)->ia_pkcb = (struct pkcb *) 0; + ((struct x25_ifaddr *) ifa)->ia_pkcb = (struct pkcb *) 0; - hd_writeinternal (hdp, DISC, POLLON); + hd_writeinternal(hdp, DISC, POLLON); hdp->hd_state = DISC_SENT; - SET_TIMER (hdp); + SET_TIMER(hdp); } - return (0); + return (void *) (0); } -hd_initvars (hdp) -register struct hdcb *hdp; +void +hd_initvars(hdp) + register struct hdcb *hdp; { register struct mbuf *m; - register int i; + register int i; /* Clear Transmit queue. */ - while ((m = hd_remove (&hdp->hd_txq)) != NULL) - m_freem (m); + while ((m = hd_remove(&hdp->hd_txq)) != NULL) + m_freem(m); /* Clear Retransmit queue. */ i = hdp->hd_lastrxnr; while (i != hdp->hd_retxqi) { - m_freem (hdp->hd_retxq[i]); + m_freem(hdp->hd_retxq[i]); i = (i + 1) % MODULUS; } hdp->hd_retxqi = 0; @@ -175,58 +180,56 @@ register struct hdcb *hdp; hdp->hd_condition = 0; } -hd_decode (hdp, frame) -register struct hdcb *hdp; -struct Hdlc_frame *frame; +int +hd_decode(hdp, frame) + register struct hdcb *hdp; + struct Hdlc_frame *frame; { - register int frametype = ILLEGAL; + register int frametype = ILLEGAL; register struct Hdlc_iframe *iframe = (struct Hdlc_iframe *) frame; register struct Hdlc_sframe *sframe = (struct Hdlc_sframe *) frame; register struct Hdlc_uframe *uframe = (struct Hdlc_uframe *) frame; - if (iframe -> hdlc_0 == 0) { + if (iframe->hdlc_0 == 0) { frametype = IFRAME; hdp->hd_iframes_in++; - } - - else if (sframe -> hdlc_01 == 1) { + } else if (sframe->hdlc_01 == 1) { /* Supervisory format. */ - switch (sframe -> s2) { - case 0: + switch (sframe->s2) { + case 0: frametype = RR; hdp->hd_rrs_in++; break; - case 1: + case 1: frametype = RNR; hdp->hd_rnrs_in++; break; - case 2: + case 2: frametype = REJ; hdp->hd_rejs_in++; } - } - else if (uframe -> hdlc_11 == 3) { + } else if (uframe->hdlc_11 == 3) { /* Unnumbered format. */ - switch (uframe -> m3) { - case 0: + switch (uframe->m3) { + case 0: frametype = DM; break; - case 1: + case 1: frametype = SABM; break; - case 2: + case 2: frametype = DISC; break; - case 3: + case 3: frametype = UA; break; - case 4: + case 4: frametype = FRMR; hdp->hd_frmrs_in++; } @@ -234,160 +237,162 @@ struct Hdlc_frame *frame; return (frametype); } -/* - * This routine is called when the HDLC layer internally generates a - * command or response for the remote machine ( eg. RR, UA etc. ). - * Only supervisory or unnumbered frames are processed. +/* + * This routine is called when the HDLC layer internally generates a command + * or response for the remote machine ( eg. RR, UA etc. ). Only + * supervisory or unnumbered frames are processed. */ -hd_writeinternal (hdp, frametype, pf) -register struct hdcb *hdp; -register int frametype, pf; +void +hd_writeinternal(hdp, frametype, pf) + register struct hdcb *hdp; + register int frametype, pf; { register struct mbuf *buf; struct Hdlc_frame *frame; register struct Hdlc_sframe *sframe; register struct Hdlc_uframe *uframe; - MGETHDR (buf, M_DONTWAIT, MT_HEADER); + MGETHDR(buf, M_DONTWAIT, MT_HEADER); if (buf == 0) return; - frame = mtod (buf, struct Hdlc_frame *); - sframe = mtod (buf, struct Hdlc_sframe *); - uframe = mtod (buf, struct Hdlc_uframe *); + frame = mtod(buf, struct Hdlc_frame *); + sframe = mtod(buf, struct Hdlc_sframe *); + uframe = mtod(buf, struct Hdlc_uframe *); /* Assume a response - address structure for DTE */ - frame -> address = ADDRESS_A; - buf -> m_len = 2; - buf -> m_act = buf -> m_next = NULL; + frame->address = ADDRESS_A; + buf->m_len = 2; + buf->m_act = buf->m_next = NULL; switch (frametype) { - case RR: - frame -> control = RR_CONTROL; + case RR: + frame->control = RR_CONTROL; hdp->hd_rrs_out++; break; - case RNR: - frame -> control = RNR_CONTROL; + case RNR: + frame->control = RNR_CONTROL; hdp->hd_rnrs_out++; break; - case REJ: - frame -> control = REJ_CONTROL; + case REJ: + frame->control = REJ_CONTROL; hdp->hd_rejs_out++; break; - case SABM: - frame -> control = SABM_CONTROL; - frame -> address = ADDRESS_B; + case SABM: + frame->control = SABM_CONTROL; + frame->address = ADDRESS_B; break; - case DISC: + case DISC: if ((hdp->hd_ifp->if_flags & IFF_UP) == 0) { hdp->hd_state = DISCONNECTED; - (void) m_freem (buf); - hd_flush (hdp->hd_ifp); + (void) m_freem(buf); + hd_flush(hdp->hd_ifp); return; } - frame -> control = DISC_CONTROL; - frame -> address = ADDRESS_B; + frame->control = DISC_CONTROL; + frame->address = ADDRESS_B; break; - case DM: - frame -> control = DM_CONTROL; + case DM: + frame->control = DM_CONTROL; break; - case UA: - frame -> control = UA_CONTROL; + case UA: + frame->control = UA_CONTROL; break; - case FRMR: - frame -> control = FRMR_CONTROL; - bcopy ((caddr_t)&hd_frmr, (caddr_t)frame -> info, 3); - buf -> m_len = 5; + case FRMR: + frame->control = FRMR_CONTROL; + bcopy((caddr_t) & hd_frmr, (caddr_t) frame->info, 3); + buf->m_len = 5; hdp->hd_frmrs_out++; } - if (sframe -> hdlc_01 == 1) { + if (sframe->hdlc_01 == 1) { /* Supervisory format - RR, REJ, or RNR. */ - sframe -> nr = hdp->hd_vr; - sframe -> pf = pf; + sframe->nr = hdp->hd_vr; + sframe->pf = pf; hdp->hd_lasttxnr = hdp->hd_vr; hdp->hd_rrtimer = 0; - } - else - uframe -> pf = pf; + } else + uframe->pf = pf; - hd_trace (hdp, TX, frame); - buf -> m_pkthdr.len = buf -> m_len; - (*hdp->hd_output) (hdp, buf); + hd_trace(hdp, TX, frame); + buf->m_pkthdr.len = buf->m_len; + (*hdp->hd_output) (buf, hdp, NULL); } struct mbuf * -hd_remove (q) -struct hdtxq *q; +hd_remove(q) + struct hdtxq *q; { register struct mbuf *m; - m = q -> head; + m = q->head; if (m) { - if ((q -> head = m -> m_act) == NULL) - q -> tail = NULL; - m -> m_act = 0; + if ((q->head = m->m_act) == NULL) + q->tail = NULL; + m->m_act = 0; } return (m); } -hd_append (q, m) -register struct hdtxq *q; -register struct mbuf *m; +void +hd_append(q, m) + register struct hdtxq *q; + register struct mbuf *m; { - m -> m_act = NULL; - if (q -> tail == NULL) - q -> head = m; + m->m_act = NULL; + if (q->tail == NULL) + q->head = m; else - q -> tail -> m_act = m; - q -> tail = m; + q->tail->m_act = m; + q->tail = m; } -hd_flush (ifp) -struct ifnet *ifp; +void +hd_flush(ifp) + struct ifnet *ifp; { register struct mbuf *m; - register int s; + register int s; while (1) { - s = splimp (); - IF_DEQUEUE (&ifp->if_snd, m); - splx (s); + s = splimp(); + IF_DEQUEUE(&ifp->if_snd, m); + splx(s); if (m == 0) break; - m_freem (m); + m_freem(m); } } -hd_message (hdp, msg) -struct hdcb *hdp; -char *msg; +void +hd_message(hdp, msg) + struct hdcb *hdp; + char *msg; { - char *format_ntn (); - - if (hdcbhead -> hd_next) - printf ("HDLC(%s): %s\n", format_ntn (hdp->hd_xcp), msg); + if (hdcbhead->hd_next) + printf("HDLC(%s): %s\n", format_ntn(hdp->hd_xcp), msg); else - printf ("HDLC: %s\n", msg); + printf("HDLC: %s\n", msg); } #ifdef HDLCDEBUG -hd_status (hdp) -struct hdcb *hdp; +void +hd_status(hdp) + struct hdcb *hdp; { - printf ("HDLC STATUS:\n V(S)=%d, V(R)=%d, retxqi=%d,\n", - hdp->hd_vs, hdp->hd_vr, hdp->hd_retxqi); + printf("HDLC STATUS:\n V(S)=%d, V(R)=%d, retxqi=%d,\n", + hdp->hd_vs, hdp->hd_vr, hdp->hd_retxqi); - printf ("Last_rx_nr=%d, Last_tx_nr=%d,\n Condition=%d, Xx=%d\n", - hdp->hd_lastrxnr, hdp->hd_lasttxnr, hdp->hd_condition, hdp->hd_xx); + printf("Last_rx_nr=%d, Last_tx_nr=%d,\n Condition=%d, Xx=%d\n", + hdp->hd_lastrxnr, hdp->hd_lasttxnr, hdp->hd_condition, hdp->hd_xx); } #endif diff --git a/sys/netccitt/hd_timer.c b/sys/netccitt/hd_timer.c index 8f934ff5436..fe453a5f2d3 100644 --- a/sys/netccitt/hd_timer.c +++ b/sys/netccitt/hd_timer.c @@ -1,4 +1,5 @@ -/* $NetBSD: hd_timer.c,v 1.5 1994/06/29 06:37:15 cgd Exp $ */ +/* $OpenBSD: hd_timer.c,v 1.2 1996/03/04 07:36:26 niklas Exp $ */ +/* $NetBSD: hd_timer.c,v 1.6 1996/02/13 22:04:33 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -55,82 +56,84 @@ #include #include #include +#include /* * these can be patched with adb if the * default values are inappropriate */ -int hd_t1 = T1; -int hd_t3 = T3; -int hd_n2 = N2; +int hd_t1 = T1; +int hd_t3 = T3; +int hd_n2 = N2; /* - * HDLC TIMER + * HDLC TIMER * * This routine is called every 500ms by the kernel. Decrement timer by this * amount - if expired then process the event. */ -hd_timer () +void +hd_timer() { register struct hdcb *hdp; - register int s = splimp (); + register int s = splimp(); for (hdp = hdcbhead; hdp; hdp = hdp->hd_next) { if (hdp->hd_rrtimer && (--hdp->hd_rrtimer == 0)) { if (hdp->hd_lasttxnr != hdp->hd_vr) - hd_writeinternal (hdp, RR, POLLOFF); + hd_writeinternal(hdp, RR, POLLOFF); } - if (!(hdp->hd_timer && --hdp->hd_timer == 0)) continue; switch (hdp->hd_state) { - case INIT: + case INIT: case DISC_SENT: - hd_writeinternal (hdp, DISC, POLLON); + hd_writeinternal(hdp, DISC, POLLON); break; - case ABM: + case ABM: if (hdp->hd_lastrxnr != hdp->hd_vs) { /* XXX */ hdp->hd_timeouts++; - hd_resend_iframe (hdp); + hd_resend_iframe(hdp); } break; - case WAIT_SABM: - hd_writeinternal (hdp, FRMR, POLLOFF); + case WAIT_SABM: + hd_writeinternal(hdp, FRMR, POLLOFF); if (++hdp->hd_retxcnt == hd_n2) { hdp->hd_retxcnt = 0; - hd_writeinternal (hdp, SABM, POLLOFF); + hd_writeinternal(hdp, SABM, POLLOFF); hdp->hd_state = WAIT_UA; } break; - case DM_SENT: + case DM_SENT: if (++hdp->hd_retxcnt == hd_n2) { /* Notify the packet level. */ - (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp); + (void) pk_ctlinput(PRC_LINKDOWN, + (struct sockaddr *) hdp->hd_pkp, NULL); hdp->hd_retxcnt = 0; hdp->hd_state = SABM_SENT; - hd_writeinternal (hdp, SABM, POLLOFF); + hd_writeinternal(hdp, SABM, POLLOFF); } else - hd_writeinternal (hdp, DM, POLLOFF); + hd_writeinternal(hdp, DM, POLLOFF); break; - case WAIT_UA: + case WAIT_UA: if (++hdp->hd_retxcnt == hd_n2) { hdp->hd_retxcnt = 0; - hd_writeinternal (hdp, DM, POLLOFF); + hd_writeinternal(hdp, DM, POLLOFF); hdp->hd_state = DM_SENT; } else - hd_writeinternal (hdp, SABM, POLLOFF); + hd_writeinternal(hdp, SABM, POLLOFF); break; - case SABM_SENT: + case SABM_SENT: /* Do this indefinitely. */ - hd_writeinternal (hdp, SABM, POLLON); + hd_writeinternal(hdp, SABM, POLLON); break; case DISCONNECTED: @@ -142,8 +145,8 @@ hd_timer () hdp->hd_state = INIT; } - SET_TIMER (hdp); + SET_TIMER(hdp); } - splx (s); + splx(s); } diff --git a/sys/netccitt/hd_var.h b/sys/netccitt/hd_var.h index 5a511da4d2c..ae1076c78c0 100644 --- a/sys/netccitt/hd_var.h +++ b/sys/netccitt/hd_var.h @@ -1,4 +1,5 @@ -/* $NetBSD: hd_var.h,v 1.6 1995/03/26 20:33:44 jtc Exp $ */ +/* $OpenBSD: hd_var.h,v 1.2 1996/03/04 07:36:27 niklas Exp $ */ +/* $NetBSD: hd_var.h,v 1.7 1996/02/13 22:04:34 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -76,7 +77,8 @@ struct hdcb { struct ifaddr *hd_ifa; /* device's X.25 network address */ struct x25config *hd_xcp; caddr_t hd_pkp; /* Level III junk */ - int (*hd_output)(); /* separate entry for HDLC direct output */ + int (*hd_output) /* separate entry for HDLC direct output */ + __P((struct mbuf *, ...)); /* link statistics */ @@ -102,8 +104,47 @@ struct hdcb { struct hdcb *hdcbhead; /* head of linked list of hdcb's */ struct Frmr_frame hd_frmr; /* rejected frame diagnostic info */ struct ifqueue hdintrq; /* hdlc packet input queue */ +struct Hdlc_frame; +struct Hdlc_iframe; +struct Hdlc_sframe; int hd_t1; /* timer T1 value */ int hd_t3; /* RR send timer */ int hd_n2; /* frame retransmission limit */ + + +/* hd_debug.c */ +void hd_trace __P((struct hdcb *, int , struct Hdlc_frame *)); +int hd_dumptrace __P((struct hdcb *)); + +/* hd_input.c */ +void hdintr __P((void)); +int process_rxframe __P((struct hdcb *, struct mbuf *)); +int process_iframe __P((struct hdcb *, struct mbuf *, struct Hdlc_iframe *)); +bool range_check __P((int, int , int )); +void process_sframe __P((struct hdcb *, struct Hdlc_sframe *, int)); +bool valid_nr __P((struct hdcb *, int , int)); + +/* hd_output.c */ +int hd_output __P((struct mbuf *, ...)); +void hd_start __P((struct hdcb *)); +void hd_send_iframe __P((struct hdcb *, struct mbuf *, int)); +int hd_ifoutput __P((struct mbuf *, ...)); +void hd_resend_iframe __P((struct hdcb *)); + +/* hd_subr.c */ +void hd_init __P((void)); +void *hd_ctlinput __P((int , struct sockaddr *, void *)); +void hd_initvars __P((struct hdcb *)); +int hd_decode __P((struct hdcb *, struct Hdlc_frame *)); +void hd_writeinternal __P((struct hdcb *, int, int )); +void hd_append __P((struct hdtxq *, struct mbuf *)); +void hd_flush __P((struct ifnet *)); +void hd_message __P((struct hdcb *, char *)); +int hd_status __P((struct hdcb *)); +struct mbuf *hd_remove __P((struct hdtxq *)); + +/* hd_timer.c */ +void hd_timer __P((void)); + #endif diff --git a/sys/netccitt/hdlc.h b/sys/netccitt/hdlc.h index ace9af41cc9..6955ce6278f 100644 --- a/sys/netccitt/hdlc.h +++ b/sys/netccitt/hdlc.h @@ -1,4 +1,5 @@ -/* $NetBSD: hdlc.h,v 1.5 1994/06/29 06:37:17 cgd Exp $ */ +/* $OpenBSD: hdlc.h,v 1.2 1996/03/04 07:36:28 niklas Exp $ */ +/* $NetBSD: hdlc.h,v 1.6 1996/02/13 22:04:37 christos Exp $ */ /*- * Copyright (c) University of British Columbia, 1984 @@ -41,10 +42,13 @@ */ #ifndef ORDER4 +#ifndef CCITT_TYPES_DEFINED +#define CCITT_TYPES_DEFINED #define FALSE 0 #define TRUE 1 typedef u_char octet; typedef char bool; +#endif /* * HDLC Packet format definitions @@ -152,7 +156,3 @@ struct Hdlc_frame { #define TX 0 #define RX 1 - -bool range_check (); -bool valid_nr (); -struct mbuf *hd_remove (); diff --git a/sys/netccitt/if_x25subr.c b/sys/netccitt/if_x25subr.c index 42b15f0621c..ade9f558b48 100644 --- a/sys/netccitt/if_x25subr.c +++ b/sys/netccitt/if_x25subr.c @@ -1,4 +1,5 @@ -/* $NetBSD: if_x25subr.c,v 1.11 1995/06/15 22:38:20 cgd Exp $ */ +/* $OpenBSD: if_x25subr.c,v 1.2 1996/03/04 07:36:29 niklas Exp $ */ +/* $NetBSD: if_x25subr.c,v 1.12 1996/02/13 22:04:39 christos Exp $ */ /* * Copyright (c) 1990, 1993 @@ -55,6 +56,7 @@ #include #include #include +#include #ifdef INET #include @@ -67,11 +69,15 @@ #endif #ifdef ISO -int tp_incoming(); #include #include #include +#ifdef TPCONS +#include +#include #endif +#endif + LIST_HEAD(, llinfo_x25) llinfo_x25; #ifndef _offsetof @@ -79,34 +85,37 @@ LIST_HEAD(, llinfo_x25) llinfo_x25; #endif struct sockaddr *x25_dgram_sockmask; struct sockaddr_x25 x25_dgmask = { - _offsetof(struct sockaddr_x25, x25_udata[1]), /* _len */ - 0, /* _family */ - 0, /* _net */ - { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* _addr */ - {0}, /* opts */ - -1, /* _udlen */ - {-1} /* _udata */ + _offsetof(struct sockaddr_x25, x25_udata[1]), /* _len */ + 0, /* _family */ + 0, /* _net */ + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* _addr */ + {0}, /* opts */ + -1, /* _udlen */ + {-1} /* _udata */ }; - + struct if_x25stats { - int ifx_wrongplen; - int ifx_nophdr; + int ifx_wrongplen; + int ifx_nophdr; } if_x25stats; int x25_autoconnect = 0; #define senderr(x) {error = x; goto bad;} + +static struct llinfo_x25 *x25_lxalloc __P((struct rtentry *)); + /* * Ancillary routines */ static struct llinfo_x25 * x25_lxalloc(rt) -register struct rtentry *rt; + register struct rtentry *rt; { register struct llinfo_x25 *lx; register struct sockaddr *dst = rt_key(rt); register struct ifaddr *ifa; - MALLOC(lx, struct llinfo_x25 *, sizeof (*lx), M_PCB, M_NOWAIT); + MALLOC(lx, struct llinfo_x25 *, sizeof(*lx), M_PCB, M_NOWAIT); if (lx == 0) return lx; Bzero(lx, sizeof(*lx)); @@ -115,20 +124,22 @@ register struct rtentry *rt; rt->rt_refcnt++; if (rt->rt_llinfo) { LIST_INSERT_AFTER( - (struct llinfo_x25 *)rt->rt_llinfo, lx, lx_list); + (struct llinfo_x25 *) rt->rt_llinfo, lx, lx_list); } else { - rt->rt_llinfo = (caddr_t)lx; + rt->rt_llinfo = (caddr_t) lx; LIST_INSERT_HEAD(&llinfo_x25, lx, lx_list); } for (ifa = rt->rt_ifp->if_addrlist.tqh_first; ifa != 0; - ifa = ifa->ifa_list.tqe_next) { + ifa = ifa->ifa_list.tqe_next) { if (ifa->ifa_addr->sa_family == AF_CCITT) - lx->lx_ia = (struct x25_ifaddr *)ifa; + lx->lx_ia = (struct x25_ifaddr *) ifa; } return lx; } + +void x25_lxfree(lx) -register struct llinfo_x25 *lx; + register struct llinfo_x25 *lx; { register struct rtentry *rt = lx->lx_rt; register struct pklcd *lcp = lx->lx_lcd; @@ -137,8 +148,8 @@ register struct llinfo_x25 *lx; lcp->lcd_upper = 0; pk_disconnect(lcp); } - if ((rt->rt_llinfo == (caddr_t)lx) && (lx->lx_list.le_next->lx_rt == rt)) - rt->rt_llinfo = (caddr_t)lx->lx_list.le_next; + if ((rt->rt_llinfo == (caddr_t) lx) && (lx->lx_list.le_next->lx_rt == rt)) + rt->rt_llinfo = (caddr_t) lx->lx_list.le_next; else rt->rt_llinfo = 0; RTFREE(rt); @@ -148,31 +159,32 @@ register struct llinfo_x25 *lx; /* * Process a x25 packet as datagram; */ -x25_ifinput(lcp, m) -struct pklcd *lcp; -register struct mbuf *m; +int +x25_ifinput(m, v) + register struct mbuf *m; + void *v; { - struct llinfo_x25 *lx = (struct llinfo_x25 *)lcp->lcd_upnext; + struct pklcd *lcp = v; + struct llinfo_x25 *lx = (struct llinfo_x25 *) lcp->lcd_upnext; register struct ifnet *ifp; struct ifqueue *inq; extern struct timeval time; - int s, len, isr; - - if (m == 0 || lcp->lcd_state != DATA_TRANSFER) { - x25_connect_callback(lcp, 0); - return; - } - pk_flowcontrol(lcp, 0, 1); /* Generate RR */ + int s, isr; + + if (m == 0 || lcp->lcd_state != DATA_TRANSFER) + return x25_connect_callback(NULL, lcp); + + pk_flowcontrol(lcp, 0, 1); /* Generate RR */ ifp = m->m_pkthdr.rcvif; ifp->if_lastchange = time; switch (m->m_type) { default: if (m) m_freem(m); - return; + return 0; case MT_DATA: - /* FALLTHROUGH */; + /* FALLTHROUGH */ ; } switch (lx->lx_family) { #ifdef INET @@ -198,7 +210,7 @@ register struct mbuf *m; default: m_freem(m); ifp->if_noproto++; - return; + return 0; } s = splimp(); schednetisr(isr); @@ -210,13 +222,17 @@ register struct mbuf *m; ifp->if_ibytes += m->m_pkthdr.len; } splx(s); + return 0; } -x25_connect_callback(lcp, m) -register struct pklcd *lcp; -register struct mbuf *m; + +int +x25_connect_callback(m, v) + register struct mbuf *m; + void *v; { - register struct llinfo_x25 *lx = (struct llinfo_x25 *)lcp->lcd_upnext; - int do_clear = 1; + register struct pklcd *lcp = v; + register struct llinfo_x25 *lx = (struct llinfo_x25 *) lcp->lcd_upnext; + int do_clear = 1; if (m == 0) goto refused; if (m->m_type != MT_CONTROL) { @@ -224,43 +240,46 @@ register struct mbuf *m; goto refused; } switch (pk_decode(mtod(m, struct x25_packet *))) { - case CALL_ACCEPTED: + case PK_CALL_ACCEPTED: lcp->lcd_upper = x25_ifinput; if (lcp->lcd_sb.sb_mb) - lcp->lcd_send(lcp); /* XXX start queued packets */ - return; + lcp->lcd_send(lcp); /* XXX start queued packets */ + return 0; default: do_clear = 0; - refused: +refused: lcp->lcd_upper = 0; lx->lx_lcd = 0; if (do_clear) pk_disconnect(lcp); - return; + return 0; } } + + #define SA(p) ((struct sockaddr *)(p)) #define RT(p) ((struct rtentry *)(p)) -x25_dgram_incoming(lcp, m0) -register struct pklcd *lcp; -struct mbuf *m0; +int +x25_dgram_incoming(m0, v) + struct mbuf *m0; + void *v; { + register struct pklcd *lcp = v; register struct rtentry *rt, *nrt; - register struct mbuf *m = m0->m_next; /* m0 has calling sockaddr_x25 */ - void x25_rtrequest(); - + register struct mbuf *m = m0->m_next; /* m0 has calling + * sockaddr_x25 */ rt = rtalloc1(SA(&lcp->lcd_faddr), 0); if (rt == 0) { -refuse: lcp->lcd_upper = 0; +refuse: lcp->lcd_upper = 0; pk_close(lcp); - return; + return 0; } rt->rt_refcnt--; if ((nrt = RT(rt->rt_llinfo)) == 0 || rt_mask(rt) != x25_dgram_sockmask) goto refuse; if ((nrt->rt_flags & RTF_UP) == 0) { - rt->rt_llinfo = (caddr_t)rtalloc1(rt->rt_gateway, 0); + rt->rt_llinfo = (caddr_t) rtalloc1(rt->rt_gateway, 0); rtfree(nrt); if ((nrt = RT(rt->rt_llinfo)) == 0) goto refuse; @@ -268,36 +287,38 @@ refuse: lcp->lcd_upper = 0; } if (nrt->rt_ifa == 0 || nrt->rt_ifa->ifa_rtrequest != x25_rtrequest) goto refuse; - lcp->lcd_send(lcp); /* confirm call */ + lcp->lcd_send(lcp); /* confirm call */ x25_rtattach(lcp, nrt); m_freem(m); + return 0; } /* * X.25 output routine. */ +int x25_ifoutput(ifp, m0, dst, rt) -struct ifnet *ifp; -struct mbuf *m0; -struct sockaddr *dst; -register struct rtentry *rt; + struct ifnet *ifp; + struct mbuf *m0; + struct sockaddr *dst; + register struct rtentry *rt; { - register struct mbuf *m = m0; - register struct llinfo_x25 *lx; - struct pklcd *lcp; - int s, error = 0; + register struct mbuf *m = m0; + register struct llinfo_x25 *lx; + struct pklcd *lcp; + int error = 0; -int plen; -for (plen = 0; m; m = m->m_next) - plen += m->m_len; -m = m0; + int plen; + for (plen = 0; m; m = m->m_next) + plen += m->m_len; + m = m0; if ((ifp->if_flags & IFF_UP) == 0) senderr(ENETDOWN); while (rt == 0 || (rt->rt_flags & RTF_GATEWAY)) { if (rt) { if (rt->rt_llinfo) { - rt = (struct rtentry *)rt->rt_llinfo; + rt = (struct rtentry *) rt->rt_llinfo; continue; } dst = rt->rt_gateway; @@ -311,29 +332,29 @@ m = m0; */ if ((rt->rt_ifp != ifp) || (rt->rt_flags & (RTF_CLONING | RTF_GATEWAY)) || - ((lx = (struct llinfo_x25 *)rt->rt_llinfo) == 0)) { + ((lx = (struct llinfo_x25 *) rt->rt_llinfo) == 0)) { senderr(ENETUNREACH); } -if ((m->m_flags & M_PKTHDR) == 0) { - if_x25stats.ifx_nophdr++; - m = m_gethdr(M_NOWAIT, MT_HEADER); - if (m == 0) - senderr(ENOBUFS); - m->m_pkthdr.len = plen; - m->m_next = m0; -} -if (plen != m->m_pkthdr.len) { - if_x25stats.ifx_wrongplen++; - m->m_pkthdr.len = plen; -} + if ((m->m_flags & M_PKTHDR) == 0) { + if_x25stats.ifx_nophdr++; + m = m_gethdr(M_NOWAIT, MT_HEADER); + if (m == 0) + senderr(ENOBUFS); + m->m_pkthdr.len = plen; + m->m_next = m0; + } + if (plen != m->m_pkthdr.len) { + if_x25stats.ifx_wrongplen++; + m->m_pkthdr.len = plen; + } next_circuit: lcp = lx->lx_lcd; if (lcp == 0) { - lx->lx_lcd = lcp = pk_attach((struct socket *)0); + lx->lx_lcd = lcp = pk_attach((struct socket *) 0); if (lcp == 0) senderr(ENOBUFS); lcp->lcd_upper = x25_connect_callback; - lcp->lcd_upnext = (caddr_t)lx; + lcp->lcd_upnext = (caddr_t) lx; lcp->lcd_packetsize = lx->lx_ia->ia_xc.xc_psize; lcp->lcd_flags = X25_MBS_HOLD; } @@ -348,7 +369,7 @@ next_circuit: senderr(EHOSTUNREACH); } else if (x25_autoconnect) error = pk_connect(lcp, - (struct sockaddr_x25 *)rt->rt_gateway); + (struct sockaddr_x25 *) rt->rt_gateway); if (error) senderr(error); /* FALLTHROUGH */ @@ -362,8 +383,8 @@ next_circuit: } if (lx->lx_ia) lcp->lcd_dg_timer = - lx->lx_ia->ia_xc.xc_dg_idletimo; - pk_send(lcp, m); + lx->lx_ia->ia_xc.xc_dg_idletimo; + pk_send(m, lcp); break; default: /* @@ -380,7 +401,7 @@ next_circuit: * under heavy load. */ error = ENOBUFS; - bad: +bad: if (m) m_freem(m); } @@ -390,22 +411,23 @@ next_circuit: /* * Simpleminded timer routine. */ +void x25_iftimeout(ifp) -struct ifnet *ifp; + struct ifnet *ifp; { register struct pkcb *pkcb = 0; register struct pklcd **lcpp, *lcp; - int s = splimp(); + int s = splimp(); FOR_ALL_PKCBS(pkcb) - if (pkcb->pk_ia->ia_ifp == ifp) + if (pkcb->pk_ia->ia_ifp == ifp) for (lcpp = pkcb->pk_chan + pkcb->pk_maxlcn; --lcpp > pkcb->pk_chan;) if ((lcp = *lcpp) && lcp->lcd_state == DATA_TRANSFER && (lcp->lcd_flags & X25_DG_CIRCUIT) && - (lcp->lcd_dg_timer && --lcp->lcd_dg_timer == 0)) { - lcp->lcd_upper(lcp, 0); + (lcp->lcd_dg_timer && --lcp->lcd_dg_timer == 0)) { + (*lcp->lcd_upper)(NULL, lcp); } splx(s); } @@ -415,32 +437,32 @@ struct ifnet *ifp; */ void x25_rtrequest(cmd, rt, dst) + int cmd; register struct rtentry *rt; struct sockaddr *dst; { - register struct llinfo_x25 *lx = (struct llinfo_x25 *)rt->rt_llinfo; - register struct sockaddr_x25 *sa =(struct sockaddr_x25 *)rt->rt_gateway; + register struct llinfo_x25 *lx = (struct llinfo_x25 *) rt->rt_llinfo; register struct pklcd *lcp; - /* would put this pk_init, except routing table doesn't - exist yet. */ + /* + * would put this pk_init, except routing table doesn't exist yet. + */ if (x25_dgram_sockmask == 0) { - struct radix_node *rn_addmask(); x25_dgram_sockmask = - SA(rn_addmask((caddr_t)&x25_dgmask, 0, 4)->rn_key); + SA(rn_addmask((caddr_t) & x25_dgmask, 0, 4)->rn_key); } if (rt->rt_flags & RTF_GATEWAY) { if (rt->rt_llinfo) - RTFREE((struct rtentry *)rt->rt_llinfo); - rt->rt_llinfo = (cmd == RTM_ADD) ? - (caddr_t)rtalloc1(rt->rt_gateway, 1) : 0; + RTFREE((struct rtentry *) rt->rt_llinfo); + rt->rt_llinfo = (cmd == RTM_ADD) ? + (caddr_t) rtalloc1(rt->rt_gateway, 1) : 0; return; } if ((rt->rt_flags & RTF_HOST) == 0) return; if (cmd == RTM_DELETE) { while (rt->rt_llinfo) - x25_lxfree((struct llinfo *)rt->rt_llinfo); + x25_lxfree((struct llinfo_x25 *) rt->rt_llinfo); x25_rtinvert(RTM_DELETE, rt->rt_gateway, rt); return; } @@ -453,8 +475,9 @@ x25_rtrequest(cmd, rt, dst) */ if (lcp->lcd_ceaddr && Bcmp(rt->rt_gateway, lcp->lcd_ceaddr, - lcp->lcd_ceaddr->x25_len) != 0) { - x25_rtinvert(RTM_DELETE, lcp->lcd_ceaddr, rt); + lcp->lcd_ceaddr->x25_len) != 0) { + x25_rtinvert(RTM_DELETE, + (struct sockaddr *) lcp->lcd_ceaddr, rt); lcp->lcd_upper = 0; pk_disconnect(lcp); } @@ -465,9 +488,11 @@ x25_rtrequest(cmd, rt, dst) int x25_dont_rtinvert = 0; +void x25_rtinvert(cmd, sa, rt) -register struct sockaddr *sa; -register struct rtentry *rt; + int cmd; + register struct sockaddr *sa; + register struct rtentry *rt; { struct rtentry *rt2 = 0; /* @@ -481,7 +506,7 @@ register struct rtentry *rt; return; if (cmd != RTM_DELETE) { rtrequest(RTM_ADD, sa, rt_key(rt), x25_dgram_sockmask, - RTF_PROTO2, &rt2); + RTF_PROTO2, &rt2); if (rt2) { rt2->rt_llinfo = (caddr_t) rt; rt->rt_refcnt++; @@ -491,13 +516,13 @@ register struct rtentry *rt; rt2 = rt; if ((rt = rtalloc1(sa, 0)) == 0 || (rt->rt_flags & RTF_PROTO2) == 0 || - rt->rt_llinfo != (caddr_t)rt2) { + rt->rt_llinfo != (caddr_t) rt2) { printf("x25_rtchange: inverse route screwup\n"); return; } else rt2->rt_refcnt--; rtrequest(RTM_DELETE, sa, rt_key(rt2), x25_dgram_sockmask, - 0, (struct rtentry **) 0); + 0, (struct rtentry **) 0); } static struct sockaddr_x25 blank_x25 = {sizeof blank_x25, AF_CCITT}; @@ -507,60 +532,61 @@ static struct sockaddr_x25 blank_x25 = {sizeof blank_x25, AF_CCITT}; union imp_addr { struct in_addr ip; struct imp { - u_char s_net; - u_char s_host; - u_char s_lh; - u_char s_impno; - } imp; + u_char s_net; + u_char s_host; + u_char s_lh; + u_char s_impno; + } imp; }; /* * The following is totally bogus and here only to preserve * the IP to X.25 translation. */ +void x25_ddnip_to_ccitt(src, rt) -struct sockaddr_in *src; -register struct rtentry *rt; + struct sockaddr *src; + register struct rtentry *rt; { - register struct sockaddr_x25 *dst = (struct sockaddr_x25 *)rt->rt_gateway; - union imp_addr imp_addr; + register struct sockaddr_x25 *dst = (struct sockaddr_x25 *) rt->rt_gateway; + union imp_addr imp_addr; int imp_no, imp_port, temp; - char *x25addr = dst->x25_addr; + char *x25addr = dst->x25_addr; - imp_addr.ip = src->sin_addr; + imp_addr.ip = ((struct sockaddr_in *) src)->sin_addr; *dst = blank_x25; if ((imp_addr.imp.s_net & 0x80) == 0x00) { /* class A */ - imp_no = imp_addr.imp.s_impno; - imp_port = imp_addr.imp.s_host; + imp_no = imp_addr.imp.s_impno; + imp_port = imp_addr.imp.s_host; } else if ((imp_addr.imp.s_net & 0xc0) == 0x80) { /* class B */ - imp_no = imp_addr.imp.s_impno; - imp_port = imp_addr.imp.s_lh; + imp_no = imp_addr.imp.s_impno; + imp_port = imp_addr.imp.s_lh; } else { /* class C */ - imp_no = imp_addr.imp.s_impno / 32; - imp_port = imp_addr.imp.s_impno % 32; + imp_no = imp_addr.imp.s_impno / 32; + imp_port = imp_addr.imp.s_impno % 32; } - x25addr[0] = 12; /* length */ + x25addr[0] = 12; /* length */ /* DNIC is cleared by struct copy above */ if (imp_port < 64) { /* Physical: 0000 0 IIIHH00 [SS] *//* s_impno - * -> III, s_host -> HH */ - x25addr[5] = 0; /* set flag bit */ - x25addr[6] = imp_no / 100; - x25addr[7] = (imp_no % 100) / 10; - x25addr[8] = imp_no % 10; - x25addr[9] = imp_port / 10; - x25addr[10] = imp_port % 10; + * -> III, s_host -> HH */ + x25addr[5] = 0; /* set flag bit */ + x25addr[6] = imp_no / 100; + x25addr[7] = (imp_no % 100) / 10; + x25addr[8] = imp_no % 10; + x25addr[9] = imp_port / 10; + x25addr[10] = imp_port % 10; } else { /* Logical: 0000 1 RRRRR00 [SS] *//* s * _host * 256 + s_impno -> RRRRR */ - temp = (imp_port << 8) + imp_no; - x25addr[5] = 1; - x25addr[6] = temp / 10000; - x25addr[7] = (temp % 10000) / 1000; - x25addr[8] = (temp % 1000) / 100; - x25addr[9] = (temp % 100) / 10; - x25addr[10] = temp % 10; + temp = (imp_port << 8) + imp_no; + x25addr[5] = 1; + x25addr[6] = temp / 10000; + x25addr[7] = (temp % 10000) / 1000; + x25addr[8] = (temp % 1000) / 100; + x25addr[9] = (temp % 100) / 10; + x25addr[10] = temp % 10; } } @@ -570,100 +596,105 @@ register struct rtentry *rt; * This is a utility routine to be called by x25 devices when a * call request is honored with the intent of starting datagram forwarding. */ +void x25_dg_rtinit(dst, ia, af) -struct sockaddr_x25 *dst; -register struct x25_ifaddr *ia; + struct sockaddr_x25 *dst; + register struct x25_ifaddr *ia; + int af; { struct sockaddr *sa = 0; struct rtentry *rt; - struct in_addr my_addr; + struct in_addr my_addr; static struct sockaddr_in sin = {sizeof(sin), AF_INET}; if (ia->ia_ifp->if_type == IFT_X25DDN && af == AF_INET) { - /* - * Inverse X25 to IP mapping copyright and courtesy ACC. - */ - int imp_no, imp_port, temp; - union imp_addr imp_addr; - { /* - * First determine our IP addr for network + * Inverse X25 to IP mapping copyright and courtesy ACC. */ - register struct in_ifaddr *ina; + int imp_no, imp_port, temp; + union imp_addr imp_addr; + { + /* + * First determine our IP addr for network + */ + register struct in_ifaddr *ina; + + for (ina = in_ifaddr.tqh_first; ina != 0; + ina = ina->ia_list.tqe_next) + if (ina->ia_ifp == ia->ia_ifp) { + my_addr = ina->ia_addr.sin_addr; + break; + } + } + { + + register char *x25addr = dst->x25_addr; + + switch (x25addr[5] & 0x0f) { + case 0:/* Physical: 0000 0 IIIHH00 [SS] */ + imp_no = + ((int) (x25addr[6] & 0x0f) * 100) + + ((int) (x25addr[7] & 0x0f) * 10) + + ((int) (x25addr[8] & 0x0f)); + - for (ina = in_ifaddr.tqh_first; ina != 0; - ina = ina->ia_list.tqe_next) - if (ina->ia_ifp == ia->ia_ifp) { - my_addr = ina->ia_addr.sin_addr; + imp_port = + ((int) (x25addr[9] & 0x0f) * 10) + + ((int) (x25addr[10] & 0x0f)); break; + case 1:/* Logical: 0000 1 RRRRR00 [SS] */ + temp = ((int) (x25addr[6] & 0x0f) * 10000) + + ((int) (x25addr[7] & 0x0f) * 1000) + + ((int) (x25addr[8] & 0x0f) * 100) + + ((int) (x25addr[9] & 0x0f) * 10) + + ((int) (x25addr[10] & 0x0f)); + + imp_port = temp >> 8; + imp_no = temp & 0xff; + break; + default: + return; + } + imp_addr.ip = my_addr; + if ((imp_addr.imp.s_net & 0x80) == 0x00) { + /* class A */ + imp_addr.imp.s_host = imp_port; + imp_addr.imp.s_impno = imp_no; + imp_addr.imp.s_lh = 0; + } else if ((imp_addr.imp.s_net & 0xc0) == 0x80) { + /* class B */ + imp_addr.imp.s_lh = imp_port; + imp_addr.imp.s_impno = imp_no; + } else { + /* class C */ + imp_addr.imp.s_impno = (imp_no << 5) + imp_port; } - } - { - - register char *x25addr = dst->x25_addr; - - switch (x25addr[5] & 0x0f) { - case 0: /* Physical: 0000 0 IIIHH00 [SS] */ - imp_no = - ((int) (x25addr[6] & 0x0f) * 100) + - ((int) (x25addr[7] & 0x0f) * 10) + - ((int) (x25addr[8] & 0x0f)); - - - imp_port = - ((int) (x25addr[9] & 0x0f) * 10) + - ((int) (x25addr[10] & 0x0f)); - break; - case 1: /* Logical: 0000 1 RRRRR00 [SS] */ - temp = ((int) (x25addr[6] & 0x0f) * 10000) - + ((int) (x25addr[7] & 0x0f) * 1000) - + ((int) (x25addr[8] & 0x0f) * 100) - + ((int) (x25addr[9] & 0x0f) * 10) - + ((int) (x25addr[10] & 0x0f)); - - imp_port = temp >> 8; - imp_no = temp & 0xff; - break; - default: - return (0L); - } - imp_addr.ip = my_addr; - if ((imp_addr.imp.s_net & 0x80) == 0x00) { - /* class A */ - imp_addr.imp.s_host = imp_port; - imp_addr.imp.s_impno = imp_no; - imp_addr.imp.s_lh = 0; - } else if ((imp_addr.imp.s_net & 0xc0) == 0x80) { - /* class B */ - imp_addr.imp.s_lh = imp_port; - imp_addr.imp.s_impno = imp_no; - } else { - /* class C */ - imp_addr.imp.s_impno = (imp_no << 5) + imp_port; } - } sin.sin_addr = imp_addr.ip; - sa = (struct sockaddr *)&sin; + sa = (struct sockaddr *) & sin; } else { /* * This uses the X25 routing table to do inverse * lookup of x25 address to sockaddr. */ - if (rt = rtalloc1(SA(dst), 0)) { + if ((rt = rtalloc1(SA(dst), 0)) != NULL) { sa = rt->rt_gateway; rt->rt_refcnt--; } } - /* - * Call to rtalloc1 will create rtentry for reverse path - * to callee by virtue of cloning magic and will allocate - * space for local control block. + /* + * Call to rtalloc1 will create rtentry for reverse path to callee by + * virtue of cloning magic and will allocate space for local control + * block. */ if (sa && (rt = rtalloc1(sa, 1))) rt->rt_refcnt--; } + + int x25_startproto = 1; +void pk_init() { /* @@ -677,35 +708,36 @@ pk_init() } struct x25_dgproto { - u_char spi; - u_char spilen; - int (*f)(); + u_char spi; + u_char spilen; + int (*f) __P((struct mbuf *, void *)); } x25_dgprototab[] = { #if defined(ISO) && defined(TPCONS) -{ 0x0, 0, tp_incoming}, + { 0x0, 0, tp_incoming }, #endif -{ 0xcc, 1, x25_dgram_incoming}, -{ 0xcd, 1, x25_dgram_incoming}, -{ 0x81, 1, x25_dgram_incoming}, + { 0xcc, 1, x25_dgram_incoming }, + { 0xcd, 1, x25_dgram_incoming }, + { 0x81, 1, x25_dgram_incoming }, }; +int pk_user_protolisten(info) -register u_char *info; + register u_char *info; { register struct x25_dgproto *dp = x25_dgprototab - + ((sizeof x25_dgprototab) / (sizeof *dp)); + + ((sizeof x25_dgprototab) / (sizeof *dp)); register struct pklcd *lcp; - + while (dp > x25_dgprototab) if ((--dp)->spi == info[0]) goto gotspi; return ESRCH; -gotspi: if (info[1]) +gotspi:if (info[1]) return pk_protolisten(dp->spi, dp->spilen, dp->f); for (lcp = pk_listenhead; lcp; lcp = lcp->lcd_listen) if (lcp->lcd_laddr.x25_udlen == dp->spilen && - Bcmp(&dp->spi, lcp->lcd_laddr.x25_udata, dp->spilen) == 0) { + Bcmp(&dp->spi, lcp->lcd_laddr.x25_udata, dp->spilen) == 0) { pk_disconnect(lcp); return 0; } @@ -718,32 +750,33 @@ gotspi: if (info[1]) * routing entry. If freshly allocated, it glues back the vc from * the rtentry to the socket. */ +int pk_rtattach(so, m0) -register struct socket *so; -struct mbuf *m0; + register struct socket *so; + struct mbuf *m0; { - register struct pklcd *lcp = (struct pklcd *)so->so_pcb; + register struct pklcd *lcp = (struct pklcd *) so->so_pcb; register struct mbuf *m = m0; struct sockaddr *dst = mtod(m, struct sockaddr *); register struct rtentry *rt = rtalloc1(dst, 0); register struct llinfo_x25 *lx; - caddr_t cp; + caddr_t cp; #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) #define transfer_sockbuf(s, f, l) \ - while (m = (s)->sb_mb)\ - {(s)->sb_mb = m->m_act; m->m_act = 0; sbfree((s), m); f(l, m);} + while ((m = (s)->sb_mb) != NULL) \ + {(s)->sb_mb = m->m_act; m->m_act = 0; sbfree((s), m); f;} if (rt) rt->rt_refcnt--; - cp = (dst->sa_len < m->m_len) ? ROUNDUP(dst->sa_len) + (caddr_t)dst : 0; + cp = (dst->sa_len < m->m_len) ? ROUNDUP(dst->sa_len) + (caddr_t) dst : 0; while (rt && ((cp == 0 && rt_mask(rt) != 0) || (cp != 0 && (rt_mask(rt) == 0 || - Bcmp(cp, rt_mask(rt), rt_mask(rt)->sa_len)) != 0))) - rt = (struct rtentry *)rt->rt_nodes->rn_dupedkey; + Bcmp(cp, rt_mask(rt), rt_mask(rt)->sa_len)) != 0))) + rt = (struct rtentry *) rt->rt_nodes->rn_dupedkey; if (rt == 0 || (rt->rt_flags & RTF_GATEWAY) || - (lx = (struct llinfo_x25 *)rt->rt_llinfo) == 0) + (lx = (struct llinfo_x25 *) rt->rt_llinfo) == 0) return ESRCH; if (lcp == 0) return ENOTCONN; @@ -763,32 +796,35 @@ struct mbuf *m0; lcp->lcd_so = so; lcp->lcd_upper = 0; lcp->lcd_upnext = 0; - transfer_sockbuf(&lcp->lcd_sb, sbappendrecord, &so->so_snd); + transfer_sockbuf(&lcp->lcd_sb, sbappendrecord(&so->so_snd, m), + &so->so_snd); soisconnected(so); return 0; case DATA_TRANSFER: /* Add VC to rtentry */ lcp->lcd_so = 0; - lcp->lcd_sb = so->so_snd; /* structure copy */ - bzero((caddr_t)&so->so_snd, sizeof(so->so_snd)); /* XXXXXX */ + lcp->lcd_sb = so->so_snd; /* structure copy */ + bzero((caddr_t) & so->so_snd, sizeof(so->so_snd)); /* XXXXXX */ so->so_pcb = 0; x25_rtattach(lcp, rt); - transfer_sockbuf(&so->so_rcv, x25_ifinput, lcp); + transfer_sockbuf(&so->so_rcv, x25_ifinput(m, lcp), lcp); soisdisconnected(so); } return 0; } + +int x25_rtattach(lcp0, rt) -register struct pklcd *lcp0; -struct rtentry *rt; + register struct pklcd *lcp0; + struct rtentry *rt; { - register struct llinfo_x25 *lx = (struct llinfo_x25 *)rt->rt_llinfo; + register struct llinfo_x25 *lx = (struct llinfo_x25 *) rt->rt_llinfo; register struct pklcd *lcp; register struct mbuf *m; - if (lcp = lx->lx_lcd) { /* adding an additional VC */ + if ((lcp = lx->lx_lcd) != NULL) { /* adding an additional VC */ if (lcp->lcd_state == READY) { - transfer_sockbuf(&lcp->lcd_sb, pk_output, lcp0); + transfer_sockbuf(&lcp->lcd_sb, pk_output(lcp0), lcp0); lcp->lcd_upper = 0; pk_close(lcp); } else { @@ -799,5 +835,6 @@ struct rtentry *rt; } lx->lx_lcd = lcp = lcp0; lcp->lcd_upper = x25_ifinput; - lcp->lcd_upnext = (caddr_t)lx; + lcp->lcd_upnext = (caddr_t) lx; + return 0; } diff --git a/sys/netccitt/llc_input.c b/sys/netccitt/llc_input.c index 1ee073b03dc..7bc5ea257a9 100644 --- a/sys/netccitt/llc_input.c +++ b/sys/netccitt/llc_input.c @@ -1,4 +1,5 @@ -/* $NetBSD: llc_input.c,v 1.2 1994/06/29 06:37:21 cgd Exp $ */ +/* $OpenBSD: llc_input.c,v 1.2 1996/03/04 07:36:30 niklas Exp $ */ +/* $NetBSD: llc_input.c,v 1.3 1996/02/13 22:04:44 christos Exp $ */ /* * Copyright (C) Dirk Husemann, Computer Science Department IV, @@ -59,6 +60,8 @@ #include #include +#include + /* * This module implements LLC as specified by ISO 8802-2. */ @@ -76,11 +79,9 @@ llcintr() register int frame_kind; register u_char cmdrsp; struct llc_linkcb *linkp; - struct rtentry *sirt; - struct npaidbentry *sapinfo; + struct npaidbentry *sapinfo = NULL; struct sdl_hdr *sdlhdr; struct llc *frame; - char *c; long expected_len; struct ifnet *ifp; @@ -180,10 +181,12 @@ llcintr() */ cmdrsp = (frame->llc_ssap & 0x01); frame->llc_ssap &= ~0x01; - if (llrt = rtalloc1((struct sockaddr *)&sdlhdr->sdlhdr_src, 0)) + llrt = rtalloc1((struct sockaddr *)&sdlhdr->sdlhdr_src, 0); + if (llrt) llrt->rt_refcnt--; #ifdef notyet - else llrt = npaidb_enter(&sdlhdr->sdlhdr_src, 0, 0, 0); + else + llrt = npaidb_enter(&sdlhdr->sdlhdr_src, 0, 0, 0); #endif /* notyet */ else { /* @@ -283,7 +286,7 @@ llcintr() /* * Pass it on thru the elements of procedure */ - llc_input(linkp, m, cmdrsp); + llc_input(m, linkp, cmdrsp); } return; } @@ -302,13 +305,28 @@ llcintr() * o ... * are then enacted accordingly. */ -llc_input(struct llc_linkcb *linkp, struct mbuf *m, u_char cmdrsp) +int +#if __STDC__ +llc_input(struct mbuf *m, ...) +#else +llc_input(m, va_alist) + struct mbuf *m; + va_dcl +#endif { int frame_kind; int pollfinal; int action = 0; struct llc *frame; - struct ifnet *ifp = linkp->llcl_if; + struct llc_linkcb *linkp; + u_int cmdrsp; + va_list ap; + + va_start(ap, m); + linkp = va_arg(ap, struct llc_linkcb *); + cmdrsp = va_arg(ap, u_int); + va_end(ap); + if ((frame = mtod(m, struct llc *)) == (struct llc *) 0) { m_freem(m); @@ -327,9 +345,9 @@ llc_input(struct llc_linkcb *linkp, struct mbuf *m, u_char cmdrsp) pollfinal)) { case LLC_DATA_INDICATION: m_adj(m, LLC_ISFRAMELEN); - if (m = m_pullup(m, NLHDRSIZEGUESS)) { + if ((m = m_pullup(m, NLHDRSIZEGUESS)) != NULL) { m->m_pkthdr.rcvif = (struct ifnet *)linkp->llcl_nlnext; - (*linkp->llcl_sapinfo->si_input)(m); + (*linkp->llcl_sapinfo->si_input)(m, NULL, NULL, NULL); } break; } @@ -348,18 +366,21 @@ llc_input(struct llc_linkcb *linkp, struct mbuf *m, u_char cmdrsp) * This routine is called by configuration setup. It sets up a station control * block and notifies all registered upper level protocols. */ -caddr_t -llc_ctlinput(int prc, struct sockaddr *addr, caddr_t info) +void * +llc_ctlinput(prc, addr, info) + int prc; + struct sockaddr *addr; + void *info; { - struct ifnet *ifp; + struct ifnet *ifp = NULL; struct ifaddr *ifa; struct dll_ctlinfo *ctlinfo = (struct dll_ctlinfo *)info; u_char sap; struct dllconfig *config; caddr_t pcb; struct rtentry *nlrt; - struct rtentry *llrt; - struct llc_linkcb *linkp; + struct rtentry *llrt = NULL; + struct llc_linkcb *linkp = NULL; register int i; /* info must point to something valid at all times */ @@ -412,7 +433,7 @@ llc_ctlinput(int prc, struct sockaddr *addr, caddr_t info) linkp = LQFIRST; while (LQVALID(linkp)) { nlinkp = LQNEXT(linkp); - if (linkp->llcl_if = ifp) { + if ((linkp->llcl_if = ifp) != NULL) { i = splimp(); (void)llc_statehandler(linkp, (struct llc *)0, NL_DISCONNECT_REQUEST, diff --git a/sys/netccitt/llc_output.c b/sys/netccitt/llc_output.c index 70df6288398..d8cdccc8eba 100644 --- a/sys/netccitt/llc_output.c +++ b/sys/netccitt/llc_output.c @@ -1,4 +1,5 @@ -/* $NetBSD: llc_output.c,v 1.2 1994/06/29 06:37:23 cgd Exp $ */ +/* $OpenBSD: llc_output.c,v 1.2 1996/03/04 07:36:31 niklas Exp $ */ +/* $NetBSD: llc_output.c,v 1.3 1996/02/13 22:04:47 christos Exp $ */ /* * Copyright (C) Dirk Husemann, Computer Science Department IV, @@ -59,21 +60,35 @@ #include #include +#include + /* * llc_output() --- called by an upper layer (network layer) entity whenever * there is an INFO frame to be transmitted. We enqueue the * info frame and call llc_start() to do the actual sending. */ -llc_output(struct llc_linkcb *linkp, struct mbuf *m) +int +#if __STDC__ +llc_output(struct mbuf *m, ...) +#else +llc_output(m, va_alist) + struct mbuf *m; + va_dcl +#endif { - register int i; + struct llc_linkcb *linkp; + register int i = splimp(); + va_list ap; + + va_start(ap, m); + linkp = va_arg(ap, struct llc_linkcb *); + va_end(ap); - i = splimp(); LLC_ENQUEUE(linkp, m); llc_start(linkp); splx(i); - + return 0; } @@ -82,22 +97,20 @@ llc_output(struct llc_linkcb *linkp, struct mbuf *m) * send them out. */ void -llc_start(struct llc_linkcb *linkp) +llc_start(linkp) + struct llc_linkcb *linkp; { - register int i; register struct mbuf *m; - int action; - while ((LLC_STATEEQ(linkp, NORMAL) || LLC_STATEEQ(linkp, BUSY) || - LLC_STATEEQ(linkp, REJECT)) && - (linkp->llcl_slotsfree > 0) && - (LLC_GETFLAG(linkp, REMOTE_BUSY) == 0)) { - LLC_DEQUEUE(linkp, m); + while ((LLC_STATEEQ(linkp,NORMAL) || LLC_STATEEQ(linkp,BUSY) || + LLC_STATEEQ(linkp,REJECT)) && + (linkp->llcl_slotsfree > 0) && + (LLC_GETFLAG(linkp,REMOTE_BUSY) == 0)) { + LLC_DEQUEUE(linkp,m); if (m == NULL) break; LLC_SETFRAME(linkp, m); - (void)llc_statehandler(linkp, (struct llc *) 0, NL_DATA_REQUEST, - 0, 0); + (void) llc_statehandler(linkp, NULL, NL_DATA_REQUEST, 0, 0); } } @@ -107,9 +120,14 @@ llc_start(struct llc_linkcb *linkp) * prepend the LLC header, otherwise we just allocate an mbuf. * In both cases the actual send is done by llc_rawsend(). */ -llc_send(struct llc_linkcb *linkp, int frame_kind, int cmdrsp, int pollfinal) +void +llc_send(linkp, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + int frame_kind; + int cmdrsp; + int pollfinal; { - register struct mbuf *m = (struct mbuf *)0; + register struct mbuf *m = (struct mbuf *) 0; register struct llc *frame; if (frame_kind == LLCFT_INFO) @@ -122,36 +140,36 @@ llc_send(struct llc_linkcb *linkp, int frame_kind, int cmdrsp, int pollfinal) if (frame_kind == LLCFT_INFO) LLC_INC(linkp->llcl_vs); - - return 0; } -/* +/* * llc_resend() --- llc_resend() retransmits all unacknowledged INFO frames. */ -llc_resend(struct llc_linkcb *linkp, int cmdrsp, int pollfinal) +void +llc_resend(linkp, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + int cmdrsp; + int pollfinal; { register struct llc *frame; register struct mbuf *m; - register int seq, slot; + register int slot; if (linkp->llcl_slotsfree < linkp->llcl_window) /* assert lock between nr_received & V(S) */ if (linkp->llcl_nr_received != linkp->llcl_vs) panic("llc: V(S) != N(R) received\n"); - for (slot = llc_seq2slot(linkp, linkp->llcl_vs); - slot != linkp->llcl_freeslot; - LLC_INC(linkp->llcl_vs), - slot = llc_seq2slot(linkp, linkp->llcl_vs)) { - m = linkp->llcl_output_buffers[slot]; - LLC_GETHDR(frame, m); - llc_rawsend(linkp, m, frame, LLCFT_INFO, linkp->llcl_vs, - cmdrsp, pollfinal); - pollfinal = 0; - } - - return 0; + for (slot = llc_seq2slot(linkp, linkp->llcl_vs); + slot != linkp->llcl_freeslot; + LLC_INC(linkp->llcl_vs), + slot = llc_seq2slot(linkp, linkp->llcl_vs)) { + m = linkp->llcl_output_buffers[slot]; + LLC_GETHDR(frame, m); + llc_rawsend(linkp, m, frame, LLCFT_INFO, linkp->llcl_vs, + cmdrsp, pollfinal); + pollfinal = 0; + } } /* @@ -174,14 +192,21 @@ llc_resend(struct llc_linkcb *linkp, int cmdrsp, int pollfinal) */ #define LLC_SETLEN(m, l) (m)->m_pkthdr.len = (m)->m_len = (l) -llc_rawsend(struct llc_linkcb *linkp, struct mbuf *m, struct llc *frame, - int frame_kind, int vs, int cmdrsp, int pollfinal) +void +llc_rawsend(linkp, m, frame, frame_kind, vs, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct mbuf *m; + struct llc *frame; + int frame_kind; + int vs; + int cmdrsp; + int pollfinal; { - register short adjust = LLC_UFRAMELEN; - struct ifnet *ifp; + register short adjust = LLC_UFRAMELEN; + struct ifnet *ifp; switch (frame_kind) { - /* supervisory and information frames */ + /* supervisory and information frames */ case LLCFT_INFO: frame->llc_control = LLC_INFO; LLCSBITS(frame->llc_control, i_ns, vs); @@ -206,7 +231,7 @@ llc_rawsend(struct llc_linkcb *linkp, struct mbuf *m, struct llc *frame, LLCSBITS(frame->llc_control_ext, s_nr, linkp->llcl_vr); adjust = LLC_ISFRAMELEN; break; - /* unnumbered frames */ + /* unnumbered frames */ case LLCFT_DM: frame->llc_control = LLC_DM; break; @@ -226,8 +251,8 @@ llc_rawsend(struct llc_linkcb *linkp, struct mbuf *m, struct llc *frame, frame->llc_control = LLC_FRMR; /* get more space --- FRMR frame are longer then usual */ LLC_SETLEN(m, LLC_FRMRLEN); - bcopy((caddr_t) &linkp->llcl_frmrinfo, - (caddr_t) &frame->llc_frmrinfo, + bcopy((caddr_t) & linkp->llcl_frmrinfo, + (caddr_t) & frame->llc_frmrinfo, sizeof(struct frmrinfo)); break; default: @@ -238,8 +263,8 @@ llc_rawsend(struct llc_linkcb *linkp, struct mbuf *m, struct llc *frame, m_freem(m); return; } - - /* + + /* * Fill in DSAP/SSAP */ frame->llc_dsap = frame->llc_ssap = LLSAPADDR(&linkp->llcl_addr); @@ -256,51 +281,51 @@ llc_rawsend(struct llc_linkcb *linkp, struct mbuf *m, struct llc *frame, case LLCFT_RNR: case LLCFT_REJ: case LLCFT_INFO: - switch (LLC_GETFLAG(linkp, DACTION)) { + switch (LLC_GETFLAG(linkp,DACTION)) { case LLC_DACKCMD: case LLC_DACKRSP: - LLC_STOPTIMER(linkp, DACTION); + LLC_STOPTIMER(linkp,DACTION); break; case LLC_DACKCMDPOLL: if (cmdrsp == LLC_CMD) { pollfinal = 1; - LLC_STOPTIMER(linkp, DACTION); + LLC_STOPTIMER(linkp,DACTION); } break; case LLC_DACKRSPFINAL: if (cmdrsp == LLC_RSP) { pollfinal = 1; - LLC_STOPTIMER(linkp, DACTION); + LLC_STOPTIMER(linkp,DACTION); } break; } break; } - + if (adjust == LLC_UFRAMELEN) - LLCSBITS(frame->llc_control, u_pf, pollfinal); - else LLCSBITS(frame->llc_control_ext, s_pf, pollfinal); + LLCSBITS(frame->llc_control,u_pf,pollfinal); + else + LLCSBITS(frame->llc_control_ext,s_pf,pollfinal); /* * Get interface to send frame onto */ ifp = linkp->llcl_if; if (frame_kind == LLCFT_INFO) { - /* - * send out a copy of the frame, retain the - * original + /* + * send out a copy of the frame, retain the original */ - (*ifp->if_output)(ifp, m_copy(m, 0, (int)M_COPYALL), - rt_key(linkp->llcl_nlrt), - linkp->llcl_nlrt); + (*ifp->if_output) (ifp, m_copy(m, 0, (int) M_COPYALL), + rt_key(linkp->llcl_nlrt), + linkp->llcl_nlrt); /* * Account for the LLC header and let it ``disappear'' * as the raw info frame payload is what we hold in * the output_buffers of the link. */ m_adj(m, LLC_ISFRAMELEN); - } else (*ifp->if_output)(ifp, m, - rt_key(linkp->llcl_nlrt), - linkp->llcl_nlrt); + } else + (*ifp->if_output) (ifp, m, + rt_key(linkp->llcl_nlrt), + linkp->llcl_nlrt); } - diff --git a/sys/netccitt/llc_subr.c b/sys/netccitt/llc_subr.c index b5e294cbabb..3445c303c10 100644 --- a/sys/netccitt/llc_subr.c +++ b/sys/netccitt/llc_subr.c @@ -1,4 +1,5 @@ -/* $NetBSD: llc_subr.c,v 1.3 1995/06/13 05:38:51 mycroft Exp $ */ +/* $OpenBSD: llc_subr.c,v 1.2 1996/03/04 07:36:33 niklas Exp $ */ +/* $NetBSD: llc_subr.c,v 1.4 1996/02/13 22:04:51 christos Exp $ */ /* * Copyright (C) Dirk Husemann, Computer Science Department IV, @@ -63,8 +64,10 @@ /* * Frame names for diagnostic messages */ -char *frame_names[] = { "INFO", "RR", "RNR", "REJ", "DM", "SABME", "DISC", - "UA", "FRMR", "UI", "XID", "TEST", "ILLEGAL", "TIMER", "N2xT1"}; +char *frame_names[] = { + "INFO", "RR", "RNR", "REJ", "DM", "SABME", "DISC", + "UA", "FRMR", "UI", "XID", "TEST", "ILLEGAL", "TIMER", "N2xT1" +}; /* @@ -76,220 +79,244 @@ int llc_tracelevel = LLCTR_URGENT; * Values for accessing various bitfields */ struct bitslice llc_bitslice[] = { -/* mask, shift value */ - { 0x1, 0x0 }, - { 0xfe, 0x1 }, - { 0x3, 0x0 }, - { 0xc, 0x2 }, - { 0x10, 0x4 }, - { 0xe0, 0x5 }, - { 0x1f, 0x0 } + /* mask, shift value */ + {0x1, 0x0}, + {0xfe, 0x1}, + {0x3, 0x0}, + {0xc, 0x2}, + {0x10, 0x4}, + {0xe0, 0x5}, + {0x1f, 0x0} }; /* - * We keep the link control blocks on a doubly linked list - - * primarily for checking in llc_time() + * We keep the link control blocks on a doubly linked list - + * primarily for checking in llc_time() */ - -struct llccb_q llccb_q = { &llccb_q, &llccb_q }; +struct llccb_q llccb_q = {&llccb_q, &llccb_q}; /* * Flag for signalling wether route tree for AF_LINK has been * initialized yet. */ -int af_link_rts_init_done = 0; +int af_link_rts_init_done = 0; /* * Functions dealing with struct sockaddr_dl */ /* Compare sdl_a w/ sdl_b */ - -sdl_cmp(struct sockaddr_dl *sdl_a, struct sockaddr_dl *sdl_b) +int +sdl_cmp(sdl_a, sdl_b) + struct sockaddr_dl *sdl_a; + struct sockaddr_dl *sdl_b; { if (LLADDRLEN(sdl_a) != LLADDRLEN(sdl_b)) - return(1); - return(bcmp((caddr_t) sdl_a->sdl_data, (caddr_t) sdl_b->sdl_data, - LLADDRLEN(sdl_a))); + return (1); + return (bcmp((caddr_t) sdl_a->sdl_data, (caddr_t) sdl_b->sdl_data, + LLADDRLEN(sdl_a))); } /* Copy sdl_f to sdl_t */ - -sdl_copy(struct sockaddr_dl *sdl_f, struct sockaddr_dl *sdl_t) +void +sdl_copy(sdl_f, sdl_t) + struct sockaddr_dl *sdl_f; + struct sockaddr_dl *sdl_t; { bcopy((caddr_t) sdl_f, (caddr_t) sdl_t, sdl_f->sdl_len); } /* Swap sdl_a w/ sdl_b */ - -sdl_swapaddr(struct sockaddr_dl *sdl_a, struct sockaddr_dl *sdl_b) +void +sdl_swapaddr(sdl_a, sdl_b) + struct sockaddr_dl *sdl_a; + struct sockaddr_dl *sdl_b; { struct sockaddr_dl sdl_tmp; - sdl_copy(sdl_a, &sdl_tmp); - sdl_copy(sdl_b, sdl_a); + sdl_copy(sdl_a, &sdl_tmp); + sdl_copy(sdl_b, sdl_a); sdl_copy(&sdl_tmp, sdl_b); } /* Fetch the sdl of the associated if */ - -struct sockaddr_dl * -sdl_getaddrif(struct ifnet *ifp) +struct sockaddr_dl * +sdl_getaddrif(ifp) + struct ifnet *ifp; { register struct ifaddr *ifa; for (ifa = ifp->if_addrlist.tqh_first; ifa != 0; - ifa = ifa->ifa_list.tqe_next) + ifa = ifa->ifa_list.tqe_next) if (ifa->ifa_addr->sa_family == AF_LINK) - return((struct sockaddr_dl *)(ifa->ifa_addr)); + return ((struct sockaddr_dl *) (ifa->ifa_addr)); - return((struct sockaddr_dl *)0); + return ((struct sockaddr_dl *) 0); } /* Check addr of interface with the one given */ - -sdl_checkaddrif(struct ifnet *ifp, struct sockaddr_dl *sdl_c) +int +sdl_checkaddrif(ifp, sdl_c) + struct ifnet *ifp; + struct sockaddr_dl *sdl_c; { register struct ifaddr *ifa; for (ifa = ifp->if_addrlist.tqh_first; ifa != 0; - ifa = ifa->ifa_list.tqe_next) - if (ifa->ifa_addr->sa_family == AF_LINK && - !sdl_cmp((struct sockaddr_dl *)(ifa->ifa_addr), sdl_c)) - return(1); - - return(0); + ifa = ifa->ifa_list.tqe_next) + if (ifa->ifa_addr->sa_family == AF_LINK && + !sdl_cmp((struct sockaddr_dl *) (ifa->ifa_addr), sdl_c)) + return (1); + + return (0); } /* Build an sdl from MAC addr, DLSAP addr, and interface */ - -sdl_setaddrif(struct ifnet *ifp, u_char *mac_addr, u_char dlsap_addr, - u_char mac_len, struct sockaddr_dl *sdl_to) +int +sdl_setaddrif(ifp, mac_addr, dlsap_addr, mac_len, sdl_to) + struct ifnet *ifp; + u_char *mac_addr; + u_char dlsap_addr; + u_char mac_len; + struct sockaddr_dl *sdl_to; { register struct sockaddr_dl *sdl_tmp; - if ((sdl_tmp = sdl_getaddrif(ifp)) ) { - sdl_copy(sdl_tmp, sdl_to); + if ((sdl_tmp = sdl_getaddrif(ifp))) { + sdl_copy(sdl_tmp, sdl_to); bcopy((caddr_t) mac_addr, (caddr_t) LLADDR(sdl_to), mac_len); - *(LLADDR(sdl_to)+mac_len) = dlsap_addr; - sdl_to->sdl_alen = mac_len+1; - return(1); - } else return(0); + *(LLADDR(sdl_to) + mac_len) = dlsap_addr; + sdl_to->sdl_alen = mac_len + 1; + return (1); + } else + return (0); } /* Fill out the sdl header aggregate */ - -sdl_sethdrif(struct ifnet *ifp, u_char *mac_src, u_char dlsap_src, u_char *mac_dst, - u_char dlsap_dst, u_char mac_len, struct sdl_hdr *sdlhdr_to) +int +sdl_sethdrif(ifp, mac_src, dlsap_src, mac_dst, dlsap_dst, mac_len, sdlhdr_to) + struct ifnet *ifp; + u_char *mac_src; + u_char dlsap_src; + u_char *mac_dst; + u_char dlsap_dst; + u_char mac_len; + struct sdl_hdr *sdlhdr_to; { - if ( !sdl_setaddrif(ifp, mac_src, dlsap_src, mac_len, - &sdlhdr_to->sdlhdr_src) || - !sdl_setaddrif(ifp, mac_dst, dlsap_dst, mac_len, - &sdlhdr_to->sdlhdr_dst) ) - return(0); - else return(1); + if (!sdl_setaddrif(ifp, mac_src, dlsap_src, mac_len, + &sdlhdr_to->sdlhdr_src) || + !sdl_setaddrif(ifp, mac_dst, dlsap_dst, mac_len, + &sdlhdr_to->sdlhdr_dst)) + return (0); + else + return (1); } -static struct sockaddr_dl sap_saddr; +static struct sockaddr_dl sap_saddr; static struct sockaddr_dl sap_sgate = { - sizeof(struct sockaddr_dl), /* _len */ - AF_LINK /* _af */ + sizeof(struct sockaddr_dl), /* _len */ + AF_LINK /* _af */ }; /* * Set sapinfo for SAP address, llcconfig, af, and interface */ struct npaidbentry * -llc_setsapinfo(struct ifnet *ifp, u_char af, u_char sap, struct dllconfig *llconf) +llc_setsapinfo(ifp, af, sap, llconf) + struct ifnet *ifp; + u_char af; + u_char sap; + struct dllconfig* llconf; { - struct protosw *pp; - struct sockaddr_dl *ifdl_addr; - struct rtentry *sirt = (struct rtentry *)0; - struct npaidbentry *sapinfo; - u_char saploc; - int size = sizeof(struct npaidbentry); + struct protosw *pp; + struct sockaddr_dl *ifdl_addr; + struct rtentry *sirt = (struct rtentry *) 0; + struct npaidbentry *sapinfo; + u_char saploc; + int size = sizeof(struct npaidbentry); USES_AF_LINK_RTS; - /* - * We rely/assume that only STREAM protocols will make use of - * connection oriented LLC2. If this will one day not be the - * case this will obviously fail. - */ - pp = pffindtype (af, SOCK_STREAM); - if (pp == 0 || pp->pr_input == 0 || pp->pr_ctlinput == 0) { - printf("network level protosw error"); - return 0; + /* + * We rely/assume that only STREAM protocols will make use of + * connection oriented LLC2. If this will one day not be the case + * this will obviously fail. + */ + pp = pffindtype(af, SOCK_STREAM); + if (pp == 0 || pp->pr_input == 0 || pp->pr_ctlinput == 0) { + printf("network level protosw error"); + return 0; } - /* * We need a way to jot down the LLC2 configuration for - * a certain LSAP address. To do this we enter + * a certain LSAP address. To do this we enter * a "route" for the SAP. */ ifdl_addr = sdl_getaddrif(ifp); - sdl_copy(ifdl_addr, &sap_saddr); + sdl_copy(ifdl_addr, &sap_saddr); sdl_copy(ifdl_addr, &sap_sgate); - saploc = LLSAPLOC(&sap_saddr, ifp); + saploc = LLSAPLOC(&sap_saddr, ifp); sap_saddr.sdl_data[saploc] = sap; sap_saddr.sdl_alen++; - /* now enter it */ - rtrequest(RTM_ADD, (struct sockaddr *)&sap_saddr, - (struct sockaddr *)&sap_sgate, 0, 0, &sirt); - if (sirt == 0) + /* now enter it */ + rtrequest(RTM_ADD, (struct sockaddr *) & sap_saddr, + (struct sockaddr *) & sap_sgate, 0, 0, &sirt); + if (sirt == 0) return 0; /* Plug in config information in rt->rt_llinfo */ - sirt->rt_llinfo = malloc(size , M_PCB, M_WAITOK); - sapinfo = (struct npaidbentry *) sirt->rt_llinfo; - if (sapinfo) { - bzero ((caddr_t)sapinfo, size); - /* - * For the time being we support LLC CLASS II here - * only - */ - sapinfo->si_class = LLC_CLASS_II; + sirt->rt_llinfo = malloc(size, M_PCB, M_WAITOK); + sapinfo = (struct npaidbentry *) sirt->rt_llinfo; + if (sapinfo) { + bzero((caddr_t) sapinfo, size); + /* + * For the time being we support LLC CLASS II here only + */ + sapinfo->si_class = LLC_CLASS_II; sapinfo->si_window = llconf->dllcfg_window; - sapinfo->si_trace = llconf->dllcfg_trace; + sapinfo->si_trace = llconf->dllcfg_trace; if (sapinfo->si_trace) llc_tracelevel--; - else llc_tracelevel++; - sapinfo->si_input = pp->pr_input; - sapinfo->si_ctlinput = (caddr_t (*)())pp->pr_ctlinput; + else + llc_tracelevel++; + sapinfo->si_input = pp->pr_input; + sapinfo->si_ctlinput = pp->pr_ctlinput; return (sapinfo); } - return 0; } /* - * Get sapinfo for SAP address and interface + * Get sapinfo for SAP address and interface */ struct npaidbentry * -llc_getsapinfo(u_char sap, struct ifnet *ifp) +llc_getsapinfo(sap, ifp) + u_char sap; + struct ifnet *ifp; { - struct sockaddr_dl *ifdl_addr; - struct sockaddr_dl si_addr; - struct rtentry *sirt; - u_char saploc; + struct sockaddr_dl *ifdl_addr; + struct sockaddr_dl si_addr; + struct rtentry *sirt; + u_char saploc; USES_AF_LINK_RTS; - ifdl_addr = sdl_getaddrif(ifp); - sdl_copy(ifdl_addr, &si_addr); - saploc = LLSAPLOC(&si_addr, ifp); + ifdl_addr = sdl_getaddrif(ifp); + sdl_copy(ifdl_addr, &si_addr); + saploc = LLSAPLOC(&si_addr, ifp); si_addr.sdl_data[saploc] = sap; si_addr.sdl_alen++; - if ((sirt = rtalloc1((struct sockaddr *)&si_addr, 0))) - sirt->rt_refcnt--; - else return(0); + if ((sirt = rtalloc1((struct sockaddr *) & si_addr, 0))) + sirt->rt_refcnt--; + else + return (0); - return((struct npaidbentry *)sirt->rt_llinfo); + return ((struct npaidbentry *) sirt->rt_llinfo); } /* @@ -308,8 +335,8 @@ llc_getsapinfo(u_char sap, struct ifnet *ifp) * The slot sl(sn) for any given sequence number sn is given by * * sl(sn) = (llcl_freeslot + llcl_window - 1 - (llcl_projvs + - * LLC_MAX_SEQUENCE- sn) % LLC_MAX_SEQUENCE) % - * llcl_window + * LLC_MAX_SEQUENCE- sn) % LLC_MAX_SEQUENCE) % + * llcl_window * * i.e. we first calculate the number of frames we need to ``go back'' * from the current one (really the next one, but that doesn't matter as @@ -318,12 +345,14 @@ llc_getsapinfo(u_char sap, struct ifnet *ifp) */ short -llc_seq2slot(struct llc_linkcb *linkp, short seqn) +llc_seq2slot(linkp, seqn) + struct llc_linkcb *linkp; + short seqn; { - register sn = 0; + register sn = 0; - sn = (linkp->llcl_freeslot + linkp->llcl_window - - (linkp->llcl_projvs + LLC_MAX_SEQUENCE - seqn) % + sn = (linkp->llcl_freeslot + linkp->llcl_window - + (linkp->llcl_projvs + LLC_MAX_SEQUENCE - seqn) % LLC_MAX_SEQUENCE) % linkp->llcl_window; return sn; @@ -334,10 +363,10 @@ llc_seq2slot(struct llc_linkcb *linkp, short seqn) * * There is in most cases one function per LLC2 state. The LLC2 standard * ISO 8802-2 allows in some cases for ambiguities, i.e. we have the choice - * to do one thing or the other. Right now I have just chosen one but have also - * indicated the spot by "multiple possibilities". One could make the behavior + * to do one thing or the other. Right now I have just chosen one but have also + * indicated the spot by "multiple possibilities". One could make the behavior * in those cases configurable, allowing the superuser to enter a profile word - * (32/64 bits, whatever is needed) that would suit her needs [I quite like + * (32/64 bits, whatever is needed) that would suit her needs [I quite like * that idea, perhaps I'll get around to it]. * * [Preceeding each state handler function is the description as taken from @@ -353,35 +382,39 @@ llc_seq2slot(struct llc_linkcb *linkp, short seqn) * command PDU with the P bit set to ``1''. */ int -llc_state_ADM(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_ADM(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_CONNECT_REQUEST: llc_send(linkp, LLCFT_SABME, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); - LLC_SETFLAG(linkp, S, 0); + LLC_SETFLAG(linkp,P,pollfinal); + LLC_SETFLAG(linkp,S,0); linkp->llcl_retry = 0; - LLC_NEWSTATE(linkp, SETUP); + LLC_NEWSTATE(linkp,SETUP); break; case LLCFT_SABME + LLC_CMD: - /* - * ISO 8802-2, table 7-1, ADM state says to set - * the P flag, yet this will cause an SABME [P] to be - * answered with an UA only, not an UA [F], all - * other `disconnected' states set the F flag, so ... + /* + * ISO 8802-2, table 7-1, ADM state says to set the P flag, + * yet this will cause an SABME [P] to be answered with an UA + * only, not an UA [F], all other `disconnected' states set + * the F flag, so ... */ - LLC_SETFLAG(linkp, F, pollfinal); - LLC_NEWSTATE(linkp, CONN); + LLC_SETFLAG(linkp,F,pollfinal); + LLC_NEWSTATE(linkp,CONN); action = LLC_CONNECT_INDICATION; break; case LLCFT_DISC + LLC_CMD: llc_send(linkp, LLCFT_DM, LLC_RSP, pollfinal); break; default: - if (cmdrsp == LLC_CMD && pollfinal == 1) + if (cmdrsp == LLC_CMD && pollfinal == 1) llc_send(linkp, LLCFT_DM, LLC_RSP, 1); /* remain in ADM state */ } @@ -395,31 +428,35 @@ llc_state_ADM(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * refuse the connection. */ int -llc_state_CONN(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_CONN(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_CONNECT_RESPONSE: - llc_send(linkp, LLCFT_UA, LLC_RSP, LLC_GETFLAG(linkp, F)); + llc_send(linkp, LLCFT_UA, LLC_RSP, LLC_GETFLAG(linkp,F)); LLC_RESETCOUNTER(linkp); - LLC_SETFLAG(linkp, P, 0); - LLC_SETFLAG(linkp, REMOTE_BUSY, 0); - LLC_NEWSTATE(linkp, NORMAL); + LLC_SETFLAG(linkp,P,0); + LLC_SETFLAG(linkp,REMOTE_BUSY, 0); + LLC_NEWSTATE(linkp,NORMAL); break; case NL_DISCONNECT_REQUEST: - llc_send(linkp, LLCFT_DM, LLC_RSP, LLC_GETFLAG(linkp, F)); - LLC_NEWSTATE(linkp, ADM); + llc_send(linkp, LLCFT_DM, LLC_RSP, LLC_GETFLAG(linkp,F)); + LLC_NEWSTATE(linkp,ADM); break; case LLCFT_SABME + LLC_CMD: - LLC_SETFLAG(linkp, F, pollfinal); + LLC_SETFLAG(linkp,F,pollfinal); break; case LLCFT_DM + LLC_RSP: - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; - /* all other frames effect nothing here */ + /* all other frames effect nothing here */ } return action; @@ -427,56 +464,60 @@ llc_state_CONN(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, /* * RESET_WAIT --- The local connection component is waiting for the local user - * to indicate a RESET_REQUEST or a DISCONNECT_REQUEST. + * to indicate a RESET_REQUEST or a DISCONNECT_REQUEST. */ int -llc_state_RESET_WAIT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_RESET_WAIT(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_RESET_REQUEST: - if (LLC_GETFLAG(linkp, S) == 0) { + if (LLC_GETFLAG(linkp,S) == 0) { llc_send(linkp, LLCFT_SABME, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); + LLC_SETFLAG(linkp,P,pollfinal); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry = 0; - LLC_NEWSTATE(linkp, RESET); + LLC_NEWSTATE(linkp,RESET); } else { - llc_send(linkp, LLCFT_UA, LLC_RSP, - LLC_GETFLAG(linkp, F)); + llc_send(linkp, LLCFT_UA, LLC_RSP, + LLC_GETFLAG(linkp,F)); LLC_RESETCOUNTER(linkp); - LLC_SETFLAG(linkp, P, 0); - LLC_SETFLAG(linkp, REMOTE_BUSY, 0); - LLC_NEWSTATE(linkp, NORMAL); + LLC_SETFLAG(linkp,P,0); + LLC_SETFLAG(linkp,REMOTE_BUSY,0); + LLC_NEWSTATE(linkp,NORMAL); action = LLC_RESET_CONFIRM; } break; case NL_DISCONNECT_REQUEST: - if (LLC_GETFLAG(linkp, S) == 0) { + if (LLC_GETFLAG(linkp,S) == 0) { llc_send(linkp, LLCFT_DISC, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); + LLC_SETFLAG(linkp,P,pollfinal); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry = 0; - LLC_NEWSTATE(linkp, D_CONN); + LLC_NEWSTATE(linkp,D_CONN); } else { - llc_send(linkp, LLCFT_DM, LLC_RSP, - LLC_GETFLAG(linkp, F)); - LLC_NEWSTATE(linkp, ADM); + llc_send(linkp, LLCFT_DM, LLC_RSP, + LLC_GETFLAG(linkp,F)); + LLC_NEWSTATE(linkp,ADM); } break; case LLCFT_DM + LLC_RSP: - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; case LLCFT_SABME + LLC_CMD: - LLC_SETFLAG(linkp, S, 1); - LLC_SETFLAG(linkp, F, pollfinal); + LLC_SETFLAG(linkp,S,1); + LLC_SETFLAG(linkp,F,pollfinal); break; case LLCFT_DISC + LLC_CMD: llc_send(linkp, LLCFT_DM, LLC_RSP, pollfinal); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; } @@ -489,32 +530,36 @@ llc_state_RESET_WAIT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind * to accept or refuse a remote reset request. */ int -llc_state_RESET_CHECK(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_RESET_CHECK(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_RESET_RESPONSE: - llc_send(linkp, LLCFT_UA, LLC_RSP, LLC_GETFLAG(linkp, F)); + llc_send(linkp, LLCFT_UA, LLC_RSP, LLC_GETFLAG(linkp,F)); LLC_RESETCOUNTER(linkp); - LLC_SETFLAG(linkp, P, 0); - LLC_SETFLAG(linkp, REMOTE_BUSY, 0); - LLC_NEWSTATE(linkp, NORMAL); + LLC_SETFLAG(linkp,P,0); + LLC_SETFLAG(linkp,REMOTE_BUSY,0); + LLC_NEWSTATE(linkp,NORMAL); break; case NL_DISCONNECT_REQUEST: - llc_send(linkp, LLCFT_DM, LLC_RSP, LLC_GETFLAG(linkp, F)); - LLC_NEWSTATE(linkp, ADM); + llc_send(linkp, LLCFT_DM, LLC_RSP, LLC_GETFLAG(linkp,F)); + LLC_NEWSTATE(linkp,ADM); break; case LLCFT_DM + LLC_RSP: action = LLC_DISCONNECT_INDICATION; break; case LLCFT_SABME + LLC_CMD: - LLC_SETFLAG(linkp, F, pollfinal); + LLC_SETFLAG(linkp,F,pollfinal); break; case LLCFT_DISC + LLC_CMD: llc_send(linkp, LLCFT_DM, LLC_RSP, pollfinal); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; } @@ -527,52 +572,56 @@ llc_state_RESET_CHECK(struct llc_linkcb *linkp, struct llc *frame, int frame_kin * remote LLC DSAP and is waiting for a reply. */ int -llc_state_SETUP(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_SETUP(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case LLCFT_SABME + LLC_CMD: LLC_RESETCOUNTER(linkp); llc_send(linkp, LLCFT_UA, LLC_RSP, pollfinal); - LLC_SETFLAG(linkp, S, 1); + LLC_SETFLAG(linkp,S,1); break; case LLCFT_UA + LLC_RSP: - if (LLC_GETFLAG(linkp, P) == pollfinal) { + if (LLC_GETFLAG(linkp,P) == pollfinal) { LLC_STOP_ACK_TIMER(linkp); LLC_RESETCOUNTER(linkp); - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_SETFLAG(linkp, REMOTE_BUSY, 0); - LLC_NEWSTATE(linkp, NORMAL); + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + LLC_SETFLAG(linkp,REMOTE_BUSY,0); + LLC_NEWSTATE(linkp,NORMAL); action = LLC_CONNECT_CONFIRM; } break; case LLC_ACK_TIMER_EXPIRED: - if (LLC_GETFLAG(linkp, S) == 1) { - LLC_SETFLAG(linkp, P, 0); - LLC_SETFLAG(linkp, REMOTE_BUSY, 0), - LLC_NEWSTATE(linkp, NORMAL); + if (LLC_GETFLAG(linkp,S) == 1) { + LLC_SETFLAG(linkp,P,0); + LLC_SETFLAG(linkp,REMOTE_BUSY,0), + LLC_NEWSTATE(linkp,NORMAL); action = LLC_CONNECT_CONFIRM; } else if (linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_SABME, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); + LLC_SETFLAG(linkp,P,pollfinal); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry++; } else { - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; } break; case LLCFT_DISC + LLC_CMD: llc_send(linkp, LLCFT_DM, LLC_RSP, pollfinal); LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; case LLCFT_DM + LLC_RSP: LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; } @@ -587,52 +636,56 @@ llc_state_SETUP(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * connection and is waiting for a reply. */ int -llc_state_RESET(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_RESET(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case LLCFT_SABME + LLC_CMD: LLC_RESETCOUNTER(linkp); - LLC_SETFLAG(linkp, S, 1); + LLC_SETFLAG(linkp,S,1); llc_send(linkp, LLCFT_UA, LLC_RSP, pollfinal); break; case LLCFT_UA + LLC_RSP: - if (LLC_GETFLAG(linkp, P) == pollfinal) { + if (LLC_GETFLAG(linkp,P) == pollfinal) { LLC_STOP_ACK_TIMER(linkp); LLC_RESETCOUNTER(linkp); - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_SETFLAG(linkp, REMOTE_BUSY, 0); - LLC_NEWSTATE(linkp, NORMAL); + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + LLC_SETFLAG(linkp,REMOTE_BUSY,0); + LLC_NEWSTATE(linkp,NORMAL); action = LLC_RESET_CONFIRM; } break; case LLC_ACK_TIMER_EXPIRED: - if (LLC_GETFLAG(linkp, S) == 1) { - LLC_SETFLAG(linkp, P, 0); - LLC_SETFLAG(linkp, REMOTE_BUSY, 0); - LLC_NEWSTATE(linkp, NORMAL); + if (LLC_GETFLAG(linkp,S) == 1) { + LLC_SETFLAG(linkp,P,0); + LLC_SETFLAG(linkp,REMOTE_BUSY,0); + LLC_NEWSTATE(linkp,NORMAL); action = LLC_RESET_CONFIRM; } else if (linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_SABME, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); + LLC_SETFLAG(linkp,P,pollfinal); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry++; } else { - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; } break; case LLCFT_DISC + LLC_CMD: llc_send(linkp, LLCFT_DM, LLC_RSP, pollfinal); LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; case LLCFT_DM + LLC_RSP: LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; } @@ -646,21 +699,25 @@ llc_state_RESET(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * for a reply. */ int -llc_state_D_CONN(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_D_CONN(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case LLCFT_SABME + LLC_CMD: llc_send(linkp, LLCFT_DM, LLC_RSP, pollfinal); LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); break; case LLCFT_UA + LLC_RSP: - if (LLC_GETFLAG(linkp, P) == pollfinal) { + if (LLC_GETFLAG(linkp,P) == pollfinal) { LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); } break; case LLCFT_DISC + LLC_CMD: @@ -668,15 +725,16 @@ llc_state_D_CONN(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, break; case LLCFT_DM + LLC_RSP: LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); break; case LLC_ACK_TIMER_EXPIRED: if (linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_DISC, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); + LLC_SETFLAG(linkp,P,pollfinal); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry++; - } else LLC_NEWSTATE(linkp, ADM); + } else + LLC_NEWSTATE(linkp,ADM); break; } @@ -685,36 +743,40 @@ llc_state_D_CONN(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, /* * ERROR --- The local connection component has detected an error in a received - * PDU and has sent a FRMR response PDU. It is waiting for a reply from + * PDU and has sent a FRMR response PDU. It is waiting for a reply from * the remote connection component. */ int -llc_state_ERROR(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_ERROR(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case LLCFT_SABME + LLC_CMD: LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, RESET_CHECK); + LLC_NEWSTATE(linkp,RESET_CHECK); action = LLC_RESET_INDICATION_REMOTE; break; case LLCFT_DISC + LLC_CMD: llc_send(linkp, LLCFT_UA, LLC_RSP, pollfinal); LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; case LLCFT_DM + LLC_RSP: LLC_STOP_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; case LLCFT_FRMR + LLC_RSP: LLC_STOP_ACK_TIMER(linkp); - LLC_SETFLAG(linkp, S, 0); - LLC_NEWSTATE(linkp, RESET_WAIT); + LLC_SETFLAG(linkp,S,0); + LLC_NEWSTATE(linkp,RESET_WAIT); action = LLC_FRMR_RECEIVED; break; case LLC_ACK_TIMER_EXPIRED: @@ -723,13 +785,13 @@ llc_state_ERROR(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, LLC_START_ACK_TIMER(linkp); linkp->llcl_retry++; } else { - LLC_SETFLAG(linkp, S, 0); - LLC_NEWSTATE(linkp, RESET_WAIT); + LLC_SETFLAG(linkp,S,0); + LLC_NEWSTATE(linkp,RESET_WAIT); action = LLC_RESET_INDICATION_LOCAL; } break; default: - if (cmdrsp == LLC_CMD){ + if (cmdrsp == LLC_CMD) { llc_send(linkp, LLCFT_FRMR, LLC_RSP, pollfinal); LLC_START_ACK_TIMER(linkp); } @@ -745,92 +807,101 @@ llc_state_ERROR(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * a common core state handler. */ int -llc_state_NBRAcore(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_NBRAcore(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = 0; + int action = 0; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_DISCONNECT_REQUEST: llc_send(linkp, LLCFT_DISC, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); + LLC_SETFLAG(linkp,P,pollfinal); LLC_STOP_ALL_TIMERS(linkp); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry = 0; - LLC_NEWSTATE(linkp, D_CONN); + LLC_NEWSTATE(linkp,D_CONN); break; case NL_RESET_REQUEST: llc_send(linkp, LLCFT_SABME, LLC_CMD, pollfinal); - LLC_SETFLAG(linkp, P, pollfinal); + LLC_SETFLAG(linkp,P,pollfinal); LLC_STOP_ALL_TIMERS(linkp); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry = 0; - LLC_SETFLAG(linkp, S, 0); - LLC_NEWSTATE(linkp, RESET); + LLC_SETFLAG(linkp,S,0); + LLC_NEWSTATE(linkp,RESET); break; case LLCFT_SABME + LLC_CMD: - LLC_SETFLAG(linkp, F, pollfinal); + LLC_SETFLAG(linkp,F,pollfinal); LLC_STOP_ALL_TIMERS(linkp); - LLC_NEWSTATE(linkp, RESET_CHECK); + LLC_NEWSTATE(linkp,RESET_CHECK); action = LLC_RESET_INDICATION_REMOTE; break; case LLCFT_DISC + LLC_CMD: llc_send(linkp, LLCFT_UA, LLC_RSP, pollfinal); LLC_STOP_ALL_TIMERS(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; case LLCFT_FRMR + LLC_RSP: LLC_STOP_ALL_TIMERS(linkp); - LLC_SETFLAG(linkp, S, 0); - LLC_NEWSTATE(linkp, RESET_WAIT); - action = LLC_FRMR_RECEIVED; + LLC_SETFLAG(linkp,S,0); + LLC_NEWSTATE(linkp,RESET_WAIT); + action = LLC_FRMR_RECEIVED; break; case LLCFT_DM + LLC_RSP: LLC_STOP_ALL_TIMERS(linkp); - LLC_NEWSTATE(linkp, ADM); + LLC_NEWSTATE(linkp,ADM); action = LLC_DISCONNECT_INDICATION; break; case LLC_INVALID_NR + LLC_CMD: case LLC_INVALID_NS + LLC_CMD: - LLC_SETFRMR(linkp, frame, cmdrsp, - (frame_kind == LLC_INVALID_NR ? LLC_FRMR_Z : - (LLC_FRMR_V | LLC_FRMR_W))); + LLC_SETFRMR(linkp, frame, cmdrsp, + (frame_kind == LLC_INVALID_NR ? LLC_FRMR_Z : + (LLC_FRMR_V | LLC_FRMR_W))); llc_send(linkp, LLCFT_FRMR, LLC_RSP, pollfinal); LLC_STOP_ALL_TIMERS(linkp); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry = 0; - LLC_NEWSTATE(linkp, ERROR); + LLC_NEWSTATE(linkp,ERROR); action = LLC_FRMR_SENT; break; case LLC_INVALID_NR + LLC_RSP: case LLC_INVALID_NS + LLC_RSP: case LLCFT_UA + LLC_RSP: - case LLC_BAD_PDU: { - char frmrcause = 0; + case LLC_BAD_PDU:{ + char frmrcause = 0; - switch (frame_kind) { - case LLC_INVALID_NR: frmrcause = LLC_FRMR_Z; break; - case LLC_INVALID_NS: frmrcause = LLC_FRMR_V | LLC_FRMR_W; break; - default: frmrcause = LLC_FRMR_W; + switch (frame_kind) { + case LLC_INVALID_NR: + frmrcause = LLC_FRMR_Z; + break; + case LLC_INVALID_NS: + frmrcause = LLC_FRMR_V | LLC_FRMR_W; + break; + default: + frmrcause = LLC_FRMR_W; + } + LLC_SETFRMR(linkp,frame,cmdrsp,frmrcause); + llc_send(linkp, LLCFT_FRMR, LLC_RSP, 0); + LLC_STOP_ALL_TIMERS(linkp); + LLC_START_ACK_TIMER(linkp); + linkp->llcl_retry = 0; + LLC_NEWSTATE(linkp,ERROR); + action = LLC_FRMR_SENT; + break; } - LLC_SETFRMR(linkp, frame, cmdrsp, frmrcause); - llc_send(linkp, LLCFT_FRMR, LLC_RSP, 0); - LLC_STOP_ALL_TIMERS(linkp); - LLC_START_ACK_TIMER(linkp); - linkp->llcl_retry = 0; - LLC_NEWSTATE(linkp, ERROR); - action = LLC_FRMR_SENT; - break; - } default: - if (cmdrsp == LLC_RSP && pollfinal == 1 && - LLC_GETFLAG(linkp, P) == 0) { - LLC_SETFRMR(linkp, frame, cmdrsp, LLC_FRMR_W); + if (cmdrsp == LLC_RSP && pollfinal == 1 && + LLC_GETFLAG(linkp,P) == 0) { + LLC_SETFRMR(linkp,frame,cmdrsp,LLC_FRMR_W); LLC_STOP_ALL_TIMERS(linkp); LLC_START_ACK_TIMER(linkp); linkp->llcl_retry = 0; - LLC_NEWSTATE(linkp, ERROR); + LLC_NEWSTATE(linkp,ERROR); action = LLC_FRMR_SENT; } break; @@ -840,8 +911,8 @@ llc_state_NBRAcore(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, case LLC_BUSY_TIMER_EXPIRED: if (linkp->llcl_retry >= llc_n2) { LLC_STOP_ALL_TIMERS(linkp); - LLC_SETFLAG(linkp, S, 0); - LLC_NEWSTATE(linkp, RESET_WAIT); + LLC_SETFLAG(linkp,S,0); + LLC_NEWSTATE(linkp,RESET_WAIT); action = LLC_RESET_INDICATION_LOCAL; } break; @@ -856,26 +927,32 @@ llc_state_NBRAcore(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * reception of information and supervisory PDUs can be performed. */ int -llc_state_NORMAL(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_NORMAL(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = LLC_PASSITON; + int action = LLC_PASSITON; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_DATA_REQUEST: - if (LLC_GETFLAG(linkp, REMOTE_BUSY) == 0) { + if (LLC_GETFLAG(linkp,REMOTE_BUSY) == 0) { #ifdef not_now - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,P) == 0) { /* multiple possibilities */ llc_send(linkp, LLCFT_INFO, LLC_CMD, 1); LLC_START_P_TIMER(linkp); - if (LLC_TIMERXPIRED(linkp, ACK) != LLC_TIMER_RUNNING) + if (LLC_TIMERXPIRED(linkp,ACK) != + LLC_TIMER_RUNNING) LLC_START_ACK_TIMER(linkp); } else { -#endif +#endif /* multiple possibilities */ llc_send(linkp, LLCFT_INFO, LLC_CMD, 0); - if (LLC_TIMERXPIRED(linkp, ACK) != LLC_TIMER_RUNNING) + if (LLC_TIMERXPIRED(linkp,ACK) != + LLC_TIMER_RUNNING) LLC_START_ACK_TIMER(linkp); #ifdef not_now } @@ -884,140 +961,148 @@ llc_state_NORMAL(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, } break; case LLC_LOCAL_BUSY_DETECTED: - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,P) == 0) { /* multiple possibilities --- action-wise */ /* multiple possibilities --- CMD/RSP-wise */ llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); LLC_START_P_TIMER(linkp); - LLC_SETFLAG(linkp, DATA, 0); - LLC_NEWSTATE(linkp, BUSY); + LLC_SETFLAG(linkp,DATA,0); + LLC_NEWSTATE(linkp,BUSY); action = 0; - } else { + } else { /* multiple possibilities --- CMD/RSP-wise */ llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_SETFLAG(linkp, DATA, 0); - LLC_NEWSTATE(linkp, BUSY); - action = 0; + LLC_SETFLAG(linkp,DATA,0); + LLC_NEWSTATE(linkp,BUSY); + action = 0; } break; case LLC_INVALID_NS + LLC_CMD: - case LLC_INVALID_NS + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_REJ, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_START_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, REJECT); - action = 0; - } else if (pollfinal == 0 && p == 1) { - llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_START_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, REJECT); - action = 0; - } else if ((pollfinal == 0 && p == 0) || - (pollfinal == 1 && p == 1 && cmdrsp == LLC_RSP)) { - llc_send(linkp, LLCFT_REJ, LLC_CMD, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_START_P_TIMER(linkp); - LLC_START_REJ_TIMER(linkp); - if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else action = 0; - LLC_NEWSTATE(linkp, REJECT); + case LLC_INVALID_NS + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_REJ, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_START_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,REJECT); + action = 0; + } else if (pollfinal == 0 && p == 1) { + llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_START_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,REJECT); + action = 0; + } else if ((pollfinal == 0 && p == 0) || + (pollfinal == 1 && p == 1 && cmdrsp == LLC_RSP)) { + llc_send(linkp, LLCFT_REJ, LLC_CMD, 1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_START_P_TIMER(linkp); + LLC_START_REJ_TIMER(linkp); + if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else + action = 0; + LLC_NEWSTATE(linkp,REJECT); + } + break; } - break; - } case LLCFT_INFO + LLC_CMD: - case LLCFT_INFO + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - LLC_INC(linkp->llcl_vr); - LLC_SENDACKNOWLEDGE(linkp, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = LLC_DATA_INDICATION; - } else if (pollfinal == 0 && p == 1) { - LLC_INC(linkp->llcl_vr); - LLC_SENDACKNOWLEDGE(linkp, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = LLC_DATA_INDICATION; - } else if ((pollfinal == 0 && p == 0 && cmdrsp == LLC_CMD) || - (pollfinal == p && cmdrsp == LLC_RSP)) { - LLC_INC(linkp->llcl_vr); - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_SENDACKNOWLEDGE(linkp, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (cmdrsp == LLC_RSP && pollfinal == 1) - LLC_CLEAR_REMOTE_BUSY(linkp, action); - action = LLC_DATA_INDICATION; + case LLCFT_INFO + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + LLC_INC(linkp->llcl_vr); + LLC_SENDACKNOWLEDGE(linkp,LLC_RSP,1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + action = LLC_DATA_INDICATION; + } else if (pollfinal == 0 && p == 1) { + LLC_INC(linkp->llcl_vr); + LLC_SENDACKNOWLEDGE(linkp,LLC_CMD,0); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + action = LLC_DATA_INDICATION; + } else if ((pollfinal == 0 && p == 0 && + cmdrsp == LLC_CMD) || + (pollfinal == p && cmdrsp == LLC_RSP)) { + LLC_INC(linkp->llcl_vr); + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + LLC_SENDACKNOWLEDGE(linkp,LLC_CMD,0); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (cmdrsp == LLC_RSP && pollfinal == 1) + LLC_CLEAR_REMOTE_BUSY(linkp,action); + action = LLC_DATA_INDICATION; + } + break; } - break; - } case LLCFT_RR + LLC_CMD: - case LLCFT_RR + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - LLC_SENDACKNOWLEDGE(linkp, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if ((pollfinal == 0) || - (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } - break; - } + case LLCFT_RR + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + LLC_SENDACKNOWLEDGE(linkp,LLC_RSP,1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else if ((pollfinal == 0) || + (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } + break; + } case LLCFT_RNR + LLC_CMD: - case LLCFT_RNR + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); - } else if ((pollfinal == 0) || - (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); + case LLCFT_RNR + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } else if ((pollfinal == 0) || + (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } + break; } - break; - } case LLCFT_REJ + LLC_CMD: - case LLCFT_REJ + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - llc_resend(linkp, LLC_RSP, 1); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if (pollfinal == 0 && p == 1) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if ((pollfinal == 0 && p == 0 && cmdrsp == LLC_CMD) || - (pollfinal == p && cmdrsp == LLC_RSP)) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_START_P_TIMER(linkp); - llc_resend(linkp, LLC_CMD, 1); - LLC_CLEAR_REMOTE_BUSY(linkp, action); + case LLCFT_REJ + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp,nr); + llc_resend(linkp,LLC_RSP,1); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else if (pollfinal == 0 && p == 1) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp,nr); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else if ((pollfinal == 0 && p == 0 && + cmdrsp == LLC_CMD) || + (pollfinal == p && cmdrsp == LLC_RSP)) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_START_P_TIMER(linkp); + llc_resend(linkp, LLC_CMD, 1); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } + break; } - break; - } case NL_INITIATE_PF_CYCLE: - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,P) == 0) { llc_send(linkp, LLCFT_RR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); action = 0; @@ -1028,24 +1113,24 @@ llc_state_NORMAL(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, llc_send(linkp, LLCFT_RR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); linkp->llcl_retry++; - LLC_NEWSTATE(linkp, AWAIT); + LLC_NEWSTATE(linkp,AWAIT); action = 0; } break; case LLC_ACK_TIMER_EXPIRED: case LLC_BUSY_TIMER_EXPIRED: - if ((LLC_GETFLAG(linkp, P) == 0) + if ((LLC_GETFLAG(linkp,P) == 0) && (linkp->llcl_retry < llc_n2)) { llc_send(linkp, LLCFT_RR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); linkp->llcl_retry++; - LLC_NEWSTATE(linkp, AWAIT); + LLC_NEWSTATE(linkp,AWAIT); action = 0; } break; } if (action == LLC_PASSITON) - action = llc_state_NBRAcore(linkp, frame, frame_kind, + action = llc_state_NBRAcore(linkp, frame, frame_kind, cmdrsp, pollfinal); return action; @@ -1059,196 +1144,211 @@ llc_state_NORMAL(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * and received. */ int -llc_state_BUSY(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_BUSY(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = LLC_PASSITON; + int action = LLC_PASSITON; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_DATA_REQUEST: - if (LLC_GETFLAG(linkp, REMOTE_BUSY) == 0) - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,REMOTE_BUSY) == 0) + if (LLC_GETFLAG(linkp,P) == 0) { llc_send(linkp, LLCFT_INFO, LLC_CMD, 1); LLC_START_P_TIMER(linkp); - if (LLC_TIMERXPIRED(linkp, ACK) != LLC_TIMER_RUNNING) + if (LLC_TIMERXPIRED(linkp,ACK) != + LLC_TIMER_RUNNING) LLC_START_ACK_TIMER(linkp); action = 0; } else { llc_send(linkp, LLCFT_INFO, LLC_CMD, 0); - if (LLC_TIMERXPIRED(linkp, ACK) != LLC_TIMER_RUNNING) + if (LLC_TIMERXPIRED(linkp,ACK) != + LLC_TIMER_RUNNING) LLC_START_ACK_TIMER(linkp); action = 0; } break; - case LLC_LOCAL_BUSY_CLEARED: { - register int p = LLC_GETFLAG(linkp, P); - register int df = LLC_GETFLAG(linkp, DATA); - - switch (df) { - case 1: - if (p == 0) { - /* multiple possibilities */ - llc_send(linkp, LLCFT_REJ, LLC_CMD, 1); - LLC_START_REJ_TIMER(linkp); - LLC_START_P_TIMER(linkp); - LLC_NEWSTATE(linkp, REJECT); - action = 0; - } else { - llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); - LLC_START_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, REJECT); - action = 0; + case LLC_LOCAL_BUSY_CLEARED:{ + register int p = LLC_GETFLAG(linkp,P); + register int df = LLC_GETFLAG(linkp,DATA); + + switch (df) { + case 1: + if (p == 0) { + /* multiple possibilities */ + llc_send(linkp, LLCFT_REJ, LLC_CMD, 1); + LLC_START_REJ_TIMER(linkp); + LLC_START_P_TIMER(linkp); + LLC_NEWSTATE(linkp,REJECT); + action = 0; + } else { + llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); + LLC_START_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,REJECT); + action = 0; + } + break; + case 0: + if (p == 0) { + /* multiple possibilities */ + llc_send(linkp, LLCFT_RR, LLC_CMD, 1); + LLC_START_P_TIMER(linkp); + LLC_NEWSTATE(linkp,NORMAL); + action = 0; + } else { + llc_send(linkp, LLCFT_RR, LLC_CMD, 0); + LLC_NEWSTATE(linkp,NORMAL); + action = 0; + } + break; + case 2: + if (p == 0) { + /* multiple possibilities */ + llc_send(linkp, LLCFT_RR, LLC_CMD, 1); + LLC_START_P_TIMER(linkp); + LLC_NEWSTATE(linkp,REJECT); + action = 0; + } else { + llc_send(linkp, LLCFT_RR, LLC_CMD, 0); + LLC_NEWSTATE(linkp,REJECT); + action = 0; + } + break; } break; - case 0: - if (p == 0) { - /* multiple possibilities */ - llc_send(linkp, LLCFT_RR, LLC_CMD, 1); - LLC_START_P_TIMER(linkp); - LLC_NEWSTATE(linkp, NORMAL); + } + case LLC_INVALID_NS + LLC_CMD: + case LLC_INVALID_NS + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (LLC_GETFLAG(linkp,DATA) == 0) + LLC_SETFLAG(linkp,DATA,1); action = 0; - } else { - llc_send(linkp, LLCFT_RR, LLC_CMD, 0); - LLC_NEWSTATE(linkp, NORMAL); + } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && + p == 0) || + (cmdrsp == LLC_RSP && pollfinal == p)) { + llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (LLC_GETFLAG(linkp,DATA) == 0) + LLC_SETFLAG(linkp,DATA,1); + if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else + action = 0; + } else if (pollfinal == 0 && p == 1) { + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (LLC_GETFLAG(linkp,DATA) == 0) + LLC_SETFLAG(linkp,DATA,1); action = 0; } break; - case 2: - if (p == 0) { - /* multiple possibilities */ - llc_send(linkp, LLCFT_RR, LLC_CMD, 1); + } + case LLCFT_INFO + LLC_CMD: + case LLCFT_INFO + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + LLC_INC(linkp->llcl_vr); + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (LLC_GETFLAG(linkp,DATA) == 2) + LLC_STOP_REJ_TIMER(linkp); + LLC_SETFLAG(linkp,DATA,0); + action = LLC_DATA_INDICATION; + } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && p == 0) || + (cmdrsp == LLC_RSP && pollfinal == p)) { + LLC_INC(linkp->llcl_vr); + llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); - LLC_NEWSTATE(linkp, REJECT); - action = 0; - } else { - llc_send(linkp, LLCFT_RR, LLC_CMD, 0); - LLC_NEWSTATE(linkp, REJECT); - action =0; + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (LLC_GETFLAG(linkp,DATA) == 2) + LLC_STOP_REJ_TIMER(linkp); + if (cmdrsp == LLC_RSP && pollfinal == 1) + LLC_CLEAR_REMOTE_BUSY(linkp,action); + action = LLC_DATA_INDICATION; + } else if (pollfinal == 0 && p == 1) { + LLC_INC(linkp->llcl_vr); + llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (LLC_GETFLAG(linkp,DATA) == 2) + LLC_STOP_REJ_TIMER(linkp); + LLC_SETFLAG(linkp,DATA,0); + action = LLC_DATA_INDICATION; } break; } - break; - } - case LLC_INVALID_NS + LLC_CMD: - case LLC_INVALID_NS + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (LLC_GETFLAG(linkp, DATA) == 0) - LLC_SETFLAG(linkp, DATA, 1); - action = 0; - } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && p == 0) || - (cmdrsp == LLC_RSP && pollfinal == p)) { - llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (LLC_GETFLAG(linkp, DATA) == 0) - LLC_SETFLAG(linkp, DATA, 1); - if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else action = 0; - } else if (pollfinal == 0 && p == 1) { - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (LLC_GETFLAG(linkp, DATA) == 0) - LLC_SETFLAG(linkp, DATA, 1); - action = 0; - } - break; - } - case LLCFT_INFO + LLC_CMD: - case LLCFT_INFO + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - LLC_INC(linkp->llcl_vr); - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (LLC_GETFLAG(linkp, DATA) == 2) - LLC_STOP_REJ_TIMER(linkp); - LLC_SETFLAG(linkp, DATA, 0); - action = LLC_DATA_INDICATION; - } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && p == 0) || - (cmdrsp == LLC_RSP && pollfinal == p)) { - LLC_INC(linkp->llcl_vr); - llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); - LLC_START_P_TIMER(linkp); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (LLC_GETFLAG(linkp, DATA) == 2) - LLC_STOP_REJ_TIMER(linkp); - if (cmdrsp == LLC_RSP && pollfinal == 1) - LLC_CLEAR_REMOTE_BUSY(linkp, action); - action = LLC_DATA_INDICATION; - } else if (pollfinal == 0 && p == 1) { - LLC_INC(linkp->llcl_vr); - llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (LLC_GETFLAG(linkp, DATA) == 2) - LLC_STOP_REJ_TIMER(linkp); - LLC_SETFLAG(linkp, DATA, 0); - action = LLC_DATA_INDICATION; - } - break; - } case LLCFT_RR + LLC_CMD: - case LLCFT_RR + LLC_RSP: + case LLCFT_RR + LLC_RSP: case LLCFT_RNR + LLC_CMD: - case LLCFT_RNR + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (frame_kind == LLCFT_RR) { - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else { - LLC_SET_REMOTE_BUSY(linkp, action); - } - } else if (pollfinal = 0 || - (cmdrsp == LLC_RSP && pollfinal == 1)) { - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (frame_kind == LLCFT_RR) { - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else { - LLC_SET_REMOTE_BUSY(linkp, action); + case LLCFT_RNR + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (frame_kind == LLCFT_RR) { + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else { + LLC_SET_REMOTE_BUSY(linkp,action); + } + } else if (pollfinal == 0 || + (cmdrsp == LLC_RSP && pollfinal == 1)) { + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + LLC_UPDATE_NR_RECEIVED(linkp,nr); + if (frame_kind == LLCFT_RR) { + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else { + LLC_SET_REMOTE_BUSY(linkp,action); + } } + break; } - break; - } case LLCFT_REJ + LLC_CMD: - case LLCFT_REJ + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && p == 0) || - (cmdrsp == LLC_RSP && pollfinal == p)) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if (pollfinal == 0 && p == 1) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); + case LLCFT_REJ + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp,nr); + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && + p == 0) || + (cmdrsp == LLC_RSP && pollfinal == p)) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp,nr); + LLC_UPDATE_P_FLAG(linkp,cmdrsp,pollfinal); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } else if (pollfinal == 0 && p == 1) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp,nr); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp,action); + } + break; } - break; - } case NL_INITIATE_PF_CYCLE: - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,P) == 0) { llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); action = 0; @@ -1260,40 +1360,40 @@ llc_state_BUSY(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); linkp->llcl_retry++; - LLC_NEWSTATE(linkp, AWAIT_BUSY); + LLC_NEWSTATE(linkp,AWAIT_BUSY); action = 0; } break; case LLC_ACK_TIMER_EXPIRED: case LLC_BUSY_TIMER_EXPIRED: - if (LLC_GETFLAG(linkp, P) == 0 && linkp->llcl_retry < llc_n2) { + if (LLC_GETFLAG(linkp,P) == 0 && linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); linkp->llcl_retry++; - LLC_NEWSTATE(linkp, AWAIT_BUSY); + LLC_NEWSTATE(linkp,AWAIT_BUSY); action = 0; } break; case LLC_REJ_TIMER_EXPIRED: - if (linkp->llcl_retry < llc_n2) - if (LLC_GETFLAG(linkp, P) == 0) { + if (linkp->llcl_retry < llc_n2) + if (LLC_GETFLAG(linkp,P) == 0) { /* multiple possibilities */ llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); linkp->llcl_retry++; - LLC_SETFLAG(linkp, DATA, 1); - LLC_NEWSTATE(linkp, AWAIT_BUSY); + LLC_SETFLAG(linkp,DATA,1); + LLC_NEWSTATE(linkp,AWAIT_BUSY); action = 0; - } else{ - LLC_SETFLAG(linkp, DATA, 1); - LLC_NEWSTATE(linkp, BUSY); + } else { + LLC_SETFLAG(linkp,DATA,1); + LLC_NEWSTATE(linkp,BUSY); action = 0; } - + break; } if (action == LLC_PASSITON) - action = llc_state_NBRAcore(linkp, frame, frame_kind, + action = llc_state_NBRAcore(linkp, frame, frame_kind, cmdrsp, pollfinal); return action; @@ -1306,163 +1406,168 @@ llc_state_BUSY(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * component resend a specific I PDU that the local connection * componnent has detected as being out of sequence. Both I PDUs and * supervisory PDUs may be sent and received. - */ + */ int -llc_state_REJECT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_REJECT(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = LLC_PASSITON; + int action = LLC_PASSITON; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case NL_DATA_REQUEST: - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,P) == 0) { llc_send(linkp, LLCFT_INFO, LLC_CMD, 1); LLC_START_P_TIMER(linkp); - if (LLC_TIMERXPIRED(linkp, ACK) != LLC_TIMER_RUNNING) + if (LLC_TIMERXPIRED(linkp,ACK) != LLC_TIMER_RUNNING) LLC_START_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, REJECT); + LLC_NEWSTATE(linkp,REJECT); action = 0; - } else { + } else { llc_send(linkp, LLCFT_INFO, LLC_CMD, 0); - if (LLC_TIMERXPIRED(linkp, ACK) != LLC_TIMER_RUNNING) + if (LLC_TIMERXPIRED(linkp,ACK) != LLC_TIMER_RUNNING) LLC_START_ACK_TIMER(linkp); - LLC_NEWSTATE(linkp, REJECT); + LLC_NEWSTATE(linkp,REJECT); action = 0; } break; case NL_LOCAL_BUSY_DETECTED: - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,P) == 0) { llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); - LLC_SETFLAG(linkp, DATA, 2); - LLC_NEWSTATE(linkp, BUSY); + LLC_SETFLAG(linkp,DATA,2); + LLC_NEWSTATE(linkp,BUSY); action = 0; } else { llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_SETFLAG(linkp, DATA, 2); - LLC_NEWSTATE(linkp, BUSY); + LLC_SETFLAG(linkp,DATA,2); + LLC_NEWSTATE(linkp,BUSY); action = 0; } break; case LLC_INVALID_NS + LLC_CMD: - case LLC_INVALID_NS + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + case LLC_INVALID_NS + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = 0; - } else if (pollfinal == 0 || - (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else action = 0; + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + action = 0; + } else if (pollfinal == 0 || + (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); + if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } else + action = 0; + } + break; } - break; - } case LLCFT_INFO + LLC_CMD: - case LLCFT_INFO + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - LLC_INC(linkp->llcl_vr); - LLC_SENDACKNOWLEDGE(linkp, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_STOP_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, NORMAL); - action = LLC_DATA_INDICATION; - } else if ((cmdrsp = LLC_RSP && pollfinal == p) || - (cmdrsp == LLC_CMD && pollfinal == 0 && p == 0)) { - LLC_INC(linkp->llcl_vr); - LLC_SENDACKNOWLEDGE(linkp, LLC_CMD, 1); - LLC_START_P_TIMER(linkp); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - if (cmdrsp == LLC_RSP && pollfinal == 1) - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_STOP_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, NORMAL); - action = LLC_DATA_INDICATION; - } else if (pollfinal == 0 && p == 1) { - LLC_INC(linkp->llcl_vr); - LLC_SENDACKNOWLEDGE(linkp, LLC_CMD, 0); - LLC_STOP_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, NORMAL); - action = LLC_DATA_INDICATION; + case LLCFT_INFO + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + LLC_INC(linkp->llcl_vr); + LLC_SENDACKNOWLEDGE(linkp, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_STOP_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,NORMAL); + action = LLC_DATA_INDICATION; + } else if ((cmdrsp = LLC_RSP && pollfinal == p) || + (cmdrsp == LLC_CMD && pollfinal == 0 && p == 0)) { + LLC_INC(linkp->llcl_vr); + LLC_SENDACKNOWLEDGE(linkp, LLC_CMD, 1); + LLC_START_P_TIMER(linkp); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + if (cmdrsp == LLC_RSP && pollfinal == 1) + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_STOP_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,NORMAL); + action = LLC_DATA_INDICATION; + } else if (pollfinal == 0 && p == 1) { + LLC_INC(linkp->llcl_vr); + LLC_SENDACKNOWLEDGE(linkp, LLC_CMD, 0); + LLC_STOP_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,NORMAL); + action = LLC_DATA_INDICATION; + } + break; } - break; - } case LLCFT_RR + LLC_CMD: - case LLCFT_RR + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - LLC_SENDACKNOWLEDGE(linkp, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if (pollfinal == 0 || - (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); + case LLCFT_RR + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + LLC_SENDACKNOWLEDGE(linkp, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } else if (pollfinal == 0 || + (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { + LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } + break; } - break; - } case LLCFT_RNR + LLC_CMD: - case LLCFT_RNR + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); - } else if (pollfinal == 0 || - (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = 0; + case LLCFT_RNR + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } else if (pollfinal == 0 || + (cmdrsp == LLC_RSP && pollfinal == 1 && p == 1)) { + LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + action = 0; + } + break; } - break; - } case LLCFT_REJ + LLC_CMD: - case LLCFT_REJ + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - llc_resend(linkp, LLC_RSP, 1); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && p == 0) || - (cmdrsp == LLC_RSP && pollfinal == p)) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if (pollfinal == 0 && p == 1) { - linkp->llcl_vs = nr; - LLC_UPDATE_NR_RECEIVED(linkp, nr); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); + case LLCFT_REJ + LLC_RSP:{ + register int p = LLC_GETFLAG(linkp,P); + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp, nr); + llc_resend(linkp, LLC_RSP, 1); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } else if ((cmdrsp == LLC_CMD && pollfinal == 0 && p == 0) || + (cmdrsp == LLC_RSP && pollfinal == p)) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_UPDATE_P_FLAG(linkp, cmdrsp, pollfinal); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } else if (pollfinal == 0 && p == 1) { + linkp->llcl_vs = nr; + LLC_UPDATE_NR_RECEIVED(linkp, nr); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } + break; } - break; - } case NL_INITIATE_PF_CYCLE: - if (LLC_GETFLAG(linkp, P) == 0) { + if (LLC_GETFLAG(linkp,P) == 0) { llc_send(linkp, LLCFT_RR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); action = 0; } break; case LLC_REJ_TIMER_EXPIRED: - if (LLC_GETFLAG(linkp, P) == 0 && linkp->llcl_retry < llc_n2) { + if (LLC_GETFLAG(linkp,P) == 0 && linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_REJ, LLC_CMD, 1); LLC_START_P_TIMER(linkp); LLC_START_REJ_TIMER(linkp); @@ -1475,31 +1580,30 @@ llc_state_REJECT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, LLC_START_P_TIMER(linkp); LLC_START_REJ_TIMER(linkp); linkp->llcl_retry++; - LLC_NEWSTATE(linkp, AWAIT_REJECT); + LLC_NEWSTATE(linkp,AWAIT_REJECT); action = 0; } break; case LLC_ACK_TIMER_EXPIRED: case LLC_BUSY_TIMER_EXPIRED: - if (LLC_GETFLAG(linkp, P) == 0 && linkp->llcl_retry < llc_n2) { + if (LLC_GETFLAG(linkp,P) == 0 && linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_RR, LLC_CMD, 1); LLC_START_P_TIMER(linkp); LLC_START_REJ_TIMER(linkp); linkp->llcl_retry++; - /* - * I cannot locate the description of RESET_V(S) - * in ISO 8802-2, table 7-1, state REJECT, last event, + /* + * I cannot locate the description of RESET_V(S) in + * ISO 8802-2, table 7-1, state REJECT, last event, * and assume they meant to set V(S) to 0 ... */ - linkp->llcl_vs = 0; /* XXX */ - LLC_NEWSTATE(linkp, AWAIT_REJECT); + linkp->llcl_vs = 0; /* XXX */ + LLC_NEWSTATE(linkp,AWAIT_REJECT); action = 0; } - break; } if (action == LLC_PASSITON) - action = llc_state_NBRAcore(linkp, frame, frame_kind, + action = llc_state_NBRAcore(linkp, frame, frame_kind, cmdrsp, pollfinal); return action; @@ -1514,117 +1618,129 @@ llc_state_REJECT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * Supervisory PDUs may be both sent and received. */ int -llc_state_AWAIT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_AWAIT(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = LLC_PASSITON; + int action = LLC_PASSITON; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case LLC_LOCAL_BUSY_DETECTED: llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_SETFLAG(linkp, DATA, 0); - LLC_NEWSTATE(linkp, AWAIT_BUSY); + LLC_SETFLAG(linkp,DATA,0); + LLC_NEWSTATE(linkp,AWAIT_BUSY); action = 0; break; case LLC_INVALID_NS + LLC_CMD: - case LLC_INVALID_NS + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_REJ, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_START_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, AWAIT_REJECT); - action = 0; - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - llc_resend(linkp, LLC_CMD, 0); - LLC_START_REJ_TIMER(linkp); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, REJECT); - } else if (pollfinal == 0) { - llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_START_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, AWAIT_REJECT); - action = 0; + case LLC_INVALID_NS + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_REJ, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_START_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,AWAIT_REJECT); + action = 0; + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + llc_resend(linkp, LLC_CMD, 0); + LLC_START_REJ_TIMER(linkp); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_NEWSTATE(linkp,REJECT); + } else if (pollfinal == 0) { + llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_START_REJ_TIMER(linkp); + LLC_NEWSTATE(linkp,AWAIT_REJECT); + action = 0; + } + break; } - break; - } case LLCFT_INFO + LLC_RSP: - case LLCFT_INFO + LLC_CMD: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - LLC_INC(linkp->llcl_vr); - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = LLC_DATA_INDICATION; - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - llc_resend(linkp, LLC_CMD, 1); - LLC_START_P_TIMER(linkp); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, NORMAL); - action = LLC_DATA_INDICATION; - } else if (pollfinal == 0) { - llc_send(linkp, LLCFT_RR, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = LLC_DATA_INDICATION; + case LLCFT_INFO + LLC_CMD:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + LLC_INC(linkp->llcl_vr); + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + action = LLC_DATA_INDICATION; + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + llc_resend(linkp, LLC_CMD, 1); + LLC_START_P_TIMER(linkp); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_NEWSTATE(linkp,NORMAL); + action = LLC_DATA_INDICATION; + } else if (pollfinal == 0) { + llc_send(linkp, LLCFT_RR, LLC_CMD, 0); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + action = LLC_DATA_INDICATION; + } + break; } - break; - } case LLCFT_RR + LLC_CMD: case LLCFT_RR + LLC_RSP: case LLCFT_REJ + LLC_CMD: - case LLCFT_REJ + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, NORMAL); - } else if (pollfinal == 0) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } - break; - } + case LLCFT_REJ + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_NEWSTATE(linkp,NORMAL); + } else if (pollfinal == 0) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } + break; + } case LLCFT_RNR + LLC_CMD: - case LLCFT_RNR + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (pollfinal == 1 && cmdrsp == LLC_CMD) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); - } else if (pollfinal == 1 && cmdrsp == LLC_RSP) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - LLC_SET_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, NORMAL); - } else if (pollfinal == 0) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); + case LLCFT_RNR + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (pollfinal == 1 && cmdrsp == LLC_CMD) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } else if (pollfinal == 1 && cmdrsp == LLC_RSP) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + LLC_SET_REMOTE_BUSY(linkp,action); + LLC_NEWSTATE(linkp,NORMAL); + } else if (pollfinal == 0) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } + break; } - break; - } case LLC_P_TIMER_EXPIRED: if (linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_RR, LLC_CMD, 1); @@ -1635,7 +1751,7 @@ llc_state_AWAIT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, break; } if (action == LLC_PASSITON) - action = llc_state_NBRAcore(linkp, frame, frame_kind, + action = llc_state_NBRAcore(linkp, frame, frame_kind, cmdrsp, pollfinal); return action; @@ -1652,139 +1768,151 @@ llc_state_AWAIT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, * Supervisory PDUs may be both sent and received. */ int -llc_state_AWAIT_BUSY(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_AWAIT_BUSY(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = LLC_PASSITON; + int action = LLC_PASSITON; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case LLC_LOCAL_BUSY_CLEARED: - switch (LLC_GETFLAG(linkp, DATA)) { + switch (LLC_GETFLAG(linkp,DATA)) { case 1: llc_send(linkp, LLCFT_REJ, LLC_CMD, 0); LLC_START_REJ_TIMER(linkp); - LLC_NEWSTATE(linkp, AWAIT_REJECT); + LLC_NEWSTATE(linkp,AWAIT_REJECT); action = 0; break; case 0: llc_send(linkp, LLCFT_RR, LLC_CMD, 0); - LLC_NEWSTATE(linkp, AWAIT); + LLC_NEWSTATE(linkp,AWAIT); action = 0; break; case 2: llc_send(linkp, LLCFT_RR, LLC_CMD, 0); - LLC_NEWSTATE(linkp, AWAIT_REJECT); + LLC_NEWSTATE(linkp,AWAIT_REJECT); action = 0; break; } break; case LLC_INVALID_NS + LLC_CMD: - case LLC_INVALID_NS + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SETFLAG(linkp, DATA, 1); - action = 0; - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - /* optionally */ - llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - LLC_SETFLAG(linkp, DATA, 1); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - llc_resend(linkp, LLC_CMD, 0); - LLC_NEWSTATE(linkp, BUSY); - } else if (pollfinal == 0) { - /* optionally */ - llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SETFLAG(linkp, DATA, 1); - action = 0; + case LLC_INVALID_NS + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SETFLAG(linkp,DATA,1); + action = 0; + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + /* optionally */ + llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + LLC_SETFLAG(linkp,DATA,1); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + llc_resend(linkp, LLC_CMD, 0); + LLC_NEWSTATE(linkp,BUSY); + } else if (pollfinal == 0) { + /* optionally */ + llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SETFLAG(linkp,DATA,1); + action = 0; + } } - } case LLCFT_INFO + LLC_CMD: - case LLCFT_INFO + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_INC(linkp->llcl_vr); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SETFLAG(linkp, DATA, 0); - action = LLC_DATA_INDICATION; - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); - LLC_INC(linkp->llcl_vr); - LLC_START_P_TIMER(linkp); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_SETFLAG(linkp, DATA, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - llc_resend(linkp, LLC_CMD, 0); - LLC_NEWSTATE(linkp, BUSY); - action = LLC_DATA_INDICATION; - } else if (pollfinal == 0) { - llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_INC(linkp->llcl_vr); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SETFLAG(linkp, DATA, 0); - action = LLC_DATA_INDICATION; + case LLCFT_INFO + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_INC(linkp->llcl_vr); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SETFLAG(linkp,DATA,0); + action = LLC_DATA_INDICATION; + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); + LLC_INC(linkp->llcl_vr); + LLC_START_P_TIMER(linkp); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_SETFLAG(linkp,DATA,0); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + llc_resend(linkp, LLC_CMD, 0); + LLC_NEWSTATE(linkp,BUSY); + action = LLC_DATA_INDICATION; + } else if (pollfinal == 0) { + llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); + LLC_INC(linkp->llcl_vr); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SETFLAG(linkp,DATA,0); + action = LLC_DATA_INDICATION; + } + break; } - break; - } case LLCFT_RR + LLC_CMD: case LLCFT_REJ + LLC_CMD: case LLCFT_RR + LLC_RSP: - case LLCFT_REJ + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, BUSY); - } else if (pollfinal == 0) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); + case LLCFT_REJ + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_NEWSTATE(linkp,BUSY); + } else if (pollfinal == 0) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } + break; } - break; - } case LLCFT_RNR + LLC_CMD: - case LLCFT_RNR + LLC_RSP: { - register int p = LLC_GETFLAG(linkp, P); - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - LLC_SET_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, BUSY); - } else if (pollfinal == 0) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); + case LLCFT_RNR + LLC_RSP:{ +#if 0 + register int p = LLC_GETFLAG(linkp,P); +#endif + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RNR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + LLC_SET_REMOTE_BUSY(linkp,action); + LLC_NEWSTATE(linkp,BUSY); + } else if (pollfinal == 0) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } + break; } - break; - } case LLC_P_TIMER_EXPIRED: if (linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_RNR, LLC_CMD, 1); @@ -1795,7 +1923,7 @@ llc_state_AWAIT_BUSY(struct llc_linkcb *linkp, struct llc *frame, int frame_kind break; } if (action == LLC_PASSITON) - action = llc_state_NBRAcore(linkp, frame, frame_kind, + action = llc_state_NBRAcore(linkp, frame, frame_kind, cmdrsp, pollfinal); return action; @@ -1815,113 +1943,118 @@ llc_state_AWAIT_BUSY(struct llc_linkcb *linkp, struct llc *frame, int frame_kind * both transmitted and received. */ int -llc_state_AWAIT_REJECT(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_state_AWAIT_REJECT(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - int action = LLC_PASSITON; + int action = LLC_PASSITON; - switch(frame_kind + cmdrsp) { + switch (frame_kind + cmdrsp) { case LLC_LOCAL_BUSY_DETECTED: llc_send(linkp, LLCFT_RNR, LLC_CMD, 0); - LLC_SETFLAG(linkp, DATA, 2); - LLC_NEWSTATE(linkp, AWAIT_BUSY); + LLC_SETFLAG(linkp,DATA,2); + LLC_NEWSTATE(linkp,AWAIT_BUSY); action = 0; break; case LLC_INVALID_NS + LLC_CMD: - case LLC_INVALID_NS + LLC_RSP: { - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = 0; - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - llc_resend(linkp, LLC_CMD, 1); - LLC_START_P_TIMER(linkp); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, REJECT); - } else if (pollfinal == 0) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - action = 0; + case LLC_INVALID_NS + LLC_RSP:{ + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + action = 0; + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + llc_resend(linkp, LLC_CMD, 1); + LLC_START_P_TIMER(linkp); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_NEWSTATE(linkp,REJECT); + } else if (pollfinal == 0) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + action = 0; + } + break; } - break; - } case LLCFT_INFO + LLC_CMD: - case LLCFT_INFO + LLC_RSP: { - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + case LLCFT_INFO + LLC_RSP:{ + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - if (cmdrsp == LLC_CMD && pollfinal == 1) { - LLC_INC(linkp->llcl_vr); - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_STOP_REJ_TIMER(linkp); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_NEWSTATE(linkp, AWAIT); - action = LLC_DATA_INDICATION; - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_INC(linkp->llcl_vr); - LLC_STOP_P_TIMER(linkp); - LLC_STOP_REJ_TIMER(linkp); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - llc_resend(linkp, LLC_CMD, 0); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, NORMAL); - action = LLC_DATA_INDICATION; - } else if (pollfinal == 0) { - LLC_INC(linkp->llcl_vr); - llc_send(linkp, LLCFT_RR, LLC_CMD, 0); - LLC_STOP_REJ_TIMER(linkp); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_NEWSTATE(linkp, AWAIT); - action = LLC_DATA_INDICATION; + if (cmdrsp == LLC_CMD && pollfinal == 1) { + LLC_INC(linkp->llcl_vr); + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_STOP_REJ_TIMER(linkp); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_NEWSTATE(linkp,AWAIT); + action = LLC_DATA_INDICATION; + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_INC(linkp->llcl_vr); + LLC_STOP_P_TIMER(linkp); + LLC_STOP_REJ_TIMER(linkp); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + llc_resend(linkp, LLC_CMD, 0); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_NEWSTATE(linkp,NORMAL); + action = LLC_DATA_INDICATION; + } else if (pollfinal == 0) { + LLC_INC(linkp->llcl_vr); + llc_send(linkp, LLCFT_RR, LLC_CMD, 0); + LLC_STOP_REJ_TIMER(linkp); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_NEWSTATE(linkp,AWAIT); + action = LLC_DATA_INDICATION; + } + break; } - break; - } case LLCFT_RR + LLC_CMD: case LLCFT_REJ + LLC_CMD: case LLCFT_RR + LLC_RSP: - case LLCFT_REJ + LLC_RSP: { - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - llc_resend(linkp, LLC_CMD, 1); - LLC_START_P_TIMER(linkp); - LLC_CLEAR_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, REJECT); - } else if (pollfinal == 0) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_CLEAR_REMOTE_BUSY(linkp, action); + case LLCFT_REJ + LLC_RSP:{ + register int nr = LLCGBITS(frame->llc_control_ext, s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + llc_resend(linkp, LLC_CMD, 1); + LLC_START_P_TIMER(linkp); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + LLC_NEWSTATE(linkp,REJECT); + } else if (pollfinal == 0) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_CLEAR_REMOTE_BUSY(linkp, action); + } + break; } - break; - } case LLCFT_RNR + LLC_CMD: - case LLCFT_RNR + LLC_RSP: { - register int nr = LLCGBITS(frame->llc_control_ext, s_nr); - - if (cmdrsp == LLC_CMD && pollfinal == 1) { - llc_send(linkp, LLCFT_RR, LLC_RSP, 1); - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); - } else if (cmdrsp == LLC_RSP && pollfinal == 1) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - linkp->llcl_vs = nr; - LLC_STOP_P_TIMER(linkp); - LLC_SET_REMOTE_BUSY(linkp, action); - LLC_NEWSTATE(linkp, REJECT); - } else if (pollfinal == 0) { - LLC_UPDATE_NR_RECEIVED(linkp, nr); - LLC_SET_REMOTE_BUSY(linkp, action); + case LLCFT_RNR + LLC_RSP:{ + register int nr = + LLCGBITS(frame->llc_control_ext,s_nr); + + if (cmdrsp == LLC_CMD && pollfinal == 1) { + llc_send(linkp, LLCFT_RR, LLC_RSP, 1); + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } else if (cmdrsp == LLC_RSP && pollfinal == 1) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + linkp->llcl_vs = nr; + LLC_STOP_P_TIMER(linkp); + LLC_SET_REMOTE_BUSY(linkp,action); + LLC_NEWSTATE(linkp,REJECT); + } else if (pollfinal == 0) { + LLC_UPDATE_NR_RECEIVED(linkp, nr); + LLC_SET_REMOTE_BUSY(linkp,action); + } + break; } - break; - } case LLC_P_TIMER_EXPIRED: if (linkp->llcl_retry < llc_n2) { llc_send(linkp, LLCFT_REJ, LLC_CMD, 1); @@ -1932,7 +2065,7 @@ llc_state_AWAIT_REJECT(struct llc_linkcb *linkp, struct llc *frame, int frame_ki break; } if (action == LLC_PASSITON) - action = llc_state_NBRAcore(linkp, frame, frame_kind, + action = llc_state_NBRAcore(linkp, frame, frame_kind, cmdrsp, pollfinal); return action; @@ -1946,39 +2079,44 @@ llc_state_AWAIT_REJECT(struct llc_linkcb *linkp, struct llc *frame, int frame_ki */ int -llc_statehandler(struct llc_linkcb *linkp, struct llc *frame, int frame_kind, - int cmdrsp, int pollfinal) +llc_statehandler(linkp, frame, frame_kind, cmdrsp, pollfinal) + struct llc_linkcb *linkp; + struct llc *frame; + int frame_kind; + int cmdrsp; + int pollfinal; { - register int action = 0; + register int action = 0; /* * To check for ``zombie'' links each time llc_statehandler() gets called * the AGE timer of linkp is reset. If it expires llc_timer() will * take care of the link --- i.e. kill it 8=) */ - LLC_STARTTIMER(linkp, AGE); + LLC_STARTTIMER(linkp,AGE); /* * Now call the current statehandler function. */ - action = (*linkp->llcl_statehandler)(linkp, frame, frame_kind, - cmdrsp, pollfinal); + action = (*linkp->llcl_statehandler) (linkp, frame, frame_kind, + cmdrsp, pollfinal); once_more_and_again: switch (action) { - case LLC_CONNECT_INDICATION: { - int naction; - - LLC_TRACE(linkp, LLCTR_INTERESTING, "CONNECT INDICATION"); - linkp->llcl_nlnext = - (*linkp->llcl_sapinfo->si_ctlinput) - (PRC_CONNECT_INDICATION, - (struct sockaddr *) &linkp->llcl_addr, (caddr_t) linkp); - if (linkp->llcl_nlnext == 0) - naction = NL_DISCONNECT_REQUEST; - else naction = NL_CONNECT_RESPONSE; - action = (*linkp->llcl_statehandler)(linkp, frame, naction, 0, 0); - goto once_more_and_again; - } + case LLC_CONNECT_INDICATION:{ + int naction; + + LLC_TRACE(linkp, LLCTR_INTERESTING, "CONNECT INDICATION"); + linkp->llcl_nlnext = + (*linkp->llcl_sapinfo->si_ctlinput) + (PRC_CONNECT_INDICATION, + (struct sockaddr *) & linkp->llcl_addr, (caddr_t) linkp); + if (linkp->llcl_nlnext == 0) + naction = NL_DISCONNECT_REQUEST; + else + naction = NL_CONNECT_RESPONSE; + action = (*linkp->llcl_statehandler) (linkp, frame, naction, 0, 0); + goto once_more_and_again; + } case LLC_CONNECT_CONFIRM: /* llc_resend(linkp, LLC_CMD, 0); */ llc_start(linkp); @@ -1986,10 +2124,10 @@ once_more_and_again: case LLC_DISCONNECT_INDICATION: LLC_TRACE(linkp, LLCTR_INTERESTING, "DISCONNECT INDICATION"); (*linkp->llcl_sapinfo->si_ctlinput) - (PRC_DISCONNECT_INDICATION, - (struct sockaddr *) &linkp->llcl_addr, linkp->llcl_nlnext); + (PRC_DISCONNECT_INDICATION, + (struct sockaddr *) & linkp->llcl_addr, linkp->llcl_nlnext); break; - /* internally visible only */ + /* internally visible only */ case LLC_RESET_CONFIRM: case LLC_RESET_INDICATION_LOCAL: /* @@ -1999,17 +2137,17 @@ once_more_and_again: break; case LLC_RESET_INDICATION_REMOTE: LLC_TRACE(linkp, LLCTR_SHOULDKNOW, "RESET INDICATION (REMOTE)"); - action = (*linkp->llcl_statehandler)(linkp, frame, - NL_RESET_RESPONSE, 0, 0); + action = (*linkp->llcl_statehandler) (linkp, frame, + NL_RESET_RESPONSE, 0, 0); goto once_more_and_again; case LLC_FRMR_SENT: LLC_TRACE(linkp, LLCTR_URGENT, "FRMR SENT"); break; case LLC_FRMR_RECEIVED: LLC_TRACE(linkp, LLCTR_URGEN, "FRMR RECEIVED"); - action = (*linkp->llcl_statehandler)(linkp, frame, - NL_RESET_REQUEST, 0, 0); - + action = (*linkp->llcl_statehandler) (linkp, frame, + NL_RESET_REQUEST, 0, 0); + goto once_more_and_again; case LLC_REMOTE_BUSY: LLC_TRACE(linkp, LLCTR_SHOULDKNOW, "REMOTE BUSY"); @@ -2021,12 +2159,12 @@ once_more_and_again: */ llc_start(linkp); break; - } + } /* * Only LLC_DATA_INDICATION is for the time being * passed up to the network layer entity. - * The remaining action codes are for the time + * The remaining action codes are for the time * being visible internally only. * However, this can/may be changed if necessary. */ @@ -2037,12 +2175,13 @@ once_more_and_again: /* * Core LLC2 routines - */ + */ /* * The INIT call. This routine is called once after the system is booted. */ +void llc_init() { llcintrq.ifq_maxlen = IFQ_MAXLEN; @@ -2055,22 +2194,24 @@ llc_init() */ void -llc_resetwindow(struct llc_linkcb *linkp) +llc_resetwindow(linkp) + struct llc_linkcb *linkp; { register struct mbuf *mptr = (struct mbuf *) 0; - register struct mbuf *anchor = (struct mbuf *)0; - register short i; + register struct mbuf *anchor = (struct mbuf *) 0; + register short i; /* Pick up all queued frames and collect them in a linked mbuf list */ if (linkp->llcl_slotsfree != linkp->llcl_window) { i = llc_seq2slot(linkp, linkp->llcl_nr_received); - anchor = mptr = linkp->llcl_output_buffers[i]; - for (; i != linkp->llcl_freeslot; - i = llc_seq2slot(linkp, i+1)) { + anchor = mptr = linkp->llcl_output_buffers[i]; + for (; i != linkp->llcl_freeslot; + i = llc_seq2slot(linkp, i + 1)) { if (linkp->llcl_output_buffers[i]) { mptr->m_nextpkt = linkp->llcl_output_buffers[i]; mptr = mptr->m_nextpkt; - } else panic("LLC2 window broken"); + } else + panic("LLC2 window broken"); } } /* clean closure */ @@ -2078,36 +2219,44 @@ llc_resetwindow(struct llc_linkcb *linkp) mptr->m_nextpkt = (struct mbuf *) 0; /* Now --- plug 'em in again */ - if (anchor != (struct mbuf *)0) { + if (anchor != (struct mbuf *) 0) { for (i = 0, mptr = anchor; mptr != (struct mbuf *) 0; i++) { linkp->llcl_output_buffers[i] = mptr; mptr = mptr->m_nextpkt; - linkp->llcl_output_buffers[i]->m_nextpkt = (struct mbuf *)0; + linkp->llcl_output_buffers[i]->m_nextpkt = (struct mbuf *) 0; } linkp->llcl_freeslot = i; - } else linkp->llcl_freeslot = 0; - + } else + linkp->llcl_freeslot = 0; + /* We're resetting the link, the next frame to be acknowledged is 0 */ linkp->llcl_nr_received = 0; - /* set distance between LLC2 sequence number and the top of window to 0 */ + /* + * set distance between LLC2 sequence number and the top of window to + * 0 + */ linkp->llcl_projvs = linkp->llcl_freeslot; return; } - + /* * llc_newlink() --- We allocate enough memory to contain a link control block - * and initialize it properly. We don't intiate the actual setup - * of the LLC2 link here. + * and initialize it properly. We don't intiate the actual + * setup of the LLC2 link here. */ struct llc_linkcb * -llc_newlink(struct sockaddr_dl *dst, struct ifnet *ifp, struct rtentry *nlrt, - caddr_t nlnext, struct rtentry *llrt) +llc_newlink(dst, ifp, nlrt, nlnext, llrt) + struct sockaddr_dl *dst; + struct ifnet *ifp; + struct rtentry *nlrt; + caddr_t nlnext; + struct rtentry *llrt; { struct llc_linkcb *nlinkp; - u_char sap = LLSAPADDR(dst); - short llcwindow; + u_char sap = LLSAPADDR(dst); + short llcwindow; /* allocate memory for link control block */ @@ -2115,8 +2264,8 @@ llc_newlink(struct sockaddr_dl *dst, struct ifnet *ifp, struct rtentry *nlrt, M_PCB, M_DONTWAIT); if (nlinkp == 0) return (NULL); - bzero((caddr_t)nlinkp, sizeof(struct llc_linkcb)); - + bzero((caddr_t) nlinkp, sizeof(struct llc_linkcb)); + /* copy link address */ sdl_copy(dst, &nlinkp->llcl_addr); @@ -2134,7 +2283,7 @@ llc_newlink(struct sockaddr_dl *dst, struct ifnet *ifp, struct rtentry *nlrt, /* setup initial state handler function */ nlinkp->llcl_statehandler = llc_state_ADM; - + /* hold on to interface pointer */ nlinkp->llcl_if = ifp; @@ -2146,14 +2295,14 @@ llc_newlink(struct sockaddr_dl *dst, struct ifnet *ifp, struct rtentry *nlrt, llcwindow = LLC_MAX_WINDOW; /* allocate memory for window buffer */ - MALLOC(nlinkp->llcl_output_buffers, struct mbuf **, - llcwindow*sizeof(struct mbuf *), M_PCB, M_DONTWAIT); + MALLOC(nlinkp->llcl_output_buffers, struct mbuf **, + llcwindow * sizeof(struct mbuf *), M_PCB, M_DONTWAIT); if (nlinkp->llcl_output_buffers == 0) { FREE(nlinkp, M_PCB); - return(NULL); + return (NULL); } - bzero((caddr_t)nlinkp->llcl_output_buffers, - llcwindow*sizeof(struct mbuf *)); + bzero((caddr_t) nlinkp->llcl_output_buffers, + llcwindow * sizeof(struct mbuf *)); /* set window size & slotsfree */ nlinkp->llcl_slotsfree = nlinkp->llcl_window = llcwindow; @@ -2161,28 +2310,30 @@ llc_newlink(struct sockaddr_dl *dst, struct ifnet *ifp, struct rtentry *nlrt, /* enter into linked listed of link control blocks */ insque(nlinkp, &llccb_q); - return(nlinkp); + return (nlinkp); } /* * llc_dellink() --- farewell to link control block */ -llc_dellink(struct llc_linkcb *linkp) +void +llc_dellink(linkp) + struct llc_linkcb *linkp; { register struct mbuf *m; register struct mbuf *n; register struct npaidbentry *sapinfo = linkp->llcl_sapinfo; - register i; + register i; /* notify upper layer of imminent death */ if (linkp->llcl_nlnext && sapinfo->si_ctlinput) (*sapinfo->si_ctlinput) - (PRC_DISCONNECT_INDICATION, - (struct sockaddr *)&linkp->llcl_addr, linkp->llcl_nlnext); + (PRC_DISCONNECT_INDICATION, + (struct sockaddr *) & linkp->llcl_addr, linkp->llcl_nlnext); /* pull the plug */ if (linkp->llcl_llrt) - ((struct npaidbentry *)(linkp->llcl_llrt->rt_llinfo))->np_link + ((struct npaidbentry *) (linkp->llcl_llrt->rt_llinfo))->np_link = (struct llc_linkcb *) 0; /* leave link control block queue */ @@ -2196,54 +2347,81 @@ llc_dellink(struct llc_linkcb *linkp) } /* drop packets in the window */ - for(i = 0; i < linkp->llcl_window; i++) + for (i = 0; i < linkp->llcl_window; i++) if (linkp->llcl_output_buffers[i]) m_freem(linkp->llcl_output_buffers[i]); /* return the window space */ - FREE((caddr_t)linkp->llcl_output_buffers, M_PCB); + FREE((caddr_t) linkp->llcl_output_buffers, M_PCB); /* return the control block space --- now it's gone ... */ - FREE((caddr_t)linkp, M_PCB); + FREE((caddr_t) linkp, M_PCB); } -llc_decode(struct llc* frame, struct llc_linkcb * linkp) +int +llc_decode(frame, linkp) + struct llc *frame; + struct llc_linkcb *linkp; { - register int ft = LLC_BAD_PDU; + register int ft = LLC_BAD_PDU; if ((frame->llc_control & 01) == 0) { ft = LLCFT_INFO; - /* S or U frame ? */ - } else switch (frame->llc_control) { - - /* U frames */ - case LLC_UI: - case LLC_UI_P: ft = LLC_UI; break; - case LLC_DM: - case LLC_DM_P: ft =LLCFT_DM; break; - case LLC_DISC: - case LLC_DISC_P: ft = LLCFT_DISC; break; - case LLC_UA: - case LLC_UA_P: ft = LLCFT_UA; break; - case LLC_SABME: - case LLC_SABME_P: ft = LLCFT_SABME; break; - case LLC_FRMR: - case LLC_FRMR_P: ft = LLCFT_FRMR; break; - case LLC_XID: - case LLC_XID_P: ft = LLCFT_XID; break; - case LLC_TEST: - case LLC_TEST_P: ft = LLCFT_TEST; break; - - /* S frames */ - case LLC_RR: ft = LLCFT_RR; break; - case LLC_RNR: ft = LLCFT_RNR; break; - case LLC_REJ: ft = LLCFT_REJ; break; - } /* switch */ + /* S or U frame ? */ + } else + switch (frame->llc_control) { + + /* U frames */ + case LLC_UI: + case LLC_UI_P: + ft = LLC_UI; + break; + case LLC_DM: + case LLC_DM_P: + ft = LLCFT_DM; + break; + case LLC_DISC: + case LLC_DISC_P: + ft = LLCFT_DISC; + break; + case LLC_UA: + case LLC_UA_P: + ft = LLCFT_UA; + break; + case LLC_SABME: + case LLC_SABME_P: + ft = LLCFT_SABME; + break; + case LLC_FRMR: + case LLC_FRMR_P: + ft = LLCFT_FRMR; + break; + case LLC_XID: + case LLC_XID_P: + ft = LLCFT_XID; + break; + case LLC_TEST: + case LLC_TEST_P: + ft = LLCFT_TEST; + break; + + /* S frames */ + case LLC_RR: + ft = LLCFT_RR; + break; + case LLC_RNR: + ft = LLCFT_RNR; + break; + case LLC_REJ: + ft = LLCFT_REJ; + break; + } /* switch */ if (linkp) { switch (ft) { case LLCFT_INFO: - if (LLCGBITS(frame->llc_control, i_ns) != linkp->llcl_vr) { + if (LLCGBITS(frame->llc_control,i_ns) != + linkp->llcl_vr) { ft = LLC_INVALID_NS; break; } @@ -2252,13 +2430,13 @@ llc_decode(struct llc* frame, struct llc_linkcb * linkp) case LLCFT_RNR: case LLCFT_REJ: /* splash! */ - if (LLC_NR_VALID(linkp, LLCGBITS(frame->llc_control_ext, - s_nr)) == 0) + if (LLC_NR_VALID(linkp, + LLCGBITS(frame->llc_control_ext,s_nr)) + == 0) ft = LLC_INVALID_NR; break; } } - return ft; } @@ -2266,16 +2444,18 @@ llc_decode(struct llc* frame, struct llc_linkcb * linkp) * llc_anytimersup() --- Checks if at least one timer is still up and running. */ int -llc_anytimersup(struct llc_linkcb * linkp) +llc_anytimersup(linkp) + struct llc_linkcb *linkp; { - register int i; - + register int i; + FOR_ALL_LLC_TIMERS(i) if (linkp->llcl_timers[i] > 0) - break; + break; if (i == LLC_AGE_SHIFT) return 0; - else return 1; + else + return 1; } /* @@ -2283,63 +2463,66 @@ llc_anytimersup(struct llc_linkcb * linkp) */ #define SAL(s) ((struct sockaddr_dl *)&(s)->llcl_addr) -#define CHECK(l, s) if (LLC_STATEEQ(l, s)) return #s +#define CHECK(l,s) if (LLC_STATEEQ(l,s)) return __STRING(s) char *timer_names[] = {"ACK", "P", "BUSY", "REJ", "AGE"}; char * -llc_getstatename(struct llc_linkcb *linkp) +llc_getstatename(linkp) + struct llc_linkcb *linkp; { - CHECK(linkp, ADM); - CHECK(linkp, CONN); - CHECK(linkp, RESET_WAIT); - CHECK(linkp, RESET_CHECK); - CHECK(linkp, SETUP); - CHECK(linkp, RESET); - CHECK(linkp, D_CONN); - CHECK(linkp, ERROR); - CHECK(linkp, NORMAL); - CHECK(linkp, BUSY); - CHECK(linkp, REJECT); - CHECK(linkp, AWAIT); - CHECK(linkp, AWAIT_BUSY); - CHECK(linkp, AWAIT_REJECT); + CHECK(linkp,ADM); + CHECK(linkp,CONN); + CHECK(linkp,RESET_WAIT); + CHECK(linkp,RESET_CHECK); + CHECK(linkp,SETUP); + CHECK(linkp,RESET); + CHECK(linkp,D_CONN); + CHECK(linkp,ERROR); + CHECK(linkp,NORMAL); + CHECK(linkp,BUSY); + CHECK(linkp,REJECT); + CHECK(linkp,AWAIT); + CHECK(linkp,AWAIT_BUSY); + CHECK(linkp,AWAIT_REJECT); return "UNKNOWN - eh?"; } void -llc_link_dump(struct llc_linkcb* linkp, const char *message) +llc_link_dump(linkp, message) + struct llc_linkcb *linkp; + const char *message; { - register int i; - register char *state; + register int i; /* print interface */ printf("if %s%d\n", linkp->llcl_if->if_name, linkp->llcl_if->if_unit); - + /* print message */ printf(">> %s <<\n", message); /* print MAC and LSAP */ printf("llc addr "); - for (i = 0; i < (SAL(linkp)->sdl_alen)-2; i++) - printf("%x:", (char)*(LLADDR(SAL(linkp))+i) & 0xff); - printf("%x,", (char)*(LLADDR(SAL(linkp))+i) & 0xff); - printf("%x\n", (char)*(LLADDR(SAL(linkp))+i+1) & 0xff); + for (i = 0; i < (SAL(linkp)->sdl_alen) - 2; i++) + printf("%x:", (char) *(LLADDR(SAL(linkp)) + i) & 0xff); + printf("%x,", (char) *(LLADDR(SAL(linkp)) + i) & 0xff); + printf("%x\n", (char) *(LLADDR(SAL(linkp)) + i + 1) & 0xff); /* print state we're in and timers */ - printf("state %s, ", llc_getstatename(linkp)); - for (i = LLC_ACK_SHIFT; i < LLC_AGE_SHIFT; i++) - printf("%s-%c %d/", timer_names[i], - (linkp->llcl_timerflags & (1<llcl_timerflags & (1 << i) ? 'R' : 'S'), linkp->llcl_timers[i]); - printf("%s-%c %d\n", timer_names[i], (linkp->llcl_timerflags & (1<llcl_timers[i]); + printf("%s-%c %d\n", timer_names[i], (linkp->llcl_timerflags & (1 << i) ? + 'R' : 'S'), linkp->llcl_timers[i]); /* print flag values */ printf("flags P %d/F %d/S %d/DATA %d/REMOTE_BUSY %d\n", - LLC_GETFLAG(linkp, P), LLC_GETFLAG(linkp, S), - LLC_GETFLAG(linkp, DATA), LLC_GETFLAG(linkp, REMOTE_BUSY)); + LLC_GETFLAG(linkp,P), LLC_GETFLAG(linkp,F), + LLC_GETFLAG(linkp,S), + LLC_GETFLAG(linkp,DATA), LLC_GETFLAG(linkp,REMOTE_BUSY)); /* print send and receive state variables, ack, and window */ printf("V(R) %d/V(S) %d/N(R) received %d/window %d/freeslot %d\n", @@ -2351,10 +2534,11 @@ llc_link_dump(struct llc_linkcb* linkp, const char *message) } void -llc_trace(struct llc_linkcb *linkp, int level, const char *message) +llc_trace(linkp, level, message) + struct llc_linkcb *linkp; + int level; + const char *message; { if (linkp->llcl_sapinfo->si_trace && level > llc_tracelevel) llc_link_dump(linkp, message); - - return; } diff --git a/sys/netccitt/llc_timer.c b/sys/netccitt/llc_timer.c index a404da99591..d6f27fde34d 100644 --- a/sys/netccitt/llc_timer.c +++ b/sys/netccitt/llc_timer.c @@ -1,4 +1,5 @@ -/* $NetBSD: llc_timer.c,v 1.2 1994/06/29 06:37:26 cgd Exp $ */ +/* $OpenBSD: llc_timer.c,v 1.2 1996/03/04 07:36:34 niklas Exp $ */ +/* $NetBSD: llc_timer.c,v 1.3 1996/02/13 22:04:57 christos Exp $ */ /* * Copyright (C) Dirk Husemann, Computer Science Department IV, @@ -102,15 +103,15 @@ llc_timer() * Check implementation specific timers first */ /* The delayed action/acknowledge idle timer */ - switch (LLC_TIMERXPIRED(linkp, DACTION)) { + switch (LLC_TIMERXPIRED(linkp,DACTION)) { case LLC_TIMER_RUNNING: - LLC_AGETIMER(linkp, DACTION); + LLC_AGETIMER(linkp,DACTION); break; case LLC_TIMER_EXPIRED: { register int cmdrsp; register int pollfinal; - switch (LLC_GETFLAG(linkp, DACTION)) { + switch (LLC_GETFLAG(linkp,DACTION)) { case LLC_DACKCMD: cmdrsp = LLC_CMD, pollfinal = 0; break; @@ -123,16 +124,19 @@ llc_timer() case LLC_DACKRSPFINAL: cmdrsp = LLC_RSP, pollfinal = 1; break; + default: + panic("Unexpected LLC_GETFLAG"); + return; } llc_send(linkp, LLCFT_RR, cmdrsp, pollfinal); - LLC_STOPTIMER(linkp, DACTION); + LLC_STOPTIMER(linkp,DACTION); break; } } /* The link idle timer */ - switch (LLC_TIMERXPIRED(linkp, AGE)) { + switch (LLC_TIMERXPIRED(linkp,AGE)) { case LLC_TIMER_RUNNING: - LLC_AGETIMER(linkp, AGE); + LLC_AGETIMER(linkp,AGE); break; case LLC_TIMER_EXPIRED: /* @@ -141,10 +145,10 @@ llc_timer() */ if (llc_anytimersup(linkp) == 0) { llc_dellink(linkp); - LLC_STOPTIMER(linkp, AGE); + LLC_STOPTIMER(linkp,AGE); goto gone; } else { - LLC_STARTTIMER(linkp, AGE); + LLC_STARTTIMER(linkp,AGE); } break; } diff --git a/sys/netccitt/llc_var.h b/sys/netccitt/llc_var.h index 63f4f9a0856..1298cb0efe3 100644 --- a/sys/netccitt/llc_var.h +++ b/sys/netccitt/llc_var.h @@ -1,4 +1,5 @@ -/* $NetBSD: llc_var.h,v 1.4 1995/03/29 22:09:12 briggs Exp $ */ +/* $OpenBSD: llc_var.h,v 1.2 1996/03/04 07:36:36 niklas Exp $ */ +/* $NetBSD: llc_var.h,v 1.5 1996/02/13 22:05:01 christos Exp $ */ /* * Copyright (C) Dirk Husemann, Computer Science Department IV, @@ -41,14 +42,9 @@ * @(#)llc_var.h 8.1 (Berkeley) 6/10/93 */ -#ifdef __STDC__ -/* - * Forward structure declarations for function prototypes [sic]. - */ struct llc; -#endif -#define NPAIDB_LINK 0 +#define NPAIDB_LINK 0 struct npaidbentry { union { @@ -61,27 +57,27 @@ struct npaidbentry { struct { u_short SI_class; #define LLC_CLASS_I 0x1 -#define LLC_CLASS_II 0x3 +#define LLC_CLASS_II 0x3 #define LLC_CLASS_III 0x4 /* Future */ #define LLC_CLASS_IV 0x7 /* Future */ u_short SI_window; u_short SI_trace; u_short SI_xchxid; void (*SI_input) - __P((struct mbuf *)); - caddr_t (*SI_ctlinput) - __P((int, struct sockaddr *, caddr_t)); + __P((struct mbuf *,...)); + void *(*SI_ctlinput) + __P((int,struct sockaddr *,void *)); } SI; } NESIun; }; -#define np_link NESIun.NE.NE_link -#define np_rt NESIun.NE.NE_rt -#define si_class NESIun.SI.SI_class -#define si_window NESIun.SI.SI_window -#define si_trace NESIun.SI.SI_trace -#define si_xchxid NESIun.SI.SI_xchxid -#define si_input NESIun.SI.SI_input -#define si_ctlinput NESIun.SI.SI_ctlinput +#define np_link NESIun.NE.NE_link +#define np_rt NESIun.NE.NE_rt +#define si_class NESIun.SI.SI_class +#define si_window NESIun.SI.SI_window +#define si_trace NESIun.SI.SI_trace +#define si_xchxid NESIun.SI.SI_xchxid +#define si_input NESIun.SI.SI_input +#define si_ctlinput NESIun.SI.SI_ctlinput #define NPDL_SAPNETMASK 0x7e @@ -95,176 +91,182 @@ struct bitslice { }; -#define i_z 0 -#define i_ns 1 -#define i_pf 0 -#define i_nr 1 -#define s_oz 2 -#define s_selector 3 -#define s_pf 0 -#define s_nr 1 -#define u_bb 2 -#define u_select_other 3 -#define u_pf 4 -#define u_select 5 -#define f_vs 1 -#define f_cr 0 -#define f_vr 1 -#define f_wxyzv 6 - -#define LLCGBITS(Arg, Index) (((Arg) & llc_bitslice[(Index)].bs_mask) >> llc_bitslice[(Index)].bs_shift) -#define LLCSBITS(Arg, Index, Val) (Arg) |= (((Val) << llc_bitslice[(Index)].bs_shift) & llc_bitslice[(Index)].bs_mask) -#define LLCCSBITS(Arg, Index, Val) (Arg) = (((Val) << llc_bitslice[(Index)].bs_shift) & llc_bitslice[(Index)].bs_mask) +#define i_z 0 +#define i_ns 1 +#define i_pf 0 +#define i_nr 1 +#define s_oz 2 +#define s_selector 3 +#define s_pf 0 +#define s_nr 1 +#define u_bb 2 +#define u_select_other 3 +#define u_pf 4 +#define u_select 5 +#define f_vs 1 +#define f_cr 0 +#define f_vr 1 +#define f_wxyzv 6 + +#define LLCGBITS(Arg,Index) \ + (((Arg) & llc_bitslice[(Index)].bs_mask) >> \ + llc_bitslice[(Index)].bs_shift) +#define LLCSBITS(Arg,Index,Val) \ + (Arg) |= (((Val) << llc_bitslice[(Index)].bs_shift) & \ + llc_bitslice[(Index)].bs_mask) +#define LLCCSBITS(Arg,Index,Val) \ + (Arg) = (((Val) << llc_bitslice[(Index)].bs_shift) & \ + llc_bitslice[(Index)].bs_mask) extern struct bitslice llc_bitslice[]; -#define LLC_CMD 0 -#define LLC_RSP 1 -#define LLC_MAXCMDRSP 2 +#define LLC_CMD 0 +#define LLC_RSP 1 +#define LLC_MAXCMDRSP 2 /* * LLC events --- These events may either be frames received from the - * remote LLC DSAP, request from the network layer user, - * timer events from llc_timer(), or diagnostic events from - * llc_input(). + * remote LLC DSAP,request from the network layer user, + * timer events from llc_timer(),or diagnostic events from + * llc_input(). */ /* LLC frame types */ -#define LLCFT_INFO 0 * LLC_MAXCMDRSP -#define LLCFT_RR 1 * LLC_MAXCMDRSP -#define LLCFT_RNR 2 * LLC_MAXCMDRSP -#define LLCFT_REJ 3 * LLC_MAXCMDRSP -#define LLCFT_DM 4 * LLC_MAXCMDRSP -#define LLCFT_SABME 5 * LLC_MAXCMDRSP -#define LLCFT_DISC 6 * LLC_MAXCMDRSP -#define LLCFT_UA 7 * LLC_MAXCMDRSP -#define LLCFT_FRMR 8 * LLC_MAXCMDRSP -#define LLCFT_UI 9 * LLC_MAXCMDRSP -#define LLCFT_XID 10 * LLC_MAXCMDRSP -#define LLCFT_TEST 11 * LLC_MAXCMDRSP +#define LLCFT_INFO 0 * LLC_MAXCMDRSP +#define LLCFT_RR 1 * LLC_MAXCMDRSP +#define LLCFT_RNR 2 * LLC_MAXCMDRSP +#define LLCFT_REJ 3 * LLC_MAXCMDRSP +#define LLCFT_DM 4 * LLC_MAXCMDRSP +#define LLCFT_SABME 5 * LLC_MAXCMDRSP +#define LLCFT_DISC 6 * LLC_MAXCMDRSP +#define LLCFT_UA 7 * LLC_MAXCMDRSP +#define LLCFT_FRMR 8 * LLC_MAXCMDRSP +#define LLCFT_UI 9 * LLC_MAXCMDRSP +#define LLCFT_XID 10 * LLC_MAXCMDRSP +#define LLCFT_TEST 11 * LLC_MAXCMDRSP /* LLC2 timer events */ -#define LLC_ACK_TIMER_EXPIRED 12 * LLC_MAXCMDRSP -#define LLC_P_TIMER_EXPIRED 13 * LLC_MAXCMDRSP -#define LLC_REJ_TIMER_EXPIRED 14 * LLC_MAXCMDRSP -#define LLC_BUSY_TIMER_EXPIRED 15 * LLC_MAXCMDRSP +#define LLC_ACK_TIMER_EXPIRED 12 * LLC_MAXCMDRSP +#define LLC_P_TIMER_EXPIRED 13 * LLC_MAXCMDRSP +#define LLC_REJ_TIMER_EXPIRED 14 * LLC_MAXCMDRSP +#define LLC_BUSY_TIMER_EXPIRED 15 * LLC_MAXCMDRSP /* LLC2 diagnostic events */ -#define LLC_INVALID_NR 16 * LLC_MAXCMDRSP -#define LLC_INVALID_NS 17 * LLC_MAXCMDRSP -#define LLC_BAD_PDU 18 * LLC_MAXCMDRSP -#define LLC_LOCAL_BUSY_DETECTED 19 * LLC_MAXCMDRSP -#define LLC_LOCAL_BUSY_CLEARED 20 * LLC_MAXCMDRSP +#define LLC_INVALID_NR 16 * LLC_MAXCMDRSP +#define LLC_INVALID_NS 17 * LLC_MAXCMDRSP +#define LLC_BAD_PDU 18 * LLC_MAXCMDRSP +#define LLC_LOCAL_BUSY_DETECTED 19 * LLC_MAXCMDRSP +#define LLC_LOCAL_BUSY_CLEARED 20 * LLC_MAXCMDRSP /* Network layer user requests */ /* * NL_CONNECT_REQUEST --- The user has requested that a data link connection - * be established with a remote LLC DSAP. + * be established with a remote LLC DSAP. */ -#define NL_CONNECT_REQUEST 21 * LLC_MAXCMDRSP +#define NL_CONNECT_REQUEST 21 * LLC_MAXCMDRSP /* * NL_CONNECT_RESPONSE --- The user has accepted the data link connection. */ -#define NL_CONNECT_RESPONSE 22 * LLC_MAXCMDRSP +#define NL_CONNECT_RESPONSE 22 * LLC_MAXCMDRSP /* * NL_RESET_REQUEST --- The user has requested that the data link with the - * remote LLC DSAP be reset. + * remote LLC DSAP be reset. */ -#define NL_RESET_REQUEST 23 * LLC_MAXCMDRSP +#define NL_RESET_REQUEST 23 * LLC_MAXCMDRSP /* * NL_RESET_RESPONSE --- The user has accepted the reset of the data link - * connection. + * connection. */ -#define NL_RESET_RESPONSE 24 * LLC_MAXCMDRSP +#define NL_RESET_RESPONSE 24 * LLC_MAXCMDRSP /* * NL_DISCONNECT_REQUEST --- The user has requested that the data link - * connection with remote LLC DSAP be terminated. + * connection with remote LLC DSAP be terminated. */ -#define NL_DISCONNECT_REQUEST 25 * LLC_MAXCMDRSP +#define NL_DISCONNECT_REQUEST 25 * LLC_MAXCMDRSP /* * NL_DATA_REQUEST --- The user has requested that a data unit be sent ot the - * remote LLC DSAP. + * remote LLC DSAP. */ -#define NL_DATA_REQUEST 26 * LLC_MAXCMDRSP +#define NL_DATA_REQUEST 26 * LLC_MAXCMDRSP /* * NL_INITIATE_PF_CYCLE --- The local LLC wants to initiate a P/F cycle. */ -#define NL_INITIATE_PF_CYCLE 27 * LLC_MAXCMDRSP +#define NL_INITIATE_PF_CYCLE 27 * LLC_MAXCMDRSP /* * NL_LOCAL_BUSY_DETECTED --- The local entity has encountered a busy condition */ -#define NL_LOCAL_BUSY_DETECTED 28 * LLC_MAXCMDRSP +#define NL_LOCAL_BUSY_DETECTED 28 * LLC_MAXCMDRSP -#define LLCFT_NONE 255 +#define LLCFT_NONE 255 /* return message from state handlers */ /* * LLC_CONNECT_INDICATION --- Inform the user that a connection has been - * requested by a remote LLC SSAP. + * requested by a remote LLC SSAP. */ -#define LLC_CONNECT_INDICATION 1 +#define LLC_CONNECT_INDICATION 1 /* * LLC_CONNECT_CONFIRM --- The connection service component indicates that the - * remote network entity has accepted the connection. + * remote network entity has accepted the connection. */ -#define LLC_CONNECT_CONFIRM 2 +#define LLC_CONNECT_CONFIRM 2 /* * LLC_DISCONNECT_INDICATION --- Inform the user that the remote network - * entity has intiated disconnection of the data - * link connection. + * entity has intiated disconnection of the data + * link connection. */ #define LLC_DISCONNECT_INDICATION 3 /* * LLC_RESET_CONFIRM --- The connection service component indicates that the - * remote network entity has accepted the reset. + * remote network entity has accepted the reset. */ -#define LLC_RESET_CONFIRM 4 +#define LLC_RESET_CONFIRM 4 /* * LLC_RESET_INDICATION_REMOTE --- The remote network entity or remote peer - * has initiated a reset of the data link - * connection. + * has initiated a reset of the data link + * connection. */ #define LLC_RESET_INDICATION_REMOTE 5 /* * LLC_RESET_INDICATION_LOCAL --- The local LLC has determined that the data - * link connection is in need of - * reinitialization. + * link connection is in need of + * reinitialization. */ #define LLC_RESET_INDICATION_LOCAL 6 /* * LLC_FRMR_RECEIVED --- The local connection service component has received a - * FRMR response PDU. + * FRMR response PDU. */ -#define LLC_FRMR_RECEIVED 7 +#define LLC_FRMR_RECEIVED 7 /* * LLC_FRMR_SENT --- The local connection component has received an ivalid - * PDU, and has sent a FRMR response PDU. + * PDU,and has sent a FRMR response PDU. */ -#define LLC_FRMR_SENT 8 +#define LLC_FRMR_SENT 8 /* * LLC_DATA_INDICATION --- The connection service component passes the data - * unit from the received I PDU to the user. + * unit from the received I PDU to the user. */ -#define LLC_DATA_INDICATION 9 +#define LLC_DATA_INDICATION 9 /* * LLC_REMOTE_NOT_BUSY --- The remote LLC DSAP is no longer busy. The local - * connection service component will now accept a - * DATA_REQUEST. + * connection service component will now accept a + * DATA_REQUEST. */ -#define LLC_REMOTE_NOT_BUSY 10 +#define LLC_REMOTE_NOT_BUSY 10 /* * LLC_REMOTE_BUSY --- The remote LLC DSAP is busy. The local connection - * service component will not accept a DATA_REQUEST. + * service component will not accept a DATA_REQUEST. */ -#define LLC_REMOTE_BUSY 11 +#define LLC_REMOTE_BUSY 11 /* Internal return code */ -#define LLC_PASSITON 255 +#define LLC_PASSITON 255 #define INFORMATION_CONTROL 0x00 #define SUPERVISORY_CONTROL 0x02 -#define UNUMBERED_CONTROL 0x03 +#define UNUMBERED_CONTROL 0x03 /* * Other necessary definitions @@ -277,7 +279,7 @@ extern struct bitslice llc_bitslice[]; /* * Don't we love this one? CCITT likes to suck on bits 8=) */ -#define NLHDRSIZEGUESS 3 +#define NLHDRSIZEGUESS 3 /* * LLC control block @@ -288,59 +290,59 @@ struct llc_linkcb { struct llccb_q *q_forw; /* admin chain */ struct llccb_q *q_backw; } llcl_q; - struct npaidbentry *llcl_sapinfo; /* SAP information */ - struct sockaddr_dl llcl_addr; /* link snpa address */ - struct rtentry *llcl_nlrt; /* layer 3 -> LLC */ + struct npaidbentry *llcl_sapinfo; /* SAP information */ + struct sockaddr_dl llcl_addr; /* link snpa address */ + struct rtentry *llcl_nlrt; /* layer 3 -> LLC */ struct rtentry *llcl_llrt; /* LLC -> layer 3 */ - struct ifnet *llcl_if; /* our interface */ + struct ifnet *llcl_if; /* our interface */ caddr_t llcl_nlnext; /* cb for network layer */ - struct mbuf *llcl_writeqh; /* Write queue head */ - struct mbuf *llcl_writeqt; /* Write queue tail */ - struct mbuf **llcl_output_buffers; - short llcl_timers[6]; /* timer array */ - long llcl_timerflags; /* flags signalling running timers */ - int (*llcl_statehandler) - __P((struct llc_linkcb *, struct llc *, int, int, int)); - int llcl_P_flag; - int llcl_F_flag; - int llcl_S_flag; - int llcl_DATA_flag; - int llcl_REMOTE_BUSY_flag; - int llcl_DACTION_flag; /* delayed action */ - int llcl_retry; + struct mbuf *llcl_writeqh; /* Write queue head */ + struct mbuf *llcl_writeqt; /* Write queue tail */ + struct mbuf **llcl_output_buffers; + short llcl_timers[6]; /* timer array */ + long llcl_timerflags; /* flags signalling running timers */ + int (*llcl_statehandler) + __P((struct llc_linkcb *,struct llc *,int,int,int)); + int llcl_P_flag; + int llcl_F_flag; + int llcl_S_flag; + int llcl_DATA_flag; + int llcl_REMOTE_BUSY_flag; + int llcl_DACTION_flag; /* delayed action */ + int llcl_retry; /* * The following components deal --- in one way or the other --- * with the LLC2 window. Indicated by either [L] or [W] is the * domain of the specific component: * - * [L] The domain is 0--LLC_MAX_WINDOW - * [W] The domain is 0--llcl_window + * [L] The domain is 0--LLC_MAX_WINDOW + * [W] The domain is 0--llcl_window */ - short llcl_vr; /* next to receive [L] */ - short llcl_vs; /* next to send [L] */ - short llcl_nr_received; /* next frame to b ack'd [L] */ - short llcl_freeslot; /* next free slot [W] */ - short llcl_projvs; /* V(S) associated with freeslot */ - short llcl_slotsfree; /* free slots [W] */ - short llcl_window; /* window size */ + short llcl_vr; /* next to receive [L] */ + short llcl_vs; /* next to send [L] */ + short llcl_nr_received; /* next frame to b ack'd [L] */ + short llcl_freeslot; /* next free slot [W] */ + short llcl_projvs; /* V(S) associated with freeslot */ + short llcl_slotsfree; /* free slots [W] */ + short llcl_window; /* window size */ /* - * In llcl_frmrinfo we jot down the last frmr info field, which we + * In llcl_frmrinfo we jot down the last frmr info field,which we * need to do as we need to be able to resend it in the ERROR state. */ - struct frmrinfo llcl_frmrinfo; /* last FRMR info field */ + struct frmrinfo llcl_frmrinfo; /* last FRMR info field */ }; -#define llcl_frmr_pdu0 llcl_frmrinfo.rej_pdu_0 -#define llcl_frmr_pdu1 llcl_frmrinfo.rej_pdu_1 -#define llcl_frmr_control llcl_frmrinfo.frmr_control -#define llcl_frmr_control_ext llcl_frmrinfo.frmr_control_ext -#define llcl_frmr_cause llcl_frmrinfo.frmr_cause - -#define LQNEXT(l) (struct llc_linkcb *)((l)->llcl_q.q_forw) -#define LQEMPTY (llccb_q.q_forw == &llccb_q) -#define LQFIRST (struct llc_linkcb *)(llccb_q.q_forw) +#define llcl_frmr_pdu0 llcl_frmrinfo.rej_pdu_0 +#define llcl_frmr_pdu1 llcl_frmrinfo.rej_pdu_1 +#define llcl_frmr_control llcl_frmrinfo.frmr_control +#define llcl_frmr_control_ext llcl_frmrinfo.frmr_control_ext +#define llcl_frmr_cause llcl_frmrinfo.frmr_cause + +#define LQNEXT(l) (struct llc_linkcb *)((l)->llcl_q.q_forw) +#define LQEMPTY (llccb_q.q_forw == &llccb_q) +#define LQFIRST (struct llc_linkcb *)(llccb_q.q_forw) #define LQVALID(l) (!((struct llccb_q *)(l) == &llccb_q)) -#define LLC_ENQUEUE(l, m) if ((l)->llcl_writeqh == NULL) { \ +#define LLC_ENQUEUE(l,m) if ((l)->llcl_writeqh == NULL) { \ (l)->llcl_writeqh = (m); \ (l)->llcl_writeqt = (m); \ } else { \ @@ -348,29 +350,29 @@ struct llc_linkcb { (l)->llcl_writeqt = (m); \ } -#define LLC_DEQUEUE(l, m) if ((l)->llcl_writeqh == NULL) \ - (m) = NULL; \ - else { \ +#define LLC_DEQUEUE(l,m) if ((l)->llcl_writeqh == NULL) \ + (m) = NULL; \ + else { \ (m) = (l)->llcl_writeqh; \ (l)->llcl_writeqh = (l)->llcl_writeqh->m_nextpkt; \ } -#define LLC_SETFRAME(l, m) { \ - if ((l)->llcl_slotsfree > 0) { \ - (l)->llcl_slotsfree--; \ +#define LLC_SETFRAME(l,m) { \ + if ((l)->llcl_slotsfree > 0) { \ + (l)->llcl_slotsfree--; \ (l)->llcl_output_buffers[(l)->llcl_freeslot] = (m); \ (l)->llcl_freeslot = ((l)->llcl_freeslot+1) % (l)->llcl_window; \ LLC_INC((l)->llcl_projvs); \ } \ - } + } /* * handling of sockaddr_dl's */ -#define LLADDRLEN(s) ((s)->sdl_alen + (s)->sdl_nlen) -#define LLSAPADDR(s) ((s)->sdl_data[LLADDRLEN(s)-1] & 0xff) -#define LLSAPLOC(s, if) ((s)->sdl_nlen + (if)->if_addrlen) +#define LLADDRLEN(s) ((s)->sdl_alen + (s)->sdl_nlen) +#define LLSAPADDR(s) ((s)->sdl_data[LLADDRLEN(s)-1] & 0xff) +#define LLSAPLOC(s,if) ((s)->sdl_nlen + (if)->if_addrlen) struct sdl_hdr { struct sockaddr_dl sdlhdr_dst; @@ -379,156 +381,176 @@ struct sdl_hdr { }; #define LLC_GETHDR(f,m) { \ - struct mbuf *_m = (struct mbuf *) (m); \ - if (_m) { \ - M_PREPEND(_m, LLC_ISFRAMELEN, M_DONTWAIT); \ - bzero(mtod(_m, caddr_t), LLC_ISFRAMELEN); \ - } else { \ - MGETHDR (_m, M_DONTWAIT, MT_HEADER); \ - if (_m != NULL) { \ - _m->m_pkthdr.len = _m->m_len = LLC_UFRAMELEN; \ - _m->m_next = _m->m_act = NULL; \ - bzero(mtod(_m, caddr_t), LLC_UFRAMELEN); \ - } else return; \ - } \ - (m) = _m; \ - (f) = mtod(m, struct llc *); \ - } - -#define LLC_NEWSTATE(l, LLCstate) (l)->llcl_statehandler = llc_state_##LLCstate -#define LLC_STATEEQ(l, LLCstate) ((l)->llcl_statehandler == llc_state_##LLCstate ? 1 : 0) - -#define LLC_ACK_SHIFT 0 -#define LLC_P_SHIFT 1 -#define LLC_BUSY_SHIFT 2 -#define LLC_REJ_SHIFT 3 -#define LLC_AGE_SHIFT 4 + struct mbuf *_m = (struct mbuf *) (m); \ + if (_m) { \ + M_PREPEND(_m,LLC_ISFRAMELEN,M_DONTWAIT); \ + bzero(mtod(_m,caddr_t),LLC_ISFRAMELEN); \ + } else { \ + MGETHDR (_m,M_DONTWAIT,MT_HEADER); \ + if (_m != NULL) { \ + _m->m_pkthdr.len = _m->m_len = LLC_UFRAMELEN; \ + _m->m_next = _m->m_act = NULL; \ + bzero(mtod(_m,caddr_t),LLC_UFRAMELEN); \ + } else return; \ + } \ + (m) = _m; \ + (f) = mtod(m,struct llc *); \ +} + +#define LLC_NEWSTATE(l,LLCstate) \ + (l)->llcl_statehandler = __CONCAT(llc_state_,LLCstate) +#define LLC_STATEEQ(l,LLCstate) \ + ((l)->llcl_statehandler == __CONCAT(llc_state_,LLCstate) ? 1 : 0) + +#define LLC_ACK_SHIFT 0 +#define LLC_P_SHIFT 1 +#define LLC_BUSY_SHIFT 2 +#define LLC_REJ_SHIFT 3 +#define LLC_AGE_SHIFT 4 #define LLC_DACTION_SHIFT 5 -#define LLC_TIMER_NOTRUNNING 0 -#define LLC_TIMER_RUNNING 1 -#define LLC_TIMER_EXPIRED 2 - -#define LLC_STARTTIMER(l, LLCtimer) { \ - (l)->llcl_timers[LLC_##LLCtimer##_SHIFT] = llc_##LLCtimer##_timer; \ - (l)->llcl_timerflags |= (1<llcl_timers[LLC_##LLCtimer##_SHIFT] = 0; \ - (l)->llcl_timerflags &= ~(1<llcl_timers[LLC_##LLCtimer##_SHIFT] > 0) \ - (l)->llcl_timers[LLC_##LLCtimer##_SHIFT]--; - -#define LLC_TIMERXPIRED(l, LLCtimer) \ - (((l)->llcl_timerflags & (1<llcl_timers[LLC_##LLCtimer##_SHIFT] == 0 ) ? \ +#define LLC_TIMER_NOTRUNNING 0 +#define LLC_TIMER_RUNNING 1 +#define LLC_TIMER_EXPIRED 2 + +#ifndef __CONCAT3 +# if __STDC__ +# define __CONCAT3(a,b,c) a ## b ## c +# else +# define __CONCAT3(a,b,c) a/**/b/**/c +# endif /* __STDC__ */ +#endif + +#define LLC_STARTTIMER(l,LLCtimer) { \ + (l)->llcl_timers[__CONCAT3(LLC_,LLCtimer,_SHIFT)] = \ + __CONCAT3(llc_,LLCtimer,_timer); \ + (l)->llcl_timerflags |= (1 << __CONCAT3(LLC_,LLCtimer,_SHIFT)); \ +} +#define LLC_STOPTIMER(l,LLCtimer) { \ + (l)->llcl_timers[__CONCAT3(LLC_,LLCtimer,_SHIFT)] = 0; \ + (l)->llcl_timerflags &= ~(1<<__CONCAT3(LLC_,LLCtimer,_SHIFT)); \ +} +#define LLC_AGETIMER(l,LLCtimer) \ + if ((l)->llcl_timers[__CONCAT3(LLC_,LLCtimer,_SHIFT)] > 0) \ + (l)->llcl_timers[__CONCAT3(LLC_,LLCtimer,_SHIFT)]--; + +#define LLC_TIMERXPIRED(l,LLCtimer) \ + (((l)->llcl_timerflags & (1<<__CONCAT3(LLC_,LLCtimer,_SHIFT))) ? \ + (((l)->llcl_timers[__CONCAT3(LLC_,LLCtimer,_SHIFT)] == 0 ) ? \ LLC_TIMER_EXPIRED : LLC_TIMER_RUNNING) : LLC_TIMER_NOTRUNNING) -#define FOR_ALL_LLC_TIMERS(t) for ((t) = LLC_ACK_SHIFT; (t) < LLC_AGE_SHIFT; (t)++) +#define FOR_ALL_LLC_TIMERS(t) \ + for ((t) = LLC_ACK_SHIFT; (t) < LLC_AGE_SHIFT; (t)++) -#define LLC_SETFLAG(l, LLCflag, v) (l)->llcl_##LLCflag##_flag = (v) -#define LLC_GETFLAG(l, LLCflag) (l)->llcl_##LLCflag##_flag +#define LLC_SETFLAG(l,LLCflag,v) (l)->__CONCAT3(llcl_,LLCflag,_flag) = (v) +#define LLC_GETFLAG(l,LLCflag) (l)->__CONCAT3(llcl_,LLCflag,_flag) #define LLC_RESETCOUNTER(l) { \ - (l)->llcl_vs = (l)->llcl_vr = (l)->llcl_retry = 0; \ - llc_resetwindow((l)); \ - } + (l)->llcl_vs = (l)->llcl_vr = (l)->llcl_retry = 0; \ + llc_resetwindow((l)); \ +} /* * LLC2 macro definitions */ -#define LLC_START_ACK_TIMER(l) LLC_STARTTIMER((l), ACK) -#define LLC_STOP_ACK_TIMER(l) LLC_STOPTIMER((l), ACK) -#define LLC_START_REJ_TIMER(l) LLC_STARTTIMER((l), REJ) -#define LLC_STOP_REJ_TIMER(l) LLC_STOPTIMER((l), REJ) +#define LLC_START_ACK_TIMER(l) LLC_STARTTIMER((l),ACK) +#define LLC_STOP_ACK_TIMER(l) LLC_STOPTIMER((l),ACK) +#define LLC_START_REJ_TIMER(l) LLC_STARTTIMER((l),REJ) +#define LLC_STOP_REJ_TIMER(l) LLC_STOPTIMER((l),REJ) #define LLC_START_P_TIMER(l) { \ - LLC_STARTTIMER((l), P); \ - if (LLC_GETFLAG((l), P) == 0) \ - (l)->llcl_retry = 0; \ - LLC_SETFLAG((l), P, 1); \ - } + LLC_STARTTIMER((l),P); \ + if (LLC_GETFLAG((l),P) == 0) \ + (l)->llcl_retry = 0; \ + LLC_SETFLAG((l),P,1); \ +} #define LLC_STOP_P_TIMER(l) { \ - LLC_STOPTIMER((l), P); \ - LLC_SETFLAG((l), P, 0); \ - } + LLC_STOPTIMER((l),P); \ + LLC_SETFLAG((l),P,0); \ +} #define LLC_STOP_ALL_TIMERS(l) { \ - LLC_STOPTIMER((l), ACK); \ - LLC_STOPTIMER((l), REJ); \ - LLC_STOPTIMER((l), BUSY); \ - LLC_STOPTIMER((l), P); \ - } + LLC_STOPTIMER((l),ACK); \ + LLC_STOPTIMER((l),REJ); \ + LLC_STOPTIMER((l),BUSY); \ + LLC_STOPTIMER((l),P); \ +} #define LLC_INC(i) (i) = ((i)+1) % LLC_MAX_SEQUENCE -#define LLC_NR_VALID(l, nr) ((l)->llcl_vs < (l)->llcl_nr_received ? \ - (((nr) >= (l)->llcl_nr_received) || \ - ((nr) <= (l)->llcl_vs) ? 1 : 0) : \ - (((nr) <= (l)->llcl_vs) && \ - ((nr) >= (l)->llcl_nr_received) ? 1 : 0)) - -#define LLC_UPDATE_P_FLAG(l, cr, pf) { \ - if ((cr) == LLC_RSP && (pf) == 1) { \ - LLC_SETFLAG((l), P, 0); \ - LLC_STOPTIMER((l), P); \ - } \ - } - -#define LLC_UPDATE_NR_RECEIVED(l, nr) { \ - while ((l)->llcl_nr_received != (nr)) { \ - struct mbuf *_m; \ - register short seq; \ - if (_m = (l)->llcl_output_buffers[seq = llc_seq2slot((l), (l)->llcl_nr_received)]) \ - m_freem(_m); \ - (l)->llcl_output_buffers[seq] = NULL; \ - LLC_INC((l)->llcl_nr_received); \ - (l)->llcl_slotsfree++; \ - } \ - (l)->llcl_retry = 0; \ - if ((l)->llcl_slotsfree < (l)->llcl_window) { \ - LLC_START_ACK_TIMER(l); \ - } else LLC_STOP_ACK_TIMER(l); \ - LLC_STARTTIMER((l), DACTION); \ - } +#define LLC_NR_VALID(l,nr) \ + ((l)->llcl_vs < (l)->llcl_nr_received ? \ + (((nr) >= (l)->llcl_nr_received) || \ + ((nr) <= (l)->llcl_vs) ? 1 : 0) : \ + (((nr) <= (l)->llcl_vs) && \ + ((nr) >= (l)->llcl_nr_received) ? 1 : 0)) + +#define LLC_UPDATE_P_FLAG(l,cr,pf) { \ + if ((cr) == LLC_RSP && (pf) == 1) { \ + LLC_SETFLAG((l),P,0); \ + LLC_STOPTIMER((l),P); \ + } \ +} + +#define LLC_UPDATE_NR_RECEIVED(l,nr) { \ + while ((l)->llcl_nr_received != (nr)) { \ + struct mbuf *_m; \ + register short seq; \ + seq = llc_seq2slot((l),(l)->llcl_nr_received); \ + if ((_m = (l)->llcl_output_buffers[seq]) != NULL) \ + m_freem(_m); \ + (l)->llcl_output_buffers[seq] = NULL; \ + LLC_INC((l)->llcl_nr_received); \ + (l)->llcl_slotsfree++; \ + } \ + (l)->llcl_retry = 0; \ + if ((l)->llcl_slotsfree < (l)->llcl_window) { \ + LLC_START_ACK_TIMER(l); \ + } else { \ + LLC_STOP_ACK_TIMER(l); \ + } \ + LLC_STARTTIMER((l),DACTION); \ +} #define LLC_SET_REMOTE_BUSY(l,a) { \ - if (LLC_GETFLAG((l), REMOTE_BUSY) == 0) { \ - LLC_SETFLAG((l), REMOTE_BUSY, 1); \ - LLC_STARTTIMER((l), BUSY); \ - (a) = LLC_REMOTE_BUSY; \ - } else { \ - (a) = 0; \ - } \ - } + if (LLC_GETFLAG((l),REMOTE_BUSY) == 0) { \ + LLC_SETFLAG((l),REMOTE_BUSY,1); \ + LLC_STARTTIMER((l),BUSY); \ + (a) = LLC_REMOTE_BUSY; \ + } else { \ + (a) = 0; \ + } \ +} + #define LLC_CLEAR_REMOTE_BUSY(l,a) { \ - if (LLC_GETFLAG((l), REMOTE_BUSY) == 1) { \ - LLC_SETFLAG((l), REMOTE_BUSY, 1); \ - LLC_STOPTIMER((l), BUSY); \ - if (LLC_STATEEQ((l), NORMAL) || \ - LLC_STATEEQ((l), REJECT) || \ - LLC_STATEEQ((l), BUSY)) \ - llc_resend((l), LLC_CMD, 0); \ - (a) = LLC_REMOTE_NOT_BUSY; \ - } else { \ - (a) = 0; \ - } \ - } - -#define LLC_DACKCMD 0x1 -#define LLC_DACKCMDPOLL 0x2 -#define LLC_DACKRSP 0x3 + if (LLC_GETFLAG((l),REMOTE_BUSY) == 1) { \ + LLC_SETFLAG((l),REMOTE_BUSY,1); \ + LLC_STOPTIMER((l),BUSY); \ + if (LLC_STATEEQ((l),NORMAL) || \ + LLC_STATEEQ((l),REJECT) || \ + LLC_STATEEQ((l),BUSY)) \ + llc_resend((l),LLC_CMD,0); \ + (a) = LLC_REMOTE_NOT_BUSY; \ + } else { \ + (a) = 0; \ + } \ +} + +#define LLC_DACKCMD 0x1 +#define LLC_DACKCMDPOLL 0x2 +#define LLC_DACKRSP 0x3 #define LLC_DACKRSPFINAL 0x4 -#define LLC_SENDACKNOWLEDGE(l, cmd, pf) { \ - if ((cmd) == LLC_CMD) { \ - LLC_SETFLAG((l), DACTION, ((pf) == 0 ? LLC_DACKCMD : LLC_DACKCMDPOLL)); \ - } else { \ - LLC_SETFLAG((l), DACTION, ((pf) == 0 ? LLC_DACKRSP : LLC_DACKRSPFINAL)); \ - } \ - } +#define LLC_SENDACKNOWLEDGE(l,cmd,pf) { \ + if ((cmd) == LLC_CMD) { \ + LLC_SETFLAG((l),DACTION,((pf) == 0 ? LLC_DACKCMD : \ + LLC_DACKCMDPOLL)); \ + } else { \ + LLC_SETFLAG((l),DACTION,((pf) == 0 ? LLC_DACKRSP : \ + LLC_DACKRSPFINAL)); \ + } \ +} #define LLC_FRMR_W (1<<0) #define LLC_FRMR_X (1<<1) @@ -536,44 +558,44 @@ struct sdl_hdr { #define LLC_FRMR_Z (1<<3) #define LLC_FRMR_V (1<<4) -#define LLC_SETFRMR(l, f, cr, c) { \ - if ((f)->llc_control & 0x3) { \ - (l)->llcl_frmr_pdu0 = (f)->llc_control; \ - (l)->llcl_frmr_pdu1 = 0; \ - } else { \ - (l)->llcl_frmr_pdu0 = (f)->llc_control; \ - (l)->llcl_frmr_pdu1 = (f)->llc_control_ext; \ - } \ - LLCCSBITS((l)->llcl_frmr_control, f_vs, (l)->llcl_vs); \ - LLCCSBITS((l)->llcl_frmr_control_ext, f_cr, (cr)); \ - LLCSBITS((l)->llcl_frmr_control_ext, f_vr, (l)->llcl_vr); \ - LLCCSBITS((l)->llcl_frmr_cause, f_wxyzv, (c)); \ - } +#define LLC_SETFRMR(l,f,cr,c) { \ + if ((f)->llc_control & 0x3) { \ + (l)->llcl_frmr_pdu0 = (f)->llc_control; \ + (l)->llcl_frmr_pdu1 = 0; \ + } else { \ + (l)->llcl_frmr_pdu0 = (f)->llc_control; \ + (l)->llcl_frmr_pdu1 = (f)->llc_control_ext; \ + } \ + LLCCSBITS((l)->llcl_frmr_control,f_vs,(l)->llcl_vs); \ + LLCCSBITS((l)->llcl_frmr_control_ext,f_cr,(cr)); \ + LLCSBITS((l)->llcl_frmr_control_ext,f_vr,(l)->llcl_vr); \ + LLCCSBITS((l)->llcl_frmr_cause,f_wxyzv,(c)); \ +} /* * LLC tracing levels: - * LLCTR_INTERESTING interesting event, we might care to know about - * it, but then again, we might not ... - * LLCTR_SHOULDKNOW we probably should know about this event - * LLCTR_URGENT something has gone utterly wrong ... + * LLCTR_INTERESTING interesting event,we might care to know about + * it,but then again,we might not ... + * LLCTR_SHOULDKNOW we probably should know about this event + * LLCTR_URGENT something has gone utterly wrong ... */ -#define LLCTR_INTERESTING 1 -#define LLCTR_SHOULDKNOW 2 -#define LLCTR_URGENT 3 +#define LLCTR_INTERESTING 1 +#define LLCTR_SHOULDKNOW 2 +#define LLCTR_URGENT 3 #ifdef LLCDEBUG -#define LLC_TRACE(lp, l, msg) llc_trace((lp), (l), (msg)) +#define LLC_TRACE(lp,l,msg) llc_trace((lp),(l),(msg)) #else /* LLCDEBUG */ -#define LLC_TRACE(lp, l, msg) /* NOOP */ +#define LLC_TRACE(lp,l,msg) /* NOOP */ #endif /* LLCDEBUG */ -#define LLC_N2_VALUE 15 /* up to 15 retries */ -#define LLC_ACK_TIMER 10 /* 5 secs */ -#define LLC_P_TIMER 4 /* 2 secs */ -#define LLC_BUSY_TIMER 12 /* 6 secs */ -#define LLC_REJ_TIMER 12 /* 6 secs */ -#define LLC_AGE_TIMER 40 /* 20 secs */ -#define LLC_DACTION_TIMER 2 /* 1 secs */ +#define LLC_N2_VALUE 15 /* up to 15 retries */ +#define LLC_ACK_TIMER 10 /* 5 secs */ +#define LLC_P_TIMER 4 /* 2 secs */ +#define LLC_BUSY_TIMER 12 /* 6 secs */ +#define LLC_REJ_TIMER 12 /* 6 secs */ +#define LLC_AGE_TIMER 40 /* 20 secs */ +#define LLC_DACTION_TIMER 2 /* 1 secs */ #if defined (_KERNEL) && defined(LLC) extern int llc_n2; @@ -588,7 +610,7 @@ extern int af_link_rts_init_done; #define USES_AF_LINK_RTS { \ if (!af_link_rts_init_done) { \ - rn_inithead((void **)&rt_tables[AF_LINK], 32); \ + rn_inithead((void **)&rt_tables[AF_LINK],32); \ af_link_rts_init_done++; \ } \ } @@ -601,26 +623,39 @@ extern char *frame_names[]; /* * Function prototypes */ +/* llc_input.c */ +void llcintr __P((void)); +int llc_input __P((struct mbuf *, ...)); +void *llc_ctlinput __P((int, struct sockaddr *, void *)); + +/* llc_output.c */ +int llc_output __P((struct mbuf *, ...)); +void llc_start __P((struct llc_linkcb *)); +void llc_send __P((struct llc_linkcb *, int, int, int)); +void llc_resend __P((struct llc_linkcb *, int, int)); +void llc_rawsend __P((struct llc_linkcb *, struct mbuf *, struct llc *, int, + int, int, int)); + +/* llc_subr.c */ int sdl_cmp __P((struct sockaddr_dl *, struct sockaddr_dl *)); -int sdl_copy __P((struct sockaddr_dl *, struct sockaddr_dl *)); -int sdl_swapaddr __P((struct sockaddr_dl *, struct sockaddr_dl *)); +void sdl_copy __P((struct sockaddr_dl *, struct sockaddr_dl *)); +void sdl_swapaddr __P((struct sockaddr_dl *, struct sockaddr_dl *)); +struct sockaddr_dl *sdl_getaddrif __P((struct ifnet *)); int sdl_checkaddrif __P((struct ifnet *, struct sockaddr_dl *)); -int sdl_setaddrif __P((struct ifnet *, u_char *, u_char, u_char, - struct sockaddr_dl *)); -int sdl_sethdrif __P((struct ifnet *, u_char *, u_char, u_char *, u_char, u_char, - struct sdl_hdr *)); +int sdl_setaddrif __P((struct ifnet *, u_char *, u_char, u_char, + struct sockaddr_dl *)); +int sdl_sethdrif __P((struct ifnet *, u_char *, u_char, u_char *, u_char, + u_char, struct sdl_hdr *)); struct npaidbentry *llc_setsapinfo __P((struct ifnet *, u_char, u_char, struct dllconfig *)); struct npaidbentry *llc_getsapinfo __P((u_char, struct ifnet *)); -struct rtentry *npaidb_enrich __P((short, caddr_t, struct sockaddr_dl *)); -int npaidb_destroy __P((struct rtentry *)); short llc_seq2slot __P((struct llc_linkcb *, short)); int llc_state_ADM __P((struct llc_linkcb *, struct llc *, int, int, int)); int llc_state_CONN __P((struct llc_linkcb *, struct llc *, int, int, int)); -int llc_state_RESET_WAIT __P((struct llc_linkcb *, struct llc *, - int, int, int)); -int llc_state_RESET_CHECK __P((struct llc_linkcb *, struct llc *, - int, int, int)); +int llc_state_RESET_WAIT __P((struct llc_linkcb *, struct llc *, int, + int, int)); +int llc_state_RESET_CHECK __P((struct llc_linkcb *, struct llc *, int, + int, int)); int llc_state_SETUP __P((struct llc_linkcb *, struct llc *, int, int, int)); int llc_state_RESET __P((struct llc_linkcb *, struct llc *, int, int, int)); int llc_state_D_CONN __P((struct llc_linkcb *, struct llc *, int, int, int)); @@ -630,32 +665,24 @@ int llc_state_NORMAL __P((struct llc_linkcb *, struct llc *, int, int, int)); int llc_state_BUSY __P((struct llc_linkcb *, struct llc *, int, int, int)); int llc_state_REJECT __P((struct llc_linkcb *, struct llc *, int, int, int)); int llc_state_AWAIT __P((struct llc_linkcb *, struct llc *, int, int, int)); -int llc_state_AWAIT_BUSY __P((struct llc_linkcb *, struct llc *, int, int, int)); -int llc_state_AWAIT_REJECT __P((struct llc_linkcb *, struct llc *, int, int, int)); +int llc_state_AWAIT_BUSY __P((struct llc_linkcb *, struct llc *, int, int, + int)); +int llc_state_AWAIT_REJECT __P((struct llc_linkcb *, struct llc *, int, int, + int)); int llc_statehandler __P((struct llc_linkcb *, struct llc *, int, int, int)); -int llc_init __P((void)); -struct llc_linkcb *llc_newlink __P((struct sockaddr_dl *, struct ifnet *, - struct rtentry *, caddr_t, struct rtentry *)); -int llc_dellink __P((struct llc_linkcb *)); +void llc_init __P((void)); +void llc_resetwindow __P((struct llc_linkcb *)); +struct llc_linkcb *llc_newlink __P((struct sockaddr_dl *, struct ifnet *, + struct rtentry *, caddr_t, + struct rtentry *)); +void llc_dellink __P((struct llc_linkcb *)); +int llc_decode __P((struct llc *, struct llc_linkcb *)); int llc_anytimersup __P((struct llc_linkcb *)); -char * llc_getstatename __P((struct llc_linkcb *)); +char *llc_getstatename __P((struct llc_linkcb *)); void llc_link_dump __P((struct llc_linkcb *, const char *)); void llc_trace __P((struct llc_linkcb *, int, const char *)); -void llc_resetwindow __P((struct llc_linkcb *)); -int llc_decode __P((struct llc *, struct llc_linkcb *)); + +/* llc_timer.c */ void llc_timer __P((void)); -void llcintr __P((void)); -int llc_input __P((struct llc_linkcb *, struct mbuf *, u_char)); -caddr_t llc_ctlinput __P((int, struct sockaddr *, caddr_t)); -int llc_output __P((struct llc_linkcb *, struct mbuf *)); -void llc_start __P((struct llc_linkcb *)); -int llc_send __P((struct llc_linkcb *, int, int, int)); -int llc_resend __P((struct llc_linkcb *, int, int)); -int llc_rawsend __P((struct llc_linkcb *, struct mbuf *, struct llc *, int, int, - int, int)); -int cons_rtrequest __P((int, struct rtentry *, struct sockaddr *)); -long x25_llcglue __P((int, struct sockaddr *)); #endif - - diff --git a/sys/netccitt/pk.h b/sys/netccitt/pk.h index 10b2fa218cf..e8fbb5de432 100644 --- a/sys/netccitt/pk.h +++ b/sys/netccitt/pk.h @@ -1,4 +1,5 @@ -/* $NetBSD: pk.h,v 1.5 1994/06/29 06:37:29 cgd Exp $ */ +/* $OpenBSD: pk.h,v 1.2 1996/03/04 07:36:37 niklas Exp $ */ +/* $NetBSD: pk.h,v 1.6 1996/02/13 22:05:08 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -95,9 +96,13 @@ #define IGNORE_PACKET 1 #define ERROR_PACKET 2 -typedef char bool; +#ifndef CCITT_TYPES_DEFINED +#define CCITT_TYPES_DEFINED #define FALSE 0 #define TRUE 1 +typedef char bool; +typedef u_char octet; +#endif /* * X.25 Packet format definitions @@ -105,7 +110,6 @@ typedef char bool; * to bit fields, to be ansi C compliant and allignment safe. */ -typedef u_char octet; struct x25_calladdr { octet addrlens; @@ -144,8 +148,6 @@ struct data_packet { #define SET_LCN(xp, lcn) ((xp -> logical_channel_number = lcn), \ (X25SBITS(xp -> bits, lc_group_number, lcn > 255 ? lcn >> 8 : 0))) -struct mbuf *pk_template (); - /* Define X.25 packet level states. */ /* Call setup and clearing substates. */ @@ -177,23 +179,23 @@ struct mbuf *pk_template (); * pk_decode procedure. */ -#define CALL 0 * MAXSTATES -#define CALL_ACCEPTED 1 * MAXSTATES -#define CLEAR 2 * MAXSTATES -#define CLEAR_CONF 3 * MAXSTATES -#define DATA 4 * MAXSTATES -#define INTERRUPT 5 * MAXSTATES -#define INTERRUPT_CONF 6 * MAXSTATES -#define RR 7 * MAXSTATES -#define RNR 8 * MAXSTATES -#define RESET 9 * MAXSTATES -#define RESET_CONF 10 * MAXSTATES -#define RESTART 11 * MAXSTATES -#define RESTART_CONF 12 * MAXSTATES -#define REJECT 13 * MAXSTATES -#define DIAG_TYPE 14 * MAXSTATES -#define INVALID_PACKET 15 * MAXSTATES -#define DELETE_PACKET INVALID_PACKET +#define PK_CALL (0 * MAXSTATES) +#define PK_CALL_ACCEPTED (1 * MAXSTATES) +#define PK_CLEAR (2 * MAXSTATES) +#define PK_CLEAR_CONF (3 * MAXSTATES) +#define PK_DATA (4 * MAXSTATES) +#define PK_INTERRUPT (5 * MAXSTATES) +#define PK_INTERRUPT_CONF (6 * MAXSTATES) +#define PK_RR (7 * MAXSTATES) +#define PK_RNR (8 * MAXSTATES) +#define PK_RESET (9 * MAXSTATES) +#define PK_RESET_CONF (10 * MAXSTATES) +#define PK_RESTART (11 * MAXSTATES) +#define PK_RESTART_CONF (12 * MAXSTATES) +#define PK_REJECT (13 * MAXSTATES) +#define PK_DIAG_TYPE (14 * MAXSTATES) +#define PK_INVALID_PACKET (15 * MAXSTATES) +#define PK_DELETE_PACKET (PK_INVALID_PACKET) /* * The following definitions are used by the restart procedures diff --git a/sys/netccitt/pk_acct.c b/sys/netccitt/pk_acct.c index 44e579864d8..e77b63f79e8 100644 --- a/sys/netccitt/pk_acct.c +++ b/sys/netccitt/pk_acct.c @@ -1,4 +1,5 @@ -/* $NetBSD: pk_acct.c,v 1.8 1994/12/14 19:03:39 mycroft Exp $ */ +/* $OpenBSD: pk_acct.c,v 1.2 1996/03/04 07:36:38 niklas Exp $ */ +/* $NetBSD: pk_acct.c,v 1.9 1996/02/13 22:05:11 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -55,6 +56,7 @@ #include #include #include +#include #include @@ -62,7 +64,7 @@ struct vnode *pkacctp; /* * Turn on packet accounting */ - +int pk_accton (path) char *path; { @@ -75,7 +77,7 @@ pk_accton (path) if (path == 0) goto close; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p); - if (error = vn_open (&nd, FWRITE, 0644)) + if ((error = vn_open (&nd, FWRITE, 0644)) != 0) return (error); vp = nd.ni_vp; VOP_UNLOCK(vp); @@ -95,14 +97,14 @@ pk_accton (path) * Write a record on the accounting file. */ +void pk_acct (lcp) -register struct pklcd *lcp; + register struct pklcd *lcp; { register struct vnode *vp; register struct sockaddr_x25 *sa; register char *src, *dst; register int len; - register long etime; static struct x25acct acbuf; if ((vp = pkacctp) == 0) diff --git a/sys/netccitt/pk_debug.c b/sys/netccitt/pk_debug.c index f7a755d6061..b01de01396a 100644 --- a/sys/netccitt/pk_debug.c +++ b/sys/netccitt/pk_debug.c @@ -1,4 +1,5 @@ -/* $NetBSD: pk_debug.c,v 1.5 1994/06/29 06:37:31 cgd Exp $ */ +/* $OpenBSD: pk_debug.c,v 1.2 1996/03/04 07:36:39 niklas Exp $ */ +/* $NetBSD: pk_debug.c,v 1.6 1996/02/13 22:05:14 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -53,6 +54,7 @@ #include #include #include +#include char *pk_state[] = { "Listen", "Ready", "Received-Call", @@ -68,10 +70,11 @@ char *pk_name[] = { "Invalid" }; +void pk_trace (xcp, m, dir) -struct x25config *xcp; -register struct mbuf *m; -char *dir; + struct x25config *xcp; + register struct mbuf *m; + char *dir; { register char *s; struct x25_packet *xp = mtod(m, struct x25_packet *); @@ -92,9 +95,10 @@ char *dir; printf ("\n"); } +void mbuf_cache(c, m) -register struct mbuf_cache *c; -struct mbuf *m; + register struct mbuf_cache *c; + struct mbuf *m; { register struct mbuf **mp; @@ -137,6 +141,6 @@ struct mbuf *m; c->mbc_num = (1 + c->mbc_num) % c->mbc_size; if (*mp) m_freem(*mp); - if (*mp = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) + if ((*mp = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) != NULL) (*mp)->m_flags |= m->m_flags & 0x08; } diff --git a/sys/netccitt/pk_extern.h b/sys/netccitt/pk_extern.h new file mode 100644 index 00000000000..3bea62343b3 --- /dev/null +++ b/sys/netccitt/pk_extern.h @@ -0,0 +1,121 @@ +/* $OpenBSD: pk_extern.h,v 1.1 1996/03/04 07:36:40 niklas Exp $ */ +/* $NetBSD: pk_extern.h,v 1.1 1996/02/13 22:05:17 christos Exp $ */ + +/* + * Copyright (c) 1995 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#ifdef _KERNEL +struct pklcd; +struct mbuf_cache; +struct x25_ifaddr; +struct x25_calladdr; +struct x25_packet; +struct llc_linkcb; +struct bcdinfo; +struct sockaddr_dl; + +/* pk_acct.c */ +int pk_accton __P((char *)); +void pk_acct __P((struct pklcd *)); + +/* pk_debug.c */ +void pk_trace __P((struct x25config *, struct mbuf *, char *)); +void mbuf_cache __P((struct mbuf_cache *, struct mbuf *)); + +/* pk_input.c */ +void ccittintr __P((void)); +struct pkcb *pk_newlink __P((struct x25_ifaddr *, caddr_t)); +int pk_dellink __P((struct pkcb *)); +int pk_resize __P((struct pkcb *)); +void *pk_ctlinput __P((int, struct sockaddr *, void *)); +void pkintr __P((void)); +void pk_input __P((struct mbuf *, ...)); +void pk_simple_bsd __P((octet *, octet *, int, int)); +void pk_from_bcd __P((struct x25_calladdr *, int, struct sockaddr_x25 *, + struct x25config *)); +void pk_incoming_call __P((struct pkcb *, struct mbuf *)); +void pk_call_accepted __P((struct pklcd *, struct mbuf *)); +void pk_parse_facilities __P((octet *, struct sockaddr_x25 *)); + +/* pk_llcsubr.c */ +int cons_rtrequest __P((int, struct rtentry *, struct sockaddr *)); +struct rtentry *npaidb_enter __P((struct sockaddr_dl *, struct sockaddr *, + struct rtentry *, struct llc_linkcb *)); +struct rtentry *npaidb_enrich __P((short, caddr_t, struct sockaddr_dl *)); +int npaidb_destroy __P((struct rtentry *)); +long x25_llcglue __P((int, struct sockaddr *)); + +/* pk_output.c */ +void pk_output __P((struct pklcd *)); +struct mbuf *nextpk __P((struct pklcd *)); + +/* pk_subr.c */ +struct pklcd *pk_attach __P((struct socket *)); +void pk_disconnect __P((struct pklcd *)); +void pk_close __P((struct pklcd *)); +struct mbuf *pk_template __P((int, int)); +void pk_restart __P((struct pkcb *, int)); +void pk_freelcd __P((struct pklcd *)); +int pk_bind __P((struct pklcd *, struct mbuf *)); +int pk_listen __P((struct pklcd *)); +int pk_protolisten __P((int, int, int (*)(struct mbuf *, void *))); +void pk_assoc __P((struct pkcb *, struct pklcd *, struct sockaddr_x25 *)); +int pk_connect __P((struct pklcd *, struct sockaddr_x25 *)); +void pk_callcomplete __P((struct pkcb *)); +void pk_callrequest __P((struct pklcd *, struct sockaddr_x25 *, + struct x25config *)); +void pk_build_facilities __P((struct mbuf *, struct sockaddr_x25 *, int)); +int to_bcd __P((struct bcdinfo *, struct sockaddr_x25 *, struct x25config *)); +int pk_getlcn __P((struct pkcb *)); +void pk_clear __P((struct pklcd *, int, int)); +void pk_flowcontrol __P((struct pklcd *, int, int)); +void pk_flush __P((struct pklcd *)); +void pk_procerror __P((int, struct pklcd *, char *, int)); +int pk_ack __P((struct pklcd *, unsigned)); +int pk_decode __P((struct x25_packet *)); +void pk_restartcause __P((struct pkcb *, struct x25_packet *)); +void pk_resetcause __P((struct pkcb *, struct x25_packet *)); +void pk_clearcause __P((struct pkcb *, struct x25_packet *)); +char *format_ntn __P((struct x25config *)); +void pk_message __P((int, struct x25config *, char *, ...)); +int pk_fragment __P((struct pklcd *, struct mbuf *, int, int, int)); + +/* pk_timer.c */ +void pk_timer __P((void)); + +/* pk_usrreq.c */ +int pk_usrreq __P((struct socket *, int, struct mbuf *, struct mbuf *, + struct mbuf *)); +int pk_start __P((struct pklcd *)); +int pk_control __P((struct socket *, u_long, caddr_t, struct ifnet *)); +int pk_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); +int pk_checksockaddr __P((struct mbuf *)); +int pk_send __P((struct mbuf *, void *)); + +#endif diff --git a/sys/netccitt/pk_input.c b/sys/netccitt/pk_input.c index 343c82c1fcb..7ed158197d9 100644 --- a/sys/netccitt/pk_input.c +++ b/sys/netccitt/pk_input.c @@ -1,8 +1,9 @@ -/* $NetBSD: pk_input.c,v 1.6 1994/06/29 06:37:33 cgd Exp $ */ +/* $OpenBSD: pk_input.c,v 1.2 1996/03/04 07:36:41 niklas Exp $ */ +/* $NetBSD: pk_input.c,v 1.7 1996/02/13 22:05:21 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 - * Copyright (C) Computer Science Department IV, + * Copyright (C) Computer Science Department IV, * University of Erlangen-Nuremberg, Germany, 1992 * Copyright (c) 1991, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -49,6 +50,7 @@ #include #include #include +#include #include #include @@ -60,9 +62,19 @@ #include #include #include +#include #include +#ifdef HDLC +#include +#include +#endif + +#include + +struct pkcb_q pkcb_q = {&pkcb_q, &pkcb_q}; -struct pkcb_q pkcb_q = {&pkcb_q, &pkcb_q}; +static void prune_dnic __P((char *, char *, char *, struct x25config *)); +static void save_extra __P((struct mbuf *, octet *, struct socket *)); /* * ccittintr() is the generic interrupt handler for HDLC, LLC2, and X.25. This @@ -70,7 +82,7 @@ struct pkcb_q pkcb_q = {&pkcb_q, &pkcb_q}; * employ boards that do all the stuff themselves, e.g. ADAX X.25 or TPS ISDN.) */ void -ccittintr () +ccittintr() { extern struct ifqueue pkintrq; extern struct ifqueue hdintrq; @@ -78,71 +90,71 @@ ccittintr () #ifdef HDLC if (hdintrq.ifq_len) - hdintr (); + hdintr(); #endif #ifdef LLC if (llcintrq.ifq_len) - llcintr (); + llcintr(); #endif if (pkintrq.ifq_len) - pkintr (); + pkintr(); } -struct pkcb * -pk_newlink (ia, llnext) -struct x25_ifaddr *ia; -caddr_t llnext; +struct pkcb * +pk_newlink(ia, llnext) + struct x25_ifaddr *ia; + caddr_t llnext; { - register struct x25config *xcp = &ia -> ia_xc; + register struct x25config *xcp = &ia->ia_xc; register struct pkcb *pkp; - register struct pklcd *lcp; register struct protosw *pp; - unsigned size; + unsigned size; - pp = pffindproto (AF_CCITT, (int) xcp -> xc_lproto, 0); - if (pp == 0 || pp -> pr_output == 0) { - pk_message (0, xcp, "link level protosw error"); - return ((struct pkcb *)0); + pp = pffindproto(AF_CCITT, (int) xcp->xc_lproto, 0); + 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); - pkp = (struct pkcb *) malloc (size, M_PCB, M_WAITOK); + size = sizeof(struct pkcb); + pkp = (struct pkcb *) malloc(size, M_PCB, M_WAITOK); if (pkp == 0) - return ((struct pkcb *)0); - bzero ((caddr_t) pkp, size); - pkp -> pk_lloutput = pp -> pr_output; - pkp -> pk_llctlinput = (caddr_t (*)()) pp -> pr_ctlinput; - pkp -> pk_xcp = xcp; - pkp -> pk_ia = ia; - pkp -> pk_state = DTE_WAITING; - pkp -> pk_llnext = llnext; - insque (pkp, &pkcb_q); + return ((struct pkcb *) 0); + bzero((caddr_t) pkp, size); + pkp->pk_lloutput = pp->pr_output; + pkp->pk_llctlinput = pp->pr_ctlinput; + pkp->pk_xcp = xcp; + pkp->pk_ia = ia; + pkp->pk_state = DTE_WAITING; + pkp->pk_llnext = llnext; + insque(pkp, &pkcb_q); /* * set defaults */ - if (xcp -> xc_pwsize == 0) - xcp -> xc_pwsize = DEFAULT_WINDOW_SIZE; - if (xcp -> xc_psize == 0) - xcp -> xc_psize = X25_PS128; + if (xcp->xc_pwsize == 0) + xcp->xc_pwsize = DEFAULT_WINDOW_SIZE; + if (xcp->xc_psize == 0) + xcp->xc_psize = X25_PS128; /* * Allocate logical channel descriptor vector */ - (void) pk_resize (pkp); + (void) pk_resize(pkp); return (pkp); } -pk_dellink (pkp) -register struct pkcb *pkp; +int +pk_dellink(pkp) + register struct pkcb *pkp; { - register int i; + register int i; register struct protosw *pp; - + /* * Essentially we have the choice to * (a) go ahead and let the route be deleted and @@ -153,10 +165,10 @@ register struct pkcb *pkp; * * For the time being we stick with (b) */ - - for (i = 1; i < pkp -> pk_maxlcn; ++i) - if (pkp -> pk_chan[i]) - pk_disconnect (pkp -> pk_chan[i]); + + for (i = 1; i < pkp->pk_maxlcn; ++i) + if (pkp->pk_chan[i]) + pk_disconnect(pkp->pk_chan[i]); /* * Free the pkcb @@ -167,784 +179,808 @@ register struct pkcb *pkp; * protocol to be notified that the packet level entity is * dissolving ... */ - pp = pffindproto (AF_CCITT, (int) pkp -> pk_xcp -> xc_lproto, 0); - if (pp == 0 || pp -> pr_output == 0) { - pk_message (0, pkp -> pk_xcp, "link level protosw error"); + pp = pffindproto(AF_CCITT, (int) pkp->pk_xcp->xc_lproto, 0); + if (pp == 0 || pp->pr_output == 0) { + pk_message(0, pkp->pk_xcp, "link level protosw error"); return (EPROTONOSUPPORT); } - - pkp -> pk_refcount--; - if (!pkp -> pk_refcount) { + pkp->pk_refcount--; + if (!pkp->pk_refcount) { struct dll_ctlinfo ctlinfo; - remque (pkp); - if (pkp -> pk_rt -> rt_llinfo == (caddr_t) pkp) - pkp -> pk_rt -> rt_llinfo = (caddr_t) NULL; - + remque(pkp); + if (pkp->pk_rt->rt_llinfo == (caddr_t) pkp) + pkp->pk_rt->rt_llinfo = (caddr_t) NULL; + /* * Tell the link level that the pkcb is dissolving */ - if (pp -> pr_ctlinput && pkp -> pk_llnext) { - ctlinfo.dlcti_pcb = pkp -> pk_llnext; - ctlinfo.dlcti_rt = pkp -> pk_rt; - (pp -> pr_ctlinput)(PRC_DISCONNECT_REQUEST, - pkp -> pk_xcp, &ctlinfo); + if (pp->pr_ctlinput && pkp->pk_llnext) { + ctlinfo.dlcti_pcb = pkp->pk_llnext; + ctlinfo.dlcti_rt = pkp->pk_rt; + (*pp->pr_ctlinput) (PRC_DISCONNECT_REQUEST, + (struct sockaddr *)pkp->pk_xcp, + &ctlinfo); } - free ((caddr_t) pkp -> pk_chan, M_IFADDR); - free ((caddr_t) pkp, M_PCB); + free((caddr_t) pkp->pk_chan, M_IFADDR); + free((caddr_t) pkp, M_PCB); } - return (0); } -pk_resize (pkp) -register struct pkcb *pkp; +int +pk_resize(pkp) + register struct pkcb *pkp; { - struct pklcd *dev_lcp = 0; - struct x25config *xcp = pkp -> pk_xcp; - if (pkp -> pk_chan && - (pkp -> pk_maxlcn != xcp -> xc_maxlcn)) { - pk_restart (pkp, X25_RESTART_NETWORK_CONGESTION); - dev_lcp = pkp -> pk_chan[0]; - free ((caddr_t) pkp -> pk_chan, M_IFADDR); - pkp -> pk_chan = 0; + struct pklcd *dev_lcp = 0; + struct x25config *xcp = pkp->pk_xcp; + if (pkp->pk_chan && + (pkp->pk_maxlcn != xcp->xc_maxlcn)) { + pk_restart(pkp, X25_RESTART_NETWORK_CONGESTION); + dev_lcp = pkp->pk_chan[0]; + free((caddr_t) pkp->pk_chan, M_IFADDR); + pkp->pk_chan = 0; } - if (pkp -> pk_chan == 0) { - unsigned size; - pkp -> pk_maxlcn = xcp -> xc_maxlcn; - size = (pkp -> pk_maxlcn + 1) * sizeof (struct pklcd *); - pkp -> pk_chan = - (struct pklcd **) malloc (size, M_IFADDR, M_WAITOK); - if (pkp -> pk_chan) { - bzero ((caddr_t) pkp -> pk_chan, size); + if (pkp->pk_chan == 0) { + unsigned size; + pkp->pk_maxlcn = xcp->xc_maxlcn; + size = (pkp->pk_maxlcn + 1) * sizeof(struct pklcd *); + pkp->pk_chan = malloc(size, M_IFADDR, M_WAITOK); + if (pkp->pk_chan) { + bzero((caddr_t) pkp->pk_chan, size); /* * Allocate a logical channel descriptor for lcn 0 */ if (dev_lcp == 0 && - (dev_lcp = pk_attach ((struct socket *)0)) == 0) + (dev_lcp = pk_attach((struct socket *) 0)) == 0) return (ENOBUFS); - dev_lcp -> lcd_state = READY; - dev_lcp -> lcd_pkp = pkp; - pkp -> pk_chan[0] = dev_lcp; + dev_lcp->lcd_state = READY; + dev_lcp->lcd_pkp = pkp; + pkp->pk_chan[0] = dev_lcp; } else { if (dev_lcp) - pk_close (dev_lcp); + pk_close(dev_lcp); return (ENOBUFS); } } return 0; } -/* - * 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. */ -/*VARARGS*/ -caddr_t -pk_ctlinput (code, src, addr) +/* VARARGS */ +void * +pk_ctlinput(code, src, addr) + int code; struct sockaddr *src; - caddr_t addr; + void *addr; { register struct pkcb *pkp = (struct pkcb *) addr; + struct rtentry *llrt; switch (code) { - case PRC_LINKUP: - if (pkp -> pk_state == DTE_WAITING) - pk_restart (pkp, X25_RESTART_NETWORK_CONGESTION); + case PRC_LINKUP: + if (pkp->pk_state == DTE_WAITING) + pk_restart(pkp, X25_RESTART_NETWORK_CONGESTION); break; - case PRC_LINKDOWN: - pk_restart (pkp, -1); /* Clear all active circuits */ - pkp -> pk_state = DTE_WAITING; + case PRC_LINKDOWN: + pk_restart(pkp, -1); /* Clear all active circuits */ + pkp->pk_state = DTE_WAITING; break; - case PRC_LINKRESET: - pk_restart (pkp, X25_RESTART_NETWORK_CONGESTION); + case PRC_LINKRESET: + pk_restart(pkp, X25_RESTART_NETWORK_CONGESTION); break; - - case PRC_CONNECT_INDICATION: { - struct rtentry *llrt; + + case PRC_CONNECT_INDICATION: if ((llrt = rtalloc1(src, 0)) == 0) return 0; - else llrt -> rt_refcnt--; - - pkp = (((struct npaidbentry *) llrt -> rt_llinfo) -> np_rt) ? - (struct pkcb *)(((struct npaidbentry *) llrt -> rt_llinfo) -> np_rt -> rt_llinfo) : (struct pkcb *) 0; + else + llrt->rt_refcnt--; + + pkp = (((struct npaidbentry *) llrt->rt_llinfo)->np_rt) ? + (struct pkcb *) (((struct npaidbentry *) llrt->rt_llinfo)->np_rt->rt_llinfo) : (struct pkcb *) 0; if (pkp == (struct pkcb *) 0) return 0; - pkp -> pk_llnext = addr; + pkp->pk_llnext = addr; return ((caddr_t) pkp); - } + case PRC_DISCONNECT_INDICATION: - pk_restart (pkp, -1) ; /* Clear all active circuits */ - pkp -> pk_state = DTE_WAITING; - pkp -> pk_llnext = (caddr_t) 0; + pk_restart(pkp, -1); /* Clear all active circuits */ + pkp->pk_state = DTE_WAITING; + pkp->pk_llnext = (caddr_t) 0; + break; } return (0); } -struct ifqueue pkintrq; +struct ifqueue pkintrq; /* * This routine is called if there are semi-smart devices that do HDLC * in hardware and want to queue the packet and call level 3 directly */ -pkintr () +void +pkintr() { register struct mbuf *m; - register struct ifaddr *ifa; - register struct ifnet *ifp; - register int s; + register int s; for (;;) { - s = splimp (); - IF_DEQUEUE (&pkintrq, m); - splx (s); + s = splimp(); + IF_DEQUEUE(&pkintrq, m); + splx(s); if (m == 0) break; - if (m -> m_len < PKHEADERLN) { - printf ("pkintr: packet too short (len=%d)\n", - m -> m_len); - m_freem (m); + if (m->m_len < PKHEADERLN) { + printf("pkintr: packet too short (len=%d)\n", + m->m_len); + m_freem(m); continue; } - pk_input (m); + pk_input(m); } } -struct mbuf *pk_bad_packet; -struct mbuf_cache pk_input_cache = {0 }; -/* - * X.25 PACKET INPUT - * - * This procedure is called by a link level procedure whenever - * an information frame is received. It decodes the packet and - * demultiplexes based on the logical channel number. - * - * We change the original conventions of the UBC code here -- - * since there may be multiple pkcb's for a given interface - * of type 802.2 class 2, we retrieve which one it is from - * m_pkthdr.rcvif (which has been overwritten by lower layers); - * That field is then restored for the benefit of upper layers which - * may make use of it, such as CLNP. - * + +struct mbuf *pk_bad_packet; +struct mbuf_cache pk_input_cache = {0}; +/* + * X.25 PACKET INPUT + * + * This procedure is called by a link level procedure whenever an information + * frame is received. It decodes the packet and demultiplexes based on the + * logical channel number. + * + * We change the original conventions of the UBC code here -- since there may be + * multiple pkcb's for a given interface of type 802.2 class 2, we retrieve + * which one it is from m_pkthdr.rcvif (which has been overwritten by lower + * layers); That field is then restored for the benefit of upper layers which + * may make use of it, such as CLNP. + * */ -#define RESTART_DTE_ORIGINATED(xp) (((xp) -> packet_cause == X25_RESTART_DTE_ORIGINATED) || \ - ((xp) -> packet_cause >= X25_RESTART_DTE_ORIGINATED2)) +#define RESTART_DTE_ORIGINATED(xp) \ + (((xp)->packet_cause == X25_RESTART_DTE_ORIGINATED) || \ + ((xp)->packet_cause >= X25_RESTART_DTE_ORIGINATED2)) -pk_input (m) -register struct mbuf *m; +void +#if __STDC__ +pk_input(struct mbuf *m, ...) +#else +pk_input(m, va_alist) + struct mbuf *m; + va_dcl +#endif { register struct x25_packet *xp; register struct pklcd *lcp; register struct socket *so = 0; register struct pkcb *pkp; - int ptype, lcn, lcdstate = LISTEN; + int ptype, lcn, lcdstate = LISTEN; if (pk_input_cache.mbc_size || pk_input_cache.mbc_oldsize) - mbuf_cache (&pk_input_cache, m); - if ((m -> m_flags & M_PKTHDR) == 0) - panic ("pkintr"); + mbuf_cache(&pk_input_cache, m); + if ((m->m_flags & M_PKTHDR) == 0) + panic("pkintr"); - if ((pkp = (struct pkcb *) m -> m_pkthdr.rcvif) == 0) + if ((pkp = (struct pkcb *) m->m_pkthdr.rcvif) == 0) return; - xp = mtod (m, struct x25_packet *); - ptype = pk_decode (xp); + xp = mtod(m, struct x25_packet *); + ptype = pk_decode(xp); lcn = LCN(xp); - lcp = pkp -> pk_chan[lcn]; + lcp = pkp->pk_chan[lcn]; - /* - * If the DTE is in Restart state, then it will ignore data, - * interrupt, call setup and clearing, flow control and reset - * packets. + /* + * If the DTE is in Restart state, then it will ignore data, + * interrupt, call setup and clearing, flow control and reset + * packets. */ - if (lcn < 0 || lcn > pkp -> pk_maxlcn) { - pk_message (lcn, pkp -> pk_xcp, "illegal lcn"); - m_freem (m); + if (lcn < 0 || lcn > pkp->pk_maxlcn) { + pk_message(lcn, pkp->pk_xcp, "illegal lcn"); + m_freem(m); return; } + pk_trace(pkp->pk_xcp, m, "P-In"); - pk_trace (pkp -> pk_xcp, m, "P-In"); - - if (pkp -> pk_state != DTE_READY && ptype != RESTART && ptype != RESTART_CONF) { - m_freem (m); + if (pkp->pk_state != DTE_READY && ptype != PK_RESTART && + ptype != PK_RESTART_CONF) { + m_freem(m); return; } if (lcp) { - so = lcp -> lcd_so; - lcdstate = lcp -> lcd_state; + so = lcp->lcd_so; + lcdstate = lcp->lcd_state; } else { - if (ptype == CLEAR) { /* idle line probe (Datapac specific) */ + if (ptype == PK_CLEAR) {/* idle line probe (Datapac specific) */ /* send response on lcd 0's output queue */ - lcp = pkp -> pk_chan[0]; - lcp -> lcd_template = pk_template (lcn, X25_CLEAR_CONFIRM); - pk_output (lcp); - m_freem (m); + lcp = pkp->pk_chan[0]; + lcp->lcd_template = pk_template(lcn, X25_CLEAR_CONFIRM); + pk_output(lcp); + m_freem(m); return; } - if (ptype != CALL) - ptype = INVALID_PACKET; + if (ptype != PK_CALL) + ptype = PK_INVALID_PACKET; } - if (lcn == 0 && ptype != RESTART && ptype != RESTART_CONF) { - pk_message (0, pkp -> pk_xcp, "illegal ptype (%d, %s) on lcn 0", - ptype, pk_name[ptype / MAXSTATES]); + if (lcn == 0 && ptype != PK_RESTART && ptype != PK_RESTART_CONF) { + pk_message(0, pkp->pk_xcp, "illegal ptype (%d, %s) on lcn 0", + ptype, pk_name[ptype / MAXSTATES]); if (pk_bad_packet) - m_freem (pk_bad_packet); + m_freem(pk_bad_packet); pk_bad_packet = m; return; } - - m -> m_pkthdr.rcvif = pkp -> pk_ia -> ia_ifp; + m->m_pkthdr.rcvif = pkp->pk_ia->ia_ifp; switch (ptype + lcdstate) { - /* - * Incoming Call packet received. - */ - case CALL + LISTEN: - pk_incoming_call (pkp, m); + /* + * Incoming Call packet received. + */ + case PK_CALL + LISTEN: + pk_incoming_call(pkp, m); break; - /* - * Call collision: Just throw this "incoming call" away since - * the DCE will ignore it anyway. - */ - case CALL + SENT_CALL: - pk_message ((int) lcn, pkp -> pk_xcp, - "incoming call collision"); + /* + * Call collision: Just throw this "incoming call" away since + * the DCE will ignore it anyway. + */ + case PK_CALL + SENT_CALL: + pk_message((int) lcn, pkp->pk_xcp, + "incoming call collision"); break; - /* - * Call confirmation packet received. This usually means our - * previous connect request is now complete. - */ - case CALL_ACCEPTED + SENT_CALL: + /* + * Call confirmation packet received. This usually means our + * previous connect request is now complete. + */ + case PK_CALL_ACCEPTED + SENT_CALL: MCHTYPE(m, MT_CONTROL); - pk_call_accepted (lcp, m); + pk_call_accepted(lcp, m); break; - /* - * This condition can only happen if the previous state was - * SENT_CALL. Just ignore the packet, eventually a clear - * confirmation should arrive. - */ - case CALL_ACCEPTED + SENT_CLEAR: + /* + * This condition can only happen if the previous state was + * SENT_CALL. Just ignore the packet, eventually a clear + * confirmation should arrive. + */ + case PK_CALL_ACCEPTED + SENT_CLEAR: break; - /* - * Clear packet received. This requires a complete tear down - * of the virtual circuit. Free buffers and control blocks. - * and send a clear confirmation. - */ - case CLEAR + READY: - case CLEAR + RECEIVED_CALL: - case CLEAR + SENT_CALL: - case CLEAR + DATA_TRANSFER: - lcp -> lcd_state = RECEIVED_CLEAR; - lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_CLEAR_CONFIRM); - pk_output (lcp); - pk_clearcause (pkp, xp); - if (lcp -> lcd_upper) { + /* + * Clear packet received. This requires a complete tear down + * of the virtual circuit. Free buffers and control blocks. + * and send a clear confirmation. + */ + case PK_CLEAR + READY: + case PK_CLEAR + RECEIVED_CALL: + case PK_CLEAR + SENT_CALL: + case PK_CLEAR + DATA_TRANSFER: + lcp->lcd_state = RECEIVED_CLEAR; + lcp->lcd_template = pk_template(lcp->lcd_lcn, X25_CLEAR_CONFIRM); + pk_output(lcp); + pk_clearcause(pkp, xp); + if (lcp->lcd_upper) { MCHTYPE(m, MT_CONTROL); - lcp -> lcd_upper (lcp, m); + (*lcp->lcd_upper)(m, lcp); } - pk_close (lcp); + pk_close(lcp); lcp = 0; break; - /* - * Clear collision: Treat this clear packet as a confirmation. - */ - case CLEAR + SENT_CLEAR: - pk_close (lcp); + /* + * Clear collision: Treat this clear packet as a + * confirmation. + */ + case PK_CLEAR + SENT_CLEAR: + pk_close(lcp); break; - /* - * Clear confirmation received. This usually means the virtual - * circuit is now completely removed. - */ - case CLEAR_CONF + SENT_CLEAR: - pk_close (lcp); + /* + * Clear confirmation received. This usually means the + * virtual circuit is now completely removed. + */ + case PK_CLEAR_CONF + SENT_CLEAR: + pk_close(lcp); break; - /* - * A clear confirmation on an unassigned logical channel - just - * ignore it. Note: All other packets on an unassigned channel - * results in a clear. - */ - case CLEAR_CONF + READY: - case CLEAR_CONF + LISTEN: + /* + * A clear confirmation on an unassigned logical channel - + * just ignore it. Note: All other packets on an unassigned + * channel results in a clear. + */ + case PK_CLEAR_CONF + READY: + case PK_CLEAR_CONF + LISTEN: break; - /* - * Data packet received. Pass on to next level. Move the Q and M - * bits into the data portion for the next level. - */ - case DATA + DATA_TRANSFER: - if (lcp -> lcd_reset_condition) { - ptype = DELETE_PACKET; + /* + * Data packet received. Pass on to next level. Move the Q + * and M bits into the data portion for the next level. + */ + case PK_DATA + DATA_TRANSFER: + if (lcp->lcd_reset_condition) { + ptype = PK_DELETE_PACKET; break; } - - /* - * Process the P(S) flow control information in this Data packet. - * Check that the packets arrive in the correct sequence and that - * they are within the "lcd_input_window". Input window rotation is - * initiated by the receive interface. + /* + * Process the P(S) flow control information in this Data + * packet. Check that the packets arrive in the correct + * sequence and that they are within the "lcd_input_window". + * Input window rotation is initiated by the receive + * interface. */ - if (PS(xp) != ((lcp -> lcd_rsn + 1) % MODULUS) || - PS(xp) == ((lcp -> lcd_input_window + lcp -> lcd_windowsize) % MODULUS)) { - m_freem (m); - pk_procerror (RESET, lcp, "p(s) flow control error", 1); + if (PS(xp) != ((lcp->lcd_rsn + 1) % MODULUS) || + PS(xp) == ((lcp->lcd_input_window + lcp->lcd_windowsize) % MODULUS)) { + m_freem(m); + pk_procerror(PK_RESET, lcp, + "p(s) flow control error", 1); break; } - lcp -> lcd_rsn = PS(xp); + lcp->lcd_rsn = PS(xp); - if (pk_ack (lcp, PR(xp)) != PACKET_OK) { - m_freem (m); + if (pk_ack(lcp, PR(xp)) != PACKET_OK) { + m_freem(m); break; } - m -> m_data += PKHEADERLN; - m -> m_len -= PKHEADERLN; - m -> m_pkthdr.len -= PKHEADERLN; + m->m_data += PKHEADERLN; + m->m_len -= PKHEADERLN; + m->m_pkthdr.len -= PKHEADERLN; - lcp -> lcd_rxcnt++; - if (lcp -> lcd_flags & X25_MBS_HOLD) { - register struct mbuf *n = lcp -> lcd_cps; - int mbit = MBIT(xp); - octet q_and_d_bits; + lcp->lcd_rxcnt++; + if (lcp->lcd_flags & X25_MBS_HOLD) { + register struct mbuf *n = lcp->lcd_cps; + int mbit = MBIT(xp); + octet q_and_d_bits; if (n) { - n -> m_pkthdr.len += m -> m_pkthdr.len; - while (n -> m_next) - n = n -> m_next; - n -> m_next = m; - m = lcp -> lcd_cps; - - if (lcp -> lcd_cpsmax && - n -> m_pkthdr.len > lcp -> lcd_cpsmax) { - pk_procerror (RESET, lcp, - "C.P.S. overflow", 128); + n->m_pkthdr.len += m->m_pkthdr.len; + while (n->m_next) + n = n->m_next; + n->m_next = m; + m = lcp->lcd_cps; + + if (lcp->lcd_cpsmax && + n->m_pkthdr.len > lcp->lcd_cpsmax) { + pk_procerror(PK_RESET, lcp, + "C.P.S. overflow", 128); return; } q_and_d_bits = 0xc0 & *(octet *) xp; xp = (struct x25_packet *) - (mtod (m, octet *) - PKHEADERLN); + (mtod(m, octet *) - PKHEADERLN); *(octet *) xp |= q_and_d_bits; } if (mbit) { - lcp -> lcd_cps = m; - pk_flowcontrol (lcp, 0, 1); + lcp->lcd_cps = m; + pk_flowcontrol(lcp, 0, 1); return; } - lcp -> lcd_cps = 0; + lcp->lcd_cps = 0; } if (so == 0) break; - if (lcp -> lcd_flags & X25_MQBIT) { - octet t = (X25GBITS(xp -> bits, q_bit)) ? t = 0x80 : 0; + if (lcp->lcd_flags & X25_MQBIT) { + octet t = (X25GBITS(xp->bits, q_bit)) ? t = 0x80 : 0; if (MBIT(xp)) t |= 0x40; - m -> m_data -= 1; - m -> m_len += 1; - m -> m_pkthdr.len += 1; - *mtod (m, octet *) = t; + m->m_data -= 1; + m->m_len += 1; + m->m_pkthdr.len += 1; + *mtod(m, octet *) = t; } - /* * Discard Q-BIT packets if the application * doesn't want to be informed of M and Q bit status */ - if (X25GBITS(xp -> bits, q_bit) - && (lcp -> lcd_flags & X25_MQBIT) == 0) { - m_freem (m); + if (X25GBITS(xp->bits, q_bit) + && (lcp->lcd_flags & X25_MQBIT) == 0) { + m_freem(m); /* * NB. This is dangerous: sending a RR here can * cause sequence number errors if a previous data * packet has not yet been passed up to the application * (RR's are normally generated via PRU_RCVD). */ - pk_flowcontrol (lcp, 0, 1); + pk_flowcontrol(lcp, 0, 1); } else { - sbappendrecord (&so -> so_rcv, m); - sorwakeup (so); + sbappendrecord(&so->so_rcv, m); + sorwakeup(so); } break; - /* - * Interrupt packet received. - */ - case INTERRUPT + DATA_TRANSFER: - if (lcp -> lcd_reset_condition) + /* + * Interrupt packet received. + */ + case PK_INTERRUPT + DATA_TRANSFER: + if (lcp->lcd_reset_condition) break; - lcp -> lcd_intrdata = xp -> packet_data; - lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_INTERRUPT_CONFIRM); - pk_output (lcp); - m -> m_data += PKHEADERLN; - m -> m_len -= PKHEADERLN; - m -> m_pkthdr.len -= PKHEADERLN; + lcp->lcd_intrdata = xp->packet_data; + lcp->lcd_template = pk_template(lcp->lcd_lcn, + X25_INTERRUPT_CONFIRM); + pk_output(lcp); + m->m_data += PKHEADERLN; + m->m_len -= PKHEADERLN; + m->m_pkthdr.len -= PKHEADERLN; MCHTYPE(m, MT_OOBDATA); if (so) { - if (so -> so_options & SO_OOBINLINE) - sbinsertoob (&so -> so_rcv, m); + if (so->so_options & SO_OOBINLINE) + sbinsertoob(&so->so_rcv, m); else - m_freem (m); - sohasoutofband (so); + m_freem(m); + sohasoutofband(so); } break; - /* - * Interrupt confirmation packet received. - */ - case INTERRUPT_CONF + DATA_TRANSFER: - if (lcp -> lcd_reset_condition) + /* + * Interrupt confirmation packet received. + */ + case PK_INTERRUPT_CONF + DATA_TRANSFER: + if (lcp->lcd_reset_condition) break; - if (lcp -> lcd_intrconf_pending == TRUE) - lcp -> lcd_intrconf_pending = FALSE; + if (lcp->lcd_intrconf_pending == TRUE) + lcp->lcd_intrconf_pending = FALSE; else - pk_procerror (RESET, lcp, "unexpected packet", 43); + pk_procerror(PK_RESET, lcp, "unexpected packet", 43); break; - /* - * Receiver ready received. Rotate the output window and output - * any data packets waiting transmission. - */ - case RR + DATA_TRANSFER: - if (lcp -> lcd_reset_condition || - pk_ack (lcp, PR(xp)) != PACKET_OK) { - ptype = DELETE_PACKET; + /* + * Receiver ready received. Rotate the output window and + * output any data packets waiting transmission. + */ + case PK_RR + DATA_TRANSFER: + if (lcp->lcd_reset_condition || + pk_ack(lcp, PR(xp)) != PACKET_OK) { + ptype = PK_DELETE_PACKET; break; } - if (lcp -> lcd_rnr_condition == TRUE) - lcp -> lcd_rnr_condition = FALSE; - pk_output (lcp); + if (lcp->lcd_rnr_condition == TRUE) + lcp->lcd_rnr_condition = FALSE; + pk_output(lcp); break; - /* - * Receiver Not Ready received. Packets up to the P(R) can be - * be sent. Condition is cleared with a RR. - */ - case RNR + DATA_TRANSFER: - if (lcp -> lcd_reset_condition || - pk_ack (lcp, PR(xp)) != PACKET_OK) { - ptype = DELETE_PACKET; + /* + * Receiver Not Ready received. Packets up to the P(R) can be + * be sent. Condition is cleared with a RR. + */ + case PK_RNR + DATA_TRANSFER: + if (lcp->lcd_reset_condition || + pk_ack(lcp, PR(xp)) != PACKET_OK) { + ptype = PK_DELETE_PACKET; break; } - lcp -> lcd_rnr_condition = TRUE; + lcp->lcd_rnr_condition = TRUE; break; - /* - * Reset packet received. Set state to FLOW_OPEN. The Input and - * Output window edges ar set to zero. Both the send and receive - * numbers are reset. A confirmation is returned. - */ - case RESET + DATA_TRANSFER: - if (lcp -> lcd_reset_condition) + /* + * Reset packet received. Set state to FLOW_OPEN. The Input + * and Output window edges ar set to zero. Both the send and + * receive numbers are reset. A confirmation is returned. + */ + case PK_RESET + DATA_TRANSFER: + if (lcp->lcd_reset_condition) /* Reset collision. Just ignore packet. */ break; - pk_resetcause (pkp, xp); - lcp -> lcd_window_condition = lcp -> lcd_rnr_condition = - lcp -> lcd_intrconf_pending = FALSE; - lcp -> lcd_output_window = lcp -> lcd_input_window = - lcp -> lcd_last_transmitted_pr = 0; - lcp -> lcd_ssn = 0; - lcp -> lcd_rsn = MODULUS - 1; + pk_resetcause(pkp, xp); + lcp->lcd_window_condition = lcp->lcd_rnr_condition = + lcp->lcd_intrconf_pending = FALSE; + lcp->lcd_output_window = lcp->lcd_input_window = + lcp->lcd_last_transmitted_pr = 0; + lcp->lcd_ssn = 0; + lcp->lcd_rsn = MODULUS - 1; - lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_RESET_CONFIRM); - pk_output (lcp); + lcp->lcd_template = pk_template(lcp->lcd_lcn, X25_RESET_CONFIRM); + pk_output(lcp); - pk_flush (lcp); + pk_flush(lcp); if (so == 0) break; - wakeup ((caddr_t) & so -> so_timeo); - sorwakeup (so); - sowwakeup (so); + wakeup((caddr_t) & so->so_timeo); + sorwakeup(so); + sowwakeup(so); break; - /* - * Reset confirmation received. - */ - case RESET_CONF + DATA_TRANSFER: - if (lcp -> lcd_reset_condition) { - lcp -> lcd_reset_condition = FALSE; - pk_output (lcp); - } - else - pk_procerror (RESET, lcp, "unexpected packet", 32); + /* + * Reset confirmation received. + */ + case PK_RESET_CONF + DATA_TRANSFER: + if (lcp->lcd_reset_condition) { + lcp->lcd_reset_condition = FALSE; + pk_output(lcp); + } else + pk_procerror(PK_RESET, lcp, "unexpected packet", 32); break; - case DATA + SENT_CLEAR: - ptype = DELETE_PACKET; - case RR + SENT_CLEAR: - case RNR + SENT_CLEAR: - case INTERRUPT + SENT_CLEAR: - case INTERRUPT_CONF + SENT_CLEAR: - case RESET + SENT_CLEAR: - case RESET_CONF + SENT_CLEAR: - /* Just ignore p if we have sent a CLEAR already. - */ + case PK_DATA + SENT_CLEAR: + ptype = PK_DELETE_PACKET; + case PK_RR + SENT_CLEAR: + case PK_RNR + SENT_CLEAR: + case PK_INTERRUPT + SENT_CLEAR: + case PK_INTERRUPT_CONF + SENT_CLEAR: + case PK_RESET + SENT_CLEAR: + case PK_RESET_CONF + SENT_CLEAR: + /* + * Just ignore p if we have sent a CLEAR already. + */ break; - /* - * Restart sets all the permanent virtual circuits to the "Data - * Transfer" stae and all the switched virtual circuits to the - * "Ready" state. - */ - case RESTART + READY: - switch (pkp -> pk_state) { - case DTE_SENT_RESTART: - /* - * Restart collision. - * If case the restart cause is "DTE originated" we - * have a DTE-DTE situation and are trying to resolve - * who is going to play DTE/DCE [ISO 8208:4.2-4.5] + /* + * Restart sets all the permanent virtual circuits to the + * "Data Transfer" stae and all the switched virtual + * circuits to the "Ready" state. + */ + case PK_RESTART + READY: + switch (pkp->pk_state) { + case DTE_SENT_RESTART: + /* + * Restart collision. If case the restart cause is + * "DTE originated" we have a DTE-DTE situation and + * are trying to resolve who is going to play DTE/DCE + * [ISO 8208:4.2-4.5] */ if (RESTART_DTE_ORIGINATED(xp)) { - pk_restart (pkp, X25_RESTART_DTE_ORIGINATED); - pk_message (0, pkp -> pk_xcp, - "RESTART collision"); - if ((pkp -> pk_restartcolls++) > MAXRESTARTCOLLISIONS) { - pk_message (0, pkp -> pk_xcp, - "excessive RESTART collisions"); - pkp -> pk_restartcolls = 0; + pk_restart(pkp, X25_RESTART_DTE_ORIGINATED); + pk_message(0, pkp->pk_xcp, + "RESTART collision"); + if ((pkp->pk_restartcolls++) > MAXRESTARTCOLLISIONS) { + pk_message(0, pkp->pk_xcp, + "excessive RESTART collisions"); + pkp->pk_restartcolls = 0; } break; } - pkp -> pk_state = DTE_READY; - pkp -> pk_dxerole |= DTE_PLAYDTE; - pkp -> pk_dxerole &= ~DTE_PLAYDCE; - pk_message (0, pkp -> pk_xcp, - "Packet level operational"); - pk_message (0, pkp -> pk_xcp, - "Assuming DTE role"); - if (pkp -> pk_dxerole & DTE_CONNECTPENDING) - pk_callcomplete (pkp); + pkp->pk_state = DTE_READY; + pkp->pk_dxerole |= DTE_PLAYDTE; + pkp->pk_dxerole &= ~DTE_PLAYDCE; + pk_message(0, pkp->pk_xcp, + "Packet level operational"); + pk_message(0, pkp->pk_xcp, + "Assuming DTE role"); + if (pkp->pk_dxerole & DTE_CONNECTPENDING) + pk_callcomplete(pkp); break; - default: - pk_restart (pkp, -1); - pk_restartcause (pkp, xp); - pkp -> pk_chan[0] -> lcd_template = pk_template (0, - X25_RESTART_CONFIRM); - pk_output (pkp -> pk_chan[0]); - pkp -> pk_state = DTE_READY; - pkp -> pk_dxerole |= RESTART_DTE_ORIGINATED(xp) ? DTE_PLAYDCE : + default: + pk_restart(pkp, -1); + pk_restartcause(pkp, xp); + pkp->pk_chan[0]->lcd_template = pk_template(0, + X25_RESTART_CONFIRM); + pk_output(pkp->pk_chan[0]); + pkp->pk_state = DTE_READY; + pkp->pk_dxerole |= RESTART_DTE_ORIGINATED(xp) ? DTE_PLAYDCE : DTE_PLAYDTE; - if (pkp -> pk_dxerole & DTE_PLAYDTE) { - pkp -> pk_dxerole &= ~DTE_PLAYDCE; - pk_message (0, pkp -> pk_xcp, - "Assuming DTE role"); + if (pkp->pk_dxerole & DTE_PLAYDTE) { + pkp->pk_dxerole &= ~DTE_PLAYDCE; + pk_message(0, pkp->pk_xcp, + "Assuming DTE role"); } else { - pkp -> pk_dxerole &= ~DTE_PLAYDTE; - pk_message (0, pkp -> pk_xcp, - "Assuming DCE role"); + pkp->pk_dxerole &= ~DTE_PLAYDTE; + pk_message(0, pkp->pk_xcp, + "Assuming DCE role"); } - if (pkp -> pk_dxerole & DTE_CONNECTPENDING) - pk_callcomplete (pkp); + if (pkp->pk_dxerole & DTE_CONNECTPENDING) + pk_callcomplete(pkp); } break; - /* - * Restart confirmation received. All logical channels are set - * to READY. - */ - case RESTART_CONF + READY: - switch (pkp -> pk_state) { - case DTE_SENT_RESTART: - pkp -> pk_state = DTE_READY; - pkp -> pk_dxerole |= DTE_PLAYDTE; - pkp -> pk_dxerole &= ~DTE_PLAYDCE; - pk_message (0, pkp -> pk_xcp, - "Packet level operational"); - pk_message (0, pkp -> pk_xcp, - "Assuming DTE role"); - if (pkp -> pk_dxerole & DTE_CONNECTPENDING) - pk_callcomplete (pkp); + /* + * Restart confirmation received. All logical channels are + * set to READY. + */ + case PK_RESTART_CONF + READY: + switch (pkp->pk_state) { + case DTE_SENT_RESTART: + pkp->pk_state = DTE_READY; + pkp->pk_dxerole |= DTE_PLAYDTE; + pkp->pk_dxerole &= ~DTE_PLAYDCE; + pk_message(0, pkp->pk_xcp, + "Packet level operational"); + pk_message(0, pkp->pk_xcp, + "Assuming DTE role"); + if (pkp->pk_dxerole & DTE_CONNECTPENDING) + pk_callcomplete(pkp); break; - default: + default: /* Restart local procedure error. */ - pk_restart (pkp, X25_RESTART_LOCAL_PROCEDURE_ERROR); - pkp -> pk_state = DTE_SENT_RESTART; - pkp -> pk_dxerole &= ~(DTE_PLAYDTE | DTE_PLAYDCE); + pk_restart(pkp, X25_RESTART_LOCAL_PROCEDURE_ERROR); + pkp->pk_state = DTE_SENT_RESTART; + pkp->pk_dxerole &= ~(DTE_PLAYDTE | DTE_PLAYDCE); } break; - default: + default: if (lcp) { - pk_procerror (CLEAR, lcp, "unknown packet error", 33); - pk_message (lcn, pkp -> pk_xcp, - "\"%s\" unexpected in \"%s\" state", - pk_name[ptype/MAXSTATES], pk_state[lcdstate]); + pk_procerror(PK_CLEAR, lcp, "unknown packet error", 33); + pk_message(lcn, pkp->pk_xcp, + "\"%s\" unexpected in \"%s\" state", + pk_name[ptype / MAXSTATES], pk_state[lcdstate]); } else - pk_message (lcn, pkp -> pk_xcp, - "packet arrived on unassigned lcn"); + pk_message(lcn, pkp->pk_xcp, + "packet arrived on unassigned lcn"); break; } - if (so == 0 && lcp && lcp -> lcd_upper && lcdstate == DATA_TRANSFER) { - if (ptype != DATA && ptype != INTERRUPT) + if (so == 0 && lcp && lcp->lcd_upper && lcdstate == DATA_TRANSFER) { + if (ptype != PK_DATA && ptype != PK_INTERRUPT) MCHTYPE(m, MT_CONTROL); - lcp -> lcd_upper (lcp, m); - } else if (ptype != DATA && ptype != INTERRUPT) - m_freem (m); + lcp->lcd_upper(m, lcp); + } else if (ptype != PK_DATA && ptype != PK_INTERRUPT) + m_freem(m); } -static -prune_dnic (from, to, dnicname, xcp) -char *from, *to, *dnicname; -register struct x25config *xcp; +static void +prune_dnic(from, to, dnicname, xcp) + char *from, *to, *dnicname; + register struct x25config *xcp; { - register char *cp1 = from, *cp2 = from; - if (xcp -> xc_prepnd0 && *cp1 == '0') { + register char *cp1 = from, *cp2 = from; + if (xcp->xc_prepnd0 && *cp1 == '0') { from = ++cp1; goto copyrest; } - if (xcp -> xc_nodnic) { - for (cp1 = dnicname; *cp2 = *cp1++;) + if (xcp->xc_nodnic) { + for (cp1 = dnicname; (*cp2 = *cp1++) != '\0';) cp2++; cp1 = from; } copyrest: - for (cp1 = dnicname; *cp2 = *cp1++;) + for (cp1 = dnicname; (*cp2 = *cp1++) != '\0';) cp2++; } -/* static */ -pk_simple_bsd (from, to, lower, len) -register octet *from, *to; -register len, lower; + +void +pk_simple_bsd(from, to, lower, len) + register octet *from, *to; + register int len, lower; { - register int c; + register int c; while (--len >= 0) { c = *from; if (lower & 0x01) - *from++; + from++; else c >>= 4; - c &= 0x0f; c |= 0x30; *to++ = c; lower++; + c &= 0x0f; + c |= 0x30; + *to++ = c; + lower++; } *to = 0; } -/*static octet * */ -pk_from_bcd (a, iscalling, sa, xcp) -register struct x25_calladdr *a; -register struct sockaddr_x25 *sa; -register struct x25config *xcp; +void +pk_from_bcd(a, iscalling, sa, xcp) + register struct x25_calladdr *a; + int iscalling; + register struct sockaddr_x25 *sa; + register struct x25config *xcp; { - octet buf[MAXADDRLN+1]; - octet *cp; - unsigned count; + octet buf[MAXADDRLN + 1]; + octet *cp; + unsigned count; - bzero ((caddr_t) sa, sizeof (*sa)); - sa -> x25_len = sizeof (*sa); - sa -> x25_family = AF_CCITT; + bzero((caddr_t) sa, sizeof(*sa)); + sa->x25_len = sizeof(*sa); + sa->x25_family = AF_CCITT; if (iscalling) { - cp = a -> address_field + (X25GBITS(a -> addrlens, called_addrlen) / 2); - count = X25GBITS(a -> addrlens, calling_addrlen); - pk_simple_bsd (cp, buf, X25GBITS(a -> addrlens, called_addrlen), count); + cp = a->address_field + (X25GBITS(a->addrlens, called_addrlen) / 2); + count = X25GBITS(a->addrlens, calling_addrlen); + pk_simple_bsd(cp, buf, X25GBITS(a->addrlens, called_addrlen), count); } else { - count = X25GBITS(a -> addrlens, called_addrlen); - pk_simple_bsd (a -> address_field, buf, 0, count); + count = X25GBITS(a->addrlens, called_addrlen); + pk_simple_bsd(a->address_field, buf, 0, count); } - if (xcp -> xc_addr.x25_net && (xcp -> xc_nodnic || xcp -> xc_prepnd0)) { - octet dnicname[sizeof (long) * NBBY/3 + 2]; + if (xcp->xc_addr.x25_net && (xcp->xc_nodnic || xcp->xc_prepnd0)) { + octet dnicname[sizeof(long) * NBBY / 3 + 2]; - sprintf ((char *) dnicname, "%d", xcp -> xc_addr.x25_net); - prune_dnic ((char *) buf, sa -> x25_addr, dnicname, xcp); + sprintf((char *) dnicname, "%d", xcp->xc_addr.x25_net); + prune_dnic((char *) buf, sa->x25_addr, dnicname, xcp); } else - bcopy ((caddr_t) buf, (caddr_t) sa -> x25_addr, count + 1); + bcopy((caddr_t) buf, (caddr_t) sa->x25_addr, count + 1); } -static -save_extra (m0, fp, so) -struct mbuf *m0; -octet *fp; -struct socket *so; +static void +save_extra(m0, fp, so) + struct mbuf *m0; + octet *fp; + struct socket *so; { register struct mbuf *m; - struct cmsghdr cmsghdr; - if (m = m_copy (m, 0, (int)M_COPYALL)) { - int off = fp - mtod (m0, octet *); - int len = m -> m_pkthdr.len - off + sizeof (cmsghdr); + struct cmsghdr cmsghdr; + /* XXX: christos: + * used to be m_copy(m, 0, ...) + * I think it is supposed to be m_copy(m0, + */ + if ((m = m_copy(m0, 0, (int) M_COPYALL)) != NULL) { + int off = fp - mtod(m0, octet *); + int len = m->m_pkthdr.len - off + sizeof(cmsghdr); cmsghdr.cmsg_len = len; cmsghdr.cmsg_level = AF_CCITT; cmsghdr.cmsg_type = PK_FACILITIES; - m_adj (m, off); - M_PREPEND (m, sizeof (cmsghdr), M_DONTWAIT); + m_adj(m, off); + M_PREPEND(m, sizeof(cmsghdr), M_DONTWAIT); if (m == 0) return; - bcopy ((caddr_t)&cmsghdr, mtod (m, caddr_t), sizeof (cmsghdr)); + bcopy((caddr_t) & cmsghdr, mtod(m, caddr_t), sizeof(cmsghdr)); MCHTYPE(m, MT_CONTROL); - sbappendrecord (&so -> so_rcv, m); + sbappendrecord(&so->so_rcv, m); } } -/* - * This routine handles incoming call packets. It matches the protocol - * field on the Call User Data field (usually the first four bytes) with - * sockets awaiting connections. +/* + * This routine handles incoming call packets. It matches the protocol field + * on the Call User Data field (usually the first four bytes) with sockets + * awaiting connections. */ -pk_incoming_call (pkp, m0) -struct mbuf *m0; -struct pkcb *pkp; +void +pk_incoming_call(pkp, m0) + struct pkcb *pkp; + struct mbuf *m0; { register struct pklcd *lcp = 0, *l; register struct sockaddr_x25 *sa; register struct x25_calladdr *a; register struct socket *so = 0; - struct x25_packet *xp = mtod (m0, struct x25_packet *); - struct mbuf *m; - struct x25config *xcp = pkp -> pk_xcp; - int len = m0 -> m_pkthdr.len; - unsigned udlen; - char *errstr = "server unavailable"; - octet *u, *facp; - int lcn = LCN(xp); - - /* First, copy the data from the incoming call packet to a X25 address - descriptor. It is to be regretted that you have - to parse the facilities into a sockaddr to determine - if reverse charging is being requested */ - if ((m = m_get (M_DONTWAIT, MT_SONAME)) == 0) + struct x25_packet *xp = mtod(m0, struct x25_packet *); + struct mbuf *m; + struct x25config *xcp = pkp->pk_xcp; + int len = m0->m_pkthdr.len; + unsigned udlen; + char *errstr = "server unavailable"; + octet *u, *facp; + int lcn = LCN(xp); + + /* + * First, copy the data from the incoming call packet to a X25 + * address descriptor. It is to be regretted that you have to parse + * the facilities into a sockaddr to determine if reverse charging is + * being requested + */ + if ((m = m_get(M_DONTWAIT, MT_SONAME)) == 0) return; - sa = mtod (m, struct sockaddr_x25 *); - a = (struct x25_calladdr *) &xp -> packet_data; - facp = u = (octet *) (a -> address_field + - ((X25GBITS(a -> addrlens, called_addrlen) + X25GBITS(a -> addrlens, calling_addrlen) + 1) / 2)); + sa = mtod(m, struct sockaddr_x25 *); + a = (struct x25_calladdr *) & xp->packet_data; + facp = u = (octet *) (a->address_field + + ((X25GBITS(a->addrlens, called_addrlen) + X25GBITS(a->addrlens, calling_addrlen) + 1) / 2)); u += *u + 1; - udlen = min (16, ((octet *) xp) + len - u); + udlen = min(16, ((octet *) xp) + len - u); +#if 0 + /* Cannot happen; udlen is unsigned */ if (udlen < 0) udlen = 0; - pk_from_bcd (a, 1, sa, pkp -> pk_xcp); /* get calling address */ - pk_parse_facilities (facp, sa); - bcopy ((caddr_t) u, sa -> x25_udata, udlen); - sa -> x25_udlen = udlen; +#endif + pk_from_bcd(a, 1, sa, pkp->pk_xcp); /* get calling address */ + pk_parse_facilities(facp, sa); + bcopy((caddr_t) u, sa->x25_udata, udlen); + sa->x25_udlen = udlen; /* * Now, loop through the listen sockets looking for a match on the * PID. That is the first few octets of the user data field. * This is the closest thing to a port number for X.25 packets. - * It does provide a way of multiplexing services at the user level. + * It does provide a way of multiplexing services at the user level. */ - for (l = pk_listenhead; l; l = l -> lcd_listen) { - struct sockaddr_x25 *sxp = l -> lcd_ceaddr; + for (l = pk_listenhead; l; l = l->lcd_listen) { + struct sockaddr_x25 *sxp = l->lcd_ceaddr; - if (bcmp (sxp -> x25_udata, u, sxp -> x25_udlen)) + if (bcmp(sxp->x25_udata, u, sxp->x25_udlen)) continue; - if (sxp -> x25_net && - sxp -> x25_net != xcp -> xc_addr.x25_net) + if (sxp->x25_net && + sxp->x25_net != xcp->xc_addr.x25_net) continue; /* * don't accept incoming calls with the D-Bit on * unless the server agrees */ - if (X25GBITS(xp -> bits, d_bit) && !(sxp -> x25_opts.op_flags & X25_DBIT)) { + if (X25GBITS(xp->bits, d_bit) && !(sxp->x25_opts.op_flags & X25_DBIT)) { errstr = "incoming D-Bit mismatch"; break; } @@ -952,16 +988,17 @@ struct pkcb *pkp; * don't accept incoming collect calls unless * the server sets the reverse charging option. */ - if ((sxp -> x25_opts.op_flags & (X25_OLDSOCKADDR|X25_REVERSE_CHARGE)) == 0 && - sa -> x25_opts.op_flags & X25_REVERSE_CHARGE) { + if ((sxp->x25_opts.op_flags & (X25_OLDSOCKADDR | X25_REVERSE_CHARGE)) == 0 && + sa->x25_opts.op_flags & X25_REVERSE_CHARGE) { errstr = "incoming collect call refused"; break; } - 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 (l->lcd_so) { + so = sonewconn(l->lcd_so, SS_ISCONNECTED); + if (so) + lcp = (struct pklcd *) so->so_pcb; + } else + lcp = pk_attach((struct socket *) 0); if (lcp == 0) { /* * Insufficient space or too many unaccepted @@ -970,33 +1007,33 @@ struct pkcb *pkp; errstr = "server malfunction"; break; } - lcp -> lcd_upper = l -> lcd_upper; - lcp -> lcd_upnext = l -> lcd_upnext; - lcp -> lcd_lcn = lcn; - lcp -> lcd_state = RECEIVED_CALL; - sa -> x25_opts.op_flags |= (sxp -> x25_opts.op_flags & - ~X25_REVERSE_CHARGE) | l -> lcd_flags; - pk_assoc (pkp, lcp, sa); - lcp -> lcd_faddr = *sa; - lcp -> lcd_laddr.x25_udlen = sxp -> x25_udlen; - lcp -> lcd_craddr = &lcp -> lcd_faddr; - lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_CALL_ACCEPTED); - if (lcp -> lcd_flags & X25_DBIT) { - if (X25GBITS(xp -> bits, d_bit)) - X25SBITS(mtod (lcp -> lcd_template, - struct x25_packet *) -> bits, d_bit, 1); + lcp->lcd_upper = l->lcd_upper; + lcp->lcd_upnext = l->lcd_upnext; + lcp->lcd_lcn = lcn; + lcp->lcd_state = RECEIVED_CALL; + sa->x25_opts.op_flags |= (sxp->x25_opts.op_flags & + ~X25_REVERSE_CHARGE) | l->lcd_flags; + pk_assoc(pkp, lcp, sa); + lcp->lcd_faddr = *sa; + lcp->lcd_laddr.x25_udlen = sxp->x25_udlen; + lcp->lcd_craddr = &lcp->lcd_faddr; + lcp->lcd_template = pk_template(lcp->lcd_lcn, X25_CALL_ACCEPTED); + if (lcp->lcd_flags & X25_DBIT) { + if (X25GBITS(xp->bits, d_bit)) + X25SBITS(mtod(lcp->lcd_template, + struct x25_packet *)->bits, d_bit, 1); else - lcp -> lcd_flags &= ~X25_DBIT; + lcp->lcd_flags &= ~X25_DBIT; } if (so) { - pk_output (lcp); - soisconnected (so); - if (so -> so_options & SO_OOBINLINE) - save_extra (m0, facp, so); - } else if (lcp -> lcd_upper) { - (*lcp -> lcd_upper) (lcp, m0); + pk_output(lcp); + soisconnected(so); + if (so->so_options & SO_OOBINLINE) + save_extra(m0, facp, so); + } else if (lcp->lcd_upper) { + (*lcp->lcd_upper) (m0, lcp); } - (void) m_free (m); + (void) m_free(m); return; } @@ -1005,59 +1042,61 @@ struct pkcb *pkp; * skeleton LCD in order to be able to properly receive the CLEAR * CONFIRMATION. */ -#ifdef WATERLOO /* be explicit */ - if (l == 0 && bcmp (sa -> x25_udata, "ean", 3) == 0) - pk_message (lcn, pkp -> pk_xcp, "host=%s ean%c: %s", - sa -> x25_addr, sa -> x25_udata[3] & 0xff, errstr); - else if (l == 0 && bcmp (sa -> x25_udata, "\1\0\0\0", 4) == 0) - pk_message (lcn, pkp -> pk_xcp, "host=%s x29d: %s", - sa -> x25_addr, errstr); +#ifdef WATERLOO /* be explicit */ + if (l == 0 && bcmp(sa->x25_udata, "ean", 3) == 0) + pk_message(lcn, pkp->pk_xcp, "host=%s ean%c: %s", + sa->x25_addr, sa->x25_udata[3] & 0xff, errstr); + else if (l == 0 && bcmp(sa->x25_udata, "\1\0\0\0", 4) == 0) + pk_message(lcn, pkp->pk_xcp, "host=%s x29d: %s", + sa->x25_addr, errstr); else #endif - pk_message (lcn, pkp -> pk_xcp, "host=%s pid=%x %x %x %x: %s", - sa -> x25_addr, sa -> x25_udata[0] & 0xff, - sa -> x25_udata[1] & 0xff, sa -> x25_udata[2] & 0xff, - sa -> x25_udata[3] & 0xff, errstr); - if ((lcp = pk_attach ((struct socket *)0)) == 0) { - (void) m_free (m); + pk_message(lcn, pkp->pk_xcp, "host=%s pid=%x %x %x %x: %s", + sa->x25_addr, sa->x25_udata[0] & 0xff, + sa->x25_udata[1] & 0xff, sa->x25_udata[2] & 0xff, + sa->x25_udata[3] & 0xff, errstr); + if ((lcp = pk_attach((struct socket *) 0)) == 0) { + (void) m_free(m); return; } - lcp -> lcd_lcn = lcn; - lcp -> lcd_state = RECEIVED_CALL; - pk_assoc (pkp, lcp, sa); - (void) m_free (m); - pk_clear (lcp, 0, 1); + lcp->lcd_lcn = lcn; + lcp->lcd_state = RECEIVED_CALL; + pk_assoc(pkp, lcp, sa); + (void) m_free(m); + pk_clear(lcp, 0, 1); } -pk_call_accepted (lcp, m) -struct pklcd *lcp; -struct mbuf *m; +void +pk_call_accepted(lcp, m) + struct pklcd *lcp; + struct mbuf *m; { register struct x25_calladdr *ap; register octet *fcp; - struct x25_packet *xp = mtod (m, struct x25_packet *); - int len = m -> m_len; - - lcp -> lcd_state = DATA_TRANSFER; - if (lcp -> lcd_so) - soisconnected (lcp -> lcd_so); - if ((lcp -> lcd_flags & X25_DBIT) && (X25GBITS(xp -> bits, d_bit) == 0)) - lcp -> lcd_flags &= ~X25_DBIT; + struct x25_packet *xp = mtod(m, struct x25_packet *); + int len = m->m_len; + + lcp->lcd_state = DATA_TRANSFER; + if (lcp->lcd_so) + soisconnected(lcp->lcd_so); + if ((lcp->lcd_flags & X25_DBIT) && (X25GBITS(xp->bits, d_bit) == 0)) + lcp->lcd_flags &= ~X25_DBIT; if (len > 3) { - ap = (struct x25_calladdr *) &xp -> packet_data; - fcp = (octet *) ap -> address_field + (X25GBITS(ap -> addrlens, calling_addrlen) + - X25GBITS(ap -> addrlens, called_addrlen) + 1) / 2; + ap = (struct x25_calladdr *) & xp->packet_data; + fcp = (octet *) ap->address_field + (X25GBITS(ap->addrlens, calling_addrlen) + + X25GBITS(ap->addrlens, called_addrlen) + 1) / 2; if (fcp + *fcp <= ((octet *) xp) + len) - pk_parse_facilities (fcp, lcp -> lcd_ceaddr); + pk_parse_facilities(fcp, lcp->lcd_ceaddr); } - pk_assoc (lcp -> lcd_pkp, lcp, lcp -> lcd_ceaddr); - if (lcp -> lcd_so == 0 && lcp -> lcd_upper) - lcp -> lcd_upper (lcp, m); + pk_assoc(lcp->lcd_pkp, lcp, lcp->lcd_ceaddr); + if (lcp->lcd_so == 0 && lcp->lcd_upper) + (*lcp->lcd_upper)(m, lcp); } -pk_parse_facilities (fcp, sa) -register octet *fcp; -register struct sockaddr_x25 *sa; +void +pk_parse_facilities(fcp, sa) + register octet *fcp; + register struct sockaddr_x25 *sa; { register octet *maxfcp; @@ -1071,36 +1110,39 @@ register struct sockaddr_x25 *sa; break; switch (*fcp) { case FACILITIES_WINDOWSIZE: - sa -> x25_opts.op_wsize = fcp[1]; + sa->x25_opts.op_wsize = fcp[1]; fcp += 3; break; case FACILITIES_PACKETSIZE: - sa -> x25_opts.op_psize = fcp[1]; + sa->x25_opts.op_psize = fcp[1]; fcp += 3; break; case FACILITIES_THROUGHPUT: - sa -> x25_opts.op_speed = fcp[1]; + sa->x25_opts.op_speed = fcp[1]; fcp += 2; break; case FACILITIES_REVERSE_CHARGE: if (fcp[1] & 01) - sa -> x25_opts.op_flags |= X25_REVERSE_CHARGE; + sa->x25_opts.op_flags |= X25_REVERSE_CHARGE; /* * Datapac specific: for a X.25(1976) DTE, bit 2 * indicates a "hi priority" (eg. international) call. */ - if (fcp[1] & 02 && sa -> x25_opts.op_psize == 0) - sa -> x25_opts.op_psize = X25_PS128; + if (fcp[1] & 02 && sa->x25_opts.op_psize == 0) + sa->x25_opts.op_psize = X25_PS128; fcp += 2; break; default: -/*printf("unknown facility %x, class=%d\n", *fcp, (*fcp & 0xc0) >> 6);*/ + /* + * printf("unknown facility %x, class=%d\n", *fcp, + * (*fcp & 0xc0) >> 6); + */ switch ((*fcp & 0xc0) >> 6) { - case 0: /* class A */ + case 0:/* class A */ fcp += 2; break; diff --git a/sys/netccitt/pk_llcsubr.c b/sys/netccitt/pk_llcsubr.c index 552552bdbe2..3725de98737 100644 --- a/sys/netccitt/pk_llcsubr.c +++ b/sys/netccitt/pk_llcsubr.c @@ -1,4 +1,5 @@ -/* $NetBSD: pk_llcsubr.c,v 1.3 1995/03/08 02:14:01 cgd Exp $ */ +/* $OpenBSD: pk_llcsubr.c,v 1.2 1996/03/04 07:36:42 niklas Exp $ */ +/* $NetBSD: pk_llcsubr.c,v 1.4 1996/02/13 22:05:26 christos Exp $ */ /* * Copyright (C) Dirk Husemann, Computer Science Department IV, @@ -62,6 +63,7 @@ #include #include #include +#include #include @@ -85,7 +87,7 @@ * * HDLC uses the DTE-DCE model of X.25, therefore we need a many-to-one * relationship, i.e.: - * + * * {X.121_a, X.121_b, X.121_c, ..., X.121_i} -> pkcb_0 * * LLC2 utilizes the DTE-DTE model of X.25, resulting effectively in a @@ -95,18 +97,18 @@ * {X.121_k} -> pkcb_1b * ... * {X.121_q} -> pkcb_1q - * + * * It might make sense to allow a many-to-one relation for LLC2 also, - * + * * {X.121_r, X.121_s, X.121_t, X.121_u} -> pkcb_2a * * This would make addresses X.121_[r-u] essentially aliases of one * address ({X.121_[r-u]} would constitute a representative set). * * Each one-to-one relation must obviously be entered individually with - * a route add command, whereas a many-to-one relationship can be + * a route add command, whereas a many-to-one relationship can be * either entered individually or generated by using a netmask. - * + * * To facilitate dealings the many-to-one case for LLC2 can only be * established via a netmask. * @@ -125,73 +127,74 @@ #define SA(s) ((struct sockaddr *)s) int -cons_rtrequest(int cmd, struct rtentry *rt, struct sockaddr *dst) +cons_rtrequest(cmd, rt, dst) + int cmd; + struct rtentry *rt; + struct sockaddr *dst; { register struct pkcb *pkp; - register int i; - register char one_to_one; - struct pkcb *pk_newlink(); - struct rtentry *npaidb_enter(); + register char one_to_one; pkp = XTRACTPKP(rt); - switch(cmd) { + switch (cmd) { case RTM_RESOLVE: case RTM_ADD: - if (pkp) - return(EEXIST); + if (pkp) + return (EEXIST); if (rt->rt_flags & RTF_GATEWAY) { if (rt->rt_llinfo) - RTFREE((struct rtentry *)rt->rt_llinfo); + RTFREE((struct rtentry *) rt->rt_llinfo); rt->rt_llinfo = (caddr_t) rtalloc1(rt->rt_gateway, 1); - return(0); + return (0); } /* * Assumptions: (1) ifnet structure is filled in - * (2) at least the pkcb created via - * x25config (ifconfig?) has been + * (2) at least the pkcb created via + * x25config (ifconfig?) has been * set up already. - * (3) HDLC interfaces have an if_type of - * IFT_X25{,DDN}, LLC2 interfaces - * anything else (any better way to + * (3) HDLC interfaces have an if_type of + * IFT_X25{,DDN}, LLC2 interfaces + * anything else (any better way to * do this?) * */ if (!rt->rt_ifa) return (ENETDOWN); - - /* - * We differentiate between dealing with a many-to-one - * (HDLC: DTE-DCE) and a one-to-one (LLC2: DTE-DTE) - * relationship (by looking at the if type). - * - * Only in case of the many-to-one relationship (HDLC) - * we set the ia->ia_pkcb pointer to the pkcb allocated - * via pk_newlink() as we will use just that one pkcb for - * future route additions (the rtentry->rt_llinfo pointer - * points to the pkcb allocated for that route). - * - * In case of the one-to-one relationship (LLC2) we - * create a new pkcb (via pk_newlink()) for each new rtentry. + + /* + * We differentiate between dealing with a many-to-one (HDLC: + * DTE-DCE) and a one-to-one (LLC2: DTE-DTE) relationship (by + * looking at the if type). * - * NOTE: Only in case of HDLC does ia->ia_pkcb point - * to a pkcb, in the LLC2 case it doesn't (as we don't - * need it here)! + * Only in case of the many-to-one relationship (HDLC) we set + * the ia->ia_pkcb pointer to the pkcb allocated via + * pk_newlink() as we will use just that one pkcb for future + * route additions (the rtentry->rt_llinfo pointer points to + * the pkcb allocated for that route). + * + * In case of the one-to-one relationship (LLC2) we create a new + * pkcb (via pk_newlink()) for each new rtentry. + * + * NOTE: Only in case of HDLC does ia->ia_pkcb point to a pkcb, + * in the LLC2 case it doesn't (as we don't need it here)! */ one_to_one = ISISO8802(rt->rt_ifp); - if (!(pkp = XIFA(rt)->ia_pkcb) && !one_to_one) - XIFA(rt)->ia_pkcb = pkp = + if (!(pkp = XIFA(rt)->ia_pkcb) && !one_to_one) + XIFA(rt)->ia_pkcb = pkp = pk_newlink(XIFA(rt), (caddr_t) 0); - else if (one_to_one && + else if (one_to_one && !equal(rt->rt_gateway, rt->rt_ifa->ifa_addr)) { pkp = pk_newlink(XIFA(rt), (caddr_t) 0); /* * We also need another route entry for mapping * MAC+LSAP->X.25 address */ - pkp->pk_llrt = npaidb_enter(rt->rt_gateway, rt_key(rt), rt, 0); + pkp->pk_llrt = npaidb_enter((struct sockaddr_dl *) + rt->rt_gateway, rt_key(rt), + rt, 0); } if (pkp) { if (!pkp->pk_rt) @@ -200,151 +203,160 @@ cons_rtrequest(int cmd, struct rtentry *rt, struct sockaddr *dst) } rt->rt_llinfo = (caddr_t) pkp; - return(0); + return (0); case RTM_DELETE: - { - /* - * The pkp might be empty if we are dealing - * with an interface route entry for LLC2, in this - * case we don't need to do anything ... - */ - if (pkp) { - if ( rt->rt_flags & RTF_GATEWAY ) { - if (rt->rt_llinfo) - RTFREE((struct rtentry *)rt->rt_llinfo); - return(0); + { + /* + * The pkp might be empty if we are dealing + * with an interface route entry for LLC2, in this + * case we don't need to do anything ... + */ + if (pkp) { + if (rt->rt_flags & RTF_GATEWAY) { + if (rt->rt_llinfo) + RTFREE((struct rtentry *) rt->rt_llinfo); + return (0); + } + if (pkp->pk_llrt) + npaidb_destroy(pkp->pk_llrt); + + pk_dellink(pkp); + + return (0); } - - if (pkp->pk_llrt) - npaidb_destroy(pkp->pk_llrt); - - pk_dellink (pkp); - - return(0); } } - } + return 0; } /* - * Network Protocol Addressing Information DataBase (npaidb) - * - * To speed up locating the entity dealing with an LLC packet use is made - * of a routing tree. This npaidb routing tree is handled - * by the normal rn_*() routines just like (almost) any other routing tree. - * - * The mapping being done by the npaidb_*() routines is as follows: - * - * Key: MAC,LSAP (enhancing struct sockaddr_dl) - * Gateway: sockaddr_x25 (i.e. X.25 address - X.121 or NSAP) - * Llinfo: npaidbentry { - * struct llc_linkcb *npaidb_linkp; - * struct rtentry *npaidb_rt; - * } - * - * Using the npaidbentry provided by llinfo we can then access - * + * Network Protocol Addressing Information DataBase (npaidb) + * + * To speed up locating the entity dealing with an LLC packet use is made + * of a routing tree. This npaidb routing tree is handled + * by the normal rn_*() routines just like (almost) any other routing tree. + * + * The mapping being done by the npaidb_*() routines is as follows: + * + * Key: MAC,LSAP (enhancing struct sockaddr_dl) + * Gateway: sockaddr_x25 (i.e. X.25 address - X.121 or NSAP) + * Llinfo: npaidbentry { + * struct llc_linkcb *npaidb_linkp; + * struct rtentry *npaidb_rt; + * } + * + * Using the npaidbentry provided by llinfo we can then access + * * o the pkcb by using (struct pkcb *) (npaidb_rt->rt_llinfo) - * o the linkcb via npaidb_linkp - * - * The following functions are provided - * - * o npaidb_enter(struct sockaddr_dl *sdl, struct sockaddr_x25 *sx25, - * struct struct llc_linkcb *link, struct rtentry *rt) - * - * o npaidb_enrich(short type, caddr_t info) - * + * o the linkcb via npaidb_linkp + * + * The following functions are provided + * + * o npaidb_enter(struct sockaddr_dl *sdl, struct sockaddr_x25 *sx25, + * struct struct llc_linkcb *link, struct rtentry *rt) + * + * o npaidb_enrich(short type, caddr_t info) + * */ struct sockaddr_dl npdl_netmask = { - sizeof(struct sockaddr_dl), /* _len */ - 0, /* _family */ - 0, /* _index */ - 0, /* _type */ - -1, /* _nlen */ - -1, /* _alen */ - -1, /* _slen */ - { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* _data */ -}; + sizeof(struct sockaddr_dl), /* _len */ + 0, /* _family */ + 0, /* _index */ + 0, /* _type */ + -1, /* _nlen */ + -1, /* _alen */ + -1, /* _slen */ + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* _data */ +}; struct sockaddr npdl_dummy; -int npdl_datasize = sizeof(struct sockaddr_dl)- - ((int)((caddr_t)&((struct sockaddr_dl *)0)->sdl_data[0])); +int npdl_datasize = sizeof(struct sockaddr_dl) - +((int) ((caddr_t) & ((struct sockaddr_dl *) 0)->sdl_data[0])); struct rtentry * -npaidb_enter(struct sockaddr_dl *key, struct sockaddr *value, - struct rtentry *rt, struct llc_linkcb *link) +npaidb_enter(key, value, rt, link) + struct sockaddr_dl *key; + struct sockaddr *value; + struct rtentry *rt; + struct llc_linkcb *link; { - struct rtentry *nprt; register int i; + struct rtentry *nprt; + register int i; USES_AF_LINK_RTS; if ((nprt = rtalloc1(SA(key), 0)) == 0) { - register u_int size = sizeof(struct npaidbentry); + register u_int size = sizeof(struct npaidbentry); register u_char saploc = LLSAPLOC(key, rt->rt_ifp); - /* + /* * set up netmask: LLC2 packets have the lowest bit set in * response packets (e.g. 0x7e for command packets, 0x7f for - * response packets), to facilitate the lookup we use a netmask - * of 11111110 for the SAP position. The remaining positions - * are zeroed out. + * response packets), to facilitate the lookup we use a + * netmask of 11111110 for the SAP position. The remaining + * positions are zeroed out. */ npdl_netmask.sdl_data[saploc] = NPDL_SAPNETMASK; - bzero((caddr_t)&npdl_netmask.sdl_data[saploc+1], - npdl_datasize-saploc-1); + bzero((caddr_t) & npdl_netmask.sdl_data[saploc + 1], + npdl_datasize - saploc - 1); if (value == 0) value = &npdl_dummy; /* now enter it */ rtrequest(RTM_ADD, SA(key), SA(value), - SA(&npdl_netmask), 0, &nprt); + SA(&npdl_netmask), 0, &nprt); /* and reset npdl_netmask */ for (i = saploc; i < npdl_datasize; i++) npdl_netmask.sdl_data[i] = -1; - nprt->rt_llinfo = malloc(size , M_PCB, M_WAITOK); + nprt->rt_llinfo = malloc(size, M_PCB, M_WAITOK); if (nprt->rt_llinfo) { - bzero (nprt->rt_llinfo, size); + bzero(nprt->rt_llinfo, size); ((struct npaidbentry *) (nprt->rt_llinfo))->np_rt = rt; } - } else nprt->rt_refcnt--; + } else + nprt->rt_refcnt--; return nprt; } struct rtentry * -npaidb_enrich(short type, caddr_t info, struct sockaddr_dl *sdl) +npaidb_enrich(type, info, sdl) + short type; + caddr_t info; + struct sockaddr_dl *sdl; { struct rtentry *rt; USES_AF_LINK_RTS; - if (rt = rtalloc1((struct sockaddr *)sdl, 0)) { + if ((rt = rtalloc1((struct sockaddr *) sdl, 0)) != NULL) { rt->rt_refcnt--; switch (type) { case NPAIDB_LINK: - ((struct npaidbentry *)(rt->rt_llinfo))->np_link = + ((struct npaidbentry *) (rt->rt_llinfo))->np_link = (struct llc_linkcb *) info; break; } return rt; - } - + } return ((struct rtentry *) 0); } -npaidb_destroy(struct rtentry *rt) +int +npaidb_destroy(rt) + struct rtentry *rt; { USES_AF_LINK_RTS; - if (rt->rt_llinfo) + if (rt->rt_llinfo) free((caddr_t) rt->rt_llinfo, M_PCB); - return(rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, rt_mask(rt), - 0, 0)); + return (rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, rt_mask(rt), + 0, 0)); } @@ -353,19 +365,20 @@ npaidb_destroy(struct rtentry *rt) * Glue between X.25 and LLC2 */ long -x25_llcglue(int prc, struct sockaddr *addr) +x25_llcglue(prc, addr) + int prc; + struct sockaddr *addr; { - register struct sockaddr_x25 *sx25 = (struct sockaddr_x25 *)addr; register struct x25_ifaddr *x25ifa; struct dll_ctlinfo ctlinfo; - - if((x25ifa = (struct x25_ifaddr *)ifa_ifwithaddr(addr)) == 0) + + if ((x25ifa = (struct x25_ifaddr *) ifa_ifwithaddr(addr)) == 0) return 0; - ctlinfo.dlcti_cfg = - (struct dllconfig *)(((struct sockaddr_x25 *)(&x25ifa->ia_xc))+1); + ctlinfo.dlcti_cfg = + (struct dllconfig *) (((struct sockaddr_x25 *) (&x25ifa->ia_xc)) + 1); ctlinfo.dlcti_lsap = LLC_X25_LSAP; - return ((long)llc_ctlinput(prc, addr, (caddr_t)&ctlinfo)); + return ((long) llc_ctlinput(prc, addr, &ctlinfo)); } -#endif /* LLC */ +#endif /* LLC */ diff --git a/sys/netccitt/pk_output.c b/sys/netccitt/pk_output.c index 9bc91325fec..36c58f39643 100644 --- a/sys/netccitt/pk_output.c +++ b/sys/netccitt/pk_output.c @@ -1,16 +1,17 @@ -/* $NetBSD: pk_output.c,v 1.6 1994/09/20 06:41:04 cgd Exp $ */ +/* $OpenBSD: pk_output.c,v 1.2 1996/03/04 07:36:43 niklas Exp $ */ +/* $NetBSD: pk_output.c,v 1.7 1996/02/13 22:05:30 christos Exp $ */ /* - * Copyright (c) University of British Columbia, 1984 - * Copyright (C) Computer Science Department IV, + * Copyright(c) University of British Columbia, 1984 + * Copyright(C) Computer Science Department IV, * University of Erlangen-Nuremberg, Germany, 1992 - * Copyright (c) 1991, 1992, 1993 + * Copyright(c) 1991, 1992, 1993 * 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 the University of British Columbia and the Computer Science - * Department (IV) of the University of Erlangen-Nuremberg, Germany. + * Department(IV) of the University of Erlangen-Nuremberg, Germany. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,14 +34,14 @@ * 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 + * 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 + * 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. * - * @(#)pk_output.c 8.1 (Berkeley) 6/10/93 + * @(#)pk_output.c 8.1(Berkeley) 6/10/93 */ #include @@ -56,163 +57,164 @@ #include #include #include +#include -struct mbuf_cache pk_output_cache = {0 }, pk_input_cache; -struct mbuf *nextpk (); +struct mbuf_cache pk_output_cache = {0}, pk_input_cache; -pk_output (lcp) -register struct pklcd *lcp; +void +pk_output(lcp) + register struct pklcd *lcp; { register struct x25_packet *xp; register struct mbuf *m; - register struct pkcb *pkp = lcp -> lcd_pkp; + register struct pkcb *pkp = lcp->lcd_pkp; if (lcp == 0 || pkp == 0) { - printf ("pk_output: zero arg\n"); + printf("pk_output: zero arg\n"); return; } - - while ((m = nextpk (lcp)) != NULL) { - xp = mtod (m, struct x25_packet *); - - switch (pk_decode (xp) + lcp -> lcd_state) { - /* - * All the work is already done - just set the state and - * pass to peer. - */ - case CALL + READY: - lcp -> lcd_state = SENT_CALL; - lcp -> lcd_timer = pk_t21; + while ((m = nextpk(lcp)) != NULL) { + xp = mtod(m, struct x25_packet *); + + switch (pk_decode(xp) + lcp->lcd_state) { + /* + * All the work is already done - just set the state + * and pass to peer. + */ + case PK_CALL + READY: + lcp->lcd_state = SENT_CALL; + lcp->lcd_timer = pk_t21; break; - /* - * Just set the state to allow packet to flow and send the - * confirmation. - */ - case CALL_ACCEPTED + RECEIVED_CALL: - lcp -> lcd_state = DATA_TRANSFER; + /* + * Just set the state to allow packet to flow and send the + * confirmation. + */ + case PK_CALL_ACCEPTED + RECEIVED_CALL: + lcp->lcd_state = DATA_TRANSFER; break; - /* - * Just set the state. Keep the LCD around till the clear - * confirmation is returned. - */ - case CLEAR + RECEIVED_CALL: - case CLEAR + SENT_CALL: - case CLEAR + DATA_TRANSFER: - lcp -> lcd_state = SENT_CLEAR; - lcp -> lcd_retry = 0; + /* + * Just set the state. Keep the LCD around till the + * clear confirmation is returned. + */ + case PK_CLEAR + RECEIVED_CALL: + case PK_CLEAR + SENT_CALL: + case PK_CLEAR + DATA_TRANSFER: + lcp->lcd_state = SENT_CLEAR; + lcp->lcd_retry = 0; /* fall through */ - case CLEAR + SENT_CLEAR: - lcp -> lcd_timer = pk_t23; - lcp -> lcd_retry++; + case PK_CLEAR + SENT_CLEAR: + lcp->lcd_timer = pk_t23; + lcp->lcd_retry++; break; - case CLEAR_CONF + RECEIVED_CLEAR: - case CLEAR_CONF + SENT_CLEAR: - case CLEAR_CONF + READY: - lcp -> lcd_state = READY; + case PK_CLEAR_CONF + RECEIVED_CLEAR: + case PK_CLEAR_CONF + SENT_CLEAR: + case PK_CLEAR_CONF + READY: + lcp->lcd_state = READY; break; - case DATA + DATA_TRANSFER: - SPS(xp, lcp -> lcd_ssn); - lcp -> lcd_input_window = - (lcp -> lcd_rsn + 1) % MODULUS; - SPR(xp, lcp -> lcd_input_window); - lcp -> lcd_last_transmitted_pr = lcp -> lcd_input_window; - lcp -> lcd_ssn = (lcp -> lcd_ssn + 1) % MODULUS; - if (lcp -> lcd_ssn == ((lcp -> lcd_output_window + lcp -> lcd_windowsize) % MODULUS)) - lcp -> lcd_window_condition = TRUE; + case PK_DATA + DATA_TRANSFER: + SPS(xp, lcp->lcd_ssn); + lcp->lcd_input_window = + (lcp->lcd_rsn + 1) % MODULUS; + SPR(xp, lcp->lcd_input_window); + lcp->lcd_last_transmitted_pr = lcp->lcd_input_window; + lcp->lcd_ssn = (lcp->lcd_ssn + 1) % MODULUS; + if (lcp->lcd_ssn == ((lcp->lcd_output_window + lcp->lcd_windowsize) % MODULUS)) + lcp->lcd_window_condition = TRUE; break; - case INTERRUPT + DATA_TRANSFER: + case PK_INTERRUPT + DATA_TRANSFER: #ifdef ancient_history - xp -> packet_data = 0; + xp->packet_data = 0; #endif - lcp -> lcd_intrconf_pending = TRUE; + lcp->lcd_intrconf_pending = TRUE; break; - case INTERRUPT_CONF + DATA_TRANSFER: + case PK_INTERRUPT_CONF + DATA_TRANSFER: break; - case RR + DATA_TRANSFER: - case RNR + DATA_TRANSFER: - lcp -> lcd_input_window = - (lcp -> lcd_rsn + 1) % MODULUS; - SPR(xp, lcp -> lcd_input_window); - lcp -> lcd_last_transmitted_pr = lcp -> lcd_input_window; + case PK_RR + DATA_TRANSFER: + case PK_RNR + DATA_TRANSFER: + lcp->lcd_input_window = + (lcp->lcd_rsn + 1) % MODULUS; + SPR(xp, lcp->lcd_input_window); + lcp->lcd_last_transmitted_pr = lcp->lcd_input_window; break; - case RESET + DATA_TRANSFER: - lcp -> lcd_reset_condition = TRUE; + case PK_RESET + DATA_TRANSFER: + lcp->lcd_reset_condition = TRUE; break; - case RESET_CONF + DATA_TRANSFER: - lcp -> lcd_reset_condition = FALSE; + case PK_RESET_CONF + DATA_TRANSFER: + lcp->lcd_reset_condition = FALSE; break; - /* - * A restart should be only generated internally. Therefore - * all logic for restart is in the pk_restart routine. - */ - case RESTART + READY: - lcp -> lcd_timer = pk_t20; + /* + * A restart should be only generated internally. + * Therefore all logic for restart is in the + * pk_restart routine. + */ + case PK_RESTART + READY: + lcp->lcd_timer = pk_t20; break; - /* - * Restarts are all handled internally. Therefore all the - * logic for the incoming restart packet is handled in the - * pk_input routine. - */ - case RESTART_CONF + READY: + /* + * Restarts are all handled internally. Therefore + * all the logic for the incoming restart packet is + * handled in the pk_input routine. + */ + case PK_RESTART_CONF + READY: break; - default: - m_freem (m); + default: + m_freem(m); return; } /* Trace the packet. */ - pk_trace (pkp -> pk_xcp, m, "P-Out"); + pk_trace(pkp->pk_xcp, m, "P-Out"); /* Pass the packet on down to the link layer */ if (pk_input_cache.mbc_size || pk_input_cache.mbc_oldsize) { m->m_flags |= 0x08; mbuf_cache(&pk_input_cache, m); } - (*pkp -> pk_lloutput) (pkp -> pk_llnext, m, pkp -> pk_rt); + (*pkp->pk_lloutput) (m, pkp->pk_llnext, pkp->pk_rt); } } -/* - * This procedure returns the next packet to send or null. A - * packet is composed of one or more mbufs. +/* + * This procedure returns the next packet to send or null. A packet is + * composed of one or more mbufs. */ struct mbuf * -nextpk (lcp) -struct pklcd *lcp; +nextpk(lcp) + struct pklcd *lcp; { register struct mbuf *m, *n; - struct socket *so = lcp -> lcd_so; + struct socket *so = lcp->lcd_so; register struct sockbuf *sb = (so ? &so->so_snd : &lcp->lcd_sb); - if (lcp -> lcd_template) { - m = lcp -> lcd_template; - lcp -> lcd_template = NULL; + if (lcp->lcd_template) { + m = lcp->lcd_template; + lcp->lcd_template = NULL; } else { - if (lcp -> lcd_rnr_condition || lcp -> lcd_window_condition || - lcp -> lcd_reset_condition) + if (lcp->lcd_rnr_condition || lcp->lcd_window_condition || + lcp->lcd_reset_condition) return (NULL); - if ((m = sb -> sb_mb) == 0) + if ((m = sb->sb_mb) == 0) return (NULL); - sb -> sb_mb = m -> m_nextpkt; - m->m_act = 0; - for (n = m; n; n = n -> m_next) - sbfree (sb, n); + sb->sb_mb = m->m_nextpkt; + m->m_act = 0; + for (n = m; n; n = n->m_next) + sbfree(sb, n); } return (m); } diff --git a/sys/netccitt/pk_subr.c b/sys/netccitt/pk_subr.c index 99a93b05ac2..043bcb35e2e 100644 --- a/sys/netccitt/pk_subr.c +++ b/sys/netccitt/pk_subr.c @@ -1,8 +1,9 @@ -/* $NetBSD: pk_subr.c,v 1.10 1995/08/17 02:57:25 mycroft Exp $ */ +/* $OpenBSD: pk_subr.c,v 1.2 1996/03/04 07:36:44 niklas Exp $ */ +/* $NetBSD: pk_subr.c,v 1.11 1996/02/13 22:05:34 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 - * Copyright (C) Computer Science Department IV, + * Copyright (C) Computer Science Department IV, * University of Erlangen-Nuremberg, Germany, 1992 * Copyright (c) 1991, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -61,114 +62,118 @@ #include #include #include +#include -int pk_sendspace = 1024 * 2 + 8; -int pk_recvspace = 1024 * 2 + 8; +#include -struct pklcd_q pklcd_q = {&pklcd_q, &pklcd_q}; +int pk_sendspace = 1024 * 2 + 8; +int pk_recvspace = 1024 * 2 + 8; + +struct pklcd_q pklcd_q = {&pklcd_q, &pklcd_q}; struct x25bitslice x25_bitslice[] = { -/* mask, shift value */ - { 0xf0, 0x4 }, - { 0xf, 0x0 }, - { 0x80, 0x7 }, - { 0x40, 0x6 }, - { 0x30, 0x4 }, - { 0xe0, 0x5 }, - { 0x10, 0x4 }, - { 0xe, 0x1 }, - { 0x1, 0x0 } + /* mask, shift value */ + {0xf0, 0x4}, + {0xf, 0x0}, + {0x80, 0x7}, + {0x40, 0x6}, + {0x30, 0x4}, + {0xe0, 0x5}, + {0x10, 0x4}, + {0xe, 0x1}, + {0x1, 0x0} }; -/* - * Attach X.25 protocol to socket, allocate logical channel descripter - * and buffer space, and enter LISTEN state if we are to accept - * IN-COMMING CALL packets. - * +static struct x25_ifaddr *pk_ifwithaddr __P((struct sockaddr_x25 *)); +static void pk_reset __P((struct pklcd *, int)); + +/* + * Attach X.25 protocol to socket, allocate logical channel descripter and + * buffer space, and enter LISTEN state if we are to accept IN-COMMING CALL + * packets. + * */ struct pklcd * -pk_attach (so) -struct socket *so; +pk_attach(so) + struct socket *so; { register struct pklcd *lcp; - register int error = ENOBUFS; - int pk_output (); + register int error = ENOBUFS; - MALLOC(lcp, struct pklcd *, sizeof (*lcp), M_PCB, M_NOWAIT); + MALLOC(lcp, struct pklcd *, sizeof(*lcp), M_PCB, M_NOWAIT); if (lcp) { - bzero ((caddr_t)lcp, sizeof (*lcp)); - insque (&lcp -> lcd_q, &pklcd_q); - lcp -> lcd_state = READY; - lcp -> lcd_send = pk_output; + bzero((caddr_t) lcp, sizeof(*lcp)); + insque(&lcp->lcd_q, &pklcd_q); + lcp->lcd_state = READY; + lcp->lcd_send = pk_output; if (so) { - error = soreserve (so, pk_sendspace, pk_recvspace); - lcp -> lcd_so = so; - if (so -> so_options & SO_ACCEPTCONN) - lcp -> lcd_state = LISTEN; + error = soreserve(so, pk_sendspace, pk_recvspace); + lcp->lcd_so = so; + if (so->so_options & SO_ACCEPTCONN) + lcp->lcd_state = LISTEN; } else - sbreserve (&lcp -> lcd_sb, pk_sendspace); + sbreserve(&lcp->lcd_sb, pk_sendspace); } if (so) { - so -> so_pcb = lcp; - so -> so_error = error; + so->so_pcb = lcp; + so->so_error = error; } return (lcp); } -/* - * Disconnect X.25 protocol from socket. +/* + * Disconnect X.25 protocol from socket. */ - -pk_disconnect (lcp) -register struct pklcd *lcp; +void +pk_disconnect(lcp) + register struct pklcd *lcp; { - register struct socket *so = lcp -> lcd_so; + register struct socket *so = lcp->lcd_so; register struct pklcd *l, *p; - switch (lcp -> lcd_state) { - case LISTEN: - for (p = 0, l = pk_listenhead; l && l != lcp; p = l, l = l -> lcd_listen); + switch (lcp->lcd_state) { + case LISTEN: + for (p = 0, l = pk_listenhead; l && l != lcp; p = l, l = l->lcd_listen); if (p == 0) { if (l != 0) - pk_listenhead = l -> lcd_listen; - } - else - if (l != 0) - p -> lcd_listen = l -> lcd_listen; - pk_close (lcp); + pk_listenhead = l->lcd_listen; + } else if (l != 0) + p->lcd_listen = l->lcd_listen; + pk_close(lcp); break; - case READY: - pk_acct (lcp); - pk_close (lcp); + case READY: + pk_acct(lcp); + pk_close(lcp); break; - case SENT_CLEAR: - case RECEIVED_CLEAR: + case SENT_CLEAR: + case RECEIVED_CLEAR: break; - default: - pk_acct (lcp); + default: + pk_acct(lcp); if (so) { - soisdisconnecting (so); - sbflush (&so -> so_rcv); + soisdisconnecting(so); + sbflush(&so->so_rcv); } - pk_clear (lcp, 241, 0); /* Normal Disconnect */ + pk_clear(lcp, 241, 0); /* Normal Disconnect */ } } -/* - * Close an X.25 Logical Channel. Discard all space held by the - * connection and internal descriptors. Wake up any sleepers. +/* + * Close an X.25 Logical Channel. Discard all space held by the connection + * and internal descriptors. Wake up any sleepers. */ -pk_close (lcp) -struct pklcd *lcp; +void +pk_close(lcp) + struct pklcd *lcp; { - register struct socket *so = lcp -> lcd_so; + register struct socket *so = lcp->lcd_so; /* * If the X.25 connection is torn down due to link @@ -177,79 +182,81 @@ struct pklcd *lcp; * send buffer is locked. An attempt to sbflush () that send * buffer will lead us into - no, not temptation but - panic! * So - we'll just check wether the send buffer is locked - * and if that's the case we'll mark the lcp as zombie and + * and if that's the case we'll mark the lcp as zombie and * have the pk_timer () do the cleaning ... */ - - if (so && so -> so_snd.sb_flags & SB_LOCK) - lcp -> lcd_state = LCN_ZOMBIE; + + if (so && so->so_snd.sb_flags & SB_LOCK) + lcp->lcd_state = LCN_ZOMBIE; else - pk_freelcd (lcp); + pk_freelcd(lcp); if (so == NULL) return; - so -> so_pcb = 0; - soisdisconnected (so); - /* sofree (so); /* gak!!! you can't do that here */ + so->so_pcb = 0; + soisdisconnected(so); +#if 0 + sofree (so); /* gak!!! you can't do that here */ +#endif } -/* - * Create a template to be used to send X.25 packets on a logical - * channel. It allocates an mbuf and fills in a skeletal packet - * depending on its type. This packet is passed to pk_output where - * the remainer of the packet is filled in. -*/ +/* + * Create a template to be used to send X.25 packets on a logical channel. It + * allocates an mbuf and fills in a skeletal packet depending on its type. + * This packet is passed to pk_output where the remainer of the packet is + * filled in. + */ struct mbuf * -pk_template (lcn, type) -int lcn, type; +pk_template(lcn, type) + int lcn, type; { register struct mbuf *m; register struct x25_packet *xp; - MGETHDR (m, M_DONTWAIT, MT_HEADER); + MGETHDR(m, M_DONTWAIT, MT_HEADER); if (m == 0) - panic ("pk_template"); - m -> m_act = 0; + panic("pk_template"); + m->m_act = 0; /* * Efficiency hack: leave a four byte gap at the beginning * of the packet level header with the hope that this will * be enough room for the link level to insert its header. */ - m -> m_data += max_linkhdr; - m -> m_pkthdr.len = m -> m_len = PKHEADERLN; + m->m_data += max_linkhdr; + m->m_pkthdr.len = m->m_len = PKHEADERLN; - xp = mtod (m, struct x25_packet *); - *(long *)xp = 0; /* ugly, but fast */ -/* xp -> q_bit = 0;*/ - X25SBITS(xp -> bits, fmt_identifier, 1); -/* xp -> lc_group_number = 0;*/ + xp = mtod(m, struct x25_packet *); + *(long *) xp = 0; /* ugly, but fast */ + /* xp->q_bit = 0; */ + X25SBITS(xp->bits, fmt_identifier, 1); + /* xp->lc_group_number = 0; */ SET_LCN(xp, lcn); - xp -> packet_type = type; + xp->packet_type = type; return (m); } -/* - * This routine restarts all the virtual circuits. Actually, - * the virtual circuits are not "restarted" as such. Instead, - * any active switched circuit is simply returned to READY - * state. +/* + * This routine restarts all the virtual circuits. Actually, the virtual + * circuits are not "restarted" as such. Instead, any active switched circuit + * is simply returned to READY state. */ -pk_restart (pkp, restart_cause) -register struct pkcb *pkp; -int restart_cause; +void +pk_restart(pkp, restart_cause) + register struct pkcb *pkp; + int restart_cause; { register struct mbuf *m; register struct pklcd *lcp; - register int i; + register int i; /* Restart all logical channels. */ - if (pkp -> pk_chan == 0) + if (pkp->pk_chan == 0) return; /* @@ -258,185 +265,189 @@ int restart_cause; * only if the X.25 link is down, i.e. a RESTART needs * to be done to get it up. */ - if (!(pkp -> pk_dxerole & DTE_CONNECTPENDING)) { - for (i = 1; i <= pkp -> pk_maxlcn; ++i) - if ((lcp = pkp -> pk_chan[i]) != NULL) { - if (lcp -> lcd_so) { - lcp -> lcd_so -> so_error = ENETRESET; - pk_close (lcp); + if (!(pkp->pk_dxerole & DTE_CONNECTPENDING)) { + for (i = 1; i <= pkp->pk_maxlcn; ++i) + if ((lcp = pkp->pk_chan[i]) != NULL) { + if (lcp->lcd_so) { + lcp->lcd_so->so_error = ENETRESET; + pk_close(lcp); } else { - pk_flush (lcp); - lcp -> lcd_state = READY; - if (lcp -> lcd_upper) - lcp -> lcd_upper (lcp, 0); + pk_flush(lcp); + lcp->lcd_state = READY; + if (lcp->lcd_upper) + (*lcp->lcd_upper)(NULL, lcp); } } } - if (restart_cause < 0) return; - pkp -> pk_state = DTE_SENT_RESTART; - pkp -> pk_dxerole &= ~(DTE_PLAYDCE | DTE_PLAYDTE); - lcp = pkp -> pk_chan[0]; - m = lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_RESTART); - m -> m_pkthdr.len = m -> m_len += 2; - mtod (m, struct x25_packet *) -> packet_data = 0; /* DTE only */ - mtod (m, octet *)[4] = restart_cause; - pk_output (lcp); + pkp->pk_state = DTE_SENT_RESTART; + pkp->pk_dxerole &= ~(DTE_PLAYDCE | DTE_PLAYDTE); + lcp = pkp->pk_chan[0]; + m = lcp->lcd_template = pk_template(lcp->lcd_lcn, X25_RESTART); + m->m_pkthdr.len = m->m_len += 2; + mtod(m, struct x25_packet *)->packet_data = 0; /* DTE only */ + mtod(m, octet *)[4] = restart_cause; + pk_output(lcp); } -/* - * This procedure frees up the Logical Channel Descripter. +/* + * This procedure frees up the Logical Channel Descripter. */ -pk_freelcd (lcp) -register struct pklcd *lcp; +void +pk_freelcd(lcp) + register struct pklcd *lcp; { if (lcp == NULL) return; - if (lcp -> lcd_lcn > 0) - lcp -> lcd_pkp -> pk_chan[lcp -> lcd_lcn] = NULL; + if (lcp->lcd_lcn > 0) + lcp->lcd_pkp->pk_chan[lcp->lcd_lcn] = NULL; - pk_flush (lcp); - remque (&lcp -> lcd_q); - free ((caddr_t)lcp, M_PCB); + pk_flush(lcp); + remque(&lcp->lcd_q); + free((caddr_t) lcp, M_PCB); } static struct x25_ifaddr * -pk_ifwithaddr (sx) +pk_ifwithaddr(sx) struct sockaddr_x25 *sx; { - struct ifnet *ifp; - struct ifaddr *ifa; + struct ifnet *ifp; + struct ifaddr *ifa; register struct x25_ifaddr *ia; - char *addr = sx -> x25_addr; + char *addr = sx->x25_addr; for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next) for (ifa = ifp->if_addrlist.tqh_first; ifa != 0; - ifa = ifa->ifa_list.tqe_next) - if (ifa -> ifa_addr -> sa_family == AF_CCITT) { - ia = (struct x25_ifaddr *)ifa; - if (bcmp (addr, ia -> ia_xc.xc_addr.x25_addr, + ifa = ifa->ifa_list.tqe_next) + if (ifa->ifa_addr->sa_family == AF_CCITT) { + ia = (struct x25_ifaddr *) ifa; + if (bcmp(addr, ia->ia_xc.xc_addr.x25_addr, 16) == 0) return (ia); - + } - return ((struct x25_ifaddr *)0); + return ((struct x25_ifaddr *) 0); } -/* - * Bind a address and protocol value to a socket. The important - * part is the protocol value - the first four characters of the - * Call User Data field. +/* + * Bind a address and protocol value to a socket. The important part is the + * protocol value - the first four characters of the Call User Data field. */ -#define XTRACTPKP(rt) ((rt) -> rt_flags & RTF_GATEWAY ? \ - ((rt) -> rt_llinfo ? \ - (struct pkcb *) ((struct rtentry *)((rt) -> rt_llinfo)) -> rt_llinfo : \ +#define XTRACTPKP(rt) ((rt)->rt_flags & RTF_GATEWAY ? \ + ((rt)->rt_llinfo ? \ + (struct pkcb *) ((struct rtentry *)((rt)->rt_llinfo))->rt_llinfo : \ (struct pkcb *) NULL) : \ - (struct pkcb *)((rt) -> rt_llinfo)) + (struct pkcb *)((rt)->rt_llinfo)) -pk_bind (lcp, nam) -struct pklcd *lcp; -struct mbuf *nam; +int +pk_bind(lcp, nam) + struct pklcd *lcp; + struct mbuf *nam; { register struct pklcd *pp; register struct sockaddr_x25 *sa; if (nam == NULL) return (EADDRNOTAVAIL); - if (lcp -> lcd_ceaddr) /* XXX */ + if (lcp->lcd_ceaddr) /* XXX */ return (EADDRINUSE); - if (pk_checksockaddr (nam)) + if (pk_checksockaddr(nam)) return (EINVAL); - sa = mtod (nam, struct sockaddr_x25 *); + sa = mtod(nam, struct sockaddr_x25 *); /* * If the user wishes to accept calls only from a particular * net (net != 0), make sure the net is known */ - if (sa -> x25_addr[0]) { - if (!pk_ifwithaddr (sa)) + if (sa->x25_addr[0]) { + if (!pk_ifwithaddr(sa)) return (ENETUNREACH); - } else if (sa -> x25_net) { - if (!ifa_ifwithnet ((struct sockaddr *)sa)) + } else if (sa->x25_net) { + if (!ifa_ifwithnet((struct sockaddr *) sa)) return (ENETUNREACH); } - /* * For ISO's sake permit default listeners, but only one such . . . */ - for (pp = pk_listenhead; pp; pp = pp -> lcd_listen) { - register struct sockaddr_x25 *sa2 = pp -> lcd_ceaddr; - if ((sa2 -> x25_udlen == sa -> x25_udlen) && - (sa2 -> x25_udlen == 0 || - (bcmp (sa2 -> x25_udata, sa -> x25_udata, - min (sa2 -> x25_udlen, sa -> x25_udlen)) == 0))) - return (EADDRINUSE); + for (pp = pk_listenhead; pp; pp = pp->lcd_listen) { + register struct sockaddr_x25 *sa2 = pp->lcd_ceaddr; + if ((sa2->x25_udlen == sa->x25_udlen) && + (sa2->x25_udlen == 0 || + (bcmp(sa2->x25_udata, sa->x25_udata, + min(sa2->x25_udlen, sa->x25_udlen)) == 0))) + return (EADDRINUSE); } - lcp -> lcd_laddr = *sa; - lcp -> lcd_ceaddr = &lcp -> lcd_laddr; + lcp->lcd_laddr = *sa; + lcp->lcd_ceaddr = &lcp->lcd_laddr; return (0); } /* * Include a bound control block in the list of listeners. */ -pk_listen (lcp) -register struct pklcd *lcp; +int +pk_listen(lcp) + register struct pklcd *lcp; { register struct pklcd **pp; - if (lcp -> lcd_ceaddr == 0) + if (lcp->lcd_ceaddr == 0) return (EDESTADDRREQ); - lcp -> lcd_state = LISTEN; + lcp->lcd_state = LISTEN; /* * Add default listener at end, any others at start. */ - if (lcp -> lcd_ceaddr -> x25_udlen == 0) { - for (pp = &pk_listenhead; *pp; ) - pp = &((*pp) -> lcd_listen); + if (lcp->lcd_ceaddr->x25_udlen == 0) { + for (pp = &pk_listenhead; *pp;) + pp = &((*pp)->lcd_listen); *pp = lcp; } else { - lcp -> lcd_listen = pk_listenhead; + lcp->lcd_listen = pk_listenhead; pk_listenhead = lcp; } return (0); } + /* * Include a listening control block for the benefit of other protocols. */ -pk_protolisten (spi, spilen, callee) -int (*callee) (); +int +pk_protolisten(spi, spilen, callee) + int spi; + int spilen; + int (*callee) __P((struct mbuf *, void *)); { - register struct pklcd *lcp = pk_attach ((struct socket *)0); + register struct pklcd *lcp = pk_attach((struct socket *) 0); register struct mbuf *nam; register struct sockaddr_x25 *sa; - int error = ENOBUFS; + int error = ENOBUFS; if (lcp) { - if (nam = m_getclr (M_DONTWAIT, MT_SONAME)) { - sa = mtod (nam, struct sockaddr_x25 *); - sa -> x25_family = AF_CCITT; - sa -> x25_len = nam -> m_len = sizeof (*sa); - sa -> x25_udlen = spilen; - sa -> x25_udata[0] = spi; - lcp -> lcd_upper = callee; - lcp -> lcd_flags = X25_MBS_HOLD; - if ((error = pk_bind (lcp, nam)) == 0) - error = pk_listen (lcp); - (void) m_free (nam); + if ((nam = m_getclr(M_DONTWAIT, MT_SONAME)) != NULL) { + sa = mtod(nam, struct sockaddr_x25 *); + sa->x25_family = AF_CCITT; + sa->x25_len = nam->m_len = sizeof(*sa); + sa->x25_udlen = spilen; + sa->x25_udata[0] = spi; + lcp->lcd_upper = callee; + lcp->lcd_flags = X25_MBS_HOLD; + if ((error = pk_bind(lcp, nam)) == 0) + error = pk_listen(lcp); + (void) m_free(nam); } if (error) - pk_freelcd (lcp); + pk_freelcd(lcp); } - return error; /* Hopefully Zero !*/ + return error; /* Hopefully Zero ! */ } /* @@ -446,100 +457,99 @@ int (*callee) (); * by the remote DTE. */ -pk_assoc (pkp, lcp, sa) -register struct pkcb *pkp; -register struct pklcd *lcp; -register struct sockaddr_x25 *sa; +void +pk_assoc(pkp, lcp, sa) + register struct pkcb *pkp; + register struct pklcd *lcp; + register struct sockaddr_x25 *sa; { - lcp -> lcd_pkp = pkp; - lcp -> lcd_packetsize = pkp -> pk_xcp -> xc_psize; - lcp -> lcd_windowsize = pkp -> pk_xcp -> xc_pwsize; - lcp -> lcd_rsn = MODULUS - 1; - pkp -> pk_chan[lcp -> lcd_lcn] = lcp; + lcp->lcd_pkp = pkp; + lcp->lcd_packetsize = pkp->pk_xcp->xc_psize; + lcp->lcd_windowsize = pkp->pk_xcp->xc_pwsize; + lcp->lcd_rsn = MODULUS - 1; + pkp->pk_chan[lcp->lcd_lcn] = lcp; - if (sa -> x25_opts.op_psize) - lcp -> lcd_packetsize = sa -> x25_opts.op_psize; + if (sa->x25_opts.op_psize) + lcp->lcd_packetsize = sa->x25_opts.op_psize; else - sa -> x25_opts.op_psize = lcp -> lcd_packetsize; - if (sa -> x25_opts.op_wsize) - lcp -> lcd_windowsize = sa -> x25_opts.op_wsize; + sa->x25_opts.op_psize = lcp->lcd_packetsize; + if (sa->x25_opts.op_wsize) + lcp->lcd_windowsize = sa->x25_opts.op_wsize; else - sa -> x25_opts.op_wsize = lcp -> lcd_windowsize; - sa -> x25_net = pkp -> pk_xcp -> xc_addr.x25_net; - lcp -> lcd_flags |= sa -> x25_opts.op_flags; - lcp -> lcd_stime = time.tv_sec; + sa->x25_opts.op_wsize = lcp->lcd_windowsize; + sa->x25_net = pkp->pk_xcp->xc_addr.x25_net; + lcp->lcd_flags |= sa->x25_opts.op_flags; + lcp->lcd_stime = time.tv_sec; } -pk_connect (lcp, sa) -register struct pklcd *lcp; -register struct sockaddr_x25 *sa; +int +pk_connect(lcp, sa) + register struct pklcd *lcp; + register struct sockaddr_x25 *sa; { register struct pkcb *pkp; register struct rtentry *rt; register struct rtentry *nrt; - struct rtentry *npaidb_enter (); - struct pkcb *pk_newlink (); - - if (sa -> x25_addr[0] == '\0') + if (sa->x25_addr[0] == '\0') return (EDESTADDRREQ); /* * Is the destination address known? */ - if (!(rt = rtalloc1 ((struct sockaddr *)sa, 1))) + if (!(rt = rtalloc1((struct sockaddr *) sa, 1))) return (ENETUNREACH); if (!(pkp = XTRACTPKP(rt))) - pkp = pk_newlink ((struct x25_ifaddr *) (rt -> rt_ifa), + pkp = pk_newlink((struct x25_ifaddr *) (rt->rt_ifa), (caddr_t) 0); /* * Have we entered the LLC address? */ - if (nrt = npaidb_enter (rt -> rt_gateway, rt_key (rt), rt, 0)) - pkp -> pk_llrt = nrt; + if ((nrt = npaidb_enter((struct sockaddr_dl *) rt->rt_gateway, + rt_key(rt), rt, 0)) != NULL) + pkp->pk_llrt = nrt; /* * Have we allocated an LLC2 link yet? */ - if (pkp -> pk_llnext == (caddr_t)0 && pkp -> pk_llctlinput) { + if (pkp->pk_llnext == (caddr_t) 0 && pkp->pk_llctlinput) { struct dll_ctlinfo ctlinfo; ctlinfo.dlcti_rt = rt; ctlinfo.dlcti_pcb = (caddr_t) pkp; - ctlinfo.dlcti_conf = - (struct dllconfig *) (&((struct x25_ifaddr *)(rt -> rt_ifa)) -> ia_xc); - pkp -> pk_llnext = - (pkp -> pk_llctlinput) (PRC_CONNECT_REQUEST, 0, &ctlinfo); + ctlinfo.dlcti_conf = + (struct dllconfig *) (&((struct x25_ifaddr *) (rt->rt_ifa))->ia_xc); + pkp->pk_llnext = + (*pkp->pk_llctlinput)(PRC_CONNECT_REQUEST, + NULL, &ctlinfo); } - - if (pkp -> pk_state != DTE_READY && pkp -> pk_state != DTE_WAITING) - return (ENETDOWN); - if ((lcp -> lcd_lcn = pk_getlcn (pkp)) == 0) + if (pkp->pk_state != DTE_READY && pkp->pk_state != DTE_WAITING) + return (ENETDOWN); + if ((lcp->lcd_lcn = pk_getlcn(pkp)) == 0) return (EMFILE); - lcp -> lcd_faddr = *sa; - lcp -> lcd_ceaddr = & lcp -> lcd_faddr; - pk_assoc (pkp, lcp, lcp -> lcd_ceaddr); + lcp->lcd_faddr = *sa; + lcp->lcd_ceaddr = &lcp->lcd_faddr; + pk_assoc(pkp, lcp, lcp->lcd_ceaddr); /* * If the link is not up yet, initiate an X.25 RESTART */ - if (pkp -> pk_state == DTE_WAITING) { - pkp -> pk_dxerole |= DTE_CONNECTPENDING; - pk_ctlinput (PRC_LINKUP, (struct sockaddr *)0, pkp); - if (lcp -> lcd_so) - soisconnecting (lcp -> lcd_so); + if (pkp->pk_state == DTE_WAITING) { + pkp->pk_dxerole |= DTE_CONNECTPENDING; + pk_ctlinput(PRC_LINKUP, NULL, pkp); + if (lcp->lcd_so) + soisconnecting(lcp->lcd_so); return 0; } - - if (lcp -> lcd_so) - soisconnecting (lcp -> lcd_so); - lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_CALL); - pk_callrequest (lcp, lcp -> lcd_ceaddr, pkp -> pk_xcp); - return (*pkp -> pk_ia -> ia_start) (lcp); + if (lcp->lcd_so) + soisconnecting(lcp->lcd_so); + lcp->lcd_template = pk_template(lcp->lcd_lcn, X25_CALL); + pk_callrequest(lcp, lcp->lcd_ceaddr, pkp->pk_xcp); + return (*pkp->pk_ia->ia_start) (lcp); } /* @@ -548,126 +558,132 @@ register struct sockaddr_x25 *sa; */ #define RESHUFFLELCN(maxlcn, lcn) ((maxlcn) - (lcn) + 1) -pk_callcomplete (pkp) +void +pk_callcomplete(pkp) register struct pkcb *pkp; { register struct pklcd *lcp; - register int i; - register int ni; - + register int i; + register int ni; + - if (pkp -> pk_dxerole & DTE_CONNECTPENDING) - pkp -> pk_dxerole &= ~DTE_CONNECTPENDING; - else return; + if (pkp->pk_dxerole & DTE_CONNECTPENDING) + pkp->pk_dxerole &= ~DTE_CONNECTPENDING; + else + return; - if (pkp -> pk_chan == 0) + if (pkp->pk_chan == 0) return; - + /* * We pretended to be a DTE for allocating lcns, if * it turns out that we are in reality performing as a * DCE we need to reshuffle the lcps. - * - * /+---------------+-------- - - * / | a (maxlcn-1) | \ - * / +---------------+ \ - * +--- * | b (maxlcn-2) | \ - * | \ +---------------+ \ - * r | \ | c (maxlcn-3) | \ - * e | \+---------------+ | - * s | | . | + * + * /+---------------+-------- - + * / | a (maxlcn-1) | \ + * / +---------------+ \ + * +--- * | b (maxlcn-2) | \ + * | \ +---------------+ \ + * r | \ | c (maxlcn-3) | \ + * e | \+---------------+ | + * s | | . | * h | | . | m * u | | . | a * f | | . | x * f | | . | l * l | /+---------------+ | c * e | / | c' ( 3 ) | | n - * | / +---------------+ | + * | / +---------------+ | * +--> * | b' ( 2 ) | / - * \ +---------------+ / - * \ | a' ( 1 ) | / - * \+---------------+ / - * | 0 | / - * +---------------+-------- - - * - */ - if (pkp -> pk_dxerole & DTE_PLAYDCE) { + * \ +---------------+ / + * \ | a' ( 1 ) | / + * \+---------------+ / + * | 0 | / + * +---------------+-------- - + * + */ + if (pkp->pk_dxerole & DTE_PLAYDCE) { /* Sigh, reshuffle it */ - for (i = pkp -> pk_maxlcn; i > 0; --i) - if (pkp -> pk_chan[i]) { - ni = RESHUFFLELCN(pkp -> pk_maxlcn, i); - pkp -> pk_chan[ni] = pkp -> pk_chan[i]; - pkp -> pk_chan[i] = NULL; - pkp -> pk_chan[ni] -> lcd_lcn = ni; + for (i = pkp->pk_maxlcn; i > 0; --i) + if (pkp->pk_chan[i]) { + ni = RESHUFFLELCN(pkp->pk_maxlcn, i); + pkp->pk_chan[ni] = pkp->pk_chan[i]; + pkp->pk_chan[i] = NULL; + pkp->pk_chan[ni]->lcd_lcn = ni; } } - - for (i = 1; i <= pkp -> pk_maxlcn; ++i) - if ((lcp = pkp -> pk_chan[i]) != NULL) { - /* if (lcp -> lcd_so) - soisconnecting (lcp -> lcd_so); */ - lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_CALL); - pk_callrequest (lcp, lcp -> lcd_ceaddr, pkp -> pk_xcp); - (*pkp -> pk_ia -> ia_start) (lcp); + for (i = 1; i <= pkp->pk_maxlcn; ++i) + if ((lcp = pkp->pk_chan[i]) != NULL) { + /* + * if (lcp->lcd_so) soisconnecting (lcp->lcd_so); + */ + lcp->lcd_template = pk_template(lcp->lcd_lcn, X25_CALL); + pk_callrequest(lcp, lcp->lcd_ceaddr, pkp->pk_xcp); + (*pkp->pk_ia->ia_start) (lcp); } } struct bcdinfo { - octet *cp; - unsigned posn; + octet *cp; + unsigned posn; }; -/* - * Build the rest of the CALL REQUEST packet. Fill in calling - * address, facilities fields and the user data field. + +/* + * Build the rest of the CALL REQUEST packet. Fill in calling address, + * facilities fields and the user data field. */ -pk_callrequest (lcp, sa, xcp) -struct pklcd *lcp; -register struct sockaddr_x25 *sa; -register struct x25config *xcp; +void +pk_callrequest(lcp, sa, xcp) + struct pklcd *lcp; + register struct sockaddr_x25 *sa; + register struct x25config *xcp; { register struct x25_calladdr *a; - register struct mbuf *m = lcp -> lcd_template; - register struct x25_packet *xp = mtod (m, struct x25_packet *); - struct bcdinfo b; - - if (lcp -> lcd_flags & X25_DBIT) - X25SBITS(xp -> bits, d_bit, 1); - a = (struct x25_calladdr *) &xp -> packet_data; - b.cp = (octet *) a -> address_field; + register struct mbuf *m = lcp->lcd_template; + register struct x25_packet *xp = mtod(m, struct x25_packet *); + struct bcdinfo b; + + if (lcp->lcd_flags & X25_DBIT) + X25SBITS(xp->bits, d_bit, 1); + a = (struct x25_calladdr *) & xp->packet_data; + b.cp = (octet *) a->address_field; b.posn = 0; - X25SBITS(a -> addrlens, called_addrlen, to_bcd (&b, sa, xcp)); - X25SBITS(a -> addrlens, calling_addrlen, to_bcd (&b, &xcp -> xc_addr, xcp)); + X25SBITS(a->addrlens, called_addrlen, to_bcd(&b, sa, xcp)); + X25SBITS(a->addrlens, calling_addrlen, to_bcd(&b, &xcp->xc_addr, xcp)); if (b.posn & 0x01) *b.cp++ &= 0xf0; - m -> m_pkthdr.len = m -> m_len += b.cp - (octet *) a; + m->m_pkthdr.len = m->m_len += b.cp - (octet *) a; - if (lcp -> lcd_facilities) { - m -> m_pkthdr.len += - (m -> m_next = lcp -> lcd_facilities) -> m_pkthdr.len; - lcp -> lcd_facilities = 0; + if (lcp->lcd_facilities) { + m->m_pkthdr.len += + (m->m_next = lcp->lcd_facilities)->m_pkthdr.len; + lcp->lcd_facilities = 0; } else - pk_build_facilities (m, sa, (int)xcp -> xc_type); + pk_build_facilities(m, sa, (int) xcp->xc_type); - m_copyback (m, m -> m_pkthdr.len, sa -> x25_udlen, sa -> x25_udata); + m_copyback(m, m->m_pkthdr.len, sa->x25_udlen, sa->x25_udata); } -pk_build_facilities (m, sa, type) -register struct mbuf *m; -struct sockaddr_x25 *sa; +void +pk_build_facilities(m, sa, type) + register struct mbuf *m; + struct sockaddr_x25 *sa; + int type; { register octet *cp; register octet *fcp; - register int revcharge; + register int revcharge; - cp = mtod (m, octet *) + m -> m_len; + cp = mtod(m, octet *) + m->m_len; fcp = cp + 1; - revcharge = sa -> x25_opts.op_flags & X25_REVERSE_CHARGE ? 1 : 0; + revcharge = sa->x25_opts.op_flags & X25_REVERSE_CHARGE ? 1 : 0; /* * This is specific to Datapac X.25(1976) DTEs. International * calls must have the "hi priority" bit on. */ - if (type == X25_1976 && sa -> x25_opts.op_psize == X25_PS128) + if (type == X25_1976 && sa->x25_opts.op_psize == X25_PS128) revcharge |= 02; if (revcharge) { *fcp++ = FACILITIES_REVERSE_CHARGE; @@ -677,161 +693,169 @@ struct sockaddr_x25 *sa; case X25_1980: case X25_1984: *fcp++ = FACILITIES_PACKETSIZE; - *fcp++ = sa -> x25_opts.op_psize; - *fcp++ = sa -> x25_opts.op_psize; + *fcp++ = sa->x25_opts.op_psize; + *fcp++ = sa->x25_opts.op_psize; *fcp++ = FACILITIES_WINDOWSIZE; - *fcp++ = sa -> x25_opts.op_wsize; - *fcp++ = sa -> x25_opts.op_wsize; + *fcp++ = sa->x25_opts.op_wsize; + *fcp++ = sa->x25_opts.op_wsize; } *cp = fcp - cp - 1; - m -> m_pkthdr.len = (m -> m_len += *cp + 1); + m->m_pkthdr.len = (m->m_len += *cp + 1); } -to_bcd (b, sa, xcp) -register struct bcdinfo *b; -struct sockaddr_x25 *sa; -register struct x25config *xcp; +int +to_bcd(b, sa, xcp) + register struct bcdinfo *b; + struct sockaddr_x25 *sa; + register struct x25config *xcp; { - register char *x = sa -> x25_addr; - unsigned start = b -> posn; + register char *x = sa->x25_addr; + unsigned start = b->posn; /* * The nodnic and prepnd0 stuff looks tedious, * but it does allow full X.121 addresses to be used, * which is handy for routing info (& OSI type 37 addresses). */ - if (xcp -> xc_addr.x25_net && (xcp -> xc_nodnic || xcp -> xc_prepnd0)) { - char dnicname[sizeof (long) * NBBY/3 + 2]; - register char *p = dnicname; + if (xcp->xc_addr.x25_net && (xcp->xc_nodnic || xcp->xc_prepnd0)) { + char dnicname[sizeof(long) * NBBY / 3 + 2]; + register char *p = dnicname; - sprintf (p, "%d", xcp -> xc_addr.x25_net & 0x7fff); - for (; *p; p++) /* *p == 0 means dnic matched */ + sprintf(p, "%d", xcp->xc_addr.x25_net & 0x7fff); + for (; *p; p++) /* *p == 0 means dnic matched */ if ((*p ^ *x++) & 0x0f) break; - if (*p || xcp -> xc_nodnic == 0) - x = sa -> x25_addr; - if (*p && xcp -> xc_prepnd0) { - if ((b -> posn)++ & 0x01) - *(b -> cp)++; + if (*p || xcp->xc_nodnic == 0) + x = sa->x25_addr; + if (*p && xcp->xc_prepnd0) { + if ((b->posn)++ & 0x01) + (b->cp)++; else - *(b -> cp) = 0; + *(b->cp) = 0; } } while (*x) - if ((b -> posn)++ & 0x01) - *(b -> cp)++ |= *x++ & 0x0F; + if ((b->posn)++ & 0x01) + *(b->cp)++ |= *x++ & 0x0F; else - *(b -> cp) = *x++ << 4; - return ((b -> posn) - start); + *(b->cp) = *x++ << 4; + return ((b->posn) - start); } -/* - * This routine gets the first available logical channel number. The - * search is - * - from the highest number to lowest number if playing DTE, and - * - from lowest to highest number if playing DCE. +/* + * This routine gets the first available logical channel number. The search + * is - from the highest number to lowest number if playing DTE, and - from + * lowest to highest number if playing DCE. */ -pk_getlcn (pkp) -register struct pkcb *pkp; +int +pk_getlcn(pkp) + register struct pkcb *pkp; { - register int i; + register int i; - if (pkp -> pk_chan == 0) + if (pkp->pk_chan == 0) return (0); - if ( pkp -> pk_dxerole & DTE_PLAYDCE ) { - for (i = 1; i <= pkp -> pk_maxlcn; ++i) - if (pkp -> pk_chan[i] == NULL) + if (pkp->pk_dxerole & DTE_PLAYDCE) { + for (i = 1; i <= pkp->pk_maxlcn; ++i) + if (pkp->pk_chan[i] == NULL) break; - } else { - for (i = pkp -> pk_maxlcn; i > 0; --i) - if (pkp -> pk_chan[i] == NULL) + } else { + for (i = pkp->pk_maxlcn; i > 0; --i) + if (pkp->pk_chan[i] == NULL) break; } - i = ( i > pkp -> pk_maxlcn ? 0 : i ); + i = (i > pkp->pk_maxlcn ? 0 : i); return (i); } -/* - * This procedure sends a CLEAR request packet. The lc state is - * set to "SENT_CLEAR". +/* + * This procedure sends a CLEAR request packet. The lc state is set to + * "SENT_CLEAR". */ -pk_clear (lcp, diagnostic, abortive) -register struct pklcd *lcp; +void +pk_clear(lcp, diagnostic, abortive) + register struct pklcd *lcp; + int diagnostic; + int abortive; { - register struct mbuf *m = pk_template (lcp -> lcd_lcn, X25_CLEAR); - - m -> m_len += 2; - m -> m_pkthdr.len += 2; - mtod (m, struct x25_packet *) -> packet_data = 0; - mtod (m, octet *)[4] = diagnostic; - if (lcp -> lcd_facilities) { - m -> m_next = lcp -> lcd_facilities; - m -> m_pkthdr.len += m -> m_next -> m_len; - lcp -> lcd_facilities = 0; + register struct mbuf *m = pk_template(lcp->lcd_lcn, X25_CLEAR); + + m->m_len += 2; + m->m_pkthdr.len += 2; + mtod(m, struct x25_packet *)->packet_data = 0; + mtod(m, octet *)[4] = diagnostic; + if (lcp->lcd_facilities) { + m->m_next = lcp->lcd_facilities; + m->m_pkthdr.len += m->m_next->m_len; + lcp->lcd_facilities = 0; } if (abortive) - lcp -> lcd_template = m; + lcp->lcd_template = m; else { - struct socket *so = lcp -> lcd_so; - struct sockbuf *sb = so ? & so -> so_snd : & lcp -> lcd_sb; - sbappendrecord (sb, m); + struct socket *so = lcp->lcd_so; + struct sockbuf *sb = so ? &so->so_snd : &lcp->lcd_sb; + sbappendrecord(sb, m); } - pk_output (lcp); + pk_output(lcp); } /* * This procedure generates RNR's or RR's to inhibit or enable * inward data flow, if the current state changes (blocked ==> open or - * vice versa), or if forced to generate one. One forces RNR's to ack data. + * vice versa), or if forced to generate one. One forces RNR's to ack data. */ -pk_flowcontrol (lcp, inhibit, forced) -register struct pklcd *lcp; +void +pk_flowcontrol(lcp, inhibit, forced) + register struct pklcd *lcp; + int inhibit; + int forced; { inhibit = (inhibit != 0); - if (lcp == 0 || lcp -> lcd_state != DATA_TRANSFER || - (forced == 0 && lcp -> lcd_rxrnr_condition == inhibit)) + if (lcp == 0 || lcp->lcd_state != DATA_TRANSFER || + (forced == 0 && lcp->lcd_rxrnr_condition == inhibit)) return; - lcp -> lcd_rxrnr_condition = inhibit; - lcp -> lcd_template = - pk_template (lcp -> lcd_lcn, inhibit ? X25_RNR : X25_RR); - pk_output (lcp); + lcp->lcd_rxrnr_condition = inhibit; + lcp->lcd_template = + pk_template(lcp->lcd_lcn, inhibit ? X25_RNR : X25_RR); + pk_output(lcp); } -/* - * This procedure sends a RESET request packet. It re-intializes - * virtual circuit. +/* + * This procedure sends a RESET request packet. It re-intializes virtual + * circuit. */ -static -pk_reset (lcp, diagnostic) -register struct pklcd *lcp; +static void +pk_reset(lcp, diagnostic) + register struct pklcd *lcp; + int diagnostic; { register struct mbuf *m; - register struct socket *so = lcp -> lcd_so; + register struct socket *so = lcp->lcd_so; - if (lcp -> lcd_state != DATA_TRANSFER) + if (lcp->lcd_state != DATA_TRANSFER) return; if (so) - so -> so_error = ECONNRESET; - lcp -> lcd_reset_condition = TRUE; + so->so_error = ECONNRESET; + lcp->lcd_reset_condition = TRUE; /* Reset all the control variables for the channel. */ - pk_flush (lcp); - lcp -> lcd_window_condition = lcp -> lcd_rnr_condition = - lcp -> lcd_intrconf_pending = FALSE; - lcp -> lcd_rsn = MODULUS - 1; - lcp -> lcd_ssn = 0; - lcp -> lcd_output_window = lcp -> lcd_input_window = - lcp -> lcd_last_transmitted_pr = 0; - m = lcp -> lcd_template = pk_template (lcp -> lcd_lcn, X25_RESET); - m -> m_pkthdr.len = m -> m_len += 2; - mtod (m, struct x25_packet *) -> packet_data = 0; - mtod (m, octet *)[4] = diagnostic; - pk_output (lcp); + pk_flush(lcp); + lcp->lcd_window_condition = lcp->lcd_rnr_condition = + lcp->lcd_intrconf_pending = FALSE; + lcp->lcd_rsn = MODULUS - 1; + lcp->lcd_ssn = 0; + lcp->lcd_output_window = lcp->lcd_input_window = + lcp->lcd_last_transmitted_pr = 0; + m = lcp->lcd_template = pk_template(lcp->lcd_lcn, X25_RESET); + m->m_pkthdr.len = m->m_len += 2; + mtod(m, struct x25_packet *)->packet_data = 0; + mtod(m, octet *)[4] = diagnostic; + pk_output(lcp); } @@ -839,319 +863,335 @@ register struct pklcd *lcp; * This procedure frees all data queued for output or delivery on a * virtual circuit. */ - -pk_flush (lcp) -register struct pklcd *lcp; +void +pk_flush(lcp) + register struct pklcd *lcp; { register struct socket *so; - if (lcp -> lcd_template) - m_freem (lcp -> lcd_template); + if (lcp->lcd_template) + m_freem(lcp->lcd_template); - if (lcp -> lcd_cps) { - m_freem (lcp -> lcd_cps); - lcp -> lcd_cps = 0; + if (lcp->lcd_cps) { + m_freem(lcp->lcd_cps); + lcp->lcd_cps = 0; } - if (lcp -> lcd_facilities) { - m_freem (lcp -> lcd_facilities); - lcp -> lcd_facilities = 0; + if (lcp->lcd_facilities) { + m_freem(lcp->lcd_facilities); + lcp->lcd_facilities = 0; } - if (so = lcp -> lcd_so) - sbflush (&so -> so_snd); - else - sbflush (&lcp -> lcd_sb); + if ((so = lcp->lcd_so) != NULL) + sbflush(&so->so_snd); + else + sbflush(&lcp->lcd_sb); } -/* - * This procedure handles all local protocol procedure errors. +/* + * This procedure handles all local protocol procedure errors. */ -pk_procerror (error, lcp, errstr, diagnostic) -register struct pklcd *lcp; -char *errstr; +void +pk_procerror(error, lcp, errstr, diagnostic) + int error; + register struct pklcd *lcp; + char *errstr; + int diagnostic; { - pk_message (lcp -> lcd_lcn, lcp -> lcd_pkp -> pk_xcp, errstr); + pk_message(lcp->lcd_lcn, lcp->lcd_pkp->pk_xcp, errstr); switch (error) { - case CLEAR: - if (lcp -> lcd_so) { - lcp -> lcd_so -> so_error = ECONNABORTED; - soisdisconnecting (lcp -> lcd_so); + case PK_CLEAR: + if (lcp->lcd_so) { + lcp->lcd_so->so_error = ECONNABORTED; + soisdisconnecting(lcp->lcd_so); } - pk_clear (lcp, diagnostic, 1); + pk_clear(lcp, diagnostic, 1); break; - case RESET: - pk_reset (lcp, diagnostic); + case PK_RESET: + pk_reset(lcp, diagnostic); } } -/* - * This procedure is called during the DATA TRANSFER state to check - * and process the P(R) values received in the DATA, RR OR RNR - * packets. +/* + * This procedure is called during the DATA TRANSFER state to check and + * process the P(R) values received in the DATA, RR OR RNR packets. */ -pk_ack (lcp, pr) -struct pklcd *lcp; -unsigned pr; +int +pk_ack(lcp, pr) + struct pklcd *lcp; + unsigned pr; { - register struct socket *so = lcp -> lcd_so; + register struct socket *so = lcp->lcd_so; - if (lcp -> lcd_output_window == pr) + if (lcp->lcd_output_window == pr) return (PACKET_OK); - if (lcp -> lcd_output_window < lcp -> lcd_ssn) { - if (pr < lcp -> lcd_output_window || pr > lcp -> lcd_ssn) { - pk_procerror (RESET, lcp, - "p(r) flow control error", 2); + if (lcp->lcd_output_window < lcp->lcd_ssn) { + if (pr < lcp->lcd_output_window || pr > lcp->lcd_ssn) { + pk_procerror(PK_RESET, lcp, + "p(r) flow control error", 2); return (ERROR_PACKET); } - } - else { - if (pr < lcp -> lcd_output_window && pr > lcp -> lcd_ssn) { - pk_procerror (RESET, lcp, - "p(r) flow control error #2", 2); + } else { + if (pr < lcp->lcd_output_window && pr > lcp->lcd_ssn) { + pk_procerror(PK_RESET, lcp, + "p(r) flow control error #2", 2); return (ERROR_PACKET); } } - lcp -> lcd_output_window = pr; /* Rotate window. */ - if (lcp -> lcd_window_condition == TRUE) - lcp -> lcd_window_condition = FALSE; + lcp->lcd_output_window = pr; /* Rotate window. */ + if (lcp->lcd_window_condition == TRUE) + lcp->lcd_window_condition = FALSE; - if (so && sb_notify (&(so -> so_snd))) - sowwakeup (so); + if (so && sb_notify(&(so->so_snd))) + sowwakeup(so); return (PACKET_OK); } -/* - * This procedure decodes the X.25 level 3 packet returning a - * code to be used in switchs or arrays. +/* + * This procedure decodes the X.25 level 3 packet returning a code to be used + * in switchs or arrays. */ -pk_decode (xp) -register struct x25_packet *xp; +int +pk_decode(xp) + register struct x25_packet *xp; { - register int type; + register int type; - if (X25GBITS(xp -> bits, fmt_identifier) != 1) - return (INVALID_PACKET); + if (X25GBITS(xp->bits, fmt_identifier) != 1) + return (PK_INVALID_PACKET); #ifdef ancient_history - /* - * Make sure that the logical channel group number is 0. - * This restriction may be removed at some later date. + /* + * Make sure that the logical channel group number is 0. This + * restriction may be removed at some later date. */ - if (xp -> lc_group_number != 0) - return (INVALID_PACKET); + if (xp->lc_group_number != 0) + return (PK_INVALID_PACKET); #endif - /* - * Test for data packet first. + /* + * Test for data packet first. */ - if (!(xp -> packet_type & DATA_PACKET_DESIGNATOR)) - return (DATA); + if (!(xp->packet_type & DATA_PACKET_DESIGNATOR)) + return (PK_DATA); - /* - * Test if flow control packet (RR or RNR). + /* + * Test if flow control packet (RR or RNR). */ - if (!(xp -> packet_type & RR_OR_RNR_PACKET_DESIGNATOR)) - switch (xp -> packet_type & 0x1f) { + if (!(xp->packet_type & RR_OR_RNR_PACKET_DESIGNATOR)) + switch (xp->packet_type & 0x1f) { case X25_RR: - return (RR); + return (PK_RR); case X25_RNR: - return (RNR); + return (PK_RNR); case X25_REJECT: - return (REJECT); + return (PK_REJECT); } - /* - * Determine the rest of the packet types. + /* + * Determine the rest of the packet types. */ - switch (xp -> packet_type) { - case X25_CALL: - type = CALL; + switch (xp->packet_type) { + case X25_CALL: + type = PK_CALL; break; - case X25_CALL_ACCEPTED: - type = CALL_ACCEPTED; + case X25_CALL_ACCEPTED: + type = PK_CALL_ACCEPTED; break; - case X25_CLEAR: - type = CLEAR; + case X25_CLEAR: + type = PK_CLEAR; break; - case X25_CLEAR_CONFIRM: - type = CLEAR_CONF; + case X25_CLEAR_CONFIRM: + type = PK_CLEAR_CONF; break; - case X25_INTERRUPT: - type = INTERRUPT; + case X25_INTERRUPT: + type = PK_INTERRUPT; break; - case X25_INTERRUPT_CONFIRM: - type = INTERRUPT_CONF; + case X25_INTERRUPT_CONFIRM: + type = PK_INTERRUPT_CONF; break; - case X25_RESET: - type = RESET; + case X25_RESET: + type = PK_RESET; break; - case X25_RESET_CONFIRM: - type = RESET_CONF; + case X25_RESET_CONFIRM: + type = PK_RESET_CONF; break; - case X25_RESTART: - type = RESTART; + case X25_RESTART: + type = PK_RESTART; break; - case X25_RESTART_CONFIRM: - type = RESTART_CONF; + case X25_RESTART_CONFIRM: + type = PK_RESTART_CONF; break; case X25_DIAGNOSTIC: - type = DIAG_TYPE; + type = PK_DIAG_TYPE; break; - default: - type = INVALID_PACKET; + default: + type = PK_INVALID_PACKET; } return (type); } -/* - * A restart packet has been received. Print out the reason - * for the restart. +/* + * A restart packet has been received. Print out the reason for the restart. */ -pk_restartcause (pkp, xp) -struct pkcb *pkp; -register struct x25_packet *xp; +void +pk_restartcause(pkp, xp) + struct pkcb *pkp; + register struct x25_packet *xp; { - register struct x25config *xcp = pkp -> pk_xcp; - register int lcn = LCN(xp); + register struct x25config *xcp = pkp->pk_xcp; + register int lcn = LCN(xp); - switch (xp -> packet_data) { - case X25_RESTART_LOCAL_PROCEDURE_ERROR: - pk_message (lcn, xcp, "restart: local procedure error"); + switch (xp->packet_data) { + case X25_RESTART_LOCAL_PROCEDURE_ERROR: + pk_message(lcn, xcp, "restart: local procedure error"); break; - case X25_RESTART_NETWORK_CONGESTION: - pk_message (lcn, xcp, "restart: network congestion"); + case X25_RESTART_NETWORK_CONGESTION: + pk_message(lcn, xcp, "restart: network congestion"); break; - case X25_RESTART_NETWORK_OPERATIONAL: - pk_message (lcn, xcp, "restart: network operational"); + case X25_RESTART_NETWORK_OPERATIONAL: + pk_message(lcn, xcp, "restart: network operational"); break; - default: - pk_message (lcn, xcp, "restart: unknown cause"); + default: + pk_message(lcn, xcp, "restart: unknown cause"); } } #define MAXRESETCAUSE 7 -int Reset_cause[] = { +int Reset_cause[] = { EXRESET, EXROUT, 0, EXRRPE, 0, EXRLPE, 0, EXRNCG }; -/* - * A reset packet has arrived. Return the cause to the user. +/* + * A reset packet has arrived. Return the cause to the user. */ -pk_resetcause (pkp, xp) -struct pkcb *pkp; -register struct x25_packet *xp; +void +pk_resetcause(pkp, xp) + struct pkcb *pkp; + register struct x25_packet *xp; { register struct pklcd *lcp = - pkp -> pk_chan[LCN(xp)]; - register int code = xp -> packet_data; + pkp->pk_chan[LCN(xp)]; + register int code = xp->packet_data; if (code > MAXRESETCAUSE) code = 7; /* EXRNCG */ - pk_message (LCN(xp), lcp -> lcd_pkp, "reset code 0x%x, diagnostic 0x%x", - xp -> packet_data, 4[(u_char *)xp]); - - if (lcp -> lcd_so) - lcp -> lcd_so -> so_error = Reset_cause[code]; + pk_message(LCN(xp), lcp->lcd_pkp->pk_xcp, + "reset code 0x%x, diagnostic 0x%x", + xp->packet_data, 4[(u_char *) xp]); + + if (lcp->lcd_so) + lcp->lcd_so->so_error = Reset_cause[code]; } #define MAXCLEARCAUSE 25 -int Clear_cause[] = { +int Clear_cause[] = { EXCLEAR, EXCBUSY, 0, EXCINV, 0, EXCNCG, 0, 0, 0, EXCOUT, 0, EXCAB, 0, EXCNOB, 0, 0, 0, EXCRPE, 0, EXCLPE, 0, 0, 0, 0, 0, EXCRRC }; -/* - * A clear packet has arrived. Return the cause to the user. +/* + * A clear packet has arrived. Return the cause to the user. */ - -pk_clearcause (pkp, xp) -struct pkcb *pkp; -register struct x25_packet *xp; +void +pk_clearcause(pkp, xp) + struct pkcb *pkp; + register struct x25_packet *xp; { register struct pklcd *lcp = - pkp -> pk_chan[LCN(xp)]; - register int code = xp -> packet_data; + pkp->pk_chan[LCN(xp)]; + register int code = xp->packet_data; if (code > MAXCLEARCAUSE) code = 5; /* EXRNCG */ - if (lcp -> lcd_so) - lcp -> lcd_so -> so_error = Clear_cause[code]; + if (lcp->lcd_so) + lcp->lcd_so->so_error = Clear_cause[code]; } char * -format_ntn (xcp) -register struct x25config *xcp; +format_ntn(xcp) + register struct x25config *xcp; { - return (xcp -> xc_addr.x25_addr); + return (xcp->xc_addr.x25_addr); } /* VARARGS1 */ -pk_message (lcn, xcp, fmt, a1, a2, a3, a4, a5, a6) -struct x25config *xcp; -char *fmt; +void +#if __STDC__ +pk_message(int lcn, struct x25config * xcp, char * fmt,...) +#else +pk_message(lcn, xcp, fmt, va_alist) + int lcn; + struct x25config *xcp; + char *fmt; + va_dcl +#endif { + va_list ap; + static const char *rec = "%r\n"; if (lcn) if (!PQEMPTY) - printf ("X.25(%s): lcn %d: ", format_ntn (xcp), lcn); + printf("X.25(%s): lcn %d: ", format_ntn(xcp), lcn); else - printf ("X.25: lcn %d: ", lcn); + printf("X.25: lcn %d: ", lcn); + else if (!PQEMPTY) + printf("X.25(%s): ", format_ntn(xcp)); else - if (!PQEMPTY) - printf ("X.25(%s): ", format_ntn (xcp)); - else - printf ("X.25: "); + printf("X.25: "); - printf (fmt, a1, a2, a3, a4, a5, a6); - printf ("\n"); + va_start(ap, fmt); + printf(rec, fmt, ap); + va_end(ap); } -pk_fragment (lcp, m0, qbit, mbit, wait) -struct mbuf *m0; -register struct pklcd *lcp; +int +pk_fragment(lcp, m0, qbit, mbit, wait) + struct mbuf *m0; + register struct pklcd *lcp; + int qbit, mbit, wait; { register struct mbuf *m = m0; register struct x25_packet *xp; register struct sockbuf *sb; - struct mbuf *head = 0, *next, **mp = &head, *m_split (); - int totlen, psize = 1 << (lcp -> lcd_packetsize); + struct mbuf *head = 0, *next, **mp = &head; + int totlen, psize = 1 << (lcp->lcd_packetsize); if (m == 0) return 0; - if (m -> m_flags & M_PKTHDR == 0) - panic ("pk_fragment"); - totlen = m -> m_pkthdr.len; - m -> m_act = 0; - sb = lcp -> lcd_so ? &lcp -> lcd_so -> so_snd : & lcp -> lcd_sb; + if (m->m_flags & M_PKTHDR == 0) + panic("pk_fragment"); + totlen = m->m_pkthdr.len; + m->m_act = 0; + sb = lcp->lcd_so ? &lcp->lcd_so->so_snd : &lcp->lcd_sb; do { if (totlen > psize) { - if ((next = m_split (m, psize, wait)) == 0) + if ((next = m_split(m, psize, wait)) == 0) goto abort; totlen -= psize; } else @@ -1160,35 +1200,35 @@ register struct pklcd *lcp; if (m == 0) goto abort; *mp = m; - mp = & m -> m_act; + mp = &m->m_act; *mp = 0; - xp = mtod (m, struct x25_packet *); - 0[(char *)xp] = 0; + xp = mtod(m, struct x25_packet *); + 0[(char *) xp] = 0; if (qbit) - X25SBITS(xp -> bits, q_bit, 1); - if (lcp -> lcd_flags & X25_DBIT) - X25SBITS(xp -> bits, d_bit, 1); - X25SBITS(xp -> bits, fmt_identifier, 1); - xp -> packet_type = X25_DATA; - SET_LCN(xp, lcp -> lcd_lcn); + X25SBITS(xp->bits, q_bit, 1); + if (lcp->lcd_flags & X25_DBIT) + X25SBITS(xp->bits, d_bit, 1); + X25SBITS(xp->bits, fmt_identifier, 1); + xp->packet_type = X25_DATA; + SET_LCN(xp, lcp->lcd_lcn); if (next || (mbit && (totlen == psize || - (lcp -> lcd_flags & X25_DBIT)))) + (lcp->lcd_flags & X25_DBIT)))) SMBIT(xp, 1); - } while (m = next); + } while ((m = next) != NULL); for (m = head; m; m = next) { - next = m -> m_act; - m -> m_act = 0; - sbappendrecord (sb, m); + next = m->m_act; + m->m_act = 0; + sbappendrecord(sb, m); } return 0; abort: if (wait) - panic ("pk_fragment null mbuf after wait"); + panic("pk_fragment null mbuf after wait"); if (next) - m_freem (next); + m_freem(next); for (m = head; m; m = next) { - next = m -> m_act; - m_freem (m); + next = m->m_act; + m_freem(m); } return ENOBUFS; } diff --git a/sys/netccitt/pk_timer.c b/sys/netccitt/pk_timer.c index c078e23b652..70455507e91 100644 --- a/sys/netccitt/pk_timer.c +++ b/sys/netccitt/pk_timer.c @@ -1,16 +1,15 @@ -/* $NetBSD: pk_timer.c,v 1.5 1994/06/29 06:37:40 cgd Exp $ */ +/* $OpenBSD: pk_timer.c,v 1.2 1996/03/04 07:36:46 niklas Exp $ */ +/* $NetBSD: pk_timer.c,v 1.6 1996/02/13 22:05:39 christos Exp $ */ /* - * Copyright (c) Computing Centre, University of British Columbia, 1984 - * Copyright (C) Computer Science Department IV, - * University of Erlangen-Nuremberg, Germany, 1990, 1992 - * Copyright (c) 1990, 1992, 1993 + * Copyright (C) Dirk Husemann, Computer Science Department IV, + * University of Erlangen-Nuremberg, Germany, 1990, 1991, 1992 + * Copyright (c) 1992, 1993 * 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 the University of British Columbia and the Computer Science - * Department (IV) of the University of Erlangen-Nuremberg, Germany. + * This code is derived from software contributed to Berkeley by + * Dirk Husemann and the Computer Science Department (IV) of + * the University of Erlangen-Nuremberg, Germany. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -56,72 +55,73 @@ #include #include #include +#include /* * Various timer values. They can be adjusted * by patching the binary with adb if necessary. */ -int pk_t20 = 18 * PR_SLOWHZ; /* restart timer */ -int pk_t21 = 20 * PR_SLOWHZ; /* call timer */ +int pk_t20 = 18 * PR_SLOWHZ; /* restart timer */ +int pk_t21 = 20 * PR_SLOWHZ; /* call timer */ /* XXX pk_t22 is never used */ -int pk_t22 = 18 * PR_SLOWHZ; /* reset timer */ -int pk_t23 = 18 * PR_SLOWHZ; /* clear timer */ +int pk_t22 = 18 * PR_SLOWHZ; /* reset timer */ +int pk_t23 = 18 * PR_SLOWHZ; /* clear timer */ -pk_timer () +void +pk_timer() { register struct pkcb *pkp; register struct pklcd *lcp, **pp; - register int lcns_jammed, cant_restart; + register int lcns_jammed, cant_restart; FOR_ALL_PKCBS(pkp) { - switch (pkp -> pk_state) { + switch (pkp->pk_state) { case DTE_SENT_RESTART: - lcp = pkp -> pk_chan[0]; + lcp = pkp->pk_chan[0]; /* * If restart failures are common, a link level * reset should be initiated here. */ - if (lcp -> lcd_timer && --lcp -> lcd_timer == 0) { - pk_message (0, pkp -> pk_xcp, - "packet level restart failed"); - pkp -> pk_state = DTE_WAITING; + if (lcp->lcd_timer && --lcp->lcd_timer == 0) { + pk_message(0, pkp->pk_xcp, + "packet level restart failed"); + pkp->pk_state = DTE_WAITING; } break; case DTE_READY: lcns_jammed = cant_restart = 0; - for (pp = &pkp -> pk_chan[1]; pp <= &pkp -> pk_chan[pkp -> pk_maxlcn]; pp++) { + for (pp = &pkp->pk_chan[1]; pp <= &pkp->pk_chan[pkp->pk_maxlcn]; pp++) { if ((lcp = *pp) == 0) continue; - switch (lcp -> lcd_state) { - case SENT_CALL: - if (--lcp -> lcd_timer == 0) { - if (lcp -> lcd_so) - lcp -> lcd_so -> so_error = ETIMEDOUT; - pk_clear (lcp, 49, 1); + switch (lcp->lcd_state) { + case SENT_CALL: + if (--lcp->lcd_timer == 0) { + if (lcp->lcd_so) + lcp->lcd_so->so_error = ETIMEDOUT; + pk_clear(lcp, 49, 1); } break; - case SENT_CLEAR: - if (lcp -> lcd_retry >= 3) + case SENT_CLEAR: + if (lcp->lcd_retry >= 3) lcns_jammed++; - else - if (--lcp -> lcd_timer == 0) - pk_clear (lcp, 50, 1); + else if (--lcp->lcd_timer == 0) + pk_clear(lcp, 50, 1); break; case DATA_TRANSFER: /* lcn active */ cant_restart++; break; - case LCN_ZOMBIE: /* zombie state */ - pk_freelcd (lcp); + case LCN_ZOMBIE: /* zombie state */ + pk_freelcd(lcp); break; } } - if (lcns_jammed > pkp -> pk_maxlcn / 2 && cant_restart == 0) { - pk_message (0, pkp -> pk_xcp, "%d lcns jammed: attempting restart", lcns_jammed); - pk_restart (pkp, 0); + if (lcns_jammed > pkp->pk_maxlcn / 2 && cant_restart == 0) { + pk_message(0, pkp->pk_xcp, "%d lcns jammed: attempting restart", lcns_jammed); + pk_restart(pkp, 0); } } } diff --git a/sys/netccitt/pk_usrreq.c b/sys/netccitt/pk_usrreq.c index fcf57003437..8fa4c9b476c 100644 --- a/sys/netccitt/pk_usrreq.c +++ b/sys/netccitt/pk_usrreq.c @@ -1,8 +1,9 @@ -/* $NetBSD: pk_usrreq.c,v 1.9 1995/06/13 05:38:58 mycroft Exp $ */ +/* $OpenBSD: pk_usrreq.c,v 1.2 1996/03/04 07:36:47 niklas Exp $ */ +/* $NetBSD: pk_usrreq.c,v 1.10 1996/02/13 22:05:43 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 - * Copyright (C) Computer Science Department IV, + * Copyright (C) Computer Science Department IV, * University of Erlangen-Nuremberg, Germany, 1992 * Copyright (c) 1991, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -60,11 +61,12 @@ #include #include #include +#include -static old_to_new(); -static new_to_old(); +static void old_to_new __P((struct mbuf *)); +static void new_to_old __P((struct mbuf *)); /* - * + * * X.25 Packet level protocol interface to socket abstraction. * * Process an X.25 user request on a logical channel. If this is a send @@ -73,20 +75,20 @@ static new_to_old(); * the particular timer. * */ - -pk_usrreq (so, req, m, nam, control) -struct socket *so; -int req; -register struct mbuf *m, *nam; -struct mbuf *control; +int +pk_usrreq(so, req, m, nam, control) + struct socket *so; + int req; + register struct mbuf *m, *nam; + struct mbuf *control; { - register struct pklcd *lcp = (struct pklcd *) so -> so_pcb; - register int error = 0; + register struct pklcd *lcp = (struct pklcd *) so->so_pcb; + register int error = 0; if (req == PRU_CONTROL) - return (pk_control (so, (long)m, (caddr_t)nam, - (struct ifnet *)control)); - if (control && control -> m_len) { + return (pk_control(so, (long) m, (caddr_t) nam, + (struct ifnet *) control)); + if (control && control->m_len) { error = EINVAL; goto release; } @@ -94,357 +96,357 @@ struct mbuf *control; error = EINVAL; goto release; } - -/* - pk_trace (pkcbhead, TR_USER, (struct pklcd *)0, - req, (struct x25_packet *)0); -*/ + /* + pk_trace (pkcbhead, TR_USER, (struct pklcd *)0, + req, (struct x25_packet *)0); + */ switch (req) { - /* - * X.25 attaches to socket via PRU_ATTACH and allocates a logical - * channel descriptor. If the socket is to receive connections, - * then the LISTEN state is entered. - */ - case PRU_ATTACH: + /* + * X.25 attaches to socket via PRU_ATTACH and allocates a + * logical channel descriptor. If the socket is to receive + * connections, then the LISTEN state is entered. + */ + case PRU_ATTACH: if (lcp) { error = EISCONN; /* Socket already connected. */ break; } - lcp = pk_attach (so); + lcp = pk_attach(so); if (lcp == 0) error = ENOBUFS; break; - /* - * Detach a logical channel from the socket. If the state of the - * channel is embryonic, simply discard it. Otherwise we have to - * initiate a PRU_DISCONNECT which will finish later. - */ - case PRU_DETACH: - pk_disconnect (lcp); + /* + * Detach a logical channel from the socket. If the state of + * the channel is embryonic, simply discard it. Otherwise we + * have to initiate a PRU_DISCONNECT which will finish later. + */ + case PRU_DETACH: + pk_disconnect(lcp); break; - /* - * Give the socket an address. - */ - case PRU_BIND: - if (nam -> m_len == sizeof (struct x25_sockaddr)) - old_to_new (nam); - error = pk_bind (lcp, nam); + /* + * Give the socket an address. + */ + case PRU_BIND: + if (nam->m_len == sizeof(struct x25_sockaddr)) + old_to_new(nam); + error = pk_bind(lcp, nam); break; - /* - * Prepare to accept connections. - */ - case PRU_LISTEN: - error = pk_listen (lcp); + /* + * Prepare to accept connections. + */ + case PRU_LISTEN: + error = pk_listen(lcp); break; - /* - * Initiate a CALL REQUEST to peer entity. Enter state SENT_CALL - * and mark the socket as connecting. Set timer waiting for - * CALL ACCEPT or CLEAR. - */ - case PRU_CONNECT: - if (nam -> m_len == sizeof (struct x25_sockaddr)) - old_to_new (nam); - if (pk_checksockaddr (nam)) + /* + * Initiate a CALL REQUEST to peer entity. Enter state + * SENT_CALL and mark the socket as connecting. Set timer + * waiting for CALL ACCEPT or CLEAR. + */ + case PRU_CONNECT: + if (nam->m_len == sizeof(struct x25_sockaddr)) + old_to_new(nam); + if (pk_checksockaddr(nam)) return (EINVAL); - error = pk_connect (lcp, mtod (nam, struct sockaddr_x25 *)); + error = pk_connect(lcp, mtod(nam, struct sockaddr_x25 *)); break; - /* - * Initiate a disconnect to peer entity via a CLEAR REQUEST packet. - * The socket will be disconnected when we receive a confirmation - * or a clear collision. - */ - case PRU_DISCONNECT: - pk_disconnect (lcp); + /* + * Initiate a disconnect to peer entity via a CLEAR REQUEST + * packet. The socket will be disconnected when we receive a + * confirmation or a clear collision. + */ + case PRU_DISCONNECT: + pk_disconnect(lcp); break; - /* - * Accept an INCOMING CALL. Most of the work has already been done - * by pk_input. Just return the callers address to the user. - */ - case PRU_ACCEPT: - if (lcp -> lcd_craddr == NULL) + /* + * Accept an INCOMING CALL. Most of the work has already been + * done by pk_input. Just return the callers address to the + * user. + */ + case PRU_ACCEPT: + if (lcp->lcd_craddr == NULL) break; - bcopy ((caddr_t)lcp -> lcd_craddr, mtod (nam, caddr_t), - sizeof (struct sockaddr_x25)); - nam -> m_len = sizeof (struct sockaddr_x25); - if (lcp -> lcd_flags & X25_OLDSOCKADDR) - new_to_old (nam); + bcopy((caddr_t) lcp->lcd_craddr, mtod(nam, caddr_t), + sizeof(struct sockaddr_x25)); + nam->m_len = sizeof(struct sockaddr_x25); + if (lcp->lcd_flags & X25_OLDSOCKADDR) + new_to_old(nam); break; - /* - * After a receive, we should send a RR. - */ - case PRU_RCVD: - pk_flowcontrol (lcp, /*sbspace (&so -> so_rcv) <= */ 0, 1); + /* + * After a receive, we should send a RR. + */ + case PRU_RCVD: + pk_flowcontrol(lcp, /* sbspace (&so -> so_rcv) <= */ 0, 1); break; - /* - * Send INTERRUPT packet. - */ - case PRU_SENDOOB: + /* + * Send INTERRUPT packet. + */ + case PRU_SENDOOB: if (m == 0) { MGETHDR(m, M_WAITOK, MT_OOBDATA); - m -> m_pkthdr.len = m -> m_len = 1; - *mtod (m, octet *) = 0; + m->m_pkthdr.len = m->m_len = 1; + *mtod(m, octet *) = 0; } - if (m -> m_pkthdr.len > 32) { - m_freem (m); + if (m->m_pkthdr.len > 32) { + m_freem(m); error = EMSGSIZE; break; } MCHTYPE(m, MT_OOBDATA); /* FALLTHROUGH */ - /* - * Do send by placing data on the socket output queue. - */ - case PRU_SEND: + /* + * Do send by placing data on the socket output queue. + */ + case PRU_SEND: if (control) { - register struct cmsghdr *ch = mtod (m, struct cmsghdr *); - control -> m_len -= sizeof (*ch); - control -> m_data += sizeof (*ch); - error = pk_ctloutput (PRCO_SETOPT, so, ch -> cmsg_level, - ch -> cmsg_type, &control); + register struct cmsghdr *ch = mtod(m, struct cmsghdr *); + control->m_len -= sizeof(*ch); + control->m_data += sizeof(*ch); + error = pk_ctloutput(PRCO_SETOPT, so, ch->cmsg_level, + ch->cmsg_type, &control); } if (error == 0 && m) - error = pk_send (lcp, m); + error = pk_send(m, lcp); break; - /* - * Abort a virtual circuit. For example all completed calls - * waiting acceptance. - */ - case PRU_ABORT: - pk_disconnect (lcp); + /* + * Abort a virtual circuit. For example all completed calls + * waiting acceptance. + */ + case PRU_ABORT: + pk_disconnect(lcp); break; - /* Begin unimplemented hooks. */ + /* Begin unimplemented hooks. */ - case PRU_SHUTDOWN: + case PRU_SHUTDOWN: error = EOPNOTSUPP; break; - case PRU_CONTROL: + case PRU_CONTROL: error = EOPNOTSUPP; break; - case PRU_SENSE: + case PRU_SENSE: #ifdef BSD4_3 - ((struct stat *)m) -> st_blksize = so -> so_snd.sb_hiwat; + ((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat; #else error = EOPNOTSUPP; #endif break; - /* End unimplemented hooks. */ + /* End unimplemented hooks. */ - case PRU_SOCKADDR: - if (lcp -> lcd_ceaddr == 0) + case PRU_SOCKADDR: + if (lcp->lcd_ceaddr == 0) return (EADDRNOTAVAIL); - nam -> m_len = sizeof (struct sockaddr_x25); - bcopy ((caddr_t)lcp -> lcd_ceaddr, mtod (nam, caddr_t), - sizeof (struct sockaddr_x25)); - if (lcp -> lcd_flags & X25_OLDSOCKADDR) - new_to_old (nam); + nam->m_len = sizeof(struct sockaddr_x25); + bcopy((caddr_t) lcp->lcd_ceaddr, mtod(nam, caddr_t), + sizeof(struct sockaddr_x25)); + if (lcp->lcd_flags & X25_OLDSOCKADDR) + new_to_old(nam); break; case PRU_PEERADDR: - if (lcp -> lcd_state != DATA_TRANSFER) + if (lcp->lcd_state != DATA_TRANSFER) return (ENOTCONN); - nam -> m_len = sizeof (struct sockaddr_x25); - bcopy (lcp -> lcd_craddr ? (caddr_t)lcp -> lcd_craddr : - (caddr_t)lcp -> lcd_ceaddr, - mtod (nam, caddr_t), sizeof (struct sockaddr_x25)); - if (lcp -> lcd_flags & X25_OLDSOCKADDR) - new_to_old (nam); + nam->m_len = sizeof(struct sockaddr_x25); + bcopy(lcp->lcd_craddr ? (caddr_t) lcp->lcd_craddr : + (caddr_t) lcp->lcd_ceaddr, + mtod(nam, caddr_t), sizeof(struct sockaddr_x25)); + if (lcp->lcd_flags & X25_OLDSOCKADDR) + new_to_old(nam); break; - /* - * Receive INTERRUPT packet. - */ - case PRU_RCVOOB: - if (so -> so_options & SO_OOBINLINE) { - register struct mbuf *n = so -> so_rcv.sb_mb; - if (n && n -> m_type == MT_OOBDATA) { - unsigned len = n -> m_pkthdr.len; - so -> so_rcv.sb_mb = n -> m_nextpkt; - if (len != n -> m_len && - (n = m_pullup (n, len)) == 0) + /* + * Receive INTERRUPT packet. + */ + case PRU_RCVOOB: + if (so->so_options & SO_OOBINLINE) { + register struct mbuf *n = so->so_rcv.sb_mb; + if (n && n->m_type == MT_OOBDATA) { + unsigned len = n->m_pkthdr.len; + so->so_rcv.sb_mb = n->m_nextpkt; + if (len != n->m_len && + (n = m_pullup(n, len)) == 0) break; - m -> m_len = len; - bcopy (mtod (m, caddr_t), mtod (n, caddr_t), len); - m_freem (n); + m->m_len = len; + bcopy(mtod(m, caddr_t), mtod(n, caddr_t), len); + m_freem(n); } break; } - m -> m_len = 1; - *mtod (m, char *) = lcp -> lcd_intrdata; + m->m_len = 1; + *mtod(m, char *) = lcp->lcd_intrdata; break; - default: - panic ("pk_usrreq"); + default: + panic("pk_usrreq"); } release: if (control != NULL) - m_freem (control); + m_freem(control); return (error); } -/* - * If you want to use UBC X.25 level 3 in conjunction with some - * other X.25 level 2 driver, have the ifp -> if_ioctl routine - * assign pk_start to ia -> ia_start when called with SIOCSIFCONF_X25. +/* + * If you want to use UBC X.25 level 3 in conjunction with some other X.25 + * level 2 driver, have the ifp -> if_ioctl routine assign pk_start to ia -> + * ia_start when called with SIOCSIFCONF_X25. */ /* ARGSUSED */ -pk_start (lcp) -register struct pklcd *lcp; +int +pk_start(lcp) + register struct pklcd *lcp; { - pk_output (lcp); - return (0); /* XXX pk_output should return a value */ + pk_output(lcp); + return (0); /* XXX pk_output should return a value */ } #ifndef _offsetof #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m)) #endif struct sockaddr_x25 pk_sockmask = { - _offsetof(struct sockaddr_x25, x25_addr[0]), /* x25_len */ - 0, /* x25_family */ - -1, /* x25_net id */ + _offsetof(struct sockaddr_x25, x25_addr[0]), /* x25_len */ + 0, /* x25_family */ + -1, /* x25_net id */ }; -/*ARGSUSED*/ -pk_control (so, cmd, data, ifp) -struct socket *so; -u_long cmd; -caddr_t data; -register struct ifnet *ifp; +/* ARGSUSED */ +int +pk_control(so, cmd, data, ifp) + struct socket *so; + u_long cmd; + caddr_t data; + register struct ifnet *ifp; { - register struct ifreq_x25 *ifr = (struct ifreq_x25 *)data; + register struct ifreq_x25 *ifr = (struct ifreq_x25 *) data; register struct ifaddr *ifa = 0; register struct x25_ifaddr *ia = 0; - struct pklcd *dev_lcp = 0; - int error, s, old_maxlcn; - unsigned n; + int error = 0, s, old_maxlcn; /* * Find address for this interface, if it exists. */ if (ifp) for (ifa = ifp->if_addrlist.tqh_first; ifa != 0; - ifa = ifa->ifa_list.tqe_next) + ifa = ifa->ifa_list.tqe_next) if (ifa->ifa_addr->sa_family == AF_CCITT) break; - ia = (struct x25_ifaddr *)ifa; + ia = (struct x25_ifaddr *) ifa; switch (cmd) { case SIOCGIFCONF_X25: if (ifa == 0) return (EADDRNOTAVAIL); - ifr -> ifr_xc = ia -> ia_xc; + ifr->ifr_xc = ia->ia_xc; return (0); case SIOCSIFCONF_X25: if ((so->so_state & SS_PRIV) == 0) return (EPERM); if (ifp == 0) - panic ("pk_control"); - if (ifa == (struct ifaddr *)0) { - register struct mbuf *m; - - MALLOC(ia, struct x25_ifaddr *, sizeof (*ia), - M_IFADDR, M_WAITOK); + panic("pk_control"); + if (ifa == (struct ifaddr *) 0) { + MALLOC(ia, struct x25_ifaddr *, sizeof(*ia), + M_IFADDR, M_WAITOK); if (ia == 0) return (ENOBUFS); - bzero ((caddr_t)ia, sizeof (*ia)); + bzero((caddr_t) ia, sizeof(*ia)); TAILQ_INSERT_TAIL(&ifp->if_addrlist, &ia->ia_ifa, - ifa_list); - ifa = &ia -> ia_ifa; - ifa -> ifa_netmask = (struct sockaddr *)&pk_sockmask; - ifa -> ifa_addr = (struct sockaddr *)&ia -> ia_xc.xc_addr; - ifa -> ifa_dstaddr = (struct sockaddr *)&ia -> ia_dstaddr; /* XXX */ - ia -> ia_ifp = ifp; - ia -> ia_dstaddr.x25_family = AF_CCITT; - ia -> ia_dstaddr.x25_len = pk_sockmask.x25_len; + ifa_list); + ifa = &ia->ia_ifa; + ifa->ifa_netmask = (struct sockaddr *) & pk_sockmask; + ifa->ifa_addr = (struct sockaddr *) & ia->ia_xc.xc_addr; + ifa->ifa_dstaddr = (struct sockaddr *) & ia->ia_dstaddr; /* XXX */ + ia->ia_ifp = ifp; + ia->ia_dstaddr.x25_family = AF_CCITT; + ia->ia_dstaddr.x25_len = pk_sockmask.x25_len; } else if (ISISO8802(ifp) == 0) { - rtinit (ifa, (int)RTM_DELETE, 0); + rtinit(ifa, (int) RTM_DELETE, 0); } - old_maxlcn = ia -> ia_maxlcn; - ia -> ia_xc = ifr -> ifr_xc; - ia -> ia_dstaddr.x25_net = ia -> ia_xc.xc_addr.x25_net; - if (ia -> ia_maxlcn != old_maxlcn && old_maxlcn != 0) { + old_maxlcn = ia->ia_maxlcn; + ia->ia_xc = ifr->ifr_xc; + ia->ia_dstaddr.x25_net = ia->ia_xc.xc_addr.x25_net; + if (ia->ia_maxlcn != old_maxlcn && old_maxlcn != 0) { /* VERY messy XXX */ register struct pkcb *pkp; FOR_ALL_PKCBS(pkp) - if (pkp -> pk_ia == ia) - pk_resize (pkp); + if (pkp->pk_ia == ia) + pk_resize(pkp); } /* * Give the interface a chance to initialize if this p * is its first address, and to validate the address. */ - ia -> ia_start = pk_start; + ia->ia_start = pk_start; s = splimp(); - if (ifp -> if_ioctl) - error = (*ifp -> if_ioctl)(ifp, SIOCSIFCONF_X25, - (caddr_t) ifa); + if (ifp->if_ioctl) + error = (*ifp->if_ioctl) (ifp, SIOCSIFCONF_X25, + (caddr_t) ifa); if (error) - ifp -> if_flags &= ~IFF_UP; + ifp->if_flags &= ~IFF_UP; else if (ISISO8802(ifp) == 0) - error = rtinit (ifa, (int)RTM_ADD, RTF_UP); - splx (s); + error = rtinit(ifa, (int) RTM_ADD, RTF_UP); + splx(s); return (error); default: - if (ifp == 0 || ifp -> if_ioctl == 0) + if (ifp == 0 || ifp->if_ioctl == 0) return (EOPNOTSUPP); - return ((*ifp -> if_ioctl)(ifp, cmd, data)); + return ((*ifp->if_ioctl) (ifp, cmd, data)); } } -pk_ctloutput (cmd, so, level, optname, mp) -struct socket *so; -struct mbuf **mp; -int cmd, level, optname; +int +pk_ctloutput(cmd, so, level, optname, mp) + struct socket *so; + struct mbuf **mp; + int cmd, level, optname; { register struct mbuf *m = *mp; - register struct pklcd *lcp = (struct pklcd *) so -> so_pcb; - int error = EOPNOTSUPP; + register struct pklcd *lcp = (struct pklcd *) so->so_pcb; + int error = EOPNOTSUPP; if (m == 0) return (EINVAL); - if (cmd == PRCO_SETOPT) switch (optname) { - case PK_FACILITIES: - if (m == 0) - return (EINVAL); - lcp -> lcd_facilities = m; - *mp = 0; - return (0); + if (cmd == PRCO_SETOPT) + switch (optname) { + case PK_FACILITIES: + if (m == 0) + return (EINVAL); + lcp->lcd_facilities = m; + *mp = 0; + return (0); + + case PK_ACCTFILE: + if ((so->so_state & SS_PRIV) == 0) + error = EPERM; + else if (m->m_len) + error = pk_accton(mtod(m, char *)); + else + error = pk_accton((char *) 0); + break; - case PK_ACCTFILE: - if ((so->so_state & SS_PRIV) == 0) - error = EPERM; - else if (m -> m_len) - error = pk_accton (mtod (m, char *)); - else - error = pk_accton ((char *)0); - break; + case PK_RTATTACH: + error = pk_rtattach(so, m); + break; - case PK_RTATTACH: - error = pk_rtattach (so, m); - break; - - case PK_PRLISTEN: - error = pk_user_protolisten (mtod (m, u_char *)); - } + case PK_PRLISTEN: + error = pk_user_protolisten(mtod(m, u_char *)); + } if (*mp) { - (void) m_freem (*mp); + (void) m_freem(*mp); *mp = 0; } return (error); @@ -457,41 +459,41 @@ int cmd, level, optname; * socket address to the new style */ -static -old_to_new (m) -register struct mbuf *m; +static void +old_to_new(m) + register struct mbuf *m; { register struct x25_sockaddr *oldp; register struct sockaddr_x25 *newp; - register char *ocp, *ncp; + register char *ocp, *ncp; struct sockaddr_x25 new; - oldp = mtod (m, struct x25_sockaddr *); + oldp = mtod(m, struct x25_sockaddr *); newp = &new; - bzero ((caddr_t)newp, sizeof (*newp)); + bzero((caddr_t) newp, sizeof(*newp)); - newp -> x25_family = AF_CCITT; - newp -> x25_len = sizeof(*newp); - newp -> x25_opts.op_flags = (oldp -> xaddr_facilities & X25_REVERSE_CHARGE) + newp->x25_family = AF_CCITT; + newp->x25_len = sizeof(*newp); + newp->x25_opts.op_flags = (oldp->xaddr_facilities & X25_REVERSE_CHARGE) | X25_MQBIT | X25_OLDSOCKADDR; - if (oldp -> xaddr_facilities & XS_HIPRIO) /* Datapac specific */ - newp -> x25_opts.op_psize = X25_PS128; - bcopy ((caddr_t)oldp -> xaddr_addr, newp -> x25_addr, - (unsigned)min (oldp -> xaddr_len, sizeof (newp -> x25_addr) - 1)); - if (bcmp ((caddr_t)oldp -> xaddr_proto, newp -> x25_udata, 4) != 0) { - bcopy ((caddr_t)oldp -> xaddr_proto, newp -> x25_udata, 4); - newp -> x25_udlen = 4; + if (oldp->xaddr_facilities & XS_HIPRIO) /* Datapac specific */ + newp->x25_opts.op_psize = X25_PS128; + bcopy((caddr_t) oldp->xaddr_addr, newp->x25_addr, + (unsigned) min(oldp->xaddr_len, sizeof(newp->x25_addr) - 1)); + if (bcmp((caddr_t) oldp->xaddr_proto, newp->x25_udata, 4) != 0) { + bcopy((caddr_t) oldp->xaddr_proto, newp->x25_udata, 4); + newp->x25_udlen = 4; } - ocp = (caddr_t)oldp -> xaddr_userdata; - ncp = newp -> x25_udata + 4; - while (*ocp && ocp < (caddr_t)oldp -> xaddr_userdata + 12) { - if (newp -> x25_udlen == 0) - newp -> x25_udlen = 4; + ocp = (caddr_t) oldp->xaddr_userdata; + ncp = newp->x25_udata + 4; + while (*ocp && ocp < (caddr_t) oldp->xaddr_userdata + 12) { + if (newp->x25_udlen == 0) + newp->x25_udlen = 4; *ncp++ = *ocp++; - newp -> x25_udlen++; + newp->x25_udlen++; } - bcopy ((caddr_t)newp, mtod (m, char *), sizeof (*newp)); - m -> m_len = sizeof (*newp); + bcopy((caddr_t) newp, mtod(m, char *), sizeof(*newp)); + m->m_len = sizeof(*newp); } /* @@ -499,81 +501,84 @@ register struct mbuf *m; * socket address to the old style */ -static -new_to_old (m) -register struct mbuf *m; +static void +new_to_old(m) + register struct mbuf *m; { register struct x25_sockaddr *oldp; register struct sockaddr_x25 *newp; - register char *ocp, *ncp; + register char *ocp, *ncp; struct x25_sockaddr old; oldp = &old; - newp = mtod (m, struct sockaddr_x25 *); - bzero ((caddr_t)oldp, sizeof (*oldp)); - - oldp -> xaddr_facilities = newp -> x25_opts.op_flags & X25_REVERSE_CHARGE; - if (newp -> x25_opts.op_psize == X25_PS128) - oldp -> xaddr_facilities |= XS_HIPRIO; /* Datapac specific */ - ocp = (char *)oldp -> xaddr_addr; - ncp = newp -> x25_addr; + newp = mtod(m, struct sockaddr_x25 *); + bzero((caddr_t) oldp, sizeof(*oldp)); + + oldp->xaddr_facilities = newp->x25_opts.op_flags & X25_REVERSE_CHARGE; + if (newp->x25_opts.op_psize == X25_PS128) + oldp->xaddr_facilities |= XS_HIPRIO; /* Datapac specific */ + ocp = (char *) oldp->xaddr_addr; + ncp = newp->x25_addr; while (*ncp) { *ocp++ = *ncp++; - oldp -> xaddr_len++; + oldp->xaddr_len++; } - bcopy (newp -> x25_udata, (caddr_t)oldp -> xaddr_proto, 4); - if (newp -> x25_udlen > 4) - bcopy (newp -> x25_udata + 4, (caddr_t)oldp -> xaddr_userdata, - (unsigned)(newp -> x25_udlen - 4)); + bcopy(newp->x25_udata, (caddr_t) oldp->xaddr_proto, 4); + if (newp->x25_udlen > 4) + bcopy(newp->x25_udata + 4, (caddr_t) oldp->xaddr_userdata, + (unsigned) (newp->x25_udlen - 4)); - bcopy ((caddr_t)oldp, mtod (m, char *), sizeof (*oldp)); - m -> m_len = sizeof (*oldp); + bcopy((caddr_t) oldp, mtod(m, char *), sizeof(*oldp)); + m->m_len = sizeof(*oldp); } -pk_checksockaddr (m) -struct mbuf *m; +int +pk_checksockaddr(m) + struct mbuf *m; { - register struct sockaddr_x25 *sa = mtod (m, struct sockaddr_x25 *); - register char *cp; + register struct sockaddr_x25 *sa = mtod(m, struct sockaddr_x25 *); + register char *cp; - if (m -> m_len != sizeof (struct sockaddr_x25)) + if (m->m_len != sizeof(struct sockaddr_x25)) return (1); - if (sa -> x25_family != AF_CCITT || - sa -> x25_udlen > sizeof (sa -> x25_udata)) + if (sa->x25_family != AF_CCITT || + sa->x25_udlen > sizeof(sa->x25_udata)) return (1); - for (cp = sa -> x25_addr; *cp; cp++) { + for (cp = sa->x25_addr; *cp; cp++) { if (*cp < '0' || *cp > '9' || - cp >= &sa -> x25_addr[sizeof (sa -> x25_addr) - 1]) + cp >= &sa->x25_addr[sizeof(sa->x25_addr) - 1]) return (1); } return (0); } -pk_send (lcp, m) -struct pklcd *lcp; -register struct mbuf *m; +int +pk_send(m, v) + register struct mbuf *m; + void *v; { - int mqbit = 0, error = 0; + struct pklcd *lcp = v; + int mqbit = 0, error = 0; register struct x25_packet *xp; register struct socket *so; - if (m -> m_type == MT_OOBDATA) { - if (lcp -> lcd_intrconf_pending) + if (m->m_type == MT_OOBDATA) { + if (lcp->lcd_intrconf_pending) error = ETOOMANYREFS; - if (m -> m_pkthdr.len > 32) + if (m->m_pkthdr.len > 32) error = EMSGSIZE; M_PREPEND(m, PKHEADERLN, M_WAITOK); if (m == 0 || error) goto bad; - *(mtod (m, octet *)) = 0; - xp = mtod (m, struct x25_packet *); - X25SBITS(xp -> bits, fmt_identifier, 1); - xp -> packet_type = X25_INTERRUPT; - SET_LCN(xp, lcp -> lcd_lcn); - sbinsertoob ( (so = lcp -> lcd_so) ? - &so -> so_snd : &lcp -> lcd_sb, m); + *(mtod(m, octet *)) = 0; + xp = mtod(m, struct x25_packet *); + X25SBITS(xp->bits, fmt_identifier, 1); + xp->packet_type = X25_INTERRUPT; + SET_LCN(xp, lcp->lcd_lcn); + sbinsertoob((so = lcp->lcd_so) ? + &so->so_snd : &lcp->lcd_sb, m); goto send; } /* @@ -581,23 +586,23 @@ register struct mbuf *m; * a control byte to each packet written indicating m-bit * and q-bit status. Examine and then discard this byte. */ - if (lcp -> lcd_flags & X25_MQBIT) { - if (m -> m_len < 1) { - m_freem (m); + if (lcp->lcd_flags & X25_MQBIT) { + if (m->m_len < 1) { + m_freem(m); return (EMSGSIZE); } - mqbit = *(mtod (m, u_char *)); - m -> m_len--; - m -> m_data++; - m -> m_pkthdr.len--; + mqbit = *(mtod(m, u_char *)); + m->m_len--; + m->m_data++; + m->m_pkthdr.len--; } - error = pk_fragment (lcp, m, mqbit & 0x80, mqbit & 0x40, 1); + error = pk_fragment(lcp, m, mqbit & 0x80, mqbit & 0x40, 1); send: - if (error == 0 && lcp -> lcd_state == DATA_TRANSFER) - lcp -> lcd_send (lcp); /* XXXXXXXXX fix pk_output!!! */ + if (error == 0 && lcp->lcd_state == DATA_TRANSFER) + lcp->lcd_send(lcp); /* XXXXXXXXX fix pk_output!!! */ return (error); bad: if (m) - m_freem (m); + m_freem(m); return (error); } diff --git a/sys/netccitt/pk_var.h b/sys/netccitt/pk_var.h index 2b87135c0c3..211694eaf1b 100644 --- a/sys/netccitt/pk_var.h +++ b/sys/netccitt/pk_var.h @@ -1,4 +1,5 @@ -/* $NetBSD: pk_var.h,v 1.7 1995/06/13 09:07:37 mycroft Exp $ */ +/* $OpenBSD: pk_var.h,v 1.2 1996/03/04 07:36:48 niklas Exp $ */ +/* $NetBSD: pk_var.h,v 1.8 1996/02/13 22:05:47 christos Exp $ */ /* * Copyright (c) Computing Centre, University of British Columbia, 1985 @@ -54,9 +55,11 @@ struct pklcd { struct pklcd_q *q_forw; /* debugging chain */ struct pklcd_q *q_back; /* debugging chain */ } lcd_q; - int (*lcd_upper)(); /* switch to socket vs datagram vs ...*/ + int (*lcd_upper) /* switch to socket vs datagram vs ...*/ + __P((struct mbuf *, void *)); caddr_t lcd_upnext; /* reference for lcd_upper() */ - int (*lcd_send)(); /* if X.25 front end, direct connect */ + void (*lcd_send) /* if X.25 front end, direct connect */ + __P((struct pklcd *)); caddr_t lcd_downnext; /* reference for lcd_send() */ short lcd_lcn; /* Logical channel number */ short lcd_state; /* Logical Channel state */ @@ -107,9 +110,11 @@ struct pkcb { struct pkcb_q *q_backw; } pk_q; short pk_state; /* packet level status */ - short pk_maxlcn; /* local copy of xc_maxlcn */ - int (*pk_lloutput) (); /* link level output procedure */ - caddr_t (*pk_llctlinput) (); /* link level ctloutput procedure */ + u_short pk_maxlcn; /* local copy of xc_maxlcn */ + int (*pk_lloutput) /* link level output procedure */ + __P((struct mbuf *, ...)); + void *(*pk_llctlinput) /* link level ctloutput procedure */ + __P((int, struct sockaddr *, void *)); caddr_t pk_llnext; /* handle for next level down */ struct x25config *pk_xcp; /* network specific configuration */ struct x25_ifaddr *pk_ia; /* backpointer to ifaddr */ @@ -141,7 +146,8 @@ struct x25_ifaddr { struct x25config ia_xc; /* network specific configuration */ struct pkcb *ia_pkcb; #define ia_maxlcn ia_xc.xc_maxlcn - int (*ia_start) (); /* connect, confirm method */ + int (*ia_start) /* connect, confirm method */ + __P((struct pklcd *)); struct sockaddr_x25 ia_dstaddr; /* reserve space for route dst */ }; @@ -225,7 +231,6 @@ struct mbuf_cache { #if defined(_KERNEL) && defined(CCITT) extern struct pkcb_q pkcb_q; struct pklcd *pk_listenhead; -struct pklcd *pk_attach(); extern char *pk_name[], *pk_state[]; int pk_t20, pk_t21, pk_t22, pk_t23; diff --git a/sys/netccitt/x25.h b/sys/netccitt/x25.h index b63545d964c..b1aa563b7ab 100644 --- a/sys/netccitt/x25.h +++ b/sys/netccitt/x25.h @@ -1,4 +1,5 @@ -/* $NetBSD: x25.h,v 1.6 1995/03/26 20:33:46 jtc Exp $ */ +/* $OpenBSD: x25.h,v 1.2 1996/03/04 07:36:49 niklas Exp $ */ +/* $NetBSD: x25.h,v 1.7 1996/02/13 22:05:51 christos Exp $ */ /* * Copyright (c) University of British Columbia, 1984 @@ -157,3 +158,27 @@ struct ifreq_x25 { #define SIOCSIFCONF_X25 _IOW('i', 12, struct ifreq_x25) /* set ifnet config */ #define SIOCGIFCONF_X25 _IOWR('i',13, struct ifreq_x25) /* get ifnet config */ #endif + +#ifdef _KERNEL +struct llinfo_x25; +struct pklcd; +struct sockaddr_in; +struct x25_ifaddr; +struct ifnet; +struct rtentry; + +void x25_lxfree __P((struct llinfo_x25 *)); +int x25_ifinput __P((struct mbuf *, void *)); +int x25_connect_callback __P((struct mbuf *, void *)); +int x25_dgram_incoming __P((struct mbuf *, void *)); +int x25_ifoutput __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *)); +void x25_iftimeout __P((struct ifnet *)); +void x25_rtrequest __P((int , struct rtentry *, struct sockaddr *)); +void x25_rtinvert __P((int , struct sockaddr *, struct rtentry *)); +void x25_ddnip_to_ccitt __P((struct sockaddr *, struct rtentry *)); +void x25_dg_rtinit __P((struct sockaddr_x25 *, struct x25_ifaddr *, int )); +void pk_init __P((void)); +int pk_user_protolisten __P((u_char *)); +int pk_rtattach __P((struct socket *, struct mbuf *)); +int x25_rtattach __P((struct pklcd *, struct rtentry *)); +#endif