/* 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.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 * $RCSfile: ca_svl_builder.h,v $
 * $Revision: #5 $
 * $Date: 2016/08/15 $
 * $Author: zhicheng.wang $
 * $CCRevision: $
 * $SWAuthor: $
 * $MD5HEX: $
 *
 * Description: 
 *         This header file contains private macros, defines, 
 *         typedefs, and enums, which are required by CA SVL Builder engine.
 *---------------------------------------------------------------------------*/

#ifndef _X_CA_SVL_BUILDER_H_
#define _X_CA_SVL_BUILDER_H_


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

#include "x_sb.h"
#include "x_sb_eng.h"
#include "u_sb_dvb_cp_eng.h"


/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
-----------------------------------------------------------------------------*/
#define CSBR_OK                         ((INT32)     0)
#define CSBR_ALREADY_INIT               ((INT32)    -1)
#define CSBR_BLDR_NOT_FOUND             ((INT32)    -2)
#define CSBR_DUP_NAME                   ((INT32)    -3)
#define CSBR_FILE_NOT_FOUND             ((INT32)    -4)
#define CSBR_INTERNAL_ERROR             ((INT32)    -5)
#define CSBR_INV_ARG                    ((INT32)    -6)
#define CSBR_INV_COND                   ((INT32)    -7)
#define CSBR_INV_HANDLE                 ((INT32)    -8)
#define CSBR_LIST_NOT_FOUND             ((INT32)    -9)
#define CSBR_NOT_INIT                   ((INT32)   -10)
#define CSBR_NOT_MATCH                  ((INT32)   -11)
#define CSBR_NOT_STARTER                ((INT32)   -12)
#define CSBR_OUT_OF_HANDLES             ((INT32)   -13)
#define CSBR_OUT_OF_MEM                 ((INT32)   -14)
#define CSBR_ERR_LOCK                   ((INT32)   -15)
#define CSBR_ERR_UNLOCK                 ((INT32)   -16)


typedef enum
{
    CA_SB_KEY_TYPE_UNKNOWN = 0,
    CA_SB_KEY_TYPE_SET_1,
    CA_SB_KEY_TYPE_GET_1,
}   CA_SB_KEY_TYPE_T;


typedef enum
{
    CA_SB_NFY_REASON_UNKNOWN = 0,
    CA_SB_NFY_REASON_FINE_TUNE_COMPLETE,
    CA_SB_NFY_REASON_SCAN_COMPLETE,
    CA_SB_NFY_REASON_SCAN_CANCEL,
    CA_SB_NFY_REASON_OP_NIT_MNGT,
    CA_SB_NFY_REASON_OSDT_REQ,
    CA_SB_NFY_REASON_LAST_CASE
}   CA_SB_NFY_REASON_T;


typedef struct _CA_SB_OPERATOR_TUNE_STATUS_T
{
    UINT8                       ui1_signal_strength;
    UINT8                       ui1_signal_quality;
    UINT8                       ui1_status;
    UINT16                      ui2_descripor_number;
    UINT8*                      pui1_descriptor;
    UINT16                      ui2_descriptor_len;
} CA_SB_OPERATOR_TUNE_STATUS_T;


typedef struct _CA_SB_NFY_DATA_T
{
    CA_SB_NFY_REASON_T        e_nfy_reason;

    union
    {
        CA_SB_OPERATOR_TUNE_STATUS_T    t_tune_status;
        SB_DVB_CP_OP_NIT_MNGT_T         t_op_nit_mngt;
    } u_data;    
} CA_SB_NFY_DATA_T;


typedef struct _CA_SB_OPEN_DATA_T
{
    UINT16                      ui2_svl_id;
    CHAR*                       ps_tuner_name;    
    SB_DVB_DELIVERY_TYPE        t_delivery_type;
    SB_DVB_CP_CAM_PROFILE_2_T   t_profile_2;
    UINT32                      ui4_nit_timeout;    /* the unit is second: 10s */
    UINT32                      ui4_osdt_timeout;   /* the unit is second: 10s */
} CA_SB_OPEN_DATA_T;


