/[rdesktop]/jpeg/rdesktop/trunk/scard.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/scard.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1312 by stargo, Wed Nov 1 21:26:55 2006 UTC revision 1319 by stargo, Thu Nov 2 20:48:28 2006 UTC
# Line 126  scard_enum_devices(uint32 * id, char *op Line 126  scard_enum_devices(uint32 * id, char *op
126          rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);          rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
127          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
128          {          {
129                  printf("[SMART CARD: PCSC service not available]\n");                  error("[SMART CARD: PCSC service not available]\n");
130                  return 0;                  return 0;
131          }          }
132          else          else
# Line 136  scard_enum_devices(uint32 * id, char *op Line 136  scard_enum_devices(uint32 * id, char *op
136    
137          if (0 != pthread_mutex_init(&queueAccess, NULL))          if (0 != pthread_mutex_init(&queueAccess, NULL))
138          {          {
139                  printf("[SMART CARD: Can't initialize queue access mutex]\n");                  error("[SMART CARD: Can't initialize queue access mutex]\n");
140                  return 0;                  return 0;
141          }          }
142    
143          if (0 != pthread_mutex_init(&queueEmpty, NULL))          if (0 != pthread_mutex_init(&queueEmpty, NULL))
144          {          {
145                  printf("[SMART CARD: Can't initialize queue control mutex]\n");                  error("[SMART CARD: Can't initialize queue control mutex]\n");
146                  return 0;                  return 0;
147          }          }
148    
149          if (0 != pthread_mutex_init(&hcardAccess, NULL))          if (0 != pthread_mutex_init(&hcardAccess, NULL))
150          {          {
151                  printf("[SMART CARD: Can't initialize hcard list access mutex]\n");                  error("[SMART CARD: Can't initialize hcard list access mutex]\n");
152                  return 0;                  return 0;
153          }          }
154    
155  #if 0  #if 0
156          if (0 != pthread_mutex_init(&sendControl, NULL))          if (0 != pthread_mutex_init(&sendControl, NULL))
157          {          {
158                  printf("[SMART CARD: Can't initialize send control mutex]\n");                  error("[SMART CARD: Can't initialize send control mutex]\n");
159                  return 0;                  return 0;
160          }          }
161  #endif  #endif
# Line 164  scard_enum_devices(uint32 * id, char *op Line 164  scard_enum_devices(uint32 * id, char *op
164          if (0 !=          if (0 !=
165              pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL))              pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL))
166          {          {
167                  printf("[SMART CARD: Can't create queue handling Thread]\n");                  error("[SMART CARD: Can't create queue handling Thread]\n");
168                  return 0;                  return 0;
169          }          }
170    
# Line 620  TS_SCardEstablishContext(STREAM in, STRE Line 620  TS_SCardEstablishContext(STREAM in, STRE
620          MYPCSC_SCARDCONTEXT hContext;          MYPCSC_SCARDCONTEXT hContext;
621          /* code segment  */          /* code segment  */
622    
623  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("Establishing PC/SC Context... \n"));
         printf("Establishing PC/SC Context... \n");  
 #endif  
624          rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);          rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 #ifdef WITH_SCARD_DEBUG  
625          if (rv)          if (rv)
626                  printf("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n", (unsigned int) rv);          {
627                    DEBUG_SCARD(("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n",
628                                 (unsigned int) rv));
629            }
630          else          else
631                  printf("<--SUCCESS SCardEstablishContext-->\n");          {
632  #endif                  DEBUG_SCARD(("<--SUCCESS SCardEstablishContext-->\n"));
633            }
634    
635          out_uint32_le(out, 0x00000004);          out_uint32_le(out, 0x00000004);
636          out_uint32_le(out, (SERVER_DWORD) hContext);    /* must not be 0 (Seems to be pointer), don't know what is this (I use hContext as value) */          out_uint32_le(out, (SERVER_DWORD) hContext);    /* must not be 0 (Seems to be pointer), don't know what is this (I use hContext as value) */
# Line 647  TS_SCardReleaseContext(STREAM in, STREAM Line 648  TS_SCardReleaseContext(STREAM in, STREAM
648    
649          in->p += 0x1C;          in->p += 0x1C;
650          in_uint32_le(in, hContext);          in_uint32_le(in, hContext);
651  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext));
652          printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext);          DEBUG_SCARD(("Releasing context... \n"));
         printf("Releasing context... \n");  
 #endif  
653          rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext);          rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext);
654  #ifdef WITH_SCARD_DEBUG  
655          if (rv)          if (rv)
656                  printf("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) rv);          {
657                    DEBUG_SCARD(("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) rv));
658            }
659          else          else
660                  printf("<--SUCCESS SCardReleaseContext-->\n");          {
661  #endif                  DEBUG_SCARD(("<--SUCCESS SCardReleaseContext-->\n"));
662            }
663    
664          return rv;          return rv;
665  }  }
666    
# Line 672  TS_SCardIsValidContext(STREAM in, STREAM Line 675  TS_SCardIsValidContext(STREAM in, STREAM
675    
676          in->p += 0x1C;          in->p += 0x1C;
677          in_uint32_le(in, hContext);          in_uint32_le(in, hContext);
678  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext));
679          printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext);          DEBUG_SCARD(("Checking... \n"));
         printf("Checking... \n");  
 #endif  
680          /* There is no realization of SCardIsValidContext in PC/SC Lite so we call SCardListReaders */          /* There is no realization of SCardIsValidContext in PC/SC Lite so we call SCardListReaders */
681    
682          readers = SC_xmalloc(&lcHandle, 1024);          readers = SC_xmalloc(&lcHandle, 1024);
# Line 683  TS_SCardIsValidContext(STREAM in, STREAM Line 684  TS_SCardIsValidContext(STREAM in, STREAM
684                  return SC_returnNoMemoryError(&lcHandle, in, out);                  return SC_returnNoMemoryError(&lcHandle, in, out);
685    
686          rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount);          rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount);
687    
688          if (rv)          if (rv)
689          {          {
690  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--ERROR SCardListReaders (no SCardIsValidContext) Code=0x%.8x-->\n",
691                  printf("<--ERROR SCardListReaders (no SCardIsValidContext) Code=0x%.8x-->\n",                               (unsigned int) rv));
                        (unsigned int) rv);  
 #endif  
692                  rv = SCARD_E_INVALID_HANDLE;                  rv = SCARD_E_INVALID_HANDLE;
693          }          }
 #ifdef WITH_SCARD_DEBUG  
694          else          else
695                  printf("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n");          {
696  #endif                  DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"));
697            }
698    
699          outForceAllignment(out, 8);          outForceAllignment(out, 8);
700          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
701          return rv;          return rv;
# Line 715  TS_SCardListReaders(STREAM in, STREAM ou Line 716  TS_SCardListReaders(STREAM in, STREAM ou
716    
717          in->p += 0x2C;          in->p += 0x2C;
718          in_uint32_le(in, hContext);          in_uint32_le(in, hContext);
719  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext));
         printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext);  
 #endif  
