MythTV  master
Classes | Macros | Enumerations | Functions | Variables
dvbci.cpp File Reference
#include "dvbci.h"
#include <array>
#include <cctype>
#include <cerrno>
#include <cstring>
#include <ctime>
#include <fcntl.h>
#include <linux/dvb/ca.h>
#include <netinet/in.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
#include <malloc.h>
#include <QString>
#include "libmythbase/mythlogging.h"
Include dependency graph for dvbci.cpp:

Go to the source code of this file.

Classes

class  cTPDU
 
class  cCiTransportConnection
 
class  cCiTransportLayer
 
class  cCiSession
 
class  cCiResourceManager
 
class  cCiApplicationInformation
 
class  cCiConditionalAccessSupport
 
class  cCiDateTime
 
class  cCiMMI
 
struct  tAnswer
 

Macros

#define esyslog(a...)   LOG(VB_GENERAL, LOG_ERR, QString::asprintf(a))
 
#define isyslog(a...)   LOG(VB_DVBCAM, LOG_INFO, QString::asprintf(a))
 
#define dsyslog(a...)   LOG(VB_DVBCAM, LOG_DEBUG, QString::asprintf(a))
 
#define LOG_ERROR   esyslog("ERROR (%s,%d): %m", __FILE__, __LINE__)
 
#define LOG_ERROR_STR(s)   esyslog("ERROR: %s: %m", s)
 
#define dbgprotocol(a...)   if (sDebugProtocol) LOG(VB_DVBCAM, LOG_DEBUG, QString::asprintf(a))
 

Enumerations

enum  T_VALUES {
  T_SB = 0x80, T_RCV = 0x81, T_CREATE_TC = 0x82, T_CTC_REPLY = 0x83,
  T_DELETE_TC = 0x84, T_DTC_REPLY = 0x85, T_REQUEST_TC = 0x86, T_NEW_TC = 0x87,
  T_TC_ERROR = 0x88, T_DATA_LAST = 0xA0, T_DATA_MORE = 0xA1
}
 
enum  eState { stIDLE, stCREATION, stACTIVE, stDELETION }
 
enum  SESSION_TAGS {
  ST_SESSION_NUMBER = 0x90, ST_OPEN_SESSION_REQUEST = 0x91, ST_OPEN_SESSION_RESPONSE = 0x92, ST_CREATE_SESSION = 0x93,
  ST_CREATE_SESSION_RESPONSE = 0x94, ST_CLOSE_SESSION_REQUEST = 0x95, ST_CLOSE_SESSION_RESPONSE = 0x96
}
 
enum  SESSION_STATUS { SS_OK = 0x00, SS_NOT_ALLOCATED = 0xF0 }
 
enum  IDENTIFIERS {
  RI_RESOURCE_MANAGER = 0x00010041, RI_APPLICATION_INFORMATION = 0x00020041, RI_CONDITIONAL_ACCESS_SUPPORT = 0x00030041, RI_HOST_CONTROL = 0x00200041,
  RI_DATE_TIME = 0x00240041, RI_MMI = 0x00400041
}
 
enum  OBJECT_TAG {
  AOT_NONE = 0x000000, AOT_PROFILE_ENQ = 0x9F8010, AOT_PROFILE = 0x9F8011, AOT_PROFILE_CHANGE = 0x9F8012,
  AOT_APPLICATION_INFO_ENQ = 0x9F8020, AOT_APPLICATION_INFO = 0x9F8021, AOT_ENTER_MENU = 0x9F8022, AOT_CA_INFO_ENQ = 0x9F8030,
  AOT_CA_INFO = 0x9F8031, AOT_CA_PMT = 0x9F8032, AOT_CA_PMT_REPLY = 0x9F8033, AOT_TUNE = 0x9F8400,
  AOT_REPLACE = 0x9F8401, AOT_CLEAR_REPLACE = 0x9F8402, AOT_ASK_RELEASE = 0x9F8403, AOT_DATE_TIME_ENQ = 0x9F8440,
  AOT_DATE_TIME = 0x9F8441, AOT_CLOSE_MMI = 0x9F8800, AOT_DISPLAY_CONTROL = 0x9F8801, AOT_DISPLAY_REPLY = 0x9F8802,
  AOT_TEXT_LAST = 0x9F8803, AOT_TEXT_MORE = 0x9F8804, AOT_KEYPAD_CONTROL = 0x9F8805, AOT_KEYPRESS = 0x9F8806,
  AOT_ENQ = 0x9F8807, AOT_ANSW = 0x9F8808, AOT_MENU_LAST = 0x9F8809, AOT_MENU_MORE = 0x9F880A,
  AOT_MENU_ANSW = 0x9F880B, AOT_LIST_LAST = 0x9F880C, AOT_LIST_MORE = 0x9F880D, AOT_SUBTITLE_SEGMENT_LAST = 0x9F880E,
  AOT_SUBTITLE_SEGMENT_MORE = 0x9F880F, AOT_DISPLAY_MESSAGE = 0x9F8810, AOT_SCENE_END_MARK = 0x9F8811, AOT_SCENE_DONE = 0x9F8812,
  AOT_SCENE_CONTROL = 0x9F8813, AOT_SUBTITLE_DOWNLOAD_LAST = 0x9F8814, AOT_SUBTITLE_DOWNLOAD_MORE = 0x9F8815, AOT_FLUSH_DOWNLOAD = 0x9F8816,
  AOT_DOWNLOAD_REPLY = 0x9F8817, AOT_COMMS_CMD = 0x9F8C00, AOT_CONNECTION_DESCRIPTOR = 0x9F8C01, AOT_COMMS_REPLY = 0x9F8C02,
  AOT_COMMS_SEND_LAST = 0x9F8C03, AOT_COMMS_SEND_MORE = 0x9F8C04, AOT_COMMS_RCV_LAST = 0x9F8C05, AOT_COMMS_RCV_MORE = 0x9F8C06
}
 
