adding new bouquets added to the context menu of the bouquet list
[enigma2.git] / lib / dvb_ci / dvbci.cpp
index 8f1fcac92c6ad7f1aef3cc8179ef36a747deea5c..7d96a296f408b8f4dec66b685cfae8446824743f 100644 (file)
@@ -72,20 +72,90 @@ int eDVBCIInterfaces::reset(int slotid)
 
        if( (slot = getSlot(slotid)) == 0 )
                return -1;
-       
+
+       eDVBCISession::deleteSessions(slot);
+
        return slot->reset();
 }
 
+int eDVBCIInterfaces::enableTS(int slotid, int enable)
+{
+       eDVBCISlot *slot;
+
+       if( (slot = getSlot(slotid)) == 0 )
+               return -1;
+
+       int tunernum = 0;
+       if (enable)
+       {
+               PMTHandlerList::iterator it = m_pmt_handlers.begin();
+               while (it != m_pmt_handlers.end())
+               {
+                       if ( it->cislot == slot )
+                       {
+                               eDVBServicePMTHandler *pmthandler = it->pmthandler;
+                               eUsePtr<iDVBChannel> channel;
+                               if (!pmthandler->getChannel(channel))
+                               {
+                                       ePtr<iDVBFrontend> frontend;
+                                       if (!channel->getFrontend(frontend))
+                                       {
+                                               eDVBFrontend *fe = (eDVBFrontend*) &(*frontend);
+                                               tunernum = fe->getID();
+                                       }
+                               }
+                               break;
+                       }
+                       ++it;
+               }
+       }
+       return slot->enableTS(enable, tunernum);
+}
+
 int eDVBCIInterfaces::initialize(int slotid)
 {
        eDVBCISlot *slot;
 
        if( (slot = getSlot(slotid)) == 0 )
                return -1;
-       
+
+       slot->resetPrevSentCAPMTVersion();
+       PMTHandlerList::iterator it = m_pmt_handlers.begin();
+       while (it != m_pmt_handlers.end())
+       {
+               if ( it->cislot == slot )
+               {
+                       slot->sendCAPMT(it->pmthandler);  // send capmt
+                       break;
+               }
+               ++it;
+       }
+
        return slot->initialize();
 }
 
