source: trunk/reader-videoguard12.c@ 3181

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

Adding threadsafety FIXMEs, feel free to join checking..

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