/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file c_ci.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/11/10 $
 *  $Author: dtvbm11 $
 *  
 *  @par Description:
 *         This header file contains Common Interface (CI) specific
 *         definitions, which are exported.
 */
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
/*! @addtogroup groupMW_CI
 *  @{ 
 */
/*----------------------------------------------------------------------------*/

#ifndef _C_CI_H_
#define _C_CI_H_

/*-------------------------------------------------------------------------
                    include files
-------------------------------------------------------------------------*/
#include "u_ci.h"

/*-------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ------------------------------------------------------------------------*/

/*--------------------------------------------------------------------
                 Functions
 -------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/*! @brief register notification callback function
 *  @param [in] pv_nfy_tag -private tag for caller who will be set in x_ci_nfy_fct() callback when notify caller
 *  @param [in] pv_nfy -callback function pointer,CI engine will notify event through this function.
 *  @param [out] ph_ci -handle for this register action who will be used in x_ci_nfy_fct() and c_ci_unreg_nfy()
 *  @note
 *  @see c_ci_unreg_nfy
 *  @return
 *  @retval      CIR_OK -the routine is successful
 *  @retval      CIR_NOT_REGISTERED -ci engine has not registered 
 *  @retval      CIR_NOT_INIT -ci engine has not initialized 
 *  @retval      CIR_NOT_ENOUGH_SPACE -allocated memory failed
 */
/*------------------------------------------------------------------*/
extern INT32 c_ci_reg_nfy(
    HANDLE_T*           ph_ci,
    VOID*               pv_nfy_tag,
    UINT32             ui4_nfy_category_tag,
    x_ci_nfy_fct        pv_nfy);

/*------------------------------------------------------------------*/
/*! @brief unregister notification callback function
 *  @param [in] h_ci -handle for unregister which is set in c_ci_reg_nfy()
 *  @param [out] NONE
 *  @note
 *  @see c_ci_reg_nfy
 *  @return
 *  @retval      CIR_OK -the routine is successful
 *  @retval      CIR_NOT_REGISTERED -no related callback function registered 
 *  @retval      CIR_NOT_INIT -ci engine has not initialized 
 */
/*------------------------------------------------------------------*/
extern INT32 c_ci_unreg_nfy(
    HANDLE_T            h_ci);

extern INT32 c_ci_reg_query_nfy(
    HANDLE_T*           ph_ci,
    VOID*               pv_tag,
    UINT32             ui4_nfy_category_tag,
    x_ci_query_info_fct pf_query_info_fct);

/*------------------------------------------------------------------*/
/*! @brief query CI  info
 *  @param [in] e_get_type -query type
 *  @param [in,out] pv_data -queried data, concrete type depends on e_get_type
 *  @param [in,out] pz_data_len -data's length
 *  @note
 *  @see
 *  @return
 *  @retval      CIR_OK -the routine is successful
 *  @retval      CIR_INV_GET_INFO -pv_get_info value is invalid
 *  @retval      CIR_INV_GET_DATA -pv_data value is invalid
 *  @retval      CIR_NOT_REGISTERED -no related callback function registered 
 *  @retval      CIR_NOT_INIT -ci engine has not initialized 
 *  @retval      CIR_NOT_ENOUGH_SPACE -allocated memory failed
 */
/*------------------------------------------------------------------*/
extern INT32 c_ci_get(
    CI_GET_TYPE_T       e_get_type,
    VOID*               pv_get_info,
    VOID*               pv_data,
    SIZE_T*             pz_data_len);

/*------------------------------------------------------------------*/
/*! @brief set CI  info
 *  @param [in] e_set_type -set type
 *  @param [in] pv_set_info -set info data
 *  @param [in] pv_data -set data
 *  @note
 *  @see
 *  @return
 *  @retval      CIR_OK -the routine is successful
 *  @retval      CIR_INV_SET_TYPE -e_set_type value is invalid
 *  @retval      CIR_INV_SET_INFO -pv_set_info value is invalid
 *  @retval      CIR_INV_SET_DATA -pv_data value is invalid
 *  @retval      CIR_NOT_REGISTERED -no related callback function registered 
 *  @retval      CIR_NOT_INIT -ci engine has not initialized 
 *  @retval      CIR_ALREADY_SET_ENTER_MENU -menu has been already entered
 *  @retval      CIR_FAILED -the routine is failed
 */
