4 * This code REQUIRES 2.1.15 or higher/ NET3.038
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.
13 * ROSE 001 Jonathan(G4KLX) Cloned from rose_timer.c
14 * ROSE 003 Jonathan(G4KLX) New timer architecture.
17 #include <linux/config.h>
18 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
19 #include <linux/errno.h>
20 #include <linux/types.h>
21 #include <linux/socket.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>
30 #include <linux/inet.h>
31 #include <linux/netdevice.h>
32 #include <linux/skbuff.h>
34 #include <asm/segment.h>
35 #include <asm/system.h>
36 #include <linux/fcntl.h>
38 #include <linux/interrupt.h>
39 #include <linux/netfilter.h>
42 static void rose_ftimer_expiry(unsigned long);
43 static void rose_t0timer_expiry(unsigned long);
45 void rose_start_ftimer(struct rose_neigh
*neigh
)
47 del_timer(&neigh
->ftimer
);
49 neigh
->ftimer
.data
= (unsigned long)neigh
;
50 neigh
->ftimer
.function
= &rose_ftimer_expiry
;
51 neigh
->ftimer
.expires
= jiffies
+ sysctl_rose_link_fail_timeout
;
53 add_timer(&neigh
->ftimer
);
56 void rose_start_t0timer(struct rose_neigh
*neigh
)
58 del_timer(&neigh
->t0timer
);
60 neigh
->t0timer
.data
= (unsigned long)neigh
;
61 neigh
->t0timer
.function
= &rose_t0timer_expiry
;
62 neigh
->t0timer
.expires
= jiffies
+ sysctl_rose_restart_request_timeout
;
64 add_timer(&neigh
->t0timer
);
67 void rose_stop_ftimer(struct rose_neigh
*neigh
)
69 del_timer(&neigh
->ftimer
);
72 void rose_stop_t0timer(struct rose_neigh
*neigh
)
74 del_timer(&neigh
->t0timer
);
77 int rose_ftimer_running(struct rose_neigh
*neigh
)
79 return (neigh
->ftimer
.prev
!= NULL
|| neigh
->ftimer
.next
!= NULL
);
82 int rose_t0timer_running(struct rose_neigh
*neigh
)
84 return (neigh
->t0timer
.prev
!= NULL
|| neigh
->t0timer
.next
!= NULL
);
87 static void rose_ftimer_expiry(unsigned long param
)
91 static void rose_t0timer_expiry(unsigned long param
)
93 struct rose_neigh
*neigh
= (struct rose_neigh
*)param
;
95 rose_transmit_restart_request(neigh
);
99 rose_start_t0timer(neigh
);
103 * Interface to ax25_send_frame. Changes my level 2 callsign depending
104 * on whether we have a global ROSE callsign or use the default port
107 static int rose_send_frame(struct sk_buff
*skb
, struct rose_neigh
*neigh
)
109 ax25_address
*rose_call
;
111 if (ax25cmp(&rose_callsign
, &null_ax25_address
) == 0)
112 rose_call
= (ax25_address
*)neigh
->dev
->dev_addr
;
114 rose_call
= &rose_callsign
;
116 neigh
->ax25
= ax25_send_frame(skb
, 260, rose_call
, &neigh
->callsign
, neigh
->digipeat
, neigh
->dev
);
118 return (neigh
->ax25
!= NULL
);
122 * Interface to ax25_link_up. Changes my level 2 callsign depending
123 * on whether we have a global ROSE callsign or use the default port
126 static int rose_link_up(struct rose_neigh
*neigh
)
128 ax25_address
*rose_call
;
130 if (ax25cmp(&rose_callsign
, &null_ax25_address
) == 0)
131 rose_call
= (ax25_address
*)neigh
->dev
->dev_addr
;
133 rose_call
= &rose_callsign
;
135 neigh
->ax25
= ax25_find_cb(rose_call
, &neigh
->callsign
, neigh
->digipeat
, neigh
->dev
);
137 return (neigh
->ax25
!= NULL
);
141 * This handles all restart and diagnostic frames.
143 void rose_link_rx_restart(struct sk_buff
*skb
, struct rose_neigh
*neigh
, unsigned short frametype
)
145 struct sk_buff
*skbn
;
148 case ROSE_RESTART_REQUEST
:
149 rose_stop_t0timer(neigh
);
150 neigh
->restarted
= 1;
151 neigh
->dce_mode
= (skb
->data
[3] == ROSE_DTE_ORIGINATED
);
152 rose_transmit_restart_confirmation(neigh
);
155 case ROSE_RESTART_CONFIRMATION
:
156 rose_stop_t0timer(neigh
);
157 neigh
->restarted
= 1;
160 case ROSE_DIAGNOSTIC
:
161 printk(KERN_WARNING
"ROSE: received diagnostic #%d - %02X %02X %02X\n", skb
->data
[3], skb
->data
[4], skb
->data
[5], skb
->data
[6]);
165 printk(KERN_WARNING
"ROSE: received unknown %02X with LCI 000\n", frametype
);
169 if (neigh
->restarted
) {
170 while ((skbn
= skb_dequeue(&neigh
->queue
)) != NULL
)
171 if (!rose_send_frame(skbn
, neigh
))
177 * This routine is called when a Restart Request is needed
179 void rose_transmit_restart_request(struct rose_neigh
*neigh
)
185 len
= AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
+ ROSE_MIN_LEN
+ 3;
187 if ((skb
= alloc_skb(len
, GFP_ATOMIC
)) == NULL
)
190 skb_reserve(skb
, AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
);
192 dptr
= skb_put(skb
, ROSE_MIN_LEN
+ 3);
194 *dptr
++ = AX25_P_ROSE
;
197 *dptr
++ = ROSE_RESTART_REQUEST
;
198 *dptr
++ = ROSE_DTE_ORIGINATED
;
201 if (!rose_send_frame(skb
, neigh
))
206 * This routine is called when a Restart Confirmation is needed
208 void rose_transmit_restart_confirmation(struct rose_neigh
*neigh
)
214 len
= AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
+ ROSE_MIN_LEN
+ 1;
216 if ((skb
= alloc_skb(len
, GFP_ATOMIC
)) == NULL
)
219 skb_reserve(skb
, AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
);
221 dptr
= skb_put(skb
, ROSE_MIN_LEN
+ 1);
223 *dptr
++ = AX25_P_ROSE
;
226 *dptr
++ = ROSE_RESTART_CONFIRMATION
;
228 if (!rose_send_frame(skb
, neigh
))
233 * This routine is called when a Diagnostic is required.
235 void rose_transmit_diagnostic(struct rose_neigh
*neigh
, unsigned char diag
)
241 len
= AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
+ ROSE_MIN_LEN
+ 2;
243 if ((skb
= alloc_skb(len
, GFP_ATOMIC
)) == NULL
)
246 skb_reserve(skb
, AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
);
248 dptr
= skb_put(skb
, ROSE_MIN_LEN
+ 2);
250 *dptr
++ = AX25_P_ROSE
;
253 *dptr
++ = ROSE_DIAGNOSTIC
;
256 if (!rose_send_frame(skb
, neigh
))
261 * This routine is called when a Clear Request is needed outside of the context
262 * of a connected socket.
264 void rose_transmit_clear_request(struct rose_neigh
*neigh
, unsigned int lci
, unsigned char cause
, unsigned char diagnostic
)
270 len
= AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
+ ROSE_MIN_LEN
+ 3;
272 if ((skb
= alloc_skb(len
, GFP_ATOMIC
)) == NULL
)
275 skb_reserve(skb
, AX25_BPQ_HEADER_LEN
+ AX25_MAX_HEADER_LEN
);
277 dptr
= skb_put(skb
, ROSE_MIN_LEN
+ 3);
279 *dptr
++ = AX25_P_ROSE
;
280 *dptr
++ = ((lci
>> 8) & 0x0F) | ROSE_GFI
;
281 *dptr
++ = ((lci
>> 0) & 0xFF);
282 *dptr
++ = ROSE_CLEAR_REQUEST
;
284 *dptr
++ = diagnostic
;
286 if (!rose_send_frame(skb
, neigh
))
290 void rose_transmit_link(struct sk_buff
*skb
, struct rose_neigh
*neigh
)
295 if (call_fw_firewall(PF_ROSE
, skb
->dev
, skb
->data
, NULL
, &skb
) != FW_ACCEPT
) {
301 if (neigh
->loopback
) {
302 rose_loopback_queue(skb
, neigh
);
306 if (!rose_link_up(neigh
))
307 neigh
->restarted
= 0;
309 dptr
= skb_push(skb
, 1);
310 *dptr
++ = AX25_P_ROSE
;
312 if (neigh
->restarted
) {
313 if (!rose_send_frame(skb
, neigh
))
316 skb_queue_tail(&neigh
->queue
, skb
);
318 if (!rose_t0timer_running(neigh
)) {
319 rose_transmit_restart_request(neigh
);
321 rose_start_t0timer(neigh
);