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