/[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 1319 by stargo, Thu Nov 2 20:48:28 2006 UTC revision 1327 by stargo, Fri Nov 3 19:56:42 2006 UTC
# Line 45  Line 45 
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 *tcp_sendcontrol_mutex = NULL;
48    static pthread_mutex_t *sec_channels_mutex = NULL;
49    
50  static uint32 curDevice = 0, curId = 0, curBytesOut = 0;  static uint32 curDevice = 0, curId = 0, curBytesOut = 0;
51  static PSCNameMapRec nameMapList = NULL;  static PSCNameMapRec nameMapList = NULL;
# Line 54  static pthread_t queueHandler; Line 55  static pthread_t queueHandler;
55  static pthread_mutex_t queueAccess;  static pthread_mutex_t queueAccess;
56  static pthread_mutex_t queueEmpty;  static pthread_mutex_t queueEmpty;
57  static pthread_mutex_t hcardAccess;  static pthread_mutex_t hcardAccess;
 /* static pthread_mutex_t sendControl; */  
58    
59  static PMEM_HANDLE threadListHandle = NULL;  static PMEM_HANDLE threadListHandle = NULL;
60  static PThreadListElement threadList = NULL;  static PThreadListElement threadList = NULL;
# Line 152  scard_enum_devices(uint32 * id, char *op Line 152  scard_enum_devices(uint32 * id, char *op
152                  return 0;                  return 0;
153          }          }
154    
 #if 0  
         if (0 != pthread_mutex_init(&sendControl, NULL))  
         {  
                 error("[SMART CARD: Can't initialize send control mutex]\n");  
                 return 0;  
         }  
 #endif  
   
   
155          if (0 !=          if (0 !=
156              pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL))              pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL))
157          {          {
# Line 233  scard_enum_devices(uint32 * id, char *op Line 224  scard_enum_devices(uint32 * id, char *op
224                  }                  }
225          }          }
226    
   
         printf("******************************************************\n");  
         printf("* Smart Card support for RDesktop is initialized.    *\n");  
         printf("* Copyright (C) by Alexi Volkov, alexi@myrealbox.com *\n");  
         printf("******************************************************\n");  
   
