+int eDVBCISlot::initialize()
+{
+ printf("edvbcislot: initialize()\n");
+ return 0;
+}
+
+int eDVBCISlot::startMMI()
+{
+ printf("edvbcislot: startMMI()\n");
+
+ if(application_manager)
+ application_manager->startMMI();
+
+ return 0;
+}
+
+int eDVBCISlot::stopMMI()
+{
+ printf("edvbcislot: stopMMI()\n");
+
+ if(mmi_session)
+ mmi_session->stopMMI();
+
+ return 0;
+}
+
+int eDVBCISlot::answerText(int answer)
+{
+ printf("edvbcislot: answerText(%d)\n", answer);
+
+ if(mmi_session)
+ mmi_session->answerText(answer);
+
+ return 0;
+}
+
+int eDVBCISlot::getMMIState()
+{
+ if(mmi_session)
+ return 1;
+
+ return 0;
+}
+
+int eDVBCISlot::answerEnq(char *value)
+{
+ printf("edvbcislot: answerENQ(%s)\n", value);
+
+ if(mmi_session)
+ mmi_session->answerEnq(value);
+
+ return 0;
+}
+
+int eDVBCISlot::cancelEnq()
+{
+ printf("edvbcislot: cancelENQ\n");
+
+ if(mmi_session)
+ mmi_session->cancelEnq();
+
+ return 0;
+}
+
+int eDVBCISlot::sendCAPMT(eDVBServicePMTHandler *pmthandler, const std::vector<uint16_t> &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;
+ else
+ {
+ eDVBTableSpec table_spec;
+ ptr->getSpec(table_spec);
+ int pmt_version = table_spec.version & 0x1F; // just 5 bits
+ if ( pmt_version == prev_sent_capmt_version )
+ {
+ eDebug("[eDVBCISlot] dont sent self capmt version twice");
+ return -1;
+ }
+ std::vector<ProgramMapSection*>::const_iterator i=ptr->getSections().begin();
+ if ( i == ptr->getSections().end() )
+ return -1;
+ else
+ {
+ unsigned char raw_data[2048];
+ CaProgramMapSection capmt(*i++, prev_sent_capmt_version != 0xFF ? 0x05 /*update*/ : 0x03 /*only*/, 0x01, caids );
+ while( i != ptr->getSections().end() )
+ {
+ // eDebug("append");
+ capmt.append(*i++);
+ }
+ capmt.writeToBuffer(raw_data);
+#if 1
+// begin calc capmt length
+ int wp=0;
+ int hlen;
+ if ( raw_data[3] & 0x80 )
+ {
+ int i=0;
+ int lenbytes = raw_data[3] & ~0x80;
+ while(i < lenbytes)
+ wp = (wp << 8) | raw_data[4 + i++];
+ wp+=4;
+ wp+=lenbytes;
+ hlen = 4 + lenbytes;
+ }
+ else
+ {
+ wp = raw_data[3];
+ wp+=4;
+ hlen = 4;
+ }
+// end calc capmt length
+ eDebug("ca_manager %p dump capmt:", ca_manager);
+ for(int i=0;i<wp;i++)
+ eDebugNoNewLine("%02x ", raw_data[i]);
+ eDebug("");
+#endif
+ //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);
+}
+