diff --git a/ccid/ccid.c b/ccid/ccid.c index 87179ae..a035026 100644 --- a/ccid/ccid.c +++ b/ccid/ccid.c @@ -8,14 +8,15 @@ #include "ccid.h" -SCARDCONTEXT hcontext = 0; -SCARDHANDLE hcard = 0; -SCARD_READERSTATE rstate; -DWORD dwActiveProtocol; -char reader_name[MAX_READERNAME]; -int reader_num; +static SCARDCONTEXT hcontext = 0; +static SCARDHANDLE hcard = 0; +static SCARD_READERSTATE rstate; +static DWORD dwActiveProtocol; +static char reader_name[MAX_READERNAME]; +static int reader_num; -char* perform_initialization(int num) + +const char* ccid_initialize(int num) { char *readers, *str; DWORD size; @@ -79,7 +80,7 @@ char* perform_initialization(int num) } -int perform_shutdown() +int ccid_shutdown() { SCardDisconnect(hcard, SCARD_UNPOWER_CARD); hcard = 0; @@ -680,13 +681,13 @@ perform_unknown(const PC_to_RDR_GetSlotStatus_t request) return result; } -int parse_ccid(const __u8* inbuf, __u8** outbuf) +int ccid_parse_bulkin(const __u8* inbuf, __u8** outbuf) { if (inbuf == NULL) return 0; int result = -1; if (SCardIsValidContext(hcontext) != SCARD_S_SUCCESS) { - if (perform_initialization(reader_num) == NULL) + if (ccid_initialize(reader_num) == NULL) goto error; } @@ -842,7 +843,7 @@ error: return result; } -int parse_ccid_control(struct usb_ctrlrequest *setup, __u8 **outbuf) +int ccid_parse_control(struct usb_ctrlrequest *setup, __u8 **outbuf) { int result = -1; __u16 value, index, length; @@ -903,3 +904,15 @@ int parse_ccid_control(struct usb_ctrlrequest *setup, __u8 **outbuf) return result; } + +int ccid_state_changed(RDR_to_PC_NotifySlotChange_t *slotchange) +{ + if (slotchange) { + *slotchange = get_RDR_to_PC_NotifySlotChange(); + + if (slotchange->bmSlotICCState) + return 1; + } + + return 0; +} diff --git a/ccid/ccid.h b/ccid/ccid.h index 89822d2..ee71bdd 100644 --- a/ccid/ccid.h +++ b/ccid/ccid.h @@ -251,40 +251,12 @@ ccid_desc = { 0x2, // PIN Modification supported .bMaxCCIDBusySlots = 0x01, }; -char* perform_initialization(int num); -int perform_shutdown(); +const char* ccid_initialize(int num); +int ccid_shutdown(); -__u8 get_bError(LONG pcsc_result); -__u8 get_bStatus(LONG pcsc_result); -RDR_to_PC_SlotStatus_t get_RDR_to_PC_SlotStatus(__u8 bSlot, __u8 bSeq, - LONG pcsc_result); -RDR_to_PC_DataBlock_t get_RDR_to_PC_DataBlock(__u8 bSlot, __u8 bSeq, - LONG pcsc_result, __le32 dwLength); -RDR_to_PC_SlotStatus_t perform_PC_to_RDR_GetSlotStatus( - const PC_to_RDR_GetSlotStatus_t request); -RDR_to_PC_SlotStatus_t perform_PC_to_RDR_GetSlotStatus( - const PC_to_RDR_GetSlotStatus_t request); -RDR_to_PC_SlotStatus_t perform_PC_to_RDR_IccPowerOn( - const PC_to_RDR_IccPowerOn_t request, char ** pATR); -RDR_to_PC_SlotStatus_t perform_PC_to_RDR_IccPowerOff( - const PC_to_RDR_IccPowerOff_t request); -RDR_to_PC_DataBlock_t perform_PC_to_RDR_XfrBlock( - const PC_to_RDR_XfrBlock_t request, const __u8* - abDataIn, __u8** abDataOut); -RDR_to_PC_Parameters_t get_RDR_to_PC_Parameters(__u8 bSlot, __u8 bSeq, - LONG pcsc_result, __u8 **abProtocolDataStructure); -RDR_to_PC_Parameters_t perform_PC_to_RDR_GetParamters( - const PC_to_RDR_GetParameters_t request, - __u8** abProtocolDataStructure); -RDR_to_PC_DataBlock_t perform_PC_to_RDR_Secure( - const PC_to_RDR_Secure_t request, const __u8* abData, - __u8** abDataOut); -RDR_to_PC_NotifySlotChange_t get_RDR_to_PC_NotifySlotChange (); -RDR_to_PC_SlotStatus_t perform_unknown( - const PC_to_RDR_GetSlotStatus_t request); - -int parse_ccid(const __u8* inbuf, __u8** outbuf); -int parse_ccid_control(struct usb_ctrlrequest *setup, __u8 **outbuf); +int ccid_parse_bulkin(const __u8* inbuf, __u8** outbuf); +int ccid_parse_control(struct usb_ctrlrequest *setup, __u8 **outbuf); +int ccid_state_changed(RDR_to_PC_NotifySlotChange_t *slotchange); #ifdef __cplusplus } diff --git a/ccid/usb.c b/ccid/usb.c index c8fe43f..93a01e5 100644 --- a/ccid/usb.c +++ b/ccid/usb.c @@ -54,7 +54,7 @@ static int verbose = 0; static int debug = 0; static int dohid = 0; static int doint = 0; -char *usb_reader_name = NULL; +const char *usb_reader_name = NULL; int usb_reader_num = 0; /* NOTE: these IDs don't imply endpoint numbering; host side drivers @@ -924,8 +924,7 @@ static void *ccid (void *param) /* so test for it explicitly. */ pthread_testcancel (); - slotchange = get_RDR_to_PC_NotifySlotChange(); - if (slotchange.bmSlotICCState) { + if (ccid_state_changed(&slotchange)) { /* don't bother host, when nothing changed */ if (debug) fprintf(stderr, "interrupt loop: writing RDR_to_PC_NotifySlotChange... "); @@ -959,7 +958,7 @@ static void *ccid (void *param) void close_pcsc() { - int result = perform_shutdown(); + int result = ccid_shutdown(); if (result != SCARD_S_SUCCESS) fprintf(stderr, "pc/sc error: %s\n", pcsc_stringify_error(result)); else if (verbose) @@ -988,10 +987,10 @@ static void *ccid (void *param) } pthread_cleanup_push (close_fd, &sink_fd); - usb_reader_name = perform_initialization(usb_reader_num); + usb_reader_name = ccid_initialize(usb_reader_num); if (usb_reader_name == NULL) { if (debug) - perror("perform_initialization"); + perror("ccid_initialize"); goto error; } pthread_cleanup_push (close_pcsc, NULL); @@ -1037,7 +1036,7 @@ static void *ccid (void *param) fprintf(stderr, "got %d, done.\n", result); if (!result) break; - result = parse_ccid(inbuf, &outbuf); + result = ccid_parse_bulkin(inbuf, &outbuf); if (result < 0) break; if (debug) @@ -1485,7 +1484,7 @@ special: switch (setup->bRequestType) { case USB_REQ_CCID: { __u8 *outbuf = NULL; - result = parse_ccid_control(setup, &outbuf); + result = ccid_parse_control(setup, &outbuf); if (result < 0 || result > 256) goto stall; if (debug)