add comment for python-lists
[enigma2.git] / lib / dvb_ci / dvbci_mmi.cpp
1 /* DVB CI MMI */
2
3 #include <lib/dvb_ci/dvbci_mmi.h>
4
5 /*
6 PyObject *list = PyList_New(len);
7 for (i=0; i<len; ++i) {
8         PyObject *tuple = PyTuple_New(3); // 3 eintrge im tuple
9         PyTuple_SetItem(tuple, 0, PyString_FromString("eintrag 1"))
10         PyTuple_SetItem(tuple, 1, PyInt_FromLong(31337));
11         PyTuple_SetItem(tuple, 2, PyString_FromString("eintrag 3"))
12         PyList_SetItem(list, i, tuple);
13 }
14 return list;
15 */
16
17 eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot)
18 {
19         slot = tslot;
20         slot->mmi_session = this;
21 }
22
23 eDVBCIMMISession::~eDVBCIMMISession()
24 {
25         slot->mmi_session = 0;
26 }
27
28 int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len)
29 {
30         printf("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
31         for (int i=0; i<len; i++)
32                 printf("%02x ", ((const unsigned char*)data)[i]);
33         printf("\n");
34
35         if ((tag[0]==0x9f) && (tag[1]==0x88))
36         {
37                 switch (tag[2])
38                 {
39                         case 0x01:
40                         printf("MMI display control\n");
41                         if (((unsigned char*)data)[0] != 1)
42                                 printf("kann ich nicht. aber das sag ich dem modul nicht.\n");
43                         state=stateDisplayReply;
44                         return 1;
45                 case 0x09:
46                 case 0x0c:
47                 {
48                         unsigned char *d=(unsigned char*)data;
49                         unsigned char *max=((unsigned char*)d) + len;
50                         printf("Tmenu_last\n");
51                         if (d > max)
52                                 break;
53                         int n=*d++;
54                         if (n == 0xFF)
55                                 n=0;
56                         else
57                                 n++;
58                         printf("%d texts\n", n);
59                         for (int i=0; i < (n+3); ++i)
60                         {
61                                 int textlen;
62                                 if ((d+3) > max)
63                                         break;
64                                 printf("text tag: %02x %02x %02x\n", d[0], d[1], d[2]);
65                                 d+=3;
66                                 d+=parseLengthField(d, textlen);
67                                 printf("%d bytes text\n", textlen);
68                                 if ((d+textlen) > max)
69                                         break;
70                                 while (textlen--)
71                                         printf("%c", *d++);
72                                 printf("\n");
73                         }
74                         break;
75                 }
76                 default:
77                         printf("unknown APDU tag 9F 88 %02x\n", tag[2]);
78                         break;
79                 }
80         }
81         return 0;
82 }
83
84 int eDVBCIMMISession::doAction()
85 {
86         switch (state)
87         {
88         case stateStarted:
89                 state=stateIdle;
90                 break;
91         case stateDisplayReply:
92         {
93                 unsigned char tag[]={0x9f, 0x88, 0x02};
94                 unsigned char data[]={0x01, 0x01};
95                 sendAPDU(tag, data, 2);
96                 state=stateFakeOK;
97                 return 1;
98                 break;
99         }
100         case stateFakeOK:
101         {
102                 unsigned char tag[]={0x9f, 0x88, 0x0b};
103                 unsigned char data[]={5};
104                 sendAPDU(tag, data, 1);
105                 state=stateIdle;
106                 break;
107         }
108         case stateIdle:
109                 break;
110         default:
111                 break;
112         }
113         return 0;
114 }
115
116 int eDVBCIMMISession::stopMMI()
117 {
118         printf("eDVBCIMMISession::stopMMI()\n");
119
120         unsigned char tag[]={0x9f, 0x88, 0x00};
121         unsigned char data[]={0x00};
122         sendAPDU(tag, data, 1);
123 }
124