Skip to content

Commit

Permalink
Resolve issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
harlequin committed Jul 4, 2016
1 parent dfeca47 commit 68c32ae
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 144 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ APP_OBJ = dvbapi.o hook.o C_support.o log.o
LIB_TV_MODEL=
CFLAGS += -fPIC -O2 -std=gnu99
CFLAGS += -ldl -DBUILD_GIT_SHA=\"$(GIT_VERSION)\"
GIT_VERSION := $(shell git describe --dirty --always --abbrev=4)
GIT_VERSION := $(shell git describe --dirty --always --abbrev=7)
TAG := $(shell git describe --tags)

ifeq ($(PLATFORM), D-MST)
Expand Down Expand Up @@ -56,7 +56,7 @@ libdvbapi.so: $(OBJS)
$(CROSS)gcc $(CFLAGS) -c -o $@ $<

clean:
rm -f $(OBJS) ${TARGETS} ./models/*.o
rm -f $(OBJS) ${TARGETS} ./models/*.o *.so

.PHONY: clean
.PHONY: install
1 change: 0 additions & 1 deletion dvbapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ EXTERN_C void lib_init(void *_h, const char *libpath) {
}

unlink(LOG_FILE);
log("SamyGO "LIB_TV_MODELS" lib"LIB_NAME" "LIB_VERSION" - "BUILD_GIT_TIME" (c) element 2016\n");

void *h = dlopen(0, RTLD_LAZY);

Expand Down
227 changes: 86 additions & 141 deletions models/serie_e.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@

#define FILTER_MASK_SIZE 16

#define DMX_HANDLE_19800000 0x19800000
#define DMX_HANDLE_LIVE 0x19800620
#define DMX_HANDLE_PVR 0x19800621
#define DMX_HANDLE_UNKNOWN 0x19800622
#define DMX_HANDLE_PIP 0x19800623

typedef struct DEMUX_FILTER {
u16 tableId;
s32 monHandle;
Expand All @@ -47,130 +41,93 @@ typedef struct DEMUX_FILTER {
static int g_send_PMT_required = 0;
static int g_SID = 0;
static int g_fltDscmb = 0;
static unsigned int g_dmxHandle = DMX_HANDLE_LIVE;
static SdTSData_Settings_t g_dmxParams;
static s32 g_dmxMonHandle = -1;
static s32 g_dmxTableId = -1;
static unsigned int g_dmxHandle = 0;
static demux_filter_t *g_demux_filter = NULL;
static SdTSData_Settings_t g_emmParams;

static u32 g_hDesc = 0;
static u32 g_DscmbId = 0;
static u32 g_SourceId = 0;
static u32 g_DescId = 0;

//typedef enum {
// EVEN = 0,
// ODD = 1,
//} KeyType_e;
//static SdTSData_Settings_t g_dmxParams;
//static s32 g_dmxMonHandle = -1;
//static s32 g_dmxTableId = -1;
//DMX_HANDLE_LIVE;
//#define DMX_HANDLE_19800000 0x19800000
//#define DMX_HANDLE_LIVE 0x19800620
//#define DMX_HANDLE_PVR 0x19800621
//#define DMX_HANDLE_UNKNOWN 0x19800622
//#define DMX_HANDLE_PIP 0x19800623


typedef union {
const void *procs[15];
const void *procs[18];
struct {
const int (*SdTSData_StartMonitor)(u32 dmx_handle, SdTSData_Settings_t *a1);
const int (*SdTSData_StopMonitor)(u32 dmx_handle, u32 mon_handle);
const int (*spITsd_Open)(signed int a1 ,void *hDesc);
const int (*spITsd_DescramblerAllocate)(u32 hDesc, signed int a2, void *u32DscmbId);
const int (*spITsd_DescramblerDeallocate)(u32 hDesc, u32 u32DscmbId);
const int (*spITsd_DescramblerLinkToDmx)(u32 hDesc, u32 u32DscmbId, u32 dmxHandle);
const int (*spITsd_DescramblerSetKey)(u32 hDesc, u32 DscmbId, u32 parity, u8 *data, u8 len);
void **g_pAppWindow;

const int (*GetSource) (void *window, int *source, int arg3);
const int (*GetTvChannel)(void *window, void *channel, int arg3);
const int (*SetChannelQuiet)(void *window, void *channel, int arg3);
const void* (*TCChannel_Create)(void *channel);
const void* (*TCChannel_Destroy)(void *channel);
const int (*ProgramNumber)(void *this);
//const int (*TCChannel_SizeOfDescriptor)(void *this)
//const int (*TCChannel_Descriptor)(void *this, int a2, int a3);
const int (*TPASource_Id)(void);
// libSDAL.so
int (*SdTSData_StartMonitor)(unsigned int dmxHandle, void* dmxParams, unsigned int eDataType);
int (*SdTSData_StopMonitor)(unsigned int dmxHandle, unsigned int monHandle);

int (*spITsd_Open)(unsigned int eTsdClassInst, unsigned int *hDesc);
int (*spITsd_DescramblerAllocate)(unsigned int hDesc, unsigned int eCaType, unsigned int *u32DescId); // eCaType = 2 (CSA)
int (*spITsd_DescramblerDeallocate)(unsigned int hDesc, unsigned int u32DescId);
int (*spITsd_DescramblerLinkToDmx)(unsigned int hDesc, unsigned int u32DescId, unsigned int dmxInfoHndl_spIHandle); // *(_DWORD *)(g_dmxHandle + 8)
int (*spITsd_DescramblerSetKey)(unsigned int hDesc, unsigned int u32DescId, int cwParity, unsigned char* pKey, int keyLen);

// exeDSP
void** g_pAppWindow;
const int (*TCWindow_GetSource)(void *window, int *source, int a2);
const int (*TCWindow_GetTVChannel)(void *window, void *channel, int arg3);
const int (*TCWindow_SetChannelQuiet)(void *window, void *channel, int arg3);
const int (*TCChannel_Create)(void *channel);
const int (*TCChannel_Destroy)(void *channel);
const int (*TCChannel_ProgramNumber)(void* channel);
const int (*TCChannel_SizeOfDescriptor)(void *channel);
const int (*TCChannel_Descriptor)(void *channel, int nine, int desc);
};

} api_callbacks_t;

api_callbacks_t api_callbacks = {
(const void*)"_Z21SdTSData_StartMonitorjP19SdTSData_Settings_tj",
(const void*)"_Z20SdTSData_StopMonitorjj",
(const void *)"spITsd_Open",
(const void *)"spITsd_DescramblerAllocate",
(const void *)"spITsd_DescramblerDeallocate",
(const void *)"spITsd_DescramblerLinkToDmx",
(const void *)"spITsd_DescramblerSetKey",
(const void *)"g_pAppWindow",
(const void *)"_ZN8TCWindow9GetSourceEPii",
(const void *)"_ZN8TCWindow12GetTVChannelEP9TCChanneli",
(const void *)"_ZN8TCWindow15SetChannelQuietEPK9TCChannelb",
(const void *)"_ZN9TCChannelC2Ev",
(const void *)"_ZN9TCChannelD2Ev",
(const void *)"_ZNK9TCChannel13ProgramNumberEv",
// (const void *)"_ZNK9TCChannel16SizeOfDescriptorEv",
// (const void *)"_ZNK9TCChannel10DescriptorEii",
(const void *)"_ZN9TPASource2IdEv",
};

static void stopMonitors() {
u32 ret;

if (g_dmxMonHandle >= 0) {
ret = api_callbacks.SdTSData_StopMonitor(g_dmxHandle, g_dmxMonHandle);
log("ECM%02X monitor stopped, dmxHandle=0x%08x, monHandle=0x%08x, ret=0x%08x\n",g_dmxTableId, g_dmxHandle, g_dmxMonHandle, ret);
g_dmxMonHandle = -1;
g_dmxTableId = -1;
}
}


static void changeMonitor(unsigned int dmxHandle) {
if ( g_dmxTableId == -1) {
return;
}

stopMonitors();

g_dmxHandle = dmxHandle;
log("using dmxHandle=0x%08X\n", dmxHandle);

g_dmxMonHandle = api_callbacks.SdTSData_StartMonitor(DMX_HANDLE_LIVE, &g_dmxParams);
log("ECM%02x monitor restarted, dmxHandle=0x%08x, monHandle=0x%08x\n",g_dmxTableId, g_dmxHandle, g_dmxMonHandle);
}



(const void*)"spITsd_Open",
(const void*)"spITsd_DescramblerAllocate",
(const void*)"spITsd_DescramblerDeallocate",
(const void*)"spITsd_DescramblerLinkToDmx",
(const void*)"spITsd_DescramblerSetKey",

(const void*)"g_pAppWindow",
(const void*)"_ZN8TCWindow9GetSourceEPii",
(const void*)"_ZN8TCWindow12GetTVChannelEP9TCChanneli",
(const void*)"_ZN8TCWindow15SetChannelQuietEPK9TCChannelb",
(const void*)"_ZN9TCChannelC2Ev",
(const void*)"_ZN9TCChannelD2Ev",
(const void*)"_ZNK9TCChannel13ProgramNumberEv",
(const void*)"_ZNK9TCChannel16SizeOfDescriptorEv",
(const void*)"_ZNK9TCChannel10DescriptorEii",
};

_HOOK_IMPL(int,SdAVDec_DemuxStop, unsigned int dmxHandle, int eDemuxOut) {
log("SdAVDec_DemuxStop, dmxHandle=0x%08X, eDemuxOut=0x%08X\n", dmxHandle, eDemuxOut);
log("g_dmxHandle=0x%08X\n", g_dmxHandle);

switch (g_dmxHandle) {
case DMX_HANDLE_LIVE:
api_callbacks.SdTSData_StopMonitor(DMX_HANDLE_LIVE, 0x00);
break;
case DMX_HANDLE_PIP:
case DMX_HANDLE_PVR:
log("CHANGE MONITOR NORMALY ...\n");
changeMonitor(DMX_HANDLE_LIVE);
break;
default:
log("Unknown dmx handle value: 0x%08X\n", dmxHandle);
break;
}

_HOOK_DISPATCH(SdAVDec_DemuxStop, dmxHandle, eDemuxOut);
g_dmxHandle = dmxHandle;
log("g_dmxHandle=0x%08X\n", g_dmxHandle);
return (int)h_ret;
}

_HOOK_IMPL(int,SdAVDec_DemuxStart, unsigned int dmxHandle, int eDemuxOut) {
log("SdDemux_Start, dmxHandle=0x%08X, eDemuxOut=0x%08X\n", dmxHandle, eDemuxOut);
g_dmxHandle = dmxHandle;
log("g_dmxHandle=0x%08X\n", g_dmxHandle);
_HOOK_DISPATCH(SdAVDec_DemuxStart, dmxHandle, eDemuxOut);

if ( g_dmxHandle != DMX_HANDLE_PVR) {
changeMonitor(dmxHandle);
}

return (int)h_ret;
}

_HOOK_IMPL(int,DemuxBase_m_Demux_SICallback, u32* data) {
//log("DemuxBase_m_Demux_SICallback, ra: %p, hmon=0x%08X, pid=0x%08X, buf=0x%08X, len=0x%08X\n", ra, SICallBackSettings_t[0], SICallBackSettings_t[1],SICallBackSettings_t[2],SICallBackSettings_t[3]);
//void *ra;
//asm("move %0, $ra\n" : "=r" (ra));

_HOOK_DISPATCH(DemuxBase_m_Demux_SICallback, data);

pmt_t *buf;
Expand Down Expand Up @@ -211,33 +168,19 @@ _HOOK_IMPL(int,DemuxBase_m_Demux_SICallback, u32* data) {
return (int)h_ret;
}

//const int (*TCCIMManagerBase_HostChannelChangeCompleted)(u32 this, u32 TCChannel, u32 a3, u32 TCCIM_SRouteInformation, u32 ECAStateType);
_HOOK_IMPL(int, TCCIMManagerBase_HostChannelChangeCompleted, u32 this, u32 TCChannel, u32 a3, u32 ESource, u32 a5) {
//void *ra;
//asm("move %0, $ra\n" : "=r" (ra));
log("TCCIMManagerBase_HostChannelChangeCompleted, this: 0x%08x tcchannel: 0x%08x a3: 0x%08x esource: 0x%08x a5: 0x%08x\n",this,TCChannel,a3,ESource,a5);
_HOOK_DISPATCH(TCCIMManagerBase_HostChannelChangeCompleted, this, TCChannel, a3, ESource, a5);
_HOOK_IMPL(int, TCCIMManagerBase_HostChannelChangeCompleted, u32 this, u32 TCChannel, u32 *TCSourceConf) {
_HOOK_DISPATCH(TCCIMManagerBase_HostChannelChangeCompleted, this, TCChannel, TCSourceConf);

if ( TCChannel != 0x00 ) {
int sid = api_callbacks.ProgramNumber( (void *) TCChannel);
int sid = api_callbacks.TCChannel_ProgramNumber( (void *) TCChannel);
if ( g_SID != sid ) {

if ( g_hDesc != 0 ) {
api_callbacks.spITsd_DescramblerDeallocate(g_hDesc, g_DscmbId);
}

g_SID = sid;
g_send_PMT_required = 1;
g_SourceId = api_callbacks.TPASource_Id();

log("Source id=%d\n", g_SourceId);
log("spITsd_DescramblerDeallocate(0x%08X, 0x%08X)=%d\n", g_hDesc, g_DescId, api_callbacks.spITsd_DescramblerDeallocate(g_hDesc, g_DescId));
log("spITsd_DescramblerAllocate(0x%08X,...)=%d, g_u32DscmbID=0x%08X\n", g_hDesc, api_callbacks.spITsd_DescramblerAllocate(g_hDesc, 2, &g_DescId), g_DescId);
log("spITsd_DescramblerLinkToDmx(0x%08X, 0x%08X, 0x%08X)=%d\n", g_hDesc, g_DescId, *(unsigned int *)(g_dmxHandle + 8), api_callbacks.spITsd_DescramblerLinkToDmx(g_hDesc, g_DescId, *(unsigned int *)(g_dmxHandle + 8)));

u32 all_res = api_callbacks.spITsd_DescramblerAllocate(g_hDesc, g_SourceId, &g_DscmbId);
log("spITsd_DescramblerAllocate(0x%08x,...)=%d, g_u32DscmbID=0x%08x\n", g_hDesc, all_res, g_DscmbId);

/*TODO: Where comes the value 0x450E2B1C from and how is this fitting to DMX_HANDLE 0x03D3407C */
all_res = api_callbacks.spITsd_DescramblerLinkToDmx(g_hDesc, g_DscmbId, 0x450E2B1C);
log("spITsd_DescramblerLinkToDmx(0x%08x, 0x%08x, 0x450E2B1C)=%d\n", g_hDesc, g_DscmbId, all_res);
g_send_PMT_required = 1;
log("Service id changes, new SID: 0x%04x\n", g_SID);
}
}
Expand All @@ -247,7 +190,7 @@ _HOOK_IMPL(int, TCCIMManagerBase_HostChannelChangeCompleted, u32 this, u32 TCCha

STATIC dyn_fn_t TCCIMManagerBase_func_table[] = {
{ 0, "_ZN11TDsSamDemux17m_DemuxSICallbackEPN8CDiDemux20SICallBackSettings_tE" },
{ 0, "_ZN16TCCIMManagerPlus13ChannelChangeEPK9TCChannelP12TCSourceConf" },
{ 0, "_ZN9TCCAMConf13ChannelChangeEP9TCChannelP12TCSourceConf" },
{ 0, "_Z13SdDemux_Startj13SdDemux_Out_k" },
{ 0, "_Z12SdDemux_Stopj13SdDemux_Out_k" },
};
Expand Down Expand Up @@ -278,32 +221,34 @@ int dvbapi_install(void *h) {
res = 1;
}

u32 value = api_callbacks.spITsd_Open(0, &g_hDesc);
log("spITsd_Open=%d, g_hDesc = 0x%08x\n", value, g_hDesc);
log("spITsd_Open=%d, g_hDesc = 0x%08X\n", api_callbacks.spITsd_Open(4096, &g_hDesc), g_hDesc);

return res;
}

