vdr  1.7.27
ci.h
Go to the documentation of this file.
00001 /*
00002  * ci.h: Common Interface
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: ci.h 2.2 2012/02/29 10:24:27 kls Exp $
00008  */
00009 
00010 #ifndef __CI_H
00011 #define __CI_H
00012 
00013 #include <stdint.h>
00014 #include <stdio.h>
00015 #include "channels.h"
00016 #include "thread.h"
00017 #include "tools.h"
00018 
00019 #define MAX_CAM_SLOTS_PER_ADAPTER     8 // maximum possible value is 255
00020 #define MAX_CONNECTIONS_PER_CAM_SLOT  8 // maximum possible value is 254
00021 #define CAM_READ_TIMEOUT  50 // ms
00022 
00023 class cCiMMI;
00024 
00025 class cCiMenu {
00026   friend class cCamSlot;
00027   friend class cCiMMI;
00028 private:
00029   enum { MAX_CIMENU_ENTRIES = 64 }; 
00030   cCiMMI *mmi;
00031   cMutex *mutex;
00032   bool selectable;
00033   char *titleText;
00034   char *subTitleText;
00035   char *bottomText;
00036   char *entries[MAX_CIMENU_ENTRIES];
00037   int numEntries;
00038   bool AddEntry(char *s);
00039   cCiMenu(cCiMMI *MMI, bool Selectable);
00040 public:
00041   ~cCiMenu();
00042   const char *TitleText(void) { return titleText; }
00043   const char *SubTitleText(void) { return subTitleText; }
00044   const char *BottomText(void) { return bottomText; }
00045   const char *Entry(int n) { return n < numEntries ? entries[n] : NULL; }
00046   int NumEntries(void) { return numEntries; }
00047   bool Selectable(void) { return selectable; }
00048   void Select(int Index);
00049   void Cancel(void);
00050   void Abort(void);
00051   bool HasUpdate(void);
00052   };
00053 
00054 class cCiEnquiry {
00055   friend class cCamSlot;
00056   friend class cCiMMI;
00057 private:
00058   cCiMMI *mmi;
00059   cMutex *mutex;
00060   char *text;
00061   bool blind;
00062   int expectedLength;
00063   cCiEnquiry(cCiMMI *MMI);
00064 public:
00065   ~cCiEnquiry();
00066   const char *Text(void) { return text; }
00067   bool Blind(void) { return blind; }
00068   int ExpectedLength(void) { return expectedLength; }
00069   void Reply(const char *s);
00070   void Cancel(void);
00071   void Abort(void);
00072   };
00073 
00074 class cDevice;
00075 class cCamSlot;
00076 
00077 enum eModuleStatus { msNone, msReset, msPresent, msReady };
00078 
00079 class cCiAdapter : public cThread {
00080   friend class cCamSlot;
00081 private:
00082   cDevice *assignedDevice;
00083   cCamSlot *camSlots[MAX_CAM_SLOTS_PER_ADAPTER];
00084   void AddCamSlot(cCamSlot *CamSlot);
00086 protected:
00087   virtual void Action(void);
00091   virtual int Read(uint8_t *Buffer, int MaxLength) = 0;
00096   virtual void Write(const uint8_t *Buffer, int Length) = 0;
00098   virtual bool Reset(int Slot) = 0;
00101   virtual eModuleStatus ModuleStatus(int Slot) = 0;
00103   virtual bool Assign(cDevice *Device, bool Query = false) = 0;
00112 public:
00113   cCiAdapter(void);
00114   virtual ~cCiAdapter();
00116   virtual bool Ready(void);
00118   };
00119 
00120 class cTPDU;
00121 class cCiTransportConnection;
00122 class cCiSession;
00123 class cCiCaProgramData;
00124 
00125 class cCamSlot : public cListObject {
00126   friend class cCiAdapter;
00127   friend class cCiTransportConnection;
00128 private:
00129   cMutex mutex;
00130   cCondVar processed;
00131   cCiAdapter *ciAdapter;
00132   int slotIndex;
00133   int slotNumber;
00134   cCiTransportConnection *tc[MAX_CONNECTIONS_PER_CAM_SLOT + 1];  // connection numbering starts with 1
00135   eModuleStatus lastModuleStatus;
00136   time_t resetTime;
00137   cTimeMs moduleCheckTimer;
00138   bool resendPmt;
00139   int source;
00140   int transponder;
00141   cList<cCiCaProgramData> caProgramList;
00142   const int *GetCaSystemIds(void);
00143   void SendCaPmt(uint8_t CmdId);
00144   void NewConnection(void);
00145   void DeleteAllConnections(void);
00146   void Process(cTPDU *TPDU = NULL);
00147   void Write(cTPDU *TPDU);
00148   cCiSession *GetSessionByResourceId(uint32_t ResourceId);
00149 public:
00150   cCamSlot(cCiAdapter *CiAdapter);
00154   virtual ~cCamSlot();
00155   bool Assign(cDevice *Device, bool Query = false);
00164   cDevice *Device(void);
00166   int SlotIndex(void) { return slotIndex; }
00169   int SlotNumber(void) { return slotNumber; }
00172   bool Reset(void);
00175   eModuleStatus ModuleStatus(void);
00177   const char *GetCamName(void);
00180   bool Ready(void);
00182   bool HasMMI(void);
00184   bool HasUserIO(void);
00187   bool EnterMenu(void);
00189   cCiMenu *GetMenu(void);
00191   cCiEnquiry *GetEnquiry(void);
00193   int Priority(void);
00196   bool ProvidesCa(const int *CaSystemIds);
00203   void AddPid(int ProgramNumber, int Pid, int StreamType);
00206   void SetPid(int Pid, bool Active);
00210   void AddChannel(const cChannel *Channel);
00215   bool CanDecrypt(const cChannel *Channel);
00226   void StartDecrypting(void);
00229   void StopDecrypting(void);
00231   bool IsDecrypting(void);
00233   };
00234 
00235 class cCamSlots : public cList<cCamSlot> {};
00236 
00237 extern cCamSlots CamSlots;
00238 
00239 class cChannelCamRelation;
00240 
00241 class cChannelCamRelations : public cList<cChannelCamRelation> {
00242 private:
00243   cMutex mutex;
00244   cChannelCamRelation *GetEntry(tChannelID ChannelID);
00245   cChannelCamRelation *AddEntry(tChannelID ChannelID);
00246   time_t lastCleanup;
00247   void Cleanup(void);
00248 public:
00249   cChannelCamRelations(void);
00250   void Reset(int CamSlotNumber);
00251   bool CamChecked(tChannelID ChannelID, int CamSlotNumber);
00252   bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber);
00253   void SetChecked(tChannelID ChannelID, int CamSlotNumber);
00254   void SetDecrypt(tChannelID ChannelID, int CamSlotNumber);
00255   void ClrChecked(tChannelID ChannelID, int CamSlotNumber);
00256   void ClrDecrypt(tChannelID ChannelID, int CamSlotNumber);
00257   };
00258 
00259 extern cChannelCamRelations ChannelCamRelations;
00260 
00261 #endif //__CI_H