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