aboutsummaryrefslogtreecommitdiff
path: root/src/mm-iface-modem-3gpp.c
diff options
context:
space:
mode:
authorUjjwal Pande <ujjwalpande@google.com>2023-05-25 21:42:01 +0000
committerAleksander Morgado <aleksandermj@chromium.org>2023-06-08 20:16:12 +0000
commite3a1206c57db685065dfd0eb4efae5083dd5cef5 (patch)
treebc0cb37666e9d7b798f0bf9f53c5558b340fa53f /src/mm-iface-modem-3gpp.c
parent97c32d6e51ebabb14085a7166db6d7c81d62e98e (diff)
api: new carrier lock support
Adding support for carrier lock for MBIM modems using google simlock mechanism.
Diffstat (limited to 'src/mm-iface-modem-3gpp.c')
-rw-r--r--src/mm-iface-modem-3gpp.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c
index 5d501042..9fd376fd 100644
--- a/src/mm-iface-modem-3gpp.c
+++ b/src/mm-iface-modem-3gpp.c
@@ -3360,6 +3360,98 @@ load_imei_ready (MMIfaceModem3gpp *self,
interface_initialization_step (task);
}
+/*****************************************************************************/
+
+typedef struct {
+ MmGdbusModem3gpp *skeleton;
+ GDBusMethodInvocation *invocation;
+ MMIfaceModem3gpp *self;
+ GVariant *data;
+} HandleSetCarrierLockContext;
+
+static void
+handle_set_carrier_lock_context_free (HandleSetCarrierLockContext *ctx)
+{
+ g_object_unref (ctx->skeleton);
+ g_object_unref (ctx->invocation);
+ g_object_unref (ctx->self);
+ g_variant_unref (ctx->data);
+ g_free (ctx);
+}
+
+static void
+handle_set_carrier_lock_ready (MMIfaceModem3gpp *self,
+ GAsyncResult *res,
+ HandleSetCarrierLockContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_carrier_lock_finish (self, res, &error))
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ else
+ mm_gdbus_modem3gpp_complete_set_carrier_lock (ctx->skeleton, ctx->invocation);
+ handle_set_carrier_lock_context_free (ctx);
+}
+
+static void
+handle_set_carrier_lock_auth_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ HandleSetCarrierLockContext *ctx)
+{
+ GError *error = NULL;
+ const guint8 *data;
+ gsize data_size;
+
+ if (!mm_base_modem_authorize_finish (self, res, &error)) {
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ handle_set_carrier_lock_context_free (ctx);
+ return;
+ }
+
+ /* If carrier lock is not implemented, report an error */
+ if (!MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_carrier_lock ||
+ !MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_carrier_lock_finish) {
+ g_dbus_method_invocation_return_error (ctx->invocation,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_UNSUPPORTED,
+ "Cannot send set carrier lock request to modem: "
+ "operation not supported");
+ handle_set_carrier_lock_context_free (ctx);
+ return;
+ }
+ data = (const guint8 *) g_variant_get_fixed_array (ctx->data, &data_size, sizeof (guint8));
+
+ MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->set_carrier_lock (ctx->self,
+ data,
+ data_size,
+ (GAsyncReadyCallback)handle_set_carrier_lock_ready,
+ ctx);
+}
+
+static gboolean
+handle_set_carrier_lock (MmGdbusModem3gpp *skeleton,
+ GDBusMethodInvocation *invocation,
+ GVariant *data,
+ MMIfaceModem3gpp *self)
+{
+ HandleSetCarrierLockContext *ctx;
+
+ ctx = g_new0 (HandleSetCarrierLockContext, 1);
+ ctx->skeleton = g_object_ref (skeleton);
+ ctx->invocation = g_object_ref (invocation);
+ ctx->self = g_object_ref (self);
+ ctx->data = g_variant_ref (data);
+
+ mm_base_modem_authorize (MM_BASE_MODEM (self),
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ (GAsyncReadyCallback)handle_set_carrier_lock_auth_ready,
+ ctx);
+ return TRUE;
+}
+
+/*****************************************************************************/
+
static void
interface_initialization_step (GTask *task)
{
@@ -3498,6 +3590,10 @@ interface_initialization_step (GTask *task)
"handle-disable-facility-lock",
G_CALLBACK (handle_disable_facility_lock),
self);
+ g_signal_connect (ctx->skeleton,
+ "handle-set-carrier-lock",
+ G_CALLBACK (handle_set_carrier_lock),
+ self);
/* Finally, export the new interface */
mm_gdbus_object_skeleton_set_modem3gpp (MM_GDBUS_OBJECT_SKELETON (self),