#ifndef _TL_SPAY_TUI_MSG_H_
#define _TL_SPAY_TUI_MSG_H_

#include "spay_msg.h"
#include "spay_init_msg.h"
#include "spay_authenticate_transaction_tl.h"
#include "spay_load_pin_random_msg.h"
#include "TZ_platform_defs.h"
#include "ta_log.h"
#include "TZ_Vendor_Tui_common_tl.h"
#include "tl_tui_layout.h"

//#ifdef USE_MOBICORE
//#include "mcSo.h"
//#define WRAP_SIZE(plainLen, encryptedLen)     MC_SO_SIZE(plainLen, encryptedLen)
//#define TIMA_TUI_SECRET_FILE  "/data/system/tima_tui/secret"
//#else
//#define WRAP_SIZE(plainLen, encryptedLen)     200 + encryptedLen //TODO: change to the right function
//#include <stdbool.h>
//#endif

#ifdef USE_BTS
#ifdef USE_QSEE
#define WRAP_SIZE(plainLen, encryptedLen) 	600 + encryptedLen	// TODO: change this
#else
#define WRAP_SIZE(plainLen, encryptedLen) 	200 + encryptedLen	// TODO: change this
#endif
#else
#define WRAP_SIZE(plainLen, encryptedLen) 	200 + encryptedLen	// TODO: change this
#endif

typedef uint32_t timaTuiCommandId_t;
typedef uint32_t timaTuiResponseId_t;
typedef uint32_t timaTuiReturnCode_t;

/**
 * Command IDs for TUI
 */
#define SPAY_TUI_CMD_LOAD_PIN		0x10000	// automatically loaded during initialization
#define SPAY_TUI_CMD_SET_MODE_TEXT	0x10001	// display "Secure Mode" in current locale
#define SPAY_TUI_CMD_SET_ACTIONBAR_TEXT	0x10002	// display text in action bar in current locale

#define SPAY_TUI_CMD_SETUP		0x20000	// setup flow
#define SPAY_TUI_CMD_VERIFY		0x20001	// verify flow
#define SPAY_TUI_CMD_RESUME		0x20002	// resume either setup or verify flow
//#define SPAY_TUI_CMD_UPDATE_BIO	0x20003	// verify FP/IRIS auth so and update FP/IRIS ID list
//#define SPAY_TUI_CMD_SETUP_BIO	0x20004	// setup FP and IRIS so
//#define SPAY_TUI_CMD_SETUP_BIO_SINGLE	0x20005	// setup iris/fp flow
#define SPAY_TUI_CMD_CLOSE		0x20010	// close the TUI session. Usually implicit called before closing TUI TA (qsee)
#define SPAY_TUI_CMD_CLEAR_STATE	0x20011	// clear the state so that TUI is ready for a new flow

#define SPAY_TUI_CMD_SET_PIN_BOX	0x30000
#define SPAY_TUI_CMD_SET_PROMPT		0x30001
#define SPAY_TUI_CMD_SET_IMAGE		0x30002
#define SPAY_TUI_CMD_SET_CANCEL_IMAGE	0x30003

#define SPAY_AUTH_CMD_SET_PREFERENCE	0x30010

#define SPAY_TUI_CMD_GET_PIN		0x40000	// return the PIN + random (for TUI)
#define SPAY_TUI_CMD_GET_SECURE_RESULT	0x40001	// return PIN verification result (for other payment TAs, and TUI)
#define SPAY_TUI_CMD_GET_RANDOM		0x40002	// return the random number associated with PIN (for other payment TAs)
#define SPAY_TUI_CMD_GENERATE_RANDOM	0x40003	// generate a random (without PIN setup). Needed when only FP is used for authentication
//#define SPAY_TUI_CMD_PRELOAD_FP_SECURE_RESULT	0x40004// Pre load the unwrapped secure result from FP module
#define SPAY_TUI_CMD_GET_PIN_RANDOM_FOR_WALLET  0x40005

#define SPAY_TUI_CMD_CHECK_TUI_SESSION	0x50000	// check whether the TUI session is still on
#define SPAY_TUI_CMD_CHECK_RET_CODE	0x50001	// Only for QC

