Giter VIP home page Giter VIP logo

Comments (20)

leifj avatar leifj commented on June 19, 2024

A bit more research... The '1' in dwProtocol for T0 is is clearly correct. The question is why 0 is sent from that piece of C-code, because that seems to be why the C code works.... Here is the same snippet of gdb from stepping through pcscd when calling the C program:

03558356 winscard_svc.c:351:ContextThread() Received command: TRANSMIT from client 14
353                     switch (header.command)
(gdb) 
621                                     READ_BODY(trStr)
(gdb) 
623                                     if (MSGCheckHandleAssociation(trStr.hCard, threadContext))
(gdb) p trStr
$1 = {hCard = 781293158, ioSendPciProtocol = 0, ioSendPciLength = 6299704, cbSendLength = 6, ioRecvPciProtocol = 3, ioRecvPciLength = 16, 
  pcbRecvLength = 266, rv = 0}

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

Why don't you use the value returned by SCardConnect() in dwActiveProtocol to use it in SCardTransmit() ?

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

You are using SCARD_SHARE_DIRECT. This imply a different protocol negotiation.
But that does not explain why the C code "works".

from pyscard.

leifj avatar leifj commented on June 19, 2024

Sure but the case statement in _Transmit in scard.i makes that impossible

from pyscard.

leifj avatar leifj commented on June 19, 2024

Yes but I use SCARD_SHARE_DIRECT in the pyscard code too - I just left that out for brevity

from pyscard.

leifj avatar leifj commented on June 19, 2024

dwActiveProtocol is 0 btw which hits the default case in _Transmit and causes an Invalid Parameter exception. This seems inconsistent with the behaviour of the C library where passing 0 while using DIRECT triggers the desired behavior in the driver

from pyscard.

leifj avatar leifj commented on June 19, 2024

Here is a patch that "fixes" this. Review pls...

diff --git a/smartcard/scard/scard.i b/smartcard/scard/scard.i
index 76f63ad..87f38fa 100644
--- a/smartcard/scard/scard.i
+++ b/smartcard/scard/scard.i
@@ -672,8 +672,12 @@ static SCARDRETCODE _Transmit(
 )
 {
     PSCARD_IO_REQUEST piorequest=NULL;
+    SCARD_IO_REQUEST unknown;
     long ret;

+    unknown.dwProtocol = 0;
+    unknown.cbPciLength = 0;
+
     pblRecvBuffer->ab = (unsigned char*)mem_Malloc(MAX_BUFFER_SIZE_EXTENDED*sizeof(unsigned char));
     pblRecvBuffer->cBytes = MAX_BUFFER_SIZE_EXTENDED;

@@ -692,6 +696,10 @@ static SCARDRETCODE _Transmit(
             piorequest=(PSCARD_IO_REQUEST)myg_prgSCardRawPci;
             break;

+        case 0x00:
+            piorequest = &unknown;
+            break;
+
         default:
             return SCARD_E_INVALID_PARAMETER

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

I guess your C code works because you go in the default case and pioSendPci is not initialized.
With luck you have pioSendPci.dwProtocol = 0 and 0 is SCARD_PROTOCOL_UNDEFINED.

What is the value of dwActiveProtocolafter the SCardConnect()?

If you add a the line pioSendPci.dwProtocol = SCARD_PROTOCOL_T0 before the switch(dwActiveProtocol) the C program should also fail. Do you confirm?

from pyscard.

leifj avatar leifj commented on June 19, 2024

Skickat från min iPhone

21 okt. 2016 kl. 21:28 skrev Ludovic Rousseau [email protected]:

I guess your C code works because you go in the default case and pioSendPci is not initialized.
With luck you have pioSendPci.dwProtocol = 0 and 0 is SCARD_PROTOCOL_UNDEFINED.

What is the value of dwActiveProtocolafter the SCardConnect()?

If you add a the line pioSendPci.dwProtocol = SCARD_PROTOCOL_T0 before the switch(dwActiveProtocol) the C program should also fail. Do you confirm?

Oh I'm absolutely sure you're right!


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

What is the value of dwActiveProtocol after the SCardConnect()?

You forgot to answer this question.

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

I got no answer?
I need to understand the problem in order to fix it correctly.

from pyscard.

leifj avatar leifj commented on June 19, 2024

On 2016-11-07 20:28, Ludovic Rousseau wrote:

I got no answer?
I need to understand the problem in order to fix it correctly.

sorry, got several NMIs

from pyscard.

leifj avatar leifj commented on June 19, 2024

Really sorry for the delay!

repr(dwActiveProtocol) == 0L after ScardConnect

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

It should be fixed with fa3addb

Please confirm it works for you.

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

Can you please confirm the fix works for you?
The idea is to close this issue and release a new version of PySCard.

from pyscard.

leifj avatar leifj commented on June 19, 2024

Actually it doesn't. I still needed my patch to make it work.

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

Your patch should not apply without modifications on the latest version.

  • Are you really using the latest PySCard git version?
  • If yes can you send me your updated patch for review?

from pyscard.

leifj avatar leifj commented on June 19, 2024

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

OK. You PR can apply cleanly.
But your patch should have NO effect since the case 0 (or SCARD_PROTOCOL_UNDEFINED) is already managed by the current code.

I also note that your repository at https://github.com/SUNET/pyscard/commits/master is NOT up to date.

from pyscard.

LudovicRousseau avatar LudovicRousseau commented on June 19, 2024

This bug should be fixed upstream.
If your problem is still present then please open a new issue with details and traces.

from pyscard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.