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 | static const unsigned char ins2a[5] = { 0xd0,0x2a,0x00,0x00,0x00 };
|
---|
10 | int l;
|
---|
11 | l=do_cmd(reader, ins2a,NULL,NULL,cta_res);
|
---|
12 | if(l<0 || !status_ok(cta_res+l)) return;
|
---|
13 | static unsigned char ins76[5] = { 0xd0,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,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,VG_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, "[videoguard2-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 |
|
---|
36 | int videoguard2_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 | get_atr;
|
---|
44 | def_resp;
|
---|
45 |
|
---|
46 | /* get information on the card from reader-videoguard-common.c */
|
---|
47 | NDS_ATR_ENTRY nds_atr_entry = {{0},0,0,0,0};
|
---|
48 | memcpy(nds_atr_entry.atr,atr,atr_size);
|
---|
49 | nds_atr_entry.atr_len = atr_size;
|
---|
50 |
|
---|
51 | getNdsAtrEntry(&nds_atr_entry);
|
---|
52 |
|
---|
53 | if((reader->ndsversion != NDS2) &&
|
---|
54 | (((nds_atr_entry.nds_version != NDS2) && (nds_atr_entry.nds_version != NDSUNKNOWN)) ||
|
---|
55 | (reader->ndsversion != NDSAUTO))) {
|
---|
56 | /* known ATR and not NDS2
|
---|
57 | or known NDS2 ATR and forced to another NDS version */
|
---|
58 | return ERROR;
|
---|
59 | }
|
---|
60 |
|
---|
61 | if(reader->ndsversion == NDS2){
|
---|
62 | cs_ri_log(reader, "[videoguard2-reader] Forced to NDS2");
|
---|
63 | }
|
---|
64 |
|
---|
65 | if (nds_atr_entry.desc){
|
---|
66 | VG_BASEYEAR=nds_atr_entry.base_year;
|
---|
67 | cs_ri_log(reader, "[videoguard2-reader] type: %s", nds_atr_entry.desc);
|
---|
68 | }
|
---|
69 |
|
---|
70 | //a non videoguard2/NDS2 card will fail on read_cmd_len(ins7401)
|
---|
71 | //this way unknown videoguard2/NDS2 cards will also pass this check
|
---|
72 |
|
---|
73 | unsigned char ins7401[5] = { 0xD0,0x74,0x01,0x00,0x00 };
|
---|
74 | int l;
|
---|
75 | ins7401[3]=0x80; // from newcs log
|
---|
76 | ins7401[4]=0x01;
|
---|
77 | if((l=read_cmd_len(reader, ins7401))<0) return ERROR; //not a videoguard2/NDS card or communication error
|
---|
78 | ins7401[3]=0x00;
|
---|
79 | ins7401[4]=l;
|
---|
80 | if(!write_cmd_vg(ins7401,NULL) || !status_ok(cta_res+l)) {
|
---|
81 | cs_log ("[videoguard2-reader] failed to read cmd list");
|
---|
82 | return ERROR;
|
---|
83 | }
|
---|
84 |
|
---|
85 | memorize_cmd_table (cta_res,l);
|
---|
86 |
|
---|
87 | unsigned char buff[256];
|
---|
88 |
|
---|
89 | unsigned char ins7416[5] = { 0xD0,0x74,0x16,0x00,0x00 };
|
---|
90 | if(do_cmd(reader, ins7416, NULL, NULL,cta_res)<0) {
|
---|
91 | cs_log ("[videoguard2-reader] cmd 7416 failed");
|
---|
92 | return ERROR;
|
---|
93 | }
|
---|
94 |
|
---|
95 | unsigned char ins36[5] = { 0xD0,0x36,0x00,0x00,0x00 };
|
---|
96 | unsigned char boxID [4];
|
---|
97 |
|
---|
98 | if (reader->boxid > 0) {
|
---|
99 | /* the boxid is specified in the config */
|
---|
100 | int i;
|
---|
101 | for (i=0; i < 4; i++) {
|
---|
102 | boxID[i] = (reader->boxid >> (8 * (3 - i))) % 0x100;
|
---|
103 | }
|
---|
104 | } else {
|
---|
105 | /* we can try to get the boxid from the card */
|
---|
106 | int boxidOK=0;
|
---|
107 | l=do_cmd(reader, ins36, NULL, buff,cta_res);
|
---|
108 | if(l<13)
|
---|
109 | cs_log("[videoguard2-reader] ins36: too short answer");
|
---|
110 | else if (buff[7] > 0x0F)
|
---|
111 | cs_log("[videoguard2-reader] ins36: encrypted - can't parse");
|
---|
112 | else {
|
---|
113 | /* skipping the initial fixed fields: cmdecho (4) + length (1) + encr/rev++ (4) */
|
---|
114 | int i=9;
|
---|
115 | int gotUA=0;
|
---|
116 | while (i<l) {
|
---|
117 | if (!gotUA && buff[i]<0xF0) { /* then we guess that the next 4 bytes is the UA */
|
---|
118 | gotUA=1;
|
---|
119 | i+=4;
|
---|
120 | } else switch (buff[i]) { /* object length vary depending on type */
|
---|
121 | case 0x00: /* padding */
|
---|
122 | i+=1;
|
---|
123 | break;
|
---|
124 | case 0xEF: /* card status */
|
---|
125 | i+=3;
|
---|
126 | break;
|
---|
127 | case 0xD1:
|
---|
128 | i+=4;
|
---|
129 | break;
|
---|
130 | case 0xDF: /* next server contact */
|
---|
131 | i+=5;
|
---|
132 | break;
|
---|
133 | case 0xF3: /* boxID */
|
---|
134 | memcpy(&boxID,&buff[i+1],sizeof(boxID));
|
---|
135 | boxidOK=1;
|
---|
136 | i+=5;
|
---|
137 | break;
|
---|
138 | case 0xF6:
|
---|
139 | i+=6;
|
---|
140 | break;
|
---|
141 | case 0x01: /* date & time */
|
---|
142 | i+=7;
|
---|
143 | break;
|
---|
144 | case 0xFA:
|
---|
145 | i+=9;
|
---|
146 | break;
|
---|
147 | case 0x5E:
|
---|
148 | case 0x67: /* signature */
|
---|
149 | case 0xDE:
|
---|
150 | case 0xE2:
|
---|
151 | case 0xE9: /* tier dates */
|
---|
152 | case 0xF8: /* Old PPV Event Record */
|
---|
153 | case 0xFD:
|
---|
154 | i+=buff[i+1]+2; /* skip length + 2 bytes (type and length) */
|
---|
155 | break;
|
---|
156 | default: /* default to assume a length byte */
|
---|
157 | cs_log("[videoguard2-reader] ins36 returned unknown type=0x%02X - parsing may fail", buff[i]);
|
---|
158 | i+=buff[i+1]+2;
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | if(!boxidOK) {
|
---|
164 | cs_log ("[videoguard2-reader] no boxID available");
|
---|
165 | return ERROR;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | unsigned char ins4C[5] = { 0xD0,0x4C,0x00,0x00,0x09 };
|
---|
170 | unsigned char payload4C[9] = { 0,0,0,0, 3,0,0,0,4 };
|
---|
171 | memcpy(payload4C,boxID,4);
|
---|
172 | if(!write_cmd_vg(ins4C,payload4C) || !status_ok(cta_res+l)) {
|
---|
173 | cs_log("[videoguard2-reader] sending boxid failed");
|
---|
174 | return ERROR;
|
---|
175 | }
|
---|
176 | // Start of suggested fix for 09ac cards
|
---|
177 | unsigned char Dimeno_Magic[0x10]={0xF9,0xFB,0xCD,0x5A,0x76,0xB5,0xC4,0x5C,0xC8,0x2E,0x1D,0xE1,0xCC,0x5B,0x6B,0x02};
|
---|
178 | int a;
|
---|
179 | for(a=0; a<4; a++)
|
---|
180 | Dimeno_Magic[a]=Dimeno_Magic[a]^boxID[a];
|
---|
181 | //I supposed to declare a AES_KEY Astro_Key somewhere before...
|
---|
182 | AES_set_decrypt_key(Dimeno_Magic,128,&Astro_Key);
|
---|
183 | Astro_Key.rounds=10;
|
---|
184 | //Important for ecm decryption...
|
---|
185 | // End of suggested fix
|
---|
186 |
|
---|
187 | //short int SWIRDstatus = cta_res[1];
|
---|
188 | unsigned char ins58[5] = { 0xD0,0x58,0x00,0x00,0x00 };
|
---|
189 | l=do_cmd(reader, ins58, NULL, buff,cta_res);
|
---|
190 | if(l<0) {
|
---|
191 | cs_log("[videoguard2-reader] cmd ins58 failed");
|
---|
192 | return ERROR;
|
---|
193 | }
|
---|
194 | memset(reader->hexserial, 0, 8);
|
---|
195 | memcpy(reader->hexserial+2, cta_res+3, 4);
|
---|
196 | memcpy(reader->sa, cta_res+3, 3);
|
---|
197 | reader->caid[0] = cta_res[24]*0x100+cta_res[25];
|
---|
198 |
|
---|
199 | /* we have one provider, 0x0000 */
|
---|
200 | reader->nprov = 1;
|
---|
201 | memset(reader->prid, 0x00, sizeof(reader->prid));
|
---|
202 |
|
---|
203 | /*
|
---|
204 | cs_log ("[videoguard2-reader] INS58 : Fuse byte=0x%02X, IRDStatus=0x%02X", cta_res[2],SWIRDstatus);
|
---|
205 | if (SWIRDstatus==4) {
|
---|
206 | // If swMarriage=4, not married then exchange for BC Key
|
---|
207 | cs_log ("[videoguard2-reader] Card not married, exchange for BC Keys");
|
---|
208 | */
|
---|
209 |
|
---|
210 | static unsigned char seed1[] = {
|
---|
211 | 0xb9, 0xd5, 0xef, 0xd5, 0xf5, 0xd5, 0xfb, 0xd5, 0x31, 0xd6, 0x43, 0xd6, 0x55, 0xd6, 0x61, 0xd6,
|
---|
212 | 0x85, 0xd6, 0x9d, 0xd6, 0xaf, 0xd6, 0xc7, 0xd6, 0xd9, 0xd6, 0x09, 0xd7, 0x15, 0xd7, 0x21, 0xd7,
|
---|
213 | 0x27, 0xd7, 0x3f, 0xd7, 0x45, 0xd7, 0xb1, 0xd7, 0xbd, 0xd7, 0xdb, 0xd7, 0x11, 0xd8, 0x23, 0xd8,
|
---|
214 | 0x29, 0xd8, 0x2f, 0xd8, 0x4d, 0xd8, 0x8f, 0xd8, 0xa1, 0xd8, 0xad, 0xd8, 0xbf, 0xd8, 0xd7, 0xd8
|
---|
215 | };
|
---|
216 | static unsigned char seed2[] = {
|
---|
217 | 0x01, 0x00, 0xcf, 0x13, 0xe0, 0x60, 0x54, 0xac, 0xab, 0x99, 0xe6, 0x0c, 0x9f, 0x5b, 0x91, 0xb9,
|
---|
218 | 0x72, 0x72, 0x4d, 0x5b, 0x5f, 0xd3, 0xb7, 0x5b, 0x01, 0x4d, 0xef, 0x9e, 0x6b, 0x8a, 0xb9, 0xd1,
|
---|
219 | 0xc9, 0x9f, 0xa1, 0x2a, 0x8d, 0x86, 0xb6, 0xd6, 0x39, 0xb4, 0x64, 0x65, 0x13, 0x77, 0xa1, 0x0a,
|
---|
220 | 0x0c, 0xcf, 0xb4, 0x2b, 0x3a, 0x2f, 0xd2, 0x09, 0x92, 0x15, 0x40, 0x47, 0x66, 0x5c, 0xda, 0xc9
|
---|
221 | };
|
---|
222 | cCamCryptVG_SetSeed(seed1,seed2);
|
---|
223 |
|
---|
224 | unsigned char insB4[5] = { 0xD0,0xB4,0x00,0x00,0x40 };
|
---|
225 | unsigned char tbuff[64];
|
---|
226 | cCamCryptVG_GetCamKey(tbuff);
|
---|
227 | l=do_cmd(reader, insB4, tbuff, NULL,cta_res);
|
---|
228 | if(l<0 || !status_ok(cta_res)) {
|
---|
229 | cs_log ("[videoguard2-reader] cmd D0B4 failed (%02X%02X)", cta_res[0], cta_res[1]);
|
---|
230 | return ERROR;
|
---|
231 | }
|
---|
232 |
|
---|
233 | unsigned char insBC[5] = { 0xD0,0xBC,0x00,0x00,0x00 };
|
---|
234 | l=do_cmd(reader, insBC, NULL, NULL,cta_res);
|
---|
235 | if(l<0) {
|
---|
236 | cs_log("[videoguard2-reader] cmd D0BC failed");
|
---|
237 | return ERROR;
|
---|
238 | }
|
---|
239 |
|
---|
240 | unsigned char insBE[5] = { 0xD3,0xBE,0x00,0x00,0x00 };
|
---|
241 | l=do_cmd(reader, insBE, NULL, NULL,cta_res);
|
---|
242 | if(l<0) {
|
---|
243 | cs_log("[videoguard2-reader] cmd D3BE failed");
|
---|
244 | return ERROR;
|
---|
245 | }
|
---|
246 |
|
---|
247 | unsigned char ins58a[5] = { 0xD1,0x58,0x00,0x00,0x00 };
|
---|
248 | l=do_cmd(reader, ins58a, NULL, NULL,cta_res);
|
---|
249 | if(l<0) {
|
---|
250 | cs_log("[videoguard2-reader] cmd D158 failed");
|
---|
251 | return ERROR;
|
---|
252 | }
|
---|
253 |
|
---|
254 | unsigned char ins4Ca[5] = { 0xD1,0x4C,0x00,0x00,0x00 };
|
---|
255 | l=do_cmd(reader, ins4Ca,payload4C, NULL,cta_res);
|
---|
256 | if(l<0 || !status_ok(cta_res)) {
|
---|
257 | cs_log("[videoguard2-reader] cmd D14Ca failed");
|
---|
258 | return ERROR;
|
---|
259 | }
|
---|
260 |
|
---|
261 | cs_ri_log(reader, "[videoguard2-reader] type: VideoGuard, caid: %04X, serial: %02X%02X%02X%02X, BoxID: %02X%02X%02X%02X",
|
---|
262 | reader->caid[0],
|
---|
263 | reader->hexserial[2],reader->hexserial[3],reader->hexserial[4],reader->hexserial[5],
|
---|
264 | boxID[0],boxID[1],boxID[2],boxID[3]);
|
---|
265 |
|
---|
266 | cs_log("[videoguard2-reader] ready for requests");
|
---|
267 |
|
---|
268 | return OK;
|
---|
269 | }
|
---|
270 |
|
---|
271 | int videoguard2_do_ecm(struct s_reader * reader, ECM_REQUEST *er)
|
---|
272 | {
|
---|
273 | unsigned char cta_res[CTA_RES_LEN];
|
---|
274 | static unsigned char ins40[5] = { 0xD1,0x40,0x00,0x80,0xFF };
|
---|
275 | static const unsigned char ins54[5] = { 0xD3,0x54,0x00,0x00,0x00};
|
---|
276 | int posECMpart2=er->ecm[6]+7;
|
---|
277 | int lenECMpart2=er->ecm[posECMpart2]+1;
|
---|
278 | unsigned char tbuff[264];
|
---|
279 | tbuff[0]=0;
|
---|
280 | memcpy(&tbuff[1],&(er->ecm[posECMpart2+1]),lenECMpart2-1);
|
---|
281 | ins40[4]=lenECMpart2;
|
---|
282 | int l;
|
---|
283 | l = do_cmd(reader, ins40,tbuff,NULL,cta_res);
|
---|
284 | if(l>0 && status_ok(cta_res)) {
|
---|
285 | l = do_cmd(reader, ins54,NULL,NULL,cta_res);
|
---|
286 | if(l>0 && status_ok(cta_res+l)) {
|
---|
287 | if (!cw_is_valid(CW1)) //sky cards report 90 00 = ok but send cw = 00 when channel not subscribed
|
---|
288 | {
|
---|
289 | snprintf( er->msglog, MSGLOGSIZE, "9000 but cw=00 -> channel not subscribed " );
|
---|
290 | return ERROR;
|
---|
291 | }
|
---|
292 |
|
---|
293 | if(er->ecm[0]&1) {
|
---|
294 | memcpy(er->cw+8,CW1,8);
|
---|
295 | memcpy(er->cw+0,CW2,8);
|
---|
296 | }
|
---|
297 | else {
|
---|
298 | memcpy(er->cw+0,CW1,8);
|
---|
299 | memcpy(er->cw+8,CW2,8);
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | //test for postprocessing marker
|
---|
304 | int posB0 = -1;
|
---|
305 | int i;
|
---|
306 | for (i = 6; i < posECMpart2; i++)
|
---|
307 | {
|
---|
308 | 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) ) ) {
|
---|
309 | posB0 = i;
|
---|
310 | break;
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (posB0 != -1) {
|
---|
315 | do_post_dw_hash( er->cw+0, &er->ecm[posB0-2]);
|
---|
316 | do_post_dw_hash( er->cw+8, &er->ecm[posB0-2]);
|
---|
317 | }
|
---|
318 |
|
---|
319 | return OK;
|
---|
320 | }
|
---|
321 | }
|
---|
322 | snprintf( er->msglog, MSGLOGSIZE, "(%d) status not ok %02x %02x",l, cta_res[0],cta_res[1] );
|
---|
323 | return ERROR;
|
---|
324 | }
|
---|
325 |
|
---|
326 | static int num_addr(const unsigned char *data)
|
---|
327 | {
|
---|
328 | return ((data[3]&0x30)>>4)+1;
|
---|
329 | }
|
---|
330 | /*
|
---|
331 | Example of GLOBAL EMM's
|
---|
332 | This one has IRD-EMM + Card-EMM
|
---|
333 | 82 70 20 00 02 06 02 7D 0E 89 53 71 16 90 14 40
|
---|
334 | 01 ED 17 7D 9E 1F 28 CF 09 97 54 F1 8E 72 06 E7
|
---|
335 | 51 AF F5
|
---|
336 | This one has only IRD-EMM
|
---|
337 | 82 70 6D 00 07 69 01 30 07 14 5E 0F FF FF 00 06
|
---|
338 | 00 0D 01 00 03 01 00 00 00 0F 00 00 00 5E 01 00
|
---|
339 | 01 0C 2E 70 E4 55 B6 D2 34 F7 44 86 9E 5C 91 14
|
---|
340 | 81 FC DF CB D0 86 65 77 DF A9 E1 6B A8 9F 9B DE
|
---|
341 | 90 92 B9 AA 6C B3 4E 87 D2 EC 92 DA FC 71 EF 27
|
---|
342 | B3 C3 D0 17 CF 0B D6 5E 8C DB EB B3 37 55 6E 09
|
---|
343 | 7F 27 3C F1 85 29 C9 4E 0B EE DF 68 BE 00 C9 00
|
---|
344 | */
|
---|
345 | static const unsigned char *payload_addr(uchar emmtype, const unsigned char *data, const unsigned char *a)
|
---|
346 | {
|
---|
347 | int s;
|
---|
348 | int l;
|
---|
349 | const unsigned char *ptr = NULL;
|
---|
350 | int position=-1;
|
---|
351 | int numAddrs=0;
|
---|
352 |
|
---|
353 | switch(emmtype) {
|
---|
354 | case SHARED: s=3; break;
|
---|
355 | case UNIQUE: s=4; break;
|
---|
356 | default: s=0;
|
---|
357 | }
|
---|
358 |
|
---|
359 | numAddrs=num_addr(data);
|
---|
360 |
|
---|
361 | if(s>0) {
|
---|
362 | for(l=0;l<numAddrs;l++) {
|
---|
363 | if(!memcmp(&data[l*4+4],a+2,s)) {
|
---|
364 | position=l;
|
---|
365 | break;
|
---|
366 | }
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 | int num_filter = (position == -1) ? 0 : numAddrs;
|
---|
371 |
|
---|
372 | /* skip header and the filter list */
|
---|
373 | ptr = data+4+4*num_filter;
|
---|
374 |
|
---|
375 | if (*ptr != 0x02 && *ptr != 0x07) // some clients omit 00 00 separator */
|
---|
376 | {
|
---|
377 | ptr += 2; // skip 00 00 separator
|
---|
378 | if (*ptr == 0x00) ptr++; // skip optional 00
|
---|
379 | ptr++; // skip the 1st bitmap len
|
---|
380 | }
|
---|
381 |
|
---|
382 | /* check for IRD-EMM */
|
---|
383 | if (*ptr != 0x02 && *ptr != 0x07) return NULL;
|
---|
384 |
|
---|
385 | /* skip IRD-EMM part, 02 00 or 02 06 xx aabbccdd yy */
|
---|
386 | ptr += 2 + ptr[1];
|
---|
387 |
|
---|
388 | /* check for EMM boundaries - ptr should not exceed EMM length */
|
---|
389 | if ((int)(ptr - (data + 3)) >= data[2]) return NULL;
|
---|
390 |
|
---|
391 | for(l=0;l<position;l++) {
|
---|
392 | /* skip the payload of the previous sub-EMM */
|
---|
393 | ptr += 1 + ptr [0];
|
---|
394 |
|
---|
395 | /* check for EMM boundaries - ptr should not exceed EMM length */
|
---|
396 | if ((int)(ptr - (data + 3)) >= data[2]) return NULL;
|
---|
397 |
|
---|
398 | /* skip optional 00 */
|
---|
399 | if (*ptr == 0x00) ptr++;
|
---|
400 |
|
---|
401 | /* skip the bitmap len */
|
---|
402 | ptr++;
|
---|
403 |
|
---|
404 | /* check for IRD-EMM */
|
---|
405 | if (*ptr != 0x02 && *ptr != 0x07) return NULL;
|
---|
406 |
|
---|
407 | /* skip IRD-EMM part, 02 00 or 02 06 xx aabbccdd yy */
|
---|
408 | ptr += 2 + ptr[1];
|
---|
409 | }
|
---|
410 |
|
---|
411 | return ptr;
|
---|
412 | }
|
---|
413 |
|
---|
414 | int videoguard2_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr)
|
---|
415 | {
|
---|
416 |
|
---|
417 | /*
|
---|
418 | 82 30 ad 70 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 XX XX XX 00 00
|
---|
419 | 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
|
---|
420 | 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
|
---|
421 | 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
|
---|
422 | 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
|
---|
423 | */
|
---|
424 |
|
---|
425 | int i, pos;
|
---|
426 | int serial_count = ((ep->emm[3] >> 4) & 3) + 1;
|
---|
427 | int serial_len = (ep->emm[3] & 0x80) ? 3 : 4;
|
---|
428 | uchar emmtype = (ep->emm[3] & VG_EMMTYPE_MASK) >> 6;
|
---|
429 |
|
---|
430 | pos = 4 + (serial_len * serial_count) + 2;
|
---|
431 |
|
---|
432 | switch(emmtype) {
|
---|
433 | case VG_EMMTYPE_G:
|
---|
434 | ep->type=GLOBAL;
|
---|
435 | cs_debug_mask(D_EMM, "VIDEOGUARD2 EMM: GLOBAL");
|
---|
436 | return TRUE;
|
---|
437 |
|
---|
438 | case VG_EMMTYPE_U:
|
---|
439 | cs_debug_mask(D_EMM, "VIDEOGUARD2 EMM: UNIQUE");
|
---|
440 | ep->type=UNIQUE;
|
---|
441 | if (ep->emm[1] == 0) // detected UNIQUE EMM from cccam (there is no serial)
|
---|
442 | return TRUE;
|
---|
443 |
|
---|
444 | for (i = 1;i <= serial_count;i++) {
|
---|
445 | if (!memcmp (rdr->hexserial + 2, ep->emm + (serial_len * i), serial_len)) {
|
---|
446 | memcpy(ep->hexserial, ep->emm + (serial_len * i), serial_len);
|
---|
447 | return TRUE;
|
---|
448 | }
|
---|
449 |
|
---|
450 | pos = pos + ep->emm[pos+5] + 5;
|
---|
451 | }
|
---|
452 | return FALSE; // if UNIQUE but no serial match return FALSE
|
---|
453 |
|
---|
454 | case VG_EMMTYPE_S:
|
---|
455 | ep->type=SHARED;
|
---|
456 | cs_debug_mask(D_EMM, "VIDEOGUARD2 EMM: SHARED");
|
---|
457 | return TRUE; // FIXME: no check for SA
|
---|
458 |
|
---|
459 | default:
|
---|
460 | if (ep->emm[pos-2] != 0x00 && ep->emm[pos-1] != 0x00 && ep->emm[pos-1] != 0x01) {
|
---|
461 | //remote emm without serial
|
---|
462 | ep->type=UNKNOWN;
|
---|
463 | return TRUE;
|
---|
464 | }
|
---|
465 | return FALSE;
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | void videoguard2_get_emm_filter(struct s_reader * rdr, uchar *filter)
|
---|
470 | {
|
---|
471 | filter[0]=0xFF;
|
---|
472 | filter[1]=3;
|
---|
473 |
|
---|
474 | //ToDo videoguard2_get_emm_filter basic construction
|
---|
475 |
|
---|
476 | filter[2]=UNIQUE;
|
---|
477 | filter[3]=0;
|
---|
478 |
|
---|
479 | filter[4+0] = 0x82;
|
---|
480 | filter[4+0+16] = 0xFF;
|
---|
481 |
|
---|
482 | memcpy(filter+4+2, rdr->hexserial+2, 4);
|
---|
483 | memset(filter+4+2+16, 0xFF, 4);
|
---|
484 |
|
---|
485 | filter[36]=UNIQUE;
|
---|
486 | filter[37]=0;
|
---|
487 |
|
---|
488 | filter[38+0] = 0x82;
|
---|
489 | filter[38+0+16] = 0xFF;
|
---|
490 |
|
---|
491 | memcpy(filter+38+6, rdr->hexserial+2, 4);
|
---|
492 | memset(filter+38+6+16, 0xFF, 4);
|
---|
493 |
|
---|
494 | filter[70]=UNIQUE;
|
---|
495 | filter[71]=0;
|
---|
496 |
|
---|
497 | filter[72+0] = 0x82;
|
---|
498 | filter[72+0+16] = 0xFF;
|
---|
499 |
|
---|
500 | memcpy(filter+72+10, rdr->hexserial+2, 4);
|
---|
501 | memset(filter+72+10+16, 0xFF, 4);
|
---|
502 |
|
---|
503 | /* filter[104]=UNIQUE;
|
---|
504 | filter[105]=0;
|
---|
505 |
|
---|
506 | filter[106+0] = 0x82;
|
---|
507 | filter[106+0+16] = 0xFF;
|
---|
508 |
|
---|
509 | memcpy(filter+106+14, rdr->hexserial+2, 2);
|
---|
510 | memset(filter+106+14+16, 0xFF, 2); */
|
---|
511 |
|
---|
512 | return;
|
---|
513 | }
|
---|
514 |
|
---|
515 | int videoguard2_do_emm(struct s_reader * reader, EMM_PACKET *ep)
|
---|
516 | {
|
---|
517 | unsigned char cta_res[CTA_RES_LEN];
|
---|
518 | unsigned char ins42[5] = { 0xD1,0x42,0x00,0x00,0xFF };
|
---|
519 | int rc=ERROR;
|
---|
520 |
|
---|
521 | const unsigned char *payload = payload_addr(ep->type, ep->emm, reader->hexserial);
|
---|
522 | while (payload) {
|
---|
523 | ins42[4]=*payload;
|
---|
524 | int l = do_cmd(reader, ins42,payload+1,NULL,cta_res);
|
---|
525 | if(l>0 && status_ok(cta_res)) {
|
---|
526 | rc=OK;
|
---|
527 | }
|
---|
528 |
|
---|
529 | cs_debug_mask(D_EMM, "[videoguard2-reader] EMM request return code : %02X%02X", cta_res[0], cta_res[1]);
|
---|
530 | //cs_dump(ep->emm, 64, "EMM:");
|
---|
531 | if (status_ok (cta_res) && (cta_res[1] & 0x01)) {
|
---|
532 | vg2_read_tiers(reader);
|
---|
533 | }
|
---|
534 |
|
---|
535 | if (num_addr(ep->emm) == 1 && (int)(&payload[1] - &ep->emm[0]) + *payload + 1 < ep->l) {
|
---|
536 | payload += *payload + 1;
|
---|
537 | if (*payload == 0x00) ++payload;
|
---|
538 | ++payload;
|
---|
539 | if (*payload != 0x02) break;
|
---|
540 | payload += 2 + payload[1];
|
---|
541 | }
|
---|
542 | else
|
---|
543 | payload = 0;
|
---|
544 |
|
---|
545 | }
|
---|
546 |
|
---|
547 | return(rc);
|
---|
548 | }
|
---|
549 |
|
---|
550 | int videoguard2_card_info(struct s_reader * reader)
|
---|
551 | {
|
---|
552 | /* info is displayed in init, or when processing info */
|
---|
553 | cs_log("[videoguard2-reader] card detected");
|
---|
554 | cs_log("[videoguard2-reader] type: VideoGuard" );
|
---|
555 | vg2_read_tiers (reader);
|
---|
556 | return OK;
|
---|
557 | }
|
---|