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

📄 t1.c

📁 SecuDe是一个由安全应用程序接口组成,对验证机制、证件处理、PEM、X.400报文处理和密钥管理提供支持。SecuDe提供DES、 RSA杂凑函数、密钥生成以及数字签名的生成和核实等多种密码机制。
💻 C
字号:
/*-------------------------------------------------------+-----*//*                                                       | GMD *//*   SYSTEM   STAMOD  -  Version 2.0                     +-----*//*                                                             *//*-------------------------------------------------------------*//*                                                             *//*    PACKAGE   T1                      VERSION 2.00           *//*                                         DATE                *//*                                           BY Zhou           *//*                                                             *//*    FILENAME                                                 *//*    t1.c                                                     *//*                                                             *//*    DESCRIPTION      Procedures necessary for communicating  *//*                     with Smartcard Terminal.                *//*    Notice:                                                  *//*    1) For exchange of transmission control information,     *//*       it supports only resynchronization.  S(RESYNCH, ...)  *//*    2) For Error Detecte Code, LRC is used currently.        *//*    3) First block to be sent to SCT is a S(RESYNCH,request) *//*                                                             *//*    EXPORT                                                   *//*      COMinit()             Initiation of serial port        *//*                                                             *//*      COMreset()            Re-initiation of port            *//*                                                             *//*      COMtrans()            Communication with SCT           *//*                                                             *//*      tp1_err               Error number                     *//*                                                             *//*    USES                                                     *//*      Module from assembly  If define DOS                    *//*      routine siofunc.asm                                    *//*                                                             *//*      RS232_init()          Initiate RS232 interface         *//*                                                             *//*      sendstr()             To send string to RS232 interface*//*                                                             *//*      recestr()             To receive string from RS232     *//*                                                             *//*    INTERNAL                                                 *//*      COMsend()             To send a TPDU-request           *//*                                                             *//*      COMrece()             To receive a TPDU-response       *//*                                                             *//*      State_reset()         To reset sending and receiving   *//*                            state variables                  *//*                                                             *//*      blk_process()         To process TPDU-response and     *//*                            produce an appropriate block     *//*                                                             *//*      Resynch()             To resynchronize protocol        *//*                                                             *//*      blkvalidity()         To check validity of a block     *//*                                                             *//*      err_handle()          To produce an appropriate R_BLOCK*//*                                                             *//*      divi_blk()            To divide a block into small     *//*                            blocks                           *//*                                                             *//*      Is_lastblkResyResp()  To check whether the block last  *//*                            sent a S(RESYNCH,response).      *//*                                                             *//*      Is_ResynchResp()      Is a S(RESYNCH,response)         *//*                                                             *//*      getbits()             To read bits  in a integer       *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//*   include-Files                                             *//*-------------------------------------------------------------*/#include <stdio.h>#include <fcntl.h>#ifdef SUN#include <sys/types.h>#ifdef SYSV#include <termio.h>#else#include <sgtty.h>#endif#include <sys/time.h>#endif#ifdef __HP__#include <sys/types.h>#define	getdtablesize()	(20)#ifndef TIOCEXCL#define	TIOCEXCL	_IO('t', 13)		/* set exclusive use of tty */#endif#ifdef FD_ZERO#undef FD_ZERO#endif#define FD_ZERO(s)	    ((s)->fds_bits[0] = 0)#ifdef SYSV#include <termio.h>#else#include <sgtty.h>#endif#include <sys/time.h>#endif#ifdef MAC#include <files.h>#include <time.h>#include <types.h>#include <devices.h>#endif#include "protocol.h"#include "sca.h"#include "sctport.h"#include <error.h>/*-------------------------------------------------------------*//*   define informatin field size for PC                       *//*-------------------------------------------------------------*/#define IFSPC 254/*-------------------------------------------------------------*//*   Extern parameters definition                              *//*-------------------------------------------------------------*/int             tp1_err = 0;	/* To include error code        */#ifdef TRACEFILE           *tp1_trfp = NULL;/* File descriptor of TRACE     */#endif/*-------------------------------------------------------------*//*   Local variables declaration                               *//*-------------------------------------------------------------*/#ifdef SUN#ifdef SYSVstatic struct termio o_par, n_par;#elsestatic struct sgttyb o_par;static struct sgttyb n_par;#endif#endif				/* from SUN */#ifdef __HP__#ifdef SYSVstatic struct termio o_par, n_par;#elsestatic struct sgttyb o_par;static struct sgttyb n_par;#endif#endif				/* from __HP__ *//*-------------------------------------------------------------*//*   Declare extern assembly module                            *//*-------------------------------------------------------------*/#ifdef DOS/*-------------------------------------------------------------*//*   To initiate rs232 interface                               *//*-------------------------------------------------------------*/extern int far  RS232_init();/*-------------------------------------------------------------*//*   To send protocol block to rs232 interface                 *//*-------------------------------------------------------------*/extern int far  sendstr(int, char far *, int);/*-------------------------------------------------------------*//*   To receive protocol block from rs232 interface            *//*-------------------------------------------------------------*/extern int far  recestr(int, char far *, int, int);#endif#ifdef MAC/* is maybe obsolete */int COMinit(struct s_portparam *portpar);int COMreset(struct s_portparam *portpar);int COMclose(int fd);int COMtrans(struct s_portparam *, char *, int , char[], int *);#define MacOk 0static ParamBlockRec InBlock, OutBlock;#endif/*-------------------------------------------------------+-----*//*                                                       | GMD *//*   SYSTEM   STAMOD  -  Version 2.0                     +-----*//*                                                             *//*-------------------------------------------------------------*//*                                                             *//*    Procedure COMinit                 VERSION 2.00           *//*                                         DATE                *//*                                           BY Zhou           *//*                                                             *//*                                                             *//*    DESCRIPTION             Initiation of the serial port    *//*                                                             *//*    INOUT                                                    *//*      portpar               port parameter                   *//*                            port_id will be set.             *//*    OUT                                                      *//*                                                             *//*    RETURN                                                   *//*       0                    Ok                               *//*      -1                    Error                            *//*-------------------------------------------------------------*/int COMinit(portpar)	struct s_portparam *portpar;{	int             fd;	int             data_stru;	int             ret;#ifdef TRACE	if (tp1_trfp == NULL)		tp1_trfp = fopen("TRACE", "w");#endif#ifdef DOS	if (!strncmp("COM1", portpar->port_name, 4))		fd = 1;	else if (!strncmp("COM2", portpar->port_name, 4))		fd = 2;	else {		portpar->port_id = -1;		tp1_err = INVALID_PORT;		return (-1);	}	data_stru = portpar->databits | portpar->stopbits | (int) portpar->parity;	if ((ret = RS232_init(fd, portpar->baud, data_stru)) != TP1_OK) {		tp1_err = OPEN_ERR;#ifdef TRACE		fprintf(tp1_trfp, "error number=\n", tp1_err);#endif		return (-1);	}#endif#ifdef SUN	if ((fd = open(portpar->port_name, O_RDWR | O_NDELAY)) == -1) {		portpar->port_id = -1;		tp1_err = OPEN_ERR;#ifdef TRACE		fprintf(tp1_trfp, "  error = %x\n", tp1_err);#endif		return (-1);	}	/*	 *  Set "exclusive-use" mode: 	 *       no further opens are permitted until the file has been closed	 */		ioctl(fd, TIOCEXCL, &o_par);#ifdef SYSV	ioctl(fd, TCGETA, &o_par);	ioctl(fd, TCGETA, &n_par);	n_par.c_iflag = 0;	n_par.c_oflag = 0;	n_par.c_cflag = portpar->baud | portpar->databits | portpar->stopbits		| (int) portpar->parity | CREAD | CLOCAL;	n_par.c_lflag = 0;	ioctl(fd, TCSETAW, &n_par);#else	ioctl(fd, TIOCGETP, &o_par);	ioctl(fd, TIOCGETP, &n_par);	n_par.sg_ispeed = portpar->baud;	n_par.sg_ospeed = portpar->baud;	n_par.sg_flags = RAW;	ioctl(fd, TIOCSETP, &n_par);#endif#endif				/* from SUN */#ifdef __HP__	if ((fd = open(portpar->port_name, O_RDWR | O_NDELAY)) == -1) {		portpar->port_id = -1;		tp1_err = OPEN_ERR;#ifdef TRACE		fprintf(tp1_trfp, "  error = %x\n", tp1_err);#endif		return (-1);	}	/*	 *  Set "exclusive-use" mode: 	 *       no further opens are permitted until the file has been closed	 */		ioctl(fd, TIOCEXCL, &o_par);#ifdef SYSV	ioctl(fd, TCGETA, &o_par);	ioctl(fd, TCGETA, &n_par);	n_par.c_iflag = 0;	n_par.c_oflag = 0;	n_par.c_cflag = portpar->baud | portpar->databits | portpar->stopbits		| (int) portpar->parity | CREAD | CLOCAL;	n_par.c_lflag = 0;	ioctl(fd, TCSETAW, &n_par);#else	ioctl(fd, TIOCGETP, &o_par);	ioctl(fd, TIOCGETP, &n_par);	n_par.sg_ispeed = portpar->baud;	n_par.sg_ospeed = portpar->baud;	n_par.sg_flags = RAW;	ioctl(fd, TIOCSETP, &n_par);#endif#endif				/* from __HP__ */#ifdef MAC     fd = 1;          /* wird zwar bei MAC nicht gebraucht, mu

⌨️ 快捷键说明

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