source: trunk/reader-videoguard12.c@ 3182

Last change on this file since 3182 was 3182, checked in by dingo35, 10 years ago

Readers checked on threadsafety except videoguard-common

File size: 17.8 KB
Line 
1#include "globals.h"
2#include "reader-common.h"
3#include "reader-videoguard-common.h"
4
5static void read_tiers(struct s_reader * reader)
6{
7 def_resp;
8 static const unsigned char ins2a[5] = { 0x48,0x2a,0x00,0x00,0x00 };
9 int l;
10 l=do_cmd(reader,ins2a,NULL,NULL,NULL,cta_res);
11 if(l<0 || !status_ok(cta_res+l)) return;
12 unsigned char ins76[5] = { 0x48,0x76,0x00,0x00,0x00 };
13 ins76[3]=0x7f; ins76[4]=2;
14 if(!write_cmd_vg(ins76,NULL) || !status_ok(cta_res+2)) return;
15 ins76[3]=0; ins76[4]=0;
16 int num=cta_res[1];
17 int i;
18#ifdef CS_RDR_INIT_HIST
19 reader->init_history_pos = 0; //reset for re-read
20 memset(reader->init_history, 0, sizeof(reader->init_history));
21#endif
22 for(i=0; i<num; i++) {
23 ins76[2]=i;
24 l=do_cmd(reader,ins76,NULL,NULL,NULL,cta_res);
25 if(l<0 || !status_ok(cta_res+l)) return;
26 if(cta_res[2]==0 && cta_res[3]==0) break;
27 int y,m,d,H,M,S;
28 rev_date_calc(&cta_res[4],&y,&m,&d,&H,&M,&S,reader->card_baseyear);
29 unsigned short tier_id = (cta_res[2] << 8) | cta_res[3];
30 char *tier_name = get_tiername(tier_id, reader->caid[0]);
31 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);
32 }
33}
34
35int videoguard12_card_init(struct s_reader * reader, ATR newatr)
36{
37
38 get_hist;
39 if ((hist_size < 7) || (hist[1] != 0xB0) || (hist[4] != 0xFF) || (hist[5] != 0x4A) || (hist[6] != 0x50)){
40 return ERROR;
41 }
42
43 get_atr;
44 def_resp;
45
46 // Copy the atr info into the reader, can we not do this in reader-common.c?
47 reader->atrlen = atr_size;
48 memcpy(reader->atr,atr,atr_size);
49
50 /* set information on the card stored in reader-videoguard-common.c */
51 set_known_card_info(reader);
52
53 if((reader->ndsversion != NDS12) && ((reader->card_system_version != NDS12) || (reader->ndsversion != NDSAUTO))) {
54 /* known ATR and not NDS1+
55 or unknown ATR and not forced to NDS1+
56 or known NDS1+ ATR and forced to another NDS version
57 ... probably not NDS1+ */
58 return ERROR;
59 }
60
61 cs_ri_log(reader, "[videoguard12-reader] type: %s, baseyear: %i", reader->card_desc, reader->card_baseyear);
62 if(reader->ndsversion == NDS12){
63 cs_log("[videoguard12-reader] forced to NDS1+");
64 }
65
66 int l = 1;
67
68 /* NDS1 and NDS1+ cards return XX 90 00 to this command NDS2 cards fail to respond to this*/
69 unsigned char ins3601[5] = { 0x48,0x36,0x01,0x00,0x01 };
70 if(!write_cmd_vg(ins3601,NULL) || !status_ok(cta_res+l)) {
71 return ERROR; // not a possible NDS1+ card
72 }
73
74 unsigned char dummy_cmd_table[132] = {
75 0x01, 0x82, 0x20, 0x01,
76 0x48, 0x0E, 0xFF, 0x02,
77 0x48, 0x18, 0x0C, 0x01,
78 0x48, 0x1A, 0x08, 0x03,
79 0x48, 0x1E, 0x09, 0x03,
80 0x48, 0x2E, 0xFF, 0x00,
81 0x48, 0x32, 0x01, 0x01,
82 0x48, 0x36, 0xFF, 0x02,
83 0x48, 0x38, 0x02, 0x03,
84 0x48, 0x40, 0xFF, 0x00,
85 0x48, 0x42, 0xFF, 0x00,
86 0x48, 0x44, 0x35, 0x01,
87 0x48, 0x46, 0xFF, 0x00,
88 0x48, 0x4A, 0xFF, 0x00,
89 0x48, 0x4C, 0x09, 0x01,
90 0x48, 0x4E, 0x05, 0x03,
91 0x48, 0x50, 0xFF, 0x02,
92 0x48, 0x54, 0x2C, 0x03,
93 0x48, 0x56, 0xFF, 0x02,
94 0x48, 0x58, 0x4A, 0x03,
95 0x48, 0x5A, 0xFF, 0x02,
96 0x48, 0x5C, 0x04, 0x03,
97 0x48, 0x5E, 0xFF, 0x02,
98 0x48, 0x70, 0x25, 0x03,
99 0x48, 0x72, 0x23, 0x03,
100 0x48, 0x74, 0xFF, 0x02,
101 0x48, 0x76, 0x0A, 0x03,
102 0x48, 0x78, 0x18, 0x03,
103 0x48, 0x7A, 0xFF, 0x00,
104 0x48, 0x7C, 0xFF, 0x02,
105 0x48, 0xB4, 0x40, 0x01,
106 0x48, 0xBC, 0x50, 0x03,
107 0x48, 0xBE, 0x10, 0x03 };
108
109 memorize_cmd_table (dummy_cmd_table,132);
110
111 unsigned char buff[256];
112
113/* Read card serial number to initialise the card
114 unsigned char ins52[5] = { 0x48,0x52,0x00,0x00,0x14 };
115
116 if(!write_cmd_vg(ins52,NULL) || !status_ok(cta_res+l)) {
117 cs_log ("[videoguard12-reader] failed to read serial");
118 return ERROR;
119 }
120*/
121
122 unsigned char ins36[5] = { 0x48,0x36,0x00,0x00,0x00 };
123 unsigned char boxID [4];
124
125 if (reader->boxid > 0) {
126 /* the boxid is specified in the config */
127 int i;
128 for (i=0; i < 4; i++) {
129 boxID[i] = (reader->boxid >> (8 * (3 - i))) % 0x100;
130 }
131 } else {
132 /* we can try to get the boxid from the card */
133 int boxidOK=0;
134 l=do_cmd(reader,ins36,NULL,buff,NULL,cta_res);
135 if(l<13)
136 cs_log("[videoguard12-reader] ins36: too short answer");
137 else if (buff[7] > 0x0F)
138 cs_log("[videoguard12-reader] ins36: encrypted - can't parse");
139 else {
140 /* skipping the initial fixed fields: cmdecho (4) + length (1) + encr/rev++ (4) */
141 int i=9;
142 int gotUA=0;
143 while (i<l) {
144 if (!gotUA && buff[i]<0xF0) { /* then we guess that the next 4 bytes is the UA */
145 gotUA=1;
146 i+=4;
147 } else switch (buff[i]) { /* object length vary depending on type */
148 case 0x00: /* padding */
149 i+=1;
150 break;
151 case 0xEF: /* card status */
152 i+=3;
153 break;
154 case 0xD1:
155 i+=4;
156 break;
157 case 0xDF: /* next server contact */
158 i+=5;
159 break;
160 case 0xF3: /* boxID */
161 memcpy(boxID,buff+i+1,sizeof(boxID));
162 boxidOK=1;
163 i+=5;
164 break;
165 case 0xF6:
166 i+=6;
167 break;
168 case 0x01: /* date & time */
169 i+=7;
170 break;
171 case 0xFA:
172 i+=9;
173 break;
174 case 0x5E:
175 case 0x67: /* signature */
176 case 0xDE:
177 case 0xE2:
178 case 0xE9: /* tier dates */
179 case 0xF8: /* Old PPV Event Record */
180 case 0xFD:
181 i+=buff[i+1]+2; /* skip length + 2 bytes (type and length) */
182 break;
183 default: /* default to assume a length byte */
184 cs_log("[videoguard12-reader] ins36 returned unknown type=0x%02X - parsing may fail", buff[i]);
185 i+=buff[i+1]+2;
186 }
187 }
188 }
189
190 if(!boxidOK) {
191 cs_log ("[videoguard12-reader] no boxID available");
192 return ERROR;
193 }
194 }
195
196 unsigned char ins4C[5] = { 0x48,0x4C,0x00,0x00,0x09 };
197 unsigned char payload4C[9] = { 0,0,0,0, 3,0,0,0,4 };
198 memcpy(payload4C,boxID,4);
199 if(!write_cmd_vg(ins4C,payload4C) || !status_ok(cta_res+l)) {
200 cs_log("[videoguard12-reader] sending boxid failed");
201 return ERROR;
202 }
203
204 //short int SWIRDstatus = cta_res[1];
205 unsigned char ins58[5] = { 0x48,0x58,0x00,0x00,0x00 };
206 l=do_cmd(reader,ins58,NULL,buff,NULL,cta_res);
207 if(l<0) {
208 cs_log("[videoguard12-reader] cmd ins58 failed");
209 return ERROR;
210 }
211 memset(reader->hexserial, 0, 8);
212 memcpy(reader->hexserial+2, cta_res+3, 4);
213 memcpy(reader->sa, cta_res+3, 3);
214 reader->caid[0] = cta_res[24]*0x100+cta_res[25];
215
216 /* we have one provider, 0x0000 */
217 reader->nprov = 1;
218 memset(reader->prid, 0x00, sizeof(reader->prid));
219
220 /*
221 cs_log ("[videoguard12-reader] INS58 : Fuse byte=0x%02X, IRDStatus=0x%02X", cta_res[2],SWIRDstatus);
222 if (SWIRDstatus==4) {
223 // If swMarriage=4, not married then exchange for BC Key
224 cs_log ("[videoguard12-reader] Card not married, exchange for BC Keys");
225 */
226
227 static const unsigned char seed1[] = {
228 0xb9, 0xd5, 0xef, 0xd5, 0xf5, 0xd5, 0xfb, 0xd5, 0x31, 0xd6, 0x43, 0xd6, 0x55, 0xd6, 0x61, 0xd6,
229 0x85, 0xd6, 0x9d, 0xd6, 0xaf, 0xd6, 0xc7, 0xd6, 0xd9, 0xd6, 0x09, 0xd7, 0x15, 0xd7, 0x21, 0xd7,
230 0x27, 0xd7, 0x3f, 0xd7, 0x45, 0xd7, 0xb1, 0xd7, 0xbd, 0xd7, 0xdb, 0xd7, 0x11, 0xd8, 0x23, 0xd8,
231 0x29, 0xd8, 0x2f, 0xd8, 0x4d, 0xd8, 0x8f, 0xd8, 0xa1, 0xd8, 0xad, 0xd8, 0xbf, 0xd8, 0xd7, 0xd8
232 };
233 static const unsigned char seed2[] = {
234 0x01, 0x00, 0xcf, 0x13, 0xe0, 0x60, 0x54, 0xac, 0xab, 0x99, 0xe6, 0x0c, 0x9f, 0x5b, 0x91, 0xb9,
235 0x72, 0x72, 0x4d, 0x5b, 0x5f, 0xd3, 0xb7, 0x5b, 0x01, 0x4d, 0xef, 0x9e, 0x6b, 0x8a, 0xb9, 0xd1,
236 0xc9, 0x9f, 0xa1, 0x2a, 0x8d, 0x86, 0xb6, 0xd6, 0x39, 0xb4, 0x64, 0x65, 0x13, 0x77, 0xa1, 0x0a,
237 0x0c, 0xcf, 0xb4, 0x2b, 0x3a, 0x2f, 0xd2, 0x09, 0x92, 0x15, 0x40, 0x47, 0x66, 0x5c, 0xda, 0xc9
238 };
239 cCamCryptVG_SetSeed(seed1,seed2);
240
241 unsigned char insB4[5] = { 0x48,0xB4,0x00,0x00,0x40 };
242 unsigned char tbuff[64];
243 cCamCryptVG_GetCamKey(tbuff);
244 l=do_cmd(reader,insB4,tbuff,NULL,NULL,cta_res);
245 if(l<0 || !status_ok(cta_res)) {
246 cs_log ("[videoguard12-reader] cmd D0B4 failed (%02X%02X)", cta_res[0], cta_res[1]);
247 return ERROR;
248 }
249
250 unsigned char insBC[5] = { 0x48,0xBC,0x00,0x00,0x00 };
251 l=do_cmd(reader,insBC,NULL,NULL,NULL,cta_res);
252 if(l<0) {
253 cs_log("[videoguard12-reader] cmd D0BC failed");
254 return ERROR;
255 }
256
257 unsigned char insBE[5] = { 0x48,0xBE,0x00,0x00,0x00 };
258 l=do_cmd(reader,insBE,NULL,NULL,NULL,cta_res);
259 if(l<0) {
260 cs_log("[videoguard12-reader] cmd D3BE failed");
261 return ERROR;
262 }
263
264 unsigned char ins58a[5] = { 0x49,0x58,0x00,0x00,0x00 };
265 l=do_cmd(reader,ins58a,NULL,NULL,NULL,cta_res);
266 if(l<0) {
267 cs_log("[videoguard12-reader] cmd D158 failed");
268 return ERROR;
269 }
270
271 unsigned char ins4Ca[5] = { 0x49,0x4C,0x00,0x00,0x00 };
272 l=do_cmd(reader,ins4Ca,payload4C,NULL,NULL,cta_res);
273 if(l<0 || !status_ok(cta_res)) {
274 cs_log("[videoguard12-reader] cmd D14Ca failed");
275 return ERROR;
276 }
277
278 // fix for 09ac cards
279 unsigned char dimeno_magic[0x10]={0xF9,0xFB,0xCD,0x5A,0x76,0xB5,0xC4,0x5C,0xC8,0x2E,0x1D,0xE1,0xCC,0x5B,0x6B,0x02};
280 int a;
281 for(a=0; a<4; a++)
282 dimeno_magic[a]=dimeno_magic[a]^boxID[a];
283 add_aes_entry(reader, reader->caid[0], 0, AESKEY_ASTRO, dimeno_magic);
284
285 AES_ENTRY *current;
286 current=reader->aes_list;
287 while(current) {
288 cs_log("**************************");
289 cs_log("current = %p",current);
290 cs_log("CAID = %04x",current->caid);
291 cs_log("IDENT = %06x",current->ident);
292 cs_log("keyID = %d",current->keyid);
293 cs_log("next = %p",current->next);
294 cs_log("**************************");
295 current=current->next;
296 }
297
298 cs_ri_log(reader, "[videoguard12-reader] type: VideoGuard, caid: %04X, serial: %02X%02X%02X%02X, BoxID: %02X%02X%02X%02X",
299 reader->caid[0],
300 reader->hexserial[2],reader->hexserial[3],reader->hexserial[4],reader->hexserial[5],
301 boxID[0],boxID[1],boxID[2],boxID[3]);
302
303 cs_log("[videoguard12-reader] ready for requests");
304
305 return OK;
306}
307
308int videoguard12_do_ecm(struct s_reader * reader, ECM_REQUEST *er)
309{
310 unsigned char cta_res[CTA_RES_LEN];
311 unsigned char ins40[5] = { 0x49,0x40,0x00,0x80,0xFF };
312 static const unsigned char ins54[5] = { 0x4B,0x54,0x00,0x00,0x00};
313 int posECMpart2=er->ecm[6]+7;
314 int lenECMpart2=er->ecm[posECMpart2]+1;
315 unsigned char tbuff[264];
316 tbuff[0]=0;
317 memcpy(tbuff+1,er->ecm+posECMpart2+1,lenECMpart2-1);
318 ins40[4]=lenECMpart2;
319 int l;
320 l = do_cmd(reader,ins40,tbuff,NULL,NULL,cta_res);
321 if(l>0 && status_ok(cta_res)) {
322 l = do_cmd(reader,ins54,NULL,NULL,er->cw,cta_res);
323 if(l>0 && status_ok(cta_res+l)) {
324 if (!cw_is_valid(er->cw+0,0)) //sky cards report 90 00 = ok but send cw = 00 when channel not subscribed
325 {
326 cs_log("[reader-videoguard12] ins54 returned status 90 00 but cw=00 -> channel not subscribed " );
327 return ERROR;
328 }
329
330 if(er->ecm[0]&1) {
331 unsigned char tmpcw[8];
332 memcpy(tmpcw,er->cw+8,8);
333 memcpy(er->cw+8,er->cw+0,8);
334 memcpy(er->cw+0,tmpcw,8);
335 }
336
337 //test for postprocessing marker
338 int posB0 = -1;
339 int i;
340 for (i = 6; i < posECMpart2; i++)
341 {
342 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) ) ) {
343 posB0 = i;
344 break;
345 }
346 }
347
348 if (posB0 != -1) {
349 do_post_dw_hash( er->cw+0, &er->ecm[posB0-2]);
350 do_post_dw_hash( er->cw+8, &er->ecm[posB0-2]);
351 }
352
353 return OK;
354 }
355 }
356 cs_log("[reader-videoguard12] ins54 (%d) status not ok %02x %02x",l, cta_res[0],cta_res[1] );
357 return ERROR;
358}
359
360static int num_addr(const unsigned char *data)
361{
362 return ((data[3]&0x30)>>4)+1;
363}
364/*
365Example of GLOBAL EMM's
366This one has IRD-EMM + Card-EMM
36782 70 20 00 02 06 02 7D 0E 89 53 71 16 90 14 40
36801 ED 17 7D 9E 1F 28 CF 09 97 54 F1 8E 72 06 E7
36951 AF F5
370This one has only IRD-EMM
37182 70 6D 00 07 69 01 30 07 14 5E 0F FF FF 00 06
37200 0D 01 00 03 01 00 00 00 0F 00 00 00 5E 01 00
37301 0C 2E 70 E4 55 B6 D2 34 F7 44 86 9E 5C 91 14
37481 FC DF CB D0 86 65 77 DF A9 E1 6B A8 9F 9B DE
37590 92 B9 AA 6C B3 4E 87 D2 EC 92 DA FC 71 EF 27
376B3 C3 D0 17 CF 0B D6 5E 8C DB EB B3 37 55 6E 09
3777F 27 3C F1 85 29 C9 4E 0B EE DF 68 BE 00 C9 00
378*/
379static const unsigned char *payload_addr(uchar emmtype, const unsigned char *data, const unsigned char *a)
380{
381 int s;
382 int l;
383 const unsigned char *ptr = NULL;
384 int position=-1;
385 int numAddrs=0;
386
387 switch(emmtype) {
388 case SHARED: s=3; break;
389 case UNIQUE: s=4; break;
390 default: s=0;
391 }
392
393 numAddrs=num_addr(data);
394
395 if(s>0) {
396 for(l=0;l<numAddrs;l++) {
397 if(!memcmp(&data[l*4+4],a+2,s)) {
398 position=l;
399 break;
400 }
401 }
402 }
403
404 int num_filter = (position == -1) ? 0 : numAddrs;
405
406 /* skip header and the filter list */
407 ptr = data+4+4*num_filter;
408
409 if (*ptr != 0x02 && *ptr != 0x07) // some clients omit 00 00 separator */
410 {
411 ptr += 2; // skip 00 00 separator
412 if (*ptr == 0x00) ptr++; // skip optional 00
413 ptr++; // skip the 1st bitmap len
414 }
415
416 /* check for IRD-EMM */
417 if (*ptr != 0x02 && *ptr != 0x07) return NULL;
418
419 /* skip IRD-EMM part, 02 00 or 02 06 xx aabbccdd yy */
420 ptr += 2 + ptr[1];
421
422 /* check for EMM boundaries - ptr should not exceed EMM length */
423 if ((int)(ptr - (data + 3)) >= data[2]) return NULL;
424
425 for(l=0;l<position;l++) {
426 /* skip the payload of the previous sub-EMM */
427 ptr += 1 + ptr [0];
428
429 /* check for EMM boundaries - ptr should not exceed EMM length */
430 if ((int)(ptr - (data + 3)) >= data[2]) return NULL;
431
432 /* skip optional 00 */
433 if (*ptr == 0x00) ptr++;
434
435 /* skip the bitmap len */
436 ptr++;
437
438 /* check for IRD-EMM */
439 if (*ptr != 0x02 && *ptr != 0x07) return NULL;
440
441 /* skip IRD-EMM part, 02 00 or 02 06 xx aabbccdd yy */
442 ptr += 2 + ptr[1];
443 }
444
445 return ptr;
446}
447
448int videoguard12_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr)
449{
450
451/*
45282 30 ad 70 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 00
453d3 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
454d3 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
455d3 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
456d2 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
457*/
458
459 int i, pos;
460 int serial_count = ((ep->emm[3] >> 4) & 3) + 1;
461 int serial_len = (ep->emm[3] & 0x80) ? 3 : 4;
462 uchar emmtype = (ep->emm[3] & VG_EMMTYPE_MASK) >> 6;
463
464 pos = 4 + (serial_len * serial_count) + 2;
465
466 switch(emmtype) {
467 case VG_EMMTYPE_G:
468 ep->type=GLOBAL;
469 cs_debug_mask(D_EMM, "VIDEOGUARD12 EMM: GLOBAL");
470 return TRUE;
471
472 case VG_EMMTYPE_U:
473 cs_debug_mask(D_EMM, "VIDEOGUARD12 EMM: UNIQUE");
474 ep->type=UNIQUE;
475 if (ep->emm[1] == 0) // detected UNIQUE EMM from cccam (there is no serial)
476 return TRUE;
477
478 for (i = 1;i <= serial_count;i++) {
479 if (!memcmp (rdr->hexserial + 2, ep->emm + (serial_len * i), serial_len)) {
480 memcpy(ep->hexserial, ep->emm + (serial_len * i), serial_len);
481 return TRUE;
482 }
483
484 pos = pos + ep->emm[pos+5] + 5;
485 }
486 return FALSE; // if UNIQUE but no serial match return FALSE
487
488 case VG_EMMTYPE_S:
489 ep->type=SHARED;
490 cs_debug_mask(D_EMM, "VIDEOGUARD12 EMM: SHARED");
491 return TRUE; // FIXME: no check for SA
492
493 default:
494 if (ep->emm[pos-2] != 0x00 && ep->emm[pos-1] != 0x00 && ep->emm[pos-1] != 0x01) {
495 //remote emm without serial
496 ep->type=UNKNOWN;
497 return TRUE;
498 }
499 return FALSE;
500 }
501}
502
503void videoguard12_get_emm_filter(struct s_reader * rdr, uchar *filter)
504{
505 filter[0]=0xFF;
506 filter[1]=3;
507
508 //ToDo videoguard12_get_emm_filter basic construction
509
510 filter[2]=UNIQUE;
511 filter[3]=0;
512
513 filter[4+0] = 0x82;
514 filter[4+0+16] = 0xFF;
515
516 memcpy(filter+4+2, rdr->hexserial+2, 4);
517 memset(filter+4+2+16, 0xFF, 4);
518
519
520 filter[36]=UNIQUE;
521 filter[37]=0;
522
523 filter[38+0] = 0x82;
524 filter[38+0+16] = 0xFF;
525
526 memcpy(filter+38+6, rdr->hexserial+2, 4);
527 memset(filter+38+6+16, 0xFF, 4);
528
529
530 filter[70]=UNIQUE;
531 filter[71]=0;
532
533 filter[72+0] = 0x82;
534 filter[72+0+16] = 0xFF;
535
536 memcpy(filter+72+10, rdr->hexserial+2, 4);
537 memset(filter+72+10+16, 0xFF, 4);
538
539
540 /* filter[104]=UNIQUE;
541 filter[105]=0;
542
543 filter[106+0] = 0x82;
544 filter[106+0+16] = 0xFF;
545
546 memcpy(filter+106+14, rdr->hexserial+2, 2);
547 memset(filter+106+14+16, 0xFF, 2); */
548
549 return;
550}
551
552int videoguard12_do_emm(struct s_reader * reader, EMM_PACKET *ep)
553{
554 unsigned char cta_res[CTA_RES_LEN];
555 unsigned char ins42[5] = { 0x49,0x42,0x00,0x00,0xFF };
556 int rc=ERROR;
557
558 const unsigned char *payload = payload_addr(ep->type, ep->emm, reader->hexserial);
559 while (payload) {
560 ins42[4]=*payload;
561 int l = do_cmd(reader,ins42,payload+1,NULL,NULL,cta_res);
562 if(l>0 && status_ok(cta_res)) {
563 rc=OK;
564 }
565
566 cs_debug_mask(D_EMM, "[videoguard12-reader] EMM request return code : %02X%02X", cta_res[0], cta_res[1]);
567 //cs_dump(ep->emm, 64, "EMM:");
568 if (status_ok (cta_res) && (cta_res[1] & 0x01)) {
569 read_tiers(reader);
570 }
571
572 if (num_addr(ep->emm) == 1 && (int)(&payload[1] - &ep->emm[0]) + *payload + 1 < ep->l) {
573 payload += *payload + 1;
574 if (*payload == 0x00) ++payload;
575 ++payload;
576 if (*payload != 0x02) break;
577 payload += 2 + payload[1];
578 }
579 else
580 payload = 0;
581
582 }
583
584 return(rc);
585}
586
587int videoguard12_card_info(struct s_reader * reader)
588{
589 /* info is displayed in init, or when processing info */
590 cs_log("[videoguard12-reader] card detected");
591 cs_log("[videoguard12-reader] type: %s", reader->card_desc);
592 read_tiers (reader);
593 return OK;
594}
595
596void reader_videoguard12(struct s_cardsystem *ph)
597{
598 ph->do_emm=videoguard12_do_emm;
599 ph->do_ecm=videoguard12_do_ecm;
600 ph->card_info=videoguard12_card_info;
601 ph->card_init=videoguard12_card_init;
602 ph->get_emm_type=videoguard12_get_emm_type;
603 ph->caids[0]=0x09;
604}
Note: See TracBrowser for help on using the repository browser.