aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2014-10-26 18:46:50 +0100
committerHarald Welte <laforge@gnumonks.org>2014-10-26 19:50:51 +0100
commit55790aa09a8f92d437ea06b3ef2c74465612fa8b (patch)
tree749a2f2e2a009644dde4c6f4ecd9c8384d006dce /src
parent586d710e0586a51ba19b71bf20f2bb12aa8c0aeb (diff)
sim: Prepare infrastructure for protocols != T=0 and other drivers
Diffstat (limited to 'src')
-rw-r--r--src/sim/reader.c48
-rw-r--r--src/sim/reader_pcsc.c6
-rw-r--r--src/sim/sim_int.h2
3 files changed, 40 insertions, 16 deletions
diff --git a/src/sim/reader.c b/src/sim/reader.c
index 4f72dd0f..160f1758 100644
--- a/src/sim/reader.c
+++ b/src/sim/reader.c
@@ -217,35 +217,55 @@ case_2s:
return sw;
}
-/* According to ISO7816-4 Annex B */
-static int transceive_apdu_t1(struct osim_card_hdl *st, struct msgb *amsg)
-{
- return -1;
-}
+/* FIXME: T=1 According to ISO7816-4 Annex B */
int osim_transceive_apdu(struct osim_chan_hdl *st, struct msgb *amsg)
{
- /* FIXME: check for protocol */
- return transceive_apdu_t0(st->card, amsg);
+ switch (st->card->proto) {
+ case OSIM_PROTO_T0:
+ return transceive_apdu_t0(st->card, amsg);
+ default:
+ return -ENOTSUP;
+ }
}
-
-
-struct osim_reader_hdl *osim_reader_open(int idx, const char *name, void *ctx)
+struct osim_reader_hdl *osim_reader_open(enum osim_reader_driver driver, int idx,
+ const char *name, void *ctx)
{
- /* FIXME: support multiple drivers */
- const struct osim_reader_ops *ops = &pcsc_reader_ops;
+ const struct osim_reader_ops *ops;
struct osim_reader_hdl *rh;
+ switch (driver) {
+ case OSIM_READER_DRV_PCSC:
+ ops = &pcsc_reader_ops;
+ break;
+ default:
+ return NULL;
+ }
+
rh = ops->reader_open(idx, name, ctx);
if (!rh)
return NULL;
rh->ops = ops;
+ /* FIXME: for now we only do T=0 on all readers */
+ rh->proto_supported = (1 << OSIM_PROTO_T0);
+
return rh;
}
-struct osim_card_hdl *osim_card_open(struct osim_reader_hdl *rh)
+struct osim_card_hdl *osim_card_open(struct osim_reader_hdl *rh, enum osim_proto proto)
{
- return rh->ops->card_open(rh);
+ struct osim_card_hdl *ch;
+
+ if (!(rh->proto_supported & (1 << proto)))
+ return NULL;
+
+ ch = rh->ops->card_open(rh, proto);
+ if (!ch)
+ return NULL;
+
+ ch->proto = proto;
+
+ return ch;
}
diff --git a/src/sim/reader_pcsc.c b/src/sim/reader_pcsc.c
index c5b8112b..5e670912 100644
--- a/src/sim/reader_pcsc.c
+++ b/src/sim/reader_pcsc.c
@@ -97,13 +97,17 @@ end:
return NULL;
}
-static struct osim_card_hdl *pcsc_card_open(struct osim_reader_hdl *rh)
+static struct osim_card_hdl *pcsc_card_open(struct osim_reader_hdl *rh,
+ enum osim_proto proto)
{
struct pcsc_reader_state *st = rh->priv;
struct osim_card_hdl *card;
struct osim_chan_hdl *chan;
LONG rc;
+ if (proto != OSIM_PROTO_T0)
+ return NULL;
+
rc = SCardConnect(st->hContext, st->name, SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0, &st->hCard, &st->dwActiveProtocol);
PCSC_ERROR(rc, "SCardConnect");
diff --git a/src/sim/sim_int.h b/src/sim/sim_int.h
index 0a3772bc..c10c5f08 100644
--- a/src/sim/sim_int.h
+++ b/src/sim/sim_int.h
@@ -32,7 +32,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, void *ctx);
- struct osim_card_hdl *(*card_open)(struct osim_reader_hdl *rh);
+ struct osim_card_hdl *(*card_open)(struct osim_reader_hdl *rh, enum osim_proto proto);
int (*transceive)(struct osim_reader_hdl *rh, struct msgb *msg);
};