#define BC_TUI_CMD_START_BACKUP_SCREEN 0x60000
#define BC_TUI_CMD_START_RESTORE_SCREEN 0x60001
#define BC_TUI_CMD_START_RECOVERY_SCREEN 0x60003
#define BC_TUI_CMD_GET_STATE 0x60004
#define BC_TUI_CMD_GET_SO 0x60005
#define BC_TUI_CMD_SET_SCREEN_BACKGROUND 0x60006
#define BC_TUI_CMD_SET_TOUCHABLE_VIEW 0x60007
#define BC_TUI_CMD_SET_DRAWABLE_VIEW 0x60008
#define BC_TUI_CMD_SEND_RESOURCE_DATA 0x60009
#define BC_TUI_CMD_UPDATE_SCREEN 0x60010
#define BC_TUI_CMD_SET_BACKUP_QUIZ_ORDER 0x60011

#define BC_TUI_CMD_SET_PIN_SCREEN_BACKGROUND 0x60012
#define BC_TUI_CMD_SEND_PIN_RESOURCE_DATA 0x60013
#define BC_TUI_CMD_SET_PIN_TOUCHABLE_VIEW 0x60014
#define BC_TUI_CMD_SET_NAVIGATION_GESTURE 0x60015
#define BC_TUI_CMD_SET_LAYOUT_PARAMS 0x60017
#define BC_TUI_CMD_SEND_RESOURCE_DATA_ARRAY 0x60018

/* TYPES FOR SEND_RESOURCe_DATA_ARRAY */
#define RESOURCE_ARRAY_TYPE_PINPAD 9
#define RESOURCE_ARRAY_TYPE_FREE 0xFF

#define SPAY_TUI_CMD_DRV_PIN	0x77777	 /** No Tlc interaction, but notification from TUI driver */
#define SPAY_TUI_CMD_DRV_QTY	0x88888	 /** No Tlc interaction, but notification from TUI driver */

/* Command IDs for authentication
*/
#define SPAY_AUTH_CMD_CHECK_WARRANTY_BIT	0x80000
#define SPAY_AUTH_CMD_GET_NONCE			0x80001
#define SPAY_AUTH_CMD_GET_AUTH_RESULT		0x80002	// return the consolidated auth result (could from FP or TUI)

//#define SPAY_AUTH_CMD_INAPP_CONFIRM		0x90000
//#define SPAY_AUTH_CMD_INAPP_SECURE_DISPLAY      0x90001
//#define SPAY_AUTH_CMD_INAPP_SECURE_TOUCH        0x90002
//#define SPAY_AUTH_CMD_INAPP_SECURE_SCREEN_INIT	0x90003
//#define SPAY_AUTH_CMD_INAPP_SEND_SECURE_IMAGE	0x90004
//#define SPAY_AUTH_CMD_SET_SECURITY_PROPERTY	0x90005

/*
 * Return code
 */
#define TIMA_SUCCESS				0
#define	TIMA_ERROR_OUT_OF_MEMORY		1
#define	TIMA_ERROR_UNKNOWN_ERROR		2
#define TIMA_TRANSFER_NOT_FINISH		3
#define TIMA_TRANSFER_FINISH_ALL		4
#define TIMA_ERROR_TUI				0x5000
#define TIMA_ERROR_TUI_CANCELLED		TIMA_ERROR_TUI
#define	TIMA_ERROR_TUI_NO_SESSION		TIMA_ERROR_TUI + 1 /** The session to TUI driver cannot be found. It was not opened or has been closed*/
#define	TIMA_ERROR_TUI_BUSY			TIMA_ERROR_TUI + 2 /** TUI driver is busy. Another session may be open. */
#define	TIMA_ERROR_TUI_NO_EVENT			TIMA_ERROR_TUI + 3 /** TUI event queue is empty. */
#define	TIMA_ERROR_TUI_OUT_OF_DISPLAY		TIMA_ERROR_TUI + 4 /** TUI driver can't display the image because it is out of screen. */
#define	TIMA_ERROR_TUI_IMG_BAD_FORMAT		TIMA_ERROR_TUI + 5 /** TUI driver can't decode the image. */
#define	TIMA_ERROR_TUI_NO_RESOURCE		TIMA_ERROR_TUI + 6
#define	TIMA_ERROR_TUI_IN_PROGRESS		TIMA_ERROR_TUI + 7
#define	TIMA_ERROR_TUI_NOT_SUPPORTED		TIMA_ERROR_TUI + 8
#define	TIMA_ERROR_TUI_UNKNOWN_CMD		TIMA_ERROR_TUI + 9
#define	TIMA_ERROR_TUI_NOT_READY		TIMA_ERROR_TUI + 10
#define TIMA_ERROR_TUI_SECRET_READ_ERROR	TIMA_ERROR_TUI + 11
#define TIMA_ERROR_TUI_SECRET_WRITE_ERROR	TIMA_ERROR_TUI + 12
#define TIMA_ERROR_TUI_SECRET_NOT_EXIST		TIMA_ERROR_TUI + 13
#define TIMA_ERROR_TUI_DISPLAY_ERROR		TIMA_ERROR_TUI + 14
#define TIMA_ERROR_TUI_IMAGE_TOO_BIG		TIMA_ERROR_TUI + 15
#define TIMA_ERROR_TUI_CERT_BAD_FORMAT		TIMA_ERROR_TUI + 16
#define TIMA_ERROR_TUI_CERT_KEY_ERROR		TIMA_ERROR_TUI + 17
#define TIMA_ERROR_TUI_PRIVATE_KEY_ERROR	TIMA_ERROR_TUI + 18
#define TIMA_ERROR_TUI_SECRET_DECRYPT_ERROR	TIMA_ERROR_TUI + 19
#define TIMA_ERROR_TUI_SECRET_SIGNATURE_ERROR	TIMA_ERROR_TUI + 20
#define TIMA_ERROR_TUI_RES_INVALID_ID		TIMA_ERROR_TUI + 21
#define TIMA_ERROR_TUI_MALLOC_ERROR		TIMA_ERROR_TUI + 22
#define TIMA_ERROR_TUI_WRAP_ERROR		TIMA_ERROR_TUI + 23
#define TIMA_ERROR_TUI_PIN_VERIFY_FAIL		TIMA_ERROR_TUI + 24
#define TIMA_ERROR_INVALID_ARGUMENT		TIMA_ERROR_TUI + 25

