Prueba de concepto

 avatar
unknown
c_cpp
10 months ago
24 kB
23
Indexable
#include <posapi.h>
#include <posapi_all.h>
#include "include/readerdata.h"
#include "include/screen.h"
#include "include/messageManager.h"
#include "include/messageUtils.h"
#include "include/generalutils.h"
#include "include/writerdata.h"
#include "include/globalVars.h"
//#include "include/LogoBBVA.h"
#include "include/emvUtils.h"
#include "appLib.h"
#include "include\trazas.h"
#include "include\bancomerBines.h"
#include "global.h"
#include "fileoper.h"
#include "include\iso8583Builder.h"
#include "DecryptFileKey.h" 
//#define MSG_INIT "BBVA BANCOMER"
#define MSG_INIT "BBVA BANCOMER"

const APPINFO AppInfo = { 
	"PXSP30",
	"APP-BETA",
	CURRENT_VERSION,
	"Vierge Group",
	"App de manejo de comandos ECR de BBVA en formato IBM BiSync",
	"",
	0,
	0,
	0,
	""
};

//configuracion del aplicativo
int current_channel;
int current_dataspeed;
int current_databits;
char current_dataparity;
int current_datastopbits;
int current_lrc_check;
int current_exec_mode;
int current_trans_counter;
int current_debug_mode = 0;

//Estatus del aplicativo
uint current_wait_command = _NONE;
uint current_SerialFileSeek = 0;
int current_trace_iFD = -1;
//indica las etapas cumplidas de un proceso en curso
uint process_init_count = 0; 
//datos de encriptación de llaves
R_RSA_PUBLIC_KEY	tPubkey;
R_RSA_PRIVATE_KEY	tPrikey;
//data usada para los procesos de emulación
uint flag_developer_mode = MODE_REAL;
uint flag_emulation_recv_counter = 0;
uint emulation_recv_len = 0;
uchar emulation_recv_trace[MAX_BUF_LEN];

//Temporal code until update of the POSAPI
#ifdef WIN32
uchar GetUsbdMode(void)
{
		return 0;
}

void SetUsbdMode(uchar mode)
{

}

int SetRebootPromptTime(ushort time)
{
	return 0;
}

void GetRebootPromptTime(ushort* time)
{

}

#endif

int event_main(ST_EVENT_MSG *msg)
{
	SystemInit();
	return 0;
}

int loadConfiguration()
{
	int result = -1;
	unsigned char value [21];
	int current_emv_mode;

	memset(value, 0, sizeof(value));
	// Obtenemos el contador
	if (GetEnv(TRANS_COUNTER, value) != 0)
	{
		current_trans_counter = 0;
	}
	else
	{
		current_trans_counter = atoi(value);
	}
	//Obtenemos el canal de conexion
#ifndef DEBUG_CON_SERIAL
	if (GetEnv(ENV_CHANNEL, value) != 0)
	{
		current_channel = _CHANNELUSBDEV;
	}
	else
	{
		current_channel = atoi(value);
	}
#else
	current_channel = 	_CHANNELRS232COM1;
#endif
	// Obtenemos la velocidad de conexion
	memset(value, 0, sizeof(value));
	if (GetEnv(ENV_DATA_SPEED, value) != 0)
	{
		current_dataspeed = _115200;
	}
	else
	{
		current_dataspeed = atoi(value);
		
		switch (current_dataspeed)
		{
			case _9600:	break;
			case _19200: break;
			case _38400: break;
			case _57600: break;
			case _115200: break;
			default:
				current_dataspeed = _115200;
				break;
		}
	}

	// Obtenemos el flag de chequeo del LRC
	if (GetEnv(ENV_LRC_CHECK, value) != 0)
	{
		current_lrc_check = TRUE;
	}
	else
	{
		current_lrc_check = atoi(value);
	}

	// Obtenemos la cantidad de bits
	memset(value, 0, sizeof(value));
	if (GetEnv(ENV_DATA_BITS, value) != 0)
	{
		current_databits = _8BITS;
	}
	else
	{
		current_databits = atoi(value);
	}

	// Obtenemos la paridad
	memset(value, 0, sizeof(value));
	if (GetEnv(ENV_PARITY, value) != 0)
	{
		current_dataparity = _NOPARITY;
	}
	else
	{
		current_dataparity = value[0];
	}

	// Obtenemos bit de parada
	memset(value, 0, sizeof(value));
	if (GetEnv(ENV_STOP_BIT, value) != 0)
	{
		current_datastopbits = _1STOPBIT;
	}
	else
	{
		current_datastopbits = atoi(value);
	}
	// Obtenemos el modo de ejecucion
	memset(value, 0, sizeof(value));
	if (GetEnv(ENV_EXEC_MODE, value) != 0)
	{
		current_exec_mode = _PROD;//_DEV;
	}
	else
	{
		current_exec_mode = atoi(value);
	}

	// Obtenemos el modo de EMV
	memset(value, 0, sizeof(value));
	if (GetEnv(ENV_EMVCONF, value) != 0)
	{
#ifndef PRODUCCION_EMV
		current_emv_mode = 3; //Test y produccion
#else
		current_emv_mode = 1; //produccion
#endif
		sprintf(value, "%d", current_emv_mode);
		PutEnv(ENV_EMVCONF, value);
	}
	else
	{
		current_emv_mode = atoi(value);
	}

	//inicia el archivo de trazas
	openTraceLog();
	//
	result = 0;
	return result;
}

