vdr  2.0.4
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 2.2 2012/02/29 10:24:27 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:
84  void AddCamSlot(cCamSlot *CamSlot);
86 protected:
87  virtual void Action(void);
91  virtual int Read(uint8_t *Buffer, int MaxLength) = 0;
96  virtual void Write(const uint8_t *Buffer, int Length) = 0;
98  virtual bool Reset(int Slot) = 0;
101  virtual eModuleStatus ModuleStatus(int Slot) = 0;
103  virtual bool Assign(cDevice *Device, bool Query = false) = 0;
112 public:
113  cCiAdapter(void);
114  virtual ~cCiAdapter();
116  virtual bool Ready(void);
118  };
119 
120 class cTPDU;
122 class cCiSession;
123 class cCiCaProgramData;
124 
125 class cCamSlot : public cListObject {
126  friend class cCiAdapter;
128 private:
134  cCiTransportConnection *tc[MAX_CONNECTIONS_PER_CAM_SLOT + 1]; // connection numbering starts with 1
136  time_t resetTime;
138  bool resendPmt;
139  int source;
142  const int *GetCaSystemIds(void);
143  void SendCaPmt(uint8_t CmdId);
144  void NewConnection(void);
145  void DeleteAllConnections(void);
146  void Process(cTPDU *TPDU = NULL);
147  void Write(cTPDU *TPDU);
148  cCiSession *GetSessionByResourceId(uint32_t ResourceId);
149 public:
150  cCamSlot(cCiAdapter *CiAdapter);
154  virtual ~cCamSlot();
155  bool Assign(cDevice *Device, bool Query = false);
164  cDevice *Device(void);
166  int SlotIndex(void) { return slotIndex; }
169  int SlotNumber(void) { return slotNumber; }
172  bool Reset(void);
177  const char *GetCamName(void);
180  bool Ready(void);
182  bool HasMMI(void);
184  bool HasUserIO(void);
187  bool EnterMenu(void);
189  cCiMenu *GetMenu(void);
191  cCiEnquiry *GetEnquiry(void);
193  int Priority(void);
196  bool ProvidesCa(const int *CaSystemIds);
203  void AddPid(int ProgramNumber, int Pid, int StreamType);
206  void SetPid(int Pid, bool Active);
210  void AddChannel(const cChannel *Channel);
215  bool CanDecrypt(const cChannel *Channel);
226  void StartDecrypting(void);
229  void StopDecrypting(void);
231  bool IsDecrypting(void);
233  };
234 
235 class cCamSlots : public cList<cCamSlot> {};
236 
237 extern cCamSlots CamSlots;
238 
239 class cChannelCamRelation;
240 
241 class cChannelCamRelations : public cList<cChannelCamRelation> {
242 private:
246  time_t lastCleanup;
247  void Cleanup(void);
248 public:
249  cChannelCamRelations(void);
250  void Reset(int CamSlotNumber);
251  bool CamChecked(tChannelID ChannelID, int CamSlotNumber);
252  bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber);
253  void SetChecked(tChannelID ChannelID, int CamSlotNumber);
254  void SetDecrypt(tChannelID ChannelID, int CamSlotNumber);
255  void ClrChecked(tChannelID ChannelID, int CamSlotNumber);
256  void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber);
257  };
258 
260 
261 #endif //__CI_H
Definition: ci.h:77
cMutex mutex
Definition: ci.h:129
virtual void Action(void)
Handles the attached CAM slots in a separate thread.
Definition: ci.c:1529
Definition: ci.h:235
bool ProvidesCa(const int *CaSystemIds)
Returns true if the CAM in this slot provides one of the given CaSystemIds.
Definition: ci.c:1848
cCondVar processed
Definition: ci.h:130
virtual ~cCiAdapter()
The derived class must call Cancel(3) in its destructor.
Definition: ci.c:1499
void AddPid(int ProgramNumber, int Pid, int StreamType)
Adds the given PID information to the list of PIDs.
Definition: ci.c:1863
bool HasUpdate(void)
Definition: ci.c:1141
int source
Definition: ci.h:139
void StartDecrypting(void)
Triggers sending all currently active CA_PMT entries to the CAM, so that it will start decrypting...
Definition: ci.c:1961
#define MAX_CONNECTIONS_PER_CAM_SLOT
Definition: ci.h:20
virtual bool Reset(int Slot)=0
Resets the CAM in the given Slot.
#define MAX_CAM_SLOTS_PER_ADAPTER
Definition: ci.h:19
Definition: ci.h:54
int slotNumber
Definition: ci.h:133
char * bottomText
Definition: ci.h:35
void Select(int Index)
Definition: ci.c:1147
virtual eModuleStatus ModuleStatus(int Slot)=0
Returns the status of the CAM in the given Slot.
Definition: ci.h:77
virtual void Write(const uint8_t *Buffer, int Length)=0
Writes Length bytes of the given Buffer.
bool resendPmt
Definition: ci.h:138
cCiMMI * mmi
Definition: ci.h:58
virtual bool Ready(void)
Returns &#39;true&#39; if all present CAMs in this adapter are ready.
Definition: ci.c:1520
time_t resetTime
Definition: ci.h:136
bool Selectable(void)
Definition: ci.h:47
cCiAdapter(void)
Definition: ci.c:1491
Definition: ci.c:921
int SlotIndex(void)
Returns the index of this CAM slot within its CI adapter.
Definition: ci.h:166
int slotIndex
Definition: ci.h:132
void NewConnection(void)
Definition: ci.c:1617
eModuleStatus ModuleStatus(void)
Returns the status of the CAM in this slot.
Definition: ci.c:1726
int numEntries
Definition: ci.h:37
void AddChannel(const cChannel *Channel)
Adds all PIDs if the given Channel to the current list of PIDs.
Definition: ci.c:1902
void Write(cTPDU *TPDU)
Definition: ci.c:1699
void Cleanup(void)
Definition: ci.c:2075
void SendCaPmt(uint8_t CmdId)
Definition: ci.c:1796
cCiTransportConnection * tc[MAX_CONNECTIONS_PER_CAM_SLOT+1]
Definition: ci.h:134
bool blind
Definition: ci.h:61
char * titleText
Definition: ci.h:33
cDevice * Device(void)
Returns the device this CAM slot is currently assigned to.
Definition: ci.c:1606
cCiSession * GetSessionByResourceId(uint32_t ResourceId)
Definition: ci.c:1693
~cCiMenu()
Definition: ci.c:1120
virtual ~cCamSlot()
Definition: ci.c:1572
char * subTitleText
Definition: ci.h:34
cCiEnquiry(cCiMMI *MMI)
Definition: ci.c:1168
void Process(cTPDU *TPDU=NULL)
Definition: ci.c:1639
const char * Text(void)
Definition: ci.h:66
bool HasUserIO(void)
Returns true if there is a pending user interaction, which shall be retrieved via GetMenu() or GetEnq...
Definition: ci.c:1757
void SetDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2140
bool CanDecrypt(const cChannel *Channel)
Returns true if there is a CAM in this slot that is able to decrypt the given Channel (or at least cl...
Definition: ci.c:1924
cCiMenu * GetMenu(void)
Gets a pending menu, or NULL if there is no menu.
Definition: ci.c:1770
Definition: ci.c:342
int expectedLength
Definition: ci.h:62
void Cancel(void)
Definition: ci.c:1154
cList< cCiCaProgramData > caProgramList
Definition: ci.h:141
Definition: ci.h:79
bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2125
eModuleStatus lastModuleStatus
Definition: ci.h:135
Definition: ci.h:125
void AddCamSlot(cCamSlot *CamSlot)
Adds the given CamSlot to this CI adapter.
Definition: ci.c:1506
cCiAdapter * ciAdapter
Definition: ci.h:131
Definition: thread.h:63
Definition: ci.c:124
const int * GetCaSystemIds(void)
Definition: ci.c:1835
bool Reset(void)
Resets the CAM in this slot.
Definition: ci.c:1708
bool IsDecrypting(void)
Returns true if the CAM in this slot is currently used for decrypting.
Definition: ci.c:1975
int transponder
Definition: ci.h:140
void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2156
void SetPid(int Pid, bool Active)
Sets the given Pid (which has previously been added through a call to AddPid()) to Active...
Definition: ci.c:1881
cCamSlot * camSlots[MAX_CAM_SLOTS_PER_ADAPTER]
Definition: ci.h:83
int ExpectedLength(void)
Definition: ci.h:68
cCiEnquiry * GetEnquiry(void)
Gets a pending enquiry, or NULL if there is no enquiry.
Definition: ci.c:1783
cChannelCamRelation * AddEntry(tChannelID ChannelID)
Definition: ci.c:2100
cMutex mutex
Definition: ci.h:243
~cCiEnquiry()
Definition: ci.c:1176
void Reply(const char *s)
Definition: ci.c:1184
Definition: ci.h:25
bool HasMMI(void)
Returns &#39;true&#39; if the CAM in this slot has an active MMI.
Definition: ci.c:1752
virtual int Read(uint8_t *Buffer, int MaxLength)=0
Reads one chunk of data into the given Buffer, up to MaxLength bytes.
void Cancel(void)
Definition: ci.c:1191
void SetChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2132
const char * GetCamName(void)
Returns the name of the CAM in this slot, or NULL if there is no ready CAM in this slot...
Definition: ci.c:1740
char * entries[MAX_CIMENU_ENTRIES]
Definition: ci.h:36
const char * Entry(int n)
Definition: ci.h:45
cChannelCamRelations ChannelCamRelations
Definition: ci.c:2068
bool Ready(void)
Returns &#39;true&#39; if the CAM in this slot is ready to decrypt.
Definition: ci.c:1746
cTimeMs moduleCheckTimer
Definition: ci.h:137
int NumEntries(void)
Definition: ci.h:46
time_t lastCleanup
Definition: ci.h:246
cMutex * mutex
Definition: ci.h:31
Definition: thread.h:77
int Priority(void)
Returns the priority if the device this slot is currently assigned to, or IDLEPRIORITY if it is not a...
Definition: ci.c:1842
bool CamChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2118
void StopDecrypting(void)
Clears the list of CA_PMT entries and tells the CAM to stop decrypting.
Definition: ci.c:1966
void ClrChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2148
const char * SubTitleText(void)
Definition: ci.h:43
Definition: tools.h:323
void Abort(void)
Definition: ci.c:1196
void Reset(int CamSlotNumber)
Definition: ci.c:2109
bool EnterMenu(void)
Requests the CAM in this slot to start its menu.
Definition: ci.c:1763
eModuleStatus
Definition: ci.h:77
cCiMenu(cCiMMI *MMI, bool Selectable)
Definition: ci.c:1111
virtual bool Assign(cDevice *Device, bool Query=false)=0
Assigns this adapter to the given Device, if this is possible.
cCiMMI * mmi
Definition: ci.h:30
const char * BottomText(void)
Definition: ci.h:44
void Abort(void)
Definition: ci.c:1159
cChannelCamRelation * GetEntry(tChannelID ChannelID)
Definition: ci.c:2089
bool Assign(cDevice *Device, bool Query=false)
Assigns this CAM slot to the given Device, if this is possible.
Definition: ci.c:1578
Definition: ci.h:77
char * text
Definition: ci.h:60
cMutex * mutex
Definition: ci.h:59
cChannelCamRelations(void)
Definition: ci.c:2070
void DeleteAllConnections(void)
Definition: ci.c:1630
cCamSlot(cCiAdapter *CiAdapter)
Creates a new CAM slot for the given CiAdapter.
Definition: ci.c:1555
cCamSlots CamSlots
Definition: ci.c:1550
int SlotNumber(void)
Returns the number of this CAM slot within the whole system.
Definition: ci.h:169
The cDevice class is the base from which actual devices can be derived.
Definition: device.h:104
bool selectable
Definition: ci.h:32
const char * TitleText(void)
Definition: ci.h:42
bool AddEntry(char *s)
Definition: ci.c:1132
cDevice * assignedDevice
Definition: ci.h:82
bool Blind(void)
Definition: ci.h:67
Definition: ci.h:77