Changeset 1389 for trunk/reader-dre.c


Ignore:
Timestamp:
Jan 31, 2010, 7:48:55 PM (10 years ago)
Author:
landlord
Message:

Backport from ump trunk 1520

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/reader-dre.c

    r1125 r1389  
    11#include "globals.h"
    22#include "reader-common.h"
    3 //#include <stdlib.h>
    4 
    5 extern uchar cta_cmd[], cta_res[];
     3
     4extern uchar cta_res[];
    65extern ushort cta_lr;
    7 unsigned long long serial;
    8 char *card;
    96static uchar provider;
    107static short int mode;
     
    1310#define CMD_BYTE 0x59
    1411
    15 uchar xor (uchar * cmd, int cmdlen)
     12static uchar xor (uchar * cmd, int cmdlen)
    1613{
    1714  int i;
     
    2219}
    2320
    24 int dre_command (uchar * cmd, int cmdlen)   //attention: inputcommand will be changed!!!! answer will be in cta_res, length cta_lr ; returning 1 = no error, return 0 = err
     21static int dre_command (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
    2522{
    2623  static uchar startcmd[] = { 0x80, 0xFF, 0x10, 0x01, 0x05 };   //any command starts with this,
     
    4744  if ((cta_lr != 2) || (cta_res[0] != OK_RESPONSE)) {
    4845    cs_log ("DRECRYPT ERROR: unexpected answer from card: %s", cs_hexdump (0, cta_res, cta_lr));
    49     return 0;           //error
     46    return ERROR;           //error
    5047  }
    5148
     
    5552  if (cta_res[0] != CMD_BYTE) {
    5653    cs_log ("DRECRYPT Unknown response: cta_res[0] expected to be %02x, is %02x", CMD_BYTE, cta_res[0]);
    57     return 0;
     54    return ERROR;
    5855  }
    5956  if ((cta_res[1] == 0x03) && (cta_res[2] == 0xe2)) {
     
    7572      break;
    7673    }
    77     return 0;           //error
     74    return ERROR;           //error
    7875  }
    7976  int length_excl_leader = cta_lr;
     
    8683    cs_log ("DRECRYPT checksum does not match, expected %02x received %02x:%s", checksum,
    8784        cta_res[length_excl_leader - 1], cs_hexdump (0, cta_res, cta_lr));
    88     return 0;           //error
    89   }
    90   return 1;
     85    return ERROR;           //error
     86  }
     87  return OK;
    9188}
    9289
     
    9693}
    9794
    98 int dre_set_provider_info (void)
     95static int dre_set_provider_info (void)
    9996{
    10097  int i;
     
    136133    }
    137134  }
    138   return 1;
    139 }
    140 
    141 int dre_card_init (uchar * atr)
    142 {
     135  return OK;
     136}
     137
     138int dre_card_init (ATR newatr)
     139{
     140    get_atr;
    143141  static uchar ua[] = { 0x43, 0x15 };   // get serial number (UA)
    144142  static uchar providers[] = { 0x49, 0x15 };    // get providers
    145143  int i;
     144    char *card;
    146145
    147146  if ((atr[0] != 0x3b) || (atr[1] != 0x15) || (atr[2] != 0x11) || (atr[3] != 0x12 || atr[4] != 0xca || atr[5] != 0x07))
    148     return (0);
     147    return ERROR;
    149148
    150149  provider = atr[6];
     
    202201  providers[1] = provider;
    203202  if (!(dre_cmd (providers)))
    204     return 0;           //fatal error
     203    return ERROR;           //fatal error
    205204  if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    206     return 0;
     205    return ERROR;
    207206  uchar provname[128];
    208207  for (i = 0; ((i < cta_res[2] - 6) && (i < 128)); i++) {
     
    249248
    250249  if (!dre_set_provider_info ())
    251     return 0;           //fatal error
     250    return ERROR;           //fatal error
    252251
    253252  cs_log ("ready for requests");
    254   return (1);
     253  return OK;
    255254}
    256255
     
    272271    if ((dre_cmd (ecmcmd41))) { //ecm request
    273272      if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    274                 return 0;       //exit if response is not 90 00
     273                return ERROR;       //exit if response is not 90 00
    275274      memcpy (er->cw, cta_res + 11, 8);
    276275      memcpy (er->cw + 8, cta_res + 3, 8);
    277276
    278       return 1;
     277      return OK;
    279278    }
    280279  }
     
    294293    if ((dre_cmd (ecmcmd51))) { //ecm request
    295294      if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    296                 return 0;       //exit if response is not 90 00
     295                return ERROR;       //exit if response is not 90 00
    297296      memcpy (er->cw, cta_res + 11, 8);
    298297      memcpy (er->cw + 8, cta_res + 3, 8);
    299       return 1;
     298      return OK;
    300299    }
    301300  }
    302   return 0;
     301  return ERROR;
    303302}
    304303
     
    319318      // check for shared address
    320319      if(ep->emm[3]!=reader[ridx].sa[0][0])
    321         return 1; // ignore, wrong address
     320        return OK; // ignore, wrong address
    322321      emmcmd52[0x39] = provider;
    323322      if ((dre_cmd (emmcmd52)))
    324323                if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    325                 return 0;       //exit if response is not 90 00
     324                return ERROR;       //exit if response is not 90 00
    326325        }
    327326  }
     
    344343                if ((dre_cmd (emmcmd42))) {
    345344                  if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    346                             return 0;       //exit if response is not 90 00
     345                            return ERROR;       //exit if response is not 90 00
    347346                    }
    348347                }
     
    360359            if ((dre_cmd (emmcmd42))) { //first emm request
    361360              if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    362                         return 0;       //exit if response is not 90 00
     361                        return ERROR;       //exit if response is not 90 00
    363362       
    364363              memcpy (emmcmd42 + 1, ep->emm + 55, 7);   //TODO OR next two lines?
     
    371370              if ((dre_cmd (emmcmd42))) {   //second emm request
    372371                        if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    373                             return 0;       //exit if response is not 90 00
     372                            return ERROR;       //exit if response is not 90 00
    374373              }
    375374            }
    376375        }
    377376  }
    378   return 1;         //success
     377  return OK;            //success
    379378}
    380379
    381380int dre_card_info (void)
    382381{
    383   return (1);
    384 }
     382  return OK;
     383}
Note: See TracChangeset for help on using the changeset viewer.