Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / net / ax25 / ax25_iface.c
blob15ca9c45304e1aa68c989e0bae2c9181ff65767f
1 /*
2 * AX.25 release 037
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
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.
12 * History
13 * AX.25 036 Jonathan(G4KLX) Split from ax25_timer.c.
16 #include <linux/config.h>
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/uaccess.h>
33 #include <asm/system.h>
34 #include <linux/fcntl.h>
35 #include <linux/mm.h>
36 #include <linux/interrupt.h>
38 static struct protocol_struct {
39 struct protocol_struct *next;
40 unsigned int pid;
41 int (*func)(struct sk_buff *, ax25_cb *);
42 } *protocol_list;
44 static struct linkfail_struct {
45 struct linkfail_struct *next;
46 void (*func)(ax25_cb *, int);
47 } *linkfail_list;
49 static struct listen_struct {
50 struct listen_struct *next;
51 ax25_address callsign;
52 struct net_device *dev;
53 } *listen_list;
55 int ax25_protocol_register(unsigned int pid, int (*func)(struct sk_buff *, ax25_cb *))
57 struct protocol_struct *protocol;
58 unsigned long flags;
60 if (pid == AX25_P_TEXT || pid == AX25_P_SEGMENT)
61 return 0;
62 #ifdef CONFIG_INET
63 if (pid == AX25_P_IP || pid == AX25_P_ARP)
64 return 0;
65 #endif
66 if ((protocol = kmalloc(sizeof(*protocol), GFP_ATOMIC)) == NULL)
67 return 0;
69 protocol->pid = pid;
70 protocol->func = func;
72 save_flags(flags);
73 cli();
75 protocol->next = protocol_list;
76 protocol_list = protocol;
78 restore_flags(flags);
80 return 1;
83 void ax25_protocol_release(unsigned int pid)
85 struct protocol_struct *s, *protocol = protocol_list;
86 unsigned long flags;
88 if (protocol == NULL)
89 return;
91 save_flags(flags);
92 cli();
94 if (protocol->pid == pid) {
95 protocol_list = protocol->next;
96 restore_flags(flags);
97 kfree(protocol);
98 return;
101 while (protocol != NULL && protocol->next != NULL) {
102 if (protocol->next->pid == pid) {
103 s = protocol->next;
104 protocol->next = protocol->next->next;
105 restore_flags(flags);
106 kfree(s);
107 return;
110 protocol = protocol->next;
113 restore_flags(flags);
116 int ax25_linkfail_register(void (*func)(ax25_cb *, int))
118 struct linkfail_struct *linkfail;
119 unsigned long flags;
121 if ((linkfail = kmalloc(sizeof(*linkfail), GFP_ATOMIC)) == NULL)
122 return 0;
124 linkfail->func = func;
126 save_flags(flags);
127 cli();
129 linkfail->next = linkfail_list;
130 linkfail_list = linkfail;
132 restore_flags(flags);
134 return 1;
137 void ax25_linkfail_release(void (*func)(ax25_cb *, int))
139 struct linkfail_struct *s, *linkfail = linkfail_list;
140 unsigned long flags;
142 if (linkfail == NULL)
143 return;
145 save_flags(flags);
146 cli();
148 if (linkfail->func == func) {
149 linkfail_list = linkfail->next;
150 restore_flags(flags);
151 kfree(linkfail);
152 return;
155 while (linkfail != NULL && linkfail->next != NULL) {
156 if (linkfail->next->func == func) {
157 s = linkfail->next;
158 linkfail->next = linkfail->next->next;
159 restore_flags(flags);
160 kfree(s);
161 return;
164 linkfail = linkfail->next;
167 restore_flags(flags);
170 int ax25_listen_register(ax25_address *callsign, struct net_device *dev)
172 struct listen_struct *listen;
173 unsigned long flags;
175 if (ax25_listen_mine(callsign, dev))
176 return 0;
178 if ((listen = kmalloc(sizeof(*listen), GFP_ATOMIC)) == NULL)
179 return 0;
181 listen->callsign = *callsign;
182 listen->dev = dev;
184 save_flags(flags);
185 cli();
187 listen->next = listen_list;
188 listen_list = listen;
190 restore_flags(flags);
192 return 1;
195 void ax25_listen_release(ax25_address *callsign, struct net_device *dev)
197 struct listen_struct *s, *listen = listen_list;
198 unsigned long flags;
200 if (listen == NULL)
201 return;
203 save_flags(flags);
204 cli();
206 if (ax25cmp(&listen->callsign, callsign) == 0 && listen->dev == dev) {
207 listen_list = listen->next;
208 restore_flags(flags);
209 kfree(listen);
210 return;
213 while (listen != NULL && listen->next != NULL) {
214 if (ax25cmp(&listen->next->callsign, callsign) == 0 && listen->next->dev == dev) {
215 s = listen->next;
216 listen->next = listen->next->next;
217 restore_flags(flags);
218 kfree(s);
219 return;
222 listen = listen->next;
225 restore_flags(flags);
228 int (*ax25_protocol_function(unsigned int pid))(struct sk_buff *, ax25_cb *)
230 struct protocol_struct *protocol;
232 for (protocol = protocol_list; protocol != NULL; protocol = protocol->next)
233 if (protocol->pid == pid)
234 return protocol->func;
236 return NULL;
239 int ax25_listen_mine(ax25_address *callsign, struct net_device *dev)
241 struct listen_struct *listen;
243 for (listen = listen_list; listen != NULL; listen = listen->next)
244 if (ax25cmp(&listen->callsign, callsign) == 0 && (listen->dev == dev || listen->dev == NULL))
245 return 1;
247 return 0;
250 void ax25_link_failed(ax25_cb *ax25, int reason)
252 struct linkfail_struct *linkfail;
254 for (linkfail = linkfail_list; linkfail != NULL; linkfail = linkfail->next)
255 (linkfail->func)(ax25, reason);
258 int ax25_protocol_is_registered(unsigned int pid)
260 struct protocol_struct *protocol;
262 for (protocol = protocol_list; protocol != NULL; protocol = protocol->next)
263 if (protocol->pid == pid)
264 return 1;
266 return 0;