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

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

Remove 'quiterror' param from cs_malloc() and cs_realloc().

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