summaryrefslogtreecommitdiffstats
path: root/net/ieee802154/socket.c
diff options
context:
space:
mode:
authorRomuald CARI <romuald.cari@devialet.com>2018-06-07 10:08:02 -0400
committerStefan Schmidt <stefan@datenfreihafen.org>2018-07-13 12:18:18 -0400
commit811e299f4645588cc7a1b78d97b6847c155324b9 (patch)
treeab73de5d56f6d2ac75a1cecc4096184abe6dda5f /net/ieee802154/socket.c
parent430ac34de9693bfe4bea0bab830e0ca0be9ef4b9 (diff)
ieee802154: add rx LQI from userspace
The Link Quality Indication data exposed by drivers could not be accessed from userspace. Since this data is per-datagram received, it makes sense to make it available to userspace application through the ancillary data mechanism in recvmsg rather than through ioctls. This can be activated using the socket option WPAN_WANTLQI under SOL_IEEE802154 protocol. This LQI data is available in the ancillary data buffer under the SOL_IEEE802154 level as the type WPAN_LQI. The value is an unsigned byte indicating the link quality with values ranging 0-255. Signed-off-by: Romuald Cari <romuald.cari@devialet.com> Signed-off-by: Clément Peron <clement.peron@devialet.com> Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
Diffstat (limited to 'net/ieee802154/socket.c')
-rw-r--r--net/ieee802154/socket.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c
index a60658c85a9a..bc6b912603f1 100644
--- a/net/ieee802154/socket.c
+++ b/net/ieee802154/socket.c
@@ -25,6 +25,7 @@
25#include <linux/termios.h> /* For TIOCOUTQ/INQ */ 25#include <linux/termios.h> /* For TIOCOUTQ/INQ */
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/socket.h>
28#include <net/datalink.h> 29#include <net/datalink.h>
29#include <net/psnap.h> 30#include <net/psnap.h>
30#include <net/sock.h> 31#include <net/sock.h>
@@ -452,6 +453,7 @@ struct dgram_sock {
452 unsigned int bound:1; 453 unsigned int bound:1;
453 unsigned int connected:1; 454 unsigned int connected:1;
454 unsigned int want_ack:1; 455 unsigned int want_ack:1;
456 unsigned int want_lqi:1;
455 unsigned int secen:1; 457 unsigned int secen:1;
456 unsigned int secen_override:1; 458 unsigned int secen_override:1;
457 unsigned int seclevel:3; 459 unsigned int seclevel:3;
@@ -486,6 +488,7 @@ static int dgram_init(struct sock *sk)
486 struct dgram_sock *ro = dgram_sk(sk); 488 struct dgram_sock *ro = dgram_sk(sk);
487 489
488 ro->want_ack = 1; 490 ro->want_ack = 1;
491 ro->want_lqi = 0;
489 return 0; 492 return 0;
490} 493}
491 494
@@ -713,6 +716,7 @@ static int dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
713 size_t copied = 0; 716 size_t copied = 0;
714 int err = -EOPNOTSUPP; 717 int err = -EOPNOTSUPP;
715 struct sk_buff *skb; 718 struct sk_buff *skb;
719 struct dgram_sock *ro = dgram_sk(sk);
716 DECLARE_SOCKADDR(struct sockaddr_ieee802154 *, saddr, msg->msg_name); 720 DECLARE_SOCKADDR(struct sockaddr_ieee802154 *, saddr, msg->msg_name);
717 721
718 skb = skb_recv_datagram(sk, flags, noblock, &err); 722 skb = skb_recv_datagram(sk, flags, noblock, &err);
@@ -744,6 +748,13 @@ static int dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
744 *addr_len = sizeof(*saddr); 748 *addr_len = sizeof(*saddr);
745 } 749 }
746 750
751 if (ro->want_lqi) {
752 err = put_cmsg(msg, SOL_IEEE802154, WPAN_WANTLQI,
753 sizeof(uint8_t), &(mac_cb(skb)->lqi));
754 if (err)
755 goto done;
756 }
757
747 if (flags & MSG_TRUNC) 758 if (flags & MSG_TRUNC)
748 copied = skb->len; 759 copied = skb->len;
749done: 760done:
@@ -847,6 +858,9 @@ static int dgram_getsockopt(struct sock *sk, int level, int optname,
847 case WPAN_WANTACK: 858 case WPAN_WANTACK:
848 val = ro->want_ack; 859 val = ro->want_ack;
849 break; 860 break;
861 case WPAN_WANTLQI:
862 val = ro->want_lqi;
863 break;
850 case WPAN_SECURITY: 864 case WPAN_SECURITY:
851 if (!ro->secen_override) 865 if (!ro->secen_override)
852 val = WPAN_SECURITY_DEFAULT; 866 val = WPAN_SECURITY_DEFAULT;
@@ -892,6 +906,9 @@ static int dgram_setsockopt(struct sock *sk, int level, int optname,
892 case WPAN_WANTACK: 906 case WPAN_WANTACK:
893 ro->want_ack = !!val; 907 ro->want_ack = !!val;
894 break; 908 break;
909 case WPAN_WANTLQI:
910 ro->want_lqi = !!val;
911 break;
895 case WPAN_SECURITY: 912 case WPAN_SECURITY:
896 if (!ns_capable(net->user_ns, CAP_NET_ADMIN) && 913 if (!ns_capable(net->user_ns, CAP_NET_ADMIN) &&
897 !ns_capable(net->user_ns, CAP_NET_RAW)) { 914 !ns_capable(net->user_ns, CAP_NET_RAW)) {