2 #include "reader-common.h"
3 #include "reader-nagra-common.h"
5 int32_t get_prov_idx(struct s_reader
*rdr
, const uint8_t *provid
)
8 for(prov
= 0; prov
< rdr
->nprov
; prov
++) // search for provider index
10 if(!memcmp(provid
, &rdr
->prid
[prov
][2], 2))
18 int32_t nagra_get_emm_type(EMM_PACKET
*ep
, struct s_reader
*rdr
)
20 if(rdr
->cak7type
== 3 || rdr
->autype
== 1)
27 memset(ep
->hexserial
, 0, 8);
28 memcpy(ep
->hexserial
, ep
->emm
+ 3, 6);
29 if(!memcmp(rdr
->hexserial
, ep
->hexserial
, 6))
34 else if ((ep
->emm
[3] == 0x00) && (ep
->emm
[4] == 0x00) && (ep
->emm
[5] == 0x00) && (ep
->emm
[6] == 0x00) && (ep
->emm
[7] == 0x00) && (ep
->emm
[8] == 0xD3) && (ep
->emm
[9] == 0x87))
43 memset(ep
->hexserial
, 0, 8);
44 memcpy(ep
->hexserial
, ep
->emm
+ 5, 3);
45 i
= get_prov_idx(rdr
, ep
->emm
+ 3);
52 return (!memcmp(rdr
->sa
[i
], ep
->hexserial
, 3));
56 uint8_t filtr
[] = {0x83, 0x00, 0x74};
57 return (!memcmp(ep
->emm
, filtr
, 3));
61 if(rdr
->cwpkcaid_length
&& rdr
->nuid_length
)
63 memset(ep
->hexserial
, 0x00, 0x08);
64 ep
->hexserial
[0] = ep
->emm
[5];
65 ep
->hexserial
[1] = ep
->emm
[4];
66 ep
->hexserial
[2] = ep
->emm
[3];
67 ep
->hexserial
[3] = ep
->emm
[6];
68 return (!memcmp(rdr
->nuid
, ep
->hexserial
, 4));
77 else if(rdr
->cak7type
== 1)
84 if(rdr
->emm82
== 1 && ep
->emm
[3] == 0x00 && ep
->emm
[4] == 0x00 && ep
->emm
[5] == 0x00)
91 if(ep
->emm
[7] == 0x10)
95 for(i
= 0; i
< rdr
->nemm83s
; i
++)
97 if(!memcmp(rdr
->emm83s
[i
] + 1, ep
->emm
+ 3, 0x03))
107 for(i
= 0; i
< rdr
->nemm83u
; i
++)
109 if(!memcmp(rdr
->emm83u
[i
] + 1, ep
->emm
+ 3, 0x04))
120 for(i
= 0; i
< rdr
->nemm84
; i
++)
122 if(!memcmp(rdr
->emm84
[i
] + 1, ep
->emm
+ 3, 0x02))
132 for(i
= 0; i
< rdr
->nemm87
; i
++)
134 if(!memcmp(rdr
->emm87
[i
] + 1, ep
->emm
+ 3, 0x04))
143 if(rdr
->cwpkcaid_length
&& rdr
->nuid_length
)
145 memset(ep
->hexserial
, 0x00, 0x08);
146 ep
->hexserial
[0] = ep
->emm
[5];
147 ep
->hexserial
[1] = ep
->emm
[4];
148 ep
->hexserial
[2] = ep
->emm
[3];
149 ep
->hexserial
[3] = ep
->emm
[6];
150 return (!memcmp(rdr
->nuid
, ep
->hexserial
, 4));
159 else if(rdr
->autype
== 2)
166 if(ep
->emm
[3] == 0x00 && ep
->emm
[4] == 0x00 && ep
->emm
[5] == 0x00)
173 memset(ep
->hexserial
, 0x00, 0x08);
174 ep
->hexserial
[0] = ep
->emm
[5];
175 ep
->hexserial
[1] = ep
->emm
[4];
176 ep
->hexserial
[2] = ep
->emm
[3];
177 if(ep
->emm
[7] == 0x10)
181 for(i
= 0; i
< rdr
->nprov
; i
++)
183 if(!memcmp(rdr
->sa
[i
], "\x00\x00\x00", 3))
188 if(!memcmp(rdr
->sa
[i
], ep
->hexserial
, 0x03))
196 ep
->hexserial
[3] = ep
->emm
[6];
199 return (!memcmp(rdr
->hexserial
+ 2, ep
->hexserial
, 0x04));
208 memset(ep
->hexserial
, 0x00, 0x08);
209 ep
->hexserial
[0] = ep
->emm
[5];
210 ep
->hexserial
[1] = ep
->emm
[4];
211 ep
->hexserial
[2] = ep
->emm
[3];
212 ep
->hexserial
[3] = ep
->emm
[6];
215 for(i
= 0; i
< rdr
->nprov
; i
++)
217 if(!memcmp(rdr
->sa
[i
], "\x00\x00\x00", 3))
221 if(!memcmp(rdr
->sa
[i
], ep
->hexserial
, 0x04))
239 memset(ep
->hexserial
, 0x00, 0x08);
240 ep
->hexserial
[0] = ep
->emm
[5];
241 ep
->hexserial
[1] = ep
->emm
[6];
242 ep
->hexserial
[2] = ep
->emm
[7];
243 ep
->hexserial
[3] = ep
->emm
[8];
244 if (!memcmp(rdr
->hexserial
+ 2, ep
->hexserial
, 0x04))
249 else if ((ep
->emm
[3] == 0x00) && (ep
->emm
[4] == 0x00) && (ep
->emm
[5] == 0x00) && (ep
->emm
[6] == 0x00) && (ep
->emm
[7] == 0x00) && ((ep
->emm
[8] == 0x04) || (ep
->emm
[8] == 0xD3)) && ((ep
->emm
[9] == 0x84) || (ep
->emm
[9] == 0x8F) || (ep
->emm
[9] == 0x87)))
257 memset(ep
->hexserial
, 0x00, 0x08);
258 memcpy(ep
->hexserial
, ep
->emm
+ 5, 3);
259 if ((ep
->emm
[2] == 0x77) && (ep
->emm
[3] == 0x00))
262 i
= get_prov_idx(rdr
, ep
->emm
+ 3);
269 return (!memcmp(rdr
->sa
[i
], ep
->hexserial
, 3));
271 else if ((ep
->emm
[3] == 0x00) && ((ep
->emm
[4] == 0x71) || (ep
->emm
[4] == 0x32) || (ep
->emm
[4] == 0xEC)) && (ep
->emm
[5] == 0x00) && (ep
->emm
[6] == 0x00) && (ep
->emm
[7] == 0x00) && (ep
->emm
[8] == 0x04) && (ep
->emm
[9] == 0x84))
279 memset(ep
->hexserial
, 0x00, 0x08);
280 ep
->hexserial
[0] = ep
->emm
[5];
281 ep
->hexserial
[1] = ep
->emm
[4];
282 ep
->hexserial
[2] = ep
->emm
[3];
283 ep
->hexserial
[3] = ep
->emm
[6];
284 if(ep
->emm
[7] == 0x10)
288 for(i
= 0; i
< rdr
->nprov
; i
++)
290 if(!memcmp(rdr
->sa
[i
], "\x00\x00\x00", 3))
295 if(!memcmp(rdr
->sa
[i
], ep
->hexserial
, 0x03))
301 else if (!memcmp(rdr
->hexserial
+ 2, ep
->hexserial
, 0x04))
306 else if ((ep
->emm
[5] == 0x04) && (ep
->emm
[6] == 0x70))
314 memset(ep
->hexserial
, 0x00, 0x08);
315 ep
->hexserial
[0] = ep
->emm
[5];
316 ep
->hexserial
[1] = ep
->emm
[4];
317 ep
->hexserial
[2] = ep
->emm
[3];
318 ep
->hexserial
[3] = ep
->emm
[6];
321 for(i
= 0; i
< rdr
->nprov
; i
++)
323 if(!memcmp(rdr
->sa
[i
], "\x00\x00\x00", 3))
327 if(!memcmp(rdr
->sa
[i
], ep
->hexserial
, 0x03))
341 int32_t nagra_get_emm_filter(struct s_reader
*rdr
, struct s_csystem_emm_filter
**emm_filters
, unsigned int *filter_count
)
343 if(rdr
->cak7type
== 3 || rdr
->autype
== 1)
345 if(*emm_filters
== NULL
)
347 const unsigned int max_filter_count
= 2 + (2 * rdr
->nprov
);
348 if(!cs_malloc(emm_filters
, max_filter_count
* sizeof(struct s_csystem_emm_filter
)))
353 struct s_csystem_emm_filter
*filters
= *emm_filters
;
358 filters
[idx
].type
= EMM_UNIQUE
;
359 filters
[idx
].enabled
= 1;
360 filters
[idx
].filter
[0] = 0x82;
361 filters
[idx
].mask
[0] = 0xFF;
362 memcpy(&filters
[idx
].filter
[1], rdr
->hexserial
, 6);
363 memset(&filters
[idx
].mask
[1], 0xFF, 6);
367 for(prov
= 0; prov
< rdr
->nprov
; prov
++)
369 if(!memcmp(rdr
->sa
[prov
], "\x00\x00\x00", 3))
374 filters
[idx
].type
= EMM_GLOBAL
;
375 filters
[idx
].enabled
= 1;
376 filters
[idx
].filter
[0] = 0x83;
377 filters
[idx
].mask
[0] = 0xFF;
378 memcpy(&filters
[idx
].filter
[1], &rdr
->prid
[prov
][2], 2);
379 memset(&filters
[idx
].mask
[1], 0xFF, 2);
382 filters
[idx
].type
= EMM_SHARED
;
383 filters
[idx
].enabled
= 1;
384 filters
[idx
].filter
[0] = 0x84;
385 filters
[idx
].mask
[0] = 0xFF;
386 memcpy(&filters
[idx
].filter
[1], &rdr
->prid
[prov
][2], 2);
387 memset(&filters
[idx
].mask
[1], 0xFF, 2);
388 memcpy(&filters
[idx
].filter
[3], &rdr
->sa
[prov
], 3);
389 memset(&filters
[idx
].mask
[3], 0xFF, 3);
393 if(rdr
->cwpkcaid_length
&& rdr
->nuid_length
)
395 filters
[idx
].type
= EMM_UNIQUE
;
396 filters
[idx
].enabled
= 1;
397 filters
[idx
].filter
[0] = 0x90;
398 filters
[idx
].filter
[1] = rdr
->nuid
[2];
399 filters
[idx
].filter
[2] = rdr
->nuid
[1];
400 filters
[idx
].filter
[3] = rdr
->nuid
[0];
401 filters
[idx
].filter
[4] = rdr
->nuid
[3];
402 memset(&filters
[idx
].mask
[0], 0xFF, 5);
411 else if(rdr
->cak7type
== 1)
413 if(*emm_filters
== NULL
)
415 const unsigned int max_filter_count
= 2 + (4 * rdr
->nprov
);
416 if(!cs_malloc(emm_filters
, max_filter_count
* sizeof(struct s_csystem_emm_filter
)))
421 struct s_csystem_emm_filter
*filters
= *emm_filters
;
428 filters
[idx
].type
= EMM_GLOBAL
;
429 filters
[idx
].enabled
= 1;
430 filters
[idx
].filter
[0] = 0x82;
431 filters
[idx
].mask
[0] = 0xFF;
436 for(i
= 0; i
< rdr
->nemm83u
; i
++)
438 filters
[idx
].type
= EMM_UNIQUE
;
439 filters
[idx
].enabled
= 1;
440 memcpy(&filters
[idx
].filter
[0], rdr
->emm83u
[i
], 6);
441 memset(&filters
[idx
].mask
[0], 0xFF, 6);
445 for(i
= 0; i
< rdr
->nemm83s
; i
++)
447 filters
[idx
].type
= EMM_SHARED
;
448 filters
[idx
].enabled
= 1;
449 memcpy(&filters
[idx
].filter
[0], rdr
->emm83s
[i
], 6);
450 memset(&filters
[idx
].mask
[0], 0xFF, 6);
454 for(i
= 0; i
< rdr
->nemm84
; i
++)
456 filters
[idx
].type
= EMM_GLOBAL
;
457 filters
[idx
].enabled
= 1;
458 memcpy(&filters
[idx
].filter
[0], rdr
->emm84
[i
], 3);
459 memset(&filters
[idx
].mask
[0], 0xFF, 3);
463 for(i
= 0; i
< rdr
->nemm87
; i
++)
465 filters
[idx
].type
= EMM_SHARED
;
466 filters
[idx
].enabled
= 1;
467 memcpy(&filters
[idx
].filter
[0], rdr
->emm87
[i
], 6);
468 memset(&filters
[idx
].mask
[0], 0xFF, 6);
472 if(rdr
->cwpkcaid_length
&& rdr
->nuid_length
)
474 filters
[idx
].type
= EMM_UNIQUE
;
475 filters
[idx
].enabled
= 1;
476 filters
[idx
].filter
[0] = 0x90;
477 filters
[idx
].filter
[1] = rdr
->nuid
[2];
478 filters
[idx
].filter
[2] = rdr
->nuid
[1];
479 filters
[idx
].filter
[3] = rdr
->nuid
[0];
480 filters
[idx
].filter
[4] = rdr
->nuid
[3];
481 memset(&filters
[idx
].mask
[0], 0xFF, 5);
490 else if(rdr
->autype
== 2)
492 if(*emm_filters
== NULL
)
494 const unsigned int max_filter_count
= 3 + (2 * rdr
->nprov
);
495 if(!cs_malloc(emm_filters
, max_filter_count
* sizeof(struct s_csystem_emm_filter
)))
500 struct s_csystem_emm_filter
*filters
= *emm_filters
;
505 filters
[idx
].type
= EMM_GLOBAL
;
506 filters
[idx
].enabled
= 1;
507 filters
[idx
].filter
[0] = 0x82;
508 filters
[idx
].mask
[0] = 0xFF;
511 filters
[idx
].type
= EMM_GLOBAL
;
512 filters
[idx
].enabled
= 1;
513 filters
[idx
].filter
[0] = 0x84;
514 filters
[idx
].mask
[0] = 0xFF;
517 filters
[idx
].type
= EMM_UNIQUE
;
518 filters
[idx
].enabled
= 1;
519 filters
[idx
].filter
[0] = 0x83;
520 filters
[idx
].filter
[1] = rdr
->hexserial
[4];
521 filters
[idx
].filter
[2] = rdr
->hexserial
[3];
522 filters
[idx
].filter
[3] = rdr
->hexserial
[2];
523 filters
[idx
].filter
[4] = rdr
->hexserial
[5];
524 filters
[idx
].filter
[5] = 0x00;
525 memset(&filters
[idx
].mask
[0], 0xFF, 6);
529 for(i
= 0; i
< rdr
->nprov
; i
++)
531 if(!memcmp(rdr
->sa
[i
], "\x00\x00\x00", 3))
536 filters
[idx
].type
= EMM_SHARED
;
537 filters
[idx
].enabled
= 1;
538 filters
[idx
].filter
[0] = 0x83;
539 filters
[idx
].filter
[1] = rdr
->sa
[i
][2];
540 filters
[idx
].filter
[2] = rdr
->sa
[i
][1];
541 filters
[idx
].filter
[3] = rdr
->sa
[i
][0];
542 filters
[idx
].filter
[4] = 0x00;
543 filters
[idx
].filter
[5] = 0x10;
544 memset(&filters
[idx
].mask
[0], 0xFF, 6);
547 filters
[idx
].type
= EMM_SHARED
;
548 filters
[idx
].enabled
= 1;
549 filters
[idx
].filter
[0] = 0x87;
550 filters
[idx
].filter
[1] = rdr
->sa
[i
][2];
551 filters
[idx
].filter
[2] = rdr
->sa
[i
][1];
552 filters
[idx
].filter
[3] = rdr
->sa
[i
][0];
553 filters
[idx
].filter
[4] = rdr
->sa
[i
][3];
554 filters
[idx
].filter
[5] = 0x00;
555 memset(&filters
[idx
].mask
[0], 0xFF, 6);
566 if(*emm_filters
== NULL
)
568 const unsigned int max_filter_count
= 5 + (3 * rdr
->nprov
);
569 if(!cs_malloc(emm_filters
, max_filter_count
* sizeof(struct s_csystem_emm_filter
)))
574 struct s_csystem_emm_filter
*filters
= *emm_filters
;
579 filters
[idx
].type
= EMM_UNIQUE
;
580 filters
[idx
].enabled
= 1;
581 filters
[idx
].filter
[0] = 0x82;
582 filters
[idx
].mask
[0] = 0xFF;
583 memcpy(&filters
[idx
].filter
[1], rdr
->hexserial
, 6);
584 memset(&filters
[idx
].mask
[1], 0xFF, 6);
587 filters
[idx
].type
= EMM_UNIQUE
;
588 filters
[idx
].enabled
= 1;
589 filters
[idx
].filter
[0] = 0x83;
590 filters
[idx
].filter
[1] = rdr
->hexserial
[4];
591 filters
[idx
].filter
[2] = rdr
->hexserial
[3];
592 filters
[idx
].filter
[3] = rdr
->hexserial
[2];
593 filters
[idx
].filter
[4] = rdr
->hexserial
[5];
594 filters
[idx
].filter
[5] = 0x00;
595 memset(&filters
[idx
].mask
[0], 0xFF, 6);
598 filters
[idx
].type
= EMM_GLOBAL
;
599 filters
[idx
].enabled
= 1;
600 filters
[idx
].filter
[0] = 0x82;
601 filters
[idx
].mask
[0] = 0xFF;
604 filters
[idx
].type
= EMM_GLOBAL
;
605 filters
[idx
].enabled
= 1;
606 filters
[idx
].filter
[0] = 0x84;
607 filters
[idx
].mask
[0] = 0xFF;
610 filters
[idx
].type
= EMM_GLOBAL
;
611 filters
[idx
].enabled
= 1;
612 filters
[idx
].filter
[0] = 0x83;
613 filters
[idx
].mask
[0] = 0xFF;
617 for(prov
= 0; prov
< rdr
->nprov
; prov
++)
619 if(!memcmp(rdr
->sa
[prov
], "\x00\x00\x00", 3))
624 filters
[idx
].type
= EMM_SHARED
;
625 filters
[idx
].enabled
= 1;
626 filters
[idx
].filter
[0] = 0x84;
627 filters
[idx
].mask
[0] = 0xFF;
628 memcpy(&filters
[idx
].filter
[1], &rdr
->prid
[prov
][2], 2);
629 memset(&filters
[idx
].mask
[1], 0xFF, 2);
630 memcpy(&filters
[idx
].filter
[3], &rdr
->sa
[prov
], 3);
631 memset(&filters
[idx
].mask
[3], 0xFF, 3);
634 filters
[idx
].type
= EMM_SHARED
;
635 filters
[idx
].enabled
= 1;
636 filters
[idx
].filter
[0] = 0x83;
637 filters
[idx
].filter
[1] = rdr
->sa
[prov
][2];
638 filters
[idx
].filter
[2] = rdr
->sa
[prov
][1];
639 filters
[idx
].filter
[3] = rdr
->sa
[prov
][0];
640 filters
[idx
].filter
[4] = 0x00;
641 filters
[idx
].filter
[5] = 0x10;
642 memset(&filters
[idx
].mask
[0], 0xFF, 6);
645 filters
[idx
].type
= EMM_SHARED
;
646 filters
[idx
].enabled
= 1;
647 filters
[idx
].filter
[0] = 0x87;
648 filters
[idx
].filter
[1] = rdr
->sa
[prov
][2];
649 filters
[idx
].filter
[2] = rdr
->sa
[prov
][1];
650 filters
[idx
].filter
[3] = rdr
->sa
[prov
][0];
651 filters
[idx
].filter
[4] = 0x00;
652 filters
[idx
].filter
[5] = 0x00;
653 memset(&filters
[idx
].mask
[0], 0xFF, 6);