/**
 * @file       task_parser.h
 * @brief      Extract data from memory to TaskInfo structure
 * @author     Ivan Vorobiov (i.vorobiov@samsung.com)
 * @version    1.0
 * @date       Created Jul 18, 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_TASK_PARSER_H_
#define PA_TZ_DRV_SRC_TASK_PARSER_H_

#include "task.h"
#include "task_descriptor.h"

/**
 * @brief Get information about task structure which is located in kernel address space
 * @param [in] virt Start kernel address of task structure
 * @param [out] out_task Pointer to structure of task
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskParseBasicInfo(KernelAddress virt, TaskInfo *out_task);

/**
 * @brief Get extra information about task structure
 * @param [in,out] out_task Pointer to structure of task
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskParseIntegrity(TaskInfo *out_task);

/**
 * @brief Get information about VMA from task structure
 * @param [in] virt Start kernel address of VMA structure
 * @param [out] out_vma Pointer to vma structure
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskParseVmaInfo(KernelAddress virt, VmaInfo *out_vma);

/**
 * @brief Read PA certificate from virtual address in NWd
 * @param [in] task Pointer to task structure (it's used to convert process address to physical)
 * @param [out] certificate Pointer to output certificate
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskParsePaCertificate(const TaskInfo *task,
                                  PaCertificate_t **certificate);

/**
 * @brief Get FIVE signature by kernel space address
 * @param [in] file_struct Pointer on file_struct
 * @param [out] signature FIVE signature
 * @param [in,out] signature_len Max signature length / real signature length
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskParseFiveSignature(KernelAddress file_struct, void *signature, size_t *signature_len);

/**
 * @brief Get information about task descriptor structure which is located in kernel space
 * @param [in] address Address in kernel address space
 * @param [out] out_descr Task descriptor structure
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskParsePaTaskDescriptorStruct(KernelAddress address,
                                           TaskDescriptor *out_descr);

#endif // PA_TZ_DRV_SRC_TASK_PARSER_H_
