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