720          plen1 = out->p;          plen1 = out->p;
721          out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */          out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */
722          out_uint32_le(out, 0x01760650);          out_uint32_le(out, 0x01760650);
# Line 738  TS_SCardListReaders(STREAM in, STREAM ou Line 737  TS_SCardListReaders(STREAM in, STREAM ou
737          {          {
738                  int i;                  int i;
739                  PSCNameMapRec tmpMap;                  PSCNameMapRec tmpMap;
740  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
741                  printf("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv);                  DEBUG_SCARD(("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv));
742                  hexdump((void *) readers, cchReaders);                  hexdump((void *) readers, cchReaders);
743  #endif  #endif
744                  for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++)                  for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++)
# Line 793  TS_SCardConnect(STREAM in, STREAM out, B Line 792  TS_SCardConnect(STREAM in, STREAM out, B
792          in->p += 0x1C;          in->p += 0x1C;
793          in_uint32_le(in, dwShareMode);          in_uint32_le(in, dwShareMode);
794          in_uint32_le(in, dwPreferredProtocol);          in_uint32_le(in, dwPreferredProtocol);
795  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[SHARE %8x]\n", (unsigned int) dwShareMode));
796          printf("[SHARE %8x]\n", (unsigned int) dwShareMode);          DEBUG_SCARD(("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol));
         printf("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol);  
 #endif  
797          inReaderName(&lcHandle, in, &szReader, wide);          inReaderName(&lcHandle, in, &szReader, wide);
798  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CONNECT TO READER \"%s\"\n", (szReader != NULL) ? (szReader) : ("NULL")));
         printf("[CONNECT TO READER \"%s\"\n", (szReader != NULL) ? (szReader) : ("NULL"));  
 #endif  
799          in->p += 0x04;          in->p += 0x04;
800          in_uint32_le(in, hContext);          in_uint32_le(in, hContext);
801  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext));
         printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext);  
 #endif  
802          rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode,          rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode,
803                            (MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol);                            (MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol);
804          hCard = scHandleToServer(myHCard);          hCard = scHandleToServer(myHCard);
805  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[RECEIVED HCARD 0x%016lx]\n", (unsigned long) myHCard));
806          printf("[RECEIVED HCARD 0x%016lx]\n", myHCard);          DEBUG_SCARD(("[MANGLED  HCARD 0x%08x]\n", hCard));
         printf("[MANGLED  HCARD 0x%08x]\n", hCard);  
 #endif  
807          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
808          {          {
809  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv));
                 printf("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv);  
 #endif  
810          }          }
811          else          else
812          {          {
813                  char *szVendor = getVendor(szReader);                  char *szVendor = getVendor(szReader);
814  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--SUCCESS ScardConnect-->\n"));
                 printf("<--SUCCESS ScardConnect-->\n");  
 #endif  
815                  if (szVendor && (strlen(szVendor) > 0))                  if (szVendor && (strlen(szVendor) > 0))
816                  {                  {
817  #ifdef WITH_SCARD_DEBUG                          DEBUG_SCARD(("Set Attribute ATTR_VENDOR_NAME\n"));
                         printf("Set Attribute ATTR_VENDOR_NAME\n");  
 #endif  
818                          pthread_mutex_lock(&hcardAccess);                          pthread_mutex_lock(&hcardAccess);
819                          PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec));                          PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec));
820                          if (hcard)                          if (hcard)
# Line 885  TS_SCardReconnect(STREAM in, STREAM out) Line 870  TS_SCardReconnect(STREAM in, STREAM out)
870          in->p += 0x04;          in->p += 0x04;
871          in_uint32_le(in, hCard);          in_uint32_le(in, hCard);
872          myHCard = scHandleToMyPCSC(hCard);          myHCard = scHandleToMyPCSC(hCard);
873  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode));
874          printf("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode);          DEBUG_SCARD(("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol));
875          printf("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol);          DEBUG_SCARD(("[INIT  = 0x%.8x]\n", (unsigned int) dwInitialization));
876          printf("[INIT  = 0x%.8x]\n", (unsigned int) dwInitialization);          DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext));
877          printf("[hContext = 0x%.8x]\n", (unsigned int) hContext);          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
878          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard));
         printf("[myHCard = 0x%016lx]\n", myHCard);  
 #endif  
879          rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol,          rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol,
880                              (MYPCSC_DWORD) dwInitialization, &dwActiveProtocol);                              (MYPCSC_DWORD) dwInitialization, &dwActiveProtocol);
 #ifdef WITH_SCARD_DEBUG  
881          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
882                  printf("<--ERROR SCardReconnect Code=0x%.8x-->\n", (unsigned int) rv);          {
883                    DEBUG_SCARD(("<--ERROR SCardReconnect Code=0x%.8x-->\n", (unsigned int) rv));
884            }
885          else          else
886                  printf("<--SUCCESS SCardReconnect-->\n");          {
887  #endif                  DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n"));
888            }
889    
890          outForceAllignment(out, 8);          outForceAllignment(out, 8);
891          out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol);          out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol);
# Line 923  TS_SCardDisconnect(STREAM in, STREAM out Line 908  TS_SCardDisconnect(STREAM in, STREAM out
908          in->p += 0x04;          in->p += 0x04;
909          in_uint32_le(in, hCard);          in_uint32_le(in, hCard);
910    
911  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext));
912          printf("[hContext = 0x%.8x]\n", (unsigned int) hContext);          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
913          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition));
         printf("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition);  
 #endif  
914    
915          pthread_mutex_lock(&hcardAccess);          pthread_mutex_lock(&hcardAccess);
916          PSCHCardRec hcard = hcardFirst;          PSCHCardRec hcard = hcardFirst;
# Line 951  TS_SCardDisconnect(STREAM in, STREAM out Line 934  TS_SCardDisconnect(STREAM in, STREAM out
934          myHCard = scHandleToMyPCSC(hCard);          myHCard = scHandleToMyPCSC(hCard);
935          rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition);          rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition);
936    
 #ifdef WITH_SCARD_DEBUG  
937          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
938                  printf("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv);          {
939                    DEBUG_SCARD(("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv));
940            }
941          else          else
942                  printf("<--SUCCESS SCardDisconnect-->\n");          {
943  #endif                  DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n"));
944            }
945    
946          outForceAllignment(out, 8);          outForceAllignment(out, 8);
947          return rv;          return rv;
948  }  }
# Line 1064  TS_SCardGetStatusChange(STREAM in, STREA Line 1050  TS_SCardGetStatusChange(STREAM in, STREA
1050          in->p += 0x08;          in->p += 0x08;
1051          in_uint32_le(in, hContext);          in_uint32_le(in, hContext);
1052          in->p += 0x04;          in->p += 0x04;
1053  #ifdef WITH_SCARD_DEBUG  
1054          printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext);          DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext));
1055          printf("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout);          DEBUG_SCARD(("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout));
1056          printf("[COUNT %d]\n", (unsigned int) dwCount);          DEBUG_SCARD(("[COUNT %d]\n", (unsigned int) dwCount));
1057          printf("[TYPE SIZE %d]\n", (unsigned int) sizeof(SERVER_SCARD_READERSTATE_A));          DEBUG_SCARD(("[TYPE SIZE %d]\n", (unsigned int) sizeof(SERVER_SCARD_READERSTATE_A)));
1058  #endif  
1059          if (dwCount > 0)          if (dwCount > 0)
1060          {          {
1061                  rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));                  rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));
# Line 1086  TS_SCardGetStatusChange(STREAM in, STREA Line 1072  TS_SCardGetStatusChange(STREAM in, STREA
1072                          in->p += 0x04;                          in->p += 0x04;
1073                          in_uint8a(in, cur, SERVER_SCARDSTATESIZE);                          in_uint8a(in, cur, SERVER_SCARDSTATESIZE);
1074                  }                  }
1075  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1076                  printf("[READERS DUMP 1]------------------\n");                  DEBUG_SCARD(("[READERS DUMP 1]------------------\n"));
1077                  hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));                  hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));
1078  #endif  #endif
1079    
# Line 1124  TS_SCardGetStatusChange(STREAM in, STREA Line 1110  TS_SCardGetStatusChange(STREAM in, STREA
1110    
1111                          in->p += 0x08;                          in->p += 0x08;
1112                          in_uint32_le(in, dataLength);                          in_uint32_le(in, dataLength);
1113  #ifdef WITH_SCARD_DEBUG                          DEBUG_SCARD(("[%d] Data Length %d]\n", (unsigned int) i, dataLength));
                         printf("[%d] Data Length %d]\n", (unsigned int) i, dataLength);  
 #endif  
