vdr  2.2.0
ci.h
Go to the documentation of this file.
1 /*
2  * ci.h: Common Interface
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: ci.h 3.11 2015/01/31 14:36:41 kls Exp $
8  */
9 
10 #ifndef __CI_H
11 #define __CI_H
12 
13 #include <stdint.h>
14 #include <stdio.h>
15 #include "channels.h"
16 #include "thread.h"
17 #include "tools.h"
18 
19 #define MAX_CAM_SLOTS_PER_ADAPTER 8 // maximum possible value is 255
20 #define MAX_CONNECTIONS_PER_CAM_SLOT 8 // maximum possible value is 254
21 #define CAM_READ_TIMEOUT 50 // ms
22 
23 class cCiMMI;
24 
25 class cCiMenu {
26  friend class cCamSlot;
27  friend class cCiMMI;
28 private:
29  enum { MAX_CIMENU_ENTRIES = 64 };
32  bool selectable;
33  char *titleText;
34  char *subTitleText;
35  char *bottomText;
38  bool AddEntry(char *s);
39  cCiMenu(cCiMMI *MMI, bool Selectable);
40 public:
41  ~cCiMenu();
42  const char *TitleText(void) { return titleText; }
43  const char *SubTitleText(void) { return subTitleText; }
44  const char *BottomText(void) { return bottomText; }
45  const char *Entry(int n) { return n < numEntries ? entries[n] : NULL; }
46  int NumEntries(void) { return numEntries; }
47  bool Selectable(void) { return selectable; }
48  void Select(int Index);
49  void Cancel(void);
50  void Abort(void);
51  bool HasUpdate(void);
52  };
53 
54 class cCiEnquiry {
55  friend class cCamSlot;
56  friend class cCiMMI;
57 private:
60  char *text;
61  bool blind;
63  cCiEnquiry(cCiMMI *MMI);
64 public:
65  ~cCiEnquiry();
66  const char *Text(void) { return text; }
67  bool Blind(void) { return blind; }
68  int ExpectedLength(void) { return expectedLength; }
69  void Reply(const char *s);
70  void Cancel(void);
71  void Abort(void);
72  };
73 
74 class cDevice;
75 class cCamSlot;
76 
78 
79 class cCiAdapter : public cThread {
80  friend class cCamSlot;
81 private:
83  void AddCamSlot(cCamSlot *CamSlot);
85 protected:
86  cCamSlot *ItCamSlot(int &Iter);
90  virtual void Action(void);
94  virtual int Read(uint8_t *Buffer, int MaxLength) { return 0; }
99  virtual void Write(const uint8_t *Buffer, int Length) {}
101  virtual bool Reset(int Slot) { return false; }
104  virtual eModuleStatus ModuleStatus(int Slot) { return msNone; }
106  virtual bool Assign(cDevice *Device, bool Query = false) { return false; }
115 public:
116  cCiAdapter(void);
117  virtual ~cCiAdapter();
119  /* ###### TODO: check if this patch is correct here ###### */
120  virtual bool SetIdle(bool Idle, bool TestOnly) { return false; }
121  virtual bool IsIdle(void) const { return false; }
122  };
123 
124 class cTPDU;
126 class cCiSession;
127 class cCiCaProgramData;
128 class cCaPidReceiver;
130 
131 class cCamSlot : public cListObject {
132  friend class cCiAdapter;
134 private:
143  cCiTransportConnection *tc[MAX_CONNECTIONS_PER_CAM_SLOT + 1]; // connection numbering starts with 1
145  time_t resetTime;
147  bool resendPmt;
148  int source;
151  const int *GetCaSystemIds(void);
152  void SendCaPmt(uint8_t CmdId);
153  void NewConnection(void);
154  void DeleteAllConnections(void);
155  void Process(cTPDU *TPDU = NULL);
156  void Write(cTPDU *TPDU);
157  cCiSession *GetSessionByResourceId(uint32_t ResourceId);
158 public:
159  cCamSlot(cCiAdapter *CiAdapter, bool WantsTsData = false);
166  virtual ~cCamSlot();
167  bool Assign(cDevice *Device, bool Query = false);
176  cDevice *Device(void) { return assignedDevice; }
178  bool WantsTsData(void) const { return caPidReceiver != NULL; }
181  int SlotIndex(void) { return slotIndex; }
184  int SlotNumber(void) { return slotNumber; }
187  virtual bool Reset(void);
190  virtual bool CanActivate(void);
193  virtual void StartActivation(void);
203  virtual void CancelActivation(void);
205  virtual bool IsActivating(void);
207  virtual eModuleStatus ModuleStatus(void);
209  virtual const char *GetCamName(void);
212  virtual bool Ready(void);
214  virtual bool HasMMI(void);
216  virtual bool HasUserIO(void);
219  virtual bool EnterMenu(void);
221  virtual cCiMenu *GetMenu(void);
223  virtual cCiEnquiry *GetEnquiry(void);
225  int Priority(void);
228  virtual bool ProvidesCa(const int *CaSystemIds);
235  virtual void AddPid(int ProgramNumber, int Pid, int StreamType);
238  virtual void SetPid(int Pid, bool Active);
242  virtual void AddChannel(const cChannel *Channel);
247  virtual bool CanDecrypt(const cChannel *Channel);
258  virtual void StartDecrypting(void);
261  virtual void StopDecrypting(void);
263  virtual bool IsDecrypting(void);
265  virtual uchar *Decrypt(uchar *Data, int &Count);
297  };
298 
299 class cCamSlots : public cList<cCamSlot> {
300 public:
301  bool WaitForAllCamSlotsReady(int Timeout = 0);
307  };
308 
309 extern cCamSlots CamSlots;
310 
311 class cChannelCamRelation;
312 
313 class cChannelCamRelations : public cList<cChannelCamRelation> {
314 private:
316  cChannelCamRelation *GetEntry(tChannelID ChannelID);
318  time_t lastCleanup;
319  void Cleanup(void);
320 public:
321  cChannelCamRelations(void);
322  void Reset(int CamSlotNumber);
323  bool CamChecked(tChannelID ChannelID, int CamSlotNumber);
324  bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber);
325  void SetChecked(tChannelID ChannelID, int CamSlotNumber);
326  void SetDecrypt(tChannelID ChannelID, int CamSlotNumber);
327  void ClrChecked(tChannelID ChannelID, int CamSlotNumber);
328  void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber);
329  };
330 
332 
333 #endif //__CI_H
Definition: ci.h:77
unsigned char uchar
Definition: tools.h:30
cMutex mutex
Definition: ci.h:135
virtual bool SetIdle(bool Idle, bool TestOnly)
Definition: ci.h:120
bool Process(cTPDU *TPDU=NULL)
Definition: ci.c:1560
Definition: ci.h:299
cCondVar processed
Definition: ci.h:136
cCamSlots CamSlots
Definition: ci.c:2235
friend class cCiAdapter
Definition: ci.h:132
bool HasUpdate(void)
Definition: ci.c:1329
virtual void Write(const uint8_t *Buffer, int Length)
Writes Length bytes of the given Buffer.
Definition: ci.h:99
int source
Definition: ci.h:148
#define MAX_CONNECTIONS_PER_CAM_SLOT
Definition: ci.h:20
cChannelCamRelations ChannelCamRelations
Definition: ci.c:2330
#define MAX_CAM_SLOTS_PER_ADAPTER
Definition: ci.h:19
Definition: ci.h:54
int slotNumber
Definition: ci.h:142
char * bottomText
Definition: ci.h:35
void Select(int Index)
Definition: ci.c:1335
Definition: ci.h:77
bool resendPmt
Definition: ci.h:147
cCiMMI * mmi
Definition: ci.h:58
time_t resetTime
Definition: ci.h:145
bool Selectable(void)
Definition: ci.h:47
cCiSession * GetSessionByResourceId(uint32_t ResourceId)
Definition: ci.c:1480
Definition: ci.c:1109
int SlotIndex(void)
Returns the index of this CAM slot within its CI adapter.
Definition: ci.h:181
int slotIndex
Definition: ci.h:141
int numEntries
Definition: ci.h:37
bool WantsTsData(void) const
Returns true if this CAM slot wants to receive the TS data through its Decrypt() function.
Definition: ci.h:178
virtual bool Reset(int Slot)
Resets the CAM in the given Slot.
Definition: ci.h:101
cCaActivationReceiver * caActivationReceiver
Definition: ci.h:140
bool blind
Definition: ci.h:61
char * titleText
Definition: ci.h:33
bool HasUserIO(void)
Definition: ci.c:441
~cCiMenu()
Definition: ci.c:1308
char * subTitleText
Definition: ci.h:34
bool Ready(void)
Definition: ci.c:1416
const char * Text(void)
Definition: ci.h:66
Definition: ci.c:524
int expectedLength
Definition: ci.h:62
void Cancel(void)
Definition: ci.c:1342
cList< cCiCaProgramData > caProgramList
Definition: ci.h:150
Definition: ci.h:79
virtual int Read(uint8_t *Buffer, int MaxLength)
Reads one chunk of data into the given Buffer, up to MaxLength bytes.
Definition: ci.h:94
eModuleStatus lastModuleStatus
Definition: ci.h:144
Definition: ci.h:131
friend class cCamSlot
Definition: ci.h:26
cCiAdapter * ciAdapter
Definition: ci.h:137
Definition: thread.h:63
Definition: ci.c:306
int transponder
Definition: ci.h:149
const char * GetCamName(void)
Definition: ci.c:1422
int ExpectedLength(void)
Definition: ci.h:68
cMutex mutex
Definition: ci.h:315
virtual bool IsIdle(void) const
Definition: ci.h:121
Definition: ci.h:25
virtual eModuleStatus ModuleStatus(int Slot)
Returns the status of the CAM in the given Slot.
Definition: ci.h:104
cDevice * assignedDevice
Definition: ci.h:138
char * entries[MAX_CIMENU_ENTRIES]
Definition: ci.h:36
const char * Entry(int n)
Definition: ci.h:45
cTimeMs moduleCheckTimer
Definition: ci.h:146
cCaPidReceiver * caPidReceiver
Definition: ci.h:139
int NumEntries(void)
Definition: ci.h:46
time_t lastCleanup
Definition: ci.h:318
cMutex * mutex
Definition: ci.h:31
Definition: thread.h:77
const char * SubTitleText(void)
Definition: ci.h:43
Definition: tools.h:333
eModuleStatus
Definition: ci.h:77
cCiMenu(cCiMMI *MMI, bool Selectable)
Definition: ci.c:1299
cCiMMI * mmi
Definition: ci.h:30
const char * BottomText(void)
Definition: ci.h:44
virtual bool Assign(cDevice *Device, bool Query=false)
Assigns this adapter to the given Device, if this is possible.
Definition: ci.h:106
void Abort(void)
Definition: ci.c:1347
Definition: ci.h:77
char * text
Definition: ci.h:60
cMutex * mutex
Definition: ci.h:59
int SlotNumber(void)
Returns the number of this CAM slot within the whole system.
Definition: ci.h:184
The cDevice class is the base from which actual devices can be derived.
Definition: device.h:109
bool selectable
Definition: ci.h:32
const char * TitleText(void)
Definition: ci.h:42
bool AddEntry(char *s)
Definition: ci.c:1320
bool Blind(void)
Definition: ci.h:67
Definition: ci.h:77
cDevice * Device(void)
Returns the device this CAM slot is currently assigned to.
Definition: ci.h:176