/*
 * Return code specific to SPAY TUI
 */
#define SPAY_TPP_ERROR_NO_PIN			0x60000
#define SPAY_TPP_ERROR_INVALID_PIN_SO		0x60001
#define SPAY_TPP_ERROR_PIN_EXIST		0x60002
#define SPAY_TPP_ERROR_NO_FLOW_TO_RESUME	0x60003
#define SPAY_TPP_SETUP_PIN_ENTERED		0x60004
#define SPAY_TPP_SETUP_PIN_VERIFIED		0x60005
#define SPAY_TPP_ERROR_SETUP_PIN_MISMATCH	0x60006
#define SPAY_TPP_PIN_VERIFYED			0x60007
#define SPAY_TPP_ERROR_PIN_MISMATCH		0x60008
#define SPAY_TPP_ERROR_CANCELED			0x60009
#define SPAY_TPP_ERROR_3_SAME_DIGITS		0x6000A	// PIN contains same digits,such as 1113
#define SPAY_TPP_ERROR_CONSECUTIVE_DIGITS	0x6000B	// such as 1234 or 4321
//#define SPAY_TPP_ERROR_TUI_FP_REJECT		0x6000C	// Do not accept FP when PIN exists but FP ID list is empty
#define SPAY_TPP_ERROR_TUI_VERIFIED_TIMEOUT	0x6000D	// TUI verification result is not valid anymore
//#define SPAY_TPP_ERROR_TUI_IRIS_REJECT		0x6000E	// Do not accept FP when PIN exists but FP ID list is empty
#define SPAY_TPP_ERROR_TIMEOUT			0x6000F

#define SPAY_TPP_ERROR_INVALID_NUMBER_OF_PIN	0x61000
#define SPAY_TPP_ERROR_INVALID_STATE		0x61001
#define SPAY_TPP_ERROR_GENERIC			0x62000

#define SPAY_TPP_TUI_SESSION_ON			0x63000
#define SPAY_TPP_TUI_SESSION_OFF		0x63001

//#define SPAY_TPP_INAPP_CONFIRMED		0x64000

#define SPAY_TPP_TUI_UPGRADE_PIN_SO_VERSION		0x65000
#define SPAY_TPP_TUI_ERROR_REWRAP_PIN_SO		0x65001

