/*
 * =====================================================================================
 *
 *       Filename:  tui_interface.h
 *
 *    Description:  Commom interface for TUI
 *
 *        Version:  1.0
 *        Created:  04/03/2020  17:06 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *        Company:  Samsung Electronics
 *        Copyright (c) 2020 by Samsung Electronics, All rights reserved.
 *
 * =====================================================================================
 */

#ifndef _TUI_INTERFACE_H_
#define _TUI_INTERFACE_H_

/**
 * Includes
 */
#include <stdint.h>
#include "tz_msg.h"

// TCI length can not be longer than 1048576, checked in mcOpenSession
#define RESOURCE_BUFFER_SIZE 1024 * 250
#define PAYMENTINFO_LEN 16384
#define MAX_RESULT_BUFFER_LEN 16384

#define PACK_C( __Declaration__ ) __Declaration__ __attribute__ ((__packed__)) 

typedef enum pinbox_resource_type {
    RESOURCE_TYPE_PINDOT,
    RESOURCE_TYPE_PINBOX,
    RESOURCE_PINBOX_RESET = 0xFF
} pinbox_resource_type_t;

typedef enum pinpad_resource_type {
    RESOURCE_TYPE_PINPAD,
    RESOURCE_TYPE_SOFTKEY,
    RESOURCE_PINPAD_RESET = 0xFF
} pinpad_resource_type_t;

/*
 * Request structures
 */
PACK_C(
  typedef struct {
        uint32_t buflen;
        uint8_t buffer[MAX_RESULT_BUFFER_LEN];
}) tuiCertificate_t;

PACK_C(
  typedef struct {
        uint32_t xLeft;
        uint32_t yTop;
        uint32_t size;
        uint8_t buf[RESOURCE_BUFFER_SIZE];
}) screenResource_t;

PACK_C(
typedef struct {
    uint32_t type; // PIN DOT = 0, PIN BOX = 1, RESET=0xFF
    uint32_t normal_dot_buf_size;
    uint32_t error_dot_buf_size;
    uint32_t clear_dot_buf_size;
    uint32_t normal_pinbox_buf_size;
    uint32_t error_pinbox_buf_size;
    uint8_t number;        // number of pin boxes
    uint8_t buf[RESOURCE_BUFFER_SIZE];
    // buf format
    // PIN DOT : [normal_dot_buf][error_dot_buf][clear_dot_buf][xLeft1 (4 byte)][yTop1 (4 byte)][...][xLeftN (4 byte)][yTopN (4 byte)]
    // PIN PAD : [normal_pinbox_buf][error_pinbox_buf][xLeft1 (4 byte)][yTop1 (4 byte)][...][xLeftN (4 byte)][yTopN (4 byte)]
} ) setPinBoxCmd_t;

PACK_C(
typedef struct {
    uint32_t type; // PINPAD = 0, SOFTKEY = 1, RESET=0XFF
    uint8_t buf[RESOURCE_BUFFER_SIZE];
    // buf format
    // PINPAD:  [total_length][num of images][0_released_buf][...][9_released_buf][0_pressed_buf][...][9_pressed_buf][xLeft0][yTop0][...][xLeft9][yTop9]
    // SOFTKEY: [total_length][num of images][softkey_released_buf][softkey_pressed_buf][xLeft_softkey][yTop_softkey]
    // EXTRA : [secure_icon_buf][knox_img_buf] - ??, TBD
}) screenResourceArray_t;
// buf format : https://mobilerndhub.sec.samsung.net/wiki/pages/viewpage.action?pageId=941491065

PACK_C(
typedef struct {
    PACK_C(
    union {
        tuiCertificate_t certificate;
        setPinBoxCmd_t setPinBox;  // pinbox image
        screenResource_t screenBackground;  // background image
        screenResourceArray_t screenResourceArray; // pinpad images
    } ) data;
}) tuiReqCommand_t;

PACK_C(
typedef struct {
    tz_msg_header_t header;
    PACK_C(
    union {
        tuiReqCommand_t cmd;
    } ) payload;
}) tciMessage_t;

#endif /* _TUI_INTERFACE_H_ */
