/[rdesktop]/sourceforge.net/trunk/rdesktop/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 /sourceforge.net/trunk/rdesktop/scard.c

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

revision 1319 by stargo, Thu Nov 2 20:48:28 2006 UTC revision 1328 by stargo, Fri Nov 3 23:51:35 2006 UTC
# Line 44  Line 44 
44    
45  static struct stream out[STREAM_COUNT];  static struct stream out[STREAM_COUNT];
46  static int cur_stream_id = 0;  static int cur_stream_id = 0;
47  static pthread_mutex_t *tcp_sendcontrol_mutex = NULL;  static pthread_mutex_t **scard_mutex = NULL;
48    
49  static uint32 curDevice = 0, curId = 0, curBytesOut = 0;  static uint32 curDevice = 0, curId = 0, curBytesOut = 0;
50  static PSCNameMapRec nameMapList = NULL;  static PSCNameMapRec nameMapList = NULL;
# Line 54  static pthread_t queueHandler; Line 54  static pthread_t queueHandler;
54  static pthread_mutex_t queueAccess;  static pthread_mutex_t queueAccess;
55  static pthread_mutex_t queueEmpty;  static pthread_mutex_t queueEmpty;
56  static pthread_mutex_t hcardAccess;  static pthread_mutex_t hcardAccess;
 /* static pthread_mutex_t sendControl; */  
57    
58  static PMEM_HANDLE threadListHandle = NULL;  static PMEM_HANDLE threadListHandle = NULL;
59  static PThreadListElement threadList = NULL;  static PThreadListElement threadList = NULL;
# Line 152  scard_enum_devices(uint32 * id, char *op Line 151  scard_enum_devices(uint32 * id, char *op
151                  return 0;                  return 0;
152          }          }
153    
 #if 0  
         if (0 != pthread_mutex_init(&sendControl, NULL))  
         {  
                 error("[SMART CARD: Can't initialize send control mutex]\n");  
                 return 0;  
         }  
 #endif  
   
   
154          if (0 !=          if (0 !=
155              pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL))              pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL))
156          {          {
# Line 233  scard_enum_devices(uint32 * id, char *op Line 223  scard_enum_devices(uint32 * id, char *op
223                  }                  }
224          }          }
225    
   
         printf("******************************************************\n");  
         printf("* Smart Card support for RDesktop is initialized.    *\n");  
         printf("* Copyright (C) by Alexi Volkov, alexi@myrealbox.com *\n");  
         printf("******************************************************\n");  
   
