Skip to contentSkip to conversation

sim: Cache flushing functions.

PATCH New Andrzej Zaborowski 2 participants 7 messages Dec 28, 2010 – Dec 30, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 sim: Cache flushing functions.

---
 src/sim.c   |   23 ++++++++++++++++++++
 src/simfs.c |   68 ++++++++++++++++++++++++++++++++++++++++++++--------------
 src/simfs.h |    5 ++++
 3 files changed, 79 insertions(+), 17 deletions(-)
src/sim.c +23 -0
index 335f611..27ff572 100644
@@ -2255,3 +2255,26 @@ void *ofono_sim_get_data(struct ofono_sim *sim)
 {
 	return sim->driver_data;
 }
+
+static void sim_file_changed_flush(struct ofono_sim *sim, int id)
+{
+	int i, imgid;
+
+	if (id == SIM_EFIMG_FILEID)
+		/* All cached images become invalid */
+		sim_fs_image_cache_flush(sim->simfs);
+	else if (sim->efimg)
+		/*
+		 * Data and CLUT for image instances stored in the changed
+		 * file need to be re-read.
+		 */
+		for (i = sim->efimg_length / 9 - 1; i >= 0; i--) {
+			imgid = (sim->efimg[i * 9 + 3] << 8) |
+				sim->efimg[i * 9 + 4];
+
+			if (imgid == id)
+				sim_fs_image_cache_flush_file(sim->simfs, i);
+		}
+
+	sim_fs_cache_flush_file(sim->simfs, id);
+}
src/simfs.c +51 -17

90 lines not on this page · raw message

src/simfs.h +5 -0
index ef962db..8c6f761 100644
@@ -47,4 +47,9 @@ char *sim_fs_get_cached_image(struct sim_fs *fs, int id);
 
 void sim_fs_cache_image(struct sim_fs *fs, const char *image, int id);
 
+void sim_fs_cache_flush(struct sim_fs *fs);
+void sim_fs_cache_flush_file(struct sim_fs *fs, int id);
+void sim_fs_image_cache_flush(struct sim_fs *fs);
+void sim_fs_image_cache_flush_file(struct sim_fs *fs, int id);
+
 void sim_fs_free(struct sim_fs *fs);
Signature · 1 line
1.7.1.86.g0e460.dirty
#1 lore raw

PATCH 2/5 Add SIM filesystem watch api.

This allows code that reads files from the SIM card to also watch for changes in these files signalled in a Refresh command by the SIM.

---
 include/sim.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