/*------------------------------------------------------------------*/
extern INT32 c_ci_set(
    CI_SET_TYPE_T       e_set_type,
    VOID*               pv_set_info,
    VOID*               pv_data);

/*------------------------------------------------------------------*/
/*! @brief query previous MMI menu object info
 *  @param [in] pv_get_info -get info
 *  @param [in][out] pz_data_len -data's length
 *  @param [out] pv_data -get data
 *  @note
 *  @see
 *  @return
 *  @retval      CIR_OK -the routine is successful
 *  @retval      CIR_INV_GET_DATA -pz_data_len is invalid
 *  @retval      CIR_FAILED -the routine is failed
 */
/*------------------------------------------------------------------*/
extern INT32 ci_wipro_get_previous_mmi(
    VOID*               pv_get_info,
    VOID**              pv_data,
    SIZE_T*             pz_data_len);

/*------------------------------------------------------------------*/
/*! @brief lock MMI object
 *  @param [in]
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval      CIR_OK-                  The routine was successful.
 */
/*------------------------------------------------------------------*/
extern INT32 c_ci_lock_mmi(VOID);

/*------------------------------------------------------------------*/
/*! @brief unlock MMI object
 *  @param [in]
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval    CIR_OK-                  The routine was successful.
 */
/*------------------------------------------------------------------*/
extern INT32 c_ci_unlock_mmi(VOID);

/*------------------------------------------------------------------*/
/*! @brief This API write ci plus data into flash.
 *  @param [in]
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval    CIR_OK-                  The routine was successful.
 *  @retval    CIR_FAILED-              Tthe routine is failed.
 */
 /*------------------------------------------------------------------*/
INT32 c_ci_update_ciplus_cred(CHAR *pc_src_file_path);

/*------------------------------------------------------------------*/
/*! @brief This API erase ci plus data in the flash.
*  @param [in]
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval    CIR_OK-                  The routine was successful.
 *  @retval    CIR_FAILED-              Tthe routine is failed.
 */
 /*------------------------------------------------------------------*/
INT32 c_ci_erase_ciplus_cred(VOID);

/*------------------------------------------------------------------*/
/*! @brief This This API writes ci plus data into flash from buffer directly.
 *  @param [in] aui1_src_buffer  pointer of the input data buffer
 *  @param [in] ui4_len         input data length
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval    CIR_OK-                  The routine was successful.
 *  @retval    CIR_FAILED-              Tthe routine is failed.
 */
 /*------------------------------------------------------------------*/
INT32 c_ci_write_ciplus_cred(CHAR *aui1_src_buffer, UINT32 ui4_len);

/*------------------------------------------------------------------*/
/*! @brief This API reads ci plus data from flash to buffer directly.
 *  @param [in] aui1_dst_buffer  pointer of the output data buffer, the buffer should be allocate from caller
 *  @param [in] ui4_len         output data length
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval    CIR_OK-                  The routine was successful.
 *  @retval    CIR_FAILED-              Tthe routine is failed.
 *  @retval    CIR_NOT_ENOUGH_SPACE-    The input data buffer length is not enough. It also ouputs the required biffer length.
 */
 /*------------------------------------------------------------------*/
INT32 c_ci_read_ciplus_cred(CHAR *aui1_dst_buffer, UINT32 *ui4_len);

/*------------------------------------------------------------------*/
/*! @brief This API activate the pre-burn data inside flash.
 *  @param [in]
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval    CIR_OK-                  The routine was successful.
 *  @retval    CIR_FAILED-              Tthe routine is failed.
 */
 /*------------------------------------------------------------------*/
INT32 c_ci_activate_ciplus_cred(VOID);

