Changeset 3870


Ignore:
Timestamp:
11/10/10 20:13:23 (13 years ago)
Author:
rorothetroll
Message:

reader-viaccess.c : improvment on long ECM parsing and making sure we only send the right ECM to the card. NOT TESTED !!!!. I tested on a card with normal ECM and it still works. I need someone to test this on a card with long ECM in debug mode.
csctapi/ifd_pcsc.c : improve debug messages.
globals.h : added number_ecm for long ecm processing in viaccess.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/csctapi/ifd_pcsc.c

    r3855 r3870  
    110110        //The pbRecvBuffer will receive the SW1 and SW2 status codes from the operation.
    111111        //The pcbRecvLength should be at least two and will be set to two upon return.
    112         cs_debug("command = %02X %02X %02X %02X %02X", buf[0],buf[1],buf[2],buf[3],buf[4]);
    113112        if(buf[4])
    114113            dwSendLength = l;
    115114        else
    116115            dwSendLength = l-1;
    117         cs_debug("sending %d bytes to PCSC", dwSendLength);
     116        cs_debug("sending %d bytes to PCSC : %s", dwSendLength,cs_hexdump(1,buf,l));
    118117        rv = SCardTransmit((SCARDHANDLE)(pcsc_reader->hCard), SCARD_PCI_T0, (LPCBYTE) buf, dwSendLength, &pioRecvPci, (LPBYTE) cta_res, (LPDWORD) &dwRecvLength);
    119118        *cta_lr=dwRecvLength;
     
    121120    else  if(pcsc_reader->dwActiveProtocol == SCARD_PROTOCOL_T1) {
    122121        dwSendLength = l;
    123         cs_debug("sending %d bytes to PCSC", dwSendLength);
     122        cs_debug("sending %d bytes to PCSC : %s", dwSendLength,cs_hexdump(1,buf,l));
    124123        rv = SCardTransmit((SCARDHANDLE)(pcsc_reader->hCard), SCARD_PCI_T1, (LPCBYTE) buf, dwSendLength, &pioRecvPci, (LPBYTE) cta_res, (LPDWORD) &dwRecvLength);
    125124        *cta_lr=dwRecvLength;
     
    130129    }
    131130
    132      cs_debug("received %d bytes from PCSC with rv=%lx", *cta_lr, rv);
     131     cs_debug("received %d bytes from PCSC with rv=%lx : %s", *cta_lr, rv,cs_hexdump(1,cta_res,*cta_lr));
     132
    133133     cs_debug("PCSC doapi (%lx ) (T=%d), %d", rv, ( pcsc_reader->dwActiveProtocol == SCARD_PROTOCOL_T0 ? 0 :  1), *cta_lr );
    134134
  • trunk/globals.h

    r3844 r3870  
    710710    uchar geo[256];
    711711    uchar geo_len;
     712    int number_ecm;
    712713};
    713714// for videoguard in s_reader
  • trunk/module-monitor.c

    r3848 r3870  
    277277            sprintf(ltime, "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
    278278                        sprintf(sbuf, "[%c--CCC]%8lX|%c|%d|%s|%d|%d|%s|%d|%s|%s|%s|%d|%04X:%04X|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d\n",
    279                     id, cl->thread, cl->typ, cnr, usr, cau, cl->crypted,
     279                    id, (unsigned long)cl->thread, cl->typ, cnr, usr, cau, cl->crypted,
    280280                    cs_inet_ntoa(cl->ip), cl->port, monitor_get_proto(cl),
    281281                    ldate, ltime, lsec, cl->last_caid, cl->last_srvid,
  • trunk/reader-viaccess.c

    r3828 r3870  
    162162static int viaccess_card_init(struct s_reader * reader, ATR newatr)
    163163{
    164   get_atr;
    165   def_resp;
    166   int i;
    167   uchar buf[256];
    168   uchar insac[] = { 0xca, 0xac, 0x00, 0x00, 0x00 }; // select data
    169   uchar insb8[] = { 0xca, 0xb8, 0x00, 0x00, 0x00 }; // read selected data
    170   uchar insa4[] = { 0xca, 0xa4, 0x00, 0x00, 0x00 }; // select issuer
    171   uchar insc0[] = { 0xca, 0xc0, 0x00, 0x00, 0x00 }; // read data item
    172 
    173   static const uchar insFAC[] = { 0x87, 0x02, 0x00, 0x00, 0x03 }; // init FAC
    174   static const uchar FacDat[] = { 0x00, 0x00, 0x28 };
     164    get_atr;
     165    def_resp;
     166    int i;
     167    uchar buf[256];
     168    uchar insac[] = { 0xca, 0xac, 0x00, 0x00, 0x00 }; // select data
     169    uchar insb8[] = { 0xca, 0xb8, 0x00, 0x00, 0x00 }; // read selected data
     170    uchar insa4[] = { 0xca, 0xa4, 0x00, 0x00, 0x00 }; // select issuer
     171    uchar insc0[] = { 0xca, 0xc0, 0x00, 0x00, 0x00 }; // read data item
     172    static const uchar insFAC[] = { 0x87, 0x02, 0x00, 0x00, 0x03 }; // init FAC
     173    static const uchar FacDat[] = { 0x00, 0x00, 0x28 };
     174    static unsigned char ins8702_data[] = { 0x00, 0x00, 0x11};
     175    static unsigned char ins8704[] = { 0x87, 0x04, 0x00, 0x00, 0x07 };
     176    static unsigned char ins8706[] = { 0x87, 0x06, 0x00, 0x00, 0x04 };
     177
    175178
    176179  if ((atr[0]!=0x3f) || (atr[1]!=0x77) || ((atr[2]!=0x18) && (atr[2]!=0x11) && (atr[2]!=0x19)) || (atr[9]!=0x68)) return ERROR;
     
    230233  cs_ri_log(reader, "providers: %d (%s)", reader->nprov, buf+1);
    231234
    232   /* init the maybe existing aes key */
    233   aes_set_key((char *)reader->aes_key);
    234 
    235   if (cfg->ulparent)
    236     unlock_parental(reader);
    237 
    238   cs_log("[viaccess-reader] ready for requests");
    239   memset(&reader->last_geo, 0, sizeof(reader->last_geo));
    240   return OK;
     235    /* init the maybe existing aes key */
     236    aes_set_key((char *)reader->aes_key);
     237   
     238    if (cfg->ulparent)
     239        unlock_parental(reader);
     240
     241    if(card_write(reader, insFAC, ins8702_data, cta_res, &cta_lr) &&
     242        card_write(reader, ins8704, NULL, cta_res, &cta_lr) &&
     243        card_write(reader, ins8706, NULL, cta_res, &cta_lr) &&
     244        (cta_res[cta_lr-2]==0x90) && (cta_res[cta_lr-1]==0x00)) {
     245        reader->last_geo.number_ecm =(cta_res[2]<<8) | (cta_res[3]);
     246        cs_log("using ecm #%04x for long viaccess ecm",reader->last_geo.number_ecm);
     247    }
     248    else
     249        reader->last_geo.number_ecm = 0;
     250
     251    cs_log("[viaccess-reader] ready for requests");
     252    memset(&reader->last_geo, 0, sizeof(reader->last_geo));
     253    return OK;
    241254}
    242255
     
    275288  uchar DE04[256];
    276289  int D2KeyID=0;
     290  int curnumber_ecm=0;
     291
    277292  memset(DE04, 0, sizeof(DE04)); //fix dorcel de04 bug
    278293
     
    312327        hasD2 = 0;
    313328
     329
    314330    // 40 07 03 0b 00  -> nano 40, len =7  ident 030B00 (tntsat), key #0  <== we're pointing here
    315331    // 09 -> use key #9
     
    323339
    324340        nanoLen=ecm88Data[1] + 2;
     341        curnumber_ecm =(ecm88Data[6]<<8) | (ecm88Data[7]);
     342        keynr=ecm88Data[4]&0x0F;       
     343
     344        // 40 07 03 0b 00  -> nano 40, len =7  ident 030B00 (tntsat), key #0  <== we're pointing here
     345        // 09 -> use key #9
     346        if(nanoLen>5) {
     347            if( reader->last_geo.number_ecm > 0 && reader->last_geo.number_ecm ==curnumber_ecm ) {
     348   
     349                keyToUse=ecm88Data[5];
     350                keynr=keyToUse;
     351                cs_debug("keyToUse = %d",keyToUse);
     352            }
     353            else
     354            {
     355                ecm88Data=nextEcm;
     356                ecm88Len-=curEcm88len;
     357                continue; //loop to next ecm
     358            }
    325359       
     360        }
     361
    326362        memcpy (ident, &ecm88Data[2], sizeof(ident));
    327363        provid = b2i(3, ident);
     
    335371        }
    336372
    337         keynr=ecm88Data[4]&0x0F;
    338         // 40 07 03 0b 00  -> nano 40, len =7  ident 030B00 (tntsat), key #0  <== we're pointing here
    339         // 09 -> use key #9
    340         if(nanoLen>5) {
    341             keyToUse=ecm88Data[5];
    342             keynr=keyToUse;
    343             cs_debug("keyToUse = %d",keyToUse);
    344         }
    345373
    346374        if (!chk_prov(reader, ident, keynr))
Note: See TracChangeset for help on using the changeset viewer.