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

📄 io.c

📁 开发源代码的CPU卡的COS源程序。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/bios/io/io.c   Version : $Id: io.c,v 1.15 2004/01/11 09:56:31 dgil Exp $	Description: input/output functions    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 - today we have an entry point !   ============================================================================*/#include "precomp.h"/* =========================================================================	__bios_send()	if_type==IF_TYPE_CONTACT		send or firstsend on T=0	if_type==IF_TYPE_CONTACTLESS		store in buffer / 0x60 manage WTX   ========================================================================= */void __bios_send(jbyte b){	#ifdef JAYACFG_CONTACT_INTERFACE	if (if_type==IF_TYPE_CONTACT) {		if (gOutBuffer.apdu.len==0) {			HAL_T0_FIRSTSEND(b);		}  else {			HAL_T0_SEND(b);		}		gOutBuffer.apdu.len++;	} else {	#endif		#ifdef JAYACFG_T0_WTX_DETECTION		if ( (b==0x60) && (gOutBuffer.apdu.len==0) ) {			/* first char is WTX -> so go for a wait */            BIOS_TCL_WTX();		} else {		#endif			/* check enough place ? */			if (gOutBuffer.apdu.len>=JAYACFG_APDU_LENGTH) {				LOG2("BIOS","__bios_send_buf(): not enough room in the buffer (%d vs %d)!",gOutBuffer.apdu.len+1,JAYACFG_APDU_LENGTH);				BIOS_SETERR(ERR_BUFFER_OVERFLOW);				return;			}			gOutBuffer.apdu.info[gOutBuffer.apdu.len] = b;			gOutBuffer.apdu.len++;		#ifdef JAYACFG_T0_WTX_DETECTION		}		#endif	#ifdef JAYACFG_CONTACT_INTERFACE	}	#endif}/* =========================================================================	__bios_send_buf()	if_type==IF_TYPE_CONTACT		send or firstsend on T=0	if_type==IF_TYPE_CONTACTLESS		store in buffer   ========================================================================= */void __bios_send_buf(jbyte xdata* buffer,jbyte len){	#ifdef JAYACFG_CONTACT_INTERFACE	if (if_type==IF_TYPE_CONTACT) {		while (len>0) {			if (gOutBuffer.apdu.len==0) {				HAL_T0_FIRSTSEND(*buffer);			}  else {				HAL_T0_SEND(*buffer);			}			gOutBuffer.apdu.len++;			buffer++;			len--;		}	} else {	#endif		/* check enough place ? */		if ((gOutBuffer.apdu.len+len)>JAYACFG_APDU_LENGTH) {			LOG2("BIOS","__bios_send_buf(): not enough room in the buffer (%d vs %d)!",gOutBuffer.apdu.len+len,JAYACFG_APDU_LENGTH);			BIOS_SETERR(ERR_BUFFER_OVERFLOW);			return;		}		while (len>0) {			gOutBuffer.apdu.info[gOutBuffer.apdu.len] = *buffer;			gOutBuffer.apdu.len++;			buffer++;			len--;		}	#ifdef JAYACFG_CONTACT_INTERFACE	}	#endif}/* =========================================================================	__bios_send_ins()	if_type==IF_TYPE_CONTACT		firstsend INS on T=0	if_type==IF_TYPE_CONTACTLESS		do nothing   ========================================================================= */#ifdef JAYACFG_CONTACT_INTERFACEvoid __bios_send_ins(void){	if (if_type==IF_TYPE_CONTACT) {		BIOS_SEND(INS);	}}#endif/* =========================================================================	__bios_send_Iins()	if_type==IF_TYPE_CONTACT		send !INS on T=0	if_type==IF_TYPE_CONTACTLESS		do nothing   ========================================================================= */#ifdef JAYACFG_CONTACT_INTERFACEvoid __bios_send_Iins(void){	if (if_type==IF_TYPE_CONTACT) {		BIOS_SEND(~INS);	}}#endif/* =========================================================================	__bios_receive()	if_type==IF_TYPE_CONTACT		receive directly on T=0	if_type==IF_TYPE_CONTACTLESS		load from the input buffer   ========================================================================= */jbyte __bios_receive(void){	#ifdef JAYACFG_CONTACT_INTERFACE	if (if_type==IF_TYPE_CONTACT) {		return HAL_T0_RECEIVE();	} else {	#endif		return gInBuffer.b[tcl_apdu++];	#ifdef JAYACFG_CONTACT_INTERFACE	}	#endif}/* =========================================================================	__bios_delayed_init()	Init the GetResponse buffer   ========================================================================= */void __bios_delayed_init(void){	BIOS_GETRESPONSE_CLA = CLA;	BIOS_GETRESPONSE_INS = INS;	BIOS_GETRESPONSE_LEN = 0;	BIOS_GETRESPONSE_OFS = JAYACFG_GETRESPONSE_OFFSET;	LOG4("DELAYED","__bios_delayed_init : CLA=%.2X INS=%.2X LEN=%.2X OFS=%.2X",			BIOS_GETRESPONSE_CLA,			BIOS_GETRESPONSE_INS,			BIOS_GETRESPONSE_LEN,			BIOS_GETRESPONSE_OFS		);}/* =========================================================================	__bios_delayed_send()	Fill the GetResponse buffer with a new byte   ========================================================================= */void __bios_delayed_send(jbyte b){	if (BIOS_GETRESPONSE_LEN>=JAYACFG_GETRESPONSE_MAXLEN) {		LOG2("BIOS","__bios_delayed_send(): not enough room in the buffer (%d vs %d)!",BIOS_GETRESPONSE_LEN,JAYACFG_GETRESPONSE_MAXLEN);		BIOS_SETERR(ERR_BUFFER_OVERFLOW);		return;	}	gOutBuffer.apdu.info[BIOS_GETRESPONSE_OFS++] = b;	BIOS_GETRESPONSE_LEN++;	LOG5("DELAYED","__bios_delayed_send : CLA=%.2X INS=%.2X newLEN=%.2X newOFS=%.2X byte=%.2X",			BIOS_GETRESPONSE_CLA,			BIOS_GETRESPONSE_INS,			BIOS_GETRESPONSE_LEN,			BIOS_GETRESPONSE_OFS,			b		);}/* =========================================================================	That's all folks !   ========================================================================= */

⌨️ 快捷键说明

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