Changeset 4998 for trunk/csctapi/protocol_t0.c
- Timestamp:
- 04/14/11 02:41:42 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/protocol_t0.c
r4141 r4998 64 64 */ 65 65 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)66 static int32_t Protocol_T0_Case2E (struct s_reader * reader, unsigned char * command, uint16_t command_len, unsigned char * rsp, uint16_t * lr); 67 68 static int32_t Protocol_T0_Case3E (struct s_reader * reader, unsigned char * command, unsigned char * rsp, uint16_t * lr); 69 70 static int32_t Protocol_T0_Case4E (struct s_reader * reader, unsigned char * command, uint16_t command_len, unsigned char * rsp, uint16_t * lr); 71 72 static int32_t Protocol_T0_ExchangeTPDU (struct s_reader *reader, unsigned char * command, uint16_t command_len, unsigned char * rsp, uint16_t * lr); 73 74 static int32_t APDU_Cmd_Case (unsigned char * command, uint16_t command_len) 75 75 { 76 76 BYTE B1; 77 u short B2B3;78 u longL;79 int res;77 uint16_t B2B3; 78 uint32_t L; 79 int32_t res; 80 80 81 81 /* Calculate length of body */ … … 89 89 B1 = command[4]; 90 90 91 if ((B1 != 0) && (L == (u long)B1 + 1))91 if ((B1 != 0) && (L == (uint32_t)B1 + 1)) 92 92 res = APDU_CASE_2S; 93 93 else if (L == 1) 94 94 res = APDU_CASE_3S; 95 else if ((B1 != 0) && (L == (u long)B1 + 2))95 else if ((B1 != 0) && (L == (uint32_t)B1 + 2)) 96 96 res = APDU_CASE_4S; 97 97 else if ((B1 == 0) && (L>2)) { 98 98 /* Get second and third byte of body */ 99 B2B3 = (((u short)(command[5]) << 8) | command[6]);100 101 if ((B2B3 != 0) && (L == (u long)B2B3 + 3))99 B2B3 = (((uint16_t)(command[5]) << 8) | command[6]); 100 101 if ((B2B3 != 0) && (L == (uint32_t)B2B3 + 3)) 102 102 res = APDU_CASE_2E; 103 103 else if (L == 3) 104 104 res = APDU_CASE_3E; 105 else if ((B2B3 != 0) && (L == (u long)B2B3 + 5))105 else if ((B2B3 != 0) && (L == (uint32_t)B2B3 + 5)) 106 106 res = APDU_CASE_4E; 107 107 else … … 118 118 */ 119 119 120 int Protocol_T0_Command (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)120 int32_t Protocol_T0_Command (struct s_reader * reader, unsigned char * command, uint16_t command_len, unsigned char * rsp, uint16_t * lr) 121 121 { 122 122 *lr = 0; //will be returned in case of error 123 123 if (command_len < 5) //APDU_CASE_1 or malformed 124 124 return ERROR; 125 int cmd_case = APDU_Cmd_Case (command, command_len);125 int32_t cmd_case = APDU_Cmd_Case (command, command_len); 126 126 switch (cmd_case) { 127 127 case APDU_CASE_2E: … … 147 147 148 148 149 static int Protocol_T0_Case2E (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)149 static int32_t Protocol_T0_Case2E (struct s_reader * reader, unsigned char * command, uint16_t command_len, unsigned char * rsp, uint16_t * lr) 150 150 { 151 151 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 152 152 unsigned char tpdu_rsp[CTA_RES_LEN]; 153 u nsigned short tpdu_lr = 0;154 u longi;155 156 u nsigned long Lc = (((unsigned long)(command[5]) << 8) | command[6]);153 uint16_t tpdu_lr = 0; 154 uint32_t i; 155 156 uint32_t Lc = (((uint32_t)(command[5]) << 8) | command[6]); 157 157 if (Lc < 256) 158 158 { … … 198 198 199 199 200 static int Protocol_T0_Case3E (struct s_reader * reader, unsigned char * command, unsigned char * rsp, unsigned short * lr)201 { 202 int ret;200 static int32_t Protocol_T0_Case3E (struct s_reader * reader, unsigned char * command, unsigned char * rsp, uint16_t * lr) 201 { 202 int32_t ret; 203 203 BYTE buffer[5]; 204 204 unsigned char tpdu_rsp[CTA_RES_LEN]; 205 u nsigned short tpdu_lr = 0;206 longLm, Lx;207 208 u nsigned long Le = ((((unsigned long)(command[5]) << 8) | command[6]) == 0 ? 65536 : (((unsigned long)(command[5]) << 8) | command[6]));205 uint16_t tpdu_lr = 0; 206 int32_t Lm, Lx; 207 208 uint32_t Le = ((((uint32_t)(command[5]) << 8) | command[6]) == 0 ? 65536 : (((uint32_t)(command[5]) << 8) | command[6])); 209 209 memcpy(buffer, command, 4);//Map APDU command onto TPDU 210 210 … … 266 266 267 267 268 static int Protocol_T0_Case4E (struct s_reader * reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)269 { 270 int ret;268 static int32_t Protocol_T0_Case4E (struct s_reader * reader, unsigned char * command, uint16_t command_len, unsigned char * rsp, uint16_t * lr) 269 { 270 int32_t ret; 271 271 BYTE buffer[PROTOCOL_T0_MAX_SHORT_COMMAND]; 272 272 unsigned char tpdu_rsp[CTA_RES_LEN]; 273 u nsigned short tpdu_lr = 0;274 longLe;275 276 u nsigned long Lc = (((unsigned long)(command[5]) << 8) | command[6]);273 uint16_t tpdu_lr = 0; 274 int32_t Le; 275 276 uint32_t Lc = (((uint32_t)(command[5]) << 8) | command[6]); 277 277 /* 4E1 */ 278 278 if (Lc < 256) { … … 289 289 if (ret == OK) 290 290 { 291 Le = ((((u nsigned long)(command[command_len - 2]) << 8) | command[command_len - 1]) == 0 ? 65536 : (((unsigned long)(command[command_len - 2]) << 8) | command[command_len - 1]));291 Le = ((((uint32_t)(command[command_len - 2]) << 8) | command[command_len - 1]) == 0 ? 65536 : (((uint32_t)(command[command_len - 2]) << 8) | command[command_len - 1])); 292 292 if (tpdu_rsp[tpdu_lr - 2] == 0x61) 293 293 { … … 335 335 336 336 337 static int Protocol_T0_ExchangeTPDU (struct s_reader *reader, unsigned char * command, unsigned short command_len, unsigned char * rsp, unsigned short * lr)337 static int32_t Protocol_T0_ExchangeTPDU (struct s_reader *reader, unsigned char * command, uint16_t command_len, unsigned char * rsp, uint16_t * lr) 338 338 { 339 339 BYTE buffer[PROTOCOL_T0_MAX_SHORT_RESPONSE]; 340 340 BYTE *data; 341 longLc, Le, sent, recv;342 int ret = OK, nulls, cmd_case;341 int32_t Lc, Le, sent, recv; 342 int32_t ret = OK, nulls, cmd_case; 343 343 *lr = 0; //in case of error this will be returned 344 344 … … 463 463 } 464 464 465 int Protocol_T14_ExchangeTPDU (struct s_reader *reader, unsigned char * cmd_raw, unsigned short command_len, unsigned char * rsp, unsigned short * lr)465 int32_t Protocol_T14_ExchangeTPDU (struct s_reader *reader, unsigned char * cmd_raw, uint16_t command_len, unsigned char * rsp, uint16_t * lr) 466 466 { 467 467 BYTE buffer[PROTOCOL_T14_MAX_SHORT_RESPONSE]; 468 longrecv;469 int cmd_case;468 int32_t recv; 469 int32_t cmd_case; 470 470 BYTE ixor = 0x3E; 471 471 BYTE ixor1 = 0x3F; 472 472 BYTE b1 = 0x01; 473 int i;474 long cmd_len = (long) command_len;473 int32_t i; 474 int32_t cmd_len = (int32_t) command_len; 475 475 *lr = 0; //in case of error this is returned 476 476 … … 503 503 cs_sleepms(2500); //FIXME why wait? 504 504 call (ICC_Async_Receive (reader, 8, buffer)); //Read one procedure byte 505 recv = ( long)buffer[7];505 recv = (int32_t)buffer[7]; 506 506 if(recv) 507 507 call (ICC_Async_Receive (reader, recv, buffer + 8));
Note:
See TracChangeset
for help on using the changeset viewer.