/**
 * @file       api.h
 * @brief      Public API of PA driver
 * @details    Provide API to authenticate and manipulate process memory
 * @author     Ivan Vorobiov (i.vorobiov@samsung.com)
 * @version    1.0
 * @date       Created Aug 26, 2016
 * @copyright  In Samsung Ukraine R&D Center (SURC) under a contract between
 * @copyright  LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine) and
 * @copyright  "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
 * @copyright  Copyright: (c) Samsung Electronics Co, Ltd 2016. All rights reserved.
**/
#ifndef PA_TZ_DRV_SRC_API_H_
#define PA_TZ_DRV_SRC_API_H_

#include "memory.h"
#include "pa_tz_api.h"

/**
 * @brief Authenticate NWd process by PID and name
 * @param [in] handler Process authenticator handler of process
 * @param [in] process_names Name list of the all processes,
 * which should be authenticated (NULL-terminated string), can be NULL
 * @param [in] process_names_size Size of all process names
 * @param [in] memory Check that memory is owned by process, can be NULL
 * @param [out] info If process is authenticated info will fill by process
 *  information, can be NULL
 * @return ::PA_TZ_SUCCESS if process is authenticated successfully,
 *         ::PA_TZ_AUTHENTICATION_FAILED if process is not authenticated,
 *         ::PA_TZ_GENERAL_ERROR if input parameter is invalid
 */
PaTzResult Authenticate(PaHandler handler,
                        const char *process_names, const size_t process_names_size,
                        const PaTzMemoryRange *memory, ProcessInfo *info);

/**
 * @brief Read task memory by PID to trustlet
 * @param [in] handler Handler of REE task
 * @param [in] user_address User space virtual address inside the task
 * @param [in] size Count of bytes needed to read
 * @param [out] out_trustlet Pointer to trustlet output buffer with size at least "size" bytes
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskReadToTrustlet(PaHandler handler, ProcessAddress user_address,
                              size_t size, void *out_trustlet);

/**
 * @brief Write memory to task by PID from trustlet
 * @param [in] handler Handler of REE task
 * @param [in] in_trustlet Pointer to trustlet source buffer
 * @param [in] size Count of bytes needed to write
 * @param [in] user_address User space virtual address inside the task
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskWriteFromTrustlet(PaHandler handler, const void *in_trustlet,
                                 size_t size, ProcessAddress user_address);

/**
 * @brief Issue new certificate for APK
 * @param [in] handler Handler of allowed issuer application
 *                     (should be handler of apk_signer or another)
 * @param [in] mapped_apk Virtual address of APK file mapped in NWd (could be only part of file)
 * @param [in] package_name Package name of APK
 * @param [in] rsa,rsa_size Public key of APK
 * @param [out] out_xattr,out_xattr_size signed certificate
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult IssueNewCertificate(PaHandler handler,
                               ProcessAddress mapped_apk,
                               const char *package_name,
                               const uint8_t *rsa, size_t rsa_size,
                               uint8_t *out_xattr, uint32_t *out_xattr_size);

#endif // PA_TZ_DRV_SRC_API_H_
