2003-01-06 14:44:27 +01:00
|
|
|
/*
|
|
|
|
* ci.h: Common Interface
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2006-08-12 10:26:43 +02:00
|
|
|
* $Id: ci.h 1.22 2006/08/12 09:43:31 kls Exp $
|
2003-01-06 14:44:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CI_H
|
|
|
|
#define __CI_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "thread.h"
|
2005-11-26 13:39:47 +01:00
|
|
|
#include "tools.h"
|
2003-01-06 14:44:27 +01:00
|
|
|
|
|
|
|
class cCiMMI;
|
|
|
|
|
|
|
|
class cCiMenu {
|
2005-10-30 13:21:23 +01:00
|
|
|
friend class cCiHandler;
|
2003-01-06 14:44:27 +01:00
|
|
|
friend class cCiMMI;
|
|
|
|
private:
|
|
|
|
enum { MAX_CIMENU_ENTRIES = 64 }; ///< XXX is there a specified maximum?
|
|
|
|
cCiMMI *mmi;
|
2005-10-30 13:21:23 +01:00
|
|
|
cMutex *mutex;
|
2003-01-06 14:44:27 +01:00
|
|
|
bool selectable;
|
|
|
|
char *titleText;
|
|
|
|
char *subTitleText;
|
|
|
|
char *bottomText;
|
|
|
|
char *entries[MAX_CIMENU_ENTRIES];
|
|
|
|
int numEntries;
|
|
|
|
bool AddEntry(char *s);
|
|
|
|
cCiMenu(cCiMMI *MMI, bool Selectable);
|
|
|
|
public:
|
|
|
|
~cCiMenu();
|
|
|
|
const char *TitleText(void) { return titleText; }
|
|
|
|
const char *SubTitleText(void) { return subTitleText; }
|
|
|
|
const char *BottomText(void) { return bottomText; }
|
|
|
|
const char *Entry(int n) { return n < numEntries ? entries[n] : NULL; }
|
|
|
|
int NumEntries(void) { return numEntries; }
|
|
|
|
bool Selectable(void) { return selectable; }
|
|
|
|
bool Select(int Index);
|
|
|
|
bool Cancel(void);
|
2005-10-02 13:54:34 +02:00
|
|
|
bool Abort(void);
|
2005-10-02 12:59:53 +02:00
|
|
|
bool HasUpdate(void);
|
2003-01-06 14:44:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class cCiEnquiry {
|
2005-10-30 13:21:23 +01:00
|
|
|
friend class cCiHandler;
|
2003-01-06 14:44:27 +01:00
|
|
|
friend class cCiMMI;
|
|
|
|
private:
|
|
|
|
cCiMMI *mmi;
|
2005-10-30 13:21:23 +01:00
|
|
|
cMutex *mutex;
|
2003-01-06 14:44:27 +01:00
|
|
|
char *text;
|
|
|
|
bool blind;
|
|
|
|
int expectedLength;
|
|
|
|
cCiEnquiry(cCiMMI *MMI);
|
|
|
|
public:
|
|
|
|
~cCiEnquiry();
|
|
|
|
const char *Text(void) { return text; }
|
|
|
|
bool Blind(void) { return blind; }
|
|
|
|
int ExpectedLength(void) { return expectedLength; }
|
|
|
|
bool Reply(const char *s);
|
|
|
|
bool Cancel(void);
|
2005-10-03 12:58:22 +02:00
|
|
|
bool Abort(void);
|
2003-01-06 14:44:27 +01:00
|
|
|
};
|
|
|
|
|
2005-11-26 13:39:47 +01:00
|
|
|
#define MAX_CI_SESSION 16 //XXX
|
|
|
|
#define MAX_CI_SLOT 16
|
|
|
|
|
|
|
|
class cCiCaPidData : public cListObject {
|
2003-01-06 14:44:27 +01:00
|
|
|
public:
|
2005-11-26 13:39:47 +01:00
|
|
|
bool active;
|
|
|
|
int pid;
|
|
|
|
int streamType;
|
|
|
|
cCiCaPidData(int Pid, int StreamType)
|
|
|
|
{
|
|
|
|
active = false;
|
|
|
|
pid = Pid;
|
|
|
|
streamType = StreamType;
|
|
|
|
}
|
2003-01-06 14:44:27 +01:00
|
|
|
};
|
|
|
|
|
2005-11-26 13:39:47 +01:00
|
|
|
class cCiCaProgramData : public cListObject {
|
|
|
|
public:
|
|
|
|
int programNumber;
|
|
|
|
cList<cCiCaPidData> pidList;
|
|
|
|
cCiCaProgramData(int ProgramNumber)
|
|
|
|
{
|
|
|
|
programNumber = ProgramNumber;
|
|
|
|
}
|
|
|
|
};
|
2003-01-06 14:44:27 +01:00
|
|
|
|
|
|
|
class cCiSession;
|
|
|
|
class cCiTransportLayer;
|
|
|
|
class cCiTransportConnection;
|
|
|
|
|
|
|
|
class cCiHandler {
|
|
|
|
private:
|
|
|
|
cMutex mutex;
|
2003-05-25 11:51:28 +02:00
|
|
|
int fd;
|
2003-01-06 14:44:27 +01:00
|
|
|
int numSlots;
|
2003-04-18 12:48:49 +02:00
|
|
|
bool newCaSupport;
|
2003-04-20 09:53:08 +02:00
|
|
|
bool hasUserIO;
|
2005-08-21 08:56:49 +02:00
|
|
|
bool moduleReady[MAX_CI_SLOT];
|
2003-01-06 14:44:27 +01:00
|
|
|
cCiSession *sessions[MAX_CI_SESSION];
|
|
|
|
cCiTransportLayer *tpl;
|
|
|
|
cCiTransportConnection *tc;
|
2005-11-26 13:39:47 +01:00
|
|
|
int source;
|
|
|
|
int transponder;
|
|
|
|
cList<cCiCaProgramData> caProgramList;
|
2006-08-12 10:26:43 +02:00
|
|
|
uint32_t ResourceIdToInt(const uint8_t *Data);
|
|
|
|
bool Send(uint8_t Tag, uint16_t SessionId, uint32_t ResourceId = 0, int Status = -1);
|
2005-12-03 11:59:05 +01:00
|
|
|
const unsigned short *GetCaSystemIds(int Slot);
|
2006-08-12 10:26:43 +02:00
|
|
|
cCiSession *GetSessionBySessionId(uint16_t SessionId);
|
|
|
|
cCiSession *GetSessionByResourceId(uint32_t ResourceId, int Slot);
|
|
|
|
cCiSession *CreateSession(uint32_t ResourceId);
|
2003-01-06 14:44:27 +01:00
|
|
|
bool OpenSession(int Length, const uint8_t *Data);
|
2006-08-12 10:26:43 +02:00
|
|
|
bool CloseSession(uint16_t SessionId);
|
2003-02-09 11:54:22 +01:00
|
|
|
int CloseAllSessions(int Slot);
|
2003-01-06 14:44:27 +01:00
|
|
|
cCiHandler(int Fd, int NumSlots);
|
2005-11-26 13:39:47 +01:00
|
|
|
void SendCaPmt(void);
|
2003-01-06 14:44:27 +01:00
|
|
|
public:
|
|
|
|
~cCiHandler();
|
|
|
|
static cCiHandler *CreateCiHandler(const char *FileName);
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Creates a new cCiHandler for the given CA device.
|
2003-04-18 12:48:49 +02:00
|
|
|
int NumSlots(void) { return numSlots; }
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Returns the number of CAM slots provided by this CA device.
|
2006-01-07 15:16:09 +01:00
|
|
|
int NumCams(void);
|
|
|
|
///< Returns the number of actual CAMs inserted into this CA device.
|
2005-08-21 08:56:49 +02:00
|
|
|
bool Ready(void);
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Returns true if all CAMs in this CA device are ready.
|
2005-11-26 13:39:47 +01:00
|
|
|
bool Process(int Slot = -1);
|
|
|
|
///< Processes the given Slot. If Slot is -1, all slots are processed.
|
|
|
|
///< Returns false in case of an error.
|
2003-04-20 09:53:08 +02:00
|
|
|
bool HasUserIO(void) { return hasUserIO; }
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Returns true if there is a pending user interaction, which shall
|
|
|
|
///< be retrieved via GetMenu() or GetEnquiry().
|
2003-02-09 11:54:22 +01:00
|
|
|
bool EnterMenu(int Slot);
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Requests the CAM in the given Slot to start its menu.
|
2003-01-06 14:44:27 +01:00
|
|
|
cCiMenu *GetMenu(void);
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Gets a pending menu, or NULL if there is no menu.
|
2003-01-06 14:44:27 +01:00
|
|
|
cCiEnquiry *GetEnquiry(void);
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Gets a pending enquiry, or NULL if there is no enquiry.
|
2004-02-08 15:11:07 +01:00
|
|
|
const char *GetCamName(int Slot);
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Returns the name of the CAM in the given Slot, or NULL if there
|
|
|
|
///< is no CAM in that slot.
|
2004-01-04 12:30:00 +01:00
|
|
|
bool ProvidesCa(const unsigned short *CaSystemIds); //XXX Slot???
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Returns true if any of the CAMs can provide one of the given
|
|
|
|
///< CaSystemIds. This doesn't necessarily mean that it will be
|
|
|
|
///< possible to actually decrypt such a programme, since CAMs
|
|
|
|
///< usually advertise several CA system ids, while the actual
|
|
|
|
///< decryption is controlled by the smart card inserted into
|
|
|
|
///< the CAM.
|
2005-11-26 13:39:47 +01:00
|
|
|
void SetSource(int Source, int Transponder);
|
|
|
|
///< Sets the Source and Transponder of the device this cCiHandler is
|
|
|
|
///< currently tuned to. If Source or Transponder are different than
|
|
|
|
///< what was given in a previous call to SetSource(), any previously
|
|
|
|
///< added PIDs will be cleared.
|
|
|
|
void AddPid(int ProgramNumber, int Pid, int StreamType);
|
|
|
|
///< Adds the given PID information to the list of PIDs. A later call
|
|
|
|
///< to SetPid() will (de)activate one of these entries.
|
|
|
|
void SetPid(int Pid, bool Active);
|
|
|
|
///< Sets the given Pid (which has previously been added through a
|
2005-12-03 11:59:05 +01:00
|
|
|
///< call to AddPid()) to Active. A later call to StartDecrypting() will
|
|
|
|
///< send the full list of currently active CA_PMT entries to the CAM.
|
2005-11-26 13:39:47 +01:00
|
|
|
bool CanDecrypt(int ProgramNumber);
|
|
|
|
///< XXX
|
2005-12-03 11:59:05 +01:00
|
|
|
///< Returns true if there is a CAM in this CA device that is able
|
|
|
|
///< to decrypt the programme with the given ProgramNumber. The PIDs
|
|
|
|
///< for this ProgramNumber must have been set through previous calls
|
|
|
|
///< to SetPid().
|
2005-11-26 13:39:47 +01:00
|
|
|
void StartDecrypting(void);
|
|
|
|
///< Triggers sending all currently active CA_PMT entries to the CAM,
|
|
|
|
///< so that it will start decrypting.
|
2003-02-09 11:54:22 +01:00
|
|
|
bool Reset(int Slot);
|
2003-01-06 14:44:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //__CI_H
|