#ifndef VENDOR_SAMSUNG_SECURITY_DRK_DEVICEINFO_H
#define VENDOR_SAMSUNG_SECURITY_DRK_DEVICEINFO_H

#include <stdint.h>
#include <mutex>
#include "systemConfig.h"

namespace vendor   {
namespace samsung  {
namespace hardware {
namespace security {
namespace drk      {

#define MAX_PREFIX_LEN      7
#define MAX_SYSTEM_ID_LEN   256

#define DEVICE_STATUS_IS_INVALID        0
#define DEVICE_STATUS_IS_VALID          1
#define BOTY_DEVICE_STATUS_IS_VALID     2
#define DEVICE_STATUS_IS_UNKNOWN        4
#define DEVICE_STATUS_IS_DRK_V1         8

#define DRK_PREFIX  0
#define SAK_PREFIX  1
#define PROPERTY_KEYSTORE_KEYTYPE       "ro.security.keystore.keytype"

#define SYSTEM_ID_MAX 6

#define VK_FEATURE          1
#define DEV_FEATURE_PRINT   3

typedef enum _systemIdType {
    SYSTEM_ID_STATUS     = 0,
    SYSTEM_ID_MODEM      = 1,
    SYSTEM_ID_IMEI       = 2,
    SYSTEM_ID_SN         = 3,
    SYSTEM_ID_MODEL      = 4,
    SYSTEM_ID_UID        = 5,
} SYSTEM_ID_TYPE;

typedef struct _devInfo_t {
    uint32_t         systemInfoLen;
    uint8_t          systemInfo[MAX_SYSTEM_ID_LEN];
} DEVICE_INFO;

class DeviceInfo
{
private:
    DEVICE_INFO   devInfo[SYSTEM_ID_MAX];

private:
    static bool     isNoImeiSupportedModel();
    static int32_t  matchUidString(uint8_t *uid, uint32_t uidLen, uint8_t *p1,  uint32_t p1Len);
    static int32_t  matchAPUidString(uint8_t *uid, uint32_t uidLen, uint8_t *p1,  uint32_t p1Len,
                                     uint8_t *p2, uint32_t p2Len);
    static int32_t  getSystemInfo(SYSTEM_ID_TYPE systemIdType, Bytes& out);
    static int32_t  getSystemProperty(uint8_t *name, Bytes& out);
    static int32_t  getModelName(Bytes& out);
    static int32_t  getSerialNo(Bytes& out);
    int32_t  gatherDevInfos(Bytes& in);
    int32_t  isMatchedDevInfo();

public:
    DeviceInfo()  { memset(devInfo, 0x0, sizeof(devInfo)); };
    ~DeviceInfo() { memset(devInfo, 0x0, sizeof(devInfo)); };

    static int32_t MakeServiceKeyInfo(Bytes& in);
    static int32_t GetFeatureSet(int32_t mode);
    int32_t  MakeTobeSignedCSR(int prefix, Bytes& in, Bytes& out);
    int32_t  MakeBigDataMsg(Bytes& serviceName, Bytes& in, Bytes& out);
    int32_t  MakeDeviceInfoMsg(Bytes& in, Bytes& out);
    int32_t  checkValidationCertwithDeviceInfo(Bytes& in);
};

}  // namespace drk
}  // namespace security
}  // namespace hardware
}  // namespace samsung
}  // namespace vendor

#endif
