aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-03-11 09:27:11 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-03-17 09:36:53 +0100
commit37d4f5c129b056517c9403a693c30f68777572da (patch)
tree781ba6109194f88d172aad38f11a9892a9bfb2e0
parent340fa919d99fc3c07af5129073b60dee71111939 (diff)
port-mbim: implement port reset logic
-rw-r--r--src/mm-port-mbim.c106
-rw-r--r--src/mm-port-mbim.h10
2 files changed, 114 insertions, 2 deletions
diff --git a/src/mm-port-mbim.c b/src/mm-port-mbim.c
index 57b7cf02..4102b6d5 100644
--- a/src/mm-port-mbim.c
+++ b/src/mm-port-mbim.c
@@ -10,7 +10,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
- * Copyright (C) 2013-2018 Aleksander Morgado <aleksander@gnu.org>
+ * Copyright (C) 2013-2021 Aleksander Morgado <aleksander@gnu.org>
*/
#include <config.h>
@@ -26,6 +26,7 @@
#include <mm-errors-types.h>
#include "mm-port-mbim.h"
+#include "mm-port-net.h"
#include "mm-log-object.h"
G_DEFINE_TYPE (MMPortMbim, mm_port_mbim, MM_TYPE_PORT)
@@ -155,6 +156,109 @@ mm_port_mbim_allocate_qmi_client (MMPortMbim *self,
/*****************************************************************************/
+typedef struct {
+ MbimDevice *device;
+ MMPort *data;
+} ResetContext;
+
+static void
+reset_context_free (ResetContext *ctx)
+{
+ g_clear_object (&ctx->device);
+ g_clear_object (&ctx->data);
+ g_slice_free (ResetContext, ctx);
+}
+
+gboolean
+mm_port_mbim_reset_finish (MMPortMbim *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return g_task_propagate_boolean (G_TASK (res), error);
+}
+
+static void
+delete_all_links_ready (MbimDevice *device,
+ GAsyncResult *res,
+ GTask *task)
+{
+ MMPortMbim *self;
+ GError *error = NULL;
+
+ self = g_task_get_source_object (task);
+
+ /* link deletion not fatal */
+ if (!mbim_device_delete_all_links_finish (device, res, &error)) {
+ mm_obj_dbg (self, "couldn't delete all links: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+}
+
+static void
+reset_device_new_ready (GObject *source,
+ GAsyncResult *res,
+ GTask *task)
+{
+ MMPortMbim *self;
+ ResetContext *ctx;
+ GError *error = NULL;
+
+ self = g_task_get_source_object (task);
+ ctx = g_task_get_task_data (task);
+
+ ctx->device = mbim_device_new_finish (res, &error);
+ if (!ctx->device) {
+ g_task_return_error (task, error);
+ g_object_unref (task);
+ return;
+ }
+
+ /* first, delete all links found, if any */
+ mm_obj_dbg (self, "deleting all links in data interface '%s'",
+ mm_port_get_device (ctx->data));
+ mbim_device_delete_all_links (ctx->device,
+ mm_port_get_device (ctx->data),
+ NULL,
+ (GAsyncReadyCallback)delete_all_links_ready,
+ task);
+}
+
+void
+mm_port_mbim_reset (MMPortMbim *self,
+ MMPort *data,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ ResetContext *ctx;
+ g_autoptr(GFile) file = NULL;
+ g_autofree gchar *fullpath = NULL;
+
+ task = g_task_new (self, NULL, callback, user_data);
+
+ if (self->priv->mbim_device) {
+ g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, "Port is already open");
+ g_object_unref (task);
+ return;
+ }
+
+ ctx = g_slice_new0 (ResetContext);
+ ctx->data = g_object_ref (data);
+ g_task_set_task_data (task, ctx, (GDestroyNotify) reset_context_free);
+
+ fullpath = g_strdup_printf ("/dev/%s", mm_port_get_device (MM_PORT (self)));
+ file = g_file_new_for_path (fullpath);
+
+ mbim_device_new (file, NULL,
+ (GAsyncReadyCallback) reset_device_new_ready,
+ task);
+}
+
+/*****************************************************************************/
+
gboolean
mm_port_mbim_open_finish (MMPortMbim *self,
GAsyncResult *res,
diff --git a/src/mm-port-mbim.h b/src/mm-port-mbim.h
index 8b37e99b..7c2d4df5 100644
--- a/src/mm-port-mbim.h
+++ b/src/mm-port-mbim.h
@@ -10,7 +10,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
- * Copyright (C) 2013 Aleksander Morgado <aleksander@gnu.org>
+ * Copyright (C) 2013-2021 Aleksander Morgado <aleksander@gnu.org>
*/
#ifndef MM_PORT_MBIM_H
@@ -92,4 +92,12 @@ gboolean mm_port_mbim_allocate_qmi_client_finish (MMPortMbim *self,
MbimDevice *mm_port_mbim_peek_device (MMPortMbim *self);
+void mm_port_mbim_reset (MMPortMbim *self,
+ MMPort *data,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean mm_port_mbim_reset_finish (MMPortMbim *self,
+ GAsyncResult *res,
+ GError **error);
+
#endif /* MM_PORT_MBIM_H */