/************************************************************************* * * DsmccCommon.h - Contains the structures and includes DSMCC module * * Copyright 2006 Digital Stream Technology * All Rights Reserved * **************************************************************************/ #ifndef DSMCC_COMMON_H #define DSMCC_COMMON_H //#include "dstddPsiBitBuffer.h" #include "dsthalPsiMemChain.h" //#include "DsmccAPI.h" /************************************************************************** DSM-CC DDB Structure Defines **************************************************************************/ typedef enum { eDDBMemData, // DDB buffer contains module image eDDBFileData // DDB buffer contains filename string } eDDBDataType_t; // DDB message processing return values typedef enum { eDsmccDDBTableIsComplete, eDsmccDDBInitContextFail, eDsmccDDBOutOfCPUMemory, eDsmccDDBParseError, eDsmccDDBWrongDownloadId, eDsmccDDBWrongModuleId, eDsmccDDBWrongVersion, eDsmccDDBInvalidBlockNum, eDsmccDDBBlockRecvd, eDsmccDDBMemOutOfBound } eDSMCCRetval_t; // Event message enumerates typedef enum { eDsmccDeactivate, eDsmccActivate, eDsmccDIIDataReceived, eDsmccDDBDataReceived } eDSMCCEvent_t; typedef void (*DsmccEventProc_t)( DHL_PSI_HANDLE *psiHandle, void *pDsmccData ); typedef void (*DsmccStatusProc_t)( DHL_PSI_HANDLE *psiHandle, eDSMCCRetval_t DsmccMsg, DS_U32 param); // This data structure is returned to DSMCC DDB client as the callback function's parameter // Client needs to destroy this data structure using FreeDsmccMemChain( DDBModulePtr_t ) typedef struct { //*** Copies of DDB monitoring parameters ***// DS_U16 moduleId; // DDB module ID DS_U8 moduleVersion; // DDB module version DS_U32 moduleSize; // DDB total module size //*** DDB module info and data ***// eDDBDataType_t dataType; // Type of information in the buffer DS_U8 *pDDBBuffer; // Buffer to store the module data or path/filename string DS_U8 *pDDBIndex; // The path/filename string of block directory (contains block number and index) DS_U32 blockTotal; // Total number of blocks DS_U16 blockSize; // Size of each block } DDBModule_t, *DDBModulePtr_t; typedef struct { DS_U16 blockNumber; // The block's sequence number DS_U16 blockIndex; // The data block index in the DDB module data file } DDBFileDir_t, *DDBFileDirPtr_t; /************************************************************************** DSM-CC DII Structure Defines **************************************************************************/ typedef struct { DS_U8 adaptationType; DS_U8 DIIMsgNumber; } *dsmccDIIAdaptHeaderPtr_t; typedef struct { DS_U8 protocolDiscriminator; DS_U8 dsmccType; DS_U16 messageId; DS_U32 transaction_id; DS_U8 adaptationLength; DS_U16 messageLength; dsmccDIIAdaptHeaderPtr_t ptrDsmccAdaptationHeader; } DsmccMsgHeader_t, *DsmccMsgHeaderPtr_t; typedef struct { DS_U8 subDescType; DS_U8 subDescLength; DS_U8 subDescInfoByte; } CompatblSubDesc_t, *CompatblSubDescPtr_t; typedef struct { DS_U8 descType; DS_U8 descLength; DS_U8 specifierType; DS_U32 specifierData; DS_U16 model; DS_U16 version; DS_BOOL bValid; DS_U8 subDescCount; ////CompatblSubDesc_t subDescInfo; } CompatblDescInfo_t, *CompatblDescInfoPtr_t; typedef struct { DS_U16 descLength; DS_U16 descCount; DS_U8 *descriptors; CompatblDescInfo_t compatblDescInfo; } CompatblDesc_t; typedef struct { DS_U16 moduleId; DS_U32 moduleSize; DS_U8 moduleVersion; DS_U8 moduleInfoLength; DS_U8* ptrModuleInfoByte; DS_U16 module_name_length; DS_U8* ptrModuleName; /* Retrieved from ModuleInfo_descriptor. Refer A/97 5.3.1 */ DS_BOOL bCrcFieldValid; DS_U32 Crc32_descriptor; /* Retrieved from CRC32_descriptor. Refer A/90 7.2.3.6.2 */ } ModuleInfo_t, *ModuleInfoPtr_t; typedef struct { DsmccMsgHeaderPtr_t ptrDsmccMsgHeader; DS_U32 downloadId; DS_U16 blockSize; DS_U8 windowSize; DS_U8 ackPeriod; DS_U32 tCDownloadWindow; DS_U32 tCDownloadScenario; CompatblDesc_t compatblDesc; DS_U16 numberOfModules; ModuleInfoPtr_t ptrDIIModuleInfo; DS_U16 privateDataLength; DS_U8* ptrPrivateDataByte; } DIIMsg_t, *DIIMsgPtr_t; // This data structure is returned to DSMCC DII client as the callback function's parameter // Client needs to destroy this data structure using FreeDsmccMemChain() typedef struct { //*** Optional information obtained from the 1st section of DSMCC-DII table ***// DS_U8 table_id; /* Table ID */ DS_U16 dsmcc_section_length; /* Length of 1st section */ DS_U16 table_id_extension; /* Contains DII transaction number */ DS_U8 version_number; /* Version number. When the table is updated, this value is changed. */ DS_U8 current_next_indicator; /* If table id is 0x3B this must be 1 */ DS_U8 section_number; /* Section number */ DS_U8 last_section_number; /* Last section number in multi section */ DS_U32 transaction_id; /* Transaction ID indicated in 1st section dsmccMessageHeader */ DS_U32 downloadId; /* Data carousel ID indicated in 1st section */ DS_U16 blockSize; /* Size of DDB message block indicated in 1st section */ //*** DII message section array ***// DS_U8 numSections; /* Number of DII msg sections */ DIIMsgPtr_t ptrDIIMsgSections; /* Ptr to DII msg sections (DIIMsg_t structures) */ } DsmccDIIMsg_t, *DsmccDIIMsgPtr_t; /************************************************************************** DSM-CC APIs **************************************************************************/ DHL_RESULT DHL_PSI_ActivateDDBTask( int *pAppTaskPriority ); /* Must be called once before start monitoring DII/DDB */ DHL_RESULT DHL_PSI_DeactivateDDBTask( void ); /* Terminate DSMCC task and all active DII/DDB monitors */ DHL_RESULT FreeDsmccMemChain( void* pDsmccMem ); #if 0 DHL_RESULT DHL_PSI_MonitorDsmccDII( DHL_PSI_HANDLE sysInfo, /* Transport unit */ DS_U16 Pid, /* DII Pid to monitor */ DS_U16 transactionId, /* The transaction ID (from SDTT?) */ DsmccEventProc_t pfCallbackProc, /* Client callback func ptr */ DHL_TBL_HANDLE *returnPsiCtl /* PSI Ctl structure */ ); #else DHL_RESULT DHL_PSI_MonitorDsmccDII( DHL_PSI_HANDLE sysInfo, DS_U16 Pid, DS_U16 transactionId, DsmccEventProc_t pfCallbackProc, DS_U32 userParam, DHL_PSI_HANDLE *returnPsiCtl ); #endif DHL_RESULT DHL_PSI_CancelDsmccDII( DHL_TBL_HANDLE *psiCtl ); DHL_RESULT DHL_PSI_MonitorDsmccDDB( DHL_PSI_HANDLE sysInfo, /* Transport unit */ DS_U16 Pid, /* DDB Pid to monitor */ DS_U32 downloadId, /* Identifies the carousel ID */ DS_U16 moduleId, /* Module ID from DII module info */ DS_U8 moduleVersion, /* Module version from DII module info */ DS_U32 moduleSize, /* Total module size in bytes from DII module info */ DS_U16 blockSize, /* DDB block size from DII module info */ DsmccEventProc_t pfCallbackProc, DsmccStatusProc_t pfStatusProc, DHL_PSI_HANDLE *returnPsiCtl ); DHL_RESULT DHL_PSI_CancelDsmccDDB( DHL_PSI_HANDLE *psiCtl ); void *DHL_PSI_GetDsmccDDBBuffer(DHL_PSI_HANDLE psiCtl); void DHL_PSI_SetDsmccAllocFreeFunc(void *AllocFunc, void *FreeFunc); int DHL_PSI_GetDsmccDDBProgress(DHL_PSI_HANDLE psiCtl); void DHL_PSI_FreeDDBBuffer(void *addr); #define DSMCC_DEBUG 0 // Set to 0 for non debug #define DSMCC_DISKFILE 0 // Diskfile buffering support #define DSMCCDDB_TASK_PRIO 0 // Priority of DSM-CC task // DSM-CC Table IDs #define DSMCC_DII_TABLE_ID 0x3B #define DSMCC_DDB_TABLE_ID 0x3C #define MAX_DSMCC_SECTION_LENGTH 4096 // Maximum DSMCC message section length #define MAX_DSMCC_SECTIONS 256 #define MIN_DSMCC_SECTIONS 1 #define NUM_DII_MON_CONTEXTS 16 // Maximum numbers of simultaneous DII monitors #define NUM_DDB_MON_CONTEXTS 16 // Maximum numbers of simultaneous DDB monitors #define DSMCC_FILE_BUFSECTIONS 16 // Number of DDB sections buffered in diskfile mode #define DDB_PATH_FILENAME "/udma/dsmcc/Mod" // DSMCC thread event message data structure typedef struct { eDSMCCEvent_t event; DS_U32 userParam; DHL_PSI_HANDLE *psiCtl; void *param; PSIDataArray_t *desc; } DsmccMsg_t; // DII monitor context data structure typedef struct { DS_BOOL isUsed; // This DII context use flag DsmccEventProc_t pfCallbackProc; // Client callback function ptr DHL_PSI_HANDLE *psiCtl; // PSI Ctl of the DII context } DIIMsgMonContext_t, *DIIMsgMonContextPtr_t; // DDB monitor context data structure typedef struct { DS_BOOL isUsed; // This DDB context use flag DsmccEventProc_t pfCallbackProc; // Client callback function ptr DsmccStatusProc_t pfStatusProc; // Status callbck function ptr //*** DDB monitoring parameters ***// DS_BOOL isInitialized; // Buffers are allocated DS_U32 downloadId; // DDB download ID identifies the data carousel DS_U16 moduleId; // DDB module ID DS_U8 moduleVersion; // DDB module version DS_U32 moduleSize; // DDB total module size DS_U16 blockSize; // DDB block size DS_U16 lastBlockSize; // DDB last block size DS_U32 blockRecvd; // Number of blocks received DS_U32 blockTotal; // Total number of blocks memId_t memId; // MemChain ID for allocating data structure for DSMCC-DDB client DDBModulePtr_t pDDBModule; // Ptr to data structure returned to DDB client DS_U8 *pBlockRecvBitFlags;// Bit flags to indicate the blocks received DHL_PSI_HANDLE *psiCtl; // PSI Ctl of the DDB context OS_MESSAGEQUEUE_ID dsmccQ; OS_TASK_ID dsmccTaskID; OS_SEMAPHORE_ID syncSema4; // Used to synchronize with DSMCC thread } DDBMsgMonContext_t, *DDBMsgMonContextPtr_t; // DSMCC thread global variable structure typedef struct { DS_BOOL isActive; OS_SEMAPHORE_ID mutexSema4; // Used to access DSMCC database variables OS_SEMAPHORE_ID controlSema4; DIIMsgMonContext_t DIIMonContexts[ NUM_DII_MON_CONTEXTS ]; // DII monitoring contexts DDBMsgMonContext_t DDBMonContexts[ NUM_DDB_MON_CONTEXTS ]; // DDB monitoring contexts } DSMCCDatabase_t; /************************************************************************** DSM-CC DDB Table Parsing Structure Defines The following data structures are used to parse the contents of DDB msgs **************************************************************************/ #define DSMCC_DDB_MEM_LIMIT (64*1024) // 64Kb max (4096) // 4Kb max typedef struct { DS_U8 adaptationType; DS_U8 adaptationDataByte; } *dsmccDDBAdaptHeaderPtr_t; typedef struct { DS_U8 protocolDiscriminator; DS_U8 dsmccType; DS_U16 messageId; DS_U32 downloadId; DS_U8 adaptationLength; DS_U16 messageLength; dsmccDDBAdaptHeaderPtr_t ptrDsmccAdaptationHeader; } DsmccDnldDataHdr_t, *DsmccDnldDataHdrPtr_t; typedef struct { DsmccDnldDataHdrPtr_t ptrDsmccDnldDataHdr; DS_U16 moduleId; /* Module ID */ DS_U8 moduleVersion; /* Version */ DS_U16 blockNumber; /* Block number */ DS_U8 *pBlockDataByte; /* DDB payload */ } DDBMsg_t, *DDBMsgPtr_t; // Structure used to parse DSMCC DDB message typedef struct { DS_U8 table_id; /* Table ID */ DS_U16 dsmcc_section_length; /* Length of section */ DS_U16 table_id_extension; /* Contains module ID */ DS_U8 version_number; /* Version number. When the table is updated, this value is changed. */ DS_U8 current_next_indicator; /* If table id is 0x3C this must be 1 */ DS_U8 section_number; /* Section number */ DS_U8 last_section_number; /* Last section number in multi section */ DDBMsgPtr_t ptrDDBMsgSection; /* Ptr to DDB msg section (DDBMsg_t structures) */ } DsmccDDBMsg_t, *DsmccDDBMsgPtr_t; /************************************************************************** DSM-CC DII Table Parsing Structure Defines The following data structures are used to parse the contents of DII msgs **************************************************************************/ #define DSMCC_DII_MEM_LIMIT (64*1024) // 64Kb max // This DSMCC encapsulator structure is used in DSMCC DII section parsing and returned to // ParseDsmccDII() typedef struct { DS_U8 table_id; /* Table ID */ DS_U16 dsmcc_section_length; /* Length of this section */ DS_U16 table_id_extension; /* Contains DII transaction number */ DS_U8 version_number; /* Version number. When the table is updated, this value is changed. */ DS_U8 current_next_indicator; /* If table id is 0x3B this must be 1 */ DS_U8 section_number; /* Section number */ DS_U8 last_section_number; /* Last section number in multi section */ DIIMsgPtr_t ptrDIIMsgSection; /* DII msg section */ } dsmccDIISection_t, *dsmccDIISectionPtr_t; /*============================================================================== DSMCC Type definitions ==============================================================================*/ #define DSMCC_MESSAGE_HEADER_PREFIX 0x11 /* DSMCC_Section.protocolDiscriminator = 0x11 */ #define DSMCC_MESSAGE_HEADER_TYPE 0x03 /* DSMCC_Section.dsmccType = 0x03 */ #define COMPATBL_DESC_SYSTEM_HW 0x01 #define COMPATBL_DESC_SYSTEM_SW 0x02 typedef enum { DSMCC_MESSAGE_DIREQ=((DSMCC_MESSAGE_HEADER_PREFIX<<24)+(DSMCC_MESSAGE_HEADER_TYPE<<16)+0x1001), // DownloadInfoRequest DSMCC_MESSAGE_DIRSP=((DSMCC_MESSAGE_HEADER_PREFIX<<24)+(DSMCC_MESSAGE_HEADER_TYPE<<16)+0x1002), // DownloadInfoResponse DSMCC_MESSAGE_DII=((DSMCC_MESSAGE_HEADER_PREFIX<<24)+(DSMCC_MESSAGE_HEADER_TYPE<<16)+0x1002), // DownloadInfoIndication DSMCC_MESSAGE_DDB=((DSMCC_MESSAGE_HEADER_PREFIX<<24)+(DSMCC_MESSAGE_HEADER_TYPE<<16)+0x1003), // DownloadDataBlock DSMCC_MESSAGE_DDR=((DSMCC_MESSAGE_HEADER_PREFIX<<24)+(DSMCC_MESSAGE_HEADER_TYPE<<16)+0x1004), // DownloadDataRequest DSMCC_MESSAGE_DC =((DSMCC_MESSAGE_HEADER_PREFIX<<24)+(DSMCC_MESSAGE_HEADER_TYPE<<16)+0x1005), // DownloadCancel DSMCC_MESSAGE_DSI=((DSMCC_MESSAGE_HEADER_PREFIX<<24)+(DSMCC_MESSAGE_HEADER_TYPE<<16)+0x1006), // DownloadSeverInitiate } dsmcc_message_type; /************************************************************************** DSM-CC DII and DDB private function prototypes **************************************************************************/ void PrintDsmccDII( const DsmccDIIMsgPtr_t pDsmccDIIMsg ); DHL_RESULT ParseDsmccDII( PSIDataArray_t *desc, DsmccDIIMsgPtr_t *ppDsmccDIIMsg ); eDSMCCRetval_t ProcessDsmccDDB( PSIDataArray_t *desc, DDBMsgMonContextPtr_t pDDBMsgMonContext, DDBModulePtr_t *ppDDBModule ); #if DSMCC_DISKFILE // Diskfile support void CloseDDBCaptureFiles( DDBMsgMonContextPtr_t pDDBMsgMonContext ); #endif #endif