enum  CLOSE_MMI { CLOSE_MMI_IMMEDIATE = 0x00, CLOSE_MMI_DELAY = 0x01 }
 
enum  DISPLAY_CONTROL {
  DCC_SET_MMI_MODE = 0x01, DCC_DISPLAY_CHARACTER_TABLE_LIST = 0x02, DCC_INPUT_CHARACTER_TABLE_LIST = 0x03, DCC_OVERLAY_GRAPHICS_CHARACTERISTICS = 0x04,
  DCC_FULL_SCREEN_GRAPHICS_CHARACTERISTICS = 0x05
}
 
enum  MMI_MODES { MM_HIGH_LEVEL = 0x01, MM_LOW_LEVEL_OVERLAY_GRAPHICS = 0x02, MM_LOW_LEVEL_FULL_SCREEN_GRAPHICS = 0x03 }
 
enum  DISPLAY_REPLY_IDS {
  DRI_MMI_MODE_ACK = 0x01, DRI_LIST_DISPLAY_CHARACTER_TABLES = 0x02, DRI_LIST_INPUT_CHARACTER_TABLES = 0x03, DRI_LIST_GRAPHIC_OVERLAY_CHARACTERISTICS = 0x04,
  DRI_LIST_FULL_SCREEN_GRAPHIC_CHARACTERISTICS = 0x05, DRI_UNKNOWN_DISPLAY_CONTROL_CMD = 0xF0, DRI_UNKNOWN_MMI_MODE = 0xF1, DRI_UNKNOWN_CHARACTER_TABLE = 0xF2
}
 
enum  ANSWER_IDS { AI_CANCEL = 0x00, AI_ANSWER = 0x01 }
 
enum  CPCI_IDS { CPCI_OK_DESCRAMBLING = 0x01, CPCI_OK_MMI = 0x02, CPCI_QUERY = 0x03, CPCI_NOT_SELECTED = 0x04 }
 

Functions

static ssize_t safe_read (int filedes, void *buffer, size_t size)
 
static const uint8_t * GetLength (const uint8_t *Data, int &Length)
 
static uint8_t * SetLength (uint8_t *Data, int Length)
 
static void SetLength (std::vector< uint8_t > &Data, int Length)
 
static char * CopyString (int Length, const uint8_t *Data)
 
static char * GetString (int &Length, const uint8_t **Data)
 
static constexpr uint8_t DEC2BCD (uint8_t d)
 
static constexpr uint8_t BYTE0 (uint16_t a)
 
static constexpr uint8_t BYTE1 (uint16_t a)
 

Variables

static bool sDumpTPDUDataTransfer = false
 
static bool sDebugProtocol = false
 
static bool sConnected = false
 
static constexpr int OK { 0 }
 
static constexpr int TIMEOUT { -1 }
 
static constexpr int ERROR { -2 }
 
static constexpr time_t WRKRND_TIME_BEFORE_ENTER_MENU { 15 }
 
static constexpr int SIZE_INDICATOR { 0x80 }
 
static constexpr size_t MAX_TPDU_SIZE { 2048 }
 
static constexpr int MAX_TPDU_DATA { MAX_TPDU_SIZE - 4 }
 
static constexpr uint8_t DATA_INDICATOR { 0x80 }
 
static constexpr int CAM_READ_TIMEOUT { 5000 }
 
