ofono.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] voicecall: Make sure SIM ecc numbers are always read
@ 2022-09-15 20:51 Ivaylo Dimitrov
  2022-09-19 16:06 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Ivaylo Dimitrov @ 2022-09-15 20:51 UTC (permalink / raw)
  To: ofono; +Cc: merlijn, tony, pavel, Ivaylo Dimitrov

It might happen that by the time ofono_voicecall_register() is called, SIM
is already in OFONO_SIM_STATE_READY state so SIM emergency numbers are
never read.

Fix that by adding code that reads emergency numbers even in the above
case. Also, make sure ECC file watch is properly removed and sim_context is
free()-ed.
---
 src/voicecall.c | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index 3da258d..2cf035a 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -64,6 +64,7 @@ struct ofono_voicecall {
 	struct ofono_sim_context *sim_context;
 	unsigned int sim_watch;
 	unsigned int sim_state_watch;
+	unsigned int ecc_watch;
 	const struct ofono_voicecall_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
@@ -2866,6 +2867,16 @@ static void voicecall_close_settings(struct ofono_voicecall *vc)
 	}
 }
 
+static void unwatch_sim_ecc_numbers(struct ofono_voicecall *vc)
+{
+	if (!vc->sim_context)
+		return;
+
+	ofono_sim_remove_file_watch(vc->sim_context, vc->ecc_watch);
+	ofono_sim_context_free(vc->sim_context);
+	vc->sim_context = NULL;
+}
+
 static void voicecall_unregister(struct ofono_atom *atom)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
@@ -2890,6 +2901,7 @@ static void voicecall_unregister(struct ofono_atom *atom)
 
 	vc->sim = NULL;
 
+	unwatch_sim_ecc_numbers(vc);
 	free_sim_ecc_numbers(vc, FALSE);
 
 	if (vc->nw_en_list) {
@@ -2993,35 +3005,39 @@ static void read_sim_ecc_numbers(int id, void *userdata)
 			ecc_g3_read_cb, vc);
 }
 
+static void watch_sim_ecc_numbers(struct ofono_voicecall *vc)
+{
+	if (vc->sim_context)
+		return;
+
+	vc->sim_context = ofono_sim_context_create(vc->sim);
+	read_sim_ecc_numbers(SIM_EFECC_FILEID, vc);
+
+	vc->ecc_watch = ofono_sim_add_file_watch(vc->sim_context,
+					SIM_EFECC_FILEID, read_sim_ecc_numbers,
+					vc, NULL);
+}
+
 static void sim_state_watch(enum ofono_sim_state new_state, void *user)
 {
 	struct ofono_voicecall *vc = user;
 
 	switch (new_state) {
 	case OFONO_SIM_STATE_INSERTED:
-		if (vc->sim_context == NULL)
-			vc->sim_context = ofono_sim_context_create(vc->sim);
-
-		read_sim_ecc_numbers(SIM_EFECC_FILEID, vc);
-
-		ofono_sim_add_file_watch(vc->sim_context, SIM_EFECC_FILEID,
-						read_sim_ecc_numbers, vc, NULL);
+		watch_sim_ecc_numbers(vc);
 		break;
 	case OFONO_SIM_STATE_NOT_PRESENT:
 	case OFONO_SIM_STATE_RESETTING:
 		/* TODO: Must release all non-emergency calls */
 
-		if (vc->sim_context) {
-			ofono_sim_context_free(vc->sim_context);
-			vc->sim_context = NULL;
-		}
-
+		unwatch_sim_ecc_numbers(vc);
 		free_sim_ecc_numbers(vc, FALSE);
 		set_new_ecc(vc);
 
 		voicecall_close_settings(vc);
 		break;
 	case OFONO_SIM_STATE_READY:
+		watch_sim_ecc_numbers(vc);
 		voicecall_load_settings(vc);
 		break;
 	case OFONO_SIM_STATE_LOCKED_OUT:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] voicecall: Make sure SIM ecc numbers are always read
  2022-09-15 20:51 [PATCH] voicecall: Make sure SIM ecc numbers are always read Ivaylo Dimitrov
@ 2022-09-19 16:06 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2022-09-19 16:06 UTC (permalink / raw)
  To: Ivaylo Dimitrov, ofono; +Cc: merlijn, tony, pavel

Hi Ivaylo,

On 9/15/22 15:51, Ivaylo Dimitrov wrote:
> It might happen that by the time ofono_voicecall_register() is called, SIM
> is already in OFONO_SIM_STATE_READY state so SIM emergency numbers are
> never read.
> 
> Fix that by adding code that reads emergency numbers even in the above
> case. Also, make sure ECC file watch is properly removed and sim_context is
> free()-ed.
> ---
>   src/voicecall.c | 40 ++++++++++++++++++++++++++++------------
>   1 file changed, 28 insertions(+), 12 deletions(-)
> 

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-19 16:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 20:51 [PATCH] voicecall: Make sure SIM ecc numbers are always read Ivaylo Dimitrov
2022-09-19 16:06 ` Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).