/*------------------------------------------------------------------*/
/*! @brief This API return the file search mode and its coresponding data.
 *  @param [in]
 *  @param [out] t_search_mode_data - pointer of the ouput data
 *  @note
 *  @see
 *  @return
 *  @retval
 */
 /*------------------------------------------------------------------*/
VOID c_ci_get_ciplus_cred_searchmode(CI_SEARCH_MODE_DATA_T *t_search_mode_data);

/*------------------------------------------------------------------*/
/*! @brief This API return the information of ci_plus data.
 *  @param [in]
 *  @param [out] t_info_data -  pointer of the output data
 *  @note
 *  @see
 *  @return
 *  @retval
 */
 /*------------------------------------------------------------------*/
INT32 c_ci_get_ciplus_cred_info(CI_PLUS_CRED_INFO_T *t_info_data);

/*------------------------------------------------------------------*/
/*! @brief This API return the information of ci_plus data.
 *  @param [in]
 *  @param [out] t_info_data -  pointer of the output data
 *  @note
 *  @see
 *  @return
 *  @retval
 */
 /*------------------------------------------------------------------*/
INT32 c_ci_get_ciplus_cred_pre_info(CI_PLUS_CRED_INFO_T *t_info_data);
/*-----------------------------------------------------------------------------
 * Name: c_ci_verify_ciplus_cred
 *
 * Description: This API will use input key data to verify the Key which has been burned to NVM, 
 *
 * Inputs: aui1_src_buffer  pointer of the input data buffer
 *            ui4_len         input data length
 * Outputs: pb_vaild     TRUE,burned key valid 
 *                                 FALSE,burned key invalid
 * Returns: CIR_OK  Success. 
 *          CIR_FAILED  Fail.
 *          CIR_INV_ARG  One of the input argument is wrong
 ----------------------------------------------------------------------------*/
INT32 c_ci_verify_ciplus_cred(CHAR *aui1_src_buffer, UINT32 ui4_len,BOOL* pb_vaild);
/*-----------------------------------------------------------------------------
 * Name: x_ci_verify_ciplus_cred
 *
 * Description: This API will check the valid CI plus credential exist or not, 
 *
 * Inputs/Outputs: pb_exist  TRUE valid key exist, FALSE no valid key here
 * Returns: CIR_OK  Success. 
 *          CIR_FAILED  Fail.
 *          CIR_INV_ARG  One of the input argument is wrong
 ----------------------------------------------------------------------------*/
INT32 c_ci_get_ciplus_cred_status(BOOL* pb_exist);


INT32 c_ci_set_channel_list_profile_info(UINT8 tuner_type,CHAR* pstuner_name,UINT8 ui1_slot_id, UINT16 ui2_svl_id);
INT32 c_ci_set_cur_channel_list_profile(BOOL b_cam_channel_list_profile,UINT8 ui1_slot_id);
INT32 c_ci_update_tuner_info(CHAR* ps_tuner_name,UINT16 ui2_tsl_id,UINT16 ui2_svl_id);
/*------------------------------------------------------------------*/
/*! @brief This API return the max slot number
 *  @param [in]
 *  @param [out] 
 *  @note
 *  @see
 *  @return
 *  @retval max slot number
 */
 /*------------------------------------------------------------------*/
UINT8 c_ci_fac_get_max_slot_num(VOID);

/*------------------------------------------------------------------*/
/*! @brief This API return the cam insert status
 *  @param [in] slot number, start from 0
 *  @param [out] pointer to keep the CAM appear status
 *  @note
 *  @see
 *  @return 
 *  @retval    CIR_OK-                  The routine was successful.
 *  @retval    CIR_FAILED-              Tthe routine is failed.
 */
 /*------------------------------------------------------------------*/

INT32 c_ci_fac_get_cam_appear_status(UINT8 ui1_slot, CI_APPEAR_COND_T *pt_status);

#endif /* _C_CI_H_ */

/*----------------------------------------------------------------------------*/
/*! @} */   /* end of  groupMW_CI*/
/*----------------------------------------------------------------------------*/
