Changeset 570 for branches

Show
Ignore:
Timestamp:
10/17/04 21:45:39 (4 years ago)
Author:
aj
Message:

increase reply buffer to 258 bytes
and add proper error handling to ifd-egate.
both by Chaskiel M Grundman.

Location:
branches/openct-0.6/src/ifd
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/openct-0.6/src/ifd/ifd-egate.c

    r503 r570  
    102102        rc = ifd_usb_control(dev, EGATE_DIR_OUT, EGATE_CMD_RESET, 
    103103                             0, 0, NULL, 0, EG_TIMEOUT); 
    104         if (rc < 0) 
    105                 goto failed; 
     104        if (rc < 0) { 
     105failed: 
     106                ct_error("egate: failed to activate token"); 
     107                return IFD_ERROR_COMM_ERROR; 
     108        } 
    106109 
    107110        rc = ifd_usb_control(reader->device, EGATE_DIR_IN, EGATE_CMD_STATUS, 
    108111                             0, 0, &stat, 1, EG_TIMEOUT); 
    109112        if (rc != 1) 
    110                 return -1; 
     113                return IFD_ERROR_COMM_ERROR; 
    111114 
    112115 
     
    127130        return atrlen; 
    128131 
    129 failed: ct_error("egate: failed to activate token"); 
    130         return -1; 
    131132} 
    132133 
     
    140141     if (proto != IFD_PROTOCOL_T0 && proto != IFD_PROTOCOL_TRANSPARENT) { 
    141142          ct_error("%s: protocol %d not supported", reader->name, proto); 
    142           return -1; 
     143          return IFD_ERROR_NOT_SUPPORTED; 
    143144     } 
    144145     slot = &reader->slot[s]; 
     
    147148     if (p == NULL) { 
    148149          ct_error("%s: internal error", reader->name); 
    149           return -1; 
     150          return IFD_ERROR_GENERIC; 
    150151     } 
    151152     if (slot->proto) { 
     
    196197                             0, 0, NULL, 0, EG_TIMEOUT); 
    197198        if (rc < 0) 
    198                 return -1; 
     199                return IFD_ERROR_COMM_ERROR; 
    199200     } 
    200201     if (ifd_iso_apdu_parse(inbuffer, inlen, &iso) < 0)  
    201          return -1; 
     202         return IFD_ERROR_INVALID_ARG; 
     203     if (inlen < 5 + iso.lc || outlen < 2 + iso.le) 
     204         return IFD_ERROR_BUFFER_TOO_SMALL; 
    202205     memset(cmdbuf,0,5); 
    203206     memmove(cmdbuf, inbuffer, inlen < 5 ? inlen : 5); 
     
    205208                        0, 0, (void *) cmdbuf, 5, -1); 
    206209     if (rc != 5) 
    207           return -1; 
     210          return IFD_ERROR_COMM_ERROR; 
    208211     stat=eg_status(reader); 
    209212     if (inlen > 5 && stat == EGATE_STATUS_DATA) { 
     
    211214                          0, 0, (void *) (((unsigned char *)inbuffer)+5), iso.lc, -1); 
    212215          if (rc < 0) 
    213                return rc; 
     216               return IFD_ERROR_COMM_ERROR; 
    214217          if (rc != iso.lc) { 
    215218               ifd_debug(1, "short USB write (%u of %u bytes)", rc, iso.lc); 
    216                return -1; 
     219               return IFD_ERROR_COMM_ERROR; 
    217220          } 
    218221          ifd_debug(3, "sent %d bytes of data", iso.lc); 
     
    223226                         (void *) outbuffer, iso.le, EG_TIMEOUT); 
    224227          if (rc < 0) 
    225                return rc; 
     228               return IFD_ERROR_COMM_ERROR; 
    226229          if (rc != iso.le) { 
    227230               ifd_debug(1, "short USB read (%u of %u bytes)", rc, iso.le); 
    228                return -1; 
     231               return IFD_ERROR_COMM_ERROR; 
    229232          } 
    230233          ifd_debug(3, "received %d bytes of data", iso.le); 
     
    233236       iso.le=0; 
    234237     if (stat != EGATE_STATUS_SW) 
    235           return -1; 
     238          return IFD_ERROR_DEVICE_DISCONNECTED; 
    236239     rc=ifd_usb_control(reader->device, EGATE_DIR_IN, EGATE_CMD_READ, 0, 0, 
    237240                    (void *) (((unsigned char *)outbuffer)+iso.le), 2, EG_TIMEOUT); 
    238241     if (rc != 2) 
    239           return -1; 
     242          return IFD_ERROR_COMM_ERROR; 
    240243     ifd_debug(2, "returning a %d byte response", iso.le + 2); 
    241244     return iso.le+2; 
  • branches/openct-0.6/src/ifd/process.c

    r510 r570  
    370370                ct_tlv_parser_t *args, ct_tlv_builder_t *resp) 
    371371{ 
    372         unsigned char   replybuf[256]; 
     372        unsigned char   replybuf[258]; 
    373373        unsigned char   *data; 
    374374        size_t          data_len;