226          return count;          return count;
227  }  }
228    
# Line 497  outBufferFinish(STREAM out, char *buffer Line 481  outBufferFinish(STREAM out, char *buffer
481  }  }
482    
483  static void  static void
484  outForceAllignment(STREAM out, unsigned int seed)  outForceAlignment(STREAM out, unsigned int seed)
485  {  {
486          SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed;          SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed;
487          if (add > 0)          if (add > 0)
         {  
488                  out_uint8s(out, add);                  out_uint8s(out, add);
         }  
489  }  }
490    
491  static unsigned int  static unsigned int
# Line 696  TS_SCardIsValidContext(STREAM in, STREAM Line 678  TS_SCardIsValidContext(STREAM in, STREAM
678                  DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"));
679          }          }
680    
681          outForceAllignment(out, 8);          outForceAlignment(out, 8);
682          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
683          return rv;          return rv;
684  }  }
# Line 769  TS_SCardListReaders(STREAM in, STREAM ou Line 751  TS_SCardListReaders(STREAM in, STREAM ou
751          out_uint32_le(out, dataLength);          out_uint32_le(out, dataLength);
752          out->p = pend;          out->p = pend;
753    
754          outForceAllignment(out, 8);          outForceAlignment(out, 8);
755          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
756          return rv;          return rv;
757  }  }
# Line 844  TS_SCardConnect(STREAM in, STREAM out, B Line 826  TS_SCardConnect(STREAM in, STREAM out, B
826          out_uint32_le(out, 0x00000004);          out_uint32_le(out, 0x00000004);
827          out_uint32_le(out, hCard);          out_uint32_le(out, hCard);
828    
829          outForceAllignment(out, 8);          outForceAlignment(out, 8);
830          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
831          return rv;          return rv;
832  }  }
# Line 887  TS_SCardReconnect(STREAM in, STREAM out) Line 869  TS_SCardReconnect(STREAM in, STREAM out)
869                  DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n"));
870          }          }
871    
872          outForceAllignment(out, 8);          outForceAlignment(out, 8);
873          out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol);          out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol);
874          return rv;          return rv;
875  }  }
# Line 943  TS_SCardDisconnect(STREAM in, STREAM out Line 925  TS_SCardDisconnect(STREAM in, STREAM out
925                  DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n"));
926          }          }
927    
928          outForceAllignment(out, 8);          outForceAlignment(out, 8);
929          return rv;          return rv;
930  }  }
931    
# Line 1200  TS_SCardGetStatusChange(STREAM in, STREA Line 1182  TS_SCardGetStatusChange(STREAM in, STREA
1182                  out_uint8p(out, (void *) ((unsigned char **) cur + 2),                  out_uint8p(out, (void *) ((unsigned char **) cur + 2),
1183                             sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));                             sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));
1184          }          }
1185          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1186          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1187          return rv;          return rv;
1188  }  }
# Line 1224  TS_SCardCancel(STREAM in, STREAM out) Line 1206  TS_SCardCancel(STREAM in, STREAM out)
1206          {          {
1207                  DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n"));
1208          }          }
1209          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1210          return rv;          return rv;
1211  }  }
1212    
# Line 1329  TS_SCardLocateCardsByATR(STREAM in, STRE Line 1311  TS_SCardLocateCardsByATR(STREAM in, STRE
1311                             sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));                             sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));
1312          }          }
1313    
1314          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1315          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1316          return rv;          return rv;
1317  }  }
# Line 1355  TS_SCardBeginTransaction(STREAM in, STRE Line 1337  TS_SCardBeginTransaction(STREAM in, STRE
1337          {          {
1338                  DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n"));
1339          }          }
1340          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1341          return rv;          return rv;
1342  }  }
1343    
# Line 1386  TS_SCardEndTransaction(STREAM in, STREAM Line 1368  TS_SCardEndTransaction(STREAM in, STREAM
1368          {          {
1369                  DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n"));
1370          }          }
1371          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1372          return rv;          return rv;
1373  }  }
1374    
# Line 1629  TS_SCardTransmit(STREAM in, STREAM out) Line 1611  TS_SCardTransmit(STREAM in, STREAM out)
1611    
1612                  outBufferFinish(out, (char *) recvBuf, cbRecvLength);                  outBufferFinish(out, (char *) recvBuf, cbRecvLength);
1613          }          }
1614          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1615          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1616          return rv;          return rv;
1617  }  }
# Line 1745  TS_SCardStatus(STREAM in, STREAM out, BO Line 1727  TS_SCardStatus(STREAM in, STREAM out, BO
1727                  out_uint32_le(out, dataLength);                  out_uint32_le(out, dataLength);
1728                  out->p = psave;                  out->p = psave;
1729          }          }
1730          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1731          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1732          return rv;          return rv;
1733  }  }
# Line 1839  TS_SCardState(STREAM in, STREAM out) Line 1821  TS_SCardState(STREAM in, STREAM out)
1821                  out_uint8p(out, atr, dwAtrLen);                  out_uint8p(out, atr, dwAtrLen);
1822                  outRepos(out, dwAtrLen);                  outRepos(out, dwAtrLen);
1823          }          }
1824          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1825          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1826          return rv;          return rv;
1827  }  }
# Line 1892  TS_SCardListReaderGroups(STREAM in, STRE Line 1874  TS_SCardListReaderGroups(STREAM in, STRE
1874          outRepos(out, dwGroups);          outRepos(out, dwGroups);
1875          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
1876    
1877          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1878          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1879          return rv;          return rv;
1880  }  }
# Line 1993  TS_SCardGetAttrib(STREAM in, STREAM out) Line 1975  TS_SCardGetAttrib(STREAM in, STREAM out)
1975                  outRepos(out, dwAttrLen);                  outRepos(out, dwAttrLen);
1976                  out_uint32_le(out, 0x00000000);                  out_uint32_le(out, 0x00000000);
1977          }          }
1978          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1979          return rv;          return rv;
1980  }  }
1981    
# Line 2046  TS_SCardSetAttrib(STREAM in, STREAM out) Line 2028  TS_SCardSetAttrib(STREAM in, STREAM out)
2028          out_uint32_le(out, 0x00000200);          out_uint32_le(out, 0x00000200);
2029          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
2030          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
2031          outForceAllignment(out, 8);          outForceAlignment(out, 8);
2032          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
2033          return rv;          return rv;
2034  }  }
# Line 2159  TS_SCardControl(STREAM in, STREAM out) Line 2141  TS_SCardControl(STREAM in, STREAM out)
2141                  outRepos(out, nBytesReturned);                  outRepos(out, nBytesReturned);
2142          }          }
2143    
2144          outForceAllignment(out, 8);          outForceAlignment(out, 8);
2145          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
2146          return rv;          return rv;
2147  }  }
# Line 2508  SC_deviceControl(PSCThreadData data) Line 2490  SC_deviceControl(PSCThreadData data)
2490          size_t buffer_len = 0;          size_t buffer_len = 0;
2491          scard_device_control(data->handle, data->request, data->in, data->out);          scard_device_control(data->handle, data->request, data->in, data->out);
2492          buffer_len = (size_t) data->out->p - (size_t) data->out->data;          buffer_len = (size_t) data->out->p - (size_t) data->out->data;
 #if 0  
         pthread_mutex_lock(&sendControl);  
 #endif  
