From 6a78233be7412dcb0d7810c1522f053ebc6cd942 Mon Sep 17 00:00:00 2001 From: frankmorgner Date: Tue, 31 Aug 2010 10:26:53 +0000 Subject: [PATCH] removed PCSC_TLV_STRUCTURE since its the attributes are not always packed git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@257 96b47cad-a561-4643-ad3b-153ac7d7599c --- ccid/src/ccid-test.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/ccid/src/ccid-test.c b/ccid/src/ccid-test.c index eddb2da..5f380cf 100644 --- a/ccid/src/ccid-test.c +++ b/ccid/src/ccid-test.c @@ -21,7 +21,10 @@ #include #include #include + +#ifdef HAVE_ARPA_INIT_H #include +#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -33,13 +36,6 @@ #ifdef HAVE_READER_H #include -#else -typedef struct -{ - uint8_t tag; - uint8_t length; - uint32_t value; -} PCSC_TLV_STRUCTURE; #endif @@ -51,6 +47,8 @@ typedef struct #define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400) #endif +#define PCSC_TLV_ELEMENT_SIZE 6 + static void printb(const char *label, unsigned char *buf, size_t len) @@ -69,7 +67,7 @@ printb(const char *label, unsigned char *buf, size_t len) } static LONG parse_EstablishPACEChannel_OutputData( - unsigned char output[], unsigned int output_length) + unsigned char output[], unsigned int output_length) { uint8_t lengthCAR, lengthCARprev; uint16_t lengthEF_CardAccess, length_IDicc; @@ -187,7 +185,6 @@ main(int argc, char *argv[]) }; BYTE pbRecvBuffer[1024]; DWORD dwActiveProtocol, dwRecvLength, dwReaders, i; - PCSC_TLV_STRUCTURE *pcsc_tlv; uint16_t lengthInputData = sizeof(pbSendBufferEstablish) - 3; memcpy(pbSendBufferEstablish + 1, &lengthInputData, 2); @@ -245,14 +242,11 @@ main(int argc, char *argv[]) fprintf(stderr, "Could not get the reader's features\n"); goto err; } + printb("reader's features\n", pbRecvBuffer, dwRecvLength); - /* get the number of elements instead of the complete size */ - dwRecvLength /= sizeof(PCSC_TLV_STRUCTURE); - - pcsc_tlv = (PCSC_TLV_STRUCTURE *)pbRecvBuffer; - for (i = 0; i < dwRecvLength; i++) { - if (pcsc_tlv[i].tag == FEATURE_EXECUTE_PACE) { - pace_ioctl = pcsc_tlv[i].value; + for (i = 0; i <= dwRecvLength-PCSC_TLV_ELEMENT_SIZE; i += PCSC_TLV_ELEMENT_SIZE) { + if (pbRecvBuffer[i] == FEATURE_EXECUTE_PACE) { + memcpy(&pace_ioctl, pbRecvBuffer+i+2, 4); break; } } @@ -284,6 +278,7 @@ main(int argc, char *argv[]) } printf("EstablishPACEChannel successfull, received %d bytes\n", dwRecvLength); + printb("EstablishPACEChannel\n", pbRecvBuffer, dwRecvLength); rv = parse_EstablishPACEChannel_OutputData(pbRecvBuffer, dwRecvLength); if (rv != SCARD_S_SUCCESS)