ofono.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
To: ofono@lists.linux.dev
Cc: merlijn@wizzup.org, tony@atomide.com, pavel@ucw.cz,
	Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Subject: [PATCH] voicecall: Make sure SIM ecc numbers are always read
Date: Thu, 15 Sep 2022 23:51:05 +0300	[thread overview]
Message-ID: <1663275065-19685-1-git-send-email-ivo.g.dimitrov.75@gmail.com> (raw)

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


             reply	other threads:[~2022-09-15 20:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 20:51 Ivaylo Dimitrov [this message]
2022-09-19 16:06 ` [PATCH] voicecall: Make sure SIM ecc numbers are always read Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1663275065-19685-1-git-send-email-ivo.g.dimitrov.75@gmail.com \
    --to=ivo.g.dimitrov.75@gmail.com \
    --cc=merlijn@wizzup.org \
    --cc=ofono@lists.linux.dev \
    --cc=pavel@ucw.cz \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).