Changeset 656
- Timestamp:
- 05/29/05 11:36:03 (7 years ago)
- Location:
- trunk/src/ifd
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ifd/apdu.c
r354 r656 11 11 * Check the APDU type and length 12 12 */ 13 static int 14 __ifd_apdu_check(const void *sbuf, size_t len, ifd_iso_apdu_t *iso) 13 static int __ifd_apdu_check(const void *sbuf, size_t len, ifd_iso_apdu_t * iso) 15 14 { 16 unsigned char *data = (unsigned char *)sbuf;17 unsigned int b;15 unsigned char *data = (unsigned char *)sbuf; 16 unsigned int b; 18 17 19 18 memset(iso, 0, sizeof(*iso)); … … 29 28 if (len == 0) { 30 29 iso->cse = IFD_APDU_CASE_2S; 31 iso->le = b ? b : 256;30 iso->le = b ? b : 256; 32 31 return 0; 33 32 } … … 50 49 if (len == b + 1) { 51 50 iso->cse = IFD_APDU_CASE_4S; 52 iso->le = data[b] ? data[b] : 256;51 iso->le = data[b] ? data[b] : 256; 53 52 iso->len--; 54 53 return 0; … … 58 57 } 59 58 60 int 61 ifd_apdu_case(const void *buf, size_t len) 59 int ifd_apdu_case(const void *buf, size_t len) 62 60 { 63 61 ifd_iso_apdu_t iso; … … 71 69 * Convert internal APDU type to an ISO-7816-4 APDU 72 70 */ 73 int 74 ifd_iso_apdu_parse(const void *data, size_t len, ifd_iso_apdu_t *iso) 71 int ifd_iso_apdu_parse(const void *data, size_t len, ifd_iso_apdu_t * iso) 75 72 { 76 unsigned char *p;73 unsigned char *p; 77 74 78 75 if (len < 4) … … 82 79 return -1; 83 80 84 p = (unsigned char *) data;81 p = (unsigned char *)data; 85 82 iso->cla = *p++; 86 83 iso->ins = *p++; 87 iso->p1 = *p++;88 iso->p2 = *p++;84 iso->p1 = *p++; 85 iso->p2 = *p++; 89 86 90 87 return 0; -
trunk/src/ifd/atr.c
r571 r656 9 9 #include "atr.h" 10 10 11 int 12 ifd_atr_parse(ifd_atr_info_t *info, const unsigned char *atr, size_t len) 11 int ifd_atr_parse(ifd_atr_info_t * info, const unsigned char *atr, size_t len) 13 12 { 14 unsigned int m, n, k;13 unsigned int m, n, k; 15 14 16 15 ifd_debug(1, "atr=%s", ct_hexdump(atr, len)); … … 32 31 33 32 for (m = 0, n = 2; n < len; m++) { 34 unsigned int TDi;33 unsigned int TDi; 35 34 36 35 /* TA1, TA2, TA3, TA4 are legal, TA5 wouldn't be */ … … 38 37 return IFD_ERROR_INVALID_ATR; 39 38 40 TDi = atr[n -1];39 TDi = atr[n - 1]; 41 40 if (n != 2) { 42 int prot;43 41 int prot; 42 44 43 prot = TDi & 0x0f; 45 44 if (info->default_protocol < 0) … … 64 63 * want to verify it. 65 64 */ 66 if (info->supported_protocols & ~ 0x1)65 if (info->supported_protocols & ~0x1) 67 66 len--; 68 67 if (n < len) … … 81 80 82 81 ifd_debug(1, "supported protocols=0x%x, default protocol=%d", 83 info->supported_protocols, 84 info->default_protocol); 82 info->supported_protocols, info->default_protocol); 85 83 return 0; 86 84 } … … 90 88 * string. 91 89 */ 92 int 93 ifd_build_pts(const ifd_atr_info_t *info, 94 int protocol, unsigned char *buf, size_t len) 90 int ifd_build_pts(const ifd_atr_info_t * info, int protocol, unsigned char *buf, 91 size_t len) 95 92 { 96 unsigned char ptsbuf[7], pck;97 size_t n, ptslen = 0;93 unsigned char ptsbuf[7], pck; 94 size_t n, ptslen = 0; 98 95 99 96 /* IFD_PROTOCOL_Tn is just n, so we take it easy here */ -
trunk/src/ifd/atr.h
r507 r656 12 12 #endif 13 13 14 typedef struct ifd_atr_info {15 /* The following contain -1 if the field wasn't present */16 intTA[3];17 intTB[3];18 intTC[3];19 unsigned intsupported_protocols;20 intdefault_protocol;21 } ifd_atr_info_t;14 typedef struct ifd_atr_info { 15 /* The following contain -1 if the field wasn't present */ 16 int TA[3]; 17 int TB[3]; 18 int TC[3]; 19 unsigned int supported_protocols; 20 int default_protocol; 21 } ifd_atr_info_t; 22 22 23 extern int ifd_atr_parse(ifd_atr_info_t *, const unsigned char *, size_t); 24 extern int ifd_build_pts(const ifd_atr_info_t *, int, 25 unsigned char *, size_t); 23 extern int ifd_atr_parse(ifd_atr_info_t *, const unsigned char *, 24 size_t); 25 extern int ifd_build_pts(const ifd_atr_info_t *, int, unsigned char *, 26 size_t); 26 27 27 28 #ifdef __cplusplus 28 29 } 29 30 #endif 30 31 #endif /* OPENCT_ATR_H */ 31 #endif /* OPENCT_ATR_H */ -
trunk/src/ifd/cardman.h
r624 r656 8 8 9 9 typedef struct atreq { 10 intatr_len;11 unsigned char atr[64];12 int power_act;13 unsigned char bIFSD;14 unsigned char bIFSC;10 int atr_len; 11 unsigned char atr[64]; 12 int power_act; 13 unsigned char bIFSD; 14 unsigned char bIFSC; 15 15 } atreq_t; 16 16 17 17 typedef struct ptsreq { 18 unsigned long protocol; /*T=0: 2^0, T=1: 2^1*/19 unsigned char flags;20 unsigned char pts1;21 unsigned char pts2;22 unsigned char pts3;18 unsigned long protocol; /*T=0: 2^0, T=1: 2^1 */ 19 unsigned char flags; 20 unsigned char pts1; 21 unsigned char pts2; 22 unsigned char pts3; 23 23 } ptsreq_t; 24 25 24 26 25 #define CM_IOC_MAGIC 'c' … … 33 32 #define CM_IOCARDOFF _IO (CM_IOC_MAGIC, 4) 34 33 35 #define CM_IOSDBGLVL _IOW(CM_IOC_MAGIC, 250, int*) 34 #define CM_IOSDBGLVL _IOW(CM_IOC_MAGIC, 250, int*) 36 35 37 36 /* card and device states */ … … 44 43 #define CM_NO_READER 0x10 45 44 #define CM_BAD_CARD 0x20 46 47 45 48 46 #ifdef __KERNEL__ … … 99 97 CB_READ_ATR, 100 98 CB_WRITE_PTS, 101 CB_READ_PTS,99 CB_READ_PTS, 102 100 CB_WRITE_T1, 103 101 CB_PROG_T1, … … 116 114 typedef struct usb_cardman { 117 115 118 struct usb_device *dev;119 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)120 struct usb_interface * interface;/* the interface for this device */121 #endif122 struct task_struct *owner;116 struct usb_device *dev; 117 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 118 struct usb_interface *interface; /* the interface for this device */ 119 #endif 120 struct task_struct *owner; 123 121 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) 124 struct usb_ctrlrequest*dr;125 #else 126 devrequest*dr;122 struct usb_ctrlrequest *dr; 123 #else 124 devrequest *dr; 127 125 #endif 128 struct urb *irq,*ctrl,*rctl;129 unsigned char *ibuf,*cbuf,*rcbuf;130 wait_queue_head_t waitq;126 struct urb *irq, *ctrl, *rctl; 127 unsigned char *ibuf, *cbuf, *rcbuf; 128 wait_queue_head_t waitq; 131 129 132 unsigned char atr[MAX_ATR];133 unsigned char atr_csum;134 unsigned char atr_len;135 unsigned charbIFSD, bIFSC;136 unsigned char ta1;// TA(1) specifies Fi over b8 to b5, Di over b4 to b1137 unsigned charpts[4];130 unsigned char atr[MAX_ATR]; 131 unsigned char atr_csum; 132 unsigned char atr_len; 133 unsigned char bIFSD, bIFSC; 134 unsigned char ta1; // TA(1) specifies Fi over b8 to b5, Di over b4 to b1 135 unsigned char pts[4]; 138 136 139 unsigned char rbuf[MAX_RBUF];140 shortrlen;137 unsigned char rbuf[MAX_RBUF]; 138 short rlen; 141 139 142 int t1_reply_len;140 int t1_reply_len; 143 141 144 142 /* length of a T=0 packet, excl. the header length */ 145 unsigned char t0_data_len;143 unsigned char t0_data_len; 146 144 147 145 /* relative data offset as we proceed through the packet */ 148 unsigned char t0_data_off;146 unsigned char t0_data_off; 149 147 150 148 /* byte 2 of the T=0 header (INS from CLA INS ADR...) */ 151 unsigned char t0_ins;149 unsigned char t0_ins; 152 150 153 151 /* length of T=0 reply we expcet. 2 for a WriteT0, else 154 152 * ReadT0 length + 2 (Sw1 Sw2) 155 153 */ 156 unsigned short t0_expected_reply_len;154 unsigned short t0_expected_reply_len; 157 155 158 int bInterval;159 unsigned char ctrlendp;160 unsigned char intendp;161 unsigned char card_state;162 int flags;163 int op;164 unsigned char proto;165 int ttl, ttl_hi,//CWT166 bwt,//BWT167 ptsttl;//PTS retry168 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)169 intopen;170 intpresent;171 struct semaphoresem;172 intminor;173 #endif 156 int bInterval; 157 unsigned char ctrlendp; 158 unsigned char intendp; 159 unsigned char card_state; 160 int flags; 161 int op; 162 unsigned char proto; 163 int ttl, ttl_hi, //CWT 164 bwt, //BWT 165 ptsttl; //PTS retry 166 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 167 int open; 168 int present; 169 struct semaphore sem; 170 int minor; 171 #endif 174 172 } usb_cardman_t; 175 #endif /* __CM2020__ */173 #endif /* __CM2020__ */ 176 174 177 175 #ifdef __CM4000__ … … 187 185 #define CM4000_IOCGIOADDR _IOW(CM_IOC_MAGIC, 255, int*) 188 186 189 #endif /* __CM4000__ */187 #endif /* __CM4000__ */ 190 188 191 #endif /* __KERNEL__ */192 #endif /* _CARDMAN_H_ */189 #endif /* __KERNEL__ */ 190 #endif /* _CARDMAN_H_ */ -
trunk/src/ifd/checksum.c
r360 r656 57 57 * Returns LRC of data. 58 58 */ 59 unsigned int 60 csum_lrc_compute(const uint8_t *in, size_t len, unsigned char *rc) 59 unsigned int csum_lrc_compute(const uint8_t * in, size_t len, unsigned char *rc) 61 60 { 62 unsigned char lrc = 0;61 unsigned char lrc = 0; 63 62 64 63 while (len--) -
trunk/src/ifd/conf.c
r413 r656 17 17 #include <openct/buffer.h> 18 18 19 struct ct_config ct_config = {19 struct ct_config ct_config = { 20 20 0, /* debug */ 21 21 1, /* autoload */ … … 40 40 }; 41 41 42 static const char * config_filename = NULL;43 static ct_buf_t config_buf;44 static int config_fd = -1;45 static int config_line = 0;46 static ifd_conf_node_t config_top;47 48 static int conf_parse_group(ifd_conf_node_t *, char);49 static void conf_dump(ifd_conf_node_t *, int);42 static const char *config_filename = NULL; 43 static ct_buf_t config_buf; 44 static int config_fd = -1; 45 static int config_line = 0; 46 static ifd_conf_node_t config_top; 47 48 static int conf_parse_group(ifd_conf_node_t *, char); 49 static void conf_dump(ifd_conf_node_t *, int); 50 50 static ifd_conf_node_t *conf_add_node(ifd_conf_node_t *, const char *); 51 51 52 static int get_token(char **);53 static int skipws(void);54 static int ateof(void);52 static int get_token(char **); 53 static int skipws(void); 54 static int ateof(void); 55 55 56 56 /* 57 57 * Parse the ifd config file 58 58 */ 59 int 60 ifd_config_parse(const char *filename) 61 { 62 char buffer[512]; 63 int rc; 59 int ifd_config_parse(const char *filename) 60 { 61 char buffer[512]; 62 int rc; 64 63 65 64 if ((config_filename = filename) == NULL) … … 93 92 * Parse list of statements 94 93 */ 95 int 96 conf_parse_group(ifd_conf_node_t *group, char closing) 94 int conf_parse_group(ifd_conf_node_t * group, char closing) 97 95 { 98 96 ifd_conf_node_t *node; 99 char *token;100 int rc = 0;97 char *token; 98 int rc = 0; 101 99 102 100 while (1) { 103 101 if (ateof()) { 104 if (closing == (char) END_OF_FILE)102 if (closing == (char)END_OF_FILE) 105 103 break; 106 104 ct_error("%s:%u: unexpected end of file", 107 config_filename, 108 config_line); 105 config_filename, config_line); 109 106 return -1; 110 107 } … … 143 140 if ((rc = get_token(&token)) < 0) 144 141 break; 145 } else 146 if (*token == GROUP_BEGIN || *token == COMMA) { 142 } else if (*token == GROUP_BEGIN || *token == COMMA) { 147 143 /* Do-nothing cases: 148 * name { ... }149 * foo, bar, baz, ...144 * name { ... } 145 * foo, bar, baz, ... 150 146 */ 151 147 } else { … … 158 154 * token */ 159 155 if ((rc = conf_parse_group(node, GROUP_END)) < 0 160 || (rc = get_token(&token)) < 0)156 || (rc = get_token(&token)) < 0) 161 157 break; 162 158 } … … 168 164 return rc; 169 165 170 unexpected:166 unexpected: 171 167 ct_error("%s: line %d: unexpected token \"%s\"", 172 config_filename, config_line, token);168 config_filename, config_line, token); 173 169 return -1; 174 170 } … … 177 173 * Debugging - dump the config tree 178 174 */ 179 void 180 conf_dump(ifd_conf_node_t *node, int indent) 175 void conf_dump(ifd_conf_node_t * node, int indent) 181 176 { 182 177 for (; node; node = node->next) { … … 189 184 if (node->children) { 190 185 printf(" %c\n", GROUP_BEGIN); 191 conf_dump(node->children, indent +2);186 conf_dump(node->children, indent + 2); 192 187 printf("%*.*s%c", indent, indent, "", GROUP_END); 193 188 } else { … … 201 196 * Config node handling 202 197 */ 203 ifd_conf_node_t * 204 conf_add_node(ifd_conf_node_t *parent, const char *name) 205 { 206 ifd_conf_node_t **p, *node; 198 ifd_conf_node_t *conf_add_node(ifd_conf_node_t * parent, const char *name) 199 { 200 ifd_conf_node_t **p, *node; 207 201 208 202 node = (ifd_conf_node_t *) calloc(1, sizeof(*node)); 209 203 node->name = strdup(name); 210 204 211 for (p = &parent->children; *p; p = &(*p)->next) 212 ; 205 for (p = &parent->children; *p; p = &(*p)->next) ; 213 206 *p = node; 214 207 … … 216 209 } 217 210 218 static ifd_conf_node_t * 219 conf_find_node(ifd_conf_node_t *node, const char *name) 220 { 221 unsigned int len; 211 static ifd_conf_node_t *conf_find_node(ifd_conf_node_t * node, const char *name) 212 { 213 unsigned int len; 222 214 223 215 if (!name) … … 229 221 230 222 len = strcspn(name, "."); 231 223 232 224 for (node = node->children; node; node = node->next) { 233 225 if (!strncmp(node->name, name, len) 234 && node->name[len] == '\0')226 && node->name[len] == '\0') 235 227 return conf_find_node(node, name + len); 236 228 } … … 239 231 } 240 232 233 int ifd_conf_get_string(const char *name, char **result) 234 { 235 return ifd_conf_node_get_string(&config_top, name, result); 236 } 237 238 int ifd_conf_get_bool(const char *name, unsigned int *result) 239 { 240 return ifd_conf_node_get_bool(&config_top, name, result); 241 } 242 243 int ifd_conf_get_integer(const char *name, unsigned int *result) 244 { 245 return ifd_conf_node_get_integer(&config_top, name, result); 246 } 247 248 int ifd_conf_get_string_list(const char *name, char **list, size_t max) 249 { 250 return ifd_conf_node_get_string_list(&config_top, name, list, max); 251 } 252 253 int ifd_conf_get_nodes(const char *name, ifd_conf_node_t ** list, size_t max) 254 { 255 return ifd_conf_node_get_nodes(&config_top, name, list, max); 256 } 257 241 258 int 242 ifd_conf_get_string(const char *name, char **result) 243 { 244 return ifd_conf_node_get_string(&config_top, name, result); 259 ifd_conf_node_get_string(ifd_conf_node_t * node, 260 const char *name, char **result) 261 { 262 if (!(node = conf_find_node(node, name)) 263 || !node->value) 264 return -1; 265 266 *result = node->value; 267 return 0; 245 268 } 246 269 247 270 int 248 ifd_conf_get_bool(const char *name, unsigned int*result) 249 { 250 return ifd_conf_node_get_bool(&config_top, name, result); 271 ifd_conf_node_get_integer(ifd_conf_node_t * node, 272 const char *name, unsigned int *result) 273 { 274 if (!(node = conf_find_node(node, name)) 275 || !node->value) 276 return -1; 277 278 *result = strtoul(node->value, 0, 0); 279 return 0; 251 280 } 252 281 253 282 int 254 ifd_conf_get_integer(const char *name, unsigned int*result) 255 { 256 return ifd_conf_node_get_integer(&config_top, name, result); 257 } 258 259 int 260 ifd_conf_get_string_list(const char *name, char **list, size_t max) 261 { 262 return ifd_conf_node_get_string_list(&config_top, name, list, max); 263 } 264 265 int 266 ifd_conf_get_nodes(const char *name, ifd_conf_node_t **list, size_t max) 267 { 268 return ifd_conf_node_get_nodes(&config_top, name, list, max); 269 } 270 271 272 int 273 ifd_conf_node_get_string(ifd_conf_node_t *node, 274 const char *name, char **result) 275 { 283 ifd_conf_node_get_bool(ifd_conf_node_t * node, 284 const char *name, unsigned int *result) 285 { 286 const char *v; 287 276 288 if (!(node = conf_find_node(node, name)) 277 || !node->value) 278 return -1; 279 280 *result = node->value; 281 return 0; 282 } 283 284 int 285 ifd_conf_node_get_integer(ifd_conf_node_t *node, 286 const char *name, unsigned int *result) 287 { 288 if (!(node = conf_find_node(node, name)) 289 || !node->value) 290 return -1; 291 292 *result = strtoul(node->value, 0, 0); 293 return 0; 294 } 295 296 int 297 ifd_conf_node_get_bool(ifd_conf_node_t *node, 298 const char *name, unsigned int *result) 299 { 300 const char *v; 301 302 if (!(node = conf_find_node(node, name)) 303 || !(v = node->value)) 289 || !(v = node->value)) 304 290 return -1; 305 291 306 292 if (!strcmp(v, "0") 307 || !strcmp(v, "off")308 || !strcmp(v, "no")) {293 || !strcmp(v, "off") 294 || !strcmp(v, "no")) { 309 295 *result = 0; 310 } else 311 if (!strcmp(v, "1") 312 || !strcmp(v, "on") 313 || !strcmp(v, "yes")) { 296 } else if (!strcmp(v, "1") 297 || !strcmp(v, "on") 298 || !strcmp(v, "yes")) { 314 299 *result = 1; 315 300 } else { … … 321 306 322 307 int 323 ifd_conf_node_get_string_list(ifd_conf_node_t * node,324 const char *name, char **list, size_t max)325 { 326 unsigned int j = 0;308 ifd_conf_node_get_string_list(ifd_conf_node_t * node, 309 const char *name, char **list, size_t max) 310 { 311 unsigned int j = 0; 327 312 328 313 if (!(node = conf_find_node(node, name))) … … 339 324 340 325 int 341 ifd_conf_node_get_nodes(ifd_conf_node_t * node,342 const char *name, ifd_conf_node_t **list, size_t max)343 { 344 unsigned int j = 0;326 ifd_conf_node_get_nodes(ifd_conf_node_t * node, 327 const char *name, ifd_conf_node_t ** list, size_t max) 328 { 329 unsigned int j = 0; 345 330 346 331 for (node = node->children; node; node = node->next) { … … 358 343 * Tokenizer 359 344 */ 360 int 361 get_token(char **tok) 362 { 363 static char buffer[512]; 364 unsigned int m, n, copy, retry = 1; 365 char *s; 345 int get_token(char **tok) 346 { 347 static char buffer[512]; 348 unsigned int m, n, copy, retry = 1; 349 char *s; 366 350 367 351 /* consume initial white space */ … … 369 353 return -1; 370 354 371 again: s = (char *)ct_buf_head(&config_buf);355 again:s = (char *)ct_buf_head(&config_buf); 372 356 n = ct_buf_avail(&config_buf); 373 357 … … 375 359 m = 1; 376 360 } else { 377 for (m = 0; !isspace((int) s[m]) && !issepa(s[m]) && m < n; m++)378 ;361 for (m = 0; !isspace((int)s[m]) && !issepa(s[m]) && m < n; 362 m++) ; 379 363 } 380 364 … … 385 369 if (ct_buf_read(&config_buf, config_fd) < 0) { 386 370 ct_error("%s: error while reading file: %m", 387 config_filename);371 config_filename); 388 372 return -1; 389 373 } … … 396 380 397 381 if ((copy = m) >= sizeof(buffer)) 398 copy = sizeof(buffer) -1;382 copy = sizeof(buffer) - 1; 399 383 memcpy(buffer, s, copy); 400 384 buffer[copy] = '\0'; … … 410 394 * Check if we're at the end of the file 411 395 */ 412 int 413 ateof(void) 414 { 415 int retry = 1; 416 417 again: 396 int ateof(void) 397 { 398 int retry = 1; 399 400 again: 418 401 if (skipws() < 0) 419 402 return -1; … … 425 408 if (ct_buf_read(&config_buf, config_fd) < 0) { 426 409 ct_error("%s: error while reading file: %m", 427 config_filename);410 config_filename); 428 411 return -1; 429 412 } … … 438 421 * Eat initial white space from buffer 439 422 */ 440 int 441 skipws(void) 442 { 443 unsigned int m, n, in_comment = 0; 444 char *s; 445 446 again: 447 s = (char *) ct_buf_head(&config_buf); 423 int skipws(void) 424 { 425 unsigned int m, n, in_comment = 0; 426 char *s; 427 428 again: 429 s = (char *)ct_buf_head(&config_buf); 448 430 n = ct_buf_avail(&config_buf); 449 431 … … 451 433 if (*s == '#') { 452 434 in_comment = 1; 453 } else if (!in_comment && !isspace((int) *s)) {435 } else if (!in_comment && !isspace((int)*s)) { 454 436 break; 455 437 } else if (*s == '\n') { … … 463 445 if (ct_buf_read(&config_buf, config_fd) < 0) { 464 446 ct_error("%s: error while reading file: %m", 465 config_filename);447 config_filename); 466 448 return -1; 467 449 } -
trunk/src/ifd/ctbcs.c
r354 r656 16 16 * Start building CTBCS apdu 17 17 */ 18 void 19 ctbcs_begin(ct_buf_t *bp, unsigned int ins, unsigned int p1,unsigned int p2)18 void ctbcs_begin(ct_buf_t * bp, unsigned int ins, unsigned int p1, 19 unsigned int p2) 20 20 { 21 21 ct_buf_putc(bp, 0x20); … … 29 29 * Finish CTBCS apdu 30 30 */ 31 int 32 ctbcs_finish(ct_buf_t *bp) 31 int ctbcs_finish(ct_buf_t * bp) 33 32 { 34 unsigned int len;33 unsigned int len; 35 34 36 35 if (ct_buf_overrun(bp)) … … 38 37 39 38 len = ct_buf_avail(bp); 40 bp->base[4] = len - 5; /* lc */39 bp->base[4] = len - 5; /* lc */ 41 40 return len; 42 41 } … … 45 44 * Output a string to the display 46 45 */ 47 int 48 ctbcs_build_output(unsigned char *cmd, size_t size, const char *message) 46 int ctbcs_build_output(unsigned char *cmd, size_t size, const char *message) 49 47 { 50 ct_buf_t buf;48 ct_buf_t buf; 51 49 52 50 if (message == NULL) … … 62 60 * Generic Verify APDU 63 61 */ 64 int 65 ctbcs_build_verify_apdu(unsigned char *cmd, size_t size, 66 unsigned char ins, unsigned char p1, 67 const char *prompt, unsigned int timeout, 68 const unsigned char *data, size_t data_len) 62 int ctbcs_build_verify_apdu(unsigned char *cmd, size_t size, unsigned char ins, 63 unsigned char p1, const char *prompt, 64 unsigned int timeout, const unsigned char *data, 65 size_t data_len) 69 66 { 70 ct_buf_t buf;67 ct_buf_t buf; 71 68 72 69 if (!data || !data_len) … … 91 88 return IFD_ERROR_BUFFER_TOO_SMALL; 92 89 93 cmd[4] = ct_buf_avail(&buf) - 5; /* lc */90 cmd[4] = ct_buf_avail(&buf) - 5; /* lc */ 94 91 return ct_buf_avail(&buf); 95 92 } … … 98 95 * Build Perform Verify APDU 99 96 */ 100 int 101 ctbcs_build_perform_verify_apdu(unsigned char *cmd, size_t size, 102 unsigned int p1, const char *prompt, 103 unsigned int timeout, 104 const unsigned char *data, size_t data_len) 97 int ctbcs_build_perform_verify_apdu(unsigned char *cmd, size_t size, 98 unsigned int p1, const char *prompt, 99 unsigned int timeout, 100 const unsigned char *data, size_t data_len) 105 101 { 106 102 return ctbcs_build_verify_apdu(cmd, size, 0x18, p1, 107 prompt, timeout, data, data_len);103 prompt, timeout, data, data_len); 108 104 } 109 105 … … 111 107 * Build Modify Verify APDU 112 108 */ 113 int 114 ctbcs_build_modify_verify_apdu(unsigned char *cmd, size_t size, 115 unsigned int p1, const char *prompt, 116 unsigned int timeout, 117 const unsigned char *data, size_t data_len) 109 int ctbcs_build_modify_verify_apdu(unsigned char *cmd, size_t size, 110 unsigned int p1, const char *prompt, 111 unsigned int timeout, 112 const unsigned char *data, size_t data_len) 118 113 { 119 114 return ctbcs_build_verify_apdu(cmd, size, 0x19, p1, 120 prompt, timeout, data, data_len);115 prompt, timeout, data, data_len); 121 116 } 122 117 … … 125 120 * buffer 126 121 */ 127 int 128 ctbcs_add_timeout(ct_buf_t *bp, unsigned int timeout) 122 int ctbcs_add_timeout(ct_buf_t * bp, unsigned int timeout) 129 123 { 130 124 if (!timeout) … … 136 130 } 137 131 138 int 139 ctbcs_add_message(ct_buf_t *bp, const char *message) 132 int ctbcs_add_message(ct_buf_t * bp, const char *message) 140 133 { 141 int n;134 int n; 142 135 143 136 if (!message || !strcmp(message, "@")) -
trunk/src/ifd/ctbcs.h
r250 r656 9 9 #define IFD_CTBCS_H 10 10 11 extern int ctbcs_build_output(unsigned char *cmd, size_t size, 12 const char *message); 13 extern int ctbcs_build_perform_verify_apdu( 14 unsigned char *cmd, size_t size, 15 unsigned int slot, const char *prompt, 16 unsigned int timeout, 17 const unsigned char *data, size_t data_len); 18 extern int ctbcs_build_modify_verify_apdu( 19 unsigned char *cmd, size_t size, 20 unsigned int dest, const char *prompt, 21 unsigned int timeout, 22 const unsigned char *data, size_t data_len); 11 extern int ctbcs_build_output(unsigned char *cmd, size_t size, 12 const char *message); 13 extern int ctbcs_build_perform_verify_apdu(unsigned char *cmd, size_t size, 14 unsigned int slot, 15 const char *prompt, 16 unsigned int timeout, 17 const unsigned char *data, 18 size_t data_len); 19 extern int ctbcs_build_modify_verify_apdu(unsigned char *cmd, size_t size, 20 unsigned int dest, const char *prompt, 21 unsigned int timeout, 22 const unsigned char *data, 23 size_t data_len); 23 24 24 extern void ctbcs_begin(ct_buf_t *, unsigned int, unsigned int, unsigned int);25 extern int ctbcs_finish(ct_buf_t *);26 extern int ctbcs_add_message(ct_buf_t *, const char *);27 extern int ctbcs_add_timeout(ct_buf_t *, unsigned int);25 extern void ctbcs_begin(ct_buf_t *, unsigned int, unsigned int, unsigned int); 26 extern int ctbcs_finish(ct_buf_t *); 27 extern int ctbcs_add_message(ct_buf_t *, const char *); 28 extern int ctbcs_add_timeout(ct_buf_t *, unsigned int); 28 29 29 #endif /* IFD_CTBCS_H */30 #endif /* IFD_CTBCS_H */
Note: See TracChangeset
for help on using the changeset viewer.
