2 * IEEE802154.4 socket interface
4 * Copyright 2007, 2008 Siemens AG
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 * Sergey Lapin <slapin@ossfans.org>
17 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
20 #include <linux/net.h>
21 #include <linux/capability.h>
22 #include <linux/module.h>
23 #include <linux/if_arp.h>
25 #include <linux/termios.h> /* For TIOCOUTQ/INQ */
26 #include <linux/list.h>
27 #include <linux/slab.h>
28 #include <net/datalink.h>
29 #include <net/psnap.h>
31 #include <net/tcp_states.h>
32 #include <net/route.h>
34 #include <net/af_ieee802154.h>
35 #include <net/ieee802154_netdev.h>
37 /* Utility function for families */
38 static struct net_device
*
39 ieee802154_get_dev(struct net
*net
, const struct ieee802154_addr
*addr
)
41 struct net_device
*dev
= NULL
;
42 struct net_device
*tmp
;
43 __le16 pan_id
, short_addr
;
44 u8 hwaddr
[IEEE802154_ADDR_LEN
];
47 case IEEE802154_ADDR_LONG
:
48 ieee802154_devaddr_to_raw(hwaddr
, addr
->extended_addr
);
50 dev
= dev_getbyhwaddr_rcu(net
, ARPHRD_IEEE802154
, hwaddr
);
55 case IEEE802154_ADDR_SHORT
:
56 if (addr
->pan_id
== cpu_to_le16(IEEE802154_PANID_BROADCAST
) ||
57 addr
->short_addr
== cpu_to_le16(IEEE802154_ADDR_UNDEF
) ||
58 addr
->short_addr
== cpu_to_le16(IEEE802154_ADDR_BROADCAST
))
63 for_each_netdev(net
, tmp
) {
64 if (tmp
->type
!= ARPHRD_IEEE802154
)
67 pan_id
= tmp
->ieee802154_ptr
->pan_id
;
68 short_addr
= tmp
->ieee802154_ptr
->short_addr
;
69 if (pan_id
== addr
->pan_id
&&
70 short_addr
== addr
->short_addr
) {
80 pr_warn("Unsupported ieee802154 address type: %d\n",
88 static int ieee802154_sock_release(struct socket
*sock
)
90 struct sock
*sk
= sock
->sk
;
94 sk
->sk_prot
->close(sk
, 0);
99 static int ieee802154_sock_sendmsg(struct socket
*sock
, struct msghdr
*msg
,
102 struct sock
*sk
= sock
->sk
;
104 return sk
->sk_prot
->sendmsg(sk
, msg
, len
);
107 static int ieee802154_sock_bind(struct socket
*sock
, struct sockaddr
*uaddr
,
110 struct sock
*sk
= sock
->sk
;
112 if (sk
->sk_prot
->bind
)
113 return sk
->sk_prot
->bind(sk
, uaddr
, addr_len
);
115 return sock_no_bind(sock
, uaddr
, addr_len
);
118 static int ieee802154_sock_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
119 int addr_len
, int flags
)
121 struct sock
*sk
= sock
->sk
;
123 if (addr_len
< sizeof(uaddr
->sa_family
))
126 if (uaddr
->sa_family
== AF_UNSPEC
)
127 return sk
->sk_prot
->disconnect(sk
, flags
);
129 return sk
->sk_prot
->connect(sk
, uaddr
, addr_len
);
132 static int ieee802154_dev_ioctl(struct sock
*sk
, struct ifreq __user
*arg
,
136 int ret
= -ENOIOCTLCMD
;
137 struct net_device
*dev
;
139 if (copy_from_user(&ifr
, arg
, sizeof(struct ifreq
)))
142 ifr
.ifr_name
[IFNAMSIZ
-1] = 0;
144 dev_load(sock_net(sk
), ifr
.ifr_name
);
145 dev
= dev_get_by_name(sock_net(sk
), ifr
.ifr_name
);
150 if (dev
->type
== ARPHRD_IEEE802154
&& dev
->netdev_ops
->ndo_do_ioctl
)
151 ret
= dev
->netdev_ops
->ndo_do_ioctl(dev
, &ifr
, cmd
);
153 if (!ret
&& copy_to_user(arg
, &ifr
, sizeof(struct ifreq
)))
160 static int ieee802154_sock_ioctl(struct socket
*sock
, unsigned int cmd
,
163 struct sock
*sk
= sock
->sk
;
167 return sock_get_timestamp(sk
, (struct timeval __user
*)arg
);
169 return sock_get_timestampns(sk
, (struct timespec __user
*)arg
);
172 return ieee802154_dev_ioctl(sk
, (struct ifreq __user
*)arg
,
175 if (!sk
->sk_prot
->ioctl
)
177 return sk
->sk_prot
->ioctl(sk
, cmd
, arg
);
181 /* RAW Sockets (802.15.4 created in userspace) */
182 static HLIST_HEAD(raw_head
);
183 static DEFINE_RWLOCK(raw_lock
);
185 static void raw_hash(struct sock
*sk
)
187 write_lock_bh(&raw_lock
);
188 sk_add_node(sk
, &raw_head
);
189 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, 1);
190 write_unlock_bh(&raw_lock
);
193 static void raw_unhash(struct sock
*sk
)
195 write_lock_bh(&raw_lock
);
196 if (sk_del_node_init(sk
))
197 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, -1);
198 write_unlock_bh(&raw_lock
);
201 static void raw_close(struct sock
*sk
, long timeout
)
203 sk_common_release(sk
);
206 static int raw_bind(struct sock
*sk
, struct sockaddr
*_uaddr
, int len
)
208 struct ieee802154_addr addr
;
209 struct sockaddr_ieee802154
*uaddr
= (struct sockaddr_ieee802154
*)_uaddr
;
211 struct net_device
*dev
= NULL
;
213 if (len
< sizeof(*uaddr
))
216 uaddr
= (struct sockaddr_ieee802154
*)_uaddr
;
217 if (uaddr
->family
!= AF_IEEE802154
)
222 ieee802154_addr_from_sa(&addr
, &uaddr
->addr
);
223 dev
= ieee802154_get_dev(sock_net(sk
), &addr
);
229 sk
->sk_bound_dev_if
= dev
->ifindex
;
239 static int raw_connect(struct sock
*sk
, struct sockaddr
*uaddr
,
245 static int raw_disconnect(struct sock
*sk
, int flags
)
250 static int raw_sendmsg(struct sock
*sk
, struct msghdr
*msg
, size_t size
)
252 struct net_device
*dev
;
258 if (msg
->msg_flags
& MSG_OOB
) {
259 pr_debug("msg->msg_flags = 0x%x\n", msg
->msg_flags
);
264 if (!sk
->sk_bound_dev_if
)
265 dev
= dev_getfirstbyhwtype(sock_net(sk
), ARPHRD_IEEE802154
);
267 dev
= dev_get_by_index(sock_net(sk
), sk
->sk_bound_dev_if
);
271 pr_debug("no dev\n");
276 mtu
= IEEE802154_MTU
;
277 pr_debug("name = %s, mtu = %u\n", dev
->name
, mtu
);
280 pr_debug("size = %Zu, mtu = %u\n", size
, mtu
);
285 hlen
= LL_RESERVED_SPACE(dev
);
286 tlen
= dev
->needed_tailroom
;
287 skb
= sock_alloc_send_skb(sk
, hlen
+ tlen
+ size
,
288 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
292 skb_reserve(skb
, hlen
);
294 skb_reset_mac_header(skb
);
295 skb_reset_network_header(skb
);
297 err
= memcpy_from_msg(skb_put(skb
, size
), msg
, size
);
303 skb
->protocol
= htons(ETH_P_IEEE802154
);
307 err
= dev_queue_xmit(skb
);
309 err
= net_xmit_errno(err
);
321 static int raw_recvmsg(struct sock
*sk
, struct msghdr
*msg
, size_t len
,
322 int noblock
, int flags
, int *addr_len
)
325 int err
= -EOPNOTSUPP
;
328 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
334 msg
->msg_flags
|= MSG_TRUNC
;
338 err
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
342 sock_recv_ts_and_drops(msg
, sk
, skb
);
344 if (flags
& MSG_TRUNC
)
347 skb_free_datagram(sk
, skb
);
354 static int raw_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
356 skb
= skb_share_check(skb
, GFP_ATOMIC
);
360 if (sock_queue_rcv_skb(sk
, skb
) < 0) {
365 return NET_RX_SUCCESS
;
368 static void ieee802154_raw_deliver(struct net_device
*dev
, struct sk_buff
*skb
)
372 read_lock(&raw_lock
);
373 sk_for_each(sk
, &raw_head
) {
375 if (!sk
->sk_bound_dev_if
||
376 sk
->sk_bound_dev_if
== dev
->ifindex
) {
377 struct sk_buff
*clone
;
379 clone
= skb_clone(skb
, GFP_ATOMIC
);
381 raw_rcv_skb(sk
, clone
);
385 read_unlock(&raw_lock
);
388 static int raw_getsockopt(struct sock
*sk
, int level
, int optname
,
389 char __user
*optval
, int __user
*optlen
)
394 static int raw_setsockopt(struct sock
*sk
, int level
, int optname
,
395 char __user
*optval
, unsigned int optlen
)
400 static struct proto ieee802154_raw_prot
= {
401 .name
= "IEEE-802.15.4-RAW",
402 .owner
= THIS_MODULE
,
403 .obj_size
= sizeof(struct sock
),
406 .sendmsg
= raw_sendmsg
,
407 .recvmsg
= raw_recvmsg
,
409 .unhash
= raw_unhash
,
410 .connect
= raw_connect
,
411 .disconnect
= raw_disconnect
,
412 .getsockopt
= raw_getsockopt
,
413 .setsockopt
= raw_setsockopt
,
416 static const struct proto_ops ieee802154_raw_ops
= {
417 .family
= PF_IEEE802154
,
418 .owner
= THIS_MODULE
,
419 .release
= ieee802154_sock_release
,
420 .bind
= ieee802154_sock_bind
,
421 .connect
= ieee802154_sock_connect
,
422 .socketpair
= sock_no_socketpair
,
423 .accept
= sock_no_accept
,
424 .getname
= sock_no_getname
,
425 .poll
= datagram_poll
,
426 .ioctl
= ieee802154_sock_ioctl
,
427 .listen
= sock_no_listen
,
428 .shutdown
= sock_no_shutdown
,
429 .setsockopt
= sock_common_setsockopt
,
430 .getsockopt
= sock_common_getsockopt
,
431 .sendmsg
= ieee802154_sock_sendmsg
,
432 .recvmsg
= sock_common_recvmsg
,
433 .mmap
= sock_no_mmap
,
434 .sendpage
= sock_no_sendpage
,
436 .compat_setsockopt
= compat_sock_common_setsockopt
,
437 .compat_getsockopt
= compat_sock_common_getsockopt
,
441 /* DGRAM Sockets (802.15.4 dataframes) */
442 static HLIST_HEAD(dgram_head
);
443 static DEFINE_RWLOCK(dgram_lock
);
448 struct ieee802154_addr src_addr
;
449 struct ieee802154_addr dst_addr
;
451 unsigned int bound
:1;
452 unsigned int connected
:1;
453 unsigned int want_ack
:1;
454 unsigned int secen
:1;
455 unsigned int secen_override
:1;
456 unsigned int seclevel
:3;
457 unsigned int seclevel_override
:1;
460 static inline struct dgram_sock
*dgram_sk(const struct sock
*sk
)
462 return container_of(sk
, struct dgram_sock
, sk
);
465 static void dgram_hash(struct sock
*sk
)
467 write_lock_bh(&dgram_lock
);
468 sk_add_node(sk
, &dgram_head
);
469 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, 1);
470 write_unlock_bh(&dgram_lock
);
473 static void dgram_unhash(struct sock
*sk
)
475 write_lock_bh(&dgram_lock
);
476 if (sk_del_node_init(sk
))
477 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, -1);
478 write_unlock_bh(&dgram_lock
);
481 static int dgram_init(struct sock
*sk
)
483 struct dgram_sock
*ro
= dgram_sk(sk
);
489 static void dgram_close(struct sock
*sk
, long timeout
)
491 sk_common_release(sk
);
494 static int dgram_bind(struct sock
*sk
, struct sockaddr
*uaddr
, int len
)
496 struct sockaddr_ieee802154
*addr
= (struct sockaddr_ieee802154
*)uaddr
;
497 struct ieee802154_addr haddr
;
498 struct dgram_sock
*ro
= dgram_sk(sk
);
500 struct net_device
*dev
;
506 if (len
< sizeof(*addr
))
509 if (addr
->family
!= AF_IEEE802154
)
512 ieee802154_addr_from_sa(&haddr
, &addr
->addr
);
513 dev
= ieee802154_get_dev(sock_net(sk
), &haddr
);
519 if (dev
->type
!= ARPHRD_IEEE802154
) {
524 ro
->src_addr
= haddr
;
536 static int dgram_ioctl(struct sock
*sk
, int cmd
, unsigned long arg
)
541 int amount
= sk_wmem_alloc_get(sk
);
543 return put_user(amount
, (int __user
*)arg
);
549 unsigned long amount
;
552 spin_lock_bh(&sk
->sk_receive_queue
.lock
);
553 skb
= skb_peek(&sk
->sk_receive_queue
);
555 /* We will only return the amount
556 * of this packet since that is all
559 amount
= skb
->len
- ieee802154_hdr_length(skb
);
561 spin_unlock_bh(&sk
->sk_receive_queue
.lock
);
562 return put_user(amount
, (int __user
*)arg
);
569 /* FIXME: autobind */
570 static int dgram_connect(struct sock
*sk
, struct sockaddr
*uaddr
,
573 struct sockaddr_ieee802154
*addr
= (struct sockaddr_ieee802154
*)uaddr
;
574 struct dgram_sock
*ro
= dgram_sk(sk
);
577 if (len
< sizeof(*addr
))
580 if (addr
->family
!= AF_IEEE802154
)
590 ieee802154_addr_from_sa(&ro
->dst_addr
, &addr
->addr
);
598 static int dgram_disconnect(struct sock
*sk
, int flags
)
600 struct dgram_sock
*ro
= dgram_sk(sk
);
609 static int dgram_sendmsg(struct sock
*sk
, struct msghdr
*msg
, size_t size
)
611 struct net_device
*dev
;
614 struct ieee802154_mac_cb
*cb
;
615 struct dgram_sock
*ro
= dgram_sk(sk
);
616 struct ieee802154_addr dst_addr
;
620 if (msg
->msg_flags
& MSG_OOB
) {
621 pr_debug("msg->msg_flags = 0x%x\n", msg
->msg_flags
);
625 if (!ro
->connected
&& !msg
->msg_name
)
626 return -EDESTADDRREQ
;
627 else if (ro
->connected
&& msg
->msg_name
)
631 dev
= dev_getfirstbyhwtype(sock_net(sk
), ARPHRD_IEEE802154
);
633 dev
= ieee802154_get_dev(sock_net(sk
), &ro
->src_addr
);
636 pr_debug("no dev\n");
640 mtu
= IEEE802154_MTU
;
641 pr_debug("name = %s, mtu = %u\n", dev
->name
, mtu
);
644 pr_debug("size = %Zu, mtu = %u\n", size
, mtu
);
649 hlen
= LL_RESERVED_SPACE(dev
);
650 tlen
= dev
->needed_tailroom
;
651 skb
= sock_alloc_send_skb(sk
, hlen
+ tlen
+ size
,
652 msg
->msg_flags
& MSG_DONTWAIT
,
657 skb_reserve(skb
, hlen
);
659 skb_reset_network_header(skb
);
661 cb
= mac_cb_init(skb
);
662 cb
->type
= IEEE802154_FC_TYPE_DATA
;
663 cb
->ackreq
= ro
->want_ack
;
666 DECLARE_SOCKADDR(struct sockaddr_ieee802154
*,
667 daddr
, msg
->msg_name
);
669 ieee802154_addr_from_sa(&dst_addr
, &daddr
->addr
);
671 dst_addr
= ro
->dst_addr
;
674 cb
->secen
= ro
->secen
;
675 cb
->secen_override
= ro
->secen_override
;
676 cb
->seclevel
= ro
->seclevel
;
677 cb
->seclevel_override
= ro
->seclevel_override
;
679 err
= wpan_dev_hard_header(skb
, dev
, &dst_addr
,
680 ro
->bound
? &ro
->src_addr
: NULL
, size
);
684 err
= memcpy_from_msg(skb_put(skb
, size
), msg
, size
);
690 skb
->protocol
= htons(ETH_P_IEEE802154
);
694 err
= dev_queue_xmit(skb
);
696 err
= net_xmit_errno(err
);
708 static int dgram_recvmsg(struct sock
*sk
, struct msghdr
*msg
, size_t len
,
709 int noblock
, int flags
, int *addr_len
)
712 int err
= -EOPNOTSUPP
;
714 DECLARE_SOCKADDR(struct sockaddr_ieee802154
*, saddr
, msg
->msg_name
);
716 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
722 msg
->msg_flags
|= MSG_TRUNC
;
726 /* FIXME: skip headers if necessary ?! */
727 err
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
731 sock_recv_ts_and_drops(msg
, sk
, skb
);
734 /* Clear the implicit padding in struct sockaddr_ieee802154
735 * (16 bits between 'family' and 'addr') and in struct
736 * ieee802154_addr_sa (16 bits at the end of the structure).
738 memset(saddr
, 0, sizeof(*saddr
));
740 saddr
->family
= AF_IEEE802154
;
741 ieee802154_addr_to_sa(&saddr
->addr
, &mac_cb(skb
)->source
);
742 *addr_len
= sizeof(*saddr
);
745 if (flags
& MSG_TRUNC
)
748 skb_free_datagram(sk
, skb
);
755 static int dgram_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
757 skb
= skb_share_check(skb
, GFP_ATOMIC
);
761 if (sock_queue_rcv_skb(sk
, skb
) < 0) {
766 return NET_RX_SUCCESS
;
770 ieee802154_match_sock(__le64 hw_addr
, __le16 pan_id
, __le16 short_addr
,
771 struct dgram_sock
*ro
)
776 if (ro
->src_addr
.mode
== IEEE802154_ADDR_LONG
&&
777 hw_addr
== ro
->src_addr
.extended_addr
)
780 if (ro
->src_addr
.mode
== IEEE802154_ADDR_SHORT
&&
781 pan_id
== ro
->src_addr
.pan_id
&&
782 short_addr
== ro
->src_addr
.short_addr
)
788 static int ieee802154_dgram_deliver(struct net_device
*dev
, struct sk_buff
*skb
)
790 struct sock
*sk
, *prev
= NULL
;
791 int ret
= NET_RX_SUCCESS
;
792 __le16 pan_id
, short_addr
;
795 /* Data frame processing */
796 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
798 pan_id
= dev
->ieee802154_ptr
->pan_id
;
799 short_addr
= dev
->ieee802154_ptr
->short_addr
;
800 hw_addr
= dev
->ieee802154_ptr
->extended_addr
;
802 read_lock(&dgram_lock
);
803 sk_for_each(sk
, &dgram_head
) {
804 if (ieee802154_match_sock(hw_addr
, pan_id
, short_addr
,
807 struct sk_buff
*clone
;
809 clone
= skb_clone(skb
, GFP_ATOMIC
);
811 dgram_rcv_skb(prev
, clone
);
819 dgram_rcv_skb(prev
, skb
);
824 read_unlock(&dgram_lock
);
829 static int dgram_getsockopt(struct sock
*sk
, int level
, int optname
,
830 char __user
*optval
, int __user
*optlen
)
832 struct dgram_sock
*ro
= dgram_sk(sk
);
836 if (level
!= SOL_IEEE802154
)
839 if (get_user(len
, optlen
))
842 len
= min_t(unsigned int, len
, sizeof(int));
849 if (!ro
->secen_override
)
850 val
= WPAN_SECURITY_DEFAULT
;
852 val
= WPAN_SECURITY_ON
;
854 val
= WPAN_SECURITY_OFF
;
856 case WPAN_SECURITY_LEVEL
:
857 if (!ro
->seclevel_override
)
858 val
= WPAN_SECURITY_LEVEL_DEFAULT
;
866 if (put_user(len
, optlen
))
868 if (copy_to_user(optval
, &val
, len
))
873 static int dgram_setsockopt(struct sock
*sk
, int level
, int optname
,
874 char __user
*optval
, unsigned int optlen
)
876 struct dgram_sock
*ro
= dgram_sk(sk
);
877 struct net
*net
= sock_net(sk
);
881 if (optlen
< sizeof(int))
884 if (get_user(val
, (int __user
*)optval
))
891 ro
->want_ack
= !!val
;
894 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
) &&
895 !ns_capable(net
->user_ns
, CAP_NET_RAW
)) {
901 case WPAN_SECURITY_DEFAULT
:
902 ro
->secen_override
= 0;
904 case WPAN_SECURITY_ON
:
905 ro
->secen_override
= 1;
908 case WPAN_SECURITY_OFF
:
909 ro
->secen_override
= 1;
917 case WPAN_SECURITY_LEVEL
:
918 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
) &&
919 !ns_capable(net
->user_ns
, CAP_NET_RAW
)) {
924 if (val
< WPAN_SECURITY_LEVEL_DEFAULT
||
925 val
> IEEE802154_SCF_SECLEVEL_ENC_MIC128
) {
927 } else if (val
== WPAN_SECURITY_LEVEL_DEFAULT
) {
928 ro
->seclevel_override
= 0;
930 ro
->seclevel_override
= 1;
943 static struct proto ieee802154_dgram_prot
= {
944 .name
= "IEEE-802.15.4-MAC",
945 .owner
= THIS_MODULE
,
946 .obj_size
= sizeof(struct dgram_sock
),
948 .close
= dgram_close
,
950 .sendmsg
= dgram_sendmsg
,
951 .recvmsg
= dgram_recvmsg
,
953 .unhash
= dgram_unhash
,
954 .connect
= dgram_connect
,
955 .disconnect
= dgram_disconnect
,
956 .ioctl
= dgram_ioctl
,
957 .getsockopt
= dgram_getsockopt
,
958 .setsockopt
= dgram_setsockopt
,
961 static const struct proto_ops ieee802154_dgram_ops
= {
962 .family
= PF_IEEE802154
,
963 .owner
= THIS_MODULE
,
964 .release
= ieee802154_sock_release
,
965 .bind
= ieee802154_sock_bind
,
966 .connect
= ieee802154_sock_connect
,
967 .socketpair
= sock_no_socketpair
,
968 .accept
= sock_no_accept
,
969 .getname
= sock_no_getname
,
970 .poll
= datagram_poll
,
971 .ioctl
= ieee802154_sock_ioctl
,
972 .listen
= sock_no_listen
,
973 .shutdown
= sock_no_shutdown
,
974 .setsockopt
= sock_common_setsockopt
,
975 .getsockopt
= sock_common_getsockopt
,
976 .sendmsg
= ieee802154_sock_sendmsg
,
977 .recvmsg
= sock_common_recvmsg
,
978 .mmap
= sock_no_mmap
,
979 .sendpage
= sock_no_sendpage
,
981 .compat_setsockopt
= compat_sock_common_setsockopt
,
982 .compat_getsockopt
= compat_sock_common_getsockopt
,
986 /* Create a socket. Initialise the socket, blank the addresses
989 static int ieee802154_create(struct net
*net
, struct socket
*sock
,
990 int protocol
, int kern
)
995 const struct proto_ops
*ops
;
997 if (!net_eq(net
, &init_net
))
998 return -EAFNOSUPPORT
;
1000 switch (sock
->type
) {
1002 proto
= &ieee802154_raw_prot
;
1003 ops
= &ieee802154_raw_ops
;
1006 proto
= &ieee802154_dgram_prot
;
1007 ops
= &ieee802154_dgram_ops
;
1010 rc
= -ESOCKTNOSUPPORT
;
1015 sk
= sk_alloc(net
, PF_IEEE802154
, GFP_KERNEL
, proto
, kern
);
1022 sock_init_data(sock
, sk
);
1023 /* FIXME: sk->sk_destruct */
1024 sk
->sk_family
= PF_IEEE802154
;
1026 /* Checksums on by default */
1027 sock_set_flag(sk
, SOCK_ZAPPED
);
1029 if (sk
->sk_prot
->hash
)
1030 sk
->sk_prot
->hash(sk
);
1032 if (sk
->sk_prot
->init
) {
1033 rc
= sk
->sk_prot
->init(sk
);
1035 sk_common_release(sk
);
1041 static const struct net_proto_family ieee802154_family_ops
= {
1042 .family
= PF_IEEE802154
,
1043 .create
= ieee802154_create
,
1044 .owner
= THIS_MODULE
,
1047 static int ieee802154_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
1048 struct packet_type
*pt
, struct net_device
*orig_dev
)
1050 if (!netif_running(dev
))
1052 pr_debug("got frame, type %d, dev %p\n", dev
->type
, dev
);
1054 print_hex_dump_bytes("ieee802154_rcv ",
1055 DUMP_PREFIX_NONE
, skb
->data
, skb
->len
);
1058 if (!net_eq(dev_net(dev
), &init_net
))
1061 ieee802154_raw_deliver(dev
, skb
);
1063 if (dev
->type
!= ARPHRD_IEEE802154
)
1066 if (skb
->pkt_type
!= PACKET_OTHERHOST
)
1067 return ieee802154_dgram_deliver(dev
, skb
);
1074 static struct packet_type ieee802154_packet_type
= {
1075 .type
= htons(ETH_P_IEEE802154
),
1076 .func
= ieee802154_rcv
,
1079 static int __init
af_ieee802154_init(void)
1083 rc
= proto_register(&ieee802154_raw_prot
, 1);
1087 rc
= proto_register(&ieee802154_dgram_prot
, 1);
1091 /* Tell SOCKET that we are alive */
1092 rc
= sock_register(&ieee802154_family_ops
);
1095 dev_add_pack(&ieee802154_packet_type
);
1101 proto_unregister(&ieee802154_dgram_prot
);
1103 proto_unregister(&ieee802154_raw_prot
);
1108 static void __exit
af_ieee802154_remove(void)
1110 dev_remove_pack(&ieee802154_packet_type
);
1111 sock_unregister(PF_IEEE802154
);
1112 proto_unregister(&ieee802154_dgram_prot
);
1113 proto_unregister(&ieee802154_raw_prot
);
1116 module_init(af_ieee802154_init
);
1117 module_exit(af_ieee802154_remove
);
1119 MODULE_LICENSE("GPL");
1120 MODULE_ALIAS_NETPROTO(PF_IEEE802154
);