[gbx] - try fix ecm and cw messages
[oscam.git] / module-cccam-data.h
blob19ed32e1dcfdd8d5092e30a0f2657a766228c1b9
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 MSG_CW_NOK1 = 0xfe, // Node no more available
62 MSG_CW_NOK2 = 0xff, // No decoding
63 MSG_NO_HEADER = 0xffff
64 } cc_msg_type_t;
66 struct cc_crypt_block
68 uint8_t keytable[256];
69 uint8_t state;
70 uint8_t counter;
71 uint8_t sum;
74 struct cc_srvid
76 uint16_t sid;
77 uint16_t chid;
78 uint8_t ecmlen;
81 struct cc_srvid_block
83 uint16_t sid;
84 uint16_t chid;
85 uint8_t ecmlen;
86 time_t blocked_till;
89 struct cc_provider
91 uint32_t prov; // provider
92 uint8_t sa[4]; // shared address
95 typedef enum
97 CT_LOCALCARD = 1,
98 CT_CARD_BY_SERVICE_READER = 2,
99 CT_CARD_BY_SERVICE_USER = 3,
100 CT_CARD_BY_CAID1 = 4,
101 CT_CARD_BY_CAID2 = 5,
102 CT_CARD_BY_CAID3 = 6,
103 CT_REMOTECARD = 10
104 } cc_card_type;
106 struct cc_card
108 uint32_t id; // cccam card (share) id - reader
109 uint32_t remote_id;
110 uint16_t caid;
111 uint8_t hop;
112 uint8_t reshare;
113 uint8_t hexserial[8]; // card serial (for au)
114 LLIST *providers; // providers (struct cc_provider)
115 LLIST *badsids; // sids that have failed to decode (struct cc_srvid_block)
116 LLIST *goodsids; // sids that could decoded (struct cc_srvid)
117 LLIST *remote_nodes; // remote note id, 8 bytes
118 struct s_reader *origin_reader;
119 uint32_t origin_id;
120 cc_card_type card_type;
121 struct s_sidtab *sidtab; // pointer to sidtab entry if card_type = CT_CARD_BY_SERVICE
122 uint64_t grp;
123 uint8_t rdr_reshare;
124 SIDTABBITS sidtabno;
125 time_t timeout;
126 uint8_t is_ext;
127 int8_t rating;
130 typedef enum
132 MODE_UNKNOWN = 0,
133 MODE_PLAIN = 1,
134 MODE_AES = 2,
135 MODE_CC_CRYPT = 3,
136 MODE_RC4_CRYPT = 4,
137 MODE_LEN0 = 5,
138 } cc_cmd05_mode;
140 typedef enum
142 MODE_CMD_0x0C_NONE = 0,
143 MODE_CMD_0x0C_RC6 = 1,
144 MODE_CMD_0x0C_RC4 = 2,
145 MODE_CMD_0x0C_CC_CRYPT = 3,
146 MODE_CMD_0x0C_AES = 4,
147 MODE_CMD_0x0C_IDEA = 5,
148 } cc_cmd0c_mode;
150 struct cc_extended_ecm_idx
152 uint8_t send_idx;
153 uint16_t ecm_idx;
154 struct cc_card *card;
155 struct cc_srvid srvid;
156 uint8_t free_card;
157 struct timeb tps;
158 uint32_t cccam_id;
161 struct cc_data
163 uint8_t g_flag;
164 char *prefix;
166 struct cc_crypt_block block[2]; // crypto state blocks
168 uint8_t node_id[8]; // client node id
169 uint8_t peer_node_id[8]; // server node id
170 uint8_t peer_version[8]; // server version
171 uint8_t dcw[16]; // control words
172 uint8_t cmd0b_aeskey[16];
173 uint8_t cmd05_aeskey[16];
174 struct cc_crypt_block cmd05_cryptkey;
176 uint8_t is_oscam_cccam;
177 uint8_t cmd05_active;
178 int32_t cmd05_data_len;
179 uint8_t cmd05_data[256];
180 cc_cmd05_mode cmd05_mode;
181 int32_t cmd05_offset;
183 cc_cmd0c_mode cmd0c_mode;
184 struct cc_crypt_block cmd0c_cryptkey;
185 RC6KEY cmd0c_RC6_cryptkey;
186 AES_KEY cmd0c_AES_key;
187 IDEA_KEY_SCHEDULE cmd0c_IDEA_dkey;
189 uint8_t receive_buffer[CC_MAXMSGSIZE];
190 uint8_t send_buffer[CC_MAXMSGSIZE];
192 LLIST *cards; // cards list
194 int32_t max_ecms;
195 int32_t ecm_counter;
196 int32_t card_added_count;
197 int32_t card_removed_count;
198 uint8_t just_logged_in; // true for checking NOK direct after login
199 uint8_t key_table; // key for CMD 0B
201 LLIST *pending_emms; // pending emm list
203 uint32_t recv_ecmtask;
205 struct cc_card *last_emm_card;
206 int32_t server_ecm_pending; // initialized by server
207 uint16_t server_ecm_idx;
209 CS_MUTEX_LOCK lockcmd;
210 int8_t ecm_busy;
211 CS_MUTEX_LOCK cards_busy;
212 struct timeb ecm_time;
213 uint8_t last_msg;
214 uint8_t cmd05NOK;
216 char remote_version[7];
217 char remote_build[7];
218 char remote_oscam[200];
220 uint8_t cccam220;
221 uint32_t remote_build_nr;
222 uint8_t sleepsend;
224 // Extended Mode for SPECIAL clients:
225 uint8_t extended_mode;
226 LLIST *extended_ecm_idx;
228 // multics detection
229 int8_t multics_mode;
230 int8_t multics_version[2];
232 // stats:
233 int32_t num_hop1;
234 int32_t num_hop2;
235 int32_t num_hopx;
237 int32_t num_reshare0;
238 int32_t num_reshare1;
239 int32_t num_reshare2;
240 int32_t num_resharex;
242 char *nok_message;
245 #endif