Changeset 1193


Ignore:
Timestamp:
01/12/10 17:00:36 (12 years ago)
Author:
dingo35
Message:

Fix some ATR issues on Dreambox, especially irdeto S02 card

Location:
trunk/csctapi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/csctapi/atr.c

    r1137 r1193  
    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);
  • trunk/csctapi/ifd_towitoko.c

    r1182 r1193  
    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        }
  • trunk/csctapi/pps.c

    r1183 r1193  
    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    {
Note: See TracChangeset for help on using the changeset viewer.