Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions libfreefare/freefare.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ freefare_tag_new_pcsc (struct pcsc_context *context, const char *reader)
tag->tag_info = tag_info;
FILL_SZREADER(tag, reader);

tag->lastPCSCerror = SCardDisconnect(tag->hCard, SCARD_LEAVE_CARD);
tag->lastPCSCerror = SCardDisconnect(tag->hCard, SCARD_RESET_CARD);

return tag;
}
Expand Down Expand Up @@ -310,16 +310,19 @@ MifareTag *
freefare_get_tags_pcsc (struct pcsc_context *context, const char *reader)
{
MifareTag *tags = NULL;

MifareTag tag = freefare_tag_new_pcsc(context, reader);
if(tag == NULL) {
return NULL;
}

tags = malloc(2*sizeof (MifareTag));
if(!tags)
{
return NULL;
}
tags[0] = freefare_tag_new_pcsc(context, reader);
tags[0] = tag;
tags[1] = NULL;
if(tags[0] == NULL)
return NULL;

return tags;
}
Expand Down Expand Up @@ -451,8 +454,9 @@ pcsc_init(struct pcsc_context** context)
LONG err;
struct pcsc_context *con = malloc(sizeof(struct pcsc_context));
err = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &con->context);
if (err < 0)
if (err != SCARD_S_SUCCESS)
{
free(con);
*context = NULL;
return;
}
Expand All @@ -468,6 +472,7 @@ pcsc_exit(struct pcsc_context* context)
if (context->readers)
SCardFreeMemory(context->context, context->readers);
SCardReleaseContext(context->context);
free(context);
}

/*
Expand Down
2 changes: 2 additions & 0 deletions libfreefare/freefare_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ struct mifare_ultralight_tag {
#define TB_AB(ab) ((ab == C_DEFAULT) ? C_100 : ab)

#ifdef WITH_DEBUG
#define DEBUG_FUNCTION() do { printf("*** \033[033;1m%s\033[0m ***\n", __FUNCTION__); } while (0)
#define DEBUG_XFER(data, nbytes, hint) do { hexdump (data, nbytes, hint, 0); } while (0)
#else
#define DEBUG_FUNCTION() do {} while (0)
#define DEBUG_XFER(data, nbytes, hint) do {} while (0)
#endif

Expand Down
2 changes: 1 addition & 1 deletion libfreefare/mifare_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ mifare_classic_disconnect (MifareTag tag)
}
else // pcsc way
{
tag->lastPCSCerror = SCardDisconnect(tag->hCard, SCARD_LEAVE_CARD);
tag->lastPCSCerror = SCardDisconnect(tag->hCard, SCARD_RESET_CARD);
if(SCARD_S_SUCCESS == tag->lastPCSCerror)
{
tag->active = 0;
Expand Down
Loading