TokenCZ

 avatar
unknown
c_cpp
22 days ago
3.7 kB
7
Indexable
int makeTokenCZ(uchar outData[50]) { 
	uchar form_factr_indData[9];
	uchar form_factr_indTLV[32], form_factr_indAscii[65];
	uchar sATC[5], SER_FLD_ACI[29];
	int iLen=0;
	memset(form_factr_indTLV, 0, sizeof(form_factr_indTLV));
	if (APP_STATUS.currentCardRead.MsgType == PICC_MSG ) {
		LOGGER(LOG_DEBUG, "MsgType == PICC_MSG");
		//obtiene el Form Factor Indicator 
		Clss_GetTLVData(0x9F6E, form_factr_indTLV, &iLen, APP_STATUS.ucKernType);
		//inicializa los arreglos
		memset(form_factr_indData, 0, 9);
		memset(form_factr_indAscii, 0, 65);
		memset(SER_FLD_ACI, 0, 40);
		//convierte de BCD a ASCII
		logHexData("0x9F6E", form_factr_indTLV, iLen);

		if (iLen > 0)
		{
			if (form_factr_indTLV[2] & 0x80 && APP_STATUS.ucKernType == KERNTYPE_MC)
			{
				memset(sATC, 0, 5);
				PubBcd2Asc0(glProcInfo.stTranLog.sATC, 2, sATC);
				LOGGER(LOG_DEBUG, "ATC [%s]", sATC);
				//Rellena con espacios en blanco
				memset(SER_FLD_ACI, 0x20, 36);
				//
				sprintf((char*)outData, "! CZ%05d %-4s%-36s", 40, sATC, form_factr_indData, SER_FLD_ACI);
			}
			else
			{
				if (APP_STATUS.ucKernType == KERNTYPE_MC)
				{

					uchar deviceType[5];
					uchar RawdeviceType[5];
					memset(deviceType, 0, sizeof(deviceType));
					memset(RawdeviceType, 0, sizeof(RawdeviceType));
					memcpy(RawdeviceType, &form_factr_indTLV[4], 2);
					logHexData("deviceType", RawdeviceType, 2);
					//Se obtiene el device type
					PubBcd2Asc0(RawdeviceType, 2, deviceType);
					LOGGER(LOG_DEBUG, "Device Type [%s]", deviceType);
					//obtiene el Application Transaction Counter
					memset(sATC, 0, 5);
					PubBcd2Asc0(glProcInfo.stTranLog.sATC, 2, sATC);
					LOGGER(LOG_DEBUG, "ATC [%s]", sATC);
					//Rellena con espacios en blanco
					memset(SER_FLD_ACI, 0x20, 28);
					//
					sprintf((char*)outData, "! CZ%05d %-4s%-4s%-4s%-28s", 40, sATC, deviceType,"0000", SER_FLD_ACI);
				}
				else
				{
					PubBcd2Asc0(form_factr_indTLV, iLen, form_factr_indAscii);
					//Otiene solo los primeros 8 bytes de datos
					memcpy(form_factr_indData, form_factr_indAscii, 8);
					//obtiene el Application Transaction Counter
					memset(sATC, 0, 5);
					PubBcd2Asc0(glProcInfo.stTranLog.sATC, 2, sATC);
					LOGGER(LOG_DEBUG, "ATC [%s]", sATC);
					//Rellena con espacios en blanco
					memset(SER_FLD_ACI, 0x20, 28);
					//
					sprintf((char*)outData, "! CZ%05d %-4s%-8s%-28s", 40, sATC, form_factr_indData, SER_FLD_ACI);
				}
			}

		}
		else
		{
			memset(sATC, 0, 5);
			PubBcd2Asc0(glProcInfo.stTranLog.sATC, 2, sATC);
			LOGGER(LOG_DEBUG, "ATC [%s]", sATC);
			//Rellena con espacios en blanco
			memset(SER_FLD_ACI, 0x20, 36);
			//
			sprintf((char*)outData, "! CZ%05d %-4s%-36s", 40, sATC, form_factr_indData, SER_FLD_ACI);
		}
	
		return 50;
	}
	else if(APP_STATUS.currentCardRead.MsgType == ICCARD_MSG ) {
		LOGGER(LOG_DEBUG, "MsgType == ICCARD_MSG");
		//inicializa los arreglos
		memset(form_factr_indAscii, 0, 9);
		memset(SER_FLD_ACI, 0, 29);
		//obtiene el Application Transaction Counter
		memset(sATC, 0, 5);
		PubBcd2Asc0(glProcInfo.stTranLog.sATC, 2, sATC);
		//Rellena con espacios en blanco
		memset(SER_FLD_ACI, 0x20, 28);
		memset(form_factr_indAscii, 0x20, 8);
		//
		sprintf((char*)outData, "! CZ%05d %-4s%-8s%-28s", 40,sATC, form_factr_indAscii,SER_FLD_ACI);
		return 50;
	}
	else {
		LOGGER(LOG_DEBUG, "  ");
		//inicializa los arreglos
		memset(form_factr_indAscii, 0, 41);
		//Rellena con espacios en blanco
		memset(form_factr_indAscii, 0x20, 40);
		sprintf((char*)outData, "! CZ%05d %-40s", 40, form_factr_indAscii);
		return 50;
	}
}
Editor is loading...
Leave a Comment