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