diff options
author | Lars Heer <l.heer@gmx.de> | 2013-09-18 05:50:03 +0200 |
---|---|---|
committer | Lars Heer <l.heer@gmx.de> | 2013-09-18 05:50:03 +0200 |
commit | ccf6e0f9c6b0481ed13e0f4794e3fbead750f385 (patch) | |
tree | ed86efb54f7ee41edfba5c89ca519b5fd10aa0d5 /mcast/tool | |
download | vdr-plugin-mcli-ccf6e0f9c6b0481ed13e0f4794e3fbead750f385.tar.gz vdr-plugin-mcli-ccf6e0f9c6b0481ed13e0f4794e3fbead750f385.tar.bz2 |
added vdr-plugin-mcli-0.0.1+svn20120927
Diffstat (limited to 'mcast/tool')
-rw-r--r-- | mcast/tool/.svn/entries | 232 | ||||
-rw-r--r-- | mcast/tool/.svn/prop-base/mcast.c.svn-base | 5 | ||||
-rw-r--r-- | mcast/tool/.svn/prop-base/tools.c.svn-base | 5 | ||||
-rw-r--r-- | mcast/tool/.svn/text-base/Makefile.svn-base | 137 | ||||
-rw-r--r-- | mcast/tool/.svn/text-base/mcast.c.svn-base | 1 | ||||
-rw-r--r-- | mcast/tool/.svn/text-base/netcvdiag.c.svn-base | 433 | ||||
-rw-r--r-- | mcast/tool/.svn/text-base/netcvlogview.c.svn-base | 206 | ||||
-rw-r--r-- | mcast/tool/.svn/text-base/netcvupdate.c.svn-base | 773 | ||||
-rw-r--r-- | mcast/tool/.svn/text-base/tools.c.svn-base | 1 | ||||
-rw-r--r-- | mcast/tool/Makefile | 137 | ||||
l--------- | mcast/tool/mcast.c | 1 | ||||
-rw-r--r-- | mcast/tool/netcvdiag.c | 433 | ||||
-rw-r--r-- | mcast/tool/netcvlogview.c | 206 | ||||
-rw-r--r-- | mcast/tool/netcvupdate.c | 773 | ||||
l--------- | mcast/tool/tools.c | 1 |
15 files changed, 3344 insertions, 0 deletions
diff --git a/mcast/tool/.svn/entries b/mcast/tool/.svn/entries new file mode 100644 index 0000000..ecfbfc1 --- /dev/null +++ b/mcast/tool/.svn/entries @@ -0,0 +1,232 @@ +10 + +dir +18963 +svn://reelbox.org/testing/src/vdr-plugins/src/mcli-1/mcast/tool +svn://reelbox.org + + + +2011-08-18T10:09:14.813360Z +17158 +dirk + + + + + + + + + + + + + + +12be777f-adf9-0310-842f-e37ecc4c7426 + +Makefile +file + + + + +2012-09-27T17:22:49.646848Z +5d30b5398eb2c233a1bd77b484d9de30 +2011-08-18T10:09:14.813360Z +17158 +dirk + + + + + + + + + + + + + + + + + + + + + +3056 + +netcvlogview.c +file + + + + +2012-09-27T17:22:49.646848Z +6d046be96a3c706912b56105f3b0d085 +2011-08-18T10:09:14.813360Z +17158 +dirk + + + + + + + + + + + + + + + + + + + + + +5324 + +tools.c +file + + + + +2012-09-27T17:22:49.646848Z +c0906e8f658e6d84d4e12dca1e3ffc57 +2011-07-12T13:36:23.313379Z +16905 +rollercoaster +has-props + + +svn:special + + + + + + + + + + + + + + + + + +17 + +netcvupdate.c +file + + + + +2012-09-27T17:22:49.646848Z +4e59ba021a9f0008be90832c0a093d2d +2011-07-12T13:36:23.313379Z +16905 +rollercoaster + + + + + + + + + + + + + + + + + + + + + +19278 + +netcvdiag.c +file + + + + +2012-09-27T17:22:49.646848Z +f5245b3c34a379143d0d6f070aa0e908 +2011-08-18T10:09:14.813360Z +17158 +dirk + + + + + + + + + + + + + + + + + + + + + +13267 + +mcast.c +file + + + + +2012-09-27T17:22:49.646848Z +b6c289caaedfc9f9a24d597c72a5d8ce +2011-07-12T13:36:23.313379Z +16905 +rollercoaster +has-props + + +svn:special + + + + + + + + + + + + + + + + + +17 + diff --git a/mcast/tool/.svn/prop-base/mcast.c.svn-base b/mcast/tool/.svn/prop-base/mcast.c.svn-base new file mode 100644 index 0000000..d222469 --- /dev/null +++ b/mcast/tool/.svn/prop-base/mcast.c.svn-base @@ -0,0 +1,5 @@ +K 11 +svn:special +V 1 +* +END diff --git a/mcast/tool/.svn/prop-base/tools.c.svn-base b/mcast/tool/.svn/prop-base/tools.c.svn-base new file mode 100644 index 0000000..d222469 --- /dev/null +++ b/mcast/tool/.svn/prop-base/tools.c.svn-base @@ -0,0 +1,5 @@ +K 11 +svn:special +V 1 +* +END diff --git a/mcast/tool/.svn/text-base/Makefile.svn-base b/mcast/tool/.svn/text-base/Makefile.svn-base new file mode 100644 index 0000000..3cee3dc --- /dev/null +++ b/mcast/tool/.svn/text-base/Makefile.svn-base @@ -0,0 +1,137 @@ +#Comment this out to disable debugging output +#DEBUG = 1 +#API_SOCK=1 + +ifdef RBMINI + ARMEL=1 +endif + +APPLE_DARWIN = $(shell gcc -dumpmachine | grep -q 'apple-darwin' && echo "1" || echo "0") +CYGWIN = $(shell gcc -dumpmachine | grep -q 'cygwin' && echo "1" || echo "0") + +DEFINES = -DCLIENT -D_REENTRANT -D_GNU_SOURCE + +ifeq ($(CYGWIN), 1) +WIN32=1 +else +API_SOCK=1 +endif + +ifeq ($(APPLE_DARWIN), 1) +INCLUDES += -I../common/darwin/include/ +DEFINES += -DAPPLE +APPLE=1 +endif + +VDRDIR=../../../../.. +-include $(VDRDIR)/Make.config + +ifdef ARMEL + XML_INC := -I/usr/arm-linux-gnueabi/include/libxml2 + XML_LIB := -lxml2 +else + XML_INC := `xml2-config --cflags` + XML_LIB := `xml2-config --libs` + LIBRARY_PATH = /usr/lib +endif + +CFLAGS ?= -Os -Wall + +INCLUDES += $(XML_INC) -I../dvbloop -I../common/ -I../client + +LDFLAGS:=$(XML_LIB) -lpthread + +ifdef API_SHM +LDFLAGS:= $(LDFLAGS) -lrt +CFLAGS:= $(CFLAGS) -DAPI_SHM +endif + +ifdef API_SOCK +CFLAGS:= $(CFLAGS) -DAPI_SOCK +endif + +ifdef DEBUG +LDFLAGS:= $(LDFLAGS) -g +CFLAGS:= $(CFLAGS) -g -DDEBUG +endif + +ifdef WIN32 +CFLAGS:= $(CFLAGS) -DWIN32 +endif + + + +NETCVDIAG = netcvdiag +NETCVDIAG_OBJS = netcvdiag.o tools.o + +NETCVUPDATE = netcvupdate +NETCVUPDATE_OBJS = netcvupdate.o + +NETCVLOGVIEW = netcvlogview +NETCVLOGVIEW_OBJS = netcvlogview.o mcast.o + +OBJS := $(NETCVDIAG_OBJS) $(NETCVUPDATE_OBJS) $(NETCVLOGVIEW_OBJS) + +all: $(NETCVDIAG) $(NETCVUPDATE) $(NETCVLOGVIEW) + +static: $(NETCVDIAG)-static $(NETCVUPDATE)-static + + +MAKEDEP = $(CXX) -MM -MG +DEPFILE = .dependencies +$(DEPFILE): Makefile + @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ + +-include $(DEPFILE) + + +$(NETCVDIAG): $(NETCVDIAG_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVDIAG_OBJS) $(LDLIBS) +ifndef DEBUG +ifndef WIN32 + strip $(NETCVDIAG) +endif +endif + +$(NETCVUPDATE): $(NETCVUPDATE_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVUPDATE_OBJS) $(LDLIBS) +ifndef DEBUG +ifndef WIN32 + strip $(NETCVUPDATE) +endif +endif + +$(NETCVLOGVIEW): $(NETCVLOGVIEW_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVLOGVIEW_OBJS) $(LDLIBS) +ifndef DEBUG +ifndef WIN32 + strip $(NETCVLOGVIEW) +endif +endif + +$(NETCVDIAG)-static: $(NETCVDIAG_OBJS) + $(CC) $(LDFLAGS) -static -static-libgcc -o $@ $(NETCVDIAG_OBJS) $(LDLIBS) $(LIBRARY_PATH)/libm.a $(LIBRARY_PATH)/libz.a + strip $(NETCVDIAG)-static + +$(NETCVUPDATE)-static: $(NETCVUPDATE_OBJS) + $(CC) $(LDFLAGS) -static -static-libgcc -o $@ $(NETCVUPDATE_OBJS) $(LDLIBS) $(LIBRARY_PATH)/libm.a + strip $(NETCVUPDATE)-static + +$(NETCVLOGVIEW)-static: $(NETCVLOGVIEW_OBJS) + $(CC) $(LDFLAGS) -static -static-libgcc -o $@ $(NETCVLOGVIEW_OBJS) $(LDLIBS) $(LIBRARY_PATH)/libm.a $(LIBRARY_PATH)/libz.a $(LIBRARY_PATH)/libpthread.a + strip $(NETCVLOGVIEW)-static + +install: $(NETCVDIAG) $(NETCVUPDATE) $(NETCVLOGVIEW) + install -p $(NETCVDIAG) /usr/sbin/$(NETCVDIAG) + install -p $(NETCVUPDATE) /usr/sbin/$(NETCVUPDATE) + install -p $(NETCVLOGVIEW) /usr/sbin/$(NETCVLOGVIEW) + +depend: .dependencies + #makedepend -Y -- $(CFLAGS) -- *c >/dev/null 2>&1 + +clean: + rm -f $(NETCVDIAG) $(NETCVUPDATE) $(NETCVLOGVIEW) *.elf *.gdb *.o *~ + +%.o: %.c + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) -o $@ $< + diff --git a/mcast/tool/.svn/text-base/mcast.c.svn-base b/mcast/tool/.svn/text-base/mcast.c.svn-base new file mode 100644 index 0000000..8900452 --- /dev/null +++ b/mcast/tool/.svn/text-base/mcast.c.svn-base @@ -0,0 +1 @@ +link ../common/mcast.c
\ No newline at end of file diff --git a/mcast/tool/.svn/text-base/netcvdiag.c.svn-base b/mcast/tool/.svn/text-base/netcvdiag.c.svn-base new file mode 100644 index 0000000..5b6e490 --- /dev/null +++ b/mcast/tool/.svn/text-base/netcvdiag.c.svn-base @@ -0,0 +1,433 @@ +/*------------------------------------------------------------------------ + * netcvdiag - NetCeiver diagnosis tool + * + *------------------------------------------------------------------------*/ + +#include "headers.h" + +#ifdef __MINGW32__ +#include <getopt.h> +#endif + +#ifdef API_SOCK + +/*------------------------------------------------------------------------*/ +#define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; \ + send (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + recv (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + if (cmd->state == API_ERROR) warn ( "SHM parameter error\n");} + +int sock_comm; + +int nc_api_init(char *path) +{ + int sock_name_len = 0; + struct sockaddr_un sock_name; + sock_name.sun_family = AF_UNIX; + + strcpy(sock_name.sun_path, path); + sock_name_len = sizeof(struct sockaddr_un); + + if((sock_comm = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + { + warn ("socket create failure %d\n", errno); + return -1; + } + + if (connect(sock_comm, (struct sockaddr*)&sock_name, sock_name_len) < 0) { + warn ("connect failure to %s: %s\n",path, strerror(errno)); + return -1; + } + return 0; +} +#endif +#ifdef API_WIN +/*------------------------------------------------------------------------*/ +#define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; \ + WriteFile( hPipe, &sock_cmd, sizeof(api_cmd_t), &cbWritten, NULL); \ + ReadFile( hPipe, &sock_cmd, sizeof(api_cmd_t), &cbRead, NULL); \ + if (cmd->state == API_ERROR) {warn ( "SHM parameter error, incompatible versions?\n"); exit(-1);}} + +HANDLE hPipe; +DWORD cbRead, cbWritten; + +int nc_api_init(char *path) +{ + hPipe = CreateFile( + TEXT("\\\\.\\pipe\\mcli"), // pipe name + GENERIC_READ | // read and write access + GENERIC_WRITE, + 0, // no sharing + NULL, // default security attributes + OPEN_EXISTING, // opens existing pipe + 0, // default attributes + NULL); // no template file + + if (hPipe == INVALID_HANDLE_VALUE) { + warn("CreatePipe failed"); + return -1; + } + return 0; +} +#endif +/*------------------------------------------------------------------------*/ +void usage(void) +{ + fprintf(stderr, + "netcvdiag - NetCeiver diagnosis tool, version " MCLI_VERSION_STR "\n" + "(c) BayCom GmbH\n" + "Usage: netcvdiag <options>\n" + "Options: -a Show all\n" + " -u Show UUIDs\n" + " -t Show tuners\n" + " -c Get NetCeiver count\n" + " -S Show satellite settings\n" + " -s Show tuner state\n" + " -r <n> Repeat every n seconds\n" + " -v Show HW/SW-versions\n" + " -P <path> Set API socket\n" + ); + exit(0); +} +/*------------------------------------------------------------------------*/ +void show_it(int show_count, int show_uuids, int show_tuners, int show_sats, int show_versions, int show_cams) +{ + int nc_num; + int i; + time_t now=time(0); + api_cmd_t sock_cmd; + api_cmd_t *api_cmd=&sock_cmd; + + api_cmd->cmd=API_GET_NC_NUM; + api_cmd->magic = MCLI_MAGIC; + api_cmd->version = MCLI_VERSION; + + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->magic != MCLI_MAGIC || api_cmd->version != MCLI_VERSION) { + info("API version mismatch!\n"); + return; + } + if (show_count) + printf("Count: %i\n", api_cmd->parm[API_PARM_NC_NUM]); + nc_num=api_cmd->parm[API_PARM_NC_NUM]; + + for(i=0;i<nc_num;i++) { + api_cmd->cmd=API_GET_NC_INFO; + api_cmd->parm[API_PARM_NC_NUM]=i; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->u.nc_info.magic != MCLI_MAGIC || api_cmd->u.nc_info.version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + if (show_uuids||show_versions) { + char buf[UUID_SIZE]; + if(strlen(api_cmd->u.nc_info.Description)) { + sprintf(buf, "%s, ", api_cmd->u.nc_info.Description); + } else { + buf[0]=0; + } + printf("NetCeiver %i:\n" + " UUID <%s>, %s%s, tuners %d\n", + i, + api_cmd->u.nc_info.uuid, + buf, + (unsigned int) api_cmd->u.nc_info.lastseen<(now-10)?"DEAD":"ALIVE", + api_cmd->u.nc_info.tuner_num); + } + if (show_versions) { + printf(" OS <%s>, App <%s>, FW <%s>, HW <%s>\n", + api_cmd->u.nc_info.OSVersion, api_cmd->u.nc_info.AppVersion, + api_cmd->u.nc_info.FirmwareVersion, api_cmd->u.nc_info.HardwareVersion + ); + printf(" Serial <%s>, Vendor <%s>, state %i\n", + api_cmd->u.nc_info.Serial, api_cmd->u.nc_info.Vendor, api_cmd->u.nc_info.DefCon); + printf(" SystemUptime %d, ProcessUptime %d\n", + (int)api_cmd->u.nc_info.SystemUptime, (int)api_cmd->u.nc_info.ProcessUptime); + printf(" TunerTimeout %d\n", + (int)api_cmd->u.nc_info.TunerTimeout); + } + if (show_cams) { + int i; + for (i = 0; i < api_cmd->u.nc_info.cam_num; i++) { + char *camstate=""; + char *cammode=""; + + switch(api_cmd->u.nc_info.cam[i].status) { + case DVBCA_CAMSTATE_MISSING: + camstate="MISSING"; break; + case DVBCA_CAMSTATE_INITIALISING: + camstate="INIT"; break; + case DVBCA_CAMSTATE_READY: + camstate="READY"; break; + } + switch(api_cmd->u.nc_info.cam[i].flags) { + case CA_SINGLE: + cammode="CA_SINGLE";break; + case CA_MULTI_SID: + cammode="CA_MULTI_SID";break; + case CA_MULTI_TRANSPONDER: + cammode="CA_MULTI_TRANSPONDER";break; + } + printf(" CI-Slot %d: State <%s>, Mode <%s>, CAPMT-Flag: %d, SIDs %d/%d, CAM <%s>\n", api_cmd->u.nc_info.cam[i].slot, camstate, cammode, api_cmd->u.nc_info.cam[i].capmt_flag, api_cmd->u.nc_info.cam[i].use_sids, api_cmd->u.nc_info.cam[i].max_sids, api_cmd->u.nc_info.cam[i].menu_string); + } + } + if (show_tuners) { + int j; + int tuner_num=api_cmd->u.nc_info.tuner_num; + for(j=0;j<tuner_num;j++) { + api_cmd->cmd=API_GET_TUNER_INFO; + api_cmd->parm[API_PARM_TUNER_NUM]=j; + API_WAIT_RESPONSE(api_cmd); + printf(" Tuner %i: <%s>, SatList: <%s>, Preference %i\n", + j, + api_cmd->u.tuner_info.fe_info.name, + api_cmd->u.tuner_info.SatelliteListName, + api_cmd->u.tuner_info.preference + ); + } + puts(""); + } + + if (show_sats) { + int sat_list_num=api_cmd->u.nc_info.sat_list_num; + int j; + for(j=0;j<sat_list_num;j++) { + api_cmd->cmd=API_GET_SAT_LIST_INFO; + api_cmd->parm[API_PARM_NC_NUM]=i; + api_cmd->parm[API_PARM_SAT_LIST_NUM]=j; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->u.sat_list.magic != MCLI_MAGIC || api_cmd->u.sat_list.version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + + printf("NetCeiver %i: SatList <%s>, entries %d\n", + i, + api_cmd->u.sat_list.Name, + api_cmd->u.sat_list.sat_num); + + int sat_num=api_cmd->u.sat_list.sat_num; + int k; + for(k=0;k<sat_num;k++) { + api_cmd->cmd=API_GET_SAT_INFO; + api_cmd->parm[API_PARM_SAT_LIST_NUM]=j; + api_cmd->parm[API_PARM_SAT_NUM]=k; + API_WAIT_RESPONSE(api_cmd); + int comp_num=api_cmd->u.sat_info.comp_num; + float pos=(float)((api_cmd->u.sat_info.SatPos-1800.0)/10.0); + float minr=(float)((api_cmd->u.sat_info.SatPosMin-1800.0)/10.0); + float maxr=(float)((api_cmd->u.sat_info.SatPosMax-1800.0)/10.0); + float af=(float)((api_cmd->u.sat_info.AutoFocus)/10.0); + float longitude=(float)((api_cmd->u.sat_info.Longitude)/10.0); + float latitude=(float)((api_cmd->u.sat_info.Latitude)/10.0); + + printf(" Satname: <%s>, Position <%.1f%c>, entries %i\n", + api_cmd->u.sat_info.Name, + fabs(pos),pos<0?'W':'E', + comp_num); + + if (api_cmd->u.sat_info.type==SAT_SRC_ROTOR) + printf(" Rotor: Range <%.1f%c>-<%.1f%c>, AF <%.1f>, Long <%.1f%c>, Lat <%.1f%c>\n", + fabs(minr),minr<0?'W':'E', + fabs(maxr),maxr<0?'W':'E', + fabs(af), + fabs(longitude),longitude<0?'W':'E', + fabs(latitude),longitude<0?'S':'N'); + + int l; + for(l=0;l<comp_num;l++) { + api_cmd->cmd=API_GET_SAT_COMP_INFO; + api_cmd->parm[API_PARM_SAT_LIST_NUM]=j; + api_cmd->parm[API_PARM_SAT_NUM]=k; + api_cmd->parm[API_PARM_SAT_COMP_NUM]=l; + API_WAIT_RESPONSE(api_cmd); + int m=0,n; + char diseqc[256]; + char *ptr=diseqc; + struct dvb_diseqc_master_cmd *diseqc_cmd=&api_cmd->u.sat_comp.sec.diseqc_cmd; + + diseqc[0]=0; + + for(n=0;n<api_cmd->u.sat_comp.diseqc_cmd_num;n++) { + for(*ptr=0,m=0;m<diseqc_cmd->msg_len;m++) { + ptr+=sprintf(ptr, "%02X ", diseqc_cmd->msg[m]); + } + ptr+=sprintf(ptr, ", "); + diseqc_cmd=api_cmd->u.sat_comp.diseqc_cmd+n; + } + if(m>0) { + *(ptr-3)=0; + } + char *mini="MINI_OFF"; + switch(api_cmd->u.sat_comp.sec.mini_cmd) { + case SEC_MINI_A:mini="MINI_A ";break; + case SEC_MINI_B:mini="MINI_B ";break; + } + printf(" Entry %i: Polarisation %c, Min% 6d, " + "Max% 6d, LOF% 6d %s %s %s DiSEqC <%s>\n", + l, + api_cmd->u.sat_comp.Polarisation?'H':'V', + api_cmd->u.sat_comp.RangeMin, + api_cmd->u.sat_comp.RangeMax, + api_cmd->u.sat_comp.LOF, + mini, + api_cmd->u.sat_comp.sec.tone_mode==SEC_TONE_ON ?"TONE_ON ":"TONE_OFF", + api_cmd->u.sat_comp.sec.voltage==SEC_VOLTAGE_18?"VOLTAGE_18":"VOLTAGE_13", + diseqc + ); + } + } + } + } + } + puts(""); +} +/*------------------------------------------------------------------------*/ +void show_stats(void) +{ + api_cmd_t sock_cmd; + api_cmd_t *api_cmd=&sock_cmd; + int i; + char *types[]={"DVB-S","DVB-C","DVB-T", "?", "DVB-S2"}; + int type; + + api_cmd->cmd=API_GET_TRA_NUM; + api_cmd->magic = MCLI_MAGIC; + api_cmd->version = MCLI_VERSION; + API_WAIT_RESPONSE(api_cmd); + +// printf("tra_num: %d\n", api_cmd->parm[API_PARM_TRA_NUM]); + int tra_num=api_cmd->parm[API_PARM_TRA_NUM]; + for(i=0;i<tra_num;i++) { + char uuid[256]; + char *p; + + api_cmd->cmd=API_GET_TRA_INFO; + api_cmd->parm[API_PARM_TRA_NUM]=i; + API_WAIT_RESPONSE(api_cmd); + char host[INET6_ADDRSTRLEN]; + inet_ntop (AF_INET6, &api_cmd->u.tra.mcg, (char *) host, INET6_ADDRSTRLEN); + type=api_cmd->u.tra.fe_type; + if (type<0 || type>4) + type=3; + + strncpy(uuid,api_cmd->u.tra.uuid,255); + uuid[255]=0; + p=strrchr(uuid,':'); + if (p) + *p=0; + + fe_type_t t; + recv_sec_t sec; + int satpos; + struct dvb_frontend_parameters fep; + + if(mcg_to_fe_parms(&api_cmd->u.tra.mcg, &t, &sec, &fep, NULL)<0) { + memset(&fep,0,sizeof(struct dvb_frontend_parameters)); + } + + mcg_get_satpos(&api_cmd->u.tra.mcg, &satpos); + float pos=(float)((satpos-1800.0)/10.0); + char pos_str[256]; + if(satpos != 0xfff) { + sprintf(pos_str, ", position <%.1f%c>", fabs(pos), pos<0?'W':'E'); + } else { + pos_str[0]=0; + } + + printf("UUID <%s>:\n" + " slot %s%d.%d, type %s, used: % 3d\n" + " %s, frequency %d%s (%.1f%s)%s\n" + " strength %04x, snr %04x, ber %04x, unc %04x\n" + " NIMCurrent %d\n" + " RotorStatus %i, RotorDiff %.1f\n", + uuid, + (time(0)-api_cmd->u.tra.lastseen)>15?"-":"", + api_cmd->u.tra.slot/2,api_cmd->u.tra.slot%2, + types[type], api_cmd->u.tra.InUse, + api_cmd->u.tra.s.st==0x1f?"LOCK ":"NO LOCK", + fep.frequency, (type==1||type==2)?"Hz":"kHz", api_cmd->u.tra.fep.frequency/1000.0, + (type==1||type==2)?"kHz":"MHz",pos_str, + api_cmd->u.tra.s.strength, + api_cmd->u.tra.s.snr, api_cmd->u.tra.s.ber, api_cmd->u.tra.s.ucblocks, + api_cmd->u.tra.NIMCurrent, + api_cmd->u.tra.rotor_status, + api_cmd->u.tra.rotor_diff/10.0 + ); + + } +} +/*------------------------------------------------------------------------*/ +int main(int argc, char **argv) +{ + int repeat=0; + int show_uuids=0,show_tuners=0,show_sats=0,show_state=0,show_cams=0; + int show_count=0, show_versions=0; +#ifdef API_SOCK + char path[256]=API_SOCK_NAMESPACE; +#endif +#ifdef API_WIN + char path[256]="\\\\.\\pipe\\mcli"; +#endif + while(1) { + int ret = getopt(argc,argv, "aucCtsSvr:P:"); + if (ret==-1) + break; + + char c=(char)ret; + + switch (c) { + case 'a': + show_uuids=1; + show_tuners=1; + show_sats=1; + show_state=1; + show_count=1; + show_versions=1; + show_cams=1; + break; + case 'u': + show_uuids=1; + break; + case 'c': + show_count=1; + break; + case 'C': + show_cams=1; + break; + case 't': + show_tuners=1; + break; + case 's': + show_state=1; + break; + case 'r': + repeat=abs(atoi(optarg)); + break; + case 'S': + show_sats=1; + break; + case 'v': + show_versions=1; + break; + case 'P': + strncpy(path,optarg,255); + path[255]=0; + break; + default: + usage(); + break; + } + } + if (nc_api_init(path)==-1) { + exit(-1); + } + + do { + show_it(show_count, show_uuids, show_tuners, show_sats, show_versions, show_cams); + if (show_state) + show_stats(); + sleep(repeat); + } while(repeat); + + exit(0); +} + diff --git a/mcast/tool/.svn/text-base/netcvlogview.c.svn-base b/mcast/tool/.svn/text-base/netcvlogview.c.svn-base new file mode 100644 index 0000000..4d8bc9f --- /dev/null +++ b/mcast/tool/.svn/text-base/netcvlogview.c.svn-base @@ -0,0 +1,206 @@ +#include "headers.h" + +#ifdef __MINGW32__ +#include <getopt.h> +extern void bzero(void *s, size_t n); +#endif + +#define HDR_CHK_PACKET_LENGTH 1424 +#define HDR_CHK_LENGTH 16 + +static int quit=0; + +void sighandler(int sig) { + quit=1; +} + +int main (int argc, char **argv) +{ + UDPContext *s; + unsigned char buf[UDP_TX_BUF_SIZE]; + memset (buf, 0x55, sizeof (buf)); + int ret, len, i, mode = 1, mcg_num = 1, port = 23000, c, needhelp = 0, wait = 0, file = 0, loop = 0, header = 0, lost = 0; + char mcg[10][1024]; + char *ifname = NULL; + strcpy (mcg[0], "ff18:5100::"); + + do { + ret = getopt_long (argc, argv, "hrtp:g:xi:w:flH", NULL, NULL); + if(ret<0) { + break; + } + c=(char)ret; + switch (c) { + case 'i': + ifname = optarg; + break; + case 'f': + file = 1; + break; + case 'r': + mode = 1; + break; + case 't': + mode = 2; + break; + case 'x': + mode = 3; + break; + case 'H': + header = 1; + break; + case 'l': + loop = 1; + break; + case 'p': + port = atoi (optarg); + break; + case 'w': + wait = atoi (optarg); + break; + case 'g': + for (mcg_num = 0, optind--; optind < argc; optind++, mcg_num++) { + if (argv[optind][0] != '-') { + strcpy (mcg[mcg_num], argv[optind]); + } else { + break; + } + } + break; + case 'h': + needhelp = 1; + break; + } + } + while (c >= 0); + + if (needhelp) { + fprintf (stderr, "usage: netcvlogview -i <network interface> <-r|-t> -g <multicast groups> -p <port> -w <seconds timeout> -H\n"); + return -1; + } + + fprintf (stderr, "mode:%d port:%d mcg:%d [ ", mode, port, mcg_num); + for (i = 0; i < mcg_num; i++) { + fprintf (stderr, "%s ", mcg[i]); + } + fprintf (stderr, "]\n"); + +#ifdef __MINGW32__ + recv_init (ifname, port); +#endif + + switch (mode) { + + case 1: + s = client_udp_open_host (mcg[0], port, ifname); + if (s) { + struct sockaddr_in6 addr; + addr.sin6_family = AF_INET6; + addr.sin6_port = htons (port); + + for (i = 1; i < mcg_num; i++) { + fprintf (stderr, "mcg: [%s]\n", mcg[i]); + inet_pton (AF_INET6, mcg[i], &addr.sin6_addr); + if (udp_ipv6_join_multicast_group (s->udp_fd, s->idx, (struct sockaddr *) &addr) < 0) { + err ("Cannot join multicast group !\n"); + } + + } + signal(SIGTERM, sighandler); + signal(SIGINT, sighandler); + + FILE *f; + time_t first; + time_t last; + int hc, i; + do { + first=last=hc=lost=0; + if(file) { + f=fopen("rawfile.temp", "wb"); + if(f==NULL) { + perror("Cannot open file for writing\n"); + return -1; + } + } else { + f=stdout; + } + while (!quit &&(!wait || !last || ((time(NULL)-last) < wait))) { + len = udp_read (s, buf, sizeof (buf), 50, NULL); + if(len>0) { + if(header) { + if(len!=HDR_CHK_PACKET_LENGTH) { + fprintf(stderr, "Expected header length mismatch %d != %d!\n", len, HDR_CHK_PACKET_LENGTH); + } + uint32_t *cnt=(uint32_t *)buf; + int hv=ntohl(*cnt); + if(hv == hc) { + fwrite (buf+HDR_CHK_LENGTH, len-HDR_CHK_LENGTH, 1, f); + hc++; + } else { + bzero(buf, HDR_CHK_PACKET_LENGTH); + for(i=hc; i<hv; i++) { + fwrite(buf, HDR_CHK_PACKET_LENGTH-HDR_CHK_LENGTH, 1, f); + } + lost+=(hv-hc); + hc=i; + } + } else { + fwrite (buf, len, 1, f); + } + last=time(NULL); + if(!first) { + first=last; + } + } + } + fclose(f); + if(file) { + if(quit) { + unlink("rawfile.temp"); + } else { + struct tm *now=localtime(&first); + char fname[80]; + sprintf(fname, "%04d%02d%02d-%02d%02d%02d.raw", now->tm_year+1900, now->tm_mon+1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec); + rename("rawfile.temp", fname); + fprintf(stderr, "[%s] New log file: %s (%u packets)\n",ifname, fname, hc); + if(lost) { + fprintf(stderr, "Warning: Lost %d frames of %d payload bytes, now filled with padding bytes (0)\n", lost, HDR_CHK_PACKET_LENGTH-HDR_CHK_LENGTH); + } + } + } + } while(loop && ! quit); + udp_close (s); + } + break; + + case 2: + s = server_udp_open_host (mcg[0], port, ifname); + if (s) { + while (1) { + if(!fread (buf, 1316, 1, stdin)) { + break; + } + udp_write (s, buf, 1316); + } + udp_close (s); + } + break; + + case 3: + s = server_udp_open_host (mcg[0], port, ifname); + if (s) { + int i; + for (i = 0; i < sizeof (buf); i++) { + buf[i] = rand (); + } + while (1) { + i = rand (); + udp_write (s, buf, ((i % 4) + 4) * 188); + } + udp_close (s); + } + break; + } + + return 0; +} diff --git a/mcast/tool/.svn/text-base/netcvupdate.c.svn-base b/mcast/tool/.svn/text-base/netcvupdate.c.svn-base new file mode 100644 index 0000000..e311470 --- /dev/null +++ b/mcast/tool/.svn/text-base/netcvupdate.c.svn-base @@ -0,0 +1,773 @@ +/*------------------------------------------------------------------------ + * netcvupdate - NetCeiver update tool + * + * Principle for firmware update + * - Unpack given .tgz into host /tmp/mkdtemp() + * - "md5sum -c md5sums.txt" + * - read script file update.scr + * - feed commands into tnftp + * + * + *------------------------------------------------------------------------*/ +#define USE_MCLI_API + +#ifdef USE_MCLI_API +#include "headers.h" +#else +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <signal.h> +#include <ctype.h> +#endif + +#define STATE_FILE "update.log" +#define FTP_CMD "ftp" +#define NC_CONFPATH "/mmc/etc/" +#define NC_CONFFILE "netceiver.conf" + +char ftp_cmd[512]=FTP_CMD; +int verbose=0; +int no_reboot=0; +char username[256]="root"; +char password[256]="root"; +char device[256]="eth0"; +char *uuids[256]={0}; +char *versions[256]={0}; +int num_uuids=0; +char socket_path[256]=API_SOCK_NAMESPACE; + +#ifdef USE_MCLI_API +/*------------------------------------------------------------------------*/ +#define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; \ + send (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + recv (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + if (cmd->state == API_ERROR) {warn ( "SHM parameter error, incompatible versions?\n"); exit(-1);}} + +int sock_comm; + +int api_init(char *path) +{ + int sock_name_len = 0; + struct sockaddr_un sock_name; + sock_name.sun_family = AF_UNIX; + + strcpy(sock_name.sun_path, path); + sock_name_len = sizeof(struct sockaddr_un); + + if((sock_comm = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + { + warn ("socket create failure %d\n", errno); + return -1; + } + + if (connect(sock_comm, (struct sockaddr*)&sock_name, sock_name_len) < 0) { + warn ("connect failure to %s: %s (are you root?)\n",path, strerror(errno)); + return -1; + } + return 0; +} +#endif +/*------------------------------------------------------------------------*/ +void add_upload(char* cmd, char* localfile, char *remotepath, char *remotefile) +{ + char tmp[1024]; + sprintf(tmp, + "cd %s\n" + "site exec rm -f /tmp/update/%s\n" + "put %s\n", + remotepath, remotefile, localfile); + strcat(cmd,tmp); +} +/*------------------------------------------------------------------------*/ +void add_download(char* cmd, char *remotepath, char *remotefile) +{ + char tmp[1024]; + sprintf(tmp, + "cd %s\n" + "get %s\n", + remotepath,remotefile); + strcat(cmd,tmp); +} +/*------------------------------------------------------------------------*/ +int script_interpreter(char *script, char *line, + char *ip, char *iface, char *user, char *pwd) +{ + char cmd[256],p1[256],p2[256]; + int end=0; + + *cmd=0; + *p1=0; + *p2=0; + sscanf(line,"%s %s %s\n",cmd,p1,p2); + + if (cmd[0]=='#') + return 0; + if (!strcmp(cmd,"connect")) { + char tmp[1024]; + sprintf(tmp, + "open %s%%%s\n" + "user %s %s\n", + ip,iface,user,pwd); + strcat(script,tmp); + } + else if (!strcmp(cmd,"upload")) { + add_upload(script,p2,p1,p2); + } + else if (!strcmp(cmd,"download")) { + add_download(script,p1,p2); + } + else if (!strcmp(cmd,"exit")) { + strcat(script,"quit\n"); + end=1; + } + else { + strcat(script,line); + } + return end; +} +/*------------------------------------------------------------------------*/ +char script[128*1024]; +int generate_script(char *filename, char *tmpname, char *ip, char *iface, char *user, char *pwd) +{ + FILE *f; + f=fopen(filename,"r"); + if (!f) { + fprintf(stderr,"Can't open script file <%s>: %s\n",filename,strerror(errno)); + return -1; + } + script[0]=0; + + while(!feof(f)) { + char line[256]; + fgets(line,255,f); + if (script_interpreter(script,line,ip,iface,user,pwd)) + break; + } + fclose(f); + return 0; +} +/*------------------------------------------------------------------------*/ +int check_state_file(char *tmpname) +{ + char cmd[512]; + int ret; + printf("\nUPDATE RESULT:\n"); + snprintf(cmd,512,"cat %s/update.log",tmpname); + ret=system(cmd); + printf("\n"); + return ret; +} +/*------------------------------------------------------------------------*/ +void sigground(int x) +{ +} +/*------------------------------------------------------------------------*/ +int run_ftp(char *tmpdir,char *script, int timeout, char *pipeout) +{ + FILE *f; + char cmd[512]; + int ret; + if (!strlen(ftp_cmd)) + return -1; + signal(SIGPIPE,sigground); + if (strlen(tmpdir)) +// snprintf(cmd,511,"cd %s; %s -q %i -n %s",tmpdir,ftp_cmd,timeout,verbose?"":"-V"); + snprintf(cmd,511,"cd %s; %s -n %s %s",tmpdir,ftp_cmd,verbose?"":"-V",pipeout); + else + snprintf(cmd,511,"%s -q %i -n %s %s",ftp_cmd,timeout,verbose?"":"-V",pipeout); + + f=popen(cmd,"w"); + if (!f) + return -1; + fputs(script,f); + ret=pclose(f); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_reboot(char *tmpdir, char *ip, char* iface, char *user, char* pwd) +{ + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "site exec reboot -d 5\n" + "quit\n" + , + ip,iface,user,pwd); + return run_ftp(tmpdir, script, 15,""); +} +/*------------------------------------------------------------------------*/ + +int do_list_fw(char *tmpdir, char *ip, char* iface, char *user, char* pwd, int maxf, int *found, char **versions) +{ + char tmpfile[256]="/tmp/ncvup.XXXXXX"; + char pipeout[256]; + int n=0; + int ret=0; + FILE *file; + + *found=0; + + if (!mkstemp(tmpfile)) { + fprintf(stderr,"Can't make temporary directory %s!\n",tmpfile); + return -2; + } + + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "ls /mmc/\n" + "quit\n" + , + ip,iface,user,pwd); + sprintf(pipeout," > %s",tmpfile); + ret=run_ftp(tmpdir, script, 15, pipeout); + if (ret) { + unlink(tmpfile); + return ret; + } + + file=fopen(tmpfile,"r"); + if (!file) { + unlink(tmpfile); // ? + perror("Can't read temp file"); + return ret; + } + + while(!feof(file)) { + char line[1024]; + char *p; + *line=0; + fgets(line, 1023,file); + line[1023]=0; + p=strstr(line,"etceivr."); + if (p) { + + char *pp=strchr(p,'\n'); + if (pp) + *pp=0; + + if (n < maxf) { + n++; + *versions++=strdup(p-1); + } + } + } + *found=n; + fclose(file); + unlink(tmpfile); + return 0; +} +/*------------------------------------------------------------------------*/ +int do_kill(char *tmpdir, char *ip, char* iface, char *user, char* pwd) +{ + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "site exec killall -9 mserv\n" + "quit\n" + , + ip,iface,user,pwd); + return run_ftp(tmpdir, script, 15,""); +} +/*------------------------------------------------------------------------*/ +int do_single_update(char *tmpdir, char *uuid, char *device) +{ + char path[256]; + int ret; + + snprintf(path,255,"%s/%s",tmpdir,"update.scr"); + if (generate_script(path, tmpdir, uuid, device, username, password)) + return -1; +// puts(script); + + printf("Upload update... "); + fflush(stdout); + + ret=run_ftp(tmpdir, script, 600,""); + if (ret) + return ret; + + printf("check result... \n"); + fflush(stdout); + + if (check_state_file(tmpdir)) + return -1; + +#if 1 + if (!no_reboot) { + printf("Issue Reboot... "); + fflush(stdout); + ret=do_reboot(tmpdir, uuid, device, username, password); + if (!ret) + return ret; + } +#endif + return 0; +} +/*------------------------------------------------------------------------*/ +int do_single_upload( char *uuid, char *device, char *remote_path, char *fname, char *remote_file) +{ + int ret; + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd %s\n" + "put %s %s\n" +// "site exec killall -HUP mserv\n" + "quit", + uuid,device,username,password,remote_path,fname,remote_file); + ret=run_ftp("", script, 120,""); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_single_download( char *uuid, char *device, char *remote_path, char *fname) +{ + int ret; + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd %s\n" + "get %s\n" + "quit", + uuid,device,username,password,remote_path,fname); + ret=run_ftp("", script, 120,""); + return ret; +} +/*------------------------------------------------------------------------*/ +int fw_action(char *uuid, char* iface, char *user, char* pwd, int mode, char *version) +{ + int ret; + if (mode==0) { // inactivate + printf("Inactivating version %s\n",version); + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd /mmc\n" + "rename netceivr.%s xetceivr.%s\n" + "quit", + uuid,device,username,password,version,version); + ret=run_ftp("", script, 120,""); + return ret; + } + else if (mode==1) { // enable + printf("Enabling version %s\n",version); + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd /mmc\n" + "rename xetceivr.%s netceivr.%s\n" + "quit", + uuid,device,username,password,version,version); + ret=run_ftp("", script, 120,""); + return ret; + } + else if (mode==2) { // delete + printf("Removing version %s\n",version); + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "site exec rm -rf /mmc/netceivr.%s\n" + "site exec rm -rf /mmc/xetceivr.%s\n" + "quit", + uuid,device,username,password,version,version); + ret=run_ftp("", script, 120,""); + return ret; + } + return 0; +} +/*------------------------------------------------------------------------*/ +int cleanup(char *tmpdir) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"rm -rf '%s'",tmpdir); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int unpack(char *tmpdir, char *file) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"tar xfz '%s' --directory %s",file,tmpdir); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int check_xml(char *file) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"xmllint --noout '%s'\n",file); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int check_integrity(char *tmpdir) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"cd %s; md5sum -c --status md5sums.txt \n",tmpdir); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_update(char **uuids, int num_uuids, char *device, char *optarg) +{ + char tmpdir[256]="/tmp/ncvupXXXXXX"; + int n; + int ret=0; + if (!mkdtemp(tmpdir)) { + fprintf(stderr,"Can't make temporary directory %s!\n",tmpdir); + return -2; + } +// printf("TEMP DIR %s\n",tmpdir); + if (unpack(tmpdir,optarg)) { + fprintf(stderr,"Update file <%s> cannot be unpacked!\n",optarg); + cleanup(tmpdir); + return -2; + } + if (check_integrity(tmpdir)) { + fprintf(stderr,"Update file <%s> corrupted!\n",optarg); + cleanup(tmpdir); + return -2; + } + printf("Update file integrity OK\n"); + printf("NUM uuids %i\n",num_uuids); + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + + printf("UUID %s: ",uuids[n]); + fflush(stdout); + ret=do_single_update(tmpdir, uuids[n], device); + if (!ret) + printf("-> Update done <-\n"); + else { + printf("-> Update failed (ret=%i) <-\n",ret); + uuids[n]=NULL; + } + } + + cleanup(tmpdir); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_upload(char **uuids, int num_uuids, char *device, char *optarg) +{ + int n; + int ret=0; + if (check_xml(optarg)) { + fprintf(stderr,"Configuration file <%s> not valid XML\n",optarg); + return -2; + } + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + + printf("UUID %s: Uploading %s ... ",uuids[n], optarg); + fflush(stdout); + ret=do_single_upload(uuids[n], device, "/mmc/etc/", optarg, NC_CONFFILE); + if (!ret) + printf("Upload done\n"); + else { + printf("Upload failed (ret=%i)\n",ret); + uuids[n]=NULL; + } + } + return ret; +} +/*------------------------------------------------------------------------*/ +int do_download(char **uuids, int num_uuids, char *device, char *remotepath, char *file) +{ + int n,ret=0; + + for(n=0;n<num_uuids;n++) { + char newfile[1024]; + if (!uuids[n]) + continue; + + if (num_uuids!=1) + snprintf(newfile,1024,"%s-%s",file,uuids[n]); + else + strncpy(newfile,file,1024); + + printf("UUID %s: Downloading %s ... ",uuids[n], newfile); + fflush(stdout); + ret=do_single_download(uuids[n], device, remotepath, file); + if (!ret) { + printf("Done\n"); + if (num_uuids!=1) + rename(file,newfile); + } + else { + printf("Download failed (ret=%i)\n",ret); + uuids[n]=NULL; + } + } + return ret; +} +/*------------------------------------------------------------------------*/ +int do_all_reboot(char **uuids, int num_uuids, char *device) +{ + int n,ret=0; + + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + printf("UUID %s: Issue Reboot... ",uuids[n]); + fflush(stdout); + ret=do_reboot("/tmp", uuids[n], device, username, password); + if (!ret) + printf("Reboot done\n"); + else + printf("Reboot failed (ret=%i)\n",ret); + } + return ret; +} +/*------------------------------------------------------------------------*/ +int do_all_kill(char **uuids, int num_uuids, char *device) +{ + int n,ret=0; + + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + printf("UUID %s: Issue Kill... ",uuids[n]); + fflush(stdout); + ret=do_kill("/tmp", uuids[n], device, username, password); + if (!ret) + printf("Kill done\n"); + else + printf("Kill failed (ret=%i)\n",ret); + } + return ret; +} +/*------------------------------------------------------------------------*/ +int get_uuids(char **uuids, int max) +{ + int count,n; + api_cmd_t sock_cmd; + api_cmd_t *api_cmd=&sock_cmd; + + if (api_init(socket_path)==-1) { + exit(-1); + } + api_cmd->cmd=API_GET_NC_NUM; + api_cmd->magic = MCLI_MAGIC; + api_cmd->version = MCLI_VERSION; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->magic != MCLI_MAGIC || api_cmd->version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + count=api_cmd->parm[API_PARM_NC_NUM]; + + for(n=0;n<max && n<count;n++) { + api_cmd->cmd=API_GET_NC_INFO; + api_cmd->parm[API_PARM_NC_NUM]=n; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->u.nc_info.magic != MCLI_MAGIC || api_cmd->u.nc_info.version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + + uuids[n]=strdup(api_cmd->u.nc_info.uuid); + versions[n]=strdup(api_cmd->u.nc_info.FirmwareVersion); + } + return count; +} +/*------------------------------------------------------------------------*/ +int show_uuids(void) +{ + char *uuids[256]={0}; + int num_uuids,n; + num_uuids=get_uuids(uuids,256); + for(n=0;n<num_uuids;n++) { + printf("%s %s\n",uuids[n],versions[n]); + } + return 0; +} +/*------------------------------------------------------------------------*/ +#define MAX_FWS 64 +void show_firmwares(char *uuid, char *device, char *username, char *passwd) +{ + char *fwversions[MAX_FWS]; + int found,m; + found=0; + + do_list_fw("/tmp", uuid, device, username, password, MAX_FWS, &found, fwversions); + + printf("Firmware versions found: %i\n Versions: ", found); + for(m=0;m<found;m++) { + if (m!=0) printf(", "); + if (fwversions[m][0]!='n') + printf("%s (disabled)",fwversions[m]+9); + else + printf("%s",fwversions[m]+9); + + free(versions[m]); + } + puts(""); +} +/*------------------------------------------------------------------------*/ + +int show_all_firmwares(char **uuids, int num_uuids) +{ + int n; + + for(n=0;n<num_uuids;n++) { + printf("%s: ",uuids[n]); + fflush(stdout); + show_firmwares(uuids[n],device,username,password); + } + return 0; +} +/*------------------------------------------------------------------------*/ +void do_fw_actions(char **uuids, int max, int mode, char *version) +{ + int n; + + if (strlen(version)!=3 || !strcmp(version,"000")) { + fprintf(stderr,"Invalid version number\n"); + return; + } + + for(n=0;n<3;n++) + version[n]=toupper(version[n]); + + for(n=0;n<max;n++) { + printf("UUID %s\n",uuids[n]); + if (fw_action(uuids[n], device, username, password, mode, version)) { + fprintf(stderr,"Failed\n"); + return; + } + show_firmwares(uuids[n],device,username,password); + } +} +/*------------------------------------------------------------------------*/ +void usage(void) +{ + fprintf(stderr, + "netcvupdate - NetCeiver update tool, version " MCLI_VERSION_STR "\n" + "(c) BayCom GmbH\n" + "Usage: netcvupdate <options> <actions> \n" + "Actions: \n" + " -l List all seen NetCeivers and their UUID\n" + " -L List available FWs\n" + " -X <Update.tgz> Update with given file\n" + " -U <configfile> Upload configfile\n" + " -D Download configfile netceiver.conf\n" + " -I <version> Inactivate FW version\n" + " -E <version> Enable FW version\n" + " -Z <version> Remove FW version\n" + " -K Restart streaming server\n" + " -R Issue reboot\n" + "Options:\n" + " -A Use all found NetCeivers (mcli must be running)\n" + " -i <uuid> Use specific UUID (can be used multiple times)\n" + " *** Either -A or -i must be given for most actions! ***\n" + "Rare options:\n" + " -d <device> Set network device (default: eth0)\n" + " -F <ftp-command> Set ftp command/path\n" + " *** ftp command must understand the -q (timeout) option! ***\n" + " -P <path> Set API socket\n" + " -u <user> Set username\n" + " -p <password> Set password\n" + " -r No reboot after update\n" + " -q Be more quiet\n" + ); + exit(0); +} +/*------------------------------------------------------------------------*/ +int main(int argc, char **argv) +{ + int ret=0; + + while(1) { + int ret = getopt(argc,argv, "U:X:Di:AlLI:E:Z:d:F:P:u:p:rRqK"); + if (ret==-1) + break; + + char c=(char)ret; + + switch(c) { + case 'F': + strncpy(ftp_cmd,optarg,512); + ftp_cmd[511]=0; + break; + case 'X': + ret=do_update(uuids, num_uuids, device, optarg); + if (ret==-2) + exit(ret); + break; + case 'U': + ret=do_upload(uuids, num_uuids, device, optarg); + if (ret==-2) + exit(ret); + break; + case 'D': + ret|=do_download(uuids, num_uuids, device, NC_CONFPATH, NC_CONFFILE); + break; + case 'i': + uuids[num_uuids]=strdup(optarg); + num_uuids++; + break; + case 'A': + num_uuids=get_uuids(uuids,255); + break; + case 'l': + show_uuids(); + break; + case 'd': + strncpy(device,optarg,255); + device[255]=0; + break; + case 'P': + strncpy(socket_path,optarg,255); + socket_path[255]=0; + break; + case 'p': + strncpy(password,optarg,255); + password[255]=0; + break; + case 'u': + strncpy(username,optarg,255); + username[255]=0; + break; + case 'r': + no_reboot=1; + break; + case 'K': + ret|=do_all_kill(uuids,num_uuids,device); + break; + case 'R': + ret|=do_all_reboot(uuids, num_uuids, device); + break; + case 'L': + show_all_firmwares(uuids, num_uuids); + break; + case 'I': + do_fw_actions(uuids, num_uuids, 0, optarg); + break; + case 'E': + do_fw_actions(uuids, num_uuids, 1, optarg); + break; + case 'Z': + do_fw_actions(uuids, num_uuids, 2, optarg); + break; + case 'q': + verbose=0; + break; + default: + usage(); + break; + } + } + exit(ret); +} diff --git a/mcast/tool/.svn/text-base/tools.c.svn-base b/mcast/tool/.svn/text-base/tools.c.svn-base new file mode 100644 index 0000000..d249f01 --- /dev/null +++ b/mcast/tool/.svn/text-base/tools.c.svn-base @@ -0,0 +1 @@ +link ../common/tools.c
\ No newline at end of file diff --git a/mcast/tool/Makefile b/mcast/tool/Makefile new file mode 100644 index 0000000..3cee3dc --- /dev/null +++ b/mcast/tool/Makefile @@ -0,0 +1,137 @@ +#Comment this out to disable debugging output +#DEBUG = 1 +#API_SOCK=1 + +ifdef RBMINI + ARMEL=1 +endif + +APPLE_DARWIN = $(shell gcc -dumpmachine | grep -q 'apple-darwin' && echo "1" || echo "0") +CYGWIN = $(shell gcc -dumpmachine | grep -q 'cygwin' && echo "1" || echo "0") + +DEFINES = -DCLIENT -D_REENTRANT -D_GNU_SOURCE + +ifeq ($(CYGWIN), 1) +WIN32=1 +else +API_SOCK=1 +endif + +ifeq ($(APPLE_DARWIN), 1) +INCLUDES += -I../common/darwin/include/ +DEFINES += -DAPPLE +APPLE=1 +endif + +VDRDIR=../../../../.. +-include $(VDRDIR)/Make.config + +ifdef ARMEL + XML_INC := -I/usr/arm-linux-gnueabi/include/libxml2 + XML_LIB := -lxml2 +else + XML_INC := `xml2-config --cflags` + XML_LIB := `xml2-config --libs` + LIBRARY_PATH = /usr/lib +endif + +CFLAGS ?= -Os -Wall + +INCLUDES += $(XML_INC) -I../dvbloop -I../common/ -I../client + +LDFLAGS:=$(XML_LIB) -lpthread + +ifdef API_SHM +LDFLAGS:= $(LDFLAGS) -lrt +CFLAGS:= $(CFLAGS) -DAPI_SHM +endif + +ifdef API_SOCK +CFLAGS:= $(CFLAGS) -DAPI_SOCK +endif + +ifdef DEBUG +LDFLAGS:= $(LDFLAGS) -g +CFLAGS:= $(CFLAGS) -g -DDEBUG +endif + +ifdef WIN32 +CFLAGS:= $(CFLAGS) -DWIN32 +endif + + + +NETCVDIAG = netcvdiag +NETCVDIAG_OBJS = netcvdiag.o tools.o + +NETCVUPDATE = netcvupdate +NETCVUPDATE_OBJS = netcvupdate.o + +NETCVLOGVIEW = netcvlogview +NETCVLOGVIEW_OBJS = netcvlogview.o mcast.o + +OBJS := $(NETCVDIAG_OBJS) $(NETCVUPDATE_OBJS) $(NETCVLOGVIEW_OBJS) + +all: $(NETCVDIAG) $(NETCVUPDATE) $(NETCVLOGVIEW) + +static: $(NETCVDIAG)-static $(NETCVUPDATE)-static + + +MAKEDEP = $(CXX) -MM -MG +DEPFILE = .dependencies +$(DEPFILE): Makefile + @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ + +-include $(DEPFILE) + + +$(NETCVDIAG): $(NETCVDIAG_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVDIAG_OBJS) $(LDLIBS) +ifndef DEBUG +ifndef WIN32 + strip $(NETCVDIAG) +endif +endif + +$(NETCVUPDATE): $(NETCVUPDATE_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVUPDATE_OBJS) $(LDLIBS) +ifndef DEBUG +ifndef WIN32 + strip $(NETCVUPDATE) +endif +endif + +$(NETCVLOGVIEW): $(NETCVLOGVIEW_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVLOGVIEW_OBJS) $(LDLIBS) +ifndef DEBUG +ifndef WIN32 + strip $(NETCVLOGVIEW) +endif +endif + +$(NETCVDIAG)-static: $(NETCVDIAG_OBJS) + $(CC) $(LDFLAGS) -static -static-libgcc -o $@ $(NETCVDIAG_OBJS) $(LDLIBS) $(LIBRARY_PATH)/libm.a $(LIBRARY_PATH)/libz.a + strip $(NETCVDIAG)-static + +$(NETCVUPDATE)-static: $(NETCVUPDATE_OBJS) + $(CC) $(LDFLAGS) -static -static-libgcc -o $@ $(NETCVUPDATE_OBJS) $(LDLIBS) $(LIBRARY_PATH)/libm.a + strip $(NETCVUPDATE)-static + +$(NETCVLOGVIEW)-static: $(NETCVLOGVIEW_OBJS) + $(CC) $(LDFLAGS) -static -static-libgcc -o $@ $(NETCVLOGVIEW_OBJS) $(LDLIBS) $(LIBRARY_PATH)/libm.a $(LIBRARY_PATH)/libz.a $(LIBRARY_PATH)/libpthread.a + strip $(NETCVLOGVIEW)-static + +install: $(NETCVDIAG) $(NETCVUPDATE) $(NETCVLOGVIEW) + install -p $(NETCVDIAG) /usr/sbin/$(NETCVDIAG) + install -p $(NETCVUPDATE) /usr/sbin/$(NETCVUPDATE) + install -p $(NETCVLOGVIEW) /usr/sbin/$(NETCVLOGVIEW) + +depend: .dependencies + #makedepend -Y -- $(CFLAGS) -- *c >/dev/null 2>&1 + +clean: + rm -f $(NETCVDIAG) $(NETCVUPDATE) $(NETCVLOGVIEW) *.elf *.gdb *.o *~ + +%.o: %.c + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) -o $@ $< + diff --git a/mcast/tool/mcast.c b/mcast/tool/mcast.c new file mode 120000 index 0000000..b2f4f7b --- /dev/null +++ b/mcast/tool/mcast.c @@ -0,0 +1 @@ +../common/mcast.c
\ No newline at end of file diff --git a/mcast/tool/netcvdiag.c b/mcast/tool/netcvdiag.c new file mode 100644 index 0000000..5b6e490 --- /dev/null +++ b/mcast/tool/netcvdiag.c @@ -0,0 +1,433 @@ +/*------------------------------------------------------------------------ + * netcvdiag - NetCeiver diagnosis tool + * + *------------------------------------------------------------------------*/ + +#include "headers.h" + +#ifdef __MINGW32__ +#include <getopt.h> +#endif + +#ifdef API_SOCK + +/*------------------------------------------------------------------------*/ +#define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; \ + send (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + recv (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + if (cmd->state == API_ERROR) warn ( "SHM parameter error\n");} + +int sock_comm; + +int nc_api_init(char *path) +{ + int sock_name_len = 0; + struct sockaddr_un sock_name; + sock_name.sun_family = AF_UNIX; + + strcpy(sock_name.sun_path, path); + sock_name_len = sizeof(struct sockaddr_un); + + if((sock_comm = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + { + warn ("socket create failure %d\n", errno); + return -1; + } + + if (connect(sock_comm, (struct sockaddr*)&sock_name, sock_name_len) < 0) { + warn ("connect failure to %s: %s\n",path, strerror(errno)); + return -1; + } + return 0; +} +#endif +#ifdef API_WIN +/*------------------------------------------------------------------------*/ +#define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; \ + WriteFile( hPipe, &sock_cmd, sizeof(api_cmd_t), &cbWritten, NULL); \ + ReadFile( hPipe, &sock_cmd, sizeof(api_cmd_t), &cbRead, NULL); \ + if (cmd->state == API_ERROR) {warn ( "SHM parameter error, incompatible versions?\n"); exit(-1);}} + +HANDLE hPipe; +DWORD cbRead, cbWritten; + +int nc_api_init(char *path) +{ + hPipe = CreateFile( + TEXT("\\\\.\\pipe\\mcli"), // pipe name + GENERIC_READ | // read and write access + GENERIC_WRITE, + 0, // no sharing + NULL, // default security attributes + OPEN_EXISTING, // opens existing pipe + 0, // default attributes + NULL); // no template file + + if (hPipe == INVALID_HANDLE_VALUE) { + warn("CreatePipe failed"); + return -1; + } + return 0; +} +#endif +/*------------------------------------------------------------------------*/ +void usage(void) +{ + fprintf(stderr, + "netcvdiag - NetCeiver diagnosis tool, version " MCLI_VERSION_STR "\n" + "(c) BayCom GmbH\n" + "Usage: netcvdiag <options>\n" + "Options: -a Show all\n" + " -u Show UUIDs\n" + " -t Show tuners\n" + " -c Get NetCeiver count\n" + " -S Show satellite settings\n" + " -s Show tuner state\n" + " -r <n> Repeat every n seconds\n" + " -v Show HW/SW-versions\n" + " -P <path> Set API socket\n" + ); + exit(0); +} +/*------------------------------------------------------------------------*/ +void show_it(int show_count, int show_uuids, int show_tuners, int show_sats, int show_versions, int show_cams) +{ + int nc_num; + int i; + time_t now=time(0); + api_cmd_t sock_cmd; + api_cmd_t *api_cmd=&sock_cmd; + + api_cmd->cmd=API_GET_NC_NUM; + api_cmd->magic = MCLI_MAGIC; + api_cmd->version = MCLI_VERSION; + + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->magic != MCLI_MAGIC || api_cmd->version != MCLI_VERSION) { + info("API version mismatch!\n"); + return; + } + if (show_count) + printf("Count: %i\n", api_cmd->parm[API_PARM_NC_NUM]); + nc_num=api_cmd->parm[API_PARM_NC_NUM]; + + for(i=0;i<nc_num;i++) { + api_cmd->cmd=API_GET_NC_INFO; + api_cmd->parm[API_PARM_NC_NUM]=i; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->u.nc_info.magic != MCLI_MAGIC || api_cmd->u.nc_info.version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + if (show_uuids||show_versions) { + char buf[UUID_SIZE]; + if(strlen(api_cmd->u.nc_info.Description)) { + sprintf(buf, "%s, ", api_cmd->u.nc_info.Description); + } else { + buf[0]=0; + } + printf("NetCeiver %i:\n" + " UUID <%s>, %s%s, tuners %d\n", + i, + api_cmd->u.nc_info.uuid, + buf, + (unsigned int) api_cmd->u.nc_info.lastseen<(now-10)?"DEAD":"ALIVE", + api_cmd->u.nc_info.tuner_num); + } + if (show_versions) { + printf(" OS <%s>, App <%s>, FW <%s>, HW <%s>\n", + api_cmd->u.nc_info.OSVersion, api_cmd->u.nc_info.AppVersion, + api_cmd->u.nc_info.FirmwareVersion, api_cmd->u.nc_info.HardwareVersion + ); + printf(" Serial <%s>, Vendor <%s>, state %i\n", + api_cmd->u.nc_info.Serial, api_cmd->u.nc_info.Vendor, api_cmd->u.nc_info.DefCon); + printf(" SystemUptime %d, ProcessUptime %d\n", + (int)api_cmd->u.nc_info.SystemUptime, (int)api_cmd->u.nc_info.ProcessUptime); + printf(" TunerTimeout %d\n", + (int)api_cmd->u.nc_info.TunerTimeout); + } + if (show_cams) { + int i; + for (i = 0; i < api_cmd->u.nc_info.cam_num; i++) { + char *camstate=""; + char *cammode=""; + + switch(api_cmd->u.nc_info.cam[i].status) { + case DVBCA_CAMSTATE_MISSING: + camstate="MISSING"; break; + case DVBCA_CAMSTATE_INITIALISING: + camstate="INIT"; break; + case DVBCA_CAMSTATE_READY: + camstate="READY"; break; + } + switch(api_cmd->u.nc_info.cam[i].flags) { + case CA_SINGLE: + cammode="CA_SINGLE";break; + case CA_MULTI_SID: + cammode="CA_MULTI_SID";break; + case CA_MULTI_TRANSPONDER: + cammode="CA_MULTI_TRANSPONDER";break; + } + printf(" CI-Slot %d: State <%s>, Mode <%s>, CAPMT-Flag: %d, SIDs %d/%d, CAM <%s>\n", api_cmd->u.nc_info.cam[i].slot, camstate, cammode, api_cmd->u.nc_info.cam[i].capmt_flag, api_cmd->u.nc_info.cam[i].use_sids, api_cmd->u.nc_info.cam[i].max_sids, api_cmd->u.nc_info.cam[i].menu_string); + } + } + if (show_tuners) { + int j; + int tuner_num=api_cmd->u.nc_info.tuner_num; + for(j=0;j<tuner_num;j++) { + api_cmd->cmd=API_GET_TUNER_INFO; + api_cmd->parm[API_PARM_TUNER_NUM]=j; + API_WAIT_RESPONSE(api_cmd); + printf(" Tuner %i: <%s>, SatList: <%s>, Preference %i\n", + j, + api_cmd->u.tuner_info.fe_info.name, + api_cmd->u.tuner_info.SatelliteListName, + api_cmd->u.tuner_info.preference + ); + } + puts(""); + } + + if (show_sats) { + int sat_list_num=api_cmd->u.nc_info.sat_list_num; + int j; + for(j=0;j<sat_list_num;j++) { + api_cmd->cmd=API_GET_SAT_LIST_INFO; + api_cmd->parm[API_PARM_NC_NUM]=i; + api_cmd->parm[API_PARM_SAT_LIST_NUM]=j; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->u.sat_list.magic != MCLI_MAGIC || api_cmd->u.sat_list.version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + + printf("NetCeiver %i: SatList <%s>, entries %d\n", + i, + api_cmd->u.sat_list.Name, + api_cmd->u.sat_list.sat_num); + + int sat_num=api_cmd->u.sat_list.sat_num; + int k; + for(k=0;k<sat_num;k++) { + api_cmd->cmd=API_GET_SAT_INFO; + api_cmd->parm[API_PARM_SAT_LIST_NUM]=j; + api_cmd->parm[API_PARM_SAT_NUM]=k; + API_WAIT_RESPONSE(api_cmd); + int comp_num=api_cmd->u.sat_info.comp_num; + float pos=(float)((api_cmd->u.sat_info.SatPos-1800.0)/10.0); + float minr=(float)((api_cmd->u.sat_info.SatPosMin-1800.0)/10.0); + float maxr=(float)((api_cmd->u.sat_info.SatPosMax-1800.0)/10.0); + float af=(float)((api_cmd->u.sat_info.AutoFocus)/10.0); + float longitude=(float)((api_cmd->u.sat_info.Longitude)/10.0); + float latitude=(float)((api_cmd->u.sat_info.Latitude)/10.0); + + printf(" Satname: <%s>, Position <%.1f%c>, entries %i\n", + api_cmd->u.sat_info.Name, + fabs(pos),pos<0?'W':'E', + comp_num); + + if (api_cmd->u.sat_info.type==SAT_SRC_ROTOR) + printf(" Rotor: Range <%.1f%c>-<%.1f%c>, AF <%.1f>, Long <%.1f%c>, Lat <%.1f%c>\n", + fabs(minr),minr<0?'W':'E', + fabs(maxr),maxr<0?'W':'E', + fabs(af), + fabs(longitude),longitude<0?'W':'E', + fabs(latitude),longitude<0?'S':'N'); + + int l; + for(l=0;l<comp_num;l++) { + api_cmd->cmd=API_GET_SAT_COMP_INFO; + api_cmd->parm[API_PARM_SAT_LIST_NUM]=j; + api_cmd->parm[API_PARM_SAT_NUM]=k; + api_cmd->parm[API_PARM_SAT_COMP_NUM]=l; + API_WAIT_RESPONSE(api_cmd); + int m=0,n; + char diseqc[256]; + char *ptr=diseqc; + struct dvb_diseqc_master_cmd *diseqc_cmd=&api_cmd->u.sat_comp.sec.diseqc_cmd; + + diseqc[0]=0; + + for(n=0;n<api_cmd->u.sat_comp.diseqc_cmd_num;n++) { + for(*ptr=0,m=0;m<diseqc_cmd->msg_len;m++) { + ptr+=sprintf(ptr, "%02X ", diseqc_cmd->msg[m]); + } + ptr+=sprintf(ptr, ", "); + diseqc_cmd=api_cmd->u.sat_comp.diseqc_cmd+n; + } + if(m>0) { + *(ptr-3)=0; + } + char *mini="MINI_OFF"; + switch(api_cmd->u.sat_comp.sec.mini_cmd) { + case SEC_MINI_A:mini="MINI_A ";break; + case SEC_MINI_B:mini="MINI_B ";break; + } + printf(" Entry %i: Polarisation %c, Min% 6d, " + "Max% 6d, LOF% 6d %s %s %s DiSEqC <%s>\n", + l, + api_cmd->u.sat_comp.Polarisation?'H':'V', + api_cmd->u.sat_comp.RangeMin, + api_cmd->u.sat_comp.RangeMax, + api_cmd->u.sat_comp.LOF, + mini, + api_cmd->u.sat_comp.sec.tone_mode==SEC_TONE_ON ?"TONE_ON ":"TONE_OFF", + api_cmd->u.sat_comp.sec.voltage==SEC_VOLTAGE_18?"VOLTAGE_18":"VOLTAGE_13", + diseqc + ); + } + } + } + } + } + puts(""); +} +/*------------------------------------------------------------------------*/ +void show_stats(void) +{ + api_cmd_t sock_cmd; + api_cmd_t *api_cmd=&sock_cmd; + int i; + char *types[]={"DVB-S","DVB-C","DVB-T", "?", "DVB-S2"}; + int type; + + api_cmd->cmd=API_GET_TRA_NUM; + api_cmd->magic = MCLI_MAGIC; + api_cmd->version = MCLI_VERSION; + API_WAIT_RESPONSE(api_cmd); + +// printf("tra_num: %d\n", api_cmd->parm[API_PARM_TRA_NUM]); + int tra_num=api_cmd->parm[API_PARM_TRA_NUM]; + for(i=0;i<tra_num;i++) { + char uuid[256]; + char *p; + + api_cmd->cmd=API_GET_TRA_INFO; + api_cmd->parm[API_PARM_TRA_NUM]=i; + API_WAIT_RESPONSE(api_cmd); + char host[INET6_ADDRSTRLEN]; + inet_ntop (AF_INET6, &api_cmd->u.tra.mcg, (char *) host, INET6_ADDRSTRLEN); + type=api_cmd->u.tra.fe_type; + if (type<0 || type>4) + type=3; + + strncpy(uuid,api_cmd->u.tra.uuid,255); + uuid[255]=0; + p=strrchr(uuid,':'); + if (p) + *p=0; + + fe_type_t t; + recv_sec_t sec; + int satpos; + struct dvb_frontend_parameters fep; + + if(mcg_to_fe_parms(&api_cmd->u.tra.mcg, &t, &sec, &fep, NULL)<0) { + memset(&fep,0,sizeof(struct dvb_frontend_parameters)); + } + + mcg_get_satpos(&api_cmd->u.tra.mcg, &satpos); + float pos=(float)((satpos-1800.0)/10.0); + char pos_str[256]; + if(satpos != 0xfff) { + sprintf(pos_str, ", position <%.1f%c>", fabs(pos), pos<0?'W':'E'); + } else { + pos_str[0]=0; + } + + printf("UUID <%s>:\n" + " slot %s%d.%d, type %s, used: % 3d\n" + " %s, frequency %d%s (%.1f%s)%s\n" + " strength %04x, snr %04x, ber %04x, unc %04x\n" + " NIMCurrent %d\n" + " RotorStatus %i, RotorDiff %.1f\n", + uuid, + (time(0)-api_cmd->u.tra.lastseen)>15?"-":"", + api_cmd->u.tra.slot/2,api_cmd->u.tra.slot%2, + types[type], api_cmd->u.tra.InUse, + api_cmd->u.tra.s.st==0x1f?"LOCK ":"NO LOCK", + fep.frequency, (type==1||type==2)?"Hz":"kHz", api_cmd->u.tra.fep.frequency/1000.0, + (type==1||type==2)?"kHz":"MHz",pos_str, + api_cmd->u.tra.s.strength, + api_cmd->u.tra.s.snr, api_cmd->u.tra.s.ber, api_cmd->u.tra.s.ucblocks, + api_cmd->u.tra.NIMCurrent, + api_cmd->u.tra.rotor_status, + api_cmd->u.tra.rotor_diff/10.0 + ); + + } +} +/*------------------------------------------------------------------------*/ +int main(int argc, char **argv) +{ + int repeat=0; + int show_uuids=0,show_tuners=0,show_sats=0,show_state=0,show_cams=0; + int show_count=0, show_versions=0; +#ifdef API_SOCK + char path[256]=API_SOCK_NAMESPACE; +#endif +#ifdef API_WIN + char path[256]="\\\\.\\pipe\\mcli"; +#endif + while(1) { + int ret = getopt(argc,argv, "aucCtsSvr:P:"); + if (ret==-1) + break; + + char c=(char)ret; + + switch (c) { + case 'a': + show_uuids=1; + show_tuners=1; + show_sats=1; + show_state=1; + show_count=1; + show_versions=1; + show_cams=1; + break; + case 'u': + show_uuids=1; + break; + case 'c': + show_count=1; + break; + case 'C': + show_cams=1; + break; + case 't': + show_tuners=1; + break; + case 's': + show_state=1; + break; + case 'r': + repeat=abs(atoi(optarg)); + break; + case 'S': + show_sats=1; + break; + case 'v': + show_versions=1; + break; + case 'P': + strncpy(path,optarg,255); + path[255]=0; + break; + default: + usage(); + break; + } + } + if (nc_api_init(path)==-1) { + exit(-1); + } + + do { + show_it(show_count, show_uuids, show_tuners, show_sats, show_versions, show_cams); + if (show_state) + show_stats(); + sleep(repeat); + } while(repeat); + + exit(0); +} + diff --git a/mcast/tool/netcvlogview.c b/mcast/tool/netcvlogview.c new file mode 100644 index 0000000..4d8bc9f --- /dev/null +++ b/mcast/tool/netcvlogview.c @@ -0,0 +1,206 @@ +#include "headers.h" + +#ifdef __MINGW32__ +#include <getopt.h> +extern void bzero(void *s, size_t n); +#endif + +#define HDR_CHK_PACKET_LENGTH 1424 +#define HDR_CHK_LENGTH 16 + +static int quit=0; + +void sighandler(int sig) { + quit=1; +} + +int main (int argc, char **argv) +{ + UDPContext *s; + unsigned char buf[UDP_TX_BUF_SIZE]; + memset (buf, 0x55, sizeof (buf)); + int ret, len, i, mode = 1, mcg_num = 1, port = 23000, c, needhelp = 0, wait = 0, file = 0, loop = 0, header = 0, lost = 0; + char mcg[10][1024]; + char *ifname = NULL; + strcpy (mcg[0], "ff18:5100::"); + + do { + ret = getopt_long (argc, argv, "hrtp:g:xi:w:flH", NULL, NULL); + if(ret<0) { + break; + } + c=(char)ret; + switch (c) { + case 'i': + ifname = optarg; + break; + case 'f': + file = 1; + break; + case 'r': + mode = 1; + break; + case 't': + mode = 2; + break; + case 'x': + mode = 3; + break; + case 'H': + header = 1; + break; + case 'l': + loop = 1; + break; + case 'p': + port = atoi (optarg); + break; + case 'w': + wait = atoi (optarg); + break; + case 'g': + for (mcg_num = 0, optind--; optind < argc; optind++, mcg_num++) { + if (argv[optind][0] != '-') { + strcpy (mcg[mcg_num], argv[optind]); + } else { + break; + } + } + break; + case 'h': + needhelp = 1; + break; + } + } + while (c >= 0); + + if (needhelp) { + fprintf (stderr, "usage: netcvlogview -i <network interface> <-r|-t> -g <multicast groups> -p <port> -w <seconds timeout> -H\n"); + return -1; + } + + fprintf (stderr, "mode:%d port:%d mcg:%d [ ", mode, port, mcg_num); + for (i = 0; i < mcg_num; i++) { + fprintf (stderr, "%s ", mcg[i]); + } + fprintf (stderr, "]\n"); + +#ifdef __MINGW32__ + recv_init (ifname, port); +#endif + + switch (mode) { + + case 1: + s = client_udp_open_host (mcg[0], port, ifname); + if (s) { + struct sockaddr_in6 addr; + addr.sin6_family = AF_INET6; + addr.sin6_port = htons (port); + + for (i = 1; i < mcg_num; i++) { + fprintf (stderr, "mcg: [%s]\n", mcg[i]); + inet_pton (AF_INET6, mcg[i], &addr.sin6_addr); + if (udp_ipv6_join_multicast_group (s->udp_fd, s->idx, (struct sockaddr *) &addr) < 0) { + err ("Cannot join multicast group !\n"); + } + + } + signal(SIGTERM, sighandler); + signal(SIGINT, sighandler); + + FILE *f; + time_t first; + time_t last; + int hc, i; + do { + first=last=hc=lost=0; + if(file) { + f=fopen("rawfile.temp", "wb"); + if(f==NULL) { + perror("Cannot open file for writing\n"); + return -1; + } + } else { + f=stdout; + } + while (!quit &&(!wait || !last || ((time(NULL)-last) < wait))) { + len = udp_read (s, buf, sizeof (buf), 50, NULL); + if(len>0) { + if(header) { + if(len!=HDR_CHK_PACKET_LENGTH) { + fprintf(stderr, "Expected header length mismatch %d != %d!\n", len, HDR_CHK_PACKET_LENGTH); + } + uint32_t *cnt=(uint32_t *)buf; + int hv=ntohl(*cnt); + if(hv == hc) { + fwrite (buf+HDR_CHK_LENGTH, len-HDR_CHK_LENGTH, 1, f); + hc++; + } else { + bzero(buf, HDR_CHK_PACKET_LENGTH); + for(i=hc; i<hv; i++) { + fwrite(buf, HDR_CHK_PACKET_LENGTH-HDR_CHK_LENGTH, 1, f); + } + lost+=(hv-hc); + hc=i; + } + } else { + fwrite (buf, len, 1, f); + } + last=time(NULL); + if(!first) { + first=last; + } + } + } + fclose(f); + if(file) { + if(quit) { + unlink("rawfile.temp"); + } else { + struct tm *now=localtime(&first); + char fname[80]; + sprintf(fname, "%04d%02d%02d-%02d%02d%02d.raw", now->tm_year+1900, now->tm_mon+1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec); + rename("rawfile.temp", fname); + fprintf(stderr, "[%s] New log file: %s (%u packets)\n",ifname, fname, hc); + if(lost) { + fprintf(stderr, "Warning: Lost %d frames of %d payload bytes, now filled with padding bytes (0)\n", lost, HDR_CHK_PACKET_LENGTH-HDR_CHK_LENGTH); + } + } + } + } while(loop && ! quit); + udp_close (s); + } + break; + + case 2: + s = server_udp_open_host (mcg[0], port, ifname); + if (s) { + while (1) { + if(!fread (buf, 1316, 1, stdin)) { + break; + } + udp_write (s, buf, 1316); + } + udp_close (s); + } + break; + + case 3: + s = server_udp_open_host (mcg[0], port, ifname); + if (s) { + int i; + for (i = 0; i < sizeof (buf); i++) { + buf[i] = rand (); + } + while (1) { + i = rand (); + udp_write (s, buf, ((i % 4) + 4) * 188); + } + udp_close (s); + } + break; + } + + return 0; +} diff --git a/mcast/tool/netcvupdate.c b/mcast/tool/netcvupdate.c new file mode 100644 index 0000000..e311470 --- /dev/null +++ b/mcast/tool/netcvupdate.c @@ -0,0 +1,773 @@ +/*------------------------------------------------------------------------ + * netcvupdate - NetCeiver update tool + * + * Principle for firmware update + * - Unpack given .tgz into host /tmp/mkdtemp() + * - "md5sum -c md5sums.txt" + * - read script file update.scr + * - feed commands into tnftp + * + * + *------------------------------------------------------------------------*/ +#define USE_MCLI_API + +#ifdef USE_MCLI_API +#include "headers.h" +#else +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <signal.h> +#include <ctype.h> +#endif + +#define STATE_FILE "update.log" +#define FTP_CMD "ftp" +#define NC_CONFPATH "/mmc/etc/" +#define NC_CONFFILE "netceiver.conf" + +char ftp_cmd[512]=FTP_CMD; +int verbose=0; +int no_reboot=0; +char username[256]="root"; +char password[256]="root"; +char device[256]="eth0"; +char *uuids[256]={0}; +char *versions[256]={0}; +int num_uuids=0; +char socket_path[256]=API_SOCK_NAMESPACE; + +#ifdef USE_MCLI_API +/*------------------------------------------------------------------------*/ +#define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; \ + send (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + recv (sock_comm, &sock_cmd, sizeof(api_cmd_t), 0); \ + if (cmd->state == API_ERROR) {warn ( "SHM parameter error, incompatible versions?\n"); exit(-1);}} + +int sock_comm; + +int api_init(char *path) +{ + int sock_name_len = 0; + struct sockaddr_un sock_name; + sock_name.sun_family = AF_UNIX; + + strcpy(sock_name.sun_path, path); + sock_name_len = sizeof(struct sockaddr_un); + + if((sock_comm = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + { + warn ("socket create failure %d\n", errno); + return -1; + } + + if (connect(sock_comm, (struct sockaddr*)&sock_name, sock_name_len) < 0) { + warn ("connect failure to %s: %s (are you root?)\n",path, strerror(errno)); + return -1; + } + return 0; +} +#endif +/*------------------------------------------------------------------------*/ +void add_upload(char* cmd, char* localfile, char *remotepath, char *remotefile) +{ + char tmp[1024]; + sprintf(tmp, + "cd %s\n" + "site exec rm -f /tmp/update/%s\n" + "put %s\n", + remotepath, remotefile, localfile); + strcat(cmd,tmp); +} +/*------------------------------------------------------------------------*/ +void add_download(char* cmd, char *remotepath, char *remotefile) +{ + char tmp[1024]; + sprintf(tmp, + "cd %s\n" + "get %s\n", + remotepath,remotefile); + strcat(cmd,tmp); +} +/*------------------------------------------------------------------------*/ +int script_interpreter(char *script, char *line, + char *ip, char *iface, char *user, char *pwd) +{ + char cmd[256],p1[256],p2[256]; + int end=0; + + *cmd=0; + *p1=0; + *p2=0; + sscanf(line,"%s %s %s\n",cmd,p1,p2); + + if (cmd[0]=='#') + return 0; + if (!strcmp(cmd,"connect")) { + char tmp[1024]; + sprintf(tmp, + "open %s%%%s\n" + "user %s %s\n", + ip,iface,user,pwd); + strcat(script,tmp); + } + else if (!strcmp(cmd,"upload")) { + add_upload(script,p2,p1,p2); + } + else if (!strcmp(cmd,"download")) { + add_download(script,p1,p2); + } + else if (!strcmp(cmd,"exit")) { + strcat(script,"quit\n"); + end=1; + } + else { + strcat(script,line); + } + return end; +} +/*------------------------------------------------------------------------*/ +char script[128*1024]; +int generate_script(char *filename, char *tmpname, char *ip, char *iface, char *user, char *pwd) +{ + FILE *f; + f=fopen(filename,"r"); + if (!f) { + fprintf(stderr,"Can't open script file <%s>: %s\n",filename,strerror(errno)); + return -1; + } + script[0]=0; + + while(!feof(f)) { + char line[256]; + fgets(line,255,f); + if (script_interpreter(script,line,ip,iface,user,pwd)) + break; + } + fclose(f); + return 0; +} +/*------------------------------------------------------------------------*/ +int check_state_file(char *tmpname) +{ + char cmd[512]; + int ret; + printf("\nUPDATE RESULT:\n"); + snprintf(cmd,512,"cat %s/update.log",tmpname); + ret=system(cmd); + printf("\n"); + return ret; +} +/*------------------------------------------------------------------------*/ +void sigground(int x) +{ +} +/*------------------------------------------------------------------------*/ +int run_ftp(char *tmpdir,char *script, int timeout, char *pipeout) +{ + FILE *f; + char cmd[512]; + int ret; + if (!strlen(ftp_cmd)) + return -1; + signal(SIGPIPE,sigground); + if (strlen(tmpdir)) +// snprintf(cmd,511,"cd %s; %s -q %i -n %s",tmpdir,ftp_cmd,timeout,verbose?"":"-V"); + snprintf(cmd,511,"cd %s; %s -n %s %s",tmpdir,ftp_cmd,verbose?"":"-V",pipeout); + else + snprintf(cmd,511,"%s -q %i -n %s %s",ftp_cmd,timeout,verbose?"":"-V",pipeout); + + f=popen(cmd,"w"); + if (!f) + return -1; + fputs(script,f); + ret=pclose(f); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_reboot(char *tmpdir, char *ip, char* iface, char *user, char* pwd) +{ + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "site exec reboot -d 5\n" + "quit\n" + , + ip,iface,user,pwd); + return run_ftp(tmpdir, script, 15,""); +} +/*------------------------------------------------------------------------*/ + +int do_list_fw(char *tmpdir, char *ip, char* iface, char *user, char* pwd, int maxf, int *found, char **versions) +{ + char tmpfile[256]="/tmp/ncvup.XXXXXX"; + char pipeout[256]; + int n=0; + int ret=0; + FILE *file; + + *found=0; + + if (!mkstemp(tmpfile)) { + fprintf(stderr,"Can't make temporary directory %s!\n",tmpfile); + return -2; + } + + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "ls /mmc/\n" + "quit\n" + , + ip,iface,user,pwd); + sprintf(pipeout," > %s",tmpfile); + ret=run_ftp(tmpdir, script, 15, pipeout); + if (ret) { + unlink(tmpfile); + return ret; + } + + file=fopen(tmpfile,"r"); + if (!file) { + unlink(tmpfile); // ? + perror("Can't read temp file"); + return ret; + } + + while(!feof(file)) { + char line[1024]; + char *p; + *line=0; + fgets(line, 1023,file); + line[1023]=0; + p=strstr(line,"etceivr."); + if (p) { + + char *pp=strchr(p,'\n'); + if (pp) + *pp=0; + + if (n < maxf) { + n++; + *versions++=strdup(p-1); + } + } + } + *found=n; + fclose(file); + unlink(tmpfile); + return 0; +} +/*------------------------------------------------------------------------*/ +int do_kill(char *tmpdir, char *ip, char* iface, char *user, char* pwd) +{ + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "site exec killall -9 mserv\n" + "quit\n" + , + ip,iface,user,pwd); + return run_ftp(tmpdir, script, 15,""); +} +/*------------------------------------------------------------------------*/ +int do_single_update(char *tmpdir, char *uuid, char *device) +{ + char path[256]; + int ret; + + snprintf(path,255,"%s/%s",tmpdir,"update.scr"); + if (generate_script(path, tmpdir, uuid, device, username, password)) + return -1; +// puts(script); + + printf("Upload update... "); + fflush(stdout); + + ret=run_ftp(tmpdir, script, 600,""); + if (ret) + return ret; + + printf("check result... \n"); + fflush(stdout); + + if (check_state_file(tmpdir)) + return -1; + +#if 1 + if (!no_reboot) { + printf("Issue Reboot... "); + fflush(stdout); + ret=do_reboot(tmpdir, uuid, device, username, password); + if (!ret) + return ret; + } +#endif + return 0; +} +/*------------------------------------------------------------------------*/ +int do_single_upload( char *uuid, char *device, char *remote_path, char *fname, char *remote_file) +{ + int ret; + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd %s\n" + "put %s %s\n" +// "site exec killall -HUP mserv\n" + "quit", + uuid,device,username,password,remote_path,fname,remote_file); + ret=run_ftp("", script, 120,""); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_single_download( char *uuid, char *device, char *remote_path, char *fname) +{ + int ret; + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd %s\n" + "get %s\n" + "quit", + uuid,device,username,password,remote_path,fname); + ret=run_ftp("", script, 120,""); + return ret; +} +/*------------------------------------------------------------------------*/ +int fw_action(char *uuid, char* iface, char *user, char* pwd, int mode, char *version) +{ + int ret; + if (mode==0) { // inactivate + printf("Inactivating version %s\n",version); + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd /mmc\n" + "rename netceivr.%s xetceivr.%s\n" + "quit", + uuid,device,username,password,version,version); + ret=run_ftp("", script, 120,""); + return ret; + } + else if (mode==1) { // enable + printf("Enabling version %s\n",version); + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "cd /mmc\n" + "rename xetceivr.%s netceivr.%s\n" + "quit", + uuid,device,username,password,version,version); + ret=run_ftp("", script, 120,""); + return ret; + } + else if (mode==2) { // delete + printf("Removing version %s\n",version); + sprintf(script, + "open %s%%%s\n" + "user %s %s\n" + "site exec rm -rf /mmc/netceivr.%s\n" + "site exec rm -rf /mmc/xetceivr.%s\n" + "quit", + uuid,device,username,password,version,version); + ret=run_ftp("", script, 120,""); + return ret; + } + return 0; +} +/*------------------------------------------------------------------------*/ +int cleanup(char *tmpdir) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"rm -rf '%s'",tmpdir); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int unpack(char *tmpdir, char *file) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"tar xfz '%s' --directory %s",file,tmpdir); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int check_xml(char *file) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"xmllint --noout '%s'\n",file); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int check_integrity(char *tmpdir) +{ + int ret; + char cmd[1024]; + snprintf(cmd,1024,"cd %s; md5sum -c --status md5sums.txt \n",tmpdir); +// puts(cmd); + ret=system(cmd); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_update(char **uuids, int num_uuids, char *device, char *optarg) +{ + char tmpdir[256]="/tmp/ncvupXXXXXX"; + int n; + int ret=0; + if (!mkdtemp(tmpdir)) { + fprintf(stderr,"Can't make temporary directory %s!\n",tmpdir); + return -2; + } +// printf("TEMP DIR %s\n",tmpdir); + if (unpack(tmpdir,optarg)) { + fprintf(stderr,"Update file <%s> cannot be unpacked!\n",optarg); + cleanup(tmpdir); + return -2; + } + if (check_integrity(tmpdir)) { + fprintf(stderr,"Update file <%s> corrupted!\n",optarg); + cleanup(tmpdir); + return -2; + } + printf("Update file integrity OK\n"); + printf("NUM uuids %i\n",num_uuids); + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + + printf("UUID %s: ",uuids[n]); + fflush(stdout); + ret=do_single_update(tmpdir, uuids[n], device); + if (!ret) + printf("-> Update done <-\n"); + else { + printf("-> Update failed (ret=%i) <-\n",ret); + uuids[n]=NULL; + } + } + + cleanup(tmpdir); + return ret; +} +/*------------------------------------------------------------------------*/ +int do_upload(char **uuids, int num_uuids, char *device, char *optarg) +{ + int n; + int ret=0; + if (check_xml(optarg)) { + fprintf(stderr,"Configuration file <%s> not valid XML\n",optarg); + return -2; + } + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + + printf("UUID %s: Uploading %s ... ",uuids[n], optarg); + fflush(stdout); + ret=do_single_upload(uuids[n], device, "/mmc/etc/", optarg, NC_CONFFILE); + if (!ret) + printf("Upload done\n"); + else { + printf("Upload failed (ret=%i)\n",ret); + uuids[n]=NULL; + } + } + return ret; +} +/*------------------------------------------------------------------------*/ +int do_download(char **uuids, int num_uuids, char *device, char *remotepath, char *file) +{ + int n,ret=0; + + for(n=0;n<num_uuids;n++) { + char newfile[1024]; + if (!uuids[n]) + continue; + + if (num_uuids!=1) + snprintf(newfile,1024,"%s-%s",file,uuids[n]); + else + strncpy(newfile,file,1024); + + printf("UUID %s: Downloading %s ... ",uuids[n], newfile); + fflush(stdout); + ret=do_single_download(uuids[n], device, remotepath, file); + if (!ret) { + printf("Done\n"); + if (num_uuids!=1) + rename(file,newfile); + } + else { + printf("Download failed (ret=%i)\n",ret); + uuids[n]=NULL; + } + } + return ret; +} +/*------------------------------------------------------------------------*/ +int do_all_reboot(char **uuids, int num_uuids, char *device) +{ + int n,ret=0; + + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + printf("UUID %s: Issue Reboot... ",uuids[n]); + fflush(stdout); + ret=do_reboot("/tmp", uuids[n], device, username, password); + if (!ret) + printf("Reboot done\n"); + else + printf("Reboot failed (ret=%i)\n",ret); + } + return ret; +} +/*------------------------------------------------------------------------*/ +int do_all_kill(char **uuids, int num_uuids, char *device) +{ + int n,ret=0; + + for(n=0;n<num_uuids;n++) { + if (!uuids[n]) + continue; + printf("UUID %s: Issue Kill... ",uuids[n]); + fflush(stdout); + ret=do_kill("/tmp", uuids[n], device, username, password); + if (!ret) + printf("Kill done\n"); + else + printf("Kill failed (ret=%i)\n",ret); + } + return ret; +} +/*------------------------------------------------------------------------*/ +int get_uuids(char **uuids, int max) +{ + int count,n; + api_cmd_t sock_cmd; + api_cmd_t *api_cmd=&sock_cmd; + + if (api_init(socket_path)==-1) { + exit(-1); + } + api_cmd->cmd=API_GET_NC_NUM; + api_cmd->magic = MCLI_MAGIC; + api_cmd->version = MCLI_VERSION; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->magic != MCLI_MAGIC || api_cmd->version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + count=api_cmd->parm[API_PARM_NC_NUM]; + + for(n=0;n<max && n<count;n++) { + api_cmd->cmd=API_GET_NC_INFO; + api_cmd->parm[API_PARM_NC_NUM]=n; + API_WAIT_RESPONSE(api_cmd); + if(api_cmd->u.nc_info.magic != MCLI_MAGIC || api_cmd->u.nc_info.version != MCLI_VERSION) { + err("API version mismatch!\n"); + } + + uuids[n]=strdup(api_cmd->u.nc_info.uuid); + versions[n]=strdup(api_cmd->u.nc_info.FirmwareVersion); + } + return count; +} +/*------------------------------------------------------------------------*/ +int show_uuids(void) +{ + char *uuids[256]={0}; + int num_uuids,n; + num_uuids=get_uuids(uuids,256); + for(n=0;n<num_uuids;n++) { + printf("%s %s\n",uuids[n],versions[n]); + } + return 0; +} +/*------------------------------------------------------------------------*/ +#define MAX_FWS 64 +void show_firmwares(char *uuid, char *device, char *username, char *passwd) +{ + char *fwversions[MAX_FWS]; + int found,m; + found=0; + + do_list_fw("/tmp", uuid, device, username, password, MAX_FWS, &found, fwversions); + + printf("Firmware versions found: %i\n Versions: ", found); + for(m=0;m<found;m++) { + if (m!=0) printf(", "); + if (fwversions[m][0]!='n') + printf("%s (disabled)",fwversions[m]+9); + else + printf("%s",fwversions[m]+9); + + free(versions[m]); + } + puts(""); +} +/*------------------------------------------------------------------------*/ + +int show_all_firmwares(char **uuids, int num_uuids) +{ + int n; + + for(n=0;n<num_uuids;n++) { + printf("%s: ",uuids[n]); + fflush(stdout); + show_firmwares(uuids[n],device,username,password); + } + return 0; +} +/*------------------------------------------------------------------------*/ +void do_fw_actions(char **uuids, int max, int mode, char *version) +{ + int n; + + if (strlen(version)!=3 || !strcmp(version,"000")) { + fprintf(stderr,"Invalid version number\n"); + return; + } + + for(n=0;n<3;n++) + version[n]=toupper(version[n]); + + for(n=0;n<max;n++) { + printf("UUID %s\n",uuids[n]); + if (fw_action(uuids[n], device, username, password, mode, version)) { + fprintf(stderr,"Failed\n"); + return; + } + show_firmwares(uuids[n],device,username,password); + } +} +/*------------------------------------------------------------------------*/ +void usage(void) +{ + fprintf(stderr, + "netcvupdate - NetCeiver update tool, version " MCLI_VERSION_STR "\n" + "(c) BayCom GmbH\n" + "Usage: netcvupdate <options> <actions> \n" + "Actions: \n" + " -l List all seen NetCeivers and their UUID\n" + " -L List available FWs\n" + " -X <Update.tgz> Update with given file\n" + " -U <configfile> Upload configfile\n" + " -D Download configfile netceiver.conf\n" + " -I <version> Inactivate FW version\n" + " -E <version> Enable FW version\n" + " -Z <version> Remove FW version\n" + " -K Restart streaming server\n" + " -R Issue reboot\n" + "Options:\n" + " -A Use all found NetCeivers (mcli must be running)\n" + " -i <uuid> Use specific UUID (can be used multiple times)\n" + " *** Either -A or -i must be given for most actions! ***\n" + "Rare options:\n" + " -d <device> Set network device (default: eth0)\n" + " -F <ftp-command> Set ftp command/path\n" + " *** ftp command must understand the -q (timeout) option! ***\n" + " -P <path> Set API socket\n" + " -u <user> Set username\n" + " -p <password> Set password\n" + " -r No reboot after update\n" + " -q Be more quiet\n" + ); + exit(0); +} +/*------------------------------------------------------------------------*/ +int main(int argc, char **argv) +{ + int ret=0; + + while(1) { + int ret = getopt(argc,argv, "U:X:Di:AlLI:E:Z:d:F:P:u:p:rRqK"); + if (ret==-1) + break; + + char c=(char)ret; + + switch(c) { + case 'F': + strncpy(ftp_cmd,optarg,512); + ftp_cmd[511]=0; + break; + case 'X': + ret=do_update(uuids, num_uuids, device, optarg); + if (ret==-2) + exit(ret); + break; + case 'U': + ret=do_upload(uuids, num_uuids, device, optarg); + if (ret==-2) + exit(ret); + break; + case 'D': + ret|=do_download(uuids, num_uuids, device, NC_CONFPATH, NC_CONFFILE); + break; + case 'i': + uuids[num_uuids]=strdup(optarg); + num_uuids++; + break; + case 'A': + num_uuids=get_uuids(uuids,255); + break; + case 'l': + show_uuids(); + break; + case 'd': + strncpy(device,optarg,255); + device[255]=0; + break; + case 'P': + strncpy(socket_path,optarg,255); + socket_path[255]=0; + break; + case 'p': + strncpy(password,optarg,255); + password[255]=0; + break; + case 'u': + strncpy(username,optarg,255); + username[255]=0; + break; + case 'r': + no_reboot=1; + break; + case 'K': + ret|=do_all_kill(uuids,num_uuids,device); + break; + case 'R': + ret|=do_all_reboot(uuids, num_uuids, device); + break; + case 'L': + show_all_firmwares(uuids, num_uuids); + break; + case 'I': + do_fw_actions(uuids, num_uuids, 0, optarg); + break; + case 'E': + do_fw_actions(uuids, num_uuids, 1, optarg); + break; + case 'Z': + do_fw_actions(uuids, num_uuids, 2, optarg); + break; + case 'q': + verbose=0; + break; + default: + usage(); + break; + } + } + exit(ret); +} diff --git a/mcast/tool/tools.c b/mcast/tool/tools.c new file mode 120000 index 0000000..71f8bc6 --- /dev/null +++ b/mcast/tool/tools.c @@ -0,0 +1 @@ +../common/tools.c
\ No newline at end of file |