source: trunk/module-ird-guess.c@ 8467

Last change on this file since 8467 was 8467, checked in by gf, 9 years ago

ird-guess: Move everything related to irdeto guessing in the module.

File size: 3.0 KB
Line 
1#include "globals.h"
2
3#ifdef IRDETO_GUESSING
4#include "module-ird-guess.h"
5#include "oscam-string.h"
6#include "oscam-conf.h"
7
8struct s_irdeto_quess {
9 int32_t b47;
10 uint16_t caid;
11 uint16_t sid;
12 struct s_irdeto_quess *next;
13};
14
15static struct s_irdeto_quess *itab[0xff];
16
17int32_t init_irdeto_guess_tab(void)
18{
19 FILE *fp = open_config_file("oscam.ird");
20 if (!fp)
21 return 1;
22
23 int32_t i, j, skip;
24 int32_t b47;
25 char token[128], *ptr, *saveptr1 = NULL;
26 char zSid[5];
27 uchar b3;
28 uint16_t caid, sid;
29 struct s_irdeto_quess *ird_row, *head;
30
31 while (fgets(token, sizeof(token), fp))
32 {
33 if( strlen(token)<20 ) continue;
34 for( i=b3=b47=caid=sid=skip=0, ptr=strtok_r(token, ":", &saveptr1); (i<4)&&(ptr); ptr=strtok_r(NULL, ":", &saveptr1), i++ )
35 {
36 trim(ptr);
37 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
38 skip=1;
39 break;
40 }
41 switch(i)
42 {
43 case 0: b3 = a2i(ptr, 2); break;
44 case 1: b47 = a2i(ptr, 8); break;
45 case 2: caid = a2i(ptr, 4); break;
46 case 3:
47 for( j=0; j<4; j++ )
48 zSid[j]=ptr[j];
49 zSid[4]=0;
50 sid = a2i(zSid, 4);
51 break;
52 }
53 }
54 if( !skip )
55 {
56 if (!cs_malloc(&ird_row, sizeof(struct s_irdeto_quess))) {
57 fclose(fp);
58 return(1);
59 }
60 ird_row->b47 = b47;
61 ird_row->caid = caid;
62 ird_row->sid = sid;
63
64 head = itab[b3];
65 if( head ) {
66 while( head->next )
67 head=head->next;
68 head->next=ird_row;
69 }
70 else
71 itab[b3]=ird_row;
72 //cs_debug_mask(D_CLIENT, "%02X:%08X:%04X:%04X", b3, b47, caid, sid);
73 }
74 }
75 fclose(fp);
76
77 for( i=0; i<0xff; i++ )
78 {
79 head=itab[i];
80 while(head)
81 {
82 cs_debug_mask(D_CLIENT, "itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
83 i, head->b47, head->caid, head->sid);
84 head=head->next;
85 }
86 }
87 return(0);
88}
89
90void free_irdeto_guess_tab(void)
91{
92 uint8_t i;
93 for (i = 0; i < 0xff; i++)
94 {
95 struct s_irdeto_quess *head = itab[i];
96 while(head)
97 {
98 void *next = head->next;
99 free(head);
100 head = next;
101 }
102 }
103}
104
105void guess_irdeto(ECM_REQUEST *er)
106{
107 uchar b3;
108 int32_t b47;
109 //uint16_t chid;
110 struct s_irdeto_quess *ptr;
111
112 b3 = er->ecm[3];
113 ptr = itab[b3];
114 if( !ptr ) {
115 cs_debug_mask(D_TRACE, "unknown irdeto byte 3: %02X", b3);
116 return;
117 }
118 b47 = b2i(4, er->ecm+4);
119 //chid = b2i(2, er->ecm+6);
120 //cs_debug_mask(D_TRACE, "ecm: b47=%08X, ptr->b47=%08X, ptr->caid=%04X", b47, ptr->b47, ptr->caid);
121 while( ptr )
122 {
123 if( b47==ptr->b47 )
124 {
125 if( er->srvid && (er->srvid!=ptr->sid) )
126 {
127 cs_debug_mask(D_TRACE, "sid mismatched (ecm: %04X, guess: %04X), wrong oscam.ird file?",
128 er->srvid, ptr->sid);
129 return;
130 }
131 er->caid=ptr->caid;
132 er->srvid=ptr->sid;
133 er->chid=(uint16_t)ptr->b47;
134// cs_debug_mask(D_TRACE, "quess_irdeto() found caid=%04X, sid=%04X, chid=%04X",
135// er->caid, er->srvid, er->chid);
136 return;
137 }
138 ptr=ptr->next;
139 }
140}
141
142#endif
Note: See TracBrowser for help on using the repository browser.