source: trunk/module-cccam.h@ 4004

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

cccam: added UA/SA to webif reader cards.

File size: 4.0 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#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
27typedef enum {
28 DECRYPT, ENCRYPT
29} cc_crypt_mode_t;
30
31typedef 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_NEW_CARD_SIDINFO = 0x0f,
46 MSG_CW_NOK1 = 0xfe, //Node no more available
47 MSG_CW_NOK2 = 0xff, //No decoding
48 MSG_NO_HEADER = 0xffff
49} cc_msg_type_t;
50
51struct cc_crypt_block {
52 uint8 keytable[256];
53 uint8 state;
54 uint8 counter;
55 uint8 sum;
56};
57
58struct cc_srvid {
59 uint16 sid;
60 uint8 ecmlen;
61};
62
63struct cc_provider {
64 ulong prov; //provider
65 uint8 sa[4]; //shared address
66};
67
68struct cc_card {
69 uint32 id; // cccam card (share) id
70 uint32 remote_id;
71 uint16 caid;
72 uint8 hop;
73 uint8 maxdown;
74 uint8 hexserial[8]; // card serial (for au)
75 LLIST *providers; // providers (struct cc_provider)
76 LLIST *badsids; // sids that have failed to decode (struct cc_srvid)
77 time_t time;
78 LLIST *goodsids; //sids that could decoded (struct cc_srvid)
79 LLIST *remote_nodes; //remote note id, 8 bytes
80};
81
82struct cc_auto_blocked {
83 uint16 caid;
84 uint32 prov;
85 struct cc_srvid srvid;
86 time_t time;
87};
88
89struct cc_current_card {
90 struct cc_card *card;
91 uint32 prov;
92 struct cc_srvid srvid;
93};
94
95typedef enum {
96 MODE_UNKNOWN = 0,
97 MODE_PLAIN = 1,
98 MODE_AES = 2,
99 MODE_CC_CRYPT = 3,
100 MODE_RC4_CRYPT = 4,
101 MODE_LEN0 = 5,
102} cc_cmd05_mode;
103
104struct cc_extended_ecm_idx {
105 uint8 send_idx;
106 ushort ecm_idx;
107 struct cc_card *card;
108 struct cc_srvid srvid;
109} EXTENDED_ECM_IDX;
110
111struct cc_data {
112 uint8 g_flag;
113 char *prefix;
114
115 struct cc_crypt_block block[2]; // crypto state blocks
116
117 uint8 node_id[8], // client node id
118 peer_node_id[8], // server node id
119 peer_version[8], // server version
120 dcw[16]; // control words
121 uint8 cmd0b_aeskey[16];
122 uint8 cmd05_aeskey[16];
123 struct cc_crypt_block cmd05_cryptkey;
124
125 uint8 is_oscam_cccam;
126 uint8 cmd05_active;
127 int cmd05_data_len;
128 uint8 cmd05_data[256];
129 cc_cmd05_mode cmd05_mode;
130 int cmd05_offset;
131 uint8 receive_buffer[CC_MAXMSGSIZE];
132
133 LLIST *cards; // cards list
134 int cards_modified;
135
136 int max_ecms;
137 int ecm_counter;
138 uint32 report_carddata_id; //Server only
139 LLIST *reported_carddatas; //struct cc_reported_carddata //struct cc_reported_carddata
140 int card_added_count;
141 int card_removed_count;
142 int card_dup_count;
143 uint8 just_logged_in; //true for checking NOK direct after login
144 uint8 key_table; //key for CMD 0B
145
146 LLIST *pending_emms; //pending emm list
147
148 uint32 recv_ecmtask;
149
150 LLIST *current_cards; //reader: current card cache
151 int server_ecm_pending; //initialized by server
152 ushort server_ecm_idx;
153
154 pthread_mutex_t lock;
155 pthread_mutex_t ecm_busy;
156 pthread_mutex_t cards_busy;
157 struct timeb ecm_time;
158 time_t answer_on_keepalive;
159 uint8 last_msg;
160 uint8 cmd05NOK;
161
162 char remote_version[7];
163 char remote_build[7];
164 char remote_oscam[200];
165 uint8 cccam220;
166
167 uint8 mode;
168
169 //Extended Mode for SPECIAL clients:
170 uint8 extended_mode;
171 LLIST *extended_ecm_idx;
172};
173
174int cc_cli_init();
175int cc_cli_init_int(struct s_client *cl);
176void cc_cleanup(struct s_client *cl);
177int cc_cli_connect(struct s_client *cl);
178int cc_get_nxt_ecm(struct s_client *cl);
179int cc_send_pending_emms(struct s_client *cl);
180void cc_rc4_crypt(struct cc_crypt_block *block, uint8 *data, int len,
181 cc_crypt_mode_t mode);
182void free_extended_ecm_idx(struct cc_data *cc);
183void cc_free_card(struct cc_card *card);
184int cc_UA_valid(uint8 *ua);
185void cc_UA_cccam2oscam(uint8 *in, uint8 *out, uint16 caid);
186
187#endif /* MODULECCCAM_H_ */
Note: See TracBrowser for help on using the repository browser.