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  virtual bool SetIdle(bool Idle, bool TestOnly) { return false; }
120  virtual bool IsIdle(void) const { return false; }
121  };
122 
123 class cTPDU;
125 class cCiSession;
126 class cCiCaProgramData;
127 class cCaPidReceiver;
129 
130 class cCamSlot : public cListObject {
131  friend class cCiAdapter;
133 private:
142  cCiTransportConnection *tc[MAX_CONNECTIONS_PER_CAM_SLOT + 1]; // connection numbering starts with 1
144  time_t resetTime;
146  bool resendPmt;
147  int source;
150  const int *GetCaSystemIds(void);
151  void SendCaPmt(uint8_t CmdId);
152  void NewConnection(void);
153  void DeleteAllConnections(void);
154  void Process(cTPDU *TPDU = NULL);
155  void Write(cTPDU *TPDU);
156  cCiSession *GetSessionByResourceId(uint32_t ResourceId);
157 public:
158  cCamSlot(cCiAdapter *CiAdapter, bool WantsTsData = false);
165  virtual ~cCamSlot();
166  bool Assign(cDevice *Device, bool Query = false);
175  cDevice *Device(void) { return assignedDevice; }
177  bool WantsTsData(void) const { return caPidReceiver != NULL; }
180  int SlotIndex(void) { return slotIndex; }
183  int SlotNumber(void) { return slotNumber; }
186  virtual bool Reset(void);
189  virtual bool CanActivate(void);
192  virtual void StartActivation(void);
202  virtual void CancelActivation(void);
204  virtual bool IsActivating(void);
206  virtual eModuleStatus ModuleStatus(void);
208  virtual const char *GetCamName(void);
211  virtual bool Ready(void);
213  virtual bool HasMMI(void);
215  virtual bool HasUserIO(void);
218  virtual bool EnterMenu(void);
220  virtual cCiMenu *GetMenu(void);
222  virtual cCiEnquiry *GetEnquiry(void);
224  int Priority(void);
227  virtual bool ProvidesCa(const int *CaSystemIds);
234  virtual void AddPid(int ProgramNumber, int Pid, int StreamType);
237  virtual void SetPid(int Pid, bool Active);
241  virtual void AddChannel(const cChannel *Channel);
246  virtual bool CanDecrypt(const cChannel *Channel);
257  virtual void StartDecrypting(void);
260  virtual void StopDecrypting(void);
262  virtual bool IsDecrypting(void);
264  virtual uchar *Decrypt(uchar *Data, int &Count);
296  };
297 
298 class cCamSlots : public cList<cCamSlot> {
299 public:
300  bool WaitForAllCamSlotsReady(int Timeout = 0);
306  };
307 
308 extern cCamSlots CamSlots;
309 
310 class cChannelCamRelation;
311 
312 class cChannelCamRelations : public cList<cChannelCamRelation> {
313 private:
317  time_t lastCleanup;
318  void Cleanup(void);
319 public:
320  cChannelCamRelations(void);
321  void Reset(int CamSlotNumber);
322  bool CamChecked(tChannelID ChannelID, int CamSlotNumber);
323  bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber);
324  void SetChecked(tChannelID ChannelID, int CamSlotNumber);
325  void SetDecrypt(tChannelID ChannelID, int CamSlotNumber);
326  void ClrChecked(tChannelID ChannelID, int CamSlotNumber);
327  void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber);
328  };
329 
331 
332 #endif //__CI_H
Definition: ci.h:77
unsigned char uchar
Definition: tools.h:30
cMutex mutex
Definition: ci.h:134
virtual bool SetIdle(bool Idle, bool TestOnly)
Definition: ci.h:119
virtual void Action(void)
Handles the attached CAM slots in a separate thread.
Definition: ci.c:1718
Definition: ci.h:298
virtual bool ProvidesCa(const int *CaSystemIds)
Returns true if the CAM in this slot provides one of the given CaSystemIds.
Definition: ci.c:2089
cCondVar processed
Definition: ci.h:135
cCamSlots CamSlots
Definition: ci.c:2235
virtual ~cCiAdapter()
The derived class must call Cancel(3) in its destructor.
Definition: ci.c:1686
virtual void StartActivation(void)
Puts the CAM in this slot into a mode where an inserted smart card can be activated.
Definition: ci.c:1919
cCamSlot * ItCamSlot(int &Iter)
Iterates over all added CAM slots of this adapter.
Definition: ci.c:1707
virtual void AddPid(int ProgramNumber, int Pid, int StreamType)
Adds the given PID information to the list of PIDs.
Definition: ci.c:2104
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:147
virtual void StartDecrypting(void)
Triggers sending all currently active CA_PMT entries to the CAM, so that it will start decrypting...
Definition: ci.c:2197
#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:141
char * bottomText
Definition: ci.h:35
void Select(int Index)
Definition: ci.c:1335
Definition: ci.h:77
virtual bool CanActivate(void)
Returns true if there is a CAM in this slot that can be put into activation mode. ...
Definition: ci.c:1914
bool resendPmt
Definition: ci.h:146
cCiMMI * mmi
Definition: ci.h:58
time_t resetTime
Definition: ci.h:144
bool Selectable(void)
Definition: ci.h:47
cCiAdapter(void)
Definition: ci.c:1679
Definition: ci.c:1109
int SlotIndex(void)
Returns the index of this CAM slot within its CI adapter.
Definition: ci.h:180
int slotIndex
Definition: ci.h:140
void NewConnection(void)
Definition: ci.c:1802
virtual eModuleStatus ModuleStatus(void)
Returns the status of the CAM in this slot.
Definition: ci.c:1945
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:177
virtual void AddChannel(const cChannel *Channel)
Adds all PIDs if the given Channel to the current list of PIDs.
Definition: ci.c:2143
void Write(cTPDU *TPDU)
Definition: ci.c:1887
void Cleanup(void)
Definition: ci.c:2337
void SendCaPmt(uint8_t CmdId)
Definition: ci.c:2015
virtual bool Reset(int Slot)
Resets the CAM in the given Slot.
Definition: ci.h:101
cCiTransportConnection * tc[MAX_CONNECTIONS_PER_CAM_SLOT+1]
Definition: ci.h:142
cCaActivationReceiver * caActivationReceiver
Definition: ci.h:139
bool blind
Definition: ci.h:61
char * titleText
Definition: ci.h:33
cCiSession * GetSessionByResourceId(uint32_t ResourceId)
Definition: ci.c:1881
~cCiMenu()
Definition: ci.c:1308
virtual ~cCamSlot()
Definition: ci.c:1762
char * subTitleText
Definition: ci.h:34
cCiEnquiry(cCiMMI *MMI)
Definition: ci.c:1356
void Process(cTPDU *TPDU=NULL)
Definition: ci.c:1824
const char * Text(void)
Definition: ci.h:66
virtual bool HasUserIO(void)
Returns true if there is a pending user interaction, which shall be retrieved via GetMenu() or GetEnq...
Definition: ci.c:1976
void SetDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2402
virtual 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:2163
virtual cCiMenu * GetMenu(void)
Gets a pending menu, or NULL if there is no menu.
Definition: ci.c:1989
Definition: ci.c:524
int expectedLength
Definition: ci.h:62
void Cancel(void)
Definition: ci.c:1342
cList< cCiCaProgramData > caProgramList
Definition: ci.h:149
Definition: ci.h:79
cCamSlot(cCiAdapter *CiAdapter, bool WantsTsData=false)
Creates a new CAM slot for the given CiAdapter.
Definition: ci.c:1742
bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2387
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:143
Definition: ci.h:130
void AddCamSlot(cCamSlot *CamSlot)
Adds the given CamSlot to this CI adapter.
Definition: ci.c:1693
cCiAdapter * ciAdapter
Definition: ci.h:136
Definition: thread.h:63
Definition: ci.c:306
const int * GetCaSystemIds(void)
Definition: ci.c:2076
virtual bool Reset(void)
Resets the CAM in this slot.
Definition: ci.c:1896
virtual bool IsDecrypting(void)
Returns true if the CAM in this slot is currently used for decrypting.
Definition: ci.c:2211
int transponder
Definition: ci.h:148
void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2418
virtual 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:2122
cCamSlot * camSlots[MAX_CAM_SLOTS_PER_ADAPTER]
Definition: ci.h:82
int ExpectedLength(void)
Definition: ci.h:68
virtual cCiEnquiry * GetEnquiry(void)
Gets a pending enquiry, or NULL if there is no enquiry.
Definition: ci.c:2002
cChannelCamRelation * AddEntry(tChannelID ChannelID)
Definition: ci.c:2362
cMutex mutex
Definition: ci.h:314
virtual bool IsIdle(void) const
Definition: ci.h:120
bool WaitForAllCamSlotsReady(int Timeout=0)
Waits until all CAM slots have become ready, or the given Timeout (seconds) has expired.
Definition: ci.c:2237
~cCiEnquiry()
Definition: ci.c:1364
void Reply(const char *s)
Definition: ci.c:1372
Definition: ci.h:25
virtual eModuleStatus ModuleStatus(int Slot)
Returns the status of the CAM in the given Slot.
Definition: ci.h:104
virtual bool HasMMI(void)
Returns 'true' if the CAM in this slot has an active MMI.
Definition: ci.c:1971
cDevice * assignedDevice
Definition: ci.h:137
void Cancel(void)
Definition: ci.c:1379
void SetChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2394
virtual 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:1959
char * entries[MAX_CIMENU_ENTRIES]
Definition: ci.h:36
const char * Entry(int n)
Definition: ci.h:45
virtual bool Ready(void)
Returns 'true' if the CAM in this slot is ready to decrypt.
Definition: ci.c:1965
cTimeMs moduleCheckTimer
Definition: ci.h:145
cCaPidReceiver * caPidReceiver
Definition: ci.h:138
int NumEntries(void)
Definition: ci.h:46
time_t lastCleanup
Definition: ci.h:317
cMutex * mutex
Definition: ci.h:31
virtual void CancelActivation(void)
Cancels a previously started activation (if any).
Definition: ci.c:1933
virtual uchar * Decrypt(uchar *Data, int &Count)
If this is a CAM slot that can be freely assigned to any device, but will not be directly inserted in...
Definition: ci.c:2227
Definition: thread.h:77
int Priority(void)
Returns the priority of the device this slot is currently assigned to, or IDLEPRIORITY if it is not a...
Definition: ci.c:2083
bool CamChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2380
virtual void StopDecrypting(void)
Clears the list of CA_PMT entries and tells the CAM to stop decrypting.
Definition: ci.c:2202
void ClrChecked(tChannelID ChannelID, int CamSlotNumber)
Definition: ci.c:2410
const char * SubTitleText(void)
Definition: ci.h:43
Definition: tools.h:333
void Abort(void)
Definition: ci.c:1384
void Reset(int CamSlotNumber)
Definition: ci.c:2371
virtual bool EnterMenu(void)
Requests the CAM in this slot to start its menu.
Definition: ci.c:1982
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
cChannelCamRelation * GetEntry(tChannelID ChannelID)
Definition: ci.c:2351
bool Assign(cDevice *Device, bool Query=false)
Assigns this CAM slot to the given Device, if this is possible.
Definition: ci.c:1772
Definition: ci.h:77
virtual bool IsActivating(void)
Returns true if this CAM slot is currently activating a smart card.
Definition: ci.c:1940
char * text
Definition: ci.h:60
cMutex * mutex
Definition: ci.h:59
cChannelCamRelations(void)
Definition: ci.c:2332
void DeleteAllConnections(void)
Definition: ci.c:1815
int SlotNumber(void)
Returns the number of this CAM slot within the whole system.
Definition: ci.h:183
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:175