<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>pcsc-lite: testpcsc.c Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2-20100208 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_c68a5dfdca54003c765e303a18006edb.html">src</a> </div> </div> <div class="contents"> <h1>testpcsc.c</h1><a href="testpcsc_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * MUSCLE SmartCard Development ( http://www.linuxnet.com )</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 1999</span> <a name="l00005"></a>00005 <span class="comment"> * David Corcoran <corcoran@linuxnet.com></span> <a name="l00006"></a>00006 <span class="comment"> * Copyright (C) 2004-2008</span> <a name="l00007"></a>00007 <span class="comment"> * Ludovic Rousseau <ludovic.rousseau@free.fr></span> <a name="l00008"></a>00008 <span class="comment"> *</span> <a name="l00009"></a>00009 <span class="comment"> * $Id: testpcsc.c 4328 2009-07-20 12:11:18Z rousseau $</span> <a name="l00010"></a>00010 <span class="comment"> */</span> <a name="l00011"></a>00011 <a name="l00017"></a>00017 <span class="preprocessor">#include "config.h"</span> <a name="l00018"></a>00018 <span class="preprocessor">#include <stdio.h></span> <a name="l00019"></a>00019 <span class="preprocessor">#include <stdlib.h></span> <a name="l00020"></a>00020 <span class="preprocessor">#include <string.h></span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="pcsclite_8h.html" title="This keeps a list of defines for pcsc-lite.">pcsclite.h</a>"</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="winscard_8h.html" title="This handles smartcard reader communications.">winscard.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="reader_8h.html" title="This keeps a list of defines shared between the driver and the application.">reader.h</a>"</span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="preprocessor">#define PANIC 0</span> <a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define DONT_PANIC 1</span> <a name="l00028"></a>00028 <span class="preprocessor"></span> <a name="l00029"></a>00029 <span class="preprocessor">#define USE_AUTOALLOCATE</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#define BLUE "\33[34m"</span> <a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define RED "\33[31m"</span> <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define BRIGHT_RED "\33[01;31m"</span> <a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#define GREEN "\33[32m"</span> <a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define NORMAL "\33[0m"</span> <a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define MAGENTA "\33[35m"</span> <a name="l00037"></a>00037 <span class="preprocessor"></span> <a name="l00038"></a>00038 <span class="keyword">static</span> <span class="keywordtype">void</span> test_rv(LONG rv, <a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, <span class="keywordtype">int</span> dont_panic) <a name="l00039"></a>00039 { <a name="l00040"></a>00040 <span class="keywordflow">if</span> (rv != <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00041"></a>00041 { <a name="l00042"></a>00042 <span class="keywordflow">if</span> (dont_panic) <a name="l00043"></a>00043 printf(BLUE <span class="stringliteral">"%s (don't panic)\n"</span> NORMAL, <a class="code" href="group__API.html#ga132e20ab457d042a06f7df733f15b22d" title="This function return a human readable text for the given PC/SC error code.">pcsc_stringify_error</a>(rv)); <a name="l00044"></a>00044 <span class="keywordflow">else</span> <a name="l00045"></a>00045 { <a name="l00046"></a>00046 printf(RED <span class="stringliteral">"%s\n"</span> NORMAL, <a class="code" href="group__API.html#ga132e20ab457d042a06f7df733f15b22d" title="This function return a human readable text for the given PC/SC error code.">pcsc_stringify_error</a>(rv)); <a name="l00047"></a>00047 (void)<a class="code" href="group__API.html#ga6aabcba7744c5c9419fdd6404f73a934" title="This function destroys a communication context to the PC/SC Resource Manager.">SCardReleaseContext</a>(hContext); <a name="l00048"></a>00048 exit(-1); <a name="l00049"></a>00049 } <a name="l00050"></a>00050 } <a name="l00051"></a>00051 <span class="keywordflow">else</span> <a name="l00052"></a>00052 (<span class="keywordtype">void</span>)puts(<a class="code" href="group__API.html#ga132e20ab457d042a06f7df733f15b22d" title="This function return a human readable text for the given PC/SC error code.">pcsc_stringify_error</a>(rv)); <a name="l00053"></a>00053 } <a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="keywordtype">int</span> main(<span class="comment">/*@unused@*/</span> <span class="keywordtype">int</span> argc, <span class="comment">/*@unused@*/</span> <span class="keywordtype">char</span> **argv) <a name="l00056"></a>00056 { <a name="l00057"></a>00057 <a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard; <a name="l00058"></a>00058 <a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext; <a name="l00059"></a>00059 <a class="code" href="structSCARD__READERSTATE__A.html">SCARD_READERSTATE_A</a> rgReaderStates[1]; <a name="l00060"></a>00060 DWORD dwReaderLen, dwState, dwProt, dwAtrLen; <a name="l00061"></a>00061 DWORD dwPref, dwReaders = 0; <a name="l00062"></a>00062 <span class="keywordtype">char</span> *pcReaders = NULL, *mszReaders; <a name="l00063"></a>00063 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00064"></a>00064 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pbAtr = NULL; <a name="l00065"></a>00065 <span class="preprocessor">#else</span> <a name="l00066"></a>00066 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> pbAtr[<a class="code" href="pcsclite_8h.html#a7ac7915ff6f9baefa66886c98bdbb91e" title="Maximum ATR size.">MAX_ATR_SIZE</a>]; <a name="l00067"></a>00067 <span class="preprocessor">#endif</span> <a name="l00068"></a>00068 <span class="preprocessor"></span> <span class="keyword">union </span>{ <a name="l00069"></a>00069 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> as_char[100]; <a name="l00070"></a>00070 DWORD as_DWORD; <a name="l00071"></a>00071 uint32_t as_uint32_t; <a name="l00072"></a>00072 } buf; <a name="l00073"></a>00073 DWORD dwBufLen; <a name="l00074"></a>00074 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pbAttr = NULL; <a name="l00075"></a>00075 DWORD pcbAttrLen; <a name="l00076"></a>00076 <span class="keywordtype">char</span> *mszGroups; <a name="l00077"></a>00077 DWORD dwGroups = 0; <a name="l00078"></a>00078 <span class="keywordtype">long</span> rv; <a name="l00079"></a>00079 DWORD i; <a name="l00080"></a>00080 <span class="keywordtype">int</span> p, iReader; <a name="l00081"></a>00081 <span class="keywordtype">int</span> iList[16]; <a name="l00082"></a>00082 <a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">SCARD_IO_REQUEST</a> pioRecvPci; <a name="l00083"></a>00083 <a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">SCARD_IO_REQUEST</a> pioSendPci; <a name="l00084"></a>00084 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> bSendBuffer[<a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>]; <a name="l00085"></a>00085 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> bRecvBuffer[<a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>]; <a name="l00086"></a>00086 DWORD send_length, length; <a name="l00087"></a>00087 <a name="l00088"></a>00088 (void)argc; <a name="l00089"></a>00089 (void)argv; <a name="l00090"></a>00090 <a name="l00091"></a>00091 printf(<span class="stringliteral">"\nMUSCLE PC/SC Lite unitary test Program\n\n"</span>); <a name="l00092"></a>00092 <a name="l00093"></a>00093 printf(MAGENTA <span class="stringliteral">"THIS PROGRAM IS NOT DESIGNED AS A TESTING TOOL FOR END USERS!\n"</span>); <a name="l00094"></a>00094 printf(<span class="stringliteral">"Do NOT use it unless you really know what you do.\n\n"</span> NORMAL); <a name="l00095"></a>00095 <a name="l00096"></a>00096 printf(<span class="stringliteral">"Testing SCardEstablishContext\t: "</span>); <a name="l00097"></a>00097 rv = <a class="code" href="group__API.html#gaa1b8970169fd4883a6dc4a8f43f19b67" title="Creates an Application Context for a client.">SCardEstablishContext</a>(<a class="code" href="pcsclite_8h.html#a01ffeed2d7fac470371c79fa86b1e309" title="Scope in system.">SCARD_SCOPE_SYSTEM</a>, NULL, NULL, &hContext); <a name="l00098"></a>00098 test_rv(rv, hContext, PANIC); <a name="l00099"></a>00099 <a name="l00100"></a>00100 printf(<span class="stringliteral">"Testing SCardIsValidContext\t: "</span>); <a name="l00101"></a>00101 rv = <a class="code" href="group__API.html#ga722eb66bcc44d391f700ff9065cc080b" title="Check if a SCARDCONTEXT is valid.">SCardIsValidContext</a>(hContext); <a name="l00102"></a>00102 test_rv(rv, hContext, PANIC); <a name="l00103"></a>00103 <a name="l00104"></a>00104 printf(<span class="stringliteral">"Testing SCardIsValidContext\t: "</span>); <a name="l00105"></a>00105 rv = <a class="code" href="group__API.html#ga722eb66bcc44d391f700ff9065cc080b" title="Check if a SCARDCONTEXT is valid.">SCardIsValidContext</a>(hContext+1); <a name="l00106"></a>00106 test_rv(rv, hContext, DONT_PANIC); <a name="l00107"></a>00107 <a name="l00108"></a>00108 printf(<span class="stringliteral">"Testing SCardListReaderGroups\t: "</span>); <a name="l00109"></a>00109 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00110"></a>00110 <span class="preprocessor"></span> dwGroups = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>; <a name="l00111"></a>00111 rv = <a class="code" href="group__API.html#ga9d970d086d5218e080d0079d63f9d496" title="This function returns a list of currently available reader groups on the system.">SCardListReaderGroups</a>(hContext, (LPSTR)&mszGroups, &dwGroups); <a name="l00112"></a>00112 <span class="preprocessor">#else</span> <a name="l00113"></a>00113 <span class="preprocessor"></span> rv = <a class="code" href="group__API.html#ga9d970d086d5218e080d0079d63f9d496" title="This function returns a list of currently available reader groups on the system.">SCardListReaderGroups</a>(hContext, NULL, &dwGroups); <a name="l00114"></a>00114 test_rv(rv, hContext, PANIC); <a name="l00115"></a>00115 <a name="l00116"></a>00116 printf(<span class="stringliteral">"Testing SCardListReaderGroups\t: "</span>); <a name="l00117"></a>00117 mszGroups = calloc(dwGroups, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>)); <a name="l00118"></a>00118 rv = <a class="code" href="group__API.html#ga9d970d086d5218e080d0079d63f9d496" title="This function returns a list of currently available reader groups on the system.">SCardListReaderGroups</a>(hContext, mszGroups, &dwGroups); <a name="l00119"></a>00119 <span class="preprocessor">#endif</span> <a name="l00120"></a>00120 <span class="preprocessor"></span> test_rv(rv, hContext, PANIC); <a name="l00121"></a>00121 <a name="l00122"></a>00122 <span class="comment">/*</span> <a name="l00123"></a>00123 <span class="comment"> * Have to understand the multi-string here</span> <a name="l00124"></a>00124 <span class="comment"> */</span> <a name="l00125"></a>00125 p = 0; <a name="l00126"></a>00126 <span class="keywordflow">for</span> (i = 0; i+1 < dwGroups; i++) <a name="l00127"></a>00127 { <a name="l00128"></a>00128 ++p; <a name="l00129"></a>00129 printf(GREEN <span class="stringliteral">"Group %02d: %s\n"</span> NORMAL, p, &mszGroups[i]); <a name="l00130"></a>00130 <span class="keywordflow">while</span> (mszGroups[++i] != 0) ; <a name="l00131"></a>00131 } <a name="l00132"></a>00132 <a name="l00133"></a>00133 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00134"></a>00134 <span class="preprocessor"></span> printf(<span class="stringliteral">"Testing SCardFreeMemory\t\t: "</span>); <a name="l00135"></a>00135 rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE...">SCardFreeMemory</a>(hContext, mszGroups); <a name="l00136"></a>00136 test_rv(rv, hContext, PANIC); <a name="l00137"></a>00137 <span class="preprocessor">#else</span> <a name="l00138"></a>00138 <span class="preprocessor"></span> free(mszGroups); <a name="l00139"></a>00139 <span class="preprocessor">#endif</span> <a name="l00140"></a>00140 <span class="preprocessor"></span> <a name="l00141"></a>00141 wait_for_card_again: <a name="l00142"></a>00142 mszGroups = NULL; <a name="l00143"></a>00143 printf(<span class="stringliteral">"Testing SCardListReaders\t: "</span>); <a name="l00144"></a>00144 rv = <a class="code" href="group__API.html#ga93b07815789b3cf2629d439ecf20f0d9" title="This function returns a list of currently available readers on the system.">SCardListReaders</a>(hContext, mszGroups, NULL, &dwReaders); <a name="l00145"></a>00145 test_rv(rv, hContext, DONT_PANIC); <a name="l00146"></a>00146 <span class="keywordflow">if</span> (<a class="code" href="pcsclite_8h.html#a81b59e9319d3fcd0d957d98781b3ebd2" title="Cannot find a smart card reader.">SCARD_E_NO_READERS_AVAILABLE</a> == rv) <a name="l00147"></a>00147 { <a name="l00148"></a>00148 printf(<span class="stringliteral">"Testing SCardGetStatusChange \n"</span>); <a name="l00149"></a>00149 printf(<span class="stringliteral">"Please insert a working reader\t: "</span>); <a name="l00150"></a>00150 (void)fflush(stdout); <a name="l00151"></a>00151 rgReaderStates[0].szReader = <span class="stringliteral">"\\\\?PnP?\\Notification"</span>; <a name="l00152"></a>00152 rgReaderStates[0].dwCurrentState = <a class="code" href="pcsclite_8h.html#aadf7badda42d372c2bc56d95a7720535" title="Card removed.">SCARD_STATE_EMPTY</a>; <a name="l00153"></a>00153 <a name="l00154"></a>00154 rv = <a class="code" href="group__API.html#gad1db67ba2b7d143498257294b873c049" title="This function receives a structure or list of structures containing reader names...">SCardGetStatusChange</a>(hContext, INFINITE, rgReaderStates, 1); <a name="l00155"></a>00155 test_rv(rv, hContext, PANIC); <a name="l00156"></a>00156 } <a name="l00157"></a>00157 <a name="l00158"></a>00158 printf(<span class="stringliteral">"Testing SCardListReaders\t: "</span>); <a name="l00159"></a>00159 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00160"></a>00160 <span class="preprocessor"></span> dwReaders = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>; <a name="l00161"></a>00161 rv = <a class="code" href="group__API.html#ga93b07815789b3cf2629d439ecf20f0d9" title="This function returns a list of currently available readers on the system.">SCardListReaders</a>(hContext, mszGroups, (LPSTR)&mszReaders, &dwReaders); <a name="l00162"></a>00162 <span class="preprocessor">#else</span> <a name="l00163"></a>00163 <span class="preprocessor"></span> rv = <a class="code" href="group__API.html#ga93b07815789b3cf2629d439ecf20f0d9" title="This function returns a list of currently available readers on the system.">SCardListReaders</a>(hContext, mszGroups, NULL, &dwReaders); <a name="l00164"></a>00164 test_rv(rv, hContext, PANIC); <a name="l00165"></a>00165 <a name="l00166"></a>00166 printf(<span class="stringliteral">"Testing SCardListReaders\t: "</span>); <a name="l00167"></a>00167 mszReaders = calloc(dwReaders, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>)); <a name="l00168"></a>00168 rv = <a class="code" href="group__API.html#ga93b07815789b3cf2629d439ecf20f0d9" title="This function returns a list of currently available readers on the system.">SCardListReaders</a>(hContext, mszGroups, mszReaders, &dwReaders); <a name="l00169"></a>00169 <span class="preprocessor">#endif</span> <a name="l00170"></a>00170 <span class="preprocessor"></span> test_rv(rv, hContext, DONT_PANIC); <a name="l00171"></a>00171 <a name="l00172"></a>00172 <span class="comment">/*</span> <a name="l00173"></a>00173 <span class="comment"> * Have to understand the multi-string here</span> <a name="l00174"></a>00174 <span class="comment"> */</span> <a name="l00175"></a>00175 p = 0; <a name="l00176"></a>00176 <span class="keywordflow">for</span> (i = 0; i+1 < dwReaders; i++) <a name="l00177"></a>00177 { <a name="l00178"></a>00178 ++p; <a name="l00179"></a>00179 printf(GREEN <span class="stringliteral">"Reader %02d: %s\n"</span> NORMAL, p, &mszReaders[i]); <a name="l00180"></a>00180 iList[p] = i; <a name="l00181"></a>00181 <span class="keywordflow">while</span> (mszReaders[++i] != 0) ; <a name="l00182"></a>00182 } <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="keywordflow">if</span> (p > 1) <a name="l00185"></a>00185 <span class="keywordflow">do</span> <a name="l00186"></a>00186 { <a name="l00187"></a>00187 <span class="keywordtype">char</span> input[80]; <a name="l00188"></a>00188 <a name="l00189"></a>00189 printf(<span class="stringliteral">"Enter the reader number\t\t: "</span>); <a name="l00190"></a>00190 (void)fgets(input, <span class="keyword">sizeof</span>(input), stdin); <a name="l00191"></a>00191 (void)sscanf(input, <span class="stringliteral">"%d"</span>, &iReader); <a name="l00192"></a>00192 <a name="l00193"></a>00193 <span class="keywordflow">if</span> (iReader > p || iReader <= 0) <a name="l00194"></a>00194 printf(<span class="stringliteral">"Invalid Value - try again\n"</span>); <a name="l00195"></a>00195 } <a name="l00196"></a>00196 <span class="keywordflow">while</span> (iReader > p || iReader <= 0); <a name="l00197"></a>00197 <span class="keywordflow">else</span> <a name="l00198"></a>00198 iReader = 1; <a name="l00199"></a>00199 <a name="l00200"></a>00200 rgReaderStates[0].szReader = &mszReaders[iList[iReader]]; <a name="l00201"></a>00201 rgReaderStates[0].dwCurrentState = <a class="code" href="pcsclite_8h.html#aadf7badda42d372c2bc56d95a7720535" title="Card removed.">SCARD_STATE_EMPTY</a>; <a name="l00202"></a>00202 <a name="l00203"></a>00203 printf(<span class="stringliteral">"Waiting for card insertion\t: "</span>); <a name="l00204"></a>00204 (void)fflush(stdout); <a name="l00205"></a>00205 rv = <a class="code" href="group__API.html#gad1db67ba2b7d143498257294b873c049" title="This function receives a structure or list of structures containing reader names...">SCardGetStatusChange</a>(hContext, INFINITE, rgReaderStates, 1); <a name="l00206"></a>00206 test_rv(rv, hContext, PANIC); <a name="l00207"></a>00207 <span class="keywordflow">if</span> (rgReaderStates[0].dwEventState & <a class="code" href="pcsclite_8h.html#a96ab0fac1bb56525c5f216428e7dd8e7" title="Reader unknown.">SCARD_STATE_UNKNOWN</a>) <a name="l00208"></a>00208 { <a name="l00209"></a>00209 printf(<span class="stringliteral">"\nA reader has been connected/disconnected\n"</span>); <a name="l00210"></a>00210 <span class="keywordflow">goto</span> wait_for_card_again; <a name="l00211"></a>00211 } <a name="l00212"></a>00212 <a name="l00213"></a>00213 printf(<span class="stringliteral">"Testing SCardConnect\t\t: "</span>); <a name="l00214"></a>00214 rv = <a class="code" href="group__API.html#ga4e515829752e0a8dbc4d630696a8d6a5" title="This function establishes a connection to the reader specified in szReader.">SCardConnect</a>(hContext, &mszReaders[iList[iReader]], <a name="l00215"></a>00215 <a class="code" href="pcsclite_8h.html#a724a33782fe519553f1e05ee77940f6f" title="Shared mode only.">SCARD_SHARE_SHARED</a>, <a class="code" href="pcsclite_8h.html#a4fe95267c322c3bf35f30fab6b25526c" title="T=0 active protocol.">SCARD_PROTOCOL_T0</a> | <a class="code" href="pcsclite_8h.html#a3c09cd155e07044f857130c183d64f03" title="T=1 active protocol.">SCARD_PROTOCOL_T1</a>, <a name="l00216"></a>00216 &hCard, &dwPref); <a name="l00217"></a>00217 test_rv(rv, hContext, PANIC); <a name="l00218"></a>00218 <a name="l00219"></a>00219 <span class="keywordflow">switch</span>(dwPref) <a name="l00220"></a>00220 { <a name="l00221"></a>00221 <span class="keywordflow">case</span> <a class="code" href="pcsclite_8h.html#a4fe95267c322c3bf35f30fab6b25526c" title="T=0 active protocol.">SCARD_PROTOCOL_T0</a>: <a name="l00222"></a>00222 pioSendPci = *<a class="code" href="pcsclite_8h.html#afe9c9747a9359719e1094e2754580a9a" title="protocol control information (PCI) for T=0">SCARD_PCI_T0</a>; <a name="l00223"></a>00223 <span class="keywordflow">break</span>; <a name="l00224"></a>00224 <span class="keywordflow">case</span> <a class="code" href="pcsclite_8h.html#a3c09cd155e07044f857130c183d64f03" title="T=1 active protocol.">SCARD_PROTOCOL_T1</a>: <a name="l00225"></a>00225 pioSendPci = *<a class="code" href="pcsclite_8h.html#ae07c084592ce8e0ae24384d93bd026e7" title="protocol control information (PCI) for T=1">SCARD_PCI_T1</a>; <a name="l00226"></a>00226 <span class="keywordflow">break</span>; <a name="l00227"></a>00227 <span class="keywordflow">case</span> <a class="code" href="pcsclite_8h.html#ab58a85ece18f4217fe5372981231d195" title="Raw active protocol.">SCARD_PROTOCOL_RAW</a>: <a name="l00228"></a>00228 pioSendPci = *<a class="code" href="pcsclite_8h.html#a884ba9fa57faa3e2537b4dafc9fe8b11" title="protocol control information (PCI) for RAW protocol">SCARD_PCI_RAW</a>; <a name="l00229"></a>00229 <span class="keywordflow">break</span>; <a name="l00230"></a>00230 <span class="keywordflow">default</span>: <a name="l00231"></a>00231 printf(<span class="stringliteral">"Unknown protocol\n"</span>); <a name="l00232"></a>00232 <span class="keywordflow">return</span> -1; <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a name="l00235"></a>00235 <span class="comment">/* APDU select file */</span> <a name="l00236"></a>00236 printf(<span class="stringliteral">"Select file:"</span>); <a name="l00237"></a>00237 send_length = 7; <a name="l00238"></a>00238 memcpy(bSendBuffer, <span class="stringliteral">"\x00\xA4\x00\x00\x02\x3F\x00"</span>, send_length); <a name="l00239"></a>00239 <span class="keywordflow">for</span> (i=0; i<send_length; i++) <a name="l00240"></a>00240 printf(<span class="stringliteral">" %02X"</span>, bSendBuffer[i]); <a name="l00241"></a>00241 printf(<span class="stringliteral">"\n"</span>); <a name="l00242"></a>00242 length = <span class="keyword">sizeof</span>(bRecvBuffer); <a name="l00243"></a>00243 <a name="l00244"></a>00244 printf(<span class="stringliteral">"Testing SCardTransmit\t\t: "</span>); <a name="l00245"></a>00245 rv = <a class="code" href="group__API.html#gac60e9e6c93b04e61594a3a8f69ee1898" title="This function sends an APDU to the smart card contained in the reader connected to...">SCardTransmit</a>(hCard, &pioSendPci, bSendBuffer, send_length, <a name="l00246"></a>00246 &pioRecvPci, bRecvBuffer, &length); <a name="l00247"></a>00247 test_rv(rv, hContext, PANIC); <a name="l00248"></a>00248 printf(<span class="stringliteral">" card response:"</span> GREEN); <a name="l00249"></a>00249 <span class="keywordflow">for</span> (i=0; i<length; i++) <a name="l00250"></a>00250 printf(<span class="stringliteral">" %02X"</span>, bRecvBuffer[i]); <a name="l00251"></a>00251 printf(<span class="stringliteral">"\n"</span> NORMAL); <a name="l00252"></a>00252 <a name="l00253"></a>00253 printf(<span class="stringliteral">"Testing SCardControl\t\t: "</span>); <a name="l00254"></a>00254 <span class="preprocessor">#ifdef PCSC_PRE_120</span> <a name="l00255"></a>00255 <span class="preprocessor"></span> { <a name="l00256"></a>00256 <span class="keywordtype">char</span> buffer[1024] = <span class="stringliteral">"Foobar"</span>; <a name="l00257"></a>00257 DWORD cbRecvLength = <span class="keyword">sizeof</span>(buffer); <a name="l00258"></a>00258 <a name="l00259"></a>00259 rv = <a class="code" href="group__API.html#gac3454d4657110fd7f753b2d3d8f4e32f" title="This function sends a command directly to the IFD Handler (reader driver) to be processed...">SCardControl</a>(hCard, buffer, 7, buffer, &cbRecvLength); <a name="l00260"></a>00260 } <a name="l00261"></a>00261 <span class="preprocessor">#else</span> <a name="l00262"></a>00262 <span class="preprocessor"></span> { <a name="l00263"></a>00263 <span class="keywordtype">char</span> buffer[1024] = { 0x02 }; <a name="l00264"></a>00264 DWORD cbRecvLength = <span class="keyword">sizeof</span>(buffer); <a name="l00265"></a>00265 <a name="l00266"></a>00266 rv = <a class="code" href="group__API.html#gac3454d4657110fd7f753b2d3d8f4e32f" title="This function sends a command directly to the IFD Handler (reader driver) to be processed...">SCardControl</a>(hCard, <a class="code" href="reader_8h.html#a77839183c3ae7b0cea39fbaff9f9aabb" title="Provide source compatibility on different platforms.">SCARD_CTL_CODE</a>(1), buffer, 1, buffer, <a name="l00267"></a>00267 <span class="keyword">sizeof</span>(buffer), &cbRecvLength); <a name="l00268"></a>00268 <span class="keywordflow">if</span> (cbRecvLength && (<a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a> == rv)) <a name="l00269"></a>00269 { <a name="l00270"></a>00270 <span class="keywordflow">for</span> (i=0; i<cbRecvLength; i++) <a name="l00271"></a>00271 printf(<span class="stringliteral">"%c"</span>, buffer[i]); <a name="l00272"></a>00272 printf(<span class="stringliteral">" "</span>); <a name="l00273"></a>00273 } <a name="l00274"></a>00274 } <a name="l00275"></a>00275 <span class="preprocessor">#endif</span> <a name="l00276"></a>00276 <span class="preprocessor"></span> test_rv(rv, hContext, DONT_PANIC); <a name="l00277"></a>00277 <a name="l00278"></a>00278 printf(<span class="stringliteral">"Testing SCardGetAttrib\t\t: "</span>); <a name="l00279"></a>00279 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00280"></a>00280 <span class="preprocessor"></span> pcbAttrLen = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>; <a name="l00281"></a>00281 rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="This function get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#ae450bada1fa917057610dd0446983784" title="Answer to reset (ATR) string.">SCARD_ATTR_ATR_STRING</a>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)&pbAttr, <a name="l00282"></a>00282 &pcbAttrLen); <a name="l00283"></a>00283 <span class="preprocessor">#else</span> <a name="l00284"></a>00284 <span class="preprocessor"></span> rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="This function get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#ae450bada1fa917057610dd0446983784" title="Answer to reset (ATR) string.">SCARD_ATTR_ATR_STRING</a>, NULL, &pcbAttrLen); <a name="l00285"></a>00285 test_rv(rv, hContext, DONT_PANIC); <a name="l00286"></a>00286 <span class="keywordflow">if</span> (rv == <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00287"></a>00287 { <a name="l00288"></a>00288 printf(<span class="stringliteral">"SCARD_ATTR_ATR_STRING length: "</span> GREEN <span class="stringliteral">"%ld\n"</span> NORMAL, pcbAttrLen); <a name="l00289"></a>00289 pbAttr = malloc(pcbAttrLen); <a name="l00290"></a>00290 } <a name="l00291"></a>00291 <a name="l00292"></a>00292 printf(<span class="stringliteral">"Testing SCardGetAttrib\t\t: "</span>); <a name="l00293"></a>00293 rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="This function get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#ae450bada1fa917057610dd0446983784" title="Answer to reset (ATR) string.">SCARD_ATTR_ATR_STRING</a>, pbAttr, &pcbAttrLen); <a name="l00294"></a>00294 <span class="preprocessor">#endif</span> <a name="l00295"></a>00295 <span class="preprocessor"></span> test_rv(rv, hContext, DONT_PANIC); <a name="l00296"></a>00296 <span class="keywordflow">if</span> (rv == <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00297"></a>00297 { <a name="l00298"></a>00298 printf(<span class="stringliteral">"SCARD_ATTR_ATR_STRING length: "</span> GREEN <span class="stringliteral">"%ld\n"</span> NORMAL, pcbAttrLen); <a name="l00299"></a>00299 printf(<span class="stringliteral">"SCARD_ATTR_ATR_STRING: "</span> GREEN); <a name="l00300"></a>00300 <span class="keywordflow">for</span> (i = 0; i < pcbAttrLen; i++) <a name="l00301"></a>00301 printf(<span class="stringliteral">"%02X "</span>, pbAttr[i]); <a name="l00302"></a>00302 printf(<span class="stringliteral">"\n"</span> NORMAL); <a name="l00303"></a>00303 } <a name="l00304"></a>00304 <a name="l00305"></a>00305 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00306"></a>00306 <span class="preprocessor"></span> printf(<span class="stringliteral">"Testing SCardFreeMemory\t\t: "</span>); <a name="l00307"></a>00307 rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE...">SCardFreeMemory</a>(hContext, pbAttr); <a name="l00308"></a>00308 test_rv(rv, hContext, PANIC); <a name="l00309"></a>00309 <span class="preprocessor">#else</span> <a name="l00310"></a>00310 <span class="preprocessor"></span> <span class="keywordflow">if</span> (pbAttr) <a name="l00311"></a>00311 free(pbAttr); <a name="l00312"></a>00312 <span class="preprocessor">#endif</span> <a name="l00313"></a>00313 <span class="preprocessor"></span> <a name="l00314"></a>00314 printf(<span class="stringliteral">"Testing SCardGetAttrib\t\t: "</span>); <a name="l00315"></a>00315 dwBufLen = <span class="keyword">sizeof</span>(buf); <a name="l00316"></a>00316 rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="This function get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#a21105eef90f69895754548688e4b0721" title="Vendor-supplied interface device version (DWORD in the form 0xMMmmbbbb where MM =...">SCARD_ATTR_VENDOR_IFD_VERSION</a>, buf.as_char, &dwBufLen); <a name="l00317"></a>00317 test_rv(rv, hContext, DONT_PANIC); <a name="l00318"></a>00318 <span class="keywordflow">if</span> (rv == <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00319"></a>00319 printf(<span class="stringliteral">"Vendor IFD version\t\t: "</span> GREEN <span class="stringliteral">"0x%08lX\n"</span> NORMAL, <a name="l00320"></a>00320 buf.as_DWORD); <a name="l00321"></a>00321 <a name="l00322"></a>00322 printf(<span class="stringliteral">"Testing SCardGetAttrib\t\t: "</span>); <a name="l00323"></a>00323 dwBufLen = <span class="keyword">sizeof</span>(buf); <a name="l00324"></a>00324 rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="This function get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#a42ea634deb1ec51e10722b661aa73d01" title="FIXME.">SCARD_ATTR_MAXINPUT</a>, buf.as_char, &dwBufLen); <a name="l00325"></a>00325 test_rv(rv, hContext, DONT_PANIC); <a name="l00326"></a>00326 <span class="keywordflow">if</span> (rv == <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00327"></a>00327 { <a name="l00328"></a>00328 <span class="keywordflow">if</span> (dwBufLen == <span class="keyword">sizeof</span>(uint32_t)) <a name="l00329"></a>00329 printf(<span class="stringliteral">"Max message length\t\t: "</span> GREEN <span class="stringliteral">"%d\n"</span> NORMAL, <a name="l00330"></a>00330 buf.as_uint32_t); <a name="l00331"></a>00331 <span class="keywordflow">else</span> <a name="l00332"></a>00332 printf(RED <span class="stringliteral">"Wrong size"</span> NORMAL); <a name="l00333"></a>00333 } <a name="l00334"></a>00334 <a name="l00335"></a>00335 printf(<span class="stringliteral">"Testing SCardGetAttrib\t\t: "</span>); <a name="l00336"></a>00336 dwBufLen = <span class="keyword">sizeof</span>(buf); <a name="l00337"></a>00337 rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="This function get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#a8c0b0539cf006d7bfef49db7136cda95" title="Vendor name.">SCARD_ATTR_VENDOR_NAME</a>, buf.as_char, &dwBufLen); <a name="l00338"></a>00338 test_rv(rv, hContext, DONT_PANIC); <a name="l00339"></a>00339 <span class="keywordflow">if</span> (rv == <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00340"></a>00340 printf(<span class="stringliteral">"Vendor name\t\t\t: "</span> GREEN <span class="stringliteral">"%s\n"</span> NORMAL, buf.as_char); <a name="l00341"></a>00341 <a name="l00342"></a>00342 printf(<span class="stringliteral">"Testing SCardSetAttrib\t\t: "</span>); <a name="l00343"></a>00343 rv = <a class="code" href="group__API.html#ga060f0038a4ddfd5dd2b8fadf3c3a2e4f" title="This function set an attribute of the IFD Handler.">SCardSetAttrib</a>(hCard, <a class="code" href="reader_8h.html#ae450bada1fa917057610dd0446983784" title="Answer to reset (ATR) string.">SCARD_ATTR_ATR_STRING</a>, (LPCBYTE)<span class="stringliteral">""</span>, 1); <a name="l00344"></a>00344 test_rv(rv, hContext, DONT_PANIC); <a name="l00345"></a>00345 <a name="l00346"></a>00346 printf(<span class="stringliteral">"Testing SCardStatus\t\t: "</span>); <a name="l00347"></a>00347 <a name="l00348"></a>00348 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00349"></a>00349 <span class="preprocessor"></span> dwReaderLen = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>; <a name="l00350"></a>00350 dwAtrLen = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>; <a name="l00351"></a>00351 rv = <a class="code" href="group__API.html#ga18f33eebb45d9e0d2a091ca7a0511d26" title="This function returns the current status of the reader connected to by hCard.">SCardStatus</a>(hCard, (LPSTR)&pcReaders, &dwReaderLen, &dwState, &dwProt, <a name="l00352"></a>00352 (LPBYTE)&pbAtr, &dwAtrLen); <a name="l00353"></a>00353 <span class="preprocessor">#else</span> <a name="l00354"></a>00354 <span class="preprocessor"></span> dwReaderLen = 100; <a name="l00355"></a>00355 pcReaders = malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) * 100); <a name="l00356"></a>00356 dwAtrLen = <a class="code" href="pcsclite_8h.html#a7ac7915ff6f9baefa66886c98bdbb91e" title="Maximum ATR size.">MAX_ATR_SIZE</a>; <a name="l00357"></a>00357 <a name="l00358"></a>00358 rv = <a class="code" href="group__API.html#ga18f33eebb45d9e0d2a091ca7a0511d26" title="This function returns the current status of the reader connected to by hCard.">SCardStatus</a>(hCard, pcReaders, &dwReaderLen, &dwState, &dwProt, <a name="l00359"></a>00359 pbAtr, &dwAtrLen); <a name="l00360"></a>00360 <span class="preprocessor">#endif</span> <a name="l00361"></a>00361 <span class="preprocessor"></span> test_rv(rv, hContext, PANIC); <a name="l00362"></a>00362 <a name="l00363"></a>00363 printf(<span class="stringliteral">"Current Reader Name\t\t: "</span> GREEN <span class="stringliteral">"%s\n"</span> NORMAL, pcReaders); <a name="l00364"></a>00364 printf(<span class="stringliteral">"Current Reader State\t\t: "</span> GREEN <span class="stringliteral">"0x%.4lx\n"</span> NORMAL, dwState); <a name="l00365"></a>00365 printf(<span class="stringliteral">"Current Reader Protocol\t\t: T="</span> GREEN <span class="stringliteral">"%ld\n"</span> NORMAL, dwProt - 1); <a name="l00366"></a>00366 printf(<span class="stringliteral">"Current Reader ATR Size\t\t: "</span> GREEN <span class="stringliteral">"%ld"</span> NORMAL <span class="stringliteral">" bytes\n"</span>, <a name="l00367"></a>00367 dwAtrLen); <a name="l00368"></a>00368 printf(<span class="stringliteral">"Current Reader ATR Value\t: "</span> GREEN); <a name="l00369"></a>00369 <a name="l00370"></a>00370 <span class="keywordflow">for</span> (i = 0; i < dwAtrLen; i++) <a name="l00371"></a>00371 { <a name="l00372"></a>00372 printf(<span class="stringliteral">"%02X "</span>, pbAtr[i]); <a name="l00373"></a>00373 } <a name="l00374"></a>00374 printf(NORMAL <span class="stringliteral">"\n"</span>); <a name="l00375"></a>00375 <a name="l00376"></a>00376 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00377"></a>00377 <span class="preprocessor"></span> printf(<span class="stringliteral">"Testing SCardFreeMemory\t\t: "</span>); <a name="l00378"></a>00378 rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE...">SCardFreeMemory</a>(hContext, pcReaders); <a name="l00379"></a>00379 test_rv(rv, hContext, PANIC); <a name="l00380"></a>00380 printf(<span class="stringliteral">"Testing SCardFreeMemory\t\t: "</span>); <a name="l00381"></a>00381 rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE...">SCardFreeMemory</a>(hContext, pbAtr); <a name="l00382"></a>00382 test_rv(rv, hContext, PANIC); <a name="l00383"></a>00383 <span class="preprocessor">#else</span> <a name="l00384"></a>00384 <span class="preprocessor"></span> <span class="keywordflow">if</span> (pcReaders) <a name="l00385"></a>00385 free(pcReaders); <a name="l00386"></a>00386 <span class="preprocessor">#endif</span> <a name="l00387"></a>00387 <span class="preprocessor"></span> <a name="l00388"></a>00388 <span class="keywordflow">if</span> (rv != <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00389"></a>00389 { <a name="l00390"></a>00390 (void)<a class="code" href="group__API.html#ga4be198045c73ec0deb79e66c0ca1738a" title="This function terminates a connection made through SCardConnect().">SCardDisconnect</a>(hCard, <a class="code" href="pcsclite_8h.html#a07feb710d597835d1afc5cfd2ef6ecef" title="Reset on close.">SCARD_RESET_CARD</a>); <a name="l00391"></a>00391 (void)<a class="code" href="group__API.html#ga6aabcba7744c5c9419fdd6404f73a934" title="This function destroys a communication context to the PC/SC Resource Manager.">SCardReleaseContext</a>(hContext); <a name="l00392"></a>00392 } <a name="l00393"></a>00393 <a name="l00394"></a>00394 printf(<span class="stringliteral">"Press enter: "</span>); <a name="l00395"></a>00395 (void)getchar(); <a name="l00396"></a>00396 printf(<span class="stringliteral">"Testing SCardReconnect\t\t: "</span>); <a name="l00397"></a>00397 rv = <a class="code" href="group__API.html#gad5d4393ca8c470112ad9468c44ed8940" title="This function reestablishes a connection to a reader that was previously connected...">SCardReconnect</a>(hCard, <a class="code" href="pcsclite_8h.html#a724a33782fe519553f1e05ee77940f6f" title="Shared mode only.">SCARD_SHARE_SHARED</a>, <a name="l00398"></a>00398 <a class="code" href="pcsclite_8h.html#a4fe95267c322c3bf35f30fab6b25526c" title="T=0 active protocol.">SCARD_PROTOCOL_T0</a> | <a class="code" href="pcsclite_8h.html#a3c09cd155e07044f857130c183d64f03" title="T=1 active protocol.">SCARD_PROTOCOL_T1</a>, <a class="code" href="pcsclite_8h.html#a6f4f7f74e35ab4269f08381c967ee97b" title="Power down on close.">SCARD_UNPOWER_CARD</a>, &dwPref); <a name="l00399"></a>00399 test_rv(rv, hContext, PANIC); <a name="l00400"></a>00400 <a name="l00401"></a>00401 printf(<span class="stringliteral">"Testing SCardDisconnect\t\t: "</span>); <a name="l00402"></a>00402 rv = <a class="code" href="group__API.html#ga4be198045c73ec0deb79e66c0ca1738a" title="This function terminates a connection made through SCardConnect().">SCardDisconnect</a>(hCard, <a class="code" href="pcsclite_8h.html#a6f4f7f74e35ab4269f08381c967ee97b" title="Power down on close.">SCARD_UNPOWER_CARD</a>); <a name="l00403"></a>00403 test_rv(rv, hContext, PANIC); <a name="l00404"></a>00404 <a name="l00405"></a>00405 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span> <a name="l00406"></a>00406 <span class="preprocessor"></span> printf(<span class="stringliteral">"Testing SCardFreeMemory\t\t: "</span>); <a name="l00407"></a>00407 rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE...">SCardFreeMemory</a>(hContext, mszReaders); <a name="l00408"></a>00408 test_rv(rv, hContext, PANIC); <a name="l00409"></a>00409 <span class="preprocessor">#else</span> <a name="l00410"></a>00410 <span class="preprocessor"></span> free(mszReaders); <a name="l00411"></a>00411 <span class="preprocessor">#endif</span> <a name="l00412"></a>00412 <span class="preprocessor"></span> <a name="l00413"></a>00413 printf(<span class="stringliteral">"Testing SCardReleaseContext\t: "</span>); <a name="l00414"></a>00414 rv = <a class="code" href="group__API.html#ga6aabcba7744c5c9419fdd6404f73a934" title="This function destroys a communication context to the PC/SC Resource Manager.">SCardReleaseContext</a>(hContext); <a name="l00415"></a>00415 test_rv(rv, hContext, PANIC); <a name="l00416"></a>00416 <a name="l00417"></a>00417 printf(<span class="stringliteral">"\n"</span>); <a name="l00418"></a>00418 printf(<span class="stringliteral">"PC/SC Test Completed Successfully !\n"</span>); <a name="l00419"></a>00419 <a name="l00420"></a>00420 <span class="keywordflow">return</span> 0; <a name="l00421"></a>00421 } </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address> </body> </html>