the CI now is useable for tuner A or tuner B (auto switched)
[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 #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->setMMIManager(this);
23 }
24
25 eDVBCIMMISession::~eDVBCIMMISession()
26 {
27         slot->setMMIManager(NULL);
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
53                         printf("in enq\n");
54                         
55                         if ((d+2) > max)
56                                 break;
57                                 
58                         int blind = *d++ & 1;
59                         int alen = *d++;
60
61                         printf("%d bytes text\n", textlen);
62                         if ((d+textlen) > max)
63                                 break;
64                         
65                         char str[textlen + 1];
66                         memcpy(str, ((char*)d), textlen);
67                         str[textlen] = '\0';
68                         
69                         printf("enq-text: %s\n",str);
70                         
71                         eDVBCI_UI::getInstance()->mmiScreenEnq(0, blind, alen, (char*)convertDVBUTF8(str).c_str());
72
73                         break;          
74                 }
75                 case 0x09:              //Tmenu_last
76                 case 0x0c:              //Tlist_last
77                 {
78                         unsigned char *d=(unsigned char*)data;
79                         unsigned char *max=((unsigned char*)d) + len;
80                         int pos = 0;
81                         printf("Tmenu_last\n");
82                         if (d > max)
83                                 break;
84                         int n=*d++;
85                         
86                         //FIXME: slotid
87                         if(tag[2] == 0x09)      //menu
88                                 eDVBCI_UI::getInstance()->mmiScreenBegin(0, 0);
89                         else                                                            //list
90                                 eDVBCI_UI::getInstance()->mmiScreenBegin(0, 1);
91                         
92                         if (n == 0xFF)
93                                 n=0;
94                         else
95                                 n++;
96                         printf("%d texts\n", n);
97                         for (int i=0; i < (n+3); ++i)
98                         {
99                                 int textlen;
100                                 if ((d+3) > max)
101                                         break;
102                                 printf("text tag: %02x %02x %02x\n", d[0], d[1], d[2]);
103                                 d+=3;
104                                 d+=parseLengthField(d, textlen);
105                                 printf("%d bytes text\n", textlen);
106                                 if ((d+textlen) > max)
107                                         break;
108                                         
109                                 char str[textlen + 1];
110                                 memcpy(str, ((char*)d), textlen);
111                                 str[textlen] = '\0';
112                                 
113                                 eDVBCI_UI::getInstance()->mmiScreenAddText(0, pos++, (char*)convertDVBUTF8(str).c_str());
114                                         
115                                 while (textlen--)
116                                         printf("%c", *d++);
117                                 printf("\n");
118                         }
119                         //FIXME: slotid
120                         eDVBCI_UI::getInstance()->mmiScreenFinish(0);
121                         break;
122                 }
123                 default:
124                         printf("unknown APDU tag 9F 88 %02x\n", tag[2]);
125                         break;
126                 }
127         }
128         return 0;
129 }
130
131 int eDVBCIMMISession::doAction()
132 {
133         switch (state)
134         {
135         case stateStarted:
136                 state=stateIdle;
137                 break;
138         case stateDisplayReply:
139         {
140                 unsigned char tag[]={0x9f, 0x88, 0x02};
141                 unsigned char data[]={0x01, 0x01};
142                 sendAPDU(tag, data, 2);
143                 state=stateIdle;
144                 //state=stateFakeOK;
145                 //return 1;
146                 break;
147         }
148         case stateFakeOK:
149         {
150                 unsigned char tag[]={0x9f, 0x88, 0x0b};
151                 unsigned char data[]={5};
152                 sendAPDU(tag, data, 1);
153                 state=stateIdle;
154                 break;
155         }
156         case stateIdle:
157                 break;
158         default:
159                 break;
160         }
161         return 0;
162 }
163
164 int eDVBCIMMISession::stopMMI()
165 {
166         printf("eDVBCIMMISession::stopMMI()\n");
167
168         unsigned char tag[]={0x9f, 0x88, 0x00};
169         unsigned char data[]={0x00};
170         sendAPDU(tag, data, 1);
171         
172         return 0;
173 }
174
175 int eDVBCIMMISession::answerText(int answer)
176 {
177         printf("eDVBCIMMISession::answerText(%d)\n",answer);
178
179         unsigned char tag[]={0x9f, 0x88, 0x0B};
180         unsigned char data[]={0x00};
181         data[0] = answer & 0xff;
182         sendAPDU(tag, data, 1);
183         
184         return 0;
185 }
186
187 int eDVBCIMMISession::cancelEnq()
188 {
189         printf("eDVBCIMMISession::cancelEnq()\n");
190
191         unsigned char tag[]={0x9f, 0x88, 0x08};
192         unsigned char data[]={0x00};
193         sendAPDU(tag, data, 1);
194         
195         return 0;
196 }
197