2493          rdpdr_send_completion(data->device, data->id, 0, buffer_len, data->out->data, buffer_len);          rdpdr_send_completion(data->device, data->id, 0, buffer_len, data->out->data, buffer_len);
 #if 0  
         pthread_mutex_unlock(&sendControl);  
 #endif  
2494          SC_destroyThreadData(data);          SC_destroyThreadData(data);
2495  }  }
2496    
# Line 2643  DEVICE_FNS scard_fns = { Line 2619  DEVICE_FNS scard_fns = {
2619  #endif /* MAKE_PROTO */  #endif /* MAKE_PROTO */
2620    
2621  void  void
2622  scard_tcp_lock(void)  scard_lock(int lock)
2623  {  {
2624          if (!tcp_sendcontrol_mutex)          if (!scard_mutex)
2625            {
2626                    scard_mutex =
2627                            (pthread_mutex_t **) xmalloc(sizeof(pthread_mutex_t *) * SCARD_LOCK_LAST);
2628            }
2629    
2630            if (!scard_mutex[lock])
2631          {          {
2632                  tcp_sendcontrol_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));                  scard_mutex[lock] = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t));
2633                  pthread_mutex_init(tcp_sendcontrol_mutex, NULL);                  pthread_mutex_init(scard_mutex[lock], NULL);
2634          }          }
2635    
2636          pthread_mutex_lock(tcp_sendcontrol_mutex);          pthread_mutex_lock(scard_mutex[lock]);
2637  }  }
2638    
2639  void  void
2640  scard_tcp_unlock(void)  scard_unlock(int lock)
2641  {  {
2642          pthread_mutex_unlock(tcp_sendcontrol_mutex);          pthread_mutex_unlock(scard_mutex[lock]);
2643  }  }
2644    
2645  STREAM  STREAM

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

  ViewVC Help
Powered by ViewVC 1.1.26