1 /*
2 * ROSE release 003
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 * ROSE 001 Jonathan(G4KLX) Cloned from rose_timer.c
14 * ROSE 003 Jonathan(G4KLX) New timer architecture.
15 */
16
17 #include <linux/errno.h>
18 #include <linux/types.h>
19 #include <linux/socket.h>
20 #include <linux/in.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/timer.h>
24 #include <linux/string.h>
25 #include <linux/sockios.h>
26 #include <linux/net.h>
27 #include <net/ax25.h>
28 #include <linux/inet.h>
29 #include <linux/netdevice.h>
30 #include <linux/skbuff.h>
31 #include <net/sock.h>
32 #include <asm/segment.h>
33 #include <asm/system.h>
34 #include <linux/fcntl.h>
35 #include <linux/mm.h>
36 #include <linux/interrupt.h>
37 #include <linux/netfilter.h>
38 #include <net/rose.h>
39
40 static void rose_ftimer_expiry(unsigned long);
41 static void rose_t0timer_expiry(unsigned long);
42
43 void rose_start_ftimer(struct rose_neigh *neigh)
44 {
45 del_timer(&neigh->ftimer);
46
47 neigh->ftimer.data = (unsigned long)neigh;
48 neigh->ftimer.function = &rose_ftimer_expiry;
49 neigh->ftimer.expires = jiffies + sysctl_rose_link_fail_timeout;
50
51 add_timer(&neigh->ftimer);
52 }
53
54 void rose_start_t0timer(struct rose_neigh *neigh)
55 {
56 del_timer(&neigh->t0timer);
57
58 neigh->t0timer.data = (unsigned long)neigh;
59 neigh->t0timer.function = &rose_t0timer_expiry;
60 neigh->t0timer.expires = jiffies + sysctl_rose_restart_request_timeout;
61
62 add_timer(&neigh->t0timer);
63 }
64
65 void rose_stop_ftimer(struct rose_neigh *neigh)
66 {
67 del_timer(&neigh->ftimer);
68 }
69
70 void rose_stop_t0timer(struct rose_neigh *neigh)
71 {
72 del_timer(&neigh->t0timer);
73 }
74
75 int rose_ftimer_running(struct rose_neigh *neigh)
76 {
77 return timer_pending(&neigh->ftimer);
78 }
79
80 int rose_t0timer_running(struct rose_neigh *neigh)
81 {
82 return timer_pending(&neigh->t0timer);
83 }
84
85 static void rose_ftimer_expiry(unsigned long param)
86 {
87 }
88
89 static void rose_t0timer_expiry(unsigned long param)
90 {
91 struct rose_neigh *neigh = (struct rose_neigh *)param;
92
93 rose_transmit_restart_request(neigh);
94
95 neigh->dce_mode = 0;
96
97 rose_start_t0timer(neigh);
98 }
99
100 /*
101 * Interface to ax25_send_frame. Changes my level 2 callsign depending
102 * on whether we have a global ROSE callsign or use the default port
103 * callsign.
104 */
105 static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
106 {
107 ax25_address *rose_call;
108
109 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
110 rose_call = (ax25_address *)neigh->dev->dev_addr;
111 else
112 rose_call = &rose_callsign;
113
114 neigh->ax25 = ax25_send_frame(skb, 260, rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
115
116 return (neigh->ax25 != NULL);
117 }
118
119 /*
120 * Interface to ax25_link_up. Changes my level 2 callsign depending
121 * on whether we have a global ROSE callsign or use the default port
122 * callsign.
123 */
124 static int rose_link_up(struct rose_neigh *neigh)
125 {
126 ax25_address *rose_call;
127
128 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
129 rose_call = (ax25_address *)neigh->dev->dev_addr;
130 else
131 rose_call = &rose_callsign;
132
133 neigh->ax25 = ax25_find_cb(rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
134
135 return (neigh->ax25 != NULL);
136 }
137
138 /*
139 * This handles all restart and diagnostic frames.
140 */
141 void rose_link_rx_restart(struct sk_buff *skb, struct rose_neigh *neigh, unsigned short frametype)
142 {
143 struct sk_buff *skbn;
144
145 switch (frametype) {
146 case ROSE_RESTART_REQUEST:
147 rose_stop_t0timer(neigh);
148 neigh->restarted = 1;
149 neigh->dce_mode = (skb->data[3] == ROSE_DTE_ORIGINATED);
150 rose_transmit_restart_confirmation(neigh);
151 break;
152
153 case ROSE_RESTART_CONFIRMATION:
154 rose_stop_t0timer(neigh);
155 neigh->restarted = 1;
156 break;
157
158 case ROSE_DIAGNOSTIC:
159 printk(KERN_WARNING "ROSE: received diagnostic #%d - %02X %02X %02X\n", skb->data[3], skb->data[4], skb->data[5], skb->data[6]);
160 break;
161
162 default:
163 printk(KERN_WARNING "ROSE: received unknown %02X with LCI 000\n", frametype);
164 break;
165 }
166
167 if (neigh->restarted) {
168 while ((skbn = skb_dequeue(&neigh->queue)) != NULL)
169 if (!rose_send_frame(skbn, neigh))
170 kfree_skb(skbn);
171 }
172 }
173
174 /*
175 * This routine is called when a Restart Request is needed
176 */
177 void rose_transmit_restart_request(struct rose_neigh *neigh)
178 {
179 struct sk_buff *skb;
180 unsigned char *dptr;
181 int len;
182
183 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
184
185 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
186 return;
187
188 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
189
190 dptr = skb_put(skb, ROSE_MIN_LEN + 3);
191
192 *dptr++ = AX25_P_ROSE;
193 *dptr++ = ROSE_GFI;
194 *dptr++ = 0x00;
195 *dptr++ = ROSE_RESTART_REQUEST;
196 *dptr++ = ROSE_DTE_ORIGINATED;
197 *dptr++ = 0;
198
199 if (!rose_send_frame(skb, neigh))
200 kfree_skb(skb);
201 }
202
203 /*
204 * This routine is called when a Restart Confirmation is needed
205 */
206 void rose_transmit_restart_confirmation(struct rose_neigh *neigh)
207 {
208 struct sk_buff *skb;
209 unsigned char *dptr;
210 int len;
211
212 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 1;
213
214 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
215 return;
216
217 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
218
219 dptr = skb_put(skb, ROSE_MIN_LEN + 1);
220
221 *dptr++ = AX25_P_ROSE;
222 *dptr++ = ROSE_GFI;
223 *dptr++ = 0x00;
224 *dptr++ = ROSE_RESTART_CONFIRMATION;
225
226 if (!rose_send_frame(skb, neigh))
227 kfree_skb(skb);
228 }
229
230 /*
231 * This routine is called when a Diagnostic is required.
232 */
233 void rose_transmit_diagnostic(struct rose_neigh *neigh, unsigned char diag)
234 {
235 struct sk_buff *skb;
236 unsigned char *dptr;
237 int len;
238
239 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 2;
240
241 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
242 return;
243
244 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
245
246 dptr = skb_put(skb, ROSE_MIN_LEN + 2);
247
248 *dptr++ = AX25_P_ROSE;
249 *dptr++ = ROSE_GFI;
250 *dptr++ = 0x00;
251 *dptr++ = ROSE_DIAGNOSTIC;
252 *dptr++ = diag;
253
254 if (!rose_send_frame(skb, neigh))
255 kfree_skb(skb);
256 }
257
258 /*
259 * This routine is called when a Clear Request is needed outside of the context
260 * of a connected socket.
261 */
262 void rose_transmit_clear_request(struct rose_neigh *neigh, unsigned int lci, unsigned char cause, unsigned char diagnostic)
263 {
264 struct sk_buff *skb;
265 unsigned char *dptr;
266 int len;
267
268 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
269
270 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
271 return;
272
273 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
274
275 dptr = skb_put(skb, ROSE_MIN_LEN + 3);
276
277 *dptr++ = AX25_P_ROSE;
278 *dptr++ = ((lci >> 8) & 0x0F) | ROSE_GFI;
279 *dptr++ = ((lci >> 0) & 0xFF);
280 *dptr++ = ROSE_CLEAR_REQUEST;
281 *dptr++ = cause;
282 *dptr++ = diagnostic;
283
284 if (!rose_send_frame(skb, neigh))
285 kfree_skb(skb);
286 }
287
288 void rose_transmit_link(struct sk_buff *skb, struct rose_neigh *neigh)
289 {
290 unsigned char *dptr;
291
292 #if 0
293 if (call_fw_firewall(PF_ROSE, skb->dev, skb->data, NULL, &skb) != FW_ACCEPT) {
294 kfree_skb(skb);
295 return;
296 }
297 #endif
298
299 if (neigh->loopback) {
300 rose_loopback_queue(skb, neigh);
301 return;
302 }
303
304 if (!rose_link_up(neigh))
305 neigh->restarted = 0;
306
307 dptr = skb_push(skb, 1);
308 *dptr++ = AX25_P_ROSE;
309
310 if (neigh->restarted) {
311 if (!rose_send_frame(skb, neigh))
312 kfree_skb(skb);
313 } else {
314 skb_queue_tail(&neigh->queue, skb);
315
316 if (!rose_t0timer_running(neigh)) {
317 rose_transmit_restart_request(neigh);
318 neigh->dce_mode = 0;
319 rose_start_t0timer(neigh);
320 }
321 }
322 }
323
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.