/*
 * Copyright (C) 2019 SAMSUNG S.LSI
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __ESE_HAL__H
#define __ESE_HAL__H

/**
 * @file ese_hal.h
 * @brief eSE HAL APIs.
 */

/**
 * @ingroup common
 * @defgroup ese_hal eSE_HAL
 * @brief eSE HAL APIs.
 *
 * This API provides functions of eSE hardware abstraction layer.
 * @{
 */

#ifdef ESE_U_BOOT_BUILD
#include <linux/types.h>
#else
//#include <unistd.h>
#include <stdint.h>
#endif

/**
 * @brief Type definition of ESE_HAL_STATUS
 */
typedef int32_t ESE_HAL_STATUS;

#define ESE_HAL_STATUS_SUCCESS				(0) /**< @brief Return value of success status */
#define ESE_HAL_STATUS_ERROR				(-1) /**< @brief Return value of error status */
#define ESE_HAL_STATUS_NO_DEV				(-5) /**< @brief Return value of no device status */
#define ESE_HAL_STATUS_BUSY				    (-10)  /**< @brief Return value of busy status */
#define ESE_HAL_STATUS_ALREADY_OPENED	    (-11)  /**< @brief Return value of busy status */

/**
 * @brief Open eSE HAL
 *
 * - Initialize eSE hardware abstraction layer for using the HAL API.
 * - Connect to the secure element.
 *
 * @return Returns ::ESE_HAL_STATUS_SUCCESS if succeeded and other value
 * 				 if failed.
 * @see eseHal_Close
 */
ESE_HAL_STATUS eseHal_Open(void);
/**
 * @brief Transmit data to eSE
 *
 * - Transmit data to eSE.
 *
 * @param[in] txData     : Data to transmit to eSE
 * @param[in] txDataSize : Size of \p txData
 * @return Returns transmitted data size if succeeded and negative value
 * 			 if failed.
 * @see eseHal_Receive
 */
int32_t eseHal_Send(uint8_t *txData, uint32_t txDataSize);
/**
 * @brief Receive data from eSE
 *
 * - Receive data from eSE.
 *
 * @param[in] rxData     : Data received from eSE
 * @param[in] rxDataSize : Size of \p rxData
 * @return Returns received data size if succeeded and negative value
 * 			 if failed.
 * @see eseHal_Send
 */
int32_t eseHal_Receive(uint8_t *rxData, uint32_t rxDataSize);
/**
 * @brief Close eSE HAL
 *
 * - Finalize eSE hardware abstraction layer.
 *
 * @return Returns ::ESE_HAL_STATUS_SUCCESS if succeeded and other value
 * 				 if failed.
 * @see eseHal_Open
 */
ESE_HAL_STATUS eseHal_Close(void);
/**
 * @}
 */
#endif
