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/errno.h>
18 #include <linux/types.h>
19 #include <linux/socket.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>
28 #include <linux/inet.h>
29 #include <linux/netdevice.h>
30 #include <linux/skbuff.h>
32 #include <asm/segment.h>
33 #include <asm/system.h>
34 #include <linux/fcntl.h>
36 #include <linux/interrupt.h>
37 #include <linux/netfilter.h>
40 static void rose_ftimer_expiry(unsigned long);
41 static void rose_t0timer_expiry(unsigned long);
43 void rose_start_ftimer(struct rose_neigh *neigh)
45 del_timer(&neigh->ftimer);
47 neigh->ftimer.data = (unsigned long)neigh;
48 neigh->ftimer.function = &rose_ftimer_expiry;
49 neigh->ftimer.expires = jiffies + sysctl_rose_link_fail_timeout;
51 add_timer(&neigh->ftimer);
54 void rose_start_t0timer(struct rose_neigh *neigh)
56 del_timer(&neigh->t0timer);
58 neigh->t0timer.data = (unsigned long)neigh;
59 neigh->t0timer.function = &rose_t0timer_expiry;
60 neigh->t0timer.expires = jiffies + sysctl_rose_restart_request_timeout;
62 add_timer(&neigh->t0timer);
65 void rose_stop_ftimer(struct rose_neigh *neigh)
67 del_timer(&neigh->ftimer);
70 void rose_stop_t0timer(struct rose_neigh *neigh)
72 del_timer(&neigh->t0timer);
75 int rose_ftimer_running(struct rose_neigh *neigh)
77 return timer_pending(&neigh->ftimer);
80 int rose_t0timer_running(struct rose_neigh *neigh)
82 return timer_pending(&neigh->t0timer);
85 static void rose_ftimer_expiry(unsigned long param)
89 static void rose_t0timer_expiry(unsigned long param)
91 struct rose_neigh *neigh = (struct rose_neigh *)param;
93 rose_transmit_restart_request(neigh);
97 rose_start_t0timer(neigh);
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
105 static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
107 ax25_address *rose_call;
109 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
110 rose_call = (ax25_address *)neigh->dev->dev_addr;
112 rose_call = &rose_callsign;
114 neigh->ax25 = ax25_send_frame(skb, 260, rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
116 return (neigh->ax25 != NULL);
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
124 static int rose_link_up(struct rose_neigh *neigh)
126 ax25_address *rose_call;
128 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
129 rose_call = (ax25_address *)neigh->dev->dev_addr;
131 rose_call = &rose_callsign;
133 neigh->ax25 = ax25_find_cb(rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
135 return (neigh->ax25 != NULL);
139 * This handles all restart and diagnostic frames.
141 void rose_link_rx_restart(struct sk_buff *skb, struct rose_neigh *neigh, unsigned short frametype)
143 struct sk_buff *skbn;
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);
153 case ROSE_RESTART_CONFIRMATION:
154 rose_stop_t0timer(neigh);
155 neigh->restarted = 1;
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]);
163 printk(KERN_WARNING "ROSE: received unknown %02X with LCI 000\n", frametype);
167 if (neigh->restarted) {
168 while ((skbn = skb_dequeue(&neigh->queue)) != NULL)
169 if (!rose_send_frame(skbn, neigh))
175 * This routine is called when a Restart Request is needed
177 void rose_transmit_restart_request(struct rose_neigh *neigh)
183 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
185 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
188 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
190 dptr = skb_put(skb, ROSE_MIN_LEN + 3);
192 *dptr++ = AX25_P_ROSE;
195 *dptr++ = ROSE_RESTART_REQUEST;
196 *dptr++ = ROSE_DTE_ORIGINATED;
199 if (!rose_send_frame(skb, neigh))
204 * This routine is called when a Restart Confirmation is needed
206 void rose_transmit_restart_confirmation(struct rose_neigh *neigh)
212 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 1;
214 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
217 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
219 dptr = skb_put(skb, ROSE_MIN_LEN + 1);
221 *dptr++ = AX25_P_ROSE;
224 *dptr++ = ROSE_RESTART_CONFIRMATION;
226 if (!rose_send_frame(skb, neigh))
231 * This routine is called when a Diagnostic is required.
233 void rose_transmit_diagnostic(struct rose_neigh *neigh, unsigned char diag)
239 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 2;
241 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
244 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
246 dptr = skb_put(skb, ROSE_MIN_LEN + 2);
248 *dptr++ = AX25_P_ROSE;
251 *dptr++ = ROSE_DIAGNOSTIC;
254 if (!rose_send_frame(skb, neigh))
259 * This routine is called when a Clear Request is needed outside of the context
260 * of a connected socket.
262 void rose_transmit_clear_request(struct rose_neigh *neigh, unsigned int lci, unsigned char cause, unsigned char diagnostic)
267 struct net_device *first;
270 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
272 first = rose_dev_first();
274 faclen = 6 + AX25_ADDR_LEN + 3 + ROSE_ADDR_LEN;
276 if ((skb = alloc_skb(len + faclen, GFP_ATOMIC)) == NULL)
279 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
281 dptr = skb_put(skb, ROSE_MIN_LEN + 3 + faclen);
283 *dptr++ = AX25_P_ROSE;
284 *dptr++ = ((lci >> 8) & 0x0F) | ROSE_GFI;
285 *dptr++ = ((lci >> 0) & 0xFF);
286 *dptr++ = ROSE_CLEAR_REQUEST;
288 *dptr++ = diagnostic;
291 *dptr++ = 0x00; /* Address length */
292 *dptr++ = 4 + AX25_ADDR_LEN + 3 + ROSE_ADDR_LEN; /* Facilities length */
294 *dptr++ = FAC_NATIONAL;
295 *dptr++ = FAC_NATIONAL_FAIL_CALL;
296 *dptr++ = AX25_ADDR_LEN;
297 memcpy(dptr, &rose_callsign, AX25_ADDR_LEN);
298 dptr += AX25_ADDR_LEN;
299 *dptr++ = FAC_NATIONAL_FAIL_ADD;
300 *dptr++ = ROSE_ADDR_LEN + 1;
301 *dptr++ = ROSE_ADDR_LEN * 2;
302 memcpy(dptr, first->dev_addr, ROSE_ADDR_LEN);
305 if (!rose_send_frame(skb, neigh))
309 void rose_transmit_link(struct sk_buff *skb, struct rose_neigh *neigh)
314 if (call_fw_firewall(PF_ROSE, skb->dev, skb->data, NULL, &skb) != FW_ACCEPT) {
320 if (neigh->loopback) {
321 rose_loopback_queue(skb, neigh);
325 if (!rose_link_up(neigh))
326 neigh->restarted = 0;
328 dptr = skb_push(skb, 1);
329 *dptr++ = AX25_P_ROSE;
331 if (neigh->restarted) {
332 if (!rose_send_frame(skb, neigh))
335 skb_queue_tail(&neigh->queue, skb);
337 if (!rose_t0timer_running(neigh)) {
338 rose_transmit_restart_request(neigh);
340 rose_start_t0timer(neigh);