/**
 * @file OTAMLAPI.h
 * @brief Implementation of OTA ML API (Over The Air Mirror Link Application Program interfaces).
 * @author Andrey Neyvanov (a.neyvanov@samsung.com)
 * @date Created 28.11.2013 12:59
 * @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)
 * @par Copyright: (c) Samsung Electronics Co, Ltd 2013. All rights reserved.
 **/
#ifndef __OTAMLAPI_H_INCLUDED__
#define __OTAMLAPI_H_INCLUDED__

#include <stdint.h>

typedef void* MLOtaSession;

/**
 * Create and return Session context. Fetch ML Server Device public key and UID.
 * @param *session OUT - Session context.
 * @param *otaMlPK OUT - OTA ML Public Key.
 * @param *otaMlPKLen IN/OUT - OTA ML Public Key Length.
 * @param *otaMlUid OUT - OTA ML UID (device ID).
 * @param *otaMlUidLen IN/OUT - OTA ML UID (device ID) Length.
 * @returns 0 if OK or error num.
 * @throws nothing.
 */
int MLOtaGetDevicePK(MLOtaSession* session,
			unsigned char* otaMlPK,
			unsigned int* otaMlPKLen,
			unsigned char* otaMlUid,
			unsigned int* otaMlUidLen);

/**
 * Sign response to CA Server.
 * @param *session IN - Session context.
 * @param *inData IN - Input data for signing.
 * @param *inDataLen IN - Length of Input data for signing.
 * @param *signature OUT - Signature of Input Data.
 * @param *signatureLen IN/OUT - Length of Signature of Input Data.
 * @returns 0 if OK or error num.
 * @throws nothing.
 */
int MLOtaSignRequest(MLOtaSession* session,
			unsigned char* inData,
			unsigned int* inDataLen,
			unsigned char* signature,
			unsigned int* signatureLen);

/**
 * Save retrieved ML Server Device / Manufacturer certificates.
 * @param *session IN - Session context.
 * @param *certMlSD IN - MlSD Certificate.
 * @param *certMlSDLen IN - Length of MlSD Certificate.
 * @param *certMlSM0 IN - MlSM0 Certificate.
 * @param *certMlSM0Len IN - Length of MlSM0 Certificate.
 * @param *certMlSM1 IN - MlSM1 Certificate.
 * @param *certMlSM1Len IN - Length of MlSM1 Certificate.
 * @returns 0 if OK or error num.
 * @throws nothing.
 */
int MLOtaSaveDeviceCert(MLOtaSession* session,
			unsigned char* certMlSD,
			unsigned int* certMlSDLen,
			unsigned char* certMlSM0,
			unsigned int* certMlSM0Len,
			unsigned char* certMlSM1,
			unsigned int* certMlSM1Len);

/**
 * Check ML Server Device certificate presence, validity and status.
 * @returns 0 if OK or error num.
 * @throws nothing.
 */
int MLOtaCheckDeviceCertificate(void);

/**
 * Get retrieved ML Device Certificate.
 * @param *MLOtaDeviceCert IN/OUT - Buffer for ML Device Certificate.
 * @param *MLOtaDeviceCertLen OUT - Length of Buffer for ML Device Certificate.
 * @returns 0 if OK or error num.
 * @throws nothing.
 */
int MLOtaGetDeviceCert(void* MLOtaDeviceCert, unsigned int* MLOtaDeviceCertLen);

/**
 * Get retrieved ML DRK Certificate.
 * @param *MLOtaDRKCert IN/OUT - Buffer for ML DRK Certificate.
 * @param *MLOtaDRKCertLen OUT - Length of Buffer for ML DRK Certificate.
 * @returns 0 if OK or error num.
 * @throws nothing.
 */
int MLOtaGetDRKCert(void* MLOtaDRKCert, unsigned int* MLOtaDRKCertLen);

/**
 * Removes /efs/prov_data/sd/sd.dat  
 * @returns 0 if OK or error num.
 * @throws nothing.
 */
int MLOtaDeleteDeviceKeyAndCert();

#endif