2001-11-13 03:12:56 +03:00
|
|
|
/* $NetBSD: hd_subr.c,v 1.15 2001/11/13 00:12:57 lukem Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1998-09-13 20:21:16 +04:00
|
|
|
* Copyright (c) 1984 University of British Columbia.
|
1994-05-13 10:02:48 +04:00
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Laboratory for Computation Vision and the Computer Science Department
|
|
|
|
* of the University of British Columbia.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-06-29 10:29:24 +04:00
|
|
|
* @(#)hd_subr.c 8.1 (Berkeley) 6/10/93
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 03:12:56 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: hd_subr.c,v 1.15 2001/11/13 00:12:57 lukem Exp $");
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/socket.h>
|
1994-05-13 10:02:48 +04:00
|
|
|
#include <sys/socketvar.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netccitt/hdlc.h>
|
|
|
|
#include <netccitt/hd_var.h>
|
|
|
|
#include <netccitt/x25.h>
|
1994-05-13 10:02:48 +04:00
|
|
|
#include <netccitt/pk_var.h>
|
1996-02-14 01:04:21 +03:00
|
|
|
#include <netccitt/pk_extern.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
hd_init()
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
hdintrq.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void *
|
|
|
|
hd_ctlinput(prc, addr, ext)
|
|
|
|
int prc;
|
|
|
|
struct sockaddr *addr;
|
|
|
|
void *ext;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 17:53:32 +04:00
|
|
|
struct x25config *xcp = (struct x25config *) addr;
|
|
|
|
struct hdcb *hdp;
|
|
|
|
struct ifaddr *ifa;
|
1996-02-14 01:04:21 +03:00
|
|
|
struct ifnet *ifp;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (addr->sa_family != AF_CCITT)
|
1996-02-14 01:04:21 +03:00
|
|
|
return (void *) (EAFNOSUPPORT);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (xcp->xc_lptype != HDLCPROTO_LAPB)
|
1996-02-14 01:04:21 +03:00
|
|
|
return (void *) (EPROTONOSUPPORT);
|
1993-04-09 16:00:07 +04:00
|
|
|
ifa = ifa_ifwithaddr(addr);
|
|
|
|
if (ifa == 0 || ifa->ifa_addr->sa_family != AF_CCITT ||
|
|
|
|
(ifp = ifa->ifa_ifp) == 0)
|
1996-02-14 01:04:21 +03:00
|
|
|
panic("hd_ctlinput");
|
1993-04-09 16:00:07 +04:00
|
|
|
for (hdp = hdcbhead; hdp; hdp = hdp->hd_next)
|
|
|
|
if (hdp->hd_ifp == ifp)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (hdp == 0) { /* new interface */
|
|
|
|
|
|
|
|
/* an hdcb is now too big to fit in an mbuf */
|
1996-02-14 01:04:21 +03:00
|
|
|
MALLOC(hdp, struct hdcb *, sizeof(*hdp), M_PCB, M_DONTWAIT);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (hdp == 0)
|
1996-02-14 01:04:21 +03:00
|
|
|
return (void *) (ENOBUFS);
|
|
|
|
bzero((caddr_t) hdp, sizeof(*hdp));
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_pkp =
|
1996-02-14 01:04:21 +03:00
|
|
|
(caddr_t) pk_newlink((struct x25_ifaddr *) ifa,
|
|
|
|
(caddr_t) hdp);
|
|
|
|
((struct x25_ifaddr *) ifa)->ia_pkcb =
|
1994-05-13 10:02:48 +04:00
|
|
|
(struct pkcb *) hdp->hd_pkp;
|
1996-02-14 01:04:21 +03:00
|
|
|
if (hdp->hd_pkp == 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
free(hdp, M_PCB);
|
1996-02-14 01:04:21 +03:00
|
|
|
return (void *) (ENOBUFS);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
hdp->hd_ifp = ifp;
|
2000-02-02 01:52:04 +03:00
|
|
|
IFAREF(ifa);
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_ifa = ifa;
|
|
|
|
hdp->hd_xcp = xcp;
|
|
|
|
hdp->hd_state = INIT;
|
|
|
|
hdp->hd_output = hd_ifoutput;
|
|
|
|
hdp->hd_next = hdcbhead;
|
|
|
|
hdcbhead = hdp;
|
1996-02-14 01:04:21 +03:00
|
|
|
} else if (hdp->hd_pkp == 0) { /* interface got reconfigured */
|
1994-05-13 10:02:48 +04:00
|
|
|
hdp->hd_pkp =
|
1996-02-14 01:04:21 +03:00
|
|
|
(caddr_t) pk_newlink((struct x25_ifaddr *) ifa,
|
|
|
|
(caddr_t) hdp);
|
|
|
|
((struct x25_ifaddr *) ifa)->ia_pkcb =
|
1994-05-13 10:02:48 +04:00
|
|
|
(struct pkcb *) hdp->hd_pkp;
|
1996-02-14 01:04:21 +03:00
|
|
|
if (hdp->hd_pkp == 0) {
|
1994-05-13 10:02:48 +04:00
|
|
|
free(hdp, M_PCB);
|
1996-02-14 01:04:21 +03:00
|
|
|
return (void *) (ENOBUFS);
|
1994-05-13 10:02:48 +04:00
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
switch (prc) {
|
|
|
|
case PRC_IFUP:
|
|
|
|
if (xcp->xc_lwsize == 0 ||
|
1996-02-14 01:04:21 +03:00
|
|
|
xcp->xc_lwsize > MAX_WINDOW_SIZE)
|
|
|
|
xcp->xc_lwsize = MAX_WINDOW_SIZE;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (hdp->hd_state == INIT)
|
1996-02-14 01:04:21 +03:00
|
|
|
SET_TIMER(hdp);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRC_IFDOWN:
|
|
|
|
if (hdp->hd_state == ABM)
|
1996-02-14 01:04:21 +03:00
|
|
|
hd_message(hdp, "Operator shutdown: link closed");
|
|
|
|
(void) pk_ctlinput(PRC_LINKDOWN,
|
|
|
|
(struct sockaddr *) hdp->hd_pkp, NULL);
|
1994-05-13 10:02:48 +04:00
|
|
|
|
|
|
|
/* fall thru to ... */
|
|
|
|
|
|
|
|
case PRC_DISCONNECT_REQUEST:
|
|
|
|
/* drop reference to pkcb --- it's dead meat */
|
|
|
|
hdp->hd_pkp = (caddr_t) 0;
|
1996-02-14 01:04:21 +03:00
|
|
|
((struct x25_ifaddr *) ifa)->ia_pkcb = (struct pkcb *) 0;
|
1994-05-13 10:02:48 +04:00
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
hd_writeinternal(hdp, DISC, POLLON);
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_state = DISC_SENT;
|
1996-02-14 01:04:21 +03:00
|
|
|
SET_TIMER(hdp);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:04:21 +03:00
|
|
|
return (void *) (0);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
hd_initvars(hdp)
|
2000-03-30 17:53:32 +04:00
|
|
|
struct hdcb *hdp;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 17:53:32 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
int i;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* Clear Transmit queue. */
|
1996-02-14 01:04:21 +03:00
|
|
|
while ((m = hd_remove(&hdp->hd_txq)) != NULL)
|
|
|
|
m_freem(m);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* Clear Retransmit queue. */
|
|
|
|
i = hdp->hd_lastrxnr;
|
|
|
|
while (i != hdp->hd_retxqi) {
|
1996-02-14 01:04:21 +03:00
|
|
|
m_freem(hdp->hd_retxq[i]);
|
1993-04-09 16:00:07 +04:00
|
|
|
i = (i + 1) % MODULUS;
|
|
|
|
}
|
|
|
|
hdp->hd_retxqi = 0;
|
|
|
|
|
|
|
|
hdp->hd_vs = hdp->hd_vr = 0;
|
|
|
|
hdp->hd_lasttxnr = hdp->hd_lastrxnr = 0;
|
|
|
|
hdp->hd_rrtimer = 0;
|
|
|
|
KILL_TIMER(hdp);
|
|
|
|
hdp->hd_retxcnt = 0;
|
|
|
|
hdp->hd_condition = 0;
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
int
|
|
|
|
hd_decode(hdp, frame)
|
2000-03-30 17:53:32 +04:00
|
|
|
struct hdcb *hdp;
|
1996-02-14 01:04:21 +03:00
|
|
|
struct Hdlc_frame *frame;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 17:53:32 +04:00
|
|
|
int frametype = ILLEGAL;
|
|
|
|
struct Hdlc_iframe *iframe = (struct Hdlc_iframe *) frame;
|
|
|
|
struct Hdlc_sframe *sframe = (struct Hdlc_sframe *) frame;
|
|
|
|
struct Hdlc_uframe *uframe = (struct Hdlc_uframe *) frame;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
if (iframe->hdlc_0 == 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = IFRAME;
|
|
|
|
hdp->hd_iframes_in++;
|
1996-02-14 01:04:21 +03:00
|
|
|
} else if (sframe->hdlc_01 == 1) {
|
1993-04-09 16:00:07 +04:00
|
|
|
/* Supervisory format. */
|
1996-02-14 01:04:21 +03:00
|
|
|
switch (sframe->s2) {
|
|
|
|
case 0:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = RR;
|
|
|
|
hdp->hd_rrs_in++;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case 1:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = RNR;
|
|
|
|
hdp->hd_rnrs_in++;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case 2:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = REJ;
|
|
|
|
hdp->hd_rejs_in++;
|
|
|
|
}
|
1996-02-14 01:04:21 +03:00
|
|
|
} else if (uframe->hdlc_11 == 3) {
|
1993-04-09 16:00:07 +04:00
|
|
|
/* Unnumbered format. */
|
1996-02-14 01:04:21 +03:00
|
|
|
switch (uframe->m3) {
|
|
|
|
case 0:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = DM;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case 1:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = SABM;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case 2:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = DISC;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case 3:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = UA;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case 4:
|
1993-04-09 16:00:07 +04:00
|
|
|
frametype = FRMR;
|
|
|
|
hdp->hd_frmrs_in++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (frametype);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
hd_writeinternal(hdp, frametype, pf)
|
2000-03-30 17:53:32 +04:00
|
|
|
struct hdcb *hdp;
|
|
|
|
int frametype, pf;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 17:53:32 +04:00
|
|
|
struct mbuf *buf;
|
1993-04-09 16:00:07 +04:00
|
|
|
struct Hdlc_frame *frame;
|
2000-03-30 17:53:32 +04:00
|
|
|
struct Hdlc_sframe *sframe;
|
|
|
|
struct Hdlc_uframe *uframe;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
MGETHDR(buf, M_DONTWAIT, MT_HEADER);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (buf == 0)
|
|
|
|
return;
|
1996-02-14 01:04:21 +03:00
|
|
|
frame = mtod(buf, struct Hdlc_frame *);
|
|
|
|
sframe = mtod(buf, struct Hdlc_sframe *);
|
|
|
|
uframe = mtod(buf, struct Hdlc_uframe *);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* Assume a response - address structure for DTE */
|
1996-02-14 01:04:21 +03:00
|
|
|
frame->address = ADDRESS_A;
|
|
|
|
buf->m_len = 2;
|
2001-10-19 00:17:24 +04:00
|
|
|
buf->m_nextpkt = buf->m_next = NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
switch (frametype) {
|
1996-02-14 01:04:21 +03:00
|
|
|
case RR:
|
|
|
|
frame->control = RR_CONTROL;
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_rrs_out++;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case RNR:
|
|
|
|
frame->control = RNR_CONTROL;
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_rnrs_out++;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case REJ:
|
|
|
|
frame->control = REJ_CONTROL;
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_rejs_out++;
|
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case SABM:
|
|
|
|
frame->control = SABM_CONTROL;
|
|
|
|
frame->address = ADDRESS_B;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case DISC:
|
1993-04-09 16:00:07 +04:00
|
|
|
if ((hdp->hd_ifp->if_flags & IFF_UP) == 0) {
|
|
|
|
hdp->hd_state = DISCONNECTED;
|
1996-02-14 01:04:21 +03:00
|
|
|
(void) m_freem(buf);
|
|
|
|
hd_flush(hdp->hd_ifp);
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
}
|
1996-02-14 01:04:21 +03:00
|
|
|
frame->control = DISC_CONTROL;
|
|
|
|
frame->address = ADDRESS_B;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case DM:
|
|
|
|
frame->control = DM_CONTROL;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case UA:
|
|
|
|
frame->control = UA_CONTROL;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case FRMR:
|
|
|
|
frame->control = FRMR_CONTROL;
|
|
|
|
bcopy((caddr_t) & hd_frmr, (caddr_t) frame->info, 3);
|
|
|
|
buf->m_len = 5;
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_frmrs_out++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
if (sframe->hdlc_01 == 1) {
|
1993-04-09 16:00:07 +04:00
|
|
|
/* Supervisory format - RR, REJ, or RNR. */
|
1996-02-14 01:04:21 +03:00
|
|
|
sframe->nr = hdp->hd_vr;
|
|
|
|
sframe->pf = pf;
|
1993-04-09 16:00:07 +04:00
|
|
|
hdp->hd_lasttxnr = hdp->hd_vr;
|
|
|
|
hdp->hd_rrtimer = 0;
|
1996-02-14 01:04:21 +03:00
|
|
|
} else
|
|
|
|
uframe->pf = pf;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1997-06-24 06:25:59 +04:00
|
|
|
hd_trace(hdp, TX, buf);
|
1996-02-14 01:04:21 +03:00
|
|
|
buf->m_pkthdr.len = buf->m_len;
|
|
|
|
(*hdp->hd_output) (buf, hdp, NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
1996-02-14 01:04:21 +03:00
|
|
|
hd_remove(q)
|
|
|
|
struct hdtxq *q;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 17:53:32 +04:00
|
|
|
struct mbuf *m;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
m = q->head;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (m) {
|
2001-10-19 00:17:24 +04:00
|
|
|
if ((q->head = m->m_nextpkt) == NULL)
|
1996-02-14 01:04:21 +03:00
|
|
|
q->tail = NULL;
|
2001-10-19 00:17:24 +04:00
|
|
|
m->m_nextpkt = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
hd_append(q, m)
|
2000-03-30 17:53:32 +04:00
|
|
|
struct hdtxq *q;
|
|
|
|
struct mbuf *m;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
|
2001-10-19 00:17:24 +04:00
|
|
|
m->m_nextpkt = NULL;
|
1996-02-14 01:04:21 +03:00
|
|
|
if (q->tail == NULL)
|
|
|
|
q->head = m;
|
1993-04-09 16:00:07 +04:00
|
|
|
else
|
2001-10-19 00:17:24 +04:00
|
|
|
q->tail->m_nextpkt = m;
|
1996-02-14 01:04:21 +03:00
|
|
|
q->tail = m;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
hd_flush(ifp)
|
|
|
|
struct ifnet *ifp;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 17:53:32 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
int s;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
while (1) {
|
2001-04-14 03:29:55 +04:00
|
|
|
s = splnet();
|
1996-02-14 01:04:21 +03:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
splx(s);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (m == 0)
|
|
|
|
break;
|
1996-02-14 01:04:21 +03:00
|
|
|
m_freem(m);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
hd_message(hdp, msg)
|
|
|
|
struct hdcb *hdp;
|
|
|
|
char *msg;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:04:21 +03:00
|
|
|
if (hdcbhead->hd_next)
|
1996-10-13 06:10:01 +04:00
|
|
|
printf("HDLC(%s): %s\n", format_ntn(hdp->hd_xcp), msg);
|
1993-04-09 16:00:07 +04:00
|
|
|
else
|
1996-10-13 06:10:01 +04:00
|
|
|
printf("HDLC: %s\n", msg);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HDLCDEBUG
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
hd_status(hdp)
|
|
|
|
struct hdcb *hdp;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-10-13 06:10:01 +04:00
|
|
|
printf("HDLC STATUS:\n V(S)=%d, V(R)=%d, retxqi=%d,\n",
|
1996-10-11 03:02:20 +04:00
|
|
|
hdp->hd_vs, hdp->hd_vr, hdp->hd_retxqi);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-10-13 06:10:01 +04:00
|
|
|
printf("Last_rx_nr=%d, Last_tx_nr=%d,\n Condition=%d, Xx=%d\n",
|
1996-10-11 03:02:20 +04:00
|
|
|
hdp->hd_lastrxnr, hdp->hd_lasttxnr, hdp->hd_condition, hdp->hd_xx);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
#endif
|