<!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_clnt.c Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.2-20100208 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_c68a5dfdca54003c765e303a18006edb.html">src</a> </div> </div> <div class="contents"> <h1>winscard_clnt.c</h1><a href="winscard__clnt_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-2004</span> <a name="l00005"></a>00005 <span class="comment"> * David Corcoran <corcoran@linuxnet.com></span> <a name="l00006"></a>00006 <span class="comment"> * Damien Sauveron <damien.sauveron@labri.fr></span> <a name="l00007"></a>00007 <span class="comment"> * Ludovic Rousseau <ludovic.rousseau@free.fr></span> <a name="l00008"></a>00008 <span class="comment"> *</span> <a name="l00009"></a>00009 <span class="comment"> * $Id: winscard_clnt.c 4333 2009-07-21 11:36:36Z 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 "config.h"</span> <a name="l00022"></a>00022 <span class="preprocessor">#include <stdlib.h></span> <a name="l00023"></a>00023 <span class="preprocessor">#include <string.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <sys/types.h></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <fcntl.h></span> <a name="l00026"></a>00026 <span class="preprocessor">#include <unistd.h></span> <a name="l00027"></a>00027 <span class="preprocessor">#include <sys/un.h></span> <a name="l00028"></a>00028 <span class="preprocessor">#include <errno.h></span> <a name="l00029"></a>00029 <span class="preprocessor">#include <stddef.h></span> <a name="l00030"></a>00030 <span class="preprocessor">#include <sys/time.h></span> <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="preprocessor">#include "misc.h"</span> <a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="pcscd_8h.html" title="This keeps a list of defines for pcsc-lite.">pcscd.h</a>"</span> <a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="winscard_8h.html" title="This handles smartcard reader communications.">winscard.h</a>"</span> <a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="debug_8h.html" title="This handles debugging.">debug.h</a>"</span> <a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="thread__generic_8h.html" title="This provides system specific thread calls.">thread_generic.h</a>"</span> <a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="strlcpycat_8h.html" title="prototypes of strlcpy()/strlcat() imported from OpenBSD">strlcpycat.h</a>"</span> <a name="l00038"></a>00038 <a name="l00039"></a>00039 <span class="preprocessor">#include "<a class="code" href="readerfactory_8h.html" title="This keeps track of a list of currently available reader structures.">readerfactory.h</a>"</span> <a name="l00040"></a>00040 <span class="preprocessor">#include "<a class="code" href="eventhandler_8h.html" title="This handles card insertion/removal events, updates ATR, protocol, and status information...">eventhandler.h</a>"</span> <a name="l00041"></a>00041 <span class="preprocessor">#include "<a class="code" href="sys__generic_8h.html" title="This handles abstract system level calls.">sys_generic.h</a>"</span> <a name="l00042"></a>00042 <span class="preprocessor">#include "<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>"</span> <a name="l00043"></a>00043 <span class="preprocessor">#include "utils.h"</span> <a name="l00044"></a>00044 <a name="l00046"></a><a class="code" href="winscard__clnt_8c.html#ac7c340dc56974012d266eff9be71e9ed">00046</a> <span class="preprocessor">#define SCARD_PROTOCOL_ANY_OLD 0x1000</span> <a name="l00047"></a>00047 <span class="preprocessor"></span> <a name="l00048"></a>00048 <span class="preprocessor">#ifndef TRUE</span> <a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define TRUE 1</span> <a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define FALSE 0</span> <a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00052"></a>00052 <span class="preprocessor"></span> <a name="l00053"></a>00053 <span class="comment">/* r = a - b */</span> <a name="l00054"></a>00054 <span class="keyword">static</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> time_sub(<span class="keyword">struct</span> timeval *a, <span class="keyword">struct</span> timeval *b) <a name="l00055"></a>00055 { <a name="l00056"></a>00056 <span class="keyword">struct </span>timeval r; <a name="l00057"></a>00057 r.tv_sec = a -> tv_sec - b -> tv_sec; <a name="l00058"></a>00058 r.tv_usec = a -> tv_usec - b -> tv_usec; <a name="l00059"></a>00059 <span class="keywordflow">if</span> (r.tv_usec < 0) <a name="l00060"></a>00060 { <a name="l00061"></a>00061 r.tv_sec--; <a name="l00062"></a>00062 r.tv_usec += 1000000; <a name="l00063"></a>00063 } <a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="keywordflow">return</span> r.tv_sec * 1000000 + r.tv_usec; <a name="l00066"></a>00066 } <span class="comment">/* time_sub */</span> <a name="l00067"></a>00067 <a name="l00068"></a>00068 <a name="l00069"></a>00069 <span class="preprocessor">#undef DO_PROFILE</span> <a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#ifdef DO_PROFILE</span> <a name="l00071"></a>00071 <span class="preprocessor"></span> <a name="l00072"></a>00072 <span class="preprocessor">#define PROFILE_FILE "/tmp/pcsc_profile"</span> <a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#include <stdio.h></span> <a name="l00074"></a>00074 <span class="preprocessor">#include <sys/time.h></span> <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="keyword">struct </span>timeval profile_time_start; <a name="l00077"></a>00077 FILE *profile_fd; <a name="l00078"></a>00078 <span class="keywordtype">char</span> profile_tty; <a name="l00079"></a>00079 <span class="keywordtype">char</span> fct_name[100]; <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="preprocessor">#define PROFILE_START profile_start(__FUNCTION__);</span> <a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define PROFILE_END(rv) profile_end(__FUNCTION__, rv);</span> <a name="l00083"></a>00083 <span class="preprocessor"></span> <a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keywordtype">void</span> profile_start(<span class="keyword">const</span> <span class="keywordtype">char</span> *f) <a name="l00085"></a>00085 { <a name="l00086"></a>00086 <span class="keyword">static</span> <span class="keywordtype">char</span> initialized = FALSE; <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="keywordflow">if</span> (!initialized) <a name="l00089"></a>00089 { <a name="l00090"></a>00090 <span class="keywordtype">char</span> filename[80]; <a name="l00091"></a>00091 <a name="l00092"></a>00092 initialized = TRUE; <a name="l00093"></a>00093 sprintf(filename, <span class="stringliteral">"%s-%d"</span>, PROFILE_FILE, getuid()); <a name="l00094"></a>00094 profile_fd = fopen(filename, <span class="stringliteral">"a+"</span>); <a name="l00095"></a>00095 <span class="keywordflow">if</span> (NULL == profile_fd) <a name="l00096"></a>00096 { <a name="l00097"></a>00097 fprintf(stderr, <span class="stringliteral">"\33[01;31mCan't open %s: %s\33[0m\n"</span>, <a name="l00098"></a>00098 PROFILE_FILE, strerror(errno)); <a name="l00099"></a>00099 exit(-1); <a name="l00100"></a>00100 } <a name="l00101"></a>00101 fprintf(profile_fd, <span class="stringliteral">"\nStart a new profile\n"</span>); <a name="l00102"></a>00102 <a name="l00103"></a>00103 <span class="keywordflow">if</span> (isatty(fileno(stderr))) <a name="l00104"></a>00104 profile_tty = TRUE; <a name="l00105"></a>00105 <span class="keywordflow">else</span> <a name="l00106"></a>00106 profile_tty = FALSE; <a name="l00107"></a>00107 } <a name="l00108"></a>00108 <a name="l00109"></a>00109 <span class="comment">/* PROFILE_END was not called before? */</span> <a name="l00110"></a>00110 <span class="keywordflow">if</span> (profile_tty && fct_name[0]) <a name="l00111"></a>00111 printf(<span class="stringliteral">"\33[01;34m WARNING: %s starts before %s finishes\33[0m\n"</span>, <a name="l00112"></a>00112 f, fct_name); <a name="l00113"></a>00113 <a name="l00114"></a>00114 strlcpy(fct_name, f, <span class="keyword">sizeof</span>(fct_name)); <a name="l00115"></a>00115 <a name="l00116"></a>00116 gettimeofday(&profile_time_start, NULL); <a name="l00117"></a>00117 } <span class="comment">/* profile_start */</span> <a name="l00118"></a>00118 <a name="l00119"></a>00119 <span class="keyword">static</span> <span class="keywordtype">void</span> profile_end(<span class="keyword">const</span> <span class="keywordtype">char</span> *f, LONG rv) <a name="l00120"></a>00120 { <a name="l00121"></a>00121 <span class="keyword">struct </span>timeval profile_time_end; <a name="l00122"></a>00122 <span class="keywordtype">long</span> d; <a name="l00123"></a>00123 <a name="l00124"></a>00124 gettimeofday(&profile_time_end, NULL); <a name="l00125"></a>00125 d = time_sub(&profile_time_end, &profile_time_start); <a name="l00126"></a>00126 <a name="l00127"></a>00127 <span class="keywordflow">if</span> (profile_tty) <a name="l00128"></a>00128 { <a name="l00129"></a>00129 <span class="keywordflow">if</span> (fct_name[0]) <a name="l00130"></a>00130 { <a name="l00131"></a>00131 <span class="keywordflow">if</span> (strncmp(fct_name, f, <span class="keyword">sizeof</span>(fct_name))) <a name="l00132"></a>00132 printf(<span class="stringliteral">"\33[01;34m WARNING: %s ends before %s\33[0m\n"</span>, <a name="l00133"></a>00133 f, fct_name); <a name="l00134"></a>00134 } <a name="l00135"></a>00135 <span class="keywordflow">else</span> <a name="l00136"></a>00136 printf(<span class="stringliteral">"\33[01;34m WARNING: %s ends but we lost its start\33[0m\n"</span>, <a name="l00137"></a>00137 f); <a name="l00138"></a>00138 <a name="l00139"></a>00139 <span class="comment">/* allow to detect missing PROFILE_END calls */</span> <a name="l00140"></a>00140 fct_name[0] = <span class="charliteral">'\0'</span>; <a name="l00141"></a>00141 <a name="l00142"></a>00142 <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="l00143"></a>00143 fprintf(stderr, <a name="l00144"></a>00144 <span class="stringliteral">"\33[01;31mRESULT %s \33[35m%ld \33[34m0x%08lX %s\33[0m\n"</span>, <a name="l00145"></a>00145 f, d, rv, <a class="code" href="group__API.html#ga132e20ab457d042a06f7df733f15b22d" title="This function return a human readable text for the given PC/SC error code.">pcsc_stringify_error</a>(rv)); <a name="l00146"></a>00146 <span class="keywordflow">else</span> <a name="l00147"></a>00147 fprintf(stderr, <span class="stringliteral">"\33[01;31mRESULT %s \33[35m%ld\33[0m\n"</span>, f, d); <a name="l00148"></a>00148 } <a name="l00149"></a>00149 fprintf(profile_fd, <span class="stringliteral">"%s %ld\n"</span>, f, d); <a name="l00150"></a>00150 fflush(profile_fd); <a name="l00151"></a>00151 } <span class="comment">/* profile_end */</span> <a name="l00152"></a>00152 <a name="l00153"></a>00153 <span class="preprocessor">#else</span> <a name="l00154"></a>00154 <span class="preprocessor"></span><span class="preprocessor">#define PROFILE_START</span> <a name="l00155"></a>00155 <span class="preprocessor"></span><span class="preprocessor">#define PROFILE_END(rv)</span> <a name="l00156"></a>00156 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00157"></a>00157 <span class="preprocessor"></span> <a name="l00162"></a><a class="code" href="struct__psChannelMap.html">00162</a> <span class="keyword">struct </span><a class="code" href="struct__psChannelMap.html" title="Represents an Application Context Channel.">_psChannelMap</a> <a name="l00163"></a>00163 { <a name="l00164"></a>00164 <a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard; <a name="l00165"></a>00165 LPSTR readerName; <a name="l00166"></a>00166 }; <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="struct__psChannelMap.html" title="Represents an Application Context Channel.">_psChannelMap</a> <a class="code" href="struct__psChannelMap.html" title="Represents an Application Context Channel.">CHANNEL_MAP</a>, *<a class="code" href="struct__psChannelMap.html" title="Represents an Application Context Channel.">PCHANNEL_MAP</a>; <a name="l00169"></a>00169 <a name="l00175"></a><a class="code" href="struct__psContextMap.html">00175</a> <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="struct__psContextMap.html" title="Represents the an Application Context on the Client side.">_psContextMap</a> <a name="l00176"></a>00176 { <a name="l00177"></a><a class="code" href="struct__psContextMap.html#a4e3f21f7252b71833af88ba9f2864577">00177</a> DWORD <a class="code" href="struct__psContextMap.html#a4e3f21f7252b71833af88ba9f2864577" title="Client Connection ID.">dwClientID</a>; <a name="l00178"></a><a class="code" href="struct__psContextMap.html#a4171c839145c22f7594818304bf4e7a9">00178</a> <a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> <a class="code" href="struct__psContextMap.html#a4171c839145c22f7594818304bf4e7a9" title="Application Context ID.">hContext</a>; <a name="l00179"></a>00179 DWORD contextBlockStatus; <a name="l00180"></a><a class="code" href="struct__psContextMap.html#af46cea0e5161cce9a32f83a8e1303521">00180</a> PCSCLITE_MUTEX_T <a class="code" href="struct__psContextMap.html#af46cea0e5161cce9a32f83a8e1303521" title="Mutex for this context.">mMutex</a>; <a name="l00181"></a>00181 <a class="code" href="struct__psChannelMap.html" title="Represents an Application Context Channel.">CHANNEL_MAP</a> psChannelMap[<a class="code" href="pcscd_8h.html#a35697bcf11218bc1aa5bfe831b360df7" title="Maximum channels on an application context.">PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS</a>]; <a name="l00182"></a>00182 } <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[<a class="code" href="pcscd_8h.html#a6a6f002ba5ba58accdf202f14cc10563" title="Maximum contexts by application.">PCSCLITE_MAX_APPLICATION_CONTEXTS</a>]; <a name="l00183"></a>00183 <a name="l00187"></a><a class="code" href="winscard__clnt_8c.html#a1a5339bb356528ce056a2b3bfcc49444">00187</a> <span class="keyword">static</span> <span class="keywordtype">short</span> <a class="code" href="winscard__clnt_8c.html#a1a5339bb356528ce056a2b3bfcc49444" title="Make sure the initialization code is executed only once.">isExecuted</a> = 0; <a name="l00188"></a>00188 <a name="l00189"></a>00189 <a name="l00193"></a><a class="code" href="winscard__clnt_8c.html#a3c905a378deb91c13dbbb15b31060f37">00193</a> <span class="keyword">static</span> time_t <a class="code" href="winscard__clnt_8c.html#a3c905a378deb91c13dbbb15b31060f37" title="creation time of pcscd PCSCLITE_PUBSHM_FILE file">daemon_ctime</a> = 0; <a name="l00194"></a>00194 <span class="keyword">static</span> pid_t daemon_pid = 0; <a name="l00199"></a><a class="code" href="winscard__clnt_8c.html#a87f9cbda197595c49572e21179cbb96b">00199</a> <span class="keyword">static</span> pid_t <a class="code" href="winscard__clnt_8c.html#a87f9cbda197595c49572e21179cbb96b" title="PID of the client application.">client_pid</a> = 0; <a name="l00200"></a>00200 <a name="l00206"></a><a class="code" href="winscard__clnt_8c.html#a0c73c984118f8eaa5115c0a89803b825">00206</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="winscard__clnt_8c.html#a0c73c984118f8eaa5115c0a89803b825" title="Memory mapped address used to read status information about the readers.">mapAddr</a> = 0; <a name="l00207"></a>00207 <a name="l00212"></a><a class="code" href="winscard__clnt_8c.html#a633fd84349357939b82a0946626a4c73">00212</a> <span class="keyword">static</span> PCSCLITE_MUTEX <a class="code" href="winscard__clnt_8c.html#a633fd84349357939b82a0946626a4c73" title="Ensure that some functions be accessed in thread-safe mode.">clientMutex</a> = PTHREAD_MUTEX_INITIALIZER; <a name="l00213"></a>00213 <a name="l00220"></a><a class="code" href="winscard__clnt_8c.html#a1db679cbe58b14a3d3ecb915938addba">00220</a> <span class="keyword">static</span> <a class="code" href="structpubReaderStatesList.html" title="Define an exported public reader state structure so each application gets instant...">PREADER_STATE</a> <a class="code" href="winscard__clnt_8c.html#a1db679cbe58b14a3d3ecb915938addba" title="Pointers to a memory mapped area used to read status information about the readers...">readerStates</a>[<a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>]; <a name="l00221"></a>00221 <a name="l00222"></a><a class="code" href="winscard__clnt_8c.html#add194ea1e5a4e8e92533a807b1b2d1ff">00222</a> PCSC_API <a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">SCARD_IO_REQUEST</a> <a class="code" href="pcsclite_8h.html#abe3a45e274a34ac64e58aa182830ab8d" title="Protocol Control Information for T=0.">g_rgSCardT0Pci</a> = { <a class="code" href="pcsclite_8h.html#a4fe95267c322c3bf35f30fab6b25526c" title="T=0 active protocol.">SCARD_PROTOCOL_T0</a>, 8 }; <a name="l00223"></a><a class="code" href="winscard__clnt_8c.html#a1ea1ee5a3fa301c87f05a18e99fcd871">00223</a> PCSC_API <a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">SCARD_IO_REQUEST</a> <a class="code" href="pcsclite_8h.html#a8e122be2c6b100398fa06abb6e470d26" title="Protocol Control Information for T=1.">g_rgSCardT1Pci</a> = { <a class="code" href="pcsclite_8h.html#a3c09cd155e07044f857130c183d64f03" title="T=1 active protocol.">SCARD_PROTOCOL_T1</a>, 8 }; <a name="l00224"></a><a class="code" href="winscard__clnt_8c.html#acadf43275ed54ac6ab7f380ade2eaf9d">00224</a> PCSC_API <a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">SCARD_IO_REQUEST</a> <a class="code" href="pcsclite_8h.html#ae4c28993abd5a1a7ad77aaadfc92281d" title="Protocol Control Information for raw access.">g_rgSCardRawPci</a> = { <a class="code" href="pcsclite_8h.html#ab58a85ece18f4217fe5372981231d195" title="Raw active protocol.">SCARD_PROTOCOL_RAW</a>, 8 }; <a name="l00227"></a>00227 <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#ac75190d70d571bca9915bef60491534a" title="Functions for managing instances of SCardEstablishContext() These functions keep...">SCardAddContext</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a>, DWORD); <a name="l00228"></a>00228 <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a>); <a name="l00229"></a>00229 <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a64c964f90285e8409a0d41d43bb05348" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndiceTH</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a>); <a name="l00230"></a>00230 <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a7e3dc878020f1e5ccdae1a6914abd3b0" title="Removes an Application Context from a control vector.">SCardRemoveContext</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a>); <a name="l00231"></a>00231 <span class="keyword">static</span> LONG SCardCleanContext(LONG indice); <a name="l00232"></a>00232 <a name="l00233"></a>00233 <span class="keyword">static</span> LONG SCardAddHandle(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a>, DWORD, LPCSTR); <a name="l00234"></a>00234 <span class="keyword">static</span> LONG SCardGetIndicesFromHandle(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a>, <span class="comment">/*@out@*/</span> PDWORD, <a name="l00235"></a>00235 <span class="comment">/*@out@*/</span> PDWORD); <a name="l00236"></a>00236 <span class="keyword">static</span> LONG SCardGetIndicesFromHandleTH(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a>, <span class="comment">/*@out@*/</span> PDWORD, <a name="l00237"></a>00237 <span class="comment">/*@out@*/</span> PDWORD); <a name="l00238"></a>00238 <span class="keyword">static</span> LONG SCardRemoveHandle(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a>); <a name="l00239"></a>00239 <a name="l00240"></a>00240 <span class="keyword">static</span> LONG SCardGetSetAttrib(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, <span class="keywordtype">int</span> command, DWORD dwAttrId, <a name="l00241"></a>00241 LPBYTE pbAttr, LPDWORD pcbAttrLen); <a name="l00242"></a>00242 <a name="l00243"></a>00243 <span class="keywordtype">void</span> DESTRUCTOR <a class="code" href="winscard__clnt_8c.html#a37765ea543e030fb158a9d6b8a7762f8" title="Free resources allocated by the library.">SCardUnload</a>(<span class="keywordtype">void</span>); <a name="l00244"></a>00244 <a name="l00245"></a>00245 <span class="comment">/*</span> <a name="l00246"></a>00246 <span class="comment"> * Thread safety functions</span> <a name="l00247"></a>00247 <span class="comment"> */</span> <a name="l00254"></a><a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe">00254</a> <span class="keyword">inline</span> <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe" title="This function locks a mutex so another thread must wait to use this function.">SCardLockThread</a>(<span class="keywordtype">void</span>) <a name="l00255"></a>00255 { <a name="l00256"></a>00256 <span class="keywordflow">return</span> SYS_MutexLock(&clientMutex); <a name="l00257"></a>00257 } <a name="l00258"></a>00258 <a name="l00264"></a><a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1">00264</a> <span class="keyword">inline</span> <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1" title="This function unlocks a mutex so another thread may use the client.">SCardUnlockThread</a>(<span class="keywordtype">void</span>) <a name="l00265"></a>00265 { <a name="l00266"></a>00266 <span class="keywordflow">return</span> SYS_MutexUnLock(&clientMutex); <a name="l00267"></a>00267 } <a name="l00268"></a>00268 <a name="l00269"></a>00269 <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#aa86f1a8ccfbdbe7c64eea5219c7639e6" title="Creates a communication context to the PC/SC Resource Manager.">SCardEstablishContextTH</a>(DWORD, LPCVOID, LPCVOID, <a name="l00270"></a>00270 <span class="comment">/*@out@*/</span> LPSCARDCONTEXT); <a name="l00271"></a>00271 <a name="l00305"></a><a class="code" href="group__API.html#gaa1b8970169fd4883a6dc4a8f43f19b67">00305</a> LONG <a class="code" href="group__API.html#gaa1b8970169fd4883a6dc4a8f43f19b67" title="Creates an Application Context for a client.">SCardEstablishContext</a>(DWORD dwScope, LPCVOID pvReserved1, <a name="l00306"></a>00306 LPCVOID pvReserved2, LPSCARDCONTEXT phContext) <a name="l00307"></a>00307 { <a name="l00308"></a>00308 LONG rv; <a name="l00309"></a>00309 <a name="l00310"></a>00310 PROFILE_START <a name="l00311"></a>00311 <a name="l00312"></a>00312 <span class="comment">/* Check if the server is running */</span> <a name="l00313"></a>00313 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l00314"></a>00314 <span class="keywordflow">if</span> (<a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a> == rv) <a name="l00315"></a>00315 <span class="comment">/* we reconnected to a daemon or we got called from a forked child */</span> <a name="l00316"></a>00316 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l00317"></a>00317 <a name="l00318"></a>00318 <span class="keywordflow">if</span> (rv != <a class="code" href="pcsclite_8h.html#a4a3c56f69570971d366642a563b34a75" title="error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx">SCARD_S_SUCCESS</a>) <a name="l00319"></a>00319 <span class="keywordflow">return</span> rv; <a name="l00320"></a>00320 <a name="l00321"></a>00321 (void)<a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe" title="This function locks a mutex so another thread must wait to use this function.">SCardLockThread</a>(); <a name="l00322"></a>00322 rv = <a class="code" href="winscard__clnt_8c.html#aa86f1a8ccfbdbe7c64eea5219c7639e6" title="Creates a communication context to the PC/SC Resource Manager.">SCardEstablishContextTH</a>(dwScope, pvReserved1, <a name="l00323"></a>00323 pvReserved2, phContext); <a name="l00324"></a>00324 (void)<a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1" title="This function unlocks a mutex so another thread may use the client.">SCardUnlockThread</a>(); <a name="l00325"></a>00325 <a name="l00326"></a>00326 PROFILE_END(rv) <a name="l00327"></a>00327 <a name="l00328"></a>00328 <span class="keywordflow">return</span> rv; <a name="l00329"></a>00329 } <a name="l00330"></a>00330 <a name="l00357"></a><a class="code" href="winscard__clnt_8c.html#aa86f1a8ccfbdbe7c64eea5219c7639e6">00357</a> <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#aa86f1a8ccfbdbe7c64eea5219c7639e6" title="Creates a communication context to the PC/SC Resource Manager.">SCardEstablishContextTH</a>(DWORD dwScope, <a name="l00358"></a>00358 <span class="comment">/*@unused@*/</span> LPCVOID pvReserved1, <a name="l00359"></a>00359 <span class="comment">/*@unused@*/</span> LPCVOID pvReserved2, LPSCARDCONTEXT phContext) <a name="l00360"></a>00360 { <a name="l00361"></a>00361 LONG rv; <a name="l00362"></a>00362 <span class="keywordtype">int</span> i; <a name="l00363"></a>00363 <a class="code" href="structestablish__struct.html" title="Information contained in SCARD_ESTABLISH_CONTEXT Messages.">establish_struct</a> scEstablishStruct; <a name="l00364"></a>00364 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l00365"></a>00365 uint32_t dwClientID = 0; <a name="l00366"></a>00366 <a name="l00367"></a>00367 (void)pvReserved1; <a name="l00368"></a>00368 (void)pvReserved2; <a name="l00369"></a>00369 <span class="keywordflow">if</span> (phContext == NULL) <a name="l00370"></a>00370 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l00371"></a>00371 <span class="keywordflow">else</span> <a name="l00372"></a>00372 *phContext = 0; <a name="l00373"></a>00373 <a name="l00374"></a>00374 <span class="comment">/*</span> <a name="l00375"></a>00375 <span class="comment"> * Do this only once:</span> <a name="l00376"></a>00376 <span class="comment"> * - Initialize debug of need.</span> <a name="l00377"></a>00377 <span class="comment"> * - Set up the memory mapped structures for reader states.</span> <a name="l00378"></a>00378 <span class="comment"> * - Allocate each reader structure.</span> <a name="l00379"></a>00379 <span class="comment"> * - Initialize context struct.</span> <a name="l00380"></a>00380 <span class="comment"> */</span> <a name="l00381"></a>00381 <span class="keywordflow">if</span> (isExecuted == 0) <a name="l00382"></a>00382 { <a name="l00383"></a>00383 <span class="keywordtype">int</span> pageSize; <a name="l00384"></a>00384 <a name="l00385"></a>00385 <span class="comment">/*</span> <a name="l00386"></a>00386 <span class="comment"> * Do any system initilization here</span> <a name="l00387"></a>00387 <span class="comment"> */</span> <a name="l00388"></a>00388 (void)<a class="code" href="sys__generic_8h.html#ad156e3731bd5de323088b202e9cb0188" title="Make system wide initialization.">SYS_Initialize</a>(); <a name="l00389"></a>00389 <a name="l00390"></a>00390 <span class="comment">/*</span> <a name="l00391"></a>00391 <span class="comment"> * Set up the memory mapped reader stats structures</span> <a name="l00392"></a>00392 <span class="comment"> */</span> <a name="l00393"></a>00393 mapAddr = <a class="code" href="sys__generic_8h.html#a83df5dae709347018a9183e6c4cb7207" title="Opens/creates a file.">SYS_OpenFile</a>(PCSCLITE_PUBSHM_FILE, O_RDONLY, 0); <a name="l00394"></a>00394 <span class="keywordflow">if</span> (mapAddr < 0) <a name="l00395"></a>00395 { <a name="l00396"></a>00396 Log3(PCSC_LOG_CRITICAL, <span class="stringliteral">"Cannot open public shared file %s: %s"</span>, <a name="l00397"></a>00397 PCSCLITE_PUBSHM_FILE, strerror(errno)); <a name="l00398"></a>00398 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l00399"></a>00399 } <a name="l00400"></a>00400 <a name="l00401"></a>00401 <span class="comment">/* close on exec so that child processes do not inherits the file</span> <a name="l00402"></a>00402 <span class="comment"> * descriptor. The child process will call SCardEstablishContext()</span> <a name="l00403"></a>00403 <span class="comment"> * if needed. */</span> <a name="l00404"></a>00404 (void)fcntl(mapAddr, F_SETFD, FD_CLOEXEC); <a name="l00405"></a>00405 <a name="l00406"></a>00406 pageSize = <a class="code" href="sys__generic_8h.html#a85ac6c80e5212b00bb15a8481657e983" title="Gets the memory page size.">SYS_GetPageSize</a>(); <a name="l00407"></a>00407 <a name="l00408"></a>00408 <span class="comment">/*</span> <a name="l00409"></a>00409 <span class="comment"> * Allocate each reader structure in the memory map</span> <a name="l00410"></a>00410 <span class="comment"> */</span> <a name="l00411"></a>00411 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l00412"></a>00412 { <a name="l00413"></a>00413 readerStates[i] = <a name="l00414"></a>00414 (<a class="code" href="structpubReaderStatesList.html" title="Define an exported public reader state structure so each application gets instant...">PREADER_STATE</a>)<a class="code" href="sys__generic_8h.html#aec318ae5b72ec6d2ead5009940d6e79d" title="Map the file iFid in memory only for reading.">SYS_PublicMemoryMap</a>(<span class="keyword">sizeof</span>(<a class="code" href="structpubReaderStatesList.html" title="Define an exported public reader state structure so each application gets instant...">READER_STATE</a>), <a name="l00415"></a>00415 mapAddr, (i * pageSize)); <a name="l00416"></a>00416 <span class="keywordflow">if</span> (readerStates[i] == NULL) <a name="l00417"></a>00417 { <a name="l00418"></a>00418 Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">"Cannot public memory map: %s"</span>, <a name="l00419"></a>00419 strerror(errno)); <a name="l00420"></a>00420 (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(mapAddr); <span class="comment">/* Close the memory map file */</span> <a name="l00421"></a>00421 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a081a564acaf166f74592906f7dff2d86" title="An internal consistency check failed.">SCARD_F_INTERNAL_ERROR</a>; <a name="l00422"></a>00422 } <a name="l00423"></a>00423 } <a name="l00424"></a>00424 <a name="l00425"></a>00425 <span class="comment">/*</span> <a name="l00426"></a>00426 <span class="comment"> * Initializes the application contexts and all channels for each one</span> <a name="l00427"></a>00427 <span class="comment"> */</span> <a name="l00428"></a>00428 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcscd_8h.html#a6a6f002ba5ba58accdf202f14cc10563" title="Maximum contexts by application.">PCSCLITE_MAX_APPLICATION_CONTEXTS</a>; i++) <a name="l00429"></a>00429 { <a name="l00430"></a>00430 <span class="keywordtype">int</span> j; <a name="l00431"></a>00431 <a name="l00432"></a>00432 <span class="comment">/*</span> <a name="l00433"></a>00433 <span class="comment"> * Initially set the context struct to zero</span> <a name="l00434"></a>00434 <span class="comment"> */</span> <a name="l00435"></a>00435 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].<a class="code" href="struct__psContextMap.html#a4e3f21f7252b71833af88ba9f2864577" title="Client Connection ID.">dwClientID</a> = 0; <a name="l00436"></a>00436 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].<a class="code" href="struct__psContextMap.html#a4171c839145c22f7594818304bf4e7a9" title="Application Context ID.">hContext</a> = 0; <a name="l00437"></a>00437 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].contextBlockStatus = <a class="code" href="pcscd_8h.html#a2100023490c145dd638a909920e9949b" title="Normal resume.">BLOCK_STATUS_RESUME</a>; <a name="l00438"></a>00438 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].<a class="code" href="struct__psContextMap.html#af46cea0e5161cce9a32f83a8e1303521" title="Mutex for this context.">mMutex</a> = NULL; <a name="l00439"></a>00439 <a name="l00440"></a>00440 <span class="keywordflow">for</span> (j = 0; j < <a class="code" href="pcscd_8h.html#a35697bcf11218bc1aa5bfe831b360df7" title="Maximum channels on an application context.">PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS</a>; j++) <a name="l00441"></a>00441 { <a name="l00442"></a>00442 <span class="comment">/*</span> <a name="l00443"></a>00443 <span class="comment"> * Initially set the hcard structs to zero</span> <a name="l00444"></a>00444 <span class="comment"> */</span> <a name="l00445"></a>00445 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].psChannelMap[j].hCard = 0; <a name="l00446"></a>00446 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].psChannelMap[j].readerName = NULL; <a name="l00447"></a>00447 } <a name="l00448"></a>00448 } <a name="l00449"></a>00449 <a name="l00450"></a>00450 } <a name="l00451"></a>00451 <a name="l00452"></a>00452 <span class="comment">/*</span> <a name="l00453"></a>00453 <span class="comment"> * Is there a free slot for this connection ?</span> <a name="l00454"></a>00454 <span class="comment"> */</span> <a name="l00455"></a>00455 <a name="l00456"></a>00456 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcscd_8h.html#a6a6f002ba5ba58accdf202f14cc10563" title="Maximum contexts by application.">PCSCLITE_MAX_APPLICATION_CONTEXTS</a>; i++) <a name="l00457"></a>00457 { <a name="l00458"></a>00458 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].dwClientID == 0) <a name="l00459"></a>00459 <span class="keywordflow">break</span>; <a name="l00460"></a>00460 } <a name="l00461"></a>00461 <a name="l00462"></a>00462 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_APPLICATION_CONTEXTS) <a name="l00463"></a>00463 { <a name="l00464"></a>00464 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l00465"></a>00465 } <a name="l00466"></a>00466 <a name="l00467"></a>00467 <span class="comment">/* Establishes a connection to the server */</span> <a name="l00468"></a>00468 <span class="keywordflow">if</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>(&dwClientID) != 0) <a name="l00469"></a>00469 { <a name="l00470"></a>00470 (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(mapAddr); <a name="l00471"></a>00471 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l00472"></a>00472 } <a name="l00473"></a>00473 <a name="l00474"></a>00474 { <span class="comment">/* exchange client/server protocol versions */</span> <a name="l00475"></a>00475 <a class="code" href="structversion__struct.html" title="Information transmitted in CMD_VERSION Messages.">version_struct</a> *veStr; <a name="l00476"></a>00476 <a name="l00477"></a>00477 memset(&msgStruct, 0, <span class="keyword">sizeof</span>(msgStruct)); <a name="l00478"></a>00478 msgStruct.mtype = <a class="code" href="winscard__msg_8h.html#ad8fb188696ea8f9b1879b9eb7ccc2a36a775afaef84c85d8173a20debb1a9e2ef" title="version of the IPC">CMD_VERSION</a>; <a name="l00479"></a>00479 msgStruct.<a class="code" href="structrxSharedSegment.html#ae137824545088a41344fde36a04e55ac" title="one of the pcsc_adm_commands ">user_id</a> = SYS_GetUID(); <a name="l00480"></a>00480 msgStruct.group_id = SYS_GetGID(); <a name="l00481"></a>00481 msgStruct.command = 0; <a name="l00482"></a>00482 msgStruct.<a class="code" href="structrxSharedSegment.html#aa5d2946fef4fdab83e295779e0c2b171" title="one of the pcsc_msg_commands ">date</a> = time(NULL); <a name="l00483"></a>00483 <a name="l00484"></a>00484 veStr = &msgStruct.veStr; <a name="l00485"></a>00485 veStr-><a class="code" href="structversion__struct.html#a32863448345f9226766e08966d89b726" title="IPC major PROTOCOL_VERSION_MAJOR.">major</a> = <a class="code" href="winscard__msg_8h.html#a2ec4920ff3b207d71c2ae86d807dbdd7" title="Major version of the current message protocol.">PROTOCOL_VERSION_MAJOR</a>; <a name="l00486"></a>00486 veStr-><a class="code" href="structversion__struct.html#a5eba3ab76bf8a5f0b97cd574b487b3d0" title="IPC minor PROTOCOL_VERSION_MINOR.">minor</a> = <a class="code" href="winscard__msg_8h.html#a9ff5cd412ba2c8563fa89754cf534d41" title="Minor version of the current message protocol.">PROTOCOL_VERSION_MINOR</a>; <a name="l00487"></a>00487 <a name="l00488"></a>00488 <span class="keywordflow">if</span> (-1 == <a class="code" href="winscard__msg_8c.html#ac1bde0241da918d1a346c0dca681dd78" title="Sends a menssage from client to server or vice-versa.">SHMMessageSend</a>(&msgStruct, <span class="keyword">sizeof</span>(msgStruct), dwClientID, <a name="l00489"></a>00489 <a class="code" href="pcscd_8h.html#ac31b0d05c817172c1ed48c885b57d1d8" title="Attempts to reach sv.">PCSCLITE_MCLIENT_ATTEMPTS</a>)) <a name="l00490"></a>00490 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l00491"></a>00491 <a name="l00492"></a>00492 <span class="comment">/*</span> <a name="l00493"></a>00493 <span class="comment"> * Read a message from the server</span> <a name="l00494"></a>00494 <span class="comment"> */</span> <a name="l00495"></a>00495 <span class="keywordflow">if</span> (-1 == <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, <a name="l00496"></a>00496 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>)) <a name="l00497"></a>00497 { <a name="l00498"></a>00498 Log1(PCSC_LOG_CRITICAL, <span class="stringliteral">"Your pcscd is too old and does not support CMD_VERSION"</span>); <a name="l00499"></a>00499 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l00500"></a>00500 } <a name="l00501"></a>00501 <a name="l00502"></a>00502 Log3(PCSC_LOG_INFO, <span class="stringliteral">"Server is protocol version %d:%d"</span>, <a name="l00503"></a>00503 veStr-><a class="code" href="structversion__struct.html#a32863448345f9226766e08966d89b726" title="IPC major PROTOCOL_VERSION_MAJOR.">major</a>, veStr-><a class="code" href="structversion__struct.html#a5eba3ab76bf8a5f0b97cd574b487b3d0" title="IPC minor PROTOCOL_VERSION_MINOR.">minor</a>); <a name="l00504"></a>00504 <a name="l00505"></a>00505 <span class="keywordflow">if</span> (veStr->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="l00506"></a>00506 <span class="keywordflow">return</span> veStr->rv; <a name="l00507"></a>00507 <a name="l00508"></a>00508 isExecuted = 1; <a name="l00509"></a>00509 } <a name="l00510"></a>00510 <a name="l00511"></a>00511 again: <a name="l00512"></a>00512 <span class="comment">/*</span> <a name="l00513"></a>00513 <span class="comment"> * Try to establish an Application Context with the server</span> <a name="l00514"></a>00514 <span class="comment"> */</span> <a name="l00515"></a>00515 scEstablishStruct.dwScope = dwScope; <a name="l00516"></a>00516 scEstablishStruct.hContext = 0; <a name="l00517"></a>00517 scEstablishStruct.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="l00518"></a>00518 <a name="l00519"></a>00519 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dcaf90d9882a83562f678f57ce8de9a51a1" title="used by SCardEstablishContext()">SCARD_ESTABLISH_CONTEXT</a>, dwClientID, <a name="l00520"></a>00520 <span class="keyword">sizeof</span>(scEstablishStruct), <a class="code" href="pcscd_8h.html#ac31b0d05c817172c1ed48c885b57d1d8" title="Attempts to reach sv.">PCSCLITE_MCLIENT_ATTEMPTS</a>, <a name="l00521"></a>00521 (<span class="keywordtype">void</span> *) &scEstablishStruct); <a name="l00522"></a>00522 <a name="l00523"></a>00523 <span class="keywordflow">if</span> (rv == -1) <a name="l00524"></a>00524 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l00525"></a>00525 <a name="l00526"></a>00526 <span class="comment">/*</span> <a name="l00527"></a>00527 <span class="comment"> * Read the response from the server</span> <a name="l00528"></a>00528 <span class="comment"> */</span> <a name="l00529"></a>00529 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, dwClientID, <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l00530"></a>00530 <a name="l00531"></a>00531 <span class="keywordflow">if</span> (rv == -1) <a name="l00532"></a>00532 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l00533"></a>00533 <a name="l00534"></a>00534 memcpy(&scEstablishStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scEstablishStruct)); <a name="l00535"></a>00535 <a name="l00536"></a>00536 <span class="keywordflow">if</span> (scEstablishStruct.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="l00537"></a>00537 <span class="keywordflow">return</span> scEstablishStruct.rv; <a name="l00538"></a>00538 <a name="l00539"></a>00539 <span class="comment">/* check we do not reuse an existing phContext */</span> <a name="l00540"></a>00540 <span class="keywordflow">if</span> (-1 != <a class="code" href="winscard__clnt_8c.html#a64c964f90285e8409a0d41d43bb05348" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndiceTH</a>(scEstablishStruct.hContext)) <a name="l00541"></a>00541 <span class="comment">/* we do not need to release the allocated context since</span> <a name="l00542"></a>00542 <span class="comment"> * SCardReleaseContext() does nothing on the server side */</span> <a name="l00543"></a>00543 <span class="keywordflow">goto</span> again; <a name="l00544"></a>00544 <a name="l00545"></a>00545 *phContext = scEstablishStruct.hContext; <a name="l00546"></a>00546 <a name="l00547"></a>00547 <span class="comment">/*</span> <a name="l00548"></a>00548 <span class="comment"> * Allocate the new hContext - if allocator full return an error</span> <a name="l00549"></a>00549 <span class="comment"> */</span> <a name="l00550"></a>00550 rv = <a class="code" href="winscard__clnt_8c.html#ac75190d70d571bca9915bef60491534a" title="Functions for managing instances of SCardEstablishContext() These functions keep...">SCardAddContext</a>(*phContext, dwClientID); <a name="l00551"></a>00551 <a name="l00552"></a>00552 <span class="keywordflow">return</span> rv; <a name="l00553"></a>00553 } <a name="l00554"></a>00554 <a name="l00576"></a><a class="code" href="group__API.html#ga6aabcba7744c5c9419fdd6404f73a934">00576</a> LONG <a class="code" href="group__API.html#ga6aabcba7744c5c9419fdd6404f73a934" title="This function destroys a communication context to the PC/SC Resource Manager.">SCardReleaseContext</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext) <a name="l00577"></a>00577 { <a name="l00578"></a>00578 LONG rv; <a name="l00579"></a>00579 <a class="code" href="structrelease__struct.html" title="Information contained in SCARD_RELEASE_CONTEXT Messages.">release_struct</a> scReleaseStruct; <a name="l00580"></a>00580 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l00581"></a>00581 LONG dwContextIndex; <a name="l00582"></a>00582 <a name="l00583"></a>00583 PROFILE_START <a name="l00584"></a>00584 <a name="l00585"></a>00585 <span class="comment">/*</span> <a name="l00586"></a>00586 <span class="comment"> * Make sure this context has been opened</span> <a name="l00587"></a>00587 <span class="comment"> * and get dwContextIndex</span> <a name="l00588"></a>00588 <span class="comment"> */</span> <a name="l00589"></a>00589 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l00590"></a>00590 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l00591"></a>00591 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l00592"></a>00592 <a name="l00593"></a>00593 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l00594"></a>00594 <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="l00595"></a>00595 { <a name="l00596"></a>00596 <span class="comment">/*</span> <a name="l00597"></a>00597 <span class="comment"> * Remove the local context from the stack</span> <a name="l00598"></a>00598 <span class="comment"> */</span> <a name="l00599"></a>00599 (void)<a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe" title="This function locks a mutex so another thread must wait to use this function.">SCardLockThread</a>(); <a name="l00600"></a>00600 (void)<a class="code" href="winscard__clnt_8c.html#a7e3dc878020f1e5ccdae1a6914abd3b0" title="Removes an Application Context from a control vector.">SCardRemoveContext</a>(hContext); <a name="l00601"></a>00601 (void)<a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1" title="This function unlocks a mutex so another thread may use the client.">SCardUnlockThread</a>(); <a name="l00602"></a>00602 <a name="l00603"></a>00603 <span class="keywordflow">return</span> rv; <a name="l00604"></a>00604 } <a name="l00605"></a>00605 <a name="l00606"></a>00606 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00607"></a>00607 <a name="l00608"></a>00608 <span class="comment">/* check the context is still opened */</span> <a name="l00609"></a>00609 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l00610"></a>00610 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l00611"></a>00611 <span class="comment">/* the context is now invalid</span> <a name="l00612"></a>00612 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l00613"></a>00613 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l00614"></a>00614 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l00615"></a>00615 <a name="l00616"></a>00616 scReleaseStruct.hContext = hContext; <a name="l00617"></a>00617 scReleaseStruct.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="l00618"></a>00618 <a name="l00619"></a>00619 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca072877189b15a07bbc7918a7fdd2a573" title="used by SCardReleaseContext()">SCARD_RELEASE_CONTEXT</a>, <a name="l00620"></a>00620 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l00621"></a>00621 <span class="keyword">sizeof</span>(scReleaseStruct), <a name="l00622"></a>00622 <a class="code" href="pcscd_8h.html#ac31b0d05c817172c1ed48c885b57d1d8" title="Attempts to reach sv.">PCSCLITE_MCLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scReleaseStruct); <a name="l00623"></a>00623 <a name="l00624"></a>00624 <span class="keywordflow">if</span> (rv == -1) <a name="l00625"></a>00625 { <a name="l00626"></a>00626 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00627"></a>00627 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l00628"></a>00628 } <a name="l00629"></a>00629 <a name="l00630"></a>00630 <span class="comment">/*</span> <a name="l00631"></a>00631 <span class="comment"> * Read a message from the server</span> <a name="l00632"></a>00632 <span class="comment"> */</span> <a name="l00633"></a>00633 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l00634"></a>00634 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l00635"></a>00635 memcpy(&scReleaseStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scReleaseStruct)); <a name="l00636"></a>00636 <a name="l00637"></a>00637 <span class="keywordflow">if</span> (rv == -1) <a name="l00638"></a>00638 { <a name="l00639"></a>00639 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00640"></a>00640 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l00641"></a>00641 } <a name="l00642"></a>00642 <a name="l00643"></a>00643 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00644"></a>00644 <a name="l00645"></a>00645 <span class="comment">/*</span> <a name="l00646"></a>00646 <span class="comment"> * Remove the local context from the stack</span> <a name="l00647"></a>00647 <span class="comment"> */</span> <a name="l00648"></a>00648 (void)<a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe" title="This function locks a mutex so another thread must wait to use this function.">SCardLockThread</a>(); <a name="l00649"></a>00649 (void)<a class="code" href="winscard__clnt_8c.html#a7e3dc878020f1e5ccdae1a6914abd3b0" title="Removes an Application Context from a control vector.">SCardRemoveContext</a>(hContext); <a name="l00650"></a>00650 (void)<a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1" title="This function unlocks a mutex so another thread may use the client.">SCardUnlockThread</a>(); <a name="l00651"></a>00651 <a name="l00652"></a>00652 PROFILE_END(scReleaseStruct.rv) <a name="l00653"></a>00653 <a name="l00654"></a>00654 <span class="keywordflow">return</span> scReleaseStruct.rv; <a name="l00655"></a>00655 } <a name="l00656"></a>00656 <a name="l00672"></a><a class="code" href="group__API.html#ga812e35ead06d4690fa96aecf371c6255">00672</a> LONG <a class="code" href="group__API.html#ga812e35ead06d4690fa96aecf371c6255" title="The function does not do anything except returning SCARD_S_SUCCESS.">SCardSetTimeout</a>(<span class="comment">/*@unused@*/</span> <a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, <a name="l00673"></a>00673 <span class="comment">/*@unused@*/</span> DWORD dwTimeout) <a name="l00674"></a>00674 { <a name="l00675"></a>00675 <span class="comment">/*</span> <a name="l00676"></a>00676 <span class="comment"> * Deprecated</span> <a name="l00677"></a>00677 <span class="comment"> */</span> <a name="l00678"></a>00678 (void)hContext; <a name="l00679"></a>00679 (void)dwTimeout; <a name="l00680"></a>00680 <span class="keywordflow">return</span> <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="l00681"></a>00681 } <a name="l00682"></a>00682 <a name="l00734"></a><a class="code" href="group__API.html#ga4e515829752e0a8dbc4d630696a8d6a5">00734</a> LONG <a class="code" href="group__API.html#ga4e515829752e0a8dbc4d630696a8d6a5" title="This function establishes a connection to the reader specified in szReader.">SCardConnect</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, LPCSTR szReader, <a name="l00735"></a>00735 DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, <a name="l00736"></a>00736 LPDWORD pdwActiveProtocol) <a name="l00737"></a>00737 { <a name="l00738"></a>00738 LONG rv; <a name="l00739"></a>00739 <a class="code" href="structconnect__struct.html" title="contained in SCARD_CONNECT Messages.">connect_struct</a> scConnectStruct; <a name="l00740"></a>00740 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l00741"></a>00741 LONG dwContextIndex; <a name="l00742"></a>00742 <a name="l00743"></a>00743 PROFILE_START <a name="l00744"></a>00744 <a name="l00745"></a>00745 <span class="comment">/*</span> <a name="l00746"></a>00746 <span class="comment"> * Check for NULL parameters</span> <a name="l00747"></a>00747 <span class="comment"> */</span> <a name="l00748"></a>00748 <span class="keywordflow">if</span> (phCard == NULL || pdwActiveProtocol == NULL) <a name="l00749"></a>00749 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l00750"></a>00750 <span class="keywordflow">else</span> <a name="l00751"></a>00751 *phCard = 0; <a name="l00752"></a>00752 <a name="l00753"></a>00753 <span class="keywordflow">if</span> (szReader == NULL) <a name="l00754"></a>00754 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a1bc24e84bfe33ef68be7251e2423190a" title="The specified reader name is not recognized.">SCARD_E_UNKNOWN_READER</a>; <a name="l00755"></a>00755 <a name="l00756"></a>00756 <span class="comment">/*</span> <a name="l00757"></a>00757 <span class="comment"> * Check for uninitialized strings</span> <a name="l00758"></a>00758 <span class="comment"> */</span> <a name="l00759"></a>00759 <span class="keywordflow">if</span> (strlen(szReader) > MAX_READERNAME) <a name="l00760"></a>00760 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a9ece9fd9e68e4f802e16e951f8f2a642" title="One or more of the supplied parameters values could not be properly interpreted.">SCARD_E_INVALID_VALUE</a>; <a name="l00761"></a>00761 <a name="l00762"></a>00762 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l00763"></a>00763 <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="l00764"></a>00764 <span class="keywordflow">return</span> rv; <a name="l00765"></a>00765 <a name="l00766"></a>00766 <span class="comment">/*</span> <a name="l00767"></a>00767 <span class="comment"> * Make sure this context has been opened</span> <a name="l00768"></a>00768 <span class="comment"> */</span> <a name="l00769"></a>00769 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l00770"></a>00770 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l00771"></a>00771 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l00772"></a>00772 <a name="l00773"></a>00773 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00774"></a>00774 <a name="l00775"></a>00775 <span class="comment">/* check the context is still opened */</span> <a name="l00776"></a>00776 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l00777"></a>00777 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l00778"></a>00778 <span class="comment">/* the context is now invalid</span> <a name="l00779"></a>00779 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l00780"></a>00780 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l00781"></a>00781 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l00782"></a>00782 <a name="l00783"></a>00783 strncpy(scConnectStruct.szReader, szReader, MAX_READERNAME); <a name="l00784"></a>00784 <a name="l00785"></a>00785 scConnectStruct.hContext = hContext; <a name="l00786"></a>00786 scConnectStruct.dwShareMode = dwShareMode; <a name="l00787"></a>00787 scConnectStruct.dwPreferredProtocols = dwPreferredProtocols; <a name="l00788"></a>00788 scConnectStruct.hCard = 0; <a name="l00789"></a>00789 scConnectStruct.dwActiveProtocol = 0; <a name="l00790"></a>00790 scConnectStruct.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="l00791"></a>00791 <a name="l00792"></a>00792 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dcae4539f439555e7f577f08de789fd4e2c" title="used by SCardConnect()">SCARD_CONNECT</a>, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l00793"></a>00793 <span class="keyword">sizeof</span>(scConnectStruct), <a name="l00794"></a>00794 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scConnectStruct); <a name="l00795"></a>00795 <a name="l00796"></a>00796 <span class="keywordflow">if</span> (rv == -1) <a name="l00797"></a>00797 { <a name="l00798"></a>00798 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00799"></a>00799 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l00800"></a>00800 } <a name="l00801"></a>00801 <a name="l00802"></a>00802 <span class="comment">/*</span> <a name="l00803"></a>00803 <span class="comment"> * Read a message from the server</span> <a name="l00804"></a>00804 <span class="comment"> */</span> <a name="l00805"></a>00805 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l00806"></a>00806 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l00807"></a>00807 <a name="l00808"></a>00808 memcpy(&scConnectStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scConnectStruct)); <a name="l00809"></a>00809 <a name="l00810"></a>00810 <span class="keywordflow">if</span> (rv == -1) <a name="l00811"></a>00811 { <a name="l00812"></a>00812 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00813"></a>00813 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l00814"></a>00814 } <a name="l00815"></a>00815 <a name="l00816"></a>00816 *phCard = scConnectStruct.hCard; <a name="l00817"></a>00817 *pdwActiveProtocol = scConnectStruct.dwActiveProtocol; <a name="l00818"></a>00818 <a name="l00819"></a>00819 <span class="keywordflow">if</span> (scConnectStruct.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="l00820"></a>00820 { <a name="l00821"></a>00821 <span class="comment">/*</span> <a name="l00822"></a>00822 <span class="comment"> * Keep track of the handle locally</span> <a name="l00823"></a>00823 <span class="comment"> */</span> <a name="l00824"></a>00824 rv = SCardAddHandle(*phCard, dwContextIndex, szReader); <a name="l00825"></a>00825 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00826"></a>00826 <a name="l00827"></a>00827 PROFILE_END(rv) <a name="l00828"></a>00828 <a name="l00829"></a>00829 <span class="keywordflow">return</span> rv; <a name="l00830"></a>00830 } <a name="l00831"></a>00831 <a name="l00832"></a>00832 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00833"></a>00833 <a name="l00834"></a>00834 PROFILE_END(scConnectStruct.rv) <a name="l00835"></a>00835 <a name="l00836"></a>00836 <span class="keywordflow">return</span> scConnectStruct.rv; <a name="l00837"></a>00837 } <a name="l00838"></a>00838 <a name="l00906"></a><a class="code" href="group__API.html#gad5d4393ca8c470112ad9468c44ed8940">00906</a> LONG <a class="code" href="group__API.html#gad5d4393ca8c470112ad9468c44ed8940" title="This function reestablishes a connection to a reader that was previously connected...">SCardReconnect</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, DWORD dwShareMode, <a name="l00907"></a>00907 DWORD dwPreferredProtocols, DWORD dwInitialization, <a name="l00908"></a>00908 LPDWORD pdwActiveProtocol) <a name="l00909"></a>00909 { <a name="l00910"></a>00910 LONG rv; <a name="l00911"></a>00911 <a class="code" href="structreconnect__struct.html" title="contained in SCARD_RECONNECT Messages.">reconnect_struct</a> scReconnectStruct; <a name="l00912"></a>00912 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l00913"></a>00913 <span class="keywordtype">int</span> i; <a name="l00914"></a>00914 DWORD dwContextIndex, dwChannelIndex; <a name="l00915"></a>00915 <a name="l00916"></a>00916 PROFILE_START <a name="l00917"></a>00917 <a name="l00918"></a>00918 <span class="keywordflow">if</span> (pdwActiveProtocol == NULL) <a name="l00919"></a>00919 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l00920"></a>00920 <a name="l00921"></a>00921 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l00922"></a>00922 <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="l00923"></a>00923 <span class="keywordflow">return</span> rv; <a name="l00924"></a>00924 <a name="l00925"></a>00925 <span class="comment">/*</span> <a name="l00926"></a>00926 <span class="comment"> * Make sure this handle has been opened</span> <a name="l00927"></a>00927 <span class="comment"> */</span> <a name="l00928"></a>00928 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l00929"></a>00929 <span class="keywordflow">if</span> (rv == -1) <a name="l00930"></a>00930 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l00931"></a>00931 <a name="l00932"></a>00932 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00933"></a>00933 <a name="l00934"></a>00934 <span class="comment">/* check the handle is still valid */</span> <a name="l00935"></a>00935 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l00936"></a>00936 <span class="keywordflow">if</span> (rv == -1) <a name="l00937"></a>00937 <span class="comment">/* the handle is now invalid</span> <a name="l00938"></a>00938 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l00939"></a>00939 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l00940"></a>00940 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l00941"></a>00941 <a name="l00942"></a>00942 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l00943"></a>00943 { <a name="l00944"></a>00944 <span class="keywordtype">char</span> *r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l00945"></a>00945 <a name="l00946"></a>00946 <span class="comment">/* by default r == NULL */</span> <a name="l00947"></a>00947 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l00948"></a>00948 <span class="keywordflow">break</span>; <a name="l00949"></a>00949 } <a name="l00950"></a>00950 <a name="l00951"></a>00951 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l00952"></a>00952 { <a name="l00953"></a>00953 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00954"></a>00954 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l00955"></a>00955 } <a name="l00956"></a>00956 <a name="l00957"></a>00957 <span class="keywordflow">do</span> <a name="l00958"></a>00958 { <a name="l00959"></a>00959 scReconnectStruct.hCard = hCard; <a name="l00960"></a>00960 scReconnectStruct.dwShareMode = dwShareMode; <a name="l00961"></a>00961 scReconnectStruct.dwPreferredProtocols = dwPreferredProtocols; <a name="l00962"></a>00962 scReconnectStruct.dwInitialization = dwInitialization; <a name="l00963"></a>00963 scReconnectStruct.dwActiveProtocol = *pdwActiveProtocol; <a name="l00964"></a>00964 scReconnectStruct.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="l00965"></a>00965 <a name="l00966"></a>00966 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca8b46439f3998639c1935c51fb984794f" title="used by SCardReconnect()">SCARD_RECONNECT</a>, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l00967"></a>00967 <span class="keyword">sizeof</span>(scReconnectStruct), <a name="l00968"></a>00968 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scReconnectStruct); <a name="l00969"></a>00969 <a name="l00970"></a>00970 <span class="keywordflow">if</span> (rv == -1) <a name="l00971"></a>00971 { <a name="l00972"></a>00972 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00973"></a>00973 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l00974"></a>00974 } <a name="l00975"></a>00975 <a name="l00976"></a>00976 <span class="comment">/*</span> <a name="l00977"></a>00977 <span class="comment"> * Read a message from the server</span> <a name="l00978"></a>00978 <span class="comment"> */</span> <a name="l00979"></a>00979 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l00980"></a>00980 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l00981"></a>00981 <a name="l00982"></a>00982 memcpy(&scReconnectStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scReconnectStruct)); <a name="l00983"></a>00983 <a name="l00984"></a>00984 <span class="keywordflow">if</span> (rv == -1) <a name="l00985"></a>00985 { <a name="l00986"></a>00986 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00987"></a>00987 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l00988"></a>00988 } <a name="l00989"></a>00989 } <span class="keywordflow">while</span> (<a class="code" href="pcsclite_8h.html#a81cd3fc9e7e84c66be2471294152235f" title="The smart card cannot be accessed because of other connections outstanding.">SCARD_E_SHARING_VIOLATION</a> == scReconnectStruct.rv); <a name="l00990"></a>00990 <a name="l00991"></a>00991 *pdwActiveProtocol = scReconnectStruct.dwActiveProtocol; <a name="l00992"></a>00992 <a name="l00993"></a>00993 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l00994"></a>00994 <a name="l00995"></a>00995 PROFILE_END(scReconnectStruct.rv) <a name="l00996"></a>00996 <a name="l00997"></a>00997 <span class="keywordflow">return</span> scReconnectStruct.rv; <a name="l00998"></a>00998 } <a name="l00999"></a>00999 <a name="l01030"></a><a class="code" href="group__API.html#ga4be198045c73ec0deb79e66c0ca1738a">01030</a> LONG <a class="code" href="group__API.html#ga4be198045c73ec0deb79e66c0ca1738a" title="This function terminates a connection made through SCardConnect().">SCardDisconnect</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, DWORD dwDisposition) <a name="l01031"></a>01031 { <a name="l01032"></a>01032 LONG rv; <a name="l01033"></a>01033 <a class="code" href="structdisconnect__struct.html" title="contained in SCARD_DISCONNECT Messages.">disconnect_struct</a> scDisconnectStruct; <a name="l01034"></a>01034 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l01035"></a>01035 DWORD dwContextIndex, dwChannelIndex; <a name="l01036"></a>01036 <a name="l01037"></a>01037 PROFILE_START <a name="l01038"></a>01038 <a name="l01039"></a>01039 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01040"></a>01040 <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="l01041"></a>01041 <span class="keywordflow">return</span> rv; <a name="l01042"></a>01042 <a name="l01043"></a>01043 <span class="comment">/*</span> <a name="l01044"></a>01044 <span class="comment"> * Make sure this handle has been opened</span> <a name="l01045"></a>01045 <span class="comment"> */</span> <a name="l01046"></a>01046 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01047"></a>01047 <span class="keywordflow">if</span> (rv == -1) <a name="l01048"></a>01048 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01049"></a>01049 <a name="l01050"></a>01050 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01051"></a>01051 <a name="l01052"></a>01052 <span class="comment">/* check the handle is still valid */</span> <a name="l01053"></a>01053 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01054"></a>01054 <span class="keywordflow">if</span> (rv == -1) <a name="l01055"></a>01055 <span class="comment">/* the handle is now invalid</span> <a name="l01056"></a>01056 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l01057"></a>01057 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l01058"></a>01058 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01059"></a>01059 <a name="l01060"></a>01060 scDisconnectStruct.hCard = hCard; <a name="l01061"></a>01061 scDisconnectStruct.dwDisposition = dwDisposition; <a name="l01062"></a>01062 scDisconnectStruct.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="l01063"></a>01063 <a name="l01064"></a>01064 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca014966b0829c1dd57df6c62a53c7c9f0" title="used by SCardDisconnect()">SCARD_DISCONNECT</a>, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01065"></a>01065 <span class="keyword">sizeof</span>(scDisconnectStruct), <a name="l01066"></a>01066 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scDisconnectStruct); <a name="l01067"></a>01067 <a name="l01068"></a>01068 <span class="keywordflow">if</span> (rv == -1) <a name="l01069"></a>01069 { <a name="l01070"></a>01070 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01071"></a>01071 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l01072"></a>01072 } <a name="l01073"></a>01073 <a name="l01074"></a>01074 <span class="comment">/*</span> <a name="l01075"></a>01075 <span class="comment"> * Read a message from the server</span> <a name="l01076"></a>01076 <span class="comment"> */</span> <a name="l01077"></a>01077 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01078"></a>01078 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l01079"></a>01079 <a name="l01080"></a>01080 memcpy(&scDisconnectStruct, &msgStruct.data, <a name="l01081"></a>01081 <span class="keyword">sizeof</span>(scDisconnectStruct)); <a name="l01082"></a>01082 <a name="l01083"></a>01083 <span class="keywordflow">if</span> (rv == -1) <a name="l01084"></a>01084 { <a name="l01085"></a>01085 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01086"></a>01086 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l01087"></a>01087 } <a name="l01088"></a>01088 <a name="l01089"></a>01089 (void)SCardRemoveHandle(hCard); <a name="l01090"></a>01090 <a name="l01091"></a>01091 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01092"></a>01092 <a name="l01093"></a>01093 PROFILE_END(scDisconnectStruct.rv) <a name="l01094"></a>01094 <a name="l01095"></a>01095 <span class="keywordflow">return</span> scDisconnectStruct.rv; <a name="l01096"></a>01096 } <a name="l01097"></a>01097 <a name="l01133"></a><a class="code" href="group__API.html#gaddb835dce01a0da1d6ca02d33ee7d861">01133</a> LONG <a class="code" href="group__API.html#gaddb835dce01a0da1d6ca02d33ee7d861" title="This function establishes a temporary exclusive access mode for doing a serie of...">SCardBeginTransaction</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard) <a name="l01134"></a>01134 { <a name="l01135"></a>01135 <a name="l01136"></a>01136 LONG rv; <a name="l01137"></a>01137 <a class="code" href="structbegin__struct.html" title="contained in SCARD_BEGIN_TRANSACTION Messages.">begin_struct</a> scBeginStruct; <a name="l01138"></a>01138 <span class="keywordtype">int</span> i; <a name="l01139"></a>01139 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l01140"></a>01140 DWORD dwContextIndex, dwChannelIndex; <a name="l01141"></a>01141 <a name="l01142"></a>01142 PROFILE_START <a name="l01143"></a>01143 <a name="l01144"></a>01144 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01145"></a>01145 <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="l01146"></a>01146 <span class="keywordflow">return</span> rv; <a name="l01147"></a>01147 <a name="l01148"></a>01148 <span class="comment">/*</span> <a name="l01149"></a>01149 <span class="comment"> * Make sure this handle has been opened</span> <a name="l01150"></a>01150 <span class="comment"> */</span> <a name="l01151"></a>01151 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01152"></a>01152 <span class="keywordflow">if</span> (rv == -1) <a name="l01153"></a>01153 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01154"></a>01154 <a name="l01155"></a>01155 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01156"></a>01156 <a name="l01157"></a>01157 <span class="comment">/* check the handle is still valid */</span> <a name="l01158"></a>01158 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01159"></a>01159 <span class="keywordflow">if</span> (rv == -1) <a name="l01160"></a>01160 <span class="comment">/* the handle is now invalid</span> <a name="l01161"></a>01161 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l01162"></a>01162 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l01163"></a>01163 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01164"></a>01164 <a name="l01165"></a>01165 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l01166"></a>01166 { <a name="l01167"></a>01167 <span class="keywordtype">char</span> *r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l01168"></a>01168 <a name="l01169"></a>01169 <span class="comment">/* by default r == NULL */</span> <a name="l01170"></a>01170 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l01171"></a>01171 <span class="keywordflow">break</span>; <a name="l01172"></a>01172 } <a name="l01173"></a>01173 <a name="l01174"></a>01174 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l01175"></a>01175 { <a name="l01176"></a>01176 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01177"></a>01177 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l01178"></a>01178 } <a name="l01179"></a>01179 <a name="l01180"></a>01180 scBeginStruct.hCard = hCard; <a name="l01181"></a>01181 scBeginStruct.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="l01182"></a>01182 <a name="l01183"></a>01183 <span class="comment">/*</span> <a name="l01184"></a>01184 <span class="comment"> * Query the server every so often until the sharing violation ends</span> <a name="l01185"></a>01185 <span class="comment"> * and then hold the lock for yourself.</span> <a name="l01186"></a>01186 <span class="comment"> */</span> <a name="l01187"></a>01187 <a name="l01188"></a>01188 <span class="keywordflow">do</span> <a name="l01189"></a>01189 { <a name="l01190"></a>01190 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dcaa49e6ed0bf4f1b9fe85c23699fdac94c" title="used by SCardBeginTransaction()">SCARD_BEGIN_TRANSACTION</a>, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01191"></a>01191 <span class="keyword">sizeof</span>(scBeginStruct), <a name="l01192"></a>01192 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scBeginStruct); <a name="l01193"></a>01193 <a name="l01194"></a>01194 <span class="keywordflow">if</span> (rv == -1) <a name="l01195"></a>01195 { <a name="l01196"></a>01196 <a name="l01197"></a>01197 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01198"></a>01198 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l01199"></a>01199 } <a name="l01200"></a>01200 <a name="l01201"></a>01201 <span class="comment">/*</span> <a name="l01202"></a>01202 <span class="comment"> * Read a message from the server</span> <a name="l01203"></a>01203 <span class="comment"> */</span> <a name="l01204"></a>01204 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01205"></a>01205 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l01206"></a>01206 <a name="l01207"></a>01207 memcpy(&scBeginStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scBeginStruct)); <a name="l01208"></a>01208 <a name="l01209"></a>01209 <span class="keywordflow">if</span> (rv == -1) <a name="l01210"></a>01210 { <a name="l01211"></a>01211 <a name="l01212"></a>01212 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01213"></a>01213 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l01214"></a>01214 } <a name="l01215"></a>01215 <a name="l01216"></a>01216 } <a name="l01217"></a>01217 <span class="keywordflow">while</span> (scBeginStruct.rv == <a class="code" href="pcsclite_8h.html#a81cd3fc9e7e84c66be2471294152235f" title="The smart card cannot be accessed because of other connections outstanding.">SCARD_E_SHARING_VIOLATION</a>); <a name="l01218"></a>01218 <a name="l01219"></a>01219 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01220"></a>01220 <a name="l01221"></a>01221 PROFILE_END(scBeginStruct.rv); <a name="l01222"></a>01222 <a name="l01223"></a>01223 <span class="keywordflow">return</span> scBeginStruct.rv; <a name="l01224"></a>01224 } <a name="l01225"></a>01225 <a name="l01266"></a><a class="code" href="group__API.html#gae8742473b404363e5c587f570d7e2f3b">01266</a> LONG <a class="code" href="group__API.html#gae8742473b404363e5c587f570d7e2f3b" title="This function ends a previously begun transaction.">SCardEndTransaction</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, DWORD dwDisposition) <a name="l01267"></a>01267 { <a name="l01268"></a>01268 LONG rv; <a name="l01269"></a>01269 <a class="code" href="structend__struct.html" title="contained in SCARD_END_TRANSACTION Messages.">end_struct</a> scEndStruct; <a name="l01270"></a>01270 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l01271"></a>01271 <span class="keywordtype">int</span> randnum, i; <a name="l01272"></a>01272 DWORD dwContextIndex, dwChannelIndex; <a name="l01273"></a>01273 <a name="l01274"></a>01274 PROFILE_START <a name="l01275"></a>01275 <a name="l01276"></a>01276 <span class="comment">/*</span> <a name="l01277"></a>01277 <span class="comment"> * Zero out everything</span> <a name="l01278"></a>01278 <span class="comment"> */</span> <a name="l01279"></a>01279 randnum = 0; <a name="l01280"></a>01280 <a name="l01281"></a>01281 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01282"></a>01282 <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="l01283"></a>01283 <span class="keywordflow">return</span> rv; <a name="l01284"></a>01284 <a name="l01285"></a>01285 <span class="comment">/*</span> <a name="l01286"></a>01286 <span class="comment"> * Make sure this handle has been opened</span> <a name="l01287"></a>01287 <span class="comment"> */</span> <a name="l01288"></a>01288 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01289"></a>01289 <span class="keywordflow">if</span> (rv == -1) <a name="l01290"></a>01290 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01291"></a>01291 <a name="l01292"></a>01292 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01293"></a>01293 <a name="l01294"></a>01294 <span class="comment">/* check the handle is still valid */</span> <a name="l01295"></a>01295 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01296"></a>01296 <span class="keywordflow">if</span> (rv == -1) <a name="l01297"></a>01297 <span class="comment">/* the handle is now invalid</span> <a name="l01298"></a>01298 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l01299"></a>01299 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l01300"></a>01300 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01301"></a>01301 <a name="l01302"></a>01302 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l01303"></a>01303 { <a name="l01304"></a>01304 <span class="keywordtype">char</span> *r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l01305"></a>01305 <a name="l01306"></a>01306 <span class="comment">/* by default r == NULL */</span> <a name="l01307"></a>01307 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l01308"></a>01308 <span class="keywordflow">break</span>; <a name="l01309"></a>01309 } <a name="l01310"></a>01310 <a name="l01311"></a>01311 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l01312"></a>01312 { <a name="l01313"></a>01313 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01314"></a>01314 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l01315"></a>01315 } <a name="l01316"></a>01316 <a name="l01317"></a>01317 scEndStruct.hCard = hCard; <a name="l01318"></a>01318 scEndStruct.dwDisposition = dwDisposition; <a name="l01319"></a>01319 scEndStruct.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="l01320"></a>01320 <a name="l01321"></a>01321 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dcac03f9c354d75ab9e5b53d0af82b2f7ff" title="used by SCardEndTransaction()">SCARD_END_TRANSACTION</a>, <a name="l01322"></a>01322 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01323"></a>01323 <span class="keyword">sizeof</span>(scEndStruct), <a name="l01324"></a>01324 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scEndStruct); <a name="l01325"></a>01325 <a name="l01326"></a>01326 <span class="keywordflow">if</span> (rv == -1) <a name="l01327"></a>01327 { <a name="l01328"></a>01328 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01329"></a>01329 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l01330"></a>01330 } <a name="l01331"></a>01331 <a name="l01332"></a>01332 <span class="comment">/*</span> <a name="l01333"></a>01333 <span class="comment"> * Read a message from the server</span> <a name="l01334"></a>01334 <span class="comment"> */</span> <a name="l01335"></a>01335 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01336"></a>01336 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l01337"></a>01337 <a name="l01338"></a>01338 memcpy(&scEndStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scEndStruct)); <a name="l01339"></a>01339 <a name="l01340"></a>01340 <span class="keywordflow">if</span> (rv == -1) <a name="l01341"></a>01341 { <a name="l01342"></a>01342 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01343"></a>01343 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l01344"></a>01344 } <a name="l01345"></a>01345 <a name="l01346"></a>01346 <span class="comment">/*</span> <a name="l01347"></a>01347 <span class="comment"> * This helps prevent starvation</span> <a name="l01348"></a>01348 <span class="comment"> */</span> <a name="l01349"></a>01349 randnum = SYS_RandomInt(1000, 10000); <a name="l01350"></a>01350 (void)<a class="code" href="sys__generic_8h.html#a910a2c6f5b5a4eadf3213bdfdd0b9bb1" title="Makes the current process sleep for some microseconds.">SYS_USleep</a>(randnum); <a name="l01351"></a>01351 <a name="l01352"></a>01352 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01353"></a>01353 <a name="l01354"></a>01354 PROFILE_END(scEndStruct.rv) <a name="l01355"></a>01355 <a name="l01356"></a>01356 <span class="keywordflow">return</span> scEndStruct.rv; <a name="l01357"></a>01357 } <a name="l01358"></a>01358 <a name="l01365"></a><a class="code" href="group__API.html#ga294d4c60b3631b9584a8c854ee8c3b1b">01365</a> LONG <a class="code" href="group__API.html#ga294d4c60b3631b9584a8c854ee8c3b1b">SCardCancelTransaction</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard) <a name="l01366"></a>01366 { <a name="l01367"></a>01367 LONG rv; <a name="l01368"></a>01368 <a class="code" href="structcancel__struct.html" title="contained in SCARD_CANCEL Messages.">cancel_struct</a> scCancelStruct; <a name="l01369"></a>01369 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l01370"></a>01370 <span class="keywordtype">int</span> i; <a name="l01371"></a>01371 DWORD dwContextIndex, dwChannelIndex; <a name="l01372"></a>01372 <a name="l01373"></a>01373 PROFILE_START <a name="l01374"></a>01374 <a name="l01375"></a>01375 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01376"></a>01376 <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="l01377"></a>01377 <span class="keywordflow">return</span> rv; <a name="l01378"></a>01378 <a name="l01379"></a>01379 <span class="comment">/*</span> <a name="l01380"></a>01380 <span class="comment"> * Make sure this handle has been opened</span> <a name="l01381"></a>01381 <span class="comment"> */</span> <a name="l01382"></a>01382 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01383"></a>01383 <span class="keywordflow">if</span> (rv == -1) <a name="l01384"></a>01384 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01385"></a>01385 <a name="l01386"></a>01386 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01387"></a>01387 <a name="l01388"></a>01388 <span class="comment">/* check the handle is still valid */</span> <a name="l01389"></a>01389 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01390"></a>01390 <span class="keywordflow">if</span> (rv == -1) <a name="l01391"></a>01391 <span class="comment">/* the handle is now invalid</span> <a name="l01392"></a>01392 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l01393"></a>01393 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l01394"></a>01394 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01395"></a>01395 <a name="l01396"></a>01396 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l01397"></a>01397 { <a name="l01398"></a>01398 <span class="keywordtype">char</span> *r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l01399"></a>01399 <a name="l01400"></a>01400 <span class="comment">/* by default r == NULL */</span> <a name="l01401"></a>01401 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l01402"></a>01402 <span class="keywordflow">break</span>; <a name="l01403"></a>01403 } <a name="l01404"></a>01404 <a name="l01405"></a>01405 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l01406"></a>01406 { <a name="l01407"></a>01407 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01408"></a>01408 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l01409"></a>01409 } <a name="l01410"></a>01410 <a name="l01411"></a>01411 scCancelStruct.hCard = hCard; <a name="l01412"></a>01412 <a name="l01413"></a>01413 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(SCARD_CANCEL_TRANSACTION, <a name="l01414"></a>01414 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01415"></a>01415 <span class="keyword">sizeof</span>(scCancelStruct), <a name="l01416"></a>01416 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scCancelStruct); <a name="l01417"></a>01417 <a name="l01418"></a>01418 <span class="keywordflow">if</span> (rv == -1) <a name="l01419"></a>01419 { <a name="l01420"></a>01420 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01421"></a>01421 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l01422"></a>01422 } <a name="l01423"></a>01423 <a name="l01424"></a>01424 <span class="comment">/*</span> <a name="l01425"></a>01425 <span class="comment"> * Read a message from the server</span> <a name="l01426"></a>01426 <span class="comment"> */</span> <a name="l01427"></a>01427 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01428"></a>01428 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l01429"></a>01429 <a name="l01430"></a>01430 memcpy(&scCancelStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scCancelStruct)); <a name="l01431"></a>01431 <a name="l01432"></a>01432 <span class="keywordflow">if</span> (rv == -1) <a name="l01433"></a>01433 { <a name="l01434"></a>01434 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01435"></a>01435 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l01436"></a>01436 } <a name="l01437"></a>01437 <a name="l01438"></a>01438 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01439"></a>01439 <a name="l01440"></a>01440 PROFILE_END(scCancelStruct.rv) <a name="l01441"></a>01441 <a name="l01442"></a>01442 <span class="keywordflow">return</span> scCancelStruct.rv; <a name="l01443"></a>01443 } <a name="l01444"></a>01444 <a name="l01532"></a><a class="code" href="group__API.html#ga18f33eebb45d9e0d2a091ca7a0511d26">01532</a> LONG <a class="code" href="group__API.html#ga18f33eebb45d9e0d2a091ca7a0511d26" title="This function returns the current status of the reader connected to by hCard.">SCardStatus</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, LPSTR mszReaderName, <a name="l01533"></a>01533 LPDWORD pcchReaderLen, LPDWORD pdwState, <a name="l01534"></a>01534 LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) <a name="l01535"></a>01535 { <a name="l01536"></a>01536 DWORD dwReaderLen, dwAtrLen; <a name="l01537"></a>01537 LONG rv; <a name="l01538"></a>01538 <span class="keywordtype">int</span> i; <a name="l01539"></a>01539 <a class="code" href="structstatus__struct.html" title="contained in SCARD_STATUS Messages.">status_struct</a> scStatusStruct; <a name="l01540"></a>01540 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l01541"></a>01541 DWORD dwContextIndex, dwChannelIndex; <a name="l01542"></a>01542 <span class="keywordtype">char</span> *r; <a name="l01543"></a>01543 <span class="keywordtype">char</span> *bufReader = NULL; <a name="l01544"></a>01544 LPBYTE bufAtr = NULL; <a name="l01545"></a>01545 DWORD dummy; <a name="l01546"></a>01546 <a name="l01547"></a>01547 PROFILE_START <a name="l01548"></a>01548 <a name="l01549"></a>01549 <span class="comment">/* default output values */</span> <a name="l01550"></a>01550 <span class="keywordflow">if</span> (pdwState) <a name="l01551"></a>01551 *pdwState = 0; <a name="l01552"></a>01552 <a name="l01553"></a>01553 <span class="keywordflow">if</span> (pdwProtocol) <a name="l01554"></a>01554 *pdwProtocol = 0; <a name="l01555"></a>01555 <a name="l01556"></a>01556 <span class="comment">/* Check for NULL parameters */</span> <a name="l01557"></a>01557 <span class="keywordflow">if</span> (pcchReaderLen == NULL) <a name="l01558"></a>01558 pcchReaderLen = &dummy; <a name="l01559"></a>01559 <a name="l01560"></a>01560 <span class="keywordflow">if</span> (pcbAtrLen == NULL) <a name="l01561"></a>01561 pcbAtrLen = &dummy; <a name="l01562"></a>01562 <a name="l01563"></a>01563 <span class="comment">/* length passed from caller */</span> <a name="l01564"></a>01564 dwReaderLen = *pcchReaderLen; <a name="l01565"></a>01565 dwAtrLen = *pcbAtrLen; <a name="l01566"></a>01566 <a name="l01567"></a>01567 *pcchReaderLen = 0; <a name="l01568"></a>01568 *pcbAtrLen = 0; <a name="l01569"></a>01569 <a name="l01570"></a>01570 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01571"></a>01571 <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="l01572"></a>01572 <span class="keywordflow">return</span> rv; <a name="l01573"></a>01573 <a name="l01574"></a>01574 <span class="comment">/*</span> <a name="l01575"></a>01575 <span class="comment"> * Make sure this handle has been opened</span> <a name="l01576"></a>01576 <span class="comment"> */</span> <a name="l01577"></a>01577 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01578"></a>01578 <span class="keywordflow">if</span> (rv == -1) <a name="l01579"></a>01579 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01580"></a>01580 <a name="l01581"></a>01581 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01582"></a>01582 <a name="l01583"></a>01583 <span class="comment">/* check the handle is still valid */</span> <a name="l01584"></a>01584 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l01585"></a>01585 <span class="keywordflow">if</span> (rv == -1) <a name="l01586"></a>01586 <span class="comment">/* the handle is now invalid</span> <a name="l01587"></a>01587 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l01588"></a>01588 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l01589"></a>01589 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01590"></a>01590 <a name="l01591"></a>01591 r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l01592"></a>01592 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l01593"></a>01593 { <a name="l01594"></a>01594 <span class="comment">/* by default r == NULL */</span> <a name="l01595"></a>01595 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l01596"></a>01596 <span class="keywordflow">break</span>; <a name="l01597"></a>01597 } <a name="l01598"></a>01598 <a name="l01599"></a>01599 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l01600"></a>01600 { <a name="l01601"></a>01601 rv = <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l01602"></a>01602 <span class="keywordflow">goto</span> end; <a name="l01603"></a>01603 } <a name="l01604"></a>01604 <a name="l01605"></a>01605 <span class="comment">/* initialise the structure */</span> <a name="l01606"></a>01606 memset(&scStatusStruct, 0, <span class="keyword">sizeof</span>(scStatusStruct)); <a name="l01607"></a>01607 scStatusStruct.hCard = hCard; <a name="l01608"></a>01608 <a name="l01609"></a>01609 <span class="comment">/* those sizes need to be initialised */</span> <a name="l01610"></a>01610 scStatusStruct.pcchReaderLen = <span class="keyword">sizeof</span>(scStatusStruct.mszReaderNames); <a name="l01611"></a>01611 scStatusStruct.pcbAtrLen = <span class="keyword">sizeof</span>(scStatusStruct.pbAtr); <a name="l01612"></a>01612 <a name="l01613"></a>01613 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca8dd333ed3f05b986c67abbd6291d4188" title="used by SCardStatus()">SCARD_STATUS</a>, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01614"></a>01614 <span class="keyword">sizeof</span>(scStatusStruct), <a name="l01615"></a>01615 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scStatusStruct); <a name="l01616"></a>01616 <a name="l01617"></a>01617 <span class="keywordflow">if</span> (rv == -1) <a name="l01618"></a>01618 { <a name="l01619"></a>01619 rv = <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l01620"></a>01620 <span class="keywordflow">goto</span> end; <a name="l01621"></a>01621 } <a name="l01622"></a>01622 <a name="l01623"></a>01623 <span class="comment">/*</span> <a name="l01624"></a>01624 <span class="comment"> * Read a message from the server</span> <a name="l01625"></a>01625 <span class="comment"> */</span> <a name="l01626"></a>01626 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l01627"></a>01627 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l01628"></a>01628 <a name="l01629"></a>01629 memcpy(&scStatusStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scStatusStruct)); <a name="l01630"></a>01630 <a name="l01631"></a>01631 <span class="keywordflow">if</span> (rv == -1) <a name="l01632"></a>01632 { <a name="l01633"></a>01633 rv = <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l01634"></a>01634 <span class="keywordflow">goto</span> end; <a name="l01635"></a>01635 } <a name="l01636"></a>01636 <a name="l01637"></a>01637 rv = scStatusStruct.rv; <a name="l01638"></a>01638 <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> && rv != <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>) <a name="l01639"></a>01639 { <a name="l01640"></a>01640 <span class="comment">/*</span> <a name="l01641"></a>01641 <span class="comment"> * An event must have occurred</span> <a name="l01642"></a>01642 <span class="comment"> */</span> <a name="l01643"></a>01643 <span class="keywordflow">goto</span> end; <a name="l01644"></a>01644 } <a name="l01645"></a>01645 <a name="l01646"></a>01646 <span class="comment">/*</span> <a name="l01647"></a>01647 <span class="comment"> * Now continue with the client side SCardStatus</span> <a name="l01648"></a>01648 <span class="comment"> */</span> <a name="l01649"></a>01649 <a name="l01650"></a>01650 *pcchReaderLen = strlen(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName) + 1; <a name="l01651"></a>01651 *pcbAtrLen = (readerStates[i])->cardAtrLength; <a name="l01652"></a>01652 <a name="l01653"></a>01653 <span class="keywordflow">if</span> (pdwState) <a name="l01654"></a>01654 *pdwState = (readerStates[i])->readerState; <a name="l01655"></a>01655 <a name="l01656"></a>01656 <span class="keywordflow">if</span> (pdwProtocol) <a name="l01657"></a>01657 *pdwProtocol = (readerStates[i])->cardProtocol; <a name="l01658"></a>01658 <a name="l01659"></a>01659 <span class="keywordflow">if</span> (<a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a> == dwReaderLen) <a name="l01660"></a>01660 { <a name="l01661"></a>01661 dwReaderLen = *pcchReaderLen; <a name="l01662"></a>01662 bufReader = malloc(dwReaderLen); <a name="l01663"></a>01663 <span class="keywordflow">if</span> (NULL == bufReader) <a name="l01664"></a>01664 { <a name="l01665"></a>01665 rv = <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l01666"></a>01666 <span class="keywordflow">goto</span> end; <a name="l01667"></a>01667 } <a name="l01668"></a>01668 <span class="keywordflow">if</span> (NULL == mszReaderName) <a name="l01669"></a>01669 { <a name="l01670"></a>01670 rv = <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l01671"></a>01671 <span class="keywordflow">goto</span> end; <a name="l01672"></a>01672 } <a name="l01673"></a>01673 *(<span class="keywordtype">char</span> **)mszReaderName = bufReader; <a name="l01674"></a>01674 } <a name="l01675"></a>01675 <span class="keywordflow">else</span> <a name="l01676"></a>01676 bufReader = mszReaderName; <a name="l01677"></a>01677 <a name="l01678"></a>01678 <span class="comment">/* return SCARD_E_INSUFFICIENT_BUFFER only if buffer pointer is non NULL */</span> <a name="l01679"></a>01679 <span class="keywordflow">if</span> (bufReader) <a name="l01680"></a>01680 { <a name="l01681"></a>01681 <span class="keywordflow">if</span> (*pcchReaderLen > dwReaderLen) <a name="l01682"></a>01682 rv = <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l01683"></a>01683 <a name="l01684"></a>01684 strncpy(bufReader, <a name="l01685"></a>01685 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName, <a name="l01686"></a>01686 dwReaderLen); <a name="l01687"></a>01687 } <a name="l01688"></a>01688 <a name="l01689"></a>01689 <span class="keywordflow">if</span> (<a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a> == dwAtrLen) <a name="l01690"></a>01690 { <a name="l01691"></a>01691 dwAtrLen = *pcbAtrLen; <a name="l01692"></a>01692 bufAtr = malloc(dwAtrLen); <a name="l01693"></a>01693 <span class="keywordflow">if</span> (NULL == bufAtr) <a name="l01694"></a>01694 { <a name="l01695"></a>01695 rv = <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l01696"></a>01696 <span class="keywordflow">goto</span> end; <a name="l01697"></a>01697 } <a name="l01698"></a>01698 <span class="keywordflow">if</span> (NULL == pbAtr) <a name="l01699"></a>01699 { <a name="l01700"></a>01700 rv = <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l01701"></a>01701 <span class="keywordflow">goto</span> end; <a name="l01702"></a>01702 } <a name="l01703"></a>01703 *(LPBYTE *)pbAtr = bufAtr; <a name="l01704"></a>01704 } <a name="l01705"></a>01705 <span class="keywordflow">else</span> <a name="l01706"></a>01706 bufAtr = pbAtr; <a name="l01707"></a>01707 <a name="l01708"></a>01708 <span class="keywordflow">if</span> (bufAtr) <a name="l01709"></a>01709 { <a name="l01710"></a>01710 <span class="keywordflow">if</span> (*pcbAtrLen > dwAtrLen) <a name="l01711"></a>01711 rv = <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l01712"></a>01712 <a name="l01713"></a>01713 memcpy(bufAtr, (readerStates[i])->cardAtr, min(*pcbAtrLen, dwAtrLen)); <a name="l01714"></a>01714 } <a name="l01715"></a>01715 <a name="l01716"></a>01716 end: <a name="l01717"></a>01717 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01718"></a>01718 <a name="l01719"></a>01719 PROFILE_END(rv) <a name="l01720"></a>01720 <a name="l01721"></a>01721 <span class="keywordflow">return</span> rv; <a name="l01722"></a>01722 } <a name="l01723"></a>01723 <a name="l01724"></a>01724 <span class="keyword">static</span> <span class="keywordtype">long</span> WaitForPcscdEvent(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, <span class="keywordtype">long</span> dwTime) <a name="l01725"></a>01725 { <a name="l01726"></a>01726 <span class="keywordtype">char</span> filename[FILENAME_MAX]; <a name="l01727"></a>01727 <span class="keywordtype">char</span> buf[1]; <a name="l01728"></a>01728 <span class="keywordtype">int</span> fd, r; <a name="l01729"></a>01729 <span class="keyword">struct </span>timeval tv, *ptv = NULL; <a name="l01730"></a>01730 <span class="keyword">struct </span>timeval before, after; <a name="l01731"></a>01731 fd_set read_fd; <a name="l01732"></a>01732 <a name="l01733"></a>01733 <span class="keywordflow">if</span> (INFINITE != dwTime) <a name="l01734"></a>01734 { <a name="l01735"></a>01735 <span class="keywordflow">if</span> (dwTime < 0) <a name="l01736"></a>01736 <span class="keywordflow">return</span> 0; <a name="l01737"></a>01737 gettimeofday(&before, NULL); <a name="l01738"></a>01738 tv.tv_sec = dwTime/1000; <a name="l01739"></a>01739 tv.tv_usec = dwTime*1000 - tv.tv_sec*1000000; <a name="l01740"></a>01740 ptv = &tv; <a name="l01741"></a>01741 } <a name="l01742"></a>01742 <a name="l01743"></a>01743 (void)snprintf(filename, <span class="keyword">sizeof</span>(filename), <span class="stringliteral">"%s/event.%d.%ld"</span>, <a name="l01744"></a>01744 PCSCLITE_EVENTS_DIR, <a class="code" href="sys__generic_8h.html#ac1fa780e658b5a18c5a75603793cb982" title="Gets the running process&#39;s ID.">SYS_GetPID</a>(), hContext); <a name="l01745"></a>01745 r = mkfifo(filename, 0644); <a name="l01746"></a>01746 <span class="keywordflow">if</span> (-1 == r) <a name="l01747"></a>01747 { <a name="l01748"></a>01748 Log2(PCSC_LOG_CRITICAL, <span class="stringliteral">"Can't create event fifo: %s"</span>, strerror(errno)); <a name="l01749"></a>01749 <span class="keywordflow">goto</span> exit; <a name="l01750"></a>01750 } <a name="l01751"></a>01751 <a name="l01752"></a>01752 fd = <a class="code" href="sys__generic_8h.html#a83df5dae709347018a9183e6c4cb7207" title="Opens/creates a file.">SYS_OpenFile</a>(filename, O_RDONLY | O_NONBLOCK, 0); <a name="l01753"></a>01753 <a name="l01754"></a>01754 <span class="comment">/* the file may have been removed between the mkfifo() and open() */</span> <a name="l01755"></a>01755 <span class="keywordflow">if</span> (-1 != fd) <a name="l01756"></a>01756 { <a name="l01757"></a>01757 FD_ZERO(&read_fd); <a name="l01758"></a>01758 FD_SET(fd, &read_fd); <a name="l01759"></a>01759 <a name="l01760"></a>01760 (void)select(fd+1, &read_fd, NULL, NULL, ptv); <a name="l01761"></a>01761 <a name="l01762"></a>01762 (void)SYS_ReadFile(fd, buf, 1); <a name="l01763"></a>01763 (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(fd); <a name="l01764"></a>01764 } <a name="l01765"></a>01765 <a name="l01766"></a>01766 (void)<a class="code" href="sys__generic_8h.html#af473e9d9a973ce499cdef8ffb87913b2" title="Removes a file.">SYS_RemoveFile</a>(filename); <a name="l01767"></a>01767 <a name="l01768"></a>01768 <span class="keywordflow">if</span> (INFINITE != dwTime) <a name="l01769"></a>01769 { <a name="l01770"></a>01770 <span class="keywordtype">long</span> <span class="keywordtype">int</span> diff; <a name="l01771"></a>01771 <a name="l01772"></a>01772 gettimeofday(&after, NULL); <a name="l01773"></a>01773 diff = time_sub(&after, &before); <a name="l01774"></a>01774 dwTime -= diff/1000; <a name="l01775"></a>01775 } <a name="l01776"></a>01776 <a name="l01777"></a>01777 exit: <a name="l01778"></a>01778 <span class="keywordflow">return</span> dwTime; <a name="l01779"></a>01779 } <a name="l01780"></a>01780 <a name="l01872"></a><a class="code" href="group__API.html#gad1db67ba2b7d143498257294b873c049">01872</a> LONG <a class="code" href="group__API.html#gad1db67ba2b7d143498257294b873c049" title="This function receives a structure or list of structures containing reader names...">SCardGetStatusChange</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, DWORD dwTimeout, <a name="l01873"></a>01873 <a class="code" href="structSCARD__READERSTATE__A.html">LPSCARD_READERSTATE_A</a> rgReaderStates, DWORD cReaders) <a name="l01874"></a>01874 { <a name="l01875"></a>01875 <a class="code" href="structSCARD__READERSTATE__A.html">PSCARD_READERSTATE_A</a> currReader; <a name="l01876"></a>01876 <a class="code" href="structpubReaderStatesList.html" title="Define an exported public reader state structure so each application gets instant...">PREADER_STATE</a> rContext; <a name="l01877"></a>01877 <span class="keywordtype">long</span> dwTime = dwTimeout; <a name="l01878"></a>01878 DWORD dwState; <a name="l01879"></a>01879 DWORD dwBreakFlag = 0; <a name="l01880"></a>01880 <span class="keywordtype">int</span> j; <a name="l01881"></a>01881 LONG dwContextIndex; <a name="l01882"></a>01882 <span class="keywordtype">int</span> currentReaderCount = 0; <a name="l01883"></a>01883 LONG 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="l01884"></a>01884 <a name="l01885"></a>01885 PROFILE_START <a name="l01886"></a>01886 <a name="l01887"></a>01887 <span class="keywordflow">if</span> ((rgReaderStates == NULL && cReaders > 0) <a name="l01888"></a>01888 || (cReaders > <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>)) <a name="l01889"></a>01889 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l01890"></a>01890 <a name="l01891"></a>01891 <span class="comment">/* Check the integrity of the reader states structures */</span> <a name="l01892"></a>01892 <span class="keywordflow">for</span> (j = 0; j < cReaders; j++) <a name="l01893"></a>01893 { <a name="l01894"></a>01894 <span class="keywordflow">if</span> (rgReaderStates[j].szReader == NULL) <a name="l01895"></a>01895 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a9ece9fd9e68e4f802e16e951f8f2a642" title="One or more of the supplied parameters values could not be properly interpreted.">SCARD_E_INVALID_VALUE</a>; <a name="l01896"></a>01896 } <a name="l01897"></a>01897 <a name="l01898"></a>01898 <span class="comment">/* return if all readers are SCARD_STATE_IGNORE */</span> <a name="l01899"></a>01899 <span class="keywordflow">if</span> (cReaders > 0) <a name="l01900"></a>01900 { <a name="l01901"></a>01901 <span class="keywordtype">int</span> nbNonIgnoredReaders = cReaders; <a name="l01902"></a>01902 <a name="l01903"></a>01903 <span class="keywordflow">for</span> (j=0; j<cReaders; j++) <a name="l01904"></a>01904 <span class="keywordflow">if</span> (rgReaderStates[j].dwCurrentState & <a class="code" href="pcsclite_8h.html#a0bfdd63120b09223fd4fed4884cbfeec" title="Ignore this reader.">SCARD_STATE_IGNORE</a>) <a name="l01905"></a>01905 nbNonIgnoredReaders--; <a name="l01906"></a>01906 <a name="l01907"></a>01907 <span class="keywordflow">if</span> (0 == nbNonIgnoredReaders) <a name="l01908"></a>01908 <span class="keywordflow">return</span> <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="l01909"></a>01909 } <a name="l01910"></a>01910 <a name="l01911"></a>01911 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01912"></a>01912 <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="l01913"></a>01913 <span class="keywordflow">return</span> rv; <a name="l01914"></a>01914 <a name="l01915"></a>01915 <span class="comment">/*</span> <a name="l01916"></a>01916 <span class="comment"> * Make sure this context has been opened</span> <a name="l01917"></a>01917 <span class="comment"> */</span> <a name="l01918"></a>01918 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l01919"></a>01919 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l01920"></a>01920 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01921"></a>01921 <a name="l01922"></a>01922 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l01923"></a>01923 <a name="l01924"></a>01924 <span class="comment">/* check the context is still opened */</span> <a name="l01925"></a>01925 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l01926"></a>01926 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l01927"></a>01927 <span class="comment">/* the context is now invalid</span> <a name="l01928"></a>01928 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l01929"></a>01929 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l01930"></a>01930 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l01931"></a>01931 <a name="l01932"></a>01932 <span class="comment">/*</span> <a name="l01933"></a>01933 <span class="comment"> * Application is waiting for a reader - return the first available</span> <a name="l01934"></a>01934 <span class="comment"> * reader</span> <a name="l01935"></a>01935 <span class="comment"> * This is DEPRECATED. Use the special reader name \\?PnP?\Notification</span> <a name="l01936"></a>01936 <span class="comment"> * instead</span> <a name="l01937"></a>01937 <span class="comment"> */</span> <a name="l01938"></a>01938 <span class="keywordflow">if</span> (cReaders == 0) <a name="l01939"></a>01939 { <a name="l01940"></a>01940 <span class="keywordflow">while</span> (1) <a name="l01941"></a>01941 { <a name="l01942"></a>01942 <span class="keywordtype">int</span> i; <a name="l01943"></a>01943 <a name="l01944"></a>01944 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01945"></a>01945 <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="l01946"></a>01946 <span class="keywordflow">goto</span> end; <a name="l01947"></a>01947 <a name="l01948"></a>01948 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l01949"></a>01949 { <a name="l01950"></a>01950 <span class="keywordflow">if</span> ((readerStates[i])->readerID != 0) <a name="l01951"></a>01951 { <a name="l01952"></a>01952 <span class="comment">/* Reader was found */</span> <a name="l01953"></a>01953 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="l01954"></a>01954 <span class="keywordflow">goto</span> end; <a name="l01955"></a>01955 } <a name="l01956"></a>01956 } <a name="l01957"></a>01957 <a name="l01958"></a>01958 <span class="keywordflow">if</span> (dwTimeout == 0) <a name="l01959"></a>01959 { <a name="l01960"></a>01960 <span class="comment">/* return immediately - no reader available */</span> <a name="l01961"></a>01961 rv = <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l01962"></a>01962 <span class="keywordflow">goto</span> end; <a name="l01963"></a>01963 } <a name="l01964"></a>01964 <a name="l01965"></a>01965 dwTime = WaitForPcscdEvent(hContext, dwTime); <a name="l01966"></a>01966 <span class="keywordflow">if</span> (dwTimeout != INFINITE) <a name="l01967"></a>01967 { <a name="l01968"></a>01968 <span class="keywordflow">if</span> (dwTime <= 0) <a name="l01969"></a>01969 { <a name="l01970"></a>01970 rv = <a class="code" href="pcsclite_8h.html#aa01265b3f55d4f18cdeb4f9cd736b508" title="The user-specified timeout value has expired.">SCARD_E_TIMEOUT</a>; <a name="l01971"></a>01971 <span class="keywordflow">goto</span> end; <a name="l01972"></a>01972 } <a name="l01973"></a>01973 } <a name="l01974"></a>01974 } <a name="l01975"></a>01975 } <a name="l01976"></a>01976 <a name="l01977"></a>01977 <span class="comment">/*</span> <a name="l01978"></a>01978 <span class="comment"> * End of search for readers</span> <a name="l01979"></a>01979 <span class="comment"> */</span> <a name="l01980"></a>01980 <a name="l01981"></a>01981 <span class="comment">/* Clear the event state for all readers */</span> <a name="l01982"></a>01982 <span class="keywordflow">for</span> (j = 0; j < cReaders; j++) <a name="l01983"></a>01983 rgReaderStates[j].dwEventState = 0; <a name="l01984"></a>01984 <a name="l01985"></a>01985 <span class="comment">/* Now is where we start our event checking loop */</span> <a name="l01986"></a>01986 Log1(PCSC_LOG_DEBUG, <span class="stringliteral">"Event Loop Start"</span>); <a name="l01987"></a>01987 <a name="l01988"></a>01988 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].contextBlockStatus = <a class="code" href="pcscd_8h.html#a4d9d9fb8624fffc60a87cbf3e62888db" title="Function is blocking.">BLOCK_STATUS_BLOCKING</a>; <a name="l01989"></a>01989 <a name="l01990"></a>01990 <span class="comment">/* Get the initial reader count on the system */</span> <a name="l01991"></a>01991 <span class="keywordflow">for</span> (j=0; j < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; j++) <a name="l01992"></a>01992 <span class="keywordflow">if</span> ((readerStates[j])->readerID != 0) <a name="l01993"></a>01993 currentReaderCount++; <a name="l01994"></a>01994 <a name="l01995"></a>01995 j = 0; <a name="l01996"></a>01996 <span class="keywordflow">do</span> <a name="l01997"></a>01997 { <a name="l01998"></a>01998 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l01999"></a>01999 <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="l02000"></a>02000 { <a name="l02001"></a>02001 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex) <a name="l02002"></a>02002 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02003"></a>02003 <a name="l02004"></a>02004 PROFILE_END(rv) <a name="l02005"></a>02005 <a name="l02006"></a>02006 <span class="keywordflow">return</span> rv; <a name="l02007"></a>02007 } <a name="l02008"></a>02008 <a name="l02009"></a>02009 currReader = &rgReaderStates[j]; <a name="l02010"></a>02010 <a name="l02011"></a>02011 <span class="comment">/* Ignore for IGNORED readers */</span> <a name="l02012"></a>02012 <span class="keywordflow">if</span> (!(currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#a0bfdd63120b09223fd4fed4884cbfeec" title="Ignore this reader.">SCARD_STATE_IGNORE</a>)) <a name="l02013"></a>02013 { <a name="l02014"></a>02014 LPSTR lpcReaderName; <a name="l02015"></a>02015 <span class="keywordtype">int</span> i; <a name="l02016"></a>02016 <a name="l02017"></a>02017 <span class="comment">/************ Looks for correct readernames *********************/</span> <a name="l02018"></a>02018 <a name="l02019"></a>02019 lpcReaderName = (<span class="keywordtype">char</span> *) currReader->szReader; <a name="l02020"></a>02020 <a name="l02021"></a>02021 for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++) <a name="l02022"></a>02022 { <a name="l02023"></a>02023 <span class="keywordflow">if</span> (strcmp(lpcReaderName, (readerStates[i])->readerName) == 0) <a name="l02024"></a>02024 <span class="keywordflow">break</span>; <a name="l02025"></a>02025 } <a name="l02026"></a>02026 <a name="l02027"></a>02027 <span class="comment">/* The requested reader name is not recognized */</span> <a name="l02028"></a>02028 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l02029"></a>02029 { <a name="l02030"></a>02030 <span class="comment">/* PnP special reader? */</span> <a name="l02031"></a>02031 <span class="keywordflow">if</span> (strcasecmp(lpcReaderName, <span class="stringliteral">"\\\\?PnP?\\Notification"</span>) == 0) <a name="l02032"></a>02032 { <a name="l02033"></a>02033 <span class="keywordtype">int</span> k, newReaderCount = 0; <a name="l02034"></a>02034 <a name="l02035"></a>02035 <span class="keywordflow">for</span> (k=0; k < PCSCLITE_MAX_READERS_CONTEXTS; k++) <a name="l02036"></a>02036 <span class="keywordflow">if</span> ((readerStates[k])->readerID != 0) <a name="l02037"></a>02037 newReaderCount++; <a name="l02038"></a>02038 <a name="l02039"></a>02039 <span class="keywordflow">if</span> (newReaderCount != currentReaderCount) <a name="l02040"></a>02040 { <a name="l02041"></a>02041 Log1(PCSC_LOG_INFO, <span class="stringliteral">"Reader list changed"</span>); <a name="l02042"></a>02042 currentReaderCount = newReaderCount; <a name="l02043"></a>02043 <a name="l02044"></a>02044 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02045"></a>02045 dwBreakFlag = 1; <a name="l02046"></a>02046 } <a name="l02047"></a>02047 } <a name="l02048"></a>02048 <span class="keywordflow">else</span> <a name="l02049"></a>02049 { <a name="l02050"></a>02050 currReader->dwEventState = <a class="code" href="pcsclite_8h.html#a96ab0fac1bb56525c5f216428e7dd8e7" title="Reader unknown.">SCARD_STATE_UNKNOWN</a> | <a class="code" href="pcsclite_8h.html#a781e4a27c9512c19935e3addaeaa152f" title="Status unavailable.">SCARD_STATE_UNAVAILABLE</a>; <a name="l02051"></a>02051 <span class="keywordflow">if</span> (!(currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#a96ab0fac1bb56525c5f216428e7dd8e7" title="Reader unknown.">SCARD_STATE_UNKNOWN</a>)) <a name="l02052"></a>02052 { <a name="l02053"></a>02053 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02054"></a>02054 <span class="comment">/*</span> <a name="l02055"></a>02055 <span class="comment"> * Spec says use SCARD_STATE_IGNORE but a removed USB</span> <a name="l02056"></a>02056 <span class="comment"> * reader with eventState fed into currentState will</span> <a name="l02057"></a>02057 <span class="comment"> * be ignored forever</span> <a name="l02058"></a>02058 <span class="comment"> */</span> <a name="l02059"></a>02059 dwBreakFlag = 1; <a name="l02060"></a>02060 } <a name="l02061"></a>02061 } <a name="l02062"></a>02062 } <a name="l02063"></a>02063 <span class="keywordflow">else</span> <a name="l02064"></a>02064 { <a name="l02065"></a>02065 <span class="comment">/* The reader has come back after being away */</span> <a name="l02066"></a>02066 <span class="keywordflow">if</span> (currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#a96ab0fac1bb56525c5f216428e7dd8e7" title="Reader unknown.">SCARD_STATE_UNKNOWN</a>) <a name="l02067"></a>02067 { <a name="l02068"></a>02068 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02069"></a>02069 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a96ab0fac1bb56525c5f216428e7dd8e7" title="Reader unknown.">SCARD_STATE_UNKNOWN</a>; <a name="l02070"></a>02070 Log0(PCSC_LOG_DEBUG); <a name="l02071"></a>02071 dwBreakFlag = 1; <a name="l02072"></a>02072 } <a name="l02073"></a>02073 <a name="l02074"></a>02074 <span class="comment">/*****************************************************************/</span> <a name="l02075"></a>02075 <a name="l02076"></a>02076 <span class="comment">/* Set the reader status structure */</span> <a name="l02077"></a>02077 rContext = readerStates[i]; <a name="l02078"></a>02078 <a name="l02079"></a>02079 <span class="comment">/* Now we check all the Reader States */</span> <a name="l02080"></a>02080 dwState = rContext->readerState; <a name="l02081"></a>02081 <a name="l02082"></a>02082 <span class="comment">/* only if current state has an non null event counter */</span> <a name="l02083"></a>02083 <span class="keywordflow">if</span> (currReader->dwCurrentState & 0xFFFF0000) <a name="l02084"></a>02084 { <a name="l02085"></a>02085 <span class="keywordtype">int</span> currentCounter, stateCounter; <a name="l02086"></a>02086 <a name="l02087"></a>02087 stateCounter = (dwState >> 16) & 0xFFFF; <a name="l02088"></a>02088 currentCounter = (currReader->dwCurrentState >> 16) & 0xFFFF; <a name="l02089"></a>02089 <a name="l02090"></a>02090 <span class="comment">/* has the event counter changed since the last call? */</span> <a name="l02091"></a>02091 <span class="keywordflow">if</span> (stateCounter != currentCounter) <a name="l02092"></a>02092 { <a name="l02093"></a>02093 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02094"></a>02094 Log0(PCSC_LOG_DEBUG); <a name="l02095"></a>02095 dwBreakFlag = 1; <a name="l02096"></a>02096 } <a name="l02097"></a>02097 <a name="l02098"></a>02098 <span class="comment">/* add an event counter in the upper word of dwEventState */</span> <a name="l02099"></a>02099 currReader->dwEventState = <a name="l02100"></a>02100 ((currReader->dwEventState & 0xffff ) <a name="l02101"></a>02101 | (stateCounter << 16)); <a name="l02102"></a>02102 } <a name="l02103"></a>02103 <a name="l02104"></a>02104 <span class="comment">/*********** Check if the reader is in the correct state ********/</span> <a name="l02105"></a>02105 <span class="keywordflow">if</span> (dwState & <a class="code" href="pcsclite_8h.html#a91be8317d47fab4b3eac201850fa917f" title="Unknown state.">SCARD_UNKNOWN</a>) <a name="l02106"></a>02106 { <a name="l02107"></a>02107 <span class="comment">/* reader is in bad state */</span> <a name="l02108"></a>02108 currReader->dwEventState = <a class="code" href="pcsclite_8h.html#a781e4a27c9512c19935e3addaeaa152f" title="Status unavailable.">SCARD_STATE_UNAVAILABLE</a>; <a name="l02109"></a>02109 <span class="keywordflow">if</span> (!(currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#a781e4a27c9512c19935e3addaeaa152f" title="Status unavailable.">SCARD_STATE_UNAVAILABLE</a>)) <a name="l02110"></a>02110 { <a name="l02111"></a>02111 <span class="comment">/* App thinks reader is in good state and it is not */</span> <a name="l02112"></a>02112 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02113"></a>02113 Log0(PCSC_LOG_DEBUG); <a name="l02114"></a>02114 dwBreakFlag = 1; <a name="l02115"></a>02115 } <a name="l02116"></a>02116 } <a name="l02117"></a>02117 <span class="keywordflow">else</span> <a name="l02118"></a>02118 { <a name="l02119"></a>02119 <span class="comment">/* App thinks reader in bad state but it is not */</span> <a name="l02120"></a>02120 <span class="keywordflow">if</span> (currReader-> dwCurrentState & <a class="code" href="pcsclite_8h.html#a781e4a27c9512c19935e3addaeaa152f" title="Status unavailable.">SCARD_STATE_UNAVAILABLE</a>) <a name="l02121"></a>02121 { <a name="l02122"></a>02122 currReader->dwEventState &= ~SCARD_STATE_UNAVAILABLE; <a name="l02123"></a>02123 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02124"></a>02124 Log0(PCSC_LOG_DEBUG); <a name="l02125"></a>02125 dwBreakFlag = 1; <a name="l02126"></a>02126 } <a name="l02127"></a>02127 } <a name="l02128"></a>02128 <a name="l02129"></a>02129 <span class="comment">/********** Check for card presence in the reader **************/</span> <a name="l02130"></a>02130 <a name="l02131"></a>02131 <span class="keywordflow">if</span> (dwState & <a class="code" href="pcsclite_8h.html#a4d99b1aacfcda4e1a36198f5668ae520" title="Card is present.">SCARD_PRESENT</a>) <a name="l02132"></a>02132 { <a name="l02133"></a>02133 <span class="comment">/* card present but not yet powered up */</span> <a name="l02134"></a>02134 <span class="keywordflow">if</span> (0 == rContext->cardAtrLength) <a name="l02135"></a>02135 <span class="comment">/* Allow the status thread to convey information */</span> <a name="l02136"></a>02136 (void)<a class="code" href="sys__generic_8h.html#a910a2c6f5b5a4eadf3213bdfdd0b9bb1" title="Makes the current process sleep for some microseconds.">SYS_USleep</a>(<a class="code" href="pcscd_8h.html#a3a41215bb0b34269bc221fad8470262b" title="Status polling rate.">PCSCLITE_STATUS_POLL_RATE</a> + 10); <a name="l02137"></a>02137 <a name="l02138"></a>02138 currReader->cbAtr = rContext->cardAtrLength; <a name="l02139"></a>02139 memcpy(currReader->rgbAtr, rContext->cardAtr, <a name="l02140"></a>02140 currReader->cbAtr); <a name="l02141"></a>02141 } <a name="l02142"></a>02142 <span class="keywordflow">else</span> <a name="l02143"></a>02143 currReader->cbAtr = 0; <a name="l02144"></a>02144 <a name="l02145"></a>02145 <span class="comment">/* Card is now absent */</span> <a name="l02146"></a>02146 <span class="keywordflow">if</span> (dwState & <a class="code" href="pcsclite_8h.html#a8108c39f71de4ea806b0a411eb9906ab" title="Card is absent.">SCARD_ABSENT</a>) <a name="l02147"></a>02147 { <a name="l02148"></a>02148 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#aadf7badda42d372c2bc56d95a7720535" title="Card removed.">SCARD_STATE_EMPTY</a>; <a name="l02149"></a>02149 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a78d2639a9716b6b27f4d516e43470f8f" title="Card inserted.">SCARD_STATE_PRESENT</a>; <a name="l02150"></a>02150 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#ae73c6e4ff31781d4358b93bbde952cfe" title="App wants status.">SCARD_STATE_UNAWARE</a>; <a name="l02151"></a>02151 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a0bfdd63120b09223fd4fed4884cbfeec" title="Ignore this reader.">SCARD_STATE_IGNORE</a>; <a name="l02152"></a>02152 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a96ab0fac1bb56525c5f216428e7dd8e7" title="Reader unknown.">SCARD_STATE_UNKNOWN</a>; <a name="l02153"></a>02153 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a781e4a27c9512c19935e3addaeaa152f" title="Status unavailable.">SCARD_STATE_UNAVAILABLE</a>; <a name="l02154"></a>02154 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#ab294bb6ccdc6bb035473a3f01697ed12" title="ATR matches card.">SCARD_STATE_ATRMATCH</a>; <a name="l02155"></a>02155 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#aba849aaf01b436d511218b18d96caf83" title="Unresponsive card.">SCARD_STATE_MUTE</a>; <a name="l02156"></a>02156 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a56b01a133df54d0ca651b1541a7f11d5" title="Shared Mode.">SCARD_STATE_INUSE</a>; <a name="l02157"></a>02157 <a name="l02158"></a>02158 <span class="comment">/* After present the rest are assumed */</span> <a name="l02159"></a>02159 <span class="keywordflow">if</span> (currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#a78d2639a9716b6b27f4d516e43470f8f" title="Card inserted.">SCARD_STATE_PRESENT</a>) <a name="l02160"></a>02160 { <a name="l02161"></a>02161 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02162"></a>02162 Log0(PCSC_LOG_DEBUG); <a name="l02163"></a>02163 dwBreakFlag = 1; <a name="l02164"></a>02164 } <a name="l02165"></a>02165 } <a name="l02166"></a>02166 <span class="comment">/* Card is now present */</span> <a name="l02167"></a>02167 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (dwState & SCARD_PRESENT) <a name="l02168"></a>02168 { <a name="l02169"></a>02169 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#a78d2639a9716b6b27f4d516e43470f8f" title="Card inserted.">SCARD_STATE_PRESENT</a>; <a name="l02170"></a>02170 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#aadf7badda42d372c2bc56d95a7720535" title="Card removed.">SCARD_STATE_EMPTY</a>; <a name="l02171"></a>02171 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#ae73c6e4ff31781d4358b93bbde952cfe" title="App wants status.">SCARD_STATE_UNAWARE</a>; <a name="l02172"></a>02172 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a0bfdd63120b09223fd4fed4884cbfeec" title="Ignore this reader.">SCARD_STATE_IGNORE</a>; <a name="l02173"></a>02173 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a96ab0fac1bb56525c5f216428e7dd8e7" title="Reader unknown.">SCARD_STATE_UNKNOWN</a>; <a name="l02174"></a>02174 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a781e4a27c9512c19935e3addaeaa152f" title="Status unavailable.">SCARD_STATE_UNAVAILABLE</a>; <a name="l02175"></a>02175 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#aba849aaf01b436d511218b18d96caf83" title="Unresponsive card.">SCARD_STATE_MUTE</a>; <a name="l02176"></a>02176 <a name="l02177"></a>02177 <span class="keywordflow">if</span> (currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#aadf7badda42d372c2bc56d95a7720535" title="Card removed.">SCARD_STATE_EMPTY</a>) <a name="l02178"></a>02178 { <a name="l02179"></a>02179 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02180"></a>02180 Log0(PCSC_LOG_DEBUG); <a name="l02181"></a>02181 dwBreakFlag = 1; <a name="l02182"></a>02182 } <a name="l02183"></a>02183 <a name="l02184"></a>02184 <span class="keywordflow">if</span> (dwState & <a class="code" href="pcsclite_8h.html#a0feed8b3b5ce43d1411359a9b0a3d78c" title="Card not powered.">SCARD_SWALLOWED</a>) <a name="l02185"></a>02185 { <a name="l02186"></a>02186 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#aba849aaf01b436d511218b18d96caf83" title="Unresponsive card.">SCARD_STATE_MUTE</a>; <a name="l02187"></a>02187 <span class="keywordflow">if</span> (!(currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#aba849aaf01b436d511218b18d96caf83" title="Unresponsive card.">SCARD_STATE_MUTE</a>)) <a name="l02188"></a>02188 { <a name="l02189"></a>02189 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02190"></a>02190 Log0(PCSC_LOG_DEBUG); <a name="l02191"></a>02191 dwBreakFlag = 1; <a name="l02192"></a>02192 } <a name="l02193"></a>02193 } <a name="l02194"></a>02194 <span class="keywordflow">else</span> <a name="l02195"></a>02195 { <a name="l02196"></a>02196 <span class="comment">/* App thinks card is mute but it is not */</span> <a name="l02197"></a>02197 <span class="keywordflow">if</span> (currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#aba849aaf01b436d511218b18d96caf83" title="Unresponsive card.">SCARD_STATE_MUTE</a>) <a name="l02198"></a>02198 { <a name="l02199"></a>02199 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02200"></a>02200 Log0(PCSC_LOG_DEBUG); <a name="l02201"></a>02201 dwBreakFlag = 1; <a name="l02202"></a>02202 } <a name="l02203"></a>02203 } <a name="l02204"></a>02204 } <a name="l02205"></a>02205 <a name="l02206"></a>02206 <span class="comment">/* Now figure out sharing modes */</span> <a name="l02207"></a>02207 <span class="keywordflow">if</span> (rContext->readerSharing == -1) <a name="l02208"></a>02208 { <a name="l02209"></a>02209 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#ae371f8ad287d26aceb591537189f962a" title="Exclusive Mode.">SCARD_STATE_EXCLUSIVE</a>; <a name="l02210"></a>02210 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a56b01a133df54d0ca651b1541a7f11d5" title="Shared Mode.">SCARD_STATE_INUSE</a>; <a name="l02211"></a>02211 <span class="keywordflow">if</span> (currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#a56b01a133df54d0ca651b1541a7f11d5" title="Shared Mode.">SCARD_STATE_INUSE</a>) <a name="l02212"></a>02212 { <a name="l02213"></a>02213 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02214"></a>02214 Log0(PCSC_LOG_DEBUG); <a name="l02215"></a>02215 dwBreakFlag = 1; <a name="l02216"></a>02216 } <a name="l02217"></a>02217 } <a name="l02218"></a>02218 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (rContext->readerSharing >= 1) <a name="l02219"></a>02219 { <a name="l02220"></a>02220 <span class="comment">/* A card must be inserted for it to be INUSE */</span> <a name="l02221"></a>02221 <span class="keywordflow">if</span> (dwState & SCARD_PRESENT) <a name="l02222"></a>02222 { <a name="l02223"></a>02223 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#a56b01a133df54d0ca651b1541a7f11d5" title="Shared Mode.">SCARD_STATE_INUSE</a>; <a name="l02224"></a>02224 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#ae371f8ad287d26aceb591537189f962a" title="Exclusive Mode.">SCARD_STATE_EXCLUSIVE</a>; <a name="l02225"></a>02225 <span class="keywordflow">if</span> (currReader-> dwCurrentState & <a class="code" href="pcsclite_8h.html#ae371f8ad287d26aceb591537189f962a" title="Exclusive Mode.">SCARD_STATE_EXCLUSIVE</a>) <a name="l02226"></a>02226 { <a name="l02227"></a>02227 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02228"></a>02228 Log0(PCSC_LOG_DEBUG); <a name="l02229"></a>02229 dwBreakFlag = 1; <a name="l02230"></a>02230 } <a name="l02231"></a>02231 } <a name="l02232"></a>02232 } <a name="l02233"></a>02233 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (rContext->readerSharing == 0) <a name="l02234"></a>02234 { <a name="l02235"></a>02235 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#a56b01a133df54d0ca651b1541a7f11d5" title="Shared Mode.">SCARD_STATE_INUSE</a>; <a name="l02236"></a>02236 currReader->dwEventState &= ~<a class="code" href="pcsclite_8h.html#ae371f8ad287d26aceb591537189f962a" title="Exclusive Mode.">SCARD_STATE_EXCLUSIVE</a>; <a name="l02237"></a>02237 <a name="l02238"></a>02238 <span class="keywordflow">if</span> (currReader->dwCurrentState & <a class="code" href="pcsclite_8h.html#a56b01a133df54d0ca651b1541a7f11d5" title="Shared Mode.">SCARD_STATE_INUSE</a>) <a name="l02239"></a>02239 { <a name="l02240"></a>02240 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02241"></a>02241 Log0(PCSC_LOG_DEBUG); <a name="l02242"></a>02242 dwBreakFlag = 1; <a name="l02243"></a>02243 } <a name="l02244"></a>02244 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (currReader-> dwCurrentState <a name="l02245"></a>02245 & <a class="code" href="pcsclite_8h.html#ae371f8ad287d26aceb591537189f962a" title="Exclusive Mode.">SCARD_STATE_EXCLUSIVE</a>) <a name="l02246"></a>02246 { <a name="l02247"></a>02247 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02248"></a>02248 Log0(PCSC_LOG_DEBUG); <a name="l02249"></a>02249 dwBreakFlag = 1; <a name="l02250"></a>02250 } <a name="l02251"></a>02251 } <a name="l02252"></a>02252 <a name="l02253"></a>02253 <span class="keywordflow">if</span> (currReader->dwCurrentState == <a class="code" href="pcsclite_8h.html#ae73c6e4ff31781d4358b93bbde952cfe" title="App wants status.">SCARD_STATE_UNAWARE</a>) <a name="l02254"></a>02254 { <a name="l02255"></a>02255 <span class="comment">/*</span> <a name="l02256"></a>02256 <span class="comment"> * Break out of the while .. loop and return status</span> <a name="l02257"></a>02257 <span class="comment"> * once all the status's for all readers is met</span> <a name="l02258"></a>02258 <span class="comment"> */</span> <a name="l02259"></a>02259 currReader->dwEventState |= <a class="code" href="pcsclite_8h.html#abd53085c631a1bade0fb5e974de90d48" title="State has changed.">SCARD_STATE_CHANGED</a>; <a name="l02260"></a>02260 Log0(PCSC_LOG_DEBUG); <a name="l02261"></a>02261 dwBreakFlag = 1; <a name="l02262"></a>02262 } <a name="l02263"></a>02263 } <span class="comment">/* End of SCARD_STATE_UNKNOWN */</span> <a name="l02264"></a>02264 } <span class="comment">/* End of SCARD_STATE_IGNORE */</span> <a name="l02265"></a>02265 <a name="l02266"></a>02266 <span class="comment">/* Counter and resetter */</span> <a name="l02267"></a>02267 j++; <a name="l02268"></a>02268 <span class="keywordflow">if</span> (j == cReaders) <a name="l02269"></a>02269 { <a name="l02270"></a>02270 <span class="comment">/* go back to the first reader */</span> <a name="l02271"></a>02271 j = 0; <a name="l02272"></a>02272 <a name="l02273"></a>02273 <span class="comment">/* Declare all the break conditions */</span> <a name="l02274"></a>02274 <a name="l02275"></a>02275 <span class="comment">/* Break if UNAWARE is set and all readers have been checked */</span> <a name="l02276"></a>02276 <span class="keywordflow">if</span> (dwBreakFlag == 1) <a name="l02277"></a>02277 <span class="keywordflow">break</span>; <a name="l02278"></a>02278 <a name="l02279"></a>02279 <span class="keywordflow">if</span> (<a class="code" href="pcscd_8h.html#a2100023490c145dd638a909920e9949b" title="Normal resume.">BLOCK_STATUS_RESUME</a> <a name="l02280"></a>02280 == <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].contextBlockStatus) <a name="l02281"></a>02281 <span class="keywordflow">break</span>; <a name="l02282"></a>02282 <a name="l02283"></a>02283 <span class="comment">/* Only sleep once for each cycle of reader checks. */</span> <a name="l02284"></a>02284 dwTime = WaitForPcscdEvent(hContext, dwTime); <a name="l02285"></a>02285 <a name="l02286"></a>02286 <span class="keywordflow">if</span> (dwTimeout != INFINITE) <a name="l02287"></a>02287 { <a name="l02288"></a>02288 <span class="comment">/* If time is greater than timeout and all readers have been</span> <a name="l02289"></a>02289 <span class="comment"> * checked</span> <a name="l02290"></a>02290 <span class="comment"> */</span> <a name="l02291"></a>02291 <span class="keywordflow">if</span> (dwTime <= 0) <a name="l02292"></a>02292 { <a name="l02293"></a>02293 rv = <a class="code" href="pcsclite_8h.html#aa01265b3f55d4f18cdeb4f9cd736b508" title="The user-specified timeout value has expired.">SCARD_E_TIMEOUT</a>; <a name="l02294"></a>02294 <span class="keywordflow">goto</span> end; <a name="l02295"></a>02295 } <a name="l02296"></a>02296 } <a name="l02297"></a>02297 } <a name="l02298"></a>02298 } <a name="l02299"></a>02299 <span class="keywordflow">while</span> (1); <a name="l02300"></a>02300 <a name="l02301"></a>02301 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].contextBlockStatus == <a class="code" href="pcscd_8h.html#a2100023490c145dd638a909920e9949b" title="Normal resume.">BLOCK_STATUS_RESUME</a>) <a name="l02302"></a>02302 rv = <a class="code" href="pcsclite_8h.html#a48cf91681fb2c14902bd41888cb5cf08" title="The action was cancelled by an SCardCancel request.">SCARD_E_CANCELLED</a>; <a name="l02303"></a>02303 <a name="l02304"></a>02304 end: <a name="l02305"></a>02305 Log1(PCSC_LOG_DEBUG, <span class="stringliteral">"Event Loop End"</span>); <a name="l02306"></a>02306 <a name="l02307"></a>02307 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02308"></a>02308 <a name="l02309"></a>02309 PROFILE_END(rv) <a name="l02310"></a>02310 <a name="l02311"></a>02311 <span class="keywordflow">return</span> rv; <a name="l02312"></a>02312 } <a name="l02313"></a>02313 <a name="l02365"></a><a class="code" href="group__API.html#gac3454d4657110fd7f753b2d3d8f4e32f">02365</a> LONG <a class="code" href="group__API.html#gac3454d4657110fd7f753b2d3d8f4e32f" title="This function sends a command directly to the IFD Handler (reader driver) to be processed...">SCardControl</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, <a name="l02366"></a>02366 DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, <a name="l02367"></a>02367 LPDWORD lpBytesReturned) <a name="l02368"></a>02368 { <a name="l02369"></a>02369 LONG rv; <a name="l02370"></a>02370 <a class="code" href="structcontrol__struct.html" title="contained in SCARD_CONTROL Messages.">control_struct</a> scControlStruct; <a name="l02371"></a>02371 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l02372"></a>02372 <span class="keywordtype">int</span> i; <a name="l02373"></a>02373 DWORD dwContextIndex, dwChannelIndex; <a name="l02374"></a>02374 <a name="l02375"></a>02375 PROFILE_START <a name="l02376"></a>02376 <a name="l02377"></a>02377 <span class="comment">/* 0 bytes received by default */</span> <a name="l02378"></a>02378 <span class="keywordflow">if</span> (NULL != lpBytesReturned) <a name="l02379"></a>02379 *lpBytesReturned = 0; <a name="l02380"></a>02380 <a name="l02381"></a>02381 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l02382"></a>02382 <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="l02383"></a>02383 <span class="keywordflow">return</span> rv; <a name="l02384"></a>02384 <a name="l02385"></a>02385 <span class="comment">/*</span> <a name="l02386"></a>02386 <span class="comment"> * Make sure this handle has been opened</span> <a name="l02387"></a>02387 <span class="comment"> */</span> <a name="l02388"></a>02388 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l02389"></a>02389 <span class="keywordflow">if</span> (rv == -1) <a name="l02390"></a>02390 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l02391"></a>02391 <a name="l02392"></a>02392 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02393"></a>02393 <a name="l02394"></a>02394 <span class="comment">/* check the handle is still valid */</span> <a name="l02395"></a>02395 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l02396"></a>02396 <span class="keywordflow">if</span> (rv == -1) <a name="l02397"></a>02397 <span class="comment">/* the handle is now invalid</span> <a name="l02398"></a>02398 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l02399"></a>02399 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l02400"></a>02400 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l02401"></a>02401 <a name="l02402"></a>02402 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l02403"></a>02403 { <a name="l02404"></a>02404 <span class="keywordtype">char</span> *r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l02405"></a>02405 <a name="l02406"></a>02406 <span class="comment">/* by default r == NULL */</span> <a name="l02407"></a>02407 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l02408"></a>02408 <span class="keywordflow">break</span>; <a name="l02409"></a>02409 } <a name="l02410"></a>02410 <a name="l02411"></a>02411 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l02412"></a>02412 { <a name="l02413"></a>02413 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02414"></a>02414 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l02415"></a>02415 } <a name="l02416"></a>02416 <a name="l02417"></a>02417 <span class="keywordflow">if</span> ((cbSendLength > <a class="code" href="pcsclite_8h.html#ae128d4b6df34e2dfdb6216b31bae2cc6" title="enhanced (64K + APDU + Lc + Le) Tx/Rx Buffer">MAX_BUFFER_SIZE_EXTENDED</a>) <a name="l02418"></a>02418 || (cbRecvLength > <a class="code" href="pcsclite_8h.html#ae128d4b6df34e2dfdb6216b31bae2cc6" title="enhanced (64K + APDU + Lc + Le) Tx/Rx Buffer">MAX_BUFFER_SIZE_EXTENDED</a>)) <a name="l02419"></a>02419 { <a name="l02420"></a>02420 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02421"></a>02421 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l02422"></a>02422 } <a name="l02423"></a>02423 <a name="l02424"></a>02424 <span class="keywordflow">if</span> ((cbSendLength > <a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>) || (cbRecvLength > <a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>)) <a name="l02425"></a>02425 { <a name="l02426"></a>02426 <span class="comment">/* extended control */</span> <a name="l02427"></a>02427 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buffer[<span class="keyword">sizeof</span>(<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a>) + <a class="code" href="pcsclite_8h.html#ae128d4b6df34e2dfdb6216b31bae2cc6" title="enhanced (64K + APDU + Lc + Le) Tx/Rx Buffer">MAX_BUFFER_SIZE_EXTENDED</a>]; <a name="l02428"></a>02428 <a class="code" href="structcontrol__struct__extended.html" title="contained in SCARD_CONTROL_EXTENDED Messages.">control_struct_extended</a> *scControlStructExtended = (<a class="code" href="structcontrol__struct__extended.html" title="contained in SCARD_CONTROL_EXTENDED Messages.">control_struct_extended</a> *)buffer; <a name="l02429"></a>02429 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> *pmsgStruct = (<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">psharedSegmentMsg</a>)buffer; <a name="l02430"></a>02430 <a name="l02431"></a>02431 scControlStructExtended->hCard = hCard; <a name="l02432"></a>02432 scControlStructExtended->dwControlCode = dwControlCode; <a name="l02433"></a>02433 scControlStructExtended->cbSendLength = cbSendLength; <a name="l02434"></a>02434 scControlStructExtended->cbRecvLength = cbRecvLength; <a name="l02435"></a>02435 scControlStructExtended->dwBytesReturned = 0; <a name="l02436"></a>02436 scControlStructExtended->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="l02437"></a>02437 <span class="comment">/* The size of data to send is the size of</span> <a name="l02438"></a>02438 <span class="comment"> * struct control_struct_extended WITHOUT the data[] field</span> <a name="l02439"></a>02439 <span class="comment"> * plus the effective data[] size</span> <a name="l02440"></a>02440 <span class="comment"> */</span> <a name="l02441"></a>02441 scControlStructExtended->size = <span class="keyword">sizeof</span>(*scControlStructExtended) <a name="l02442"></a>02442 - (<span class="keyword">sizeof</span>(<a class="code" href="structcontrol__struct__extended.html" title="contained in SCARD_CONTROL_EXTENDED Messages.">control_struct_extended</a>) - offsetof(<a class="code" href="structcontrol__struct__extended.html" title="contained in SCARD_CONTROL_EXTENDED Messages.">control_struct_extended</a>, data)) <a name="l02443"></a>02443 + cbSendLength; <a name="l02444"></a>02444 memcpy(scControlStructExtended->data, pbSendBuffer, cbSendLength); <a name="l02445"></a>02445 <a name="l02446"></a>02446 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca33919bd674d4f6cfa58178cdaf50cf38" title="used by SCardControl()">SCARD_CONTROL_EXTENDED</a>, <a name="l02447"></a>02447 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l02448"></a>02448 scControlStructExtended->size, <a name="l02449"></a>02449 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, buffer); <a name="l02450"></a>02450 <a name="l02451"></a>02451 <span class="keywordflow">if</span> (rv == -1) <a name="l02452"></a>02452 { <a name="l02453"></a>02453 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02454"></a>02454 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l02455"></a>02455 } <a name="l02456"></a>02456 <a name="l02457"></a>02457 <span class="comment">/*</span> <a name="l02458"></a>02458 <span class="comment"> * Read a message from the server</span> <a name="l02459"></a>02459 <span class="comment"> */</span> <a name="l02460"></a>02460 <span class="comment">/* read the first block */</span> <a name="l02461"></a>02461 rv = <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>(buffer, <span class="keyword">sizeof</span>(<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a>), <a name="l02462"></a>02462 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l02463"></a>02463 <span class="keywordflow">if</span> (rv == -1) <a name="l02464"></a>02464 { <a name="l02465"></a>02465 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02466"></a>02466 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l02467"></a>02467 } <a name="l02468"></a>02468 <a name="l02469"></a>02469 <span class="comment">/* we receive a sharedSegmentMsg and not a control_struct_extended */</span> <a name="l02470"></a>02470 scControlStructExtended = (<a class="code" href="structcontrol__struct__extended.html" title="contained in SCARD_CONTROL_EXTENDED Messages.">control_struct_extended</a> *)&(pmsgStruct -> data); <a name="l02471"></a>02471 <a name="l02472"></a>02472 <span class="comment">/* a second block is present */</span> <a name="l02473"></a>02473 <span class="keywordflow">if</span> (scControlStructExtended->size > <a class="code" href="pcscd_8h.html#a78a7d25c2d67ffb7f2bcb7f857a827f7" title="Transport msg len.">PCSCLITE_MAX_MESSAGE_SIZE</a>) <a name="l02474"></a>02474 { <a name="l02475"></a>02475 rv = <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>(buffer + <span class="keyword">sizeof</span>(<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a>), <a name="l02476"></a>02476 scControlStructExtended->size-<a class="code" href="pcscd_8h.html#a78a7d25c2d67ffb7f2bcb7f857a827f7" title="Transport msg len.">PCSCLITE_MAX_MESSAGE_SIZE</a>, <a name="l02477"></a>02477 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].<a class="code" href="struct__psContextMap.html#a4e3f21f7252b71833af88ba9f2864577" title="Client Connection ID.">dwClientID</a>, <a name="l02478"></a>02478 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l02479"></a>02479 <span class="keywordflow">if</span> (rv == -1) <a name="l02480"></a>02480 { <a name="l02481"></a>02481 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02482"></a>02482 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l02483"></a>02483 } <a name="l02484"></a>02484 } <a name="l02485"></a>02485 <a name="l02486"></a>02486 <span class="keywordflow">if</span> (scControlStructExtended -> 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="l02487"></a>02487 { <a name="l02488"></a>02488 <span class="comment">/*</span> <a name="l02489"></a>02489 <span class="comment"> * Copy and zero it so any secret information is not leaked</span> <a name="l02490"></a>02490 <span class="comment"> */</span> <a name="l02491"></a>02491 memcpy(pbRecvBuffer, scControlStructExtended -> data, <a name="l02492"></a>02492 scControlStructExtended -> dwBytesReturned); <a name="l02493"></a>02493 memset(scControlStructExtended -> data, 0x00, <a name="l02494"></a>02494 scControlStructExtended -> dwBytesReturned); <a name="l02495"></a>02495 } <a name="l02496"></a>02496 <a name="l02497"></a>02497 <span class="keywordflow">if</span> (NULL != lpBytesReturned) <a name="l02498"></a>02498 *lpBytesReturned = scControlStructExtended -> dwBytesReturned; <a name="l02499"></a>02499 <a name="l02500"></a>02500 rv = scControlStructExtended -> rv; <a name="l02501"></a>02501 } <a name="l02502"></a>02502 <span class="keywordflow">else</span> <a name="l02503"></a>02503 { <a name="l02504"></a>02504 scControlStruct.hCard = hCard; <a name="l02505"></a>02505 scControlStruct.dwControlCode = dwControlCode; <a name="l02506"></a>02506 scControlStruct.cbSendLength = cbSendLength; <a name="l02507"></a>02507 scControlStruct.cbRecvLength = cbRecvLength; <a name="l02508"></a>02508 memcpy(scControlStruct.pbSendBuffer, pbSendBuffer, cbSendLength); <a name="l02509"></a>02509 <a name="l02510"></a>02510 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca50f40e02c69625cb2e03e7094ce9d8b1" title="used by SCardControl()">SCARD_CONTROL</a>, <a name="l02511"></a>02511 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l02512"></a>02512 <span class="keyword">sizeof</span>(scControlStruct), <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, &scControlStruct); <a name="l02513"></a>02513 <a name="l02514"></a>02514 <span class="keywordflow">if</span> (rv == -1) <a name="l02515"></a>02515 { <a name="l02516"></a>02516 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02517"></a>02517 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l02518"></a>02518 } <a name="l02519"></a>02519 <a name="l02520"></a>02520 <span class="comment">/*</span> <a name="l02521"></a>02521 <span class="comment"> * Read a message from the server</span> <a name="l02522"></a>02522 <span class="comment"> */</span> <a name="l02523"></a>02523 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l02524"></a>02524 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l02525"></a>02525 <a name="l02526"></a>02526 <span class="keywordflow">if</span> (rv == -1) <a name="l02527"></a>02527 { <a name="l02528"></a>02528 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02529"></a>02529 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l02530"></a>02530 } <a name="l02531"></a>02531 <a name="l02532"></a>02532 memcpy(&scControlStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scControlStruct)); <a name="l02533"></a>02533 <a name="l02534"></a>02534 <span class="keywordflow">if</span> (NULL != lpBytesReturned) <a name="l02535"></a>02535 *lpBytesReturned = scControlStruct.dwBytesReturned; <a name="l02536"></a>02536 <a name="l02537"></a>02537 <span class="keywordflow">if</span> (scControlStruct.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="l02538"></a>02538 { <a name="l02539"></a>02539 <span class="comment">/*</span> <a name="l02540"></a>02540 <span class="comment"> * Copy and zero it so any secret information is not leaked</span> <a name="l02541"></a>02541 <span class="comment"> */</span> <a name="l02542"></a>02542 memcpy(pbRecvBuffer, scControlStruct.pbRecvBuffer, <a name="l02543"></a>02543 scControlStruct.cbRecvLength); <a name="l02544"></a>02544 memset(scControlStruct.pbRecvBuffer, 0x00, <a name="l02545"></a>02545 <span class="keyword">sizeof</span>(scControlStruct.pbRecvBuffer)); <a name="l02546"></a>02546 } <a name="l02547"></a>02547 <a name="l02548"></a>02548 rv = scControlStruct.rv; <a name="l02549"></a>02549 } <a name="l02550"></a>02550 <a name="l02551"></a>02551 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02552"></a>02552 <a name="l02553"></a>02553 PROFILE_END(rv) <a name="l02554"></a>02554 <a name="l02555"></a>02555 <span class="keywordflow">return</span> rv; <a name="l02556"></a>02556 } <a name="l02557"></a>02557 <a name="l02658"></a><a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602">02658</a> LONG <a class="code" href="group__API.html#gaacfec51917255b7a25b94c5104961602" title="This function get an attribute from the IFD Handler (reader driver).">SCardGetAttrib</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, DWORD dwAttrId, LPBYTE pbAttr, <a name="l02659"></a>02659 LPDWORD pcbAttrLen) <a name="l02660"></a>02660 { <a name="l02661"></a>02661 LONG ret; <a name="l02662"></a>02662 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buf = NULL; <a name="l02663"></a>02663 <a name="l02664"></a>02664 PROFILE_START <a name="l02665"></a>02665 <a name="l02666"></a>02666 <span class="keywordflow">if</span> (NULL == pcbAttrLen) <a name="l02667"></a>02667 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l02668"></a>02668 <a name="l02669"></a>02669 <span class="keywordflow">if</span> (<a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a> == *pcbAttrLen) <a name="l02670"></a>02670 { <a name="l02671"></a>02671 <span class="keywordflow">if</span> (NULL == pbAttr) <a name="l02672"></a>02672 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l02673"></a>02673 <a name="l02674"></a>02674 *pcbAttrLen = <a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>; <a name="l02675"></a>02675 buf = malloc(*pcbAttrLen); <a name="l02676"></a>02676 <span class="keywordflow">if</span> (NULL == buf) <a name="l02677"></a>02677 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l02678"></a>02678 <a name="l02679"></a>02679 *(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> **)pbAttr = buf; <a name="l02680"></a>02680 } <a name="l02681"></a>02681 <span class="keywordflow">else</span> <a name="l02682"></a>02682 { <a name="l02683"></a>02683 buf = pbAttr; <a name="l02684"></a>02684 <a name="l02685"></a>02685 <span class="comment">/* if only get the length */</span> <a name="l02686"></a>02686 <span class="keywordflow">if</span> (NULL == pbAttr) <a name="l02687"></a>02687 <span class="comment">/* use a reasonable size */</span> <a name="l02688"></a>02688 *pcbAttrLen = <a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>; <a name="l02689"></a>02689 } <a name="l02690"></a>02690 <a name="l02691"></a>02691 ret = SCardGetSetAttrib(hCard, <a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca9198ad4e3cd0613906124c5243e7c12e" title="used by SCardGetAttrib()">SCARD_GET_ATTRIB</a>, dwAttrId, buf, <a name="l02692"></a>02692 pcbAttrLen); <a name="l02693"></a>02693 <a name="l02694"></a>02694 PROFILE_END(ret) <a name="l02695"></a>02695 <a name="l02696"></a>02696 <span class="keywordflow">return</span> ret; <a name="l02697"></a>02697 } <a name="l02698"></a>02698 <a name="l02732"></a><a class="code" href="group__API.html#ga060f0038a4ddfd5dd2b8fadf3c3a2e4f">02732</a> LONG <a class="code" href="group__API.html#ga060f0038a4ddfd5dd2b8fadf3c3a2e4f" title="This function set an attribute of the IFD Handler.">SCardSetAttrib</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, DWORD dwAttrId, LPCBYTE pbAttr, <a name="l02733"></a>02733 DWORD cbAttrLen) <a name="l02734"></a>02734 { <a name="l02735"></a>02735 LONG ret; <a name="l02736"></a>02736 <a name="l02737"></a>02737 PROFILE_START <a name="l02738"></a>02738 <a name="l02739"></a>02739 <span class="keywordflow">if</span> (NULL == pbAttr || 0 == cbAttrLen) <a name="l02740"></a>02740 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l02741"></a>02741 <a name="l02742"></a>02742 ret = SCardGetSetAttrib(hCard, <a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca068f22e88bd4939797c3c359c9fbf075" title="used by SCardSetAttrib()">SCARD_SET_ATTRIB</a>, dwAttrId, (LPBYTE)pbAttr, <a name="l02743"></a>02743 &cbAttrLen); <a name="l02744"></a>02744 <a name="l02745"></a>02745 PROFILE_END(ret) <a name="l02746"></a>02746 <a name="l02747"></a>02747 <span class="keywordflow">return</span> ret; <a name="l02748"></a>02748 } <a name="l02749"></a>02749 <a name="l02750"></a>02750 <span class="keyword">static</span> LONG SCardGetSetAttrib(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, <span class="keywordtype">int</span> command, DWORD dwAttrId, <a name="l02751"></a>02751 LPBYTE pbAttr, LPDWORD pcbAttrLen) <a name="l02752"></a>02752 { <a name="l02753"></a>02753 LONG rv; <a name="l02754"></a>02754 <a class="code" href="structgetset__struct.html" title="contained in SCARD_GET_ATTRIB and Messages.">getset_struct</a> scGetSetStruct; <a name="l02755"></a>02755 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l02756"></a>02756 <span class="keywordtype">int</span> i; <a name="l02757"></a>02757 DWORD dwContextIndex, dwChannelIndex; <a name="l02758"></a>02758 <a name="l02759"></a>02759 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l02760"></a>02760 <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="l02761"></a>02761 <span class="keywordflow">return</span> rv; <a name="l02762"></a>02762 <a name="l02763"></a>02763 <span class="comment">/*</span> <a name="l02764"></a>02764 <span class="comment"> * Make sure this handle has been opened</span> <a name="l02765"></a>02765 <span class="comment"> */</span> <a name="l02766"></a>02766 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l02767"></a>02767 <span class="keywordflow">if</span> (rv == -1) <a name="l02768"></a>02768 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l02769"></a>02769 <a name="l02770"></a>02770 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02771"></a>02771 <a name="l02772"></a>02772 <span class="comment">/* check the handle is still valid */</span> <a name="l02773"></a>02773 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l02774"></a>02774 <span class="keywordflow">if</span> (rv == -1) <a name="l02775"></a>02775 <span class="comment">/* the handle is now invalid</span> <a name="l02776"></a>02776 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l02777"></a>02777 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l02778"></a>02778 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l02779"></a>02779 <a name="l02780"></a>02780 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcsclite_8h.html#af750e6e22c809de2b523c17e4a092036" title="Maximum readers context (a slot is count as a reader).">PCSCLITE_MAX_READERS_CONTEXTS</a>; i++) <a name="l02781"></a>02781 { <a name="l02782"></a>02782 <span class="keywordtype">char</span> *r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l02783"></a>02783 <a name="l02784"></a>02784 <span class="comment">/* by default r == NULL */</span> <a name="l02785"></a>02785 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l02786"></a>02786 <span class="keywordflow">break</span>; <a name="l02787"></a>02787 } <a name="l02788"></a>02788 <a name="l02789"></a>02789 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l02790"></a>02790 { <a name="l02791"></a>02791 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02792"></a>02792 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l02793"></a>02793 } <a name="l02794"></a>02794 <a name="l02795"></a>02795 <span class="keywordflow">if</span> (*pcbAttrLen > <a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>) <a name="l02796"></a>02796 { <a name="l02797"></a>02797 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02798"></a>02798 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l02799"></a>02799 } <a name="l02800"></a>02800 <a name="l02801"></a>02801 scGetSetStruct.hCard = hCard; <a name="l02802"></a>02802 scGetSetStruct.dwAttrId = dwAttrId; <a name="l02803"></a>02803 scGetSetStruct.cbAttrLen = *pcbAttrLen; <a name="l02804"></a>02804 scGetSetStruct.rv = <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l02805"></a>02805 memset(scGetSetStruct.pbAttr, 0, <span class="keyword">sizeof</span>(scGetSetStruct.pbAttr)); <a name="l02806"></a>02806 <span class="keywordflow">if</span> (<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca068f22e88bd4939797c3c359c9fbf075" title="used by SCardSetAttrib()">SCARD_SET_ATTRIB</a> == command) <a name="l02807"></a>02807 memcpy(scGetSetStruct.pbAttr, pbAttr, *pcbAttrLen); <a name="l02808"></a>02808 <a name="l02809"></a>02809 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(command, <a name="l02810"></a>02810 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <span class="keyword">sizeof</span>(scGetSetStruct), <a name="l02811"></a>02811 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, &scGetSetStruct); <a name="l02812"></a>02812 <a name="l02813"></a>02813 <span class="keywordflow">if</span> (rv == -1) <a name="l02814"></a>02814 { <a name="l02815"></a>02815 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02816"></a>02816 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l02817"></a>02817 } <a name="l02818"></a>02818 <a name="l02819"></a>02819 <span class="comment">/*</span> <a name="l02820"></a>02820 <span class="comment"> * Read a message from the server</span> <a name="l02821"></a>02821 <span class="comment"> */</span> <a name="l02822"></a>02822 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l02823"></a>02823 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l02824"></a>02824 <a name="l02825"></a>02825 <span class="keywordflow">if</span> (rv == -1) <a name="l02826"></a>02826 { <a name="l02827"></a>02827 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02828"></a>02828 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l02829"></a>02829 } <a name="l02830"></a>02830 <a name="l02831"></a>02831 memcpy(&scGetSetStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scGetSetStruct)); <a name="l02832"></a>02832 <a name="l02833"></a>02833 <span class="keywordflow">if</span> ((<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> == scGetSetStruct.rv) && (<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca9198ad4e3cd0613906124c5243e7c12e" title="used by SCardGetAttrib()">SCARD_GET_ATTRIB</a> == command)) <a name="l02834"></a>02834 { <a name="l02835"></a>02835 <span class="comment">/*</span> <a name="l02836"></a>02836 <span class="comment"> * Copy and zero it so any secret information is not leaked</span> <a name="l02837"></a>02837 <span class="comment"> */</span> <a name="l02838"></a>02838 <span class="keywordflow">if</span> (*pcbAttrLen < scGetSetStruct.cbAttrLen) <a name="l02839"></a>02839 { <a name="l02840"></a>02840 scGetSetStruct.cbAttrLen = *pcbAttrLen; <a name="l02841"></a>02841 scGetSetStruct.rv = <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l02842"></a>02842 } <a name="l02843"></a>02843 <span class="keywordflow">else</span> <a name="l02844"></a>02844 *pcbAttrLen = scGetSetStruct.cbAttrLen; <a name="l02845"></a>02845 <a name="l02846"></a>02846 <span class="keywordflow">if</span> (pbAttr) <a name="l02847"></a>02847 memcpy(pbAttr, scGetSetStruct.pbAttr, scGetSetStruct.cbAttrLen); <a name="l02848"></a>02848 <a name="l02849"></a>02849 memset(scGetSetStruct.pbAttr, 0x00, <span class="keyword">sizeof</span>(scGetSetStruct.pbAttr)); <a name="l02850"></a>02850 } <a name="l02851"></a>02851 <a name="l02852"></a>02852 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02853"></a>02853 <a name="l02854"></a>02854 <span class="keywordflow">return</span> scGetSetStruct.rv; <a name="l02855"></a>02855 } <a name="l02856"></a>02856 <a name="l02915"></a><a class="code" href="group__API.html#gac60e9e6c93b04e61594a3a8f69ee1898">02915</a> LONG <a class="code" href="group__API.html#gac60e9e6c93b04e61594a3a8f69ee1898" title="This function sends an APDU to the smart card contained in the reader connected to...">SCardTransmit</a>(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, <a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">LPCSCARD_IO_REQUEST</a> pioSendPci, <a name="l02916"></a>02916 LPCBYTE pbSendBuffer, DWORD cbSendLength, <a name="l02917"></a>02917 <a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">LPSCARD_IO_REQUEST</a> pioRecvPci, LPBYTE pbRecvBuffer, <a name="l02918"></a>02918 LPDWORD pcbRecvLength) <a name="l02919"></a>02919 { <a name="l02920"></a>02920 LONG rv; <a name="l02921"></a>02921 <span class="keywordtype">int</span> i; <a name="l02922"></a>02922 DWORD dwContextIndex, dwChannelIndex; <a name="l02923"></a>02923 <a name="l02924"></a>02924 PROFILE_START <a name="l02925"></a>02925 <a name="l02926"></a>02926 <span class="keywordflow">if</span> (pbSendBuffer == NULL || pbRecvBuffer == NULL || <a name="l02927"></a>02927 pcbRecvLength == NULL || pioSendPci == NULL) <a name="l02928"></a>02928 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l02929"></a>02929 <a name="l02930"></a>02930 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l02931"></a>02931 <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="l02932"></a>02932 <span class="keywordflow">return</span> rv; <a name="l02933"></a>02933 <a name="l02934"></a>02934 <span class="comment">/*</span> <a name="l02935"></a>02935 <span class="comment"> * Make sure this handle has been opened</span> <a name="l02936"></a>02936 <span class="comment"> */</span> <a name="l02937"></a>02937 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l02938"></a>02938 <span class="keywordflow">if</span> (rv == -1) <a name="l02939"></a>02939 { <a name="l02940"></a>02940 *pcbRecvLength = 0; <a name="l02941"></a>02941 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l02942"></a>02942 } <a name="l02943"></a>02943 <a name="l02944"></a>02944 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02945"></a>02945 <a name="l02946"></a>02946 <span class="comment">/* check the handle is still valid */</span> <a name="l02947"></a>02947 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex); <a name="l02948"></a>02948 <span class="keywordflow">if</span> (rv == -1) <a name="l02949"></a>02949 <span class="comment">/* the handle is now invalid</span> <a name="l02950"></a>02950 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l02951"></a>02951 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l02952"></a>02952 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l02953"></a>02953 <a name="l02954"></a>02954 <span class="keywordflow">for</span> (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++) <a name="l02955"></a>02955 { <a name="l02956"></a>02956 <span class="keywordtype">char</span> *r = <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[dwChannelIndex].readerName; <a name="l02957"></a>02957 <a name="l02958"></a>02958 <span class="comment">/* by default r == NULL */</span> <a name="l02959"></a>02959 <span class="keywordflow">if</span> (r && strcmp(r, (readerStates[i])->readerName) == 0) <a name="l02960"></a>02960 <span class="keywordflow">break</span>; <a name="l02961"></a>02961 } <a name="l02962"></a>02962 <a name="l02963"></a>02963 <span class="keywordflow">if</span> (i == PCSCLITE_MAX_READERS_CONTEXTS) <a name="l02964"></a>02964 { <a name="l02965"></a>02965 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02966"></a>02966 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad70bc694ffdf40c3b494d9239160d69d" title="The specified reader is not currently available for use.">SCARD_E_READER_UNAVAILABLE</a>; <a name="l02967"></a>02967 } <a name="l02968"></a>02968 <a name="l02969"></a>02969 <span class="keywordflow">if</span> ((cbSendLength > <a class="code" href="pcsclite_8h.html#ae128d4b6df34e2dfdb6216b31bae2cc6" title="enhanced (64K + APDU + Lc + Le) Tx/Rx Buffer">MAX_BUFFER_SIZE_EXTENDED</a>) <a name="l02970"></a>02970 || (*pcbRecvLength > <a class="code" href="pcsclite_8h.html#ae128d4b6df34e2dfdb6216b31bae2cc6" title="enhanced (64K + APDU + Lc + Le) Tx/Rx Buffer">MAX_BUFFER_SIZE_EXTENDED</a>)) <a name="l02971"></a>02971 { <a name="l02972"></a>02972 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l02973"></a>02973 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l02974"></a>02974 } <a name="l02975"></a>02975 <a name="l02976"></a>02976 <span class="keywordflow">if</span> ((cbSendLength > <a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>) || (*pcbRecvLength > <a class="code" href="pcsclite_8h.html#ad4d796b98c583d49e83adabd74a63bf6" title="Maximum Tx/Rx Buffer for short APDU.">MAX_BUFFER_SIZE</a>)) <a name="l02977"></a>02977 { <a name="l02978"></a>02978 <span class="comment">/* extended APDU */</span> <a name="l02979"></a>02979 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buffer[<span class="keyword">sizeof</span>(<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a>) + <a class="code" href="pcsclite_8h.html#ae128d4b6df34e2dfdb6216b31bae2cc6" title="enhanced (64K + APDU + Lc + Le) Tx/Rx Buffer">MAX_BUFFER_SIZE_EXTENDED</a>]; <a name="l02980"></a>02980 <a class="code" href="structtransmit__struct__extended.html" title="contained in SCARD_TRANSMIT_EXTENDED Messages.">transmit_struct_extended</a> *scTransmitStructExtended = (<a class="code" href="structtransmit__struct__extended.html" title="contained in SCARD_TRANSMIT_EXTENDED Messages.">transmit_struct_extended</a> *)buffer; <a name="l02981"></a>02981 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> *pmsgStruct = (<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">psharedSegmentMsg</a>)buffer; <a name="l02982"></a>02982 <a name="l02983"></a>02983 scTransmitStructExtended->hCard = hCard; <a name="l02984"></a>02984 scTransmitStructExtended->cbSendLength = cbSendLength; <a name="l02985"></a>02985 scTransmitStructExtended->pcbRecvLength = *pcbRecvLength; <a name="l02986"></a>02986 <span class="comment">/* The size of data to send is the size of</span> <a name="l02987"></a>02987 <span class="comment"> * struct control_struct_extended WITHOUT the data[] field</span> <a name="l02988"></a>02988 <span class="comment"> * plus the effective data[] size</span> <a name="l02989"></a>02989 <span class="comment"> */</span> <a name="l02990"></a>02990 scTransmitStructExtended->size = <span class="keyword">sizeof</span>(*scTransmitStructExtended) <a name="l02991"></a>02991 - (<span class="keyword">sizeof</span>(<a class="code" href="structtransmit__struct__extended.html" title="contained in SCARD_TRANSMIT_EXTENDED Messages.">transmit_struct_extended</a>) - offsetof(<a class="code" href="structtransmit__struct__extended.html" title="contained in SCARD_TRANSMIT_EXTENDED Messages.">transmit_struct_extended</a>, data)) <a name="l02992"></a>02992 + cbSendLength; <a name="l02993"></a>02993 scTransmitStructExtended->ioSendPciProtocol = pioSendPci-><a class="code" href="structSCARD__IO__REQUEST.html#a06a981d5eb5bae479767d77641d50002" title="Protocol identifier.">dwProtocol</a>; <a name="l02994"></a>02994 scTransmitStructExtended->ioSendPciLength = pioSendPci-><a class="code" href="structSCARD__IO__REQUEST.html#a90993ce745546245b494a35a9559a083" title="Protocol Control Inf Length.">cbPciLength</a>; <a name="l02995"></a>02995 memcpy(scTransmitStructExtended->data, pbSendBuffer, cbSendLength); <a name="l02996"></a>02996 scTransmitStructExtended->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="l02997"></a>02997 <a name="l02998"></a>02998 <span class="keywordflow">if</span> (pioRecvPci) <a name="l02999"></a>02999 { <a name="l03000"></a>03000 scTransmitStructExtended->ioRecvPciProtocol = pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a06a981d5eb5bae479767d77641d50002" title="Protocol identifier.">dwProtocol</a>; <a name="l03001"></a>03001 scTransmitStructExtended->ioRecvPciLength = pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a90993ce745546245b494a35a9559a083" title="Protocol Control Inf Length.">cbPciLength</a>; <a name="l03002"></a>03002 } <a name="l03003"></a>03003 <span class="keywordflow">else</span> <a name="l03004"></a>03004 { <a name="l03005"></a>03005 scTransmitStructExtended->ioRecvPciProtocol = <a class="code" href="pcsclite_8h.html#ad3896343af44a54d232d407719abad95" title="IFD determines prot.">SCARD_PROTOCOL_ANY</a>; <a name="l03006"></a>03006 scTransmitStructExtended->ioRecvPciLength = <span class="keyword">sizeof</span>(<a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">SCARD_IO_REQUEST</a>); <a name="l03007"></a>03007 } <a name="l03008"></a>03008 <a name="l03009"></a>03009 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dca35bfc3eb2607c5bd387d1f8566de814e" title="used by SCardTransmit()">SCARD_TRANSMIT_EXTENDED</a>, <a name="l03010"></a>03010 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l03011"></a>03011 scTransmitStructExtended->size, <a name="l03012"></a>03012 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, buffer); <a name="l03013"></a>03013 <a name="l03014"></a>03014 <span class="keywordflow">if</span> (rv == -1) <a name="l03015"></a>03015 { <a name="l03016"></a>03016 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03017"></a>03017 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l03018"></a>03018 } <a name="l03019"></a>03019 <a name="l03020"></a>03020 <span class="comment">/*</span> <a name="l03021"></a>03021 <span class="comment"> * Read a message from the server</span> <a name="l03022"></a>03022 <span class="comment"> */</span> <a name="l03023"></a>03023 <span class="comment">/* read the first block */</span> <a name="l03024"></a>03024 rv = <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>(buffer, <span class="keyword">sizeof</span>(<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a>), <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l03025"></a>03025 <span class="keywordflow">if</span> (rv == -1) <a name="l03026"></a>03026 { <a name="l03027"></a>03027 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03028"></a>03028 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l03029"></a>03029 } <a name="l03030"></a>03030 <a name="l03031"></a>03031 <span class="comment">/* we receive a sharedSegmentMsg and not a transmit_struct_extended */</span> <a name="l03032"></a>03032 scTransmitStructExtended = (<a class="code" href="structtransmit__struct__extended.html" title="contained in SCARD_TRANSMIT_EXTENDED Messages.">transmit_struct_extended</a> *)&(pmsgStruct -> data); <a name="l03033"></a>03033 <a name="l03034"></a>03034 <span class="comment">/* a second block is present */</span> <a name="l03035"></a>03035 <span class="keywordflow">if</span> (scTransmitStructExtended->size > <a class="code" href="pcscd_8h.html#a78a7d25c2d67ffb7f2bcb7f857a827f7" title="Transport msg len.">PCSCLITE_MAX_MESSAGE_SIZE</a>) <a name="l03036"></a>03036 { <a name="l03037"></a>03037 rv = <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>(buffer + <span class="keyword">sizeof</span>(<a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a>), <a name="l03038"></a>03038 scTransmitStructExtended->size-<a class="code" href="pcscd_8h.html#a78a7d25c2d67ffb7f2bcb7f857a827f7" title="Transport msg len.">PCSCLITE_MAX_MESSAGE_SIZE</a>, <a name="l03039"></a>03039 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].<a class="code" href="struct__psContextMap.html#a4e3f21f7252b71833af88ba9f2864577" title="Client Connection ID.">dwClientID</a>, <a name="l03040"></a>03040 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l03041"></a>03041 <span class="keywordflow">if</span> (rv == -1) <a name="l03042"></a>03042 { <a name="l03043"></a>03043 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03044"></a>03044 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l03045"></a>03045 } <a name="l03046"></a>03046 } <a name="l03047"></a>03047 <a name="l03048"></a>03048 <span class="keywordflow">if</span> (scTransmitStructExtended -> 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="l03049"></a>03049 { <a name="l03050"></a>03050 <span class="comment">/*</span> <a name="l03051"></a>03051 <span class="comment"> * Copy and zero it so any secret information is not leaked</span> <a name="l03052"></a>03052 <span class="comment"> */</span> <a name="l03053"></a>03053 memcpy(pbRecvBuffer, scTransmitStructExtended -> data, <a name="l03054"></a>03054 scTransmitStructExtended -> pcbRecvLength); <a name="l03055"></a>03055 memset(scTransmitStructExtended -> data, 0x00, <a name="l03056"></a>03056 scTransmitStructExtended -> pcbRecvLength); <a name="l03057"></a>03057 <a name="l03058"></a>03058 <span class="keywordflow">if</span> (pioRecvPci) <a name="l03059"></a>03059 { <a name="l03060"></a>03060 pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a06a981d5eb5bae479767d77641d50002" title="Protocol identifier.">dwProtocol</a> = scTransmitStructExtended->ioRecvPciProtocol; <a name="l03061"></a>03061 pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a90993ce745546245b494a35a9559a083" title="Protocol Control Inf Length.">cbPciLength</a> = scTransmitStructExtended->ioRecvPciLength; <a name="l03062"></a>03062 } <a name="l03063"></a>03063 } <a name="l03064"></a>03064 <a name="l03065"></a>03065 *pcbRecvLength = scTransmitStructExtended -> pcbRecvLength; <a name="l03066"></a>03066 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03067"></a>03067 <a name="l03068"></a>03068 rv = scTransmitStructExtended -> rv; <a name="l03069"></a>03069 } <a name="l03070"></a>03070 <span class="keywordflow">else</span> <a name="l03071"></a>03071 { <a name="l03072"></a>03072 <span class="comment">/* short APDU */</span> <a name="l03073"></a>03073 <a class="code" href="structtransmit__struct.html" title="contained in SCARD_TRANSMIT Messages.">transmit_struct</a> scTransmitStruct; <a name="l03074"></a>03074 <a class="code" href="structrxSharedSegment.html" title="General structure for client/serve message data exchange.">sharedSegmentMsg</a> msgStruct; <a name="l03075"></a>03075 <a name="l03076"></a>03076 scTransmitStruct.hCard = hCard; <a name="l03077"></a>03077 scTransmitStruct.cbSendLength = cbSendLength; <a name="l03078"></a>03078 scTransmitStruct.pcbRecvLength = *pcbRecvLength; <a name="l03079"></a>03079 scTransmitStruct.ioSendPciProtocol = pioSendPci-><a class="code" href="structSCARD__IO__REQUEST.html#a06a981d5eb5bae479767d77641d50002" title="Protocol identifier.">dwProtocol</a>; <a name="l03080"></a>03080 scTransmitStruct.ioSendPciLength = pioSendPci-><a class="code" href="structSCARD__IO__REQUEST.html#a90993ce745546245b494a35a9559a083" title="Protocol Control Inf Length.">cbPciLength</a>; <a name="l03081"></a>03081 memcpy(scTransmitStruct.pbSendBuffer, pbSendBuffer, cbSendLength); <a name="l03082"></a>03082 memset(scTransmitStruct.pbSendBuffer+cbSendLength, 0, <span class="keyword">sizeof</span>(scTransmitStruct.pbSendBuffer)-cbSendLength); <a name="l03083"></a>03083 memset(scTransmitStruct.pbRecvBuffer, 0, <span class="keyword">sizeof</span>(scTransmitStruct.pbRecvBuffer)); <a name="l03084"></a>03084 scTransmitStruct.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="l03085"></a>03085 <a name="l03086"></a>03086 <span class="keywordflow">if</span> (pioRecvPci) <a name="l03087"></a>03087 { <a name="l03088"></a>03088 scTransmitStruct.ioRecvPciProtocol = pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a06a981d5eb5bae479767d77641d50002" title="Protocol identifier.">dwProtocol</a>; <a name="l03089"></a>03089 scTransmitStruct.ioRecvPciLength = pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a90993ce745546245b494a35a9559a083" title="Protocol Control Inf Length.">cbPciLength</a>; <a name="l03090"></a>03090 } <a name="l03091"></a>03091 <span class="keywordflow">else</span> <a name="l03092"></a>03092 { <a name="l03093"></a>03093 scTransmitStruct.ioRecvPciProtocol = <a class="code" href="pcsclite_8h.html#ad3896343af44a54d232d407719abad95" title="IFD determines prot.">SCARD_PROTOCOL_ANY</a>; <a name="l03094"></a>03094 scTransmitStruct.ioRecvPciLength = <span class="keyword">sizeof</span>(<a class="code" href="structSCARD__IO__REQUEST.html" title="Protocol Control Information (PCI).">SCARD_IO_REQUEST</a>); <a name="l03095"></a>03095 } <a name="l03096"></a>03096 <a name="l03097"></a>03097 rv = <a class="code" href="winscard__msg_8c.html#a00bf262b8a867838e4a851da8123e349" title="Wrapper for the SHMMessageSend() function.">WrapSHMWrite</a>(<a class="code" href="winscard__msg_8h.html#add241284f0460327d523aec6e1cd17dcaaa1c43a9cc7497df780b9e5a81a3abcb" title="used by SCardTransmit()">SCARD_TRANSMIT</a>, <a name="l03098"></a>03098 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <span class="keyword">sizeof</span>(scTransmitStruct), <a name="l03099"></a>03099 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>, (<span class="keywordtype">void</span> *) &scTransmitStruct); <a name="l03100"></a>03100 <a name="l03101"></a>03101 <span class="keywordflow">if</span> (rv == -1) <a name="l03102"></a>03102 { <a name="l03103"></a>03103 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03104"></a>03104 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l03105"></a>03105 } <a name="l03106"></a>03106 <a name="l03107"></a>03107 <span class="comment">/*</span> <a name="l03108"></a>03108 <span class="comment"> * Read a message from the server</span> <a name="l03109"></a>03109 <span class="comment"> */</span> <a name="l03110"></a>03110 rv = <a class="code" href="winscard__msg_8c.html#a5e0014bbafe9bcd7df5f44a6ebc6e2f0" title="Wrapper for the SHMMessageReceive() function.">SHMClientRead</a>(&msgStruct, <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].dwClientID, <a name="l03111"></a>03111 <a class="code" href="pcscd_8h.html#af1d43fd078faf2c4fae301e649cc81af" title="Attempts to reach sv.">PCSCLITE_CLIENT_ATTEMPTS</a>); <a name="l03112"></a>03112 <a name="l03113"></a>03113 memcpy(&scTransmitStruct, &msgStruct.data, <span class="keyword">sizeof</span>(scTransmitStruct)); <a name="l03114"></a>03114 <a name="l03115"></a>03115 <span class="keywordflow">if</span> (rv == -1) <a name="l03116"></a>03116 { <a name="l03117"></a>03117 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03118"></a>03118 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a93d3cf468d69423eab1d478a7a870408" title="An internal communications error has been detected.">SCARD_F_COMM_ERROR</a>; <a name="l03119"></a>03119 } <a name="l03120"></a>03120 <a name="l03121"></a>03121 <span class="comment">/*</span> <a name="l03122"></a>03122 <span class="comment"> * Zero it and free it so any secret information cannot be leaked</span> <a name="l03123"></a>03123 <span class="comment"> */</span> <a name="l03124"></a>03124 memset(scTransmitStruct.pbSendBuffer, 0x00, cbSendLength); <a name="l03125"></a>03125 <a name="l03126"></a>03126 <span class="keywordflow">if</span> (scTransmitStruct.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="l03127"></a>03127 { <a name="l03128"></a>03128 <span class="comment">/*</span> <a name="l03129"></a>03129 <span class="comment"> * Copy and zero it so any secret information is not leaked</span> <a name="l03130"></a>03130 <span class="comment"> */</span> <a name="l03131"></a>03131 memcpy(pbRecvBuffer, scTransmitStruct.pbRecvBuffer, <a name="l03132"></a>03132 scTransmitStruct.pcbRecvLength); <a name="l03133"></a>03133 memset(scTransmitStruct.pbRecvBuffer, 0x00, <a name="l03134"></a>03134 scTransmitStruct.pcbRecvLength); <a name="l03135"></a>03135 <a name="l03136"></a>03136 <span class="keywordflow">if</span> (pioRecvPci) <a name="l03137"></a>03137 { <a name="l03138"></a>03138 pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a06a981d5eb5bae479767d77641d50002" title="Protocol identifier.">dwProtocol</a> = scTransmitStruct.ioRecvPciProtocol; <a name="l03139"></a>03139 pioRecvPci-><a class="code" href="structSCARD__IO__REQUEST.html#a90993ce745546245b494a35a9559a083" title="Protocol Control Inf Length.">cbPciLength</a> = scTransmitStruct.ioRecvPciLength; <a name="l03140"></a>03140 } <a name="l03141"></a>03141 } <a name="l03142"></a>03142 <a name="l03143"></a>03143 *pcbRecvLength = scTransmitStruct.pcbRecvLength; <a name="l03144"></a>03144 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03145"></a>03145 <a name="l03146"></a>03146 rv = scTransmitStruct.rv; <a name="l03147"></a>03147 } <a name="l03148"></a>03148 <a name="l03149"></a>03149 PROFILE_END(rv) <a name="l03150"></a>03150 <a name="l03151"></a>03151 <span class="keywordflow">return</span> rv; <a name="l03152"></a>03152 } <a name="l03153"></a>03153 <a name="l03202"></a><a class="code" href="group__API.html#ga93b07815789b3cf2629d439ecf20f0d9">03202</a> LONG <a class="code" href="group__API.html#ga93b07815789b3cf2629d439ecf20f0d9" title="This function returns a list of currently available readers on the system.">SCardListReaders</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, <span class="comment">/*@unused@*/</span> LPCSTR mszGroups, <a name="l03203"></a>03203 LPSTR mszReaders, LPDWORD pcchReaders) <a name="l03204"></a>03204 { <a name="l03205"></a>03205 DWORD dwReadersLen; <a name="l03206"></a>03206 <span class="keywordtype">int</span> i; <a name="l03207"></a>03207 LONG dwContextIndex; <a name="l03208"></a>03208 LONG 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="l03209"></a>03209 <span class="keywordtype">char</span> *buf = NULL; <a name="l03210"></a>03210 <a name="l03211"></a>03211 (void)mszGroups; <a name="l03212"></a>03212 PROFILE_START <a name="l03213"></a>03213 <a name="l03214"></a>03214 <span class="comment">/*</span> <a name="l03215"></a>03215 <span class="comment"> * Check for NULL parameters</span> <a name="l03216"></a>03216 <span class="comment"> */</span> <a name="l03217"></a>03217 <span class="keywordflow">if</span> (pcchReaders == NULL) <a name="l03218"></a>03218 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l03219"></a>03219 <a name="l03220"></a>03220 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l03221"></a>03221 <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="l03222"></a>03222 <span class="keywordflow">return</span> rv; <a name="l03223"></a>03223 <a name="l03224"></a>03224 <span class="comment">/*</span> <a name="l03225"></a>03225 <span class="comment"> * Make sure this context has been opened</span> <a name="l03226"></a>03226 <span class="comment"> */</span> <a name="l03227"></a>03227 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l03228"></a>03228 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l03229"></a>03229 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03230"></a>03230 <a name="l03231"></a>03231 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03232"></a>03232 <a name="l03233"></a>03233 <span class="comment">/* check the context is still opened */</span> <a name="l03234"></a>03234 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l03235"></a>03235 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l03236"></a>03236 <span class="comment">/* the context is now invalid</span> <a name="l03237"></a>03237 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l03238"></a>03238 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l03239"></a>03239 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03240"></a>03240 <a name="l03241"></a>03241 dwReadersLen = 0; <a name="l03242"></a>03242 <span class="keywordflow">for</span> (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++) <a name="l03243"></a>03243 <span class="keywordflow">if</span> ((readerStates[i])->readerID != 0) <a name="l03244"></a>03244 dwReadersLen += strlen((readerStates[i])->readerName) + 1; <a name="l03245"></a>03245 <a name="l03246"></a>03246 <span class="comment">/* for the last NULL byte */</span> <a name="l03247"></a>03247 dwReadersLen += 1; <a name="l03248"></a>03248 <a name="l03249"></a>03249 <span class="keywordflow">if</span> (1 == dwReadersLen) <a name="l03250"></a>03250 { <a name="l03251"></a>03251 rv = <a class="code" href="pcsclite_8h.html#a81b59e9319d3fcd0d957d98781b3ebd2" title="Cannot find a smart card reader.">SCARD_E_NO_READERS_AVAILABLE</a>; <a name="l03252"></a>03252 <span class="keywordflow">goto</span> end; <a name="l03253"></a>03253 } <a name="l03254"></a>03254 <a name="l03255"></a>03255 <span class="keywordflow">if</span> (<a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a> == *pcchReaders) <a name="l03256"></a>03256 { <a name="l03257"></a>03257 buf = malloc(dwReadersLen); <a name="l03258"></a>03258 <span class="keywordflow">if</span> (NULL == buf) <a name="l03259"></a>03259 { <a name="l03260"></a>03260 rv = <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l03261"></a>03261 <span class="keywordflow">goto</span> end; <a name="l03262"></a>03262 } <a name="l03263"></a>03263 <span class="keywordflow">if</span> (NULL == mszReaders) <a name="l03264"></a>03264 { <a name="l03265"></a>03265 rv = <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l03266"></a>03266 <span class="keywordflow">goto</span> end; <a name="l03267"></a>03267 } <a name="l03268"></a>03268 *(<span class="keywordtype">char</span> **)mszReaders = buf; <a name="l03269"></a>03269 } <a name="l03270"></a>03270 <span class="keywordflow">else</span> <a name="l03271"></a>03271 { <a name="l03272"></a>03272 buf = mszReaders; <a name="l03273"></a>03273 <a name="l03274"></a>03274 <span class="comment">/* not enough place to store the reader names */</span> <a name="l03275"></a>03275 <span class="keywordflow">if</span> ((NULL != mszReaders) && (*pcchReaders < dwReadersLen)) <a name="l03276"></a>03276 { <a name="l03277"></a>03277 rv = <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l03278"></a>03278 <span class="keywordflow">goto</span> end; <a name="l03279"></a>03279 } <a name="l03280"></a>03280 } <a name="l03281"></a>03281 <a name="l03282"></a>03282 <span class="keywordflow">if</span> (mszReaders == NULL) <span class="comment">/* text array not allocated */</span> <a name="l03283"></a>03283 <span class="keywordflow">goto</span> end; <a name="l03284"></a>03284 <a name="l03285"></a>03285 <span class="keywordflow">for</span> (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++) <a name="l03286"></a>03286 { <a name="l03287"></a>03287 <span class="keywordflow">if</span> ((readerStates[i])->readerID != 0) <a name="l03288"></a>03288 { <a name="l03289"></a>03289 <span class="comment">/*</span> <a name="l03290"></a>03290 <span class="comment"> * Build the multi-string</span> <a name="l03291"></a>03291 <span class="comment"> */</span> <a name="l03292"></a>03292 strcpy(buf, (readerStates[i])->readerName); <a name="l03293"></a>03293 buf += strlen((readerStates[i])->readerName)+1; <a name="l03294"></a>03294 } <a name="l03295"></a>03295 } <a name="l03296"></a>03296 *buf = <span class="charliteral">'\0'</span>; <span class="comment">/* Add the last null */</span> <a name="l03297"></a>03297 <a name="l03298"></a>03298 end: <a name="l03299"></a>03299 <span class="comment">/* set the reader names length */</span> <a name="l03300"></a>03300 *pcchReaders = dwReadersLen; <a name="l03301"></a>03301 <a name="l03302"></a>03302 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03303"></a>03303 <a name="l03304"></a>03304 PROFILE_END(rv) <a name="l03305"></a>03305 <a name="l03306"></a>03306 <span class="keywordflow">return</span> rv; <a name="l03307"></a>03307 } <a name="l03308"></a>03308 <a name="l03321"></a><a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961">03321</a> LONG <a class="code" href="group__API.html#ga0522241e3180cb05dfd166e28930e961" title="Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE...">SCardFreeMemory</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, LPCVOID pvMem) <a name="l03322"></a>03322 { <a name="l03323"></a>03323 LONG 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="l03324"></a>03324 LONG dwContextIndex; <a name="l03325"></a>03325 <a name="l03326"></a>03326 PROFILE_START <a name="l03327"></a>03327 <a name="l03328"></a>03328 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l03329"></a>03329 <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="l03330"></a>03330 <span class="keywordflow">return</span> rv; <a name="l03331"></a>03331 <a name="l03332"></a>03332 <span class="comment">/*</span> <a name="l03333"></a>03333 <span class="comment"> * Make sure this context has been opened</span> <a name="l03334"></a>03334 <span class="comment"> */</span> <a name="l03335"></a>03335 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l03336"></a>03336 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l03337"></a>03337 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03338"></a>03338 <a name="l03339"></a>03339 free((<span class="keywordtype">void</span> *)pvMem); <a name="l03340"></a>03340 <a name="l03341"></a>03341 PROFILE_END(rv) <a name="l03342"></a>03342 <a name="l03343"></a>03343 <span class="keywordflow">return</span> rv; <a name="l03344"></a>03344 } <a name="l03345"></a>03345 <a name="l03395"></a><a class="code" href="group__API.html#ga9d970d086d5218e080d0079d63f9d496">03395</a> LONG <a class="code" href="group__API.html#ga9d970d086d5218e080d0079d63f9d496" title="This function returns a list of currently available reader groups on the system.">SCardListReaderGroups</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, LPSTR mszGroups, <a name="l03396"></a>03396 LPDWORD pcchGroups) <a name="l03397"></a>03397 { <a name="l03398"></a>03398 LONG 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="l03399"></a>03399 LONG dwContextIndex; <a name="l03400"></a>03400 <span class="keywordtype">char</span> *buf = NULL; <a name="l03401"></a>03401 <a name="l03402"></a>03402 PROFILE_START <a name="l03403"></a>03403 <a name="l03404"></a>03404 <span class="comment">/* Multi-string with two trailing \0 */</span> <a name="l03405"></a>03405 <span class="keyword">const</span> <span class="keywordtype">char</span> ReaderGroup[] = <span class="stringliteral">"SCard$DefaultReaders\0"</span>; <a name="l03406"></a>03406 <span class="keyword">const</span> <span class="keywordtype">int</span> dwGroups = <span class="keyword">sizeof</span>(ReaderGroup); <a name="l03407"></a>03407 <a name="l03408"></a>03408 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l03409"></a>03409 <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="l03410"></a>03410 <span class="keywordflow">return</span> rv; <a name="l03411"></a>03411 <a name="l03412"></a>03412 <span class="comment">/*</span> <a name="l03413"></a>03413 <span class="comment"> * Make sure this context has been opened</span> <a name="l03414"></a>03414 <span class="comment"> */</span> <a name="l03415"></a>03415 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l03416"></a>03416 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l03417"></a>03417 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03418"></a>03418 <a name="l03419"></a>03419 (void)SYS_MutexLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03420"></a>03420 <a name="l03421"></a>03421 <span class="comment">/* check the context is still opened */</span> <a name="l03422"></a>03422 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l03423"></a>03423 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l03424"></a>03424 <span class="comment">/* the context is now invalid</span> <a name="l03425"></a>03425 <span class="comment"> * -> another thread may have called SCardReleaseContext</span> <a name="l03426"></a>03426 <span class="comment"> * -> so the mMutex has been unlocked */</span> <a name="l03427"></a>03427 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03428"></a>03428 <a name="l03429"></a>03429 <span class="keywordflow">if</span> (<a class="code" href="pcsclite_8h.html#a67db0943aeb13f9f468eaae39b5ff1b0" title="see SCardFreeMemory()">SCARD_AUTOALLOCATE</a> == *pcchGroups) <a name="l03430"></a>03430 { <a name="l03431"></a>03431 buf = malloc(dwGroups); <a name="l03432"></a>03432 <span class="keywordflow">if</span> (NULL == buf) <a name="l03433"></a>03433 { <a name="l03434"></a>03434 rv = <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l03435"></a>03435 <span class="keywordflow">goto</span> end; <a name="l03436"></a>03436 } <a name="l03437"></a>03437 <span class="keywordflow">if</span> (NULL == mszGroups) <a name="l03438"></a>03438 { <a name="l03439"></a>03439 rv = <a class="code" href="pcsclite_8h.html#a47a6da10ec4ea2cbebfcc4b2a93d786f" title="One or more of the supplied parameters could not be properly interpreted.">SCARD_E_INVALID_PARAMETER</a>; <a name="l03440"></a>03440 <span class="keywordflow">goto</span> end; <a name="l03441"></a>03441 } <a name="l03442"></a>03442 *(<span class="keywordtype">char</span> **)mszGroups = buf; <a name="l03443"></a>03443 } <a name="l03444"></a>03444 <span class="keywordflow">else</span> <a name="l03445"></a>03445 { <a name="l03446"></a>03446 buf = mszGroups; <a name="l03447"></a>03447 <a name="l03448"></a>03448 <span class="keywordflow">if</span> ((NULL != mszGroups) && (*pcchGroups < dwGroups)) <a name="l03449"></a>03449 { <a name="l03450"></a>03450 rv = <a class="code" href="pcsclite_8h.html#aac3f8d945f8a0e667e0926daaa18dc57" title="The data buffer to receive returned data is too small for the returned data.">SCARD_E_INSUFFICIENT_BUFFER</a>; <a name="l03451"></a>03451 <span class="keywordflow">goto</span> end; <a name="l03452"></a>03452 } <a name="l03453"></a>03453 } <a name="l03454"></a>03454 <a name="l03455"></a>03455 <span class="keywordflow">if</span> (buf) <a name="l03456"></a>03456 memcpy(buf, ReaderGroup, dwGroups); <a name="l03457"></a>03457 <a name="l03458"></a>03458 end: <a name="l03459"></a>03459 *pcchGroups = dwGroups; <a name="l03460"></a>03460 <a name="l03461"></a>03461 (void)SYS_MutexUnLock(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].mMutex); <a name="l03462"></a>03462 <a name="l03463"></a>03463 PROFILE_END(rv) <a name="l03464"></a>03464 <a name="l03465"></a>03465 <span class="keywordflow">return</span> rv; <a name="l03466"></a>03466 } <a name="l03467"></a>03467 <a name="l03495"></a><a class="code" href="group__API.html#gaacbbc0c6d6c0cbbeb4f4debf6fbeeee6">03495</a> LONG <a class="code" href="group__API.html#gaacbbc0c6d6c0cbbeb4f4debf6fbeeee6" title="This function cancels all pending blocking requests on the SCardGetStatusChange()...">SCardCancel</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext) <a name="l03496"></a>03496 { <a name="l03497"></a>03497 LONG dwContextIndex; <a name="l03498"></a>03498 LONG 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="l03499"></a>03499 <a name="l03500"></a>03500 PROFILE_START <a name="l03501"></a>03501 <a name="l03502"></a>03502 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l03503"></a>03503 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l03504"></a>03504 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03505"></a>03505 <a name="l03506"></a>03506 <span class="comment">/*</span> <a name="l03507"></a>03507 <span class="comment"> * Set the block status for this Context so blocking calls will</span> <a name="l03508"></a>03508 <span class="comment"> * complete</span> <a name="l03509"></a>03509 <span class="comment"> */</span> <a name="l03510"></a>03510 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].contextBlockStatus = <a class="code" href="pcscd_8h.html#a2100023490c145dd638a909920e9949b" title="Normal resume.">BLOCK_STATUS_RESUME</a>; <a name="l03511"></a>03511 <a name="l03512"></a>03512 <span class="keywordflow">if</span> (<a class="code" href="utils_8c.html#ab3b1e02c9f709a9b02f1f74c1074ff01" title="Sends an asynchronous event to a specific waiting client.">StatSynchronizeContext</a>(hContext)) <a name="l03513"></a>03513 rv = <a class="code" href="pcsclite_8h.html#a081a564acaf166f74592906f7dff2d86" title="An internal consistency check failed.">SCARD_F_INTERNAL_ERROR</a>; <a name="l03514"></a>03514 <a name="l03515"></a>03515 PROFILE_END(rv) <a name="l03516"></a>03516 <a name="l03517"></a>03517 <span class="keywordflow">return</span> rv; <a name="l03518"></a>03518 } <a name="l03519"></a>03519 <a name="l03543"></a><a class="code" href="group__API.html#ga722eb66bcc44d391f700ff9065cc080b">03543</a> LONG <a class="code" href="group__API.html#ga722eb66bcc44d391f700ff9065cc080b" title="Check if a SCARDCONTEXT is valid.">SCardIsValidContext</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext) <a name="l03544"></a>03544 { <a name="l03545"></a>03545 LONG rv; <a name="l03546"></a>03546 LONG dwContextIndex; <a name="l03547"></a>03547 <a name="l03548"></a>03548 PROFILE_START <a name="l03549"></a>03549 <a name="l03550"></a>03550 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="l03551"></a>03551 <a name="l03552"></a>03552 <span class="comment">/* Check if the _same_ server is running */</span> <a name="l03553"></a>03553 rv = <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(); <a name="l03554"></a>03554 <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="l03555"></a>03555 <span class="keywordflow">return</span> rv; <a name="l03556"></a>03556 <a name="l03557"></a>03557 <span class="comment">/*</span> <a name="l03558"></a>03558 <span class="comment"> * Make sure this context has been opened</span> <a name="l03559"></a>03559 <span class="comment"> */</span> <a name="l03560"></a>03560 dwContextIndex = <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(hContext); <a name="l03561"></a>03561 <span class="keywordflow">if</span> (dwContextIndex == -1) <a name="l03562"></a>03562 rv = <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03563"></a>03563 <a name="l03564"></a>03564 PROFILE_END(rv) <a name="l03565"></a>03565 <a name="l03566"></a>03566 <span class="keywordflow">return</span> rv; <a name="l03567"></a>03567 } <a name="l03568"></a>03568 <a name="l03585"></a><a class="code" href="winscard__clnt_8c.html#ac75190d70d571bca9915bef60491534a">03585</a> <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#ac75190d70d571bca9915bef60491534a" title="Functions for managing instances of SCardEstablishContext() These functions keep...">SCardAddContext</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext, DWORD dwClientID) <a name="l03586"></a>03586 { <a name="l03587"></a>03587 <span class="keywordtype">int</span> i; <a name="l03588"></a>03588 <a name="l03589"></a>03589 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcscd_8h.html#a6a6f002ba5ba58accdf202f14cc10563" title="Maximum contexts by application.">PCSCLITE_MAX_APPLICATION_CONTEXTS</a>; i++) <a name="l03590"></a>03590 { <a name="l03591"></a>03591 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].hContext == 0) <a name="l03592"></a>03592 { <a name="l03593"></a>03593 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].<a class="code" href="struct__psContextMap.html#a4171c839145c22f7594818304bf4e7a9" title="Application Context ID.">hContext</a> = hContext; <a name="l03594"></a>03594 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].<a class="code" href="struct__psContextMap.html#a4e3f21f7252b71833af88ba9f2864577" title="Client Connection ID.">dwClientID</a> = dwClientID; <a name="l03595"></a>03595 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].contextBlockStatus = <a class="code" href="pcscd_8h.html#a2100023490c145dd638a909920e9949b" title="Normal resume.">BLOCK_STATUS_RESUME</a>; <a name="l03596"></a>03596 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].<a class="code" href="struct__psContextMap.html#af46cea0e5161cce9a32f83a8e1303521" title="Mutex for this context.">mMutex</a> = malloc(<span class="keyword">sizeof</span>(PCSCLITE_MUTEX)); <a name="l03597"></a>03597 (void)SYS_MutexInit(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].mMutex); <a name="l03598"></a>03598 <span class="keywordflow">return</span> <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="l03599"></a>03599 } <a name="l03600"></a>03600 } <a name="l03601"></a>03601 <a name="l03602"></a>03602 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l03603"></a>03603 } <a name="l03604"></a>03604 <a name="l03617"></a><a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949">03617</a> <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a7f66332c12595b27726461b242b14949" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndice</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext) <a name="l03618"></a>03618 { <a name="l03619"></a>03619 LONG rv; <a name="l03620"></a>03620 <a name="l03621"></a>03621 (void)<a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe" title="This function locks a mutex so another thread must wait to use this function.">SCardLockThread</a>(); <a name="l03622"></a>03622 rv = <a class="code" href="winscard__clnt_8c.html#a64c964f90285e8409a0d41d43bb05348" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndiceTH</a>(hContext); <a name="l03623"></a>03623 (void)<a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1" title="This function unlocks a mutex so another thread may use the client.">SCardUnlockThread</a>(); <a name="l03624"></a>03624 <a name="l03625"></a>03625 <span class="keywordflow">return</span> rv; <a name="l03626"></a>03626 } <a name="l03627"></a>03627 <a name="l03640"></a><a class="code" href="winscard__clnt_8c.html#a64c964f90285e8409a0d41d43bb05348">03640</a> <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a64c964f90285e8409a0d41d43bb05348" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndiceTH</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext) <a name="l03641"></a>03641 { <a name="l03642"></a>03642 <span class="keywordtype">int</span> i; <a name="l03643"></a>03643 <a name="l03644"></a>03644 <span class="comment">/*</span> <a name="l03645"></a>03645 <span class="comment"> * Find this context and return its spot in the array</span> <a name="l03646"></a>03646 <span class="comment"> */</span> <a name="l03647"></a>03647 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcscd_8h.html#a6a6f002ba5ba58accdf202f14cc10563" title="Maximum contexts by application.">PCSCLITE_MAX_APPLICATION_CONTEXTS</a>; i++) <a name="l03648"></a>03648 { <a name="l03649"></a>03649 <span class="keywordflow">if</span> ((hContext == <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].hContext) && (hContext != 0)) <a name="l03650"></a>03650 <span class="keywordflow">return</span> i; <a name="l03651"></a>03651 } <a name="l03652"></a>03652 <a name="l03653"></a>03653 <span class="keywordflow">return</span> -1; <a name="l03654"></a>03654 } <a name="l03655"></a>03655 <a name="l03665"></a><a class="code" href="winscard__clnt_8c.html#a7e3dc878020f1e5ccdae1a6914abd3b0">03665</a> <span class="keyword">static</span> LONG <a class="code" href="winscard__clnt_8c.html#a7e3dc878020f1e5ccdae1a6914abd3b0" title="Removes an Application Context from a control vector.">SCardRemoveContext</a>(<a class="code" href="pcsclite_8h.html#a3524142a16d7185916422baf6bb7883f" title="hContext returned by SCardEstablishContext()">SCARDCONTEXT</a> hContext) <a name="l03666"></a>03666 { <a name="l03667"></a>03667 LONG retIndice; <a name="l03668"></a>03668 <a name="l03669"></a>03669 retIndice = <a class="code" href="winscard__clnt_8c.html#a64c964f90285e8409a0d41d43bb05348" title="Get the index from the Application Context vector _psContextMap for the passed context...">SCardGetContextIndiceTH</a>(hContext); <a name="l03670"></a>03670 <a name="l03671"></a>03671 <span class="keywordflow">if</span> (retIndice == -1) <a name="l03672"></a>03672 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03673"></a>03673 <span class="keywordflow">else</span> <a name="l03674"></a>03674 <span class="keywordflow">return</span> SCardCleanContext(retIndice); <a name="l03675"></a>03675 } <a name="l03676"></a>03676 <a name="l03677"></a>03677 <span class="keyword">static</span> LONG SCardCleanContext(LONG indice) <a name="l03678"></a>03678 { <a name="l03679"></a>03679 <span class="keywordtype">int</span> i; <a name="l03680"></a>03680 <a name="l03681"></a>03681 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].<a class="code" href="struct__psContextMap.html#a4171c839145c22f7594818304bf4e7a9" title="Application Context ID.">hContext</a> = 0; <a name="l03682"></a>03682 (void)<a class="code" href="winscard__msg_8c.html#afa75f2e575d731004a8daa0287838af5" title="Closes the socket used by the client to communicate with the server.">SHMClientCloseSession</a>(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].dwClientID); <a name="l03683"></a>03683 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].<a class="code" href="struct__psContextMap.html#a4e3f21f7252b71833af88ba9f2864577" title="Client Connection ID.">dwClientID</a> = 0; <a name="l03684"></a>03684 free(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].mMutex); <a name="l03685"></a>03685 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].<a class="code" href="struct__psContextMap.html#af46cea0e5161cce9a32f83a8e1303521" title="Mutex for this context.">mMutex</a> = NULL; <a name="l03686"></a>03686 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].contextBlockStatus = <a class="code" href="pcscd_8h.html#a2100023490c145dd638a909920e9949b" title="Normal resume.">BLOCK_STATUS_RESUME</a>; <a name="l03687"></a>03687 <a name="l03688"></a>03688 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcscd_8h.html#a35697bcf11218bc1aa5bfe831b360df7" title="Maximum channels on an application context.">PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS</a>; i++) <a name="l03689"></a>03689 { <a name="l03690"></a>03690 <span class="comment">/*</span> <a name="l03691"></a>03691 <span class="comment"> * Reset the \c hCard structs to zero</span> <a name="l03692"></a>03692 <span class="comment"> */</span> <a name="l03693"></a>03693 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].psChannelMap[i].hCard = 0; <a name="l03694"></a>03694 free(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].psChannelMap[i].readerName); <a name="l03695"></a>03695 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[indice].psChannelMap[i].readerName = NULL; <a name="l03696"></a>03696 } <a name="l03697"></a>03697 <a name="l03698"></a>03698 <span class="keywordflow">return</span> <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="l03699"></a>03699 } <a name="l03700"></a>03700 <a name="l03701"></a>03701 <span class="comment">/*</span> <a name="l03702"></a>03702 <span class="comment"> * Functions for managing hCard values returned from SCardConnect.</span> <a name="l03703"></a>03703 <span class="comment"> */</span> <a name="l03704"></a>03704 <a name="l03705"></a>03705 <span class="keyword">static</span> LONG SCardAddHandle(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, DWORD dwContextIndex, <a name="l03706"></a>03706 LPCSTR readerName) <a name="l03707"></a>03707 { <a name="l03708"></a>03708 <span class="keywordtype">int</span> i; <a name="l03709"></a>03709 <a name="l03710"></a>03710 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcscd_8h.html#a35697bcf11218bc1aa5bfe831b360df7" title="Maximum channels on an application context.">PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS</a>; i++) <a name="l03711"></a>03711 { <a name="l03712"></a>03712 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[i].hCard == 0) <a name="l03713"></a>03713 { <a name="l03714"></a>03714 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[i].hCard = hCard; <a name="l03715"></a>03715 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndex].psChannelMap[i].readerName = strdup(readerName); <a name="l03716"></a>03716 <span class="keywordflow">return</span> <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="l03717"></a>03717 } <a name="l03718"></a>03718 } <a name="l03719"></a>03719 <a name="l03720"></a>03720 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a81694393a1494d5091145734a2f0b36c" title="Not enough memory available to complete this command.">SCARD_E_NO_MEMORY</a>; <a name="l03721"></a>03721 } <a name="l03722"></a>03722 <a name="l03723"></a>03723 <span class="keyword">static</span> LONG SCardRemoveHandle(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard) <a name="l03724"></a>03724 { <a name="l03725"></a>03725 DWORD dwContextIndice, dwChannelIndice; <a name="l03726"></a>03726 LONG rv; <a name="l03727"></a>03727 <a name="l03728"></a>03728 rv = SCardGetIndicesFromHandle(hCard, &dwContextIndice, &dwChannelIndice); <a name="l03729"></a>03729 <span class="keywordflow">if</span> (rv == -1) <a name="l03730"></a>03730 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03731"></a>03731 <span class="keywordflow">else</span> <a name="l03732"></a>03732 { <a name="l03733"></a>03733 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndice].psChannelMap[dwChannelIndice].hCard = 0; <a name="l03734"></a>03734 free(<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndice].psChannelMap[dwChannelIndice].readerName); <a name="l03735"></a>03735 <a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[dwContextIndice].psChannelMap[dwChannelIndice].readerName = NULL; <a name="l03736"></a>03736 <span class="keywordflow">return</span> <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="l03737"></a>03737 } <a name="l03738"></a>03738 } <a name="l03739"></a>03739 <a name="l03740"></a>03740 <span class="keyword">static</span> LONG SCardGetIndicesFromHandle(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, <a name="l03741"></a>03741 PDWORD pdwContextIndice, PDWORD pdwChannelIndice) <a name="l03742"></a>03742 { <a name="l03743"></a>03743 LONG rv; <a name="l03744"></a>03744 <a name="l03745"></a>03745 <span class="keywordflow">if</span> (0 == hCard) <a name="l03746"></a>03746 <span class="keywordflow">return</span> -1; <a name="l03747"></a>03747 <a name="l03748"></a>03748 (void)<a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe" title="This function locks a mutex so another thread must wait to use this function.">SCardLockThread</a>(); <a name="l03749"></a>03749 rv = SCardGetIndicesFromHandleTH(hCard, pdwContextIndice, pdwChannelIndice); <a name="l03750"></a>03750 (void)<a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1" title="This function unlocks a mutex so another thread may use the client.">SCardUnlockThread</a>(); <a name="l03751"></a>03751 <a name="l03752"></a>03752 <span class="keywordflow">return</span> rv; <a name="l03753"></a>03753 } <a name="l03754"></a>03754 <a name="l03755"></a>03755 <span class="keyword">static</span> LONG SCardGetIndicesFromHandleTH(<a class="code" href="pcsclite_8h.html#a0ef8f5baf9ee6c07dbdc7644c641d0a9" title="hCard returned by SCardConnect()">SCARDHANDLE</a> hCard, <a name="l03756"></a>03756 PDWORD pdwContextIndice, PDWORD pdwChannelIndice) <a name="l03757"></a>03757 { <a name="l03758"></a>03758 <span class="keywordtype">int</span> i; <a name="l03759"></a>03759 <a name="l03760"></a>03760 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="pcscd_8h.html#a6a6f002ba5ba58accdf202f14cc10563" title="Maximum contexts by application.">PCSCLITE_MAX_APPLICATION_CONTEXTS</a>; i++) <a name="l03761"></a>03761 { <a name="l03762"></a>03762 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].hContext != 0) <a name="l03763"></a>03763 { <a name="l03764"></a>03764 <span class="keywordtype">int</span> j; <a name="l03765"></a>03765 <a name="l03766"></a>03766 <span class="keywordflow">for</span> (j = 0; j < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; j++) <a name="l03767"></a>03767 { <a name="l03768"></a>03768 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].psChannelMap[j].hCard == hCard) <a name="l03769"></a>03769 { <a name="l03770"></a>03770 *pdwContextIndice = i; <a name="l03771"></a>03771 *pdwChannelIndice = j; <a name="l03772"></a>03772 <span class="keywordflow">return</span> <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="l03773"></a>03773 } <a name="l03774"></a>03774 } <a name="l03775"></a>03775 <a name="l03776"></a>03776 } <a name="l03777"></a>03777 } <a name="l03778"></a>03778 <a name="l03779"></a>03779 <span class="keywordflow">return</span> -1; <a name="l03780"></a>03780 } <a name="l03781"></a>03781 <a name="l03790"></a><a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f">03790</a> LONG <a class="code" href="winscard__clnt_8c.html#aaa02e1f70d68a502cd92ed066c44542f" title="Checks if the server is running.">SCardCheckDaemonAvailability</a>(<span class="keywordtype">void</span>) <a name="l03791"></a>03791 { <a name="l03792"></a>03792 LONG rv; <a name="l03793"></a>03793 <span class="keyword">struct </span>stat statBuffer; <a name="l03794"></a>03794 <span class="keywordtype">int</span> need_restart = 0; <a name="l03795"></a>03795 <a name="l03796"></a>03796 rv = SYS_Stat(PCSCLITE_PUBSHM_FILE, &statBuffer); <a name="l03797"></a>03797 <a name="l03798"></a>03798 <span class="keywordflow">if</span> (rv != 0) <a name="l03799"></a>03799 { <a name="l03800"></a>03800 Log2(PCSC_LOG_INFO, <span class="stringliteral">"PCSC Not Running: "</span> PCSCLITE_PUBSHM_FILE <span class="stringliteral">": %s"</span>, <a name="l03801"></a>03801 strerror(errno)); <a name="l03802"></a>03802 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#ad4729ab109ff490285d2ad881c04bee8" title="The Smart card resource manager is not running.">SCARD_E_NO_SERVICE</a>; <a name="l03803"></a>03803 } <a name="l03804"></a>03804 <a name="l03805"></a>03805 <span class="comment">/* when the _first_ reader is connected the ctime changes</span> <a name="l03806"></a>03806 <span class="comment"> * I don't know why yet */</span> <a name="l03807"></a>03807 <span class="keywordflow">if</span> (daemon_ctime && statBuffer.st_ctime > daemon_ctime) <a name="l03808"></a>03808 { <a name="l03809"></a>03809 <span class="comment">/* so we also check the daemon pid to be sure it is a new pcscd */</span> <a name="l03810"></a>03810 <span class="keywordflow">if</span> (GetDaemonPid() != daemon_pid) <a name="l03811"></a>03811 { <a name="l03812"></a>03812 Log1(PCSC_LOG_INFO, <span class="stringliteral">"PCSC restarted"</span>); <a name="l03813"></a>03813 need_restart = 1; <a name="l03814"></a>03814 } <a name="l03815"></a>03815 } <a name="l03816"></a>03816 <a name="l03817"></a>03817 <span class="comment">/* after fork() need to restart */</span> <a name="l03818"></a>03818 <span class="keywordflow">if</span> (client_pid && client_pid != getpid()) <a name="l03819"></a>03819 { <a name="l03820"></a>03820 Log1(PCSC_LOG_INFO, <span class="stringliteral">"Client forked"</span>); <a name="l03821"></a>03821 need_restart = 1; <a name="l03822"></a>03822 } <a name="l03823"></a>03823 <a name="l03824"></a>03824 <span class="keywordflow">if</span> (need_restart) <a name="l03825"></a>03825 { <a name="l03826"></a>03826 <span class="keywordtype">int</span> i; <a name="l03827"></a>03827 <a name="l03828"></a>03828 <span class="comment">/* invalid all handles */</span> <a name="l03829"></a>03829 (void)<a class="code" href="winscard__clnt_8c.html#a1f7e1b05b30f1e5a5cd62b2f925222fe" title="This function locks a mutex so another thread must wait to use this function.">SCardLockThread</a>(); <a name="l03830"></a>03830 <a name="l03831"></a>03831 <span class="keywordflow">for</span> (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXTS; i++) <a name="l03832"></a>03832 <span class="keywordflow">if</span> (<a class="code" href="winscard__clnt_8c.html#ae302184e5b19da694c09713cb5bcbb8a" title="Represents the an Application Context on the Client side.">psContextMap</a>[i].hContext) <a name="l03833"></a>03833 (void)SCardCleanContext(i); <a name="l03834"></a>03834 <a name="l03835"></a>03835 (void)<a class="code" href="winscard__clnt_8c.html#a5dc8cab71db796c9e91329c22f4ebfa1" title="This function unlocks a mutex so another thread may use the client.">SCardUnlockThread</a>(); <a name="l03836"></a>03836 <a name="l03837"></a>03837 <span class="comment">/* reset pcscd status */</span> <a name="l03838"></a>03838 daemon_ctime = 0; <a name="l03839"></a>03839 client_pid = 0; <a name="l03840"></a>03840 <a name="l03841"></a>03841 <span class="comment">/* reset the lib */</span> <a name="l03842"></a>03842 <a class="code" href="winscard__clnt_8c.html#a37765ea543e030fb158a9d6b8a7762f8" title="Free resources allocated by the library.">SCardUnload</a>(); <a name="l03843"></a>03843 <a name="l03844"></a>03844 <span class="keywordflow">return</span> <a class="code" href="pcsclite_8h.html#a05bdea2f2341e78d920885d1cc357676" title="The supplied handle was invalid.">SCARD_E_INVALID_HANDLE</a>; <a name="l03845"></a>03845 } <a name="l03846"></a>03846 <a name="l03847"></a>03847 daemon_ctime = statBuffer.st_ctime; <a name="l03848"></a>03848 daemon_pid = GetDaemonPid(); <a name="l03849"></a>03849 client_pid = getpid(); <a name="l03850"></a>03850 <a name="l03851"></a>03851 <span class="keywordflow">return</span> <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="l03852"></a>03852 } <a name="l03853"></a>03853 <a name="l03860"></a>03860 <span class="preprocessor">#ifdef __SUNPRO_C</span> <a name="l03861"></a>03861 <span class="preprocessor"></span><span class="preprocessor">#pragma fini (SCardUnload)</span> <a name="l03862"></a>03862 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l03863"></a>03863 <span class="preprocessor"></span> <a name="l03864"></a><a class="code" href="winscard__clnt_8c.html#a37765ea543e030fb158a9d6b8a7762f8">03864</a> <span class="keywordtype">void</span> DESTRUCTOR <a class="code" href="winscard__clnt_8c.html#a37765ea543e030fb158a9d6b8a7762f8" title="Free resources allocated by the library.">SCardUnload</a>(<span class="keywordtype">void</span>) <a name="l03865"></a>03865 { <a name="l03866"></a>03866 <span class="keywordtype">int</span> i; <a name="l03867"></a>03867 <a name="l03868"></a>03868 <span class="keywordflow">if</span> (!isExecuted) <a name="l03869"></a>03869 <span class="keywordflow">return</span>; <a name="l03870"></a>03870 <a name="l03871"></a>03871 <span class="comment">/* unmap public shared file from memory */</span> <a name="l03872"></a>03872 <span class="keywordflow">for</span> (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++) <a name="l03873"></a>03873 { <a name="l03874"></a>03874 <span class="keywordflow">if</span> (readerStates[i] != NULL) <a name="l03875"></a>03875 { <a name="l03876"></a>03876 <a class="code" href="sys__generic_8h.html#ad41a56d6ccc76f970fbb33179d694410" title="Unmap a memory segment.">SYS_PublicMemoryUnmap</a>(readerStates[i], <span class="keyword">sizeof</span>(<a class="code" href="structpubReaderStatesList.html" title="Define an exported public reader state structure so each application gets instant...">READER_STATE</a>)); <a name="l03877"></a>03877 readerStates[i] = NULL; <a name="l03878"></a>03878 } <a name="l03879"></a>03879 } <a name="l03880"></a>03880 <a name="l03881"></a>03881 (void)<a class="code" href="sys__generic_8h.html#af10fc153fdf365c3a3001635c065a1c6" title="Opens/creates a file.">SYS_CloseFile</a>(mapAddr); <a name="l03882"></a>03882 isExecuted = 0; <a name="l03883"></a>03883 } <a name="l03884"></a>03884 </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address> </body> </html>