From: Denis Kenzior <denkenz@gmail.com>
To: ofono@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH v2 01/11] phonesim: Allow phonesim to work with Multiplexer=internal
Date: Fri, 22 Mar 2024 10:42:14 -0500 [thread overview]
Message-ID: <20240322154234.2720542-1-denkenz@gmail.com> (raw)
If use_mux code path was used, certain commands (like querying of the
SIM status) were not sent, resulting in incomplete modem initialization.
Fix that.
---
plugins/phonesim.c | 102 +++++++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 46 deletions(-)
diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index 07afc14d56bb..29a983611d75 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -512,13 +512,27 @@ static void usimstate_notify(GAtResult *result, gpointer user_data)
ofono_sim_inserted_notify(data->sim, inserted);
}
-static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
+static void emulator_battery_cb(struct ofono_atom *atom, void *data)
{
- struct ofono_modem *modem = user_data;
+ struct ofono_emulator *em = __ofono_atom_get_data(atom);
+ int val = 0;
- DBG("");
+ if (GPOINTER_TO_INT(data) > 0)
+ val = (GPOINTER_TO_INT(data) - 1) / 20 + 1;
- ofono_modem_set_powered(modem, ok);
+ ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_BATTERY, val);
+}
+
+static void emulator_hfp_watch(struct ofono_atom *atom,
+ enum ofono_atom_watch_condition cond,
+ void *user_data)
+{
+ struct phonesim_data *data = user_data;
+
+ if (cond != OFONO_ATOM_WATCH_CONDITION_REGISTERED)
+ return;
+
+ emulator_battery_cb(atom, GUINT_TO_POINTER(data->batt_level));
}
static gboolean phonesim_reset(void *user_data)
@@ -545,17 +559,6 @@ static void crst_notify(GAtResult *result, gpointer user_data)
g_idle_add(phonesim_reset, user_data);
}
-static void emulator_battery_cb(struct ofono_atom *atom, void *data)
-{
- struct ofono_emulator *em = __ofono_atom_get_data(atom);
- int val = 0;
-
- if (GPOINTER_TO_INT(data) > 0)
- val = (GPOINTER_TO_INT(data) - 1) / 20 + 1;
-
- ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_BATTERY, val);
-}
-
static void cbc_notify(GAtResult *result, gpointer user_data)
{
struct ofono_modem *modem = user_data;
@@ -582,6 +585,43 @@ static void cbc_notify(GAtResult *result, gpointer user_data)
GUINT_TO_POINTER(level));
}
+static void finish_powerup(struct ofono_modem *modem)
+{
+ struct phonesim_data *data = ofono_modem_get_data(modem);
+
+ g_at_chat_send(data->chat, "AT+CSCS=\"GSM\"", none_prefix,
+ NULL, NULL, NULL);
+
+ g_at_chat_register(data->chat, "+CRST:",
+ crst_notify, FALSE, modem, NULL);
+
+ g_at_chat_register(data->chat, "+CBC:",
+ cbc_notify, FALSE, modem, NULL);
+
+ g_at_chat_send(data->chat, "AT+CBC", none_prefix, NULL, NULL, NULL);
+
+ g_at_chat_send(data->chat, "AT+SIMSTATE?", simstate_prefix,
+ simstate_query, modem, NULL);
+ g_at_chat_register(data->chat, "+USIMSTATE:", usimstate_notify,
+ FALSE, modem, NULL);
+
+ data->hfp_watch = __ofono_modem_add_atom_watch(modem,
+ OFONO_ATOM_TYPE_EMULATOR_HFP,
+ emulator_hfp_watch, data, NULL);
+}
+
+static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct ofono_modem *modem = user_data;
+
+ DBG("");
+
+ ofono_modem_set_powered(modem, ok);
+
+ if (ok)
+ finish_powerup(modem);
+}
+
static void phonesim_disconnected(gpointer user_data)
{
struct ofono_modem *modem = user_data;
@@ -644,18 +684,6 @@ static void mux_setup(GAtMux *mux, gpointer user_data)
cfun_set_on_cb, modem, NULL);
}
-static void emulator_hfp_watch(struct ofono_atom *atom,
- enum ofono_atom_watch_condition cond,
- void *user_data)
-{
- struct phonesim_data *data = user_data;
-
- if (cond != OFONO_ATOM_WATCH_CONDITION_REGISTERED)
- return;
-
- emulator_battery_cb(atom, GUINT_TO_POINTER(data->batt_level));
-}
-
static int connect_socket(const char *address, int port)
{
struct sockaddr_in addr;
@@ -755,25 +783,7 @@ static int phonesim_enable(struct ofono_modem *modem)
return -EINPROGRESS;
}
- g_at_chat_send(data->chat, "AT+CSCS=\"GSM\"", none_prefix,
- NULL, NULL, NULL);
-
- g_at_chat_register(data->chat, "+CRST:",
- crst_notify, FALSE, modem, NULL);
-
- g_at_chat_register(data->chat, "+CBC:",
- cbc_notify, FALSE, modem, NULL);
-
- g_at_chat_send(data->chat, "AT+CBC", none_prefix, NULL, NULL, NULL);
-
- g_at_chat_send(data->chat, "AT+SIMSTATE?", simstate_prefix,
- simstate_query, modem, NULL);
- g_at_chat_register(data->chat, "+USIMSTATE:", usimstate_notify,
- FALSE, modem, NULL);
-
- data->hfp_watch = __ofono_modem_add_atom_watch(modem,
- OFONO_ATOM_TYPE_EMULATOR_HFP,
- emulator_hfp_watch, data, NULL);
+ finish_powerup(modem);
return 0;
}
--
2.43.0
next reply other threads:[~2024-03-22 15:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 15:42 Denis Kenzior [this message]
2024-03-22 15:42 ` [PATCH v2 02/11] modem: commonize feature string list generation Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 03/11] modem: commonize interface " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 04/11] doc: Add new Modem.Capabilities property Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 05/11] modem: add implementation for the Capabilities property Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 06/11] phonesim: Set modem lte capable Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 07/11] gemalto: " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 08/11] xmm7xxx: Set modem as " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 09/11] ublox: Set modem " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 10/11] gobi: " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 11/11] quectel: " Denis Kenzior
2024-03-22 16:20 ` [PATCH v2 01/11] phonesim: Allow phonesim to work with Multiplexer=internal patchwork-bot+ofono
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=20240322154234.2720542-1-denkenz@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@lists.linux.dev \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).