fix: StandardError: eDVBCIInterfaces::setDescrambleRules entry in caid list is not...
[vuplus_dvbapp] / lib / dvb_ci / dvbci_mmi.cpp
1 /* DVB CI MMI */
2
3 #include <lib/dvb_ci/dvbci_mmi.h>
4 #include <lib/dvb_ci/dvbci_ui.h>
5
6 #include <string>
7
8 /*
9 PyObject *list = PyList_New(len);
10 for (i=0; i<len; ++i) {
11         PyObject *tuple = PyTuple_New(3); // 3 eintrge im tuple
12         PyTuple_SetItem(tuple, 0, PyString_FromString("eintrag 1"))
13         PyTuple_SetItem(tuple, 1, PyInt_FromLong(31337));
14         PyTuple_SetItem(tuple, 2, PyString_FromString("eintrag 3"))
15         PyList_SetItem(list, i, tuple);
16 }
17 return list;
18 */
19
20 eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot)
21 {
22         slot = tslot;
23         slot->setMMIManager(this);
24 }
25
26 eDVBCIMMISession::~eDVBCIMMISession()
27 {
28         slot->setMMIManager(NULL);
29         eDVBCI_UI::getInstance()->mmiSessionDestroyed(slot->getSlotID());
30 }
31
32 int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len)
33 {
34         eDebugNoNewLine("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
35         for (int i=0; i<len; i++)
36                 eDebugNoNewLine("%02x ", ((const unsigned char*)data)[i]);
37         eDebug("");
38
39         if ((tag[0]==0x9f) && (tag[1]==0x88))
40                 if (eDVBCI_UI::getInstance()->processMMIData(slot->getSlotID(), tag, data, len) == 1)
41                 {
42                         state=stateDisplayReply;
43                         return 1;
44                 }
45
46         return 0;
47 }
48
49 int eDVBCIMMISession::doAction()
50 {
51         switch (state)
52         {
53         case stateStarted:
54                 state=stateIdle;
55                 break;
56         case stateDisplayReply:
57         {
58                 unsigned char tag[]={0x9f, 0x88, 0x02};
59                 unsigned char data[]={0x01, 0x01};
60                 sendAPDU(tag, data, 2);
61                 state=stateIdle;
62                 //state=stateFakeOK;
63                 //return 1;
64                 break;
65         }
66         case stateFakeOK:
67         {
68                 unsigned char tag[]={0x9f, 0x88, 0x0b};
69                 unsigned char data[]={5};
70                 sendAPDU(tag, data, 1);
71                 state=stateIdle;
72                 break;
73         }
74         case stateIdle:
75                 break;
76         default:
77                 break;
78         }
79         return 0;
80 }
81
82 int eDVBCIMMISession::stopMMI()
83 {
84         eDebug("eDVBCIMMISession::stopMMI()");
85
86         unsigned char tag[]={0x9f, 0x88, 0x00};
87         unsigned char data[]={0x00};
88         sendAPDU(tag, data, 1);
89         
90         return 0;
91 }
92
93 int eDVBCIMMISession::answerText(int answer)
94 {
95         eDebug("eDVBCIMMISession::answerText(%d)",answer);
96
97         unsigned char tag[]={0x9f, 0x88, 0x0B};
98         unsigned char data[]={0x00};
99         data[0] = answer & 0xff;
100         sendAPDU(tag, data, 1);
101         
102         return 0;
103 }
104
105 int eDVBCIMMISession::answerEnq(char *answer)
106 {
107         unsigned int len = strlen(answer);
108         eDebug("eDVBCIMMISession::answerEnq(%d bytes)", len);
109
110         unsigned char data[len+1];
111         data[0] = 0x01; // answer ok
112         memcpy(data+1, answer, len);
113
114         unsigned char tag[]={0x9f, 0x88, 0x08};
115         sendAPDU(tag, data, len+1);
116
117         return 0;
118 }
119
120 int eDVBCIMMISession::cancelEnq()
121 {
122         eDebug("eDVBCIMMISession::cancelEnq()");
123
124         unsigned char tag[]={0x9f, 0x88, 0x08};
125         unsigned char data[]={0x00}; // canceled
126         sendAPDU(tag, data, 1);
127         
128         return 0;
129 }
130