From patchwork Thu Jun 15 18:25:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Greer X-Patchwork-Id: 9789805 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 1819060325 for ; Thu, 15 Jun 2017 18:25:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 115C22861E for ; Thu, 15 Jun 2017 18:25:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 066D22862C; Thu, 15 Jun 2017 18:25:55 +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 999CE2861E for ; Thu, 15 Jun 2017 18:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752424AbdFOSZv (ORCPT ); Thu, 15 Jun 2017 14:25:51 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:58573 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751956AbdFOSZc (ORCPT ); Thu, 15 Jun 2017 14:25:32 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id E20D820AAB; 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=VC8 /tuDLMdDIUWatnzGA/7a5bxGgyEILm3C+aXw2K9o=; b=cMmXBnkge7S2KfKnXk3 llC8M4fiYJIezLTHwzlJytmgWSQfu992AIWedlVUnn5ofUzo9hXwSdCqmm1pxmk6 oSNKr1OgrYmhxMT68l3QQSZ28TDKdE84uzwCb6w2jePmPGXOBqTN9NVAh5utFXOz AWmNaoC9rCjW0Lqx/qJQui/M= 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=VC8/tuDLMdDIUWatnzGA/7a5bxGgyEILm3C+aXw2K 9o=; b=lc1oOJM/P9KJM82hzwkB51+tcce1PJ+P+KaFKz2e+KUJPGjiqjvn8fQeH o8ao0lLN70MetebdeEsUcPvDxxO5KYEdaP0BT4ckKxUx9sIWZKpw3vgmX1qh1GWR 4AP1TVnik8EEVMw73YxNdJcZ2+nw4pWIgCH7rCzY52KOjujhkDE9G7ISAhibFwp4 V6MqPB1ILow9aa2LrialWQQPczKal4ZUKNVMhL8q6Io658yhS4/yepTv9vfhGuAb iAknig7NOI1toHZEUU5d85QALbEfbungu0L0UvxiGPh5VOYOh7PenwQuuba5aZj2 9c4w/FYSNBCHIQ4lJZ2iQYgmsjGpw== X-ME-Sender: X-Sasl-enc: GJkZ0U3qZBAFkcs01kMCVXTrjBHToFb0Ue7zboi8IvZT 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 957387E96F; 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 20CACA205F5; 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 16/23] nfctype5: Rework code that identifies ST Micro Type 5 tags Date: Thu, 15 Jun 2017 11:25:09 -0700 Message-Id: <20170615182516.4508-17-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 Rework the code that identifies ST Micro Type 5 tags to make it conform better to established coding style in the file and to make it easier to add check for tags from other manufacturers. Signed-off-by: Mark Greer --- plugins/nfctype5.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/plugins/nfctype5.c b/plugins/nfctype5.c index 9d09bf8..689dec3 100644 --- a/plugins/nfctype5.c +++ b/plugins/nfctype5.c @@ -116,7 +116,7 @@ #define GET_SYS_INFO_FLAG_16B_NB_BLOCK 0x10 #define TYPE5_UID_MANUFAC_IDX 0x06 -#define TYPE5_UID_STMICRO_MANUFAC_ID 0x02 +#define TYPE5_UID_MANUFAC_ID_STMICRO 0x02 struct type5_cmd_hdr { uint8_t flags; @@ -194,6 +194,29 @@ struct t5_cookie { uint8_t nb_requested_blocks; }; +static bool t5_manufacturer_is(struct near_tag *tag, uint8_t manufacturer_id) +{ + uint8_t *uid; + bool match; + + uid = near_tag_get_iso15693_uid(near_tag_get_adapter_idx(tag), + near_tag_get_target_idx(tag)); + if (!uid) { + near_error("No type 5 UID"); + return false; + } + + match = (uid[TYPE5_UID_MANUFAC_IDX] == manufacturer_id); + + g_free(uid); + return match; +} + +static bool t5_manufacturer_is_stmicro(struct near_tag *tag) +{ + return t5_manufacturer_is(tag, TYPE5_UID_MANUFAC_ID_STMICRO); +} + static int t5_cmd_hdr_init(struct near_tag *tag, struct type5_cmd_hdr *cmd_hdr, int cmd) { @@ -392,26 +415,6 @@ static int t5_read(struct near_tag *tag, uint8_t offset, uint8_t *buf, cookie, t5_cookie_release_local); } -static bool t5_manufacturer_stmicro(struct near_tag *tag) -{ - uint8_t *uid; - - uid = near_tag_get_iso15693_uid(near_tag_get_adapter_idx(tag), - near_tag_get_target_idx(tag)); - if (!uid) { - near_error("No type 5 UID"); - return false; - } - - if (uid[TYPE5_UID_MANUFAC_IDX] != TYPE5_UID_STMICRO_MANUFAC_ID) { - g_free(uid); - return false; - } - - g_free(uid); - return true; -} - static int t5_write_resp(uint8_t *resp, int length, void *data) { struct type5_write_single_block_resp *t5_resp = @@ -456,7 +459,7 @@ static int t5_write_resp(uint8_t *resp, int length, void *data) goto out_done; /* CMD_FLAG_OPTION should be set for non ST tags */ - if (!t5_manufacturer_stmicro(tag)) + if (!t5_manufacturer_is_stmicro(tag)) t5_cmd->hdr.flags |= CMD_FLAG_OPTION; t5_cmd->blk_no = cookie->blk; @@ -515,7 +518,7 @@ static int t5_write(struct near_tag *tag, uint8_t offset, uint8_t *buf, * does not work with ST Type5 tags. * So, implemeting OPTION flag set only for non ST tags. */ - if (!t5_manufacturer_stmicro(tag)) + if (!t5_manufacturer_is_stmicro(tag)) t5_cmd->hdr.flags |= CMD_FLAG_OPTION; t5_cmd->blk_no = offset / blk_size; @@ -1046,7 +1049,7 @@ static int t5_format_read_multiple_blocks_resp(uint8_t *resp, int length, * lying in different sectors. So, doing multi block read * support setting only for non ST tags. */ - if (!t5_manufacturer_stmicro(tag)) { + if (!t5_manufacturer_is_stmicro(tag)) { if (read_multiple_supported) t5_cc.cc3 |= TYPE5_CC3_MBREAD_FLAG; }