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

Last change on this file since 532 was 532, checked in by smurzch2, 12 years ago

Merge drecrypt stuff in the Merlin branch.

This should merge the commits 491, 492, 497, 498, 501 and 521.

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