//#define SPAY_TPP_TUI_MERCHANT_BASE		0x66000
//#define SPAY_TPP_TUI_MERCHANT_ERROR_BASE	0x67000
//#define SPAY_TPP_TUI_MERCHANT_ERROR_INVALID_INPUT	SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x1
//#define SPAY_TPP_TUI_MERCHANT_ERROR_INVALID_LENGTH	SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x2
//#define SPAY_TPP_TUI_MERCHANT_ERROR_INVALID_KEYPADLEN	SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x3
//#define SPAY_TPP_TUI_MERCHANT_ERROR_INVALID_COORDS	SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x4
//#define SPAY_TPP_TUI_MERCHANT_ERROR_SECON_NONCE		SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x10 // nonce before secure display
//#define SPAY_TPP_TUI_MERCHANT_ERROR_SEC_IS_ON		SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x11 // secure display too short
//#define SPAY_TPP_TUI_MERCHANT_ERROR_FPPRELOAD_SECOFF	SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x12 // time between fp preload and sec display off is too long
//#define SPAY_TPP_TUI_MERCHANT_ERROR_SECURE_INDICATOR	SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x13 // the number of secure textinfo image is wrong when show merchant display
//#define SPAY_TPP_TUI_MERCHANT_ERROR_INVALID_SEC_LEVEL	SPAY_TPP_TUI_MERCHANT_ERROR_BASE + 0x14 // secure level is invalid

#define TBASE_SPAYTUI_PROCESS		"ffffffff000000000000000000000083"
#define QSEE_SPAYTUI_PROCESS		"bc_tui"

#define EXIT_ERROR			0xffffffff

#define SPAY_TUI_MAX_TIMER_VAL_SECS	300

#define NONCE_BUFFER_SIZE	64	/* The number of bytes in nonce */


#define PIN_SIZE		16	/* Maximum PIN size */
#define FP_ID_LEN		1024	/* Maximum buffer used to save all FP IDs */

#define TUI_MAX_ERROR_STR_LEN		TA_MAX_ERROR_STR_LEN

// This is the old PIN SO structure. Leave it for backward compatibility
PACK(
typedef struct _pin_so {
	uint8_t pin[PIN_SIZE];
	uint8_t pin_len;
	uint8_t rand[SPAY_RANDOM_NUMBER_SIZE];
}) pin_so_t; // original : 41 -> packed : 41

#define PIN_SO_SIZE		WRAP_SIZE(0, sizeof(pin_so_t))

PACK(
typedef struct {
	uint8_t pin[PIN_SIZE];
	uint8_t pin_len;
	uint8_t rand[SPAY_RANDOM_NUMBER_SIZE];
#ifndef USE_BTS
	uint8_t fp_id_len;
	uint8_t fp_id[FP_ID_LEN];
#endif
}) pin_fp_so_t; // original : 1066 -> packed : 1066

#define PIN_FP_SO_SIZE		WRAP_SIZE(0, sizeof(pin_fp_so_t))

#ifdef IRIS_SUPPORTED
#define PIN_FP_SO_OLD_SIZE	WRAP_SIZE(0, sizeof(pin_fp_so_old_t))
#endif  /* IRIS_SUPPORTED */

#define PIN_BUFFER_SIZE			4096
//TCI length can not be longer than 1048576, checked in mcOpenSession
#define RESOURCE_BUFFER_SIZE		1024 * 250
#define BC_TUI_TRANSACTION_SO_BUFFER_SIZE	2048
#define IMG_SIZE_LIMIT				1024 * 1750		// normal world image size limit

#define SPAY_AUTH_RESULT_SRC_TUI			0x00
//#define SPAY_AUTH_RESULT_SRC_FP			0x01 
#define SPAY_AUTH_RESULT_SRC_BACKUP_PWD		0x02
//#define SPAY_AUTH_RESULT_SRC_IRIS			0x03
#define SPAY_AUTH_RESULT_SRC_UNKNOWN		0xFF
//#define SPAY_AUTH_RESULT_INAPP_BIT		0x80	// when the bit is set, authentication is allowed for inapp. Otherwise, instore only

#define TUI_RESULT_MAGIC	"TUI "
/*
typedef struct verifyPinResult {
	uint8_t magic[4];
	uint32_t nonce_len;
	uint8_t nonce[NONCE_BUFFER_SIZE];
	uint32_t app_name_len;
	uint8_t app_name[APP_NAME_BUFFER_SIZE];
	uint32_t result;   // SPAY_TUI_PIN_VERIFY_SUCCESS: success, all other: failed
} ) spayVerifyPinResult_t;
*/

#define SPAY_VERIFY_PIN_SO_SIZE		WRAP_SIZE(0, sizeof(spayVerifyPinResult_t))
#define INAPP_VERIFY_PIN_SO_SIZE	WRAP_SIZE(0, sizeof(inappVerifyPinResult_t))

#define SO_BUFFER_SIZE	1024

