Closed kouwasi closed 4 years ago
I have never tried to use DIRECT
, and support for that is indeed missing.
When trying to add this, I have hit one problem though, namely the pioSendPci
parameter of the SCardTransmit
function. In the pcsc
crate's wrapper of this function, pcsc::Card::transmit
, I have tried to automatically handle this parameter as follows:
let pioSendPci = get_protocol_pci(self.active_protocol);
fn get_protocol_pci(protocol: Protocol) -> &'static ffi::SCARD_IO_REQUEST {
unsafe {
match protocol {
Protocol::T0 => &ffi::g_rgSCardT0Pci,
Protocol::T1 => &ffi::g_rgSCardT1Pci,
Protocol::RAW => &ffi::g_rgSCardRawPci,
}
}
}
This is no longer possible, or at least requires some refinement, once we have Protocol::Undefined
.
I admit to not knowing much about this, so before I look into how to wrap it properly, you can help me understand by answering a few questions:
SCardTransmit
/pcsc::Card::transmit
in your application?pioSendPci
? Do you pass some special values for the custom protocol? How does it look?pioRecvPci
return value?Thanks!
I forgot to link to the SCARD_IO_REQUEST
struct, which is the type of the pioSendPci
and pioRecvPci
parameters.
I'm not sure if this issue is still monitored, but anyway:
I ran into a similar problem, being unable to connect to the reader without a card. This I bypassed by:
1) Adding Protocols::UNDEFINED
and Protocol::UNDEFINED
as appropriate
2) Changed functionality mentioned above as follows:
let send_pci = get_protocol_pci(self.active_protocol).ok_or(Error::InternalError)?;
fn get_protocol_pci(protocol: Protocol) -> Option<&'static ffi::SCARD_IO_REQUEST> {
unsafe {
match protocol {
Protocol::UNDEFINED => None,
Protocol::T0 => Some(&ffi::g_rgSCardT0Pci),
Protocol::T1 => Some(&ffi::g_rgSCardT1Pci),
Protocol::RAW => Some(&ffi::g_rgSCardRawPci),
}
}
}
This may not be ideal and has not been well tested, but it did allow me to connect to the reader without having a card, and to send control commands (SCardControl
). At least so far in my current use-case, SCardTransmit
is not required in the same connection, meaning that if I need to transmit data by ordinary means, I can reconnect with a standard protocol.
Hopefully this helps!
@arttuys This is a valid use case and I had use for it myself, to set some parameters (buzzer etc.) of an ACS reader. I've created a PR #15 for it, if you are able to test.
@arttuys This is a valid use case and I had use for it myself, to set some parameters (buzzer etc.) of an ACS reader. I've created a PR #15 for it, if you are able to test.
Sounds promising! I've been a bit caught up with other work, I'll try to test it when work calms down.
Support for this was added in pcsc v2.4.0.
Can't connect during not place the card but can connect using pcsc-sys. I think Protocol::from_raw() have a problem.
pcsc-rust throw the below error.
thread 'main' panicked at 'impossible protocol: 0x0', pcsc-1.0.1\src\lib.rs:173:18
I think add to
Protocol::UNDEFINED
pattern in from_raw function is necessary.What do you think?
Can't connect example code.
Can connect example code. *using pcsc_sys