Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 1d49b8f9ae104bfd1869bc35e6bbf50d > files > 264

pcsc-lite-doc-1.7.2-1.fc15.noarch.rpm

<!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.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">pcsc-lite&#160;<span id="projectnumber">1.7.2</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;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 id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_7a4553ee0c3b13d0e595a5d1659110a6.html">src</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<h1>testpcsc.c</h1>  </div>
</div>
<div class="contents">
<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 &lt;corcoran@linuxnet.com&gt;</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright (C) 2004-2010</span>
<a name="l00007"></a>00007 <span class="comment"> *  Ludovic Rousseau &lt;ludovic.rousseau@free.fr&gt;</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * $Id: testpcsc.c 5096 2010-08-02 14:33:35Z 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 &quot;config.h&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="preprocessor">#include &quot;pcsclite.h&quot;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;winscard.h&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;reader.h&quot;</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 &quot;\33[34m&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define RED &quot;\33[31m&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define BRIGHT_RED &quot;\33[01;31m&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#define GREEN &quot;\33[32m&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define NORMAL &quot;\33[0m&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define MAGENTA &quot;\33[35m&quot;</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#a22530ffaff18b5d3e32260a5f1ce4abd" 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">&quot;%s (don&#39;t panic)\n&quot;</span> NORMAL, <a class="code" href="group__API.html#gab5c302876c4c8187143603837a41aa86" 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">&quot;%s\n&quot;</span> NORMAL, <a class="code" href="group__API.html#gab5c302876c4c8187143603837a41aa86" 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="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#gab5c302876c4c8187143603837a41aa86" 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#af328aca3e11de737ecd771bcf1f75fb5" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard;
<a name="l00058"></a>00058     <a class="code" href="pcsclite_8h.html#a22530ffaff18b5d3e32260a5f1ce4abd" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext;
<a name="l00059"></a>00059     <a class="code" href="structSCARD__READERSTATE.html">SCARD_READERSTATE</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">&quot;\nMUSCLE PC/SC Lite unitary test Program\n\n&quot;</span>);
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     printf(MAGENTA <span class="stringliteral">&quot;THIS PROGRAM IS NOT DESIGNED AS A TESTING TOOL FOR END USERS!\n&quot;</span>);
<a name="l00094"></a>00094     printf(<span class="stringliteral">&quot;Do NOT use it unless you really know what you do.\n\n&quot;</span> NORMAL);
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     printf(<span class="stringliteral">&quot;Testing SCardEstablishContext\t: &quot;</span>);
<a name="l00097"></a>00097     rv = <a class="code" href="group__API.html#gaa1b8970169fd4883a6dc4a8f43f19b67" title="Creates an Application Context to the PC/SC Resource Manager.">SCardEstablishContext</a>(<a class="code" href="pcsclite_8h.html#a01ffeed2d7fac470371c79fa86b1e309" title="Scope in system.">SCARD_SCOPE_SYSTEM</a>, NULL, NULL, &amp;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">&quot;Testing SCardIsValidContext\t: &quot;</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">&quot;Testing SCardIsValidContext\t: &quot;</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">&quot;Testing SCardListReaderGroups\t: &quot;</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="Returns a list of currently available reader groups on the system.">SCardListReaderGroups</a>(hContext, (LPSTR)&amp;mszGroups, &amp;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="Returns a list of currently available reader groups on the system.">SCardListReaderGroups</a>(hContext, NULL, &amp;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">&quot;Testing SCardListReaderGroups\t: &quot;</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="Returns a list of currently available reader groups on the system.">SCardListReaderGroups</a>(hContext, mszGroups, &amp;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 &lt; dwGroups; i++)
<a name="l00127"></a>00127     {
<a name="l00128"></a>00128         ++p;
<a name="l00129"></a>00129         printf(GREEN <span class="stringliteral">&quot;Group %02d: %s\n&quot;</span> NORMAL, p, &amp;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">&quot;Testing SCardFreeMemory\t\t: &quot;</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 length ...">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">&quot;Testing SCardListReaders\t: &quot;</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, &amp;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">&quot;Testing SCardGetStatusChange \n&quot;</span>);
<a name="l00149"></a>00149         printf(<span class="stringliteral">&quot;Please insert a working reader\t: &quot;</span>);
<a name="l00150"></a>00150         (void)fflush(stdout);
<a name="l00151"></a>00151         rgReaderStates[0].szReader = <span class="stringliteral">&quot;\\\\?PnP?\\Notification&quot;</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#ga33247d5d1257d59e55647c3bb717db24" title="Blocks execution until the current availability of the cards in a specific set of readers changes...">SCardGetStatusChange</a>(hContext, <a class="code" href="pcsclite_8h.html#aa84a29002ab81c719c0d07bb446296e0" title="Infinite timeout.">INFINITE</a>, 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">&quot;Testing SCardListReaders\t: &quot;</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)&amp;mszReaders, &amp;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, &amp;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">&quot;Testing SCardListReaders\t: &quot;</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, &amp;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 &lt; dwReaders; i++)
<a name="l00177"></a>00177     {
<a name="l00178"></a>00178         ++p;
<a name="l00179"></a>00179         printf(GREEN <span class="stringliteral">&quot;Reader %02d: %s\n&quot;</span> NORMAL, p, &amp;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 &gt; 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">&quot;Enter the reader number\t\t: &quot;</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">&quot;%d&quot;</span>, &amp;iReader);
<a name="l00192"></a>00192 
<a name="l00193"></a>00193             <span class="keywordflow">if</span> (iReader &gt; p || iReader &lt;= 0)
<a name="l00194"></a>00194                 printf(<span class="stringliteral">&quot;Invalid Value - try again\n&quot;</span>);
<a name="l00195"></a>00195         }
<a name="l00196"></a>00196         <span class="keywordflow">while</span> (iReader &gt; p || iReader &lt;= 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 = &amp;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">&quot;Waiting for card insertion\t: &quot;</span>);
<a name="l00204"></a>00204     (void)fflush(stdout);
<a name="l00205"></a>00205     rv = <a class="code" href="group__API.html#ga33247d5d1257d59e55647c3bb717db24" title="Blocks execution until the current availability of the cards in a specific set of readers changes...">SCardGetStatusChange</a>(hContext, <a class="code" href="pcsclite_8h.html#aa84a29002ab81c719c0d07bb446296e0" title="Infinite timeout.">INFINITE</a>, 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 &amp; <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">&quot;\nA reader has been connected/disconnected\n&quot;</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">&quot;Testing SCardConnect\t\t: &quot;</span>);
<a name="l00214"></a>00214     rv = <a class="code" href="group__API.html#ga4e515829752e0a8dbc4d630696a8d6a5" title="Establishes a connection to the reader specified in * szReader.">SCardConnect</a>(hContext, &amp;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         &amp;hCard, &amp;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">&quot;Unknown protocol\n&quot;</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">&quot;Select file:&quot;</span>);
<a name="l00237"></a>00237     send_length = 7;
<a name="l00238"></a>00238     memcpy(bSendBuffer, <span class="stringliteral">&quot;\x00\xA4\x00\x00\x02\x3F\x00&quot;</span>, send_length);
<a name="l00239"></a>00239     <span class="keywordflow">for</span> (i=0; i&lt;send_length; i++)
<a name="l00240"></a>00240         printf(<span class="stringliteral">&quot; %02X&quot;</span>, bSendBuffer[i]);
<a name="l00241"></a>00241     printf(<span class="stringliteral">&quot;\n&quot;</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">&quot;Testing SCardTransmit\t\t: &quot;</span>);
<a name="l00245"></a>00245     rv = <a class="code" href="group__API.html#ga9a2d77242a271310269065e64633ab99" title="Sends an APDU to the smart card contained in the reader connected to by SCardConnect().">SCardTransmit</a>(hCard, &amp;pioSendPci, bSendBuffer, send_length,
<a name="l00246"></a>00246         &amp;pioRecvPci, bRecvBuffer, &amp;length);
<a name="l00247"></a>00247     test_rv(rv, hContext, PANIC);
<a name="l00248"></a>00248     printf(<span class="stringliteral">&quot; card response:&quot;</span> GREEN);
<a name="l00249"></a>00249     <span class="keywordflow">for</span> (i=0; i&lt;length; i++)
<a name="l00250"></a>00250         printf(<span class="stringliteral">&quot; %02X&quot;</span>, bRecvBuffer[i]);
<a name="l00251"></a>00251     printf(<span class="stringliteral">&quot;\n&quot;</span> NORMAL);
<a name="l00252"></a>00252 
<a name="l00253"></a>00253     printf(<span class="stringliteral">&quot;Testing SCardControl\t\t: &quot;</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">&quot;Foobar&quot;</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="Sends a command directly to the IFD Handler (reader driver) to be processed by the reader...">SCardControl</a>(hCard, buffer, 7, buffer, &amp;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="Sends a command directly to the IFD Handler (reader driver) to be processed by the reader...">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), &amp;cbRecvLength);
<a name="l00268"></a>00268         <span class="keywordflow">if</span> (cbRecvLength &amp;&amp; (<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&lt;cbRecvLength; i++)
<a name="l00271"></a>00271                 printf(<span class="stringliteral">&quot;%c&quot;</span>, buffer[i]);
<a name="l00272"></a>00272             printf(<span class="stringliteral">&quot; &quot;</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">&quot;Testing SCardGetAttrib\t\t: &quot;</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="Get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#a362e5f163fda06e0aa6d2964d2a4bbae" title="Reader&amp;#39;s display name.">SCARD_ATTR_DEVICE_FRIENDLY_NAME</a>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)&amp;pbAttr,
<a name="l00282"></a>00282         &amp;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="Get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#a362e5f163fda06e0aa6d2964d2a4bbae" title="Reader&amp;#39;s display name.">SCARD_ATTR_DEVICE_FRIENDLY_NAME</a>, NULL, &amp;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">&quot;SCARD_ATTR_DEVICE_FRIENDLY_NAME length: &quot;</span> GREEN <span class="stringliteral">&quot;%ld\n&quot;</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">&quot;Testing SCardGetAttrib\t\t: &quot;</span>);
<a name="l00293"></a>00293     rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="Get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(hCard, <a class="code" href="reader_8h.html#a362e5f163fda06e0aa6d2964d2a4bbae" title="Reader&amp;#39;s display name.">SCARD_ATTR_DEVICE_FRIENDLY_NAME</a>, pbAttr, &amp;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         printf(<span class="stringliteral">&quot;SCARD_ATTR_DEVICE_FRIENDLY_NAME: &quot;</span> GREEN <span class="stringliteral">&quot;%s\n&quot;</span> NORMAL, pbAttr);
<a name="l00298"></a>00298 
<a name="l00299"></a>00299 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span>
<a name="l00300"></a>00300 <span class="preprocessor"></span>    printf(<span class="stringliteral">&quot;Testing SCardFreeMemory\t\t: &quot;</span>);
<a name="l00301"></a>00301     rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length ...">SCardFreeMemory</a>(hContext, pbAttr);
<a name="l00302"></a>00302     test_rv(rv, hContext, PANIC);
<a name="l00303"></a>00303 <span class="preprocessor">#else</span>
<a name="l00304"></a>00304 <span class="preprocessor"></span>    <span class="keywordflow">if</span> (pbAttr)
<a name="l00305"></a>00305         free(pbAttr);
<a name="l00306"></a>00306 <span class="preprocessor">#endif</span>
<a name="l00307"></a>00307 <span class="preprocessor"></span>
<a name="l00308"></a>00308     printf(<span class="stringliteral">&quot;Testing SCardGetAttrib\t\t: &quot;</span>);
<a name="l00309"></a>00309 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span>
<a name="l00310"></a>00310 <span class="preprocessor"></span>    pcbAttrLen = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>;
<a name="l00311"></a>00311     rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="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> *)&amp;pbAttr,
<a name="l00312"></a>00312         &amp;pcbAttrLen);
<a name="l00313"></a>00313 <span class="preprocessor">#else</span>
<a name="l00314"></a>00314 <span class="preprocessor"></span>    rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="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, &amp;pcbAttrLen);
<a name="l00315"></a>00315     test_rv(rv, hContext, DONT_PANIC);
<a name="l00316"></a>00316     <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="l00317"></a>00317     {
<a name="l00318"></a>00318         printf(<span class="stringliteral">&quot;SCARD_ATTR_ATR_STRING length: &quot;</span> GREEN <span class="stringliteral">&quot;%ld\n&quot;</span> NORMAL, pcbAttrLen);
<a name="l00319"></a>00319         pbAttr = malloc(pcbAttrLen);
<a name="l00320"></a>00320     }
<a name="l00321"></a>00321 
<a name="l00322"></a>00322     printf(<span class="stringliteral">&quot;Testing SCardGetAttrib\t\t: &quot;</span>);
<a name="l00323"></a>00323     rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="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, &amp;pcbAttrLen);
<a name="l00324"></a>00324 <span class="preprocessor">#endif</span>
<a name="l00325"></a>00325 <span class="preprocessor"></span>    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         printf(<span class="stringliteral">&quot;SCARD_ATTR_ATR_STRING length: &quot;</span> GREEN <span class="stringliteral">&quot;%ld\n&quot;</span> NORMAL, pcbAttrLen);
<a name="l00329"></a>00329         printf(<span class="stringliteral">&quot;SCARD_ATTR_ATR_STRING: &quot;</span> GREEN);
<a name="l00330"></a>00330         <span class="keywordflow">for</span> (i = 0; i &lt; pcbAttrLen; i++)
<a name="l00331"></a>00331             printf(<span class="stringliteral">&quot;%02X &quot;</span>, pbAttr[i]);
<a name="l00332"></a>00332         printf(<span class="stringliteral">&quot;\n&quot;</span> NORMAL);
<a name="l00333"></a>00333     }
<a name="l00334"></a>00334 
<a name="l00335"></a>00335 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span>
<a name="l00336"></a>00336 <span class="preprocessor"></span>    printf(<span class="stringliteral">&quot;Testing SCardFreeMemory\t\t: &quot;</span>);
<a name="l00337"></a>00337     rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length ...">SCardFreeMemory</a>(hContext, pbAttr);
<a name="l00338"></a>00338     test_rv(rv, hContext, PANIC);
<a name="l00339"></a>00339 <span class="preprocessor">#else</span>
<a name="l00340"></a>00340 <span class="preprocessor"></span>    <span class="keywordflow">if</span> (pbAttr)
<a name="l00341"></a>00341         free(pbAttr);
<a name="l00342"></a>00342 <span class="preprocessor">#endif</span>
<a name="l00343"></a>00343 <span class="preprocessor"></span>
<a name="l00344"></a>00344     printf(<span class="stringliteral">&quot;Testing SCardGetAttrib\t\t: &quot;</span>);
<a name="l00345"></a>00345     dwBufLen = <span class="keyword">sizeof</span>(buf);
<a name="l00346"></a>00346     rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="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 = major version...">SCARD_ATTR_VENDOR_IFD_VERSION</a>, buf.as_char, &amp;dwBufLen);
<a name="l00347"></a>00347     test_rv(rv, hContext, DONT_PANIC);
<a name="l00348"></a>00348     <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="l00349"></a>00349         printf(<span class="stringliteral">&quot;Vendor IFD version\t\t: &quot;</span> GREEN <span class="stringliteral">&quot;0x%08lX\n&quot;</span> NORMAL,
<a name="l00350"></a>00350             buf.as_DWORD);
<a name="l00351"></a>00351 
<a name="l00352"></a>00352     printf(<span class="stringliteral">&quot;Testing SCardGetAttrib\t\t: &quot;</span>);
<a name="l00353"></a>00353     dwBufLen = <span class="keyword">sizeof</span>(buf);
<a name="l00354"></a>00354     rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="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, &amp;dwBufLen);
<a name="l00355"></a>00355     test_rv(rv, hContext, DONT_PANIC);
<a name="l00356"></a>00356     <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="l00357"></a>00357     {
<a name="l00358"></a>00358         <span class="keywordflow">if</span> (dwBufLen == <span class="keyword">sizeof</span>(uint32_t))
<a name="l00359"></a>00359             printf(<span class="stringliteral">&quot;Max message length\t\t: &quot;</span> GREEN <span class="stringliteral">&quot;%d\n&quot;</span> NORMAL,
<a name="l00360"></a>00360                 buf.as_uint32_t);
<a name="l00361"></a>00361         <span class="keywordflow">else</span>
<a name="l00362"></a>00362             printf(RED <span class="stringliteral">&quot;Wrong size&quot;</span> NORMAL);
<a name="l00363"></a>00363     }
<a name="l00364"></a>00364 
<a name="l00365"></a>00365     printf(<span class="stringliteral">&quot;Testing SCardGetAttrib\t\t: &quot;</span>);
<a name="l00366"></a>00366     dwBufLen = <span class="keyword">sizeof</span>(buf);
<a name="l00367"></a>00367     rv = <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="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, &amp;dwBufLen);
<a name="l00368"></a>00368     test_rv(rv, hContext, DONT_PANIC);
<a name="l00369"></a>00369     <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="l00370"></a>00370         printf(<span class="stringliteral">&quot;Vendor name\t\t\t: &quot;</span> GREEN <span class="stringliteral">&quot;%s\n&quot;</span> NORMAL, buf.as_char);
<a name="l00371"></a>00371 
<a name="l00372"></a>00372     printf(<span class="stringliteral">&quot;Testing SCardSetAttrib\t\t: &quot;</span>);
<a name="l00373"></a>00373     rv = <a class="code" href="group__API.html#ga060f0038a4ddfd5dd2b8fadf3c3a2e4f" title="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">&quot;&quot;</span>, 1);
<a name="l00374"></a>00374     test_rv(rv, hContext, DONT_PANIC);
<a name="l00375"></a>00375 
<a name="l00376"></a>00376     printf(<span class="stringliteral">&quot;Testing SCardStatus\t\t: &quot;</span>);
<a name="l00377"></a>00377 
<a name="l00378"></a>00378 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span>
<a name="l00379"></a>00379 <span class="preprocessor"></span>    dwReaderLen = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>;
<a name="l00380"></a>00380     dwAtrLen = <a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a>;
<a name="l00381"></a>00381     rv = <a class="code" href="group__API.html#ga18f33eebb45d9e0d2a091ca7a0511d26" title="Returns the current status of the reader connected to by hCard.">SCardStatus</a>(hCard, (LPSTR)&amp;pcReaders, &amp;dwReaderLen, &amp;dwState, &amp;dwProt,
<a name="l00382"></a>00382         (LPBYTE)&amp;pbAtr, &amp;dwAtrLen);
<a name="l00383"></a>00383 <span class="preprocessor">#else</span>
<a name="l00384"></a>00384 <span class="preprocessor"></span>    dwReaderLen = 100;
<a name="l00385"></a>00385     pcReaders   = malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) * 100);
<a name="l00386"></a>00386     dwAtrLen    = <a class="code" href="pcsclite_8h.html#a7ac7915ff6f9baefa66886c98bdbb91e" title="Maximum ATR size.">MAX_ATR_SIZE</a>;
<a name="l00387"></a>00387 
<a name="l00388"></a>00388     rv = <a class="code" href="group__API.html#ga18f33eebb45d9e0d2a091ca7a0511d26" title="Returns the current status of the reader connected to by hCard.">SCardStatus</a>(hCard, pcReaders, &amp;dwReaderLen, &amp;dwState, &amp;dwProt,
<a name="l00389"></a>00389         pbAtr, &amp;dwAtrLen);
<a name="l00390"></a>00390 <span class="preprocessor">#endif</span>
<a name="l00391"></a>00391 <span class="preprocessor"></span>    test_rv(rv, hContext, PANIC);
<a name="l00392"></a>00392 
<a name="l00393"></a>00393     printf(<span class="stringliteral">&quot;Current Reader Name\t\t: &quot;</span> GREEN <span class="stringliteral">&quot;%s\n&quot;</span> NORMAL, pcReaders);
<a name="l00394"></a>00394     printf(<span class="stringliteral">&quot;Current Reader State\t\t: &quot;</span> GREEN <span class="stringliteral">&quot;0x%.4lx\n&quot;</span> NORMAL, dwState);
<a name="l00395"></a>00395     printf(<span class="stringliteral">&quot;Current Reader Protocol\t\t: T=&quot;</span> GREEN <span class="stringliteral">&quot;%ld\n&quot;</span> NORMAL, dwProt - 1);
<a name="l00396"></a>00396     printf(<span class="stringliteral">&quot;Current Reader ATR Size\t\t: &quot;</span> GREEN <span class="stringliteral">&quot;%ld&quot;</span> NORMAL <span class="stringliteral">&quot; bytes\n&quot;</span>,
<a name="l00397"></a>00397         dwAtrLen);
<a name="l00398"></a>00398     printf(<span class="stringliteral">&quot;Current Reader ATR Value\t: &quot;</span> GREEN);
<a name="l00399"></a>00399 
<a name="l00400"></a>00400     <span class="keywordflow">for</span> (i = 0; i &lt; dwAtrLen; i++)
<a name="l00401"></a>00401     {
<a name="l00402"></a>00402         printf(<span class="stringliteral">&quot;%02X &quot;</span>, pbAtr[i]);
<a name="l00403"></a>00403     }
<a name="l00404"></a>00404     printf(NORMAL <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00405"></a>00405 
<a name="l00406"></a>00406 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span>
<a name="l00407"></a>00407 <span class="preprocessor"></span>    printf(<span class="stringliteral">&quot;Testing SCardFreeMemory\t\t: &quot;</span>);
<a name="l00408"></a>00408     rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length ...">SCardFreeMemory</a>(hContext, pcReaders);
<a name="l00409"></a>00409     test_rv(rv, hContext, PANIC);
<a name="l00410"></a>00410     printf(<span class="stringliteral">&quot;Testing SCardFreeMemory\t\t: &quot;</span>);
<a name="l00411"></a>00411     rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length ...">SCardFreeMemory</a>(hContext, pbAtr);
<a name="l00412"></a>00412     test_rv(rv, hContext, PANIC);
<a name="l00413"></a>00413 <span class="preprocessor">#else</span>
<a name="l00414"></a>00414 <span class="preprocessor"></span>    <span class="keywordflow">if</span> (pcReaders)
<a name="l00415"></a>00415         free(pcReaders);
<a name="l00416"></a>00416 <span class="preprocessor">#endif</span>
<a name="l00417"></a>00417 <span class="preprocessor"></span>
<a name="l00418"></a>00418     <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="l00419"></a>00419     {
<a name="l00420"></a>00420         (void)<a class="code" href="group__API.html#ga4be198045c73ec0deb79e66c0ca1738a" title="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="l00421"></a>00421         (void)<a class="code" href="group__API.html#ga6aabcba7744c5c9419fdd6404f73a934" title="Destroys a communication context to the PC/SC Resource Manager.">SCardReleaseContext</a>(hContext);
<a name="l00422"></a>00422     }
<a name="l00423"></a>00423 
<a name="l00424"></a>00424     printf(<span class="stringliteral">&quot;Press enter: &quot;</span>);
<a name="l00425"></a>00425     (void)getchar();
<a name="l00426"></a>00426     printf(<span class="stringliteral">&quot;Testing SCardReconnect\t\t: &quot;</span>);
<a name="l00427"></a>00427     rv = <a class="code" href="group__API.html#gad5d4393ca8c470112ad9468c44ed8940" title="Reestablishes a connection to a reader that was previously connected to using SCardConnect().">SCardReconnect</a>(hCard, <a class="code" href="pcsclite_8h.html#a724a33782fe519553f1e05ee77940f6f" title="Shared mode only.">SCARD_SHARE_SHARED</a>,
<a name="l00428"></a>00428         <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>, &amp;dwPref);
<a name="l00429"></a>00429     test_rv(rv, hContext, PANIC);
<a name="l00430"></a>00430 
<a name="l00431"></a>00431     printf(<span class="stringliteral">&quot;Testing SCardDisconnect\t\t: &quot;</span>);
<a name="l00432"></a>00432     rv = <a class="code" href="group__API.html#ga4be198045c73ec0deb79e66c0ca1738a" title="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="l00433"></a>00433     test_rv(rv, hContext, PANIC);
<a name="l00434"></a>00434 
<a name="l00435"></a>00435 <span class="preprocessor">#ifdef USE_AUTOALLOCATE</span>
<a name="l00436"></a>00436 <span class="preprocessor"></span>    printf(<span class="stringliteral">&quot;Testing SCardFreeMemory\t\t: &quot;</span>);
<a name="l00437"></a>00437     rv = <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length ...">SCardFreeMemory</a>(hContext, mszReaders);
<a name="l00438"></a>00438     test_rv(rv, hContext, PANIC);
<a name="l00439"></a>00439 <span class="preprocessor">#else</span>
<a name="l00440"></a>00440 <span class="preprocessor"></span>    free(mszReaders);
<a name="l00441"></a>00441 <span class="preprocessor">#endif</span>
<a name="l00442"></a>00442 <span class="preprocessor"></span>
<a name="l00443"></a>00443     printf(<span class="stringliteral">&quot;Testing SCardReleaseContext\t: &quot;</span>);
<a name="l00444"></a>00444     rv = <a class="code" href="group__API.html#ga6aabcba7744c5c9419fdd6404f73a934" title="Destroys a communication context to the PC/SC Resource Manager.">SCardReleaseContext</a>(hContext);
<a name="l00445"></a>00445     test_rv(rv, hContext, PANIC);
<a name="l00446"></a>00446 
<a name="l00447"></a>00447     printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00448"></a>00448     printf(<span class="stringliteral">&quot;PC/SC Test Completed Successfully !\n&quot;</span>);
<a name="l00449"></a>00449 
<a name="l00450"></a>00450     <span class="keywordflow">return</span> 0;
<a name="l00451"></a>00451 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Thu Mar 31 2011 for pcsc-lite by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>