xref: /original-bsd/sys/netccitt/pk_timer.c (revision 35d77a20)
1 /*
2  * Copyright (c) University of British Columbia, 1984
3  * Copyright (c) 1990 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Laboratory for Computation Vision and the Computer Science Department
8  * of the University of British Columbia.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)pk_timer.c	7.5 (Berkeley) 05/29/91
13  */
14 
15 #include "param.h"
16 #include "systm.h"
17 #include "mbuf.h"
18 #include "socket.h"
19 #include "protosw.h"
20 #include "socketvar.h"
21 #include "errno.h"
22 
23 #include "../net/if.h"
24 
25 #include "x25.h"
26 #include "pk.h"
27 #include "pk_var.h"
28 
29 /*
30  * Various timer values.  They can be adjusted
31  * by patching the binary with adb if necessary.
32  */
33 int	pk_t20 = 18 * PR_SLOWHZ;	/* restart timer */
34 int	pk_t21 = 20 * PR_SLOWHZ;	/* call timer */
35 /* XXX pk_t22 is never used */
36 int	pk_t22 = 18 * PR_SLOWHZ;	/* reset timer */
37 int	pk_t23 = 18 * PR_SLOWHZ;	/* clear timer */
38 
39 pk_timer ()
40 {
41 	register struct pkcb *pkp;
42 	register struct pklcd *lcp, **pp;
43 	register int lcns_jammed, cant_restart;
44 
45 	for (pkp = pkcbhead; pkp; pkp = pkp->pk_next) {
46 		switch (pkp -> pk_state) {
47 		case DTE_SENT_RESTART:
48 			lcp = pkp -> pk_chan[0];
49 			/*
50 			 * If restart failures are common, a link level
51 			 * reset should be initiated here.
52 			 */
53 			if (lcp -> lcd_timer && --lcp -> lcd_timer == 0)
54 				pk_message (0, pkp -> pk_xcp,
55 					"packet level restart failed");
56 			break;
57 
58 		case DTE_READY:
59 			lcns_jammed = cant_restart = 0;
60 			for (pp = &pkp -> pk_chan[1]; pp <= &pkp -> pk_chan[pkp -> pk_maxlcn]; pp++) {
61 				if ((lcp = *pp) == 0)
62 					continue;
63 				switch (lcp -> lcd_state) {
64 				case SENT_CALL:
65 					if (--lcp -> lcd_timer == 0) {
66 					    if (lcp -> lcd_so)
67 						lcp -> lcd_so -> so_error = ETIMEDOUT;
68 					    pk_clear (lcp, 49, 1);
69 					}
70 					break;
71 
72 				case SENT_CLEAR:
73 					if (lcp -> lcd_retry >= 3)
74 						lcns_jammed++;
75 					else
76 						if (--lcp -> lcd_timer == 0)
77 							pk_clear (lcp, 50, 1);
78 					break;
79 
80 				case DATA_TRANSFER:	/* lcn active */
81 					cant_restart++;
82 					break;
83 				}
84 			}
85 			if (lcns_jammed > pkp -> pk_maxlcn / 2 && cant_restart == 0) {
86 				pk_message (0, pkp -> pk_xcp, "%d lcns jammed: attempting restart", lcns_jammed);
87 				pk_restart (pkp, 0);
88 			}
89 		}
90 	}
91 }
92