void setMode() {
	flag_developer_mode = MODE_REAL;//MODE_REAL, MODE_EMULATION_ALL, MODE_EMULATION_READ, MODE_EMULATION_WRITE
}

void setTrace() {
	if (flag_developer_mode == MODE_EMULATION_ALL || flag_developer_mode == MODE_EMULATION_READ  || flag_developer_mode == MODE_DEMO)
	{
		APP_STATUS.flag_hasBines = 1;
		//emulation_recv_len = 1 + 1; memcpy(emulation_recv_trace, emulation_enq, emulation_recv_len);
		//emulation_recv_len = 41 + 1; memcpy(emulation_recv_trace, emulation_initialization, emulation_recv_len);
		//emulation_recv_len = 3384 + 49; memcpy(emulation_recv_trace, hello_world_app, emulation_recv_len);
		//emulation_recv_len = 520; memcpy(emulation_recv_trace, q7part, emulation_recv_len);		
		//emulation_recv_len = 47 + 1; memcpy(emulation_recv_trace, emulation_q8, emulation_recv_len);
		//emulation_recv_len = 50 + 1; memcpy(emulation_recv_trace, emulation_z4, emulation_recv_len);
		//emulation_recv_len = 175; memcpy(emulation_recv_trace, emulation_c51, emulation_recv_len);
		//CONTACT/CONTACTLESS NO SOLICITA FECHA DE VENCIMIENTO PERO SI CVV
		emulation_recv_len = 177; memcpy(emulation_recv_trace, emulation_c51_EGB_C2_TransType_7, emulation_recv_len);
		//emulation_recv_len = 15; memcpy(emulation_recv_trace, emulation_z10_failz11, emulation_recv_len);
		//emulation_recv_len = 38; memcpy(emulation_recv_trace, emulation_z2, emulation_recv_len);
		//emulation_recv_len = 220; memcpy(emulation_recv_trace, emulation_z10_guide, emulation_recv_len);
		//emulation_recv_len = 43; memcpy(emulation_recv_trace, emulation_c54, emulation_recv_len);
		//emulation_recv_len = 0; memcpy(emulation_recv_trace, emulation_CONTROL_CHARACTER, emulation_recv_len);
		//emulation_recv_len = 51; memcpy(emulation_recv_trace, emulation_z10_ECR_DISCONNECT, emulation_recv_len);
		//FALLA INIC LLAVE CHECK VALUE ERROR
		//emulation_recv_len = 92 + 1; memcpy(emulation_recv_trace, emulation_z10_ECR_FAIL, emulation_recv_len);
		//emulation_recv_len = 38049; memcpy(emulation_recv_trace, q7_app_clone, emulation_recv_len);
		//emulation_recv_len = 7; memcpy(emulation_recv_trace, test_q2, emulation_recv_len);
		//emulation_recv_len = 13; memcpy(emulation_recv_trace, emulation_z10_72, emulation_recv_len);
		//emulation_recv_len = 13; memcpy(emulation_recv_trace, emulation_z10_72, emulation_recv_len);
		//emulation_recv_len = 167; memcpy(emulation_recv_trace, emulation_c51_EGB_C2_FAIL, emulation_recv_len);
		
		//NO SOLICITA CVV O FECHA DE VENCIMIENTO
		//emulation_recv_len = 175; memcpy(emulation_recv_trace, emulation_c51_EGB_C2_AMEX, emulation_recv_len);
		//NO SOLICITA FECHA DE VENCIMIENTO PERO SI CVV
		//emulation_recv_len = 177; memcpy(emulation_recv_trace, emulation_c51_EGB_C2_TransType_7, emulation_recv_len);
		//FORMATO C51 NO VALIDO
		//emulation_recv_len = 85; memcpy(emulation_recv_trace, C1_FORMAT_ERROR, emulation_recv_len);
		//TX_TYPE NO VALIDO
		//emulation_recv_len = 175; memcpy(emulation_recv_trace, emulation_c51_TransType_INVALID, emulation_recv_len);
		//COMANDO NO VALIDO
		//emulation_recv_len = 5; memcpy(emulation_recv_trace, emulation_c52_COMMAND_INVALID, emulation_recv_len);
		//FALLBACK
		//emulation_recv_len = 299; memcpy(emulation_recv_trace, fallback, emulation_recv_len);
		//C14
		//emulation_recv_len = 506; memcpy(emulation_recv_trace, emulation_C14, emulation_recv_len);
		//emulation_recv_len = 252; memcpy(emulation_recv_trace, emulation_c51_2, emulation_recv_len);
		//emulation_recv_len = 335; memcpy(emulation_recv_trace, emulation_c51_3, emulation_recv_len);
		//emulation_recv_len = 175; memcpy(emulation_recv_trace, emulation_c51_CVV, emulation_recv_len);
		//emulation_recv_len = 341; memcpy(emulation_recv_trace, emulation_c51_FAILS, emulation_recv_len);
		//emulation_recv_len = 124; memcpy(emulation_recv_trace, emulation_c51_TIMEOUT, emulation_recv_len);
		//
		//emulation_recv_len = 115; memcpy(emulation_recv_trace, emulation_z10, emulation_recv_len);
		//emulation_recv_len = 38; memcpy(emulation_recv_trace, emulation_z2BadLRC, emulation_recv_len);
		//emulation_recv_len = 169; memcpy(emulation_recv_trace, emulation_c51_TXN_DIGITADA_ERROR03, emulation_recv_len);
		//emulation_recv_len = 83; memcpy(emulation_recv_trace, emulation_c51_ERROR_DENIAL_CAJA2, emulation_recv_len);

		//emulation_recv_len = 175; memcpy(emulation_recv_trace, emulation_c51_EGB_C2, emulation_recv_len);
		
		emulation_recv_len = 115; memcpy(emulation_recv_trace, emulation_z10, emulation_recv_len);
		
		//emulation_recv_len = 240; memcpy(emulation_recv_trace, emulation_z4_c51_EGB_C2_TransType_7, emulation_recv_len);
		//emulation_recv_len = 54; memcpy(emulation_recv_trace, emulation_c25c12, emulation_recv_len);
		//emulation_recv_len = 7; memcpy(emulation_recv_trace, emulation_Q5_CIERRE, emulation_recv_len);
		//emulation_recv_len = 37; memcpy(emulation_recv_trace, emulation_z10_resp_z11_sin_respuesta, emulation_recv_len);
		//emulation_recv_len = 383; memcpy(emulation_recv_trace, emulation_c14_eglobal, emulation_recv_len);
		
		//emulation_recv_len = 231; memcpy(emulation_recv_trace, emulation_c51_TransType_7_C25_C12, emulation_recv_len);
		//emulation_recv_len = 396; memcpy(emulation_recv_trace, emulation_c51_TransType_7_C25_7Scripts_C12, emulation_recv_len);
		//emulation_recv_len = 7; memcpy(emulation_recv_trace, emulation_Q5_APERTURA, emulation_recv_len);
		//emulation_recv_len = 520; memcpy(emulation_recv_trace, q7part, emulation_recv_len);
		//emulation_recv_len = 7; memcpy(emulation_recv_trace, Z11_Estado_99, emulation_recv_len);
		
		
	}
}

