From 982a650789b1e8d67b56e752ad9f385375058f07 Mon Sep 17 00:00:00 2001 From: max_10 Date: Sun, 15 Nov 2015 20:29:20 +0100 Subject: [PATCH] test c** Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/ca27972f165ad7351d47ab8dd05c294fd790b09d Author: max_10 Date: 2015-11-15 (Sun, 15 Nov 2015) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- common/ca_ci.cpp | 18 ++++++++++--- common/ca_ci.h | 4 +++ libdvbci/dvbci_appmgr.cpp | 56 +++++++++++++++++++++++++++++++++++++++ libdvbci/dvbci_appmgr.h | 2 ++ libdvbci/dvbci_ccmgr.cpp | 3 ++- 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/common/ca_ci.cpp b/common/ca_ci.cpp index a823bdc..e8c26bb 100644 --- a/common/ca_ci.cpp +++ b/common/ca_ci.cpp @@ -570,6 +570,7 @@ void cCA::ModuleReset(enum CA_SLOT_TYPE, uint32_t slot) (*it)->DataLast = false; (*it)->DataRCV = false; + (*it)->SidBlackListed = false; (*it)->counter = 0; (*it)->init = false; @@ -669,10 +670,13 @@ SlotIt cCA::FindFreeSlot(ca_map_t camap, unsigned char scrambled) /* erstmal den capmt wie er von Neutrino kommt in den Slot puffern */ bool cCA::SendCAPMT(u64 tpid, u8 source_demux, u8 camask, const unsigned char * cabuf, u32 calen, const unsigned char * /*rawpmt*/, u32 /*rawlen*/, enum CA_SLOT_TYPE /*SlotType*/, unsigned char scrambled, ca_map_t cm, int mode, bool enabled) { + u16 SID = (u16)(tpid & 0x000000000000FFFF); + unsigned int i = 0; printf("%s -> %s\n", FILENAME, __func__); if (!num_slots) return true; /* stb's without ci-slots */ #if x_debug printf("TPID: %llX\n", tpid); + printf("SID: %04X\n", SID); printf("SOURCE_DEMUX: %X\n", source_demux); printf("CA_MASK: %X\n", camask); printf("CALEN: %d\n", calen); @@ -700,11 +704,17 @@ bool cCA::SendCAPMT(u64 tpid, u8 source_demux, u8 camask, const unsigned char * (*It)->tpid = tpid; (*It)->source = source_demux; (*It)->pmtlen = calen; - for (unsigned int i = 0; i < calen; i++) + for (i = 0; i < calen; i++) (*It)->pmtdata[i] = cabuf[i]; (*It)->newCapmt = true; } - if (mode && scrambled && enabled) + if ((*It)->bsids.size()) + { + for (i = 0; i < (*It)->bsids.size(); i++) + if ((*It)->bsids[i] == SID) {(*It)->SidBlackListed = true; break;} + if (i == (*It)->bsids.size()) {(*It)->SidBlackListed = false;} + } + if (mode && scrambled && enabled && !(*It)->SidBlackListed) (*It)->inUse = true; } } @@ -774,6 +784,7 @@ cCA::cCA(int Slots) slot->DataLast = false; slot->DataRCV = false; + slot->SidBlackListed = false; slot->counter = 0; slot->init = false; @@ -1068,6 +1079,7 @@ void cCA::slot_pollthread(void *c) slot->DataLast = false; slot->DataRCV = false; + slot->SidBlackListed = false; slot->counter = 0; slot->pollConnection = false; @@ -1138,7 +1150,7 @@ void cCA::slot_pollthread(void *c) /* not necessary: the arrived capmt will be automaticly send */ //SendCaPMT(slot); } - if (slot->hasCAManager && slot->hasAppManager && slot->newCapmt) + if (slot->hasCAManager && slot->hasAppManager && slot->newCapmt && !slot->SidBlackListed) { SendCaPMT(slot); slot->newCapmt = false; diff --git a/common/ca_ci.h b/common/ca_ci.h index 1fe6e66..0739c9f 100644 --- a/common/ca_ci.h +++ b/common/ca_ci.h @@ -103,6 +103,8 @@ typedef struct CA_MESSAGE { typedef std::set ca_map_t; typedef ca_map_t::iterator ca_map_iterator_t; +typedef std::vector bSIDVector; + typedef std::vector CaIdVector; typedef std::vector::iterator CaIdVectorIterator; typedef std::vector::const_iterator CaIdVectorConstIterator; @@ -203,11 +205,13 @@ typedef struct CaIdVector cam_caids; std::priority_queue sendqueue; + bSIDVector bsids; unsigned char lastKey[32]; unsigned char scrambled; u8 lastParity; bool DataLast; bool DataRCV; + bool SidBlackListed; /* private data */ void *private_data; diff --git a/libdvbci/dvbci_appmgr.cpp b/libdvbci/dvbci_appmgr.cpp index 033a1f2..2d316fc 100644 --- a/libdvbci/dvbci_appmgr.cpp +++ b/libdvbci/dvbci_appmgr.cpp @@ -1,6 +1,8 @@ /* DVB CI Application Manager */ #include #include +#include +#include #include "dvbci_appmgr.h" @@ -73,6 +75,7 @@ int eDVBCIApplicationManagerSession::doAction() const unsigned char tag[3] = {0x9F, 0x80, 0x20}; sendAPDU(tag); state = stateFinal; + checkBlist(); return 1; } case stateFinal: @@ -102,3 +105,56 @@ int eDVBCIApplicationManagerSession::startMMI() return 0; } +bool eDVBCIApplicationManagerSession::readBlist() +{ + int rc, i; + char cSid[4] = {0,0,0,0}; + u16 Sid; + FILE *fd; + char blacklist_file[32]; + + sprintf(blacklist_file,"/etc/blacklist_slot_%d",slot->slot); + + if (access(blacklist_file, F_OK) != 0) + return false; + fd = fopen(blacklist_file,"r"); + if (!fd) + return false; + else + { + do + { + for (i = 0; i < 4; i++) + { + rc = fgetc(fd); + if (rc == ',' || rc == EOF) break; + cSid[i] = (char)rc; + } + if (rc == EOF) goto fin; + if (i == 4) + { + Sid = (u16)strtol(cSid, NULL, 16); + slot->bsids.push_back(Sid); + } + } while (rc != EOF); +fin: + fclose(fd); + } + if (slot->bsids.size()) + return true; + else + return false; +} + +int eDVBCIApplicationManagerSession::checkBlist() +{ + if (readBlist()) + { + printf("Blacked sids: %d > ", slot->bsids.size()); + for (unsigned int i = 0; i < slot->bsids.size(); i++) + printf("%04x ", slot->bsids[i]); + printf("\n"); + } + return 0; +} + diff --git a/libdvbci/dvbci_appmgr.h b/libdvbci/dvbci_appmgr.h index f996c6e..3eb212e 100644 --- a/libdvbci/dvbci_appmgr.h +++ b/libdvbci/dvbci_appmgr.h @@ -14,6 +14,8 @@ class eDVBCIApplicationManagerSession: public eDVBCISession int wantmenu; int receivedAPDU(const unsigned char *tag, const void *data, int len); int doAction(); + bool readBlist(); + int checkBlist(); public: eDVBCIApplicationManagerSession(tSlot *tslot); ~eDVBCIApplicationManagerSession(); diff --git a/libdvbci/dvbci_ccmgr.cpp b/libdvbci/dvbci_ccmgr.cpp index 7ddd06c..afc7dd0 100644 --- a/libdvbci/dvbci_ccmgr.cpp +++ b/libdvbci/dvbci_ccmgr.cpp @@ -1327,6 +1327,7 @@ int eDVBCIContentControlManagerSession::doAction() void eDVBCIContentControlManagerSession::resendKey(tSlot *tslot) { - descrambler_set_key((int)tslot->source, tslot->lastParity, tslot->lastKey); + if (!tslot->SidBlackListed) + descrambler_set_key((int)tslot->source, tslot->lastParity, tslot->lastKey); }