]> git.saurik.com Git - apple/xnu.git/blame - bsd/netccitt/llc_timer.c
xnu-201.42.3.tar.gz
[apple/xnu.git] / bsd / netccitt / llc_timer.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (C) Dirk Husemann, Computer Science Department IV,
24 * University of Erlangen-Nuremberg, Germany, 1990, 1991, 1992
25 * Copyright (c) 1992, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * This code is derived from software contributed to Berkeley by
29 * Dirk Husemann and the Computer Science Department (IV) of
30 * the University of Erlangen-Nuremberg, Germany.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)llc_timer.c 8.1 (Berkeley) 6/10/93
61 */
62
63#include <sys/param.h>
64#include <sys/systm.h>
65#include <sys/mbuf.h>
66#include <sys/domain.h>
67#include <sys/socket.h>
68#include <sys/protosw.h>
69#include <sys/errno.h>
70#include <sys/time.h>
71#include <sys/kernel.h>
72
73#include <net/if.h>
74#include <net/if_dl.h>
75#include <net/if_llc.h>
76
77#include <netccitt/dll.h>
78#include <netccitt/llc_var.h>
79
80
81/*
82 * Various timer values. They can be adjusted
83 * by patching the binary with adb if necessary.
84 */
85/* ISO 8802-2 timers */
86int llc_n2 = LLC_N2_VALUE;
87int llc_ACK_timer = LLC_ACK_TIMER;
88int llc_P_timer = LLC_P_TIMER;
89int llc_BUSY_timer = LLC_BUSY_TIMER;
90int llc_REJ_timer = LLC_REJ_TIMER;
91/* Implementation specific timers */
92int llc_AGE_timer = LLC_AGE_TIMER;
93int llc_DACTION_timer = LLC_DACTION_TIMER;
94
95/*
96 * The timer routine. We are called every 500ms by the kernel.
97 * Handle the various virtual timers.
98 */
99
100void
101llc_timer()
102{
103 register struct llc_linkcb *linkp;
104 register struct llc_linkcb *nlinkp;
105 register int timer;
106 register int action;
107 register int s = splimp();
108
109 /*
110 * All links are accessible over the doubly linked list llccb_q
111 */
112 if (!LQEMPTY) {
113 /*
114 * A for-loop is not that great an idea as the linkp
115 * might get deleted if the age timer has expired ...
116 */
117 linkp = LQFIRST;
118 while (LQVALID(linkp)) {
119 nlinkp = LQNEXT(linkp);
120 /*
121 * Check implementation specific timers first
122 */
123 /* The delayed action/acknowledge idle timer */
124 switch (LLC_TIMERXPIRED(linkp, DACTION)) {
125 case LLC_TIMER_RUNNING:
126 LLC_AGETIMER(linkp, DACTION);
127 break;
128 case LLC_TIMER_EXPIRED: {
129 register int cmdrsp;
130 register int pollfinal;
131
132 switch (LLC_GETFLAG(linkp, DACTION)) {
133 case LLC_DACKCMD:
134 cmdrsp = LLC_CMD, pollfinal = 0;
135 break;
136 case LLC_DACKCMDPOLL:
137 cmdrsp = LLC_CMD, pollfinal = 1;
138 break;
139 case LLC_DACKRSP:
140 cmdrsp = LLC_RSP, pollfinal = 0;
141 break;
142 case LLC_DACKRSPFINAL:
143 cmdrsp = LLC_RSP, pollfinal = 1;
144 break;
145 }
146 llc_send(linkp, LLCFT_RR, cmdrsp, pollfinal);
147 LLC_STOPTIMER(linkp, DACTION);
148 break;
149 }
150 }
151 /* The link idle timer */
152 switch (LLC_TIMERXPIRED(linkp, AGE)) {
153 case LLC_TIMER_RUNNING:
154 LLC_AGETIMER(linkp, AGE);
155 break;
156 case LLC_TIMER_EXPIRED:
157 /*
158 * Only crunch the link when really no
159 * timers are running any more.
160 */
161 if (llc_anytimersup(linkp) == 0) {
162 llc_dellink(linkp);
163 LLC_STOPTIMER(linkp, AGE);
164 goto gone;
165 } else {
166 LLC_STARTTIMER(linkp, AGE);
167 }
168 break;
169 }
170 /*
171 * Now, check all the ISO 8802-2 timers
172 */
173 FOR_ALL_LLC_TIMERS(timer) {
174 action = 0;
175 if ((linkp->llcl_timerflags & (1<<timer)) &&
176 (linkp->llcl_timers[timer] == 0)) {
177 switch (timer) {
178 case LLC_ACK_SHIFT:
179 action = LLC_ACK_TIMER_EXPIRED;
180 break;
181 case LLC_P_SHIFT:
182 action = LLC_P_TIMER_EXPIRED;
183 break;
184 case LLC_BUSY_SHIFT:
185 action = LLC_BUSY_TIMER_EXPIRED;
186 break;
187 case LLC_REJ_SHIFT:
188 action = LLC_REJ_TIMER_EXPIRED;
189 break;
190 }
191 linkp->llcl_timerflags &= ~(1<<timer);
192 (void)llc_statehandler(linkp, (struct llc *)0, action, 0, 1);
193 } else if (linkp->llcl_timers[timer] > 0)
194 linkp->llcl_timers[timer]--;
195 }
196
197gone: linkp = nlinkp;
198 }
199 }
200 splx (s);
201}