void initStatusAndFlags() {
	uchar value[64];
	unsigned char Display[120];

	memset(Display, 0, sizeof(Display));
	memset(APP_STATUS.title,0,128);

	//Recover display TITLE
	if(GetEnv(ENV_DISTITLE, Display) == 0 && memcmp((char *)Display, "__NULL__", 8)!=0)
	{
		memcpy(APP_STATUS.title, Display, strlen((char *)Display));
	}
	
	APP_STATUS.current_status = STATUS_WAIT;
	APP_STATUS.current_process = PROCESS_INIT;
	APP_STATUS.current_substatus = SUBSTATUS_ENQ;
	APP_STATUS.current_command = _NONE;
	current_wait_command = _NONE;
	APP_STATUS.current_error_code = ERROR_NONE;
	cleanBuff(APP_STATUS.command_data, sizeof(APP_STATUS.command_data));
	APP_STATUS.processTimeOut = PROCESS_TIMEOUT;
	APP_STATUS.command_data_len = 0;
	cleanBuff((uchar*)APP_STATUS.binesid_data, sizeof(APP_STATUS.binesid_data));
	APP_STATUS.current_binesid_version = 0;
	
	// Se limpian los datos de la sesión de operador
	APP_STATUS.flag_operatorSesion = FALSE;
	memset(APP_STATUS.operatorPAN, 0, 16);
	memset(APP_STATUS.lastPAN, 0, 16);
	cleanBuff(emulation_recv_trace, sizeof(emulation_recv_trace));
	APP_STATUS.flag_isInit = 0;
	APP_STATUS.flag_hasBines = 0;
	//recupera Z3 guardado
	memset(value, 0, sizeof(value));
	if (GetEnv(ENV_Z3_ID, value) == 0)
	{
		memcpy(APP_STATUS_OTHERS.binesid_z3, value, 9);
	} else {
		memset(APP_STATUS_OTHERS.binesid_z3, 0, sizeof(APP_STATUS_OTHERS.binesid_z3));
		memset(APP_STATUS_OTHERS.binesid_z3, '0', 8);
	}
	//
	memset(APP_STATUS_OTHERS.binesver_loader, 0, 3);
	memset(APP_STATUS_OTHERS.binesid_loader, 0, 9);
	if (GetEnv(ENV_BINES_VERSION, value) != 0 || (strlen((char*)value) == 0) || (PubStrNoCaseCmp(value,"00") == 0))
	{
		APP_STATUS_OTHERS.flag_hasBinesLoader = FALSE;
		strcpy((char*)APP_STATUS_OTHERS.binesver_loader, "00");
	}
	else {
		APP_STATUS_OTHERS.flag_hasBinesLoader = TRUE;
		memcpy(APP_STATUS_OTHERS.binesver_loader, value, 2);
		//carga el id de bines cargados
		GetEnv(ENV_BINES_ID, value);
		memcpy(APP_STATUS_OTHERS.binesid_loader, value, 8);
		//recupera la tabla de bines de archivo
		//readBinesTable(&APP_STATUS_OTHERS.binesTable);
	}
	APP_STATUS_OTHERS.flag_z4 = FALSE;
	
	// Se inicializan las estructuras correspondientes alos scripts
	APP_STATUS_SCRIPTS.scriptData.headerLength = 7;
	sprintf((char*)APP_STATUS_SCRIPTS.scriptData.header, "9F180400000000");
	//
	waitCommandActive(FALSE);
	sendActive(FALSE);
	resetChannelActive(FALSE);
	APP_STATUS.gl_stSupportDRL = FALSE;// TRUE;
	APP_STATUS.gl_stSecondTransaction = FALSE;

	//borrar archivos de basura
	if (fexist(FILE_LOG_TRACE))
	{
		remove(FILE_LOG_TRACE);
	}
	if (fexist("emvCAPK.dat"))
	{
		remove("emvCAPK.dat");
	}
	if (fexist("EMVSTATUS.DAT"))
	{
		remove("EMVSTATUS.DAT");
	}
	if (fexist("kAppList.dat"))
	{
		remove("kAppList.dat");
	}
}

