1 | /*
|
---|
2 | * module-cccam.h
|
---|
3 | *
|
---|
4 | * Created on: 23.04.2010
|
---|
5 | * Author: alno
|
---|
6 | */
|
---|
7 | #include "module-obj-llist.h"
|
---|
8 |
|
---|
9 | #ifndef MODULECCCAM_H_
|
---|
10 | #define MODULECCCAM_H_
|
---|
11 |
|
---|
12 | #define CC_MAXMSGSIZE 512
|
---|
13 | #define CC_MAX_PROV 16
|
---|
14 | #define CC_CAIDINFO_REBUILD 200 //SS: Rebuid Caidinfos after 200 Card-Updates
|
---|
15 | #define SWAPC(X, Y) do { char p; p = *X; *X = *Y; *Y = p; } while(0)
|
---|
16 |
|
---|
17 | #if (defined(WIN32) || defined(OS_CYGWIN32)) && !defined(MSG_WAITALL)
|
---|
18 | # define MSG_WAITALL 0
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | typedef enum {
|
---|
22 | DECRYPT, ENCRYPT
|
---|
23 | } cc_crypt_mode_t;
|
---|
24 |
|
---|
25 | typedef enum {
|
---|
26 | MSG_CLI_DATA = 0,
|
---|
27 | MSG_CW_ECM = 1,
|
---|
28 | MSG_EMM_ACK = 2,
|
---|
29 | MSG_CARD_REMOVED = 4,
|
---|
30 | MSG_CMD_05 = 5,
|
---|
31 | MSG_KEEPALIVE = 6,
|
---|
32 | MSG_NEW_CARD = 7,
|
---|
33 | MSG_SRV_DATA = 8,
|
---|
34 | MSG_CMD_0A = 0x0a,
|
---|
35 | MSG_CMD_0B = 0x0b,
|
---|
36 | MSG_CW_NOK1 = 0xfe,
|
---|
37 | MSG_CW_NOK2 = 0xff,
|
---|
38 | MSG_NO_HEADER = 0xffff
|
---|
39 | } cc_msg_type_t;
|
---|
40 |
|
---|
41 | struct cc_crypt_block {
|
---|
42 | uint8 keytable[256];
|
---|
43 | uint8 state;
|
---|
44 | uint8 counter;
|
---|
45 | uint8 sum;
|
---|
46 | };
|
---|
47 |
|
---|
48 | struct cc_srvid {
|
---|
49 | uint16 sid;
|
---|
50 | uint8 ecmlen;
|
---|
51 | };
|
---|
52 |
|
---|
53 | struct cc_card {
|
---|
54 | uint32 id; // cccam card (share) id
|
---|
55 | uint32 sub_id; // subshare id
|
---|
56 | uint16 caid;
|
---|
57 | uint8 hop;
|
---|
58 | uint8 maxdown;
|
---|
59 | uint8 hexserial[8]; // card serial (for au)
|
---|
60 | LLIST *provs; // providers
|
---|
61 | LLIST *badsids; // sids that have failed to decode (struct cc_srvid)
|
---|
62 | time_t time;
|
---|
63 | LLIST *goodsids; //sids that could decoded
|
---|
64 | };
|
---|
65 |
|
---|
66 | struct cc_reported_carddata {
|
---|
67 | uint8 *buf;
|
---|
68 | int len;
|
---|
69 | };
|
---|
70 |
|
---|
71 | struct cc_caid_info {
|
---|
72 | uint16 caid;
|
---|
73 | LLIST *provs;
|
---|
74 | uint8 hop;
|
---|
75 | };
|
---|
76 |
|
---|
77 | struct cc_auto_blocked {
|
---|
78 | uint16 caid;
|
---|
79 | uint32 prov;
|
---|
80 | struct cc_srvid srvid;
|
---|
81 | time_t time;
|
---|
82 | };
|
---|
83 |
|
---|
84 | struct cc_current_card {
|
---|
85 | struct cc_card *card;
|
---|
86 | uint32 prov;
|
---|
87 | struct cc_srvid srvid;
|
---|
88 | };
|
---|
89 |
|
---|
90 | typedef enum {
|
---|
91 | MODE_UNKNOWN = 0,
|
---|
92 | MODE_PLAIN = 1,
|
---|
93 | MODE_AES = 2,
|
---|
94 | MODE_CC_CRYPT = 3,
|
---|
95 | MODE_RC4_CRYPT = 4,
|
---|
96 | MODE_LEN0 = 5,
|
---|
97 | } cc_cmd05_mode;
|
---|
98 |
|
---|
99 | struct cc_data {
|
---|
100 | struct cc_crypt_block block[2]; // crypto state blocks
|
---|
101 |
|
---|
102 | uint8 node_id[8], // client node id
|
---|
103 | peer_node_id[8], // server node id
|
---|
104 | peer_version[8], // server version
|
---|
105 | dcw[16]; // control words
|
---|
106 | uint8 cmd0b_aeskey[16];
|
---|
107 | uint8 cmd05_aeskey[16];
|
---|
108 | struct cc_crypt_block cmd05_cryptkey;
|
---|
109 |
|
---|
110 | int is_oscam_cccam;
|
---|
111 | int cmd05_active;
|
---|
112 | int cmd05_data_len;
|
---|
113 | uint8 cmd05_data[256];
|
---|
114 | cc_cmd05_mode cmd05_mode;
|
---|
115 | int cmd05_offset;
|
---|
116 | uint8 receive_buffer[CC_MAXMSGSIZE];
|
---|
117 |
|
---|
118 | LLIST *cards; // cards list
|
---|
119 |
|
---|
120 | LLIST *caid_infos; //struct cc_caid_info
|
---|
121 | long caid_size;
|
---|
122 | uint16 needs_rebuild_caidinfo;
|
---|
123 | int max_ecms;
|
---|
124 | int ecm_counter;
|
---|
125 | uint32 report_carddata_id; //Server only
|
---|
126 | LLIST *reported_carddatas; //struct cc_reported_carddata //struct cc_reported_carddata
|
---|
127 | LLIST *auto_blocked; //struct cc_auto_blocked //struct cc_auto_blocked
|
---|
128 | int just_logged_in; //true for checking NOK direct after login
|
---|
129 | uint8 key_table; //key for CMD 0B
|
---|
130 |
|
---|
131 | LLIST *pending_emms; //pending emm list
|
---|
132 |
|
---|
133 | ulong crc;
|
---|
134 | uint32 send_ecmtask;
|
---|
135 | uint32 recv_ecmtask;
|
---|
136 |
|
---|
137 | int current_ecm_cidx; //index to last current_card (reader)
|
---|
138 | struct cc_current_card *current_card; //initialized by reader (index CS_MAXPID)
|
---|
139 | struct cc_card *server_card; //initialized by server
|
---|
140 | int server_ecm_pending; //initialized by server
|
---|
141 |
|
---|
142 | pthread_mutex_t lock;
|
---|
143 | pthread_mutex_t ecm_busy;
|
---|
144 | struct timeb ecm_time;
|
---|
145 | time_t answer_on_keepalive;
|
---|
146 | };
|
---|
147 |
|
---|
148 | #endif /* MODULECCCAM_H_ */
|
---|