armbox: add dvbci (thx DboxOldie)

Origin commit data
------------------
Branch: master
Commit: 8886015bac
Author: max_10 <max_10@gmx.de>
Date: 2017-11-05 (Sun, 05 Nov 2017)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
max_10
2017-11-05 16:02:44 +01:00
parent d05c5f387b
commit d5fa88c7cd
11 changed files with 845 additions and 386 deletions

View File

@@ -9,13 +9,24 @@ AM_CXXFLAGS += \
-I $(top_srcdir)/libdvbci -I $(top_srcdir)/libdvbci
endif endif
if BOXTYPE_ARMBOX
AM_CXXFLAGS += \
-I $(top_srcdir)/include \
-I $(top_srcdir)/libdvbci
endif
if BOXTYPE_DUCKBOX if BOXTYPE_DUCKBOX
libcommon_la_SOURCES = \ libcommon_la_SOURCES = \
ca_ci.cpp ca_ci.cpp
else else
if BOXTYPE_ARMBOX
libcommon_la_SOURCES = \
ca_ci.cpp
else
libcommon_la_SOURCES = \ libcommon_la_SOURCES = \
ca.cpp ca.cpp
endif endif
endif
libcommon_la_SOURCES += \ libcommon_la_SOURCES += \
lt_debug.cpp \ lt_debug.cpp \

View File

@@ -1,7 +1,7 @@
/* /*
* dummy functions to implement ca_cs.h interface * dummy functions to implement ca_cs.h interface
*/ */
#if HAVE_DUCKBOX_HARDWARE #if HAVE_DUCKBOX_HARDWARE || HAVE_ARM_HARDWARE
#include "ca_ci.h" #include "ca_ci.h"
#else #else
#ifndef __CA_LIBTRIPLE_H_ #ifndef __CA_LIBTRIPLE_H_

File diff suppressed because it is too large Load Diff

View File