static constexpr int8_t MAX_CONNECT_RETRIES { 25 }
 
static constexpr std::chrono::milliseconds POLL_INTERVAL { 100ms }
 
static constexpr size_t MAX_CI_CONNECT { 16 }
 
static constexpr uint8_t EF_BLIND { 0x01 }
 

Macro Definition Documentation

◆ esyslog

#define esyslog (   a...)    LOG(VB_GENERAL, LOG_ERR, QString::asprintf(a))

Definition at line 52 of file dvbci.cpp.

◆ isyslog

#define isyslog (   a...)    LOG(VB_DVBCAM, LOG_INFO, QString::asprintf(a))

Definition at line 53 of file dvbci.cpp.

◆ dsyslog

#define dsyslog (   a...)    LOG(VB_DVBCAM, LOG_DEBUG, QString::asprintf(a))

Definition at line 54 of file dvbci.cpp.

◆ LOG_ERROR

#define LOG_ERROR   esyslog("ERROR (%s,%d): %m", __FILE__, __LINE__)

Definition at line 56 of file dvbci.cpp.

◆ LOG_ERROR_STR

#define LOG_ERROR_STR (   s)    esyslog("ERROR: %s: %m", s)

Definition at line 57 of file dvbci.cpp.

◆ dbgprotocol

#define dbgprotocol (   a...)    if (sDebugProtocol) LOG(VB_DVBCAM, LOG_DEBUG, QString::asprintf(a))

Definition at line 67 of file dvbci.cpp.

Enumeration Type Documentation

◆ T_VALUES

enum T_VALUES
Enumerator
T_SB 
T_RCV 
T_CREATE_TC 
T_CTC_REPLY 
T_DELETE_TC 
T_DTC_REPLY 
T_REQUEST_TC 
T_NEW_TC 
T_TC_ERROR 
T_DATA_LAST 
T_DATA_MORE 

Definition at line 250 of file dvbci.cpp.

◆ eState

enum eState
Enumerator
stIDLE 
stCREATION 
stACTIVE 
stDELETION 

Definition at line 392 of file dvbci.cpp.

◆ SESSION_TAGS

Enumerator
ST_SESSION_NUMBER 
ST_OPEN_SESSION_REQUEST 
ST_OPEN_SESSION_RESPONSE 
ST_CREATE_SESSION 
ST_CREATE_SESSION_RESPONSE 
ST_CLOSE_SESSION_REQUEST 
ST_CLOSE_SESSION_RESPONSE 

Definition at line 696 of file dvbci.cpp.

◆ SESSION_STATUS

Enumerator
SS_OK 
SS_NOT_ALLOCATED 

Definition at line 708 of file dvbci.cpp.

◆ IDENTIFIERS

Enumerator
RI_RESOURCE_MANAGER 
RI_APPLICATION_INFORMATION 
RI_CONDITIONAL_ACCESS_SUPPORT 
RI_HOST_CONTROL 
RI_DATE_TIME 
RI_MMI 

Definition at line 715 of file dvbci.cpp.

◆ OBJECT_TAG

enum OBJECT_TAG
Enumerator
AOT_NONE 
AOT_PROFILE_ENQ 
AOT_PROFILE 
AOT_PROFILE_CHANGE 
AOT_APPLICATION_INFO_ENQ 
AOT_APPLICATION_INFO 
AOT_ENTER_MENU 
AOT_CA_INFO_ENQ 
AOT_CA_INFO 
AOT_CA_PMT 
AOT_CA_PMT_REPLY 
AOT_TUNE 
AOT_REPLACE 
AOT_CLEAR_REPLACE 
AOT_ASK_RELEASE 
AOT_DATE_TIME_ENQ 
AOT_DATE_TIME 
AOT_CLOSE_MMI 
AOT_DISPLAY_CONTROL 
AOT_DISPLAY_REPLY 
AOT_TEXT_LAST 
AOT_TEXT_MORE 
AOT_KEYPAD_CONTROL 
AOT_KEYPRESS 
AOT_ENQ 
AOT_ANSW 
AOT_MENU_LAST 
AOT_MENU_MORE 
AOT_MENU_ANSW 
AOT_LIST_LAST 
AOT_LIST_MORE 
AOT_SUBTITLE_SEGMENT_LAST 
AOT_SUBTITLE_SEGMENT_MORE 
AOT_DISPLAY_MESSAGE 
AOT_SCENE_END_MARK 
AOT_SCENE_DONE 
AOT_SCENE_CONTROL 
AOT_SUBTITLE_DOWNLOAD_LAST 
AOT_SUBTITLE_DOWNLOAD_MORE 
AOT_FLUSH_DOWNLOAD 
AOT_DOWNLOAD_REPLY 
AOT_COMMS_CMD 
AOT_CONNECTION_DESCRIPTOR 
AOT_COMMS_REPLY 
AOT_COMMS_SEND_LAST 
AOT_COMMS_SEND_MORE 
AOT_COMMS_RCV_LAST 
AOT_COMMS_RCV_MORE 

