[Pcsclite-git-commit] [pcsc-tools] 20/32: pcsc_scan: add a stress() function
Ludovic Rousseau
rousseau at moszumanska.debian.org
Thu May 4 15:44:48 UTC 2017
This is an automated email from the git hooks/post-receive script.
rousseau pushed a commit to branch master
in repository pcsc-tools.
commit de52e7442e9de288a95e5aabc2241e298d85ce77
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date: Sat Apr 8 17:38:16 2017 +0200
pcsc_scan: add a stress() function
---
pcsc_scan.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/pcsc_scan.c b/pcsc_scan.c
index 4f37606..f592778 100644
--- a/pcsc_scan.c
+++ b/pcsc_scan.c
@@ -22,6 +22,7 @@
#include <time.h>
#include <unistd.h>
#include <string.h>
+#include <sys/time.h>
#ifdef __APPLE__
#include <PCSC/wintypes.h>
@@ -97,6 +98,82 @@ static void spin_suspend(void)
fflush(stdout);
}
+static LONG stress(LONG hContext, const char *readerName)
+{
+ LONG rv;
+ SCARDHANDLE hCard;
+ DWORD dwActiveProtocol;
+ const SCARD_IO_REQUEST *pioSendPci;
+
+ printf("Stress card\n\n");
+ rv = SCardConnect(hContext, readerName, SCARD_SHARE_SHARED,
+ SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ print_pcsc_error("SCardConnect", rv);
+ return rv;
+ }
+
+ /* Select Master File */
+ BYTE pbSendBuffer[] = {0, 0xA4, 0, 0, 2, 0x3F, 0};
+ BYTE pbRecvBuffer[256+2];
+ DWORD dwSendLength, dwRecvLength;
+ struct timeval time_start, time_end;
+
+ switch (dwActiveProtocol)
+ {
+ case SCARD_PROTOCOL_T0:
+ pioSendPci = SCARD_PCI_T0;
+ break;
+ case SCARD_PROTOCOL_T1:
+ pioSendPci = SCARD_PCI_T1;
+ break;
+ case SCARD_PROTOCOL_RAW:
+ pioSendPci = SCARD_PCI_RAW;
+ break;
+ default:
+ printf("Unknown protocol\n");
+ return -1;
+ }
+
+ gettimeofday(&time_start, NULL);
+
+#define COUNT 100
+ size_t count;
+ for (count=0; count<COUNT; count++)
+ {
+ printf("\033[FAPDU n°: %ld\n", count);
+ dwSendLength = sizeof(pbSendBuffer);
+ dwRecvLength = sizeof(pbRecvBuffer);
+ rv = SCardTransmit(hCard, pioSendPci, pbSendBuffer, dwSendLength,
+ NULL, pbRecvBuffer, &dwRecvLength);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ print_pcsc_error("SCardDisconnect", rv);
+ break;
+ }
+ }
+
+ gettimeofday(&time_end, NULL);
+ struct timeval r;
+ r.tv_sec = time_end.tv_sec - time_start.tv_sec;
+ r.tv_usec = time_end.tv_usec - time_start.tv_usec;
+ if (r.tv_usec < 0)
+ {
+ r.tv_sec--;
+ r.tv_usec += 1000000;
+ }
+ long delta = r.tv_sec * 1000000 + r.tv_usec;
+ printf("Total time: %ld µs\n", delta);
+ printf("%f APDU/s\n", 1000000. / (delta / count));
+
+ rv = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
+ if (rv != SCARD_S_SUCCESS)
+ print_pcsc_error("SCardDisconnect", rv);
+
+ return rv;
+}
+
int main(int argc, char *argv[])
{
int current_reader;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/pcsc-tools.git
More information about the Pcsclite-cvs-commit
mailing list