1114                          inRepos(in,                          inRepos(in,
1115                                  inString(&lcHandle, in, (char **) &(cur->szReader), dataLength,                                  inString(&lcHandle, in, (char **) &(cur->szReader), dataLength,
1116                                           wide));                                           wide));
# Line 1134  TS_SCardGetStatusChange(STREAM in, STREA Line 1118  TS_SCardGetStatusChange(STREAM in, STREA
1118                          if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0)                          if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0)
1119                                  cur->dwCurrentState |= SCARD_STATE_IGNORE;                                  cur->dwCurrentState |= SCARD_STATE_IGNORE;
1120                  }                  }
1121  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1122                  printf("[READERS DUMP 2]------------------\n");                  DEBUG_SCARD(("[READERS DUMP 2]------------------\n"));
1123                  hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));                  hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));
1124  #endif  #endif
1125          }          }
# Line 1145  TS_SCardGetStatusChange(STREAM in, STREA Line 1129  TS_SCardGetStatusChange(STREAM in, STREA
1129                  stateArray = NULL;                  stateArray = NULL;
1130          }          }
1131    
1132  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("\nCalling SCardGetStatusChange...\n"));
         printf("\nCalling SCardGetStatusChange...\n");  
 #endif  
1133    
1134    
1135          myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A));          myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A));
# Line 1155  TS_SCardGetStatusChange(STREAM in, STREA Line 1137  TS_SCardGetStatusChange(STREAM in, STREA
1137                  return SC_returnNoMemoryError(&lcHandle, in, out);                  return SC_returnNoMemoryError(&lcHandle, in, out);
1138          memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));          memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));
1139          copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount);          copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount);
1140  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1141          printf("[TRANSLATION OF READERS]--------------------\n");          DEBUG_SCARD(("[TRANSLATION OF READERS]--------------------\n"));
1142          hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A));          hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A));
1143  #endif  #endif
1144    
# Line 1164  TS_SCardGetStatusChange(STREAM in, STREA Line 1146  TS_SCardGetStatusChange(STREAM in, STREA
1146                                    myRsArray, (MYPCSC_DWORD) dwCount);                                    myRsArray, (MYPCSC_DWORD) dwCount);
1147          copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount);          copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount);
1148    
 #ifdef WITH_SCARD_DEBUG  
1149          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1150                  printf("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv);          {
1151                    DEBUG_SCARD(("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv));
1152            }
1153          else          else
1154                  printf("<--SUCCESS SCardGetStatusChange-->\n");          {
1155                    DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange-->\n"));
1156            }
1157    
1158    #ifdef WITH_DEBUG_SCARD
1159          if (dwCount > 0)          if (dwCount > 0)
1160          {          {
1161                  printf("[READERS DUMP]------------------\n");                  DEBUG_SCARD(("[READERS DUMP]------------------\n"));
1162                  hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));                  hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A));
1163          }          }
1164  #endif  #endif
# Line 1227  TS_SCardCancel(STREAM in, STREAM out) Line 1213  TS_SCardCancel(STREAM in, STREAM out)
1213    
1214          in->p += 0x1C;          in->p += 0x1C;
1215          in_uint32_le(in, hContext);          in_uint32_le(in, hContext);
1216  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext));
1217          printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext);          DEBUG_SCARD(("Canceling... \n"));
         printf("Canceling... \n");  
 #endif  
1218          rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext);          rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext);
 #ifdef WITH_SCARD_DEBUG  
1219          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1220                  printf("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv);          {
1221                    DEBUG_SCARD(("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv));
1222            }
1223          else          else
1224                  printf("<--SUCCESS SCardCancel-->\n");          {
1225  #endif                  DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n"));
1226            }
1227          outForceAllignment(out, 8);          outForceAllignment(out, 8);
1228          return rv;          return rv;
1229  }  }
# Line 1259  TS_SCardLocateCardsByATR(STREAM in, STRE Line 1245  TS_SCardLocateCardsByATR(STREAM in, STRE
1245    
1246          in->p += 0x2C;          in->p += 0x2C;
1247          in_uint32_le(in, hContext);          in_uint32_le(in, hContext);
1248  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext));
         printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext);  
 #endif  
1249          in_uint32_le(in, atrMaskCount);          in_uint32_le(in, atrMaskCount);
1250          pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L));          pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L));
1251          if (!pAtrMasks)          if (!pAtrMasks)
# Line 1289  TS_SCardLocateCardsByATR(STREAM in, STRE Line 1273  TS_SCardLocateCardsByATR(STREAM in, STRE
1273          for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++)          for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++)
1274          {          {
1275                  inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide);                  inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide);
1276  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("[CHECK READER %s]\n",
1277                  printf("[CHECK READER %s]\n", (rsCur->szReader) ? (rsCur->szReader) : ("NULL"));                               (rsCur->szReader) ? (rsCur->szReader) : ("NULL")));
 #endif  
1278          }          }
1279    
1280  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[CALL subfunction \"SCardGetStatusChange\"]\n"));
         printf("[CALL subfunction \"SCardGetStatusChange\"]\n");  
 #endif  
1281          /* FIXME segfault here. */          /* FIXME segfault here. */
1282          myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A));          myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A));
1283          if (!myRsArray)          if (!myRsArray)
# Line 1306  TS_SCardLocateCardsByATR(STREAM in, STRE Line 1287  TS_SCardLocateCardsByATR(STREAM in, STRE
1287          copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount);          copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount);
1288          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1289          {          {
1290  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x-->\n", (unsigned int) rv));
                 printf("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x-->\n",  
                        (unsigned int) rv);  
 #endif  
1291          }          }
1292          else          else
1293          {          {
1294  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n"));
                 printf("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n");  
 #endif  
1295                  cur = pAtrMasks;                  cur = pAtrMasks;
1296                  for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++)                  for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++)
1297                  {                  {
# Line 1335  TS_SCardLocateCardsByATR(STREAM in, STRE Line 1311  TS_SCardLocateCardsByATR(STREAM in, STRE
1311                                  }                                  }
1312                                  if (equal)                                  if (equal)
1313                                  {                                  {
1314  #ifdef WITH_SCARD_DEBUG                                          DEBUG_SCARD(("[FOUND]\n"));
                                         printf("[FOUND]\n");  
 #endif  
1315                                          rsCur->dwEventState |= 0x00000040;      /* SCARD_STATE_ATRMATCH 0x00000040 */                                          rsCur->dwEventState |= 0x00000040;      /* SCARD_STATE_ATRMATCH 0x00000040 */
1316                                          memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A));                                          memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A));
1317                                  }                                  }
# Line 1370  TS_SCardBeginTransaction(STREAM in, STRE Line 1344  TS_SCardBeginTransaction(STREAM in, STRE
1344          in->p += 0x30;          in->p += 0x30;
1345          in_uint32_le(in, hCard);          in_uint32_le(in, hCard);
1346          myHCard = scHandleToMyPCSC(hCard);          myHCard = scHandleToMyPCSC(hCard);
1347  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
1348          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard));
         printf("[myHCard = 0x%016lx]\n", myHCard);  
 #endif  
