📄 sta_r_w.c
字号:
/*---------------------------------------------------------------------------+-----*//* | GMD *//* SYSTEM STAPAC - Version 1.0 +-----*//* *//*---------------------------------------------------------------------------------*//* *//* PACKAGE STAMOD-stasc VERSION 1.0 *//* DATE Januar 1992 *//* BY Ursula Viebeg *//* Levona Eckstein*//* *//* FILENAME *//* sta_r_w.c *//* *//* DESCRIPTION *//* This modul provides all functions for file handling and data access *//* on the smartcard of the smartcard application interface *//* *//* EXPORT DESCRIPTION *//* sca_read_data() Read data from EF on the smartcard *//* *//* sca_read_file() Read complete file from smartcard *//* *//* sca_write_data() Write data in EF on the smartcard *//* *//* sca_write_file() Write complete file on the smartcard *//* *//* sca_delete_record() Delete record in EF on the smartcard *//* *//* sca_lock_key() Lock key on smartcard *//* *//* sca_unlock_key() Unlock key on the smartcard *//* *//* *//* *//* *//* *//* IMPORT DESCRIPTION *//* - aux_xdmp.c (libcrypt) *//* *//* aux_fxdump() dump buffer in File *//* *//* *//* - sta_free.c (libsm) *//* *//* sta_aux_bytestr_free() set the bytes-buffer in Bytestring free *//* *//* *//* - sta_dev.c (libsm) *//* *//* check_sct_sc() check SCT and SC *//* *//* check_sec_mess() check security mode(s) for command and response*//* *//* set_errmsg() set sca_errmsg *//* *//* err_analyse() error analyse and handling *//* *//* sca_errno global error variable set by STAMOD *//* *//* sca_errmsg global pointer to error message set by STAMOD*//* *//* - stasc.c (libsm) *//* *//* create_trans() send SC command *//* *//* cr_header() create SC-Command header *//* *//* request global variable for create_trans *//* *//* response global variable for create_trans *//* *//* sc_param global variable for create_trans *//* */ /* sc_apdu global variable for create_trans *//* *//* - staprint.c (libsm) for TEST-output *//* *//* print_filecat() *//* print_filetype() *//* print_datastruc() *//* print_filecontinfo() *//* print_secmess() *//* print_filesel() *//* print_fileid() *//* print_inforeq() *//* print_closecontext() *//* print_datasel() *//* print_datastruc() *//* print_keyid() *//* print_recordlist() *//* print_transmode() *//* *//* *//*---------------------------------------------------------------------------------*//*-------------------------------------------------------------*//* include-Files *//*-------------------------------------------------------------*/#include "stamod.h"#include "stamsg.h"#include "sctint.h"#include "sccom.h"#ifndef MAC#include <sys/types.h>#include <sys/stat.h>#else#include <stdlib.h>#endif#include <stdio.h>#include <fcntl.h>#include <string.h>/*-------------------------------------------------------------*//* extern declarations *//*-------------------------------------------------------------*/extern void sta_aux_bytestr_free();extern void aux_fxdump();extern int check_sct_sc();extern int check_sec_mess();extern int set_errmsg();extern void err_analyse();extern int create_trans();extern int cr_header();extern unsigned int sca_errno; /* error number set by STAMOD- */ /* stadevice */extern char *sca_errmsg; /* pointer to error message set by */ /* STAMOD-stadevice */#ifdef TESTextern void print_filecat();extern void print_filetype();extern void print_datastruc();extern void print_filecontinfo();extern void print_secmess();extern void print_filesel();extern void print_fileid();extern void print_inforeq();extern void print_closecontext();extern void print_datasel();extern void print_keyid();extern void print_recordlist();extern void print_transmode();#endifextern Request request; /* body of the SCT commands */extern Bytestring response; /* body of the response of the SCT */extern int command; /* INS-Code of the SCT command */extern struct s_command sc_param; /* structure of parameters for the */ /* SC-commands */extern Bytestring sc_apdu; /* generated apdu of the SC-command *//*-------------------------------------------------------------*//* globale variable definitions *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* type definitions *//*-------------------------------------------------------------*//* definitions for the SC-Interface */#define SCCMD sc_param.sc_header.inscode#define SCHEAD sc_param.sc_header#define SCREADF sc_param.sc_uval.sc_readf#define SCWRITEF sc_param.sc_uval.sc_writef#define SCDELREC sc_param.sc_uval.sc_delrec#define SCLOCKK sc_param.sc_uval.sc_lockkey#define FIRST_FIX_RID 0x00#define FIRST_VAR_RID 0x00/*-------------------------------------------------------------*//* local Variable definitions *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* local procedure definitions *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* | GMD *//* +-----*//* PROC sca_read_data VERSION 1.0 *//* DATE Januar 1992 *//* BY Levona Eckstein *//* *//* DESCRIPTION *//* Read data from elementary file on the smartcard. *//* *//* *//* IN DESCRIPTION *//* sct_id SCT identifier *//* *//* file_id File identifier *//* *//* data_sel Offset of the data to be read *//* *//* data_length Number of octets to be read *//* */ /* sec_mess security modes *//* *//* OUT *//* *//* out_data Buffer where the returned data *//* are stored *//* *//* *//* RETURN DESCRIPTION *//* 0 o.k *//* -1 error *//* M_EMEMORY *//* *//* CALLED FUNCTIONS *//* check_sct_sc ERROR-Codes *//* ENOCARD *//* ESIDUNK *//* ENOSHELL *//* EOPERR *//* EEMPTY *//* EMEMAVAIL *//* ECLERR *//* ERDERR *//* EINVARG *//* ETOOLONG *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* *//* cr_header ERROR-Codes *//* M_ESECMESS *//* *//* *//* create_trans ERROR-Codes *//* EINVARG *//* ETOOLONG *//* EMEMAVAIL *//* ESIDUNK *//* EPARMISSED *//* EPARINC *//* INVPAR *//* EINVINS *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* sw1/sw2 from SC response *//* *//*-------------------------------------------------------------*/intsca_read_data(sct_id, file_id, data_sel, data_length, out_data, sec_mess) int sct_id; FileId *file_id; DataSel *data_sel; int data_length; OctetString *out_data; SecMess *sec_mess;{ /*----------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------*/ int i, rc; int data_incon = 0; /*----------------------------------------------------------*/ /* Statements */ /*----------------------------------------------------------*/#ifdef TEST fprintf(stdout, "\n***** STAMOD-Routine sca_read_data *****\n\n"); fprintf(stdout, "TRACE of the input parameters : \n"); fprintf(stdout, "sct_id : %d\n", sct_id); print_fileid(file_id); print_datasel(data_sel); fprintf(stdout, "data_length : %d\n", data_length); print_secmess(sec_mess);#endif /*-------------------------------------*/ /* call check_sct_sc */ /*-------------------------------------*/ if (check_sct_sc(sct_id, TRUE)) return (-1); /*-------------------------------------*/ /* create SC command READF */ /*-------------------------------------*/ /* create header */ if (cr_header(SC_READF, sec_mess)) return (-1); /* set parameters */ SCREADF.data_sel = data_sel; SCREADF.fid = file_id; SCREADF.lrddata = (unsigned) data_length; /* call create_trans */ rc = create_trans(sct_id, TRUE); if (rc == -1) { switch (sca_errno) { case EDATAINC_CLPEN: if (response.nbytes != 0) { data_incon = 1; } else { sta_aux_bytestr_free(&response); return (-1); } break; default: /*---------------------------------------*/ /* error while reading file */ /*---------------------------------------*/ sta_aux_bytestr_free(&response); return (-1); break; } }; /* get data from SC */ out_data->noctets = response.nbytes; if ((out_data->octets = (char *) malloc(out_data->noctets)) == NULL) { sca_errno = M_EMEMORY; set_errmsg(); sta_aux_bytestr_free(&response); return (-1); } for (i = 0; i < out_data->noctets; i++) out_data->octets[i] = response.bytes[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -