add stuff
[enigma2.git] / lib / dvb_ci / dvbci_mmi.cpp
1 /* DVB CI MMI */
2
3 #include <lib/dvb_ci/dvbci_mmi.h>
4
5 int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len)
6 {
7         printf("SESSION(%d)/MMI %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
8         for (int i=0; i<len; i++)
9                 printf("%02x ", ((const unsigned char*)data)[i]);
10         printf("\n");
11
12         if ((tag[0]==0x9f) && (tag[1]==0x88))
13         {
14                 switch (tag[2])
15                 {
16                         case 0x01:
17                         printf("MMI display control\n");
18                         if (((unsigned char*)data)[0] != 1)
19                                 printf("kann ich nicht. aber das sag ich dem modul nicht.\n");
20                         state=stateDisplayReply;
21                         return 1;
22                 case 0x09:
23                 case 0x0c:
24                 {
25                         unsigned char *d=(unsigned char*)data;
26                         unsigned char *max=((unsigned char*)d) + len;
27                         printf("Tmenu_last\n");
28                         if (d > max)
29                                 break;
30                         int n=*d++;
31                         if (n == 0xFF)
32                                 n=0;
33                         else
34                                 n++;
35                         printf("%d texts\n", n);
36                         for (int i=0; i < (n+3); ++i)
37                         {
38                                 int textlen;
39                                 if ((d+3) > max)
40                                         break;
41                                 printf("text tag: %02x %02x %02x\n", d[0], d[1], d[2]);
42                                 d+=3;
43                                 d+=parseLengthField(d, textlen);
44                                 printf("%d bytes text\n", textlen);
45                                 if ((d+textlen) > max)
46                                         break;
47                                 while (textlen--)
48                                         printf("%c", *d++);
49                                 printf("\n");
50                         }
51                         break;
52                 }
53                 default:
54                         printf("unknown APDU tag 9F 88 %02x\n", tag[2]);
55                         break;
56                 }
57         }
58         return 0;
59 }
60
61 int eDVBCIMMISession::doAction()
62 {
63         switch (state)
64         {
65         case stateStarted:
66                 state=stateIdle;
67                 break;
68         case stateDisplayReply:
69         {
70                 unsigned char tag[]={0x9f, 0x88, 0x02};
71                 unsigned char data[]={0x01, 0x01};
72                 sendAPDU(tag, data, 2);
73                 state=stateFakeOK;
74                 return 1;
75                 break;
76         }
77         case stateFakeOK:
78         {
79                 unsigned char tag[]={0x9f, 0x88, 0x0b};
80                 unsigned char data[]={5};
81                 sendAPDU(tag, data, 1);
82                 state=stateIdle;
83                 break;
84         }
85         case stateIdle:
86                 break;
87         default:
88                 break;
89         }
90         return 0;
91 }
92