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, 1993 6 * The Regents of the University of California. All rights reserved. 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. 12 * 13 * %sccs.include.redist.c% 14 * 15 * @(#)pk_timer.c 8.1 (Berkeley) 06/10/93 16 */ 17 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> 25 26 #include <net/if.h> 27 28 #include <netccitt/x25.h> 29 #include <netccitt/pk.h> 30 #include <netccitt/pk_var.h> 31 32 /* 33 * Various timer values. They can be adjusted 34 * by patching the binary with adb if necessary. 35 */ 36 int pk_t20 = 18 * PR_SLOWHZ; /* restart timer */ 37 int pk_t21 = 20 * PR_SLOWHZ; /* call timer */ 38 /* XXX pk_t22 is never used */ 39 int pk_t22 = 18 * PR_SLOWHZ; /* reset timer */ 40 int pk_t23 = 18 * PR_SLOWHZ; /* clear timer */ 41 42 pk_timer () 43 { 44 register struct pkcb *pkp; 45 register struct pklcd *lcp, **pp; 46 register int lcns_jammed, cant_restart; 47 48 FOR_ALL_PKCBS(pkp) { 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 */ 56 if (lcp -> lcd_timer && --lcp -> lcd_timer == 0) { 57 pk_message (0, pkp -> pk_xcp, 58 "packet level restart failed"); 59 pkp -> pk_state = DTE_WAITING; 60 } 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) { 71 if (lcp -> lcd_so) 72 lcp -> lcd_so -> so_error = ETIMEDOUT; 73 pk_clear (lcp, 49, 1); 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) 82 pk_clear (lcp, 50, 1); 83 break; 84 85 case DATA_TRANSFER: /* lcn active */ 86 cant_restart++; 87 break; 88 89 case LCN_ZOMBIE: /* zombie state */ 90 pk_freelcd (lcp); 91 break; 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 } 101