source: branches/merlin/src/CAM/common.c@ 395

Last change on this file since 395 was 395, checked in by Merlin, 12 years ago

Fixed functions' name in log.h/log.c

File size: 5.5 KB
Line 
1#include "globals.h"
2#include "CAM/common.h"
3
4#include "CAM/conax.h"
5#include "CAM/cryptoworks.h"
6#include "CAM/irdeto.h"
7#include "CAM/seca.h"
8#include "CAM/viaccess.h"
9#include "CAM/videoguard.h"
10
11#include "reader/common.h"
12
13#include "simples.h"
14#include "log.h"
15
16ushort cam_common_len4caid[256]; // table for guessing caid (by len)
17
18typedef enum {
19 CAM_UNKNOWN,
20
21 CAM_CONAX,
22 CAM_CRYPTOWORKS,
23 CAM_IRDETO,
24 CAM_SECA,
25 CAM_VIACCESS,
26 CAM_VIDEOGUARD
27} cam_common_card_system;
28
29int cam_common_detect(uchar *atr, ushort atr_size)
30{
31 cam_common_card_system card_system = CAM_UNKNOWN;
32
33 /* Test each CAM to detect the card_system */
34 if (cam_conax_detect(atr, atr_size)) {
35 card_system = CAM_CONAX;
36 log_normal("CAM: Conax detected");
37 } else if (cam_cryptoworks_detect(atr, atr_size)) {
38 card_system = CAM_CRYPTOWORKS;
39 log_normal("CAM: Cryptoworks detected");
40 } else if (cam_irdeto_detect(atr, atr_size)) {
41 card_system = CAM_IRDETO;
42 log_normal("CAM: Irdeto detected");
43 } else if (cam_seca_detect(atr, atr_size)) {
44 card_system = CAM_SECA;
45 log_normal("CAM: Seca detected");
46 } else if (cam_viaccess_detect(atr, atr_size)) {
47 card_system = CAM_VIACCESS;
48 log_normal("CAM: Viaccess detected");
49 } else if (cam_videoguard_detect(atr, atr_size)) {
50 card_system = CAM_VIDEOGUARD;
51 log_normal("CAM: Videoguard detected");
52 } else {
53 log_normal("CAM: Card system not supported !");
54 }
55
56 /* Save the card_system value for the reader */
57 reader[ridx].card_system = card_system;
58
59 return card_system;
60}
61
62int cam_common_load_card()
63{
64 int rc = 0;
65
66 log_normal("CAM: Loading card ...");
67
68 switch (reader[ridx].card_system) {
69 case CAM_CONAX:
70 rc = cam_conax_load_card();
71 break;
72 case CAM_CRYPTOWORKS:
73 rc = cam_cryptoworks_load_card();
74 break;
75 case CAM_IRDETO:
76 rc = cam_irdeto_load_card();
77 break;
78 case CAM_SECA:
79 rc = cam_seca_load_card();
80 break;
81 case CAM_VIACCESS:
82 rc = cam_viaccess_load_card();
83 break;
84 case CAM_VIDEOGUARD:
85 rc = cam_videoguard_load_card();
86 break;
87 }
88
89 if (rc) {
90 log_normal("CAM: Card information loaded");
91 } else {
92 log_normal("CAM: Cannot load card information !");
93 }
94
95 return rc;
96}
97
98int cam_common_process_ecm(ECM_REQUEST * er)
99{
100 int rc = 0;
101
102 switch (reader[ridx].card_system) {
103 case CAM_CONAX:
104 rc = cam_conax_process_ecm(er);
105 break;
106 case CAM_CRYPTOWORKS:
107 rc = cam_cryptoworks_process_ecm(er);
108 break;
109 case CAM_IRDETO:
110 rc = cam_irdeto_process_ecm(er);
111 break;
112 case CAM_SECA:
113 rc = cam_seca_process_ecm(er);
114 break;
115 case CAM_VIACCESS:
116 rc = cam_viaccess_process_ecm(er);
117 break;
118 case CAM_VIDEOGUARD:
119 rc = cam_videoguard_process_ecm(er);
120 break;
121 }
122
123 return rc;
124}
125
126int cam_common_process_emm(EMM_PACKET * ep)
127{
128 int rc = 0;
129
130 switch (reader[ridx].card_system) {
131 case CAM_CONAX:
132 rc = cam_conax_process_emm(ep);
133 break;
134 case CAM_CRYPTOWORKS:
135 rc = cam_cryptoworks_process_emm(ep);
136 break;
137 case CAM_IRDETO:
138 rc = cam_irdeto_process_emm(ep);
139 break;
140 case CAM_SECA:
141 rc = cam_seca_process_emm(ep);
142 break;
143 case CAM_VIACCESS:
144 rc = cam_viaccess_process_emm(ep);
145 break;
146 case CAM_VIDEOGUARD:
147 rc = cam_videoguard_process_emm(ep);
148 break;
149 }
150
151 return rc;
152}
153
154int cam_common_cmd2card(uchar *cmd, ushort cmd_size, uchar *result, ushort result_max_size, ushort *result_size)
155{
156 // Forward to the reader
157 return reader_common_cmd2card(&reader[ridx], cmd, cmd_size, result, result_max_size, result_size);
158}
159
160ulong cam_common_get_provider_id(uchar *ecm, ushort caid)
161{
162 int i;
163 ulong provid = 0;
164
165 switch (caid) {
166 case 0x100: // seca
167 provid = b2i(2, ecm + 3);
168 break;
169
170 case 0x500: // viaccess
171 i = (ecm[4] == 0xD2) ? ecm[5] + 2 : 0; // skip d2 nano
172 if ((ecm[5 + i] == 3) && ((ecm[4 + i] == 0x90) || (ecm[4 + i] == 0x40)))
173 provid = (b2i(3, ecm + 6 + i) & 0xFFFFF0);
174
175 default:
176 // cryptoworks ?
177 if (caid & 0x0d00 && ecm[8] == 0x83 && ecm[9] == 1)
178 provid = (ulong) ecm[10];
179 }
180
181 return provid;
182}
183
184void cam_common_guess_card_system(ECM_REQUEST * er)
185{
186 ushort last_hope = 0;
187
188 // viaccess - check by provid-search
189 if ((er->prid = cam_common_get_provider_id(er->ecm, 0x500)))
190 er->caid = 0x500;
191
192 // nagra
193 // is ecm[1] always 0x30 ?
194 // is ecm[3] always 0x07 ?
195 if ((er->ecm[6] == 1) && (er->ecm[4] == er->ecm[2] - 2))
196 er->caid = 0x1801;
197
198 // seca2 - very poor
199 if ((er->ecm[8] == 0x10) && ((er->ecm[9] & 0xF1) == 1))
200 last_hope = 0x100;
201
202 // is cryptoworks, but which caid ?
203 if ((er->ecm[3] == 0x81) && (er->ecm[4] == 0xFF) && (!er->ecm[5]) && (!er->ecm[6]) && (er->ecm[7] == er->ecm[2] - 5))
204 last_hope = 0xd00;
205
206/*
207 if (!er->caid && er->ecm[2]==0x31 && er->ecm[0x0b]==0x28) {
208 uchar b3;
209 int b47;
210 //ushort chid;
211 struct s_irdeto_guess {
212 int b47;
213 ushort caid;
214 ushort sid;
215 struct s_irdeto_quess *next;
216 };
217 struct s_irdeto_guess *ptr;
218
219 b3 = er->ecm[3];
220 ptr = cfg->itab[b3];
221 if( !ptr ) {
222 cs_debug("unknown irdeto byte 3: %02X", b3);
223 return;
224 }
225 b47 = b2i(4, er->ecm+4);
226 //chid = b2i(2, er->ecm+6);
227 //cs_debug("ecm: b47=%08X, ptr->b47=%08X, ptr->caid=%04X", b47, ptr->b47, ptr->caid);
228 while( ptr )
229 {
230 if (b47 == ptr->b47) {
231 if (er->srvid && (er->srvid!=ptr->sid)) {
232 cs_debug("sid mismatched (ecm: %04X, guess: %04X), wrong oscam.ird file?", er->srvid, ptr->sid);
233 return;
234 }
235 er->caid = ptr->caid;
236 er->srvid = ptr->sid;
237 er->chid = (ushort) ptr->b47;
238// cs_debug("guess_irdeto() found caid=%04X, sid=%04X, chid=%04X", er->caid, er->srvid, er->chid);
239 return;
240 }
241 ptr = ptr->next;
242 }
243 }
244*/
245
246 if (!er->caid) // guess by len
247 er->caid = cam_common_len4caid[er->ecm[2] + 3];
248
249 if (!er->caid)
250 er->caid = last_hope;
251}
Note: See TracBrowser for help on using the repository browser.