changed naming
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@22 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
35
ccid/ccid.c
35
ccid/ccid.c
@@ -8,14 +8,15 @@
|
|||||||
#include "ccid.h"
|
#include "ccid.h"
|
||||||
|
|
||||||
|
|
||||||
SCARDCONTEXT hcontext = 0;
|
static SCARDCONTEXT hcontext = 0;
|
||||||
SCARDHANDLE hcard = 0;
|
static SCARDHANDLE hcard = 0;
|
||||||
SCARD_READERSTATE rstate;
|
static SCARD_READERSTATE rstate;
|
||||||
DWORD dwActiveProtocol;
|
static DWORD dwActiveProtocol;
|
||||||
char reader_name[MAX_READERNAME];
|
static char reader_name[MAX_READERNAME];
|
||||||
int reader_num;
|
static int reader_num;
|
||||||
|
|
||||||
char* perform_initialization(int num)
|
|
||||||
|
const char* ccid_initialize(int num)
|
||||||
{
|
{
|
||||||
char *readers, *str;
|
char *readers, *str;
|
||||||
DWORD size;
|
DWORD size;
|
||||||
@@ -79,7 +80,7 @@ char* perform_initialization(int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int perform_shutdown()
|
int ccid_shutdown()
|
||||||
{
|
{
|
||||||
SCardDisconnect(hcard, SCARD_UNPOWER_CARD);
|
SCardDisconnect(hcard, SCARD_UNPOWER_CARD);
|
||||||
hcard = 0;
|
hcard = 0;
|
||||||
@@ -680,13 +681,13 @@ perform_unknown(const PC_to_RDR_GetSlotStatus_t request)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_ccid(const __u8* inbuf, __u8** outbuf)
|
int ccid_parse_bulkin(const __u8* inbuf, __u8** outbuf)
|
||||||
{
|
{
|
||||||
if (inbuf == NULL)
|
if (inbuf == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
if (SCardIsValidContext(hcontext) != SCARD_S_SUCCESS) {
|
if (SCardIsValidContext(hcontext) != SCARD_S_SUCCESS) {
|
||||||
if (perform_initialization(reader_num) == NULL)
|
if (ccid_initialize(reader_num) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -842,7 +843,7 @@ error:
|
|||||||
return result;
|
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;
|
int result = -1;
|
||||||
__u16 value, index, length;
|
__u16 value, index, length;
|
||||||
@@ -903,3 +904,15 @@ int parse_ccid_control(struct usb_ctrlrequest *setup, __u8 **outbuf)
|
|||||||
|
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
38
ccid/ccid.h
38
ccid/ccid.h
@@ -251,40 +251,12 @@ ccid_desc = {
|
|||||||
0x2, // PIN Modification supported
|
0x2, // PIN Modification supported
|
||||||
.bMaxCCIDBusySlots = 0x01,
|
.bMaxCCIDBusySlots = 0x01,
|
||||||
};
|
};
|
||||||
char* perform_initialization(int num);
|
const char* ccid_initialize(int num);
|
||||||
int perform_shutdown();
|
int ccid_shutdown();
|
||||||
|
|
||||||
__u8 get_bError(LONG pcsc_result);
|
int ccid_parse_bulkin(const __u8* inbuf, __u8** outbuf);
|
||||||
__u8 get_bStatus(LONG pcsc_result);
|
int ccid_parse_control(struct usb_ctrlrequest *setup, __u8 **outbuf);
|
||||||
RDR_to_PC_SlotStatus_t get_RDR_to_PC_SlotStatus(__u8 bSlot, __u8 bSeq,
|
int ccid_state_changed(RDR_to_PC_NotifySlotChange_t *slotchange);
|
||||||
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);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
15
ccid/usb.c
15
ccid/usb.c
@@ -54,7 +54,7 @@ static int verbose = 0;
|
|||||||
static int debug = 0;
|
static int debug = 0;
|
||||||
static int dohid = 0;
|
static int dohid = 0;
|
||||||
static int doint = 0;
|
static int doint = 0;
|
||||||
char *usb_reader_name = NULL;
|
const char *usb_reader_name = NULL;
|
||||||
int usb_reader_num = 0;
|
int usb_reader_num = 0;
|
||||||
|
|
||||||
/* NOTE: these IDs don't imply endpoint numbering; host side drivers
|
/* 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. */
|
/* so test for it explicitly. */
|
||||||
pthread_testcancel ();
|
pthread_testcancel ();
|
||||||
|
|
||||||
slotchange = get_RDR_to_PC_NotifySlotChange();
|
if (ccid_state_changed(&slotchange)) {
|
||||||
if (slotchange.bmSlotICCState) {
|
|
||||||
/* don't bother host, when nothing changed */
|
/* don't bother host, when nothing changed */
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "interrupt loop: writing RDR_to_PC_NotifySlotChange... ");
|
fprintf(stderr, "interrupt loop: writing RDR_to_PC_NotifySlotChange... ");
|
||||||
@@ -959,7 +958,7 @@ static void *ccid (void *param)
|
|||||||
|
|
||||||
void close_pcsc()
|
void close_pcsc()
|
||||||
{
|
{
|
||||||
int result = perform_shutdown();
|
int result = ccid_shutdown();
|
||||||
if (result != SCARD_S_SUCCESS)
|
if (result != SCARD_S_SUCCESS)
|
||||||
fprintf(stderr, "pc/sc error: %s\n", pcsc_stringify_error(result));
|
fprintf(stderr, "pc/sc error: %s\n", pcsc_stringify_error(result));
|
||||||
else if (verbose)
|
else if (verbose)
|
||||||
@@ -988,10 +987,10 @@ static void *ccid (void *param)
|
|||||||
}
|
}
|
||||||
pthread_cleanup_push (close_fd, &sink_fd);
|
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 (usb_reader_name == NULL) {
|
||||||
if (debug)
|
if (debug)
|
||||||
perror("perform_initialization");
|
perror("ccid_initialize");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pthread_cleanup_push (close_pcsc, NULL);
|
pthread_cleanup_push (close_pcsc, NULL);
|
||||||
@@ -1037,7 +1036,7 @@ static void *ccid (void *param)
|
|||||||
fprintf(stderr, "got %d, done.\n", result);
|
fprintf(stderr, "got %d, done.\n", result);
|
||||||
if (!result) break;
|
if (!result) break;
|
||||||
|
|
||||||
result = parse_ccid(inbuf, &outbuf);
|
result = ccid_parse_bulkin(inbuf, &outbuf);
|
||||||
if (result < 0) break;
|
if (result < 0) break;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
@@ -1485,7 +1484,7 @@ special:
|
|||||||
switch (setup->bRequestType) {
|
switch (setup->bRequestType) {
|
||||||
case USB_REQ_CCID: {
|
case USB_REQ_CCID: {
|
||||||
__u8 *outbuf = NULL;
|
__u8 *outbuf = NULL;
|
||||||
result = parse_ccid_control(setup, &outbuf);
|
result = ccid_parse_control(setup, &outbuf);
|
||||||
if (result < 0 || result > 256)
|
if (result < 0 || result > 256)
|
||||||
goto stall;
|
goto stall;
|
||||||
if (debug)
|
if (debug)
|
||||||
|
|||||||
Reference in New Issue
Block a user