void paintInitScreen() {
char  MSG2[60];
int iRet, index;
char COLORARRAY[6][4], BGCOLOR[4];
uint COLOR;
char VerInfo[60];
uchar TipoLLave[10+1]={0};
uchar EW[548];

	PintaGif(GIF_VIERGE);
	//PINTA LA PANTALLA DE INICIO
	index = 0;
	COLORARRAY[index][0] = 146; COLORARRAY[index][1] = 65; COLORARRAY[index][2] = 0; COLORARRAY[index][3] = 0;
	COLOR = *(int *)COLORARRAY[0];
	CLcdSetFgColor(COLOR);

	//Se muestra pantalla de Bienvenida
	memset(MSG2, 0, sizeof(MSG2));
	sprintf(MSG2, MSG_WELCOMEL2, CURRENT_VERSION);
	paintCenterLineOriginal(MSG2, 0, 0, -1);
	memset(VerInfo, 0, sizeof(VerInfo));
	ReadVerInfo((uchar *)VerInfo); 
	memset(MSG2, 0, sizeof(MSG2));
	sprintf(MSG2, "Monitor OS %d.%d", VerInfo[1], VerInfo[2]);
	paintCenterLineOriginal(MSG2, 0, 0, 0);
	memset(VerInfo, 0, sizeof(VerInfo));
	EMV_II_ReadVerInfo(VerInfo); 
	memset(MSG2, 0, sizeof(MSG2));
	sprintf(MSG2, "Kernel v650");//%s", VerInfo);
	paintCenterLineOriginal(MSG2, 0, 0, 1);
	memset(MSG2, 0, sizeof(MSG2));
	sprintf(MSG2, "Build %s %s", __DATE__, __TIME__);
	paintCenterLineOriginal(MSG2, 0, 0, 2);

	iRet = makeTokenEW(EW, TipoLLave);
	if(iRet==RET_OK)
	{
		if(	memcmp(TipoLLave, "DESARROLLO", 10)==0	)
			paintCenterLineOriginal("DESARROLLO", 0, 0, 4);
	}
	else if (iRet == ERROR_RSAKEYNOTEXIST)
	{
		paintCenterLineOriginal("LLAVE RSA NO EXISTE", 0, 0, 4);
	}
	
	//CLcdBgDrawImg(60,0,"ViergeGroup.jpg");
	//FsRecycle(STACK_SIZE_MEMORY);

	DelayMs(DELAY_WELCO_MESSAGE);
	PintaGif(GIF_NULO);
	BGCOLOR[0] = 250; BGCOLOR[1] = 250; BGCOLOR[2] = 250; BGCOLOR[3] = 0;
	COLOR = *(int *)BGCOLOR;
	iRet = CLcdBgDrawBox(0, 0, 319, 199, COLOR); 
	clearScr();
	//GifActual = 0;
}

