Changed the default 'reboot' routine from cpu_reset() to shutdown_nice().
[unix-history] / sys / netccitt / hd_timer.c
CommitLineData
15637ed4
RG
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 *
1cdffd64 38 * from: @(#)hd_timer.c 7.4 (Berkeley) 5/29/91
4c45483e 39 * $Id: hd_timer.c,v 1.2 1993/10/16 19:46:40 rgrimes Exp $
15637ed4
RG
40 */
41
42#include "param.h"
43#include "systm.h"
44#include "mbuf.h"
45#include "domain.h"
46#include "socket.h"
47#include "protosw.h"
48#include "errno.h"
49#include "time.h"
50#include "kernel.h"
51
52#include "../net/if.h"
53
54#include "hdlc.h"
55#include "hd_var.h"
56#include "x25.h"
57
58/*
59 * these can be patched with adb if the
60 * default values are inappropriate
61 */
62
63int hd_t1 = T1;
64int hd_t3 = T3;
65int hd_n2 = N2;
66
67/*
68 * HDLC TIMER
69 *
70 * This routine is called every 500ms by the kernel. Decrement timer by this
71 * amount - if expired then process the event.
72 */
73
4c45483e 74void
15637ed4
RG
75hd_timer ()
76{
77 register struct hdcb *hdp;
78 register int s = splimp ();
79
80 for (hdp = hdcbhead; hdp; hdp = hdp->hd_next) {
81 if (hdp->hd_rrtimer && (--hdp->hd_rrtimer == 0)) {
82 if (hdp->hd_lasttxnr != hdp->hd_vr)
83 hd_writeinternal (hdp, RR, POLLOFF);
84 }
85
86 if (!(hdp->hd_timer && --hdp->hd_timer == 0))
87 continue;
88
89 switch (hdp->hd_state) {
90 case INIT:
91 case DISC_SENT:
92 hd_writeinternal (hdp, DISC, POLLON);
93 break;
94
95 case ABM:
96 if (hdp->hd_lastrxnr != hdp->hd_vs) { /* XXX */
97 hdp->hd_timeouts++;
98 hd_resend_iframe (hdp);
99 }
100 break;
101
102 case WAIT_SABM:
103 hd_writeinternal (hdp, FRMR, POLLOFF);
104 if (++hdp->hd_retxcnt == hd_n2) {
105 hdp->hd_retxcnt = 0;
106 hd_writeinternal (hdp, SABM, POLLOFF);
107 hdp->hd_state = WAIT_UA;
108 }
109 break;
110
111 case DM_SENT:
112 if (++hdp->hd_retxcnt == hd_n2) {
113 /* Notify the packet level. */
114 (void) pk_ctlinput (PRC_LINKDOWN, hdp->hd_pkp);
115 hdp->hd_retxcnt = 0;
116 hdp->hd_state = SABM_SENT;
117 hd_writeinternal (hdp, SABM, POLLOFF);
118 } else
119 hd_writeinternal (hdp, DM, POLLOFF);
120 break;
121
122 case WAIT_UA:
123 if (++hdp->hd_retxcnt == hd_n2) {
124 hdp->hd_retxcnt = 0;
125 hd_writeinternal (hdp, DM, POLLOFF);
126 hdp->hd_state = DM_SENT;
127 } else
128 hd_writeinternal (hdp, SABM, POLLOFF);
129 break;
130
131 case SABM_SENT:
132 /* Do this indefinitely. */
133 hd_writeinternal (hdp, SABM, POLLON);
134 break;
135
136 case DISCONNECTED:
137 /*
138 * Poll the interface driver flags waiting
139 * for the IFF_UP bit to come on.
140 */
141 if (hdp->hd_ifp->if_flags & IFF_UP)
142 hdp->hd_state = INIT;
143
144 }
145 SET_TIMER (hdp);
146 }
147
148 splx (s);
149}