Extrenal srt problem gst-1 solved.
[openblackhole/openblackhole-enigma2.git] / 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         eDebugNoNewLineStart("[CI RM] 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         eDebugNoNewLine("\n");
12         if ((tag[0]==0x9f) && (tag[1]==0x80))
13         {
14                 switch (tag[2])
15                 {
16                 case 0x10:  // profile enquiry
17                         eDebug("[CI RM] cam profile inquiry");
18                         state=stateProfileEnquiry;
19                         return 1;
20                         break;
21                 case 0x11: // Tprofile
22                         eDebugNoNewLineStart("[CI RM] can do: ");
23                         if (!len)
24                                 eDebugNoNewLine("nothing");
25                         else
26                                 for (int i=0; i<len; i++)
27                                         eDebugNoNewLine("%02x ", ((const unsigned char*)data)[i]);
28                         eDebugNoNewLine("\n");
29
30                         if (state == stateFirstProfileEnquiry)
31                         {
32                                 // profile change
33                                 return 1;
34                         }
35                         state=stateFinal;
36                         break;
37                 default:
38                         eDebug("[CI RM] unknown APDU tag 9F 80 %02x", tag[2]);
39                 }
40         }
41
42         return 0;
43 }
44
45 int eDVBCIResourceManagerSession::doAction()
46 {
47         switch (state)
48         {
49         case stateStarted:
50         {
51                 const unsigned char tag[3]={0x9F, 0x80, 0x10}; // profile enquiry
52                 sendAPDU(tag);
53                 state = stateFirstProfileEnquiry;
54                 return 0;
55         }
56         case stateFirstProfileEnquiry:
57         {
58                 const unsigned char tag[3]={0x9F, 0x80, 0x12}; // profile change
59                 sendAPDU(tag);
60                 state=stateProfileChange;
61                 return 0;
62         }
63         case stateProfileChange:
64         {
65                 eDebug("[CI RM] cannot deal with statProfileChange");
66                 break;
67         }
68         case stateProfileEnquiry:
69         {
70                 const unsigned char tag[3]={0x9F, 0x80, 0x11};
71                 const unsigned char data[][4]=
72                         {
73                                 {0x00, 0x01, 0x00, 0x41},
74                                 {0x00, 0x02, 0x00, 0x41},
75                                 {0x00, 0x03, 0x00, 0x41},
76 //                              {0x00, 0x20, 0x00, 0x41}, // host control
77                                 {0x00, 0x24, 0x00, 0x41},
78                                 {0x00, 0x40, 0x00, 0x41},
79 //                              {0x00, 0x10, 0x00, 0x41}, // auth.
80                         };
81                 sendAPDU(tag, data, sizeof(data));
82                 state=stateFinal;
83                 return 0;
84         }
85         case stateFinal:
86                 eDebug("[CI RM] Should not happen: action on stateFinal");
87         default:
88                 break;
89         }
90         return 0;
91 }