#define SECURE_TEXT_INFO_NUM	3

/*
 * Request structures
 */

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[PIN_FP_SO_SIZE];
	} ) pin_so;
} ) loadPinCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[NONCE_BUFFER_SIZE];
	} ) nonce;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[APP_NAME_BUFFER_SIZE];
	} ) app_name;
}) getSecureResultCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[APP_NAME_BUFFER_SIZE];
	} ) app_name;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[NONCE_BUFFER_SIZE];
	} ) wallet_nonce;
} ) getPinRandForWalletCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[RESOURCE_BUFFER_SIZE];
	} ) images;
	uint32_t normal_pin_buf_len;	// the length of normal pin box image
	uint32_t error_pin_buf_len;	// the length of error pin box image
	uint8_t number;		// number of pin boxes
	uint32_t y_dp;		// where to display the pin box
	uint32_t space;		// space between 2 pin boxes
	uint32_t pinbox_width_dp;	// the conceptual width of pin box, since PIN box may not be a box shape.
	uint32_t pinbox_height_dp;	// the conceptual height of pin box, since PIN box may not be a box shape.
} ) setPinBoxCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[RESOURCE_BUFFER_SIZE];
	} ) image;
	uint32_t above_pin_box;
	uint32_t dis_to_pinbox_dp;
} ) setPromptCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[RESOURCE_BUFFER_SIZE];
	} ) image;
	uint32_t x_dp;
	uint32_t y_dp;
} ) setImgCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[RESOURCE_BUFFER_SIZE];
	} ) images;	// images for pressed and unpressed buttons
	uint32_t unpressed_len;	// the buffer len for unpressed image
	uint32_t pressed_len;	// the buffer len for pressed image
	uint32_t x_dp;
	uint32_t y_dp;
} ) setCancelImgCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[RESOURCE_BUFFER_SIZE];
	} ) image;
} ) setSecureModeText_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[RESOURCE_BUFFER_SIZE];
	} ) image;
} ) setActionBarText_t;

/* auth request structures */
PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[NONCE_BUFFER_SIZE];
	} ) nonce;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[APP_NAME_BUFFER_SIZE];
	} ) app_name;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[SO_BUFFER_SIZE];
	} ) so;
} ) getAuthResult_t;

PACK(
typedef struct {
	uint32_t nonce_len;
} ) getNonce_t;

PACK(
typedef struct {
	uint8_t close_tui_session;
	uint8_t update_display_only;
} ) verify_t;

PACK(
typedef struct {
	uint8_t update_display_only;
} ) resume_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[APP_NAME_BUFFER_SIZE];
	} ) app_name;
} ) getRandomCmd_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[SO_BUFFER_SIZE];
	} ) so;
} ) fpAuthResult_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t isRTL;
		uint8_t isBHR;
	} ) val;
} ) setPreference_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[RESOURCE_BUFFER_SIZE];
	} ) image;
	uint32_t x;
	uint32_t y;
} ) textImage_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[BC_TUI_TRANSACTION_SO_BUFFER_SIZE];
	} ) mnemonic_so;
} ) backupScreen_t;

PACK(
typedef struct {
	uint32_t firstWord;
	uint32_t secondWord;
	uint32_t thirdWord;
}) quizOrder_t;

PACK(
typedef struct {
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[BC_TUI_TRANSACTION_SO_BUFFER_SIZE];
	}) mnemonic_so;
}) recoveryScreen_t;

PACK(
	typedef struct {
	uint32_t imageSize;
	uint32_t imageWidth;
	uint32_t imageHeight;
}) screenBackground_t;

PACK(
  typedef struct {
    uint32_t index;
      PACK(
        struct {
          uint32_t len;
          uint8_t buf[RESOURCE_BUFFER_SIZE];
      }) resource;
}) screenResource_t;

typedef struct {
    uint32_t len;
    uint8_t buf[RESOURCE_BUFFER_SIZE];
} resource_t;

PACK(
	typedef struct {
	uint32_t viewId;
	uint32_t startX;
	uint32_t startY;
	uint32_t viewWidth;
	uint32_t viewHeight;
	uint32_t eventSize;
	uint32_t originSize;
	uint32_t extraSize;
  resource_t resource;
}) screenView_t;


PACK(
typedef struct {
    uint32_t type;
    uint8_t buf[RESOURCE_BUFFER_SIZE];
}) screenResourceArray_t;

PACK(
	typedef struct {
	uint32_t index;
}) updateScreen_t;

