openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
cahandler.h
Go to the documentation of this file.
1 #ifndef __DVB_CAHANDLER_H_
2 #define __DVB_CAHANDLER_H_
3 
5 
6 #ifndef SWIG
7 
9 #include <dvbsi++/program_map_section.h>
10 #include <lib/base/eptrlist.h>
11 #include <lib/dvb/idvb.h>
12 #include <lib/dvb/esection.h>
13 
14 /*
15  * eDVBCAHandler provides external clients with CAPMT objects
16  *
17  * The traditional way of receiving this information was by providing a listening
18  * socket on /tmp/camd.socket.
19  * For every channel change, a connection will be opened, and a CAPMT object is transmitted.
20  *
21  * This has a few disadvantages:
22  * 1. a new connection has to be opened for each channel change
23  * 2. only one external client can receive CAPMT objects
24  * 3. when the client restarts, it has no way of requesting the DVBCAHandler
25  * to reconnect
26  *
27  * To overcome these disadvantages, a new method has been added;
28  * eDVBCAHandler now also provides a serversocket on "/tmp/.listen.camd.socket".
29  * Clients can connect to this socket, and receive CAPMT objects as channel
30  * changes occur. The socket should be left open.
31  * Clients should check the ca_pmt_list_management field in the CAPMT objects, to
32  * determine whether an object is the first or last object in the list, an object in the middle,
33  * or perhaps an update for an existing service.
34  *
35  * the DVBCAHandler will immediately (re)transmit the current list of CAPMT objects when
36  * the client (re)connects.
37  *
38  */
39 
40 /* CAPMT client sockets */
41 #define PMT_SERVER_SOCKET "/tmp/.listen.camd.socket"
42 #define PMT_CLIENT_SOCKET "/tmp/camd.socket"
43 
44  /* ca_pmt_list_management values: */
45 
46 #define LIST_MORE 0x00
47  /* CA application should append a 'MORE' CAPMT object the list,
48  * and start receiving the next object
49  */
50 #define LIST_FIRST 0x01
51  /* CA application should clear the list when a 'FIRST' CAPMT object
52  * is received, and start receiving the next object
53  */
54 #define LIST_LAST 0x02
55  /* CA application should append a 'LAST' CAPMT object to the list,
56  * and start working with the list
57  */
58 #define LIST_ONLY 0x03
59  /* CA application should clear the list when an 'ONLY' CAPMT object
60  * is received, and start working with the object
61  */
62 #define LIST_ADD 0x04
63  /* CA application should append an 'ADD' CAPMT object to the current list,
64  * and start working with the updated list
65  */
66 #define LIST_UPDATE 0x05
67  /* CA application should replace an entry in the list with an
68  * 'UPDATE' CAPMT object, and start working with the updated list
69  */
70 
71 /* ca_pmt_cmd_id's: */
72 #define CMD_OK_DESCRAMBLING 0x01
73  /* CA application should start descrambling the service in this CAPMT object,
74  * as soon as the list of CAPMT objects is complete
75  */
76 #define CMD_OK_MMI 0x02
77 #define CMD_QUERY 0x03
78 #define CMD_NOT_SELECTED 0x04
79  /* CA application should stop descrambling this service
80  * (used when the last service in a list has left, note
81  * that there is no CI definition to send an empty list)
82  */
83 
84 class eDVBCAHandler;
85 
87 {
88  unsigned char receivedTag[4];
89  int receivedLength;
90  unsigned char *receivedValue;
91  char *displayText;
92 protected:
94  void connectionLost();
95  void dataAvailable();
96  void clientTLVReceived(unsigned char *tag, int length, unsigned char *value);
97  void parseTLVObjects(unsigned char *data, int size);
98 public:
99  ePMTClient(eDVBCAHandler *handler, int socket);
100 };
101 
103 {
104  eServiceReferenceDVB m_service;
105  uint8_t m_used_demux[8];
106  uint8_t m_adapter;
107  uint32_t m_service_type_mask;
108  uint64_t m_prev_build_hash;
109  uint32_t m_crc32;
110  int m_version;
111  unsigned char m_capmt[2048];
112  ePtr<eTimer> m_retryTimer;
113 public:
115  ~eDVBCAService();
116 
117  std::string toString();
118  int getCAPMTVersion();
119  int getNumberOfDemuxes();
120  uint8_t getUsedDemux(int index);
121  void setUsedDemux(int index, uint8_t value);
122  uint8_t getAdapter();
123  void setAdapter(uint8_t value);
124  void addServiceType(int type);
125  void sendCAPMT();
126  int writeCAPMTObject(eSocket *socket, int list_management = -1);
128  int buildCAPMT(ePtr<eDVBService> &dvbservice);
129  void connectionLost();
130 };
131 
132 typedef std::map<eServiceReferenceDVB, eDVBCAService*> CAServiceMap;
133 
134 #endif
135 
137 class iCryptoInfo : public iObject
138 {
139 #ifdef SWIG
140 public:
141  iCryptoInfo();
142  ~iCryptoInfo();
143 private:
144 #endif
145 public:
152 };
154 
155 #ifndef SWIG
157 #else
158 class eDVBCAHandler : public iCryptoInfo
159 #endif
160 {
161 DECLARE_REF(eDVBCAHandler);
162 #ifndef SWIG
163  CAServiceMap services;
164  ePtrList<ePMTClient> clients;
165  ePtr<eTimer> serviceLeft;
166  std::map<eServiceReferenceDVB, ePtr<eTable<ProgramMapSection> > > pmtCache;
167 
168  void newConnection(int socket);
169  void processPMTForService(eDVBCAService *service, eTable<ProgramMapSection> *ptr);
170  void distributeCAPMT();
171  void serviceGone();
172 #endif
173  static eDVBCAHandler *instance;
174 public:
175  eDVBCAHandler();
176 #ifndef SWIG
177  ~eDVBCAHandler();
178 
179  int registerService(const eServiceReferenceDVB &service, int adapter, int demux_nums[2], int servicetype, eDVBCAService *&caservice);
180  int unregisterService(const eServiceReferenceDVB &service , int adapter, int demux_nums[2], eTable<ProgramMapSection> *ptr);
182  void handlePMT(const eServiceReferenceDVB &service, ePtr<eDVBService> &dvbservice);
183  void connectionLost(ePMTClient *client);
184 
185  static eDVBCAHandler *getInstance() { return instance; }
186 #endif
187  static SWIG_VOID(RESULT) getCryptoInfo(ePtr<iCryptoInfo> &SWIG_NAMED_OUTPUT(ptr)) { ptr = instance; return 0; }
188 };
189 
190 #endif // __DVB_CAHANDLER_H_
static int ptr
Definition: bcm.cpp:17
SWIG_IGNORE(iCryptoInfo)
SWIG_TEMPLATE_TYPEDEF(ePtr< iCryptoInfo >, iCryptoInfoPtr)
std::map< eServiceReferenceDVB, eDVBCAService * > CAServiceMap
Definition: cahandler.h:132
Definition: cahandler.h:160
~eDVBCAHandler()
Definition: cahandler.cpp:224
int unregisterService(const eServiceReferenceDVB &service, int adapter, int demux_nums[2], eTable< ProgramMapSection > *ptr)
Definition: cahandler.cpp:311
eDVBCAHandler()
Definition: cahandler.cpp:214
static eDVBCAHandler * getInstance()
Definition: cahandler.h:185
void handlePMT(const eServiceReferenceDVB &service, ePtr< eTable< ProgramMapSection > > &ptr)
Definition: cahandler.cpp:454
static SWIG_VOID(RESULT) getCryptoInfo(ePtr< iCryptoInfo > &SWIG_NAMED_OUTPUT(ptr))
Definition: cahandler.h:187
int registerService(const eServiceReferenceDVB &service, int adapter, int demux_nums[2], int servicetype, eDVBCAService *&caservice)
Definition: cahandler.cpp:256
void connectionLost(ePMTClient *client)
Definition: cahandler.cpp:246
Definition: cahandler.h:103
void setUsedDemux(int index, uint8_t value)
Definition: cahandler.cpp:521
int getNumberOfDemuxes()
Definition: cahandler.cpp:510
int getCAPMTVersion()
Definition: cahandler.cpp:505
int buildCAPMT(eTable< ProgramMapSection > *ptr)
Definition: cahandler.cpp:548
void setAdapter(uint8_t value)
Definition: cahandler.cpp:532
uint8_t getAdapter()
Definition: cahandler.cpp:527
void addServiceType(int type)
Definition: cahandler.cpp:537
uint8_t getUsedDemux(int index)
Definition: cahandler.cpp:515
void sendCAPMT()
Definition: cahandler.cpp:895
~eDVBCAService()
Definition: cahandler.cpp:495
void connectionLost()
Definition: cahandler.cpp:542
eDVBCAService(const eServiceReferenceDVB &service)
Definition: cahandler.cpp:487
int writeCAPMTObject(eSocket *socket, int list_management=-1)
Definition: cahandler.cpp:914
std::string toString()
Definition: cahandler.cpp:500
Definition: cahandler.h:87
void dataAvailable()
Definition: cahandler.cpp:31
void clientTLVReceived(unsigned char *tag, int length, unsigned char *value)
Definition: cahandler.cpp:119
void parseTLVObjects(unsigned char *data, int size)
Definition: cahandler.cpp:86
eDVBCAHandler * parent
Definition: cahandler.h:93
ePMTClient(eDVBCAHandler *handler, int socket)
Definition: cahandler.cpp:16
void connectionLost()
Definition: cahandler.cpp:26
Definition: serversocket.h:7
Definition: idvb.h:192
Definition: socket.h:19
Definition: esection.h:41
Definition: socket.h:65
Definition: cahandler.h:138
PSignal1< void, const char * > clientinfo
Definition: cahandler.h:147
PSignal1< void, int > decodetime
Definition: cahandler.h:150
PSignal1< void, int > usedcaid
Definition: cahandler.h:149
PSignal1< void, const char * > usedcardid
Definition: cahandler.h:151
PSignal1< void, const char * > verboseinfo
Definition: cahandler.h:148
PSignal1< void, const char * > clientname
Definition: cahandler.h:146
Definition: object.h:15
unsigned char length
Definition: hdmi_cec.h:1
unsigned char data[256]
Definition: hdmi_cec.h:2
int socket(int domain, int type, int protocol)
Definition: libopen.c:165
size
Definition: Plugins/SystemPlugins/PositionerSetup/log.py:16
value
Definition: Profile.py:29
string servicetype
Definition: create_picon_e1_to_e2.py:28
index
Definition: main.py:28
int RESULT
Definition: object.h:12
Definition: dvb/scan.h:16
#define SWIG_NAMED_OUTPUT(x)
Definition: swig.h:21