Changeset 1290
- Timestamp:
- 01/19/10 16:48:50 (14 years ago)
- Location:
- branches/smartreader
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/smartreader/CMakeLists.txt
r1197 r1290 18 18 if (OSCAM_SYSTEM_NAME MATCHES "Tuxbox") 19 19 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") 20 24 set (CS_OS_HW "tuxbox") 21 25 set (CS_OS_SYS "linux") … … 92 96 elseif (OSCamOperatingSystem MATCHES "Tuxbox") 93 97 add_definitions ("-DOS_LINUX -DTUXBOX -DPPC") 98 set (DEFAULT_CS_CONFDIR "/var/tuxbox/config") 99 elseif (OSCamOperatingSystem MATCHES "TripleDragon") 100 add_definitions ("-DOS_LINUX -DTRIPLEDRAGON -DHAVE_DVBAPI -DSTB04SCI -DTUXBOX -DPPC") 94 101 set (DEFAULT_CS_CONFDIR "/var/tuxbox/config") 95 102 elseif (OSCamOperatingSystem MATCHES "NeutrinoHD") … … 231 238 elseif (OSCamOperatingSystem MATCHES "Tuxbox") 232 239 target_link_libraries ( ${exe_name} dl) 233 elseif (OSCamOperatingSystem MATCHES " NeutrinoHD")234 target_link_libraries ( ${exe_name} rt nxp)240 elseif (OSCamOperatingSystem MATCHES "TripleDragon") 241 target_link_libraries ( ${exe_name} dl) 235 242 elseif (OSCamOperatingSystem MATCHES "SlugOS") 236 243 elseif (OSCamOperatingSystem MATCHES "Fonera2") … … 238 245 elseif (OSCamOperatingSystem MATCHES "Amino") 239 246 elseif (OSCamOperatingSystem MATCHES "Windows/cygwin") 247 elseif (OSCamOperatingSystem MATCHES "NeutrinoHD") 248 target_link_libraries ( ${exe_name} rt nxp ) 240 249 endif (OSCamOperatingSystem MATCHES "Linux") 241 250 -
branches/smartreader/Makefile
r1158 r1290 12 12 freebsd: i386-pc-freebsd 13 13 tuxbox: cross-powerpc-tuxbox-linux 14 tripledragon: cross-powerpc-405-linux 14 15 win: cross-i386-pc-cygwin 15 16 cygwin: i386-pc-cygwin … … 20 21 cross-i386-pc-cygwin \ 21 22 cross-powerpc-tuxbox-linux \ 23 cross-powerpc-405-linux \ 22 24 cross-i386-pc-freebsd \ 23 25 cross-arm-nslu2-linux \ … … 108 110 OS_CULI="-lncurses" \ 109 111 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)\""'" \ 111 113 DS_CFLAGS="-c" \ 112 114 DS_LDFLAGS="-framework PCSC" \ … … 198 200 DS_ST=powerpc-tuxbox-linux-uclibc-strip 199 201 202 ###################################################################### 203 # 204 # TripleDragon crosscompiler 205 # 206 ###################################################################### 207 cross-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 200 222 201 223 ###################################################################### -
branches/smartreader/csctapi/ct_slot.c
r1280 r1290 117 117 char CT_Slot_Probe (CT_Slot * slot, BYTE * userdata, unsigned length) 118 118 { 119 PPS * pps;119 //PPS * pps; 120 120 BYTE buffer[PPS_MAX_LENGTH]; 121 121 unsigned buffer_len = 0; … … 138 138 if (slot->icc_type == CT_SLOT_ICC_ASYNC) 139 139 { 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) 143 148 { 144 149 ICC_Async_Close (); 145 150 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;163 151 slot->icc_type = CT_SLOT_NULL; 164 152 slot->protocol_type = CT_SLOT_NULL; … … 167 155 } 168 156 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; 174 158 } 175 159 … … 183 167 ret = OK; 184 168 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;208 169 slot->protocol_type = CT_SLOT_NULL; 209 170 … … 214 175 } 215 176 216 slot->icc = NULL;217 177 slot->icc_type = CT_SLOT_NULL; 218 178 … … 227 187 if (slot->protocol_type == CT_SLOT_PROTOCOL_T0) /* T=0 protocol ICC */ 228 188 { 229 if (Protocol_T0_Command ( 189 if (Protocol_T0_Command (cmd, rsp) != PROTOCOL_T0_OK) 230 190 ret = ERR_TRANS; 231 191 else … … 234 194 else if (slot->protocol_type == CT_SLOT_PROTOCOL_T1) /* T=1 protocol ICC */ 235 195 { 236 if (Protocol_T1_Command ( (Protocol_T1 *) slot->protocol,cmd, rsp) != PROTOCOL_T1_OK)196 if (Protocol_T1_Command (cmd, rsp) != PROTOCOL_T1_OK) 237 197 ret = ERR_TRANS; 238 198 else … … 241 201 else if (slot->protocol_type == CT_SLOT_PROTOCOL_T14) /* T=14 protocol ICC */ 242 202 { 243 if (Protocol_T14_Command (cmd, rsp) != PROTOCOL_T 14_OK)203 if (Protocol_T14_Command (cmd, rsp) != PROTOCOL_T0_OK) 244 204 ret = ERR_TRANS; 245 205 else … … 266 226 { 267 227 return slot->icc_type; 268 }269 270 void * CT_Slot_GetICC (CT_Slot * slot)271 {272 return slot->icc;273 228 } 274 229 … … 301 256 ret = OK; 302 257 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 325 258 if (slot->icc_type == CT_SLOT_ICC_ASYNC) 326 259 { … … 348 281 static void CT_Slot_Clear (CT_Slot * slot) 349 282 { 350 slot->icc = NULL;351 slot->protocol = NULL;352 283 slot->icc_type = CT_SLOT_NULL; 353 284 slot->protocol_type = CT_SLOT_NULL; -
branches/smartreader/csctapi/ct_slot.h
r1271 r1290 52 52 typedef struct 53 53 { 54 void * icc; /* Integrated circuit card */55 void * protocol; /* Protocol handler */56 54 int icc_type; /* Type of ICC */ 57 55 int protocol_type; /* Type of protocol */ … … 91 89 CT_Slot_GetICCType (CT_Slot * slot); 92 90 93 /* Return a reference to the ICC */94 extern void *95 CT_Slot_GetICC (CT_Slot * slot);96 97 91 /* Get answer to reset of the card */ 98 92 extern void * -
branches/smartreader/csctapi/pps.c
r1280 r1290 38 38 39 39 #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 41 49 /* 42 50 * Not exported macros definition … … 57 65 static unsigned PPS_GetLength (BYTE * block); 58 66 59 static int PPS_InitICC ( PPS * pps);60 61 static int PPS_InitProtocol ( PPS * pps, int protocol_selected);67 static int PPS_InitICC (); 68 69 static int PPS_InitProtocol (); 62 70 63 71 static BYTE PPS_GetPCK (BYTE * block, unsigned length); … … 67 75 */ 68 76 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) 77 void 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 86 int PPS_Perform (BYTE * params, unsigned *length) 88 87 { 89 88 //Performs PPS Exchange on command when *length >0 … … 110 109 if (ret == PPS_OK) 111 110 { 112 p ps->parameters.t = params[1] & 0x0F;111 parameters.t = params[1] & 0x0F; 113 112 114 113 if (PPS_HAS_PPS1 (params)) 115 114 { 116 p ps->parameters.FI = (params[2] >> 4);117 p ps->parameters.d = atr_d_table[(params[2] & 0x0F)];115 parameters.FI = (params[2] >> 4); 116 parameters.d = atr_d_table[(params[2] & 0x0F)]; 118 117 } 119 118 120 119 /* 121 ret = PPS_InitICC( pps);120 ret = PPS_InitICC(); 122 121 123 122 if (ret != PPS_OK) … … 186 185 187 186 //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, &(p ps->parameters.n));189 ATR_GetProtocolType(atr,1,&(p ps->parameters.t)); //get protocol from TD1187 ATR_GetParameter (atr, ATR_PARAMETER_N, &(parameters.n)); 188 ATR_GetProtocolType(atr,1,&(parameters.t)); //get protocol from TD1 190 189 BYTE TA2; 191 190 bool SpecificMode = (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TA, &TA2) == ATR_OK); //if TA2 present, specific mode, else negotiable mode 192 191 if (SpecificMode) { 193 p ps->parameters.t = TA2 & 0x0F;192 parameters.t = TA2 & 0x0F; 194 193 if ((TA2 & 0x10) != 0x10) { //bit 5 set to 0 means F and D explicitly defined in interface characters 195 194 BYTE TA1; 196 195 if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) { 197 p ps->parameters.FI = TA1 >> 4;198 ATR_GetParameter (atr, ATR_PARAMETER_D, &(p ps->parameters.d));196 parameters.FI = TA1 >> 4; 197 ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d)); 199 198 } 200 199 else { 201 p ps->parameters.FI = ATR_DEFAULT_FI;202 p ps->parameters.d = ATR_DEFAULT_D;200 parameters.FI = ATR_DEFAULT_FI; 201 parameters.d = ATR_DEFAULT_D; 203 202 } 204 203 } 205 204 else { 206 205 cs_log("Specific mode: speed 'implicitly defined', not sure how to proceed, assuming default values"); 207 p ps->parameters.FI = ATR_DEFAULT_FI;208 p ps->parameters.d = ATR_DEFAULT_D;209 } 210 cs_debug("Specific mode: T%i, F=%.0f, D=%.6f, N=%.0f\n", p ps->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); 211 210 } 212 211 else { //negotiable mode 213 212 214 bool NeedsPTS = ((p ps->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 PTS213 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 215 214 if (NeedsPTS) { 216 215 // PTSS PTS0 PTS1 PTS2 PTS3 PCK 217 216 // PTSS PTS0 PTS1 PCK 218 217 BYTE req[] = { 0xFF, 0x10, 0x00, 0x00 }; //we currently do not support PTS2, standard guardtimes 219 req[1]=0x10 | p ps->parameters.t; //PTS0 always flags PTS1 to be sent always218 req[1]=0x10 | parameters.t; //PTS0 always flags PTS1 to be sent always 220 219 if (ATR_GetInterfaceByte (atr, 1, ATR_INTERFACE_BYTE_TA, &req[2]) != ATR_OK) //PTS1 221 220 req[2] = 0x11; //defaults FI and DI to 1 … … 224 223 ret = PPS_Exchange (req, &len); 225 224 if (ret == PPS_OK) { 226 p ps->parameters.FI = req[2] >> 4;225 parameters.FI = req[2] >> 4; 227 226 BYTE DI = req[2] & 0x0F; 228 p ps->parameters.d = (double) (atr_d_table[DI]);227 parameters.d = (double) (atr_d_table[DI]); 229 228 PPS_success = TRUE; 230 cs_debug("PTS Succesfull, selected protocol: T%i, F=%.0f, D=%.6f, N=%.0f\n", p ps->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); 231 230 } 232 231 else … … 239 238 BYTE TA1; 240 239 if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) { 241 p ps->parameters.FI = TA1 >> 4;242 ATR_GetParameter (atr, ATR_PARAMETER_D, &(p ps->parameters.d));240 parameters.FI = TA1 >> 4; 241 ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d)); 243 242 } 244 243 else { //do not obey TA1 245 p ps->parameters.FI = ATR_DEFAULT_FI;246 p ps->parameters.d = ATR_DEFAULT_D;244 parameters.FI = ATR_DEFAULT_FI; 245 parameters.d = ATR_DEFAULT_D; 247 246 } 248 ATR_GetProtocolType (atr, 1, &(p ps->parameters.t));247 ATR_GetProtocolType (atr, 1, &(parameters.t)); 249 248 protocol_selected = 1; 250 249 251 250 if (NeedsPTS) { 252 if ((p ps->parameters.d == 32) || (pps->parameters.d == 12) || (pps->parameters.d == 20))253 p ps->parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this251 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 254 253 } 255 254 /////Here all non-ISO behaviour 256 255 /////End all non-ISO behaviour 257 256 258 cs_debug("No PTS %s, selected protocol T%i, F=%.0f, D=%.6f, N=%.0f\n", NeedsPTS?"happened":"needed", p ps->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); 259 258 } 260 259 }//end negotiable mode … … 262 261 263 262 //make sure no zero values 264 double F = (double) atr_f_table[p ps->parameters.FI];263 double F = (double) atr_f_table[parameters.FI]; 265 264 if (!F) { 266 p ps->parameters.FI = ATR_DEFAULT_FI;267 cs_log("Warning: F=0 is invalid, forcing FI=%d", p ps->parameters.FI);268 } 269 if (!p ps->parameters.d) {270 p ps->parameters.d = ATR_DEFAULT_D;271 cs_log("Warning: D=0 is invalid, forcing D=%.0f",p ps->parameters.d);272 } 273 274 protocol_type = p ps->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; 275 274 276 275 #ifdef DEBUG_PROTOCOL 277 276 printf("PPS: T=%i, F=%.0f, D=%.6f, N=%.0f\n", 278 p ps->parameters.t,277 parameters.t, 279 278 F, 280 p ps->parameters.d,281 p ps->parameters.n);282 #endif 283 284 ret = PPS_InitICC( pps);279 parameters.d, 280 parameters.n); 281 #endif 282 283 ret = PPS_InitICC(); 285 284 286 285 if (ret != PPS_OK) … … 288 287 289 288 /* 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 292 PPS_ProtocolParameters *PPS_GetProtocolParameters () 304 293 { 305 294 /* 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); 312 296 } 313 297 … … 423 407 } 424 408 425 static int PPS_InitICC ( PPS * pps)409 static int PPS_InitICC () 426 410 { 427 411 #ifdef SCI_DEV … … 437 421 return PPS_ICC_ERROR; 438 422 439 params.T = p ps->parameters.t;440 params.fs = atr_fs_table[p ps->parameters.FI] / 1000000;441 double F = (double) atr_f_table[p ps->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]; 442 426 //for Irdeto T14 cards, do not set ETU 443 427 if (!(atr->hbn >= 6 && !memcmp(atr->hb, "IRDETO", 6) && params.T == 14)) 444 params.ETU = F / p ps->parameters.d;445 if (p ps->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? 446 430 params.EGT = 0; 447 431 else 448 params.EGT = p ps->parameters.n;432 params.EGT = parameters.n; 449 433 450 434 double a; … … 462 446 #elif COOL 463 447 if(reader[ridx].typ == R_INTERNAL) { 464 int mhz = atr_fs_table[p ps->parameters.FI] / 10000;448 int mhz = atr_fs_table[parameters.FI] / 10000; 465 449 if (!Cool_SetBaudrate(mhz)) 466 450 return PPS_ICC_ERROR; … … 473 457 { 474 458 unsigned long baudrate; 475 double F = (double) atr_f_table[p ps->parameters.FI];476 if (p ps->parameters.t == 14)459 double F = (double) atr_f_table[parameters.FI]; 460 if (parameters.t == 14) 477 461 baudrate = 9600; 478 462 else 479 baudrate = p ps->parameters.d * ICC_Async_GetClockRate () / F;463 baudrate = parameters.d * ICC_Async_GetClockRate () / F; 480 464 481 465 #ifdef DEBUG_PROTOCOL … … 491 475 } 492 476 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) 477 int 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) 502 500 { 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 550 static 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? 504 568 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; 557 587 } 558 588 -
branches/smartreader/csctapi/pps.h
r1280 r1290 51 51 PPS_ProtocolParameters; 52 52 53 typedef struct 54 { 55 void *protocol; 56 PPS_ProtocolParameters parameters; 57 } 58 PPS; 53 void *protocol; 54 PPS_ProtocolParameters parameters; 59 55 60 56 /* … … 63 59 64 60 /* Create PPS context */ 65 extern PPS *PPS_New ();61 extern void PPS_New (); 66 62 67 63 /* 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); 64 extern int PPS_Perform (BYTE * params, unsigned *length); 72 65 73 66 /* Get protocol parameters */ 74 extern PPS_ProtocolParameters *PPS_GetProtocolParameters (PPS * pps); 75 76 /* Delete PPS context */ 77 extern void PPS_Delete (PPS * pps); 67 extern PPS_ProtocolParameters *PPS_GetProtocolParameters (); 78 68 79 69 #endif /* _PPS_ */ -
branches/smartreader/csctapi/protocol_t0.c
r1280 r1290 52 52 */ 53 53 54 static void Protocol_T0_Clear (Protocol_T0 * t0);55 static void Protocol_T14_Clear (Protocol_T14 * t14);56 57 54 static int Protocol_T0_Case1 (APDU_Cmd * cmd, APDU_Rsp ** rsp); 58 55 … … 77 74 * Exproted funtions definition 78 75 */ 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_TIMINGS110 if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)111 #endif112 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_PROTOCOL124 printf ("Protocol: T=0: WWT=%d, Clockrate=%lu\n", (int)(t0->wwt),ICC_Async_GetClockRate());125 #endif126 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_TIMINGS136 if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)137 #endif138 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_PROTOCOL151 printf ("Protocol: T=14: WWT=%d\n", (int)(t14->wwt));152 #endif153 154 return PROTOCOL_T14_OK;155 }156 76 157 77 int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp) … … 215 135 printf ("Protocol: T=14: Invalid APDU\n"); 216 136 #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; 245 141 } 246 142 … … 964 860 BYTE *cmd_raw; 965 861 long sent, recv, cmd_len; 966 int ret = PROTOCOL_T 14_OK, nulls, cmd_case;862 int ret = PROTOCOL_T0_OK, nulls, cmd_case; 967 863 BYTE ixor = 0x3E; 968 864 BYTE ixor1 = 0x3F; … … 979 875 /* Check case of command */ 980 876 if ((cmd_case != APDU_CASE_2S) && (cmd_case != APDU_CASE_3S)) 981 return PROTOCOL_T 14_ERROR;877 return PROTOCOL_T0_ERROR; 982 878 983 879 if (reader[ridx].typ != R_INTERNAL) … … 987 883 { 988 884 (*rsp) = NULL; 989 return PROTOCOL_T 14_ICC_ERROR;885 return PROTOCOL_T0_ICC_ERROR; 990 886 } 991 887 … … 994 890 { 995 891 (*rsp) = NULL; 996 return PROTOCOL_T 14_ICC_ERROR;892 return PROTOCOL_T0_ICC_ERROR; 997 893 } 998 894 … … 1001 897 { 1002 898 (*rsp) = NULL; 1003 return PROTOCOL_T 14_ICC_ERROR;899 return PROTOCOL_T0_ICC_ERROR; 1004 900 } 1005 901 } … … 1014 910 { 1015 911 (*rsp) = NULL; 1016 return PROTOCOL_T 14_ICC_ERROR;912 return PROTOCOL_T0_ICC_ERROR; 1017 913 } 1018 914 } … … 1050 946 if (ICC_Async_Receive (8, buffer) != ICC_ASYNC_OK) 1051 947 { 1052 ret = PROTOCOL_T 14_ICC_ERROR;948 ret = PROTOCOL_T0_ICC_ERROR; 1053 949 break; 1054 950 } … … 1061 957 if (ICC_Async_Receive (recv, buffer + 8) != ICC_ASYNC_OK) 1062 958 { 1063 ret = PROTOCOL_T 14_ICC_ERROR;959 ret = PROTOCOL_T0_ICC_ERROR; 1064 960 break; 1065 961 } … … 1068 964 if (ICC_Async_Receive (1, &ixor) != ICC_ASYNC_OK) 1069 965 { 1070 ret = PROTOCOL_T 14_ICC_ERROR;966 ret = PROTOCOL_T0_ICC_ERROR; 1071 967 break; 1072 968 } … … 1077 973 if(ixor1 != ixor) 1078 974 { 1079 ret = PROTOCOL_T 14_ERROR;975 ret = PROTOCOL_T0_ERROR; 1080 976 break; 1081 977 } … … 1084 980 1085 981 1086 ret = PROTOCOL_T 14_OK;982 ret = PROTOCOL_T0_OK; 1087 983 break; 1088 984 } 1089 985 } 1090 986 1091 if (ret == PROTOCOL_T 14_OK)987 if (ret == PROTOCOL_T0_OK) 1092 988 { 1093 989 memcpy(buffer + 8 + recv, buffer + 2, 2); … … 1101 997 return (ret); 1102 998 } 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 42 42 #define PROTOCOL_T0_ERROR 4 /* T=0 Protocol Error */ 43 43 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 51 44 /* 52 45 * Exported datatypes definition 53 46 */ 54 55 /* T=0 Protocol handler */56 typedef struct57 {58 unsigned long wwt; /* Work waiting time (ms) */59 }60 Protocol_T0;61 62 /* T=14 Protocol handler */63 typedef struct64 {65 unsigned long wwt; /* Work waiting time (ms) */66 }67 Protocol_T14;68 47 69 48 /* … … 71 50 */ 72 51 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 85 52 /* Send a command and return a response */ 86 53 extern int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp); 87 54 extern int Protocol_T14_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp); 88 55 89 /* Close a protocol handler */90 extern int Protocol_T0_Close (Protocol_T0 * t0);91 extern int Protocol_T14_Close (Protocol_T14 * t14);92 93 56 #endif /* _PROTOCOL_T0_ */ 94 57 -
branches/smartreader/csctapi/protocol_t1.c
r1280 r1290 31 31 32 32 /* 33 * Not exported constants definition34 */35 #define PROTOCOL_T1_DEFAULT_IFSC 3236 #define PROTOCOL_T1_DEFAULT_IFSD 3237 #define PROTOCOL_T1_MAX_IFSC 251 /* Cannot send > 255 buffer */38 #define PROTOCOL_T1_DEFAULT_CWI 1339 #define PROTOCOL_T1_DEFAULT_BWI 440 #define PROTOCOL_T1_EDC_LRC 041 #define PROTOCOL_T1_EDC_CRC 142 43 /*44 33 * Not exported functions declaration 45 34 */ 46 35 47 static void48 Protocol_T1_Clear (Protocol_T1 * t1);49 50 36 static int 51 37 Protocol_T1_SendBlock (T1_Block * block); 52 38 53 39 static int 54 Protocol_T1_ReceiveBlock ( Protocol_T1 * t1,T1_Block ** block);40 Protocol_T1_ReceiveBlock (T1_Block ** block); 55 41 56 42 static int … … 61 47 */ 62 48 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 76 49 int 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) 50 Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp) 162 51 { 163 52 T1_Block *block; … … 183 72 184 73 /* Receive a block */ 185 ret = Protocol_T1_ReceiveBlock ( t1,&block);74 ret = Protocol_T1_ReceiveBlock (&block); 186 75 187 76 if (ret == PROTOCOL_T1_OK) … … 194 83 /* Update IFSD value */ 195 84 inf = (*T1_Block_GetInf (block)); 196 t1->ifsd = inf;85 ifsd = inf; 197 86 #ifdef DEBUG_PROTOCOL 198 87 printf ("Protocol: Received block S(IFS response, %d)\n", inf); … … 206 95 /* Calculate the number of bytes to send */ 207 96 counter = 0; 208 bytes = MIN (APDU_Cmd_RawLen (cmd), t1->ifsc);97 bytes = MIN (APDU_Cmd_RawLen (cmd), ifsc); 209 98 210 99 /* See if chaining is needed */ 211 more = (APDU_Cmd_RawLen (cmd) > t1->ifsc);100 more = (APDU_Cmd_RawLen (cmd) > ifsc); 212 101 213 102 /* Increment ns */ 214 t1->ns = (t1->ns + 1) %2;103 ns = (ns + 1) %2; 215 104 216 105 /* 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); 221 110 #endif 222 111 … … 230 119 { 231 120 /* Receive a block */ 232 ret = Protocol_T1_ReceiveBlock ( t1,&block);121 ret = Protocol_T1_ReceiveBlock (&block); 233 122 234 123 if (ret == PROTOCOL_T1_OK) … … 246 135 247 136 /* Increment ns */ 248 t1->ns = (t1->ns + 1) % 2;137 ns = (ns + 1) % 2; 249 138 250 139 /* Calculate the number of bytes to send */ 251 140 counter += bytes; 252 bytes = MIN (APDU_Cmd_RawLen (cmd) - counter, t1->ifsc);141 bytes = MIN (APDU_Cmd_RawLen (cmd) - counter, ifsc); 253 142 254 143 /* See if chaining is needed */ 255 more = (APDU_Cmd_RawLen (cmd) - counter > t1->ifsc);144 more = (APDU_Cmd_RawLen (cmd) - counter > ifsc); 256 145 257 146 /* Create an I-Block */ 258 147 block = 259 148 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); 263 152 #endif 264 153 /* Send a block */ … … 293 182 { 294 183 if (wtx > 1) 295 Protocol_T1_UpdateBWT (wtx * ( t1->bwt));184 Protocol_T1_UpdateBWT (wtx * (bwt)); 296 185 297 186 /* Receive a block */ 298 ret = Protocol_T1_ReceiveBlock ( t1,&block);187 ret = Protocol_T1_ReceiveBlock (&block); 299 188 300 189 if (wtx > 1) 301 190 { 302 Protocol_T1_UpdateBWT ( t1->bwt);191 Protocol_T1_UpdateBWT (bwt); 303 192 wtx = 0; 304 193 } … … 383 272 } 384 273 385 int386 Protocol_T1_Close (Protocol_T1 * t1)387 {388 Protocol_T1_Clear (t1);389 390 return PROTOCOL_T1_OK;391 }392 393 void394 Protocol_T1_Delete (Protocol_T1 * t1)395 {396 free (t1);397 }398 399 274 /* 400 275 * Not exported functions definition … … 425 300 426 301 static int 427 Protocol_T1_ReceiveBlock ( Protocol_T1 * t1,T1_Block ** block)302 Protocol_T1_ReceiveBlock (T1_Block ** block) 428 303 { 429 304 BYTE buffer[T1_BLOCK_MAX_SIZE]; … … 442 317 { 443 318 /* Set timings to read the remaining block */ 444 Protocol_T1_UpdateBWT ( t1->cwt);319 Protocol_T1_UpdateBWT (cwt); 445 320 446 321 /* Receive remaining bytes */ … … 459 334 460 335 /* Restore timings */ 461 Protocol_T1_UpdateBWT ( t1->bwt);336 Protocol_T1_UpdateBWT (bwt); 462 337 } 463 338 else … … 469 344 470 345 return ret; 471 }472 473 static void474 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;483 346 } 484 347 -
branches/smartreader/csctapi/protocol_t1.h
r1280 r1290 45 45 */ 46 46 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 47 unsigned short ifsc; /* Information field size for the ICC */ 48 unsigned short ifsd; /* Information field size for the IFD */ 49 unsigned short bgt; /* Block guard time */ 50 unsigned short bwt; /* Block waiting time */ 51 unsigned short cwt; /* Character waiting time */ 52 int edc; /* Type of error detection code */ 53 BYTE ns; /* Send sequence number */ 60 54 /* 61 55 * Exported functions declaration 62 56 */ 63 57 64 /* Create a new protocol handler */65 extern Protocol_T1 *66 Protocol_T1_New (void);67 68 /* Delete a protocol handler */69 extern void70 Protocol_T1_Delete (Protocol_T1 * t1);71 72 58 /* Initialise a protocol handler */ 73 59 extern int 74 Protocol_T1_Init ( Protocol_T1 * t1, int selected_protocol);60 Protocol_T1_Init (); 75 61 76 62 /* Send a command and return a response */ 77 63 extern 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); 64 Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp); 83 65 84 66 #endif /* _PROTOCOL_T1_ */ -
branches/smartreader/oscam.c
r1277 r1290 103 103 cs_hw=CS_HW_DBOX2; // dbox2, default for now 104 104 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 105 108 switch(cs_hw) 106 109 { … … 109 112 #endif 110 113 case CS_HW_DREAM: hw="dreambox"; break; 114 #ifdef TRIPLEDRAGON 115 case CS_HW_DRAGON: hw="tripledragon"; break; 116 #endif 111 117 } 112 118 #endif
Note:
See TracChangeset
for help on using the changeset viewer.