1349          rv = SCardBeginTransaction(myHCard);          rv = SCardBeginTransaction(myHCard);
 #ifdef WITH_SCARD_DEBUG  
1350          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1351                  printf("<--ERROR SCardBeginTransaction Code=0x%.8x-->\n", (unsigned int) rv);          {
1352                    DEBUG_SCARD(("<--ERROR SCardBeginTransaction Code=0x%.8x-->\n", (unsigned int) rv));
1353            }
1354          else          else
1355                  printf("<--SUCCESS SCardBeginTransaction-->\n");          {
1356  #endif                  DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n"));
1357            }
1358          outForceAllignment(out, 8);          outForceAllignment(out, 8);
1359          return rv;          return rv;
1360  }  }
# Line 1398  TS_SCardEndTransaction(STREAM in, STREAM Line 1372  TS_SCardEndTransaction(STREAM in, STREAM
1372          in->p += 0x0C;          in->p += 0x0C;
1373          in_uint32_le(in, hCard);          in_uint32_le(in, hCard);
1374          myHCard = scHandleToMyPCSC(hCard);          myHCard = scHandleToMyPCSC(hCard);
1375  #ifdef WITH_SCARD_DEBUG  
1376          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
1377          printf("[myHCard = 0x%016lx]\n", myHCard);          DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard));
1378          printf("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition);          DEBUG_SCARD(("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition));
1379  #endif  
1380          rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition);          rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition);
 #ifdef WITH_SCARD_DEBUG  
1381          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1382                  printf("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv);          {
1383                    DEBUG_SCARD(("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv));
1384            }
1385          else          else
1386                  printf("<--SUCCESS SCardEndTransaction-->\n");          {
1387  #endif                  DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n"));
1388            }
1389          outForceAllignment(out, 8);          outForceAllignment(out, 8);
1390          return rv;          return rv;
1391  }  }
# Line 1509  TS_SCardTransmit(STREAM in, STREAM out) Line 1485  TS_SCardTransmit(STREAM in, STREAM out)
1485    
1486          if (cbRecvLength)          if (cbRecvLength)
1487          {          {
                 /* FIXME: handle responses with length > 448 bytes */  
                 if (cbRecvLength > 448)  
                 {  
 #ifdef WITH_SCARD_DEBUG  
                         printf("[RECV LEN %d -> %d]\n", (unsigned int) cbRecvLength, 400);  
 #endif  
                         cbRecvLength = 448;  
                 }  
   
   
1488                  recvBuf = SC_xmalloc(&lcHandle, cbRecvLength);                  recvBuf = SC_xmalloc(&lcHandle, cbRecvLength);
1489                  if (!recvBuf)                  if (!recvBuf)
1490                          return SC_returnNoMemoryError(&lcHandle, in, out);                          return SC_returnNoMemoryError(&lcHandle, in, out);
# Line 1552  TS_SCardTransmit(STREAM in, STREAM out) Line 1518  TS_SCardTransmit(STREAM in, STREAM out)
1518          else          else
1519                  pioRecvPci = NULL;                  pioRecvPci = NULL;
1520    
1521  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1522          printf("++++++++++\n");          DEBUG_SCARD(("++++++++++\n"));
1523          printf("[SEND LEN = %d]\n", (unsigned int) cbSendLength);          DEBUG_SCARD(("[SEND LEN = %d]\n", (unsigned int) cbSendLength));
1524          printf("[RECV LEN = %d]\n", (unsigned int) cbRecvLength);          DEBUG_SCARD(("[RECV LEN = %d]\n", (unsigned int) cbRecvLength));
1525          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
1526          printf("[myHCard = 0x%016lx]\n", myHCard);          DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard));
1527          printf("[pioSendPci]\n");          DEBUG_SCARD(("[pioSendPci]\n"));
1528          if (pioSendPci == NULL)          if (pioSendPci == NULL)
1529                  printf("NULL\n");          {
1530                    DEBUG_SCARD(("NULL\n"));
1531            }
1532          else          else
1533            {
1534                  hexdump((void *) pioSendPci, pioSendPci->cbPciLength);                  hexdump((void *) pioSendPci, pioSendPci->cbPciLength);
1535          printf("[pioRecvPci]\n");          }
1536    
1537            DEBUG_SCARD(("[pioRecvPci]\n"));
1538          if (pioRecvPci == NULL)          if (pioRecvPci == NULL)
1539                  printf("NULL\n");          {
1540                    DEBUG_SCARD(("NULL\n"));
1541            }
1542          else          else
1543            {
1544                  hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength);                  hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength);
1545          printf("[sendBuf]\n");          }
1546            DEBUG_SCARD(("[sendBuf]\n"));
1547          hexdump(sendBuf, cbSendLength);          hexdump(sendBuf, cbSendLength);
1548          printf("++++++++++\n");          DEBUG_SCARD(("++++++++++\n"));
1549  #endif  #endif
1550    
1551          myCbRecvLength = cbRecvLength;          myCbRecvLength = cbRecvLength;
# Line 1598  TS_SCardTransmit(STREAM in, STREAM out) Line 1573  TS_SCardTransmit(STREAM in, STREAM out)
1573          rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength,          rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength,
1574                             myPioRecvPci, recvBuf, &myCbRecvLength);                             myPioRecvPci, recvBuf, &myCbRecvLength);
1575          cbRecvLength = myCbRecvLength;          cbRecvLength = myCbRecvLength;
1576    
1577            /* FIXME: handle responses with length > 448 bytes */
1578            if (cbRecvLength > 448)
1579            {
1580                    warning("Card response limited from %d to 448 bytes!\n", cbRecvLength);
1581                    DEBUG_SCARD(("[RECV LEN %d -> %d]\n", (unsigned int) cbRecvLength, 400));
1582                    cbRecvLength = 448;
1583            }
1584    
1585          if (pioRecvPci)          if (pioRecvPci)
1586          {          {
1587                  copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci);                  copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci);
# Line 1605  TS_SCardTransmit(STREAM in, STREAM out) Line 1589  TS_SCardTransmit(STREAM in, STREAM out)
1589    
1590          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1591          {          {
1592  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv));
                 printf("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv);  
 #endif  
1593          }          }
1594          else          else
1595          {          {
1596  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1597                  printf("<--SUCCESS SCardTransmit-->\n");                  DEBUG_SCARD(("<--SUCCESS SCardTransmit-->\n"));
1598                  printf("RESULT %d\n", (unsigned int) cbRecvLength);                  DEBUG_SCARD(("RESULT %d\n", (unsigned int) cbRecvLength));
1599                  hexdump(recvBuf, cbRecvLength);                  hexdump(recvBuf, cbRecvLength);
1600                  if (myPioRecvPci)                  if (myPioRecvPci)
1601                  {                  {
1602                          printf("--- myPioRecvPci ---\n");                          DEBUG_SCARD(("--- myPioRecvPci ---\n"));
1603                          hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength);                          hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength);
1604                  }                  }
1605                  printf("------------------\n");                  DEBUG_SCARD(("------------------\n"));
1606  #endif  #endif
1607  #if 0  #if 0
1608                  if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0))                  if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0))
# Line 1672  TS_SCardStatus(STREAM in, STREAM out, BO Line 1654  TS_SCardStatus(STREAM in, STREAM out, BO
1654          in_uint32_le(in, hCard);          in_uint32_le(in, hCard);
1655          in->p += 0x04;          in->p += 0x04;
1656          myHCard = scHandleToMyPCSC(hCard);          myHCard = scHandleToMyPCSC(hCard);
1657  #ifdef WITH_SCARD_DEBUG  
1658          printf("[hCard 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard));
1659          printf("[myHCard 0x%016lx]\n", myHCard);          DEBUG_SCARD(("[myHCard 0x%016lx]\n", (unsigned long) myHCard));
1660          printf("[dwReaderLen %d]\n", (unsigned int) dwReaderLen);          DEBUG_SCARD(("[dwReaderLen %d]\n", (unsigned int) dwReaderLen));
1661          printf("[dwAtrLen %d]\n", (unsigned int) dwAtrLen);          DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen));
 #endif  
