📄 sta_r_w.c
字号:
/*----------------------------------------------*/ /* normal end => release response storage */ /*----------------------------------------------*/ sta_aux_bytestr_free(&response);#ifdef TEST fprintf(stdout, "TRACE of the output parameters : \n"); fprintf(stdout, "out_data : \n"); fprintf(stdout, " noctets : %d\n", out_data->noctets); fprintf(stdout, " octets : \n"); aux_fxdump(stdout, out_data->octets, out_data->noctets, 0); fprintf(stdout, "\n***** Normal end of sca_read_data *****\n\n");#endif if (data_incon) return (-1); else return (0);}/*-------------------------------------------------------------*//* E N D O F P R O C E D U R E sca_read_data *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* | GMD *//* +-----*//* PROC sca_read_file VERSION 1.0 *//* DATE Januar 1992 *//* BY Levona Eckstein *//* *//* DESCRIPTION *//* Read complete file from smartcard. *//* *//* *//* IN DESCRIPTION *//* sct_id SCT identifier *//* *//* file_id File identifier *//* *//* data_struc Data structure *//* (LIN_FIX or LIN_VAR) *//* sec_mess security modes *//* *//* OUT *//* *//* out_data Buffer where the returned data *//* are stored *//* *//* RETURN DESCRIPTION *//* 0 file completly read *//* -1 error *//* out_data may be present *//* M_EDATASTRUC *//* M_EFILEEMPTY *//* 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_file(sct_id, file_id, data_struc, out_data, sec_mess) int sct_id; FileId *file_id; DataStruc data_struc; RecordList **out_data; SecMess *sec_mess;{ /*----------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------*/ int end_flag = 0; int first_read = 1; int data_incon = 0; int rc, i; RecordList *p_head, *p_last; /*----------------------------------------------------------*/ /* Statements */ /*----------------------------------------------------------*/#ifdef TEST fprintf(stdout, "\n***** STAMOD-Routine sca_read_file *****\n\n"); fprintf(stdout, "TRACE of the input parameters : \n"); fprintf(stdout, "sct_id : %d\n", sct_id); print_fileid(file_id); print_datastruc(data_struc); print_secmess(sec_mess);#endif /*-------------------------------------*/ /* check parameter */ /*-------------------------------------*/ if ((data_struc != LIN_FIX) && (data_struc != LIN_VAR)) { sca_errno = M_EDATASTRUC; set_errmsg(); return (-1); } /*-------------------------------------*/ /* 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_struc = data_struc; if (data_struc == LIN_FIX) SCREADF.data_sel->data_ref.record_sel.record_id = FIRST_FIX_RID; else SCREADF.data_sel->data_ref.record_sel.record_id = FIRST_VAR_RID; SCREADF.fid = file_id; SCREADF.data_sel->data_ref.record_sel.record_pos = 0; SCREADF.lrddata = 0; *out_data = NULL; while (!end_flag) { /*---------------------------------------*/ /* call create_trans */ /*---------------------------------------*/ rc = create_trans(sct_id, TRUE); if (rc == -1) { switch (sca_errno) { case EINVRID: if (first_read) { /*---------------------------------------*/ /* file empty */ /*---------------------------------------*/#ifdef TEST fprintf(stdout, "\n***** File empty *****\n\n"); fprintf(stdout, "\n***** Normal end of sca_read_file *****\n\n");#endif sca_errno = M_EFILEEMPTY; set_errmsg(); sta_aux_bytestr_free(&response); return (-1); } /*---------------------------------------*/ /* end of file reached */ /*---------------------------------------*/ *out_data = p_head; sta_aux_bytestr_free(&response);#ifdef TEST fprintf(stdout, "\n***** end of file reached *****\n\n"); fprintf(stdout, "TRACE of the output parameters : \n"); print_recordlist(*out_data); fprintf(stdout, "\n***** Normal end of sca_read_file *****\n\n");#endif return (0); break; case EDATAINC_CLPEN: if (response.nbytes != 0) { /* Data inconsistency */ end_flag = 1; data_incon = 1;#ifdef TEST fprintf(stdout, "\n***** Data inconsistency, but data reached *****\n\n");#endif } else { *out_data = p_head;#ifdef TEST fprintf(stdout, "\n***** error while reading data *****\n\n"); fprintf(stdout, "TRACE of the output parameters : \n"); print_recordlist(*out_data);#endif sta_aux_bytestr_free(&response); return (-1); } break; default: /*---------------------------------------*/ /* error while reading file */ /*---------------------------------------*/ *out_data = p_head; sta_aux_bytestr_free(&response);#ifdef TEST fprintf(stdout, "\n***** error while reading data *****\n\n"); fprintf(stdout, "TRACE of the output parameters : \n"); print_recordlist(*out_data);#endif return (-1); break; } }; /*---------------------------------------------------------*/ /* allocate new RecordList - element and get data from SC */ /*---------------------------------------------------------*/ if (first_read) { /*---------------------------------------*/ /* create first element */ /*---------------------------------------*/ if ((p_head = (RecordList *) malloc(sizeof(RecordList))) == RECNULL) {#ifdef TEST fprintf(stdout, "\n***** error while creating first recordlist - element *****\n\n");#endif sca_errno = M_EMEMORY; set_errmsg(); sta_aux_bytestr_free(&response); return (-1); } p_head->next = RECNULL; p_last = p_head; } else { /*---------------------------------------*/ /* create next RecordList element */ /*---------------------------------------*/ if ((p_last->next = (RecordList *) malloc(sizeof(RecordList))) == RECNULL) { *out_data = p_head;#ifdef TEST fprintf(stdout, "\n***** error while creating next recordlist - element *****\n\n"); fprintf(stdout, "TRACE of the output parameters : \n"); print_recordlist(*out_data);#endif sca_errno = M_EMEMORY; set_errmsg(); sta_aux_bytestr_free(&response); return (-1); } p_last = p_last->next; p_last->next = RECNULL; } p_last->record.noctets = response.nbytes; /*---------------------------------------*/ /* allocate record.octets */ /*---------------------------------------*/ if ((p_last->record.octets = (char *) malloc(p_last->record.noctets)) == NULL) { *out_data = p_head;#ifdef TEST fprintf(stdout, "\n***** error while creating next octet - element *****\n\n"); fprintf(stdout, "TRACE of the output parameters : \n"); print_recordlist(*out_data);#endif sca_errno = M_EMEMORY; set_errmsg(); sta_aux_bytestr_free(&response); return (-1); } for (i = 0; i < p_last->record.noctets; i++) p_last->record.octets[i] = response.bytes[i]; sta_aux_bytestr_free(&response); SCREADF.data_sel->data_ref.record_sel.record_id++; /* next record */ first_read = 0; } sta_aux_bytestr_free(&response); *out_data = p_head;#ifdef TEST fprintf(stdout, "TRACE of the output parameters : \n"); print_recordlist(*out_data);#endif if (data_incon) return (-1); else return (0);}/*-------------------------------------------------------------*//* E N D O F P R O C E D U R E sca_read_file *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* | GMD *//* +-----*//* PROC sca_write_data VERSION 1.0 *//* DATE Januar 1992 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -