2000-03-14 02:52:25 +03:00
|
|
|
/* $NetBSD: pk_output.c,v 1.12 2000/03/13 23:52:40 soren 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.
|
|
|
|
* Copyright (c) 1992 Computer Science Department IV,
|
|
|
|
* University of Erlangen-Nuremberg, Germany.
|
|
|
|
* Copyright (c) 1991, 1992, 1993
|
1994-05-13 10:02:48 +04:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1994-05-13 10:02:48 +04:00
|
|
|
* This code is derived from software contributed to Berkeley by the
|
|
|
|
* Laboratory for Computation Vision and the Computer Science Department
|
2000-03-14 02:52:25 +03:00
|
|
|
* of the University of British Columbia and the Computer Science
|
1998-09-13 20:21:16 +04:00
|
|
|
* Department (IV) of the University of Erlangen-Nuremberg, Germany.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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
|
1998-09-13 20:21:16 +04:00
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
1993-04-09 16:00:07 +04:00
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
1998-09-13 20:21:16 +04:00
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
1993-04-09 16:00:07 +04:00
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)pk_output.c 8.2(Berkeley) 9/22/94
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/errno.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/x25.h>
|
|
|
|
#include <netccitt/pk.h>
|
|
|
|
#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
|
|
|
struct mbuf_cache pk_output_cache = {0}, pk_input_cache;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
void
|
|
|
|
pk_output(lcp)
|
|
|
|
register struct pklcd *lcp;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
register struct x25_packet *xp;
|
|
|
|
register struct mbuf *m;
|
1996-02-14 01:04:21 +03:00
|
|
|
register struct pkcb *pkp = lcp->lcd_pkp;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (lcp == 0 || pkp == 0) {
|
1996-10-13 06:10:01 +04:00
|
|
|
printf("pk_output: zero arg\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
}
|
1996-02-14 01:04:21 +03:00
|
|
|
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;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
/*
|
|
|
|
* Just set the state to allow packet to flow and send the
|
|
|
|
* confirmation.
|
|
|
|
*/
|
|
|
|
case PK_CALL_ACCEPTED + RECEIVED_CALL:
|
|
|
|
lcp->lcd_state = DATA_TRANSFER;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
1993-04-09 16:00:07 +04:00
|
|
|
/* fall through */
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case PK_CLEAR + SENT_CLEAR:
|
|
|
|
lcp->lcd_timer = pk_t23;
|
|
|
|
lcp->lcd_retry++;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case PK_CLEAR_CONF + RECEIVED_CLEAR:
|
|
|
|
case PK_CLEAR_CONF + SENT_CLEAR:
|
|
|
|
case PK_CLEAR_CONF + READY:
|
|
|
|
lcp->lcd_state = READY;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
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;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case PK_INTERRUPT + DATA_TRANSFER:
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef ancient_history
|
1996-02-14 01:04:21 +03:00
|
|
|
xp->packet_data = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
#endif
|
1996-02-14 01:04:21 +03:00
|
|
|
lcp->lcd_intrconf_pending = TRUE;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case PK_INTERRUPT_CONF + DATA_TRANSFER:
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
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;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case PK_RESET + DATA_TRANSFER:
|
|
|
|
lcp->lcd_reset_condition = TRUE;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
case PK_RESET_CONF + DATA_TRANSFER:
|
|
|
|
lcp->lcd_reset_condition = FALSE;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
/*
|
|
|
|
* 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:
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
default:
|
|
|
|
m_freem(m);
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trace the packet. */
|
1996-02-14 01:04:21 +03:00
|
|
|
pk_trace(pkp->pk_xcp, m, "P-Out");
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* Pass the packet on down to the link layer */
|
1994-05-13 10:02:48 +04:00
|
|
|
if (pk_input_cache.mbc_size || pk_input_cache.mbc_oldsize) {
|
|
|
|
m->m_flags |= 0x08;
|
|
|
|
mbuf_cache(&pk_input_cache, m);
|
|
|
|
}
|
1996-02-14 01:04:21 +03:00
|
|
|
(*pkp->pk_lloutput) (m, pkp->pk_llnext, pkp->pk_rt);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
/*
|
|
|
|
* This procedure returns the next packet to send or null. A packet is
|
|
|
|
* composed of one or more mbufs.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct mbuf *
|
1996-02-14 01:04:21 +03:00
|
|
|
nextpk(lcp)
|
|
|
|
struct pklcd *lcp;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
register struct mbuf *m, *n;
|
1996-02-14 01:04:21 +03:00
|
|
|
struct socket *so = lcp->lcd_so;
|
1994-09-20 10:41:04 +04:00
|
|
|
register struct sockbuf *sb = (so ? &so->so_snd : &lcp->lcd_sb);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
if (lcp->lcd_template) {
|
|
|
|
m = lcp->lcd_template;
|
|
|
|
lcp->lcd_template = NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
} else {
|
1996-02-14 01:04:21 +03:00
|
|
|
if (lcp->lcd_rnr_condition || lcp->lcd_window_condition ||
|
|
|
|
lcp->lcd_reset_condition)
|
1993-04-09 16:00:07 +04:00
|
|
|
return (NULL);
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
if ((m = sb->sb_mb) == 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
return (NULL);
|
|
|
|
|
1996-02-14 01:04:21 +03:00
|
|
|
sb->sb_mb = m->m_nextpkt;
|
|
|
|
m->m_act = 0;
|
|
|
|
for (n = m; n; n = n->m_next)
|
|
|
|
sbfree(sb, n);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
return (m);
|
|
|
|
}
|