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

📄 tcltypeb.c

📁 开发源代码的CPU卡的COS源程序。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/bios/tcl/tcltypeb.c   Version : $Id: tcltypeb.c,v 1.23 2004/01/11 09:56:31 dgil Exp $	Description: Type B support for the T=CL library    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   030803 dgil	wrote it from scratch   ============================================================================*/#include "precomp.h"#ifdef JAYACFG_CONTACTLESS_TYPEB/* ============================================================================	ROM tables (see tclrom.c)   ========================================================================= */extern jword code fsd[16];extern jbyte code slots[5];/* ============================================================================	tcl_fsmb_reqb()   ========================================================================= */jbyte tcl_fsmb_reqb(void){	/* wait for a valid message (REQB expected) */	do {		LOG("TCL","wait for REQB/WAKEB ...");		tcl_cnt = HAL_TCL_RECEIVE(gInBuffer.b,sizeof(gInBuffer),jtrue);	} while ((tcl_cnt==0) || (gInBuffer.b[0]!=TYPEB_REQB));	/* Check Family */	return TCL_FSMB_AFI;}/* ============================================================================	tcl_fsmb_afi()   ========================================================================= */jbyte tcl_fsmb_afi(void){	/* unexpected message length */	if (tcl_cnt!=5) {		LOG("TCL", "REQB too short" );		return TCL_FSMB_REQB;	}	/* check AFI - family specified ? */	if ((gInBuffer.b[1]&0xF0)!=0) {		/* family matching */		if ((gInBuffer.b[1]&0xF0) != JAYACFG_AFI_FAMS_X) {			LOG1("TCL", "Family does not match %d", JAYACFG_AFI_FAMS_X );			return TCL_FSMB_REQB;		}	}	if ((gInBuffer.b[1]&0x0F)!=0) {		/* subfamily matching */		if ((gInBuffer.b[1]&0x0F) != JAYACFG_AFI_FAMS_Y) {			LOG1("TCL", "Subfamily does not match %d", JAYACFG_AFI_FAMS_Y );			return TCL_FSMB_REQB;		}	}	/* unsupported function ? */	if ((gInBuffer.b[2]&0xF0)!=0) {		LOG("TCL", "Unsupported function" );		return TCL_FSMB_REQB;	}	if ((gInBuffer.b[2]&0x07)>4) {		LOG("TCL", "Bad slot number" );		return TCL_FSMB_REQB;	}	/* set the number of slots (N) */	tcl_nslot = slots[gInBuffer.b[2]&0x07];	if (tcl_nslot==1) {		/* send ATQB */		return TCL_FSMB_ATQB;	}	/* build the random slot number (R) */    tcl_rslot = (HAL_RANDOM_BYTE()%tcl_nslot)+1;    /* __r random -> chipUUID => determinist */	if (tcl_rslot==1) {		/* send ATQB */		return TCL_FSMB_ATQB;	}	/* send Wait for slot marker command */	return TCL_FSMB_SLOTMARKER;}/* ============================================================================	tcl_fsmb_slotmarker()   ========================================================================= */jbyte tcl_fsmb_slotmarker(void){	do {		/* wait for a valid message */		do {			LOG("TCL","wait for REQB/SLOT-MARKER  ...");			tcl_cnt = HAL_TCL_RECEIVE(gInBuffer.b,sizeof(gInBuffer),jtrue);		} while (tcl_cnt==0);		if (gInBuffer.b[0]==TYPEB_REQB) return TCL_FSMB_AFI;		/* unexpected message length */		if (tcl_cnt!=1) continue;		/* slot marker command ? */		if ((gInBuffer.b[0]&0xF)!=TYPEB_SLOT_MARKER) continue;		/* slot marker match ? */		if (((gInBuffer.b[0]>>4)+1)!=tcl_rslot) continue;		break;	} while (1);	/* slot marker match -> send ATQB */	return TCL_FSMB_ATQB;}/* ============================================================================	tcl_fsmb_atqb()   ========================================================================= */jbyte tcl_fsmb_atqb(void){    LOCAL(jbyte,bitratecap);    /* on some platform */	HAL_BOOST();    if ((cfg_config_flag1&CONFIG_FLAG1_CONFIG_BITRATECAP)==CONFIG_FLAG1_CONFIG_BITRATECAP) {        bitratecap = HAL_EEPROM_READ_BYTE(ADDR_CONFIG_BITRATECAP);    } else {        bitratecap = 0x80 | (JAYACFG_BITRATECAP&0x07) | ((JAYACFG_BITRATECAP&0x07)<<4);    }	HAL_TCL_INITSEND(TYPEB_ATQB);	/* send PUPI */	HAL_TCL_SENDBUF(chipUUID,4);	/* send AppliData */	HAL_TCL_SENDBUF(AppliData,4);	/* supported bit rates */    HAL_TCL_SEND(bitratecap);	/* maximum frame size */	HAL_TCL_SEND(((cfg_fsci&0x0F)<<4) | 0x01);	HAL_TCL_SEND(((cfg_fwi&0x0F)<<4) | 0x02 | 0x01);	HAL_TCL_SENDGO(jfalse);	return TCL_FSMB_ATTRIB;}/* ============================================================================	tcl_fsmb_attrib()   ========================================================================= */jbyte tcl_fsmb_attrib(void){	do {		/* wait for a valid message */		do {			LOG("TCL","wait for REQB/ATTRIB  ...");			tcl_cnt = HAL_TCL_RECEIVE(gInBuffer.b,sizeof(gInBuffer),jtrue);		} while (tcl_cnt==0);		if (gInBuffer.b[0]==TYPEB_REQB) return TCL_FSMB_AFI;		/* ATTRIB command */		if (gInBuffer.b[0]==TYPEB_ATTRIB) {			/* unexpected message length */			if (tcl_cnt<11) continue;			/* identifier match PUPI */			if (HAL_MEMCMP(&gInBuffer.b[1],chipUUID,4) == JSEC_FAIL) {				LOG8("TCL_FSMB","ATTRIB pupi %.2X%.2X%.2X%.2X does not match card uid %.2X%.2X%.2X%.2X", gInBuffer.b[1], gInBuffer.b[2], gInBuffer.b[3], gInBuffer.b[4], chipUUID[0],chipUUID[1],chipUUID[2], chipUUID[3] );				continue;			}			/* CID */			cos_cid = gInBuffer.b[8] & 0x0F;			if (cos_cid == 15) continue; 	/* CID unused */			/* baudrate */			tcl_baudrate = (gInBuffer.b[6]>>4)&0x03;			/* FSD */			tcl_fsd = MIN(fsd[gInBuffer.b[6]&0x0F],fsd[cfg_fsci]);			if (tcl_fsd == 0) {				LOG1("TCL","Unknown fsd size ! index=%.2X",gInBuffer.b[6]);				continue;			}			#ifdef JAYACFG_HLINF_FOR_TYPEB			if (tcl_cnt>11) {				/* high-layer info */				tcl_hl_info = jtrue;            } else {				tcl_hl_info = jfalse;			}			#endif			return TCL_FSMB_ANSWERATTRIB;		} else if (gInBuffer.b[0]==TYPEB_HALT) {			/* unexpected message length */			if (tcl_cnt<5) continue;			/* halt command - check identifier */			if (HAL_MEMCMP(&gInBuffer.b[1],chipUUID,4) == JSEC_FAIL) continue;			HAL_TCL_INITSEND(TYPEB_ANSWER_HALT);			HAL_TCL_SENDGO(jtrue);			/* goto halt */			break;		}	} while (1); /* repeat this state in all other cases */	return TCL_FSMB_HALT;}/* ============================================================================	tcl_fsmb_answerattrib()   ========================================================================= */jbyte tcl_fsmb_answerattrib(void){	LOG("TCL","tcl_fsmb_answerattrib");	/* second step of the cos_initialization can occur here	   __r check the timing required between ATTRIB and ANSWERATTRIB answer	*/	cos_init2();	/* MBLI=0 | tcl_cid */	HAL_TCL_INITSEND(tcl_cid);	/* high-layer info */	#ifdef JAYACFG_HLINF_FOR_TYPEB	if (tcl_hl_info) {	}	#endif	/* finish to send */	HAL_TCL_SENDGO(jtrue);	/* wait because next step will be a baudrate change ! */	/* change baudrate just after answering the frame */	HAL_TCL_SETBAUDRATE(tcl_baudrate&0x03);	/* goto active mode */	return TCL_FSMB_ACTIVE;}/* ============================================================================	tcl_fsm_active()   ========================================================================= */jbyte tcl_fsmb_active(void){	tcl_state = TCL_FSM_START;	BIOS_TCL_FSM();	return TCL_FSMB_HALT;}/* ============================================================================	tcl_fsmb_halt()   ========================================================================= */jbyte tcl_fsmb_halt(void){	/* wait for a valid message (WAKEB expected) */	do {		LOG("TCL","wait for WAKEB ...");		tcl_cnt = HAL_TCL_RECEIVE(gInBuffer.b,sizeof(gInBuffer),jtrue);	} while ((tcl_cnt==0) || (gInBuffer.b[0]!=TYPEB_REQB) || (tcl_cnt!=5) || ((gInBuffer.b[2]&0x08)==0));	/* Check Family */	return TCL_FSMB_AFI;}/* ============================================================================	fn_fsm[]   ========================================================================= */typedef jbyte (*FNB)(void);FNB code fn_fsmb[] = {	tcl_fsmb_reqb, 				/* TCL_FSMB_REQB */	tcl_fsmb_active,			/* TCL_FSMB_ACTIVE */	tcl_fsmb_halt,				/* TCL_FSMB_HALT */	tcl_fsmb_answerattrib,		/* TCL_FSMB_ANSWERATTRIB */	tcl_fsmb_attrib,			/* TCL_FSMB_ATTRIB */	tcl_fsmb_atqb,				/* TCL_FSMB_ATQB */	tcl_fsmb_slotmarker,		/* TCL_FSMB_SLOTMARKER */	tcl_fsmb_afi,				/* TCL_FSMB_AFI */	};/* ============================================================================	__bios_tcl_anticollisionB()   ========================================================================= */void __bios_tcl_anticollisionB(void){	/* on some platform */	HAL_BOOST();	tcl_state = TCL_FSMB_REQB;	do {		LOG1("TCL","__bios_tcl_anticollisionB() : state=%d\n",tcl_state);		if (tcl_state>=(sizeof(fn_fsmb)/sizeof(fn_fsmb[0]))) {			/* invalid state number */			HAL_HALT();		} else {			tcl_state = fn_fsmb[tcl_state]();		}	} while (1);	HAL_HALT();}/* =========================================================================	That's all folks !   ========================================================================= */#endif/* JAYACFG_CONTACTLESS_TYPEB */

⌨️ 快捷键说明

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