1 | #include "globals.h"
|
---|
2 | #include "reader-common.h"
|
---|
3 | #include "reader-videoguard-common.h"
|
---|
4 |
|
---|
5 |
|
---|
6 | static void vg2_read_tiers(struct s_reader * reader)
|
---|
7 | {
|
---|
8 | def_resp;
|
---|
9 | int l;
|
---|
10 |
|
---|
11 | /* ins2a is not needed and causes an error on some cards eg Sky Italy 09CD
|
---|
12 | check if ins2a is in command table before running it
|
---|
13 | */
|
---|
14 | static const unsigned char ins2a[5] = { 0xD0,0x2a,0x00,0x00,0x00 };
|
---|
15 | if(cmd_exists(reader,ins2a)) {
|
---|
16 | l=do_cmd(reader,ins2a,NULL,NULL,NULL,cta_res);
|
---|
17 | if(l<0 || !status_ok(cta_res+l)){
|
---|
18 | cs_log ("[videoguard2-reader] classD0 ins2a: failed");
|
---|
19 | return;
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | static const unsigned char ins76007f[5] = { 0xD0,0x76,0x00,0x7f,0x02 };
|
---|
24 | if(!write_cmd_vg(ins76007f,NULL) || !status_ok(cta_res+2)){
|
---|
25 | cs_log ("[videoguard2-reader] classD0 ins76007f: failed");
|
---|
26 | return;
|
---|
27 | }
|
---|
28 | int num=cta_res[1];
|
---|
29 |
|
---|
30 | int i;
|
---|
31 | unsigned char ins76[5] = { 0xD0,0x76,0x00,0x00,0x00 };
|
---|
32 |
|
---|
33 | // some cards start real tiers info in middle of tier info
|
---|
34 | // and have blank tiers between old tiers and real tiers eg 09AC
|
---|
35 | int starttier;
|
---|
36 | bool stopemptytier = TRUE;
|
---|
37 | if((starttier = reader->card_tierstart) == -1){
|
---|
38 | stopemptytier = FALSE;
|
---|
39 | starttier = 0;
|
---|
40 | }
|
---|
41 | // check to see if specified start tier is blank and if so start at 0 and ignore blank tiers
|
---|
42 | ins76[2]=starttier;
|
---|
43 | l=do_cmd(reader,ins76,NULL,NULL,NULL,cta_res);
|
---|
44 | if(l<0 || !status_ok(cta_res+l)) return;
|
---|
45 | if(cta_res[2]==0 && cta_res[3]==0 ){
|
---|
46 | stopemptytier = FALSE;
|
---|
47 | starttier = 0;
|
---|
48 | }
|
---|
49 | for(i=starttier; i<num; i++) {
|
---|
50 | ins76[2]=i;
|
---|
51 | l=do_cmd(reader,ins76,NULL,NULL,NULL,cta_res);
|
---|
52 | if(l<0 || !status_ok(cta_res+l)) return;
|
---|
53 | if(cta_res[2]==0 && cta_res[3]==0 && stopemptytier) return;
|
---|
54 | if(cta_res[2]!=0 || cta_res[3]!=0) {
|
---|
55 | int y,m,d,H,M,S;
|
---|
56 | rev_date_calc(&cta_res[4],&y,&m,&d,&H,&M,&S,reader->card_baseyear);
|
---|
57 | unsigned short tier_id = (cta_res[2] << 8) | cta_res[3];
|
---|
58 | char *tier_name = get_tiername(tier_id, reader->caid[0]);
|
---|
59 | if(reader->card_tierstart == -1){
|
---|
60 | cs_ri_log(reader, "[videoguard2-reader] tier-number: 0x%02x, tier: %04x",i,tier_id);
|
---|
61 | }
|
---|
62 | cs_ri_log(reader, "[videoguard2-reader] tier: %04x, expiry date: %04d/%02d/%02d-%02d:%02d:%02d %s",tier_id,y,m,d,H,M,S,tier_name);
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | int videoguard2_card_init(struct s_reader * reader, ATR newatr)
|
---|
68 | {
|
---|
69 | get_hist;
|
---|
70 | if ((hist_size < 7) || (hist[1] != 0xB0) || (hist[4] != 0xFF) || (hist[5] != 0x4A) || (hist[6] != 0x50))
|
---|
71 | return ERROR;
|
---|
72 | cs_log("[videoguard2-reader] in videoguard2_card_init");
|
---|
73 |
|
---|
74 | get_atr;
|
---|
75 | def_resp;
|
---|
76 |
|
---|
77 | /* set information on the card stored in reader-videoguard-common.c */
|
---|
78 | set_known_card_info(reader,atr,&atr_size);
|
---|
79 |
|
---|
80 | if((reader->ndsversion != NDS2) &&
|
---|
81 | (((reader->card_system_version != NDS2) && (reader->card_system_version != NDSUNKNOWN)) ||
|
---|
82 | (reader->ndsversion != NDSAUTO))) {
|
---|
83 | /* known ATR and not NDS2
|
---|
84 | or known NDS2 ATR and forced to another NDS version */
|
---|
85 | return ERROR;
|
---|
86 | }
|
---|
87 |
|
---|
88 | cs_ri_log(reader, "[videoguard2-reader] type: %s, baseyear: %i", reader->card_desc, reader->card_baseyear);
|
---|
89 | if(reader->ndsversion == NDS2){
|
---|
90 | cs_log("[videoguard2-reader] forced to NDS2");
|
---|
91 | }
|
---|
92 |
|
---|
93 | //a non videoguard2/NDS2 card will fail on read_cmd_len(ins7401)
|
---|
94 | //this way unknown videoguard2/NDS2 cards will also pass this check
|
---|
95 |
|
---|
96 | unsigned char ins7401[5] = { 0xD0,0x74,0x01,0x00,0x00 };
|
---|
97 | int l;
|
---|
98 | ins7401[3]=0x80; // from newcs log
|
---|
99 | ins7401[4]=0x01;
|
---|
100 | if((l=read_cmd_len(reader,ins7401))<0) return ERROR; //not a videoguard2/NDS card or communication error
|
---|
101 | ins7401[3]=0x00;
|
---|
102 | ins7401[4]=l;
|
---|
103 | if(!write_cmd_vg(ins7401,NULL) || !status_ok(cta_res+l)) {
|
---|
104 | cs_log ("[videoguard2-reader] classD0 ins7401: failed - cmd list not read");
|
---|
105 | return ERROR;
|
---|
106 | }
|
---|
107 |
|
---|
108 | memorize_cmd_table (reader,cta_res,l);
|
---|
109 |
|
---|
110 | unsigned char buff[256];
|
---|
111 |
|
---|
112 | static const unsigned char ins7416[5] = { 0xD0,0x74,0x16,0x00,0x00 };
|
---|
113 | if(do_cmd(reader,ins7416,NULL,NULL,NULL,cta_res)<0) {
|
---|
114 | cs_log ("[videoguard2-reader] classD0 ins7416: failed");
|
---|
115 | return ERROR;
|
---|
116 | }
|
---|
117 |
|
---|
118 | unsigned char ins36[5] = { 0xD0,0x36,0x00,0x00,0x00 };
|
---|
119 | static const unsigned char ins5e[5] = { 0xD0,0x5E,0x00,0x0C,0x02 };
|
---|
120 | unsigned char boxID [4];
|
---|
121 |
|
---|
122 | if (reader->boxid > 0) {
|
---|
123 | /* the boxid is specified in the config */
|
---|
124 | int i;
|
---|
125 | for (i=0; i < 4; i++) {
|
---|
126 | boxID[i] = (reader->boxid >> (8 * (3 - i))) % 0x100;
|
---|
127 | }
|
---|
128 | } else {
|
---|
129 | /* we can try to get the boxid from the card */
|
---|
130 | int boxidOK=0;
|
---|
131 | if((ins36[4]=read_cmd_len(reader,ins36))==0 && cmd_exists(reader,ins5e)) {
|
---|
132 | if(!write_cmd_vg(ins5e,NULL) || !status_ok(cta_res+2)){
|
---|
133 | cs_log ("[videoguard2-reader] classD0 ins5e: failed");
|
---|
134 | } else {
|
---|
135 | ins36[3] = cta_res[0];
|
---|
136 | ins36[4] = cta_res[1];
|
---|
137 | }
|
---|
138 | }
|
---|
139 | l=ins36[4];
|
---|
140 | if(!write_cmd_vg(ins36,NULL) || !status_ok(cta_res+l)){
|
---|
141 | cs_log ("[videoguard2-reader] classD0 ins36: failed");
|
---|
142 | return ERROR;
|
---|
143 | }
|
---|
144 | memcpy(buff,ins36,5);
|
---|
145 | memcpy(buff+5,cta_res,l);
|
---|
146 | memcpy(buff+5+l,cta_res+l,2);
|
---|
147 | if(l<13)
|
---|
148 | cs_log("[videoguard2-reader] classD0 ins36: too short answer");
|
---|
149 | else if (buff[7] > 0x0F)
|
---|
150 | cs_log("[videoguard2-reader] classD0 ins36: encrypted - can't parse");
|
---|
151 | else {
|
---|
152 | /* skipping the initial fixed fields: cmdecho (4) + length (1) + encr/rev++ (4) */
|
---|
153 | int i=9;
|
---|
154 | int gotUA=0;
|
---|
155 | while (i<l) {
|
---|
156 | if (!gotUA && buff[i]<0xF0) { /* then we guess that the next 4 bytes is the UA */
|
---|
157 | gotUA=1;
|
---|
158 | i+=4;
|
---|
159 | } else switch (buff[i]) { /* object length vary depending on type */
|
---|
160 | case 0x00: /* padding */
|
---|
161 | i+=1;
|
---|
162 | break;
|
---|
163 | case 0xEF: /* card status */
|
---|
164 | i+=3;
|
---|
165 | break;
|
---|
166 | case 0xD1:
|
---|
167 | i+=4;
|
---|
168 | break;
|
---|
169 | case 0xDF: /* next server contact */
|
---|
170 | i+=5;
|
---|
171 | break;
|
---|
172 | case 0xF3: /* boxID */
|
---|
173 | memcpy(boxID,buff+i+1,sizeof(boxID));
|
---|
174 | boxidOK=1;
|
---|
175 | i+=5;
|
---|
176 | break;
|
---|
177 | case 0xF6:
|
---|
178 | i+=6;
|
---|
179 | break;
|
---|
180 | case 0x01: /* date & time */
|
---|
181 | i+=7;
|
---|
182 | break;
|
---|
183 | case 0xFA:
|
---|
184 | i+=9;
|
---|
185 | break;
|
---|
186 | case 0x5E:
|
---|
187 | case 0x67: /* signature */
|
---|
188 | case 0xDE:
|
---|
189 | case 0xE2:
|
---|
190 | case 0xE9: /* tier dates */
|
---|
191 | case 0xF8: /* Old PPV Event Record */
|
---|
192 | case 0xFD:
|
---|
193 | i+=buff[i+1]+2; /* skip length + 2 bytes (type and length) */
|
---|
194 | break;
|
---|
195 | default: /* default to assume a length byte */
|
---|
196 | cs_log("[videoguard2-reader] classD0 ins36: returned unknown type=0x%02X - parsing may fail", buff[i]);
|
---|
197 | i+=buff[i+1]+2;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | if(!boxidOK) {
|
---|
203 | cs_log ("[videoguard2-reader] no boxID available");
|
---|
204 | return ERROR;
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 | static const unsigned char ins4C[5] = { 0xD0,0x4C,0x00,0x00,0x09 };
|
---|
209 | unsigned char payload4C[9] = { 0,0,0,0, 3,0,0,0,4 };
|
---|
210 | memcpy(payload4C,boxID,4);
|
---|
211 | if(!write_cmd_vg(ins4C,payload4C) || !status_ok(cta_res+l)) {
|
---|
212 | cs_log("[videoguard2-reader] classD0 ins4C: failed - sending boxid failed");
|
---|
213 | return ERROR;
|
---|
214 | }
|
---|
215 |
|
---|
216 | //short int SWIRDstatus = cta_res[1];
|
---|
217 | static const unsigned char ins58[5] = { 0xD0,0x58,0x00,0x00,0x00 };
|
---|
218 | l=do_cmd(reader,ins58,NULL,buff,NULL,cta_res);
|
---|
219 | if(l<0) {
|
---|
220 | cs_log("[videoguard2-reader] classD0 ins58: failed");
|
---|
221 | return ERROR;
|
---|
222 | }
|
---|
223 | memset(reader->hexserial, 0, 8);
|
---|
224 | memcpy(reader->hexserial+2, cta_res+3, 4);
|
---|
225 | memcpy(reader->sa, cta_res+3, 3);
|
---|
226 | reader->caid[0] = cta_res[24]*0x100+cta_res[25];
|
---|
227 |
|
---|
228 | /* we have one provider, 0x0000 */
|
---|
229 | reader->nprov = 1;
|
---|
230 | memset(reader->prid, 0x00, sizeof(reader->prid));
|
---|
231 |
|
---|
232 | /*
|
---|
233 | cs_log ("[videoguard2-reader] INS58 : Fuse byte=0x%02X, IRDStatus=0x%02X", cta_res[2],SWIRDstatus);
|
---|
234 | if (SWIRDstatus==4) {
|
---|
235 | // If swMarriage=4, not married then exchange for BC Key
|
---|
236 | cs_log ("[videoguard2-reader] Card not married, exchange for BC Keys");
|
---|
237 | */
|
---|
238 |
|
---|
239 | cCamCryptVG_SetSeed(reader);
|
---|
240 |
|
---|
241 | static const unsigned char insB4[5] = { 0xD0,0xB4,0x00,0x00,0x40 };
|
---|
242 | unsigned char tbuff[64];
|
---|
243 | cCamCryptVG_GetCamKey(reader,tbuff);
|
---|
244 | l=do_cmd(reader,insB4,tbuff,NULL,NULL,cta_res);
|
---|
245 | if(l<0 || !status_ok(cta_res)) {
|
---|
246 | cs_log ("[videoguard2-reader] classD0 insB4: failed (%02X%02X)", cta_res[0], cta_res[1]);
|
---|
247 | return ERROR;
|
---|
248 | }
|
---|
249 |
|
---|
250 | static const unsigned char insBC[5] = { 0xD0,0xBC,0x00,0x00,0x00 };
|
---|
251 | l=do_cmd(reader,insBC,NULL,NULL,NULL,cta_res);
|
---|
252 | if(l<0) {
|
---|
253 | cs_log("[videoguard2-reader] classD0 insBC: failed");
|
---|
254 | return ERROR;
|
---|
255 | }
|
---|
256 |
|
---|
257 | // Class D1/D3 instructions only work after this point
|
---|
258 |
|
---|
259 | static const unsigned char insBE[5] = { 0xD3,0xBE,0x00,0x00,0x00 };
|
---|
260 | l=do_cmd(reader,insBE,NULL,NULL,NULL,cta_res);
|
---|
261 | if(l<0) {
|
---|
262 | cs_log("[videoguard2-reader] classD3 insBE: failed");
|
---|
263 | return ERROR;
|
---|
264 | }
|
---|
265 |
|
---|
266 | static const unsigned char ins58a[5] = { 0xD1,0x58,0x00,0x00,0x00 };
|
---|
267 | l=do_cmd(reader,ins58a,NULL,NULL,NULL,cta_res);
|
---|
268 | if(l<0) {
|
---|
269 | cs_log("[videoguard2-reader] classD1 ins58: failed");
|
---|
270 | return ERROR;
|
---|
271 | }
|
---|
272 |
|
---|
273 | static const unsigned char ins4Ca[5] = { 0xD1,0x4C,0x00,0x00,0x00 };
|
---|
274 | l=do_cmd(reader,ins4Ca,payload4C,NULL,NULL,cta_res);
|
---|
275 | if(l<0 || !status_ok(cta_res)) {
|
---|
276 | cs_log("[videoguard2-reader] classD1 ins4Ca: failed");
|
---|
277 | return ERROR;
|
---|
278 | }
|
---|
279 |
|
---|
280 | // fix for 09ac cards
|
---|
281 | unsigned char dimeno_magic[0x10]={0xF9,0xFB,0xCD,0x5A,0x76,0xB5,0xC4,0x5C,0xC8,0x2E,0x1D,0xE1,0xCC,0x5B,0x6B,0x02};
|
---|
282 | int a;
|
---|
283 | for(a=0; a<4; a++)
|
---|
284 | dimeno_magic[a]=dimeno_magic[a]^boxID[a];
|
---|
285 | AES_set_decrypt_key(dimeno_magic,128,&(reader->astrokey));
|
---|
286 |
|
---|
287 | cs_ri_log(reader, "[videoguard2-reader] type: %s, caid: %04X, serial: %02X%02X%02X%02X, BoxID: %02X%02X%02X%02X",
|
---|
288 | reader->card_desc,
|
---|
289 | reader->caid[0],
|
---|
290 | reader->hexserial[2],reader->hexserial[3],reader->hexserial[4],reader->hexserial[5],
|
---|
291 | boxID[0],boxID[1],boxID[2],boxID[3]);
|
---|
292 |
|
---|
293 | cs_log("[videoguard2-reader] ready for requests");
|
---|
294 |
|
---|
295 | return OK;
|
---|
296 | }
|
---|
297 |
|
---|
298 | int videoguard2_do_ecm(struct s_reader * reader, ECM_REQUEST *er)
|
---|
299 | {
|
---|
300 | unsigned char cta_res[CTA_RES_LEN];
|
---|
301 | unsigned char ins40[5] = { 0xD1,0x40,0x00,0x80,0xFF };
|
---|
302 | static const unsigned char ins54[5] = { 0xD3,0x54,0x00,0x00,0x00};
|
---|
303 | int posECMpart2=er->ecm[6]+7;
|
---|
304 | int lenECMpart2=er->ecm[posECMpart2]+1;
|
---|
305 | unsigned char tbuff[264];
|
---|
306 | tbuff[0]=0;
|
---|
307 | memcpy(tbuff+1,er->ecm+posECMpart2+1,lenECMpart2-1);
|
---|
308 | ins40[4]=lenECMpart2;
|
---|
309 | int l;
|
---|
310 | l = do_cmd(reader,ins40,tbuff,NULL,NULL,cta_res);
|
---|
311 | if(l>0 && status_ok(cta_res)) {
|
---|
312 | l = do_cmd(reader,ins54,NULL,NULL,er->cw,cta_res);
|
---|
313 | if(l>0 && status_ok(cta_res+l)) {
|
---|
314 | if (!cw_is_valid(er->cw+0,0)) //sky cards report 90 00 = ok but send cw = 00 when channel not subscribed
|
---|
315 | {
|
---|
316 | cs_log("[reader-videoguard2] classD3 ins54: status 90 00 but cw=00 -> channel not subscribed " );
|
---|
317 | return ERROR;
|
---|
318 | }
|
---|
319 |
|
---|
320 | if(er->ecm[0]&1) {
|
---|
321 | unsigned char tmpcw[8];
|
---|
322 | memcpy(tmpcw,er->cw+8,8);
|
---|
323 | memcpy(er->cw+8,er->cw+0,8);
|
---|
324 | memcpy(er->cw+0,tmpcw,8);
|
---|
325 | }
|
---|
326 |
|
---|
327 | //test for postprocessing marker
|
---|
328 | int posB0 = -1;
|
---|
329 | int i;
|
---|
330 | for (i = 6; i < posECMpart2; i++)
|
---|
331 | {
|
---|
332 | 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) ) ) {
|
---|
333 | posB0 = i;
|
---|
334 | break;
|
---|
335 | }
|
---|
336 | }
|
---|
337 |
|
---|
338 | if (posB0 != -1) {
|
---|
339 | do_post_dw_hash( er->cw+0, &er->ecm[posB0-2]);
|
---|
340 | do_post_dw_hash( er->cw+8, &er->ecm[posB0-2]);
|
---|
341 | }
|
---|
342 |
|
---|
343 | return OK;
|
---|
344 | }
|
---|
345 | }
|
---|
346 | cs_log("[reader-videoguard2] classD3 ins54: (%d) status not ok %02x %02x",l, cta_res[0],cta_res[1] );
|
---|
347 | return ERROR;
|
---|
348 | }
|
---|
349 |
|
---|
350 | int videoguard2_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr)
|
---|
351 | {
|
---|
352 |
|
---|
353 | /*
|
---|
354 | 82 30 ad 70 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 00
|
---|
355 | 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
|
---|
356 | 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
|
---|
357 | 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
|
---|
358 | 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
|
---|
359 | */
|
---|
360 |
|
---|
361 | int i, pos;
|
---|
362 | int serial_count = ((ep->emm[3] >> 4) & 3) + 1;
|
---|
363 | int serial_len = (ep->emm[3] & 0x80) ? 3 : 4;
|
---|
364 | uchar emmtype = (ep->emm[3] & VG_EMMTYPE_MASK) >> 6;
|
---|
365 |
|
---|
366 | pos = 4 + (serial_len * serial_count) + 2;
|
---|
367 |
|
---|
368 | switch(emmtype) {
|
---|
369 | case VG_EMMTYPE_G:
|
---|
370 | ep->type=GLOBAL;
|
---|
371 | cs_debug_mask(D_EMM, "VIDEOGUARD2 EMM: GLOBAL");
|
---|
372 | return TRUE;
|
---|
373 |
|
---|
374 | case VG_EMMTYPE_U:
|
---|
375 | cs_debug_mask(D_EMM, "VIDEOGUARD2 EMM: UNIQUE");
|
---|
376 | ep->type=UNIQUE;
|
---|
377 | if (ep->emm[1] == 0) // detected UNIQUE EMM from cccam (there is no serial)
|
---|
378 | return TRUE;
|
---|
379 |
|
---|
380 | for (i = 1;i <= serial_count;i++) {
|
---|
381 | if (!memcmp (rdr->hexserial + 2, ep->emm + (serial_len * i), serial_len)) {
|
---|
382 | memcpy(ep->hexserial, ep->emm + (serial_len * i), serial_len);
|
---|
383 | return TRUE;
|
---|
384 | }
|
---|
385 |
|
---|
386 | pos = pos + ep->emm[pos+5] + 5;
|
---|
387 | }
|
---|
388 | return FALSE; // if UNIQUE but no serial match return FALSE
|
---|
389 |
|
---|
390 | case VG_EMMTYPE_S:
|
---|
391 | ep->type=SHARED;
|
---|
392 | cs_debug_mask(D_EMM, "VIDEOGUARD2 EMM: SHARED");
|
---|
393 | return TRUE; // FIXME: no check for SA
|
---|
394 |
|
---|
395 | default:
|
---|
396 | if (ep->emm[pos-2] != 0x00 && ep->emm[pos-1] != 0x00 && ep->emm[pos-1] != 0x01) {
|
---|
397 | //remote emm without serial
|
---|
398 | ep->type=UNKNOWN;
|
---|
399 | return TRUE;
|
---|
400 | }
|
---|
401 | return FALSE;
|
---|
402 | }
|
---|
403 | }
|
---|
404 |
|
---|
405 | void videoguard2_get_emm_filter(struct s_reader * rdr, uchar *filter)
|
---|
406 | {
|
---|
407 | filter[0]=0xFF;
|
---|
408 | filter[1]=3;
|
---|
409 |
|
---|
410 | //ToDo videoguard2_get_emm_filter basic construction
|
---|
411 |
|
---|
412 | filter[2]=UNIQUE;
|
---|
413 | filter[3]=0;
|
---|
414 |
|
---|
415 | filter[4+0] = 0x82;
|
---|
416 | filter[4+0+16] = 0xFF;
|
---|
417 |
|
---|
418 | memcpy(filter+4+2, rdr->hexserial+2, 4);
|
---|
419 | memset(filter+4+2+16, 0xFF, 4);
|
---|
420 |
|
---|
421 | filter[36]=UNIQUE;
|
---|
422 | filter[37]=0;
|
---|
423 |
|
---|
424 | filter[38+0] = 0x82;
|
---|
425 | filter[38+0+16] = 0xFF;
|
---|
426 |
|
---|
427 | memcpy(filter+38+6, rdr->hexserial+2, 4);
|
---|
428 | memset(filter+38+6+16, 0xFF, 4);
|
---|
429 |
|
---|
430 | filter[70]=UNIQUE;
|
---|
431 | filter[71]=0;
|
---|
432 |
|
---|
433 | filter[72+0] = 0x82;
|
---|
434 | filter[72+0+16] = 0xFF;
|
---|
435 |
|
---|
436 | memcpy(filter+72+10, rdr->hexserial+2, 4);
|
---|
437 | memset(filter+72+10+16, 0xFF, 4);
|
---|
438 |
|
---|
439 | /* filter[104]=UNIQUE;
|
---|
440 | filter[105]=0;
|
---|
441 |
|
---|
442 | filter[106+0] = 0x82;
|
---|
443 | filter[106+0+16] = 0xFF;
|
---|
444 |
|
---|
445 | memcpy(filter+106+14, rdr->hexserial+2, 2);
|
---|
446 | memset(filter+106+14+16, 0xFF, 2); */
|
---|
447 |
|
---|
448 | return;
|
---|
449 | }
|
---|
450 |
|
---|
451 | int videoguard2_do_emm(struct s_reader * reader, EMM_PACKET *ep)
|
---|
452 | {
|
---|
453 | unsigned char cta_res[CTA_RES_LEN];
|
---|
454 | unsigned char ins42[5] = { 0xD1,0x42,0x00,0x00,0xFF };
|
---|
455 | int rc=ERROR;
|
---|
456 |
|
---|
457 | const unsigned char *payload = payload_addr(ep->type, ep->emm, reader->hexserial);
|
---|
458 | while (payload) {
|
---|
459 | ins42[4]=*payload;
|
---|
460 | int l = do_cmd(reader,ins42,payload+1,NULL,NULL,cta_res);
|
---|
461 | if(l>0 && status_ok(cta_res)) {
|
---|
462 | rc=OK;
|
---|
463 | }
|
---|
464 |
|
---|
465 | cs_debug_mask(D_EMM, "[videoguard2-reader] EMM request return code : %02X%02X", cta_res[0], cta_res[1]);
|
---|
466 | //cs_dump(ep->emm, 64, "EMM:");
|
---|
467 | if (status_ok (cta_res) && (cta_res[1] & 0x01)) {
|
---|
468 | vg2_read_tiers(reader);
|
---|
469 | }
|
---|
470 |
|
---|
471 | if (num_addr(ep->emm) == 1 && (int)(&payload[1] - &ep->emm[0]) + *payload + 1 < ep->l) {
|
---|
472 | payload += *payload + 1;
|
---|
473 | if (*payload == 0x00) ++payload;
|
---|
474 | ++payload;
|
---|
475 | if (*payload != 0x02) break;
|
---|
476 | payload += 2 + payload[1];
|
---|
477 | }
|
---|
478 | else
|
---|
479 | payload = 0;
|
---|
480 |
|
---|
481 | }
|
---|
482 |
|
---|
483 | return(rc);
|
---|
484 | }
|
---|
485 |
|
---|
486 | int videoguard2_card_info(struct s_reader * reader)
|
---|
487 | {
|
---|
488 | /* info is displayed in init, or when processing info */
|
---|
489 | cs_log("[videoguard2-reader] card detected");
|
---|
490 | cs_log("[videoguard2-reader] type: %s", reader->card_desc );
|
---|
491 | vg2_read_tiers (reader);
|
---|
492 | return OK;
|
---|
493 | }
|
---|
494 |
|
---|
495 | void reader_videoguard2(struct s_cardsystem *ph)
|
---|
496 | {
|
---|
497 | ph->do_emm=videoguard2_do_emm;
|
---|
498 | ph->do_ecm=videoguard2_do_ecm;
|
---|
499 | ph->card_info=videoguard2_card_info;
|
---|
500 | ph->card_init=videoguard2_card_init;
|
---|
501 | ph->get_emm_type=videoguard2_get_emm_type;
|
---|
502 | ph->caids[0]=0x09;
|
---|
503 | }
|
---|