+int eDVBCIInterfaces::sendCAPMT(int slotid)
+{
+       eDVBCISlot *slot;
+
+       if( (slot = getSlot(slotid)) == 0 )
+               return -1;
+
+       slot->resetPrevSentCAPMTVersion();
+       PMTHandlerList::iterator it = m_pmt_handlers.begin();
+       while (it != m_pmt_handlers.end())
+       {
+               if ( it->cislot == slot )
+               {
+                       slot->sendCAPMT(it->pmthandler);  // send capmt
+                       return 0;
+               }
+               ++it;
+       }
+
+       return -1;
+}
+
 int eDVBCIInterfaces::startMMI(int slotid)
 {
        eDVBCISlot *slot;
@@ -182,7 +252,7 @@ void eDVBCIInterfaces::removePMTHandler(eDVBServicePMTHandler *pmthandler)
        if (it != m_pmt_handlers.end())
        {
                eDVBCISlot *slot = it->cislot;
-               eDVBServicePMTHandler *pmthandler = it->pmthandler;
+//             eDVBServicePMTHandler *pmthandler = it->pmthandler;
                m_pmt_handlers.erase(it);
                if (slot && !--slot->use_count)
                {
@@ -253,7 +323,9 @@ void eDVBCISlot::data(int what)
        if(what == eSocketNotifier::Priority) {
                if(state != stateRemoved) {
                        state = stateRemoved;
+                       enableTS(0);
                        printf("ci removed\n");
+                       eDVBCISession::deleteSessions(this);
                        notifier->setRequested(eSocketNotifier::Read);
                        //HACK
                        eDVBCI_UI::getInstance()->setState(0,0);
@@ -327,6 +399,22 @@ eDVBCISlot::eDVBCISlot(eMainloop *context, int nr)
 
 eDVBCISlot::~eDVBCISlot()
 {
+       enableTS(0);
+}
+
+void eDVBCISlot::setAppManager( eDVBCIApplicationManagerSession *session )
+{
+       application_manager=session;
+}
+
+void eDVBCISlot::setMMIManager( eDVBCIMMISession *session )
+{
+       mmi_session = session;
+}
+
+void eDVBCISlot::setCAManager( eDVBCICAManagerSession *session )
+{
+       ca_manager = session;
 }
 
 int eDVBCISlot::getSlotID()
@@ -338,6 +426,8 @@ int eDVBCISlot::reset()
 {
        printf("edvbcislot: reset requested\n");
 
+       enableTS(0);
+
        ioctl(fd, 0);
 
        return 0;
@@ -390,6 +480,10 @@ int eDVBCISlot::getMMIState()
 int eDVBCISlot::answerEnq(char *value)
 {
        printf("edvbcislot: answerENQ(%s)\n", value);
+
+       if(mmi_session)
+               mmi_session->answerEnq(value);
+
        return 0;
 }
 
@@ -405,7 +499,12 @@ int eDVBCISlot::cancelEnq()
 
 int eDVBCISlot::sendCAPMT(eDVBServicePMTHandler *pmthandler, const std::vector<uint16_t> &ids)
 {
-       const std::vector<uint16_t> &caids = ids.empty() && ca_manager ? ca_manager->getCAIDs() : ids;
+       if (!ca_manager)
+       {
+               eDebug("no ca_manager (no CI plugged?)");
+               return -1;
+       }
+       const std::vector<uint16_t> &caids = ids.empty() ? ca_manager->getCAIDs() : ids;
        ePtr<eTable<ProgramMapSection> > ptr;
        if (pmthandler->getPMT(ptr))
                return -1;
@@ -453,23 +552,50 @@ int eDVBCISlot::sendCAPMT(eDVBServicePMTHandler *pmthandler, const std::vector<u
                                hlen = 4;
                        }
 // end calc capmt length
-                       if (!ca_manager)
-                               eDebug("no ca_manager !!! dump unfiltered capmt:");
-                       else
-                               eDebug("ca_manager %p dump capmt:", ca_manager);
+                       eDebug("ca_manager %p dump capmt:", ca_manager);
                        for(int i=0;i<wp;i++)
                                eDebugNoNewLine("%02x ", raw_data[i]);
                        eDebug("");
 #endif
-                       if (ca_manager)
-                       {
-                               //dont need tag and lenfield
-                               ca_manager->sendCAPMT(raw_data + hlen, wp - hlen);
-                               prev_sent_capmt_version = pmt_version;
-                       }
+                       //dont need tag and lenfield
+                       ca_manager->sendCAPMT(raw_data + hlen, wp - hlen);
+                       prev_sent_capmt_version = pmt_version;
                }
        }
-       
+       return 0;
+}
+
+int eDVBCISlot::enableTS(int enable, int tuner)
+{
+       printf("eDVBCISlot::enableTS(%d %d)\n", enable, tuner);
+
+       FILE *input0, *input1, *ci;
+       if((input0 = fopen("/proc/stb/tsmux/input0", "wb")) == NULL) {
+               printf("cannot open /proc/stb/tsmux/input0\n");
+               return 0;
+       }
+       if((input1 = fopen("/proc/stb/tsmux/input1", "wb")) == NULL) {
+               printf("cannot open /proc/stb/tsmux/input1\n");
+               return 0;
+       }
+       if((ci = fopen("/proc/stb/tsmux/input2", "wb")) == NULL) {
+               printf("cannot open /proc/stb/tsmux/input2\n");
+               return 0;
+       }
+
+       fprintf(ci, "%s", tuner==0 ? "A" : "B");  // configure CI data source (TunerA, TunerB)
+       fprintf(input0, "%s", tuner==0 && enable ? "CI" : "A"); // configure ATI input 0 data source
+       fprintf(input1, "%s", tuner==1 && enable ? "CI" : "B"); // configure ATI input 1 data source
+
+       fclose(input0);
+       fclose(input1);
+       fclose(ci);
+       return 0;
+}
+
+void eDVBCISlot::resendCAPMT()
+{
+       eDVBCIInterfaces::getInstance()->sendCAPMT(slotid);
 }
 
 eAutoInitP0<eDVBCIInterfaces> init_eDVBCIInterfaces(eAutoInitNumbers::dvb, "CI Slots");