source: trunk/module-cccam.h@ 4012

Last change on this file since 4012 was 4012, checked in by schlocke, 10 years ago

cccam: added full cccam 2.2.x support !!

File size: 4.4 KB
Line 
1/*
2 * module-cccam.h
3 *
4 * Created on: 23.04.2010
5 * Author: alno
6 */
7#ifndef MODULECCCAM_H_
8#define MODULECCCAM_H_
9
10#include "module-datastruct-llist.h"
11
12#include "cscrypt/rc6.h"
13#include "cscrypt/idea.h"
14
15#define CC_MAXMSGSIZE 512
16#define CC_MAX_PROV 16
17#define SWAPC(X, Y) do { char p; p = *X; *X = *Y; *Y = p; } while(0)
18
19#if (defined(WIN32) || defined(OS_CYGWIN32)) && !defined(MSG_WAITALL)
20# define MSG_WAITALL 0
21#endif
22
23#define MINIMIZE_NONE 0
24#define MINIMIZE_HOPS 1
25#define MINIMIZE_CAID 2
26
27#define CCCAM_MODE_NORMAL 0
28#define CCCAM_MODE_SHUTDOWN 0xFF
29
30typedef enum {
31 DECRYPT, ENCRYPT
32} cc_crypt_mode_t;
33
34typedef enum {
35 MSG_CLI_DATA = 0,
36 MSG_CW_ECM = 1,
37 MSG_EMM_ACK = 2,
38 MSG_CARD_REMOVED = 4,
39 MSG_CMD_05 = 5,
40 MSG_KEEPALIVE = 6,
41 MSG_NEW_CARD = 7,
42 MSG_SRV_DATA = 8,
43 MSG_CMD_0A = 0x0a,
44 MSG_CMD_0B = 0x0b,
45 MSG_CMD_0C = 0x0c, //Attacking Commands! Just logging the user
46 MSG_CMD_0D = 0x0d, // "
47 MSG_CMD_0E = 0x0e, // "
48 MSG_NEW_CARD_SIDINFO = 0x0f,
49 MSG_CW_NOK1 = 0xfe, //Node no more available
50 MSG_CW_NOK2 = 0xff, //No decoding
51 MSG_NO_HEADER = 0xffff
52} cc_msg_type_t;
53
54struct cc_crypt_block {
55 uint8 keytable[256];
56 uint8 state;
57 uint8 counter;
58 uint8 sum;
59};
60
61struct cc_srvid {
62 uint16 sid;
63 uint8 ecmlen;
64};
65
66struct cc_provider {
67 ulong prov; //provider
68 uint8 sa[4]; //shared address
69};
70
71struct cc_card {
72 uint32 id; // cccam card (share) id
73 uint32 remote_id;
74 uint16 caid;
75 uint8 hop;
76 uint8 maxdown;
77 uint8 hexserial[8]; // card serial (for au)
78 LLIST *providers; // providers (struct cc_provider)
79 LLIST *badsids; // sids that have failed to decode (struct cc_srvid)
80 time_t time;
81 LLIST *goodsids; //sids that could decoded (struct cc_srvid)
82 LLIST *remote_nodes; //remote note id, 8 bytes
83};
84
85struct cc_auto_blocked {
86 uint16 caid;
87 uint32 prov;
88 struct cc_srvid srvid;
89 time_t time;
90};
91
92struct cc_current_card {
93 struct cc_card *card;
94 uint32 prov;
95 struct cc_srvid srvid;
96};
97
98typedef enum {
99 MODE_UNKNOWN = 0,
100 MODE_PLAIN = 1,
101 MODE_AES = 2,
102 MODE_CC_CRYPT = 3,
103 MODE_RC4_CRYPT = 4,
104 MODE_LEN0 = 5,
105} cc_cmd05_mode;
106
107typedef enum {
108 MODE_CMD_0x0C_NONE = 0,
109 MODE_CMD_0x0C_RC6 = 1,
110 MODE_CMD_0x0C_RC4 = 2,
111 MODE_CMD_0x0C_CC_CRYPT = 3,
112 MODE_CMD_0x0C_AES = 4,
113 MODE_CMD_0x0C_IDEA = 5,
114} cc_cmd0c_mode;
115
116
117struct cc_extended_ecm_idx {
118 uint8 send_idx;
119 ushort ecm_idx;
120 struct cc_card *card;
121 struct cc_srvid srvid;
122} EXTENDED_ECM_IDX;
123
124struct cc_data {
125 uint8 g_flag;
126 char *prefix;
127
128 struct cc_crypt_block block[2]; // crypto state blocks
129
130 uint8 node_id[8], // client node id
131 peer_node_id[8], // server node id
132 peer_version[8], // server version
133 dcw[16]; // control words
134 uint8 cmd0b_aeskey[16];
135 uint8 cmd05_aeskey[16];
136 struct cc_crypt_block cmd05_cryptkey;
137
138 uint8 is_oscam_cccam;
139 uint8 cmd05_active;
140 int cmd05_data_len;
141 uint8 cmd05_data[256];
142 cc_cmd05_mode cmd05_mode;
143 int cmd05_offset;
144
145 cc_cmd0c_mode cmd0c_mode;
146 struct cc_crypt_block cmd0c_cryptkey;
147 RC6KEY cmd0c_RC6_cryptkey;
148 AES_KEY cmd0c_AES_key;
149 IDEA_KEY_SCHEDULE cmd0c_IDEA_dkey;
150
151 uint8 receive_buffer[CC_MAXMSGSIZE];
152
153 LLIST *cards; // cards list
154 int cards_modified;
155
156 int max_ecms;
157 int ecm_counter;
158 uint32 report_carddata_id; //Server only
159 LLIST *reported_carddatas; //struct cc_reported_carddata //struct cc_reported_carddata
160 int card_added_count;
161 int card_removed_count;
162 int card_dup_count;
163 uint8 just_logged_in; //true for checking NOK direct after login
164 uint8 key_table; //key for CMD 0B
165
166 LLIST *pending_emms; //pending emm list
167
168 uint32 recv_ecmtask;
169
170 LLIST *current_cards; //reader: current card cache
171 int server_ecm_pending; //initialized by server
172 ushort server_ecm_idx;
173
174 pthread_mutex_t lock;
175 pthread_mutex_t ecm_busy;
176 pthread_mutex_t cards_busy;
177 struct timeb ecm_time;
178 time_t answer_on_keepalive;
179 uint8 last_msg;
180 uint8 cmd05NOK;
181
182 char remote_version[7];
183 char remote_build[7];
184 char remote_oscam[200];
185 uint8 cccam220;
186
187 uint8 mode;
188
189 //Extended Mode for SPECIAL clients:
190 uint8 extended_mode;
191 LLIST *extended_ecm_idx;
192};
193
194int cc_cli_init();
195int cc_cli_init_int(struct s_client *cl);
196void cc_cleanup(struct s_client *cl);
197int cc_cli_connect(struct s_client *cl);
198int cc_get_nxt_ecm(struct s_client *cl);
199int cc_send_pending_emms(struct s_client *cl);
200void cc_rc4_crypt(struct cc_crypt_block *block, uint8 *data, int len,
201 cc_crypt_mode_t mode);
202void free_extended_ecm_idx(struct cc_data *cc);
203void cc_free_card(struct cc_card *card);
204int cc_UA_valid(uint8 *ua);
205void cc_UA_cccam2oscam(uint8 *in, uint8 *out, uint16 caid);
206
207#endif /* MODULECCCAM_H_ */
Note: See TracBrowser for help on using the repository browser.