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 * 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>
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/uaccess.h>
33 #include <asm/system.h>
34 #include <linux/fcntl.h>
36 #include <linux/interrupt.h>
38 static struct protocol_struct
{
39 struct protocol_struct
*next
;
41 int (*func
)(struct sk_buff
*, ax25_cb
*);
44 static struct linkfail_struct
{
45 struct linkfail_struct
*next
;
46 void (*func
)(ax25_cb
*, int);
49 static struct listen_struct
{
50 struct listen_struct
*next
;
51 ax25_address callsign
;
52 struct net_device
*dev
;
55 int ax25_protocol_register(unsigned int pid
, int (*func
)(struct sk_buff
*, ax25_cb
*))
57 struct protocol_struct
*protocol
;
60 if (pid
== AX25_P_TEXT
|| pid
== AX25_P_SEGMENT
)
63 if (pid
== AX25_P_IP
|| pid
== AX25_P_ARP
)
66 if ((protocol
= kmalloc(sizeof(*protocol
), GFP_ATOMIC
)) == NULL
)
70 protocol
->func
= func
;
75 protocol
->next
= protocol_list
;
76 protocol_list
= protocol
;
83 void ax25_protocol_release(unsigned int pid
)
85 struct protocol_struct
*s
, *protocol
= protocol_list
;
94 if (protocol
->pid
== pid
) {
95 protocol_list
= protocol
->next
;
101 while (protocol
!= NULL
&& protocol
->next
!= NULL
) {
102 if (protocol
->next
->pid
== pid
) {
104 protocol
->next
= protocol
->next
->next
;
105 restore_flags(flags
);
110 protocol
= protocol
->next
;
113 restore_flags(flags
);
116 int ax25_linkfail_register(void (*func
)(ax25_cb
*, int))
118 struct linkfail_struct
*linkfail
;
121 if ((linkfail
= kmalloc(sizeof(*linkfail
), GFP_ATOMIC
)) == NULL
)
124 linkfail
->func
= func
;
129 linkfail
->next
= linkfail_list
;
130 linkfail_list
= linkfail
;
132 restore_flags(flags
);
137 void ax25_linkfail_release(void (*func
)(ax25_cb
*, int))
139 struct linkfail_struct
*s
, *linkfail
= linkfail_list
;
142 if (linkfail
== NULL
)
148 if (linkfail
->func
== func
) {
149 linkfail_list
= linkfail
->next
;
150 restore_flags(flags
);
155 while (linkfail
!= NULL
&& linkfail
->next
!= NULL
) {
156 if (linkfail
->next
->func
== func
) {
158 linkfail
->next
= linkfail
->next
->next
;
159 restore_flags(flags
);
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
;
175 if (ax25_listen_mine(callsign
, dev
))
178 if ((listen
= kmalloc(sizeof(*listen
), GFP_ATOMIC
)) == NULL
)
181 listen
->callsign
= *callsign
;
187 listen
->next
= listen_list
;
188 listen_list
= listen
;
190 restore_flags(flags
);
195 void ax25_listen_release(ax25_address
*callsign
, struct net_device
*dev
)
197 struct listen_struct
*s
, *listen
= listen_list
;
206 if (ax25cmp(&listen
->callsign
, callsign
) == 0 && listen
->dev
== dev
) {
207 listen_list
= listen
->next
;
208 restore_flags(flags
);
213 while (listen
!= NULL
&& listen
->next
!= NULL
) {
214 if (ax25cmp(&listen
->next
->callsign
, callsign
) == 0 && listen
->next
->dev
== dev
) {
216 listen
->next
= listen
->next
->next
;
217 restore_flags(flags
);
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
;
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
))
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
)