int dvbapi_server_info(void) {
//g_SID = -1;

u8 channel[0x20];
u32 source = 0; /*TODO Check if source is live tv 0x00 */
api_callbacks.GetSource(*api_callbacks.g_pAppWindow, &source, 0x01);
api_callbacks.TCChannel_Create(channel);
api_callbacks.GetTvChannel(*api_callbacks.g_pAppWindow, channel, 0x01);
/*TODO: Implement descriptor stuff and check if scrambled */
//int scrambled = api_callbacks.FlagScrambled(channel);
//if ( scrambled != 0) {
api_callbacks.SetChannelQuiet(*api_callbacks.g_pAppWindow, channel, 0x01);
//}
int source = 0;

return 0;
api_callbacks.TCWindow_GetSource(*api_callbacks.g_pAppWindow, &source, 1);
if(source == 0) {
u32 channel[32] = {0};

api_callbacks.TCChannel_Create(channel);
api_callbacks.TCWindow_GetTVChannel(*api_callbacks.g_pAppWindow, channel, 1);

for(int i = 0; i < api_callbacks.TCChannel_SizeOfDescriptor(channel); i++) {
if(api_callbacks.TCChannel_Descriptor(channel, 9, i)) {
api_callbacks.TCWindow_SetChannelQuiet(*api_callbacks.g_pAppWindow, channel, 1);
break;
}
}
api_callbacks.TCChannel_Destroy(channel);
}
}