1662    
1663          if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM)          if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM)
1664                  dwReaderLen = SCARD_MAX_MEM;                  dwReaderLen = SCARD_MAX_MEM;
# Line 1705  TS_SCardStatus(STREAM in, STREAM out, BO Line 1686  TS_SCardStatus(STREAM in, STREAM out, BO
1686    
1687          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1688          {          {
1689  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv));
                 printf("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv);  
 #endif  
1690                  return SC_returnCode(rv, &lcHandle, in, out);                  return SC_returnCode(rv, &lcHandle, in, out);
1691          }          }
1692          else          else
1693          {          {
1694  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1695                  printf("<--SUCCESS SCardStatus-->\n");                  DEBUG_SCARD(("<--SUCCESS SCardStatus-->\n"));
1696                  printf("[dwState 0x%.8x]\n", (unsigned int) dwState);                  DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState));
1697                  printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol);                  DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol));
1698                  printf("[Reader Name]\n");                  DEBUG_SCARD(("[Reader Name]\n"));
1699                  hexdump((unsigned char *) readerName, dwReaderLen);                  hexdump((unsigned char *) readerName, dwReaderLen);
1700                  printf("[Atr]\n");                  DEBUG_SCARD(("[Atr]\n"));
1701                  hexdump(atr, dwAtrLen);                  hexdump(atr, dwAtrLen);
1702  #endif  #endif
1703                  if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE))                  if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE))
# Line 1789  TS_SCardState(STREAM in, STREAM out) Line 1768  TS_SCardState(STREAM in, STREAM out)
1768          in_uint32_le(in, hCard);          in_uint32_le(in, hCard);
1769          in->p += 0x04;          in->p += 0x04;
1770          myHCard = scHandleToMyPCSC(hCard);          myHCard = scHandleToMyPCSC(hCard);
 #ifdef WITH_SCARD_DEBUG  
         printf("[hCard 0x%.8x]\n", (unsigned int) hCard);  
         printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard);  
         printf("[dwAtrLen %d]\n", (unsigned int) dwAtrLen);  
 #endif  
1771    
1772            DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard));
1773            DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard));
1774            DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen));
1775    
1776          dwReaderLen = SCARD_MAX_MEM;          dwReaderLen = SCARD_MAX_MEM;
1777          if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM)          if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM)
# Line 1820  TS_SCardState(STREAM in, STREAM out) Line 1797  TS_SCardState(STREAM in, STREAM out)
1797    
1798          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1799          {          {
1800  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n",
1801                  printf("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n", (unsigned int) rv);                               (unsigned int) rv));
 #endif  
1802                  return SC_returnCode(rv, &lcHandle, in, out);                  return SC_returnCode(rv, &lcHandle, in, out);
1803          }          }
1804          else          else
1805          {          {
1806  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1807                  printf("<--SUCCESS SCardStatus (no ScardState)-->\n");                  DEBUG_SCARD(("<--SUCCESS SCardStatus (no ScardState)-->\n"));
1808                  printf("[dwState 0x%.8x]\n", (unsigned int) dwState);                  DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState));
1809                  printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol);                  DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol));
1810                  printf("[Atr]\n");                  DEBUG_SCARD(("[Atr]\n"));
1811                  hexdump(atr, dwAtrLen);                  hexdump(atr, dwAtrLen);
1812  #endif  #endif
1813                  if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE))                  if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE))
# Line 1899  TS_SCardListReaderGroups(STREAM in, STRE Line 1875  TS_SCardListReaderGroups(STREAM in, STRE
1875          dwGroups = groups;          dwGroups = groups;
1876    
1877          if (rv)          if (rv)
 #ifdef WITH_SCARD_DEBUG  
1878          {          {
1879                  printf("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv);                  DEBUG_SCARD(("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv));
 #endif  
1880                  return SC_returnCode(rv, &lcHandle, in, out);                  return SC_returnCode(rv, &lcHandle, in, out);
 #ifdef WITH_SCARD_DEBUG  
1881          }          }
1882          else          else
1883          {          {
1884                  printf("<--SUCCESS SCardListReaderGroups-->\n");                  DEBUG_SCARD(("<--SUCCESS SCardListReaderGroups-->\n"));
1885          }          }
 #endif  
1886    
1887    
1888          out_uint32_le(out, dwGroups);          out_uint32_le(out, dwGroups);
# Line 1946  TS_SCardGetAttrib(STREAM in, STREAM out) Line 1918  TS_SCardGetAttrib(STREAM in, STREAM out)
1918    
1919          dwAttrId = dwAttrId & 0x0000FFFF;          dwAttrId = dwAttrId & 0x0000FFFF;
1920    
1921  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
1922          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard));
1923          printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard);          DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId));
1924          printf("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId);          DEBUG_SCARD(("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen));
         printf("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen);  
 #endif  
1925    
1926          if (dwAttrLen > MAX_BUFFER_SIZE)          if (dwAttrLen > MAX_BUFFER_SIZE)
1927                  dwAttrLen = MAX_BUFFER_SIZE;                  dwAttrLen = MAX_BUFFER_SIZE;
# Line 1977  TS_SCardGetAttrib(STREAM in, STREAM out) Line 1947  TS_SCardGetAttrib(STREAM in, STREAM out)
1947    
1948          if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS)          if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS)
1949          {          {
1950  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("Get Attribute ATTR_VENDOR_NAME\n"));
                 printf("Get Attribute ATTR_VENDOR_NAME\n");  
 #endif  
1951                  pthread_mutex_lock(&hcardAccess);                  pthread_mutex_lock(&hcardAccess);
1952                  PSCHCardRec hcard = hcardFirst;                  PSCHCardRec hcard = hcardFirst;
1953                  while (hcard)                  while (hcard)
# Line 1994  TS_SCardGetAttrib(STREAM in, STREAM out) Line 1962  TS_SCardGetAttrib(STREAM in, STREAM out)
1962                          hcard = hcard->next;                          hcard = hcard->next;
1963                  }                  }
1964                  pthread_mutex_unlock(&hcardAccess);                  pthread_mutex_unlock(&hcardAccess);
1965  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("[0x%.8x]\n", (unsigned int) rv));
                 printf("[0x%.8x]\n", (unsigned int) rv);  
 #endif  
