many changes for better CI handling
[enigma2.git] / lib / dvb_ci / dvbci_camgr.cpp
1 /* DVB CI CA Manager */
2
3 #include <lib/dvb_ci/dvbci_camgr.h>
4
5 eDVBCICAManagerSession::eDVBCICAManagerSession(eDVBCISlot *tslot)
6 {
7         slot = tslot;
8         slot->setCAManager(this);
9 }
10
11 eDVBCICAManagerSession::~eDVBCICAManagerSession()
12 {
13         slot->setCAManager(NULL);
14 }
15
16 int eDVBCICAManagerSession::receivedAPDU(const unsigned char *tag, const void *data, int len)
17 {
18         printf("SESSION(%d)/CA %02x %02x %02x: ", session_nb, tag[0], tag[1],tag[2]);
19         for (int i=0; i<len; i++)
20                 printf("%02x ", ((const unsigned char*)data)[i]);
21         printf("\n");
22
23         if ((tag[0]==0x9f) && (tag[1]==0x80))
24         {
25                 switch (tag[2])
26                 {
27                 case 0x31:
28                         printf("ca info:\n");
29                         for (int i=0; i<len; i+=2)
30                         {
31                                 printf("%04x ", (((const unsigned char*)data)[i]<<8)|(((const unsigned char*)data)[i+1]));
32                                 caids.push_back((((const unsigned char*)data)[i]<<8)|(((const unsigned char*)data)[i+1]));
33                         }
34                         std::sort(caids.begin(), caids.end());
35                         printf("\n");
36                         eDVBCIInterfaces::getInstance()->recheckPMTHandlers();
37                         break;
38                 default:
39                         printf("unknown APDU tag 9F 80 %02x\n", tag[2]);
40                         break;
41                 }
42         }
43         return 0;
44 }
45
46 int eDVBCICAManagerSession::doAction()
47 {
48         switch (state)
49         {
50         case stateStarted:
51         {
52                 const unsigned char tag[3]={0x9F, 0x80, 0x30}; // ca info enq
53                 sendAPDU(tag);
54                 state=stateFinal;
55                 return 0;
56         }
57         case stateFinal:
58                 printf("stateFinal und action! kann doch garnicht sein ;)\n");
59         default:
60                 return 0;
61         }
62 }
63
64 int eDVBCICAManagerSession::sendCAPMT(unsigned char *data, int len)
65 {
66         const unsigned char tag[3]={0x9F, 0x80, 0x32}; // ca_pmt
67
68         sendAPDU(tag, data, len);
69
70         return 0;
71 }
72