wwan: ofono: add support for querying operator code

The oFono SimManager interface exposes MNC and MCC individually, which
we can use to craft an operator code and store it in NM internally.

Signed-off-by: Muhammad Asif <thevancedgamer@mentallysanemainliners.org>
This commit is contained in:
Muhammad Asif 2025-12-22 02:18:11 +05:00 committed by Muhammad
parent 3b264e830e
commit 0118a1d07c

View file

@ -58,6 +58,9 @@ typedef struct {
GError *property_error;
char *imsi;
char *mnc;
char *mcc;
char *operator_code;
gboolean modem_online;
gboolean modem_powered;
@ -238,6 +241,25 @@ update_modem_state(NMModemOfono *self)
}
}
static void
operator_code_changed(NMModemOfono *self)
{
NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self);
_LOGD("MCC: %s MNC: %s", priv->mcc ? priv->mcc : "(null)", priv->mnc ? priv->mnc : "(null)");
if (priv->mcc && priv->mnc) {
char operator_code[7];
g_snprintf(operator_code, sizeof(operator_code), "%s%s", priv->mcc, priv->mnc);
if (priv->operator_code)
g_free(priv->operator_code);
priv->operator_code = g_strdup(operator_code);
_nm_modem_set_operator_code(NM_MODEM(self), priv->operator_code);
}
}
/* Disconnect */
typedef struct {
NMModemOfono *self;
@ -443,6 +465,26 @@ handle_sim_property(GDBusProxy *proxy, const char *property, GVariant *v, gpoint
priv->imsi = g_strdup(value_str);
update_modem_state(self);
}
} else if (g_strcmp0(property, "MobileCountryCode") == 0 && VARIANT_IS_OF_TYPE_STRING(v)) {
const char *value_str = g_variant_get_string(v, NULL);
_LOGD("MobileCountryCode: %s", value_str);
if (priv->mcc)
g_free(priv->mcc);
priv->mcc = g_strdup(value_str);
operator_code_changed(self);
} else if (g_strcmp0(property, "MobileNetworkCode") == 0 && VARIANT_IS_OF_TYPE_STRING(v)) {
const char *value_str = g_variant_get_string(v, NULL);
_LOGD("MobileNetworkCode: %s", value_str);
if (priv->mnc)
g_free(priv->mnc);
priv->mnc = g_strdup(value_str);
operator_code_changed(self);
}
}
@ -1957,6 +1999,13 @@ dispose(GObject *object)
g_free(priv->imsi);
priv->imsi = NULL;
g_free(priv->mcc);
priv->mcc = NULL;
g_free(priv->mnc);
priv->mnc = NULL;
g_free(priv->operator_code);
priv->operator_code = NULL;
g_strfreev(priv->available_technologies);
priv->available_technologies = NULL;