1966          }          }
1967    
1968          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
1969          {          {
1970  #ifdef WITH_SCARD_DEBUG                  DEBUG_SCARD(("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv));
                 printf("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv);  
 #endif  
1971                  return SC_returnCode(rv, &lcHandle, in, out);                  return SC_returnCode(rv, &lcHandle, in, out);
1972          }          }
1973          else          else
1974          {          {
1975  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
1976                  printf("<--SUCCESS SCardGetAttrib-->\n");                  DEBUG_SCARD(("<--SUCCESS SCardGetAttrib-->\n"));
1977                  printf("[LENGTH %d]\n", (unsigned int) dwAttrLen);                  DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) dwAttrLen));
1978                  printf("+++++++++++++++++++++\n");                  DEBUG_SCARD(("+++++++++++++++++++++\n"));
1979                  hexdump(pbAttr, dwAttrLen);                  hexdump(pbAttr, dwAttrLen);
1980                  printf("+++++++++++++++++++++\n");                  DEBUG_SCARD(("+++++++++++++++++++++\n"));
1981  #endif  #endif
1982                  out_uint32_le(out, dwAttrLen);                  out_uint32_le(out, dwAttrLen);
1983                  out_uint32_le(out, 0x00000200);                  out_uint32_le(out, 0x00000200);
# Line 2054  TS_SCardSetAttrib(STREAM in, STREAM out) Line 2018  TS_SCardSetAttrib(STREAM in, STREAM out)
2018    
2019          dwAttrId = dwAttrId & 0x0000FFFF;          dwAttrId = dwAttrId & 0x0000FFFF;
2020    
2021  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
2022          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard));
2023          printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard);          DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId));
2024          printf("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId);          DEBUG_SCARD(("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen));
         printf("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen);  
 #endif  
2025    
2026          if (dwAttrLen > MAX_BUFFER_SIZE)          if (dwAttrLen > MAX_BUFFER_SIZE)
2027                  dwAttrLen = MAX_BUFFER_SIZE;                  dwAttrLen = MAX_BUFFER_SIZE;
# Line 2071  TS_SCardSetAttrib(STREAM in, STREAM out) Line 2033  TS_SCardSetAttrib(STREAM in, STREAM out)
2033          in_uint8a(in, pbAttr, dwAttrLen);          in_uint8a(in, pbAttr, dwAttrLen);
2034          rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen);          rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen);
2035    
 #ifdef WITH_SCARD_DEBUG  
2036          if (rv)          if (rv)
2037                  printf("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv);          {
2038                    DEBUG_SCARD(("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv));
2039            }
2040          else          else
2041                  printf("<--SUCCESS SCardSetAttrib-->\n");          {
2042  #endif                  DEBUG_SCARD(("<--SUCCESS SCardSetAttrib-->\n"));
2043            }
2044    
2045          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
2046          out_uint32_le(out, 0x00000200);          out_uint32_le(out, 0x00000200);
2047          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
# Line 2144  TS_SCardControl(STREAM in, STREAM out) Line 2109  TS_SCardControl(STREAM in, STREAM out)
2109          if (!pOutBuffer)          if (!pOutBuffer)
2110                  return SC_returnNoMemoryError(&lcHandle, in, out);                  return SC_returnNoMemoryError(&lcHandle, in, out);
2111    
2112  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
2113          printf("[hContext = 0x%.8x]\n", (unsigned int) hContext);          DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext));
2114          printf("[hCard = 0x%.8x]\n", (unsigned int) hCard);          DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard));
2115          printf("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode);          DEBUG_SCARD(("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode));
2116          printf("[nInBufferSize  = %d]\n", (unsigned int) nInBufferSize);          DEBUG_SCARD(("[nInBufferSize  = %d]\n", (unsigned int) nInBufferSize));
2117          printf("[nOutBufferSize  = %d]\n", (unsigned int) nOutBufferSize);          DEBUG_SCARD(("[nOutBufferSize  = %d]\n", (unsigned int) nOutBufferSize));
2118          if (nInBufferSize > 0)          if (nInBufferSize > 0)
2119          {          {
2120                  printf("[In buffer]\n");                  DEBUG_SCARD(("[In buffer]\n"));
2121                  hexdump((unsigned char *) pInBuffer, nInBufferSize);                  hexdump((unsigned char *) pInBuffer, nInBufferSize);
2122          }          }
2123          printf("---> Calling SCardControl\n");          DEBUG_SCARD(("---> Calling SCardControl\n"));
2124  #endif  #endif
2125    
 #ifdef WITH_PCSC120  
2126          sc_nBytesReturned = nBytesReturned;          sc_nBytesReturned = nBytesReturned;
2127          myHCard = scHandleToMyPCSC(hCard);          myHCard = scHandleToMyPCSC(hCard);
2128    #ifdef WITH_PCSC120
2129          rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer,          rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer,
2130                            &sc_nBytesReturned);                            &sc_nBytesReturned);
         nBytesReturned = sc_nBytesReturned;  
2131  #else  #else
         sc_nBytesReturned = nBytesReturned;  
         myHCard = scHandleToMyPCSC(hCard);  
2132          rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer,          rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer,
2133                            (MYPCSC_DWORD) nInBufferSize, pOutBuffer,                            (MYPCSC_DWORD) nInBufferSize, pOutBuffer,
2134                            (MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned);                            (MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned);
         nBytesReturned = sc_nBytesReturned;  
2135  #endif  #endif
2136            nBytesReturned = sc_nBytesReturned;
2137    
2138  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
2139          if (rv != SCARD_S_SUCCESS)          if (rv != SCARD_S_SUCCESS)
2140                  printf("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv);          {
2141                    DEBUG_SCARD(("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv));
2142            }
2143          else          else
2144          {          {
2145                  printf("<--SUCCESS SCardControl-->\n");                  DEBUG_SCARD(("<--SUCCESS SCardControl-->\n"));
2146                  printf("[LENGTH %d]\n", (unsigned int) nBytesReturned);                  DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) nBytesReturned));
2147                  printf("+++++++++++++++++++++\n");                  DEBUG_SCARD(("+++++++++++++++++++++\n"));
2148                  hexdump((unsigned char *) pOutBuffer, nBytesReturned);                  hexdump((unsigned char *) pOutBuffer, nBytesReturned);
2149                  printf("+++++++++++++++++++++\n");                  DEBUG_SCARD(("+++++++++++++++++++++\n"));
2150          }          }
2151  #endif  #endif
2152    
# Line 2214  scard_device_control(NTHANDLE handle, ui Line 2178  scard_device_control(NTHANDLE handle, ui
2178          SERVER_DWORD Result = 0x00000000;          SERVER_DWORD Result = 0x00000000;
2179          unsigned char *psize, *pend, *pStatusCode;          unsigned char *psize, *pend, *pStatusCode;
2180          SERVER_DWORD addToEnd = 0;          SERVER_DWORD addToEnd = 0;
2181    #ifdef WITH_DEBUG_SCARD
 #ifdef WITH_SCARD_DEBUG  
