From 4a50be27de9c142c9944ac77c082aa25afb2bd6a Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 14 Oct 2010 17:32:15 +0000 Subject: [PATCH] Add a iso14443a function to extract Historical Bytes from ATS --- libnfc/iso14443-subr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libnfc/iso14443-subr.c b/libnfc/iso14443-subr.c index 0f64f57..4035da9 100644 --- a/libnfc/iso14443-subr.c +++ b/libnfc/iso14443-subr.c @@ -52,3 +52,26 @@ append_iso14443a_crc (byte_t * pbtData, size_t szLen) { iso14443a_crc (pbtData, szLen, pbtData + szLen); } + +byte_t * +extract_historical_bytes(byte_t * pbtAts, size_t szAts, size_t * pszHB) +{ + if (szAts) { + size_t offset = 1; + if (pbtAts[0] & 0x10) { // TA + offset++; + } + if (pbtAts[0] & 0x20) { // TB + offset++; + } + if (pbtAts[0] & 0x40) { // TC + offset++; + } + if (szAts > offset) { + *pszHB = (szAts-offset); + return (pbtAts+offset); + } + } + *pszHB = 0; + return NULL; +}