Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 3ef085c66d4a743f8dec260630a0b19c > files > 305

pcsc-lite-doc-1.5.5-4.fc13.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: winscard_msg.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&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;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&nbsp;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>winscard_msg.c</h1><a href="winscard__msg_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) 2001-2004</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"> *  Damien Sauveron &lt;damien.sauveron@labri.fr&gt;</span>
<a name="l00007"></a>00007 <span class="comment"> *  Ludoic 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: winscard_msg.c 3250 2009-01-02 13:32:17Z rousseau $</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;config.h&quot;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;sys/socket.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;sys/un.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#ifdef HAVE_SYS_FILIO_H</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/filio.h&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;misc.h&quot;</span>
<a name="l00039"></a>00039 <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="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="winscard_8h.html" title="This handles smartcard reader communications.">winscard.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="debug_8h.html" title="This handles debugging.">debug.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="winscard__msg_8h.html" title="This defines some structures and #defines to be used over the transport layer.">winscard_msg.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="sys__generic_8h.html" title="This handles abstract system level calls.">sys_generic.h</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;utils.h&quot;</span>
<a name="l00045"></a>00045 
<a name="l00057"></a><a class="code" href="winscard__msg_8h.html#a02b7e838fe9c455051b90d0d9b517cbe">00057</a> INTERNAL int32_t <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">psharedSegmentMsg</a> msgStruct, uint32_t dwClientID, int32_t blockamount)
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059     <span class="keywordflow">return</span> <a class="code" href="winscard__msg_8c.html#a79ad4835c2384316592152d320eef49a" title="Called by the Client to get the reponse from the server or vice-versa.">SHMMessageReceive</a>(msgStruct, <span class="keyword">sizeof</span>(*msgStruct), dwClientID, blockamount);
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 
<a name="l00075"></a><a class="code" href="winscard__msg_8h.html#a73ff6cd124c68eafa964ea105cf561ff">00075</a> INTERNAL <span class="keywordtype">int</span> <a class="code" href="winscard__msg_8c.html#a562fe25a1e3f02f53891cbace306bb4b" title="Prepares a communication channel for the client to talk to the server.">SHMClientSetupSession</a>(uint32_t *pdwClientID)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077     <span class="keyword">struct </span>sockaddr_un svc_addr;
<a name="l00078"></a>00078     <span class="keywordtype">int</span> one;
<a name="l00079"></a>00079     <span class="keywordtype">int</span> ret;
<a name="l00080"></a>00080 
<a name="l00081"></a>00081     ret = socket(AF_UNIX, SOCK_STREAM, 0);
<a name="l00082"></a>00082     <span class="keywordflow">if</span> (ret &lt; 0)
<a name="l00083"></a>00083     {
<a name="l00084"></a>00084         Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Error: create on client socket: %s&quot;</span>,
<a name="l00085"></a>00085             strerror(errno));
<a name="l00086"></a>00086         <span class="keywordflow">return</span> -1;
<a name="l00087"></a>00087     }
<a name="l00088"></a>00088     *pdwClientID = ret;
<a name="l00089"></a>00089 
<a name="l00090"></a>00090     svc_addr.sun_family = AF_UNIX;
<a name="l00091"></a>00091     strncpy(svc_addr.sun_path, PCSCLITE_CSOCK_NAME,
<a name="l00092"></a>00092         <span class="keyword">sizeof</span>(svc_addr.sun_path));
<a name="l00093"></a>00093 
<a name="l00094"></a>00094     <span class="keywordflow">if</span> (connect(*pdwClientID, (<span class="keyword">struct</span> sockaddr *) &amp;svc_addr,
<a name="l00095"></a>00095             <span class="keyword">sizeof</span>(svc_addr.sun_family) + strlen(svc_addr.sun_path) + 1) &lt; 0)
<a name="l00096"></a>00096     {
<a name="l00097"></a>00097         Log3(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Error: connect to client socket %s: %s&quot;</span>,
<a name="l00098"></a>00098             PCSCLITE_CSOCK_NAME, strerror(errno));
<a name="l00099"></a>00099         (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(*pdwClientID);
<a name="l00100"></a>00100         <span class="keywordflow">return</span> -1;
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102 
<a name="l00103"></a>00103     one = 1;
<a name="l00104"></a>00104     <span class="keywordflow">if</span> (ioctl(*pdwClientID, FIONBIO, &amp;one) &lt; 0)
<a name="l00105"></a>00105     {
<a name="l00106"></a>00106         Log3(PCSC_LOG_CRITICAL, <span class="stringliteral">&quot;Error: cannot set socket %s nonblocking: %s&quot;</span>,
<a name="l00107"></a>00107             PCSCLITE_CSOCK_NAME, strerror(errno));
<a name="l00108"></a>00108         (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(*pdwClientID);
<a name="l00109"></a>00109         <span class="keywordflow">return</span> -1;
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     <span class="keywordflow">return</span> 0;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
<a name="l00122"></a><a class="code" href="winscard__msg_8h.html#a772dacc8c80c31a7b507e90dae02bea5">00122</a> INTERNAL <span class="keywordtype">int</span> <a class="code" href="winscard__msg_8c.html#afa75f2e575d731004a8daa0287838af5" title="Closes the socket used by the client to communicate with the server.">SHMClientCloseSession</a>(uint32_t dwClientID)
<a name="l00123"></a>00123 {
<a name="l00124"></a>00124     (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(dwClientID);
<a name="l00125"></a>00125     <span class="keywordflow">return</span> 0;
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 
<a name="l00143"></a><a class="code" href="winscard__msg_8h.html#a2fb170b1c0bb878f95b09397a85a3dd3">00143</a> INTERNAL int32_t <a class="code" href="winscard__msg_8c.html#ac1bde0241da918d1a346c0dca681dd78" title="Sends a menssage from client to server or vice-versa.">SHMMessageSend</a>(<span class="keywordtype">void</span> *buffer_void, uint64_t buffer_size,
<a name="l00144"></a>00144     int32_t filedes, int32_t blockAmount)
<a name="l00145"></a>00145 {
<a name="l00146"></a>00146     <span class="keywordtype">char</span> *buffer = buffer_void;
<a name="l00147"></a>00147 
<a name="l00148"></a>00148     <span class="comment">/*</span>
<a name="l00149"></a>00149 <span class="comment">     * default is success</span>
<a name="l00150"></a>00150 <span class="comment">     */</span>
<a name="l00151"></a>00151     <span class="keywordtype">int</span> retval = 0;
<a name="l00152"></a>00152     <span class="comment">/*</span>
<a name="l00153"></a>00153 <span class="comment">     * record the time when we started</span>
<a name="l00154"></a>00154 <span class="comment">     */</span>
<a name="l00155"></a>00155     time_t start = time(0);
<a name="l00156"></a>00156     <span class="comment">/*</span>
<a name="l00157"></a>00157 <span class="comment">     * how many bytes remains to be written</span>
<a name="l00158"></a>00158 <span class="comment">     */</span>
<a name="l00159"></a>00159     <span class="keywordtype">size_t</span> remaining = buffer_size;
<a name="l00160"></a>00160 
<a name="l00161"></a>00161     <span class="comment">/*</span>
<a name="l00162"></a>00162 <span class="comment">     * repeat until all data is written</span>
<a name="l00163"></a>00163 <span class="comment">     */</span>
<a name="l00164"></a>00164     <span class="keywordflow">while</span> (remaining &gt; 0)
<a name="l00165"></a>00165     {
<a name="l00166"></a>00166         fd_set write_fd;
<a name="l00167"></a>00167         <span class="keyword">struct </span>timeval timeout;
<a name="l00168"></a>00168         <span class="keywordtype">int</span> selret;
<a name="l00169"></a>00169 
<a name="l00170"></a>00170         FD_ZERO(&amp;write_fd);
<a name="l00171"></a>00171         FD_SET(filedes, &amp;write_fd);
<a name="l00172"></a>00172 
<a name="l00173"></a>00173         timeout.tv_usec = 0;
<a name="l00174"></a>00174         <span class="keywordflow">if</span> ((timeout.tv_sec = start + blockAmount - time(0)) &lt; 0)
<a name="l00175"></a>00175         {
<a name="l00176"></a>00176             <span class="comment">/*</span>
<a name="l00177"></a>00177 <span class="comment">             * we already timed out</span>
<a name="l00178"></a>00178 <span class="comment">             */</span>
<a name="l00179"></a>00179             retval = -1;
<a name="l00180"></a>00180             <span class="keywordflow">break</span>;
<a name="l00181"></a>00181         }
<a name="l00182"></a>00182 
<a name="l00183"></a>00183         selret = select(filedes + 1, NULL, &amp;write_fd, NULL, &amp;timeout);
<a name="l00184"></a>00184 
<a name="l00185"></a>00185         <span class="comment">/*</span>
<a name="l00186"></a>00186 <span class="comment">         * try to write only when the file descriptor is writable</span>
<a name="l00187"></a>00187 <span class="comment">         */</span>
<a name="l00188"></a>00188         <span class="keywordflow">if</span> (selret &gt; 0)
<a name="l00189"></a>00189         {
<a name="l00190"></a>00190             <span class="keywordtype">int</span> written;
<a name="l00191"></a>00191 
<a name="l00192"></a>00192             <span class="keywordflow">if</span> (!FD_ISSET(filedes, &amp;write_fd))
<a name="l00193"></a>00193             {
<a name="l00194"></a>00194                 <span class="comment">/*</span>
<a name="l00195"></a>00195 <span class="comment">                 * very strange situation. it should be an assert really</span>
<a name="l00196"></a>00196 <span class="comment">                 */</span>
<a name="l00197"></a>00197                 retval = -1;
<a name="l00198"></a>00198                 <span class="keywordflow">break</span>;
<a name="l00199"></a>00199             }
<a name="l00200"></a>00200             written = write(filedes, buffer, remaining);
<a name="l00201"></a>00201 
<a name="l00202"></a>00202             <span class="keywordflow">if</span> (written &gt; 0)
<a name="l00203"></a>00203             {
<a name="l00204"></a>00204                 <span class="comment">/*</span>
<a name="l00205"></a>00205 <span class="comment">                 * we wrote something</span>
<a name="l00206"></a>00206 <span class="comment">                 */</span>
<a name="l00207"></a>00207                 buffer += written;
<a name="l00208"></a>00208                 remaining -= written;
<a name="l00209"></a>00209             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (written == 0)
<a name="l00210"></a>00210             {
<a name="l00211"></a>00211                 <span class="comment">/*</span>
<a name="l00212"></a>00212 <span class="comment">                 * peer closed the socket</span>
<a name="l00213"></a>00213 <span class="comment">                 */</span>
<a name="l00214"></a>00214                 retval = -1;
<a name="l00215"></a>00215                 <span class="keywordflow">break</span>;
<a name="l00216"></a>00216             } <span class="keywordflow">else</span>
<a name="l00217"></a>00217             {
<a name="l00218"></a>00218                 <span class="comment">/*</span>
<a name="l00219"></a>00219 <span class="comment">                 * we ignore the signals and socket full situations, all</span>
<a name="l00220"></a>00220 <span class="comment">                 * other errors are fatal</span>
<a name="l00221"></a>00221 <span class="comment">                 */</span>
<a name="l00222"></a>00222                 <span class="keywordflow">if</span> (errno != EINTR &amp;&amp; errno != EAGAIN)
<a name="l00223"></a>00223                 {
<a name="l00224"></a>00224                     retval = -1;
<a name="l00225"></a>00225                     <span class="keywordflow">break</span>;
<a name="l00226"></a>00226                 }
<a name="l00227"></a>00227             }
<a name="l00228"></a>00228         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (selret == 0)
<a name="l00229"></a>00229         {
<a name="l00230"></a>00230             <span class="comment">/*</span>
<a name="l00231"></a>00231 <span class="comment">             * timeout</span>
<a name="l00232"></a>00232 <span class="comment">             */</span>
<a name="l00233"></a>00233             retval = -1;
<a name="l00234"></a>00234             <span class="keywordflow">break</span>;
<a name="l00235"></a>00235         } <span class="keywordflow">else</span>
<a name="l00236"></a>00236         {
<a name="l00237"></a>00237             <span class="comment">/*</span>
<a name="l00238"></a>00238 <span class="comment">             * ignore signals</span>
<a name="l00239"></a>00239 <span class="comment">             */</span>
<a name="l00240"></a>00240             <span class="keywordflow">if</span> (errno != EINTR)
<a name="l00241"></a>00241             {
<a name="l00242"></a>00242                 Log2(PCSC_LOG_ERROR, <span class="stringliteral">&quot;select returns with failure: %s&quot;</span>,
<a name="l00243"></a>00243                     strerror(errno));
<a name="l00244"></a>00244                 retval = -1;
<a name="l00245"></a>00245                 <span class="keywordflow">break</span>;
<a name="l00246"></a>00246             }
<a name="l00247"></a>00247         }
<a name="l00248"></a>00248     }
<a name="l00249"></a>00249 
<a name="l00250"></a>00250     <span class="keywordflow">return</span> retval;
<a name="l00251"></a>00251 }
<a name="l00252"></a>00252 
<a name="l00268"></a><a class="code" href="winscard__msg_8h.html#aeafdb2c686d0cf2787eb3efc43c60d7f">00268</a> INTERNAL int32_t <a class="code" href="winscard__msg_8c.html#a79ad4835c2384316592152d320eef49a" title="Called by the Client to get the reponse from the server or vice-versa.">SHMMessageReceive</a>(<span class="keywordtype">void</span> *buffer_void, uint64_t buffer_size,
<a name="l00269"></a>00269     int32_t filedes, int32_t blockAmount)
<a name="l00270"></a>00270 {
<a name="l00271"></a>00271     <span class="keywordtype">char</span> *buffer = buffer_void;
<a name="l00272"></a>00272 
<a name="l00273"></a>00273     <span class="comment">/*</span>
<a name="l00274"></a>00274 <span class="comment">     * default is success</span>
<a name="l00275"></a>00275 <span class="comment">     */</span>
<a name="l00276"></a>00276     <span class="keywordtype">int</span> retval = 0;
<a name="l00277"></a>00277     <span class="comment">/*</span>
<a name="l00278"></a>00278 <span class="comment">     * record the time when we started</span>
<a name="l00279"></a>00279 <span class="comment">     */</span>
<a name="l00280"></a>00280     time_t start = time(0);
<a name="l00281"></a>00281     <span class="comment">/*</span>
<a name="l00282"></a>00282 <span class="comment">     * how many bytes we must read</span>
<a name="l00283"></a>00283 <span class="comment">     */</span>
<a name="l00284"></a>00284     <span class="keywordtype">size_t</span> remaining = buffer_size;
<a name="l00285"></a>00285 
<a name="l00286"></a>00286     <span class="comment">/*</span>
<a name="l00287"></a>00287 <span class="comment">     * repeat until we get the whole message</span>
<a name="l00288"></a>00288 <span class="comment">     */</span>
<a name="l00289"></a>00289     <span class="keywordflow">while</span> (remaining &gt; 0)
<a name="l00290"></a>00290     {
<a name="l00291"></a>00291         fd_set read_fd;
<a name="l00292"></a>00292         <span class="keyword">struct </span>timeval timeout;
<a name="l00293"></a>00293         <span class="keywordtype">int</span> selret;
<a name="l00294"></a>00294 
<a name="l00295"></a>00295         FD_ZERO(&amp;read_fd);
<a name="l00296"></a>00296         FD_SET(filedes, &amp;read_fd);
<a name="l00297"></a>00297 
<a name="l00298"></a>00298         timeout.tv_usec = 0;
<a name="l00299"></a>00299         <span class="keywordflow">if</span> ((timeout.tv_sec = start + blockAmount - time(0)) &lt; 0)
<a name="l00300"></a>00300         {
<a name="l00301"></a>00301             <span class="comment">/*</span>
<a name="l00302"></a>00302 <span class="comment">             * we already timed out</span>
<a name="l00303"></a>00303 <span class="comment">             */</span>
<a name="l00304"></a>00304             retval = -1;
<a name="l00305"></a>00305             <span class="keywordflow">break</span>;
<a name="l00306"></a>00306         }
<a name="l00307"></a>00307 
<a name="l00308"></a>00308         selret = select(filedes + 1, &amp;read_fd, NULL, NULL, &amp;timeout);
<a name="l00309"></a>00309 
<a name="l00310"></a>00310         <span class="comment">/*</span>
<a name="l00311"></a>00311 <span class="comment">         * try to read only when socket is readable</span>
<a name="l00312"></a>00312 <span class="comment">         */</span>
<a name="l00313"></a>00313         <span class="keywordflow">if</span> (selret &gt; 0)
<a name="l00314"></a>00314         {
<a name="l00315"></a>00315             <span class="keywordtype">int</span> readed;
<a name="l00316"></a>00316 
<a name="l00317"></a>00317             <span class="keywordflow">if</span> (!FD_ISSET(filedes, &amp;read_fd))
<a name="l00318"></a>00318             {
<a name="l00319"></a>00319                 <span class="comment">/*</span>
<a name="l00320"></a>00320 <span class="comment">                 * very strange situation. it should be an assert really</span>
<a name="l00321"></a>00321 <span class="comment">                 */</span>
<a name="l00322"></a>00322                 retval = -1;
<a name="l00323"></a>00323                 <span class="keywordflow">break</span>;
<a name="l00324"></a>00324             }
<a name="l00325"></a>00325             readed = read(filedes, buffer, remaining);
<a name="l00326"></a>00326 
<a name="l00327"></a>00327             <span class="keywordflow">if</span> (readed &gt; 0)
<a name="l00328"></a>00328             {
<a name="l00329"></a>00329                 <span class="comment">/*</span>
<a name="l00330"></a>00330 <span class="comment">                 * we got something</span>
<a name="l00331"></a>00331 <span class="comment">                 */</span>
<a name="l00332"></a>00332                 buffer += readed;
<a name="l00333"></a>00333                 remaining -= readed;
<a name="l00334"></a>00334             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (readed == 0)
<a name="l00335"></a>00335             {
<a name="l00336"></a>00336                 <span class="comment">/*</span>
<a name="l00337"></a>00337 <span class="comment">                 * peer closed the socket</span>
<a name="l00338"></a>00338 <span class="comment">                 */</span>
<a name="l00339"></a>00339                 retval = -1;
<a name="l00340"></a>00340                 <span class="keywordflow">break</span>;
<a name="l00341"></a>00341             } <span class="keywordflow">else</span>
<a name="l00342"></a>00342             {
<a name="l00343"></a>00343                 <span class="comment">/*</span>
<a name="l00344"></a>00344 <span class="comment">                 * we ignore the signals and empty socket situations, all</span>
<a name="l00345"></a>00345 <span class="comment">                 * other errors are fatal</span>
<a name="l00346"></a>00346 <span class="comment">                 */</span>
<a name="l00347"></a>00347                 <span class="keywordflow">if</span> (errno != EINTR &amp;&amp; errno != EAGAIN)
<a name="l00348"></a>00348                 {
<a name="l00349"></a>00349                     retval = -1;
<a name="l00350"></a>00350                     <span class="keywordflow">break</span>;
<a name="l00351"></a>00351                 }
<a name="l00352"></a>00352             }
<a name="l00353"></a>00353         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (selret == 0)
<a name="l00354"></a>00354         {
<a name="l00355"></a>00355 <span class="preprocessor">#ifdef PCSCD</span>
<a name="l00356"></a>00356 <span class="preprocessor"></span>            <span class="comment">/*</span>
<a name="l00357"></a>00357 <span class="comment">             * timeout</span>
<a name="l00358"></a>00358 <span class="comment">             */</span>
<a name="l00359"></a>00359             retval = -1;
<a name="l00360"></a>00360             <span class="keywordflow">break</span>;
<a name="l00361"></a>00361 <span class="preprocessor">#else</span>
<a name="l00362"></a>00362 <span class="preprocessor"></span>            <span class="comment">/* is the daemon still there? */</span>
<a name="l00363"></a>00363             <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>() != <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="l00364"></a>00364             {
<a name="l00365"></a>00365                 <span class="comment">/*</span>
<a name="l00366"></a>00366 <span class="comment">                 * timeout</span>
<a name="l00367"></a>00367 <span class="comment">                 */</span>
<a name="l00368"></a>00368                 retval = -1;
<a name="l00369"></a>00369                 <span class="keywordflow">break</span>;
<a name="l00370"></a>00370             }
<a name="l00371"></a>00371 
<a name="l00372"></a>00372             <span class="comment">/* the command is extra slow so we keep waiting */</span>
<a name="l00373"></a>00373             start = time(0);
<a name="l00374"></a>00374 
<a name="l00375"></a>00375             <span class="comment">/* you need to set the env variable PCSCLITE_DEBUG=0 since this is</span>
<a name="l00376"></a>00376 <span class="comment">             * logged on the client side and not on the pcscd side*/</span>
<a name="l00377"></a>00377             Log1(PCSC_LOG_INFO, <span class="stringliteral">&quot;Command not yet finished&quot;</span>);
<a name="l00378"></a>00378 <span class="preprocessor">#endif</span>
<a name="l00379"></a>00379 <span class="preprocessor"></span>        } <span class="keywordflow">else</span>
<a name="l00380"></a>00380         {
<a name="l00381"></a>00381             <span class="comment">/*</span>
<a name="l00382"></a>00382 <span class="comment">             * we ignore signals, all other errors are fatal</span>
<a name="l00383"></a>00383 <span class="comment">             */</span>
<a name="l00384"></a>00384             <span class="keywordflow">if</span> (errno != EINTR)
<a name="l00385"></a>00385             {
<a name="l00386"></a>00386                 Log2(PCSC_LOG_ERROR, <span class="stringliteral">&quot;select returns with failure: %s&quot;</span>,
<a name="l00387"></a>00387                     strerror(errno));
<a name="l00388"></a>00388                 retval = -1;
<a name="l00389"></a>00389                 <span class="keywordflow">break</span>;
<a name="l00390"></a>00390             }
<a name="l00391"></a>00391         }
<a name="l00392"></a>00392     }
<a name="l00393"></a>00393 
<a name="l00394"></a>00394     <span class="keywordflow">return</span> retval;
<a name="l00395"></a>00395 }
<a name="l00396"></a>00396 
<a name="l00412"></a><a class="code" href="winscard__msg_8h.html#a5484b7f633a56ce3805c2fdbfe2a114b">00412</a> INTERNAL int32_t <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(uint32_t command, uint32_t dwClientID,
<a name="l00413"></a>00413     uint64_t size, uint32_t blockAmount, <span class="keywordtype">void</span> *data_void)
<a name="l00414"></a>00414 {
<a name="l00415"></a>00415     <span class="keywordtype">char</span> *data = data_void;
<a name="l00416"></a>00416 
<a name="l00417"></a>00417     <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct;
<a name="l00418"></a>00418     <span class="keywordtype">int</span> ret;
<a name="l00419"></a>00419 
<a name="l00420"></a>00420     <span class="comment">/*</span>
<a name="l00421"></a>00421 <span class="comment">     * Set the appropriate packet parameters</span>
<a name="l00422"></a>00422 <span class="comment">     */</span>
<a name="l00423"></a>00423 
<a name="l00424"></a>00424     memset(&amp;msgStruct, 0, <span class="keyword">sizeof</span>(msgStruct));
<a name="l00425"></a>00425     msgStruct.mtype = CMD_FUNCTION;
<a name="l00426"></a>00426     msgStruct.<a class="code" href="structrxSharedSegment.html#ae137824545088a41344fde36a04e55ac" title="one of the pcsc_adm_commands ">user_id</a> = SYS_GetUID();
<a name="l00427"></a>00427     msgStruct.group_id = SYS_GetGID();
<a name="l00428"></a>00428     msgStruct.command = command;
<a name="l00429"></a>00429     msgStruct.<a class="code" href="structrxSharedSegment.html#aa5d2946fef4fdab83e295779e0c2b171" title="one of the pcsc_msg_commands ">date</a> = time(NULL);
<a name="l00430"></a>00430     memset(msgStruct.key, 0, <span class="keyword">sizeof</span>(msgStruct.key));
<a name="l00431"></a>00431     <span class="keywordflow">if</span> ((<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca35bfc3eb2607c5bd387d1f8566de814e" title="used by SCardTransmit()">SCARD_TRANSMIT_EXTENDED</a> == command)
<a name="l00432"></a>00432         || (<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca33919bd674d4f6cfa58178cdaf50cf38" title="used by SCardControl()">SCARD_CONTROL_EXTENDED</a> == command))
<a name="l00433"></a>00433     {
<a name="l00434"></a>00434         <span class="comment">/* first block */</span>
<a name="l00435"></a>00435         <span class="keywordflow">if</span> (size &gt; <span class="keyword">sizeof</span>(msgStruct.data))
<a name="l00436"></a>00436             memcpy(msgStruct.data, data, <span class="keyword">sizeof</span>(msgStruct.data));
<a name="l00437"></a>00437         <span class="keywordflow">else</span>
<a name="l00438"></a>00438         {
<a name="l00439"></a>00439             memcpy(msgStruct.data, data, size);
<a name="l00440"></a>00440             memset(msgStruct.data+size, 0, <span class="keyword">sizeof</span>(msgStruct.data)-size);
<a name="l00441"></a>00441         }
<a name="l00442"></a>00442 
<a name="l00443"></a>00443         ret = <a class="code" href="winscard__msg_8c.html#ac1bde0241da918d1a346c0dca681dd78" title="Sends a menssage from client to server or vice-versa.">SHMMessageSend</a>(&amp;msgStruct, <span class="keyword">sizeof</span>(msgStruct), dwClientID,
<a name="l00444"></a>00444             blockAmount);
<a name="l00445"></a>00445 
<a name="l00446"></a>00446         <span class="comment">/* do not send an empty second block */</span>
<a name="l00447"></a>00447         <span class="keywordflow">if</span> ((0 == ret) &amp;&amp; (size &gt; <span class="keyword">sizeof</span>(msgStruct.data)))
<a name="l00448"></a>00448         {
<a name="l00449"></a>00449             <span class="comment">/* second block */</span>
<a name="l00450"></a>00450             ret = <a class="code" href="winscard__msg_8c.html#ac1bde0241da918d1a346c0dca681dd78" title="Sends a menssage from client to server or vice-versa.">SHMMessageSend</a>(data+<span class="keyword">sizeof</span>(msgStruct.data),
<a name="l00451"></a>00451                 size-<span class="keyword">sizeof</span>(msgStruct.data), dwClientID, blockAmount);
<a name="l00452"></a>00452         }
<a name="l00453"></a>00453     }
<a name="l00454"></a>00454     <span class="keywordflow">else</span>
<a name="l00455"></a>00455     {
<a name="l00456"></a>00456         memcpy(msgStruct.data, data, size);
<a name="l00457"></a>00457 
<a name="l00458"></a>00458         ret = <a class="code" href="winscard__msg_8c.html#ac1bde0241da918d1a346c0dca681dd78" title="Sends a menssage from client to server or vice-versa.">SHMMessageSend</a>(&amp;msgStruct, <span class="keyword">sizeof</span>(msgStruct), dwClientID,
<a name="l00459"></a>00459             blockAmount);
<a name="l00460"></a>00460     }
<a name="l00461"></a>00461 
<a name="l00462"></a>00462     <span class="keywordflow">if</span> (<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dcaaa1c43a9cc7497df780b9e5a81a3abcb" title="used by SCardTransmit()">SCARD_TRANSMIT</a> == command)
<a name="l00463"></a>00463         <span class="comment">/* clean APDU buffer to remove any possible PIN or secret value */</span>
<a name="l00464"></a>00464         memset(msgStruct.data, 0, min(size, <span class="keyword">sizeof</span>(msgStruct.data)));
<a name="l00465"></a>00465 
<a name="l00466"></a>00466     <span class="keywordflow">return</span> ret;
<a name="l00467"></a>00467 }
<a name="l00468"></a>00468 
<a name="l00478"></a><a class="code" href="winscard__msg_8c.html#a300df343a6a356eebb24216f787ad8ea">00478</a> INTERNAL <span class="keywordtype">void</span> <a class="code" href="winscard__msg_8c.html#a300df343a6a356eebb24216f787ad8ea" title="Closes the communications channel used by the server to talk to the clients.">SHMCleanupSharedSegment</a>(<span class="keywordtype">int</span> sockValue, <span class="keyword">const</span> <span class="keywordtype">char</span> *pcFilePath)
<a name="l00479"></a>00479 {
<a name="l00480"></a>00480     (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(sockValue);
<a name="l00481"></a>00481     (void)<a class="code" href="sys__generic_8h.html#af473e9d9a973ce499cdef8ffb87913b2" title="Removes a file.">SYS_RemoveFile</a>(pcFilePath);
<a name="l00482"></a>00482 }
<a name="l00483"></a>00483 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated by&nbsp;
<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>