/* 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_smc.h,v $
 * $Revision: #1 $
 * $Date: 2015/11/10 $
 * $Author: dtvbm11 $
 * $CCRevision: $
 * $SWAuthor: Alec Lu $
 * $MD5HEX: $
 *
 * Description:
 *         This header file contains Smart Card driver specific definitions,
 *         which are exported.
 *---------------------------------------------------------------------------*/

#ifndef _X_SMC_H_
#define _X_SMC_H_

/*-----------------------------------------------------------------------------
                    include files
 ----------------------------------------------------------------------------*/
#include "x_common.h"
#include "x_rm.h"

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/
/* Get operations */
#define SMC_GET_TYPE_CARD_PRESENCE          (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 0))
#define SMC_GET_TYPE_STATUS                 (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 1))
#define SMC_GET_TYPE_PROTOCOL               (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 2))
#define SMC_GET_TYPE_CHECKSUM_TYPE          (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 3))
#define SMC_GET_TYPE_RECEIVE_CMD            (RM_GET_TYPE_LAST_ENTRY + ((DRV_GET_TYPE_T) 4))

/* Set operations */
#define SMC_SET_TYPE_INIT                   (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 0))
#define SMC_SET_TYPE_TERMINATE              (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 1))
#define SMC_SET_TYPE_RESET                  (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 2))
#define SMC_SET_TYPE_WARM_RESET             (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 3))
#define SMC_SET_TYPE_NFY_FCT                (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 4))
#define SMC_SET_TYPE_PARAM                  (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 5))
#define SMC_SET_TYPE_SEND_CMD               (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 6))
#define SMC_SET_TYPE_SEND_RECEIVE_CMD       (RM_SET_TYPE_LAST_ENTRY + ((DRV_SET_TYPE_T) 7))

/* Card status */
typedef enum
{
    SMC_CARD_STS_PRESENT = 0,    
    SMC_CARD_STS_ABSENT,
    SMC_CARD_STS_ERROR,
    SMC_CARD_STS_INIT_FAIL
}   SMC_CARD_STS_T;

/* SMC command */
typedef struct _SMC_CMD_T
{
    UINT8       ui1_blk_type;   /* Block type (e.g. info, receive, supervisory) */
    UINT8       ui1_ins_code;   /* Instruction code */
    UINT8       ui1_ns;         /* Send sequence number */
}   SMC_CMD_T;

/* SMC response */
typedef struct _SMC_RESPONSE_T
{
    UINT8       ui1_protocol_num;   /* Version of IC card */
    UINT8       ui1_unit_len;       /* Length of payload */
    UINT16      ui1_card_ins;       /* Instruction from smart card */
    UINT16      ui1_rtn_code;       /* Process result of smart card */
}   SMC_RESPONSE_T;
    
/* SMC octet */
typedef struct _SMC_OCTET_T
{
    UINT8*      pui1_data;
    SIZE_T      z_data_size;
}   SMC_OCTET_T;

/* SMC send/receive command info */
typedef struct _SMC_COMMAND_INFO_T
{
    SMC_CMD_T       t_cmd;
    SMC_OCTET_T     t_data;
}   SMC_COMMAND_INFO_T;

/* SMC send & receive info */
typedef struct _SMC_TX_RX_INFO_T
{
    SMC_OCTET_T         t_send_data;
    SMC_RESPONSE_T      t_response;
    SMC_OCTET_T         t_response_data;
}   SMC_TX_RX_INFO_T;

/* Notify function */
typedef VOID (*x_smc_nfy_fct)(VOID*             pv_nfy_tag,
                              SMC_CARD_STS_T    e_nfy_cond,
                              UINT32            ui4_data);

/* Notify setting structure */
typedef struct _SMC_NFY_INFO_T
{
    VOID*           pv_tag;
    x_smc_nfy_fct   pf_nfy;
}   SMC_NFY_INFO_T;       

#endif /* _X_SMC_H_ */

