From patchwork Fri Jun 16 03:57:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Greer X-Patchwork-Id: 9790483 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 60D0860326 for ; Fri, 16 Jun 2017 03:57:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A4CF2841D for ; Fri, 16 Jun 2017 03:57:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F2DB2856A; Fri, 16 Jun 2017 03:57:41 +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 A1FD5284C0 for ; Fri, 16 Jun 2017 03:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751761AbdFPD5c (ORCPT ); Thu, 15 Jun 2017 23:57:32 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49459 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981AbdFPD5b (ORCPT ); Thu, 15 Jun 2017 23:57:31 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 5E74E20A08; Thu, 15 Jun 2017 23:57:30 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute3.internal (MEProxy); Thu, 15 Jun 2017 23:57:30 -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=gXq 78CgLtg/6Htn9swHcJPWVuHAprpIX67nHl9T/wQI=; b=f/ctpXKIYVY0EiSbZGS CuIFco2LLt6Mw6hOB776uUPFQP7q/2u0wpzf1wwrQ6hN0vrD+0FyeftHUaulmm7o ZTRQOneGNPmVQXLYGIYCdN9SZGogN31ZlmBfC6704K1R/DgCIp8uMsqwzx5jVO1W +AKKIFS/WlXfwZMRtyDxpr0Y= 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=gXq78CgLtg/6Htn9swHcJPWVuHAprpIX67nHl9T/w QI=; b=j1wHGxxUKjnAlXi3HlfMlcQJSvAQb+kbtMEb2V2oE6pvGxCPtvCSV8dhk AobC3xX9Pd4+3i7flH9wf1gFGDU3hnBsXoVudYu2t4GyKT4qrecpwy6ZgrFANoUo gGLi+ME8c1wj9luJ2zZDphJFnGEihZwFl9rf2v/JotPnyDTCSY1rEfUV0WOysf+N 3Q2P9f8v+nkT7LWSwRibyxCpNUC3/mZ3Rx48EOOmZ7+Sydxgrr7DWk67dcO1DFON q/uy7iHhaydpqyblJjiSCVasfqNRH6V2+Vx46DneO7MiFvrXt3AXZcEL8dgM9Qu+ lPrE9kiBeeF0reBWOvcS7oytlhl4Q== X-ME-Sender: X-Sasl-enc: MB+wOFaMasRnlyBL2fhyBhcVefFMykF+YfZyAe3llgHd 1497585450 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 1AF0F2492D; Thu, 15 Jun 2017 23:57:30 -0400 (EDT) Received: from blue.animalcreek.com (localhost [127.0.0.1]) by blue.animalcreek.com (Postfix) with ESMTP id 85DF0A20501; Thu, 15 Jun 2017 20:57:29 -0700 (MST) From: Mark Greer To: Samuel Ortiz Cc: linux-wireless@vger.kernel.org, linux-nfc@lists.01.org, Mark Greer Subject: [PATCH 3/4] tag: Add Tag deactivate support Date: Thu, 15 Jun 2017 20:57:27 -0700 Message-Id: <20170616035728.19415-4-mgreer@animalcreek.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170616035728.19415-1-mgreer@animalcreek.com> References: <20170616035728.19415-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 a tag has been discovered, it remains active until it is moved out of range, or an error occurs while reading or writing it. While the tag is active, the adapter cannot be powered off. This wastes power when the client application no longer cares whether the tag is in range or not. To address this issue, add the ability for a client application to deactivate an active tag. Once deactivated, the client application can poll the tag again to read it or power off the adapter. The 'NFC_CMD_DEACTIVATE_TARGET' netlink command is added to request that the kernel deactivate the target (tag). Signed-off-by: Mark Greer --- doc/tag-api.txt | 8 ++++++++ include/nfc_copy.h | 2 ++ src/near.h | 1 + src/netlink.c | 33 +++++++++++++++++++++++++++++++++ src/tag.c | 29 +++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+) diff --git a/doc/tag-api.txt b/doc/tag-api.txt index b388b22..4ed24da 100644 --- a/doc/tag-api.txt +++ b/doc/tag-api.txt @@ -25,6 +25,14 @@ Method void Write(dict attributes) org.neard.Error.InvalidArguments org.neard.Error.InProgress +Method void Deactivate() + + Deactivates a tag. + + Possible Errors: org.neard.Error.PermissionDenied + org.neard.Error.OutOfMemory + org.neard.Error.InvalidArguments + org.neard.Error.NotSupported Properties string Type [readonly] diff --git a/include/nfc_copy.h b/include/nfc_copy.h index 399f39f..f6e3c8c 100644 --- a/include/nfc_copy.h +++ b/include/nfc_copy.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/src/near.h b/src/near.h index 50a4c8b..e7f7fa7 100644 --- a/src/near.h +++ b/src/near.h @@ -166,6 +166,7 @@ int __near_netlink_start_poll(int idx, int __near_netlink_stop_poll(int idx); int __near_netlink_activate_target(uint32_t idx, uint32_t target_idx, uint32_t protocol); +int __near_netlink_deactivate_target(uint32_t idx, uint32_t target_idx); int __near_netlink_dep_link_up(uint32_t idx, uint32_t target_idx, uint8_t comm_mode, uint8_t rf_mode); int __near_netlink_dep_link_down(uint32_t idx); diff --git a/src/netlink.c b/src/netlink.c index d02d62f..3c77999 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -329,6 +329,39 @@ nla_put_failure: return err; } +int __near_netlink_deactivate_target(uint32_t idx, uint32_t target_idx) +{ + struct nl_msg *msg; + void *hdr; + int err; + + DBG(""); + + msg = nlmsg_alloc(); + if (!msg) + return -ENOMEM; + + hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0, + NLM_F_REQUEST, NFC_CMD_DEACTIVATE_TARGET, + NFC_GENL_VERSION); + if (!hdr) { + err = -EINVAL; + goto nla_put_failure; + } + + err = -EMSGSIZE; + + NLA_PUT_U32(msg, NFC_ATTR_DEVICE_INDEX, idx); + NLA_PUT_U32(msg, NFC_ATTR_TARGET_INDEX, target_idx); + + err = nl_send_msg(nfc_state->cmd_sock, msg, NULL, NULL); + +nla_put_failure: + nlmsg_free(msg); + + return err; +} + int __near_netlink_dep_link_up(uint32_t idx, uint32_t target_idx, uint8_t comm_mode, uint8_t rf_mode) { diff --git a/src/tag.c b/src/tag.c index 01015a1..9eba4ee 100644 --- a/src/tag.c +++ b/src/tag.c @@ -486,9 +486,38 @@ fail: return __near_error_failed(msg, ENOMEM); } +static DBusMessage *deactivate_tag(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct near_tag *tag = data; + struct near_adapter *adapter; + int err; + + DBG("deactivating tag %p", conn); + + adapter = __near_adapter_get(tag->adapter_idx); + if (!adapter) + return __near_error_failed(msg, EINVAL); + + __near_adapter_stop_check_presence(tag->adapter_idx, tag->target_idx); + + err = __near_netlink_deactivate_target(tag->adapter_idx, + tag->target_idx); + if (err < 0) + return __near_error_failed(msg, -err); + + near_adapter_disconnect(tag->adapter_idx); + + if (__near_adapter_is_constant_poll(adapter)) + __near_adapter_start_poll(adapter); + + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); +} + static const GDBusMethodTable tag_methods[] = { { GDBUS_ASYNC_METHOD("Write", GDBUS_ARGS({"attributes", "a{sv}"}), NULL, write_ndef) }, + { GDBUS_METHOD("Deactivate", NULL, NULL, deactivate_tag) }, { }, };