home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / sys / netccitt / pk_timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-29  |  3.9 KB  |  118 lines

  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.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    @(#)pk_timer.c    7.5 (Berkeley) 5/29/91
  39.  */
  40.  
  41. #include "param.h"
  42. #include "systm.h"
  43. #include "mbuf.h"
  44. #include "socket.h"
  45. #include "protosw.h"
  46. #include "socketvar.h"
  47. #include "errno.h"
  48.  
  49. #include "../net/if.h"
  50.  
  51. #include "x25.h"
  52. #include "pk.h"
  53. #include "pk_var.h"
  54.  
  55. /*
  56.  * Various timer values.  They can be adjusted
  57.  * by patching the binary with adb if necessary.
  58.  */
  59. int    pk_t20 = 18 * PR_SLOWHZ;    /* restart timer */
  60. int    pk_t21 = 20 * PR_SLOWHZ;    /* call timer */
  61. /* XXX pk_t22 is never used */
  62. int    pk_t22 = 18 * PR_SLOWHZ;    /* reset timer */
  63. int    pk_t23 = 18 * PR_SLOWHZ;    /* clear timer */
  64.  
  65. pk_timer ()
  66. {
  67.     register struct pkcb *pkp;
  68.     register struct pklcd *lcp, **pp;
  69.     register int lcns_jammed, cant_restart;
  70.  
  71.     for (pkp = pkcbhead; pkp; pkp = pkp->pk_next) {
  72.         switch (pkp -> pk_state) {
  73.         case DTE_SENT_RESTART:
  74.             lcp = pkp -> pk_chan[0];
  75.             /*
  76.              * If restart failures are common, a link level
  77.              * reset should be initiated here.
  78.              */
  79.             if (lcp -> lcd_timer && --lcp -> lcd_timer == 0)
  80.                 pk_message (0, pkp -> pk_xcp,
  81.                     "packet level restart failed");
  82.             break;
  83.  
  84.         case DTE_READY:
  85.             lcns_jammed = cant_restart = 0;
  86.             for (pp = &pkp -> pk_chan[1]; pp <= &pkp -> pk_chan[pkp -> pk_maxlcn]; pp++) {
  87.                 if ((lcp = *pp) == 0)
  88.                     continue;
  89.                 switch (lcp -> lcd_state) {
  90.                 case SENT_CALL: 
  91.                     if (--lcp -> lcd_timer == 0) {
  92.                         if (lcp -> lcd_so)
  93.                         lcp -> lcd_so -> so_error = ETIMEDOUT;
  94.                         pk_clear (lcp, 49, 1);
  95.                     }
  96.                     break;
  97.  
  98.                 case SENT_CLEAR: 
  99.                     if (lcp -> lcd_retry >= 3)
  100.                         lcns_jammed++;
  101.                     else
  102.                         if (--lcp -> lcd_timer == 0)
  103.                             pk_clear (lcp, 50, 1);
  104.                     break;
  105.  
  106.                 case DATA_TRANSFER:    /* lcn active */
  107.                     cant_restart++;
  108.                     break;
  109.                 }
  110.             }
  111.             if (lcns_jammed > pkp -> pk_maxlcn / 2 && cant_restart == 0) {
  112.                 pk_message (0, pkp -> pk_xcp, "%d lcns jammed: attempting restart", lcns_jammed);
  113.                 pk_restart (pkp, 0);
  114.             }
  115.         }
  116.     }
  117. }
  118.