Hi Denis,

2009/12/18 Denis Kenzior <[email protected]>:
> So I think this is the right approach, but lets tweak it a bit.  According to
> 51.011 EFphase can always be read.  So even if 51.011 tells us to read it
> after PIN has been verified there's nothing (theoretically) preventing us from
> doing so earlier.
>
> Thus we can do it in one of two ways
>
> 1. Read EFphase on startup and block the rest of the sim file queue until we
> determined the phase.  Then kick off the sim file ops queue as normal.  Here 
> we
> can even shortcut the 'select' operation since we always know the length of
> the file.  Just use read_binary straight away here.
>
> 2. Proceed as we do today, but do not cache any file until we know EFphase.
> For EFecc we make sure that EFphase is read after EFecc.  This results in us
> always reading EFecc at startup.
>
> It is important to note that in both approaches we get rid of the race
> conditions of running the sim ops queue and querying cpin & imsi in parallel.

Here's a patch following 1. but I think you can take either patch.
Note that we already know that no file gets cached until imsi is
retrieved, imsi doesn't get retrieved before  EFphase and EFphase
isn't read before our PIN situation is sorted out.

Regards
From 244f0b8cf84fbd01ced6e608d4cac13ee90134e0 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 19 Dec 2009 02:49:21 +0100
Subject: [PATCH] Index SIM cache by phase also.

---
 include/sim.h |    7 +++++++
 src/sim.c     |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
 src/simutil.h |    1 +
 3 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 2bfe067..bc846f3 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -57,6 +57,12 @@ enum ofono_sim_password_type {
 	OFONO_SIM_PASSWORD_INVALID,
 };
 
