Skip to content

Commit

Permalink
[connman] Cancel set_online request if modem is powered off. JB#61333
Browse files Browse the repository at this point in the history
Had Android device paired via bluetooth to Sailfish one, then
disconnected them. A hfp modem was created which stayed offline.

That's a problem of its own, but amplified by connman trying every 2
seconds to make the modem go online. That's doomed to fail as long
as it's not powered. Thus, if set_powered fails, the online attempts
are stopped.
  • Loading branch information
pvuorela committed Mar 25, 2024
1 parent bf214d8 commit 32d5319
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions connman/plugins/sailfish_ofono.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct modem_data {
gulong connctx_handler_id[CONNCTX_HANDLER_COUNT];
guint activate_timeout_id;
guint online_check_id;
GCancellable *pending_set_powered;
struct connman_device *device;
struct connman_network *network;
const char *country;
Expand Down Expand Up @@ -1060,6 +1061,25 @@ static void modem_online_check(struct modem_data *md)
modem_set_online(md, !__connman_technology_get_offlinemode());
}

static void set_powered_cb(OfonoModem* sender, const GError* error, void* arg)
{
struct modem_data *md = arg;
DBG("set powered callback");

md->pending_set_powered = NULL;

if (error) {
connman_warn("Error setting modem powered %s: %s",
ofono_modem_path(md->modem), error->message);

// these are doomed to fail until the modem is powered
if (md->online_check_id) {
g_source_remove(md->online_check_id);
md->online_check_id = 0;
}
}
}

static void modem_changed(OfonoModem *modem, void *arg)
{
struct modem_data *md = arg;
Expand All @@ -1068,7 +1088,12 @@ static void modem_changed(OfonoModem *modem, void *arg)
modem->powered, modem->online);
if (!modem->powered) {
DBG("%s powering up", ofono_modem_path(modem));
ofono_modem_set_powered(modem, TRUE);
if (md->pending_set_powered) {
g_cancellable_cancel(md->pending_set_powered);
}
md->pending_set_powered
= ofono_modem_set_powered_full(modem, TRUE,
&set_powered_cb, md);
}

/* Keep modem online state in sync with the offline mode */
Expand Down Expand Up @@ -1177,7 +1202,9 @@ static void modem_create(struct plugin_data *plugin, OfonoModem *modem)
g_hash_table_replace(plugin->modems, g_strdup(path), md);

if (ofono_modem_valid(modem)) {
ofono_modem_set_powered(modem, TRUE);
md->pending_set_powered
= ofono_modem_set_powered_full(modem, TRUE,
&set_powered_cb, md);
modem_online_check(md);
}
if (ofono_connmgr_valid(md->connmgr)) {
Expand All @@ -1197,6 +1224,10 @@ static void modem_delete(gpointer value)
g_source_remove(md->online_check_id);
}

if (md->pending_set_powered) {
g_cancellable_cancel(md->pending_set_powered);
}

if (md->delayed_set_connected_id) {
g_source_remove(md->delayed_set_connected_id);
}
Expand Down

0 comments on commit 32d5319

Please sign in to comment.