/*
 * board/mt53xx_com/mt53xx_com_rpmb.h
 *
 * MT53xx common board function
 *
 * Copyright (c) 2010-2012 MediaTek Inc.
 * $Author: brianpc.huang $
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 *
 */

#include "x_typedef.h"

#define RPMB_NONCE_SIZE (16)
#define RPMB_DATA_SIZE (256)

#ifndef SHA256_HASH_SIZE
#define SHA256_HASH_SIZE (32)
#endif

typedef struct RPMB_DATAFRAM {
    unsigned short type;
    unsigned short result;
    unsigned short blkCnt;
    unsigned short addr;
    uint32_t writeCnt;
    uint8_t nonce[RPMB_NONCE_SIZE];
    uint8_t data[RPMB_DATA_SIZE];
    uint8_t mac[SHA256_HASH_SIZE];
    uint8_t stuff[196];
} RPMB_DATAFRAM;

typedef enum {
    REQ_SET_KEY = 0x1,
    REQ_GET_CNT = 0x2,
    REQ_WR_DATA = 0x3,
    REQ_RD_DATA = 0x4,
    REQ_RD_RESULT = 0x5,
} RPMB_REQ;

typedef enum {
    RESP_SET_KEY = 0x100,
    RESP_GET_CNT = 0x200,
    RESP_WR_DATA = 0x300,
    RESP_RD_DATA = 0x400,
} RPMB_RESP;

typedef enum {
    RESULT_OK = 0x0,
    RESULT_NG = 0x1,
    RESULT_ATH_NG = 0x2,
    RESULT_CNT_NG = 0x3,
    RESULT_ADR_NG = 0x4,
    RESULT_WR_NG = 0x5,
    RESULT_RD_NG = 0x6,
    RESULT_NO_KEY = 0x7,
    RESULT_TRYLOCK_FAIL = 0x8,
    RESULT_DECRYPT_FAIL = 0x80,
} RPMB_RESULT;

typedef enum {
    RPMB_WV_GENERATION = 0x0,
    RPMB_PR_GENERATION = 0x1,
    RPMB_AVB_GENERATION_1 = 0x2,
    RPMB_AVB_GENERATION_2 = 0x3,
} RPMB_ADDR;

INT32 ubootRpmbReadData(uint8_t *data, RPMB_ADDR addr);
INT32 ubootRpmbWriteData(const uint8_t *data, RPMB_ADDR addr, unsigned short blkCnt);

