From 4d13b401aef49da34e6cd9f27118e2ba9cd5b077 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Tue, 1 Nov 2011 16:28:08 +0100 Subject: host/layer23: SIM client now supports reading records correctly Written-by: Andreas Eversberg Signed-off-by: Sylvain Munaut --- src/host/layer23/src/common/sim.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/host/layer23/src/common/sim.c b/src/host/layer23/src/common/sim.c index 3aca6937..8c89cf0b 100644 --- a/src/host/layer23/src/common/sim.c +++ b/src/host/layer23/src/common/sim.c @@ -1045,8 +1045,25 @@ int sim_apdu_resp(struct osmocom_ms *ms, struct msgb *msg) ntohs(ef->file_id), sim->file); goto sim_error; } - /* get length of file */ - ef_len = ntohs(ef->file_size); + /* check for record */ + if (length >= 15 && ef->length >= 2 && ef->structure != 0x00) { + /* get length of record */ + ef_len = ntohs(ef->file_size); + if (ef_len < data[14]) { + LOGP(DSIM, LOGL_NOTICE, "total length is " + "smaller (%d) than record size (%d)\n", + ef_len, data[14]); + goto request_error; + } + ef_len = data[14]; + LOGP(DSIM, LOGL_NOTICE, "selected record (len %d " + "structure %d)\n", ef_len, ef->structure); + } else { + /* get length of file */ + ef_len = ntohs(ef->file_size); + LOGP(DSIM, LOGL_NOTICE, "selected file (len %d)\n", + ef_len); + } /* do file command */ sim->job_state = SIM_JST_WAIT_FILE; switch (sh->job_type) { -- cgit v1.2.3