Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2213542imm; Thu, 7 Jun 2018 07:10:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIhXp4bS0eKREj9CuVXQPkPEbGnVV7WWpF0/KIj+HH1EjRJDqgNdXNbsoOujZhUw3KNqyQ8 X-Received: by 2002:a65:5143:: with SMTP id g3-v6mr1743181pgq.190.1528380636364; Thu, 07 Jun 2018 07:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528380636; cv=none; d=google.com; s=arc-20160816; b=nnfmkPw6IP33ULFc9ZrOouUyNJDEUT/d+6BxqqGRUE+2GX0U1M9s+VbFwwj+eGG3vD R5iwdOOJe8/zIRzcpco7nY/wmq7EtkyTiASj6S3f1obU3PrQhAMQ2Vb6aydEforMli2K wM54BRAuHvTNjTUYEIqYl5Ehdbf+8rcBiAyWOY9H2Z0V8Vxpvf1hqe7dsybKb0vpFJFn EFTrVLIRZYOjObrtAj/+WGYE3GCVcXXUsvrG6xYEcKacnSg8QNb81VrNwB6/MVKVNa10 QMsx6Tl+8JUjrqBaAPWqf4qyFTxAuHLpHMtGqRus+tV+WjcgX1fRx/VWOvO4+QkBFMDV nxiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=TTq6FcN4scqYAmpupQ6CB48xck81EgeWWIq/66Nv8pw=; b=RQXViiCro6ThP7GHFRHCR11LD7Wy5iBeBnS9w/o/TxF9U2URn2mftnzWLXaFzV6nfi M/ZYIRQ1vKiE/4Bqukd7NLDrb+NSmSM68fkbc6bdG6AzSgf305zBNWq1CTMnn/I+s5jm rTxpk6fpHIqaUpssLKEIP0kDfMAAqM1jBtnY3WrGqL/ASJsuXvZO1/RJxNToCNbb+Fvy lN7e8UHJcJJV6goI/QnhtmsHE4A602uqM/taE45nJVbSH52QOcj7u+7UA11BKx2Y85O+ DYIcBvaTnizBDpsGbwxRrSIriPcCyLcO395oXbF4ycLyn4/skehof1r268I4fqS6frvc oEWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pPNoSARG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5-v6si28257015pln.567.2018.06.07.07.10.21; Thu, 07 Jun 2018 07:10:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pPNoSARG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932846AbeFGOIb (ORCPT + 99 others); Thu, 7 Jun 2018 10:08:31 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33171 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753447AbeFGOI3 (ORCPT ); Thu, 7 Jun 2018 10:08:29 -0400 Received: by mail-wm0-f67.google.com with SMTP id z6-v6so3366904wma.0; Thu, 07 Jun 2018 07:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=TTq6FcN4scqYAmpupQ6CB48xck81EgeWWIq/66Nv8pw=; b=pPNoSARG77X2wVbfkDovvpmLl33EQ52hkiAQv4X228ETXY5avxq7Ok+wHWAetLq9qA fAfvvn8XR9g9PlpAWFokcsklu3CrZU3zlKyWt4FsqgQhiWBRB9zjPFGAZRKoGwRr7+Kp fStTU91Rta3A6Bd3YBP+kUw0Y7Os7AVTo5U2IY9d9MNl+OxTaTdoxykWD4KLS9G8E27v dRIGleMRsQg/uj9MN4YpBPROOCoRvWDGr3sXgmP00vn/IFj/IzgjHqwGKvufkmvwckdW 25YOGakzdZ1zho8cAg06LproiyVxln/3tP9XwfOGGJozqeHgNyxtBcf1NsMrsXqpuuW0 N3/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=TTq6FcN4scqYAmpupQ6CB48xck81EgeWWIq/66Nv8pw=; b=l62HCdWOP12pztRTQy5DJczV37BN0D6MIFBhnJXIBPtZmNQaHMPMV4tYf/3vRtfqMO 7zmZ6BQQ8iwfdLOWj41E+bkzsoBPfq9yXw6YhuX23pt4vME0HuYmDBmf0BeZH1kiNJkU HOwPZ303E972zj1KU4oq6HNl3zfvsSWnUW+n1pnT9Dg7U61A7RDAefr4CGggEaK1HUnq qQVWkLG6S7zBBKGYctg+ggjQ0BmZQNpWYptcAeB2dZ/S7DkVoQhzp/bYuMbHjJB03i9s TQTd2aUsrAPHtUDYoGoQsdfIX+p3LvTfprgMi/DRKIXInsJaH3JotM5QZ1uZMGPS/6ts IeWA== X-Gm-Message-State: APt69E234A7C59rTvh/nBJAaCdD4VPVFjYlJc+f0LEmFX2eUuv4UZdKe oxcZ9BsFjhIK2puZHqZ2XuQ= X-Received: by 2002:a1c:5b0d:: with SMTP id p13-v6mr1766032wmb.53.1528380508122; Thu, 07 Jun 2018 07:08:28 -0700 (PDT) Received: from cperon-Latitude-7490.lan (static-css-csd-151233.business.bouyguestelecom.com. [176.162.151.233]) by smtp.gmail.com with ESMTPSA id u15-v6sm2591636wma.37.2018.06.07.07.08.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 07:08:27 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= To: Romuald Cari , linux-wpan@vger.kernel.org Cc: Alexander Aring , Stefan Schmidt , "David S . Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Cl=C3=A9ment=20Peron?= Subject: [PATCH] ieee802154: add rx LQI from userspace Date: Thu, 7 Jun 2018 16:08:02 +0200 Message-Id: <20180607140802.22666-1-peron.clem@gmail.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Romuald CARI 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 Signed-off-by: Clément Peron --- include/net/af_ieee802154.h | 1 + net/ieee802154/socket.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/net/af_ieee802154.h b/include/net/af_ieee802154.h index a5563d27a3eb..8003a9f6eb43 100644 --- a/include/net/af_ieee802154.h +++ b/include/net/af_ieee802154.h @@ -56,6 +56,7 @@ struct sockaddr_ieee802154 { #define WPAN_WANTACK 0 #define WPAN_SECURITY 1 #define WPAN_SECURITY_LEVEL 2 +#define WPAN_WANTLQI 3 #define WPAN_SECURITY_DEFAULT 0 #define WPAN_SECURITY_OFF 1 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 @@ #include /* For TIOCOUTQ/INQ */ #include #include +#include #include #include #include @@ -452,6 +453,7 @@ struct dgram_sock { unsigned int bound:1; unsigned int connected:1; unsigned int want_ack:1; + unsigned int want_lqi:1; unsigned int secen:1; unsigned int secen_override:1; unsigned int seclevel:3; @@ -486,6 +488,7 @@ static int dgram_init(struct sock *sk) struct dgram_sock *ro = dgram_sk(sk); ro->want_ack = 1; + ro->want_lqi = 0; return 0; } @@ -713,6 +716,7 @@ static int dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, size_t copied = 0; int err = -EOPNOTSUPP; struct sk_buff *skb; + struct dgram_sock *ro = dgram_sk(sk); DECLARE_SOCKADDR(struct sockaddr_ieee802154 *, saddr, msg->msg_name); 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, *addr_len = sizeof(*saddr); } + if (ro->want_lqi) { + err = put_cmsg(msg, SOL_IEEE802154, WPAN_WANTLQI, + sizeof(uint8_t), &(mac_cb(skb)->lqi)); + if (err) + goto done; + } + if (flags & MSG_TRUNC) copied = skb->len; done: @@ -847,6 +858,9 @@ static int dgram_getsockopt(struct sock *sk, int level, int optname, case WPAN_WANTACK: val = ro->want_ack; break; + case WPAN_WANTLQI: + val = ro->want_lqi; + break; case WPAN_SECURITY: if (!ro->secen_override) val = WPAN_SECURITY_DEFAULT; @@ -892,6 +906,9 @@ static int dgram_setsockopt(struct sock *sk, int level, int optname, case WPAN_WANTACK: ro->want_ack = !!val; break; + case WPAN_WANTLQI: + ro->want_lqi = !!val; + break; case WPAN_SECURITY: if (!ns_capable(net->user_ns, CAP_NET_ADMIN) && !ns_capable(net->user_ns, CAP_NET_RAW)) { -- 2.17.1