summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/src/mobile/subscriber.c
diff options
context:
space:
mode:
authorAndreas.Eversberg <jolly@eversberg.eu>2010-09-18 19:15:15 +0000
committerAndreas.Eversberg <jolly@eversberg.eu>2010-09-18 19:15:15 +0000
commit0856c8a6a5ad48d810da598b421f81fc21d0ba55 (patch)
tree3b87fe6abbf65c4fc165827dea7f107e8f4c4435 /src/host/layer23/src/mobile/subscriber.c
parentdf05c6ca94a5597a83afd29e7df5b2e4b6343fc2 (diff)
[layer23] SIM client completion
The SIM client is now complete. Because it usefull for multiple applications, i moved it to the layer23/src/common directory. The SIM reader works together with mobile process. Fixes were made. Thanx to all for testing, finding bugs, and making it work as it is supposed to do. The current version uses special L1CTL messages to send and receive APDUs. This will change in the future, when BTSAP interface is completed. Please note that this client will not work until the layer1 SIM reader fixes and extensions are committed.
Diffstat (limited to 'src/host/layer23/src/mobile/subscriber.c')
-rw-r--r--src/host/layer23/src/mobile/subscriber.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/host/layer23/src/mobile/subscriber.c b/src/host/layer23/src/mobile/subscriber.c
index fce62f0d..b95858f8 100644
--- a/src/host/layer23/src/mobile/subscriber.c
+++ b/src/host/layer23/src/mobile/subscriber.c
@@ -63,12 +63,12 @@ static char *sim_decode_bcd(uint8_t *data, uint8_t length)
for (i = 0; i < (length << 1); i++) {
if ((i & 1))
- c = (data[i >> 1] >> 4) + '0';
+ c = (data[i >> 1] >> 4);
else
- c = (data[i >> 1] & 0xf) + '0';
+ c = (data[i >> 1] & 0xf);
if (c == 0xf)
break;
- result[j++] = c;
+ result[j++] = c + '0';
if (j == sizeof(result) - 1)
break;
}
@@ -229,6 +229,7 @@ static int subscr_sim_imsi(struct osmocom_ms *ms, uint8_t *data,
uint8_t length)
{
struct gsm_subscriber *subscr = &ms->subscr;
+ char *imsi;
/* get actual length */
if (length < 1)
@@ -238,14 +239,16 @@ static int subscr_sim_imsi(struct osmocom_ms *ms, uint8_t *data,
return -EINVAL;
}
length = data[0];
- if ((length << 1) > GSM_IMSI_LENGTH - 1 || (length << 1) < 6) {
+
+ /* decode IMSI, skip first digit (parity) */
+ imsi = sim_decode_bcd(data + 1, length);
+ if (strlen(imsi) - 1 > GSM_IMSI_LENGTH - 1 || strlen(imsi) - 1 < 6) {
LOGP(DMM, LOGL_NOTICE, "IMSI invalid length = %d\n",
- length << 1);
+ strlen(imsi) - 1);
return -EINVAL;
}
- strncpy(subscr->imsi, sim_decode_bcd(data + 1, length),
- sizeof(subscr->imsi - 1));
+ strncpy(subscr->imsi, imsi + 1, sizeof(subscr->imsi) - 1);
LOGP(DMM, LOGL_INFO, "received IMSI %s from SIM\n", subscr->imsi);
@@ -281,7 +284,9 @@ static int subscr_sim_loci(struct osmocom_ms *ms, uint8_t *data,
subscr->ustate = GSM_SIM_U2_NOT_UPDATED;
}
- LOGP(DMM, LOGL_INFO, "received LOCI from SIM\n");
+ LOGP(DMM, LOGL_INFO, "received LOCI from SIM (mcc=%s mnc=%s lac=0x%04x "
+ "U%d)\n", gsm_print_mcc(subscr->mcc),
+ gsm_print_mnc(subscr->mnc), subscr->lac, subscr->ustate);
return 0;
}
@@ -386,8 +391,8 @@ static int subscr_sim_hpplmn(struct osmocom_ms *ms, uint8_t *data,
/* HPLMN search interval */
subscr->t6m_hplmn = *data; /* multiple of 6 minutes */
- LOGP(DMM, LOGL_INFO, "received HPPLMN %d from SIM\n",
- subscr->t6m_hplmn);
+ LOGP(DMM, LOGL_INFO, "received HPPLMN %d (%d mins) from SIM\n",
+ subscr->t6m_hplmn, subscr->t6m_hplmn * 6);
return 0;
}
@@ -578,6 +583,12 @@ static void subscr_sim_query_cb(struct osmocom_ms *ms, struct msgb *msg)
vty_notify(ms, "PIN is blocked\n");
break;
default:
+ if (!subscr_sim_files[subscr->sim_file_index].
+ mandatory) {
+ LOGP(DMM, LOGL_NOTICE, "SIM reading failed, "
+ "ignoring!\n");
+ goto ignore;
+ }
LOGP(DMM, LOGL_NOTICE, "SIM reading failed\n");
vty_notify(ms, NULL);
@@ -604,6 +615,7 @@ static void subscr_sim_query_cb(struct osmocom_ms *ms, struct msgb *msg)
}
}
+ignore:
msgb_free(msg);
/* trigger next file */