CI mmi is now working every time (for support alphacrypt parental control or other...
[enigma2.git] / lib / dvb_ci / dvbci_appmgr.cpp
1 /* DVB CI Application Manager */
2
3 #include <lib/dvb_ci/dvbci_appmgr.h>
4 #include <lib/dvb_ci/dvbci_ui.h>
5
6 eDVBCIApplicationManagerSession::eDVBCIApplicationManagerSession(eDVBCISlot *tslot)
7 {
8         slot = tslot;
9         slot->setAppManager(this);
10 }
11
12 eDVBCIApplicationManagerSession::~eDVBCIApplicationManagerSession()
13 {
14         slot->setAppManager(NULL);
15 }
16
17 int eDVBCIApplicationManagerSession::receivedAPDU(const unsigned char *tag,const void *data, int len)
18 {
19         printf("SESSION(%d)/APP %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
20         for (int i=0; i<len; i++)
21                 printf("%02x ", ((const unsigned char*)data)[i]);
22         printf("\n");
23
24         if ((tag[0]==0x9f) && (tag[1]==0x80))
25         {
26                 switch (tag[2])
27                 {
28                 case 0x21:
29                 {
30                         int dl;
31                         printf("application info:\n");
32                         printf("  len: %d\n", len);
33                         printf("  application_type: %d\n", ((unsigned char*)data)[0]);
34                         printf("  application_manufacturer: %02x %02x\n", ((unsigned char*)data)[2], ((unsigned char*)data)[1]);
35                         printf("  manufacturer_code: %02x %02x\n", ((unsigned char*)data)[4],((unsigned char*)data)[3]);
36                         printf("  menu string: ");
37                         dl=((unsigned char*)data)[5];
38                         if ((dl + 6) > len)
39                         {
40                                 printf("warning, invalid length (%d vs %d)\n", dl+6, len);
41                                 dl=len-6;
42                         }
43                         char str[dl + 1];
44                         memcpy(str, ((char*)data) + 6, dl);
45                         str[dl] = '\0';
46                         for (int i = 0; i < dl; ++i)
47                                 printf("%c", ((unsigned char*)data)[i+6]);
48                         printf("\n");
49
50                         eDVBCI_UI::getInstance()->setAppName(slot->getSlotID(), str);
51
52                         eDVBCI_UI::getInstance()->setState(slot->getSlotID(), 2);
53                         break;
54                 }
55                 default:
56                         printf("unknown APDU tag 9F 80 %02x\n", tag[2]);
57                         break;
58                 }
59         }
60         return 0;
61 }
62
63 int eDVBCIApplicationManagerSession::doAction()
64 {
65   switch (state)
66   {
67   case stateStarted:
68   {
69     const unsigned char tag[3]={0x9F, 0x80, 0x20}; // application manager info e    sendAPDU(tag);
70                 sendAPDU(tag);
71     state=stateFinal;
72     return 1;
73   }
74   case stateFinal:
75     printf("in final state.\n");
76                 wantmenu = 0;
77     if (wantmenu)
78     {
79       printf("wantmenu: sending Tenter_menu\n");
80       const unsigned char tag[3]={0x9F, 0x80, 0x22};  // Tenter_menu
81       sendAPDU(tag);
82       wantmenu=0;
83       return 0;
84     } else
85       return 0;
86   default:
87     return 0;
88   }
89 }
90
91 int eDVBCIApplicationManagerSession::startMMI()
92 {
93         printf("in appmanager -> startmmi()\n");
94         const unsigned char tag[3]={0x9F, 0x80, 0x22};  // Tenter_menu
95         sendAPDU(tag);
96         return 0;
97 }
98