1 /*
2 * LAPB release 002
3 *
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
5 *
6 * This module:
7 * This module is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * History
13 * LAPB 001 Jonathan Naylor Started Coding
14 * LAPB 002 Jonathan Naylor New timer architecture.
15 */
16
17 #include <linux/config.h>
18 #if defined(CONFIG_LAPB) || defined(CONFIG_LAPB_MODULE)
19 #include <linux/errno.h>
20 #include <linux/types.h>
21 #include <linux/socket.h>
22 #include <linux/in.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/timer.h>
26 #include <linux/string.h>
27 #include <linux/sockios.h>
28 #include <linux/net.h>
29 #include <linux/inet.h>
30 #include <linux/skbuff.h>
31 #include <net/sock.h>
32 #include <asm/uaccess.h>
33 #include <asm/system.h>
34 #include <linux/fcntl.h>
35 #include <linux/mm.h>
36 #include <linux/interrupt.h>
37 #include <net/lapb.h>
38
39 static void lapb_t1timer_expiry(unsigned long);
40 static void lapb_t2timer_expiry(unsigned long);
41
42 void lapb_start_t1timer(lapb_cb *lapb)
43 {
44 del_timer(&lapb->t1timer);
45
46 lapb->t1timer.data = (unsigned long)lapb;
47 lapb->t1timer.function = &lapb_t1timer_expiry;
48 lapb->t1timer.expires = jiffies + lapb->t1;
49
50 add_timer(&lapb->t1timer);
51 }
52
53 void lapb_start_t2timer(lapb_cb *lapb)
54 {
55 del_timer(&lapb->t2timer);
56
57 lapb->t2timer.data = (unsigned long)lapb;
58 lapb->t2timer.function = &lapb_t2timer_expiry;
59 lapb->t2timer.expires = jiffies + lapb->t2;
60
61 add_timer(&lapb->t2timer);
62 }
63
64 void lapb_stop_t1timer(lapb_cb *lapb)
65 {
66 del_timer(&lapb->t1timer);
67 }
68
69 void lapb_stop_t2timer(lapb_cb *lapb)
70 {
71 del_timer(&lapb->t2timer);
72 }
73
74 int lapb_t1timer_running(lapb_cb *lapb)
75 {
76 return timer_pending(&lapb->t1timer);
77 }
78
79 static void lapb_t2timer_expiry(unsigned long param)
80 {
81 lapb_cb *lapb = (lapb_cb *)param;
82
83 if (lapb->condition & LAPB_ACK_PENDING_CONDITION) {
84 lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
85 lapb_timeout_response(lapb);
86 }
87 }
88
89 static void lapb_t1timer_expiry(unsigned long param)
90 {
91 lapb_cb *lapb = (lapb_cb *)param;
92
93 switch (lapb->state) {
94
95 /*
96 * If we are a DCE, keep going DM .. DM .. DM
97 */
98 case LAPB_STATE_0:
99 if (lapb->mode & LAPB_DCE)
100 lapb_send_control(lapb, LAPB_DM, LAPB_POLLOFF, LAPB_RESPONSE);
101 break;
102
103 /*
104 * Awaiting connection state, send SABM(E), up to N2 times.
105 */
106 case LAPB_STATE_1:
107 if (lapb->n2count == lapb->n2) {
108 lapb_clear_queues(lapb);
109 lapb->state = LAPB_STATE_0;
110 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
111 #if LAPB_DEBUG > 0
112 printk(KERN_DEBUG "lapb: (%p) S1 -> S0\n", lapb->token);
113 #endif
114 return;
115 } else {
116 lapb->n2count++;
117 if (lapb->mode & LAPB_EXTENDED) {
118 #if LAPB_DEBUG > 1
119 printk(KERN_DEBUG "lapb: (%p) S1 TX SABME(1)\n", lapb->token);
120 #endif
121 lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
122 } else {
123 #if LAPB_DEBUG > 1
124 printk(KERN_DEBUG "lapb: (%p) S1 TX SABM(1)\n", lapb->token);
125 #endif
126 lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
127 }
128 }
129 break;
130
131 /*
132 * Awaiting disconnection state, send DISC, up to N2 times.
133 */
134 case LAPB_STATE_2:
135 if (lapb->n2count == lapb->n2) {
136 lapb_clear_queues(lapb);
137 lapb->state = LAPB_STATE_0;
138 lapb_disconnect_confirmation(lapb, LAPB_TIMEDOUT);
139 #if LAPB_DEBUG > 0
140 printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->token);
141 #endif
142 return;
143 } else {
144 lapb->n2count++;
145 #if LAPB_DEBUG > 1
146 printk(KERN_DEBUG "lapb: (%p) S2 TX DISC(1)\n", lapb->token);
147 #endif
148 lapb_send_control(lapb, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
149 }
150 break;
151
152 /*
153 * Data transfer state, restransmit I frames, up to N2 times.
154 */
155 case LAPB_STATE_3:
156 if (lapb->n2count == lapb->n2) {
157 lapb_clear_queues(lapb);
158 lapb->state = LAPB_STATE_0;
159 lapb_stop_t2timer(lapb);
160 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
161 #if LAPB_DEBUG > 0
162 printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->token);
163 #endif
164 return;
165 } else {
166 lapb->n2count++;
167 lapb_requeue_frames(lapb);
168 }
169 break;
170
171 /*
172 * Frame reject state, restransmit FRMR frames, up to N2 times.
173 */
174 case LAPB_STATE_4:
175 if (lapb->n2count == lapb->n2) {
176 lapb_clear_queues(lapb);
177 lapb->state = LAPB_STATE_0;
178 lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
179 #if LAPB_DEBUG > 0
180 printk(KERN_DEBUG "lapb: (%p) S4 -> S0\n", lapb->token);
181 #endif
182 return;
183 } else {
184 lapb->n2count++;
185 lapb_transmit_frmr(lapb);
186 }
187 break;
188 }
189
190 lapb_start_t1timer(lapb);
191 }
192
193 #endif
194
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.