mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-16 21:28:33 +03:00
simtrace2-cardem-pcsc: Detect card power-up without RESET
In some readers (at least CardMan 3121), the simtrace2-cardem firmware claims there are power-up sequences where RESET is released before VCC becomes active. Let's detect such spec-incompliant power-up sequences and use them to trigger a cold reset of the card. Change-Id: I682ac3d0c2b98749a6ed44f9a73e4b39354a4284 Closes: OS#5421
This commit is contained in:
@@ -74,22 +74,40 @@ static void cemu_status_flags2str(char *out, unsigned int out_len, uint32_t flag
|
|||||||
|
|
||||||
static uint32_t last_status_flags = 0;
|
static uint32_t last_status_flags = 0;
|
||||||
|
|
||||||
|
#define NO_RESET 0
|
||||||
|
#define COLD_RESET 1
|
||||||
|
#define WARM_RESET 2
|
||||||
|
|
||||||
static void update_status_flags(struct osmo_st2_cardem_inst *ci, uint32_t flags)
|
static void update_status_flags(struct osmo_st2_cardem_inst *ci, uint32_t flags)
|
||||||
{
|
{
|
||||||
struct osim_card_hdl *card = ci->chan->card;
|
struct osim_card_hdl *card = ci->chan->card;
|
||||||
|
int reset = NO_RESET;
|
||||||
|
|
||||||
|
/* check if card is _now_ operational: VCC+CLK present, RST absent */
|
||||||
if ((flags & CEMU_STATUS_F_VCC_PRESENT) && (flags & CEMU_STATUS_F_CLK_ACTIVE) &&
|
if ((flags & CEMU_STATUS_F_VCC_PRESENT) && (flags & CEMU_STATUS_F_CLK_ACTIVE) &&
|
||||||
!(flags & CEMU_STATUS_F_RESET_ACTIVE)) {
|
!(flags & CEMU_STATUS_F_RESET_ACTIVE)) {
|
||||||
if (last_status_flags & CEMU_STATUS_F_RESET_ACTIVE) {
|
if (last_status_flags & CEMU_STATUS_F_RESET_ACTIVE) {
|
||||||
/* a reset has just ended, forward it to the real card */
|
/* a reset has just ended, forward it to the real card */
|
||||||
bool cold_reset = true;
|
|
||||||
if (last_status_flags & CEMU_STATUS_F_VCC_PRESENT)
|
if (last_status_flags & CEMU_STATUS_F_VCC_PRESENT)
|
||||||
cold_reset = false;
|
reset = WARM_RESET;
|
||||||
LOGCI(ci, LOGL_NOTICE, "%s Resetting card in reader...\n",
|
else
|
||||||
cold_reset ? "Cold" : "Warm");
|
reset = COLD_RESET;
|
||||||
osim_card_reset(card, cold_reset);
|
} else if (!(last_status_flags & CEMU_STATUS_F_VCC_PRESENT)) {
|
||||||
|
/* power-up has just happened, perform cold reset */
|
||||||
|
reset = COLD_RESET;
|
||||||
}
|
}
|
||||||
|
} else if (flags == CEMU_STATUS_F_VCC_PRESENT &&
|
||||||
|
!(last_status_flags & CEMU_STATUS_F_VCC_PRESENT)) {
|
||||||
|
/* improper power-up: Only power enabled, but no reset active. */
|
||||||
|
reset = COLD_RESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reset) {
|
||||||
|
LOGCI(ci, LOGL_NOTICE, "%s Resetting card in reader...\n",
|
||||||
|
reset == COLD_RESET ? "Cold" : "Warm");
|
||||||
|
osim_card_reset(card, reset == COLD_RESET ? true : false);
|
||||||
|
}
|
||||||
|
|
||||||
last_status_flags = flags;
|
last_status_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user