2182          unsigned char *pbeg = out->p;          unsigned char *pbeg = out->p;
2183          printf("--------------------------------\n");  
2184          printf("[NTHANDLE %08X]\n", handle);          DEBUG_SCARD(("--------------------------------\n"));
2185          printf("[REQUEST %08X]\n", request);          DEBUG_SCARD(("[NTHANDLE %08X]\n", handle));
2186          printf("[INPUT DUMP]--------------------\n");          DEBUG_SCARD(("[REQUEST %08X]\n", request));
2187            DEBUG_SCARD(("[INPUT DUMP]--------------------\n"));
2188          hexdump(in->p, in->end - in->p);          hexdump(in->p, in->end - in->p);
2189  #endif  #endif
2190          /* Processing request */          /* Processing request */
# Line 2238  scard_device_control(NTHANDLE handle, ui Line 2202  scard_device_control(NTHANDLE handle, ui
2202                          /* SCardEstablishContext */                          /* SCardEstablishContext */
2203                  case SC_ESTABLISH_CONTEXT:                  case SC_ESTABLISH_CONTEXT:
2204                          {                          {
2205  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardEstablishContext--->\n"));
                                 printf("<---SCardEstablishContext--->\n");  
 #endif  
2206                                  Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out);                                  Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out);
2207                                  break;                                  break;
2208                          }                          }
2209                          /* SCardReleaseContext */                          /* SCardReleaseContext */
2210                  case SC_RELEASE_CONTEXT:                  case SC_RELEASE_CONTEXT:
2211                          {                          {
2212  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardReleaseContext--->\n"));
                                 printf("<---SCardReleaseContext--->\n");  
 #endif  
2213                                  Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out);                                  Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out);
2214                                  break;                                  break;
2215                          }                          }
2216                          /* SCardIsValidContext */                          /* SCardIsValidContext */
2217                  case SC_IS_VALID_CONTEXT:                  case SC_IS_VALID_CONTEXT:
2218                          {                          {
2219  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardIsValidContext--->\n"));
                                 printf("<---SCardIsValidContext--->\n");  
 #endif  
2220                                  Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out);                                  Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out);
2221                                  break;                                  break;
2222                          }                          }
# Line 2267  scard_device_control(NTHANDLE handle, ui Line 2225  scard_device_control(NTHANDLE handle, ui
2225                  case SC_LIST_READERS + 4:       /* SCardListReadersW */                  case SC_LIST_READERS + 4:       /* SCardListReadersW */
2226                          {                          {
2227                                  BOOL wide = request != SC_LIST_READERS;                                  BOOL wide = request != SC_LIST_READERS;
2228  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardListReaders---> (%s)\n",
2229                                  printf("<---SCardListReaders---> (%s)\n",                                               (wide) ? ("WIDE") : ("ASCII")));
                                        (wide) ? ("WIDE") : ("ASCII"));  
 #endif  
2230                                  Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide);                                  Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide);
2231                                  break;                                  break;
2232                          }                          }
# Line 2279  scard_device_control(NTHANDLE handle, ui Line 2235  scard_device_control(NTHANDLE handle, ui
2235                  case SC_CONNECT + 4:    /* SCardConnectW */                  case SC_CONNECT + 4:    /* SCardConnectW */
2236                          {                          {
2237                                  BOOL wide = request != SC_CONNECT;                                  BOOL wide = request != SC_CONNECT;
2238  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardConnect---> (%s)\n",
2239                                  printf("<---SCardConnect---> (%s)\n",                                               (wide) ? ("WIDE") : ("ASCII")));
                                        (wide) ? ("WIDE") : ("ASCII"));  
 #endif  
2240                                  Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide);                                  Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide);
2241                                  break;                                  break;
2242                          }                          }
2243                          /* ScardReconnect */                          /* ScardReconnect */
2244                  case SC_RECONNECT:                  case SC_RECONNECT:
2245                          {                          {
2246  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardReconnect--->\n"));
                                 printf("<---SCardReconnect--->\n");  
 #endif  
2247                                  Result = (SERVER_DWORD) TS_SCardReconnect(in, out);                                  Result = (SERVER_DWORD) TS_SCardReconnect(in, out);
2248                                  break;                                  break;
2249                          }                          }
2250                          /* ScardDisconnect */                          /* ScardDisconnect */
2251                  case SC_DISCONNECT:                  case SC_DISCONNECT:
2252                          {                          {
2253  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardDisconnect--->\n"));
                                 printf("<---SCardDisconnect--->\n");  
 #endif  
2254                                  Result = (SERVER_DWORD) TS_SCardDisconnect(in, out);                                  Result = (SERVER_DWORD) TS_SCardDisconnect(in, out);
2255                                  break;                                  break;
2256                          }                          }
# Line 2309  scard_device_control(NTHANDLE handle, ui Line 2259  scard_device_control(NTHANDLE handle, ui
2259                  case SC_GET_STATUS_CHANGE + 4:  /* SCardGetStatusChangeW */                  case SC_GET_STATUS_CHANGE + 4:  /* SCardGetStatusChangeW */
2260                          {                          {
2261                                  BOOL wide = request != SC_GET_STATUS_CHANGE;                                  BOOL wide = request != SC_GET_STATUS_CHANGE;
2262  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardGetStatusChange---> (%s)\n",
2263                                  printf("<---SCardGetStatusChange---> (%s)\n",                                               (wide) ? ("WIDE") : ("ASCII")));
                                        (wide) ? ("WIDE") : ("ASCII"));  
 #endif  
2264                                  Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide);                                  Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide);
2265                                  break;                                  break;
2266                          }                          }
2267                          /* SCardCancel */                          /* SCardCancel */
2268                  case SC_CANCEL:                  case SC_CANCEL:
2269                          {                          {
2270  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardCancel--->\n"));
                                 printf("<---SCardCancel--->\n");  
 #endif  
2271                                  Result = (SERVER_DWORD) TS_SCardCancel(in, out);                                  Result = (SERVER_DWORD) TS_SCardCancel(in, out);
2272                                  break;                                  break;
2273                          }                          }
# Line 2330  scard_device_control(NTHANDLE handle, ui Line 2276  scard_device_control(NTHANDLE handle, ui
2276                  case SC_LOCATE_CARDS_BY_ATR + 4:        /* SCardLocateCardsByATRW */                  case SC_LOCATE_CARDS_BY_ATR + 4:        /* SCardLocateCardsByATRW */
2277                          {                          {
2278                                  BOOL wide = request != SC_LOCATE_CARDS_BY_ATR;                                  BOOL wide = request != SC_LOCATE_CARDS_BY_ATR;
2279  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardLocateCardsByATR---> (%s)\n",
2280                                  printf("<---SCardLocateCardsByATR---> (%s)\n",                                               (wide) ? ("WIDE") : ("ASCII")));
                                        (wide) ? ("WIDE") : ("ASCII"));  
 #endif  
