Changeset 1290


Ignore:
Timestamp:
01/19/10 16:48:50 (11 years ago)
Author:
rorothetroll
Message:

resync with trunk

Location:
branches/smartreader
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/smartreader/CMakeLists.txt

    r1197 r1290  
    1818    if (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
    1919        set (OSCamOperatingSystem "Tuxbox")
     20        set (CS_OS_HW "tuxbox")
     21        set (CS_OS_SYS "linux")
     22    elseif (OSCAM_SYSTEM_NAME MATCHES "TripleDragon")
     23        set (OSCamOperatingSystem "TripleDragon")
    2024        set (CS_OS_HW "tuxbox")
    2125        set (CS_OS_SYS "linux")
     
    9296elseif (OSCamOperatingSystem MATCHES "Tuxbox")
    9397    add_definitions ("-DOS_LINUX -DTUXBOX -DPPC")
     98    set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
     99elseif (OSCamOperatingSystem MATCHES "TripleDragon")
     100    add_definitions ("-DOS_LINUX -DTRIPLEDRAGON -DHAVE_DVBAPI -DSTB04SCI -DTUXBOX -DPPC")   
    94101    set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
    95102elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
     
    231238elseif (OSCamOperatingSystem MATCHES "Tuxbox")
    232239    target_link_libraries ( ${exe_name} dl)
    233 elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
    234     target_link_libraries ( ${exe_name} rt nxp )
     240elseif (OSCamOperatingSystem MATCHES "TripleDragon")
     241    target_link_libraries ( ${exe_name} dl)
    235242elseif (OSCamOperatingSystem MATCHES "SlugOS")
    236243elseif (OSCamOperatingSystem MATCHES "Fonera2")
     
    238245elseif (OSCamOperatingSystem MATCHES "Amino")
    239246elseif (OSCamOperatingSystem MATCHES "Windows/cygwin")
     247elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
     248    target_link_libraries ( ${exe_name} rt nxp )
    240249endif (OSCamOperatingSystem MATCHES "Linux")
    241250
  • branches/smartreader/Makefile

    r1158 r1290  
    1212freebsd:    i386-pc-freebsd
    1313tuxbox: cross-powerpc-tuxbox-linux
     14tripledragon: cross-powerpc-405-linux
    1415win:    cross-i386-pc-cygwin
    1516cygwin: i386-pc-cygwin
     
    2021    cross-i386-pc-cygwin \
    2122    cross-powerpc-tuxbox-linux \
     23    cross-powerpc-405-linux \
    2224    cross-i386-pc-freebsd \
    2325    cross-arm-nslu2-linux \
     
    108110        OS_CULI="-lncurses" \
    109111        OS_PTLI="-lpthread" \
    110         DS_OPTS="-O2 -DOS_MACOSX -DNEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD -DCS_CONFDIR=${CS_CONFDIR} -DHAVE_PCSC=1 -Winline -Wall -Wextra -finline-functions -fomit-frame-pointer -D'CS_SVN_VERSION="\"$(SVN_REV)\""'" \
     112        DS_OPTS="-O2 -DOS_MACOSX -DNEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD -DCS_CONFDIR=${CS_CONFDIR} -DHAVE_PCSC=1 -m32 -Winline -Wall -Wextra -finline-functions -fomit-frame-pointer -D'CS_SVN_VERSION="\"$(SVN_REV)\""'" \
    111113        DS_CFLAGS="-c" \
    112114        DS_LDFLAGS="-framework PCSC" \
     
    198200        DS_ST=powerpc-tuxbox-linux-uclibc-strip
    199201
     202######################################################################
     203#
     204#   TripleDragon crosscompiler
     205#
     206######################################################################
     207cross-powerpc-405-linux:
     208    @-$(MAKE) --no-print-directory \
     209        -f Maketype TYP=$(subst cross-,,$@) \
     210        OS_LIBS="-lcrypto -ldl -lm" \
     211        OS_CULI="-lncurses" \
     212        OS_PTLI="-lpthread" \
     213        DS_OPTS="-O2 -DOS_LINUX -DTRIPLEDRAGON -DCS_LOGHISTORY -DCS_ANTICASC -DHAVE_DVBAPI_TD -DSTB04SCI -DCS_CONFDIR='\"/var/tuxbox/config\"' -D'CS_SVN_VERSION="\"$(SVN_REV)\""'" \
     214        DS_CFLAGS="-c" \
     215        DS_LDFLAGS="" \
     216        DS_ARFLAGS="-rvsl" \
     217        DS_CC=powerpc-405-linux-gnu-gcc \
     218        DS_AR=powerpc-405-linux-gnu-ar \
     219        DS_LD=powerpc-405-linux-gnu-ld \
     220        DS_RL=powerpc-405-linux-gnu-ranlib \
     221        DS_ST=powerpc-405-linux-gnu-strip
    200222
    201223######################################################################
  • branches/smartreader/csctapi/ct_slot.c

    r1280 r1290  
    117117char CT_Slot_Probe (CT_Slot * slot, BYTE * userdata, unsigned length)
    118118{
    119     PPS * pps;
     119    //PPS * pps;
    120120    BYTE buffer[PPS_MAX_LENGTH];
    121121    unsigned buffer_len  = 0;
     
    138138    if (slot->icc_type == CT_SLOT_ICC_ASYNC)
    139139    {
    140         pps = PPS_New();
    141        
    142         if (pps == NULL)
     140        PPS_New();
     141       
     142        /* Prepare PPS request */
     143        if ((userdata != NULL) && (length > 0))
     144            memcpy (buffer, userdata, buffer_len = MIN(length, PPS_MAX_LENGTH));
     145       
     146        /* Do PPS */
     147        if (PPS_Perform (buffer, &buffer_len) != PPS_OK)
    143148        {
    144149            ICC_Async_Close ();
    145150           
    146             slot->icc = NULL;
    147             slot->icc_type = CT_SLOT_NULL;
    148             return ERR_MEMORY;
    149         }
    150        
    151         /* Prepare PPS request */
    152         if ((userdata != NULL) && (length > 0))
    153             memcpy (buffer, userdata, buffer_len = MIN(length, PPS_MAX_LENGTH));
    154        
    155         /* Do PPS */
    156         if (PPS_Perform (pps, buffer, &buffer_len) != PPS_OK)
    157         {
    158             PPS_Delete (pps);
    159            
    160             ICC_Async_Close ();
    161            
    162             slot->icc = NULL;
    163151            slot->icc_type = CT_SLOT_NULL;
    164152            slot->protocol_type = CT_SLOT_NULL;
     
    167155        }
    168156       
    169         slot->protocol_type = (PPS_GetProtocolParameters (pps))->t;
    170         slot->protocol = PPS_GetProtocol (pps);
    171        
    172        
    173         PPS_Delete (pps);
     157        slot->protocol_type = (PPS_GetProtocolParameters ())->t;
    174158    }
    175159   
     
    183167    ret = OK;
    184168   
    185     if (slot->protocol_type == CT_SLOT_PROTOCOL_T0)
    186     {
    187         if (Protocol_T0_Close ((Protocol_T0 *) slot->protocol) != PROTOCOL_T0_OK)
    188             ret = ERR_TRANS;
    189        
    190         Protocol_T0_Delete ((Protocol_T0 *) slot->protocol);
    191     }
    192     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T1)
    193     {
    194         if (Protocol_T1_Close ((Protocol_T1 *) slot->protocol) != PROTOCOL_T1_OK)
    195             ret = ERR_TRANS;
    196        
    197         Protocol_T1_Delete ((Protocol_T1 *) slot->protocol);
    198     }
    199     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T14)
    200     {
    201         if (Protocol_T14_Close ((Protocol_T14 *) slot->protocol) != PROTOCOL_T14_OK)
    202             ret = ERR_TRANS;
    203        
    204         Protocol_T14_Delete ((Protocol_T14 *) slot->protocol);
    205     }
    206    
    207     slot->protocol = NULL;
    208169    slot->protocol_type = CT_SLOT_NULL;
    209170   
     
    214175    }
    215176   
    216     slot->icc = NULL;
    217177    slot->icc_type = CT_SLOT_NULL;
    218178   
     
    227187    if (slot->protocol_type == CT_SLOT_PROTOCOL_T0) /* T=0 protocol ICC */
    228188    {
    229         if (Protocol_T0_Command ( cmd, rsp) != PROTOCOL_T0_OK)
     189        if (Protocol_T0_Command (cmd, rsp) != PROTOCOL_T0_OK)
    230190            ret = ERR_TRANS;
    231191        else
     
    234194    else if (slot->protocol_type == CT_SLOT_PROTOCOL_T1) /* T=1 protocol ICC */
    235195    {
    236         if (Protocol_T1_Command ((Protocol_T1 *) slot->protocol, cmd, rsp) != PROTOCOL_T1_OK)
     196        if (Protocol_T1_Command (cmd, rsp) != PROTOCOL_T1_OK)
    237197            ret = ERR_TRANS;
    238198        else
     
    241201    else if (slot->protocol_type == CT_SLOT_PROTOCOL_T14) /* T=14 protocol ICC */
    242202    {
    243         if (Protocol_T14_Command (cmd, rsp) != PROTOCOL_T14_OK)
     203        if (Protocol_T14_Command (cmd, rsp) != PROTOCOL_T0_OK)
    244204            ret = ERR_TRANS;
    245205        else
     
    266226{
    267227    return slot->icc_type;
    268 }
    269 
    270 void * CT_Slot_GetICC (CT_Slot * slot)
    271 {
    272     return slot->icc;
    273228}
    274229
     
    301256    ret = OK;
    302257   
    303     if (slot->protocol_type == CT_SLOT_PROTOCOL_T0)
    304     {
    305         if (Protocol_T0_Close ((Protocol_T0 *) slot->protocol) != PROTOCOL_T0_OK)
    306             ret = ERR_TRANS;
    307        
    308         Protocol_T0_Delete ((Protocol_T0 *) slot->protocol);
    309     }
    310     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T1)
    311     {
    312         if (Protocol_T1_Close ((Protocol_T1 *) slot->protocol) != PROTOCOL_T1_OK)
    313             ret = ERR_TRANS;
    314        
    315         Protocol_T1_Delete ((Protocol_T1 *) slot->protocol);
    316     }
    317     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T14)
    318     {
    319         if (Protocol_T14_Close ((Protocol_T14 *) slot->protocol) != PROTOCOL_T14_OK)
    320             ret = ERR_TRANS;
    321        
    322         Protocol_T14_Delete ((Protocol_T14 *) slot->protocol);
    323     }
    324    
    325258    if (slot->icc_type == CT_SLOT_ICC_ASYNC)
    326259    {
     
    348281static void CT_Slot_Clear (CT_Slot * slot)
    349282{
    350     slot->icc = NULL;
    351     slot->protocol = NULL;
    352283    slot->icc_type = CT_SLOT_NULL;
    353284    slot->protocol_type = CT_SLOT_NULL;
  • branches/smartreader/csctapi/ct_slot.h

    r1271 r1290  
    5252typedef struct
    5353{
    54   void * icc;       /* Integrated circuit card */
    55   void * protocol;  /* Protocol handler */
    5654  int icc_type;     /* Type of ICC */
    5755  int protocol_type;    /* Type of protocol */
     
    9189CT_Slot_GetICCType (CT_Slot * slot);
    9290
    93 /* Return a reference to the ICC */
    94 extern void *
    95 CT_Slot_GetICC (CT_Slot * slot);
    96 
    9791/* Get answer to reset of the card */
    9892extern void *
  • branches/smartreader/csctapi/pps.c

    r1280 r1290  
    3838
    3939#define PPS_DEFAULT_PROTOCOL    0x00
    40 
     40#define PROTOCOL_T0_DEFAULT_WI 10
     41
     42#define PROTOCOL_T1_DEFAULT_IFSC        32
     43#define PROTOCOL_T1_DEFAULT_IFSD        32
     44#define PROTOCOL_T1_MAX_IFSC            251  /* Cannot send > 255 buffer */
     45#define PROTOCOL_T1_DEFAULT_CWI         13
     46#define PROTOCOL_T1_DEFAULT_BWI         4
     47#define PROTOCOL_T1_EDC_LRC             0
     48#define PROTOCOL_T1_EDC_CRC             1
    4149/*
    4250 * Not exported macros definition
     
    5765static unsigned PPS_GetLength (BYTE * block);
    5866
    59 static int PPS_InitICC (PPS * pps);
    60 
    61 static int PPS_InitProtocol (PPS * pps, int protocol_selected);
     67static int PPS_InitICC ();
     68
     69static int PPS_InitProtocol ();
    6270
    6371static BYTE PPS_GetPCK (BYTE * block, unsigned length);
     
    6775 */
    6876
    69 PPS * PPS_New ()
    70 {
    71     PPS *pps;
    72    
    73     pps = (PPS *) malloc (sizeof (PPS));
    74    
    75     if (pps != NULL)
    76     {
    77         pps->protocol = NULL;
    78         pps->parameters.t = PPS_DEFAULT_PROTOCOL;
    79         pps->parameters.FI = ATR_DEFAULT_FI;
    80         pps->parameters.d = ATR_DEFAULT_D;
    81         pps->parameters.n = ATR_DEFAULT_N;
    82     }
    83    
    84     return pps;
    85 }
    86 
    87 int PPS_Perform (PPS * pps, BYTE * params, unsigned *length)
     77void PPS_New ()
     78{
     79        protocol = NULL;
     80        parameters.t = PPS_DEFAULT_PROTOCOL;
     81        parameters.FI = ATR_DEFAULT_FI;
     82        parameters.d = ATR_DEFAULT_D;
     83        parameters.n = ATR_DEFAULT_N;
     84}
     85
     86int PPS_Perform (BYTE * params, unsigned *length)
    8887{
    8988    //Performs PPS Exchange on command when *length >0
     
    110109        if (ret == PPS_OK)
    111110        {
    112             pps->parameters.t = params[1] & 0x0F;
     111            parameters.t = params[1] & 0x0F;
    113112           
    114113            if (PPS_HAS_PPS1 (params))
    115114            {
    116                 pps->parameters.FI = (params[2] >> 4);
    117                 pps->parameters.d = atr_d_table[(params[2] & 0x0F)];
     115                parameters.FI = (params[2] >> 4);
     116                parameters.d = atr_d_table[(params[2] & 0x0F)];
    118117            }
    119118           
    120119/*         
    121             ret  = PPS_InitICC(pps);
     120            ret  = PPS_InitICC();
    122121           
    123122            if (ret != PPS_OK)
     
    186185
    187186//If more than one protocol type and/or TA1 parameter values other than the default values and/or N equeal to 255 is/are indicated in the answer to reset, the card shall know unambiguously, after having sent the answer to reset, which protocol type or/and transmission parameter values (FI, D, N) will be used. Consequently a selection of the protocol type and/or the transmission parameters values shall be specified.
    188         ATR_GetParameter (atr, ATR_PARAMETER_N, &(pps->parameters.n));
    189         ATR_GetProtocolType(atr,1,&(pps->parameters.t)); //get protocol from TD1
     187        ATR_GetParameter (atr, ATR_PARAMETER_N, &(parameters.n));
     188        ATR_GetProtocolType(atr,1,&(parameters.t)); //get protocol from TD1
    190189        BYTE TA2;
    191190        bool SpecificMode = (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TA, &TA2) == ATR_OK); //if TA2 present, specific mode, else negotiable mode
    192191        if (SpecificMode) {
    193             pps->parameters.t = TA2 & 0x0F;
     192            parameters.t = TA2 & 0x0F;
    194193            if ((TA2 & 0x10) != 0x10) { //bit 5 set to 0 means F and D explicitly defined in interface characters
    195194                BYTE TA1;
    196195                if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) {
    197                     pps->parameters.FI = TA1 >> 4;
    198                     ATR_GetParameter (atr, ATR_PARAMETER_D, &(pps->parameters.d));
     196                    parameters.FI = TA1 >> 4;
     197                    ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d));
    199198                }
    200199                else {
    201                     pps->parameters.FI = ATR_DEFAULT_FI;
    202                     pps->parameters.d = ATR_DEFAULT_D;
     200                    parameters.FI = ATR_DEFAULT_FI;
     201                    parameters.d = ATR_DEFAULT_D;
    203202                }
    204203            }
    205204            else {
    206205                cs_log("Specific mode: speed 'implicitly defined', not sure how to proceed, assuming default values");
    207                 pps->parameters.FI = ATR_DEFAULT_FI;
    208                 pps->parameters.d = ATR_DEFAULT_D;
    209             }
    210             cs_debug("Specific mode: 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);
     206                parameters.FI = ATR_DEFAULT_FI;
     207                parameters.d = ATR_DEFAULT_D;
     208            }
     209            cs_debug("Specific mode: T%i, F=%.0f, D=%.6f, N=%.0f\n", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
    211210        }
    212211        else { //negotiable mode
    213212
    214             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            bool NeedsPTS = ((parameters.t != 14) && (numprottype > 1 || (atr->ib[0][ATR_INTERFACE_BYTE_TA].present == TRUE && atr->ib[0][ATR_INTERFACE_BYTE_TA].value != 0x11) || parameters.n == 255)); //needs PTS according to ISO 7816 , SCI gets stuck on our PTS
    215214            if (NeedsPTS) {
    216215                //             PTSS  PTS0  PTS1  PTS2  PTS3  PCK
    217216                //             PTSS  PTS0  PTS1  PCK
    218217                BYTE req[] = { 0xFF, 0x10, 0x00, 0x00 }; //we currently do not support PTS2, standard guardtimes
    219                 req[1]=0x10 | pps->parameters.t; //PTS0 always flags PTS1 to be sent always
     218                req[1]=0x10 | parameters.t; //PTS0 always flags PTS1 to be sent always
    220219                if (ATR_GetInterfaceByte (atr, 1, ATR_INTERFACE_BYTE_TA, &req[2]) != ATR_OK)  //PTS1
    221220                    req[2] = 0x11; //defaults FI and DI to 1
     
    224223                ret = PPS_Exchange (req, &len);
    225224            if (ret == PPS_OK) {
    226                     pps->parameters.FI = req[2] >> 4;
     225                    parameters.FI = req[2] >> 4;
    227226                    BYTE DI = req[2] & 0x0F;
    228                     pps->parameters.d = (double) (atr_d_table[DI]);
     227                    parameters.d = (double) (atr_d_table[DI]);
    229228                    PPS_success = TRUE;
    230                     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);
     229                    cs_debug("PTS Succesfull, selected protocol: T%i, F=%.0f, D=%.6f, N=%.0f\n", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
    231230                }
    232231                else
     
    239238                BYTE TA1;
    240239                if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) {
    241                     pps->parameters.FI = TA1 >> 4;
    242                     ATR_GetParameter (atr, ATR_PARAMETER_D, &(pps->parameters.d));
     240                    parameters.FI = TA1 >> 4;
     241                    ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d));
    243242                }
    244243                else { //do not obey TA1
    245                     pps->parameters.FI = ATR_DEFAULT_FI;
    246                     pps->parameters.d = ATR_DEFAULT_D;
     244                    parameters.FI = ATR_DEFAULT_FI;
     245                    parameters.d = ATR_DEFAULT_D;
    247246                }
    248                 ATR_GetProtocolType (atr, 1, &(pps->parameters.t));
     247                ATR_GetProtocolType (atr, 1, &(parameters.t));
    249248                protocol_selected = 1;
    250249   
    251250                if (NeedsPTS) {
    252                     if ((pps->parameters.d == 32) || (pps->parameters.d == 12) || (pps->parameters.d == 20))
    253                         pps->parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this
     251                    if ((parameters.d == 32) || (parameters.d == 12) || (parameters.d == 20))
     252                        parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this
    254253                }
    255254                /////Here all non-ISO behaviour
    256255                /////End  all non-ISO behaviour
    257256
    258                 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                cs_debug("No PTS %s, selected protocol T%i, F=%.0f, D=%.6f, N=%.0f\n", NeedsPTS?"happened":"needed", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
    259258            }
    260259        }//end negotiable mode
     
    262261       
    263262    //make sure no zero values
    264     double F =  (double) atr_f_table[pps->parameters.FI];
     263    double F =  (double) atr_f_table[parameters.FI];
    265264    if (!F) {
    266         pps->parameters.FI = ATR_DEFAULT_FI;
    267         cs_log("Warning: F=0 is invalid, forcing FI=%d", pps->parameters.FI);
    268     }
    269     if (!pps->parameters.d) {
    270         pps->parameters.d = ATR_DEFAULT_D;
    271         cs_log("Warning: D=0 is invalid, forcing D=%.0f",pps->parameters.d);
    272     }
    273 
    274     protocol_type = pps->parameters.t;
     265        parameters.FI = ATR_DEFAULT_FI;
     266        cs_log("Warning: F=0 is invalid, forcing FI=%d", parameters.FI);
     267    }
     268    if (!parameters.d) {
     269        parameters.d = ATR_DEFAULT_D;
     270        cs_log("Warning: D=0 is invalid, forcing D=%.0f",parameters.d);
     271    }
     272
     273    protocol_type = parameters.t;
    275274   
    276275#ifdef DEBUG_PROTOCOL
    277276    printf("PPS: T=%i, F=%.0f, D=%.6f, N=%.0f\n",
    278     pps->parameters.t,
     277    parameters.t,
    279278    F,
    280     pps->parameters.d,
    281     pps->parameters.n);
    282 #endif
    283 
    284     ret  = PPS_InitICC(pps);
     279    parameters.d,
     280    parameters.n);
     281#endif
     282
     283    ret  = PPS_InitICC();
    285284           
    286285    if (ret != PPS_OK)
     
    288287   
    289288    /* Initialize selected protocol with selected parameters */
    290     if (pps->parameters.t == 1)
    291         ret = PPS_InitProtocol (pps, 3); //FIXME in practice most T1 cards carry timing parameters in TA3, TB3 and TC3
    292     else
    293         ret = PPS_InitProtocol (pps, 2); //FIXME T0 cards carry timing parameters in TC2
    294    
    295     return ret;
    296 }
    297 
    298 void * PPS_GetProtocol (PPS * pps)
    299 {
    300     return pps->protocol;
    301 }
    302 
    303 PPS_ProtocolParameters *PPS_GetProtocolParameters (PPS * pps)
     289    return PPS_InitProtocol ();
     290}
     291
     292PPS_ProtocolParameters *PPS_GetProtocolParameters ()
    304293{
    305294    /* User must Remember not to reference this struct after removing PPS */
    306     return &(pps->parameters);
    307 }
    308 
    309 void PPS_Delete (PPS * pps)
    310 {
    311     free (pps);
     295    return &(parameters);
    312296}
    313297
     
    423407}
    424408
    425 static int PPS_InitICC (PPS * pps)
     409static int PPS_InitICC ()
    426410{
    427411#ifdef SCI_DEV
     
    437421            return PPS_ICC_ERROR;
    438422
    439         params.T = pps->parameters.t;
    440         params.fs = atr_fs_table[pps->parameters.FI] / 1000000;
    441         double F =  (double) atr_f_table[pps->parameters.FI];
     423        params.T = parameters.t;
     424        params.fs = atr_fs_table[parameters.FI] / 1000000;
     425        double F =  (double) atr_f_table[parameters.FI];
    442426        //for Irdeto T14 cards, do not set ETU
    443427    if (!(atr->hbn >= 6 && !memcmp(atr->hb, "IRDETO", 6) && params.T == 14))
    444           params.ETU = F / pps->parameters.d;
    445         if (pps->parameters.n == 255) //only for T0 or also for T1?
     428          params.ETU = F / parameters.d;
     429        if (parameters.n == 255) //only for T0 or also for T1?
    446430            params.EGT = 0;
    447431        else
    448             params.EGT = pps->parameters.n;
     432            params.EGT = parameters.n;
    449433
    450434        double a;
     
    462446#elif COOL
    463447    if(reader[ridx].typ == R_INTERNAL) {
    464         int mhz = atr_fs_table[pps->parameters.FI] / 10000;
     448        int mhz = atr_fs_table[parameters.FI] / 10000;
    465449        if (!Cool_SetBaudrate(mhz))
    466450            return PPS_ICC_ERROR;
     
    473457    {
    474458    unsigned long baudrate;
    475     double F =  (double) atr_f_table[pps->parameters.FI];
    476     if (pps->parameters.t == 14)
     459    double F =  (double) atr_f_table[parameters.FI];
     460    if (parameters.t == 14)
    477461        baudrate = 9600;
    478462    else
    479         baudrate = pps->parameters.d * ICC_Async_GetClockRate () / F;
     463        baudrate = parameters.d * ICC_Async_GetClockRate () / F;
    480464
    481465#ifdef DEBUG_PROTOCOL
     
    491475}
    492476
    493 static int PPS_InitProtocol (PPS * pps, int selected_protocol)
    494 {
    495     int ret;
    496    
    497     if (pps->parameters.t == ATR_PROTOCOL_TYPE_T0)
    498     {
    499         pps->protocol = Protocol_T0_New ();
    500        
    501         if ((pps->protocol) != NULL)
     477int Protocol_T1_Init ()
     478{
     479    BYTE ta, tb, tc, cwi, bwi;
     480    unsigned long baudrate;
     481    double work_etu;
     482
     483    // Set IFSC
     484    if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TA, &ta) == ATR_NOT_FOUND)
     485        ifsc = PROTOCOL_T1_DEFAULT_IFSC;
     486    else if ((ta != 0x00) && (ta != 0xFF))
     487        ifsc = ta;
     488    else
     489        ifsc = PROTOCOL_T1_DEFAULT_IFSC;
     490
     491    // Towitoko does not allow IFSC > 251 //FIXME not sure whether this limitation still exists
     492    ifsc = MIN (ifsc, PROTOCOL_T1_MAX_IFSC);
     493
     494    // Set IFSD
     495    ifsd = PROTOCOL_T1_DEFAULT_IFSD;
     496
     497#ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS
     498    // Calculate CWI and BWI
     499    if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TB, &tb) == ATR_NOT_FOUND)
    502500        {
    503             ret = Protocol_T0_Init ((Protocol_T0 *) pps->protocol, &(pps->parameters), selected_protocol);
     501#endif
     502            cwi = PROTOCOL_T1_DEFAULT_CWI;
     503            bwi = PROTOCOL_T1_DEFAULT_BWI;
     504#ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS
     505        }
     506    else
     507        {
     508            cwi = tb & 0x0F;
     509            bwi = tb >> 4;
     510        }
     511#endif
     512   
     513    // Work etu = (1000 / baudrate) milliseconds
     514    ICC_Async_GetBaudrate (&baudrate);
     515    work_etu = 1000 / (double)baudrate;
     516
     517    // Set CWT = (2^CWI + 11) work etu
     518    cwt = (unsigned short) (((1<<cwi) + 11) * work_etu);
     519
     520    // Set BWT = (2^BWI * 960 + 11) work etu
     521    bwt = (unsigned short) (((1<<bwi) * 960 + 11) * work_etu);
     522
     523    // Set BGT = 22 * work etu
     524    bgt = (unsigned short) (22 * work_etu);
     525
     526    // Set the error detection code type
     527    if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TC, &tc) == ATR_NOT_FOUND)
     528        edc = PROTOCOL_T1_EDC_LRC;
     529    else
     530        edc = tc & 0x01;
     531
     532    // Set initial send sequence (NS)
     533    ns = 1;
     534   
     535    // Set timings
     536    icc_timings.block_timeout = bwt;
     537    icc_timings.char_timeout = cwt;
     538    icc_timings.block_delay = bgt;
     539    ICC_Async_SetTimings ();
     540
     541#ifdef DEBUG_PROTOCOL
     542    printf ("Protocol: T=1: IFSC=%d, IFSD=%d, CWT=%d, BWT=%d, BGT=%d, EDC=%s\n",
     543                    ifsc, ifsd, cwt, bwt, t1->bgt,
     544                    (edc == PROTOCOL_T1_EDC_LRC) ? "LRC" : "CRC");
     545#endif
     546
     547    return PROTOCOL_T1_OK;
     548}
     549
     550static int PPS_InitProtocol ()
     551{
     552    switch (parameters.t) {
     553        case ATR_PROTOCOL_TYPE_T0:
     554        case ATR_PROTOCOL_TYPE_T14:
     555            {
     556            BYTE wi;
     557            /* Integer value WI = TC2, by default 10 */
     558#ifndef PROTOCOL_T0_USE_DEFAULT_TIMINGS
     559            if (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
     560#endif
     561            wi = PROTOCOL_T0_DEFAULT_WI;
     562
     563            /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */
     564            double F =  (double) atr_f_table[parameters.FI];
     565            unsigned long wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
     566            if (parameters.t == 14)
     567                wwt >>= 1; //is this correct?
    504568           
    505             if (ret != PROTOCOL_T0_OK)
    506             {
    507                 Protocol_T0_Delete ((Protocol_T0 *) pps->protocol);
    508                 pps->protocol = NULL;
    509                 return PPS_PROTOCOL_ERROR;
    510             }
    511            
    512             return PPS_OK;
    513         }       
    514     }
    515     else if (pps->parameters.t == ATR_PROTOCOL_TYPE_T1)
    516     {
    517         pps->protocol = Protocol_T1_New ();
    518        
    519         if (pps->protocol != NULL)
    520         {
    521             ret = Protocol_T1_Init ((Protocol_T1 *) pps->protocol, selected_protocol);
    522            
    523             if (ret != PROTOCOL_T1_OK)
    524             {
    525                 Protocol_T1_Delete ((Protocol_T1 *) pps->protocol);
    526                 pps->protocol = NULL;
    527                 return PPS_PROTOCOL_ERROR;
    528             }
    529            
    530             return PPS_OK;
    531         }
    532     }
    533     else if (pps->parameters.t == ATR_PROTOCOL_TYPE_T14)
    534     {
    535         pps->protocol = Protocol_T14_New ();
    536        
    537         if ((pps->protocol) != NULL)
    538         {
    539             ret = Protocol_T14_Init ((Protocol_T14 *) pps->protocol, &(pps->parameters), selected_protocol);
    540            
    541             if (ret != PROTOCOL_T14_OK)
    542             {
    543                 Protocol_T14_Delete ((Protocol_T14 *) pps->protocol);
    544                 pps->protocol = NULL;
    545                 return PPS_PROTOCOL_ERROR;
    546             }
    547            
    548             return PPS_OK;
    549         }       
    550     }
    551     else
    552     {
    553         pps->protocol = NULL;
    554     }
    555    
    556     return PPS_PROTOCOL_ERROR;
     569            /* Set timings */
     570            icc_timings.block_timeout = wwt;
     571            icc_timings.char_timeout = wwt;
     572            ICC_Async_SetTimings ();
     573#ifdef DEBUG_PROTOCOL
     574            printf ("Protocol: T=%i: WWT=%d, Clockrate=%lu\n", params->t, (int)(wwt),ICC_Async_GetClockRate());
     575#endif
     576            }
     577            break;
     578     case ATR_PROTOCOL_TYPE_T1:
     579            Protocol_T1_Init ();//always returns ok
     580            break;
     581     default:
     582            protocol = NULL;
     583            return PPS_PROTOCOL_ERROR;
     584            break;
     585    }
     586    return PPS_OK;
    557587}
    558588
  • branches/smartreader/csctapi/pps.h

    r1280 r1290  
    5151PPS_ProtocolParameters;
    5252
    53 typedef struct
    54 {
    55   void *protocol;
    56   PPS_ProtocolParameters parameters;
    57 }
    58 PPS;
     53void *protocol;
     54PPS_ProtocolParameters parameters;
    5955
    6056/*
     
    6359
    6460/* Create PPS context */
    65 extern PPS *PPS_New ();
     61extern void PPS_New ();
    6662
    6763/* Perform protcol type selection and return confirm */
    68 extern int PPS_Perform (PPS * pps, BYTE * params, unsigned *length);
    69 
    70 /* Get protocol handler */
    71 extern void *PPS_GetProtocol (PPS * pps);
     64extern int PPS_Perform (BYTE * params, unsigned *length);
    7265
    7366/* Get protocol parameters */
    74 extern PPS_ProtocolParameters *PPS_GetProtocolParameters (PPS * pps);
    75 
    76 /* Delete PPS context */
    77 extern void PPS_Delete (PPS * pps);
     67extern PPS_ProtocolParameters *PPS_GetProtocolParameters ();
    7868
    7969#endif /* _PPS_ */
  • branches/smartreader/csctapi/protocol_t0.c

    r1280 r1290  
    5252 */
    5353
    54 static void Protocol_T0_Clear (Protocol_T0 * t0);
    55 static void Protocol_T14_Clear (Protocol_T14 * t14);
    56 
    5754static int Protocol_T0_Case1 (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    5855
     
    7774 * Exproted funtions definition
    7875 */
    79 
    80 Protocol_T0 * Protocol_T0_New (void)
    81 {
    82     Protocol_T0 *t0;
    83    
    84     t0 = (Protocol_T0 *) malloc (sizeof (Protocol_T0));
    85    
    86     if (t0 != NULL)
    87         Protocol_T0_Clear (t0);
    88    
    89     return t0;
    90 }
    91 
    92 Protocol_T14 * Protocol_T14_New (void)
    93 {
    94     Protocol_T14 *t14;
    95    
    96     t14 = (Protocol_T14 *) malloc (sizeof (Protocol_T14));
    97    
    98     if (t14 != NULL)
    99         Protocol_T14_Clear (t14);
    100    
    101     return t14;
    102 }
    103 
    104 int Protocol_T0_Init (Protocol_T0 * t0, PPS_ProtocolParameters * params, int selected_protocol)
    105 {
    106     BYTE wi;
    107    
    108     /* Integer value WI  = TC2, by default 10 */
    109 #ifndef PROTOCOL_T0_USE_DEFAULT_TIMINGS
    110     if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
    111 #endif
    112     wi = PROTOCOL_T0_DEFAULT_WI;
    113    
    114     /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */
    115     double F =  (double) atr_f_table[params->FI];
    116     t0->wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
    117    
    118     /* Set timings */
    119     icc_timings.block_timeout = t0->wwt;
    120     icc_timings.char_timeout = t0->wwt;
    121     ICC_Async_SetTimings ();
    122    
    123 #ifdef DEBUG_PROTOCOL
    124     printf ("Protocol: T=0: WWT=%d, Clockrate=%lu\n", (int)(t0->wwt),ICC_Async_GetClockRate());
    125 #endif
    126    
    127     return PROTOCOL_T0_OK;
    128 }
    129 
    130 int Protocol_T14_Init (Protocol_T14 * t14, PPS_ProtocolParameters * params, int selected_protocol)
    131 {
    132     BYTE wi;
    133    
    134     /* Integer value WI  = TC2, by default 10 */
    135 #ifndef PROTOCOL_T14_USE_DEFAULT_TIMINGS
    136     if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
    137 #endif
    138     wi = PROTOCOL_T14_DEFAULT_WI;
    139    
    140     /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */
    141     double F =  (double) atr_f_table[params->FI];
    142     t14->wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
    143     t14->wwt >>= 1;
    144    
    145     /* Set timings */
    146     icc_timings.block_timeout = t14->wwt;
    147     icc_timings.char_timeout = t14->wwt;
    148     ICC_Async_SetTimings ();
    149 
    150 #ifdef DEBUG_PROTOCOL
    151     printf ("Protocol: T=14: WWT=%d\n", (int)(t14->wwt));
    152 #endif
    153    
    154     return PROTOCOL_T14_OK;
    155 }
    15676
    15777int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp)
     
    215135        printf ("Protocol: T=14: Invalid APDU\n");
    216136#endif
    217     ret = PROTOCOL_T14_ERROR;
    218     }
    219    
    220     return ret;
    221 }
    222 
    223 int Protocol_T0_Close (Protocol_T0 * t0)
    224 {
    225     Protocol_T0_Clear (t0);
    226    
    227     return PROTOCOL_T0_OK;
    228 }
    229 
    230 int Protocol_T14_Close (Protocol_T14 * t14)
    231 {
    232     Protocol_T14_Clear (t14);
    233    
    234     return PROTOCOL_T14_OK;
    235 }
    236 
    237 void Protocol_T0_Delete (Protocol_T0 * t0)
    238 {
    239     free (t0);
    240 }
    241 
    242 void Protocol_T14_Delete (Protocol_T14 * t14)
    243 {
    244     free (t14);
     137    ret = PROTOCOL_T0_ERROR;
     138    }
     139   
     140    return ret;
    245141}
    246142
     
    964860    BYTE *cmd_raw;
    965861    long sent, recv, cmd_len;
    966     int ret = PROTOCOL_T14_OK, nulls, cmd_case;
     862    int ret = PROTOCOL_T0_OK, nulls, cmd_case;
    967863    BYTE ixor = 0x3E;
    968864    BYTE ixor1 = 0x3F;
     
    979875    /* Check case of command */
    980876    if ((cmd_case != APDU_CASE_2S) && (cmd_case != APDU_CASE_3S))
    981         return PROTOCOL_T14_ERROR;
     877        return PROTOCOL_T0_ERROR;
    982878   
    983879    if (reader[ridx].typ != R_INTERNAL)
     
    987883        {
    988884            (*rsp) = NULL;
    989             return PROTOCOL_T14_ICC_ERROR;
     885            return PROTOCOL_T0_ICC_ERROR;
    990886        }
    991887       
     
    994890        {
    995891            (*rsp) = NULL;
    996             return PROTOCOL_T14_ICC_ERROR;
     892            return PROTOCOL_T0_ICC_ERROR;
    997893        }
    998894       
     
    1001897        {
    1002898            (*rsp) = NULL;
    1003             return PROTOCOL_T14_ICC_ERROR;
     899            return PROTOCOL_T0_ICC_ERROR;
    1004900        }
    1005901    }
     
    1014910        {
    1015911            (*rsp) = NULL;
    1016             return PROTOCOL_T14_ICC_ERROR;
     912            return PROTOCOL_T0_ICC_ERROR;
    1017913        }
    1018914    }
     
    1050946        if (ICC_Async_Receive (8, buffer) != ICC_ASYNC_OK)
    1051947        {
    1052             ret = PROTOCOL_T14_ICC_ERROR;
     948            ret = PROTOCOL_T0_ICC_ERROR;
    1053949            break;
    1054950        }
     
    1061957                if (ICC_Async_Receive (recv, buffer + 8) != ICC_ASYNC_OK)
    1062958                {
    1063                     ret = PROTOCOL_T14_ICC_ERROR;
     959                    ret = PROTOCOL_T0_ICC_ERROR;
    1064960                    break;
    1065961                }
     
    1068964            if (ICC_Async_Receive (1, &ixor) != ICC_ASYNC_OK)
    1069965            {
    1070                 ret = PROTOCOL_T14_ICC_ERROR;
     966                ret = PROTOCOL_T0_ICC_ERROR;
    1071967                break;
    1072968            }
     
    1077973            if(ixor1 != ixor)
    1078974            {
    1079                 ret = PROTOCOL_T14_ERROR;
     975                ret = PROTOCOL_T0_ERROR;
    1080976                break;
    1081977            }
     
    1084980           
    1085981               
    1086             ret = PROTOCOL_T14_OK;
     982            ret = PROTOCOL_T0_OK;
    1087983            break;
    1088984        }
    1089985    }
    1090986       
    1091     if (ret == PROTOCOL_T14_OK)
     987    if (ret == PROTOCOL_T0_OK)
    1092988    {
    1093989        memcpy(buffer + 8 + recv, buffer + 2, 2);
     
    1101997    return (ret);
    1102998}
    1103 
    1104 static void Protocol_T0_Clear (Protocol_T0 * t0)
    1105 {
    1106     t0->wwt = 0;
    1107 }
    1108 
    1109 static void Protocol_T14_Clear (Protocol_T14 * t14)
    1110 {
    1111     t14->wwt = 0;
    1112 }
  • branches/smartreader/csctapi/protocol_t0.h

    r1280 r1290  
    4242#define PROTOCOL_T0_ERROR       4   /* T=0 Protocol Error */
    4343
    44 /* Return codes */
    45 #define PROTOCOL_T14_OK         0   /* Command OK */
    46 #define PROTOCOL_T14_NULL_ERROR     1   /* Maximum NULL's reachec */
    47 #define PROTOCOL_T14_ICC_ERROR      2   /* ICC comunication error */
    48 #define PROTOCOL_T14_IFD_ERROR      3   /* IFD comunication error */
    49 #define PROTOCOL_T14_ERROR      4   /* T=0 Protocol Error */
    50 
    5144/*
    5245 * Exported datatypes definition
    5346 */
    54 
    55 /* T=0 Protocol handler */
    56 typedef struct
    57 {
    58   unsigned long wwt;        /* Work waiting time (ms) */
    59 }
    60 Protocol_T0;
    61 
    62 /* T=14 Protocol handler */
    63 typedef struct
    64 {
    65   unsigned long wwt;        /* Work waiting time (ms) */
    66 }
    67 Protocol_T14;
    6847
    6948/*
     
    7150 */
    7251
    73 /* Create a new protocol handler */
    74 extern Protocol_T0 *Protocol_T0_New (void);
    75 extern Protocol_T14 *Protocol_T14_New (void);
    76 
    77 /* Delete a protocol handler */
    78 extern void Protocol_T0_Delete (Protocol_T0 * t0);
    79 extern void Protocol_T14_Delete (Protocol_T14 * t14);
    80 
    81 /* Initialise a protocol handler */
    82 extern int Protocol_T0_Init (Protocol_T0 * t0, PPS_ProtocolParameters * params, int selected_protocol);
    83 extern int Protocol_T14_Init (Protocol_T14 * t14, PPS_ProtocolParameters * params, int selected_protocol);
    84 
    8552/* Send a command and return a response */
    8653extern int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    8754extern int Protocol_T14_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    8855
    89 /* Close a protocol handler */
    90 extern int Protocol_T0_Close (Protocol_T0 * t0);
    91 extern int Protocol_T14_Close (Protocol_T14 * t14);
    92 
    9356#endif /* _PROTOCOL_T0_ */
    9457
  • branches/smartreader/csctapi/protocol_t1.c

    r1280 r1290  
    3131
    3232/*
    33  * Not exported constants definition
    34  */
    35 #define PROTOCOL_T1_DEFAULT_IFSC        32
    36 #define PROTOCOL_T1_DEFAULT_IFSD        32
    37 #define PROTOCOL_T1_MAX_IFSC            251  /* Cannot send > 255 buffer */
    38 #define PROTOCOL_T1_DEFAULT_CWI         13
    39 #define PROTOCOL_T1_DEFAULT_BWI         4
    40 #define PROTOCOL_T1_EDC_LRC             0
    41 #define PROTOCOL_T1_EDC_CRC             1
    42 
    43 /*
    4433 * Not exported functions declaration
    4534 */
    4635
    47 static void
    48 Protocol_T1_Clear (Protocol_T1 * t1);
    49 
    5036static int
    5137Protocol_T1_SendBlock (T1_Block * block);
    5238
    5339static int
    54 Protocol_T1_ReceiveBlock (Protocol_T1 * t1, T1_Block ** block);
     40Protocol_T1_ReceiveBlock (T1_Block ** block);
    5541
    5642static int
     
    6147 */
    6248
    63 Protocol_T1 *
    64 Protocol_T1_New (void)
    65 {
    66   Protocol_T1 *t1;
    67 
    68   t1 = (Protocol_T1 *) malloc (sizeof (Protocol_T1));
    69 
    70   if (t1 != NULL)
    71     Protocol_T1_Clear (t1);
    72 
    73   return t1;
    74 }
    75 
    7649int
    77 Protocol_T1_Init (Protocol_T1 * t1, int selected_protocol)
    78 {
    79   BYTE ta, tb, tc, cwi, bwi;
    80   unsigned long baudrate;
    81   double work_etu;
    82   int i;
    83 
    84   /* Set IFSC */
    85   if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TA, &ta) == ATR_NOT_FOUND)
    86     t1->ifsc = PROTOCOL_T1_DEFAULT_IFSC;
    87   else if ((ta != 0x00) && (ta != 0xFF))
    88     t1->ifsc = ta;
    89   else
    90     t1->ifsc = PROTOCOL_T1_DEFAULT_IFSC;
    91 
    92   /* Towitoko does not allow IFSC > 251 */
    93   t1->ifsc = MIN (t1->ifsc, PROTOCOL_T1_MAX_IFSC);
    94 
    95   /* Set IFSD */
    96   t1->ifsd = PROTOCOL_T1_DEFAULT_IFSD;
    97 
    98 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS
    99   /* Calculate CWI and BWI */
    100   if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TB, &tb) == ATR_NOT_FOUND)
    101     {
    102 #endif
    103       cwi  = PROTOCOL_T1_DEFAULT_CWI;
    104       bwi = PROTOCOL_T1_DEFAULT_BWI;
    105 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS
    106     }
    107   else
    108     {
    109       cwi  = tb & 0x0F;
    110       bwi = (tb & 0xF0) >> 4;
    111     }
    112 #endif
    113  
    114   /* Work etu  = (1000 / baudrate) milliseconds */
    115   ICC_Async_GetBaudrate (&baudrate);
    116   work_etu = 1000 / (double)baudrate;
    117 
    118   /* Set CWT = (2^CWI + 11) work etu */
    119   t1->cwt = 1;
    120 
    121   for (i = 0; i < cwi ; i++)
    122     t1->cwt *= 2;
    123 
    124   t1->cwt = (unsigned short) ((t1->cwt + 11) * work_etu);
    125 
    126   /* Set BWT = (2^BWI * 960 + 11) work etu */
    127   t1->bwt = 1;
    128   for (i = 0; i < bwi; i++)
    129     t1->bwt *= 2;
    130 
    131   t1->bwt = (unsigned short) ((t1->bwt * 960 + 11) * work_etu);
    132 
    133   /* Set BGT = 22 * work etu */
    134   t1->bgt = (unsigned short) (22 * work_etu);
    135 
    136   /* Set the error detection code type */
    137   if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &tc) == ATR_NOT_FOUND)
    138     t1->edc = PROTOCOL_T1_EDC_LRC;
    139   else
    140     t1->edc = tc & 0x01;
    141 
    142   /* Set initial send sequence (NS) */
    143   t1->ns = 1;
    144  
    145   /* Set timings */
    146   icc_timings.block_timeout = t1->bwt;
    147   icc_timings.char_timeout = t1->cwt;
    148   icc_timings.block_delay = t1->bgt;
    149     ICC_Async_SetTimings ();
    150 
    151 #ifdef DEBUG_PROTOCOL
    152   printf ("Protocol: T=1: IFSC=%d, IFSD=%d, CWT=%d, BWT=%d, BGT=%d, EDC=%s\n",
    153           t1->ifsc, t1->ifsd, t1->cwt, t1->bwt, t1->bgt,
    154           (t1->edc == PROTOCOL_T1_EDC_LRC) ? "LRC" : "CRC");
    155 #endif
    156 
    157   return PROTOCOL_T1_OK;
    158 }
    159 
    160 int
    161 Protocol_T1_Command (Protocol_T1 * t1, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     50Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    16251{
    16352  T1_Block *block;
     
    18372
    18473      /* Receive a block */
    185       ret = Protocol_T1_ReceiveBlock (t1, &block);
     74      ret = Protocol_T1_ReceiveBlock (&block);
    18675
    18776      if (ret == PROTOCOL_T1_OK)
     
    19483              /* Update IFSD value */
    19584              inf = (*T1_Block_GetInf (block));
    196               t1->ifsd = inf;
     85              ifsd = inf;
    19786#ifdef DEBUG_PROTOCOL
    19887              printf ("Protocol: Received block S(IFS response, %d)\n", inf);
     
    20695  /* Calculate the number of bytes to send */
    20796  counter = 0;
    208   bytes = MIN (APDU_Cmd_RawLen (cmd), t1->ifsc);
     97  bytes = MIN (APDU_Cmd_RawLen (cmd), ifsc);
    20998
    21099  /* See if chaining is needed */
    211   more = (APDU_Cmd_RawLen (cmd) > t1->ifsc);
     100  more = (APDU_Cmd_RawLen (cmd) > ifsc);
    212101
    213102  /* Increment ns */
    214   t1->ns = (t1->ns + 1) %2;
     103  ns = (ns + 1) %2;
    215104
    216105  /* Create an I-Block */
    217   block = T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd), t1->ns, more);
    218 
    219 #ifdef DEBUG_PROTOCOL
    220   printf ("Sending block I(%d,%d)\n", t1->ns, more);
     106  block = T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd), ns, more);
     107
     108#ifdef DEBUG_PROTOCOL
     109  printf ("Sending block I(%d,%d)\n", ns, more);
    221110#endif
    222111
     
    230119    {
    231120      /* Receive a block */
    232       ret = Protocol_T1_ReceiveBlock (t1, &block);
     121      ret = Protocol_T1_ReceiveBlock (&block);
    233122
    234123      if (ret == PROTOCOL_T1_OK)
     
    246135 
    247136              /* Increment ns  */
    248               t1->ns = (t1->ns + 1) % 2;
     137              ns = (ns + 1) % 2;
    249138
    250139              /* Calculate the number of bytes to send */
    251140              counter += bytes;
    252               bytes = MIN (APDU_Cmd_RawLen (cmd) - counter, t1->ifsc);
     141              bytes = MIN (APDU_Cmd_RawLen (cmd) - counter, ifsc);
    253142
    254143              /* See if chaining is needed */
    255               more = (APDU_Cmd_RawLen (cmd) - counter > t1->ifsc);
     144              more = (APDU_Cmd_RawLen (cmd) - counter > ifsc);
    256145
    257146              /* Create an I-Block */
    258147              block =
    259148                T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd) + counter,
    260                                     t1->ns, more);
    261 #ifdef DEBUG_PROTOCOL
    262               printf ("Protocol: Sending block I(%d,%d)\n", t1->ns, more);
     149                                    ns, more);
     150#ifdef DEBUG_PROTOCOL
     151              printf ("Protocol: Sending block I(%d,%d)\n", ns, more);
    263152#endif
    264153              /* Send a block */
     
    293182    {
    294183      if (wtx > 1)
    295         Protocol_T1_UpdateBWT (wtx * (t1->bwt));         
     184        Protocol_T1_UpdateBWT (wtx * (bwt));         
    296185
    297186      /* Receive a block */
    298       ret = Protocol_T1_ReceiveBlock (t1, &block);
     187      ret = Protocol_T1_ReceiveBlock (&block);
    299188
    300189      if (wtx > 1)
    301190        {
    302           Protocol_T1_UpdateBWT (t1->bwt);         
     191          Protocol_T1_UpdateBWT (bwt);         
    303192          wtx = 0;
    304193        }
     
    383272}
    384273
    385 int
    386 Protocol_T1_Close (Protocol_T1 * t1)
    387 {
    388   Protocol_T1_Clear (t1);
    389 
    390   return PROTOCOL_T1_OK;
    391 }
    392 
    393 void
    394 Protocol_T1_Delete (Protocol_T1 * t1)
    395 {
    396   free (t1);
    397 }
    398 
    399274/*
    400275 * Not exported functions definition
     
    425300
    426301static int
    427 Protocol_T1_ReceiveBlock (Protocol_T1 * t1, T1_Block ** block)
     302Protocol_T1_ReceiveBlock (T1_Block ** block)
    428303{
    429304  BYTE buffer[T1_BLOCK_MAX_SIZE];
     
    442317        {
    443318          /* Set timings to read the remaining block */
    444           Protocol_T1_UpdateBWT (t1->cwt);
     319          Protocol_T1_UpdateBWT (cwt);
    445320
    446321          /* Receive remaining bytes */
     
    459334
    460335          /* Restore timings */
    461           Protocol_T1_UpdateBWT (t1->bwt);
     336          Protocol_T1_UpdateBWT (bwt);
    462337        }
    463338      else
     
    469344
    470345  return ret;
    471 }
    472 
    473 static void
    474 Protocol_T1_Clear (Protocol_T1 * t1)
    475 {
    476   t1->ifsc = 0;
    477   t1->ifsd = 0;
    478   t1->bgt = 0;
    479   t1->bwt = 0;
    480   t1->cwt = 0;
    481   t1->edc = 0;
    482   t1->ns = 0;
    483346}
    484347
  • branches/smartreader/csctapi/protocol_t1.h

    r1280 r1290  
    4545 */
    4646
    47 /* T=1 Protocol context */
    48 typedef struct
    49 {
    50   unsigned short ifsc;  /* Information field size for the ICC */
    51   unsigned short ifsd;  /* Information field size for the IFD */
    52   unsigned short bgt;   /* Block guard time */
    53   unsigned short bwt;   /* Block waiting time */
    54   unsigned short cwt;   /* Character waiting time */
    55   int edc;              /* Type of error detection code */
    56   BYTE ns;              /* Send sequence number */
    57 }
    58 Protocol_T1;
    59 
     47unsigned short ifsc;  /* Information field size for the ICC */
     48unsigned short ifsd;  /* Information field size for the IFD */
     49unsigned short bgt;   /* Block guard time */
     50unsigned short bwt;   /* Block waiting time */
     51unsigned short cwt;   /* Character waiting time */
     52int edc;              /* Type of error detection code */
     53BYTE ns;              /* Send sequence number */
    6054/*
    6155 * Exported functions declaration
    6256 */
    6357
    64 /* Create a new protocol handler */
    65 extern Protocol_T1 *
    66 Protocol_T1_New (void);
    67 
    68 /* Delete a protocol handler */
    69 extern void
    70 Protocol_T1_Delete (Protocol_T1 * t1);
    71 
    7258/* Initialise a protocol handler */
    7359extern int
    74 Protocol_T1_Init (Protocol_T1 * t1, int selected_protocol);
     60Protocol_T1_Init ();
    7561
    7662/* Send a command and return a response */
    7763extern int
    78 Protocol_T1_Command (Protocol_T1 * t1, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    79 
    80 /* Close a protocol handler */
    81 extern int
    82 Protocol_T1_Close (Protocol_T1 * t1);
     64Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    8365
    8466#endif /* _PROTOCOL_T1_ */
  • branches/smartreader/oscam.c

    r1277 r1290  
    103103    cs_hw=CS_HW_DBOX2;          // dbox2, default for now
    104104    if (!stat("/dev/sci0", &st)) cs_hw=CS_HW_DREAM; // dreambox
     105#ifdef TRIPLEDRAGON
     106    if (!stat("/dev/stb/tdsc0", &st)) cs_hw=CS_HW_DRAGON; // tripledragon
     107#endif
    105108    switch(cs_hw)
    106109    {
     
    109112#endif
    110113      case CS_HW_DREAM: hw="dreambox"; break;
     114#ifdef TRIPLEDRAGON
     115      case CS_HW_DRAGON: hw="tripledragon"; break;
     116#endif
    111117    }
    112118#endif
Note: See TracChangeset for help on using the changeset viewer.