1 | #include "globals.h"
|
---|
2 | #include "reader-common.h"
|
---|
3 | #include "reader-videoguard-common.h"
|
---|
4 |
|
---|
5 | // Redefine logging funtion to include reader name
|
---|
6 | #define cs_log(x...) cs_log("[videoguard12-reader] "x)
|
---|
7 | #define cs_ri_log(x,y...) cs_ri_log(x,"[videoguard12-reader] "y)
|
---|
8 | #ifdef WITH_DEBUG
|
---|
9 | #define cs_debug(x...) cs_debug("[videoguard12-reader] "x)
|
---|
10 | #define cs_debug_mask(x,y...) cs_debug_mask(x,"[videoguard12-reader] "y)
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | static int vg12_do_cmd(struct s_reader * reader, const unsigned char *ins, const unsigned char *txbuff, unsigned char *rxbuff,
|
---|
14 | unsigned char * cta_res)
|
---|
15 | {
|
---|
16 | ushort cta_lr;
|
---|
17 | unsigned char ins2[5];
|
---|
18 | memcpy(ins2,ins,5);
|
---|
19 | unsigned char len=0, mode=0;
|
---|
20 |
|
---|
21 | if(cmd_table_get_info(reader,ins2,&len,&mode)) {
|
---|
22 | if(len==0xFF && mode==2) {
|
---|
23 | if(ins2[4]==0) ins2[4]=len=read_cmd_len(reader,ins2);
|
---|
24 | }
|
---|
25 | else if(mode!=0) ins2[4]=len;
|
---|
26 | }
|
---|
27 |
|
---|
28 | len=ins2[4];
|
---|
29 |
|
---|
30 | unsigned char tmp[264];
|
---|
31 | if(!rxbuff) rxbuff=tmp;
|
---|
32 | if(mode>1) {
|
---|
33 | if(!write_cmd_vg(ins2,NULL) || !status_ok(cta_res+len)) return -1;
|
---|
34 | memcpy(rxbuff,ins2,5);
|
---|
35 | memcpy(rxbuff+5,cta_res,len);
|
---|
36 | memcpy(rxbuff+5+len,cta_res+len,2);
|
---|
37 | }
|
---|
38 | else {
|
---|
39 | if(!write_cmd_vg(ins2,(uchar *)txbuff) || !status_ok(cta_res)) return -2;
|
---|
40 | memcpy(rxbuff,ins2,5);
|
---|
41 | memcpy(rxbuff+5,txbuff,len);
|
---|
42 | memcpy(rxbuff+5+len,cta_res,2);
|
---|
43 | }
|
---|
44 |
|
---|
45 | return len;
|
---|
46 | }
|
---|
47 |
|
---|
48 | static void read_tiers(struct s_reader * reader)
|
---|
49 | {
|
---|
50 | def_resp;
|
---|
51 | static const unsigned char ins2a[5] = { 0x48,0x2a,0x00,0x00,0x00 };
|
---|
52 | int l;
|
---|
53 | l=vg12_do_cmd(reader,ins2a,NULL,NULL,cta_res);
|
---|
54 | if(l<0 || !status_ok(cta_res+l)) return;
|
---|
55 | unsigned char ins76[5] = { 0x48,0x76,0x00,0x00,0x00 };
|
---|
56 | ins76[3]=0x7f; ins76[4]=2;
|
---|
57 | if(!write_cmd_vg(ins76,NULL) || !status_ok(cta_res+2)) return;
|
---|
58 | ins76[3]=0; ins76[4]=0;
|
---|
59 | int num=cta_res[1];
|
---|
60 | int i;
|
---|
61 |
|
---|
62 | for(i=0; i<num; i++) {
|
---|
63 | ins76[2]=i;
|
---|
64 | l=vg12_do_cmd(reader,ins76,NULL,NULL,cta_res);
|
---|
65 | if(l<0 || !status_ok(cta_res+l)) return;
|
---|
66 | if(cta_res[2]==0 && cta_res[3]==0) break;
|
---|
67 | int y,m,d,H,M,S;
|
---|
68 | rev_date_calc(&cta_res[4],&y,&m,&d,&H,&M,&S,reader->card_baseyear);
|
---|
69 | unsigned short tier_id = (cta_res[2] << 8) | cta_res[3];
|
---|
70 | char *tier_name = get_tiername(tier_id, reader->caid[0]);
|
---|
71 | cs_ri_log(reader, "tier: %04x, expiry date: %04d/%02d/%02d-%02d:%02d:%02d %s",tier_id,y,m,d,H,M,S,tier_name);
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | static int videoguard12_card_init(struct s_reader * reader, ATR newatr)
|
---|
76 | {
|
---|
77 |
|
---|
78 | get_hist;
|
---|
79 | if ((hist_size < 7) || (hist[1] != 0xB0) || (hist[4] != 0xFF) || (hist[5] != 0x4A) || (hist[6] != 0x50)){
|
---|
80 | cs_debug("failed history check");
|
---|
81 | return ERROR;
|
---|
82 | }
|
---|
83 | cs_debug("passed history check");
|
---|
84 |
|
---|
85 | get_atr;
|
---|
86 | def_resp;
|
---|
87 |
|
---|
88 | /* set information on the card stored in reader-videoguard-common.c */
|
---|
89 | set_known_card_info(reader,atr,&atr_size);
|
---|
90 |
|
---|
91 | if((reader->ndsversion != NDS12) && ((reader->card_system_version != NDS12) || (reader->ndsversion != NDSAUTO))) {
|
---|
92 | /* known ATR and not NDS1+
|
---|
93 | or unknown ATR and not forced to NDS1+
|
---|
94 | or known NDS1+ ATR and forced to another NDS version
|
---|
95 | ... probably not NDS1+ */
|
---|
96 | return ERROR;
|
---|
97 | }
|
---|
98 |
|
---|
99 | cs_debug("type: %s, baseyear: %i", reader->card_desc, reader->card_baseyear);
|
---|
100 | if(reader->ndsversion == NDS12){
|
---|
101 | cs_debug("forced to NDS1+");
|
---|
102 | }
|
---|
103 |
|
---|
104 | int l = 1;
|
---|
105 |
|
---|
106 | /* NDS1 and NDS1+ cards return XX 90 00 to this command NDS2 cards fail to respond to this*/
|
---|
107 | static const unsigned char ins3601[5] = { 0x48,0x36,0x01,0x00,0x01 };
|
---|
108 | if(!write_cmd_vg(ins3601,NULL) || !status_ok(cta_res+l)) {
|
---|
109 | return ERROR; // not a possible NDS1+ card
|
---|
110 | }
|
---|
111 |
|
---|
112 | static const unsigned char dummy_cmd_table[132] = {
|
---|
113 | 0x01, 0x82, 0x20, 0x01,
|
---|
114 | 0x48, 0x0E, 0xFF, 0x02,
|
---|
115 | 0x48, 0x18, 0x0C, 0x01,
|
---|
116 | 0x48, 0x1A, 0x08, 0x03,
|
---|
117 | 0x48, 0x1E, 0x09, 0x03,
|
---|
118 | 0x48, 0x2E, 0xFF, 0x00,
|
---|
119 | 0x48, 0x32, 0x01, 0x01,
|
---|
120 | 0x48, 0x36, 0xFF, 0x02,
|
---|
121 | 0x48, 0x38, 0x02, 0x03,
|
---|
122 | 0x48, 0x40, 0xFF, 0x00,
|
---|
123 | 0x48, 0x42, 0xFF, 0x00,
|
---|
124 | 0x48, 0x44, 0x35, 0x01,
|
---|
125 | 0x48, 0x46, 0xFF, 0x00,
|
---|
126 | 0x48, 0x4A, 0xFF, 0x00,
|
---|
127 | 0x48, 0x4C, 0x09, 0x01,
|
---|
128 | 0x48, 0x4E, 0x05, 0x03,
|
---|
129 | 0x48, 0x50, 0xFF, 0x02,
|
---|
130 | 0x48, 0x54, 0x2C, 0x03,
|
---|
131 | 0x48, 0x56, 0xFF, 0x02,
|
---|
132 | 0x48, 0x58, 0x4A, 0x03,
|
---|
133 | 0x48, 0x5A, 0xFF, 0x02,
|
---|
134 | 0x48, 0x5C, 0x04, 0x03,
|
---|
135 | 0x48, 0x5E, 0xFF, 0x02,
|
---|
136 | 0x48, 0x70, 0x25, 0x03,
|
---|
137 | 0x48, 0x72, 0x23, 0x03,
|
---|
138 | 0x48, 0x74, 0xFF, 0x02,
|
---|
139 | 0x48, 0x76, 0x0A, 0x03,
|
---|
140 | 0x48, 0x78, 0x18, 0x03,
|
---|
141 | 0x48, 0x7A, 0xFF, 0x00,
|
---|
142 | 0x48, 0x7C, 0xFF, 0x02,
|
---|
143 | 0x48, 0xB4, 0x40, 0x01,
|
---|
144 | 0x48, 0xBC, 0x50, 0x03,
|
---|
145 | 0x48, 0xBE, 0x10, 0x03 };
|
---|
146 |
|
---|
147 | memorize_cmd_table (reader,dummy_cmd_table,132);
|
---|
148 |
|
---|
149 | unsigned char buff[256];
|
---|
150 |
|
---|
151 | // Read card serial number to check the card
|
---|
152 | unsigned char ins52[5] = { 0x48,0x52,0x00,0x00,0x14 };
|
---|
153 |
|
---|
154 | if(!write_cmd_vg(ins52,NULL) || !status_ok(cta_res+0x14)) {
|
---|
155 | cs_log ("class48 ins52: failed to read serial");
|
---|
156 | return ERROR;
|
---|
157 | }
|
---|
158 |
|
---|
159 | static const unsigned char ins36[5] = { 0x48,0x36,0x00,0x00,0x00 };
|
---|
160 | unsigned char boxID [4];
|
---|
161 |
|
---|
162 | if (reader->boxid > 0) {
|
---|
163 | /* the boxid is specified in the config */
|
---|
164 | int i;
|
---|
165 | for (i=0; i < 4; i++) {
|
---|
166 | boxID[i] = (reader->boxid >> (8 * (3 - i))) % 0x100;
|
---|
167 | }
|
---|
168 | } else {
|
---|
169 | /* we can try to get the boxid from the card */
|
---|
170 | int boxidOK=0;
|
---|
171 | l=vg12_do_cmd(reader,ins36,NULL,buff,cta_res);
|
---|
172 | if(l<13)
|
---|
173 | cs_log("class48 ins36: too short answer");
|
---|
174 | else if (buff[7] > 0x0F)
|
---|
175 | cs_log("class48 ins36: encrypted - can't parse");
|
---|
176 | else {
|
---|
177 | /* skipping the initial fixed fields: cmdecho (4) + length (1) + encr/rev++ (4) */
|
---|
178 | int i=9;
|
---|
179 | int gotUA=0;
|
---|
180 | while (i<l) {
|
---|
181 | if (!gotUA && buff[i]<0xF0) { /* then we guess that the next 4 bytes is the UA */
|
---|
182 | gotUA=1;
|
---|
183 | i+=4;
|
---|
184 | } else switch (buff[i]) { /* object length vary depending on type */
|
---|
185 | case 0x00: /* padding */
|
---|
186 | i+=1;
|
---|
187 | break;
|
---|
188 | case 0xEF: /* card status */
|
---|
189 | i+=3;
|
---|
190 | break;
|
---|
191 | case 0xD1:
|
---|
192 | i+=4;
|
---|
193 | break;
|
---|
194 | case 0xDF: /* next server contact */
|
---|
195 | i+=5;
|
---|
196 | break;
|
---|
197 | case 0xF3: /* boxID */
|
---|
198 | memcpy(boxID,buff+i+1,sizeof(boxID));
|
---|
199 | boxidOK=1;
|
---|
200 | i+=5;
|
---|
201 | break;
|
---|
202 | case 0xF6:
|
---|
203 | i+=6;
|
---|
204 | break;
|
---|
205 | case 0x01: /* date & time */
|
---|
206 | i+=7;
|
---|
207 | break;
|
---|
208 | case 0xFA:
|
---|
209 | i+=9;
|
---|
210 | break;
|
---|
211 | case 0x5E:
|
---|
212 | case 0x67: /* signature */
|
---|
213 | case 0xDE:
|
---|
214 | case 0xE2:
|
---|
215 | case 0xE9: /* tier dates */
|
---|
216 | case 0xF8: /* Old PPV Event Record */
|
---|
217 | case 0xFD:
|
---|
218 | i+=buff[i+1]+2; /* skip length + 2 bytes (type and length) */
|
---|
219 | break;
|
---|
220 | default: /* default to assume a length byte */
|
---|
221 | cs_log("class48 ins36: returned unknown type=0x%02X - parsing may fail", buff[i]);
|
---|
222 | i+=buff[i+1]+2;
|
---|
223 | }
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | if(!boxidOK) {
|
---|
228 | cs_log ("no boxID available");
|
---|
229 | return ERROR;
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | static const unsigned char ins4C[5] = { 0x48,0x4C,0x00,0x00,0x09 };
|
---|
234 | unsigned char payload4C[9] = { 0,0,0,0, 3,0,0,0,4 };
|
---|
235 | memcpy(payload4C,boxID,4);
|
---|
236 | if(!write_cmd_vg(ins4C,payload4C) || !status_ok(cta_res+l)) {
|
---|
237 | cs_log("class48 ins4C: failed - sending boxid failed");
|
---|
238 | return ERROR;
|
---|
239 | }
|
---|
240 |
|
---|
241 | static const unsigned char ins58[5] = { 0x48,0x58,0x00,0x00,0x00 };
|
---|
242 | l=vg12_do_cmd(reader,ins58,NULL,buff,cta_res);
|
---|
243 | if(l<0) {
|
---|
244 | cs_log("class48 ins58: failed");
|
---|
245 | return ERROR;
|
---|
246 | }
|
---|
247 | memset(reader->hexserial, 0, 8);
|
---|
248 | memcpy(reader->hexserial+2, cta_res+3, 4);
|
---|
249 | memcpy(reader->sa, cta_res+3, 3);
|
---|
250 | reader->caid[0] = cta_res[24]*0x100+cta_res[25];
|
---|
251 |
|
---|
252 | /* we have one provider, 0x0000 */
|
---|
253 | reader->nprov = 1;
|
---|
254 | memset(reader->prid, 0x00, sizeof(reader->prid));
|
---|
255 |
|
---|
256 | static const unsigned char insBE[5] = { 0x4B,0xBE,0x00,0x00,0x00 };
|
---|
257 | l=vg12_do_cmd(reader,insBE,NULL,NULL,cta_res);
|
---|
258 | if(l<0) {
|
---|
259 | cs_log("class4B insBE: failed");
|
---|
260 | return ERROR;
|
---|
261 | }
|
---|
262 |
|
---|
263 | cs_ri_log(reader, "type: %s, caid: %04X",
|
---|
264 | reader->card_desc,
|
---|
265 | reader->caid[0]);
|
---|
266 | cs_ri_log(reader, "serial: %02X%02X%02X%02X, BoxID: %02X%02X%02X%02X, baseyear: %i",
|
---|
267 | reader->hexserial[2],reader->hexserial[3],reader->hexserial[4],reader->hexserial[5],
|
---|
268 | boxID[0],boxID[1],boxID[2],boxID[3],
|
---|
269 | reader->card_baseyear);
|
---|
270 | cs_log("ready for requests");
|
---|
271 |
|
---|
272 | return OK;
|
---|
273 | }
|
---|
274 |
|
---|
275 | static int videoguard12_do_ecm(struct s_reader * reader, ECM_REQUEST *er)
|
---|
276 | {
|
---|
277 | unsigned char cta_res[CTA_RES_LEN];
|
---|
278 | unsigned char ins40[5] = { 0x49,0x40,0x00,0x80,0xFF };
|
---|
279 | static const unsigned char ins54[5] = { 0x4B,0x54,0x00,0x00,0x00};
|
---|
280 | int posECMpart2=er->ecm[6]+7;
|
---|
281 | int lenECMpart2=er->ecm[posECMpart2]+1;
|
---|
282 | unsigned char tbuff[264], rbuff[264];
|
---|
283 | tbuff[0]=0;
|
---|
284 |
|
---|
285 | memset(er->cw+0,0,16); //set cw to 0 so client will know it is invalid unless it is overwritten with a valid cw
|
---|
286 | memcpy(tbuff+1,er->ecm+posECMpart2+1,lenECMpart2-1);
|
---|
287 |
|
---|
288 | ins40[4]=lenECMpart2;
|
---|
289 | int l;
|
---|
290 |
|
---|
291 | l = vg12_do_cmd(reader,ins40,tbuff,NULL,cta_res);
|
---|
292 | if(l<0 || !status_ok(cta_res)) {
|
---|
293 | cs_log ("class49 ins40: (%d) status not ok %02x %02x",l,cta_res[0],cta_res[1]);
|
---|
294 | return ERROR;
|
---|
295 | } else {
|
---|
296 | l = vg12_do_cmd(reader,ins54,NULL,rbuff,cta_res);
|
---|
297 | if(l<0 || !status_ok(cta_res+l)) {
|
---|
298 | cs_log("class4B ins54: (%d) status not ok %02x %02x",l,cta_res[0],cta_res[1]);
|
---|
299 | return ERROR;
|
---|
300 | } else {
|
---|
301 |
|
---|
302 | if (!cw_is_valid(rbuff+5,0)){ //sky cards report 90 00 = ok but send cw = 00 when channel not subscribed
|
---|
303 | cs_log("class4B ins54: status 90 00 = ok but cw=00 -> channel not subscribed " );
|
---|
304 | return ERROR;
|
---|
305 | }
|
---|
306 |
|
---|
307 | // copy cw1 in place
|
---|
308 | memcpy(er->cw+0,rbuff+5,8);
|
---|
309 |
|
---|
310 | if(er->ecm[0]&1) {
|
---|
311 | unsigned char tmpcw[8];
|
---|
312 | memcpy(tmpcw,er->cw+8,8);
|
---|
313 | memcpy(er->cw+8,er->cw+0,8);
|
---|
314 | memcpy(er->cw+0,tmpcw,8);
|
---|
315 | }
|
---|
316 |
|
---|
317 | return OK;
|
---|
318 | }
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | static int videoguard12_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr)
|
---|
323 | {
|
---|
324 |
|
---|
325 | /*
|
---|
326 | 82 30 ad 70 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 00
|
---|
327 | 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
|
---|
328 | 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
|
---|
329 | 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
|
---|
330 | 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
|
---|
331 | */
|
---|
332 |
|
---|
333 | int i, pos;
|
---|
334 | int serial_count = ((ep->emm[3] >> 4) & 3) + 1;
|
---|
335 | int serial_len = (ep->emm[3] & 0x80) ? 3 : 4;
|
---|
336 | uchar emmtype = (ep->emm[3] & VG_EMMTYPE_MASK) >> 6;
|
---|
337 |
|
---|
338 | pos = 4 + (serial_len * serial_count) + 2;
|
---|
339 |
|
---|
340 | switch(emmtype) {
|
---|
341 | case VG_EMMTYPE_G:
|
---|
342 | ep->type=GLOBAL;
|
---|
343 | cs_debug_mask(D_EMM, "EMM: GLOBAL");
|
---|
344 | return TRUE;
|
---|
345 |
|
---|
346 | case VG_EMMTYPE_U:
|
---|
347 | cs_debug_mask(D_EMM, "EMM: UNIQUE");
|
---|
348 | ep->type=UNIQUE;
|
---|
349 | if (ep->emm[1] == 0) // detected UNIQUE EMM from cccam (there is no serial)
|
---|
350 | return TRUE;
|
---|
351 |
|
---|
352 | for (i = 1;i <= serial_count;i++) {
|
---|
353 | if (!memcmp (rdr->hexserial + 2, ep->emm + (serial_len * i), serial_len)) {
|
---|
354 | memcpy(ep->hexserial, ep->emm + (serial_len * i), serial_len);
|
---|
355 | return TRUE;
|
---|
356 | }
|
---|
357 |
|
---|
358 | pos = pos + ep->emm[pos+5] + 5;
|
---|
359 | }
|
---|
360 | return FALSE; // if UNIQUE but no serial match return FALSE
|
---|
361 |
|
---|
362 | case VG_EMMTYPE_S:
|
---|
363 | ep->type=SHARED;
|
---|
364 | cs_debug_mask(D_EMM, "EMM: SHARED");
|
---|
365 | return TRUE; // FIXME: no check for SA
|
---|
366 |
|
---|
367 | default:
|
---|
368 | if (ep->emm[pos-2] != 0x00 && ep->emm[pos-1] != 0x00 && ep->emm[pos-1] != 0x01) {
|
---|
369 | //remote emm without serial
|
---|
370 | ep->type=UNKNOWN;
|
---|
371 | return TRUE;
|
---|
372 | }
|
---|
373 | return FALSE;
|
---|
374 | }
|
---|
375 | }
|
---|
376 |
|
---|
377 | static void videoguard12_get_emm_filter(struct s_reader * rdr, uchar *filter)
|
---|
378 | {
|
---|
379 | filter[0]=0xFF;
|
---|
380 | filter[1]=3;
|
---|
381 |
|
---|
382 | //ToDo videoguard12_get_emm_filter basic construction
|
---|
383 |
|
---|
384 | filter[2]=UNIQUE;
|
---|
385 | filter[3]=0;
|
---|
386 |
|
---|
387 | filter[4+0] = 0x82;
|
---|
388 | filter[4+0+16] = 0xFF;
|
---|
389 |
|
---|
390 | memcpy(filter+4+2, rdr->hexserial+2, 4);
|
---|
391 | memset(filter+4+2+16, 0xFF, 4);
|
---|
392 |
|
---|
393 |
|
---|
394 | filter[36]=UNIQUE;
|
---|
395 | filter[37]=0;
|
---|
396 |
|
---|
397 | filter[38+0] = 0x82;
|
---|
398 | filter[38+0+16] = 0xFF;
|
---|
399 |
|
---|
400 | memcpy(filter+38+6, rdr->hexserial+2, 4);
|
---|
401 | memset(filter+38+6+16, 0xFF, 4);
|
---|
402 |
|
---|
403 |
|
---|
404 | filter[70]=UNIQUE;
|
---|
405 | filter[71]=0;
|
---|
406 |
|
---|
407 | filter[72+0] = 0x82;
|
---|
408 | filter[72+0+16] = 0xFF;
|
---|
409 |
|
---|
410 | memcpy(filter+72+10, rdr->hexserial+2, 4);
|
---|
411 | memset(filter+72+10+16, 0xFF, 4);
|
---|
412 |
|
---|
413 |
|
---|
414 | /* filter[104]=UNIQUE;
|
---|
415 | filter[105]=0;
|
---|
416 |
|
---|
417 | filter[106+0] = 0x82;
|
---|
418 | filter[106+0+16] = 0xFF;
|
---|
419 |
|
---|
420 | memcpy(filter+106+14, rdr->hexserial+2, 2);
|
---|
421 | memset(filter+106+14+16, 0xFF, 2); */
|
---|
422 |
|
---|
423 | return;
|
---|
424 | }
|
---|
425 |
|
---|
426 | static int videoguard12_do_emm(struct s_reader * reader, EMM_PACKET *ep)
|
---|
427 | {
|
---|
428 | unsigned char cta_res[CTA_RES_LEN];
|
---|
429 | unsigned char ins42[5] = { 0x49,0x42,0x00,0x00,0xFF };
|
---|
430 | int rc=ERROR;
|
---|
431 |
|
---|
432 | const unsigned char *payload = payload_addr(ep->type, ep->emm, reader->hexserial);
|
---|
433 | while (payload) {
|
---|
434 | ins42[4]=*payload;
|
---|
435 | int l = vg12_do_cmd(reader,ins42,payload+1,NULL,cta_res);
|
---|
436 | if(l>0 && status_ok(cta_res)) {
|
---|
437 | rc=OK;
|
---|
438 | }
|
---|
439 |
|
---|
440 | cs_debug_mask(D_EMM, "EMM request return code : %02X%02X", cta_res[0], cta_res[1]);
|
---|
441 | //cs_dump(ep->emm, 64, "EMM:");
|
---|
442 | if (status_ok (cta_res) && (cta_res[1] & 0x01)) {
|
---|
443 | read_tiers(reader);
|
---|
444 | }
|
---|
445 |
|
---|
446 | if (num_addr(ep->emm) == 1 && (int)(&payload[1] - &ep->emm[0]) + *payload + 1 < ep->l) {
|
---|
447 | payload += *payload + 1;
|
---|
448 | if (*payload == 0x00) ++payload;
|
---|
449 | ++payload;
|
---|
450 | if (*payload != 0x02) break;
|
---|
451 | payload += 2 + payload[1];
|
---|
452 | }
|
---|
453 | else
|
---|
454 | payload = 0;
|
---|
455 |
|
---|
456 | }
|
---|
457 |
|
---|
458 | return(rc);
|
---|
459 | }
|
---|
460 |
|
---|
461 | static int videoguard12_card_info(struct s_reader * reader)
|
---|
462 | {
|
---|
463 | /* info is displayed in init, or when processing info */
|
---|
464 | cs_log("card detected");
|
---|
465 | cs_log("type: %s", reader->card_desc);
|
---|
466 | read_tiers (reader);
|
---|
467 | return OK;
|
---|
468 | }
|
---|
469 |
|
---|
470 | void reader_videoguard12(struct s_cardsystem *ph)
|
---|
471 | {
|
---|
472 | ph->do_emm=videoguard12_do_emm;
|
---|
473 | ph->do_ecm=videoguard12_do_ecm;
|
---|
474 | ph->card_info=videoguard12_card_info;
|
---|
475 | ph->card_init=videoguard12_card_init;
|
---|
476 | ph->get_emm_type=videoguard12_get_emm_type;
|
---|
477 | ph->get_emm_filter=videoguard12_get_emm_filter;
|
---|
478 | ph->caids[0]=0x09;
|
---|
479 | }
|
---|