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 003 Jonathan(G4KLX) Created this file from nr_loopback.c.
17 #include <linux/types.h>
18 #include <linux/socket.h>
19 #include <linux/timer.h>
21 #include <linux/skbuff.h>
23 #include <linux/init.h>
25 static struct sk_buff_head loopback_queue;
26 static struct timer_list loopback_timer;
28 static void rose_set_loopback_timer(void);
30 void rose_loopback_init(void)
32 skb_queue_head_init(&loopback_queue);
34 init_timer(&loopback_timer);
37 static int rose_loopback_running(void)
39 return timer_pending(&loopback_timer);
42 int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh)
46 skbn = skb_clone(skb, GFP_ATOMIC);
51 skb_queue_tail(&loopback_queue, skbn);
53 if (!rose_loopback_running())
54 rose_set_loopback_timer();
60 static void rose_loopback_timer(unsigned long);
62 static void rose_set_loopback_timer(void)
64 del_timer(&loopback_timer);
66 loopback_timer.data = 0;
67 loopback_timer.function = &rose_loopback_timer;
68 loopback_timer.expires = jiffies + 10;
70 add_timer(&loopback_timer);
73 static void rose_loopback_timer(unsigned long param)
76 struct net_device *dev;
79 unsigned short frametype;
80 unsigned int lci_i, lci_o;
82 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {
83 lci_i = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF);
84 frametype = skb->data[2];
85 dest = (rose_address *)(skb->data + 4);
86 lci_o = 0xFFF - lci_i;
88 skb->h.raw = skb->data;
90 if ((sk = rose_find_socket(lci_o, rose_loopback_neigh)) != NULL) {
91 if (rose_process_rx_frame(sk, skb) == 0)
96 if (frametype == ROSE_CALL_REQUEST) {
97 if ((dev = rose_dev_get(dest)) != NULL) {
98 if (rose_rx_call_request(skb, dev, rose_loopback_neigh, lci_o) == 0)
109 void __exit rose_loopback_clear(void)
113 del_timer(&loopback_timer);
115 while ((skb = skb_dequeue(&loopback_queue)) != NULL) {