Changeset 3799
- Timestamp:
- 11/01/10 23:00:51 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/protocol_t0.c
r3219 r3799 151 151 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 152 152 unsigned char tpdu_rsp[CTA_RES_LEN]; 153 unsigned short *tpdu_lr = 0;154 153 unsigned short tpdu_lr = 0; 154 ulong i; 155 155 156 156 unsigned long Lc = (((unsigned long)(command[5]) << 8) | command[6]); … … 175 175 buffer[4] = MIN (255, command_len - i); 176 176 memcpy (buffer + 5, command + i, buffer[4]); 177 call (Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, tpdu_lr));177 call (Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, &tpdu_lr)); 178 178 /* Card does support envelope command */ 179 if (tpdu_rsp[ *tpdu_lr - 2] == 0x90)179 if (tpdu_rsp[tpdu_lr - 2] == 0x90) 180 180 { 181 181 /* This is not the last segment */ 182 182 if (buffer[4] + i < command_len) 183 *tpdu_lr = 0;183 tpdu_lr = 0; 184 184 else { 185 memcpy(rsp, tpdu_rsp, *tpdu_lr); // Map response TPDU onto APDU186 *lr = *tpdu_lr;185 memcpy(rsp, tpdu_rsp, tpdu_lr); // Map response TPDU onto APDU 186 *lr = tpdu_lr; 187 187 } 188 188 } 189 189 else /* Card does not support envelope command or error */ 190 190 { 191 memcpy(rsp, tpdu_rsp, *tpdu_lr); // Map response TPDU onto APDU192 *lr = *tpdu_lr;191 memcpy(rsp, tpdu_rsp, tpdu_lr); // Map response TPDU onto APDU 192 *lr = tpdu_lr; 193 193 break; 194 194 } … … 203 203 BYTE buffer[5]; 204 204 unsigned char tpdu_rsp[CTA_RES_LEN]; 205 unsigned short *tpdu_lr = 0;205 unsigned short tpdu_lr = 0; 206 206 long Lm, Lx; 207 207 … … 217 217 /* Map APDU onto command TPDU */ 218 218 buffer[4] = 0x00; 219 call (Protocol_T0_ExchangeTPDU(reader, buffer, 5 , tpdu_rsp, tpdu_lr));220 221 if (tpdu_rsp[ *tpdu_lr - 2] == 0x6C) {/* Le not accepted, La indicated */219 call (Protocol_T0_ExchangeTPDU(reader, buffer, 5 , tpdu_rsp, &tpdu_lr)); 220 221 if (tpdu_rsp[tpdu_lr - 2] == 0x6C) {/* Le not accepted, La indicated */ 222 222 /* Map command APDU onto TPDU */ 223 223 memcpy (buffer, command, 4); 224 buffer[4] = tpdu_rsp[ *tpdu_lr - 1];224 buffer[4] = tpdu_rsp[tpdu_lr - 1]; 225 225 226 226 /* Delete response TPDU */ 227 *tpdu_lr = 0;227 tpdu_lr = 0; 228 228 229 229 return Protocol_T0_ExchangeTPDU(reader, buffer, 5, rsp, lr); //Reissue command 230 230 } 231 231 232 memcpy(rsp, tpdu_rsp, *tpdu_lr);//Map response TPDU onto APDU without change , also for SW1 = 0x67233 *lr = *tpdu_lr;232 memcpy(rsp, tpdu_rsp, tpdu_lr);//Map response TPDU onto APDU without change , also for SW1 = 0x67 233 *lr = tpdu_lr; 234 234 ret = OK; 235 if (tpdu_rsp[ *tpdu_lr - 2] == 0x61) {/* Command processed, Lx indicated */236 Lx = (tpdu_rsp[ *tpdu_lr - 1] == 0x00) ? 256 : tpdu_rsp[*tpdu_lr - 1];235 if (tpdu_rsp[tpdu_lr - 2] == 0x61) {/* Command processed, Lx indicated */ 236 Lx = (tpdu_rsp[tpdu_lr - 1] == 0x00) ? 256 : tpdu_rsp[tpdu_lr - 1]; 237 237 Lm = Le - (*lr - 2); 238 238 … … 246 246 { 247 247 buffer[4] = (BYTE) MIN (Lm, Lx); 248 call (Protocol_T0_ExchangeTPDU(reader, buffer, 5, tpdu_rsp, tpdu_lr));248 call (Protocol_T0_ExchangeTPDU(reader, buffer, 5, tpdu_rsp, &tpdu_lr)); 249 249 250 250 /* Append response TPDU to APDU */ 251 if ((*lr + *tpdu_lr) > CTA_RES_LEN) {252 cs_log("TPDU Append error, new length %i exceeds max length %i", *lr + *tpdu_lr, CTA_RES_LEN);251 if ((*lr + tpdu_lr) > CTA_RES_LEN) { 252 cs_log("TPDU Append error, new length %i exceeds max length %i", *lr + tpdu_lr, CTA_RES_LEN); 253 253 return ERROR; 254 254 } 255 memcpy (rsp + (*lr - 2), tpdu_rsp, *tpdu_lr);256 *lr += *tpdu_lr;255 memcpy (rsp + (*lr - 2), tpdu_rsp, tpdu_lr); 256 *lr += tpdu_lr; 257 257 258 258 /* Delete response TPDU */ 259 *tpdu_lr = 0;259 tpdu_lr = 0; 260 260 261 261 Lm = Le - (*lr - 2); … … 271 271 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 272 272 unsigned char tpdu_rsp[CTA_RES_LEN]; 273 unsigned short *tpdu_lr = 0;273 unsigned short tpdu_lr = 0; 274 274 long Le; 275 275 … … 281 281 buffer[4] = (BYTE) Lc; 282 282 memcpy (buffer + 5, command, buffer[4]); 283 ret = Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, tpdu_lr);283 ret = Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, &tpdu_lr); 284 284 } 285 285 else /* 4E2 */ 286 ret = Protocol_T0_Case2E (reader, command, command_len, tpdu_rsp, tpdu_lr);286 ret = Protocol_T0_Case2E (reader, command, command_len, tpdu_rsp, &tpdu_lr); 287 287 288 288 /* 4E1 a) b) and c) */ … … 290 290 { 291 291 Le = ((((unsigned long)(command[command_len - 2]) << 8) | command[command_len - 1]) == 0 ? 65536 : (((unsigned long)(command[command_len - 2]) << 8) | command[command_len - 1])); 292 if (tpdu_rsp[ *tpdu_lr - 2] == 0x61)292 if (tpdu_rsp[tpdu_lr - 2] == 0x61) 293 293 { 294 294 /* Lm == (Le - APDU_Rsp_RawLen (tpdu_rsp)) == 0 */ 295 if (tpdu_rsp[ *tpdu_lr - 1] != 0x00)296 Le = MIN(tpdu_rsp[ *tpdu_lr - 1], Le);295 if (tpdu_rsp[tpdu_lr - 1] != 0x00) 296 Le = MIN(tpdu_rsp[tpdu_lr - 1], Le); 297 297 298 298 /* Delete response TPDU */ 299 *tpdu_lr = 0;299 tpdu_lr = 0; 300 300 301 301 /* Prepare extended Get Response APDU command */ … … 309 309 ret = Protocol_T0_Case3E (reader, buffer, rsp, lr); 310 310 } 311 else if ((tpdu_rsp[ *tpdu_lr - 2] & 0xF0) == 0x60)311 else if ((tpdu_rsp[tpdu_lr - 2] & 0xF0) == 0x60) 312 312 { 313 313 /* Map response TPDU onto APDU without change */ 314 memcpy(rsp, tpdu_rsp, *tpdu_lr);315 *lr = *tpdu_lr;314 memcpy(rsp, tpdu_rsp, tpdu_lr); 315 *lr = tpdu_lr; 316 316 } 317 317 else 318 318 { 319 319 /* Delete response TPDU */ 320 *tpdu_lr = 0;320 tpdu_lr = 0; 321 321 322 322 /* Prepare extended Get Response APDU command */
Note:
See TracChangeset
for help on using the changeset viewer.