Definition at line 726 of file dvbci.cpp.

◆ CLOSE_MMI

enum CLOSE_MMI
Enumerator
CLOSE_MMI_IMMEDIATE 
CLOSE_MMI_DELAY 

Definition at line 1198 of file dvbci.cpp.

◆ DISPLAY_CONTROL

Enumerator
DCC_SET_MMI_MODE 
DCC_DISPLAY_CHARACTER_TABLE_LIST 
DCC_INPUT_CHARACTER_TABLE_LIST 
DCC_OVERLAY_GRAPHICS_CHARACTERISTICS 
DCC_FULL_SCREEN_GRAPHICS_CHARACTERISTICS 

Definition at line 1205 of file dvbci.cpp.

◆ MMI_MODES

enum MMI_MODES
Enumerator
MM_HIGH_LEVEL 
MM_LOW_LEVEL_OVERLAY_GRAPHICS 
MM_LOW_LEVEL_FULL_SCREEN_GRAPHICS 

Definition at line 1215 of file dvbci.cpp.

◆ DISPLAY_REPLY_IDS

Enumerator
DRI_MMI_MODE_ACK 
DRI_LIST_DISPLAY_CHARACTER_TABLES 
DRI_LIST_INPUT_CHARACTER_TABLES 
DRI_LIST_GRAPHIC_OVERLAY_CHARACTERISTICS 
DRI_LIST_FULL_SCREEN_GRAPHIC_CHARACTERISTICS 
DRI_UNKNOWN_DISPLAY_CONTROL_CMD 
DRI_UNKNOWN_MMI_MODE 
DRI_UNKNOWN_CHARACTER_TABLE 

Definition at line 1223 of file dvbci.cpp.

◆ ANSWER_IDS

enum ANSWER_IDS
Enumerator
AI_CANCEL 
AI_ANSWER 

Definition at line 1240 of file dvbci.cpp.

◆ CPCI_IDS

enum CPCI_IDS
Enumerator
CPCI_OK_DESCRAMBLING 
CPCI_OK_MMI 
CPCI_QUERY 
CPCI_NOT_SELECTED 

Definition at line 1491 of file dvbci.cpp.

Function Documentation

◆ safe_read()

static ssize_t safe_read ( int  filedes,
void *  buffer,
size_t  size 
)
static

Definition at line 83 of file dvbci.cpp.

Referenced by cTPDU::Read().

◆ GetLength()

static const uint8_t* GetLength ( const uint8_t *  Data,
int &  Length 
)
static
Parameters
LengthGets the length field from the beginning of Data. This number is encoded into the output buffer. If the high order bit of the first byte is zero, then the remaining seven bits hold the actual length. If the high order bit is set then the remaining bits of that byte indicate how many bytes are used to hold the length. The subsequent bytes hold the actual length value.
DataA pointer to current location for reading data.
LengthUsed to store the length from the data stream.
Returns
Returns a pointer to the first byte after the length and stores the length value in Length.

Definition at line 95 of file dvbci.cpp.

Referenced by cTPDU::GetData(), cCiSession::GetData(), and GetString().

◆ SetLength() [1/2]

static uint8_t* SetLength ( uint8_t *  Data,
int  Length 
)
static
Parameters
LengthSets the length field at the beginning of Data. This number is encoded into the output buffer. If the length is less than 128, it is written directly into the first byte. If 128 or more, the high order bit of the first byte is set and the remaining bits indicate how many bytes are needed to hold the length. The subsequent bytes hold the actual length.
DataA pointer to current location for writing data.
LengthA number to encode into the data stream.
Returns
Returns a pointer to the first byte after the length.

Definition at line 117 of file dvbci.cpp.

Referenced by cTPDU::cTPDU(), cCiSession::SendData(), and PESPacket::SetTotalLength().

◆ SetLength() [2/2]

static void SetLength ( std::vector< uint8_t > &  Data,
int  Length 
)
static

Definition at line 145 of file dvbci.cpp.

◆ CopyString()

static char* CopyString ( int  Length,
const uint8_t *  Data 
)
static
Parameters
DataCopies the string at Data.
LengthThe number of bytes to copy from Data.
DataA pointer to current location for reading data.
Returns
Returns a pointer to a newly allocated string.

