xref: /csrg-svn/sys/netccitt/pk_timer.c (revision 63216)
157024Ssklower /*
257024Ssklower  * Copyright (c) Computing Centre, University of British Columbia, 1984
357024Ssklower  * Copyright (C) Computer Science Department IV,
457024Ssklower  * 		 University of Erlangen-Nuremberg, Germany, 1990, 1992
5*63216Sbostic  * Copyright (c) 1990, 1992, 1993
6*63216Sbostic  *	The Regents of the University of California.  All rights reserved.
757024Ssklower  *
857024Ssklower  * This code is derived from software contributed to Berkeley by the
957024Ssklower  * Laboratory for Computation Vision and the Computer Science Department
1057024Ssklower  * of the the University of British Columbia and the Computer Science
1157024Ssklower  * Department (IV) of the University of Erlangen-Nuremberg, Germany.
1241709Ssklower  *
1341709Ssklower  * %sccs.include.redist.c%
1441709Ssklower  *
15*63216Sbostic  *	@(#)pk_timer.c	8.1 (Berkeley) 06/10/93
1641709Ssklower  */
1741594Ssklower 
1856530Sbostic #include <sys/param.h>
1956530Sbostic #include <sys/systm.h>
2056530Sbostic #include <sys/mbuf.h>
2156530Sbostic #include <sys/socket.h>
2256530Sbostic #include <sys/protosw.h>
2356530Sbostic #include <sys/socketvar.h>
2456530Sbostic #include <sys/errno.h>
2541594Ssklower 
2656530Sbostic #include <net/if.h>
2741594Ssklower 
2856530Sbostic #include <netccitt/x25.h>
2956530Sbostic #include <netccitt/pk.h>
3056530Sbostic #include <netccitt/pk_var.h>
3141594Ssklower 
3241594Ssklower /*
3341594Ssklower  * Various timer values.  They can be adjusted
3441594Ssklower  * by patching the binary with adb if necessary.
3541594Ssklower  */
3641594Ssklower int	pk_t20 = 18 * PR_SLOWHZ;	/* restart timer */
3741594Ssklower int	pk_t21 = 20 * PR_SLOWHZ;	/* call timer */
3841594Ssklower /* XXX pk_t22 is never used */
3941594Ssklower int	pk_t22 = 18 * PR_SLOWHZ;	/* reset timer */
4041594Ssklower int	pk_t23 = 18 * PR_SLOWHZ;	/* clear timer */
4141594Ssklower 
pk_timer()4241594Ssklower pk_timer ()
4341594Ssklower {
4441594Ssklower 	register struct pkcb *pkp;
4541594Ssklower 	register struct pklcd *lcp, **pp;
4641594Ssklower 	register int lcns_jammed, cant_restart;
4741594Ssklower 
4857024Ssklower 	FOR_ALL_PKCBS(pkp) {
4941594Ssklower 		switch (pkp -> pk_state) {
5041594Ssklower 		case DTE_SENT_RESTART:
5141594Ssklower 			lcp = pkp -> pk_chan[0];
5241594Ssklower 			/*
5341594Ssklower 			 * If restart failures are common, a link level
5441594Ssklower 			 * reset should be initiated here.
5541594Ssklower 			 */
5657024Ssklower 			if (lcp -> lcd_timer && --lcp -> lcd_timer == 0) {
5741594Ssklower 				pk_message (0, pkp -> pk_xcp,
5841594Ssklower 					"packet level restart failed");
5957024Ssklower 				pkp -> pk_state = DTE_WAITING;
6057024Ssklower 			}
6141594Ssklower 			break;
6241594Ssklower 
6341594Ssklower 		case DTE_READY:
6441594Ssklower 			lcns_jammed = cant_restart = 0;
6541594Ssklower 			for (pp = &pkp -> pk_chan[1]; pp <= &pkp -> pk_chan[pkp -> pk_maxlcn]; pp++) {
6641594Ssklower 				if ((lcp = *pp) == 0)
6741594Ssklower 					continue;
6841594Ssklower 				switch (lcp -> lcd_state) {
6941594Ssklower 				case SENT_CALL:
7041594Ssklower 					if (--lcp -> lcd_timer == 0) {
7149934Ssklower 					    if (lcp -> lcd_so)
7241594Ssklower 						lcp -> lcd_so -> so_error = ETIMEDOUT;
7349934Ssklower 					    pk_clear (lcp, 49, 1);
7441594Ssklower 					}
7541594Ssklower 					break;
7641594Ssklower 
7741594Ssklower 				case SENT_CLEAR:
7841594Ssklower 					if (lcp -> lcd_retry >= 3)
7941594Ssklower 						lcns_jammed++;
8041594Ssklower 					else
8141594Ssklower 						if (--lcp -> lcd_timer == 0)
8245894Ssklower 							pk_clear (lcp, 50, 1);
8341594Ssklower 					break;
8441594Ssklower 
8541594Ssklower 				case DATA_TRANSFER:	/* lcn active */
8641594Ssklower 					cant_restart++;
8741594Ssklower 					break;
8857024Ssklower 
8957024Ssklower 				case LCN_ZOMBIE:       /* zombie state */
9057024Ssklower 					pk_freelcd (lcp);
9157024Ssklower 					break;
9241594Ssklower 				}
9341594Ssklower 			}
9441594Ssklower 			if (lcns_jammed > pkp -> pk_maxlcn / 2 && cant_restart == 0) {
9541594Ssklower 				pk_message (0, pkp -> pk_xcp, "%d lcns jammed: attempting restart", lcns_jammed);
9641594Ssklower 				pk_restart (pkp, 0);
9741594Ssklower 			}
9841594Ssklower 		}
9941594Ssklower 	}
10041594Ssklower }
101