/* 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: x_tm.h,v $
 * $Revision: #1 $
 * $Date: 2015/05/29 $
 * $Author: brianpc.huang $
 *
 * Description:
 *         This header file contains Table Manager specific definitions,
 *         which are exported.
 *---------------------------------------------------------------------------*/

#ifndef _X_TM_H_
#define _X_TM_H_


/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/

#include "x_handle.h"
#include "x_common.h"
#include "x_sys_name.h"
#include "u_tm.h"

/*-----------------------------------------------------------------------------
                    functions declarations
 ----------------------------------------------------------------------------*/

 /* The following structure is a representation of a section header. */
typedef struct _SECT_HDR_T
{
    UINT8 ui1_tbl_id;          /* Table id. */

    BOOL  b_sect_syntax_ind;   /* Section syntax indicator. */
    BOOL  b_pvt_ind;           /* Private indicator. */

    UINT16  ui2_sect_len;      /* Section length. */
    UINT16  ui2_tbl_ext_id;    /* Table extension id. Only valid if "b_sect_syntax_ind == TRUE". */

    UINT8  ui1_version;        /* Version number. Only valid if "b_sect_syntax_ind == TRUE". */

    BOOL  b_curr_next_ind;     /* Current / next indicator. Only valid if "b_sect_syntax_ind == TRUE". */

    UINT8  ui1_sect_num;       /* Section number. Only valid if "b_sect_syntax_ind == TRUE". */
    UINT8  ui1_last_sect_num;  /* Last section number. Only valid if "b_sect_syntax_ind == TRUE". */

    SIZE_T  z_data_len;        /* Actual data length. */
}   SECT_HDR_T;

extern INT32 x_tm_change_src (HANDLE_T       h_obj,
                              TM_SRC_TYPE_T  e_src_type,
                              VOID*          pv_src_info,
                              TM_COND_T*     pe_cond);
extern INT32 x_tm_delete_obj (HANDLE_T  h_obj);
extern BOOL x_tm_find_root (const CHAR*  ps_name);
extern INT32 x_tm_free (HANDLE_T  h_obj);
extern INT32 x_tm_get_cond (HANDLE_T    h_obj,
                            TM_COND_T*  pe_cond);
extern INT32 x_tm_get_obj (HANDLE_T       h_obj,
                           TM_GET_TYPE_T  e_get_type,
                           VOID*          pv_get_info,
                           VOID*          pv_data,
                           SIZE_T*        pz_data_len,
                           TM_COND_T*     pe_cond);
extern INT32 x_tm_get_protection (HANDLE_T    h_obj,
                                  BOOL*       pb_protected,
                                  TM_COND_T*  pe_cond);
extern INT32 x_tm_get_tbl_version (HANDLE_T    h_obj,
                                   UINT8*      pui1_version,
                                   TM_COND_T*  pe_cond);
extern INT32 x_tm_load_obj (HANDLE_T        h_parent,
                            HANDLE_TYPE_T   e_obj_type,
                            TM_LOAD_TYPE_T  e_load_type,
                            VOID*           pv_load_info,
                            TM_SRC_TYPE_T   e_src_type,
                            VOID*           pv_src_info,
                            VOID*           pv_nfy_tag,
                            x_tm_nfy_fct    pf_nfy,
                            HANDLE_T*       ph_obj,
                            TM_COND_T*      pe_cond);
extern INT32 x_tm_monitor_obj (HANDLE_T       h_parent,
                               HANDLE_TYPE_T  e_obj_type,
                               TM_MON_TYPE_T  e_mon_type,
                               VOID*          pv_mon_info,
                               TM_SRC_TYPE_T  e_src_type,
                               VOID*          pv_src_info,
                               VOID*          pv_nfy_tag,
                               x_tm_nfy_fct   pf_nfy,
                               HANDLE_T*      ph_obj,
                               TM_COND_T*     pe_cond);
extern INT32 x_tm_open_root (const CHAR*    ps_name,
                             TM_SRC_TYPE_T  e_src_type,
                             VOID*          pv_src_info,
                             VOID*          pv_nfy_tag,
                             x_tm_nfy_fct   pf_nfy,
                             HANDLE_T*      ph_root,
                             TM_COND_T*     pe_cond);
extern INT32 x_tm_parse_obj (HANDLE_T         h_obj,
                             TM_PARSE_TYPE_T  e_parse_type,
                             VOID*            pv_parse_info,
                             VOID*            pv_data,
                             SIZE_T           z_data_len,
                             x_tm_parse_fct   pf_parse,
                             TM_COND_T*       pe_cond);
extern INT32 x_tm_set_obj (HANDLE_T       h_obj,
                           TM_SET_TYPE_T  e_set_type,
                           VOID*          pv_set_info,
                           SIZE_T         z_len,
                           TM_COND_T*     pe_cond);
extern INT32 x_tm_set_protection (HANDLE_T    h_obj,
                                  BOOL        b_protected,
                                  TM_COND_T*  pe_cond);
extern INT32 x_tm_store_obj (HANDLE_T         h_obj,
                             TM_STORE_TYPE_T  e_store_type,
                             VOID*            pv_store_info,
                             TM_COND_T*       pe_cond);


extern INT32 x_tm_refresh_obj (HANDLE_T    h_obj,
                        TM_COND_T*  pe_cond);


extern INT32 x_tm_get_conn_status(HANDLE_T     h_root,
                                  BOOL*        pb_connect);

extern VOID x_tm_xlat_sect_hdr (UINT8*       pui1_sect_data,
                              SECT_HDR_T*  pt_sect_hdr);

extern INT32 x_tm_set_src_conn_nfy_cond (HANDLE_T    h_root,
                                BOOL        b_src_conn_nfy_cond,
                                TM_COND_T*  pe_cond);

#endif /* _X_TM_H */
