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 |
|
---|
30 | typedef enum {
|
---|
31 | DECRYPT, ENCRYPT
|
---|
32 | } cc_crypt_mode_t;
|
---|
33 |
|
---|
34 | typedef 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, // CCCam 2.2.x fake client checks
|
---|
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 |
|
---|
54 | struct cc_crypt_block {
|
---|
55 | uint8 keytable[256];
|
---|
56 | uint8 state;
|
---|
57 | uint8 counter;
|
---|
58 | uint8 sum;
|
---|
59 | };
|
---|
60 |
|
---|
61 | struct cc_srvid {
|
---|
62 | uint16 sid;
|
---|
63 | uint8 ecmlen;
|
---|
64 | };
|
---|
65 |
|
---|
66 | struct cc_provider {
|
---|
67 | ulong prov; //provider
|
---|
68 | uint8 sa[4]; //shared address
|
---|
69 | };
|
---|
70 |
|
---|
71 | struct 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 | void *origin_reader;
|
---|
84 | };
|
---|
85 |
|
---|
86 | struct cc_auto_blocked {
|
---|
87 | uint16 caid;
|
---|
88 | uint32 prov;
|
---|
89 | struct cc_srvid srvid;
|
---|
90 | time_t time;
|
---|
91 | };
|
---|
92 |
|
---|
93 | struct cc_current_card {
|
---|
94 | struct cc_card *card;
|
---|
95 | uint32 prov;
|
---|
96 | struct cc_srvid srvid;
|
---|
97 | };
|
---|
98 |
|
---|
99 | typedef enum {
|
---|
100 | MODE_UNKNOWN = 0,
|
---|
101 | MODE_PLAIN = 1,
|
---|
102 | MODE_AES = 2,
|
---|
103 | MODE_CC_CRYPT = 3,
|
---|
104 | MODE_RC4_CRYPT = 4,
|
---|
105 | MODE_LEN0 = 5,
|
---|
106 | } cc_cmd05_mode;
|
---|
107 |
|
---|
108 | typedef enum {
|
---|
109 | MODE_CMD_0x0C_NONE = 0,
|
---|
110 | MODE_CMD_0x0C_RC6 = 1,
|
---|
111 | MODE_CMD_0x0C_RC4 = 2,
|
---|
112 | MODE_CMD_0x0C_CC_CRYPT = 3,
|
---|
113 | MODE_CMD_0x0C_AES = 4,
|
---|
114 | MODE_CMD_0x0C_IDEA = 5,
|
---|
115 | } cc_cmd0c_mode;
|
---|
116 |
|
---|
117 |
|
---|
118 | struct cc_extended_ecm_idx {
|
---|
119 | uint8 send_idx;
|
---|
120 | ushort ecm_idx;
|
---|
121 | struct cc_card *card;
|
---|
122 | struct cc_srvid srvid;
|
---|
123 | } EXTENDED_ECM_IDX;
|
---|
124 |
|
---|
125 | struct cc_data {
|
---|
126 | uint8 g_flag;
|
---|
127 | char *prefix;
|
---|
128 |
|
---|
129 | struct cc_crypt_block block[2]; // crypto state blocks
|
---|
130 |
|
---|
131 | uint8 node_id[8], // client node id
|
---|
132 | peer_node_id[8], // server node id
|
---|
133 | peer_version[8], // server version
|
---|
134 | dcw[16]; // control words
|
---|
135 | uint8 cmd0b_aeskey[16];
|
---|
136 | uint8 cmd05_aeskey[16];
|
---|
137 | struct cc_crypt_block cmd05_cryptkey;
|
---|
138 |
|
---|
139 | uint8 is_oscam_cccam;
|
---|
140 | uint8 cmd05_active;
|
---|
141 | int cmd05_data_len;
|
---|
142 | uint8 cmd05_data[256];
|
---|
143 | cc_cmd05_mode cmd05_mode;
|
---|
144 | int cmd05_offset;
|
---|
145 |
|
---|
146 | cc_cmd0c_mode cmd0c_mode;
|
---|
147 | struct cc_crypt_block cmd0c_cryptkey;
|
---|
148 | RC6KEY cmd0c_RC6_cryptkey;
|
---|
149 | AES_KEY cmd0c_AES_key;
|
---|
150 | IDEA_KEY_SCHEDULE cmd0c_IDEA_dkey;
|
---|
151 |
|
---|
152 | uint8 receive_buffer[CC_MAXMSGSIZE];
|
---|
153 |
|
---|
154 | LLIST *cards; // cards list
|
---|
155 | int cards_modified;
|
---|
156 |
|
---|
157 | int max_ecms;
|
---|
158 | int ecm_counter;
|
---|
159 | uint32 report_carddata_id; //Server only
|
---|
160 | LLIST *reported_carddatas; //struct cc_reported_carddata //struct cc_reported_carddata
|
---|
161 | int card_added_count;
|
---|
162 | int card_removed_count;
|
---|
163 | int card_dup_count;
|
---|
164 | uint8 just_logged_in; //true for checking NOK direct after login
|
---|
165 | uint8 key_table; //key for CMD 0B
|
---|
166 |
|
---|
167 | LLIST *pending_emms; //pending emm list
|
---|
168 |
|
---|
169 | uint32 recv_ecmtask;
|
---|
170 |
|
---|
171 | LLIST *current_cards; //reader: current card cache
|
---|
172 | int server_ecm_pending; //initialized by server
|
---|
173 | ushort server_ecm_idx;
|
---|
174 |
|
---|
175 | pthread_mutex_t lock;
|
---|
176 | pthread_mutex_t ecm_busy;
|
---|
177 | pthread_mutex_t cards_busy;
|
---|
178 | struct timeb ecm_time;
|
---|
179 | time_t answer_on_keepalive;
|
---|
180 | uint8 last_msg;
|
---|
181 | uint8 cmd05NOK;
|
---|
182 |
|
---|
183 | char remote_version[7];
|
---|
184 | char remote_build[7];
|
---|
185 | char remote_oscam[200];
|
---|
186 | uint8 cccam220;
|
---|
187 |
|
---|
188 | uint8 mode;
|
---|
189 |
|
---|
190 | //Extended Mode for SPECIAL clients:
|
---|
191 | uint8 extended_mode;
|
---|
192 | LLIST *extended_ecm_idx;
|
---|
193 | };
|
---|
194 |
|
---|
195 | int cc_cli_init();
|
---|
196 | int cc_cli_init_int(struct s_client *cl);
|
---|
197 | void cc_cleanup(struct s_client *cl);
|
---|
198 | int cc_cli_connect(struct s_client *cl);
|
---|
199 | int cc_get_nxt_ecm(struct s_client *cl);
|
---|
200 | int cc_send_pending_emms(struct s_client *cl);
|
---|
201 | void cc_rc4_crypt(struct cc_crypt_block *block, uint8 *data, int len,
|
---|
202 | cc_crypt_mode_t mode);
|
---|
203 | void free_extended_ecm_idx(struct cc_data *cc);
|
---|
204 | void cc_free_card(struct cc_card *card);
|
---|
205 | int cc_UA_valid(uint8 *ua);
|
---|
206 | void cc_UA_cccam2oscam(uint8 *in, uint8 *out, uint16 caid);
|
---|
207 |
|
---|
208 | #endif /* MODULECCCAM_H_ */
|
---|