PACK(
	typedef struct {
	uint8_t isGesture;
}) navigation_t;

PACK(
typedef struct {
	PACK(
	union {
		loadPinCmd_t loadPin;
		getSecureResultCmd_t getSecureResult;
		getPinRandForWalletCmd_t getSecureResultForWallet;
		setPinBoxCmd_t setPinBox;
		setPromptCmd_t setPrompt;
		setImgCmd_t setImage;
		setCancelImgCmd_t setCancel;
		setSecureModeText_t setSecureModeText;
		setActionBarText_t setActionBarText;
		verify_t verify;
		resume_t resume;
		fpAuthResult_t setup;
		getAuthResult_t getAuthResult;
		getNonce_t getNonce;
		getRandomCmd_t getRandom;

		setPreference_t setPreference;

		textImage_t textImage;
		backupScreen_t backupScreen;
		quizOrder_t quizOrder;
		recoveryScreen_t recoveryScreen;
		screenBackground_t screenBackground;
		screenView_t screenView;
		screenResource_t screenResource;
		layoutParams_t layoutParams;
		screenResourceArray_t screenResourceArray;
		updateScreen_t updateScreen;

		navigation_t navigation;

	} ) data;
} ) spayTuiCommand_t;

/**
 * Response structure Trusted Application -> Trusted Application Connector.
 */
PACK(
typedef struct {
	timaTuiReturnCode_t retCode;
	PACK(
	struct {
		uint32_t len;
		uint8_t data[TUI_MAX_ERROR_STR_LEN];
	} ) err_msg;
} ) commonRsp_t;

PACK(
typedef struct {
	commonRsp_t ret_comm;
	uint32_t existing_pin_len;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[PIN_FP_SO_SIZE];
	} ) updated_pin_so;
} ) loadPinRsp_t;

PACK(
typedef struct {
	commonRsp_t ret_comm;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[PIN_FP_SO_SIZE];
	} ) pin_so;
	uint32_t existing_pin_len;
} ) getPinRsp_t;

PACK(
typedef struct {
	commonRsp_t ret_comm;
	uint32_t auth_result_src;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[SPAY_VERIFY_PIN_SO_SIZE];
	} ) result_so;
} ) getSecureResultRsp_t;

PACK(
typedef struct {
	//timaTuiReturnCode_t retCode;
	commonRsp_t ret_comm;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[NONCE_BUFFER_SIZE];
	} ) nonce;
} ) getNonceRsp_t;

PACK(
typedef struct {
	//timaTuiReturnCode_t retCode;
	commonRsp_t ret_comm;
	uint32_t auth_result_src;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[INAPP_VERIFY_PIN_SO_SIZE];
	} ) result_so;

	uint8_t need_update_pin_so;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[PIN_FP_SO_SIZE];
	} ) pin_so;

	uint32_t existing_pin_len;

} ) getAuthResultRsp_t;

PACK(
typedef struct {
	//timaTuiReturnCode_t retCode;
	commonRsp_t ret_comm;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[INAPP_VERIFY_PIN_SO_SIZE];
	} ) result_so;
} ) bcConrimRsp_t;

PACK(
typedef struct {
	commonRsp_t ret_comm;
	PACK(
	struct {
		uint32_t len;
		uint8_t buf[BC_TUI_TRANSACTION_SO_BUFFER_SIZE];
	} ) transaction_so;
} ) bcTransactionSoRsp_t;


// response
PACK(
typedef struct {
	PACK(
	union {
		loadPinRsp_t loadPinRsp;
		getPinRsp_t getPinRsp;
		getSecureResultRsp_t getSecureResultRsp;
		getAuthResultRsp_t getAuthResultRsp;
		commonRsp_t commonRsp;

		getNonceRsp_t getNonceRsp;

		bcConrimRsp_t bcConfirmRsp;
		bcTransactionSoRsp_t bcTransactionSoRsp;
	} ) data;
} ) spayTuiRsp_t;

PACK(
typedef struct {
	spay_msg_hdr_t spayhdr;
	PACK(
	union {
		tz_spay_init_msg_payload_t init;
		tz_spay_load_pin_random_payload_t load_pin_random;
		spayTuiCommand_t cmd;
		spayTuiRsp_t rsp;
	} ) payload;
} ) spayTuiMsg_t;

typedef spayTuiMsg_t tciMessage_t;	// to make the message common to use the common entry point


#endif // _TL_TIMA_TUI_MSG_H_
