1 // SPDX-License-Identifier: GPL-2.0-only
3 * IEEE802154.4 socket interface
5 * Copyright 2007, 2008 Siemens AG
8 * Sergey Lapin <slapin@ossfans.org>
9 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
12 #include <linux/net.h>
13 #include <linux/capability.h>
14 #include <linux/module.h>
15 #include <linux/if_arp.h>
17 #include <linux/termios.h> /* For TIOCOUTQ/INQ */
18 #include <linux/list.h>
19 #include <linux/slab.h>
20 #include <linux/socket.h>
21 #include <net/datalink.h>
22 #include <net/psnap.h>
24 #include <net/tcp_states.h>
25 #include <net/route.h>
27 #include <net/af_ieee802154.h>
28 #include <net/ieee802154_netdev.h>
30 /* Utility function for families */
31 static struct net_device
*
32 ieee802154_get_dev(struct net
*net
, const struct ieee802154_addr
*addr
)
34 struct net_device
*dev
= NULL
;
35 struct net_device
*tmp
;
36 __le16 pan_id
, short_addr
;
37 u8 hwaddr
[IEEE802154_ADDR_LEN
];
40 case IEEE802154_ADDR_LONG
:
41 ieee802154_devaddr_to_raw(hwaddr
, addr
->extended_addr
);
43 dev
= dev_getbyhwaddr_rcu(net
, ARPHRD_IEEE802154
, hwaddr
);
47 case IEEE802154_ADDR_SHORT
:
48 if (addr
->pan_id
== cpu_to_le16(IEEE802154_PANID_BROADCAST
) ||
49 addr
->short_addr
== cpu_to_le16(IEEE802154_ADDR_UNDEF
) ||
50 addr
->short_addr
== cpu_to_le16(IEEE802154_ADDR_BROADCAST
))
55 for_each_netdev(net
, tmp
) {
56 if (tmp
->type
!= ARPHRD_IEEE802154
)
59 pan_id
= tmp
->ieee802154_ptr
->pan_id
;
60 short_addr
= tmp
->ieee802154_ptr
->short_addr
;
61 if (pan_id
== addr
->pan_id
&&
62 short_addr
== addr
->short_addr
) {
72 pr_warn("Unsupported ieee802154 address type: %d\n",
80 static int ieee802154_sock_release(struct socket
*sock
)
82 struct sock
*sk
= sock
->sk
;
86 sk
->sk_prot
->close(sk
, 0);
91 static int ieee802154_sock_sendmsg(struct socket
*sock
, struct msghdr
*msg
,
94 struct sock
*sk
= sock
->sk
;
96 return sk
->sk_prot
->sendmsg(sk
, msg
, len
);
99 static int ieee802154_sock_bind(struct socket
*sock
, struct sockaddr
*uaddr
,
102 struct sock
*sk
= sock
->sk
;
104 if (sk
->sk_prot
->bind
)
105 return sk
->sk_prot
->bind(sk
, uaddr
, addr_len
);
107 return sock_no_bind(sock
, uaddr
, addr_len
);
110 static int ieee802154_sock_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
111 int addr_len
, int flags
)
113 struct sock
*sk
= sock
->sk
;
115 if (addr_len
< sizeof(uaddr
->sa_family
))
118 if (uaddr
->sa_family
== AF_UNSPEC
)
119 return sk
->sk_prot
->disconnect(sk
, flags
);
121 return sk
->sk_prot
->connect(sk
, uaddr
, addr_len
);
124 static int ieee802154_dev_ioctl(struct sock
*sk
, struct ifreq __user
*arg
,
128 int ret
= -ENOIOCTLCMD
;
129 struct net_device
*dev
;
131 if (get_user_ifreq(&ifr
, NULL
, arg
))
134 ifr
.ifr_name
[IFNAMSIZ
-1] = 0;
136 dev_load(sock_net(sk
), ifr
.ifr_name
);
137 dev
= dev_get_by_name(sock_net(sk
), ifr
.ifr_name
);
142 if (dev
->type
== ARPHRD_IEEE802154
&& dev
->netdev_ops
->ndo_do_ioctl
)
143 ret
= dev
->netdev_ops
->ndo_do_ioctl(dev
, &ifr
, cmd
);
145 if (!ret
&& put_user_ifreq(&ifr
, arg
))
152 static int ieee802154_sock_ioctl(struct socket
*sock
, unsigned int cmd
,
155 struct sock
*sk
= sock
->sk
;
160 return ieee802154_dev_ioctl(sk
, (struct ifreq __user
*)arg
,
163 if (!sk
->sk_prot
->ioctl
)
165 return sk_ioctl(sk
, cmd
, (void __user
*)arg
);
169 /* RAW Sockets (802.15.4 created in userspace) */
170 static HLIST_HEAD(raw_head
);
171 static DEFINE_RWLOCK(raw_lock
);
173 static int raw_hash(struct sock
*sk
)
175 write_lock_bh(&raw_lock
);
176 sk_add_node(sk
, &raw_head
);
177 write_unlock_bh(&raw_lock
);
178 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, 1);
183 static void raw_unhash(struct sock
*sk
)
185 write_lock_bh(&raw_lock
);
186 if (sk_del_node_init(sk
))
187 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, -1);
188 write_unlock_bh(&raw_lock
);
191 static void raw_close(struct sock
*sk
, long timeout
)
193 sk_common_release(sk
);
196 static int raw_bind(struct sock
*sk
, struct sockaddr
*_uaddr
, int len
)
198 struct ieee802154_addr addr
;
199 struct sockaddr_ieee802154
*uaddr
= (struct sockaddr_ieee802154
*)_uaddr
;
201 struct net_device
*dev
= NULL
;
203 err
= ieee802154_sockaddr_check_size(uaddr
, len
);
207 uaddr
= (struct sockaddr_ieee802154
*)_uaddr
;
208 if (uaddr
->family
!= AF_IEEE802154
)
213 ieee802154_addr_from_sa(&addr
, &uaddr
->addr
);
214 dev
= ieee802154_get_dev(sock_net(sk
), &addr
);
220 sk
->sk_bound_dev_if
= dev
->ifindex
;
230 static int raw_connect(struct sock
*sk
, struct sockaddr
*uaddr
,
236 static int raw_disconnect(struct sock
*sk
, int flags
)
241 static int raw_sendmsg(struct sock
*sk
, struct msghdr
*msg
, size_t size
)
243 struct net_device
*dev
;
249 if (msg
->msg_flags
& MSG_OOB
) {
250 pr_debug("msg->msg_flags = 0x%x\n", msg
->msg_flags
);
255 if (!sk
->sk_bound_dev_if
)
256 dev
= dev_getfirstbyhwtype(sock_net(sk
), ARPHRD_IEEE802154
);
258 dev
= dev_get_by_index(sock_net(sk
), sk
->sk_bound_dev_if
);
262 pr_debug("no dev\n");
267 mtu
= IEEE802154_MTU
;
268 pr_debug("name = %s, mtu = %u\n", dev
->name
, mtu
);
271 pr_debug("size = %zu, mtu = %u\n", size
, mtu
);
280 hlen
= LL_RESERVED_SPACE(dev
);
281 tlen
= dev
->needed_tailroom
;
282 skb
= sock_alloc_send_skb(sk
, hlen
+ tlen
+ size
,
283 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
287 skb_reserve(skb
, hlen
);
289 skb_reset_mac_header(skb
);
290 skb_reset_network_header(skb
);
292 err
= memcpy_from_msg(skb_put(skb
, size
), msg
, size
);
297 skb
->protocol
= htons(ETH_P_IEEE802154
);
299 err
= dev_queue_xmit(skb
);
301 err
= net_xmit_errno(err
);
315 static int raw_recvmsg(struct sock
*sk
, struct msghdr
*msg
, size_t len
,
316 int flags
, int *addr_len
)
319 int err
= -EOPNOTSUPP
;
322 skb
= skb_recv_datagram(sk
, flags
, &err
);
328 msg
->msg_flags
|= MSG_TRUNC
;
332 err
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
336 sock_recv_cmsgs(msg
, sk
, skb
);
338 if (flags
& MSG_TRUNC
)
341 skb_free_datagram(sk
, skb
);
348 static int raw_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
350 skb
= skb_share_check(skb
, GFP_ATOMIC
);
354 if (sock_queue_rcv_skb(sk
, skb
) < 0) {
359 return NET_RX_SUCCESS
;
362 static void ieee802154_raw_deliver(struct net_device
*dev
, struct sk_buff
*skb
)
366 read_lock(&raw_lock
);
367 sk_for_each(sk
, &raw_head
) {
369 if (!sk
->sk_bound_dev_if
||
370 sk
->sk_bound_dev_if
== dev
->ifindex
) {
371 struct sk_buff
*clone
;
373 clone
= skb_clone(skb
, GFP_ATOMIC
);
375 raw_rcv_skb(sk
, clone
);
379 read_unlock(&raw_lock
);
382 static int raw_getsockopt(struct sock
*sk
, int level
, int optname
,
383 char __user
*optval
, int __user
*optlen
)
388 static int raw_setsockopt(struct sock
*sk
, int level
, int optname
,
389 sockptr_t optval
, unsigned int optlen
)
394 static struct proto ieee802154_raw_prot
= {
395 .name
= "IEEE-802.15.4-RAW",
396 .owner
= THIS_MODULE
,
397 .obj_size
= sizeof(struct sock
),
400 .sendmsg
= raw_sendmsg
,
401 .recvmsg
= raw_recvmsg
,
403 .unhash
= raw_unhash
,
404 .connect
= raw_connect
,
405 .disconnect
= raw_disconnect
,
406 .getsockopt
= raw_getsockopt
,
407 .setsockopt
= raw_setsockopt
,
410 static const struct proto_ops ieee802154_raw_ops
= {
411 .family
= PF_IEEE802154
,
412 .owner
= THIS_MODULE
,
413 .release
= ieee802154_sock_release
,
414 .bind
= ieee802154_sock_bind
,
415 .connect
= ieee802154_sock_connect
,
416 .socketpair
= sock_no_socketpair
,
417 .accept
= sock_no_accept
,
418 .getname
= sock_no_getname
,
419 .poll
= datagram_poll
,
420 .ioctl
= ieee802154_sock_ioctl
,
421 .gettstamp
= sock_gettstamp
,
422 .listen
= sock_no_listen
,
423 .shutdown
= sock_no_shutdown
,
424 .setsockopt
= sock_common_setsockopt
,
425 .getsockopt
= sock_common_getsockopt
,
426 .sendmsg
= ieee802154_sock_sendmsg
,
427 .recvmsg
= sock_common_recvmsg
,
428 .mmap
= sock_no_mmap
,
431 /* DGRAM Sockets (802.15.4 dataframes) */
432 static HLIST_HEAD(dgram_head
);
433 static DEFINE_RWLOCK(dgram_lock
);
438 struct ieee802154_addr src_addr
;
439 struct ieee802154_addr dst_addr
;
441 unsigned int bound
:1;
442 unsigned int connected
:1;
443 unsigned int want_ack
:1;
444 unsigned int want_lqi
:1;
445 unsigned int secen
:1;
446 unsigned int secen_override
:1;
447 unsigned int seclevel
:3;
448 unsigned int seclevel_override
:1;
451 static inline struct dgram_sock
*dgram_sk(const struct sock
*sk
)
453 return container_of(sk
, struct dgram_sock
, sk
);
456 static int dgram_hash(struct sock
*sk
)
458 write_lock_bh(&dgram_lock
);
459 sk_add_node(sk
, &dgram_head
);
460 write_unlock_bh(&dgram_lock
);
461 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, 1);
466 static void dgram_unhash(struct sock
*sk
)
468 write_lock_bh(&dgram_lock
);
469 if (sk_del_node_init(sk
))
470 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, -1);
471 write_unlock_bh(&dgram_lock
);
474 static int dgram_init(struct sock
*sk
)
476 struct dgram_sock
*ro
= dgram_sk(sk
);
483 static void dgram_close(struct sock
*sk
, long timeout
)
485 sk_common_release(sk
);
488 static int dgram_bind(struct sock
*sk
, struct sockaddr
*uaddr
, int len
)
490 struct sockaddr_ieee802154
*addr
= (struct sockaddr_ieee802154
*)uaddr
;
491 struct ieee802154_addr haddr
;
492 struct dgram_sock
*ro
= dgram_sk(sk
);
494 struct net_device
*dev
;
500 err
= ieee802154_sockaddr_check_size(addr
, len
);
504 if (addr
->family
!= AF_IEEE802154
) {
509 ieee802154_addr_from_sa(&haddr
, &addr
->addr
);
510 dev
= ieee802154_get_dev(sock_net(sk
), &haddr
);
516 if (dev
->type
!= ARPHRD_IEEE802154
) {
521 ro
->src_addr
= haddr
;
533 static int dgram_ioctl(struct sock
*sk
, int cmd
, int *karg
)
538 *karg
= sk_wmem_alloc_get(sk
);
548 spin_lock_bh(&sk
->sk_receive_queue
.lock
);
549 skb
= skb_peek(&sk
->sk_receive_queue
);
551 /* We will only return the amount
552 * of this packet since that is all
555 *karg
= skb
->len
- ieee802154_hdr_length(skb
);
557 spin_unlock_bh(&sk
->sk_receive_queue
.lock
);
565 /* FIXME: autobind */
566 static int dgram_connect(struct sock
*sk
, struct sockaddr
*uaddr
,
569 struct sockaddr_ieee802154
*addr
= (struct sockaddr_ieee802154
*)uaddr
;
570 struct dgram_sock
*ro
= dgram_sk(sk
);
573 err
= ieee802154_sockaddr_check_size(addr
, len
);
577 if (addr
->family
!= AF_IEEE802154
)
587 ieee802154_addr_from_sa(&ro
->dst_addr
, &addr
->addr
);
595 static int dgram_disconnect(struct sock
*sk
, int flags
)
597 struct dgram_sock
*ro
= dgram_sk(sk
);
606 static int dgram_sendmsg(struct sock
*sk
, struct msghdr
*msg
, size_t size
)
608 struct net_device
*dev
;
611 struct ieee802154_mac_cb
*cb
;
612 struct dgram_sock
*ro
= dgram_sk(sk
);
613 struct ieee802154_addr dst_addr
;
614 DECLARE_SOCKADDR(struct sockaddr_ieee802154
*, daddr
, msg
->msg_name
);
618 if (msg
->msg_flags
& MSG_OOB
) {
619 pr_debug("msg->msg_flags = 0x%x\n", msg
->msg_flags
);
626 if (msg
->msg_namelen
< IEEE802154_MIN_NAMELEN
)
628 err
= ieee802154_sockaddr_check_size(daddr
, msg
->msg_namelen
);
631 ieee802154_addr_from_sa(&dst_addr
, &daddr
->addr
);
634 return -EDESTADDRREQ
;
635 dst_addr
= ro
->dst_addr
;
639 dev
= dev_getfirstbyhwtype(sock_net(sk
), ARPHRD_IEEE802154
);
641 dev
= ieee802154_get_dev(sock_net(sk
), &ro
->src_addr
);
644 pr_debug("no dev\n");
648 mtu
= IEEE802154_MTU
;
649 pr_debug("name = %s, mtu = %u\n", dev
->name
, mtu
);
652 pr_debug("size = %zu, mtu = %u\n", size
, mtu
);
657 hlen
= LL_RESERVED_SPACE(dev
);
658 tlen
= dev
->needed_tailroom
;
659 skb
= sock_alloc_send_skb(sk
, hlen
+ tlen
+ size
,
660 msg
->msg_flags
& MSG_DONTWAIT
,
665 skb_reserve(skb
, hlen
);
667 skb_reset_network_header(skb
);
669 cb
= mac_cb_init(skb
);
670 cb
->type
= IEEE802154_FC_TYPE_DATA
;
671 cb
->ackreq
= ro
->want_ack
;
672 cb
->secen
= ro
->secen
;
673 cb
->secen_override
= ro
->secen_override
;
674 cb
->seclevel
= ro
->seclevel
;
675 cb
->seclevel_override
= ro
->seclevel_override
;
677 err
= wpan_dev_hard_header(skb
, dev
, &dst_addr
,
678 ro
->bound
? &ro
->src_addr
: NULL
, size
);
682 err
= memcpy_from_msg(skb_put(skb
, size
), msg
, size
);
687 skb
->protocol
= htons(ETH_P_IEEE802154
);
689 err
= dev_queue_xmit(skb
);
691 err
= net_xmit_errno(err
);
705 static int dgram_recvmsg(struct sock
*sk
, struct msghdr
*msg
, size_t len
,
706 int flags
, int *addr_len
)
709 int err
= -EOPNOTSUPP
;
711 struct dgram_sock
*ro
= dgram_sk(sk
);
712 DECLARE_SOCKADDR(struct sockaddr_ieee802154
*, saddr
, msg
->msg_name
);
714 skb
= skb_recv_datagram(sk
, flags
, &err
);
720 msg
->msg_flags
|= MSG_TRUNC
;
724 /* FIXME: skip headers if necessary ?! */
725 err
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
729 sock_recv_cmsgs(msg
, sk
, skb
);
732 /* Clear the implicit padding in struct sockaddr_ieee802154
733 * (16 bits between 'family' and 'addr') and in struct
734 * ieee802154_addr_sa (16 bits at the end of the structure).
736 memset(saddr
, 0, sizeof(*saddr
));
738 saddr
->family
= AF_IEEE802154
;
739 ieee802154_addr_to_sa(&saddr
->addr
, &mac_cb(skb
)->source
);
740 *addr_len
= sizeof(*saddr
);
744 err
= put_cmsg(msg
, SOL_IEEE802154
, WPAN_WANTLQI
,
745 sizeof(uint8_t), &(mac_cb(skb
)->lqi
));
750 if (flags
& MSG_TRUNC
)
753 skb_free_datagram(sk
, skb
);
760 static int dgram_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
762 skb
= skb_share_check(skb
, GFP_ATOMIC
);
766 if (sock_queue_rcv_skb(sk
, skb
) < 0) {
771 return NET_RX_SUCCESS
;
775 ieee802154_match_sock(__le64 hw_addr
, __le16 pan_id
, __le16 short_addr
,
776 struct dgram_sock
*ro
)
781 if (ro
->src_addr
.mode
== IEEE802154_ADDR_LONG
&&
782 hw_addr
== ro
->src_addr
.extended_addr
)
785 if (ro
->src_addr
.mode
== IEEE802154_ADDR_SHORT
&&
786 pan_id
== ro
->src_addr
.pan_id
&&
787 short_addr
== ro
->src_addr
.short_addr
)
793 static int ieee802154_dgram_deliver(struct net_device
*dev
, struct sk_buff
*skb
)
795 struct sock
*sk
, *prev
= NULL
;
796 int ret
= NET_RX_SUCCESS
;
797 __le16 pan_id
, short_addr
;
800 /* Data frame processing */
801 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
803 pan_id
= dev
->ieee802154_ptr
->pan_id
;
804 short_addr
= dev
->ieee802154_ptr
->short_addr
;
805 hw_addr
= dev
->ieee802154_ptr
->extended_addr
;
807 read_lock(&dgram_lock
);
808 sk_for_each(sk
, &dgram_head
) {
809 if (ieee802154_match_sock(hw_addr
, pan_id
, short_addr
,
812 struct sk_buff
*clone
;
814 clone
= skb_clone(skb
, GFP_ATOMIC
);
816 dgram_rcv_skb(prev
, clone
);
824 dgram_rcv_skb(prev
, skb
);
829 read_unlock(&dgram_lock
);
834 static int dgram_getsockopt(struct sock
*sk
, int level
, int optname
,
835 char __user
*optval
, int __user
*optlen
)
837 struct dgram_sock
*ro
= dgram_sk(sk
);
841 if (level
!= SOL_IEEE802154
)
844 if (get_user(len
, optlen
))
847 len
= min_t(unsigned int, len
, sizeof(int));
857 if (!ro
->secen_override
)
858 val
= WPAN_SECURITY_DEFAULT
;
860 val
= WPAN_SECURITY_ON
;
862 val
= WPAN_SECURITY_OFF
;
864 case WPAN_SECURITY_LEVEL
:
865 if (!ro
->seclevel_override
)
866 val
= WPAN_SECURITY_LEVEL_DEFAULT
;
874 if (put_user(len
, optlen
))
876 if (copy_to_user(optval
, &val
, len
))
881 static int dgram_setsockopt(struct sock
*sk
, int level
, int optname
,
882 sockptr_t optval
, unsigned int optlen
)
884 struct dgram_sock
*ro
= dgram_sk(sk
);
885 struct net
*net
= sock_net(sk
);
889 if (optlen
< sizeof(int))
892 if (copy_from_sockptr(&val
, optval
, sizeof(int)))
899 ro
->want_ack
= !!val
;
902 ro
->want_lqi
= !!val
;
905 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
) &&
906 !ns_capable(net
->user_ns
, CAP_NET_RAW
)) {
912 case WPAN_SECURITY_DEFAULT
:
913 ro
->secen_override
= 0;
915 case WPAN_SECURITY_ON
:
916 ro
->secen_override
= 1;
919 case WPAN_SECURITY_OFF
:
920 ro
->secen_override
= 1;
928 case WPAN_SECURITY_LEVEL
:
929 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
) &&
930 !ns_capable(net
->user_ns
, CAP_NET_RAW
)) {
935 if (val
< WPAN_SECURITY_LEVEL_DEFAULT
||
936 val
> IEEE802154_SCF_SECLEVEL_ENC_MIC128
) {
938 } else if (val
== WPAN_SECURITY_LEVEL_DEFAULT
) {
939 ro
->seclevel_override
= 0;
941 ro
->seclevel_override
= 1;
954 static struct proto ieee802154_dgram_prot
= {
955 .name
= "IEEE-802.15.4-MAC",
956 .owner
= THIS_MODULE
,
957 .obj_size
= sizeof(struct dgram_sock
),
959 .close
= dgram_close
,
961 .sendmsg
= dgram_sendmsg
,
962 .recvmsg
= dgram_recvmsg
,
964 .unhash
= dgram_unhash
,
965 .connect
= dgram_connect
,
966 .disconnect
= dgram_disconnect
,
967 .ioctl
= dgram_ioctl
,
968 .getsockopt
= dgram_getsockopt
,
969 .setsockopt
= dgram_setsockopt
,
972 static const struct proto_ops ieee802154_dgram_ops
= {
973 .family
= PF_IEEE802154
,
974 .owner
= THIS_MODULE
,
975 .release
= ieee802154_sock_release
,
976 .bind
= ieee802154_sock_bind
,
977 .connect
= ieee802154_sock_connect
,
978 .socketpair
= sock_no_socketpair
,
979 .accept
= sock_no_accept
,
980 .getname
= sock_no_getname
,
981 .poll
= datagram_poll
,
982 .ioctl
= ieee802154_sock_ioctl
,
983 .gettstamp
= sock_gettstamp
,
984 .listen
= sock_no_listen
,
985 .shutdown
= sock_no_shutdown
,
986 .setsockopt
= sock_common_setsockopt
,
987 .getsockopt
= sock_common_getsockopt
,
988 .sendmsg
= ieee802154_sock_sendmsg
,
989 .recvmsg
= sock_common_recvmsg
,
990 .mmap
= sock_no_mmap
,
993 static void ieee802154_sock_destruct(struct sock
*sk
)
995 skb_queue_purge(&sk
->sk_receive_queue
);
998 /* Create a socket. Initialise the socket, blank the addresses
1001 static int ieee802154_create(struct net
*net
, struct socket
*sock
,
1002 int protocol
, int kern
)
1006 struct proto
*proto
;
1007 const struct proto_ops
*ops
;
1009 if (!net_eq(net
, &init_net
))
1010 return -EAFNOSUPPORT
;
1012 switch (sock
->type
) {
1015 if (!capable(CAP_NET_RAW
))
1017 proto
= &ieee802154_raw_prot
;
1018 ops
= &ieee802154_raw_ops
;
1021 proto
= &ieee802154_dgram_prot
;
1022 ops
= &ieee802154_dgram_ops
;
1025 rc
= -ESOCKTNOSUPPORT
;
1030 sk
= sk_alloc(net
, PF_IEEE802154
, GFP_KERNEL
, proto
, kern
);
1037 sock_init_data(sock
, sk
);
1038 sk
->sk_destruct
= ieee802154_sock_destruct
;
1039 sk
->sk_family
= PF_IEEE802154
;
1041 /* Checksums on by default */
1042 sock_set_flag(sk
, SOCK_ZAPPED
);
1044 if (sk
->sk_prot
->hash
) {
1045 rc
= sk
->sk_prot
->hash(sk
);
1047 sk_common_release(sk
);
1052 if (sk
->sk_prot
->init
) {
1053 rc
= sk
->sk_prot
->init(sk
);
1055 sk_common_release(sk
);
1061 static const struct net_proto_family ieee802154_family_ops
= {
1062 .family
= PF_IEEE802154
,
1063 .create
= ieee802154_create
,
1064 .owner
= THIS_MODULE
,
1067 static int ieee802154_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
1068 struct packet_type
*pt
, struct net_device
*orig_dev
)
1070 if (!netif_running(dev
))
1072 pr_debug("got frame, type %d, dev %p\n", dev
->type
, dev
);
1074 print_hex_dump_bytes("ieee802154_rcv ",
1075 DUMP_PREFIX_NONE
, skb
->data
, skb
->len
);
1078 if (!net_eq(dev_net(dev
), &init_net
))
1081 ieee802154_raw_deliver(dev
, skb
);
1083 if (dev
->type
!= ARPHRD_IEEE802154
)
1086 if (skb
->pkt_type
!= PACKET_OTHERHOST
)
1087 return ieee802154_dgram_deliver(dev
, skb
);
1094 static struct packet_type ieee802154_packet_type
= {
1095 .type
= htons(ETH_P_IEEE802154
),
1096 .func
= ieee802154_rcv
,
1099 static int __init
af_ieee802154_init(void)
1103 rc
= proto_register(&ieee802154_raw_prot
, 1);
1107 rc
= proto_register(&ieee802154_dgram_prot
, 1);
1111 /* Tell SOCKET that we are alive */
1112 rc
= sock_register(&ieee802154_family_ops
);
1115 dev_add_pack(&ieee802154_packet_type
);
1121 proto_unregister(&ieee802154_dgram_prot
);
1123 proto_unregister(&ieee802154_raw_prot
);
1128 static void __exit
af_ieee802154_remove(void)
1130 dev_remove_pack(&ieee802154_packet_type
);
1131 sock_unregister(PF_IEEE802154
);
1132 proto_unregister(&ieee802154_dgram_prot
);
1133 proto_unregister(&ieee802154_raw_prot
);
1136 module_init(af_ieee802154_init
);
1137 module_exit(af_ieee802154_remove
);
1139 MODULE_LICENSE("GPL");
1140 MODULE_DESCRIPTION("IEEE 802.15.4 socket interface");
1141 MODULE_ALIAS_NETPROTO(PF_IEEE802154
);