/*
 * =====================================================================================
 *
 *       Filename:  taConfig.c
 *
 *    Description:  TA configuration.
 *
 *        Version:  1.0
 *        Created:  03/27/2017 11:10:00 AM
 *       Compiler:  armcc
 *
 *         Author:  Dongwook Shim (), dw.shim@samsung.com
 *        Company:  Samsung Electronics
 *
 *        Copyright (c) 2017 by Samsung Electronics, All rights reserved. 
 *
 * =====================================================================================
 */

#include "commonConfig.h"
#include "systemConfig.h"
#include "taConfig.h"

#define MAX_TA_UID_SIZE              16

#if (defined USE_QSEE)
#define UID_PROV                  "prov"
#define UID_SKM                   "skm"
#elif (defined USE_MOBICORE)
#define UID_PROV                   {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c}
#define UID_SKM                    {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d}
#elif (defined USE_BLOWFISH)
#define UID_PROV                   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x52, 0x56, 0x54, 0x45, 0x45}
#define UID_SKM                    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x4b, 0x4d}
#endif

#define SKM_SAVE_FILE_PATH         COMMON_DIR"/prov_data/dev_root/dev_root.dat"
#define SKM_PRE_GEN_KEY_PATH       COMMON_DIR"/prov_data/dev_root/dev_root_key.dat"
#define KEYMASTER_SAVE_FILE_PATH   COMMON_DIR"/keymaster/keymaster.dat"

// Trustzone App data structure.
typedef struct {
	const uint8_t teeUid[MAX_TA_UID_SIZE];
	const size_t teeUidLen;
	const size_t maxBufferSize;
	const char preGenKeyPath[MAX_FILE_PATH_LEN];
	const char saveKeyPath[MAX_FILE_PATH_LEN];
} TeeAppData_t;

const TeeAppData_t gTeeAppData[] =
{ 
	{	// TA_PROV
		UID_PROV,
#if (defined USE_QSEE)
		sizeof(UID_PROV) - 1,
#else
		MAX_UID_SIZE,
#endif	// End of USE_QSEE
		MAX_PROV_BUF_SIZE,  
		"",
		""
	},
	{ 	// TA_SKM 
		UID_SKM,
#if (defined USE_QSEE)
		sizeof(UID_SKM) - 1,
#else
		MAX_UID_SIZE,
#endif	// End of USE_QSEE
		MAX_SKM_BUF_SIZE,
		SKM_PRE_GEN_KEY_PATH,
		SKM_SAVE_FILE_PATH
	},
};

uint8_t *getTaUid(TeeAppId_t teeAppId)
{
	return (uint8_t *)gTeeAppData[teeAppId].teeUid;
}

size_t getTaUidLen(TeeAppId_t teeAppId)
{
	return gTeeAppData[teeAppId].teeUidLen;
}

size_t getTaTotalBufferSize(TeeAppId_t teeAppId)
{
	return gTeeAppData[teeAppId].maxBufferSize + TA_BUFFER_HEADER_LEN;
}

size_t getTaMaxDataSize(TeeAppId_t teeAppId)
{
	return gTeeAppData[teeAppId].maxBufferSize;
}

char *getPreGenKeyPath(TeeAppId_t teeAppId)
{
	return (char *)gTeeAppData[teeAppId].preGenKeyPath;
}

char *getSaveKeyPath(TeeAppId_t teeAppId)
{
	return (char *)gTeeAppData[teeAppId].saveKeyPath;
}
