2 * An implementation of the Acorn Econet and AUN protocols.
3 * Philip Blundell <philb@gnu.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
12 #include <linux/config.h>
13 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/string.h>
20 #include <linux/socket.h>
21 #include <linux/sockios.h>
23 #include <linux/errno.h>
24 #include <linux/interrupt.h>
25 #include <linux/if_ether.h>
26 #include <linux/netdevice.h>
27 #include <linux/inetdevice.h>
28 #include <linux/route.h>
29 #include <linux/inet.h>
30 #include <linux/etherdevice.h>
31 #include <linux/if_arp.h>
32 #include <linux/wireless.h>
33 #include <linux/skbuff.h>
35 #include <net/inet_common.h>
36 #include <linux/stat.h>
37 #include <linux/init.h>
38 #include <linux/if_ec.h>
41 #include <linux/spinlock.h>
43 #include <asm/uaccess.h>
44 #include <asm/system.h>
45 #include <asm/bitops.h>
47 static struct proto_ops econet_ops
;
48 static struct sock
*econet_sklist
;
50 /* Since there are only 256 possible network numbers (or fewer, depends
51 how you count) it makes sense to use a simple lookup table. */
52 static struct net_device
*net2dev_map
[256];
54 #define EC_PORT_IP 0xd2
56 #ifdef CONFIG_ECONET_AUNUDP
57 static spinlock_t aun_queue_lock
;
58 static struct socket
*udpsock
;
59 #define AUN_PORT 0x8000
64 unsigned char code
; /* AUN magic protocol byte */
71 static unsigned long aun_seq
= 0;
73 /* Queue of packets waiting to be transmitted. */
74 static struct sk_buff_head aun_queue
;
75 static struct timer_list ab_cleanup_timer
;
77 #endif /* CONFIG_ECONET_AUNUDP */
79 /* Per-packet information */
82 struct sockaddr_ec sec
;
83 unsigned long cookie
; /* Supplied by user. */
84 #ifdef CONFIG_ECONET_AUNUDP
86 unsigned long seq
; /* Sequencing */
87 unsigned long timeout
; /* Timeout */
88 unsigned long start
; /* jiffies */
90 #ifdef CONFIG_ECONET_NATIVE
91 void (*sent
)(struct sk_buff
*, int result
);
96 * Pull a packet from our receive queue and hand it to the user.
97 * If necessary we block.
100 static int econet_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int len
,
101 int flags
, struct scm_cookie
*scm
)
103 struct sock
*sk
= sock
->sk
;
107 msg
->msg_namelen
= sizeof(struct sockaddr_ec
);
110 * Call the generic datagram receiver. This handles all sorts
111 * of horrible races and re-entrancy so we can forget about it
112 * in the protocol layers.
114 * Now it will return ENETDOWN, if device have just gone down,
115 * but then it will block.
118 skb
=skb_recv_datagram(sk
,flags
,flags
&MSG_DONTWAIT
,&err
);
121 * An error occurred so return it. Because skb_recv_datagram()
122 * handles the blocking we don't see and worry about blocking
130 * You lose any data beyond the buffer you gave. If it worries a
131 * user program they can ask the device for its MTU anyway.
138 msg
->msg_flags
|=MSG_TRUNC
;
141 /* We can't use skb_copy_datagram here */
142 err
= memcpy_toiovec(msg
->msg_iov
, skb
->data
, copied
);
145 sk
->stamp
=skb
->stamp
;
148 memcpy(msg
->msg_name
, skb
->cb
, msg
->msg_namelen
);
151 * Free or return the buffer as appropriate. Again this
152 * hides all the races and re-entrancy issues from us.
157 skb_free_datagram(sk
, skb
);
163 * Bind an Econet socket.
166 static int econet_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
168 struct sockaddr_ec
*sec
= (struct sockaddr_ec
*)uaddr
;
169 struct sock
*sk
=sock
->sk
;
175 if (addr_len
< sizeof(struct sockaddr_ec
))
177 if (sec
->sec_family
!= AF_ECONET
)
180 sk
->protinfo
.af_econet
->cb
= sec
->cb
;
181 sk
->protinfo
.af_econet
->port
= sec
->port
;
182 sk
->protinfo
.af_econet
->station
= sec
->addr
.station
;
183 sk
->protinfo
.af_econet
->net
= sec
->addr
.net
;
189 * Queue a transmit result for the user to be told about.
192 static void tx_result(struct sock
*sk
, unsigned long cookie
, int result
)
194 struct sk_buff
*skb
= alloc_skb(0, GFP_ATOMIC
);
196 struct sockaddr_ec
*sec
;
200 printk(KERN_DEBUG
"ec: memory squeeze, transmit result dropped.\n");
204 eb
= (struct ec_cb
*)&skb
->cb
;
205 sec
= (struct sockaddr_ec
*)&eb
->sec
;
206 memset(sec
, 0, sizeof(struct sockaddr_ec
));
207 sec
->cookie
= cookie
;
208 sec
->type
= ECTYPE_TRANSMIT_STATUS
| result
;
209 sec
->sec_family
= AF_ECONET
;
211 if (sock_queue_rcv_skb(sk
, skb
) < 0)
215 #ifdef CONFIG_ECONET_NATIVE
217 * Called by the Econet hardware driver when a packet transmit
218 * has completed. Tell the user.
221 static void ec_tx_done(struct sk_buff
*skb
, int result
)
223 struct ec_cb
*eb
= (struct ec_cb
*)&skb
->cb
;
224 tx_result(skb
->sk
, eb
->cookie
, result
);
229 * Send a packet. We have to work out which device it's going out on
230 * and hence whether to use real Econet or the UDP emulation.
233 static int econet_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int len
,
234 struct scm_cookie
*scm
)
236 struct sock
*sk
= sock
->sk
;
237 struct sockaddr_ec
*saddr
=(struct sockaddr_ec
*)msg
->msg_name
;
238 struct net_device
*dev
;
241 unsigned char port
, cb
;
244 #ifdef CONFIG_ECONET_NATIVE
245 unsigned short proto
= 0;
247 #ifdef CONFIG_ECONET_AUNUDP
248 struct msghdr udpmsg
;
249 struct iovec iov
[msg
->msg_iovlen
+1];
251 struct sockaddr_in udpdest
;
252 __kernel_size_t size
;
261 if (msg
->msg_flags
&~MSG_DONTWAIT
)
265 * Get and verify the address.
269 addr
.station
= sk
->protinfo
.af_econet
->station
;
270 addr
.net
= sk
->protinfo
.af_econet
->net
;
271 port
= sk
->protinfo
.af_econet
->port
;
272 cb
= sk
->protinfo
.af_econet
->cb
;
274 if (msg
->msg_namelen
< sizeof(struct sockaddr_ec
))
276 addr
.station
= saddr
->addr
.station
;
277 addr
.net
= saddr
->addr
.net
;
282 /* Look for a device with the right network number. */
283 dev
= net2dev_map
[addr
.net
];
285 /* If not directly reachable, use some default */
288 dev
= net2dev_map
[0];
289 /* No interfaces at all? */
294 if (dev
->type
== ARPHRD_ECONET
)
296 /* Real hardware Econet. We're not worthy etc. */
297 #ifdef CONFIG_ECONET_NATIVE
298 atomic_inc(&dev
->refcnt
);
300 skb
= sock_alloc_send_skb(sk
, len
+dev
->hard_header_len
+15, 0,
301 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
305 skb_reserve(skb
, (dev
->hard_header_len
+15)&~15);
306 skb
->nh
.raw
= skb
->data
;
308 eb
= (struct ec_cb
*)&skb
->cb
;
310 eb
->cookie
= saddr
->cookie
;
312 eb
->sent
= ec_tx_done
;
314 if (dev
->hard_header
) {
316 struct ec_framehdr
*fh
;
318 res
= dev
->hard_header(skb
, dev
, ntohs(proto
),
320 /* Poke in our control byte and
321 port number. Hack, hack. */
322 fh
= (struct ec_framehdr
*)(skb
->data
);
325 if (sock
->type
!= SOCK_DGRAM
) {
326 skb
->tail
= skb
->data
;
332 /* Copy the data. Returns -EFAULT on error */
333 err
= memcpy_fromiovec(skb_put(skb
,len
), msg
->msg_iov
, len
);
334 skb
->protocol
= proto
;
336 skb
->priority
= sk
->priority
;
341 if (!(dev
->flags
& IFF_UP
))
363 #ifdef CONFIG_ECONET_AUNUDP
364 /* AUN virtual Econet. */
367 return -ENETDOWN
; /* No socket - can't send */
369 /* Make up a UDP datagram and hand it off to some higher intellect. */
371 memset(&udpdest
, 0, sizeof(udpdest
));
372 udpdest
.sin_family
= AF_INET
;
373 udpdest
.sin_port
= htons(AUN_PORT
);
375 /* At the moment we use the stupid Acorn scheme of Econet address
376 y.x maps to IP a.b.c.x. This should be replaced with something
377 more flexible and more aware of subnet masks. */
379 struct in_device
*idev
= in_dev_get(dev
);
380 unsigned long network
= 0;
382 read_lock(&idev
->lock
);
384 network
= ntohl(idev
->ifa_list
->ifa_address
) &
385 0xffffff00; /* !!! */
386 read_unlock(&idev
->lock
);
389 udpdest
.sin_addr
.s_addr
= htonl(network
| addr
.station
);
394 ah
.code
= 2; /* magic */
397 /* tack our header on the front of the iovec */
398 size
= sizeof(struct aunhdr
);
399 iov
[0].iov_base
= (void *)&ah
;
400 iov
[0].iov_len
= size
;
401 for (i
= 0; i
< msg
->msg_iovlen
; i
++) {
402 void *base
= msg
->msg_iov
[i
].iov_base
;
403 size_t len
= msg
->msg_iov
[i
].iov_len
;
404 /* Check it now since we switch to KERNEL_DS later. */
405 if ((err
= verify_area(VERIFY_READ
, base
, len
)) < 0)
407 iov
[i
+1].iov_base
= base
;
408 iov
[i
+1].iov_len
= len
;
412 /* Get a skbuff (no data, just holds our cb information) */
413 if ((skb
= sock_alloc_send_skb(sk
, 0, 0,
414 msg
->msg_flags
& MSG_DONTWAIT
, &err
)) == NULL
)
417 eb
= (struct ec_cb
*)&skb
->cb
;
419 eb
->cookie
= saddr
->cookie
;
420 eb
->timeout
= (5*HZ
);
423 eb
->seq
= (aun_seq
++);
426 skb_queue_tail(&aun_queue
, skb
);
428 udpmsg
.msg_name
= (void *)&udpdest
;
429 udpmsg
.msg_namelen
= sizeof(udpdest
);
430 udpmsg
.msg_iov
= &iov
[0];
431 udpmsg
.msg_iovlen
= msg
->msg_iovlen
+ 1;
432 udpmsg
.msg_control
= NULL
;
433 udpmsg
.msg_controllen
= 0;
436 oldfs
= get_fs(); set_fs(KERNEL_DS
); /* More privs :-) */
437 err
= sock_sendmsg(udpsock
, &udpmsg
, size
);
446 * Look up the address of a socket.
449 static int econet_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
450 int *uaddr_len
, int peer
)
452 struct sock
*sk
= sock
->sk
;
453 struct sockaddr_ec
*sec
= (struct sockaddr_ec
*)uaddr
;
458 sec
->sec_family
= AF_ECONET
;
459 sec
->port
= sk
->protinfo
.af_econet
->port
;
460 sec
->addr
.station
= sk
->protinfo
.af_econet
->station
;
461 sec
->addr
.net
= sk
->protinfo
.af_econet
->net
;
463 *uaddr_len
= sizeof(*sec
);
467 static void econet_destroy_timer(unsigned long data
)
469 struct sock
*sk
=(struct sock
*)data
;
471 if (!atomic_read(&sk
->wmem_alloc
) && !atomic_read(&sk
->rmem_alloc
)) {
477 sk
->timer
.expires
=jiffies
+10*HZ
;
478 add_timer(&sk
->timer
);
479 printk(KERN_DEBUG
"econet socket destroy delayed\n");
483 * Close an econet socket.
486 static int econet_release(struct socket
*sock
)
489 struct sock
*sk
= sock
->sk
;
494 sklist_remove_socket(&econet_sklist
, sk
);
497 * Now the socket is dead. No more input will appear.
500 sk
->state_change(sk
); /* It is useless. Just for sanity. */
508 while ((skb
=skb_dequeue(&sk
->receive_queue
))!=NULL
)
511 if (atomic_read(&sk
->rmem_alloc
) || atomic_read(&sk
->wmem_alloc
)) {
512 sk
->timer
.data
=(unsigned long)sk
;
513 sk
->timer
.expires
=jiffies
+HZ
;
514 sk
->timer
.function
=econet_destroy_timer
;
515 add_timer(&sk
->timer
);
525 * Create an Econet socket
528 static int econet_create(struct socket
*sock
, int protocol
)
533 /* Econet only provides datagram services. */
534 if (sock
->type
!= SOCK_DGRAM
)
535 return -ESOCKTNOSUPPORT
;
537 sock
->state
= SS_UNCONNECTED
;
541 sk
= sk_alloc(PF_ECONET
, GFP_KERNEL
, 1);
546 sock
->ops
= &econet_ops
;
547 sock_init_data(sock
,sk
);
549 sk
->protinfo
.af_econet
= kmalloc(sizeof(struct econet_opt
), GFP_KERNEL
);
550 if (sk
->protinfo
.af_econet
== NULL
)
552 memset(sk
->protinfo
.af_econet
, 0, sizeof(struct econet_opt
));
554 sk
->family
= PF_ECONET
;
557 sklist_insert_socket(&econet_sklist
, sk
);
568 * Handle Econet specific ioctls
571 static int ec_dev_ioctl(struct socket
*sock
, unsigned int cmd
, void *arg
)
574 struct ec_device
*edev
;
575 struct net_device
*dev
;
576 struct sockaddr_ec
*sec
;
579 * Fetch the caller's info block into kernel space
582 if (copy_from_user(&ifr
, arg
, sizeof(struct ifreq
)))
585 if ((dev
= dev_get_by_name(ifr
.ifr_name
)) == NULL
)
588 sec
= (struct sockaddr_ec
*)&ifr
.ifr_addr
;
596 /* Magic up a new one. */
597 edev
= kmalloc(sizeof(struct ec_device
), GFP_KERNEL
);
599 printk("af_ec: memory squeeze.\n");
603 memset(edev
, 0, sizeof(struct ec_device
));
607 net2dev_map
[edev
->net
] = NULL
;
608 edev
->station
= sec
->addr
.station
;
609 edev
->net
= sec
->addr
.net
;
610 net2dev_map
[sec
->addr
.net
] = dev
;
612 net2dev_map
[0] = dev
;
623 memset(sec
, 0, sizeof(struct sockaddr_ec
));
624 sec
->addr
.station
= edev
->station
;
625 sec
->addr
.net
= edev
->net
;
626 sec
->sec_family
= AF_ECONET
;
628 if (copy_to_user(arg
, &ifr
, sizeof(struct ifreq
)))
638 * Handle generic ioctls
641 static int econet_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
643 struct sock
*sk
= sock
->sk
;
650 if (get_user(pid
, (int *) arg
))
652 if (current
->pid
!= pid
&& current
->pgrp
!= -pid
&& !capable(CAP_NET_ADMIN
))
658 return put_user(sk
->proc
, (int *)arg
);
660 if(sk
->stamp
.tv_sec
==0)
662 return copy_to_user((void *)arg
, &sk
->stamp
, sizeof(struct timeval
)) ? -EFAULT
: 0;
682 case SIOCSIFHWBROADCAST
:
683 return(dev_ioctl(cmd
,(void *) arg
));
687 return ec_dev_ioctl(sock
, cmd
, (void *)arg
);
691 return(dev_ioctl(cmd
,(void *) arg
));
697 static struct net_proto_family econet_family_ops
= {
702 static struct proto_ops
SOCKOPS_WRAPPED(econet_ops
) = {
705 release
: econet_release
,
707 connect
: sock_no_connect
,
708 socketpair
: sock_no_socketpair
,
709 accept
: sock_no_accept
,
710 getname
: econet_getname
,
713 listen
: sock_no_listen
,
714 shutdown
: sock_no_shutdown
,
715 setsockopt
: sock_no_setsockopt
,
716 getsockopt
: sock_no_getsockopt
,
717 sendmsg
: econet_sendmsg
,
718 recvmsg
: econet_recvmsg
,
722 #include <linux/smp_lock.h>
723 SOCKOPS_WRAP(econet
, PF_ECONET
);
726 * Find the listening socket, if any, for the given data.
729 struct sock
*ec_listening_socket(unsigned char port
, unsigned char
730 station
, unsigned char net
)
732 struct sock
*sk
= econet_sklist
;
736 struct econet_opt
*opt
= sk
->protinfo
.af_econet
;
737 if ((opt
->port
== port
|| opt
->port
== 0) &&
738 (opt
->station
== station
|| opt
->station
== 0) &&
739 (opt
->net
== net
|| opt
->net
== 0))
749 * Queue a received packet for a socket.
752 static int ec_queue_packet(struct sock
*sk
, struct sk_buff
*skb
,
753 unsigned char stn
, unsigned char net
,
754 unsigned char cb
, unsigned char port
)
756 struct ec_cb
*eb
= (struct ec_cb
*)&skb
->cb
;
757 struct sockaddr_ec
*sec
= (struct sockaddr_ec
*)&eb
->sec
;
759 memset(sec
, 0, sizeof(struct sockaddr_ec
));
760 sec
->sec_family
= AF_ECONET
;
761 sec
->type
= ECTYPE_PACKET_RECEIVED
;
765 sec
->addr
.station
= stn
;
767 return sock_queue_rcv_skb(sk
, skb
);
770 #ifdef CONFIG_ECONET_AUNUDP
773 * Send an AUN protocol response.
776 static void aun_send_response(__u32 addr
, unsigned long seq
, int code
, int cb
)
778 struct sockaddr_in sin
;
781 struct msghdr udpmsg
;
785 memset(&sin
, 0, sizeof(sin
));
786 sin
.sin_family
= AF_INET
;
787 sin
.sin_port
= htons(AUN_PORT
);
788 sin
.sin_addr
.s_addr
= addr
;
796 iov
.iov_base
= (void *)&ah
;
797 iov
.iov_len
= sizeof(ah
);
799 udpmsg
.msg_name
= (void *)&sin
;
800 udpmsg
.msg_namelen
= sizeof(sin
);
801 udpmsg
.msg_iov
= &iov
;
802 udpmsg
.msg_iovlen
= 1;
803 udpmsg
.msg_control
= NULL
;
804 udpmsg
.msg_controllen
= 0;
807 oldfs
= get_fs(); set_fs(KERNEL_DS
);
808 err
= sock_sendmsg(udpsock
, &udpmsg
, sizeof(ah
));
814 * Handle incoming AUN packets. Work out if anybody wants them,
815 * and send positive or negative acknowledgements as appropriate.
818 static void aun_incoming(struct sk_buff
*skb
, struct aunhdr
*ah
, size_t len
)
820 struct iphdr
*ip
= skb
->nh
.iph
;
821 unsigned char stn
= ntohl(ip
->saddr
) & 0xff;
823 struct sk_buff
*newskb
;
824 struct ec_device
*edev
= skb
->dev
->ec_ptr
;
829 if ((sk
= ec_listening_socket(ah
->port
, stn
, edev
->net
)) == NULL
)
830 goto bad
; /* Nobody wants it */
832 newskb
= alloc_skb((len
- sizeof(struct aunhdr
) + 15) & ~15,
836 printk(KERN_DEBUG
"AUN: memory squeeze, dropping packet.\n");
837 /* Send nack and hope sender tries again */
841 memcpy(skb_put(newskb
, len
- sizeof(struct aunhdr
)), (void *)(ah
+1),
842 len
- sizeof(struct aunhdr
));
844 if (ec_queue_packet(sk
, newskb
, stn
, edev
->net
, ah
->cb
, ah
->port
))
846 /* Socket is bankrupt. */
851 aun_send_response(ip
->saddr
, ah
->handle
, 3, 0);
855 aun_send_response(ip
->saddr
, ah
->handle
, 4, 0);
859 * Handle incoming AUN transmit acknowledgements. If the sequence
860 * number matches something in our backlog then kill it and tell
861 * the user. If the remote took too long to reply then we may have
862 * dropped the packet already.
865 static void aun_tx_ack(unsigned long seq
, int result
)
871 spin_lock_irqsave(&aun_queue_lock
, flags
);
872 skb
= skb_peek(&aun_queue
);
873 while (skb
&& skb
!= (struct sk_buff
*)&aun_queue
)
875 struct sk_buff
*newskb
= skb
->next
;
876 eb
= (struct ec_cb
*)&skb
->cb
;
882 spin_unlock_irqrestore(&aun_queue_lock
, flags
);
883 printk(KERN_DEBUG
"AUN: unknown sequence %ld\n", seq
);
887 tx_result(skb
->sk
, eb
->cookie
, result
);
889 spin_unlock_irqrestore(&aun_queue_lock
, flags
);
894 * Deal with received AUN frames - sort out what type of thing it is
895 * and hand it to the right function.
898 static void aun_data_available(struct sock
*sk
, int slen
)
907 while ((skb
= skb_recv_datagram(sk
, 0, 1, &err
)) == NULL
) {
908 if (err
== -EAGAIN
) {
909 printk(KERN_ERR
"AUN: no data available?!");
912 printk(KERN_DEBUG
"AUN: recvfrom() error %d\n", -err
);
915 data
= skb
->h
.raw
+ sizeof(struct udphdr
);
916 ah
= (struct aunhdr
*)data
;
917 len
= skb
->len
- sizeof(struct udphdr
);
923 aun_incoming(skb
, ah
, len
);
926 aun_tx_ack(ah
->handle
, ECTYPE_TRANSMIT_OK
);
929 aun_tx_ack(ah
->handle
, ECTYPE_TRANSMIT_NOT_LISTENING
);
932 /* This isn't quite right yet. */
934 aun_send_response(ip
->saddr
, ah
->handle
, 6, ah
->cb
);
938 printk(KERN_DEBUG
"unknown AUN packet (type %d)\n", data
[0]);
941 skb_free_datagram(sk
, skb
);
945 * Called by the timer to manage the AUN transmit queue. If a packet
946 * was sent to a dead or nonexistent host then we will never get an
947 * acknowledgement back. After a few seconds we need to spot this and
951 static void ab_cleanup(unsigned long h
)
956 spin_lock_irqsave(&aun_queue_lock
, flags
);
957 skb
= skb_peek(&aun_queue
);
958 while (skb
&& skb
!= (struct sk_buff
*)&aun_queue
)
960 struct sk_buff
*newskb
= skb
->next
;
961 struct ec_cb
*eb
= (struct ec_cb
*)&skb
->cb
;
962 if ((jiffies
- eb
->start
) > eb
->timeout
)
964 tx_result(skb
->sk
, eb
->cookie
,
965 ECTYPE_TRANSMIT_NOT_PRESENT
);
971 spin_unlock_irqrestore(&aun_queue_lock
, flags
);
973 mod_timer(&ab_cleanup_timer
, jiffies
+ (HZ
*2));
976 static int __init
aun_udp_initialise(void)
979 struct sockaddr_in sin
;
981 skb_queue_head_init(&aun_queue
);
982 spin_lock_init(&aun_queue_lock
);
983 init_timer(&ab_cleanup_timer
);
984 ab_cleanup_timer
.expires
= jiffies
+ (HZ
*2);
985 ab_cleanup_timer
.function
= ab_cleanup
;
986 add_timer(&ab_cleanup_timer
);
988 memset(&sin
, 0, sizeof(sin
));
989 sin
.sin_port
= htons(AUN_PORT
);
991 /* We can count ourselves lucky Acorn machines are too dim to
993 if ((error
= sock_create(PF_INET
, SOCK_DGRAM
, 0, &udpsock
)) < 0)
995 printk("AUN: socket error %d\n", -error
);
999 udpsock
->sk
->reuse
= 1;
1000 udpsock
->sk
->allocation
= GFP_ATOMIC
; /* we're going to call it
1003 error
= udpsock
->ops
->bind(udpsock
, (struct sockaddr
*)&sin
,
1007 printk("AUN: bind error %d\n", -error
);
1011 udpsock
->sk
->data_ready
= aun_data_available
;
1016 sock_release(udpsock
);
1022 #ifdef CONFIG_ECONET_NATIVE
1025 * Receive an Econet frame from a device.
1028 static int econet_rcv(struct sk_buff
*skb
, struct net_device
*dev
, struct packet_type
*pt
)
1030 struct ec_framehdr
*hdr
= (struct ec_framehdr
*)skb
->data
;
1032 struct ec_device
*edev
= dev
->ec_ptr
;
1040 if (skb
->len
< sizeof(struct ec_framehdr
))
1042 /* Frame is too small to be any use */
1047 /* First check for encapsulated IP */
1048 if (hdr
->port
== EC_PORT_IP
)
1050 skb
->protocol
= htons(ETH_P_IP
);
1051 skb_pull(skb
, sizeof(struct ec_framehdr
));
1056 sk
= ec_listening_socket(hdr
->port
, hdr
->src_stn
, hdr
->src_net
);
1063 return ec_queue_packet(sk
, skb
, edev
->net
, hdr
->src_stn
, hdr
->cb
,
1067 struct packet_type econet_packet_type
=
1076 static void econet_hw_initialise(void)
1078 econet_packet_type
.type
= htons(ETH_P_ECONET
);
1079 dev_add_pack(&econet_packet_type
);
1084 static int econet_notifier(struct notifier_block
*this, unsigned long msg
, void *data
)
1086 struct net_device
*dev
= (struct net_device
*)data
;
1087 struct ec_device
*edev
;
1090 case NETDEV_UNREGISTER
:
1091 /* A device has gone down - kill any data we hold for it. */
1095 if (net2dev_map
[0] == dev
)
1097 net2dev_map
[edev
->net
] = NULL
;
1107 struct notifier_block econet_netdev_notifier
={
1113 void __exit
econet_proto_exit(void)
1115 extern void econet_sysctl_unregister(void);
1116 #ifdef CONFIG_ECONET_AUNUDP
1117 del_timer(&ab_cleanup_timer
);
1119 sock_release(udpsock
);
1121 unregister_netdevice_notifier(&econet_netdev_notifier
);
1122 sock_unregister(econet_family_ops
.family
);
1123 #ifdef CONFIG_SYSCTL
1124 econet_sysctl_unregister();
1128 int __init
econet_proto_init(void)
1130 extern void econet_sysctl_register(void);
1131 sock_register(&econet_family_ops
);
1132 #ifdef CONFIG_ECONET_AUNUDP
1133 spin_lock_init(&aun_queue_lock
);
1134 aun_udp_initialise();
1136 #ifdef CONFIG_ECONET_NATIVE
1137 econet_hw_initialise();
1139 register_netdevice_notifier(&econet_netdev_notifier
);
1140 #ifdef CONFIG_SYSCTL
1141 econet_sysctl_register();
1146 module_init(econet_proto_init
);
1147 module_exit(econet_proto_exit
);