+enum ofono_sim_phase {
+	OFONO_SIM_PHASE_G1,
+	OFONO_SIM_PHASE_G2,
+	OFONO_SIM_PHASE_G3,
+};
+
 typedef void (*ofono_sim_file_info_cb_t)(const struct ofono_error *error,
 					int filelength,
 					enum ofono_sim_file_structure structure,
@@ -154,6 +160,7 @@ void ofono_sim_set_data(struct ofono_sim *sim, void *data);
 void *ofono_sim_get_data(struct ofono_sim *sim);
 
 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
+enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
 
 unsigned int ofono_sim_add_ready_watch(struct ofono_sim *sim,
 				ofono_sim_ready_notify_cb_t cb,
diff --git a/src/sim.c b/src/sim.c
index 06a7815..3f28086 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -46,8 +46,8 @@
 #define SIM_MANAGER_INTERFACE "org.ofono.SimManager"
 
 #define SIM_CACHE_MODE 0600
-#define SIM_CACHE_PATH STORAGEDIR "/%s/%04x"
-#define SIM_CACHE_PATH_LEN(imsilen) (strlen(SIM_CACHE_PATH) - 2 + imsilen)
+#define SIM_CACHE_PATH STORAGEDIR "/%s-%i/%04x"
+#define SIM_CACHE_PATH_LEN(imsilen) (strlen(SIM_CACHE_PATH) - 3 + imsilen)
 #define SIM_CACHE_HEADER_SIZE 6
 
 static GSList *g_drivers = NULL;
@@ -72,6 +72,7 @@ struct sim_file_op {
 
 struct ofono_sim {
 	char *imsi;
+	enum ofono_sim_phase phase;
 	unsigned char mnc_length;
 	GSList *own_numbers;
 	GSList *new_numbers;
@@ -1219,6 +1220,34 @@ static void sim_retrieve_efli_and_efpl(struct ofono_sim *sim)
 			sim_efpl_read_cb, sim);
 }
 
+static void sim_efphase_read_cb(const struct ofono_error *error,
+				const unsigned char *data, int len, void *user)
+{
+	struct ofono_sim *sim = user;
+
+	if (!error || error->type != OFONO_ERROR_TYPE_NO_ERROR || len != 1)
+		sim->phase = OFONO_SIM_PHASE_G3;
+	else if (data[0] != 0x00)
+		sim->phase = OFONO_SIM_PHASE_G2;
+	else
+		sim->phase = OFONO_SIM_PHASE_G1;
+
+	/* Proceed with SIM initialization */
+	sim_retrieve_efli_and_efpl(sim);
+	sim_pin_check(sim);
+}
+
+static void sim_determine_phase(struct ofono_sim *sim)
+{
+	if (!sim->driver->read_file_transparent) {
+		sim_efphase_read_cb(NULL, NULL, 0, sim);
+		return;
+	}
+
+	sim->driver->read_file_transparent(sim, SIM_EFPHASE_FILEID, 0, 1,
+						sim_efphase_read_cb, sim);
+}
+
 static void sim_op_error(struct ofono_sim *sim)
 {
 	struct sim_file_op *op = g_queue_pop_head(sim->simop_q);
@@ -1278,7 +1307,8 @@ static void sim_op_retrieve_cb(const struct ofono_error *error,
 	cb(1, op->length, op->current, data, op->record_length, op->userdata);
 
 	if (op->cache && imsi) {
-		char *path = g_strdup_printf(SIM_CACHE_PATH, imsi, op->id);
+		char *path = g_strdup_printf(SIM_CACHE_PATH,
+						imsi, sim->phase, op->id);
 
 		op->cache = cache_record(path, op->current, op->record_length,
 						data);
@@ -1400,8 +1430,8 @@ static void sim_op_info_cb(const struct ofono_error *error, int length,
 		fileinfo[4] = record_length >> 8;
 		fileinfo[5] = record_length & 0xff;
 
-		if (write_file(fileinfo, 6, SIM_CACHE_MODE,
-					SIM_CACHE_PATH, imsi, op->id) != 6)
+		if (write_file(fileinfo, 6, SIM_CACHE_MODE, SIM_CACHE_PATH,
+					imsi, sim->phase, op->id) != 6)
 			op->cache = FALSE;
 	}
 }
@@ -1443,7 +1473,7 @@ static gboolean sim_op_check_cached(struct ofono_sim *sim)
 	if (!imsi)
 		return FALSE;
 
-	path = g_strdup_printf(SIM_CACHE_PATH, imsi, op->id);
+	path = g_strdup_printf(SIM_CACHE_PATH, imsi, sim->phase, op->id);
 
 	fd = TFR(open(path, O_RDONLY));
 	g_free(path);
@@ -1662,6 +1692,14 @@ const char *ofono_sim_get_imsi(struct ofono_sim *sim)
 	return sim->imsi;
 }
 
+enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim)
+{
+	if (sim == NULL)
+		return 0;
+
+	return sim->phase;
+}
+
 unsigned int ofono_sim_add_ready_watch(struct ofono_sim *sim,
 				ofono_sim_ready_notify_cb_t notify,
 				void *data, ofono_destroy_func destroy)
@@ -1915,6 +1953,7 @@ void ofono_sim_register(struct ofono_sim *sim)
 	 * Read EFecc
 	 * Read EFli and EFpl
 	 * SIM Pin check
+	 * Request SIM phase (only in 51.011)
 	 * Read EFust
 	 * Read EFest
 	 * Read IMSI
@@ -1923,8 +1962,7 @@ void ofono_sim_register(struct ofono_sim *sim)
 	 * arbitrary files to be written or read, assuming their presence
 	 * in the EFust
 	 */
-	sim_retrieve_efli_and_efpl(sim);
-	sim_pin_check(sim);
+	sim_determine_phase(sim);
 }
 
 void ofono_sim_remove(struct ofono_sim *sim)
diff --git a/src/simutil.h b/src/simutil.h
index f4fbce3..f90c792 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -26,6 +26,7 @@ enum sim_fileid {
 	SIM_EFSPN_FILEID = 0x6f46,
 	SIM_EFSDN_FILEID = 0x6f49,
 	SIM_EFAD_FILEID = 0x6fad,
+	SIM_EFPHASE_FILEID = 0x6fae,
 	SIM_EFPNN_FILEID = 0x6fc5,
 	SIM_EFOPL_FILEID = 0x6fc6,
 	SIM_EFMBDN_FILEID = 0x6fc7,
-- 
1.6.1

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to