int dvbapi_set_descriptor(ca_descr_t ca_descr) {
g_fltDscmb = api_callbacks.spITsd_DescramblerSetKey(g_hDesc, g_DscmbId, ca_descr.parity, ca_descr.cw, 8);
log("spITsd_DescramblerSetKey(0x%08x, 0x%08x, 0x%02x, ...)=%d\n", g_hDesc, g_DscmbId, ca_descr.parity, g_fltDscmb);
g_fltDscmb = g_hDesc,g_DescId, ca_descr.parity, api_callbacks.spITsd_DescramblerSetKey(g_hDesc, g_DescId, ca_descr.parity, ca_descr.cw, 8);
log("spITsd_DescramblerSetKey(0x%08X, 0x%08X, 0x%02X, ...)=%d\n", g_fltDscmb);
return g_fltDscmb;
}

Expand All @@ -323,7 +268,7 @@ int dvbapi_start_filter(u8 demux_index, u8 filter_num, struct dmx_sct_filter_par
}

if (filter->monHandle != -1) {
u32 ret = api_callbacks.SdTSData_StopMonitor(g_dmxHandle, filter->monHandle);
u32 ret = api_callbacks.SdTSData_StopMonitor(g_dmxHandle, filter->monHandle );
log("EMM%02X monitor stopped, dmxHandle=0x%08x, monHandle=0x%08x, ret=0x%08x\n",filter->tableId, g_dmxHandle, filter->monHandle, ret);
filter->monHandle = -1;
filter->tableId = -1;
Expand All @@ -336,7 +281,7 @@ int dvbapi_start_filter(u8 demux_index, u8 filter_num, struct dmx_sct_filter_par
filter->tableId = params.filter.filter[0];
filter->demuxId = demux_index;
filter->filterId = filter_num;
filter->monHandle = api_callbacks.SdTSData_StartMonitor(DMX_HANDLE_LIVE, &g_emmParams);
filter->monHandle = api_callbacks.SdTSData_StartMonitor(g_dmxHandle, &g_emmParams,0 );
log("EMM%02x monitor started, dmxHandle=0x%08x, monHandle=0x%08x\n",filter->tableId, g_dmxHandle, filter->monHandle);
}
return 0;
Expand Down

0 comments on commit 68c32ae

Please sign in to comment.