vdr  2.0.6
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  virtual bool SetIdle(bool Idle, bool TestOnly) { return false; }
119  virtual bool IsIdle(void) const { return false; }
120  };
121 
122 class cTPDU;
124 class cCiSession;
125 class cCiCaProgramData;
126 
127 class cCamSlot : public cListObject {
128  friend class cCiAdapter;
130 private:
136  cCiTransportConnection *tc[MAX_CONNECTIONS_PER_CAM_SLOT + 1]; // connection numbering starts with 1
138  time_t resetTime;
140  bool resendPmt;
141  int source;
144  const int *GetCaSystemIds(void);
145  void SendCaPmt(uint8_t CmdId);
146  void NewConnection(void);
147  void DeleteAllConnections(void);
148  void Process(cTPDU *TPDU = NULL);
149  void Write(cTPDU *TPDU);
150  cCiSession *GetSessionByResourceId(uint32_t ResourceId);
151 public:
152  cCamSlot(cCiAdapter *CiAdapter);
156  virtual ~cCamSlot();
157  bool Assign(cDevice *Device, bool Query = false);
166  cDevice *Device(void);
168  int SlotIndex(void) { return slotIndex; }
171  int SlotNumber(void) { return slotNumber; }
174  bool Reset(void);
179  const char *GetCamName(void);
182  bool Ready(void);
184  bool HasMMI(void);
186  bool HasUserIO(void);
189  bool EnterMenu(void);
191  cCiMenu *GetMenu(void);
193  cCiEnquiry *GetEnquiry(void);
195  int Priority(void);
198  bool ProvidesCa(const int *CaSystemIds);
205  void AddPid(int ProgramNumber, int Pid, int StreamType);
208  void SetPid(int Pid, bool Active);
212  void AddChannel(const cChannel *Channel);
217  bool CanDecrypt(const cChannel *Channel);
228  void StartDecrypting(void);
231  void StopDecrypting(void);
233  bool IsDecrypting(void);
235  };
236 
237 class cCamSlots : public cList<cCamSlot> {};
238 
239 extern cCamSlots CamSlots;
240 
241 class cChannelCamRelation;
242 
243 class cChannelCamRelations : public cList<cChannelCamRelation> {
244 private:
248  time_t lastCleanup;
249  void Cleanup(void);
250 public:
251  cChannelCamRelations(void);
252  void Reset(int CamSlotNumber);
253  bool CamChecked(tChannelID ChannelID, int CamSlotNumber);
254  bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber);
255  void SetChecked(tChannelID ChannelID, int CamSlotNumber);
256  void SetDecrypt(tChannelID ChannelID, int CamSlotNumber);
257  void ClrChecked(tChannelID ChannelID, int CamSlotNumber);
258  void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber);
259  };
260 
262 
263 #endif //__CI_H
Definition: ci.h:77
cMutex mutex
Definition: ci.h:131
virtual bool SetIdle(bool Idle, bool TestOnly)
Definition: ci.h:118
virtual void Action(void)
Handles the attached CAM slots in a separate thread.
Definition: ci.c:1531
Definition: ci.h:237
bool ProvidesCa(const int *CaSystemIds)
Returns true if the CAM in this slot provides one of the given CaSystemIds.
Definition: ci.c:1852
cCondVar processed
Definition: ci.h:132
cCamSlots CamSlots
Definition: ci.c:1552
virtual ~cCiAdapter()
The derived class must call Cancel(3) in its destructor.
Definition: ci.c:1501
void AddPid(int ProgramNumber, int Pid, int StreamType)
Adds the given PID information to the list of PIDs.
Definition: ci.c:1867
bool HasUpdate(void)
Definition: ci.c:1143
int source
Definition: ci.h:141
void StartDecrypting(void)
Triggers sending all currently active CA_PMT entries to the CAM, so that it will start decrypting...
Definition: ci.c:1960
#define MAX_CONNECTIONS_PER_CAM_SLOT
Definition: ci.h:20
virtual bool Reset(int Slot)=0
Resets the CAM in the given Slot.
cChannelCamRelations ChannelCamRelations
Definition: ci.c:2067
#define MAX_CAM_SLOTS_PER_ADAPTER
Definition: ci.h:19
Definition: ci.h:54
int slotNumber
Definition: ci.h:135
char * bottomText
Definition: ci.h:35
void Select(int Index)
Definition: ci.c:1149
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:140
cCiMMI * mmi
Definition: ci.h:58
virtual bool Ready(void)
Returns 'true' if all present CAMs in this adapter are ready.
Definition: ci.c:1522
time_t resetTime
Definition: ci.h:138
bool Selectable(void)
Definition: ci.h:47
cCiAdapter(void)
Definition: ci.c:1493
Definition: ci.c:923
int SlotIndex(void)
Returns the index of this CAM slot within its CI adapter.
Definition: ci.h:168
int slotIndex
Definition: ci.h:134
void NewConnection(void)
Definition: ci.c:1621
eModuleStatus ModuleStatus(void)
Returns the status of the CAM in this slot.
Definition: ci.c:1730
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:1906
void Write(cTPDU *TPDU)
Definition: ci.c:1703
void Cleanup(void)
Definition: ci.c:2074
void SendCaPmt(uint8_t CmdId)
Definition: ci.c:1800
cCiTransportConnection * tc[MAX_CONNECTIONS_PER_CAM_SLOT+1]
Definition: ci.h:136
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:1610
cCiSession * GetSessionByResourceId(uint32_t ResourceId)
Definition: ci.c:1697
~cCiMenu()
Definition: ci.c:1122
virtual ~cCamSlot()
Definition: ci.c:1574
char * subTitleText
Definition: ci.h:34
cCiEnquiry(cCiMMI *MMI)
Definition: ci.c:1170
void Process(cTPDU *TPDU=NULL)
Definition: ci.c:1643
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:1761
void SetDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2139
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:1926
cCiMenu * GetMenu(void)
Gets a pending menu, or NULL if there is no menu.
Definition: ci.c:1774
Definition: ci.c:342
int expectedLength
Definition: ci.h:62
void Cancel(void)
Definition: ci.c:1156
cList< cCiCaProgramData > caProgramList
Definition: ci.h:143
Definition: ci.h:79
bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2124
eModuleStatus lastModuleStatus
Definition: ci.h:137
Definition: ci.h:127
void AddCamSlot(cCamSlot *CamSlot)
Adds the given CamSlot to this CI adapter.
Definition: ci.c:1508
cCiAdapter * ciAdapter
Definition: ci.h:133
Definition: thread.h:63
Definition: ci.c:124
const int * GetCaSystemIds(void)
Definition: ci.c:1839
bool Reset(void)
Resets the CAM in this slot.
Definition: ci.c:1712
bool IsDecrypting(void)
Returns true if the CAM in this slot is currently used for decrypting.
Definition: ci.c:1974
int transponder
Definition: ci.h:142
void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2155
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:1885
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:1787
cChannelCamRelation * AddEntry(tChannelID ChannelID)
Definition: ci.c:2099
cMutex mutex
Definition: ci.h:245
virtual bool IsIdle(void) const
Definition: ci.h:119
~cCiEnquiry()
Definition: ci.c:1178
void Reply(const char *s)
Definition: ci.c:1186
Definition: ci.h:25
bool HasMMI(void)
Returns 'true' if the CAM in this slot has an active MMI.
Definition: ci.c:1756
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:1193
void SetChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2131
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:1744
char * entries[MAX_CIMENU_ENTRIES]
Definition: ci.h:36
const char * Entry(int n)
Definition: ci.h:45
bool Ready(void)
Returns 'true' if the CAM in this slot is ready to decrypt.
Definition: ci.c:1750
cTimeMs moduleCheckTimer
Definition: ci.h:139
int NumEntries(void)
Definition: ci.h:46
time_t lastCleanup
Definition: ci.h:248
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:1846
bool CamChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2117
void StopDecrypting(void)
Clears the list of CA_PMT entries and tells the CAM to stop decrypting.
Definition: ci.c:1965
void ClrChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2147
const char * SubTitleText(void)
Definition: ci.h:43
Definition: tools.h:323
void Abort(void)
Definition: ci.c:1198
void Reset(int CamSlotNumber)
Definition: ci.c:2108
bool EnterMenu(void)
Requests the CAM in this slot to start its menu.
Definition: ci.c:1767
eModuleStatus
Definition: ci.h:77
cCiMenu(cCiMMI *MMI, bool Selectable)
Definition: ci.c:1113
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:1161
cChannelCamRelation * GetEntry(tChannelID ChannelID)
Definition: ci.c:2088
bool Assign(cDevice *Device, bool Query=false)
Assigns this CAM slot to the given Device, if this is possible.
Definition: ci.c:1582
Definition: ci.h:77
char * text
Definition: ci.h:60
cMutex * mutex
Definition: ci.h:59
cChannelCamRelations(void)
Definition: ci.c:2069
void DeleteAllConnections(void)
Definition: ci.c:1634
cCamSlot(cCiAdapter *CiAdapter)
Creates a new CAM slot for the given CiAdapter.
Definition: ci.c:1557
int SlotNumber(void)
Returns the number of this CAM slot within the whole system.
Definition: ci.h:171
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:1134
cDevice * assignedDevice
Definition: ci.h:82
bool Blind(void)
Definition: ci.h:67
Definition: ci.h:77