1 | #include "globals.h"
|
---|
2 | #include "reader-common.h"
|
---|
3 | #include "reader-videoguard-common.h"
|
---|
4 |
|
---|
5 | ////// ====================================================================================
|
---|
6 | int VG12_BASEYEAR = 1997;
|
---|
7 |
|
---|
8 | static const unsigned short NdTabB001[0x15][0x20]= {
|
---|
9 | { 0xEAF1,0x0237,0x29D0,0xBAD2,0xE9D3,0x8BAE,0x2D6D,0xCD1B,0x538D,0xDE6B,0xA634,0xF81A,0x18B5,0x5087,0x14EA,0x672E,
|
---|
10 | 0xF0FC,0x055E,0x62E5,0xB78F,0x5D09,0x0003,0xE4E8,0x2DCE,0x6BE0,0xAC4E,0xF485,0x6967,0xF28C,0x97A0,0x01EF,0x0100 },
|
---|
11 | { 0xC539,0xF5B9,0x9099,0x013A,0xD4B9,0x6AB5,0xEA67,0x7EB4,0x6C30,0x4BF0,0xB810,0xB0B5,0xB76D,0xA751,0x1AE7,0x14CA,
|
---|
12 | 0x4F4F,0x1586,0x2608,0x10B1,0xE7E1,0x48BE,0x7DDD,0x5ECB,0xCFBF,0x323B,0x8B31,0xB131,0x0F1A,0x664B,0x0140,0x0100 },
|
---|
13 | { 0x3C7D,0xBDC4,0xFEC7,0x26A6,0xB0A0,0x6E55,0xF710,0xF9BF,0x0023,0xE81F,0x41CA,0xBE32,0xB461,0xE92D,0xF1AF,0x409F,
|
---|
14 | 0xFC85,0xFE5B,0x7FCE,0x17F5,0x01AB,0x4A46,0xEB05,0xA251,0xDC6F,0xF0C0,0x10F0,0x1D51,0xEFAA,0xE9BF,0x0100,0x0100 },
|
---|
15 | { 0x1819,0x0CAA,0x9067,0x607A,0x7576,0x1CBC,0xE51D,0xBF77,0x7EC6,0x839E,0xB695,0xF096,0xDC10,0xCB69,0x4654,0x8E68,
|
---|
16 | 0xD62D,0x4F1A,0x4227,0x92AC,0x9064,0x6BD1,0x1E75,0x2747,0x00DA,0xA6A6,0x6CF1,0xD151,0xBE56,0x3E33,0x0128,0x0100 },
|
---|
17 | { 0x4091,0x09ED,0xD494,0x6054,0x1869,0x71D5,0xB572,0x7BF1,0xE925,0xEE2D,0xEEDE,0xA13C,0x6613,0x9BAB,0x122D,0x7AE4,
|
---|
18 | 0x5268,0xE6C9,0x50CB,0x79A1,0xF212,0xA062,0x6B48,0x70B3,0xF6B0,0x06D5,0xF8AB,0xECF5,0x6255,0xEDD8,0x79D2,0x290A },
|
---|
19 | { 0xD3CF,0x014E,0xACB3,0x8F6B,0x0F2C,0xA5D8,0xE8E0,0x863D,0x80D5,0x5705,0x658A,0x8BC2,0xEE46,0xD3AE,0x0199,0x0100,
|
---|
20 | 0x4A35,0xABE4,0xF976,0x935A,0xA8A5,0xBAE9,0x24D0,0x71AA,0xB3FE,0x095E,0xAB06,0x4CD5,0x2F0D,0x1ACB,0x59F3,0x4C50 },
|
---|
21 | { 0xFD27,0x0F8E,0x191A,0xEEE7,0x2F49,0x3A05,0x3267,0x4F88,0x38AE,0xFCE9,0x9476,0x18C6,0xF961,0x4EF0,0x39D0,0x42E6,
|
---|
22 | 0xB747,0xE625,0xB68E,0x5100,0xF92A,0x86FE,0xE79B,0xEE91,0x21D5,0x4C3C,0x683D,0x5AD1,0x1B49,0xF407,0x0194,0x0100 },
|
---|
23 | { 0x4BF9,0xDC0D,0x9478,0x5174,0xCB4A,0x8A89,0x4D6A,0xFED8,0xF123,0xA8CD,0xEEE7,0xA6D1,0xB763,0xF5E2,0xE085,0x01EF,
|
---|
24 | 0xE466,0x9FA3,0x2F68,0x2190,0x423F,0x287F,0x7F3F,0x09F6,0x2111,0xA963,0xD0BB,0x674A,0xBA72,0x45F9,0xF186,0xB8F5 },
|
---|
25 | { 0x0010,0xD1B9,0xB164,0x9E87,0x1F49,0x6950,0x2DBF,0x38D3,0x2EB0,0x3E8E,0x91E6,0xF688,0x7E41,0x566E,0x01B0,0x0100,
|
---|
26 | 0x24A1,0x73D8,0xA0C3,0xF71B,0xA0A5,0x2A06,0xBA46,0xFEC3,0xDD4C,0x52CC,0xF9BC,0x3B7E,0x3812,0x0666,0xB74B,0x40F8 },
|
---|
27 | { 0x28F2,0x7C81,0xFC92,0x6FBD,0x53D6,0x72A3,0xBBDF,0xB6FC,0x9CE5,0x2331,0xD4F6,0xC5BB,0xE8BB,0x6676,0x02D9,0x2F0E,
|
---|
28 | 0xD009,0xD136,0xCD09,0x7551,0x1826,0x9D9B,0x63EA,0xFC63,0x68CD,0x3672,0xCB95,0xD28E,0xF1CD,0x20CA,0x014C,0x0100 },
|
---|
29 | { 0xE539,0x55B7,0x989D,0x21C4,0x463A,0xE68F,0xF8B5,0xE5C5,0x662B,0x35BF,0x3C50,0x0131,0xF4BF,0x38B2,0x41BC,0xB829,
|
---|
30 | 0x02B7,0x6B8F,0xA25C,0xAFD2,0xD84A,0x2243,0x53EB,0xC6C9,0x2E14,0x181F,0x8F96,0xDF0E,0x0D4C,0x30F6,0xFFE1,0x9DDA },
|
---|
31 | { 0x30B6,0x777E,0xDA3D,0xAF77,0x205E,0xC90B,0x856B,0xB451,0x3BCC,0x76C2,0x8ACF,0xDCB1,0xA5E5,0xDD64,0x0197,0x0100,
|
---|
32 | 0xE751,0xB661,0x0404,0xDB4A,0xE9DD,0xA400,0xAF26,0x3F5E,0x904B,0xA924,0x09E0,0xE72B,0x825B,0x2C50,0x6FD0,0x0D52 },
|
---|
33 | { 0x2730,0xC2BA,0x9E44,0x5815,0xFC47,0xB21D,0x67B8,0xF8B9,0x047D,0xB0AF,0x9F14,0x741B,0x4668,0xBE54,0xDE16,0xDB14,
|
---|
34 | 0x7CB7,0xF2B8,0x0683,0x762C,0x09A0,0x9507,0x7F92,0x022C,0xBA6A,0x7D52,0x0AF4,0x1BC3,0xB46A,0xC4FD,0x01C2,0x0100 },
|
---|
35 | { 0x7611,0x66F3,0xEE87,0xEDD3,0xC559,0xEFD4,0xDC59,0xF86B,0x6D1C,0x1C85,0x9BB1,0x3373,0x763F,0x4EBE,0x1BF3,0x99B5,
|
---|
36 | 0xD721,0x978F,0xCF5C,0xAC51,0x0984,0x7462,0x8F0C,0x2817,0x4AD9,0xFD41,0x6678,0x7C85,0xD330,0xC9F8,0x1D9A,0xC622 },
|
---|
37 | { 0x5AE4,0xE16A,0x60F6,0xFD45,0x668C,0x29D6,0x0285,0x6B92,0x92C2,0x21DE,0x45E0,0xEF3D,0x8B0D,0x02CD,0x0198,0x0100,
|
---|
38 | 0x9E6D,0x4D38,0xDEF9,0xE6F2,0xF72E,0xB313,0x14F2,0x390A,0x2D67,0xC71E,0xCB69,0x7F66,0xD3CF,0x7F8A,0x81D9,0x9DDE },
|
---|
39 | { 0x85E3,0x8F29,0x36EB,0xC968,0x3696,0x59F6,0x7832,0xA78B,0xA1D8,0xF5CF,0xAB64,0x646D,0x7A2A,0xBAF8,0xAA87,0x41C7,
|
---|
40 | 0x5120,0xDE78,0x738D,0xDC1A,0x268D,0x5DF8,0xED69,0x1C8A,0xBC85,0x3DCD,0xAE30,0x0F8D,0xEC89,0x3ABD,0x0166,0x0100 },
|
---|
41 | { 0xB8BD,0x643B,0x748E,0xBD63,0xEC6F,0xE23A,0x9493,0xDD76,0x0A62,0x774F,0xCD68,0xA67A,0x9A23,0xC8A8,0xBDE5,0x9D1B,
|
---|
42 | 0x2B86,0x8B36,0x5428,0x1DFB,0xCD1D,0x0713,0x29C2,0x8E8E,0x5207,0xA13F,0x6005,0x4F5E,0x52E0,0xE7C8,0x6D1C,0x3E34 },
|
---|
43 | { 0x581D,0x2BFA,0x5E1D,0xA891,0x1069,0x1DA4,0x39A0,0xBE45,0x5B9A,0x7333,0x6F3E,0x8637,0xA550,0xC9E9,0x5C6C,0x42BA,
|
---|
44 | 0xA712,0xC3EA,0x3808,0x0910,0xAA4D,0x5B25,0xABCD,0xE680,0x96AD,0x2CEC,0x8EBB,0xA47D,0x1690,0xE8FB,0x01C8,0x0100 },
|
---|
45 | { 0x73B9,0x82BC,0x9EBC,0xB130,0x0DA5,0x8617,0x9F7B,0x9766,0x205D,0x752D,0xB05C,0x2A17,0xA75C,0x18EF,0x8339,0xFD34,
|
---|
46 | 0x8DA2,0x7970,0xD0B4,0x70F1,0x3765,0x7380,0x7CAF,0x570E,0x6440,0xBC44,0x0743,0x2D02,0x0419,0xA240,0x2113,0x1AD4 },
|
---|
47 | { 0x1EB5,0xBBFF,0x39B1,0x3209,0x705F,0x15F4,0xD7AD,0x340B,0xC2A6,0x25CA,0xF412,0x9570,0x0F4F,0xE4D5,0x1614,0xE464,
|
---|
48 | 0x911A,0x0F0E,0x07DA,0xA929,0x2379,0xD988,0x0AA6,0x3B57,0xBF63,0x71FB,0x72D5,0x26CE,0xB0AF,0xCF45,0x011B,0x0100 },
|
---|
49 | { 0x9999,0x98FE,0xA108,0x6588,0xF90B,0x4554,0xFF38,0x4642,0x8F5F,0x6CC3,0x4E8E,0xFF7E,0x64C2,0x50CA,0x0E7F,0xAD7D,
|
---|
50 | 0x6AAB,0x33C1,0xE1F4,0x6165,0x7894,0x83B9,0x0A0C,0x38AF,0x5803,0x18C0,0xFA36,0x592C,0x4548,0xABB8,0x1527,0xAEE9 }
|
---|
51 |
|
---|
52 | };
|
---|
53 |
|
---|
54 | static const unsigned short Hash3[] = {0x0123,0x4567,0x89AB,0xCDEF,0xF861,0xCB52};
|
---|
55 | static const unsigned char Hash4[] = {0x0B,0x04,0x07,0x08,0x05,0x09,0x0B,0x0A,0x07,0x02,0x0A,0x05,0x04,0x08,0x0D,0x0F};
|
---|
56 |
|
---|
57 |
|
---|
58 |
|
---|
59 | ////// ====================================================================================
|
---|
60 |
|
---|
61 | static void read_tiers(struct s_reader * reader)
|
---|
62 | {
|
---|
63 | def_resp;
|
---|
64 | static const unsigned char ins2a[5] = { 0x48,0x2a,0x00,0x00,0x00 };
|
---|
65 | int l;
|
---|
66 | l=do_cmd(reader, ins2a,NULL,NULL,cta_res);
|
---|
67 | if(l<0 || !status_ok(cta_res+l)) return;
|
---|
68 | static unsigned char ins76[5] = { 0x48,0x76,0x00,0x00,0x00 };
|
---|
69 | ins76[3]=0x7f; ins76[4]=2;
|
---|
70 | if(!write_cmd_vg(ins76,NULL) || !status_ok(cta_res+2)) return;
|
---|
71 | ins76[3]=0; ins76[4]=0;
|
---|
72 | int num=cta_res[1];
|
---|
73 | int i;
|
---|
74 | #ifdef CS_RDR_INIT_HIST
|
---|
75 | reader->init_history_pos = 0; //reset for re-read
|
---|
76 | memset(reader->init_history, 0, sizeof(reader->init_history));
|
---|
77 | #endif
|
---|
78 | for(i=0; i<num; i++) {
|
---|
79 | ins76[2]=i;
|
---|
80 | l=do_cmd(reader, ins76,NULL,NULL,cta_res);
|
---|
81 | if(l<0 || !status_ok(cta_res+l)) return;
|
---|
82 | if(cta_res[2]==0 && cta_res[3]==0) break;
|
---|
83 | int y,m,d,H,M,S;
|
---|
84 | rev_date_calc(&cta_res[4],&y,&m,&d,&H,&M,&S,VG12_BASEYEAR);
|
---|
85 | unsigned short tier_id = (cta_res[2] << 8) | cta_res[3];
|
---|
86 | char *tier_name = get_tiername(tier_id, reader->caid[0]);
|
---|
87 | cs_ri_log(reader, "[videoguard12-reader] tier: %04x, expiry date: %04d/%02d/%02d-%02d:%02d:%02d %s",tier_id,y,m,d,H,M,S,tier_name);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | int videoguard12_card_init(struct s_reader * reader, ATR newatr)
|
---|
92 | {
|
---|
93 |
|
---|
94 | /* known atrs */
|
---|
95 | NDS_ATR_ENTRY nds12_atr_table[]={ // {atr}, atr len, base year, description
|
---|
96 | {{ 0x3F, 0x78, 0x13, 0x25, 0x03, 0x40, 0xB0, 0x20, 0xFF, 0xFF, 0x4A, 0x50, 0x00 }, 13, 1997, NDS12, "VideoGuard DirecTV"},
|
---|
97 | {{0},0,0,0,NULL},
|
---|
98 | };
|
---|
99 |
|
---|
100 | get_hist;
|
---|
101 | if ((hist_size < 7) || (hist[1] != 0xB0) || (hist[4] != 0xFF) || (hist[5] != 0x4A) || (hist[6] != 0x50))
|
---|
102 | return ERROR;
|
---|
103 | get_atr;
|
---|
104 | def_resp;
|
---|
105 |
|
---|
106 | int i=0;
|
---|
107 | while(nds12_atr_table[i].desc) {
|
---|
108 | if ((atr_size == nds12_atr_table[i].atr_len) && (memcmp (atr, nds12_atr_table[i].atr, atr_size) == 0)) {
|
---|
109 | VG12_BASEYEAR=nds12_atr_table[i].base_year;
|
---|
110 | cs_ri_log(reader, "[videoguard12-reader] type: %s", nds12_atr_table[i].desc);
|
---|
111 | break;
|
---|
112 | }
|
---|
113 | i++;
|
---|
114 | }
|
---|
115 | if(!nds12_atr_table[i].desc)
|
---|
116 | return ERROR; // unknown ATR... probably not NDS1+
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | //a non videoguard2/NDS card will fail on read_cmd_len(ins7401)
|
---|
121 | //this way also unknown videoguard2/NDS cards will work
|
---|
122 |
|
---|
123 | int l = 0;
|
---|
124 |
|
---|
125 | /*
|
---|
126 | unsigned char ins7401[5] = { 0x48,0x74,0x01,0x00,0x00 };
|
---|
127 | ins7401[3]=0x80; // from newcs log
|
---|
128 | ins7401[4]=0x01;
|
---|
129 | if((l=read_cmd_len(reader, ins7401))<0) return ERROR; //not a videoguard2/NDS card or communication error
|
---|
130 | ins7401[3]=0x00;
|
---|
131 | ins7401[4]=l;
|
---|
132 | if(!write_cmd_vg(ins7401,NULL) || !status_ok(cta_res+l)) {
|
---|
133 | cs_log ("[videoguard12-reader] failed to read cmd list");
|
---|
134 | return ERROR;
|
---|
135 | }
|
---|
136 |
|
---|
137 | memorize_cmd_table (cta_res,l);
|
---|
138 | */
|
---|
139 |
|
---|
140 | unsigned char dummy_cmd_table[132] = {
|
---|
141 | 0x01, 0x82, 0x20, 0x01,
|
---|
142 | 0x48, 0x0E, 0xFF, 0x02,
|
---|
143 | 0x48, 0x18, 0x0C, 0x01,
|
---|
144 | 0x48, 0x1A, 0x08, 0x03,
|
---|
145 | 0x48, 0x1E, 0x09, 0x03,
|
---|
146 | 0x48, 0x2E, 0xFF, 0x00,
|
---|
147 | 0x48, 0x32, 0x01, 0x01,
|
---|
148 | 0x48, 0x36, 0xFF, 0x02,
|
---|
149 | 0x48, 0x38, 0x02, 0x03,
|
---|
150 | 0x48, 0x40, 0xFF, 0x00,
|
---|
151 | 0x48, 0x42, 0xFF, 0x00,
|
---|
152 | 0x48, 0x44, 0x35, 0x01,
|
---|
153 | 0x48, 0x46, 0xFF, 0x00,
|
---|
154 | 0x48, 0x4A, 0xFF, 0x00,
|
---|
155 | 0x48, 0x4C, 0x09, 0x01,
|
---|
156 | 0x48, 0x4E, 0x05, 0x03,
|
---|
157 | 0x48, 0x50, 0xFF, 0x02,
|
---|
158 | 0x48, 0x54, 0x2C, 0x03,
|
---|
159 | 0x48, 0x56, 0xFF, 0x02,
|
---|
160 | 0x48, 0x58, 0x4A, 0x03,
|
---|
161 | 0x48, 0x5A, 0xFF, 0x02,
|
---|
162 | 0x48, 0x5C, 0x04, 0x03,
|
---|
163 | 0x48, 0x5E, 0xFF, 0x02,
|
---|
164 | 0x48, 0x70, 0x25, 0x03,
|
---|
165 | 0x48, 0x72, 0x23, 0x03,
|
---|
166 | 0x48, 0x74, 0xFF, 0x02,
|
---|
167 | 0x48, 0x76, 0x0A, 0x03,
|
---|
168 | 0x48, 0x78, 0x18, 0x03,
|
---|
169 | 0x48, 0x7A, 0xFF, 0x00,
|
---|
170 | 0x48, 0x7C, 0xFF, 0x02,
|
---|
171 | 0x48, 0xB4, 0x40, 0x01,
|
---|
172 | 0x48, 0xBC, 0x50, 0x03,
|
---|
173 | 0x48, 0xBE, 0x10, 0x03 };
|
---|
174 |
|
---|
175 | memorize_cmd_table (dummy_cmd_table,132);
|
---|
176 |
|
---|
177 | unsigned char buff[256];
|
---|
178 |
|
---|
179 | /*
|
---|
180 | unsigned char ins7416[5] = { 0x48,0x74,0x16,0x00,0x00 };
|
---|
181 | if(do_cmd(reader, ins7416, NULL, NULL,cta_res)<0) {
|
---|
182 | cs_log ("[videoguard12-reader] cmd 7416 failed");
|
---|
183 | return ERROR;
|
---|
184 | }
|
---|
185 | */
|
---|
186 |
|
---|
187 | /* Read card serial number to initialise the card
|
---|
188 | unsigned char ins52[5] = { 0x48,0x52,0x00,0x00,0x14 };
|
---|
189 |
|
---|
190 | if(!write_cmd_vg(ins52,NULL) || !status_ok(cta_res+l)) {
|
---|
191 | cs_log ("[videoguard12-reader] failed to read serial");
|
---|
192 | return ERROR;
|
---|
193 | }
|
---|
194 | */
|
---|
195 |
|
---|
196 | unsigned char ins36[5] = { 0x48,0x36,0x00,0x00,0x00 };
|
---|
197 | unsigned char boxID [4];
|
---|
198 |
|
---|
199 | if (reader->boxid > 0) {
|
---|
200 | /* the boxid is specified in the config */
|
---|
201 | int i;
|
---|
202 | for (i=0; i < 4; i++) {
|
---|
203 | boxID[i] = (reader->boxid >> (8 * (3 - i))) % 0x100;
|
---|
204 | }
|
---|
205 | } else {
|
---|
206 | /* we can try to get the boxid from the card */
|
---|
207 | int boxidOK=0;
|
---|
208 | l=do_cmd(reader, ins36, NULL, buff,cta_res);
|
---|
209 | if(l<13)
|
---|
210 | cs_log("[videoguard12-reader] ins36: too short answer");
|
---|
211 | else if (buff[7] > 0x0F)
|
---|
212 | cs_log("[videoguard12-reader] ins36: encrypted - can't parse");
|
---|
213 | else {
|
---|
214 | /* skipping the initial fixed fields: cmdecho (4) + length (1) + encr/rev++ (4) */
|
---|
215 | int i=9;
|
---|
216 | int gotUA=0;
|
---|
217 | while (i<l) {
|
---|
218 | if (!gotUA && buff[i]<0xF0) { /* then we guess that the next 4 bytes is the UA */
|
---|
219 | gotUA=1;
|
---|
220 | i+=4;
|
---|
221 | } else switch (buff[i]) { /* object length vary depending on type */
|
---|
222 | case 0x00: /* padding */
|
---|
223 | i+=1;
|
---|
224 | break;
|
---|
225 | case 0xEF: /* card status */
|
---|
226 | i+=3;
|
---|
227 | break;
|
---|
228 | case 0xD1:
|
---|
229 | i+=4;
|
---|
230 | break;
|
---|
231 | case 0xDF: /* next server contact */
|
---|
232 | i+=5;
|
---|
233 | break;
|
---|
234 | case 0xF3: /* boxID */
|
---|
235 | memcpy(&boxID,&buff[i+1],sizeof(boxID));
|
---|
236 | boxidOK=1;
|
---|
237 | i+=5;
|
---|
238 | break;
|
---|
239 | case 0xF6:
|
---|
240 | i+=6;
|
---|
241 | break;
|
---|
242 | case 0x01: /* date & time */
|
---|
243 | i+=7;
|
---|
244 | break;
|
---|
245 | case 0xFA:
|
---|
246 | i+=9;
|
---|
247 | break;
|
---|
248 | case 0x5E:
|
---|
249 | case 0x67: /* signature */
|
---|
250 | case 0xDE:
|
---|
251 | case 0xE2:
|
---|
252 | case 0xE9: /* tier dates */
|
---|
253 | case 0xF8: /* Old PPV Event Record */
|
---|
254 | case 0xFD:
|
---|
255 | i+=buff[i+1]+2; /* skip length + 2 bytes (type and length) */
|
---|
256 | break;
|
---|
257 | default: /* default to assume a length byte */
|
---|
258 | cs_log("[videoguard12-reader] ins36 returned unknown type=0x%02X - parsing may fail", buff[i]);
|
---|
259 | i+=buff[i+1]+2;
|
---|
260 | }
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | if(!boxidOK) {
|
---|
265 | cs_log ("[videoguard12-reader] no boxID available");
|
---|
266 | return ERROR;
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | unsigned char ins4C[5] = { 0x48,0x4C,0x00,0x00,0x09 };
|
---|
271 | unsigned char payload4C[9] = { 0,0,0,0, 3,0,0,0,4 };
|
---|
272 | memcpy(payload4C,boxID,4);
|
---|
273 | if(!write_cmd_vg(ins4C,payload4C) || !status_ok(cta_res+l)) {
|
---|
274 | cs_log("[videoguard12-reader] sending boxid failed");
|
---|
275 | return ERROR;
|
---|
276 | }
|
---|
277 | // Start of suggested fix for 09ac cards
|
---|
278 | unsigned char Dimeno_Magic[0x10]={0xF9,0xFB,0xCD,0x5A,0x76,0xB5,0xC4,0x5C,0xC8,0x2E,0x1D,0xE1,0xCC,0x5B,0x6B,0x02};
|
---|
279 | int a;
|
---|
280 | for(a=0; a<4; a++)
|
---|
281 | Dimeno_Magic[a]=Dimeno_Magic[a]^boxID[a];
|
---|
282 | //I supposed to declare a AES_KEY Astro_Key somewhere before...
|
---|
283 | AES_set_decrypt_key(Dimeno_Magic,128,&Astro_Key);
|
---|
284 | Astro_Key.rounds=10;
|
---|
285 | //Important for ecm decryption...
|
---|
286 | // End of suggested fix
|
---|
287 |
|
---|
288 | //short int SWIRDstatus = cta_res[1];
|
---|
289 | unsigned char ins58[5] = { 0x48,0x58,0x00,0x00,0x00 };
|
---|
290 | l=do_cmd(reader, ins58, NULL, buff,cta_res);
|
---|
291 | if(l<0) {
|
---|
292 | cs_log("[videoguard12-reader] cmd ins58 failed");
|
---|
293 | return ERROR;
|
---|
294 | }
|
---|
295 | memset(reader->hexserial, 0, 8);
|
---|
296 | memcpy(reader->hexserial+2, cta_res+3, 4);
|
---|
297 | memcpy(reader->sa, cta_res+3, 3);
|
---|
298 | reader->caid[0] = cta_res[24]*0x100+cta_res[25];
|
---|
299 |
|
---|
300 | /* we have one provider, 0x0000 */
|
---|
301 | reader->nprov = 1;
|
---|
302 | memset(reader->prid, 0x00, sizeof(reader->prid));
|
---|
303 |
|
---|
304 | /*
|
---|
305 | cs_log ("[videoguard12-reader] INS58 : Fuse byte=0x%02X, IRDStatus=0x%02X", cta_res[2],SWIRDstatus);
|
---|
306 | if (SWIRDstatus==4) {
|
---|
307 | // If swMarriage=4, not married then exchange for BC Key
|
---|
308 | cs_log ("[videoguard12-reader] Card not married, exchange for BC Keys");
|
---|
309 | */
|
---|
310 |
|
---|
311 | static unsigned char seed1[] = {
|
---|
312 | 0xb9, 0xd5, 0xef, 0xd5, 0xf5, 0xd5, 0xfb, 0xd5, 0x31, 0xd6, 0x43, 0xd6, 0x55, 0xd6, 0x61, 0xd6,
|
---|
313 | 0x85, 0xd6, 0x9d, 0xd6, 0xaf, 0xd6, 0xc7, 0xd6, 0xd9, 0xd6, 0x09, 0xd7, 0x15, 0xd7, 0x21, 0xd7,
|
---|
314 | 0x27, 0xd7, 0x3f, 0xd7, 0x45, 0xd7, 0xb1, 0xd7, 0xbd, 0xd7, 0xdb, 0xd7, 0x11, 0xd8, 0x23, 0xd8,
|
---|
315 | 0x29, 0xd8, 0x2f, 0xd8, 0x4d, 0xd8, 0x8f, 0xd8, 0xa1, 0xd8, 0xad, 0xd8, 0xbf, 0xd8, 0xd7, 0xd8
|
---|
316 | };
|
---|
317 | static unsigned char seed2[] = {
|
---|
318 | 0x01, 0x00, 0xcf, 0x13, 0xe0, 0x60, 0x54, 0xac, 0xab, 0x99, 0xe6, 0x0c, 0x9f, 0x5b, 0x91, 0xb9,
|
---|
319 | 0x72, 0x72, 0x4d, 0x5b, 0x5f, 0xd3, 0xb7, 0x5b, 0x01, 0x4d, 0xef, 0x9e, 0x6b, 0x8a, 0xb9, 0xd1,
|
---|
320 | 0xc9, 0x9f, 0xa1, 0x2a, 0x8d, 0x86, 0xb6, 0xd6, 0x39, 0xb4, 0x64, 0x65, 0x13, 0x77, 0xa1, 0x0a,
|
---|
321 | 0x0c, 0xcf, 0xb4, 0x2b, 0x3a, 0x2f, 0xd2, 0x09, 0x92, 0x15, 0x40, 0x47, 0x66, 0x5c, 0xda, 0xc9
|
---|
322 | };
|
---|
323 | cCamCryptVG_SetSeed(seed1,seed2);
|
---|
324 |
|
---|
325 | unsigned char insB4[5] = { 0x48,0xB4,0x00,0x00,0x40 };
|
---|
326 | unsigned char tbuff[64];
|
---|
327 | cCamCryptVG_GetCamKey(tbuff);
|
---|
328 | l=do_cmd(reader, insB4, tbuff, NULL,cta_res);
|
---|
329 | if(l<0 || !status_ok(cta_res)) {
|
---|
330 | cs_log ("[videoguard12-reader] cmd D0B4 failed (%02X%02X)", cta_res[0], cta_res[1]);
|
---|
331 | return ERROR;
|
---|
332 | }
|
---|
333 |
|
---|
334 | unsigned char insBC[5] = { 0x48,0xBC,0x00,0x00,0x00 };
|
---|
335 | l=do_cmd(reader, insBC, NULL, NULL,cta_res);
|
---|
336 | if(l<0) {
|
---|
337 | cs_log("[videoguard12-reader] cmd D0BC failed");
|
---|
338 | return ERROR;
|
---|
339 | }
|
---|
340 |
|
---|
341 | unsigned char insBE[5] = { 0x48,0xBE,0x00,0x00,0x00 };
|
---|
342 | l=do_cmd(reader, insBE, NULL, NULL,cta_res);
|
---|
343 | if(l<0) {
|
---|
344 | cs_log("[videoguard12-reader] cmd D3BE failed");
|
---|
345 | return ERROR;
|
---|
346 | }
|
---|
347 |
|
---|
348 | unsigned char ins58a[5] = { 0x49,0x58,0x00,0x00,0x00 };
|
---|
349 | l=do_cmd(reader, ins58a, NULL, NULL,cta_res);
|
---|
350 | if(l<0) {
|
---|
351 | cs_log("[videoguard12-reader] cmd D158 failed");
|
---|
352 | return ERROR;
|
---|
353 | }
|
---|
354 |
|
---|
355 | unsigned char ins4Ca[5] = { 0x49,0x4C,0x00,0x00,0x00 };
|
---|
356 | l=do_cmd(reader, ins4Ca,payload4C, NULL,cta_res);
|
---|
357 | if(l<0 || !status_ok(cta_res)) {
|
---|
358 | cs_log("[videoguard12-reader] cmd D14Ca failed");
|
---|
359 | return ERROR;
|
---|
360 | }
|
---|
361 |
|
---|
362 | cs_ri_log(reader, "[videoguard12-reader] type: VideoGuard, caid: %04X, serial: %02X%02X%02X%02X, BoxID: %02X%02X%02X%02X",
|
---|
363 | reader->caid[0],
|
---|
364 | reader->hexserial[2],reader->hexserial[3],reader->hexserial[4],reader->hexserial[5],
|
---|
365 | boxID[0],boxID[1],boxID[2],boxID[3]);
|
---|
366 |
|
---|
367 | cs_log("[videoguard12-reader] ready for requests");
|
---|
368 |
|
---|
369 | return OK;
|
---|
370 | }
|
---|
371 |
|
---|
372 | static void do_post_dw_hash(unsigned char *cw, unsigned char *ecm_header_data) {
|
---|
373 | int i,ecmi,ecm_header_count;
|
---|
374 | unsigned char buffer[0x80];
|
---|
375 | unsigned char md5_digest[0x10];
|
---|
376 | //ecm_header_data = 01 03 b0 01 01
|
---|
377 |
|
---|
378 | if (!cw_is_valid(cw)) //if cw is all zero, keep it that way
|
---|
379 | return;
|
---|
380 |
|
---|
381 | ecm_header_count=ecm_header_data[0];
|
---|
382 |
|
---|
383 | for(i=0, ecmi = 1; i<ecm_header_count; i++) {
|
---|
384 | if(ecm_header_data[ecmi+1] != 0xb0) {
|
---|
385 | ecmi += ecm_header_data[ecmi]+1;
|
---|
386 | } else {
|
---|
387 | switch(ecm_header_data[ecmi+2]) { //b0 01
|
---|
388 | case 1:
|
---|
389 | {
|
---|
390 | unsigned short hk[8],i,j,m=0;
|
---|
391 | for (i = 0; i < 6; i++) hk[2+i]=Hash3[i];
|
---|
392 | for (i = 0; i < 2; i++) {
|
---|
393 | for (j = 0; j < 0x48; j+=2) {
|
---|
394 | if (i)
|
---|
395 | hk[0]=((hk[3] & hk[5]) | ((~hk[5]) & hk[4]));
|
---|
396 | else
|
---|
397 | hk[0]=((hk[3] & hk[4]) | ((~hk[3]) & hk[5]));
|
---|
398 | if (j<8)
|
---|
399 | hk[0]=(hk[0]+((cw[j +1]<<8) | cw[j]));
|
---|
400 | if(j==8) hk[0]=(hk[0]+0x80);
|
---|
401 | hk[0]=(hk[0]+hk[2] + (0xFF & NdTabB001[ecm_header_data[ecmi+3]][m>>1] >> ((m&1)<<3))) ;
|
---|
402 | hk[1] = hk[2];
|
---|
403 | hk[2] = hk[3];
|
---|
404 | hk[3] = hk[4];
|
---|
405 | hk[4] = hk[5];
|
---|
406 | hk[5] = hk[6];
|
---|
407 | hk[6] = hk[7];
|
---|
408 | hk[7] = hk[2]+
|
---|
409 | (((hk[0] << Hash4[m&0xF]) | (hk[0] >> (0x10 - Hash4[m&0xF]))));
|
---|
410 | m=(m+1)&0x3F;
|
---|
411 | }
|
---|
412 | }
|
---|
413 | for (i = 0; i < 6; i++)
|
---|
414 | hk[2+i]+=Hash3[i];
|
---|
415 | for (i = 0; i < 7; i++)
|
---|
416 | cw[i]=hk[2+(i>>1)]>>((i&1)<<3);
|
---|
417 |
|
---|
418 | cw[3] = (cw[0] + cw[1] + cw[2]) & 0xFF;
|
---|
419 | cw[7] = (cw[4] + cw[5] + cw[6]) & 0xFF;
|
---|
420 | cs_ddump (cw, 8, "Postprocessed2 DW:");
|
---|
421 | break;
|
---|
422 | }
|
---|
423 | case 3:
|
---|
424 | {
|
---|
425 | memset(buffer,0,sizeof(buffer));
|
---|
426 | memcpy(buffer,cw,8);
|
---|
427 | memcpy(buffer+8,&ecm_header_data[ecmi+3],ecm_header_data[ecmi]-2);
|
---|
428 | MD5( buffer, 8+ecm_header_data[ecmi]-2, md5_digest) ;
|
---|
429 | memcpy(cw,md5_digest,8);
|
---|
430 | cs_ddump (cw, 8, "Postprocessed2 DW:");
|
---|
431 | break;
|
---|
432 | }
|
---|
433 |
|
---|
434 | case 2:
|
---|
435 | { /* Method 2 left out */
|
---|
436 | //memcpy(DW_OUTPUT, DW_INPUT, 8);
|
---|
437 | break;
|
---|
438 | }
|
---|
439 | }
|
---|
440 | }
|
---|
441 | }
|
---|
442 | }
|
---|
443 |
|
---|
444 | int videoguard12_do_ecm(struct s_reader * reader, ECM_REQUEST *er)
|
---|
445 | {
|
---|
446 | unsigned char cta_res[CTA_RES_LEN];
|
---|
447 | static unsigned char ins40[5] = { 0x49,0x40,0x00,0x80,0xFF };
|
---|
448 | static const unsigned char ins54[5] = { 0x4B,0x54,0x00,0x00,0x00};
|
---|
449 | int posECMpart2=er->ecm[6]+7;
|
---|
450 | int lenECMpart2=er->ecm[posECMpart2]+1;
|
---|
451 | unsigned char tbuff[264];
|
---|
452 | tbuff[0]=0;
|
---|
453 | memcpy(&tbuff[1],&(er->ecm[posECMpart2+1]),lenECMpart2-1);
|
---|
454 | ins40[4]=lenECMpart2;
|
---|
455 | int l;
|
---|
456 | l = do_cmd(reader, ins40,tbuff,NULL,cta_res);
|
---|
457 | if(l>0 && status_ok(cta_res)) {
|
---|
458 | l = do_cmd(reader, ins54,NULL,NULL,cta_res);
|
---|
459 | if(l>0 && status_ok(cta_res+l)) {
|
---|
460 | if (!cw_is_valid(CW1)) //sky cards report 90 00 = ok but send cw = 00 when channel not subscribed
|
---|
461 | {
|
---|
462 | snprintf( er->msglog, MSGLOGSIZE, "9000 but cw=00 -> channel not subscribed " );
|
---|
463 | return ERROR;
|
---|
464 | }
|
---|
465 |
|
---|
466 | if(er->ecm[0]&1) {
|
---|
467 | memcpy(er->cw+8,CW1,8);
|
---|
468 | memcpy(er->cw+0,CW2,8);
|
---|
469 | }
|
---|
470 | else {
|
---|
471 | memcpy(er->cw+0,CW1,8);
|
---|
472 | memcpy(er->cw+8,CW2,8);
|
---|
473 | }
|
---|
474 |
|
---|
475 |
|
---|
476 | //test for postprocessing marker
|
---|
477 | int posB0 = -1;
|
---|
478 | int i;
|
---|
479 | for (i = 6; i < posECMpart2; i++)
|
---|
480 | {
|
---|
481 | if (er->ecm[i-3] == 0x80 && er->ecm[i] == 0xB0 && ((er->ecm[i+1] == 0x01) ||(er->ecm[i+1] == 0x02)||(er->ecm[i+1] == 0x03) ) ) {
|
---|
482 | posB0 = i;
|
---|
483 | break;
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | if (posB0 != -1) {
|
---|
488 | do_post_dw_hash( er->cw+0, &er->ecm[posB0-2]);
|
---|
489 | do_post_dw_hash( er->cw+8, &er->ecm[posB0-2]);
|
---|
490 | }
|
---|
491 |
|
---|
492 | return OK;
|
---|
493 | }
|
---|
494 | }
|
---|
495 | snprintf( er->msglog, MSGLOGSIZE, "(%d) status not ok %02x %02x",l, cta_res[0],cta_res[1] );
|
---|
496 | return ERROR;
|
---|
497 | }
|
---|
498 |
|
---|
499 | static int num_addr(const unsigned char *data)
|
---|
500 | {
|
---|
501 | return ((data[3]&0x30)>>4)+1;
|
---|
502 | }
|
---|
503 | /*
|
---|
504 | Example of GLOBAL EMM's
|
---|
505 | This one has IRD-EMM + Card-EMM
|
---|
506 | 82 70 20 00 02 06 02 7D 0E 89 53 71 16 90 14 40
|
---|
507 | 01 ED 17 7D 9E 1F 28 CF 09 97 54 F1 8E 72 06 E7
|
---|
508 | 51 AF F5
|
---|
509 | This one has only IRD-EMM
|
---|
510 | 82 70 6D 00 07 69 01 30 07 14 5E 0F FF FF 00 06
|
---|
511 | 00 0D 01 00 03 01 00 00 00 0F 00 00 00 5E 01 00
|
---|
512 | 01 0C 2E 70 E4 55 B6 D2 34 F7 44 86 9E 5C 91 14
|
---|
513 | 81 FC DF CB D0 86 65 77 DF A9 E1 6B A8 9F 9B DE
|
---|
514 | 90 92 B9 AA 6C B3 4E 87 D2 EC 92 DA FC 71 EF 27
|
---|
515 | B3 C3 D0 17 CF 0B D6 5E 8C DB EB B3 37 55 6E 09
|
---|
516 | 7F 27 3C F1 85 29 C9 4E 0B EE DF 68 BE 00 C9 00
|
---|
517 | */
|
---|
518 | static const unsigned char *payload_addr(uchar emmtype, const unsigned char *data, const unsigned char *a)
|
---|
519 | {
|
---|
520 | int s;
|
---|
521 | int l;
|
---|
522 | const unsigned char *ptr = NULL;
|
---|
523 | int position=-1;
|
---|
524 | int numAddrs=0;
|
---|
525 |
|
---|
526 | switch(emmtype) {
|
---|
527 | case SHARED: s=3; break;
|
---|
528 | case UNIQUE: s=4; break;
|
---|
529 | default: s=0;
|
---|
530 | }
|
---|
531 |
|
---|
532 | numAddrs=num_addr(data);
|
---|
533 |
|
---|
534 | if(s>0) {
|
---|
535 | for(l=0;l<numAddrs;l++) {
|
---|
536 | if(!memcmp(&data[l*4+4],a+2,s)) {
|
---|
537 | position=l;
|
---|
538 | break;
|
---|
539 | }
|
---|
540 | }
|
---|
541 | }
|
---|
542 |
|
---|
543 | int num_filter = (position == -1) ? 0 : numAddrs;
|
---|
544 |
|
---|
545 | /* skip header and the filter list */
|
---|
546 | ptr = data+4+4*num_filter;
|
---|
547 |
|
---|
548 | if (*ptr != 0x02 && *ptr != 0x07) // some clients omit 00 00 separator */
|
---|
549 | {
|
---|
550 | ptr += 2; // skip 00 00 separator
|
---|
551 | if (*ptr == 0x00) ptr++; // skip optional 00
|
---|
552 | ptr++; // skip the 1st bitmap len
|
---|
553 | }
|
---|
554 |
|
---|
555 | /* check for IRD-EMM */
|
---|
556 | if (*ptr != 0x02 && *ptr != 0x07) return NULL;
|
---|
557 |
|
---|
558 | /* skip IRD-EMM part, 02 00 or 02 06 xx aabbccdd yy */
|
---|
559 | ptr += 2 + ptr[1];
|
---|
560 |
|
---|
561 | /* check for EMM boundaries - ptr should not exceed EMM length */
|
---|
562 | if ((int)(ptr - (data + 3)) >= data[2]) return NULL;
|
---|
563 |
|
---|
564 | for(l=0;l<position;l++) {
|
---|
565 | /* skip the payload of the previous sub-EMM */
|
---|
566 | ptr += 1 + ptr [0];
|
---|
567 |
|
---|
568 | /* check for EMM boundaries - ptr should not exceed EMM length */
|
---|
569 | if ((int)(ptr - (data + 3)) >= data[2]) return NULL;
|
---|
570 |
|
---|
571 | /* skip optional 00 */
|
---|
572 | if (*ptr == 0x00) ptr++;
|
---|
573 |
|
---|
574 | /* skip the bitmap len */
|
---|
575 | ptr++;
|
---|
576 |
|
---|
577 | /* check for IRD-EMM */
|
---|
578 | if (*ptr != 0x02 && *ptr != 0x07) return NULL;
|
---|
579 |
|
---|
580 | /* skip IRD-EMM part, 02 00 or 02 06 xx aabbccdd yy */
|
---|
581 | ptr += 2 + ptr[1];
|
---|
582 | }
|
---|
583 |
|
---|
584 | return ptr;
|
---|
585 | }
|
---|
586 |
|
---|
587 | int videoguard12_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr)
|
---|
588 | {
|
---|
589 |
|
---|
590 | /*
|
---|
591 | 82 30 ad 70 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 00
|
---|
592 | d3 02 00 22 90 20 44 02 4a 50 1d 88 ab 02 ac 79 16 6c df a1 b1 b7 77 00 ba eb 63 b5 c9 a9 30 2b 43 e9 16 a9 d5 14 00
|
---|
593 | d3 02 00 22 90 20 44 02 13 e3 40 bd 29 e4 90 97 c3 aa 93 db 8d f5 6b e4 92 dd 00 9b 51 03 c9 3d d0 e2 37 44 d3 bf 00
|
---|
594 | d3 02 00 22 90 20 44 02 97 79 5d 18 96 5f 3a 67 70 55 bb b9 d2 49 31 bd 18 17 2a e9 6f eb d8 76 ec c3 c9 cc 53 39 00
|
---|
595 | d2 02 00 21 90 1f 44 02 99 6d df 36 54 9c 7c 78 1b 21 54 d9 d4 9f c1 80 3c 46 10 76 aa 75 ef d6 82 27 2e 44 7b 00
|
---|
596 | */
|
---|
597 |
|
---|
598 | int i, pos;
|
---|
599 | int serial_count = ((ep->emm[3] >> 4) & 3) + 1;
|
---|
600 | int serial_len = (ep->emm[3] & 0x80) ? 3 : 4;
|
---|
601 | uchar emmtype = (ep->emm[3] & VG_EMMTYPE_MASK) >> 6;
|
---|
602 |
|
---|
603 | pos = 4 + (serial_len * serial_count) + 2;
|
---|
604 |
|
---|
605 | switch(emmtype) {
|
---|
606 | case VG_EMMTYPE_G:
|
---|
607 | ep->type=GLOBAL;
|
---|
608 | cs_debug_mask(D_EMM, "VIDEOGUARD12 EMM: GLOBAL");
|
---|
609 | return TRUE;
|
---|
610 |
|
---|
611 | case VG_EMMTYPE_U:
|
---|
612 | cs_debug_mask(D_EMM, "VIDEOGUARD12 EMM: UNIQUE");
|
---|
613 | ep->type=UNIQUE;
|
---|
614 | if (ep->emm[1] == 0) // detected UNIQUE EMM from cccam (there is no serial)
|
---|
615 | return TRUE;
|
---|
616 |
|
---|
617 | for (i = 1;i <= serial_count;i++) {
|
---|
618 | if (!memcmp (rdr->hexserial + 2, ep->emm + (serial_len * i), serial_len)) {
|
---|
619 | memcpy(ep->hexserial, ep->emm + (serial_len * i), serial_len);
|
---|
620 | return TRUE;
|
---|
621 | }
|
---|
622 |
|
---|
623 | pos = pos + ep->emm[pos+5] + 5;
|
---|
624 | }
|
---|
625 | return FALSE; // if UNIQUE but no serial match return FALSE
|
---|
626 |
|
---|
627 | case VG_EMMTYPE_S:
|
---|
628 | ep->type=SHARED;
|
---|
629 | cs_debug_mask(D_EMM, "VIDEOGUARD12 EMM: SHARED");
|
---|
630 | return TRUE; // FIXME: no check for SA
|
---|
631 |
|
---|
632 | default:
|
---|
633 | if (ep->emm[pos-2] != 0x00 && ep->emm[pos-1] != 0x00 && ep->emm[pos-1] != 0x01) {
|
---|
634 | //remote emm without serial
|
---|
635 | ep->type=UNKNOWN;
|
---|
636 | return TRUE;
|
---|
637 | }
|
---|
638 | return FALSE;
|
---|
639 | }
|
---|
640 | }
|
---|
641 |
|
---|
642 | void videoguard12_get_emm_filter(struct s_reader * rdr, uchar *filter)
|
---|
643 | {
|
---|
644 | filter[0]=0xFF;
|
---|
645 | filter[1]=3;
|
---|
646 |
|
---|
647 | //ToDo videoguard12_get_emm_filter basic construction
|
---|
648 |
|
---|
649 | filter[2]=UNIQUE;
|
---|
650 | filter[3]=0;
|
---|
651 |
|
---|
652 | filter[4+0] = 0x82;
|
---|
653 | filter[4+0+16] = 0xFF;
|
---|
654 |
|
---|
655 | memcpy(filter+4+2, rdr->hexserial+2, 4);
|
---|
656 | memset(filter+4+2+16, 0xFF, 4);
|
---|
657 |
|
---|
658 |
|
---|
659 | filter[36]=UNIQUE;
|
---|
660 | filter[37]=0;
|
---|
661 |
|
---|
662 | filter[38+0] = 0x82;
|
---|
663 | filter[38+0+16] = 0xFF;
|
---|
664 |
|
---|
665 | memcpy(filter+38+6, rdr->hexserial+2, 4);
|
---|
666 | memset(filter+38+6+16, 0xFF, 4);
|
---|
667 |
|
---|
668 |
|
---|
669 | filter[70]=UNIQUE;
|
---|
670 | filter[71]=0;
|
---|
671 |
|
---|
672 | filter[72+0] = 0x82;
|
---|
673 | filter[72+0+16] = 0xFF;
|
---|
674 |
|
---|
675 | memcpy(filter+72+10, rdr->hexserial+2, 4);
|
---|
676 | memset(filter+72+10+16, 0xFF, 4);
|
---|
677 |
|
---|
678 |
|
---|
679 | /* filter[104]=UNIQUE;
|
---|
680 | filter[105]=0;
|
---|
681 |
|
---|
682 | filter[106+0] = 0x82;
|
---|
683 | filter[106+0+16] = 0xFF;
|
---|
684 |
|
---|
685 | memcpy(filter+106+14, rdr->hexserial+2, 2);
|
---|
686 | memset(filter+106+14+16, 0xFF, 2); */
|
---|
687 |
|
---|
688 | return;
|
---|
689 | }
|
---|
690 |
|
---|
691 | int videoguard12_do_emm(struct s_reader * reader, EMM_PACKET *ep)
|
---|
692 | {
|
---|
693 | unsigned char cta_res[CTA_RES_LEN];
|
---|
694 | unsigned char ins42[5] = { 0x49,0x42,0x00,0x00,0xFF };
|
---|
695 | int rc=ERROR;
|
---|
696 |
|
---|
697 | const unsigned char *payload = payload_addr(ep->type, ep->emm, reader->hexserial);
|
---|
698 | while (payload) {
|
---|
699 | ins42[4]=*payload;
|
---|
700 | int l = do_cmd(reader, ins42,payload+1,NULL,cta_res);
|
---|
701 | if(l>0 && status_ok(cta_res)) {
|
---|
702 | rc=OK;
|
---|
703 | }
|
---|
704 |
|
---|
705 | cs_debug_mask(D_EMM, "[videoguard12-reader] EMM request return code : %02X%02X", cta_res[0], cta_res[1]);
|
---|
706 | //cs_dump(ep->emm, 64, "EMM:");
|
---|
707 | if (status_ok (cta_res) && (cta_res[1] & 0x01)) {
|
---|
708 | read_tiers(reader);
|
---|
709 | }
|
---|
710 |
|
---|
711 | if (num_addr(ep->emm) == 1 && (int)(&payload[1] - &ep->emm[0]) + *payload + 1 < ep->l) {
|
---|
712 | payload += *payload + 1;
|
---|
713 | if (*payload == 0x00) ++payload;
|
---|
714 | ++payload;
|
---|
715 | if (*payload != 0x02) break;
|
---|
716 | payload += 2 + payload[1];
|
---|
717 | }
|
---|
718 | else
|
---|
719 | payload = 0;
|
---|
720 |
|
---|
721 | }
|
---|
722 |
|
---|
723 | return(rc);
|
---|
724 | }
|
---|
725 |
|
---|
726 | int videoguard12_card_info(struct s_reader * reader)
|
---|
727 | {
|
---|
728 | /* info is displayed in init, or when processing info */
|
---|
729 | cs_log("[videoguard12-reader] card detected");
|
---|
730 | cs_log("[videoguard12-reader] type: VideoGuard" );
|
---|
731 | read_tiers (reader);
|
---|
732 | return OK;
|
---|
733 | }
|
---|