Sophie

Sophie

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

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: prothandler.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>prothandler.c</h1>  </div>
</div>
<div class="contents">
<a href="prothandler_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</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: prothandler.c 5567 2011-01-29 13:18:49Z 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;string.h&gt;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;misc.h&quot;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;<a class="code" href="pcscd_8h.html" title="This keeps a list of defines for pcsc-lite.">pcscd.h</a>&quot;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &quot;debuglog.h&quot;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;<a class="code" href="readerfactory_8h.html" title="This keeps track of a list of currently available reader structures.">readerfactory.h</a>&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;<a class="code" href="prothandler_8h.html" title="This handles protocol defaults, PTS, etc.">prothandler.h</a>&quot;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;<a class="code" href="atrhandler_8h.html" title="This keeps track of smartcard protocols, timing issues and Answer to Reset ATR handling.">atrhandler.h</a>&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &quot;<a class="code" href="ifdwrapper_8h.html" title="This wraps the dynamic ifdhandler functions.">ifdwrapper.h</a>&quot;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;<a class="code" href="eventhandler_8h.html" title="This handles card insertion/removal events, updates ATR, protocol, and status information.">eventhandler.h</a>&quot;</span>
<a name="l00028"></a>00028 
<a name="l00034"></a><a class="code" href="prothandler_8h.html#ab90a8ce8ccece0e82beb131d99e42724">00034</a> UCHAR <a class="code" href="prothandler_8c.html#a30e7c843c2a5a626a1df5abe4a116e99" title="Get the default protocol used immediately after reset.">PHGetDefaultProtocol</a>(PUCHAR pucAtr, DWORD dwLength)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036     <a class="code" href="structSMARTCARD__EXTENSION.html">SMARTCARD_EXTENSION</a> sSmartCard;
<a name="l00037"></a>00037 
<a name="l00038"></a>00038     <span class="comment">/*</span>
<a name="l00039"></a>00039 <span class="comment">     * Zero out everything</span>
<a name="l00040"></a>00040 <span class="comment">     */</span>
<a name="l00041"></a>00041     memset(&amp;sSmartCard, 0x00, <span class="keyword">sizeof</span>(<a class="code" href="structSMARTCARD__EXTENSION.html">SMARTCARD_EXTENSION</a>));
<a name="l00042"></a>00042 
<a name="l00043"></a>00043     <span class="keywordflow">if</span> (<a class="code" href="atrhandler_8c.html#a76bf3383cc11cc95499325c987d6f193" title="Uncomment the following for ATR debugging or use .">ATRDecodeAtr</a>(&amp;sSmartCard, pucAtr, dwLength))
<a name="l00044"></a>00044         <span class="keywordflow">return</span> sSmartCard.CardCapabilities.CurrentProtocol;
<a name="l00045"></a>00045     <span class="keywordflow">else</span>
<a name="l00046"></a>00046         <span class="keywordflow">return</span> 0x00;
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 
<a name="l00054"></a><a class="code" href="prothandler_8h.html#ae1bf5f71af644725f12dcdb2e26e4111">00054</a> UCHAR <a class="code" href="prothandler_8c.html#a028195440f572393f25e2daf6d4df05b" title="Get the protocols supported by the card.">PHGetAvailableProtocols</a>(PUCHAR pucAtr, DWORD dwLength)
<a name="l00055"></a>00055 {
<a name="l00056"></a>00056     <a class="code" href="structSMARTCARD__EXTENSION.html">SMARTCARD_EXTENSION</a> sSmartCard;
<a name="l00057"></a>00057 
<a name="l00058"></a>00058     <span class="comment">/*</span>
<a name="l00059"></a>00059 <span class="comment">     * Zero out everything</span>
<a name="l00060"></a>00060 <span class="comment">     */</span>
<a name="l00061"></a>00061     memset(&amp;sSmartCard, 0x00, <span class="keyword">sizeof</span>(<a class="code" href="structSMARTCARD__EXTENSION.html">SMARTCARD_EXTENSION</a>));
<a name="l00062"></a>00062 
<a name="l00063"></a>00063     <span class="keywordflow">if</span> (<a class="code" href="atrhandler_8c.html#a76bf3383cc11cc95499325c987d6f193" title="Uncomment the following for ATR debugging or use .">ATRDecodeAtr</a>(&amp;sSmartCard, pucAtr, dwLength))
<a name="l00064"></a>00064         <span class="keywordflow">return</span> sSmartCard.CardCapabilities.AvailableProtocols;
<a name="l00065"></a>00065     <span class="keywordflow">else</span>
<a name="l00066"></a>00066         <span class="keywordflow">return</span> 0x00;
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068 
<a name="l00079"></a><a class="code" href="prothandler_8h.html#a3f27bce2e5c3ba9e7d97240d6c01a746">00079</a> DWORD <a class="code" href="prothandler_8c.html#a4522f0d45b2ab13cf3d264a605eec02d" title="Determine which protocol to use.">PHSetProtocol</a>(<span class="keyword">struct</span> <a class="code" href="structReaderContext.html">ReaderContext</a> * rContext,
<a name="l00080"></a>00080     DWORD dwPreferred, UCHAR ucAvailable, UCHAR ucDefault)
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082     DWORD protocol;
<a name="l00083"></a>00083     LONG rv;
<a name="l00084"></a>00084     UCHAR ucChosen;
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <span class="comment">/* App has specified no protocol */</span>
<a name="l00087"></a>00087     <span class="keywordflow">if</span> (dwPreferred == 0)
<a name="l00088"></a>00088         <span class="keywordflow">return</span> SET_PROTOCOL_WRONG_ARGUMENT;
<a name="l00089"></a>00089 
<a name="l00090"></a>00090     <span class="comment">/* requested protocol is not available */</span>
<a name="l00091"></a>00091     <span class="keywordflow">if</span> (! (dwPreferred &amp; ucAvailable))
<a name="l00092"></a>00092     {
<a name="l00093"></a>00093         <span class="comment">/* Note:</span>
<a name="l00094"></a>00094 <span class="comment">         * dwPreferred must be either SCARD_PROTOCOL_T0 or SCARD_PROTOCOL_T1</span>
<a name="l00095"></a>00095 <span class="comment">         * if dwPreferred == SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1 the test</span>
<a name="l00096"></a>00096 <span class="comment">         * (SCARD_PROTOCOL_T0 == dwPreferred) will not work as expected</span>
<a name="l00097"></a>00097 <span class="comment">         * and the debug message will not be correct.</span>
<a name="l00098"></a>00098 <span class="comment">         *</span>
<a name="l00099"></a>00099 <span class="comment">         * This case may only occur if</span>
<a name="l00100"></a>00100 <span class="comment">         * dwPreferred == SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1</span>
<a name="l00101"></a>00101 <span class="comment">         * and ucAvailable == 0 since we have (dwPreferred &amp; ucAvailable) == 0</span>
<a name="l00102"></a>00102 <span class="comment">         * and the case ucAvailable == 0 should never occur (the card is at</span>
<a name="l00103"></a>00103 <span class="comment">         * least T=0 or T=1)</span>
<a name="l00104"></a>00104 <span class="comment">         */</span>
<a name="l00105"></a>00105         Log2(PCSC_LOG_ERROR, <span class="stringliteral">&quot;Protocol T=%d requested but unsupported by the card&quot;</span>,
<a name="l00106"></a>00106             (<a class="code" href="pcsclite_8h.html#a4fe95267c322c3bf35f30fab6b25526c" title="T=0 active protocol.">SCARD_PROTOCOL_T0</a> == dwPreferred) ? 0 : 1);
<a name="l00107"></a>00107         <span class="keywordflow">return</span> SET_PROTOCOL_WRONG_ARGUMENT;
<a name="l00108"></a>00108     }
<a name="l00109"></a>00109 
<a name="l00110"></a>00110     <span class="comment">/* set default value */</span>
<a name="l00111"></a>00111     protocol = ucDefault;
<a name="l00112"></a>00112 
<a name="l00113"></a>00113     <span class="comment">/* keep only the available protocols */</span>
<a name="l00114"></a>00114     dwPreferred &amp;= ucAvailable;
<a name="l00115"></a>00115 
<a name="l00116"></a>00116     <span class="comment">/* we try to use T=1 first */</span>
<a name="l00117"></a>00117     <span class="keywordflow">if</span> (dwPreferred &amp; <a class="code" href="pcsclite_8h.html#a3c09cd155e07044f857130c183d64f03" title="T=1 active protocol.">SCARD_PROTOCOL_T1</a>)
<a name="l00118"></a>00118         ucChosen = <a class="code" href="pcsclite_8h.html#a3c09cd155e07044f857130c183d64f03" title="T=1 active protocol.">SCARD_PROTOCOL_T1</a>;
<a name="l00119"></a>00119     <span class="keywordflow">else</span>
<a name="l00120"></a>00120         <span class="keywordflow">if</span> (dwPreferred &amp; <a class="code" href="pcsclite_8h.html#a4fe95267c322c3bf35f30fab6b25526c" title="T=0 active protocol.">SCARD_PROTOCOL_T0</a>)
<a name="l00121"></a>00121             ucChosen = <a class="code" href="pcsclite_8h.html#a4fe95267c322c3bf35f30fab6b25526c" title="T=0 active protocol.">SCARD_PROTOCOL_T0</a>;
<a name="l00122"></a>00122         <span class="keywordflow">else</span>
<a name="l00123"></a>00123             <span class="comment">/* App wants unsupported protocol */</span>
<a name="l00124"></a>00124             <span class="keywordflow">return</span> SET_PROTOCOL_WRONG_ARGUMENT;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126     Log2(PCSC_LOG_INFO, <span class="stringliteral">&quot;Attempting PTS to T=%d&quot;</span>,
<a name="l00127"></a>00127         (SCARD_PROTOCOL_T0 == ucChosen ? 0 : 1));
<a name="l00128"></a>00128     rv = <a class="code" href="ifdwrapper_8c.html#ad794bea544918757cd2fbbae218fa458" title="Set the protocol type selection (PTS).">IFDSetPTS</a>(rContext, ucChosen, 0x00, 0x00, 0x00, 0x00);
<a name="l00129"></a>00129 
<a name="l00130"></a>00130     <span class="keywordflow">if</span> (<a class="code" href="ifdhandler_8h.html#ae45ef2a236e5e6f15eb6b24a7bdf2d72" title="no error">IFD_SUCCESS</a> == rv)
<a name="l00131"></a>00131         protocol = ucChosen;
<a name="l00132"></a>00132     <span class="keywordflow">else</span>
<a name="l00133"></a>00133         <span class="keywordflow">if</span> (<a class="code" href="ifdhandler_8h.html#a35aea7275c1fcb4e97d57f6c8fa28918" title="request is not supported">IFD_NOT_SUPPORTED</a> == rv)
<a name="l00134"></a>00134             Log2(PCSC_LOG_INFO, <span class="stringliteral">&quot;PTS not supported by driver, using T=%d&quot;</span>,
<a name="l00135"></a>00135                 (SCARD_PROTOCOL_T0 == protocol) ? 0 : 1);
<a name="l00136"></a>00136         <span class="keywordflow">else</span>
<a name="l00137"></a>00137             <span class="keywordflow">if</span> (<a class="code" href="ifdhandler_8h.html#a920dd667096ace9714f4cdcbcf687cf3" title="requested protocol not supported">IFD_PROTOCOL_NOT_SUPPORTED</a> == rv)
<a name="l00138"></a>00138                 Log2(PCSC_LOG_INFO, <span class="stringliteral">&quot;PTS protocol not supported, using T=%d&quot;</span>,
<a name="l00139"></a>00139                     (SCARD_PROTOCOL_T0 == protocol) ? 0 : 1);
<a name="l00140"></a>00140             <span class="keywordflow">else</span>
<a name="l00141"></a>00141             {
<a name="l00142"></a>00142                 Log3(PCSC_LOG_INFO, <span class="stringliteral">&quot;PTS failed (%d), using T=%d&quot;</span>, rv,
<a name="l00143"></a>00143                     (SCARD_PROTOCOL_T0 == protocol) ? 0 : 1);
<a name="l00144"></a>00144 
<a name="l00145"></a>00145                 <span class="comment">/* ISO 7816-3:1997 ch. 7.2 PPS protocol page 14</span>
<a name="l00146"></a>00146 <span class="comment">                 * - If the PPS exchange is unsuccessful, then the interface device</span>
<a name="l00147"></a>00147 <span class="comment">                 *   shall either reset or reject the card.</span>
<a name="l00148"></a>00148 <span class="comment">                 */</span>
<a name="l00149"></a>00149                 <span class="keywordflow">return</span> SET_PROTOCOL_PPS_FAILED;
<a name="l00150"></a>00150             }
<a name="l00151"></a>00151 
<a name="l00152"></a>00152     <span class="keywordflow">return</span> protocol;
<a name="l00153"></a>00153 }
<a name="l00154"></a>00154 
</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>