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

📄 psfdemux_drm.c

📁 Sample code for use on smp 863x processor.
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	return(err);}/************************************************************************ * Use Outband command through demuxhw writing multi2 key into table ************************************************************************/RMstatus Multi2KeyOutband(struct context_per_task *context, RMuint32 index, enum key_type key_type){	RMstatus	err;	struct		DemuxTask_OutbandKeyChange_type outband;	struct		arib_key_band *ecm_key;		ecm_key = &(context->arib_key_table[index]);	RMDBGLOG((KEYDBG, "key index %d, type %d, 0x%lx, actually index %d \n", index, key_type, ecm_key->index_cipher_table, ecm_key->multi2_key.key_index ));		/*	 * Reuse the already allocated entry in the Multi2Table	 */	outband.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_Ignore;		ecm_key->offset_value = 0;		/*		 * Set key for entry #emc_key->index_cipher_table in CipherTable		 */		outband.cipher_type = EMhwlibCipher_Multi2;		outband.cipher_index = ecm_key->index_cipher_table;		outband.scrambling = ecm_key->scrambling;		err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_OutbandKeyChange, &outband, sizeof(outband), 0);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Error RMDemuxTaskPropertyID_OutbandKeyChange\n"));			return(err);		}		ecm_key->ciphertable_done = TRUE;	}	return(err);}/************************************************************************ * Use xtask to write ClearText DVB-CSA key into table ************************************************************************/RMstatus DvbKeyXtask(struct context_per_task *context, RMuint8 ecm_entry, enum EMhwlibScramblingBits scrambling, RMuint8 *pkey){#if (ALLOW_LIBRMARIB)	RMstatus err;	RMascii *error;	RMuint32 offset = (ecm_entry == ECM0_SECTION_ENTRY) ? 0 : 1;	struct DemuxTask_OutbandKeyChange_type outband;	RMstatus	(*set_dvb_key_table)(RMuint8 *key, RMuint32 index);		set_dvb_key_table = dlsym(context->drm_handle, "rmdrm_set_dvb_key_table");	if (((error = dlerror()) != NULL) || (set_dvb_key_table == NULL)) {		RMDBGLOG((ENABLE, "Error getting librmarib.so interface : %s\n", error));		dlclose(context->drm_handle);		context->drm_handle = NULL;		return(RM_ERROR);	}		/* set the key using outband command */	if (scrambling == EMhwlibScramblingBits_10) {		outband.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((ENABLE, "********************** DvbKeyXtask Even *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_11) {		outband.key_index = context->key_index[(offset << 1) + 1];		RMDBGLOG((ENABLE, "********************** DvbKeyXtask Odd *********************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_10_11) {		outband.key_index = context->key_index[(offset << 1) + 0];		RMDBGLOG((ENABLE, "********************** DvbKeyXtask Even+Odd *********************************\n"));	}	/*	 * Setup DvbTable for demux task	 */	err = (*set_dvb_key_table)(pkey, outband.key_index);	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Error Xtask wirte ClearText key\n"));		return(err);	}		/* 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);#else	return RM_NOTIMPLEMENTED;#endif // #if (ALLOW_LIBRMARIB)}/************************************************************************ * Use xtask to write CipherText DVB-CSA key into table ************************************************************************/#if 0RMstatus DvbKeyXtaskEncrypted(struct context_per_task *context, enum EMhwlibScramblingBits scrambling, RMuint8 *pkey){#if (ALLOW_LIBRMARIB)	static const struct { RMuint8 key[8]; RMuint32 cipher_text[32]; }	Dvb4ECMCipher[4] = {		{ { 0x5e, 0x2d, 0x29, 0x08, 0xbd, 0x2d, 0x61, 0x2f },		  {		   0x99f0e7d2, 0x90b3fd00, 0xe0503b41, 0xeb448451,		   0x9af4f1ca, 0x6eeeffae, 0xb46f3fa6, 0x8d425caa,		   0x0bf76717, 0xed7ceb59, 0xf8ce4047, 0x877b3de4,		   0xc2089161, 0x3640623d, 0x9ee0a02d, 0x95ad25db,		   0xc53a7cc7, 0x56f94664, 0x3dfee25c, 0x95a2d598,		   0x86afbafb, 0x39d8bdc0, 0x2f280e33, 0x86ebe449,		   0x9943a933, 0xb0c4b324, 0x5bbdd634, 0x3d80bfc4,		   0x27f5fd05, 0xee3d00fc, 0x15086206, 0x561a7cc0,		  }		}, /* 4ECM key starts from LSB (byte 0) */		{ { 0x5c, 0x2c, 0x28, 0x08, 0xba, 0x2c, 0x60, 0x2e },		  {		   0xb30d014a, 0xc301d23e, 0x4c2265ae, 0x74a9b60a,		   0x9e7e0649, 0xc74277e0, 0x9d81f67b, 0xa66c71ce,		   0x14f64323, 0xa0a7d9e4, 0xa0128474, 0x615c5e02,		   0x1045227a, 0xb75a7c55, 0xcf604199, 0xde4b2a39,		   0x89ad3f81, 0xd8090de2, 0xafcf7be7, 0x19d02693,		   0xa7c07601, 0x7ee9d860, 0x375b4d06, 0x398da9a4,		   0x48e3eb7a, 0xa44f770c, 0xe90a6c21, 0xc7355cb9,		   0x8a848444, 0x4c54b7f0, 0x5a1cb989, 0x4625ff7d,		  }		},		{ { 0x62, 0x2f, 0x2b, 0x08, 0xbf, 0x2f, 0x63, 0x2d },		  {		   0x016b1b6e, 0x6daf00df, 0x3155ac6a, 0x6039bde2,		   0x9542d03a, 0x48261572, 0xb1e1c3b8, 0xbbccecbf,		   0xa1c5b94e, 0xa3454055, 0x778c0e8f, 0x240fe703,		   0x101d8f8a, 0x6edf7ee7, 0x652262c2, 0x3e757ac9,		   0x4c834f2f, 0x2ba0a381, 0x6244c81c, 0x58827c66,		   0x56b5514c, 0xe43eef31, 0x985f7933, 0xbb36dfe1,		   0x7673079b, 0x6421064d, 0xbe5f8a7a, 0xcfc20c77,		   0xbf967751, 0x921225b8, 0x14c3b6c9, 0xbd48f44b,		  }		},		{ { 0x60, 0x2e, 0x2a, 0x08, 0xbc, 0x2e, 0x62, 0x2c },		  {		   0x866f5d10, 0xb3f663f5, 0xa3df052d, 0x83ece431,		   0xc1862f3f, 0x8e6603fc, 0xb46cd56c, 0xd4308da3,		   0x6e370363, 0xd6257b0d, 0xb005dced, 0xd729353a,		   0x38a88819, 0x28ec8c17, 0x0b84196d, 0x384ba907,		   0x92949977, 0x3b63ba08, 0x72520960, 0x1a690930,		   0x477e3035, 0x955defc3, 0xdc1a76c2, 0x446a0070,		   0x2a1856fb, 0x74615f6b, 0xabcab675, 0x34da8f40,		   0x8bdd6369, 0xe2b0bc5d, 0x7f44da53, 0x1c57f8a4,		  }		},	};	RMuint32	i;	RMuint32 *	cipher_text = 0;	RMstatus	err;	RMascii *	error;	struct DemuxTask_OutbandKeyChange_type outband;	RMstatus	(*set_dvb_key_cipher)(RMuint32 *cipher_text, RMuint32 index);		set_dvb_key_cipher = dlsym(context->drm_handle, "rmdrm_set_dvb_key_cipher");	if (((error = dlerror()) != NULL) || (set_dvb_key_cipher == NULL)) {		RMDBGLOG((ENABLE, "Error getting librmarib.so interface : %s\n", error));		dlclose(context->drm_handle);		context->drm_handle = NULL;		return(RM_ERROR);	}		/* set the key using outband command */	if (scrambling == EMhwlibScramblingBits_10) {		outband.key_index = context->key_index[0];		RMDBGLOG((ENABLE, "********************** DvbKeyXtaskEncrypted Even *****************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_11) {		outband.key_index = context->key_index[1];		RMDBGLOG((ENABLE, "********************** DvbKeyXtaskEncrypted Odd ******************************\n"));	}	else if (scrambling == EMhwlibScramblingBits_10_11) {		outband.key_index = context->key_index[0];		RMDBGLOG((ENABLE, "********************** DvbKeyXtaskEncrypted Even+Odd *************************\n"));	}	for (i = 0; i < 4; i++) {		if (RMMemcmp((void*)pkey, (void *)Dvb4ECMCipher[i].key, 8)==0) {			cipher_text = (RMuint32 *)(Dvb4ECMCipher[i].cipher_text);			break;		}	}	if (cipher_text == 0) {		RMDBGLOG((ENABLE, "No matching CipherText for this key\n"));		return(RM_ERROR);	}	/*	 * Setup DvbTable for demux task	 */	err = (*set_dvb_key_cipher)(cipher_text, outband.key_index);	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Error Xtask wirte CipherText key\n"));		return(err);	}		/* set key index for entry 0 in CipherTable */	outband.cipher_index = context->cipher_index[0];	outband.cipher_type = EMhwlibCipher_DVBCSA;	outband.scrambling = scrambling;	return RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_OutbandKeyChange, &outband, sizeof(outband), 0);#else	return RM_NOTIMPLEMENTED;#endif // #if (ALLOW_LIBRMARIB)}#endif/************************************************************************ * Use xtask to write ClearText multi2 key into table ************************************************************************/RMstatus Multi2KeyXtask(struct context_per_task *context, RMuint32 index, enum key_type	key_type){#if (ALLOW_LIBRMARIB)	RMstatus	err;	RMascii *	error;	struct		arib_key_band *ecm_key;	struct		DemuxTask_OutbandKeyChange_type outband;	RMstatus	(*set_multi2_key_table)(RMuint8 *system_key, RMuint8 *data_key, RMuint8 *iv, RMuint32 index);		set_multi2_key_table = dlsym(context->drm_handle, "rmdrm_set_multi2_key_table");	if (((error = dlerror()) != NULL) || (set_multi2_key_table == NULL)) {		RMDBGLOG((ENABLE, "Error getting librmarib.so interface : %s\n", error));		dlclose(context->drm_handle);		context->drm_handle = NULL;		return(RM_ERROR);	}	ecm_key = &(context->arib_key_table[index]);	/*	 * Setup Multi2Table for demux task	 */	err = (*set_multi2_key_table)(ecm_key->multi2_key.system_key, ecm_key->multi2_key.data_key, ecm_key->multi2_key.iv, ecm_key->multi2_key.key_index); 	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Error Xtask wirte ClearText key\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_Ignore;		ecm_key->offset_value = 0;		/*		 * Set key for entry #emc_key->index_cipher_table in CipherTable		 */		outband.cipher_type = EMhwlibCipher_Multi2;		outband.cipher_index = ecm_key->index_cipher_table;		outband.scrambling = ecm_key->scrambling;		outband.key_index = ecm_key->multi2_key.key_index;		err = RUASetProperty(context->pRUA, context->demux_task, RMDemuxTaskPropertyID_OutbandKeyChange, &outband, sizeof(outband), 0);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Error RMDemuxTaskPropertyID_OutbandKeyChange\n"));			return(err);		}		ecm_key->ciphertable_done = TRUE;	}	return(err);#else	return RM_NOTIMPLEMENTED;#endif // #if (ALLOW_LIBRMARIB)}/************************************************************************ * Use xtask to write CipherText multi2 key into table ************************************************************************/RMstatus Multi2KeyXtaskEncrypted(struct context_per_task *context, RMuint32 index, enum key_type key_type){#if (ALLOW_LIBRMARIB)	RMstatus	err;	RMascii *	error;	struct		arib_key_band *ecm_key;	struct		DemuxTask_OutbandKeyChange_type outband;	RMstatus	(*set_multi2_key_cipher)(RMuint32 *cipher_text, RMuint32 index);		set_multi2_key_cipher = dlsym(context->drm_handle, "rmdrm_set_multi2_key_cipher");	if (((error = dlerror()) != NULL) || (set_multi2_key_cipher == NULL)) {		RMDBGLOG((ENABLE, "Error getting librmarib.so interface : %s\n", error));		dlclose(context->drm_handle);		context->drm_handle = NULL;		return(RM_ERROR);	}	ecm_key = &(context->arib_key_table[index]);	/*	 * Setup Multi2Table for demux task	 */	err = (*set_multi2_key_cipher)(ecm_key->cipher_text, ecm_key->multi2_key.key_index); 	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Error Xtask wirte CipherText key\n"));		return(err);	}	

⌨️ 快捷键说明

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