revert breaks some stupid old compilers
[oscam.git] / module-cccam-data.h
blob235f35f865d4c78e1e9c8e83003703cf93e5a56f
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;
151 struct cc_extended_ecm_idx
153 uint8_t send_idx;
154 uint16_t ecm_idx;
155 struct cc_card *card;
156 struct cc_srvid srvid;
157 uint8_t free_card;
158 struct timeb tps;
159 uint32_t cccam_id;
162 struct cc_data
164 uint8_t g_flag;
165 char *prefix;
167 struct cc_crypt_block block[2]; // crypto state blocks
169 uint8_t node_id[8], // client node id
170 peer_node_id[8], // server node id
171 peer_version[8], // server version
172 dcw[16]; // control words
173 uint8_t cmd0b_aeskey[16];
174 uint8_t cmd05_aeskey[16];
175 struct cc_crypt_block cmd05_cryptkey;
177 uint8_t is_oscam_cccam;
178 uint8_t cmd05_active;
179 int32_t cmd05_data_len;
180 uint8_t cmd05_data[256];
181 cc_cmd05_mode cmd05_mode;
182 int32_t cmd05_offset;
184 cc_cmd0c_mode cmd0c_mode;
185 struct cc_crypt_block cmd0c_cryptkey;
186 RC6KEY cmd0c_RC6_cryptkey;
187 AES_KEY cmd0c_AES_key;
188 IDEA_KEY_SCHEDULE cmd0c_IDEA_dkey;
190 uint8_t receive_buffer[CC_MAXMSGSIZE];
191 uint8_t send_buffer[CC_MAXMSGSIZE];
193 LLIST *cards; // cards list
195 int32_t max_ecms;
196 int32_t ecm_counter;
197 int32_t card_added_count;
198 int32_t card_removed_count;
199 uint8_t just_logged_in; //true for checking NOK direct after login
200 uint8_t key_table; //key for CMD 0B
202 LLIST *pending_emms; //pending emm list
204 uint32_t recv_ecmtask;
206 struct cc_card *last_emm_card;
207 int32_t server_ecm_pending; //initialized by server
208 uint16_t server_ecm_idx;
210 CS_MUTEX_LOCK lockcmd;
211 int8_t ecm_busy;
212 CS_MUTEX_LOCK cards_busy;
213 struct timeb ecm_time;
214 uint8_t last_msg;
215 uint8_t cmd05NOK;
217 char remote_version[7];
218 char remote_build[7];
219 char remote_oscam[200];
221 uint8_t cccam220;
222 uint32_t remote_build_nr;
223 uint8_t sleepsend;
225 //Extended Mode for SPECIAL clients:
226 uint8_t extended_mode;
227 LLIST *extended_ecm_idx;
229 //multics detection
230 int8_t multics_mode;
231 int8_t multics_version[2];
233 //stats:
234 int32_t num_hop1;
235 int32_t num_hop2;
236 int32_t num_hopx;
238 int32_t num_reshare0;
239 int32_t num_reshare1;
240 int32_t num_reshare2;
241 int32_t num_resharex;
243 char *nok_message;
246 #endif