Changeset 1306
- Timestamp:
- 01/20/10 19:11:15 (14 years ago)
- Location:
- branches/monitor-improvement
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/monitor-improvement/csctapi/icc_async.c
r1282 r1306 273 273 } 274 274 275 int ICC_Async_SetTimings () 276 { 277 /* if (protocol_type == ATR_PROTOCOL_TYPE_T1) 278 cs_debug("SetTimings: T1: chardelay %d, chartimeout CWT %d, blockdelay BGT??? %d, blocktimeout BWT %d",timings->char_delay,timings->char_timeout, timings->block_delay, timings->block_timeout); 279 else 280 cs_debug("SetTimings: T0/T14: chardelay %d, chartimeout WWT %d, blockdelay %d, blocktimeout %d",timings->char_delay,timings->char_timeout, timings->block_delay, timings->block_timeout);*/ 281 282 #ifdef SCI_DEV 283 #include <sys/ioctl.h> 284 #include "sci_global.h" 285 #include "sci_ioctl.h" 286 if (reader[ridx].typ == R_INTERNAL) { 287 SCI_PARAMETERS params; 288 if (ioctl(reader[ridx].handle, IOCTL_GET_PARAMETERS, ¶ms) < 0 ) 289 return ICC_ASYNC_IFD_ERROR; 290 switch (protocol_type) { 291 case ATR_PROTOCOL_TYPE_T1: 292 params.BWT = icc_timings.block_timeout; 293 params.CWT = icc_timings.char_timeout; 294 //params.BGT = icc_timings.block_delay; load into params.EGT?? 295 break; 296 case ATR_PROTOCOL_TYPE_T0: 297 case ATR_PROTOCOL_TYPE_T14: 298 default: 299 params.WWT = icc_timings.char_timeout; 300 break; 301 } 302 if (ioctl(reader[ridx].handle, IOCTL_SET_PARAMETERS, ¶ms)!=0) 303 return ICC_ASYNC_IFD_ERROR; 304 305 cs_debug("Set Timings: T=%d fs=%lu ETU=%d WWT=%d CWT=%d BWT=%d EGT=%d clock=%d check=%d P=%d I=%d U=%d", (int)params.T, params.fs, (int)params.ETU, (int)params.WWT, (int)params.CWT, (int)params.BWT, (int)params.EGT, (int)params.clock_stop_polarity, (int)params.check, (int)params.P, (int)params.I, (int)params.U); 306 } 307 #endif 275 int ICC_Async_SetTimings (unsigned short bwt) 276 { 277 if (protocol_type != ATR_PROTOCOL_TYPE_T1) 278 return ICC_ASYNC_IFD_ERROR; 279 280 //currently not supporting update BWT for T1 308 281 return ICC_ASYNC_OK; 309 282 } … … 317 290 } 318 291 319 int ICC_Async_GetBaudrate (unsigned long * baudrate)320 {321 (*baudrate) = reader[ridx].baudrate;322 return ICC_ASYNC_OK;323 }324 325 292 int ICC_Async_Transmit (unsigned size, BYTE * data) 326 293 { 327 294 BYTE *buffer = NULL, *sent; 328 IFD_Timings timings;329 295 330 296 if (convention == ATR_CONVENTION_INVERSE && reader[ridx].typ != R_INTERNAL) … … 340 306 } 341 307 342 timings.block_delay = icc_timings.block_delay;343 timings.char_delay = icc_timings.char_delay;344 345 308 #ifdef COOL 346 309 if (reader[ridx].typ == R_INTERNAL) { … … 350 313 else 351 314 #endif 352 if (!Phoenix_Transmit (sent, size, &timings, size))353 return ICC_ASYNC_IFD_ERROR; 354 355 if (convention == ATR_CONVENTION_INVERSE )315 if (!Phoenix_Transmit (sent, size, icc_timings.block_delay, icc_timings.char_delay)) 316 return ICC_ASYNC_IFD_ERROR; 317 318 if (convention == ATR_CONVENTION_INVERSE && reader[ridx].typ != R_INTERNAL) 356 319 free (buffer); 357 320 … … 361 324 int ICC_Async_Receive (unsigned size, BYTE * data) 362 325 { 363 IFD_Timings timings;364 365 timings.block_timeout = icc_timings.block_timeout;366 timings.char_timeout = icc_timings.char_timeout;367 368 326 #ifdef COOL 369 327 if (reader[ridx].typ == R_INTERNAL) { … … 373 331 else 374 332 #else 375 if (!Phoenix_Receive (data, size, &timings))333 if (!Phoenix_Receive (data, size, icc_timings.block_timeout, icc_timings.char_timeout)) 376 334 return ICC_ASYNC_IFD_ERROR; 377 335 #endif -
branches/monitor-improvement/csctapi/icc_async.h
r1282 r1306 58 58 } 59 59 ICC_Async_Timings; 60 /* 61 typedef struct 62 { 63 } 64 ICC_Async; 65 */ 60 66 61 ATR *atr; /* Answer to reset of this ICC */ 67 62 int convention; /* Convention of this ICC */ … … 78 73 79 74 /* Attributes */ 80 extern int ICC_Async_SetTimings ( );75 extern int ICC_Async_SetTimings (unsigned short bwt); 81 76 extern int ICC_Async_SetBaudrate (unsigned long baudrate); 82 extern int ICC_Async_GetBaudrate (unsigned long * baudrate);83 77 extern unsigned long ICC_Async_GetClockRate (); 84 78 -
branches/monitor-improvement/csctapi/ifd.h
r1268 r1306 5 5 6 6 #include "ifd_cool.h" 7 8 typedef struct9 {10 unsigned block_delay; /* Delay (ms) after starting to transmit */11 unsigned char_delay; /* Delay (ms) after transmiting sucesive chars */12 unsigned block_timeout; /* Max timeout (ms) to receive firtst char */13 unsigned char_timeout; /* Max timeout (ms) to receive sucesive characters */14 }15 IFD_Timings; //FIXME kill this -
branches/monitor-improvement/csctapi/ifd_phoenix.c
r1282 r1306 199 199 } 200 200 201 int Phoenix_Transmit (BYTE * buffer, unsigned size, IFD_Timings * timings)202 { 203 unsigned block_delay, char_delay,sent=0, to_send = 0;201 int Phoenix_Transmit (BYTE * buffer, unsigned size, unsigned int block_delay, unsigned int char_delay) 202 { 203 unsigned sent=0, to_send = 0; 204 204 205 205 #ifdef DEBUG_IFD … … 209 209 printf ("\n"); 210 210 #endif 211 212 #define IFD_TOWITOKO_DELAY 0213 214 /* Calculate delays */215 char_delay = IFD_TOWITOKO_DELAY + timings->char_delay;216 block_delay = IFD_TOWITOKO_DELAY + timings->block_delay;217 211 218 212 for (sent = 0; sent < size; sent = sent + to_send) … … 239 233 } 240 234 241 int Phoenix_Receive (BYTE * buffer, unsigned size, IFD_Timings * timings) 242 { 243 unsigned char_timeout, block_timeout; 244 #ifdef DEBUG_IFD 245 int i; 246 #endif 247 235 int Phoenix_Receive (BYTE * buffer, unsigned size, unsigned int block_timeout, unsigned int char_timeout) 236 { 248 237 #define IFD_TOWITOKO_TIMEOUT 1000 249 238 250 239 /* Calculate timeouts */ 251 char_timeout = IFD_TOWITOKO_TIMEOUT + timings->char_timeout;252 block_timeout = IFD_TOWITOKO_TIMEOUT + timings->block_timeout;240 char_timeout += IFD_TOWITOKO_TIMEOUT; 241 block_timeout += IFD_TOWITOKO_TIMEOUT; 253 242 if (block_timeout != char_timeout) 254 243 { … … 272 261 273 262 #ifdef DEBUG_IFD 263 int i; 274 264 printf ("IFD: Receive: "); 275 265 for (i = 0; i < size; i++) -
branches/monitor-improvement/csctapi/pps.c
r1291 r1306 66 66 67 67 static int PPS_InitICC (); 68 69 static int PPS_InitProtocol ();70 68 71 69 static BYTE PPS_GetPCK (BYTE * block, unsigned length); … … 272 270 273 271 protocol_type = parameters.t; 274 275 272 #ifdef DEBUG_PROTOCOL 276 273 printf("PPS: T=%i, F=%.0f, D=%.6f, N=%.0f\n", … … 281 278 #endif 282 279 283 ret = PPS_InitICC();284 285 if (ret != PPS_OK)286 return ret;287 288 280 /* Initialize selected protocol with selected parameters */ 289 return PPS_InitProtocol (); 281 // if (PPS_InitProtocol () != PPS_OK) 282 // return PPS_ICC_ERROR; 283 284 return PPS_InitICC(); 290 285 } 291 286 … … 407 402 } 408 403 404 unsigned int ETU_to_ms(unsigned long WWT) 405 { 406 #define CHAR_LEN 10L //character length in ETU, perhaps should be 9 when parity = none? 407 if (WWT > CHAR_LEN) 408 WWT -= CHAR_LEN; 409 else 410 WWT = 0; 411 double work_etu = 1000 / (double)reader[ridx].baudrate;//FIXME sometimes work_etu should be used, sometimes initial etu 412 return (unsigned int) WWT * work_etu; 413 } 414 415 409 416 static int PPS_InitICC () 410 417 { 418 unsigned long WWT, BWT, CWT, BGT, edc, EGT, CGT; 419 420 if (parameters.n == 255) //Extra Guard Time 421 EGT = 0; 422 else 423 EGT = parameters.n; 424 unsigned int GT = EGT + 12; //Guard Time in ETU 425 unsigned long gt_ms = ETU_to_ms(GT); 426 427 switch (parameters.t) { 428 case ATR_PROTOCOL_TYPE_T0: 429 case ATR_PROTOCOL_TYPE_T14: 430 { 431 BYTE wi; 432 /* Integer value WI = TC2, by default 10 */ 433 #ifndef PROTOCOL_T0_USE_DEFAULT_TIMINGS 434 if (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK) 435 #endif 436 wi = PROTOCOL_T0_DEFAULT_WI; 437 438 // WWT = 960 * WI * (Fi / f) * 1000 milliseconds 439 WWT = (unsigned long) 960 * wi; //in ETU 440 if (parameters.t == 14) 441 WWT >>= 1; //is this correct? 442 443 if (reader[ridx].typ != R_INTERNAL) { 444 unsigned long wwt_ms = ETU_to_ms(WWT); 445 446 icc_timings.block_timeout = wwt_ms; 447 icc_timings.char_timeout = wwt_ms; 448 icc_timings.block_delay = gt_ms; 449 icc_timings.char_delay = gt_ms; 450 cs_debug("Setting timings: block_timeout=%u ms, char_timeout=%u ms, block_delay=%u ms, char_delay=%u ms",icc_timings.block_timeout, icc_timings.char_timeout, icc_timings.block_delay, icc_timings.char_delay); 451 } 452 #ifdef DEBUG_PROTOCOL 453 printf ("Protocol: T=%i: WWT=%d, Clockrate=%lu\n", params->t, (int)(wwt),ICC_Async_GetClockRate()); 454 #endif 455 } 456 break; 457 case ATR_PROTOCOL_TYPE_T1: 458 { 459 BYTE ta, tb, tc, cwi, bwi; 460 461 // Set IFSC 462 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TA, &ta) == ATR_NOT_FOUND) 463 ifsc = PROTOCOL_T1_DEFAULT_IFSC; 464 else if ((ta != 0x00) && (ta != 0xFF)) 465 ifsc = ta; 466 else 467 ifsc = PROTOCOL_T1_DEFAULT_IFSC; 468 469 // Towitoko does not allow IFSC > 251 //FIXME not sure whether this limitation still exists 470 ifsc = MIN (ifsc, PROTOCOL_T1_MAX_IFSC); 471 472 // Set IFSD 473 ifsd = PROTOCOL_T1_DEFAULT_IFSD; 474 475 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS 476 // Calculate CWI and BWI 477 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TB, &tb) == ATR_NOT_FOUND) 478 { 479 #endif 480 cwi = PROTOCOL_T1_DEFAULT_CWI; 481 bwi = PROTOCOL_T1_DEFAULT_BWI; 482 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS 483 } 484 else 485 { 486 cwi = tb & 0x0F; 487 bwi = tb >> 4; 488 } 489 #endif 490 491 // Set CWT = (2^CWI + 11) work etu 492 CWT = (unsigned short) (((1<<cwi) + 11)); // in ETU 493 494 // Set BWT = (2^BWI * 960 + 11) work etu 495 BWT = (unsigned short) (((1<<bwi) * 960 + 11)); //in ETU 496 497 // Set BGT = 22 * work etu 498 BGT = 22L; //in ETU 499 500 if (parameters.n == 255) 501 CGT = 11L; //in ETU 502 else 503 CGT = GT; 504 505 // Set the error detection code type 506 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TC, &tc) == ATR_NOT_FOUND) 507 edc = PROTOCOL_T1_EDC_LRC; 508 else 509 edc = tc & 0x01; 510 511 // Set initial send sequence (NS) 512 ns = 1; 513 514 cs_debug ("Protocol: T=1: IFSC=%d, IFSD=%d, CWT=%d etu, BWT=%d etu, BGT=%d etu, EDC=%s\n", ifsc, ifsd, CWT, BWT, BGT, (edc == PROTOCOL_T1_EDC_LRC) ? "LRC" : "CRC"); 515 516 if (reader[ridx].typ != R_INTERNAL) { 517 icc_timings.block_timeout = ETU_to_ms(BWT); 518 icc_timings.char_timeout = ETU_to_ms(CWT); 519 icc_timings.block_delay = ETU_to_ms(BGT); 520 icc_timings.char_delay = ETU_to_ms(CGT); 521 cs_debug("Setting timings: block_timeout=%u ms, char_timeout=%u ms, block_delay=%u ms, char_delay=%u ms",icc_timings.block_timeout, icc_timings.char_timeout, icc_timings.block_delay, icc_timings.char_delay); 522 } 523 } 524 break; 525 default: 526 protocol = NULL; 527 return PPS_PROTOCOL_ERROR; 528 break; 529 } 530 411 531 #ifdef SCI_DEV 412 532 #include <sys/ioctl.h> … … 427 547 if (!(atr->hbn >= 6 && !memcmp(atr->hb, "IRDETO", 6) && params.T == 14)) 428 548 params.ETU = F / parameters.d; 429 if (parameters.n == 255) //only for T0 or also for T1?430 params.EGT = 0;431 else432 params.EGT = parameters.n;549 params.EGT = EGT; 550 params.WWT = WWT; 551 params.BWT = BWT; 552 params.CWT = CWT; 433 553 434 554 double a; … … 475 595 } 476 596 477 int Protocol_T1_Init ()478 {479 BYTE ta, tb, tc, cwi, bwi;480 unsigned long baudrate;481 double work_etu;482 483 // Set IFSC484 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 else489 ifsc = PROTOCOL_T1_DEFAULT_IFSC;490 491 // Towitoko does not allow IFSC > 251 //FIXME not sure whether this limitation still exists492 ifsc = MIN (ifsc, PROTOCOL_T1_MAX_IFSC);493 494 // Set IFSD495 ifsd = PROTOCOL_T1_DEFAULT_IFSD;496 497 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS498 // Calculate CWI and BWI499 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TB, &tb) == ATR_NOT_FOUND)500 {501 #endif502 cwi = PROTOCOL_T1_DEFAULT_CWI;503 bwi = PROTOCOL_T1_DEFAULT_BWI;504 #ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS505 }506 else507 {508 cwi = tb & 0x0F;509 bwi = tb >> 4;510 }511 #endif512 513 // Work etu = (1000 / baudrate) milliseconds514 ICC_Async_GetBaudrate (&baudrate);515 work_etu = 1000 / (double)baudrate;516 517 // Set CWT = (2^CWI + 11) work etu518 cwt = (unsigned short) (((1<<cwi) + 11) * work_etu);519 520 // Set BWT = (2^BWI * 960 + 11) work etu521 bwt = (unsigned short) (((1<<bwi) * 960 + 11) * work_etu);522 523 // Set BGT = 22 * work etu524 bgt = (unsigned short) (22 * work_etu);525 526 // Set the error detection code type527 if (ATR_GetInterfaceByte (atr, 3, ATR_INTERFACE_BYTE_TC, &tc) == ATR_NOT_FOUND)528 edc = PROTOCOL_T1_EDC_LRC;529 else530 edc = tc & 0x01;531 532 // Set initial send sequence (NS)533 ns = 1;534 535 // Set timings536 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_PROTOCOL542 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 #endif546 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_TIMINGS559 if (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)560 #endif561 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?568 569 /* Set timings */570 icc_timings.block_timeout = wwt;571 icc_timings.char_timeout = wwt;572 ICC_Async_SetTimings ();573 #ifdef DEBUG_PROTOCOL574 printf ("Protocol: T=%i: WWT=%d, Clockrate=%lu\n", params->t, (int)(wwt),ICC_Async_GetClockRate());575 #endif576 }577 break;578 case ATR_PROTOCOL_TYPE_T1:579 Protocol_T1_Init ();//always returns ok580 break;581 default:582 protocol = NULL;583 return PPS_PROTOCOL_ERROR;584 break;585 }586 return PPS_OK;587 }588 597 589 598 static BYTE PPS_GetPCK (BYTE * block, unsigned length) -
branches/monitor-improvement/csctapi/protocol_t1.c
r1291 r1306 349 349 Protocol_T1_UpdateBWT (unsigned short bwt) 350 350 { 351 icc_timings.block_timeout = bwt; 352 ICC_Async_SetTimings ();351 if (ICC_Async_SetTimings (bwt) != ICC_ASYNC_OK) 352 return PROTOCOL_T1_ICC_ERROR; 353 353 354 354 return PROTOCOL_T1_OK; -
branches/monitor-improvement/oscam.c
r1291 r1306 942 942 #ifdef USE_PTHREAD 943 943 pthread_t tid; 944 if ( i=pthread_create(&tid, (pthread_attr_t *)0, (void *) &cs_logger, (void *) 0))944 if ((i=pthread_create(&tid, (pthread_attr_t *)0, (void *) &cs_logger, (void *) 0))) 945 945 cs_log("ERROR: can't create logging-thread (err=%d)", i); 946 946 else -
branches/monitor-improvement/reader-videoguard2.c
r1140 r1306 15 15 int aes_active=0; 16 16 AES_KEY dkey, ekey; 17 17 int BASEYEAR = 1997; 18 18 static void cAES_SetKey(const unsigned char *key) 19 19 { … … 548 548 } 549 549 550 #define BASEYEAR 1997551 550 static void rev_date_calc(const unsigned char *Date, int *year, int *mon, int *day, int *hh, int *mm, int *ss) 552 551 { … … 597 596 unsigned char atr_kbw[] = { 0x3F, 0xFF, 0x14, 0x25, 0x03, 0x10, 0x80, 0x54, 0xB0, 0x01, 0x69, 0xFF, 0x4A, 0x50, 0x70, 0x00, 0x00, 0x4B, 0x57, 0x01, 0x00, 0x00}; 598 597 598 599 599 if ((atrsize == sizeof (atr_bskyb)) && (memcmp (atr, atr_bskyb, atrsize) == 0)) 600 600 { … … 602 602 /* BSkyB seems to need one additionnal byte in the serial communication... */ 603 603 io_serial_need_dummy_char = 1; 604 BASEYEAR = 2000; 604 605 } 605 606 else if ((atrsize == sizeof (atr_bskyb_new)) && (memcmp (atr, atr_bskyb_new, atrsize) == 0)) 606 607 { 607 608 cs_log("Type: Videoguard BSkyB - New"); 609 BASEYEAR = 2000; 608 610 } 609 611 else if ((atrsize == sizeof (atr_skyitalia)) && (memcmp (atr, atr_skyitalia, atrsize) == 0)) 610 612 { 611 613 cs_log("Type: Videoguard Sky Italia"); 614 BASEYEAR = 2000; 612 615 } 613 616 else if ((atrsize == sizeof (atr_directv)) && (memcmp (atr, atr_directv, atrsize) == 0)) … … 622 625 { 623 626 cs_log("Type: Videoguard Viasat new (093E)"); 627 BASEYEAR = 2000; 624 628 } 625 629 else if ((atrsize == sizeof (atr_viasat_scandinavia)) && (memcmp (atr, atr_viasat_scandinavia, atrsize) == 0)) 626 630 { 627 631 cs_log("Type: Videoguard Viasat Scandinavia"); 632 BASEYEAR = 2000; 628 633 } 629 634 else if ((atrsize == sizeof (atr_skyitalia93b)) && (memcmp (atr, atr_skyitalia93b, atrsize) == 0))
Note:
See TracChangeset
for help on using the changeset viewer.