@@ -194,8 +194,10 @@ typedef struct
bool ccmgr_ready; bool ccmgr_ready;
char ci_dev[32];
char name[512]; char name[512];
bool newPids;
bool newCapmt; bool newCapmt;
bool multi; bool multi;
bool recordUse[CI_MAX_MULTI]; bool recordUse[CI_MAX_MULTI];
@@ -212,6 +214,8 @@ typedef struct
CaIdVector cam_caids; CaIdVector cam_caids;
std::priority_queue<queueData> sendqueue; std::priority_queue<queueData> sendqueue;
std::vector<u16> pids;
bSIDVector bsids; bSIDVector bsids;
unsigned char lastKey[32]; unsigned char lastKey[32];
unsigned char scrambled; unsigned char scrambled;
@@ -237,6 +241,38 @@ private:
cCA(void); cCA(void);
/// Private data for the CA module /// Private data for the CA module
CS_CA_PDATA *privateData; CS_CA_PDATA *privateData;
/// set inputs with tuner letter in tsmux
void setInputs();
/// write ci info file to /tmp
void write_ci_info(int slot, CaIdVector caids);
/// delete ci info file
void del_ci_info(int slot);
/// extract audio / video pids from capmt
void extractPids(eDVBCISlot* slot);
/// ci module is detected
void ci_inserted(eDVBCISlot* slot);
/// ci module is removed
void ci_removed(eDVBCISlot* slot);
/// decode the tpdu tag
void process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int asn_data_length, int con_id);
/// set flag of running ci record to false
bool StopRecordCI( u64 TP, u16 SID, u8 source, u32 calen);
/// set flag of running ci live-tv to false
bool StopLiveCI( u64 TP, u16 SID, u8 source, u32 calen);
/// find an unused ci slot for use with service
SlotIt FindFreeSlot(u64 tpid, u8 source, u16 sid, ca_map_t camap, u8 scrambled);
/// get slot iterator by slot number
SlotIt GetSlot(unsigned int slot);
/// send buffered capmt to ci modul
bool SendCaPMT(eDVBCISlot* slot);
/// send a dummy capmt to ci for deactivating
bool SendNullPMT(eDVBCISlot* slot);
/// set ci source
void setSource(eDVBCISlot* slot);
/// set demux source
void setInputSource(eDVBCISlot* slot, bool ci);
/// check if data in queue
bool checkQueueSize(eDVBCISlot* slot);
enum CA_INIT_MASK initMask; enum CA_INIT_MASK initMask;
int num_slots; int num_slots;
bool init; bool init;
@@ -246,7 +282,9 @@ private:
pthread_t slot_thread; pthread_t slot_thread;
public: public:
/// sh4 unused
bool Init(void); bool Init(void);
/// init ci and start the loop
cCA(int Slots); cCA(int Slots);
/// Returns the number of CI slots /// Returns the number of CI slots
uint32_t GetNumberCISlots(void); uint32_t GetNumberCISlots(void);
@@ -260,17 +298,23 @@ public:
bool SendMessage(const CA_MESSAGE *Msg); bool SendMessage(const CA_MESSAGE *Msg);
/// Sets which modules to initialize. It is only /// Sets which modules to initialize. It is only
/// possible to change this once! /// possible to change this once!
/// sh4 unused
void SetInitMask(enum CA_INIT_MASK InitMask); void SetInitMask(enum CA_INIT_MASK InitMask);
/// Sets the frequency (in Hz) of the TS stream input (only valid for CI) /// Sets the frequency (in Hz) of the TS stream input (only valid for CI)
void SetTSClock(u32 /*Speed*/) { return; }; /// sh4 unused
void SetTSClock(u32 Speed);
/// Start the CA module /// Start the CA module
/// sh4 unused
bool Start(void); bool Start(void);
/// Stops the CA module /// Stops the CA module
/// sh4 unused
void Stop(void); void Stop(void);
/// Notify that the GUI is ready to receive messages /// Notify that the GUI is ready to receive messages
/// (CA messages coming from a module) /// (CA messages coming from a module)
/// sh4 unused
void Ready(bool Set); void Ready(bool Set);
/// Resets a module (if possible) /// Resets a module (if possible)
/// sh4 unused
void ModuleReset(enum CA_SLOT_TYPE, uint32_t Slot); void ModuleReset(enum CA_SLOT_TYPE, uint32_t Slot);
/// Checks if a module is present /// Checks if a module is present
bool ModulePresent(enum CA_SLOT_TYPE, uint32_t Slot); bool ModulePresent(enum CA_SLOT_TYPE, uint32_t Slot);
@@ -285,29 +329,20 @@ public:
/// Notify the module we closed the menu /// Notify the module we closed the menu
void MenuClose(enum CA_SLOT_TYPE, uint32_t Slot); void MenuClose(enum CA_SLOT_TYPE, uint32_t Slot);
/// Get the supported CAIDs /// Get the supported CAIDs
// int GetCAIDS(CaIdVector & /*Caids*/) { return 0; };
int GetCAIDS(CaIdVector &Caids); int GetCAIDS(CaIdVector &Caids);
/// Send a CA-PMT object and Raw unparsed PMT to the CA layer /// Send a CA-PMT object and Raw unparsed PMT to the CA layer
bool SendCAPMT(u64 /*Source*/, u8 /*DemuxSource*/, u8 /*DemuxMask*/, const unsigned char * /*CAPMT*/, u32 /*CAPMTLen*/, const unsigned char * /*RawPMT*/, u32 /*RawPMTLen*/, enum CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL, bool SendCAPMT(u64 /*Source*/, u8 /*DemuxSource*/, u8 /*DemuxMask*/, const unsigned char * /*CAPMT*/, u32 /*CAPMTLen*/, const unsigned char * /*RawPMT*/, u32 /*RawPMTLen*/, enum CA_SLOT_TYPE SlotType = CA_SLOT_TYPE_ALL,
unsigned char scrambled = 0, ca_map_t camap = std::set<int>(), int mode = 0, bool enabled = false); unsigned char scrambled = 0, ca_map_t camap = std::set<int>(), int mode = 0, bool enabled = false);
/// sh4 unused
bool StopRecordCI( u64 TP, u16 SID, u8 source, u32 calen);
bool StopLiveCI( u64 TP, u16 SID, u8 source, u32 calen);
SlotIt FindFreeSlot(u64 tpid, u8 source, u16 sid, ca_map_t camap, unsigned char scrambled);
SlotIt GetSlot(unsigned int slot);
bool SendDateTime(void); bool SendDateTime(void);
bool SendCaPMT(eDVBCISlot* slot); /// the main loop
void slot_pollthread(void *c); void slot_pollthread(void *c);
void setSource(eDVBCISlot* slot); /// check if current channel uses any ci module
bool checkQueueSize(eDVBCISlot* slot);
void process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int asn_data_length, int con_id);
bool checkChannelID(u64 chanID); bool checkChannelID(u64 chanID);
/// set checking for live-tv use ci to true
void setCheckLiveSlot(int check); void setCheckLiveSlot(int check);
bool SendNullPMT(eDVBCISlot* slot); /// as the name says
bool CheckCerts(void); bool CheckCerts(void);
void Test(int slot, CaIdVector caids);
void DelTest(int slot);
/// Virtual destructor /// Virtual destructor
virtual ~cCA(); virtual ~cCA();
}; };

