vdr  2.0.2
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
262