Changeset 782
- Timestamp:
- 12/11/09 05:31:18 (14 years ago)
- Location:
- branches/smartreader
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/smartreader/CMakeLists.txt
r714 r782 71 71 72 72 set (OPTIONAL_LINK_DIR "" CACHE STRING "Some optional link directories") 73 set (OPTIONAL_INCLUDE_DIR " " CACHE STRING "Some optional include directories")73 set (OPTIONAL_INCLUDE_DIR "/usr/include/PCSC" CACHE STRING "Some optional include directories") 74 74 75 75 include_directories ( … … 86 86 set (DEFAULT_CS_CONFDIR "/usr/local/etc") 87 87 elseif (OSCamOperatingSystem MATCHES "Mac OS X") 88 add_definitions ("-DOS_MACOSX -D NEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD")88 add_definitions ("-DOS_MACOSX -DHAVE_PCSC -DNEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD") 89 89 set (DEFAULT_CS_CONFDIR "/usr/local/etc") 90 90 elseif (OSCamOperatingSystem MATCHES "Tuxbox") … … 136 136 endif (HAVE_SHA) 137 137 138 check_include_file ("PCSC/wintypes.h" HAVE_PCSC) 139 if (HAVE_PCSC) 140 add_definitions ("-DHAVE_PCSC") 141 endif (HAVE_PCSC) 142 138 143 #----------------------- subdirectories ------------------------------ 139 144 … … 176 181 target_link_libraries (${exe_name} crypto) 177 182 endif (HAVE_AES) 183 if (HAVE_PCSC) 184 if (NOT OSCamOperatingSystem MATCHES "Mac OS X") 185 target_link_libraries (${exe_name} pcsclite) 186 endif (NOT OSCamOperatingSystem MATCHES "Mac OS X") 187 endif (HAVE_PCSC) 188 178 189 add_dependencies (${exe_name} ${csoscam} ${csreaders} ${csmodules}) 179 190 … … 182 193 if (OSCamOperatingSystem MATCHES "Linux") 183 194 elseif (OSCamOperatingSystem MATCHES "Mac OS X") 195 FIND_LIBRARY (PCSC_LIBRARY PCSC) 196 message (STATUS "OS X system PCSC : ${PCSC_LIBRARY}") 197 target_link_libraries ( ${exe_name} ${PCSC_LIBRARY}) 198 set (HAVE_PCSC "1") 184 199 elseif (OSCamOperatingSystem MATCHES "Tuxbox") 185 200 target_link_libraries ( ${exe_name} dl) … … 295 310 message (STATUS " use built-in sha functions") 296 311 endif (HAVE_SHA) 312 if (HAVE_PCSC) 313 message (STATUS " use system pcsc functions") 314 endif (HAVE_PCSC) 297 315 message (STATUS "") -
branches/smartreader/Distribution/doc/man/oscam.server.5
r764 r782 9 9 .SS "The [reader] section" 10 10 .PP 11 \fBdevice\fP = \fBdevice\fP|\fB<ip|hostname >,<port>[,<lport>]\fP12 .RS 3n 13 define local or remote reader (lport: remapping to local port) 11 \fBdevice\fP = \fBdevice\fP|\fB<ip|hostname|pcsc>,<port>[,<lport>]\fP 12 .RS 3n 13 define local or remote reader (lport: remapping to local port). For pcsc, it defines the number of the reader in the system, starting at 0. 14 14 .RE 15 15 .PP … … 277 277 .TP 3n 278 278 \(bu 279 PCSC compatible reader 280 281 [reader] 282 label = myPCSCReader 283 protocol = pcsc 284 device = 0 285 aeskey = 0102030405060708090a0b0c0d0e0f10 286 group = 1 287 caid = 0500 288 .TP 3n 289 \(bu 279 290 camd 3.78x reader 280 291 -
branches/smartreader/Distribution/doc/txt/oscam.server.txt
r764 r782 13 13 DESCRIPTIONS 14 14 The [reader] section 15 device = device|<ip|hostname >,<port>[,<lport>]15 device = device|<ip|hostname|pscs reader number>,<port>[,<lport>] 16 16 define local or remote reader (lport: remapping to local port) 17 For pcsc, it defines the number of the reader in the system, starting 18 at 0. 17 19 18 20 key = DES key … … 84 86 internal 85 87 serial 88 pcsc 86 89 camd35|cs357x 87 90 cs378x … … 216 219 group = 2 217 220 caid = 0200 221 222 PCSC compatible reader 223 224 [reader] 225 label = myPCSCReader 226 protocol = pcsc 227 device = 0 228 aeskey = 0102030405060708090a0b0c0d0e0f10 229 group = 1 230 caid = 0500 218 231 219 232 camd 3.78x reader -
branches/smartreader/Makefile
r639 r782 7 7 8 8 linux: i386-pc-linux 9 linux-pcsc: i386-pc-linux-pcsc 9 10 freebsd: i386-pc-freebsd 10 11 tuxbox: cross-powerpc-tuxbox-linux … … 75 76 ###################################################################### 76 77 # 78 # LINUX native with PCSC 79 # 80 ###################################################################### 81 i386-pc-linux-pcsc: 82 @-$(MAKE) --no-print-directory \ 83 -f Maketype TYP=$(subst i386,$(shell uname --machine),$(subst cross-,,$@)) \ 84 OS_LIBS="-lcrypto" \ 85 OS_CULI="-lncurses" \ 86 OS_PTLI="-lpthread -lpcsclite" \ 87 DS_OPTS="-O2 -DOS_LINUX -DCS_CONFDIR=${CS_CONFDIR} -DHAVE_PCSC=1 -I/usr/include/PCSC -Winline -Wall -Wno-implicit-function-declaration -Wno-parentheses -finline-functions -fomit-frame-pointer -D'CS_SVN_VERSION="'"$(shell svnversion -n . | sed 's/[MS]$$//' )"'"'" \ 88 DS_CFLAGS="-c" \ 89 DS_LDFLAGS="" \ 90 DS_ARFLAGS="-rvsl" \ 91 DS_CC=gcc \ 92 DS_AR=ar \ 93 DS_LD=ld \ 94 DS_RL=ranlib \ 95 DS_ST=strip 96 97 ###################################################################### 98 # 77 99 # MacOSX native 78 100 # … … 84 106 OS_CULI="-lncurses" \ 85 107 OS_PTLI="-lpthread" \ 86 DS_OPTS="-O2 -DOS_MACOSX -DNEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD -DCS_CONFDIR=${CS_CONFDIR} - Winline -Wall -Wno-implicit-function-declaration -Wno-parentheses -finline-functions -fomit-frame-pointer -D'CS_SVN_VERSION="'"$(shell svnversion -n . | sed 's/[MS]$$//' )"'"'" \87 DS_CFLAGS="-c" \ 88 DS_LDFLAGS=" " \108 DS_OPTS="-O2 -DOS_MACOSX -DNEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD -DCS_CONFDIR=${CS_CONFDIR} -DHAVE_PCSC=1 -Winline -Wall -Wno-implicit-function-declaration -Wno-parentheses -finline-functions -fomit-frame-pointer -D'CS_SVN_VERSION="'"$(shell svnversion -n . | sed 's/[MS]$$//' )"'"'" \ 109 DS_CFLAGS="-c" \ 110 DS_LDFLAGS="-framework PCSC" \ 89 111 DS_ARFLAGS="-rvsl" \ 90 112 DS_CC=gcc \ -
branches/smartreader/Maketype
r660 r782 19 19 VERX = -gbx-$(subst ",,$(filter-out \#define GBXVERSION,$(shell grep GBXVERSION csgbox/gbox.h))) 20 20 endif 21 EXEFILE1 = Distribution/oscam-$(VER)$(VERX)-$(subst cygwin,cygwin.exe,$(TYP))22 21 22 #EXEFILE1 = Distribution/oscam-$(VER)$(VERX)-$(subst cygwin,cygwin.exe,$(TYP)) 23 EXEFILE1 = Distribution/oscam--$(subst cygwin,cygwin.exe,$(TYP)) 23 24 24 25 LIBDIR = lib … … 74 75 75 76 $(EXEFILE1): oscam.c $(LIBFILE1) $(LIBFILE2) $(LIBFILE3) $(GENERAL) 76 $(CC) $(LDFLAGS) oscam.c $(LIBFILE1) $(LIBFILE2) $(LIBFILE3) -o "$@" $( LIBS)77 $(CC) $(LDFLAGS) oscam.c $(LIBFILE1) $(LIBFILE2) $(LIBFILE3) -o "$@" $(OS_INCLUDES) $(LIBS) 77 78 $(STRIP) $@ 78 79 … … 83 84 84 85 .c.a: 85 $(CC) $(CFLAGS) -Icsctapi $ <86 $(CC) $(CFLAGS) -Icsctapi $(OS_INCLUDES) $< 86 87 $(AR) $(ARFLAGS) $@ $*.o 87 88 -@rm -f $*.o -
branches/smartreader/globals.h
r764 r782 48 48 #include "cscrypt/cscrypt.h" 49 49 50 #ifdef HAVE_PCSC 51 #include <PCSC/pcsclite.h> 52 #ifdef OS_MACOSX 53 #include <PCSC/wintypes.h> 54 #else 55 #include <PCSC/reader.h> 56 #endif 57 #endif 58 50 59 #ifndef CS_CONFDIR 51 60 #define CS_CONFDIR "/usr/local/etc" … … 130 139 #define R_IS_NETWORK 0x70 131 140 #define R_IS_CASCADING 0xF0 141 142 #ifdef HAVE_PCSC 143 #define R_PCSC 0x6 // PCSC 144 #endif 132 145 133 146 #define CS_MAX_MOD 8 … … 355 368 char label[32]; 356 369 char device[128]; 370 char pcsc_name[128]; 357 371 int detect; 358 372 int mhz; //actual clock rate of reader in 10khz steps … … 419 433 #endif 420 434 int msg_idx; 435 #ifdef HAVE_PCSC 436 SCARDCONTEXT hContext; 437 SCARDHANDLE hCard; 438 DWORD dwActiveProtocol; 439 #endif 440 421 441 }; 422 442 -
branches/smartreader/oscam-config.c
r744 r782 1099 1099 if (!strcmp(value, "smartreader")) { rdr->typ=R_SMART; return; } 1100 1100 if (!strcmp(value, "internal")) { rdr->typ=R_INTERN; return; } 1101 #ifdef HAVE_PCSC 1102 if (!strcmp(value, "pcsc")) { rdr->typ=R_PCSC; return; } 1103 #endif 1101 1104 if (!strcmp(value, "serial")) { rdr->typ=R_SERIAL; return; } 1102 1105 if (!strcmp(value, "camd35")) { rdr->typ=R_CAMD35; return; } -
branches/smartreader/reader-common.c
r727 r782 69 69 int reader_doapi(uchar dad, uchar *buf, int l, int dbg) 70 70 { 71 #ifdef HAVE_PCSC 72 if (reader[ridx].typ == R_PCSC) { 73 LONG rv; 74 SCARD_IO_REQUEST pioRecvPci; 75 DWORD dwSendLength, dwRecvLength; 76 77 dwSendLength = l; 78 dwRecvLength = sizeof(cta_res); 79 80 //cs_ddump(buf, dwSendLength, "sending %d bytes to PCSC", dwSendLength); 81 82 if(reader[ridx].dwActiveProtocol == SCARD_PROTOCOL_T0) 83 rv = SCardTransmit(reader[ridx].hCard, SCARD_PCI_T0, buf, dwSendLength, &pioRecvPci, &cta_res, &dwRecvLength); 84 else if(reader[ridx].dwActiveProtocol == SCARD_PROTOCOL_T1) 85 rv = SCardTransmit(reader[ridx].hCard, SCARD_PCI_T1, buf, dwSendLength, &pioRecvPci, &cta_res, &dwRecvLength); 86 else { 87 cs_debug("PCSC invalid protocol (T=%d)", reader[ridx].dwActiveProtocol); 88 return ERR_INVALID; 89 } 90 91 cta_lr=dwRecvLength; 92 // cs_ddump(cta_res, cta_lr, "received %d bytes from PCSC with rv=%lx", cta_lr, rv); 93 94 cs_debug("PCSC doapi (%lx ) (T=%d)", rv, reader[ridx].dwActiveProtocol ); 95 if ( rv == SCARD_S_SUCCESS ){ 96 return OK; 97 } else { 98 return ERR_INVALID; 99 } 100 } 101 102 #endif 71 103 int rc; 72 104 uchar sad; … … 121 153 int i; 122 154 char ret; 155 156 #ifdef HAVE_PCSC 157 if (reader[ridx].typ == R_PCSC) { 158 cs_debug("PCSC initializing card in (%s)", &reader[ridx].pcsc_name); 159 LONG rv; 160 DWORD dwState, dwAtrLen, dwReaderLen; 161 BYTE pbAtr[64]; 162 dwAtrLen = sizeof(pbAtr); 163 164 cs_debug("PCSC resetting card in (%s)", &reader[ridx].pcsc_name); 165 rv = SCardReconnect(reader[ridx].hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, SCARD_RESET_CARD, &reader[ridx].dwActiveProtocol); 166 cs_debug("PCSC resetting done on card in (%s)", &reader[ridx].pcsc_name); 167 cs_debug("PCSC Protocol (T=%d)",reader[ridx].dwActiveProtocol); 168 169 if ( rv != SCARD_S_SUCCESS ) { 170 cs_debug("Error PCSC failed to reset card (%lx)", rv); 171 return(0); 172 } 173 174 cs_debug("PCSC getting ATR for card in (%s)", &reader[ridx].device); 175 rv = SCardStatus(reader[ridx].hCard, NULL, &dwReaderLen, &dwState, &reader[ridx].dwActiveProtocol, pbAtr, &dwAtrLen); 176 if ( rv == SCARD_S_SUCCESS ) { 177 cs_debug("PCSC Protocol (T=%d)",reader[ridx].dwActiveProtocol); 178 179 /* 180 DWORD currentClk, currentClkLen; 181 currentClkLen = sizeof(currentClk); 182 rv = SCardGetAttrib(reader[ridx].hCard, SCARD_ATTR_CURRENT_CLK , ¤tClk, ¤tClkLen); 183 cs_debug("PCSC rv=(%lx) Current clk = %lx Khz",rv, currentClk); 184 */ 185 186 // TODO: merge better 187 memcpy(atr, pbAtr, dwAtrLen); 188 atr_size=dwAtrLen; 189 #ifdef CS_RDR_INIT_HIST 190 reader[ridx].init_history_pos=0; 191 memset(reader[ridx].init_history, 0, sizeof(reader[ridx].init_history)); 192 #endif 193 cs_ri_log("ATR: %s", cs_hexdump(1, (uchar *)pbAtr, dwAtrLen)); 194 sleep(1); 195 return(1); 196 197 } else { 198 cs_debug("Error PCSC failed to get ATR for card (%lx)", rv); 199 return(0); 200 } 201 } 202 #endif 123 203 124 204 cta_cmd[0] = CTBCS_INS_RESET; … … 278 358 static int reader_card_inserted(void) 279 359 { 360 #ifdef HAVE_PCSC 361 if (reader[ridx].typ == R_PCSC) { 362 DWORD dwState, dwAtrLen, dwReaderLen; 363 BYTE pbAtr[64]; 364 LONG rv; 365 366 dwAtrLen = sizeof(pbAtr); 367 rv = SCardStatus(reader[ridx].hCard, NULL, &dwReaderLen, &dwState, &reader[ridx].dwActiveProtocol, pbAtr, &dwAtrLen); 368 if (rv == SCARD_S_SUCCESS && (dwState & (SCARD_PRESENT | SCARD_NEGOTIABLE | SCARD_POWERED ) )) { 369 cs_debug("PCSC card IS inserted in %s card state [dwstate=%lx rv=(%lx)]", reader[ridx].pcsc_name, dwState,rv); 370 //cs_debug("ATR: %s", cs_hexdump(1, (uchar *)pbAtr, dwAtrLen)); 371 return 3; 372 } 373 else { 374 if ( (rv==SCARD_W_RESET_CARD) && (dwState == 0) ) { 375 cs_debug("PCSC check card reinserted in %s [dwstate=%lx rv=(%lx)]", reader[ridx].pcsc_name, dwState, rv ); 376 SCardDisconnect(reader[ridx].hCard,SCARD_LEAVE_CARD); 377 rv = SCardConnect(reader[ridx].hContext, &reader[ridx].pcsc_name, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &reader[ridx].hCard, &reader[ridx].dwActiveProtocol); 378 return ((rv != SCARD_S_SUCCESS) ? 2 : 0); 379 } else if ( rv == SCARD_W_REMOVED_CARD || (dwState | SCARD_ABSENT) ) { 380 cs_debug("PCSC card in %s removed / absent [dwstate=%lx rv=(%lx)]", reader[ridx].pcsc_name, dwState, rv ); 381 } else { 382 cs_debug("PCSC card inserted FAILURE in %s (%lx) card state (%x) (T=%d)", reader[ridx].pcsc_name, rv, dwState, reader[ridx].dwActiveProtocol); 383 } 384 return 0; 385 } 386 } 387 #endif 388 280 389 cta_cmd[0]=CTBCS_CLA; 281 390 cta_cmd[1]=CTBCS_INS_STATUS; … … 289 398 int reader_device_init(char *device, int typ) 290 399 { 400 #ifdef HAVE_PCSC 401 if (reader[ridx].typ == R_PCSC) { 402 LONG rv; 403 DWORD dwReaders; 404 LPSTR mszReaders = NULL; 405 char *ptr, **readers = NULL; 406 int nbReaders; 407 int reader_nb; 408 409 cs_debug("PCSC establish context for PCSC reader %s", device); 410 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &reader[ridx].hContext); 411 if ( rv == SCARD_S_SUCCESS ) { 412 // here we need to list the pcsc readers and get the name from there, 413 // the reader[ridx].device should contain the reader number 414 // and after the actual device name is copied in reader[ridx].pcsc_name . 415 rv = SCardListReaders(reader[ridx].hContext, NULL, NULL, &dwReaders); 416 if( rv != SCARD_S_SUCCESS ) { 417 cs_debug("PCSC failed listing readers [1] : (%lx)", rv); 418 return 0; 419 } 420 mszReaders = malloc(sizeof(char)*dwReaders); 421 if (mszReaders == NULL) { 422 cs_debug("PCSC failed malloc"); 423 return 0; 424 } 425 rv = SCardListReaders(reader[ridx].hContext, NULL, mszReaders, &dwReaders); 426 if( rv != SCARD_S_SUCCESS ) { 427 cs_debug("PCSC failed listing readers [2]: (%lx)", rv); 428 return 0; 429 } 430 /* Extract readers from the null separated string and get the total 431 * number of readers */ 432 nbReaders = 0; 433 ptr = mszReaders; 434 while (*ptr != '\0') { 435 ptr += strlen(ptr)+1; 436 nbReaders++; 437 } 438 439 if (nbReaders == 0) { 440 cs_debug("PCSC : no reader found"); 441 return 0; 442 } 443 444 readers = calloc(nbReaders, sizeof(char *)); 445 if (readers == NULL) { 446 cs_debug("PCSC failed malloc"); 447 return 0; 448 } 449 450 /* fill the readers table */ 451 nbReaders = 0; 452 ptr = mszReaders; 453 while (*ptr != '\0') { 454 cs_debug("%d: %s\n", nbReaders, ptr); 455 readers[nbReaders] = ptr; 456 ptr += strlen(ptr)+1; 457 nbReaders++; 458 } 459 reader_nb=atoi((const char *)&reader[ridx].device); 460 if (reader_nb < 0 || reader_nb >= nbReaders) { 461 cs_debug("Wrong reader index: %d\n", reader_nb); 462 return 0; 463 } 464 snprintf(reader[ridx].pcsc_name,sizeof(reader[ridx].pcsc_name),"%s",readers[reader_nb]); 465 cs_log("PCSC initializing reader (%s)", &reader[ridx].pcsc_name); 466 rv = SCardConnect(reader[ridx].hContext, &reader[ridx].pcsc_name, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &reader[ridx].hCard, &reader[ridx].dwActiveProtocol); 467 cs_debug("PCSC initializing result (%lx) protocol (T=%lx)", rv, reader[ridx].dwActiveProtocol ); 468 469 return ((rv != SCARD_S_SUCCESS) ? 2 : 0); 470 } 471 else { 472 cs_debug("PCSC failed establish context (%lx)", rv); 473 return 0; 474 } 475 } 476 #endif 477 291 478 int rc; 292 479 oscam_card_detect=reader[ridx].detect;
Note:
See TracChangeset
for help on using the changeset viewer.