Changeset 1197
- Timestamp:
- 01/12/10 20:18:00 (13 years ago)
- Location:
- branches/smartreader
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/smartreader/CMakeLists.txt
r1186 r1197 140 140 check_include_file ("usb.h" HAVE_LIBUSB) 141 141 if (HAVE_LIBUSB) 142 message(STATUS " libusb found. Adding smartreader support ") 142 143 add_definitions ("-DHAVE_LIBUSB") 143 144 elseif (HAVE_USB) … … 225 226 include_directories( SYSTEM ${USB_INCLUDE}) 226 227 set (HAVE_LIBUSB "1") 228 add_definitions ("-DHAVE_LIBUSB") 229 message (STATUS "OS X libusb found .. adding smartreader support") 227 230 endif ( ${USB_INCLUDE} MATCHES "USB_INCLUDE-NOTFOUND" ) 228 231 elseif (OSCamOperatingSystem MATCHES "Tuxbox") … … 362 365 message (STATUS " use system pcsc functions") 363 366 endif (HAVE_PCSC) 367 if (HAVE_LIBUSB) 368 message (STATUS " use system libusb functions") 369 endif (HAVE_LIBUSB) 364 370 message (STATUS "") -
branches/smartreader/csctapi/atr.c
r1144 r1197 153 153 atr->ib[pn][ATR_INTERFACE_BYTE_TD].present = TRUE; 154 154 (atr->TCK).present = ((TDi & 0x0F) != ATR_PROTOCOL_TYPE_T0); 155 if ((TDi & 0xF0) == 0) //last TDi byte156 break;157 155 if (pn >= ATR_MAX_PROTOCOLS) 158 156 return (ATR_MALFORMED); … … 284 282 atr->ib[pn][ATR_INTERFACE_BYTE_TD].present = TRUE; 285 283 (atr->TCK).present = ((TDi & 0x0F) != ATR_PROTOCOL_TYPE_T0); 286 if ((TDi & 0xF0) == 0) //last TDi byte287 break;288 284 if (pn >= ATR_MAX_PROTOCOLS) 289 285 return (ATR_MALFORMED); -
branches/smartreader/csctapi/ifd_towitoko.c
r1186 r1197 620 620 if(n==0) 621 621 return IFD_TOWITOKO_IO_ERROR; 622 #endif 622 623 if ((buf[0] !=0x3B) && (buf[0] != 0x3F)) //irdeto S02 reports FD as first byte ?!? 624 buf[0] = 0x3B; 623 625 624 #ifdef SCI_DEV625 626 (*atr) = ATR_New (); 626 627 if(ATR_InitFromArray ((*atr), buf, n) == ATR_OK) … … 630 631 req_ts.tv_nsec = 50000000; 631 632 nanosleep (&req_ts, NULL); 632 #ifdef SCI_DEV633 633 if (ioctl(ifd->io->fd, IOCTL_SET_ATR_READY)<0) 634 634 return IFD_TOWITOKO_IO_ERROR; 635 #endif636 635 return IFD_TOWITOKO_OK; 637 636 } -
branches/smartreader/csctapi/pps.c
r1186 r1197 138 138 if ((*length) <= 0 || !PPS_success) // If not by command, or PPS Exchange by command failed: Try PPS Exchange by ATR or Get parameters from ATR 139 139 { 140 int numprot = atr->pn ;//number of protocol lines in ATR140 int numprot = atr->pn-1;//number of protocol lines in ATR 141 141 BYTE tx; 142 cs_debug("ATR reports smartcard supports %i protocols:",numprot);142 cs_debug("ATR reports %i protocol lines:",numprot); 143 143 int i,point; 144 144 char txt[50]; … … 147 147 OffersT[i] = FALSE; 148 148 for (i=1; i<= numprot; i++) { 149 sprintf(txt,"Protocol %01i: ",i); 150 point = 12; 149 point = 0; 151 150 if (ATR_GetInterfaceByte (atr, i, ATR_INTERFACE_BYTE_TA, &tx) == ATR_OK) { 152 151 sprintf((char *)txt+point,"TA%i=%02X ",i,tx); … … 211 210 else { //negotiable mode 212 211 213 bool NeedsPTS = ((pps->parameters.t != 14) && (numprottype > 1 || (atr->ib[0][ATR_INTERFACE_BYTE_TA].present == TRUE && atr->ib[0][ATR_INTERFACE_BYTE_TA].value != 0x11) || pps->parameters.n == 255)); //needs PTS according to ISO 7816 , SCI gets stuck on our PTS 214 if (NeedsPTS) { 215 // PTSS PTS0 PTS1 PTS2 PTS3 PCK 216 // PTSS PTS0 PTS1 PCK 217 BYTE req[] = { 0xFF, 0x10, 0x00, 0x00 }; //we currently do not support PTS2, standard guardtimes 218 219 int p; 220 for (p=1; p<=numprot; p++) { 221 ATR_GetProtocolType(atr,p,&(pps->parameters.t)); 212 bool NeedsPTS = ((pps->parameters.t != 14) && (numprottype > 1 || (atr->ib[0][ATR_INTERFACE_BYTE_TA].present == TRUE && atr->ib[0][ATR_INTERFACE_BYTE_TA].value != 0x11) || pps->parameters.n == 255)); //needs PTS according to ISO 7816 , SCI gets stuck on our PTS 213 if (NeedsPTS) { 214 // PTSS PTS0 PTS1 PTS2 PTS3 PCK 215 // PTSS PTS0 PTS1 PCK 216 BYTE req[] = { 0xFF, 0x10, 0x00, 0x00 }; //we currently do not support PTS2, standard guardtimes 222 217 req[1]=0x10 | pps->parameters.t; //PTS0 always flags PTS1 to be sent always 223 if (ATR_GetInterfaceByte (atr, p, ATR_INTERFACE_BYTE_TA, &req[2]) != ATR_OK) //PTS1218 if (ATR_GetInterfaceByte (atr, 1, ATR_INTERFACE_BYTE_TA, &req[2]) != ATR_OK) //PTS1 224 219 req[2] = 0x11; //defaults FI and DI to 1 225 220 //req[3]=PPS_GetPCK(req,sizeof(req)-1); will be set by PPS_Exchange … … 231 226 pps->parameters.d = (double) (atr_d_table[DI]); 232 227 PPS_success = TRUE; 233 protocol_selected = p; 234 cs_debug("PTS Succesfull, selected protocol %i: T%i, F=%.0f, D=%.6f, N=%.0f\n", protocol_selected, pps->parameters.t, (double) atr_f_table[pps->parameters.FI], pps->parameters.d, pps->parameters.n); 235 break; 228 cs_debug("PTS Succesfull, selected protocol: T%i, F=%.0f, D=%.6f, N=%.0f\n", pps->parameters.t, (double) atr_f_table[pps->parameters.FI], pps->parameters.d, pps->parameters.n); 236 229 } 237 230 else 238 cs_ddump(req,4,"PTS Failure for protocol %i, response:",p); 239 } 240 } 241 242 //FIXME Currently InitICC sets baudrate to 9600 for all T14 cards (=no switching); 243 //When for SCI, T14 protocol, TA1 is obeyed, this goes OK for mosts devices, but somehow on DM7025 Sky S02 card goes wrong when setting ETU (ok on DM800/DM8000) 244 if (!PPS_success) {//last PPS not succesfull 245 BYTE TA1; 246 if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) { 247 pps->parameters.FI = TA1 >> 4; 248 ATR_GetParameter (atr, ATR_PARAMETER_D, &(pps->parameters.d)); 249 } 250 else { //do not obey TA1 251 pps->parameters.FI = ATR_DEFAULT_FI; 252 pps->parameters.d = ATR_DEFAULT_D; 253 } 254 ATR_GetProtocolType (atr, 1, &(pps->parameters.t)); 255 protocol_selected = 1; 256 257 if (NeedsPTS) { 258 if ((pps->parameters.d == 32) || (pps->parameters.d == 12) || (pps->parameters.d == 20)) 259 pps->parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this 260 } 261 /////Here all non-ISO behaviour 262 /////End all non-ISO behaviour 263 264 cs_debug("No PTS %s, selected protocol 1: T%i, F=%.0f, D=%.6f, N=%.0f\n", NeedsPTS?"happened":"needed", pps->parameters.t, (double) atr_f_table[pps->parameters.FI], pps->parameters.d, pps->parameters.n); 265 } 231 cs_ddump(req,4,"PTS Failure, response:"); 232 } 233 234 //FIXME Currently InitICC sets baudrate to 9600 for all T14 cards (=no switching); 235 //When for SCI, T14 protocol, TA1 is obeyed, this goes OK for mosts devices, but somehow on DM7025 Sky S02 card goes wrong when setting ETU (ok on DM800/DM8000) 236 if (!PPS_success) {//last PPS not succesfull 237 BYTE TA1; 238 if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) { 239 pps->parameters.FI = TA1 >> 4; 240 ATR_GetParameter (atr, ATR_PARAMETER_D, &(pps->parameters.d)); 241 } 242 else { //do not obey TA1 243 pps->parameters.FI = ATR_DEFAULT_FI; 244 pps->parameters.d = ATR_DEFAULT_D; 245 } 246 ATR_GetProtocolType (atr, 1, &(pps->parameters.t)); 247 protocol_selected = 1; 248 249 if (NeedsPTS) { 250 if ((pps->parameters.d == 32) || (pps->parameters.d == 12) || (pps->parameters.d == 20)) 251 pps->parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this 252 } 253 /////Here all non-ISO behaviour 254 /////End all non-ISO behaviour 255 256 cs_debug("No PTS %s, selected protocol T%i, F=%.0f, D=%.6f, N=%.0f\n", NeedsPTS?"happened":"needed", pps->parameters.t, (double) atr_f_table[pps->parameters.FI], pps->parameters.d, pps->parameters.n); 257 } 266 258 }//end negotiable mode 267 259 }//end length<0 … … 468 460 469 461 } 470 else471 462 #elif COOL 472 463 if(pps->icc->ifd->io->com==RTYP_SCI) { … … 479 470 return PPS_OK; 480 471 } 481 else482 472 #endif 483 473 { -
branches/smartreader/globals.h
r1186 r1197 387 387 ulong boxid; 388 388 uchar nagra_boxkey[16]; //n3 boxkey 8byte or tiger idea key 16byte 389 int nagra_native;389 int has_rsa; 390 390 uchar aes_key[16]; 391 391 uchar rsa_mod[120]; //rsa modulus for nagra cards. -
branches/smartreader/oscam-config.c
r1186 r1197 1131 1131 return; 1132 1132 } 1133 if ( !strcmp(token, "n3_rsakey"))1134 { 1135 rdr-> nagra_native=1;1133 if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey")) ) 1134 { 1135 rdr->has_rsa=1; 1136 1136 if (key_atob_l(value, rdr->rsa_mod, 128)) 1137 1137 { … … 1143 1143 if (!strcmp(token, "tiger_rsakey")) 1144 1144 { 1145 rdr->nagra_native=1;1146 1145 if (key_atob_l(value, rdr->rsa_mod, 240)) 1147 1146 { … … 1151 1150 return; 1152 1151 } 1153 if ( !strcmp(token, "n3_boxkey"))1152 if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey"))) 1154 1153 { 1155 1154 if (key_atob_l(value, rdr->nagra_boxkey, 16)) -
branches/smartreader/reader-nagra.c
r1186 r1197 192 192 unsigned char d2_data[88]; 193 193 unsigned char sign1[8]; 194 unsigned char sessi1[8]; 195 unsigned char sessi2[8]; 194 unsigned char sk[16]; 196 195 unsigned char tmp[104]; 197 unsigned char tmp1[8];198 196 unsigned char idea_sig[16]; 199 unsigned char random[88] = {0x51,0xd0,0xcc,0x4a,0x51,0xbc,0x4f,0xa4,0x7d,0x44,0xa9,0xa8,0x97,0x13,0x01,0x63, 200 0x8f,0xaf,0x86,0x60,0x7c,0xe3,0xee,0x29,0xca,0x13,0x09,0x44,0x83,0x48,0x17,0x8b, 201 0x88,0xa6,0x64,0x20,0x22,0x2b,0x04,0x50,0xd8,0x15,0x9c,0x50,0x09,0x7c,0x6a,0x5d, 202 0xa0,0xb3,0xb0,0x11,0xa2,0x15,0x00,0x58,0xae,0x4b,0xe7,0xb0,0x06,0xa0,0x1d,0xe0, 203 0x53,0x58,0x6a,0xf0,0x60,0x51,0x71,0xdb,0xe7,0x7c,0xf7,0x1b,0x37,0x9d,0x20,0xf8, 204 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 197 unsigned char random[88]; 205 198 206 199 if(!do_cmd(0xd1,0x02,0x51,0xd2,NULL)) … … 264 257 reader[ridx].prid[0][3]=parte_variable[74]; 265 258 reader[ridx].caid[0] =(SYSTEM_NAGRA|parte_variable[76]); 266 memcpy(sessi1,&parte_variable[79],8); 259 memcpy(sk,&parte_variable[79],8); 260 memcpy(sk+8,&parte_variable[79],8); 267 261 cs_ri_log("[nagra-reader] CAID: %04X, IRD ID: %s",reader[ridx].caid[0], cs_hexdump (1,irdId,4)); 268 262 cs_ri_log("[nagra-reader] ProviderID: %s",cs_hexdump (1,reader[ridx].prid[0],4)); 269 270 memcpy(sessi2,&random[72], 8); 271 memset(tmp1,0,8); 272 memcpy(tmp1, random+72,8); 273 ReverseMem(tmp1, 8); //byteflop last 8 bytes of random data 274 memcpy(random+72, tmp1,8); // insert back the byteflop data 275 276 memset(tmp1,0,8); 277 memcpy(tmp1, sessi1,8); 278 ReverseMem(tmp1, 8); // byteflop sessi1 one from rsa variabled part 279 memcpy(random+80,tmp1,8); // and attach him to random data 263 264 memcpy(random, sk,16); 265 ReverseMem(random, 88); 280 266 281 267 … … 302 288 if (cta_res[2] == 0x00) 303 289 { 304 memcpy(sessi,s essi1,8); memcpy(sessi+8,sessi2,8);290 memcpy(sessi,sk,16); 305 291 IDEA_KEY_SCHEDULE ks; 306 292 idea_set_encrypt_key(sessi,&ks); … … 608 594 { 609 595 cs_ri_log("[nagra-reader] detect Irdeto tunneled nagra card"); 610 if(!reader[ridx]. nagra_native) return 0;596 if(!reader[ridx].has_rsa) return 0; 611 597 cs_ri_log("[nagra-reader] using nagra mode"); 612 598 is_pure_nagra=1;
Note:
See TracChangeset
for help on using the changeset viewer.