Changeset 3758 for trunk/reader-nagra.c
- Timestamp:
- 10/28/10 18:42:36 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/reader-nagra.c
r3729 r3758 664 664 } 665 665 666 static char *tiger_date(uint8_t *ndays, int offset, char *result) 667 { 668 struct tm tms; 669 670 memset(&tms, 0, sizeof(tms)); 671 tms.tm_year = 92; 672 tms.tm_mday = (ndays[0] << 8 | ndays[1]) + offset + 1; 673 mktime(&tms); 674 sprintf(result, "%02d/%02d/%04d", tms.tm_mday, tms.tm_mon + 1, tms.tm_year + 1900); 675 return result; 676 } 677 678 typedef struct 679 { 680 char date1[11]; 681 char date2[11]; 682 uint8_t type; 683 uint16_t value; 684 } ncmed_rec; 685 686 int reccmp(const void *r1, const void *r2) 687 { 688 int v1, v2, y, m, d; 689 sscanf(((ncmed_rec *)r1)->date1, "%02d/%02d/%04d", &d, &m, &y); 690 v1 = y * 372 + 1 + m * 31 + d; 691 sscanf(((ncmed_rec *)r2)->date1, "%02d/%02d/%04d", &d, &m, &y); 692 v2 = y * 372 + 1 + m * 31 + d; 693 return (v1 == v2) ? 0 : (v1 < v2) ? -1 : 1; 694 } 695 696 666 697 static int nagra2_card_info(struct s_reader * reader) 667 698 { … … 676 707 cs_ri_log(reader, "Prv.ID: %s",cs_hexdump (1,reader->prid[i],4)); 677 708 } 709 if (reader->nagra_read && reader->is_tiger && memcmp(reader->rom, "NCMED", 5) == 0) 710 { 711 ncmed_rec records[255]; 712 int num_records = 0; 713 uint8_t tier_cmd1[] = { 0x00, 0x00 }; 714 uint8_t tier_cmd2[] = { 0x01, 0x00 }; 715 def_resp; 716 int j; 717 do_cmd(reader, 0xD0, 0x04, 0xFF, 0x0A, tier_cmd1, cta_res, &cta_lr); 718 if (cta_lr == 0x0C) 719 { 720 //cs_ri_log(reader, "Expiry date : %s", tiger_date(&cta_res[5], 0, date1)); 721 int prepaid = 0; 722 int credit = 0; 723 for (i = 0; i < 32; ++i) 724 { 725 tier_cmd2[1] = i; 726 do_cmd(reader, 0xD0, 0x04, 0xFF, 0xAA, tier_cmd2, cta_res, &cta_lr); 727 if (cta_lr == 0xAC) 728 { 729 //cs_dump(cta_res, cta_lr, "NCMED Card Record #%d", i+1); 730 for (j = 2; j < cta_res[1] - 14; ++j) 731 { 732 if (cta_res[j] == 0x80 && cta_res[j+6] != 0x00) 733 { 734 int val_offs = 0; 735 tiger_date(&cta_res[j+6], 0, records[num_records].date2); 736 tiger_date(&cta_res[j+8], 0, records[num_records].date1); 737 switch (cta_res[j+1]) 738 { 739 case 0x00: 740 case 0x01: 741 val_offs = 4; 742 break; 743 case 0x80: 744 tiger_date(&cta_res[j+6], 0, records[num_records].date1); 745 val_offs = 11; 746 break; 747 case 0x21: 748 val_offs = 11; 749 break; 750 case 0x29: 751 val_offs = 11; 752 break; 753 default: 754 cs_ri_log(reader, "Unknown record : %s", cs_hexdump(1, &cta_res[j], 17)); 755 } 756 if (val_offs > 0) 757 { 758 records[num_records].type = cta_res[j+1]; 759 records[num_records++].value = cta_res[j+val_offs] << 8 | cta_res[j+val_offs+1]; 760 } 761 j += 16; 762 } 763 } 764 } 765 } 766 qsort(records, num_records, sizeof(ncmed_rec), reccmp); 767 768 int euro=0; 769 char *tier_name = NULL; 770 time_t rawtime; 771 struct tm * timeinfo; 772 time ( &rawtime ); 773 timeinfo = localtime ( &rawtime ); 774 char currdate[11]; 775 sprintf(currdate, "%02d/%02d/%04d", timeinfo->tm_mday, timeinfo->tm_mon+1, timeinfo->tm_year+1900); 776 777 for (i = 0; i < num_records; ++i) 778 { 779 if( (records[i].type == 0x00) || (records[i].type == 0x01) ) 780 { 781 tier_name = get_tiername(records[i].value, reader->caid[0]); 782 if( (reader->nagra_read == 2) && (reccmp(records[i].date2,currdate) >= 0) ) 783 cs_ri_log(reader, "tier: %04X, expiry date: %s %s", 784 records[i].value, records[i].date2, tier_name); 785 else if(reader->nagra_read == 1) 786 cs_ri_log(reader, "Activation : from %s to %s ( %04X ) %s", 787 records[i].date1, records[i].date2, records[i].value, tier_name); 788 } 789 } 790 791 for (i = 0; i < num_records; ++i) 792 { 793 switch (records[i].type) 794 { 795 case 0x80: 796 euro = (records[i].value / 100) - prepaid; 797 credit += euro; 798 prepaid += euro; 799 cs_ri_log(reader, "Recharge : %s (%3d euro)", 800 records[i].date1, euro); 801 break; 802 803 case 0x21: 804 euro = records[i].value / 100; 805 credit -= euro; 806 if( !( (reader->nagra_read == 2) && (reccmp(currdate,records[i].date2) == 1) ) ) 807 cs_ri_log(reader, "Subscription : from %s to %s (%3d euro)", 808 records[i].date1, records[i].date2, euro); 809 break; 810 811 case 0x29: 812 euro = records[i].value / 100; 813 credit -= euro; 814 cs_ri_log(reader, "Event purchase : %s (%3d euro)", 815 records[i].date1, euro); 816 break; 817 } 818 } 819 cs_ri_log(reader, "Credit : %3d euro", credit); 820 } 821 } 678 822 cs_log("[nagra-reader] ready for requests"); 679 823 return OK;
Note:
See TracChangeset
for help on using the changeset viewer.