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

📄 fs.h

📁 这是用VB6.0写的一个通用的CPU卡操作程序,支持PC/SC接口 安装任何一个PC/SC驱动的IC读写器后,都可以使用此程序进行CPU卡的测试
💻 H
字号:
#ifndef FS__H/* ============================================================================   Project Name : jayaCard   Module Name  : proto/bios/fs/fs.h   Version : $Id: fs.h,v 1.48 2004/01/11 09:56:30 dgil Exp $	Description: This is File System API    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   040203 dgil	wrote it from bios.h   ============================================================================*/#define FS__H/* ============================================================================	File descriptor   ========================================================================= */#define FDESC_INTERNAL_EF		0x80	//内部EF#define FDESC_TYPE_DF			0x00	//DF文件#define FDESC_TYPE_BINARY		0x20	//二进制文件#define FDESC_TYPE_LINEAR		0x40	//定长记录文件#define FDESC_TYPE_CYCLIC		0x60	//循环记录文件#define FDESC_TYPE_MASK			0x60	#ifdef JAYA_TRANSACTION#define FDESC_TRANSACTIONAL		0x10	//事务处理#endif#ifdef JAYACFG_FILESYSTEM_ALIAS#define FDESC_SHAREABLE			0x08	//共享的#define FDESC_ALIAS				0x04	//别名的#endif#ifdef JAYACFG_FILESYSTEM_INVALIDATE#define FDESC_INVALIDATED		0x02#endif#define FDESC_UPDATE_ONCE       0x01    /* apply to binary EF only *//* ============================================================================	Specific SFI under our filesystem   ========================================================================= */#define SFI_NOTUSE		0x00	/* this EF has no SFI */#define SFI_CURRENT		0x00	/* current EF file */#define SFI_MASK		0x1F	/* mask for SFI validity *//* ============================================================================	Specific File Descriptor (bits 7 and 6 of the SFI field)	secure: if one of the FDESC2 bit is set, the BIOS will put write-only	restriction for the outside world.   ========================================================================= */#define	FDESC2_MASK			0xC0#define FDESC2_STANDARD		0x00	/* 标准的二进制文件 */#define FDESC2_KEYS			0x40	/* 这个二进制文件存放了一些密钥 */#define FDESC2_COUNTERS		0x80	/* 这个二进制文件存放了一些计数器 */#define FDESC2_TEMPLATE		0xC0	/* 这个二进制文件存放了一些模板(i.e. biometry) *//* ============================================================================	Specific FID under our filesystem   ========================================================================= */#define FID_BOGUS			0x0000#define FID_RFU				0xFFFF#define FID_CURRENT			0x3FFF#define FID_MF				0x3F00#define FID_SD				0x2F00	/* EF_SD System Directory */#define FID_KEYS			0x2F01	/* EF_Keys : 密钥文件和PIN文件 *//* ============================================================================	Header file   ========================================================================= *//* see /jayacard/proto/bios/fs/DESIGN */typedef struct tagHEADER_FILE {	jword	fid;			/* 0: 文件标识符 或 0xFFFF if erased/reusable header */	jbyte	fdesc;			/* 2: 文件描述 */	jbyte	sfi;			/* 3: [bit0-4 EF: SFI ; DF: SFI of the SD] [bit 7-6: file descriptor ext] */    jbyte   ac[3];          /* 4: Access Conditions */    jbyte   ac_key[3];      /* 7: Key/Pin to use for the Access Condition */	union {        jword   next_file;  /* 10: EF/DF: pointer on the next sibling EF/DF */        jword   default_df; /* 10: MF: pointer on the default selected DF */	} u2;	union {        jword   body_ef;    /* 12: EF: 指向EF文件体的指针 */        jword   alias;      /* 12: alias:pointer on the aliased */        jword   parent;     /* 12: DF:pointer on the parent DF */	} u3;	union {		struct {            jbyte   nummax; /* 14: EF:record: number max of records */            jbyte   size;   /* 15: EF:record: size of a record */		} record;        jword   sizefile;   /* 14: EF:transparent: size of the file */        jword   first_file; /* 14: MF/DF: pointer on the first child EF/DF */	} u4;	union {		struct {            jbyte   num;    /* 16: EF:record: 在使用的记录数 */            jbyte   top;    /* 17: EF:cyclic: 最上边的记录 */		} record;		jword		numEF;	/* 16: DF: EF文件数 */	} u5;    jword   crc;            /* 18: CRC of this header */} HEADER_FILE;#define SIZE_HEADER_FILE    20/* ============================================================================	Current Header File with API   ========================================================================= *//* current_<xxx>_addr value when no file selected */#define NO_CURRENT_FILE		0x0000/* current DF header */GLOBAL_XDATA(HEADER_FILE,current_DF);GLOBAL_XDATA(jword,current_DF_addr);/* current EF header */GLOBAL_XDATA(HEADER_FILE,current_EF);GLOBAL_XDATA(jword,current_EF_addr);/* EF or DF header file for specific operations */GLOBAL_XDATA(HEADER_FILE,header_file);GLOBAL_XDATA(jword,header_file_addr);/* eventually close the current session and go back to the MF */void __fs_new_session(jbool bResetAlsoDF,jbool bSelMF);#define FS_NEW_SESSION(bResetAlsoDF,bSelMF)		__fs_new_session(bResetAlsoDF,bSelMF)/* save and restore current_EF context to/from header_file context */void __fs_save_EF_context(void);#define FS_SAVE_EF_CONTEXT()    __fs_save_EF_context()void __fs_restore_EF_context(void);#define FS_RESTORE_EF_CONTEXT() __fs_restore_EF_context()/* ============================================================================	Current Streams   ========================================================================= */GLOBAL_IDATA(BIOS_STREAM,streamSrc);GLOBAL_IDATA(BIOS_STREAM,streamDest);/* ============================================================================	File Access Conditions Rules		8 4 2 1		0 0 0 0		never		0 0 0 1		pin		0 0 1 0     authenticate		0 0 1 1		pin AND authenticate		0 1 0 0		secure messaging (ISO)		0 1 0 1		pin AND secure messaging		0 1 1 0		pin OR authenticate        0 1 1 1     pin CHV2		1 0 0 0		picoseal		1 0 0 1		prior pin		1 0 1 0		extension		1 0 1 1		prior pin AND authenticate		1 1 0 0		secure messaging (GP) - unsupported by default		1 1 0 1		prior pin AND secure messaging		1 1 1 0		prior pin OR authenticate		1 1 1 1		always   ========================================================================= */#define ACR_NEVER				0x00#define ACR_PIN					0x01#define ACR_AUTH				0x02#define ACR_PIN_AND_AUTH		0x03#define ACR_SM					0x04#define ACR_PIN_AND_SM			0x05#define ACR_PIN_OR_AUTH			0x06#define ACR_PIN_CHV2            0x07#define ACR_PICOSEAL			0x08#define ACR_PRIOR_PIN			0x09#define ACR_EXT					0x0A#define ACR_PRIOR_PIN_AND_AUTH	0x0B#define ACR_CHANNEL_GP			0x0C#define ACR_PRIOR_PIN_AND_SM	0x0D#define ACR_PRIOR_PIN_OR_AUTH	0x0E#define ACR_ALWAYS				0x0F/* ============================================================================	File Access Condition ClassesFileType            ACS[0]                      ACS[1]                      ACS[2]DF              LOOKUP  CREATE FILE     DELETE DF   DELETE FILE     INVALIDATE REHABILITATEEF BINARY       READ    UPDATE          DELETE EF   ERASE           INVALIDATE REHABILITATEEF RECORD       READ    UPDATE          DELETE EF   APPEND          INVALIDATE REHABILITATEEF KEYS         n.a.    UPDATE          DELETE EF   USE             INVALIDATE REHABILITATEEF COUNTERS     READ    INCREASE        DELETE EF   DECREASE        INVALIDATE REHABILITATEEF TEMPLATE     n.a.    UPDATE          DELETE EF   USE             INVALIDATE REHABILITATE   ========================================================================= */#define ACC_LOOKUP          0x00    /* lookup file in a DF */#define ACC_READ            0x00    /* read file content */#define ACC_CREATE_FILE     0x01    /* create a file in a DF */#define ACC_UPDATE          0x01    /* write, update or erase file content */#define ACC_INCREASE        0x01    /* increase a counter */#define ACC_DELETE          0x02    /* delete file itself */#define ACC_DELETE_FILE     0x03    /* delete a file in a DF */#define ACC_APPEND          0x03    /* append a record */#define ACC_DECREASE        0x03    /* decrease a counter */#define ACC_ERASE           0x03    /* erase binary file content */#define ACC_USE             0x03    /* use a template */#define ACC_INVALIDATE      0x04#define ACC_REHABILITATE    0x05#define ACC_MASK            0x0F#define ACC_CHECK_DF		0x10	/* check ACS on the current DF */#define ACC_CHECK_EF		0x00	/* check ACS on the current EF *//* ============================================================================    function to check File Access Conditions	secure: use the global semaphore   ========================================================================= */jbyte __fs_check_AC(jbyte acc);#define FS_CHECK_AC(acc)                __fs_check_AC(acc)/* ============================================================================    Mount MF	notes:		Some error code in lasterr if any problem.   ========================================================================= */void __fs_mount_MF(void);#define FS_MOUNT_MF()					__fs_mount_MF()/* ============================================================================    file EF and DF lookup by FID    notes:        Some error code in lasterr if any problem.   ========================================================================= */#define LOOKUP_MODE_DEFAULT      0x00#define LOOKUP_MODE_EF_ONLY      0x01#define LOOKUP_MODE_DF_ONLY      0x02void __fs_lookup_FID(jword fid,jbyte mode);#define FS_LOOKUP_FID(fid,mode)         __fs_lookup_FID(fid,mode)/* ============================================================================    other kind of lookup    notes:        Some error code in lasterr if any problem.   ========================================================================= *//* lookup by application name or AID (read the SD file) */void __fs_lookup_name(jbyte xdata* name,jbyte len,jbool bFirst);#define FS_LOOKUP_NAME(name,len,first)	__fs_lookup_name(name,len,first)/* lookup by SFI in the current DF */void __fs_lookup_SFI(jbyte sfi);#define FS_LOOKUP_SFI(sfi)				__fs_lookup_SFI(sfi)/* ============================================================================	Filesystem Bootstrap API   ========================================================================= */void __fs_bootstrap(jbyte npages);#define FS_BOOTSTRAP(b)	__fs_bootstrap(b)jbyte __fs_isbootstraped(void);#define FS_ISBOOTSTRAPED()	__fs_isbootstraped()/* ============================================================================	file EF and DF creation / deletion	notes: 		current_DF has been filled with a lookup (a SELECT FILE)		header_file has been filled with the command (CREATE/DELETE FILE)		Some error code in lasterr if any problem.   ========================================================================= */void __fs_create_file(void);#define FS_CREATE_FILE()			__fs_create_file()void __fs_delete_file(void);#define FS_DELETE_FILE()			__fs_delete_file()void __fs_erase_file(void);#define FS_ERASE_FILE()				__fs_erase_file()/* ============================================================================	file EF and DF selection	notes: 		current_DF has been filled with a previous select file		Some error code in lasterr if any problem.        test the INVALIDATED flag   ========================================================================= */void __fs_select_file_by_fid(jword fid,jbyte mode);#define FS_SELECT_FILE_BY_FID(fid,mode) __fs_select_file_by_fid(fid,mode)void __fs_select_file_by_sfi(jbyte sfi);#define FS_SELECT_FILE_BY_SFI(sfi)      __fs_select_file_by_sfi(sfi)/* ============================================================================	Record Management   ========================================================================= */#define SET_RECORD		0x00#define FIRST_RECORD	0x01#define LAST_RECORD		0x02#define NEXT_RECORD		0x03#define PREV_RECORD		0x04/* given a logical record number and a command, update the current physical record number */void __fs_set_record_EF(jbyte logrecnum,jbyte cmd);#define FS_SET_RECORD_EF(lrn,cmd)       __fs_set_record_EF(lrn,cmd)/* append a physical record and update both current_EF header and current   physical record number with the added record / note that header file   must be persisted after this call*/void __fs_append_record_EF(void);#define FS_APPEND_RECORD_EF()           __fs_append_record_EF()#define NO_CURRENT_RECORD	0x00/* current physical record number of the current file */GLOBAL_IDATA(jbyte,current_recnum);/* read current record */void __fs_read_record_EF(jbyte len);#define FS_READ_RECORD_EF(len)          __fs_read_record_EF(len)/* update current record */void __fs_update_record_EF(jbyte len,jbool bAfterAppend);#define FS_UPDATE_RECORD_EF(len,bAfterAppend)   __fs_update_record_EF(len,bAfterAppend)/* ============================================================================	Binary Files   ========================================================================= *//* read the file and output the bytes */void __fs_read_binary_EF(jword ofs,jbyte len);#define FS_READ_BINARY_EF(ofs,len)		__fs_read_binary_EF(ofs,len)/* get the bytes and write on the file */void __fs_update_binary_EF(jword ofs,jbyte len);#define FS_UPDATE_BINARY_EF(ofs,len)	__fs_update_binary_EF(ofs,len)/* erase the bytes from the offset to the end of the file */void __fs_erase_binary_EF(jword ofs);#define FS_ERASE_BINARY_EF(ofs)			__fs_erase_binary_EF(ofs)/* ============================================================================    Invalidate / Rehabilitate Files    On the current file (EF or DF)   ========================================================================= */#ifdef JAYACFG_FILESYSTEM_INVALIDATEvoid __fs_invalidate(void);#define FS_INVALIDATE()         __fs_invalidate()#endif#ifdef JAYA_FILESYSTEM_REHABILITATEvoid __fs_rehabilitate(void);#define FS_REHABILITATE()       __fs_rehabilitate()#endif/* ========================================================================= */#endif/* defined FS__H */

⌨️ 快捷键说明

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