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 <linux/socket.h>
29 #include <net/datalink.h>
30 #include <net/psnap.h>
32 #include <net/tcp_states.h>
33 #include <net/route.h>
35 #include <net/af_ieee802154.h>
36 #include <net/ieee802154_netdev.h>
38 /* Utility function for families */
39 static struct net_device
*
40 ieee802154_get_dev(struct net
*net
, const struct ieee802154_addr
*addr
)
42 struct net_device
*dev
= NULL
;
43 struct net_device
*tmp
;
44 __le16 pan_id
, short_addr
;
45 u8 hwaddr
[IEEE802154_ADDR_LEN
];
48 case IEEE802154_ADDR_LONG
:
49 ieee802154_devaddr_to_raw(hwaddr
, addr
->extended_addr
);
51 dev
= dev_getbyhwaddr_rcu(net
, ARPHRD_IEEE802154
, hwaddr
);
56 case IEEE802154_ADDR_SHORT
:
57 if (addr
->pan_id
== cpu_to_le16(IEEE802154_PANID_BROADCAST
) ||
58 addr
->short_addr
== cpu_to_le16(IEEE802154_ADDR_UNDEF
) ||
59 addr
->short_addr
== cpu_to_le16(IEEE802154_ADDR_BROADCAST
))
64 for_each_netdev(net
, tmp
) {
65 if (tmp
->type
!= ARPHRD_IEEE802154
)
68 pan_id
= tmp
->ieee802154_ptr
->pan_id
;
69 short_addr
= tmp
->ieee802154_ptr
->short_addr
;
70 if (pan_id
== addr
->pan_id
&&
71 short_addr
== addr
->short_addr
) {
81 pr_warn("Unsupported ieee802154 address type: %d\n",
89 static int ieee802154_sock_release(struct socket
*sock
)
91 struct sock
*sk
= sock
->sk
;
95 sk
->sk_prot
->close(sk
, 0);
100 static int ieee802154_sock_sendmsg(struct socket
*sock
, struct msghdr
*msg
,
103 struct sock
*sk
= sock
->sk
;
105 return sk
->sk_prot
->sendmsg(sk
, msg
, len
);
108 static int ieee802154_sock_bind(struct socket
*sock
, struct sockaddr
*uaddr
,
111 struct sock
*sk
= sock
->sk
;
113 if (sk
->sk_prot
->bind
)
114 return sk
->sk_prot
->bind(sk
, uaddr
, addr_len
);
116 return sock_no_bind(sock
, uaddr
, addr_len
);
119 static int ieee802154_sock_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
120 int addr_len
, int flags
)
122 struct sock
*sk
= sock
->sk
;
124 if (addr_len
< sizeof(uaddr
->sa_family
))
127 if (uaddr
->sa_family
== AF_UNSPEC
)
128 return sk
->sk_prot
->disconnect(sk
, flags
);
130 return sk
->sk_prot
->connect(sk
, uaddr
, addr_len
);
133 static int ieee802154_dev_ioctl(struct sock
*sk
, struct ifreq __user
*arg
,
137 int ret
= -ENOIOCTLCMD
;
138 struct net_device
*dev
;
140 if (copy_from_user(&ifr
, arg
, sizeof(struct ifreq
)))
143 ifr
.ifr_name
[IFNAMSIZ
-1] = 0;
145 dev_load(sock_net(sk
), ifr
.ifr_name
);
146 dev
= dev_get_by_name(sock_net(sk
), ifr
.ifr_name
);
151 if (dev
->type
== ARPHRD_IEEE802154
&& dev
->netdev_ops
->ndo_do_ioctl
)
152 ret
= dev
->netdev_ops
->ndo_do_ioctl(dev
, &ifr
, cmd
);
154 if (!ret
&& copy_to_user(arg
, &ifr
, sizeof(struct ifreq
)))
161 static int ieee802154_sock_ioctl(struct socket
*sock
, unsigned int cmd
,
164 struct sock
*sk
= sock
->sk
;
168 return sock_get_timestamp(sk
, (struct timeval __user
*)arg
);
170 return sock_get_timestampns(sk
, (struct timespec __user
*)arg
);
173 return ieee802154_dev_ioctl(sk
, (struct ifreq __user
*)arg
,
176 if (!sk
->sk_prot
->ioctl
)
178 return sk
->sk_prot
->ioctl(sk
, cmd
, arg
);
182 /* RAW Sockets (802.15.4 created in userspace) */
183 static HLIST_HEAD(raw_head
);
184 static DEFINE_RWLOCK(raw_lock
);
186 static int raw_hash(struct sock
*sk
)
188 write_lock_bh(&raw_lock
);
189 sk_add_node(sk
, &raw_head
);
190 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, 1);
191 write_unlock_bh(&raw_lock
);
196 static void raw_unhash(struct sock
*sk
)
198 write_lock_bh(&raw_lock
);
199 if (sk_del_node_init(sk
))
200 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, -1);
201 write_unlock_bh(&raw_lock
);
204 static void raw_close(struct sock
*sk
, long timeout
)
206 sk_common_release(sk
);
209 static int raw_bind(struct sock
*sk
, struct sockaddr
*_uaddr
, int len
)
211 struct ieee802154_addr addr
;
212 struct sockaddr_ieee802154
*uaddr
= (struct sockaddr_ieee802154
*)_uaddr
;
214 struct net_device
*dev
= NULL
;
216 if (len
< sizeof(*uaddr
))
219 uaddr
= (struct sockaddr_ieee802154
*)_uaddr
;
220 if (uaddr
->family
!= AF_IEEE802154
)
225 ieee802154_addr_from_sa(&addr
, &uaddr
->addr
);
226 dev
= ieee802154_get_dev(sock_net(sk
), &addr
);
232 sk
->sk_bound_dev_if
= dev
->ifindex
;
242 static int raw_connect(struct sock
*sk
, struct sockaddr
*uaddr
,
248 static int raw_disconnect(struct sock
*sk
, int flags
)
253 static int raw_sendmsg(struct sock
*sk
, struct msghdr
*msg
, size_t size
)
255 struct net_device
*dev
;
261 if (msg
->msg_flags
& MSG_OOB
) {
262 pr_debug("msg->msg_flags = 0x%x\n", msg
->msg_flags
);
267 if (!sk
->sk_bound_dev_if
)
268 dev
= dev_getfirstbyhwtype(sock_net(sk
), ARPHRD_IEEE802154
);
270 dev
= dev_get_by_index(sock_net(sk
), sk
->sk_bound_dev_if
);
274 pr_debug("no dev\n");
279 mtu
= IEEE802154_MTU
;
280 pr_debug("name = %s, mtu = %u\n", dev
->name
, mtu
);
283 pr_debug("size = %zu, mtu = %u\n", size
, mtu
);
288 hlen
= LL_RESERVED_SPACE(dev
);
289 tlen
= dev
->needed_tailroom
;
290 skb
= sock_alloc_send_skb(sk
, hlen
+ tlen
+ size
,
291 msg
->msg_flags
& MSG_DONTWAIT
, &err
);
295 skb_reserve(skb
, hlen
);
297 skb_reset_mac_header(skb
);
298 skb_reset_network_header(skb
);
300 err
= memcpy_from_msg(skb_put(skb
, size
), msg
, size
);
305 skb
->protocol
= htons(ETH_P_IEEE802154
);
307 err
= dev_queue_xmit(skb
);
309 err
= net_xmit_errno(err
);
323 static int raw_recvmsg(struct sock
*sk
, struct msghdr
*msg
, size_t len
,
324 int noblock
, int flags
, int *addr_len
)
327 int err
= -EOPNOTSUPP
;
330 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
336 msg
->msg_flags
|= MSG_TRUNC
;
340 err
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
344 sock_recv_ts_and_drops(msg
, sk
, skb
);
346 if (flags
& MSG_TRUNC
)
349 skb_free_datagram(sk
, skb
);
356 static int raw_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
358 skb
= skb_share_check(skb
, GFP_ATOMIC
);
362 if (sock_queue_rcv_skb(sk
, skb
) < 0) {
367 return NET_RX_SUCCESS
;
370 static void ieee802154_raw_deliver(struct net_device
*dev
, struct sk_buff
*skb
)
374 read_lock(&raw_lock
);
375 sk_for_each(sk
, &raw_head
) {
377 if (!sk
->sk_bound_dev_if
||
378 sk
->sk_bound_dev_if
== dev
->ifindex
) {
379 struct sk_buff
*clone
;
381 clone
= skb_clone(skb
, GFP_ATOMIC
);
383 raw_rcv_skb(sk
, clone
);
387 read_unlock(&raw_lock
);
390 static int raw_getsockopt(struct sock
*sk
, int level
, int optname
,
391 char __user
*optval
, int __user
*optlen
)
396 static int raw_setsockopt(struct sock
*sk
, int level
, int optname
,
397 char __user
*optval
, unsigned int optlen
)
402 static struct proto ieee802154_raw_prot
= {
403 .name
= "IEEE-802.15.4-RAW",
404 .owner
= THIS_MODULE
,
405 .obj_size
= sizeof(struct sock
),
408 .sendmsg
= raw_sendmsg
,
409 .recvmsg
= raw_recvmsg
,
411 .unhash
= raw_unhash
,
412 .connect
= raw_connect
,
413 .disconnect
= raw_disconnect
,
414 .getsockopt
= raw_getsockopt
,
415 .setsockopt
= raw_setsockopt
,
418 static const struct proto_ops ieee802154_raw_ops
= {
419 .family
= PF_IEEE802154
,
420 .owner
= THIS_MODULE
,
421 .release
= ieee802154_sock_release
,
422 .bind
= ieee802154_sock_bind
,
423 .connect
= ieee802154_sock_connect
,
424 .socketpair
= sock_no_socketpair
,
425 .accept
= sock_no_accept
,
426 .getname
= sock_no_getname
,
427 .poll
= datagram_poll
,
428 .ioctl
= ieee802154_sock_ioctl
,
429 .listen
= sock_no_listen
,
430 .shutdown
= sock_no_shutdown
,
431 .setsockopt
= sock_common_setsockopt
,
432 .getsockopt
= sock_common_getsockopt
,
433 .sendmsg
= ieee802154_sock_sendmsg
,
434 .recvmsg
= sock_common_recvmsg
,
435 .mmap
= sock_no_mmap
,
436 .sendpage
= sock_no_sendpage
,
438 .compat_setsockopt
= compat_sock_common_setsockopt
,
439 .compat_getsockopt
= compat_sock_common_getsockopt
,
443 /* DGRAM Sockets (802.15.4 dataframes) */
444 static HLIST_HEAD(dgram_head
);
445 static DEFINE_RWLOCK(dgram_lock
);
450 struct ieee802154_addr src_addr
;
451 struct ieee802154_addr dst_addr
;
453 unsigned int bound
:1;
454 unsigned int connected
:1;
455 unsigned int want_ack
:1;
456 unsigned int want_lqi
:1;
457 unsigned int secen
:1;
458 unsigned int secen_override
:1;
459 unsigned int seclevel
:3;
460 unsigned int seclevel_override
:1;
463 static inline struct dgram_sock
*dgram_sk(const struct sock
*sk
)
465 return container_of(sk
, struct dgram_sock
, sk
);
468 static int dgram_hash(struct sock
*sk
)
470 write_lock_bh(&dgram_lock
);
471 sk_add_node(sk
, &dgram_head
);
472 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, 1);
473 write_unlock_bh(&dgram_lock
);
478 static void dgram_unhash(struct sock
*sk
)
480 write_lock_bh(&dgram_lock
);
481 if (sk_del_node_init(sk
))
482 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, -1);
483 write_unlock_bh(&dgram_lock
);
486 static int dgram_init(struct sock
*sk
)
488 struct dgram_sock
*ro
= dgram_sk(sk
);
495 static void dgram_close(struct sock
*sk
, long timeout
)
497 sk_common_release(sk
);
500 static int dgram_bind(struct sock
*sk
, struct sockaddr
*uaddr
, int len
)
502 struct sockaddr_ieee802154
*addr
= (struct sockaddr_ieee802154
*)uaddr
;
503 struct ieee802154_addr haddr
;
504 struct dgram_sock
*ro
= dgram_sk(sk
);
506 struct net_device
*dev
;
512 if (len
< sizeof(*addr
))
515 if (addr
->family
!= AF_IEEE802154
)
518 ieee802154_addr_from_sa(&haddr
, &addr
->addr
);
519 dev
= ieee802154_get_dev(sock_net(sk
), &haddr
);
525 if (dev
->type
!= ARPHRD_IEEE802154
) {
530 ro
->src_addr
= haddr
;
542 static int dgram_ioctl(struct sock
*sk
, int cmd
, unsigned long arg
)
547 int amount
= sk_wmem_alloc_get(sk
);
549 return put_user(amount
, (int __user
*)arg
);
555 unsigned long amount
;
558 spin_lock_bh(&sk
->sk_receive_queue
.lock
);
559 skb
= skb_peek(&sk
->sk_receive_queue
);
561 /* We will only return the amount
562 * of this packet since that is all
565 amount
= skb
->len
- ieee802154_hdr_length(skb
);
567 spin_unlock_bh(&sk
->sk_receive_queue
.lock
);
568 return put_user(amount
, (int __user
*)arg
);
575 /* FIXME: autobind */
576 static int dgram_connect(struct sock
*sk
, struct sockaddr
*uaddr
,
579 struct sockaddr_ieee802154
*addr
= (struct sockaddr_ieee802154
*)uaddr
;
580 struct dgram_sock
*ro
= dgram_sk(sk
);
583 if (len
< sizeof(*addr
))
586 if (addr
->family
!= AF_IEEE802154
)
596 ieee802154_addr_from_sa(&ro
->dst_addr
, &addr
->addr
);
604 static int dgram_disconnect(struct sock
*sk
, int flags
)
606 struct dgram_sock
*ro
= dgram_sk(sk
);
615 static int dgram_sendmsg(struct sock
*sk
, struct msghdr
*msg
, size_t size
)
617 struct net_device
*dev
;
620 struct ieee802154_mac_cb
*cb
;
621 struct dgram_sock
*ro
= dgram_sk(sk
);
622 struct ieee802154_addr dst_addr
;
626 if (msg
->msg_flags
& MSG_OOB
) {
627 pr_debug("msg->msg_flags = 0x%x\n", msg
->msg_flags
);
631 if (!ro
->connected
&& !msg
->msg_name
)
632 return -EDESTADDRREQ
;
633 else if (ro
->connected
&& msg
->msg_name
)
637 dev
= dev_getfirstbyhwtype(sock_net(sk
), ARPHRD_IEEE802154
);
639 dev
= ieee802154_get_dev(sock_net(sk
), &ro
->src_addr
);
642 pr_debug("no dev\n");
646 mtu
= IEEE802154_MTU
;
647 pr_debug("name = %s, mtu = %u\n", dev
->name
, mtu
);
650 pr_debug("size = %zu, mtu = %u\n", size
, mtu
);
655 hlen
= LL_RESERVED_SPACE(dev
);
656 tlen
= dev
->needed_tailroom
;
657 skb
= sock_alloc_send_skb(sk
, hlen
+ tlen
+ size
,
658 msg
->msg_flags
& MSG_DONTWAIT
,
663 skb_reserve(skb
, hlen
);
665 skb_reset_network_header(skb
);
667 cb
= mac_cb_init(skb
);
668 cb
->type
= IEEE802154_FC_TYPE_DATA
;
669 cb
->ackreq
= ro
->want_ack
;
672 DECLARE_SOCKADDR(struct sockaddr_ieee802154
*,
673 daddr
, msg
->msg_name
);
675 ieee802154_addr_from_sa(&dst_addr
, &daddr
->addr
);
677 dst_addr
= ro
->dst_addr
;
680 cb
->secen
= ro
->secen
;
681 cb
->secen_override
= ro
->secen_override
;
682 cb
->seclevel
= ro
->seclevel
;
683 cb
->seclevel_override
= ro
->seclevel_override
;
685 err
= wpan_dev_hard_header(skb
, dev
, &dst_addr
,
686 ro
->bound
? &ro
->src_addr
: NULL
, size
);
690 err
= memcpy_from_msg(skb_put(skb
, size
), msg
, size
);
695 skb
->protocol
= htons(ETH_P_IEEE802154
);
697 err
= dev_queue_xmit(skb
);
699 err
= net_xmit_errno(err
);
713 static int dgram_recvmsg(struct sock
*sk
, struct msghdr
*msg
, size_t len
,
714 int noblock
, int flags
, int *addr_len
)
717 int err
= -EOPNOTSUPP
;
719 struct dgram_sock
*ro
= dgram_sk(sk
);
720 DECLARE_SOCKADDR(struct sockaddr_ieee802154
*, saddr
, msg
->msg_name
);
722 skb
= skb_recv_datagram(sk
, flags
, noblock
, &err
);
728 msg
->msg_flags
|= MSG_TRUNC
;
732 /* FIXME: skip headers if necessary ?! */
733 err
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
737 sock_recv_ts_and_drops(msg
, sk
, skb
);
740 /* Clear the implicit padding in struct sockaddr_ieee802154
741 * (16 bits between 'family' and 'addr') and in struct
742 * ieee802154_addr_sa (16 bits at the end of the structure).
744 memset(saddr
, 0, sizeof(*saddr
));
746 saddr
->family
= AF_IEEE802154
;
747 ieee802154_addr_to_sa(&saddr
->addr
, &mac_cb(skb
)->source
);
748 *addr_len
= sizeof(*saddr
);
752 err
= put_cmsg(msg
, SOL_IEEE802154
, WPAN_WANTLQI
,
753 sizeof(uint8_t), &(mac_cb(skb
)->lqi
));
758 if (flags
& MSG_TRUNC
)
761 skb_free_datagram(sk
, skb
);
768 static int dgram_rcv_skb(struct sock
*sk
, struct sk_buff
*skb
)
770 skb
= skb_share_check(skb
, GFP_ATOMIC
);
774 if (sock_queue_rcv_skb(sk
, skb
) < 0) {
779 return NET_RX_SUCCESS
;
783 ieee802154_match_sock(__le64 hw_addr
, __le16 pan_id
, __le16 short_addr
,
784 struct dgram_sock
*ro
)
789 if (ro
->src_addr
.mode
== IEEE802154_ADDR_LONG
&&
790 hw_addr
== ro
->src_addr
.extended_addr
)
793 if (ro
->src_addr
.mode
== IEEE802154_ADDR_SHORT
&&
794 pan_id
== ro
->src_addr
.pan_id
&&
795 short_addr
== ro
->src_addr
.short_addr
)
801 static int ieee802154_dgram_deliver(struct net_device
*dev
, struct sk_buff
*skb
)
803 struct sock
*sk
, *prev
= NULL
;
804 int ret
= NET_RX_SUCCESS
;
805 __le16 pan_id
, short_addr
;
808 /* Data frame processing */
809 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
811 pan_id
= dev
->ieee802154_ptr
->pan_id
;
812 short_addr
= dev
->ieee802154_ptr
->short_addr
;
813 hw_addr
= dev
->ieee802154_ptr
->extended_addr
;
815 read_lock(&dgram_lock
);
816 sk_for_each(sk
, &dgram_head
) {
817 if (ieee802154_match_sock(hw_addr
, pan_id
, short_addr
,
820 struct sk_buff
*clone
;
822 clone
= skb_clone(skb
, GFP_ATOMIC
);
824 dgram_rcv_skb(prev
, clone
);
832 dgram_rcv_skb(prev
, skb
);
837 read_unlock(&dgram_lock
);
842 static int dgram_getsockopt(struct sock
*sk
, int level
, int optname
,
843 char __user
*optval
, int __user
*optlen
)
845 struct dgram_sock
*ro
= dgram_sk(sk
);
849 if (level
!= SOL_IEEE802154
)
852 if (get_user(len
, optlen
))
855 len
= min_t(unsigned int, len
, sizeof(int));
865 if (!ro
->secen_override
)
866 val
= WPAN_SECURITY_DEFAULT
;
868 val
= WPAN_SECURITY_ON
;
870 val
= WPAN_SECURITY_OFF
;
872 case WPAN_SECURITY_LEVEL
:
873 if (!ro
->seclevel_override
)
874 val
= WPAN_SECURITY_LEVEL_DEFAULT
;
882 if (put_user(len
, optlen
))
884 if (copy_to_user(optval
, &val
, len
))
889 static int dgram_setsockopt(struct sock
*sk
, int level
, int optname
,
890 char __user
*optval
, unsigned int optlen
)
892 struct dgram_sock
*ro
= dgram_sk(sk
);
893 struct net
*net
= sock_net(sk
);
897 if (optlen
< sizeof(int))
900 if (get_user(val
, (int __user
*)optval
))
907 ro
->want_ack
= !!val
;
910 ro
->want_lqi
= !!val
;
913 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
) &&
914 !ns_capable(net
->user_ns
, CAP_NET_RAW
)) {
920 case WPAN_SECURITY_DEFAULT
:
921 ro
->secen_override
= 0;
923 case WPAN_SECURITY_ON
:
924 ro
->secen_override
= 1;
927 case WPAN_SECURITY_OFF
:
928 ro
->secen_override
= 1;
936 case WPAN_SECURITY_LEVEL
:
937 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
) &&
938 !ns_capable(net
->user_ns
, CAP_NET_RAW
)) {
943 if (val
< WPAN_SECURITY_LEVEL_DEFAULT
||
944 val
> IEEE802154_SCF_SECLEVEL_ENC_MIC128
) {
946 } else if (val
== WPAN_SECURITY_LEVEL_DEFAULT
) {
947 ro
->seclevel_override
= 0;
949 ro
->seclevel_override
= 1;
962 static struct proto ieee802154_dgram_prot
= {
963 .name
= "IEEE-802.15.4-MAC",
964 .owner
= THIS_MODULE
,
965 .obj_size
= sizeof(struct dgram_sock
),
967 .close
= dgram_close
,
969 .sendmsg
= dgram_sendmsg
,
970 .recvmsg
= dgram_recvmsg
,
972 .unhash
= dgram_unhash
,
973 .connect
= dgram_connect
,
974 .disconnect
= dgram_disconnect
,
975 .ioctl
= dgram_ioctl
,
976 .getsockopt
= dgram_getsockopt
,
977 .setsockopt
= dgram_setsockopt
,
980 static const struct proto_ops ieee802154_dgram_ops
= {
981 .family
= PF_IEEE802154
,
982 .owner
= THIS_MODULE
,
983 .release
= ieee802154_sock_release
,
984 .bind
= ieee802154_sock_bind
,
985 .connect
= ieee802154_sock_connect
,
986 .socketpair
= sock_no_socketpair
,
987 .accept
= sock_no_accept
,
988 .getname
= sock_no_getname
,
989 .poll
= datagram_poll
,
990 .ioctl
= ieee802154_sock_ioctl
,
991 .listen
= sock_no_listen
,
992 .shutdown
= sock_no_shutdown
,
993 .setsockopt
= sock_common_setsockopt
,
994 .getsockopt
= sock_common_getsockopt
,
995 .sendmsg
= ieee802154_sock_sendmsg
,
996 .recvmsg
= sock_common_recvmsg
,
997 .mmap
= sock_no_mmap
,
998 .sendpage
= sock_no_sendpage
,
1000 .compat_setsockopt
= compat_sock_common_setsockopt
,
1001 .compat_getsockopt
= compat_sock_common_getsockopt
,
1005 /* Create a socket. Initialise the socket, blank the addresses
1008 static int ieee802154_create(struct net
*net
, struct socket
*sock
,
1009 int protocol
, int kern
)
1013 struct proto
*proto
;
1014 const struct proto_ops
*ops
;
1016 if (!net_eq(net
, &init_net
))
1017 return -EAFNOSUPPORT
;
1019 switch (sock
->type
) {
1021 proto
= &ieee802154_raw_prot
;
1022 ops
= &ieee802154_raw_ops
;
1025 proto
= &ieee802154_dgram_prot
;
1026 ops
= &ieee802154_dgram_ops
;
1029 rc
= -ESOCKTNOSUPPORT
;
1034 sk
= sk_alloc(net
, PF_IEEE802154
, GFP_KERNEL
, proto
, kern
);
1041 sock_init_data(sock
, sk
);
1042 /* FIXME: sk->sk_destruct */
1043 sk
->sk_family
= PF_IEEE802154
;
1045 /* Checksums on by default */
1046 sock_set_flag(sk
, SOCK_ZAPPED
);
1048 if (sk
->sk_prot
->hash
) {
1049 rc
= sk
->sk_prot
->hash(sk
);
1051 sk_common_release(sk
);
1056 if (sk
->sk_prot
->init
) {
1057 rc
= sk
->sk_prot
->init(sk
);
1059 sk_common_release(sk
);
1065 static const struct net_proto_family ieee802154_family_ops
= {
1066 .family
= PF_IEEE802154
,
1067 .create
= ieee802154_create
,
1068 .owner
= THIS_MODULE
,
1071 static int ieee802154_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
1072 struct packet_type
*pt
, struct net_device
*orig_dev
)
1074 if (!netif_running(dev
))
1076 pr_debug("got frame, type %d, dev %p\n", dev
->type
, dev
);
1078 print_hex_dump_bytes("ieee802154_rcv ",
1079 DUMP_PREFIX_NONE
, skb
->data
, skb
->len
);
1082 if (!net_eq(dev_net(dev
), &init_net
))
1085 ieee802154_raw_deliver(dev
, skb
);
1087 if (dev
->type
!= ARPHRD_IEEE802154
)
1090 if (skb
->pkt_type
!= PACKET_OTHERHOST
)
1091 return ieee802154_dgram_deliver(dev
, skb
);
1098 static struct packet_type ieee802154_packet_type
= {
1099 .type
= htons(ETH_P_IEEE802154
),
1100 .func
= ieee802154_rcv
,
1103 static int __init
af_ieee802154_init(void)
1107 rc
= proto_register(&ieee802154_raw_prot
, 1);
1111 rc
= proto_register(&ieee802154_dgram_prot
, 1);
1115 /* Tell SOCKET that we are alive */
1116 rc
= sock_register(&ieee802154_family_ops
);
1119 dev_add_pack(&ieee802154_packet_type
);
1125 proto_unregister(&ieee802154_dgram_prot
);
1127 proto_unregister(&ieee802154_raw_prot
);
1132 static void __exit
af_ieee802154_remove(void)
1134 dev_remove_pack(&ieee802154_packet_type
);
1135 sock_unregister(PF_IEEE802154
);
1136 proto_unregister(&ieee802154_dgram_prot
);
1137 proto_unregister(&ieee802154_raw_prot
);
1140 module_init(af_ieee802154_init
);
1141 module_exit(af_ieee802154_remove
);
1143 MODULE_LICENSE("GPL");
1144 MODULE_ALIAS_NETPROTO(PF_IEEE802154
);