forked from catalinii/minisatip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minisatip.c
1500 lines (1363 loc) · 40.5 KB
/
minisatip.c
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2014-2020 Catalin Toda <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*/
#include "minisatip.h"
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <sys/ucontext.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <syslog.h>
#include "socketworks.h"
#include "stream.h"
#include "adapter.h"
#include "dvb.h"
#include "tables.h"
struct struct_opts opts;
#define DESC_XML "desc.xml"
#define PID_NAME "/var/run/%s.pid"
char version[] = VERSION;
char app_name[] = "minisatip";
char pid_file[50];
extern sockets s[MAX_SOCKS];
char public[] = "Public: OPTIONS, DESCRIBE, SETUP, PLAY, TEARDOWN";
int rtsp, http, si, si1, ssdp1;
static const struct option long_options[] =
{
{ "remote-rtp", required_argument, NULL, 'r' },
{ "device-id", required_argument, NULL, 'D' },
{ "check-signal", no_argument, NULL, 'z' },
{ "clean-psi", no_argument, NULL, 't' },
{ "log", no_argument, NULL, 'l' },
{ "buffer", required_argument, NULL, 'b' },
{ "enable-adapters", required_argument, NULL, 'e' },
{ "unicable", required_argument, NULL, 'u' },
{ "jess", required_argument, NULL, 'j' },
{ "diseqc", required_argument, NULL, 'd' },
{ "diseqc-timing", required_argument, NULL, 'q' },
{"nopm", required_argument, NULL, 'Z'},
#ifndef DISABLE_DVBAPI
{ "dvbapi", required_argument, NULL, 'o' },
#endif
#ifndef DISABLE_SATIPCLIENT
{ "satip-servers", required_argument, NULL, 's' },
{ "satip-tcp", no_argument, NULL, 'O' },
#endif
#ifndef DISABLE_NETCVCLIENT
{ "netceiver", required_argument, NULL, 'n' },
#endif
{ "rtsp-port", required_argument, NULL, 'y' },
{ "http-port", required_argument, NULL, 'x' },
{ "http-host", required_argument, NULL, 'w' },
{ "slave", required_argument, NULL, 'S' },
{ "delsys", required_argument, NULL, 'Y' },
{ "priority", required_argument, NULL, 'i' },
{ "document-root", required_argument, NULL, 'R' },
{ "threads", no_argument, NULL, 'T' },
{ "dmx-source", required_argument, NULL, '9' },
{ "lnb", required_argument, NULL, 'L' },
{ "xml", required_argument, NULL, 'X' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ 0, 0, 0, 0 } };
#define RRTP_OPT 'r'
#define DEVICEID_OPT 'D'
#define HTTPSERVER_OPT 'w'
#define HTTPPORT_OPT 'x'
#define LOG_OPT 'l'
#define HELP_OPT 'h'
#define PLAYLIST_OPT 'p'
#define DVBS2_ADAPTERS_OPT 'a'
#define CLEANPSI_OPT 't'
#define MAC_OPT 'm'
#define FOREGROUND_OPT 'f'
#define DVRBUFFER_OPT 'b'
#define APPBUFFER_OPT 'B'
#define ENABLE_ADAPTERS_OPT 'e'
#define UNICABLE_OPT 'u'
#define JESS_OPT 'j'
#define DISEQC_OPT 'd'
#define DISEQC_TIMING_OPT 'q'
#define SLAVE_OPT 'S'
#define DELSYS_OPT 'Y'
#define DVBAPI_OPT 'o'
#define SYSLOG_OPT 'g'
#define RTSPPORT_OPT 'y'
#define SATIPCLIENT_OPT 's'
#define NETCVCLIENT_OPT 'n'
#define PRIORITY_OPT 'i'
#define SATIP_TCP_OPT 'O'
#define DOCUMENTROOT_OPT 'R'
#define XML_OPT 'X'
#define THREADS_OPT 'T'
#define DMXSOURCE_OPT '9'
#define LNB_OPT 'L'
#define DROP_ENCRYPTED_OPT 'E'
#define UDPPORT_OPT 'P'
#define NOPM_OPT 'Z'
char *built_info[] =
{
#ifdef DISABLE_DVBCSA
"Built without dvbcsa",
#else
"Built with dvbcsa",
#endif
#ifdef DISABLE_DVBCA
"Built without CI",
#else
"Built with CI",
#endif
#ifdef DISABLE_DVBAPI
"Built without dvbapi",
#else
"Built with dvbapi",
#endif
#ifdef DISABLE_DVBAES
"Built without AES (OpenSSL)",
#else
"Built with AES (OpenSSL)",
#endif
#ifdef DISABLE_TABLES
"Built without tables processing",
#else
"Built with tables processing",
#endif
#ifdef DISABLE_SATIPCLIENT
"Built without satip client",
#else
"Built with satip client",
#endif
#ifdef DISABLE_LINUXDVB
"Built without linux dvb client",
#else
"Built with linux dvb client",
#endif
#ifdef NO_BACKTRACE
"Built without backtrace",
#else
"Built with backtrace",
#endif
#ifdef DISABLE_NETCVCLIENT
"Built without netceiver",
#else
"Built with netceiver",
#endif
NULL };
void print_version(int use_log)
{
char buf[200];
int i, len = 0;
memset(buf, 0, sizeof(buf));
len += sprintf(buf, "%s version %s, compiled with s2api version: %04X",
app_name, version, LOGDVBAPIVERSION);
if (!use_log)
puts(buf);
else
LOGL(0, buf);
for (i = 0; built_info[i]; i++)
LOGL(0, "%s", built_info[i]);
}
void usage()
{
print_version(0);
printf(
"\n\t./%s [-[fgltzE]] [-a x:y:z] [-b X:Y] [-B X] [-d A:C-U ] [-D device_id] [-e X-Y,Z] [-i prio] \n\
\t[-[uj] A1:S1-F1[-PIN]] [-m mac] [-P port]"
#ifndef DISABLE_DVBAPI
"[-o oscam_host:dvbapi_port] "
#endif
"[-p public_host] [-r remote_rtp_host] \n\
\t[-R document_root] "
#ifndef DISABLE_SATIPCLIENT
"[-s [DELSYS:]host[:port] "
#endif
"[-u A1:S1-F1[-PIN]] [-L A1:low-high-switch] [-w http_server[:port]] \n\
\t[-x http_port] [-X xml_path] [-y rtsp_port] \n\n\
Help\n\
-------\n\
\n\
* -a x:y:z simulate x DVB-S2, y DVB-T2 and z DVB-C adapters on this box (0 means auto-detect)\n\
* eg: -a 1:2:3 \n\
- it will report 1 dvb-s2 device, 2 dvb-t2 devices and 3 dvb-c devices \n\
\n\
* -b --buffers X:Y : set the app adapter buffer to X Bytes (default: %d) and set the kernel DVB buffer to Y Bytes (default: %d) - both multiple of 188\n\
* eg: -b 18800:18988\n\
\n\
* -B X : set the app socket write buffer to X KB. \n\
The buffer will be split between multiple sockets, each getting maximum 0.4 * X KB\n\
* eg: -B 10\n\
\n\
* -d --diseqc ADAPTER1:COMMITTED1-UNCOMMITTED1[,ADAPTER2:COMMITTED2-UNCOMMITTED2[,...]\n\
\t* The first argument is the adapter number, second is the number of committed packets to send to a Diseqc 1.0 switch, third the number of uncommitted commands to sent to a Diseqc 1.1 switch\n\
\tThe higher number between the committed and uncommitted will be sent first.\n\
* eg: -d 0:1-0 (which is the default for each adapter).\n\
- note: * as adapter means apply to all adapters\n\
- note: * before committed number enables fast-switch (only voltage/tone)\n\
\n\
* -q --diseqc-timing ADAPTER1:BEFORE_CMD1-AFTER_CMD1-AFTER_REPEATED_CMD1-AFTER_SWITCH1-AFTER_BURST1-AFTER_TONE1[,...]\n\
\t* All timing values are in ms, default adapter values are: 15-54-15-15-15-0\n\
- note: * as adapter means apply to all adapters\n\
\n\
* -D --device-id DVC_ID: specify the device id (in case there are multiple SAT>IP servers in the network)\n \
* eg: -D 4 \n\
\n\
* -E Allow encrypted stream to be sent to the client even if the decrypting was unsuccessfull\n \
\n\
* -Y --delsys ADAPTER1:DELIVERY_SYSTEM1[,ADAPTER2:DELIVERY_SYSTEM2[,..]] - specify the delivery system of the adapters \n\
* eg: --delsys 1:dvbt,2:dvbs\n\
- specifies adapter 1 as a DVBT device, adapter 2 as DVB-S, which overrides the system detection of the adapter\n\
\n\
* --dmx-source ADAPTER1:FRONTENDX - specifies the frontend number specified as argument for DMX_SET_SOURCE \n\
* eg: --dmx-source 0:1 - enables DMX_SET_SOURCE ioctl call with parameter 1 for adapter 0\n\
\n\
* -e --enable-adapters list_of_enabled adapters: enable only specified adapters\n\
* eg: -e 0-2,5,7 (no spaces between parameters)\n\
- keep in mind that the first adapters are the local ones starting with 0 after that are the satip adapters \n\
if you have 3 local dvb cards 0-2 will be the local adapters, 3,4, ... will be the satip servers specified with argument -s\n\
\n\
* -f foreground, otherwise run in background\n\
\n\
* -g use syslog instead stdout for logging, multiple -g - print to stderr as well\n\
\n\
* -i --priority prio: set the DVR thread priority to prio \n\
\n\
* -l increases the verbosity (you can use multiple -l), logging to stdout in foreground mode or in /tmp/log when a daemon\n\
* eg: -l -l -l\n\
\n\
* -L --lnb specifies the adapter and LNB parameters (low, high and switch frequency)\n\
* eg: -L *:9750-10600-11700 - sets all the adapters to use Universal LNB parameters (default)\n\
* eg: -L *:10750-10750-10750 - sets the parameters for Sky NZ LNB using 10750 Mhz\n\
* eg: -L 0:10750-10750-10750,1:9750-10600-11700 - adapter 0 has a SKY NZ LNB, adapter 1 has an Universal LNB\n\
\n\
* -m xx: simulate xx as local mac address, generates UUID based on mac\n\
* eg: -m 001122334455 \n\
\n\
* -Z --nopm ADAPTER1,ADAPTER2-ADAPTER4[,..] - specify no power management for the adapters (does not turn power off) \n\
eg: --nopm 1-2\n\
- turns off power management for adapter 1 to 2 \n\
--nopm *\n\
- turns off power management for all adapters (recommended instead of --nopm 0-32) \n\
- required for some Unicable LNBs \n\
\n\
"
#ifndef DISABLE_NETCVCLIENT
"\
* -n --netceiver if:count: use network interface <if> (default vlan4) and look for <count> netceivers\n\
* eg: -n vlan4:2 \n\
\n\
"
#endif
#ifndef DISABLE_DVBAPI
"\
* -o --dvbapi host:port - specify the hostname and port for the dvbapi server (oscam). Port 9000 is set by default (if not specified) \n\
* eg: -o 192.168.9.9:9000 \n\
192.168.9.9 is the host where oscam is running and 9000 is the port configured in dvbapi section in oscam.conf.\n\
* eg: -o /tmp/camd.socket \n\
/tmp/camd.socket is the local socket that can be used \n\
\n\
"
#endif
"\
* -p url: specify playlist url using X_SATIPM3U header \n\
* eg: -p http://192.168.2.3:8080/playlist\n\
- this will add X_SATIPM3U tag into the satip description xml\n\
\n\
* -P port: use port number to listen for UDP socket in the RTP communication. port + 1000 will be used to listen by the sat>ip client (option -s)\n \
* eg: -P 5500 (default): will use for the sat>ip server 5500 + 2*A and 5500 + 2*A + 1, where A is the adapter number. \n\
6500 + 2*A and 6500 + 2*A + 1 - will be used by the sat>ip client\n \
\n\
* -r --remote-rtp remote_rtp_host: send the rtp stream to remote_rtp_host instead of the ip the connection comes from\n \
* eg: -r 192.168.7.9\n \
\n\
* -R --document-root directory: document root for the minisatip web page and images\n\
\n\
"
#ifndef DISABLE_SATIPCLIENT
"\
* -s --satip-servers DELSYS:host:port - specify the remote satip host and port with delivery system DELSYS, it is possible to use multiple -s \n\
* DELSYS - can be one of: dvbs, dvbs2, dvbt, dvbt2, dvbc, dvbc2, isdbt, atsc, dvbcb ( - DVBC_ANNEX_B ) [default: dvbs2]\n\
host - the server of the satip server\n\
port - rtsp port for the satip server [default: 554]\n\
eg: -s 192.168.1.2 -s dvbt:192.168.1.3:554 -s dvbc:192.168.1.4\n\
- specifies 1 dvbs2 (and dvbs)satip server with address 192.168.1.2:554\n\
- specifies 1 dvbt satip server with address 192.168.1.3:554\n\
- specifies 1 dvbc satip server with address 192.168.1.4:554\n\
\n\
* -O --satip-tcp Use RTSP over TCP instead of UDP for data transport \n\
"
#endif
"\
* -S --slave ADAPTER1,ADAPTER2-ADAPTER4[,..] - specify slave adapters \n\
* Allows specifying bonded adapters (multiple adapters connected with a splitter to the same LNB)\n\
Only one adapter needs to be master all others needs to have this parameter specified\n\
eg: -S 1-2\n\
- specifies adapter 1 to 2 as slave, in this case adapter 0 can be the master that controls the LNB\n\
- the slave adapter will not control the LNB polarity or band, but it will just change the internal frequency to tune to a different transponder\n\
- in this way the master will be responsible for changing the LNB polarity and band\n\
\n\
* -t --cleanpsi clean the PSI from all CA information, the client will see the channel as clear if decrypted successfully\n\
\n\
* -T --threads: enables/disable multiple threads (reduces memory consumptions) (default: %s)\n\
\n\
* -u --unicable unicable_string: defines the unicable adapters (A) and their slot (S), frequency (F) and optionally the PIN for the switch:\n\
\t* The format is: A1:S1-F1[-PIN][,A2:S2-F2[-PIN][,...]]\n\
eg: 2:0-1284[-1111]\n\
\t* When * character is used before frequency, force 13V only for setup\n\
\n\
* -j --jess jess_string - same format as -u \n\
\n\
* -w --http-host http_server[:port]: specify the host and the port (if not 80) where the xml file can be downloaded from [default: default_local_ip_address:8080] \n\
* eg: -w 192.168.1.1:8080 \n\
\n\
* -x --http-port port: port for listening on http [default: 8080]\n\
* eg: -x 9090 \n\
\n\
* -X --xml PATH: the path to the xml that is provided as part of the satip protocol \n\
* by default desc.xml is provided by minisatip without needing an additional file, \n\
however satip.xml is included if it needs to be customized\n\
\n\
* -y --rtsp-port rtsp_port: port for listening for rtsp requests [default: 554]\n\
* eg: -y 5544 \n\
- changing this to a port > 1024 removes the requirement for minisatip to run as root\n\
\n\
",
app_name,
ADAPTER_BUFFER,
DVR_BUFFER, opts.no_threads ? "DISABLED" : "ENABLED");
exit(1);
}
void set_options(int argc, char *argv[])
{
int opt;
char *lip;
opts.log = 1;
opts.rrtp = NULL;
opts.disc_host = "239.255.255.250";
opts.start_rtp = 5500;
opts.http_port = 8080;
opts.http_host = NULL;
opts.log = 0;
opts.timeout_sec = 30000;
opts.force_sadapter = 0;
opts.force_tadapter = 0;
opts.force_cadapter = 0;
opts.mac[0] = 0;
opts.daemon = 1;
opts.device_id = 0;
opts.bootid = 0;
opts.dvr_buffer = DVR_BUFFER;
opts.adapter_buffer = ADAPTER_BUFFER;
opts.file_line = 0;
opts.dvbapi_port = 0;
opts.dvbapi_host = NULL;
opts.drop_encrypted = 1;
opts.rtsp_port = 554;
opts.clean_psi = 0;
opts.satip_addpids = 1;
opts.satip_setup_pids = 0;
opts.satip_rtsp_over_tcp = 0;
opts.output_buffer = 512 * 1024;
opts.satip_servers[0] = 0;
opts.document_root = "html";
opts.xml_path = DESC_XML;
opts.no_threads = 0;
opts.th_priority = -1;
opts.diseqc_before_cmd = 15;
opts.diseqc_after_cmd = 54;
opts.diseqc_after_repeated_cmd = 15;
opts.diseqc_after_switch = 15;
opts.diseqc_after_burst = 15;
opts.diseqc_after_tone = 0;
opts.diseqc_committed_no = 1;
opts.nopm = 0;
opts.lnb_low = (9750*1000UL);
opts.lnb_high = (10600*1000UL);
opts.lnb_circular = (10750*1000UL);
opts.lnb_switch = (11700*1000UL);
opts.max_sinfo = 200;
opts.max_pids = 0;
#if defined(__sh__)
opts.max_pids = 20;
#endif
#ifdef NO_BACKTRACE
opts.no_threads = 1;
#endif
memset(opts.playlist, 0, sizeof(opts.playlist));
while ((opt = getopt_long(argc, argv,
"flr:a:td:w:p:s:n:hB:b:m:p:e:x:u:j:o:gy:i:q:D:VR:S:TX:Y:OL:EP:Z:",
long_options, NULL)) != -1)
{
// printf("options %d %c %s\n",opt,opt,optarg);
switch (opt)
{
case FOREGROUND_OPT:
{
opts.daemon = 0;
break;
}
case MAC_OPT:
{
strncpy(opts.mac, optarg, 12);
opts.mac[12] = 0;
break;
}
case RRTP_OPT:
{
opts.rrtp = optarg;
break;
}
case DEVICEID_OPT:
{
opts.device_id = atoi(optarg);
break;
}
case HTTPSERVER_OPT:
{
// int i=0;
opts.http_host = optarg;
break;
}
case LOG_OPT:
{
opts.log++;
break;
}
case SYSLOG_OPT:
{
opts.slog++;
break;
}
case HELP_OPT:
{
usage();
exit(0);
}
case HTTPPORT_OPT:
{
opts.http_port = atoi(optarg);
break;
}
case UDPPORT_OPT:
{
opts.start_rtp = atoi(optarg);
break;
}
case DVRBUFFER_OPT:
{
sscanf(optarg, "%d:%d", &opts.adapter_buffer, &opts.dvr_buffer);
opts.adapter_buffer = (opts.adapter_buffer / 188) * 188;
if (opts.adapter_buffer < ADAPTER_BUFFER)
opts.adapter_buffer = ADAPTER_BUFFER;
if (opts.dvr_buffer == 0)
opts.dvr_buffer = DVR_BUFFER;
break;
}
case APPBUFFER_OPT:
{
int val = atoi(optarg) / 1.5;
if(val > opts.max_sinfo)
opts.max_sinfo = val;
break;
}
case DVBS2_ADAPTERS_OPT:
{
sscanf(optarg, "%d:%d:%d", &opts.force_sadapter,
&opts.force_tadapter, &opts.force_cadapter);
break;
}
case CLEANPSI_OPT:
{
opts.clean_psi = 1;
break;
}
case PLAYLIST_OPT:
{
snprintf(opts.playlist, sizeof(opts.playlist),
"<satip:X_SATIPM3U xmlns:satip=\"urn:ses-com:satip\">%s</satip:X_SATIPM3U>\r\n",
optarg);
break;
}
case ENABLE_ADAPTERS_OPT:
{
enable_adapters(optarg);
break;
}
case DMXSOURCE_OPT:
{
set_adapter_dmxsource(optarg);
break;
}
case UNICABLE_OPT:
{
set_unicable_adapters(optarg, SWITCH_UNICABLE);
break;
}
case JESS_OPT:
{
set_unicable_adapters(optarg, SWITCH_JESS);
break;
}
case DISEQC_OPT:
{
set_diseqc_adapters(optarg);
break;
}
case DISEQC_TIMING_OPT:
{
set_diseqc_timing(optarg);
break;
}
case LNB_OPT:
{
set_lnb_adapters(optarg);
break;
}
case SLAVE_OPT:
{
set_slave_adapters(optarg);
break;
}
case NOPM_OPT:
{
set_nopm_adapters(optarg);
break;
}
case DELSYS_OPT:
{
set_adapters_delsys(optarg);
break;
}
case DVBAPI_OPT:
{
#ifdef DISABLE_DVBAPI
LOGL(0, "%s was not compiled with DVBAPI support, please install libdvbcsa (libdvbcsa-dev in Ubuntu) and change the Makefile", app_name);
exit (0);
#else
char* sep1 = strchr(optarg, ':');
if (sep1 != NULL)
{
*sep1 = 0;
opts.dvbapi_host = optarg;
opts.dvbapi_port = map_int(sep1 + 1, NULL);
}
else
{
opts.dvbapi_host = optarg;
opts.dvbapi_port = 9000;
}
#endif
break;
}
case RTSPPORT_OPT:
{
opts.rtsp_port = atoi(optarg);
break;
}
case SATIPCLIENT_OPT:
#ifdef DISABLE_SATIPCLIENT
LOGL(0, "%s was not compiled with satip client support, please change the Makefile", app_name);
exit (0);
#endif
if (strlen(optarg) + strlen(opts.satip_servers)
> sizeof(opts.satip_servers))
break;
if (opts.satip_servers[0])
sprintf(opts.satip_servers + strlen(opts.satip_servers), ",%s",
optarg);
else
sprintf(opts.satip_servers, "%s", optarg);
break;
case SATIP_TCP_OPT:
#ifdef DISABLE_SATIPCLIENT
LOGL(0, "%s was not compiled with satip client support, please change the Makefile", app_name);
exit (0);
#endif
opts.satip_rtsp_over_tcp = 1;
break;
case NETCVCLIENT_OPT:
{
#ifdef DISABLE_NETCVCLIENT
LOGL(0, "%s was not compiled with netceiver client support, please change the Makefile", app_name);
exit (0);
#else
// parse network interface name and number of netceivers
char* sep1 = strchr(optarg, ':');
if (sep1 != NULL)
{
*sep1 = 0;
opts.netcv_if = optarg;
opts.netcv_count = map_int(sep1 + 1, NULL);
break;
}
// default interface is vlan4 as it is used on the REEL
opts.netcv_if = "vlan4";
opts.netcv_count = map_int(optarg, NULL);
#endif
break;
}
case PRIORITY_OPT:
opts.th_priority = map_int(optarg, NULL);
break;
case DOCUMENTROOT_OPT:
opts.document_root = optarg;
break;
case THREADS_OPT:
opts.no_threads = 1 - opts.no_threads;
break;
case DROP_ENCRYPTED_OPT:
opts.drop_encrypted = 1 - opts.drop_encrypted;
break;
case XML_OPT:
while (*optarg > 0 && *optarg == '/')
optarg++;
if (*optarg > 0)
opts.xml_path = optarg;
else
LOGL(0, "Not a valid path for the xml file")
;
break;
}
}
lip = getlocalip();
if (!opts.http_host)
{
opts.http_host = (char *) malloc(MAX_HOST);
sprintf(opts.http_host, "%s:%d", lip, opts.http_port);
}
}
#define RBUF 4000
int read_rtsp(sockets * s)
{
char *arg[50];
int cseq, la, i, rlen;
char *transport = NULL, *useragent = NULL;
int sess_id = 0;
char buf[2000];
char tmp_ra[50];
streams *sid = get_sid(s->sid);
if (s->buf[0] == 0x24 && s->buf[1] < 2)
{
if (sid)
sid->rtime = s->rtime;
int rtsp_len = s->buf[2] * 256 + s->buf[3];
LOG(
"Received RTSP over tcp packet (sock_id %d, stream %d, rlen %d) packet len: %d, type %02X %02X discarding %s...",
s->id, s->sid, s->rlen, rtsp_len, s->buf[4], s->buf[5],
(s->rlen == rtsp_len + 4) ? "complete" : "fragment");
if (s->rlen == rtsp_len + 4)
{ // we did not receive the entire packet
s->rlen = 0;
return 0;
}
}
if (s->rlen < 4 || !end_of_header(s->buf + s->rlen - 4))
{
if (s->rlen > RBUF - 10)
{
LOG(
"Discarding %d bytes from the socket buffer, request > %d, consider increasing RBUF",
s->rlen, RBUF);
s->rlen = 0;
}
LOG(
"read_rtsp: read %d bytes from handle %d, sock_id %d, flags %d not ending with \\r\\n\\r\\n",
s->rlen, s->sock, s->id, s->flags);
if (s->flags & 1)
return 0;
unsigned char *new_alloc = malloc1(RBUF);
memcpy(new_alloc, s->buf, s->rlen);
s->buf = new_alloc;
s->flags = s->flags | 1;
return 0;
}
rlen = s->rlen;
s->rlen = 0;
LOG("read RTSP (from handle %d sock_id %d, len: %d, sid %d):", s->sock,
s->id, s->rlen, s->sid);
LOGL(3, "%s", s->buf);
if ((s->type != TYPE_HTTP)
&& (strncasecmp((const char*) s->buf, "GET", 3) == 0))
{
http_response(s, 404, NULL, NULL, 0, 0);
return 0;
}
la = split(arg, (char*) s->buf, 50, ' ');
cseq = 0;
if (la < 2)
LOG_AND_RETURN(0,
"Most likely not an RTSP packet sock_id: %d sid: %d rlen: %d, dropping ....",
s->id, s->sid, rlen);
if (s->sid < 0)
for (i = 0; i < la; i++)
if (strncasecmp("Session:", arg[i], 8) == 0)
{
sess_id = map_int(header_parameter(arg, i), NULL);
s->sid = find_session_id(sess_id);
}
if (strstr(arg[1], "freq") || strstr(arg[1], "pids"))
{
sid = (streams *) setup_stream(arg[1], s);
}
//setup empty stream, removing this breaks satip tests
if (!get_sid(s->sid)
&& ((strncasecmp(arg[0], "PLAY", 4) == 0)
|| (strncasecmp(arg[0], "GET", 3) == 0)
|| (strncasecmp(arg[0], "SETUP", 5) == 0)))
sid = (streams *) setup_stream(arg[1], s);
sid = get_sid(s->sid);
if (sid)
sid->rtime = s->rtime;
if (sess_id)
set_session_id(s->sid, sess_id);
for (i = 0; i < la; i++)
if (strncasecmp("CSeq:", arg[i], 5) == 0)
cseq = map_int(header_parameter(arg, i), NULL);
else if (strncasecmp("Transport:", arg[i], 9) == 0)
{
transport = header_parameter(arg, i);
if (-1 == decode_transport(s, transport, opts.rrtp, opts.start_rtp))
{
http_response(s, 400, NULL, NULL, cseq, 0);
return 0;
}
}
else if (strstr(arg[i], "LIVE555"))
{
if (sid)
sid->timeout = 0;
}
else if (strstr(arg[i], "Lavf"))
{
if (sid)
sid->timeout = 0;
}
else if (strncasecmp("User-Agent:", arg[i], 10) == 0)
useragent = header_parameter(arg, i);
else if (!useragent && strncasecmp("Server:", arg[i], 10) == 0)
useragent = header_parameter(arg, i);
if ((strncasecmp(arg[0], "PLAY", 4) == 0)
|| (strncasecmp(arg[0], "GET", 3) == 0)
|| (strncasecmp(arg[0], "SETUP", 5) == 0))
{
char ra[100];
int rv;
if (!(sid = get_sid(s->sid)))
{
http_response(s, 454, NULL, NULL, cseq, 0);
return 0;
}
if (useragent)
strncpy(sid->useragent, useragent, sizeof(sid->useragent) - 1);
if ((strncasecmp(arg[0], "PLAY", 3) == 0)
|| (strncasecmp(arg[0], "GET", 3) == 0))
if ((rv = start_play(sid, s)) < 0)
{
http_response(s, -rv, NULL, NULL, cseq, 0);
return 0;
}
buf[0] = 0;
if (transport)
{
int s_timeout;
if (sid->timeout == 1)
sid->timeout = opts.timeout_sec;
s_timeout = (
(sid->timeout > 20000) ? sid->timeout : opts.timeout_sec)
/ 1000;
get_stream_rhost(sid->sid, ra, sizeof(ra));
switch (sid->type)
{
case STREAM_RTSP_UDP:
if (atoi(ra) < 224)
snprintf(buf, sizeof(buf),
"Transport: RTP/AVP;unicast;destination=%s;source=%s;client_port=%d-%d;server_port=%d-%d\r\nSession: %010d;timeout=%d\r\ncom.ses.streamID: %d",
ra, get_sock_shost(s->sock),
get_stream_rport(sid->sid),
get_stream_rport(sid->sid) + 1,
// opts.start_rtp, opts.start_rtp + 1,
get_sock_sport(sid->rsock),
get_sock_sport(sid->rtcp), get_session_id(s->sid),
s_timeout, sid->sid + 1);
else
snprintf(buf, sizeof(buf),
"Transport: RTP/AVP;multicast;destination=%s;port=%d-%d\r\nSession: %010d;timeout=%d\r\ncom.ses.streamID: %d",
ra, get_stream_rport(sid->sid),
ntohs (sid->sa.sin_port) + 1,
get_session_id(s->sid), s_timeout, sid->sid + 1);
break;
case STREAM_RTSP_TCP:
snprintf(buf, sizeof(buf),
"Transport: RTP/AVP/TCP;interleaved=0-1\r\nSession: %010d;timeout=%d\r\ncom.ses.streamID: %d",
get_session_id(s->sid), s_timeout, sid->sid + 1);
break;
}
}
if (strncasecmp(arg[0], "PLAY", 4) == 0)
{
char *qm = strchr(arg[1], '?');
if (qm)
*qm = 0;
if (buf[0])
strcat(buf, "\r\n");
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf) - 1,
"RTP-Info: url=%s;seq=%jd;rtptime=%jd\r\nRange: npt=0.000-",
arg[1], getTick(), (getTickUs() / 1000000));
}
if (buf[0] == 0 && sid->type == STREAM_HTTP)
snprintf(buf, sizeof(buf), "Content-Type: video/mp2t");
http_response(s, 200, buf, NULL, cseq, 0);
}
else if (strncmp(arg[0], "TEARDOWN", 8) == 0)
{
buf[0] = 0;
if (get_sid(s->sid))
sprintf(buf, "Session: %010d", get_session_id(s->sid));
close_stream(s->sid);
http_response(s, 200, buf, NULL, cseq, 0);
}
else
{
if (strncmp(arg[0], "DESCRIBE", 8) == 0)
{
char sbuf[1000];
char *rv = NULL;
rv = describe_streams(s, arg[1], sbuf, sizeof(sbuf));
if (!rv)
{
http_response(s, 404, NULL, NULL, cseq, 0);
return 0;
}
snprintf(buf, sizeof(buf),
"Content-type: application/sdp\r\nContent-Base: rtsp://%s/",
get_sock_shost(s->sock));
http_response(s, 200, buf, sbuf, cseq, 0);
}
else if (strncmp(arg[0], "OPTIONS", 8) == 0)
{
// if(!get_sid(s->sid))
// http_response(s, 454, public, NULL, cseq, 0);
// else
http_response(s, 200, public, NULL, cseq, 0);
}
}
return 0;
}
#define REPLY_AND_RETURN(c) {http_response (s, c, NULL, NULL, 0, 0);return 0;}
char uuid[100];
int uuidi;
struct sockaddr_in ssdp_sa;
int read_http(sockets * s)
{
char *arg[50];
char buf[2000]; // the XML should not be larger than 1400 as it will create problems
char url[300];
char *space;
int is_head = 0;
static char *xml =
"<?xml version=\"1.0\"?>"
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\" configId=\"0\">"
"<specVersion><major>1</major><minor>1</minor></specVersion>"
"<device><deviceType>urn:ses-com:device:SatIPServer:1</deviceType>"
"<friendlyName>%s</friendlyName><manufacturer>cata</manufacturer>"
"<manufacturerURL>http://github.com/catalinii/minisatip</manufacturerURL>"
"<modelDescription>%s for Linux</modelDescription><modelName>%s</modelName>"
"<modelNumber>1.1</modelNumber><modelURL></modelURL><serialNumber>1</serialNumber><UDN>uuid:%s</UDN>"
"<iconList>"
"<icon><mimetype>image/png</mimetype><width>48</width><height>48</height><depth>24</depth><url>/sm.png</url></icon>"
"<icon><mimetype>image/png</mimetype><width>120</width><height>120</height><depth>24</depth><url>/lr.png</url></icon>"
"<icon><mimetype>image/jpeg</mimetype><width>48</width><height>48</height><depth>24</depth><url>/sm.jpg</url></icon>"
"<icon><mimetype>image/jpeg</mimetype><width>120</width><height>120</height><depth>24</depth><url>/lr.jpg</url></icon>"
"</iconList>"
"<presentationURL>http://%s/</presentationURL>\r\n"
"<satip:X_SATIPCAP xmlns:satip=\"urn:ses-com:satip\">%s</satip:X_SATIPCAP>"
"%s"
"</device></root>";
if (s->rlen < 5 || !end_of_header(s->buf + s->rlen - 4))
{
if (s->rlen > RBUF - 10)
{
LOG(
"Discarding %d bytes from the socket buffer, request > %d, consider increasing RBUF",
s->rlen, RBUF);
s->rlen = 0;
}
if (s->flags & 1)
return 0;
unsigned char *new_alloc = malloc1(RBUF);
memcpy(new_alloc, s->buf, s->rlen);
set_socket_buffer(s->id, new_alloc, RBUF);
s->flags = s->flags | 1;