Projects
Multimedia
vdr-plugin-mcli
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
vdr-plugin-mcli.spec
Changed
@@ -1,11 +1,13 @@ # # spec file for package vdr-plugin-mcli # +# svn co https://svn.baycom.de/repos/vdr-mcli-plugin/ +# tar cj --exclude=.svn -f vdr-mcli-plugin.tar.bz2 vdr-mcli-plugin # # norootforbuild -%define pluginversion 0.9.1 +%define pluginversion 0.9.186 %define pluginname mcli %define pluginurl http://www.baycom.de # @@ -16,7 +18,7 @@ Name: vdr-plugin-mcli Version: %pkgversion -Release: 2 +Release: 0 Source: %plugintarball Source1: sysconfig.vdr-mcli BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -119,6 +121,8 @@ %changelog +* Fri Aug 19 2011 Manfred Tremmel <Manfred.Tremmel@iiv.de> - 0.9.186-0.pm.0 +- update to svn 186 * Sun Jan 16 2011 Manfred Tremmel <Manfred.Tremmel@iiv.de> - 0.9.1-2.pm.0 - update to svn 176 * Sun Jun 20 2010 Manfred Tremmel <Manfred.Tremmel@iiv.de> - 0.9.1-0.pm.3
View file
vdr-mcli-plugin.tar.bz2/README
Changed
@@ -50,4 +50,11 @@ this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +To properly integrate the mcli plugin into your VDR please apply these two +patches: + +vdr-1.6.0-altmenuaction.patch (allows CAM messages to be displayed) +vdr-1.6.0-intcamdevices.patch (enables selection of encrypted channels + without local CI stack). \ No newline at end of file
View file
vdr-mcli-plugin.tar.bz2/device.c
Changed
@@ -89,6 +89,10 @@ DELETENULL (m_PB); } +bool cMcliDevice::Ready() { + return m_mcli ? m_mcli->Ready() : false; +} + void cMcliDevice::SetTenData (tra_t * ten) { if(!ten->lastseen) {
View file
vdr-mcli-plugin.tar.bz2/device.h
Changed
@@ -71,6 +71,7 @@ cMcliFilters *m_filters; cMcliDevice (void); virtual ~ cMcliDevice (); + virtual bool Ready(); void SetMcliRef(cPluginMcli *m) { m_mcli=m;
View file
vdr-mcli-plugin.tar.bz2/mcast/client/api_shm_test.c
Changed
@@ -1,127 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#include "headers.h" - - -int main (int argc, char **argv) -{ -#ifdef USE_SHM_API - #define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; while (cmd->state == API_REQUEST) usleep(10*1000); if (cmd->state == API_ERROR) warn ("SHM parameter error\n");} - - int fd = shm_open (API_SHM_NAMESPACE, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); - if (fd == -1 ) { - warn ("Cannot get a shared memory handle\n"); - return -1; - } - - if (ftruncate (fd, sizeof(api_cmd_t)) == -1) { - err ("Cannot truncate shared memory\n"); - } - - api_cmd_t *api_cmd = mmap(NULL, sizeof(api_cmd_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if ( api_cmd == MAP_FAILED ) { - err ("MMap of shared memory region failed\n"); - } - close(fd); -#endif -#ifdef USE_SOCK_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\n");} - - int sock_comm; - int sock_name_len = 0; - struct sockaddr_un sock_name; - api_cmd_t sock_cmd; - api_cmd_t *api_cmd=&sock_cmd; - sock_name.sun_family = AF_UNIX; - - strcpy(sock_name.sun_path, API_SOCK_NAMESPACE); - sock_name_len = strlen(API_SOCK_NAMESPACE) + sizeof(sock_name.sun_family); - - if((sock_comm = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { - warn ("socket create failure %d\n", errno); - return -1; - } - - if (connect(sock_comm, &sock_name, sock_name_len) < 0) { - err ("connect failure\n"); - } -#endif - api_cmd->cmd=API_GET_NC_NUM; - API_WAIT_RESPONSE(api_cmd); - - printf("nc_num: %d\n", api_cmd->parm[API_PARM_NC_NUM]); - int nc_num=api_cmd->parm[API_PARM_NC_NUM]; - int i; - 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); - printf("nc_info.uuid: %s nc_info.lastseen: %u nc_info.tuner_num: %d\n", api_cmd->u.nc_info.uuid, (unsigned int) api_cmd->u.nc_info.lastseen, api_cmd->u.nc_info.tuner_num); - 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_info.fe_info.name: %s SatList: %s\n",api_cmd->u.tuner_info.fe_info.name, api_cmd->u.tuner_info.SatelliteListName); - } - - - int sat_list_num=api_cmd->u.nc_info.sat_list_num; - 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); - - printf("sat_list_info.Name: %s sat_list_info.sat_num: %d\n", 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); - printf("sat_info.Name: %s\n",api_cmd->u.sat_info.Name); - int comp_num=api_cmd->u.sat_info.comp_num; - 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); - printf("sat_comp.Polarisation: %d sat_comp.RangeMin: %d sat_comp.RangeMax: %d sat_comp.LOF: %d\n", api_cmd->u.sat_comp.Polarisation, api_cmd->u.sat_comp.RangeMin, api_cmd->u.sat_comp.RangeMax, api_cmd->u.sat_comp.LOF); - } - } - } - } - - while (1) { - api_cmd->cmd=API_GET_TRA_NUM; - 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++) { - 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); - - printf("tra.slot:%d tra.fe_type: %d tra.InUse: % 3d tra.mcg: %s tra.uuid: %s tra.lastseen: %u tra.lock:%d tra.strength:%d tra.snr:%d tra.ber:%d\n", api_cmd->u.tra.slot, api_cmd->u.tra.fe_type, api_cmd->u.tra.InUse, host, api_cmd->u.tra.uuid, (unsigned int) api_cmd->u.tra.lastseen, api_cmd->u.tra.s.st, api_cmd->u.tra.s.strength, api_cmd->u.tra.s.snr, api_cmd->u.tra.s.ber); - } - sleep(2); - } - return 0; -} - +(symlink to api_test.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/api_sock_test.c
Changed
@@ -1,127 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#include "headers.h" - - -int main (int argc, char **argv) -{ -#ifdef USE_SHM_API - #define API_WAIT_RESPONSE(cmd) { cmd->state=API_REQUEST; while (cmd->state == API_REQUEST) usleep(10*1000); if (cmd->state == API_ERROR) warn ("SHM parameter error\n");} - - int fd = shm_open (API_SHM_NAMESPACE, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); - if (fd == -1 ) { - warn ("Cannot get a shared memory handle\n"); - return -1; - } - - if (ftruncate (fd, sizeof(api_cmd_t)) == -1) { - err ("Cannot truncate shared memory\n"); - } - - api_cmd_t *api_cmd = mmap(NULL, sizeof(api_cmd_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if ( api_cmd == MAP_FAILED ) { - err ("MMap of shared memory region failed\n"); - } - close(fd); -#endif -#ifdef USE_SOCK_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\n");} - - int sock_comm; - int sock_name_len = 0; - struct sockaddr_un sock_name; - api_cmd_t sock_cmd; - api_cmd_t *api_cmd=&sock_cmd; - sock_name.sun_family = AF_UNIX; - - strcpy(sock_name.sun_path, API_SOCK_NAMESPACE); - sock_name_len = strlen(API_SOCK_NAMESPACE) + sizeof(sock_name.sun_family); - - if((sock_comm = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { - warn ("socket create failure %d\n", errno); - return -1; - } - - if (connect(sock_comm, &sock_name, sock_name_len) < 0) { - err ("connect failure\n"); - } -#endif - api_cmd->cmd=API_GET_NC_NUM; - API_WAIT_RESPONSE(api_cmd); - - printf("nc_num: %d\n", api_cmd->parm[API_PARM_NC_NUM]); - int nc_num=api_cmd->parm[API_PARM_NC_NUM]; - int i; - 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); - printf("nc_info.uuid: %s nc_info.lastseen: %u nc_info.tuner_num: %d\n", api_cmd->u.nc_info.uuid, (unsigned int) api_cmd->u.nc_info.lastseen, api_cmd->u.nc_info.tuner_num); - 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_info.fe_info.name: %s SatList: %s\n",api_cmd->u.tuner_info.fe_info.name, api_cmd->u.tuner_info.SatelliteListName); - } - - - int sat_list_num=api_cmd->u.nc_info.sat_list_num; - 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); - - printf("sat_list_info.Name: %s sat_list_info.sat_num: %d\n", 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); - printf("sat_info.Name: %s\n",api_cmd->u.sat_info.Name); - int comp_num=api_cmd->u.sat_info.comp_num; - 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); - printf("sat_comp.Polarisation: %d sat_comp.RangeMin: %d sat_comp.RangeMax: %d sat_comp.LOF: %d\n", api_cmd->u.sat_comp.Polarisation, api_cmd->u.sat_comp.RangeMin, api_cmd->u.sat_comp.RangeMax, api_cmd->u.sat_comp.LOF); - } - } - } - } - - while (1) { - api_cmd->cmd=API_GET_TRA_NUM; - 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++) { - 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); - - printf("tra.slot:%d tra.fe_type: %d tra.InUse: % 3d tra.mcg: %s tra.uuid: %s tra.lastseen: %u tra.lock:%d tra.strength:%d tra.snr:%d tra.ber:%d\n", api_cmd->u.tra.slot, api_cmd->u.tra.fe_type, api_cmd->u.tra.InUse, host, api_cmd->u.tra.uuid, (unsigned int) api_cmd->u.tra.lastseen, api_cmd->u.tra.s.st, api_cmd->u.tra.s.strength, api_cmd->u.tra.s.snr, api_cmd->u.tra.s.ber); - } - sleep(2); - } - return 0; -} - +(symlink to api_test.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/ci_handler.c
Changed
@@ -121,7 +121,11 @@ pthread_cleanup_push (clean_ci_recv_thread, c); c->rxdata = (u_int8_t *) malloc (CA_TPDU_MAX + 2); + if (!c->rxdata) + err ("ci_recv: out of memory\n"); c->txdata = (u_int8_t *) malloc (CA_TPDU_MAX + 2); + if (!c->txdata) + err ("ci_recv: out of memory\n"); if (c->rxdata && c->txdata) { c->recv_run = 1; @@ -201,7 +205,8 @@ static ci_dev_t *ci_add (void) { ci_dev_t *c = (ci_dev_t *) malloc (sizeof (ci_dev_t)); - + if (!c) + return NULL; memset (c, 0, sizeof (ci_dev_t)); dvbmc_list_add_head (&devs.list, &c->list); return c;
View file
vdr-mcli-plugin.tar.bz2/mcast/client/ciparser.c
Changed
@@ -1,691 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -//#define TESTING -#ifdef TESTING -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <netinet/in.h> -#include <stdlib.h> - -#include "ciparser.h" -static unsigned char ll[] = { 0x00, 0x01, 0xA0, 0x28, 0x01, 0x90, 0x02, 0x00, 0x05, 0x9F, 0x80, 0x32, 0x1F, 0x03, 0x32, 0xC9, 0x01, 0x00, 0x0F, 0x01, 0x09, 0x06, 0x17, 0x62, 0xE0, 0x65, 0x00, 0x09, 0x09, 0x04, 0x17, 0x02, 0xE1, 0x2D, 0x02, 0x00, 0xA0, 0x00, 0x00, 0x04, 0x00, 0xA1, 0x00, 0x00 }; -static unsigned char lr[] = { 0x00, 0x01, 0x80, 0x02, 0x01, 0x80 }; -static unsigned char la[] = { 0x00, 0x01, 0xA0, 0x07, 0x01, 0x91, 0x04, 0x00, 0x01, 0x00, 0x41, 0x80, 0x02, 0x01, 0x00 }; -static unsigned char lb[] = { 0x00, 0x01, 0xA0, 0x82, 0x00, 0x17, 0x01, 0x90, 0x02, 0x00, 0x03, 0x9F, 0x80, 0x31, 0x0E, 0x06, 0x02, 0x06, 0x02, 0x17, 0x02, 0x17, 0x62, 0x01, 0x00, 0x05, 0x00, 0x18, 0x00, 0x80, 0x02, 0x01, 0x00 }; -static unsigned char lc[] = { 0x01, 0x02, 0xA0, 0x5F, 0x02, 0x90, 0x02, 0x00, 0x06, 0x9F, 0x80, 0x32, 0x56, 0x03, 0x03, 0x8B, 0x01, 0x00, 0x00, 0x02, 0x00, 0xA3, 0x00, 0x23, 0x01, 0x09, 0x0F, 0x05, 0x00, 0xE2, 0xC3, 0x10, 0x01, 0x00, 0x13, 0x01, 0x20, 0x14, 0x03, 0x00, 0x94, 0x0D, 0x09, 0x0F, 0x05, 0x00, 0xE2, 0xCD, 0x10, 0x01, 0x00, 0x13, 0x01, 0x20, 0x14, 0x03, 0x02, 0x38, 0x08, 0x04, 0x00, 0x5C, 0x00, 0x23, 0x01, 0x09, 0x0F, 0x05, 0x00, 0xE2, 0xC3, 0x10, 0x01, 0x00, 0x13, 0x01, 0x20, 0x14, 0x03, 0x00, 0x94, 0x0D, 0x09, 0x0F, 0x05, 0x00, 0xE2, 0xCD, 0x10, 0x01, 0x00, 0x13, 0x01, 0x20, 0x14, 0x03, 0x02, 0x38, 0x08 }; -static unsigned char ld[] = { 0x00, 0x01, 0xA0, 0x82, 0x00, 0x10, 0x01, 0x90, 0x02, 0x00, 0x03, 0x9F, 0x80, 0x33, 0x07, 0x2D, 0xB9, 0x01, 0x81, 0x00, 0x08, 0x00, 0x80, 0x02, 0x01, 0x00 }; -static unsigned char le[] = { 0x00, 0x01, 0xA0, 0x34, 0x01, 0x90, 0x02, 0x00, 0x03, 0x9F, 0x80, 0x32, 0x2B, 0x03, 0x00, 0x0B, 0x01, 0x00, 0x11, 0x01, 0x09, 0x06, 0x17, 0x22, 0xF0, 0x0B, 0x00, 0x0B, 0x09, 0x06, 0x17, 0x02, 0xF0, 0x0B, 0x00, 0x0B, 0x02, 0x06, 0xFF, 0x00, 0x00, 0x04, 0x07, 0x00, 0x00, 0x00, 0x04, 0x07, 0x01, 0x00, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00}; - -#define dbg(format, arg...) printf("%s:%d " format , __FILE__ , __LINE__ , ## arg) -#define err(format, arg...) {printf("err:%s:%d: %s (%d): " format , __FILE__ , __LINE__ ,strerror(errno), errno, ## arg);print_trace();abort();} -#define info(format, arg...) printf("%s:%d: " format , __FILE__ , __LINE__ ,## arg) -#define warn(format, arg...) printf("%s:%d: " format , __FILE__ , __LINE__ ,## arg) -#define STATIC -#else -//#define DEBUG -#include "headers.h" -#endif - -#define CA_MAX_CAIDS 16 -#define CA_MAX_PIDS 16 -#ifndef CA_MAX_SLOTS -#define CA_MAX_SLOTS 3 -#endif -typedef struct -{ - u_int16_t caid[CA_MAX_CAIDS]; - u_int16_t pid[CA_MAX_PIDS]; - u_int16_t capid[CA_MAX_PIDS]; -} caid_pid_list_t; - -static caid_pid_list_t cpl[CA_MAX_SLOTS]; - -STATIC void dump(u_int8_t *data, int len) -{ -#ifdef DEBUG - int j; - printf("Dump: "); - for(j=0;j<len;j++) { - printf("%02x ",data[j]); - } - printf("\n"); -#endif -} - -STATIC int ci_cpl_find_pid (int slot, int pid) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - int i; - for (i = 0; i < CA_MAX_PIDS; i++) { - if (pid == cpl[slot].pid[i]) - return 1; - } - return 0; -} - -STATIC int ci_cpl_find_caid (int slot, int caid) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - int i; - for (i = 0; i < CA_MAX_CAIDS; i++) { - if (caid == cpl[slot].caid[i]) - return 1; - } - return 0; -} - -STATIC int ci_cpl_find_capid (int slot, int pid) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - int i; - for (i = 0; i < CA_MAX_PIDS; i++) { - if (pid == cpl[slot].capid[i]) - return 1; - } - return 0; -} - -STATIC int ci_cpl_delete_pid (int slot, int pid) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - int i; - for (i = 0; i < CA_MAX_PIDS; i++) { - if (cpl[slot].pid[i]==pid) { - cpl[slot].pid[i] = 0; - dbg ("-------> Slot: %d Deleted pid: %04x\n", slot, pid); - return 1; - } - } - return 0; -} - -STATIC int ci_cpl_update_pid (int slot, int pid) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - if (!ci_cpl_find_pid (slot, pid)) { - int i; - for (i = 0; i < CA_MAX_PIDS; i++) { - if (!cpl[slot].pid[i]) { - cpl[slot].pid[i] = pid; - dbg ("-------> Slot: %d Added pid: %04x\n", slot, pid); - return 1; - } - } - } - return 0; -} - -STATIC int ci_cpl_update_caid (int slot, int caid) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - if (!ci_cpl_find_caid (slot, caid)) { - int i; - for (i = 0; i < CA_MAX_CAIDS; i++) { - if (!cpl[slot].caid[i]) { - cpl[slot].caid[i] = caid; - dbg ("-------> Slot: %d Added caid: %04x\n", slot, caid); - return 1; - } - } - } - return 0; -} - -STATIC int ci_cpl_update_capid (int slot, int capid) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - if (!ci_cpl_find_capid (slot, capid)) { - int i; - for (i = 0; i < CA_MAX_PIDS; i++) { - if (!cpl[slot].capid[i]) { - cpl[slot].capid[i] = capid; - dbg ("-------> Slot: %d Added capid: %04x\n", slot, capid); - return 1; - } - } - } - return 0; -} - -int ci_cpl_find_caid_by_pid (int pid) -{ - int i; - int slot; - - if(!pid) { - return 0; - } - for (slot = 0; slot < CA_MAX_SLOTS; slot++) { - for (i = 0; i < CA_MAX_PIDS; i++) { - if (pid == cpl[slot].pid[i]) { - return cpl[slot].caid[0]; - } - } - } - return 0; -} - -int ci_cpl_find_slot_by_caid_and_pid (int caid, int pid) -{ - int slot; - for (slot = 0; slot < CA_MAX_SLOTS; slot++) { - if (ci_cpl_find_pid (slot, pid) && ci_cpl_find_caid (slot, caid)) { - return slot; - } - } - return -1; -} - -int ci_cpl_clear (int slot) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - memset (&cpl[slot], 0, sizeof (caid_pid_list_t)); - return 0; -} - -int ci_cpl_clear_pids (int slot) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - memset (cpl[slot].pid, 0, sizeof (u_int16_t) * CA_MAX_PIDS); - return 0; -} - -int ci_cpl_clear_caids (int slot) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - memset (cpl[slot].caid, 0, sizeof (u_int16_t) * CA_MAX_CAIDS); - return 0; -} - -int ci_cpl_clear_capids (int slot) -{ - if (slot < 0 || slot >= CA_MAX_SLOTS) { - return -1; - } - memset (cpl[slot].capid, 0, sizeof (u_int16_t) * CA_MAX_PIDS); - return 0; -} - -STATIC int ci_decode_length (unsigned int *len, u_int8_t * v) -{ - int ret = 0; - - if (*v & LENGTH_SIZE_INDICATOR) { - int l = *v & 0x7f; - if (l > 4) { - return -1; - } - ret = l + 1; - *len = 0; - while (l--) { - v++; - *len <<= 8; - *len |= *v; - } - } else { - *len = *v; - ret = 1; - } - return ret; -} - -STATIC int ci_decode_al_ca_info (ci_al_t * al) -{ - int i = 0; - u_int8_t *data = al->data; - int len = al->length; - - if (len & 1) { - dbg ("ci_decode_al_ca_info: invalid length %d\n", len); - } - - len >>= 1; - - u_int16_t *caid = (u_int16_t *) malloc (sizeof (u_int16_t) * len); - ci_cpl_clear_caids (al->sl->tl->ll->slot); - while (i < len) { - caid[i++] = ntohs16 (data); - data += 2; - ci_cpl_update_caid (al->sl->tl->ll->slot, caid[i - 1]); - dbg ("CAID[%d]: %04x\n", i - 1, caid[i - 1]); - } - if (caid) { - free (caid); - } - return data - al->data; -} - -STATIC int ca_decode_ca_descr (ca_desc_t ** cadescr, int count, u_int8_t * data, int len, int *magic) -{ - *cadescr = (ca_desc_t *) realloc (*cadescr, sizeof (ca_desc_t *) * (count + 1)); - ca_desc_t *c = *cadescr + count; - -// u_int8_t descriptor_tag = *data; - data++; - u_int8_t descriptor_length = *data; - data++; - c->ca_id = ntohs16 (data); - data += 2; - c->ca_pid = ntohs16 (data); - data += 2; - dbg ("cadescr: %p %d ca_id: %04x ca_pid: %04x\n", cadescr, count, c->ca_id, c->ca_pid); - if(magic && c->ca_id > 0 && c->ca_id < 3 && c->ca_pid > 0 && c->ca_pid < 3 && c->ca_id == c->ca_pid){ - *magic = c->ca_id; - } - return descriptor_length + 2; -} - - -STATIC int ci_decode_al_ca_pmt (ci_al_t * al) -{ - ca_pmt_t p; - int magic = 0; - int slot = 0; - int cleared = 0; - - memset (&p, 0, sizeof (ca_pmt_t)); - - int ret; - u_int8_t *data = al->data; - int len; - - p.ca_pmt_list_management = *data; - data++; - - p.program_number = ntohs16 (data); - data += 2; - - p.version_number = *data; - data++; - - p.program_info_length = (u_int16_t) ntohs16 (data); - data += 2; - - dbg ("ci_decode_al_ca_pmt: ca_pmt_list_management:%02x program_number:%04x version_number:%02x program_info_length:%04x\n", p.ca_pmt_list_management, p.program_number, p.version_number, p.program_info_length); - if (p.program_info_length) { - int ca_descr_count = 0; - len = p.program_info_length - 1; - p.ca_pmt_cmd_id = *data; - dbg ("p.ca_pmt_cmd_id:%02x\n", p.ca_pmt_cmd_id); - data++; - while (len>0) { - ret = ca_decode_ca_descr (&p.cadescr, ca_descr_count, data, len, &magic); - if (magic) - slot = magic - 1; - else - slot = al->sl->tl->ll->slot; - if (!cleared) { - if(p.ca_pmt_list_management == CPLM_ONLY || p.ca_pmt_list_management == CPLM_FIRST || p.ca_pmt_list_management == CPLM_UPDATE) { - ci_cpl_clear_pids(slot); - ci_cpl_clear_capids(slot); - ci_cpl_clear_caids(slot); - cleared = 1; - } - } - if (ret < 0) { - warn ("error decoding ca_descriptor\n"); - break; - } - if((magic != p.cadescr[ca_descr_count].ca_id) || (magic != p.cadescr[ca_descr_count].ca_pid)){ - ci_cpl_update_caid (slot, p.cadescr[ca_descr_count].ca_id); - ci_cpl_update_capid (slot, p.cadescr[ca_descr_count].ca_pid); - } - ca_descr_count++; - data += ret; - len -= ret; - } - if (p.cadescr) { - free (p.cadescr); - } - } - - len = al->length - (data - al->data); - int pidn = 0; - - while (len>0) { - p.pidinfo = (pidinfo_t *) realloc (p.pidinfo, sizeof (pidinfo_t) * (pidn + 1)); - memset (&p.pidinfo[pidn], 0, sizeof (pidinfo_t)); - p.pidinfo[pidn].stream_type = *data; - data++; - len--; - p.pidinfo[pidn].pid = ntohs16 (data); - data += 2; - len -= 2; - p.pidinfo[pidn].es_info_length = ntohs16 (data); - data += 2; - len -= 2; - - dbg ("len: %d count: %d, stream_type: %02x, pid: %04x es_info_length: %04x\n", len, pidn, p.pidinfo[pidn].stream_type, p.pidinfo[pidn].pid, p.pidinfo[pidn].es_info_length); - if (p.pidinfo[pidn].es_info_length) { - int pi_len = p.pidinfo[pidn].es_info_length - 1; - p.pidinfo[pidn].ca_pmt_cmd_id = *data; - data++; - len--; - int pid_ca_descr_count = 0; - while (pi_len>0) { - ret = ca_decode_ca_descr (&p.pidinfo[pidn].cadescr, pid_ca_descr_count, data, pi_len, NULL); - if (!cleared) { - if(p.ca_pmt_list_management == CPLM_ONLY || p.ca_pmt_list_management == CPLM_FIRST || p.ca_pmt_list_management == CPLM_UPDATE) { - ci_cpl_clear_pids(slot); - ci_cpl_clear_capids(slot); - ci_cpl_clear_caids(slot); - cleared = 1; - } - } - if (ret < 0) { - warn ("error decoding ca_descriptor\n"); - break; - } - if((magic != p.pidinfo[pidn].cadescr[pid_ca_descr_count].ca_id) || (magic != p.pidinfo[pidn].cadescr[pid_ca_descr_count].ca_pid)){ - ci_cpl_update_pid (slot, p.pidinfo[pidn].pid); - ci_cpl_update_caid (slot, p.pidinfo[pidn].cadescr[pid_ca_descr_count].ca_id); - ci_cpl_update_capid (slot, p.pidinfo[pidn].cadescr[pid_ca_descr_count].ca_pid); - } - pid_ca_descr_count++; - data += ret; - pi_len -= ret; - len -= ret; - } - } - if (p.pidinfo[pidn].cadescr) { - free (p.pidinfo[pidn].cadescr); - } - pidn++; - } - if (p.pidinfo) { - free (p.pidinfo); - } - return 0; -} - -STATIC int ci_decode_al_ca_pmt_reply (ci_al_t * al) -{ - ca_pmt_reply_t p; - - memset (&p, 0, sizeof (ca_pmt_reply_t)); - - u_int8_t *data = al->data; - int len; - - p.program_number = ntohs16 (data); - data += 2; - - p.version_number = *data; - data++; - - p.ca_enable = *data; - data++; - - len = al->length - (data - al->data); - int pidn = 0; - - dbg ("ci_decode_al_ca_pmt_reply: program_number: %04x ca_enable: %02x\n", p.program_number, p.ca_enable); - - while (len>0) { - p.pidcaenable = (pid_ca_enable_t *) realloc (p.pidcaenable, sizeof (pid_ca_enable_t) * (pidn + 1)); - memset (&p.pidcaenable[pidn], 0, sizeof (pid_ca_enable_t)); - p.pidcaenable[pidn].pid = ntohs16 (data); - data += 2; - p.pidcaenable[pidn].ca_enable = *data; - data++; - len -= 3; - if ((p.pidcaenable[pidn].ca_enable == CPCI_OK_DESCRAMBLING) || (p.pidcaenable[pidn].ca_enable == CPCI_OK_MMI) || (p.pidcaenable[pidn].ca_enable == CPCI_QUERY)) { - ci_cpl_update_pid (al->sl->tl->ll->slot, p.pidcaenable[pidn].pid); - } else { - ci_cpl_delete_pid (al->sl->tl->ll->slot, p.pidcaenable[pidn].pid); - } - dbg ("count: %d pid: %04x pid_ca_enable: %02x\n", pidn, p.pidcaenable[pidn].pid, p.pidcaenable[pidn].ca_enable); - pidn++; - } - if (p.pidcaenable) { - free (p.pidcaenable); - } - return 0; -} - -STATIC int ci_decode_al (ci_sl_t * sl) -{ - int ret = 0; - int done = 0; - int len = 3; - ci_al_t al; - u_int8_t *data = sl->data; - al.sl = sl; - - al.tag = 0; - while (len--) { - al.tag <<= 8; - al.tag |= *data; - data++; - } - done += 3; - ret = ci_decode_length (&al.length, data); - if (ret < 0) { - warn ("ci_decode_al ci_decode_length failed\n"); - return ret; - } - - data += ret; - done += ret; - //Fake - al.data = data; - - dbg ("ci_decode_al: tag:%03x length: %02x data[0]:%02x done: %02x\n", al.tag, al.length, al.data[0], done); - - switch (al.tag) { - case AOT_CA_INFO: -// ci_decode_al_ca_info (&al); - break; - case AOT_CA_PMT: - ci_decode_al_ca_pmt (&al); - break; - case AOT_CA_PMT_REPLY: - ci_decode_al_ca_pmt_reply (&al); - break; - } - - done += al.length; - - dbg ("ci_decode_al: done %02x\n", done); - return done; -} - -STATIC int ci_decode_sl (ci_tl_t * tl) -{ - int ret = 0; - int done = 0; - unsigned int len; - ci_sl_t sl; - u_int8_t *data = tl->data; - sl.tl = tl; - - sl.tag = *data; - data++; - done++; - - if(sl.tag != ST_SESSION_NUMBER) { - return tl->length; - } - - ret = ci_decode_length (&len, data); - if (ret < 0) { - warn ("ci_decode_sl ci_decode_length failed\n"); - return ret; - } - data += ret; - done += ret; - - if (len > 4) { - warn ("invalid length (%d) for session_object_value\n", len); - return -1; - } - - sl.object_value = 0; - while (len--) { - sl.object_value <<= 8; - sl.object_value |= *data; - data++; - done++; - } - - sl.data = data; - sl.length = tl->length - done; - - while (sl.length>0) { - dbg ("ci_decode_sl: object_value:%02x length: %02x done: %02x\n", sl.object_value, sl.length, done); - ret = ci_decode_al (&sl); - if (ret < 0) { - warn ("ci_decode_al failed\n"); - return ret; - } - sl.length -= ret; - sl.data += ret; - done += ret; - } - dbg ("ci_decode_sl: done %02x\n", done); - return done; -} - -STATIC int ci_decode_tl (ci_ll_t * ll) -{ - int ret = 0; - int done = 0; - ci_tl_t tl; - u_int8_t *data = ll->data; - tl.ll = ll; - - tl.c_tpdu_tag = *data; - data++; - done++; - - ret = ci_decode_length (&tl.length, data); - if (ret < 0) { - warn ("ci_decode_tl ci_decode_length failed\n"); - return ret; - } - - data += ret; - done += ret; - - tl.tcid = *data; - data++; - done++; - - if (tl.tcid != ll->tcid) { - warn ("Error: redundant tcid mismatch %02x %02x\n",tl.tcid, ll->tcid); - return -1; - } - - tl.data = data; - - //According to A.4.1.1 - tl.length--; - - while (tl.length>0) { - dbg ("ci_decode_tl: c_tpdu_tag:%02x tcid:%02x length: %02x done: %02x\n", tl.c_tpdu_tag, tl.tcid, tl.length, done); - if (tl.c_tpdu_tag == T_DATA_LAST || tl.c_tpdu_tag == T_DATA_MORE) { - ret = ci_decode_sl (&tl); - if (ret < 0) { - warn ("ci_decode_sl failed\n"); - return ret; - } - } else { - ret = tl.length; - } - tl.length -= ret; - tl.data += ret; - done += ret; - } - dbg ("ci_decode_tl: done %02x\n", done); - return done; -} - -int ci_decode_ll (uint8_t * tpdu, int len) -{ - int ret = 0; - int done = 0; - u_int8_t *data=tpdu; - ci_ll_t ll; - dump(tpdu,len); - - ll.slot = *data; - data++; - - ll.tcid = *data; - data++; - - ll.data = data; - ll.length = len - (data-tpdu); - - while (ll.length) { - - dbg ("ci_decode_ll: slot:%02x tcid:%02x length: %02x\n", ll.slot, ll.tcid, ll.length); - ret = ci_decode_tl (&ll); - if (ret < 0) { - warn ("ci_decode_tl failed\n"); - return ret; - } - ll.length -= ret; - ll.data += ret; - } - dbg ("ci_decode_ll: done %02x\n", len); - return done; -} - -#ifdef TESTING -int main (int argc, char **argv) -{ - int ret; - - printf ("ci_decode_ll len: %02x\n", sizeof (lb)); - ret = ci_decode_ll (lb, sizeof (lb)); - printf ("ci_decode_ll ret: %02x\n", ret); - - printf ("ci_decode_ll len: %02x\n", sizeof (ll)); - ret = ci_decode_ll (ll, sizeof (ll)); - printf ("ci_decode_ll ret: %02x\n", ret); - - - printf ("ci_decode_ll len: %02x\n", sizeof (ld)); - ret = ci_decode_ll (ld, sizeof (ld)); - printf ("ci_decode_ll ret: %02x\n", ret); - - printf ("ci_decode_ll len: %02x\n", sizeof (lc)); - ret = ci_decode_ll (lc, sizeof (lc)); - printf ("ci_decode_ll ret: %02x\n", ret); - - printf ("ci_decode_ll len: %02x\n", sizeof (le)); - ret = ci_decode_ll (le, sizeof (le)); - printf ("ci_decode_ll ret: %02x\n", ret); - -// printf ("caid %04x for pid %04x\n", ci_cpl_find_caid_by_pid (0x5c), 0x5c); - return 0; -} -#endif +(symlink to ../common/ciparser.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/dummy_client.c
Changed
@@ -44,7 +44,7 @@ dvb_pid_t pids[3]; netceiver_info_list_t *nc_list=nc_get_list(); - +#if 0 printf("Looking for netceivers out there....\n"); while(run) { nc_lock_list(); @@ -61,7 +61,7 @@ } sleep(1); } - +#endif f=fopen("out.ts","wb"); r = recv_add(); @@ -86,7 +86,11 @@ memset(&pids, 0, sizeof(pids)); pids[0].pid=511; pids[1].pid=512; - pids[2].pid=-1; + pids[2].pid=511; + pids[2].id=2; + pids[3].pid=511; + pids[3].id=1; + pids[4].pid=-1; printf("\nTuning a station and writing transport data to file 'out.ts':\n"); recv_tune (r, (fe_type_t)FE_QPSK, 1800+192, &sec, &fep, pids);
View file
vdr-mcli-plugin.tar.bz2/mcast/client/dvblo_handler.c
Changed
@@ -453,6 +453,8 @@ { dvblo_dev_t *d = (dvblo_dev_t *) malloc (sizeof (dvblo_dev_t)); + if (!d) + return NULL; memset (d, 0, sizeof (dvblo_dev_t)); dvbmc_list_add_head (&devs.list, &d->list); return d; @@ -630,7 +632,7 @@ strcpy (d->uuid, nci->tuner[i].uuid); if (!cmd.reelcammode) { if (cidev < CA_MAX_SLOTS && (cmd.ca_enable & (1 << dev_num))) { - d->cacaps=(dvblo_cacaps_t*) &nci->ci; + d->cacaps=(dvblo_cacaps_t*)((void *) &nci->ci); d->ca_enable = 1; dbg ("Enabling CA support for device %d\n", dev_num); char addrstr[INET6_ADDRSTRLEN]; @@ -655,7 +657,7 @@ d->ca_enable = 1; dbg ("Enabling CA support for device %d\n", dev_num); if (!cidev) { - d->cacaps = (dvblo_cacaps_t*) &nci->ci; + d->cacaps = (dvblo_cacaps_t*)((void *) &nci->ci); char addrstr[INET6_ADDRSTRLEN]; dvblo_get_nc_addr (addrstr, d->uuid); dbg ("dvblo_get_nc_addr: %s %s\n", addrstr, d->uuid);
View file
vdr-mcli-plugin.tar.bz2/mcast/client/inet_aton.c
Changed
@@ -1,55 +0,0 @@ -/* - * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Kungliga Tekniska - * Högskolan and its contributors. - * - * 4. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $Id: inet_aton.c,v 1.6 2003/11/16 09:36:49 guy Exp $ */ - -#include "defs.h" - -/* Minimal implementation of inet_aton. - * Cannot distinguish between failure and a local broadcast address. */ - -#ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff -#endif - -int -inet_aton(const char *cp, struct in_addr *addr) -{ - addr->s_addr = inet_addr(cp); - return (addr->s_addr == INADDR_NONE) ? 0 : 1; -} +(symlink to ../common/win32/inet_aton.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/inet_ntop.c
Changed
@@ -1,211 +0,0 @@ -/* - * Copyright (c) 1999 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Kungliga Tekniska - * Högskolan and its contributors. - * - * 4. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $Id: inet_ntop.c,v 1.8 2005/02/09 02:25:46 guy Exp $ */ - -#include "defs.h" - -/* - * - */ - -#ifndef IN6ADDRSZ -#define IN6ADDRSZ 16 /* IPv6 T_AAAA */ -#endif - -#ifndef INT16SZ -#define INT16SZ 2 /* word size */ -#endif - -static const char * -inet_ntop_v4 (const void *src, char *dst, size_t size) -{ - const char digits[] = "0123456789"; - int i; - struct in_addr *addr = (struct in_addr *)src; - u_long a = ntohl(addr->s_addr); - const char *orig_dst = dst; - - if (size < INET_ADDRSTRLEN) { - errno = ENOSPC; - return NULL; - } - for (i = 0; i < 4; ++i) { - int n = (a >> (24 - i * 8)) & 0xFF; - int non_zerop = 0; - - if (non_zerop || n / 100 > 0) { - *dst++ = digits[n / 100]; - n %= 100; - non_zerop = 1; - } - if (non_zerop || n / 10 > 0) { - *dst++ = digits[n / 10]; - n %= 10; - non_zerop = 1; - } - *dst++ = digits[n]; - if (i != 3) - *dst++ = '.'; - } - *dst++ = '\0'; - return orig_dst; -} - -#ifdef INET6 -/* - * Convert IPv6 binary address into presentation (printable) format. - */ -static const char * -inet_ntop_v6 (const u_char *src, char *dst, size_t size) -{ - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp [INET6_ADDRSTRLEN+1]; - char *tp; - struct { - long base; - long len; - } best, cur; - u_long words [IN6ADDRSZ / INT16SZ]; - int i; - - /* Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset (words, 0, sizeof(words)); - for (i = 0; i < IN6ADDRSZ; i++) - words[i/2] |= (src[i] << ((1 - (i % 2)) << 3)); - - best.base = -1; - cur.base = -1; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) - { - if (words[i] == 0) - { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else cur.len++; - } - else if (cur.base != -1) - { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - if ((cur.base != -1) && (best.base == -1 || cur.len > best.len)) - best = cur; - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* Format the result. - */ - tp = tmp; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) - { - /* Are we inside the best run of 0x00's? - */ - if (best.base != -1 && i >= best.base && i < (best.base + best.len)) - { - if (i == best.base) - *tp++ = ':'; - continue; - } - - /* Are we following an initial run of 0x00s or any real hex? - */ - if (i != 0) - *tp++ = ':'; - - /* Is this address an encapsulated IPv4? - */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) - { - if (!inet_ntop_v4(src+12, tp, sizeof(tmp) - (tp - tmp))) - { - errno = ENOSPC; - return (NULL); - } - tp += strlen(tp); - break; - } - tp += sprintf (tp, "%lX", words[i]); - } - - /* Was it a trailing run of 0x00's? - */ - if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; - - /* Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) - { - errno = ENOSPC; - return (NULL); - } - return strcpy (dst, tmp); - return (NULL); -} -#endif /* INET6 */ - - -const char * -inet_ntop(int af, const void *src, char *dst, size_t size) -{ - switch (af) { - case AF_INET : - return inet_ntop_v4 (src, dst, size); -#ifdef INET6 - case AF_INET6: - return inet_ntop_v6 ((const u_char*)src, dst, size); -#endif - default : - errno = EAFNOSUPPORT; - return NULL; - } -} +(symlink to ../common/win32/inet_ntop.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/inet_pton.c
Changed
@@ -1,59 +0,0 @@ -/* - * Copyright (c) 1999 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Kungliga Tekniska - * Högskolan and its contributors. - * - * 4. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $Id: inet_pton.c,v 1.6 2003/11/16 09:36:51 guy Exp $ */ - -#include "defs.h" - -int -inet_pton(int af, const char *src, void *dst) -{ - if (af == AF_INET6) { - struct sockaddr_storage ss; - int sslen = sizeof(ss); - int ret; - ret=WSAStringToAddressA((LPSTR)src, AF_INET6, NULL, (struct sockaddr*)&ss, &sslen); - memcpy(dst, &((struct sockaddr_in6 *)&ss)->sin6_addr, sizeof(struct in6_addr)); - return ret; - } - if (af != AF_INET) { - errno = EAFNOSUPPORT; - return -1; - } - return inet_aton (src, (struct in_addr *)dst); -} +(symlink to ../common/win32/inet_pton.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/input.c
Changed
@@ -9,6 +9,10 @@ #include "headers.h" #define CI_RESET_WAIT 10 +#ifdef __MINGW32__ +#include <getopt.h> +#endif + cmdline_t cmd; //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
View file
vdr-mcli-plugin.tar.bz2/mcast/client/interfaces.c
Changed
@@ -1,339 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#include "headers.h" - -void int_destroy (struct intnode *intn) -{ - dbg ("Destroying interface %s\n", intn->name); - - /* Resetting the MTU to zero disabled the interface */ - intn->mtu = 0; -} - -struct intnode *int_find (unsigned int ifindex) -{ - unsigned int i; - for (i = 0; i < g_conf->maxinterfaces; i++) { - if(g_conf->ints[i].ifindex == ifindex) { - return g_conf->ints+i; - } - } - return NULL; -} - -struct intnode *int_find_name (char *ifname) -{ - unsigned int i; - for (i = 0; i < g_conf->maxinterfaces; i++) { - if (!strcmp (ifname, g_conf->ints[i].name) && g_conf->ints[i].mtu != 0) { - return g_conf->ints+i; - } - } - return NULL; -} - - -struct intnode *int_find_first (void) -{ - unsigned int i; - for (i = 0; i < g_conf->maxinterfaces; i++) { - dbg("int: %d %s\n",i, g_conf->ints[i].name); - if (g_conf->ints[i].mtu != 0) { - return g_conf->ints+i; - } - } - return NULL; -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -#if ! (defined WIN32 || defined APPLE) || defined __CYGWIN__ - -/* Initiliaze interfaces */ -void update_interfaces (struct intnode *intn) -{ - struct in6_addr addr; - - FILE *file; - unsigned int prefixlen, scope, flags, ifindex; - char devname[IFNAMSIZ]; - - /* Only update every 5 seconds to avoid rerunning it every packet */ - if (g_conf->maxinterfaces) - return; - - dbg ("Updating Interfaces\n"); - - /* Get link local addresses from /proc/net/if_inet6 */ - file = fopen ("/proc/net/if_inet6", "r"); - - /* We can live without it though */ - if (!file) { - err ("Cannot open /proc/net/if_inet6\n"); - return; - } - - char buf[255]; - /* Format "fe80000000000000029027fffe24bbab 02 0a 20 80 eth0" */ - while (fgets (buf, sizeof (buf), file)) { - if (21 != sscanf (buf, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx %x %x %x %x %8s", &addr.s6_addr[0], &addr.s6_addr[1], &addr.s6_addr[2], &addr.s6_addr[3], &addr.s6_addr[4], &addr.s6_addr[5], &addr.s6_addr[6], &addr.s6_addr[7], &addr.s6_addr[8], &addr.s6_addr[9], &addr.s6_addr[10], &addr.s6_addr[11], &addr.s6_addr[12], &addr.s6_addr[13], &addr.s6_addr[14], &addr.s6_addr[15], &ifindex, &prefixlen, &scope, &flags, devname)) { - - warn ("/proc/net/if_inet6 in wrong format!\n"); - continue; - } - if (!IN6_IS_ADDR_LINKLOCAL (&addr) && (IN6_IS_ADDR_UNSPECIFIED (&addr) || IN6_IS_ADDR_LOOPBACK (&addr) || IN6_IS_ADDR_MULTICAST (&addr))) { - continue; - } - - if((intn=int_find(ifindex))==NULL) { - g_conf->ints=(struct intnode*)realloc(g_conf->ints, sizeof(struct intnode)*(++g_conf->maxinterfaces)); - if (!g_conf->ints) { - err ("Cannot get memory for interface structures.\n"); - } - intn=g_conf->ints+g_conf->maxinterfaces-1; - memset(intn, 0, sizeof(struct intnode)); - } -#ifdef WIN32 - // Ugly WINXP workaround - if(scope==0x20 && flags==0x80) { - intn->mtu=1480; - } else { - intn->mtu=0; - } -#else - intn->ifindex = ifindex; - strcpy(intn->name, devname); - - struct ifreq ifreq; - int sock; - sock = socket (AF_INET6, SOCK_DGRAM, 0); - if (sock < 0) { - err ("Cannot get socket for setup\n"); - } - - memcpy (&ifreq.ifr_name, &intn->name, sizeof (ifreq.ifr_name)); - /* Get the MTU size of this interface */ - /* We will use that for fragmentation */ - if (ioctl (sock, SIOCGIFMTU, &ifreq) != 0) { - warn ("Cannot get MTU size for %s index %d: %s\n", intn->name, intn->ifindex, strerror (errno)); - } - intn->mtu = ifreq.ifr_mtu; - - /* Get hardware address + type */ - if (ioctl (sock, SIOCGIFHWADDR, &ifreq) != 0) { - warn ("Cannot get hardware address for %s, interface index %d : %s\n", intn->name, intn->ifindex, strerror (errno)); - } - intn->hwaddr = ifreq.ifr_hwaddr; - close (sock); -#endif - /* Link Local IPv6 address ? */ - if (IN6_IS_ADDR_LINKLOCAL (&addr)) { - /* Update the linklocal address */ - intn->linklocal = addr; - } else { - intn->global = addr; - } - - dbg ("Available interface %s index %u hardware %s/%u MTU %d\n", intn->name, intn->ifindex, (intn->hwaddr.sa_family == ARPHRD_ETHER ? "Ethernet" : (intn->hwaddr.sa_family == ARPHRD_SIT ? "sit" : "Unknown")), intn->hwaddr.sa_family, intn->mtu); - } - - fclose (file); -} -#endif -#if defined WIN32 && ! defined __CYGWIN__ - -unsigned int if_nametoindex (const char *ifname) -{ - unsigned int ifindex; - for (ifindex = 0; ifindex < g_conf->maxinterfaces; ifindex++) { - if (!strcmp (ifname, g_conf->ints[ifindex].name) && g_conf->ints[ifindex].mtu != 0) { - return g_conf->ints[ifindex].ifindex; - } - } - return 0; -} - -void update_interfaces (struct intnode *intn) -{ - - /* Declare and initialize variables */ - - DWORD dwRetVal = 0; - - int i = 0; - - // Set the flags to pass to GetAdaptersAddresses - ULONG flags = GAA_FLAG_INCLUDE_PREFIX; - - // default to unspecified address family (both) - ULONG family = AF_INET6; - - PIP_ADAPTER_ADDRESSES pAddresses = NULL; - ULONG outBufLen = 0; - - PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL; - PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL; - - outBufLen = sizeof (IP_ADAPTER_ADDRESSES); - pAddresses = (IP_ADAPTER_ADDRESSES *) malloc (outBufLen); - if (pAddresses == NULL) { - printf ("Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n"); - exit (1); - } - // Make an initial call to GetAdaptersAddresses to get the - // size needed into the outBufLen variable - if (GetAdaptersAddresses (family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) { - free (pAddresses); - pAddresses = (IP_ADAPTER_ADDRESSES *) malloc (outBufLen); - } - - if (pAddresses == NULL) { - printf ("Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n"); - exit (1); - } - - dwRetVal = GetAdaptersAddresses (family, flags, NULL, pAddresses, &outBufLen); - - if (dwRetVal == NO_ERROR) { - // If successful, output some information from the data we received - pCurrAddresses = pAddresses; - g_conf->maxinterfaces=0; - - while (pCurrAddresses) { - - if( /* pCurrAddresses->Flags & IP_ADAPTER_IPV6_ENABLED && */ (pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD || pCurrAddresses->IfType == IF_TYPE_IEEE80211) && pCurrAddresses->OperStatus == IfOperStatusUp ) { - g_conf->ints=(struct intnode*)realloc(g_conf->ints, sizeof(struct intnode)*(g_conf->maxinterfaces+1)); - intn=g_conf->ints+g_conf->maxinterfaces; - memset(intn, 0, sizeof(struct intnode)); - - printf ("Interface: %s (%wS)\n", pCurrAddresses->AdapterName, pCurrAddresses->Description); - dbg ("\tFriendly name: %wS\n", pCurrAddresses->FriendlyName); - dbg ("\tFlags: %x\n", pCurrAddresses->Flags); - dbg ("\tIfType: %ld\n", pCurrAddresses->IfType); - dbg ("\tOperStatus: %ld\n", pCurrAddresses->OperStatus); - dbg ("\tMtu: %lu\n", pCurrAddresses->Mtu); - dbg ("\tIpv6IfIndex (IPv6 interface): %u\n", pCurrAddresses->Ipv6IfIndex); - - strncpy(intn->name, pCurrAddresses->AdapterName, IFNAMSIZ-1); - - intn->mtu = pCurrAddresses->Mtu; - intn->ifindex= pCurrAddresses->Ipv6IfIndex; - - pUnicast = pCurrAddresses->FirstUnicastAddress; - if (pUnicast != NULL) { - for (i = 0; pUnicast != NULL; i++) { - char host[80]; - inet_ntop (AF_INET6, ((struct sockaddr_in6 *)(pUnicast->Address.lpSockaddr))->sin6_addr.s6_addr, host, sizeof(host)); - dbg("\tIP:%s LL:%d\n",host, IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)(pUnicast->Address.lpSockaddr))->sin6_addr)); - if(IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)(pUnicast->Address.lpSockaddr))->sin6_addr)) { - intn->linklocal=((struct sockaddr_in6 *)(pUnicast->Address.lpSockaddr))->sin6_addr; - } else { - intn->global=((struct sockaddr_in6 *)(pUnicast->Address.lpSockaddr))->sin6_addr; - } - pUnicast = pUnicast->Next; - } - dbg ("\tNumber of Unicast Addresses: %d\n", i); - } -#ifdef DEBUG - if (pCurrAddresses->PhysicalAddressLength != 0) { - dbg ("\tPhysical address: "); - for (i = 0; i < (int) pCurrAddresses->PhysicalAddressLength; i++) { - if (i == (pCurrAddresses->PhysicalAddressLength - 1)) - printf ("%.2X\n", (int) pCurrAddresses->PhysicalAddress[i]); - else - printf ("%.2X:", (int) pCurrAddresses->PhysicalAddress[i]); - } - } -#endif - g_conf->maxinterfaces++; - } - pCurrAddresses = pCurrAddresses->Next; - } - } - - free (pAddresses); -} - -#endif -#ifdef APPLE -void update_interfaces (struct intnode *intn) -{ - struct ifaddrs *myaddrs, *ifa; - struct sockaddr_in *s4; - struct sockaddr_in6 *s6; - int if_index; - /* - * buf must be big enough for an IPv6 address (e.g. - * 3ffe:2fa0:1010:ca22:020a:95ff:fe8a:1cf8) - */ - char buf[64]; - - if (getifaddrs(&myaddrs)) { - err ("getifaddrs"); - } - - for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) - continue; - if ((ifa->ifa_flags & IFF_UP) == 0) - continue; - - if_index=if_nametoindex(ifa->ifa_name); - dbg("%s(%d): ", ifa->ifa_name,if_index); - - if(!if_index) { - warn("cannot get interface index for %s\n",ifa->ifa_name); - continue; - } - - if((intn=int_find(if_index))==NULL) { - g_conf->ints=(struct intnode*)realloc(g_conf->ints, sizeof(struct intnode)*(++g_conf->maxinterfaces)); - if (!g_conf->ints) { - err ("Cannot get memory for interface structures.\n"); - } - intn=g_conf->ints+g_conf->maxinterfaces-1; - memset(intn, 0, sizeof(struct intnode)); - } - - intn->ifindex=if_index; - strcpy(intn->name,ifa->ifa_name); - - if(ifa->ifa_addr->sa_family == AF_LINK && ((struct if_data *)ifa->ifa_data)->ifi_type != IFT_LOOP && ifa->ifa_data) { - dbg("MTU: %d\n", ((struct if_data *)ifa->ifa_data)->ifi_mtu); - intn->mtu=((struct if_data *)ifa->ifa_data)->ifi_mtu; - memcpy(&intn->hwaddr, ifa->ifa_addr, sizeof(struct sockaddr_in)); - } - - if (ifa->ifa_addr->sa_family == AF_INET) { - s4 = (struct sockaddr_in *) (ifa->ifa_addr); - if (inet_ntop(ifa->ifa_addr->sa_family, (void *) &(s4->sin_addr), buf, sizeof(buf)) == NULL) { - warn("%s: inet_ntop failed!\n", ifa->ifa_name); - } else { - dbg("%s\n", buf); - } - } else if (ifa->ifa_addr->sa_family == AF_INET6) { - s6 = (struct sockaddr_in6 *) (ifa->ifa_addr); - /* Link Local IPv6 address ? */ - if (IN6_IS_ADDR_LINKLOCAL (&s6->sin6_addr)) { - /* Update the linklocal address */ - intn->linklocal = s6->sin6_addr; - } else { - intn->global = s6->sin6_addr; - } - if (inet_ntop(ifa->ifa_addr->sa_family, (void *) &(s6->sin6_addr), buf, sizeof(buf)) == NULL) { - warn("%s: inet_ntop failed!\n", ifa->ifa_name); - } else { - dbg("%s\n", buf); - } - } - } - - freeifaddrs(myaddrs); -} - -#endif +(symlink to ../common/interfaces.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/main.c
Changed
@@ -20,11 +20,15 @@ printf ("DVB - TV Client Version " MCLI_VERSION_STR " (c) BayCom GmbH\n\n"); //#if (defined WIN32 || defined APPLE) #ifdef WIN32 +#ifndef __MINGW32__ cmdline_t cmd; cmd.iface[0]=0; cmd.port=0; cmd.mld_start=1; #else + get_options (argc, argv); +#endif +#else #ifdef BACKTRACE signal(SIGSEGV, SignalHandlerCrash); signal(SIGBUS, SignalHandlerCrash);
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mcast.c
Changed
@@ -1,657 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - * modified by Reel Multimedia, http://www.reel-multimedia.com, info@reel-multimedia.com - * 01042010 DL: use a single thread for reading from network layer (uses less resources) - * - */ - -#include "headers.h" - -//---------------------------------------------------------------------------------------------------------------------------------- -STATIC int udp_ipv6_is_multicast_address (const struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) - return IN_MULTICAST (ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr)); -#endif - if (addr->sa_family == AF_INET6) - return IN6_IS_ADDR_MULTICAST (&((struct sockaddr_in6 *) addr)->sin6_addr); - return -1; -} - -//--------------------------------------------------------------------------------------------------------------------------------- -STATIC int udp_ipv6_set_multicast_ttl (SOCKET sockfd, int mcastTTL, struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) { - if (setsockopt (sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof (mcastTTL)) < 0) { - perror ("setsockopt(IP_MULTICAST_TTL)"); - return -1; - } - } -#endif - if (addr->sa_family == AF_INET6) { - if (setsockopt (sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (_SOTYPE)&mcastTTL, sizeof (mcastTTL)) < 0) { - perror ("setsockopt(IPV6_MULTICAST_HOPS)"); - return -1; - } - } - return 0; -} - -//--------------------------------------------------------------------------------------------------------------------------------- -int udp_ipv6_join_multicast_group (SOCKET sockfd, int iface, struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) { - struct ip_mreq mreq; - mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; - mreq.imr_interface.s_addr = INADDR_ANY; - if (setsockopt (sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *) &mreq, sizeof (mreq)) < 0) { - perror ("setsockopt(IP_ADD_MEMBERSHIP)"); - return -1; - } - } -#endif - if (addr->sa_family == AF_INET6) { - struct ipv6_mreq mreq6; - memcpy (&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *) addr)->sin6_addr), sizeof (struct in6_addr)); - mreq6.ipv6mr_interface = iface; - if (setsockopt (sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (_SOTYPE)&mreq6, sizeof (mreq6)) < 0) { - perror ("setsockopt(IPV6_ADD_MEMBERSHIP)"); - return -1; - } - } - return 0; -} - -//--------------------------------------------------------------------------------------------------------------------------------- -int udp_ipv6_leave_multicast_group (SOCKET sockfd, int iface, struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) { - struct ip_mreq mreq; - mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; - mreq.imr_interface.s_addr = INADDR_ANY; - if (setsockopt (sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *) &mreq, sizeof (mreq)) < 0) { - perror ("setsockopt(IP_DROP_MEMBERSHIP)"); - return -1; - } - } -#endif - if (addr->sa_family == AF_INET6) { - struct ipv6_mreq mreq6; - memcpy (&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *) addr)->sin6_addr), sizeof (struct in6_addr)); - mreq6.ipv6mr_interface = iface; - if (setsockopt (sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, (_SOTYPE)&mreq6, sizeof (mreq6)) < 0) { - perror ("setsockopt(IPV6_DROP_MEMBERSHIP)"); - return -1; - } - } - return 0; -} - -//----------------------------------------------------------------------------------------------------------------------------------- -STATIC int sockfd_to_family (SOCKET sockfd) -{ - struct sockaddr_storage ss; - socklen_t len; - - len = sizeof (ss); - if (getsockname (sockfd, (SA *) & ss, &len) < 0) - return (-1); - return (ss.ss_family); -} - -/* end sockfd_to_family */ -//---------------------------------------------------------------------------------------------------------------------------------- -int mcast_set_if (SOCKET sockfd, const char *ifname, u_int ifindex) -{ - switch (sockfd_to_family (sockfd)) { -#ifdef IPV4 - case AF_INET:{ - struct in_addr inaddr; - struct ifreq ifreq; - - if (ifindex > 0) { - if (if_indextoname (ifindex, ifreq.ifr_name) == NULL) { - errno = ENXIO; /* i/f index not found */ - return (-1); - } - goto doioctl; - } else if (ifname != NULL) { - memset(&ifreq, 0, sizeof(struct ifreq)); - strncpy (ifreq.ifr_name, ifname, IFNAMSIZ-1); - doioctl: - if (ioctl (sockfd, SIOCGIFADDR, &ifreq) < 0) - return (-1); - memcpy (&inaddr, &((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr, sizeof (struct in_addr)); - } else - inaddr.s_addr = htonl (INADDR_ANY); /* remove prev. set default */ - - return (setsockopt (sockfd, IPPROTO_IP, IP_MULTICAST_IF, &inaddr, sizeof (struct in_addr))); - } -#endif - case AF_INET6:{ - u_int idx; -// printf("Changing interface IPV6...\n"); - if ((idx = ifindex) == 0) { - if (ifname == NULL) { - errno = EINVAL; /* must supply either index or name */ - return (-1); - } - if ((idx = if_nametoindex (ifname)) == 0) { - errno = ENXIO; /* i/f name not found */ - return (-1); - } - } - return (setsockopt (sockfd, IPPROTO_IPV6, IPV6_MULTICAST_IF, (_SOTYPE)&idx, sizeof (idx))); - } - - default: -// errno = EAFNOSUPPORT; - return (-1); - } -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -UDPContext *server_udp_open (const struct in6_addr *mcg, int port, const char *ifname) -{ - UDPContext *s; - int sendfd; - int n; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - - s = (UDPContext *) calloc (1, sizeof (UDPContext)); - if (!s) { - err ("Cannot allocate memory !\n"); - goto error; - } - struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &s->dest_addr; - - addr->sin6_addr=*mcg;; - addr->sin6_family = AF_INET6; - addr->sin6_port = htons (port); - s->dest_addr_len = sizeof (struct sockaddr_in6); - - sendfd = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (sendfd < 0) { - err ("cannot get socket\n"); - } - - s->dest_addr_len = sizeof (struct sockaddr_in6); - - if ((udp_ipv6_is_multicast_address ((struct sockaddr *) &s->dest_addr))) { - if (ifname && strlen (ifname) && (mcast_set_if (sendfd, ifname, 0) < 0)) { - warn ("mcast_set_if error\n"); - goto error; - } - if (udp_ipv6_set_multicast_ttl (sendfd, MCAST_TTL, (struct sockaddr *) &s->dest_addr) < 0) { - warn ("udp_ipv6_set_multicast_ttl"); - } - } - - n = UDP_TX_BUF_SIZE; - if (setsockopt (sendfd, SOL_SOCKET, SO_SNDBUF, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt sndbuf"); - } - s->is_multicast = 0; //server - s->udp_fd = sendfd; - s->local_port = port; - - dbg ("Multicast streamer initialized successfully ! \n"); - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return s; - error: - err ("Cannot init udp_server !\n"); - if (s) { - free (s); - } - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return NULL; -} - -UDPContext *server_udp_open_host (const char *host, int port, const char *ifname) -{ - struct in6_addr addr; - - inet_pton (AF_INET6, host, &addr); - - return server_udp_open (&addr, port, ifname); -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -UDPContext *client_udp_open (const struct in6_addr *mcg, int port, const char *ifname) -{ - UDPContext *s; - int recvfd; - int n; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - - s = (UDPContext *) calloc (1, sizeof (UDPContext)); - if (!s) { - err ("Cannot allocate memory !\n"); - goto error; - } - - struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &s->dest_addr; -#ifndef WIN32 - addr->sin6_addr=*mcg; -#else - struct in6_addr any=IN6ADDR_ANY_INIT; - addr->sin6_addr=any; -#endif - addr->sin6_family = AF_INET6; - addr->sin6_port = htons (port); - s->dest_addr_len = sizeof (struct sockaddr_in6); - - recvfd = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (recvfd < 0) { - err ("cannot get socket\n"); - } -#ifdef WIN32 -# ifndef IPV6_PROTECTION_LEVEL -# define IPV6_PROTECTION_LEVEL 23 -# endif - n = 10 /*PROTECTION_LEVEL_UNRESTRICTED*/; - if(setsockopt( recvfd, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (_SOTYPE)&n, sizeof(n) ) < 0 ) { - warn ("setsockopt IPV6_PROTECTION_LEVEL\n"); - } -#endif - n = 1; - if (setsockopt (recvfd, SOL_SOCKET, SO_REUSEADDR, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt REUSEADDR\n"); - } - -#if ! (defined WIN32 || defined APPLE) - if (ifname && strlen (ifname) && setsockopt (recvfd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen (ifname) + 1)) { - dbg ("setsockopt SO_BINDTODEVICE %s failed\n", ifname); - } -#endif - if (bind (recvfd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len) < 0) { - warn ("bind failed\n"); - goto error; - } -#ifdef WIN32 - addr->sin6_addr=*mcg; -#endif - if (udp_ipv6_is_multicast_address ((struct sockaddr *) &s->dest_addr)) { -#if 0 - if (ifname && strlen (ifname) && (mcast_set_if (recvfd, ifname, 0) < 0)) { - warn ("mcast_set_if error \n"); - goto error; - } -#endif - if (ifname) { - if ((s->idx = if_nametoindex (ifname)) == 0) { - s->idx = 0; - } else { - dbg("Selecting interface %s (%d)", ifname, s->idx); - } - } else { - s->idx = 0; - } - - if (udp_ipv6_join_multicast_group (recvfd, s->idx, (struct sockaddr *) &s->dest_addr) < 0) { - warn ("Cannot join multicast group !\n"); - goto error; - } - s->is_multicast = 1; - } - - n = UDP_RX_BUF_SIZE; - if (setsockopt (recvfd, SOL_SOCKET, SO_RCVBUF, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt rcvbuf"); - goto error; - } - - s->udp_fd = recvfd; - s->local_port = port; - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - - return s; - error: - warn ("socket error !\n"); - if (s) { - free (s); - } - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return NULL; -} - -UDPContext *client_udp_open_host (const char *host, int port, const char *ifname) -{ - struct in6_addr addr; - - inet_pton (AF_INET6, host, &addr); - - return client_udp_open (&addr, port, ifname); -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -int udp_read (UDPContext * s, uint8_t * buf, int size, int timeout, struct sockaddr_storage *from) -{ - socklen_t from_len = sizeof (struct sockaddr_storage); - struct sockaddr_storage from_local; - - if(!from) { - from=&from_local; - } - - fd_set rfds; - struct timeval tv; - FD_ZERO(&rfds); - FD_SET(s->udp_fd, &rfds); - tv.tv_sec = 0; - tv.tv_usec = timeout; - - if(select(s->udp_fd+1, &rfds, NULL, NULL, &tv)>0) { - return recvfrom (s->udp_fd, (char *)buf, size, 0, (struct sockaddr *) from, &from_len); - } - return -1; -} - -//-------------------------------------------------------------------------------------------------------------------------------------------------- -int udp_write (UDPContext * s, uint8_t * buf, int size) -{ - int ret; - - for (;;) { - ret = sendto (s->udp_fd, (char *) buf, size, 0, (struct sockaddr *) &s->dest_addr, s->dest_addr_len); - - if (ret < 0) { - if (errno != EINTR && errno != EAGAIN) - return -1; - } else { - break; - } - } - return size; -} - -//---------------------------------------------------------------------------------------------------------------------------------------------------- -int udp_close (UDPContext * s) -{ - if (s->is_multicast) - udp_ipv6_leave_multicast_group (s->udp_fd, s->idx, (struct sockaddr *) &s->dest_addr); - - closesocket (s->udp_fd); - free (s); - - return 0; -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- - -#ifndef MULTI_THREAD_RECEIVER - -#define MAX_BUFF_SIZE 0x10000 -#define MAX_CON_LIST 128 -UDPContext *gConList[MAX_CON_LIST]; -pthread_mutex_t gConListLock = PTHREAD_MUTEX_INITIALIZER; -static int gConListInit=0; - -STATIC void client_upd_cleanup (void *arg) { - if(!gConListInit) return; - pthread_mutex_lock(&gConListLock); - memset(&gConList, 0, sizeof(gConList)); - gConListInit=0; - pthread_mutex_unlock(&gConListLock); -} // client_upd_cleanup - -void *client_upd_process(void *arg) { -#ifdef RT -#if 1 - if (setpriority (PRIO_PROCESS, 0, -15) == -1) -#else - if (pthread_setschedprio (p->recv_ts_thread, -15)) -#endif - { - dbg ("Cannot raise priority to -15\n"); - } -#endif - unsigned char buff[MAX_BUFF_SIZE]; - socklen_t from_len = sizeof (struct sockaddr_storage); - struct sockaddr_storage from_local; - struct timeval timeout; - struct pollfd fds[MAX_CON_LIST]; - - pthread_cleanup_push (client_upd_cleanup, 0); - int i; - while(1) { - int max_fd=0; - pthread_mutex_lock(&gConListLock); - - for(i=0;i<MAX_CON_LIST;i++) { - if(gConList[i]) { - fds[max_fd].fd = gConList[i]->udp_fd; - fds[max_fd].events = POLLIN; - fds[max_fd].revents = 0; - gConList[i]->pfd = &fds[max_fd]; - max_fd++; - } // if - } // for - pthread_mutex_unlock(&gConListLock); - timeout.tv_sec = 0; - timeout.tv_usec = 100000; - int rs = poll(fds, max_fd, 1000); - if(rs>0) { - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) { - if(gConList[i] && gConList[i]->pfd && (gConList[i]->pfd->revents & POLLIN)) { - if(gConList[i]->cb) { - int ret = recvfrom (gConList[i]->udp_fd, (char *)buff, MAX_BUFF_SIZE, 0, 0, 0/*(struct sockaddr *) &from_local, &from_len*/); - if(ret>0) - gConList[i]->cb(buff, ret, gConList[i]->arg); - } else if(gConList[i]->buff && !gConList[i]->bufflen) { - pthread_mutex_lock(&gConList[i]->bufflock); - int ret = recvfrom (gConList[i]->udp_fd, (char *)gConList[i]->buff, gConList[i]->buffmax, 0, (struct sockaddr *) &from_local, &from_len); - if(ret>0) - gConList[i]->bufflen = ret; - pthread_mutex_unlock(&gConList[i]->bufflock); - } // if - } // if - } // for - pthread_mutex_unlock(&gConListLock); - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - } // if - pthread_testcancel(); - } // while - pthread_cleanup_pop (1); - return NULL; -} - -static int client_upd_init() { - pthread_mutex_lock(&gConListLock); - if(gConListInit) { - pthread_mutex_unlock(&gConListLock); - return 1; - } // if - memset(&gConList, 0, sizeof(gConList)); - pthread_t client_upd_thread; - if(0==pthread_create (&client_upd_thread, NULL, client_upd_process, 0)) { - gConListInit = 1; - pthread_detach(client_upd_thread); - } // if - pthread_mutex_unlock(&gConListLock); - return gConListInit; -} // client_upd_init - -UDPContext *client_udp_open_buff (const struct in6_addr *mcg, int port, const char *ifname, int buff_size) { - UDPContext *ret = client_udp_open_cb (mcg, port, ifname, 0, 0); - if(ret) { - ret->buff = (unsigned char *)malloc(buff_size); - ret->buffmax = buff_size; - ret->bufflen = 0; - } // if - return ret; -} // client_udp_open_buff - -UDPContext *client_udp_open_cb (const struct in6_addr *mcg, int port, const char *ifname, client_udp_cb cb, void *arg) -{ - if(!client_upd_init()) return NULL; - - UDPContext *s; - int recvfd = -1; - int n; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - - s = (UDPContext *) calloc (1, sizeof (UDPContext)); - if (!s) { - err ("Cannot allocate memory !\n"); - goto error; - } - - struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &s->dest_addr; -#ifndef WIN32 - addr->sin6_addr=*mcg; -#else - struct in6_addr any=IN6ADDR_ANY_INIT; - addr->sin6_addr=any; -#endif - addr->sin6_family = AF_INET6; - addr->sin6_port = htons (port); - s->dest_addr_len = sizeof (struct sockaddr_in6); - - recvfd = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (recvfd < 0) { - err ("cannot get socket\n"); - } -#ifdef WIN32 -# ifndef IPV6_PROTECTION_LEVEL -# define IPV6_PROTECTION_LEVEL 23 -# endif - n = 10 /*PROTECTION_LEVEL_UNRESTRICTED*/; - if(setsockopt( recvfd, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (_SOTYPE)&n, sizeof(n) ) < 0 ) { - warn ("setsockopt IPV6_PROTECTION_LEVEL\n"); - } -#endif - n = 1; - if (setsockopt (recvfd, SOL_SOCKET, SO_REUSEADDR, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt REUSEADDR\n"); - } - -#if ! (defined WIN32 || defined APPLE) - if (ifname && strlen (ifname) && setsockopt (recvfd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen (ifname) + 1)) { - dbg ("setsockopt SO_BINDTODEVICE %s failed\n", ifname); - } -#endif - if (bind (recvfd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len) < 0) { - warn ("bind failed\n"); - goto error; - } -#ifdef WIN32 - addr->sin6_addr=*mcg; -#endif - if (udp_ipv6_is_multicast_address ((struct sockaddr *) &s->dest_addr)) { -#if 0 - if (ifname && strlen (ifname) && (mcast_set_if (recvfd, ifname, 0) < 0)) { - warn ("mcast_set_if error \n"); - goto error; - } -#endif - if (ifname) { - if ((s->idx = if_nametoindex (ifname)) == 0) { - s->idx = 0; - } else { - dbg("Selecting interface %s (%d)", ifname, s->idx); - } - } else { - s->idx = 0; - } - - if (udp_ipv6_join_multicast_group (recvfd, s->idx, (struct sockaddr *) &s->dest_addr) < 0) { - warn ("Cannot join multicast group !\n"); - goto error; - } - s->is_multicast = 1; - } - - n = cb ? UDP_PID_BUF_SIZE : UDP_RX_BUF_SIZE; - if (setsockopt (recvfd, SOL_SOCKET, SO_RCVBUF, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt rcvbuf"); - goto error; - } - - s->udp_fd = recvfd; - s->local_port = port; - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - - s->cb = cb; - s->arg = arg; - pthread_mutex_init(&s->bufflock, NULL); - int i; - pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) { - if(!gConList[i]) { - gConList[i]=s; - break; - } // if - } // for - pthread_mutex_unlock(&gConListLock); - if(i>=MAX_CON_LIST) - warn("---------------------------------------------No slot found!\n"); - - return s; - error: - warn ("socket error !\n"); - if (s) { - free (s); - } - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return NULL; -} - -UDPContext *client_udp_open_host_buff (const char *host, int port, const char *ifname, int buff_size) -{ - struct in6_addr addr; - - inet_pton (AF_INET6, host, &addr); - - return client_udp_open_buff (&addr, port, ifname, buff_size); -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -int udp_read_buff (UDPContext * s, uint8_t * buf, int size, int timeout, struct sockaddr_storage *from) -{ - pthread_mutex_lock(&s->bufflock); - int ret = s->bufflen>size ? size : s->bufflen; - if(ret>0) { - memcpy(buf, s->buff, ret); - s->bufflen-=ret; - } - pthread_mutex_unlock(&s->bufflock); - return ret; -} -//---------------------------------------------------------------------------------------------------------------------------------------------------- -int udp_close_buff (UDPContext * s) -{ - int i; - pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) - if(gConList[i] == s) - gConList[i]=0; - pthread_mutex_unlock(&gConListLock); - if (s->is_multicast) - udp_ipv6_leave_multicast_group (s->udp_fd, s->idx, (struct sockaddr *) &s->dest_addr); - - closesocket (s->udp_fd); - free(s->buff); - pthread_mutex_destroy(&s->bufflock); - free (s); - - return 0; -} -#endif +(symlink to ../common/mcast.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mingw/Makefile
Changed
@@ -1,8 +1,9 @@ -PATH:=/MinGW/bin/:$(PATH) +# Set by batch file +#PATH:=/MinGW/bin/:$(PATH) CC:=gcc -#Comment this out to disable debugging output -DEBUG=1 +#Uncomment the following line to enable debugging output +#DEBUG=1 #VERBOSE=1 #API_SOCK=1 @@ -13,9 +14,9 @@ DEBUG=1 endif -CFLAGS:= $(DEFS) -Wall -Iwin32/include $(CFLAGS) -LDFLAGS:= -Lwin32/lib $(LDFLAGS) -LDLIBS:= -lwsock32 -liphlpapi -lpthreadGC2 -lxml2 -lzdll +CFLAGS:= $(DEFS) -O2 -Wall -I../win32/include -I../../common $(CFLAGS) +LDFLAGS:= -s -L../win32/lib $(LDFLAGS) +LDLIBS:= -liphlpapi -lpthreadGC2 -lws2_32 -lxml2 -lz ifdef DEBUG LDFLAGS:= $(LDFLAGS) -g @@ -25,21 +26,28 @@ endif MCLI = mcli -MCLI_OBJS = mld_common.o mld_client.o mld_reporter.o mcast.o recv_tv.o recv_ccpp.o tools.o tca_handler.o tra_handler.o satlists.o interfaces.o inet_pton.o inet_ntop.o inet_aton.o -MCLI_SOBJS := main.o dummy_client.o +MCLI_OBJS = mld_common.o mld_client.o mld_reporter.o mcast.o recv_tv.o recv_ccpp.o tools.o tca_handler.o tra_handler.o satlists.o interfaces.o inet_pton.o inet_ntop.o inet_aton.o poll.o +MCLI_SOBJS := main.o dummy_client.o api_server.o input.o + +all: lib$(MCLI).a $(MCLI).exe -all: lib$(MCLI) +lib$(MCLI).a: $(MCLI_OBJS) + $(AR) $(ARFLAGS) $@ $(MCLI_OBJS) + @copy /b $@ ..\\win32\\lib\\ + @echo "You can find all libraries in directory ..\\win32\lib" + @echo "If you need a shared library you need MSVC installed." + @echo "To build the shared library execute the following:" + @echo "mingw32-make libmcli.dll" -lib$(MCLI): $(MCLI_OBJS) - $(CC) $(LDFLAGS) -shared -o $@.dll $(MCLI_OBJS) $(LDLIBS) -Wl,--out-implib,$@.a -Wl,--output-def,$@.def -# $(AR) $(ARFLAGS) $@.a $(MCLI_OBJS) - @copy /b $@.dll win32\\lib\\ - @copy /b $@.a win32\\lib\\ - @copy /b $@.def win32\\lib\\ - lib.exe /def:$@.def /machine:x86 /out:win32\\lib\\$@.lib - @echo "You can find all libraries in directory win32\lib" +lib$(MCLI).dll: $(MCLI_OBJS) + @echo You need MSVC lib.exe for shared libraries! + $(CC) $(LDFLAGS) -shared -o $@ $(MCLI_OBJS) $(LDLIBS) -Wl,--out-implib,lib$(MCLI).a -Wl,--output-def,lib$(MCLI).def + @copy /b $@ ..\\win32\\lib\\ + @copy /b lib$(MCLI).def ..\\win32\\lib\\ + @lib.exe /def:lib$(MCLI).def /machine:x86 /out:..\\win32\\lib\\lib$(MCLI).lib + @echo "You can find all libraries in directory ..\\win32\lib" -$(MCLI): $(MCLI_OBJS) $(MCLI_SOBJS) +$(MCLI).exe: $(MCLI_OBJS) $(MCLI_SOBJS) $(CC) $(LDFLAGS) -o $@ $(MCLI_OBJS) $(MCLI_SOBJS) $(LDLIBS) $(MCLI)-shared: lib$(MCLI) @@ -48,8 +56,9 @@ $(CC) $(LDFLAGS) -o $@ $(MCLI_SOBJS) $(LDLIBS) -lmcli clean: - @del $(MCLI)*.exe lib$(MCLI).* *.lib *.o *.la *~ + @-del $(MCLI)*.exe lib$(MCLI).* *.lib *.o *.la *~ + @-del ..\\win32\\lib\\lib$(MCLI).* -%.o: %.c +%.o: ../%.c $(CC) -c $(CFLAGS) -o $@ $<
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mingw/build.cmd
Changed
@@ -1,2 +1,2 @@ -@set %PATH%=c:\MinGw\bin;%PATH% -@mingw32-make clean libmcli +@set PATH=c:\MinGw\bin;%PATH% +@mingw32-make
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mingw/clean.cmd
Added
@@ -0,0 +1,2 @@ +@set PATH=c:\MinGw\bin;%PATH% +@mingw32-make clean
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mld_client.c
Changed
@@ -1,244 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#undef DEBUG -#include "headers.h" - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -int send_mldv2_report (struct intnode *intn, int grec_number, struct in6_addr *mcas, int srcn, struct in6_addr *sources, int mode) -{ - unsigned int length; - struct mld_report_packet - { - struct ip6_hdr ip6; - struct ip6_hbh hbh; - struct - { - uint8_t type; - uint8_t length; - uint16_t value; - uint8_t optpad[2]; - } routeralert; - struct mld2_report mld2r; - } *packet; - struct mld2_grec *grec = NULL; - struct in6_addr *src = NULL; - int mca_index, src_index; - int count = 0; - - bool any = false; - - - //printf("creating multicast listener report packet....\n"); - //printf("size src = %d size grec = %d \n",sizeof(*src),sizeof(*grec)); - if (intn->mtu < sizeof (*packet)) { - /* - * MTU is too small to support this type of packet - * Should not happen though - */ - dbg ("MTU too small for packet while sending MLDv2 report on interface %s/%u mtu=%u!?\n", intn->name, intn->ifindex, intn->mtu); - return -1; - } - - /* Allocate a buffer matching the MTU size of this interface */ - packet = (struct mld_report_packet *) malloc (intn->mtu); - - if (!packet) { - err ("Cannot get memory for MLD2 report packet, aborting\n"); - } -// printf("addr packet = %u \n",packet); - memset (packet, 0, intn->mtu); - - - /* Create the IPv6 packet */ - packet->ip6.ip6_vfc = 0x60; - packet->ip6.ip6_plen = ntohs (sizeof (*packet) - sizeof (packet->ip6)); - packet->ip6.ip6_nxt = IPPROTO_HOPOPTS; - packet->ip6.ip6_hlim = 1; - - /* - * The source address must be the link-local address - * of the interface we are sending on - */ - memcpy (&packet->ip6.ip6_src, &intn->linklocal, sizeof (packet->ip6.ip6_src)); - - /* MLDv2 Report -> All IPv6 Multicast Routers (ff02::16) */ - packet->ip6.ip6_dst.s6_addr[0] = 0xff; - packet->ip6.ip6_dst.s6_addr[1] = 0x02; - packet->ip6.ip6_dst.s6_addr[15] = 0x16; - - /* HopByHop Header Extension */ - packet->hbh.ip6h_nxt = IPPROTO_ICMPV6; - packet->hbh.ip6h_len = 0; - - /* Router Alert Option */ - packet->routeralert.type = 5; - packet->routeralert.length = sizeof (packet->routeralert.value); - packet->routeralert.value = 0; /* MLD ;) */ - - /* Option Padding */ - packet->routeralert.optpad[0] = IP6OPT_PADN; - packet->routeralert.optpad[1] = 0; - - /* ICMPv6 MLD Report */ - packet->mld2r.type = ICMP6_V2_MEMBERSHIP_REPORT; - //number of multi cast address reocrds - packet->mld2r.ngrec = 0; //grec_number;//htons(1); - length = 0; - count = 0; - for (mca_index = 0; mca_index < grec_number; mca_index++) { - src = NULL; - if (!grec) { - length = sizeof (*packet) + sizeof (*grec) - sizeof (packet->ip6); - //fprintf(stdout,"(grec = %02d) %02d. current report length = %04d MTU: %04d)\n",packet->mld2r.ngrec,mca_index,length+sizeof(packet->ip6),intn->mtu); - - if (length + sizeof (packet->ip6) > intn->mtu) { - /* Should not happen! Would mean the MTU is smaller than a standard mld report */ - dbg ("No grec and MTU too small for packet while sending MLDv2 report on interface %s/%u mtu=%u!?\n", intn->name, intn->ifindex, intn->mtu); - free (packet); - return (-1); - } else - grec = (struct mld2_grec *) (((char *) packet) + sizeof (*packet)); - - packet->mld2r.ngrec++; - } else { - if (!src) - length = ((((char *) grec) - ((char *) packet)) + sizeof (*grec) + (sizeof (*src) * (grec->grec_nsrcs))) - sizeof (packet->ip6); - - //fprintf(stdout,"\nloop1:(grec = %02d) %02d.length = %04d (Total : %04d MTU: %04d)\n\n", packet->mld2r.ngrec , mca_index,length,(length + sizeof(packet->ip6)), intn->mtu); - - if (((length + sizeof (packet->ip6) + sizeof (*grec)) > intn->mtu)) { - - /* Take care of endianess */ - //fprintf(stdout,"next grec record does not fit... sending... \n"); - - packet->mld2r.ngrec = htons (packet->mld2r.ngrec); - grec->grec_nsrcs = htons (grec->grec_nsrcs); - - /* Calculate and fill in the checksum */ - packet->ip6.ip6_plen = htons (length); - packet->mld2r.csum = htons (0); - packet->mld2r.csum = ipv6_checksum (&packet->ip6, IPPROTO_ICMPV6, (uint8_t *) & packet->mld2r, length - sizeof (struct ip6_hbh) - sizeof (packet->routeralert)); - count++; -#ifdef DEBUG - dbg ("%04d.Sending2 MLDv2 Report on %s/%u, ngrec=%u, length=%u sources=%u (in last grec)\n", count, intn->name, intn->ifindex, ntohs (packet->mld2r.ngrec), length, ntohs (grec->grec_nsrcs)); - sendpacket6 (intn, (const struct ip6_hdr *) packet, length + sizeof (packet->ip6)); -#endif - /* Increase ICMP sent statistics */ - g_conf->stat_icmp_sent++; - intn->stat_icmp_sent++; - - /* Reset the MLDv2 struct */ - packet->mld2r.ngrec = 0; - grec = (struct mld2_grec *) (((char *) packet) + sizeof (*packet)); - } else { - //next grec - grec->grec_nsrcs = htons (grec->grec_nsrcs); - grec = (struct mld2_grec *) (((char *) grec) + sizeof (*grec) + (sizeof (*src) * ntohs (grec->grec_nsrcs))); - - } - packet->mld2r.ngrec++; - } - //Copy MCA to record - memcpy (&grec->grec_mca, mcas + mca_index, sizeof (grec->grec_mca)); - - /* Zero sources upto now */ - grec->grec_nsrcs = 0; - /* 0 Sources -> Exclude those */ - grec->grec_type = MLD2_MODE_IS_EXCLUDE; - if (mode) { - grec->grec_type = mode; - } - - /* Nothing added yet */ - any = false; - - for (src_index = 0; src_index < srcn || (!srcn && src_index == 0); src_index++) { - - //check for duplicate source reocrds and any address - - /* Packet with at least one grec and one or more src's, excluding ip6 header */ - - length = (((char *) grec) - ((char *) packet)) + sizeof (*grec) + (sizeof (*src) * (grec->grec_nsrcs)) - sizeof (packet->ip6); - - //fprintf(stdout,"loop2:(grec = %02d) %02d.length = %04d (Total : %04d MTU: %04d)\n", packet->mld2r.ngrec,mca_index,length,(length + sizeof(packet->ip6)),intn->mtu); - /* Would adding it not fit? -> Send it out */ - if (((length + sizeof (packet->ip6) + sizeof (*src)) > (intn->mtu)) && srcn) { - //fprintf(stdout,"next source addr. does not fit... sending... \n"); - //fprintf(stdout,"src_index = %d grec->grec_nsrcs = %d \n",src_index,grec->grec_nsrcs); - - /* Take care of endianess */ - packet->mld2r.ngrec = htons (packet->mld2r.ngrec); - grec->grec_nsrcs = htons (grec->grec_nsrcs); - /* Calculate and fill in the checksum */ - - packet->ip6.ip6_plen = htons (length); - packet->mld2r.csum = htons (0); - packet->mld2r.csum = ipv6_checksum (&packet->ip6, IPPROTO_ICMPV6, (uint8_t *) & packet->mld2r, length - sizeof (struct ip6_hbh) - sizeof (packet->routeralert)); - - count++; - dbg ("%04d.Sending2 MLDv2 Report on %s/%u, ngrec=%u, length=%u sources=%u (in last grec)\n", count, intn->name, intn->ifindex, ntohs (packet->mld2r.ngrec), length, ntohs (grec->grec_nsrcs)); - sendpacket6 (intn, (const struct ip6_hdr *) packet, length + sizeof (packet->ip6)); - - /* Increase ICMP sent statistics */ - g_conf->stat_icmp_sent++; - intn->stat_icmp_sent++; - - /* Reset the MLDv2 struct */ - packet->mld2r.ngrec = 0; - src = NULL; - grec = NULL; - //if not IS_EX or TO EXCLUDE_MODE splitting must be done - break; - } - - /* Only add non-:: addresses */ - if (!srcn) - break; - if (!IN6_IS_ADDR_UNSPECIFIED (sources + src_index) && srcn) { - /* First/Next address */ - src = (struct in6_addr *) (((char *) grec) + sizeof (*grec) + (sizeof (*src) * grec->grec_nsrcs)); - /* An additional source */ - grec->grec_nsrcs++; - if (mode) { - grec->grec_type = mode; //MLD2_MODE_IS_EXCLUDE; - } - /* Append the source address */ - memcpy (src, sources + src_index, sizeof (*src)); - } - } - } - - //fprintf(stdout,"done\n"); - if (packet->mld2r.ngrec == 0) { - //fprintf(stdout,"All data sent !!!!!!\n"); - free (packet); - packet = NULL; - return (1); - } - /* Take care of endianess */ - length = (((char *) grec) - ((char *) packet) + sizeof (*grec) + (sizeof (*src) * (grec->grec_nsrcs)) - sizeof (packet->ip6)); - packet->mld2r.ngrec = htons (packet->mld2r.ngrec); - grec->grec_nsrcs = htons (grec->grec_nsrcs); - - /* Calculate and fill in the checksum */ - packet->ip6.ip6_plen = htons (length); - packet->mld2r.csum = htons (0); - packet->mld2r.csum = ipv6_checksum (&packet->ip6, IPPROTO_ICMPV6, (uint8_t *) & packet->mld2r, length - sizeof (struct ip6_hbh) - sizeof (packet->routeralert)); - count++; - dbg ("%04d.Sending2 MLDv2 Report on %s/%u, ngrec=%u, length=%u sources=%u (in last grec)\n", count, intn->name, intn->ifindex, ntohs (packet->mld2r.ngrec), length, ntohs (grec->grec_nsrcs)); - sendpacket6 (intn, (const struct ip6_hdr *) packet, length + sizeof (packet->ip6)); - - /* Increase ICMP sent statistics */ - g_conf->stat_icmp_sent++; - intn->stat_icmp_sent++; - - free (packet); - //fprintf(stdout,"Total ICMP packets sent = %llu\n", intn->stat_icmp_sent ); - return 0; -} +(symlink to ../common/mld_client.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mld_common.c
Changed
@@ -1,243 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#include "headers.h" -struct conf *g_conf=NULL; - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -#ifdef DEBUG -struct lookup icmpv6_types[] = { - {ICMP6_DST_UNREACH, "Destination Unreachable"}, - {ICMP6_PACKET_TOO_BIG, "Packet too big"}, - {ICMP6_TIME_EXCEEDED, "Time Exceeded"}, - {ICMP6_PARAM_PROB, "Parameter Problem"}, - {ICMP6_ECHO_REQUEST, "Echo Request"}, - {ICMP6_ECHO_REPLY, "Echo Reply"}, - {ICMP6_MEMBERSHIP_QUERY, "Membership Query"}, - {ICMP6_MEMBERSHIP_REPORT, "Membership Report"}, - {ICMP6_MEMBERSHIP_REDUCTION, "Membership Reduction"}, - {ICMP6_V2_MEMBERSHIP_REPORT, "Membership Report (V2)"}, - {ICMP6_V2_MEMBERSHIP_REPORT_EXP, "Membership Report (V2) - Experimental"}, - {ND_ROUTER_SOLICIT, "ND Router Solicitation"}, - {ND_ROUTER_ADVERT, "ND Router Advertisement"}, - {ND_NEIGHBOR_SOLICIT, "ND Neighbour Solicitation"}, - {ND_NEIGHBOR_ADVERT, "ND Neighbour Advertisement"}, - {ND_REDIRECT, "ND Redirect"}, - {ICMP6_ROUTER_RENUMBERING, "Router Renumbering",}, - {ICMP6_NI_QUERY, "Node Information Query"}, - {ICMP6_NI_REPLY, "Node Information Reply"}, - {MLD_MTRACE_RESP, "Mtrace Response"}, - {MLD_MTRACE, "Mtrace Message"}, - {0, NULL}, -}, icmpv6_codes_unreach[] = { - {ICMP6_DST_UNREACH_NOROUTE, "No route to destination"}, - {ICMP6_DST_UNREACH_ADMIN, "Administratively prohibited"}, - {ICMP6_DST_UNREACH_NOTNEIGHBOR, "Not a neighbor (obsolete)"}, - {ICMP6_DST_UNREACH_BEYONDSCOPE, "Beyond scope of source address"}, - {ICMP6_DST_UNREACH_ADDR, "Address Unreachable"}, - {ICMP6_DST_UNREACH_NOPORT, "Port Unreachable"}, -}, icmpv6_codes_ttl[] = { - - {ICMP6_TIME_EXCEED_TRANSIT, "Time Exceeded during Transit",}, - {ICMP6_TIME_EXCEED_REASSEMBLY, "Time Exceeded during Reassembly"}, -}, icmpv6_codes_param[] = { - - {ICMP6_PARAMPROB_HEADER, "Erroneous Header Field"}, - {ICMP6_PARAMPROB_NEXTHEADER, "Unrecognized Next Header"}, - {ICMP6_PARAMPROB_OPTION, "Unrecognized Option"}, -}, icmpv6_codes_ni[] = { - - {ICMP6_NI_SUCCESS, "Node Information Successful Reply"}, - {ICMP6_NI_REFUSED, "Node Information Request Is Refused"}, - {ICMP6_NI_UNKNOWN, "Unknown Qtype"}, -}, icmpv6_codes_renumber[] = { - - {ICMP6_ROUTER_RENUMBERING_COMMAND, "Router Renumbering Command"}, - {ICMP6_ROUTER_RENUMBERING_RESULT, "Router Renumbering Result"}, - {ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET, "Router Renumbering Sequence Number Reset"}, -}, mld2_grec_types[] = { - - {MLD2_MODE_IS_INCLUDE, "MLDv2 Mode Is Include"}, - {MLD2_MODE_IS_EXCLUDE, "MLDv2 Mode Is Exclude"}, - {MLD2_CHANGE_TO_INCLUDE, "MLDv2 Change to Include"}, - {MLD2_CHANGE_TO_EXCLUDE, "MLDv2 Change to Exclude"}, - {MLD2_ALLOW_NEW_SOURCES, "MLDv2 Allow New Source"}, - {MLD2_BLOCK_OLD_SOURCES, "MLDv2 Block Old Sources"}, -}; -#endif - -//---------------------------------------------------------------------------------------------------------------- -const char *lookup (struct lookup *l, unsigned int num) -{ - unsigned int i; - for (i = 0; l && l[i].desc; i++) { - if (l[i].num != num) - continue; - return l[i].desc; - } - return "Unknown"; -} - -const char *icmpv6_type (unsigned int type) -{ -#ifdef DEBUG - return lookup (icmpv6_types, type); -#else - return ""; -#endif -} - -const char *icmpv6_code (unsigned int type, unsigned int code) -{ -#ifdef DEBUG - struct lookup *l = NULL; - switch (type) { - case ICMP6_DST_UNREACH: - l = icmpv6_codes_unreach; - break; - case ICMP6_TIME_EXCEEDED: - l = icmpv6_codes_ttl; - break; - case ICMP6_PARAM_PROB: - l = icmpv6_codes_param; - break; - case ICMP6_NI_QUERY: - case ICMP6_NI_REPLY: - l = icmpv6_codes_ni; - break; - case ICMP6_ROUTER_RENUMBERING: - l = icmpv6_codes_renumber; - break; - } - return lookup (l, code); -#else - return ""; -#endif -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -uint16_t inchksum (const void *data, uint32_t length) -{ - register long sum = 0; - register const uint16_t *wrd = (const uint16_t *) data; - register long slen = (long) length; - - while (slen >= 2) { - sum += *wrd++; - slen -= 2; - } - - if (slen > 0) - sum += *(const uint8_t *) wrd; - - while (sum >> 16) - sum = (sum & 0xffff) + (sum >> 16); - - return (uint16_t) sum; -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -uint16_t ipv6_checksum (const struct ip6_hdr * ip6, uint8_t protocol, const void *data, const uint16_t length) -{ - struct - { - uint16_t length; - uint16_t zero1; - uint8_t zero2; - uint8_t next; - } pseudo; - register uint32_t chksum = 0; - - pseudo.length = htons (length); - pseudo.zero1 = 0; - pseudo.zero2 = 0; - pseudo.next = protocol; - - /* IPv6 Source + Dest */ - chksum = inchksum (&ip6->ip6_src, sizeof (ip6->ip6_src) + sizeof (ip6->ip6_dst)); - chksum += inchksum (&pseudo, sizeof (pseudo)); - chksum += inchksum (data, length); - - /* Wrap in the carries to reduce chksum to 16 bits. */ - chksum = (chksum >> 16) + (chksum & 0xffff); - chksum += (chksum >> 16); - - /* Take ones-complement and replace 0 with 0xFFFF. */ - chksum = (uint16_t) ~ chksum; - if (chksum == 0UL) - chksum = 0xffffUL; - return (uint16_t) chksum; -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -void sendpacket6 (struct intnode *intn, const struct ip6_hdr *iph, const uint16_t len) -{ - int sent; -#if ! (defined WIN32 || defined APPLE) - struct sockaddr_ll sa; - - memset (&sa, 0, sizeof (sa)); - - sa.sll_family = AF_PACKET; - sa.sll_protocol = htons (ETH_P_IPV6); - sa.sll_ifindex = intn->ifindex; - sa.sll_hatype = intn->hwaddr.sa_family; - sa.sll_pkttype = 0; - sa.sll_halen = 6; - - /* - * Construct a Ethernet MAC address from the IPv6 destination multicast address. - * Per RFC2464 - */ - sa.sll_addr[0] = 0x33; - sa.sll_addr[1] = 0x33; - sa.sll_addr[2] = iph->ip6_dst.s6_addr[12]; - sa.sll_addr[3] = iph->ip6_dst.s6_addr[13]; - sa.sll_addr[4] = iph->ip6_dst.s6_addr[14]; - sa.sll_addr[5] = iph->ip6_dst.s6_addr[15]; - - /* Send the packet */ - errno = 0; - -#else -// info("Send on Interface %s@%d len:%d\n",intn->name, intn->ifindex, len); - struct sockaddr_in6 sa; - memset (&sa, 0, sizeof (sa)); - - sa.sin6_family = AF_INET6; - sa.sin6_addr = iph->ip6_dst; -#endif -#ifdef APPLE - unsigned char *x=(unsigned char *)iph; - sent = sendto (g_conf->rawsocket, (_SOTYPE)x+40, len-40, 0, (struct sockaddr *) &sa, sizeof (sa)); -#else - sent = sendto (g_conf->rawsocket, (_SOTYPE)iph, len, 0, (struct sockaddr *) &sa, sizeof (sa)); -#endif - if (sent < 0) { - /* - * Remove the device if it doesn't exist anymore, - * can happen with dynamic tunnels etc - */ - if (errno == ENXIO) { - warn ("Cannot send %u bytes on interface %s received ENXIO, interface %u no longer usable\n", len, intn->name, intn->ifindex); - /* Destroy the interface itself */ - int_destroy (intn); - } else - warn ("Cannot send %u bytes on interface %s (%d) failed with a mtu of %u: %s (errno %d)\n", len, intn->name, intn->ifindex, intn->mtu, strerror (errno), errno); - return; - } - - /* Update the global statistics */ - g_conf->stat_packets_sent++; - g_conf->stat_bytes_sent += len; - - /* Update interface statistics */ - intn->stat_bytes_sent += len; - intn->stat_packets_sent++; - return; -} +(symlink to ../common/mld_common.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mld_reporter.c
Changed
@@ -60,7 +60,11 @@ memset(&c, 0, sizeof(mld_reporter_context_t)); c.mld_mca_add=(struct in6_addr *)malloc(maxpids*sizeof(struct in6_addr)); + if (!c.mld_mca_add) + err ("mld_send_reports: out of memory\n"); c.mld_mca_drop=(struct in6_addr *)malloc(maxpids*sizeof(struct in6_addr)); + if (!c.mld_mca_drop) + err ("mld_send_reports: out of memory\n"); pthread_cleanup_push (clean_mld_send_reports_thread, &c); @@ -78,7 +82,11 @@ if(pids>maxpids) { maxpids=pids; c.mld_mca_add=(struct in6_addr *)realloc(c.mld_mca_add, pids*sizeof(struct in6_addr)); + if (!c.mld_mca_add) + err ("mld_send_reports: out of memory\n"); c.mld_mca_drop=(struct in6_addr *)realloc(c.mld_mca_drop, pids*sizeof(struct in6_addr)); + if (!c.mld_mca_drop) + err ("mld_send_reports: out of memory\n"); } //Send listener reports for all recently dropped MCGs
View file
vdr-mcli-plugin.tar.bz2/mcast/client/mmi_handler.c
Changed
@@ -130,14 +130,11 @@ int mmi_get_menu_text (int sockfd, char *buf, int buf_len, int timeout) { int n = -1; - fd_set rfds; - struct timeval tv; - FD_ZERO (&rfds); - FD_SET (sockfd, &rfds); - tv.tv_sec = 0; - tv.tv_usec = timeout; + struct pollfd p; memset (buf, 0, buf_len); - if (select (sockfd + 1, &rfds, NULL, NULL, &tv) > 0) { + p.fd = sockfd; + p.events = POLLIN; + if (poll (&p, 1, (timeout+999)>>10) > 0) { n = recv (sockfd, buf, buf_len, 0); //MSG_DONTWAIT); } if (n > 0) { @@ -298,6 +295,8 @@ mcg_get_id (&mcg, &sid); mcg_set_id (&mcg, 0); mmi_info->caids = (caid_mcg_t *) realloc (mmi_info->caids, sizeof (caid_mcg_t) * (mmi_info->caid_num + 1)); + if (!mmi_info->caids) + err ("mmi_get_data: out of memory\n"); caid_mcg_t *cm = mmi_info->caids + mmi_info->caid_num; cm->caid = sid; cm->mcg = mcg;
View file
vdr-mcli-plugin.tar.bz2/mcast/client/poll.c
Added
+(symlink to ../common/win32/poll.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/recv_ccpp.c
Changed
@@ -1,1329 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#undef DEBUG -#include "headers.h" - -extern int port; -extern char iface[IFNAMSIZ]; - -typedef struct -{ - xmlDocPtr doc; - xmlChar *str, *key; -} xml_parser_context_t; - -STATIC void clean_xml_parser_thread (void *arg) -{ - xml_parser_context_t *c = (xml_parser_context_t *) arg; - if (c->str) { - xmlFree (c->str); - } - if (c->key) { - xmlFree (c->key); - } - if (c->doc) { - xmlFreeDoc (c->doc); - } - dbg ("Free XML parser structures!\n"); -} - -int get_tra_data (xmlChar * xmlbuff, int buffersize, tra_info_t * tra_info) -{ - xml_parser_context_t c; - xmlNode *root_element = NULL, *cur_node = NULL; - - xmlKeepBlanksDefault (0); //reomve this f. "text" nodes - c.doc = xmlParseMemory ((char *) xmlbuff, buffersize); - root_element = xmlDocGetRootElement (c.doc); - pthread_cleanup_push (clean_xml_parser_thread, &c); - time_t t=time(NULL); - - if (root_element != NULL) { - - cur_node = root_element->children; - - if (!xmlStrcmp (cur_node->name, (xmlChar *) "Description")) { - - root_element = cur_node->children; - while (root_element != NULL) { - c.key = NULL; - c.str = NULL; - if ((xmlStrcmp (root_element->name, (const xmlChar *) "component"))) { - warn ("Cannot parse XML data\n"); - root_element = root_element->next; - continue; - } - - cur_node = root_element->children; - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Description"))) { - c.str = xmlGetProp (cur_node, (unsigned char *) "about"); -// fprintf(stdout,"\n%s:\n",c.str); -// fprintf(stdout,"-----------------------------------------------------------\n"); - } else { - warn ("Cannot parse XML data\n"); - root_element = root_element->next; - continue; - } -#ifdef P2P - if (c.str && (!xmlStrcmp (c.str, (const xmlChar *) "P2P_Data"))) { - cur_node = cur_node->children; - while (cur_node != NULL) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Quit"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Quit: %s\n", c.key); - tra_info->quit = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "TCA_ID"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("TCA_ID: %s\n", c.key); - tra_info->tca_id = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "MC_Groups"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("MC_Groups: %s\n", c.key); - tra_info->mca_grps = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "IP"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("IP: %s\n", c.key); - inet_pton (AF_INET6, (char *) c.key, &tra_info->ipv6); - xmlFree (c.key); - } - } - cur_node = cur_node->next; - } - } else if (c.str && (!xmlStrcmp (c.str, (const xmlChar *) "Tuner_Status"))) { -#else - if (c.str && (!xmlStrcmp (c.str, (const xmlChar *) "Tuner_Status"))) { -#endif - cur_node = cur_node->children; - tra_info->tra = (tra_t *) realloc (tra_info->tra, (tra_info->tra_num + 1) * sizeof (tra_t)); - if (!tra_info->tra) { - err ("Cannot get memory for tra_t\n"); - } - tra_t *tra = tra_info->tra + tra_info->tra_num; - memset(tra, 0, sizeof (tra_t)); - tra->magic=MCLI_MAGIC; - tra->version=MCLI_VERSION; - - while (cur_node != NULL) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Status"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Status: %s\n", c.key); - tra->s.st = (fe_status_t) atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Signal"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Signal: %s\n", c.key); - tra->s.strength = (u_int16_t) atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SNR"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("SNR: %s\n", c.key); - tra->s.snr = (u_int16_t) atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "BER"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("BER: %s\n", c.key); - tra->s.ber = (u_int32_t) atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "UNC"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("UNC: %s\n", c.key); - tra->s.ucblocks = (u_int32_t) atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Slot"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Slot: %s\n", c.key); - tra->slot = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "RotorStatus"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Rotor: %s\n", c.key); - tra->rotor_status = (u_int32_t) atoi ((char *) c.key); - xmlFree (c.key); - } - - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "RotorDiff"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Rotor: %s\n", c.key); - tra->rotor_diff = (u_int32_t) atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "UUID"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("UUID: %s\n", c.key); - strncpy (tra->uuid, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "MCG"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("MCG: %s\n", c.key); - inet_pton (AF_INET6, (char *) c.key, &tra->mcg); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Redirect"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Redirect: %s\n", c.key); - tra->redirect = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "NIMCurrent"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("NIMCurrent: %s\n", c.key); - tra->NIMCurrent = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "InUse"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("InUse: %s\n", c.key); - tra->InUse = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Frequency"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Frequency: %s\n", c.key); - tra->fep.frequency = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Inversion"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Inversion: %s\n", c.key); - tra->fep.inversion = (fe_spectral_inversion_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Type"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Type: %s\n", c.key); - tra->fe_type = (fe_type_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } -#ifdef P2P - else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Token"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Token: %s\n", c.key); - tra->token = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Preference"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Preference: %s\n", c.key); - tra->preference = atoi ((char *) c.key); - xmlFree (c.key); - } - } -#endif - else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SymbolRate"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("SymbolRate: %s\n", c.key); - int val=atoi ((char *) c.key); - switch(tra->fe_type) { - case FE_DVBS2: - case FE_QPSK: - tra->fep.u.qpsk.symbol_rate=val; - break; - case FE_QAM: - tra->fep.u.qam.symbol_rate=val; - break; - case FE_OFDM: - default: - break; - } - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "FecInner"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("FecInner: %s\n", c.key); - int val=atoi ((char *) c.key); - switch(tra->fe_type) { - case FE_DVBS2: - case FE_QPSK: - tra->fep.u.qpsk.fec_inner=(fe_code_rate_t)val; - break; - case FE_QAM: - tra->fep.u.qam.fec_inner=(fe_code_rate_t)val; - break; - case FE_OFDM: - default: - break; - } - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Modulation"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Modulation: %s\n", c.key); - int val=atoi ((char *) c.key); - switch(tra->fe_type) { - case FE_QAM: - tra->fep.u.qam.modulation=(fe_modulation_t)val; - break; - case FE_ATSC: - tra->fep.u.vsb.modulation=(fe_modulation_t)val; - break; - case FE_DVBS2: - case FE_QPSK: - case FE_OFDM: - default: - break; - - } - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Bandwidth"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Bandwidth: %s\n", c.key); - tra->fep.u.ofdm.bandwidth=(fe_bandwidth_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "CodeRateHP"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("CodeRateHP: %s\n", c.key); - tra->fep.u.ofdm.code_rate_HP=(fe_code_rate_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "CodeRateLP"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("CodeRateLP: %s\n", c.key); - tra->fep.u.ofdm.code_rate_LP=(fe_code_rate_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Constellation"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Constellation: %s\n", c.key); - tra->fep.u.ofdm.constellation=(fe_modulation_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "TransmissionMode"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("TransmissionMode: %s\n", c.key); - tra->fep.u.ofdm.transmission_mode=(fe_transmit_mode_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "GuardInterval"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("GuardInterval: %s\n", c.key); - tra->fep.u.ofdm.guard_interval=(fe_guard_interval_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "HierarchyInformation"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("HierarchyInformation: %s\n", c.key); - tra->fep.u.ofdm.hierarchy_information=(fe_hierarchy_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } - cur_node = cur_node->next; - } - tra->lastseen=t; - tra_info->tra_num++; - } else if (c.str && (!xmlStrcmp (c.str, (const xmlChar *) "CAM"))) { - cur_node = cur_node->children; - cam_info_t *cam = tra_info->cam + tra_info->cam_num; - while(cur_node) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Slot"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->slot = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Status"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->status = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "MenuString"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - strncpy(cam->menu_string, (char *) c.key, MAX_MENU_STR_LEN-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Flags"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->flags = (nc_ca_caps_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "MaxSids"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->max_sids = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "UseSids"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->use_sids = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "PmtFlag"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->capmt_flag = atoi ((char *) c.key); - xmlFree (c.key); - } - } - cur_node = cur_node->next; - } - tra_info->cam_num++; - } - xmlFree (c.str); - root_element = root_element->next; - } - } - } - xmlFreeDoc (c.doc); - pthread_cleanup_pop (0); - return (1); -} - -#ifdef CLIENT -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -typedef struct ccpp_thread_context -{ - UDPContext *s; - xmlChar *buf; - xmlChar *dst; - int run; -} ccpp_thread_context_t; - - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -STATIC void clean_ccpp_thread (void *arg) -{ - ccpp_thread_context_t *c = (ccpp_thread_context_t *) arg; - if (c->s) { -#ifdef MULTI_THREAD_RECEIVER - udp_close (c->s); -#else - udp_close_buff (c->s); -#endif - } - if(c->buf) { - free (c->buf); - } - if(c->dst) { - free (c->dst); - } - dbg ("CCPP thread data buffer for tid %d freed !\n", gettid ()); -} - -void *recv_ten (void *arg) -{ - recv_info_t *r = (recv_info_t *) arg; - ccpp_thread_context_t c; - struct in6_addr ten = r->mcg; - int n; - tra_info_t tra_info; - unsigned int dstlen; - clock_t lastrecv=0; - int donetimeout=0; - - pthread_cleanup_push (clean_ccpp_thread, &c); - memset (&c, 0, sizeof (ccpp_thread_context_t)); - - c.buf=(xmlChar *)malloc(XML_BUFLEN); - if (!c.buf) { - err ("Cannot get memory for TEN buffer\n"); - } - c.dst=(xmlChar *)malloc(XML_BUFLEN * 5); - if (!c.dst) { - err ("Cannot get memory for TEN destination buffer\n"); - } - -#ifdef FE_STATUS_CLEAR - memset (&r->fe_status, 0, sizeof(recv_festatus_t)); - ioctl (r->fd, DVBLO_SET_FRONTEND_STATUS, &r->fe_status); -#endif - memset (&tra_info, 0, sizeof (tra_info_t)); - tra_info.magic=MCLI_MAGIC; - tra_info.version=MCLI_VERSION; - - mcg_set_streaming_group (&ten, STREAMING_TEN); -#ifdef MULTI_THREAD_RECEIVER - c.s = client_udp_open (&ten, port, iface); -#else - c.s = client_udp_open_buff (&ten, port, iface, XML_BUFLEN); -#endif - if (!c.s) { - warn ("client_udp_open error !\n"); - } else { -#ifdef DEBUG - char host[INET6_ADDRSTRLEN]; - inet_ntop (AF_INET6, &ten, (char *) host, INET6_ADDRSTRLEN); - dbg ("Start receive TEN for tid %d receiver %p at %s port %d %s\n", gettid (), r, host, port, iface); -#endif - r->ten_run = 1; - while (r->ten_run) { -#ifdef MULTI_THREAD_RECEIVER - if ((n = udp_read (c.s, c.buf, XML_BUFLEN, 1000, NULL)) > 0) { -#else - usleep(100000); // 10 times per seconds should be enough - if ((n = udp_read_buff (c.s, c.buf, XML_BUFLEN, 1000, NULL)) > 0) { -#endif - dstlen = XML_BUFLEN*5; - if (!gunzip (c.dst, &dstlen, c.buf, n)) { - memset (&tra_info, 0, sizeof (tra_info_t)); - tra_info.magic=MCLI_MAGIC; - tra_info.version=MCLI_VERSION; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - if (get_tra_data (c.dst, dstlen, &tra_info)) { - lastrecv=clock(); - donetimeout=0; - if (tra_info.tra_num) { - r->fe_status = tra_info.tra->s; - if(r->handle_ten) { - r->handle_ten (tra_info.tra, r->handle_ten_context); - } - - if (tra_info.tra->redirect) { -#ifdef DEBUG - char hostname[INET6_ADDRSTRLEN]; - inet_ntop (AF_INET6, &tra_info.tra->mcg, hostname, INET6_ADDRSTRLEN); - dbg ("Redirect for receiver %p: MCG is at %s\n", r, hostname); -#endif - int ret = recv_redirect (r, tra_info.tra->mcg); - - if (ret) { - printf("New MCG for recv_ten !\n"); -#ifdef MULTI_THREAD_RECEIVER - udp_close (c.s); -#else - udp_close_buff (c.s); -#endif - struct in6_addr ten = r->mcg; - mcg_set_streaming_group (&ten, STREAMING_TEN); -#ifdef MULTI_THREAD_RECEIVER - c.s = client_udp_open (&ten, port, iface); -#else - c.s = client_udp_open_buff (&ten, port, iface, XML_BUFLEN); -#endif - if (!c.s) { - warn ("client_udp_open error !\n"); - break; - } - } - } - } - free (tra_info.tra); - tra_info.tra=NULL; - } - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - } else { - dbg ("uncompress failed\n"); - } - } else { - if (!donetimeout && (clock()-lastrecv)>(TEN_TIMEOUT*CLOCKS_PER_SEC)) { - donetimeout=1; - memset (&r->fe_status, 0, sizeof(recv_festatus_t)); - if(r->handle_ten) { - r->handle_ten (NULL, r->handle_ten_context); - } - dbg ("Signal Timeout on receiver %p!\n", r); - } - } - pthread_testcancel(); - } -#ifdef DEBUG - dbg ("Stop receive TEN on receiver %p %s %d %s\n", r, host, port, iface); -#endif - } - pthread_cleanup_pop (1); - r->ten_run = 1; - return NULL; -} - -int register_ten_handler (recv_info_t * r, int (*p) (tra_t *, void *c), void *c) -{ - r->handle_ten=p; - r->handle_ten_context=c; - return 0; -} - -void *recv_tra (void *arg) -{ - ccpp_thread_context_t c; - int n; - tra_info_t tra_info; - unsigned int dstlen; - struct in6_addr tra; - - pthread_cleanup_push (clean_ccpp_thread, &c); - memset (&c, 0, sizeof (ccpp_thread_context_t)); - - c.buf=(xmlChar *)malloc(XML_BUFLEN); - if (!c.buf) { - err ("Cannot get memory for TRA buffer\n"); - } - c.dst=(xmlChar *)malloc(XML_BUFLEN * 5); - if (!c.dst) { - err ("Cannot get memory for TRA destination buffer\n"); - } - - mcg_init_streaming_group (&tra, STREAMING_TRA); - -#ifdef MULTI_THREAD_RECEIVER - c.s = client_udp_open (&tra, port, iface); -#else - c.s = client_udp_open_buff (&tra, port, iface, XML_BUFLEN); -#endif - if (!c.s) { - warn ("client_udp_open error !\n"); - } else { - c.run=1; -#ifdef DEBUG - char host[INET6_ADDRSTRLEN]; - inet_ntop (AF_INET6, &tra, (char *) host, INET6_ADDRSTRLEN); - dbg ("Start receive TRA at %s port %d %s\n", host, port, iface); -#endif - while (c.run) { -#ifdef MULTI_THREAD_RECEIVER - if ((n = udp_read (c.s, c.buf, XML_BUFLEN, 500000, NULL)) > 0) { -#else - usleep(100000); // 10 times per seconds should be enough - if ((n = udp_read_buff (c.s, c.buf, XML_BUFLEN, 500000, NULL)) > 0) { -#endif - dstlen = XML_BUFLEN*5; - if (!gunzip (c.dst, &dstlen, c.buf, n)) { - memset (&tra_info, 0, sizeof (tra_info_t)); - tra_info.magic=MCLI_MAGIC; - tra_info.version=MCLI_VERSION; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - if (get_tra_data (c.dst, dstlen, &tra_info)) { - handle_tra (&tra_info); - } - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - } else { - dbg ("uncompress failed\n"); - } - } -#ifdef DEBUG - dbg ("Stop receive TRA on %s %d %s len:%d\n", host, port, iface, n); -#endif - pthread_testcancel(); - } - } - pthread_cleanup_pop (1); - return NULL; -} -#endif - -//-------------------------------------------------------------------------------------------------------------------------- -int get_tca_data (xmlChar * xmlbuff, int buffersize, netceiver_info_t * nc_info) -{ - xml_parser_context_t c; - xmlNode *root_element, *cur_node; - - xmlKeepBlanksDefault (0); //reomve this f. "text" nodes - c.doc = xmlParseMemory ((char *) xmlbuff, buffersize); - root_element = xmlDocGetRootElement (c.doc); - pthread_cleanup_push (clean_xml_parser_thread, &c); - nc_info->magic=MCLI_MAGIC; - nc_info->version=MCLI_VERSION; - - if (root_element != NULL) { - cur_node = root_element->children; - - if (!xmlStrcmp (cur_node->name, (xmlChar *) "Description")) { - - root_element = cur_node->children; - while (root_element != NULL) { - c.key = NULL; - c.str = NULL; - if ((xmlStrcmp (root_element->name, (const xmlChar *) "component"))) { - warn ("Cannot parse XML data\n"); - root_element = root_element->next; - continue; - } - - cur_node = root_element->children; - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Description"))) { - c.str = xmlGetProp (cur_node, (unsigned char *) "about"); - } else { - warn ("Cannot parse XML data\n"); - root_element = root_element->next; - continue; - } - if (c.str && (!xmlStrcmp (c.str, (const xmlChar *) "Platform"))) { - cur_node = cur_node->children; - while (cur_node != NULL) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "OSVersion"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("OSVersion: %s\n", c.key); - strncpy (nc_info->OSVersion, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "AppVersion"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("AppVersion: %s\n", c.key); - strncpy (nc_info->AppVersion, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "FirmwareVersion"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("FirmwareVersion: %s\n", c.key); - strncpy (nc_info->FirmwareVersion, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "HardwareVersion"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("HardwareVersion: %s\n", c.key); - strncpy (nc_info->HardwareVersion, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Serial"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Serial: %s\n", c.key); - strncpy (nc_info->Serial, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Vendor"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Vendor: %s\n", c.key); - strncpy (nc_info->Vendor, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "DefCon"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("DefCon: %s\n", c.key); - nc_info->DefCon = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "UUID"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("UUID: %s\n", c.key); - strncpy (nc_info->uuid, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Description"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("Description: %s\n", c.key); - strncpy (nc_info->Description, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "IP"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("IP: %s\n", c.key); - inet_pton (AF_INET6, (char *) c.key, &nc_info->ip); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "ProcessUptime"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("ProcessUptime: %s\n", c.key); - nc_info->ProcessUptime=atoi((char *)c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SystemUptime"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("SystemUptime: %s\n", c.key); - nc_info->SystemUptime=atoi((char *)c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "TunerTimeout"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("TunerTimeout: %s\n", c.key); - nc_info->TunerTimeout=atoi((char *)c.key); - xmlFree (c.key); - } - } - cur_node = cur_node->next; - } - } else if (c.str && (!xmlStrcmp (c.str, (const xmlChar *) "Tuner"))) { - cur_node = cur_node->children; - nc_info->tuner = (tuner_info_t *) realloc (nc_info->tuner, (nc_info->tuner_num + 1) * sizeof (tuner_info_t)); - if (!nc_info->tuner) { - err ("Cannot get memory for tuner_info\n"); - } - - tuner_info_t *t = nc_info->tuner + nc_info->tuner_num; - memset (t, 0, sizeof (tuner_info_t)); - t->magic=MCLI_MAGIC; - t->version=MCLI_VERSION; - - while (cur_node != NULL) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Name"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - strncpy (t->fe_info.name, (char *) c.key, 127); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Type"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - if ((!xmlStrcmp (c.key, (const xmlChar *) "DVB-S"))) - t->fe_info.type = FE_QPSK; - if ((!xmlStrcmp (c.key, (const xmlChar *) "DVB-S2"))) - t->fe_info.type = (fe_type_t)FE_DVBS2; - if ((!xmlStrcmp (c.key, (const xmlChar *) "DVB-C"))) - t->fe_info.type = FE_QAM; - if ((!xmlStrcmp (c.key, (const xmlChar *) "DVB-T"))) - t->fe_info.type = FE_OFDM; - if ((!xmlStrcmp (c.key, (const xmlChar *) "ATSC"))) - t->fe_info.type = FE_ATSC; - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "FrequencyMin"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.frequency_min = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "FrequencyMax"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.frequency_max = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "FrequencyStepSize"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.frequency_stepsize = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "FrequencyTolerance"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.frequency_tolerance = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SymbolRateMin"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.symbol_rate_min = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SymbolRateMax"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.symbol_rate_max = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SymbolRateTolerance"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.symbol_rate_tolerance = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Caps"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->fe_info.caps = (fe_caps_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Slot"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->slot = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Preference"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - t->preference = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "UUID"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - strncpy (t->uuid, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SatelliteListName"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - strncpy (t->SatelliteListName, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } - cur_node = cur_node->next; - } - nc_info->tuner_num++; - } else if (c.str && !(xmlStrcmp (c.str, (xmlChar *) "CI"))) { - cur_node = cur_node->children; - recv_cacaps_t *ci=&nc_info->ci; - while(cur_node) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "component"))) { - xmlNode *l2_node = cur_node->children; - if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "Description"))) { - c.key = xmlGetProp (l2_node, (unsigned char *) "about"); - dbg ("Parsing CI-Description: %s\n", c.key); - if (c.key && !xmlStrcmp (c.key, (xmlChar *) "Capabilities")) { - xmlFree (c.key); - xmlNode * l3_node = l2_node->children; - while (l3_node != NULL) { - dbg ("Capability-Element: %s\n", l3_node->name); - if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "SlotNum"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("SlotNum: %s\n", c.key); - ci->cap.slot_num=atoi((char*)c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "SlotType"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("SlotType: %s\n", c.key); - ci->cap.slot_type=atoi((char*)c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "DescrNum"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("DescrNum: %s\n", c.key); - ci->cap.descr_num=atoi((char*)c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "DescrType"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("DescrType: %s\n", c.key); - ci->cap.descr_type=atoi((char*)c.key); - xmlFree (c.key); - } - } - l3_node = l3_node->next; - } - } else if (c.key && !xmlStrcmp (c.key, (xmlChar *) "Slot")) { - xmlFree (c.key); - xmlNode *l3_node = l2_node->children; - int slot=-1; - while (l3_node != NULL) { - dbg ("Slot-Element: %s\n", l3_node->name); - if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "Num"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Num: %s\n", c.key); - int x=atoi((char*)c.key); - if( (x < 0) || (x >= CA_MAX_SLOTS) ) { - continue; - } - slot=x; - ci->info[slot].num=slot; - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "Type"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Type: %s\n", c.key); - if(slot>=0) { - ci->info[slot].type=atoi((char*)c.key); - } - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "Flags"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Flags: %s\n", c.key); - if(slot>=0) { - ci->info[slot].flags=atoi((char*)c.key); - } - xmlFree (c.key); - } - } - l3_node = l3_node->next; - } - } - } - } - cur_node = cur_node->next; - } - //CAM start - } else if (c.str && !(xmlStrcmp (c.str, (xmlChar *) "CAM"))) { - cur_node = cur_node->children; - cam_info_t *cam = nc_info->cam + nc_info->cam_num; - while(cur_node) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Slot"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->slot = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Status"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->status = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "MenuString"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - strncpy(cam->menu_string, (char *) c.key, MAX_MENU_STR_LEN-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "Flags"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->flags = (nc_ca_caps_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "MaxSids"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->max_sids = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "UseSids"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->use_sids = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "PmtFlag"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - cam->capmt_flag = atoi ((char *) c.key); - xmlFree (c.key); - } - } - cur_node = cur_node->next; - } - nc_info->cam_num++; - //CAM end - } else if (c.str && !(xmlStrcmp (c.str, (xmlChar *) "SatelliteList"))) { - cur_node = cur_node->children; - nc_info->sat_list = (satellite_list_t *) realloc (nc_info->sat_list, (nc_info->sat_list_num + 1) * sizeof (satellite_list_t)); - if (!nc_info->sat_list) { - err ("Cannot get memory for sat_list\n"); - } - - satellite_list_t *sat_list = nc_info->sat_list + nc_info->sat_list_num; - memset (sat_list, 0, sizeof (satellite_list_t)); - sat_list->magic=MCLI_MAGIC; - sat_list->version=MCLI_VERSION; - - while (cur_node != NULL) { - if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "SatelliteListName"))) { - c.key = xmlNodeListGetString (c.doc, cur_node->xmlChildrenNode, 1); - if (c.key) { - dbg ("SatelliteListName: %s\n", c.key); - strncpy (sat_list->Name, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (cur_node->name, (const xmlChar *) "component"))) { - xmlNode *l2_node = cur_node->children; - if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "Description"))) { - c.key = xmlGetProp (l2_node, (unsigned char *) "about"); - dbg ("Parsing L2-Description: %s\n", c.key); - if (c.key && !xmlStrcmp (c.key, (xmlChar *) "Satellite")) { - xmlFree (c.key); - l2_node = l2_node->children; - sat_list->sat = (satellite_info_t *) realloc (sat_list->sat, (sat_list->sat_num + 1) * sizeof (satellite_info_t)); - if (!sat_list->sat) { - err ("Cannot get memory for sat\n"); - } - - satellite_info_t *sat = sat_list->sat + sat_list->sat_num; - memset (sat, 0, sizeof (satellite_info_t)); - sat->magic=MCLI_MAGIC; - sat->version=MCLI_VERSION; - - while (l2_node != NULL) { - dbg ("L2-Element: %s\n", l2_node->name); - if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "Name"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Name: %s\n", c.key); - strncpy (sat->Name, (char *) c.key, UUID_SIZE-1); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "Position"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Position: %s\n", c.key); - sat->SatPos = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "PositionMin"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("PositionMin: %s\n", c.key); - sat->SatPosMin = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "PositionMax"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("PositionMax: %s\n", c.key); - sat->SatPosMax = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "AutoFocus"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("AutoFocus: %s\n", c.key); - sat->AutoFocus = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "Latitude"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Latitude: %s\n", c.key); - sat->Latitude = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "Longitude"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Longitude: %s\n", c.key); - sat->Longitude = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "Type"))) { - c.key = xmlNodeListGetString (c.doc, l2_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Type: %s\n", c.key); - sat->type = (satellite_source_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l2_node->name, (const xmlChar *) "component"))) { - xmlNode *l3_node = l2_node->children; - - if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "Description"))) { - c.key = xmlGetProp (l3_node, (unsigned char *) "about"); - dbg ("Parsing L3-Description: %s\n", c.key); - if (c.key && !xmlStrcmp (c.key, (xmlChar *) "SatelliteComponent")) { - xmlFree (c.key); - l3_node = l3_node->children; - dbg ("Now checking for SatelliteCompontents\n"); - sat->comp = (satellite_component_t *) realloc (sat->comp, (sat->comp_num + 1) * sizeof (satellite_component_t)); - if (!sat->comp) { - err ("Cannot get memory for comp\n"); - } - - satellite_component_t *comp = sat->comp + sat->comp_num; - memset (comp, 0, sizeof (satellite_component_t)); - comp->magic=MCLI_MAGIC; - comp->version=MCLI_VERSION; - - while (l3_node != NULL) { - dbg ("L3-Element: %s\n", l3_node->name); - if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "Polarisation"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Polarisation: %s\n", c.key); - comp->Polarisation = (polarisation_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "RangeMin"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("RangeMin: %s\n", c.key); - comp->RangeMin = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "RangeMax"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("RangeMax: %s\n", c.key); - comp->RangeMax = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "LOF"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("LOF: %s\n", c.key); - comp->LOF = atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "Voltage"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Voltage: %s\n", c.key); - comp->sec.voltage = (fe_sec_voltage_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "Tone"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("Tone: %s\n", c.key); - comp->sec.tone_mode = (fe_sec_tone_mode_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "MiniCmd"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - if(c.key) { - dbg ("MiniCmd: %s\n", c.key); - comp->sec.mini_cmd = (fe_sec_mini_cmd_t)atoi ((char *) c.key); - xmlFree (c.key); - } - } else if ((!xmlStrcmp (l3_node->name, (const xmlChar *) "DiSEqC_Cmd"))) { - c.key = xmlNodeListGetString (c.doc, l3_node->xmlChildrenNode, 1); - dbg ("DiSEqC_Cmd: %s\n", c.key); - if(c.key) { - int v[6], i, n=0; - char *s= (char *)c.key; - struct dvb_diseqc_master_cmd *diseqc_cmd=&comp->sec.diseqc_cmd; - do { - dbg("Parsing: %s\n",s); - diseqc_cmd->msg_len = sscanf (s, "%x %x %x %x %x %x", v, v + 1, v + 2, v + 3, v + 4, v + 5); - for (i = 0; i < diseqc_cmd->msg_len; i++) { - diseqc_cmd->msg[i] = v[i]; - } - s=strchr(s,','); - if(s) { - s++; - } - diseqc_cmd=comp->diseqc_cmd+n; - n++; - } while(s && n<=DISEQC_MAX_EXTRA); - xmlFree (c.key); - comp->diseqc_cmd_num=n; - } - } - l3_node = l3_node->next; - } - sat->comp_num++; - } else { - xmlFree (c.key); - } - } - } - l2_node = l2_node->next; - } - sat_list->sat_num++; - } else { - xmlFree (c.key); - } - } - } - cur_node = cur_node->next; - } - nc_info->sat_list_num++; - } - xmlFree (c.str); - root_element = root_element->next; - } - } - } - - xmlFreeDoc (c.doc); - pthread_cleanup_pop (0); - return (1); -} - -#ifdef CLIENT - -void *recv_tca (void *arg) -{ - int n; - ccpp_thread_context_t c; - unsigned int dstlen; - netceiver_info_t nc_info; - struct in6_addr tca; - - pthread_cleanup_push (clean_ccpp_thread, &c); - - c.buf=(xmlChar *)malloc(XML_BUFLEN); - if (!c.buf) { - err ("Cannot get memory for TRA buffer\n"); - } - c.dst=(xmlChar *)malloc(XML_BUFLEN * 5); - if (!c.dst) { - err ("Cannot get memory for TRA destination buffer\n"); - } - - mcg_init_streaming_group (&tca, STREAMING_TCA); - -#ifdef MULTI_THREAD_RECEIVER - c.s = client_udp_open (&tca, port, iface); -#else - c.s = client_udp_open_buff (&tca, port, iface, XML_BUFLEN); -#endif - if (!c.s) { - warn ("client_udp_open error !\n"); - } else { - c.run=1; -#ifdef DEBUG - char host[INET6_ADDRSTRLEN]; - inet_ntop (AF_INET6, &tca, (char *) host, INET6_ADDRSTRLEN); - dbg ("Start Receive TCA on interface %s port %d\n", iface, port); -#endif - while (c.run) { -#ifdef MULTI_THREAD_RECEIVER - if ((n = udp_read (c.s, c.buf, XML_BUFLEN, 500000, NULL)) > 0) { -#else - usleep(100000); // 10 times per seconds should be enough - if ((n = udp_read_buff (c.s, c.buf, XML_BUFLEN, 500000, NULL)) > 0) { -#endif - dstlen = XML_BUFLEN * 5; - if (!gunzip (c.dst, &dstlen, c.buf, n)) { - memset (&nc_info, 0, sizeof (netceiver_info_t)); - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - get_tca_data (c.dst, dstlen, &nc_info); - handle_tca (&nc_info); - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - } else { - dbg ("uncompress failed\n"); - } - } - pthread_testcancel(); - } - } - pthread_cleanup_pop (1); - return NULL; -} -#endif +(symlink to ../common/recv_ccpp.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/recv_tv.c
Changed
@@ -146,29 +146,28 @@ if (n >0 ) { pid_info_t *p = (pid_info_t *) arg; recv_info_t *r = p->recv; - unsigned char *ptr = buf; - if (n % 188) { - warn ("Received %d bytes is not multiple of 188!\n", n); - } int i; - for (i = 0; i < (n / 188); i++) { - unsigned char *ts = buf + (i * 188); + for (i = 0; i < n; i += 188) { + unsigned char *ts = buf + i; int adaption_field = (ts[3] >> 4) & 3; int cont = ts[3] & 0xf; int pid = ((ts[1] << 8) | ts[2]) & 0x1fff; int transport_error_indicator = ts[1]&0x80; if (pid != 8191 && (adaption_field & 1) && (((p->cont_old + 1) & 0xf) != cont) && p->cont_old >= 0) { - warn ("Discontinuity on receiver %p for pid %d: %d->%d at pos %d/%d\n", r, pid, p->cont_old, cont, i, n / 188); + warn ("Discontinuity on receiver %p for pid %d: %d->%d at pos %d/%d\n", r, pid, p->cont_old, cont, i / 188, n / 188); } if (transport_error_indicator) { - warn ("Transport error indicator set on receiver %p for pid %d: %d->%d at pos %d/%d\n", r, pid, p->cont_old, cont, i, n / 188); + warn ("Transport error indicator set on receiver %p for pid %d: %d->%d at pos %d/%d\n", r, pid, p->cont_old, cont, i / 188, n / 188); } p->cont_old = cont; } + if (i != n) { + warn ("Received %d bytes is not multiple of 188!\n", n); + } if(r->handle_ts) { while (n) { - int res = r->handle_ts (ptr, n, r->handle_ts_context); + int res = r->handle_ts (buf, n, r->handle_ts_context); if (res != n) { warn ("Not same amount of data written: res:%d<=n:%d\n", res, n); } @@ -177,7 +176,7 @@ perror ("Write failed"); break; } else { - ptr += res; + buf += res; n -= res; } } @@ -520,6 +519,7 @@ //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #ifdef RE +#if 0 static int find_redirected_sid (recv_info_t * r, int id) { pid_info_t *slot; @@ -531,6 +531,7 @@ return 0; } +#endif int check_if_already_redirected(recv_info_t *r, int sid) {
View file
vdr-mcli-plugin.tar.bz2/mcast/client/satlists.c
Changed
@@ -49,7 +49,7 @@ sat->SatPosMin, newpos , sat->SatPosMax, newpos); // Check if coded sat pos matches - if (sat->type==SAT_SRC_LNB && mode == 0 && sec->diseqc_cmd.msg_len>0 && + if ((sat->type==SAT_SRC_LNB || sat->type==SAT_SRC_UNI) && mode == 0 && sec->diseqc_cmd.msg_len>0 && (freq >= comp->RangeMin) && (freq <= comp->RangeMax) && !memcmp (buf, &sec->diseqc_cmd.msg, sec->diseqc_cmd.msg_len)) { dbg("Satpos MATCH\n"); @@ -70,7 +70,7 @@ comp->sec.diseqc_cmd.msg[0], comp->sec.diseqc_cmd.msg[1], comp->sec.diseqc_cmd.msg[2], comp->sec.diseqc_cmd.msg[3], comp->sec.diseqc_cmd.msg[4], comp->sec.diseqc_cmd.msg[5]); ret=1; - }else if (mode == 2 && comp->Polarisation == sec->voltage && comp->sec.tone_mode== sec->tone_mode && comp->sec.mini_cmd == sec->mini_cmd) { + }else if (mode == 2 && (fe_sec_voltage_t)comp->Polarisation == sec->voltage && comp->sec.tone_mode== sec->tone_mode && comp->sec.mini_cmd == sec->mini_cmd) { dbg("Legacy Match, pol %i, tone %i, cmd %i\n",comp->Polarisation,comp->sec.tone_mode,comp->sec.mini_cmd); ret=1; }
View file
vdr-mcli-plugin.tar.bz2/mcast/client/tools.c
Changed
@@ -1,777 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#define DEBUG 1 -#include "headers.h" - -#ifdef DEBUG -const Param inversion_list[] = { - {"INVERSION_OFF", INVERSION_OFF}, - {"INVERSION_ON", INVERSION_ON}, - {"INVERSION_AUTO", INVERSION_AUTO} -}; - -const Param bw_list[] = { - {"BANDWIDTH_6_MHZ", BANDWIDTH_6_MHZ}, - {"BANDWIDTH_7_MHZ", BANDWIDTH_7_MHZ}, - {"BANDWIDTH_8_MHZ", BANDWIDTH_8_MHZ} -}; - -const Param fec_list[] = { - {"FEC_1_2", FEC_1_2}, - {"FEC_2_3", FEC_2_3}, - {"FEC_3_4", FEC_3_4}, - {"FEC_4_5", FEC_4_5}, - {"FEC_5_6", FEC_5_6}, - {"FEC_6_7", FEC_6_7}, - {"FEC_7_8", FEC_7_8}, - {"FEC_8_9", FEC_8_9}, - {"FEC_AUTO", FEC_AUTO}, - {"FEC_NONE", FEC_NONE}, - {"FEC_1_4", FEC_1_4}, // RMM S2 Extension - {"FEC_1_3", FEC_1_3}, - {"FEC_2_5", FEC_2_5}, - {"FEC_9_10", FEC_9_10} -}; - -const Param guard_list[] = { - {"GUARD_INTERVAL_1_16", GUARD_INTERVAL_1_16}, - {"GUARD_INTERVAL_1_32", GUARD_INTERVAL_1_32}, - {"GUARD_INTERVAL_1_4", GUARD_INTERVAL_1_4}, - {"GUARD_INTERVAL_1_8", GUARD_INTERVAL_1_8} -}; - -const Param hierarchy_list[] = { - {"HIERARCHY_1", HIERARCHY_1}, - {"HIERARCHY_2", HIERARCHY_2}, - {"HIERARCHY_4", HIERARCHY_4}, - {"HIERARCHY_NONE", HIERARCHY_NONE} -}; - -const Param constellation_list[] = { - {"QPSK", QPSK}, - {"QAM_128", QAM_128}, - {"QAM_16", QAM_16}, - {"QAM_256", QAM_256}, - {"QAM_32", QAM_32}, - {"QAM_64", QAM_64}, - {"QPSK_S2", QPSK_S2}, // RMM S2 Extension - {"PSK8", PSK8} -}; - -const Param transmissionmode_list[] = { - {"TRANSMISSION_MODE_2K", TRANSMISSION_MODE_2K}, - {"TRANSMISSION_MODE_8K", TRANSMISSION_MODE_8K}, -}; - -const Param capabilities_list[] = { - {"Stupid: ", FE_IS_STUPID}, - {"FE_CAN_INVERSION_AUTO: ", FE_CAN_INVERSION_AUTO}, - {"CAN_FEC_1_2: ", FE_CAN_FEC_1_2}, - {"CAN_FEC_2_3: ", FE_CAN_FEC_2_3}, - {"CAN_FEC_3_4: ", FE_CAN_FEC_3_4}, - {"CAN_FEC_4_5: ", FE_CAN_FEC_4_5}, - {"CAN_FEC_6_7: ", FE_CAN_FEC_6_7}, - {"CAN_FEC_7_8: ", FE_CAN_FEC_7_8}, - {"CAN_FEC_8_9: ", FE_CAN_FEC_8_9}, - {"CAN_FEC_AUTO: ", FE_CAN_FEC_AUTO}, - {"FE_CAN_QPSK: ", FE_CAN_QPSK}, - {"FE_CAN_QAM_16: ", FE_CAN_QAM_16}, - {"FE_CAN_QAM_32: ", FE_CAN_QAM_32}, - {"FE_CAN_QAM_64: ", FE_CAN_QAM_64}, - {"FE_CAN_QAM_128: ", FE_CAN_QAM_128}, - {"FE_CAN_QAM_256: ", FE_CAN_QAM_256}, - {"FE_CAN_QAM_AUTO: ", FE_CAN_QAM_AUTO}, - {"FE_CAN_TRANSMISSION_MODE_AUTO: ", FE_CAN_TRANSMISSION_MODE_AUTO}, - {"FE_CAN_BANDWIDTH_AUTO: ", FE_CAN_BANDWIDTH_AUTO}, - {"FE_CAN_GUARD_INTERVAL_AUTO: ", FE_CAN_GUARD_INTERVAL_AUTO}, - {"FE_CAN_HIERARCHY_AUTO: ", FE_CAN_HIERARCHY_AUTO}, - {"FE_CAN_MUTE_TS: ", FE_CAN_MUTE_TS} -// {"FE_CAN_CLEAN_SETUP: ",FE_CAN_CLEAN_SETUP} -}; - -#define LIST_SIZE(x) sizeof(x)/sizeof(Param) - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -void print_fe_info (struct dvb_frontend_info *fe_info) -{ - fprintf (stdout, "-------------------------------------------\n"); - fprintf (stdout, "Tuner name: %s\n", fe_info->name); - fprintf (stdout, "Tuner type: %u\n", (unsigned int) fe_info->type); - fprintf (stdout, "Frequency min.: %u\n", fe_info->frequency_min); - fprintf (stdout, "Frequency max.: %u\n", fe_info->frequency_max); - fprintf (stdout, "Frequency stepsize: %u\n", fe_info->frequency_stepsize); - fprintf (stdout, "Frequency tolerance: %u\n", fe_info->frequency_tolerance); - fprintf (stdout, "Symbol rate min: %u\n", fe_info->symbol_rate_min); - fprintf (stdout, "Symbol rate max: %u\n", fe_info->symbol_rate_max); - fprintf (stdout, "Symbol rate tolerance: %u\n", fe_info->symbol_rate_tolerance); - fprintf (stdout, "Notifier delay: %u\n", fe_info->notifier_delay); - fprintf (stdout, "Cpas: 0x%x\n", (unsigned int) fe_info->caps); - - fprintf (stdout, "-------------------------------------------\n"); - fprintf (stdout, "Frontend Capabilities:\n"); - int i; - - for (i = 0; i < LIST_SIZE (capabilities_list); i++) { - if (fe_info->caps & capabilities_list[i].value) - fprintf (stdout, "%syes\n", capabilities_list[i].name); - else - fprintf (stdout, "%sno\n", capabilities_list[i].name); - } - fprintf (stdout, "-------------------------------------------\n"); -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -void print_frontend_settings (struct dvb_frontend_parameters *frontend_param) -{ - int i; - fprintf (stdout, "\n----- Front End Settings ----- "); - fprintf (stdout, "\nFrequency : %u \n", frontend_param->frequency); - for (i = 0; i < LIST_SIZE (inversion_list); i++) { - if (inversion_list[i].value == frontend_param->inversion) - fprintf (stdout, "Inversion : %s\n", inversion_list[i].name); - - } - // - for (i = 0; i < LIST_SIZE (bw_list); i++) { - if (frontend_param->u.ofdm.bandwidth == bw_list[i].value) - fprintf (stdout, "Bandwidth : %s\n", bw_list[i].name); - - } - for (i = 0; i < LIST_SIZE (fec_list); i++) { - if (fec_list[i].value == frontend_param->u.ofdm.code_rate_HP) - fprintf (stdout, "Code Rate HP : %s\n", fec_list[i].name); - - } - for (i = 0; i < LIST_SIZE (fec_list); i++) { - if (fec_list[i].value == frontend_param->u.ofdm.code_rate_LP) - fprintf (stdout, "Code Rate LP : %s\n", fec_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (constellation_list); i++) { - if (constellation_list[i].value == frontend_param->u.ofdm.constellation) - fprintf (stdout, "Modulation : %s\n", constellation_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (transmissionmode_list); i++) { - if (transmissionmode_list[i].value == frontend_param->u.ofdm.transmission_mode) - fprintf (stdout, "Transmission mode : %s\n", transmissionmode_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (guard_list); i++) { - if (guard_list[i].value == frontend_param->u.ofdm.guard_interval) - fprintf (stdout, "Guard interval : %s\n", guard_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (hierarchy_list); i++) { - if (hierarchy_list[i].value == frontend_param->u.ofdm.hierarchy_information) - fprintf (stdout, "Hierarchy Information : %s\n", hierarchy_list[i].name); - - } - -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -void print_mcg (struct in6_addr *mcg) -{ - char host[80]; - unsigned int freq; - struct in6_addr mc; - int i; - - for (i = 0; i < 8; i++) { - mc.s6_addr16[i] = ntohs (mcg->s6_addr16[i]); - } - - freq = mc.s6_addr16[6] | (mc.s6_addr16[7] & NOPID_MASK) << 3; - - inet_ntop (AF_INET6, mcg->s6_addr, (char *) host, INET6_ADDRSTRLEN); - fprintf (stdout, "MCG: %s\n", host); - - fprintf (stdout, "\n"); - fprintf (stdout, "TS-Streaming group\n"); - fprintf (stdout, "-----------------------------\n"); - fprintf (stdout, "Streaming Group - 0x%x \n", (mc.s6_addr16[1] >> 12) & 0xf); - fprintf (stdout, "Priority - 0x%x \n", (mc.s6_addr16[1] >> 8) & 0xf); - fprintf (stdout, "Reception System - 0x%x \n", mc.s6_addr16[1] & 0xff); - fprintf (stdout, "CAM Handling - 0x%x \n", mc.s6_addr16[2]); - fprintf (stdout, "Polarisation - 0x%x \n", (mc.s6_addr16[3] >> 12) & 0xf); - fprintf (stdout, "SATPosition - 0x%x \n", mc.s6_addr16[3] & 0xfff); - fprintf (stdout, "Symbol Rate - 0x%x \n", mc.s6_addr16[4]); - fprintf (stdout, "Modulation - 0x%x \n", mc.s6_addr16[5]); - fprintf (stdout, "Frequency (0x%x) - %d / %d\n\n", freq, freq * (16667 / 8), freq * (250 / 8)); - - fprintf (stdout, "PID - 0x%x \n", mc.s6_addr16[7] & PID_MASK); -} -#endif -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -/* Frequency 19Bit - DVB-T/DVB-C 524288 Steps * (25/12)kHz = 0...1092MHz in 2.083333kHz steps - DVB-S 524288 Steps * (1/20) MHz = 0...26.2GHz in 50kHz steps -*/ -void fe_parms_to_mcg (struct in6_addr *mcg, streaming_group_t StreamingGroup, fe_type_t type, recv_sec_t * sec, struct dvb_frontend_parameters *fep, int vpid) -{ - int i; - unsigned int Priority = 0; - unsigned int ReceptionSystem = 0; - unsigned int CAMHandling = 0; - unsigned int Polarisation = 0; - unsigned int SATPosition = NO_SAT_POS; - unsigned int Symbolrate = 0; - unsigned int Modulation = 0; - unsigned int TransmissionMode = 0; - unsigned int Frequency; - double fmul; - - // Default for DVB-T and DVB-C - fmul = 12.0 * (((double) fep->frequency) + 1041); - Frequency = (unsigned int) (fmul / 25000.0); - - switch (type) { - case FE_QPSK: - case FE_DVBS2: - Frequency = (fep->frequency + 24) / 50; - //sec->diseqc_cmd currently not used - // Fixme: Translation Diseqc->position/LOF-frequency - Polarisation = (sec->mini_cmd << 3) | (sec->tone_mode << 2) | sec->voltage; - Symbolrate = fep->u.qpsk.symbol_rate / 1000; - Modulation |= (fep->u.qpsk.fec_inner) & 0xf; - - // RMM S2 extension: Put Modulation in 23:16 and rolloff in 31:24 - if (((fep->u.qpsk.fec_inner >> 16) & 0xff) == PSK8) - Modulation |= 2 << 4; - if (((fep->u.qpsk.fec_inner >> 16) & 0xff) == QPSK_S2) - Modulation |= 1 << 4; - Modulation |= fep->inversion << 14; - break; - case FE_QAM: - Symbolrate = fep->u.qam.symbol_rate / 200; - Modulation |= fep->u.qam.modulation; - Modulation |= fep->inversion << 14; - break; - case FE_OFDM: - TransmissionMode = fep->u.ofdm.transmission_mode; - Symbolrate = (TransmissionMode & 0x7) << 8 | (fep->u.ofdm.code_rate_HP << 4) | fep->u.ofdm.code_rate_LP; - Modulation |= (fep->u.ofdm.constellation & 0xf) | (fep->u.ofdm.hierarchy_information & 3) << 4 | (fep->u.ofdm.bandwidth & 3) << 7 | (fep->u.ofdm.guard_interval & 7) << 9 | (fep->inversion & 3) << 14; - break; - case FE_ATSC: - Modulation |= fep->u.vsb.modulation; - Modulation |= fep->inversion << 14; - break; - } - - if (type == FE_DVBS2 && !(Modulation & 0x30) ){ - type=FE_QPSK; - } - - ReceptionSystem = type; - - mcg->s6_addr16[0] = MC_PREFIX; - mcg->s6_addr16[1] = ((StreamingGroup & 0xf) << 12) | ((Priority & 0xf) << 8) | (ReceptionSystem & 0xff); - mcg->s6_addr16[2] = CAMHandling; - mcg->s6_addr16[3] = ((Polarisation & 0xf) << 12) | (SATPosition & 0xfff); - mcg->s6_addr16[4] = Symbolrate; - mcg->s6_addr16[5] = Modulation; - mcg->s6_addr16[6] = Frequency; - mcg->s6_addr16[7] = (vpid & PID_MASK) | ((Frequency >> 16) << 13); - - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = htons (mcg->s6_addr16[i]); - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -int mcg_to_all_parms(struct in6_addr *mcg, struct mcg_data * mcd) -{ - int ret; - mcd->mcg=*mcg; - int n; - - ret=mcg_to_fe_parms(mcg, &mcd->type, &mcd->sec, &mcd->fep, &mcd->vpid); - - if (ret) - return ret; - mcg_get_satpos(mcg, &mcd->satpos); - - for(n=0;n<MAX_TUNER_CACHE;n++) { - mcd->sat_cache[n].resolved=NOT_RESOLVED; - mcd->sat_cache[n].num=0; - mcd->sat_cache[n].component=0; - } - - return 0; -} -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -int mcg_to_fe_parms (struct in6_addr *mcg, fe_type_t * type, recv_sec_t * sec, struct dvb_frontend_parameters *fep, int *vpid) -{ - struct in6_addr mc = *mcg; - streaming_group_t StreamingGroup; - unsigned int freq; - double fmul; - fe_type_t fetype; - - int i; - for (i = 0; i < 8; i++) { - mc.s6_addr16[i] = ntohs (mc.s6_addr16[i]); - } - - StreamingGroup = (streaming_group_t)((mc.s6_addr16[1] >> 12) & 0xf); - - if (StreamingGroup != STREAMING_PID) { - return -1; - } - - if (fep) { - memset (fep, 0, sizeof (struct dvb_frontend_parameters)); - } - if (sec) { - memset (sec, 0, sizeof (recv_sec_t)); - } - - - freq = mc.s6_addr16[6] | ((mc.s6_addr16[7] & NOPID_MASK) << 3); - - fmul = 25000.0 * (double) freq; - - fep->frequency = (unsigned int) (fmul / 12.0); - fep->inversion = (fe_spectral_inversion_t)((mc.s6_addr16[5] >> 14) & 3); - fetype = (fe_type_t)(mc.s6_addr16[1] & 0xff); - - if (type) { - *type = fetype; - } - switch (fetype) { - case FE_QPSK: - case FE_DVBS2: - { - int Polarisation = mc.s6_addr16[3] >> 12; - fep->frequency = freq * 50; - sec->mini_cmd = (fe_sec_mini_cmd_t)((Polarisation >> 3) & 1); - sec->tone_mode = (fe_sec_tone_mode_t)((Polarisation >> 2) & 1); - sec->voltage = (fe_sec_voltage_t)(Polarisation & 3); - - fep->u.qpsk.symbol_rate = mc.s6_addr16[4] * 1000; - fep->u.qpsk.fec_inner = (fe_code_rate_t)(mc.s6_addr16[5] & 0xf); - - unsigned int fec_inner=(unsigned int)fep->u.qpsk.fec_inner; - - // RMM S2 Extension - switch (mc.s6_addr16[5] & 0x30) { - case 0x10: - fec_inner |= QPSK_S2 << 16; - fep->u.qpsk.fec_inner=(fe_code_rate_t)fec_inner; - *type = (fe_type_t) FE_DVBS2; // force FE type - break; - case 0x20: - fec_inner |= PSK8 << 16; - fep->u.qpsk.fec_inner=(fe_code_rate_t)fec_inner; - *type = (fe_type_t) FE_DVBS2; - break; - default: - *type = FE_QPSK; - } - } - break; - case FE_QAM: - fep->u.qam.symbol_rate = mc.s6_addr16[4] * 200; - fep->u.qam.modulation = (fe_modulation_t)(mc.s6_addr16[5] & 0xf); - // Ignore inversion - break; - case FE_OFDM: - fep->u.ofdm.transmission_mode = (fe_transmit_mode_t)((mc.s6_addr16[4] >> 8) & 3); - fep->u.ofdm.code_rate_HP = (fe_code_rate_t)((mc.s6_addr16[4] >> 4) & 0xf); - fep->u.ofdm.code_rate_LP = (fe_code_rate_t)(mc.s6_addr16[4] & 0xf); - - fep->u.ofdm.constellation = (fe_modulation_t) (mc.s6_addr16[5] & 0xf); - fep->u.ofdm.hierarchy_information = (fe_hierarchy_t)((mc.s6_addr16[5] >> 4) & 3); - fep->u.ofdm.bandwidth = (fe_bandwidth_t)((mc.s6_addr16[5] >> 7) & 3); - fep->u.ofdm.guard_interval = (fe_guard_interval_t)((mc.s6_addr16[5] >> 9) & 7); - break; - case FE_ATSC: - fep->u.vsb.modulation = (fe_modulation_t)(mc.s6_addr16[5] & 0xf); - break; - } - - if (vpid) { - *vpid = mc.s6_addr16[7] & PID_MASK; - } - //print_frontend_settings(fep); - return 0; -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_set_streaming_group (struct in6_addr *mcg, streaming_group_t StreamingGroup) -{ - int i; - - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = ntohs (mcg->s6_addr16[i]); - } - - // Change StreamingGroup - mcg->s6_addr16[1] = ((StreamingGroup & 0xf) << 12) | (mcg->s6_addr16[1] & 0x0fff); - - // Remove PID - mcg->s6_addr16[7] &= NOPID_MASK; - - // Remove CAID - mcg->s6_addr16[2] = 0; - - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = htons (mcg->s6_addr16[i]); - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_get_streaming_group (struct in6_addr *mcg, streaming_group_t *StreamingGroup) -{ - if(StreamingGroup) { - *StreamingGroup=(streaming_group_t)((ntohs (mcg->s6_addr16[1]) >> 12) & 0xf); - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_set_pid (struct in6_addr *mcg, int pid) -{ - - mcg->s6_addr16[7] = ntohs (mcg->s6_addr16[7]); - - // Remove PID - mcg->s6_addr16[7] &= NOPID_MASK; - - // Set new PID - mcg->s6_addr16[7] |= pid; - - mcg->s6_addr16[7] = htons (mcg->s6_addr16[7]); -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_get_pid (struct in6_addr *mcg, int *pid) -{ - if (pid) { - *pid=ntohs (mcg->s6_addr16[7]) & PID_MASK; - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_init_streaming_group (struct in6_addr *mcg, streaming_group_t StreamingGroup) -{ - unsigned int Priority = 1; - mcg->s6_addr16[0] = MC_PREFIX; - mcg->s6_addr16[1] = ((StreamingGroup & 0xf) << 12) | ((Priority & 0xf) << 8) | (0 & 0xff); - mcg->s6_addr16[2] = 0; - mcg->s6_addr16[3] = 0; - mcg->s6_addr16[4] = 0; - mcg->s6_addr16[5] = 0; - mcg->s6_addr16[6] = 0; - mcg->s6_addr16[7] = 0; - int i; - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = htons (mcg->s6_addr16[i]); - } - -} - -void mcg_get_priority (struct in6_addr *mcg, int *priority) -{ - if (priority) { - *priority = (ntohs (mcg->s6_addr16[1])>>8) & 0xf; - } -} - -void mcg_set_priority (struct in6_addr *mcg, int priority) -{ - mcg->s6_addr16[1] = ntohs (mcg->s6_addr16[1]); - mcg->s6_addr16[1] &= 0xf0ff; - mcg->s6_addr16[1] |= (priority & 0xf) << 8; - mcg->s6_addr16[1] = htons (mcg->s6_addr16[1]); -} - -void mcg_get_satpos (struct in6_addr *mcg, int *satpos) -{ - if (satpos) { - *satpos = ntohs (mcg->s6_addr16[3]) & 0xfff; - } -} - -void mcg_set_satpos (struct in6_addr *mcg, int satpos) -{ - mcg->s6_addr16[3] = ntohs (mcg->s6_addr16[3]); - - // Remove SatPos - mcg->s6_addr16[3] &= ~NO_SAT_POS; - - // Set new SatPos - mcg->s6_addr16[3] |= (satpos & NO_SAT_POS); - - mcg->s6_addr16[3] = htons (mcg->s6_addr16[3]); -} - -void mcg_get_id (struct in6_addr *mcg, int *id) -{ - if (id) { - *id = ntohs (mcg->s6_addr16[2]); - } -} - -void mcg_set_id (struct in6_addr *mcg, int id) -{ - mcg->s6_addr16[2] = htons(id); -} - -#if defined LIBRARY || defined SERVER -#ifndef OS_CODE - #define OS_CODE 3 -#endif -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif - -static unsigned char gzip_hdr[] = { 0x1f, 0x8b, Z_DEFLATED, 0 /*flags */ , 0, 0, 0, 0 /*time */ , 0 /*xflags */ , OS_CODE }; - -int check_header (const Bytef * buf, unsigned int buflen) -{ - if (buflen <= 10) - return 0; - - if (buf[0] != gzip_hdr[0] || buf[1] != gzip_hdr[1]) { - return -1; - } - - if (memcmp (buf, gzip_hdr, sizeof (gzip_hdr))) { - return -2; - } - return 10; -} - -unsigned int get32_lsb_first (unsigned char *ptr) -{ - int i; - unsigned int val = 0; - for (i = 3; i >= 0; i--) { - val <<= 8; - val |= (ptr[i] & 0xff); - } - return val; -} - -void put32_lsb_first (unsigned char *ptr, unsigned int val) -{ - int i; - for (i = 0; i < 4; i++) { - ptr[i] = val & 0xff; - val >>= 8; - } -} - -int gzip_ (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen, int level) -{ - unsigned int crc = crc32 (0L, Z_NULL, 0); - z_stream stream; - int err; - - if (*destLen <= 10) { - return Z_BUF_ERROR; - } - memcpy (dest, gzip_hdr, sizeof (gzip_hdr)); - - stream.next_in = (Bytef *) source; - stream.avail_in = sourceLen; - - stream.next_out = dest + 10; - stream.avail_out = *destLen - 10; - - stream.zalloc = (alloc_func) 0; - stream.zfree = (free_func) 0; - stream.opaque = (voidpf) 0; - - err = deflateInit2 (&stream, level, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); - - if (err != Z_OK) - return err; - - err = deflate (&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd (&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out + 10; - - err = deflateEnd (&stream); - crc = crc32 (crc, source, sourceLen); - - put32_lsb_first ((unsigned char *) (dest + *destLen), crc); - put32_lsb_first ((unsigned char *) (dest + *destLen + 4), sourceLen); - - *destLen += 8; - return err; -} - -int gzip (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen, int level) -{ - if (!level) { - memcpy (dest, source, sourceLen); - *destLen = sourceLen; - return 0; - } - return gzip_ (dest, destLen, source, sourceLen,level); -} - -int gunzip_ (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen) -{ - unsigned int crc = crc32 (0L, Z_NULL, 0); - z_stream stream; - int err; - int ret = check_header (source, sourceLen); - if (ret < 0) { - return ret; - } - - stream.next_in = (Bytef *) source + ret; - stream.avail_in = sourceLen - ret; - - stream.next_out = dest; - stream.avail_out = *destLen; - - stream.zalloc = (alloc_func) 0; - stream.zfree = (free_func) 0; - - err = inflateInit2 (&stream, -MAX_WBITS); - if (err != Z_OK) - return err; - - err = inflate (&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd (&stream); - if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) - return Z_DATA_ERROR; - return err; - } - *destLen = stream.total_out; - - err = inflateEnd (&stream); - crc = crc32 (crc, dest, stream.total_out); - - int crc_found = get32_lsb_first ((unsigned char *) (stream.next_in)); - int len_found = get32_lsb_first ((unsigned char *) (stream.next_in + 4)); - - if (crc_found == crc && len_found == stream.total_out) { - return err; - } - - return Z_DATA_ERROR; -} - -int gunzip (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen) -{ - int ret = gunzip_ (dest, destLen, source, sourceLen); - if (ret == -1) { - memcpy (dest, source, sourceLen); - *destLen = sourceLen; - return 0; - } else if (ret < 0) { - return -1; - } - return 0; -} -#endif -#ifndef BACKTRACE - void print_trace (void) - { - } -#else -#include <execinfo.h> -/* Obtain a backtrace and print it to stdout. */ -void print_trace (void) -{ - void *array[10]; - size_t size; - char **strings; - size_t i; - - size = backtrace (array, 10); - strings = backtrace_symbols (array, size); - - printf ("Obtained %zd stack frames.\n", size); - - for (i = 0; i < size; i++) { - printf ("%s\n", strings[i]); - } - free (strings); -} - - -void SignalHandlerCrash(int signum) -{ - void *array[15]; - size_t size; - char **strings; - size_t i; - FILE *f; - char dtstr[16]; - time_t t=time(NULL); - struct tm *tm=localtime(&t); - - signal(signum,SIG_DFL); // Allow core dump - - f=fopen("/var/log/mcli.crashlog","a"); - if (f) { - strftime(dtstr, sizeof(dtstr), "%b %e %T", tm); - size = backtrace (array, 15); - strings = backtrace_symbols (array, size); - fprintf(f,"%s ### Crash signal %i ###\n",dtstr, signum); - for (i = 0; i < size; i++) - fprintf (f, "%s Backtrace %i: %s\n", dtstr, i, strings[i]); - free (strings); - fclose(f); - } -} -#endif - -#ifdef SYSLOG -pthread_mutex_t _loglock = PTHREAD_MUTEX_INITIALIZER; - -UDPContext * syslog_fd = NULL; -char *_logstr = NULL; - -int syslog_init(void) -{ - struct in6_addr mcglog; - mcg_init_streaming_group (&mcglog, STREAMING_LOG); - syslog_fd = server_udp_open (&mcglog, 23000, NULL); - if(syslog_fd) { - _logstr=(char *)malloc(10240); - } - - return syslog_fd?0:-1; -} - -int syslog_write(char *s) -{ - return udp_write (syslog_fd, (uint8_t *)s, strlen(s)); -} - -void syslog_exit(void) -{ - if(syslog_fd) { - udp_close(syslog_fd); - free(_logstr); - } -} -#endif +(symlink to ../common/tools.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/client/win32
Changed
-(directory) +(symlink to ../common/win32)
View file
vdr-mcli-plugin.tar.bz2/mcast/common/ciparser.c
Changed
@@ -256,6 +256,7 @@ return ret; } +#if 0 STATIC int ci_decode_al_ca_info (ci_al_t * al) { int i = 0; @@ -281,10 +282,14 @@ } return data - al->data; } +#endif STATIC int ca_decode_ca_descr (ca_desc_t ** cadescr, int count, u_int8_t * data, int len, int *magic) { *cadescr = (ca_desc_t *) realloc (*cadescr, sizeof (ca_desc_t *) * (count + 1)); + if (!*cadescr) { + err ("ca_decode_ca_descr: out of memory\n"); + } ca_desc_t *c = *cadescr + count; // u_int8_t descriptor_tag = *data; @@ -371,6 +376,9 @@ while (len>0) { p.pidinfo = (pidinfo_t *) realloc (p.pidinfo, sizeof (pidinfo_t) * (pidn + 1)); + if (!p.pidinfo) { + err ("ci_decode_al_ca_pmt: out of memory"); + } memset (&p.pidinfo[pidn], 0, sizeof (pidinfo_t)); p.pidinfo[pidn].stream_type = *data; data++; @@ -450,6 +458,9 @@ while (len>0) { p.pidcaenable = (pid_ca_enable_t *) realloc (p.pidcaenable, sizeof (pid_ca_enable_t) * (pidn + 1)); + if (!p.pidcaenable) { + err ("ci_decode_al_ca_pmt_reply: out of memory\n"); + } memset (&p.pidcaenable[pidn], 0, sizeof (pid_ca_enable_t)); p.pidcaenable[pidn].pid = ntohs16 (data); data += 2;
View file
vdr-mcli-plugin.tar.bz2/mcast/common/darwin/include/linux
Changed
-(directory) +(symlink to ../../win32/include/linux)
View file
vdr-mcli-plugin.tar.bz2/mcast/common/defs.h
Changed
@@ -35,9 +35,12 @@ int inet_pton(int af, const char *src, void *dst); const char *inet_ntop(int af, const void *src, char *dst, size_t size); int inet_aton(const char *cp, struct in_addr *addr); - int getopt(int nargc, char **nargv, char *ostr); - extern int opterr, optind, optopt, optreset; - extern char *optarg; + #ifndef __MINGW32__ + int getopt(int nargc, char **nargv, char *ostr); + extern int opterr, optind, optopt, optreset; + extern char *optarg; + #define inline __inline + #endif typedef struct { @@ -65,7 +68,11 @@ #ifdef LIBRARY #define DLL_SYMBOL CALLCONV __declspec( dllexport ) #else - #define DLL_SYMBOL CALLCONV __declspec( dllimport ) + #ifdef STATICLIB + #define DLL_SYMBOL CALLCONV + #else + #define DLL_SYMBOL CALLCONV __declspec( dllimport ) + #endif #endif #define pthread_exist(x) (x).p @@ -76,6 +83,8 @@ #define LIBXML_STATIC #define PTW32_STATIC_LIB #define MULTI_THREAD_RECEIVER + + #include <poll.h> #endif #else #if defined __cplusplus @@ -305,6 +314,15 @@ fprintf(stderr, "%s:%d: %s", __FILE__ , __LINE__ , buffer ); va_end (args); } + static void inline sys(const char *format, ...) + { + char buffer[1024]; + va_list args; + va_start (args, format); + vsprintf(buffer, format , args); + printf("%s:%d: %s", __FILE__ , __LINE__ , buffer ); + va_end (args); + } #else static void inline dbg (char *format, ...) { @@ -337,6 +355,15 @@ fputs(buffer, stderr); va_end (args); } + static void inline sys(const char *format, ...) + { + char buffer[1024]; + va_list args; + va_start (args, format); + vsprintf(buffer, format, args); + fputs(buffer, stdout); + va_end (args); + } #endif //DEBUG #endif // WIN32
View file
vdr-mcli-plugin.tar.bz2/mcast/common/interfaces.c
Changed
@@ -208,11 +208,19 @@ if( /* pCurrAddresses->Flags & IP_ADAPTER_IPV6_ENABLED && */ (pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD || pCurrAddresses->IfType == IF_TYPE_IEEE80211) && pCurrAddresses->OperStatus == IfOperStatusUp ) { g_conf->ints=(struct intnode*)realloc(g_conf->ints, sizeof(struct intnode)*(g_conf->maxinterfaces+1)); + if (!g_conf->ints) { + err ("update_interfaces: out of memory\n"); + } intn=g_conf->ints+g_conf->maxinterfaces; memset(intn, 0, sizeof(struct intnode)); +#ifndef __MINGW32__ printf ("Interface: %s (%wS)\n", pCurrAddresses->AdapterName, pCurrAddresses->Description); dbg ("\tFriendly name: %wS\n", pCurrAddresses->FriendlyName); +#else + printf ("Interface: %s (%ls)\n", pCurrAddresses->AdapterName, pCurrAddresses->Description); + dbg ("\tFriendly name: %ls\n", pCurrAddresses->FriendlyName); +#endif dbg ("\tFlags: %x\n", pCurrAddresses->Flags); dbg ("\tIfType: %ld\n", pCurrAddresses->IfType); dbg ("\tOperStatus: %ld\n", pCurrAddresses->OperStatus);
View file
vdr-mcli-plugin.tar.bz2/mcast/common/mcast.c
Changed
@@ -10,7 +10,6 @@ */ #include "headers.h" - //---------------------------------------------------------------------------------------------------------------------------------- STATIC int udp_ipv6_is_multicast_address (const struct sockaddr *addr) { @@ -246,7 +245,8 @@ #ifndef WIN32 addr->sin6_addr=*mcg; #else - struct in6_addr any=IN6ADDR_ANY_INIT; + struct in6_addr any; + memset(&any,0,sizeof(any)); addr->sin6_addr=any; #endif addr->sin6_family = AF_INET6; @@ -347,14 +347,11 @@ from=&from_local; } - fd_set rfds; - struct timeval tv; - FD_ZERO(&rfds); - FD_SET(s->udp_fd, &rfds); - tv.tv_sec = 0; - tv.tv_usec = timeout; - - if(select(s->udp_fd+1, &rfds, NULL, NULL, &tv)>0) { + struct pollfd p; + p.fd = s->udp_fd; + p.events = POLLIN; + + if(poll(&p,1,(timeout+999)>>10)>0) { return recvfrom (s->udp_fd, (char *)buf, size, 0, (struct sockaddr *) from, &from_len); } return -1; @@ -399,6 +396,8 @@ UDPContext *gConList[MAX_CON_LIST]; pthread_mutex_t gConListLock = PTHREAD_MUTEX_INITIALIZER; static int gConListInit=0; +static int gConListModified; +static UDPContext *gConChain; STATIC void client_upd_cleanup (void *arg) { if(!gConListInit) return; @@ -422,43 +421,42 @@ unsigned char buff[MAX_BUFF_SIZE]; socklen_t from_len = sizeof (struct sockaddr_storage); struct sockaddr_storage from_local; - struct timeval timeout; struct pollfd fds[MAX_CON_LIST]; pthread_cleanup_push (client_upd_cleanup, 0); - int i; + int max_fd=0; while(1) { - int max_fd=0; + UDPContext *e; pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) { - if(gConList[i]) { - fds[max_fd].fd = gConList[i]->udp_fd; + if(gConListModified) { + gConListModified=0; + max_fd=0; + for(e=gConChain;e;e=e->next) { + fds[max_fd].fd = e->udp_fd; fds[max_fd].events = POLLIN; fds[max_fd].revents = 0; - gConList[i]->pfd = &fds[max_fd]; + e->pfd = &fds[max_fd]; max_fd++; - } // if - } // for + } // for + } // if pthread_mutex_unlock(&gConListLock); - timeout.tv_sec = 0; - timeout.tv_usec = 100000; int rs = poll(fds, max_fd, 1000); if(rs>0) { pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) { - if(gConList[i] && gConList[i]->pfd && (gConList[i]->pfd->revents & POLLIN)) { - if(gConList[i]->cb) { - int ret = recvfrom (gConList[i]->udp_fd, (char *)buff, MAX_BUFF_SIZE, 0, 0, 0/*(struct sockaddr *) &from_local, &from_len*/); + for(e=gConChain;e;e=e->next) { + if(e->pfd && (e->pfd->revents & POLLIN)) { + if(e->cb) { + int ret = recvfrom (e->udp_fd, (char *)buff, MAX_BUFF_SIZE, 0, 0, 0/*(struct sockaddr *) &from_local, &from_len*/); if(ret>0) - gConList[i]->cb(buff, ret, gConList[i]->arg); - } else if(gConList[i]->buff && !gConList[i]->bufflen) { - pthread_mutex_lock(&gConList[i]->bufflock); - int ret = recvfrom (gConList[i]->udp_fd, (char *)gConList[i]->buff, gConList[i]->buffmax, 0, (struct sockaddr *) &from_local, &from_len); + e->cb(buff, ret, e->arg); + } else if(e->buff && !e->bufflen) { + pthread_mutex_lock(&e->bufflock); + int ret = recvfrom (e->udp_fd, (char *)e->buff, e->buffmax, 0, (struct sockaddr *) &from_local, &from_len); if(ret>0) - gConList[i]->bufflen = ret; - pthread_mutex_unlock(&gConList[i]->bufflock); + e->bufflen = ret; + pthread_mutex_unlock(&e->bufflock); } // if } // if } // for @@ -478,6 +476,8 @@ return 1; } // if memset(&gConList, 0, sizeof(gConList)); + gConListModified = 0; + gConChain = NULL; pthread_t client_upd_thread; if(0==pthread_create (&client_upd_thread, NULL, client_upd_process, 0)) { gConListInit = 1; @@ -493,6 +493,9 @@ ret->buff = (unsigned char *)malloc(buff_size); ret->buffmax = buff_size; ret->bufflen = 0; + if (!ret->buff) { + err ("client_udp_open_buff: out of memory\n"); + } } // if return ret; } // client_udp_open_buff @@ -597,6 +600,9 @@ for(i=0;i<MAX_CON_LIST;i++) { if(!gConList[i]) { gConList[i]=s; + gConListModified=1; + s->next=gConChain; + gConChain=s; break; } // if } // for @@ -640,9 +646,20 @@ { int i; pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) - if(gConList[i] == s) + for(i=0;i<MAX_CON_LIST;i++) { + if(gConList[i] == s) { gConList[i]=0; + gConListModified=1; + UDPContext **e; + for(e=&gConChain;*e;e=&(*e)->next) { + if(*e == s) { + *e=(*e)->next; + break; + } + } + break; + } + } pthread_mutex_unlock(&gConListLock); if (s->is_multicast) udp_ipv6_leave_multicast_group (s->udp_fd, s->idx, (struct sockaddr *) &s->dest_addr);
View file
vdr-mcli-plugin.tar.bz2/mcast/common/mcast.h
Changed
@@ -14,8 +14,9 @@ typedef void (*client_udp_cb)(unsigned char *buf, int n, void *arg); -typedef struct +typedef struct _UDPContext { + struct _UDPContext *next; SOCKET udp_fd; int ttl; int idx;
View file
vdr-mcli-plugin.tar.bz2/mcast/common/recv_ccpp.c
Changed
@@ -256,7 +256,7 @@ if (c.key) { dbg ("SymbolRate: %s\n", c.key); int val=atoi ((char *) c.key); - switch(tra->fe_type) { + switch((int)tra->fe_type) { case FE_DVBS2: case FE_QPSK: tra->fep.u.qpsk.symbol_rate=val; @@ -275,7 +275,7 @@ if (c.key) { dbg ("FecInner: %s\n", c.key); int val=atoi ((char *) c.key); - switch(tra->fe_type) { + switch((int)tra->fe_type) { case FE_DVBS2: case FE_QPSK: tra->fep.u.qpsk.fec_inner=(fe_code_rate_t)val; @@ -294,7 +294,7 @@ if (c.key) { dbg ("Modulation: %s\n", c.key); int val=atoi ((char *) c.key); - switch(tra->fe_type) { + switch((int)tra->fe_type) { case FE_QAM: tra->fep.u.qam.modulation=(fe_modulation_t)val; break;
View file
vdr-mcli-plugin.tar.bz2/mcast/common/satlists.h
Changed
@@ -7,6 +7,7 @@ */ #define DISEQC_MAX_EXTRA 8 +#define MAX_EXTRA_DATA 16 typedef enum { @@ -36,8 +37,9 @@ typedef enum { - SAT_SRC_LNB, - SAT_SRC_ROTOR, + SAT_SRC_LNB=0, + SAT_SRC_ROTOR=1, + SAT_SRC_UNI=2, // !!! match DISEQC_* values in dvb_server.h !!! } satellite_source_t; typedef struct @@ -57,6 +59,8 @@ int AutoFocus; int Latitude; int Longitude; + int num_extra_data; + int extra_data[MAX_EXTRA_DATA]; // reserved } satellite_info_t; typedef struct satellite_list
View file
vdr-mcli-plugin.tar.bz2/mcast/common/siparser.c
Changed
@@ -227,6 +227,10 @@ *month = m; *day = d; + } else { + *year = 0; + *month = 0; + *day = 0; } } @@ -243,7 +247,7 @@ long y,m,d; get_time_mjd(mjd, &y, &m, &d); - info("TIME: [= %02d-%02d-%02d %02lx:%02lx:%02lx (UTC) ]\n\n",y,m,d,(utc>>16) &0xFF, (utc>>8) &0xFF, (utc) &0xFF); + info("TIME: [= %02ld-%02ld-%02ld %02x:%02x:%02x (UTC) ]\n\n",y,m,d,(utc>>16) &0xFF, (utc>>8) &0xFF, (utc) &0xFF); info("--------------------------------------------------------------\n"); } @@ -256,7 +260,7 @@ info("Reserverd : %d (%#x)\n",p->reserved,p->reserved); info("CA pid : %d (%#x)\n",p->ca_pid,p->ca_pid); - printhex_buf("Private data",p->private_data,p->descriptor_length-4); + printhex_buf((char *)"Private data",p->private_data,p->descriptor_length-4); } //----------------------------------------------------------------------------------- @@ -488,7 +492,7 @@ pmt_hdr->reserved_1=(ptr[1] >> 4) & 3; pmt_hdr->section_length=((ptr[1] << 8) | ptr[2]) & 0xfff; - if (pmt_hdr->section_length < 13 || pmt_hdr->section_length > 1021 || pmt_hdr->section_length > size) { + if (pmt_hdr->section_length < 13 || pmt_hdr->section_length > 1021 || (int)pmt_hdr->section_length > size) { info("#####\nERROR: Invalid section length!\n"); return -1; } @@ -505,12 +509,12 @@ } pmt_hdr->program_number=(ptr[3] << 8) | ptr[4]; - if (pmt_hdr->program_number != sid) { + if ((int)pmt_hdr->program_number != sid) { info("#####\nERROR: Invalid SID in PMT !!!\n"); return -1; } pmt_hdr->program_info_length=((ptr[10] << 8) | ptr[11]) & 0x0fff; - if (pmt_hdr->program_info_length < 0 || pmt_hdr->program_info_length > 1021 - 9 || pmt_hdr->program_info_length > size - 9) { + if (pmt_hdr->program_info_length < 0 || pmt_hdr->program_info_length > 1021 - 9 || (int)pmt_hdr->program_info_length > size - 9) { info("#####\nERROR: Invalid PI length in PMT!\n"); return -1; } @@ -570,6 +574,10 @@ //parsing ok we can take this program level descriptors if (pm_cads->size && pm_cads->cads) { pm_cads->cad = (unsigned char*)malloc(sizeof(unsigned char)*pm_cads->size); + if (!pm_cads->cad) { + info("ERROR: parse_ca_desc() : out of memory\n"); + return -1; + } memcpy(pm_cads->cad, tmp, pm_cads->size); } @@ -588,7 +596,7 @@ esi.reserved_2=(ptr[3] >> 4) & 0xf; esi.es_info_length=((ptr[3] << 8) | ptr[4]) & 0x0fff; - if (esi.es_info_length > buf_len) { + if ((int)esi.es_info_length > buf_len) { info("PMT: Invalid ES info length !\n"); err = -1; break; @@ -684,6 +692,12 @@ //parsing ok we can take this ES level descriptors if (((es_cads->cads && es_cads->size) || (pm_cads->cads && es_cads->size)) || *fta) { //take ES stream info if we have PM or ES desc. es_cads->cad = (unsigned char*)malloc(sizeof(unsigned char)*es_cads->size); + if (!es_cads->cad) { + info("ERROR: parse_ca_desc() : out of memory\n"); + if (pm_cads->cad) + free(pm_cads->cad); + return -1; + } memcpy(es_cads->cad, tmp, es_cads->size); } @@ -700,9 +714,9 @@ print_pmt(&pmt_hdr); #endif //cleanup ... - if (pm_cads->size) + if (pm_cads->cad) free(pm_cads->cad); - if (es_cads->size) + if (es_cads->cad) free(es_cads->cad); *es_pid_num = 0; memset(pm_cads,0,sizeof(si_ca_pmt_t)); @@ -728,7 +742,7 @@ c.reserved_1 = (ptr[1] >> 4) & 3; c.section_length = ((ptr[1] << 8) | ptr[2]) & 0xfff; - if (c.section_length < 9 || c.section_length > 1021 || c.section_length > size) { + if (c.section_length < 9 || c.section_length > 1021 || (int)c.section_length > size) { info("CAT: Invalid section length!\n"); return -1; } @@ -795,7 +809,7 @@ p.reserved_1=(ptr[1] & 0x30) >> 4; p.section_length=((ptr[1] << 8) | ptr[2]) & 0x0fff; - if (p.section_length < 9 || p.section_length > 1021 || p.section_length > size) { + if (p.section_length < 9 || p.section_length > 1021 || (int)p.section_length > size) { info("PAT: Invalid section length !\n"); return -1; @@ -825,6 +839,10 @@ pmt_num=0; if (n > 0 && ((ptr + n) < (buf + size))) { pat_info=(pat_list_t *)malloc(sizeof(pat_list_t)*n/4); + if (!pat_info) { + info ("PAT: out of memory\n"); + return -1; + } for(i=0;i<n;i+=4) { pat_list_t *pat = pat_info + pmt_num; pat->program_number=(ptr[0] << 8) | (ptr[1]); @@ -840,6 +858,10 @@ p.crc32=(ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; if (n != pmt_num) pat_info=(pat_list_t *)realloc(pat_info,sizeof(pat_list_t)*pmt_num); + if (!pat_info) { + info("parse_pat_sect():realloc error\n"); + return -1; + } } if (pmt) { pmt->p=p; @@ -913,7 +935,7 @@ } - if (pid_req != h.pid) { + if (pid_req != (int)h.pid) { #ifdef DBG info("%s:pids mismatch (pid req = %#x ts pid = %#x )!\n", __FUNCTION__,pid_req, h.pid); #endif @@ -972,21 +994,21 @@ if (!h.payload_unit_start_indicator && p->start) { //packet continuation //duplicate packet - if ((p->pid == h.pid) && (p->continuity == h.continuity_counter)){ + if ((p->pid == (int)h.pid) && (p->continuity == (int)h.continuity_counter)){ #ifdef DBG info("Packet duplicate ???\n"); #endif return -1; } //new packet - if (p->pid != h.pid) { + if (p->pid != (int)h.pid) { #ifdef DBG info("New pid buf start %d len %d bytes (pid in buf = %d pid in ts = %d) !\n", p->start,p->len, p->pid, h.pid); #endif return -1; } //discontinuity of packets - if (((++p->continuity)%16) != h.continuity_counter) { + if (((++p->continuity)%16) != (int)h.continuity_counter) { #ifdef DBG info("Discontinuity of ts stream !!!\n"); #endif
View file
vdr-mcli-plugin.tar.bz2/mcast/common/tools.c
Changed
@@ -236,7 +236,7 @@ fmul = 12.0 * (((double) fep->frequency) + 1041); Frequency = (unsigned int) (fmul / 25000.0); - switch (type) { + switch ((int)type) { case FE_QPSK: case FE_DVBS2: Frequency = (fep->frequency + 24) / 50; @@ -349,7 +349,7 @@ if (type) { *type = fetype; } - switch (fetype) { + switch ((int)fetype) { case FE_QPSK: case FE_DVBS2: {
View file
vdr-mcli-plugin.tar.bz2/mcast/common/win32/include/poll.h
Added
@@ -0,0 +1,20 @@ +#ifndef _POLL_H_H_ +#define _POLL_H_H_ + +struct pollfd { + int fd; + short events; + short revents; +}; + +#define POLLIN 001 +#define POLLPRI 002 +#define POLLOUT 004 +#define POLLNORM POLLIN +#define POLLERR 010 +#define POLLHUP 020 +#define POLLNVAL 040 + +DLL_SYMBOL int poll(struct pollfd *, int, int); + +#endif /* _POLL_H_H_ */
View file
vdr-mcli-plugin.tar.bz2/mcast/common/win32/poll.c
Added
@@ -0,0 +1,57 @@ +#include <defs.h> + +int poll(struct pollfd *p,int n,int tmo) +{ + struct timeval timeout, *tptr; + fd_set in, out, err, *pin, *pout; + int i, m; + + FD_ZERO(&err); + for (i = 0, m = -1, pout = pin = NULL; i < n; i++) { + p[i].revents = 0; + if (p[i].fd < 0) + continue; + if (p[i].fd > m) + m = p[i].fd; + if (p[i].events & (POLLIN|POLLPRI)) { + if (!pin) { + FD_ZERO(&in); + pin = ∈ + } + FD_SET(p[i].fd, pin); + } + if (p[i].events & POLLOUT) { + if (!pout) { + FD_ZERO(&out); + pout = &out; + } + FD_SET(p[i].fd, pout); + } + FD_SET(p[i].fd, &err); + } + if (tmo < 0) + tptr = NULL; + else { + tptr = &timeout; + timeout.tv_sec = tmo / 1000; + timeout.tv_usec = (tmo % 1000) * 1000; + } + + i = select(m+1, pin, pout, &err, tptr); + if (i <= 0) + return i; + + for (i = 0, m = 0; i < n; i++) { + if (p[i].fd < 0) + continue; + if ((p[i].events & (POLLIN|POLLPRI)) && FD_ISSET(p[i].fd, pin)) + p[i].revents |= POLLIN; + if ((p[i].events & POLLOUT) && FD_ISSET(p[i].fd, pout)) + p[i].revents |= POLLOUT; + if (FD_ISSET(p[i].fd, &err)) + p[i].revents |= POLLHUP; + if (p[i].revents) + m++; + } + return m; +}
View file
vdr-mcli-plugin.tar.bz2/mcast/dvbfuse/crc32.c
Changed
@@ -1,88 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -/* -$Id: crc32.c,v 1.2 2006/01/02 18:24:04 rasc Exp $ - - - DVBSNOOP - - a dvb sniffer and mpeg2 stream analyzer tool - http://dvbsnoop.sourceforge.net/ - - (c) 2001-2006 Rainer.Scherg@gmx.de (rasc) - - - -- Code Module CRC32 taken von linuxtv.org -*/ - - - - -#include "defs.h" -#include "crc32.h" - - - -// CRC32 lookup table for polynomial 0x04c11db7 - -static u_long crc_table[256] = { - 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, - 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, - 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, - 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, - 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, - 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, - 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, - 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, - 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, - 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, - 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, - 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, - 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, - 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, - 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, - 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, - 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, - 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, - 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, - 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, - 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, - 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, - 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, - 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, - 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, - 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, - 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, - 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, - 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, - 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, - 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, - 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, - 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, - 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, - 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4}; - -uint32_t dvb_crc32 (char *data, int len) -{ - register int i; - u_long crc = 0xffffffff; - - for (i=0; i<len; i++) - crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *data++) & 0xff]; - - return crc; -} +(symlink to ../common/crc32.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/dvbfuse/libmcli.so
Added
+(symlink to ../client/libmcli.so)
View file
vdr-mcli-plugin.tar.bz2/mcast/dvbfuse/siparser.c
Changed
@@ -1,1027 +0,0 @@ -#include "headers.h" - -//#define DBG 1 -#define CRC32_CHECK 1 - -enum ca_desc_type { EMM, ECM }; - -//----------------------------------------------------------------------------------- -void printhex_buf(char *msg,unsigned char *buf,int len) -{ - int i,j,k; - int width=8; - - i=k=0; - sys ("%s: %d bytes (0x%04x)\n",msg,len,len); - sys ("---------------------------------------------------------------\n"); - while(len) { - sys ("%04x ",k++*width*2); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - sys ("%02x ",buf[i]); - } - if (i >= len) { - sys ("\n"); - break; - } - sys(" "); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - sys("%02x ",buf[i]); - } - sys("\n"); - if (i >= len) break; - } - sys("---------------------------------------------------------------\n"); -} -//----------------------------------------------------------------------------------- -void writehex_buf(FILE *f, char *msg,unsigned char *buf,int len) -{ - int i,j,k; - int width=8; - - i=k=0; - fprintf(f,"%s: %d bytes (0x%04x)\n",msg,len,len); - fprintf(f,"---------------------------------------------------------------\n"); - while(len) { - fprintf(f,"%04x ",k++*width*2); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - fprintf(f,"%02x ",buf[i]); - } - if (i >= len) { - fprintf(f,"\n"); - break; - } - fprintf(f," "); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - fprintf(f,"%02x ",buf[i]); - } - fprintf(f,"\n"); - if (i >= len) break; - } - fprintf(f,"---------------------------------------------------------------\n"); - - -} -//----------------------------------------------------------------------------------- -void print_ts_header(ts_packet_hdr_t *p) -{ - info("--------------------------------------------------------------\n"); - info("TS header data:\n"); - info("Sync-byte : 0x%04x\n",p->sync_byte); - info("Transport error indicator : 0x%04x\n",p->transport_error_indicator); - info("Payload unit start indicator : 0x%04x\n",p->payload_unit_start_indicator); - info("Transport priority : 0x%04x\n",p->transport_priority); - info("PID : 0x%04x\n",p->pid); - info("Transport scrambling control : 0x%04x\n",p->transport_scrambling_control); - info("Adaptation field control : 0x%04x\n",p->adaptation_field_control); - info("Continuity_counter : 0x%04x\n",p->continuity_counter); - -} -//----------------------------------------------------------------------------------- -void print_pmt(pmt_t *p) -{ - info("--------------------------------------------------------------\n"); - info("PMT section:\n"); - info("Table ID : %-5d (0x%04x)\n",p->table_id,p->table_id); - info("(fixed): : %-5d (0x%04x)\n",0,0); - info("Section syntax indicator : %-5d (0x%04x)\n",p->section_syntax_indicator,p->section_syntax_indicator); - info("Reserved 1 : %-5d (0x%04x)\n",p->reserved_1,p->reserved_1); - info("Section length : %-5d (0x%04x)\n",p->section_length,p->section_length); - info("Program number : %-5d (0x%04x)\n",p->program_number,p->program_number); - info("Reserved 2 : %-5d (0x%04x)\n",p->reserved_2,p->reserved_2); - info("Version number : %-5d (0x%04x)\n",p->version_number,p->version_number); - info("Current next indicator : %-5d (0x%04x)\n",p->current_next_indicator,p->current_next_indicator); - info("Section number : %-5d (0x%04x)\n",p->section_number,p->section_number); - info("Last section number : %-5d (0x%04x)\n",p->last_section_number,p->last_section_number); - info("Reserved 3 : %-5d (0x%04x)\n",p->reserved_3,p->reserved_3); - info("PCR pid : %-5d (0x%04x)\n",p->pcr_pid,p->pcr_pid); - info("Reserved 4 : %-5d (0x%04x)\n",p->reserved_4,p->reserved_4); - info("Program info length : %-5d (0x%04x)\n",p->program_info_length,p->program_info_length); - - - - info("CRC32 : 0x%04x\n",p->crc32); -} -//----------------------------------------------------------------------------------- -void print_pat(pat_t *p, pat_list_t *pl, int pmt_num) -{ - info("--------------------------------------------------------------\n"); - info("PAT section:\n"); - info("Table_id : %-5d (0x%04x)\n",p->table_id,p->table_id); - info("(fixed): : %-5d (0x%04x)\n",0,0); - info("Section syntax indicator : %-5d (0x%04x)\n",p->section_syntax_indicator,p->section_syntax_indicator); - info("Reserved_1 : %-5d (0x%04x)\n",p->reserved_1,p->reserved_1); - info("Section length : %-5d (0x%04x)\n",p->section_length,p->section_length); - info("Transport stream id : %-5d (0x%04x)\n",p->transport_stream_id,p->transport_stream_id); - info("Reserved 2 : %-5d (0x%04x)\n",p->reserved_2,p->reserved_2); - info("Version number : %-5d (0x%04x)\n",p->version_number,p->version_number); - info("Current next indicator : %-5d (0x%04x)\n",p->current_next_indicator,p->current_next_indicator); - info("Section number : %-5d (0x%04x)\n",p->section_number,p->section_number); - info("Last section number : %-5d (0x%04x)\n",p->last_section_number,p->last_section_number); - - if (pl && pmt_num){ - int i; - info("Number of PMTs in PAT : %-5d \n", pmt_num); - for(i=0;i<pmt_num;i++) { - pat_list_t *pat = pl + i; - info("\nProgram number : %-5d (0x%04x)\n",pat->program_number,pat->program_number); - info("Reserved : %-5d (0x%04x)\n",pat->reserved,pat->reserved); - info("Network PMT PID : %-5d (0x%04x)\n",pat->network_pmt_pid,pat->network_pmt_pid); - } - } - - info("CRC32 : 0x%04x\n",p->crc32); - - -} -//----------------------------------------------------------------------------------- -char *si_caid_to_name(unsigned int caid) -{ - - str_table table[] = { - // -- updated from dvb.org 2003-10-16 - { 0x0000, 0x0000, "Reserved" }, - { 0x0001, 0x00FF, "Standardized Systems" }, - { 0x0100, 0x01FF, "Canal Plus (Seca/MediaGuard)" }, - { 0x0200, 0x02FF, "CCETT" }, - { 0x0300, 0x03FF, "MSG MediaServices GmbH" }, - { 0x0400, 0x04FF, "Eurodec" }, - { 0x0500, 0x05FF, "France Telecom (Viaccess)" }, - { 0x0600, 0x06FF, "Irdeto" }, - { 0x0700, 0x07FF, "Jerrold/GI/Motorola" }, - { 0x0800, 0x08FF, "Matra Communication" }, - { 0x0900, 0x09FF, "News Datacom (Videoguard)" }, - { 0x0A00, 0x0AFF, "Nokia" }, - { 0x0B00, 0x0BFF, "Norwegian Telekom (Conax)" }, - { 0x0C00, 0x0CFF, "NTL" }, - { 0x0D00, 0x0DFF, "Philips (Cryptoworks)" }, - { 0x0E00, 0x0EFF, "Scientific Atlanta (Power VU)" }, - { 0x0F00, 0x0FFF, "Sony" }, - { 0x1000, 0x10FF, "Tandberg Television" }, - { 0x1100, 0x11FF, "Thompson" }, - { 0x1200, 0x12FF, "TV/COM" }, - { 0x1300, 0x13FF, "HPT - Croatian Post and Telecommunications" }, - { 0x1400, 0x14FF, "HRT - Croatian Radio and Television" }, - { 0x1500, 0x15FF, "IBM" }, - { 0x1600, 0x16FF, "Nera" }, - { 0x1700, 0x17FF, "Beta Technik (Betacrypt)" }, - { 0x1800, 0x18FF, "Kudelski SA"}, - { 0x1900, 0x19FF, "Titan Information Systems"}, - { 0x2000, 0x20FF, "TelefXnica Servicios Audiovisuales"}, - { 0x2100, 0x21FF, "STENTOR (France Telecom, CNES and DGA)"}, - { 0x2200, 0x22FF, "Scopus Network Technologies"}, - { 0x2300, 0x23FF, "BARCO AS"}, - { 0x2400, 0x24FF, "StarGuide Digital Networks "}, - { 0x2500, 0x25FF, "Mentor Data System, Inc."}, - { 0x2600, 0x26FF, "European Broadcasting Union"}, - { 0x4700, 0x47FF, "General Instrument"}, - { 0x4800, 0x48FF, "Telemann"}, - { 0x4900, 0x49FF, "Digital TV Industry Alliance of China"}, - { 0x4A00, 0x4A0F, "Tsinghua TongFang"}, - { 0x4A10, 0x4A1F, "Easycas"}, - { 0x4A20, 0x4A2F, "AlphaCrypt"}, - { 0x4A30, 0x4A3F, "DVN Holdings"}, - { 0x4A40, 0x4A4F, "Shanghai Advanced Digital Technology Co. Ltd. (ADT)"}, - { 0x4A50, 0x4A5F, "Shenzhen Kingsky Company (China) Ltd"}, - { 0x4A60, 0x4A6F, "@SKY"}, - { 0x4A70, 0x4A7F, "DreamCrypt"}, - { 0x4A80, 0x4A8F, "THALESCrypt"}, - { 0x4A90, 0x4A9F, "Runcom Technologies"}, - { 0x4AA0, 0x4AAF, "SIDSA"}, - { 0x4AB0, 0x4ABF, "Beijing Comunicate Technology Inc."}, - { 0x4AC0, 0x4ACF, "Latens Systems Ltd"}, - { 0,0, NULL } - }; - - int i = 0; - while (table[i].str) { - if (table[i].from <= caid && table[i].to >= caid) - return (char *) table[i].str; - i++; - } - - return (char *) "ERROR: Undefined!"; -} -//----------------------------------------------------------------------------------- -void get_time_mjd (unsigned long mjd, long *year , long *month, long *day) -{ - if (mjd > 0) { - long y,m,d ,k; - - // algo: ETSI EN 300 468 - ANNEX C - - y = (long) ((mjd - 15078.2) / 365.25); - m = (long) ((mjd - 14956.1 - (long)(y * 365.25) ) / 30.6001); - d = (long) (mjd - 14956 - (long)(y * 365.25) - (long)(m * 30.6001)); - k = (m == 14 || m == 15) ? 1 : 0; - y = y + k + 1900; - m = m - 1 - k*12; - *year = y; - *month = m; - *day = d; - - } - -} -//----------------------------------------------------------------------------------- -void print_tdt(tdt_sect_t *tdt, uint16_t mjd, uint32_t utc) -{ - info("--------------------------------------------------------------\n"); - info("TDT section:\n"); - info("Table_id : %-5d (0x%04x)\n",tdt->table_id,tdt->table_id); - info("Reserved : %-5d (0x%04x)\n",tdt->reserved,tdt->reserved); - info("Reserved_1 : %-5d (0x%04x)\n",tdt->reserved_1,tdt->reserved_1); - info("Section length : %-5d (0x%04x)\n",tdt->section_length,tdt->section_length); - info("UTC_time : 0x%2x%2x%2x%2x%2x\n",tdt->dvbdate[0],tdt->dvbdate[1],tdt->dvbdate[2],tdt->dvbdate[3],tdt->dvbdate[4]); - - long y,m,d; - get_time_mjd(mjd, &y, &m, &d); - info("TIME: [= %02d-%02d-%02d %02lx:%02lx:%02lx (UTC) ]\n\n",y,m,d,(utc>>16) &0xFF, (utc>>8) &0xFF, (utc) &0xFF); - info("--------------------------------------------------------------\n"); - -} -//----------------------------------------------------------------------------------- -void print_ca_desc(si_desc_t *p) -{ - info("CA desc. tag : %d (%#x)\n",p->descriptor_tag,p->descriptor_tag); - info("CA desc. length : %d (%#x)\n",p->descriptor_length,p->descriptor_length); - info("CA system id : %d (%#x)\n",p->ca_system_id,p->ca_system_id); - info("Reserverd : %d (%#x)\n",p->reserved,p->reserved); - info("CA pid : %d (%#x)\n",p->ca_pid,p->ca_pid); - - printhex_buf("Private data",p->private_data,p->descriptor_length-4); - -} -//----------------------------------------------------------------------------------- -void print_ca_bytes(si_desc_t *p) -{ - unsigned int i; - info("%x %x %x %x %x ",p->descriptor_tag, p->descriptor_length, p->ca_system_id, p->reserved, p->ca_pid); - for (i = 0; i < p->descriptor_length - 4; i++) - info("%x ",p->private_data[i]); - info(";"); - -} -//----------------------------------------------------------------------------------- -void print_cad_lst(si_cad_t *l, int ts_id) -{ - int i; - - for (i = 0; i < l->cads; i++) { - print_ca_desc(&l->cad[i]); - } - info("Total CA desc. for TS ID %d : %d\n",ts_id,l->cads); -} -//----------------------------------------------------------------------------------- -int parse_ca_descriptor(unsigned char *desc, si_desc_t *t) -{ - unsigned char *ptr=desc; - int tag=0,len=0; - - tag=ptr[0]; - len=ptr[1]; - - if (len > MAX_DESC_LEN) { - info("descriptor():Descriptor too long !\n"); - return -1; - } - - switch(tag){ - case 0x09: { - t->descriptor_tag=tag; - t->descriptor_length=len; //??? - t->ca_system_id=((ptr[2] << 8) | ptr[3]); - t->reserved=(ptr[4] >> 5) & 7; - t->ca_pid=((ptr[4] << 8) | ptr[5]) & 0x1fff; - //header 4 bytes + 2 bytes - memcpy(t->private_data,ptr+6,len-4); - - //print_ca_desc(t); - - break; - } - default: - break; - } - - return len + 2; //2 bytes tag + length -} -//-------------------------------------------------------------------------------------------- -int ca_free_cpl_desc(ca_pmt_list_t *cpl) -{ - if (cpl->pm.size > 0 && cpl->pm.cad) - free(cpl->pm.cad); - if (cpl->es.size > 0 && cpl->es.cad) - free(cpl->es.cad); - - memset(cpl,0,sizeof(ca_pmt_list_t)); - - return 0; -} -//-------------------------------------------------------------------------------------------- -int descriptor(unsigned char *desc, si_cad_t *c) -{ - unsigned char *ptr=desc; - int tag=0,len=0; - - tag=ptr[0]; - len=ptr[1]; - - if (len > MAX_DESC_LEN) { - info("descriptor():Descriptor too long !\n"); - return -1; - } - - switch(tag){ - case 0x09: { - c->cads++; - c->cad = (si_desc_t*)realloc(c->cad,sizeof(si_desc_t)*c->cads); - if (!c->cad) { - c->cads--; - info("descriptor():realloc error\n"); - return -1; - } - si_desc_t *t = c->cad + c->cads - 1; - t->descriptor_tag=tag; - t->descriptor_length=len; //??? - t->ca_system_id=((ptr[2] << 8) | ptr[3]); - t->reserved=(ptr[4] >> 5) & 7; - t->ca_pid=((ptr[4] << 8) | ptr[5]) & 0x1fff; - //header 4 bytes + 2 bytes - if (len - 4 > 0) - memcpy(t->private_data,ptr+6,len-4); - - //print_ca_desc(t); - break; - } - default: { -#if 0 - other_desc_t d; - d.descriptor_tag=tag; - d.descriptor_length=len; - memcpy(d.data,ptr+2,len); - //print_desc(d); -#endif - } - } - - return len + 2; //2 bytes tag + length -} - -//----------------------------------------------------------------------------------- -int si_get_video_pid(unsigned char *esi_buf, int size, int *vpid) -{ - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - //ptr[0] //stream type - if (ptr[0] == 2 || ptr[0] == 0x1b) - { - *vpid = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - return 1; - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - *vpid = -1; - return 0; - -} -//----------------------------------------------------------------------------------- -int si_get_audio_pid(unsigned char *esi_buf, int size, int *apid) -{ - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - //ptr[0] //stream type - if (ptr[0] == 0x1 || ptr[0] == 0x3 || ptr[0] == 0x4) - { - *apid = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - return 1; - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - *apid = -1; - return 0; - -} -//----------------------------------------------------------------------------------- -int si_get_private_pids(unsigned char *esi_buf, int size, int *upids) -{ - - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - if (ptr[0] == 0x6) - { - upids[pid_num] = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - pid_num++; - if (pid_num >= MAX_ES_PIDS) { - info ("error: ES pids number out of bounds !\n"); - return -1; - } - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - return pid_num; - -} -//----------------------------------------------------------------------------------- -int get_pmt_es_pids(unsigned char *esi_buf, int size, int *es_pids, int all) -{ - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - //ptr[0] //stream type - //int pid = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - //printf("Stream type: %d (%#x) pid = %d (%#x)\n",ptr[0], ptr[0], pid, pid); - if (ptr[0] == 0x1 || ptr[0] == 0x2 || ptr[0] == 0x3 || ptr[0] == 0x4 || ptr[0] == 0x6 || ptr[0] == 0x1b || all) - { - es_pids[pid_num] = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - pid_num++; - if (pid_num >= MAX_ES_PIDS) { - info ("error: ES pids number out of bounds !\n"); - return -1; - } - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - return pid_num; -} -//----------------------------------------------------------------------------------- -int parse_pmt_ca_desc(unsigned char *buf, int size, int sid, si_ca_pmt_t *pm_cads, si_ca_pmt_t *es_cads, pmt_t *pmt_hdr, int *fta, ca_es_pid_info_t *espids, int *es_pid_num) -{ - unsigned char *ptr=buf, tmp[PSI_BUF_SIZE]; //sections can be only 12 bit long - - memset(pm_cads,0,sizeof(si_ca_pmt_t)); - memset(es_cads,0,sizeof(si_ca_pmt_t)); - memset(pmt_hdr,0,sizeof(pmt_hdr)); - - pmt_hdr->table_id=ptr[0]; - pmt_hdr->section_syntax_indicator=(ptr[1] >> 7) & 1; - pmt_hdr->reserved_1=(ptr[1] >> 4) & 3; - pmt_hdr->section_length=((ptr[1] << 8) | ptr[2]) & 0xfff; - - if (pmt_hdr->section_length < 13 || pmt_hdr->section_length > 1021 || pmt_hdr->section_length > size) { - info("#####\nERROR: Invalid section length!\n"); - return -1; - } - - u_long crc = dvb_crc32 ((char *)buf,pmt_hdr->section_length+3); - -#ifdef DBG - info("CRCcc: 0x%lx\n",crc); - info("len = %d\n", pmt_hdr->section_length+3); -#endif - if (crc & 0xffffffff) { //FIXME: makr arch flags - info("#####\nPMT -> ERROR: parse_pmt_ca_desc() : CRC err. crc = 0x%lx\n", crc); - return -1; - } - - pmt_hdr->program_number=(ptr[3] << 8) | ptr[4]; - if (pmt_hdr->program_number != sid) { - info("#####\nERROR: Invalid SID in PMT !!!\n"); - return -1; - } - pmt_hdr->program_info_length=((ptr[10] << 8) | ptr[11]) & 0x0fff; - if (pmt_hdr->program_info_length < 0 || pmt_hdr->program_info_length > 1021 - 9 || pmt_hdr->program_info_length > size - 9) { - info("#####\nERROR: Invalid PI length in PMT!\n"); - return -1; - } - - pmt_hdr->reserved_2=(ptr[5] >> 6) & 3; - pmt_hdr->version_number=(ptr[5] >> 1) & 0x1f; - pmt_hdr->current_next_indicator=ptr[5] & 1; - pmt_hdr->section_number=ptr[6]; - pmt_hdr->last_section_number=ptr[7]; - pmt_hdr->reserved_3=(ptr[8] >> 5) & 7; - pmt_hdr->pcr_pid=((ptr[8] << 8) | ptr[9]) & 0x1fff; - pmt_hdr->reserved_4=(ptr[10] >> 4) & 0xf; - - //pmt_hdr->program_info_length=((ptr[10] << 8) | ptr[11]) & 0x0fff; - //print_pmt(pmt_hdr); - - int buf_len=0,len=0; - unsigned int i=0; - - buf_len = pmt_hdr->section_length - 9; - ptr += 12; // 12 byte header - - pm_cads->size = pm_cads->cads = 0; - for (i = 0; i < pmt_hdr->program_info_length;) { - int dtag = ptr[0]; - int dlen = ptr[1] + 2; - if (dlen > size || dlen > MAX_DESC_LEN) { - info("PMT: Invalide CA desc. length!\n"); - return -1; - } - if (dtag == 0x09) { //we have CA descriptor - memcpy(tmp + pm_cads->size, ptr, dlen); - pm_cads->size+=dlen; - pm_cads->cads++; - *fta=0; - } - i+=dlen; - if (i > pmt_hdr->program_info_length) { - info("PMT: Index out of bounds!\n"); - return -1; - } - - ptr+=dlen; //desc. length plus 2 bytes for tag and header; - if (ptr >= buf + size) { - info("PMT: Invalid Buffer offset !\n"); - return -1; - } - - buf_len-=dlen; - if (buf_len < 0) { - info("PMT: Index out of bounds!\n"); - return -1; - - } - } - - //parsing ok we can take this program level descriptors - if (pm_cads->size && pm_cads->cads) { - pm_cads->cad = (unsigned char*)malloc(sizeof(unsigned char)*pm_cads->size); - memcpy(pm_cads->cad, tmp, pm_cads->size); - } - -#ifdef DBG - info("%d bytes remaining (program info len = %d bytes)\n",buf_len,i); -#endif - - int err = 0; - es_pmt_info_t esi; - es_cads->size = es_cads->cads = 0; - *es_pid_num = 0; - while (buf_len > 4) { //end of section crc32 is 4 bytes - esi.stream_type=ptr[0]; - esi.reserved_1=(ptr[1] >> 5) & 7; - esi.elementary_pid=((ptr[1] << 8) | ptr[2]) & 0x1fff; - esi.reserved_2=(ptr[3] >> 4) & 0xf; - esi.es_info_length=((ptr[3] << 8) | ptr[4]) & 0x0fff; - - if (esi.es_info_length > buf_len) { - info("PMT: Invalid ES info length !\n"); - err = -1; - break; - } - - if (espids) { - switch(esi.stream_type) { - case VIDEO_11172_STREAM_TYPE: - case VIDEO_13818_STREAM_TYPE: - case VISUAL_MPEG4_STREAM_TYPE: - case VIDEO_H264_STREAM_TYPE: - case AUDIO_11172_STREAM_TYPE: - case AUDIO_13818_STREAM_TYPE: - espids[*es_pid_num].pid = esi.elementary_pid; - espids[*es_pid_num].type = esi.stream_type; - break; - default: - espids[*es_pid_num].pid = esi.elementary_pid; - espids[*es_pid_num].type = 0; - - } - } - memcpy(tmp + es_cads->size, ptr, 5); - tmp[es_cads->size+1] &= 0x1f; //remove reserved value ??? - tmp[es_cads->size+3] &= 0x0f; //remove reserved value ??? - - int es_info_len_pos = es_cads->size+3; //mark length position to set it later - int cur_len = 0; //current ES stream descriptor length - - es_cads->size += 5; - ptr += 5; - buf_len -= 5; - len=esi.es_info_length; - while(len > 0) { - int dtag = ptr[0]; - int dlen = ptr[1] + 2; //2 bytes for tag and len - - if (dlen > len || dlen > MAX_DESC_LEN) { - info("PMT: Invalide CA desc. length!\n"); - err = -1; - break; - } - - if (dtag == 0x09) { //we have CA descriptor - memcpy(tmp + es_cads->size, ptr, dlen); - es_cads->size += dlen; - es_cads->cads++; - cur_len += dlen; - *fta=0; - } - if (espids) { - if (espids[*es_pid_num].type == 0) { - switch(dtag) { - case TeletextDescriptorTag: - case SubtitlingDescriptorTag: - case AC3DescriptorTag: - case EnhancedAC3DescriptorTag: - case DTSDescriptorTag: - case AACDescriptorTag: - espids[*es_pid_num].type = dtag; - //go to next pid - } - } - } - - ptr += dlen; - if (ptr >= buf + size) { - info("PMT: Invalid Buffer offset !\n"); - err = -1; - break; - } - - len -= dlen; - buf_len -= dlen; - } - if (err == -1) { - break; - } - tmp[es_info_len_pos] = (cur_len >> 8) & 0xff; - tmp[es_info_len_pos+1] = cur_len & 0xff; - if (espids) { - if (espids[*es_pid_num].type) { - //go to next pid - (*es_pid_num)++; - if (*es_pid_num >= MAX_ES_PIDS) { - info ("ERROR: ES pids array index out bounds (pids %d sid %d)!\n", *es_pid_num, pmt_hdr->program_number); - break; - } - } - } - } - - //parsing ok we can take this ES level descriptors - if (((es_cads->cads && es_cads->size) || (pm_cads->cads && es_cads->size)) || *fta) { //take ES stream info if we have PM or ES desc. - es_cads->cad = (unsigned char*)malloc(sizeof(unsigned char)*es_cads->size); - memcpy(es_cads->cad, tmp, es_cads->size); - - } - -#ifdef DBG - info("%d bytes remaining\n",buf_len); -#endif - - pmt_hdr->crc32=(ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; - - if (len < 0 || err == -1) { - info("ERROR: parse_ca_desc() : section index out of bounds %d or (CRC err.) crc in sec. = 0x%x crc calc. = 0x%lx\n", buf_len,pmt_hdr->crc32, crc); -#ifdef DBG - print_pmt(&pmt_hdr); -#endif - //cleanup ... - if (pm_cads->size) - free(pm_cads->cad); - if (es_cads->size) - free(es_cads->cad); - *es_pid_num = 0; - memset(pm_cads,0,sizeof(si_ca_pmt_t)); - memset(es_cads,0,sizeof(si_ca_pmt_t)); - return -1; - } - -#ifdef DBG - info("#####################################\n"); - info("parse_ca_desc(): section parsed: OK !\n"); -#endif - return 0; -} -//----------------------------------------------------------------------------------- -int parse_cat_sect(unsigned char *buf, int size, si_cad_t *emm) -{ - unsigned char *ptr=buf; - int len,i,ret; - cat_t c; - - c.table_id = ptr[0]; - c.section_syntax_indicator = (ptr[1] >> 7) & 1; - c.reserved_1 = (ptr[1] >> 4) & 3; - c.section_length = ((ptr[1] << 8) | ptr[2]) & 0xfff; - - if (c.section_length < 9 || c.section_length > 1021 || c.section_length > size) { - info("CAT: Invalid section length!\n"); - return -1; - } - -#ifdef CRC32_CHECK - u_long crc = dvb_crc32 ((char *)buf,c.section_length+3); -#ifdef DBG - info("CRCcc: 0x%lx\n",crc); -#endif - if (crc & 0xffffffff) { - info("CAT:CRC32 error (0x%lx)!\n",crc); - return -1; - } -#endif - - c.reserved_2 = (ptr[3] << 10) | (ptr[4] << 2) | ((ptr[5] >> 6) & 3); - c.version_number = (ptr[5] >> 1) & 0x1f; - c.current_next_indicator = ptr[5] & 1; - c.section_number = ptr[6]; - c.last_section_number = ptr[7]; - - - //do desc. here - len = c.section_length - 5; - ptr+=8; //go after hdr. - - i = len; - while(i > 4) { //crc32 4 bytes - ret = descriptor(ptr, emm); - if (ret < 0) { - info ("cannot parse CA descriptor in CAT !\n"); - return -1; - } - i-=ret; - ptr+=ret; - if (ptr >= buf + size) { - info("CAT: Invalid Buffer offset !\n"); - break; - } - } - if (i != 4) { - info("CAT: index out of bounds !\n"); - return -1; - } -#ifdef DBG - info("%d bytes remaining (program info len = %d bytes)\n",len-i,len); -#endif - c.crc32 = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; - - - return 0; -} -//----------------------------------------------------------------------------------- -int parse_pat_sect(unsigned char *buf, int size, pmt_pid_list_t *pmt) -{ - unsigned char *ptr=buf; - pat_t p; - pat_list_t *pat_info = NULL; - - memset(&p,0,sizeof(p)); - - p.table_id=ptr[0]; - p.section_syntax_indicator=(ptr[1] & 0x80) >> 7; - p.reserved_1=(ptr[1] & 0x30) >> 4; - p.section_length=((ptr[1] << 8) | ptr[2]) & 0x0fff; - - if (p.section_length < 9 || p.section_length > 1021 || p.section_length > size) { - info("PAT: Invalid section length !\n"); - return -1; - - } - -#ifdef CRC32_CHECK - u_long crc = dvb_crc32 ((char *)buf,p.section_length+3); - //FIXME: is it the right way ? - if (crc & 0xffffffff) { - info("PAT:CRC32 error (0x%lx)!\n",crc); - return -1; - } -#endif - - p.transport_stream_id=(ptr[3] << 8) | ptr[4]; - p.reserved_2=(ptr[5] & 0xc0) >> 6; - p.version_number=(ptr[5] & 0x3e) >> 1; - p.current_next_indicator=(ptr[5] & 1); - p.section_number=ptr[6]; - p.last_section_number=ptr[7]; - - int n,i,pmt_num; - - n = p.section_length - 5 - 4; //bytes following section_length field + crc32 chk_sum - - ptr+=8; - pmt_num=0; - if (n > 0 && ((ptr + n) < (buf + size))) { - pat_info=(pat_list_t *)malloc(sizeof(pat_list_t)*n/4); - for(i=0;i<n;i+=4) { - pat_list_t *pat = pat_info + pmt_num; - pat->program_number=(ptr[0] << 8) | (ptr[1]); - pat->reserved=(ptr[2] & 0xe0) >> 5; - pat->network_pmt_pid=((ptr[2] << 8) | ptr[3]) & 0x1fff; - if (pat->network_pmt_pid != 0x10) { //NIT => FIXME: remove other known pids - // memset(&pat->desc,0,sizeof(pmt_desc_list_t)); - pmt_num++; - } - ptr+=4; - } - - p.crc32=(ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; - if (n != pmt_num) - pat_info=(pat_list_t *)realloc(pat_info,sizeof(pat_list_t)*pmt_num); - } - if (pmt) { - pmt->p=p; - pmt->pl=pat_info; - pmt->pmt_pids=pmt_num; - } - - return 0; -} -int parse_tdt_sect(unsigned char *buf, int size, tdt_sect_t *tdt) -{ - unsigned char *ptr = buf; - - tdt->table_id=ptr[0]; - tdt->section_syntax_indicator=(ptr[1] & 0x80) >> 7; - tdt->reserved_1=(ptr[1] >> 4) >> 3; - tdt->section_length=((ptr[1] << 8) | ptr[2]) & 0x0fff; - - if (tdt->section_length != 5) { - info("TDT: Invalid section length !\n"); - return -1; - } - - //copy UTC time MJD + UTC - memcpy(tdt->dvbdate, ptr + 3, 5); - - return 0; - -} -//----------------------------------------------------------------------------------- -//TS packets handling -int get_ts_packet_hdr(unsigned char *buf, ts_packet_hdr_t *p) -{ - unsigned char *ptr=buf; - - memset(p,0,sizeof(p)); - - p->sync_byte=ptr[0]; - p->transport_error_indicator=(ptr[1] & 0x80) >> 7; - p->payload_unit_start_indicator=(ptr[1] & 0x40) >> 6; - p->transport_priority=(ptr[1] & 0x20) >> 5; - p->pid=((ptr[1] << 8) | ptr[2]) & 0x1fff; - p->transport_scrambling_control=(ptr[3] & 0xC0) >> 6; - p->adaptation_field_control=(ptr[3] & 0x30) >> 4; - p->continuity_counter=(ptr[3] & 0xf); - -#ifdef DBG - print_ts_header(p); -#endif - - return 0; - -} -//----------------------------------------------------------------------------------- -int ts2psi_data(unsigned char *buf,psi_buf_t *p,int len, int pid_req) -{ - unsigned char *b=buf; - ts_packet_hdr_t h; - - - get_ts_packet_hdr(buf,&h); - - b+=4; - len-=4; - - if (h.sync_byte != 0x47) { -#ifdef SERVER - sys("%s:No sync byte in header !\n",__FUNCTION__); -#endif - return -1; - } - - - if (pid_req != h.pid) { -#ifdef DBG - info("%s:pids mismatch (pid req = %#x ts pid = %#x )!\n", __FUNCTION__,pid_req, h.pid); -#endif - return -1; - } - - //FIXME:Handle adaptation field if present/needed - if (h.adaptation_field_control & 0x2) { - int n; - - n=b[0]+1; - b+=n; - len-=n; - - } - - if (h.adaptation_field_control & 0x1) { - if (h.transport_error_indicator) { -#ifdef DBG - info("Transport error flag set !\n"); -#endif - return -1; - } - if (h.transport_scrambling_control) { -#ifdef DBG - info("Transport scrambling flag set !\n"); -#endif - //return -1; - } - - if (h.payload_unit_start_indicator && p->start) { //whole section new begin packet -#ifdef DBG - info("%s:section read !\n",__FUNCTION__); -#endif - return 1; - } - - if (h.payload_unit_start_indicator && !p->start) { //packet beginning - int si_offset=b[0]+1; //always pointer field in first byte of TS packet payload with start indicator set - b+=si_offset; - len-=si_offset; - if (len < 0 || len > 184) { -#ifdef DBG - info("WARNING 1: TS Packet damaged !\n"); -#endif - return -1; - } - //move to buffer - memcpy(p->buf,b,len); - p->len=len; - p->start=((b[1] << 8) | b[2]) & 0x0fff; //get section length, using start for length - p->pid=h.pid; - p->continuity=h.continuity_counter; - - } - - if (!h.payload_unit_start_indicator && p->start) { //packet continuation - //duplicate packet - if ((p->pid == h.pid) && (p->continuity == h.continuity_counter)){ -#ifdef DBG - info("Packet duplicate ???\n"); -#endif - return -1; - } - //new packet - if (p->pid != h.pid) { -#ifdef DBG - info("New pid buf start %d len %d bytes (pid in buf = %d pid in ts = %d) !\n", p->start,p->len, p->pid, h.pid); -#endif - return -1; - } - //discontinuity of packets - if (((++p->continuity)%16) != h.continuity_counter) { -#ifdef DBG - info("Discontinuity of ts stream !!!\n"); -#endif - return -1; - } - p->continuity=h.continuity_counter; - if (len < 0 || len > 184) { - info("WARNING 2: TS Packet damaged !\n"); - return -1; - } - //move to buffer - memcpy(p->buf+p->len,b,len); - p->len+=len; //FIXME: circular buffer - if (p->len + 188 > PSI_BUF_SIZE) { - info("Error: Buffer full !\n"); - return -1; - //FIXME:realloc - } - } - } - -#if 1 - //3 bytes for bytes containing table id and section length - TS_SECT_LEN(b); - if (slen+3 <= len && h.payload_unit_start_indicator) //len = 188 bytes - 4 bytes ts hdr. - adapt. field bytes - 1 byte offset - offset - return 1; -#else //possible opt. - /*if (p->start+3 == len) - return 1;*/ -#endif - - return 0; -} -//TS packets handling end -//----------------------------------------------------------------------------------- - - - +(symlink to ../common/siparser.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/crc32.c
Changed
@@ -1,88 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -/* -$Id: crc32.c,v 1.2 2006/01/02 18:24:04 rasc Exp $ - - - DVBSNOOP - - a dvb sniffer and mpeg2 stream analyzer tool - http://dvbsnoop.sourceforge.net/ - - (c) 2001-2006 Rainer.Scherg@gmx.de (rasc) - - - -- Code Module CRC32 taken von linuxtv.org -*/ - - - - -#include "defs.h" -#include "crc32.h" - - - -// CRC32 lookup table for polynomial 0x04c11db7 - -static u_long crc_table[256] = { - 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, - 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, - 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, - 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, - 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, - 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, - 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, - 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, - 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, - 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, - 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, - 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, - 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, - 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, - 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, - 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, - 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, - 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, - 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, - 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, - 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, - 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, - 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, - 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, - 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, - 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, - 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, - 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, - 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, - 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, - 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, - 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, - 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, - 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, - 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4}; - -uint32_t dvb_crc32 (char *data, int len) -{ - register int i; - u_long crc = 0xffffffff; - - for (i=0; i<len; i++) - crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *data++) & 0xff]; - - return crc; -} +(symlink to ../common/crc32.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/dvbipstream.h
Changed
@@ -4,10 +4,12 @@ #include "headers.h" #include "misc.h" -#define MAXAPIDS 4 +#define MAXAPIDS 32 #define MAXDPIDS 4 #define MAXCAIDS 2 +#define TS_PER_UDP 7 + typedef struct { int number; @@ -42,15 +44,26 @@ int NumDpids; int eitpids[1]; int NumEitpids; + int sdtpids[1]; + int NumSdtpids; } channel_t; +typedef struct _stream_buffer_t +{ + struct _stream_buffer_t *next; + char data[TS_PER_UDP*188]; +} stream_buffer_t; + typedef struct { recv_info_t *r; - char *buffer; - int rp, wp; - off_t offset; + stream_buffer_t *free; + stream_buffer_t *head; + stream_buffer_t *tail; + stream_buffer_t *wr; + stream_buffer_t *rd; + int fill; int si_state; psi_buf_t psi; channel_t *cdata; @@ -61,11 +74,10 @@ pthread_t t; int stop; int ts_cnt; - pthread_mutex_t lock_wr; - pthread_mutex_t lock_rd; + pthread_mutex_t lock_bf; + pthread_mutex_t lock_ts; } stream_info_t; - channel_t *read_channel_list (char *filename); int get_channel_num (void); @@ -75,7 +87,9 @@ // mcilink.c void mcli_startup (void); void* mcli_stream_setup (const int channum); -size_t mcli_stream_read (void* handle, char *buf, size_t maxlen, off_t offset); +size_t mcli_stream_access (void* handle, char **buf); +size_t mcli_stream_part_access (void* handle, char **buf); +void mcli_stream_skip (void* handle); int mcli_stream_stop (void* handle); // parse.c
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/iface.c
Changed
@@ -94,7 +94,8 @@ nifaces = ifconf.ifc_len/sizeof(struct ifreq); - printf("Interfaces (count = %d):\n", nifaces); + if (!quiet) + printf("Interfaces (count = %d):\n", nifaces); for(i = 0; i < nifaces; i++) { @@ -104,7 +105,8 @@ if(get_iface_ipaddress(&ifreqs[i])<0) continue; addr = (u_char *) & (((struct sockaddr_in *)&(ifreqs[i]).ifr_addr)->sin_addr); - printf("\t%i - %-10s : addr %d.%d.%d.%d\n",(i+1),ifreqs[i].ifr_name,addr[0],addr[1],addr[2],addr[3]); + if (!quiet) + printf("\t%i - %-10s : addr %d.%d.%d.%d\n",(i+1),ifreqs[i].ifr_name,addr[0],addr[1],addr[2],addr[3]); iflist[i].ipaddr = ( (struct sockaddr_in *)&(ifreqs[i]).ifr_addr)->sin_addr.s_addr; } @@ -125,13 +127,12 @@ int discover_interfaces(iface_t iflist[]) { + if (!quiet) printf("Interfaces:\n"); /* Declare and initialize variables */ - DWORD dwSize = 0; DWORD dwRetVal = 0; - unsigned int i = 0; unsigned int anum = 0; // Set the flags to pass to GetAdaptersAddresses @@ -179,8 +180,10 @@ // If successful, output some information from the data we received pCurrAddresses = pAddresses; while (pCurrAddresses) { - printf("\tIfIndex (IPv4 interface): %u\n", pCurrAddresses->IfIndex); - printf("\tAdapter name: %s\n", pCurrAddresses->AdapterName); + if (!quiet) { + printf("\tIfIndex (IPv4 interface): %u\n", (unsigned int)pCurrAddresses->IfIndex); + printf("\tAdapter name: %s\n", pCurrAddresses->AdapterName); + } strncpy(iflist[anum].name, pCurrAddresses->AdapterName, IFNAMSIZ); pUnicast = pCurrAddresses->FirstUnicastAddress; @@ -188,17 +191,27 @@ if (pCurrAddresses->OperStatus == IfOperStatusUp) { if (pUnicast != NULL) { - printf("\tUnicast Address: %s\n", inet_ntoa(((struct sockaddr_in*)(pUnicast->Address.lpSockaddr))->sin_addr) ); + if (!quiet) + printf("\tUnicast Address: %s\n", inet_ntoa(((struct sockaddr_in*)(pUnicast->Address.lpSockaddr))->sin_addr) ); iflist[anum].ipaddr = ((struct sockaddr_in*)(pUnicast->Address.lpSockaddr))->sin_addr.S_un.S_addr; - } else + } else { + if (!quiet) printf("\tNo Unicast Addresses\n"); + } + + if (!quiet) { +#ifndef __MINGW32__ + printf("\tDescription: %wS\n", pCurrAddresses->Description); + printf("\tFriendly name: %wS\n", pCurrAddresses->FriendlyName); +#else + printf("\tDescription: %ls\n", pCurrAddresses->Description); + printf("\tFriendly name: %ls\n", pCurrAddresses->FriendlyName); +#endif - printf("\tDescription: %wS\n", pCurrAddresses->Description); - printf("\tFriendly name: %wS\n", pCurrAddresses->FriendlyName); - - printf("\tMtu: %lu\n", pCurrAddresses->Mtu); + printf("\tMtu: %lu\n", pCurrAddresses->Mtu); - printf("\n"); + printf("\n"); + } anum++; } @@ -206,7 +219,7 @@ } } else { printf("Call to GetAdaptersAddresses failed with error: %d\n", - dwRetVal); + (int)dwRetVal); if (dwRetVal == ERROR_NO_DATA) printf("\tNo addresses were found for the requested parameters\n"); else { @@ -216,7 +229,7 @@ NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) & lpMsgBuf, 0, NULL)) { - printf("\tError: %s", lpMsgBuf); + printf("\tError: %s", (char *)lpMsgBuf); LocalFree(lpMsgBuf); if (pAddresses) FREE(pAddresses);
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/igmp.c
Changed
@@ -2,9 +2,13 @@ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN -#include <ws2tcpip.h> +#include <winsock2.h> +#ifndef __MINGW32__ #include <mstcpip.h> #else +#define SIO_RCVALL_IGMPMCAST _WSAIOW(IOC_VENDOR,3) +#endif +#else #include <sys/socket.h> #include <unistd.h> #include <netinet/in.h> @@ -13,6 +17,7 @@ #ifdef APPLE #include <netinet/ip_mroute.h> #else +#define _LINUX_IN_H #include <linux/mroute.h> #endif #endif @@ -142,10 +147,12 @@ #endif } -bool cIgmpListener::Initialize(iface_t bindif) +bool cIgmpListener::Initialize(iface_t bindif, int table) { int rc = 0; +#ifndef WIN32 int val = 0; +#endif m_bindaddr = bindif.ipaddr; @@ -173,6 +180,17 @@ #ifndef WIN32 +#ifdef MRT_TABLE + if ( table ) + { + rc = ::setsockopt( m_socket, IPPROTO_IP, MRT_TABLE, (void*)&table, sizeof(table) ); + if ( rc < 0 ) + { + log_socket_error("IGMP setsockopt(MRT_TABLE)"); + printf("IGMPv2 policy routing won't work! Please enable multicast policy routing option in the kernel configuration!\n"); + } + } +#endif val = 1; rc = ::setsockopt( m_socket, IPPROTO_IP, MRT_INIT, (void*)&val, sizeof(val) ); if ( rc < 0 ) @@ -290,61 +308,51 @@ void cIgmpListener::Action() { int recvlen; - char recv_buf[8192]; - int MaxFD; - fd_set ReadFDS; - struct timeval tv; - int Rt; + struct pollfd p; + char recv_buf[8192]; + p.fd = m_socket; + p.events = POLLIN; + while (Running()) { - tv.tv_usec = 0; - tv.tv_sec = 1; - - MaxFD = m_socket; - FD_ZERO( &ReadFDS ); - FD_SET( m_socket, &ReadFDS ); - - // wait for input - Rt = ::select( MaxFD +1, &ReadFDS, NULL, NULL, &tv ); + switch (poll(&p,1,1000)) { + case -1: +#ifndef WIN32 + if ( (errno != EINTR) && (errno != EWOULDBLOCK) ) +#else + int Rt; + Rt = WSAGetLastError(); + if ( (Rt != WSAEINTR) && (Rt != WSAEWOULDBLOCK) ) +#endif + log_socket_error( "IGMP poll()" ); + case 0: + continue; - // log and ignore failures - if( Rt < 0 ) - { - log_socket_error( "IGMP select()" ); - continue; - } - else if( Rt > 0 ) - { + default: + if (!(p.revents&POLLIN)) + continue; - // Read IGMP request, and handle it... - if( FD_ISSET( m_socket, &ReadFDS ) ) + recvlen = recv(m_socket, (char*)&recv_buf, sizeof(recv_buf), 0); + if (recvlen < 0) { - recvlen = ::recv(m_socket, (char*)&recv_buf, sizeof(recv_buf), 0); - if (recvlen < 0) - { #ifndef WIN32 - if ( (errno == EINTR) || (errno == EWOULDBLOCK) ) - continue; + if ( (errno == EINTR) || (errno == EWOULDBLOCK) ) #else - Rt = WSAGetLastError(); - if ( (Rt == WSAEINTR) || (Rt == WSAEWOULDBLOCK) ) - continue; + int Rt; + Rt = WSAGetLastError(); + if ( (Rt == WSAEINTR) || (Rt == WSAEWOULDBLOCK) ) #endif - log_socket_error("IGMP recv()"); - break; - } - /* - printf("recvlen: %d\n", recvlen); - for(int i=0; i<recvlen; i++) - printf("%02x ", (unsigned char) recv_buf[i]); - printf("\n"); - */ - Parse(recv_buf, recvlen); + continue; + log_socket_error("IGMP recv()"); + goto out; } + Parse(recv_buf, recvlen); + break; } } +out:; } void cIgmpListener::Parse(char* buffer, int len) @@ -361,23 +369,25 @@ // Check that IP version is IPV4 and that payload is IGMP if ( (HI_BYTE(*buf) == 4) && ( *(buf+9) == IPPROTO_IGMP) ) { + if (!quiet) { printf("IGMP: SrcAddr: %d.%d.%d.%d -> ", (unsigned char) *(buf+12), (unsigned char) *(buf+13), (unsigned char) *(buf+14), (unsigned char) *(buf+15) ); printf("DstAddr: %d.%d.%d.%d\n", (unsigned char) *(buf+16), (unsigned char) *(buf+17), (unsigned char) *(buf+18), (unsigned char) *(buf+19) ); - memcpy(&senderaddr, buf+12, 4); + } + memcpy(&senderaddr, buf+12, 4); - // skip rest of ip header and move to next to next protocol header - len -= LO_BYTE(*buf) * 4; - buf += LO_BYTE(*buf) * 4; + // skip rest of ip header and move to next to next protocol header + len -= LO_BYTE(*buf) * 4; + buf += LO_BYTE(*buf) * 4; uint16_t chksum = ((*(buf+3)<<8)&0xFF00 ) | (*(buf+2) & 0x00FF); *(buf+2) = 0; *(buf+3) = 0; if (chksum != inetChecksum((uint16_t *)buf, len)) { - printf("IGMP: INVALID CHECKSUM 0x%04x 0x%04x - discarding packet.\n", - chksum, inetChecksum((uint16_t *)buf, len)); + printf("IGMP: INVALID CHECKSUM 0x%04x 0x%04x - discarding packet.\n", + chksum, inetChecksum((uint16_t *)buf, len)); return; } @@ -385,38 +395,43 @@ { if ( *buf == 0x11 ) { - printf("IGMP: Version: %s, Type: Membership Query\n", (*(buf+1) == 0 ) ? "1":"2"); - printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), - (unsigned char) *(buf+6), (unsigned char) *(buf+7) - ); + if (!quiet) { + printf("IGMP: Version: %s, Type: Membership Query\n", (*(buf+1) == 0 ) ? "1":"2"); + printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), + (unsigned char) *(buf+6), (unsigned char) *(buf+7)); + } memcpy(&groupaddr, buf+4, 4); m_IgmpMain->ProcessIgmpQueryMessage( groupaddr, senderaddr ); } else if ( *buf == 0x12 ) { - printf("IGMP: Version: 1, Type: Membership Report\n"); + if (!quiet) + printf("IGMP: Version: 1, Type: Membership Report\n"); } else if (*buf == 0x16) { - printf("IGMP: Version: 2, Type: Membership Report\n"); + if (!quiet) + printf("IGMP: Version: 2, Type: Membership Report\n"); } else if (*buf == 0x17) { - printf("IGMP: Version: 2, Type: Leave Group\n"); + if (!quiet) + printf("IGMP: Version: 2, Type: Leave Group\n"); } - printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), - (unsigned char) *(buf+6), (unsigned char) *(buf+7) - ); + if( !quiet) + printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), + (unsigned char) *(buf+6), (unsigned char) *(buf+7)); memcpy(&groupaddr, buf+4, 4); m_IgmpMain->ProcessIgmpReportMessage( (int) *buf, groupaddr, senderaddr); } else if ( (*buf == 0x11) && (len > 8) ) { - printf("IGMP: Version: 3, Type: Membership Query, Maximum Response Time: %d\n",*(buf+1)); - printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), - (unsigned char) *(buf+6), (unsigned char) *(buf+7) - ); + if (!quiet) { + printf("IGMP: Version: 3, Type: Membership Query, Maximum Response Time: %d\n",*(buf+1)); + printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), + (unsigned char) *(buf+6), (unsigned char) *(buf+7)); + } memcpy(&groupaddr, buf+4, 4); m_IgmpMain->ProcessIgmpQueryMessage( groupaddr, senderaddr ); @@ -424,29 +439,26 @@ else if ( (*buf == 0x22) && (len > 8) ) { unsigned short numrecords = ntohs((unsigned short)*(buf+7)<<8|*(buf+6)); - printf("IGMP: Version: 3, Type: Membership Report, Number of Records: %d\n",numrecords); + if (!quiet) + printf("IGMP: Version: 3, Type: Membership Report, Number of Records: %d\n",numrecords); // Skip Header and move to records buf += 8; for(int i = 0; i<numrecords; i++) { unsigned short numsources = (unsigned short)*(buf+3)<<8|*(buf+2); - printf(" ---> Record No: %d, Type: %d, Number of Sources: %d\n", - i+1, - *buf, - numsources - ); - printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), - (unsigned char) *(buf+6), (unsigned char) *(buf+7) - ); + if (!quiet) { + printf(" ---> Record No: %d, Type: %d, Number of Sources: %d\n", i+1, *buf, numsources); + printf(" Group: %d.%d.%d.%d\n", (unsigned char) *(buf+4), (unsigned char) *(buf+5), + (unsigned char) *(buf+6), (unsigned char) *(buf+7)); + } memcpy(&groupaddr, buf+4, 4); m_IgmpMain->ProcessIgmpReportMessage( (int) *buf, groupaddr, senderaddr); - for(int j = 0; j<numsources; j++) + if (!quiet) for(int j = 0; j<numsources; j++) { printf(" Sources: %d.%d.%d.%d\n", (unsigned char) *(buf+j*4), (unsigned char) *(buf+j*4+1), - (unsigned char) *(buf+j*4+2), (unsigned char) *(buf+j*4+3) - ); + (unsigned char) *(buf+j*4+2), (unsigned char) *(buf+j*4+3)); // move to next record: header bytes + aux data len } buf += 8 + *(buf+1) + (numsources *4); @@ -505,16 +517,18 @@ // ------------------------------------------------------------------------------------------------------------------------- -cIgmpMain::cIgmpMain(cStreamer* streamer, iface_t bindif) +cIgmpMain::cIgmpMain(cStreamer* streamer, iface_t bindif, int table) : cThread("IGMP timeout handler") { m_bindaddr = bindif.ipaddr; m_bindif = bindif; + m_table = table; m_IgmpListener = new cIgmpListener(this); m_StartupQueryCount = IGMP_STARTUP_QUERY_COUNT; m_Querier = true; m_streamer = streamer; + m_stopping = 0; TV_CLR(m_GeneralQueryTimer); } @@ -530,6 +544,7 @@ } // Wake up timeout thread in case it is currently sleeping + m_stopping=1; m_CondWait.Signal(); // Now try to stop thread. After 3 seconds it will be canceled. @@ -554,7 +569,7 @@ bool cIgmpMain::StartListener(void) { - if ( m_IgmpListener && m_IgmpListener->Initialize(m_bindif) ) + if ( m_IgmpListener && m_IgmpListener->Initialize(m_bindif, m_table) ) { Start(); return true; @@ -654,7 +669,8 @@ LOCK_THREAD; if (TV_CMP(m_GeneralQueryTimer, <, now)) { - printf("IGMP: Starting General Query.\n"); + if (!quiet) + printf("IGMP: Starting General Query.\n"); IGMPSendGeneralQuery(); IGMPStartGeneralQueryTimer(); } @@ -697,7 +713,12 @@ sleep += (next.tv_usec - now.tv_usec) / 1000; if (next.tv_usec < now.tv_usec) sleep += 1000; - printf("IGMP main thread: Sleeping %d ms\n", sleep); + if (m_stopping) + sleep = 100; + else if (!sleep) + continue; + if (!quiet) + printf("IGMP main thread: Sleeping %d ms\n", sleep); m_CondWait.Wait(sleep); } }
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/igmp.h
Changed
@@ -3,8 +3,7 @@ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN -#include <ws2tcpip.h> -#include <mstcpip.h> +#include <winsock2.h> #else #include <sys/socket.h> #include <netinet/in.h> @@ -49,7 +48,7 @@ public: cIgmpListener(cIgmpMain* igmpmain); - bool Initialize(iface_t bindif); + bool Initialize(iface_t bindif, int table); void Destruct(void); bool Membership(in_addr_t mcaddr, bool Add); void IGMPSendQuery(in_addr_t Group, int Timeout); @@ -71,7 +70,7 @@ class cIgmpMain : public cThread { public: - cIgmpMain(cStreamer* streamer, iface_t bindif); + cIgmpMain(cStreamer* streamer, iface_t bindif, int table); ~cIgmpMain(void); bool StartListener(void); void Destruct(void); @@ -86,6 +85,7 @@ cIgmpListener* m_IgmpListener; in_addr_t m_bindaddr; iface_t m_bindif; + int m_table; cList<cMulticastGroup> m_Groups; @@ -111,6 +111,7 @@ // Main thread virtual void Action(); cCondWait m_CondWait; + int m_stopping; // Helper cMulticastGroup* FindGroup(in_addr_t Group) const;
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/main.c
Changed
@@ -15,6 +15,15 @@ #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> +#ifndef APPLE +#define _LINUX_IN_H +#include <linux/mroute.h> +#endif +#else +#include <direct.h> +#ifdef __MINGW32__ +#include <getopt.h> +#endif #endif #include "streamer.h" @@ -36,10 +45,13 @@ int channel_num=0; int channel_max_num=0; int channel_use_eit = 0; +int channel_use_sdt = 0; int portnum = 12345; +int table = 0; +int quiet = 0; /*-------------------------------------------------------------------------*/ -channel_t * read_channel_list(char *filename) +channel_t * read_channel_list(char *filename, char *dirname) { FILE *cf; FILE *pf; @@ -50,9 +62,27 @@ printf("Can't read %s: %s\n",filename,strerror(errno)); return NULL; } + + if (dirname) { +#ifdef WIN32 + if (((dirname[0]>='A'&&dirname[0]<='Z') || (dirname[0]>='a'&&dirname[0]<='z')) && dirname[1]==':') { + if (_chdrive((dirname[0]&0xdf)-'A'+1)) { + printf("Can't access %s: %s\n", dirname, strerror(errno)); + fclose(cf); + return NULL; + } + } +#endif + if (chdir(dirname)) { + printf("Can't access %s: %s\n", dirname, strerror(errno)); + fclose(cf); + return NULL; + } + } + pf =fopen("channels.m3u", "w"); if (!pf) { - printf("Can't read %s: %s\n", "channels.m3u", strerror(errno)); + printf("Can't create %s: %s\n", "channels.m3u", strerror(errno)); fclose(cf); return NULL; } @@ -62,13 +92,20 @@ if (channel_num==channel_max_num) { channel_max_num+=200; channels=(channel_t*)realloc(channels,channel_max_num*sizeof(channel_t)); + if (!channels) { + printf("out of memory\n"); + fclose(pf); + fclose(cf); + return NULL; + } } fgets(buf,512,cf); if ( !feof(cf) && ParseLine(buf,&channels[channel_num])) { int ip1 = (channel_num+1)/256; int ip2 = (channel_num) - (ip1*256) + 1; - printf("%i: udp://@239.255.%i.%i:%i - %s \n", - channel_num+1, ip1, ip2, 12345, channels[channel_num].name); + if (!quiet) + printf("%i: udp://@239.255.%i.%i:%i - %s \n", + channel_num+1, ip1, ip2, 12345, channels[channel_num].name); fprintf(pf, "#EXTINF: %i,%s\n", channel_num+1, channels[channel_num].name); fprintf(pf, "udp://@239.255.%i.%i:%i\n", ip1,ip2, portnum); if (channel_use_eit) @@ -76,6 +113,11 @@ channels[channel_num].NumEitpids = 1; channels[channel_num].eitpids[0] = 0x12; } + if (channel_use_sdt) + { + channels[channel_num].NumSdtpids = 1; + channels[channel_num].sdtpids[0] = 0x11; + } channel_num++; } } @@ -116,14 +158,26 @@ void usage (void) { - printf("Usage: netcv2dvbip [-b <multicast interface>] [-p <port>] [-i <netceiver interface>] [-c <channels.conf>] [-e activate EIT PID (EPG)\n"); - exit(0); + printf("Usage: netcv2dvbip " + "[-b <multicast interface>] " + "[-p <port>] " + "[-i <netceiver interface>] " + "[-c <channels.conf>] " + "[-e activate EIT PID (EPG)] " + "[-s activate SDT PID (may be required for EPG)] " +#ifdef MRT_TABLE + "[-t <routing table number> (requires CONFIG_IP_MROUTE_MULTIPLE_TABLES)] " +#endif + "[-q be more quiet on the screen] " + "[-o <output directory>]\n"); + exit(1); } /*-------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char c; + char *dirname = NULL; char channels[_POSIX_PATH_MAX]; strcpy(channels, "channels.conf"); char bindiface[IFNAMSIZ]; @@ -160,7 +214,11 @@ while(1) { - int ret = getopt(argc,argv, "i:hc:b:p:e"); + int ret = getopt(argc,argv, "i:hc:b:p:esqo:" +#ifdef MRT_TABLE + "t:" +#endif + ); if (ret==-1) break; @@ -182,12 +240,26 @@ case 'p': portnum = atoi(optarg); break; +#ifdef MRT_TABLE + case 't': + table = atoi(optarg); + break; +#endif case 'h': usage(); return(0); case 'e': channel_use_eit = 1; break; + case 's': + channel_use_sdt = 1; + break; + case 'q': + quiet = 1; + break; + case 'o': + dirname = optarg; + break; } } @@ -219,7 +291,7 @@ printf("Starting netcv2dvbip. Streams will be sent to port: %d\n", portnum); - if (!read_channel_list(channels)) + if (!read_channel_list(channels, dirname)) exit(-1); mcli_startup(); @@ -247,6 +319,7 @@ streamer.SetBindIf(iflist[ifindex]); streamer.SetStreamPort(portnum); + streamer.SetTable(table); streamer.SetNumGroups(get_channel_num()); streamer.Run();
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/mclilink.c
Changed
@@ -1,6 +1,12 @@ #include "dvbipstream.h" -#define BUFFER_SIZE (10000*188) +#define BUFFER_SIZE (256*TS_PER_UDP*188) + +#ifdef WIN32 +#define CVT (char *) +#else +#define CVT +#endif int gen_pat(unsigned char *buf, unsigned int program_number, unsigned int pmt_pid, unsigned int ts_cnt) { @@ -51,19 +57,14 @@ return i; } -int lastwp = 0; /*-------------------------------------------------------------------------*/ int mcli_handle_ts (unsigned char *buffer, size_t len, void *p) { stream_info_t *si = (stream_info_t *) p; - if(si->stop) { + if(si->stop) return len; - } - pthread_mutex_lock(&si->lock_wr); - - int wp = si->wp; int olen = len; int ret; @@ -79,6 +80,7 @@ goto again; case 1: + ret = 0; for(i=0; i<len; i+=188) { ret = ts2psi_data (buffer+i, &si->psi, 188, 0); if(ret){ @@ -90,7 +92,8 @@ } if (ret == 1) { - printf ("Channel: %s - Got PAT\n", si->cdata->name); + if (!quiet) + printf ("Channel: %s - Got PAT\n", si->cdata->name); pmt_pid_list_t pat; ret = parse_pat_sect (si->psi.buf, si->psi.len, &pat); if (ret < 0) { @@ -101,7 +104,8 @@ for (n = 0; n < pat.pmt_pids; n++) { if (pat.pl[n].program_number == (unsigned int)si->cdata->sid) { si->pmt_pid = pat.pl[n].network_pmt_pid; - printf ("Channel: %s - SID %d has PMT Pid %d\n", si->cdata->name, si->cdata->sid, si->pmt_pid); + if (!quiet) + printf ("Channel: %s - SID %d has PMT Pid %d\n", si->cdata->name, si->cdata->sid, si->pmt_pid); break; } } @@ -113,6 +117,7 @@ } break; case 4: + ret = 0; for(i=0; i<len; i+=188) { ret = ts2psi_data (buffer+i, &si->psi, 188, si->pmt_pid); if(ret){ @@ -124,7 +129,8 @@ } if (ret == 1) { - printf ("Channel: %s - Got PMT\n", si->cdata->name); + if (!quiet) + printf ("Channel: %s - Got PMT\n", si->cdata->name); pmt_t hdr; si_ca_pmt_t pm, es; int es_pid_num; @@ -159,27 +165,94 @@ } } */ - if ((wp + len) >= BUFFER_SIZE) { - int l; - l = BUFFER_SIZE - wp; - memcpy (si->buffer + wp, buffer, l); - len -= l; - wp = 0; - buffer += l; + pthread_mutex_lock(&si->lock_ts); + + switch(len) { + case 1*188: + case 2*188: + case 3*188: + case 4*188: + case 5*188: + case 6*188: + case 7*188: + break; + default: + err(CVT "Channel: %s - bad data length %d, skipping\n", + si->cdata->name,(int)len); + goto out; } - memcpy (si->buffer + wp, buffer, len); - wp += len; - si->wp = wp % (BUFFER_SIZE); -#if 1 - if (abs (si->wp - lastwp) > 500 * 1000) { -// printf ("wp %i, rp %i\n", si->wp, si->rp); - lastwp = si->wp; + + if(!si->wr) { + pthread_mutex_lock(&si->lock_bf); + if(si->free) { + si->wr=si->free; + si->free=si->free->next; + pthread_mutex_unlock(&si->lock_bf); + } else { + pthread_mutex_unlock(&si->lock_bf); + si->wr=(stream_buffer_t *) + malloc(sizeof(stream_buffer_t)); + if(!si->wr) { + err(CVT "Channel: %s - out of memory\n", + si->cdata->name); + goto out; + } + } + si->wr->next=NULL; + si->fill=0; } -#endif + + i=TS_PER_UDP*188-si->fill; + + if(len>i) { + memcpy(si->wr->data+si->fill,buffer,i); + + pthread_mutex_lock(&si->lock_bf); + if(!si->head) + si->head=si->tail=si->wr; + else { + si->tail->next=si->wr; + si->tail=si->wr; + } + if(si->free) { + si->wr=si->free; + si->free=si->free->next; + pthread_mutex_unlock(&si->lock_bf); + } else { + pthread_mutex_unlock(&si->lock_bf); + si->wr=(stream_buffer_t *) + malloc(sizeof(stream_buffer_t)); + if(!si->wr) { + err(CVT "Channel: %s - out of memory\n", + si->cdata->name); + goto out; + } + } + si->wr->next=NULL; + si->fill=0; + buffer+=i; + len-=i; + } + + memcpy(si->wr->data+si->fill,buffer,len); + si->fill+=len; + + if(si->fill==TS_PER_UDP*188) { + pthread_mutex_lock(&si->lock_bf); + if(!si->head) + si->head=si->tail=si->wr; + else { + si->tail->next=si->wr; + si->tail=si->wr; + } + pthread_mutex_unlock(&si->lock_bf); + si->wr=NULL; + } + +out: pthread_mutex_unlock(&si->lock_ts); break; } - pthread_mutex_unlock(&si->lock_wr); return olen; } @@ -203,23 +276,28 @@ { unsigned char ts[188]; stream_info_t *si = (stream_info_t *) p; - printf("Channel: %s - stream watch thread started.\n", si->cdata->name); - while (!si->stop) { + if (!quiet) + printf("Channel: %s - stream watch thread started.\n", si->cdata->name); + while (1 ) { + if(si->stop) + break; if (si->pmt_pid && si->si_state == 2) { dvb_pid_t pids[3]; memset (&pids, 0, sizeof (pids)); pids[0].pid = si->pmt_pid; pids[1].pid = -1; - printf ("Channel: %s - Add PMT-PID: %d\n", si->cdata->name, si->pmt_pid); + if (!quiet) + printf ("Channel: %s - Add PMT-PID: %d\n", si->cdata->name, si->pmt_pid); recv_pids (si->r, pids); si->si_state++; } if (si->es_pidnum && si->si_state == 5) { int i,k=0; - size_t sz = sizeof(dvb_pid_t) * (si->es_pidnum+2 + si->cdata->NumEitpids); + size_t sz = sizeof(dvb_pid_t) * (si->es_pidnum+2 + si->cdata->NumEitpids + si->cdata->NumSdtpids); dvb_pid_t *pids=(dvb_pid_t*)malloc(sz); if(pids==NULL) { - err("Channel: %s - Can't get memory for pids\n", si->cdata->name); + err(CVT "Channel: %s - Can't get memory for pids\n", si->cdata->name); + goto out; } memset (pids, 0, sz); pids[k++].pid = si->pmt_pid; @@ -227,14 +305,24 @@ for (i = 0; i < si->cdata->NumEitpids; i++) { pids[k++].pid = si->cdata->eitpids[i]; - printf("Channel: %s - Add EIT-PID: %d\n", si->cdata->name, si->cdata->eitpids[i]); + if (!quiet) + printf("Channel: %s - Add EIT-PID: %d\n", si->cdata->name, si->cdata->eitpids[i]); + } + //SDT PIDs + for (i = 0; i < si->cdata->NumSdtpids; i++) + { + pids[k++].pid = si->cdata->sdtpids[i]; + if (!quiet) + printf("Channel: %s - Add SDT-PID: %d\n", si->cdata->name, si->cdata->sdtpids[i]); } for (i = 0; i < si->es_pidnum; i++) { - printf ("Channel: %s - Add ES-PID: %d\n", si->cdata->name, si->es_pids[i]); + if (!quiet) + printf ("Channel: %s - Add ES-PID: %d\n", si->cdata->name, si->es_pids[i]); pids[i + k].pid = si->es_pids[i]; // if(si->cdata->NumCaids) { if(!si->fta) { - printf("Channel: %s - %s\n", si->cdata->name, si->fta ? "Free-To-Air":"Crypted"); + if (!quiet) + printf("Channel: %s - %s\n", si->cdata->name, si->fta ? "Free-To-Air":"Crypted"); pids[i + k].id = si->cdata->sid; } pids[i + k +1].pid = -1; @@ -247,9 +335,10 @@ gen_pat(ts, si->cdata->sid, si->pmt_pid, si->ts_cnt++); mcli_handle_ts (ts, 188, si); } - usleep (50000); +out: usleep (50000); } - printf("Channel: %s - stream watch thread stopped.\n", si->cdata->name); + if (!quiet) + printf("Channel: %s - stream watch thread stopped.\n", si->cdata->name); return NULL; } @@ -262,31 +351,42 @@ struct dvb_frontend_parameters fep; recv_sec_t sec; dvb_pid_t pids[4]; - int source; - fe_type_t tuner_type; + int source = -1; + fe_type_t tuner_type = FE_ATSC; cnum = channum-1; - printf ("mcli_stream_setup %i\n", cnum); +// printf ("mcli_stream_setup %i\n", cnum); if (cnum < 0 || cnum > get_channel_num ()) return 0; si = (stream_info_t *) malloc (sizeof (stream_info_t)); + if (!si) { + fprintf (stderr, "Cannot get memory for receiver\n"); + return NULL; + } memset(si, 0, sizeof(stream_info_t)); - si->buffer = (char *) malloc (BUFFER_SIZE); si->psi.buf = (unsigned char *) malloc (PSI_BUF_SIZE); - pthread_mutex_init (&si->lock_wr, NULL); - pthread_mutex_init (&si->lock_rd, NULL); + if (!si->psi.buf) { + fprintf (stderr, "Cannot get memory for receiver\n"); + free (si); + return NULL; + } r = recv_add (); if (!r) { fprintf (stderr, "Cannot get memory for receiver\n"); - return 0; + free (si->psi.buf); + free (si); + return NULL; } - si->r = r; - register_ten_handler (r, mcli_handle_ten, si); + pthread_mutex_init (&si->lock_bf, NULL); + pthread_mutex_init (&si->lock_ts, NULL); + + if (!quiet) + register_ten_handler (r, mcli_handle_ten, si); register_ts_handler (r, mcli_handle_ts, si); si->cdata = get_channel_data (cnum); @@ -341,7 +441,8 @@ pids[0].pid = 0; // PAT pids[1].pid = -1; - printf ("Tuning: source: %s, frequency: %i, PAT pid %i, symbol rate %i\n", + if (!quiet) + printf ("Tuning: source: %s, frequency: %i, PAT pid %i, symbol rate %i\n", source>=0 ? "DVB-S(2)" : source==-2 ? "DVB-T" : source==-3 ? "DVB-C" : "unknown" , si->cdata->frequency, pids[0].pid, fep.u.qpsk.symbol_rate); @@ -352,66 +453,80 @@ #else pthread_create (&si->t, NULL, stream_watch, si); #endif - printf("mcli_setup %p\n",si); +// printf("mcli_setup %p\n",si); return si; } /*-------------------------------------------------------------------------*/ -size_t mcli_stream_read (void *handle, char *buf, size_t maxlen, off_t offset) +size_t mcli_stream_access (void *handle, char **buf) { stream_info_t *si = (stream_info_t *) handle; - size_t len, rlen; - int wp; -// printf("mcli_read %p\n",handle); - if (!handle || si->stop) + if (!handle) + return 0; + if (si->stop) + return 0; + + pthread_mutex_lock(&si->lock_bf); + if(!si->head) { + pthread_mutex_unlock(&si->lock_bf); return 0; -#if 0 - if (offset < si->offset) { - // Windback - si->rp = (si->rp - (si->offset - offset)) % BUFFER_SIZE; - si->offset = offset; } -/* else if (offset>si->offset && ) { - si->rp=(si->rp+(offset-si->offset))%BUFFER_SIZE; - si->offset=offset; - }*/ -#endif - wp = si->wp; + si->rd=si->head; + si->head=si->head->next; + pthread_mutex_unlock(&si->lock_bf); - if (si->rp == wp) { + *buf=si->rd->data; + return TS_PER_UDP*188; +} + +/*-------------------------------------------------------------------------*/ +size_t mcli_stream_part_access (void *handle, char **buf) +{ + stream_info_t *si = (stream_info_t *) handle; + + if (!handle) return 0; - } - - if (si->rp < wp) { - len = wp - si->rp; - if (maxlen < len) - rlen = maxlen; - else - rlen = len; - - memcpy (buf, si->buffer + si->rp, rlen); - si->rp += rlen; - } else { - len = BUFFER_SIZE - (si->rp - wp); - if (maxlen < len) - rlen = maxlen; - else - rlen = len; - - if (si->rp + rlen > BUFFER_SIZE) { - int xlen = BUFFER_SIZE - si->rp; - memcpy (buf, si->buffer + si->rp, xlen); - memcpy (buf + xlen, si->buffer, rlen - xlen); - } else - memcpy (buf, si->buffer + si->rp, rlen); - si->rp += rlen; + if (si->stop) + return 0; + + pthread_mutex_lock(&si->lock_ts); + if(!si->head) { + int len; + + if(!si->wr) + len=0; + else { + si->rd=si->wr; + si->wr=NULL; + len=si->fill; + *buf=si->rd->data; + } + pthread_mutex_unlock(&si->lock_ts); + return len; } + si->rd=si->head; + si->head=si->head->next; + pthread_mutex_unlock(&si->lock_ts); - si->rp %= (BUFFER_SIZE); - si->offset += rlen; -// printf("rlen %i, rp %i wp %i\n",rlen,si->rp, si->wp); - return rlen; + *buf=si->rd->data; + return TS_PER_UDP*188; +} + +/*-------------------------------------------------------------------------*/ +void mcli_stream_skip (void *handle) +{ + stream_info_t *si = (stream_info_t *) handle; + + if (!handle) + return; + + pthread_mutex_lock(&si->lock_bf); + si->rd->next=si->free; + si->free=si->rd; + pthread_mutex_unlock(&si->lock_bf); + + si->rd=NULL; } /*-------------------------------------------------------------------------*/ @@ -420,28 +535,43 @@ if (handle) { stream_info_t *si = (stream_info_t *) handle; recv_info_t *r = si->r; - pthread_mutex_lock(&si->lock_rd); if (pthread_exist(si->t)) { si->stop = 1; pthread_join (si->t, NULL); } - pthread_mutex_unlock(&si->lock_rd); - pthread_mutex_lock(&si->lock_wr); if (r) { + pthread_mutex_lock(&si->lock_ts); register_ten_handler (r, NULL, NULL); register_ts_handler (r, NULL, NULL); + pthread_mutex_unlock(&si->lock_ts); recv_stop(r); sleep(2); recv_del (r); } - pthread_mutex_unlock(&si->lock_wr); - if (si->buffer) - free (si->buffer); if (si->psi.buf) { free (si->psi.buf); } - + + if (si->rd) + free (si->rd); + if (si->wr) + free (si->wr); + while (si->head) { + stream_buffer_t *e; + e = si->head; + si->head = si->head->next; + free (e); + } + while (si->free) { + stream_buffer_t *e; + e = si->free; + si->free = si->free->next; + free (e); + } + + pthread_mutex_destroy(&si->lock_ts); + pthread_mutex_destroy(&si->lock_bf); free (si); } return 0; @@ -475,7 +605,8 @@ for (n = 0; n < nc_list->nci_num; n++) { netceiver_info_t *nci = nc_list->nci + n; printf ("\nFound NetCeiver: %s\n", nci->uuid); - for (i = 0; i < nci->tuner_num; i++) { + if (!quiet) + for (i = 0; i < nci->tuner_num; i++) { printf (" Tuner: %s, Type %d\n", nci->tuner[i].fe_info.name, nci->tuner[i].fe_info.type); } }
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/mingw
Added
+(directory)
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/mingw/Makefile
Added
@@ -0,0 +1,19 @@ +OBJS=main.o parse.o mclilink.o siparser.o crc32.o clist.o stream.o thread.o misc.o streamer.o igmp.o iface.o +EXE=netcv2dvbip.exe +CC:=gcc +CXX=g++ +CFLAGS:= -O2 -DCLIENT -DSTATICLIB -Wall -I../../common/win32/include -I../../common -I../../client +LDFLAGS:= -s -L../../common/win32/lib +LDLIBS:= -lmingwex -lmcli -liphlpapi -lpthreadGC2 -lws2_32 -lxml2 -lz + +all: $(EXE) + +$(EXE): $(OBJS) + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) + +%.o: ../%.c + $(CXX) -c $(CFLAGS) -o $@ $< + +clean: + @-del $(EXE) *.o *.la *~ +
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/mingw/build.cmd
Added
@@ -0,0 +1,2 @@ +@set PATH=c:\MinGw\bin;%PATH% +@mingw32-make
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/mingw/clean.cmd
Added
@@ -0,0 +1,2 @@ +@set PATH=c:\MinGw\bin;%PATH% +@mingw32-make clean
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/misc.c
Changed
@@ -89,6 +89,13 @@ } #ifdef WIN32 + +#ifdef __MINGW32__ +#define __try if(1) +#define __leave goto out +#define __finally if(1) +#endif + bool IsUserAdmin( bool* pbAdmin ) { #if WINVER < 0x0500 @@ -98,7 +105,7 @@ PTOKEN_GROUPS ptgGroups = NULL; #endif PSID psidAdministrators = NULL; - SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY; + SID_IDENTIFIER_AUTHORITY siaNtAuthority = {SECURITY_NT_AUTHORITY}; BOOL bResult = FALSE; __try @@ -150,6 +157,9 @@ __finally { +#ifdef __MINGW32__ +out: +#endif #if WINVER < 0x0500 if( hAccessToken ) CloseHandle( hAccessToken );
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/misc.h
Changed
@@ -39,6 +39,10 @@ extern bool GetAbsTime(struct timespec *Abstime, int MillisecondsFromNow); #ifdef WIN32 +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of DST correction */ +}; extern int gettimeofday(struct timeval * tp, struct timezone * tzp); bool IsUserAdmin( bool* pbAdmin ); bool IsVistaOrHigher(); @@ -58,5 +62,6 @@ uint64_t Elapsed(void); }; +extern int quiet; #endif
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/parse.c
Changed
@@ -114,6 +114,43 @@ {-1} }; +#ifdef WIN32 +#define strtok_r mystrtok +char *strtok_r(char *s, const char *d, char **m) +{ + char *p; + char *q; + + if (s) + *m = s; + + p = *m; + if (!p) + return NULL; + + while (*p && strchr(d,*p)) + p++; + + if (*p == 0) { + *m = NULL; + return NULL; + } + + q = p; + while (*q && !strchr(d,*q)) + q++; + + if (!*q) + *m = NULL; + else { + *q++ = 0; + *m = q; + } + + return p; +} +#endif + char *strreplace (char *s, char c1, char c2) { if (s) { @@ -239,7 +276,7 @@ s = ParseParameter (s, &ch->hierarchy, HierarchyValues); break; default: - printf ("ERROR: unknown parameter key '%c' at pos %d\n", *s, s-start); + printf ("ERROR: unknown parameter key '%c' at pos %d\n", *s, (int)((long)(s-start))); return 0; } } @@ -356,7 +393,6 @@ while ((q = strtok_r (p, ",", &strtok_next)) != NULL) { if (ch->NumApids < MAXAPIDS) { - char *l = strchr (q, '='); ch->apids[ch->NumApids++] = strtol (q, NULL, 10); } else printf ("ERROR: too many APIDs!\n"); // no need to set ok to 'false' @@ -370,7 +406,6 @@ char *strtok_next; while ((q = strtok_r (p, ",", &strtok_next)) != NULL) { if (NumDpids < MAXDPIDS) { - char *l = strchr (q, '='); ch->dpids[ch->NumDpids++] = strtol (q, NULL, 10); } else printf ("ERROR: too many DPIDs!\n"); // no need to set ok to 'false' @@ -403,23 +438,37 @@ if (p) { *p++ = 0; ch->provider = strdup (p); + if (!ch->provider) { + printf ("ERROR: out of memory!\n"); + ok = 0; + } } p = strchr (namebuf, ','); if (p) { *p++ = 0; ch->shortName = strdup (p); + if (!ch->shortName) { + printf ("ERROR: out of memory!\n"); + ok = 0; + } } } ch->name = strdup (namebuf); + if (!ch->name) { + printf ("ERROR: out of memory!\n"); + ok = 0; + } - free (parambuf); - free (sourcebuf); - free (vpidbuf); - free (apidbuf); - free (caidbuf); - free (namebuf); } else - return 0; + ok = 0; +#if (defined WIN32 || defined APPLE) + free (parambuf); + free (sourcebuf); + free (vpidbuf); + free (apidbuf); + free (caidbuf); + free (namebuf); +#endif } return ok; }
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/siparser.c
Changed
@@ -1,1027 +0,0 @@ -#include "headers.h" - -//#define DBG 1 -#define CRC32_CHECK 1 - -enum ca_desc_type { EMM, ECM }; - -//----------------------------------------------------------------------------------- -void printhex_buf(char *msg,unsigned char *buf,int len) -{ - int i,j,k; - int width=8; - - i=k=0; - sys ("%s: %d bytes (0x%04x)\n",msg,len,len); - sys ("---------------------------------------------------------------\n"); - while(len) { - sys ("%04x ",k++*width*2); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - sys ("%02x ",buf[i]); - } - if (i >= len) { - sys ("\n"); - break; - } - sys(" "); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - sys("%02x ",buf[i]); - } - sys("\n"); - if (i >= len) break; - } - sys("---------------------------------------------------------------\n"); -} -//----------------------------------------------------------------------------------- -void writehex_buf(FILE *f, char *msg,unsigned char *buf,int len) -{ - int i,j,k; - int width=8; - - i=k=0; - fprintf(f,"%s: %d bytes (0x%04x)\n",msg,len,len); - fprintf(f,"---------------------------------------------------------------\n"); - while(len) { - fprintf(f,"%04x ",k++*width*2); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - fprintf(f,"%02x ",buf[i]); - } - if (i >= len) { - fprintf(f,"\n"); - break; - } - fprintf(f," "); - j=i; - for(;i < j + width ; i++){ - if (i >= len) break; - fprintf(f,"%02x ",buf[i]); - } - fprintf(f,"\n"); - if (i >= len) break; - } - fprintf(f,"---------------------------------------------------------------\n"); - - -} -//----------------------------------------------------------------------------------- -void print_ts_header(ts_packet_hdr_t *p) -{ - info("--------------------------------------------------------------\n"); - info("TS header data:\n"); - info("Sync-byte : 0x%04x\n",p->sync_byte); - info("Transport error indicator : 0x%04x\n",p->transport_error_indicator); - info("Payload unit start indicator : 0x%04x\n",p->payload_unit_start_indicator); - info("Transport priority : 0x%04x\n",p->transport_priority); - info("PID : 0x%04x\n",p->pid); - info("Transport scrambling control : 0x%04x\n",p->transport_scrambling_control); - info("Adaptation field control : 0x%04x\n",p->adaptation_field_control); - info("Continuity_counter : 0x%04x\n",p->continuity_counter); - -} -//----------------------------------------------------------------------------------- -void print_pmt(pmt_t *p) -{ - info("--------------------------------------------------------------\n"); - info("PMT section:\n"); - info("Table ID : %-5d (0x%04x)\n",p->table_id,p->table_id); - info("(fixed): : %-5d (0x%04x)\n",0,0); - info("Section syntax indicator : %-5d (0x%04x)\n",p->section_syntax_indicator,p->section_syntax_indicator); - info("Reserved 1 : %-5d (0x%04x)\n",p->reserved_1,p->reserved_1); - info("Section length : %-5d (0x%04x)\n",p->section_length,p->section_length); - info("Program number : %-5d (0x%04x)\n",p->program_number,p->program_number); - info("Reserved 2 : %-5d (0x%04x)\n",p->reserved_2,p->reserved_2); - info("Version number : %-5d (0x%04x)\n",p->version_number,p->version_number); - info("Current next indicator : %-5d (0x%04x)\n",p->current_next_indicator,p->current_next_indicator); - info("Section number : %-5d (0x%04x)\n",p->section_number,p->section_number); - info("Last section number : %-5d (0x%04x)\n",p->last_section_number,p->last_section_number); - info("Reserved 3 : %-5d (0x%04x)\n",p->reserved_3,p->reserved_3); - info("PCR pid : %-5d (0x%04x)\n",p->pcr_pid,p->pcr_pid); - info("Reserved 4 : %-5d (0x%04x)\n",p->reserved_4,p->reserved_4); - info("Program info length : %-5d (0x%04x)\n",p->program_info_length,p->program_info_length); - - - - info("CRC32 : 0x%04x\n",p->crc32); -} -//----------------------------------------------------------------------------------- -void print_pat(pat_t *p, pat_list_t *pl, int pmt_num) -{ - info("--------------------------------------------------------------\n"); - info("PAT section:\n"); - info("Table_id : %-5d (0x%04x)\n",p->table_id,p->table_id); - info("(fixed): : %-5d (0x%04x)\n",0,0); - info("Section syntax indicator : %-5d (0x%04x)\n",p->section_syntax_indicator,p->section_syntax_indicator); - info("Reserved_1 : %-5d (0x%04x)\n",p->reserved_1,p->reserved_1); - info("Section length : %-5d (0x%04x)\n",p->section_length,p->section_length); - info("Transport stream id : %-5d (0x%04x)\n",p->transport_stream_id,p->transport_stream_id); - info("Reserved 2 : %-5d (0x%04x)\n",p->reserved_2,p->reserved_2); - info("Version number : %-5d (0x%04x)\n",p->version_number,p->version_number); - info("Current next indicator : %-5d (0x%04x)\n",p->current_next_indicator,p->current_next_indicator); - info("Section number : %-5d (0x%04x)\n",p->section_number,p->section_number); - info("Last section number : %-5d (0x%04x)\n",p->last_section_number,p->last_section_number); - - if (pl && pmt_num){ - int i; - info("Number of PMTs in PAT : %-5d \n", pmt_num); - for(i=0;i<pmt_num;i++) { - pat_list_t *pat = pl + i; - info("\nProgram number : %-5d (0x%04x)\n",pat->program_number,pat->program_number); - info("Reserved : %-5d (0x%04x)\n",pat->reserved,pat->reserved); - info("Network PMT PID : %-5d (0x%04x)\n",pat->network_pmt_pid,pat->network_pmt_pid); - } - } - - info("CRC32 : 0x%04x\n",p->crc32); - - -} -//----------------------------------------------------------------------------------- -char *si_caid_to_name(unsigned int caid) -{ - - str_table table[] = { - // -- updated from dvb.org 2003-10-16 - { 0x0000, 0x0000, "Reserved" }, - { 0x0001, 0x00FF, "Standardized Systems" }, - { 0x0100, 0x01FF, "Canal Plus (Seca/MediaGuard)" }, - { 0x0200, 0x02FF, "CCETT" }, - { 0x0300, 0x03FF, "MSG MediaServices GmbH" }, - { 0x0400, 0x04FF, "Eurodec" }, - { 0x0500, 0x05FF, "France Telecom (Viaccess)" }, - { 0x0600, 0x06FF, "Irdeto" }, - { 0x0700, 0x07FF, "Jerrold/GI/Motorola" }, - { 0x0800, 0x08FF, "Matra Communication" }, - { 0x0900, 0x09FF, "News Datacom (Videoguard)" }, - { 0x0A00, 0x0AFF, "Nokia" }, - { 0x0B00, 0x0BFF, "Norwegian Telekom (Conax)" }, - { 0x0C00, 0x0CFF, "NTL" }, - { 0x0D00, 0x0DFF, "Philips (Cryptoworks)" }, - { 0x0E00, 0x0EFF, "Scientific Atlanta (Power VU)" }, - { 0x0F00, 0x0FFF, "Sony" }, - { 0x1000, 0x10FF, "Tandberg Television" }, - { 0x1100, 0x11FF, "Thompson" }, - { 0x1200, 0x12FF, "TV/COM" }, - { 0x1300, 0x13FF, "HPT - Croatian Post and Telecommunications" }, - { 0x1400, 0x14FF, "HRT - Croatian Radio and Television" }, - { 0x1500, 0x15FF, "IBM" }, - { 0x1600, 0x16FF, "Nera" }, - { 0x1700, 0x17FF, "Beta Technik (Betacrypt)" }, - { 0x1800, 0x18FF, "Kudelski SA"}, - { 0x1900, 0x19FF, "Titan Information Systems"}, - { 0x2000, 0x20FF, "TelefXnica Servicios Audiovisuales"}, - { 0x2100, 0x21FF, "STENTOR (France Telecom, CNES and DGA)"}, - { 0x2200, 0x22FF, "Scopus Network Technologies"}, - { 0x2300, 0x23FF, "BARCO AS"}, - { 0x2400, 0x24FF, "StarGuide Digital Networks "}, - { 0x2500, 0x25FF, "Mentor Data System, Inc."}, - { 0x2600, 0x26FF, "European Broadcasting Union"}, - { 0x4700, 0x47FF, "General Instrument"}, - { 0x4800, 0x48FF, "Telemann"}, - { 0x4900, 0x49FF, "Digital TV Industry Alliance of China"}, - { 0x4A00, 0x4A0F, "Tsinghua TongFang"}, - { 0x4A10, 0x4A1F, "Easycas"}, - { 0x4A20, 0x4A2F, "AlphaCrypt"}, - { 0x4A30, 0x4A3F, "DVN Holdings"}, - { 0x4A40, 0x4A4F, "Shanghai Advanced Digital Technology Co. Ltd. (ADT)"}, - { 0x4A50, 0x4A5F, "Shenzhen Kingsky Company (China) Ltd"}, - { 0x4A60, 0x4A6F, "@SKY"}, - { 0x4A70, 0x4A7F, "DreamCrypt"}, - { 0x4A80, 0x4A8F, "THALESCrypt"}, - { 0x4A90, 0x4A9F, "Runcom Technologies"}, - { 0x4AA0, 0x4AAF, "SIDSA"}, - { 0x4AB0, 0x4ABF, "Beijing Comunicate Technology Inc."}, - { 0x4AC0, 0x4ACF, "Latens Systems Ltd"}, - { 0,0, NULL } - }; - - int i = 0; - while (table[i].str) { - if (table[i].from <= caid && table[i].to >= caid) - return (char *) table[i].str; - i++; - } - - return (char *) "ERROR: Undefined!"; -} -//----------------------------------------------------------------------------------- -void get_time_mjd (unsigned long mjd, long *year , long *month, long *day) -{ - if (mjd > 0) { - long y,m,d ,k; - - // algo: ETSI EN 300 468 - ANNEX C - - y = (long) ((mjd - 15078.2) / 365.25); - m = (long) ((mjd - 14956.1 - (long)(y * 365.25) ) / 30.6001); - d = (long) (mjd - 14956 - (long)(y * 365.25) - (long)(m * 30.6001)); - k = (m == 14 || m == 15) ? 1 : 0; - y = y + k + 1900; - m = m - 1 - k*12; - *year = y; - *month = m; - *day = d; - - } - -} -//----------------------------------------------------------------------------------- -void print_tdt(tdt_sect_t *tdt, uint16_t mjd, uint32_t utc) -{ - info("--------------------------------------------------------------\n"); - info("TDT section:\n"); - info("Table_id : %-5d (0x%04x)\n",tdt->table_id,tdt->table_id); - info("Reserved : %-5d (0x%04x)\n",tdt->reserved,tdt->reserved); - info("Reserved_1 : %-5d (0x%04x)\n",tdt->reserved_1,tdt->reserved_1); - info("Section length : %-5d (0x%04x)\n",tdt->section_length,tdt->section_length); - info("UTC_time : 0x%2x%2x%2x%2x%2x\n",tdt->dvbdate[0],tdt->dvbdate[1],tdt->dvbdate[2],tdt->dvbdate[3],tdt->dvbdate[4]); - - long y,m,d; - get_time_mjd(mjd, &y, &m, &d); - info("TIME: [= %02d-%02d-%02d %02lx:%02lx:%02lx (UTC) ]\n\n",y,m,d,(utc>>16) &0xFF, (utc>>8) &0xFF, (utc) &0xFF); - info("--------------------------------------------------------------\n"); - -} -//----------------------------------------------------------------------------------- -void print_ca_desc(si_desc_t *p) -{ - info("CA desc. tag : %d (%#x)\n",p->descriptor_tag,p->descriptor_tag); - info("CA desc. length : %d (%#x)\n",p->descriptor_length,p->descriptor_length); - info("CA system id : %d (%#x)\n",p->ca_system_id,p->ca_system_id); - info("Reserverd : %d (%#x)\n",p->reserved,p->reserved); - info("CA pid : %d (%#x)\n",p->ca_pid,p->ca_pid); - - printhex_buf("Private data",p->private_data,p->descriptor_length-4); - -} -//----------------------------------------------------------------------------------- -void print_ca_bytes(si_desc_t *p) -{ - unsigned int i; - info("%x %x %x %x %x ",p->descriptor_tag, p->descriptor_length, p->ca_system_id, p->reserved, p->ca_pid); - for (i = 0; i < p->descriptor_length - 4; i++) - info("%x ",p->private_data[i]); - info(";"); - -} -//----------------------------------------------------------------------------------- -void print_cad_lst(si_cad_t *l, int ts_id) -{ - int i; - - for (i = 0; i < l->cads; i++) { - print_ca_desc(&l->cad[i]); - } - info("Total CA desc. for TS ID %d : %d\n",ts_id,l->cads); -} -//----------------------------------------------------------------------------------- -int parse_ca_descriptor(unsigned char *desc, si_desc_t *t) -{ - unsigned char *ptr=desc; - int tag=0,len=0; - - tag=ptr[0]; - len=ptr[1]; - - if (len > MAX_DESC_LEN) { - info("descriptor():Descriptor too long !\n"); - return -1; - } - - switch(tag){ - case 0x09: { - t->descriptor_tag=tag; - t->descriptor_length=len; //??? - t->ca_system_id=((ptr[2] << 8) | ptr[3]); - t->reserved=(ptr[4] >> 5) & 7; - t->ca_pid=((ptr[4] << 8) | ptr[5]) & 0x1fff; - //header 4 bytes + 2 bytes - memcpy(t->private_data,ptr+6,len-4); - - //print_ca_desc(t); - - break; - } - default: - break; - } - - return len + 2; //2 bytes tag + length -} -//-------------------------------------------------------------------------------------------- -int ca_free_cpl_desc(ca_pmt_list_t *cpl) -{ - if (cpl->pm.size > 0 && cpl->pm.cad) - free(cpl->pm.cad); - if (cpl->es.size > 0 && cpl->es.cad) - free(cpl->es.cad); - - memset(cpl,0,sizeof(ca_pmt_list_t)); - - return 0; -} -//-------------------------------------------------------------------------------------------- -int descriptor(unsigned char *desc, si_cad_t *c) -{ - unsigned char *ptr=desc; - int tag=0,len=0; - - tag=ptr[0]; - len=ptr[1]; - - if (len > MAX_DESC_LEN) { - info("descriptor():Descriptor too long !\n"); - return -1; - } - - switch(tag){ - case 0x09: { - c->cads++; - c->cad = (si_desc_t*)realloc(c->cad,sizeof(si_desc_t)*c->cads); - if (!c->cad) { - c->cads--; - info("descriptor():realloc error\n"); - return -1; - } - si_desc_t *t = c->cad + c->cads - 1; - t->descriptor_tag=tag; - t->descriptor_length=len; //??? - t->ca_system_id=((ptr[2] << 8) | ptr[3]); - t->reserved=(ptr[4] >> 5) & 7; - t->ca_pid=((ptr[4] << 8) | ptr[5]) & 0x1fff; - //header 4 bytes + 2 bytes - if (len - 4 > 0) - memcpy(t->private_data,ptr+6,len-4); - - //print_ca_desc(t); - break; - } - default: { -#if 0 - other_desc_t d; - d.descriptor_tag=tag; - d.descriptor_length=len; - memcpy(d.data,ptr+2,len); - //print_desc(d); -#endif - } - } - - return len + 2; //2 bytes tag + length -} - -//----------------------------------------------------------------------------------- -int si_get_video_pid(unsigned char *esi_buf, int size, int *vpid) -{ - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - //ptr[0] //stream type - if (ptr[0] == 2 || ptr[0] == 0x1b) - { - *vpid = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - return 1; - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - *vpid = -1; - return 0; - -} -//----------------------------------------------------------------------------------- -int si_get_audio_pid(unsigned char *esi_buf, int size, int *apid) -{ - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - //ptr[0] //stream type - if (ptr[0] == 0x1 || ptr[0] == 0x3 || ptr[0] == 0x4) - { - *apid = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - return 1; - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - *apid = -1; - return 0; - -} -//----------------------------------------------------------------------------------- -int si_get_private_pids(unsigned char *esi_buf, int size, int *upids) -{ - - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - if (ptr[0] == 0x6) - { - upids[pid_num] = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - pid_num++; - if (pid_num >= MAX_ES_PIDS) { - info ("error: ES pids number out of bounds !\n"); - return -1; - } - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - return pid_num; - -} -//----------------------------------------------------------------------------------- -int get_pmt_es_pids(unsigned char *esi_buf, int size, int *es_pids, int all) -{ - int index, pid_num, es_len; - unsigned char *ptr = esi_buf; - - index = pid_num = 0; - while(index < size) { - //ptr[0] //stream type - //int pid = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - //printf("Stream type: %d (%#x) pid = %d (%#x)\n",ptr[0], ptr[0], pid, pid); - if (ptr[0] == 0x1 || ptr[0] == 0x2 || ptr[0] == 0x3 || ptr[0] == 0x4 || ptr[0] == 0x6 || ptr[0] == 0x1b || all) - { - es_pids[pid_num] = ((ptr[1] << 8) | ptr[2]) & 0x1fff; - pid_num++; - if (pid_num >= MAX_ES_PIDS) { - info ("error: ES pids number out of bounds !\n"); - return -1; - } - } - es_len = ((ptr[3] << 8) | ptr[4]) & 0x0fff; - index += 5 + es_len; - ptr += 5 + es_len; - } - - return pid_num; -} -//----------------------------------------------------------------------------------- -int parse_pmt_ca_desc(unsigned char *buf, int size, int sid, si_ca_pmt_t *pm_cads, si_ca_pmt_t *es_cads, pmt_t *pmt_hdr, int *fta, ca_es_pid_info_t *espids, int *es_pid_num) -{ - unsigned char *ptr=buf, tmp[PSI_BUF_SIZE]; //sections can be only 12 bit long - - memset(pm_cads,0,sizeof(si_ca_pmt_t)); - memset(es_cads,0,sizeof(si_ca_pmt_t)); - memset(pmt_hdr,0,sizeof(pmt_hdr)); - - pmt_hdr->table_id=ptr[0]; - pmt_hdr->section_syntax_indicator=(ptr[1] >> 7) & 1; - pmt_hdr->reserved_1=(ptr[1] >> 4) & 3; - pmt_hdr->section_length=((ptr[1] << 8) | ptr[2]) & 0xfff; - - if (pmt_hdr->section_length < 13 || pmt_hdr->section_length > 1021 || pmt_hdr->section_length > size) { - info("#####\nERROR: Invalid section length!\n"); - return -1; - } - - u_long crc = dvb_crc32 ((char *)buf,pmt_hdr->section_length+3); - -#ifdef DBG - info("CRCcc: 0x%lx\n",crc); - info("len = %d\n", pmt_hdr->section_length+3); -#endif - if (crc & 0xffffffff) { //FIXME: makr arch flags - info("#####\nPMT -> ERROR: parse_pmt_ca_desc() : CRC err. crc = 0x%lx\n", crc); - return -1; - } - - pmt_hdr->program_number=(ptr[3] << 8) | ptr[4]; - if (pmt_hdr->program_number != sid) { - info("#####\nERROR: Invalid SID in PMT !!!\n"); - return -1; - } - pmt_hdr->program_info_length=((ptr[10] << 8) | ptr[11]) & 0x0fff; - if (pmt_hdr->program_info_length < 0 || pmt_hdr->program_info_length > 1021 - 9 || pmt_hdr->program_info_length > size - 9) { - info("#####\nERROR: Invalid PI length in PMT!\n"); - return -1; - } - - pmt_hdr->reserved_2=(ptr[5] >> 6) & 3; - pmt_hdr->version_number=(ptr[5] >> 1) & 0x1f; - pmt_hdr->current_next_indicator=ptr[5] & 1; - pmt_hdr->section_number=ptr[6]; - pmt_hdr->last_section_number=ptr[7]; - pmt_hdr->reserved_3=(ptr[8] >> 5) & 7; - pmt_hdr->pcr_pid=((ptr[8] << 8) | ptr[9]) & 0x1fff; - pmt_hdr->reserved_4=(ptr[10] >> 4) & 0xf; - - //pmt_hdr->program_info_length=((ptr[10] << 8) | ptr[11]) & 0x0fff; - //print_pmt(pmt_hdr); - - int buf_len=0,len=0; - unsigned int i=0; - - buf_len = pmt_hdr->section_length - 9; - ptr += 12; // 12 byte header - - pm_cads->size = pm_cads->cads = 0; - for (i = 0; i < pmt_hdr->program_info_length;) { - int dtag = ptr[0]; - int dlen = ptr[1] + 2; - if (dlen > size || dlen > MAX_DESC_LEN) { - info("PMT: Invalide CA desc. length!\n"); - return -1; - } - if (dtag == 0x09) { //we have CA descriptor - memcpy(tmp + pm_cads->size, ptr, dlen); - pm_cads->size+=dlen; - pm_cads->cads++; - *fta=0; - } - i+=dlen; - if (i > pmt_hdr->program_info_length) { - info("PMT: Index out of bounds!\n"); - return -1; - } - - ptr+=dlen; //desc. length plus 2 bytes for tag and header; - if (ptr >= buf + size) { - info("PMT: Invalid Buffer offset !\n"); - return -1; - } - - buf_len-=dlen; - if (buf_len < 0) { - info("PMT: Index out of bounds!\n"); - return -1; - - } - } - - //parsing ok we can take this program level descriptors - if (pm_cads->size && pm_cads->cads) { - pm_cads->cad = (unsigned char*)malloc(sizeof(unsigned char)*pm_cads->size); - memcpy(pm_cads->cad, tmp, pm_cads->size); - } - -#ifdef DBG - info("%d bytes remaining (program info len = %d bytes)\n",buf_len,i); -#endif - - int err = 0; - es_pmt_info_t esi; - es_cads->size = es_cads->cads = 0; - *es_pid_num = 0; - while (buf_len > 4) { //end of section crc32 is 4 bytes - esi.stream_type=ptr[0]; - esi.reserved_1=(ptr[1] >> 5) & 7; - esi.elementary_pid=((ptr[1] << 8) | ptr[2]) & 0x1fff; - esi.reserved_2=(ptr[3] >> 4) & 0xf; - esi.es_info_length=((ptr[3] << 8) | ptr[4]) & 0x0fff; - - if (esi.es_info_length > buf_len) { - info("PMT: Invalid ES info length !\n"); - err = -1; - break; - } - - if (espids) { - switch(esi.stream_type) { - case VIDEO_11172_STREAM_TYPE: - case VIDEO_13818_STREAM_TYPE: - case VISUAL_MPEG4_STREAM_TYPE: - case VIDEO_H264_STREAM_TYPE: - case AUDIO_11172_STREAM_TYPE: - case AUDIO_13818_STREAM_TYPE: - espids[*es_pid_num].pid = esi.elementary_pid; - espids[*es_pid_num].type = esi.stream_type; - break; - default: - espids[*es_pid_num].pid = esi.elementary_pid; - espids[*es_pid_num].type = 0; - - } - } - memcpy(tmp + es_cads->size, ptr, 5); - tmp[es_cads->size+1] &= 0x1f; //remove reserved value ??? - tmp[es_cads->size+3] &= 0x0f; //remove reserved value ??? - - int es_info_len_pos = es_cads->size+3; //mark length position to set it later - int cur_len = 0; //current ES stream descriptor length - - es_cads->size += 5; - ptr += 5; - buf_len -= 5; - len=esi.es_info_length; - while(len > 0) { - int dtag = ptr[0]; - int dlen = ptr[1] + 2; //2 bytes for tag and len - - if (dlen > len || dlen > MAX_DESC_LEN) { - info("PMT: Invalide CA desc. length!\n"); - err = -1; - break; - } - - if (dtag == 0x09) { //we have CA descriptor - memcpy(tmp + es_cads->size, ptr, dlen); - es_cads->size += dlen; - es_cads->cads++; - cur_len += dlen; - *fta=0; - } - if (espids) { - if (espids[*es_pid_num].type == 0) { - switch(dtag) { - case TeletextDescriptorTag: - case SubtitlingDescriptorTag: - case AC3DescriptorTag: - case EnhancedAC3DescriptorTag: - case DTSDescriptorTag: - case AACDescriptorTag: - espids[*es_pid_num].type = dtag; - //go to next pid - } - } - } - - ptr += dlen; - if (ptr >= buf + size) { - info("PMT: Invalid Buffer offset !\n"); - err = -1; - break; - } - - len -= dlen; - buf_len -= dlen; - } - if (err == -1) { - break; - } - tmp[es_info_len_pos] = (cur_len >> 8) & 0xff; - tmp[es_info_len_pos+1] = cur_len & 0xff; - if (espids) { - if (espids[*es_pid_num].type) { - //go to next pid - (*es_pid_num)++; - if (*es_pid_num >= MAX_ES_PIDS) { - info ("ERROR: ES pids array index out bounds (pids %d sid %d)!\n", *es_pid_num, pmt_hdr->program_number); - break; - } - } - } - } - - //parsing ok we can take this ES level descriptors - if (((es_cads->cads && es_cads->size) || (pm_cads->cads && es_cads->size)) || *fta) { //take ES stream info if we have PM or ES desc. - es_cads->cad = (unsigned char*)malloc(sizeof(unsigned char)*es_cads->size); - memcpy(es_cads->cad, tmp, es_cads->size); - - } - -#ifdef DBG - info("%d bytes remaining\n",buf_len); -#endif - - pmt_hdr->crc32=(ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; - - if (len < 0 || err == -1) { - info("ERROR: parse_ca_desc() : section index out of bounds %d or (CRC err.) crc in sec. = 0x%x crc calc. = 0x%lx\n", buf_len,pmt_hdr->crc32, crc); -#ifdef DBG - print_pmt(&pmt_hdr); -#endif - //cleanup ... - if (pm_cads->size) - free(pm_cads->cad); - if (es_cads->size) - free(es_cads->cad); - *es_pid_num = 0; - memset(pm_cads,0,sizeof(si_ca_pmt_t)); - memset(es_cads,0,sizeof(si_ca_pmt_t)); - return -1; - } - -#ifdef DBG - info("#####################################\n"); - info("parse_ca_desc(): section parsed: OK !\n"); -#endif - return 0; -} -//----------------------------------------------------------------------------------- -int parse_cat_sect(unsigned char *buf, int size, si_cad_t *emm) -{ - unsigned char *ptr=buf; - int len,i,ret; - cat_t c; - - c.table_id = ptr[0]; - c.section_syntax_indicator = (ptr[1] >> 7) & 1; - c.reserved_1 = (ptr[1] >> 4) & 3; - c.section_length = ((ptr[1] << 8) | ptr[2]) & 0xfff; - - if (c.section_length < 9 || c.section_length > 1021 || c.section_length > size) { - info("CAT: Invalid section length!\n"); - return -1; - } - -#ifdef CRC32_CHECK - u_long crc = dvb_crc32 ((char *)buf,c.section_length+3); -#ifdef DBG - info("CRCcc: 0x%lx\n",crc); -#endif - if (crc & 0xffffffff) { - info("CAT:CRC32 error (0x%lx)!\n",crc); - return -1; - } -#endif - - c.reserved_2 = (ptr[3] << 10) | (ptr[4] << 2) | ((ptr[5] >> 6) & 3); - c.version_number = (ptr[5] >> 1) & 0x1f; - c.current_next_indicator = ptr[5] & 1; - c.section_number = ptr[6]; - c.last_section_number = ptr[7]; - - - //do desc. here - len = c.section_length - 5; - ptr+=8; //go after hdr. - - i = len; - while(i > 4) { //crc32 4 bytes - ret = descriptor(ptr, emm); - if (ret < 0) { - info ("cannot parse CA descriptor in CAT !\n"); - return -1; - } - i-=ret; - ptr+=ret; - if (ptr >= buf + size) { - info("CAT: Invalid Buffer offset !\n"); - break; - } - } - if (i != 4) { - info("CAT: index out of bounds !\n"); - return -1; - } -#ifdef DBG - info("%d bytes remaining (program info len = %d bytes)\n",len-i,len); -#endif - c.crc32 = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; - - - return 0; -} -//----------------------------------------------------------------------------------- -int parse_pat_sect(unsigned char *buf, int size, pmt_pid_list_t *pmt) -{ - unsigned char *ptr=buf; - pat_t p; - pat_list_t *pat_info = NULL; - - memset(&p,0,sizeof(p)); - - p.table_id=ptr[0]; - p.section_syntax_indicator=(ptr[1] & 0x80) >> 7; - p.reserved_1=(ptr[1] & 0x30) >> 4; - p.section_length=((ptr[1] << 8) | ptr[2]) & 0x0fff; - - if (p.section_length < 9 || p.section_length > 1021 || p.section_length > size) { - info("PAT: Invalid section length !\n"); - return -1; - - } - -#ifdef CRC32_CHECK - u_long crc = dvb_crc32 ((char *)buf,p.section_length+3); - //FIXME: is it the right way ? - if (crc & 0xffffffff) { - info("PAT:CRC32 error (0x%lx)!\n",crc); - return -1; - } -#endif - - p.transport_stream_id=(ptr[3] << 8) | ptr[4]; - p.reserved_2=(ptr[5] & 0xc0) >> 6; - p.version_number=(ptr[5] & 0x3e) >> 1; - p.current_next_indicator=(ptr[5] & 1); - p.section_number=ptr[6]; - p.last_section_number=ptr[7]; - - int n,i,pmt_num; - - n = p.section_length - 5 - 4; //bytes following section_length field + crc32 chk_sum - - ptr+=8; - pmt_num=0; - if (n > 0 && ((ptr + n) < (buf + size))) { - pat_info=(pat_list_t *)malloc(sizeof(pat_list_t)*n/4); - for(i=0;i<n;i+=4) { - pat_list_t *pat = pat_info + pmt_num; - pat->program_number=(ptr[0] << 8) | (ptr[1]); - pat->reserved=(ptr[2] & 0xe0) >> 5; - pat->network_pmt_pid=((ptr[2] << 8) | ptr[3]) & 0x1fff; - if (pat->network_pmt_pid != 0x10) { //NIT => FIXME: remove other known pids - // memset(&pat->desc,0,sizeof(pmt_desc_list_t)); - pmt_num++; - } - ptr+=4; - } - - p.crc32=(ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; - if (n != pmt_num) - pat_info=(pat_list_t *)realloc(pat_info,sizeof(pat_list_t)*pmt_num); - } - if (pmt) { - pmt->p=p; - pmt->pl=pat_info; - pmt->pmt_pids=pmt_num; - } - - return 0; -} -int parse_tdt_sect(unsigned char *buf, int size, tdt_sect_t *tdt) -{ - unsigned char *ptr = buf; - - tdt->table_id=ptr[0]; - tdt->section_syntax_indicator=(ptr[1] & 0x80) >> 7; - tdt->reserved_1=(ptr[1] >> 4) >> 3; - tdt->section_length=((ptr[1] << 8) | ptr[2]) & 0x0fff; - - if (tdt->section_length != 5) { - info("TDT: Invalid section length !\n"); - return -1; - } - - //copy UTC time MJD + UTC - memcpy(tdt->dvbdate, ptr + 3, 5); - - return 0; - -} -//----------------------------------------------------------------------------------- -//TS packets handling -int get_ts_packet_hdr(unsigned char *buf, ts_packet_hdr_t *p) -{ - unsigned char *ptr=buf; - - memset(p,0,sizeof(p)); - - p->sync_byte=ptr[0]; - p->transport_error_indicator=(ptr[1] & 0x80) >> 7; - p->payload_unit_start_indicator=(ptr[1] & 0x40) >> 6; - p->transport_priority=(ptr[1] & 0x20) >> 5; - p->pid=((ptr[1] << 8) | ptr[2]) & 0x1fff; - p->transport_scrambling_control=(ptr[3] & 0xC0) >> 6; - p->adaptation_field_control=(ptr[3] & 0x30) >> 4; - p->continuity_counter=(ptr[3] & 0xf); - -#ifdef DBG - print_ts_header(p); -#endif - - return 0; - -} -//----------------------------------------------------------------------------------- -int ts2psi_data(unsigned char *buf,psi_buf_t *p,int len, int pid_req) -{ - unsigned char *b=buf; - ts_packet_hdr_t h; - - - get_ts_packet_hdr(buf,&h); - - b+=4; - len-=4; - - if (h.sync_byte != 0x47) { -#ifdef SERVER - sys("%s:No sync byte in header !\n",__FUNCTION__); -#endif - return -1; - } - - - if (pid_req != h.pid) { -#ifdef DBG - info("%s:pids mismatch (pid req = %#x ts pid = %#x )!\n", __FUNCTION__,pid_req, h.pid); -#endif - return -1; - } - - //FIXME:Handle adaptation field if present/needed - if (h.adaptation_field_control & 0x2) { - int n; - - n=b[0]+1; - b+=n; - len-=n; - - } - - if (h.adaptation_field_control & 0x1) { - if (h.transport_error_indicator) { -#ifdef DBG - info("Transport error flag set !\n"); -#endif - return -1; - } - if (h.transport_scrambling_control) { -#ifdef DBG - info("Transport scrambling flag set !\n"); -#endif - //return -1; - } - - if (h.payload_unit_start_indicator && p->start) { //whole section new begin packet -#ifdef DBG - info("%s:section read !\n",__FUNCTION__); -#endif - return 1; - } - - if (h.payload_unit_start_indicator && !p->start) { //packet beginning - int si_offset=b[0]+1; //always pointer field in first byte of TS packet payload with start indicator set - b+=si_offset; - len-=si_offset; - if (len < 0 || len > 184) { -#ifdef DBG - info("WARNING 1: TS Packet damaged !\n"); -#endif - return -1; - } - //move to buffer - memcpy(p->buf,b,len); - p->len=len; - p->start=((b[1] << 8) | b[2]) & 0x0fff; //get section length, using start for length - p->pid=h.pid; - p->continuity=h.continuity_counter; - - } - - if (!h.payload_unit_start_indicator && p->start) { //packet continuation - //duplicate packet - if ((p->pid == h.pid) && (p->continuity == h.continuity_counter)){ -#ifdef DBG - info("Packet duplicate ???\n"); -#endif - return -1; - } - //new packet - if (p->pid != h.pid) { -#ifdef DBG - info("New pid buf start %d len %d bytes (pid in buf = %d pid in ts = %d) !\n", p->start,p->len, p->pid, h.pid); -#endif - return -1; - } - //discontinuity of packets - if (((++p->continuity)%16) != h.continuity_counter) { -#ifdef DBG - info("Discontinuity of ts stream !!!\n"); -#endif - return -1; - } - p->continuity=h.continuity_counter; - if (len < 0 || len > 184) { - info("WARNING 2: TS Packet damaged !\n"); - return -1; - } - //move to buffer - memcpy(p->buf+p->len,b,len); - p->len+=len; //FIXME: circular buffer - if (p->len + 188 > PSI_BUF_SIZE) { - info("Error: Buffer full !\n"); - return -1; - //FIXME:realloc - } - } - } - -#if 1 - //3 bytes for bytes containing table id and section length - TS_SECT_LEN(b); - if (slen+3 <= len && h.payload_unit_start_indicator) //len = 188 bytes - 4 bytes ts hdr. - adapt. field bytes - 1 byte offset - offset - return 1; -#else //possible opt. - /*if (p->start+3 == len) - return 1;*/ -#endif - - return 0; -} -//TS packets handling end -//----------------------------------------------------------------------------------- - - - +(symlink to ../common/siparser.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/stream.c
Changed
@@ -3,9 +3,6 @@ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include <winsock2.h> -#include <mstcpip.h> -#include <Ws2ipdef.h> - #endif #include <pthread.h> @@ -15,30 +12,21 @@ #include "stream.h" #include "thread.h" +#define SLEEPTIME (20*1000) + static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; cStream::cStream(int Channum, in_addr_t Addr, int portnum) : cThread("udp streamer") { - size = 188*TS_PER_UDP; handle = 0; channum = Channum; addr = Addr; m_portnum = portnum; - - buf = new char[size]; - - if (buf == NULL) - { - printf("Channel: %d - Cannot allocate memory for buffer", channum); - } - } cStream::~cStream(void) { - if(buf) - delete(buf); } bool cStream::StartStream(in_addr_t bindaddr) @@ -109,84 +97,61 @@ void cStream::Action() { - int retries = 0; - size_t len = 0; - off_t offset = 0; - - int MaxFD; - fd_set WriteFDS; - struct timeval tv; + unsigned int retries; + size_t len; + char *ptr; + struct pollfd p; - stream_info_t *si = (stream_info_t *) handle; + p.fd = udp_socket; + p.events = POLLOUT; while (Running()) { - pthread_mutex_lock(&si->lock_rd); - - if (si->stop) { - pthread_mutex_unlock(&si->lock_rd); - break; - } - - retries = 0; - len = 0; - offset = 0; - - while (retries < 50) { -// printf("si->closed %d\n",si->closed); - len += mcli_stream_read (handle, buf + len, size - len, offset); - offset += len; - if (len == size) + for (retries=1;;retries++) { + if (retries&0xff) + len = mcli_stream_access (handle, &ptr); + else + len = mcli_stream_part_access (handle, &ptr); + if (len) break; - // Sleep 100ms - usleep (100 * 1000); - retries++; + if(!Running())goto out; + usleep (SLEEPTIME); } -// printf("read %s %i, offset %i\n",si->cdata->name,(int)len,(int)offset); - - int rc = 0; - - tv.tv_usec = 500000; - tv.tv_sec = 0; - - MaxFD = udp_socket; - FD_ZERO( &WriteFDS ); - FD_SET( udp_socket, &WriteFDS ); - - // wait for input - rc = ::select( MaxFD +1, NULL, &WriteFDS, NULL, &tv ); - - // log and ignore failures - if( rc < 0 ) - { - log_socket_error( "STREAM select()" ); - continue; - } - else if( rc > 0 ) - { - - // check if socket if writable - if( FD_ISSET( udp_socket, &WriteFDS ) ) - { - rc = ::sendto( udp_socket, buf, len, 0, (struct sockaddr *)&peer, sizeof(peer) ); - if (rc < 0) - { + + switch (poll(&p,1,100)) { + case -1: + log_socket_error( "STREAM poll()" ); + case 0: + usleep (SLEEPTIME); + continue; + default: + if (!(p.revents&POLLOUT)) { + usleep (SLEEPTIME); + continue; + } + if (sendto( udp_socket, ptr, len, 0, (struct sockaddr *)&peer, sizeof(peer) ) < 0) { #ifndef WIN32 - if ( (errno == EINTR) || (errno == EWOULDBLOCK) ) - continue; + if ( (errno == EINTR) || (errno == EWOULDBLOCK) ) { + usleep (SLEEPTIME); + continue; + } #else - rc = WSAGetLastError(); - if ( (rc == WSAEINTR) || (rc == WSAEWOULDBLOCK) ) - continue; -#endif - log_socket_error("STREAM: sendto()"); - pthread_mutex_unlock(&si->lock_rd); - break; + int rc; + rc = WSAGetLastError(); + if ( (rc == WSAEINTR) || (rc == WSAEWOULDBLOCK) ) { + usleep (SLEEPTIME); + continue; } +#endif + log_socket_error("STREAM: sendto()"); + goto out; } + break; } - pthread_mutex_unlock(&si->lock_rd); + + mcli_stream_skip (handle); } +out:; } void cStream::StopStream()
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/stream.h
Changed
@@ -3,16 +3,12 @@ #ifdef WIN32 #include <winsock2.h> -#include <mstcpip.h> -#include <Ws2ipdef.h> #endif #include "clist.h" #include "thread.h" #include "misc.h" -#define TS_PER_UDP 7 - class cStream : public cListObject, public cThread { public: @@ -27,11 +23,9 @@ struct sockaddr_in peer; int channum; in_addr_t addr; - size_t size; - char* buf; int m_portnum; virtual void Action(); }; -#endif \ No newline at end of file +#endif
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/streamer.c
Changed
@@ -15,6 +15,7 @@ m_IgmpMain = NULL; m_bindaddr = 0; m_portnum = 0; + m_table = 0; } void cStreamer::SetBindIf(iface_t bindif) @@ -28,11 +29,16 @@ m_portnum = portnum; } +void cStreamer::SetTable(int table) +{ + m_table = table; +} + void cStreamer::Run() { if ( m_IgmpMain == NULL ) { - m_IgmpMain = new cIgmpMain(this, m_bindif); + m_IgmpMain = new cIgmpMain(this, m_bindif, m_table); m_IgmpMain->StartListener(); } return; @@ -91,4 +97,3 @@ Group->stream = NULL; } } - \ No newline at end of file
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/streamer.h
Changed
@@ -15,6 +15,7 @@ void Stop(); void SetBindIf(iface_t bindif); void SetStreamPort(int portnum); + void SetTable(int table); void SetNumGroups(int numgroups); bool IsGroupinRange(in_addr_t groupaddr); @@ -26,6 +27,7 @@ cIgmpMain* m_IgmpMain; in_addr_t m_bindaddr; iface_t m_bindif; + int m_table; int m_portnum; int m_numgroups; };
View file
vdr-mcli-plugin.tar.bz2/mcast/netcv2dvbip/thread.c
Changed
@@ -170,11 +170,11 @@ void *cThread::StartThread(cThread *Thread) { - if (Thread->description) + if (Thread->description && !quiet) printf("%s thread started.\n", Thread->description); Thread->Action(); - if (Thread->description) + if (Thread->description && !quiet) printf("%s thread ended.\n", Thread->description); Thread->running = false; Thread->active = false;
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/mcast.c
Changed
@@ -1,657 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - * modified by Reel Multimedia, http://www.reel-multimedia.com, info@reel-multimedia.com - * 01042010 DL: use a single thread for reading from network layer (uses less resources) - * - */ - -#include "headers.h" - -//---------------------------------------------------------------------------------------------------------------------------------- -STATIC int udp_ipv6_is_multicast_address (const struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) - return IN_MULTICAST (ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr)); -#endif - if (addr->sa_family == AF_INET6) - return IN6_IS_ADDR_MULTICAST (&((struct sockaddr_in6 *) addr)->sin6_addr); - return -1; -} - -//--------------------------------------------------------------------------------------------------------------------------------- -STATIC int udp_ipv6_set_multicast_ttl (SOCKET sockfd, int mcastTTL, struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) { - if (setsockopt (sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof (mcastTTL)) < 0) { - perror ("setsockopt(IP_MULTICAST_TTL)"); - return -1; - } - } -#endif - if (addr->sa_family == AF_INET6) { - if (setsockopt (sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (_SOTYPE)&mcastTTL, sizeof (mcastTTL)) < 0) { - perror ("setsockopt(IPV6_MULTICAST_HOPS)"); - return -1; - } - } - return 0; -} - -//--------------------------------------------------------------------------------------------------------------------------------- -int udp_ipv6_join_multicast_group (SOCKET sockfd, int iface, struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) { - struct ip_mreq mreq; - mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; - mreq.imr_interface.s_addr = INADDR_ANY; - if (setsockopt (sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *) &mreq, sizeof (mreq)) < 0) { - perror ("setsockopt(IP_ADD_MEMBERSHIP)"); - return -1; - } - } -#endif - if (addr->sa_family == AF_INET6) { - struct ipv6_mreq mreq6; - memcpy (&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *) addr)->sin6_addr), sizeof (struct in6_addr)); - mreq6.ipv6mr_interface = iface; - if (setsockopt (sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (_SOTYPE)&mreq6, sizeof (mreq6)) < 0) { - perror ("setsockopt(IPV6_ADD_MEMBERSHIP)"); - return -1; - } - } - return 0; -} - -//--------------------------------------------------------------------------------------------------------------------------------- -int udp_ipv6_leave_multicast_group (SOCKET sockfd, int iface, struct sockaddr *addr) -{ -#ifdef IPV4 - if (addr->sa_family == AF_INET) { - struct ip_mreq mreq; - mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; - mreq.imr_interface.s_addr = INADDR_ANY; - if (setsockopt (sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *) &mreq, sizeof (mreq)) < 0) { - perror ("setsockopt(IP_DROP_MEMBERSHIP)"); - return -1; - } - } -#endif - if (addr->sa_family == AF_INET6) { - struct ipv6_mreq mreq6; - memcpy (&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *) addr)->sin6_addr), sizeof (struct in6_addr)); - mreq6.ipv6mr_interface = iface; - if (setsockopt (sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, (_SOTYPE)&mreq6, sizeof (mreq6)) < 0) { - perror ("setsockopt(IPV6_DROP_MEMBERSHIP)"); - return -1; - } - } - return 0; -} - -//----------------------------------------------------------------------------------------------------------------------------------- -STATIC int sockfd_to_family (SOCKET sockfd) -{ - struct sockaddr_storage ss; - socklen_t len; - - len = sizeof (ss); - if (getsockname (sockfd, (SA *) & ss, &len) < 0) - return (-1); - return (ss.ss_family); -} - -/* end sockfd_to_family */ -//---------------------------------------------------------------------------------------------------------------------------------- -int mcast_set_if (SOCKET sockfd, const char *ifname, u_int ifindex) -{ - switch (sockfd_to_family (sockfd)) { -#ifdef IPV4 - case AF_INET:{ - struct in_addr inaddr; - struct ifreq ifreq; - - if (ifindex > 0) { - if (if_indextoname (ifindex, ifreq.ifr_name) == NULL) { - errno = ENXIO; /* i/f index not found */ - return (-1); - } - goto doioctl; - } else if (ifname != NULL) { - memset(&ifreq, 0, sizeof(struct ifreq)); - strncpy (ifreq.ifr_name, ifname, IFNAMSIZ-1); - doioctl: - if (ioctl (sockfd, SIOCGIFADDR, &ifreq) < 0) - return (-1); - memcpy (&inaddr, &((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr, sizeof (struct in_addr)); - } else - inaddr.s_addr = htonl (INADDR_ANY); /* remove prev. set default */ - - return (setsockopt (sockfd, IPPROTO_IP, IP_MULTICAST_IF, &inaddr, sizeof (struct in_addr))); - } -#endif - case AF_INET6:{ - u_int idx; -// printf("Changing interface IPV6...\n"); - if ((idx = ifindex) == 0) { - if (ifname == NULL) { - errno = EINVAL; /* must supply either index or name */ - return (-1); - } - if ((idx = if_nametoindex (ifname)) == 0) { - errno = ENXIO; /* i/f name not found */ - return (-1); - } - } - return (setsockopt (sockfd, IPPROTO_IPV6, IPV6_MULTICAST_IF, (_SOTYPE)&idx, sizeof (idx))); - } - - default: -// errno = EAFNOSUPPORT; - return (-1); - } -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -UDPContext *server_udp_open (const struct in6_addr *mcg, int port, const char *ifname) -{ - UDPContext *s; - int sendfd; - int n; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - - s = (UDPContext *) calloc (1, sizeof (UDPContext)); - if (!s) { - err ("Cannot allocate memory !\n"); - goto error; - } - struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &s->dest_addr; - - addr->sin6_addr=*mcg;; - addr->sin6_family = AF_INET6; - addr->sin6_port = htons (port); - s->dest_addr_len = sizeof (struct sockaddr_in6); - - sendfd = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (sendfd < 0) { - err ("cannot get socket\n"); - } - - s->dest_addr_len = sizeof (struct sockaddr_in6); - - if ((udp_ipv6_is_multicast_address ((struct sockaddr *) &s->dest_addr))) { - if (ifname && strlen (ifname) && (mcast_set_if (sendfd, ifname, 0) < 0)) { - warn ("mcast_set_if error\n"); - goto error; - } - if (udp_ipv6_set_multicast_ttl (sendfd, MCAST_TTL, (struct sockaddr *) &s->dest_addr) < 0) { - warn ("udp_ipv6_set_multicast_ttl"); - } - } - - n = UDP_TX_BUF_SIZE; - if (setsockopt (sendfd, SOL_SOCKET, SO_SNDBUF, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt sndbuf"); - } - s->is_multicast = 0; //server - s->udp_fd = sendfd; - s->local_port = port; - - dbg ("Multicast streamer initialized successfully ! \n"); - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return s; - error: - err ("Cannot init udp_server !\n"); - if (s) { - free (s); - } - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return NULL; -} - -UDPContext *server_udp_open_host (const char *host, int port, const char *ifname) -{ - struct in6_addr addr; - - inet_pton (AF_INET6, host, &addr); - - return server_udp_open (&addr, port, ifname); -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -UDPContext *client_udp_open (const struct in6_addr *mcg, int port, const char *ifname) -{ - UDPContext *s; - int recvfd; - int n; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - - s = (UDPContext *) calloc (1, sizeof (UDPContext)); - if (!s) { - err ("Cannot allocate memory !\n"); - goto error; - } - - struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &s->dest_addr; -#ifndef WIN32 - addr->sin6_addr=*mcg; -#else - struct in6_addr any=IN6ADDR_ANY_INIT; - addr->sin6_addr=any; -#endif - addr->sin6_family = AF_INET6; - addr->sin6_port = htons (port); - s->dest_addr_len = sizeof (struct sockaddr_in6); - - recvfd = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (recvfd < 0) { - err ("cannot get socket\n"); - } -#ifdef WIN32 -# ifndef IPV6_PROTECTION_LEVEL -# define IPV6_PROTECTION_LEVEL 23 -# endif - n = 10 /*PROTECTION_LEVEL_UNRESTRICTED*/; - if(setsockopt( recvfd, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (_SOTYPE)&n, sizeof(n) ) < 0 ) { - warn ("setsockopt IPV6_PROTECTION_LEVEL\n"); - } -#endif - n = 1; - if (setsockopt (recvfd, SOL_SOCKET, SO_REUSEADDR, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt REUSEADDR\n"); - } - -#if ! (defined WIN32 || defined APPLE) - if (ifname && strlen (ifname) && setsockopt (recvfd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen (ifname) + 1)) { - dbg ("setsockopt SO_BINDTODEVICE %s failed\n", ifname); - } -#endif - if (bind (recvfd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len) < 0) { - warn ("bind failed\n"); - goto error; - } -#ifdef WIN32 - addr->sin6_addr=*mcg; -#endif - if (udp_ipv6_is_multicast_address ((struct sockaddr *) &s->dest_addr)) { -#if 0 - if (ifname && strlen (ifname) && (mcast_set_if (recvfd, ifname, 0) < 0)) { - warn ("mcast_set_if error \n"); - goto error; - } -#endif - if (ifname) { - if ((s->idx = if_nametoindex (ifname)) == 0) { - s->idx = 0; - } else { - dbg("Selecting interface %s (%d)", ifname, s->idx); - } - } else { - s->idx = 0; - } - - if (udp_ipv6_join_multicast_group (recvfd, s->idx, (struct sockaddr *) &s->dest_addr) < 0) { - warn ("Cannot join multicast group !\n"); - goto error; - } - s->is_multicast = 1; - } - - n = UDP_RX_BUF_SIZE; - if (setsockopt (recvfd, SOL_SOCKET, SO_RCVBUF, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt rcvbuf"); - goto error; - } - - s->udp_fd = recvfd; - s->local_port = port; - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - - return s; - error: - warn ("socket error !\n"); - if (s) { - free (s); - } - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return NULL; -} - -UDPContext *client_udp_open_host (const char *host, int port, const char *ifname) -{ - struct in6_addr addr; - - inet_pton (AF_INET6, host, &addr); - - return client_udp_open (&addr, port, ifname); -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -int udp_read (UDPContext * s, uint8_t * buf, int size, int timeout, struct sockaddr_storage *from) -{ - socklen_t from_len = sizeof (struct sockaddr_storage); - struct sockaddr_storage from_local; - - if(!from) { - from=&from_local; - } - - fd_set rfds; - struct timeval tv; - FD_ZERO(&rfds); - FD_SET(s->udp_fd, &rfds); - tv.tv_sec = 0; - tv.tv_usec = timeout; - - if(select(s->udp_fd+1, &rfds, NULL, NULL, &tv)>0) { - return recvfrom (s->udp_fd, (char *)buf, size, 0, (struct sockaddr *) from, &from_len); - } - return -1; -} - -//-------------------------------------------------------------------------------------------------------------------------------------------------- -int udp_write (UDPContext * s, uint8_t * buf, int size) -{ - int ret; - - for (;;) { - ret = sendto (s->udp_fd, (char *) buf, size, 0, (struct sockaddr *) &s->dest_addr, s->dest_addr_len); - - if (ret < 0) { - if (errno != EINTR && errno != EAGAIN) - return -1; - } else { - break; - } - } - return size; -} - -//---------------------------------------------------------------------------------------------------------------------------------------------------- -int udp_close (UDPContext * s) -{ - if (s->is_multicast) - udp_ipv6_leave_multicast_group (s->udp_fd, s->idx, (struct sockaddr *) &s->dest_addr); - - closesocket (s->udp_fd); - free (s); - - return 0; -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- - -#ifndef MULTI_THREAD_RECEIVER - -#define MAX_BUFF_SIZE 0x10000 -#define MAX_CON_LIST 128 -UDPContext *gConList[MAX_CON_LIST]; -pthread_mutex_t gConListLock = PTHREAD_MUTEX_INITIALIZER; -static int gConListInit=0; - -STATIC void client_upd_cleanup (void *arg) { - if(!gConListInit) return; - pthread_mutex_lock(&gConListLock); - memset(&gConList, 0, sizeof(gConList)); - gConListInit=0; - pthread_mutex_unlock(&gConListLock); -} // client_upd_cleanup - -void *client_upd_process(void *arg) { -#ifdef RT -#if 1 - if (setpriority (PRIO_PROCESS, 0, -15) == -1) -#else - if (pthread_setschedprio (p->recv_ts_thread, -15)) -#endif - { - dbg ("Cannot raise priority to -15\n"); - } -#endif - unsigned char buff[MAX_BUFF_SIZE]; - socklen_t from_len = sizeof (struct sockaddr_storage); - struct sockaddr_storage from_local; - struct timeval timeout; - struct pollfd fds[MAX_CON_LIST]; - - pthread_cleanup_push (client_upd_cleanup, 0); - int i; - while(1) { - int max_fd=0; - pthread_mutex_lock(&gConListLock); - - for(i=0;i<MAX_CON_LIST;i++) { - if(gConList[i]) { - fds[max_fd].fd = gConList[i]->udp_fd; - fds[max_fd].events = POLLIN; - fds[max_fd].revents = 0; - gConList[i]->pfd = &fds[max_fd]; - max_fd++; - } // if - } // for - pthread_mutex_unlock(&gConListLock); - timeout.tv_sec = 0; - timeout.tv_usec = 100000; - int rs = poll(fds, max_fd, 1000); - if(rs>0) { - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) { - if(gConList[i] && gConList[i]->pfd && (gConList[i]->pfd->revents & POLLIN)) { - if(gConList[i]->cb) { - int ret = recvfrom (gConList[i]->udp_fd, (char *)buff, MAX_BUFF_SIZE, 0, 0, 0/*(struct sockaddr *) &from_local, &from_len*/); - if(ret>0) - gConList[i]->cb(buff, ret, gConList[i]->arg); - } else if(gConList[i]->buff && !gConList[i]->bufflen) { - pthread_mutex_lock(&gConList[i]->bufflock); - int ret = recvfrom (gConList[i]->udp_fd, (char *)gConList[i]->buff, gConList[i]->buffmax, 0, (struct sockaddr *) &from_local, &from_len); - if(ret>0) - gConList[i]->bufflen = ret; - pthread_mutex_unlock(&gConList[i]->bufflock); - } // if - } // if - } // for - pthread_mutex_unlock(&gConListLock); - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - } // if - pthread_testcancel(); - } // while - pthread_cleanup_pop (1); - return NULL; -} - -static int client_upd_init() { - pthread_mutex_lock(&gConListLock); - if(gConListInit) { - pthread_mutex_unlock(&gConListLock); - return 1; - } // if - memset(&gConList, 0, sizeof(gConList)); - pthread_t client_upd_thread; - if(0==pthread_create (&client_upd_thread, NULL, client_upd_process, 0)) { - gConListInit = 1; - pthread_detach(client_upd_thread); - } // if - pthread_mutex_unlock(&gConListLock); - return gConListInit; -} // client_upd_init - -UDPContext *client_udp_open_buff (const struct in6_addr *mcg, int port, const char *ifname, int buff_size) { - UDPContext *ret = client_udp_open_cb (mcg, port, ifname, 0, 0); - if(ret) { - ret->buff = (unsigned char *)malloc(buff_size); - ret->buffmax = buff_size; - ret->bufflen = 0; - } // if - return ret; -} // client_udp_open_buff - -UDPContext *client_udp_open_cb (const struct in6_addr *mcg, int port, const char *ifname, client_udp_cb cb, void *arg) -{ - if(!client_upd_init()) return NULL; - - UDPContext *s; - int recvfd = -1; - int n; - - pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - - s = (UDPContext *) calloc (1, sizeof (UDPContext)); - if (!s) { - err ("Cannot allocate memory !\n"); - goto error; - } - - struct sockaddr_in6 *addr = (struct sockaddr_in6 *) &s->dest_addr; -#ifndef WIN32 - addr->sin6_addr=*mcg; -#else - struct in6_addr any=IN6ADDR_ANY_INIT; - addr->sin6_addr=any; -#endif - addr->sin6_family = AF_INET6; - addr->sin6_port = htons (port); - s->dest_addr_len = sizeof (struct sockaddr_in6); - - recvfd = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (recvfd < 0) { - err ("cannot get socket\n"); - } -#ifdef WIN32 -# ifndef IPV6_PROTECTION_LEVEL -# define IPV6_PROTECTION_LEVEL 23 -# endif - n = 10 /*PROTECTION_LEVEL_UNRESTRICTED*/; - if(setsockopt( recvfd, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (_SOTYPE)&n, sizeof(n) ) < 0 ) { - warn ("setsockopt IPV6_PROTECTION_LEVEL\n"); - } -#endif - n = 1; - if (setsockopt (recvfd, SOL_SOCKET, SO_REUSEADDR, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt REUSEADDR\n"); - } - -#if ! (defined WIN32 || defined APPLE) - if (ifname && strlen (ifname) && setsockopt (recvfd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen (ifname) + 1)) { - dbg ("setsockopt SO_BINDTODEVICE %s failed\n", ifname); - } -#endif - if (bind (recvfd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len) < 0) { - warn ("bind failed\n"); - goto error; - } -#ifdef WIN32 - addr->sin6_addr=*mcg; -#endif - if (udp_ipv6_is_multicast_address ((struct sockaddr *) &s->dest_addr)) { -#if 0 - if (ifname && strlen (ifname) && (mcast_set_if (recvfd, ifname, 0) < 0)) { - warn ("mcast_set_if error \n"); - goto error; - } -#endif - if (ifname) { - if ((s->idx = if_nametoindex (ifname)) == 0) { - s->idx = 0; - } else { - dbg("Selecting interface %s (%d)", ifname, s->idx); - } - } else { - s->idx = 0; - } - - if (udp_ipv6_join_multicast_group (recvfd, s->idx, (struct sockaddr *) &s->dest_addr) < 0) { - warn ("Cannot join multicast group !\n"); - goto error; - } - s->is_multicast = 1; - } - - n = cb ? UDP_PID_BUF_SIZE : UDP_RX_BUF_SIZE; - if (setsockopt (recvfd, SOL_SOCKET, SO_RCVBUF, (_SOTYPE)&n, sizeof (n)) < 0) { - warn ("setsockopt rcvbuf"); - goto error; - } - - s->udp_fd = recvfd; - s->local_port = port; - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - - s->cb = cb; - s->arg = arg; - pthread_mutex_init(&s->bufflock, NULL); - int i; - pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) { - if(!gConList[i]) { - gConList[i]=s; - break; - } // if - } // for - pthread_mutex_unlock(&gConListLock); - if(i>=MAX_CON_LIST) - warn("---------------------------------------------No slot found!\n"); - - return s; - error: - warn ("socket error !\n"); - if (s) { - free (s); - } - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - return NULL; -} - -UDPContext *client_udp_open_host_buff (const char *host, int port, const char *ifname, int buff_size) -{ - struct in6_addr addr; - - inet_pton (AF_INET6, host, &addr); - - return client_udp_open_buff (&addr, port, ifname, buff_size); -} - -//-------------------------------------------------------------------------------------------------------------------------------------------- -int udp_read_buff (UDPContext * s, uint8_t * buf, int size, int timeout, struct sockaddr_storage *from) -{ - pthread_mutex_lock(&s->bufflock); - int ret = s->bufflen>size ? size : s->bufflen; - if(ret>0) { - memcpy(buf, s->buff, ret); - s->bufflen-=ret; - } - pthread_mutex_unlock(&s->bufflock); - return ret; -} -//---------------------------------------------------------------------------------------------------------------------------------------------------- -int udp_close_buff (UDPContext * s) -{ - int i; - pthread_mutex_lock(&gConListLock); - for(i=0;i<MAX_CON_LIST;i++) - if(gConList[i] == s) - gConList[i]=0; - pthread_mutex_unlock(&gConListLock); - if (s->is_multicast) - udp_ipv6_leave_multicast_group (s->udp_fd, s->idx, (struct sockaddr *) &s->dest_addr); - - closesocket (s->udp_fd); - free(s->buff); - pthread_mutex_destroy(&s->bufflock); - free (s); - - return 0; -} -#endif +(symlink to ../common/mcast.c)
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/mingw
Added
+(directory)
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/mingw/Makefile
Added
@@ -0,0 +1,26 @@ +NETCVDIAG = netcvdiag.exe +NETCVDIAG_OBJS = netcvdiag.o tools.o + +NETCVLOGVIEW = netcvlogview.exe +NETCVLOGVIEW_OBJS = netcvlogview.o mcast.o + +CC:=gcc +CFLAGS:= -O2 -DCLIENT -DSTATICLIB -Wall -I../../common/win32/include -I../../common -I../../client +LDFLAGS:= -s -L../../common/win32/lib +LDLIBS:=-lmingwex -lpthreadGC2 -lmcli -lxml2 -lz -liphlpapi -lws2_32 + +all: $(NETCVDIAG) $(NETCVLOGVIEW) + @echo Note: netcvupdate.exe can't be built without POSIX environment. + +$(NETCVDIAG): $(NETCVDIAG_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVDIAG_OBJS) $(LDLIBS) + +$(NETCVLOGVIEW): $(NETCVLOGVIEW_OBJS) + $(CC) $(LDFLAGS) -o $@ $(NETCVLOGVIEW_OBJS) $(LDLIBS) + +%.o: ../%.c + $(CC) -c $(CFLAGS) -o $@ $< + +clean: + @-del $(NETCVDIAG) $(NETCVLOGVIEW) *.o *.la *~ +
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/mingw/build.cmd
Added
@@ -0,0 +1,2 @@ +@set PATH=c:\MinGw\bin;%PATH% +@mingw32-make
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/mingw/clean.cmd
Added
@@ -0,0 +1,2 @@ +@set PATH=c:\MinGw\bin;%PATH% +@mingw32-make clean
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/netcvdiag.c
Changed
@@ -5,6 +5,10 @@ #include "headers.h" +#ifdef __MINGW32__ +#include <getopt.h> +#endif + #ifdef API_SOCK /*------------------------------------------------------------------------*/
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/netcvlogview.c
Changed
@@ -1,17 +1,31 @@ #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; + 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:", NULL, NULL); + ret = getopt_long (argc, argv, "hrtp:g:xi:w:flH", NULL, NULL); if(ret<0) { break; } @@ -20,6 +34,9 @@ case 'i': ifname = optarg; break; + case 'f': + file = 1; + break; case 'r': mode = 1; break; @@ -29,9 +46,18 @@ 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] != '-') { @@ -49,7 +75,7 @@ while (c >= 0); if (needhelp) { - fprintf (stderr, "usage: netcvlogview -i <network interface> <-r|-t> -g <multicast groups> -p <port>\n"); + fprintf (stderr, "usage: netcvlogview -i <network interface> <-r|-t> -g <multicast groups> -p <port> -w <seconds timeout> -H\n"); return -1; } @@ -59,6 +85,10 @@ } fprintf (stderr, "]\n"); +#ifdef __MINGW32__ + recv_init (ifname, port); +#endif + switch (mode) { case 1: @@ -76,12 +106,69 @@ } } - while (1) { - len = udp_read (s, buf, sizeof (buf), 50, NULL); - for (i = 0; i < len; i++) { - fputc (buf[i], stdout); + 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; @@ -90,7 +177,7 @@ s = server_udp_open_host (mcg[0], port, ifname); if (s) { while (1) { - if(fread (buf, 1316, 1, stdin)<0) { + if(!fread (buf, 1316, 1, stdin)) { break; } udp_write (s, buf, 1316);
View file
vdr-mcli-plugin.tar.bz2/mcast/tool/tools.c
Changed
@@ -1,777 +0,0 @@ -/* - * (c) BayCom GmbH, http://www.baycom.de, info@baycom.de - * - * See the COPYING file for copyright information and - * how to reach the author. - * - */ - -#define DEBUG 1 -#include "headers.h" - -#ifdef DEBUG -const Param inversion_list[] = { - {"INVERSION_OFF", INVERSION_OFF}, - {"INVERSION_ON", INVERSION_ON}, - {"INVERSION_AUTO", INVERSION_AUTO} -}; - -const Param bw_list[] = { - {"BANDWIDTH_6_MHZ", BANDWIDTH_6_MHZ}, - {"BANDWIDTH_7_MHZ", BANDWIDTH_7_MHZ}, - {"BANDWIDTH_8_MHZ", BANDWIDTH_8_MHZ} -}; - -const Param fec_list[] = { - {"FEC_1_2", FEC_1_2}, - {"FEC_2_3", FEC_2_3}, - {"FEC_3_4", FEC_3_4}, - {"FEC_4_5", FEC_4_5}, - {"FEC_5_6", FEC_5_6}, - {"FEC_6_7", FEC_6_7}, - {"FEC_7_8", FEC_7_8}, - {"FEC_8_9", FEC_8_9}, - {"FEC_AUTO", FEC_AUTO}, - {"FEC_NONE", FEC_NONE}, - {"FEC_1_4", FEC_1_4}, // RMM S2 Extension - {"FEC_1_3", FEC_1_3}, - {"FEC_2_5", FEC_2_5}, - {"FEC_9_10", FEC_9_10} -}; - -const Param guard_list[] = { - {"GUARD_INTERVAL_1_16", GUARD_INTERVAL_1_16}, - {"GUARD_INTERVAL_1_32", GUARD_INTERVAL_1_32}, - {"GUARD_INTERVAL_1_4", GUARD_INTERVAL_1_4}, - {"GUARD_INTERVAL_1_8", GUARD_INTERVAL_1_8} -}; - -const Param hierarchy_list[] = { - {"HIERARCHY_1", HIERARCHY_1}, - {"HIERARCHY_2", HIERARCHY_2}, - {"HIERARCHY_4", HIERARCHY_4}, - {"HIERARCHY_NONE", HIERARCHY_NONE} -}; - -const Param constellation_list[] = { - {"QPSK", QPSK}, - {"QAM_128", QAM_128}, - {"QAM_16", QAM_16}, - {"QAM_256", QAM_256}, - {"QAM_32", QAM_32}, - {"QAM_64", QAM_64}, - {"QPSK_S2", QPSK_S2}, // RMM S2 Extension - {"PSK8", PSK8} -}; - -const Param transmissionmode_list[] = { - {"TRANSMISSION_MODE_2K", TRANSMISSION_MODE_2K}, - {"TRANSMISSION_MODE_8K", TRANSMISSION_MODE_8K}, -}; - -const Param capabilities_list[] = { - {"Stupid: ", FE_IS_STUPID}, - {"FE_CAN_INVERSION_AUTO: ", FE_CAN_INVERSION_AUTO}, - {"CAN_FEC_1_2: ", FE_CAN_FEC_1_2}, - {"CAN_FEC_2_3: ", FE_CAN_FEC_2_3}, - {"CAN_FEC_3_4: ", FE_CAN_FEC_3_4}, - {"CAN_FEC_4_5: ", FE_CAN_FEC_4_5}, - {"CAN_FEC_6_7: ", FE_CAN_FEC_6_7}, - {"CAN_FEC_7_8: ", FE_CAN_FEC_7_8}, - {"CAN_FEC_8_9: ", FE_CAN_FEC_8_9}, - {"CAN_FEC_AUTO: ", FE_CAN_FEC_AUTO}, - {"FE_CAN_QPSK: ", FE_CAN_QPSK}, - {"FE_CAN_QAM_16: ", FE_CAN_QAM_16}, - {"FE_CAN_QAM_32: ", FE_CAN_QAM_32}, - {"FE_CAN_QAM_64: ", FE_CAN_QAM_64}, - {"FE_CAN_QAM_128: ", FE_CAN_QAM_128}, - {"FE_CAN_QAM_256: ", FE_CAN_QAM_256}, - {"FE_CAN_QAM_AUTO: ", FE_CAN_QAM_AUTO}, - {"FE_CAN_TRANSMISSION_MODE_AUTO: ", FE_CAN_TRANSMISSION_MODE_AUTO}, - {"FE_CAN_BANDWIDTH_AUTO: ", FE_CAN_BANDWIDTH_AUTO}, - {"FE_CAN_GUARD_INTERVAL_AUTO: ", FE_CAN_GUARD_INTERVAL_AUTO}, - {"FE_CAN_HIERARCHY_AUTO: ", FE_CAN_HIERARCHY_AUTO}, - {"FE_CAN_MUTE_TS: ", FE_CAN_MUTE_TS} -// {"FE_CAN_CLEAN_SETUP: ",FE_CAN_CLEAN_SETUP} -}; - -#define LIST_SIZE(x) sizeof(x)/sizeof(Param) - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -void print_fe_info (struct dvb_frontend_info *fe_info) -{ - fprintf (stdout, "-------------------------------------------\n"); - fprintf (stdout, "Tuner name: %s\n", fe_info->name); - fprintf (stdout, "Tuner type: %u\n", (unsigned int) fe_info->type); - fprintf (stdout, "Frequency min.: %u\n", fe_info->frequency_min); - fprintf (stdout, "Frequency max.: %u\n", fe_info->frequency_max); - fprintf (stdout, "Frequency stepsize: %u\n", fe_info->frequency_stepsize); - fprintf (stdout, "Frequency tolerance: %u\n", fe_info->frequency_tolerance); - fprintf (stdout, "Symbol rate min: %u\n", fe_info->symbol_rate_min); - fprintf (stdout, "Symbol rate max: %u\n", fe_info->symbol_rate_max); - fprintf (stdout, "Symbol rate tolerance: %u\n", fe_info->symbol_rate_tolerance); - fprintf (stdout, "Notifier delay: %u\n", fe_info->notifier_delay); - fprintf (stdout, "Cpas: 0x%x\n", (unsigned int) fe_info->caps); - - fprintf (stdout, "-------------------------------------------\n"); - fprintf (stdout, "Frontend Capabilities:\n"); - int i; - - for (i = 0; i < LIST_SIZE (capabilities_list); i++) { - if (fe_info->caps & capabilities_list[i].value) - fprintf (stdout, "%syes\n", capabilities_list[i].name); - else - fprintf (stdout, "%sno\n", capabilities_list[i].name); - } - fprintf (stdout, "-------------------------------------------\n"); -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -void print_frontend_settings (struct dvb_frontend_parameters *frontend_param) -{ - int i; - fprintf (stdout, "\n----- Front End Settings ----- "); - fprintf (stdout, "\nFrequency : %u \n", frontend_param->frequency); - for (i = 0; i < LIST_SIZE (inversion_list); i++) { - if (inversion_list[i].value == frontend_param->inversion) - fprintf (stdout, "Inversion : %s\n", inversion_list[i].name); - - } - // - for (i = 0; i < LIST_SIZE (bw_list); i++) { - if (frontend_param->u.ofdm.bandwidth == bw_list[i].value) - fprintf (stdout, "Bandwidth : %s\n", bw_list[i].name); - - } - for (i = 0; i < LIST_SIZE (fec_list); i++) { - if (fec_list[i].value == frontend_param->u.ofdm.code_rate_HP) - fprintf (stdout, "Code Rate HP : %s\n", fec_list[i].name); - - } - for (i = 0; i < LIST_SIZE (fec_list); i++) { - if (fec_list[i].value == frontend_param->u.ofdm.code_rate_LP) - fprintf (stdout, "Code Rate LP : %s\n", fec_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (constellation_list); i++) { - if (constellation_list[i].value == frontend_param->u.ofdm.constellation) - fprintf (stdout, "Modulation : %s\n", constellation_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (transmissionmode_list); i++) { - if (transmissionmode_list[i].value == frontend_param->u.ofdm.transmission_mode) - fprintf (stdout, "Transmission mode : %s\n", transmissionmode_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (guard_list); i++) { - if (guard_list[i].value == frontend_param->u.ofdm.guard_interval) - fprintf (stdout, "Guard interval : %s\n", guard_list[i].name); - - } - - for (i = 0; i < LIST_SIZE (hierarchy_list); i++) { - if (hierarchy_list[i].value == frontend_param->u.ofdm.hierarchy_information) - fprintf (stdout, "Hierarchy Information : %s\n", hierarchy_list[i].name); - - } - -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -void print_mcg (struct in6_addr *mcg) -{ - char host[80]; - unsigned int freq; - struct in6_addr mc; - int i; - - for (i = 0; i < 8; i++) { - mc.s6_addr16[i] = ntohs (mcg->s6_addr16[i]); - } - - freq = mc.s6_addr16[6] | (mc.s6_addr16[7] & NOPID_MASK) << 3; - - inet_ntop (AF_INET6, mcg->s6_addr, (char *) host, INET6_ADDRSTRLEN); - fprintf (stdout, "MCG: %s\n", host); - - fprintf (stdout, "\n"); - fprintf (stdout, "TS-Streaming group\n"); - fprintf (stdout, "-----------------------------\n"); - fprintf (stdout, "Streaming Group - 0x%x \n", (mc.s6_addr16[1] >> 12) & 0xf); - fprintf (stdout, "Priority - 0x%x \n", (mc.s6_addr16[1] >> 8) & 0xf); - fprintf (stdout, "Reception System - 0x%x \n", mc.s6_addr16[1] & 0xff); - fprintf (stdout, "CAM Handling - 0x%x \n", mc.s6_addr16[2]); - fprintf (stdout, "Polarisation - 0x%x \n", (mc.s6_addr16[3] >> 12) & 0xf); - fprintf (stdout, "SATPosition - 0x%x \n", mc.s6_addr16[3] & 0xfff); - fprintf (stdout, "Symbol Rate - 0x%x \n", mc.s6_addr16[4]); - fprintf (stdout, "Modulation - 0x%x \n", mc.s6_addr16[5]); - fprintf (stdout, "Frequency (0x%x) - %d / %d\n\n", freq, freq * (16667 / 8), freq * (250 / 8)); - - fprintf (stdout, "PID - 0x%x \n", mc.s6_addr16[7] & PID_MASK); -} -#endif -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -/* Frequency 19Bit - DVB-T/DVB-C 524288 Steps * (25/12)kHz = 0...1092MHz in 2.083333kHz steps - DVB-S 524288 Steps * (1/20) MHz = 0...26.2GHz in 50kHz steps -*/ -void fe_parms_to_mcg (struct in6_addr *mcg, streaming_group_t StreamingGroup, fe_type_t type, recv_sec_t * sec, struct dvb_frontend_parameters *fep, int vpid) -{ - int i; - unsigned int Priority = 0; - unsigned int ReceptionSystem = 0; - unsigned int CAMHandling = 0; - unsigned int Polarisation = 0; - unsigned int SATPosition = NO_SAT_POS; - unsigned int Symbolrate = 0; - unsigned int Modulation = 0; - unsigned int TransmissionMode = 0; - unsigned int Frequency; - double fmul; - - // Default for DVB-T and DVB-C - fmul = 12.0 * (((double) fep->frequency) + 1041); - Frequency = (unsigned int) (fmul / 25000.0); - - switch (type) { - case FE_QPSK: - case FE_DVBS2: - Frequency = (fep->frequency + 24) / 50; - //sec->diseqc_cmd currently not used - // Fixme: Translation Diseqc->position/LOF-frequency - Polarisation = (sec->mini_cmd << 3) | (sec->tone_mode << 2) | sec->voltage; - Symbolrate = fep->u.qpsk.symbol_rate / 1000; - Modulation |= (fep->u.qpsk.fec_inner) & 0xf; - - // RMM S2 extension: Put Modulation in 23:16 and rolloff in 31:24 - if (((fep->u.qpsk.fec_inner >> 16) & 0xff) == PSK8) - Modulation |= 2 << 4; - if (((fep->u.qpsk.fec_inner >> 16) & 0xff) == QPSK_S2) - Modulation |= 1 << 4; - Modulation |= fep->inversion << 14; - break; - case FE_QAM: - Symbolrate = fep->u.qam.symbol_rate / 200; - Modulation |= fep->u.qam.modulation; - Modulation |= fep->inversion << 14; - break; - case FE_OFDM: - TransmissionMode = fep->u.ofdm.transmission_mode; - Symbolrate = (TransmissionMode & 0x7) << 8 | (fep->u.ofdm.code_rate_HP << 4) | fep->u.ofdm.code_rate_LP; - Modulation |= (fep->u.ofdm.constellation & 0xf) | (fep->u.ofdm.hierarchy_information & 3) << 4 | (fep->u.ofdm.bandwidth & 3) << 7 | (fep->u.ofdm.guard_interval & 7) << 9 | (fep->inversion & 3) << 14; - break; - case FE_ATSC: - Modulation |= fep->u.vsb.modulation; - Modulation |= fep->inversion << 14; - break; - } - - if (type == FE_DVBS2 && !(Modulation & 0x30) ){ - type=FE_QPSK; - } - - ReceptionSystem = type; - - mcg->s6_addr16[0] = MC_PREFIX; - mcg->s6_addr16[1] = ((StreamingGroup & 0xf) << 12) | ((Priority & 0xf) << 8) | (ReceptionSystem & 0xff); - mcg->s6_addr16[2] = CAMHandling; - mcg->s6_addr16[3] = ((Polarisation & 0xf) << 12) | (SATPosition & 0xfff); - mcg->s6_addr16[4] = Symbolrate; - mcg->s6_addr16[5] = Modulation; - mcg->s6_addr16[6] = Frequency; - mcg->s6_addr16[7] = (vpid & PID_MASK) | ((Frequency >> 16) << 13); - - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = htons (mcg->s6_addr16[i]); - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -int mcg_to_all_parms(struct in6_addr *mcg, struct mcg_data * mcd) -{ - int ret; - mcd->mcg=*mcg; - int n; - - ret=mcg_to_fe_parms(mcg, &mcd->type, &mcd->sec, &mcd->fep, &mcd->vpid); - - if (ret) - return ret; - mcg_get_satpos(mcg, &mcd->satpos); - - for(n=0;n<MAX_TUNER_CACHE;n++) { - mcd->sat_cache[n].resolved=NOT_RESOLVED; - mcd->sat_cache[n].num=0; - mcd->sat_cache[n].component=0; - } - - return 0; -} -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -int mcg_to_fe_parms (struct in6_addr *mcg, fe_type_t * type, recv_sec_t * sec, struct dvb_frontend_parameters *fep, int *vpid) -{ - struct in6_addr mc = *mcg; - streaming_group_t StreamingGroup; - unsigned int freq; - double fmul; - fe_type_t fetype; - - int i; - for (i = 0; i < 8; i++) { - mc.s6_addr16[i] = ntohs (mc.s6_addr16[i]); - } - - StreamingGroup = (streaming_group_t)((mc.s6_addr16[1] >> 12) & 0xf); - - if (StreamingGroup != STREAMING_PID) { - return -1; - } - - if (fep) { - memset (fep, 0, sizeof (struct dvb_frontend_parameters)); - } - if (sec) { - memset (sec, 0, sizeof (recv_sec_t)); - } - - - freq = mc.s6_addr16[6] | ((mc.s6_addr16[7] & NOPID_MASK) << 3); - - fmul = 25000.0 * (double) freq; - - fep->frequency = (unsigned int) (fmul / 12.0); - fep->inversion = (fe_spectral_inversion_t)((mc.s6_addr16[5] >> 14) & 3); - fetype = (fe_type_t)(mc.s6_addr16[1] & 0xff); - - if (type) { - *type = fetype; - } - switch (fetype) { - case FE_QPSK: - case FE_DVBS2: - { - int Polarisation = mc.s6_addr16[3] >> 12; - fep->frequency = freq * 50; - sec->mini_cmd = (fe_sec_mini_cmd_t)((Polarisation >> 3) & 1); - sec->tone_mode = (fe_sec_tone_mode_t)((Polarisation >> 2) & 1); - sec->voltage = (fe_sec_voltage_t)(Polarisation & 3); - - fep->u.qpsk.symbol_rate = mc.s6_addr16[4] * 1000; - fep->u.qpsk.fec_inner = (fe_code_rate_t)(mc.s6_addr16[5] & 0xf); - - unsigned int fec_inner=(unsigned int)fep->u.qpsk.fec_inner; - - // RMM S2 Extension - switch (mc.s6_addr16[5] & 0x30) { - case 0x10: - fec_inner |= QPSK_S2 << 16; - fep->u.qpsk.fec_inner=(fe_code_rate_t)fec_inner; - *type = (fe_type_t) FE_DVBS2; // force FE type - break; - case 0x20: - fec_inner |= PSK8 << 16; - fep->u.qpsk.fec_inner=(fe_code_rate_t)fec_inner; - *type = (fe_type_t) FE_DVBS2; - break; - default: - *type = FE_QPSK; - } - } - break; - case FE_QAM: - fep->u.qam.symbol_rate = mc.s6_addr16[4] * 200; - fep->u.qam.modulation = (fe_modulation_t)(mc.s6_addr16[5] & 0xf); - // Ignore inversion - break; - case FE_OFDM: - fep->u.ofdm.transmission_mode = (fe_transmit_mode_t)((mc.s6_addr16[4] >> 8) & 3); - fep->u.ofdm.code_rate_HP = (fe_code_rate_t)((mc.s6_addr16[4] >> 4) & 0xf); - fep->u.ofdm.code_rate_LP = (fe_code_rate_t)(mc.s6_addr16[4] & 0xf); - - fep->u.ofdm.constellation = (fe_modulation_t) (mc.s6_addr16[5] & 0xf); - fep->u.ofdm.hierarchy_information = (fe_hierarchy_t)((mc.s6_addr16[5] >> 4) & 3); - fep->u.ofdm.bandwidth = (fe_bandwidth_t)((mc.s6_addr16[5] >> 7) & 3); - fep->u.ofdm.guard_interval = (fe_guard_interval_t)((mc.s6_addr16[5] >> 9) & 7); - break; - case FE_ATSC: - fep->u.vsb.modulation = (fe_modulation_t)(mc.s6_addr16[5] & 0xf); - break; - } - - if (vpid) { - *vpid = mc.s6_addr16[7] & PID_MASK; - } - //print_frontend_settings(fep); - return 0; -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_set_streaming_group (struct in6_addr *mcg, streaming_group_t StreamingGroup) -{ - int i; - - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = ntohs (mcg->s6_addr16[i]); - } - - // Change StreamingGroup - mcg->s6_addr16[1] = ((StreamingGroup & 0xf) << 12) | (mcg->s6_addr16[1] & 0x0fff); - - // Remove PID - mcg->s6_addr16[7] &= NOPID_MASK; - - // Remove CAID - mcg->s6_addr16[2] = 0; - - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = htons (mcg->s6_addr16[i]); - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_get_streaming_group (struct in6_addr *mcg, streaming_group_t *StreamingGroup) -{ - if(StreamingGroup) { - *StreamingGroup=(streaming_group_t)((ntohs (mcg->s6_addr16[1]) >> 12) & 0xf); - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_set_pid (struct in6_addr *mcg, int pid) -{ - - mcg->s6_addr16[7] = ntohs (mcg->s6_addr16[7]); - - // Remove PID - mcg->s6_addr16[7] &= NOPID_MASK; - - // Set new PID - mcg->s6_addr16[7] |= pid; - - mcg->s6_addr16[7] = htons (mcg->s6_addr16[7]); -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_get_pid (struct in6_addr *mcg, int *pid) -{ - if (pid) { - *pid=ntohs (mcg->s6_addr16[7]) & PID_MASK; - } -} - -//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -void mcg_init_streaming_group (struct in6_addr *mcg, streaming_group_t StreamingGroup) -{ - unsigned int Priority = 1; - mcg->s6_addr16[0] = MC_PREFIX; - mcg->s6_addr16[1] = ((StreamingGroup & 0xf) << 12) | ((Priority & 0xf) << 8) | (0 & 0xff); - mcg->s6_addr16[2] = 0; - mcg->s6_addr16[3] = 0; - mcg->s6_addr16[4] = 0; - mcg->s6_addr16[5] = 0; - mcg->s6_addr16[6] = 0; - mcg->s6_addr16[7] = 0; - int i; - for (i = 0; i < 8; i++) { - mcg->s6_addr16[i] = htons (mcg->s6_addr16[i]); - } - -} - -void mcg_get_priority (struct in6_addr *mcg, int *priority) -{ - if (priority) { - *priority = (ntohs (mcg->s6_addr16[1])>>8) & 0xf; - } -} - -void mcg_set_priority (struct in6_addr *mcg, int priority) -{ - mcg->s6_addr16[1] = ntohs (mcg->s6_addr16[1]); - mcg->s6_addr16[1] &= 0xf0ff; - mcg->s6_addr16[1] |= (priority & 0xf) << 8; - mcg->s6_addr16[1] = htons (mcg->s6_addr16[1]); -} - -void mcg_get_satpos (struct in6_addr *mcg, int *satpos) -{ - if (satpos) { - *satpos = ntohs (mcg->s6_addr16[3]) & 0xfff; - } -} - -void mcg_set_satpos (struct in6_addr *mcg, int satpos) -{ - mcg->s6_addr16[3] = ntohs (mcg->s6_addr16[3]); - - // Remove SatPos - mcg->s6_addr16[3] &= ~NO_SAT_POS; - - // Set new SatPos - mcg->s6_addr16[3] |= (satpos & NO_SAT_POS); - - mcg->s6_addr16[3] = htons (mcg->s6_addr16[3]); -} - -void mcg_get_id (struct in6_addr *mcg, int *id) -{ - if (id) { - *id = ntohs (mcg->s6_addr16[2]); - } -} - -void mcg_set_id (struct in6_addr *mcg, int id) -{ - mcg->s6_addr16[2] = htons(id); -} - -#if defined LIBRARY || defined SERVER -#ifndef OS_CODE - #define OS_CODE 3 -#endif -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif - -static unsigned char gzip_hdr[] = { 0x1f, 0x8b, Z_DEFLATED, 0 /*flags */ , 0, 0, 0, 0 /*time */ , 0 /*xflags */ , OS_CODE }; - -int check_header (const Bytef * buf, unsigned int buflen) -{ - if (buflen <= 10) - return 0; - - if (buf[0] != gzip_hdr[0] || buf[1] != gzip_hdr[1]) { - return -1; - } - - if (memcmp (buf, gzip_hdr, sizeof (gzip_hdr))) { - return -2; - } - return 10; -} - -unsigned int get32_lsb_first (unsigned char *ptr) -{ - int i; - unsigned int val = 0; - for (i = 3; i >= 0; i--) { - val <<= 8; - val |= (ptr[i] & 0xff); - } - return val; -} - -void put32_lsb_first (unsigned char *ptr, unsigned int val) -{ - int i; - for (i = 0; i < 4; i++) { - ptr[i] = val & 0xff; - val >>= 8; - } -} - -int gzip_ (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen, int level) -{ - unsigned int crc = crc32 (0L, Z_NULL, 0); - z_stream stream; - int err; - - if (*destLen <= 10) { - return Z_BUF_ERROR; - } - memcpy (dest, gzip_hdr, sizeof (gzip_hdr)); - - stream.next_in = (Bytef *) source; - stream.avail_in = sourceLen; - - stream.next_out = dest + 10; - stream.avail_out = *destLen - 10; - - stream.zalloc = (alloc_func) 0; - stream.zfree = (free_func) 0; - stream.opaque = (voidpf) 0; - - err = deflateInit2 (&stream, level, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); - - if (err != Z_OK) - return err; - - err = deflate (&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd (&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out + 10; - - err = deflateEnd (&stream); - crc = crc32 (crc, source, sourceLen); - - put32_lsb_first ((unsigned char *) (dest + *destLen), crc); - put32_lsb_first ((unsigned char *) (dest + *destLen + 4), sourceLen); - - *destLen += 8; - return err; -} - -int gzip (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen, int level) -{ - if (!level) { - memcpy (dest, source, sourceLen); - *destLen = sourceLen; - return 0; - } - return gzip_ (dest, destLen, source, sourceLen,level); -} - -int gunzip_ (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen) -{ - unsigned int crc = crc32 (0L, Z_NULL, 0); - z_stream stream; - int err; - int ret = check_header (source, sourceLen); - if (ret < 0) { - return ret; - } - - stream.next_in = (Bytef *) source + ret; - stream.avail_in = sourceLen - ret; - - stream.next_out = dest; - stream.avail_out = *destLen; - - stream.zalloc = (alloc_func) 0; - stream.zfree = (free_func) 0; - - err = inflateInit2 (&stream, -MAX_WBITS); - if (err != Z_OK) - return err; - - err = inflate (&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd (&stream); - if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) - return Z_DATA_ERROR; - return err; - } - *destLen = stream.total_out; - - err = inflateEnd (&stream); - crc = crc32 (crc, dest, stream.total_out); - - int crc_found = get32_lsb_first ((unsigned char *) (stream.next_in)); - int len_found = get32_lsb_first ((unsigned char *) (stream.next_in + 4)); - - if (crc_found == crc && len_found == stream.total_out) { - return err; - } - - return Z_DATA_ERROR; -} - -int gunzip (Bytef * dest, unsigned int *destLen, const Bytef * source, unsigned int sourceLen) -{ - int ret = gunzip_ (dest, destLen, source, sourceLen); - if (ret == -1) { - memcpy (dest, source, sourceLen); - *destLen = sourceLen; - return 0; - } else if (ret < 0) { - return -1; - } - return 0; -} -#endif -#ifndef BACKTRACE - void print_trace (void) - { - } -#else -#include <execinfo.h> -/* Obtain a backtrace and print it to stdout. */ -void print_trace (void) -{ - void *array[10]; - size_t size; - char **strings; - size_t i; - - size = backtrace (array, 10); - strings = backtrace_symbols (array, size); - - printf ("Obtained %zd stack frames.\n", size); - - for (i = 0; i < size; i++) { - printf ("%s\n", strings[i]); - } - free (strings); -} - - -void SignalHandlerCrash(int signum) -{ - void *array[15]; - size_t size; - char **strings; - size_t i; - FILE *f; - char dtstr[16]; - time_t t=time(NULL); - struct tm *tm=localtime(&t); - - signal(signum,SIG_DFL); // Allow core dump - - f=fopen("/var/log/mcli.crashlog","a"); - if (f) { - strftime(dtstr, sizeof(dtstr), "%b %e %T", tm); - size = backtrace (array, 15); - strings = backtrace_symbols (array, size); - fprintf(f,"%s ### Crash signal %i ###\n",dtstr, signum); - for (i = 0; i < size; i++) - fprintf (f, "%s Backtrace %i: %s\n", dtstr, i, strings[i]); - free (strings); - fclose(f); - } -} -#endif - -#ifdef SYSLOG -pthread_mutex_t _loglock = PTHREAD_MUTEX_INITIALIZER; - -UDPContext * syslog_fd = NULL; -char *_logstr = NULL; - -int syslog_init(void) -{ - struct in6_addr mcglog; - mcg_init_streaming_group (&mcglog, STREAMING_LOG); - syslog_fd = server_udp_open (&mcglog, 23000, NULL); - if(syslog_fd) { - _logstr=(char *)malloc(10240); - } - - return syslog_fd?0:-1; -} - -int syslog_write(char *s) -{ - return udp_write (syslog_fd, (uint8_t *)s, strlen(s)); -} - -void syslog_exit(void) -{ - if(syslog_fd) { - udp_close(syslog_fd); - free(_logstr); - } -} -#endif +(symlink to ../common/tools.c)
View file
vdr-mcli-plugin.tar.bz2/mcli.c
Changed
@@ -410,6 +410,7 @@ satellite_info_t *s=satlist->sat+i; switch(s->type){ case SAT_SRC_LNB: + case SAT_SRC_UNI: if(pos == s->SatPos) { // printf("satlist found\n"); return true; @@ -471,6 +472,17 @@ return NULL; } +bool cPluginMcli::Ready() +{ + tuner_pool_t *tp; + for(int i=0; i<TUNER_POOL_MAX; i++) { + tp=m_tuner_pool+i; + if(tp->type != -1) + return true; + } + return false; +} + int cPluginMcli::TunerCountByType (const fe_type_t type) { int ret=0;
View file
vdr-mcli-plugin.tar.bz2/mcli.h
Changed
@@ -161,6 +161,7 @@ bool TunerSatelitePositionLookup(tuner_pool_t *tp, int pos) const; tuner_pool_t *TunerFindByUUID (const char *uuid); + bool Ready(); int TunerCountByType (const fe_type_t type); bool TunerPoolAdd(tuner_info_t *t); bool TunerPoolDel(tuner_pool_t *tp);
View file
vdr-mcli-plugin.tar.bz2/po/de_DE.po
Changed
@@ -22,7 +22,7 @@ msgstr "Aktualisiere Konfiguration..." msgid "Configuration is up to date..." -msgstr "Konfuguration ist aktuell..." +msgstr "Konfiguration ist aktuell..." #, c-format msgid "Getting configuration from Netceiver %s" @@ -30,7 +30,7 @@ #, c-format msgid "Failed to get configuration from Netceiver %s" -msgstr "Fehler beim Holen der Konfiguration von Netceiver %s" +msgstr "Fehler beim Laden der Konfiguration von Netceiver %s" #, c-format msgid "Changing configuration for Netceiver %s"
View file
vdr-mcli-plugin.tar.bz2/po/nl_NL.po
Added
@@ -0,0 +1,87 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: vdr-mcli 1.0\n" +"Report-Msgid-Bugs-To: <see README>\n" +"POT-Creation-Date: 2010-06-29 16:08+0200\n" +"PO-Revision-Date: 2011-06-15 21:59+0100\n" +"Last-Translator: TechNL <technl@reelbox4all.com>\n" +"Language-Team: German <reelbox-devel@mailings.reelbox.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "Multi-Transponder" +msgstr "Multi-Transponder" + +msgid "Updating configuration..." +msgstr "Konfiguratie updaten..." + +msgid "Configuration is up to date..." +msgstr "Konfuguratie is aktueel..." + +#, c-format +msgid "Getting configuration from Netceiver %s" +msgstr "Configuratiie van Netceiver %s ophalen" + +#, c-format +msgid "Failed to get configuration from Netceiver %s" +msgstr "Fout tijdens het ophalen van de configuratie van Netceiver %s" + +#, c-format +msgid "Changing configuration for Netceiver %s" +msgstr "Configuratie aktualiseren van Netceiver %s" + +#, c-format +msgid "Failed to parse configuration from Netceiver %s" +msgstr "Fout tijdens het parsen van de config van Netceiver %s" + +#, c-format +msgid "Failed to set configuration for Netceiver %s" +msgstr "Fout tijdens het instellen van de config van Netceiver %s" + +#, c-format +msgid "Failed to save configuration for Netceiver %s" +msgstr "Fout bij het opslaan van de config van Netceiver %s" + +#, c-format +msgid "Saving configuration for Netceiver %s" +msgstr "Opslaan van de configuratie van Netceiver %s" + +msgid "Multi-Transponder-Decryption is" +msgstr "Multi-Transponder decoderen is niet" + +msgid "impossible because of mixed CAMs" +msgstr "mogelijk omdat verschillende CAM's worden gebruikt" + +msgid "Save" +msgstr "Opslaan" + +#, c-format +msgid "Waiting for a free tuner (%s)" +msgstr "Wachten tot tuner voor (%s) beschikbaar komt" + +msgid "DVB-C" +msgstr "DVB-C" + +msgid "DVB-T" +msgstr "DVB-T" + +msgid "DVB-S" +msgstr "DVB-S" + +msgid "DVB-S2" +msgstr "DVB-S2" + +#, c-format +msgid "Module '%s' ready" +msgstr "Module '%s' gereed" + +#, c-format +msgid "Module '%s' removed" +msgstr "Module '%s' verwijderd" +
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.