Changeset 1951 for trunk/reader-dre.c


Ignore:
Timestamp:
Apr 5, 2010, 9:13:48 AM (10 years ago)
Author:
merek
Message:

Merge from UMP r1973-1983

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/reader-dre.c

    r1948 r1951  
    11#include "globals.h"
    22#include "reader-common.h"
    3 
    4 extern uchar cta_res[];
    5 extern ushort cta_lr;
    6 static uchar provider;
    7 static short int mode;
    83
    94#define OK_RESPONSE 0x61
     
    1914}
    2015
    21 static int dre_command (struct s_reader * reader, uchar * cmd, int cmdlen)  //attention: inputcommand will be changed!!!! answer will be in cta_res, length cta_lr ; returning 1 = no error, return ERROR = err
     16static int dre_command (struct s_reader * reader, uchar * cmd, int cmdlen, unsigned char * cta_res, unsigned short * p_cta_lr)  //attention: inputcommand will be changed!!!! answer will be in cta_res, length cta_lr ; returning 1 = no error, return ERROR = err
    2217{
    2318  static uchar startcmd[] = { 0x80, 0xFF, 0x10, 0x01, 0x05 };   //any command starts with this,
     
    4035  command[cmdlen++] = checksum;
    4136
    42   reader_cmd2icc (reader, command, cmdlen);
    43 
    44   if ((cta_lr != 2) || (cta_res[0] != OK_RESPONSE)) {
    45     cs_log ("[dre-reader] unexpected answer from card: %s", cs_hexdump (0, cta_res, cta_lr));
     37  reader_cmd2icc (reader, command, cmdlen, cta_res, p_cta_lr);
     38
     39  if ((*p_cta_lr != 2) || (cta_res[0] != OK_RESPONSE)) {
     40    cs_log ("[dre-reader] unexpected answer from card: %s", cs_hexdump (0, cta_res, *p_cta_lr));
    4641    return ERROR;           //error
    4742  }
    4843
    4944  reqans[4] = cta_res[1];   //adapt length byte
    50   reader_cmd2icc (reader, reqans, 5);
     45  reader_cmd2icc (reader, reqans, 5, cta_res, p_cta_lr);
    5146
    5247  if (cta_res[0] != CMD_BYTE) {
     
    5752    switch (cta_res[3]) {
    5853    case 0xe1:
    59       cs_log ("[dre-reader] checksum error: %s.", cs_hexdump (0, cta_res, cta_lr));
     54      cs_log ("[dre-reader] checksum error: %s.", cs_hexdump (0, cta_res, *p_cta_lr));
    6055      break;
    6156    case 0xe2:
    62       cs_log ("[dre-reader] wrong provider: %s.", cs_hexdump (0, cta_res, cta_lr));
     57      cs_log ("[dre-reader] wrong provider: %s.", cs_hexdump (0, cta_res, *p_cta_lr));
    6358      break;
    6459    case 0xe3:
    65       cs_log ("[dre-reader] illegal command: %s.", cs_hexdump (0, cta_res, cta_lr)); 
     60      cs_log ("[dre-reader] illegal command: %s.", cs_hexdump (0, cta_res, *p_cta_lr)); 
    6661      break;
    6762    case 0xec:
    68       cs_log ("[dre-reader] wrong signature: %s.", cs_hexdump (0, cta_res, cta_lr));
     63      cs_log ("[dre-reader] wrong signature: %s.", cs_hexdump (0, cta_res, *p_cta_lr));
    6964      break;
    7065    default:
    71       cs_debug ("[dre-reader] unknown error: %s.", cs_hexdump (0, cta_res, cta_lr));
     66      cs_debug ("[dre-reader] unknown error: %s.", cs_hexdump (0, cta_res, *p_cta_lr));
    7267      break;
    7368    }
    7469    return ERROR;           //error
    7570  }
    76   int length_excl_leader = cta_lr;
    77   if ((cta_res[cta_lr - 2] == 0x90) && (cta_res[cta_lr - 1] == 0x00))
     71  int length_excl_leader = *p_cta_lr;
     72  if ((cta_res[*p_cta_lr - 2] == 0x90) && (cta_res[*p_cta_lr - 1] == 0x00))
    7873    length_excl_leader -= 2;
    7974
     
    8277  if (cta_res[length_excl_leader - 1] != checksum) {
    8378    cs_log ("[dre-reader] checksum does not match, expected %02x received %02x:%s", checksum,
    84         cta_res[length_excl_leader - 1], cs_hexdump (0, cta_res, cta_lr));
     79        cta_res[length_excl_leader - 1], cs_hexdump (0, cta_res, *p_cta_lr));
    8580    return ERROR;           //error
    8681  }
     
    9085#define dre_cmd(cmd) \
    9186{ \
    92     dre_command(reader, cmd, sizeof(cmd)); \
     87    dre_command(reader, cmd, sizeof(cmd),cta_res,&cta_lr); \
    9388}
    9489
    9590static int dre_set_provider_info (struct s_reader * reader)
    9691{
     92  def_resp;
    9793  int i;
    9894  static uchar cmd59[] = { 0x59, 0x14 };    // subscriptions
    9995  static uchar cmd5b[] = { 0x5b, 0x00, 0x14 };  //validity dates
    10096
    101   cmd59[1] = provider;
     97  cmd59[1] = reader->provider;
    10298  if ((dre_cmd (cmd59))) {  //ask subscription packages, returns error on 0x11 card
    10399    uchar pbm[32];
     
    111107    if (pbm[i] != 0xff) {
    112108      cmd5b[1] = i;
    113       cmd5b[2] = provider;
     109      cmd5b[2] = reader->provider;
    114110      dre_cmd (cmd5b);  //ask for validity dates
    115111
     
    139135{
    140136    get_atr;
     137  def_resp;
    141138  static uchar ua[] = { 0x43, 0x15 };   // get serial number (UA)
    142139  static uchar providers[] = { 0x49, 0x15 };    // get providers
     
    147144    return ERROR;
    148145
    149   provider = atr[6];
     146  reader->provider = atr[6];
    150147  uchar checksum = xor (atr + 1, 6);
    151148
     
    157154    card = "Tricolor Centr";
    158155    reader->caid[0] = 0x4ae0;
    159     mode = 41;
    160156    break;          //59 type card = MSP (74 type = ATMEL)
    161157  case 0x12:
    162158    card = "Cable TV";
    163159    reader->caid[0] = 0x4ae0;   //TODO not sure about this one
    164     mode = 41;          //TODO not sure
    165160    break;
    166161  case 0x14:
    167162    card = "Tricolor Syberia / Platforma HD new";
    168163    reader->caid[0] = 0x4ae1;
    169     mode = 51;
    170164    break;          //59 type card
    171165  case 0x15:
    172166    card = "Platforma HD / DW old";
    173167    reader->caid[0] = 0x4ae1;
    174     mode = 51;
    175168    break;          //59 type card
    176169  default:
    177170    card = "Unknown";
    178171    reader->caid[0] = 0x4ae1;
    179     mode = 51;
    180172    break;
    181173  }
     
    194186
    195187  static uchar cmd54[] = { 0x54, 0x14 };    // geocode
    196   cmd54[1] = provider;
     188  cmd54[1] = reader->provider;
    197189  uchar geocode = 0;
    198190  if ((dre_cmd (cmd54)))    //error would not be fatal, like on 0x11 cards
    199191    geocode = cta_res[3];
    200192
    201   providers[1] = provider;
     193  providers[1] = reader->provider;
    202194  if (!(dre_cmd (providers)))
    203195    return ERROR;           //fatal error
     
    213205  int minor_version = cta_res[4];
    214206
    215   ua[1] = provider;
     207  ua[1] = reader->provider;
    216208  dre_cmd (ua);         //error would not be fatal
    217209
     
    225217  int dre_chksum = 0;
    226218  uchar buf[32];
    227   sprintf ((char *)buf, "%i%i%08i", provider - 16, major_version + 1, low_dre_id);
     219  sprintf ((char *)buf, "%i%i%08i", reader->provider - 16, major_version + 1, low_dre_id);
    228220  for (i = 0; i < 32; i++) {
    229221    if (buf[i] == 0x00)
     
    234226  //cs_ri_log("[dre-reader] type: DRE Crypt, caid: %04X, serial: %llu, card: v%x",
    235227  cs_ri_log (reader, "[dre-reader] type: DRE Crypt, caid: %04X, serial: %s, dre id: %i%i%i%08i, geocode %i, card: %s v%i.%i",
    236       reader->caid[0], cs_hexdump (0, reader->hexserial + 2, 4), dre_chksum, provider - 16,
     228      reader->caid[0], cs_hexdump (0, reader->hexserial + 2, 4), dre_chksum, reader->provider - 16,
    237229      major_version + 1, low_dre_id, geocode, card, major_version, minor_version);
    238230  cs_ri_log (reader, "[dre-reader] Provider name:%s.", provname);
     
    256248int dre_do_ecm (struct s_reader * reader, ECM_REQUEST * er)
    257249{
    258   if (mode == 41) {
     250  def_resp;
     251  if (reader->caid[0] == 0x4ae0) {
    259252    static uchar ecmcmd41[] = { 0x41,
    260253      0x58, 0x1f, 0x00,     //fixed part, dont change
     
    263256      0x3b, 0x59, 0x11      //0x3b = keynumber, can be a value 56 ;; 0x59 number of package = 58+1 - Pay Package ;; 0x11 = provider
    264257    };
    265     ecmcmd41[22] = provider;
     258    ecmcmd41[22] = reader->provider;
    266259    memcpy (ecmcmd41 + 4, er->ecm + 8, 16);
    267260    ecmcmd41[20] = er->ecm[6];  //keynumber
     
    290283    cs_debug ("[dre-reader] unused ECM info front:%s", cs_hexdump (0, er->ecm, 5));
    291284    cs_debug ("[dre-reader] unused ECM info back:%s", cs_hexdump (0, er->ecm + 37, 4));
    292     ecmcmd51[33] = provider;    //no part of sig
     285    ecmcmd51[33] = reader->provider;    //no part of sig
    293286    if ((dre_cmd (ecmcmd51))) { //ecm request
    294287      if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
     
    321314int dre_do_emm (struct s_reader * reader, EMM_PACKET * ep)
    322315{
    323 
     316  def_resp;
    324317  int emm_length = ((ep->emm[1] & 0x0f) << 8) + ep->emm[2];
    325318
     
    327320  ep->type = ep->emm[0];
    328321
    329   if (mode == 51) {
     322  if (reader->caid[0] == 0x4ae1) {
    330323    static uchar emmcmd52[0x3a];
    331324    emmcmd52[0] = 0x52;
     
    336329      if(ep->emm[3]!=reader->sa[0][0])
    337330        return OK; // ignore, wrong address
    338       emmcmd52[0x39] = provider;
     331      emmcmd52[0x39] = reader->provider;
    339332      if ((dre_cmd (emmcmd52)))
    340333                if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
     
    357350                    emmcmd42[49] = ep->emm[i*49 + 41]; //keynr
    358351                    emmcmd42[50] = 0x58 + ep->emm[40]; //package nr
    359                 emmcmd42[51] = provider;
     352                emmcmd42[51] = reader->provider;
    360353                if ((dre_cmd (emmcmd42))) {
    361354                  if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
     
    367360            default:
    368361            memcpy (emmcmd42 + 1, ep->emm + 6, 48);
    369             emmcmd42[51] = provider;
     362            emmcmd42[51] = reader->provider;
    370363            //emmcmd42[50] = ecmcmd42[2]; //TODO package nr could also be fixed 0x58
    371364            emmcmd42[50] = 0x58;
     
    381374              /*memcpy (emmcmd42 + 1, ep->emm + 55, 7);  //FIXME either I cant count or my EMM log contains errors
    382375                 memcpy (emmcmd42 + 8, ep->emm + 67, 41); */
    383               emmcmd42[51] = provider;
     376              emmcmd42[51] = reader->provider;
    384377              //emmcmd42[50] = ecmcmd42[2]; //TODO package nr could also be fixed 0x58
    385378              emmcmd42[50] = 0x58;
Note: See TracChangeset for help on using the changeset viewer.