- fix Building without Nagra not possible at Nagra_Merlin https://trac.streamboard...
[oscam.git] / module-cccam-data.h
blobcdcee741bb67a43ef1ba44655124809f6ccf00f5
1 /*
2 * Created on: 23.04.2010
3 * Author: alno
4 */
5 #ifndef MODULE_CCCAM_DATA_H_
6 #define MODULE_CCCAM_DATA_H_
8 #include "cscrypt/rc6.h"
9 #include "cscrypt/idea.h"
11 #define CAID_KEY 0x20
13 #define CC_MAXMSGSIZE 0x400 // by Project::Keynation: Buffer size is limited on "O" CCCam to 1024 bytes
14 #define CC_MAX_PROV 32
15 #define SWAPC(X, Y) do { char p; p = *X; *X = *Y; *Y = p; } while(0)
17 #if (defined(WIN32) || defined(__CYGWIN__)) && !defined(MSG_WAITALL)
18 #define MSG_WAITALL 0
19 #endif
21 #define MINIMIZE_NONE 0
22 #define MINIMIZE_HOPS 1
23 #define MINIMIZE_CAID 2
24 #define MINIMIZE_TRANSPARENT 3
26 #define CCCAM_MODE_NOTINIT 0
27 #define CCCAM_MODE_NORMAL 1
28 #define CCCAM_MODE_SHUTDOWN 0xFF
30 #define QUITERROR 1
32 #define MIN_RATING -25
33 #define MAX_RATING 25
35 #define HOP_RATING 5
37 typedef enum
39 DECRYPT, ENCRYPT
40 } cc_crypt_mode_t;
42 typedef enum
44 MSG_CLI_DATA = 0,
45 MSG_CW_ECM = 1,
46 MSG_EMM_ACK = 2,
47 MSG_CARD_REMOVED = 4,
48 MSG_CMD_05 = 5,
49 MSG_KEEPALIVE = 6,
50 MSG_NEW_CARD = 7,
51 MSG_SRV_DATA = 8,
52 MSG_CMD_0A = 0x0a,
53 MSG_CMD_0B = 0x0b,
54 MSG_CMD_0C = 0x0c, // CCCam 2.2.x fake client checks
55 MSG_CMD_0D = 0x0d, // "
56 MSG_CMD_0E = 0x0e, // "
57 MSG_NEW_CARD_SIDINFO = 0x0f,
58 MSG_SLEEPSEND = 0x80, // Sleepsend support
59 MSG_CACHE_PUSH = 0x81, // CacheEx Cache-Push In/Out
60 MSG_CACHE_FILTER = 0x82, // CacheEx Cache-Filter Request
61 #ifdef CS_CACHEEX_AIO
62 MSG_CACHE_FEATURE_EXCHANGE = 0x83, // CacheEx feature-exchange
63 MSG_CACHE_FEATURE_EXCHANGE_REPLY = 0x84, // CacheEx feature-exchange-reply
64 MSG_CACHE_FEATURE_TRIGGER = 0x85, // CacheEx feature-trigger
65 MSG_CW_ECM_LGF = 0x86, // oscam lg-flagged CW
66 #endif
67 MSG_CW_NOK1 = 0xfe, // Node no more available
68 MSG_CW_NOK2 = 0xff, // No decoding
69 MSG_NO_HEADER = 0xffff
70 } cc_msg_type_t;
72 struct cc_crypt_block
74 uint8_t keytable[256];
75 uint8_t state;
76 uint8_t counter;
77 uint8_t sum;
80 struct cc_srvid
82 uint16_t sid;
83 uint16_t chid;
84 uint8_t ecmlen;
87 struct cc_srvid_block
89 uint16_t sid;
90 uint16_t chid;
91 uint8_t ecmlen;
92 time_t blocked_till;
95 struct cc_provider
97 uint32_t prov; // provider
98 uint8_t sa[4]; // shared address
101 typedef enum
103 CT_LOCALCARD = 1,
104 CT_CARD_BY_SERVICE_READER = 2,
105 CT_CARD_BY_SERVICE_USER = 3,
106 CT_CARD_BY_CAID1 = 4,
107 CT_CARD_BY_CAID2 = 5,
108 CT_CARD_BY_CAID3 = 6,
109 CT_REMOTECARD = 10
110 } cc_card_type;
112 struct cc_card
114 uint32_t id; // cccam card (share) id - reader
115 uint32_t remote_id;
116 uint16_t caid;
117 uint8_t hop;
118 uint8_t reshare;
119 uint8_t hexserial[8]; // card serial (for au)
120 LLIST *providers; // providers (struct cc_provider)
121 LLIST *badsids; // sids that have failed to decode (struct cc_srvid_block)
122 LLIST *goodsids; // sids that could decoded (struct cc_srvid)
123 LLIST *remote_nodes; // remote note id, 8 bytes
124 struct s_reader *origin_reader;
125 uint32_t origin_id;
126 cc_card_type card_type;
127 struct s_sidtab *sidtab; // pointer to sidtab entry if card_type = CT_CARD_BY_SERVICE
128 uint64_t grp;
129 uint8_t rdr_reshare;
130 SIDTABBITS sidtabno;
131 time_t timeout;
132 uint8_t is_ext;
133 int8_t rating;
136 typedef enum
138 MODE_UNKNOWN = 0,
139 MODE_PLAIN = 1,
140 MODE_AES = 2,
141 MODE_CC_CRYPT = 3,
142 MODE_RC4_CRYPT = 4,
143 MODE_LEN0 = 5,
144 } cc_cmd05_mode;
146 typedef enum
148 MODE_CMD_0x0C_NONE = 0,
149 MODE_CMD_0x0C_RC6 = 1,
150 MODE_CMD_0x0C_RC4 = 2,
151 MODE_CMD_0x0C_CC_CRYPT = 3,
152 MODE_CMD_0x0C_AES = 4,
153 MODE_CMD_0x0C_IDEA = 5,
154 } cc_cmd0c_mode;
156 struct cc_extended_ecm_idx
158 uint8_t send_idx;
159 uint16_t ecm_idx;
160 struct cc_card *card;
161 struct cc_srvid srvid;
162 uint8_t free_card;
163 struct timeb tps;
164 uint32_t cccam_id;
167 struct cc_data
169 uint8_t g_flag;
170 char *prefix;
172 struct cc_crypt_block block[2]; // crypto state blocks
174 uint8_t node_id[8]; // client node id
175 uint8_t peer_node_id[8]; // server node id
176 uint8_t peer_version[8]; // server version
177 uint8_t dcw[16]; // control words
178 uint8_t cmd0b_aeskey[16];
179 uint8_t cmd05_aeskey[16];
180 struct cc_crypt_block cmd05_cryptkey;
182 uint8_t is_oscam_cccam;
183 uint8_t cmd05_active;
184 int32_t cmd05_data_len;
185 uint8_t cmd05_data[256];
186 cc_cmd05_mode cmd05_mode;
187 int32_t cmd05_offset;
189 cc_cmd0c_mode cmd0c_mode;
190 struct cc_crypt_block cmd0c_cryptkey;
191 RC6KEY cmd0c_RC6_cryptkey;
192 AES_KEY cmd0c_AES_key;
193 IDEA_KEY_SCHEDULE cmd0c_IDEA_dkey;
195 uint8_t receive_buffer[CC_MAXMSGSIZE];
196 uint8_t send_buffer[CC_MAXMSGSIZE];
198 LLIST *cards; // cards list
200 int32_t max_ecms;
201 int32_t ecm_counter;
202 int32_t card_added_count;
203 int32_t card_removed_count;
204 uint8_t just_logged_in; // true for checking NOK direct after login
205 uint8_t key_table; // key for CMD 0B
207 LLIST *pending_emms; // pending emm list
209 uint32_t recv_ecmtask;
211 struct cc_card *last_emm_card;
212 int32_t server_ecm_pending; // initialized by server
213 uint16_t server_ecm_idx;
215 CS_MUTEX_LOCK lockcmd;
216 int8_t ecm_busy;
217 CS_MUTEX_LOCK cards_busy;
218 struct timeb ecm_time;
219 uint8_t last_msg;
220 uint8_t cmd05NOK;
222 char remote_version[7];
223 char remote_build[7];
224 char remote_oscam[200];
226 uint8_t cccam220;
227 uint32_t remote_build_nr;
228 uint8_t sleepsend;
230 // Extended Mode for SPECIAL clients:
231 uint8_t extended_mode;
232 LLIST *extended_ecm_idx;
234 // multics detection
235 int8_t multics_mode;
236 int8_t multics_version[2];
238 // stats:
239 int32_t num_hop1;
240 int32_t num_hop2;
241 int32_t num_hopx;
243 int32_t num_reshare0;
244 int32_t num_reshare1;
245 int32_t num_reshare2;
246 int32_t num_resharex;
248 char *nok_message;
250 #ifdef CS_CACHEEX_AIO
251 uint8_t extended_lg_flagged_cws;
252 #endif
255 #endif