diff --git a/common/ca_ci.cpp b/common/ca_ci.cpp index 9f8cd3c..0ef216f 100644 --- a/common/ca_ci.cpp +++ b/common/ca_ci.cpp @@ -57,7 +57,7 @@ void cs_register_messenger(cs_messenger messenger) return; } -bool cCA::checkQueueSize(tSlot* slot) +bool cCA::checkQueueSize(eDVBCISlot* slot) { return (slot->sendqueue.size() > 0); } @@ -100,14 +100,15 @@ void cCA::DelTest(int slot) /* helper function to call the cpp thread loop */ void* execute_thread(void *c) { - tSlot* slot = (tSlot*) c; + eDVBCISlot* slot = (eDVBCISlot*) c; cCA *obj = (cCA*)slot->pClass; obj->slot_pollthread(c); return NULL; } /* from dvb-apps */ -int asn_1_decode(uint16_t * length, unsigned char * asn_1_array, uint32_t asn_1_array_len) +int asn_1_decode(uint16_t * length, unsigned char * asn_1_array, + uint32_t asn_1_array_len) { uint8_t length_field; @@ -183,7 +184,7 @@ eData waitData(int fd, unsigned char* buffer, int* len) return eDataError; } -static bool transmitData(tSlot* slot, unsigned char* d, int len) +static bool transmitData(eDVBCISlot* slot, unsigned char* d, int len) { printf("%s -> %s len(%d)\n", FILENAME, __func__, len); @@ -207,7 +208,7 @@ static bool transmitData(tSlot* slot, unsigned char* d, int len) return true; } -static bool sendDataLast(tSlot* slot) +static bool sendDataLast(eDVBCISlot* slot) { unsigned char data[5]; slot->pollConnection = false; @@ -227,7 +228,7 @@ static bool sendDataLast(tSlot* slot) return true; } -static bool sendRCV(tSlot* slot) +static bool sendRCV(eDVBCISlot* slot) { unsigned char send_data[5]; slot->pollConnection = false; @@ -295,7 +296,7 @@ eData sendData(tSlot* slot, unsigned char* data, int len) } //send a transport connection create request -bool sendCreateTC(tSlot* slot) +bool sendCreateTC(eDVBCISlot* slot) { unsigned char data[5]; data[0] = slot->slot; @@ -311,7 +312,7 @@ bool sendCreateTC(tSlot* slot) return true; } -void cCA::process_tpdu(tSlot* slot, unsigned char tpdu_tag, __u8* data, int asn_data_length, int /*con_id*/) +void cCA::process_tpdu(eDVBCISlot* slot, unsigned char tpdu_tag, __u8* data, int asn_data_length, int /*con_id*/) { switch (tpdu_tag) { @@ -432,7 +433,7 @@ void cCA::MenuEnter(enum CA_SLOT_TYPE, uint32_t bSlotIndex) { printf("%s -> %s Slot(%d)\n", FILENAME, __func__, bSlotIndex); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -460,7 +461,7 @@ void cCA::MenuAnswer(enum CA_SLOT_TYPE, uint32_t bSlotIndex, uint32_t choice) { printf("%s -> %s Slot(%d) choice(%d)\n", FILENAME, __func__, bSlotIndex, choice); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -476,7 +477,7 @@ void cCA::InputAnswer(enum CA_SLOT_TYPE, uint32_t bSlotIndex, uint8_t * pBuffer, { printf("%s -> %s Slot(%d)\n", FILENAME, __func__, bSlotIndex); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -493,7 +494,7 @@ void cCA::MenuClose(enum CA_SLOT_TYPE, uint32_t bSlotIndex) { printf("%s -> %s Slot(%d)\n", FILENAME, __func__, bSlotIndex); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -520,7 +521,7 @@ uint32_t cCA::GetNumberSmartCardSlots(void) void cCA::ModuleName(enum CA_SLOT_TYPE, uint32_t slot, char * Name) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { if ((*it)->slot == slot) @@ -533,7 +534,7 @@ void cCA::ModuleName(enum CA_SLOT_TYPE, uint32_t slot, char * Name) bool cCA::ModulePresent(enum CA_SLOT_TYPE, uint32_t slot) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { @@ -550,7 +551,7 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; bool haveFound = false; for (it = slot_data.begin(); it != slot_data.end(); ++it) @@ -566,8 +567,8 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) (*it)->status = eStatusReset; usleep(200000); if ((*it)->hasCCManager) - (*it)->ccmgrSession->ci_ccmgr_doClose((tSlot*)(*it)); - eDVBCISession::deleteSessions((tSlot*)(*it)); + (*it)->ccmgrSession->ci_ccmgr_doClose((eDVBCISlot*)(*it)); + eDVBCISession::deleteSessions((eDVBCISlot*)(*it)); (*it)->mmiSession = NULL; (*it)->hasMMIManager = false; (*it)->hasCAManager = false; @@ -619,7 +620,7 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) int cCA::GetCAIDS(CaIdVector &Caids) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { if ((*it)->camIsReady) @@ -634,7 +635,7 @@ int cCA::GetCAIDS(CaIdVector &Caids) bool cCA::StopLiveCI( u64 TP, u16 SID, u8 source, u32 calen) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { for (int j = 0; j < CI_MAX_MULTI; j++) @@ -652,7 +653,7 @@ bool cCA::StopLiveCI( u64 TP, u16 SID, u8 source, u32 calen) bool cCA::StopRecordCI( u64 TP, u16 SID, u8 source, u32 calen) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) { for (int j = 0; j < CI_MAX_MULTI; j++) @@ -670,7 +671,7 @@ bool cCA::StopRecordCI( u64 TP, u16 SID, u8 source, u32 calen) SlotIt cCA::FindFreeSlot(u64 TP, u8 source, u16 SID, ca_map_t camap, unsigned char scrambled) { printf("%s -> %s\n", FILENAME, __func__); - std::list::iterator it; + std::list::iterator it; ca_map_iterator_t caIt; unsigned int i; int count = 0; @@ -741,7 +742,7 @@ SlotIt cCA::FindFreeSlot(u64 TP, u8 source, u16 SID, ca_map_t camap, unsigned ch { if ((*it)->source == source && (!checkLiveSlot || !liveUse_found)) { - SendNullPMT((tSlot*)(*it)); + SendNullPMT((eDVBCISlot*)(*it)); (*it)->SidBlackListed = true; for (int j = 0; j < CI_MAX_MULTI; j++) (*it)->SID[j] = 0; @@ -844,7 +845,7 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, } else { - SendNullPMT((tSlot*)(*It2)); + SendNullPMT((eDVBCISlot*)(*It2)); (*It2)->scrambled = 0; (*It2)->TP = 0; for (int j = 0; j < CI_MAX_MULTI; j++) @@ -911,7 +912,7 @@ bool cCA::SendCAPMT(u64 tpid, u8 source, u8 camask, const unsigned char * cabuf, } if (!(*It)->newCapmt && (*It)->ccmgr_ready && (*It)->hasCCManager && (*It)->scrambled && !(*It)->SidBlackListed) - (*It)->ccmgrSession->resendKey((tSlot*)(*It)); + (*It)->ccmgrSession->resendKey((eDVBCISlot*)(*It)); } else @@ -952,7 +953,7 @@ cCA::cCA(int Slots) { printf("failed to open %s ->%m", filename); } - tSlot* slot = (tSlot*) malloc(sizeof(tSlot)); + eDVBCISlot* slot = (eDVBCISlot*) malloc(sizeof(eDVBCISlot)); slot->slot = i; slot->fd = fd; slot->connection_id = 0; @@ -1034,7 +1035,7 @@ cCA::cCA(void) printf("%s -> %s\n", FILENAME, __func__); } -void cCA::setSource(tSlot* slot) +void cCA::setSource(eDVBCISlot* slot) { char buf[64]; snprintf(buf, 64, "/proc/stb/tsmux/ci%d_input", slot->slot); @@ -1065,7 +1066,7 @@ void cCA::slot_pollthread(void *c) { ca_slot_info_t info; unsigned char data[1024 * 4]; - tSlot* slot = (tSlot*) c; + eDVBCISlot* slot = (eDVBCISlot*) c; while (1) { @@ -1373,7 +1374,7 @@ void cCA::slot_pollthread(void *c) cCA *CA = cCA::GetInstance(); -bool cCA::SendCaPMT(tSlot* slot) +bool cCA::SendCaPMT(eDVBCISlot* slot) { printf("%s -> %s\n", FILENAME, __func__); if ((slot->fd > 0) && (slot->camIsReady)) @@ -1434,14 +1435,14 @@ void cCA::SetInitMask(enum CA_INIT_MASK p) SlotIt cCA::GetSlot(unsigned int slot) { - std::list::iterator it; + std::list::iterator it; for (it = slot_data.begin(); it != slot_data.end(); ++it) if ((*it)->slot == slot && (*it)->init) return it; return it; } -bool cCA::SendNullPMT(tSlot* slot) +bool cCA::SendNullPMT(eDVBCISlot* slot) { printf("%s > %s >**\n", FILENAME, __func__); if ((slot->fd > 0) && (slot->camIsReady) && (slot->hasCAManager)) @@ -1464,7 +1465,7 @@ bool cCA::CheckCerts(void) bool cCA::checkChannelID(u64 chanID) { - std::list::iterator it; + std::list::iterator it; u16 SID = (u16)(chanID & 0xFFFF); u64 TP = chanID >> 16; for (it = slot_data.begin(); it != slot_data.end(); ++it) diff --git a/common/ca_ci.h b/common/ca_ci.h index 83bc24c..c4362f0 100644 --- a/common/ca_ci.h +++ b/common/ca_ci.h @@ -222,11 +222,11 @@ typedef struct /* private data */ void *private_data; -} tSlot; +} eDVBCISlot; -eData sendData(tSlot *slot, unsigned char* data, int len); +eData sendData(eDVBCISlot *slot, unsigned char* data, int len); -typedef std::list::iterator SlotIt; +typedef std::list::iterator SlotIt; /// CA module class class cCA { @@ -242,7 +242,7 @@ private: bool init; void SendPMT(); pthread_mutex_t ciMutex; - std::list slot_data; + std::list slot_data; pthread_t slot_thread; public: @@ -296,15 +296,15 @@ public: SlotIt FindFreeSlot(u64 tpid, u8 source, u16 sid, ca_map_t camap, unsigned char scrambled); SlotIt GetSlot(unsigned int slot); bool SendDateTime(void); - bool SendCaPMT(tSlot* slot); + bool SendCaPMT(eDVBCISlot* slot); void slot_pollthread(void *c); - void setSource(tSlot* slot); - bool checkQueueSize(tSlot* slot); - void process_tpdu(tSlot* slot, unsigned char tpdu_tag, __u8* data, int asn_data_length, int con_id); + void setSource(eDVBCISlot* slot); + 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); void setCheckLiveSlot(int check); - bool SendNullPMT(tSlot* slot); + bool SendNullPMT(eDVBCISlot* slot); bool CheckCerts(void); void Test(int slot, CaIdVector caids); void DelTest(int slot); diff --git a/libdvbci/dvbci_appmgr.cpp b/libdvbci/dvbci_appmgr.cpp index b0f83bd..de95912 100644 --- a/libdvbci/dvbci_appmgr.cpp +++ b/libdvbci/dvbci_appmgr.cpp @@ -7,11 +7,9 @@ #include "dvbci_appmgr.h" /* prevent possibly segfaults: read at end of this file */ -#define yy_debug 0 +#define yy_debug 0 -static const char * FILENAME = "[dvbci_appmgr]"; - -eDVBCIApplicationManagerSession::eDVBCIApplicationManagerSession(tSlot *tslot) +eDVBCIApplicationManagerSession::eDVBCIApplicationManagerSession(eDVBCISlot *tslot) { slot = tslot; slot->hasAppManager = true; @@ -26,7 +24,7 @@ eDVBCIApplicationManagerSession::~eDVBCIApplicationManagerSession() int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag, const void *data, int len) { - printf("SESSION(%d)/APP %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); + printf("[CI AM] SESSION(%d)/APP %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) printf("%02x ", ((const unsigned char*)data)[i]); printf("\n"); @@ -38,16 +36,16 @@ int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag, cons case 0x21: { int dl; - printf("application info:\n"); - printf(" len: %d\n", len); - printf(" application_type: %d\n", ((unsigned char*)data)[0]); - printf(" application_manufacturer: %02x %02x\n", ((unsigned char*)data)[2], ((unsigned char*)data)[1]); - printf(" manufacturer_code: %02x %02x\n", ((unsigned char*)data)[4], ((unsigned char*)data)[3]); + printf("[CI AM] application info:\n"); + printf("[CI AM] len: %d\n", len); + printf("[CI AM] application_type: %d\n", ((unsigned char*)data)[0]); + printf("[CI AM] application_manufacturer: %02x %02x\n", ((unsigned char*)data)[2], ((unsigned char*)data)[1]); + printf("[CI AM] manufacturer_code: %02x %02x\n", ((unsigned char*)data)[4], ((unsigned char*)data)[3]); printf(" menu string: "); dl = ((unsigned char*)data)[5]; if ((dl + 6) > len) { - printf("warning, invalid length (%d vs %d)\n", dl + 6, len); + printf("[CI AM] warning, invalid length (%d vs %d)\n", dl + 6, len); dl = len - 6; } char str[dl + 1]; @@ -60,11 +58,11 @@ int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag, cons strcpy(slot->name, str); if (!strcmp(slot->name, "AlphaCrypt")) slot->multi = true; - printf("%s set cam name %s on slot(%d)\n", FILENAME, slot->name, slot->slot); + printf("[CI AM] set cam name %s on slot(%d)\n", slot->name, slot->slot); break; } default: - printf("%s unknown APDU tag 9F 80 %02x\n", FILENAME, tag[2]); + printf("[CI AM] unknown APDU tag 9F 80 %02x\n", tag[2]); break; } } @@ -77,19 +75,19 @@ int eDVBCIApplicationManagerSession::doAction() { case stateStarted: { - const unsigned char tag[3] = {0x9F, 0x80, 0x20}; + const unsigned char tag[3] = {0x9F, 0x80, 0x20}; // application manager info e sendAPDU(tag); sendAPDU(tag); state = stateFinal; checkBlist(); return 1; } case stateFinal: - printf("%s -> in final state\n", FILENAME); + printf("[CI AM] in final state."); wantmenu = 0; if (wantmenu) { - printf("%s wantmenu: sending Tenter_menu\n", FILENAME); - const unsigned char tag[3] = {0x9F, 0x80, 0x22}; + printf("[CI AM] wantmenu: sending Tenter_menu"); + const unsigned char tag[3] = {0x9F, 0x80, 0x22}; // Tenter_menu sendAPDU(tag); wantmenu = 0; return 0; @@ -103,8 +101,8 @@ int eDVBCIApplicationManagerSession::doAction() int eDVBCIApplicationManagerSession::startMMI() { - printf("%s -> %s\n", FILENAME, __func__); - const unsigned char tag[3] = {0x9F, 0x80, 0x22}; + printf("[CI AM] in appmanager -> startmmi()"); + const unsigned char tag[3] = {0x9F, 0x80, 0x22}; // Tenter_menu sendAPDU(tag); slot->mmiOpened = true; return 0; diff --git a/libdvbci/dvbci_appmgr.h b/libdvbci/dvbci_appmgr.h index 3eb212e..0f7d04d 100644 --- a/libdvbci/dvbci_appmgr.h +++ b/libdvbci/dvbci_appmgr.h @@ -9,7 +9,7 @@ class eDVBCIApplicationManagerSession: public eDVBCISession stateFinal=statePrivate }; - tSlot *slot; + eDVBCISlot *slot; int wantmenu; int receivedAPDU(const unsigned char *tag, const void *data, int len); @@ -17,7 +17,7 @@ class eDVBCIApplicationManagerSession: public eDVBCISession bool readBlist(); int checkBlist(); public: - eDVBCIApplicationManagerSession(tSlot *tslot); + eDVBCIApplicationManagerSession(eDVBCISlot *tslot); ~eDVBCIApplicationManagerSession(); int enterMenu(); int startMMI(); diff --git a/libdvbci/dvbci_camgr.cpp b/libdvbci/dvbci_camgr.cpp index c6fb238..c56ac16 100644 --- a/libdvbci/dvbci_camgr.cpp +++ b/libdvbci/dvbci_camgr.cpp @@ -1,12 +1,11 @@ /* DVB CI CA Manager */ #include #include +#include #include "dvbci_camgr.h" -#include - -eDVBCICAManagerSession::eDVBCICAManagerSession(tSlot *tslot) +eDVBCICAManagerSession::eDVBCICAManagerSession(eDVBCISlot *tslot) { slot = tslot; } @@ -19,7 +18,7 @@ eDVBCICAManagerSession::~eDVBCICAManagerSession() int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *data, int len) { - printf("SESSION(%d)/CA %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); + printf("[CI CA] SESSION(%d)/CA %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) printf("%02x ", ((const unsigned char*)data)[i]); printf("\n"); @@ -30,7 +29,7 @@ int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *d { case 0x31: { - printf("ca info:\n"); + printf("[CI CA] ca info:\n"); for (int i = 0; i < len; i += 2) { printf("%04x ", (((const unsigned char*)data)[i] << 8) | (((const unsigned char*)data)[i + 1])); @@ -51,7 +50,7 @@ int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *d } break; default: - printf("unknown APDU tag 9F 80 %02x\n", tag[2]); + printf("[CI CA] unknown APDU tag 9F 80 %02x\n", tag[2]); break; } } @@ -70,7 +69,7 @@ int eDVBCICAManagerSession::doAction() return 0; } case stateFinal: - printf("stateFinal und action! kann doch garnicht sein ;)\n"); + printf("[CI CA] stateFinal and action should not happen\n"); default: return 0; } diff --git a/libdvbci/dvbci_camgr.h b/libdvbci/dvbci_camgr.h index 44c9f98..647057a 100644 --- a/libdvbci/dvbci_camgr.h +++ b/libdvbci/dvbci_camgr.h @@ -14,7 +14,7 @@ class eDVBCICAManagerSession: public eDVBCISession int receivedAPDU(const unsigned char *tag, const void *data, int len); int doAction(); public: - eDVBCICAManagerSession(tSlot *tslot); + eDVBCICAManagerSession(eDVBCISlot *tslot); ~eDVBCICAManagerSession(); const std::vector &getCAIDs() const { return caids; } diff --git a/libdvbci/dvbci_ccmgr.cpp b/libdvbci/dvbci_ccmgr.cpp index 459e000..6dcbefe 100644 --- a/libdvbci/dvbci_ccmgr.cpp +++ b/libdvbci/dvbci_ccmgr.cpp @@ -333,7 +333,7 @@ struct element { struct cc_ctrl_data { /* parent */ //struct ci_session *session; - tSlot *slot; + eDVBCISlot *slot; /* ci+ credentials */ struct element elements[MAX_ELEMENTS]; @@ -1039,7 +1039,7 @@ static int data_req_loop(struct cc_ctrl_data *cc_data, unsigned char *dest, cons return pos; } -bool eDVBCIContentControlManagerSession::data_initialize(tSlot *tslot) +bool eDVBCIContentControlManagerSession::data_initialize(eDVBCISlot *tslot) { struct cc_ctrl_data *data; uint8_t buf[32], host_id[8]; @@ -1093,7 +1093,7 @@ bool eDVBCIContentControlManagerSession::data_initialize(tSlot *tslot) return true; } -void eDVBCIContentControlManagerSession::ci_ccmgr_cc_open_cnf(tSlot *tslot) +void eDVBCIContentControlManagerSession::ci_ccmgr_cc_open_cnf(eDVBCISlot *tslot) { const uint8_t tag[3] = { 0x9f, 0x90, 0x02 }; const uint8_t bitmap = 0x01; @@ -1104,7 +1104,7 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_cc_open_cnf(tSlot *tslot) sendAPDU(tag, &bitmap, 1); } -bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(tSlot *tslot, const uint8_t *data, unsigned int len) +bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len) { struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data); uint8_t cc_data_cnf_tag[3] = { 0x9f, 0x90, 0x04 }; @@ -1147,7 +1147,7 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_data_req(tSlot *tslot, cons return true; } -void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_sync_req(tSlot *tslot, const uint8_t *data, unsigned int +void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int #if y_debug len #endif @@ -1183,7 +1183,7 @@ void eDVBCIContentControlManagerSession::ci_ccmgr_cc_sync_req() sendAPDU(tag, &sync_req_status, 1); } -bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(tSlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos) +bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos) { struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data); printf("%s -> %s (%02X%02X%02X) \n", FILENAME, __FUNCTION__, tag[0], tag[1], tag[2]); @@ -1207,7 +1207,7 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_send(tSlot *tslot, cons return true; } -bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(tSlot *tslot, const uint8_t *data, unsigned int len) +bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len) { struct cc_ctrl_data *cc_data = (struct cc_ctrl_data*)(tslot->private_data); const uint8_t data_cnf_tag[3] = { 0x9f, 0x90, 0x08 }; @@ -1270,7 +1270,7 @@ bool eDVBCIContentControlManagerSession::ci_ccmgr_cc_sac_data_req(tSlot *tslot, return ci_ccmgr_cc_sac_send(tslot, data_cnf_tag, dest, pos); } -eDVBCIContentControlManagerSession::eDVBCIContentControlManagerSession(tSlot *tslot) +eDVBCIContentControlManagerSession::eDVBCIContentControlManagerSession(eDVBCISlot *tslot) { slot = tslot; slot->hasCCManager = true; @@ -1284,7 +1284,7 @@ eDVBCIContentControlManagerSession::~eDVBCIContentControlManagerSession() slot->ccmgrSession = NULL; } -void eDVBCIContentControlManagerSession::ci_ccmgr_doClose(tSlot *tslot) +void eDVBCIContentControlManagerSession::ci_ccmgr_doClose(eDVBCISlot *tslot) { struct cc_ctrl_data *data = (struct cc_ctrl_data*)(tslot->private_data); printf("%s -> %s\n", FILENAME, __FUNCTION__); @@ -1339,12 +1339,13 @@ int eDVBCIContentControlManagerSession::doAction() } } -void eDVBCIContentControlManagerSession::resendKey(tSlot *tslot) +void eDVBCIContentControlManagerSession::resendKey(eDVBCISlot *tslot) { /* Fix me ! no ci* cam with multi decrypt is known * therefore for now it is OK to use element [0] - * in bool arrays */ - + * in bool arrays + */ + if (!tslot->SidBlackListed && (tslot->recordUse[0] || tslot->liveUse[0])) descrambler_set_key((int)tslot->source, tslot->lastParity, tslot->lastKey); } diff --git a/libdvbci/dvbci_ccmgr.h b/libdvbci/dvbci_ccmgr.h index 7f97231..a9046ee 100644 --- a/libdvbci/dvbci_ccmgr.h +++ b/libdvbci/dvbci_ccmgr.h @@ -5,13 +5,13 @@ class eDVBCIContentControlManagerSession: public eDVBCISession { - bool data_initialize(tSlot *tslot); - bool ci_ccmgr_cc_data_req(tSlot *tslot, const uint8_t *data, unsigned int len); - bool ci_ccmgr_cc_sac_data_req(tSlot *tslot, const uint8_t *data, unsigned int len); - bool ci_ccmgr_cc_sac_send(tSlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos); - void ci_ccmgr_cc_sac_sync_req(tSlot *tslot, const uint8_t *data, unsigned int len); + bool data_initialize(eDVBCISlot *tslot); + bool ci_ccmgr_cc_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); + bool ci_ccmgr_cc_sac_data_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); + bool ci_ccmgr_cc_sac_send(eDVBCISlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos); + void ci_ccmgr_cc_sac_sync_req(eDVBCISlot *tslot, const uint8_t *data, unsigned int len); void ci_ccmgr_cc_sync_req(); - void ci_ccmgr_cc_open_cnf(tSlot *slot); + void ci_ccmgr_cc_open_cnf(eDVBCISlot *slot); enum { stateFinal=statePrivate @@ -19,9 +19,9 @@ class eDVBCIContentControlManagerSession: public eDVBCISession int receivedAPDU(const unsigned char *tag, const void *data, int len); int doAction(); public: - eDVBCIContentControlManagerSession(tSlot *tslot); + eDVBCIContentControlManagerSession(eDVBCISlot *tslot); ~eDVBCIContentControlManagerSession(); - void ci_ccmgr_doClose(tSlot *tslot); - void resendKey(tSlot *tslot); + void ci_ccmgr_doClose(eDVBCISlot *tslot); + void resendKey(eDVBCISlot *tslot); }; #endif diff --git a/libdvbci/dvbci_datetimemgr.cpp b/libdvbci/dvbci_datetimemgr.cpp index d5bda41..89106f7 100644 --- a/libdvbci/dvbci_datetimemgr.cpp +++ b/libdvbci/dvbci_datetimemgr.cpp @@ -6,9 +6,7 @@ #include "dvbci_datetimemgr.h" -static const char * FILENAME = "[dvbci_datetimemgr]"; - -eDVBCIDateTimeSession::eDVBCIDateTimeSession(tSlot *tslot) +eDVBCIDateTimeSession::eDVBCIDateTimeSession(eDVBCISlot *tslot) { slot = tslot; slot->hasDateTime = true; @@ -22,7 +20,7 @@ eDVBCIDateTimeSession::~eDVBCIDateTimeSession() int eDVBCIDateTimeSession::receivedAPDU(const unsigned char *tag, const void *data, int len) { - printf("SESSION(%d)/DATETIME %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); + printf("[CI DT] SESSION(%d)/DATETIME %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) printf("%02x ", ((const unsigned char*)data)[i]); printf("\n"); @@ -36,7 +34,7 @@ int eDVBCIDateTimeSession::receivedAPDU(const unsigned char *tag, const void *da return 1; break; default: - printf("unknown APDU tag 9F 84 %02x\n", tag[2]); + printf("[CI DT] unknown APDU tag 9F 84 %02x\n", tag[2]); break; } } diff --git a/libdvbci/dvbci_datetimemgr.h b/libdvbci/dvbci_datetimemgr.h index 3cb12a2..49f7dfb 100644 --- a/libdvbci/dvbci_datetimemgr.h +++ b/libdvbci/dvbci_datetimemgr.h @@ -11,7 +11,7 @@ class eDVBCIDateTimeSession: public eDVBCISession int receivedAPDU(const unsigned char *tag, const void *data, int len); int doAction(); public: - eDVBCIDateTimeSession(tSlot *tslot); + eDVBCIDateTimeSession(eDVBCISlot *tslot); ~eDVBCIDateTimeSession(); }; diff --git a/libdvbci/dvbci_mmi.cpp b/libdvbci/dvbci_mmi.cpp index 94d5b06..5ca766b 100644 --- a/libdvbci/dvbci_mmi.cpp +++ b/libdvbci/dvbci_mmi.cpp @@ -7,11 +7,8 @@ #include "dvbci_mmi.h" #include -static const char * FILENAME = "[dvbci_mmi]"; - -eDVBCIMMISession::eDVBCIMMISession(tSlot *tslot) +eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot) { - printf("%s -> %s\n", FILENAME, __func__); slot = tslot; slot->hasMMIManager = true; slot->mmiSession = this; @@ -35,7 +32,7 @@ eDVBCIMMISession::~eDVBCIMMISession() int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len) { - printf("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); + printf("[CI MMI] SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]); for (int i = 0; i < len; i++) printf("%02x ", ((const unsigned char*)data)[i]); printf("\n"); @@ -235,7 +232,7 @@ int eDVBCIMMISession::doAction() int eDVBCIMMISession::stopMMI() { - printf("%s -> %s\n", FILENAME, __func__); + printf("[CI MMI] eDVBCIMMISession::stopMMI()\n"); unsigned char tag[] = {0x9f, 0x88, 0x00}; unsigned char data[] = {0x00}; @@ -247,7 +244,7 @@ int eDVBCIMMISession::stopMMI() int eDVBCIMMISession::answerText(int answer) { - printf("%s -> %s(%d)\n", FILENAME, __func__, answer); + printf("[CI MMI] eDVBCIMMISession::answerText(%d)\n",answer); unsigned char tag[] = {0x9f, 0x88, 0x0B}; unsigned char data[] = {0x00}; @@ -257,9 +254,9 @@ int eDVBCIMMISession::answerText(int answer) return 0; } -int eDVBCIMMISession::answerEnq(char * answer, int len) +int eDVBCIMMISession::answerEnq(char *answer, int len) { - printf("%s -> %s(%d bytes)\n", FILENAME, __func__, len); + printf("[CI MMI] eDVBCIMMISession::answerEnq(%d bytes)\n", len); unsigned char data[len + 1]; data[0] = 0x01; // answer ok @@ -273,7 +270,7 @@ int eDVBCIMMISession::answerEnq(char * answer, int len) int eDVBCIMMISession::cancelEnq() { - printf("%s -> %s\n", FILENAME, __func__); + printf("[CI MMI] eDVBCIMMISession::cancelEnq()\n"); unsigned char tag[] = {0x9f, 0x88, 0x08}; unsigned char data[] = {0x00}; // canceled diff --git a/libdvbci/dvbci_mmi.h b/libdvbci/dvbci_mmi.h index 9132697..25501c2 100644 --- a/libdvbci/dvbci_mmi.h +++ b/libdvbci/dvbci_mmi.h @@ -11,9 +11,9 @@ class eDVBCIMMISession: public eDVBCISession int receivedAPDU(const unsigned char *tag, const void *data, int len); int doAction(); - tSlot *slot; + eDVBCISlot *slot; public: - eDVBCIMMISession(tSlot *tslot); + eDVBCIMMISession(eDVBCISlot *tslot); ~eDVBCIMMISession(); int stopMMI(); int answerText(int answer); diff --git a/libdvbci/dvbci_resmgr.cpp b/libdvbci/dvbci_resmgr.cpp index 747c3e7..0f6924c 100644 --- a/libdvbci/dvbci_resmgr.cpp +++ b/libdvbci/dvbci_resmgr.cpp @@ -1,12 +1,11 @@ /* DVB CI Resource Manager */ + #include #include "dvbci_resmgr.h" -static const char * FILENAME = "[dvbci_resmgr]"; - int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag, const void *data, int len) { - printf("SESSION(%d)RES %02x %02x %02x (len = %d): \n", session_nb, tag[0], tag[1], tag[2], len); + printf("[CI RM] SESSION(%d)RES %02x %02x %02x (len = %d): \n", session_nb, tag[0], tag[1], tag[2], len); if (len) { for (int i = 0; i < len; i++) @@ -18,12 +17,12 @@ int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag, const v switch (tag[2]) { case 0x10: // profile enquiry - printf("%s -> cam asks what I'm able to\n", FILENAME); + printf("[CI RM] cam profile inquiry\n"); state = stateProfileEnquiry; return 1; break; case 0x11: // Tprofile - printf("%s -> my cam can do: ", FILENAME); + printf("[CI RM] -> my cam can do: "); if (!len) printf("nothing"); else @@ -39,9 +38,10 @@ int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag, const v state = stateFinal; break; default: - printf("%s %s unknown APDU tag 9F 80 %02x\n", FILENAME, __FUNCTION__, tag[2]); + printf("[CI RM] unknown APDU tag 9F 80 %02x\n", tag[2]); } } + return 0; } @@ -66,7 +66,7 @@ int eDVBCIResourceManagerSession::doAction() } case stateProfileChange: { - printf("bla kaputt\n"); + printf("[CI RM] cannot deal with statProfileChange\n"); break; } case stateProfileEnquiry: @@ -108,7 +108,7 @@ int eDVBCIResourceManagerSession::doAction() return 0; } case stateFinal: - printf("stateFinal und action! kann doch garnicht sein ;)\n"); + printf("[CI RM] Should not happen: action on stateFinal\n"); default: break; } diff --git a/libdvbci/dvbci_session.cpp b/libdvbci/dvbci_session.cpp index a48e42b..6ba17a4 100644 --- a/libdvbci/dvbci_session.cpp +++ b/libdvbci/dvbci_session.cpp @@ -1,4 +1,5 @@ /* DVB CI Transport Connection */ + #include #include #include @@ -11,8 +12,6 @@ #include "dvbci_mmi.h" #include "dvbci_ccmgr.h" -static const char * FILENAME = "[dvbci_session]"; - eDVBCISession* eDVBCISession::sessions[SLMS]; int eDVBCISession::buildLengthField(unsigned char *pkt, int len) @@ -94,10 +93,11 @@ void eDVBCISession::sendSPDU(tSlot *slot, unsigned char tag, const void *data, i sendData(slot, pkt, ptr - pkt); } -void eDVBCISession::sendOpenSessionResponse(tSlot *slot, unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb) +void eDVBCISession::sendOpenSessionResponse(eDVBCISlot *slot, unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb) { char pkt[6]; pkt[0] = session_status; + printf("[CI SESS] sendOpenSessionResponse"); memcpy(pkt + 1, resource_identifier, 4); sendSPDU(slot, 0x92, pkt, 5, session_nb); } @@ -107,7 +107,7 @@ void eDVBCISession::recvCreateSessionResponse(const unsigned char *data) status = data[0]; state = stateStarted; action = 1; - printf("%s -> %s status(%x)\n", FILENAME, __func__, status); + printf("[CI SESS] create Session Response, status %x\n", status); } void eDVBCISession::recvCloseSessionRequest(const unsigned char *data) @@ -115,13 +115,11 @@ void eDVBCISession::recvCloseSessionRequest(const unsigned char *data) status = data[0]; state = stateInDeletion; action = 1; - printf("%s -> %s\n", FILENAME, __func__); + printf("[CI SESS] close Session Request\n"); } -void eDVBCISession::deleteSessions(const tSlot *slot) +void eDVBCISession::deleteSessions(const eDVBCISlot *slot) { - printf("%s -> %s\n", FILENAME, __func__); - for (unsigned short session_nb = 0; session_nb < SLMS; ++session_nb) { if (sessions[session_nb] && sessions[session_nb]->slot == slot) @@ -129,18 +127,16 @@ void eDVBCISession::deleteSessions(const tSlot *slot) } } -eDVBCISession* eDVBCISession::createSession(tSlot *slot, const unsigned char *resource_identifier, unsigned char &status) +eDVBCISession* eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status) { unsigned long tag; unsigned short session_nb; - printf("%s -> %s\n", FILENAME, __func__); - for (session_nb = 1; session_nb < SLMS; ++session_nb) if (!sessions[session_nb - 1]) break; - printf("%s -> use session_nb = %d\n", FILENAME, session_nb); + printf("[CI SESS] -> use session_nb = %d\n", session_nb); if (session_nb == SLMS) { status = 0xF3; @@ -152,56 +148,56 @@ eDVBCISession* eDVBCISession::createSession(tSlot *slot, const unsigned char *re tag |= resource_identifier[2] << 8; tag |= resource_identifier[3]; - printf("Tag: %08lx > ", tag); + printf("[CI SESS] Tag: %08lx > ", tag); switch (tag) { case 0x00010041: sessions[session_nb - 1] = new eDVBCIResourceManagerSession; - printf("RESOURCE MANAGER\n"); + printf("[CI SESS] RESOURCE MANAGER\n"); break; case 0x00020041: case 0x00020043: sessions[session_nb - 1] = new eDVBCIApplicationManagerSession(slot); - printf("APPLICATION MANAGER\n"); + printf("[CI SESS] APPLICATION MANAGER\n"); break; case 0x00030041: sessions[session_nb - 1] = new eDVBCICAManagerSession(slot); - printf("CA MANAGER\n"); + printf("[CI SESS] CA MANAGER\n"); break; case 0x00240041: sessions[session_nb - 1] = new eDVBCIDateTimeSession(slot); - printf("DATE-TIME\n"); + printf("[CI SESS] DATE-TIME\n"); break; case 0x00400041: - printf("MMI\n"); sessions[session_nb - 1] = new eDVBCIMMISession(slot); + printf("[CI SESS] MMI - create session\n"); break; if (cCA::GetInstance()->CheckCerts()) { case 0x008c1001: - printf("CC MANAGER\n"); + printf("[CI SESS] CC MANAGER\n"); sessions[session_nb - 1] = new eDVBCIContentControlManagerSession(slot); break; } case 0x00100041: // session=new eDVBCIAuthSession; - printf("AuthSession\n"); + printf("[CI SESS] AuthSession\n"); // break; case 0x00200041: default: - printf("unknown resource type %02x %02x %02x %02x\n", resource_identifier[0], resource_identifier[1], resource_identifier[2], resource_identifier[3]); + printf("[CI SESS] unknown resource type %02x %02x %02x %02x\n", resource_identifier[0], resource_identifier[1], resource_identifier[2], resource_identifier[3]); sessions[session_nb - 1] = 0; status = 0xF0; } if (!sessions[session_nb - 1]) { - printf("unknown session.. expect crash\n"); + printf("[CI SESS] unknown session.. expect crash\n"); return NULL; } - printf("%s -> new session nb %d %p\n", FILENAME, session_nb, sessions[session_nb - 1]); + printf("[CI SESS] new session nb %d %p\n", session_nb, sessions[session_nb - 1]); sessions[session_nb - 1]->session_nb = session_nb; if (sessions[session_nb - 1]) @@ -215,7 +211,7 @@ eDVBCISession* eDVBCISession::createSession(tSlot *slot, const unsigned char *re void eDVBCISession::handleClose() { - printf("%s %s\n", FILENAME, __FUNCTION__); + printf("%s\n", __FUNCTION__); unsigned char data[1] = {0x00}; sendSPDU(0x96, data, 1, 0, 0); @@ -228,6 +224,7 @@ int eDVBCISession::pollAll() if (sessions[session_nb - 1]) { int r; + if (sessions[session_nb - 1]->state == stateInDeletion) { sessions[session_nb - 1]->handleClose(); @@ -246,22 +243,23 @@ int eDVBCISession::pollAll() return 0; } -void eDVBCISession::receiveData(tSlot *slot, const unsigned char *ptr, size_t len) +void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len) { - printf("%s -> %s\n",FILENAME, __FUNCTION__); -#if 0 - for(unsigned int i = 0; i < len; i++) - printf("%02x ", ptr[i]); - printf("\n"); -#endif if ((ptr[0] == 0x90 || ptr[0] == 0x95) && (ptr[3] == 0 )) { - printf("****Mist: %02x %02x %02x %02x\n", ptr[0], ptr[1], ptr[2], ptr[3]); + printf("[CI SESS] ****Mist: %02x %02x %02x %02x\n", ptr[0], ptr[1], ptr[2], ptr[3]); } const unsigned char *pkt = (const unsigned char*)ptr; unsigned char tag = *pkt++; int llen, hlen; + printf("[CI SESS] slot: %p",slot); + +#if 0 + for(unsigned int i = 0; i < len; i++) + printf("%02x ", ptr[i]); + printf("\n"); +#endif llen = parseLengthField(pkt, hlen); pkt += llen; @@ -290,14 +288,14 @@ void eDVBCISession::receiveData(tSlot *slot, const unsigned char *ptr, size_t le if ((!session_nb) || (session_nb >= SLMS)) { - printf("PROTOCOL: illegal session number %x\n", session_nb); + printf("[CI SESS] PROTOCOL: illegal session number %x\n", session_nb); return; } session = sessions[session_nb - 1]; if (!session) { - printf("PROTOCOL: data on closed session %x\n", session_nb); + printf("[CI SESS] PROTOCOL: data on closed session %x\n", session_nb); return; } @@ -309,10 +307,11 @@ void eDVBCISession::receiveData(tSlot *slot, const unsigned char *ptr, size_t le session->recvCreateSessionResponse(pkt); break; case 0x95: + printf("[CI SESS] recvCloseSessionRequest"); session->recvCloseSessionRequest(pkt); break; default: - printf("INTERNAL: nyi, tag %02x.\n", tag); + printf("[CI SESS] INTERNAL: nyi, tag %02x.\n", tag); return; } } @@ -324,7 +323,6 @@ void eDVBCISession::receiveData(tSlot *slot, const unsigned char *ptr, size_t le if (session) { - //printf("len %d\n", len); while (len > 0) { int alen; @@ -339,7 +337,7 @@ void eDVBCISession::receiveData(tSlot *slot, const unsigned char *ptr, size_t le if (((len - alen) > 0) && ((len - alen) < 3)) { - printf("WORKAROUND: applying work around MagicAPDULength\n"); + printf("[CI SESS] WORKAROUND: applying work around MagicAPDULength\n"); alen = len; } @@ -352,7 +350,7 @@ void eDVBCISession::receiveData(tSlot *slot, const unsigned char *ptr, size_t le } } if (len) - printf("PROTOCOL: warning, TL-Data has invalid length\n"); + printf("[CI SESS] PROTOCOL: warning, TL-Data has invalid length\n"); } eDVBCISession::~eDVBCISession() diff --git a/libdvbci/dvbci_session.h b/libdvbci/dvbci_session.h index 1687181..f1dd3c2 100644 --- a/libdvbci/dvbci_session.h +++ b/libdvbci/dvbci_session.h @@ -12,16 +12,16 @@ class eDVBCISession { static eDVBCISession* sessions[SLMS]; - static eDVBCISession* createSession(tSlot *slot, const unsigned char *resource_identifier, unsigned char &status); - static void sendSPDU(tSlot *slot, unsigned char tag,const void *data, int len, unsigned short session_nb, const void *apdu = 0, int alen = 0); - static void sendOpenSessionResponse(tSlot *slot,unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb); + static eDVBCISession* createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status); + static void sendSPDU(eDVBCISlot *slot, unsigned char tag,const void *data, int len, unsigned short session_nb, const void *apdu = 0, int alen = 0); + static void sendOpenSessionResponse(eDVBCISlot *slot,unsigned char session_status, const unsigned char *resource_identifier, unsigned short session_nb); void recvCreateSessionResponse(const unsigned char *data); void recvCloseSessionRequest(const unsigned char *data); protected: int state; int status; int action; - tSlot *slot; + eDVBCISlot *slot; unsigned short session_nb; virtual int receivedAPDU(const unsigned char *tag, const void *data, int len) = 0; void sendAPDU(const unsigned char *tag, const void *data=0,int len=0); @@ -30,7 +30,7 @@ protected: public: virtual ~eDVBCISession(); - static void deleteSessions(const tSlot *slot); + static void deleteSessions(const eDVBCISlot *slot); void sendSPDU(unsigned char tag, const void *data, int len, const void *apdu = 0, int alen = 0); int poll() { if (action) { action=doAction(); return 1; } return 0; } @@ -39,7 +39,7 @@ public: static int parseLengthField(const unsigned char *pkt, int &len); static int buildLengthField(unsigned char *pkt, int len); - static void receiveData(tSlot *slot, const unsigned char *ptr, size_t len); + static void receiveData(eDVBCISlot *slot, const unsigned char *ptr, size_t len); int getState() { return state; } int getStatus() { return status; }