changes to run over both LLC and HDLC, and also use explicit shifts
[unix-history] / usr / src / sys / netccitt / pk_timer.c
CommitLineData
a130a8be
KS
1/*
2 * Copyright (c) Computing Centre, University of British Columbia, 1984
3 * Copyright (C) Computer Science Department IV,
4 * University of Erlangen-Nuremberg, Germany, 1990, 1992
5 * Copyright (c) 1990, 1992 Regents of the University of California.
51386eb2 6 * All rights reserved.
a130a8be
KS
7 *
8 * This code is derived from software contributed to Berkeley by the
9 * Laboratory for Computation Vision and the Computer Science Department
10 * of the the University of British Columbia and the Computer Science
11 * Department (IV) of the University of Erlangen-Nuremberg, Germany.
51386eb2
KS
12 *
13 * %sccs.include.redist.c%
14 *
a130a8be 15 * @(#)pk_timer.c 7.7 (Berkeley) %G%
51386eb2 16 */
758293b0 17
5548a02f
KB
18#include <sys/param.h>
19#include <sys/systm.h>
20#include <sys/mbuf.h>
21#include <sys/socket.h>
22#include <sys/protosw.h>
23#include <sys/socketvar.h>
24#include <sys/errno.h>
758293b0 25
5548a02f 26#include <net/if.h>
758293b0 27
5548a02f
KB
28#include <netccitt/x25.h>
29#include <netccitt/pk.h>
30#include <netccitt/pk_var.h>
758293b0
KS
31
32/*
33 * Various timer values. They can be adjusted
34 * by patching the binary with adb if necessary.
35 */
36int pk_t20 = 18 * PR_SLOWHZ; /* restart timer */
37int pk_t21 = 20 * PR_SLOWHZ; /* call timer */
38/* XXX pk_t22 is never used */
39int pk_t22 = 18 * PR_SLOWHZ; /* reset timer */
40int pk_t23 = 18 * PR_SLOWHZ; /* clear timer */
41
42pk_timer ()
43{
44 register struct pkcb *pkp;
45 register struct pklcd *lcp, **pp;
46 register int lcns_jammed, cant_restart;
47
a130a8be 48 FOR_ALL_PKCBS(pkp) {
758293b0
KS
49 switch (pkp -> pk_state) {
50 case DTE_SENT_RESTART:
51 lcp = pkp -> pk_chan[0];
52 /*
53 * If restart failures are common, a link level
54 * reset should be initiated here.
55 */
a130a8be 56 if (lcp -> lcd_timer && --lcp -> lcd_timer == 0) {
758293b0
KS
57 pk_message (0, pkp -> pk_xcp,
58 "packet level restart failed");
a130a8be
KS
59 pkp -> pk_state = DTE_WAITING;
60 }
758293b0
KS
61 break;
62
63 case DTE_READY:
64 lcns_jammed = cant_restart = 0;
65 for (pp = &pkp -> pk_chan[1]; pp <= &pkp -> pk_chan[pkp -> pk_maxlcn]; pp++) {
66 if ((lcp = *pp) == 0)
67 continue;
68 switch (lcp -> lcd_state) {
69 case SENT_CALL:
70 if (--lcp -> lcd_timer == 0) {
dd4760db 71 if (lcp -> lcd_so)
758293b0 72 lcp -> lcd_so -> so_error = ETIMEDOUT;
dd4760db 73 pk_clear (lcp, 49, 1);
758293b0
KS
74 }
75 break;
76
77 case SENT_CLEAR:
78 if (lcp -> lcd_retry >= 3)
79 lcns_jammed++;
80 else
81 if (--lcp -> lcd_timer == 0)
700ea0e2 82 pk_clear (lcp, 50, 1);
758293b0
KS
83 break;
84
85 case DATA_TRANSFER: /* lcn active */
86 cant_restart++;
87 break;
a130a8be
KS
88
89 case LCN_ZOMBIE: /* zombie state */
90 pk_freelcd (lcp);
91 break;
758293b0
KS
92 }
93 }
94 if (lcns_jammed > pkp -> pk_maxlcn / 2 && cant_restart == 0) {
95 pk_message (0, pkp -> pk_xcp, "%d lcns jammed: attempting restart", lcns_jammed);
96 pk_restart (pkp, 0);
97 }
98 }
99 }
100}