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  };
120 
121 class cTPDU;
123 class cCiSession;
124 class cCiCaProgramData;
125 class cCaPidReceiver;
127 
128 class cCamSlot : public cListObject {
129  friend class cCiAdapter;
131 private:
140  cCiTransportConnection *tc[MAX_CONNECTIONS_PER_CAM_SLOT + 1]; // connection numbering starts with 1
142  time_t resetTime;
144  bool resendPmt;
145  int source;
148  const int *GetCaSystemIds(void);
149  void SendCaPmt(uint8_t CmdId);
150  void NewConnection(void);
151  void DeleteAllConnections(void);
152  void Process(cTPDU *TPDU = NULL);
153  void Write(cTPDU *TPDU);
154  cCiSession *GetSessionByResourceId(uint32_t ResourceId);
155 public:
156  cCamSlot(cCiAdapter *CiAdapter, bool WantsTsData = false);
163  virtual ~cCamSlot();
164  bool Assign(cDevice *Device, bool Query = false);
173  cDevice *Device(void) { return assignedDevice; }
175  bool WantsTsData(void) const { return caPidReceiver != NULL; }
178  int SlotIndex(void) { return slotIndex; }
181  int SlotNumber(void) { return slotNumber; }
184  virtual bool Reset(void);
187  virtual bool CanActivate(void);
190  virtual void StartActivation(void);
200  virtual void CancelActivation(void);
202  virtual bool IsActivating(void);
204  virtual eModuleStatus ModuleStatus(void);
206  virtual const char *GetCamName(void);
209  virtual bool Ready(void);
211  virtual bool HasMMI(void);
213  virtual bool HasUserIO(void);
216  virtual bool EnterMenu(void);
218  virtual cCiMenu *GetMenu(void);
220  virtual cCiEnquiry *GetEnquiry(void);
222  int Priority(void);
225  virtual bool ProvidesCa(const int *CaSystemIds);
232  virtual void AddPid(int ProgramNumber, int Pid, int StreamType);
235  virtual void SetPid(int Pid, bool Active);
239  virtual void AddChannel(const cChannel *Channel);
244  virtual bool CanDecrypt(const cChannel *Channel);
255  virtual void StartDecrypting(void);
258  virtual void StopDecrypting(void);
260  virtual bool IsDecrypting(void);
262  virtual uchar *Decrypt(uchar *Data, int &Count);
294  };
295 
296 class cCamSlots : public cList<cCamSlot> {
297 public:
298  bool WaitForAllCamSlotsReady(int Timeout = 0);
304  };
305 
306 extern cCamSlots CamSlots;
307 
308 class cChannelCamRelation;
309 
310 class cChannelCamRelations : public cList<cChannelCamRelation> {
311 private:
313  cChannelCamRelation *GetEntry(tChannelID ChannelID);
315  time_t lastCleanup;
316  void Cleanup(void);
317 public:
318  cChannelCamRelations(void);
319  void Reset(int CamSlotNumber);
320  bool CamChecked(tChannelID ChannelID, int CamSlotNumber);
321  bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber);
322  void SetChecked(tChannelID ChannelID, int CamSlotNumber);
323  void SetDecrypt(tChannelID ChannelID, int CamSlotNumber);
324  void ClrChecked(tChannelID ChannelID, int CamSlotNumber);
325  void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber);
326  };
327 
329 
330 #endif //__CI_H
Definition: ci.h:77
unsigned char uchar
Definition: tools.h:30
cMutex mutex
Definition: ci.h:132
bool Process(cTPDU *TPDU=NULL)
Definition: ci.c:1560
Definition: ci.h:296
cCondVar processed
Definition: ci.h:133
cCamSlots CamSlots
Definition: ci.c:2240
friend class cCiAdapter
Definition: ci.h:129
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:145
#define MAX_CONNECTIONS_PER_CAM_SLOT
Definition: ci.h:20
cChannelCamRelations ChannelCamRelations
Definition: ci.c:2335
#define MAX_CAM_SLOTS_PER_ADAPTER
Definition: ci.h:19
Definition: ci.h:54
int slotNumber
Definition: ci.h:139
char * bottomText
Definition: ci.h:35
void Select(int Index)
Definition: ci.c:1335
Definition: ci.h:77
bool resendPmt
Definition: ci.h:144
cCiMMI * mmi
Definition: ci.h:58
time_t resetTime
Definition: ci.h:142
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:178
int slotIndex
Definition: ci.h:138
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:175
virtual bool Reset(int Slot)
Resets the CAM in the given Slot.
Definition: ci.h:101
cCaActivationReceiver * caActivationReceiver
Definition: ci.h:137
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:147
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:141
Definition: ci.h:128
friend class cCamSlot
Definition: ci.h:26
cCiAdapter * ciAdapter
Definition: ci.h:134
Definition: thread.h:63
Definition: ci.c:306
int transponder
Definition: ci.h:146
const char * GetCamName(void)
Definition: ci.c:1422
int ExpectedLength(void)
Definition: ci.h:68
cMutex mutex
Definition: ci.h:312
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:135
char * entries[MAX_CIMENU_ENTRIES]
Definition: ci.h:36
const char * Entry(int n)
Definition: ci.h:45
cTimeMs moduleCheckTimer
Definition: ci.h:143
cCaPidReceiver * caPidReceiver
Definition: ci.h:136
int NumEntries(void)
Definition: ci.h:46
time_t lastCleanup
Definition: ci.h:315
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:181
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:173