include/sim.h +10 -0
index 7860e24..aab981c 100644
@@ -114,6 +114,8 @@ typedef void (*ofono_sim_lock_unlock_cb_t)(const struct ofono_error *error,
 typedef void (*ofono_sim_locked_cb_t)(const struct ofono_error *error,
 					int locked, void *data);
 
+typedef void (*ofono_sim_file_notify_t)(int id, void *userdata);
+
 struct ofono_sim_driver {
 	const char *name;
 	int (*probe)(struct ofono_sim *sim, unsigned int vendor, void *data);
@@ -207,6 +209,14 @@ int ofono_sim_write(struct ofono_sim *sim, int id,
 int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
 			unsigned short offset, unsigned short num_bytes,
 			ofono_sim_file_read_cb_t cb, void *data);
+
+int ofono_sim_add_file_watch(struct ofono_sim *sim, int id,
+			enum ofono_sim_state reset_state,
+			ofono_sim_file_notify_t notify, void *userdata);
+
+void ofono_sim_remove_file_watch(struct ofono_sim *sim, int id,
+			ofono_sim_file_notify_t notify, void *userdata);
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.7.1.86.g0e460.dirty
#2 lore raw

RFC PATCH 3/5 sim: Implement file watching and basic refresh.

In reply to Andrzej Zaborowski
---
 src/ofono.h |    4 +
 src/sim.c   |  182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+), 0 deletions(-)
src/ofono.h +4 -0
index cab70cd..4c0a8e1 100644
@@ -297,6 +297,10 @@ ofono_bool_t __ofono_sim_service_available(struct ofono_sim *sim,
 						int ust_service,
 						int sst_service);
 
+void __ofono_sim_refresh(struct ofono_sim *sim, GSList *file_list,
+				ofono_bool_t full_file_change,
+				ofono_bool_t naa_init);
+
 #include <ofono/stk.h>
 
 typedef void (*__ofono_sms_sim_download_cb_t)(ofono_bool_t ok,
src/sim.c +182 -0

203 lines not on this page · raw message

Signature · 1 line
1.7.1.86.g0e460.dirty
#3 lore raw

PATCH 4/5 sim: Watch files that ofono keeps in memory.

In reply to Andrzej Zaborowski

These are dummy watches on files who's state is kept in memory, just to ensure that on a refresh affecting any of those files ofono re-reads them from SIM. Only EFmsisdn and EFsdn changes are handled without changing sim state right now.

---
 src/sim.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 87 insertions(+), 3 deletions(-)
src/sim.c +87 -3
index 3f79c6a..8f69b4c 100644
@@ -890,6 +890,8 @@ static void sim_get_image(struct ofono_sim *sim, unsigned char id,
 	/* read the image data */
 	ofono_sim_read_bytes(sim, iidf_id, iidf_offset, iidf_len,
 				sim_iidf_read_cb, sim);
+	ofono_sim_add_file_watch(sim, iidf_id,
+					OFONO_SIM_STATE_READY, NULL, sim);
 }
 
 static DBusMessage *sim_get_icon(DBusConnection *conn,
@@ -1127,11 +1129,12 @@ out:
 check:
 	/* All records retrieved */
 	if (sim->service_numbers) {
-		char **service_numbers;
-
 		sim->service_numbers = g_slist_reverse(sim->service_numbers);
 		sim->sdn_ready = TRUE;
+	}
 
+	if (sim->sdn_ready) {
+		char **service_numbers;
 		service_numbers = get_service_numbers(sim->service_numbers);
 
 		ofono_dbus_signal_dict_property_changed(conn, path,
@@ -1143,12 +1146,34 @@ check:
 	}
 }
 
+static void sim_service_numbers_changed(int id, void *userdata)
+{
+	struct ofono_sim *sim = userdata;
+
+	if (sim->service_numbers) {
+		g_slist_foreach(sim->service_numbers,
+				(GFunc)service_number_free, NULL);
+		g_slist_free(sim->service_numbers);
+		sim->service_numbers = NULL;
+	}
+
+	ofono_sim_read(sim, SIM_EFSDN_FILEID, OFONO_SIM_FILE_STRUCTURE_FIXED,
+			sim_sdn_read_cb, sim);
+}
+
 static void sim_own_numbers_update(struct ofono_sim *sim)
 {
 	ofono_sim_read(sim, SIM_EFMSISDN_FILEID, OFONO_SIM_FILE_STRUCTURE_FIXED,
 			sim_msisdn_read_cb, sim);
 }
 
+static void sim_own_numbers_changed(int id, void *userdata)
+{
+	struct ofono_sim *sim = userdata;
+
+	sim_own_numbers_update(sim);
+}
+
 static void sim_efimg_read_cb(int ok, int length, int record,
 				const unsigned char *data,
 				int record_length, void *userdata)
@@ -1193,16 +1218,42 @@ static void sim_efimg_read_cb(int ok, int length, int record,
 static void sim_ready(enum ofono_sim_state new_state, void *user)
 {
 	struct ofono_sim *sim = user;
+	int i, iidf_id;
+
+	if (new_state != OFONO_SIM_STATE_READY) {
+		ofono_sim_remove_file_watch(sim, SIM_EFMSISDN_FILEID,
+						NULL, sim);
+		ofono_sim_remove_file_watch(sim, SIM_EFSDN_FILEID, NULL, sim);
+		ofono_sim_remove_file_watch(sim, SIM_EFIMG_FILEID, NULL, sim);
+
+		if (sim->efimg == NULL)
+			return;
+
+		for (i = sim->efimg_length / 9 - 1; i >= 0; i--) {
+			iidf_id = (sim->efimg[i * 9 + 3] << 8) |
+				sim->efimg[i * 9 + 4];
+
+			ofono_sim_remove_file_watch(sim, iidf_id, NULL, sim);
+		}
 
-	if (new_state != OFONO_SIM_STATE_READY)
 		return;
+	}
 
 	sim_own_numbers_update(sim);
+	ofono_sim_add_file_watch(sim, SIM_EFMSISDN_FILEID,
+					OFONO_SIM_STATE_READY,
+					sim_own_numbers_changed, sim);
 
 	ofono_sim_read(sim, SIM_EFSDN_FILEID, OFONO_SIM_FILE_STRUCTURE_FIXED,
 			sim_sdn_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EFSDN_FILEID,
+					OFONO_SIM_STATE_READY,
+					sim_service_numbers_changed, sim);
+
 	ofono_sim_read(sim, SIM_EFIMG_FILEID, OFONO_SIM_FILE_STRUCTURE_FIXED,
 			sim_efimg_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EFIMG_FILEID,
+					OFONO_SIM_STATE_READY, NULL, sim);
 }
 
 static void sim_imsi_cb(const struct ofono_error *error, const char *imsi,
@@ -1466,6 +1517,9 @@ static void sim_efust_read_cb(int ok, int length, int record,
 		ofono_sim_read(sim, SIM_EFEST_FILEID,
 				OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 				sim_efest_read_cb, sim);
+		ofono_sim_add_file_watch(sim, SIM_EFEST_FILEID,
+						OFONO_SIM_STATE_INSERTED,
+						NULL, sim);
 
 		return;
 	}
@@ -1527,6 +1581,9 @@ static void sim_efphase_read_cb(int ok, int length, int record,
 		ofono_sim_read(sim, SIM_EFUST_FILEID,
 				OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 				sim_efust_read_cb, sim);
+		ofono_sim_add_file_watch(sim, SIM_EFUST_FILEID,
+						OFONO_SIM_STATE_INSERTED,
+						NULL, sim);
 
 		return;
 	}
@@ -1549,6 +1606,8 @@ static void sim_efphase_read_cb(int ok, int length, int record,
 	ofono_sim_read(sim, SIM_EFSST_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_efsst_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EFSST_FILEID,
+					OFONO_SIM_STATE_INSERTED, NULL, sim);
 }
 
 static void sim_initialize_after_pin(struct ofono_sim *sim)
@@ -1556,10 +1615,14 @@ static void sim_initialize_after_pin(struct ofono_sim *sim)
 	ofono_sim_read(sim, SIM_EFPHASE_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_efphase_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EFPHASE_FILEID,
+					OFONO_SIM_STATE_INSERTED, NULL, sim);
 
 	ofono_sim_read(sim, SIM_EFAD_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_ad_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EFAD_FILEID,
+					OFONO_SIM_STATE_INSERTED, NULL, sim);
 
 	/*
 	 * Read CPHS-support bits, this is still part of the SIM
@@ -1568,6 +1631,8 @@ static void sim_initialize_after_pin(struct ofono_sim *sim)
 	ofono_sim_read(sim, SIM_EF_CPHS_INFORMATION_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_cphs_information_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EF_CPHS_INFORMATION_FILEID,
+					OFONO_SIM_STATE_INSERTED, NULL, sim);
 }
 
 static void sim_pin_query_cb(const struct ofono_error *error,
@@ -1858,6 +1923,8 @@ static void sim_initialize(struct ofono_sim *sim)
 	ofono_sim_read(sim, SIM_EF_ICCID_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_iccid_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EF_ICCID_FILEID,
+					OFONO_SIM_STATE_INSERTED, NULL, sim);
 
 	/* EFecc is read by the voicecall atom */
 
@@ -1872,9 +1939,14 @@ static void sim_initialize(struct ofono_sim *sim)
 	ofono_sim_read(sim, SIM_EFLI_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_efli_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EFLI_FILEID,
+					OFONO_SIM_STATE_INSERTED, NULL, sim);
+
 	ofono_sim_read(sim, SIM_EFPL_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_efpl_read_cb, sim);
+	ofono_sim_add_file_watch(sim, SIM_EFPL_FILEID,
+					OFONO_SIM_STATE_INSERTED, NULL, sim);
 }
 
 int ofono_sim_read_bytes(struct ofono_sim *sim, int id,
@@ -1995,6 +2067,7 @@ static void sim_free_state(struct ofono_sim *sim)
 				(GFunc)service_number_free, NULL);
 		g_slist_free(sim->service_numbers);
 		sim->service_numbers = NULL;
+		sim->sdn_ready = FALSE;
 	}
 
 	if (sim->efli) {
@@ -2039,6 +2112,17 @@ static void sim_free_state(struct ofono_sim *sim)
 
 	sim->fixed_dialing = FALSE;
 	sim->barred_dialing = FALSE;
+
+	ofono_sim_remove_file_watch(sim, SIM_EFUST_FILEID, NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EFEST_FILEID, NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EFSST_FILEID, NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EFPHASE_FILEID, NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EFAD_FILEID, NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EF_CPHS_INFORMATION_FILEID,
+					NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EF_ICCID_FILEID, NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EFLI_FILEID, NULL, sim);
+	ofono_sim_remove_file_watch(sim, SIM_EFPL_FILEID, NULL, sim);
 }
 
 void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted)
Signature · 1 line
1.7.1.86.g0e460.dirty
#4 lore raw

RFC PATCH 5/5 stk: Partially handle Refresh command.

In reply to Andrzej Zaborowski

Only the four "NAA initialisation" modes are handled at the moment.

---
 src/stk.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)
src/stk.c +65 -0
index 9dcbda6..e30f600 100644
@@ -1951,10 +1951,22 @@ static gboolean handle_command_send_ussd(const struct stk_command *cmd,
 	return FALSE;
 }
 
+static void free_idle_mode_text(struct ofono_stk *stk)
+{
+	g_free(stk->idle_mode_text);
+	stk->idle_mode_text = NULL;
+
+	memset(&stk->idle_mode_icon, 0, sizeof(stk->idle_mode_icon));
+}
+
 static gboolean handle_command_refresh(const struct stk_command *cmd,
 					struct stk_response *rsp,
 					struct ofono_stk *stk)
 {
+	struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+	struct ofono_sim *sim = NULL;
+	struct ofono_atom *sim_atom;
+	int err;
 	GSList *l;
 
 	DBG("");
@@ -2008,6 +2020,59 @@ static gboolean handle_command_refresh(const struct stk_command *cmd,
 					cmd->refresh.icon_id.qualifier);
 	DBG("Alpha ID: %s", cmd->refresh.alpha_id);
 
+	sim_atom = __ofono_modem_find_atom(__ofono_atom_get_modem(stk->atom),
+						OFONO_ATOM_TYPE_SIM);
+	if (sim_atom)
+		sim = __ofono_atom_get_data(sim_atom);
+
+	if (sim == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		return TRUE;
+	}
+
+	if (cmd->qualifier < 4) {
+		int qualifier = stk->pending_cmd->qualifier;
+		GSList *file_list = stk->pending_cmd->refresh.file_list;
+
+		/* Don't free the list yet */
+		stk->pending_cmd->refresh.file_list = NULL;
+
+		/*
+		 * Queue the TERMINAL RESPONSE before triggering potential
+		 * file accesses.
+		 */
+		err = stk_respond(stk, rsp, stk_command_cb);
+		if (err)
+			stk_command_cb(&failure, stk);
+
+		/* TODO: use the alphaId / icon */
+		/* TODO: if AID is supplied, check its value */
+		/* TODO: possibly check if a D-bus call is pending or
+		 * an STK session ongoing. */
+
+		/* TODO: free some elements of the atom state */
+
+		switch (qualifier) {
+		case 0:
+			free_idle_mode_text(stk);
+			__ofono_sim_refresh(sim, file_list, TRUE, TRUE);
+			break;
+		case 1:
+			__ofono_sim_refresh(sim, file_list, FALSE, FALSE);
+			break;
+		case 2:
+		case 3:
+			free_idle_mode_text(stk);
+			__ofono_sim_refresh(sim, file_list, FALSE, TRUE);
+			break;
+		}
+
+		g_slist_foreach(file_list, (GFunc) g_free, NULL);
+		g_slist_free(file_list);
+
+		return FALSE;
+	}
+
 	rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
 	return TRUE;
 }
Signature · 1 line
1.7.1.86.g0e460.dirty
#5 lore raw

PATCH 1/1 doc: Fix wording.

In reply to Andrzej Zaborowski
---
 doc/sim-api.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
doc/sim-api.txt +1 -1
index d4d2b1b..89c321e 100644
@@ -44,7 +44,7 @@ Methods		dict GetProperties()
 
 			Obtain the icon given by id.  Only ids greater than 1
 			are valid.  XPM format is currently used to return the
-			icon format.
+			icon data.
 
 Signals		PropertyChanged(string name, variant value)
 
Signature · 1 line
1.7.1.86.g0e460.dirty
#6 lore raw

Re: [PATCH] doc: Fix wording.

Hi Andrew,

Quoted 4 lines · Andrzej Zaborowski
---
 doc/sim-api.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis