forked from nx111/oscam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module-gbox.h
196 lines (172 loc) · 5.14 KB
/
module-gbox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef MODULE_GBOX_H_
#define MODULE_GBOX_H_
#ifdef MODULE_GBOX
#define NO_GBOX_ID 0
#define GBOX_MAXHOPS 8
#define DEFAULT_GBOX_MAX_DIST 2
#define DEFAULT_GBOX_MAX_ECM_SEND 5
#define DEFAULT_GBOX_RESHARE 2
#define DEFAULT_CCC_GBOX_RESHARE 1
#define DEFAULT_GBOX_RECONNECT 180
#define GBOX_MIN_RECONNECT 60
#define GBOX_MAX_RECONNECT 300
#define GBOX_MAX_LOCAL_CARDS 32
#define GBOX_SID_CONFIRM_TIME 3600
#define GBOX_DEFAULT_CW_TIME 500
#define RECEIVE_BUFFER_SIZE 1024
#define MIN_GBOX_MESSAGE_LENGTH 10 // CMD + pw + pw. TODO: Check if is really min
#define MIN_ECM_LENGTH 8
#define STATS_WRITE_TIME 60 // write stats file every 1 min
#define MAX_GBOX_CARDS 1024 // send max. 1024 cards to peer
#define LOCAL_GBOX_MAJOR_VERSION 0x02
#define GBOX_START_TIME 30
#define MSG_ECM 0x445C
#define MSG_CW 0x4844
#define MSG_HELLO 0xDDAB
#define MSG_HELLO1 0x4849
#define MSG_CHECKCODE 0x41C0
#define MSG_GOODBYE 0x9091
#define MSG_GSMS_ACK 0x9099
#define MSG_GSMS 0x0FFF
#define MSG_HERE 0xA0A1
#define GBOX_ECM_NEW_REQ 0
#define GBOX_ECM_SENT 1
#define GBOX_ECM_ANSWERED 2
#define GBOX_CARD_TYPE_GBOX 0
#define GBOX_CARD_TYPE_LOCAL 1
#define GBOX_CARD_TYPE_BETUN 2
#define GBOX_CARD_TYPE_CCCAM 3
#define GBOX_CARD_TYPE_PROXY 4
#define FILE_GBOX_VERSION "gbox.ver"
#define FILE_SHARED_CARDS_INFO "share.info"
#define FILE_BACKUP_CARDS_INFO "expired.info"
#define FILE_ATTACK_INFO "attack.txt"
#define FILE_GBOX_PEER_ONL "share.onl"
#define FILE_STATS "stats.info"
#define FILE_MSG_INFO "msg.info"
#define FILE_LOCAL_CARDS_INFO "sc.info"
#define MSGID_GOODNIGHT 0
#define MSGID_GSMS 1
#define MSGID_GONEOFFLINE 2
#define MSGID_COMEONLINE 3
#define MSGID_GOODBYE 4
#define MSGID_LOSTCONNECT 5
#define MSGID_ATTACK 6
#define MSGID_IPCHANGE 7
#define MSGID_GBOXONL 8
#define MSGID_UNKNOWNMSG 9
#define MSGID_REMM 12
#define GBOX_STAT_HELLOL 0
#define GBOX_STAT_HELLOS 1
#define GBOX_STAT_HELLOR 2
#define GBOX_DELETE_FROM_PEER 0
#define GBOX_DELETE_WITH_ID 1
#define GBOX_DELETE_WITH_TYPE 2
#define GBOX_PEER_OFFLINE 0
#define GBOX_PEER_ONLINE 1
#define GBOX_ATTACK_LOCAL_PW 0
#define GBOX_ATTACK_PEER_IGNORE 1
#define GBOX_ATTACK_PEER_PW 2
#define GBOX_ATTACK_AUTH_FAIL 3
#define GBOX_ATTACK_ECM_BLOCKED 4
#define GBOX_ATTACK_REMM_REQ_BLOCKED 5
#define GBOX_ATTACK_UNKWN_HDR 6
#define LOCALCARDEJECTED 1
#define LOCALCARDUP 2
#define LOCALCARDDISABLED 3
struct gbox_srvid
{
uint16_t sid;
uint32_t provid_id;
};
struct gbox_good_srvid
{
struct gbox_srvid srvid;
time_t last_cw_received;
};
struct gbox_bad_srvid
{
struct gbox_srvid srvid;
uint8_t bad_strikes;
};
struct gbox_card_id
{
uint16_t peer;
uint8_t slot;
};
struct gbox_card_pending
{
struct gbox_card_id id;
uint32_t pending_time;
};
struct gbox_card
{
struct gbox_card_id id;
uint32_t caprovid;
uint8_t dist;
uint8_t lvl;
uint8_t type;
LLIST *badsids; // sids that have failed to decode (struct gbox_srvid)
LLIST *goodsids; // sids that could be decoded (struct gbox_srvid)
uint32_t no_cws_returned;
uint32_t average_cw_time;
struct gbox_peer *origin_peer;
};
struct gbox_data
{
uint16_t id;
uint32_t password;
uint8_t minor_version;
uint8_t cpu_api;
};
struct gbox_peer
{
struct gbox_data gbox;
uint8_t *hostname;
uint8_t checkcode[7];
int8_t online;
uint8_t onlinestat;
uint8_t authstat;
uint8_t next_hello;
uint8_t gbox_rev;
uint8_t crd_crc_change;
uint8_t ecm_idx;
CS_MUTEX_LOCK lock;
struct s_client *my_user;
uint16_t filtered_cards;
uint16_t total_cards;
uint32_t last_remm_crc;
};
struct gbox_ecm_request_ext
{
uint8_t gbox_slot;
uint8_t gbox_version;
uint8_t gbox_rev;
uint8_t gbox_type;
uint8_t gbox_routing_info[GBOX_MAXHOPS];
};
void handle_attack(struct s_client *cli, uint8_t txt_id, uint16_t rcvd_id);
char *get_gbox_tmp_fname(char *fext);
uint16_t gbox_get_local_gbox_id(void);
uint16_t gbox_convert_password_to_id(uint32_t password);
uint8_t get_peer_onl_status(uint16_t peer_id);
int8_t check_peer_ignored(uint16_t peer_id);
uint32_t gbox_get_local_gbox_password(void);
void gbox_send(struct s_client *cli, uint8_t *buf, int32_t l);
int8_t gbox_message_header(uint8_t *buf, uint16_t cmd, uint32_t peer_password, uint32_t local_password);
void gbox_free_cards_pending(ECM_REQUEST *er);
void gbox_send_good_night(void);
void gbox_send_goodbye(struct s_client *cli);
void restart_gbox_peer(char *rdrlabel, uint8_t all, uint16_t gbox_id);
void write_msg_info(struct s_client *cli, uint8_t msg_id, uint8_t txt_id, uint16_t misc);
extern void gbx_local_card_stat(uint8_t crdstat, uint16_t caid);
extern void gbox_send_init_hello(void);
extern void stop_gbx_ticker(void);
#else
static inline void gbox_free_cards_pending(ECM_REQUEST *UNUSED(er)) { }
static inline void gbox_send_good_night(void) { }
static inline void gbx_local_card_stat(uint8_t UNUSED(crdstat), uint16_t UNUSED(caid) ) { }
static inline void gbox_send_init_hello(void) { }
static inline void stop_gbx_ticker(void) { }
#endif
#endif