satip-axe/patches/minisatip-axe.patch

782 lines
22 KiB
Diff

diff --git a/adapter.c b/adapter.c
index 285faea..fe3ce54 100755
--- a/adapter.c
+++ b/adapter.c
@@ -29,10 +29,15 @@
#include <linux/dvb/dmx.h>
#include <poll.h>
#include <linux/ioctl.h>
+#include <errno.h>
#include "socketworks.h"
#include "dvb.h"
#include "adapter.h"
+#ifdef AXE
+#define AXE_MAIN 1
+#include "axe.h"
+#endif
adapter a[MAX_ADAPTERS];
extern struct struct_opts opts;
@@ -49,7 +54,12 @@ find_adapters ()
for (i = 0; i < 8; i++)
for (j = 0; j < 8; j++)
{
+#ifdef AXE
+ if (j > 0) continue;
+ sprintf (buf, "/dev/axe/frontend-%d", i);
+#else
sprintf (buf, "/dev/dvb/adapter%d/frontend%d", i, j);
+#endif
fd = open (buf, O_RDONLY | O_NONBLOCK);
//LOG("testing device %s -> fd: %d",buf,fd);
if (fd >= 0)
@@ -61,6 +71,17 @@ find_adapters ()
if (na == MAX_ADAPTERS)
return;
}
+#ifdef AXE
+ if (i == 0)
+ axe_set_network_led(0);
+ if (i < 4)
+ axe_set_tuner_led(i + 1, 0);
+ if (i < 4 && fd < 0) {
+ LOGL(0, "AXE - cannot open %s: %i", buf, errno);
+ sleep(60);
+ exit(239);
+ }
+#endif
}
for (na; na < MAX_ADAPTERS; na++)
a[na].pa = a[na].fn = -1;
@@ -122,9 +143,18 @@ init_hw ()
find_adapters ();
LOG ("trying to open [%d] adapter %d and frontend %d", i, a[i].pa,
a[i].fn);
+#ifdef AXE
+ sprintf (buf, "/dev/axe/frontend-%d", a[i].pa);
+#else
sprintf (buf, "/dev/dvb/adapter%d/frontend%d", a[i].pa, a[i].fn);
+#endif
a[i].fe = open (buf, O_RDWR | O_NONBLOCK);
+
+#ifdef AXE
+ sprintf (buf, "/dev/axe/demuxts-%d", a[i].pa);
+#else
sprintf (buf, "/dev/dvb/adapter%d/dvr%d", a[i].pa, a[i].fn);
+#endif
a[i].dvr = open (buf, O_RDONLY | O_NONBLOCK);
if (a[i].fe < 0 || a[i].dvr < 0)
{
@@ -151,10 +181,12 @@ init_hw ()
num_adapters++;
LOG ("opened DVB adapter %d fe:%d dvr:%d", i, a[i].fe, a[i].dvr);
+#ifndef AXE
if (ioctl (a[i].dvr, DMX_SET_BUFFER_SIZE, opts.dvr) < 0)
perror ("couldn't set DVR buffer size");
else
LOG ("Done setting DVR buffer to %d bytes", DVR_BUFFER);
+#endif
init_dvb_parameters (&a[i].tp);
mark_pids_deleted (i, -1, NULL);
update_pids (i);
@@ -194,6 +226,24 @@ close_adapter (int na)
mark_pids_deleted (na, -1, NULL);
update_pids (na);
// if(a[na].dmx>0)close(a[na].dmx);
+#ifdef AXE
+ if (a[na].fe > 0) {
+ int i;
+ axe_fe_reset(a[na].fe);
+ for (i = 0; i < 4; i++)
+ if (i != na && a[i].sid_cnt > 0) break;
+ if (i >= 4) {
+ LOG("AXE standby");
+ for (i = 0; i < 4; i++) {
+ axe_fe_standby(a[i].fe, -1);
+ ioctl(a[i].fe, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF);
+ a[i].tp.old_diseqc = a[i].tp.old_pol = a[i].tp.old_hiband = -1;
+ }
+ } else {
+ LOG("AXE standby: adapter %d busy (%d), keeping", i, a[i].sid_cnt);
+ }
+ }
+#endif
if (a[na].fe > 0)
close (a[na].fe);
if (a[na].sock >= 0)
@@ -366,8 +416,8 @@ close_adapter_for_stream (int sid, int aid)
// delete the attached PIDs as well
mark_pids_deleted (aid, sid, NULL);
update_pids (aid);
-// if (a[aid].sid_cnt == 0)
-// close_adapter (aid);
+ if (a[aid].sid_cnt == 0)
+ close_adapter (aid);
}
@@ -410,7 +460,7 @@ update_pids (int aid)
int tune (int aid, int sid)
{
adapter *ad = get_adapter(aid);
- int i, rv = 0;
+ int rv = 0;
if(!ad) return -400;
ad->last_sort = getTick ();
@@ -419,7 +469,10 @@ int tune (int aid, int sid)
ad->tp.switch_type = ad->switch_type;
ad->tp.uslot = ad->uslot;
ad->tp.ufreq = ad->ufreq;
-
+
+#ifdef AXE
+ axe_set_tuner_led(aid + 1, 1);
+#endif
rv = tune_it_s2 (ad->fe, &ad->tp);
a[aid].status = 0;
a[aid].status_cnt = 0;
@@ -428,6 +481,10 @@ int tune (int aid, int sid)
close_streams_for_adapter (aid, sid);
update_pids (aid);
}
+#ifdef AXE
+ if (rv < 0)
+ axe_set_tuner_led(aid + 1, 0);
+#endif
}
else
LOG ("not tuning for SID %d (do_tune=%d, master_sid=%d)", sid,
@@ -684,7 +741,11 @@ describe_adapter (int sid, int aid)
memset (dad, 0, sizeof (dad));
x = 0;
// do just max 3 signal check 1s after tune
+#ifndef AXE
if (use_ad && ((ad->status <= 0 && ad->status_cnt<8 && ad->status_cnt++>4) || opts.force_scan))
+#else
+ if (use_ad && (ad->status_cnt++ & 3) == 0)
+#endif
{
int new_gs = 1;
ts = getTick ();
@@ -701,11 +762,20 @@ describe_adapter (int sid, int aid)
if (ad->max_snr <= ad->snr) ad->max_snr = (ad->snr>0)?ad->snr:1;
LOG ("get_signal%s took %d ms for adapter %d handle %d (status: %d, ber: %d, strength:%d, snr: %d, max_strength: %d, max_snr: %d %d)",
new_gs?"":"_new", getTick () - ts, aid, ad->fe, ad->status, ad->ber, ad->strength, ad->snr, ad->max_strength, ad->max_snr, opts.force_scan);
+#ifndef AXE
if(new_gs)
{
ad->strength = ad->strength * 255 / ad->max_strength;
ad->snr = ad->snr * 15 / ad->max_snr;
}
+#else
+ ad->strength = ad->strength * 240 / 24000;
+ if (ad->strength > 240)
+ ad->strength = 240;
+ ad->snr = ad->snr * 15 / 54000;
+ if (ad->snr > 15)
+ ad->snr = 15;
+#endif
}
if(use_ad)
{
@@ -715,14 +785,14 @@ describe_adapter (int sid, int aid)
}
if (t->sys == SYS_DVBS || t->sys == SYS_DVBS2)
sprintf (dad, "ver=1.0;src=%d;tuner=%d,%d,%d,%d,%d,%s,%s,%s,%s,%s,%d,%s;pids=",
- t->diseqc, aid, strength, status, snr, t->freq / 1000, get_pol(t->pol), get_modulation(t->mtype),
+ t->diseqc, aid+1, strength, status, snr, t->freq / 1000, get_pol(t->pol), get_modulation(t->mtype),
get_pilot(t->plts), get_rolloff(t->ro), get_delsys(t->sys), t->sr / 1000, get_fec(t->fec));
else if (t->sys == SYS_DVBT || t->sys == SYS_DVBT2)
sprintf (dad, "ver=1.1;src=%d;tuner=%d,%d,%d,%d,%.2f,%d,%s,%s,%s,%s,%s,%d,%d,%d;pids=",
- t->diseqc, aid, strength, status, snr, (double) t->freq/1000, t->bw, get_delsys(t->sys), get_tmode(t->tmode), get_modulation(t->mtype), get_gi(t->gi),
+ t->diseqc, aid+1, strength, status, snr, (double) t->freq/1000, t->bw, get_delsys(t->sys), get_tmode(t->tmode), get_modulation(t->mtype), get_gi(t->gi),
get_fec(t->fec), t->plp, t->t2id, t->sm);
else sprintf (dad, "ver=1.2;src=%d;tuner=%d,%d,%d,%d,%.2f,8,%s,%s,%d,%d,%d,%d,%d;pids=",
- t->diseqc, aid, strength, status, snr, (double )t->freq/1000, get_delsys(t->sys), get_modulation(t->mtype), t->sr,
+ t->diseqc, aid+1, strength, status, snr, (double )t->freq/1000, get_delsys(t->sys), get_modulation(t->mtype), t->sr,
t->c2tft, t->ds, t->plp, t->inversion);
for (i = 0; i < MAX_PIDS; i++)
if (use_ad && ad->pids[i].flags == 1)
diff --git a/adapter.h b/adapter.h
index 629bd9c..caa1019 100755
--- a/adapter.h
+++ b/adapter.h
@@ -7,7 +7,7 @@
#define MAX_ADAPTERS 8
#define DVR_BUFFER 30*1024*188
#define MAX_STREAMS_PER_PID 8
-#define ADAPTER_BUFFER 7*7*DVB_FRAME
+#define ADAPTER_BUFFER 70*7*DVB_FRAME
typedef struct struct_pid
{
int pid; // pid for this demux - not used
diff --git a/axe.h b/axe.h
new file mode 100644
index 0000000..4c62d86
--- /dev/null
+++ b/axe.h
@@ -0,0 +1,113 @@
+#ifndef __AXE_H
+#define __AXE_H
+
+#include <linux/dvb/dmx.h>
+#include <linux/dvb/frontend.h>
+
+typedef struct fe_frontend_status fe_frontend_status_t;
+
+struct fe_frontend_status {
+ __u32 val0;
+ __u32 val1;
+ __u32 val2;
+ __u32 modulation;
+ __u32 val4;
+ __u32 frequency;
+ __u32 val6;
+ __u32 val7;
+ __u32 symbol_rate;
+ __u32 val9;
+ __u32 fec;
+ __u32 rolloff;
+ __u32 val12;
+ __u32 val13;
+} __attribute__ ((packed));
+
+#define FE_FRONTEND_STANDBY _IOW('o', 91, __u32)
+#define FE_FRONTEND_RESET _IO('o', 93)
+#define FE_FRONTEND_STATUS _IOR('o', 96, fe_frontend_status_t)
+#define FE_FRONTEND_INPUT _IOW('o', 97, __u8)
+
+static inline int axe_fe_standby(int fd, __u32 stdby)
+{
+ return ioctl(fd, FE_FRONTEND_STANDBY, &stdby);
+}
+
+static inline int axe_fe_reset(int fd)
+{
+ return ioctl(fd, FE_FRONTEND_RESET, 0x54);
+}
+
+static inline int axe_fe_input(int fd, __u8 in)
+{
+ return ioctl(fd, FE_FRONTEND_INPUT, &in);
+}
+
+#define DMXTS_ADD_PID _IOW('o', 1, __u16)
+#define DMXTS_REMOVE_PID _IOW('o', 2, __u16)
+
+static inline int axe_dmxts_add_pid(int fd, __u16 pid)
+{
+ return ioctl(fd, DMXTS_ADD_PID, &pid);
+}
+
+static inline int axe_dmxts_remove_pid(int fd, __u16 pid)
+{
+ return ioctl(fd, DMXTS_REMOVE_PID, &pid);
+}
+
+#ifdef AXE_MAIN
+
+int axe_fp_fd = -1;
+
+static inline axe_fp_fd_open(void)
+{
+ if (axe_fp_fd < 0)
+ axe_fp_fd = open("/dev/axe/fp-0", O_WRONLY);
+}
+
+static inline axe_fp_fd_write(const char *s)
+{
+ const char *b;
+ size_t len;
+ ssize_t r;
+
+ axe_fp_fd_open();
+ len = strlen(b = s);
+ while (len > 0) {
+ r = write(axe_fp_fd, b, len);
+ if (r > 0) {
+ len -= r;
+ b += r;
+ }
+ }
+}
+
+void axe_set_tuner_led(int tuner, int on)
+{
+ static int state = -1;
+ char buf[16];
+ if (state != on) {
+ sprintf(buf, "T%d_LED %d\n", tuner, on ? 1 : 0);
+ axe_fp_fd_write(buf);
+ state = on;
+ }
+}
+
+void axe_set_network_led(int on)
+{
+ static int state = -1;
+ if (state != on) {
+ axe_fp_fd_write(on ? "NET_LED 1\n" : "NET_LED 0\n");
+ state = on;
+ }
+}
+
+#else
+
+void axe_set_tuner_led(int tuner, int on);
+void axe_set_network_led(int on);
+
+#endif
+
+#endif
diff --git a/dvb.c b/dvb.c
index 5701bd2..7e1686d 100755
--- a/dvb.c
+++ b/dvb.c
@@ -41,6 +41,10 @@
#include <ctype.h>
#include "dvb.h"
#include "minisatip.h"
+#ifdef AXE
+#include "axe.h"
+#include "adapter.h"
+#endif
extern struct struct_opts opts;
@@ -215,6 +219,29 @@ msleep (uint32_t msec)
;
}
+#ifdef AXE
+void axe_wakeup(int voltage)
+{
+ int i;
+ adapter *a;
+ for (i = 0; i < 4; i++) {
+ a = get_adapter(i);
+ if (a == NULL || a->force_disable)
+ continue;
+ if (a->tp.old_pol >= 0)
+ return;
+ }
+ LOG("AXE wakeup");
+ for (i = 0; i < 4; i++) {
+ a = get_adapter(i);
+ if (a == NULL || a->force_disable)
+ continue;
+ if (ioctl(a->fe, FE_SET_VOLTAGE, voltage) == -1)
+ LOG("axe_wakeup: FE_SET_VOLTAGE failed fd %d: %s", a->fe, strerror(errno));
+ }
+}
+#endif
+
int send_diseqc(int fd, int pos, int pol, int hiband)
{
struct dvb_diseqc_master_cmd cmd = {
@@ -229,6 +256,9 @@ int send_diseqc(int fd, int pos, int pol, int hiband)
if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
LOG("send_diseqc: FE_SET_TONE failed for fd %d: %s", fd, strerror(errno));
+#ifdef AXE
+ axe_wakeup(pol ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13);
+#endif
if (ioctl(fd, FE_SET_VOLTAGE, pol ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13) == -1)
LOG("send_diseqc: FE_SET_VOLTAGE failed for fd %d: %s", fd, strerror(errno));
@@ -262,6 +292,9 @@ int send_unicable(int fd, int freq, int pos, int pol, int hiband, int slot, int
LOGL(3, "send_unicable fd %d, freq %d, ufreq %d, pos = %d, pol = %d, hiband = %d, slot %d, diseqc => %02x %02x %02x %02x %02x",
fd, freq, ufreq, pos, pol, hiband, slot, cmd.msg[0], cmd.msg[1], cmd.msg[2], cmd.msg[3], cmd.msg[4]);
+#ifdef AXE
+ axe_wakeup(SEC_VOLTAGE_13);
+#endif
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) == -1)
LOG("send_unicable: pre voltage SEC_VOLTAGE_13 failed for fd %d: %s", fd, strerror(errno));
msleep(15);
@@ -295,6 +328,9 @@ int send_jess(int fd, int freq, int pos, int pol, int hiband, int slot, int ufre
LOGL(3, "send_jess fd %d, freq %d, ufreq %d, pos = %d, pol = %d, hiband = %d, slot %d, diseqc => %02x %02x %02x %02x %02x",
fd, freq, ufreq, pos, pol, hiband, slot, cmd.msg[0], cmd.msg[1], cmd.msg[2], cmd.msg[3], cmd.msg[4]);
+#ifdef AXE
+ axe_wakeup(SEC_VOLTAGE_13);
+#endif
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) == -1)
LOG("send_jess: pre voltage SEC_VOLTAGE_13 failed for fd %d: %s", fd, strerror(errno));
msleep(15);
@@ -332,10 +368,26 @@ int setup_switch (int frontend_fd, transponder *tp)
if(tp->switch_type == SWITCH_UNICABLE)
{
+#ifdef AXE
+ adapter *a = get_adapter(0);
+ if (a)
+ freq = send_unicable(a->fe, freq / 1000, diseqc, pol, hiband, tp->uslot, tp->ufreq);
+ else
+ LOGL(3, "axe unicable setup: unable to find adapter 0");
+#else
freq = send_unicable(frontend_fd, freq / 1000, diseqc, pol, hiband, tp->uslot, tp->ufreq);
+#endif
}else if(tp->switch_type == SWITCH_JESS)
{
+#ifdef AXE
+ adapter *a = get_adapter(0);
+ if (a)
+ freq = send_jess(a->fe, freq / 1000, diseqc, pol, hiband, tp->uslot, tp->ufreq);
+ else
+ LOGL(3, "axe jess setup: unable to find adapter 0");
+#else
freq = send_jess(frontend_fd, freq / 1000, diseqc, pol, hiband, tp->uslot, tp->ufreq);
+#endif
}else
{
if(tp->old_pol != pol || tp->old_hiband != hiband || tp->old_diseqc != diseqc)
@@ -343,6 +395,26 @@ int setup_switch (int frontend_fd, transponder *tp)
else
LOGL(3, "Skip sending diseqc commands since the switch position doesn't need to be changed: pol %d, hiband %d, switch position %d", pol, hiband, diseqc);
}
+#ifdef AXE
+ {
+ int aid = 0;
+ if (tp->switch_type != SWITCH_UNICABLE && tp->switch_type != SWITCH_JESS) {
+ for (aid = 0; aid < 4; aid++) {
+ adapter *a = get_adapter(aid);
+ LOGL(3, "axe adapter %i fe fd %d", aid, a->fe);
+ if (a && a->fe == frontend_fd)
+ break;
+ }
+ if (aid >= 4)
+ LOG("axe_fe: unknown adapter for fd %d", frontend_fd);
+ }
+ LOGL(3, "axe_fe: reset for fd %d adapter %d", frontend_fd, aid);
+ if (axe_fe_reset(frontend_fd) < 0)
+ LOG("axe_fe: RESET failed for fd %d: %s", frontend_fd, strerror(errno));
+ if (aid < 4 && axe_fe_input(frontend_fd, aid))
+ LOG("axe_fe: INPUT failed for fd %d: %s", frontend_fd, strerror(errno));
+ }
+#endif
tp->old_pol = pol;
tp->old_hiband = hiband;
@@ -383,8 +455,10 @@ tune_it_s2 (int fd_frontend, transponder * tp)
{.cmd = DTV_INVERSION,.u.data = 0},
{.cmd = DTV_SYMBOL_RATE,.u.data = 0},
{.cmd = DTV_INNER_FEC,.u.data = 0},
+#ifndef AXE
{.cmd = DTV_PILOT,.u.data = 0},
{.cmd = DTV_ROLLOFF,.u.data = 0},
+#endif
{.cmd = DTV_TUNE},
};
static struct dtv_properties dvbs2_cmdseq =
@@ -465,8 +539,10 @@ tune_it_s2 (int fd_frontend, transponder * tp)
p = &dvbs2_cmdseq;
p->props[DELSYS].u.data = tp->sys;
p->props[MODULATION].u.data = tp->mtype;
+#ifndef AXE
p->props[PILOT].u.data = tp->plts;
p->props[ROLLOFF].u.data = tp->ro;
+#endif
p->props[INVERSION].u.data = tp->inversion;
p->props[SYMBOL_RATE].u.data = tp->sr;
p->props[FEC_INNER].u.data = tp->fec;
@@ -475,7 +551,12 @@ tune_it_s2 (int fd_frontend, transponder * tp)
LOG("tuning to %d(%d) pol: %s (%d) sr:%d fec:%s delsys:%s mod:%s rolloff:%s pilot:%s, ts clear=%d, ts pol=%d",
tp->freq, p->props[FREQUENCY].u.data, get_pol(tp->pol), tp->pol, p->props[SYMBOL_RATE].u.data, fe_fec[p->props[FEC_INNER].u.data],
fe_delsys[p->props[DELSYS].u.data], fe_modulation[p->props[MODULATION].u.data],
- fe_rolloff[p->props[ROLLOFF].u.data], fe_pilot[p->props[PILOT].u.data], bclear, bpol);
+#ifdef AXE
+ "auto", "auto",
+#else
+ fe_rolloff[p->props[ROLLOFF].u.data], fe_pilot[p->props[PILOT].u.data],
+#endif
+ bclear, bpol);
break;
@@ -560,6 +641,20 @@ set_pid (int hw, int ad, uint16_t i_pid)
char buf[100];
int fd;
+#ifdef AXE
+ adapter *a = get_adapter(hw);
+
+ if ( i_pid > 8192 || a == NULL)
+ LOG_AND_RETURN(-1, "pid %d > 8192 for ADAPTER %d", i_pid, hw);
+
+ if (axe_dmxts_add_pid(a->dvr, i_pid) < 0)
+ {
+ LOG ("failed setting filter on %d (%s)", i_pid, strerror (errno));
+ return -1;
+ }
+ LOG ("setting filter on PID %d for ADAPTER %d", i_pid, a->pa);
+ return (hw << 16) | i_pid;
+#else
if ( i_pid > 8192 )
LOG_AND_RETURN(-1, "pid %d > 8192 for /dev/dvb/adapter%d/demux%d", i_pid, hw, ad);
@@ -585,6 +680,7 @@ set_pid (int hw, int ad, uint16_t i_pid)
}
LOG ("setting filter on PID %d for fd %d", i_pid, fd);
+#endif
return fd;
}
@@ -592,6 +688,17 @@ set_pid (int hw, int ad, uint16_t i_pid)
int del_filters (int fd, int pid)
{
+#ifdef AXE
+ adapter *a = get_adapter(fd >> 16);
+ if (a == NULL)
+ return 0; /* closed */
+ if ((fd & 0xffff) != pid)
+ LOG_AND_RETURN(0, "AXE PID remove on an invalid handle %d, pid %d", fd, pid);
+ if (axe_dmxts_remove_pid(a->dvr, pid) < 0)
+ LOG ("AXE PID remove failed on PID %d ADAPTER %d: %s", pid, a->pa, strerror (errno))
+ else
+ LOG ("clearing filters on PID %d ADAPTER %d", pid, a->pa);
+#else
if (fd < 0)
LOG_AND_RETURN(0, "DMX_STOP on an invalid handle %d, pid %d", fd, pid);
if (ioctl (fd, DMX_STOP) < 0)
@@ -599,6 +706,7 @@ int del_filters (int fd, int pid)
else
LOG ("clearing filters on PID %d FD %d", pid, fd);
close (fd);
+#endif
return 0;
}
@@ -606,6 +714,15 @@ int del_filters (int fd, int pid)
fe_delivery_system_t
dvb_delsys (int aid, int fd, fe_delivery_system_t *sys)
{
+#ifdef AXE
+ int i;
+ LOG ("Delivery System DVB-S/DVB-S2 (AXE)");
+ for(i = 0 ; i < 10 ; i ++)
+ sys[i] = 0;
+ sys[0] = SYS_DVBS;
+ sys[1] = SYS_DVBS2;
+ return SYS_DVBS2;
+#else
int i, res, rv = 0;
struct dvb_frontend_info fe_info;
@@ -703,6 +820,7 @@ dvb_delsys (int aid, int fd, fe_delivery_system_t *sys)
LOG ("returning default from dvb_delsys => %s (count %d)", fe_delsys[rv] , nsys);
return (fe_delivery_system_t) rv;
+#endif
}
diff --git a/minisatip.c b/minisatip.c
index d4076ba..4cc82dc 100755
--- a/minisatip.c
+++ b/minisatip.c
@@ -36,6 +36,7 @@
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <syslog.h>
#include "socketworks.h"
#include "stream.h"
#include "adapter.h"
@@ -62,6 +63,7 @@ usage ()
-c X: bandwidth capping for the output to the network (default: unlimited)\n\
-b X: set the DVR buffer to X KB (default: %dKB)\n\
-l increases the verbosity (you can use multiple -l), logging to stdout in foreground mode or in /tmp/log when a daemon\n\
+ -g use syslog instead stdout for logging, multiple -g - print to stderr as well\n\
-p url: specify playlist url using X_SATIPM3U header \n\
-u unicable_string: defines the unicable adapters (A) and their slot (S) and frequency (F):\n\
\tThe format is: A1:S1-F1[,A2:S2-F2[,...]] \n\
@@ -101,7 +103,7 @@ set_options (int argc, char *argv[])
opts.file_line = 0;
memset(opts.playlist, sizeof(opts.playlist), 0);
- while ((opt = getopt (argc, argv, "flr:a:t:d:w:p:shc:b:m:p:e:x:u:j:")) != -1)
+ while ((opt = getopt (argc, argv, "flr:a:t:d:w:p:shc:b:m:p:e:x:u:j:g")) != -1)
{
// printf("options %d %c %s\n",opt,opt,optarg);
switch (opt)
@@ -143,6 +145,12 @@ set_options (int argc, char *argv[])
break;
}
+ case SYSLOG_OPT:
+ {
+ opts.slog++;
+ break;
+ }
+
case HELP_OPT:
{
usage ();
@@ -483,6 +491,11 @@ http_response (sockets *s, int rc, char *ah, char *desc, int cseq, int lr)
#define RBUF 4000
+static inline end_of_header(char *buf)
+{
+ return buf[0] == 0x0d && buf[1] == 0x0a && buf[2] == 0x0d && buf[3] == 0x0a;
+}
+
int
read_rtsp (sockets * s)
{
@@ -507,8 +520,7 @@ read_rtsp (sockets * s)
}
}
- if (s->rlen < 4
- || (htonl (*(uint32_t *) & s->buf[s->rlen - 4]) != 0x0D0A0D0A))
+ if (s->rlen < 4 || !end_of_header(s->buf + s->rlen - 4))
{
if( s->rlen > RBUF - 10 )
{
@@ -524,6 +536,9 @@ read_rtsp (sockets * s)
return 0;
}
+#ifdef AXE
+ axe_set_network_led(1);
+#endif
rlen = s->rlen;
s->rlen = 0;
@@ -726,8 +741,7 @@ read_http (sockets * s)
"%s"
"</device></root>";
- if (s->rlen < 5
- || (htonl (*(uint32_t *) & s->buf[s->rlen - 4]) != 0x0D0A0D0A))
+ if (s->rlen < 5 || !end_of_header(s->buf + s->rlen - 4))
{
if( s->rlen > RBUF - 10 )
{
@@ -749,6 +763,9 @@ read_http (sockets * s)
return 0;
}
+#ifdef AXE
+ axe_set_network_led(1);
+#endif
rlen = s->rlen;
s->rlen = 0;
@@ -904,6 +921,9 @@ ssdp_reply (sockets * s)
return 0;
}
+#ifdef AXE
+ axe_set_network_led(1);
+#endif
// not my uuid
LOG("Received SSDP packet from %s:%d -> handle %d", inet_ntoa(s->sa.sin_addr), ntohs(s->sa.sin_port), s->sock);
LOGL(3, "%s", s->buf);
@@ -987,7 +1007,13 @@ main (int argc, char *argv[])
set_options (argc, argv);
if (opts.daemon)
becomeDaemon ();
+ if (opts.slog)
+ openlog ("minisatip", LOG_NDELAY|LOG_NOWAIT|LOG_PID|(opts.slog>1?LOG_PERROR:0), LOG_DAEMON);
+#ifdef AXE
+ LOGL(0, "Starting minisatip version %s, compiled with AXE DVB API",VERSION);
+#else
LOGL(0, "Starting minisatip version %s, compiled with dvbapi version: %04X",VERSION, DVBAPIVERSION);
+#endif
readBootID();
if ((ssdp = udp_bind (NULL, 1900)) < 1)
FAIL ("SSDP: Could not bind on udp port 1900");
@@ -1021,7 +1047,9 @@ main (int argc, char *argv[])
select_and_execute ();
unlink(PID_FILE);
free_all ();
- return 0;
+ if (opts.slog)
+ closelog();
+ return 0;
}
@@ -1247,12 +1275,16 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
idx = 1;
else if ( idx < 0)
idx = 0;
- if(opts.file_line)
+ if(opts.file_line && !opts.slog)
len1 = snprintf(output[idx], sizeof(output[0]), "[%s] %s:%d: ", get_current_timestamp_log(), file, line);
- else
+ else if (!opts.slog)
len1 = snprintf(output[idx], sizeof(output[0]), "[%s]: ", get_current_timestamp_log());
+ else if (opts.file_line) {
+ len1 = 0;
+ output[idx][0] = '\0';
+ }
/* Write the error message */
- len = len1;
+ len = len1 = len1 < sizeof(output[0]) ? len1 : sizeof(output[0]) - 1;
both = 0;
va_start(arg, fmt);
len += vsnprintf(output[idx] + len, sizeof(output[0]) - len, fmt, arg);
@@ -1271,9 +1303,9 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
}
if(both){
- puts(output[1-idx]);
+ if(opts.slog)syslog(LOG_NOTICE, "%s", output[1-idx]); else puts(output[1-idx]);
both = 0;
}
- if(times==0)puts(output[idx]);
+ if(times==0) if(opts.slog)syslog(LOG_NOTICE, "%s", output[idx]); else puts(output[idx]);
fflush(stdout);
}
diff --git a/minisatip.h b/minisatip.h
index 821e756..4f4e6ac 100755
--- a/minisatip.h
+++ b/minisatip.h
@@ -30,6 +30,7 @@ void set_options (int argc, char *argv[]);
#define ENABLE_ADAPTERS_OPT 'e'
#define UNICABLE_OPT 'u'
#define JESS_OPT 'j'
+#define SYSLOG_OPT 'g'
#define PID_FILE "/var/run/minisatip.pid"
struct struct_opts
@@ -39,6 +40,7 @@ struct struct_opts
char *disc_host; //discover host
char mac[13];
unsigned int log,
+ slog,
start_rtp,
http_port;
int timeout_sec;
diff --git a/socketworks.c b/socketworks.c
index b4891f1..1857089 100755
--- a/socketworks.c
+++ b/socketworks.c
@@ -433,6 +433,17 @@ select_and_execute ()
ss->rtime = c_time;
if(rlen>0)
ss->rlen += rlen;
+#ifdef AXE
+ if (ss->type == TYPE_DVR) {
+ while (rlen > 0 && ss->lbuf - ss->rlen >= 1316) {
+ rlen = read (ss->sock, &ss->buf[ss->rlen], ss->lbuf - ss->rlen);
+ if (rlen > 0)
+ ss->rlen += rlen;
+ }
+ if (rlen == 0 || (rlen < 0 || errno == -EAGAIN))
+ rlen = 1;
+ }
+#endif
//force 0 at the end of the string
if(ss->lbuf >= ss->rlen)
ss->buf[ss->rlen] = 0;