View File

@@ -131,6 +131,11 @@ void cPlayback::SetTitle(int /*title*/)
{ {
} }
uint64_t cPlayback::GetReadCount(void)
{
return 0;
}
cPlayback::cPlayback(int /*num*/) cPlayback::cPlayback(int /*num*/)
{ {
printf("%s:%s\n", FILENAME, __func__); printf("%s:%s\n", FILENAME, __func__);

View File

@@ -40,7 +40,7 @@ inline void cs_api_exit()
#define cs_free_uncached free #define cs_free_uncached free
// Callback function helpers // Callback function helpers
static inline void cs_register_messenger(cs_messenger) { return; }; void cs_register_messenger(cs_messenger messenger);
static inline void cs_deregister_messenger(void) { return; }; static inline void cs_deregister_messenger(void) { return; };
//cs_messenger cs_get_messenger(void); //cs_messenger cs_get_messenger(void);

View File

@@ -29,7 +29,7 @@ hw_caps_t *get_hwcaps(void)
memset(&caps, 0, sizeof(hw_caps_t)); memset(&caps, 0, sizeof(hw_caps_t));
initialized = 1; initialized = 1;
caps.has_CI = 0; caps.has_CI = 1;
caps.can_cec = 1; caps.can_cec = 1;
caps.can_shutdown = 1; caps.can_shutdown = 1;
caps.display_xres = 16; caps.display_xres = 16;

View File

@@ -3,25 +3,106 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <string.h>
#include <linux/dvb/ca.h> #include <linux/dvb/ca.h>
#include "misc.h" #include "misc.h"
#include "descrambler.h" #include "descrambler.h"
#include <config.h>
static const char * FILENAME = "[descrambler]"; static const char * FILENAME = "[descrambler]";
static const char *descrambler_filename = "/dev/dvb/adapter0/ca3";
static int desc_fd = -1; static int desc_fd = -1;
static int desc_user_count = 0; static int desc_user_count = 0;
#if HAVE_ARM_HARDWARE
//static const char *descrambler_filename = "/dev/dvb/adapter0/ca0";
//static const char *descrambler_filename = "/dev/dvb/adapter0/ca1";
static const char *descrambler_filename = "/dev/ciplus_ca0";
enum ca_descr_data_type {
CA_DATA_IV,
CA_DATA_KEY,
};
enum ca_descr_parity {
CA_PARITY_EVEN,
CA_PARITY_ODD,
};
struct ca_descr_data {
unsigned int index;
enum ca_descr_parity parity;
enum ca_descr_data_type data_type;
unsigned int length;
unsigned char *data;
};
#define CA_SET_DESCR_DATA _IOW('o', 137, struct ca_descr_data)
//#define CA_SET_DESCR_DATA _IOW('o', 10, struct ca_descr_data)
int descrambler_set_key(int index, int parity, unsigned char *data)
{
struct ca_descr_data d;
int ret;
printf("%s -> %s %s\n", FILENAME, __FUNCTION__, descrambler_filename);
if (descrambler_open())
{
printf("Complete Data-> Index: (%d) Parity: (%d) -> ", index, parity);
hexdump(data, 32);
d.index = index;
d.parity = (ca_descr_parity)parity;
d.data_type = CA_DATA_KEY;
d.length = 16;
d.data = data;
printf("AES Index: (%d) Parity: (%d) -> ", d.index, d.parity);
hexdump(d.data, 16);
ret = ioctl(desc_fd, CA_SET_DESCR_DATA, &d);
if (ret)
{
printf("CA_SET_DESCR_DATA (AES) index=%d parity=%d (errno=%d %s)\n", index, parity, errno, strerror(errno));
}
d.index = index;
d.parity = (ca_descr_parity)parity;
d.data_type = CA_DATA_IV;
d.length = 16;
d.data = data + 16;
printf("IV Index: (%d) Parity: (%d) -> ", d.index, d.parity);
hexdump(d.data, 16);
ret = ioctl(desc_fd, CA_SET_DESCR_DATA, &d);
if (ret)
{
printf("CA_SET_DESCR_DATA (IV) index=%d parity=%d (errno=%d %s)\n", index, parity, errno, strerror(errno));
}
descrambler_close();
}
return 0;
}
#else
static const char *descrambler_filename = "/dev/dvb/adapter0/ca3";
/* Byte 0 to 15 are AES Key, Byte 16 to 31 are IV */ /* Byte 0 to 15 are AES Key, Byte 16 to 31 are IV */
int descrambler_set_key(int index, int parity, unsigned char *data) int descrambler_set_key(int index, int parity, unsigned char *data)
{ {
struct ca_descr_data d; struct ca_descr_data d;
printf("%s -> %s\n", FILENAME, __FUNCTION__); printf("%s -> %s %s\n", FILENAME, __FUNCTION__, descrambler_filename);
index |= 0x100; index |= 0x100;
@@ -32,37 +113,55 @@ int descrambler_set_key(int index, int parity, unsigned char *data)
d.data_type = CA_DATA_KEY; d.data_type = CA_DATA_KEY;
d.length = 32; d.length = 32;
d.data = data; d.data = data;
#if 0
printf("Index: %d Parity: (%d) -> ", d.index, d.parity);
hexdump(d.data, 32);
#endif
if (ioctl(desc_fd, CA_SET_DESCR_DATA, &d))
{
printf("CA_SET_DESCR_DATA index=%d parity=%d (errno=%d %s)\n", index, parity, errno, strerror(errno));
}
printf("Index: %d Parity: (%d) -> ", d.index, d.parity); printf("Index: %d Parity: (%d) -> ", d.index, d.parity);
hexdump(d.data, 32); hexdump(d.data, 32);
if (ioctl(desc_fd, CA_SET_DESCR_DATA, &d))
{
//printf("CA_SET_DESCR_DATA\n");
}
descrambler_close(); descrambler_close();
} }
return 0; return 0;
} }
#endif
/* we don't use this for sh4 ci cam ! */
/* we don't use this for ci cam ! */
/*
int descrambler_set_pid(int index, int enable, int pid) int descrambler_set_pid(int index, int enable, int pid)
{ {
struct ca_pid p; struct ca_pid p;
#if HAVE_ARM_HARDWARE
unsigned int flags = 0x80;
if (index)
flags |= 0x40;
if (enable) if (enable)
p.index = index; flags |= 0x20;
else
p.index = -1;
p.index = flags;
p.pid = pid; p.pid = pid;
#else
p.index = index;
if (enable)
p.pid = pid;
else
p.pid = -1;
#endif
if (ioctl(desc_fd, CA_SET_PID, &p)) printf("CA_SET_PID pid=0x%04x index=0x%04x\n", p.pid, p.index);
printf("CA_SET_PID\n"); if (ioctl(desc_fd, CA_SET_PID, &p) == -1)
printf("CA_SET_PID pid=0x%04x index=0x%04x (errno=%d %s)\n", p.pid, p.index, errno, strerror(errno));
return 0; return 0;
} }
*/
bool descrambler_open(void) bool descrambler_open(void)
{ {
@@ -74,12 +173,6 @@ bool descrambler_open(void)
return true; return true;
} }
void descrambler_close(void)
{
close(desc_fd);
desc_fd = -1;
}
int descrambler_init(void) int descrambler_init(void)
{ {
desc_user_count++; desc_user_count++;
@@ -87,6 +180,12 @@ int descrambler_init(void)
return 0; return 0;
} }
void descrambler_close(void)
{
close(desc_fd);
desc_fd = -1;
}
void descrambler_deinit(void) void descrambler_deinit(void)
{ {
desc_user_count--; desc_user_count--;

View File

@@ -6,7 +6,7 @@ void descrambler_deinit(void);
bool descrambler_open(void); bool descrambler_open(void);
void descrambler_close(void); void descrambler_close(void);
int descrambler_set_key(int index, int parity, unsigned char *data); int descrambler_set_key(int index, int parity, unsigned char *data);
/* we don't use this for ci cam ! */ /* we don't use this for sh4 ci cam ! */
//int descrambler_set_pid(int index, int enable, int pid); int descrambler_set_pid(int index, int enable, int pid);
#endif #endif

View File

@@ -1347,6 +1347,38 @@ void eDVBCIContentControlManagerSession::resendKey(eDVBCISlot *tslot)
*/ */
if (!tslot->SidBlackListed && (tslot->recordUse[0] || tslot->liveUse[0])) if (!tslot->SidBlackListed && (tslot->recordUse[0] || tslot->liveUse[0]))
{
#if HAVE_ARM_HARDWARE
if (slot->newPids)
{
if (slot->pids.size())
{
if (descrambler_open())
{
for (unsigned int i = 0; i < slot->pids.size(); i++)
descrambler_set_pid((int)tslot->slot, 1, (int) slot->pids[i]);
descrambler_close();
}
}
slot->newPids = false;
}
descrambler_set_key((int)tslot->slot, tslot->lastParity, tslot->lastKey);
#else
if (slot->newPids)
{
if (slot->pids.size())
{
if (descrambler_open())
{
for (unsigned int i = 0; i < slot->pids.size(); i++)
descrambler_set_pid((int)tslot->slot, 1, (int) slot->pids[i]);
descrambler_close();
}
}
slot->newPids = false;
}
descrambler_set_key((int)tslot->source, tslot->lastParity, tslot->lastKey); descrambler_set_key((int)tslot->source, tslot->lastParity, tslot->lastKey);
#endif
}
} }

View File

@@ -5,9 +5,9 @@
#define SLMS 256 #define SLMS 256
#define ROOT_CERT "/etc/pem/root.pem" #define ROOT_CERT "/etc/ssl/certs/root.pem"
#define CUSTOMER_CERT "/etc/pem/customer.pem" #define CUSTOMER_CERT "/etc/ssl/certs/customer.pem"
#define DEVICE_CERT "/etc/pem/device.pem" #define DEVICE_CERT "/etc/ssl/certs/device.pem"
class eDVBCISession class eDVBCISession
{ {