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

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

ird-guess: Allocate irdeto guess tab structure dynamically.

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