remove fake answer
[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 #include <lib/base/estring.h>
6
7 /*
8 PyObject *list = PyList_New(len);
9 for (i=0; i<len; ++i) {
10         PyObject *tuple = PyTuple_New(3); // 3 eintrge im tuple
11         PyTuple_SetItem(tuple, 0, PyString_FromString("eintrag 1"))
12         PyTuple_SetItem(tuple, 1, PyInt_FromLong(31337));
13         PyTuple_SetItem(tuple, 2, PyString_FromString("eintrag 3"))
14         PyList_SetItem(list, i, tuple);
15 }
16 return list;
17 */
18
19 eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot)
20 {
21         slot = tslot;
22         slot->mmi_session = this;
23 }
24
25 eDVBCIMMISession::~eDVBCIMMISession()
26 {
27         slot->mmi_session = 0;
28 }
29
30 int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len)
31 {
32         printf("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
33         for (int i=0; i<len; i++)
34                 printf("%02x ", ((const unsigned char*)data)[i]);
35         printf("\n");
36
37         if ((tag[0]==0x9f) && (tag[1]==0x88))
38         {
39                 switch (tag[2])
40                 {
41                         case 0x01:
42                         printf("MMI display control\n");
43                         if (((unsigned char*)data)[0] != 1)
44                                 printf("kann ich nicht. aber das sag ich dem modul nicht.\n");
45                         state=stateDisplayReply;
46                         return 1;
47                 case 0x07:              //Tmenu_enq
48                 {
49                         unsigned char *d=(unsigned char*)data;
50                         unsigned char *max=((unsigned char*)d) + len;
51                         int textlen = len - 2;
52                         int i;
53
54                         printf("in enq\n");
55                         
56                         if ((d+2) > max)
57                                 break;
58                                 
59                         int blind = *d++ & 1;
60                         int alen = *d++;
61
62                         printf("%d bytes text\n", textlen);
63                         if ((d+textlen) > max)
64                                 break;
65                         
66                         char str[textlen + 1];
67                         memcpy(str, ((char*)d), textlen);
68                         str[textlen] = '\0';
69                         
70                         printf("enq-text: %s\n",str);
71                         
72                         eDVBCI_UI::getInstance()->mmiScreenEnq(0, blind, alen, (char*)convertDVBUTF8(str).c_str());
73
74                         break;          
75                 }
76                 case 0x09:              //Tmenu_last
77                 case 0x0c:              //Tlist_last
78                 {
79                         unsigned char *d=(unsigned char*)data;
80                         unsigned char *max=((unsigned char*)d) + len;
81                         int pos = 0;
82                         printf("Tmenu_last\n");
83                         if (d > max)
84                                 break;
85                         int n=*d++;
86                         
87                         //FIXME: slotid
88                         if(tag[2] == 0x09)      //menu
89                                 eDVBCI_UI::getInstance()->mmiScreenBegin(0, 0);
90                         else                                                            //list
91                                 eDVBCI_UI::getInstance()->mmiScreenBegin(0, 1);
92                         
93                         if (n == 0xFF)
94                                 n=0;
95                         else
96                                 n++;
97                         printf("%d texts\n", n);
98                         for (int i=0; i < (n+3); ++i)
99                         {
100                                 int textlen;
101                                 if ((d+3) > max)
102                                         break;
103                                 printf("text tag: %02x %02x %02x\n", d[0], d[1], d[2]);
104                                 d+=3;
105                                 d+=parseLengthField(d, textlen);
106                                 printf("%d bytes text\n", textlen);
107                                 if ((d+textlen) > max)
108                                         break;
109                                         
110                                 char str[textlen + 1];
111                                 memcpy(str, ((char*)d), textlen);
112                                 str[textlen] = '\0';
113                                 
114                                 eDVBCI_UI::getInstance()->mmiScreenAddText(0, pos++, (char*)convertDVBUTF8(str).c_str());
115                                         
116                                 while (textlen--)
117                                         printf("%c", *d++);
118                                 printf("\n");
119                         }
120                         //FIXME: slotid
121                         eDVBCI_UI::getInstance()->mmiScreenFinish(0);
122                         break;
123                 }
124                 default:
125                         printf("unknown APDU tag 9F 88 %02x\n", tag[2]);
126                         break;
127                 }
128         }
129         return 0;
130 }
131
132 int eDVBCIMMISession::doAction()
133 {
134         switch (state)
135         {
136         case stateStarted:
137                 state=stateIdle;
138                 break;
139         case stateDisplayReply:
140         {
141                 unsigned char tag[]={0x9f, 0x88, 0x02};
142                 unsigned char data[]={0x01, 0x01};
143                 sendAPDU(tag, data, 2);
144                 state=stateIdle;
145                 //state=stateFakeOK;
146                 //return 1;
147                 break;
148         }
149         case stateFakeOK:
150         {
151                 unsigned char tag[]={0x9f, 0x88, 0x0b};
152                 unsigned char data[]={5};
153                 sendAPDU(tag, data, 1);
154                 state=stateIdle;
155                 break;
156         }
157         case stateIdle:
158                 break;
159         default:
160                 break;
161         }
162         return 0;
163 }
164
165 int eDVBCIMMISession::stopMMI()
166 {
167         printf("eDVBCIMMISession::stopMMI()\n");
168
169         unsigned char tag[]={0x9f, 0x88, 0x00};
170         unsigned char data[]={0x00};
171         sendAPDU(tag, data, 1);
172         
173         return 0;
174 }
175
176 int eDVBCIMMISession::answerText(int answer)
177 {
178         printf("eDVBCIMMISession::answerText(%d)\n",answer);
179
180         unsigned char tag[]={0x9f, 0x88, 0x0B};
181         unsigned char data[]={0x00};
182         data[0] = answer & 0xff;
183         sendAPDU(tag, data, 1);
184         
185         return 0;
186 }
187
188 int eDVBCIMMISession::cancelEnq()
189 {
190         printf("eDVBCIMMISession::cancelEnq()\n");
191
192         unsigned char tag[]={0x9f, 0x88, 0x08};
193         unsigned char data[]={0x00};
194         sendAPDU(tag, data, 1);
195         
196         return 0;
197 }
198