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