/* * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved. * Description: Define functions used to test function of demux driver * Author: Hisilicon * Create: 2019-4-25 */ #ifndef __UAPI_DESCRAMBLER_H__ #define __UAPI_DESCRAMBLER_H__ #include "td_type.h" #include "uapi_security.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif /* CA Entropy reduction mode.CNcomment:熵减少模式 */ typedef enum { UAPI_DMX_CA_ENTROPY_REDUCTION_CLOSE = 0, /* 64bit */ UAPI_DMX_CA_ENTROPY_REDUCTION_OPEN, /* 48bit */ UAPI_DMX_CA_ENTROPY_REDUCTION_MAX } uapi_dmx_ca_entropy; /* Attribute of the key area.CNcomment:密钥区属性 */ typedef struct { uapi_crypto_alg alg_type; /* Descrambling alg type of the descrambler.CNcomment:解扰器解扰协议类型 */ uapi_dmx_ca_entropy entropy_reduction; /* CA Entropy reduction mode,for CSA2.0.CNcomment:熵减少模式,CSA2.0有效 */ td_bool is_create_keyslot; /* Whether the keysloy will be created, when create descrambler */ } uapi_dmx_desc_attr; /* * brief Creates a key area. The key area type and descrambling protocol type can be selected. * CNcomment:创建一个密钥区,支持选择高安全CA和解扰协议类型。 * attention * When an advanced CA key area is created, the descrambling protocol depends on the hardware and interface settings * are ignored. * CNcomment:如果是高安全CA,解扰协议已经由硬件决定,接口的设置被忽略。 * param[in] dmx_id DEMUX ID. CNcomment: DEMUX号。 * param[in] attr Pointer to the attributes of a key area.CNcomment:密钥区属性指针。 * param[out] desc_handle Pointer to the handle of a created key area. * CNcomment:指针类型,输出申请到的密钥区Handle。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 * retval ::SOC_ERR_DMX_NOFREE_KEY There is no available key area.CNcomment:没有空闲的密钥区。 * retval ::SOC_ERR_DMX_NOT_SUPPORT Not support uapi_dmx_desc_attr type. * CNcomment:不支持的UAPI_DMX_DESCRAMBLER_ATTR_S类型。 */ td_s32 uapi_dmx_desc_create(td_u32 dmx_id, const uapi_dmx_desc_attr *attr, td_handle *desc_handle); /* * brief Destroys an existing key area.CNcomment:销毁创建的密钥区。 * attention * If a key area is attached to a channel, the key area needs to be detached from the channel first, * but the channel is not disabled. * If a key area is detached or destroyed before the attached channel is disabled, * an error may occur during data receiving. * CNcomment:如果密钥区绑定在通道上,会先从通道上解绑定密钥区,但是注意不会关闭通道 * 如果没有关闭通道则进行密钥区的解绑定或销毁操作,可能导致数据接收的错误。 * param[in] desc_handle Handle of the key area to be destroyed.CNcomment:待删除的密钥区Handle。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 */ td_s32 uapi_dmx_desc_destroy(td_handle desc_handle); /* * brief Gets the attributes of a Descrambler.CNcomment:获取密钥配置属性。 * attention * NA.CNcomment:无。 * param[in] desc_handle key handle. CNcomment: key句柄。 * param[out] attr Pointer to the attributes of a key area.CNcomment:密钥区属性指针。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 * retval ::SOC_ERR_DMX_NOFREE_KEY There is no available key area.CNcomment:没有空闲的密钥区。 * retval ::SOC_ERR_DMX_NOT_SUPPORT Not support uapi_dmx_desc_attr type. * CNcomment:不支持的uapi_dmx_desc_attr类型。 */ td_s32 uapi_dmx_desc_get_attr(td_handle desc_handle, uapi_dmx_desc_attr *attr); /* * brief Sets the attributes of a Descrambler.CNcomment:设置密钥配置属性。 * attention * NA.CNcomment:无。 * param[in] desc_handle key handle. CNcomment: key句柄。 * param[out] attr Pointer to the attributes of a key area.CNcomment:密钥区属性指针。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 * retval ::SOC_ERR_DMX_NOFREE_KEY There is no available key area.CNcomment:没有空闲的密钥区。 * retval ::SOC_ERR_DMX_NOT_SUPPORT Not support uapi_dmx_desc_attr type. * CNcomment:不支持的uapi_dmx_desc_attr类型。 */ td_s32 uapi_dmx_desc_set_attr(td_handle desc_handle, const uapi_dmx_desc_attr *attr); /* * brief Set Even IV.For algs do not use IV,do not care. * CNcomment:设置偶密钥区的初始化向量。对于不涉及初始化向量的解扰算法可以不关注。 * attention * even_iv points to the iv key data to be set.The data consists of 16 bytes: CW1, CW2, ..., and CW16. * The key value can be set dynamically, that is, the key value can be set at any time after a key area is created. * CNcomment:even_iv指向要设置的初始化向量数据。奇密钥数据共16byte,byte依次是CW1、CW2、……、CW16 * 支持密钥区的动态设置,可以在密钥区申请后的任意时刻设置。 * param[in] desc_handle Handle of the key area to be set.CNcomment:待设置的密钥区句柄。 * param[in] even_iv Pointer to the 16-byte IV key data to be set. * CNcomment:指针类型,指向要设置的偶密钥数据,必须是16个字节的数组。 * param[in] even_iv_len Length of the IV key data.CNcomment:偶密钥数据的长度。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 */ td_s32 uapi_dmx_desc_set_even_iv(td_handle desc_handle, const td_u8 *even_iv, td_u32 even_iv_len); /* * brief Set Odd IV.For algs do not use IV,do not care. * CNcomment:设置奇密钥区的初始化向量。对于不涉及初始化向量的解扰算法可以不关注。 * attention * odd_iv points to the iv key data to be set.The data consists of 16 bytes: CW1, CW2, ..., and CW16. * The key value can be set dynamically, that is, the key value can be set at any time after a key area is created. * CNcomment:odd_iv指向要设置的初始化向量数据。奇密钥数据共16byte,byte依次是CW1、CW2、……、CW16 * 支持密钥区的动态设置,可以在密钥区申请后的任意时刻设置。 * param[in] desc_handle Handle of the key area to be set.CNcomment:待设置的密钥区句柄。 * param[in] odd_iv Pointer to the 16-byte IV key data to be set. * CNcomment:指针类型,指向要设置的奇密钥数据,必须是16个字节的数组。 * param[in] odd_iv_len Length of the IV key data.CNcomment:奇密钥数据的长度。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 */ td_s32 uapi_dmx_desc_set_odd_iv(td_handle desc_handle, const td_u8 *odd_iv, td_u32 odd_iv_len); /* * brief Set system key,only used for multi2 algs.CNcomment:设置系统密钥,只用于multi2算法类型。 * attention * sys_key points to the system key data to be set.The data length is specified by parameter sys_key_len, * ususlly the length is 32 Bytes. * The system key value can be set before or after setting IV key and clear key, * and just need to set it once each taransport stream. * CNcomment:sys_key指向要设置的系统密钥数据。密钥数据的长度由参数sys_key_len指定,通常情况是32字节长度。 * 系统密钥可以在设置IV和明文密钥的之前或者之后设置,而且每条码流只需要设置一次。 * param[in] desc_handle Handle of the key area to be set.CNcomment:待设置的密钥区句柄。 * param[in] sys_key Pointer to the system key data to be set.CNcomment:指针类型,指向要设置的系统密钥数据。 * param[in] sys_key_len The length of system key.CNcomment:待设置的密钥的长度。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 */ td_s32 uapi_dmx_desc_set_sys_key(td_handle desc_handle, const td_u8 *sys_key, td_u32 sys_key_len); /* * brief Attaches a keyslot to a key area.CNcomment:绑定keyslot到指定的密钥区。 * attention * A keyslot can be attached to multiple keys. * The key area can obtain the key value from the keyslot module. * The same keyslot or different keyslot cannot be attached to the same key area. * CNcomment:一个keyslot可以绑定到多个密钥区上。 * 绑定后的密钥区可以从keyslot模块获取密钥值。 * 不允许重复绑定相同或不同的keyslot到同一个密钥区上。 * param[in] desc_handle Handle of the key area to be attached.CNcomment:待绑定的密钥区句柄。 * param[in] key_slot Keyslot handle.CNcomment:Keyslot句柄。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_ATTACHED_KEY A keyslot is attached to the key area.CNcomment:密钥区已经绑定了一个keyslot。 */ td_s32 uapi_dmx_desc_attach_key_slot(td_handle desc_handle, td_handle key_slot); /* * brief Detaches the keyslot handle of a key area.CNcomment:解绑定指定密钥区的keyslot句柄。 * attention * You can detach the keyslot at any time after the key area is created. * Detach can be successfully performed even if the key area is not attach to keyslot. * After detach the keyslot, the key area will not be able to get the key value from the keyslot module. * CNcomment:可以在密钥区创建后的任何时刻解绑定keyslot。 * 即使密钥区没有绑定keyslot句柄也可以成功执行解绑定。 * 解绑定keyslot之后密钥区将不能从keyslot模块获取密钥值。 * param[in] desc_handle Handle of the key area to be attached.CNcomment:待解绑定的密钥区句柄。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 */ td_s32 uapi_dmx_desc_detach_key_slot(td_handle desc_handle); /* * brief Get the keyslot handle of a key area.CNcomment:获取指定密钥区的keyslot句柄。 * attention * Used to get the detached keyslot handle from the specified key area. * If the key area did not attach to a keyslot, it will return failure. * CNcomment:用于从指定的密钥区获取绑定的keyslot句柄。 * 如果密钥区没有绑定keyslot,则会返回失败。 * param[in] desc_handle Handle of the key area to be attached.CNcomment:指定的密钥区句柄。 * param[out] key_slot Pointer to the handle of the keyslot that is attached to a key area (output). * CNcomment:指针类型,输出密钥区绑定的keyslot句柄。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NOATTACH_KEY A keyslot is not attached to the key area. * CNcomment:密钥区还没有绑定一个keyslot。 */ td_s32 uapi_dmx_desc_get_key_slot_handle(td_handle desc_handle, td_handle *key_slot); /* * brief Attaches a key area to a specific channel.CNcomment:绑定密钥区到指定通道。 * attention * A key area can be attached to multiple channels that belong to different DEMUXs. * The static loading data in the key areas that are attached to all types of channels can be descrambled. * The same key area or different key areas cannot be attached to the same pid channel. * CNcomment:一个密钥区可以绑定到多个通道上,通道可以属于不同的DEMUX * 可以对所有类型的通道绑定密钥区进行数据的解扰 * 不允许重复绑定相同或不同的密钥区到同一个通道上。 * param[in] desc_handle Handle of the key area to be attached.CNcomment:待绑定的密钥区句柄。 * param[in] pid_channel Pid channel handle.CNcomment:Pid通道句柄。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_ATTACHED_KEY A key area is attached to the channel. * CNcomment:通道上已经有一个密钥区绑定在上面。 */ td_s32 uapi_dmx_desc_attach_pid_chan(td_handle desc_handle, td_handle pid_chan); /* * brief Detaches a key area from a channel.CNcomment:将密钥区从通道上解绑定。 * attention * The key area used by a pid channel can be detached dynamically. * That is, you can call this API to detach a key area at any time after it is attached. * The scrambled data, however, may not be descrambled after the key area is detached, which causes data error. * The value of a key area retains even after it is detached. If the key area is attached again, * its value is still the previously configured value. * If you do not want to descramble data, you can detach the corresponding key area or set all key values to 0. * CNcomment:可以动态的解绑定通道使用的密钥区,可以在绑定后的任意时刻使用此接口解绑定密钥区 * 但是解绑定后可能导致加扰数据没有被解扰,导致数据错误 * 解绑定密钥区并不能改变密钥区的值,如果重新绑定密钥区,密钥值仍然是上次设置的值 * 如果不想进行解扰,除了解绑定密钥区之外,也可以直接将密钥值全部设置为0来实现。 * param[in] desc_handle Handle of the key area to be detached.CNcomment:待解绑定的密钥区句柄。 * param[in] pid_channel Pid channel handle.CNcomment:Pid通道句柄。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NOATTACH_KEY No key areas are attached to the channel.CNcomment:通道上没有绑定任何密钥区。 * retval ::SOC_ERR_DMX_UNMATCH_KEY The specified key area is not attached to the specified channel. * CNcomment:指定的密钥区没有绑定在指定的通道上。 */ td_s32 uapi_dmx_desc_detach_pid_chan(td_handle desc_handle, td_handle pid_chan); /* * brief Obtains the handle of the key area that is attached to a channel.CNcomment:获取通道绑定的密钥区句柄。 * attention * If no key area is attached to the channel, the error code SOC_ERR_DMX_NOATTACH_KEY is returned when you call the API. * CNcomment:当通道没有绑定密钥区时,调用本接口返回SOC_ERR_DMX_NOATTACH_KEY错误码。 * param[in] pid_hannel Handle of the channel to be queried.CNcomment:要查询的通道句柄。 * param[out] desc_handle Pointer to the handle of the key area that is attached to a channel (output). * CNcomment:指针类型,输出通道绑定的密钥区句柄。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 * retval ::SOC_ERR_DMX_NOATTACH_KEY No key areas are attached to the channel.CNcomment:通道上没有绑定任何密钥区。 */ td_s32 uapi_dmx_desc_get_handle(td_handle pid_chan, td_handle *desc_handle); /* * brief Obtains the number of available key areas.CNcomment:获取空闲密钥区数量。 * attention * Because key areas are shared by multiple DEMUXs, the first parameter is meaningless. * Therefore, you only need to enter a valid value. * CNcomment:密钥区在几路DEMUX之间共用,所以第一个参数没有意义,只要输入一个合法值就可以了。 * param[in] dmx_id DEMUX ID. CNcomment: DEMUX号。 * param[out] free_count Pointer to the number of available key areas (output). * CNcomment:指针类型,输出空闲密钥区数目。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 */ td_s32 uapi_dmx_desc_get_free_count(td_u32 dmx_id, td_u32 *free_count); /* * brief Set Even key.For algs do not use key,do not care. * CNcomment:设置偶密钥区的初始化密钥。对于不涉及初始化密钥的解扰算法可以不关注。 * attention * even_key points to the iv key data to be set.The data consists of 16 bytes: CW1, CW2, ..., and CW16. * The key value can be set dynamically, that is, the key value can be set at any time after a key area is created. * CNcomment:even_key指向要设置的初始化密钥数据。奇密钥数据共16byte,byte依次是CW1、CW2、……、CW16 * 支持密钥区的动态设置,可以在密钥区申请后的任意时刻设置。 * param[in] desc_handle Handle of the key area to be set.CNcomment:待设置的密钥区句柄。 * param[in] even_key Pointer to the 16-byte key data to be set. * CNcomment:指针类型,指向要设置的偶密钥数据,必须是16个字节的数组。 * param[in] even_key_len Length of the key data.CNcomment:偶密钥数据的长度。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 */ td_s32 uapi_dmx_desc_set_even_key(td_handle desc_handle, const td_u8 *even_key, td_u32 even_key_len); /* * brief Set Odd IV.For algs do not use IV,do not care. * CNcomment:设置奇密钥区的密钥。对于不涉及初始化密钥的解扰算法可以不关注。 * attention * odd_key points to the key data to be set.The data consists of 16 bytes: CW1, CW2, ..., and CW16. * The key value can be set dynamically, that is, the key value can be set at any time after a key area is created. * CNcomment:odd_iv指向要设置的初始化密钥数据。奇密钥数据共16byte,byte依次是CW1、CW2、……、CW16 * 支持密钥区的动态设置,可以在密钥区申请后的任意时刻设置。 * param[in] desc_handle Handle of the key area to be set.CNcomment:待设置的密钥区句柄。 * param[in] odd_key Pointer to the 16-byte key data to be set. * CNcomment:指针类型,指向要设置的奇密钥数据,必须是16个字节的数组。 * param[in] odd_key_len Length of the key data.CNcomment:奇密钥数据的长度。 * retval ::TD_SUCCESS Success.CNcomment:成功。 * retval ::TD_FAILURE Calling this API fails.CNcomment:API系统调用失败。 * retval ::SOC_ERR_DMX_NOT_INIT The DEMUX module is not initialized.CNcomment:模块没有初始化。 * retval ::SOC_ERR_DMX_INVALID_PARA The input parameter is invalid. CNcomment:输入参数非法。 * retval ::SOC_ERR_DMX_NULL_PTR The pointer is null. CNcomment:指针参数为空。 */ td_s32 uapi_dmx_desc_set_odd_key(td_handle desc_handle, const td_u8 *odd_key, td_u32 odd_key_len); #ifdef __cplusplus #if __cplusplus } #endif #endif #endif /* __UAPI_DESCRAMBLER_H__ */