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