#if 0
typedef struct _CA_SB_CALLBACK_TAG_T
{
    VOID*                       pv_ca_sb_nfy_tag1;
    VOID*                       pv_ca_sb_nfy_tag2;
    VOID*                       pv_ca_sb_nfy_tag3;
    VOID*                       pv_ca_sb_nfy_tag4;
    VOID*                       pv_ca_sb_nfy_tag5;
} CA_SB_CALLBACK_TAG_T;
#endif


typedef VOID (*ca_sb_scan_nfy_fct) (
      HANDLE_T                  h_builder,
      CA_SB_NFY_DATA_T*         pt_nfy_data,
      VOID*                     pv_tag );


typedef struct _CA_SB_SCAN_DATA_T
{
    ISO_3166_COUNT_T            t_country_code;
    SB_DVB_CONFIG_T             t_cp_eng_cfg;
    ca_sb_scan_nfy_fct          pf_ca_sb_scan_nfy;
    VOID*                       pv_tag;
    SB_DVB_CP_STRING_PREFIX_T   t_cp_string_prefix;
    UINT16                      ui2_refer_brdcst_satl_id;
    SB_DVB_CP_CAM_PROFILE_TYPE  t_profile_type;
} CA_SB_SCAN_DATA_T;


typedef struct _CA_SB_TUNE_INFO_T
{
    UINT8*                      pui1_tune_data;
    UINT32                      ui4_data_len;
} CA_SB_TUNE_INFO_T;


typedef struct _CA_SB_CI_NIT_T
{
    UINT8*                      pui1_ci_nit_data;
    UINT32                      ui4_data_len;
} CA_SB_CI_NIT_T;

typedef struct _CA_SB_CI_OSDT_T
{
    UINT8*                      pui1_ci_osdt_data;
    UINT32                      ui4_data_len;
} CA_SB_CI_OSDT_T;


/*-----------------------------------------------------------------------------
                    data declarations, extern, static, const
----------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------------
                    functions declarations
-----------------------------------------------------------------------------*/
INT32 ca_sb_open_builder(
        const CHAR*             ps_builder_name,
        CA_SB_OPEN_DATA_T*      pt_open_data,
        HANDLE_T*               ph_builder);


INT32 ca_sb_close_builder(
        HANDLE_T                h_builder);


INT32 ca_sb_start_scan(
        HANDLE_T                h_builder,
        CA_SB_SCAN_DATA_T*      pt_scan_data);


INT32 ca_sb_cancel_scan(
        HANDLE_T                h_builder);


INT32 ca_sb_start_monitor(
        HANDLE_T                h_builder);


INT32 ca_sb_stop_monitor(
        HANDLE_T                h_builder);


INT32 ca_sb_send_fine_tune_info(
        HANDLE_T                h_builder,
        CA_SB_TUNE_INFO_T*      pt_tune_info);


INT32 ca_sb_send_fine_tune_info_complete(
        HANDLE_T                h_builder );


INT32 ca_sb_send_ci_nit(
        HANDLE_T                h_builder,
        CA_SB_CI_NIT_T*         pt_ci_nit_info);


INT32 ca_sb_send_ci_osdt(
        HANDLE_T                h_builder,
        CA_SB_CI_OSDT_T*        pt_ci_osdt_info);


INT32 ca_sb_send_cam_replaced(
        HANDLE_T                h_builder );


INT32 ca_sb_set(
        HANDLE_T                h_builder,
        CA_SB_KEY_TYPE_T        e_set_type,
        VOID*                   pv_set_type_info,
        SIZE_T                  z_set_content_len,
        VOID*                   pv_set_content);


INT32 ca_sb_get(
        HANDLE_T                h_builder,
        CA_SB_KEY_TYPE_T        e_get_type,
        VOID*                   pv_get_type_info,
        SIZE_T                  z_get_content_len,
        VOID*                   pv_get_content);


#endif /* _X_CA_SVL_BUILDER_H_ */



