translations
[enigma2.git] / 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 /*
7 PyObject *list = PyList_New(len);
8 for (i=0; i<len; ++i) {
9         PyObject *tuple = PyTuple_New(3); // 3 eintrge im tuple
10         PyTuple_SetItem(tuple, 0, PyString_FromString("eintrag 1"))
11         PyTuple_SetItem(tuple, 1, PyInt_FromLong(31337));
12         PyTuple_SetItem(tuple, 2, PyString_FromString("eintrag 3"))
13         PyList_SetItem(list, i, tuple);
14 }
15 return list;
16 */
17
18 eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot)
19 {
20         slot = tslot;
21         slot->mmi_session = this;
22 }
23
24 eDVBCIMMISession::~eDVBCIMMISession()
25 {
26         slot->mmi_session = 0;
27 }
28
29 int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len)
30 {
31         printf("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
32         for (int i=0; i<len; i++)
33                 printf("%02x ", ((const unsigned char*)data)[i]);
34         printf("\n");
35
36         if ((tag[0]==0x9f) && (tag[1]==0x88))
37         {
38                 switch (tag[2])
39                 {
40                         case 0x01:
41                         printf("MMI display control\n");
42                         if (((unsigned char*)data)[0] != 1)
43                                 printf("kann ich nicht. aber das sag ich dem modul nicht.\n");
44                         state=stateDisplayReply;
45                         return 1;
46                 case 0x09:
47                 case 0x0c:
48                 {
49                         unsigned char *d=(unsigned char*)data;
50                         unsigned char *max=((unsigned char*)d) + len;
51                         int pos = 0;
52                         printf("Tmenu_last\n");
53                         if (d > max)
54                                 break;
55                         int n=*d++;
56                         
57                         //FIXME: slotid
58                         if(tag[2] == 0x09)
59                                 eDVBCI_UI::getInstance()->mmiScreenBegin(0, 0);
60                         else
61                                 eDVBCI_UI::getInstance()->mmiScreenBegin(0, 1);
62                         
63                         if (n == 0xFF)
64                                 n=0;
65                         else
66                                 n++;
67                         printf("%d texts\n", n);
68                         for (int i=0; i < (n+3); ++i)
69                         {
70                                 int textlen;
71                                 if ((d+3) > max)
72                                         break;
73                                 printf("text tag: %02x %02x %02x\n", d[0], d[1], d[2]);
74                                 d+=3;
75                                 d+=parseLengthField(d, textlen);
76                                 printf("%d bytes text\n", textlen);
77                                 if ((d+textlen) > max)
78                                         break;
79                                         
80                                 char str[textlen + 1];
81                                 memcpy(str, ((char*)d), textlen);
82                                 str[textlen] = '\0';
83                                 
84                                 eDVBCI_UI::getInstance()->mmiScreenAddText(0, pos++, str);
85                                         
86                                 while (textlen--)
87                                         printf("%c", *d++);
88                                 printf("\n");
89                         }
90                         //FIXME: slotid
91                         eDVBCI_UI::getInstance()->mmiScreenFinish(0);
92                         break;
93                 }
94                 default:
95                         printf("unknown APDU tag 9F 88 %02x\n", tag[2]);
96                         break;
97                 }
98         }
99         return 0;
100 }
101
102 int eDVBCIMMISession::doAction()
103 {
104         switch (state)
105         {
106         case stateStarted:
107                 state=stateIdle;
108                 break;
109         case stateDisplayReply:
110         {
111                 unsigned char tag[]={0x9f, 0x88, 0x02};
112                 unsigned char data[]={0x01, 0x01};
113                 sendAPDU(tag, data, 2);
114                 state=stateFakeOK;
115                 return 1;
116                 break;
117         }
118         case stateFakeOK:
119         {
120                 unsigned char tag[]={0x9f, 0x88, 0x0b};
121                 unsigned char data[]={5};
122                 sendAPDU(tag, data, 1);
123                 state=stateIdle;
124                 break;
125         }
126         case stateIdle:
127                 break;
128         default:
129                 break;
130         }
131         return 0;
132 }
133
134 int eDVBCIMMISession::stopMMI()
135 {
136         printf("eDVBCIMMISession::stopMMI()\n");
137
138         unsigned char tag[]={0x9f, 0x88, 0x00};
139         unsigned char data[]={0x00};
140         sendAPDU(tag, data, 1);
141 }
142
143 int eDVBCIMMISession::answerText(int answer)
144 {
145         printf("eDVBCIMMISession::answerText(%d)\n",answer);
146
147         unsigned char tag[]={0x9f, 0x88, 0x0B};
148         unsigned char data[]={0x00};
149         data[0] = answer & 0xff;
150         sendAPDU(tag, data, 1);
151 }
152