Definition at line 166 of file dvbci.cpp.

Referenced by GetString(), and cCiMMI::Process().

◆ GetString()

static char* GetString ( int &  Length,
const uint8_t **  Data 
)
static
Parameters
DataGets the string at Data. Upon return Length and Data represent the remaining data after the string has been copied off.
[in,out]LengthThe number of bytes to copy from Data. Updated for the size of the string read.
[in,out]DataA pointer to current location for reading data. Updated for the size of the string read.
Returns
Returns a pointer to a newly allocated string, or nullptr in case of error.

Definition at line 178 of file dvbci.cpp.

Referenced by cCiMMI::GetText(), and cCiApplicationInformation::Process().

◆ DEC2BCD()

static constexpr uint8_t DEC2BCD ( uint8_t  d)
staticconstexpr

Definition at line 1122 of file dvbci.cpp.

Referenced by cCiDateTime::SendDateTime().

◆ BYTE0()

static constexpr uint8_t BYTE0 ( uint16_t  a)
staticconstexpr

Definition at line 1124 of file dvbci.cpp.

Referenced by cCiDateTime::SendDateTime().

◆ BYTE1()

static constexpr uint8_t BYTE1 ( uint16_t  a)
staticconstexpr

Definition at line 1126 of file dvbci.cpp.

Referenced by cCiDateTime::SendDateTime().

Variable Documentation

◆ sDumpTPDUDataTransfer

bool sDumpTPDUDataTransfer = false
static

Definition at line 62 of file dvbci.cpp.

Referenced by cTPDU::Dump().

◆ sDebugProtocol

bool sDebugProtocol = false
static

Definition at line 63 of file dvbci.cpp.

◆ sConnected

bool sConnected = false
static

Definition at line 64 of file dvbci.cpp.

Referenced by cLlCiHandler::connected(), and cCiTransportConnection::CreateConnection().

◆ OK

constexpr int OK { 0 }
staticconstexpr

◆ TIMEOUT

constexpr int TIMEOUT { -1 }
staticconstexpr

Definition at line 70 of file dvbci.cpp.

Referenced by cCiTransportLayer::Process().

◆ ERROR

constexpr int ERROR { -2 }
staticconstexpr

◆ WRKRND_TIME_BEFORE_ENTER_MENU

constexpr time_t WRKRND_TIME_BEFORE_ENTER_MENU { 15 }
staticconstexpr

Definition at line 77 of file dvbci.cpp.

Referenced by cCiApplicationInformation::EnterMenu().

◆ SIZE_INDICATOR

constexpr int SIZE_INDICATOR { 0x80 }
staticconstexpr

Definition at line 81 of file dvbci.cpp.

Referenced by GetLength(), and SetLength().

◆ MAX_TPDU_SIZE

constexpr size_t MAX_TPDU_SIZE { 2048 }
staticconstexpr

Definition at line 245 of file dvbci.cpp.

◆ MAX_TPDU_DATA

constexpr int MAX_TPDU_DATA { MAX_TPDU_SIZE - 4 }
staticconstexpr

Definition at line 246 of file dvbci.cpp.

Referenced by cTPDU::cTPDU(), and cCiTransportConnection::SendData().

◆ DATA_INDICATOR

constexpr uint8_t DATA_INDICATOR { 0x80 }
staticconstexpr

Definition at line 248 of file dvbci.cpp.

Referenced by cCiTransportConnection::RecvTPDU().

◆ CAM_READ_TIMEOUT

constexpr int CAM_READ_TIMEOUT { 5000 }
staticconstexpr

Definition at line 454 of file dvbci.cpp.

Referenced by cCiTransportConnection::RecvTPDU().

◆ MAX_CONNECT_RETRIES

constexpr int8_t MAX_CONNECT_RETRIES { 25 }
staticconstexpr

Definition at line 543 of file dvbci.cpp.

Referenced by cCiTransportConnection::CreateConnection().

◆ POLL_INTERVAL

constexpr std::chrono::milliseconds POLL_INTERVAL { 100ms }
staticconstexpr

Definition at line 571 of file dvbci.cpp.

Referenced by cCiTransportConnection::Poll().

◆ MAX_CI_CONNECT

constexpr size_t MAX_CI_CONNECT { 16 }
staticconstexpr

Definition at line 594 of file dvbci.cpp.

Referenced by cCiTransportLayer::NewConnection().

◆ EF_BLIND

constexpr uint8_t EF_BLIND { 0x01 }
staticconstexpr

Definition at line 1236 of file dvbci.cpp.

Referenced by cCiMMI::Process().