fix absolute paths to be relative
[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()->setState(0,2);
51                         eDVBCI_UI::getInstance()->setAppName(0,str);
52                         break;
53                 }
54                 default:
55                         printf("unknown APDU tag 9F 80 %02x\n", tag[2]);
56                         break;
57                 }
58         }
59         return 0;
60 }
61
62 int eDVBCIApplicationManagerSession::doAction()
63 {
64   switch (state)
65   {
66   case stateStarted:
67   {
68     const unsigned char tag[3]={0x9F, 0x80, 0x20}; // application manager info e    sendAPDU(tag);
69                 sendAPDU(tag);
70     state=stateFinal;
71     return 1;
72   }
73   case stateFinal:
74     printf("in final state.\n");
75                 wantmenu = 0;
76     if (wantmenu)
77     {
78       printf("wantmenu: sending Tenter_menu\n");
79       const unsigned char tag[3]={0x9F, 0x80, 0x22};  // Tenter_menu
80       sendAPDU(tag);
81       wantmenu=0;
82       return 0;
83     } else
84       return 0;
85   default:
86     return 0;
87   }
88 }
89
90 int eDVBCIApplicationManagerSession::startMMI()
91 {
92         printf("in appmanager -> startmmi()\n");
93         const unsigned char tag[3]={0x9F, 0x80, 0x22};  // Tenter_menu
94         sendAPDU(tag);
95         return 0;
96 }
97