#define TOTAL_OPTIONS 9
#define ITEMS_PER_PAGE 4


const char* opciones[TOTAL_OPTIONS] = {
	"Otro # cuotas",
	"12345678901234",
	"Otro Nº cuotas",
	"Otro N# cuotas",
	"Opcion 5",
	"Opcion 6",
	"Opcion 7",
	"Opcion 8",
	"Opcion 9"
};


const char* opciones2[TOTAL_OPTIONS] = {
	"Opcion 1",
	"1234567890123456789",
	"Otro Nº cuotas",
	"Otro N# cuotas",
	"Opcion 5",
	"Opcion 6",
	"Opcion 7",
	"Opcion 8",
	"Opcion 9"
};

#include <string.h>
#include <stdio.h>
#include "posapi.h"
#include "appLib.h"

#define TOTAL_OPTIONS 9
#define ITEMS_PER_PAGE2 6


void MostrarMenuPaginado()
{
	int pageIndex = 0;
	int totalPages = (TOTAL_OPTIONS + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE;
	int seleccion = 0;
	int key;

	while (1)
	{
		ScrCls();

		ScrFontSet(2);    
		int columnas = 16;

		
		const char* titulo = " MENU PRINCIPAL ";
		int titulo_len = strlen(titulo);
		int titulo_x = (columnas - titulo_len) / 2;
		ScrAttrSet(1);
		ScrGotoxy(titulo_x, 0);
		Lcdprintf("%s", titulo);
		ScrAttrSet(0);
		
		int start = pageIndex * ITEMS_PER_PAGE;
		int end = start + ITEMS_PER_PAGE;
		if (end > TOTAL_OPTIONS) end = TOTAL_OPTIONS;

		int y_base = 2;       
		int y_step = 2;       
		int i = 0;
		for (i = start; i < end; ++i)
		{
			char linea[32];
			snprintf(linea, sizeof(linea), "%d.%s", i + 1, opciones[i]);
			int len = strlen(linea);
			int x = (columnas - len) / 2;
			int y = y_base + (i - start) * y_step; 
			ScrGotoxy(x, y);
			Lcdprintf("%s", linea);
		}

		
		ScrSetIcon(ICON_UP, (pageIndex > 0) ? OPENICON : CLOSEICON);
		ScrSetIcon(ICON_DOWN, (pageIndex < totalPages - 1) ? OPENICON : CLOSEICON);

		key = getkey();

		if (key == KEYUP || key == GUI_KEYPREV)
		{
			if (pageIndex > 0) pageIndex--;
		}
		else if (key == KEYDOWN || key == GUI_KEYNEXT)
		{
			if (pageIndex < totalPages - 1) pageIndex++;
		}
		else if (key >= KEY1 && key <= KEY9)
		{
			seleccion = key - KEY0;
			if (seleccion > start && seleccion <= end)
			{
				
				ScrCls();      
				ScrFontSet(2); 
				char msg1[] = "ha seleccionado";
				char msg2[32];
				snprintf(msg2, sizeof(msg2), "la opcion %d", seleccion);

				
				int x1 = (columnas - strlen(msg1)) / 2;
				int x2 = (columnas - strlen(msg2)) / 2;
				ScrGotoxy(x1, 2);
				Lcdprintf("%s", msg1);
				ScrGotoxy(x2, 4);
				Lcdprintf("%s", msg2);

				DelayMs(2000); 

				break;
			}
		}
		else if (key == KEYCANCEL)
		{
			seleccion = 0;


			break;
		}
	}
	ScrSetIcon(ICON_UP, CLOSEICON);
	ScrSetIcon(ICON_DOWN, CLOSEICON);
}

#define ITEMS_PER_PAGE3 6

void MostrarMenuPaginado3()
{
	int pageIndex = 0;
	int totalPages = (TOTAL_OPTIONS + ITEMS_PER_PAGE3 - 1) / ITEMS_PER_PAGE3;
	int seleccion = 0;
	int key;
	int columnas = 16; 

	while (1)
	{
		ScrCls();
		ScrFontSet(0); 

		
		ScrAttrSet(1);
		ScrGotoxy((columnas - 17) / 2, 0); // "   MENU PRINCIPAL   " = 17 chars
		Lcdprintf("   MENU PRINCIPAL   ");
		ScrAttrSet(0);

		
		int start = pageIndex * ITEMS_PER_PAGE3;
		int end = start + ITEMS_PER_PAGE3;
		if (end > TOTAL_OPTIONS) end = TOTAL_OPTIONS;
		int i;
		for ( i = start; i < end; ++i)
		{
			int y = 2 + (i - start) * 2; 
			ScrGotoxy(2, y);
			Lcdprintf("%d. %s", i + 1, opciones2[i]);
		}

		ScrSetIcon(ICON_UP, (pageIndex > 0) ? OPENICON : CLOSEICON);
		ScrSetIcon(ICON_DOWN, (pageIndex < totalPages - 1) ? OPENICON : CLOSEICON);

		key = getkey();

		if (key == KEYUP || key == GUI_KEYPREV)
		{
			if (pageIndex > 0)
				pageIndex--;
		}
		else if (key == KEYDOWN || key == GUI_KEYNEXT)
		{
			if (pageIndex < totalPages - 1)
				pageIndex++;
		}
		else if (key >= KEY1 && key <= KEY9)
		{
			seleccion = key - KEY0;
			if (seleccion > start && seleccion <= end)
			{
				ScrCls();
				ScrFontSet(2);
				char msg1[] = "ha seleccionado";
				char msg2[32];
				snprintf(msg2, sizeof(msg2), "la opcion %d", seleccion);
				int x1 = (columnas - strlen(msg1)) / 2;
				int x2 = (columnas - strlen(msg2)) / 2;
				ScrGotoxy(x1, 2);
				Lcdprintf("%s", msg1);
				ScrGotoxy(x2, 4);
				Lcdprintf("%s", msg2);
				DelayMs(2000);
				break;
			}
		}
		else if (key == KEYCANCEL)
		{
			seleccion = 0;
			break;
		}
	}
}




void MostrarMenuPaginado2()
{
	int pageIndex = 0;
	int totalPages = (TOTAL_OPTIONS + ITEMS_PER_PAGE2 - 1) / ITEMS_PER_PAGE2;
	int seleccion = 0;
	int key;
	int columnas = 16; 
	while (1)
	{
		
		ScrCls();     
		ScrFontSet(0);
		
		ScrAttrSet(1);
		ScrGotoxy(2, 0);
		Lcdprintf("   MENU PRINCIPAL   ");
		ScrAttrSet(0);
		
		int start = pageIndex * ITEMS_PER_PAGE2;
		int end = start + ITEMS_PER_PAGE2;
		if (end > TOTAL_OPTIONS) end = TOTAL_OPTIONS;

		int i = 0;
		for ( i = start; i < end; ++i)
		{
			ScrGotoxy(2, 2 + (i - start)); 
			Lcdprintf("%d.%s", i + 1, opciones2[i]);
		}

		
		ScrSetIcon(ICON_UP, (pageIndex > 0) ? OPENICON : CLOSEICON);
		ScrSetIcon(ICON_DOWN, (pageIndex < totalPages - 1) ? OPENICON : CLOSEICON);

		
		key = getkey();

		if (key == KEYUP || key == GUI_KEYPREV)
		{
			if (pageIndex > 0)
				pageIndex--;
		}
		else if (key == KEYDOWN || key == GUI_KEYNEXT)
		{
			if (pageIndex < totalPages - 1)
				pageIndex++;
		}
		else if (key >= KEY1 && key <= KEY9)
		{
			seleccion = key - KEY0; 
			if (seleccion > start && seleccion <= end)
			{
				
				ScrCls();     
				ScrFontSet(2);
				char msg1[] = "ha seleccionado";
				char msg2[32];
				snprintf(msg2, sizeof(msg2), "la opcion %d", seleccion);

				
				int x1 = (columnas - strlen(msg1)) / 2;
				int x2 = (columnas - strlen(msg2)) / 2;
				ScrGotoxy(x1, 2);
				Lcdprintf("%s", msg1);
				ScrGotoxy(x2, 4);
				Lcdprintf("%s", msg2);

				DelayMs(2000); 
				break;
			}
		}
		else if (key == KEYCANCEL)
		{
			
			seleccion = 0;
			break;
		}
	}

	
}

int main(void)
{
	uchar portOpenRet, firstExec;
	//uchar LAST_VERSION[32];
	char dato[20];
	uchar value[2]={0};
	int current_emv_mode;


#ifdef SP30
	if(GetUsbdMode() == 0)
	{
		SetUsbdMode(1);
		paintMessageDelayMs("Configurando USB, Modo CDC\r\n");
	}
#endif

	InitLogs();

	
	//TestCrytoKey();
	//Reboot();

	memset(dato, 0, 20);
	//
	firstExec = SystemInit();

	ushort time;
	GetRebootPromptTime(&time);

	if (time != 5)
	{
		int iRet;
		time = 5;
		SetRebootPromptTime(time);
	}

	uchar p_reboot_time[3] = { 0 };
	uint p_run_time;
	uchar p_sw;
	GetScheduledRebootTime(&p_reboot_time,&p_run_time,&p_sw);
	if (p_sw != 1 || p_reboot_time[0] != 0x04 || p_reboot_time[1] != 0x00 || p_reboot_time[2] != 0x00)
	{
		int iRet;
		p_sw = 1;
		p_reboot_time[0] = 0x04;
		p_reboot_time[1] = 0x00;
		p_reboot_time[2] = 0x00;
		SetScheduledRebootTime(&p_reboot_time,p_sw);
	}


	//EMV
	if(GetEnv(ENV_EMVCONF, value)!=0)
	{
#ifndef PRODUCCION_EMV
		current_emv_mode = 3; //Test y produccion
#else
		current_emv_mode = 1; //produccion
#endif
		sprintf(value, "%d", current_emv_mode);
		PutEnv(ENV_EMVCONF, value);
	}
	else
	{
		current_emv_mode=atoi(value); 
	}

	//Timeout = glSysParam.Timeout*100;
	InitEmv(FALSE);
	cleanTraceLog();

	/*ST_FONT prueba[10];
	int i, j;
	j = EnumFont(prueba, i);
	ScrCls();
	Lcdprintf("EnumFont %d %d", i, j);
	getkey();

	for (i == 0; i < j; i++)
	{
		ScrSelectFont(&prueba[i], &prueba[i]);
		ScrCls();
		Lcdprintf("ABCDEFGHIJKLMN %d", i);
		getkey();
	}*/

	//Elimina mensaje de error si PIN se solicita muy seguido
	PedSetIntervaltime(1, 1);
	//
	printf("EJECUCION DE PXSP30");
#ifndef DEBUG_LOG
	DEVICE_SetDebug(1, 0);
#endif
	//mantiene la luz de la pantalla siempre encendida
	ScrBackLight(2);
	loadMasterPubRSA();
	//ScrCls();
	loadConfiguration();
	cleanBuff((uchar*)APP_STATUS.title, 128);
	cleanBuff((uchar*)APP_STATUS.BDK0, 16);
	APP_STATUS.FLAG_MESSAGE_DELAY = FLAG_OFF;


	LOGGER(LOG_DEBUG, "MostrarMenuConPaginacion inicio");
	//MostrarMenuPaginado3();
	MostrarMenuPaginado2();
	MostrarMenuPaginado();
	LOGGER(LOG_DEBUG, "MostrarMenuConPaginacion fin");




	//pedDukptTest();
	paintInitScreen();
	
	// Se valida si se instalo un binario antes de la ejecución actual, de ser así se borran los datos sensibles 
	if (firstExec == 0x00 || getIntEnvData(ENV_FLAG_KEY_LOADED) == 0)
	{
		//paintMessageDelayMs("Borrando!");
		//getkey();
		cleanVersion();
	}





	while (1) {
		//Inicializa los valores de status y banderas
		initStatusAndFlags();
		//MODO DE DESARROLLO
		setMode();
		//
		APP_STATUS.flag_NAKCounter = 0;
		current_SerialFileSeek = 0;
		flag_emulation_recv_counter = 0;
		process_init_count = 0;
		//Timeout = 0;
		//Muestra mensaje inicial
		//paintTitleDecorate(MSG_INIT);
		//TEST CONFIGURATION
		//current_channel = _CHANNELRS232;
		//current_exec_mode = _PROD;
		//Inicia el canal de comunicación
		//sprintf(dato, "Canal: %d", current_channel);
		//paintMessageDelayMs(dato);
		portOpenRet = openChannel(current_channel);
		//
		if (portOpenRet != APIPOS_OK) {
			showAPIPOSError(portOpenRet);
			APP_STATUS.current_error_code = ERROR_OPEN_PORT;
			paintStandarError();
			validateUserRequest();
			continue;
		}
		infoLog("carga la configuracion");
		//verifica si es necesario el proceso de emulacion
		setTrace();
		//Inicia la espera de comando
		initAppProcess();
		//asegura cerrar el canal de comunicación
		closeChannel(current_channel);
	}//end while

	return 0;
}


Editor is loading...
Leave a Comment