diff options
author | Werner Koch <wk@gnupg.org> | 2011-02-04 12:57:53 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2011-02-04 12:57:53 +0100 |
commit | b008274afdbe375b32a7e66dbd073e200f6f0587 (patch) | |
tree | 219e239d39cf06be3f03aa82fb572080ac163a15 /scd/ccid-driver.c | |
parent | Let autogen.sh check the git config (diff) | |
download | gnupg2-b008274afdbe375b32a7e66dbd073e200f6f0587.tar.xz gnupg2-b008274afdbe375b32a7e66dbd073e200f6f0587.zip |
Nuked almost all trailing white space.post-nuke-of-trailing-ws
We better do this once and for all instead of cluttering all future
commits with diffs of trailing white spaces. In the majority of cases
blank or single lines are affected and thus this change won't disturb
a git blame too much. For future commits the pre-commit scripts
checks that this won't happen again.
Diffstat (limited to 'scd/ccid-driver.c')
-rw-r--r-- | scd/ccid-driver.c | 274 |
1 files changed, 137 insertions, 137 deletions
diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c index 98268c00c..2abb6b5b1 100644 --- a/scd/ccid-driver.c +++ b/scd/ccid-driver.c @@ -57,7 +57,7 @@ /* CCID (ChipCardInterfaceDevices) is a specification for accessing - smartcard via a reader connected to the USB. + smartcard via a reader connected to the USB. This is a limited driver allowing to use some CCID drivers directly without any other specila drivers. This is a fallback driver to be @@ -220,20 +220,20 @@ enum { }; static struct -{ +{ char *name; /* Device name. */ int type; } transports[] = { - { "/dev/cmx0", TRANSPORT_CM4040 }, - { "/dev/cmx1", TRANSPORT_CM4040 }, + { "/dev/cmx0", TRANSPORT_CM4040 }, + { "/dev/cmx1", TRANSPORT_CM4040 }, { NULL }, }; /* Store information on the driver's state. A pointer to such a structure is used as handle for most functions. */ -struct ccid_driver_s +struct ccid_driver_s { usb_dev_handle *idev; char *rid; @@ -271,7 +271,7 @@ struct ccid_driver_s static int initialized_usb; /* Tracks whether USB has been initialized. */ -static int debug_level; /* Flag to control the debug output. +static int debug_level; /* Flag to control the debug output. 0 = No debugging 1 = USB I/O info 2 = Level 1 + T=1 protocol tracing @@ -290,19 +290,19 @@ static int abort_cmd (ccid_driver_t handle, int seqno); /* Convert a little endian stored 4 byte value into an unsigned integer. */ -static unsigned int +static unsigned int convert_le_u32 (const unsigned char *buf) { - return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); + return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); } /* Convert a little endian stored 2 byte value into an unsigned integer. */ -static unsigned int +static unsigned int convert_le_u16 (const unsigned char *buf) { - return buf[0] | (buf[1] << 8); + return buf[0] | (buf[1] << 8); } static void @@ -323,7 +323,7 @@ my_sleep (int seconds) may give up its timeslot. */ if (!seconds) { -# ifdef HAVE_W32_SYSTEM +# ifdef HAVE_W32_SYSTEM Sleep (0); # else sleep (0); @@ -331,7 +331,7 @@ my_sleep (int seconds) } pth_sleep (seconds); #else -# ifdef HAVE_W32_SYSTEM +# ifdef HAVE_W32_SYSTEM Sleep (seconds*1000); # else sleep (seconds); @@ -372,7 +372,7 @@ print_command_failed (const unsigned char *msg) switch (ec) { case 0x00: t = "Command not supported"; break; - + case 0xE0: t = "Slot busy"; break; case 0xEF: t = "PIN cancelled"; break; case 0xF0: t = "PIN timeout"; break; @@ -423,7 +423,7 @@ print_pr_data (const unsigned char *data, size_t datalen, size_t off) DEBUGOUT_LF (); } - + static void print_p2r_header (const char *name, const unsigned char *msg, size_t msglen) { @@ -647,7 +647,7 @@ print_r2p_slotstatus (const unsigned char *msg, size_t msglen) msg[9] == 3? " (stopped)":""); print_pr_data (msg, msglen, 10); } - + static void print_r2p_parameters (const unsigned char *msg, size_t msglen) @@ -771,7 +771,7 @@ parse_ccid_descriptor (ccid_driver_t handle, DEBUGOUT_1 (" bLength %5u\n", buf[0]); DEBUGOUT_1 (" bDescriptorType %5u\n", buf[1]); DEBUGOUT_2 (" bcdCCID %2x.%02x", buf[3], buf[2]); - if (buf[3] != 1 || buf[2] != 0) + if (buf[3] != 1 || buf[2] != 0) DEBUGOUT_CONT(" (Warning: Only accurate for version 1.0)"); DEBUGOUT_LF (); @@ -803,7 +803,7 @@ parse_ccid_descriptor (ccid_driver_t handle, us = convert_le_u32(buf+23); DEBUGOUT_1 (" dwMaxDataRate %7u bps\n", us); DEBUGOUT_1 (" bNumDataRatesSupp. %5u\n", buf[27]); - + us = convert_le_u32(buf+28); DEBUGOUT_1 (" dwMaxIFSD %5u\n", us); handle->max_ifsd = us; @@ -869,7 +869,7 @@ parse_ccid_descriptor (ccid_driver_t handle, { DEBUGOUT (" TPDU level exchange\n"); have_tpdu = 1; - } + } else if ((us & 0x00020000)) { DEBUGOUT (" Short APDU level exchange\n"); @@ -903,7 +903,7 @@ parse_ccid_descriptor (ccid_driver_t handle, DEBUGOUT_CONT ("none\n"); else DEBUGOUT_CONT_2 ("%u cols %u lines\n", buf[50], buf[51]); - + DEBUGOUT_1 (" bPINSupport %5u ", buf[52]); if ((buf[52] & 1)) { @@ -916,7 +916,7 @@ parse_ccid_descriptor (ccid_driver_t handle, handle->has_pinpad |= 2; } DEBUGOUT_LF (); - + DEBUGOUT_1 (" bMaxCCIDBusySlots %5u\n", buf[53]); if (buf[0] > 54) @@ -942,18 +942,18 @@ parse_ccid_descriptor (ccid_driver_t handle, lower than that: 64 - 10 CCID header - 4 T1frame - 2 reserved = 48 Product Ids: - 0xe001 - SCR 331 - 0x5111 - SCR 331-DI - 0x5115 - SCR 335 - 0xe003 - SPR 532 - The + 0xe001 - SCR 331 + 0x5111 - SCR 331-DI + 0x5115 - SCR 335 + 0xe003 - SPR 532 + The 0x5117 - SCR 3320 USB ID-000 reader seems to be very slow but enabling this workaround boosts the - performance to a a more or less acceptable level (tested by David). - + performance to a a more or less acceptable level (tested by David). + */ if (handle->id_vendor == VENDOR_SCM - && handle->max_ifsd > 48 + && handle->max_ifsd > 48 && ( (handle->id_product == 0xe001 && handle->bcd_device < 0x0516) ||(handle->id_product == 0x5111 && handle->bcd_device < 0x0620) ||(handle->id_product == 0x5115 && handle->bcd_device < 0x0514) @@ -992,7 +992,7 @@ get_escaped_usb_string (usb_dev_handle *idev, int idx, If we do don't find it we try to use English. Note that this is all in a 2 bute Unicode encoding using little endian. */ rc = usb_control_msg (idev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, - (USB_DT_STRING << 8), 0, + (USB_DT_STRING << 8), 0, (char*)buf, sizeof buf, 1000 /* ms timeout */); if (rc < 4) langid = 0x0409; /* English. */ @@ -1014,7 +1014,7 @@ get_escaped_usb_string (usb_dev_handle *idev, int idx, n++; /* High byte set. */ else if (*s <= 0x20 || *s >= 0x7f || *s == '%' || *s == ':') n += 3 ; - else + else n++; } @@ -1033,7 +1033,7 @@ get_escaped_usb_string (usb_dev_handle *idev, int idx, sprintf (result+n, "%%%02X", *s); n += 3; } - else + else result[n++] = *s; } strcpy (result+n, suffix); @@ -1115,7 +1115,7 @@ scan_or_find_usb_device (int scan_mode, int ifc_no; int set_no; struct usb_config_descriptor *config; - struct usb_interface *interface; + struct usb_interface *interface; struct usb_interface_descriptor *ifcdesc; char *rid; usb_dev_handle *idev; @@ -1133,7 +1133,7 @@ scan_or_find_usb_device (int scan_mode, interface = config->interface + ifc_no; if (!interface) continue; - + for (set_no=0; set_no < interface->num_altsetting; set_no++) { ifcdesc = (interface->altsetting + set_no); @@ -1156,7 +1156,7 @@ scan_or_find_usb_device (int scan_mode, strerror (errno)); continue; /* with next setting. */ } - + rid = make_reader_id (idev, dev->descriptor.idVendor, dev->descriptor.idProduct, @@ -1166,7 +1166,7 @@ scan_or_find_usb_device (int scan_mode, if (scan_mode) { char *p; - + /* We are collecting infos about all available CCID readers. Store them and continue. */ @@ -1188,7 +1188,7 @@ scan_or_find_usb_device (int scan_mode, } else /* Out of memory. */ free (rid); - + rid = NULL; ++*count; } @@ -1232,7 +1232,7 @@ scan_or_find_usb_device (int scan_mode, } else free (rid); - + *r_idev = idev; return 1; /* Found requested device. */ } @@ -1246,7 +1246,7 @@ scan_or_find_usb_device (int scan_mode, } free (rid); } - + usb_close (idev); idev = NULL; return 0; @@ -1259,7 +1259,7 @@ scan_or_find_usb_device (int scan_mode, } /* Combination function to either scan all CCID devices or to find and - open one specific device. + open one specific device. The function returns 0 if a reader has been found or when a scan returned without error. @@ -1318,7 +1318,7 @@ scan_or_find_devices (int readerno, const char *readerid, if (r_rid) *r_rid = NULL; if (r_dev) - *r_dev = NULL; + *r_dev = NULL; if (ifcdesc_extra) *ifcdesc_extra = NULL; if (ifcdesc_extra_len) @@ -1331,7 +1331,7 @@ scan_or_find_devices (int readerno, const char *readerid, *r_fd = -1; /* See whether we want scan or find mode. */ - if (scan_mode) + if (scan_mode) { assert (r_rid); } @@ -1345,7 +1345,7 @@ scan_or_find_devices (int readerno, const char *readerid, busses = usb_busses; #endif - for (bus = busses; bus; bus = bus->next) + for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { @@ -1367,7 +1367,7 @@ scan_or_find_devices (int readerno, const char *readerid, return -1; /* error */ } *r_idev = idev; - return 0; + return 0; } } } @@ -1494,9 +1494,9 @@ ccid_get_reader_list (void) } -/* Open the reader with the internal number READERNO and return a +/* Open the reader with the internal number READERNO and return a pointer to be used as handle in HANDLE. Returns 0 on success. */ -int +int ccid_open_reader (ccid_driver_t *handle, const char *readerid) { int rc = 0; @@ -1592,7 +1592,7 @@ ccid_open_reader (ccid_driver_t *handle, const char *readerid) rc = CCID_DRIVER_ERR_NO_READER; goto leave; } - + rc = usb_claim_interface (idev, ifc_no); if (rc) { @@ -1626,7 +1626,7 @@ do_close_reader (ccid_driver_t handle) unsigned char msg[100]; size_t msglen; unsigned char seqno; - + if (!handle->powered_off) { msg[0] = PC_to_RDR_IccPowerOff; @@ -1637,7 +1637,7 @@ do_close_reader (ccid_driver_t handle) msg[9] = 0; /* RFU */ set_msg_len (msg, 0); msglen = 10; - + rc = bulk_out (handle, msg, msglen, 0); if (!rc) bulk_in (handle, msg, sizeof msg, &msglen, RDR_to_PC_SlotStatus, @@ -1661,12 +1661,12 @@ do_close_reader (ccid_driver_t handle) /* Reset a reader on HANDLE. This is useful in case a reader has been plugged of and inserted at a different port. By resetting the handle, the same reader will be get used. Note, that on error the - handle won't get released. + handle won't get released. This does not return an ATR, so ccid_get_atr should be called right after this one. */ -int +int ccid_shutdown_reader (ccid_driver_t handle) { int rc = 0; @@ -1704,7 +1704,7 @@ ccid_shutdown_reader (ccid_driver_t handle) rc = CCID_DRIVER_ERR_NO_READER; goto leave; } - + rc = usb_claim_interface (idev, ifc_no); if (rc) { @@ -1731,8 +1731,8 @@ ccid_shutdown_reader (ccid_driver_t handle) } -int -ccid_set_progress_cb (ccid_driver_t handle, +int +ccid_set_progress_cb (ccid_driver_t handle, void (*cb)(void *, const char *, int, int, int), void *cb_arg) { @@ -1746,7 +1746,7 @@ ccid_set_progress_cb (ccid_driver_t handle, /* Close the reader HANDLE. */ -int +int ccid_close_reader (ccid_driver_t handle) { if (!handle || (!handle->idev && handle->dev_fd == -1)) @@ -1774,7 +1774,7 @@ writen (int fd, const void *buf, size_t nbytes) { size_t nleft = nbytes; int nwritten; - + while (nleft > 0) { nwritten = write (fd, buf, nleft); @@ -1788,7 +1788,7 @@ writen (int fd, const void *buf, size_t nbytes) nleft -= nwritten; buf = (const char*)buf + nwritten; } - + return 0; } @@ -1857,10 +1857,10 @@ bulk_out (ccid_driver_t handle, unsigned char *msg, size_t msglen, break; } } - + if (handle->idev) { - rc = usb_bulk_write (handle->idev, + rc = usb_bulk_write (handle->idev, handle->ep_bulk_out, (char*)msg, msglen, 5000 /* ms timeout */); @@ -1897,7 +1897,7 @@ bulk_out (ccid_driver_t handle, unsigned char *msg, size_t msglen, return 0; DEBUGOUT_2 ("writen to %d failed: %s\n", handle->dev_fd, strerror (errno)); - + } return CCID_DRIVER_ERR_CARD_IO_ERROR; } @@ -1925,7 +1925,7 @@ bulk_in (ccid_driver_t handle, unsigned char *buffer, size_t length, retry: if (handle->idev) { - rc = usb_bulk_read (handle->idev, + rc = usb_bulk_read (handle->idev, handle->ep_bulk_in, (char*)buffer, length, timeout); @@ -1967,12 +1967,12 @@ bulk_in (ccid_driver_t handle, unsigned char *buffer, size_t length, abort_cmd (handle, seqno); return CCID_DRIVER_ERR_INV_VALUE; } - if (buffer[5] != 0) + if (buffer[5] != 0) { DEBUGOUT_1 ("unexpected bulk-in slot (%d)\n", buffer[5]); return CCID_DRIVER_ERR_INV_VALUE; } - if (buffer[6] != seqno) + if (buffer[6] != seqno) { DEBUGOUT_2 ("bulk-in seqno does not match (%d/%d)\n", seqno, buffer[6]); @@ -1985,7 +1985,7 @@ bulk_in (ccid_driver_t handle, unsigned char *buffer, size_t length, for the Cherry keyboard which sends a time extension request for each key hit. */ if ( !(buffer[7] & 0x03) && (buffer[7] & 0xC0) == 0x80) - { + { /* Card present and active, time extension requested. */ DEBUGOUT_2 ("time extension requested (%02X,%02X)\n", buffer[7], buffer[8]); @@ -2055,13 +2055,13 @@ abort_cmd (ccid_driver_t handle, int seqno) /* I don't know how to send an abort to non-USB devices. */ rc = CCID_DRIVER_ERR_NOT_SUPPORTED; } - + seqno &= 0xff; DEBUGOUT_1 ("sending abort sequence for seqno %d\n", seqno); /* Send the abort command to the control pipe. Note that we don't need to keep track of sent abort commands because there should never be another thread using the same slot concurrently. */ - rc = usb_control_msg (handle->idev, + rc = usb_control_msg (handle->idev, 0x21,/* bmRequestType: host-to-device, class specific, to interface. */ 1, /* ABORT */ @@ -2081,7 +2081,7 @@ abort_cmd (ccid_driver_t handle, int seqno) seqno--; /* Adjust for next increment. */ do { - seqno++; + seqno++; msg[0] = PC_to_RDR_Abort; msg[5] = 0; /* slot */ msg[6] = seqno; @@ -2091,24 +2091,24 @@ abort_cmd (ccid_driver_t handle, int seqno) msglen = 10; set_msg_len (msg, 0); - rc = usb_bulk_write (handle->idev, + rc = usb_bulk_write (handle->idev, handle->ep_bulk_out, (char*)msg, msglen, 5000 /* ms timeout */); if (rc == msglen) rc = 0; else if (rc == -1) - DEBUGOUT_1 ("usb_bulk_write error in abort_cmd: %s\n", + DEBUGOUT_1 ("usb_bulk_write error in abort_cmd: %s\n", strerror (errno)); else DEBUGOUT_1 ("usb_bulk_write failed in abort_cmd: %d\n", rc); if (rc) return rc; - - rc = usb_bulk_read (handle->idev, + + rc = usb_bulk_read (handle->idev, handle->ep_bulk_in, - (char*)msg, sizeof msg, + (char*)msg, sizeof msg, 5000 /*ms timeout*/); if (rc < 0) { @@ -2124,7 +2124,7 @@ abort_cmd (ccid_driver_t handle, int seqno) (unsigned int)msglen); return CCID_DRIVER_ERR_INV_VALUE; } - if (msg[5] != 0) + if (msg[5] != 0) { DEBUGOUT_1 ("unexpected bulk-in slot (%d) in abort_cmd\n", msg[5]); return CCID_DRIVER_ERR_INV_VALUE; @@ -2149,7 +2149,7 @@ abort_cmd (ccid_driver_t handle, int seqno) operation will get returned in RESULT and its length in RESULTLEN. If the response is larger than RESULTMAX, an error is returned and the required buffer length returned in RESULTLEN. */ -static int +static int send_escape_cmd (ccid_driver_t handle, const unsigned char *data, size_t datalen, unsigned char *result, size_t resultmax, size_t *resultlen) @@ -2201,7 +2201,7 @@ send_escape_cmd (ccid_driver_t handle, default: break; } - + return rc; } @@ -2227,14 +2227,14 @@ ccid_poll (ccid_driver_t handle) if (handle->idev) { - rc = usb_bulk_read (handle->idev, + rc = usb_bulk_read (handle->idev, handle->ep_intr, (char*)msg, sizeof msg, 0 /* ms timeout */ ); if (rc < 0 && errno == ETIMEDOUT) return 0; } - else + else return 0; if (rc < 0) @@ -2258,12 +2258,12 @@ ccid_poll (ccid_driver_t handle) for (i=1; i < msglen; i++) for (j=0; j < 4; j++) DEBUGOUT_CONT_3 (" %d:%c%c", - (i-1)*4+j, + (i-1)*4+j, (msg[i] & (1<<(j*2)))? 'p':'-', (msg[i] & (2<<(j*2)))? '*':' '); DEBUGOUT_LF (); } - else if (msg[0] == RDR_to_PC_HardwareError) + else if (msg[0] == RDR_to_PC_HardwareError) { DEBUGOUT ("hardware error occured\n"); } @@ -2278,7 +2278,7 @@ ccid_poll (ccid_driver_t handle) /* Note that this function won't return the error codes NO_CARD or CARD_INACTIVE */ -int +int ccid_slot_status (ccid_driver_t handle, int *statusbits) { int rc; @@ -2328,7 +2328,7 @@ ccid_slot_status (ccid_driver_t handle, int *statusbits) /* Return the ATR of the card. This is not a cached value and thus an actual reset is done. */ -int +int ccid_get_atr (ccid_driver_t handle, unsigned char *atr, size_t maxatrlen, size_t *atrlen) { @@ -2387,7 +2387,7 @@ ccid_get_atr (ccid_driver_t handle, handle->powered_off = 0; - + if (atr) { size_t n = msglen - 10; @@ -2462,7 +2462,7 @@ ccid_get_atr (ccid_driver_t handle, tpdu[0] = handle->nonnull_nad? ((1 << 4) | 0): 0; tpdu[1] = (0xc0 | 0 | 1); /* S-block request: change IFSD */ tpdu[2] = 1; - tpdu[3] = handle->max_ifsd? handle->max_ifsd : 32; + tpdu[3] = handle->max_ifsd? handle->max_ifsd : 32; tpdulen = 4; edc = compute_edc (tpdu, tpdulen, use_crc); if (use_crc) @@ -2472,7 +2472,7 @@ ccid_get_atr (ccid_driver_t handle, msg[0] = PC_to_RDR_XfrBlock; msg[5] = 0; /* slot */ msg[6] = seqno = handle->seqno++; - msg[7] = 0; + msg[7] = 0; msg[8] = 0; /* RFU */ msg[9] = 0; /* RFU */ set_msg_len (msg, tpdulen); @@ -2495,12 +2495,12 @@ ccid_get_atr (ccid_driver_t handle, RDR_to_PC_DataBlock, seqno, 5000, 0); if (rc) return rc; - + tpdu = msg + 10; tpdulen = msglen - 10; - - if (tpdulen < 4) - return CCID_DRIVER_ERR_ABORTED; + + if (tpdulen < 4) + return CCID_DRIVER_ERR_ABORTED; if (debug_level > 1) DEBUGOUT_4 ("T=1: got %c-block seq=%d err=%d%s\n", @@ -2525,7 +2525,7 @@ ccid_get_atr (ccid_driver_t handle, -static unsigned int +static unsigned int compute_edc (const unsigned char *data, size_t datalen, int use_crc) { if (use_crc) @@ -2535,7 +2535,7 @@ compute_edc (const unsigned char *data, size_t datalen, int use_crc) else { unsigned char crc = 0; - + for (; datalen; datalen--) crc ^= *data++; return crc; @@ -2580,7 +2580,7 @@ ccid_transceive_apdu_level (ccid_driver_t handle, extended APDU exchange level is not yet supported. */ if (apdulen > 261) return CCID_DRIVER_ERR_INV_VALUE; /* Invalid length. */ - + msg[0] = PC_to_RDR_XfrBlock; msg[5] = 0; /* slot */ msg[6] = seqno = handle->seqno++; @@ -2600,10 +2600,10 @@ ccid_transceive_apdu_level (ccid_driver_t handle, RDR_to_PC_DataBlock, seqno, 5000, 0); if (rc) return rc; - + apdu = msg + 10; apdulen = msglen - 10; - + if (resp) { if (apdulen > maxresplen) @@ -2613,11 +2613,11 @@ ccid_transceive_apdu_level (ccid_driver_t handle, (unsigned int)apdulen, (unsigned int)maxresplen); return CCID_DRIVER_ERR_INV_VALUE; } - - memcpy (resp, apdu, apdulen); + + memcpy (resp, apdu, apdulen); *nresp = apdulen; } - + return 0; } @@ -2628,15 +2628,15 @@ ccid_transceive_apdu_level (ccid_driver_t handle, Block Structure: Prologue Field: - 1 byte Node Address (NAD) + 1 byte Node Address (NAD) 1 byte Protocol Control Byte (PCB) - 1 byte Length (LEN) + 1 byte Length (LEN) Information Field: 0-254 byte APDU or Control Information (INF) Epilogue Field: 1 byte Error Detection Code (EDC) - NAD: + NAD: bit 7 unused bit 4..6 Destination Node Address (DAD) bit 3 unused @@ -2651,7 +2651,7 @@ ccid_transceive_apdu_level (ccid_driver_t handle, Information Block (I-Block): bit 7 0 bit 6 Sequence number (yep, that is modulo 2) - bit 5 Chaining flag + bit 5 Chaining flag bit 4..0 reserved Received-Ready Block (R-Block): bit 7 1 @@ -2754,7 +2754,7 @@ ccid_transceive (ccid_driver_t handle, if (apdulen > handle->ifsc ) { apdulen = handle->ifsc; - apdu_buf += handle->ifsc; + apdu_buf += handle->ifsc; apdu_buflen -= handle->ifsc; tpdu[1] |= (1 << 5); /* Set more bit. */ } @@ -2801,14 +2801,14 @@ ccid_transceive (ccid_driver_t handle, : !!(msg[pcboff] & 0x40)), (!(msg[pcboff] & 0x80) && (msg[pcboff] & 0x20)? " [more]":"")); - + rc = bulk_out (handle, msg, msglen, 0); if (rc) return rc; msg = recv_buffer; rc = bulk_in (handle, msg, sizeof recv_buffer, &msglen, - via_escape? RDR_to_PC_Escape : RDR_to_PC_DataBlock, + via_escape? RDR_to_PC_Escape : RDR_to_PC_DataBlock, seqno, 5000, 0); if (rc) return rc; @@ -2816,11 +2816,11 @@ ccid_transceive (ccid_driver_t handle, tpdu = msg + hdrlen; tpdulen = msglen - hdrlen; resyncing = 0; - - if (tpdulen < 4) + + if (tpdulen < 4) { usb_clear_halt (handle->idev, handle->ep_bulk_in); - return CCID_DRIVER_ERR_ABORTED; + return CCID_DRIVER_ERR_ABORTED; } if (debug_level > 1) @@ -2872,16 +2872,16 @@ ccid_transceive (ccid_driver_t handle, (unsigned int)n, (unsigned int)maxresplen); return CCID_DRIVER_ERR_INV_VALUE; } - - memcpy (resp, p, n); + + memcpy (resp, p, n); resp += n; *nresp += n; maxresplen -= n; } - + if (!(tpdu[1] & 0x20)) return 0; /* No chaining requested - ready. */ - + msg = send_buffer; tpdu = msg + hdrlen; tpdu[0] = nad_byte; @@ -2895,8 +2895,8 @@ ccid_transceive (ccid_driver_t handle, } else if ((tpdu[1] & 0xc0) == 0x80) { /* This is a R-block. */ - if ( (tpdu[1] & 0x0f)) - { + if ( (tpdu[1] & 0x0f)) + { retries++; if (via_escape && retries == 1 && (msg[pcboff] & 0x0f)) { @@ -2946,7 +2946,7 @@ ccid_transceive (ccid_driver_t handle, return CCID_DRIVER_ERR_CARD_IO_ERROR; } } - else + else { /* This is a S-block. */ retries = 0; DEBUGOUT_2 ("T=1: S-block %s received cmd=%d\n", @@ -3010,14 +3010,14 @@ ccid_transceive (ccid_driver_t handle, /* Send the CCID Secure command to the reader. APDU_BUF should contain the APDU template. PIN_MODE defines how the pin gets formatted: - + 1 := The PIN is ASCII encoded and of variable length. The length of the PIN entered will be put into Lc by the reader. The APDU should me made up of 4 bytes without Lc. PINLEN_MIN and PINLEN_MAX define the limits for the pin length. 0 may be used t enable reasonable defaults. PIN_PADLEN should be 0. - + When called with RESP and NRESP set to NULL, the function will merely check whether the reader supports the secure command for the given APDU and PIN_MODE. */ @@ -3025,7 +3025,7 @@ int ccid_transceive_secure (ccid_driver_t handle, const unsigned char *apdu_buf, size_t apdu_buflen, int pin_mode, int pinlen_min, int pinlen_max, - int pin_padlen, + int pin_padlen, unsigned char *resp, size_t maxresplen, size_t *nresp) { int rc; @@ -3049,7 +3049,7 @@ ccid_transceive_secure (ccid_driver_t handle, return CCID_DRIVER_ERR_NOT_SUPPORTED; /* Not yet by our code. */ else return CCID_DRIVER_ERR_NO_KEYPAD; - + if (pin_mode != 1) return CCID_DRIVER_ERR_NOT_SUPPORTED; @@ -3063,7 +3063,7 @@ ccid_transceive_secure (ccid_driver_t handle, /* Note that the 25 is the maximum value the SPR532 allows. */ if (pinlen_min < 1 || pinlen_min > 25 - || pinlen_max < 1 || pinlen_max > 25 + || pinlen_max < 1 || pinlen_max > 25 || pinlen_min > pinlen_max) return CCID_DRIVER_ERR_INV_VALUE; @@ -3091,7 +3091,7 @@ ccid_transceive_secure (ccid_driver_t handle, if (testmode) return 0; /* Success */ - + msg = send_buffer; if (handle->id_vendor == VENDOR_SCM) { @@ -3121,7 +3121,7 @@ ccid_transceive_secure (ccid_driver_t handle, else { msg[13] = 0x00; /* bmPINBlockString: - 0 bits of pin length to insert. + 0 bits of pin length to insert. 0 bytes of PIN block size. */ msg[14] = 0x00; /* bmPINLengthFormat: Units are bytes, position is 0. */ @@ -3157,13 +3157,13 @@ ccid_transceive_secure (ccid_driver_t handle, rc = bulk_out (handle, msg, msglen, 0); if (rc) return rc; - + msg = recv_buffer; rc = bulk_in (handle, msg, sizeof recv_buffer, &msglen, RDR_to_PC_DataBlock, seqno, 30000, 0); if (rc) return rc; - + tpdu = msg + 10; tpdulen = msglen - 10; @@ -3178,17 +3178,17 @@ ccid_transceive_secure (ccid_driver_t handle, (unsigned int)tpdulen, (unsigned int)maxresplen); return CCID_DRIVER_ERR_INV_VALUE; } - - memcpy (resp, tpdu, tpdulen); + + memcpy (resp, tpdu, tpdulen); *nresp = tpdulen; } return 0; } - - if (tpdulen < 4) + + if (tpdulen < 4) { usb_clear_halt (handle->idev, handle->ep_bulk_in); - return CCID_DRIVER_ERR_ABORTED; + return CCID_DRIVER_ERR_ABORTED; } if (debug_level > 1) DEBUGOUT_4 ("T=1: got %c-block seq=%d err=%d%s\n", @@ -3223,22 +3223,22 @@ ccid_transceive_secure (ccid_driver_t handle, (unsigned int)n, (unsigned int)maxresplen); return CCID_DRIVER_ERR_INV_VALUE; } - - memcpy (resp, p, n); + + memcpy (resp, p, n); resp += n; *nresp += n; maxresplen -= n; } - + if (!(tpdu[1] & 0x20)) return 0; /* No chaining requested - ready. */ - + DEBUGOUT ("chaining requested but not supported for Secure operation\n"); return CCID_DRIVER_ERR_CARD_IO_ERROR; } else if ((tpdu[1] & 0xc0) == 0x80) { /* This is a R-block. */ - if ( (tpdu[1] & 0x0f)) + if ( (tpdu[1] & 0x0f)) { /* Error: repeat last block */ DEBUGOUT ("No retries supported for Secure operation\n"); return CCID_DRIVER_ERR_CARD_IO_ERROR; @@ -3254,13 +3254,13 @@ ccid_transceive_secure (ccid_driver_t handle, return CCID_DRIVER_ERR_CARD_IO_ERROR; } } - else + else { /* This is a S-block. */ DEBUGOUT_2 ("T=1: S-block %s received cmd=%d for Secure operation\n", (tpdu[1] & 0x20)? "response": "request", (tpdu[1] & 0x1f)); return CCID_DRIVER_ERR_CARD_IO_ERROR; - } + } return 0; } @@ -3416,7 +3416,7 @@ main (int argc, char **argv) result, sizeof result, &resultlen); print_result (rc, result, resultlen); } - + if (!no_poll) ccid_poll (ccid); @@ -3437,7 +3437,7 @@ main (int argc, char **argv) { static unsigned char apdu[] = { 0, 0x20, 0, 0x81 }; - + if (ccid_transceive_secure (ccid, apdu, sizeof apdu, 1, 0, 0, 0, @@ -3446,7 +3446,7 @@ main (int argc, char **argv) else { fputs ("verifying CHV1 using the PINPad ....\n", stderr); - + rc = ccid_transceive_secure (ccid, apdu, sizeof apdu, 1, 0, 0, 0, @@ -3455,7 +3455,7 @@ main (int argc, char **argv) did_verify = 1; } } - + if (verify_123456 && !did_verify) { fputs ("verifying that CHV1 is 123456....\n", stderr); |