+int eDVBCIInterfaces::setInputSource(int tuner_no, data_source source)
+{
+// eDebug("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+// eDebug("eDVBCIInterfaces::setInputSource(%d %d)", tuner_no, (int)source);
+ if (getNumOfSlots() > 1) // FIXME .. we force DM8000 when more than one CI Slot is avail
+ {
+ char buf[64];
+ snprintf(buf, 64, "/proc/stb/tsmux/input%d", tuner_no);
+
+ FILE *input=0;
+ if((input = fopen(buf, "wb")) == NULL) {
+ eDebug("cannot open %s", buf);
+ return 0;
+ }
+
+ if (tuner_no > 3)
+ eDebug("setInputSource(%d, %d) failed... dm8000 just have four inputs", tuner_no, (int)source);
+
+ switch(source)
+ {
+ case CI_A:
+ fprintf(input, "CI0");
+ break;
+ case CI_B:
+ fprintf(input, "CI1");
+ break;
+ case CI_C:
+ fprintf(input, "CI2");
+ break;
+ case CI_D:
+ fprintf(input, "CI3");
+ break;
+ case TUNER_A:
+ fprintf(input, "A");
+ break;
+ case TUNER_B:
+ fprintf(input, "B");
+ break;
+ case TUNER_C:
+ fprintf(input, "C");
+ break;
+ case TUNER_D:
+ fprintf(input, "D");
+ break;
+ default:
+ eDebug("setInputSource for input %d failed!!!\n", (int)source);
+ break;
+ }
+
+ fclose(input);
+ }
+ else // DM7025
+ {
+ char buf[64];
+ snprintf(buf, 64, "/proc/stb/tsmux/input%d", tuner_no);
+
+ if (tuner_no > 1)
+ eDebug("setInputSource(%d, %d) failed... dm7025 just have two inputs", tuner_no, (int)source);
+
+ FILE *input=0;
+ if((input = fopen(buf, "wb")) == NULL) {
+ eDebug("cannot open %s", buf);
+ return 0;
+ }
+
+ switch(source)
+ {
+ case CI_A:
+ fprintf(input, "CI");
+ break;
+ case TUNER_A:
+ fprintf(input, "A");
+ break;
+ case TUNER_B:
+ fprintf(input, "B");
+ break;
+ default:
+ eDebug("setInputSource for input %d failed!!!\n", (int)source);
+ break;
+ }
+
+ fclose(input);
+ }
+ eDebug("eDVBCIInterfaces->setInputSource(%d, %d)", tuner_no, (int)source);
+ return 0;
+}
+
+PyObject *eDVBCIInterfaces::getDescrambleRules(int slotid)
+{
+ eDVBCISlot *slot = getSlot(slotid);
+ if (!slot)
+ {
+ char tmp[255];
+ snprintf(tmp, 255, "eDVBCIInterfaces::getDescrambleRules try to get rules for CI Slot %d... but just %d slots are available", slotid, m_slots.size());
+ PyErr_SetString(PyExc_StandardError, tmp);
+ return 0;
+ }
+ ePyObject tuple = PyTuple_New(3);
+ int caids = slot->possible_caids.size();
+ int services = slot->possible_services.size();
+ int providers = slot->possible_providers.size();
+ ePyObject caid_list = PyList_New(caids);
+ ePyObject service_list = PyList_New(services);
+ ePyObject provider_list = PyList_New(providers);
+ caidSet::iterator caid_it(slot->possible_caids.begin());
+ while(caids)
+ {
+ --caids;
+ PyList_SET_ITEM(caid_list, caids, PyLong_FromLong(*caid_it));
+ ++caid_it;
+ }
+ serviceSet::iterator ref_it(slot->possible_services.begin());
+ while(services)
+ {
+ --services;
+ PyList_SET_ITEM(service_list, services, PyString_FromString(ref_it->toString().c_str()));
+ ++ref_it;
+ }
+ providerSet::iterator provider_it(slot->possible_providers.begin());
+ while(providers)
+ {
+ ePyObject tuple = PyTuple_New(2);
+ PyTuple_SET_ITEM(tuple, 0, PyString_FromString(provider_it->first.c_str()));
+ PyTuple_SET_ITEM(tuple, 1, PyLong_FromUnsignedLong(provider_it->second));
+ --providers;
+ PyList_SET_ITEM(provider_list, providers, tuple);
+ ++provider_it;
+ }
+ PyTuple_SET_ITEM(tuple, 0, service_list);
+ PyTuple_SET_ITEM(tuple, 1, provider_list);
+ PyTuple_SET_ITEM(tuple, 2, caid_list);
+ return tuple;
+}
+
+const char *PyObject_TypeStr(PyObject *o)
+{
+ return o->ob_type && o->ob_type->tp_name ? o->ob_type->tp_name : "unknown object type";
+}
+
+RESULT eDVBCIInterfaces::setDescrambleRules(int slotid, SWIG_PYOBJECT(ePyObject) obj )
+{
+ eDVBCISlot *slot = getSlot(slotid);
+ if (!slot)
+ {
+ char tmp[255];
+ snprintf(tmp, 255, "eDVBCIInterfaces::setDescrambleRules try to set rules for CI Slot %d... but just %d slots are available", slotid, m_slots.size());
+ PyErr_SetString(PyExc_StandardError, tmp);
+ return -1;
+ }
+ if (!PyTuple_Check(obj))
+ {
+ char tmp[255];
+ snprintf(tmp, 255, "2nd argument of setDescrambleRules is not a tuple.. it is a '%s'!!", PyObject_TypeStr(obj));
+ PyErr_SetString(PyExc_StandardError, tmp);
+ return -1;
+ }
+ if (PyTuple_Size(obj) != 3)
+ {
+ const char *errstr = "eDVBCIInterfaces::setDescrambleRules not enough entrys in argument tuple!!\n"
+ "first argument should be a pythonlist with possible services\n"
+ "second argument should be a pythonlist with possible providers/dvbnamespace tuples\n"
+ "third argument should be a pythonlist with possible caids";
+ PyErr_SetString(PyExc_StandardError, errstr);
+ return -1;
+ }
+ ePyObject service_list = PyTuple_GET_ITEM(obj, 0);
+ ePyObject provider_list = PyTuple_GET_ITEM(obj, 1);
+ ePyObject caid_list = PyTuple_GET_ITEM(obj, 2);
+ if (!PyList_Check(service_list) || !PyList_Check(provider_list) || !PyList_Check(caid_list))
+ {
+ char errstr[512];
+ snprintf(errstr, 512, "eDVBCIInterfaces::setDescrambleRules incorrect data types in argument tuple!!\n"
+ "first argument(%s) should be a pythonlist with possible services (reference strings)\n"
+ "second argument(%s) should be a pythonlist with possible providers (providername strings)\n"
+ "third argument(%s) should be a pythonlist with possible caids (ints)",
+ PyObject_TypeStr(service_list), PyObject_TypeStr(provider_list), PyObject_TypeStr(caid_list));
+ PyErr_SetString(PyExc_StandardError, errstr);
+ return -1;
+ }
+ slot->possible_caids.clear();
+ slot->possible_services.clear();
+ slot->possible_providers.clear();
+ int size = PyList_Size(service_list);
+ while(size)
+ {
+ --size;
+ ePyObject refstr = PyList_GET_ITEM(service_list, size);
+ if (!PyString_Check(refstr))
+ {
+ char buf[255];
+ snprintf(buf, 255, "eDVBCIInterfaces::setDescrambleRules entry in service list is not a string.. it is '%s'!!", PyObject_TypeStr(refstr));
+ PyErr_SetString(PyExc_StandardError, buf);
+ return -1;
+ }
+ char *tmpstr = PyString_AS_STRING(refstr);
+ eServiceReference ref(tmpstr);
+ if (ref.valid())
+ slot->possible_services.insert(ref);
+ else
+ eDebug("eDVBCIInterfaces::setDescrambleRules '%s' is not a valid service reference... ignore!!", tmpstr);
+ };
+ size = PyList_Size(provider_list);
+ while(size)
+ {
+ --size;
+ ePyObject tuple = PyList_GET_ITEM(provider_list, size);
+ if (!PyTuple_Check(tuple))
+ {
+ char buf[255];
+ snprintf(buf, 255, "eDVBCIInterfaces::setDescrambleRules entry in provider list is not a tuple it is '%s'!!", PyObject_TypeStr(tuple));
+ PyErr_SetString(PyExc_StandardError, buf);
+ return -1;
+ }
+ if (PyTuple_Size(tuple) != 2)
+ {
+ char buf[255];
+ snprintf(buf, 255, "eDVBCIInterfaces::setDescrambleRules provider tuple has %d instead of 2 entries!!", PyTuple_Size(tuple));
+ PyErr_SetString(PyExc_StandardError, buf);
+ return -1;
+ }
+ if (!PyString_Check(PyTuple_GET_ITEM(tuple, 0)))
+ {
+ char buf[255];
+ snprintf(buf, 255, "eDVBCIInterfaces::setDescrambleRules 1st entry in provider tuple is not a string it is '%s'", PyObject_TypeStr(PyTuple_GET_ITEM(tuple, 0)));
+ PyErr_SetString(PyExc_StandardError, buf);
+ return -1;
+ }
+ if (!PyLong_Check(PyTuple_GET_ITEM(tuple, 1)))
+ {
+ char buf[255];
+ snprintf(buf, 255, "eDVBCIInterfaces::setDescrambleRules 2nd entry in provider tuple is not a long it is '%s'", PyObject_TypeStr(PyTuple_GET_ITEM(tuple, 1)));
+ PyErr_SetString(PyExc_StandardError, buf);
+ return -1;
+ }
+ char *tmpstr = PyString_AS_STRING(PyTuple_GET_ITEM(tuple, 0));
+ uint32_t orbpos = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(tuple, 1));
+ if (strlen(tmpstr))
+ slot->possible_providers.insert(std::pair<std::string, uint32_t>(tmpstr, orbpos));
+ else
+ eDebug("eDVBCIInterfaces::setDescrambleRules ignore invalid entry in provider tuple (string is empty)!!");
+ };
+ size = PyList_Size(caid_list);
+ while(size)
+ {
+ --size;
+ ePyObject caid = PyList_GET_ITEM(caid_list, size);
+ if (!PyLong_Check(caid))
+ {
+ char buf[255];
+ snprintf(buf, 255, "eDVBCIInterfaces::setDescrambleRules entry in caid list is not a long it is '%s'!!", PyObject_TypeStr(caid));
+ PyErr_SetString(PyExc_StandardError, buf);
+ return -1;
+ }
+ int tmpcaid = PyLong_AsLong(caid);
+ if (tmpcaid > 0 && tmpcaid < 0x10000)
+ slot->possible_caids.insert(tmpcaid);
+ else
+ eDebug("eDVBCIInterfaces::setDescrambleRules %d is not a valid caid... ignore!!", tmpcaid);
+ };
+ return 0;
+}
+
+PyObject *eDVBCIInterfaces::readCICaIds(int slotid)
+{
+ eDVBCISlot *slot = getSlot(slotid);
+ if (!slot)
+ {
+ char tmp[255];
+ snprintf(tmp, 255, "eDVBCIInterfaces::readCICaIds try to get CAIds for CI Slot %d... but just %d slots are available", slotid, m_slots.size());
+ PyErr_SetString(PyExc_StandardError, tmp);
+ }
+ else
+ {
+ int idx=0;
+ eDVBCICAManagerSession *ca_manager = slot->getCAManager();
+ const std::vector<uint16_t> *ci_caids = ca_manager ? &ca_manager->getCAIDs() : 0;
+ ePyObject list = PyList_New(ci_caids ? ci_caids->size() : 0);
+ if (ci_caids)
+ {
+ for (std::vector<uint16_t>::const_iterator it = ci_caids->begin(); it != ci_caids->end(); ++it)
+ PyList_SET_ITEM(list, idx++, PyLong_FromLong(*it));
+ }
+ return list;
+ }
+ return 0;
+}
+
+int eDVBCIInterfaces::setCIClockRate(int slotid, int rate)
+{
+ eDVBCISlot *slot = getSlot(slotid);
+ if (slot)
+ return slot->setClockRate(rate);
+ return -1;
+}
+