⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psfdemux_drm.c

📁 Sample code for use on smp 863x processor.
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * * Copyright (c) Sigma Designs, Inc. 2006. All rights reserved. * *//* * *********************************************************** * This is UGLY, #including this file isnt the way to go, but * it's a fast way of cleaning play_psfdemux.c * The best approach will be to convert this into a library * and merge it with RMDRM lib. * *********************************************************** *//**   @file psfdemux_drm.c   @brief drm functionality for play_psfdemux	   @author Aurelia Popa-Radu   @ingroup dccsamplecode*/#include "../samples/sample_os.h"#define ALLOW_OS_CODE 1#include "../dcc/include/dcc.h"#include "../samples/common.h"#include "psfdemux_common.h"#if (ALLOW_LIBRMARIB)#include <dlfcn.h>#endif#if 0#define LOCALDBG ENABLE#else#define LOCALDBG DISABLE#endif#if 0#define CALLDBG ENABLE#else#define CALLDBG DISABLE#endif#if 0#define KEYDBG ENABLE#else#define KEYDBG DISABLE#endif/**************************** application types *******************************/RMstatus DvbKeyInband(struct context_per_task *context, RMuint8 ecm_entry, enum EMhwlibScramblingBits scrambling, RMuint8 *pkey, RMuint32 key_size){	RMuint32 size;	RMuint32 offset = (ecm_entry == ECM0_SECTION_ENTRY) ? 0 : 1;	struct DemuxTask_InbandKeyChange_type ibc;		RUAGetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_InbandFifoWritableSize, &size, sizeof(size));	if (size == 0) {		RMDBGLOG((LOCALDBG, "********************** insufficient InbandFifoWritableSize\n"));		return RM_INSUFFICIENT_SIZE;	}		/* set the key using inband command */	if (scrambling == EMhwlibScramblingBits_10) {		ibc.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((ENABLE, "********************** DvbKeyInband Even *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_11) {		ibc.key_index = context->key_index[(offset << 1) + 1];		RMDBGLOG((ENABLE, "********************** DvbKeyInband Odd *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_10_11) {		ibc.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((ENABLE, "********************** DvbKeyInband Even+Odd *********************************\n"));	}	{		struct DemuxTask_DVBCSAKey_type dvb_key;		dvb_key.key_index = ibc.key_index;		RMMemcpy(dvb_key.key, pkey, key_size);		/* do DVBCSA conformance mechanism */		dvb_key.key[0] = (dvb_key.key[1] + dvb_key.key[2] + dvb_key.key[3])%256;		dvb_key.key[4] = (dvb_key.key[5] + dvb_key.key[6] + dvb_key.key[7])%256;		RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_DVBCSAKey, &dvb_key, sizeof(dvb_key), 0);	}	//fprintf(stderr, "DvbKeyInband key_index=%ld, cipher_index=%ld\n", ibc.key_index, context->cipher_index[offset]);		/* set key for entry 0 in CipherTable */	ibc.cipher_index = context->cipher_index[offset];	ibc.scrambling = scrambling;	ibc.offset_control = EMhwlibInbandOffset_Ignore;	ibc.offset_value = 0;	return RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_InbandKeyChange, &ibc, sizeof(ibc), 0);}RMstatus DvbKeyOutband(struct context_per_task *context, RMuint8 ecm_entry, enum EMhwlibScramblingBits scrambling, RMuint8 *pkey, RMuint32 key_size){	RMuint32 offset = (ecm_entry == ECM0_SECTION_ENTRY) ? 0 : 1;	struct DemuxTask_DVBCSAKey_type dvb_key;	struct DemuxTask_OutbandKeyChange_type outband;		/* set the key using outband command */	if (scrambling == EMhwlibScramblingBits_10) {		outband.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((ENABLE, "********************** DvbKeyOutband Even *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_11) {		outband.key_index = context->key_index[(offset << 1) + 1];		RMDBGLOG((ENABLE, "********************** DvbKeyOutband Odd *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_10_11) {		outband.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((ENABLE, "********************** DvbKeyOutband Even+Odd *********************************\n"));	}	dvb_key.key_index = outband.key_index;	RMMemcpy(dvb_key.key, pkey, key_size);	/* do DVBCSA conformance mechanism */	dvb_key.key[0] = (dvb_key.key[1] + dvb_key.key[2] + dvb_key.key[3])%256;	dvb_key.key[4] = (dvb_key.key[5] + dvb_key.key[6] + dvb_key.key[7])%256;	RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_DVBCSAKey, &dvb_key, sizeof(dvb_key), 0);		/* set key index for entry 0 in CipherTable */	outband.cipher_index = context->cipher_index[offset];	outband.cipher_type = EMhwlibCipher_DVBCSA;	outband.scrambling = scrambling;	return RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_OutbandKeyChange, &outband, sizeof(outband), 0);}RMstatus AESKeyInband(struct context_per_task *context, RMuint8 ecm_entry, enum EMhwlibScramblingBits scrambling, RMuint8 *pkey, RMuint8 *piv, RMuint32 key_size){	RMuint32 size;	struct DemuxTask_InbandKeyChange_type ibc;	RMuint32 offset = (ecm_entry == ECM0_SECTION_ENTRY) ? 0 : 1;	struct DemuxTask_AESKey_type aes_key;		RUAGetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_InbandFifoWritableSize, &size, sizeof(size));	if (size == 0) {		RMDBGLOG((LOCALDBG, "********************** insufficient InbandFifoWritableSize\n"));		return RM_INSUFFICIENT_SIZE;	}		/* set the key using inband command */	// assuming the first two keys are associated with cipher 0	ibc.cipher_index = 0;	if (scrambling == EMhwlibScramblingBits_10) {		ibc.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((KEYDBG, "AESKeyInband Even cipher_index %d key_index %d\n", ibc.cipher_index, ibc.key_index));	}	else if (scrambling == EMhwlibScramblingBits_11) {		ibc.key_index = context->key_index[(offset << 1) + 1];		RMDBGLOG((KEYDBG, "AESKeyInband Odd cipher_index %d key_index %d\n", ibc.cipher_index, ibc.key_index));	}	else if (scrambling == EMhwlibScramblingBits_10_11) {		ibc.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((KEYDBG, "AESKeyInband Even+Odd cipher_index %d key_index %d\n", ibc.cipher_index, ibc.key_index));	}	aes_key.key_index = ibc.key_index;	aes_key.key_size = key_size; // 16 bytes	RMMemcpy(aes_key.key, pkey, key_size);	RMMemcpy(aes_key.iv, piv, key_size);	RMDBGLOG((KEYDBG, "AESKey key_index %d key_size %d\n", aes_key.key_index, aes_key.key_size));	RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AESKey, &aes_key, sizeof(aes_key), 0);		/* set key for entry 0 in CipherTable */	ibc.cipher_index = context->cipher_index[offset];	ibc.scrambling = scrambling;	ibc.offset_control = EMhwlibInbandOffset_Ignore;	ibc.offset_value = 0;	RMDBGLOG((KEYDBG, "Key change cipher_index %d key_index %d scrambling bits %d  inband no offset\n\n", ibc.cipher_index, ibc.key_index, ibc.scrambling));	return RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_InbandKeyChange, &ibc, sizeof(ibc), 0);}RMstatus AESKeyOutband(struct context_per_task *context, RMuint8 ecm_entry, enum EMhwlibScramblingBits scrambling, RMuint8 *pkey, RMuint8 *piv, RMuint32 key_size){	RMuint32 offset = (ecm_entry == ECM0_SECTION_ENTRY) ? 0 : 1;	struct DemuxTask_AESKey_type aes_key;	struct DemuxTask_OutbandKeyChange_type outband;		/* set the key using outband command */	if (scrambling == EMhwlibScramblingBits_10) {		outband.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((KEYDBG, "********************** AesKeyOutband Even *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_11) {		outband.key_index = context->key_index[(offset << 1) + 1];		RMDBGLOG((KEYDBG, "********************** AesKeyOutband Odd *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_10_11) {		outband.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((KEYDBG, "********************** AesKeyOutband Even+Odd *********************************\n"));	}	aes_key.key_index = outband.key_index;	aes_key.key_size = key_size; // 16 bytes	RMMemcpy(aes_key.key, pkey, key_size);	RMMemcpy(aes_key.iv, piv, key_size);	RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_AESKey, &aes_key, sizeof(aes_key), 0);		/* set key index for entry 0 in CipherTable */	outband.cipher_index = context->cipher_index[offset];	outband.cipher_type = EMhwlibCipher_AES;	outband.scrambling = scrambling;	return RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_OutbandKeyChange, &outband, sizeof(outband), 0);}/* ############## AES_CBC_PRECIPHER CODE BEGIN ############## */RMstatus AESKeyPrecipherInband(struct RUA *Context_RUA,RMuint32 Context_demux_task,enum EMhwlibScramblingBits scrambling, RMuint8 *pkey, RMuint8 *piv, RMuint32 key_size,RMuint32 inband_state){	RMstatus err;	RMuint32 size = 0;	struct DemuxTask_InbandKeyChange_type ibc;	struct DemuxTask_AESKey_type aes_key;	struct DemuxTask_PreprocessCipher_type ppc;	/*********** write AES Key *************************/	aes_key.key_index = (inband_state&1)?1:0;	aes_key.key_size = key_size;	RMMemcpy(aes_key.key,pkey, key_size);	RMMemcpy(aes_key.iv ,piv , key_size);                                                                                                                             	err=RUASetProperty(Context_RUA, Context_demux_task, RMDemuxTaskPropertyID_AESKey, &aes_key, sizeof(aes_key), 0);	if (RMFAILED(err)){		RMDBGLOG((ENABLE, "AESKeyPrecipherInband :error AESKey\n"));		return RM_ERROR;	}	/*********** Set PreprocessCipher *******************/	if (inband_state == 0) {		ppc.enable = TRUE;		ppc.cipher_index = 0;		err = RUASetProperty(Context_RUA, Context_demux_task, RMDemuxTaskPropertyID_PreprocessCipher, &ppc, sizeof(ppc), 0);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "AESKeyPrecipherInband:error PreprocessCipher\n"));			return RM_ERROR;		}	}	/********** InbandFifoWritableSize *****************/	err = RUAGetProperty(Context_RUA, Context_demux_task, RMDemuxTaskPropertyID_InbandFifoWritableSize, &size, sizeof(size));	if (size == 0 || RMFAILED(err)) {		RMDBGLOG((ENABLE, "********************** insufficient InbandFifoWritableSize\n"));		return RM_ERROR;	}		/*** Inband Key Change: set key_index 0 or 1 for cipher entry 0 in CipherTable ***/	ibc.key_index = (inband_state & 1);	ibc.cipher_index = 0;	ibc.scrambling = scrambling;	ibc.offset_control = EMhwlibInbandOffset_Ignore;	ibc.offset_value = 0;	err = RUASetProperty(Context_RUA, Context_demux_task, RMDemuxTaskPropertyID_InbandKeyChange, &ibc, sizeof(ibc), 0);		if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "AESKeyPrecipherInband :error InbandKeyChange"));		return RM_ERROR;	}		return RM_OK;}/* ############## AES_CBC_PRECIPHER CODE END ############### *//************************************************************************ * Use Inband command through demuxhw writing multi2 key into table ************************************************************************/RMstatus Multi2KeyInband(struct context_per_task *context, RMuint32 index, enum key_type key_type){	RMuint32	size;	RMstatus	err = RM_OK;	struct		DemuxTask_InbandKeyChange_type ibc;	struct		arib_key_band *ecm_key;		RUAGetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_InbandFifoWritableSize, &size, sizeof(size));	if (size == 0) {		RMDBGLOG((LOCALDBG, "********************** insufficient InbandFifoWritableSize\n"));		return RM_INSUFFICIENT_SIZE;	}		ecm_key = &(context->arib_key_table[index]);	/*	 * Reuse the already allocated entry in the Multi2Table	 */	ibc.key_index = ecm_key->multi2_key.key_index;	/*	 * Setup Multi2Table for demux task	 */	err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_Multi2Key, &(ecm_key->multi2_key), sizeof(struct DemuxTask_Multi2Key_type), 0);	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Error RMDemuxTaskPropertyID_Multi2Key\n"));		return(err);	}		/*	 * Already setup ciphertable index?	 */	if (!ecm_key->ciphertable_done) {		/*		 * scrambling = ? offset_control = ? offset_value = ?		 */		if (key_type == EVEN_KEY) {			ecm_key->scrambling = EMhwlibScramblingBits_10;		}		else {			ecm_key->scrambling = EMhwlibScramblingBits_11;		}		ecm_key->offset_control = EMhwlibInbandOffset_Absolute;		ecm_key->offset_value = context->file_byte_counter;		/*		 * Set key for entry #emc_key->index_cipher_table in CipherTable		 */		ibc.cipher_index = ecm_key->index_cipher_table;		ibc.scrambling = ecm_key->scrambling;		ibc.offset_control = ecm_key->offset_control;		ibc.offset_value = ecm_key->offset_value;		err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_InbandKeyChange, &ibc, sizeof(ibc), 0);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Error RMDemuxTaskPropertyID_InbandKeyChange\n"));			return(err);		}		ecm_key->ciphertable_done = TRUE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -