aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc
diff options
context:
space:
mode:
authorMark Greer <mgreer@animalcreek.com>2017-06-15 23:34:22 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2017-11-09 18:03:39 -0500
commit4d63adfe12dd9cb61ed8badb4d798955399048c2 (patch)
tree66b92544d76b7033e73a78897169612109eefe29 /net/nfc
parent72ad533acc22870156736c2fef4674c01307695e (diff)
NFC: Add NFC_CMD_DEACTIVATE_TARGET support
Once an NFC target (i.e., a tag) is found, it remains active until there is a failure reading or writing it (often caused by the target moving out of range). While the target is active, the NFC adapter and antenna must remain powered. This wastes power when the target remains in range but the client application no longer cares whether it is there or not. To mitigate this, add a new netlink command that allows userspace to deactivate an active target. When issued, this command will cause the NFC subsystem to act as though the target was moved out of range. Once the command has been executed, the client application can power off the NFC adapter to reduce power consumption. Signed-off-by: Mark Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'net/nfc')
-rw-r--r--net/nfc/netlink.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index b251fb936a27..f6359c277212 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -928,6 +928,30 @@ static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info)
928 return rc; 928 return rc;
929} 929}
930 930
931static int nfc_genl_deactivate_target(struct sk_buff *skb,
932 struct genl_info *info)
933{
934 struct nfc_dev *dev;
935 u32 device_idx, target_idx;
936 int rc;
937
938 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
939 return -EINVAL;
940
941 device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
942
943 dev = nfc_get_device(device_idx);
944 if (!dev)
945 return -ENODEV;
946
947 target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
948
949 rc = nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
950
951 nfc_put_device(dev);
952 return rc;
953}
954
931static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info) 955static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info)
932{ 956{
933 struct nfc_dev *dev; 957 struct nfc_dev *dev;
@@ -1751,6 +1775,11 @@ static const struct genl_ops nfc_genl_ops[] = {
1751 .doit = nfc_genl_vendor_cmd, 1775 .doit = nfc_genl_vendor_cmd,
1752 .policy = nfc_genl_policy, 1776 .policy = nfc_genl_policy,
1753 }, 1777 },
1778 {
1779 .cmd = NFC_CMD_DEACTIVATE_TARGET,
1780 .doit = nfc_genl_deactivate_target,
1781 .policy = nfc_genl_policy,
1782 },
1754}; 1783};
1755 1784
1756static struct genl_family nfc_genl_family __ro_after_init = { 1785static struct genl_family nfc_genl_family __ro_after_init = {