Changeset 1949
- Timestamp:
- 04/04/10 11:05:43 (14 years ago)
- Location:
- trunk/csctapi
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/Makefile
r1946 r1949 6 6 LIBFILE1 = $(LIBDIR)/libcsctapi-$(TYP).a 7 7 8 OBJECTS1 = $(LIBFILE1)(atr.o) \ 8 OBJECTS1 = $(LIBFILE1)(apdu.o) \ 9 $(LIBFILE1)(atr.o) \ 9 10 $(LIBFILE1)(icc_async.o) \ 10 11 $(LIBFILE1)(ifd_cool.o) \ -
trunk/csctapi/icc_async.c
r1946 r1949 31 31 #include "ifd.h" 32 32 #include "mc_global.h" 33 #include "apdu.h" 33 34 #include "protocol_t0.h" 34 35 #include "protocol_t1.h" … … 215 216 { 216 217 cs_debug_mask (D_IFD, "IFD: Activating card in reader %s\n", reader->label); 217 int card;218 218 219 219 reader->current_baudrate = DEFAULT_BAUDRATE; //this is needed for all readers to calculate work_etu for timings 220 switch(reader->typ) { 221 case R_DB2COM1: 222 case R_DB2COM2: 223 case R_SC8in1: 224 case R_MOUSE: 225 call (Phoenix_Reset(reader, atr)); 226 break; 220 if (reader->atr[0] != 0) { 221 cs_log("using ATR from reader config"); 222 ATR_InitFromArray(atr, reader->atr, 33); 223 } 224 else { 225 switch(reader->typ) { 226 case R_DB2COM1: 227 case R_DB2COM2: 228 case R_SC8in1: 229 case R_MOUSE: 230 call (Phoenix_Reset(reader, atr)); 231 break; 227 232 #if defined(LIBUSB) 228 case R_SMART:229 call (SR_Reset(reader, atr));230 break;231 #endif 232 case R_INTERNAL:233 case R_SMART: 234 call (SR_Reset(reader, atr)); 235 break; 236 #endif 237 case R_INTERNAL: 233 238 #ifdef SCI_DEV 234 call (Sci_Activate(reader));235 call (Sci_Reset(reader, atr));239 call (Sci_Activate(reader)); 240 call (Sci_Reset(reader, atr)); 236 241 #elif COOL 237 call (Cool_Reset(atr)); 238 #endif 239 break; 240 default: 241 cs_log("ERROR ICC_Async_Activate: unknow reader type %i",reader->typ); 242 return ERROR; 242 call (Cool_Reset(atr)); 243 #endif 244 break; 245 default: 246 cs_log("ERROR ICC_Async_Activate: unknow reader type %i",reader->typ); 247 return ERROR; 248 } 243 249 } 244 250 … … 271 277 } 272 278 273 int ICC_Async_CardWrite (struct s_reader *reader, unsigned char *command, unsigned short command_len, unsigned char *rsp, unsigned short *lr) 274 { 275 *lr = 0; //will be returned in case of error 279 static int Protocol_Command (struct s_reader *reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 280 { 276 281 switch (reader->protocol_type) { 277 282 case ATR_PROTOCOL_TYPE_T0: 278 call (Protocol_T0_Command (reader, command, command_len, rsp , lr));283 call (Protocol_T0_Command (reader, command, command_len, rsp)); 279 284 break; 280 285 case ATR_PROTOCOL_TYPE_T1: … … 282 287 int try = 1; 283 288 do { 284 if (Protocol_T1_Command (reader, command, command_len, rsp , lr) == OK)289 if (Protocol_T1_Command (reader, command, command_len, rsp) == OK) 285 290 break; 286 291 try++; 287 292 //try to resync 293 APDU_Rsp ** rsp; 288 294 unsigned char resync[] = { 0x21, 0xC0, 0x00, 0xE1 }; 289 Protocol_T1_Command (reader, resync, sizeof(resync), rsp , lr);295 Protocol_T1_Command (reader, resync, sizeof(resync), rsp); 290 296 ifsc = DEFAULT_IFSC; 291 297 } while (try <= 3); … … 293 299 } 294 300 case ATR_PROTOCOL_TYPE_T14: 295 call (Protocol_T14_ExchangeTPDU (reader, command, command_len, rsp , lr));301 call (Protocol_T14_ExchangeTPDU (reader, command, command_len, rsp)); 296 302 break; 297 303 default: … … 301 307 return OK; 302 308 } 309 310 int ICC_Async_CardWrite (struct s_reader *reader, unsigned char *cmd, unsigned short lc, unsigned char *rsp, unsigned short *lr) 311 { 312 APDU_Rsp *apdu_rsp = NULL; 313 int remain; 314 bool err = FALSE; 315 316 call (Protocol_Command (reader, cmd, lc, &apdu_rsp)); 317 { 318 if (apdu_rsp != NULL) { 319 /* Copy APDU data to rsp */ 320 remain = MAX ((short)APDU_Rsp_RawLen(apdu_rsp) - (*lr),0); 321 if (remain > 0) { 322 cs_log("MEMORY ERROR"); 323 err = TRUE; //FIXME do I need this? 324 } 325 (*lr) = MIN ((*lr), (short)APDU_Rsp_RawLen (apdu_rsp)); 326 memcpy (rsp, APDU_Rsp_Raw (apdu_rsp) + remain, (*lr)); 327 APDU_Rsp_Delete (apdu_rsp); 328 } 329 else 330 (*lr) = 0; 331 } 332 333 if (err) { 334 cs_log("ERROR creating APDU response"); 335 return ERROR; 336 } 337 338 return OK; 339 } 340 303 341 304 342 int ICC_Async_SetTimings (struct s_reader * reader, unsigned wait_etu) … … 843 881 //IFS setting in case of T1 844 882 if ((reader->protocol_type == ATR_PROTOCOL_TYPE_T1) && (ifsc != DEFAULT_IFSC)) { 845 unsigned char rsp[CTA_RES_LEN]; 846 unsigned short * lr; 883 APDU_Rsp ** rsp; 847 884 unsigned char tmp[] = { 0x21, 0xC1, 0x01, 0x00, 0x00 }; 848 885 tmp[3] = ifsc; // Information Field size 849 886 tmp[4] = ifsc ^ 0xE1; 850 Protocol_T1_Command (reader, tmp, sizeof(tmp), rsp , lr);887 Protocol_T1_Command (reader, tmp, sizeof(tmp), rsp); 851 888 } 852 889 return OK; -
trunk/csctapi/icc_async.h
r1946 r1949 60 60 int ICC_Async_Receive (struct s_reader *reader, unsigned size, BYTE * buffer); 61 61 62 #define apdu2resp \63 { \64 int remain; \65 bool err = FALSE; \66 if (apdu_rsp != NULL) { \67 remain = MAX ((short)APDU_Rsp_RawLen(apdu_rsp) - (*lr),0); \68 if (remain > 0) { \69 cs_log("MEMORY ERROR"); \70 err = TRUE; \71 } \72 (*lr) = MIN ((*lr), (short)APDU_Rsp_RawLen (apdu_rsp)); \73 memcpy (rsp, APDU_Rsp_Raw (apdu_rsp) + remain, (*lr)); \74 APDU_Rsp_Delete (apdu_rsp); \75 } \76 else \77 (*lr) = 0; \78 if (err) { \79 cs_log("ERROR creating APDU response"); \80 return ERROR; \81 } \82 }83 84 62 #endif /* _ICC_ASYNC_ */ 85 63 -
trunk/csctapi/ifd_phoenix.c
r1946 r1949 77 77 call (IO_Serial_SetParams (reader, DEFAULT_BAUDRATE, 8, PARITY_EVEN, 2, IO_SERIAL_HIGH, IO_SERIAL_LOW)); 78 78 IO_Serial_Flush(reader); 79 if (reader->atr[0] == 0) { 80 call (IO_Serial_SetParams (reader, DEFAULT_BAUDRATE, 8, PARITY_EVEN, 2, IO_SERIAL_HIGH, IO_SERIAL_LOW)); 81 call (Phoenix_SetBaudrate (reader, DEFAULT_BAUDRATE)); 82 call (IO_Serial_SetParity (reader, PARITY_EVEN)); 83 IO_Serial_Flush(reader); 84 } 79 85 return OK; 80 86 } -
trunk/csctapi/ifd_sc8in1.c
r1946 r1949 43 43 // bit6=1 means Slot7=Smartcard inside 44 44 // bit7=1 means Slot8=Smartcard inside 45 int res ,i;45 int res; 46 46 unsigned char tmp[128]; 47 47 struct termios termio, termiobackup; -
trunk/csctapi/protocol_t0.c
r1946 r1949 47 47 #define PROTOCOL_T14_MAX_SHORT_RESPONSE 258 48 48 49 /* Types of APDU's */50 #define APDU_CASE_1 0x0001 /* Nor send neither receive data */51 #define APDU_CASE_2S 0x0002 /* Receive data (1..256) */52 #define APDU_CASE_3S 0x0003 /* Send data (1..255) */53 #define APDU_CASE_4S 0x0004 /* Send data (1..255) and receive data (1..256) */54 #define APDU_CASE_2E 0x0102 /* Receive data (1..65536) */55 #define APDU_CASE_3E 0x0103 /* Send data (1..65535) */56 #define APDU_CASE_4E 0x0104 /* Send data (1..65535) and receive data (1..65536) */57 #define APDU_MALFORMED 5 /* Malformed APDU */58 59 49 /* Timings in ATR are not used in T=0 cards */ 60 50 /* #undef PROTOCOL_T0_USE_DEFAULT_TIMINGS */ … … 64 54 */ 65 55 66 static int Protocol_T0_Case2E (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr); 67 68 static int Protocol_T0_Case3E (struct s_reader * reader, unsigned char * command, unsigned char * rsp, unsigned short * lr); 69 70 static int Protocol_T0_Case4E (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr); 71 72 static int Protocol_T0_ExchangeTPDU (struct s_reader *reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr); 73 74 static int APDU_Cmd_Case (unsigned char * command, unsigned short command_len) 75 { 76 BYTE B1; 77 ushort B2B3; 78 ulong L; 79 int res; 80 81 /* Calculate length of body */ 82 L = MAX(command_len - 4, 0); 83 84 /* Case 1 */ 85 if (L == 0) 86 res = APDU_CASE_1; 87 else { 88 /* Get first byte of body */ 89 B1 = command[4]; 90 91 if ((B1 != 0) && (L == (ulong)B1 + 1)) 92 res = APDU_CASE_2S; 93 else if (L == 1) 94 res = APDU_CASE_3S; 95 else if ((B1 != 0) && (L == (ulong)B1 + 2)) 96 res = APDU_CASE_4S; 97 else if ((B1 == 0) && (L>2)) { 98 /* Get second and third byte of body */ 99 B2B3 = (((ushort)(command[5]) << 8) | command[6]); 100 101 if ((B2B3 != 0) && (L == (ulong)B2B3 + 3)) 102 res = APDU_CASE_2E; 103 else if (L == 3) 104 res = APDU_CASE_3E; 105 else if ((B2B3 != 0) && (L == (ulong)B2B3 + 5)) 106 res = APDU_CASE_4E; 107 else 108 res = APDU_MALFORMED; 109 } 110 else 111 res = APDU_MALFORMED; 112 } 113 return res; 114 } 56 static int Protocol_T0_Case2E (struct s_reader * reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 57 58 static int Protocol_T0_Case3E (struct s_reader * reader, unsigned char * command, APDU_Rsp ** rsp); 59 60 static int Protocol_T0_Case4E (struct s_reader * reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 61 62 static int Protocol_T0_ExchangeTPDU (struct s_reader *reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 115 63 116 64 /* 117 * Exp orted funtions definition65 * Exproted funtions definition 118 66 */ 119 67 120 int Protocol_T0_Command (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr) 121 { 122 *lr = 0; //will be returned in case of error 68 int Protocol_T0_Command (struct s_reader * reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 69 { 123 70 if (command_len < 5) //APDU_CASE_1 or malformed 124 71 return ERROR; 72 125 73 int cmd_case = APDU_Cmd_Case (command, command_len); 126 74 switch (cmd_case) { 127 75 case APDU_CASE_2E: 128 return Protocol_T0_Case2E (reader, command, command_len, rsp , lr);76 return Protocol_T0_Case2E (reader, command, command_len, rsp); 129 77 case APDU_CASE_3E: 130 return Protocol_T0_Case3E (reader, command, rsp , lr);78 return Protocol_T0_Case3E (reader, command, rsp); 131 79 case APDU_CASE_4E: 132 return Protocol_T0_Case4E (reader, command, command_len, rsp , lr);80 return Protocol_T0_Case4E (reader, command, command_len, rsp); 133 81 case APDU_CASE_4S: 134 82 command_len--; //FIXME this should change 4S to 2S/3S command 135 83 case APDU_CASE_2S: 136 84 case APDU_CASE_3S: 137 return Protocol_T0_ExchangeTPDU(reader, command, command_len, rsp , lr);85 return Protocol_T0_ExchangeTPDU(reader, command, command_len, rsp); 138 86 default: 139 87 cs_debug_mask (D_IFD,"Protocol: T=0: Invalid APDU\n"); … … 147 95 148 96 149 static int Protocol_T0_Case2E (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)97 static int Protocol_T0_Case2E (struct s_reader * reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 150 98 { 151 99 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 152 unsigned char tpdu_rsp[CTA_RES_LEN]; 153 unsigned short * tpdu_lr; 100 APDU_Rsp *tpdu_rsp; 154 101 ulong i; 155 102 … … 161 108 buffer[4] = (BYTE) Lc; 162 109 memcpy (buffer + 5, command + 7, buffer[4]); 163 return Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, rsp , lr);110 return Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, rsp); 164 111 } 165 112 … … 175 122 buffer[4] = MIN (255, command_len - i); 176 123 memcpy (buffer + 5, command + i, buffer[4]); 177 call (Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, tpdu_lr));124 call (Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, (&tpdu_rsp))); 178 125 /* Card does support envelope command */ 179 if ( tpdu_rsp[*tpdu_lr - 2]== 0x90)126 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x90) 180 127 { 181 128 /* This is not the last segment */ 182 129 if (buffer[4] + i < command_len) 183 *tpdu_lr = 0; 184 else { 185 memcpy(rsp, tpdu_rsp, *tpdu_lr); // Map response TPDU onto APDU 186 *lr = *tpdu_lr; 187 } 130 APDU_Rsp_Delete (tpdu_rsp); //delete response TPDU 131 else 132 (*rsp) = tpdu_rsp;// Map response TPDU onto APDU 188 133 } 189 134 else /* Card does not support envelope command or error */ 190 135 { 191 memcpy(rsp, tpdu_rsp, *tpdu_lr); // Map response TPDU onto APDU192 *lr = *tpdu_lr;136 /* Map response tpdu onto APDU without change */ 137 (*rsp) = tpdu_rsp; 193 138 break; 194 139 } 195 140 } 141 196 142 return OK; 197 143 } 198 144 199 145 200 static int Protocol_T0_Case3E (struct s_reader * reader, unsigned char * command, unsigned char * rsp, unsigned short * lr)146 static int Protocol_T0_Case3E (struct s_reader * reader, unsigned char * command, APDU_Rsp ** rsp) 201 147 { 202 148 int ret; 203 149 BYTE buffer[5]; 204 unsigned char tpdu_rsp[CTA_RES_LEN]; 205 unsigned short * tpdu_lr; 150 APDU_Rsp *tpdu_rsp; 206 151 long Lm, Lx; 207 152 … … 212 157 { 213 158 buffer[4] = (BYTE)Le; 214 return Protocol_T0_ExchangeTPDU(reader, buffer, 5, rsp , lr); //this was Case3S !!!159 return Protocol_T0_ExchangeTPDU(reader, buffer, 5, rsp); //this was Case3S !!! 215 160 } 216 161 217 162 /* Map APDU onto command TPDU */ 218 163 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 */164 call (Protocol_T0_ExchangeTPDU(reader, buffer, 5 , (&tpdu_rsp))); 165 166 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x6C) {/* Le not accepted, La indicated */ 222 167 /* Map command APDU onto TPDU */ 223 168 memcpy (buffer, command, 4); 224 buffer[4] = tpdu_rsp[*tpdu_lr - 1];169 buffer[4] = APDU_Rsp_SW2 (tpdu_rsp); 225 170 226 171 /* Delete response TPDU */ 227 *tpdu_lr = 0; 228 229 return Protocol_T0_ExchangeTPDU(reader, buffer, 5, rsp, lr); //Reissue command 230 } 231 232 memcpy(rsp, tpdu_rsp, *tpdu_lr);//Map response TPDU onto APDU without change , also for SW1 = 0x67 233 *lr = *tpdu_lr; 172 APDU_Rsp_Delete (tpdu_rsp); 173 174 return Protocol_T0_ExchangeTPDU(reader, buffer, 5, rsp); //Reissue command 175 } 176 177 (*rsp) = tpdu_rsp; //Map response TPDU onto APDU without change , also for SW1 = 0x67 234 178 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];237 Lm = Le - (*lr - 2);179 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x61) {/* Command processed, Lx indicated */ 180 Lx = (APDU_Rsp_SW2 (tpdu_rsp) == 0x00) ? 256 : APDU_Rsp_SW2 (tpdu_rsp); 181 Lm = Le - APDU_Rsp_DataLen (*rsp); 238 182 239 183 /* Prepare Get Response TPDU */ … … 246 190 { 247 191 buffer[4] = (BYTE) MIN (Lm, Lx); 248 call (Protocol_T0_ExchangeTPDU(reader, buffer, 5, tpdu_rsp, tpdu_lr));192 call (Protocol_T0_ExchangeTPDU(reader, buffer, 5, (&tpdu_rsp))); 249 193 250 194 /* 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);253 ret urnERROR;254 }255 memcpy (rsp + (*lr - 2), tpdu_rsp, *tpdu_lr);256 *lr += *tpdu_lr;195 if (APDU_Rsp_AppendData ((*rsp), tpdu_rsp) != APDU_OK) 196 { 197 ret = ERROR; 198 APDU_Rsp_Delete (tpdu_rsp); 199 break; 200 } 257 201 258 202 /* Delete response TPDU */ 259 *tpdu_lr = 0;260 261 Lm = Le - (*lr - 2);203 APDU_Rsp_Delete (tpdu_rsp); 204 205 Lm = Le - APDU_Rsp_DataLen (*rsp); 262 206 }/* Lm == 0 */ 263 207 } … … 266 210 267 211 268 static int Protocol_T0_Case4E (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)212 static int Protocol_T0_Case4E (struct s_reader * reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 269 213 { 270 214 int ret; 271 215 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 272 unsigned char tpdu_rsp[CTA_RES_LEN]; 273 unsigned short * tpdu_lr; 216 APDU_Rsp *tpdu_rsp; 274 217 long Le; 275 218 … … 281 224 buffer[4] = (BYTE) Lc; 282 225 memcpy (buffer + 5, command, buffer[4]); 283 ret = Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, tpdu_lr);226 ret = Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, (&tpdu_rsp)); 284 227 } 285 228 else /* 4E2 */ 286 ret = Protocol_T0_Case2E (reader, command, command_len, tpdu_rsp, tpdu_lr);229 ret = Protocol_T0_Case2E (reader, command, command_len, (&tpdu_rsp)); 287 230 288 231 /* 4E1 a) b) and c) */ … … 290 233 { 291 234 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)235 if (APDU_Rsp_SW1 (tpdu_rsp) == 0x61) 293 236 { 294 237 /* 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);238 if (APDU_Rsp_SW2 (tpdu_rsp) != 0x00) 239 Le = MIN(APDU_Rsp_SW2 (tpdu_rsp), Le); 297 240 298 241 /* Delete response TPDU */ 299 *tpdu_lr = 0;242 APDU_Rsp_Delete (tpdu_rsp); 300 243 301 244 /* Prepare extended Get Response APDU command */ … … 307 250 buffer[5] = (BYTE) (Le >> 8); /* B2 = BL-1 */ 308 251 buffer[6] = (BYTE) (Le & 0x00FF); /* B3 = BL */ 309 ret = Protocol_T0_Case3E (reader, buffer, rsp , lr);310 } 311 else if (( tpdu_rsp[*tpdu_lr - 2]& 0xF0) == 0x60)252 ret = Protocol_T0_Case3E (reader, buffer, rsp); 253 } 254 else if ((APDU_Rsp_SW1 (tpdu_rsp) & 0xF0) == 0x60) 312 255 { 313 256 /* Map response TPDU onto APDU without change */ 314 memcpy(rsp, tpdu_rsp, *tpdu_lr); 315 *lr = *tpdu_lr; 257 (*rsp) = tpdu_rsp; 316 258 } 317 259 else 318 260 { 319 261 /* Delete response TPDU */ 320 *tpdu_lr = 0;262 APDU_Rsp_Delete (tpdu_rsp); 321 263 322 264 /* Prepare extended Get Response APDU command */ … … 328 270 buffer[5] = (BYTE) Le >> 8; /* B2 = BL-1 */ 329 271 buffer[6] = (BYTE) Le & 0x00FF; /* B3 = BL */ 330 ret = Protocol_T0_Case3E (reader, buffer, rsp , lr);272 ret = Protocol_T0_Case3E (reader, buffer, rsp); 331 273 } 332 274 } … … 335 277 336 278 337 static int Protocol_T0_ExchangeTPDU (struct s_reader *reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)279 static int Protocol_T0_ExchangeTPDU (struct s_reader *reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 338 280 { 339 281 BYTE buffer[PROTOCOL_T0_MAX_SHORT_RESPONSE]; … … 341 283 long Lc, Le, sent, recv; 342 284 int ret = OK, nulls, cmd_case; 343 *lr = 0;//in case of error this will be returned285 (*rsp) = NULL;//in case of error this will be returned 344 286 345 287 cmd_case = APDU_Cmd_Case (command, command_len); … … 458 400 }//while 459 401 460 memcpy(rsp, buffer, recv); 461 *lr = recv; 402 (*rsp) = APDU_Rsp_New (buffer, recv); 462 403 return OK; 463 404 } 464 405 465 int Protocol_T14_ExchangeTPDU (struct s_reader *reader, unsigned char * cmd_raw, unsigned short command_len, unsigned char * rsp, unsigned short * lr)406 int Protocol_T14_ExchangeTPDU (struct s_reader *reader, unsigned char * cmd_raw, unsigned long command_len, APDU_Rsp ** rsp) 466 407 { 467 408 BYTE buffer[PROTOCOL_T14_MAX_SHORT_RESPONSE]; … … 473 414 int i; 474 415 long cmd_len = (long) command_len; 475 *lr = 0;//in case of error this is returned416 (*rsp) = NULL;//in case of error this is returned 476 417 477 418 /* Parse APDU */ … … 514 455 } 515 456 memcpy(buffer + 8 + recv, buffer + 2, 2); 516 *lr = recv + 2; 517 memcpy(rsp, buffer + 8, *lr); 457 (*rsp) = APDU_Rsp_New (buffer + 8, recv + 2); 518 458 return OK; 519 459 } -
trunk/csctapi/protocol_t0.h
r1946 r1949 28 28 #include "defines.h" 29 29 #include "icc_async.h" 30 #include "apdu.h" 30 31 31 32 /* Send a command and return a response */ 32 int Protocol_T0_Command (struct s_reader *reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr);33 int Protocol_T14_ExchangeTPDU (struct s_reader *reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr);33 int Protocol_T0_Command (struct s_reader *reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 34 int Protocol_T14_ExchangeTPDU (struct s_reader *reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 34 35 35 36 #endif /* _PROTOCOL_T0_ */ -
trunk/csctapi/protocol_t1.c
r1946 r1949 47 47 */ 48 48 49 int Protocol_T1_Command (struct s_reader *reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)49 int Protocol_T1_Command (struct s_reader *reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp) 50 50 { 51 51 T1_Block *block; … … 244 244 } 245 245 246 if (ret == OK) { 247 memcpy(rsp, buffer, counter); 248 *lr = counter; 249 } 246 if (ret == OK) 247 (*rsp) = APDU_Rsp_New (buffer, counter); 250 248 251 249 if (buffer != NULL) -
trunk/csctapi/protocol_t1.h
r1946 r1949 27 27 28 28 #include "defines.h" 29 #include "apdu.h" 29 30 30 31 /* … … 39 40 40 41 /* Send a command and return a response */ 41 int Protocol_T1_Command (struct s_reader *reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr);42 int Protocol_T1_Command (struct s_reader *reader, unsigned char * command, unsigned long command_len, APDU_Rsp ** rsp); 42 43 43 44 #endif /* _PROTOCOL_T1_ */
Note:
See TracChangeset
for help on using the changeset viewer.