Changeset 1197


Ignore:
Timestamp:
01/12/10 20:18:00 (12 years ago)
Author:
rorothetroll
Message:

resync with trunk and fix some missing -D for the cflags on OS X to compile libftdi

Location:
branches/smartreader
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/smartreader/CMakeLists.txt

    r1186 r1197  
    140140check_include_file ("usb.h" HAVE_LIBUSB)
    141141if (HAVE_LIBUSB)
     142    message(STATUS "  libusb found. Adding smartreader support ")
    142143    add_definitions ("-DHAVE_LIBUSB")
    143144elseif (HAVE_USB)
     
    225226        include_directories( SYSTEM ${USB_INCLUDE})
    226227        set (HAVE_LIBUSB "1")
     228        add_definitions ("-DHAVE_LIBUSB")
     229        message (STATUS "OS X libusb found .. adding smartreader support")
    227230    endif ( ${USB_INCLUDE} MATCHES "USB_INCLUDE-NOTFOUND" )
    228231elseif (OSCamOperatingSystem MATCHES "Tuxbox")
     
    362365    message (STATUS "  use system pcsc functions")
    363366endif (HAVE_PCSC)
     367if (HAVE_LIBUSB)
     368    message (STATUS "  use system libusb functions")
     369endif (HAVE_LIBUSB)
    364370message (STATUS "")
  • branches/smartreader/csctapi/atr.c

    r1144 r1197  
    153153            atr->ib[pn][ATR_INTERFACE_BYTE_TD].present = TRUE;
    154154            (atr->TCK).present = ((TDi & 0x0F) != ATR_PROTOCOL_TYPE_T0);
    155             if ((TDi & 0xF0)  == 0) //last TDi byte
    156                 break;
    157155            if (pn >= ATR_MAX_PROTOCOLS)
    158156                return (ATR_MALFORMED);
     
    284282            atr->ib[pn][ATR_INTERFACE_BYTE_TD].present = TRUE;
    285283            (atr->TCK).present = ((TDi & 0x0F) != ATR_PROTOCOL_TYPE_T0);
    286             if ((TDi & 0xF0)  == 0) //last TDi byte
    287                 break;
    288284            if (pn >= ATR_MAX_PROTOCOLS)
    289285                return (ATR_MALFORMED);
  • branches/smartreader/csctapi/ifd_towitoko.c

    r1186 r1197  
    620620        if(n==0)
    621621            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;
    623625           
    624 #ifdef SCI_DEV
    625626        (*atr) = ATR_New ();
    626627        if(ATR_InitFromArray ((*atr), buf, n) == ATR_OK)
     
    630631            req_ts.tv_nsec = 50000000;
    631632            nanosleep (&req_ts, NULL);
    632 #ifdef SCI_DEV
    633633            if (ioctl(ifd->io->fd, IOCTL_SET_ATR_READY)<0)
    634634                return IFD_TOWITOKO_IO_ERROR;
    635 #endif
    636635            return IFD_TOWITOKO_OK;
    637636        }
  • branches/smartreader/csctapi/pps.c

    r1186 r1197  
    138138    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
    139139    {
    140         int numprot = atr->pn;//number of protocol lines in ATR
     140        int numprot = atr->pn-1;//number of protocol lines in ATR
    141141        BYTE tx;
    142       cs_debug("ATR reports smartcard supports %i protocols:",numprot);
     142      cs_debug("ATR reports %i protocol lines:",numprot);
    143143        int i,point;
    144144        char txt[50];
     
    147147            OffersT[i] = FALSE;
    148148        for (i=1; i<= numprot; i++) {
    149             sprintf(txt,"Protocol %01i:  ",i);
    150             point = 12;
     149            point = 0;
    151150            if (ATR_GetInterfaceByte (atr, i, ATR_INTERFACE_BYTE_TA, &tx) == ATR_OK) {
    152151              sprintf((char *)txt+point,"TA%i=%02X ",i,tx);
     
    211210        else { //negotiable mode
    212211
    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
    222217                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)  //PTS1
     218                if (ATR_GetInterfaceByte (atr, 1, ATR_INTERFACE_BYTE_TA, &req[2]) != ATR_OK)  //PTS1
    224219                    req[2] = 0x11; //defaults FI and DI to 1
    225220            //req[3]=PPS_GetPCK(req,sizeof(req)-1); will be set by PPS_Exchange
     
    231226                    pps->parameters.d = (double) (atr_d_table[DI]);
    232227                    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);
    236229                }
    237230                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            }
    266258        }//end negotiable mode
    267259    }//end length<0
     
    468460       
    469461    }
    470     else
    471462#elif COOL
    472463    if(pps->icc->ifd->io->com==RTYP_SCI) {
     
    479470        return PPS_OK;
    480471    }
    481     else
    482472#endif
    483473    {
  • branches/smartreader/globals.h

    r1186 r1197  
    387387  ulong     boxid;
    388388  uchar     nagra_boxkey[16]; //n3 boxkey 8byte  or tiger idea key 16byte
    389   int       nagra_native;
     389  int       has_rsa;
    390390  uchar     aes_key[16];
    391391  uchar     rsa_mod[120]; //rsa modulus for nagra cards.
  • branches/smartreader/oscam-config.c

    r1186 r1197  
    11311131    return;
    11321132  }
    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;
    11361136    if (key_atob_l(value, rdr->rsa_mod, 128))
    11371137    {
     
    11431143  if (!strcmp(token, "tiger_rsakey"))
    11441144  {
    1145     rdr->nagra_native=1;
    11461145    if (key_atob_l(value, rdr->rsa_mod, 240))
    11471146    {
     
    11511150    return;
    11521151  }
    1153   if (!strcmp(token, "n3_boxkey"))
     1152  if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey")))
    11541153  {
    11551154    if (key_atob_l(value, rdr->nagra_boxkey, 16))
  • branches/smartreader/reader-nagra.c

    r1186 r1197  
    192192    unsigned char d2_data[88];
    193193    unsigned char sign1[8];
    194     unsigned char sessi1[8];
    195     unsigned char sessi2[8];
     194    unsigned char sk[16];
    196195    unsigned char tmp[104];
    197     unsigned char tmp1[8];
    198196    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];
    205198                     
    206199    if(!do_cmd(0xd1,0x02,0x51,0xd2,NULL))
     
    264257    reader[ridx].prid[0][3]=parte_variable[74];
    265258    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);
    267261        cs_ri_log("[nagra-reader] CAID: %04X, IRD ID: %s",reader[ridx].caid[0], cs_hexdump (1,irdId,4));
    268262        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);
    280266   
    281267   
     
    302288    if (cta_res[2] == 0x00)
    303289    {
    304         memcpy(sessi,sessi1,8); memcpy(sessi+8,sessi2,8);
     290        memcpy(sessi,sk,16);
    305291        IDEA_KEY_SCHEDULE ks;
    306292        idea_set_encrypt_key(sessi,&ks);
     
    608594    {
    609595        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;
    611597        cs_ri_log("[nagra-reader] using nagra mode");
    612598        is_pure_nagra=1;
Note: See TracChangeset for help on using the changeset viewer.