2281                                  Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide);                                  Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide);
2282                                  break;                                  break;
2283                          }                          }
2284                          /* SCardBeginTransaction */                          /* SCardBeginTransaction */
2285                  case SC_BEGIN_TRANSACTION:                  case SC_BEGIN_TRANSACTION:
2286                          {                          {
2287  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardBeginTransaction--->\n"));
                                 printf("<---SCardBeginTransaction--->\n");  
 #endif  
2288                                  Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out);                                  Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out);
2289                                  break;                                  break;
2290                          }                          }
2291                          /* SCardBeginTransaction */                          /* SCardBeginTransaction */
2292                  case SC_END_TRANSACTION:                  case SC_END_TRANSACTION:
2293                          {                          {
2294  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardEndTransaction--->\n"));
                                 printf("<---SCardEndTransaction--->\n");  
 #endif  
2295                                  Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out);                                  Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out);
2296                                  break;                                  break;
2297                          }                          }
2298                          /* ScardTransmit */                          /* ScardTransmit */
2299                  case SC_TRANSMIT:                  case SC_TRANSMIT:
2300                          {                          {
2301  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardTransmit--->\n"));
                                 printf("<---SCardTransmit--->\n");  
 #endif  
2302                                  Result = (SERVER_DWORD) TS_SCardTransmit(in, out);                                  Result = (SERVER_DWORD) TS_SCardTransmit(in, out);
2303                                  break;                                  break;
2304                          }                          }
2305                          /* SCardControl */                          /* SCardControl */
2306                  case SC_CONTROL:                  case SC_CONTROL:
2307                          {                          {
2308  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardControl--->\n"));
                                 printf("<---SCardControl--->\n");  
 #endif  
2309                                  Result = (SERVER_DWORD) TS_SCardControl(in, out);                                  Result = (SERVER_DWORD) TS_SCardControl(in, out);
2310                                  break;                                  break;
2311                          }                          }
# Line 2377  scard_device_control(NTHANDLE handle, ui Line 2313  scard_device_control(NTHANDLE handle, ui
2313  #ifndef WITH_PCSC120  #ifndef WITH_PCSC120
2314                  case SC_GETATTRIB:                  case SC_GETATTRIB:
2315                          {                          {
2316  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardGetAttrib--->\n"));
                                 printf("<---SCardGetAttrib--->\n");  
 #endif  
2317                                  Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out);                                  Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out);
2318                                  break;                                  break;
2319                          }                          }
2320  #endif  #endif
2321                  case SC_ACCESS_STARTED_EVENT:                  case SC_ACCESS_STARTED_EVENT:
2322                          {                          {
2323  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardAccessStartedEvent-->\n"));
                                 printf("<---SCardAccessStartedEvent-->\n");  
 #endif  
2324                                  Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out);                                  Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out);
2325                                  break;                                  break;
2326                          }                          }
# Line 2396  scard_device_control(NTHANDLE handle, ui Line 2328  scard_device_control(NTHANDLE handle, ui
2328                  case SC_STATUS + 4:     /* SCardStatusW */                  case SC_STATUS + 4:     /* SCardStatusW */
2329                          {                          {
2330                                  BOOL wide = request != SC_STATUS;                                  BOOL wide = request != SC_STATUS;
2331  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardStatus---> (%s)\n",
2332                                  printf("<---SCardStatus---> (%s)\n", (wide) ? ("WIDE") : ("ASCII"));                                               (wide) ? ("WIDE") : ("ASCII")));
 #endif  
2333                                  Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide);                                  Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide);
2334                                  break;                                  break;
2335                          }                          }
2336                  case SC_STATE:  /* SCardState */                  case SC_STATE:  /* SCardState */
2337                          {                          {
2338  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---SCardState--->"));
                                 printf("<---SCardState--->");  
 #endif  
2339                                  Result = (SERVER_DWORD) TS_SCardState(in, out);                                  Result = (SERVER_DWORD) TS_SCardState(in, out);
2340                                  break;                                  break;
2341                          }                          }
2342                  default:                  default:
2343                          {                          {
2344  #ifdef WITH_SCARD_DEBUG                                  DEBUG_SCARD(("<---UNSUPPORTED-FUNC--->\n"));
                                 printf("<---UNSUPPORTED-FUNC--->\n");  
 #endif  
2345                                  Result = 0x80100014;                                  Result = 0x80100014;
2346                                  out_uint8s(out, 256);                                  out_uint8s(out, 256);
2347                                  break;                                  break;
# Line 2441  scard_device_control(NTHANDLE handle, ui Line 2368  scard_device_control(NTHANDLE handle, ui
2368                  out_uint8s(out, addToEnd);                  out_uint8s(out, addToEnd);
2369          }          }
2370    
2371  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
2372          printf("[OUTPUT DUMP]-------------------\n");          DEBUG_SCARD(("[OUTPUT DUMP]-------------------\n"));
2373          hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg);          hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg);
2374          printf("--------------------------------\n");          DEBUG_SCARD(("--------------------------------\n"));
2375  #endif  #endif
2376          return STATUS_SUCCESS;          return STATUS_SUCCESS;
2377  }  }
# Line 2595  SC_deviceControl(PSCThreadData data) Line 2522  SC_deviceControl(PSCThreadData data)
2522  static void *  static void *
2523  thread_function(PThreadListElement listElement)  thread_function(PThreadListElement listElement)
2524  {  {
2525  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
2526          long sTime = 0;          long sTime = 0;
2527  #endif  #endif
2528          if ((listElement != NULL) && (listElement->data != NULL))          if ((listElement != NULL) && (listElement->data != NULL))
2529          {          {
2530                  while (1)                  while (1)
2531                  {                  {
2532  #ifdef WITH_SCARD_DEBUG  #ifdef WITH_DEBUG_SCARD
2533                          sTime = time(NULL);                          sTime = time(NULL);
2534  #endif  #endif
2535                          pthread_mutex_lock(&listElement->nodata);                          pthread_mutex_lock(&listElement->nodata);
2536                          SC_deviceControl(listElement->data);                          SC_deviceControl(listElement->data);
2537                          listElement->data = NULL;                          listElement->data = NULL;
2538  #ifdef WITH_SCARD_DEBUG                          DEBUG_SCARD(("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime)));
                         printf("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime));  
 #endif  
2539                          pthread_mutex_unlock(&listElement->busy);                          pthread_mutex_unlock(&listElement->busy);
2540                  }                  }
2541          }          }
# Line 2624  SC_handleRequest(PSCThreadData data) Line 2549  SC_handleRequest(PSCThreadData data)
2549          int Result = 0;          int Result = 0;
2550          PThreadListElement cur = threadList, last = threadList;          PThreadListElement cur = threadList, last = threadList;
2551    
2552  #ifdef WITH_SCARD_DEBUG          DEBUG_SCARD(("[THREAD COUNT %d]\n", threadCount));
         printf("[THREAD COUNT %d]\n", threadCount);  
 #endif  
2553    
2554          while (cur)          while (cur)
2555          {          {
# Line 2659  SC_handleRequest(PSCThreadData data) Line 2582  SC_handleRequest(PSCThreadData data)
2582          Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur);          Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur);
2583          if (0 != Result)          if (0 != Result)
2584          {          {
2585                  printf("[THREAD CREATE ERROR 0x%.8x]\n", Result);                  error("[THREAD CREATE ERROR 0x%.8x]\n", Result);
2586                  SC_xfree(&threadListHandle, cur);                  SC_xfree(&threadListHandle, cur);
2587                  SC_destroyThreadData(data);                  SC_destroyThreadData(data);
2588                  data = NULL;                  data = NULL;

Legend:
Removed from v.1312  
changed lines
  Added in v.1319

  ViewVC Help
Powered by ViewVC 1.1.26