-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timed read for smartcards + littles changes #160
Conversation
… (1/((1/3500000)*372))
Thanks for the contribution |
uint8_t nb_rdata, i; | ||
mode_config_proto_t* proto = &con->mode->proto; | ||
|
||
nb_rdata = bsp_smartcard_read_u8_timeout(proto->dev_num, rx_data, nb_data, proto->config.smartcard.dev_timeout * 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hard coded value "proto->config.smartcard.dev_timeout * 10" it shall be TIME_MS2I(proto->config.smartcard.dev_timeout) (to be checked as the unit is expected to be in ms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -63,6 +63,7 @@ static void init_proto_default(t_hydra_console *con) | |||
proto->config.smartcard.dev_guardtime = 16; | |||
proto->config.smartcard.dev_phase = 0; | |||
proto->config.smartcard.dev_convention = DEV_CONVENTION_NORMAL; | |||
proto->config.smartcard.dev_timeout = 10000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why default timeout is so long (10000ms => 10s) ? (It will be better to be less than 1s especially as default value and usually any HW shall return data in less than 1s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also found it huge but I kept the value used by bsp_smartcard_read_u8()
in src/drv/stm32cube/bsp_smartcard.c
(SMARTCARDx_TIMEOUT_MAX
).
Thanks for the contribution ! I really like the read with timeout idea and it could be applied to all modes by changing the I would suggest to change this PR by only including 0d0862a and d9a7097 so it can be merged quickly, and I'll open an issue regarding the read with timeout feature for all modes. Edit: #164 has been opened |
Hi,
Here's a patch adding a command to receive a smartcard message with a timeout.
With the existing code, a successful read can only be achieved by specifying the exact number of characters (or less). This works:
But not this:
Of course, ATR is just an example, we don't always know the size of the data returned by the card.. So I added a new
tread
(timed read) command and atimeout
parameter. And now we can do this:Here, after the ATR, I selected the application on the smartcard (NXP J2A081, T=1 protocol) and used an APDU for a counter reading.
I have also configured a pull-up resistor on PA7 so that the normally closed contactor on the card reader opens and
query
displaysCD=1
when the card is present.Finally, the default communication speed should be 9408 bps because (1/((1/3500000)*372)). 9600 bps is a rounding-off that works but the ETU is normally 106µs with a 3.5 MHz clock.
Perhaps timeout read could be interesting for other buses too.