diff --git a/include/osmocom/sim/sim.h b/include/osmocom/sim/sim.h index 1b136938a..92b3b5a6c 100644 --- a/include/osmocom/sim/sim.h +++ b/include/osmocom/sim/sim.h @@ -231,6 +231,8 @@ struct osim_card_profile { const struct osim_card_sw *osim_find_sw(const struct osim_card_profile *cp, uint16_t sw); +enum osim_card_sw_class osim_sw_class(const struct osim_card_profile *cp, + uint16_t sw_in); struct osim_card_hdl; char *osim_print_sw(const struct osim_card_hdl *ch, uint16_t sw_in); @@ -291,6 +293,6 @@ struct osim_chan_hdl { /* reader.c */ int osim_transceive_apdu(struct osim_chan_hdl *st, struct msgb *amsg); -struct osim_reader_hdl *osim_reader_open(int idx, const char *name); +struct osim_reader_hdl *osim_reader_open(int idx, const char *name, void *ctx); struct osim_card_hdl *osim_card_open(struct osim_reader_hdl *rh); #endif /* _OSMOCOM_SIM_H */ diff --git a/src/sim/core.c b/src/sim/core.c index bf6827777..d1d4de731 100644 --- a/src/sim/core.c +++ b/src/sim/core.c @@ -279,3 +279,14 @@ const struct osim_card_sw *osim_find_sw(const struct osim_card_profile *cp, } return NULL; } + +enum osim_card_sw_class osim_sw_class(const struct osim_card_profile *cp, + uint16_t sw_in) +{ + const struct osim_card_sw *csw = osim_find_sw(cp, sw_in); + + if (!csw) + return SW_CLS_NONE; + + return csw->class; +} diff --git a/src/sim/reader.c b/src/sim/reader.c index 71d10d142..4f72dd0f4 100644 --- a/src/sim/reader.c +++ b/src/sim/reader.c @@ -166,6 +166,7 @@ case_2s: goto transceive_again; break; case 0x61: /* Case 4S.3: command accepted with info added */ + case 0x9F: /* FIXME: This is specific to SIM cards */ tpduh->ins = 0xC0; tpduh->p1 = tpduh->p2 = 0; tpduh->p3 = OSMO_MIN(msgb_apdu_le(amsg), sw & 0xff); @@ -230,13 +231,13 @@ int osim_transceive_apdu(struct osim_chan_hdl *st, struct msgb *amsg) -struct osim_reader_hdl *osim_reader_open(int idx, const char *name) +struct osim_reader_hdl *osim_reader_open(int idx, const char *name, void *ctx) { /* FIXME: support multiple drivers */ const struct osim_reader_ops *ops = &pcsc_reader_ops; struct osim_reader_hdl *rh; - rh = ops->reader_open(idx, name); + rh = ops->reader_open(idx, name, ctx); if (!rh) return NULL; rh->ops = ops; diff --git a/src/sim/reader_pcsc.c b/src/sim/reader_pcsc.c index 60a9dee1b..b490b97f6 100644 --- a/src/sim/reader_pcsc.c +++ b/src/sim/reader_pcsc.c @@ -70,6 +70,7 @@ static struct osim_reader_hdl *pcsc_reader_open(int num, const char *id, void *c rc = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &st->hContext); + PCSC_ERROR(rc, "SCardEstablishContext"); if (rc != SCARD_S_SUCCESS) goto end; diff --git a/src/sim/sim_int.h b/src/sim/sim_int.h index 411c3225f..73f144ca7 100644 --- a/src/sim/sim_int.h +++ b/src/sim/sim_int.h @@ -28,7 +28,7 @@ add_adf_with_ef(struct osim_file_desc *parent, struct osim_reader_ops { const char *name; - struct osim_reader_hdl *(*reader_open)(int idx, const char *name); + struct osim_reader_hdl *(*reader_open)(int idx, const char *name, void *ctx); struct osim_card_hdl *(*card_open)(struct osim_reader_hdl *rh); int (*transceive)(struct osim_reader_hdl *rh, struct msgb *msg); };