remove obsolete .cvsignore files
[vuplus_dvbapp] / lib / dvb_ci / dvbci_resmgr.cpp
1 /* DVB CI Resource Manager */
2
3 #include <lib/base/eerror.h>
4 #include <lib/dvb_ci/dvbci_resmgr.h>
5
6 int eDVBCIResourceManagerSession::receivedAPDU(const unsigned char *tag,const void *data, int len)
7 {
8         eDebugNoNewLine("SESSION(%d) %02x %02x %02x: ", session_nb, tag[0], tag[1], tag[2]);
9         for (int i=0; i<len; i++)
10                 eDebugNoNewLine("%02x ", ((const unsigned char*)data)[i]);
11         eDebug("");
12         if ((tag[0]==0x9f) && (tag[1]==0x80))
13         {
14                 switch (tag[2])
15                 {
16                 case 0x10:  // profile enquiry
17                         eDebug("cam fragt was ich kann.");
18                         state=stateProfileEnquiry;
19                         return 1;
20                         break;
21                 case 0x11: // Tprofile
22                         eDebugNoNewLine("mein cam kann: ");
23                         if (!len)
24                                 eDebug("nichts");
25                         else
26                                 for (int i=0; i<len; i++)
27                                         eDebugNoNewLine("%02x ", ((const unsigned char*)data)[i]);
28
29                         if (state == stateFirstProfileEnquiry)
30                         {
31                                 // profile change
32                                 return 1;
33                         }
34                         state=stateFinal;
35                         break;
36                 default:
37                         eDebug("unknown APDU tag 9F 80 %02x", tag[2]);
38                 }
39         }
40         
41         return 0;
42 }
43
44 int eDVBCIResourceManagerSession::doAction()
45 {
46         switch (state)
47         {
48         case stateStarted:
49         {
50                 const unsigned char tag[3]={0x9F, 0x80, 0x10}; // profile enquiry
51                 sendAPDU(tag);
52                 state = stateFirstProfileEnquiry;
53                 return 0;
54         }
55         case stateFirstProfileEnquiry:
56         {
57                 const unsigned char tag[3]={0x9F, 0x80, 0x12}; // profile change
58                 sendAPDU(tag);
59                 state=stateProfileChange;
60                 return 0;
61         }
62         case stateProfileChange:
63         {
64                 eDebug("bla kaputt");
65                 break;
66         }
67         case stateProfileEnquiry:
68         {
69                 const unsigned char tag[3]={0x9F, 0x80, 0x11};
70                 const unsigned char data[][4]=
71                         {
72                                 {0x00, 0x01, 0x00, 0x41},
73                                 {0x00, 0x02, 0x00, 0x41},
74                                 {0x00, 0x03, 0x00, 0x41},
75 //                              {0x00, 0x20, 0x00, 0x41}, // host control
76                                 {0x00, 0x24, 0x00, 0x41},
77                                 {0x00, 0x40, 0x00, 0x41},
78 //                              {0x00, 0x10, 0x00, 0x41}, // auth.
79                         };
80                 sendAPDU(tag, data, sizeof(data));
81                 state=stateFinal;
82                 return 0;
83         }
84         case stateFinal:
85                 eDebug("stateFinal und action! kann doch garnicht sein ;)");
86         default:
87                 break;
88         }
89         return 0;
90 }