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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
/*
* (c) BayCom GmbH, http://www.baycom.de, info@baycom.de
*
* See the COPYING file for copyright information and
* how to reach the author.
*
*/
#ifndef __DEFS_H__
#define __DEFS_H__
#ifdef WIN32
#ifdef __CYGWIN__
#include <cygwin/version.h>
#include <cygwin/in.h>
#include <cygwin/socket.h>
#else
#define _CRT_SECURE_NO_WARNINGS
#define _WIN32_WINNT 0x0502
#include <winsock2.h>
#include <WS2tcpip.h>
#include <iphlpapi.h>
#define _SOTYPE char*
#define IFNAMSIZ 1024
#define CA_TPDU_MAX 2048
#define _POSIX_PATH_MAX MAX_PATH
#define usleep(useconds) Sleep((useconds+500)/1000)
#define sleep(seconds) Sleep((seconds)*1000)
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#ifndef IP_ADAPTER_IPV6_ENABLED
#define IP_ADAPTER_IPV6_ENABLED 0x0100
#endif
int inet_pton(int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
int inet_aton(const char *cp, struct in_addr *addr);
#ifndef __MINGW32__
int getopt(int nargc, char **nargv, char *ostr);
extern int opterr, optind, optopt, optreset;
extern char *optarg;
#define inline __inline
#endif
typedef struct
{
DWORD thread;
HANDLE threadH; /* Win32 thread handle - POSIX thread is invalid if threadH == 0 */
} ptw32_thread_t;
typedef unsigned int uint32_t;
typedef uint32_t __u32;
typedef uint32_t u_int32_t;
typedef unsigned short uint16_t;
typedef uint16_t __u16;
typedef uint16_t u_int16_t;
typedef unsigned char uint8_t;
typedef uint8_t __u8;
typedef uint8_t u_int8_t;
#ifndef s6_addr16
#define s6_addr16 s6_words
#endif
#if ! defined _GNU_SOURCE && defined __cplusplus
#define CALLCONV extern "C"
#else
#define CALLCONV
#endif
#ifdef LIBRARY
#define DLL_SYMBOL CALLCONV __declspec( dllexport )
#else
#ifdef STATICLIB
#define DLL_SYMBOL CALLCONV
#else
#define DLL_SYMBOL CALLCONV __declspec( dllimport )
#endif
#endif
#define pthread_exist(x) (x).p
#define pthread_null(x) (x).p=NULL
#define _SOTYPE char*
#define INET6
#define API_WIN
#define LIBXML_STATIC
#define PTW32_STATIC_LIB
#define MULTI_THREAD_RECEIVER
#include <poll.h>
#endif
#else
#if defined __cplusplus
#define CALLCONV extern "C"
#else
#define CALLCONV
#endif
#define DLL_SYMBOL CALLCONV
#define pthread_exist(x) x
#define pthread_null(x) x=0
#define _SOTYPE void*
#define SOCKET int
#if ! (defined __uClinux__ || defined APPLE || defined MIPSEL)
#include <mcheck.h>
#include <ifaddrs.h>
#endif
#include <pwd.h>
#include <sched.h>
#include <syslog.h>
#include <unistd.h>
#include <getopt.h>
#include <stdint.h>
#include <termios.h>
#include <arpa/inet.h>
#ifndef APPLE
#include <linux/version.h>
#include <netpacket/packet.h>
#include <sys/sysinfo.h>
#else
typedef unsigned int uint32_t;
typedef uint32_t __u32;
typedef uint32_t u_int32_t;
typedef unsigned short uint16_t;
typedef uint16_t __u16;
typedef uint16_t u_int16_t;
typedef unsigned char uint8_t;
typedef uint8_t __u8;
typedef uint8_t u_int8_t;
#define CA_TPDU_MAX 2048
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
#ifndef s6_addr16
#define s6_addr16 __u6_addr.__u6_addr16
#endif
#endif
#include <netdb.h>
#include <net/if.h>
#ifdef APPLE
#include <ifaddrs.h>
#include <net/if_types.h>
#endif
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/icmp6.h>
#include <netinet/ip_icmp.h>
#include <netinet/if_ether.h>
#include <netinet/ip6.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/poll.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h> /* for iovec{} and readv/writev */
#include <sys/un.h> /* for Unix domain sockets */
#include <sys/utsname.h>
#include <sys/wait.h>
#if defined __uClinux__
#include <mathf.h>
#endif
#define closesocket close
#endif
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <math.h>
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <zlib.h>
#include <sys/stat.h>
//----------------------------------------------------------------------
#ifndef __uClinux__
//DVBAPI
#include <linux/dvb/version.h>
#include <linux/dvb/frontend.h>
#include <linux/dvb/ca.h>
#if ! (defined WIN32 || defined APPLE)
#include <linux/dvb/dmx.h>
#endif
// #else
// #endif
#define dvb_ioctl ioctl
#define dvb_close close
#else
#include <dvb/frontend.h>
#include <ci/ca.h>
#endif
#define CA_TPDU_MAX 2048
typedef struct recv_sec
{
struct dvb_diseqc_master_cmd diseqc_cmd;
fe_sec_mini_cmd_t mini_cmd;
fe_sec_tone_mode_t tone_mode;
fe_sec_voltage_t voltage;
} recv_sec_t;
#define CA_MAX_SLOTS 16
typedef struct {
ca_caps_t cap;
ca_slot_info_t info[CA_MAX_SLOTS];
} recv_cacaps_t;
typedef struct recv_festatus
{
fe_status_t st;
uint32_t ber;
uint16_t strength;
uint16_t snr;
uint32_t ucblocks;
} recv_festatus_t;
//XML
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#if ! defined GETTID && ! defined WIN32 && ! defined APPLE
#include <asm/unistd.h>
#define gettid() syscall (__NR_gettid)
#else
#define gettid pthread_self
#endif
#define UUID_SIZE 256
#ifndef WIN32
#ifdef SYSLOG
extern char *_logstr;
extern pthread_mutex_t _loglock;
#ifdef DEBUG
#define dbg(format, arg...) { pthread_mutex_lock (&_loglock); sprintf(_logstr, "%s:%d " format , __FILE__ , __LINE__ , ## arg); syslog_write(_logstr); pthread_mutex_unlock (&_loglock);}
#else
#define dbg(format, arg...) do {} while (0)
#endif
#define err(format, arg...) {pthread_mutex_lock (&_loglock); sprintf(_logstr, "err:%s:%d: %s (%d): " format , __FILE__ , __LINE__ ,strerror(errno), errno, ## arg); fprintf(stdout, "%s", _logstr); syslog_write(_logstr);abort(); pthread_mutex_unlock (&_loglock);}
#define info(format, arg...){pthread_mutex_lock (&_loglock); sprintf(_logstr, format ,## arg); fprintf(stdout, "%s", _logstr); syslog_write(_logstr); pthread_mutex_unlock (&_loglock);}
#define warn(format, arg...){pthread_mutex_lock (&_loglock); sprintf(_logstr, format ,## arg); fprintf(stdout, "%s", _logstr); syslog_write(_logstr); pthread_mutex_unlock (&_loglock);}
#define sys(format, arg...){pthread_mutex_lock (&_loglock); sprintf(_logstr, format ,## arg); syslog_write(_logstr); pthread_mutex_unlock (&_loglock);}
#elif defined DEBUG
#define dbg(format, arg...) {printf("%s:%d " format , __FILE__ , __LINE__ , ## arg)}
#define err(format, arg...) {fprintf(stderr,"err:%s:%d: %s (%d): " format , __FILE__ , __LINE__ ,strerror(errno), errno, ## arg);print_trace();abort();}
#define info(format, arg...) printf("%s:%d: " format , __FILE__ , __LINE__ ,## arg)
#define warn(format, arg...) fprintf(stderr,"%s:%d: " format , __FILE__ , __LINE__ ,## arg)
#else
#define dbg(format, arg...) do {} while (0)
#define err(format, arg...) {fprintf(stderr,"%s (%d): " format, strerror(errno), errno, ## arg);exit(-1);}
#define info(format, arg...) printf(format , ## arg)
#define warn(format, arg...) fprintf(stderr, format , ## arg)
#define sys(format, arg...) printf(format, ## arg)
#endif // SYSLOG
#else // !WIN32
#ifdef DEBUG
static void inline dbg (char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf (buffer, format, args);
printf("%s:%d %s", __FILE__ , __LINE__ , buffer);
va_end (args);
}
static void inline err (char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format , args);
fprintf(stderr, "err:%s:%d: %s (%d): %s " , __FILE__ , __LINE__ ,strerror(errno), errno, buffer);
va_end (args);
abort();
}
static void inline info(const char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format , args);
printf("%s:%d: %s" , __FILE__ , __LINE__ , buffer);
va_end (args);
}
static void inline warn(const char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format , args);
fprintf(stderr, "%s:%d: %s", __FILE__ , __LINE__ , buffer );
va_end (args);
}
static void inline sys(const char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format , args);
printf("%s:%d: %s", __FILE__ , __LINE__ , buffer );
va_end (args);
}
#else
static void inline dbg (char *format, ...)
{
}
static void inline err (char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format, args);
fprintf(stderr, "err:%s:%d: %s",strerror(errno), errno, buffer);
va_end (args);
abort();
}
static void inline info(const char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format, args);
puts(buffer);
va_end (args);
}
static void inline warn(const char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format, args);
fputs(buffer, stderr);
va_end (args);
}
static void inline sys(const char *format, ...)
{
char buffer[1024];
va_list args;
va_start (args, format);
vsprintf(buffer, format, args);
fputs(buffer, stdout);
va_end (args);
}
#endif //DEBUG
#endif // WIN32
#ifndef MICROBLAZE
#define FE_DVBS2 (FE_ATSC+1)
#endif
// RMM S2 Extension
#define FEC_1_4 10
#define FEC_1_3 11
#define FEC_2_5 12
#define FEC_3_5 13
#define FEC_9_10 14
#define QPSK_S2 9
#define PSK8 10
#ifdef MICROBLAZE
#define STATIC
#else
#define STATIC static
#endif
#endif
|