Changeset 1290 for branches/smartreader/csctapi/protocol_t0.c
- Timestamp:
- 01/19/10 16:48:50 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/smartreader/csctapi/protocol_t0.c
r1280 r1290 52 52 */ 53 53 54 static void Protocol_T0_Clear (Protocol_T0 * t0);55 static void Protocol_T14_Clear (Protocol_T14 * t14);56 57 54 static int Protocol_T0_Case1 (APDU_Cmd * cmd, APDU_Rsp ** rsp); 58 55 … … 77 74 * Exproted funtions definition 78 75 */ 79 80 Protocol_T0 * Protocol_T0_New (void)81 {82 Protocol_T0 *t0;83 84 t0 = (Protocol_T0 *) malloc (sizeof (Protocol_T0));85 86 if (t0 != NULL)87 Protocol_T0_Clear (t0);88 89 return t0;90 }91 92 Protocol_T14 * Protocol_T14_New (void)93 {94 Protocol_T14 *t14;95 96 t14 = (Protocol_T14 *) malloc (sizeof (Protocol_T14));97 98 if (t14 != NULL)99 Protocol_T14_Clear (t14);100 101 return t14;102 }103 104 int Protocol_T0_Init (Protocol_T0 * t0, PPS_ProtocolParameters * params, int selected_protocol)105 {106 BYTE wi;107 108 /* Integer value WI = TC2, by default 10 */109 #ifndef PROTOCOL_T0_USE_DEFAULT_TIMINGS110 if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)111 #endif112 wi = PROTOCOL_T0_DEFAULT_WI;113 114 /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */115 double F = (double) atr_f_table[params->FI];116 t0->wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);117 118 /* Set timings */119 icc_timings.block_timeout = t0->wwt;120 icc_timings.char_timeout = t0->wwt;121 ICC_Async_SetTimings ();122 123 #ifdef DEBUG_PROTOCOL124 printf ("Protocol: T=0: WWT=%d, Clockrate=%lu\n", (int)(t0->wwt),ICC_Async_GetClockRate());125 #endif126 127 return PROTOCOL_T0_OK;128 }129 130 int Protocol_T14_Init (Protocol_T14 * t14, PPS_ProtocolParameters * params, int selected_protocol)131 {132 BYTE wi;133 134 /* Integer value WI = TC2, by default 10 */135 #ifndef PROTOCOL_T14_USE_DEFAULT_TIMINGS136 if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)137 #endif138 wi = PROTOCOL_T14_DEFAULT_WI;139 140 /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */141 double F = (double) atr_f_table[params->FI];142 t14->wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);143 t14->wwt >>= 1;144 145 /* Set timings */146 icc_timings.block_timeout = t14->wwt;147 icc_timings.char_timeout = t14->wwt;148 ICC_Async_SetTimings ();149 150 #ifdef DEBUG_PROTOCOL151 printf ("Protocol: T=14: WWT=%d\n", (int)(t14->wwt));152 #endif153 154 return PROTOCOL_T14_OK;155 }156 76 157 77 int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp) … … 215 135 printf ("Protocol: T=14: Invalid APDU\n"); 216 136 #endif 217 ret = PROTOCOL_T14_ERROR; 218 } 219 220 return ret; 221 } 222 223 int Protocol_T0_Close (Protocol_T0 * t0) 224 { 225 Protocol_T0_Clear (t0); 226 227 return PROTOCOL_T0_OK; 228 } 229 230 int Protocol_T14_Close (Protocol_T14 * t14) 231 { 232 Protocol_T14_Clear (t14); 233 234 return PROTOCOL_T14_OK; 235 } 236 237 void Protocol_T0_Delete (Protocol_T0 * t0) 238 { 239 free (t0); 240 } 241 242 void Protocol_T14_Delete (Protocol_T14 * t14) 243 { 244 free (t14); 137 ret = PROTOCOL_T0_ERROR; 138 } 139 140 return ret; 245 141 } 246 142 … … 964 860 BYTE *cmd_raw; 965 861 long sent, recv, cmd_len; 966 int ret = PROTOCOL_T 14_OK, nulls, cmd_case;862 int ret = PROTOCOL_T0_OK, nulls, cmd_case; 967 863 BYTE ixor = 0x3E; 968 864 BYTE ixor1 = 0x3F; … … 979 875 /* Check case of command */ 980 876 if ((cmd_case != APDU_CASE_2S) && (cmd_case != APDU_CASE_3S)) 981 return PROTOCOL_T 14_ERROR;877 return PROTOCOL_T0_ERROR; 982 878 983 879 if (reader[ridx].typ != R_INTERNAL) … … 987 883 { 988 884 (*rsp) = NULL; 989 return PROTOCOL_T 14_ICC_ERROR;885 return PROTOCOL_T0_ICC_ERROR; 990 886 } 991 887 … … 994 890 { 995 891 (*rsp) = NULL; 996 return PROTOCOL_T 14_ICC_ERROR;892 return PROTOCOL_T0_ICC_ERROR; 997 893 } 998 894 … … 1001 897 { 1002 898 (*rsp) = NULL; 1003 return PROTOCOL_T 14_ICC_ERROR;899 return PROTOCOL_T0_ICC_ERROR; 1004 900 } 1005 901 } … … 1014 910 { 1015 911 (*rsp) = NULL; 1016 return PROTOCOL_T 14_ICC_ERROR;912 return PROTOCOL_T0_ICC_ERROR; 1017 913 } 1018 914 } … … 1050 946 if (ICC_Async_Receive (8, buffer) != ICC_ASYNC_OK) 1051 947 { 1052 ret = PROTOCOL_T 14_ICC_ERROR;948 ret = PROTOCOL_T0_ICC_ERROR; 1053 949 break; 1054 950 } … … 1061 957 if (ICC_Async_Receive (recv, buffer + 8) != ICC_ASYNC_OK) 1062 958 { 1063 ret = PROTOCOL_T 14_ICC_ERROR;959 ret = PROTOCOL_T0_ICC_ERROR; 1064 960 break; 1065 961 } … … 1068 964 if (ICC_Async_Receive (1, &ixor) != ICC_ASYNC_OK) 1069 965 { 1070 ret = PROTOCOL_T 14_ICC_ERROR;966 ret = PROTOCOL_T0_ICC_ERROR; 1071 967 break; 1072 968 } … … 1077 973 if(ixor1 != ixor) 1078 974 { 1079 ret = PROTOCOL_T 14_ERROR;975 ret = PROTOCOL_T0_ERROR; 1080 976 break; 1081 977 } … … 1084 980 1085 981 1086 ret = PROTOCOL_T 14_OK;982 ret = PROTOCOL_T0_OK; 1087 983 break; 1088 984 } 1089 985 } 1090 986 1091 if (ret == PROTOCOL_T 14_OK)987 if (ret == PROTOCOL_T0_OK) 1092 988 { 1093 989 memcpy(buffer + 8 + recv, buffer + 2, 2); … … 1101 997 return (ret); 1102 998 } 1103 1104 static void Protocol_T0_Clear (Protocol_T0 * t0)1105 {1106 t0->wwt = 0;1107 }1108 1109 static void Protocol_T14_Clear (Protocol_T14 * t14)1110 {1111 t14->wwt = 0;1112 }
Note:
See TracChangeset
for help on using the changeset viewer.