227          return count;          return count;
228  }  }
229    
# Line 497  outBufferFinish(STREAM out, char *buffer Line 482  outBufferFinish(STREAM out, char *buffer
482  }  }
483    
484  static void  static void
485  outForceAllignment(STREAM out, unsigned int seed)  outForceAlignment(STREAM out, unsigned int seed)
486  {  {
487          SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed;          SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed;
488          if (add > 0)          if (add > 0)
         {  
489                  out_uint8s(out, add);                  out_uint8s(out, add);
         }  
490  }  }
491    
492  static unsigned int  static unsigned int
# Line 696  TS_SCardIsValidContext(STREAM in, STREAM Line 679  TS_SCardIsValidContext(STREAM in, STREAM
679                  DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"));
680          }          }
681    
682          outForceAllignment(out, 8);          outForceAlignment(out, 8);
683          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
684          return rv;          return rv;
685  }  }
# Line 769  TS_SCardListReaders(STREAM in, STREAM ou Line 752  TS_SCardListReaders(STREAM in, STREAM ou
752          out_uint32_le(out, dataLength);          out_uint32_le(out, dataLength);
753          out->p = pend;          out->p = pend;
754    
755          outForceAllignment(out, 8);          outForceAlignment(out, 8);
756          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
757          return rv;          return rv;
758  }  }
# Line 844  TS_SCardConnect(STREAM in, STREAM out, B Line 827  TS_SCardConnect(STREAM in, STREAM out, B
827          out_uint32_le(out, 0x00000004);          out_uint32_le(out, 0x00000004);
828          out_uint32_le(out, hCard);          out_uint32_le(out, hCard);
829    
830          outForceAllignment(out, 8);          outForceAlignment(out, 8);
831          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
832          return rv;          return rv;
833  }  }
# Line 887  TS_SCardReconnect(STREAM in, STREAM out) Line 870  TS_SCardReconnect(STREAM in, STREAM out)
870                  DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n"));
871          }          }
872    
873          outForceAllignment(out, 8);          outForceAlignment(out, 8);
874          out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol);          out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol);
875          return rv;          return rv;
876  }  }
# Line 943  TS_SCardDisconnect(STREAM in, STREAM out Line 926  TS_SCardDisconnect(STREAM in, STREAM out
926                  DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n"));
927          }          }
928    
929          outForceAllignment(out, 8);          outForceAlignment(out, 8);
930          return rv;          return rv;
931  }  }
932    
# Line 1200  TS_SCardGetStatusChange(STREAM in, STREA Line 1183  TS_SCardGetStatusChange(STREAM in, STREA
1183                  out_uint8p(out, (void *) ((unsigned char **) cur + 2),                  out_uint8p(out, (void *) ((unsigned char **) cur + 2),
1184                             sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));                             sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));
1185          }          }
1186          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1187          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1188          return rv;          return rv;
1189  }  }
# Line 1224  TS_SCardCancel(STREAM in, STREAM out) Line 1207  TS_SCardCancel(STREAM in, STREAM out)
1207          {          {
1208                  DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n"));
1209          }          }
1210          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1211          return rv;          return rv;
1212  }  }
1213    
# Line 1329  TS_SCardLocateCardsByATR(STREAM in, STRE Line 1312  TS_SCardLocateCardsByATR(STREAM in, STRE
1312                             sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));                             sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *));
1313          }          }
1314    
1315          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1316          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1317          return rv;          return rv;
1318  }  }
# Line 1355  TS_SCardBeginTransaction(STREAM in, STRE Line 1338  TS_SCardBeginTransaction(STREAM in, STRE
1338          {          {
1339                  DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n"));
1340          }          }
1341          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1342          return rv;          return rv;
1343  }  }
1344    
# Line 1386  TS_SCardEndTransaction(STREAM in, STREAM Line 1369  TS_SCardEndTransaction(STREAM in, STREAM
1369          {          {
1370                  DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n"));                  DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n"));
1371          }          }
1372          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1373          return rv;          return rv;
1374  }  }
1375    
# Line 1629  TS_SCardTransmit(STREAM in, STREAM out) Line 1612  TS_SCardTransmit(STREAM in, STREAM out)
1612    
1613                  outBufferFinish(out, (char *) recvBuf, cbRecvLength);                  outBufferFinish(out, (char *) recvBuf, cbRecvLength);
1614          }          }
1615          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1616          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1617          return rv;          return rv;
1618  }  }
# Line 1745  TS_SCardStatus(STREAM in, STREAM out, BO Line 1728  TS_SCardStatus(STREAM in, STREAM out, BO
1728                  out_uint32_le(out, dataLength);                  out_uint32_le(out, dataLength);
1729                  out->p = psave;                  out->p = psave;
1730          }          }
1731          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1732          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1733          return rv;          return rv;
1734  }  }
# Line 1839  TS_SCardState(STREAM in, STREAM out) Line 1822  TS_SCardState(STREAM in, STREAM out)
1822                  out_uint8p(out, atr, dwAtrLen);                  out_uint8p(out, atr, dwAtrLen);
1823                  outRepos(out, dwAtrLen);                  outRepos(out, dwAtrLen);
1824          }          }
1825          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1826          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1827          return rv;          return rv;
1828  }  }
# Line 1892  TS_SCardListReaderGroups(STREAM in, STRE Line 1875  TS_SCardListReaderGroups(STREAM in, STRE
1875          outRepos(out, dwGroups);          outRepos(out, dwGroups);
1876          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
1877    
1878          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1879          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
1880          return rv;          return rv;
1881  }  }
# Line 1993  TS_SCardGetAttrib(STREAM in, STREAM out) Line 1976  TS_SCardGetAttrib(STREAM in, STREAM out)
1976                  outRepos(out, dwAttrLen);                  outRepos(out, dwAttrLen);
1977                  out_uint32_le(out, 0x00000000);                  out_uint32_le(out, 0x00000000);
1978          }          }
1979          outForceAllignment(out, 8);          outForceAlignment(out, 8);
1980          return rv;          return rv;
1981  }  }
1982    
# Line 2046  TS_SCardSetAttrib(STREAM in, STREAM out) Line 2029  TS_SCardSetAttrib(STREAM in, STREAM out)
2029          out_uint32_le(out, 0x00000200);          out_uint32_le(out, 0x00000200);
2030          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
2031          out_uint32_le(out, 0x00000000);          out_uint32_le(out, 0x00000000);
2032          outForceAllignment(out, 8);          outForceAlignment(out, 8);
2033          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
2034          return rv;          return rv;
2035  }  }
# Line 2159  TS_SCardControl(STREAM in, STREAM out) Line 2142  TS_SCardControl(STREAM in, STREAM out)
2142                  outRepos(out, nBytesReturned);                  outRepos(out, nBytesReturned);
2143          }          }
2144    
2145          outForceAllignment(out, 8);          outForceAlignment(out, 8);
2146          SC_xfreeallmemory(&lcHandle);          SC_xfreeallmemory(&lcHandle);
2147          return rv;          return rv;
2148  }  }
# Line 2508  SC_deviceControl(PSCThreadData data) Line 2491  SC_deviceControl(PSCThreadData data)
2491          size_t buffer_len = 0;          size_t buffer_len = 0;
2492          scard_device_control(data->handle, data->request, data->in, data->out);          scard_device_control(data->handle, data->request, data->in, data->out);
2493          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  
2494          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  
2495          SC_destroyThreadData(data);          SC_destroyThreadData(data);
2496  }  }
2497    
# Line 2647  scard_tcp_lock(void) Line 2624  scard_tcp_lock(void)
2624  {  {
2625          if (!tcp_sendcontrol_mutex)          if (!tcp_sendcontrol_mutex)
2626          {          {
2627                  tcp_sendcontrol_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));                  tcp_sendcontrol_mutex = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t));
2628                  pthread_mutex_init(tcp_sendcontrol_mutex, NULL);                  pthread_mutex_init(tcp_sendcontrol_mutex, NULL);
2629          }          }
2630    
# Line 2660  scard_tcp_unlock(void) Line 2637  scard_tcp_unlock(void)
2637          pthread_mutex_unlock(tcp_sendcontrol_mutex);          pthread_mutex_unlock(tcp_sendcontrol_mutex);
2638  }  }
2639    
2640    void
2641    scard_sec_lock(void)
2642    {
2643            if (!sec_channels_mutex)
2644            {
2645                    sec_channels_mutex = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t));
2646                    pthread_mutex_init(sec_channels_mutex, NULL);
2647            }
2648    
2649            pthread_mutex_lock(sec_channels_mutex);
2650    }
2651    
2652    void
2653    scard_sec_unlock(void)
2654    {
2655            pthread_mutex_unlock(sec_channels_mutex);
2656    }
2657    
2658  STREAM  STREAM
2659  scard_tcp_init(void)  scard_tcp_init(void)
2660  {  {

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

  ViewVC Help
Powered by ViewVC 1.1.26