From patchwork Fri Jun 16 03:34:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Greer X-Patchwork-Id: 9790473 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E53CC60231 for ; Fri, 16 Jun 2017 03:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8AFE1FF81 for ; Fri, 16 Jun 2017 03:41:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDAD62029B; Fri, 16 Jun 2017 03:41:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EA00200DF for ; Fri, 16 Jun 2017 03:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751727AbdFPDkz (ORCPT ); Thu, 15 Jun 2017 23:40:55 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37061 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750792AbdFPDkx (ORCPT ); Thu, 15 Jun 2017 23:40:53 -0400 X-Greylist: delayed 386 seconds by postgrey-1.27 at vger.kernel.org; Thu, 15 Jun 2017 23:40:53 EDT Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 4A896209A9; Thu, 15 Jun 2017 23:34:27 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute3.internal (MEProxy); Thu, 15 Jun 2017 23:34:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=animalcreek.com; h=cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=wop ul6FPApnG2yqdjPLqGE8NgNAJFXDJUNYIqfnYbVI=; b=AwEGBby7aY+ggdTkNrk tSJMP5lOR+c6tSimOAiKXWV+xm6ecu3S3oZRFkHV52mJFP/JWTKxj28rOlO81AAD Qls9hWvLcrLSwpH3dZ4Lba9vfK/7AJ5ej+w6l3G4jopFFACxKbYFrlYlnNOdF0IX jffbXWcJcBQbfIxh52NlAUCc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=wopul6FPApnG2yqdjPLqGE8NgNAJFXDJUNYIqfnYb VI=; b=jPZYx5SD90Ydp99J2keYBmrkyGJzZbhPCxzuTWYDTBLFztHaAMXn0GZiq nYkN4MGNiW8wHHzQgcMaTJuOG/gqk2b4LGxy+yA60OK6e1ZYaQxKx3kNn950lDLd i10IzIL3kvklIdWCYvsjAffWhhp7/NY6O2L8TpEtn4UO3P8Zga7v+tWl5Fiq8Jxc 8y0b/JlB7bQ94wccy1DYMGVjgiuAA2bmNYtEbRWuuNRl0nUo/R4882vXu0KIv2// L1zsE5DxyLwGVCoz4xEFps7e5sG2HROvNEMai3YKYAEo6ih3uRtKdl3Z56QOTBFw Nj9DzbQdCLVDamIATBFrJma1TcNfw== X-ME-Sender: X-Sasl-enc: gluCookwYWh3zQT/23CSySOa9kK7ZHyCxCkSyw5ci7Tj 1497584067 Received: from blue.animalcreek.com (ip68-2-81-12.ph.ph.cox.net [68.2.81.12]) by mail.messagingengine.com (Postfix) with ESMTPA id 097CC249CF; Thu, 15 Jun 2017 23:34:27 -0400 (EDT) Received: from blue.animalcreek.com (localhost [127.0.0.1]) by blue.animalcreek.com (Postfix) with ESMTP id 51F2FA202D8; Thu, 15 Jun 2017 20:34:26 -0700 (MST) From: Mark Greer To: Samuel Ortiz Cc: linux-wireless@vger.kernel.org, linux-nfc@lists.01.org, Mark Greer Subject: [PATCH 2/2] NFC: Add NFC_CMD_DEACTIVATE_TARGET support Date: Thu, 15 Jun 2017 20:34:22 -0700 Message-Id: <20170616033422.18484-3-mgreer@animalcreek.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170616033422.18484-1-mgreer@animalcreek.com> References: <20170616033422.18484-1-mgreer@animalcreek.com> Organization: Animal Creek Technologies, Inc. Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- I'm not really sure what the correct argument for the mode parameter of digital_activate_target() is. I do not have any NCI controllers to test with. --- include/uapi/linux/nfc.h | 2 ++ net/nfc/netlink.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/uapi/linux/nfc.h b/include/uapi/linux/nfc.h index 399f39ff8048..f6e3c8c9c744 100644 --- a/include/uapi/linux/nfc.h +++ b/include/uapi/linux/nfc.h @@ -89,6 +89,7 @@ * @NFC_CMD_ACTIVATE_TARGET: Request NFC controller to reactivate target. * @NFC_CMD_VENDOR: Vendor specific command, to be implemented directly * from the driver in order to support hardware specific operations. + * @NFC_CMD_DEACTIVATE_TARGET: Request NFC controller to deactivate target. */ enum nfc_commands { NFC_CMD_UNSPEC, @@ -121,6 +122,7 @@ enum nfc_commands { NFC_CMD_SE_IO, NFC_CMD_ACTIVATE_TARGET, NFC_CMD_VENDOR, + NFC_CMD_DEACTIVATE_TARGET, /* private: internal use only */ __NFC_CMD_AFTER_LAST }; diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c index 6b0850e63e09..43a27e43ef12 100644 --- a/net/nfc/netlink.c +++ b/net/nfc/netlink.c @@ -926,6 +926,30 @@ static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info) return rc; } +static int nfc_genl_deactivate_target(struct sk_buff *skb, + struct genl_info *info) +{ + struct nfc_dev *dev; + u32 device_idx, target_idx; + int rc; + + if (!info->attrs[NFC_ATTR_DEVICE_INDEX]) + return -EINVAL; + + device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]); + + dev = nfc_get_device(device_idx); + if (!dev) + return -ENODEV; + + target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]); + + rc = nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP); + + nfc_put_device(dev); + return rc; +} + static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info) { struct nfc_dev *dev; @@ -1749,6 +1773,11 @@ static const struct genl_ops nfc_genl_ops[] = { .doit = nfc_genl_vendor_cmd, .policy = nfc_genl_policy, }, + { + .cmd = NFC_CMD_DEACTIVATE_TARGET, + .doit = nfc_genl_deactivate_target, + .policy = nfc_genl_policy, + }, }; static struct genl_family nfc_genl_family __ro_after_init = {