2009/12/17 Andrzej Zaborowski <[email protected]>:
> Attached patch adds the SIM phase to the index

Now with the attachment..
From 3459eba961d526105d615afbc6ee26075ef680c4 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Thu, 17 Dec 2009 16:41:53 +0100
Subject: [PATCH 10/10] Index SIM cache by phase also.

---
 include/sim.h |    1 +
 src/sim.c     |   42 +++++++++++++++++++++++++++++++++---------
 src/simutil.h |    1 +
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index f76f9d1..40fd257 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -151,6 +151,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);
+int 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 907e4ce..565f595 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;
+	int phase;
 	unsigned char mnc_length;
 	GSList *own_numbers;
 	GSList *new_numbers;
@@ -964,8 +965,14 @@ static void sim_imsi_cb(const struct ofono_error *error, const char *imsi,
 	ofono_sim_set_ready(sim);
 }
 
-static void sim_retrieve_imsi(struct ofono_sim *sim)
+static void sim_efphase_read_cb(int ok, int length, int record,
+				const unsigned char *data,
+				int record_length, void *userdata)
 {
+	struct ofono_sim *sim = userdata;
+
+	sim->phase = (ok && length == 1) ? data[0] == 0x00 ? 1 : 2 : 3;
+
 	if (!sim->driver->read_imsi) {
 		ofono_error("IMSI retrieval not implemented,"
 				" only emergency calls will be available");
@@ -975,6 +982,13 @@ static void sim_retrieve_imsi(struct ofono_sim *sim)
 	sim->driver->read_imsi(sim, sim_imsi_cb, sim);
 }
 
+static void sim_request_phase(struct ofono_sim *sim)
+{
+	ofono_sim_read(sim, SIM_EFPHASE_FILEID,
+			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+			sim_efphase_read_cb, sim);
+}
+
 static void sim_pin_query_cb(const struct ofono_error *error,
 				enum ofono_sim_password_type pin_type,
 				void *data)
@@ -1005,13 +1019,13 @@ static void sim_pin_query_cb(const struct ofono_error *error,
 
 checkdone:
 	if (pin_type == OFONO_SIM_PASSWORD_NONE)
-		sim_retrieve_imsi(sim);
+		sim_request_phase(sim);
 }
 
 static void sim_pin_check(struct ofono_sim *sim)
 {
 	if (!sim->driver->query_passwd_state) {
-		sim_retrieve_imsi(sim);
+		sim_request_phase(sim);
 		return;
 	}
 
@@ -1276,7 +1290,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);
@@ -1398,8 +1413,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;
 	}
 }
@@ -1441,7 +1456,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);
@@ -1660,6 +1675,14 @@ const char *ofono_sim_get_imsi(struct ofono_sim *sim)
 	return sim->imsi;
 }
 
+int 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)
@@ -1877,6 +1900,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
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