re-add mutex_unlock after pthread_cond_wait,
[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
28                         if (state == stateFirstProfileEnquiry)
29                         {
30                                 // profile change
31                                 return 1;
32                         }
33                         state=stateFinal;
34                         break;
35                 default:
36                         printf("unknown APDU tag 9F 80 %02x\n", tag[2]);
37                 }
38         }
39         
40         return 0;
41 }
42
43 int eDVBCIResourceManagerSession::doAction()
44 {
45         switch (state)
46         {
47         case stateStarted:
48         {
49                 const unsigned char tag[3]={0x9F, 0x80, 0x10}; // profile enquiry
50                 sendAPDU(tag);
51                 state = stateFirstProfileEnquiry;
52                 return 0;
53         }
54         case stateFirstProfileEnquiry:
55         {
56                 const unsigned char tag[3]={0x9F, 0x80, 0x12}; // profile change
57                 sendAPDU(tag);
58                 state=stateProfileChange;
59                 return 0;
60         }
61   case stateProfileChange:
62   {
63     printf("bla kaputt\n");
64     break;
65   }
66         case stateProfileEnquiry:
67         {
68                 const unsigned char tag[3]={0x9F, 0x80, 0x11};
69                 const unsigned char data[][4]=
70                         {
71                                 {0x00, 0x01, 0x00, 0x41},
72                                 {0x00, 0x02, 0x00, 0x41},
73                                 {0x00, 0x03, 0x00, 0x41},
74                                 {0x00, 0x20, 0x00, 0x41},
75                                 {0x00, 0x24, 0x00, 0x41},
76                                 {0x00, 0x40, 0x00, 0x41},
77                                 {0x00, 0x10, 0x00, 0x41}, // auth.
78                         };
79                 sendAPDU(tag, data, sizeof(data));
80                 state=stateFinal;
81                 return 0;
82         }
83         case stateFinal:
84                 printf("stateFinal und action! kann doch garnicht sein ;)\n");
85         default:
86                 break;
87         }
88         return 0;
89 }