From patchwork Thu Jun 15 18:25:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Greer X-Patchwork-Id: 9789801 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 1108960325 for ; Thu, 15 Jun 2017 18:25:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 098A12861E for ; Thu, 15 Jun 2017 18:25:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F267F2862C; Thu, 15 Jun 2017 18:25:48 +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 8661D2861E for ; Thu, 15 Jun 2017 18:25:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753211AbdFOSZe (ORCPT ); Thu, 15 Jun 2017 14:25:34 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:55073 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752070AbdFOSZb (ORCPT ); Thu, 15 Jun 2017 14:25:31 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 97E1320A98; Thu, 15 Jun 2017 14:25:19 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Thu, 15 Jun 2017 14:25:19 -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=hMW skdUICUERMeLcLR8BI8ggHblikjdZyJJEEBWHJJA=; b=TNPMxQ5phtGW9p9nViS CSeG2x384VQHL0Pm+5KuvERPjR6lwETBW8alojCFvjIUkUNLZyeTNkJEOgySQY9k z+ySTAufY2Lea2y/7pRaxk2Tx16kBys9aqbZM1AF3GhAIuJXd1As+F2PUynomwU+ KL9ZG1IitNw6V/SCUnpi5hFA= 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=hMWskdUICUERMeLcLR8BI8ggHblikjdZyJJEEBWHJ JA=; b=p1abE/hiAJBdwWA/UrJCgyTXSbQLLnKxYkMmMo45S13kVeztxNNoYc62X P3itjIYKMt3bUL0szeUYW2DcCbgLvtf9asneeF4X0zIWiCe5w70cfNF1IyX5V0A6 XBKqlmXCBZ1aNvzMGkIAXSx6zYfw1Od8uLD2gSvB8GB+XvuX/5z1cleGoiuyrQoT qsypXLfy6I2uNvd1N1HOgXEuE2bI64O9+DtuNnGq5zRBGXXXetNgMngjPdD1qcV7 fWX2hTZmfHN7wW/+gPnhEASz1q4J8uu5c8wjhgpC2HGzIEzktbZX5/7iY24m55qr cp/KOSZUzRo1pok3bNKHFx6Ra1f9A== X-ME-Sender: X-Sasl-enc: GJkGxVX1ZQoMgck01kMCVXTrjBHToFb0Ue7zboi8IvZT 1497551119 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 2BAFF7E9CC; Thu, 15 Jun 2017 14:25:19 -0400 (EDT) Received: from blue.animalcreek.com (localhost [127.0.0.1]) by blue.animalcreek.com (Postfix) with ESMTP id 423E5A20607; Thu, 15 Jun 2017 11:25:18 -0700 (MST) From: Mark Greer To: Samuel Ortiz Cc: linux-wireless@vger.kernel.org, linux-nfc@lists.01.org, Mark Greer Subject: [PATCH 19/23] nfctype5: Don't issue RMB command when formatting Date: Thu, 15 Jun 2017 11:25:12 -0700 Message-Id: <20170615182516.4508-20-mgreer@animalcreek.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170615182516.4508-1-mgreer@animalcreek.com> References: <20170615182516.4508-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 Currently, when neard is formatting a Type 5 tag, it issues the Read Multiple Blocks (RMB) command to see if the tag supports it. If the command succeeds, the appropriate bit in the CC is set so the RMB command can be used in the future. The problem is that when the tag doesn't support the command, a failure is returned by the kernel causing the neard adapter code to disconnect from the tag. This effectively makes the tag unusable by neard. To avoid this issue, don't bother checking to see if the RMB command is supported and just assume that it isn't (and therefore, do not set the MBREAD bit in the CC). This has the benefit of formatting Type 5 tags that don't support RMB at the cost of forcing future readers to use a series of Read Single Block commands for multi-block reads (i.e., slower than a single multi-block read). Signed-off-by: Mark Greer --- plugins/nfctype5.c | 77 +++++++++++++++++------------------------------------- 1 file changed, 24 insertions(+), 53 deletions(-) diff --git a/plugins/nfctype5.c b/plugins/nfctype5.c index 873ac79..a91d8f5 100644 --- a/plugins/nfctype5.c +++ b/plugins/nfctype5.c @@ -1048,30 +1048,31 @@ static int nfctype5_format_resp(struct near_tag *tag, int err, void *data) return t5_cookie_release(err, cookie); } -static int t5_format_read_multiple_blocks_resp(uint8_t *resp, int length, - void *data) +static int nfctype5_format(uint32_t adapter_idx, uint32_t target_idx, + near_tag_io_cb cb) { - struct type5_read_multiple_blocks_resp *t5_resp = - (struct type5_read_multiple_blocks_resp *) - (resp + NFC_HEADER_SIZE); - struct t5_cookie *cookie = data; struct type5_cc t5_cc; - struct near_tag *tag = cookie->tag; - uint8_t blk_size = near_tag_get_blk_size(tag); + struct t5_cookie *cookie; + struct near_tag *tag; size_t mem_size; - bool read_multiple_supported = false; int err; DBG(""); - err = t5_check_resp(resp, length); - if (!err) { - length -= NFC_HEADER_SIZE; + tag = near_tag_get_tag(adapter_idx, target_idx); + if (!tag) { + err = -EINVAL; + goto out_err; + } - if (length == (int)(sizeof(*t5_resp) + (2 * blk_size))) - read_multiple_supported = true; + cookie = t5_cookie_alloc(tag); + if (!cookie) { + err = -ENOMEM; + goto out_err; } + cookie->cb = cb; + t5_cc.cc0 = TYPE5_CC0_NDEF_MAGIC; t5_cc.cc1 = TYPE5_VERSION_MAJOR << TYPE5_CC1_VER_MAJOR_SHIFT; @@ -1086,7 +1087,7 @@ static int t5_format_read_multiple_blocks_resp(uint8_t *resp, int length, */ t5_cc.cc1 |= TYPE5_CC1_WRITE_ACCESS_ALWAYS; - mem_size = blk_size * near_tag_get_num_blks(tag); + mem_size = near_tag_get_blk_size(tag) * near_tag_get_num_blks(tag); mem_size = MIN(mem_size, TYPE5_MAX_MEM_SIZE); t5_cc.cc2 = mem_size / 8; @@ -1098,53 +1099,23 @@ static int t5_format_read_multiple_blocks_resp(uint8_t *resp, int length, * just say that its not supported. We also don't know whether * the tag needs a special frame format so just say "no" for that * one too. If it does, we probably can't write to the tag anyway. + * + * In order to know if the tag supports the Read Multiple Blocks + * command, we would have to issue that command here to see if it + * succeeds. If it does succeed, then TYPE5_CC3_MBREAD_FLAG could + * be set; however, if it fails, the adapter code will disconnect + * from the tag and the format will fail making the tag unusable. + * To avoid that possibility, indicate that Read Multiple Blocks + * commands is not supported (i.e., do not set TYPE5_CC3_MBREAD_FLAG). */ t5_cc.cc3 = 0; - /* - * ST Type5 tags does not support multiblock read for blocks - * lying in different sectors. So, doing multi block read - * support setting only for non ST tags. - */ - if (!t5_manufacturer_is_stmicro(tag)) { - if (read_multiple_supported) - t5_cc.cc3 |= TYPE5_CC3_MBREAD_FLAG; - } - err = t5_write(tag, TYPE5_META_START_OFFSET, (uint8_t *)&t5_cc, sizeof(t5_cc), nfctype5_format_resp, cookie); if (err < 0) err = t5_cookie_release(err, cookie); return err; -} - -static int nfctype5_format(uint32_t adapter_idx, uint32_t target_idx, - near_tag_io_cb cb) -{ - struct t5_cookie *cookie; - struct near_tag *tag; - int err; - - DBG(""); - - tag = near_tag_get_tag(adapter_idx, target_idx); - if (!tag) { - err = -EINVAL; - goto out_err; - } - - cookie = t5_cookie_alloc(tag); - if (!cookie) { - err = -ENOMEM; - goto out_err; - } - - cookie->cb = cb; - - return t5_read_multiple_blocks(tag, 0, 2, - t5_format_read_multiple_blocks_resp, - cookie); out_err: if (cb)