⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startup.c

📁 开发源代码的CPU卡的COS源程序。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/cos/simu/startup.c   Version : $Id: startup.c,v 1.66 2004/01/11 09:56:32 dgil Exp $	Description: main simulator startup    The Original Code is jayaCard code.    The Initial Developer of the Original Code is Gilles Dumortier.	Portions created by the Initial Developer are Copyright (C) 2002-2004 the    Initial Developer. All Rights Reserved.    Contributor(s):    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    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.    You should have received a copy of the GNU General Public License    along with this program; see http://www.gnu.org/licenses/gpl.html   History Rev	Description   020203 dgil	wrote it from scratch   ============================================================================*/#include "precomp.h"/* ============================================================================	port number to listen   ========================================================================= */short	gPort = 2000;/* ============================================================================	the global socket to handle i/o with the simulator outisde world   ========================================================================= */SOCKET	socketCard;/* ============================================================================	main() for the card simulator   ========================================================================= */int main(int argc, char ** argv){	PSIMUMSG	msgR;	int			jmpret;	jresult		res;	/* hard-coded log setting */	LOG_ENABLE("COS");	LOG_DISABLE("SIMUDATA");	LOG_DISABLE("SIMUMSG");    LOG_DISABLE("TRANSACTION");	LOG_DISABLE("MSK");	LOG_ENABLE("BIOS");    LOG_ENABLE("TCL");	LOG_ENABLE("TCLFSM");    LOG_DISABLE("STREAM");	LOG_ENABLE("FS");    LOG_ENABLE("RECORD");    LOG_ENABLE("FSTOOLS");	LOG_DISABLE("HAL");	LOG_DISABLE("LOCK");	LOG_DISABLE("T0");	LOG_DISABLE("HARDWARE");	LOG_DISABLE("EEPROM");	LOG_ENABLE("ERROR");    LOG_ENABLE("CRYPTO");	LOG_ENABLE("SEQVAL");	LOG_DISABLE("EAUTH");	LOG_DISABLE("TAGLIFE");	LOG_DISABLE("DELAYED");    LOG_ENABLE("CHANGEKEY");    LOG_ENABLE("KEY");	LOG_ENABLE("PIN");    LOG_DISABLE("TLV");	LOG_DISABLE("simuXML");	LOG_ENABLE("Simu");	LOG_DISABLE("SimuVar");	/* after hard-coded log setting, check the command line ... */	jlog_parse_argv( argc, argv );	LOG("Simu", "Simulator started" );	res = init_socket();	if (res!=JY_OK) {		fprintf(stderr,"can't initialise the socket library ... exiting ...\n");		exit(-1);	}accept:	LOG1("Simu","waiting for socket connection on port %d ...", gPort);	res = accept_socket(gPort,&socketCard);	if (res!=JY_OK) {		fprintf(stderr,"error accepting a connection ... exiting ...\n");		simu_exit(-1);	}	/* start with a fresh eeprom after connecting a socket ... */	if (! __simu_load_eeprom(EEPROM_FILE_START) ) {		fprintf(stdout,"\n*** can't load the EEPROM content file ... initialize a new content ...\n");		if (! __simu_blank_eeprom() ) {			fprintf(stderr,"\n*** can't start the simulator ... errors with the EEPROM content files !\n");			simu_exit(-1);		}		/* sick of having useless eeprom000.bin files everywhere */		/* (void)__simu_save_eeprom(EEPROM_FILE_START); */	} else {		fprintf(stdout, "Using eeprom image eeprom%.3d.bin\n",  EEPROM_FILE_START );	}	jmpret = THROW_COLDRESET;	/* return here after a reset */reset:	try {		if (jmpret==THROW_COLDRESET) {			/* hard-reset */			rr_type = RR_COLDRESET;			LOG("COS","[COLDRESET]");			/* reset memory simulator, cleaning up the area */			gIDATA.resetAll(jtrue);			gXDATA.resetAll(jtrue);			/* by default, next reset will be warm */			jmpret = THROW_WARMRESET;			/* hard reset -> halt state is false */			#ifdef JAYACFG_CONTACTLESS_TYPEA			tcl_halt_state = jfalse;			#endif			#ifdef JAYACFG_CONTACTLESS_BAUDRATE			simu_baudrate_from_card = BAUDRATE_106;			simu_baudrate_to_card = BAUDRATE_106;			#endif		} else { /* jmpret==THROW_WARMRESET */			/* soft-reset */			rr_type = RR_WARMRESET;			LOG("COS","[WARMRESET]");			/* reset memory simulator, not cleaning up the area (try to catch some strange errors ...) */			gIDATA.resetAll(jfalse);			gXDATA.resetAll(jfalse);			#ifdef JAYACFG_CONTACTLESS_BAUDRATE			simu_baudrate_from_card = BAUDRATE_106;			simu_baudrate_to_card = BAUDRATE_106;			#endif			goto start;		}		/* wait a message */	wait:		res = receive_simumsg(socketCard,&msgR);		if (res!=JY_OK) {			/* __y XXX differenciate between socket error and simusmg of wrong type ! */			fprintf(stderr,"error receiving information on socketCard ... reconnecting ...\n");			close_socket( socketCard );			goto accept;		}		/* wait for POWERON - if other message, dispatch it, them wait POWERON */		if (msgR->h.kindof!=SIMUMSG_POWERON) {			__simu_dispatch(msgR);			goto wait;		}		if (msgR->h.param>2) msgR->h.param = 0;		/* on power-on, message parameter is the interface type */		switch (msgR->h.param) {			case 0:				#ifdef JAYACFG_CONTACT_INTERFACE				LOG("Simu", "Activate contact interface" );				if_type = IF_TYPE_CONTACT;				#endif				break;			case 1:				LOG("Simu", "Activate TypeA contactless interface" );				#ifdef JAYACFG_CONTACT_INTERFACE				if_type = IF_TYPE_CONTACTLESS;				#endif				#ifdef TCL_TYPEAB				tcl_type = TCL_TYPEA;				#endif				break;			case 2:				LOG("Simu", "Activate TypeB contactless interface" );				#ifdef JAYACFG_CONTACT_INTERFACE				if_type = IF_TYPE_CONTACTLESS;				#endif				#ifdef TCL_TYPEAB				tcl_type = TCL_TYPEB;				#endif				break;		}		/* remove the SIMUMSG message */		free_simumsg(msgR);start:		#ifdef JAYACFG_CONTACT_INTERFACE		if (if_type==IF_TYPE_CONTACT) {			/* 0x3B is sent here because in target card the interface auto-detection code			   will also send this byte to sense the contact			*/			HAL_T0_SEND(0x3B);		}		#endif		/* quick cos initialisation */		cos_init();		/* cos main */		if (if_type==IF_TYPE_CONTACT) {			/* long cos initialization */			cos_init2();			/* finish sending the ATR */			BIOS_ATR();			/* enter the COS command loop */			cos_main();		} else {			/* cos_init2(); -> will be called after receiving the RATS and before answering it */			/* cos_main(); -> will be called each time an IBLOCK is received */			if (tcl_type==TCL_TYPEA) {				/* low-level anticollision and selection */				HAL_TCL_ANTICOL_AND_SELECTA(gInBuffer.b);			} else {				BIOS_TCL_ANTICOL_AND_SELECTB();			}		}	} catch (int err) {		//LOG1("Simu","catch err=%d",err);		jmpret = err;	}	/* save the EEPROM content */	//LOG("Simu","save eeprom");	(void)__simu_save_eeprom(EEPROM_FILE_LATEST);	//LOG("Simu","save XML eeprom");	(void)__simu_save_XML_eeprom(EEPROM_FILE_LATEST);	/* warm/cold reset the simulator */	//LOG("Simu","warm/cold reset");	if (jmpret==THROW_WARMRESET) goto reset;	if (jmpret==THROW_COLDRESET) goto reset;	/* disconnect then cold warm */	//LOG("Simu","disconnect socket");	close_socket( socketCard );	/* be sure we're not exiting */	//LOG("Simu","acceptp");	if (jmpret!=THROW_EXIT) goto accept;	LOG("Simu", "Simulator exiting" );	return 0;}/* =========================================================================	That's all folks !   ========================================================================= */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -