/*
 *
 * (c) Copyright 2018 Samsung Research America, Inc.
 *                  All rights reserved
 *
 *                  MCL-B2B Lab
 *
 *
 * File: dualdar_api.h
 * Author: r.kadir@samsung.com
 * Creation Date: Nov, 2018
 *
 */
/**
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*
* Mobile Platform & Solutions Lab (MPS Lab),
* Samsung Electronics Co., Ltd.
*
* This software and its documentation are confidential and proprietary
* information of Samsung Electronics Co., Ltd.  No part of the software and
* documents may be copied, reproduced, transmitted, translated, or reduced to
* any electronic medium or machine-readable form without the prior written
* consent of Samsung Electronics.
*
* Samsung Electronics makes no representations with respect to the contents,
* and assumes no responsibility for any errors that might appear in the
* software and documents. This publication and the contents hereof are subject
* to change without notice.
*/

#ifndef DUALDAR_API_H_
#define DUALDAR_API_H_

#include <stdint.h>

/* Command ID's for communication between Trustlet Connector and Trustlet */
#define CMD_DUALDAR_SETUP_PASSWORD				 0x00000001
#define CMD_DUALDAR_CHANGE_PASSWORD				 0x00000002
#define CMD_DUALDAR_AUTHENTICATE				 0x00000003

#define CMD_DUALDAR_CMD_UNKNOWN                 0x7FFFFFFF
//////////////////////////////
//////////////////////////////

#define DUALDAR_TA_NAME  "dualdar"

/* Constants for vts server */
#define QSEE_DUALDAR_ROOT "/lib/firmware"
#define QSEE_DUALDAR_PROCESS "dualdar"

#define TBASE_DUALDAR_ROOT "0"
#define TBASE_DUALDAR_PROCESS "0000000000000000000064756c444152"
#define DUALDAR_APP_NAME "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64\x75\x6c\x44\x41\x52"
#define DUALDAR_APP_NAME_LEN   16

#define KB								        1024
#define MAX_DATA_LEN							(8*KB)

#define MAX_PASSWORD_LEN                        (1*KB)

#define MAX_MASTERKEY_LEN                       32
#define MAX_EMASTERKEY_LEN                      (1*KB)

#define MAX_KEK_LEN                             32

#define MAX_SALT_LEN                            32
#define MAX_WSALT_LEN                           (1*KB)

/////////////////////////////////////
/////////////////////////////////////
#define DUALDAR_MAX_BUF_SIZE					4*KB
#define DUALDAR_MAX_CRYPTO_TEMPBUF_SIZE 		16*KB

//////////////////////////////////////////////////////////
#define BLOB_LENGTH_FIELD_SIZE		sizeof(uint32_t)
#define LIST_COUNT_FIELD_SIZE		sizeof(uint32_t)
#define BUF_T(MAX_BUF_LEN) \
	struct { \
	   uint32_t len; \
	   uint8_t buf[MAX_BUF_LEN]; \
	} __attribute__ ((packed))
#define DECLARE_BUF_T(MAX_BUF_LEN) \
	typedef struct { \
	   uint32_t len; \
	   uint8_t buf[MAX_BUF_LEN]; \
	} __attribute__ ((packed))
#define BSIZE(BUF_SIZE) (BLOB_LENGTH_FIELD_SIZE+BUF_SIZE)
#define LIST_T(entrytype,  MAX_LIST_SIZE) \
	struct { \
	   uint32_t count; \
	   entrytype entry[MAX_LIST_SIZE]; \
	} __attribute__ ((packed))
#define DECLARE_LIST_T(entrytype,  MAX_LIST_SIZE) \
	typedef struct { \
	   uint32_t count; \
	   entrytype entry[MAX_LIST_SIZE]; \
	} __attribute__ ((packed))
#define LIST_SIZE(entrytype,  MAX_LIST_SIZE) \
		(LIST_COUNT_FIELD_SIZE + MAX_LIST_SIZE * sizeof(entrytype))
#define CHECK_OUT_OF_BOUND_ACCESS(len, curr)								\
		if ((curr) > (len)) {												\
			ret = DUALDAR_INVALID_INPUT_BUFFER;							\
			break;															\
		}


#include "dualdar_errors.h"
#include "dualdar_msg.h"

#endif /* DUALDAR_API_H_ */
