/*!
*  \file MlDapApi.h
*  \brief ML Server DAP API (Testing purposes, see develop-RS_Test_MlService branch)
*  \author Roman Striapko (r.striapko@samsung.com)
*  \date Created 10.28.2013 10:23
*  \date Last Change 11.05.2013 11:13
*  \par In Samsung Ukraine R&D Center (SRK) under a contract between
*  \par LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
*  \par and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
*  \copyright (c) Samsung Electronics Co, Ltd 2013. All rights reserved.
*/

#ifndef _MLDAPAPI_H_
#define _MLDAPAPI_H_

/*
 * Macro to export only API methods
 */
#if __GNUC__ >= 4
    #define APIEXPORT __attribute__((visibility("default")))
#else
    #define APIEXPORT
#endif

typedef enum _MlDapApiError_t
{
	MLDAPAPIERR_NO_ERROR = 0,
	MLDAPAPIERR_BUFFER_TOO_SMALL = -1,
	MLDAPAPIERR_PCR_ERROR = -2,
	MLDAPAPIERR_DECODE_ERROR = -3,
	MLDAPAPIERR_RSA_ERROR = -4,
	MLDAPAPIERR_READ_KEY_ERROR = -5,
	MLDAPAPIERR_MAX = -128
} MlDapApiError_t;

/*
 *  \method getDeviceCertificate
 *  \desc Fetches Device certificate (created once per device),
 *  \par which is signed by Manufacturer key.
 */
APIEXPORT
MlDapApiError_t getDeviceCertificate(
	uint8_t*  buf,
	uint32_t* buflen);

/*
 *  \method getManufactureCertificate
 *  \desc Fetches Manufacturer certificate which is signed
 *  \par by CCC Root CA.
 */
APIEXPORT
MlDapApiError_t getManufactureCertificate(
	uint8_t* certSM0, uint32_t* certSM0Len,
	uint8_t* certSM1, uint32_t* certSM1Len);

/* 
 *  \method getPcr
 *  \desc Fetches 20 byte PCR buffer.
 */
APIEXPORT
MlDapApiError_t getPcr(
	uint8_t*  buf,
	uint32_t* bufLen);

/*
 *  \method extendPcr
 *  \desc Extend the PCR buffer using input data and read
 *  \par new PCR buffer to buf.
 */
APIEXPORT
MlDapApiError_t extendPcr(
	uint8_t*  inData,
	uint32_t  inLen,
	uint8_t*  buf,
	uint32_t* bufLen);

/*
 *  \method generateSignature
 *  \desc Perform sign operation on inData using Device
 *  \par private key and fill the signature in the buf.
 */
APIEXPORT
MlDapApiError_t generateSignature(
	uint8_t*  inData,
	uint32_t  inLen,
	uint8_t*  buf,
	uint32_t* bufLen);

/*
 *  \method getOemFlag
 *  \desc get OEM flag for integrity check
 *  \par none.
 */
APIEXPORT
int getOemFlag(void);

APIEXPORT int MLOtaInitialize();

APIEXPORT int MLOtaDeInitialize();

#endif /*_MLDAPAPI_H_*/