sim: further updates/fixes
diff --git a/include/osmocom/sim/sim.h b/include/osmocom/sim/sim.h
index 1b13693..92b3b5a 100644
--- a/include/osmocom/sim/sim.h
+++ b/include/osmocom/sim/sim.h
@@ -231,6 +231,8 @@
 
 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 @@
 
 /* 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 bf68277..d1d4de7 100644
--- a/src/sim/core.c
+++ b/src/sim/core.c
@@ -279,3 +279,14 @@
 	}
 	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 71d10d1..4f72dd0 100644
--- a/src/sim/reader.c
+++ b/src/sim/reader.c
@@ -166,6 +166,7 @@
 			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 @@
 
 
 
-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 60a9dee..b490b97 100644
--- a/src/sim/reader_pcsc.c
+++ b/src/sim/reader_pcsc.c
@@ -70,6 +70,7 @@
 
 	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 411c322..73f144c 100644
--- a/src/sim/sim_int.h
+++ b/src/sim/sim_int.h
@@ -28,7 +28,7 @@
 
 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);
 };